akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

int main(void) {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	
	string s;
	cin >> s;

	char bef = s[0];
	int cnt1 = 0;
	for(int i=1; i<s.size(); i++){
		if(bef != s[i]){
			cnt1++;
		}
		bef = s[i];
	}

	reverse(s.begin(), s.end());

	bef = s[0];
	int cnt2 = 0;
	for(int i=1; i<s.size(); i++){
		if(bef != s[i]){
			cnt2++;
		}
		bef = s[i];
	}

	cout << min(cnt1, cnt2) << endl;
	
	return 0;
}


Measured memory_bytes: 512
n = int(input())
s_input = [input() for i in range(n)]
s = [[s_input[i][j] for j in range(10)] for i in range(n)]
sum = 0
count = 1
for i in range(n):
    s[i] = sorted(s[i])
s = sorted(s)
i = 0
for i in range(n - 1):
    if s[i] == s[i + 1]:
        count += 1
    else:
        sum += (count * (count - 1)) // 2
        count = 1
sum += (count * (count - 1)) // 2
print(sum)

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

#define REP(i,n) for(int i=0;i<int(n);i++)
#define ALL(v) (v).begin(),(v).end()

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

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

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*b/gcd(a,b);}	 

const ll mod=1e9+7;
const int INF=INT_MAX/2;
const int N_MAX=200020;

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


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;
// auto mod int
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {if ((x += a.x) >= mod) x -= mod; return *this;}
  mint& operator-=(const mint a) {if ((x += mod-a.x) >= mod) x -= mod; return *this;}
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main() {
  int n,k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  sort(a.begin(),a.end());
  if((k&1)&&a[n-1]<=0){
    mint ans = 1;
    rep(i,k) ans*=a[n-1-i];
    cout << ans << endl;
    return 0;
  }
  mint ans=1;
  int l=0,r=n-1;
  if(k&1) ans*=a[r--];
  rep(_,k/2){
    ll lv=a[l]*a[l+1],rv=a[r]*a[r-1];
    if(rv>=lv){
      ans *= rv;
      r-=2;
    }else{
      ans *= lv;
      l+=2;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 4760
def main():
  ## IMPORT MODULE
  #import sys

  #sys.setrecursionlimit(100000)
  #input=lambda :sys.stdin.readline().rstrip()

  #f_inf=float("inf")
  MOD=998244353
  
  if 'get_ipython' in globals(): 
    ## SAMPLE INPUT
    n, m, k = 60522, 114575, 7559

  else:
    ##INPUT 
    #n = input()
    n, m, k = map(int, input().split())

  ## SUBMITION CODES HERE
  fac = [1] * (n+1)
  inv = [1] * (n+1)

  for i in range(n):
    fac[i+1] = fac[i] * (i+1) % MOD # Calculating the Factorial 
    inv[i+1] = pow(fac[i+1], MOD-2, MOD) # The inverse of the MOD's law (Fermat's Little Theorem)
  
  def nCr(n, r):
    if 2*r > n: nCr(n, n-r)
    return fac[n] * inv[r] * inv[n-r] % MOD
  
  ans = 0
  for i in range(k+1):
    tmp = nCr(n-1, i) * m * pow(m-1, n-1-i, MOD) 
    ans += tmp
    ans %= MOD
  print(ans)

main()

Measured memory_bytes: 24616
N, K = [int(nk) for nk in input().split()]
S = input()
T = []
for n in range(N):
  T.append(S[n])
if T[K-1] == "A":
  T[K-1] = "a"
elif T[K-1] == "B":
  T[K-1] = "b"
else:
  T[K-1] = "c"
U = "".join(T)
print(U)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define for1(i,n) for (ll i=0;i<(n);i++)
#define for2(i,m,n) for (ll i=(m);i<(n);i++)
#define for3(i,m,n,d) for (ll i=(m);i<(n);i+=(d))
#define DEBUG 0

ld solve()
{
    ld ans = 0;
    ll N,K;
    cin >> N >> K;
    ld ans1 = 0;
    ll sc = 0;
    for2(i,1,N+1) {
        ans1 = 1;
        sc = i;
        while (sc < K) {
            ans1 /= 2.0;
            sc *= 2;
        }
        ans += ans1;
    }
    //cout << setprecision(16) << ans / N << endl;
    printf("%.11Lf\n", ans / N);
    return 0;
}

int main()
{
    do {
        solve();
        //cout << solve() << endl;
    } while (DEBUG);
}


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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

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; }



void func(std::string S){

    cout<<S.substr(0,3)<<endl;

}

int main(){
    // cout << fixed << setprecision(5);

    std::string S;
    std::cin >> S;
    func(S);
    return 0;
}


Measured memory_bytes: 3604
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <string>
#include <set>
#include <iomanip>
#include <map>
#include <stdio.h>
#include <queue>
#define rep(i,n) for (int i=0;i<(n);++i)
#define REP(i,n) for (int i=0;i<=(n);++i)
#define all(x) (x).begin(), (x).end()

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 namespace std;
typedef long long ll;
const int INF = 10000000;

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

    for(ll i = -118; i <= 120; ++i) {
        for(ll j = -119; j <= 119; ++j) {
            if(pow(i, 5) - pow(j, 5) == x) {
                cout << i << ' ' << j << endl;
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 4008
#include<iostream>
#include<cmath>
#include<string>
#include<algorithm>
#include <iomanip>
#include<sstream>
#include<string.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(0), cin.tie(0);
    long long r, x, d, i, j;
    while (cin >> r >> d >> x)
        for (i = 1;i <= 10;i++)
        {
            x = r * x - d;
            cout << x << '\n';
        }
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define RREP(i,n) RFOR(i,0,n)

const int _N = 3e5 + 100;

int n;

/// --BIT--

struct BIT {
	int data[_N+1];
	void init(int n){
		REP(i, n+1){
			data[i] = 0;
		}
	}
	void add(int i, int x){
		i++;
		while(i<=n){
			data[i]+=x;
			i+=i&-i;
		}
	}
	// return sum of [0, i]
	// max is 3e5 -> int
	int sum(int i){
		i++;
		int s = 0;
		while(i>=1){
			s += data[i];
			i-=i&-i;
		}
		return s;
	}
};

/// --BIT--

BIT tree;
int d[_N];
int main(){
	cin >> n;
	REP(i, n){
		cin >> d[i];
		d[i] /= 10;
	}
	tree.init(n);
	tree.add(0, 1);
	tree.add(1, -1);
	REP(i, n-1){
		if(tree.sum(i) > 0){
			tree.add(i+1, 1);
			int t = i+1+d[i];
			if(t<n)tree.add(t, -1);
		}
	}

	if(tree.sum(n-1) == 0){
		cout << "no" << endl;
		return 0;
	}

	tree.init(n);
	tree.add(0, 1);
	tree.add(1, -1);
	REP(i, n-1){
		if(tree.sum(i) > 0){
			tree.add(i+1, 1);
			int t = i+1+d[n-1-i];
			if(t<n)tree.add(t, -1);
		}
	}

	if(tree.sum(n-1) == 0){
		cout << "no" << endl;
		return 0;
	}
	cout << "yes" << endl;
}

Measured memory_bytes: 5428
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define IFOR(i, m, n) for(ll i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

typedef pair<ll,ll> P;

void no(){
  cout << -1 << endl;
  exit(0);
}

int main(){
  ll n; cin >> n;
  vector<ll> a(n), b(n);
  priority_queue<P, vector<P>,less<P>> pq;
  REP(i,n) cin >> a[i];
  REP(i,n){
    cin >> b[i];
    pq.push({b[i],i});
  }
  ll ans = 0;
  while(!pq.empty()){
    ll i =  pq.top().second;
    pq.pop();
    if(b[i] == a[i]) continue;
    ll step = b[(i+1+n)%n] + b[(i-1+n)%n];
    if(b[i]<step) no();
    if(b[i]>a[i] && (b[i]-a[i])%step == 0){
      ans += (b[i]-a[i])/step;
      b[i] = a[i];
      continue;
    }
    if(b[i]>a[i]){
      ans += b[i]/step;
      b[i] %= step;
    }
    if(b[i]<a[i]) no();
    pq.push({b[i],i});
  }
  cout << ans << endl;
}



Measured memory_bytes: 9456
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int main(){
  int N;
  cin>>N;
  vector<int> ans(N+1,0);
  FOR(x,1,101)FOR(y,1,101)FOR(z,1,101){
    int temp=x*x+y*y+z*z+x*y+y*z+z*x;
    if(temp<=N)ans[temp]++;
  }
  FOR(i,1,N+1)cout<<ans[i]<<endl;
  return 0;
}


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

int main(){
  int n,h,w,count=0,a,b;
  cin>>n>>h>>w;
  r(i,n){
    cin >> a >> b;
    if(a>=h&&b>=w)count++;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int a,b,c;
	while(scanf("%d %d %d",&a,&b,&c)!=EOF)
	{
		int sum=0;
		sum=a*100+b*10+c*1;
		if(sum%4==0)
		printf("YES\n");
		else
		printf("NO\n");	
		
	}
	return 0;
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
//typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};

const int INF = 1<<29;

template<typename T> struct RangeMaxQuery {
  int N, _N;
  vector<T> dat;

  RangeMaxQuery(int _N) : _N(_N) {
    assert(_N > 0);
    N = 1;
    while (N < _N)
      N <<= 1;
    dat.assign(2 * N - 1, 0);
  }

  void update(int k, T val) {
    assert(0 <= k && k < _N);
    k += N - 1;
    dat[k] = val;

    while (k > 0) {
      k = (k - 1) / 2;
      dat[k] = max(dat[2 * k + 1], dat[2 * k + 2]);
    }
  }

  // [a, b)
  T query(int a, int b) {
    assert(0 <= a && a <= b && b <= _N);
    return query(a, b, 0, 0, N);
  }
  T query(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l) return 0;
    if (a <= l && r <= b) return dat[k];

    int mid = (l + r) / 2;
    return max(query(a, b, 2 * k + 1, l, mid),
               query(a, b, 2 * k + 2, mid, r));
  }
};

int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(20);

  ll sx, sy, gx, gy; cin >> sx >> sy >> gx >> gy;
  if (sx > gx) swap(sx, gx), swap(sy, gy);
  bool flag = false;
  if (sy > gy) {
    gy += 2 * (sy - gy);
    flag = true;
  }
  assert(sx <= gx and sy <= gy);

  int N; cin >> N;
  vector<pair<ll, ll>> jet;
  REP(i, N) {
    ll x, y; cin >> x >> y;
    if (flag) y += 2 * (sy - y);
    if (sx <= x and x <= gx and sy <= y and y <= gy) jet.emplace_back(x, y);
  }
  N = jet.size();

  double ans = 100 * (1.0 * (gx - sx) + 1.0 * (gy - sy));

  if (N == 0) {
    cout << ans << endl;
    return 0;
  }

  vector<pair<ll, int>> X, Y;
  REP(i, N) {
    int x, y; tie(x, y) = jet[i];
    X.emplace_back(x, i);
    Y.emplace_back(y, i);
  }
  sort(ALL(X)), sort(ALL(Y));

  vector<int> segt_idx(N);
  REP(i, N) segt_idx[X[i].second] = i;

  RangeMaxQuery<int> dp(N);
  for (int i = N - 1; i >= 0; i--) {
    int idx = Y[i].second;
    int left = lower_bound(ALL(X), make_pair(jet[idx].first + 1, 0)) - X.begin();
    dp.update(segt_idx[idx], dp.query(left, N) + 1);
  }

  if (dp.query(0, N) == min(gx - sx, gy - sy) + 1) {
    cout << ans + (20 * acos(-1) / 4 - 20) * (dp.query(0, N) - 1) + (20 * acos(-1) / 2 - 20) << endl;
  } else {
    cout << ans + (20 * acos(-1) / 4 - 20) * dp.query(0, N) << endl;
  }
  //cout << dp.query(0, N) << endl;
  return 0;
}


Measured memory_bytes: 17516
#include<iostream>
#include<string>
#include<sstream>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<cmath>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};

int main()
{
    int y,x,d;
    cin >> y >> x >> d;
    pair<int,int> A[y*x+1];
    for (int i=0; i<y; ++i)
    {
        for (int j=0; j<x; ++j)
        {
            int tmp;
            cin >> tmp;
            A[tmp] = make_pair(i+1,j+1);
        }
    }
    ll dp[y*x+1],cumsum[y*x+1];
    for (int i=0; i<y*x+1; ++i)
    {
        dp[i] = 0;
        cumsum[i] = 0;
    } 

    for (int i=1; i<y*x; ++i)
    {
        if(i+d>y*x) break;
        dp[i+d] = abs(A[i].first-A[i+d].first) + abs(A[i].second-A[i+d].second);
        cumsum[i+d] = dp[i+d] + cumsum[i]; 
    }

    // for (int i=1; i<y*x; ++i)
    // {
    //     for (int j=i+d; j<y*x+1; j+=d)
    //     {
    //         cumsum[j] += cumsum[j-d];
    //     }
    // }

    int q;
    cin >> q;
    vector<int> ans;
    for (int i=0; i<q; ++i)
    {
        int l,r;
        cin >> l >> r;
        // int cost = 0;
        // for (int j=r; j>=l+d; j -= d)
        // {
        //     cost += dp[j];
        // }
        int cost = cumsum[r]-cumsum[l];
        ans.push_back(cost);
        // cout << ans << endl;
    }
    
    for (int i=0; i<q; ++i)
    {
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 3704
from numpy import*
n,m=map(int,input().split())
s=[[int(j) for j in input().split()][1:] for i in range(m)]
p=[int(i) for i in input().split()]
a=0
for i in range(2**n):
    b=array([(i>>j)&1 for j in range(n)])
    if [sum(b[array(k)-1])%2 for k in s]==p:
      a+=1
print(a)

Measured memory_bytes: 12492
#include<stdio.h>

int fibona(int n);

int main()
{
  int n;
  int fib;
  scanf("%d",&n);
  fib = fibona(n);
  printf("%d\n",fib);
}

int fibona(int n)
{
  int i=0;
  int fib[45];
  for(i=0;i<=n;i++)
    {
      fib[i]=0;
      if(i==0)
	{
	  fib[0] = 1;
	}
      else if(i==1)
	{
	  fib[1] = 1;
	}
      else
	{
	  fib[i] = fib[i-1] + fib[i-2];
	}
    }
  return fib[n];
}



Measured memory_bytes: 2112
n=int(input())
*l,=map(int,input().split())
m=[0]*n
a=n*(n+1)//2
b=sum(l)

if b%a:
  print("NO")
else:
  k=b//a
  m=[l[(i+1)%n]-l[i]-k for i in range(n)]
  for i in range(n):
    if m[i]>0 or m[i]%n!=0:
      print("NO")
      break
  else:
    print("YES")

Measured memory_bytes: 14492
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ALL(a) (a).begin(), (a).end()
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
const ll mod = 1e9 + 7;

int main()
{
    ll a, b, c;
    cin >> a >> b >> c;
    if (a + b >= c)
    {
        cout << c + b << endl;
        return 0;
    }
    else
    {
        cout << a + b * 2 + 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
x = int(input())
if x < 7:
    print(1)
    exit()
elif x % 11 is 0:
    print((x // 11) * 2)
elif x % 11 < 7:
    print((x // 11) * 2 + 1)
else:
    print((x // 11) * 2 + 2)


Measured memory_bytes: 2940
#include<stdio.h>
int min(int a,int b){
  if(a>b) return b;
  return a;
}
int main(void){
  int n,i;
  long long int ans=0;
  scanf("%d",&n);
  int b[n-1];
  for(i=0;i<n-1;i++) scanf("%d",&b[i]);
  ans = b[0]+b[n-2];
  for(i=1;i<n-1;i++) ans += min(b[i-1],b[i]);
  
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using P =pair<long,long>;
const ll MOD = ll(1e9) +7;

// Sieve of Eratosthenes
// https://youtu.be/UTVg7wzMWQc?t=2774
struct Sieve {
  int n;
  vector<int> f, primes;
  Sieve(int n=1):n(n), f(n+1) {
    f[0] = f[1] = -1;
    for (ll i = 2; i <= n; ++i) {
      if (f[i]) continue;
      primes.push_back(i);
      f[i] = i;
      for (ll j = i*i; j <= n; j += i) {
        if (!f[j]) f[j] = i;
      }
    }
  }
  bool isPrime(int x) { return f[x] == x;}
  vector<int> factorList(int x) {
    vector<int> res;
    while (x != 1) {
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }
  vector<P> factor(int x) {
    vector<int> fl = factorList(x);
    if (fl.size() == 0) return {};
    vector<P> res(1, P(fl[0], 0));
    for (int p : fl) {
      if (res.back().first == p) {
        res.back().second++;
      } else {
        res.emplace_back(p, 1);
      }
    }
    return res;
  }
};

int main() {
    ll N;
    cin >> N;
    Sieve sieve = Sieve(N);
    map<ll,ll> mp;
    for(int i=1;i<=N;i++){
        vector<P> factors = sieve.factor(i);
        for(P p:factors){
            mp[p.first] += p.second;
        }
    }
    ll ans =1;
    for(auto itr = mp.begin();itr != mp.end();++itr){
        ans *= (itr->second +1);
        ans %= MOD;
    }
    cout << ans << endl;


    return 0;
}

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

int main() {
	
	

	string s,t;
	cin>>s>>t;
	
   long int counter=0;
	    for(int i=0;i<s.length();i++)
	    {
	        if(s[i]!=t[i])counter++;
	    }
	cout<<counter;
	
	return 0;
}

Measured memory_bytes: 3916
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
const long long INF = 1LL << 60;
const int MOD = 1000000007;
signed main(void){
    int h,w,n; cin>>h>>w>>n;
    vector <pair<int,int>> data(n);
    map <pair <int,int> , int> ma;
    rep(i,n) {int a,b; cin>>b>>a; a--; b--; ma[{a,b}]++; data[i] = {a,b};}
    vector <int> ans(10); 
    map <pair <int,int>, bool> done;
    rep(i,n){
        int nx = data[i].F, ny = data[i].S;
        for(int x=-1;x<=1;x++){
            for(int y = -1; y<=1; y++){
                int cx = nx+x, cy = ny+y;
                if(cx+1>= w|| cx-1<0||cy+1>=h||cy-1<0) continue;
                if(done[{cx, cy}]) continue;
                else done[{cx, cy}] = true;
                int cnt = 0;
                for(int ix=-1;ix<=1;ix++) for(int jy=-1;jy<=1;jy++) if(ma[{cx+ix, cy+jy}]) cnt++;
                ans[cnt]++;
            }
        }
    }
    rep(i,10) ans[0]-=ans[i];
    ans[0] += (h-2)*(w-2);
    
    rep(i,10) cout<<ans[i]<<endl;
}


Measured memory_bytes: 216192
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:https://beta.atcoder.jp/contests/abc098/tasks/abc098_b>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */
ll solve(){
    ll res = 0;
    map<char,bool> mp1,mp2;
    ll N; cin >> N;
    string S; cin >> S;
    for(int i = 0; i < S.length();i++){
        ll T = 0;
        mp1.clear(); mp2.clear();
        string S1 = S.substr(0,i),S2 = S.substr(i);
        for(auto& c:S1) mp1[c] = true;
        for(auto& c:S2) mp2[c] = true;
        for(char c = 'a'; c <= 'z'; c++)if(mp1[c] && mp2[c]) T++;
        res = max(res,T);
    }
    
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    cout << solve() << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
 
A, B, C, D, E, F = map(int, sys.stdin.readline().split())
 
max_a = (F - 1) // (100 * A) + 1
max_b = (F - 1) // (100 * B) + 1
 
max_rate = 0
ans_water = 0
ans_sugar = 0
for a in range(max_a + 1):
    for b in range(max_b + 1):
        water = 100 * A * a + 100 * B * b
        if water >= F:
            break
 
        max_sugar = min(F - water, water // 100 * E)
        # print("max_sugar", max_sugar)
        max_c = (max_sugar - 1) // C + 1
        max_d = (max_sugar - 1) // D + 1
        for c in range(max_c + 1):
            for d in range(max_d + 1):
                sugar = C * c + D * d
                if sugar > max_sugar or sugar + water > F:
                    break
 
                if sugar * (ans_water + ans_sugar) >= ans_sugar * (water + sugar):
                    ans_water = water
                    ans_sugar = sugar
 
print(ans_water + ans_sugar, ans_sugar)

Measured memory_bytes: 70856
#include <bits/stdc++.h>
#define MOD (long long)(1E9+7)
#define rep(i, n) for(int i = 0; i < n; i++)

using namespace std;

int main(){
	long long x, t = 100;
  	int count = 0;	
  	cin >> x;
  	while(t < x) {
    	count++;
      	t *= 1.01;
    }
  	cout << count << endl;
}



Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());
typedef long long ll;

int n,m,q;
vector<string> strings(0);

void dfs(string s){
  if(s.size() == n){
    strings.push_back(s);
    return;
  }
  char saf = s[s.size()-1];
  for(char c = saf;c<='0'+m;c++){
    dfs(s + c);
  }
  return;
}

int main(){
  cin >> n >> m >> q;
  vector<int> a(q),b(q),c(q),d(q);
  rep(i,q) cin >> a[i] >> b[i] >> c[i] >> d[i];
  dfs("1");
  int ans = 0;
  for(auto s : strings){
    //cout << s << endl;
    int tmp = 0;
    rep(i,q){
      int abi = s[b[i]-1] - '0';
      int aai = s[a[i]-1] - '0';
      //cout << abi << "-" << abi << " " << c[i] << endl;
      if(abi - aai == c[i]) tmp += d[i];
    }//i
    //cout << tmp << endl;
    ans = max(tmp,ans);
  }
  cout << ans << endl;
}


Measured memory_bytes: 5372
//In the name of God
#include <bits/stdc++.h>
using namespace std;

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

const ll maxn = 2e5 + 100;
const ll mod = 1e9 + 7;
const ll inf = 1e18;

#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io freopen("input.txt", "r+", stdin);freopen("output.txt", "w+", stdout);
#define pb push_back
#define all(vec) (vec).begin(), (vec).end()
#define Mp make_pair
#define F first
#define S second

ll n, m, a[maxn], b[maxn], par[maxn];
vector<pll> c;
vector<ll> vec;
vector<ll> g[2][maxn];
vector<ll> dsu[maxn];

void Union(ll v, ll u){
    v = par[v];
    u = par[u];
    if(v == u) return;
    if(dsu[v].size() < dsu[u].size()) swap(v, u);
    for(ll x : dsu[u]){
        par[x] = v;
        dsu[v].pb(x);
    }
    dsu[u].clear();
    return;
}

int main(){
    fast_io;

    cin >> n;
    for(ll i = 0; i < n; i++){
        cin >> a[i];
        a[n] ^= a[i];
    }
    for(ll i = 0; i < n; i++){
        cin >> b[i];
        b[n] ^= b[i];
    }
    for(ll i = 0; i < n; i++){
        if(a[i] != b[i]) c.pb(Mp(a[i], b[i]));
    }
    c.pb(Mp(a[n], b[n]));
    m = c.size();
    for(ll i = 0; i < m; i++){
        vec.pb(c[i].F);
        vec.pb(c[i].S);
    }
    sort(all(vec));
    vec.resize(unique(all(vec)) - vec.begin());
    for(ll i = 0; i < m; i++){
        c[i].F = lower_bound(all(vec), c[i].F) - vec.begin();
        c[i].S = lower_bound(all(vec), c[i].S) - vec.begin();
        g[0][c[i].F].pb(i);
        g[1][c[i].S].pb(i);
        par[i] = i;
        dsu[i].pb(i);
    }
    for(ll i = 0; i < maxn; i++){
        if(g[0][i].size() != g[1][i].size()){
            cout << -1;
            return 0;
        }
        for(ll j = 0; j < (ll)g[0][i].size(); j++){
            Union(g[0][i][j], g[1][i][j]);
            if(j) Union(g[0][i][j], g[0][i][j - 1]);
        }
    }
    ll t = 0;
    for(ll i = 0; i < m; i++){
        if(par[i] == i) t++;
    }
    cout << m + t - 2;

    return 0;
}


Measured memory_bytes: 39848
#include  <iostream>
    using namespace std;
    int main() {
    	int n, w[100];
    	int num;
    	int s1, s2, sum1=0, sum2=0,min,diff;
    	int t = 0;
     
    	cin >> n;
    	for (int i = 0; i < n; i++) {
    		cin >> num;
    		w[i] = num;
    	}
     
    	min =100000000;
     
     
    	for (t = 1; t < n; t++) {
    		for (s1 = 0; s1 < t; s1++) {
    			sum1 += w[s1];
    		}
    		for (s2 = t; s2 < n; s2++) {
    			sum2 += w[s2];
    		}
     
    		
    		
    		diff = abs(sum2 - sum1);
    		
    		if (diff < min)
    			min = diff;
     
    		
    		sum1 = 0, sum2 = 0;
    	}
     
    	cout << min << endl;
    	system("pause");
    	return 0;
    }

Measured memory_bytes: 504
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

ll a[100010];
int main() {
	ll n;
	cin>>n;
	for(int i=0;i<n;i++){
		int z;
		cin>>z;
		z--;
		a[z]++;
	}
	ll oddcnt=0;
	ll ans=0;
	for(int i=0;i<100010;i++){
		if(a[i]==0){
			continue;
		}
		if(a[i]%2==0){
			oddcnt++;
		}
		if(a[i]!=0){
			ans++;
		}
	}
	cout << (oddcnt%2==0 ? ans:ans-1);
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    string s;
    cin >> s;
    reverse(s.begin(), s.end());
    int cnt = s.size();
    int i=0;
    while(cnt){
        if(s.substr(i,7)=="remaerd"){
            i += 7;
            if(cnt==i){
                puts("YES");
                return 0;
            }
        }else if(s.substr(i,6)=="resare"){
            i += 6;
            if(cnt==i){
                puts("YES");
                return 0;
            }
        }else if(s.substr(i,5)=="maerd"){
            i += 5;
            if(cnt==i){
                puts("YES");
                return 0;
            }
        }else if(s.substr(i,5)=="esare"){
            i += 5;
            if(cnt==i){
                puts("YES");
                return 0;
            }
        }else{
            puts("NO");
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3764
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N,P = [int(x) for x in input().split()]
A = [int(x)%2 for x in input().split()]
cnt_odd = 0
cnt_even = 0
cnt = 0
for i in A:
    if(i==1):
        cnt_odd+=1
    else:
        cnt_even+=1
if(cnt_odd==0):
    if(P==1):
        print(0)
    else:
        print(1<<cnt_even)
else:
    i = 0
    while(cnt_odd>=i*2+P):
        cnt+=combinations_count(cnt_odd,i*2+P)*(1<<cnt_even)
        i+=1
    print(cnt)


Measured memory_bytes: 3064
using System;
using System.Linq;
using System.Collections.Generic;

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var nk = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        var n = nk[0];
        var k = nk[1];
        var seqH = Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray();

        Array.Sort(seqH);
        Array.Reverse(seqH);
        var m = seqH.Skip(k).Sum();
        
        Console.WriteLine(m);
    }
}


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

#define MP make_pair
#define PB push_back
#define F first 
#define int long long 
#define S second
#define Runner_up ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()

signed main()
{	
	Runner_up
	int t=1; //cin>>t;
	while(t--){
		int n; cin>>n; int a[n];
		map <int , int> m;
		for(int i=0; i<n; i++){
			cin>>a[i];
			m[i-a[i]]++;
		}
		int ans=0;
		for(int i=0; i<n; i++){
			m[i-a[i]]--;
			ans += m[i+a[i]];
		}
		cout<<ans;
	}
	return 0;
}

Measured memory_bytes: 27884
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int inf = 999999999;
const double pi = acos(-1);

#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}

///////////////////////////////////////////////////////////////////////////

int main(){
	
	int h,w;
	cin >> h >> w;

	rep(i,0,h){
        string s;
        cin >> s;
        cout << s << endl;
        cout << s << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#define p pair <int,int>
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
using namespace std;
int n,buckets[100005];
vector<int> sorted;
vector<int>::iterator it;
int main(int argc,char const* argv[])
{
  int count=0;
  cin >> n;
  vector<int> a(n,0);
  rep(i,n)
    {
      scanf("%d",&a[i]);
    }
  map<int, int> mp;
  for(int i=0;i<n;i++)
    {
      mp[a[i]]++;
    }
  int k=mp.size();
  for(auto itr = mp.begin(); itr != mp.end(); itr++)
    {
      count+=itr->second - 1;
    }
  while(count-2>0)
    {
      count-=2;
    }
  if(count ==1)
    {
      cout << k-1 << endl;
      return 0;
    }
  else
    {
      cout << k << endl;
      return 0;
    }
  
}

Measured memory_bytes: 5376
#include <iostream>
#include <cstdio>
#include <string>
using namespace std;
char a[5];
int main() {
	string str;
	cin >> str;
	int top = 0;
	a[++top] = 'F';
	a[++top] = 'C';
	for (int i = 0; i < str.size(); ++i) {
		if (str[i] == a[top]) {
			top--;
		}
	}
	if (top == 0) {
		printf("Yes\n");
	} else {
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
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; }

const int MOD = 1000000007;
const int INF = 1e9;

const int mod = 1000000007;
const int inf = 1e9;
#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};

vector<Pll> edge[100100];

int main(){
    int n, m;
    cin >> n >> m;
    vector<ll> p(m), q(m), r(m);
    for(int i = 0; i < m; i++) {
        int a, b; ll c;
        cin >> a >> b >> c;
        a--,b--;
        p[i] = a, q[i] = b, r[i] = c;
        edge[a].push_back(Pll(b, c));
        edge[b].push_back(Pll(a, -c));
    }
    vector<ll> dis(n, -1e18);
    auto bfs = [&](int i) {
        queue<int> q;
        q.push(i);
        dis[i] = 0;
        while(!q.empty()) {
            int p = q.front();
            q.pop();
            for(auto u : edge[p]) {
                if(dis[u.first] == -1e18) {
                    dis[u.first] = dis[p] + u.second;
                    q.push(u.first);
                }
            }
        }

    };
    for(int i = 0; i < n; i++) {
        if(dis[i] == -1e18) bfs(i);
    }
    bool ok = true;
    for(int i = 0; i < m; i++) {
        if(dis[q[i]] - dis[p[i]] != r[i]) ok = false;
    }
    cout << (ok?"Yes":"No") << endl;

}

Measured memory_bytes: 18560
#include <cassert>
#include <algorithm>
#include <array>
#include <bitset>
#include <cctype>
#include <cstdint>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <memory>
#include <utility>
#include <limits>
 
#define rep(i, a, b) for (long long i = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  debug_out(t...);
}
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
long long pow_mod(long long a, long long b, long long mod=-1) {
  if(b==0)return 1;
  if ((a == 0)||(mod!=-1&&(a+mod)%mod==0))return 0;
  long long x = 1;
  while (b > 0) {
    if (b & 1)x = (mod!=-1)?(x * a) % mod:x*a;
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}

//const long long MOD = 998244353;
const long long MOD = 1e9 + 7;

using ll = long long;
using P=std::pair<long long,long long>;

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

  ll n;
  std::cin>>n;

  std::vector<ll> a(n);
  rep(i,0,n)std::cin>>a[i];

  std::vector<ll> cnt(n+2,0);
  rep(i,0,n)cnt[a[i]]++;

  ll ans=0;

  rep(i,0,n+2)ans+=cnt[i]*(cnt[i]-1)/2;

  rep(i,0,n){
    ans-=cnt[a[i]]*(cnt[a[i]]-1)/2;
    cnt[a[i]]--;
    ans+=cnt[a[i]]*(cnt[a[i]]-1)/2;
    std::cout<<ans<<"\n";
    ans-=cnt[a[i]]*(cnt[a[i]]-1)/2;
    cnt[a[i]]++;
    ans+=cnt[a[i]]*(cnt[a[i]]-1)/2;
  }

  return 0;
}


Measured memory_bytes: 5760
//DEEPANSHU RAWAT
//BTECH/10530/18
//INFORMATION TECHNOLOGY

/* Look for:
* the exact constraints (multiple sets are too slow for n=10^6 :( ) 
* special cases (n=1?)
* overflow (ll vs int?)
* array bounds
* if you have no idea just guess the appropriate well-known algo instead of doing nothing :/
 */
/*************************************************************************************************************************/
#include<bits/stdc++.h>
#define ull unsigned long long
#define lld long long int
#define infi LLONG_MAX
#define ninfi LLONG_MIN
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define e endl
#define mod 1000000007
#define modd 20000
using namespace std ;
/**************************************************************************************************************************/

/**************************************************************************************************************************/
int main()
    {
        ios_base::sync_with_stdio(false);//FOR FAST INPUT OUTPUT METHOD
        cin.tie(NULL);
        cout.tie(NULL);
       
        string s;
        string t;
        lld count=0;
        cin>>s>>t;
        if(s[0]==t[0])
        {
            count++;
        }
        if(s[1]==t[1])
        {
            count++;
        }
        if(s[2]==t[2])
        {
            count++;
        }

       cout<<count;

        
}
       
/**************************************************************************************************************************/                            


Measured memory_bytes: 256
import heapq, copy
n, k = map(int, input().split())
v = list(map(int, input().split()))
ans = -10 ** 10
for a in range(k + 1):
    for b in range(k - a + 1):
        if a + b > min(k, n):
            break
        # print(a, b)
        have = v[:a] + v[n-b:]
        # print(have)

        tmp = sum(have)
        ans = max(ans, tmp)

        have.sort()

        c = k - a - b

        for item in have:
            if c <= 0:
                break
            c -= 1
            if item >= 0:
                break

            tmp -= item
            ans = max(ans, tmp)

print(ans)

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

n = int(input())
l = [0] * n
r = [0] * n
for i in range(n):
    l[i],r[i] = map(int,input().split())

answer = 0

for i in range(n):
    answer += r[i] - l[i] + 1

print(answer)

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

main(){
     ll l,r,ans=3000,i,j;
     cin >> l >> r;

     if((r-l)>=2019){
         ans=0;
     }else{
         for(i=l;i<=r;i++){
             for(j=i+1;j<=r;j++){
                 if((i*j)%2019<=ans) ans=(i*j)%2019;
             }
         }
     }

     cout << ans << endl;
}

Measured memory_bytes: 256
s = input()
k = int(input())

# 1の連続性を確認し終わった段階の数字を記録
cnt = 1

if len(s) == 1:
    print(s)
    exit()

for i in range(len(s)-1):
    if s[i] != '1':
        num = s[i]
        break
    if s[i] == s[i+1] == '1':
        cnt += 1

if cnt >= k:
    print(1)
else:
    print(num)


Measured memory_bytes: 3060
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        UnionFind unionFind = new UnionFind(n);
        List<Integer> list = new ArrayList<>();

        for (int i = 0; i < n; i++) {
            list.add(sc.nextInt() - 1);
        }
        for (int i = 0; i < m; i++) {
            unionFind.unite(sc.nextInt() - 1, sc.nextInt() - 1);
        }

        int count = 0;
        for (int i = 0; i < n; i++) {
            if(unionFind.same(i, list.get(i))){
                count++;
            }
        }
        System.out.println(count);
    }


    static class UnionFind{
        int[] parent;

        public UnionFind(int N){
            this.parent = new int[N];
            for (int i = 0; i < N; i++){
                parent[i] = i;
            }
        }

        public int root(int x){
            if (parent[x] == x) return x;
            else{
                return parent[x] = root(parent[x]);
            }
        }
        public void unite(int x, int y){
            if (same(x, y)) return;
            int xroot = root(x);
            int yroot = root(y);
            parent[xroot] = yroot;
            return;
        }
        public boolean same(int x, int y){
            return (root(x) == root(y));
        }
    }
}

Measured memory_bytes: 93940
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy,bisect
from operator import itemgetter
#from heapq import heappush, heappop
#import numpy as np
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
#from scipy.sparse import csr_matrix
#from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
nf = lambda: float(ns())
na = lambda: list(map(int, stdin.readline().split()))
nb = lambda: list(map(float, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

N, M = na()
print(N * (N - 1) // 2 + M * (M - 1) // 2)




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

int N, X;
int L[100];

int main() {
  cin >> N >> X;
  rep(i, N) {
    cin >> L[i];
  }
  int cnt=1;
  int total=0;
  rep(i, N) {
    total += L[i];
    if(total > X) {
      cout << cnt << endl;
      return 0;
    }
    cnt++;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

using namespace std;
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; }


int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1000000000000000000;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using pLL = std::pair<long long, long long>;
using ll = long long;
#define SORT(v) std::sort(v.begin(), v.end())


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
    ll N,a[5],temp=LINF;
    cin >> N >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];
    
    for (int i = 0; i < 5; ++i) {
        temp = min(a[i], temp);
    }
    ll ans = 5;
    if (temp== 1) {
        cout << ans + N - 1 << endl;
        return 0;
    }
    if (N / temp == 0) {
        cout << ans << endl;
    }
    else if (N%temp == 0) {
        cout << ans+1 << endl;
    }
    else {
        ans += N / temp;
        cout << ans << endl;
    }
    
    
	return 0;
}

Measured memory_bytes: 256
// includes
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>

// macros
#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a); i<(b);++i)
#define rep(i, n) FOR(i, 0, n)

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;

// solve

bool is_digit(string s){
  rep(i, s.size()){
    if(!(s[i] >= '0' && s[i] <= '9'))return false;
  }
  return true;
}

int main(int argc, char const* argv[])
{
  string c;
  stack<string> st;
  while(cin >> c){
    if(is_digit(c)){
      st.push(c);
    }else{
      string a, b;
      b = st.top(); st.pop();
      a = st.top(); st.pop();
      if(c == "+")st.push(to_string(stoi(a) + stoi(b)));
      else if(c == "-")st.push(to_string(stoi(a) - stoi(b)));
      else if(c == "*")st.push(to_string(stoi(a) * stoi(b)));
    }
  }
  string s = st.top();
  cout << s << endl;
	return 0;
}



Measured memory_bytes: 3284
#include <iostream>

int main(){
  unsigned long N,A,B;
  std::cin >> N;
  std::cin >> A;
  std::cin >> B;
  const unsigned long a1 = (N/(A+B))*A;
  const unsigned long judge = N%(A+B);
  if(judge <= A){
    std::cout << a1 + judge << std::endl;
  }
  else{
    std::cout << a1 + A << std::endl;
  }
  return 0;
}

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


int main(){
	string S;
  	cin >> S;
  	if((S.at(2) == S.at(3))&&(S.at(4) == S.at(5))){
    	cout << "Yes" << endl;
    }
  	else{cout << "No" << endl;}
}

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


def gcd(a,b):
  x = max([a,b])
  y = min([a,b])
  while y:
    x, y = y, x % y
  return x

L = [0]
R = [0]

for i in range(N):
    L.append(gcd(L[-1], A[i]))
    
for i in reversed(range(N)):
    R.append(gcd(R[-1], A[i]))

R = list(reversed(R))


ans = 1
for i in range(N-1):
    ans = max(ans, gcd(L[i], R[i+1]))

# 上のループだと、左端を除いたパターンと右端を除いたパターンが含まれないのでここで考慮に入れる
ans = max(ans, R[1])
ans = max(ans, L[-2])

print(ans)
#print(R)
#print(L)

Measured memory_bytes: 14584
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;


public class Main {

    int A, B;
    private void solve() {
        A = nextInt();
        B = nextInt();
        out.println(A * B);
    }

    public static void main(String[] args) {
        out.flush();
        new Main().solve();
        out.close();
    }

    /* Input */
    private static final InputStream in = System.in;
    private static final PrintWriter out = new PrintWriter(System.out);
    private final byte[] buffer = new byte[4096];
    private int p = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (p < buflen)
            return true;
        p = 0;
        try {
            buflen = in.read(buffer);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (buflen <= 0)
            return false;
        return true;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrint(buffer[p])) {
            p++;
        }
        return hasNextByte();
    }

    private boolean isPrint(int ch) {
        if (ch >= '!' && ch <= '~')
            return true;
        return false;
    }

    private int nextByte() {
        if (!hasNextByte())
            return -1;
        return buffer[p++];
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = -1;
        while (isPrint((b = nextByte()))) {
            sb.appendCodePoint(b);
        }
        return sb.toString();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}

Measured memory_bytes: 25340
dish = [int(input()) for _ in range(5)]
min_i = 0
n = 10

for i in range(len(dish)):
  matu = list(str(dish[i]))
  matu = int(matu[-1])
  if n > matu and matu != 0:
    min_i = i
    n = matu
min_ = dish.pop(min_i)
sum_ = 0
for i in dish:
  if i%10 != 0:
    sum_ += (i//10 +1)*10
  else:
    sum_ += (i//10)*10
    
sum_ += min_
print(sum_)

Measured memory_bytes: 3064