akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <cstring>
#include <bits/stdc++.h>

typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n,m) for(int i=n;i<m;i++)
#define repn1(i,n,m) for(int i=n;i<=m;i++)
using namespace std;

const int INF = 1e+8;

int main(){

	int n;
	int ave[5];

	rep(i, 5){
		cin >> n;
		if(n <= 40) ave[i] = 40;
		else ave[i] = n;
	}
	n = 0;

	rep(i,5) n += ave[i];

	cout << n/5 << endl;


	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
using ll = long long;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rep2(i, s, n) for(ll i = s; i < n; i++)
using namespace std;

const ll MAX = 10000;
const ll MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit(){
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

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

int main(){
  ll n, k;
  cin >> n >> k;
  
  COMinit();
  rep2(i, 1, k+1) cout << COM(n-k+1, i) * COM(k-1, i-1) % MOD << endl;
  
  return 0;
}

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

int main() {
    string S;
    cin >> S;
    if(S == "Sunny") cout << "Cloudy" << endl;
    if(S == "Cloudy") cout << "Rainy" << endl;
    if(S == "Rainy") cout << "Sunny" << endl;
    return 0;
}

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

int main(){
    string S;
    cin >> S;
    int N = S.size();
    S += "ZZZ";

    int64_t i = 0, a = 0, ans = 0;
    while(i < N){
        if(S[i] == 'A'){
            a++;
            i++;
        }else if(S.substr(i, 2) == "BC"){
            ans += a;
            i += 2;
        }else{
            a = 0;
            i++;
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

int main()
{
	int n;
	cin >> n;
	int a[100000];
	int ans = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		for (;;)
		{
			if (a[i] % 2 == 0)
			{
				a[i] /= 2;
				ans++;
			}
			else
			{
				break;
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(a) int((a).size())
 
int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
     
    string s;
    cin>>s;
    ll n = sz(s),i,j;
    ll mn, mx;
    ll a,b;
    i = 0;
    ll ans =  0;
    while(i<n && s[i] == '>') i++;
    ans += (i*(i+1))/2;
    while(i<n)
    {
        a = 0;
        b = 0;
        if(s[i] == '<')
        {
            while(i<n && s[i] == '<') a++,i++;
            while(i<n && s[i] == '>') b++,i++;
        }
        else
        {
            while(i<n && s[i] == '>') a++,i++;
            while(i<n && s[i] == '<') b++,i++;
        }
        mx = max(a,b);
        mn = min(a,b);
        ans += (mx*(mx+1))/2;
        if(mn > 1)
        {
            mn--;
            ans += (mn*(mn+1))/2;
        }
    }
    cout<<ans;
}

Measured memory_bytes: 1172
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <map>
#include <vector>

using namespace std;

using namespace std;

int n, k;
map<int, int> mp;
vector<int> vec;

int main() {
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; i++) {
        int x = 0; scanf("%d", &x);
        mp[x] ++;
    }
    if (mp.size() <= k) printf("0\n");
    else {
        int ans = 0;
        for (map<int, int>::iterator iter = mp.begin(); iter != mp.end(); ++iter) {
            vec.push_back(iter->second);
        }
        sort(vec.begin(), vec.end());
        for (int i = 0; i < vec.size()-k; i++) ans += vec[i];
        printf("%d\n", ans);
    }
    return 0;
}

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

#define fi                      first
#define se                      second
#define pb                      push_back
#define endl                    '\n'
#define all(x)                  x.begin(),x.end()
#define pii                     pair<int,int>
#define pll                     pair< long long int, long long int> 
#define fast                    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define SZ(x)                   ((int)x.size())

#define FOR(i,a,b)              for(int i = a; i < b; ++i)
#define REV(i,a,b)              for(int i = a; i >= b; --i)
#define FORE(i,a,b)             for(int i = a; i <= b; ++i)

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

void solve();

int32_t main()
{
        fast;
        int t = 1;
        // cin >> t;
        for(int i = 1; i <= t; ++i)
                solve();
        cerr << "Time taken: " << ((clock() * 1000) / CLOCKS_PER_SEC) << "ms\n";
}

#define int ull
void solve() {
	int h,w;
	cin >> h >> w;
	if(min(h,w) == 1) {
		cout << 1 << endl;
		return;
	}
	int ans = (h - (h/2)) * (w - (w/2)) + (h/2) * (w/2);
	cout << ans << endl;        
}

Measured memory_bytes: 256
my $in1 = get;
my $n = chomp($in1);

my $in2 = get;
my $s = chomp($in2);
my @d = split(" ",$s);
my @data;

for @d -> $s {
	@data.push($s.Int);
}
#@data .= sort: { $^b leg $^a };
#say @data;
my $ans = 0;

loop (my $i = 0; $i < @data.elems  ;$i++) {
	loop (my $j = $i+1; $j < @data.elems ; $j++) {
		loop (my $k = $j+1; $k < @data.elems;$k++) {
			#say "$i ~ ',' ~ $j ~ ',' ~ $k";
			if check(@data[$i],@data[$j], @data[$k]) == True {
				$ans +=1;
			}
		}
	}
}

say $ans;


sub check (Int $i, Int $j, Int $k ) {
	if  $i + $j > $k && $j + $k > $i && $k + $i > $j  {
		if $i != $j && $i != $k && $j != $k {
			return True;
		} 
	}
}


Measured memory_bytes: 110364
#include <bits/stdc++.h>
#define ss second
#define ff first
#define all(x) x.begin(), x.end()
// #define DEBUG 10
 
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<ll, ll>;
 
const int oo = 1e9 + 7;
const ll mod = 1e9+7, maxn = 20, maxm = (1 << 18);
const ld PI = acos(-1);


bool check(ll a, ll b){
    return a > b;
}


int main (){
    ios_base::sync_with_stdio(false);
    ll n, m;

    cin >> n >> m;

    vector<ll> vs(n), ps(n);

    for (auto &x : vs) cin >> x;

    sort(all(vs), check);

    ps[0] = vs[0];

    for (int i=1;i<n; i++) ps[i] = ps[i-1] + vs[i];

    ll l = 0, r = 2 * 1e5 + 100, ans, cnt;

    while (l < r - 1) {
        ll mid = (l+r)/2, pos = n-1, count = 0, sum = 0;

        for (int i=0; i<n; i++){
            while (pos >= 0 and (vs[i] + vs[pos] < mid)) pos--;
            if (pos < 0) break;
            count += pos + 1;
            sum += vs[i]*(pos + 1) + ps[pos];
        }

        if (count >= m){
            l = mid;
            cnt = count;
            ans = sum;
        }
        else {
            r = mid;
        }
    }

    cout << ans - (cnt - m) * l << endl;
    return 0;
}

Measured memory_bytes: 4828
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using ll = long long int;

int main(){
    ll N; cin >> N;
    vll A(N+1);
    map<ll, ll> m;
    map<ll, ll> n;
    for(int i=1; i<N+1; i++){
        ll a, b;
        cin >> A[i];
        a = i - A[i];
        b = i + A[i];
        if(m.find(a) == m.end()){
            m[a] = 1;
        }else{
            m[a]++;
        }
        if(n.find(b) == n.end()){
            n[b] = 1;
        }else{
            n[b]++;
        }
    }
    ll c = 0;
    for(int i=1; i<N+1; i++){
        ll p = A[i] + i;
        if(m.find(p) != m.end()){
            c += m[p];
        }
        ll q = i - A[i];
        if(n.find(q) != n.end()){
            c += n[q];
        }
    }
    cout << c/2;
}

Measured memory_bytes: 27980
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;


using namespace std;

#define debug(x) cout << '>' << #x << ':' << x << endl;
#define loop(i,n) for(int i=0;i<(int)(n);i++)
#define foi(i,k,n) for(int i=(k); i<(int)(n); i+=1)
#define fod(i,n,k) for(int i=k; i>=(int)n; i-=1)
#define fast_io ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define all(x) x.begin(), x.end()
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define endl "\n"


#define INF 0x3f3f3f3f
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007

#define fir first
#define sec second
#define pb push_back
#define mp make_pair

typedef long long int llint;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<llint> VL;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MII;
typedef set<int> SI;
string tostr(int n) {stringstream rr;rr<<n;return rr.str();}
llint toint(string s) {stringstream ss(s); llint x; ss >> x; return x;}
//gp_hash_table<string, llint> table;


//int mpow(llint base, llint exp) {
  //base %= MOD;
  //llint result = 1;
  //while (exp > 0) {
    //if (exp & 1) result = ((llint)result * base) % MOD;
    //base = ((llint)base * base) % MOD;
    //exp >>= 1;
  //}
  //return result;
//}


//void makegraph(int n, int m){
	//int i, u, v;
	//while(m--){
		//cin>>u>>v;
		//u--, v--;
		//g[u].pb(v);
		//g[v].pb(u);
	//}
//}

//void dfs(int u, int par){
	//for(int v:g[u]){
		//if (v == par) continue;
		//dfs(v, u);
	//}
//}


// ------------------------------------------------------------------ILB----------------------------------------------------------------  //


int n, k;
VI v;

bool bs(int x){
	int moves = 0;
	for(auto i : v){
		if(i <= x) break;
		int t = i / x;
		//if((i + t - 1) / t > x) t++;
		moves += t;
		if(moves > k) return false;
	}
	
	return true;
}


void solve(){
	cin >> n >> k;
	v.resize(n);
	
	loop(i, n) cin >> v[i];
	
	sort(all(v), greater<int>());
	int l = 0, r = *max_element(all(v));
	
	
	while(r - l > 1){
		int m = l + (r - l) / 2;
		bs(m) ? r = m : l = m;
	} 
	
	cout << r;
}




int main() {
	fast_io;
    int t = 1;
    //cin >> t;
    //int xx = 0
    while(t--) {
		//xx++;
		//cout << "Case ";
      solve();
    }
    return 0;
}



Measured memory_bytes: 3924
#include<bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin>>S;
  int no=0;
  for(int i=0;i<S.size()/2;i++) {
    
    if(S.at(i) != S.at(S.size()-1-i)) {
      no++;
    }
  }
  cout <<no<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.begin(), c.end()
#define Cin(T, x) T x; cin >> x;
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i];
#define Cout(val) cout << (val) << "\n";
#define Sort(a) sort(Range(a));
#define DeSort(a) sort(RevRange(a));

using namespace std;
using ll = long long;

int main(void){
    Cin(string, a);
    Cin(string, b);
    Cin(string, c);
    //Cout();
    //Cout(() ? "Yes" : "No");
    Cout((a.back() == b.front() && b.back() == c.front()) ? "YES" : "NO");
}


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

#define int long long
const int MOD = 1000000007;

signed main(){

    int n, m; cin >> n >> m;
    vector<int> x(m);
    for(int i = 0; i < m; i++){
        cin >> x[i];
    }

    sort(x.begin(), x.end());
    vector<int> l;
    for(int i = 1; i < m; i++) l.push_back(x[i] - x[i - 1]);
    int ans = 0;
    sort(l.begin(), l.end());
    for(int i = 0; i < m - n; i++){
        ans += l[i];
    }

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

Measured memory_bytes: 2168
#include <bits/stdc++.h>
#define PREP(i, s, x) for(ll i = (s); i < (x); i++)
#define MREP(i, s, x) for(ll i = (s); i >= (x); i--)
#define REP(i, x) PREP(i, 0, x)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template<typename T> inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); }
template<typename T> inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); }

// variable -------------------------------------------

constexpr ll INF = (1ll << 60);
constexpr ll MOD = 998244353ll;

// structure ------------------------------------------

// function -------------------------------------------

// main -----------------------------------------------

int main() {
    ll n, m;
    cin >> n >> m;
    vector<ll> w(n), v(n);
    ll sum = 0;
    REP(i, n) {
        cin >> w[i] >> v[i];
        sum += v[i];
    }

    vector<vector<ll>> dp(n + 1, vector<ll>(sum + 1, INF));
    dp[0][0] = 0;
    REP(i, n) {
        REP(j, sum + 1) {
            chmin(dp[i + 1][j], dp[i][j]);
            if(j - v[i] >= 0) { chmin(dp[i + 1][j], dp[i][j - v[i]] + w[i]); }
        }
    }

    ll ans = 0;
    MREP(j, sum, 0){
        if(dp[n][j] <= m){
            ans = j;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 80256
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
void solve() {
	long long s, d; cin >> s >> d;
	int cnt = 0;
	while (true) {
		if (s == d)break;
		else if (d - s == 1) {
			cnt++; break;
		}
		if (s % 2 != 0) {
			cnt++; s++;
		}
		if (d % 2 != 0) {
			cnt++; d--;
		}
		s /= 2; d /= 2;
	}
	cout << cnt << endl;
	return;
}
int main() {
	int n; cin >> n;
	for (int i = 0; i < n; i++)solve();
}

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

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

#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(ll i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const double PI = 3.1415926535;
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;

ll modPow(ll a, ll n, ll p) {
  if (n == 0) return 1;
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modPow(a, n - 1, p)) % p;
  ll t = modPow(a, n / 2, p);
  return (t * t) % p;
}

int main(){
    int n;
    cin >> n;
    map<ll,ll>mp;
    vector<ll>a(n);
    rep(i, 0, n)cin >> a[i];
    lrep(i, 0, n){
        ll p = a[i];
        sqrep(j, 2, a[i]){
            ll cnt=0;
            while(p%j==0){
                p /= j;
                cnt++;
            }
            if(mp[j]<cnt)mp[j]=cnt;
        }
        //cout << p << endl;
        if(p>1 && mp[p]==0)mp[p]++;
    }
    ll x = 1;
    for(auto i:mp){
        ll y = modPow(i.first, i.second, mod);
        x = x * y % mod;
    }
    ll ans = 0;
    rep(i, 0, n){
        ll z = modPow(a[i], mod-2, mod);
        ans += (x*z)%mod;
        ans %= mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4252
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll mod = 1e9 + 7;

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

  ll n;
  cin >> n;

  ll a[4];
  REP(i, 4){
    a[3 - i] = n % 10;
    n /= 10;
  }
  ll p, q, r;
  char x, y, z;
  REP(i, 2){
    REP(j, 2){
      REP(k, 2){
        if(i){
          p = a[1];
          x = '+';
        }
        else{
          p = -a[1];
          x = '-';
        }

        if(j){
          q = a[2];
          y = '+';
        }

        else{
          q = -a[2];
          y = '-';
        }

        if(k){
          r = a[3];
          z = '+';
        }
        else{
          r = -a[3];
          z = '-';
        }

        if(a[0] + p + q + r == 7){
          cout << a[0] << x << a[1] << y << a[2] << z << a[3] << "=7" << endl;
          return 0;
        }
      }
    }
  }


  return 0;
}


Measured memory_bytes: 256
require 'prime'

N = gets.to_i

def _divisors(primes, k)
  Enumerator.new do |y|
    if primes.size == k
      y << 1
    else
      p, e = primes[k]
      _divisors(primes, k + 1).each {|d|
        (e + 1).times {|e1|
          y << p ** e1 * d
        }
      }
    end
  end
end

def divisors(n)
  _divisors(Prime.prime_division(n), 0).to_a.sort
end

arr = divisors(N)
num = arr.length
if num % 2 == 0
    puts arr[num/2] + arr[num/2-1] - 2
else
    puts arr[num/2] + arr[num/2] - 2
end


Measured memory_bytes: 4092
#include <bits/stdc++.h>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
typedef tuple<ll,int,int> tup;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vp;
int A,P;
int main(int argc,char const* argv[])
{
  cin >> A >> P;
  cout << (A*3+P)/2 << endl;
  return 0;
}


Measured memory_bytes: 764
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>

using namespace std;

/////////////         qsortのラッピング

int qsort_int_compare_ascend(const void* a, const void* b) {
	return *(int*)a - *(int*)b;
}
int qsort_int_compare_descend(const void* a, const void* b) {
	return *(int*)b - *(int*)a;
}
void ascendOrder(int size, int* array) {//昇順
	qsort(array, size, sizeof(int), qsort_int_compare_ascend);
}
void descendOrder(int size, int* array) {//降順
	qsort(array, size, sizeof(int), qsort_int_compare_descend);
}

int main() {
	int K; cin >> K;
	int N;
	{
		N = 1;
		for (int i = 0; i < K; i++) {
			N *= 2;
		}
	}
	int* s = new int[N];
	for (int i = 0; i < N; i++) {
		cin >> s[i];
	}

	descendOrder(N, s);

	vector<int> n;

	int c = 0;
	{
		int past = -1;
		for (int i = 0; i < N; i++) {
			if (s[i] != past) {
				past = s[i];
				n.push_back(1);
				c++;
			}
			else {
				n[c - 1]++;
			}
		}
	}

	if (n[0] != 1) { cout << "No" << endl; return 0; }
	int sum = 1;

	vector<int> a;
	for (int i = 0; i < c; i++) {
		if (i == 0) { a.push_back(1); }
		else {
			a.push_back(0);
		}
	}

	for (int k = 0; k < K; k++) {
		vector<int> p;
		for (int i = 0; i < c; i++) {
			p.push_back(a[i]);
		}
		int sum = 0;
		for (int i = 0; i < c; i++) {
			int _p = p[i];
			if (p[i] + sum >= n[i]) {
				sum -= (n[i] - p[i]);
				p[i] = n[i];
			}
			else {
				p[i] += sum;
				sum = 0;
			}
			sum += _p;
		}
		if (sum > 0) { cout << "No" << endl; return 0; }
		for (int i = 0; i < c; i++) {
			a[i] = p[i];
		}
	}

	for (int i = 0; i < c; i++) {
		if (a[i] != n[i]) {
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;

	return 0;
}


Measured memory_bytes: 5368
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>
#include <fstream>
#include <map>
#include <ctime>
using namespace std;

#define LL unsigned long long int
#define SZ 110
#define LCM30 2329089562800

int main()
{
    int k, x;

    cin >> k >> x;
    if(k*500>=x) cout << "Yes\n";
    else cout << "No\n";

    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n+1];
        int[] b = new int[n];
        for(int i = 0; i < n+1; i++){
            a[i] = sc.nextInt();
        }
        for(int i = 0; i < n; i++){
            b[i] = sc.nextInt();
        }
        long ans = 0;
        for(int i = 0; i < n; i++){
            if(a[i] <= b[i]){
                ans += a[i];
                b[i] -= a[i];
                a[i] = 0;
                ans += Math.min(a[i+1], b[i]);
                a[i+1] = Math.max(0,a[i+1]-b[i]);
            }else{
                ans += b[i];
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 67124
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <stdio.h>
#include <string.h>
using ll = long long;

//LLONG_MAX
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()

using namespace std;

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

	int ans = 0;
	REP(i, N) REP(j, N) REP(k, N) ans++;
	cout << ans << endl;
}



Measured memory_bytes: 256
# AOJ 0025 Hit and Blow
# Python3 2018.6.16 bal4u

while True:
	try:
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
	except: break
	
	hit = blow = 0
	for i in range(4):
		if a[i] == b[i]:
			hit += 1
			b[i] = -1
	for i in range(4):
		if b[i] >= 0:
			if b[i] in a: blow += 1
	print(hit, blow)



Measured memory_bytes: 5596
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef long double ld;
typedef vector<ll>VI;
typedef pair<ll,ll>P;
#define VV(T) vector<vector<T>>
#define sz(x) int(x.size())
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define ALL(a)  (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX6 1001001//6
#define MAX7 10010010//7
#define SENTINEL 2000000000//9
#define INF 1<<30
#define INFTY 1LL<<61
#define MAX_INT INT_MAX
#define Endl '\n'
#define CLR(mat) memset(mat, 0, sizeof(mat))
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}
template<class T> bool contain(const std::string& s, const T& v) {
   return s.find(v) != std::string::npos;
}
using Edge=pair<int,ll>;
using Graph=vector<vector<ll> >;//ll or Edge
const int MOD = 1000000007;
//const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
// vector型から重複を削除 list.erase(unique(ALL(list)),list.end());
// g++ -o a a.cpp -Wall -lm -std=c++17
//push_back -> emplace_back
int c[10][1005];
char S[11][1010];
int main(){
   int h,w,k;
   cin>>h>>w>>k;
   rep(i,h)rep(j,w)cin>>S[i][j];
   int res=INF;
   for(int bit=0;bit<(1<<(h-1));bit++){
      int g=0;
      VI id(h);
      rep(i,h){
         id[i]=g;
         if(bit>>i & 1)++g;
      }
      ++g;
      rep(i,g)rep(j,w)c[i][j]=0;
      rep(i,h)rep(j,w)c[id[i]][j]+=(S[i][j]-'0');
      int ans=g-1;
      VI now(g);
      auto add=[&](int j){
         rep(i,g)now[i]+=c[i][j];
         rep(i,g)if(now[i]>k)return false;
         return true;
      };
      rep(j,w){
         if(!add(j)){
            ans++;
            now=VI(g);
           if(!add(j)){
              ans=INF;
              break;
           }
         }
         }
         chmin(res,ans);
      }
      cout<<res<<endl;
      return 0;
   }


Measured memory_bytes: 3680
#include <iostream>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <unordered_map>
#include <random>
#include <queue>
#include <iomanip>

#define BIG 1000000007
#define LLMAX 9223372036854775807
#define LLMIN (-9223372036854775808)
#define long long long

using namespace std;

int main(){
    double w,h,x,y;
    cin >> w >> h >> x >> y;
    double w2,h2;
    double o = w * h / 2.0;
    w2 = w / 2;
    h2 = h / 2;
    if(x - w2 == 0 && y - h2 == 0){
        cout << o << ' ' << 1 << endl;
    }
    else{
        cout << o << ' ' << 0 << endl;
    }
}




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

namespace ABC054A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b;
            var word = Console.ReadLine().Split(' ');
            a = int.Parse(word[0]);
            b = int.Parse(word[1]);
            if (a == 1)
            {
                a = 14;
            }
            if (b == 1)
            {
                b = 14;
            }
            if (a > b)
                Console.WriteLine("Alice");
            else if (b > a)
                Console.WriteLine("Bob");
            else
                Console.WriteLine("Draw");
            Console.ReadKey();
           
               
        }
    }
}


Measured memory_bytes: 11092
import numpy as np
# from collections import defaultdict

N = int(input())
A = list(map(int, input().split()))
A = np.array(A)
A = np.cumsum(A)
A = list(A)
# dic = defaultdict(int)
# for i in A:
    # dic[i] += 1

dic = dict()
for i in A:
    if i in dic:
        dic[i] += 1
    else:
        dic[i] = 1

ans = 0
for i in dic:
    ans += dic[i] * (dic[i] - 1)
ans //= 2

if 0 in dic:
    ans += dic[0]

print (ans)

Measured memory_bytes: 41964
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
#define lli long long int
#define fop(i,m,n) for (int i=(m);i<(n);i++)
#define FOP(i,m,n) for (int i=(m)-1;i>=(n);--i)
#define test(x) cout << #x << ' ' << x << endl;
#define print(a) {\
    for (auto i : a) cout << i << ' ';\
    cout << '\n';\
}
#define eb emplace_back
#define pb push_back
#define mp make_pair 
#define mt make_tuple
#define pii pair<int,int> 
#define pll pair<lli,lli>
#define tiii tuple<int,int,int>
#define all(a) a.begin(), a.end()
#define X first
#define Y second
#define oset tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update>
auto SEED = chrono::steady_clock::now().time_since_epoch().count();
mt19937 rng(SEED);
const int mod = 998244353, x = 864197532, N = 100000;

int main () {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m, u, v;
	cin >> n >> m;
	vector <int> h(n);
	vector <bool> is(n, true);
	fop (i,0,n) cin >> h[i];
	fop (i,0,m) {
		cin >> u >> v;
		u--; v--;
		if (h[u] <= h[v]) is[u] = false;
		if (h[v] <= h[u]) is[v] = false;
	}
	cout << accumulate(all(is), 0) << endl;
}

Measured memory_bytes: 3752
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <algorithm>
#include <set>
#include <string>
#include <queue>
#include <utility>

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

using namespace std;

int main(){
    string S;
    string T;
    cin >> S >> T;
    vector<char> sT(26, 0);
    vector<char> tS(26, 0);
    string ans = "Yes";
    rep(i, S.size()){
        int index1 = S[i] - 'a';
        int index2 = T[i] - 'a';
        if(sT[index1] == 0){
            sT[index1] = T[i];
        }
        if(tS[index2] == 0){
            tS[index2] = S[i];
        }
        if(sT[index1] != T[i] || tS[index2] != S[i]){
            // not 全射 || not 単射.
            ans = "No";
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 776
N=int(input())
A=list(map(int,input().strip().split()))

l=[0 for n in range(N)]

for e in A:
    l[e-1]+=1

count=0
for n in range(N):
    if l[n]>=2:
        count+=l[n]*(l[n]-1)//2
            
for n in range(N):
    print(count-l[A[n]-1]+1)

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

int main()
{
	int A, B, C, D;
	cin >> A >> B >> C >> D;

	int X = A >= C ? A : C;
	int Y = B >= D ? D : B;

	if (Y - X > 0)
	{
		cout << Y - X << endl;
	}
	else
	{
		cout << 0 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <utility>
using namespace std;
int main(){
	long N;
	cin >> N;
	vector<long> A(N), B(N);
	for(int i=0;i<N;i++){
		cin >> A[i] >> B[i];
	}
	vector<pair<long, long>> C;
	for(int i=0;i<N;i++){
		pair<long, long> tmp;
		tmp.first = B[i];
		tmp.second = i;
		C.push_back(tmp);
	}
	sort(C.begin(), C.end());
	long sum = 0;
	bool check = true;
	for(int i=0;i<N;i++){
		sum += A[C[i].second];
		if(sum > B[C[i].second]) check = false;
	}
	if(check) cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

using namespace std;
const int MOD = 1000000007,MAX = 510000;
long int pow107 = (int)pow(10, 9) + 7,llimit = LONG_MAX,fac[MAX], finv[MAX], inv[MAX];
int ilimit = INT_MAX;

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

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

bool comp(pair<int, int> a, pair<int, int> b){
    if(a.first != b.first) return a.first > b.first;
    else return a.second < b.second;
}

long int jou(long int x, long int y){
    long int f = 1;
    for(int i = 0; i < y; ++i){
        f = f * x % pow107;
    }
    return f;
}

bool pn(long int x){
    if(x != 2 && x % 2 == 0)
        return false;
    for(int i = 3; i < x; ++i){
        if(x != i && x % i == 0)
            return false;
    }
    return true;
}

long int factorial(long int n){
    long int f = 1;
    for(long int i = 1; i <= n; ++i){
        f = f * i % pow107;
    }
    return f;
}

long int Func2(long int n,long int m){
    long int s2 = 1,
        r = 1;
    for(long int i = 1; i <= m; ++i){
        s2 = (s2*(n - (i - 1))/i) % (pow107);
    }
    return s2;
}

bool secsort(pair<int, int> a, pair<int, int> b){
    if(a.second == b.second)return a.first > b.first;
    else return a.second > b.second;
}

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

long int LCM(long int a,long int b){
    return a/GCD(a,b)*b;
}

//long intの最大llimit
//intの最大ilimit
//10^9+7    pow107
//素数pn
//n乗jou
//階乗factorial
//コンビネーションFunc2
//コンビネーションCOMinit(),COM(n,m)

int main(){
    string s;
    cin >> s;
    bool f[26];
    for(int i = 0; i < 26; ++i){
        f[i] = true;
    }
    for(int i = 0; i < s.size(); ++i){
        f[s[i] - 'a'] = false;
    }
    for(int i = 0; i < 26; ++i){
        if(f[i]){
            cout << char('a' + i) << endl;
            return 0;
        }
    }

    cout << "None" << endl;
    

}

Measured memory_bytes: 512
#include <iostream>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<stdio.h>
#include<string>

using namespace std;

int main() {
	int N;
	int a[110];
	cin >> N;
	for (int i = 0; i < N; ++i)cin >> a[i];

	int Alice = 0;
	int Bob = 0;
	sort(a, a + N, greater<int>());
	for (int i = 0; i < N; ++i) {
		
		if (i % 2 == 0) {
			Alice += a[i];
		}
		else {
			Bob += a[i];
		}
	}

cout << Alice-Bob << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define endl "\n"
#define fo for(int i=0;i<n;i++)
#define clear cin.clear();cin.ignore(numeric_limits<streamsize>::max(), '\n');
#define loopSolve int t; cin>>t; while(t--){solve();}
//INT_MAX         2,147,483,647                       <10^10
//U_INT_MAX       4,294,967,295                       <10^10
//LONG_LONG_MAX   9,223,372,036,854,775,807           <10^18
//U_LONG_LONG_MAX 18,446,744,073,709,551,615          <10^18
/*ll power(int a, int b){
    return (ll)(pow(a,b)+0.5);
}*/

int getBits(ll num){
	return (int)log2(num) + 1;
}

vector<int> gV(int n){
    vector<int> v;
    int input;
    fo { cin>>input; v.pb(input); }
    return v;
}

int* gA(int n){
    int* arr = new int[n];
    fo cin>>arr[i];
    return arr;
}

bool possible(int ans,vector<int> &a,int k){
    for(auto log: a){
        if(log%ans==0)
            k-=(log/ans-1);
        else
            k-=log/ans;
    }
    return k>=0;
}

void solve(){
    int n,k,mx=INT_MIN;
    cin>>n>>k;
    vector<int> a(n);
    fo{
        cin>>a[i];
        mx=max(mx,a[i]);
    }
    int min=1;                      //max denotes that value which is definitely the answer. min denotes that value which is trying to approach that answer
    while(min!=mx){
        int mid=(min+mx)/2;         //Let's see if this answer works
        if(possible(mid,a,k))
            mx=mid;
        else
            min=mid+1;
    }

    cout<<min<<endl;

}


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

    solve();
    //loopSolve;

	return 0;
}


Measured memory_bytes: 3992
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
using Pair = System.Tuple<int, int>;
using Edge = System.Tuple<int, int, long>;
//using Debug;
//using static System.Globalization.CultureInfo;

class Program
{
    static void Main(string[] args)
    {
        var k = ReadLine();
        var d = Input.num;
        var dp = new long[k.Length+1, d, 2];
        dp[0, 0, 0] = 1;
        for (var i = 1; i <= k.Length; i++)
            for (var w = 0; w < d; w++)
                for (var j = 0; j < 2; j++)
                {
                    var val = k[i - 1] - '0';
                    for (var h = 0; h < 10; h++)
                        if (h < val)
                            dp[i, (w + h) % d, 1] = (dp[i, (w + h) % d, 1] + dp[i - 1, w, j]) % Input.MOD;
                        else if (h == val) dp[i, (w + h) % d, j] = (dp[i, (w + h) % d, j] + dp[i - 1, w, j]) % Input.MOD;
                        else if (j == 1) dp[i, (h + w) % d, j] = (dp[i, (w + h) % d, j] + dp[i - 1, w, j]) % Input.MOD;
                }
        WriteLine((dp[k.Length, 0, 0] + dp[k.Length, 0, 1]+Input.MOD-1) % Input.MOD);
    }
}

public class Input
{
    public static string read => ReadLine();
    public  static int[] ar => Array.ConvertAll(read.Split(' '), int.Parse);
    public  static int num => ToInt32(read);
    public static long[] arL => Array.ConvertAll(read.Split(' '), long.Parse);
    public  static long numL => ToInt64(read);
    public static char[][] gred(int h) 
        => Enumerable.Repeat(0, h).Select(v => read.ToCharArray()).ToArray();
    public static int[][] twodim(int num)
        => Enumerable.Repeat(0, num).Select(v => ar).ToArray();
    public static long[][] twodimL(int num)
        => Enumerable.Repeat(0, num).Select(v => arL).ToArray();
    public const long Inf = (long)1e18;
    public const double eps = 1e-6;
    public  const string Alfa = "abcdefghijklmnopqrstuvwxyz";
    public  const int MOD = 1000000007;
}


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

int main() {
    int n;
    cin >> n;
    vector<int> b(n - 1);
    int x = 0;

    for (int i = 0; i < n - 1; i++) {
        cin >> b.at(i);
    }
    x = b.at(0) + b.at(n - 2);

    for (int j = 1; j < n - 1; j++) {
        x += min(b.at(j - 1), b.at(j));
    }
    cout << x << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        long p[] = new long[a];
        long q[] = new long[b];
        long r[] = new long[c];

        for(int i=0;i<a;i++)p[i]=sc.nextLong();
        for(int i=0;i<b;i++)q[i]=sc.nextLong();
        for(int i=0;i<c;i++)r[i]=sc.nextLong();

        Arrays.sort(p);
        Arrays.sort(q);
        Arrays.sort(r);

        long red[] = new long [x+1];
        long green[] = new long[y+1];
        red[x]=Long.MAX_VALUE;
        green[y]=Long.MAX_VALUE;

        for(int i=0;i<x;i++){
            red[i]=p[a-i-1];
        }
        for(int i=0;i<y;i++){
            green[i]=q[b-i-1];
        }

        Arrays.sort(red);
        Arrays.sort(green);

        int redP = 0;
        int greenP = 0;

        for(int i=c-1;i>=0;i--){
            //System.out.println("r:"+r[i]+" red:"+red[redP]+" grn:"+green[greenP]);

            if(r[i]<=red[redP]&&r[i]<=green[greenP])break;

            if(r[i]>red[redP]&&r[i]>green[greenP]){
                if(red[redP]<=green[greenP]){
                    red[redP]=r[i];
                    redP++;
                }else{
                    green[greenP]=r[i];
                    greenP++;
                }
            }else if(r[i]>red[redP]){
                red[redP]=r[i];
                redP++;
            }else if(r[i]>green[greenP]){
                green[greenP]=r[i];
                greenP++;
            }
            
        }

        long ans = 0;

        for(int i=0;i<x;i++)ans+=red[i];
        for(int i=0;i<y;i++)ans+=green[i];


        System.out.println(ans);

    }

}


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

void sort(int *a, int n)
{
    int i, j;
    int temp;

    for(i=0;i<n;i++){
        for(j=i;j<n;j++){
            if(a[j] < a[i]){
                temp = a[i];
                a[i] = a[j];
                a[j] = temp;
            }
        }
    }
}

int main()
{
    int n;
    int v[50];

    int i;
    int min, next;

    float ans;

    min = 10000;

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

    sort(v, n);

    ans = v[0];
    for(i=1;i<n;i++){
        ans = (ans + v[i]) / 2;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
from collections import deque

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N, D, A = map(int, input().split())
    monster = {}
    X = []
    for _ in range(N):
        x, h = map(int, input().split())
        monster[x] = h
        X.append(x)

    X.sort()

    # x, damage
    q = deque([])

    acc_damage = 0

    ans = 0
    for i in range(N):
        x = X[i]
        h = monster[x]

        while q and q[0][0] < x:
            p, damage = q.popleft()
            acc_damage -= damage

        if h - acc_damage <= 0:
            continue

        cnt = (h - acc_damage + A - 1) // A
        ans += cnt
        acc_damage += cnt * A

        q.append((x + 2 * D, cnt * A))

    print(ans)


if __name__ == "__main__":
    main()


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

double su(double s,double n,vector<double> arr)
{
    double r=0;
    rep2(i,s,n)
    {
      r+=arr[i];
    }
    return r;
}
double ki(double n)
{
    double t=0;
    rep2(j,1,n+1)t+=j;
    return t/n;
}

int main()
{
    double n,k;
    cin >> n >> k;
    vector<double> arr(n);
    rep(i,n){
    cin >> arr[i];
      arr[i]=ki(arr[i]);
    }
  
  double t=su(0,k,arr);
  double m=t;
  double b=t;
    rep2(i,1,n-k+1){
        t=b-arr[i-1]+arr[i+k-1];
        if(m < t){
            m=t;
        }
      b=t;
    }

    printf("%.12lf\n",m);
}



Measured memory_bytes: 3328
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <utility>
#include <ctime>
#include <map>
#include <set>
#include <unordered_set>

using namespace std;

#define endl "\n"
#define X first
#define Y second
#define Z third
#define mp make_pair
#define mt make_triple

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

const ld PI = 3.141592653589793;
const ld E = 2.71828182845904523;
const ll LLINF = 4000000009000000099;
const ll INF = 1009000099;
const ll MOD7 = 1000000007;
const ll MOD9 = 1000000009;

template<class A, class B, class C> struct triple { A first; B second; C third; triple(A, B, C); triple(); };
template<class A, class B, class C> triple<A, B, C>::triple(A a, B b, C c) { first = a; second = b; third = c; }
template<class A, class B, class C> triple<A, B, C>::triple() { }
template<class A, class B, class C> triple<A, B, C> make_triple(A a, B b, C c) { triple<A, B, C> t(a, b, c); return t; }
template<class A, class B, class C> bool operator<(triple<A, B, C> a, triple<A, B, C> b) { if (a.first != b.first) return a.first < b.first; if (a.second != b.second) return a.second < b.second; if (a.third != b.third) return a.third < b.third; }
template<class T> T inline sqr(T a) { return a * a; }

ll bpow(ll a, ll d, ll mod) { if (d == 0) return 1; ll t = bpow(a, d / 2, mod); t = (t * t) % mod; if (d & 1) t = (t * a) % mod; return t; }
ll bpow(ll a, ll d) { if (d == 0) return 1; ll t = bpow(a, d / 2); t = (t * t); if (d & 1) t = (t * a); return t; }
ll gcd(ll a, ll b) { while (a && b) if (a > b) a %= b; else b %= a; return a + b; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll C(ll n, ll k) { ll res = 1; for (int i = 1; i <= k; ++i) res = res * (n - k + i) / i; return res; }
ll C(ll n, ll k, ll mod) { ll u = 1, d = 1; for (int i = 2; i <= n; ++i) u = (u * i) % mod; int x = max(k, n - k), z = min(k, n - k); for (int i = 2; i <= x; ++i) { d = (d * i) % mod; if (i <= z) d = (d * i) % mod; } d = bpow(d, mod - 2, mod); ll res = (u * d) % mod; return res; }

vector<int> p;

int get(int v) 
{
	return (p[v] == v ? v : p[v] = get(p[v]));
}

void unit(int u, int v)
{
	int gu = get(u), gv = get(v);
	if (gu != gv)
	{
		if (rand() % 2)
			p[gu] = gv;
		else
			p[gv] = gu;
	}
}

void solve()
{
	int n, m; cin >> n >> m;
	vector<int> v(n);
	for (int i = 0; i < n; ++i)
		cin >> v[i];
	p.resize(n);
	for (int i = 0; i < n; ++i)
		p[i] = i;

	for (int i = 0; i < m; ++i)
	{
		int x, y;
		cin >> x >> y;
		x--;
		y--;
		unit(x, y);
	}

	int cnt = 0;
	for (int i = 0; i < n; ++i)
		cnt += get(i) == get(v[i] - 1);
	cout << cnt;
}


int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
#ifdef _DEBUG
	freopen("in.txt", "r", stdin);
#else
#endif
	solve();
	return 0;
}

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

int main() {
    long long a, b, n;
    cin >> a >> b >> n;
    long long ans = -1;
    if(n < b - 1) {
        ans = a*n/b;
    } else {
        ans = a*(b-1)/b;
    }
    cout << ans << endl;
}


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

int a[200], n, s;

int main() {
  cin >> n;
  for (int i = 0; i < 2*n; i++) cin >> a[i];
  sort(a,a+2*n);
  for (int i = 0; i < 2*n; i += 2) s += a[i];
  cout << s;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <complex>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,C,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;


int main() {
    cin>>N;
    mat f(N,vec(10));
    rep(i,N) rep(j,10) cin>>f[i][j];
    mat p(N,vec(11));
    rep(i,N) rep(j,11) cin>>p[i][j];
    ll ans = -(1e+10);
    reps(i,1,(1LL << 10)){
        ll temp = 0;
        rep(j,N){
            ll same = 0;
            rep(k,10) same += ((i>>k)&1) && (f[j][k]);
            temp += p[j][same];
        }
        ans = max(ans, temp);
    }
    cout<<ans<<endl;
}

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

using namespace std;

string s;
char buf[100002];
char star;
char en;
deque<char> d;
bool no(){
	if (d.size() == 0&&star==en){
		return true;
	}
	if (d.size() == 0){
		return false;
	}
	if (star == d[0] || en == d.back()){
		return true;
	}
	return false;
}
int main(){
	scanf("%s", buf);
	s = buf;
	char f[] = { s[0], s[1] };
	bool ok = false;
	for (int i = 0; i < s.size(); i++){
		if (s[i] == f[i % 2]){

		}
		else{
			ok = true;
			break;
		}
	}
	
	if (ok){
		int len = s.size();
		len -= 2;
		if (s.back() == s[0])len--;
		if (len % 2 == 0){
			puts("Second");
		}
		else{
			puts("First");
		}
		return 0;
	}
	puts("Second");
	return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
typedef long long LL;
 
char b[10];
int a[10];
string str;
bool dfs(int x,int deep)
{
	int sum;
	if(deep==4)
	{
		if(x==7)
			return true;
		else
			return false;
	}
	for(int i=1;i<=2;i++)
	{
		if(i==1)
		{
			sum=x+a[deep+1];
			if(dfs(sum,deep+1))
			{
				b[deep]='+';
				return true;
			}
		}
		else
		{
			sum=x-a[deep+1];	
			if(dfs(sum,deep+1))
			{
				b[deep]='-';
				return true;
			}
		}	
	}
	return false;
}
int main()
{
	int i;
	cin>>str;
	for(i=0;i<4;i++)
	{
		a[i+1]=str[i]-'0';
	}
	dfs(a[1],1);
	cout<<a[1]<<b[1]<<a[2]<<b[2]<<a[3]<<b[3]<<a[4]<<"=7"<<endl;
}

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

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

ll LCM(ll a,ll b){
    return (a*b/GCD(a,b));
}

int main(){
    ll A,B;
    cin>>A>>B;
    cout<<LCM(A,B);
}

Measured memory_bytes: 3672
#include <iostream>
#define llint long long
 
using namespace std;
 
llint n, W;
llint w[105], v[105];
llint dp[105][100005];
 
int main(void)
{
	cin >> n >> W;
	for(int i = 1; i <= n; i++) cin >> w[i] >> v[i];
	
	for(int i = 0; i <= n; i++){
		for(int j = 0; j <= W; j++){
			dp[i][j] = -1e18;
		}
	}
	dp[0][0] = 0;
	
	for(int i = 0; i < n; i++){
		for(int j = 0; j <= W; j++){
			dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
			if(j+w[i+1] <= W) dp[i+1][j+w[i+1]] = max(dp[i+1][j+w[i+1]], dp[i][j] + v[i+1]);
		}
	}
	llint ans = 0;
	for(int i = 0; i <= W; i++) ans = max(ans, dp[n][i]);
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 80128