akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define g(a, b) __gcd((a), (b))
#define l(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
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<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;}
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        ll N;
        cin >> N;
        vll A(N);
        rep(i, 0, N) cin >> A[i];

        ll now = 1;
        ll ans = 0;
        rep(i, 0, N) {
                if (A[i] == now) {
                        ++now;
                        ++ans;
                }
        }
        if (ans != 0)
                cout << N - ans << endl;
        else
                cout << -1 << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include<cmath>

using namespace std;
            
int main(){

    int syakkin = 100000;
    int syu;
    double d;
    cin >> syu;
    
    for(int i = 0; i < syu; ++i){
        syakkin = (syakkin + ((syakkin / 100) * 5));
        syakkin = ceil(syakkin / 1000.0) * 1000;
    }

    cout << syakkin << endl;
    
	return 0;
}

Measured memory_bytes: 1164
import itertools

X, Y, Z, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]
 
list_ = [b+c for (b,c) in itertools.product(B, C)]
list_.sort(reverse=True)
 
list__ = [ab+c for (ab,c) in itertools.product(list_[:K], A)]
list__.sort(reverse=True)
for N in list__[:K]:
  print(N)

Measured memory_bytes: 143920
#include <iostream>
#include <queue>
#include <map>
#include <vector>
using namespace std;

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

typedef pair<int,int> state;

int main(){
	int n,m,field[10][10];
	while(cin >> m >> n,n){
		int cnt = 0,x[25],y[25],sx,sy,res = 0;
		map<state,int> ans;
		for(int i = 0;i < n;i++){
			for(int j = 0;j < m;j++) {
				cin >> field[i][j];
				if(field[i][j] == 2) {
					field[i][j] = -1;
					sx = i;
					sy = j;
				}
				else if(field[i][j] == 1) {
					x[cnt] = i;
					y[cnt] = j;
					field[i][j] = ++cnt;
				}
			}
		}
		x[cnt] = sx;
		y[cnt] = sy;
		priority_queue<state,vector<state>,greater<state> > que;
		que.push(state(0,cnt));
		ans[state(0,cnt)] = 1;
		while(!que.empty()){
			state st = que.top();que.pop();
			for(int i = 0;i < 4;i++){
				int nx = x[st.second] + dx[i],ny = y[st.second] + dy[i];
				while(nx >= 0 && nx < n && ny >= 0 && ny < m){
					if(st.first == (1 << cnt) - 1){
						if(field[nx][ny] == -1){
							res += ans[st];
							break;
						}
					}
					else if(field[nx][ny] > 0 && !(st.first >> (field[nx][ny] - 1) & 1)){
						state now = state(st.first | (1 << (field[nx][ny] - 1)),field[nx][ny] - 1);
						if(!ans[now]) que.push(now);
						ans[now] += ans[st];
						break;
					}
					nx += dx[i];
					ny += dy[i];
				}
			}
			ans.erase(ans.find(st));
		}
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 8784
#include<bits/stdc++.h>
#define mp make_pair
#define fi first
#define se second
#define VAL 100000
#define ll  long long
#define INF 10000000000000000LL
#define pll pair<long long , long long>
const int MAX=1e6+10;
const ll MOD=2019;
const int TOT_PRIMES=19;
const int MAX_A=70;
using namespace std;
vector<int>adj[MAX];
int dep[MAX];
int vis[MAX];
int par[MAX];
void dfs(int u){
	queue<pair<int, int> > q;
	q.push(mp(u,0));
	while(!q.empty()){
		pair<int,int> from=q.front();
		q.pop();
		if(vis[from.first])
			continue;
		vis[from.first]=1;
		
		for(auto v:adj[from.first]){
			if(dep[v]>=dep[from.first]+1)
			{
				par[v]=from.first;
				dep[v]=dep[from.first]+1;
			}
			q.push(mp(v, dep[v]));
		}
	}
}
int main() 
{
	int n , m;
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int x, y;
		cin>>x>>y;
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	for(int i=1;i<=n;i++)
		dep[i]=INT_MAX;
	dep[1]=0;
	int cp=0;
	dfs(1);
	bool flag=true;
	for(int i=1;i<=n;i++){
		if(!vis[i])
			flag=false;
	}
	if(!flag)
		cout<<"No";
	else{
		cout<<"Yes"<<"\n";
		for(int i=2;i<=n;i++)
			cout<<par[i]<<"\n";
	}

}

Measured memory_bytes: 34024
n, m = map(int, input().split())
k = []
s = [[] for _ in range(m)]
for i in range(m):
    line = list(map(int, input().split()))
    k.append(line[0])
    for j in range(len(line)-1):
        s[i].append(line[j+1])
p = list(map(int, input().split()))

def make(n):
    lists = []
    for i in range(2**n):
        str = format(i,"10b")
        bitlist = list(reversed(str.replace(" ", "0")))
        lists.append(bitlist)
    return lists
count = 0

for switch in make(n):
    flag = 0
    for i in range(m):
        sum = 0
        for j in range(k[i]):
            sum += int(switch[s[i][j]-1])
        if sum % 2 != p[i]:
            flag = 1
    if flag == 0:
        count += 1
print(count)

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

int main()
{
    int n, l;
    cin >> n >> l;
    vector<string> s(n);
    for (int i = 0; i < n; i++)
    {
        cin >> s[i];
    }
    sort(s.begin(), s.end());
    for (int i = 0; i < n; i++)
    {
        cout << s[i];
    }
}

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

int m, n;
vector<int> books;

bool ok(int w) {
    int cnt = 1, sum = 0;
    for (int i=0; i<n; ++i) {
        if (w < books[i]) return false;
        if (w < sum + books[i]) {
            sum = books[i];
            cnt ++;
        } else {
            sum += books[i];
        }
    }
    return cnt <= m;
}

int main() {
    while (cin >> m >> n, m) {
        books.resize(n);
        for (int i=0; i<n; ++i) {
            cin >> books[i];
        }
        int l = 0;
        int h = 100000000;
        while (l < h) {
            int mid = (l + h) / 2;
            if (ok(mid)) {
                h = mid;
            } else {
                l = mid + 1;
            }
        }
        cout << l << endl;
    }
    return 0;
}

Measured memory_bytes: 1216
n = int(input())
k = n
cnt = 1
while(n>0):
    if(n>=10):
        #print(n)
        n = n//10
        cnt += 1
    else:
        break
#print(cnt)
if(cnt == 1):
    print(k)
elif(cnt == 2):
    print(9)
elif(cnt == 3):
    print(9 + k-99)
elif(cnt == 4):
    print(9 + 900)
elif(cnt == 5):
    print(9 + 900 + k-9999)
elif(cnt == 6):
    print(9 + 900 + 90000)


Measured memory_bytes: 3060
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;

int main(){
  int n;
  while(cin >> n,n){
    map<int, long long> m;
    vector<int> order;
    for(int i = 0 ; i < n ; i++ ){
      int id;
      long long a, b;
      cin >> id >> a >> b;
      if( m.find(id) == m.end()){
	order.push_back(id);
	m[id] = a*b;
      }else{
	m[id] += a*b;
      }
    }
    bool isAns = false;
    for(int i = 0; i < (int)order.size(); i++){
      long long money = m[ order[i] ];
      if( money  >= 1000000){
	cout << order[i] << endl;
	isAns = true;
      }
    }
    if( !isAns )cout << "NA" << endl;
  }
  return 0;
}

Measured memory_bytes: 1288
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1000000007;

int main()
{
	int n;
	cin >> n;
	switch (n % 10) {
	case 2:
	case 4:
	case 5:
	case 7:
	case 9:
		cout << "hon" << endl;
		break;
	case 0:
	case 1:
	case 6:
	case 8:
		cout << "pon" << endl;
		break;
	case 3:
		cout << "bon" << endl;
		break;
	default:
		break;
	}
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<long>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,s,t) for(int i=s; i<t; i++)
#define RNG(i,s,t,u) for(int i=s; i<t; i+=u)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()

int main(){
  long n,wm;
  cin >> n >> wm;
  vl w(n),v(n);
  rep(i,n){
    cin >> w[i] >> v[i];
  }
  vvl dp(n+1, vl(2e5, 1e16));
  dp[0][0] = 0;
  rep(i,n){
    rep(j,2e5){
      if(j-v[i] < 0) dp[i+1][j] = dp[i][j];
      else dp[i+1][j] = min(dp[i][j], dp[i][j-v[i]] + w[i]);
    }
    for(int j=2e5-2;j>=0;j--){
      dp[i+1][j] = min(dp[i+1][j+1], dp[i+1][j]);
    }
  }
  int iter = upper_bound(all(dp[n]), wm) - dp.at(n).begin();
  cout << iter-1 << endl;
  //rep(i,141) cout << dp[n][i] << " ";
}
  

Measured memory_bytes: 162708
n = int(input())
P = list(map(int, input().split()))
ans = 0

for p1, p2, p3 in zip(P, P[1:], P[2:]):
    p = [p1, p2, p3]
    p.sort()
    if p2 == p[1]:
        ans += 1
print(ans)


Measured memory_bytes: 38256
from collections import deque
import sys

N_MAX = 200000 + 5

H, W, K = map(int, input().split())
sth, stw, glh, glw = map(int, input().split())

INF = 10**6 * K

dp = [[INF for _ in range(W+2)] for _ in range(H+2)]

dp[0] = [-1]*(W+2)
dp[H+1] = [-1]*(W+2)
for h in range(1, H+1):
    s = sys.stdin.readline()
    dp[h][0] = -1
    dp[h][W+1] = -1
    for w in range(1, W+1):
        if s[w-1] == "@":
            dp[h][w] = -1


# Seen = [[INF]*W for _ in range(H)]
XY = {(1, 0), (-1, 0), (0, 1), (0, -1)}


def bfs(sth, stw, glh, glw):
    next_q = deque()
    next_q.append((sth, stw, 0))
    dp[sth][stw] = 0

    while len(next_q) != 0:
        # キュー取り出し(先頭)
        h, w, c = next_q.popleft()
        for dh, dw in XY:
            for sk in range(1, K+1):
                hs, ws = h + dh*sk, w + dw*sk
                if dp[hs][ws] == -1:
                    break
                if dp[hs][ws] == INF:
                    next_q.append((hs, ws, c+1))
                    dp[hs][ws] = c + 1
                elif dp[hs][ws] <= c:
                    break
                if hs == glh and ws == glw:
                    return c + 1
    return -1


def main():
    ret = bfs(sth, stw, glh, glw)
    print(ret)


if __name__ == '__main__':
    main()


Measured memory_bytes: 53000
/*
 * @Author: Wa_King 
 * @Date: 2019-11-23 19:58:12 
 * @Last Modified by: Wa_King
 * @Last Modified time: 2019-11-23 20:12:12
 */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pb push_back
#define fi first
#define se second
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
const int mod = 1e9 + 7;
const int maxn = 2e5 + 10;
const int inf = 0x3f3f3f3f;
ll book[maxn];
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    int n;
    cin>>n;
    ll sum=0,now=0;
    rep(i,1,n) cin>>book[i],sum+=book[i];
    ll ans=1e18;
    rep(i,1,n-1)
    {
        now+=book[i];
        ans=min(ans,abs(sum-2*now));
    }
    cout<<ans<<'\n';
    return 0;
}

Measured memory_bytes: 1792
from collections import deque
N = int(input())
A = list(map(int, input().split()))
X = [0]*(N+1)
S = sum(A)

even_list = [A[i] for i in range(1, N) if (i+1) % 2 == 0]
odd_list = [A[i] for i in range(1, N) if (i+1) % 2 != 0]

X[1] = S - 2 * sum(even_list)
X[2] = S - 2 * sum(odd_list)

even = sum(even_list)
odd = sum(odd_list)
s_even_idx = 2
s_odd_idx = 3
t_even_idx = N-1
t_odd_idx = N
A = A + A

for i in range(3, N+1):
  if i%2:
    even -= A[s_even_idx-1]
    s_even_idx += 2 
    t_even_idx += 2 
    even += A[t_even_idx-1]
    X[i] = S - 2 * even
  else:
    odd -= A[s_odd_idx-1]
    s_odd_idx += 2
    t_odd_idx += 2
    odd += A[t_odd_idx-1]
    X[i] = S - 2 * odd

for i in range(1, N+1):
  print(X[i], end=" ")
    


Measured memory_bytes: 67684
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;


int main() {
	
	long long int a;
	cin >> a ; 
	int flag = 0;
	long long int minn;
  for(long long  i=2 ; i*i<=a; ++i)
    {
        if(a%i==0) {
            minn=a/i +i -2;
 
        }
    }
    if(minn) cout << minn << endl;
    else{cout << a-1 << endl;}
	return 0;

}

Measured memory_bytes: 508
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <numeric>
#include <map>

#define rep(i, j) for(int i = 0; i < j; i++)
#define all(i) i.begin(), i.end()

using namespace std;

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, Q; while (cin >> N >> Q && N != 0 && Q != 0)
	{
		map<int, int> dat;
		rep(i, N)
		{
			int M; cin >> M;
			rep(j, M)
			{
				int tmp; cin >> tmp;
				dat[tmp] ++;
			}
		}
		int ans[2] = { 0 };
		for(auto i : dat)
		{
			if (ans[1] < i.second)
			{
				ans[0] = i.first;
				ans[1] = i.second;
			}
			else if (ans[1] == i.second && ans[0] > i.first)
			{
				ans[0] = i.first;
				ans[1] = i.second;
			}
		}
		if (ans[1] < Q) { ans[0] = 0; }
		printf("%d\n", ans[0]);
	}
	return 0;
}

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

#define INF 1001001001
#define SIZE 500100

int L[SIZE / 2], R[SIZE / 2], cnt = 0;

void merge(int a[], int left, int middle, int right) {
    int n1 = middle - left, n2 = right - middle;
    for (int i = 0; i < n1; i++) L[i] = a[left + i];
    for (int i = 0; i < n2; i++) R[i] = a[middle + i];
    L[n1] = R[n2] = INF;
    int i = 0, j = 0;
    for (int k = left; k < right; k++) {
        if (L[i] <= R[j]) {
            a[k] = L[i];
            i++;
        } else {
            a[k] = R[j];
            j++;
        }
        cnt++;
    }
    return;
}

void mergeSort(int a[], int left, int right) {
    if (left + 1 < right) {
        int middle = (left + right) / 2;
        mergeSort(a, left, middle);
        mergeSort(a, middle, right);
        merge(a, left, middle, right);
    }
    return;
}

void print(int n,int a[]) {
    for (int i = 0; i < n; i++) {
        if (i) cout << " ";
        cout << a[i];
    }
    cout << endl;
    return;
}

int main() {
    int n, S[SIZE];
    cin >> n;
    for (int i = 0; i < n; i++) cin >> S[i];
    mergeSort(S, 0, n);
    print(n, S);
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 7012
#include <bits/stdc++.h>
using namespace std;
 
int main() {int n;cin>>n;
            if(n==111)cout<<999;
            else if(n==119)cout<<991;
            else if(n==191)cout<<919;
            else if(n==911)cout<<199;
            else if(n==199)cout<<911;
            else if(n==919)cout<<191;
            else if(n==991)cout<<119;
            else if(n==999)cout<<111;
            cout<<endl;}

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

// 💖 Hi, thanks for using ICIE! 💖
// 🔧 To use a custom code template, set it in Settings(Ctrl+,) in "Icie Template List" entry 🔧
// 📝 If you spot any bugs or miss any features, create an issue at https://github.com/pustaczek/icie/issues 📝

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

    int n, k;

    int p = 1, ans=0;
    cin >> n >> k;
    while (p <= n)
    {
        p *= k;
        ans++;
    }
    cout << ans << '\n';
}



Measured memory_bytes: 256
from collections import Counter
 
n = int(input())
V =list(map(int,input().split()))

V1 = V[::2]
V2 = V[1::2]
 
V1c = Counter(V1).most_common()
V2c = Counter(V2).most_common()

k1, v1 = V1c[0][0], V1c[0][1]
k2, v2 = V2c[0][0], V2c[0][1]

ans = 0
if k1 == k2:
    ans = n - v1
    m = 0
    if len(V1c) >= 2:
        m = max(m, V1c[1][1])
    if len(V2c) >= 2:
        m = max(m, V2c[1][1])
    ans = ans - m
else:
    ans = n - v1 - v2
print(ans)

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

const int MAX = 1 << 30;

struct node {
	ll sum, add;
	node *lch, *rch;
	node() : sum(0), add(0), lch(nullptr), rch(nullptr) {}
};

node* fix(node *x) {
	node *y = new node();
	if (x) *y = *x;
	return y;
}

node* add(node *x, int l, int r, int lb = 0, int ub = MAX) {
	if (r <= lb || ub <= l) return x;
	x = fix(x);
	if (l <= lb && ub <= r) {
		x->add++;
		return x;
	}
	int c = (lb + ub) / 2;
	x->lch = add(x->lch, l, r, lb, c);
	x->rch = add(x->rch, l, r, c, ub);
	x->sum += min(r, ub) - max(l, lb);
	return x;
}

ll find(node *x, int l, int r, int lb = 0, int ub = MAX) {
	if (!x || r <= lb || ub <= l) return 0;
	if (l <= lb && ub <= r) return x->sum + x->add * (ub - lb);
	int c = (lb + ub) / 2;
	return find(x->lch, l, r, lb, c) + find(x->rch, l, r, c, ub) + x->add * (min(r, ub) - max(l, lb));
}

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int N, M, Q;
	cin >> N >> M >> Q;
	vector<vector<int>> vab(M, vector<int>(3));
	vector<int> vs;
	for (int i = 0; i < M; i++) {
		cin >> vab[i][1] >> vab[i][2] >> vab[i][0]; vab[i][1]--;
		vs.push_back(vab[i][0]);
	}
	sort(vab.begin(), vab.end());
	sort(vs.begin(), vs.end());
	vs.erase(unique(vs.begin(), vs.end()), vs.end());
	int s = vs.size();
	node* root = nullptr;
	vector<node*> rts(s);
	for (int i = 0, j = 0; i < s; i++) {
		while (j < M && vab[j][0] == vs[i]) {
			root = add(root, vab[j][1], vab[j][2]);
			j++;
		}
		rts[i] = root;
	}
	while (Q--) {
		int x, y;
		ll j;
		cin >> x >> y >> j; x--, j--;
		int lb = -1, ub = s - 1;
		while (ub - lb > 1) {
			int m = (lb + ub) / 2;
			if (find(rts[m], x, y) <= j) {
				lb = m;
			}
			else {
				ub = m;
			}
		}
		printf("%d\n", vs[ub]);
	}
	return 0;
}



Measured memory_bytes: 402268
import sys
import math
import itertools
import collections
from collections import deque
from collections import defaultdict
 
sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
MOD2 = 998244353
INF = float('inf')
input = lambda: sys.stdin.readline().strip()
 
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()
 
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
 
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
 
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
 
        if x == y:
            return
 
        if self.parents[x] > self.parents[y]:
            x, y = y, x
 
        self.parents[x] += self.parents[y]
        self.parents[y] = x
 
    def size(self, x):
        return -self.parents[self.find(x)]
 
    def same(self, x, y):
        return self.find(x) == self.find(y)
 
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
 
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
 
    def group_count(self):
        return len(self.roots())
 
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
 
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
    
def main():
    
    N, M = NMI()
    
    uf = UnionFind(N)
    
    for m in range(M):
        A,B = NMI()
        uf.union(A-1, B-1)
 
    ans = 0
    for n in range(N):
        ans = max(ans,uf.size(n))
    print(ans)
 
 

if __name__ == '__main__':
    main()

Measured memory_bytes: 14888
#include<bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(int)(b);++i)
#define rep(i,n) REP(i,0,n)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

using namespace std;
typedef long long ll;

int main() {
    int a, b;
    cin >> a >> b;
    cout << a * b - (a + b - 1) << endl;
    return 0;
}




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

int main(){
    int n;
    cin >> n;
    int d[n];
    for(int i = 0; i < n; i++)  cin >> d[i];
    int ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            ans += d[i]*d[j];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
#define rep(i, N) for(i = 0; i < N; i++)
#define ll long long

int main() {
  ll N, M;
  cin >> N >> M;
  vector<bool> rep = {};

  vector<ll> H = {};
  ll i;
  rep(i, N) {
    ll tmp;
    cin >> tmp;
    H.push_back(tmp);
    rep.push_back(true);
  }

  rep(i, M) {
    ll a, b;
    cin >> a >> b;
    a -= 1;
    b -= 1;
    if(H[a] > H[b]) {
      rep[b] = false;
    } else if(H[a] == H[b]) {
      rep[a] = false;
      rep[b] = false;
    } else {
      rep[a] = false;
    }
  }

  ll ans = 0;
  rep(i, N) {
    if(rep[i]) ans++;
  }
  cout << ans;

  return 0;
}

Measured memory_bytes: 4320
#include<cstdio>
#include<algorithm>

using namespace std;

const int MAX_N = 100000;
const int MAX_Q = 100000;
const long long UB = 1000000000;

long long A[MAX_N];
int N;

long long eSum[MAX_N], oSum[MAX_N];
long long sum[MAX_N];

bool lt(int x, int a, int b){
	if(b < 0 || b >= N) return true;
	if(a < 0 || a >= N) return false;
	long long d1 = abs(x - A[a]);
	long long d2 = abs(x - A[b]);
	if(d1 < d2) return true;
	if(d1 == d2) return a < b;
	return false;
}

long long calc(int r, int d){
	if(r < 0) return 0;
	if(d == 0) return eSum[r];
	else if(d == 1) return oSum[r];
	else return sum[r];
}

long long calc(int l, int r, int d){
	if(l > r) return 0;
	return calc(r, d) - calc(l - 1, d);
}

long long query(int x){
	int lb = 1, ub = N + 1;
	while(ub - lb > 1){
		int mid = (lb + ub) / 2;
		int a = mid / 2;
		int b = mid / 2;
		if(a + b < mid) a++;
		int l = N - mid;
		int r = N - a - 1;
		// take [l, r]
		if(lt(x, r + 1, l)) ub = mid;
		else lb = mid;
	}
	// lb cards: no conflict
	int a = (lb + 1) / 2;
	int d = N % 2;
	long long ans = calc(0, N - lb - 1, d) + calc(N - lb, N - a - 1, -1);
	return sum[N - 1] - ans;
}

int main(){
	int Q;
	scanf("%d%d", &N, &Q);
	for(int i = 0; i < N; ++i) scanf("%lld", A + i);
	sum[0] = A[0];
	for(int i = 1; i < N; ++i) sum[i] = sum[i - 1] + A[i];
	eSum[0] = A[0];
	for(int i = 1; i < N; ++i) eSum[i] = eSum[i - 1] + (i % 2 == 0 ? A[i] : 0);
	oSum[0] = 0;
	for(int i = 1; i < N; ++i) oSum[i] = oSum[i - 1] + (i % 2 == 1 ? A[i] : 0);
	for(int i = 0; i < Q; ++i){
		long long x;
		scanf("%lld", &x);
		long long ans = query(x);
		printf("%lld\n", ans);
	}
	return 0;
}


Measured memory_bytes: 4736
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <iomanip>
#include <list>
#include <queue>
#include <stack>
#include <map>
#define modulus 1000000007
using namespace std;

int main(){
    long long a, b, c, k;
    cin >> a >> b >> c >> k;
    long long res = 0;
    while(k > 0){
        if(k <= a){
            res += k;
            k = 0;
        }
        else{
            res += a;
            k -= a;
        }
        if(k <= b){
            k = 0;
        }
        else k -= b;
        if(k <= c){
            res -= k;
            k = 0;
        }
        else k -= c;
    }
    cout << res << endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define INF (1 << 30) - 1
#define LLINF (1LL << 61) - 1
// #define int ll
using namespace std;
const int MOD = 1000000007;
const int MAX = 510000;


ll extgcd(ll a, ll b, ll& x, ll& y){
    ll d=a;
    if(b != 0){
        d = extgcd(b, a%b, y, x);
        y -= (a/b) * x;
    }
    else{
        x=1;y=0;
    }
    return d;
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll a,b,x,y;
    cin>>a>>b;
    extgcd(a,b,x,y);
    cout<<x<<" "<<y<<endl;
    return 0;
}


Measured memory_bytes: 3200
s = input()
t = input()
s_ = sorted(s)
t_ = sorted(t, reverse=True)
for n, i in enumerate(zip(s_, t_)):
    if i [0]< i[1]:
        print('Yes')
        break
    elif i[1] < i[0]:
        print('No')
        break
    if n + 1 == min(len(s_), len(t_)):
        if len(s_) < len(t_):
            print('Yes')
            break
        elif len(t_) <= len(s_):
            print('No')
            break

Measured memory_bytes: 3064
A, B , C , D = list(map(int,input().split()))

S = C
T = A

while S>0 and T>0:
    S=S-B
    T=T-D
    if S<=0 and T<=0 or S<=0 and T>=0:
        print("Yes")

    if T<=0 and S>0:
         print("No")
    




Measured memory_bytes: 61792
import java.io.*;
import java.util.ArrayList;

public class Main {
	public static void main(String[] a){

		ArrayList<Integer> inputs = new ArrayList<Integer>(); 
		String line;

		try {
			int count=0;
				BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
				while ((line = br.readLine()) != null&&line.length()>0) {
						inputs.add(Integer.parseInt(line));
					count++;
					if (count>9) {
						break;
					}
				}
		} catch (Exception e) {
		}
		int sub = 0;
		for(int k=0;k<inputs.size()-1;k++){
			for (int i = k+1; i < inputs.size(); i++) {
				try{
					int num1 = inputs.get(k);
					int num2 = inputs.get(i);
					if (num1<num2) {
						sub = num2;
						inputs.set(i,num1);
						inputs.set(k, sub);
					}
				}catch(Exception e){
				}
			}
		}
		for (int i = 0; i < 3; i++) {
			if(i<inputs.size()){
				System.out.println(inputs.get(i));
			}
		}
	}
}

Measured memory_bytes: 9356
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

constexpr int MOD_TYPE = 2;
constexpr ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
constexpr int INF = (int)1e9;
constexpr ll LINF = (ll)4e18;
constexpr ld PI = acos(-1.0);
constexpr ld EPS = 1e-11;
constexpr int Dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
constexpr int Dy[] = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

#pragma endregion

template <typename T = ll, typename U = ll>
struct dijkstra
{
  U init;
  dijkstra(U init_ = LINF) : init(init_) {}
  struct edge
  {
    T to;
    U cost;
  };

  using P = pair<U, T>;
  map<T, vector<edge>> E;
  map<T, U> d;

  void add_E(T a, T b, U c = 1, bool directed = true)
  {
    E[a].emplace_back(edge{b, c});
    if (!directed)
      E[b].emplace_back(edge{a, c});
  }

  void calc(T s)
  {
    priority_queue<P, vector<P>, greater<P>> que;
    que.emplace(U(0), s);
    d[s] = U(0);
    while (!que.empty())
    {
      P p = que.top();
      que.pop();
      T v = p.second;
      if (d[v] < p.first)
        continue;
      for (auto e : E[v])
      {
        if (!d.count(e.to))
          d[e.to] = init;
        if (d[e.to] > d[v] + e.cost)
        {
          d[e.to] = d[v] + e.cost;
          que.emplace(d[e.to], e.to);
        }
      }
    }
  }

  U dist(T v)
  {
    return d.count(v) ? d[v] : init;
  }
};

void solve()
{
  int n, m;
  cin >> n >> m;
  dijkstra<pii, int> ds(INF);
  rep(i, m)
  {
    int p, q, c;
    cin >> p >> q >> c;
    p--, q--;
    ds.add_E(MP(p, c), MP(q, c), 0, false);
    ds.add_E(MP(p, -1), MP(p, c), 1);
    ds.add_E(MP(q, -1), MP(q, c), 1);
    ds.add_E(MP(p, c), MP(p, -1), 0);
    ds.add_E(MP(q, c), MP(q, -1), 0);
  }
  ds.calc(MP(0, -1));
  int d = ds.dist(MP(n - 1, -1));
  cout << (d == INF ? -1 : d) << endl;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);
  solve();
  return 0;
}


Measured memory_bytes: 92336
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int q = scanner.nextInt();
    for (int i = 0; i < q; i++) {
      long a = scanner.nextLong();
      long b = scanner.nextLong();
      System.out.println(solve(a, b));
    }
  }

  private static long solve(long a, long b) {
    if (a > b) return solve(b, a);

    long ab = a * b;
    long i = findUpperRoot(ab);
    if (i == 0) return 0;
    long j = (ab - 1) / i;

    long res = i * 2;
    if (i == j) res--;
    if (i >= a) res--;

    return res;
  }

  private static long findUpperRoot(long n) {
    long ll = 0;
    long ul = (long) Math.sqrt(n) + 1;
    while (ll + 1 < ul) {
      long mid = (ll + ul) / 2;
      if (mid * mid < n) {
        ll = mid;
      } else {
        ul = mid;
      }
    }
    return ll;
  }
}


Measured memory_bytes: 21204
import sys
input = sys.stdin.readline
import numpy as np
def print_ans(r, D, x):
    """Test Case
    >>> print_ans(2, 10, 20)
    30
    50
    90
    170
    330
    650
    1290
    2570
    5130
    10250
    >>> print_ans(4, 40, 60)
    200
    760
    3000
    11960
    47800
    191160
    764600
    3058360
    12233400
    48933560
    """
    for _ in range(10):
        x = r * x - D
        print(x)

if __name__ == '__main__':
    r, D, x = map(int, input().rstrip().split())
    print_ans(r, D, x)




Measured memory_bytes: 22304
#include <iostream>
#include <vector>
#include<algorithm>
#include <string>
#include <cmath>
#include<map>
#define PI 3.141592653589793238
#define INF -1
#define ll long long
using namespace std;

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

	if (n % 2 == 0) {
		printf("%d", n / 2);
	} else {
		printf("%d", n / 2 + 1);
	}
	
	return 0;
}

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

int main()
{
    long long int n,i;
    cin>>n;
    vector<long long int> v;
    for(i=0;i<n;i++)
    {
        long long int y;
        cin>>y;
        v.push_back(y);
    }

    long long int t=1;
    for(i=n-2;i>=0;i--)
    {
        if(v[i]-v[i+1]>1)
        {
            t=0;
            break;
        }
        else if(v[i]-v[i+1]==1)
        {
            v[i]=v[i+1];
        }
    }

    if(t)
        cout<<"Yes";
    else
        cout<<"No";

}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
const long long INF = 1LL<<60; // 仮想的な無限大の値;
using namespace std;
using ll = long long;
using P  = pair<int, int>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
int main()
{
    string s;
    cin >> s;
    int N = s.size();
    vector<ll> h(N, 1);
 //   rep(i, N) cout << h[i]  <<" " ;
//    cout << endl;
    
    ll x = -1;
    ll r = 0;
    ll l = 0;
    rep(i, N)
    {
      if(s[i] == 'R')
      {
        if(x >= 0)
        {
            int d = l+r;
            h[x] = d/2+d%2;
            h[x+1] = d/2;
            if((i-x)%2 == 0)
            {
                swap(h[x], h[x+1]);
            }
            x = -1;
            l = 0;
            r = 0;
        }
        h[i] = 0;
        ++r;  
      }
      if(s[i] == 'L')
      {
        if(i>=1 && s[i-1] == 'R') x = i-1;
        h[i] = 0;
        ++l;
      }
    }
    if(x >= 0)
    {
        int i = N-2;
        int d = l+r;
        h[x] = d/2+d%2;
        h[x+1] = d/2;
        if((i-x)%2 == 0)
            {
                swap(h[x], h[x+1]);
            }
    }
    rep(i, N) cout << h[i]  <<" " ;
    cout << endl;
    return 0;
}

Measured memory_bytes: 4308
#include<iostream>
#include<cstdio>
#include<math.h>
#include<string>
#include<algorithm>
#include<functional>
#include<vector>
#include<set>
#include<map>
#define INF 1000000000000000
#define EPS 1.0e-6

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

int n, m, r;
int city[9];
ll d[210][210];

void warshall_floyd()
{
	for (int k = 0; k < n; k++) {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if (i != j) {
					if (d[i][j] > d[i][k] + d[k][j]) {
						d[i][j] = d[i][k] + d[k][j];
					}
				}
		
			}
		}
	}

}

int main()
{

	cin >> n >> m >> r;
	int cityi;
	for (int i = 0; i < r; i++) {
		cin >> cityi;
		cityi--;
		city[i] = cityi;
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (i != j)d[i][j] = INF;
			else d[i][j] = 0;
		}
	}
	for (int i = 0; i < m; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		d[a][b] = c;
		d[b][a] = c;
	}
	warshall_floyd();
/*
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			printf("d[%d][%d]:%d\n", i+1, j+1, d[i][j]);
		}
	}
*/


	sort(city, city + r);
	
	ll cur_0 = 0;
	for (int i = 1; i < r; i++) {
		cur_0 += d[city[i - 1]][city[i]];
	}
	ll ans = cur_0;

	while (next_permutation(city, city + r)) {
		ll cur = 0;
		
		for (int i = 1; i < r; i++) {
			
		//	printf("city[%d]:%d,city[%d]:%d\n", i - 1, city[i - 1], i, city[i]);
			
			cur += d[city[i - 1]][city[i]];
		}
		if (cur<ans)ans = cur;

	}
	cout << ans << endl;

	return 0;
}

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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  int N, T; scanf("%d %d", &N, &T);
  vector<int> A(N);
  for (int i = 0; i < N; ++i) {
    scanf("%d", &A[i]);
  }
  int least = INF;
  int most_profit = 0;
  vector<int> P(N);
  for (int i = 0; i < N; ++i) {
    least = min(least, A[i]);
    P[i] = A[i] - least;
    most_profit = max(most_profit, P[i]);
  }
  int ans = count(P.begin(), P.end(), most_profit);
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 1024
N = int(input())
arr = []
for i in range(2, int(-(-N**0.5//1))+1):
  if N == 1:
    break
  if N % i == 0:
    cnt = 0
    while N % i == 0:
      cnt += 1
      N = int(N / i)
    arr.append([i, cnt])

if N != 1:
  arr.append([N, 1])

n = 0
for p, e in arr:
  temp = e
  j = 0
  while temp > 0:
    j += 1
    temp = temp - j
    if temp < 0:
      break
    n += 1

print(n)
    


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

const int MOD = 1000000007;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define copy(from, to) copy(from.begin(), from.end(), back_inserter(to))
#define sort(a) sort(a.begin(), a.end())
#define reverse(s) reverse(s.begin(), s.end())
#define p(s) cout << (s) << endl

typedef long long ll;
using namespace std;

template<class T>
void load(vector<T> &v, int n) {
  for (int i = 0; i < n; ++i) {
    T t;
    cin >> t;
    v.push_back(t);
  }
}

template<class T>
T max(vector<T> &v) {
  return *max_element(v.begin(), v.end());
}

template<class T>
T min(vector<T> &v) {
  return *min_element(v.begin(), v.end());
}

void py(bool isUpper = false) {
  if (isUpper) {
    p("YES");
  } else {
    p("Yes");
  }
}

void pn(bool isUpper = false) {
  if (isUpper) {
    p("NO");
  } else {
    p("No");
  }
}

int main() {
  string str;
  cin >> str;

  int n = false, w = false, s = false, e = false;
  for (int i = 0; i < str.length(); ++i) {
    if (str[i] == 'N') n = true;
    if (str[i] == 'W') w = true;
    if (str[i] == 'S') s = true;
    if (str[i] == 'E') e = true;
  }

  if (n == !s || s == !n || w == !e || e == !w) {
    pn();
  } else {
    py();
  }
}

Measured memory_bytes: 256
def warshal_floyd(weights,N):
    d=weights
    for i in range(N):
        d[i][i]=0
    for k in range(N):
        for i in range(N):
            for j in range(N):
                d[i][j]=min(d[i][j],d[i][k]+d[k][j])
    return d

if __name__ == '__main__':
    H,W=list(map(int,input().split()))
    weights=[[None for i in range(10)] for j in range(10)]
    for i in range(10):
        Cs = list(map(int, input().split()))
        for j in range(10):
            weights[i][j]=Cs[j]
    wall=[]

    for i in range(H):
        temp=list(map(int,input().split()))
        wall.append(temp)

    paths=warshal_floyd(weights,10)
    cost=0

    for row in wall:
        for a in row:
            if a==-1:
                continue
            else:
                cost+=paths[a][1]
    print(cost)


Measured memory_bytes: 40284
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
const ll INF = 1e18;
#define print(x) cout << (x) << endl;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    long long sum = 0;
    for (long long i = 0; i < (1 << S.size() - 1); i++) {
        string preS = S;
        long long cutLong = S.size() - 1;
        long long preCut = 0;
        for (long long j = 0; j <= cutLong; j++) {
            // print(i);
            // print(j);
            if ((i >> j) & 1 || j == cutLong) {
                preCut = j;
                string fragment = preS.substr(cutLong - preCut);
                preS = preS.substr(0, cutLong - preCut);
                // cout << "preS:" << preS << endl;
                // cout << "fragment:" << fragment << endl;
                sum += stoll(fragment);
            }
            // print(":::::");
        }
        // cout << "////" << endl;
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
# def div(n):
#     ans = []
#     for i in range(1,int(n**(1/2)+2)):
#         if n%i == 0:
#             ans.append(i)
#             ans.append(n//i)
#     ans = set(ans)
#     return ans

k = int(input())
# print(div(k))
a = 7
if k % 2 == 0:
    print(-1)
    exit()
for i in range(1,10**8+2):
    if a%k == 0:
        print(i)
        exit()
    a=a*10+7
    a=a%k
print(-1)
# print(div(k))


Measured memory_bytes: 63176
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define PRINTALL(V)                                                            \
  for (auto v : (V)) {                                                         \
    cout << v << " ";                                                          \
  }                                                                            \
  cout << "\n";
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
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 (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template < class T > using vec = std::vector< T >;
template < class T > void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF = 1061109567;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
vec< vec< int > > graph;
vec< int > label;
void dfs(int id, int num) {
  label[id] = num;
  FORA(e, graph[id]) {
    if (label[e] == -1)
      dfs(e, num);
  }
  return;
}
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int N, M;
  cin >> N >> M;
  vec< int > p(N);
  REP(i, N) {
    cin >> p[i];
    p[i]--;
  }
  graph.resize(N, vec< int >());
  REP(i, M) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    graph[x].pb(y);
    graph[y].pb(x);
  }
  label.assign(N, -1);
  int count = 0;
  REP(i, N) {
    if (label[i] == -1) {
      dfs(i, count);
      count++;
    }
  }
  int ans = 0;
  REP(i, N) {
    if (label[i] == label[p[i]]) {
      ans++;
    }
  }
  print(ans);
}

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

using namespace std;

long long gcd(long long m,long long n){
	long long r;
	if(m<n){
		r = m;
		m = n;
		n = r;
	}
	r = m%n;
	while(r!=0){
		m = n;
		n = r;
		r = m%n;
	}
	return n;
}
long long lcm(long long a, long long b){
	return (a/gcd(a,b))*b;
}

int main(){
	int i,n;
	long long ans;
	long long T[110];
	cin >> n;
	for(i=0;i<n;i++){
		cin >> T[i];
	}
	ans = 1;
	for(i=0;i<n;i++){
		ans = lcm(T[i],ans);
	}
	cout << ans << endl;
}
	

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

#define int long long

using namespace std;

int d[101];
int ans, n;
map <pair <string, string>, int> used;
char a[1001];

void go (int v) {
	if (v > n) {
		string s1 = "";
		string s2 = "";
		for (int i = 1;i <= n;i ++) {
			if (d[i] == 0) s1 += a[i];
			else s2 += a[i];
		}
		used[make_pair (s1, s2)] ++;
		return;
	}
	d[v] = 0;
	go (v + 1);
	d[v] = 1;
	go (v + 1);
}

void go1 (int v) {
	if (v > n + n) {
		string s1 = "";
		string s2 = "";
		for (int i = n + 1;i <= n + n;i ++) {
			if (d[i] == 0) s1 += a[i];
			else s2 += a[i];
		}
		reverse (s1.begin (), s1.end ());
		reverse (s2.begin (), s2.end ());
		ans += used[make_pair (s2, s1)];
		return;
	}
	d[v] = 0;
	go1 (v + 1);
	d[v] = 1;
	go1 (v + 1);
}
		
 main () {
	cin >> n;
	for (int i = 1;i <= n + n;i ++) {
		cin >> a[i];
	}
	go (1);
	go1 (n + 1);
	cout << ans;   
	return 0;
}

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

#define int long long
#define pii pair<int,int>
#define vi vector<int>
#define pb push_back
#define ff first
#define ss second
#define init(a, x) memset(a, x, sizeof(a))
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

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

	int res = 0;
	int temp = 0;
	for (int i = 0; i < s.size(); ++i)
	{
		if (s[i] == 'R'){
			temp += 1;
		}
		else{
			res = max(temp, res);
			temp = 0;
		}

	}
	res = max(temp, res);
	cout << res << endl;
	
	return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    long long n;
    cin >> n;
    string ans = "";
    for(int i = 1; i < 100; i++){
        if(n <= pow(26,i)){
            n--;
            for(int j = 0; j < i; j++){
                ans += char('a'+ n % 26);
                n /= 26;
            }
            break;
        }else{
            n -= pow(26,i);
        }
    }
    reverse(ans.begin(),ans.end());
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4036
fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(' ').map { it.toInt() }
    val graph = Array(n + 1) { BooleanArray(n + 1) { false } }
    repeat(m) {
        val (a, b) = readLine()!!.split(' ').map { it.toInt() }
        graph[a][b] = true
        graph[b][a] = true
    }

    fun dfs(u: Int, i: Int, visited: BooleanArray): Int {

        visited[u] = true

        if (i == n) {
            return if (visited.all { it }) 1 else 0
        }

        return (1..n)
                .filter { !visited[it] && graph[u][it] }
                .map { dfs(it, i + 1 ,visited.clone()) }
                .sum()
    }

    val visited = BooleanArray(n + 1) { false }
    visited[0] = true

    println(dfs(1, 1, visited))
}


Measured memory_bytes: 42940
using System;
using System.Linq;

namespace ITP1_10_C
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                int n = int.Parse(Console.ReadLine());
                if (n == 0)
                    break;
                var points = Console.ReadLine().Split(' ').Select(s => int.Parse(s));
                double average = points.Average();
                double variance = points.Select(p => (p - average) * (p - average)).Sum() / n;
                Console.WriteLine(Math.Sqrt(variance));
            }
        }
    }
}

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

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) 
using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;

const ld PI = 3.14159265359;

const ll MOD = (ll) 1e9 + 7;
const ll MAXN = (ll) 3e5 + 10;
const ll INF = (ll) 2242545357980376863;
const ld EPS = (ld) 1e-8;
const ll LOG = (ll) 30;



int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n;
	cin >> n;
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	
	str s;
	cin >> s;
	s = '!' + s + '!';
	if(c < d){
		for(int i = b; i + 1 <= d; i++) if(s[i] == '#' && s[i + 1] == '#') return cout << "No", 0;
		for(int i = a; i + 1 <= c; i++) if(s[i] == '#' && s[i + 1] == '#') return cout << "No", 0;
		cout << "Yes";
	} else {
		for(int i = b; i + 1 <= d; i++) if(s[i] == '#' && s[i + 1] == '#') return cout << "No", 0;
		for(int i = a; i + 1 <= c; i++) if(s[i] == '#' && s[i + 1] == '#') return cout << "No", 0;
		ll fl = 0;
		for(int i = b; i <= d; i++){
			if(s[i] != '.') continue;
			if(s[i - 1] != '.') continue;
			if(s[i + 1] != '.') continue;
			fl = 1;
		}
		if(fl) cout << "Yes";
		else cout << "No";
	}
	return 0;
}

/*

                                 ____              ,----..               ,----..
   ,---,                       ,'  , `.           /   /   \             /   /   \
  '  .' \                   ,-+-,.' _ |          /   .     :           /   .     :
 /  ;    '.              ,-+-. ;   , ||         .   /   ;.  \         .   /   ;.  \
:  :       \            ,--.'|'   |  ;|        .   ;   /  ` ;        .   ;   /  ` ;
:  |   /\   \          |   |  ,', |  ':        ;   |  ; \ ; |        ;   |  ; \ ; |
|  :  ' ;.   :         |   | /  | |  ||        |   :  | ; | '        |   :  | ; | '
|  |  ;/  \   \        '   | :  | :  |,        .   |  ' ' ' :        .   |  ' ' ' :
'  :  | \  \ ,'        ;   . |  ; |--'         '   ;  \; /  |        '   ;  \; /  |
|  |  '  '--'          |   : |  | ,             \   \  ',  /          \   \  ',  /
|  :  :                |   : '  |/               ;   :    /            ;   :    /
|  | ,'                ;   | |`-'                 \   \ .'              \   \ .'
`--''                  |   ;/                      `---`                 `---`
                       '---'

*/


Measured memory_bytes: 764