akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>	
#include <deque>
#include <set>
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define fore(i,a) for(auto &i:a)
#define INF INT_MAX/2;
const int INF2 = 1001001001;
typedef long long ll;
using namespace std;
using vi = vector<int>;
using vll = vector<ll>;
ll mod = 1e9 + 7;
//ll llmax = 10000000000000000000ll;
using namespace std;
using Graph = vector<vector<int>>;


int cnt_digit(ll N)
{
	int digit = 0;

	while (N > 0)
	{
		N /= 10;
		digit++;
	}
	return digit;
}


 // 最大公約数計算
 
ll gcd(ll a, ll b)
{
	if (b == 0) {
		return a;
	}
	else {
		return gcd(b, a % b);
	}
}
// 最小公倍数の計算

ll lcm(ll a, ll b)
{
	ll g = gcd(a, b);

	return a / g * b;
}

struct union_find
{
	vector<int> par, r;
	union_find(int n)
	{
		par.resize(n);
		r.resize(n);
		init(n);
	}


	void init(int n)
	{
		for (int i = 0; i < n; i++) par[i] = i;
		for (int i = 0; i < n; i++) r[i] = 0;
	}

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

	void unite(int x, int y)
	{
		x = find(x);
		y = find(y);

		if (r[x] < r[y])
		{
			par[x] = y;
		}
		else
		{
			par[y] = x;
			if (r[x] == r[y])
			{
				r[x]++;
			}
		}
	}
};

const int MAX_N = 110000;

int memo[MAX_N];

int rec(int n) {
	if (n == 0)return 0;
	if (memo[n] != -1)return memo[n];

	int res = n;

	for (int pow6 = 1; pow6 <= n; pow6 *= 6)res = min(res, rec(n - pow6) + 1);

	for (int pow9 = 1; pow9 <= n; pow9 *= 9)res = min(res, rec(n - pow9) + 1);

	return memo[n] = res;
}

int calc(int x) {
	int ret = 0;
	while (x % 2 == 0) {
		x /= 2;
		ret++;
	}

	return ret;
}

int a[12][12];
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,k;

	cin >> n >> k;
	vector<int> data(n);
	rep(i, 0, n) {
		cin >> data[i];
	}

	int res = 0;
	int length = 0;

	while (length < n) {
		if (length == 0) {

			length += k;
			res++;
		}
		else {
			length += k - 1;
			res++;
		}

	}


	
		cout << res << endl;
	



}
	


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
#define vector2(a,b,c) vector<vector<int>> a(b/*縦！w*/,vector<int>(c/*横！w*/))
#define INF 1e10
#define MOD 1e9+7
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; }
using Graph = vector<vector<int>>;
signed main(){
  int a,b,c;
  cin>>a>>b>>c;
  if((a==b&&b!=c)||(c==b&&b!=a)||(a==c&&b!=c))
  cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}

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

using namespace std;

//////////////////////////////////////////////////
class SegmentTree
{
public:
    typedef long long Int;
    static const Int DEFAULT_VALUE = 1LL << 60; 
    vector<Int> data;
    Int N;

    inline Int func(Int x, Int y) {
        return min(x, y);
    }

    inline void updateLeaf(Int v, Int val) {
        data[v] = val;
    }

    SegmentTree(vector<Int> vec) {
        Int x = 1;
        while (x < (Int)vec.size()) {
            x *= 2;
        }

        this->N = x;
        data = vector<Int>(2 * x, DEFAULT_VALUE);
        for (int i = 0; i < (Int)vec.size(); i++) {
            update(i, vec[i]);
        }
    }

    Int get(Int l, Int r) {
        return getSub(l, r, 0, N, 1);
    }

    void update(Int index, Int val) {
        Int v = index + N;
        updateLeaf(v, val);

        v /= 2;
        while (v > 0) {
            data[v] = func(data[2 * v], data[2 * v + 1]);
            v /= 2;
        }
    }

    Int getSub(Int l, Int r, Int myl, Int myr, Int v) {
        if (myr <= l || r <= myl) return DEFAULT_VALUE;
        if (l <= myl && myr <= r) return data[v];

        Int mid = (myl + myr) / 2;
        return func(getSub(l, r, myl, mid, 2 * v),
                   getSub(l, r, mid, myr, 2 * v + 1));
    }
};
//////////////////////////////////////////////////

int main() {
    int n, q;
    cin >> n >> q;
    SegmentTree seg(vector<long long>(n, (1LL << 31) - 1));
    for (int i = 0; i < q; i++) {
        int c, x, y;
        cin >> c >> x >> y;
        if (c == 0) {
            seg.update(x, y);
        } else {
            cout << seg.get(x, y + 1) << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 6020
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <cstdio>
#include <numeric>
#include <iomanip>

using namespace std;

using ll = long long;

int main()
{
    ll a;
    cin >> a;
    cout << a + a*a + a*a*a << endl;

    return 0;
}

Measured memory_bytes: 3192
n, W = map(int, input().split())
l = [list(map(int, input().split())) for i in range(n)]
w, v = [list(i) for i in zip(*l)]
dp = [[0] * (W+1) for i in range(n+1)]
for i in range(1, n+1):
    for j in range(W+1):
        if j - w[i-1] >= 0:
            dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i-1]]+v[i-1])
        else:
            dp[i][j] = dp[i-1][j]
print(dp[n][W])


Measured memory_bytes: 150284
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, T;
    cin >> n >> T;
    vi c(n), t(n);
    int mn = INF;
    rep(i,n){
        cin >> c[i] >> t[i];
        if(t[i] <= T){
            cmn(mn,c[i]);
        }
    }
    if(mn == INF){
        cout << "TLE\n";
    }else{
        cout << mn << "\n";
    }
    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
cnt_list = [0 for _ in range(N+1)]

for i in range(N):
    cnt_list[A[i]] += 1

ans_list1 = []
ans_list2 = []

for i in cnt_list:
    if i < 2:
        ans_list1.append(0)
        ans_list2.append(0)
    elif i == 2:
        ans_list1.append(1)
        ans_list2.append(0)
    else:
        ans_list1.append(i*(i-1)//2)
        ans_list2.append((i-1)*(i-2)//2)

SUM = sum(ans_list1)

for i in A:
    print(SUM - ans_list1[i] + ans_list2[i])

Measured memory_bytes: 26140
c = [list(map(int, input().split())) for i in range(3)]

right = c[0][1] + c[1][0] == c[0][0] + c[1][1] \
    and c[1][2] + c[2][1] == c[1][1] + c[2][2] \
    and c[2][0] + c[0][2] == c[2][2] + c[0][0]
print('Yes' if right else 'No')


Measured memory_bytes: 3060
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
using namespace std;
typedef long long LL;
const int MaxN = 1e5;
const int Inf = 1 << 30;
const LL mod = 1e9 + 7;

int main()
{
	int a,b;
	while(~scanf("%d%d",&a,&b)){
		printf("%d\n",(a + b) % 24);
	}
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
#define mp make_pair
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
const ll INF=1LL<<30;
const ll LINF=1LL<<60;
const double eps=1e-5;
const ll MOD=1000000007LL;
template<typename T>void chmin(T &a,T b){a=min(a,b);};
template<typename T>void chmax(T &a,T b){a=max(a,b);};
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int n;
int dp[3010],a[3010];
vector<int> G[3010];
void dfs(int i,int p){
	if(G[i].size()==1&&p!=-1){
		dp[i]=-1;
		return;
	}
	dp[i]=0;
	for(auto e:G[i]){
		if(e==p)continue;
		dfs(e,i);
		if(dp[e]<=0&&a[i]>a[e])dp[i]=1;
	}
}
int main(){
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<n-1;i++){
		int u,v;cin>>u>>v;--u;--v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	vector<int> ans;
	for(int i=0;i<n;i++){
		dfs(i,-1);
		if(dp[i]>0){
			ans.push_back(i+1);
		}
		cout<<endl;
	}
	for(auto e:ans)cout<<e<<" ";
	cout<<endl;
    return 0;
}


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

const ll INF=1e18;
int main() {
	int n,k;
	cin >> n >> k;
	vector<int> p(n),c(n);
	rep(i,n) {
		cin >> p[i];
		p[i]--;
	}
	rep(i,n) cin >> c[i];

	ll ans = -INF;
	// 周期はp[i] をスキャンして決める.n とは限らない.
	// si を開始位置とする
	rep(si,n) {
		// 周期を求める
		vector<ll> s; // めぐった先だけのスコア
		ll tot = 0;
		int x = si;
		while(1) {
			x = p[x];
			s.push_back(c[x]);
			tot += c[x];
			if(x == si) break;
		}
		// 周期l
		int l = s.size();
		// 周期の中でどこで切るかを全部試す。
		ll t = 0;
		rep(i,l) {
			t += s[i];
			if(i+1 > k) break;
			ll now = t;
			if(tot > 0) {
				ll e = (k - (i+1))/l;
				now += tot*e;
			}
			ans = max(ans, now);
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3768
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <complex>
#include <vector>
#include<limits>
#include<iomanip>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const long double pi = 3.141592653589793;

#define debug(x) cout << #x << " = " << (x) << endl;
#define rep(i, n) for(int i = 0;i < n;i++)
#define repi(i, j, n) for(int i = j;i < n;i++)
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define F first
#define S second

// #define COMMENT

/*

const int NN = 200090;
ll fact[NN];
ll finv[NN];
ll inv[NN];

void inverse_modulao() {
  fact[0] = fact[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;

  for(int i = 2;i < NN;i++) {
    fact[i] = fact[i-1]*i%mod;
    inv[i] = mod-mod/i*inv[mod%i]%mod;
    finv[i] = finv[i-1]*inv[i]%mod;
  }
}

ll nCr(int n, int r) {
  return fact[n]*finv[r]%mod*finv[n-r]%mod;
}

*/

int A[4000];
int main() {

//  freopen("input.in","r",stdin);
//  freopen("output.out","w",stdout);

  string s;

  cin >> s;
  reverse(s.begin(), s.end());
  int m = 2019, cum = 0, mul = 1;
  for(int i = 0;i < s.size();i++) {
    cum = (cum + (s[i]-'0')*mul)%m;
    A[cum]++;
    mul = (mul*10)%m;
  }

  ll ans = 0;
  repi(i, 0, 2019) ans += A[i]*(A[i]-1)/2;
  cout<<ans+A[0];

  return 0;
}


Measured memory_bytes: 3692
#include <iostream>
using namespace std;
 
int main() {
  int a, b;
  cin >> a >> b;
  if(a >= 13){
    cout << b;
  }else if(a <= 12 && a >= 6){
    cout << b / 2;
  }else{
    cout << 0;
  }
  return 0;
}

Measured memory_bytes: 256
#include <climits>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int N, M, X;
  cin >> N >> M >> X;
  int C[N], A[N][M];
  for (int i = 0; i < N; i++) {
    cin >> C[i];
    for (int j = 0; j < M; j++) {
      cin >> A[i][j];
    }
  }

  int result = INT_MAX;
  for (int mask = 0; mask < (1 << N); mask++) {
    int c = 0;
    vector<int> a(M);
    for (int i = 0; i < N; i++) {
      if (mask & (1 << i)) {
        c += C[i];
        for (int j = 0; j < M; j++) {
          a[j] += A[i][j];
        }
      }
    }

    bool x = true;
    for (int i = 0; i < M; i++) {
      if (a[i] < X) {
        x = false;
      }
    }
    if (x) {
      result = min(result, c);
    }
  }

  if (result != INT_MAX) {
    cout << result << endl;
  } else {
    cout << -1 << endl;
  }

  return 0;
}

Measured memory_bytes: 3632
import bisect, copy, heapq, math, 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))
def celi(a,b):
    return -(-a//b)
sys.setrecursionlimit(5000000)
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,k=map(int,input().split())
p=list(map(int,input().split()))
c=list(map(int,input().split()))

dic_s={}
dic_i={}

for i in range(1,n+1):
    if not i in dic_i:
        dic_s[i]=0
        j=i
        while not j in dic_i:
            dic_i[j]=1
            j=p[j-1]
            dic_s[i]+=1

ans=-float('inf')
for i in dic_s.keys():
    lst_c=[]
    # print(i)
    for j in range(dic_s[i]):
        i=p[i-1]
        lst_c.append(c[i-1])
    # print(lst_p)
    # print(lst_c)
    # print(i)
    sm=sum(lst_c)
    lst=lst_c+lst_c+lst_c
    if sm>0:
        cnt2=-float('inf')
        if k//dic_s[i]>=2:
            for j in range(dic_s[i]):
                tmp=0
                for l in range(k%dic_s[i]+dic_s[i]):
                    tmp+=lst[j+l]
                    cnt2=max(cnt2,tmp)
        ans=max(ans,sm*(k//dic_s[i]-1)+cnt2)
        cnt2=-float('inf')
        for j in range(dic_s[i]):
            tmp=0
            for l in range(k%dic_s[i]):
                tmp+=lst[j+l]
                cnt2=max(cnt2,tmp)
        ans=max(ans,sm*(k//dic_s[i])+cnt2)

    # else:
        # lst=lst_c+lst_c
    cnt2=-float('inf')
    for j in range(dic_s[i]):
        tmp=0
        for l in range(min(k,dic_s[i])):
            tmp+=lst[j+l]
            cnt2=max(cnt2,tmp)
        # print(cnt2)
    ans=max(ans,cnt2)

print(ans)

Measured memory_bytes: 70272
// Author: Jashan Bansal
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second   
#define mp make_pair
#define int long long
#define ll long long
#define pii pair<int,int>
#define all(arr) arr.begin(), arr.end()
#define sz(arr) ((long long)arr.size())
#define sp(n) setprecision(n)
// const int mod=998244353;
const int mod=1000000007;
typedef vector<int> vi;
#define log1(x) cout << x << '\n'
#define log2(x,y) cout << x << " " << y <<'\n'
#define log3(x,y,z) cout << x <<" " << y <<" " << z << '\n'
#define logarr(arr,n) for(int __=0; __ < n; __++)   cout << arr[__] << " "; cout << '\n'

int powm(int a, int b) {
    int res=1;
    while(b) {
        if(b&1)
            res=(res*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}



void solve(){
    int n;
    cin >> n;
    double arr[n+1];
    double dp[n+1][n+1];
    double ans = 0;
    for(int i=1; i<=n; i++){
        cin >> arr[i];
    } 


    for(int i=0; i<=n; i++){
        for(int j=0; j<=n; j++){
            dp[i][j] = 0;
        }
    }

    dp[1][0] = 1 - arr[1]; 
    for(int i=2; i<=n; i++){
        dp[i][0] = (1 - arr[i])* dp[i-1][0]; 
    }


    dp[1][1] = arr[1]; 
    for(int i=2; i<=n; i++){
        dp[i][i] = (arr[i])* dp[i-1][i-1]; 
    }

    for(int i=1; i<=n; i++){
        for(int j=1; j<i; j++){
            dp[i][j] = dp[i-1][j]*(1-arr[i]) + dp[i-1][j-1] * (arr[i]);
        }
    }


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

    cout << fixed << setprecision(10) << ans;
}

signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--)
        solve();
    return 0;
}   



Measured memory_bytes: 70656
#include <iostream>
#include <algorithm>
#include <iomanip>
using namespace std;
string alphabet = "abcdefghijklmnopqrstuvwxyz";
string ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main(){
int a , b;
cin >> a >> b;
if(a == 1)a += 13;
if(b == 1)b += 13;
if(a == b)cout << "Draw" << endl;
else if(a > b)cout << "Alice" << endl;
else cout << "Bob" << endl;
}

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

using namespace std;

using i64 = int64_t;

const i64 MOD = 1e9+7;

const i64 INF = 1e18+7;


signed main(){
    int a, b, c, d, n, x, y;
    string s, t;


    auto Yes = [&](bool t){
        cout << (t ? "Yes" : "No") << endl;
    };
    auto YES = [&](bool t){
        cout << (t ? "YES" : "NO") << endl;
    };
    auto tri = [&](bool t, string a, string b){
        cout << (t ? a : b) << endl;
    };

    cin >> a >> b;
    Yes((a * b) & 1);
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
#include <stdio.h>
#include <algorithm>
#include <string>
/********
*   ?????¢??¢?´¢ Linear Search
*********/ 

/*
int linearSearch(int strS int strT, int n )
{
	int key;
	
	for(int i =0 ; i < n; i++){
		if(strS[i] == key){
			return i;
		}
	}
	return NOT_FOUND;
}
*/

int main(void)
{
	int n , q;
	int strS[10000]={0} ;
	int strT[500]={0} ;
	int count = 0 ;
	
	cin >> n;	
	for(int i = 0; i<n; i++){
		cin >> strS[i];
	}
	
	cin >> q;
	for(int i = 0; i<n; i++){
		cin >> strT[i];
	}
	
	for(int j = 0; j<q ; j++){
		for(int i =0; i < n; i++){
			if(strT[j] == strS[i]){
				count++;
				break;
			}
		}
	}
	cout << count << endl;
	
    return 0;
}

Measured memory_bytes: 1208
n = int(input())
i = 0
sortedSet = {}
while i < n:
    temp = ''.join(sorted(input()))

    if temp in sortedSet:
        sortedSet[temp]+=1
    else:
        sortedSet[temp]=1
    i += 1

result = 0
for v in sortedSet.values():
    result = int(result + v*(v-1)/2)

print(result)

Measured memory_bytes: 17852
S = list(input())
f1 = f2 = f3 = False
if S[0] == 'A':
    f1 = True
    del S[0]
if S[1:-1].count('C') == 1:
    f2 = True
    del S[S[1:-1].index('C')+1]
if ''.join(S).islower():
    f3 = True

if f1 and f2 and f3:
    print('AC')
else:
    print('WA')

Measured memory_bytes: 3060
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <complex>
#include <cstdint>
#include <tuple>
#include <numeric>
#define M_PI       3.14159265358979323846


using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FILL(a, x) memset(a, x, sizeof(a))

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

int a[100005];

int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	REP(i, n)scanf("%d", &a[i]);
	priority_queue<PII, vector<PII>, greater<PII>> q;
	REP(i, n) q.push(MP(a[i], 1));
	REP(i, m) {
		int b, c;
		scanf("%d%d", &b, &c);

		int cnt = 0;
		while (b != 0) {
			auto tmp = q.top();
			if (tmp.first > c) break;
			int d  = min(b, tmp.second);
			cnt += d;
			tmp.second -= d;
			b -= d;
			q.pop();
			if (tmp.second != 0)q.push(tmp);
		}
		if (cnt != 0) {
			q.push(MP(c, cnt));
		}
	}
	LL ret = 0;
	while (!q.empty()) {
		auto tmp = q.top();
		q.pop();
		ret += ((LL)tmp.first)*tmp.second;
	}
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 1784
/*input
1
*/
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
#define ll          long long
#define pb          push_back
#define pii         pair<long,long>
#define vi          vector<long long>
#define vii         vector<pii>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define mod         998244353
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define repi(i,a,b) for(ll i=a;i>=b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define fIO         ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define tr(it, a)   for(auto it = a.begin(); it != a.end(); it++)
#define clr(x)      memset(x, 0, sizeof(x))
#define debug(x)      cerr << #x << "=" << x << endl
#define debug2(x, y)  cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define TIME        cerr << "\nTime elapsed: "<<1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; 
//#define ordered_set tree<ll,null_type,less<ll>,rb_tree_tag, tree_order_statistics_node_update>;

ll sub(ll a, ll b){return (a-b+hell)%hell;}
ll add(ll a, ll b){return (a+b)%hell;}
ll mul(ll a, ll b){return (a*b)%hell;}
/*vector<ll>adj[100005];
bool vis[100005];
ll siz,edges;
void dfs(ll i)
{
    vis[i]=1;
    //siz++;
    for(ll j=0;j<adj[i].size();j++)
    {        
        edges++;
        if(!vis[adj[i][j]])
            dfs(adj[i][j]);
    }
}
ll mpow(ll base, ll exp) {
  base %= hell;
  ll result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % hell;
    base = ((ll)base * base) % hell;
    exp >>= 1;
  }
  return result;
}*/
int main()
{
fIO;
ll n,sum=0,t=1,m,ans;

//cin >> t;
while(t--){
  //string s;
  cin>>n;
  set<ll>s;
  map<ll,ll>m;
  rep(i,-131,131){
    ll cc=i*i*i*i*i;
    m[i]=cc;
    s.insert(cc);
    m[cc]=i;
  }
  tr(it,s){
    if(s.find(*it+n)!=s.end()){cout<<m[*it+n]<<" "<<" "<<m[*it]; return 0;}
  }
    













}
TIME;
    
}

Measured memory_bytes: 3688
#![allow(unused_imports)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

// -----------------------------------------------
// Framework <https://github.com/vain0x/procon>
// -----------------------------------------------

//
// Macro debug!
//

#[cfg(debug_assertions)]
include!{"./procon/debug.rs"}

#[cfg(not(debug_assertions))]
macro_rules! debug {
    ($($arg:expr),*) => {};
}

//
// Macro input!
//

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

//
// IteratorExt
//

trait IteratorExt: Iterator + Sized {
    fn vec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

impl<T: Iterator> IteratorExt for T {}



fn main() {
    input! {
        r: isize,
        d: isize,
        x_2000: isize,
    }

    let mut x = x_2000;
    let mut xs = Vec::new();

    for _ in 0..10 {
        x = r * x - d;
        xs.push(x);
    }

    for x in xs {
        println!("{}", x);
    }
}


Measured memory_bytes: 4352
n, d = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
b = 0
for i in range(n):
    for j in range(i + 1, n):
        s = 0
        for c, e in zip(a[i], a[j]):
            s += (c - e) ** 2
        if s ** 0.5 == int(s ** 0.5):
            b += 1
print(b)

Measured memory_bytes: 9424
h, w = map(int, input().split())

if h % 2 == 0:
    ans = (h // 2)*w
else:
    if w % 2 == 0:
        ans = ((h // 2)*2 + 1)*(w // 2)
    else:
        ans = (h // 2)*(w // 2) + ((h // 2) + 1)*(w - (w // 2))

if h == 1 or w == 1:
    ans = 1

print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(long long i=a; i<b; i+=1)
#define repr(i,a,b) for(long long i=a; i<=b; i+=1)
#define vec vector<ll>
#define map map<string,int>
#define repa(p,A) for(auto p:A)
#define pb push_back
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())

using namespace std;
int main() {
  string A,B;
  cin>>A>>B;
  bool ans=true;
  rep(i,0,A.size()) {
    if(A[i]!=B[i])
      ans=false;
    if(B.size()-A.size()!=1) {
      ans=false;
    }
  }
  if(ans) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}
  


Measured memory_bytes: 3628
def main():
  s=input()
  sa=int(s[:2])
  sb=int(s[2:])
  if 1 <= sa and sa <= 12:
    if 1 <= sb and sb <= 12:
      print('AMBIGUOUS')
    else:
      print('MMYY')
  else:
    if 1 <= sb and sb <= 12:
      print('YYMM')
    else:
      print('NA')
main()

Measured memory_bytes: 8904
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>

using namespace std;

#define mod 1000000007

int main()
{
	string s;
	int w;
	cin >> s >> w;
	for(int i = 0; i < s.length(); i += w) cout << s[i];
	cout << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define max0(a,b,c) max(max(a,b),c)
#define min0(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
using Graph = vector<vector<int>>;
typedef long long lint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldouble;
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<ull> ulvec;
typedef vector<double> dvec;
typedef vector<pair<int,int>> pvec;
typedef vector<pair<ll,ll>> plvec;
typedef vector<tuple<ll,ll,ll>> tvec;
typedef vector<string> svec;

const ll INF=10000000;

int main(){
    ll n,s,sum=0;
    cin>>n>>s;
    lvec a(n);
    rep(i,n){
        cin>>a[i];
        sum+=a[i];
    }
    if(s>sum) cout<<0<<endl;
    else{
        ll l=0,r=0,ans=INF;
        lvec t(n+1,0);
        for(int i=0;i<n;i++) t[i+1]=t[i]+a[i];
        while(true){
            if(t[r]-t[l]<s&&r<n){
                r++;
                continue;
            }
            ans=min(ans,r-l);
            l++;
            if(r==n&&t[r]-t[l]<s) break;
        }
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 4428
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int n;
int v[55];
double ans;
int main()
{
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> v[i];
    }
    sort(v, v + n);
    ans = (v[0] + v[1]) / 2.0;
    for(int i = 2; i < n; i++){
        ans = (ans + v[i]) / 2.0;
    }
    printf("%.7f", ans);
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <numeric>
#define REP(i, n) for(int i = 0; i < n; 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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;	

int main() {
    ll a, b, c, k; cin >> a >> b >> c >> k;
    if (k % 2 == 0) {
        cout << a - b << endl;
    }
    else {
        cout << b - a << endl;
    }
}


Measured memory_bytes: 3628
// ???????????´??°a, b, c??????????????????????????????a < b < c????????¶????????????????????°
// "Yes"?????????????????????????????°"No"???????????????????????°?????????????????????????????????

#include <stdio.h>

int main(void)
{
	int a, b, c;
	scanf("%d%d%d", &a, &b, &c);

	if (a < b && a < c && b < c) {
		printf("Yes\n");
	} else {
		printf("No\n");
	}

	return 0;
}

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

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

  if (H == 1 || W == 1) {
    cout << 1 << endl;
  }
  else {
    double result = W * H / 2;
    printf("%.0lf\n", round(result));
  }
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int w, n, a, b, x, i, rs[30];

	scanf("%d %d", &w, &n);

	for(i = 0; i < w; i++){
		rs[i] = i+1;
	}

	for(i = 0; i < n; i++){
		scanf("%d,%d", &a, &b);

		x = rs[a-1];
		rs[a-1] = rs[b-1];
		rs[b-1] = x;
	}

	for(i = 0; i < w; i++){
		printf("%d\n", rs[i]);
	}
	
	return 0;
}

Measured memory_bytes: 596
import math
import sys


N = int(input())
S  = input()
# print (N,S)

if N < 3:
    print(0)
    exit(0)

ans = 0 
for i in range(0,N-3+1):
    if S[i:i+3 ] == 'ABC':
        ans = ans + 1

print(ans)
exit(0)



Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define  ll long long
int main()
{
	ll a,b,c,d;  cin>>a>>b>>c>>d;
	ll f=a*c;
	ll s=a*d;
	ll r=b*c;
	ll t=b*d;
	cout<<max({f,s,r,t});
	
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n, m, l;
	long long a[110][110], b[110][110], c[110][110];
	memset(c, 0, sizeof(c));
	cin >> n >> m >> l;
	for(int i=1; i<=n; i++)
		for(int j=1; j<=m; j++)
			cin >> a[i][j];
	for(int i=1; i<=m; i++)
		for(int j=1; j<=l; j++)
			cin >> b[i][j];
	for(int i=1; i<=n; i++)
		for(int j=1; j<=l; j++)
			for(int k=1; k<=m; k++)
				c[i][j] += a[i][k]*b[k][j];
	for(int i=1; i<=n; i++){
		for(int j=1; j<l; j++)
			cout << c[i][j] << " ";
		cout << c[i][l] << endl;
	}
	return 0;
}


Measured memory_bytes: 3372
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

#define rip(i,n,s) (int i=(s);i<(int)(n);i++)
int n;

void dfs(vector<int> &day, vector<int> &co, vector<vector<int>> &da, int gg) {
	if (co[gg] == n - 1) {
		return;
	}
	int x = da[gg][co[gg]];
	if (co[x] == n - 1) {
		return;
	}
	if (da[x][co[x]] == gg) {
		co[x]++;
		co[gg]++;
		day[x] = max(day[x], day[gg]) + 1;
		day[gg] = day[x];
		dfs(day, co, da, gg);
		dfs(day, co, da, x);
	}
}

int main() {
	cin >> n;
	vector<vector<int>> da(n, vector<int>(n - 1));
	for rip(i, n, 0) {
		for rip(j, n - 1, 0) {
			cin >> da[i][j];
			da[i][j]--;
		}
	}
	vector<int> day(n, 0), co(n, 0);
	int ma = n * (n - 1) / 2;
	for rip(i, n, 0) {
		dfs(day, co, da, i);
	}
	for rip(i, n, 0) {
		if (co[i] != n - 1) {
			cout << -1 << endl;
			return 0;
		}
	}
	int ans = 0;
	for rip(i, n, 0) {
		ans = max(ans, day[i]);
	}
	cout << ans << endl;
}


Measured memory_bytes: 27520
N = int(input())
A = list(map(int,input().split()))
A.sort()

from bisect import bisect
i = bisect(A, A[-1]//2)
a = min(A[i], A[-1]-A[i])
b = min(A[i-1], A[-1]-A[i-1])
if a > b:
    print(A[-1], A[i])
else:
    print(A[-1], A[i-1])


Measured memory_bytes: 14428
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
int main(){
  double a,b,c;
  cin>>a>>b>>c;
  static const double pi = 3.141592653589793;
  if(c<=a*b*a/2){
    cout<<setprecision(10)<<90-atan(2*c/a/b/b)/pi*180<<endl;
  }else{
    cout<<setprecision(10)<<atan(2*(a*b*a-c)/a/a/a)/pi*180<<endl;
  }
return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#include<bits/stdc++.h>
using namespace std;

#define int long long
#define endl '\n'

const int N = 200005;

signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int k, x;
	cin >> k >> x;
	for(int i = max(-1000000LL,x - k + 1) ; i <= min(1000000LL, x + k - 1) ; i ++)
		cout << i << " ";
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test() int t;cin>>t;for(int test=1;test<=t;test++)
#define pb push_back
#define nl cout<<"\n"
#define F first
#define S second
#define all(x) x.begin(),x.end()

template<class C> void min_self( C &a, C b ){ a = min(a,b); }
template<class C> void max_self( C &a, C b ){ a = max(a,b); }

const ll MOD = 1000000007;
ll mod( ll n, ll m=MOD ){ n%=m,n+=m,n%=m;return n; }

const int MAXN = 1e5+5;
const int LOGN = 21;
const ll INF = 1e14;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

template<class T1, class T2> void add( T1 &x, T2 y, ll m = MOD )
{
    x += y;
    if( x >= m )
        x -= m;
}

template<class T1, class T2> void sub( T1 &x, T2 y, ll m = MOD )
{
    x -= y;
    if( x < 0 )
        x += m;
}

int main() 
{
    fastio();

    string s;
    cin>>s;

    if( s[0] == '7' || s[1] == '7' || s[2] == '7' )
        cout<<"Yes";
    else
        cout<<"No";

    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}


Measured memory_bytes: 3680
#pragma GCC optimize ("O3")
// #pragma GCC target ("avx")
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

int D;
int C[26];
int S[365][26];
int T[365];

int M;
int qq[100011], qd[100011];

int last[26];

int score(int day) {
    int cur = 0;
    REP (c, 26) last[c] = -1;

    REP (i, day) {
	int t = T[i];
	last[t] = i;

	cur += S[i][t];
	REP (c, 26) cur -= C[c] * (i - last[c]);
    }
    return cur;
}

void solve() {
    REP (day, D) {
	int best = 0, bestc = 0;
	REP (c, 26) {
	    T[day] = c;
	    int s = score(day+1);
	    if (best < s) {
		best = s;
		bestc = c;
	    }
	}
	T[day] = bestc;
	// eprintf("%d\n", best);
    }
}

void solveC() {
    int best = score(D);
    REP (q, M) {
	int old = T[qd[q]];
	T[qd[q]] = qq[q];
	int tmp = score(D);
	printf("%d\n", tmp);
    }
}

void output() {
    REP (d, D) printf("%d\n", T[d]+1);
}

void MAIN() {
    scanf("%d", &D);
    REP (c, 26) scanf("%d", C+c);
    REP (i, D) REP (c, 26) scanf("%d", S[i]+c);
    REP (i, D) scanf("%d", T+i), T[i]--;

    scanf("%d", &M);
    REP (i, M) {
	scanf("%d%d", qd+i, qq+i);
	qd[i]--;
	qq[i]--;
    }

    solveC();
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 4640
#include<bits/stdc++.h>
using namespace std;
int F[101][11],P[101][11];
int main(){
  int N;
  cin>>N;
  for(int i=0;i<N;i++){
    for(int j=0;j<5;j++){
      int f,g;
      cin>>f>>g;
      F[i][2*j]=f;
      F[i][2*j+1]=g;
    }
  }
  for(int i=0;i<N;i++){
    for(int j=0;j<11;j++){
      int p;
      cin>>p;
      P[i][j]=p;
    }
  }
  long ans=LONG_MIN;
  for(int i=1;i<1<<10;i++){
    long cost=0;
    for(int k=0;k<N;k++){
      long cnt=0;
      for(int j=0;j<10;j++)if((i&1<<j)&&F[k][j])cnt++;
      cost+=P[k][cnt];
    }
    ans=max(ans,cost);
  }
  cout<<ans<<endl;
}


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

int main()
{
	int n;
	cin >> n;
	auto d = vector<int>(n);
	for(auto&& dd : d) cin >> dd;
	sort(d.begin(), d.end());
	cout << d[n / 2] - d[n / 2 - 1] << endl;
	return 0;
}

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

const int mod = 1e9+7;
typedef vector<vector<long long int> > vvi;

vvi mul(vvi a, vvi b){
	int n = a.size();
	vvi c(n,vector<long long int>(n));
	for(int i =0;i<n;i++){
		for(int j =0;j<n;j++){
			for(int k =0;k<n;k++){
				c[i][j]+= (a[i][k]*b[k][j])%mod;
				c[i][j]%=mod;
			}
		}
	}
	return c;
}

int main(){

	long long int n,k;
	cin >> n >> k;
	vvi g(n,vector<long long int>(n));
	vvi ans(n,vector<long long int>(n));
	for(int i =0;i<n;i++){
		for(int j =0;j<n;j++){
			cin >> g[i][j];
			ans[i][j]  = g[i][j];
		}
	}

	
	k--;
	while(k){
		if(k&1){
			ans = mul(ans,g);
		}
		g = mul(g,g);
		k>>=1;
	}

	long long res = 0;
	for(int i =0;i<n;i++){
		for(int j =0;j<n;j++){
			res+=ans[i][j];
			// cout << ans[i][j] << " ";
			res%=mod;
		}
	}
	cout << res << endl;

}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.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 INF = 1LL << 60;
const double pi = acos(-1.0);

int par[110000];
int r[110000];

void init(int n) {
    rep(i, n) {
        par[i] = i;
        r[i] = 0;
    }
}

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

void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if(x == y) return;
    if(r[x] < r[y]) par[x] = y;
    else {
        par[y] = x;
        if(r[x] == r[y]) r[x]++;
    }
}

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

int main() {
    ll n, m; cin >> n >> m;
    vector<ll> p(n); rep(i, n) cin >> p[i];
    init(110000);
    rep(i, m) {
        ll x, y; cin >> x >> y; x--; y--;
        unite(x, y);
    }
    ll ans = 0;
    rep(i, n) if(same(i, p[i] - 1)) ans++;
    cout << ans << endl;
}


Measured memory_bytes: 4788
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10 ** 7)
 
def solve(N: int, u: "List[int]", v: "List[int]", w: "List[int]"):
    res = [0 for i in range(N)]
    G = [[] for i in range(N)]
    for i, j, k in zip(u, v, w):
        # print(i, j, k)
        i -= 1
        j -= 1
        # print(i, j, k)
        G[i].append((j, k))
        G[j].append((i, k))
 
    # v を c に塗る。 p は v の親。
    def dfs(v, p, c):
        res[v] = c
        for e in G[v]:
            if e[0] == p:
                continue
            if e[1] & 1:
                dfs(e[0], v, 1 - c)
            else:
                dfs(e[0], v, c)
 
    dfs(0, -1, 1)
 
    for x in res:
        print(x)
 
    return
 
 
# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools
# (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    u = [int()] * (N - 1)  # type: "List[int]"
    v = [int()] * (N - 1)  # type: "List[int]"
    w = [int()] * (N - 1)  # type: "List[int]"
    for i in range(N - 1):
        u[i] = int(next(tokens))
        v[i] = int(next(tokens))
        w[i] = int(next(tokens))
    solve(N, u, v, w)
 
 
if __name__ == '__main__':
    main()

Measured memory_bytes: 100360
#include<stdio.h>
#include<queue>
#include<assert.h>
#include<tuple>
#include<string>
#include<algorithm>
#include<iostream>
#include<map>
#include<string.h>
#include<vector>
#include<math.h>
#include<stdlib.h>
#include<set>
#include<ctype.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef tuple<int,int,int> t3;

const int MX = 1 << 18;
const int MM = 1000000007;

int T[MX];
vector<int> G[MX];

void dfs(int x, int p = -1)
{
	vector<int> L;
	for(int c : G[x]){
		if( c == p ) continue;
		dfs(c, x);
		L.push_back(T[c]);
	}
	sort(L.begin(), L.end());
	for(int i = 0; i < L.size(); i++){
		T[x] = max(T[x], L[i] + (int)L.size() - i);
	}
}

int main()
{
	int N;
	scanf("%d", &N);
	for(int i = 2; i <= N; i++){
		int a;
		scanf("%d", &a);
		G[a].push_back(i);
		G[i].push_back(a);
	}
	dfs(1);
	printf("%d\n", T[1]);
}


Measured memory_bytes: 19328
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
int n, a, b[100005];
int main(){
	scanf("%d", &n);
	rep(i,n){
		scanf("%d", &a);
		b[a-1] = i+1;
	}
	rep(i,n) printf("%d%c", b[i], i == n-1 ? '\n' : ' ');
}

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

#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\n'
#define all(x) x.begin(), x.end()
#define arr array

template<typename T> void umin(T& a,T b){a = min(a,b);}
template<typename T> void umax(T& a,T b){a = max(a,b);}

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
using vvll = vector< vector<ll> >;
using vll = vector<ll> ;
using pll = pair<ll, ll> ;

const ll maxs = 1e6+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e18;


void pre(){



}



void solve(){

    string a,b;
    cin >> a >> b;
    int l=0,r=b.size()-1;
    int ans = b.size();
    while(r < a.size()){

        int c=0;
        for(int i=l;i<=r;i++){
            if(a[i] != b[i-l])
                c++;
        }
        umin(ans,c);
        l++,r++;
    }
    cout << ans ;
    
}

int32_t main(){
    // #ifndef ONLINE_JUDGE
    // freopen("input00.txt","r",stdin);
    // #endif
    IOS;
    pre();
    ll T = 1;
    //cin>>T;
    while(T--){
        solve();   
    }
    return 0;
}

Measured memory_bytes: 3644
N = int(input())
a = list(map(float, input().split(" ")))
b = list(map(float, input().split(" ")))
c = list(map(float, input().split(" ")))

a.sort()
c.sort()


def bisect_left(a, x, lo=0, hi=None):
    """Return the index where to insert item x in list a, assuming a is sorted.
    The return value i is such that all e in a[:i] have e < x, and all e in
    a[i:] have e >= x.  So if x already appears in the list, a.insert(x) will
    insert just before the leftmost x already there.
    Optional args lo (default 0) and hi (default len(a)) bound the
    slice of a to be searched.
    """

    if lo < 0:
        raise ValueError('lo must be non-negative')
    if hi is None:
        hi = len(a)
    while lo < hi:
        mid = (lo+hi)//2
        if a[mid] < x: lo = mid+1
        else: hi = mid
    return lo

def bisect_right(a, x, lo=0, hi=None):
    """Return the index where to insert item x in list a, assuming a is sorted.
    The return value i is such that all e in a[:i] have e <= x, and all e in
    a[i:] have e > x.  So if x already appears in the list, a.insert(x) will
    insert just after the rightmost x already there.
    Optional args lo (default 0) and hi (default len(a)) bound the
    slice of a to be searched.
    """

    if lo < 0:
        raise ValueError('lo must be non-negative')
    if hi is None:
        hi = len(a)
    while lo < hi:
        mid = (lo+hi)//2
        if x < a[mid]: hi = mid
        else: lo = mid+1
    return lo

num = 0
for i in range(N):
    num += (bisect_left(a, b[i])) * (len(c) - bisect_right(c, b[i]))
print(num)

Measured memory_bytes: 21024
#define _USE_MATH_DEFINES
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <string.h>
#include <math.h>
#include <map>
#include <time.h>
using namespace std; 

int main(){
	int N, M, K[30], A[30][30], c[30] = {}, ans = 0;
	cin >> N >> M;
	
	for (int i = 0; i < N; ++i){
		cin >> K[i];
		for (int j = 0; j < K[i]; ++j){
			cin >> A[i][j];
			++c[A[i][j] - 1];
		}
	}

	for (int i = 0; i < M; ++i){
		if (c[i] == N)
			++ans;
	}

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

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

using ll = long long;
using G = vector<vector<int>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const ll MOD = 1000000007;

ll GCD(ll x, ll y){
	return y ? GCD(y, x%y) : x;	
}

int main() {
	int x, y; cin >> x >> y;
	for(int i=0;i<=x;i++){
		if(2*i+4*(x-i)==y){
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

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

int main(){
  int n;
  int sum=0;
  
  while(1){
    cin >> n;
    if(n==0)break;

    int cnt=0;
    int a[1000+1];

    for(int i=1;i <= n;i++){
      a[i] = i;
    }
    
    for(int i=1;i < n;i++){
      for(int j=i;;j++){
	sum += a[j];
	if(sum == n) cnt++;
	else if(sum > n) break;
      }
      sum = 0;
    }
    cout << cnt << endl;
  }
  return 0;
}



Measured memory_bytes: 3044
def merge(a,b): #整列済みの配列aとbを併合
    r =[]
    #結果の格納先を用意
    ai = 0 #aは何番目まで処理したか?
    bi = 0 #bは何番目まで処理したか?
    for i in range(0, len(a)+len(b)):
        if (bi >= len(b) or (ai < len(a) and a[ai] < b[bi])):
         #aとbの先頭を比較(長さを超えないよう注意)
            r.append(a[ai])
            ai = ai + 1
        else:
            r.append(b[bi])
            bi = bi + 1 #aとbの先頭の小さい方をrへ
    return r
def mergesort(a): #配列aを整列
    n = len(a)
    if n <= 1: #短いときはそれでよし
        return a
    else:
        l = mergesort(a[0 : n//2])
        r = mergesort(a[n//2 : n])
        #前半と後半をそれぞれ整列
        return merge(l,r)
        #整列した結果を併合
N,K=map(int,input().split())
h=[]
for i in range(0,N):
    h.append(int(input()))
h_New=mergesort(h)
h_k=[]
for i in range(0,N-K+1):
    h_k.append(h_New[i+K-1]-h_New[i])
print(min(h_k))

Measured memory_bytes: 12172