akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

typedef long long ll;

int main(){
  int X, Y, A, B, C, tmp;
  cin >> X >> Y >> A >> B >> C;
  priority_queue<int> P;
  priority_queue<int> Q;
  priority_queue<int> R;
  for (int i=0; i<A; i++){
    cin >> tmp;
    P.push(-tmp);
  }
  for (int i=0; i<B; i++){
    cin >> tmp;
    Q.push(-tmp);
  }
  for (int i=0; i<C; i++){
    cin >> tmp;
    R.push(tmp);
  }
  while (P.size() > X){
    P.pop();
  }
  while (Q.size() > Y){
    Q.pop();
  }
  //cerr << P.top() << " " << Q.top() << " " << R.top() << endl;
  while (!R.empty() && (R.top() > -P.top() || R.top() > -Q.top())){
    int tar = R.top();
    R.pop();
    int inc_r = R.top() + P.top();
    int inc_g = R.top() + Q.top();
    //cerr << tar << " " << inc_r << " " << inc_g << endl;
    if (P.size() < X) inc_r = 0;
    if (Q.size() < Y) inc_g = 0;
    if (inc_r < inc_g){
      if (Q.size() >= Y){
      	Q.pop();
      }
      Q.push(-tar);
    }
    else{
      if (P.size() >= X){
      	P.pop();
      }
      P.push(-tar);
    }
  }
  
  ll ans = 0;
  while (!P.empty()){
    ans += -P.top();
    P.pop();
  }
    while (!Q.empty()){
    ans += -Q.top();
    Q.pop();
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1912
from math import sqrt
from itertools import accumulate

def inpl(): return list(map(int, input().split()))

MOD = 10**9 + 7
N, K = inpl()

p = 0
X = []
for i in range(1, int(sqrt(N))+1):
    X.append(N//i)

A = [1]*len(X) 
B = [X[-2-i] - X[-1-i] for i in range(len(X)-1)]
if sum(A) + sum(B) < N:
    C = A + [N-sum(A)-sum(B)] + B
else:
    C = A + B

DP = [c%MOD for c in C]

for _ in range(K-1):
    DP2 = [0]*len(C)
    S = [0]*len(C)
    S[0] = DP[0]*1
    for i in range(1, len(C)):
        S[i] = (S[i-1] + DP[i])%MOD

    for i in range(len(C)):
        DP2[i] = (S[-1-i]*C[i])%MOD

    DP = DP2

print(sum(DP)%MOD)

Measured memory_bytes: 72476
a = list(input())
b = list(input())
c = list(input())
turn = a
g = None
while True:
  if turn == []:
    print(g.upper())
    break
  g = turn.pop(0)
  if g == "a":
    turn = a
  elif g == "b":
    turn = b
  else:
    turn = c

  
  

Measured memory_bytes: 3060
while 1:
    m,f,r=map(int,raw_input().split())
    #m:Midterm exam  f:final exam r:Retest
    score=m+f
    if m == -1  or  f ==  -1 :
        if m == -1 and f == -1 and r == -1 :
            break
        else: print 'F'
    elif score >= 80:
        print 'A'
    elif score >= 65:
        print 'B'
    elif score >= 50 or (score >= 30 and r >= 50):
        print 'C'
    elif score >= 30:
        print 'D'
    else:
        print 'F'

Measured memory_bytes: 6396
#include<bits/stdc++.h>  
    using namespace std;  
    typedef long long LL;  
    const int maxn=1e5+10;  
    int n,d[maxn];  
    LL a[maxn];  
    vector<int> G[maxn];  
    bool flag=1;  
    void dfs(int u,int fu)  
    {  
        LL sum=0,maxs=0;  
        int o=0;  
        for (int i=0;i<G[u].size();i++)  
        {  
            int v=G[u][i];  
            if (v==fu) continue;  
            o++;  
            dfs(v,u);  
            sum+=a[v];  
            maxs=max(maxs,a[v]);  
        }  
        if (o==0) return ;  
        LL x=sum-a[u],y=2*a[u]-sum;  
        if (x<0||y<0||x>min(sum-maxs,sum/2)||(fu==-1&&y)) flag=0;  
        a[u]=y;  
    }  
    int main()  
    {  
        cin>>n;  
        for (int i=1;i<=n;i++) scanf("%I64d",&a[i]);  
        for (int i=1;i<n;i++)  
        {  
            int u,v;scanf("%d%d",&u,&v);  
            G[u].push_back(v);G[v].push_back(u);  
            d[u]++;d[v]++;  
        }  
        int root=0;  
        for (int u=1;u<=n;u++) if (d[u]>1) {root=u;break;}  
        if (root) dfs(root,-1);  
        else flag=(a[1]==a[2]);  
        if (flag) cout<<"YES";  
        else cout<<"NO";  
        return 0;  
    }  

Measured memory_bytes: 13568
N = int(input())
h_list = list(map(int, input().split()))

ans = 0
h_list.append(0)
while True:
    idx_left = 0
    idx_right = None
    for i in range(N):
        if h_list[i] == 0 and h_list[i+1] != 0:
            idx_left = i+1
        if h_list[i] != 0 and h_list[i+1] == 0:
            idx_right = i+1

        if idx_right is not None:
            if idx_right == idx_left:
                pour = h_list[idx_left]
                ans += pour
                h_list[idx_left] = 0
            else:
                pour = min(h_list[idx_left:idx_right])
                for j in range(idx_right - idx_left):
                    h_list[idx_left+j] = h_list[idx_left+j] - pour
                ans += pour
            break

    if all([h == 0 for h in h_list]):
        break

print(ans)

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

int n, ans, point[5];

void sim(vector<vector<int> > A){
  
  int sum = 0, x = 1, update = 1;
  
  int used[5][5];
  
  while(update){
    
    update = 0;
    
    memset( used, 0, sizeof(used) );
    
    for(int i=0;i<5;i++){
      
      for(int j=1;j<4;j++){
	
	if( A[i][j] == 0 ) continue;
	
	if( A[i][j-1] == A[i][j] && A[i][j] == A[i][j+1] ){
	  used[i][j-1] = 1;
	  used[i][j] = 1;
	  used[i][j+1] = 1;
	}
		
      }

    }

    for(int i=1;i<4;i++){

      for(int j=0;j<5;j++){
	
	if( A[i][j] == 0 ) continue;
	
    	if( A[i-1][j] == A[i][j] && A[i][j] == A[i+1][j] ){
	  used[i-1][j] = 1;
	  used[i][j] = 1;
	  used[i+1][j] = 1;
	}
	
      }
      
    }

    int cnt[5] = {};
    
    for(int i=0;i<5;i++){
      
      for(int j=0;j<5;j++){
	
	if( used[i][j] ){
	  cnt[A[i][j]-1]++;
	  A[i][j] = 0;
	  update = 1;
	}
	
      }
      
    }
    /*    
    for(int i=0;i<5;i++){
      for(int j=0;j<5;j++) cout<<A[i][j]<<' ';
      cout<<endl;
    }
    */
    
    int update2 = 1;

    while(update2){
      
      update2 = 0;
      
      for(int i=0;i<5;i++){
	
	for(int j=4;j>=1;j--){
	  
	  if( A[j][i] == 0 && A[j-1][i] != 0 ){
	    
	    swap( A[j][i], A[j-1][i] );
	    
	    update2 = 1;
	    
	  }
	  
	}
	
      }

    }
       
    for(int i=0;i<5;i++){
      sum += x * cnt[i] * point[i];
    }
    
    x++;
    
  }
  
  ans = max( ans, sum );
  
}

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

void dfs(int y, int x, vector<vector<int> > A, int cnt){
  
  if( n < cnt ) return;
  
  sim(A);
  
  for(int i=0;i<4;i++){
    
    int ny = y + dy[i], nx = x + dx[i];

    if( ny < 0 || nx < 0 || 5 <= ny || 5 <= nx ) continue;
    
    swap( A[y][x], A[ny][nx] );
    
    dfs( ny, nx, A, cnt + 1 );

    swap( A[y][x], A[ny][nx] );
      
  }
  
}

int main(){
  
  while(1){
    
    cin>>n;
    
    if( n == -1 ) break;
    
    vector<vector<int> > A( 5, vector<int>(5) );
    
    for(int i=0;i<5;i++)
      for(int j=0;j<5;j++) cin>>A[i][j];
    
    for(int i=0;i<5;i++) cin>>point[i];
    
    ans = 0;
    
    for(int i=0;i<5;i++){
      
      for(int j=0;j<5;j++){
	
	dfs( i, j, A, 0 );
	
      }
      
    }
    
    cout << ans << endl;
    
  }
  
  return 0;
}



Measured memory_bytes: 3128
using System;
using System.Collections.Generic;
class Program
{

    static void Main()
    {
        string S = Console.ReadLine();

        if(S.StartsWith("RRR"))
        {
            Console.WriteLine("3");
        }
        else if (S.StartsWith("RRS"))
        {
            Console.WriteLine("2");
        }
        else if (S.StartsWith("SRR"))
        {
            Console.WriteLine("2");
        }
        else if (S.StartsWith("SSS"))
        {
            Console.WriteLine("0");
        }
        else
        {
            Console.WriteLine("1");
        }
    }

}



Measured memory_bytes: 26168
//Author: A_S_M_M@sud_P@rvez
#include<bits/stdc++.h>
using namespace std;
#define    MP ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define    For(i,n) for(int i=0;i<n;i++)
#define    rFor(i,n) for(int i=n-1;i>=0;i--)
#define    forn(i,n) for(int i=1;i<=n;i++)
#define    fors(i,s) for(int i=0;i<s.size();i++)
#define    all(v) v.begin(),v.end()
#define    gcd(a, b) __gcd(a , b)
#define    lcm(a,b) (a*(b/__gcd(a,b)))
#define    test   int t;cin>>t;for(int l=0;l<t;l++)
#define    min3(a,b,c)     min(a,min(b,c))
#define    max3(a,b,c)     max(a,max(b,c))
#define    min4(a,b,c,d)   min(min(a,b),min(c,d))
#define    max4(a,b,c,d)   max(max(a,b),max(c,d))
#define    Max(a)  *max_element(a,a+sizeof(a)/sizeof(a[0]))
#define    Min(a)  *min_element(a,a+sizeof(a)/sizeof(a[0]))
#define    nl     "\n"
#define    End    return 0 
#define    gt     greater<int>()
#define    ll     long long 
#define    mp     make_pair
#define    pb     push_back
#define    vi     vector<int>
#define    vl     vector<ll>
#define    mod    1000000007
#define    sp(n)  fixed<<setprecision(n)
#define    pi     acos(-1)

int main()
{
MP;
    //test
    {
        int c=0,mx=0;
        string s;
        cin>>s;
        fors(i,s){
            if(s[i]=='R')c++;
            else c=0;
            mx=max(mx,c);
        }
        cout<<mx;
    }
    
End;
}


Measured memory_bytes: 3664
#include <iostream>
#include <string>
#include <list>
#include <algorithm>
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n; cin >> n;
    list<int> li;

    for (int i=0; i<n; ++i) {
        string op; cin >> op;
        if (op[0] == 'i') {
            int key; cin >> key;
            li.push_front(key);
        } else if (op.size() > 6 && op[6] == 'F') {
            li.pop_front();
        } else if (op.size() > 6 && op[6] == 'L') {
            li.pop_back();
        } else {
            int key; cin >> key;
            list<int>::iterator pos = find(li.begin(), li.end(), key);
            if (pos != li.end()) {
                li.erase(pos);
            }
        }
    }

    for (list<int>::iterator it = li.begin(); it != li.end(); ++it) {
        cout << ((it == li.begin()) ? "" : " ") << *it;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 32472
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
using namespace std;
typedef long long ll;
typedef long long int llint;
typedef pair<ll, ll> pa;
#define MM 1000000000
#define MOD MM+7
#define MAX 101000
#define MAP 110
#define initial_value -1
#define MAX_T 1001
#define Pair pair<int,int>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define INF (1 << 29) //536870912
const long double PI = acos(-1);
const ll DEP = 1e18;
int dx[8] = {-1,0,1,0,1,-1,1,-1};
int dy[8] = {0,-1,0,1,1,1,-1,-1};
int num[51][51];
int H,W;
void init(){
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            num[i][j] = MM;
        }
    }
}
int main(){
    string s,t; cin >> s >> t;
    string ans;
    if(s.size() == t.size()){
        for(int i = 0; i < s.size(); i++){
            ans = ans + s[i] + t[i];
        }
    } else {
        for(int i = 0; i < t.size(); i++){
            ans = ans + s[i] + t[i];
        }
        ans = ans + s[s.size()-1];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<sstream>
#include<cmath>
#include<stack>
#include<map>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define P pair<int,int>
#define ll __int64
set<string>t;
int n;
string s[100];
string ns;

string code(string s,int k){
	string ns="";
	ns.pb(s[0]);
	for(int i=1;i<s.size();i++){
		if(s[i-1]=='a'||s[i-1]=='i'||s[i-1]=='u'||s[i-1]=='e'||s[i-1]=='o')ns.pb(s[i]);
	}
	if(ns.size()<k)
	return ns;
string nss;
nss.resize(k);
rep(i,k)nss[i]=ns[i];
return nss;
}
int main(){
while(cin>>n,n){
rep(i,n){
	cin>>s[i];

}
int ans=-1;

for(int i=1;i<=50;i++){
	t.clear();

	for(int j=0;j<n;j++){
		ns=code(s[j],i);
		//cout<<s[j]<<" "<<ns<<endl;
		if(t.find(ns)!=t.end())break;
		t.insert(ns);
	}
	if(t.size()==n){
		ans=i;
		break;
	}

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


Measured memory_bytes: 3212
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    int a = sc.nextInt();
    int b = sc.nextInt();
    
    if (a == 2 || b == 2) {
      System.out.println("No");
    } else {
      System.out.println("Yes");
    }
  }
}

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

int main() {
	string s;
	cin>>s;
	int count=0;
	for(int i=0;i<3;i++){
	    if(s[i]=='R')
	    count++;
	}
	if(count!=2)
	cout<<count;
	else if(s[1]=='R')
	cout<<"2";
	else
	cout<<"1";
	return 0;
}


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

using namespace std;

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

double p, e, t;

double solve(int k, double r, double l) {
  if (k == 0) {
    double m = (r + l) / 2;
    if (t - e < m && m < t + e) return 1;
    return 0;
  }
  if (t + e < r) return 0;
  if (l < t - e) return 0;
  if (t - e < r && l < t + e) return 1;
  double m = (r + l) / 2;
  if (m < t) {
    return solve(k - 1, r, m) * p + solve(k - 1, m, l) * (1 - p);
  } else {
    return solve(k - 1, r, m) * (1 - p) + solve(k - 1, m, l) * p;  
  }
}

int main() {
  int k, r, l;
  cin >> k >> r >> l >> p >> e >> t;
  printf("%.12f\n", solve(k, r, l));
}

Measured memory_bytes: 1248
/**
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

#include <bits/stdc++.h>
using namespace std;

const bool ready = [](){
    ios_base::sync_with_stdio(false); cin.tie(0);
    cout << fixed << setprecision(12);
    return true;
}();

const double PI = acos(-1);
using ll= long long;
#define int ll
#define all(v) (v).begin(), (v).end()
#define fori(n) for(int i=0; i<int(n); i++)

#define cini(i) int i; cin>>i;
#define cins(s) string s; cin>>s;
#define cind(d) double d; cin>>d;
#define cinai(a,n) vi a(n); fori(n) { cin>>a[i]; }
#define cinas(s,n) vs s(n); fori(n) { cin>>s[i]; }
#define cinad(a,n) vd a(n); fori(n) { cin>>a[i]; }

using pii= pair<int, int>;
using pdd= pair<double, double>;
using vd= vector<double>;
using vb= vector<bool>;
using vi= vector<int>;
using vvi= vector<vi>;
using vs= vector<string>;

void solve() {
    cini(L);
    cini(R);
    cini(d);
    int l1=(L/d)*d;
    if(l1<L)
        l1+=d;

    int r1=(R/d)*d;
    if(r1>R)
        r1-=d;

    if(l1>r1)
        cout<<0<<endl;
    else
        cout<<(r1-l1)/d+1;
}

signed main() {
    solve();
}

// FIRST THINK, THEN CODE
// DO NOT JUMP BETWEEN PROBLEMS


Measured memory_bytes: 3644
#include<stdio.h>
#include<string.h>
#include<queue>
using namespace std;
struct easy
{
	int x;
	int y;
};
char a[55][55];
int step[55][55];
int visit[55][55];
int dir[][2]={{0,1},{1,0},{0,-1},{-1,0}};
queue<easy>q;
easy s,t,w;
int bfs(int n,int m);
int main()
{
	int i,j,n,m,k,count=0;
	scanf("%d%d",&n,&m);
	for(i=0;i<n;i++)
	 scanf("%s",a[i]);
	 memset(step,0,sizeof(step));
	 memset(visit,0,sizeof(visit));
	 k=bfs(n,m);
	if(k==-1)  printf("-1\n");
	else 
	{
	   for(i=0;i<n;i++)
	    for(j=0;j<m;j++)
	     {
	     	if(a[i][j]=='.') count++;
		 }
	   printf("%d\n",count-k);
	}
  return 0;	
}
int bfs(int n,int m)
{
	int i;
	s.x=0;
	s.y=0;
	q.push(s);
	step[0][0]=1;
	visit[0][0]=1;
	while(!q.empty())
	{
	   t=q.front();
	   q.pop();
	   for(i=0;i<4;i++)
	   {
	   	 w.x=t.x+dir[i][0];
	   	 w.y=t.y+dir[i][1];
	   	 if(w.x==n-1 && w.y==m-1)  return step[t.x][t.y]+1;
	   	 if(!(w.x<0 || w.y<0 || w.x>=n || w.y>=m || a[w.x][w.y]=='#' || visit[w.x][w.y]==1))
	   	 {
	   	 	visit[w.x][w.y]=1;
	   	 	step[w.x][w.y]=step[t.x][t.y]+1;
	   	 	q.push(w);
		 }
	   }   
   }
   return -1;
}

Measured memory_bytes: 504
#include <cstdio>
#include <iostream>
#include <cstring>
#include <vector>
#include <cmath> 
#include <algorithm> 
using namespace std;
const int maxn=2e5+5;
typedef long long ll;
ll a[maxn];
ll n,temp;
int main()
{
	while(cin>>n)
	{
		ll sum=0,ave,ans;
		for(int i=1;i<=n;i++)
		{
			cin>>temp;
			a[i]=temp-i;	
			sum+=a[i];
		}
		sort(a+1,a+n+1);
		if(n&1)
		{
			ave=a[(n+1)/2];
			sum=0;
			for(int i=1;i<=n;i++)
				sum+=abs(ave-a[i]);
			cout<<sum<<endl;
		}	
		else
		{
			ave=a[n/2];
			sum=0;
			for(int i=1;i<=n;i++)
				sum+=abs(ave-a[i]);
			cout<<sum<<endl;	
		}
	}
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
    using namespace std;
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    using namespace __gnu_pbds;
     
    #define fast { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
    #define pb push_back
    #define ll long long
    #define ld long double
     
    #define vi vector<int>
    #define vl vector<long>
    #define vll vector<long long>
    #define infd LDBL_MAX
    #define f(i,a,b) for(ll i=a;i<b;i++)
    
    #define ff first
    #define ss second
   
    #define pll pair<ll,ll> 
    #define endl "\n"
    #define ALL(v) v.begin(),v.end()
    #define nl cout<<"\n";
    #define pr(x) cout<<x;
    #define pr1(x) cout<<x<<" ";
    #define pr2(x,y) cout<<x<<" "<<y;
    #define deb printf("*****************************\n");
    #define idk printf("idk idk ! \n");
    #define hi printf("hi ! \n");
    #define bye printf("bye bye ! \n");
    #define o_set(ll) tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
    #define number_of_set_bits  __builtin_popcountll  
     
  
     
     
    //const ll N=1e6+7;
    ll p=1e9+7;
    //ll fac[N];
     
// taking inpugt with help of string and " "
     /*   string s;
         getline(cin,s);
         vi a=init(s);
         if(a.size()==2)cout<<query_(a[0]+1,a[1]+1)<<endl;
         else update_(a[0]+1,a[1]+1,a[2]);
 
      */
 vi init(string s)
{
    istringstream sin(s);
    int n;
    vi arr;
    while(sin>>n)arr.push_back(n);
    return arr;
}

    ll gcd(ll a, ll b) 
    { 
        if (a == 0) 
            return b; 
        return gcd(b % a, a); 
    } 
    
    ll pow_mod_p(ll a,ll b)
    {
      a=a%p;
      ll res=1;
      while(b>0)
      {
        if(b&1) res=(res*a)%p;
        b=b>>1;
        a=(a*a)%p;
      }
      return res;
    }
     
    inline ll mod_inv(ll x)
    {
      return pow_mod_p(x,p-2);
    }
     
   
     int main() 
    {
        fast
        //#ifndef ONLINE_JUDGE
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
        //#endif // ONLINE_JUDGE
        
     
        ll ntc=1;
     //   cin>>ntc;
     
        f(i,1,ntc+1)
        {
          //cout<<"Case #"<<i<<": ";
         
          ll n, x,t; cin>>n>>x>>t;
          ll ans = (((n+x-1)/x)*t);
          cout<<ans<<endl;
          
        }
     
        return 0;
    }

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

using namespace std;
//#define int long long
#define float double
//const int INF = 100000000000000000;

bool isss(string s){
  if(s.size()%2){
    return false;
  }else{
    int half = s.size()/2;
    if(s.substr(0,half) == s.substr(half,half)){
      return true;
    }else{
      return false;
    }
  }
  return false;
}

signed main(void){
  string s;
  cin >> s;
  while(true){
    s = s.substr(0, s.size()-1);
    if(isss(s)){
      cout << s.size() << "\r\n";
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define nl ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
#define all(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()

using namespace std;


int main() {
    nl // lofi  
    int x;

    for(int i=0; i<5; i++) {
        cin >> x;
        if(x == 0){
            cout << i+1;
            return 0;
        }
    }
} 

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

int main() {
	
	string str1;
	string str2;
	cin >> str1;
	cin >> str2;
	int count = 0;
	for(int i=0;i<3;i++)
	{
	    if(str1[i] == str2[i]) count++;
	}
	cout << count;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cassert>
#include <cstring>
#include <vector>
#include <valarray>
#include <array>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <complex>
#include <random>

using namespace std;
typedef long long ll;

int sc[26], tc[26];

int main() {
	int n;
	cin >> n;
	string s, t;
	cin >> s >> t;
	for (char c: s) {
		sc[c-'a']++;
	}
	for (char c: t) {
		tc[c-'a']++;
	}

	sort(sc, sc+26);
	sort(tc, tc+26);

	int sm = 0;
	for (int i = 0; i < 26; i++) {
		sm += min(sc[i], tc[i]);
	}
	cout << n - sm << endl;
    return 0;
}

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

int main(){
  int N,A,B,sum=0,co=0;
  cin >> N >> A >> B;
  for(int i=1; i<=N; i++){
    int t=i;
    co=0;
    for(int j=0; j<5; j++){
      co+=t%10; t/=10;
    }if(A<=co && co<=B){
      sum+=i;
    }
  }
  cout << sum << endl;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++) 
#define ll long long
#define ld long double
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)  

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

  string ret = "No";
  if(M == L || M == N || L == N)
  {
    if(M== L && N == L)
    {
      
    }
    else
    {
      ret = "Yes";
    }
  }

	cout << fixed << ret << endl;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){
    int n; cin >> n;
    map<int, int> mp;
    rep(i, n){
        int a; cin >> a;
        if(a%4==0) mp[2]++;
        else if(a%2==0) mp[1]++;
        else mp[0]++;
    }
    bool fg = true;
    int num = 2;
    rep(i, n){
        if(num == 0){
            if(mp[2]>0){mp[2]--; num = 2;}
            else{fg = false; break;}
        }else if(num == 1){
            if(mp[1]>0){mp[1]--; num = 1;}
            else if(mp[2] > 0){mp[2]--; num = 2;}
            else {fg = false; break;}
        }else{
            if(mp[0]>0){mp[0]--; num = 0;}
            else if(mp[1]>0){mp[1]--; num = 1;}
            else if(mp[2] > 0){mp[2]--; num = 2;}
        }
    }
    if(fg) cout << "Yes" << ln;
    else cout << "No" << ln;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)

int main(){
    ll n;
    cin >> n;
    vector<ll> s(n);
    REP(i, n){
        cin >> s.at(i);
    }

    ll q;
    cin >> q;
    ll ans = 0;
    REP(i, q){
        ll t;
        cin >> t;
        const auto it = lower_bound(s.begin(), s.end(), t);
        ans += (*it == t);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3552
#include <bits/stdc++.h>
using namespace std;
map <int, int> m;
vector <pair <int, int> > pairs;
int main() {
	int n;
	cin >> n;
	for (int i =0; i < n; i++) {
		int v;
		cin >> v;
		m[v]++;
	}
	for (auto it : m) {
		pairs.emplace_back(it.first, it.second);
	}
	if (pairs.size() == 3 && pairs[0].second == pairs[1].second && pairs[1].second == pairs[2].second && ((pairs[0].first ^ pairs[1].first) == pairs[2].first)) {
		cout << "Yes" << endl;
	} else if (pairs.size() == 1 && pairs[0].first == 0) {
		cout << "Yes" << endl;
	} else if (pairs.size() == 2 && pairs[0].first == 0 && pairs[1].second == 2 * pairs[0].second) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 4988
n = int(input())
v = list(map(int, input().split()))
 
for i in range(n-1):
  mn1 = min(v)
  v.remove(min(v))
  mn2 = min(v)
  v.remove(min(v))
  v.append((mn1 + mn2) / 2.0)
 
print(v[0])


Measured memory_bytes: 38512
use proconio::input;
use std::collections::HashSet;
fn main(){
    input!{
        n:usize,
        b:[usize;n],
    }
    let mut a = b;
    a.sort();
    let mut div = HashSet::new();
    let mut ans = 0;
    for i in 0..n {
        let mut flag = true;
        for j in 1..(1 + (a[i] as f64).sqrt() as usize){
            if a[i] % j == 0{
                let k = (&a[i])/(&j);
                if div.contains(&j) || div.contains(&k){
                    flag = false;
                    break;
                }
            }
        }
        div.insert(a[i]);
        if flag{
            if i != n-1 && a[i] != a[i+1]{
                ans += 1
            }
            if i == n-1{
                ans += 1
            }
        }
    }
    println!("{}",ans);
}


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

int aa(int n){
  if(n==0) return 0;
  if(n==1) return 10;
  if(n==2) return 100;
}
int main() {
  int N,M;
  cin>>N>>M;
  vector<pair<int,char>> p(M);
  for(int i=0;i<M;i++) {
    int X;
    char Y;
    cin>>X>>Y;
    p[i]=make_pair(X,Y);
  }
  for(int i=aa(N-1);i<1000;i++){
    string s;
    s=to_string(i);
    bool flag=true;
    for(int j=0;j<M;j++) {
      if(s[p[j].first-1]!=p[j].second) flag=false; 
   		 }
    if(flag) {cout<<i<<endl; return 0;}
  }
  cout<<-1<<endl;
}
      

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

char *pt;
int parseAtom();
int parseExpr();
int parseTerm();
int parseAtom() {
  if('0' <= *pt && *pt <= '9') {
    int x = *pt-'0';
    pt++;
    while('0' <= *pt && *pt <= '9') {
      x = x*10 + *pt-'0';
      pt++;
    }
    return x;
  }
  if('(' == *pt) {
    pt++;
    int x = parseExpr();
    assert(*pt == ')');
    pt++;
    return x;
  }
  assert(false);
  return -1;
}
int parseExpr() {
  int x = parseTerm();
  while(*pt == '+' || *pt == '-') {
    if(*pt == '+') {
      pt++;
      x += parseTerm();
    } else {
      pt++;
      x -= parseTerm();
    }
  }
  return x;
}
int parseTerm() {
  int x = parseAtom();
  while(*pt == '*' || *pt == '/') {
    if(*pt == '*') {
      pt++;
      x *= parseAtom();
    } else {
      pt++;
      x /= parseAtom();
    }
  }
  return x;
}

int main() {
  int tc; scanf("%d", &tc);
  for(int tci = 0; tci < tc; tci++) {
    static char expr[200]; scanf(" %s", expr);
    pt = expr;
    int x = parseExpr();
    assert(*pt == '=');
    printf("%d\n", x);
  }
  return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
	char name[100];
	int t
}P;

P Q[LEN];
int head,tail,n;

void enqueue(P x){
	Q[tail]=x;
	tail=(tail+1)%LEN;
	return 0;
}

P dequeue(){
	P x=Q[head];
	head=(head+1)%LEN;
	return x;
}

int min(int a,int b){return a<b?a:b;}

int main(void){
	int elaps=0,c;
	int i,q;
	P u;
	scanf("%d %d",&n,&q);
	for(i=1;i<=n;i++){
		scanf("%s",Q[i].name);
		scanf("%d",&Q[i].t);
	}
	
	head=1; tail=n+1;
	
	while(head !=tail){
		u=dequeue();
		c=min(q,u.t);
		u.t -=c;
		elaps +=c;
		if(u.t>0)enqueue(u);
		else{
			printf("%s %d\n",u.name,elaps);
		}
	
	}
	return 0;
}


Measured memory_bytes: 11900
# ABC091B - Two Colors Card Game
n = int(input())
lst_1 = [input().rstrip() for _ in range(n)]
set_1 = set(lst_1)
m = int(input())
lst_2 = [input().rstrip() for _ in range(m)]
count = 0

for i in set_1:
    count = max(count, lst_1.count(i) - lst_2.count(i))

print(count)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
    int R,G,B,N; cin >> R >> G >> B >> N;
    int ans = 0;
    for(int i = 0; i <= N / R; i++){
        for(int j = 0; j <= N / G; j++){
            if((N - (R*i + G*j)) % B == 0 && N >= R*i + G*j) ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
import           Control.Exception           (assert)
import           Control.Monad
import           Control.Monad.Primitive
import qualified Control.Monad.ST            as ST
import qualified Data.Array.IO               as IO
import qualified Data.Array.ST               as ST
import qualified Data.Array.Unboxed          as A
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Foldable
import           Data.List
import           Data.Maybe
import qualified Data.Sequence               as Seq
import qualified Data.Set                    as Set
import qualified Data.Vector                 as VB
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM
import           Debug.Trace

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readInteger = fst . fromJust . BS.readInteger
readIntegerList = map readInteger . BS.words
getInteger = readInteger <$> BS.getLine
getIntegerList = readIntegerList <$> BS.getLine

inf :: Int
inf = 10^18

main = do
  [h, w] <- getIntList

  g <- VB.replicateM h BS.getLine
  let getPos r c = (g VB.! (r-1)) `BS.index` (c-1)

  arr <- IO.newArray ((1,1),(h,w)) inf :: IO (IO.IOUArray (Int, Int) Int)

  let dfs :: Int -> Int -> Int -> Char -> IO ()
      dfs i j d col | i > h || j > w = return ()
                    | otherwise = do
                        let col' = getPos i j
                            d' = d + if col' == '#' && col == '.'
                                     then 1 else 0
                        t <- IO.readArray arr (i, j)
                        when (d' < t) $ do
                          IO.writeArray arr (i, j) d'
                          dfs (i+1) j (d'+1) col'
                          dfs i (j+1) (d'+1) col'

  dfs 1 1 0 '.'

  dist <- IO.readArray arr (h, w)

  let dist0 = h + w - 2
      ans = dist - dist0

  print ans

Measured memory_bytes: 636
#include <bits/stdc++.h>
using namespace std;
 
//long long
using ll = long long;
 
// pair<int, int>
using PII = pair<int, int>;
 
//最大値、mod
const int MOD = 1000000007;
const int INF = 1000000000;
const long long LINF = 1e18;
const int MAX = 510000;
 
//出力系
#define print(x) cout << x << endl
#define prints(x) cout << fixed << setprecision(10) << x << endl
#define printc(x) cout << setw(2) << setfill('0') << x << endl;
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()
 
//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
 
//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
 
// 最小公倍数
unsigned lcm(unsigned a, unsigned b){
    return a / gcd(a, b) * b; 
}
 
// a = max(a, b), a = min(a, b)
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; }
 
// 階乗(MODをとる)
ll pow_mod(ll num, ll pow, ll mod) {
    ll prod = 1;
    num %= mod;
    while (pow > 0) {
        if (pow & 1) prod = prod * num % mod;
        num = num * num % mod;
        pow >>= 1;
    }
    return prod;
}
 
 
 
// 二項係数(MODとる、1 ≦ k ≦ n ≦ 10^7 程度)
// COMinit()
// COM(x, y)
// とコンビで使う
 
// テーブルを作る前処理
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
//int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0};


int main(){
    int N;
    cin >> N;
    int ans = (N + 1) / 2;
    print(ans);
}

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

void solve() {
  string s;
  cin >> s;
  char cur = s[0];
  int n = s.length();
  int i = 1;
  int ans = 0;
  for(;;) {
    while(i < n && s[i] != cur) {
      cur = s[i++];
    }
    if(i >= n) break;
    if (s[i] == '0') s[i] = '1';
    else s[i] = '0';
    ans++;
    cur = s[i++];
  }
  cout << ans << endl;
}

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

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

typedef long long lglg;

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

	int n, k;
	string x;
	cin >> n >> k >> x;
	int comps = 1;
	for (int i=0; i<n-1; ++i) if (x[i] != x[i+1]) ++comps;
	cout << n - max(1, comps - 2*k);
}

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

pair<complex<double>, double> min_circle (vector<complex<double>> data, int seed = 1333) {
    using P = complex<double>;
    using circle = pair<P, double>;
    const double eps = 1e-10; int n = data.size();
    if (n == 1) { return {data[0], 0}; };
    auto inner = [&] (const P &a, const circle &c) -> bool { 
        return norm(a - c.first) <= c.second + eps;
    };
    auto make_circle_2 = [&](const P &a, const P &b) -> circle {
        P c = (a + b) / 2.0; double r = norm(a - c);
        return {c, r};
    };
    auto make_circle_3 = [&](const P &a, const P &b, const P &c) -> circle {
        double A = norm(b - c), B = norm(c - a), C = norm(a - b);
        double S = norm((a - c) * conj(b - c) - conj(a - c) * (b - c));
        P p = (A * (B + C - A) * a + B * (C + A - B) * b + C * (A + B - C) * c) / S;
        double r = norm(p - a);
        return {p, r};
    };
    
    // MinDisk
    shuffle (data.begin(), data.end(), mt19937(seed));
    circle d = make_circle_2(data[0], data[1]);
    for (int i = 2; i < n; i++) {
        if (not inner(data[i], d)) {
            // MinDiskWithPoints
            d = make_circle_2(data[0], data[i]);
            for (int j = 1; j < i; j++) {
                if (not inner(data[j], d)) {
                    // MinDiskWith2Points
                    d = make_circle_2(data[i], data[j]);
                    for (int k = 0; k < j; k++) {
                        if (not inner(data[k], d)) {
                            d = make_circle_3(data[k], data[j], data[i]);
                        }
                    }
                }
            }
        }
    }
    return d;
}



int main() {
    int n;
    cin >> n;
    vector<complex<double>> dat;
    for (int i = 0; i < n; i++) {
        double x, y;
        cin >> x >> y;
        dat.emplace_back(x, y);
    }
    
    double ans = min_circle(dat).second;
    
    cout << fixed << setprecision(20) << sqrt(ans) << '\n';
    
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define MOD7 1000000007
#define LL_INF 9000000000000000000
#define LL_MINF -9000000000000000000
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};


ll N;
vector<string> A;
void push(string s){
    if(atoi(s.c_str())>N) return;
    if(s.size() == 10) return;
    A.push_back(s);
    push(s + "3");
    push(s + "5");
    push(s + "7");
};
int main(){
    cin >> N;
    push("");
    int count = 0;
    for(string a : A){
        bool seven = false, five = false, three = false;
        for(char c : a){
            if(c == '3') three = true;
            if(c == '5') five = true;
            if(c == '7') seven = true;
        }
        if(three and five and seven) count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 4216
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

const int w = 5;
int h;
int field[20][20];
bool del[20][20];
int main() {
  while (scanf("%d", &h) > 0 && h) {
    MEMSET(field, 0);
    REP(y, h) {
      REP(x, w) {
        scanf("%d", &field[y][x]);
      }
    }
    int ans = 0;
    REP(iter1, 100) {
      MEMSET(del, false);
      REP(y, h) {
        REP(x, w - 2) {
          if (field[y][x] == field[y][x + 1] && field[y][x] == field[y][x + 2]) {
            del[y][x] = del[y][x + 1] = del[y][x + 2] = true;
          }
        }
        REP(x, w) {
          if (!del[y][x]) { continue; }
          ans += field[y][x];
          field[y][x] = 0;
        }
      }
      REP(iter2, h) {
        for (int y =  h - 2; y >= 0; y--) {
          REP(x, w) {
            if (field[y + 1][x] == 0) { swap(field[y][x], field[y + 1][x]); }
          }
        }
      }
    }
    printf("%d\n", ans);
  }
}

Measured memory_bytes: 1188
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#define MAX_N 23
#define INF 23333333

using namespace std;

int n,m,ans=INF;
int a[MAX_N];
int c[MAX_N];

int getans(int s)
{
	int cnt=0,sum=0;
	for(int i=1;i<=n;i++) if((s>>(i-1)&1)) cnt+=a[i],sum+=a[i]*i*100+c[i];
	for(int i=n;i>=1 && sum<m;i--)
	{
		if((s>>(i-1))&1) continue;
		int x=min(a[i],(int)ceil((double)(m-sum)/(i*100)));
		cnt+=x,sum+=x*i*100;
	}
	return sum>=m ? cnt : INF;
}

int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) scanf("%d%d",&a[i],&c[i]);
	for(int s=0;s<(1<<n);s++) ans=min(ans,getans(s));
	printf("%d\n",ans);
}


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

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();

            string[] weather = new string[4] {"Sunny", "Cloudy", "Rainy","Sunny"};

            for(int i=0;i<3;i++)
            {
                if(s == weather[i])
                {
                    Console.WriteLine(weather[i+1]);
                }
            }
            
        }
    }
}


Measured memory_bytes: 13140
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int main(void){
  int n;
  double xa, ya, ra, xb, yb, rb, d;

  cin >> n;
  for(int i = 0;i < n; i++){
    cin >> xa >> ya >> ra >> xb >> yb >> rb;
    d = sqrt((xb - xa) * (xb - xa) + (yb - ya) * (yb - ya));
    if(d < ra - rb) cout << "2" << endl;
    else if(d < rb - ra) cout << "-2" << endl;
    else if(d > ra + rb) cout << "0" << endl;
    else if(d >= ra - rb) cout << "1" << endl;
  }

}


Measured memory_bytes: 1224
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll INF=1e18;

class DisjointSet{
    public:
    vector<ll> rank,p,sz;
    DisjointSet(){}
    DisjointSet(ll size){ //作られうる木の頂点数の最大値を入れる。
        rank.resize(size,0);
        p.resize(size,0);
        sz.resize(size,0);
        rep(i,size) makeSet(i);
    }
    void makeSet(ll x){ //xだけが属する木を作る。
        p[x]=x;
        rank[x]=0;
    }
    bool same(ll x,ll y){ //xとyが同じ木に属するかどうか
        return findSet(x)==findSet(y);
    }
    void unite(ll x, ll y){
        link(findSet(x),findSet(y));
    }
    void link(ll x, ll y){ //rankが大きい方の根に小さい方の根をつける。
        if(rank[x]>rank[y]){
            p[y]=x;
        }
        else{
            p[x]=y;
            if(rank[x]==rank[y]){
                rank[y]++; //xとyの木のrankが同じであれば、統合するとrankが1増える。
            }
        }
        sz[x]+=sz[y];
        sz[y]=sz[x];
    }
    ll findSet(ll x){ //xが属する木の根の番号を返す
        if(x!=p[x]){
            p[x]=findSet(p[x]);
        }
        return p[x];
    }
};

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

Measured memory_bytes: 4992
// #pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);
#define fou(i,a,n) for(int i=a;i<n;i++)
#define fod(i,a,n) for(int i=n-1;i>=a;i--)
#define rep(n) fou(_,0,n)
#define tra(a,x) for(auto& a : x)
#define elif(c) else if(c)
#define VI vector<int>
#define VD vector<double>
#define VC vector<char>
#define VS vector<string>
#define VVI vector<VI>
#define VVD vector<VD>
#define VVC vector<VC>
#define VVS vector<VS>
#define emb emplace_back
#define pub push_back
#define pob pop_back
#define mp make_pair
#define fi first
#define se second
#define si(vec) ((int)(vec).size())
#define all(vec) vec.begin(),vec.end()
#define lla(vec) vec.rbegin(),vec.rend()
#define range(vec,x,y) vec.begin()+x,vec.begin()+y
#define sortup(vec) sort(all(vec))
#define sortdown(vec) sort(lla(vec))
#define eraseif(vec,condition_x) vec.erase(remove_if(all(vec),[](auto x){return condition_x;}),vec.end())
#define countif(vec,condition_x) count_if(all(vec),[](auto x){return condition_x;})
#define replaceif(vec,condition_x,n) replace_if(all(vec),[](auto x){return condition_x;},n)
#define optvalue(vec,condition_x,relation_x_opt) *min_element(all(vec),[](int x,int opt){return condition_x ? (opt==0)||!(relation_x_opt):false;})
#define erase_unique(vec) vec.erase(unique(all(vec)),vec.end())
#define calcvec(vec,calc_x) for_each(all(vec),[](int&x){x= calc_x;})
#define calc2vec(vec1,op,vec2) {rep(1){int s=min(si(vec1),si(vec2));fou(i,0,s)vec1[i]=vec1[i] op vec2[i];}}
template<class C>void mini(C &a,C b){a=min(a,b);}
template<class C>void maxi(C &a,C b){a=max(a,b);}
#define in(T,...) T __VA_ARGS__;_cin(__VA_ARGS__);
#define out(...) _cout(__VA_ARGS__);
void _cin(){}template<class Head,class...Tail>void _cin(Head&head,Tail&&...tail){cin>>head;_cin(forward<Tail>(tail)...);}
template<class Head>void _cout(Head head){cout<<head<<endl;}template<class Head,class...Tail>void _cout(Head head,Tail...tail){cout<<head<<" ";_cout(forward<Tail>(tail)...);}
template<class C>void outvec(vector<C> vec){int vecsize=si(vec);fou(i,0,vecsize-1)cout<<vec[i]<<" ";out(vec[vecsize-1]);}
template<class C> C gcd(C a,C b){if(a&&b)return gcd(min(a,b),max(a,b)%min(a,b));else return a;}
template<class C> C lcm(C a,C b){return a/gcd(a,b)*b;}




// #define int int64_t
// #define double long double


// 無名関数template
// map,makepair

signed main(){
  IOS;

  VVI c(3,VI(3));
  fou(i,0,3)fou(j,0,3) cin>>c[i][j];

  calc2vec(c[0],-,c[1]);
  calc2vec(c[1],-,c[2]);

  string ans="Yes";
  if (c[0][1]!=c[0][0]||c[0][2]!=c[0][0]) ans="No";
  if (c[1][1]!=c[1][0]||c[1][2]!=c[1][0]) ans="No";
  out(ans);

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MAXN=100005;
int a[MAXN];
int n,ans;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;++i)
    {
        scanf("%d",&a[i]);
    }
    int p=1;
    while(p<=n)
    {
        int p2=p+1;
        while(a[p2]==a[p]&&p2<=n)++p2;
        ans+=(p2-p)/2;
        p=p2;
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();

        for (int i = s.length() - 2; i >= 2; i -= 2) {
            String former = s.substring(0, i / 2);
            String latter = s.substring(i / 2, i);
            if (former.equals(latter)) {
                System.out.println(former.length() + latter.length());
                return;
            }
        }
    }

}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
#include <iostream>
#include <utility> // pair
#include <string>
#include <vector>
#define MAX_N 200001
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define FOR(i, a, b) for(ll i=a; i<b; i++)
#define REP(i, n) for(ll i=0; i<n; i++)
#define REV(i, n) for(ll i=n-1; i>=0; i--)
#define ALL(v) v.begin(), v.end()
#define pb push_back
const ll INF = 9e18;
ll n, a[MAX_N];

signed main(){
    cin >> n;
    REP(i, n) cin >> a[i];
    sort(a, a+n);
    REP(i, n-1){
        if(a[i] == a[i+1]){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define db(x) (cerr << #x << ": " << (x) << '\n')
#define cps CLOCKS_PER_SEC
#define tests(t) int t; cin >> t; while(t--)
#define iceil(n, x) (((n) + (x) - 1) / (x))
#define eb emplace_back
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define sz size()
#define all(v) (v).begin(), (v).end()
#define uni(v) sort(all(v)), (v).erase(unique(all(v)), (v).end())
#define fi first
#define se second
#define bitcount(x) __builtin_popcount(x)
#define bit(x) (1LL << x)
#define PI acos(-1.0)
#define EPS 1e-9

#define mod 1000000007
#define maxn 2005

using namespace std;

using namespace __gnu_pbds;
template<class key, class cmp = std::less<key>>
using ordered_set = tree<key, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
///All indexing is 0-based
///methods: find_by_order(k); & order_of_key(k);
///To make it an ordered_multiset, use pairs of (value, time_of_insertion)
///to distinguish values which are similar

typedef long long ll;
typedef double ld;
typedef pair<ll, ll> par;



int main()
{
    #ifdef acm
    freopen("a.in","r",stdin);
    #endif // acm
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int N;
    cin >> N;

    int sol=0,men=1<<30,a;
    for(int i=1;i<=N;i++){cin >> a;
        if(men>a)
          sol++,men = min(men,a);
    }

    cout << sol;






}



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

int main(){
	int a, b;
   	scanf("%d %d", &a,&b);
   	if( a < b )
   	{
   	printf("a < b\n");
	}else if ( a > b ){
		printf("a > b\n");
		}else{
			printf("a == b\n");
			}
}


Measured memory_bytes: 3156
#include <bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pi;
const ll inf = 1e18+5;
ll h, n, dp[10005];
pi spell[1005];
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin >> h >> n;
	for (ll i = 0; i < n; i++)cin >> spell[i].F >> spell[i].S;
	for (ll i = 0; i < h; i++)dp[i] = inf;
	//~ dp[i] stores the minimum points needed to reach this state
	for (ll i= h-1; i >= 0; i--){//for each possible value
		for (ll j = 0; j < n; j++){//each spell
			dp[i] = min(dp[i], dp[min(i+spell[j].F, h)]+spell[j].S);
		}
	}
	cout << dp[0];
}


Measured memory_bytes: 384