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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}
 
//Write From this Line

//const ll mod = 1e9+7;
//const ll mod = 998244353;
int main()
{
	string s;
	cin >> s;
	int ans = 0;
	int tmp = 0;
	rep(i,3){
		if(s[i] == 'R'){
			tmp ++;
			ans = max(ans, tmp);
		} else {
			tmp = 0;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> vp(n);
  for (auto& p : vp) {
    int x, l;
    cin >>x >> l;
    p = {x - l, x + l};
  }
  sort(vp.begin(), vp.end(), [](auto a, auto b){return a.second < b.second;});

  int ans = 0;
  int r = -2e9;
  for (auto p : vp) {
    if (r <= p.first) {
      ans++;
      r = p.second;
    }
  }
  cout << ans << endl;
}

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

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

signed main() {
    ll N,H,maxa=-123,ans=0;
    cin>>N>>H;
    vector<ll> b(N);
    rep(i,0,N){
        ll a;
        cin>>a>>b[i];
        maxa=max(maxa,a);
    }
    sort(begin(b),end(b));
    for (ll i=N-1; H>0 && i>=0 && b[i]>maxa; i--){
        H -= b[i];
        ans++;
    }
    if (H>0){
        ans += (H + maxa - 1) /maxa;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1024
import numpy as np
K = int(input())
lunlun_number = [[1, 2, 3, 4, 5, 6, 7, 8, 9]]
for _ in range(9):
    tmp = []
    for n in lunlun_number[-1]:
        if n % 10 != 0:  # 末尾が0の場合は-1した数がルンルン数にならないのでそれ以外を採用
            tmp.append(n * 10 + (n % 10 - 1))
        tmp.append(n * 10 + (n % 10))
        if n % 10 != 9:  # 末尾が9のときは+1した数がルンルン数にならないのでそれ以外を採用
            tmp.append(n * 10 + (n % 10 + 1))
    lunlun_number.append(tmp)
lunlun_number = [flatten for inner in lunlun_number for flatten in inner]
print(lunlun_number[K - 1])


Measured memory_bytes: 29592
#include<iostream>
using namespace std;
int main(){
long n,c,*p,i,j;
n=1000000;
p=new long[1000001];
for(p[1]=0,i=3;i<=n;i+=2)p[i]=1;
for(p[2]=1,i=4;i<=n;i+=2)p[i]=0;
j=3;
while(j*j<=n){
for(i=j;i<=n/j;i+=2)p[i*j]=0;
j++;
while(p[j]==0)j++;
}
while(cin>>n){
if(n==0)break;
for(c=0,i=3;i*2<=n;i++){
if(p[i]==1&&p[n-i]==1)c++;
}
cout<<c<<endl;
}
return 0;
}

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

#define IOS             ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define watch(x);       cout << "\n" <<  #x << " is: " << x << "\n";
#define ll              long long int
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define pb              push_back
#define nl              cout<<"\n"
#define gcd(a,b)        __gcd(a,b)
#define sq(a)           (a)*(a)
#define loop(i,a,b)     for (int i = a; i <= b; i++)
#define rloop(i,a,b)    for (int i = a; i >= b; i--)
#define sz(a)           a.size()
#define mod             1000000007
#define PI              2*acos(0.0)


int main()
{
    IOS
    int T=1;
    //cin>>T;
    while(T--)
    {
        int n;
        cin>>n;
        string s;
        cin>>s;
        ll r=0,g=0,b=0;
        loop(i,0,n-1)
        {
            if(s[i]=='R') r++;
            if(s[i]=='G') g++;
            if(s[i]=='B') b++;
        }
        ll tot=r*g*b;
        //int rgb=(int)'R'+(int)'G'+(int)'B';
        loop(i,0,n-1)
        {
            loop(j,i+1,n-1)
            {
                int k=2*j-i;
                if(k<n)
                {
                    if(s[i]!=s[j] and s[i]!=s[k] and s[j]!=s[k]) tot--;
                }
            }
        }
        cout<<tot;

    }
    return 0;
}


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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;cin >> s;
	int ans=0;
	rep(i,3){
		if(s[i]=='1') ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
S = str(input())
count = 0
for i in range(1,len(S)+1):
    if i%2 == 1:
        if S[i-1] == "L":
            count += 1
    else:
        if S[i-1] == "R":
            count += 1
if count == 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
N = int(input())
lst = []

for _ in range(N):
  l = [int(i) for i in input().split()]
  lst.append([sum(l)] + l)

lst.sort()

result = 0
count = 0
for i in lst[::-1]:
  result += i[count + 1] * (-1) ** count
  count = (count + 1) % 2

print(result)

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

typedef long long int lli;
const int MOD = 1000000007;
#define rep(i,n) for (int i = 0; i < n; i++)

using namespace std;

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

	int N, M, res; cin >> N >> M;
	if (N<M) {
		cout << "0" << endl;
	}
	else {
		cout << "10" << endl;
	}
}

Measured memory_bytes: 256
/*Shivam Bhalla */
/* f2016941@pilani.bits-pilani.ac.in */

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <algorithm>
#include <map>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iostream>
#include <string>
#include <cmath>
#include <cassert>
#include <bits/stdc++.h>
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
using namespace std;
long long maxv = 1e9;


long long X,Y,Z,K;
vector<long long>A;
vector<long long>B;
vector<long long>C;
int main(){
	cin>>X>>Y>>Z>>K;
	A.resize(X);
	B.resize(Y);
	C.resize(Z);
	for(int i=0;i<X;i++)
		cin>>A[i];
	for(int i=0;i<Y;i++)
		cin>>B[i];
	for(int i=0;i<Z;i++)
		cin>>C[i];
	sort(A.rbegin(),A.rend());
	sort(B.rbegin(),B.rend());
	sort(C.rbegin(),C.rend());
	vector<long long>ab;
	for(int i=0;i<X;i++){
		for(int j=0;j<Y;j++)
			ab.push_back(A[i]+B[j]);
	}
	sort(ab.rbegin(),ab.rend());
	vector<long long>abc;
	for(int i=0;i<(min(K,X*Y));i++){
		for(int j=0;j<Z;j++)
			abc.push_back(ab[i]+C[j]);
	}
	sort(abc.rbegin(),abc.rend());
	for(int i=0;i<K;i++)
		cout<<abc[i]<<"\n";
	return 0;
}


Measured memory_bytes: 43240
#include<bits/stdc++.h>
using namespace std;
int main()
{
 
  int n; cin>>n; int i,j; int a[n];
  for(i=0;i<n;i++)
    cin>>a[i];
  int ans[n]; ans[n-1]=0;
    for(i=n-2;i>=0;i--)
    { if(a[i]>=a[i+1])  ans[i]=ans[i+1] +1;
      else ans[i]=0;
    }
  int m=0;
  for(i=0;i<n;i++)
    m=max(m,ans[i]);
  cout<<m<<endl;
return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
/*-----------------------*/
#define FAST        ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL);
#define endl        "\n"
#define ff          first
#define ss          second
#define cc(x)       cout<<#x<<"="<<x<<" ";
#define CC(x)       for(auto xx: x) cout<<xx<<" ";
#define ee          cout<<"\n";
#define ll          long long
#define ull         unsigned long long
#define pii         pair<int,int>
#define mp          make_pair
#define all(x)      x.begin(),x.end()
#define ps(x)       push(x)
#define psb(x)      push_back(x)
#define psf(x)      push_front(x)
#define pp          pop()
#define ppb         pop_back()
#define ppf         pop_front()
#define OK          cout<<"Ok"<<"\n";
#define TESTS       ll test;cin>>test;for(ll   tcase=1;tcase<=test;tcase++)
/*------------------------*/
#define MAX int(1e6)
    string s;
bool is_ok(int ss,int e)
{
    int cnt=(e-ss+1)/2;
    for(int i=ss,j=e;cnt--;i++,j--)
    {
        if(s[i]!=s[j]) return 0;
    }
    return 1;
}
int main()
{
    FAST
    ll n;
    cin>>n;
    vector <ll> v(n+1);
    vector <ll> fre(n+1,0);
    vector <ll> cnt(n+1,0);
    for(ll i=1;i<=n;i++)
    {
        cin>>v[i];
        fre[v[i]]++;
    }
    ll sum=0ll;
    for(ll i=1;i<=n;i++)
    {
        cnt[i]= ( fre[i]*(fre[i]-1) ) /2;
        sum+=cnt[i];

    }
    for(ll i=1;i<=n;i++)
    {
        ll x= fre[v[i]]-1;
        cout<<sum-cnt[v[i]]+( x*(x-1) )/2ll<<endl;
    }

    return 0;
}


Measured memory_bytes: 7296
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll = long long;
using p = pair<int,int>;
using Graph = vector<vector<int>>;
int main(int argc, const char * argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

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

    return 0;
}

Measured memory_bytes: 3656
class UnionFind():
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0 for i in range(n)]

    def find(self, x):
        if self.par[x] == x:
            return x
        self.par[x] = self.find(self.par[x])
        return self.par[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        elif self.rank[y] < self.rank[x]:
            self.par[y] = x
        else:
            self.par[x] = y
            self.rank[y] += 1
        return

N, M = map(int, input().split())
p = [int(i) for i in input().split()]
uf = UnionFind(N)
for i in range(M):
    x, y = map(int, input().split())
    uf.unite(x-1, y-1)

ans = 0
for i in range(N):
    if uf.find(i) == uf.find(p[i]-1):
        ans += 1
print(ans)


Measured memory_bytes: 13812
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());


int main(){
    vector<int> month = {4, 6, 9, 11};
    string s;
    cin >> s;
    int a = stoi(s.substr(0, 2)), b = stoi(s.substr(2, 2));
    if(a == 0 && b == 0){
        cout << "NA" << endl;
    }else if(a == 0 && b <= 12){
        cout << "YYMM" << endl;
    }else if(b == 0 && a <= 12){
        cout << "MMYY" << endl;
    }else if(a <= 12 && b <= 12){
        cout << "AMBIGUOUS" << endl;
    }else if(a == 0 && b > 12){
        cout << "NA" << endl;
    }else if(b == 0 && a > 12){
        cout << "NA" << endl;
    }else if(a <= 12){
        cout << "MMYY" << endl;
    }else if(b <= 12){
        cout << "YYMM" << endl;
    }else{
        cout << "NA" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int h,w;
string s[50];
main()
{
	cin>>h>>w;
	int sx,sy;
	bool flagx=0,flagy=0;
	for(int i=0;i<h;i++)
	{
		cin>>s[i];
		for(int j=0;j<w;j++)if(s[i][j]=='@')sx=i,sy=j;
	}
	if(sy==0)
	{
		flagy=1;
		for(int i=0;i<h;i++)reverse(s[i].begin(),s[i].end());
		sy=w-1-sy;
	}
	if(sx%4)
	{
		flagx=1;
		for(int i=0;i<h/2;i++)swap(s[i],s[h-1-i]);
		sx=h-1-sx;
	}
	for(int i=sx-1;i>=0;i--)if(s[i][sy]!='*')s[i][sy]='#';
	int nx=0,ny=sy-1,nd=0;
	while(nx<h)
	{
		if(nd==0)
		{
			while(ny>=0)
			{
				if(s[nx][ny]!='*')s[nx][ny]='#';
				ny--;
			}
			ny++;
			if(nx+1<h&&s[nx+1][ny]!='*')s[nx+1][ny]='#';
			if(nx+2<h&&s[nx+2][ny]!='*')s[nx+2][ny]='#';
			ny++;
			nx+=2;
			nd=1;
		}
		else
		{
			while(ny<=(nx<=sx?sy-2:sy))
			{
				if(s[nx][ny]!='*')s[nx][ny]='#';
				ny++;
			}
			ny--;
			if(nx+1<h&&s[nx+1][ny]!='*')s[nx+1][ny]='#';
			if(nx+2<h&&s[nx+2][ny]!='*')s[nx+2][ny]='#';
			nx+=2;
			nd=0;
		}
	}
	nx-=2;
	while(ny+2<w)
	{
		ny++;
		if(s[nx][ny]!='*')s[nx][ny]='#';
		ny++;
		if(nd==0)
		{
			while(nx>=0)
			{
				if(s[nx][ny]!='*')s[nx][ny]='#';
				nx--;
			}
			nx++;
			nd=1;
		}
		else
		{
			while(nx<h)
			{
				if(s[nx][ny]!='*')s[nx][ny]='#';
				nx++;
			}
			nx--;
			nd=0;
		}
	}
	int d[]={0,1,0,-1,0};
	while(s[nx][ny]!='*')
	{
		s[nx][ny]='.';
		for(int r=0;r<4;r++)
		{
			int tx=nx+d[r],ty=ny+d[r+1];
			if(tx>=0&&ty>=0&&tx<h&&ty<w&&s[tx][ty]!='.')
			{
				nx=tx;
				ny=ty;
				break;
			}
		}
	}
	if(flagx)
	{
		for(int i=0;i<h/2;i++)swap(s[i],s[h-1-i]);
	}
	if(flagy)
	{
		for(int i=0;i<h;i++)reverse(s[i].begin(),s[i].end());
	}
	for(int i=0;i<h;i++)cout<<s[i]<<endl;
}


Measured memory_bytes: 3184
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <numeric>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <utility>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1e9 + 7
#define INF 1e9
#define PIE 3.14159265358979323

template <class T>
inline bool chmin(T &a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T>
inline bool chmax(T &a, T b) {if (a < b) {a = b; return true;} return false;}
template <class T>
T GCD(T a, T b) {if (b == 0) return a; else return GCD(b, a % b);}
template <class T>
inline T LCM(T a, T b) { return (a * b) / GCD(a, b);}

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> g(n);
    int a, b;
    rep(i, m){
        cin >> a >> b;
        a--;
        b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    queue<int> q;
    vector<int> this_way(n, 0);
    q.push(0);
    this_way[0] = 1;
    while(!q.empty()){
        int a = q.front();
        q.pop();
        for (int i = 0; i < g[a].size(); i++){
            if (this_way[g[a][i]] == 0){
                this_way[g[a][i]] = a + 1;
                q.push(g[a][i]);
            }
        }
    }
    rep(i, n) {
        if (!this_way[i]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    repk(i,1,n)
        cout << this_way[i] << endl;
    return 0;
}   

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

#define mod 1000000007

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

using namespace std;
typedef long long ll;
const long long INF = 1LL << 60;
 
int main(void){
	
	string S;
    cin >> S;

    if(S[0] == 'A' && S[1] == 'A' && S[2] == 'A')
        cout << "No" << endl;
    else if(S[0] == 'B' && S[1] == 'B' && S[2] == 'B')
        cout << "No" << endl;
    else
        cout << "Yes" << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
#include <climits>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
 
 
int main() {
    int D, G;
    cin >> D >> G;
    vector<int> p(D), c(D);
    for (int i = 0; i < D; i++) {
        cin >> p[i] >> c[i];
    }
    int mincount = INT_MAX;
    for (int mask = 0; mask < (1 << D); mask++) {
        int count = 0;
        int score = 0;
        for (int i = 0; i < D; i++) {
            if (mask & (1 << i)) {
                count += p[i];
                score += 100 * (i + 1) * p[i] + c[i];
            }
        }
        if (score >= G) {
            mincount = min(mincount, count);
        } else {
            for (int i = D - 1; i >= 0; i--) {
                if ((mask & (1 << i)) == 0) {
                    if (score + 100 * (i + 1) * (p[i] - 1) >= G) {
                        int add = 0;
                        while (score + 100 * (i + 1) * add < G) {
                            add++;
                        }
                        count += add;
                        mincount = min(mincount, count);
                    }
                    break;
                }
            }
        }
    }
    cout << mincount << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N;
    cin >> N;
    int B[N];
    for (int i = 0; i < N; i++){
        cin >> B[i];
    }
    int ans = B[0]+B[N-2];
    for(int i = 0 ; i < N-2; i++){
        ans += min(B[i], B[i+1]);
    }
    printf("%d\n",ans);

}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int top=0;
int S[1000];

void push(int a)
{
    S[++top] = a;
}

int pop()
{
    return S[top--];
}


int main()
{
    char s[100];
    int a;
    int b;

    while(scanf("%s",&s)!= EOF)
    {
        if( s[0] == '+' )
            push( pop() + pop() );
        else if( s[0] == '-' )
            {
                a = pop();
                b = pop();
                push(  b-a );
            }
        else if( s[0] == '*' )
            push( pop() * pop() );
        else push( atoi( s ) );
    }

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

    return 0;
}



Measured memory_bytes: 2736
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll a,b,d;
    char c;
    while(1)
    {
        cin>>a>>c>>b;
        if(c=='+') d=a+b;
        if(c=='-') d=a-b;
        if(c=='*') d=a*b;
        if(c=='/') d=a/b;
        if(c=='?') break;
        cout<<d<<endl;
    }
    return 0;
}



Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>

using namespace std;

int n, k, st;
int ans = 1e9;
int x[100005];

int main() {
  scanf("%d%d", &n, &k); st = n + 1;
  for(int i = 1; i <= n; i++)
    scanf("%d", &x[i]);
  for(int i = 1; i <= n; i++)
    if(x[i] >= 0) {st = i; break;}
  for(int r = st - 1; r <= n; r++) {
    if(r < k) continue;
    int ll = min(0, x[r - k + 1]);
    int rr = max(0, x[r]);
    ll = abs(ll); rr = abs(rr);
    ans = min(ans, min(ll * 2 + rr, rr * 2 + ll));
  } printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 640
# -*- coding: utf-8 -*-
"""
B - Digital Gifts
https://atcoder.jp/contests/abc119/tasks/abc119_b

"""
import sys


def main(args):
    N = int(input())
    total = 0
    BTC = 380000
    for _ in range(N):
        x, u = input().split()
        if u == 'JPY':
            total += float(x)
        else:
            total += float(x) * BTC
    print(total)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 3060
#include<iostream>
#include<map>
#include<string.h>
#include<queue>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<cstdlib>
#include<math.h>
#include<set>
#include<array>
using namespace std;

template<class T>inline bool chmax(T&a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T>inline bool chmin(T&a, T b) { if (a > b) { a = b; return 1; }return 0; }



#define rep(n) for(int i=0;i<(n);i++)
typedef pair<int, int> pii;

typedef long long ll;
typedef pair<ll, ll>pll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
const int MOD = 1000000007;
const int INF = 1 << 29;
const long long LINF = 1LL << 60;

int main() {
	
	int x,y;
	cin >> x >> y;
	int ans = 0;
	if (x == 1 && y == 1)ans+=400000;
	if (x == 1)ans += 300000;
	if (y == 1)ans += 300000;
	if (x == 2 )ans += 200000;
	if (y == 2)ans += 200000;
	if (x == 3 )ans += 100000;
	if (y == 3)ans += 100000;
	cout << ans << endl;
	return 0;
}

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

N = int(input())

a_list = [0]*100

for i in range(2, N+1):
	cur = i
	for j in range(2, i+1):
		while cur % j == 0:
			a_list[j] += 1
			cur //= j

answer = 0

count_2 = len(list(filter(lambda x: x >= 2, a_list)))
count_4 = len(list(filter(lambda x: x >= 4, a_list)))
count_14 = len(list(filter(lambda x: x >= 14, a_list)))
count_24 = len(list(filter(lambda x: x >= 24, a_list)))
count_74 = len(list(filter(lambda x: x >= 74, a_list)))

answer = count_74 + (count_24 * (count_2-1)) + (count_14 * (count_4-1)) + (count_4 * (count_4-1) * (count_2-2))/2

answer = int(answer)
print(answer)

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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  
  if (a+b > c+d) {
    cout << "Left" << endl;
  }
  
  else if (a+b < c+d) {
    cout << "Right" << endl;
  }
  
  else {
    cout << "Balanced" << endl;
  }   
}

Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include<string>
#include <numeric>
#include<math.h>
#include <bits/stdc++.h>
using namespace std;

int main(void) {
    char op;
    int a,b;
    cin>>a;
    cin>>op;
    cin>>b;
    if(op=='+')cout<<a+b<<endl;
    else cout<<a-b<<endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
N = int(input())
an = list(map(int, input().split()))

m4 = []
m2 = []
mo = []

for a in an:
    if a%4 == 0:
        m4.append(a)
    elif a%2 == 0:
        m2.append(a)
    else:
        mo.append(a)

if len(m4) >= len(mo):
    print('Yes')
elif len(m2) == 0 and len(m4) >= len(mo) - 1:
    print('Yes')
else:        
    print('No')


Measured memory_bytes: 14252
N, M, K = map(int, input().split())
MOD = 998244353

def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n - r] % p

fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % MOD)
    inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
    factinv.append((factinv[-1] * inv[-1]) % MOD)

ans = 0
for k in range(K+1):
    ans += M * pow(M-1, N-1-k, MOD) * cmb(N-1, k, MOD)
print(ans%MOD)

Measured memory_bytes: 32860
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
constexpr lint MOD = 1000000007;

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

struct UnionFind
{
    vector<int> par, rank;

    UnionFind(int N) {
        par = rank = vector<int>(N, 0);
        for (int i=0; i<N; i++) par[i] = i;
    }
    int find(int x) {
        if (par[x] == x) return x;
        else return par[x] = find(par[x]);
    }

    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;

        if (rank[x] < rank[y]) par[x] = y;
        else par[y] = x;
        if (rank[x] == rank[y]) rank[x]++;
    }

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

struct UndirectedGraph
{
    using Pint = pair<int, int>;
    int V;
    int E;
    vector<lint> weights;
    vector<vector<Pint>> to;
    vector<Pint> edges;
    UnionFind uf;

    UndirectedGraph(int V) : V(V), E(0),
                             to(vector<vector<Pint> >(V)),
                             uf(UnionFind(V)) {}

    void add_edge(int v1, int v2, lint w)
    {
        to[v1].push_back(Pint(v2, E));
        to[v2].push_back(Pint(v1, E));
        edges.push_back(Pint(v1, v2));
        weights.push_back(w);
        E++;
    }

    vector<int> edge_used;
    lint kruskal()
    {
        priority_queue<Pint, vector<Pint>, greater<Pint> > pq;
        for (int i=0; i<E; i++) pq.push(Pint(weights[i], i));

        lint ans = 0;
        while (!pq.empty())
        {
            Pint p = pq.top(); pq.pop();
            int v1 = edges[p.second].first;
            int v2 = edges[p.second].second;
            if (!uf.same(v1, v2))
            {
                uf.unite(v1, v2);
                ans += p.first;
                edge_used.push_back(p.second);
            }
        }
        return ans;
    }
};

int N, M;
lint X;

int main()
{
    cin >> N >> M >> X;
    UndirectedGraph graph(N);
    for (int i=0; i<M; i++)
    {
        int u, v, w;
        cin >> u >> v >> w;
        graph.add_edge(u-1, v-1, w);
    }

    lint lowest = graph.kruskal();

    lint ans = 0;
    if (lowest == X) ans = (power(2, N-1) - 2 + MOD) * power(2, M-N+1) % MOD;

    vector<int> cand = graph.edge_used;
    sort(cand.begin(), cand.end());

    int ng_num = 0, good_num = 0;

    for (int i=0; i<M; i++)
    {
        if (binary_search(cand.begin(), cand.end(), i)) continue;
        graph.edge_used = {i};
        graph.uf = UnionFind(N);
        graph.uf.unite(graph.edges[i].first, graph.edges[i].second);
        lint w = graph.kruskal() + graph.weights[i];
        if (w < X) ng_num++;
        if (w == X) good_num++;
    }
    ans += (2LL * (power(2, good_num) - 1 + MOD) % MOD) * power(2, M-N+1-good_num-ng_num);
    ans %= MOD;
    cout << ans << endl;
}


Measured memory_bytes: 384
#include<iostream>

using namespace std;

int main(){
  int n,i;
  
  //宝石の個数を入力（１以上２０以下の整数）
  cin >> n;
  //宝石の価値を入力（１以上５０以下の整数）
  int v[n];
  for(i=0;i<n;i++){
    cin >> v[i];
  }
  //"宝石のコストを入力（１以上５０以下の整数)
  int c[n];
  for(i=0;i<n;i++){
    cin >> c[i];
  }
  
 int x,y;
  for(i=0;i<n;i++){
    if(v[i]>c[i]){
    	x+=v[i];
        y+=c[i];
    }
  }
  cout << x-y << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<ll> VLL;
typedef vector<PLL> VP;
const static int INF = 1000000000;
const static int MOD = 1000000007;
const int dx[4]={1, 0, -1, 0};
const int dy[4]={0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i,n) for (ll i=0; i<(ll)(n); i++)
#define repd(i,n) for (ll i=n-1; i>=0; i--)
#define rept(i,m,n) for(ll i=m; i<n; i++)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PF push_front
#define PB push_back
#define SORT(V) sort((V).begin(), (V).end())
#define RVERSE(V) reverse((V).begin(), (V).end())
#define paired make_pair
#define PRINT(V) for(auto v : (V)) cout << v << " "
//charを整数に
int ctoi(char c) { if (c >= '0' && c <= '9') { return c - '0'; } return 0; }
// 累積和 for (int i = 0; i < N; ++i) s[i+1] = s[i] + a[i]; 
void cum_sum(int N,vector<double> a, vector<double> &s){ for(int i=0; i<N; i++){ s[i+1]=s[i]+a[i];}}
//ユークリッドの控除法
ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}
//最小公倍数
ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}
//素数判定
bool is_prime(long long n) {
    if (n <= 1) return false;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p == 0) return false;
    }
    return true;
}
int getdigit(ll num){
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}
//空白文字も入力 getline(cin, S);
//桁数指定 setprecision

int main()
{
    ios::sync_with_stdio(0); 
    cin.tie(0); 
    cout.tie(0);
    int N;
    cin >> N;
    int tmp=0;
    int maxi=0;
    int buf=0;
    rept(i,1,N+1){
        int count=0;
        buf=i;
        while(1){
            if(buf%2==0){
                count++;
                buf/=2;
            }
            else{
                if(maxi<=count){
                    maxi=count;
                    tmp=i;
                }
                break;
            }
        }
    }
    cout << tmp << endl;
}

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

using namespace std;
#define ll long long

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

    ll n;
    cin>>n;

    unordered_map<ll,ll> hmap;

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

    int q;
    cin>>q;

    ll sum = 0;
    for(auto it:hmap)
        sum += (it.first * it.second);

    for(int i=0;i<q;i++)
    {
        ll a,b;
        cin>>a>>b;

        ll val = hmap[a];
        hmap[a] = 0;
        sum += ( b-a) * val;
        hmap[b] += val;

        cout<<sum<<endl;
    }

    return 0;
}


Measured memory_bytes: 7024
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>
#include <cassert>
#include <numeric>
#include <string>
#include <cstring>
#include <cmath>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long int int64;




int main(int,  char **)
{
#ifdef LOCAL
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

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

    long long mn = 2, mx = 2;
    vector <int> v;
    for (int i = 0; i < n; i++)
    {
        int x;
        scanf("%d", &x);
        v.push_back(x);
    }
    reverse(v.begin(), v.end() );
    for (int x : v)
    {
        long long d = (mn + x - 1) / x;
        mn = d * x;
        long long dmax = mx / x;
        mx = dmax * x;

        if (mn > mx)
        {
            printf("-1\n");
            return 0;
        }

        mx += x - 1;
     //   eprintf("%lld %lld\n", mn, mx);
    }
    printf("%lld %lld\n", mn, mx);




	return 0;
}



Measured memory_bytes: 892
#include <iostream>

#define N_MAX 200000

using namespace std;

int main(){
    int N;
    int diff_max = 0;
    int min_b = 1000000001;
    int diff_max_index;
    long sum = 0;
    int A[N_MAX], B[N_MAX];
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> A[i] >> B[i];
        sum += A[i];
    }
    for(int i = 0; i < N; i++){
        if(A[i] > B[i]){
            diff_max = max(diff_max, A[i] - B[i]);
            min_b = min(min_b, B[i]);
        }
    }
    if(diff_max == 0){
        cout << 0 << endl;
    }else{
        cout << sum - min_b << endl;
    }
    
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define MAXN 200000
#define lowbit(x) ((x)&(-(x)))

using namespace std;
void get(int &v)
{
	char c;
	while((c=getchar())!=EOF&&isdigit(c)==0);
	v=c-'0';
	while((c=getchar())!=EOF&&isdigit(c))
		v=(v<<1)+(v<<3)+c-'0';
	return ;
}
int get()
{
	int v;
	char c;
	while((c=getchar())!=EOF&&isdigit(c)==0);
	v=c-'0';
	while((c=getchar())!=EOF&&isdigit(c))
		v=(v<<1)+(v<<3)+c-'0';
	return v;
}
priority_queue<int,vector<int>,greater<int> >q;
stack<int>s;
void chk(int n)
{
	int i,tmp;
	for(i=1;i<=50;i++)
		q.push(49);
	while(n--)
	{
		tmp=q.top();
		q.pop();
		tmp+=50;
		while(q.size())
		{
			s.push(q.top()-1);
			q.pop();
		}
		while(s.size())
		{
			q.push(s.top());
			s.pop();
		}
		q.push(tmp);
	}
	return ;
}
int main()
{
	long long k;
	cin>>k;
	puts("50");
	chk(k%50);
	while(q.size()>1)
	{
		cout<<q.top()+k/50<<' ';
		q.pop();
	}
	cout<<q.top()+k/50;
	return 0;
}
//g++ -g cc.cpp -o cc

Measured memory_bytes: 256
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE InstanceSigs #-}

import Control.Monad
import Data.List

main :: IO ()
main = do
    [n, _l] :: [Int] <- map read . words <$> getLine
    putStrLn =<< concat . sort <$> replicateM n getLine

Measured memory_bytes: 1404
#include<iostream>
#include<algorithm>
#define FOR(i,a,n) for(int i=a;i<n;i++)
using namespace std;
int n;
int a[100];
int main(){
  cin >> n;
  FOR(i,0,n) cin >> a[i];
  int asum=0,bsum=0;
  sort(a,a+n);
  if(n%2==0){
    FOR(i,0,n/2){
      bsum+=a[i*2];
      asum+=a[i*2+1];
    }
  }
  else{
    FOR(i,0,n/2){
      asum+=a[i*2];
      bsum+=a[i*2+1];
    }
    asum+=a[n-1];
  }
  cout << asum-bsum << "\n";
  return 0;
}


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

class B
{
	static void Main()
	{
		var s = Console.ReadLine();
		Console.WriteLine(string.Join("", s.Reverse()) == s && s[..(s.Length / 2)] == s[^(s.Length / 2)..] ? "Yes" : "No");
	}
}


Measured memory_bytes: 26572
s = input()
imin = 753
for i in range(len(s)-2):
  if(abs(int(s[i] + s[i+1] + s[i+2]) - 753) )< imin:
     imin = abs(int(s[i] + s[i+1] + s[i+2])-753)
print(imin)

Measured memory_bytes: 3060
import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;

void main() {
    while (true) {
        int n;
        scan(n);
        if (!n) return;
        auto a = readln.split.to!(int[]);
        a.sort();
        int ans = 10^^7;
        foreach (i ; 0 .. n-1) {
            ans = min(ans, a[i+1] - a[i]);
        }

        writeln(ans);
    }
}

void solve(int n, int a, int b, int[] p) {
    int difmax, ans;

    foreach (i ; a .. b + 1) {
        if (difmax <= p[i-1] - p[i]) {
            difmax = p[i-1] - p[i];
            ans = i;
        }
    }

    writeln(ans);
}

void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

Measured memory_bytes: 3116
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;

bool in(int h, int m){
    if((h == 17 && m >=30)||(h == 18)||(h == 19 && m <=30)) return true;
    return false;
}

signed main(){
    int s, t, sh, sm, th, tm;
    int d[49] = {0, 30, 50, 60, 70, 135, 165,
                6, 0, 35, 45, 60, 115, 150,
                13, 7, 0, 25, 40, 100, 135,
                18, 12, 5, 0, 25, 85, 130,
                23, 17, 10, 5, 0, 60, 115,
                43, 37, 30, 25, 20, 0, 50,
                58, 52, 45, 40, 35, 15, 0};

    while(cin >> s, s){
        cin >> sh >> sm >> t >> th >> tm;
        s--; t--;
        if(s > t) swap(s, t);
        int ans = d[s*7 + t] * 10;
        if((in(sh, sm)||in(th, tm)) && d[t*7 + s] <= 40) ans /= 2;
        if(ans % 50 != 0) ans = (ans / 50 + 1)*50;
        cout << ans << endl;
    }
}

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

#define ll long long
#define ull unsigned long long
#define pb push_back
#define pf push_front
#define pof pop_front
#define pob pop_back
#define mp make_pair
#define pll pair<ll,ll>
#define pii pair<int,int>
#define all(s) s.begin(),s.end()
#define vll vector<ll>
#define vi vector<int>
#define vpii vector<pii>
#define vpll vector<pll>
#define vd vector<double>
#define vull vector<ull>
#define vc vector<char>
#define vs vector<string>
#define fi first
#define se second
#define sz(x) x.size()
#define cinarr(n,a) for(int i = 0; i < n; i++) cin >> a[i];
#define coutarr(n,a) for(int i = 0; i < n; i++) cout << a[i] << (i+1==n?'\n':' ');
#define fori(i,a,b,x) for(int i = a; i <= b; i+=x)
#define ford(i,a,b,x) for(int i = a; i >= b; i-=x)
#define tc int t; cin >> t; for(int cs = 1; cs <= t; cs++)
#define IOS ios_base::sync_with_stdio(0); cin.tie(NULL);
#define ld long double
#define reset(x,y) memset(x,y,sizeof x);
#define sqr(x) 1LL*(x)*(x)
#define cube(x) 1LL*(x)*(x)*(x)
#define ub(v, a) upper_bound(all(v), a)
#define lb(v, a) lower_bound(all(v), a)
#define EPS 1e-10
#define INF 2000000000
#define mod 1000000007
#define minof(a) min_element(all(a))
#define maxof(a) max_element(all(a))
#define debug(val) cerr << "The value of " << #val << " is = " << val << endl;
#define testing cerr << "--------------------------\n";

ll fwt[200005],n,a[200005],h[200005];

void upd(ll x, ll v) {
	for(; x <= n; x+=x&-x) {
		fwt[x] = max(fwt[x],v);
	}
}

ll qry(ll x) {
	ll ret = 0;
	for(; x; x-=x&-x) {
		ret = max(ret,fwt[x]);
	}
	return ret;
}

int main() {
	IOS
	cin >> n;
	fori(i,1,n,1) {
		cin >> h[i];
	}
	fori(i,1,n,1) {
		cin >> a[i];
	}
	fori(i,1,n,1) {
		upd(h[i],qry(h[i]-1)+a[i]);
	}
	cout << qry(n) << endl;
}


Measured memory_bytes: 4992
#include"iostream"
#include<stdlib.h>
#include<stdio.h>
#include<time.h>
#include<list>
#include<map>
#include<string>
#include<algorithm> 
#include <queue> 
#include <sstream>
#include <fstream>
#include<cmath>
#define INF 100000000000
#define LL long long
using namespace std;
map<LL , LL> m;
vector<LL> v[100001];
long long N, M, K, ans,x[100000],sa;



int main() {
	cin >> N>>K;
	for (int i = 0; i < N; i++) {
		cin >> x[i];
	}
	sa = INF;
	for (int i = 0; i < N - K + 1; i++) {
		sa = min(sa, min(abs(x[i]), abs(x[i + (K - 1)])) + abs(x[i] - x[i + (K - 1)]));
	}
	cout << sa << endl;
	return 0;
}

Measured memory_bytes: 3456
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.nextLine());
    String[] S = sc.nextLine().split(" ");
    boolean f = false;
    for(int i = 0; i < N; i++){
      if(S[i].equals("Y")){
        f = true;
        break;
      }
    }
    System.out.println(f ? "Four" : "Three");
  }
}

Measured memory_bytes: 23892
from collections import defaultdict
from collections import deque
from collections import Counter
import itertools
import math

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

n = readInt()
p = readInts()
ans = 0
for i in range(n-1):
	if i+1==p[i]:
		p[i],p[i+1]=p[i+1],p[i]
		ans+=1

if p[-1]==n:
	ans+=1

print(ans)

Measured memory_bytes: 20608
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()

    fun dfs(x: Long, is7: Boolean = false, is5: Boolean = false, is3: Boolean = false): Int {
        if (x > n) {
            return 0
        }
        var r = 0
        if (is7 && is5 && is3) {
            r++
        }
        r += dfs(x * 10 + 7, true, is5, is3)
        r += dfs(x * 10 + 5, is7, true, is3)
        r += dfs(x * 10 + 3, is7, is5, true)
        return r
    }

    println(dfs(0))
}


Measured memory_bytes: 33720
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>
#include <bitset>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 2 - 170;


int main() {
    int n, c, k;
    cin >> n >> c >> k;
    vector<int> v;
    for (int i = 0; i < n; ++i) {
        int t;
        scanf("%d", &t);
        v.emplace_back(t);
    }
    sort(v.begin(), v.end());
    vector<bool> b(n+1, false);
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        if(b[i]) continue;
        int cnt = 1;
        b[i] = true;
        for (int j = i+1; j < n; ++j) {
            if(v[j] <= v[i]+k && cnt < c){
                b[j] = true;
                cnt++;
            }else break;
        }
        ans++;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 892
#include<stdio.h>
int main()
{
	int n,r[200000],min,k;
	scanf("%d",&n);
	for (int i = 0; i < n; ++i)
	{
		/* code */
		scanf("%d",&r[i]);
	}
	k = r[1] - r[0];
	min = r[0];
	for (int i = 0; i < n -1; ++i)
	{
		if (min > r[i])
		{
			min = r[i];
		} 
		if (k <  r[i + 1] - min)
		{
			k = r[i + 1] - min;
		}
		
	}
	printf("%d\n",k);
	return 0;
}


Measured memory_bytes: 2568
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
    
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x
        
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    
    def size(self, x):
        return -self.parents[self.find(x)]
    
    def isSame(self, x, y):
        return self.find(x) == self.find(y)

def solve():
    N, M = map(int, input().split())
    p = list(map(int, input().split()))
    uf = UnionFind(N+1)
    
    for _ in range(M):
        x, y = map(lambda elem: int(elem)-1, input().split())
        uf.unite(p[x], p[y])
    
    cnt = 0
    for i in range(1, N+1):
        if i == p[i-1]:
            cnt += 1
            continue

        if uf.isSame(i, p[i-1]):
            cnt += 1
    
    print(cnt)

if __name__ == '__main__':
    solve()

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

#define FAST ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define show(x) cout<<(x)<<endl
#define REP(i,a,n) for (int i=a;i<n;i++)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define UM unordered_map
#define PB push_back
#define V vector
#define EPS 1e-8
typedef unsigned long ul;
typedef long long ll;
typedef string str;
/*FIN*/
const ll INF = 1e9;
int main() {
	FAST;
	int n,k;
	V<int> h(100002,0);
	V<ll> dp(100002);
	cin>>n>>k;
	REP(i,1,n+1) cin>>h[i];

	dp[1] = 0;
	REP(i,2,n+1) {
		dp[i] = INF;
		REP(j,max(1,i-k),i) {
			dp[i] = min(dp[i],dp[j]+abs(h[i]-h[j]));
		}
	}
	show(dp[n]);
	return 0;
}


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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    vector<pair<int, int>> v(101);
    char c;
    int i = 0;
    while (cin >> v[i].second >> c >> v[i].first, v[i].second)
        i++;

    sort(ALL(v), greater<pair<int, int>>());

    int a[101], rank = 1;
    a[v[0].second] = 1;

    for (int i = 1; i < v.size(); i++)
    {
        if (v[i].first != v[i - 1].first)
        {
            rank += 1;
        }
        a[v[i].second] = rank;
    }

    int n;
    while (cin >> n)
        OP(a[n]);

    return 0;
}


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

int main(){
  int a, b;
  cin >> a >> b;
  int re = (a + b) % 2;
  if (re == 0){
    cout << (a + b) / 2 << endl;
  } else {
    cout << (a + b) / 2 + 1 << endl;
  }
}

Measured memory_bytes: 256
N = int(input())
W = list(map(int, input().split()))
S_min = sum(W)

for t in range(1,N):
    if S_min > abs(sum(W[:t])-sum(W[t:])):
        S_min = abs(sum(W[:t])-sum(W[t:]))
    else:
        break

print(S_min)


Measured memory_bytes: 38512
#include <iostream>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <cmath>
#define INF 100000000000
#define MOD 1000000007
#define ll long long int
//#define int long long int
using namespace std;

int main(){
  ll N; cin>>N;
  vector <ll> d;d.resize(N);
  for(int i=0;i<N;i++) cin>>d[i];
  sort(d.begin(),d.end());
  vector <ll> point(100010,0);
  for(int i=0;i<N;i++){
      point[0]++;
      point[d[i]+1]--;
  }

  for(int i=1;i<100010;i++){
      point[i] += point[i-1]; 
    // cout<<point[i]<<endl;
  }
  int num = 0;
  int ans = 0;
  int minp = -10;
  int maxp = -20;
  for(int i=1;i<=100010;i++){
      num = point[i];
     // cout<<num<<endl;
     
      if(num == N- num) {ans++;continue;}
      if(num < N-num ) break;
  }
  
cout<<ans<<endl;

    return 0;
}



Measured memory_bytes: 1792
/*
░░░░██████████████████
░░▄███████▀▀▀▀▀▀███████▄
░▐████▀▒ManavJ07▒▀██████▄
░███▀▒▒▒▒BITS▒▒▒▒▒▒▀█████
░▐██▒▒▒.........▒▒▒▒▒████▌
░▐█▌▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒████▌
░░█▒▄▀▀▀▀▀▄▒▒▄▀▀▀▀▀▄▒▐███▌
░░░▐░░░▄▄░░▌▐░░░▄▄░░▌▐███▌
░▄▀▌░░░▀▀░░▌▐░░░▀▀░░▌▒▀▒█▌
░▌▒▀▄░░░░▄▀▒▒▀▄░░░▄▀▒▒▄▀▒▌
░▀▄▐▒▀▀▀▀▒▒▒▒▒▒▀▀▀▒▒▒▒▒▒█
░░░▀▌▒▄██▄▄▄▄████▄▒▒▒▒█▀
░░░░▄██████████████▒▒▐▌
░░░▀███▀▀████▀█████▀▒▌
░░░░░▌▒▒▒▄▒▒▒▄▒▒▒▒▒▒▐
░░░░░▌▒▒▒▒▀▀▀▒▒▒▒▒▒▒▐
*/
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define LONGMAX 1e18
#define ll long long
#define dd double
#define MOD 1000000007
#define nl cout<<endl
#define rt ll Q[100005]={0}
#define mp make_pair
#define endl "\n"
#define test() ull t;cin>>t;while(t--)
#define pb push_back
#define ff first	
#define ss second
#define all(v) v.begin(),v.end()
#define s(ar,n) sort(ar,ar+n)
#define rs(ar,n) sort(ar, ar+n, greater<ll>()) 
#define oa(a,n) for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n) for(ll i=0;i<n;i++)cin>>a[i];
#define ov(a,n) for(ll i=n-1;i>=0;i--)cout<<a[i]<<" ";nl
#define maxa(ar,N) *max_element(ar,ar+N)
#define mina(ar,N) *min_element(ar,ar+N)
#define INF 1e9
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
ll powe(ll x,ll y){ll res=1;while(y>0){if(y&1)res=res*x;y=y>>1;x=x*x;}return res;}
ll mpowe(ll n,ll m){if(m==0)return 1;ll t=powe(n,m/2);t%=MOD;if(m%2==0)return (t*t)%MOD;return (((t*t)%MOD)*n)%MOD;}
ll logtwo(ll n){if(n==1)return 0;return logtwo(n/2)+1;}
void ceilsearch(ll ar[],ll low,ll high,ll x,ll &y){ll mid=(low+high)/2;if(low>high)return;if(ar[mid]>=x){y=mid;ceilsearch(ar,low,mid-1,x,y);}else{ceilsearch(ar,mid+1,high,x,y);}}
int main()
{
	fastio();
	ll fact[10];
	fact[0]=1;
	for(ll i=1;i<10;i++)
	{
	    fact[i]=fact[i-1]*i;
	}
	ll N;
	cin>>N;
	ll ar[N];
	ll br[N];
	cn(ar,N);
	cn(br,N);
	ll a=0;
	ll b=0;
	ll mn=1;
	vector <ll> v;
	set<ll> se;
	for(ll i=1;i<=N;i++)
	    se.insert(i);
	for(ll i=0;i<N-1;i++)
	{
	    ll c=0;
	    for(ll j=0;j<v.size();j++)
	    {
	        if(v[j]<ar[i]&&v[j]>mn)
	            c++;
	    }
	    a=a+((ar[i]-mn-c)*fact[N-i-1]);
	    se.erase(ar[i]);
	    v.pb(ar[i]);
	    mn=*se.begin();
	}
	v.clear();
	se.clear();
	mn=1;
	for(ll i=1;i<=N;i++)
	    se.insert(i);
	for(ll i=0;i<N-1;i++)
	{
	    ll c=0;
	    for(ll j=0;j<v.size();j++)
	    {
	        if(v[j]<br[i]&&v[j]>mn)
	            c++;
	    }
	    b=b+((br[i]-mn-c)*fact[N-i-1]);
	    se.erase(br[i]);
	    v.pb(br[i]);
	    mn=*se.begin();
	}
	cout<<abs(a-b)<<endl;
	cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr double EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max()/2;
constexpr int MOD = 1e9+7;

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

    int a,b,c,d;cin>>a>>b>>c>>d;
    cout<<min(a,b)+min(c,d)<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=1e5+5;
struct student{
	int num,id;
}a[N];
bool cmp(student x,student y){
	return x.num<y.num;
}
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i].num);
		a[i].id=i;
	} 
	sort(a+1,a+n+1,cmp);
	cout<<a[1].id;
	for(int i=2;i<=n;i++)
		cout<<' '<<a[i].id;
	return 0;
}

Measured memory_bytes: 1536
#include <stdio.h>
#include <string.h>
int main(){
  int a, b, c, d;

  scanf("%d%d%d%d", &a, &b, &c, &d);

  if(a*b >= c*d){
    printf("%d", a * b);
  }else if(a*b < c*d){
    printf("%d", c * d);
  }
  printf("\n");
  
}


Measured memory_bytes: 128
const input = require('fs').readFileSync('/dev/stdin', 'utf8');

const list = input.trim().split('\n');
const n = Number(list[0]);
const A = list[1].trim().split(' ');
const q = Number(list[2]);
const mi = list[3].trim().split(' ');

// const dp = {};
// const memo = (i, sum) => {
//   dp[sum] = true;
//   if (i === n) {
//     return;
//   }
//   memo(i + 1, sum);
//   memo(i + 1, sum + Number(A[i]));
// }
// memo(0, 0);

// for (let i = 0; i < q; i++) {
//   console.log(dp[mi[i]] ? 'yes' : 'no');
// }

// const dp = {};
// const memo = (i, m) => {
//   if (m <= 0) {
//     dp[i] = dp[i] || {};
//     return dp[i][m] = m === 0;
//   } 
//   if (i === n) {
//     return false;
//   }

//   dp[i][m] 
//   return memo(i + 1, m) || memo(i + 1, m - Number(A[i]));
// }


class KeyMap {
  constructor() {
    this.map = {};
  }
  get(...args) {
    let map = this.map;
    args.forEach(arg => {
      map[arg] = map[arg] || {};
      map = map[arg];
    });
    return map;
  }
}

const dp = new Map();
const keyMap = new KeyMap();
const memo = (i, m) => {
  if (dp.has(keyMap.get(i, m))) {
    // console.log('has');
    return dp.get(keyMap.get(i, m));
  }
  if (i === n || m === 0) {
    return m === 0;
  }

  const nI = i + 1;
  const nM = m - A[i];
  dp.set(keyMap.get(nI, m), memo(nI, m));
  dp.set(keyMap.get(nI, nM), memo(nI, nM));
  return dp.get(keyMap.get(nI, m)) || dp.get(keyMap.get(nI, nM));
}
for (let i = 0; i < q; i++) {
  console.log(memo(0, Number(mi[i])) ? 'yes' : 'no');
}
// console.log(dp);


Measured memory_bytes: 31940