akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    string S = in<string>(),T = in<string>();
    vector<char> A(26,'0');
    bool ok = 1;
    REP(i,S.size()){
        if(A[S[i]-'a'] == '0'){
            A[S[i]-'a'] = T[i];
        }else{
            if(A[S[i]-'a'] != T[i])ok = 0;
        }
    }
    sort(ALL(A));
    char before = '0';
    REP(i,26){
        if(before != '0'){
            if(before == A[i]){
                ok = 0;
            }
        }
        before = A[i];
    }
    cout << (ok ? "Yes" : "No") << "\n";
}

Measured memory_bytes: 916
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define inf 10000000000000007
#define eps 1e-13
#define PI 3.14159265359
#define sp printf(" ")
#define vi vector<int>
#define vl vector<long long>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pcc pair<char, char>
#define mp make_pair
#define FF first
#define SS second
#define pb(x) push_back(x)
#define sd(x) scanf("%d", &(x))
#define pd(x) printf("%d", (x))
#define pdn(x) printf("%d\n", (x))
#define sld(x) scanf("%ld", &(x))
#define pld(x) printf("%ld", (x))
#define pldn(x) printf("%ld\n", (x))
#define slf(x) scanf("%lf", &(x))
#define plf(x) printf("%.9lf", (x))
#define plfn(x) printf("%.9lf\n", (x))
#define sch(x) scanf("%c", &(x))
#define pch(x) printf("%c", (x))
#define pchn(x) printf("%c\n", (x))
#define gtl(x) getline(cin, (x))
#define flsh fflush(stdout)
#define ios ios::sync_with_stdio(false); cin.tie(0) ; cout.tie(0)
#define endl '\n'
using namespace std;
ll h[100004];
int main()
{
    ll n,a,b;
    cin>>n>>a>>b;
    set<pll>s;
    for(int i=1;i<=n;i++)
    {
        cin>>h[i];
    }
    sort(h+1,h+n+1);
    int l=0;int r=1000000000;
    while(r-l>1)
    {
        ll mid=(l+r)/2;
        ll g=mid*b;
        ll t=a-b;
        ll p=mid;
        bool b1=true;
        for(int i=n;i>=1;i--)
        {
            ll o=h[i]-g;
            if(o<=0)continue;
            ll w=o/t;
            if(o%t!=0)w++;
            if(p>=w)p=p-w;
            else b1=false;
        }
        if(b1)r=mid;
        else l=mid;

    }
    cout<<r<<endl;








}




Measured memory_bytes: 1024
using System;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;
using static System.Console;

class Solver {
    Scanner sc = new Scanner();

    int N;
    int[] A;
    public void Solve() {
        N = sc.nextInt();
        A = sc.ArrayInt(N);

        WriteLine(Sub());
    }

    public long Sub() {
        var arr = new int[N];
        for (int i = 0; i < N; i++) {
            arr[A[i]]++;
        }

        if (N % 2 == 0) {
            for (int j = 1; j < N; j += 2) {
                if (arr[j] != 2) return 0;
            }
        } else {
            if (A.Count(i => i == 0) != 1) return 0;

            for (int j = 2; j < N; j += 2) {
                if (arr[j] != 2) return 0;
            }
        }

        long ans = 1;
        for (int i = 0; i < N /2; i++) {
            ans = ans * 2 % 1000000007;
        }

        return ans;
    }
}



class Scanner {
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt() {


        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble() {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0) {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Program {
    static void Main(string[] args) {
        Solver s = new Solver();
        s.Solve();
    }
}

Measured memory_bytes: 20704
#include<bits/stdc++.h>
#define ll long long 
#define pb push_back 
#define mp make_pair 
#define f(i,n) for(int i=0;i<n;i++) 
#define fr(i,a,b) for(int i=a;i<b;i++) 
#define F first 
#define S second 

using namespace std;

ll nC3(ll x){
	if(x<3)return 0;
	ll c = x*(x-1)*(x-2);
	c = c/6;
	return c;
}

ll nC2(ll x){
	if(x<2)return 0;
	ll c = x*(x-1);
	c = c/2;
	return c;
}

void test(){
	ll n;
	cin>>n;
	string s;
	cin>>s;
	ll tot = nC3(n);
	ll r=0,g=0,b=0;
	f(i,n){
		if(s[i]=='R')r++;
		else if(s[i]=='G')g++;
		else b++;
	}
	ll dif = 0LL;
	dif = dif + nC3(r);
	dif = dif + nC3(g);
	dif = dif + nC3(b);
	
	dif = dif + nC2(g)*(r+b);
	dif = dif + nC2(r)*(g+b);
	dif = dif + nC2(b)*(r+g);
	
	
	for(int i=0;i<n-2;i++) // starting
	{
		for(int j = 1;i+(2*j)<n;j++){
			string temp = "";
			temp.pb(s[i]);
			temp.pb(s[i+j]);
			temp.pb(s[i+2*j]);
			sort(temp.begin(),temp.end());
			if(temp=="BGR")dif++;
		}
	}
	
	cout<<tot-dif<<"\n";	
}

int main(){
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t=1;
//	cin>>t;
	while(t--){
		test();
	}
}

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

int main()
{
    int N;
    cin >> N;

    map<long long, long long> count;
    long long A;
    for (int i = 0; i < N; i++)
    {
        cin >> A;
        count[A]++;
    }

    long long h = 0;
    long long w = 0;
    for (auto itr = count.rbegin(); itr != count.rend(); itr++)
    {
        while (itr->second >= 2)
        {
            if (h == 0)
            {
                h = itr->first;
            }
            else
            {
                w = itr->first;
                itr = count.rend();
                itr--;
                break;
            }
            count[itr->first] -= 2;
        }
    }
    cout << h * w << endl;
}


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

int main(){
	string s;
	cin >> s;
	set<char> st;
	for(int i=0;i<3;i++) {
		st.insert(s[i]);
	}
	if(st.size() != 1) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
static const long long MOD = 1000000000+7;
static const double PI = 3.141592653589793;

long long powmod(long long x, long long n, long long mod = 0) {
  if (mod == 0) {
      long long res=1;
    while (n > 0) {
      if (n%2 == 1) {
        res = ( res*x );
      }
      x = (x*x);
      n /= 2;
    }
    return res;
  }

  long long res=1;
  while (n > 0) {
    if (n%2 == 1) {
      res = ( res*x ) % mod;
    }
    x = (x*x) % mod;
    n /= 2;
  }
  return res;
}

long long modinverse(long long x, long long mod) {
  // mod must be prime number.
  return powmod(x, mod-2, mod);
}

int main() {
  int t1, t2;
  int h1,m1,h2,m2;
  cin >> h1 >> m1 >> h2 >> m2;
  t1 = 60*h1 + m1;
  t2 = 60*h2 + m2;
  int k;
  cin >> k;

  cout << t2 - k - t1 << endl;
}

Measured memory_bytes: 3628
n = int(input())
P = list(map(int, input().split()))
counter = 0
for i in range(n-2):
    flag = 0
    if P[i+1] > P[i] and P[i+1] > P[i+2]:
        flag = 1
    if P[i+1] < P[i] and P[i+1] < P[i+2]:
        flag = 1
    if flag == 0:
        counter = counter + 1
print(counter)


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
	int x = 0;
	int a, b;
	cin >> a >> b;
	cout << (x ^ a ^ b) << endl;
    
    return 0;
}



Measured memory_bytes: 3520
#include<bits/stdc++.h>
using namespace std;
const int N=200005;
int a[N],n;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	for(int i=2;i<=n;i++)
	{
		if(a[i]==a[i-1])
		{
			puts("NO");
			return 0;
		}
	}
	puts("YES");
	return 0;
}

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

int main ()
{
    int n;
    scanf("%d",&n);
    long long a[n];
    for(int i=0; i<n; i++)
        cin>>a[i];
    sort(a,a+n);
    if(a[0]==0)
    {

        printf("0\n");
        return 0;
    }
    long long prod =1;
    for(int i=0; i<n; i++)
    {
        if(a[i ] <=1000000000000000000/ prod )
        {
            prod *=a[i];
        }
        else
        {
            printf("-1\n");
            return 0;
        }
    }
    cout<<prod<<'\n';
}


Measured memory_bytes: 4444
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using pi = pair<int, int>;
using pll = pair<ll, ll>;
constexpr int INF = 0x3f3f3f3f; constexpr ll LLINF = 0x3f3f3f3f3f3f3f3f;
#define db(x) { cerr << #x << " = " << x << endl; }
template <typename T> void _dbarr(T* a, size_t sz){ for(int i = 0; i < sz; i++) cerr << a[i] << " \n"[i == sz-1]; }
template <typename T> void _dbarr(vector<T> a, size_t sz){ for(int i = 0; i < sz; i++) cerr << a[i] << " \n"[i == sz-1]; }
#define dbarr(x, n) {cerr << #x << ": "; _dbarr((x),(n));}
#define all(x) begin(x), end(x)
#define pb push_back
#define eb emplace_back
#define mpr make_pair
#define fs first
#define sn second
const int MM = 7;
int h,w,k;
char grid[MM][MM],cur[MM][MM];
int main() {
	//cin.tie(0)->sync_with_stdio(0);
    cin >> h >> w >> k;
    int cnt = 0;
    for(int i = 0; i < h; i++) for(int j = 0; j < w; j++)
        cin >> grid[i][j],cnt += (grid[i][j] == '#');
    int ans = 0;
    for(int maskr = 0; maskr < (1<<h); maskr++){
        for(int maskc = 0; maskc < (1<<w); maskc++){
            int cur = 0;
            for(int i = 0; i < h; i++){
                for(int j = 0; j < w; j++){
                    if(!(maskr & (1<<i)) && !(maskc & (1<<j))){
                        cur += (grid[i][j] == '#');
                    }
                }
            }
            ans += (cur==k);
        }
    }
    cout << ans << "\n";
}


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

int main() {
	int N;
	int d[110];
	cin >> N;
	int i;
	for(i=0; i<N; ++i)
	{
	    cin >> d[i];
	}
	sort(d, d+N);
	int out = 1;
	for(i=1; i<N; ++i)
	{
	    if(d[i] != d[i-1]) ++out;
	}
	cout << out << endl;
	return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return input().rstrip().decode()
def II(): return int(input())
def FI(): return float(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()


def main():
	n=II()
	T=LI()
	A=LI()

	X=[0]*n
	Y=[10**10]*n

	now=0
	for i,v in enumerate(T):
		if now<v:
			X[i]=v
			Y[i]=v
			now=v
		else:
			X[i]=max(X[i],1)
			Y[i]=min(Y[i],now)
	#print(X,Y)

	now=0
	for i,v in enumerate(reversed(A)):
		if now<v:
			if X[n-i-1]<=v<=Y[n-i-1]:
				X[n-i-1]=v
				Y[n-i-1]=v
			else:
				print(0)
				exit()
			now=v
		else:
			X[n-i-1]=max(X[n-i-1],1)
			Y[n-i-1]=min(Y[n-i-1],now)




	#print(X,Y)

	mod=10**9+7
	ans=1

	for i,j in zip(X,Y):
		if i>j:
			print(0)
			exit()
		else:
			ans*=(j-i+1)
			ans%=mod
	print(ans)










if __name__ == "__main__":
	main()


Measured memory_bytes: 98680
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ls signed long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define rep(i,k,n) for (ll i = k; i < n; ++i)
#define all(c) (c).begin(),(c).end()
#define test() ll t;cin>>t;while(t--)
#define debug(x) cout << (#x) << " is " << (x) << endl
#define hello ios_base::sync_with_stdio(0);cin.tie(0)
/* sort on the basis of the size of the  string in a vector modified sort function
	 sort(a.begin(), a.end(), [&] (const string &s, const string &t) {
		return s.size() < t.size();
		
		
			upper_bound(v.begin(),v.end(),r);
			lower_bound(v.begin(),v.end(),l)
	});
*/
//const int DR[4][2]={{1,0},{0,1},{-1,0},{0,-1}}
const ll MOD = 1e9 + 7;
const ll MAX = 1001;
void solve()
{
	int n;
	cin>>n;
	int a[n];
	ll s[n],r[n];
	ll x=0;
	int k=0;
	int ans=INT_MAX;
	rep(i,0,n)
	{
		cin>>a[i];
		x+=a[i];
		s[i]=x;
	}
	 x=0;
	for(int i=n-1;i>=0;i--)
	{
		x+=a[i];
		r[i]=x;
	}
	rep(i,0,n-1)
	{
	///	debug(s[i]);
	//	debug(r[i+1]);
	 if(abs(s[i]-r[i+1])<ans)
		{
			ans=abs(s[i]-r[i+1]);
		}
	//		debug(ans);
	}
	cout<<ans<<endl;
		  
}
int main()
{

	hello;
	solve();
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

using namespace std;

int main() {
  // N × (3 × 3)要素の配列を宣言
  /* vector<vector<vector<char>>> data(N, vector<vector<char>>(3, vector<char>(3))); */
  // int型の2次元配列(3×4要素の)の宣言
  /* vector<vector<int>> data(3, vector<int>(4)); */
  int N;
  cin >> N;
  int64_t result = 1;
  int64_t before = 2;
  int64_t tmp;
  for(int i = 1; i < (int)N; i++) {
    tmp = result;
    result += before;
    before = tmp;
  }

  cout << result << endl;
}


Measured memory_bytes: 3632
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
using namespace std;
int MOD = 1000000007;

signed main(){
    int n;
    string s;
    cin >> n >> s;

    string s1 = s.substr(0,n);
    string s2 = "";
    rep(i,n){
        s2.pb(s[2*n-1-i]);
    }
    // cerr << s1 << endl;
    // cerr << s2 << endl;
    map<pair<string,string>,int> m1,m2;
    for(int i = 0;i < (1LL<<n);i++){
        string t1 = "";
        string t2 = "";
        string t3 = "";
        string t4 = "";
        for(int j = 0;j < n;j++){
            if(i&(1LL<<j)){
                t1.push_back(s1[j]);
                t3.push_back(s2[j]);
            }else{
                t2.push_back(s1[j]);
                t4.push_back(s2[j]);
            }
        }
        m1[MP(t1,t2)]++;
        m2[MP(t3,t4)]++;
    }
    //for(auto x:m1)cerr << (x.fi).fi << " " << (x.fi).se << endl;
    int ans = 0;
    for(auto x:m1){
        auto itr = m2.find(x.fi);
        if(itr != m2.end()){
            ans += (x.se) * (itr->se);
        }
    }
    cout << ans << endl;





    
    
    return 0; 
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://agc026.contest.atcoder.jp/tasks/agc026_c
// rm -r -f test;oj dl http://abc107.contest.atcoder.jp/tasks/abc107_b

Measured memory_bytes: 91904
#include<stdio.h>

int main(){
long long i,n,max=-1000000,min=1000000,total=0;
scanf("%d",&n);
int inp[n];
for(i=0;i<n;i++){
scanf("%d ",&inp[i]);
total+=inp[i];
if(max<inp[i])max=inp[i];
if(min>inp[i])min=inp[i];
}
printf("%ld %ld %ld\n",min,max,total);
return 0;
}

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int c[101]={};
    int n, max=0;
    while(cin>>n){
        ++c[n];
        if(max<c[n]) max=c[n];
    }
    for(int i=1; i<=100; i++){
        if(c[i]==max) cout<<i<<'\n';
    }
    return 0;
}

Measured memory_bytes: 2976
#include <iostream>
#include <algorithm>
#include <string>
 
using namespace std;
 
typedef long long lli;
 
const int N = 60;
 
lli C[N+1][N+1];
 
string calc(lli num, lli rem, lli n){
  string res;
  if(num == 0){
    for(int i=0;i<n;i++){
      res.push_back('0');
    }
  }else{
    lli pre = 0;
    for(int i=0;i<n;i++){
      lli cur = C[num+i-1][num-1];
      if(pre <= rem && rem < pre + cur){
        for(int j=0;j<n-(num+i);j++) res.push_back('0');
        res.push_back('1');
        res += calc(num - 1, rem - pre, num + i - 1);
        break;
      }
      pre += cur;
    }
  }
  return res;
}
 
string solve(lli n, lli m){
  string res;
  if(m == 1){
    for(int i=0;i<n;i++) res.push_back('0');
  }else{
    m--;
    lli pre = 1;
    for(int i=1;i<=N;i++){
      if(pre <= m && m < pre + C[n][i]){
        res = calc(i, m - pre, n);
      }
      pre += C[n][i];
    }
  }
  return res;
}
 
void init(){
  C[0][0] = 1;
  for(int i=1;i<=N;i++){
    for(int j=0;j<=i;j++){
      C[i][j] = 0;
      if(j-1 >= 0) C[i][j] += C[i-1][j-1];
      if(j <= i-1) C[i][j] += C[i-1][j];
    }
  }
}
 
main(){
  init();
  lli n, m;
  while(cin >> n >> m && (n|m)){
    cout << solve(n, m) << endl;
  }
}

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

using namespace std;
typedef long long ll;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1e9;

int main(){

  int n;cin>>n;
  map<int,int>mp;
  rep(i,0,n){
    int a;cin>>a;
    mp[a]=i;
  }

  for(map<int,int>::iterator itr=mp.begin();itr!=mp.end();itr++){
    cout<<itr->second+1<<" ";
  }
  cout<<endl;






  return 0;
}


Measured memory_bytes: 5504
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long w, h, x, y;
  cin >> w >> h >> x >> y;
  cout << (double)(w*h/2.0) << " " 
       << ((w%2==0 and w/2==x) and (h%2==0 and h/2==y) ?1 :0) << "\n";
}

Measured memory_bytes: 256
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(m)]

class WeightedUnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
        self.weight = [0] * (n+1)
        self.sizes = [1] * (n+1)

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            y = self.find(self.par[x])
            self.weight[x] += self.weight[self.par[x]]
            self.par[x] = y
            return y

    def union(self, x, y, w=1):
        rx = self.find(x)
        ry = self.find(y)
        if self.rank[rx] < self.rank[ry]:
            self.sizes[ry] += self.size(rx)
            self.par[rx] = ry
            self.weight[rx] = w - self.weight[x] + self.weight[y]
        else:
            self.sizes[rx] += self.size(ry)
            self.par[ry] = rx
            self.weight[ry] = -w - self.weight[y] + self.weight[x]
            if self.rank[rx] == self.rank[ry]:
                self.rank[rx] += 1

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

    def diff(self, x, y):
        return self.weight[x] - self.weight[y]

    def size(self, x):
        return self.sizes[self.find(x)]

uf=WeightedUnionFind(n)

for a,b in ab:
    uf.union(a,b)

s=set()
ans=0
for i in range(n):
    if not uf.find(i+1) in s:
        ans+=1
        s.add(uf.find(i+1))
print(ans-1)

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

int main()
{
    while(true){
        int n;
        cin>>n;
        if(n==0)
            break;
        unsigned sum=0;
        for(int i=0; i<n; i++){
            int p;
            cin>>p;
            
            sum+=(unsigned)p;
        }
        
        int j[65000];
        for(int i=0; i<n-1; i++){
            cin>>j[i];
        }
        
        sort(j, j+(n-1));
        
        unsigned sal_max = (unsigned)n*sum;
        for(int i=n-1; i>=1; i--){
            sum+=(unsigned)j[i-1];
            
            sal_max = max(sal_max, (unsigned)i*sum);
        }
        
        cout<<sal_max<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 1424
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
const int N = 205; 
typedef long long ll; 
using namespace std;

int T, n, vis[N], in[N], pa[N], pb[N], da[N], ans, flag; 
vector<int> g[N], ga[N], gb[N];
queue<int> q; 

template < typename T >
inline T read()
{
	T x = 0, w = 1; char c = getchar();
	while(c < '0' || c > '9') { if(c == '-') w = -1; c = getchar(); }
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * w; 
}

void dfs(int u, int fa, vector<int> *g, int *p)
{
	p[u] = fa;
	for(int v, i = 0; i < g[u].size(); i++)
		if((v = g[u][i]) != fa) dfs(v, u, g, p); 		
}

int solve()
{
	int cnt = 0, tmp = 0; 
	for(int i = 0; i <= n; i++) vis[i] = in[i] = 0;
	for(int i = 1; i <= n; i++) if(pa[i] != pb[i]) vis[i] = 1, cnt++; 
	for(int i = 1; i <= n; i++) if(!vis[i] && vis[pa[i]]) return -1; 
	for(int i = 1; i <= n; i++) g[i].clear();
	for(int i = 1; i <= n; i++)
		if(vis[i])
		{
			if(vis[pa[i]]) g[i].push_back(pa[i]), in[pa[i]]++; 
			if(vis[pb[i]]) g[pb[i]].push_back(i), in[i]++; 
		}
	for(int i = 1; i <= n; i++) if(!in[i] && vis[i]) q.push(i); 
	while(!q.empty())
	{
		int u = q.front(); q.pop(); tmp++; 
		for(int v, i = 0; i < g[u].size(); i++)
		{
			v = g[u][i], in[v]--;
			if(!in[v]) q.push(v); 
		}
	}
	if(cnt != tmp) return -1;
	else return cnt; 
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("cpp.in", "r", stdin); 
#endif
	T = read <int> ();
	while(T--)
	{
		n = read <int> ();
		for(int i = 1; i <= n; i++) ga[i].clear(), gb[i].clear(), da[i] = 0; 
		for(int u, v, i = 1; i < n; i++)
		{
			u = read <int> (), v = read <int> ();
			ga[u].push_back(v), ga[v].push_back(u), da[u]++, da[v]++; 
		}
		for(int u, v, i = 1; i < n; i++)
		{
			u = read <int> (), v = read <int> ();
			gb[u].push_back(v), gb[v].push_back(u); 
		}
		dfs(1, 0, ga, pa), dfs(1, 0, gb, pb);
		ans = n + 1, flag = 1;
		for(int i = 1; i <= n; i++) if(pa[i] != pb[i]) flag = 0;
		if(flag) { puts("0"); continue; }
		for(int tmp, i = 1; i <= n; i++)
			if(da[i] == 1)
			{
				dfs(i, 0, gb, pb); 
				for(int j = 1; j <= n; j++)
					if(j != i)
					{
						dfs(j, 0, ga, pa), pa[i] = 0, pa[j] = i; 
						tmp = solve(); 
						if(tmp != -1) ans = min(ans, tmp + 1); 
					}
			}
		printf("%d\n", ans == n + 1 ? -1 : ans); 
	}
	return 0;
}


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

const long double PI = acos(-1);
 
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

 bool IsPrime(ll num){
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2){
        if (num % i == 0){
            return false;
        }
    }
    return true;
}

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

    ll pcnt = 0, qcnt = 0;
    do{
        pcnt++;
    }while(next_permutation(p.begin(), p.end()));

    do{
        qcnt++;
    }while(next_permutation(q.begin(), q.end()));

    cout << abs(pcnt - qcnt) << endl;
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"strconv"
)


func main(){
	var s string
	fmt.Scan(&s)
	var dp []int
	n := len(s)
	dp = append(dp,0)
	var sum int
	ten := 1
	for i:=n-1 ; i>=0 ; i-- {
		x,_ := strconv.Atoi(s[i:i+1])
		x = ((x*ten)%2019 + sum%2019)%2019
		ten *= 10
		ten = ten%2019
		sum = x
		dp = append(dp,x)
	}
//fmt.Println(dp)
	ans := make([]int,2019)
	for i:=0 ; i<len(dp) ; i++ {
		ans[dp[i]]++
	}
	var a int
	for i:=0 ; i<2019; i++ {
		a += ans[i]*(ans[i]-1)/2
	}
	fmt.Println(a)
}


Measured memory_bytes: 8992
#include <stdio.h>
int main(void) {
	int n, r, i, j;
	char c;
	char d[4][13];
	char cl[] = { 'S', 'H', 'C', 'D' };

	for( i = 0; i < 4; ++i ) {
		for(j = 0; j < 13; ++j) {
			d[i][j] = 0;
		}
	}

	scanf("%d", &n );
	for( i = 0; i < n; ++i ) {
		scanf(" %c %d", &c, &r);
		if( c == 'S' ) { j = 0; }
		else if( c == 'H' ) { j = 1; }
		else if( c == 'C' ) { j = 2; }
		else if( c == 'D' ) { j = 3; }
		else { continue; }
		d[j][r-1] = 1;
	}

	for( i = 0; i < 4; ++i ) {
		c = cl[i];
		for( j = 0; j < 13; ++j ) {
			if( d[i][j] == 0 ) {
				printf("%c %d\n",c,j+1);
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;
const ll inf = 1e15;
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}


ll fac[2000010], finv[2000010], inv[2000010];
 
void init(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(ll i=2;i<2000010;i++){
        fac[i]=fac[i-1]*i%mod;
        inv[i]=mod-inv[mod%i]*(mod/i)%mod;
        finv[i]=finv[i-1]*inv[i]%mod;
    }
}

ll C(ll n, ll k){
  return fac[n] %mod *finv[k] %mod *finv[n-k] %mod;
}


//E 
int main(){FIN

    
    ll k; cin>>k;
    string s; cin>>s;
    ull ans=0;
    init();
    for(ll i=0; i<=k; i++){
        ans = (ans + power(26,i) *power(25, k-i) %mod *C(k+s.size()-i-1, k-i)) % mod;
        ans%=mod;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 51244
n, m, q = input().split()
n = int( n )
m = int( m )
q = int( q )
a = []
b = []
c = []
d = []
for i in range( int( q ) ):
    a_i, b_i, c_i, d_i = input().split()
    a.append( int( a_i ) )
    b.append( int( b_i ) )
    c.append( int( c_i ) )
    d.append( int( d_i ) )

array = [ 1 ] * n
array_list = [ array ]

i = 0
while True:
    for k in range( array_list[i][-1], m + 1 ):
        array_list.append( array_list[i][1:] + [ k ] )
        #print( array_list[i][1:] + [ k ] )
    i = i + 1
    if len( array_list ) > 100000:
        break

max_score = 0
for array in array_list:
    score = 0
    for i in range( q ):
        #print( i, a[i], b[i], c[i], array )
        if array[b[i]-1] - array[a[i]-1] == c[i]:
            score = score + d[i]
    if max_score < score:
        max_score = score

print( max_score )

Measured memory_bytes: 24108
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,m,a,b,c,d,sum=0,array[100000+10],cnt=0,ans=INT_MIN,i,j;
    string str,ptr;
    cin>>str>>ptr;
    for(i=0;i<str.length();i++)
    {
        if(str[i]==ptr[i])
            cnt++;
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	string s; cin >> s;
	cout << 700 + 100 * count(ALL(s), 'o') << endl;
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-


def main():
    n, l = map(int, input().split())
    a = list(map(int, input().split()))

    # KeyInsight
    # 最後から直前の状態を考える
    # ある位置a[i]と右隣の値a[i+1]の和がL以上であれば構成できる
    # iの位置を特定
    # 左右の両端から切る
    pos = -1

    for i in range(n - 1):
        if (a[i] + a[i + 1]) >= l:
            pos = i

    if pos == -1:
        print("Impossible")
    else:
        print("Possible")

        # 1-indexに
        pos += 1

        # See:
        # https://atcoder.jp/contests/agc002/submissions/7179969
        ans = [i for i in range(1, pos)] + [i for i in range(n - 1, pos, -1)] + [pos]
        print('\n'.join(map(str, ans)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 17892
#include <iostream> // cout, endl, cin
#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 vi = vector<int>;
using vii = vector<vi>;
using in6 = int64_t;
using ind = double;
using p = pair<int,int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

vi fpn(int x) {
    vi ret;
    for(int i = 1; i <= x; i++) {
        if(x % i == 0) ret.push_back(i);
    }
    return ret;
}

int main() {
    int a,b,c;
    cin >> a >> b >> c;
    vi data = fpn(c);
    int size = data.size();
    int count = 0;
    rep(i,size) {
        if(data[i] >= a && data[i] <= b) count++;
    }
    cout << count << endl;
}


Measured memory_bytes: 3140
#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 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef vector<llong> V;

#define _ cin.tie(0);ios::sync_with_stdio(false);
int n;
int main(){ _;
  cin>>n;
  V a(n);
  REP(i,n) cin>>a[i];
  int i=0;
  int ans=0;
  while(a[i]!=-1){
    int j=i;
    i=a[i]-1;
    ans++;
    if(i==1){
      cout<<ans<<endl;
      return 0;
    }
    a[j]=-1;
  }
  cout<<-1<<endl;
    

  return 0;
}


Measured memory_bytes: 1024
import math

def sol(ans, i):
  for j in range(2,1001):
    tmp_ans = math.pow(i,j)
    if tmp_ans > X: return ans
    elif ans < tmp_ans: ans = tmp_ans
  return ans

X=int(input())
if X == 1:
  print(1)
  exit()

ans = -1 * float('inf')
for i in range(1,1001):
  ans = sol(ans,i)
print(int(ans))

Measured memory_bytes: 38896
///#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
///#pragma GCC target("sse,sse2,sse3,ssse3,sse4,abm,mmx,popcnt,avx,avx2,tune=native")

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

/*
    zet:
        find_by_order(k): k-stat [k > 0]
        order_of_key(k) : {el < k}

    gp_hash_table<key, val, custom_hash>

    rope<T>:
        iterators: mutable_begin, ..
        methods  : erase, insert, substr, ..
*/

#define all(x) (x).begin(), (x).end()
#define size(x) (int)((x).size())
#define em_back emplace_back

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<typename T>
using zet = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

mt19937 eng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 54;
const int M = N * N;

int n, a, x[N];
ll cnt[N][N][M]; /// cnt, last, sum

void solve() {
    cin >> n >> a;
    for (int i = 1; i <= n; ++i) {
        cin >> x[i];
    }

    cnt[0][0][0] = 1;
    for (int i = 1; i <= n; ++i) {
        for (int j = M - 1; j > 0; --j) {
            for (int k = 1; k <= n; ++k) if (j - x[k] >= 0) {
                for (int t = 0; t < k; ++t) {
                    cnt[i][k][j] += cnt[i - 1][t][j - x[k]];
                }
            }
        }
    }

    ll res = 0;
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= n; ++j) {
            for (int s = 1; s < M; ++s) {
                if (a * i == s) {
                    res += cnt[i][j][s];
                }
            }
        }
    }
    cout << res << "\n";
}

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

    int z = 1;
    /// cin >> z;

    while (z--) {
        solve();
    }

    return 0;
}


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

using ll = long long;
using namespace std;
const int INFint = 2e9+1;
const ll INFll = 2e18+1;
ll MOD=1e9+7;


vector<ll> divisor(ll n){
  vector<ll> res;
  for (ll i(1);i*i<=n;i++){
    if (n%i==0){
      res.push_back(i);
      if (i != n/i) res.push_back(n/i);
    }
  }
  return res;
}

int main(){
  ll N,M;
  cin>>N>>M;
  vector<ll> yakusuu = divisor(M);
  sort(yakusuu.begin(),yakusuu.end());
  for(int i(0);i<int(yakusuu.size());i++){
    if(N<=yakusuu[i]) {
      cout << M/yakusuu[i] << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <climits>
#include <map>

constexpr int SINT_MAX = std::numeric_limits<int>::max();
constexpr int SINT_MIN = std::numeric_limits<int>::min();

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

template<class T>
T choose(bool b, T t, T f)
{
    if (b) return t;
    else return f;    
}

const char *YesNo(bool b)
{
    return choose(b, "Yes", "No");
}

const char *YESNO(bool b)
{
    return choose(b, "YES", "NO");
}

template<template<class...> class ContT, class ValueT, size_t Dim>
struct vec_type
{
    using type = ContT<typename vec_type<ContT, ValueT, Dim-1>::type>;
};

template<template<class...> class ContT, class ValueT>
struct vec_type<ContT, ValueT, 0>
{
    using type = ValueT;
};

template<class ValueT, size_t Dim = 1>
using vec_t = typename vec_type<std::vector, ValueT, Dim>::type;


template<class ValueT, size_t Dim, class = typename std::enable_if<Dim == 0>::type>
auto make_vec(ValueT value = ValueT()) -> ValueT
{
    return value;
}

template<class ValueT, size_t Dim, class... Rest>
auto make_vec(size_t size0, Rest... rest)
{
    auto vec = make_vec<ValueT, Dim-1>(rest...);
    return std::vector(size0, vec);
}

int diffabs(int l, int r)
{
    if (l < r) return r-l;
    else return l-r;    
}


///////////////////////////////////////////////////

ll P1;
map<int,ll> divmaps;
using memo_map = map<ll,ll>;

ll ff(ll n, memo_map &memo)
{
    if (auto it = memo.find(n); it != memo.end()) return memo[n];

    ll ans = (n >= LLONG_MAX / P1) ? LLONG_MAX : n * P1;


    for (auto [div, T] : divmaps)
    {
        if (n >= div)
        {
            ll fp = ff(n/div, memo);
            if (int m = n % div; m == 0)
                ans = min(ans, fp + T);
            else
            {
                ll fn = ff(n/div+1, memo);
                ans = min({ans, fp + T + P1 * m, fn + T + P1 * (div-m)});
            }
        }
    }

    // cout << "(" << n << "," << ans << ")" << endl;
    return memo[n] = ans;
}

ll f()
{
    ll N;
    cin >> N >> divmaps[2] >> divmaps[3] >> divmaps[5] >> P1;
    
    memo_map memo;
    return ff(N, memo);
}

int main()
{
    int T;
    cin >> T;
    for (int ttt = 0; ttt < T; ttt++)
    {
        ll ans = f();
        cout << ans << endl;
    }
}

Measured memory_bytes: 4264
import sys
sys.setrecursionlimit(10**9)

def BF(edges,n,s):
    inf=float("inf")
    d=[inf for i in range(n+1)]
    d[s]=0
    update=True
    cnt=0
    while 1:
      update=False
      for v,u,cost in edges:
        if cand[v]!=1 or cand[u]!=1:
          continue
        if d[v]!=inf and d[u]>d[v]+cost:
          d[u]=d[v]+cost
          update=True
      if update==False:
        break
      cnt+=1
      if cnt>n:
        return inf
    return -d[-1]

def DFS_1toN(v):
  for u in to[v]:
    if toflag[u]==0:
      toflag[u]=1
      DFS_1toN(u)
      
def DFS_Nto1(v):
  for u in ot[v]:
    if otflag[u]==0:
      otflag[u]=1
      DFS_Nto1(u)
    
n,m,p=map(int,input().split())
g=[]
to=[[] for _ in range(n+1)]
ot=[[] for _ in range(n+1)]
for _ in range(m):
  a,b,c=map(int,input().split())
  g.append([a,b,-(c-p)])
  to[a].append(b)
  ot[b].append(a)
toflag=[0]*(n+1)
toflag[1]=1
DFS_1toN(1)
otflag=[0]*(n+1)
otflag[n]=1
DFS_Nto1(n)
cand=[0]*(n+1)
for i in range(1,n+1):
  cand[i]=toflag[i]*otflag[i]
ans=BF(g,n,1)
if ans==float('inf'):
  print(-1)
else:
  print(max(ans,0))

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

int main(){
  string s;
  bool ok=true;
  cin>>s;
  for(int i=0;i<s.size();i++){
    if(i%2!=0){
      if(s.at(i)=='R')ok=false;
    }
    if(i%2==0){
      if(s.at(i)=='L')ok=false;
    }
  }
  if(ok)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}

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

#define N 2000

int func(int, int);

int an, a[N], maxnum = 0;

int main() {
    
    int bn, b[N], res;
    
    cin>>an;
    for(int i = 0; i < an; i++) {
        cin>>a[i];
        maxnum += a[i];
    }

    cin>>bn;
    for(int i = 0; i < bn; i++) cin>>b[i];
        
    for(int i = 0; i < bn; i++) {
       
      if( func(0, b[i]) ) cout<<"yes"<<endl;
      else cout<<"no"<<endl;
    }
    
    return 0;
}

int func(int i, int num) {
    
  if(num == 0) return 1;
  if(i >= an) return 0;

  int res = func(i+1, num) || func(i+1, num-a[i]);
  return res;
}



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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	os << v[0];
	for (int i = 1; i < v.size(); i++) os << " " << v[i];
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u; return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}

int N, M, K;
vvint G;
vint A, B;
int color[100005];
int nn[100005] = {};

vint ans;

int dfs(int u, int col) {
	if (color[u] != -1) return (0);
	color[u] = col;
	int ret = 1;
	for (auto &v : G[u]) {
		ret += dfs(v, col);
	}
	return (ret);
}

void Main() {
	cin >> N >> M >> K;
	G = vvint(N);
	A = vint(M);
	B = vint(M);
	ans = vint(N);	
	for (int i = 0; i < M; i++) {
		cin >> A[i] >> B[i]; --A[i], --B[i];
		G[A[i]].push_back(B[i]);
		G[B[i]].push_back(A[i]);
	}
	
	fill_n(color, 100005, -1);
	int cnt = 0;
	for (int i = 0; i < N; i++) {
		if (color[i] == -1) {
			ll num = dfs(i, cnt);
			nn[cnt] = num;
			cnt++;
		}
	}
	
	for (int i = 0; i < N; i++) {
		ans[i] = nn[color[i]] - (int)G[i].size() - 1;
	}
	
	for (int i = 0; i < K; i++) {
		int c, d; cin >> c >> d; --c, --d;
		if (color[c] == color[d]) {
			ans[c]--, ans[d]--;
		}
	}
	cout << ans << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


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

	public static void main(String[] args) throws Exception{
		int num = 998244353;

		// TODO Auto-generated method stub
 		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
 		PrintWriter out = new PrintWriter(System.out);
 		String input = bf.readLine();
 		int sum = 0;
 		for(int j =0 ;j<input.length();j++){
 			sum+=Integer.parseInt(input.charAt(j) + "");
 		}
 		
 		
 		out.println(sum%9 == 0 ? "Yes" : "No");
	 		
 		out.close();
 		
 		
 		
 	}
}
 	
 
//StringJoiner sj = new StringJoiner(" "); 
//sj.add(strings)
//sj.toString() gives string of those stuff w spaces or whatever that sequence is

 		
 		
 		
 		
	




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

int main() {
    int n;
    cin >> n;

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

    //sort(a,a+n);
    sort(a,a+n, greater<int>());

    int a_sum=0, b_sum=0;
    for(int i=0; i< n; i++){
        if(i%2==0){
            a_sum+=a[i];
        }else{
            b_sum+=a[i];
        }
    }
    std::cout << a_sum - b_sum << std::endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt(), m = scanner.nextInt();
			int[] x = IntStream.range(0, m).map(i -> scanner.nextInt()).sorted().toArray();
			Queue<Integer> queue = new PriorityQueue<>((a, b) -> Integer.compare(b, a));
			IntStream.range(1, m).forEach(i -> queue.add(x[i] - x[i - 1]));
			int sum = Arrays.stream(x).max().getAsInt() - Arrays.stream(x).min().getAsInt();
			System.out.println(sum - IntStream.range(1, Math.min(n, m)).map(i -> queue.poll()).sum());
		}
	}
}


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

ll min(ll a, ll b){
    if (a < b) return a;
    else return b;
}

ll max(ll a, ll b){
    if (a > b) return a;
    else return b;
}

int main(void){
    ll N; cin >> N;
    ll A[N]; for(ll i = 0; i < N; i++) cin >> A[i];
    
    map<ll, ll> mp;
    for(ll i = 0; i < N; i++){
        mp[A[i]-1] += 1;
    }
    
    for(ll i = 0; i < N; i++){
        cout << mp[i] << endl;
    }
}


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

int main() {
    int s;
    cin>>s;
    int n=s;
    int a = 0;
    while(n>0){
        a+=n%10;
        n/=10;
    }
    if(s%a){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
    return 0;
    
   
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n;
	map<pair<char, int>, int> m;
	for (int i=0;i<n;i++){
		char c; int x;
		cin >> c >> x;
		m[{c,x}] = 1;
	}
	for (int i=1;i<=13;i++){
		if (!m[{'S',i}]){
			cout << 'S' << ' ' << i << endl;
		}
	}
	for (int i=1;i<=13;i++){
		if (!m[{'H',i}]){
			cout << 'H' << ' ' << i << endl;
		}
	}
	for (int i=1;i<=13;i++){
		if (!m[{'C',i}]){
			cout << 'C' << ' ' << i << endl;
		}
	}
	for (int i=1;i<=13;i++){
		if (!m[{'D',i}]){
			cout << 'D' << ' ' << i << endl;
		}
	}
}


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

#include <iostream>
#include <fstream>

#include <iostream>
#include "bits/stdc++.h"

using namespace std;
typedef unsigned long long ll;
typedef int                     integer;
#define int                     long long
#define ii                      pair<int,int>
#define vii                     vector<pair<int,int>>
#define vi                      vector<int>
#define vvi                     vector<vector<int>>
#define f(a,b,c)                for(int a=b;a<c;a++)
#define s(x)                    in>>x
#define s2(x,y)                 in>>x>>y
#define s3(x,y,z)               in>>x>>y>>z
#define s4(x,y,z,w)             in>>x>>y>>z>>w
#define p(x)                    out<<x<<endl
#define p2(x,y)                 out<<x<<' '<<y<<endl
#define p3(x,y,z)               out<<x<<' '<<y<<' '<<z<<endl
#define p4(x,y,z,w)             out<<x<<' '<<y<<' '<<z<<' '<<w<<endl
#define pl(x)                   out<<x
#define pll(x)                  out<<x<<' '
#define range(v)                v.begin(),v.end()
#define rst(x)                  memset(x, -1, sizeof(x))
#define UNVISITED               -1
#define VISITED                 0
#define EXPLORED                2

#define EACH(x, a) for (auto& x: a)
template<class T> void read_v(T& x, std::istream& in) {
    in >> (x);
}
template<class A> void read_vec(vector<A>& x, std::istream& in) {
    EACH(a, x)
        read_v(a, in);
}

bool sortpairbysec(const pair<int,int> &a,const pair<int,int> &b){return (a.second < b.second);}
template <typename T>
T factmod(T a, T modulus){ int res = 1, i; for (i = 2; i <= a; i++){ res *= i; res%=modulus;} return res; }
template <typename T>
int powmod(T a,T b,int m){ int ans=1; while(b>0){if(b&1){ans*=a;ans%=m;}a*=a;a%=m;b>>=1;} return ans; }
template <typename T>
int power(T a, T b){ int ans=1; while(b>0){if(b&1){ans*=a;}a*=a;b>>=1;}return ans;}


void ssolve(std::istream& in, std::ostream& out){
    int x, k, d;
    s3(x, k, d);

    if(x>0){
        int quo = x/d;
        if(quo > k){
            p(x - (k * d));
            return;
        }
        x -= (quo * d);
        if(quo%2 != k%2){
            if(x>0){
                x -= d;
            }else{
                x += d;
            }
        }
        p(abs(x));
    }else{
        int quo = x/d;
        quo = abs(quo);
        if(quo > k){
            p(abs(x + (k * d)));
            return;
        }
        x += (quo * d);
        if(quo%2 != k%2){
            if(x>0){
                x -= d;
            }else{
                x += d;
            }
        }
        p(abs(x));
    }

    return;
}

class CWalkingTakahashi {
public:
void solve(std::istream& in, std::ostream& out) {
    ios_base::sync_with_stdio(false);
    in.tie(nullptr);out.tie(nullptr);
    int t;
    int READ = 0;
    if(READ) s(t);
    else t = 1;
    while(t--){
        ssolve(in, out);
    }
}
};

integer main() {
    CWalkingTakahashi solver;
    std::istream& in(std::cin);
     std::ostream& out(std::cout);
     solver.solve(in, out);
}

Measured memory_bytes: 3580