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

using namespace std;

int main()
{
  int n , m , c , x=0;

  cin >> n >> m >> c;

  int b[25] , a[25][25] , s=c;

  for ( int i=0 ; i<m ; i++ )
  {
      cin >> b[i];
  }

  for ( int i=0 ; i<n ; i++ )
  {
      for ( int j=0 ; j<m ; j++)
      {
          cin >> a[i][j];
      }
  }

  for ( int i=0 ; i<n ; i++ )
  {
      for (int j=0 ; j<m ; j++)
      {
          s+=(a[i][j]*b[j]);
      }

      if ( s>0 )
      {
          x++;
      }

      s=c;
  }

  cout << x << endl;





    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int P[100];
    int N,A,B;
    int a=0,b=0,c=0;
    cin>>N>>A>>B;
    int temp;
    for(int i=0;i<N;i++){
	cin>>temp;
	if(temp<=A) a++;
	if(temp>A&&temp<=B) b++;
	if(temp>B) c++;
    }
    int ans=a;
    if(ans>b) ans=b;
    if(ans>c) ans=c;
    cout<<ans<<endl;
    return 0;
}
    

Measured memory_bytes: 256
#include <cassert>

template <class Monoid, template <class> class Container> class segment_tree {
public:
	using value_structure = Monoid;
	using value_type = typename value_structure::value_type;
	using container_type = Container<value_type>;
	using const_reference = typename container_type::const_reference;
	using size_type = typename container_type::size_type;

private:
	size_type size_, capacity;
	container_type c;
	static size_type getsize(const size_type size) {
		size_type ret = 1;
		while (ret < size)
			ret <<= 1;
		return ret;
	}
	void recalc(const size_type index) {
		c[index] = value_structure::operation(c[index << 1], c[index << 1 | 1]);
	}

public:
	segment_tree() : size_(0), capacity(0), c() {}
	explicit segment_tree(const size_type size)
		: size_(size), capacity(getsize(size_)),
		c(capacity << 1, value_structure::identity()) {}

	bool empty() const { return !size_; }
	size_type size() const { return size_; }

	const_reference operator[](const size_type index) const {
		assert(index < size());
		return c[index + capacity];
	}
	value_type fold(size_type first, size_type last) const {
		assert(first <= last);
		assert(first <= size());
		assert(last <= size());
		value_type ret_l = value_structure::identity(),
			ret_r = value_structure::identity();
		for (first += capacity, last += capacity; first < last;
			first >>= 1, last >>= 1) {
			if (first & 1)
				ret_l = value_structure::operation(ret_l, c[first++]);
			if (last & 1)
				ret_r = value_structure::operation(c[last - 1], ret_r);
		}
		return value_structure::operation(ret_l, ret_r);
	}
	template <class F> size_type search(const F &f) const {
		if (f(value_structure::identity()))
			return 0;
		if (!f(c[1]))
			return size() + 1;
		value_type acc = value_structure::identity();
		size_type i = 1;
		while (i < capacity)
			if (!f(value_structure::operation(acc, c[i <<= 1])))
				acc = value_structure::operation(acc, c[i++]);
		return i - capacity + 1;
	}

	void update(size_type index, const value_type &value) {
		assert(index < size());
		index += capacity;
		c[index] = value;
		while (index >>= 1)
			recalc(index);
	}
};

#include <algorithm>
#include <limits>
template <class T> class min_monoid {
public:
	using value_type = T;
	static value_type operation(const value_type &x, const value_type &y) {
		return ::std::min(x, y);
	}
	static value_type identity() {
		return 2147483647;
	}
	static value_type reverse(const value_type &x) { return x; }
};

#include <iostream>
#include <vector>

template<class T> using vec_alias = ::std::vector<T>;

int main() {
	int n, q;
	::std::cin >> n >> q;
	segment_tree<min_monoid<int>, vec_alias> seg(n);

	while (q--) {
		int c, x, y;
		::std::cin >> c >> x >> y;
		if (c)
			::std::cout << seg.fold(x, y + 1) << ::std::endl;
		else
			seg.update(x, y);
	}

	return 0;
}



Measured memory_bytes: 3796
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<iomanip>
#include<set>
#include<queue>

using namespace std;

int main()
{
	int n;
	cin >> n;
	string s;
	cin >> s;
	int cnt=0;
	for(int i=0;i<10;i++)
	for(int j=0;j<10;j++)
	for(int k=0;k<10;k++)
	{
		bool f1=false;
		bool f2=false;
		bool f3=false;
		for(int l=0;l<n;l++)
		{
			if(!f1)
			{
				if(s[l]=='0'+i)f1=true;
			}
			else if(!f2)
			{
				if(s[l]=='0'+j)f2=true;
			}
			else if(!f3)
			{
				if(s[l]=='0'+k)f3=true;
			}
			if(f1 and f2 and f3)
			{
				cnt++;
				break;
			}
		}
	}

	cout << cnt << endl;




}


Measured memory_bytes: 256
import math
x,y =map(int,input().split())
a=int(math.ceil(x/0.08))####
b=(x+1)/0.08
W=int(b)
if b!=W:
    xx=[i for i in range(a,W+1)]
elif b==W:
    xx=[i for i in range(a,W)]    
c=int(y/0.1)
d=int((y+1)/0.1)
yy=[i for i in range(c,d)]
sx=set(xx)
sy=set(yy)
Q=list(sx&sy)
if len(Q)==0:
  print(-1)
else:
  print(min(Q)) 

Measured memory_bytes: 3064
import math

class Vector():
    def __init__(self, x, y):
        self.x = x
        self.y = y

    def inner_product(self, vec):
        return self.x*vec.x + self.y*vec.y

    def outer_product(self, vec):
        return self.x*vec.y - self.y*vec.x

    def norm(self):
        return math.sqrt(self.x**2 + self.y**2)

n = int(input())
points = []
for i in range(n):
    x, y = list(map(int, input().split(' ')))
    points.append(Vector(x, y))
points.append(points[0])

area = 0
for i in range(n):
    a, b = points[i], points[i+1]
    if (a.x == 0 and a.y == 0) or (b.x == 0 and b.y == 0): continue
    theta = math.atan2(a.outer_product(b), a.inner_product(b))
    if theta > 0:
        area += abs(a.outer_product(b))/2
    elif theta < 0:
        area -= abs(a.outer_product(b))/2
print(area)


Measured memory_bytes: 5740
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string.h>
typedef long long ll;
#define MAX(x, y)	(((x) > (y))? (x) : (y))
#define MIN(x, y)	(((x) < (y))? (x) : (y))
#define ABS(x)		(((x) < 0)? (-1*(x)) : (x))
#define REPI(x,y)	for (int i=(x);i<(y);i++)
#define REPJ(x,y)	for (int j=(x);j<(y);j++)
#define MEMCLR(X)	memset((X),0,sizeof((X)))

using namespace std;
typedef pair<int, int> Point;
typedef vector<vector<Point>> Graph;

int i,j,N;
string s;

int main() {
	cin >> s;
	
	if ( ( s[0]==s[1] && s[1] == s[2] ) 
		|| ( s[1] == s[2] && s[2] == s[3] )
	) 	cout << "Yes";
	else 	cout << "No";	
	
	return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
using namespace std;
#include<stdio.h>
#include<string>
#include<malloc.h>
#include<string.h>
#include<stack>
#include<algorithm>
#include<map>
#include<utility>//pair
#define MAX 0x3f3f3f3f
int arr[100005];
bool solve(int n,int arr[])
{
	int i, count = 0, even = 0;;
	for (i = 0; i < n; i++) {
		if (arr[i] % 4 == 0)count++;
		else if (arr[i] % 2 == 0)even++;
		if(count>= n / 2)return true;
	}
	n -= count * 2;
	if (even >= n)return true;
	return false;
}

int main()
{
	int n;
	while (scanf("%d",&n)!=EOF) {
		for (int i = 0; i < n; i++)scanf("%d", &arr[i]);
		if (solve(n, arr))printf("Yes\n");
		else printf("No\n");
	}
	return 0;
}

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

using namespace std;

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

    int a[200001] = {};
    int cnt = 0;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        if (a[x] == 0) ++cnt;
        ++a[x];
    }

    int ans = 0;
    if (cnt <= k) {
        cout << ans << endl;
    } else {
        sort(a, a + 200001);
        int y = 200001 - cnt;
        while (k != cnt) {
            ans += a[y];
            --cnt;
            ++y;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {
    
    static int A;
    static int B ;
    static int Q;
    
    static long[] s;
    static long[] t;
    
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        A = sc.nextInt();
        B = sc.nextInt();
        Q = sc.nextInt();
        
        s = new long[A+2];
        t = new long[B+2];
        
        s[0] = 0L;
        for(int i = 1; i <= A; i++){
            s[i] = sc.nextLong();
        }
        s[A+1] = (long)1e10 + 5L;
        
        t[0] = 0L;        
        for(int i = 1; i <= B; i++){
            t[i] = sc.nextLong();
        }
        t[B+1] = (long)1e10 + 5L;        
        
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < Q; i++){
            long x = sc.nextLong(); 
            sb.append( minDistance(x) ).append("\r\n");
        }
        System.out.println(sb.toString());
    }
    
    static long minDistance(long x){
        
        int left = -1;
        int right = A+1;
        
        while(right - left > 1){
            int mid = (right + left) / 2;
            if( x < s[mid]) right = mid;
            if( s[mid] <= x) left = mid;
        }
        
        long minDistance = Long.MAX_VALUE;
        if( 0 < left ){
            long minL = minDistanceL(x, left);
            minDistance = Math.min(minDistance, minL);
        }
        if( right < A+1){
            long minR = minDistanceR(x, right);
            minDistance = Math.min(minDistance, minR);
        }
        
        return minDistance;
    }
    
    static long minDistanceL(long x, int sleft){
        
        int left = -1;
        int right = B+1;
        
        while( right - left > 1 ){
            int mid = (right + left) / 2;
            if( x < t[mid] ) right = mid;
            if( t[mid] <= x) left = mid;
        }
        
        if( 0 < left && s[sleft] <= t[left] ){
            return x - s[sleft];
        }
        
        long minDistanceL = Long.MAX_VALUE;
        if( 0 < left) {
            minDistanceL = Math.min(minDistanceL, x - t[left]);
        }
        
        if( right < B+1){
            long X = Math.min( t[right] - x, x - s[sleft] );
            minDistanceL = Math.min(minDistanceL, t[right] - s[sleft] + X);
        }
        
        return minDistanceL;
    }
    
    static long minDistanceR(long x, int sright){
        
        int left = -1;
        int right = B+1;
        
        while( right - left > 1 ){
            int mid = (right + left) / 2;
            if( x < t[mid] ) right = mid;
            if( t[mid] <= x) left = mid;
        }
        
        if( right < B+1 && t[right] <= s[sright] ){
            return s[sright] - x;
        }
        
        long minDistanceR = Long.MAX_VALUE;
        if( 0 < left) {
            long X = Math.min( s[sright] - x, x - t[left] );
            minDistanceR = Math.min(minDistanceR, s[sright] - t[left] + X);
        }
        
        if( right < B+1){
            minDistanceR = Math.min(minDistanceR, t[right] - x);
        }
        
        return minDistanceR;
    }    
}


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

using namespace std;

bool purePrimeDetermination(const int &n) {
	int size = int(sqrt(n)) + 1;
	for (int i = 2; i < size; ++i) {
		if (n%i == 0)
			return false;
	}
	return true;
}

int main() {
	int N, A; cin >> N;
	vector<int> a;
	for (int i = 0; i < N; ++i) {
		cin >> A;
		a.push_back(A);
	}

	int cnt = 0;

	for (auto it : a) {
		if (purePrimeDetermination(it)) {
			++cnt;
		}
	}

	cout << cnt << endl;
}


Measured memory_bytes: 3264
/**
*   @Author : MeGaCrazy
*   @InitTime : Sun Dec 30 15:08:12 2018
*   @Idea :
*
*
*
*
*
*  Happy Solving :)
**/
#include <bits/stdc++.h>
using namespace std;
int main(){
#ifndef ONLINE_JUDGE
   //freopen("in","r",stdin);
   //freopen("out","w",stdout);
#endif
   string s;
   cin>>s;
   set<string>f;
   f.insert("dream");
   f.insert("dreamer");
   f.insert("erase");
   f.insert("eraser");
   string cur="";
   reverse(s.begin(),s.end());
   for(int i=0;i<s.size();i++){
        cur.insert(0,string(1,s[i]));
        if(f.count(cur)){
          cur="";
        }	
   }
   if(cur==""){
    printf("YES");
   }
   else{
    printf("NO");
   }



}

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

using namespace std;

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

  long long n;
  cin >> n;
  long long ans = 0;
  auto test = [&](long long u) {
    long long nn = n;
    while (nn % u == 0) {
      nn /= u;
    }
    if (nn % u == 1) {
      ++ans;
    }
  };
  for (long long i = 1; i * i <= n; ++i) {
    if (n % i) {
      continue;
    }
    if (i != 1) {
      test(i);
    }
    if (n / i != i) {
      test(n / i);
    }
  }
  --n;
  for (long long i = 1; i * i <= n; ++i) {
    if (n % i) {
      continue;
    }
    if (i != 1) {
      ++ans;
    }
    if (n / i != i) {
      ++ans;
    }
  }
  cout << ans;

  return 0;
}

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

#define M 20000

typedef struct Data{
  int area, pos;
} Data;

Data B,X,t[M];
char str[M+1];
int i,n,ans,T,U,A,u[M];


void D_push(Data);

Data D_pop();

void push(int);

int pop();

void init();
 
Data makeData(int, int);

int main(){
  
  init();
  
  scanf("%s", str);
  
  n = strlen(str);

  for( i = 0 ; i < n ; i++){

    if(str[i] == '/'){

      if( U == 0 ) continue;
      A = pop();
      X = makeData( i-A, A);
      ans += i - A;
      while( T > 0 ){
        B = D_pop();
        if( B.pos < A ){
          D_push(B);
          break;
        }
        X.area += B.area;
        if(B.pos<X.pos){
	  X.pos = B.pos;
	}
      }
      D_push(X);
    }
    else if( str[i] == '\\' ){
      push(i);
    }

  }

  printf("%d\n%d", ans, T);
  
  for( i = 0 ; i < T ; i++ ){
    printf(" %d", t[i].area);
  }
  
  printf("\n");

  return 0;
}

void D_push(Data data){
  t[T++] = data;
}
Data D_pop(){
  return t[--T];
}

void push(int x){
  u[U++] = x;
}

int pop(){
  return u[--U];
}

void init(){
  ans = T = U = 0;
}

Data makeData(int x, int y){
  Data res;
  res.area = x;
  res.pos = y;
  return res;
}



Measured memory_bytes: 2096
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e17)
template<class T> bool chmax(T &a,  T b) {if(a<b){a=b; return 1;} return 0;}
template<class T> bool chmin(T &a,  T b) {if(a>b){a=b; return 1;} return 0;}
bool Add(int &a,int b){a = (a + b) % MOD;}
void myprint(int* A,int A_num){
   REP(i,A_num) cout << A[i] << " ";
   cout << endl;
}

signed main(){
    int n;
    cin >> n;
    int id = 0;
    int ma = -1;
    int A[n];
    REP(i,n){
        cin >> A[i];
        if(ma < abs(A[i])){
            ma = abs(A[i]);
            id = i;
        }
    }
    bool flag = true;
    cout << 2 * n - 2 << endl;
    REP(i,n){
        if(i == id) continue;
        cout << id + 1 << " " << i + 1 << endl;
        A[i] += A[id];
        if(A[i] < 0) flag = false;
    }

    if(flag){
        REP(i,n-1){
            cout << i + 1 << " " << i +  2 << endl;
        }
    }
    else{
        REPR(i,n-1){
            if(i == 0) break;
            cout << i + 1 << " " << i  << endl;
        }
    }

}

Measured memory_bytes: 256
from itertools import accumulate

N, X, *A = map(int, open(0).read().split())

S = list(accumulate(A))

ans = float("inf")
for k, s in enumerate(S, 1):
    E = k * X + 2 * sum(S[j] for j in range(N - 2 * k - 1, -1, -k))
    ans = min(ans, E)

print(ans + N * X + 5 * S[-1])

Measured memory_bytes: 25884
#include <bits/stdc++.h>
#define i_love_u_Phuong ios_base::sync_with_stdio(0); cin.tie(0);

using ll = long long;
using namespace std;
using ld = long double;




int main()
{
#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
#endif // ONLINE_JUDGE
    i_love_u_Phuong;
    int n;
    cin >> n;
    n*=2;
    vector<int> a(n);
    for(int i=0; i<n; ++i) cin >> a[i];
    sort(a.begin(), a.end());
    int ans=0;
    for(int i=n-1; i>=1; i-=2)
        ans+=min(a[i],a[i-1]);
    cout << ans;
    return 0;
}



Measured memory_bytes: 256
#define rep(i,n) REP(i,0,n)
#define REP(i, a, b) for(int i = a; i < (int)(b); i++)
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
template<class T> inline void chmax(T &a, const T &b) {if(a < b) a = b;}
template<class T> inline void chmin(T &a, const T &b) {if(a > b) a = b;}
const long long INF = 1LL<<60;

const ll MAXN = (ll)1e5+10;
const ll DIV = (ll)1e9+7;
// ll dp[MAXN][MAXN];

int dp[MAXN];
vector<int> A;
int GetWin(int k) {
   if (dp[k]>=0) return dp[k];
   for (auto el: A) {
      if (k-el<0) continue;
      if (GetWin(k-el)==1) dp[k] = 0;
   }
   if (dp[k]<0) dp[k] = 1;
   return dp[k];
}

int main(void) {
   int N,K;
   cin>>N>>K;
   A.resize(N);
   rep(i,N) cin>>A[i];
   rep(i,MAXN) dp[i] = -1;
   dp[0]  =1;
   rep(i,K) GetWin(i);
   if (GetWin(K)) cout<<"Second"<<endl;
   else cout<<"First"<<endl;

   return 0;
}

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i, n) for(int i = (int)(n); i >= 0; i--)
#define repm(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define repmr(i, m, n) for(int i = (int)(n); i >= (int)(m); i--)
#define all(x) (x).begin(),(x).end()
#define inf 2e9
#define MOD 1000000007

using namespace std;
typedef long long ll;

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

  ll ans;
  if(n == 100){
    ans = (n+1)*pow(100,d);
  }
  else{
    ans =  n*pow(100,d);
  }

  cout << ans << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <map>
#include <vector>
#include <set>
#include <cmath>
#include <string>
#include <algorithm>
#include <queue>

using namespace std;

#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)
#define all(c) (c).begin(), (c).end()

typedef unsigned long long ull;
typedef vector<int> vi;

int d[10] = {1,1,4,4,2,1,1,4,4,2};
int dd[10][4]{
    { 0, 0, 0, 0 },
    { 1, 1, 1, 1 },
    { 2, 4, 8, 6 },
    { 3, 9, 7, 1 },
    { 4, 6, 4, 6 },
    { 5, 5, 5, 5 },
    { 6, 6, 6, 6 },
    { 7, 9, 3, 1 },
    { 8, 4, 2, 6 },
    { 9, 1, 9, 1 }
};

int main(){
    long long n, m, k;
    cin >> n >> m >> k;

    long long nn = n % 10;
    long long mm = m % d[nn];

    long long kk = k / d[nn];
    long long kkk = k % d[nn];
    long long ans = 0;
    

    if (mm == 1){
        rep(i, d[nn]){
            ans += dd[nn][i] * kk;
        }
        rep(i, kkk){
            ans += dd[nn][i];
        }
    }
    else if (mm == 2){
        ans += dd[nn][0] * 2 * kk + dd[nn][2] * 2 * kk;
        if (kkk >= 1){
            ans += dd[nn][0];
        }
        if (kkk >= 2){
            ans += dd[nn][2];
        }
        if (kkk >= 3){
            ans += dd[nn][0];
        }
    }
    else if (mm == 3) {
        rep(i, 4){
            ans += dd[nn][i] * kk;
        }
        if (kkk > 0){
            ans += dd[nn][0];
            kkk--;
            for (int i = 3; i > 3 - kkk; i--){
                ans += dd[nn][i];
            }
        }
    }

    if (mm == 0) cout << nn*k << endl;
    else cout << ans << endl;
    return 0;
}


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


int main() {
	double N,K;
	cin >> N >> K;
	double prob=0;
	int point=0;
	if(K<N){
		for(int i=1;i<K;i++){
			double p=1.0/N;
			point = i;
			while(point<K){
				p=p*0.5;
				point = point*2;
			}
			prob = prob + p;
		}
		prob += (N-K+1)/N;
		printf("%.16f\n",prob);
	}
	else{
		for(int i=1;i<=N;i++){
			double p=1.0/N;
			point = i;
			while(point<K){
				p=p*0.5;
				point = point*2;
			}
			prob = prob + p;
		}
		printf("%.16f\n",prob);
	
	}
}


Measured memory_bytes: 256
import sys, math
from collections import deque

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    N, K = mi()
    N -= K
    print(N if K!=1 else 0)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9488
MM = input().split()
N = int(MM[0])
M = int(MM[1])
C = int(MM[2])
count= 0
BB = input().split()
for i in range(N):
  AA = input().split()
  total = C
  for i,j in zip(BB,AA):
    
    total += int(i)*int(j)
  
  if total >0:
    count +=1
print(count)

Measured memory_bytes: 9152
#include<bits/stdc++.h>
using namespace std;
const unsigned int M = 1000000007;
int main(){
 string s,t;
 cin >> s;
 cin >> t;
 int ans = t.size();
 for(int i= 0;i<=s.size()-t.size();i++){
   int diff = 0;
   for(int j= 0;j<t.size();j++){
     if(t[j]!=s[i+j]){
       diff++;
     }
   }
   ans = min(ans,diff);
 }
 cout << ans << endl;
 return 0;
}

Measured memory_bytes: 3584
import sys
import math

def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))
def RN(N): return [input().strip() for i in range(N)]


def main():
    A, B, H, M = MI()
    th_h = (H / 12+ M / 720) * 360 
    th_m = M / 60 * 360 
    theta = abs(th_h-th_m)
    rad = math.radians(theta)
    ans2 = pow(A,2) + pow(B,2) - 2*A*B*math.cos(rad)

    print(pow(ans2,0.5))


if __name__ == "__main__":
	main()

Measured memory_bytes: 62616
N=int(input())

A=list(map(int,input().split()))

B=[sum(A)]

for i in range(1,N,2):
    B[0]-=2*A[i]

for i in range(N-1):
    B.append(2*A[i]-B[i])

print(' '.join(map(str,B)))
    


Measured memory_bytes: 19144
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Zayakin Andrey
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Input in = new Input(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, Input in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = in.nextIntArray(n);
            int r = 102;
            int[][] dp = new int[n + 1][r + 1];
            for (int[] d : dp) {
                Arrays.fill(d, Integer.MAX_VALUE / 2);
            }
            dp[0][r] = 0;
            for (int i = 0; i < n; i++) {
                for (int p = 1; p <= r; p++) {
                    for (int j = 1; j <= r; j++) {
                        if (dp[i][p] >= Integer.MAX_VALUE / 2) {
                            continue;
                        }
                        if (p != j) {
                            dp[i + 1][j] = Math.min(dp[i + 1][j], dp[i][p] +
                                    (j == a[i] ? 0 : 1));

                        }
                    }
                }
            }
            int best = Integer.MAX_VALUE / 2;
            for (int p = 1; p <= r; p++) {
                best = Math.min(best, dp[n][p]);
            }
            out.println(best);
        }

    }

    static class Input {
        private StringTokenizer tokenizer = null;
        private BufferedReader reader;

        public Input(InputStream inputStream) {
            reader = new BufferedReader(new InputStreamReader(inputStream));
        }

        public String nextLine() {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException();
            }
        }

        public String nextToken() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                tokenizer = new StringTokenizer(nextLine());
            }
            return tokenizer.nextToken();
        }

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

        public int[] nextIntArray(int n, int add) {
            int[] result = new int[n];
            for (int i = 0; i < n; i++) {
                result[i] = nextInt() + add;
            }
            return result;
        }

        public int[] nextIntArray(int n) {
            return nextIntArray(n, 0);
        }

    }
}



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

#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

int main() {

    long long int a, b, c, k;
    cin >> a >> b >> c >> k;

    if ( k <= a ) {
        cout << k << endl;
    } else if ( k <= a + b ) {
        cout << a << endl;
    } else {
        cout << a - ( k - a - b ) << endl;
    }

    return 0;

}


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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    ll N, A[100000], ans = 0, mc = 0, abs_min = 1e9;
    cin >> N;
    REP(i, N) {
        cin >> A[i];
        ans += abs(A[i]);
        abs_min = min(abs_min, abs(A[i]));
        if (A[i] < 0) mc++;
    }

    if (mc % 2 == 0) cout << ans << endl;
    else cout << ans - abs_min * 2 << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main() {
  long int a, b, c, x, y, result, result1, result2, result3;
  result = result1 = result2 = result3 = 0;
  cin >> a >> b >> c >> x >> y;
  result1 = (a * x) + (b * y);
  if (x < y) {
    result2 = (c * x * 2) + (b * (y - x));
    result3 = (c * y * 2);
  } else if (x > y) {
    result2 = (c * y * 2) + (a * (x - y));
    result3 = (c * x * 2);
  } else if (x == y) {
    result2 = (c * y * 2) + (a * (x - y));
    result3 = (c * x * 2);
  }
  if (result1 < result2 && result2 < result3) {
    result = result1;
  } else if (result1 > result2 && result2 < result3) {
    result = result2;
  } else if (result1 < result2 && result2 > result3) {
    if (result1 < result3) {
      result = result1;
    } else {
      result = result3;
    }
  } else {
    result = result3;
  }
  cout << result << endl;
}

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

using namespace std;

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

	if ( k - n <= 1 ) printf("%d", k - n);
	else if ( n == 1 ) {
		printf("0");
	}
	else {
		printf("%d", max({k, n}) - min({k, n}));
	}
	
	return 0;
}

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

int main(void) {
    int N;
    cin >> N;
    vector<int> T(N), A(N);
    for (int i = 0; i < N; i++) {
        cin >> T[i] >> A[i];
    }
    long long t = 1, a = 1;
    for (int i = 0; i < N; i++) {
        long long x = max((t + T[i] - 1) / T[i], (a + A[i] - 1) / A[i]);
        t = x * T[i];
        a = x * A[i];
    }
    cout << t + a << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 100000000000
#define MOD 1000000007
#define ll long long int
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()




using namespace std;



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


  return 0;
}

Measured memory_bytes: 3636
class Dice:
    def __init__(self):
        self.faces=[]

    def rotate(self, direction):
        tmp = self.faces.copy()

        if direction =="N":
            self.faces[5-1] = tmp[1-1]
            self.faces[1-1] = tmp[2-1]
            self.faces[2-1] = tmp[6-1]
            self.faces[6-1] = tmp[5-1]
        if direction =="S":
            self.faces[5-1] = tmp[6-1]
            self.faces[1-1] = tmp[5-1]
            self.faces[2-1] = tmp[1-1]
            self.faces[6-1] = tmp[2-1]
        if direction =="W":
            self.faces[4-1] = tmp[1-1]
            self.faces[1-1] = tmp[3-1]
            self.faces[3-1] = tmp[6-1]
            self.faces[6-1] = tmp[4-1]
        if direction =="E":
            self.faces[3-1] = tmp[1-1]
            self.faces[1-1] = tmp[4-1]
            self.faces[4-1] = tmp[6-1]
            self.faces[6-1] = tmp[3-1]
        return 0

    def spin(self):
        self.faces[4-1], self.faces[2-1],self.faces[5-1],self.faces[3-1] =\
        self.faces[2-1], self.faces[3-1],self.faces[4-1],self.faces[5-1]

        return 0

res = "Yes"
dices = []
lines = int(input())
for i in range(lines):
    dices.append(Dice())
    dices[i].faces=[int(x) for x in input().split(" ")]

#set up side
for i, d1 in enumerate(dices):
    for d2 in dices[i+1 :]:
        for _ in range(3):
            for _ in range(4):
                for ___ in range(4):
                    #print("d1: {}".format(d1.faces))
                    #print("d2: {}".format(d2.faces))
                    if d1.faces == d2.faces:
                        res = "No"
                        break
                    d2.spin()
                d2.rotate("W")
            d2.rotate("N")

print(res)

Measured memory_bytes: 7824
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

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

    int n;
    cin >> n;
    if(n < 1000){
        cout << "ABC\n";
    }
    else{
        cout << "ABD\n";
    }
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;

void solve() {
	int r;
	static const double PI = acos(-1);
	cin >> r;
	cout << 2 * PI * r << "\n";
}

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int o_o = 1;
  if (!o_o)
    cin >> o_o;
  for (; o_o; --o_o)
    solve();
  return 0;
}


Measured memory_bytes: 3260
A, B, K = map(int, input().split())

for i in range(K):
    if A + i <= B:
        print(A + i)

for j in range(K):
    if (B - K + j + 1 > A + K - 1) and (B - K + j + 1 <= B):
        print(B - K + j + 1)

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

using namespace std;

const int md = int(1e9) + 7;

inline void add(int &a, int b) {
  a += b;
  if (a >= md) a -= md;
}

inline void sub(int &a, int b) {
  a -= b;
  if (a < 0) a += md;
}

inline int mul(int a, int b) {
  return (int) ((long long) a * b % md);
}

inline int power(int a, long long b) {
  int res = 1;
  while (b > 0) {
    if (b & 1) {
      res = mul(res, a);
    }
    a = mul(a, a);
    b >>= 1;
  }
  return res;
}

inline int inv(int a) {
  a %= md;
  if (a < 0) a += md;
  int b = md, u = 0, v = 1;
  while (a) {
    int t = b / a;
    b -= t * a; swap(a, b);
    u -= t * v; swap(u, v);
  }
  assert(b == 1);
  if (u < 0) u += md;
  return u;
}

const int N = 404;
int dp[N][N];

int main() {
  int n, C;
  cin >> n >> C;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  vector< vector<int> > coef(n, vector<int>(C + 1));
  for (int i = 0; i < n; i++) {
    for (int j = a[i]; j <= b[i]; j++) {
      int c = 1;
      for (int k = 0; k <= C; k++) {
        add(coef[i][k], c);
        c = mul(c, j);
      }
    }
  }

  dp[0][0] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= C; j++) {
      for (int k = j; k >= 0; k--) {
        add(dp[i + 1][j], mul(dp[i][k], coef[i][j - k]));
      }
    }
  }

  cout << dp[n][C] << '\n';

  return 0;
}

Measured memory_bytes: 1536
#include<iostream>
#include<cmath>
#include<stack>
#include<vector>
#include<cstring>
#include<algorithm>
#include<set>
#include<queue>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <complex>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cassert>
using namespace std;
typedef long long ll;
const ll inf =1e17;
#define scn(a) scanf("%d",&a)
#define scd(a) scanf("%lf",&a)
#define scl(a) scanf("%lld",&a)
#define ptf(a) printf("%d\n",&a)
#define mes(a,b) memset(a,b,sizeof(a))
#define fon(s,n) for(int i=s;i<=n;i++)
#define range(i,a,b) for(int i=a;i<=b;++i)
#define rerange(i,a,b) for(int i=a;i>=b;--i)
//#define N 100010
const int S=20;
int gcd(int a,int b) { return b>0 ? gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
ll q_pow(ll a,ll b,ll mod)
{
	ll ans=1,res=a;
	while(b){
		if(b&1) ans=ans*res%mod;
		res=res*res%mod;
		b>>=1;
	}
	return ans%mod;
}


int main()
{
	int n,temp;
    ll sum=0;
	scn(n);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			for(int k=1;k<=n;k++)
				temp=gcd(i,j),temp=gcd(k,temp),sum+=temp;
	printf("%lld\n",sum);
	return 0;
}



Measured memory_bytes: 3716
N= int(input())
B = list(map(int,input().split()))
A = [0]*N
A[0] = B[0]
for i in range(len(A)-2):
    A[i+1] = min(B[i],B[i+1])
    
A[-1] = B[-1]  
#print(A)
print(sum(A))

Measured memory_bytes: 9136
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
    class Program
    {
        private const int MODULO = 1000000007;
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static long Func(long b, long n)
        {
            return (n < b) ? n : Func(b, n / b) + n % b;
        }
        static long Solve(long n, long s)
        {
            if (s > n) { return -1; }
            if (s == n) { return n + 1; }
            long b;
            for (b = 2; b * b <= n; ++b)
            {
                if (Func(b, n) == s) { return b; }
            }
            long min = long.MaxValue;
            for (int i = 1; i <= b; ++i)
            {
                if ((n - s) % i == 0)
                {
                    long a = (n - s) / i + 1;
                    if (Func(a, n) == s) { min = Math.Min(a, min); }
                }
            }
            return (min < long.MaxValue) ? min : -1;
        }
        static void Main(string[] args)
        {
            long n = ReadLong();
            long s = ReadLong();
            Console.WriteLine(Solve(n, s));
        }
    }
}


Measured memory_bytes: 11220
import java.lang.*;
import java.io.*;
import java.util.*;
import java.util.stream.*;

public class Main{
	static void swap(int[] arr, int index1, int index2){
		int temp = arr[index1];
		arr[index1] = arr[index2];
		arr[index2] = temp;
	}
	static void heapify(int index, int[] arr, int n){
		int parent = index;
		int l = 2*parent + 1;  
		int r = 2*parent + 2; 
		int next_parent = parent;
    	if (l < n && arr[l] < arr[parent]) 
        	next_parent = l; 
    	if (r < n && arr[r] < arr[next_parent]) 
        	next_parent = r; 
    	if (next_parent != parent){ 
        	swap(arr,parent,next_parent); 
        	heapify(next_parent, arr, n); 
    	}
	}
	static void buildHeap(int[] arr, int n){
		int last_non_leaf_node = (n/2) - 1;
		for(int i=last_non_leaf_node;i>=0;--i)
			heapify(i,arr,n);
	}
	static void heapifyM(int index, int[] arr, int n){
		int parent = index;
		int l = 2*parent + 1;  
		int r = 2*parent + 2; 
		int next_parent = parent;
    	if (l < n && arr[l] > arr[parent]) 
        	next_parent = l; 
    	if (r < n && arr[r] > arr[next_parent]) 
        	next_parent = r; 
    	if (next_parent != parent){ 
        	swap(arr,parent,next_parent); 
        	heapifyM(next_parent, arr, n); 
    	}
	}
	static void buildHeapMax(int[] arr, int n){
		int last_non_leaf_node = (n/2) - 1;
		for(int i=last_non_leaf_node;i>=0;--i)
			heapifyM(i,arr,n);
	}
	static void rev(int[] arr) 
    { 
        int n = arr.length;
        int i, k, t; 
        for (i = 0; i < n / 2; i++) { 
            t = arr[i]; 
            arr[i] = arr[n - i - 1]; 
            arr[n - i - 1] = t; 
        }
    }
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int y = sc.nextInt();
		int na = sc.nextInt();
		int nb = sc.nextInt();
		int nc = sc.nextInt();

		int[] a = new int[na];
		int[] b = new int[nb];
		int[] c = new int[nc];
		
		for(int i=0;i<na;++i) a[i] = sc.nextInt();
		for(int i=0;i<nb;++i) b[i] = sc.nextInt();
		for(int i=0;i<nc;++i) c[i] = sc.nextInt();
		
		Arrays.sort(a);
		Arrays.sort(b);
		Arrays.sort(c);

		rev(a);
		rev(b);
		rev(c); 
		
		int[] heapA = new int[x];
		int[] heapB = new int[y];
		
		for(int i=0;i<x;++i) heapA[i] = a[i];
		for(int i=0;i<y;++i) heapB[i] = b[i];
		
		long valA = 0;
		long valB = 0;
		for(int i=0;i<x;++i) valA += (long)heapA[i];
		for(int i=0;i<y;++i) valB += (long)heapB[i];
		
		buildHeap(heapA,x);
		buildHeap(heapB,y);

		buildHeapMax(c,nc);

		// System.out.println(Arrays.toString(heapA));
		// System.out.println(Arrays.toString(heapB));
		// System.out.println(Arrays.toString(c));
		// System.out.println(valA + " " + valB);

		while (c[0] > heapA[0] || c[0] > heapB[0]){
			if (heapA[0] < heapB[0]){
				if (c[0] > heapA[0]){
					valA -= heapA[0];
					valA += c[0];
					int temp1 = heapA[0];
					heapA[0] = c[0];
					c[0] = temp1;
					heapifyM(0,c,nc);
					heapify(0,heapA,x);
				}
			}
			else{
				if (c[0] > heapB[0]){
					valB -= heapB[0];
					valB += c[0];
					int temp2 = heapB[0];
					heapB[0] = c[0];
					c[0] = temp2;
					heapifyM(0,c,nc);
					heapify(0,heapB,y);
				}
			}
		}

		System.out.println(valA + valB);
	}
}


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

const int N = 1e4 + 10;

int key, sum = 0;
int a[N];
int n, q;

int search(int a[], int n, int key)
{
    int i = 0;
    a[n] = key; //?  0-n-1   如果走到n了  就没有该值
    while(a[i] != key) i++;
    return i != n;
}

int main(void)
{
    scanf("%d", &n);
    for(int i = 0; i < n; i++) scanf("%d", &a[i]);
    scanf("%d", &q);
    while(q--)
    {
        scanf("%d", &key);
        if(search(a, n, key)) sum++;
    }
    printf("%d\n", sum);
    return 0;
}



Measured memory_bytes: 3220
N = int(input())
A = [0] + list(map(int, input().split())) + [0]

full = sum(abs(A[i] - A[i+1]) for i in range(0, N+1))

for i in range(1, N+1):
  if A[i-1] <= A[i] <= A[i+1]:
    print(full)
  else:
    print(full - abs(A[i-1] - A[i]) - abs(A[i] - A[i+1]) + abs(A[i-1] - A[i+1]))

Measured memory_bytes: 14176
#include<bits/stdc++.h>
using namespace std;
int main()
{
	
	int b;
	cin>>b;
	char a[100];
	cin>>a;
	int s=strlen(a);
	if(b<s)
	{
		a[b]='\0';
		cout<<a<<"...";
	}
	else
	{
		cout<<a;
	}
}

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


int main(){
    int n;
    int a[100];
    int p, q;

    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a[i];   
    }
    p = a[0];
    q = a[0];
    for(int i=0;i<n;i++){
        if(a[i] < p) p = a[i];
        if(a[i] > q) q = a[i];   
    }
    cout << q - p << endl;
	
	
	return 0;
}


Measured memory_bytes: 764
// D - Equals

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

class DisjointSet {
public:
	int size;
	vector<int> rank;
	vector<int> parent;

	DisjointSet() {}

	// 0, 1, ... size-1 をそれぞれ唯一の要素とする
	// size個の互いに素な集合を作成
	DisjointSet(int size) {
		this->size = size;
		rank.resize(size, 0);
		parent.resize(size, 0);
		for (int i=0; i<size; i++) {
			makeSet(i);
		}
	}

	// 要素がXただ一つである新しい集合を作る
	void makeSet(int x) {
		parent[x] = x;
		rank[x] = 0;
	}

	// xとyが同じ集合に属しているかを判定する
	bool same(int x, int y) {
		return findSet(x) == findSet(y);
	}

	// 指定された2つの要素x, yを合併する
	void unite(int x, int y) {
		link(findSet(x), findSet(y));
	}

	// 低い方の木を高い方の木に合併
	void link(int x, int y) {
		if (rank[x] > rank[y]) {
			parent[y] = x;
		} else {
			parent[x] = y;
			if (rank[x] == rank[y]) {
				rank[y]++;
			}
		}
	}

	// 要素xが属する集合の代表の要素を求める
	int findSet(int x) {
		if (x != parent[x]) {
			parent[x] = findSet(parent[x]);
		}
		return parent[x];
	}

	// 集合の個数を求める
	int countSet() {
		int cnt = 0;
		for (int x=0; x<size; x++) {
			if (x == parent[x]) cnt++;
		}
		return cnt;
	}
};

int p[100000];

int main() {
	int N, M;
	cin >> N >> M;

	DisjointSet ds = DisjointSet(N);
	unordered_map<int, unordered_set<int>> grp_to_idx;

	for (int i=0; i<N; i++) {
		cin >> p[i];
		p[i]--;
	}

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

		ds.unite(x, y);
	}

	for (int i=0; i<N; i++) {
		int grp = ds.findSet(p[i]);
		grp_to_idx[grp].insert(i);
	}

	int ans = 0;

	for (int i=0; i<N; i++) {
		int grp = ds.findSet(p[i]);
		if (grp_to_idx[grp].count(p[i]) >= 1) ans++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 19616
#include<stdio.h>
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,m[100][100],color[100],d[100],f[100],tt;

void dfs_v(int u){
  int v;
  color[u]=GRAY;
  d[u]=++tt;
  for(v=0;v<n;v++){
    if(m[u][v]==0)continue;
    if(color[v]==WHITE){
      dfs_v(v);
    }
  }
  color[u]=BLACK;
  f[u]=++tt;
}

void dfs(){
  int u;
  for(u=0;u<n;u++){
    color[u]=WHITE;
  }
  tt=0;
  for(u=0;u<n;u++){
    if(color[u]==WHITE)dfs_v(u);
  }
  for(u=0;u<n;u++){
    printf("%d %d %d\n",u+1,d[u],f[u]);
  }
}

int main(){
  int u,v,k,i,j;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      m[i][j]=0;
    }
  }

  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      m[u][v]=1;
    }
  }
  dfs();
  return 0;
}



Measured memory_bytes: 2108
let pn = 1000003

let pow x n =
  let rec doit i acc =
    if i = n then acc
    else doit (i + 1) (acc*x)
  in doit 0 1

let str_fold_left f init s =
  let n = String.length s in
  let rec doit i acc =
    if i = n then acc
    else doit (i + 1) (f acc s.[i])
  in doit 0 init

let () =
  let p = read_line () in
  let t = read_line () in
  let n = String.length p in
  let m = String.length t in
  let h = Array.make (n + 1) 0 in
  String.iteri (fun i c -> h.(i+1) <- h.(i)*pn + Char.code c) p;
  let ht = str_fold_left (fun acc c -> acc*pn + Char.code c) 0 t in
  let x = pow pn m in
  let rec doit i =
    if i <= n then begin
      if h.(i) - h.(i-m)*x = ht then Printf.printf "%d\n" (i - m);
      doit (i + 1)
    end in
  doit m

Measured memory_bytes: 14384
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (n);i++)
using ll = long long;
const ll MOD=1000000007;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);

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 main() 
{
  ll N,M; cin>>N>>M;
  vector<vector<ll>> s(M,vector<ll>(0));
  rep(i,M)
  {
    ll k; cin>>k;
    rep(j,k)
    {
      ll ss; cin>>ss; ss--;
      s.at(i).push_back(ss);
    }
  }
  vector<ll> p(M);
  rep(i,M)
  {
    cin>>p.at(i);
  }
  
  ll ans=0;
  rep(i,1<<N)
  {
    bitset<10> i2(i);
    bool judge=true;
    rep(j,M)
    {
      ll sum=0;
      for(auto ss:s.at(j))
      {
        if(i2.test(ss)) sum++;
      }
      sum%=2;
      if(p.at(j)!=sum) judge=false;
    }
    if(judge) ans++;
  } 
  cout<<ans<<endl;
  return 0;
}


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

int N;
map<string,int> m;

int main()
{
    cin>>N;
    for(int i=0;i<N;i++)
    {
        string si;
        cin>>si;
        sort(si.begin(),si.end());
        m[si]++;
    }
    long  long sum=0;
    for(map<string,int>::iterator it=m.begin();it!=m.end();it++)
    {
        sum+=it->second*1LL*(it->second*1LL-1)/2;
    }
    cout<<sum<<endl;
    return 0;
}


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

#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

#define rep(i, n) for (int i = 0; i < (n); i++)
#define mins(x, y) (x = min(x, y))
#define maxs(x, y) (x = max(x, y))
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using P = pair<int, int>;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

void solve() {
  int n;
  cin >> n;
  vi a(n);
  rep(i, n) cin >> a[i];
  map<int, int> mp;
  rep(i, n) mp[a[i]]++;
  int q;
  cin >> q;
  ll sum = 0;
  for (auto m : mp) {
    sum += ((ll)m.first * m.second);
  }
  rep(i, q) {
    int b, c;
    cin >> b >> c;
    int cnt = mp[b];
    sum += ((ll)mp[b] * (c - b));
    mp[c] += cnt;
    mp[b] = 0;
    cout << sum << endl;
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}

Measured memory_bytes: 7964
#include<stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,M[N][N];
int color[N],d[N],f[N],tt;

void dfs_visit(int u){
    int v;
    color[u] = GRAY;
    d[u] = ++tt;
    for(v = 0;v<n;v++){
        if(M[u][v] == 0)continue;
        if(color[v] == WHITE){
            dfs_visit(v);
        }
    }
    color[u] = BLACK;
    f[u] = ++tt;
}

void dfs(){
    int u;
    for(u = 0;u < n;u++){
        color[u] = WHITE;
    }
    tt = 0;
    
    for(u = 0;u<n;u++){
    if(color[u] == WHITE) dfs_visit(u);
    }
    for(u = 0;u < n;u++){
        printf("%d %d %d\n",u+1,d[u],f[u]);
    }
}

int main(){
    int u,v,k,i,j;
    
    scanf("%d",&n);
    for(i = 0;i<n;i++){
        for(j = 0;j<n;j++)M[i][j]=0;
    }
    
    for(i = 0;i<n;i++){
        scanf("%d %d",&u,&k);
        u--;
        for(j = 0;j < k;j++){
            scanf("%d",&v);
            v--;
            M[u][v] = 1;
        }
    }
    
    dfs();
    
    return 0;
}


Measured memory_bytes: 2068