akhauriyash/Code-Regression huggingface dataset:
N, x = map(int, input().split())
A = [0 for i in range(2 * N - 1)]
if N == 2:
  if x == 2:
    print('Yes')
    print(1)
    print(2)
    print(3)
  else:
    print('No')
elif N >= 3:
  if x == 1 or x == 2 * N - 1:
    print('No')
  elif x > 2 and x < 2 * N - 2:
    A[N - 3], A[N - 2], A[N - 1], A[N], A[N + 1] = 1, 2*N - 1, x, 2, 2*N - 2
    j = 2
    for i in range(2*N-1):
      if i < N - 3 or i > N + 1:
        j += 1
        if j == x:
          j += 1
        A[i] = j
    print('Yes')
    for i in range(2*N-1):
      print(A[i])
  elif x == 2 or x == 2 * N - 2:
    A[N - 2], A[N - 1], A[N] = 1, x, 2*N - 1
    j = 1
    for i in range(2*N-1):
      if i < N - 2 or i > N:
        j += 1
        if j == x:
          j += 1
        A[i] = j
    print('Yes')
    for i in range(2*N-1):
      print(A[i])

Measured memory_bytes: 12496
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    int c[12];
    int a[12][12];

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

    int INF = 1 << 30;
    int r = INF;
    for (int k = 0; k < 1 << n; k++) {
        int s = 0, t[12] = {};
        for (int i = 0; i < n; i++) {
            if (k >> i & 1) {
                s += c[i];
                for (int j = 0; j < m; j++) {
                    t[j] += a[i][j];
                }
            }
        }

        int b = 1;
        for (int j = 0; j < m; j++) {
            if (t[j] < x) b = 0;
        }
        if (b) r = min(r, s);
    }

    cout << (r == INF ? -1 : r) << endl;

    return 0;
}

Measured memory_bytes: 3652
using System;
using System.Collections.Generic;
using System.Linq;


namespace AtCoder
{
    class Program
    {
        public static void Main()
        {
            new Program().Solve();
        }

        void Solve()
        {
            int n = int.Parse(Console.ReadLine());
            int a = int.Parse(Console.ReadLine());
            Console.WriteLine((a - (n % 500)) >= 0 ? "Yes" : "No");
        }

    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <vector>
#include <chrono>
#include <random>

std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

int main() {
	std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);
	std::string s;
	std::cin >> s;
	int n = (int) s.size();
	std::vector<int> to(n);
	for(int i = 0; i < n; i++) {
		if(s[i] == 'R') {
			to[i] = i+1;
		} else {
			to[i] = i-1;
		}
	}
	for(int j = 0; j < 100; j++) {
		std::vector<int> nxt(n);
		for(int i = 0; i < n; i++) {
			nxt[i] = i;
			for(int k = 0; k < 10; k++) {
				nxt[i] = to[nxt[i]];
			}
		}
		to.swap(nxt);
	}
	std::vector<int> freq(n, 0);
	for(int i = 0; i < n; i++) {
		freq[to[i]]++;
	}
	for(int i = 0; i < n; i++) {
		std::cout << freq[i] << (i + 1 == n ? '\n' : ' ');
	}
}

Measured memory_bytes: 1344
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


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


int main(){
    ll a = 0;
    ll max_a = 0;
    string S;
    cin>>S;
    rep(i,0,3){
        if(S[i] == 'R')a++;
        else{
            a=0;
        }
        max_a = max(a,max_a);
    }
    cout<<max_a;
    return 0;
}

Measured memory_bytes: 3584
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;


public class Main {
    int N;
    long X;
    long[] patty;

    private long patties(int layer) {
        if (layer == 0) {
            return patty[layer] = 1;
        }

        if (patty[layer] != - 1) {
            return patty[layer];
        }

        return patty[layer] = patties(layer - 1) + 1 + patties(layer - 1);
    }

    private long dfs(long left, long right, int layer) {
        if (layer == 0) {
            return 1;
        }

        long center = (left + right) / 2;

        if (left == X) {
            return 0;
        }

        if (right == X) {
            return patty[layer - 1] * 2 + 1;
        }

        if (center == X) {
            return patty[layer - 1] + 1;
        }

        if (center < X) {
            return patty[layer - 1] + dfs(center + 1, right - 1, layer - 1) + 1;
        } else {
            return dfs(left + 1, center - 1, layer - 1);
        }
    }

    private void solve() {
        N = nextInt();
        X = nextLong();

        patty = new long[N + 1];
        Arrays.fill(patty, -1);
        patty[N] = patties(N);

        long layerSum = 1;
        for(int i = 1;i < N + 1;i++) {
            layerSum = layerSum * 2 + 3;
        }

        long ans = dfs(1, layerSum, N);
        out.println(ans);
    }

    public static void main(String[] args) {
        out.flush();
        new Main().solve();
        out.close();
    }

    /* Input */
    private static final InputStream in = System.in;
    private static final PrintWriter out = new PrintWriter(System.out);
    private final byte[] buffer = new byte[4096];
    private int p = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (p < buflen)
            return true;
        p = 0;
        try {
            buflen = in.read(buffer);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (buflen <= 0)
            return false;
        return true;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrint(buffer[p])) {
            p++;
        }
        return hasNextByte();
    }

    private boolean isPrint(int ch) {
        if (ch >= '!' && ch <= '~')
            return true;
        return false;
    }

    private int nextByte() {
        if (!hasNextByte())
            return -1;
        return buffer[p++];
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = -1;
        while (isPrint((b = nextByte()))) {
            sb.appendCodePoint(b);
        }
        return sb.toString();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 21460
N = input()

saidai = 0

for i in range(1,int(N)+1):
    count = 0
    flag = 0
    x = i
    
    while flag == 0:
        y = int(int(x) % 2)
        if y == 0:
            count = int(int(count) + 1)
            x = int(int(x) / 2)
        elif y == 1:
            flag = 1

    if int(count) >= int(saidai):
        saidai = count
        z = i

print(z)

Measured memory_bytes: 3316
#include <cstring>
#include <iostream>
using namespace std;
const int rx[] = {0, 1, 1, 0, -1, -1, -1, 0, 1};
const int ry[] = {0, 0, 1, 1, 1, 0, -1, -1, -1};
const int dx[] = {2, 2, 1, 0, -1, -2, -2, -2, -1, 0, 1, 2};
const int dy[] = {0, 1, 2, 2, 2, 1, 0, -1, -2, -2, -2, -1};
int n;
int x, y;
int sx[10];
int sy[10];
bool field[11][10][10];

void printfiled(int c) {
	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 10; j++) {
			cout << field[c][j][i];
		}
		cout << endl;
	}
	cout << endl;
}

bool exists(int current, int na, int nb) {
	for (int i = 0; i < 12; i++) {
		const int a = na - dx[i];
		const int b = nb - dy[i];
		if (0 <= a && a < 10 && 0 <= b && b < 10) {
			if (field[current][a][b]) return true;
		}
	}
	return false;
}

bool solve() {
	field[0][x][y] = true;
	for (int i = 0; i < n; i++) {
		const int current = i;
		const int next = current + 1;
		bool alive = false;
		for (int j = 0; j < 9; j++) {
			const int na = sx[i] + rx[j];
			const int nb = sy[i] + ry[j];
			if (0 <= na && na < 10 && 0 <= nb && nb < 10) {
				field[next][na][nb] = exists(current, na, nb);
				alive = alive || field[next][na][nb];
			}
		}
		if (!alive) return false;
//		printfiled(i);
	}
	return true;
}

int main () {
	while (cin >> x >> y, x || y) {
		memset(field, 0, sizeof(field));
		cin >> n;
		for (int i = 0; i < n; i++) {
			cin >> sx[i] >> sy[i];
		}
		cout << (solve() ? "OK":"NA") << endl;
	}
	return 0;
}

Measured memory_bytes: 1152
i = list( map(int, input().split()) )

w = i[0]
h = i[1]
x = i[2]
y = i[3]
r = i[4]

if (x-r>=0 and x+r<=w and y-r>=0 and y+r<=h):
    print("Yes")
else:
    print("No")


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

#define pb push_back
#define mp make_pair
#define sqr(a) ((a) * (a)) 
#define io() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

typedef long long int li;
typedef long double ld;


int main()
{
    io();
    string s;
    cin>>s;
    if(s=="ABC")
    cout<<"ARC";
    else if(s=="ARC")
    cout<<"ABC";
}

Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>
#include <vector>
#include <string.h>
#include <cmath>
#include <math.h>
#include <ctime>
#include <cstring>
#include <climits>
#include <sstream>
#include <array>
#include <tuple>
#include <set>
#include <iterator>
#include <cstdio>
#include <string>
#include <stack>
#include <valarray>
#include <utility>
#include <iomanip>
#include <list>
#include <numeric>
#include <regex>
#include <map>
#include <queue>
#include <deque>
#include <unordered_set>
#include <unordered_map>

using namespace std;

#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll          long long
#define PI          3.1415926535
#define pb          push_back
#define ins         insert
#define INF         LLONG_MAX
#define mk          make_pair
#define lb(v,x)     lower_bound(all(v),x)
#define ub(v,x)     upper_bound(all(v),x)
#define ff          first
#define ss          second
#define rev         reverse
#define uset        unordered_set
#define umap        unordered_map
#define endl        "\n"
#define max3(x,y,z)  max(x,max(y,z))
#define min3(x,y,z)  min(x,min(y,z))
#define sz(a)       (ll)a.size()
#define double      long double
#define minpq       priority_queue <ll,vector<ll>,greater<ll> > 
#define fill(x,y)   memset(x,y,sizeof(x))
#define all(x)      (x).begin(), (x).end()
#define rall(x)     (x).rbegin(), (x).rend()
#define MOD         1000000007 //1e9+7
#define bp(n)       __builtin_popcountll(n)
#define mxt(a)      *(max_element(a.begin(),a.end()))
#define mnt(a)      *(min_element(a.begin(),a.end())
#define unique_sort(c) (sort(all(c)), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define rep(i, a, b) for(ll i = (a); i<= (b); ++i)
#define trav(a, x) 	 for(auto &a : x)
#define re(i,n)      for(ll i = 0; i < n; ++i) 
const ll N = 4e5 + 7;
typedef pair<ll,ll>   pii;
typedef vector<pii>   vpii;
typedef vector<ll>    vll;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
ll power(ll x,ll y){ll res=1;x=x;while(y>0){if(y&1)res=(res*x);y=y>>1;x=(x*x);}return res;}
template<typename T> T gcd(T a,T b){ if(a==0) return b; return gcd(b%a,a); }
template<typename T> T powm(T a,T b, ll m){T cnt=1; while(b>0){ if(b%2==1) cnt=(cnt*a)%m; b/=2; a=(a*a)%m; }return cnt%m;}
ll ncr(ll n,ll r){ll res=1;if(r>n)return 0;if(r>n-r)r=n-r;for(ll i=0;i<r;i++){res*=(n-i);res/=(i+1);}return res;}
ll sqr(ll x) { return x * x;}
// always use 1ll*ans to avoid signed integer overflow; 
void prec(){

}

void solve(){
	int n,a,b,c;
	cin>>n;
	int dp[n+10][4];
	dp[0][1]=0,dp[0][2]=0,dp[0][3]=0;
	rep(i,1,n){
		cin>>a>>b>>c;
		dp[i][1]=a+max(dp[i-1][2],dp[i-1][3]);
		dp[i][2]=b+max(dp[i-1][1],dp[i-1][3]);
		dp[i][3]=c+max(dp[i-1][2],dp[i-1][1]);
	}
	cout<<max3(dp[n][1],dp[n][2],dp[n][3])<<endl;
}

int main()
{
    ios;
    int tc=1;
    //cin>>tc;
    prec();
    while(tc--)
    	solve();
    return 0; 
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <sstream>
using namespace std;

long long GetNewSat(int d, int newT, const vector<int>& ts, const vector<int>& cs, const vector<vector<int>>& ss, long long sat, int D)
{
	int prevT = ts[d];
	int prevTdaysBefore = distance(ts.rbegin() + (D - d), find(ts.rbegin() + (D - d), ts.rend(), prevT));
	int prevTdaysAfter = distance(ts.begin() + d, find(ts.begin() + d + 1, ts.end(), prevT));
	int newTdaysBefore = distance(ts.rbegin() + (D - d), find(ts.rbegin() + (D - d), ts.rend(), newT));
	int newTdaysAfter = distance(ts.begin() + d, find(ts.begin() + d + 1, ts.end(), newT));
	sat -= cs[prevT] * (prevTdaysBefore + 1) * prevTdaysAfter;
	sat += cs[newT] * (newTdaysBefore + 1) * newTdaysAfter;
	sat -= ss[d][prevT];
	sat += ss[d][newT];
	return sat;
}

int main()
{
	auto& in = cin;

	const int numA = 26;
	int D;
	in >> D;
	vector<int> cs;
	vector<vector<int>> ss;
	for (int i = 0; i < numA; ++i) {
		int c;
		in >> c;
		cs.push_back(c);
	}
	for (int i = 0; i < D; ++i) {
		vector<int> s;
		for (int j = 0; j < numA; ++j) {
			int is;
			in >> is;
			s.push_back(is);
		}
		ss.emplace_back(move(s));
	}

	long long sat = 0;
	vector<int> ds(numA);
	vector<int> ts;
	for (int i = 0; i < D; ++i) {
		int t = distance(ss[i].begin(), max_element(ss[i].begin(), ss[i].end()));
		ts.push_back(t);
		sat += ss[i][t];
		for (int j = 0; j < numA; ++j)
			++ds[j];
		ds[t] = 0;
		for (int j = 0; j < numA; ++j)
			sat -= cs[j] * ds[j];
	}

	int M = 50000;
	int dif = 1;
	for (int i = 0; i < M; ++i) {
		for (int d = 0; d < D; ++d) {
			int newT = ts[d] + dif;
			dif = (dif + 1) % numA;
			newT %= numA;
			long long newSat = GetNewSat(d, newT, ts, cs, ss, sat, D);
			if (newSat > sat) {
				sat = newSat;
				ts[d] = newT;
			}
		}
	}

	for (int i = 0; i < D; ++i) {
		cout << ts[i] + 1 << "\n";
	}

	return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	int n;
	cin >> n;
	vector<int> v(n);
	for( auto &i : v ) cin >> i;
	sort(v.begin(), v.end());
	int total = accumulate(v.begin(), v.end(), 0);
	bool w[n+1][total+1];
	for( int i = 0; i < n+1; ++i ){
		for( int j = 0; j < total+1; ++j ){
			w[i][j] = false;
		}
	}
	w[0][0] = true;
	for( int i = 1; i < n+1; ++i ){
		for( int j = 0; j < total+1; ++j ){
			if( w[i-1][j] ){
				w[i][j] = true;
				w[i][j+v[i-1]] = true;
			}
		}
	}
	for( int j = total; j >= 0; --j ){
		if( w[n][j] && ( j % 10 != 0 ) ){
			cout << j << endl;
			return 0;
		}
	}
	cout << "0" << endl;
	return 0;
}

Measured memory_bytes: 1280
s = input()
l = len(s)
i, cnt = 0, 0
pre = ""

while i < l:
    if pre == s[i]:
        if i + 1 < l:
            pre = s[i:i + 2]
            i += 1
        else:
            break
    else:
        pre = s[i]
    cnt += 1
    i += 1

print(cnt)

Measured memory_bytes: 3500
#include <bits/stdc++.h>
using namespace std;
#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()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
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 <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...));
}

int main() {
    string s, t;
    cin >> s >> t;
    int n = sz(s);
    map<char, char> stot, ttos;
    rep(i, n) {
        if (stot.count(s[i])) {
            if (stot[s[i]] != t[i]) {
                cout << "No" << endl;
                return 0;
            }
        } else if (ttos.count(t[i])) {
            if (ttos[t[i]] != s[i]) {
                cout << "No" << endl;
                return 0;
            }
        } else {
            stot[s[i]] = t[i];
            ttos[t[i]] = s[i];
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 776
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <cstdlib>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}





int main() {

	ll N ,an=1;
	cin >> N;
	rep(i, N) {
		an *= (i + 1);
		an %= 1000000007;
	}
	cout << an << endl;
}

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

#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp> //required

using namespace __gnu_pbds; 
using namespace std;

template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; 
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
typedef long long  ll;
typedef vector<ll> VL;
typedef vector<int> VI;
typedef pair<ll,ll> PLL;
typedef pair<int,int> PII;
#define pb push_back

#define F first
#define S second
#define SZ(a) int((a).size())
#define ALL(a) a.begin(),a.end()
#define fr(i,x,y) for(int i=x;i<y;i++)
#define frr(i,x,y) for(int i=x-1;i>=y;i--)
#define inf 1e18+1
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int mod=1000000007;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll power(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;}a=a*a;b>>=1;}return ans;}
ll powerm(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;ans%=mod;}a=a*a;a%=mod;b>>=1;}return ans%mod;}
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();

void solve()
{
    ll x,k,d;
    cin>>x>>k>>d;
    if(x>0)
    {
        ll y=x/d;
        y=min(y,k);
        k-=y;
        ll p=x-(y*d);
        if(abs(p)<abs(p-d))
        {
            if(k%2==0)
            {
                cout<<abs(p)<<endl;
            }
            else
            {
                cout<<abs(p-d)<<endl;
            }
        }
        else
        {
            if(k%2==0)
            {
                cout<<abs(p)<<endl;
            }
            else
            {
                cout<<abs(p-d)<<endl;
            }
        }
    }
    else
    {
        ll y=abs(x)/d;
        y=min(y,k);
        k-=y;
        ll p=x+(y*d);
        if(abs(p)<abs(p+d))
        {
            if(k%2==0)
            {
                cout<<abs(p)<<endl;
            }
            else
            {
                cout<<abs(p+d)<<endl;
            }
        }
        else
        {
            if(k%2==0)
            {
                cout<<abs(p)<<endl;
            }
            else
            {
                cout<<abs(p+d)<<endl;
            }
        }
    }
    return;
}
int main()
{
    IOS;
    ll t=1;
    //cin>>t;
    while(t--)
    {
        //cout<<"Case #"<<pp-t<<":\n";
        solve();
    }
    return 0;
}
/* stuff you should look for
        * int overflow, array bounds
        * special cases (n=1?)
        * do smth instead of nothing and stay organized
        * WRITE STUFF DOWN
*/
/*
recursion - matrix exponential

*/
// BITMASK:
// 1)When some constrall is of the order of 15-20, think of bitmask DP.
// 2)When some constrall is around 40, try out meet in the middle
// 3) See Strings,palindromes,prefix,suffix etc -> KMP,Z algorithm

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

ll power( ll a, ll b ){
	ll res = 1;
	while( b > 0 ){
		if( b & 1 ) res = res*a % mod;
		a = a*a % mod;
		b >>= 1;
	}
	return res;
}

int main(){
	ll n; cin >> n;
	cout << ( ( power(10, n) - ( power(9, n) * 2 ) + mod + mod ) % mod + power(8, n) ) % mod << endl;
}

Measured memory_bytes: 3648
from typing import List


class DSU:
    def __init__(self, n: int) -> None:
        self._n = n
        self.parent_or_size = [-1] * n

    def merge(self, a: int, b: int) -> int:
        assert 0 <= a <= self._n
        assert 0 <= b <= self._n
        x, y = self.leader(a), self.leader(b)
        if x == y:
            return x
        if -self.parent_or_size[x] < -self.parent_or_size[y]:
            x, y = y, x
        self.parent_or_size[x] += self.parent_or_size[y]
        self.parent_or_size[y] = x
        return x

    def same(self, a: int, b: int) -> bool:
        assert 0 <= a <= self._n
        assert 0 <= b <= self._n
        return self.leader(a) == self.leader(b)

    def leader(self, a: int) -> int:
        assert 0 <= a < self._n
        while self.parent_or_size[a] >= 0:
            a = self.parent_or_size[a]
        return a

    def size(self, a: int) -> int:
        assert 0 <= a <= self._n
        return -self.parent_or_size[self.leader(a)]

    def groups(self) -> List[List[int]]:
        leader_buf = [self.leader(i) for i in range(self._n)]
        group_size = [0] * self._n
        for i in leader_buf:
            group_size[i] += 1
        result = [[] for _ in range(self._n)]
        for i in range(self._n):
            result[leader_buf[i]].append(i)
        result = [i for i in result if i]
        return result


n, q = map(int, input().split())
uf = DSU(n)
for i in range(q):
    t, u, v = map(int, input().split())
    if t:
        print(int(uf.same(u, v)))
    else:
        uf.merge(u, v)


Measured memory_bytes: 79380
#include <bits/stdc++.h>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;
typedef pair<int, int> P;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M, X;
  cin >> N >> M >> X;
  int C[N];
  int A[N][M];
  FOR(i,0,N) {
    cin >> C[i];
    FOR(j,0,M) {
      cin >> A[i][j];
    }
  }
  int money = 2e9;
  FOR(i,0,1<<N) {
    vector<int> rikaido(M, 0);
    int m = 0;
    FOR(j,0,N) {
      // 本jを買う
      if (i & (1 << j)) {
        m += C[j];
        FOR(k,0,M) {
          rikaido[k] += A[j][k];
        }
      }
    }
    bool ok = true;
    FOR(j,0,M) {
      if (rikaido[j] < X) {
        ok = false;
        break;
      }
    }
    if (ok) {
      money = min(m, money);
    }
  }
  cout << (money == 2e9 ? -1 : money) << endl;
}

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

using namespace std;
#define inputInt(a) int a; cin >> a; 
#define inputInt2(a,b) int a; int b; cin >> a >> b; 
#define inputInt3(a,b,c) int a; int b; int c; cin >> a >> b >> c;
#define inputLong(a) long a;cin >> a; 
#define inputIntArray(a,N) int a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputLongArray(a,N) long a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputIntArray2(a,b,N) int a[N]; int b[N]; for(int i=0;i<N;i++){cin >> a[i] >> b[i];}
#define output(answer) cout << answer << endl;
#define fN(i,N)    for(int i=0; i<N; i++)
#define fSE(i,s,e) for(int i=s; i<=e; i++)
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i,N) for(int i=0; i<N; i++)
#define cinv(v,N) vector<int> v(N); for(int i=0; i<N; i++){ cin >> v[i]; }
#define mt make_tuple
#define vll vector<long long int>
#define vvll vector<vector<long long int>>
#define all(v) (v).begin(),(v).end()
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main()
{
  //input
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll H; cin >> H;
  
  //main
  ll ans = H;
  ll tmp = 1;
  while(H>=1){
    if(H%2==0){
      ans += tmp;
    }
    tmp *= 2;
    H /= 2;
  }
  
  // output
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll a, b, s;
  in2(a, b);
  s = 0;
  rep(i, b - a)
    s += i;
  out(s - a);
  memi;
}

Measured memory_bytes: 256
/*
　　　  ∧＿∧　やあ
　　 （´・ω・｀)　　　　　/　　　　　ようこそ、バーボンハウスへ。
　　 ／∇y:::::＼　　　 [￣]　　　　　このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
　　 |:⊃:|:::::|　　　|──|
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|　うん、「また」なんだ。済まない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|￣　  仏の顔もって言うしね、謝って許してもらおうとも思っていない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣／|
　　　　∇　∇　∇　∇　　　／.／|　　　でも、この提出を見たとき、君は、きっと言葉では言い表せない
　　　　┴　┴　┴　┴　／ ／　  |　　　「ときめき」みたいなものを感じてくれたと思う。
￣￣￣￣￣￣￣￣￣￣|／　　  |　　　殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
￣￣￣￣￣￣￣￣￣￣　　　　 |　　　そう思って、この提出を投げたんだ。
　　　(⊆⊇)　(⊆⊇)　(⊆⊇)　　|
　    ||　　 ||　　||　　|　　　 じゃあ、判定を聞こうか。
　　.／|＼　／|＼ ／|＼
*/

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define mp make_pair
#define ALL(obj) (obj).begin(),(obj).end()
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n) 
#define SIZE(x) ((int)(x).size())
#define debug(x) cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef pair<int, int> pint;
typedef pair<lint, lint> plint;
typedef vector<lint> vec;
typedef vector<vector<lint>> matrix;
typedef priority_queue<lint> p_que;
typedef priority_queue<lint, vector<lint>, greater<lint>> p_que_rev;
const lint INF = INT_MAX;
const lint LINF = LLONG_MAX;
const lint MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};

lint gcd(lint a, lint b) {
    lint r;
    while (b != 0) {
        r = a % b;
        a = b; 
        b = r;
    }
    return a;
}

lint lcm(lint a, lint b) {
    return (a / gcd(a, b)) * b;
}

lint power(lint x, lint n, lint mod = MOD) {
    lint ret = 1;
    while(n > 0) {
        if(n & 1){
            (ret *= x) %= mod;
        }
        (x *= x) %= mod;
        n >>= 1;
    }
    return ret;
}

vector<lint> make_power(int n, lint base){
    lint num = 1;
    vector<lint> ret;
    for (int i=0; i<=n; ++i){
        ret.push_back(num);
        num *= base;
    }
    return ret;
}

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    string w;
    cin >> w;
    int cnt[26];
    REP(i, 26){
        cnt[i] = 0;
    }
    REP(i, w.length()){
        cnt[w[i] - 'a']++;
    }
    bool isEven = true;
    REP(i, 26){
        if(cnt[i] % 2 == 1){
            isEven = false;
            break;
        }
    }
    cout << ((isEven) ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
a,b,c,d = map(int,input().split())

if(a>= 0 and c>= 0):
    print(b*d)
elif(b<=0 and d<=0):
    print(a*c)
elif(a>=0 and d<=0):
    print(a*d)
elif(b<=0 and c>=0):
    print(b*c)
elif(a*c >= b*d):
    print(a*c)
elif(a*c < b*d):
    print(b*d)







Measured memory_bytes: 9140
#include "bits/stdc++.h"
#define ll unsigned long long
#define PI 3.1415926535897932384626433832795l
#define MAX_NUM 1000000000
using namespace std;
template <typename T> inline T __lcm(T a,T b)
{
    return (a*b)/__gcd(a,b);
}

ll weight[1000005];
ll cost[1000005];
ll dp[101][100005];
bool dpbool[101][100005];
ll n,w;

ll knapsack(ll position, ll weight_used)
{
    if(position>=n)
    {
        return 0;
    }
    if(dpbool[position][weight_used])
    {
        return dp[position][weight_used];
    }
    ll profit1,profit2;
    if(weight_used+weight[position]<=w)
    {
        profit1=cost[position]+knapsack(position+1,weight_used+weight[position]);
    }
    else
    {
        profit1=0;
    }
    profit2=knapsack(position+1,weight_used);
    dp[position][weight_used]=max(profit1,profit2);
    dpbool[position][weight_used]=true;
    return dp[position][weight_used];
}

int main()
{
    cin>>n>>w;
    for(int i=0;i<n;i++)
    {
        cin>>weight[i]>>cost[i];
    }
    memset(dpbool, false, sizeof(dpbool[0][0]) * 101 * 100005);
    ll ans=knapsack(0,0);
    printf("%llu\n",ans);
}

Measured memory_bytes: 92416
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <unordered_map> 
#include <map> 
#include <numeric>
#include <limits>
#include <utility>
#include <queue>
#include <random>
#include <bitset>
#include <memory>
#include <complex>
using namespace std;
typedef long long LL;

int main(void)
{
	int n,ans=0;
	cin >> n;
	vector<int> p(n);
	for (int i = 0; i < n; i++) {
		cin >> p[i];
	}

	for (int i = 1; i < n-1; i++) {
		vector<int> dst(3);
		dst[0]=p[i-1];
		dst[1] = p[i];
		dst[2] = p[i + 1];
		sort(dst.begin(),dst.end());
		if (dst[1] == p[i]) {
			ans++;
		}
	}
	cout <<ans<<endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int now = 1;
		for(int i = 0 ; i < n ; i++) {
			if(now < k)
				now *= 2;
			else
				now += k;
		}

		sc.close();
		System.out.println(now);

	}
}



Measured memory_bytes: 35720
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
const long double eps = 1e-12;
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL
#define MOD 998244353LL
#define seg_size 262144*2
#define REP(a,b) for(long long a = 0;a < b;++a)
long long mae[2000000];
long long gyaku[2000000];
long long powing(long long a, long long b) {
	long long ans = 1;
	while (b != 0) {
		if (b % 2 == 1) {
			ans *= a;
			ans %= MAX_MOD;
		}
		a *= a;
		a %= MAX_MOD;
		b /= 2;
	}
	return ans;
}
long long inv(long long now) {
	return powing(now, MAX_MOD - 2LL);
}
long long combination(long long a, long long b) {
	long long ans = mae[a];
	ans *= gyaku[a - b];
	ans %= MAX_MOD;
	ans *= gyaku[b];
	ans %= MAX_MOD;
	return ans;
}
int main() {
	long long a, b, c;
	cin >> a >> b >> c;
	mae[0] = 1;
	gyaku[0] = 1;
	for (long long i = 1; i <= a+b+c; ++i) {
		mae[i] = mae[i - 1] * i;
		mae[i] %= MAX_MOD;
		gyaku[i] = inv(mae[i]);
	}
	long long ans = 0;
	long long geko = 0;
	long long l = 0;
	long long r = 0;
	for (long long i = a; i <= a + (b) + (c); ++i) {
		long long first_multiply = powing(3LL, a + b + c - i);
		first_multiply *= combination(i-1, a-1);
		first_multiply %= MAX_MOD;
		long long second_multiply = powing(2LL, i - a);
		r *= 2LL;
		l *= 2LL;
		if (i >= a + b + 1) l += combination(i - a - 1, i - a - b - 1);
		if (i >= a + c + 1) r += combination(i - a - 1, i - a - c - 1);
		r %= MAX_MOD;
		l %= MAX_MOD;

		second_multiply += (MAX_MOD - ((l) % MAX_MOD)) % MAX_MOD;
		second_multiply += (MAX_MOD - ((r) % MAX_MOD)) % MAX_MOD;
		/*
		for (long long q = 0; q <= b; ++q) {
			long long geko = i - a - q;
			if (geko < 0) break;
			if (geko > c)continue;
			second_multiply += combination(i-a,q);
			second_multiply %= MAX_MOD;
		}
		*/
		ans += first_multiply * second_multiply;
		ans %= MAX_MOD;
	}
	cout << ans << endl;
}

Measured memory_bytes: 18688
def solve():
    n = int(input())
    sp = list(list(input().split()) for _ in range(n))
    ans = sorted(enumerate(sp), key=lambda x: (x[1][0], -int(x[1][1])))
    for d in ans:
        print(d[0] + 1)


if __name__ == "__main__":
    solve()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


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

  int a,b;
  cin >> a >> b;
  cout << max(a- 2*b,0) << endl;
  
  return 0;
    

}


Measured memory_bytes: 256
n, m = map(int, input().split())
left = 0
right = n+1
for i in range(m):
    l, r = map(int, input().split())
    left = max(left, l)
    right = min(right, r)
ans = 0
for i in range(left-1, right):
    ans += 1
print(ans)


Measured memory_bytes: 3188
import sys

r, g, b = map(int, sys.stdin.readline().split())
k = int(sys.stdin.readline())

for i in range(k):
    if not r < g:
        g *= 2
    elif not g < b:
        b *= 2

if r < g and g < b:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 9140
/*
   ЗАПУСКАЕМ СТЕНУ ИЗ КРЕМА
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
*/

#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <iomanip>

using namespace std;

typedef long long ll;

mt19937 rnd(228);

int main()
{
#ifdef ONPC
    freopen("a.in", "r", stdin);
#endif
    string s;
    cin >> s;
    int n = (int) s.size();
    vector <int> cnt(26);
    ll ans = 1;
    for (int i = n - 1; i >= 0; i--)
    {
        s[i] -= 'a';
        for (int j = 0; j < 26; j++)
        {
            if (s[i] != j)
            {
                ans += cnt[j];
            }
        }
        cnt[s[i]]++;
    }
    cout << ans << '\n';
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
using namespace  std;
int w, h;
int field[30][30];
int dx[] = {0,0,1,-1};
int dy[] = {1,-1,0,0};
int sy, sx, gy, gx;
bool in(int y,int x)
{
	if (y < 0 || x < 0 || y >= h || x >= w)return false;
	return true;
}
int dfs(int y, int x, int count)
{
	if (count > 10)return 11;
	if (count <= 10 && y == gy && x == gx)return count;
	int ret = 11;
	for (int i = 0; i < 4; i++)
	{
		int ny = y + dy[i];
		int nx = x + dx[i];
		if (!in(ny, nx))continue;
		if (field[ny][nx] == 1)continue;
		if (field[ny][nx] == 3)return count + 1;
		while (in(ny + dy[i], nx + dx[i]) && field[ny + dy[i]][nx + dx[i]] == 0)
		{
			ny += dy[i];
			nx += dx[i];
		}
		if (!in(ny + dy[i], nx + dx[i]) && field[ny][nx] == 0)continue;
		if (in(ny + dy[i], nx + dx[i]))
		{
			if (ny + dy[i] == gy && nx + dx[i] == gx)
			{
				return count + 1;
			}
			else
			{
				field[ny + dy[i]][nx + dx[i]] = 0;
				ret = min(ret, dfs(ny, nx, count + 1));
				field[ny + dy[i]][nx + dx[i]] = 1;
			}
		}
	}
	return ret;
}
int main()
{
	while (cin >> w >> h && w != 0 || h != 0)
	{
		for (int i = 0; i < h; i++)
		{
			for (int j = 0; j < w; j++)
			{
				cin >> field[i][j];

				if (field[i][j] == 2)
				{
					sy = i;
					sx = j;
					field[i][j] = 0;
				}
				else if (field[i][j] == 3)
				{
					gy = i;
					gx = j;
				}
			}
		}

		int ans = dfs(sy,sx,0);
		if (ans == 11)cout << -1 << endl;
		else cout << ans << endl;
	}
	return 0;
}

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

int main() {
    int H, N;
    std::cin >> H >> N;

    int A;
    for (int i = 0; i < N; ++i) {
        std::cin >> A;
        H -= A;
        if (H <= 0) {
            std::cout << "Yes\n";
            return 0;
        }
    }

    std::cout << "No\n";

    return 0;
}


Measured memory_bytes: 256
def resolve():
    n = int(input())
    d, x = map(int, input().split())
    a = [int(input()) for i in range(n)]

    count = 0
    for i in a:
        m = 0
        while i * m + 1 <= d:
            m += 1
        count += m

    print(count + x)

if __name__ == "__main__":
    resolve()

Measured memory_bytes: 38640
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<ll, int> P;
typedef tuple<int, int, int> T;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n;
int a[200100];

void solve() {
    map<int, ll> m;
    for (int i = 0; i < n; i++) {
        m[a[i]]++;
    }
    ll sum = 0;
    for (auto v : m) {
        sum += v.second * (v.second-1) / 2;
    }

    for (int i = 0; i < n; i++) {
        const ll v = m[a[i]];
        cout << sum - v * (v-1) / 2 + (v-1) * (v-2) / 2 << endl;
    }
}

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

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

    input();
    solve();
}


Measured memory_bytes: 11896
n=int(input())
a=sorted(list(map(int,input().split())))
mod=10**9+7
if n%2==1:
    for i in range(n):
        if a[i]!=2*((i+1)//2):
            print(0)
            exit()
    print((2**(n//2))%mod)
else:
    for i in range(n):
        if a[i]!=(((i//2)+1)*2)-1:
            print(0)
            exit()
    print((2**(n//2))%mod)

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

int main(){
  string S;
  cin >> S;
  int L=S.size();
  string ans="Yes";
  for(int i=0; i<L; i++){
    if(i%2==0 && S.at(i)=='L'){
      ans="No";
      break;
    }
    if(i%2!=0 && S.at(i)=='R'){
      ans="No";
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
//Name: Carpet
//Level: 2
//Category: ヒストグラム,矩形数え上げ
//Note:

/**
 * x方向に見ていくと、ヒストグラムを何枚の矩形で覆えるかという問題になる。
 * 枚数を最小化するためには、y座標を固定してx方向にスキャンし、連続している区間を1枚のカーペットで覆った上で
 * y方向に同じ長さのカーペットが隣接していればマージする、という操作を行えばよいことがわかる。
 *
 * ナイーブに実装するとO(AN)かかるが、現在の高さと、その高さが終わったときにどの高さに復帰するかという履歴をスタックでもつことにより、
 * y座標が一気に2以上変化する箇所もまとめて扱うことができる。
 * オーダーは O(N)。
 */
#include <iostream>
#include <stack>

using namespace std;

bool solve() {
    int N;
    if(!(cin >> N)) return false;

    stack<int> stk;
    int ans = 0;
    for(int i = 0; i < N; ++i) {
        int a;
        cin >> a;
        while(stk.size() > 0 && stk.top() > a) {
            ++ans;
            stk.pop();
        }
        if(stk.size() == 0 || stk.top() != a) stk.push(a);
    }
    ans += stk.size();
    cout << ans << endl;
    return true;
}

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

    while(solve()) ;
    return 0;
}

Measured memory_bytes: 1804
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;typedef vector<pl> vp;
#define fore(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);++i)
#define rep(i,n) fore(i,0,(n)-1)
#define rfore(i,a,b) for(ll i=(ll)(b);i>=(ll)(a);--i)
#define rrep(i,n) rfore(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
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;}

ll M=12000;
ll org=M/2;
bool f(string &s,string &t,ll si,ll ti){
    if(si<0||si>=s.size()||ti<0||ti>=t.size())return 1;
    if(s[si]==t[ti])return 1;
    if(s[si]=='?'||t[ti]=='?')return 1;
    return 0;
}
vector<bool> g(string &s,string &t){
    vector<bool> ret(M,1);
    rep(i,M){
        rep(j,s.size()){
            ret[i]=ret[i]&f(s,t,j,j+org-i);
        }
    }
    return ret;
}
void solve(std::string a, std::string b, std::string c){
    vector<bool> okab=g(a,b);
    vector<bool> okbc=g(b,c);
    vector<bool> okac=g(a,c);

    ll na=a.size(),nb=b.size(),nc=c.size();

    ll ans=na+nb+nc;
    rep(i,M)rep(j,M){
        if(!okab[i]||!okbc[j])continue;
        ll k=org+(i-org)+(j-org);
        bool ok=k>=0&&k<M&&okac[k];
        if(ok){
            ll mi=min(0LL,min(i-org,i-org+j-org));
            ll ma=max(na,max(i-org+nb,i-org+j-org+nc));
            chmin(ans,ma-mi);
        }
    }
    cout<<ans<<endl;
}

int main(){
    std::string a;
    std::cin >> a;
    std::string b;
    std::cin >> b;
    std::string c;
    std::cin >> c;
    solve(a, b, c);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	long long n;
	cin >> n;
	long long x,y;
	x = (long long)n / 50;
	y = (long long)n % 50;
	cout << 50 << endl;
	for (int i = 0;i < 50;i++) {
		if (i < y)
			cout << (long long)x + 99-y;
		else
			cout << (long long)x + 49 - y;
		if (i != 49)
			cout << " ";
	}
	cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;
typedef long long llint;

llint a,b;

void solve(){
	cin >> a >> b;
	if(a>=9 || b>=9){
		cout << ":(" << endl;
	}
	else{
		cout << "Yay!" << endl;
	}
}

int main(int argc, char *argv[]) {
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

#define N 10000
#define Q 500
#define S 1000000000
#define T 1000000000

int LSearch(int,int,int*);

int main(){
  int i,n[N],q[Q],non,noq,ans=0;

  scanf("%d",&non);
  for(i=0;i<non;i++){
    scanf("%d",&n[i]);
  }
  scanf("%d",&noq);
  for(i=0;i<noq;i++){
    scanf("%d",&q[i]);
  }

  for(i=0;i<noq;i++){
    ans += LSearch(q[i],non,n);
  }

  printf("%d\n",ans);
  
  return 0;
}

int LSearch(int voq,int non,int* n){
  int i;
  for(i=0;i<non;i++){
    if(n[i] == voq){
      return 1;
    }
  }
  return 0;
}


		  



Measured memory_bytes: 2128
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int a = 0;
    int b = 0;

    scanf("%d%d", &a, &b);
    
    int diff = b - a;

    int height_east = (1 + diff) * diff / 2;

    int ans = height_east - b;

    printf("%d", ans);

    return 0;
}

Measured memory_bytes: 128
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

alias S = Tuple!(int, "t", long, "d");

void main()
{
    auto nk = readln.split.to!(int[]);
    auto N = nk[0];
    long K = nk[1];
    S[] ss;
    foreach (_; 0..N) {
        auto td = readln.split.to!(int[]);
        ss ~= S(td[0], td[1]);
    }
    sort!"a.t == b.t ? a.d > b.d : a.t < b.t"(ss);
    long[] ts, os;
    int last = -1;
    foreach (s; ss) {
        if (s.t != last) {
            last = s.t;
            ts ~= s.d;
        } else {
            os ~= s.d;
        }
    }
    sort!"a > b"(ts);
    foreach (i; 1..ts.length) ts[i] += ts[i-1];
    sort!"a > b"(os);
    foreach (i; 1..os.length) os[i] += os[i-1];

    long max_d;
    foreach (k; 1..K+1) {
        if (ts.length < k) continue;
        if (os.length < K-k) continue;
        max_d = max(max_d, k*k + ts[k-1] + (K-k == 0 ? 0 : os[K-k-1]));
    }
    writeln(max_d);
}

Measured memory_bytes: 5244
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;

    set<int> st;
    int A;
    int cnt[200010] = {};
    rep(i, N) {
        cin >> A;
        st.insert(A);
        cnt[A]++;
    }
    K = st.size() - K;
    sort(cnt, cnt + 200010);
    int ans = 0;
    rep(i, 200010) {
        if (cnt[i] == 0) continue;
        if (K > 0) {
            ans += cnt[i];
            K--;
        } else break;
    }
    cout << ans << endl;



    return 0;
}


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

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    int N;
    cin >> N;
    double sum = 0;
    for (int i = 0; i < N; i++) {
        double a; string s;
        cin >> a >> s;
        if (s == "BTC") {
            a *= 380000;
        }
        sum += a;
    }
    cout << sum << endl;
}

int main() {
    #ifdef LOCAL_ENV
    cin.exceptions(ios::failbit);
    #endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    
    solve();
}

Measured memory_bytes: 256
// AUTHOR : Kishan Srivastav
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define in freopen("input.txt", "r", stdin)
#define out freopen("output.txt", "w", stdout)
#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
ll gcd(ll a,ll b){ if(b==0) return a;    return gcd(b,a%b);}
ll lcm(ll a,ll b) { return (a/gcd(a,b)*b);}

int main() {
	ios
#ifndef ONLINE_JUDGE
	in;
	out;
#endif
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	ll n1 = a*c;
  	ll n2 = a*d;
  	ll n3 = b*c;
  	ll n4 = b*d;
 
  cout << max(n1, max(n2, max(n3, n4))) << endl;
	
}

Measured memory_bytes: 3408