akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define INF 1e9
typedef long long ll;
using namespace std;


int wa(int a){
    int ans = 0;
    while(a!=0){
        int num = a % 10;
        ans += num;
        a /= 10;
    }
    return ans;
}

int main() {
    int n; cin >> n;
    if(n%wa(n)==0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static long Mod = (long)1e9 + 7;
        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var N = Sarray()[0];
            var k = 0L;
            for (k = 0; k <= N; ++k)
            {
                if (2 * N == k * (k + 1))
                    break;
            }
            if (2 * N != k * (k + 1))
            {
                WriteLine("No");
                return;
            }
            var ans = Enumerable.Range(0, (int)k + 1).Select(_ => new long[k + 1]).ToArray();
            var s = 1L;
            for (var i = 0; i <= k; ++i)
                ans[i][0] = k;
            for (var i = 0; i < k; ++i)
            {
                for (var j = i + 1; j <= k; ++j)
                    ans[j][i+1] = s + j - (i + 1);
                for (var j = i; j < k; ++j)
                    ans[i][j+1] = s++;
            }
            WriteLine("Yes");
            WriteLine(k + 1);
            for (var i = 0; i <= k; ++i)
                WriteLine(string.Join(" ", ans[i]));
            //Out.Flush();
        }
    }
}

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

int main(){
  int N;
  cin >> N;
  int ans=0;
  for(int i=0; i<N; i++){
    int l,r;
    cin >> l >> r;
    ans+=r-l+1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>

using namespace std;

#define sz			size()
#define lgt			length()
#define rep(i,n)	for (int i = 0; i < n; i++)
#define ALL(X)		(X).begin(),(X).end()
#define RALL(X)		(X).rbegin(),(X).rend()
#define pb			push_back
#define SORT(a)		sort(ALL(a));
#define RSORT(a)	sort(RALL(a));
#define mp			make_pair
#define dump(x)		cerr<<#x<<" = "<<(x)<<endl;
#define fir			first
#define sec			second

typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<string> vs;

int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
vs form(string a,char s){vs v;string b;rep(i,a.lgt){if(a[i]==s){v.pb(b);b="";}else b+=a[i];}v.pb(b);return v;}
vi formint(string a,char s){vi v;string b;rep(i,a.lgt){if(a[i]==s){v.pb(toInt(b));b="";}else b+=a[i];}v.pb(toInt(b));return v;}

const double EPS=1e-10,PI=acos(-1.0);
const int INF=2100000000;

int main(void)
{
	int n, k;
	while (cin >> n >> k, n && k){
		string num[16];
		vector <string> ans;
		for (int i = 0; i < n; i++)	cin >> num[i];
		
		if (k == 2){
			for (int i = 0; i < n; i++){
				for (int j = 0; j < n; j++){
					if (i != j){
//						cout << i << " " << j << endl;
						string tmp;
						tmp += num[i];
						tmp += num[j];
//						cout << "*" << tmp << endl;
						ans.pb(tmp);
					}
				}
			}
		}
		if (k == 3){
			for (int i = 0; i < n; i++){
				for (int j = 0; j < n; j++){
					for (int k = 0; k < n; k++){
						if (i != j && j != k && i != k){
							string tmp;
							tmp += num[i];
							tmp += num[j];
							tmp += num[k];
							ans.pb(tmp);
						}
					}
				}
			}
		}
		if (k == 4){
			for (int i = 0; i < n; i++){
				for (int j = 0; j < n; j++){
					for (int k = 0; k < n; k++){
						for (int l = 0; l < n; l++){
							if (i != j && i != k && i != l && j != k && j != l && k != l){
								string tmp;
								tmp += num[i];
								tmp += num[j];
								tmp += num[k];
								tmp += num[l];
								ans.pb(tmp);
							}
						}
					}
				}
			}
		}
		
		ans.pb("2100000000");
		SORT(ans);
		int res = 0;
		for (int i = 0; i < ans.sz - 1; i++){
			if (ans[i] != ans[i + 1]) res++;
		}
		cout << res << endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int cs[200010];
vector<int> A;
int N;
long long M;

template <typename T>
T binSearch(T first, T last, bool func(T)) {
    T len = last-first;
    while (len != 0) {
        T half = len / 2;
        T mid = first+half;
        if (func(mid)) {
            len -= half + 1;
            first = ++mid;
        } else {
            len = half;
        }
    }
    return first;
}

inline bool check(const int n) {
    long long tmp = 0;
    for (const int a : A) {
        tmp += cs[max(n-a, 0)];
    }
    return tmp > M;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> N >> M;
    A.resize(N);
    for (auto &a : A) {
        cin >> a;
        ++cs[a];
    }
    sort(A.rbegin(), A.rend());
    for (int i = 100000; i > 0; --i) {
        cs[i-1] += cs[i];
    }
    vector<long long> cs2(N+1);
    cs2[0] = 0;
    for (int i = 0; i < (int)A.size(); ++i) {
        cs2[i+1] = cs2[i] + A[i];
    }
    int bs = binSearch<int>(1, 200001, check);
    --bs;
    long long tmp = 0, ans = 0;
    for (const int a : A) {
        const int cnt = cs[max(bs-a, 0)];
        tmp += cnt;
        ans += cs2[cnt];
        ans += (long long)a*cnt;
    }
#ifdef DEBUG
    printf("bs: %d, tmp: %lld, ans: %lld\n", bs, tmp, ans);
#endif
    ans -= (tmp-M)*bs;
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 1792
#!/usr/bin/python
# coding=utf-8


MAX = 10000

def getdata():
    data = map(int, input().split())
    return (list(data))

def countsort(data, max):
    C =[0*x for x in range(0,max)]

    for i in data:
        C[i] += 1

    for i in range(1,max):
        C[i] = C[i] + C[i-1]
    
    B = [i*0 for i in data]
    for i in range(len(data)-1, -1,-1):
        B[C[data[i]]-1] = data[i]   
        C[data[i]] -= 1

    return B

getdata()
ans = countsort(getdata(),MAX)
print(" ".join(map(str,ans)))





Measured memory_bytes: 226300
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

int main() {
    ll H, W;
    cin >> H >> W;

    // 縦
    ll w_opt = 1e18;
    FOR(w, 1, W-1) {
        ll S1 = H * w;
        ll S2_tmp1, S2_tmp2, S3_tmp1, S3_tmp2;
        S2_tmp1 = H * ((W-w) / 2), S3_tmp1 = H * ((W-w+1) / 2);
        S2_tmp2 = (W-w) * (H/2), S3_tmp2 = (W-w) * ((H+1) / 2);

        ll cand1 = max(S1, max(S2_tmp1, S3_tmp1)) - min(S1, min(S2_tmp1, S3_tmp1));
        ll cand2 = max(S1, max(S2_tmp2, S3_tmp2)) - min(S1, min(S2_tmp2, S3_tmp2));
        w_opt = min(w_opt, min(cand1, cand2));
    }

    // 横
    ll h_opt = 1e18;
    FOR(h, 1, H-1) {
        ll S1 = h * W;
        ll S2_tmp1, S2_tmp2, S3_tmp1, S3_tmp2;
        S2_tmp1 = W * ((H-h) / 2), S3_tmp1 = W * ((H-h+1) / 2);
        S2_tmp2 = (H-h)* (W/2), S3_tmp2 = (H-h) * ((W+1) / 2);

        ll cand1 = max(S1, max(S2_tmp1, S3_tmp1)) - min(S1, min(S2_tmp1, S3_tmp1));
        ll cand2 = max(S1, max(S2_tmp2, S3_tmp2)) - min(S1, min(S2_tmp2, S3_tmp2));
        h_opt = min(h_opt, min(cand1, cand2));
    }

    cout << min(w_opt, h_opt) << endl;

    return 0;
}

Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<utility>
#include<algorithm>
#include<cstring>
#include<sstream>
#include <iomanip>

typedef long long ll ;
typedef double db;
typedef unsigned long long ull ;
const double pi = 2*acos(0) ;

#define pf		  	printf
#define sf			  scanf
#define pb(a)         push_back(a)
#define for0(i,n)          for(int i=0;i<n;i++)
#define for1(i,n)          for(int i=1;i<=n;i++)
#define forab(a,b)       for(int i=a;i<=b;i++)
//#define gcd(a, b)     __gcd(a, b)
#define lcm(a, b)     ((a)*((b)/gcd(a,b)))
#define sq(a)		   (a)*(a)
#define nw				"\n"
#define abs(x)		fabs(x)
#define pcase(z,x)     cout<<"Case "<<z<<": "<<x<<"\n"
#define CIN	ios_base::sync_with_stdio(0); cin.tie(0)

using namespace std;

int main()
{
	int r;
	cin>>r;
	db x = 2*pi*(db)r;
	pf("%.2lf\n",x);
	return 0;
}

Measured memory_bytes: 3736
#include<iostream>
#include<vector>


using namespace std;

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

	vector<long long> L;
	L.push_back(2);
	L.push_back(1);
	for (int i = 2; i <= N; i++) {
		long long l = L[i - 1] + L[i - 2];
		//cout << l << endl;
		L.push_back(l);
	}

	cout << L[N] << endl;


}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define RI register int
typedef long long LL;

#define FILEIO(name) freopen(name".in", "r", stdin), freopen(name".out", "w", stdout);

using namespace std;

int main() {
  
#ifdef LOCAL
  FILEIO("a");
#endif

  LL a, b, k;
  cin >> a >> b >> k;
  if (k >= a) {
    k -= a, a = 0;
    if (k >= b) k -= b, b = 0;
    else b -= k;
  }
  else a -= k;
  cout << a << " " << b << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <atcoder/all>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
using namespace atcoder;
void Main()
{
    ll n, m;
    cin >> n >> m;

    vector<string> S(n);
    rep(i, n) cin >> S[i];

    mf_graph<ll> G(n * m + 2);
    ll s = n * m;
    ll t = n * m + 1;

    rep(i, n) {
        rep(j, m) {
            if (S[i][j] == '#') {
                continue;
            }
            if ((i + j) % 2 == 0) {
                G.add_edge(s, i * m + j, 1);
            }
            else {
                G.add_edge(i * m + j, t, 1);
            }

            if ((i + j) % 2 == 0) {
                // 奇数ますとつなげる
                if (i - 1 >= 0 && S[i - 1][j] != '#')
                    G.add_edge(i * m + j, (i - 1) * m + j, 1);
                if (i + 1 < n && S[i + 1][j] != '#')
                    G.add_edge(i * m + j, (i + 1) * m + j, 1);
                if (j - 1 >= 0 && S[i][j-1] != '#')
                    G.add_edge(i * m + j, i * m + j - 1, 1);
                if (j + 1 < m && S[i][j+1] != '#')
                    G.add_edge(i * m + j, i * m + j + 1, 1);
            }
        }
    }

    put(G.flow(s, t));

    for (auto e: G.edges()) {
        if (e.from == s || e.to == t || e.flow == 0)
            continue;

        ll y1 = e.from / m;
        ll x1 = e.from % m;
        ll y2 = e.to / m;
        ll x2 = e.to % m;

        if (x1 - x2 == -1) {
            S[y1][x1] = '>';
            S[y2][x2] = '<';
        }
        else if (x1 - x2 == 1) {
            S[y1][x1] = '<';
            S[y2][x2] = '>';
        }
        else if (y1 - y2 == -1) {
            S[y1][x1] = 'v';
            S[y2][x2] = '^';
        }
        else if (y1 - y2 == 1) {
            S[y1][x1] = '^';
            S[y2][x2] = 'v';
        }
    }

    rep(i, n) put(S[i]);    
}
signed main(){ Main();return 0;}

Measured memory_bytes: 6184
#include<iostream>
#include<algorithm>
#include<cstring>

int main(){

	int r, c;
	while (std::cin >> r >> c, r || c){

		int max = 0;

		int data[11][10001];
		for (int i = 0; i < r; i++){
			for (int j = 0; j < c; j++){
				std::cin >> data[i][j];
			}
		}

		for (int i = 0; i < (1 << r); i++){
			int copy[11][10001];
			memcpy(copy, data, sizeof(copy));

			int res = 0;

			for (int j = 0; j < r; j++){
				if ((i >> j) & 1){
					for (int k = 0; k < c; k++)copy[j][k] = (copy[j][k] + 1) % 2;
				}
			}

			for (int j = 0; j < c; j++){
				int cnt = 0;
				for (int k = 0; k < r; k++){
					if (copy[k][j])cnt++;
				}
				if (cnt < r - cnt)cnt = r - cnt;
				res += cnt;
			}

			max = std::max(max, res);
		}

		std::cout << max << std::endl;
	}

	return 0;
}

Measured memory_bytes: 1984
#include <stdlib.h>

int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

main()
{
  int n,i,data[100001];
  scanf ("%d",&n);
    for (i = 0; i < n; i++) {
     scanf ("%d",&data[i]);
    }
    qsort(data, n, sizeof(int), compare_int);
   /* for (i = 0; i < n; i++) {
        printf("%d ", data[i]);
    }
    printf("\n");*/
  printf ("%d",data[(n/2)]-data[(n/2)-1]);
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define INFF 9223372036854775807
#define ll long long
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,m,n) for(int i=m;i<n;i++)
#define ALL(N) (N.begin(),N.end())
#define de cout << "debug" << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() {
    cin.tie(0);
	ios::sync_with_stdio(false);
    string S;
    cin >> S;
    int ans = 0;
    ans += (15-S.size());

    REP(i,S.size()){
        if(S[i] == 'o'){
            ans++;
        }
    }

    if(ans >= 8) cout << "YES" << endl;
    else cout << "NO" << endl;
}

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

int main() {
  int N = 5;
  vector<int> X(N);
  for (int i = 0; i < N; i++) cin >> X.at(i);
  for (int i = 0; i < N; i++) {
    if (X.at(i) == 0) return cout << i + 1 << "\n", 0;
  }
}

Measured memory_bytes: 3588
// Best practice

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <functional> // for less 

#define int         long long
#define pb          emplace_back
#define pf          emplace_front
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define x           first
#define y           second
#define endl        '\n'
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
using namespace __gnu_pbds; 
 
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> pbds; 

#define fbo find_by_order
#define ook order_of_key

signed main() {
   tezz
   
    int n;
    cin >> n;
    vector<int> a(n);
    int c=1;
    int mm;
    for(int i=0; i<n; i++){
        cin >> a[i];
        if(i!=0){
            if(a[i]<=mm)c++,mm=a[i];
            
        }
        else{
            mm=a[0];
        }
    }
    cout << c << endl;
    
    
   return 0;
}

Measured memory_bytes: 1792
import heapq
n,m = map(int, input().split())
job = {}
for i in range(n):
    a,b = map(int, input().split())
    if a not in job.keys():
        job[a] = [(-b,a)]
    else:
        job[a].append((-b,a))
 
hq = []
 
max_income = 0
for i in range(1,m+1):
    if i in job.keys():
        for j in job[i]:
            heapq.heappush(hq,(j))
    if len(hq) < 1:
        continue
    b_i, a_i = heapq.heappop(hq)
    max_income += -b_i
 
print(max_income)

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


int main() {
  int N;
  cin >> N;
  vector<int64_t> H(N);
  int cnt = 0;
  int cmax = 0;
  int ans = 0;
  for( int i=0; i<N; ++i) {
    cin >> H[i];
  }
  for( int i=0; i<N-1; ++i) {
//    cout << cnt << endl;
    if (H[i] >= H[i+1]) {
      cnt++;
    } else {
      if ( cmax < cnt ) {
        cmax = cnt;
      }
      cnt = 0;
    }
  }
  if ( cmax < cnt ) {
    cmax = cnt;
  }
  ans = cmax;

  cout << ans << endl;

}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define vi vector<int>
#define vll vector<ll>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pb  push_back
#define ppb pop_back
#define mp  make_pair
map<string,int> m;
int main(){
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// #endif
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);
	ll n;
	cin>>n;
	for(int i=0;i<n;++i){
		string str;
		cin>>str;
		m[str]=1;
	}
	cout<<m.size()<<endl;
}

Measured memory_bytes: 19288
#include <stdio.h>

int main(void)
{
	int w,h,x,y,r;
	scanf("%d %d %d %d %d",&w,&h,&x,&y,&r);
	
	if(x+r>w||x-r<0||y+r>h||y-r<0)
		printf("No\n");
	else printf("Yes\n");
	
	return 0;
}

Measured memory_bytes: 584
from collections import deque
time = 1

def dfs(adj_list, d, f, color, u):

    global time
    S = list()

    S.append(u)
    color[u] = "G"
    d[u] = time
    time += 1

    while len(S) != 0:
        u = S[-1]

        if len(adj_list[u]) != 0:
            v = adj_list[u].popleft()

            if color[v] == "W":
                color[v] = "G"
                d[v] = time
                time += 1
                S.append(v)
        else:
            S.pop()
            color[u] = "B"
            f[u] = time
            time += 1

def Main():
    
    N = int(input())
    adj_list = [deque() for n in range(N)]
    d = [0] * N
    f = [0] * N
    color = [ "W" for i in range(len(d)) ]

    for n in range(N):
        u, k, *V = map(int, input().split())

        if k > 0:
            for i in V:
                adj_list[n].append(i - 1)

    while(True):

        ind = None
        for i in range(N):
            if color[i] == "W":
                ind = i
                break

        if ind == None:
            break
        else:
            dfs(adj_list, d, f, color, ind)

    for i in range(N):
        print("{} {} {}".format(i + 1, d[i], f[i] ))

Main()


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

int main(void){
    string S;
    cin >> S;
    int ans=0;
    for(int i=0; i<S.size(); i++){
        int Max=0;
        for(int j=i; j < S.size(); j++){
            if(S.at(j) == 'A' || S.at(j) == 'C' || S.at(j) == 'G' || S.at(j) == 'T'){
            Max++;
            continue;
            }else{
                break;
            }
        }
        if(ans < Max){
            ans = Max;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,n) for (int i = a; i < n; i++)
#define per(i,n,a) for (int i = n - 1; i >= a; i--)
using namespace std;

int main() {
    string s;
    cin >> s;
    cout << (s[0] == 'Y' && s[1] == 'A' && s[2] == 'K' && s[3] == 'I' ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[][] c = new int[n][26];
        
        for (int i = 0; i < n; i++) {
            String str = sc.next();
            for (int j = 0; j < str.length(); j++) {
                char chr = str.charAt(j);
                int toInt = (int)chr - 97;
                c[i][toInt]++;
            }
        }
        
        for (int i = 0; i < 26; i++) {
            int min = Integer.MAX_VALUE;
            for (int j = 0; j < n; j++) {
                min = Math.min(min, c[j][i]);
            }
            
            for (int k = 0; k < min; k++) {
                char toAlphabet = (char)(i + 97);
                System.out.print(toAlphabet);
            }
        }
        
        System.out.println();
    }
}


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

using namespace std;

int main(void)
{
	int n,m; cin>>n>>m;
	int x[m],y[m]; for(int i = 0; i < m; i++) cin>>x[i]>>y[i];
	int list[n+1];
	for(int i = 1; i < n+1; i++) list[i] = 1;
	bool aka[n+1];
	for(int i = 1; i < n+1; i++) aka[i] = false;
	aka[1] = true;
	for(int i = 0; i < m; i++){
		if(aka[x[i]] == true){
			aka[y[i]] = true;
			list[x[i]]--;
			list[y[i]]++;
			if(list[x[i]] == 0){
				aka[x[i]] = false;
			}
		}
		else{
			list[x[i]]--;
			list[y[i]]++;
		}
	}
	
	int ans = 0;
	for(int i = 1; i < n+1; i++){
		if(aka[i] == true) ans++;
	}
	cout<<ans<<endl;
	return 0;
}



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

using namespace std;

int h,w,n;

bool ok(vector<vector<char> > &field) {
  bool flag=true;
  vector<vector<char> > tmap(field);
  while(flag) {
    /*
    for(int i=0;i<h;++i) {
      for(int j=0;j<w;++j) {
	cout << field[i][j];
      }
      cout << endl;
    }
    */
    for(int j=0;j<w;++j) {
      int tmp=0;
      for(int i=h-1;i>=0;--i) {
	if(tmap[i][j]=='.') tmp++;
	else if(tmp) {
	  tmap[i+tmp][j]=tmap[i][j];
	  tmap[i][j]='.';
	}
      }
    }
    field=tmap;
    
    flag=false;
    
    for(int i=0;i<h;++i) {
      for(int j=0;j<w;++j) {
	if(field[i][j]=='.') continue;
	if(i<=h-n) {
	  queue<pair<int,int> > q;
	  q.push(make_pair(i,j));
	  int cnt=0;
	  while(!q.empty()) {
	    cnt++;
	    auto p=q.front(); q.pop();
	    int x=p.first,y=p.second;
	    if(x>=h-1) break;
	    if(field[x][y]==field[x+1][y]) q.push(make_pair(x+1,y));
	  }
	  if(cnt>=n) {
	    flag = true;
	    for(int k=i;k<i+cnt;++k) tmap[k][j]='.';
	  }
	}
	if(j<=w-n) {
	  queue<pair<int,int> > q;
	  q.push(make_pair(i,j));
	  int cnt=0;
	  while(!q.empty()) {
	    cnt++;
	    auto p=q.front(); q.pop();
	    int x=p.first,y=p.second;
	    if(y>=w-1) break;
	    if(field[x][y]==field[x][y+1]) q.push(make_pair(x,y+1));
	  }
	  if(cnt>=n) {
	    flag = true;
	    for(int k=j;k<j+cnt;++k) tmap[i][k]='.';
	  }
	}
      }
    }
    field=tmap;
    
    bool en=true;
    for(int i=0;i<h;++i)
      for(int j=0;j<w;++j)
	if(field[i][j]!='.') en=false;
    if(en) return true;
  }
  return false;
}

int main(){
  cin >> h >> w >> n;
  vector<vector<char> > field(h,vector<char>(w)),tmp;
  int num=0;
  for(int i=0;i<h;++i) {
    for(int j=0;j<w;++j) {
      cin >> field[i][j];
      if(field[i][j]!='.') num++;
    }
  }
  bool flag=false;
  for(int i=0;i<h;++i) {
    for(int j=0;j<w;++j) {
      if(j<w-1) {
	if(field[i][j]!=field[i][j+1]) {
	  tmp = field;
	  swap(tmp[i][j],tmp[i][j+1]);
	  if(ok(tmp)) {
	    cout << "YES" << endl;
	    return 0;
	  }
	}
      }
      if(field[i][j]!='.') {
	tmp=field;
	tmp[i][j]='.';
	if(ok(tmp)) {
	  cout << "YES" << endl;
	  return 0;
	}
      }
    }
  }
  cout << "NO" << endl;
  
  return 0;
}



Measured memory_bytes: 3160
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define pb push_back
#define endl '\n'
#define PI acos(-1)
#define bitcount(a) __builtin_popcountll(a)
#define P pair<int,int>
#define ff first
#define ss second
typedef tree<int,null_type,less_equal <int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
long double eps=1e-9;
int mod=1e9+7;

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin>>n;
	int ans=n-1;
	for(int i=1;i*i<=n;i++)
	{
		if(n%i==0)
		{
			int one=i;int two=n/i;
			ans=min(ans,one-1+two-1);
		}
	}
	cout<<ans;
	return 0;
}

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

int main(void){
  
 	int x, y; cin >> x >> y;
  	int a[] = {1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};
  	cout << ( a[x-1] == a[y-1] ? "Yes":"No") << endl;
  
  	return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> vi;

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

	int n, k, x, y, s;
	cin >> n >> k >> x >> y;
	if (n > k) {
		s = k * x + (n-k) * y;
	} else if (n==k){
		s = k*x;
	} else {
		s = n*x;
	}
	cout << s;
	return 0;
}


Measured memory_bytes: 3608
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val aList = readLine()!!.split(" ").map(String::toLong)
    val bList = readLine()!!.split(" ").map(String::toLong)
    val diffList = aList.zip(bList).map { it -> it.second - it.first }
    // val positiveSum = diffList.filter { it >= 0 }.sum()
    val negativeSum = diffList.filter { it < 0 }.sum() * -1
    val positiveTwoSum = diffList.filter { it >= 2 }.map { it / 2 }.sum()
    println(if (positiveTwoSum >=  negativeSum) "Yes" else "No")
}

Measured memory_bytes: 42192
#include<bits/stdc++.h>
#define C(x,y) ((y)<=(x)?1ll*fac[x]*invf[y]%mod*invf[x-(y)]%mod:0)
using namespace std;
const int mod=1e9+7;
int n,m,a[20],dp[20][(1<<16)+10],t[(1<<16)+10],fac[(1<<16)+10],invf[(1<<16)+10],ans;
int POW(int x,int y){
	int ret=1;
	while(y)y&1?ret=1ll*ret*x%mod:0,x=1ll*x*x%mod,y>>=1;
	return ret;
}
int main(){
	scanf("%d%d",&n,&m),fac[0]=t[0]=1;
	for(int i=1;i<(1<<n);++i)t[i]=t[i>>1]*((i&1)?-1:1),fac[i]=1ll*fac[i-1]*i%mod;
	invf[(1<<n)-1]=POW(fac[(1<<n)-1],mod-2);
	for(int i=(1<<n)-2;i>=0;--i)invf[i]=1ll*invf[i+1]*(i+1)%mod;
	for(int i=1;i<=m;++i)scanf("%d",&a[i]);
	sort(a+1,a+m+1),reverse(a+1,a+m+1);
	dp[0][0]=1;
	for(int i=0;i<m;++i)for(int j=0;j<(1<<n);++j)if(dp[i][j]){
		dp[i+1][j]=(dp[i+1][j]+dp[i][j])%mod;
		for(int k=0;k<n;++k)if(!(j&(1<<k)))dp[i+1][j|(1<<k)]=(dp[i+1][j|(1<<k)]+1ll*C((1<<n)-a[i+1]-j,(1<<k)-1)*fac[1<<k]%mod*dp[i][j])%mod;
	}
	for(int i=0;i<(1<<n);++i)ans=(ans+1ll*t[i]*dp[m][i]%mod*fac[(1<<n)-i-1]%mod+mod)%mod;
	printf("%lld\n",1ll*ans*(1<<n)%mod);
	return 0;
}

Measured memory_bytes: 4608
def choose2(number):
	if number>=2:
		return (number*(number-1))/2
	else:
		return 0
N = int(input())
k = list(map(int,input().split()))
valArr = list(set(k))
occurence = []
occurenceIndex = []
mx = 0
for l in k:
	if l>mx:
		mx=l
for i in range(mx+1):
	occurence.append(0)
for j in range(N):
	occurence[k[j]]+=1
	
			
'''6*5/2
5*4/2
N*(N-1)/2
(N-2)*(N-1)/2
N*(N-1)/2*(N-2)/N
occurence = [1,2,3]
ans = 0+2*1/2+3*2/2
k val = 3
correct = 0+2*1/2+2*1/2

'''
ans = 0
for time in range(len(occurence)):
	ans+=choose2(occurence[time])
for ball in range(N):
	kans = ans-choose2(occurence[k[ball]])+choose2(occurence[k[ball]]-1)
	
	print(int(kans))


Measured memory_bytes: 26140
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>
#include <queue>
#include <deque>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T> &p){ cout << "[" << p.first << ", " << p.second << "]"; return os; }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define Return(expr) { Cout(expr); return 0; }
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(int, n);
    Cins(int, n, a);
    
    int s = 0;
    For(i, n) s ^= a[i];
    
    For(i, n){
        cout << (s ^ a[i]) << " ";
    }
    Cout();
}



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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "YES" << '\n'; exit(0); }
inline void no() { cout << "NO" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> inline T bis(T ok, T ng, function<bool(T)> f, T eps = 1) { while (abs(ok - ng) > eps) { T mi = (ok + ng) / 2; (f(mi) ? ok : ng) = mi; } return ok; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int n;
  cin >> n;
  set<int> se;
  rep(i, n) {
    int a;
    cin >> a;
    if (se.count(a)) no();
    se.insert(a);
  }
  yes();
}


Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
long long m,x,y;
int n,ans;
int main()
{
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		cin>>x>>y;
		if(x*x+y*y<=m*m)ans++;
	}
	cout<<ans;
} 

Measured memory_bytes: 3628
s = str(input())

for i in range(1, len(s)):
    s_del = s[:(-1)*i]
    if len(s_del) % 2 == 1:
        continue
    else:
        half = int(len(s_del) / 2)
        if s_del[:half] == s_del[half:]:
            ans = len(s_del)
            break

print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>
#include <cmath>

#define rep(i,b,e) for (int (i) = (b); (i) < (e); (i)++)
typedef long long ll;


using namespace std;

int main() {

    int N;
    cin >> N;

    int ans = 0;
    for (int i = 1; i <= N; i+=2) {
        int cnt = 0;
        for (int j = i; j > 0; j-=2) {
            if ((i%j)==0) {
                cnt++;
                //cout << j << endl;
            }
        }
        if (cnt == 8) { 
            ans ++;
            //cout << i << endl;
        }
    }
    cout << ans << endl;


}

Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for _ in range(n)]
def LIR(n):
    return [LI() for _ in range(n)]
def SR(n):
    return [S() for _ in range(n)]
def LSR(n):
    return [LS() for _ in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    f = [1]*n
    f[1] = 1
    for i in range(1,n):
        j = 2*i
        fi = f[i]
        while j < n:
            f[j] += 1
            j += i
    print(sum(f)-1)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 75880
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn solve(q: i32, p: i32, r: i32) -> i32 {
    let total = q + p + r;
    let max = std::cmp::max(q, std::cmp::max(p, r));
    total - max
}

fn main() {
    let q: i32 = read();
    let p: i32 = read();
    let r: i32 = read();
    let ans = solve(q, p, r);
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int n; cin >> n;
    vector<int> d(n);
    for (int i = 0; i < n; i++)
    {
        cin >> d[i];
    }
    sort(d.begin(),d.end());
    int base=0;
    int ans =0;
    for (int i = 0; i < n; i++)
    {
        if (base !=d[i] )
        {
            ans++;
        }
        base = d[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 3524
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) ((x).begin()),((x).end())
#define usecppio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

int B[101010];
int A[101010];
int res = 0;
int main()
{
	usecppio
	int n;
	cin >> n;
	B[0] = INT_MAX;
	B[n] = INT_MAX;
	for (int i = 1; i<=n-1; i++)
	{
		cin >> B[i];
	}
	for (int i = 1; i<=n; i++)
	{
		A[i] = min(B[i],B[i-1]);
		res += A[i];
	}
	cout << res << '\n';
}

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

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

cnt = max(0, a[0] - x)
a[0] -= cnt
for i in range(1, n):
    eat = max(0, a[i-1] + a[i] - x)
    a[i] -= eat
    cnt += eat

print(cnt)


Measured memory_bytes: 14252
#include <iostream>
#include <string>
#include <vector>

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

    std::vector<int> count(N, 0);

    int penalty = 0, pts = 0;

    for (int i = 0; i < M; ++i) {
        int p;
        std::string S;

        std::cin >> p >> S;
        if (S == "AC") {
            if (count[p] != -1) {
                penalty += count[p];
                count[p] = -1;
                pts++;
            }
        } else {
            if (count[p] != -1) {
                count[p]++;
            }
        }
    }

    std::cout << pts << ' ' << penalty << std::endl;

    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define Loop(i,a,b) for(int i=a;i<b;++i)
#define NLoop(i,a,b) for(int i=a;i>=b;--i)
#define print(arr,n,m) for(int i=0;i<n;++i) { for(int j=0;j<m;++j) cout<<arr[i][j]<<" "; cout<<endl; }
#define print2(arr,n) for(int i=0;i<n;++i) { cout<<arr[i]<<" "; } cout<<endl;
#define mp(a,b) make_pair(a,b)
#define MOD 1000000007
#define pb(x) push_back(x)
#define ub(x,el) upper_bound(x.begin(),x.end(),el) - x.begin()
#define lb(x,el) lower_bound(x.begin(),x.end(),el) - x.begin();
#define bs(x,el) binary_search(x.begin(),x.end(),el)
using namespace std;
typedef long long int ll;
ll gcd(ll a,ll b) { if (b == 0) return a; return gcd(b, a % b);  }

ll power(ll x,ll y, ll p) { ll res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res*x) % p; y = y>>1; x = (x*x) % p;   } return res; } 
//class compare { public: bool operator() (ll a,ll b) { return a>b;};
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	ll x,a;
	cin>>x>>a;
	if(x<a) cout<<0<<endl;
	else cout<<10<<endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Sun Jul  5 21:03:34 2020

@author: NEC-PCuser
"""

N = int(input())

a = [0,0,0,0]

for i in range(N):
    s = input()
    if s == 'AC':
        a[0] += 1
    elif s == 'WA':
        a[1] += 1
    elif s == 'TLE':
        a[2] += 1
    elif s == 'RE':
        a[3] += 1

print("AC x " + str(a[0]))
print("WA x " + str(a[1]))
print("TLE x " + str(a[2]))
print("RE x " + str(a[3]))

Measured memory_bytes: 9208
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;
const int maxn = -1;

const double eps = 1e-7;
bool eq(const double &a, double const &b) { return fabs(a - b) < eps; }
bool ls(const double &a, double const &b) { return a + eps < b; }

map <int,bool> M;

int main ()
{
    int n;
    scanf("%d",&n);
    int ans = 0;
    rep(i,0,n) {
        int t;
        scanf("%d",&t);
        if (M[t]) {
            M[t] = false;
            ans--;
        } else {
            M[t] = true;
            ans++;
        }
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 4864
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Scanner;


class Main {
	public static void main(String[] args) throws IOException {
		DecimalFormat df1 = new DecimalFormat("0.000");
		Scanner in = new Scanner(System.in);
		ArrayList<String> SL = new ArrayList<String>();
		
		
		while((in.hasNext())){
			String li = in.nextLine();
			String[] ss = li.split(" ");
			double x1 = Double.parseDouble(ss[0]);
			double y1 = Double.parseDouble(ss[1]);
			double a1 = Double.parseDouble(ss[2]);
			double x2 = Double.parseDouble(ss[3]);
			double y2 = Double.parseDouble(ss[4]);
			double a2 = Double.parseDouble(ss[5]);
			double y3 = y1*x2 - y2*x1;
			double a3 = a1*x2 - a2*x1;
			double y = a3/y3;
			double x = (a1 - y1*y) / x1;
			System.out.println(df1.format(x) +" "+df1.format(y));
			}
		
		
	}

}

Measured memory_bytes: 17172
import collections
n, m = map(int, input().split())
h = list(map(int, input().split()))
l = [-1 for _ in range(n)]
a = [tuple(map(int, input().split())) for _ in range(m)]
for i in a:
    if h[i[0] - 1] > h[i[1] - 1]:
        l[i[1] - 1] = 0
    elif h[i[0] - 1] == h[i[1] - 1]:
        l[i[1] - 1] = 0
        l[i[0] - 1] = 0
    else:
        l[i[0] - 1] = 0

c = collections.Counter(l)
print(n - c[0])

Measured memory_bytes: 27720
#include<bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(0)
#define loop(i, a, b) for(lli i=a; i<b; i++)
#define loopb(i, a, b) for(lli i=a; i>=b; i--)
#define pb push_back
#define umap unordered_map
typedef long long int lli;
typedef pair<lli, lli> pii;
typedef vector<lli> vll;
typedef pair<lli, pii> ppi;
typedef tree<lli, null_type, less<lli>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// use to avoid collision
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);
    }
};
// for pair in unordered_map
struct hash_pair {
    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);
    }
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const{
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        uint64_t x = hash1 ^ hash2;
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
lli M = 1e9 + 7;
lli power(lli x, lli y){
    lli res = 1;
    x = x%M ;
    while (y > 0) {
        if (y & 1)
            res = (res*x)%M ;
        y = y>>1;
        x = (x*x)%M;
    }
    return res%M;
}
const double PI = 3.141592653589793238463;
lli solve(){
    lli h, w;
    cin>>h>>w;
    if(h == 1 || w == 1){
        cout<<1<<"\n";
        return 0;
    }
    lli ans = floor(h/2.0) * (ceil(w/2.0) + floor(w / 2.0));
    if(h%2 == 1)
        ans += ceil(w/2.0);
    cout<<ans<<"\n";
    return 0;
}
int main(){
    fastio;
    lli t;
    // cin>>t;
    t = 1;
    while(t>0){
        t--;
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
/*بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيم*/

#include <bits/stdc++.h>
using namespace std;

const int mx=1e5+5;
vector <int> edges[mx];
int cnt,level[mx],dist[mx];
bool vis[mx];
void dfs (int u,int d,int ara[])
{
    vis[u]=true;
    ara[u]=d;
    for (int v : edges[u]) {
        if (!vis[v]) dfs(v,d+1,ara);
    }
}
int main ()
{
    int i,n,a,b;

    scanf ("%d",&n);
    for (i=1;i<n;i++) {
        scanf ("%d %d",&a,&b);
        edges[a].push_back(b);
        edges[b].push_back(a);
    }
    memset(vis,0,sizeof(vis));
    dfs(1,0,level);
    memset(vis,0,sizeof(vis));
    dfs(n,0,dist);
    cnt=0;
    for (i=1;i<=n;i++) if (dist[i]<level[i]) cnt++;
    int m=n-cnt;
    if (m>cnt) printf ("Fennec\n");
    else printf("Snuke\n");

    return 0;
}


Measured memory_bytes: 13312
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy,copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
	lis = [1, 2, 3]
	lis.remove(INT())
	lis.remove(INT())
	print(*lis)
	

if __name__=='__main__':
	main()


Measured memory_bytes: 5148
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
long long solve(string s) {
	long long ans = 0;
	int cnt = 0;
	for(int i = 0; i < s.size(); ++i) {
		if(s[i] == 'X') {
			ans += i - cnt;
			++cnt;
		}
	}
	return ans;
}
int main() {
	string s;
	cin >> s;
	int n = s.size();
	string t;
	for(int i = 0; i < n; ++i) {
		t += s[i];
		if(t.size() >= 2 && t.substr(t.size() - 2, 2) == "BC") {
			t.pop_back();
			t.pop_back();
			t += "X";
		}
	}
	int pre = 0; long long ans = 0;
	for(int i = 0; i <= t.size(); ++i) {
		if(i == t.size() || (t[i] != 'A' && t[i] != 'X')) {
			if(pre != i) {
				ans += solve(t.substr(pre, i - pre));
			}
			pre = i + 1;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 904
#include <cstdio>
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
 
using namespace std;
 
int gcd(int u, int v) {
int r;
while (0 != v) {
r = u % v; u = v; v = r;
}
return u;
}
 
map<pair<int,int>,int>x;
 
 
int main(void) {
 
	int N;
 
	scanf("%d",&N);
	
	int a,b,c;
 
	for(c=1;c<=3500;c++){
		if((4*c)-N>0){
		int div=gcd(N*c,(4*c)-N);
		x[make_pair(((4*c)-N)/div,(N*c)/div)]=c;
		}
	}
 
	for(a=1;a<=3500;a++){
		for(b=3*N/4;b<=3500;b++){
			int div=gcd(a+b,a*b);
			if(x[make_pair((a+b)/div,(a*b)/div)]>0){
				printf("%d %d %d\n",a,b,x[make_pair((a+b)/div,(a*b)/div)]);
				return 0;
			}
		}
	}
 
	return 0;
}

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

const int N = 100005, P = 1000000007;
int n, sum[N], dp[N], fst[N];
vector<int> pos[3];
char s[N];

int main() {
	scanf("%s", s + 1), n = strlen(s + 1);
	bool flag = true;
	for (int i = 2; i <= n; ++i)
		flag &= s[i] != s[i - 1];
	if (flag) return puts("1"), 0;
	for (int i = 1; i <= n; ++i) {
		sum[i] = (sum[i - 1] + (s[i] == 'a' ? 1 : 2)) % 3;
		pos[sum[i]].push_back(i);
	}
	fst[n] = n + 1;
	for (int i = n - 1; i; --i)
		if (s[i] == s[i + 1]) fst[i] = i;
		else fst[i] = fst[i + 1];
	dp[0] = 1;
	for (int i = 0; i < n; ++i) {
		dp[i + 1] = (dp[i + 1] + dp[i]) % P;
		char x = 'a' + 'b' - s[i + 1];
		if (fst[i + 1] <= n) {
			const auto &v = pos[(sum[i] + (x == 'a' ? 1 : 2)) % 3];
			int t = lower_bound(v.begin(), v.end(), fst[i + 1]) - v.begin();
			if (t != v.size())
				dp[v[t]] = (dp[v[t]] + dp[i]) % P;
		}
	}
	int ans = 0;
	for (int i = 1; i <= n; ++i)
		if (sum[i] == sum[n]) ans = (ans + dp[i]) % P;
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 2168