akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <cmath>

using namespace std;

int count(const vector<string>& v, int y1, int y2, int x) {
    int ans = 0;
    for (int i=y1;i<=y2;i++) {
        if (v[i][x] == '1') ans++;
    }
    return ans;
}

int main() {
    int h, w, k;
    vector<string> v;
    cin >> h >> w >> k;
    for (int i=0;i<h;i++) {
        string x;
        cin >> x;
        v.push_back(x);
    }
    int horizontal = int(pow(2, h-1));
    int m_line = 100000;
    for (int i=0;i<horizontal;i++) {
        vector<int> vh;
        int line;
        int hor = i;
        vh.push_back(0);
        for (int j=1;j<=h-1;j++) {
            if (hor & 1) {
                vh.push_back(j);
            }
            hor >>= 1;
        }
        vh.push_back(h);
        line = int(vh.size() - 2);

        vector<int> vv(line+1);

//        for (auto l: vh) {
//            cout << l << ' ';
//        }
//        cout << endl;

        for (int x=0; x<w; x++) {
            vector<int> vvv;

            for (int j=0;j<vh.size()-1;j++) {
                int y1 = vh[j];
                int y2 = vh[j+1] - 1;
                vvv.push_back(count(v, y1, y2, x));
            }
            for(int j=0;j<vv.size();j++) {
                if (vvv[j] > k) {
                    line = m_line;
                }
                if (vv[j] + vvv[j] > k) {
                    copy(vvv.begin(), vvv.end(), vv.begin());
                    line++;
                    break;
                }

                vv[j] += vvv[j];
            }
            if (line >= m_line) {
                break;
            }
        }
        if (line < m_line) {
            m_line = line;
        }
    }
    cout << m_line << endl;
}


Measured memory_bytes: 384
n, k = (int(x) for x in input().split())

# すぬけ君は全員お菓子を持っていないと仮定する
list_snuke = [str(i) for i in range(1, n + 1)]

# お菓子をもっているすぬけ君の番号を削除
# appendではなくリスト内包表記で書きたい
for i in range(0, k):
     d = int(input())
     a = [s for s in input().split()]
     for j in range(0, d):
         if a[j] in list_snuke:
             list_snuke.remove(a[j])

# お菓子をもっていないすぬけ君の人数を出力
print(len(list_snuke))

Measured memory_bytes: 9052
mod = 10 ** 9 + 7
d = {}


def prime_factorizer(n):
    i = 2
    global d
    while i * i <= n:
        if n % i == 0:
            if i in d.keys():
                d[i] += 1
            else:
                d.setdefault(i, 1)
            n //= i
        else:
            i += 1
    if n != 1:
        if n in d.keys():
            d[n] += 1
        else:
            d.setdefault(n, 1)


n = int(input())

for i in range(n, 0, -1):
    prime_factorizer(i)

cnt = 1
for k, v in d.items():
    cnt *= v + 1
print(cnt % mod)


Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>

double i,j,a,b,c,d,e,f;
double x,y;

int main(){
    while (scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f) != EOF) {
        y = (c * d - a * f) / (b * d - e * a);
        x = (c - (b * y)) / a;
        
        printf("%.3lf %.3lf\n",x,y);
    }    
    return 0;
}	


Measured memory_bytes: 2040
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var A = new int[N];
            for (var i = 0; i < N; i++)
                A[i] = int.Parse(Console.ReadLine());

            Array.Sort(A);

            var mid = N / 2;
            var one = CalcA(mid, 0, A);
            var two = 0L;
            if (N % 2 == 1) 
                two = CalcB(mid, N - 1, A);

            Console.WriteLine(Math.Max(one, two));
        }

        static long CalcA(int mid, int cur, int[] A)
        {
            var ret = 0L;
            var bef = mid;
            while (cur < mid)
            {
                ret += Math.Abs(A[bef] - A[cur]);
                bef = cur;
                var minusIndex = A.Length - cur - 1;
                if (minusIndex == mid) break;
                ret += Math.Abs(A[bef] - A[minusIndex]);
                bef = minusIndex;
                cur++;
            }

            return ret;
        }

        static long CalcB(int mid, int cur, int[] A)
        {
            var ret = 0L;
            var bef = mid;
            while (mid < cur)
            {
                ret += Math.Abs(A[bef] - A[cur]);
                bef = cur;
                var minusIndex = A.Length - cur - 1;
                if (minusIndex == mid) break;
                ret += Math.Abs(A[bef] - A[minusIndex]);
                bef = minusIndex;
                cur--;
            }

            return ret;
        }
    }
}


Measured memory_bytes: 17500
sx,sy,tx,ty = map(int,input().split())

X = tx - sx
Y = ty - sy
go1 = ''
back1 = ''

for i in range(abs(X)):
  go1 += 'R'
  back1 += 'L'
for i in range(abs(Y)):
  go1 += 'U'
  back1 += 'D'

go2 = 'D'
back2 = 'U'

for i in range(go1.count('R')+1):
  go2 += 'R'
  back2 += 'L'
for i in range(go1.count('U')+1):
  go2 += 'U'
  back2 += 'D'

go2 += 'L'
back2 += 'R'

print(go1+back1+go2+back2)


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
#include <numeric> //lcm
#include <iomanip> //double精度 setprecision

using namespace std;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = n-1; i >= 0; --i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)
#define rrep1(i,n) for(int i = (n); i >= 1; --i)
#define REP(i,n,m) for(int i = (n); i < (m); ++i)
#define all(vec) (vec).begin(),(vec).end()

#define debug(vec) for(auto v : vec) cerr << v << " "; cerr << endl;
#define debug2D(vec2D) for(auto vec : vec2D) { for (auto v : vec) cerr << v << " "; cerr << endl; } 
#define debugP(vec) for(auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl;
#define debug2DP(vec2D) for(auto vec : vec2D) { for (auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl; } 

typedef long long ll;

constexpr ll INF = 1000000000; //10^10
//const ll MOD = 998244353;
constexpr ll MOD = 1000000007;

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


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

	vector<vector<int>> mat(n, vector<int>(n, 2));
	rep(i, n) {
		int a; cin >> a;
		rep(j, a) {
			int x, y; cin >> x >> y;
			mat[i][x - 1] = y;
		}
	}

	ll ans = 0;
	rep(state, 1 << n) {
		vector<bool> isHonest(n, false);
		rep(i,n) if (state >> i & 1) isHonest[i] = true;

		bool ok = true;
		rep(i, n) {
			if(!isHonest[i]) continue;
			rep(j,n) {
				if (mat[i][j] == 1 && !isHonest[j]){ ok = false; break;}
				if (mat[i][j] == 0 && isHonest[j] ){ ok = false; break;}
			}
		}
		if(!ok) continue;

		ll popcnt = 0;
		rep(i,n) popcnt += state >> i & 1;
		chmax(ans, popcnt);
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
#define PI 3.141592653589793

int main(){
  ll dp[55][6000];
  int N, A;
  cin >> N >> A;
  int x[N];
  rep(i, N){
    cin >> x[i];
    x[i] -= A;
  }
  dp[0][A*N]=1;
  rep(i, N){
    rep(j, 5590){
       dp[i+1][j+x[i]] += dp[i][j];
       dp[i+1][j] += dp[i][j];
    }
  }
  ll ans = dp[N][A*N];
  ans--;
  cout << ans << endl;
}

Measured memory_bytes: 2688
#include <stdio.h>

int main(){
	int n,j, i=0;
	int set[12000] = { 0};
	while (1){
		scanf("%d", &set[i]);
		
		if (set[i] == 0){
			break;
		}
		i++;
	}
	for (j = 0; j < i; j++){
		printf("Case %d: %d\n", j+1, set[j]);

	}
	return 0;
}

Measured memory_bytes: 1080
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cmath>

using namespace std;

int main() {
    int64_t n;
    cin >> n;
    int dmin = 20;
    for (int i = 1; i <= sqrt(n); i++) {
        int a = i, b;
        if (n%i == 0) {
            b = n/i;
            int c = max(to_string(a).size(), to_string(b).size());
            dmin = min(dmin, c);
        }
    }
    cout << dmin << endl;
}


Measured memory_bytes: 256
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
input = sys.stdin.buffer.readline

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

# A[i]: iの次の要素
# M: 何個先まで調べたいか
class Doubling(object):
    def __init__(self,A,M):
        self.N = len(A)
        self.kmax = M.bit_length()
        # nex[i][k]: i番目の2^k先
        self.nex = [[-1]*self.kmax for _ in range(N)]
        for i in range(N):
            self.nex[i][0] = A[i]
        
        for k in range(1,self.kmax):
            for i in range(N):
                if self.nex[i][k-1] == -1:
                    self.nex[i][k] = -1
                else:
                    self.nex[i][k] = self.nex[self.nex[i][k-1]][k-1]
    
    # i番目の要素のx個先
    def query(self,i,x):
        L = x.bit_length()
        for k in range(L)[::-1]:
            if i == -1:
                break
            if (x >> k) & 1:
                i = self.nex[i][k]
        return i

N,K = LI()
A = LI()
A = list(map(lambda x: x-1, A))

d = Doubling(A,K)
print(d.query(0,K)+1)

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

int bfs(int x, int y, int h, int w, string s[]){
    queue<pair<int,int>> q;
    int ans = 0;
    int visited[h][w];
    for(int i = 0; i < h; i++)
        for(int j = 0; j < w; j++)
            visited[i][j] = -1;
    q.push({x,y});
    visited[x][y] = 0;
    int dx[4] = {0, 1, 0, -1};
    int dy[4] = {1, 0, -1, 0};
    while(!q.empty()){
        int a = q.front().first, b = q.front().second;
        q.pop();
        for(int i = 0; i < 4; i++){
            if(a + dx[i] > h -1 || b + dy[i] > w - 1 || a + dx[i] < 0 || b + dy[i] < 0 || visited[a + dx[i]][b + dy[i]] != -1 || s[a + dx[i]][b + dy[i]] == '#')
                continue;
            q.push({a + dx[i], b + dy[i]});
            visited[a + dx[i]][b + dy[i]] = visited[a][b] + 1;
            ans = max(visited[a + dx[i]][b + dy[i]], ans);
            //cout << a + dx[i] << ' ' << b + dy[i] << " " << visited[a + dx[i]][b + dy[i]] << endl;
        }
    }
    return ans;
}
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int h, w, ans = 0;
    cin >> h >> w;
    string s[h];
    for(int i = 0; i < h; i++)
        cin >> s[i];
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(s[i][j] == '.'){
                ans = max(ans, bfs(i,j,h,w,s));
                //cout << endl;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

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

    int n,m,c;
    cin>>n>>m>>c;
    int a[n][m], b[m];
    for(int i = 0;i < m;i++) cin>>b[i];
    for(int i = 0;i < n;i++) {
        for(int j = 0;j < m;j++) cin>>a[i][j];
    }
    
    // cin>>c;
    int ans = 0;
    for(int i = 0;i < n;i++) {
        int x = c;
        for(int j = 0;j < m;j++) {
            x += a[i][j]*b[j];
        }
        if(x > 0) ans++;
    }
    cout<<ans;
}

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

using namespace std;
#define int long long int
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define vi vector <int>
#define sz(s) (int)s.size()
#define pii pair<int,int>
#define piii pair< int,pair<int,int> >
#define tiii tuple <int,int,int>
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define rall(v) v.rbegin(),v.rend()
#define endl '\n'
#define matrix vector <vector <int> >
#define boost ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define NAYAN freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define N 500006
#define mod 1000000007
#define mod2 998244353
#define inf 1e17

int dp[100001];
int a[N];
int n;

int solve(int id)
{
    if(id==n-1)
    {
        return 0;
    }
    if(id>=n)
        return inf;
    if(dp[id]!=-1)
        return dp[id];
    int x=abs(a[id+1]-a[id])+solve(id+1);
    int y=abs(a[id+2]-a[id])+solve(id+2);
    dp[id]=min(x,y);
    return dp[id];
}

int32_t main()  
{
    boost
    // #ifndef ONLINE_JUDGE 
    // NAYAN
    // #endif
    
    

    cin >> n;

    
    memset(dp,-1,sizeof dp);
    int i;
    
    for(i=0;i<n;i++)
    {
        cin >> a[i];
    }

    int ans=solve(0);

    cout << ans;



   


}

Measured memory_bytes: 6784
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		String n = sc.next();
        String a[] = n.split("");
        System.out.println(a[0] + a[1] + a[2]);

      	
    }
}

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


int main() {
	int h, w;
	cin >> h >> w;
	vector<string> vec(h);
	for (int i = 0; i < h; i++) cin >> vec[i];
	vec.insert(vec.begin(), string(w+2, '#'));
	vec.push_back(string(w+2, '#'));

	for (int i = 1; i < h+1; i++) {
		vec[i].insert(vec[i].begin(), '#');
		vec[i].push_back('#');
	}

	for (int i = 0; i < h+2; i++) {
		cout << vec[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#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(){
    ll n, a, b;
    cin >> n >> a >> b;
    ll i = n / (a+b);
    ll r = n % (a+b);
    cout << i*a + min(a, r) << endl;
    return 0;
}

Measured memory_bytes: 256
listA=list(map(int,input().split()))
x_list = []
for i in [0,1]:
    x_list.append(listA[i])

y_list = []
for i in [2,3]:
    y_list.append(listA[i])

i_list = []
for x in x_list:
    for y in y_list:
        i_list.append(x*y)

print(max(i_list))

Measured memory_bytes: 9176
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <stack>
#include <set>
#include <queue>
#include <algorithm>
#include <deque>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;

#define INF 1e18
#define int long long
#define MAX 200010

signed main() {
    string s, t; cin >> s >> t;

    int res = 0;
    for(int i = 0; i < s.size(); i++) {
        if(s[i] == t[i]) res++;
    }

    cout << res << endl;
    return 0;
}


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

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

    int bt = 0;
    int bx = 0;
    int by = 0;
    bool is_possible = true;
    
    for (int i = 0; i < N; i++) {
        int t, x, y;
        cin >> t >> x >> y;
        int e = (t - bt) - (abs(x - bx) + abs(y - bx));
        if (e < 0 || e % 2 != 0) {
            is_possible = false;
            break;
        }
    }

    if (is_possible) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

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

ll N,K;
ll i, j, k;
ll dp[10];
char ansS[101010];
int main(){
    scanf("%lld%lld", &N, &K);
    if(N>K){
        N = N % K;
    }
    set<ll> st;
    while(st.count(N)==0){
        st.insert(N);
        N = abs(N - K);
    }
    printf("%lld\n", *(st.begin()));
    return 0;
    
    return 0;
}

Measured memory_bytes: 256
// 2020-07-25 21:03:33
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

void answer() {
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  while(k && a >= b) {
    b *= 2;
    k--;
  }
  while(k && b >= c) {
    c *= 2;
    k--;
  }
  if(a < b && b < c) {
    cout << "Yes" << '\n';
  } else {
    cout << "No" << '\n';
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

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

//#define kk
#define FOR(i, n) for(int i=1; i<=n; i++)
#define ff first
#define ss second
#define ll int
#define inf 1000000000
typedef pair<int, int> pi;

int dp[100001][3];

void solve(){
	int n;
	cin>>n;
	
	int a, b, c;
	cin>>a>>b>>c;
	
	dp[1][0]=a, dp[1][1]=b, dp[1][2]=c;
	
	for(int i=2; i<=n; i++){
		cin>>a>>b>>c;
		
		dp[i][0]=a+max(dp[i-1][1], dp[i-1][2]);
		dp[i][1]=b+max(dp[i-1][0], dp[i-1][2]);
		dp[i][2]=c+max(dp[i-1][0], dp[i-1][1]);
	}
	
	cout<<max({dp[n][0], dp[n][1], dp[n][2]})<<endl;
}

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	#ifdef kk
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	
	int T=1;
	//cin>>T;
	
	while(T--){
		solve();
	}
}


Measured memory_bytes: 4736
// 20
/****************************************************
https://searleser97.gitlab.io/algorithms/template.cpp
****************************************************/

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define forr(_, x, n) for (int _ = x; _ > n; _--)
#define fos(_, x, n, s) for (int _ = x; _ < n; _ += s)
#define forn(_, x, n) fos(_, x, n, 1)
#define rep(_, n) forn(_, 0, n)
#define fi first
#define se second
#define pb push_back
#define pairii pair<int, int>
#define all(x) x.begin(), x.end()
#define cerr(s) cerr << "\033[48;5;196m\033[38;5;15m" << s << "\033[0m"
// typedef __int128_t lli;
typedef long long int li;
typedef long double ld;
// 12

// li dp(int sum, vector<int>& v, int pos, vector<vector<vector<li>>> &mem, int need) {
//   if (pos == v.size()) {
//     if (sum == 0 && need == 0) return 1;
//     else return 0;
//   }
//   if (sum == 0 && need == 0) return 1;
//   if (sum < 0) return 0;
//   if (need < 0) return 0;
//   if (mem[pos][sum][need] != -1) return mem[pos][sum][need];
//   return mem[pos][sum][need] = dp(sum - v[pos], v, pos + 1, mem, need - 1) + dp(sum, v, pos + 1, mem, need);
// }

li dp(int sum, vector<int>& v, int pos, vector<vector<vector<li>>>& mem, int cnt, int a) {
  if (pos == v.size()) {
    if (cnt == 0) return 0;
    if (sum % cnt == 0) {
      if (sum / cnt == a) {
        return 1;
      } else {
        return 0;
      }
    } else {
      return 0;
    }
  }
  if (mem[pos][sum][cnt] != -1) return mem[pos][sum][cnt];
  return mem[pos][sum][cnt] = dp(sum + v[pos], v, pos + 1, mem, cnt + 1, a) + dp(sum, v, pos + 1, mem, cnt, a);
}

void _main(int tc) {
  int n, a;
  cin >> n >> a;
  vector<int> v(n);
  rep(i, n) cin >> v[i];
  vector<vector<vector<li>>> mem(51, vector<vector<li>>(50 * 50 + 1, vector<li>(51, -1)));
  // vector<vector<li>> mem(50 + 1, vector<li>())
  // li ans = 0;
  // for (int i = 1; i <= n; i++) {
  //   ans += dp(i * a, v, 0, mem, i);
  // }
  li ans = dp(0, v, 0, mem, 0, a);
  cout << ans << endl;
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  _main(0); return 0;
  int tc;
  cin >> tc;
  rep(i, tc) _main(i + 1);
}

Measured memory_bytes: 56192
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>

using namespace std;

using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;
using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;

int main(int argc, char* argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  i32 N, Q;
  i64 K;
  cin >> N >> K >> Q;
  
  vector<i32> list(N, Q);
  for(i32 i = 0; i < Q; ++i) {
    i32 a;
    cin >> a;
    list[a-1] -= 1;
  }
  
  for(i32 i = 0; i < N; ++i) {
    auto val = K - list[i];
    if(val > 0) {cout << "Yes" << endl;}
    else {cout << "No" << endl;}
  }
  
  return 0;
}


Measured memory_bytes: 1024
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
from collections import deque, defaultdict
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    N = II()
    A = LI()
    counter = defaultdict(int)
    for a in A:
        counter[a] += 1
    # print(counter)

    odd = 0
    ans = N
    for key, val in counter.items():
        if val > 1:
            c = val - 1
            # print(val, c, c // 2)
            if c % 2 == 1:
                odd += 1
            ans -= (c - c % 2)
    # print(ans, odd)
    ans = ans - (odd // 2) * 2 - (odd % 2) * 2
    print(ans)

            

    

if __name__ == '__main__':
    solve()



Measured memory_bytes: 22088
n = int(input())
s = input()


white = []
for i in range(n):
    if s[i] == "W":
        white.append(i)

white = white[::-1]
if len(white) == 0:
    print(0)
    exit()
ans = 0
for i in range(n)[::-1]:
    if s[i] == "R":
        if not white:
            continue
        if i > white[-1]:
            ans += 1
            del white[-1]
print(ans)

Measured memory_bytes: 82540
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int lli;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}

template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

int main() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int mx = max({a, b, c});
    REP(i, 0, k) {
        mx *= 2;
    }
    cout << a + b + c + mx - max({a, b, c}) << endl;
    return 0;
}

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

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

int num,counter,repeat;
counter = n;

for(int i=0; i<n; i++){
    cin >> num;
    repeat = sqrt(num)+1;
    for (int j=2; j<repeat; j++){
        if(num%j == 0){
            counter--;
            break;
        }
    }
}
cout << counter << endl;
return 0;
}


Measured memory_bytes: 3088
#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

int N, K;
vector<int> A;

bool f(int x) {
  if (A[x] >= K) return true;

  bool sum[K + 1];
  memset(sum, false, sizeof(sum));
  sum[0] = true;
  int d;

  for (int i = 1; i <= N; ++i) {
    if (i == x) continue;
    int a = A[i];

    for (int k = K; k >= 0; --k) {
      if (!sum[k]) continue;

      int d = min(K, k + a);

      sum[d] = true;
    }
  }

  for (int i = K - A[x]; i < K; ++i) {
    if (sum[i]) return true;
  }

  return false;
}

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

  A.push_back(0);
  int a;
  for (int i = 0; i < N; ++i) {
    cin >> a;
    A.push_back(a);
  }

  sort(A.begin(), A.end());

  A.push_back(K);

  int ok = N + 1;
  int ng = 0;

  while (abs(ok - ng) > 1) {
    int x = (ok + ng) / 2;

    bool res = f(x);

    if (f(x)) {
      ok = x;
    } else {
      ng = x;
    }
  }

  cout << ng << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	int map[][];
	int w,h,k;

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new Main().solve();
	}
	
	void solve(){
		Scanner sc=new Scanner(System.in);
		while(true){
			w=sc.nextInt();
			h=sc.nextInt();
			int n=0;
			if(w+h==0)break;
			map=new int[w][h];
			for(int y=0;y<h;y++){
				for(int x=0;x<w;x++){
					map[x][y]=sc.nextInt();
				}
			}
			for(int x=0;x<w;x++){
				for(int y=0;y<h;y++){
					if(map[x][y]==1){
						def(x,y);
						n++;
					}
				}
			}
			System.out.println(n);
		}
	}
	
	void def(int x,int y){
		map[x][y]=0;
		for(int xi=-1;xi<=1;xi++){
			for(int yi=-1;yi<=1;yi++){
				if(x+xi>=0&&x+xi<w&&y+yi>=0&&y+yi<h){
					if(map[x+xi][y+yi]==1)def(x+xi,y+yi);
				}
			}			
		}
	}

}

Measured memory_bytes: 43204
#include <iostream>

using namespace std;

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

    int c[n + 1];
    for (int i = 1; i <= n - 1; i++) {
        c[i] = n + 1;
    }

    int a, b;
    for (int i = 0; i < m; i++) {
        cin >> a >> b;
        if (b - 1 < c[a]) {
            c[a] = b - 1;
        }
    }

    bool removed[n];
    for (int i = 1; i <= n - 1; i++) {
        removed[i] = false;
    }

    for (int i = 1; i <= n - 1; i++) {
        if (c[i] != n + 1) {
            int min = i;
            int max = c[i];
            for (int j = min + 1; j <= max; j++) {
                if (c[j] != n + 1) {
                    if (c[j] < max) {
                        max = c[j];
                    }
                }
            }
            removed[max] = true;
            i = max;
        }
    }

    int numOfRemoved = 0;
    for (int i = 1; i <= n - 1; i++) {
        if (removed[i]) {
            numOfRemoved++;
        }
    }

    cout << numOfRemoved << endl;

    return 0;
}


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

bool wall[5][5][4];
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

int main(){
	string s;
	for(int i = 0; i < 9; ++i){
		cin >> s;

		if(i % 2 == 0){
			for(int j = 0; j < 4; ++j){
				if(s[j] == '1'){
					wall[j][i / 2][0] = wall[j + 1][i / 2][2] = true;
				}
			}
		}
		else{
			for(int j = 0; j < 5; ++j){
				if(s[j] == '1'){
					wall[j][i / 2][1] = wall[j][i / 2 + 1][3] = true;
				}
			}
		}
	}

	s.clear();
	int x = 0, y = 0, dir = 0;
	do{
		s += "RDLU"[dir];
		x += dx[dir];
		y += dy[dir];

		if(wall[x][y][(dir + 3) % 4]){
			dir = (dir + 3) % 4;
		}
		else if(!wall[x][y][dir]){
			if(wall[x][y][(dir + 1) % 4]){
				dir = (dir + 1) % 4;
			}
			else{
				dir = (dir + 2) % 4;
			}
		}
	} while(x != 0 || y != 0 || dir != 0);
	
	cout << s << endl;
}

Measured memory_bytes: 1176
def main():
  import sys
  input = sys.stdin.readline
  import numpy as np
  n,k = map(int,input().split())
  s = input()
  chk_0 = []
  chk_1 = []
  c0 = 0
  c1 = 0
  if s[0]=='0':
    c0 += 1
  else:
    c1 += 1
    chk_0.append(0)

  for i in range(n-1):
    if s[i]=='0' and s[i+1]=='0':
      c0 += 1
    if s[i]=='0' and s[i+1]=='1':
      chk_0.append(c0)
      c0 = 0
      c1 = 1
    if s[i]=='1' and s[i+1]=='0':
      chk_1.append(c1)
      c0 = 1
      c1 = 0
    if s[i]=='1' and s[i+1]=='1':
      c1 += 1

  if c0 != 0:
    chk_0.append(c0)
    chk_1.append(0)
  elif c1 != 0:
    chk_1.append(c1)
    chk_0.append(0)

  if len(chk_0) <= k:
    print(n)
    exit()

  ab = np.array([x+y for x,y in zip(chk_0,chk_1)])
  np.cumsum(ab,out=ab)

  ans = ab[k-1]
  for i in range(len(ab)-k):
    chk = ab[k+i]-ab[i]
    chk += chk_1[i]
    ans = max(ans,chk)
  print(ans)
if __name__ == '__main__':
    main()

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

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

  int res=0;
  int tmp=10000000;
  rep(i, n) {
    if (tmp>=p[i]) res++;
    tmp=min(tmp, p[i]);
  }
  cout<<res<<endl;
}

Measured memory_bytes: 1024
#!/usr/bin/env python
import string
import sys
from itertools import chain, dropwhile, takewhile


def read(
    *shape, f=int, it=chain.from_iterable(sys.stdin), whitespaces=set(string.whitespace)
):
    def read_word():
        w = lambda c: c in whitespaces
        nw = lambda c: c not in whitespaces
        return f("".join(takewhile(nw, dropwhile(w, it))))

    if not shape:
        return read_word()
    elif len(shape) == 1:
        return [read_word() for _ in range(shape[0])]
    elif len(shape) == 2:
        return [[read_word() for _ in range(shape[1])] for _ in range(shape[0])]


def readi(*shape):
    return read(*shape)


def readi1(*shape):
    return [i - 1 for i in read(*shape)]


def readf(*shape):
    return read(*shape, f=float)


def reads(*shape):
    return read(*shape, f=str)


def arr(*shape, fill_value=0):
    if len(shape) == 1:
        return [fill_value] * shape[fill_value]
    elif len(shape) == 2:
        return [[fill_value] * shape[1] for _ in range(shape[0])]


def dbg(**kwargs):
    print(
        ", ".join("{} = {}".format(k, repr(v)) for k, v in kwargs.items()),
        file=sys.stderr,
    )


def main():
    sys.setrecursionlimit(100000)
    n, q = readi(2)
    par = arr(n + 1)
    for i in range(len(par)):
        par[i] = i

    def find(x):
        if x == par[x]:
            return x
        else:
            par[x] = find(par[x])
            return par[x]

    def unite(x, y):
        x = find(x)
        y = find(y)
        if x == y:
            return
        par[x] = y

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

    for _ in range(q):
        com, x, y = readi(3)
        if com == 0:
            unite(x, y)
        else:
            print(1 if same(x, y) else 0)


if __name__ == "__main__":
    main()



Measured memory_bytes: 16432
import scala.annotation.tailrec

object Main extends App {
  @tailrec
  def gcd(n: Int, m: Int): Int = {
    if (n < m) gcd(m, n)
    else {
      val r = n % m
      if (r > 0) gcd(m, r)
      else m
    }
  }

  var sum = 0
  val k = io.StdIn.readInt()
  for (a <- 1 to k)
    for (b <- 1 to k)
      for (c <- 1 to k)
        sum += gcd(a, gcd(b, c))

  println(sum)
}

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

template<typename Abel>
struct WeightedUnionFind{
    int num;
    vector<int> par,rank;
    vector<Abel> diff_weight;
    WeightedUnionFind(int n,Abel id=0):
        num(n),par(n),rank(n,1),diff_weight(n,Abel(0)){
        iota(par.begin(),par.end(),0);
    }
    int root(int x){
        if (x==par[x]) return x;
        int t=root(par[x]);
        diff_weight[x]+=diff_weight[par[x]];
        return par[x]=t;
    }
    bool merge(int x,int y,Abel w){
        w+=weight(x),w-=weight(y);
        x=root(x),y=root(y);
        if (x==y) return false;
        if (rank[x]<rank[y]) swap(x,y),w=-w;
        par[y]=x;
        rank[x]+=rank[y];
        diff_weight[y]=w;
        --num;
        return true;
    }
    Abel weight(int x){
        root(x);
        return diff_weight[x];
    }
    Abel diff(int x,int y){return weight(y)-weight(x);}
    bool same(int x,int y){return root(x)==root(y);}
    int size(int x){return rank[root(x)];}
    int count(){return num;}
};

int N,M,a,b;
char c; ll w;

void solve(){
    WeightedUnionFind<int> uf(N);
    for (;M--;){
        cin >> c >> a >> b; --a,--b;
        if (c=='!'){
            cin >> w;
            uf.merge(a,b,w);
        } else {
            if (!uf.same(a,b)) cout << "UNKNOWN" << '\n';
            else cout << uf.diff(a,b) << '\n';
        }
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> N >> M,N,M){
        solve();
    }
}


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

//#define kk
//#define int long long
#define FOR(i, n) for(int i=1; i<=n; i++)
#define ff first
#define ss second
#define ll int
#define inf 1000000000
#define pb push_back

const long long INF=1e18+5;
 
typedef pair<int, int> pi;

vector<int> arr[100001];
int dp[100001];

int dfs(int v){
	if(dp[v]!=-1) return dp[v];
	
	int temp=0;
	for(int child: arr[v]){
		temp=max(temp, 1+dfs(child));
	}
	return dp[v]=temp;
}

void solve(){
	int n, m;
	cin>>n>>m;
	
	for(int i=1; i<=m; i++){
		int a, b;
		cin>>a>>b;
		arr[a].pb(b);
	}
	
	for(int i=1; i<=n; i++) dp[i]=-1;
	
	int ans=0;
	for(int i=1; i<=n; i++){
		int res=dfs(i);
		ans=max(ans, res);
	}
	cout<<ans<<endl;
}

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	#ifdef kk
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	
	int T=1;
	//cin>>T;
	
	while(T--){
		solve();
	}
}


Measured memory_bytes: 11492
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

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

  int a[M]={0}, b[M]={0};
  int packet[N+1]={0};

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

  for (int i = 0; i < M; ++i) {
    ++packet[a[i]];
    ++packet[b[i]];
  }

  for (int i = 1; i <= N; ++i) {
    cout << packet[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(" ").map { it.toInt() }
    val routes = hashMapOf<Int, MutableSet<Int>>()
    for (i in 0 until m) {
        val (a, b) = readLine()!!.split(" ").map { it.toInt() }
        routes.getOrPut(b) { hashSetOf() }.add(a)
        routes.getOrPut(a) { hashSetOf() }.add(b)
    }

    val remainRooms = (2..n).toMutableSet()
    val result = IntArray(n - 1).toMutableList()
    var nextRooms = setOf(1)
    while (true) {
        val next = hashSetOf<Int>()
        for (room in nextRooms) {
            val found = routes[room] ?: continue
            for (f in found) {
                if (remainRooms.contains(f)) {
                    result[f - 2] = room
                    remainRooms.remove(f)
                    next.add(f)
                }
            }
        }
        if (next.isEmpty()) {
            break
        }
        nextRooms = next
    }

    if (remainRooms.isEmpty()) {
        println("Yes")
        for (i in result) {
            println(i)
        }
    } else {
        println("No")
    }
}

Measured memory_bytes: 129600
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
  double W,H,x,y;
  cin>>W>>H>>x>>y;
  double maxS=W*H/2;
  int m;
  if(x*2==W&&y*2==H){
    m=1;
  }else{
    m=0;
  }
  cout<<maxS<<" "<<m<<endl;
  return 0;
}
  


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 100000000000000000


int main(){
	
	int H,W;
	cin>>H>>W;
	
	vector<int> cnt(26,0);
	
	vector<string> S(H);
	
	for(int i=0;i<H;i++)cin>>S[i];
	
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			cnt[S[i][j]-'a']++;
		}
	}
	
	int mul_1 = 0,mul_2 = 0;
	if((H*W)%2==1)mul_1 = 1;
	
	if(H%2==1)mul_2 += W/2;
	if(W%2==1)mul_2 += H/2;
	
	int Mul_1 = 0,Mul_2 = 0;
	
	
	for(int i=0;i<26;i++){
		if(cnt[i]%2==1){
			Mul_1 ++;
		}
		if(cnt[i]%4==2||cnt[i]%4==3){
			Mul_2 ++;
		}
	}
	
	if(Mul_1<=mul_1&&Mul_2<=mul_2){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
		
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  long A,B,C,D;cin>>A>>B>>C>>D;
  
  long P=C,Q=D;
  if(P<Q)swap(P,Q);
  while(P%Q!=0){
    P=P%Q;
    swap(P,Q);
  }
  Q=C*D/Q;
  long a=(A-1)/C,b=B/C,c=(A-1)/D,d=B/D,e=(A-1)/Q,f=B/Q;
  cout<<B-A+1-b+a-d+c+f-e<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K, X, Y;
  cin >> N >> K >> X >> Y;
  if (K <= N) {
  cout << K * X + (N - K) * Y << endl;
  }
  else {
    cout << N * X << endl;
  }
}

Measured memory_bytes: 256
N = int(input())
card = list(map(int,input().split()))
A = 0
B = 0
card.sort(reverse = True)
while True:
    A += card[0]
    card.pop(0)
    if not card:
        break
    B += card[0]
    card.pop(0)
    if not card:
        break
print(A - B)

Measured memory_bytes: 3060
n = int(input())
cc = []
ss = []
ff = []
for i in range(n-1):
    c, s, f = list(map(int, input().split()))
    cc.append(c)
    ss.append(s)
    ff.append(f)
for l in range(n-1):
    ans = ss[l]+cc[l]
    for k in range(l+1, n-1):
        temp = ss[k]
        while temp < ans:
            temp += ff[k]
        ans = temp + cc[k]
    print(ans)
print(0)



Measured memory_bytes: 44828
A, B, C, D = gets.chomp.split(" ").map(&:to_i)
E = C.lcm(D)
ans = B - A + 1

ans -= (B / C) - (A - 1) / C
ans -= (B / D) - (A - 1) / D
ans += (B / E) - (A - 1) / E

puts ans


Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define ll long long
#define REP(i,n) for(int i=0;i<n;i++)
#define PP(m) REP(i, m.size()) cout << m[i] << endl;

int gcd(int a, int b) {
    if(b == 0) return a;
    return gcd(b, a % b);
}

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

int main() {
  int a,b;
  while (cin >> a >> b && a) {
    cout << gcd(a,b) << " " << lcm(a,b) << endl;
  }

  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
typedef unsigned long long ll;
using namespace std;
 
 
 
int main() {
    ll n ; cin>>n; ll a=0 ;
 
    for(int i = 1 ; i <=  pow(n,0.5) ; i++){
        ll k = n/i;
        if(n%i==0){
            int x=0;
            if(i>=k){
                x=k;
            }
            else{
                x=i;
            }
            if(a<x){
                a=x;
            }
        }
    }
   
    cout<<a+n/a-2;
    int l ; cin>>l;
}

Measured memory_bytes: 512
/*  -*- coding: utf-8 -*-
 *
 * d.cc: D - Triangles
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 2000;

/* typedef */

typedef long long ll;

/* global variables */

int ls[MAX_N];

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", ls + i);
  sort(ls, ls + n);

  ll sum = 0;
  for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++) {
      int s = ls[i] + ls[j];
      int k = lower_bound(ls + j + 1, ls + n, s) - (ls + j + 1);
      sum += k;
    }

  printf("%lld\n", sum);
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N, M;
int A[100000];
vector<int> G[100000];
int U[100000];
int R[100000];
bool yes[100000];

int find(int x) {
  if (U[x] == x) return x;
  return U[x] = find(U[x]);
}

void unite(int x, int y) {
  x = find(x), y = find(y);
  if (x == y) return;
  if (R[x] < R[y]) swap(x, y);
  U[y] = x;
  R[x] += R[y];
  R[y] = 0;
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N >> M;
  for (int i=0; i<N; i++) U[i] = i, R[i] = 1;
  rep(i, N) cin >> A[i], A[i]--;
  rep(i, M) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    unite(x, y);
  }
  rep(i, N) G[find(i)].pb(i);
  int ans = 0;
  rep(g, N) if (find(g) == g) {
    for (int x : G[g]) yes[A[x]] = true;
    for (int x : G[g]) if (yes[x]) ans++;
    for (int x : G[g]) yes[A[x]] = false;
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 7040
#pragma GCC optimize ("O3")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ts to_string
#define ub upper_bound
#define lb lower_bound
const char nl = '\n';
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using str = string;
//The following debugging code was taken from Benjamin Qi's template :) 
str ts(char c) { return str(1,c); }
str ts(bool b) { return b ? "true" : "false"; }
str ts(const char* s) { return (str)s; }
str ts(str s) { return s; }
template<class A> str ts(complex<A> c) { 
    stringstream ss; ss << c; return ss.str(); }
str ts(vector<bool> v) { 
    str res = "{"; for(int i = 0;i < (int)v.size(); i++) res += char('0'+v[i]);
    res += "}"; return res; }
template<size_t SZ> str ts(bitset<SZ> b) {
    str res = ""; for(int i = 0; i < b.size(); i++) res += char('0'+b[i]);
    return res; }
template<class A, class B> str ts(pair<A,B> p);
template<class T> str ts(T v) { 
    bool fst = 1; str res = "{";
    for (const auto& x: v) {
        if (!fst) res += ", ";
        fst = 0; res += ts(x);
    }
    res += "}"; return res;
}
template<class A, class B> str ts(pair<A,B> p) {
    return "("+ts(p.f)+", "+ts(p.s)+")"; }
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {
    cerr << ts(h); if (sizeof...(t)) cerr << ", ";
    DBG(t...); }

#ifdef LOCAL 
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
//freopen(".in", "r", stdin);
//freopen(".out", "w", stdout);
#endif
//CODE STARTS HERE-----------------------------------------------------------------------------------------// 
const int N = 1e5 + 10;
int n, m, d[N], vis[N];
vi adj[N];
void dfs(int u){
    vis[u] = 1;
    dbg(u);
    if(adj[u].size() == 0) d[u] = 0;
    for(auto&v : adj[u]){
        if(!vis[v])
            dfs(v);
        d[u] = max(d[u], d[v] + 1);
    }
}
signed main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cin >> n >> m;
    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        // adj[a-1].pb(b-1);
        adj[a-1].pb(b-1);
    }
    memset(d, -1, sizeof(d));
    for(int i =0 ; i < n; i++){
        if(!vis[i]){
            dfs(i);
        }
    }
    int ma = 0;
    for(int i =0 ; i < n; i++){
        dbg(d[i]);
        if(d[i] > ma){
            ma = d[i];
        }
    }
    cout << ma << nl;
}

Measured memory_bytes: 11956
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
//#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vl = vector<ll>;
using vi = vector<int>;
using Graph = vector<vi>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(15); //"for float-base
  // problem"
  string s;
  cin >> s;
  for (auto c : s) {
    if (c == '1')
      cout << '9';
    else
      cout << 1;
  }
  cout << endl;
}

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

int main(void){
   char str[101];
   int str_l,i;

   scanf("%s",str);
   str_l= strlen(str);
   str_l-=2;

   printf("%c",str[0]);
   printf("%d",str_l);
   printf("%c\n",str[str_l+1]);
   return 0;
}

Measured memory_bytes: 128
n,x,y = map(int, input().split())
l = [0]*(n+1)
for i in range(1,n+1):
    for j in range(1,i):#j<i
        a = min(i-j,abs(x-j)+abs(y-i)+1)
        l[a] += 1
for i in range(1,n):
    print(l[i])

Measured memory_bytes: 3444
#include <stdio.h>

int main(void) {
  int E[4];
  for(int i = 0; i < 4; i++) {
    E[i] = 0;
  }

  int A, B;
  for(int i = 0; i < 3; i++) {
    scanf("%d %d", &A, &B);
    E[A-1]++;
    E[B-1]++;
  }

  int One = 0;
  int Two = 0;
  for(int i = 0; i < 4; i++) {
    //printf("E[%d] = %d\n", i, E[i]);
    if(E[i] == 1) One++;
    if(E[i] == 2) Two++;
  }

  if(One == 2 && Two == 2) {
    printf("YES\n");
  } else {
    printf("NO\n");
  }
  
  return 0;
}


Measured memory_bytes: 128
import copy
N,K = map(int,input().split())
A = list(map(int,input().split()))

for i in range(K):
  l = [0]*N
  for i in range(N):
    m,p = i-A[i],i+A[i]
    if p+1 <= N-1:
      l[p+1] -= 1
    if m >= 0:
      l[m] += 1
    if m < 0:
      l[0] += 1
  for i in range(N-1):
    l[i+1] += l[i]
  A = copy.deepcopy(l)
  if A[0] == N:
    break 
print(*A)

Measured memory_bytes: 178276
use proconio::input;

fn main() {
    input! {
        v: [i32; 5]
    }

    let ans = {
        let mut ans = 0;
        for i in 0..5 {
            if v[i] == 0 {
                ans = i;
                break;
            }
        }
        ans+1
    };

    println!("{}",ans)
}


Measured memory_bytes: 2108