akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;
//import java.util.Map.Entry;
//import java.util.stream.*;
//import java.math.*;

public class Main {

    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        Scanner sc = new Scanner(System.in);
        long MOD = (long) (Math.pow(10, 9) + 7);
        int n = sc.nextInt();
        int m = sc.nextInt();
        long ans = 1;
        if (Math.abs(n - m) <= 1) {
            for (long i = 1; i <= n; i++) {
                ans = (ans * i) % MOD;
            }
            for (long i = 1; i <= m; i++) {
                ans = (ans * i) % MOD;
            }
            if (n == m) {
                ans = (ans * 2) % MOD;
            }
        } else {
            ans = 0;
        }
        System.out.println(ans);

        bw.flush();
    }
//==============================================//
//==============================================//
//==============================================//
//==============================================//
//==============================================//
//==============================================//
//==============================================//
//==============================================//

    static class Pair implements Comparable<Pair> {

        int a, b;

        public Pair(int x, int y) {
            a = x;
            b = y;
        }

        @Override
        public int compareTo(Pair p) {
            return a - p.a;
        }
    }

    static void forl_0(int n, int[] array, Scanner sc) {
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }
    }

    static void forl_1(int n, int[] array, Scanner sc) {
        for (int i = 1; i <= n; i++) {
            array[i] = sc.nextInt();
        }
    }

    static void two_d(int n, int m, int[][] array, Scanner sc) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                array[i][j] = sc.nextInt();
            }
        }
    }

    static boolean isPrime(long n) {
        if (n < 2) {
            return false;
        } else if (n == 2 || n == 3) {
            return true;
        } else if (n % 2 == 0 || n % 3 == 0) {
            return false;
        }
        long sqrtN = (long) Math.sqrt(n) + 1;
        for (long i = 6L; i <= sqrtN; i += 6) {
            if (n % (i - 1) == 0 || n % (i + 1) == 0) {
                return false;
            }
        }
        return true;
    }

    public static long gcd(long a, long b) {
        return (b == 0) ? a : gcd(b, a % b);
    }

    public static long lcm(long a, long b) {
        return a / gcd(a, b) * b;
    }
}


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

int main(void) {
  string s;
  cin >> s;
  int ans = 0;
  if (s[0] == '1') ++ans;
  if (s[1] == '1') ++ans;
  if (s[2] == '1') ++ans;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    for(int i=1;i<=b;i++)
    {
        if(i*a%b==c)
        {
            printf("YES\n");
            return 0;
        }
    }
    printf("NO\n");
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  int n, m;
  cin >> n >> m;
  int k[10], s[10][10], p[10];
  for (int i = 0; i < m; i++){
    cin >> k[i];
    for(int j=0; j<k[i]; j++){
      cin >> s[i][j];
      s[i][j]--;
    }
  }
  for(int i=0; i<m; i++){
    cin >> p[i];
  }
  int ans = 0;
  bool flag = true;
  for (int bit = 0; bit < (1 << n); bit++){
    for (int i = 0; i < m; i++){
      int count = 0;
      for(int j=0; j<k[i]; j++){
        if(bit & (1<<s[i][j])){
          count++;
        }
      }
      if(count %2 == p[i]){
        flag = true;
        continue;
      }else{
        flag = false;
        break;
      }
    }
    if(flag) ans++;
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    char S[26];
    int i=0;
    while(cin>>S[i++]);
    sort(S,S+i);
    bool ans=true;
    for(int j=0; j<i; j++){
        if(S[j]==S[j+1])ans=false;
    }
    if(ans)cout<<"yes\n";
    else cout<<"no\n";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;

int modpow(int base,int n){
	int res=1;
	while(n){
		if(n&1)res=1L*res*base%mod;
		base=1L*base*base%mod;
		n>>=1;
	}
	return res;
}

int comb(int n,int a){
	int up=1,lo=1;
	for(int i=0;i<a;++i){
		up=1L*up*(n-i)%mod;
		lo=1L*lo*(i+1)%mod;
	}
	return 1L*up*modpow(lo,mod-2)%mod;
}

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n,a,b; cin>>n>>a>>b;
	cout<<(0L+mod+mod+modpow(2,n)-1-comb(n,a)-comb(n,b))%mod<<"\n"s;
}


Measured memory_bytes: 3520
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel.Design;
using System.Globalization;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Schema;
using static System.Console;

namespace ConsoleApp2
{
    class Program
    {
        static public int[] Sarray() { return ReadLine().Split().Select(int.Parse).ToArray(); }
        static public List<int> Slist() { return new List<int>(ReadLine().Split().Select(int.Parse)); }
        static void Main(string[] args)
        {
            var NK = Sarray();
            var N = NK[0];
            var K = NK[1];
            double ans = 0;
            for(var i=1;i<=N;i++)
            {
                double p = 1;
                var x = i;
                while(x<K)
                {
                    p *= 0.5;
                    x *= 2;
                }
                ans += p / N;
            }
            WriteLine(ans);
        }
    }
}


Measured memory_bytes: 19692
import java.util.*;
public class Main {

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      long k = sc.nextLong();
      int[] arr = new int[n+1];
      for(int i = 1; i <= n; i++)
        arr[i] = sc.nextInt();

      int fast = 1;
      int slow = 1;
      while(true) {
        fast = arr[arr[fast]];
        slow = arr[slow];
        if(fast == slow) break;
      }

      long moves = 0;
      int sp = slow;
      do {
        slow = arr[slow];
        moves++;
      } while(sp != slow);

      fast = 1;
      while(fast != slow && k > 0) {
        fast = arr[fast];
        slow = arr[slow];
        k--;
      }

      k %= moves;
      while(k > 0) {
        fast = arr[fast];
        k--;
      }
      System.out.println(fast);
  }
}


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

int main()
{
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i, 0, h) cin >> s[i];
    rep(i, 0, h){
        if(i == 0){
            rep(k, 0, w+2) cout << '#';
            cout << endl;
        }
        cout << '#';
        rep(j, 0, w){
            cout << s[i][j];
        }
        cout << '#' << endl;
        if(i == h-1){
            rep(k, 0, w+2) cout << '#';
            cout << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <class T> using treap = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long
#define REP(i, n) for (long long i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (long long i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) begin(obj), end(obj)
#define RALL(obj) rbegin(obj), rend(obj)
#define fi first
#define se second
using ii = pair<int, int>;
vector<ii> dirs = {
  {1, 0}, {0, 1}, {-1, 0}, {0, -1},  // 4方向
  {1, 1}, {-1, 1}, {-1, -1}, {1, -1},  // 斜め
  {0, 0},  // 自身
};
template <class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template <class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <class T, class S> vector<T> make_vec(size_t n, S x) { return vector<T>(n, x); }
template <class T, class... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(n, make_vec<T>(ts...)); }

// debug
template <class T> ostream& operator<<(ostream& s, vector<T>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : " "); return s; }
template <class T> ostream& operator<<(ostream& s, vector<vector<T>>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : "\n"); return s; }
template <class T, class S> ostream& operator<<(ostream& s, pair<T, S>& p) { s << "{" << p.first << ", " << p.second << "}"; return s; }
template <class T, class S> ostream& operator<<(ostream& s, map<T, S> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
template <class T, class S> ostream& operator<<(ostream& s, unordered_map<T, S> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
#ifdef _MY_DEBUG
  #define dump(...) cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), cerr << "*/\n\n";
#else
  #define dump(...)
  #define endl "\n"
#endif
void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head&& h, Tail&&... t) { cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...); }

struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); } } fast;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
constexpr int MOD = 1000000007;
// *************** TEMPLATE END *************** 

const int K = 2e5 + 10;
signed main() {
  int n, m; cin >> n >> m;
  vector<int> A(n); REP (i, n) cin >> A[i];
  unordered_map<int, int> B;
  REP (i, m) {
    int x; cin >> x;
    B[x]++;
  }
  vector<int> acc(K, m);
  acc[0] = 0;
  
  for (auto p : B) {
    for (int j = p.fi; j < K; j += p.fi) {
      acc[j] -= p.fi * p.se;
    }
  }

  REP (i, K - 1) acc[i + 1] += acc[i];
  int ans = 0;
  for (int a : A) ans += acc[a];
  cout << ans << endl;
}



Measured memory_bytes: 14020
from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))
A.sort()
d = defaultdict(int)
for a in A:
    d[a] += 1
ans = 0

for i in range(N-1, -1, -1):
    a = A[i]
    if d[a] == 0:
        continue
    s = 2**(len(bin(a))-2)
    p = s-a
    if (d[p] > 0 and p!=a) or d[p]>1:
        ans += 1
        d[p] -= 1
        d[a] -= 1
print(ans)



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

using namespace std;

typedef pair<int, int> PII;

int main() {
	int n, m;
	scanf("%d %d", &n, &m);
	vector<PII> a;
	for (int i = 0; i < m; i++) {
		int x, y;
		scanf("%d %d", &x, &y);
		a.push_back(make_pair(x, 0));
		a.push_back(make_pair(y, -x));
	}
	sort(a.begin(), a.end());
	int pre = 0, ans = 0;
	for (int i = 0; i < a.size(); i++) {
		int pos = -a[i].second;
		if (pos) {
			if (pos >= pre) {
				pre = a[i].first;
				ans++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
  int N,W;
  cin >> N >> W;
  int w[N];
  int v[N];
  for(int i=0; i<N; i++){
    cin >> v[i] >> w[i];
  }

  int DP[N+1][W+1];

  for(int j=0; j<=W; j++){
    DP[0][j]=0;
  }

  for(int i=1; i<=N; i++){
    for(int j=0; j<=W; j++){
      if(j<w[i-1]){
        DP[i][j] = DP[i-1][j];
      }else{
        if(DP[i-1][j] > DP[i-1][j-w[i-1]]+v[i-1]){
          DP[i][j] = DP[i-1][j];
        }else{
          DP[i][j] = DP[i-1][j-w[i-1]]+v[i-1];
        }
      }
    }
  }

  cout << DP[N][W] << endl;

  return 0;
}


Measured memory_bytes: 7016
import numpy as np
N, M = map(int, input().split())
AB = []
H = [int(h) for h in input().split()]
Hall = [1] * N
 
# print(H)
for i in range(M):
    a, b = map(int, input().split())
    AB.append([a, b])
    AH = H[a - 1]
    BH = H[b - 1]
    if AH >= BH:
        Hall[b - 1] = 0
    if BH >= AH:
        Hall[a - 1] = 0
 
 
print(Hall.count(1))

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



#define ll          long long
#define pb          push_back
#define PI 3.14159265
#define float double
using namespace std;

float sine(float theta){
    return sin(PI*theta/180);
}
float cosine(float theta){
    return sqrt(1-sine(theta)*sine(theta));
}
float tangent(float theta){
    return sine(theta)/cosine(theta);
}
int main(){
    float a,b,x;
    float t;
    //cout<<tr<<endl;
    cin>>a>>b>>x;
    cout<<setprecision(10);
    float tr = a/b;
    float h = 90.0;
    float m,l = 0.0;
    float mm = -1;
    while(l<h){
        m = l+ (h-l)/2;
        if(mm==m) break;
        //cout<<l<<' '<<m<<' '<<h<<endl;
        float vol;
        if(tangent(m)<=tr){
            //cout<<"dum"<<endl;
            vol = (b*b*a*tangent(m))/2;
        }
        else{
            vol = (a*a*a)/(2*tangent(m));
            vol+= a*a*(b-(a/tangent(m)));
        }
        if(vol<x){
            l = m;
        }
        else{
            h = m;
        }
        mm = m;
    }
    cout<<90-m<<endl;
}

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

int N, M;
int k[11];
int s[11][11];
int p[11];

int main(){	
  	cin >> N >> M;
  	for(int i=0; i<M; i++){
    	cin >> k[i];
        for(int j=0; j<k[i]; j++){
        	cin >> s[i][j];
          	s[i][j]--;
        }
    }
    for(int i=0; i<M; i++){
    	cin >> p[i];
    }
  	int ans = 0;
  	for (int i=0; i<(1<<N); i++){
      	bitset<11> bit(i);
      	int cnt = 0;
        for(int j=0; j<M; j++){
          	int tmp=0;
         	for(int l=0; l<k[j]; l++){
            	if(bit[s[j][l]]){
            		tmp++;
            	}
            }
          	if(tmp % 2 == p[j]){
            	cnt++;
            }
        }
      	if(cnt == M) ans++;
    }
    cout << ans << endl; 
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	
	if(b <= c){
		if(c-a-b < 0){
			cout<<"0"<<endl;
			return 0;
		}
		cout<<c-a-b<<endl;
		return 0;
	}
	cout<<b-a-c<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b); (i) >= (a); --(i)) //Reversi for
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}

int main()
{
    string n;
    int ans = 0;
    cin >> n;
    rep(i, 4)if(n[i] == '2')ans++;
    cout << ans << endl;;
    return 0;
}

Measured memory_bytes: 256
import heapq
N = int(input())
A = sorted([int(x) for x in input().split()], reverse=True)
a = A.pop(0)
h = []
heapq.heappush(h, (-a, (a, a)))
ans = 0
for a in A:
    score, (a1, a2) = heapq.heappop(h)
    ans += (-score)
    s1 = min(a, a1)
    s2 = min(a, a2)
    heapq.heappush(h, (-s1, (a, a1)))
    heapq.heappush(h, (-s2, (a, a2)))
print(ans)


Measured memory_bytes: 126804
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define nl cout<<endl
 
#define pii pair<ll,ll>
#define vi  vector<ll>
#define vii vector<pii>
#define mi  map<ll,ll>
#define all(a)  (a).begin(),(a).end()
 
#define pb push_back
#define ff first
#define ss second
#define hell 1000000007
 
#define test4(x,y,z,a) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<"		a is "<<a<<endl;
#define test3(x,y,z) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<endl;
#define test2(x,y) cout<<"x is "<<x<<"		y is "<<y<<endl;
#define test1(x) cout<<"x is "<<x<<endl;
#define N 300009
 
ll power(ll a,ll b,ll m)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%m;
		b/=2;
		a=(a*a)%m;
	}
	return ans;
}
int main()
{	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	string s;cin>>s;
	ll q;cin>>q;
	ll cnt=0;

	string start="",endd="";
	while(q--)
	{
		ll t;cin>>t;
		if(t&1)
		{
			cnt++;
		}
		else
		{
			ll x;cin>>x;
			char c;cin>>c;
			if(cnt%2==0)
			{
				if(x==1)
				start=c+start;
				else
				endd+=c;
			}
			else
			{
				if(x==1)
				endd+=c;
				else
				start=c+start;
			}
		}
	}
	s=start+s+endd;
	if(cnt%2)
	reverse(all(s));
	cout<<s<<endl;
}

Measured memory_bytes: 1316
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;

class DICE{
private:
	int D[6];//??????????????????
	
public:
	DICE();
	void set(int*);
	int show();
	void roll(char);
	void change(int);
};


//???????????????????????????????????????????????????
DICE::DICE(){
	
	for(int i = 0; i < 6; ++i){
		D[i] = i+1;
	}
}



//??????????????????????????´=========================================
void DICE::set(int *number){
	
	for(int i = 0; i < 6; ++i){
		D[i] = number[i];
	}
}



//??????????????????????????¨???=========================================
int DICE::show(){
	
	return D[0];
}



//?????????????????¢??????===========================================
void DICE::roll(char order){
	
	int exchange;
		
	if(order == 'N'){//???????????????1????????¢??????
		exchange = D[0];
		D[0] = D[1];
		D[1] = D[5];
		D[5] = D[4];
		D[4] = exchange;
	}
		
	if(order == 'S'){//???????????????1????????¢??????
		exchange = D[0];
		D[0] = D[4];
		D[4] = D[5];
		D[5] = D[1];
		D[1] = exchange;
	}

	if(order == 'E'){//??±????????????1????????¢??????
		exchange = D[0];
		D[0] = D[3];
		D[3] = D[5];
		D[5] = D[2];
		D[2] = exchange;
	}

	if(order == 'W'){//?\?????????????1????????¢??????
		exchange = D[0];
		D[0] = D[2];
		D[2] = D[5];
		D[5] = D[3];
		D[3] = exchange;
	}
}



//??????????????´==================================================
void DICE::change(int n){
	
	for(int i = 0; i < 5; ++i){
		
		if(D[0] == n)	{ break; }
		if(i % 2 == 0)	{ roll('N'); }
		if(i % 2 == 1)	{ roll('W'); }
	}
}





int main(){
	
	int number[6];
	int n, x, y;
	DICE dice;
	
	//???????????????????????\???======================
	for(int i = 0; i < 6; ++i){
		cin >> number[i];
	}
	dice.set(number);
	
	
	//??????===================================
	cin >> n;
	
	for(int i = 0; i < n; ++i){
		
		cin >> x >> y;
		
		
		dice.change(x);
		dice.roll('N');
		
		
		while(1){
			if(dice.show() == y) break;
			dice.roll('W');
		}
		
		
		dice.roll('W');
		cout << dice.show() << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
 
using namespace std;
 
#define endl '\n'
#define f first
#define s second
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using ld = long double;
using ll = long long;
using pii = pair <int,int>;
using pll = pair <ll,ll>;
using vi = vector <int>;
using vll = vector <ll>;
using vpii = vector <pii>;
using vpll = vector<pll>;
using vs = vector <string>;


int main(){
  fastio;

  ll x,k,d;

  cin >> x >> k >> d;
  x = abs(x);
  ll k2 = x/d;

  x -= min(k2,k)*d;

  if(k2 < k){
    ll m = (k2%2 != k%2);
    x = min(abs(x-m*d),abs(x+m*d));
  }

  cout << abs(x) << endl;
  
  return 0;
}

Measured memory_bytes: 3644
#include<cstdio>

int k,s;
int ans;

int main()
{
	scanf("%d %d",&k,&s);
	for(int i = 0;i <= k; i++){
		for(int j = 0;j <= k; j++){
			if((s - i - j <= k) && (s - i - j >= 0)) ans++;
		}
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 128
n,p = map(int,input().split())

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

ans = 1
for i, j in pfact(p).items():
	ans *= i**(j//n)
print(ans)

Measured memory_bytes: 9452
import sys
from collections import defaultdict

# https://ikatakos.com/pot/programming_algorithm/data_structure/union_find_tree
class UnionFind:
    def __init__(self, n):
        # 負  : 根であることを示す。絶対値はランクを示す
        # 非負: 根でないことを示す。値は親を示す
        self.table = [-1] * n

    def _root(self, x):
        stack = []
        tbl = self.table
        while tbl[x] >= 0:
            stack.append(x)
            x = tbl[x]
        for y in stack:
            tbl[y] = x
        return x

    def find(self, x, y):
        return self._root(x) == self._root(y)

    def union(self, x, y):
        r1 = self._root(x)
        r2 = self._root(y)
        if r1 == r2:
            return
        # ランクの取得
        d1 = self.table[r1]
        d2 = self.table[r2]
        if d1 <= d2:
            self.table[r2] = r1
            if d1 == d2:
                self.table[r1] -= 1
        else:
            self.table[r1] = r2

    def friend_candidate(self):
        tbl = self.table
        n = len(tbl)
        candidates = [0] * n
        root = [-1] * n
        for i, parent in enumerate(tbl):
            if parent >= 0:
                root[i] = self._root(parent)
                candidates[root[i]] += 1
        for i in range(n):
            if tbl[i] >= 0:
                candidates[i] = candidates[root[i]]
        return candidates


def main():
    input = sys.stdin.buffer.readline
    n, m, k = map(int, input().split())
    uf = UnionFind(n)
    num_friends = [0] * n
    for _ in range(m):
        a, b = map(lambda x: int(x) - 1, input().split())
        uf.union(a, b)
        num_friends[a] += 1
        num_friends[b] += 1
    num_block = [0] * n
    for _ in range(k):
        c, d = map(lambda x: int(x) - 1, input().split())
        if uf.find(c, d):
            num_block[c] += 1
            num_block[d] += 1
    fc = uf.friend_candidate()
    ans = [0] * n
    for i in range(n):
        ans[i] = fc[i] - num_friends[i] - num_block[i]
    print(*ans)


if __name__ == "__main__":
    main()


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

int main(){
    
    int W, H;
    cin>>W>>H;
    
    int x, y, r;
    cin>>x>>y>>r;
    
    if(x - r >= 0 && x + r <= W && y - r >= 0 && y + r <= H)
    cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3104
n,m=map(int,input().split())
l=[]
h=[]
count=0
for i in range(m):
    a,b=map(int,input().split())
    l.append(a)
    h.append(b)

l_max=max(l)
h_min=min(h)
if (h_min-l_max)<0:
    print(0)
else:
    print(h_min-l_max+1)



Measured memory_bytes: 55896
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1005;
const int M = 7005;
int a[N], b[N], c[N], d[N], e[N], f[N];
vector<int> vx, vy;
int dx[] = {0, 0, -1, 1}, dy[] = {-1, 1, 0, 0};
bool ma[M][M], vis[M][M];
int get_x(int x) {
    return lower_bound(vx.begin(), vx.end(), x) - vx.begin();
}
int get_y(int x) {
    return lower_bound(vy.begin(), vy.end(), x) - vy.begin();
}
int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    vx.push_back(-1.1e9), vx.push_back(0);
    vy.push_back(-1.1e9), vy.push_back(0);
    for(int i = 0; i < n; i++) {
        scanf("%d%d%d", &a[i], &b[i], &c[i]);
        vx.push_back(a[i]), vx.push_back(b[i]);
        vy.push_back(c[i]);
    }
    for(int i = 0; i < m; i++) {
        scanf("%d%d%d", &d[i], &e[i], &f[i]);
        vy.push_back(e[i]), vy.push_back(f[i]);
        vx.push_back(d[i]);
    }
    sort(vx.begin(), vx.end()), vx.erase(unique(vx.begin(), vx.end()), vx.end());
    sort(vy.begin(), vy.end()), vy.erase(unique(vy.begin(), vy.end()), vy.end());
    for(int i = 0; i < n; i++) {
        a[i] = get_x(a[i]), b[i] = get_x(b[i]), c[i] = get_y(c[i]);
        for(int j = a[i] * 2 - 1; j < 2 * b[i]; j++) {
            ma[j][2 * c[i] - 1] = true;
        }
    }
    for(int i = 0; i < m; i++) {
        d[i] = get_x(d[i]), e[i] = get_y(e[i]), f[i] = get_y(f[i]);
        for(int j = 2 * e[i] - 1; j < 2 * f[i]; j++) {
            ma[2 * d[i] - 1][j] = true;
        }
    }
    int sx = get_x(0) * 2 - 1, sy = get_y(0) * 2 - 1;
    bool flag = false;
    ll ans = 0;
    queue<pair<int, int>> qu;
    qu.push({sx, sy}), vis[sx][sy] = true;
    while(!qu.empty()) {
        int ux = qu.front().first, uy = qu.front().second;
        qu.pop();
        if(ux == M - 1 || uy == M - 1 || ux == 0 || uy == 0) {
            flag = true;
            break;
        }
        if(ux % 2 == 0 && uy % 2 == 0) {
            int x = ux / 2, y = uy / 2;
            ans += 1LL * (vx[x + 1] - vx[x]) * (vy[y + 1] - vy[y]);
        }
        for(int i = 0 ; i < 4; i++) {
            int xx = ux + dx[i], yy = uy + dy[i];
            if(xx >= M || xx < 0 || yy >= M || yy < 0 || vis[xx][yy] || ma[xx][yy]) continue;
            qu.push({xx, yy}), vis[xx][yy] = true;
        }
    }
    if(flag) printf("INF\n");
    else printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 89004
#include <stdio.h>

int main(void)
{
    int N;
    
    
    scanf("%d", &N);
    
    
    if(N <= 111)
    {
        N = 111;
    }
    else if(N <= 222)
    {
        N = 222;
    }
    else if(N <= 333)
    {
        N = 333;
    }
    else if(N <= 444)
    {
        N = 444;
    }
    else if(N <= 555)
    {
        N = 555;
    }
    else if(N <= 666)
    {
        N = 666;
    }
    else if(N <= 777)
    {
        N = 777;
    }
    else if(N <= 888)
    {
        N = 888;
    }
    else
    {
        N = 999;
    }
    
    printf("%d\n", N);
    
    //system("pause");
    
    return 0;
}

Measured memory_bytes: 128
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
const int N = 2e5+7;
ll a[N];

int main()
{
	int n;scanf("%d",&n);
	map<ll,ll> tb;
	for(int i = 1;i <= n;++i)
	{
		scanf("%lld",&a[i]);
		tb[i - a[i]]++;
	}
	ll res = 0;
	for(int i = 1;i <= n;++i)
	{
		--tb[i - a[i]];
		//cout << i << " " << -1 * (a[i] + i) << endl;
		if(tb.count((a[i] + i)))	res += tb[a[i] + i];
	}
	printf("%lld",res);		
    return 0;
}


Measured memory_bytes: 16800
n = int(raw_input())
S = float(0)
x = []
y = []
for _ in range(n):
  xi,yi = map(float, raw_input().split())
  x.append(xi)
  y.append(yi)
result = True
for i in range(n):
  ax = x[(i+1) % n] - x[i % n]
  ay = y[(i+1) % n] - y[i % n]
  bx = x[(i+2) % n] - x[(i+1) % n]
  by = y[(i+2) % n] - y[(i+1) % n]
  outer = (ax * by - bx * ay)
  if outer < 0:
    result = False
    break
if result:
  print "1"
else:
  print "0"

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

#define rep(n, i) for (int i = 0; i < (n); ++i)

using ll = long long;
using namespace std;

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

    map<int, int> count;
    for (auto e : a) {
      count[e]++;
    }

    ll sum = 0;
    for (auto p : count) {
      ll m = p.second;
      sum += m * (m-1) / 2;
    }

    for (auto e : a) {
      auto k = count[e] - 1;
      cout << sum - k << endl;
    }
}


Measured memory_bytes: 9728
/*author: hyperion_1724
  date: 
*/

//Optional FAST

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define trav(x,A) for(auto &x:A)
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef vector<int> veci;
typedef vector<long long> vecl;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);

//Required Functions

ll power(ll x,ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % MOD; 
    p = (p * p) % MOD; 
  
    return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

int main()
{
    #ifndef ONLINE_JUDGE
    if (fopen("INPUT.txt", "r"))
    {
        freopen ("INPUT.txt" , "r" , stdin);
        //freopen ("OUTPUT.txt" , "w" , stdout);
    }
    #endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    clock_t clk;
    clk = clock();
//-----------------------------------------------------------------------------------------------------------//

    map<string,ll> Z;
    string S1,S2;
    READ(S1);
    Z[S1]=0;
    READ(S2);
    Z[S2]=0;
    ll x;
    READ(x);
    Z[S1]=x;
    READ(x);
    Z[S2]=x;
    string U;
    READ(U);
    Z[U]--;
    cout<<Z[S1]<<" "<<Z[S2]<<endl;

//-----------------------------------------------------------------------------------------------------------//


    clk = clock() - clk;
    cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << endl;

    return 0;
}

Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

const int MAX_N = 200000;
int n, d, a;
pii xh[MAX_N + 1];
ll addition[MAX_N + 1];

int main() {
    fastio();

    cin >> n >> d >> a;
    forn(i, n) {
        cin >> xh[i].fst >> xh[i].snd;
    }
    xh[n].fst = INT_MAX;

    sort(xh, xh + n);

    ll ans = 0;
    ll cur = 0;
    forn(i, n) {
        cur += addition[i];
        xh[i].snd -= cur;

        if (xh[i].snd <= 0) continue;

        auto it = lower_bound(xh, xh + n, mp(xh[i].fst + 2 * d + 1, 0));
        int j = it - xh;

        ll c = (xh[i].snd + a - 1) / a;

        cur += c * a;
        addition[j] -= c * a;
        ans += c;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#pragma region
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << (#x) << "] = [", _print(x)
#else
#define debug(x...)
#endif
#pragma endregion
typedef long long ll;
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define sz(v) int((v).size())
#define int ll
#pragma region
#define f first
#define s second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#pragma endregion


void solve()
{
    int n;
    vector<int> a;
    cin>>n;
    a.resize(n);
    forn(i, n) cin>>a[i];
    int MOD = 1e9 + 7;
    int sum = 0;
    forn(i, n) sum = (sum+a[i])%MOD;
    sum%=MOD;
    int asum = sum*sum%MOD;
    int ivsum = 0;
    forn(i, n) ivsum = (ivsum + a[i]*a[i]%MOD)%MOD;
    cout << ((asum - ivsum)%MOD*(MOD+1)/2%MOD + MOD)%MOD;
}

signed main()
{
    int T = 1;
    ios_base::sync_with_stdio(0); cin.tie(0);
    //cin >> T;
    for(int i=1;i<=T;++i)
    {
        //cout << "Case #" << i << ": ";
        solve();
    }
    return 0;
}


Measured memory_bytes: 4780
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main() {
    int n; cin >> n;
    string temp[n][2];
    string cards[n];

    for (int i = 0; i < n; i++) {
        cin >> temp[i][0];
        cin >> temp[i][1];
        cards[i] = temp[i][0] + ' ' + temp[i][1];
    }

    // spades
    for (int i = 1; i <= 13; i++) {
        string *index = find(cards, cards+n, "S " + to_string(i));
        if (index == cards+n) {
            cout << "S " + to_string(i) << '\n';
        }
    }

    // hearts
    for (int i = 1; i <= 13; i++) {
        string *index = find(cards, cards+n, "H " + to_string(i));
        if (index == cards+n) {
            cout << "H " + to_string(i) << '\n';
        }
    }

    // clubs
    for (int i = 1; i <= 13; i++) {
        string *index = find(cards, cards+n, "C " + to_string(i));
        if (index == cards+n) {
            cout << "C " + to_string(i) << '\n';
        }
    }

    // diamonds
    for (int i = 1; i <= 13; i++) {
        string *index = find(cards, cards+n, "D " + to_string(i));
        if (index == cards+n) {
            cout << "D " + to_string(i) << '\n';
        }
    }

    return 0;
}



Measured memory_bytes: 3300
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s, t; cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.rbegin(), t.rend());
  int i = 0;
  int ls = s.length();
  int lt = t.length();
  while(i < ls && i < lt && s[i] == t[i]) i++;
  if(i == ls && i == lt) cout << "No" << endl;
  else if(i == ls) cout << "Yes" << endl;
  else if(i == lt) cout << "No" << endl;
  else {
    if(s[i] < t[i]) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main () {

    char c;
    int num;
    int cnt[26] = {0};

    while (cin >> c) {

        // if (c == '0') break;

        if ('a' <= c && c <= 'z') {
            num = c - 'a';
            cnt[num]++;
        } else if ('A' <= c && c <= 'Z') {
            num = c - 'A';
            cnt[num]++;
        }
    }

    for (int i = 0; i < 26; i ++) {
        char a = i + 'a';
        cout << a << " : " << cnt[i] << endl;
    }

    return 0;

}


Measured memory_bytes: 3088
#include<iostream>
#include<vector>

using namespace std;

typedef long long ll;

int main(){
	long long H;
	cin>>H;
	long long ans=0;
	long long enemy_num=1;
	while(H>0){
		H=H/2;
		ans += enemy_num;
		enemy_num = enemy_num*2;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
//OPTIMIZATONS
#pragma GCC optimize("02")
//CODE
#include<bits/stdc++.h>
#define int long long
#define float double
#define endl "\n"
#define debug cout<<"Good uptill here"<<endl<<flush;
#define deb(x) cout<<#x<<":"<<x<<endl<<flush;

using namespace std;

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	//CODE FOR SPECIFIED INPUT AND OUTPUT
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n,k;
	cin>>n>>k;
	set<int> s;
	int temp;
	for(int i=0;i<k;i++){
		int d;
		cin>>d;
		for(int j=0;j<d;j++){
			cin>>temp;
			s.insert(temp);
		}
	}
	cout<<n-s.size()<<endl;
	return 0;
}



Measured memory_bytes: 3644
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

LL N, M;
std::vector<LL>d;

int main()
{
	in >> N;
	std::vector<LL>X(N), Y(N);
	rep(i, N)
	{
		in >> X[i] >> Y[i];
		if ((llabs(X[i]) + llabs(Y[i])) % 2 != (llabs(X[0]) + llabs(Y[0])) % 2)
		{
			out << -1 << std::endl;
			return 0;
		}
	}
	M = 33;
	rep(i, M) d.push_back(1LL << (M - i - 1));
	if ((llabs(X[0]) + llabs(Y[0])) % 2 == 0)
	{
		++M;
		d.push_back(1);
	}
	out << M << std::endl;
	rep(i, M) out << d[i] << (i < M - 1 ? " " : "\n");
	rep(i, N)
	{
		LL px = 0, py = 0;
		std::string ans;
		rep(j, M)
		{
			LL dx = X[i] - px, dy = Y[i] - py;
			if (llabs(dx) >= llabs(dy))
			{
				if (dx >= 0)
				{
					ans += "R";
					px += d[j];
				}
				else
				{
					ans += "L";
					px -= d[j];
				}
			}
			else
			{
				if (dy >= 0)
				{
					ans += "U";
					py += d[j];
				}
				else
				{
					ans += "D";
					py -= d[j];
				}
			}
		}
		out << ans << std::endl;
	}
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

abstract class Product {
	
	// check the input values
	public abstract boolean check();
	
	// calcurate area
	public abstract int calcArea();
	
	// calcurate perimeter
	public abstract int calcPerimeter();
}

abstract class Factory {
	
	// create instance of product
	public Product create(int a, int b) {
		return createProduct(a, b);
	}
	
	// create instance of product
	protected abstract Product createProduct(int a, int b);
}

final class RectangleProduct extends Product {

	private int a;
	private int b;
	
	public RectangleProduct(int a, int b) {
		this.a = a;
		this.b = b;
	}
	
	// calcurate area
	@Override
	public int calcArea() {
		
		return a * b;
	}

	// calcurate perimeter
	@Override
	public int calcPerimeter() {
		
		return 2 * a + 2 * b;
	}

	// check the input values
	@Override
	public boolean check() {
		
		if ((a >= 1 && a <= 100) && (b >= 1 && b <= 100)) {
			return true;
		}
		
		return false;
	}
}

final class RectagleFactory extends Factory {

	// create instance of product
	@Override
	protected Product createProduct(int a, int b) {
		
		return new RectangleProduct(a, b);
	}
	
}

public class Main {

	public static void main(String[] args) {
		
		Factory f = new RectagleFactory();
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		Product p = f.create(a, b);
		if (p.check()) {
			System.out.printf("%d %d\n", p.calcArea(), p.calcPerimeter());
		}
	}

}



Measured memory_bytes: 26236
#include <bits/stdc++.h>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)

using namespace std;
using ll = long long;
using P = pair<int,int>;
using ull= unsigned long long;
const ll K_MAX=1e5+5;
const ll Lmax=ll(1e18);
const ll INF=1e9;
const int Bmax=2e5;
const int Nd=61;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
//const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


int main(){
  int n; cin>>n;
  vector<ll> a(n);
  rep(i,n) cin>>a[i];
  mint ans=0;
  mint test;

  rep(i,Nd){//各桁を考える
    int n1=0;
    int n0=0;
    rep(j,n){
      if(a[j]>>i&1) n1++;
      else n0++;
    }
    //cout<<i<<":"<<n1<<" "<<n0<<" "<<(1<<i)<<endl;
    test=1;
    rep(k,i) test*=2;
    
    test*=n0; test*=n1;
    ans+= test;
  }
  cout<<ans<<endl;


}


Measured memory_bytes: 5620
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rec register char
#define rel register ll
#define gc getchar
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
template <typename mitsuha>
inline bool read(mitsuha &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';
  if (!~c) return 0;
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return x=f?x:-x,1;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return 0&pc(48);
  if (x<0) x=-x,pc('-');
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  return 0;
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;
int n,ans;
int main(){
for (n=read();n--;){
  int x=read();
  for (;x%2==0;x>>=1) ans++;
  }
cout<<ans;
}

Measured memory_bytes: 256
def main():
    n = int(input())
    a = list(map(int, input().split()))
    ans = 0
    old = a[0]
    for ai in a[1:]:
        if ai < old:
            ans += old-ai
        else:
            old = ai
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 94132
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int x;
int main(){
  cin >> x;
  ll n = 1;
  ll m,k;
  rep(i,x){
    cin >> k;
    m = __gcd(n,k);
    n = (n/m)*k;
  }
  cout << n << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1000000000
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int H,W;
  cin >> H >> W;
  char S[H][W];
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin >> S[i][j];
    }
  }
  bool flg=true;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(S[i][j] == '#') flg = false;
    }
    if(flg){
      for(int j=0;j<W;j++){
        S[i][j] = ' ';
      }
    }
    else flg = true;
  }
  flg=true;
  for(int j=0;j<W;j++){
    for(int i=0;i<H;i++){
      if(S[i][j] == '#') flg = false;
    }
    if(flg){
      for(int i=0;i<H;i++){
        S[i][j] = ' ';
      }
    }
    else flg = true;
  }

  for(int i=0;i<H;i++){
    flg = true;
    for(int j=0;j<W;j++){
      if(S[i][j] == '.' || S[i][j] == '#'){
        cout << S[i][j];
        flg = false;
      }
    }
    if(!flg) cout << endl;
  }
  
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define for(i,a,b) for(int i=a;i<=b;i++)
#define _inline __inline__ __attribute__((always_inline))
using namespace std;
_inline void read(int &x){
	int res=0,f=1;
	char c=getchar();
	if(c=='-') f=-1;
	while(c>'9'||c<'0') c=getchar();
	while(c>='0'&&c<='9'){
		res=res*10+c-'0';
		c=getchar();
	}
	x=res*f;
}
inline void print(int x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) print(x/10);
    putchar(x%10+'0');
}
int n,m;
int main(){
	read(n),read(m);
	puts(n==m?"Yes":"No");
	exit(0);
}

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

int main() {
	// your code goes here
	ll n, i, j, k, w;
	cin >> n >> w;
	ll weights[n+1];
	ll values[n+1];
	
	weights[0] = 0;
	values[0] = 0;
	
	for(i=1; i<=n; i++){
		cin >> weights[i];
		cin >> values[i];
	}
	
	ll dp[n+1][w+1];
	for(i=0; i<n+1; i++) dp[i][0] = 0;
	for(i=0; i<w+1; i++) dp[0][i] = 0;
	
	for(i = 1; i < n+1; i++){
		for(j = 1; j < w+1; j++){
			if(j < weights[i]) dp[i][j] = dp[i-1][j];
			else{
				dp[i][j] = max(dp[i-1][j], values[i] + dp[i-1][j-weights[i]]);
			}
		}
	}

	cout << dp[n][w];
	
	return 0;
}

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

using namespace std;

constexpr int64_t mod = INT64_C(1000000007);

static std::array<int64_t, 200000> colorDp{};

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  int n;
  std::cin >> n;
  int previousColor = n;
  int64_t dp = 1;
  for (int i = 0; i < n; ++i) {
    int color;
    std::cin >> color;
    color--;
    if (color == previousColor) {
      continue;
    }
    dp += colorDp[color];
    dp %= mod;
    colorDp[color] = dp;
    previousColor = color;
  }
  std::cout << dp << std::endl;
  return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,tot=0,nn;
	scanf("%d",&n);
	nn=n;
	while(nn){
		tot+=nn%10;
		nn/=10;
	}
	if(n%tot==0)
		printf("Yes\n");
	else printf("No\n");
	return 0;
}


Measured memory_bytes: 256