akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
long long X[200200];
int F2[200200],F5[200200];
long long F25[70][30];
long long Sum[70][30];
int main()
{
  int N;
  cin>>N;
  for(int i=0;i<N;i++)
  {
    string S;
    cin>>S;
    bool Find=0;
    for(int iii=0;iii<S.length();iii++)
    	if(S[iii]=='.')
    	{
    		int xx=S.length()-iii-1;
    		xx=9-xx;
    		for(int ii=0;ii<xx;ii++)
    			S+='0';
    		S.erase(S.begin()+iii);
    		Find=1;
    		break;
		}
	if(!Find)
		S+="000000000";
	stringstream SS;
	SS<<S;
	SS>>X[i];
  }
//  for(int i=0;i<N;i++)
//  	cout<<X[i]<<" ";
///puts("");
  for(int i=0;i<N;i++)
  {
    int exp=-1;
	long long tmp=1;
    while(X[i]%tmp==0)
    {
      exp++;
      tmp*=2;
    }
    F2[i]=exp;
    exp=-1;
    tmp=1;
    while(X[i]%tmp==0)
    {
      exp++;
      tmp*=5;
    }
    F5[i]=exp;
   // cout<<i<<":F2="<<F2[i]<<",F5="<<F5[i]<<endl;
    F25[F2[i]][F5[i]]++;
  }
  for(int i=0;i<70;i++)
  	for(int j=0;j<30;j++)
  		for(int ii=i;ii<70;ii++)
  			for(int jj=j;jj<30;jj++)
  				Sum[i][j]+=F25[ii][jj];
	long long Ans=0;
	for(int i=0;i<N;i++)
	{
		Ans+=Sum[max(0,18-F2[i])][max(0,18-F5[i])];
		if(F2[i]>=9&&F5[i]>=9)
			Ans--;
	}
	cout<<Ans/2ll<<endl;
	return 0;
}

Measured memory_bytes: 6672
n = int(input())
xs = list(map(int, input().split(' ')))

min_w = -1
for p in range(0, 101):
    w = 0
    for x in xs:
        w += pow(x - p, 2)
    if min_w == -1:
        min_w = w
    else:
        if min_w > w:
            min_w = w
print(min_w)


Measured memory_bytes: 2940
#include "bits/stdc++.h"
using namespace std;

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

#define FOR(i, s, e) for (ll(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (ll(i) = (s); (i) > (e); (i)--)
#define debug(x) cout << #x << ": " << x << endl
#define mp make_pair
#define pb push_back
const ll MOD = 1000000007;
const int INF = 1e9;
const ll LINF = 1e16;
const double PI = acos(-1.0);
int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1};
int dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

/* -----  2017/06/03  Problem: ARC 075 A / Link: http://arc075.contest.atcoder.jp/tasks/arc075_a  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

ll N;
ll s[105];
ll dp[200000];
ll ans = 0LL;

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

  cin >> N;
  FOR(i, 0, N)cin >> s[i];

  dp[0] = 1;
  FOR(i, 0, N) {
	  FORR(j, 15000, -1) {
		  if(dp[j])
		  dp[j+s[i]] = dp[j];
	  }
  }
  FOR(i, 0, 10001) {
	  if (dp[i]&&i%10!=0)ans = max(ans, i);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
int main() {
	constexpr long long int mod = 998244353LL;
	int n; std::string str; std::cin >> n >> str;
	std::vector<std::vector<int>> indices(3);
	for (auto i = 0; i < str.size(); ++i) {
		int color = 0;
		switch (str[i]) {
		case 'B': ++color;
		case 'G': ++color;
		default: break;
		}
		indices[color].push_back(i);
	}
	std::vector<int> direction(3 * n, 0);
	for (auto i = 0; i < n; ++i) {
		for (int color = 0; color < 3; ++color) {
			if (indices[color][i] < indices[(color + 1) % 3][i] && indices[color][i] < indices[(color + 2) % 3][i]) {
				direction[indices[color][i]] = -1;
			}
			else if (indices[color][i] > indices[(color + 1) % 3][i] && indices[color][i] > indices[(color + 2) % 3][i]) {
				direction[indices[color][i]] = 1;
			}
		}
	}
	long long int sum = 1LL;
	std::vector<int> min(3, 0);
	std::vector<int> mid_for(3, 0);
	int rank = 0;
	for (auto i = 0; i < direction.size(); ++i) {
		int color = 0;
		switch (str[i]) {
		case 'B': ++color;
		case 'G': ++color;
		default: break;
		}

		switch (direction[i]) {
		case -1:++min[color]; break;
		case 0:
			int min_color, max_color;
			for (auto c = 0; c < 3; ++c) {
				if (indices[c][rank] > i) max_color = c;
				if (indices[c][rank] < i) min_color = c;
			}
			sum *= min[min_color]--;
			++mid_for[max_color];
			++rank;
			break;
		case 1: sum *= mid_for[color]--; break;
		default: break;
		}
		sum %= mod;
	}
	for (auto i = 2; i <= n; ++i) {
		sum *= i; sum %= mod;
	}
	std::cout << sum << std::endl;
}

Measured memory_bytes: 3324
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
const int maxn = 1e3+5;
int main()
{
    int b[maxn], a[maxn] = {0};
    int n, sum = 0;
    cin >> n;
    for (int i = 0; i < n - 1; i++)
        cin >> b[i];
    for (int i = 0; i < n - 2; i++){
           a[i+1] = min(b[i+1],b[i]);
    }
    a[n-1] = b[n-2];
    a[0] = b[0];
    for (int i = 0; i < n; i++)
    sum += a[i];
    cout << sum << endl;
    return 0; 
}

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

const int mod = 1000000007;

int mul(int x,int y){
   return (ll)x*y%mod;
}

int T[2][2];
void solve(){
   int n;
   string s,t;
   cin>>n>>s>>t;
   vector<int> v;
   for(int i=0;i<n;){
      int j;
      if(s[i]==s[i+1]){
         v.push_back(1);
         i = i+2;
      } else {
         v.push_back(0);
         ++i;
      }
   }
   int ret = 1;
   int op = v[0];
   T[0][0] = 2;
   T[0][1] = 2;
   T[1][0] = 1;
   T[1][1] = 3;
   for(int i=1;i<v.size();++i) {
      int nop = v[i];
      ret = mul(ret, T[op][nop]);
      op = nop;
   }
   if(v[0]==0){
      ret = mul(ret, 3);
   } else {
      ret = mul(ret,6);
   }
   printf("%d\n", ret);
}
int main() {
   //freopen("input.txt","r",stdin);
   solve();
}

Measured memory_bytes: 256
using System;

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        if (n % 2 == 0) Console.WriteLine((n / 2) * (n / 2));
        else Console.WriteLine((n - 1) / 2 * ((n - 1) / 2 + 1));
    }
}


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

int a, b;
string res = "Even";

int main(){
  cin >> a >> b;
  if(a % 2 == 1 && b % 2 == 1){
    res = "Odd";
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

namespace ConsoleApplication2
{
    class Program
    {

        static void Main(string[] args)
        {
            int gameCount = int.Parse(Console.ReadLine());
            int[] result = new int[2];
            for (int i = 0; i < gameCount; i++)
            {
                string[] line = Console.ReadLine().Split(' ');
                int iCompare = string.Compare(line[0], line[1]);
                if (iCompare < 0)
                {
                    result[1] += 3;
                }
                else if (iCompare > 0)
                {
                    result[0] += 3;
                }
                else
                {
                    result[0] += 1;
                    result[1] += 1;
                }
            }

            Console.WriteLine("{0} {1}", result[0], result[1]);
        }
    }
}

Measured memory_bytes: 9972
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main() {
  int N;
  cin >> N;
  vector< pair< int, int > > vc;
  REP(i, N) {
    int p, q;
    cin >> p >> q;
    vc.push_back(pair< int, int >(p, q));
  }

  sort(vc.begin(), vc.end(),
       [](const pair< int, int > &x, const pair< int, int > &y) {
         return x.second < y.second;
       });

  //  pair< int, int > p = vc.front();
  // cout << p.first << ' ' << p.second << '\n';
  int task = 0;
  bool flg = true;
  REP(i, N) {
    if (task + vc[i].first > vc[i].second) {

      flg = false;
      break;
    } else {
      task += vc[i].first;
    }
  }
  cout << (flg ? "Yes" : "No") << endl;
}

Measured memory_bytes: 2420
#include <iostream>
#include <string>
#include <climits>
#include <vector>
#include <algorithm>

using namespace std;

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

    string s;
    cin >> s;
    s = '0' + s;
    int n = s.size();

    vector<int> dp_cur = { 0, INT_MAX }; // текущее состояние динамики
    for (int i = n - 1; i >= 0; i--) // перебираем цифры
    {
        vector<int> dp_next = { INT_MAX, INT_MAX }; // следующее состояние динамики
        int z = s[i] - '0'; // текущая цифра
        for (int j = 0; j < 2; j++) // перебираем есть ли переход
        {
            if (dp_cur[j] == INT_MAX) continue;
            for (int x = 0; x < 10; x++)
            {
                int y = (x - j - z + 10) % 10; // (x - y - z + 10) % 10 -> y
                int j_next = (x - j - y) < 0; // будет ли переход
                dp_next[j_next] = min(dp_next[j_next], dp_cur[j] + x + y);
            }
        }
        dp_cur = dp_next;
    }

    cout << dp_cur[0] << "\n";

    return 0;
}


Measured memory_bytes: 2332
#include <iostream>
#include <vector>
#include <algorithm>

int main(){
    int tmp;
    std::vector<int> number;
    for(int i = 0; i < 3; i++){
        std::cin >> tmp;
        number.push_back(tmp);
    }
    std::sort(number.begin(), number.end());
    int ret = number[2]*10 + number[1] + number[0];
    std::cout << ret << std::endl;

    return 0;
}

Measured memory_bytes: 256
N,K=map(int,input().split())
n=N
S=input()
if S[-1]=="0":
    S+="1"
else:
    S+="0"
List=[]
ini=S[0]
now=0
zeronum=0
for i in range(N+1):
    if S[i]==ini:
        now+=1
        continue
    else:
        if ini=="1":
            List.append(now)
        else:
            List.append(now*(-1))
            zeronum+=1
        ini=S[i]
        now=1
if List[0]<0:
    List.insert(0,0)

sum=0
SUM=0

if zeronum<=K:
    print(n)
    quit()
N=len(List)
for i in range(2*K+1):
    if i%2==1:
        sum+=List[i]*(-1)
    else:
        sum+=List[i]
SUM=max(sum,SUM)

for i in range(6):
    List.append(0)
ind=0
for i in range(K+1,N//2+3):

    sum+=-List[ind]+List[ind+1]-List[2*i-1]+List[2*i]
    ind+=2
    SUM=max(sum,SUM)
print(SUM)


Measured memory_bytes: 45808
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main(){
	int n; cin >> n; vector<int> v[n];
	for(int i=0; i<n; i++) {
		string s; cin >> s;
		for(int j=0; j<n; j++) {
			if (s[j] == '1') {
				v[i].push_back(j);
			}
		}
	}
  int max_an = 0;
  for(int i=0; i<n; i++){
	int done = 1, p[n]; fill(p, p+n, -1); p[i] = 0;
	priority_queue<P, vector<P>, greater<P>> q; q.push({0,i});
	while(!q.empty()) {
		P pp = q.top(); q.pop();
		int fr = pp.second, id = pp.first;
      //cout << id <<" " << fr << endl; 
 		for(int x:v[fr]) {
			if (p[x] == -1) {
				p[x] = id+1; q.push({id+1,x}); done++;
			} else {
				if (p[x] != id+1 && p[x] != id-1) {
				  cout << -1 << endl; return 0;
				}
			}
		}
	}
	int an = 0;
	for(int i=0; i<n; i++) {
		an = max(an, p[i]+1);
	}
    max_an = max(an, max_an);
  }
	cout << max_an << endl;
}

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

int main()
{
	int stu[30];

	int i, n;

	for (i = 0; i < 30; i++){
		stu[i] = 100;
	}

	for (i = 0; i < 28; i++){
		cin >> n;
		stu[n-1] = n-1;
	}

	for (i = 0; i < 30; i++){
		if (stu[i] == 100){
			cout << i+1 << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1160
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
def resolve():
    N = ir()
    S = lr()
    T = lr()
    U = lr()
    V = lr()
    a = [[0]*N for i in range(N)]
    for k in range(64):
        val = [[bool(U[i]&(1<<k)), bool(V[i]&(1<<k))] for i in range(N)]
        d = [[-1]*N for i in range(N)]
        for i in range(N):
            x = val[i][0]
            if S[i] != x:
                for j in range(N):
                    if d[i][j] != x and d[i][j] != -1:
                        print(-1)
                        return
                    d[i][j] = x
        for j in range(N):
            x = val[j][1]
            if T[j] != x:
                for i in range(N):
                    if d[i][j] != x and d[i][j] != -1:
                        print(-1)
                        return
                    d[i][j] = x
        for _ in range(2):
            for i in range(N):
                x = val[i][0]
                if S[i] == x:
                    p = []
                    ok = False
                    for j in range(N):
                        if d[i][j] == -1:
                            p.append(j)
                        if d[i][j] == x:
                            ok = True
                    if ok:
                        continue
                    if len(p) == 0:
                        print(-1)
                        return
                    if len(p) == 1:
                        d[i][p[0]] = x
            for j in range(N):
                x = val[j][1]
                if T[j] == x:
                    p = []
                    ok = False
                    for i in range(N):
                        if d[i][j] == -1:
                            p.append(i)
                        if d[i][j] == x:
                            ok = True
                    if ok:
                        continue
                    if len(p) == 0:
                        print(-1)
                        return
                    if len(p) == 1:
                        d[p[0]][j] = x
        ni = []
        nj = []
        for i in range(N):
            filled = True
            for j in range(N):
                if d[i][j] == -1:
                    filled = False
                    break
            if not filled:
                ni.append(i)
        for j in range(N):
            filled = True
            for i in range(N):
                if d[i][j] == -1:
                    filled = False
                    break
            if not filled:
                nj.append(j)
        for i, ii in enumerate(ni):
            for j, jj in enumerate(nj):
                d[ii][jj] = (i+j)%2
        for i in range(N):
            for j in range(N):
                a[i][j] |= d[i][j]<<k
    for i in range(N):
        print(*a[i], sep=' ')
resolve()

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

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

  int N;
  cin >> N;
  vector<int> d(N);
  for (int i = 0; i < N; ++i) {
    cin >> d.at(i);
  }

  int ans = 0;
  for (int i = 0; i < N; ++i) {
    for (int j = i + 1; j < N; ++j) {
      ans += d.at(i) * d.at(j);
    }
  }

  cout << ans << endl;
  return 0;
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,D,A;
pair<ll,ll> P[202020];
ll DD[202020];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>D>>A;
	FOR(i,N) {
		cin>>x>>y;
		P[i]={x,(y+A-1)/A};
	}
	sort(P,P+N);
	P[N]={1LL<<60,0};
	
	ll sum=0;
	FOR(i,N) {
		if(i) DD[i]+=DD[i-1];
		P[i].second-=DD[i];
		if(P[i].second>0) {
			x=lower_bound(P,P+N,make_pair(P[i].first+2LL*D+1,-1LL<<60))-P;
			sum+=P[i].second;
			DD[i]+=P[i].second;
			DD[x]-=P[i].second;
		}
	}
	cout<<sum<<endl;
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 4992
def make_dict(S):
  dic = dict()
  for s in S:
    if s in dic.keys():
      dic[s] += 1
    else:
      dic[s] = 1
  return dic

N = int(input())
S = [input() for i in range(N)]
M = int(input())
T = [input() for i in range(M)]
blue = make_dict(S)
red = make_dict(T)
ans = 0
for s in blue.keys():
  tmp = blue[s]
  if s in red.keys():
    tmp -= red[s]
  ans = max(ans,tmp)
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;

const ll MOD = 1000000007;

ll modpow(ll x, ll n){
    if(n < 0) return 0;
    ll res = 1, r = x;
    while(n){
        if(n % 2) res = res * r % MOD;
        r = r * r % MOD;
        n /= 2;
    }
    return res;
}

ll dp[2][5002];

int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    int k = s.size();
    int d[5002];
    dp[0][0] = 1;
    d[0] = 1;
    for(int i = 1; i <= n; i++){
        for(int j = 0; j <= n; j++) dp[i % 2][j] = 0;
        for(int j = 1; j <= n; j++){
            dp[i % 2][j] = (dp[i % 2][j] + dp[(i + 1) % 2][j - 1] * 2) % MOD;
        }
        for(int j = 0; j <= n; j++){
            dp[i % 2][j] = (dp[i % 2][j] + dp[(i + 1) % 2][j + 1]) % MOD;
        }
        dp[i % 2][0] = (dp[i % 2][0] + dp[(i + 1) % 2][0]) % MOD;
        d[i] = dp[i % 2][0];
    }
    for(int j = 0; j <= n; j++) dp[0][j] = dp[1][j] = 0;
    ll ans = 0;
    dp[0][0] = 1;
    for(int i = 1; i <= n; i++){
        for(int j = 0; j <= n; j++) dp[i % 2][j] = 0;
        for(int j = 1; j <= n; j++){
            dp[i % 2][j] = (dp[i % 2][j] + dp[(i + 1) % 2][j - 1]) % MOD;
        }
        for(int j = 1; j <= n; j++){
            dp[i % 2][j] = (dp[i % 2][j] + dp[(i + 1) % 2][j + 1]) % MOD;
        }
        ans = (ans + dp[i % 2][k] * modpow(2, (i - k) / 2) % MOD * d[n - i] % MOD) % MOD;
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
#include<stdio.h>

int main(void)
{
  int n,m;
  int i,j;
  int a[100];
for(i=0;i<49;i++)
  a[i]=0;

  scanf("%d %d",&n,&m);

  for(i=0;i<2*m;i++){
    scanf("%d",&j);
    a[j]++;
  }

  for(i=1;i<=n;i++)
    printf("%d\n",a[i]);

    return 0;
}



Measured memory_bytes: 128
#include <stdio.h>

int main(void){
        int n, i, min=1000000, max=-1000000, a[10000]={};
        long long sum=0;

        scanf("%d", &n);


        for( i=0 ; i<n ; i++ )
                scanf("%d", &a[i]);

        for( i=0 ; i<n ; i++ ){
                sum+=a[i];

                if( a[i]>max )
                        max=a[i];

                if( a[i]<min )
                        min=a[i];
        }

        printf("%d %d %lld\n", min, max, sum);

        return 0;
}


Measured memory_bytes: 2080
#include <iostream>
#include <array>
#include <vector>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>

using namespace std;

typedef  pair<int,int> P;
typedef long long LL;
typedef vector<LL> VEC;
typedef vector<VEC> VVEC;

const LL INF=1<<30;
const LL MOD=1000000007;






int main(){
    string n;
    cin>>n;
    if((n[0]==n[1]&&n[1]==n[2])||(n[1]==n[2]&&n[2]==n[3])){
        cout<<"Yes"<<endl;

    }else cout<<"No"<<endl;
}



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

using namespace std;
long long  n,t1,a,t[1000002],wynik,m=1e9+7,x,suma,licz;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> a;
	n++;
	for(int i=n-a;i < n;i++)
		suma = (suma + i);
	for(int i=0;i < a;i++)
		licz = (licz + i);
	while(a <= n)
	{
		wynik = (wynik + suma - licz + 1);
		a++;
		suma = (suma + (n-a));
		licz = (licz + (a-1));
	}
	cout << wynik % m << endl;
}

Measured memory_bytes: 3656
#coding:utf-8
from collections import defaultdict
N,M=map(int,raw_input().split())
P=map(int,raw_input().split())
X=[];Y=[]
for i in range(M):
    x,y=map(int,raw_input().split())
    X.append(x);Y.append(y)

#### https://www.kumilog.net/entry/union-find#%E6%9C%80%E7%B5%82%E7%9A%84%E3%81%AA%E3%82%B3%E3%83%BC%E3%83%89
class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.size = [1 for _ in range(n)]

    def find(self, x):
        """
        x が属するグループを探索
        """
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        """
        x と y のグループを結合
        """
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.size[x] += self.size[y]

    def is_same(self, x, y):
        """
        x と y が同じグループか否か
        """
        return self.find(x) == self.find(y)

    def get_size(self, x):
        """
        x が属するグループの要素数
        """
        x = self.find(x)
        return self.size[x]
######################################################################################################
uf=UnionFind(N+1)
for x,y in zip(X,Y):
    uf.union(x,y)
groups=defaultdict(set)
for n in range(1,N+1):
    groups[uf.find(n)].add(n)
ans=N
for _,A in groups.iteritems():
    B=set()
    for a in A:
        B.add(P[a-1])
    ans-=len(A-B)
print(ans)    

        


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

#define ll long long
#define forn(i, n) for(int i=0; i<int(n); i++)
#define endl '\n'

const int N = 1e5+5;
ll w[N], v[N];

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

    ll n, W;
    cin>>n>>W;

    forn(i, n) cin>>w[i]>>v[i];
    ll dp[n+1][W+1];


    forn(i, n+1) {
        forn(j, W+1) {
            if(!i || !j) {
                dp[i][j] = 0;
                continue;
            }

            dp[i][j] = dp[i-1][j];
            if(w[i-1] <= j)
                dp[i][j] = max(dp[i][j], v[i-1] + dp[i-1][j-w[i-1]]);

        }
    }



    cout<<dp[n][W];
}
 


Measured memory_bytes: 82480
#include <stdio.h>

int main(void)
{
    int N;
    scanf("%d", &N);

    int seq[N];
    int i;

    for (i = 0; i < N; i++)
        scanf("%d", &seq[i]);

    int j, cnt = 0;

    for (i = 0; i < N; i++) {
        for (j = N - 1; j > i; j--) {
            if (seq[j] < seq[j - 1]) {
                int temp = seq[j];
                seq[j] = seq[j - 1];
                seq[j - 1] = temp;
                cnt++;
            }
        }
    }

    for (i = 0; i < N - 1; i++)
        printf("%d ", seq[i]);
    printf("%d\n", seq[N - 1]);

    printf("%d\n", cnt);

    return 0;
}

Measured memory_bytes: 600
n = int(input())
a = input()
r = [None] * (n + 1)
for i in range(n, 0, -1):
    r[i] = (ord(a[2 * i - 2]) + sum(r[i * 2::i])) % 2
print(r.count(1))
print(*(i for i, x in enumerate(r) if x))


Measured memory_bytes: 12028
import sys
input=sys.stdin.readline
n,k=map(int,input().split())
l=list(map(int,input().split()))
ok=max(l)
ng=0
def solve(m):
    s=0
    for i in l:
        s+=-((-i)//m)-1
    return s

while ok-ng>1:
    m=(ok+ng)//2
    if k<solve(m):
        ng=m
    else:
        ok=m
print(ok)

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

#define dump(x) cout << (x) << endl
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()

Int INF = 1e18;
Int mod = 1e9+7;
//Int mod = 998244353;

typedef struct {
    double x, y;
} p_t;

int main() {
    Int n, m;
    cin >> n >> m;
    vector<queue<Int>> q(n);
    for (Int i = 0; i < n; i++) {
        for (Int j = 0; j < m; j++) {
            Int x;
            cin >> x;
            q[i].push(x);
        }
    }
    Int mi = INF;
    vector<bool> used(m + 1, false);
    for (Int i = 0; i < m; i++) {
        vector<Int> a(m + 1, 0);
        for (Int j = 0; j < n; j++) {
            a[q[j].front()]++;
        }
        Int ma = 0;
        Int index = 0;
        for (Int j = 1; j <= m; j++) {
            if (ma < a[j]) {
                ma = a[j];
                index = j;
            }
        }
        used[index] = true;
        mi = min(mi, ma);
        for (Int j = 0; j < n; j++) {
            while (!q[j].empty() and used[q[j].front()]) {
                q[j].pop();
            }
        }
    }
    dump(mi);
    return 0;
}

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

using namespace std;

int main() {

	long n,i,counter;

	cin >> n;
	vector<long> a(n+1);

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

	i = 1;
	counter =1;
	while (1) {
		if (a[i] == 2) {
			cout << counter << endl;
			return 0;
		}
		i = a[i];

		if (counter > n) {
			cout << "-1" << endl;
			return 0;
		}
		counter++;
	}


	return 0;
}

Measured memory_bytes: 1152
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	v := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&v[i])
	}

	sort.Sort(sort.IntSlice(v))

	ans := float64(v[0])
	for i := 1; i < n; i++ {
		ans = (ans + float64(v[i])) / 2
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
void Main()
{
    long n, p;
    cin >> n >> p;
    string s;
    cin >> s;

    if(p == 2 || p == 5){
        long sum = 0;
        for (long i = 0; i < n; i++)
        {
            if((s[i] - '0') % p == 0){
                sum += (long)i+1;
            }
        }
        cout << sum << endl;
    }else{
        vector<long> sm(s.size()+1); // sの下i桁の数 % p
        vector<long> cm(p); // i = sの下i桁の数 % p となる数
        sm[0] = 0;
        cm[0] = 1;
        long e = 1;
        for (long i = 1; i <= s.size(); i++)
        {
            sm[i] = (((s[s.size()-i] - '0') * e) % p + sm[i-1]) % p;
            cm[sm[i]]++;
            e = (e * 10) % p;
        }
        long sum = 0;
        for (long i = 0; i < p; i++)
        {
            if(cm[i] >= 2)
                sum += (long)cm[i] * (cm[i]-1) / 2;
        }
        cout << sum << endl;
    }

    // s[i..j] % p == 0 % p
    // (s[i..n] - s[j..n]) / 10^(n-j) % p == 0 % p
    // (s[i..n] % p) - (s[j..n] % p) == 0 % p
    // s[i..n] % p == s[j..n] % p
    
}
 
int main(int argc, char **argv)
{
    Main();
    return 0;
}

Measured memory_bytes: 5220
#include <stdio.h>
int main(){
	int a,b;
	scanf("%d %d",&a,&b);
	if(a<b){
	printf("a < b\n");
	}else if(a>b){
	printf("a > b\n");
	}else if(a==b){
	printf("a == b\n");
	}
	return 0;
}


Measured memory_bytes: 2052
// STRIVER_79 
// Lets goto the next level 
// AIM 6* at CC and CM at CF *__* 

#include <algorithm>
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define mod (int)(1e9 + 21)
#define all(a) a.begin(),a.end()
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define tc(t) int t; cin >> t; while (t--)
#define int long long
#define ll long long 
#define pb emplace_back
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL)
#define in(x) scanf("%intd", &x)
#define rr return 0
#define prec(n) fixed<<setprecision(n)
#define maxheap priority_queue<int>
#define minheap priority_queue<int, vector<int>, greater<int> >
#define inf (int)(1e18)
#define ini(a, i) memset(a, i, sizeof(a))
#define fi first
#define se second
#define kitna se
#define endl "\n"
#define pi pair<int, int>
#define LL long long 
const int MAXN = (int)((1e5) + 10);
int gcd(int a,int b) { if (a == 0) return b; return gcd(b%a, a);}
int max(int a,int b){if(a>b) return a; else return b;}
int min(int a,int b){if(a<b) return a; else return b;}  
bool isPrime(int N){ for(int i=2;i*i<=N;++i){if(N%i==0) return false;}return true;}
int cbrt(int x){ int lo=1,hi=min(2000000ll,x);while(hi-lo>1){int mid=(lo+hi)/2;if(mid*mid*mid<x){lo=mid;}else hi=mid;}if(hi*hi*hi<=x) return hi;else return lo;} 
const int dx[4] = {-1, 1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
const int nax =  (int)(1*1e5+10);

// int SPF[N+5];

// void SOF()
// {
//     SPF[1] = 1;
//     for (int i=2; i<N; i++)
//         SPF[i] = i;
//     for (int i=4; i<N; i+=2)
//         SPF[i] = 2;
 
//     for (int i=3; i*i<N; i++)
//         {
//         if (SPF[i] == i)
//             {
//             for (int kon=i*i; kon<N; kon+=i)
//                 if (SPF[kon]==kon)
//                    SPF[kon] = i;
//             }
//         }
// }
int n,m; 
int dp[nax];
vector<int>vec[nax]; 
bool vis[nax]; 

void dfs(int node, int prev)
{
	vis[node] = 1; 
	
	for(auto it:vec[node])
	{
		if(!vis[it])
			dfs(it,node); 

		dp[node] = max(dp[node],dp[it]+1);
	}
}






signed main(){

int t=1; 
//cin >> t;
// string s; 
// getline(cin,s);

while(t--)
{
	ini(dp,0); 
	cin >> n >> m;
	for0(i,m)
	{
		int x,y;
		cin >> x >> y; 
		vec[x].pb(y);
		//vec[y].pb(x); 
	}

	for1(i,n)
	{
		if(!vis[i])
			dfs(i,0); 
	}
	int ans = 0;

	for1(i,n) ans = max(ans,dp[i]);

	cout << ans;







}

rr;
}

Measured memory_bytes: 8576
from sys import stdin
n, k = map(int, stdin.readline().rstrip().split())
gems = list(map(int, stdin.readline().rstrip().split()))
total = -99999999999
for i in range(min(n, k)+1):
    for j in range(min(n, k)+1):
        if i + j <= min(n, k):
            tmp = gems[:i] + gems[n-j:]
            tmp.sort()
            for l in range(min(k-i-j, len(tmp))):
                if tmp[l] < 0:
                    tmp[l] = 0
            total = max(total, sum(tmp))


print(total)

Measured memory_bytes: 3188
//設定言語check
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <limits.h>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <queue>
using namespace std;

long long int ansgudge(long long int a){
  if(a >=1000000007) return ansgudge(a - 1000000007);
  else if(a < 0) return ansgudge(a + 1000000007);
  else return a;
}
long long int modinv(long long int a, long long int mod){
  long long int ans = 1 , n = mod - 2 ;
  while(n > 0){
    if(n & 1) ans = (ans * a) % mod ;
    a = (a * a) % mod ;
    n = n >> 1 ;
  }  
  return ans ;
}  

int main(){
  int N, W, M ;
  cin >> N ;
  long long int A[N], total = 0, dob[N], ans = 0 ;
  for(int i=0;i<N;i++){
    cin >> A[i] ;
    dob[i] = (A[i] * A[i]) % 1000000007 ;
    total = (total + A[i]) % 1000000007 ;
  }
  ans = (total * total) % 1000000007 ;
  for(int i=0;i<N;i++){
    ans += (1000000007 - dob[i]) ;
    ans %= 1000000007 ;
  }
  ans = ans * modinv(2ll,1000000007ll) ;
  ans = ans % 1000000007 ;
  cout << ans << endl ;
  return 0 ;
}  

Measured memory_bytes: 6716
# if true


# include <iostream>
# include <string>

int main()
{
    std::string s;
    std::cin >> s;

    auto isGood = true;
    
    auto last = '\0';
    for (auto c : s)
    {
        if (c == last) isGood = false;
        last = c;
    }

    if (isGood) std::cout << "Good";
    else        std::cout << "Bad";



    return 0;
}

# endif

Measured memory_bytes: 256
N, X, Y = map(int, input().split())

d = {}

for i in range(1, N):
    for j in range(i + 1, N + 1):
        if j >= Y and i <= X:
            d[(i, j)] = min(j - i - (Y - X) + 1, j - i)    
        elif i <= X:
            d[(i, j)] = min(j - i, X - i + 1 + Y - j)    
        elif j >= Y:
            d[(i, j)] = min(j - i, i - X + 1 + j - Y)    
        else:
            d[(i, j)] = min(j - i, i - X + 1 + Y - j)

ans = [0] * (N - 1)

for k, v in d.items():
    ans[v - 1] += 1

for v in ans:
    print(v)

Measured memory_bytes: 272116
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <iterator>  // std::back_inserter()
#include <set>
#include <map>
#include <algorithm>  // std::copy()
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;

#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for (int i=0; i < (int)(n); i++)  // 0 ~ n-1
#define REPN(i, n) for (int i=1; i <= (int)(n); i++)  // 1 ~ n
#define MIN(vec) min_element(ALL((vec)))  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(ALL((vec)))
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(ALL((vec)), 0)  // 0 は初期値
#define COPY(vec1, vec2) copy(ALL(vec1), back_inserter(vec2))  // vec1をvec2にコピーする vec2は空にしておく必要あり
typedef long long ll;

const int MOD = 1000000007;  // 1 000 000 007

int ctoi(char c) {
    // 'a' == 97, 'z' == 122
    // int a = 'a', z = 'z';
    if ('a' <= c && c <= 'z') {
        return (int)c;
    }
    return -1;
}


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

    // input
    string w;
    cin >> w;
    vector<int> alphabet(26);
    // calc
    int int_w;
    REP(i, w.length()) {
        int_w = ctoi(w[i]) - 97;
        alphabet[int_w]++;
    }
    REP(i, 26) {
        if (alphabet[i]%2 != 0) {
            cout << "No" << "\n";
            return 0;
        }
    }
    
    cout << "Yes" << "\n";
    
    return 0;
}


Measured memory_bytes: 256
defmodule Main do
  def main do
    a = IO.read(:line) |> String.trim
    b = IO.read(:line) |> String.trim |> String.to_charlist
    c = IO.read(:line) |> String.trim
    [_head | tail] = b
    b = List.to_string(tail)
    IO.puts(String.first(a) <> String.first(b) <> String.last(c))
  end
end


Measured memory_bytes: 31224
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma warning(disable:4996)
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <list>
#include <set>
#include <ctime>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

const int INF = 100000000;
const int MAX_M = 100000;



int main(int argc, char *args[]) {
	int n, k, q;
	int A[100001];
	int point[100001];

	cin >> n >> k >> q;
	for (int i = 0; i < q; i++) cin >> A[i];

	for (int i = 0; i < n; i++) {
		point[i] = -q + k;
	}

	for (int i = 0; i < q; i++) {
		point[A[i] - 1]++;
	}
	
	for (int i = 0; i < n; i++) {
		if (point[i] <= 0) {
			cout << "No" << endl;
		}
		else {
			cout << "Yes" << endl;
		}
	}
}

Measured memory_bytes: 1408
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int a = sc.nextInt(),b = sc.nextInt();
    int ans = 0;
    for(int i = 1;i<=n;i++){
      int sum = 0;
      int trying = i;
      while(trying > 0){
        sum += trying - (trying / 10) * 10;
        trying = trying / 10;
      }
      if(a <= sum && sum <= b){
        ans += i;
      }
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 23124
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define FOR(i,a,n) for(i=a;i<n;i++)
#define swap(type,a,b) do{type t=a;a=b;b=t;}while(0);
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define INF 1000000000000000
#define MAX_V 200
#define MAX_E 10000
#define ll long long
typedef struct LIST{
	int to;
	ll cap;
	struct LIST *rev; //逆辺のポインタ
	struct LIST *next;
}Edge;

Edge *iter[MAX_V];
Edge new_edge[MAX_E];
Edge new_rev_edge[MAX_E];
int level[MAX_V];
int que[MAX_V];
int edge_size=0;

void add_edge(Edge **graph,int s,int t,ll c){
	new_edge[edge_size].to = t;      new_edge[edge_size].cap = c;
	new_rev_edge[edge_size].to = s;  new_rev_edge[edge_size].cap = 0;
	
	new_edge[edge_size].rev = &new_rev_edge[edge_size];
	new_rev_edge[edge_size].rev = &new_edge[edge_size];
	
	new_edge[edge_size].next = graph[s];      graph[s] = &new_edge[edge_size];
	new_rev_edge[edge_size].next = graph[t];  graph[t] = &new_rev_edge[edge_size];
	
	edge_size++;
	return;
}

void bfs(Edge **graph,int s){
	int front=0,rear=0,v;
	Edge *e;
	
	memset(level,-1,sizeof(level));
	level[s]=0;
	que[rear++]=s;
	
	while(front!=rear){
		v=que[front++];
		for(e=graph[v];e!=NULL;e=e->next){
			if(e->cap>0&&level[e->to]<0){
				level[e->to]=level[v]+1;
				que[rear++]=e->to;
			}
		}
	}
	return;
}

ll dfs(int v,int t,ll f){
	ll d; Edge *e;
	
	if(v==t) return f;
	
	for(;iter[v]!=NULL;iter[v]=iter[v]->next){
		e=iter[v];
		if(e->cap>0&&level[v]<level[e->to]){
			d=dfs(e->to,t,MIN(f,e->cap));
			if(d>0){
				e->cap-=d;
				e->rev->cap+=d;
				return d;
			}
		}
	}
	return 0;
}
ll max_flow(Edge **graph,int s,int t){
	ll flow=0,f;
	
	while(1){
		bfs(graph,s);
		if(level[t]<0) return flow;
		memcpy(iter,graph,sizeof(iter));
		while((f=dfs(s,t,INF))>0) flow+=f;
	}
}
Edge *g[MAX_V];
int a[101];
int main(void)
{
	int n,s,t,i,j;
	ll res=0;
	scanf("%d",&n);
	s=0,t=n+1;
	FOR(i,1,n+1){
	    scanf("%d",a+i);
	    if(a[i]>0){
	        add_edge(g,i,t,a[i]);
	        res+=a[i];
	    }else{
	        add_edge(g,s,i,-a[i]);
	    }
	    for(j=2*i;j<=n;j+=i) add_edge(g,i,j,INF);
	}
	printf("%lld\n",res-max_flow(g,s,t));
	return 0;
}
    

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a,b,c;
	scanf("%d %d",&a,&b);
	c=0;
	if(a>b){
		c=a-b;
		printf("%d\n",c);
	}
	else if(a<b){
		c=b-a;
		printf("%d\n",c);
	}
	else{
		printf("0\n");
	}
	return 0;
}


Measured memory_bytes: 2068
#![allow(unused_imports)]
use itertools::Itertools;
use num_traits::clamp;
use ordered_float::OrderedFloat;
use proconio::{fastout, input, marker::*};
use std::cmp::*;
use std::collections::*;
use superslice::*;

#[fastout()]
fn main() {
    input! {
        n: usize, k: usize,
        mut a: [i64; n],
    }
    let m = 1000000007i64;
    let mod_product = |acc: i64, &value: &i64| {
        (acc * value).rem_euclid(m)
    };

    if k == n || k % 2 == 1 && a.iter().all(|v| *v <= 0) {
        a.sort_by_key(|v| -*v);
        let ans = a.iter().take(k).fold(1, mod_product);
        println!("{}", ans);
        return;
    }

    a.sort_by_key(|v| Reverse(v.abs()));
    let mut plus = Vec::new();
    let mut minus = Vec::new();
    for i in 0..n {
        if a[i] >= 0 {
            plus.push(a[i]);
        } else {
            minus.push(a[i]);
        }
    }

    let mut ppos = 0;
    let mut mpos = 0;
    let mut vals = Vec::new();
    let mut retry = false;
    while vals.len() < k {
        if vals.len() < k - 1 && ppos + 1< plus.len() && mpos + 1 < minus.len() {
            if plus[ppos] * plus[ppos+1] < minus[mpos] * minus[mpos+1] {
                vals.push(minus[mpos]);
                vals.push(minus[mpos+1]);
                mpos += 2;
            } else {
                vals.push(plus[ppos]);
                vals.push(plus[ppos+1]);
                ppos += 2;
            }
        } else if vals.len() < k - 1 && mpos + 1 < minus.len() {
            vals.push(minus[mpos]);
            vals.push(minus[mpos+1]);
            mpos += 2;
        } else if ppos < plus.len() {
            vals.push(plus[ppos]);
            ppos += 1;
        } else {
            retry = true;
            break;
        }
    }
    let ans = if !retry {
        vals.iter().fold(1, mod_product)
    } else {
        a.sort_by_key(|v| v.abs());
        a.iter().take(k).fold(1, mod_product)
    };
    println!("{}", ans);
}


Measured memory_bytes: 9748
#include <bits/stdc++.h>
#define sp ' '
#define nyan "(=^・ω・^=)"
#define mkp make_pair
#define intmax 2147483647
#define llmax 9223372036854775807
#define lP pair<ll,ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;
const int mod = 1000000007, mod998 = 998244353;

int H, W;
bool h[100], w[100];
char a[100][100];

int main() {
	cin >> H >> W;
	for (int i = 0; i != H; ++i) {
		for (int j = 0; j != W; ++j) {
			cin >> a[i][j];
			if (a[i][j] == '#') {
				h[i] = w[j] = true;
			}
		}
	}
	for (int i = 0; i != H; ++i) {
		if (h[i]) {
			for (int j = 0; j != W; ++j) {
				if (w[j]) {
					cout << a[i][j];
				}
			}
			cout << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        checked
        {
            var mod = 1000000007;
            var N = int.Parse(Console.ReadLine());
            var A = new List<long>();
            var line = Console.ReadLine().Split(" ");
            for (int i = 0; i < N; i++)
            {
                A.Add(long.Parse(line[i]));
            };

            var sums = new List<long>();
            long sum = 0;
            for (int i = 1; i < N; i++)
            {
                sum = sum + A[i];
                sums.Add(sum);
            }
            sum = sum % mod;
            sum = sum * A[0];
            sum = sum % mod;

            for (int left = 0; left < N - 2; left++)
            {
                sum += A[left + 1] * ((sums[N - 2] - sums[left]) % mod);
                sum = sum % mod;
            }
            Console.WriteLine(sum);
        }
    }
}

Measured memory_bytes: 53012
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		long A = sc.nextInt();
		long B = sc.nextInt();
		long mul = A * B;
		System.out.print(mul / gcd(A, B));
	}

	private static long gcd(long a, long b) {
		while (a * b != 0) {
			if (a >= b) {
				a = a % b;
			} else {
				b = b % a;
			}
		}
		return Math.max(a, b);
	}
}

Measured memory_bytes: 22740
#include<iostream>

using namespace std;

int main() {
	int N, M, X;
	cin >> N >> M >> X;
	
	int A[M+1];
	for (int i = 1; i <= M; ++i) {
		cin >> A[i];
	}

	if (A[M] < X) cout << "0";
	
	int left = 0;
	int right = 0;
	for (int j = 1; j <= M; ++j) {
		if (A[j] < X) ++left;
		else ++right;
	}
	
	if (left < right) cout << left;
	else cout << right;

	return 0;
}

Measured memory_bytes: 256
from collections import Counter

n, k = map(int, input().split())
a = list(map(int, input().split()))

count = []
c = Counter(a) # dict {'a': 3, 'b': 4, ...}
for i in c:
    count.append(c[i])

count.sort(reverse = True)
print(n - sum(count[:k]))


Measured memory_bytes: 100552
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<pair<ll, ll>> vpll;
typedef pair<ll, ll> pll;
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define yes(a) printf(a ? "yes\n" : "no\n")
#define Yes(a) printf(a ? "Yes\n" : "No\n")
#define YES(a) printf(a ? "YES\n" : "NO\n") 
const long double PI = acos(-1);
const long long INF = (1 << 30);
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(const ll a, const ll b){return ((a)+(b)-1)/b;}

ll h, w;
string s[51];
ll dist[51][51];

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

  ll n;
  cin >> n;
  cout << n * (n-1) / 2 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7;
const ll LINF=1e18;
using namespace std;
#define int long long

int pw(int n,int k){
  int res=1;
  while(k--)res*=n;
  return res;
}

signed main(){
  int N,K;cin>>N>>K;
  typedef pair<int,int> P;
  std::vector<P> ans;
  for(int i=1;i<=N;i++)for(int j=0;pw(2,j)<i;j++)if(i&pw(2,j))ans.push_back(P(i,pw(2,j)));
  cout<<ans.size()<<endl;
  for(P p:ans)cout<<p.first<<" "<<p.second<<endl;
  for(int i=0;i<K;i++){
    int rr=0;
    for(int j=0;j<9;j++){
      if(pw(2,j)>N)break;
      cout<<pw(2,j)<<endl;
      string s;cin>>s;
      if(s=="Yes"){rr=-1;break;}
      if(s=="Near")rr+=pw(2,j);
    }
    if(rr==-1)continue;
    cout<<rr<<endl;string t;cin>>t;
  }
}



Measured memory_bytes: 3308
/**
 * File    : A.cpp
 * Author  : Kazune Takahashi
 * Created : 2018-9-15 20:56:47
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <functional>
#include <random> // auto rd = bind(uniform_int_distribution<int>(0, 9), mt19937(19920725));
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
// start = std::chrono::system_clock::now();
// double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int N, x;
int a[100010];

int main()
{
  cin >> N >> x;
  for (auto i = 0; i < N; i++)
  {
    cin >> a[i];
  }
  sort(a, a + N);
  int ans = 0;
  for (auto i = 0; i < N; i++)
  {
    if (a[i] > x)
    {
      x = 0;
      break;
    }
    else
    {
      x -= a[i];
      ans++;
    }
  }
  if (x > 0)
  {
    ans--;
  }
  cout << ans << endl;
}

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

int main(){
    int A=0,B=0,result[2];
    cin >> A >>B;

    result[0] = A + B;
    result[1] = A * B;
    result[2] = A - B;

    sort(result, result+3);



    cout << result[2]<< endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void debug(String str) {
        boolean debug = false;
        if (debug != false) {
            return;
        }
        System.out.println(str);
    }

    static long[] C1;
    static long[] C2;

    static int MAX = 4000;
    static int MOD = 1000_000_007;
    static long fac[] = new long[MAX];
    static long finv[] = new long[MAX];
    static long inv[] = new long[MAX];

    public static void main(String[] args) {

        int N;
        int K;
        int mod = 1000_000_007;

        try (Scanner sc = new Scanner(System.in)) {
            N = sc.nextInt();
            K = sc.nextInt();
        }
        COMinit();
        for(int i = 1;i< K+1;i++){
            long temp;
            temp = COM((N-K)+1,i);
            temp = (temp * COM(K-1,i-1))% MOD;
            System.out.println(temp);
        }

    }

    public static void COMinit() {
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for (int i = 2; i < MAX; 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;
        }
    }

    // 二項係数計算
    public static int COM(int n, int k) {
        if (n < k)
            return 0;
        if (n < 0 || k < 0)
            return 0;
        return (int) (fac[n] * (finv[k] * finv[n - k] % MOD) % MOD);
    }
}


Measured memory_bytes: 21972
from collections import deque
K = int(input())
q = deque([0])

cnt = 0
ans = []
while q:
  a = q.popleft()
  r = a % 10
  a *= 10
  for i in range(10):
    if abs(r - i) <= 1 or a == 0:
      if cnt < K and a + i != 0:
        q.append(a + i)
        ans.append(a + i)
        cnt += 1

print(ans[-1])

Measured memory_bytes: 10584
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second
#define mp make_pair
 
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

ll N, sum[100], ans = 0;

int Solve(){
  ll now = N;
  for (ll i = 2; i * i <= N; i++){
    int cnt = 0;
    while (now % i == 0){
      now /= i; cnt++;
    }

    int L = 0, R = 100;
    while (R - L > 1){
      int mid = (L + R) / 2;
      if (sum[mid] <= cnt) L = mid;
      else R = mid;
    }
    ans += L;
  }
  if (now > 1) ans++;
  cout << ans << endl;

  return 0;
}

int main(){
  scanf("%lld", &N);
  for (int i = 1; i < 100; i++) sum[i] = sum[i - 1] + i;


  Solve();
  return 0;
}


Measured memory_bytes: 3728