akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
int gcd(int x,int y){
    if(y == 0)return x;
    return gcd(y,x%y);
}
signed main(){
    int a,b,c,d;cin >> a >> b >> c >> d;
    auto f = [&](int x){
        int tmp = x/c + x/d - x/(c*d/gcd(c,d));
        return x - tmp;
    };
    cout << f(b) - f(a-1) << endl;
    return 0;
}

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

int main() {
  	int N,M=0;
  	cin >> N >> M;
  
	vector<int> vec(N);
	for (int i = 0; i < N; i++) {
  		cin >> vec.at(i);
	}
  	int sum = accumulate(vec.begin(), vec.end(), 0);
  	sort(vec.begin(),vec.end(),greater<int>());
  	if (vec.at(M-1)*4*M < sum)
      cout << "No";
    else
      cout << "Yes";
}


Measured memory_bytes: 256
#include <iostream>
 
using namespace std;
 
const int MAXN = 3010;
int N;
int score[MAXN];

int64_t dp[MAXN][MAXN][2];
bool isCalc[MAXN][MAXN][2];

int64_t solve(int leftPointer, int righPointer, int turn) {
    if (leftPointer > righPointer) return 0;

    int64_t ans = dp[leftPointer][righPointer][turn];
    bool isCalculated = isCalc[leftPointer][righPointer][turn];

    if (isCalculated) return ans;
    if (turn == 0) {
        if (leftPointer == righPointer) {
            ans = (-score[leftPointer] + solve(leftPointer + 1, righPointer, 1));
        } else {
            int64_t pickLeft = -score[leftPointer] + solve(leftPointer + 1, righPointer, 1);
            int64_t pickRight = -score[righPointer] + solve(leftPointer, righPointer - 1, 1);
            ans = min(pickLeft, pickRight);
        }
    } else {
        if ( leftPointer == righPointer ){
            ans = score[leftPointer] + solve(leftPointer + 1, righPointer, 0);
        } else {
            int64_t pickLeft = score[leftPointer] + solve(leftPointer + 1, righPointer, 0);
            int64_t pickRight = score[righPointer] + solve(leftPointer, righPointer - 1, 0);
            ans = max(pickLeft, pickRight);
        }
    }
    dp[leftPointer][righPointer][turn] = ans;
    isCalc[leftPointer][righPointer][turn] = true;

    return ans;
}

int main(){
    
 
    cin >> N;
    for (int i = 1; i <= N; i++) cin >> score[i];

    cout << solve(1, N, 1);

    return 0;
}

Measured memory_bytes: 158336
if __name__ == '__main__':
    from sys import stdin
    input = stdin.readline

    N = 100
    p = [0]*(N+1)
    m = [[0]*(N+1) for _ in range(N+1)]

    n = int(input())
    for i in range(n):
        p[i], p[i+1] = map(int, input().split())

    for l in range(2, n+1):
        for i in range(1, n-l+2):
            j = i + l - 1
            m[i][j] = 2**21 # 十分大きい数
            for k in range(i, j):
                m[i][j] = min(m[i][j], m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j])

    print(m[1][n])



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

typedef long long ll;
#define rep(i,x) for(int i=0;i<x;i++)
#define put(ans)    cout << ans << endl;

int main(){
    ll n;  cin >> n;
    ll L[87];

    rep(i,87){
        if(i==0)    L[i] = 2;
        else if(i==1)    L[i] = 1;
        else    L[i] = L[i-1]+L[i-2];
    }

    cout << L[n] << endl;

    return 0;
}

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

#define rep(i, n) for (ll i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const ll INF = 1e18;

ll dx[] = {1, 0};
ll dy[] = {0, 1};

int main() {
  ll h, w;
  cin >> h >> w;
  string s[h];
  ll ans[h][w] = {};
  rep(i, h) rep(j, w) ans[i][j] = INF;
  rep(i, h) cin >> s[i];
  ans[0][0] = 0 + (s[0][0] == '#' ? 1 : 0);

  rep(i, h) rep(j, w) rep(k, 2) {
    ll ny = i + dy[k];
    ll nx = j + dx[k];
    if (nx < w && ny < h)
      ans[ny][nx] =
          min(ans[i][j] + (s[ny][nx] == '#' && s[i][j] == '.' ? 1 : 0),
              ans[ny][nx]);
  }

  // rep(i, h) {
  //   rep(j, w) { cout << ans[i][j] << " "; }
  //   cout << endl;
  // }

  cout << ans[h - 1][w - 1] << endl;
  return 0;
}


Measured memory_bytes: 384
from collections import deque

que = deque([])
n = int(input())
for i in range(0, 	n):
	a = input()
	if a == 'deleteFirst':
		que.popleft()
#		print(a)
#		print(que)
	elif a == 'deleteLast':
		que.pop()
#		print(a)
#		print(que)
	else:
		a, b = a.split()
		b = int(b)
		if a == 'insert':
			que.appendleft(b)
#			print('{0} {1}'.format(a,b))
#			print(que)
		elif a == 'delete':
			if que.count(b) != 0:
				que.remove(b)
#			print('{0} {1}'.format(a, b))

print(*que)

#while not len(que) == 0:
#	if len(que) == 1:
#		print(que.pop())
#	else:
#		print(que.pop(), end=' ')



Measured memory_bytes: 46056
const lines = [];
const reader = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout,
});
reader.on("line", function (line) {
  lines.push(line);
});

reader.on("close", function () {
  const input = (lines[0] as string).split(" ");
  const num = Number(input[0]);
  const sum = Number(input[1]);

  const res = matchPatterns(num, sum);

  console.log(res[2], res[1], res[0]);
});

function matchPatterns(num: number, sum: number): number[] {
  for (let i = 0; i <= num; i++) {
    for (let j = 0; j <= num; j++) {
      const k = num - i - j;
      if (k >= 0 && i + j + k === num) {
        const tmp = 1000 * i + 5000 * j + 10000 * k;
        if (tmp === sum) {
          return [i, j, k];
        }
      }
    }
  }
  return [-1, -1, -1];
}


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

#define MOD 1000000007

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

	int s, w;
	cin >> s >> w;
	if (w >= s)
		cout << "unsafe";
	else
		cout << "safe";
}


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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

// n回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii;  // 2次元配列
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> PII;

template<typename T>
using vec = vector<T>;
template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

const ld Pi = std::acos(-1.0L);
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    // cout << fixed << setprecision(15);

    int n,m,x; cin >> n >> m >> x;
    vi a(m); rep(i,m) cin >> a[i];
    
    int cnt1 = 0;
    int cnt2 = 0;
    for(auto i : a) {
        if(x<i && i<n) cnt1++;
    }
    for(auto i : a) {
        if(0 < i && i < x) cnt2++;
    }
    cout <<  min(cnt2,cnt1) << '\n';
}

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

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

    vector<int> a(3);
    rep(i, 3){
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    rep(i, 2){
        cout << a[i] << " ";
    }
    cout << a[2] << endl;
    

    return 0;
}


Measured memory_bytes: 3132
#include <iostream>
#include <vector>
#include <string>
#include <bits/stdc++.h>
#include <queue>
using namespace std;
using ll = long long ;

int count_digits(ll n){
   
   int digits = 0 ;

   while (n>0)
   {
       n /= 10 ;
       digits++ ;
   }
 return digits ;
}



int main(void)
{

 ll N ;
 cin >> N ;
  
 int ans = count_digits(N) ;

 for(ll i=1LL;i*i<=N;i++){
     if(N%i!=0)continue ;
     ll B = N/i ; 
     int cur = max(count_digits(i),count_digits(B)) ;
     if(ans>cur){ans = cur ;}
 }

    cout << ans << endl ;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <limits>
#include <sstream>
#include <fstream>

typedef long long int64;

int main(void) {
  int n, k;
  std::cin >> n >> k;
  int dnm = 1;
  int keta = 1;
  while (true) {
    if (n / dnm == 0) {
      std::cout << keta - 1 << std::endl;
      break;
    }
    dnm *= k;
    keta++;
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<numeric>

using namespace std;

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

template<typename A, typename B> bool chmin(A &a, const B &b){ return b < a && (a = b, true); }
template<typename A, typename B> bool chmax(A &a, const B &b){ return a < b && (a = b, true); }

int main() {
  double n,m,sum = 0;
  cin >> n;
  vector<double> a(n);
  for (int i = 0; i < n; i++){
    cin >> a[i];
    sum += 1 / a[i];
  }
  sum = 1 / sum;
  cout << sum << '\n';
  return 0;
}

Measured memory_bytes: 3796
#include <iostream>
#include <vector>
#include <cmath>

int main(){
  int n;
  int check, cnt;
  bool hoge;
  std::vector<int> x(100), y(100), h(100);
  std::cin >> n;
  for(int i = 0; i < n; i++){
    std::cin >> x[i] >> y[i] >> h[i];
    if(h[i] != 0){
      check = i;
      cnt++;
    }
  }

  if(cnt == 1){
    std::cout << x[check] << " " << y[check] << " " << h[check] << std::endl;
  }
  else{
    for(int centre_x = 0; centre_x <= 100; centre_x++){
      for(int centre_y = 0; centre_y <= 100; centre_y++){
        hoge = true;
        for(int i = 0; i < n; i++){
          if(h[i] != 0 && h[i] - h[check] != abs(x[check] - centre_x) - abs(x[i] - centre_x) + abs(y[check] - centre_y) - abs(y[i] - centre_y)) hoge = false;
        }
        if(hoge == true){
          std::cout << centre_x << " " << centre_y << " " << h[check] + abs(x[check] - centre_x) + abs(y[check] - centre_y) << std::endl;
          break;
        }
      }
      if(hoge == true) break;
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using VVV = vector<VV>;
using VVVll = vector<VVll>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
#define rep2(i, m, n) for (int i = (m); i < (n); ++i)
#define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) (a).begin(), (a).end()
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline int sz(T &x) { return x.size(); }
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int fLog2(const int x) { assert(x > 0); return 31-__builtin_clz(x); } // floor(log2(x))
inline int fLog2(const ll x) { assert(x > 0); return 63-__builtin_clzll(x); }
inline int cLog2(const int x) { assert(x > 0); return (x == 1) ? 0 : 32-__builtin_clz(x-1); } // ceil(log2(x))
inline int cLog2(const ll x) { assert(x > 0); return (x == 1) ? 0 : 64-__builtin_clzll(x-1); }
inline int popcount(const int x) { return __builtin_popcount(x); }
inline int popcount(const ll x) { return __builtin_popcountll(x); }
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const ld PI    = acos(-1.0);
// const int MOD  = int(1e9)+7;
// const int MOD  = 998244353;


int main() {
  ll n; cin >> n;
  V a(n), b(n);
  cin >> a >> b;

  priority_queue<P> pq;
  rep(i, n) if (a[i] < b[i]) pq.emplace(b[i], i);
  ll ans = 0;

  while (!pq.empty()) {
    auto [y, j] = pq.top(); pq.pop();
    int i = (j - 1 + n) % n;
    int k = (j + 1) % n;
    int &x = b[i];
    int &z = b[k];

    int m = (y-x+z)/(x+z) + 1;
    chmin(m, (y-a[j])/(x+z));

    if (m <= 0) {
      cout << -1 << '\n';
      return 0;
    }

    ans += m;
    b[j] -= (x+z)*m;
    if (a[j] < b[j]) pq.emplace(b[j], j);
  }

  bool ok = true;
  rep(i, n) if (a[i] != b[i]) ok = false;
  cout << (ok ? ans : -1) << '\n';
  return 0;
}


Measured memory_bytes: 6832
#include<iostream>
#include<cstdio>
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
const int N=24,S=1200120;
int n,K,L,ans,f[N][S],g[N][S];
char s[S];
int main(){
	scanf("%d%d",&n,&K);
	FOR(i,0,n){
		scanf("%s",s);
		FOR(j,0,(1<<i)-1) f[i][j]=s[j]=='1'; 
	}
	FOR(i,1,n)FOR(j,0,(1<<i)-1){
		int t=j>>i-1&1,r=i-1;
		for(;r && (j>>r-1&1)==t;r--);g[i][j]=r;
	}
	FOR(i,0,n){
		FOR(j,1,n-i)FOR(k,0,(1<<i+j)-1){
			f[i][k>>j]+=f[i+j][k];
			int t=g[j][k&(1<<j)-1];
			if(t) f[i+t][(k>>j<<t)|(k&(1<<t)-1)]+=f[i+j][k];
		}
		ROF(j,(1<<i)-1,0)if(f[i][j]>=K) L=i,ans=j;
	}
	for(L--;~L;L--) cout<<(ans>>L&1);cout<<"\n";
}/*
5 100
0
01
1011
11010111
0001110111011110
01100100100011110101111111011010
*/

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

int main() {
  string AC="CODEFESTIVAL2016";
  string s;
  
  int result=0;
  
  cin>>s;
  
  for(int i=0;i<s.size();i++){
    if(s.at(i)!=AC.at(i))result++;
  }
  cout<<result<<endl;
  
}


Measured memory_bytes: 256
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n=int(input())
h=list(map(int,input().split()))

ans=0
while sum(h)>0:
    flag=0
    for i in range(n):
        if flag==0:
            if h[i]>0:
                h[i]-=1
                flag=1
                ans+=1
            else:
                continue
        else:
            if h[i]>0:
                h[i]-=1
            else:
                flag=0
    # print(h)
print(ans)

Measured memory_bytes: 74488
#include <iostream>
#include <string>

using namespace std;

void solve()
{
	string str;
	cin >> str;
	int n = str.size();
	for(int i = n - 1; i >= 0; --i)
	{
		cout << str[i];
	}
	cout << endl;
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int func(int n) {
	if (n & 1) {
		return 3 * n + 1;
	}
	return n / 2;
}

int main() {
	int s;

	cin >> s;

	vector<bool> used(1000001, false);

	int count = 1;
	int prev = s;

	while(true) {
		used[prev] = true; 

		//cout << "prev: " << prev << endl;
		
		count++;
		int next = func(prev);

		if (used[next]) {
			break;
		}
		prev = next;
		
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 384
//  SMOKE SHISHA PLAY FIFA  // 
#include<bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef long double ld;

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pll pair<ll,ll>
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define mod 1000000007
#define lp(start,end) for(ll i=start;i<=end;i++) 
#define deb1(a) cout<<#a<<" = "<<(a)<<endl;
#define deb2(a,b) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;
#define deb3(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;


ll modu(ll a, ll b)
{
	ll ans =1;
	while(b>0)
	{
		if(b&1)
		ans = (ans*a)%mod;
		b/=2;
		a = (a*a)%mod;
	}
	return ans;
}

int main()
{
	fastio
	ll n;
	cin >> n;
	set<ll>s;
	vector<ll>v;
	for(ll i=1;i<=n;i++)
	{
		ll temp;
		cin >> temp;
		//if(s.find(temp)==s.end())
		//{
			v.pb(temp);
	//	}
	//	s.insert(temp);

	}
	ll ans=0;
	for(ll i=0;i<v.size();i++)
	{
		for(ll j=i+1;j<v.size();j++)
		{
			for(ll k=j+1;k<v.size();k++)
			{
				ll x = v[i];
				ll y= v[j];
				ll z= v[k];
				if(z!=y && x!=y && x!=z)
				{
					if((x+y > z) && (y+z > x) && (x+z >y)){
					//	deb3(i,j,k);
						ans++;
					}
				}
			}
		}
	}
	cout << ans << endl;
	return 0;	
}


Measured memory_bytes: 3656
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
#include <string>
#include <bitset>
#include <queue>
#include <tuple>
#include <cmath>
#include <map>
#include <cstring>

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

using namespace std;

using ll = long long;
using ull = unsigned long long;

using Pint = pair<int, int>;
using Pll  = pair<ll, ll>;
using Pull = pair<ull, ull>;

#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple

#define F first
#define S second

#define rep( i, n ) for ( int i = 0; i < (int)( n ); ++i )
#define reps( i, n ) for ( int i = 1; i <= (int)( n ); ++i )
#define rrep( i, n ) for ( int i = (int)( ( n ) - 1 ); i >= 0; --i )
#define rreps( i, n ) for ( int i = (int)( ( n ) ); i > 0; --i )
#define arep( i, v ) for ( auto &&i : ( v ) )

template<typename T> T gcd( const T a, const T b ) { return ( b ? gcd( b, a % b ) : a ); }

#define ALL( c ) ( c ).begin(), ( c ).end()
#define RALL( c ) ( c ).rbegin(), ( c ).rend()
#define UNIQUE( c ) ( c ).erase( unique( ( c ).begin(), ( c ).end() ), ( c ).end() )

constexpr ll MOD = 1000000007LL;

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev

template<typename T = ll> class UnionFind {
public:
	UnionFind( T n ) { rep( i, n ) { par.resize( n ); siz.resize( n ); par[i] = i; siz[i] = 1; } }
	T find( T x ) { if ( x == par[x] ) return ( x ); else return( par[x] = find( par[x] ) ); }
	void unite( T x, T y ) { T xx = find( x ); T yy = find( y ); if ( xx == yy ) return;
		if ( siz[xx] <= siz[yy] ) swap( xx, yy ); par[yy] = xx; siz[xx] += siz[yy]; }
private:
	vector<T> par, siz;
};

template<typename T = ll> T power( T a, T b, T m = MOD ) {
	T res = 1;
	while ( b > 0 ) { if ( b & 1 ) res = res * a % m;
		a = a * a % m; b >>= 1; }
	return ( res );
}

/*
constexpr ll MAX = 500010;
ll fact[MAX];
ll inv[MAX];
ll inv_fact[MAX];

template<typename T> void initComb( T n, T m = MOD )
{
	fact[0] = fact[1] = inv_fact[0] = inv_fact[1] = 1;
	inv[1] = 1;
	for ( int i = 2; i < n; i++ ) {
		fact[i] = ( fact[i - 1] * i ) % m;
		inv[i] = m - inv[m % i] * ( m / i ) % m;
		inv_fact[i] = inv_fact[i - 1] * inv[i] % m;
	}
}

template<typename T> T comb( T n, T r, T m = MOD )
{
	if ( n < r ) return ( 0 );
	if ( n < 0 || r < 0 ) return ( 0 );
	return ( fact[n] * ( inv_fact[r] * inv_fact[n - r] % m ) % m );
}
*/

void replace( string &s, string t, string r ) {
	string::size_type p = 0;
	while ( ( p = s.find( t, p ) ) != string::npos ) {
		s.replace( p, t.length(), r );
		p += r.length();
	}
}


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

	vector<ll> v( N );
	rep( i, N ) cin >> v[i];
	sort( ALL( v ) );

	map<ll, ll> m;
	rep( i, N ) m[v[i]]++;

	ll cnt = 0;
	arep( it, m )
	{
		if ( it.F > it.S )
		{
			cnt += it.S;
		}
		else
		{
			cnt += it.S - it.F;
		}
	}

	cout << cnt << endl;

	return ( 0 );
}


Measured memory_bytes: 7040
import sys
sys.setrecursionlimit(10**6)
    
def main():
    N = int(input())
    d = {}
    for _ in range(N-1):
        a, b = map(int, input().split())
        if a in d:
            d[a].append(b)
        else:
            d[a] = [b]
        if b in d:
            d[b].append(a)
        else:
            d[b] = [a]
    v = set()
    v.add(1)
    l = []
    def dfs(n):
        if n == N:
            l.append(n)
            return True
        for i in d[n]:
            if i not in v:
                v.add(i)
                if dfs(i):
                    l.append(n)
                    return True
        return False
    dfs(1)
    l.reverse()
    v = set()
    if len(l) % 2 == 0:
        half = len(l) // 2 - 1
    else:
        half = len(l) // 2
    v.add(l[half])
    s = l[half+1]
    v.add(s)
    def dfs2(n):
        r = 1
        for i in d[n]:
            if i not in v:
                v.add(i)
                r += dfs2(i)
        return r
    x = dfs2(s)
    if N - x > x:
        return 'Fennec'
    else:
        return 'Snuke'
print(main())


Measured memory_bytes: 140416
if __name__ == "__main__":
    N = int(input())
    buka_num_arr = [0] * N
    joshi_idx_arr = list(map(int,input().split()))
    for joshi_idx in joshi_idx_arr:
        buka_num_arr[joshi_idx-1] += 1
    for i in range(N):
        print(buka_num_arr[i])

Measured memory_bytes: 33780
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int main() {
	FAST
	int a,b,c;
	cin>>a>>b>>c;
	int d=a-b;
	if(d>c)
	cout<<0<<endl;
	else
	cout<<c-d<<endl;
	return 0;
}

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

char grid[25][25];

const int dx[4] = {-1, 1, 0, 0};
const int dy[4] = {0, 0, -1, 1};

int main() {
	int h, w;
	cin >> h >> w;
	for(int row = 0; row < h; ++row) {
		cin >> grid[row];
	}
	
	auto is_good = [&](int row, int col) {
		return 0 <= row && row < h && 0 <= col && col < w
			&& grid[row][col] == '.';
	};
	
	int answer = 0;
	for(int s_row = 0; s_row < h; ++s_row) {
		for(int s_col = 0; s_col < w; ++s_col) {
			if(is_good(s_row, s_col)) {
				vector<pair<int,int>> q;
				q.emplace_back(s_row, s_col);
				vector<vector<int>> dist(h, vector<int>(w));
				vector<vector<bool>> vis(h, vector<bool>(w));
				vis[s_row][s_col] = true;
				for(int i = 0; i < (int) q.size(); ++i) {
					pair<int,int> me = q[i];
					for(int dir = 0; dir < 4; ++dir) {
						int row2 = me.first + dx[dir];
						int col2 = me.second + dy[dir];
						if(is_good(row2, col2) && !vis[row2][col2]) {
							vis[row2][col2] = true;
							dist[row2][col2] = dist[me.first][me.second] + 1;
							answer = max(answer, dist[row2][col2]);
							q.emplace_back(row2, col2);
						}
					}
				}
			}
		}
	}
	cout << answer;
}


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

int main() {
  int64_t n, k = 0, r = 0;
  cin >> n;
  vector<string> v(n);
  for(int i = 0; i < n; ++i){
    int64_t a, c = 0;
    string b = "";
    cin >> a;
    while(a > 0){
      if(a % 2 == 0) b += '0';
      else b += '1';
      a /= 2;
      ++c;
    }
    v.at(i) = b;
    k = max(k, c);
  }
  vector<int> c1(k, 0);
  for(int i = 0; i < k; ++i){
    for(int j = 0; j < n; ++j){
      if(v.at(j).size() > i && v.at(j).at(i) == '1') ++c1.at(i);
    }
  }
  for(int i = 0; i < k; ++i){
    int64_t ri = c1.at(i) * (n - c1.at(i));
    ri %= 1000000007;
    for(int j = 0; j < i; ++j){
      ri *= 2;
      ri %= 1000000007;
    }
    r += ri;
    r %= 1000000007;
  }
  cout << r << endl;
}

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

using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  vector<int> vc;
  cin >> n;
  int store;
  store = n;
  while(n--) {
    int x;
    cin >> x;
    vc.push_back(x);
  }
  int result;
  int i, j;
  result = 0;
  for(i = 0;i < store-1;i++) {
    for(j = i+1;j < store;j++) {
      result+=vc[i]*vc[j];
    }
  }
  cout << result << '\n';
}





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

int main(){
   char S[3];
   for(int i=0; i<3; ++i)
      std::cin >> S[i];

   int sum = 700;
   for(int i=0; i<3; ++i)
      if(S[i]=='o') sum += 100;

   std::cout << sum << std::endl;

   return 0;
}


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

int main(void)
{
	int a;
	int asum = 0, bsum = 0;
	
	for (int i = 0; i < 4; i++){
		cin >> a;
		asum += a;
	}
	for (int i = 0; i < 4; i++){
		cin >> a;
		bsum += a;
	}
	
	cout << max(asum, bsum) << endl;
	
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
struct Edge
{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
// using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1}, dy[8] = {-1, 0, 1, 1, -1, 1, 0, -1};

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int a, b, c;
  cin >> a >> b >> c;
  if ((a + b) == c || (b + c) == a || (c + a) == b) 
    cout << "Yes" << endl;
  else 
    cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3620
#define FNAME ""

#ifdef LOCAL
    #define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

#define hash padjf9srpi
#define y0 sdkfaslhagaklsldk
#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define forn(i, n) for (int i = 0; i < (n); i++)
#define fornr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define forab(i, a, b) for (int i = (a); i < (b); i++)
#define gcd __gcd
#define all(a) (a).begin(), (a).end()
 
#ifdef _WIN32
    #define I64 "%I64d"
#else
    #define I64 "%lld"
#endif

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <int, int> pii;                                                                                                                                                                                      
typedef vector <int> vi;

template <class T> T sqr(const T &a) {return a * a;}


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

#ifdef LOCAL
    freopen(FNAME".in", "r", stdin);
    freopen(FNAME".out", "w", stdout);
#endif

    int n, m, k;
    scanf("%d%d%d", &n, &m, &k);
    forn(i, n + 1) {
        forn(j, m + 1) {
//            printf("i=%d j=%d res=%d\n", i, j, i * m + j * n - i * j);
            if (i * m + j * n - 2 * i * j == k) {
                puts("Yes");
                return 0;
            }
        }
    }
    puts("No");
}




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

int main(int argc, const char * argv[]) {
	
	int n,taro_p=0,hanako_p=0,i;
	
	
	
	scanf("%d",&n);
	
	for(i = 0 ; i  < n; i++) {
		
		//printf("%d %d ",taro_p,hanako_p);
		char taro_card[101],hanako_card[101];
		scanf("%s",taro_card);
		scanf("%s",hanako_card);
		
		int cmp=strcmp(taro_card,hanako_card);

		if(cmp == 0) {
			taro_p += 1;
			hanako_p += 1;
			//printf("drow\n");
		} else if (cmp > 0) {
			taro_p += 3;
		} else {
			hanako_p +=3;
		}
		
		int x = 0;
		
// 		while (taro_card[x] != hanako_card[x]) {
// 			
// 			if(taro_card[x] >= 'A' && taro_card[x] <= 'Z'){
// 				taro_card[x] += 32;
// 			}
// 			
// 			if(hanako_card[x] >= 'A' && hanako_card[x] <= 'Z'){
// 				hanako_card[x] += 32;
// 			}
// 			if(taro_card[x] > hanako_card[x] ) {
// 				taro_p += 3;
// 				break;
// 			}
// 			if(hanako_card[x] > taro_card[x] ) {
// 				hanako_p += 3;
// 				break;
// 			}
// 			
// 		}
		
		//printf("%s %s\n",taro_card,hanako_card);
			
	}	
	printf("%d %d\n",taro_p,hanako_p);	
	return 0;
	
}

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

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

    long long SA, SB, SC;

    long long minv = 1e9;
    for(long long y = 1; y < H; y++){
        SA = y * W;
        long long sby = (H - y)/2;
        SB = sby * W;
        SC = (H - y - sby) * W;
        if(SB == 0 || SC == 0) continue;

        long long maxs;
        long long mins;
        maxs = max(SA, SB);
        maxs = max(maxs, SC);
        mins = min(SA, SB);
        mins = min(mins, SC);
        minv = min(minv, maxs-mins);
    }

    for(long long y = 1; y < H; y++){
        SA = y * W;
        long long sbx = W/2;
        SB = (H - y) * sbx;
        SC = (H - y) * (W - sbx);
        if(SB == 0 || SC == 0) continue;

        long long maxs;
        long long mins;
        maxs = max(SA, SB);
        maxs = max(maxs, SC);
        mins = min(SA, SB);
        mins = min(mins, SC);
        minv = min(minv, maxs-mins);
    }

    for(long long x = 1; x < W; x++){
        SA = x * H;
        long long sbx = (W - x)/2;
        SB = sbx * H;
        SC = (W - x - sbx) * H;
        if(SB == 0 || SC == 0) continue;

        long long maxs;
        long long mins;
        maxs = max(SA, SB);
        maxs = max(maxs, SC);
        mins = min(SA, SB);
        mins = min(mins, SC);
        minv = min(minv, maxs-mins);
    }

    for(long long x = 1; x < W; x++){
        SA = x * H;
        long long sby = H/2;
        SB = (W - x) * sby;
        SC = (W - x) * (H - sby);
        if(SB == 0 || SC == 0) continue;

        long long maxs;
        long long mins;
        maxs = max(SA, SB);
        maxs = max(maxs, SC);
        mins = min(SA, SB);
        mins = min(mins, SC);
        minv = min(minv, maxs-mins);
    }

    cout << minv << endl;
    return 0;
}

Measured memory_bytes: 3644
import sys

read = sys.stdin.read
N, *a = map(int, read().split())
a = [0] + a

seq = []
idx = 1
for i in range(1, N + 1):
    if a[i] == idx:
        seq.append(idx)
        idx += 1

if seq:
    print(N - len(seq))
else:
    print(-1)

Measured memory_bytes: 25116
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<numeric>
#include<utility>

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;

int main(){
    ll t1, t2, a1, a2, b1, b2;
    cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;
    ll d1, d2, q1, q2;
    d1 = t1 * a1;
    d2 = t2 * a2;
    q1 = t1 * b1;
    q2 = t2 * b2;
    if(d1 < q1){
        swap(d1, q1);
        swap(d2, q2);
    }
    ll diff = (q1 + q2) - (d1 + d2);
    if(diff == 0){
        cout << "infinity" << endl;
        return 0;
    }
    if(diff < 0){
        cout << 0 << endl;
        return 0;
    }
    ll ans = 1 + 2 * (ll)(((d1 - q1) + diff - 1) / diff - 1);
    if((d1 - q1) % diff == 0) ans++;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
typedef long long ll;
ll gcd(ll x, ll y){return y? gcd(y, x%y) : x;}

vector<pair<ll, int>>factorize(ll n){
	vector<pair<ll, int>> res;
	for (ll i=2; i*i<=n; ++i){
		if(n%i) continue;
		res.emplace_back(i, 0);
		while(n%i == 0){
			n /= i;
			res.back().second++;
		}
	}
	if(n != 1) res.emplace_back(n, 1);
	return res;
}

int main(){
	ll a, b;
	cin >> a >> b;
	ll g = gcd(a, b);
	auto f = factorize(g);
	int ans = f.size() + 1;
	cout << ans << endl;
	return 0;
}




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

fn main() {
    let h: usize = read();
    let w: usize = read();
    let s: Vec<Vec<char>> = (0..h).map(|_| read::<String>().chars().collect()).collect();

    let n = h * w;
    let mut uf = UnionFind::new(n);
    for i in 0..h {
        for j in 0..w {
            if i < h-1 && s[i][j] != s[i+1][j] {
                uf.unite(i*w + j, (i+1)*w + j);
            }
            if j < w-1 && s[i][j] != s[i][j+1] {
                uf.unite(i*w + j, i*w + j+1);
            }
        }
    }

    let mut black = vec![0; n];
    let mut white = vec![0; n];
    for i in 0..h {
        for j in 0..w {
            let root = uf.find(i*w + j);
            if s[i][j] == '#' {
                black[root] += 1;
            } else {
                white[root] += 1;
            }
        }
    }

    let mut used = vec![false; n];
    let mut ans: i64 = 0;
    for i in 0..h {
        for j in 0..w {
            let root = uf.find(i*w + j);
            if used[root] {
                continue;
            }
            ans += black[root] * white[root];
            used[root] = true;
        }
    }

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

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

#[derive(Debug)]
struct UnionFind {
    par: Vec<usize>,
    rank: Vec<usize>,
}

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

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

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

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

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

Measured memory_bytes: 12540
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>

using namespace std;

int main() {
	int n;
	cin >> n;
	int cards[4][13];
	
	for (int i = 0; i < n; ++i) {
		int v;
		char s;
		cin >> s >> v;
		if (s == 'S') cards[0][v-1] = v;
		else if(s=='H') cards[1][v-1] = v;
		else if(s=='C') cards[2][v-1] = v;
		else if(s=='D') cards[3][v-1] = v;
	}
	int _cards[4][13];
	
	for (int i = 0; i < 4; ++i) {
		for (int j = 1; j <= 13; ++j) {
			_cards[i][j-1] = j;
		}
	}

	for (int i = 0; i < 4; ++i) {
		for (int j = 1; j <= 13; ++j) {
			if (cards[i][j-1] != _cards[i][j-1]) {
				if (i == 0) cout << "S " << _cards[i][j-1] << endl;
				else if (i == 1) cout << "H " << _cards[i][j-1] << endl;
				else if (i == 2) cout << "C " << _cards[i][j-1] << endl;
				else if (i == 3) cout << "D " << _cards[i][j-1] << endl;
			}
		}
	}
}


Measured memory_bytes: 3072
#include <iostream>
#include <cstdio>

using namespace std;




int main()
{
	int x, y;
	
	while (1)
	{
		cin >> x >> y;
		if (x==0 && y==0) return 0;
		if (x < y) cout << x << " " << y << "\n";
		else cout << y << " " << x << "\n";
	}
	
	return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<vector>
using namespace std;
typedef long long int ll;
int w, h, n;
int sdx, sdy, edx, edy;
int res;

void calc1(int x, int y) {
	if (x > sdx) {
		if (x < edx) {
			res -= (x - sdx)*(edy - sdy);
			sdx = x;
		}
		else {
			res -= (edx - sdx)*(edy - sdy);
		}
	}
	//cout << "最初: " << "res=" << res << " sdx=" << sdx << " sdy=" << sdy << " edx=" << edx << " edy=" << edy << endl;
}
void calc2(int x, int y) {
	if (x < edx) {
		if (x > sdx) {
			res -= (edx - x)*(edy - sdy);
			edx = x;
		}
		else {
			res -= (edx - sdx)*(edy - sdy);
		}
	}
	//cout << "最初: " << "res=" << res << " sdx=" << sdx << " sdy=" << sdy << " edx=" << edx << " edy=" << edy << endl;

}
void calc3(int x, int y) {
	if (y > sdy) {
		if (y < edy) {
			res -= (edx - sdx)*(y - sdy);
			sdy = y;
		}
		else {
			res -= (edx - sdx)*(edy - sdy);
		}
	}
	//cout << "最初: " << "res=" << res << " sdx=" << sdx << " sdy=" << sdy << " edx=" << edx << " edy=" << edy << endl;

}
void calc4(int x, int y) {
	if (y < edy) {
		if (y > sdy) {
			res -= (edy - y)*(edx - sdx);
			edy = y;
		}
		else {
			res -= (edx - sdx)*(edy - sdy);
		}
	}
	//cout << "最初: " << "res=" << res << " sdx=" << sdx << " sdy=" << sdy << " edx=" << edx << " edy=" << edy << endl;
}



int main()
{

	
	cin >> w >> h >> n;
	res = w*h;
	int x, y, a;
	sdx = 0;
	sdy = 0;
	edx = w;
	edy = h;
	//cout << "最初: " << "res=" << res << " sdx=" << sdx << " sdy=" << sdy << " edx=" << edx << " edy=" << edy << endl;

	for (int i = 0; i < n; i++) {
		cin >> x >> y >> a;
		if (a == 1) { calc1(x, y); }
		else if (a == 2) { calc2(x, y); }
		else if (a == 3) { calc3(x, y); }
		else if (a == 4) { calc4(x, y); }
		if (res == 0)break;
	}
	cout << res << endl;

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
    auto val = table(args...);
    return vector<decltype(val)>(n, move(val));
}
const ll INF = 1e16;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 200005;
int nx[4] = {1,0,-1,0};
int ny[4] = {0,1,0,-1};
class UnionFind{
    private:
        vector<ll> par;
        vector<ll> siz;
    public:
        UnionFind(ll sz){
            par.resize(sz);
            siz.assign(sz,1LL);
            rep(i,sz) par[i] = i;
        }

        ll find(ll x){
            if (par[x] == x) return x;
            else return par[x] = find(par[x]);
        }

        void unite(ll x,ll y){
            x = find(x);
            y = find(y);
            if (x == y) return;
            if (siz[x] < siz[y]) swap(x,y);
            siz[x] += siz[y];
            par[y] = x;
        }

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

        ll size(ll x){
            return siz[find(x)];
        }
};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;
    cin >> n >> m;
    UnionFind sw(n);
    vector<int> p(n);
    rep(i,n) cin >> p[i];
    int a,b;
    rep(i,m){
        cin >> a >> b;
        a--;
        b--;
        sw.unite(a,b);
    }
    int ans = 0;
    rep(i,n){
        if (sw.same(i,--p[i])) ans++;
    }
    PRINT(ans);
}


Measured memory_bytes: 2176
#include <iostream>
#include <queue>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

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

    int n, m;
    cin >> n >> m;

    vector<vector<int> > dp(n);
    REP(i, m) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        dp[a].push_back(b);
        dp[b].push_back(a);
    }

    queue<int> q;
    vector<int> dist(n, -1);
    vector<int> pre(n, -1);

    q.push(0);
    dist[0] = 0;

    while (!q.empty()) {
        int v = q.front();
        q.pop();
        for (int i : dp[v]) {
            if (dist[i] != -1) continue ;
            dist[i] = dist[v] + 1;
            q.push(i);
            pre[i] = v;
        }
    }

    cout << "Yes" << '\n';
    for (int i = 1; i < n; i++)
        cout << pre[i] + 1 << '\n';
    return 0;
}

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

using ll = long long;
using ull = unsigned long long;
using st = string;
using db = double;
using bl = bool;
using vll = vector<long long>;
using vdb = vector<db>;
using vvll = vector<vll>;
using vst = vector<st>;
using vchar = vector<char>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
#define rep(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define vrep(i, vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b;return true;} return false;}
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b;return true;} return false;}
const ll mod = 1000000007;
const ll inf = 1LL << 60;


int main(){
  st s;
  cin >> s;
  vchar check = {'A', 'C', 'G', 'T'};
  ll now = 0;
  ll flag = 0;
  ll ans = 0;
  ll max = 0;
  while(now < s.size()){
    vrep(i, check){
      if(flag == 0 && s.at(now) == i){
        max++;
        flag = 1;
        goto skip;
      }
      else if(flag == 1 && s.at(now) == i) {
        max++;
        goto skip;
      }
    }
    max = 0;
    flag = 0;
    skip:
    chmax(ans, max);
    now++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <unordered_set>
#include <unordered_map>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>

using namespace std;

namespace {

}

int main()
{
	int N = 0;
	string S;

	cin >> N;
	cin >> S;

	// 切断箇所のループ
	int maxCount = 0;
	for (int i = 0; i < N; ++i){
		string sl = S.substr(0, i);
		string sr = S.substr(i, S.size() - i);

		set<char> ssl(sl.cbegin(),sl.cend());
		set<char> ssr(sr.cbegin(), sr.cend());

		set<char> ands;

		set_intersection(ssl.begin(), ssl.end(), ssr.begin(), ssr.end(), inserter(ands, ands.begin()));
		int tmpCount = ands.size();
		maxCount = max(maxCount, tmpCount);

		
	}
	cout << maxCount;

	return 0;
}

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

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  string s;
  cin >> s;
  string ans = "x";
  rep(i,s.length()-1) {
    ans += "x";
  }
  cout << ans << endl;
  return 0;
}

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

#define ll long long
#define pi 2*acos(0.0)

const int maxn = 1e5+7;

int n;

ll a[maxn][3], dp[maxn][3];

ll call(int pos, int act)
{
    if(pos >= n)
    {
        return 0;
    }

    if(dp[pos][act] != -1)
    {
        return dp[pos][act];
    }

    ll ret = 0;

    if(act == 0)
    {
        ret = a[pos][act] + max(call(pos+1, 1), call(pos+1, 2));
    }
    else if(act == 1)
    {
        ret = a[pos][act] + max(call(pos+1, 0), call(pos+1, 2));
    }
    else if(act == 2)
    {
        ret = a[pos][act] + max(call(pos+1, 1), call(pos+1, 0));
    }

    return dp[pos][act] = ret;
}

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

    for(int i = 0; i < n; i++)
    {
        scanf("%lld %lld %lld", &a[i][0], &a[i][1], &a[i][2]);
    }

    memset(dp, -1, sizeof dp);

    ll ans = max(call(0, 0), max(call(0, 1), call(0, 2)));

    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 9600
#19 Grid Coloring
h,w=map(int,input().split() )
n=int(input())
a=list(map(int,input().split()))


import numpy as np

lis=[]
for i in range(n):
    lis.extend([i+1]*a[i])

lis = np.array(lis).reshape((h,w))

for i in range(1,h,2):
    lis[i] = lis[i][::-1]

for i in range(h):
    print(*lis[i])

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

int main(){
int a,b,c;
cin >> a>>b >>c;
if(a==b && a==c && b==c)cout <<"No" <<endl;
else if(a==b)cout <<"Yes" <<endl;
else if(a==c) cout <<"Yes" <<endl;
else if(b==c)cout <<"Yes" <<endl;
else    cout<<"No" <<endl;



return 0;
}

Measured memory_bytes: 256
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 min(a: i32, b: i32) -> i32 {
    return if a > b { b } else { a };
}

fn main() {
    let (A, B, K): (i32, i32, i32) = (read(), read(), read());
    let mut cnt = 0;
    for i in (0..min(A, B)).rev() {
        let t = i + 1;
        if A % t == 0 && B % t == 0 {
            cnt += 1;
            if cnt == K {
                println!("{}", t);
                break;
            }

        }
    }
}


Measured memory_bytes: 4352
x = int(input())
if 400<=x<=599:
    print("8")
elif 600<=x<=799:
    print("7")
elif 800<=x<=999:
    print("6")
elif 1000<=x<=1199:
    print("5")
elif 1200<=x<=1399:
    print("4")
elif 1400<=x<=1599:
    print("3")
elif 1600<=x<=1799:
    print("2")
elif 1800<=x<=1999:
    print("1")

Measured memory_bytes: 9188
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
MOD = 10**9 + 7
alpa = [chr(ord("a")+ i) for i in range(26)]
cnt = [10000000 for i in range(26)]
n = int(input())
li = [list(input()) for i in range(n)]
for i in range(n):
    c = collections.Counter(li[i])
    Key = []
    Val = []
    for key,value in c.items():
        Key.append(ord(key)-97)
        Val.append(value)
    for j in range(26):
        if j in Key:
            for k in range(len(Key)):
                if j == Key[k]:
                    cnt[j] = min(cnt[j],Val[k])
        else:
            cnt[j] = 0
ans = ""
for i in range(len(alpa)):
    ans += alpa[i]*cnt[i]
print(ans)
    

Measured memory_bytes: 3316