akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<stdio.h>
#include<string>
#include<numeric>
using namespace std;
#define pb push_back
#define pf push_front

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define sz(x) int(x.size())
#define INF 1e5
#define MODE 1000007
int main(){
	int n,x;
	cin>>n>>x;
	vi v(n);
	rep(i,n) cin>>v[i];
	int ans=0;
	int now=0;
	rep(i,n){
		now+=v[i];
		if(now<=x) ans++;
	}
	cout<<ans+1<<endl;
	}


Measured memory_bytes: 256
#include <vector>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;i++)
#define SORT(c) sort((c).begin(),(c).end())

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

  int n;
  cin >> n;

  REP(i, n) {
    int t, x, y;
    cin >> t >> x >> y;

    if(t%2 == 0 && (x+y)%2 == 0 || t%2 == 1 && (x+y)%2 == 1) {
      if(t >= (x+y)) {
        continue;
      }
    }

    cout << "No" << endl;
    return 0;
  }

  cout << "Yes" << endl;
  return 0;
}


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

int main(int argc, char** argv) {
	long long n,ans=0,r=0,g=0,b=0;
	string a;
	cin >> n >> a;
	a=' '+a;
	for(int i=1;i<=n;i++)
	{
		r+=a[i]=='R';
		g+=a[i]=='G';
		b+=a[i]=='B';
	}
	ans=r*g*b;
	for(int i=1;i<=n;i++)
	{
		for(int j=i+1;j<=n;j++)
		{
			int k=j+(j-i);
			if(k>n) break;
			if(a[i]!=a[j]&&a[j]!=a[k]&&a[k]!=a[i])
				--ans;
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 3196
import java.util.Scanner;
import java.util.Arrays;

public class Main{
public static void main(String[] args){
Scanner scan=new Scanner(System.in);
int x=scan.nextInt();
int a=x/500;
int b=x%500;
int c=b/5;

System.out.println(a*1000+c*5);


}
}

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

using i64 = int_fast64_t;
using f64 = double;
using p64 = pair<i64, i64>;

void solve() {
    i64 n;
    cin >> n;
    vector<p64> rl(n);
    for (auto& e : rl) {
        i64 x, l;
        cin >> x >> l;
        e = { x + l, x - l };
    }

    sort(begin(rl), end(rl));

    i64 ans = 0;
    i64 cur = -INT64_MAX;
    for (auto& e : rl) {
        i64 r, l;
        tie(r, l) = e;
        if (cur <= l) {
            cur = r;
            ans++;
        }
    }

    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


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

using namespace std;

const int N = 3005;
int n, m, lcs[N][N];

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

	string s, t;
	cin>>s>>t;
	n = s.size(), m = t.size();
	s = '*' + s; t = '*' + t;

	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j){
			if(s[i] == t[j])lcs[i][j] = lcs[i - 1][j - 1] + 1;
			else lcs[i][j] = max(lcs[i - 1][j], lcs[i][j - 1]);
		}

	string ans;
	int i = n, j = m;
	while(i >= 1 && j >= 1){
		if(s[i] == t[j]){
			ans.push_back(s[i]);
			i--; j--;
		}
		else if(lcs[i][j] == lcs[i - 1][j])i--;
		else j--;
	}
	reverse(ans.begin(), ans.end());
	cout<<ans<<"\n";
	return 0;
}

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

#define CIN2(a,b) long long a,b;cin >> a >> b;
#define CIN3(a,b,c) long long a,b,c;cin >> a >> b >> c;
#define rep(i,n) for(int i=0,i##_len=(n); i<i##_len; ++i)
#define MAX(p,q)((p)>(q)?(p):(q))
typedef long long lli;

int main(){
    vector<lli> v(5,0);
    lli n;cin >> n;
    rep(i,5){
        cin >> v[i];
    }
    lli m = *min_element(v.begin(),v.end());
    cout << 4 + (lli)ceil((double)n/m) << endl;
}


Measured memory_bytes: 256
sa = input()
sb = input()
sc = input()

def judges(lis):
    if lis[0] == 'a':
        judge=1
    elif lis[0] == 'b':
        judge=2
    else:
        judge=3
    return judge

import sys

judge = 1
while(1):
    if judge == 1:
        try:
            judge = judges(sa)
            sa = sa[1:]
        except IndexError:
            print('A')
            break
    
    elif judge == 2:
        try:
            judge = judges(sb)
            sb = sb[1:]
        except IndexError:
            print('B')
            break
    else:
        try:
            judge = judges(sc)
            sc = sc[1:]
        except IndexError:
            print('C')
            break


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
const int maxn = 1<<18;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	string s;
	cin >> s;
	int g = 0, r = 0, p = 0;
	for(auto i : s) {
		if(p+1 > g) {
			r -= i == 'p';
			g++;
		} else {
			r += i == 'g';
			p++;
		}
	}
	cout << r;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Debug_array(a,n) for (ll i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (ll i=(s); i<=(e); i++)
#define Fod(i,s,e) for (ll i=(s)-1; i>=(e); i--)
#define pii pair<ll,ll>
#define fi first
#define se second
#define endl "\n"
#define mp make_pair
#define big_prime 15486277
#define bigger_prime 179424697
#define biggest_prime 32416188691
//#define random_shuffle(indices.begin(), indices.end());
//std::random_device rd;
//std::mt19937 g(rd());
//std::shuffle(v.begin(), v.end(), g);
using namespace __gnu_pbds; 
using namespace std;
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
// template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 0
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE


typedef long long ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set; 

#define Mod 1000000007
#define MAX 5002

bool dist(vector<ll>& a,vector<ll>& b){
	ll c = 0;
	For(i,0,a.size()){
		c += (a[i]-b[i])*(a[i]-b[i]);
	}
	ll d = sqrt(c);
	return d*d==c;
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll n,d;cin>>n>>d;
	vector<ll> a[n];
	For(i,0,n){
		For(j,0,d){
			ll x;cin>>x;
			a[i].pb(x);
		}
	}

	ll ans=0;
	For(i,0,n) For(j,i+1,n) if(dist(a[i],a[j])) ans++;
	cout<<ans<<endl;





























	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];
    ll now = 0;
    ll ans = 0;
    rep(i, n) {
        if (a[i] == 0) {
            ans += now/2;
            now = 0;
        } else {
            now += a[i];
        }
    }
    ans += now/2;
    cout << ans << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define MO 1000000007
#define mem(a,s) memset(a,s,sizeof(a))
#define IOS ios_base::sync_with_stdio(0); cin.tie(NULL);
#define lop(i,s,e) for(int i=s;i<e;i++)
#define lopi(i,s,e) for(int i=s;i>=e;i--)
#define prina(a,n) for(int i=0;i<=n;i++)cout<<a[i]<<" ";cout<<endl; 
#define prin2da(a,n,m) lop(i,1,n){lop(j,1,m)cout<<a[i][j]<<" ";cout<<endl;}
#define atout(v) for(auto x:v) cout<<x<<" ";cout<<endl;
#define atin(v) for(auto &x:v) cin>>x;
#define vl vector<ll >
#define vi vector<int >
#define lb lower_bound
#define ub upper_bound
#define sort(a) sort(a.begin(),a.end())  
#define mp make_pair
#define all(v) v.begin(),v.end() 
#define pll pair<ll,ll>
using namespace std;

void dfs(vector<vector<ll>> &g, vector<bool> &visited, ll node) {
	visited[node]=true;
	for(auto x:g[node]) {
		if(!visited[x]) {
			dfs(g,visited,x);
		}
	}
	return;
}

void solve() {
	ll n,m;
	cin>>n>>m;
	vector<vector<ll>> g(n+1);
	lop(i,0,m) {
		ll u,v;
		cin>>u>>v;
		g[u].pb(v);
		g[v].pb(u);
	}
	vector<bool> visited(n+1,false);
	ll ans=0;
	lop(i,1,n+1) {
		if(!visited[i]) {
			ans++;
			dfs(g,visited,i);
		}
	}
	cout<<ans-1<<endl;
	return;
}

int main() {
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	#endif

	ll t=1;
	while(t--) {
		solve();
	}

	return 0;
}

Measured memory_bytes: 10368
#include<bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
const lint mod=1e9+7;

int main()
{
  int n, m;
  cin >> n >> m;
  std::vector<int> a(n);
  REP(i,n) cin >> a[i];

  int cnt = 0;
  double sum = accumulate(ALL(a),0);
  REP(i,n){
    if(a[i] >= sum/(4*m)) cnt++;
  }

  string res = "No";
  if(cnt >= m) res = "Yes";

  cout << res << "\n";
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;


int main(){
  ll n; cin >> n; vl high(n); ll count = 0; ll maxnum = 0;
  rep(i,n){
    ll x; cin >> x; high.at(i) = x;
  }
  
  rep(i,n-1){
    if(high.at(i) >= high.at(i+1)){
      count++;
    }
    else{
      maxnum = max(maxnum,count);
      count = 0;
    }
  }
  
  cout << max(count,maxnum) << endl;
}
      

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

using namespace std;

int main() {
    int n;
    cin >> n;
    int i, h[n];
    for(i=0; i<n; i++) {
        cin >> h[i];
    }
    int cost[n];
    cost[0] = 0;
    cost[1] = abs(h[1] - h[0]);

    for(i=2; i<n; i++) {
        cost[i] = min(abs(h[i] - h[i-1])+cost[i-1], abs(h[i] - h[i-2]) + cost[i-2]);
    }

    cout << cost[n-1] << endl;
}



Measured memory_bytes: 1024
#include <iostream>
#include<list>
#include<vector>
using namespace std;

int main()
{
    int n,q;
    cin>>n>>q;
    vector<int> v[n];
    int tp1,tp2,a;
    while(q--){
        cin>>tp1;
        switch(tp1){
        case 0:
            cin>>tp2>>a;
            v[tp2].push_back(a);
            break;
        case 1:
            cin>>tp2;
                for(int i=0;i<v[tp2].size();i++){
                    if(i!=0)cout<<" ";
                    cout<<v[tp2][i];
                }
                cout<<"\n";
            break;
        case 2:
            cin>>tp2;
            v[tp2].clear();
            break;
        }
    }
}



Measured memory_bytes: 5796
#include <bits/stdc++.h>
using namespace std;
int main()
{
	char a[15];
	long long len,s=0,m=0;
	cin>>a;
	len=strlen(a);
	for(int i=0;i<(1<<(len-1));i++)
	{
		m=a[0]-'0';
		for(int j=0;j<len-1;j++)
		{
			if(i&(1<<j))
			{
				s+=m;
				m=0;
			}
			m=m*10+(a[j+1]-'0');
		}
		s+=m;
	}
	cout<<s<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {

  int h,w;
  scanf("%d %d", &h, &w);
  char a[h][w+1];
  for (int i = 0; i < h; i++) {
    scanf("%s", a[i]);
  }
  int count = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (a[i][j] == '#') {
        count++;
      }
    }
  }
  if (count == h+w-1) {
    printf("Possible\n");
  } else {
    printf("Impossible\n");
  }

  return 0;
}

Measured memory_bytes: 128
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  int n; ll d; cin >> n >> d;
  int ans = 0;
  while (n--) {
    ll x, y; cin >> x >> y;
    ans += x * x + y * y <= d * d;
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3644
#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>;
 
int main() {
    string s;
    cin >> s;
    bool a = false;
    bool b = false;
    for(int i=0;i<3;++i){
        if(s[i] == 'A'){
            a=true;
        }
        else{
            b=true;
        }
    }
    if(a&&b){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define PI 3.14159265358979323846
#define int64 long long
#define uint64 unsigned long long
using namespace std;

int main()
{
	string ss;
	cin >> ss;
	for(int64 ii = 0;ii < ss.length();ii++)
	{
		if(ii == 5 || ii == 13)
		{
			cout << ' ';
		}
		else
		{
			cout << ss[ii];
		}
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 3596
///age yekam bekeshi beham is no problem ._.
#include<bits/stdc++.h>
#define size(a) (int)a.size()
#define int long long
#define F first
#define S second
#define pb push_back
using namespace std;
void null(){return ;}
const int maxn=3e5+7,INF=3e18+9237,mod=1e9+7;
string s,t;

int32_t main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>s;
	for(int i=0;i<size(s);i++){
		if(i%2==0)t+=s[i];
	}
	cout<<t;
}


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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(condition) if(condition){cout << "POSSIBLE" << endl;}else{cout << "IMPOSSIBLE" << endl;}
#define Possible(condition) if(condition){cout << "Possible" << endl;}else{cout << "Impossible" << endl;}
#define possible(condition) if(condition){cout << "possible" << endl;}else{cout << "impossible" << endl;}
#define Size(n) (n).size()

typedef long long ll;


using namespace std;

const int INF = 1e9,MOD = 1e9 + 7,ohara = 1e6;
const ll LINF = 1e18;


long long int n,cnt=0,a,b,c,d,cmp[100],cmpp[100],m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s[100],ans;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

      
      cin>>n;
      rep(i,99)cmpp[i]=INF;
      rep(i,n){
        map<char,ll> mp;
        cin>>s[i];
        rep(j,Size(s[i])){
          mp[s[i][j]]++;
        }
        for(char c='a';c<='z';c++){
          if(mp[c]==0)continue;
          rep(j,26){
            if(alph[j]==c){
              cnt=j;
              break;
            }
          }
          cmp[cnt]++;
          cmpp[cnt]=min(cmpp[cnt],mp[c]);
        }
      }
      rep(i,26){
        if(cmp[i]!=n){
          cmpp[i]=0;
        }
      }
      rep(i,26){
        if(cmpp[i]==0)continue;
        rep(j,cmpp[i]){
          ans+=alph[i];
        }
      }
      sort(all(ans));
      Cout(ans);
     

       
return 0;
}


Measured memory_bytes: 256
n,k = map(int,input().split())
p = list(map(lambda x: int(x)-1,input().split()))
c = list(map(int,input().split()))

ans = max(c)
if(ans <= 0):
    print(ans)
    exit()

for i in range(n):
    now = i
    score = [0]
    while(p[now] != i ):
        now = p[now]
        score.append(score[-1] + c[now])
    cyc_score = score[-1] + c[i]
    cyc = len(score)

    max_loop = k//cyc
    if(cyc_score <= 0):
        tmp = max(score[: min(k+1, cyc)])
    else:
        tmp = max(score) + (max_loop-1)*cyc_score
        tmp = max(tmp, max(score[:(k%cyc) + 1]) + max_loop*cyc_score)

    ans = max(ans,tmp)
print(ans)

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> mat;
#define FOR(i,a,b) for(int (i)=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define mset(a,x) memset(a,x,sizeof(a))
#define FASTIO cin.tie(0),ios::sync_with_stdio(0)
#define dbg(x) cout<<#x<<": "<<x<<endl;


int n, k;

int main() {
    cin >> n >> k;
    map<int, int> MP;
    rep(i, n) {
        int a;
        scanf("%d", &a);
        MP[a]++;
    }

    int m = MP.size();
    if (m <= k) {
        puts("0");
        return 0;
    }
    
    map<int, int> mp;
    for (auto&& i : MP) {
        mp[i.second]++;
    }

    int ans = 0;
    for (auto&& i : mp) {
        rep(j, i.second) {
            m--;
            ans += i.first;
            if (m <= k) break;
        }
        if (m <= k) break;
    }

    cout << ans << endl;
    


    return 0;
}

Measured memory_bytes: 9600
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC144A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, c;
            var word = Console.ReadLine().Split(' ');

            a = int.Parse(word[0]);
            b = int.Parse(word[1]);

            if (1 <= a && 1 <= b && a <= 9 && b <= 9) 
            {
                c = a * b;
            } 
            else
            {
                c = -1;
            }
            Console.WriteLine(c);
            Console.ReadKey();
            


        }
    }
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
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;
} 


int main(){
    ll k;cin >> k;
    if(k%5==0||k%2==0)cout << -1 <<endl,exit(0);
    ll p=0;
    ll cnt=0;
        while(true){
            cnt++;
            p*=10;p+=7;
            p%=k;
            if(p==0){
                cout << cnt <<endl;
                break;
            }
        }

}

Measured memory_bytes: 3592
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
    int n;
    cin>>n;
    vector<ll int> a(n,0);
    for(int i=0;i<n;i++)cin>>a[i];
    stack<ll int> s;
    int maxi=0;
    s.push(a[0]);
    for(int i=1;i<n;i++){
        if(a[i]>s.top()){
            int cnt=0;
            while(!s.empty()){
                s.pop();
                cnt++;
            }
          
            maxi=max(maxi,cnt-1);
        }
          s.push(a[i]);
    }
    if(s.empty()==false){
         int cnt=0;
            while(!s.empty()){
                s.pop();
                cnt++;
            }
        maxi=max(maxi,cnt-1);
    }
    cout<<maxi<<endl;
    // vector<vector<int>> a(n,vector<int>(m,0));
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define ll long long
#define si short int
#define speed ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define pill pair<ll,ll>
#define f first
#define s second
#define pilc pair<ll,char>
#define all(a) (a).begin(),(a).end()
#define rep(s,e,step) for(int i = (s); i < (e) ; i += step)
#define vrep(s,e,step) for(int j = (s); j < (e) ; j += step)
#define ex exit(0)
#define sz(a) (a).size()
#define triple pair<pill, ll>
using namespace __gnu_pbds;
using namespace std;
typedef gp_hash_table<int, short, hash<int>, equal_to<int>, direct_mod_range_hashing<int>, linear_probe_fn<>, hash_standard_resize_policy<hash_prime_size_policy, hash_load_check_resize_trigger<true>, true>> gp;

const ll N = 2e5 + 100;
const ll big = 1e18;
const ll block = 800;
const ll mod = 1e6;

ll n, s;
ll a[N];

int main() {
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		s += max(0ll, a[i - 1] - a[i]);
		a[i] = max(a[i - 1], a[i]);
	}
	cout << s;
		
}

/*

*/


Measured memory_bytes: 5176
<?php

$line = explode(' ', trim(fgets(STDIN)));
$sold_types = $line[0];
$type = $line[1];
$prices = explode(' ', trim(fgets(STDIN)));

sort($prices);
$min = 0;

for($i=0; $i<$type; $i++)
{
  $min += $prices[$i];
}

echo $min . PHP_EOL;


Measured memory_bytes: 16196
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <map>

#define ll long long
#define REP(i,n) for(int i = 0; i < n; i++)
#define PI 3.141592653589

using namespace std;

int gcd(int a, int b){return (a % b)? gcd(b, a % b) : b;}
int lcm(int a, int b){return a * b / gcd(a, b);}

void solve_A(){
    int x, y, z;
    cin >> x >> y >> z;
    cout << z << " " << x << " " << y;
    
}

void solve_B(){
    int n, m;
    cin >> n >> m;

    int all = 0;
    
    int a[n];
    REP(i,n){
        cin >> a[i];
        all += a[i];
    }

    int ctr = 0;
    int max = all /4/m;
    REP(i,n){
        if(a[i] >= max){
            ctr++;
        }
    }

    if(ctr >= m) cout << "Yes";
    else cout << "No";
}

void solve_C(){
    ll n, k;
    cin >> n >> k;

    ll ans1 = n/k;
    ll ans2 = n/k + 1;

    if(abs(n-ans1*k) < abs(n-ans2*k)) cout << abs(n-k*ans1);
    else cout << abs(n-k*ans2);
}

int main(void){
    solve_C();
    
    return 0;
}

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

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define read() 	        freopen("in.txt","r",stdin)
#define write()         freopen("out.txt","w",stdout)
#define sf(n) 	        scanf("%d",&n)
#define sfd(n)          scanf("%lf",&n)
#define sl(x)           scanf("%I64d",&x)
#define sfl(n) 	        scanf("%lld", &n)
#define sfc(n)          scanf(" %c",&n)
#define sful(n)         scanf("%ull",&n)
#define ull             unsigned long long int
#define endll           pf("\n")
#define pf              printf
#define pi              acos(-1.0)
#define eps 	        1e-10
#define mem(a,b)        memset(a,b,sizeof(a))
#define pb              push_back
#define xx              first
#define yy              second
#define pii             pair<int, int>
#define pll             pair<ll, ll>
#define MP make_pair
#define ll              long long
#define uniq(a)      a.erase(unique(a.begin(), a.end()), a.end())
#define cnd tree[idx]
#define lnd tree[idx<<1]
#define rnd tree[(idx<<1)+1]
#define lndp (idx<<1),(b),((b+e)>>1)
#define rndp ((idx<<1)+1),(((b+e)>>1)+1),(e)
#define inf 1999999999
#define MX 100005
#define mod 100000000007
#define var    int i,j,k,n,m,z=0,c=0,t,x,y,l,r,mid
//int dx[8]={0,0,1,1,-1,-1,1,-1};  //8 direction
//int dy[8]={1,-1,1,-1,1,-1,0,0};
//int dx[4]={1,-1,0,0};  //4 direction
//int dy[4]={0,0,1,-1};


ll int ans;
map<ll int, vector<ll int> > mp;
void findSubArrays(ll int arr[],ll int n)
{

   ll int sum = 0;

    for (ll int i = 0; i < n; i++)
    {
        sum += arr[i];
        if (sum == 0)
            ans++;

        if (mp.find(sum) != mp.end())
        {
            ans+=mp[sum].size();
        }
        mp[sum].push_back(i);
    }

}

ll int a[200005];
int main()
{
     ll var;
     cin>>n;
     for(i=0;i<n;i++)cin>>a[i];

    findSubArrays(a, n);

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 23680
use proconio::input;
use num::integer::gcd;

#[proconio::fastout]
pub fn main() {
    input! {
    k:usize,
    }
    let mut ans = 0;
    for a in 1..=k {
        for b in 1..=k {
            for c in 1..=k {
                ans += gcd(gcd(a, b), c);
            }
        }
    }
    println!("{}", ans);
}


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

namespace KCity
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] strInp = Console.ReadLine().Split(' ');
            int intInpN = int.Parse(strInp[0]);  
            int intInpM = int.Parse(strInp[1]);

            int intOut = (intInpN - 1) * (intInpM-1);

            Console.WriteLine(intOut);

            return;
        }
    }
}


Measured memory_bytes: 11092
/*Lucky_Glass*/
#include<map>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

const int N=1e5;

int cas,n;
long long A[N+3];
map<long long,int> cnt;

bool Solve2(){
	int stk[5]={},nstk=0;
	for(map<long long,int>::iterator it=cnt.begin();it!=cnt.end();it++){
		if(it->second!=n/3*2 && it->second!=n/3) return false;
		if(it->second==n/3*2) stk[++nstk]=it->first,stk[++nstk]=it->first;
		else stk[++nstk]=it->first;
	}
	sort(stk+1,stk+4);
	do{
		if((stk[3]^stk[1])==stk[2] && (stk[1]^stk[2])==stk[3] && (stk[2]^stk[3])==stk[1])
			return true;
	}while(next_permutation(stk+1,stk+4));
	return false;
}
bool Solve3(){
	int stk[5]={},nstk=0;
	for(map<long long,int>::iterator it=cnt.begin();it!=cnt.end();it++){
		if(it->second!=n/3) return false;
		stk[++nstk]=it->first;
	}
	sort(stk+1,stk+4);
	do{
		if((stk[3]^stk[1])==stk[2] && (stk[1]^stk[2])==stk[3] && (stk[2]^stk[3])==stk[1])
			return true;
	}while(next_permutation(stk+1,stk+4));
	return false;
}
int main(){
//	freopen("circle.in","r",stdin);
//	freopen("circle.out","w",stdout);
//	scanf("%d",&cas);
	cas=1;
	while(cas--){
		cnt.clear();
		scanf("%d",&n);
//		bool fail=false;
		for(int i=1;i<=n;i++){
			scanf("%lld",&A[i]);
			cnt[A[i]]++;
		}
		if(cnt.size()>3){
			printf("No\n");
			continue;
		}
		switch(cnt.size()){
			case 1:
				if(cnt.begin()->first==0) printf("Yes\n");
				else printf("No\n");
				break;
			case 2:
				printf("%s\n",Solve2()?"Yes":"No");
				break;
			case 3:
				printf("%s\n",Solve3()?"Yes":"No");
				break;
		}
	}
	return 0;
}
/*
15: 001111
24: 011000
44: 101100
15 * 10
24 * 10
15 24 15 24 44 44 24 24 15 44 44 15 15 44 15 15 15 24 44 24 44 44 44 24 24 24 15 24 15 44
*/

Measured memory_bytes: 5632
#include <stdio.h>

int main() {
    int x, a, b;
    scanf("%d %d %d", &x, &a, &b);
    if (b <= a)
        puts("delicious");
    else {
        if (b > a+x)
            puts("dangerous");
        else
            puts("safe");
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define _GLIBCXX_DEBUG
#define FOR(i, a, b) for (int i=(a); i<(b); i++)
typedef long long ll;
using Graph = vector<vector<int>>;
int main() {
  int N,M;
  cin >> N >> M;
  dsu d(N);
  FOR(i,0,M) {
    int x,y;
    cin >> x >> y;
    d.merge(x-1,y-1);
  }
  Graph a = d.groups();
  cout << a.size()-1 << endl;
  return 0;
}

Measured memory_bytes: 9048
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Collections;
static class Extensions
{
    public static int ToInt(this string s) => int.Parse(s);
    public static long ToLong(this string s) => long.Parse(s);
    public static char ToChar(this string s) => char.Parse(s);
    public static double ToDouble(this string s) => double.Parse(s);
    public static int[] ToIntArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToInt()).ToArray();
    public static long[] ToLongArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToLong()).ToArray();
    public static double[] ToDoubleArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToDouble()).ToArray();
    public static Queue<T> ToQueue<T>(this IEnumerable<T> seq) => new Queue<T>(seq);
    public static Stack<T> ToStack<T>(this IEnumerable<T> seq) => new Stack<T>(seq);
}

class Program
{
    static string[] ReadLines(int n) => Enumerable.Range(0, n).Select(s => Console.ReadLine()).ToArray();

    static void Main()
    {
        long[] abcd = Console.ReadLine().ToLongArray();

        long A = abcd[0];
        long B = abcd[1];
        long C = abcd[2];
        long D = abcd[3];

        long all = B - A + 1;

        long canDivByC = calc(A, B, C);
        long canDivByD = calc(A, B, D);
        long canDivByCD = calc(A, B, calcLCM(C, D));

        var ans = all - canDivByC - canDivByD + canDivByCD;

        Console.WriteLine(ans);

    }

    //x以上y以下の整数のうち、zで割り切れるものの個数を求める
    static long calc(long x, long y, long z)
    {
        var n1 = (x - 1) / z;
        var n2 = y / z;

        return n2 - n1;
    }

    static long calcLCM(long a, long b)
    {
        return a * b / calcGCD(a, b);
    }

    static long calcGCD(long a, long b)
    {
        if (a < b)
        {
            var tmp = b;
            b = a;
            a = tmp;
        }

        if (a % b == 0)
        {
            return b;
        }
        else
        {
            return (calcGCD(b, a % b));
        }
    }
}

Measured memory_bytes: 13396
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define mod ((int)1e9+7)
#define lim 1000000000000000007
#define lim1 18446744073709551615  //Unsigned
#define sq(a) ((a)*(a))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mms(v,i) memset(v,i,sizeof(v))
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define REPN(i,a,b) for (int i = a; i >= b; i--)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pi;
typedef pair<ll,ll> PL;
typedef pair<ll,int> PLI;
typedef pair<int,ll> PIL;
typedef pair<int,pair<int,int> > pii;
typedef pair<double,double> pdd;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
typedef tree<pi,null_type,less<pi>,rb_tree_tag,tree_order_statistics_node_update> indexed_set_pair;
ll power(ll a,ll b) {
   ll res=1;
   while(b){
      if(b%2==1) res=(res*a)%mod;
      a=(a*a)%mod;
      b>>=1;
   }
   return res;
}
ll gcdll(ll a,ll b) {
    if (b==0) return a;
    return gcdll(b,a%b);
}
int gcd(int a,int b) {
    if (b==0) return a;
    return gcd(b,a%b);
}

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

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

const int N = (int)2e5+5;
const int M = (int)3e3+5;
const int Q = 102;
const int logN = 19;

const double pie = acos(-1);

void solve() {
    int x,y;
    cin>>x>>y;
    REP(t,0,x) {
        int legs = 4*t + 2*(x-t);
        if(legs==y) {
            cout<<"Yes";
            return;
        }
    }
    cout<<"No";
}
int main() {
    //freopen("output.txt","r",stdin);
    //freopen("output.txt","w",stdout);

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

    int T=1;
    //cin>>T;
    REP(TC,1,T) {
        //cout<<"Case #"<<TC<<": ";
        solve();
        cout<<"\n";
    }
}


Measured memory_bytes: 3636
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647 -> 10桁
// MAX ll 9,223,372,036,854,775,807 -> 19桁
// MAX O(n) 10^8 -> 8回
// double pi = M_PI or acos(-1)
// printf("%.10f\n", ans);

int main() {
    ll n, k, q;
    cin >> n >> k >> q;
    map<ll, ll> mp;
    rep(i, q) {
        int tmp;
        cin >> tmp;
        mp[--tmp]++;
    }

    vector<ll> scores(n, k - q);

    for(auto row : mp) {
        scores[row.first] += row.second;
    }

    rep(i, n) {
        if(scores.at(i) > 0) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }

    return 0;
}


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

int main() {
    int N, D;
    cin >> N >> D;
    vector<vector<int>> X(N, vector<int>(D));
    for (int i=0; i<N; i++) {
        for (int j=0; j<D; j++) {
            cin >> X[i][j];
        }
    }
    
    int ans = 0;
    
    for (int i=0; i<N-1; i++) {
        for (int j=i+1; j<N; j++) {
            int d = 0;
            for (int k=0; k<D; k++) {
                d += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
            }
            bool check = false;
            for (int k=0; k<=128; k++) {
                if (sqrt(d) == k) check = true;
            }
            if (check) ans++;
        }
    }
    
    cout << ans << endl;
    
}

Measured memory_bytes: 256
/*
❤️❤️❤️I_love_QMsh❤️❤️❤️
*/

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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define x first
#define y second

using namespace std;
using namespace __gnu_pbds; // gp_hash_table<int, int> table;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // <int> .find_by_order(int) .order_of_key(int)

template<typename T> bool smin(T &a, const T &b) { bool ret = b < a; return a = (ret ? b : a), ret; }
template<typename T> bool smax(T &a, const T &b) { bool ret = a < b; return a = (ret ? b : a), ret; }

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;

mt19937 rnd;

signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  string s;
  cin >> s;
  int n = s.size();
  ll ans = 0;
  for (int mask = 0; mask < (1 << (n - 1)); mask++) {
    ll cur = 0;
    for (int b = 0; b < n; b++) {
      cur = (cur * 10 + s[b] - '0');
      if (mask >> b & 1) {
        ans += cur;
        cur = 0;
      }
    }
    ans += cur;
  }
  cout << ans;
  return 0;
}

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

using namespace std;
//最小の数を探す
int min(int a, int b, int c)
{
	return a > b ? (b > c ? c : b) : (a > c ? c : a);
}

//レーベンシュタイン距離を求める
int LevenshteinDistance(string str1, string str2)
{
	int lenstr1 = str1.length() + 1;
	int lenstr2 = str2.length()+ 1;
	int d[lenstr1][lenstr2];
	int i1 = 0, i2 = 0, cost = 0;

	for (;i1 < lenstr1; i1++) d[i1][0] = i1;
	for (;i2 < lenstr2; i2++) d[0][i2] = i2;

	for (i1 = 1; i1 < lenstr1; i1++) {
		for (i2 = 1; i2 < lenstr2; i2++) {
			cost = str1[i1 - 1] == str2[i2 - 1] ? 0 : 1;
			d[i1][i2] = min(d[i1 - 1][i2] + 1, d[i1][i2 - 1] + 1, d[i1 - 1][i2 - 1] + cost);
		}
	}
	
	return d[lenstr1 - 1][lenstr2 - 1];
}

int main()
{	
	string str1;
	string str2;
	cin>>str1;
	cin>>str2;
	printf("%d\n", LevenshteinDistance(str1, str2));
	return 0;
}

Measured memory_bytes: 5100
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

struct UnionFind {
    par: Vec<usize>,
    rank: Vec<usize>,
}

impl UnionFind {
    fn new(n: usize) -> Self {
        UnionFind {
            par: (0..n).collect(),
            rank: vec![0; n],
        }
    }

    fn root(&mut self, n: usize) -> usize {
        let par = self.par[n];
        if par != n {
            self.par[n] = self.root(par);
        }
        self.par[n]
    }

    fn same(&mut self, x: usize, y: usize) -> bool {
        self.root(x) == self.root(y)
    }

    fn unite(&mut self, x: usize, y: usize) {
        let x = self.root(x);
        let y = self.root(y);
        if x == y {
            return;
        }

        if self.rank[x] < self.rank[y] {
            self.par[x] = y;
        } else {
            self.par[y] = x;
            if self.rank[x] == self.rank[y] {
                self.rank[x] += 1;
            }
        }
    }
}

fn main() {
    input! {
        n: usize,
        m: usize,
        p: [usize1; n],
        xy: [(usize1, usize1); m],
    }

    let mut uf = UnionFind::new(n);
    for (x, y) in xy.into_iter() {
        uf.unite(x, y);
    }

    let mut ans = 0;
    for (i, j) in p.into_iter().enumerate() {
        if uf.same(i, j) {
            ans += 1;
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 10492
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

const i64 mod = 1e9 + 7;
i64 n;
vector<i64> a;
int main() {
  cin >> n;
  read_n(a, n);

  i64 ans = 1, c[3] = {};
  for (int i = 0; i < n; ++i) {
    i64 cnt = 0;
    for (int j = 0; j <= 2; ++j) {
      if (c[j] == a[i]) {
        ++cnt;
      }
    }
    (ans *= cnt) %= mod;
    for (int j = 0; j <= 2; ++j) {
      if (c[j] == a[i]) {
        c[j]++;
        break;
      }
    }
    // sort(begin(c), end(c));
  }

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

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

#include <bits/stdc++.h>


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

#define int long long

using namespace std;
const int N = 3e3 + 5;
int dp[N][N];

class FLCS {
public:
    string s, t;
    int n, m;

    int rec(int i, int j) {
        if (i <= 0 or j <= 0) return dp[i][j] = 0;
        if (dp[i][j] != -1) return dp[i][j];
        int res;
        if (s[i - 1] == t[j - 1]) {
            res = 1 + rec(i - 1, j - 1);
        } else {
            int p1 = rec(i - 1, j), p2 = rec(i, j - 1);
            if (p1 >= p2) {
                res = p1;
            } else {
                res = p2;
            }
        }
        return dp[i][j] = res;
    }

    void solve(std::istream &in, std::ostream &out) {
        in >> s >> t;
        n = s.length(), m = t.length();
        memset(dp, -1, sizeof dp);
        int len = rec(n, m);
        int i = n, j = m;
        string res = "";
        while (i > 0 and j > 0) {
            if (dp[i][j] == dp[i - 1][j]) --i;
            else if (dp[i][j] == dp[i][j - 1]) --j;
            else res += s[i - 1], --i, --j;
        }
        reverse(res.begin(), res.end());
        out << res;
    }
};


int32_t main() {
    FLCS solver;
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 71040
#include<bits/stdc++.h>
//#include <cmath>
//const double PI = 3.141592653589793;

using namespace std;
int main()
{
    int n,m,a;
    cin>>n>>m;
    //vector<int>arr(m);
    long long ans=0;
    for(int i=0;i<m;i++)
    {
        cin>>a;
        ans+=a;
    }
    if(ans>n)
    {
        cout<<-1<<endl;
    }
    else
    {
        cout<<n-ans<<endl;
    }
    

    return 0;
}

Measured memory_bytes: 3636
#include<cstdio>
#include<cstring>
#include<cctype>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<vector>
#include<algorithm>
#define ll long long
#define lowbit(x) x&-x
using namespace std;
int read(){
    char c;int s=0,t=1;
    while(!isdigit(c=getchar()))if(c=='-')t=-1;
    do{s=s*10+c-'0';}while(isdigit(c=getchar()));
    return s*t;
}
int min(int a,int b){return a<b?a:b;}
int max(int a,int b){return a<b?b:a;}
int ab(int x){return x>0?x:-x;}
//int MO(int x){return x>=MOD?x-MOD:x;}
//void insert(int u,int v){tot++;e[tot].v=v;e[tot].from=first[u];first[u]=tot;}
/*------------------------------------------------------------*/
const int inf=0x3f3f3f3f,maxn=200050;
 
int n,c[maxn],num[maxn];
bool vis[maxn];
char s[maxn];
vector<int>v[30];
void modify(int x,int k){for(int i=x;i<=n;i+=lowbit(i))c[i]+=k;}
int query(int x){int ans=0;for(int i=x;i>=1;i-=lowbit(i))ans+=c[i];return ans;}
int main(){
    scanf("%s",s+1);
    n=strlen(s+1);
    for(int i=1;i<=n;i++)num[s[i]-'a']++,v[s[i]-'a'].push_back(i);
    int ok=0;
    for(int i=0;i<26;i++){
        if(num[i]%2)ok++;
    }
    if(ok>1){printf("-1");return 0;}
    for(int i=1;i<=n+1;i++)modify(i,1);
    ll ans=0;
    for(int i=1;i<=n;i++)if(!vis[i]){
        int c=s[i]-'a';
        int x=v[c].back();
        if(i==x){
            ans+=(query(n)-query(i))>>1;
        }
        else{
            ans+=query(n)-query(x);
        }
        modify(i,-1);modify(x,-1);
        vis[i]=vis[x]=1;
        v[c].pop_back();
    }
    printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 2424
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String W = sc.next();

        StringBuilder Wt = new StringBuilder();
        for (String s : W.split("")) {
            Wt.append(Character.toLowerCase(s.charAt(0)));
        }

        int sum = 0;
        while (true) {
            String T = sc.next();
            if ("END_OF_TEXT".equals(T)) break;

            StringBuilder tmp = new StringBuilder();
            for(String s : T.split("")) {
                if (Character.isLetter(s.charAt(0))) tmp.append(Character.toLowerCase(s.charAt(0)));
            }

            if (tmp.toString().equals(Wt.toString())) sum++;
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 26372
#include <iostream> 
#include <vector>
#include <cmath>
#include <string>
#include <sstream>
#include <algorithm>
#include <queue>
#include <stack>
#include <unordered_set>
#include <set>
#include <unordered_map>
#include <map>
#include <iomanip>
#include <cctype>
#include <climits>

using namespace std;

using ii = pair<int, int>;
using vi = vector<int>;
using vii = vector<ii>;
using vvi = vector<vi>;

using ll = long long int;

#define mp(a,b) make_pair(a,b)

const int MOD = 1000 * 1000 * 1000 + 7;

bool res() {
	double l;
	cin >> l;
	if (!cin) return false;

	double a = l / 3;

	cout << fixed << setprecision(10) << a * a * a << '\n';

	return true;
}

int main() {
	while (res()) {}
	return 0;
}

Measured memory_bytes: 256
process.stdin.resume()
process.stdin.setEncoding('utf8')
process.stdin.on('data', function(y) {
  var value = y.split(' ').map(Number)
  var a = value[0]
  var b = value[1]
  var c = value[2]
  if (a < b && b < c) {
    console.log('Yes')
  } else {
    console.log('No')
  }
})

Measured memory_bytes: 15480
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C,K;
  cin >> A >> B >> C >> K;
  if (K <= A) {
    cout << K << endl;
  }
  else if (K > A && K <= A + B) {
    cout << A << endl;
  }
  else if (K > A + B && K <= A + B + C) {
    cout << A - (K - A - B) << endl;
  }
}

Measured memory_bytes: 3648
import sys
input = sys.stdin.readline

N,K=map(int,input().split())
A=list(map(int,input().split()))
mod=10**9+7

A.sort()

FACT=[1]
for i in range(1,2*10**5+1):
    FACT.append(FACT[-1]*i%mod)

FACT_INV=[pow(FACT[-1],mod-2,mod)]
for i in range(2*10**5,0,-1):
    FACT_INV.append(FACT_INV[-1]*i%mod)

FACT_INV.reverse()

def Combi(a,b):
    if 0<=b<=a:
        return FACT[a]*FACT_INV[b]*FACT_INV[a-b]%mod
    else:
        return 0
    

MINUS=0

for i in range(N):
    if N-i-1<K-1:
        break
    MINUS+=A[i]*Combi(N-i-1,K-1)

PLUS=0
A.reverse()

for i in range(N):
    if N-i-1<K-1:
        break
    PLUS+=A[i]*Combi(N-i-1,K-1)

print((PLUS-MINUS)%mod)


Measured memory_bytes: 23956