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

using namespace std;

#define int long long 
#define INF 1e9
#define LINF 1e18

typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<int, P> Pi;
typedef pair<P, P> PP;

const int MOD = 1e9 + 7;
const int dy[] = { 0, 0, 1, -1 };
const int dx[] = { 1, -1, 0, 0 };

template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N, M;
    cin >> N >> M;
    for(int i = M / N; i >= 1; --i) {
        if(M % i == 0) {
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}


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

int main() {
    string s, t, u;
    cin >> s >> t >> u;
    printf("%c%c%c\n", s[0] - 'a' + 'A', t[0] - 'a' + 'A', u[0] - 'a' + 'A');
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
int vali[100100];
int a[1000][1000];
int main()
{
    for(int i=1;i*(i-1)/2<=100000;++i)
        vali[i*(i-1)/2]=i;
    int n;
    scanf("%d",&n);
    if(!vali[n])
    {
        puts("No");
        return 0;
    }
    puts("Yes");
    printf("%d\n",vali[n]);
    int t=1,l=2*n/vali[n];
    for(int i=1;i<=vali[n];++i)
    {
        printf("%d ",l);
        for(int j=1;j<i;++j)
        {
            printf("%d ",a[j][i-1]);
            a[i][j]=a[j][i-1];
        }
        for(int j=i;j<=l;++j)
        {
            printf("%d ",t);
            a[i][j]=t++;
        }
        puts("");
    }
    return 0;
}


Measured memory_bytes: 5248
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void minAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) min(dst, src);
}

void main()
{
    long N, Q;
    scan(N, Q);
    auto S = sread();
    auto T = new char[](Q);
    auto D = new char[](Q);
    foreach (i; 0 .. Q)
        scan(T[i], D[i]);

    bool isSurviveLeft(long x)
    {
        long now = x;
        foreach (i; 0 .. Q)
            if (T[i] == S[now])
            {
                now += (D[i] == 'R') ? 1 : -1;
                if (now == -1)
                    return false;
                if (now == N)
                    return true;
            }
        return true;
    }

    bool isSurviveRight(long x)
    {
        long now = x;
        foreach (i; 0 .. Q)
            if (T[i] == S[now])
            {
                now += (D[i] == 'R') ? 1 : -1;
                if (now == -1)
                    return true;
                if (now == N)
                    return false;
            }
        return true;
    }

    long l = () {
        long ok = N;
        long ng = -1;
        while (1 < abs(ok - ng))
        {
            long m = (ok + ng) / 2;
            if (isSurviveLeft(m))
            {
                ok = m;
            }
            else
            {
                ng = m;
            }
        }
        return ok;
    }();
    long r = () {
        long ok = -1;
        long ng = N;
        while (1 < abs(ok - ng))
        {
            long m = (ok + ng) / 2;
            if (isSurviveRight(m))
            {
                ok = m;
            }
            else
            {
                ng = m;
            }
        }
        return ok;
    }();
    // iota(N).map!isSurviveLeft().writeln();
    // iota(N).map!isSurviveRight().writeln();
    // writeln(l);
    // writeln(r);
    writeln(r - l + 1);
}


Measured memory_bytes: 3964
#include<iostream>
#include<cassert>
#include<stdexcept>
#include<utility>
#include<functional>
#include<numeric>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<array>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<complex>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<bitset>
using namespace std;
using ll=long long;

void cmax(int &lhs,int rhs){lhs=max(lhs,rhs);}
int main(){
    string s;
    cin>>s;
    vector<vector<int>> dp(s.size()+1,vector<int>(2,-1e9));
    dp[0][0]=0;
    for(int i=0;i<s.size();i++){
        for(int j=0;j<2;j++){
            if(i+1<=s.size()){
                if(i==0 || j==1 || j==0 && s[i-1]!=s[i]){
                    cmax(dp[i+1][0],dp[i][j]+1);
                }
                
            }
            if(i+2<=s.size()){
                if(i<=1 || j==0 || s.substr(i-2,2)!=s.substr(i,2)){
                    cmax(dp[i+2][1],dp[i][j]+1);
                }
            }
        }
    }
    cout<<max(dp[s.size()][0],dp[s.size()][1])<<endl;

    
    return 0;
}


Measured memory_bytes: 11396
#include <iostream>
#include <vector>
#include <queue>
#include <deque>

using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> A(N);
    int sum = 0;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        sum += A[i];
    }
    int count = 0;
    for (int i = 0; i < N; i++) {
        if (A[i] * 4 * M >= sum) {
            count++;
        }
    }
    cout << (count >= M ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<char> S(N);
  bool ans = false;
  for(int i=0; i < N; i++){
    cin >> S.at(i);
    if(S.at(i) == 'Y' ){
      ans = true;
    }
  }
  if(ans == true){
    cout << "Four" << endl;
  }
  else {
    cout << "Three" << endl;   
  }
}


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

int n;
long long ans;

template<typename Drake>
void Read(Drake &x){
	x=0;char ch=getchar();int f=1;
	while(!isdigit(ch)){
		if(ch=='-')f=-f;
		ch=getchar();
	}
	while(isdigit(ch)){
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	x=x*f;
}

template<typename Drake>
void write(Drake x){
	if(x>=10)write(x/10);
	putchar((char)(x%10+'0'));
}

template<typename Drake>
void writeln(Drake x){
	write(x);
	puts("");
}

int main(){
	Read(n);
	ans=0;
	for(int i=1;i<=n;++i){
		ans+=n/i-(n%i==0);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3620
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;

int main(){
    // input
    string s; cin >> s;
    
    // compute
    vector<int> a;
    vector<int> z;
    for (int i=0; i < s.size(); i++){
        if (s.at(i) == 'A'){
            a.push_back(i);
        }
        if (s.at(i) == 'Z'){
            z.push_back(i);
        }
    }
    int A = *min_element(a.begin(), a.end());
    int Z = *max_element(z.begin(), z.end());
    // output
    cout << Z-A+1 << endl;
}



Measured memory_bytes: 1364
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
typedef long long ll;

using ipair = pair<int, int>;

ll INF = 1e16+7;
ll mod = 998244353;

bool operator>(const ipair a,const ipair b){return a.first > b.first;}

int main(){
  int N;
  cin >> N;
  vector<ll> A(N+1);
  rep(i, N) cin >> A[i];

  ll ans = 0;
  ll MOD = 1e9+7;

  rep(k, 60){
    ll cnt_x = 0;
    ll cnt_y = 0;

    rep(i, N) if(A[i]>>k&1) cnt_x++;
    cnt_y = N-cnt_x;
    ll tmp = cnt_x * cnt_y;
    rep(i, k){
      tmp *= 2;
      tmp %= MOD;
    }
    ans += tmp;
    ans %= MOD;
  }


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


Measured memory_bytes: 5640
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

#define MIN_INT -2147483648
#define MAX_INT 2147483647
#define MIN_LONG -9223372036854775808L
#define MAX_LONG 9223372036854775807L
#define PI 3.141592653589793238462643383279502884L

#define long long long int

using std::vector;
using std::map;
using std::set;
using std::string;
using std::pair;
using std::cin;
using std::cout;
using std::cerr;

// @author: pashka

string s;
bool ok;

void bt(int i, int sum, string res) {
    if (ok) return;
    if (i == 4) {
        if (sum == 7) {
            cout << res << "=7";
            ok = true;
        }
    } else {
        bt(i + 1, sum + (s[i] - '0'), res + "+" + s.substr(i, 1));
        bt(i + 1, sum - (s[i] - '0'), res + "-" + s.substr(i, 1));
    }
}

int main() {
    std::ios::sync_with_stdio(false);


    cin >> s;
    ok = false;
    bt(1, s[0] - '0', s.substr(0, 1));

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstdlib>
#include <stack>
#include <vector>
#define INF 0x3f3f3f3f
#define MOD 1000000009
# define FOR(i,a,n) for(register int i=a; i<=n; ++i)
# define FDR(i,a,n) for(register int i=a; i>=n; --i)
typedef long long ll;

using namespace std;
int f[1005][20];
int p[1005][20];
int b[2000];
int sum[1000];
int ji = 0;
ll ans;
int n;
void solve(int cur)
{
    for(int i = 0; i < cur; i++)
    {
        for(int j = 1; j <= n; j++)
        {
            for(int k = 1; k <= 10; k++)
            if(f[j][k] == 1 && b[i] == k)sum[j]++;
        }
    }
    ll sum1 = 0;
    for(int i = 1; i <= n; i++)
    {
        sum1 += p[i][sum[i]];
    }
    ans = max(ans, sum1);
}
void dfs(int cur)
{
    memset(sum, 0, sizeof(sum));
    if(cur != 0)solve(cur);
    int s = cur?b[cur-1]+1:1;
    for (int i = s;i <= 10; i++)
     {
         b[cur] = i;
         dfs(cur+1);
     }
}
int main()
{
    scanf("%d", &n);
    FOR(i,1,n)
    FOR(j,1,10)
    cin >> f[i][j];
    FOR(i,1,n)
    FOR(j,0,10)
    cin >> p[i][j];
    memset(b, 0, sizeof(b));
    ans = -INF;
    ji = 1;
    dfs(0);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<numeric>
#include<set>
#include<map>
#include<deque>
#include<list>
#include<forward_list>
#include<utility>
#include<bitset>
#define ll long long 
using namespace std;
void fireman()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

int prime(int x)
{
	bool b = true;
	if (x == 2)
	{
		return true;
	}
	else if (x == 1 || x % 2 == 0)
	{
		return false;
	}
	for (int i = 3; i * i <= x; i += 2)
	{
		if (x % i == 0)
		{
			b = false;
			return false;
			break;
		}
	}
	return true;
}

int main()
{
	fireman();
	int arr[6];
	for (int i = 1; i <= 5; i++)
	{
		cin >> arr[i];
		if (arr[i] == 0)
		{
			cout << i << endl;
		}
	}


}





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

#include <iostream>
#include <algorithm>

#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>
#include <string>
#include <utility>
#include <array>
#include <complex>
#include <valarray>

#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <chrono>
#include <random>
#include <numeric>


using namespace std;
#define int long long

typedef long long ll;
typedef unsigned long long ull;
//typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef pair<ll,pll> plpll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<vector<int>> mat;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const int INF = 1<<30;
const ll mod = 1000000000 + 7;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

#define addm(X, Y) (X) = ((X) + ((Y) % mod) + mod) % mod

struct edge {int to, cost;};
vector<vector<edge>> g(100000 + 5);
vector<int> dijkstra(int s, int n, vector<vector<edge>>& g) {
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
    vector<int> d(n, INF);
    d[s] = 0;
    pq.push({d[s], s});
    while (!pq.empty()) {
        pair<int, int> pa = pq.top(); pq.pop();
        int now = pa.se;
        for (auto e : g[now]) {
            if (d[e.to] > d[now] + e.cost) {
                d[e.to] = d[now] + e.cost;
                pq.push({d[e.to], e.to});
            }
        }
    }
    return d;
}

int k;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> k;
    rep(i, k) {
        g[i].push_back(edge{(i + 1) % k, 1});
        g[i].push_back(edge{(i * 10) % k, 0});
    }
    vector<int> dist = dijkstra(1, k, g);
    cout << dist[0] + 1 << endl;
}

Measured memory_bytes: 9212
#include<stdio.h>
int main()
{
    int n;
    scanf ("%d",&n);
    long long int sum=0;
    for (int i=1;i<=n;i++)
    {
        if (i%3!=0 && i%5!=0)
        {
            sum=sum+i;
        }
    }
    printf ("%lld\n",sum);

}

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

using namespace std;
using ll=long long;
using vi=vector<int>;
using vl=vector<ll>;
using vs=vector<string>;
using li=list<int>;
using lil=list<ll>;
using lis=list<string>;
using fli=forward_list<int>;
using fll=forward_list<ll>;
using fls=forward_list<string>;
using si=stack<int>;
using sl=stack<ll>;
using ss=stack<string>;
using qi=queue<int>;
using ql=queue<ll>;
using qs=queue<string>;
using pqi=priority_queue<int>;
using pql=priority_queue<ll>;
using pqs=priority_queue<string>;
using dqi=deque<int>;
using dql=deque<ll>;
using dqs=deque<string>;

#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, a, n) for(int i = (n); i < (a); i++)
#define repr(i, n) for(int i = (n); i >= 0; i--)
#define repr2(i, a, n) for(int i = (n); i >= (a); i--)

template<typename T,typename U>
void Inparray(T &f,U n){
  for(int i=0;i<n;i++) cin>>f[i];
}

template<typename T,typename U>
void Printarray(T f,U n){
  for(int i=0;i<n;i++) i!=n ? cout<<f[i]<<" " : cout<<f[i];
}

template<typename T,typename U>
void Printarray2(T f,U n){
  for(int i=0;i<n;i++) cout<<f[i]<<endl;
}

void flagfunc(bool flag,string A,string B){
  flag ? cout<<A<<endl : cout<<B<<endl;
}

void flag2func(bool flag){
  flag ? cout<<"Yes"<<endl : cout<<"No"<<endl;
}

void flag3func(bool flag){
  flag ? cout<<"YES"<<endl : cout<<"NO"<<endl;
}

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  string s,t,u;cin>>s>>t;
  int a,b;cin>>a>>b>>u;
  if(u==s)a--;
  if(u==t)b--;
  cout<<a<<" "<<b<<endl;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const int mod=1000000007;

struct BinaryIndexedTree{
	int n;
	vector<int>dat;
	BinaryIndexedTree(int n=0):n(n){
		dat.resize(n+1);
	}
	void add(int k,int x){
		for(k++;k<=n;k+=k&-k)dat[k]=(dat[k]+x)%mod;
	}
	int sum(int k){
		int ret=0;
		for(k++;k;k-=k&-k)ret=(ret+dat[k])%mod;
		return ret;
	}
};

signed main(){
	int N,M;
	cin>>N>>M;
	vint X(N),Y(M);
	rep(i,N)cin>>X[i];
	rep(i,M)cin>>Y[i];

	vpint ps;
	vint ys;
	rep(i,N){
		if(X[i]<Y[0]||Y[M-1]<X[i])continue;
		int k=lower_bound(all(Y),X[i])-Y.begin()-1;
		ps.pb(pint(X[i]-Y[k],Y[k+1]-X[i]));
		ys.pb(ps.back().se);
	}

	sort(all(ys));ys.erase(unique(all(ys)),ys.end());
	rep(i,ps.size()){
		ps[i].se=lower_bound(all(ys),ps[i].se)-ys.begin()+1;
		ps[i].se*=-1;
	}
	sort(all(ps));ps.erase(unique(all(ps)),ps.end());


	rep(i,ps.size())ps[i].se*=-1;


	BinaryIndexedTree bit(N+114);
	bit.add(0,1);

	for(auto &p:ps){
		int y=p.se;
		bit.add(y,bit.sum(y-1));
	}
	cout<<bit.sum(N)<<endl;
	return 0;
}

Measured memory_bytes: 5232
#include<bits/stdc++.h>
//#include <atcoder/all>
#define ll long long int
#define vec vector<ll>
#define mat vector<vector<ll>>

using namespace std;
//using namespace atcoder;

const ll mod=1000000007;
const ll inf=LONG_LONG_MAX;
ll dx4[4]={1,0,-1,0};
ll dy4[4]={0,-1,0,1};
ll dx8[8]={1,0,-1,1,-1,1,0,-1};
ll dy8[8]={1,1,1,0,0,-1,-1,-1};

int main(){

  double a,b;
  cin >> a >> b;
  cout << ceil((a+b)/2) << endl;

  return 0;
}

Measured memory_bytes: 3748
#include <stdio.h>

int main(){
    int n,t,a;
    scanf("%d%d%d",&n,&t,&a);
    
    int i;
    int m;
    int x=100000000;
    int d;
    int ans=0;
    for(i=0; i<n; i++){
        scanf("%d",&m);
        
        d=t*1000-m*6-a*1000;
        if(d<0)d=-d;
        
        if(d<x)x=d,ans=i+1;
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

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

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;

const int INF = 1 << 30;
const long long INFL = 1LL << 60;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100;

int main() {
	int x,t;cin>>x>>t;
	cout<<max(x-t,0)<<endl;
}


Measured memory_bytes: 256
#!/usr/bin/python3

from math import floor

while True:
    n = eval(input())
    if n != 0:
        ls = []
        for i in range(n):
            m = eval(input())
            ls.append(m)
        ls.remove(max(ls))
        ls.remove(min(ls))
        print(floor(sum(ls)/len(ls)))
    else:
        break

Measured memory_bytes: 6812
MOD=10**9+7
cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.chomp.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def desc(ar) ar.sort!{|x,y| y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end
def rui(ar) s=[0]; ar.size.times{|i| s<<s[-1]+ar[i]}; s end
def rev_rui(ar) s=[0]; ar.size.times.reverse_each{|i| s<<s[-1]+ar[i]}; s end

def puts_yesno(b) puts(b ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def debug(k,v) puts "#{k}:#{v}" end
########### ( ˘ω˘ )ｽﾔｧ… ###########
h=gi
w=gi
n=gi
puts (n.to_f/max(h,w)).ceil

Measured memory_bytes: 1788
/*author:anshumanc007
   created on:09/01/2019
            */
//EMBRACE THE STRUGGLE!!!
#include <bits/stdc++.h>
#include <queue>
#include <stack>
using namespace std;
#define MAX 100005
long long int MOD=1e9+7;
long long int INF=1e18;
long long int dp[MAX]={0};

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long int i,j,k,l,m,n,o,p,q,r,x,y,a,b,mini=INF,maxi=0,cnt=0,W,ans,iter=0;
    cin>>n>>k;
    long long int A[n];
    for(i=0;i<n;i++)
    {
        cin>>A[i];
        dp[A[i]]=1;
    }
    for(i=1;i<=k;i++)
    { p=0;
        for(j=0;j<n;j++)
        { if(i-A[j]>=0)
        {
            if(dp[i-A[j]]==0)
            {
                p=1;
            }
        }
        }
     if(p==1)
     dp[i]=1;
    }
    if(dp[k])
    {
        cout<<"First";
    }
    else{
        cout<<"Second";
    }
  

    
}

Measured memory_bytes: 1024
from math import ceil
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))

A.sort()

if N % 2 == 1:
    num = (N - 1) // 2
    if A[0] != 0:
        print(0)
        exit()
    for i in range(1, N):
        if A[i] == ceil(i / 2) * 2:
            continue
        else:
            print(0)
            exit()
else:
    num = N // 2
    for i in range(N - 1):
        if A[i] == (i // 2) * 2 + 1:
            continue
        else:
            print(0)
            exit()
ans = 1
for i in range(num):
    ans *= 2
    ans %= (10**9 + 7)

print(ans)


Measured memory_bytes: 52828
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int main() {
    string s;
    int k;
    cin >> s >> k;
    vector<int> n;
    for (auto a : s) n.push_back(a - '0');
    int l = n.size();

    vector<vector<vector<int64>>> dp(l+1, vector<vector<int64>>(2, vector<int64>(5,0)));

    dp[0][0][0] = 1;

    for(int64 i = 0; i < l; i++){
        for(int64 smaller = 0; smaller < 2; smaller++){
            for(int64 j = 0; j <= 3; j++){
                for(int64 x = 0; x<= (smaller ? 9 : n[i]); x++){
                    dp[i + 1][smaller || x < n[i]][j + (x!=0? 1 : 0)] += dp[i][smaller][j];
                }
            }
        }
    }
    
    cout << dp[l][0][k] + dp[l][1][k] << endl;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MAX_N = 1005;
ll a[MAX_N];
bool use[MAX_N*MAX_N];
vector<ll> subs;

int main()
{
	int N,K;
	cin >> N >> K;
	rep(i,N)
	{
		cin >> a[i];
	}
	for (int i = 0; i < N; ++i)
	{
		ll temp = 0;
		for (int j = i; j < N; ++j)
		{
			temp += a[j];
			subs.push_back(temp);
		}
	}

	/*
	rep(i,subs.size())
	{
		cout << subs[i] << " ";
	}
	*/

	ll ans = 0;
	rep(i,subs.size())
	{
		use[i] = true;
	}
	for(int i = 45; i >= 0; --i)
	{
		int cnt = 0;
		rep(j,subs.size())
		{
			if (use[j] && ((1ull << i) & subs[j])) cnt++;
		}
		if (cnt >= K)
		{
			ans += (1ull << i);
			//cout << ans << " ";
			rep(j,subs.size())
			{
				if (use[j] && !((1ull << i) & subs[j])) use[j] = false;
			}
		}
		//cout << i << " " << cnt << endl;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 7608
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5;
int a[maxn+5];
ll sum[maxn+5];
int n,k;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
    for (;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+ch-'0';
    return x*f;
}
int main()
{
    scanf("%d%d",&n,&k);
    for (int i=1;i<=n;i++) scanf("%d",&a[i]);
    for (int i=1;i<=n;i++) sum[i]=sum[i-1]+a[i];
    ll mx=0;
    for (int i=k;i<=n;i++)
        if (sum[i]-sum[i-k]>=mx) mx=sum[i]-sum[i-k];
    printf("%.10f\n",(mx+k)/2.0);
    return 0;
}



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

int main(){
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  
  for(int i = 0; i < tx-sx; i++){
    cout << 'R';
  }
  for(int i = 0; i < ty - sy; i++){
    cout << 'U';
  }
  for(int i = 0; i < tx - sx; i++){
    cout << 'L';
  }
  for(int i = 0; i < ty-sy; i++){
    cout << 'D';
  }
  
  cout << 'D';
   for(int i = 0; i < tx-sx+1; i++){
    cout << 'R';
  }
  for(int i = 0; i < ty - sy+1; i++){
    cout << 'U';
  }
  cout << 'L';
  cout << 'U';
  for(int i = 0; i < tx - sx+1; i++){
    cout << 'L';
  }
  for(int i = 0; i < ty-sy+1; i++){
    cout << 'D';
  }
  cout << 'R';
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace chrono;
using namespace __gnu_pbds;
mt19937 rng(high_resolution_clock::now().time_since_epoch().count());
mt19937_64 rngll(high_resolution_clock::now().time_since_epoch().count());
template<typename T> T ctmax(T &x, const T &y){ return x = max(x, y); }
template<typename T> T ctmin(T &x, const T &y){ return x = min(x, y); }
template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;



int main(){
	cin.tie(0)->sync_with_stdio(0);
	int n, m, k;
	cin >> n >> m >> k;
	vector<int> a(n), b(m);
	copy_n(istream_iterator<int>(cin), n, a.begin());
	copy_n(istream_iterator<int>(cin), m, b.begin());
	int res = *min_element(a.begin(), a.end()) + *min_element(b.begin(), b.end());
	for(int i = 0; i < k; ++ i){
		int x, y, c;
		cin >> x >> y >> c, -- x, -- y;
		ctmin(res, a[x] + b[y] - c);
	}
	cout << res;
	return 0;
}

/*

*/

////////////////////////////////////////////////////////////////////////////////////////
//                                                                                    //
//                                   Coded by Aeren                                   //
//                                                                                    //
////////////////////////////////////////////////////////////////////////////////////////

Measured memory_bytes: 1024
#include<iostream>

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


Measured memory_bytes: 3632
#define TEST_MODE true
 
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
 
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define rrep(i, n) for (int i = (n)-1; i >= 0; --i)
#define rrep2(i, a, b) for (int i = (a)-1; i >= (int)b; --i)
#define range(i, a, b, c) for (int i = a;		\
                               c > 0 ? i < b : i > b;	\
                               i += c)
#define chmax(a, b) (a = (a) < (b) ? (b) : (a))
#define chmin(a, b) (a = (a) > (b) ? (b) : (a))
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(a) begin(a), end(a)
#define ifnot(a) if (not(a))
#define int long long
 
#if TEST_MODE == true
const bool test = true;
#define dump(x) cerr << #x << " = " << (x) << " "
#define dumpl(x) cerr << #x << " = " << (x) << " " << endl;
#else
const bool test = false;
#define dump(x) 
#define dumpl(x) 
#endif
 
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
const int INF = (int)1 << 60;
const ll INFL = (ll)1 << 60;
ll mod_n = (int)1e9 + 7;
const double eps = 1e-10;
typedef long double Real;
// return -1, 0, 1
int sgn(const Real &r) { return (r > eps) - (r < -eps); }
int sgn(const Real &a, const Real &b) { return sgn(a - b); }
 
//.....................
const int MAX = (int)2e5 + 5;
 
vector<string> split(const string &str, char sep)
{
  vector<string> v;
  stringstream ss(str);
  string buffer;
  while (getline(ss, buffer, sep))
    {
      v.push_back(buffer);
    }
  return v;
}
 
template <class InputIterator>
int sum(InputIterator begin, InputIterator end)
{
  return accumulate(begin, end, 0ll);
}
 
template<typename T>
T gcd(T a, T b)
{
  T c;
  while (a != 0) {
    c = a; a = b%a;  b = c;
  }
  return b;
}
 
void solve();
 
class Solver {
public:
  int N;
  vector<int> A;

  int ans() {
    set<int> set1;
    rep(i, A.size()) {
      if (set1.count(A[i]) == 0) {
	set1.insert(A[i]);
      }
      else set1.erase(A[i]);
    }
    return set1.size();
  }
 
  void solve() {
    cin >> N;
    A.resize(N);
    rep(i, N) cin >> A[i];
    cout << ans() << endl;
  }
};
 
signed main()
{
  srand(time(NULL));
  cout << fixed << setprecision(20);
  auto ptr = new Solver();
  ptr->solve();
  delete ptr;
  // while (true) {    
  //     auto ptr = new Solver();
  //     ptr->solve();
  //     delete ptr;
  // }
  return 0;
}
 
// class Mycin {
// 	bool flag = true;
// public:
// 	Mycin& operator >> (int& a) {flag = scanf("%lld", &a) != EOF; return *this;}
// 	Mycin& operator >> (char& a) {flag = scanf("%c", &a) != EOF; return *this;}
// 	Mycin& operator >> (string& s) {flag = (bool)(cin >> s); return *this;}
// 	operator bool() {return flag;}
// } mycin;
 
// class Mycout {
// public:
// 	Mycout& operator << (const int& a) {printf("%lld", a); return *this;}
// 	Mycout& operator << (const char c) {printf("%c", c); return *this;}
// 	Mycout& operator << (const string& s) {printf("%s", s.c_str()); return *this;}
// } mycout;
 
// #define cin mycin
// #define cout mycout
// #define endl '\n'


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

int main() {
    int H, W, count=0;
    cin >> H >> W;
    char S[H][W];
    
    for(int i=0; i<H; i++)
        for(int j=0; j<W; j++)
            cin >> S[i][j];
    
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            if(S[i][j]=='#'){
                if(i==0){
                    if(j==0){
                        if(S[i+1][j]=='.' && S[i][j+1]=='.'){
                            cout << "No" << endl;
                            return 0;
                        }
                    }
                    else if(j == W-1){
                        if(S[i+1][j]=='.' && S[i][j-1]=='.'){
                            cout << "No" << endl;
                            return 0;
                        }
                    }
                    else{
                        if(S[i+1][j]=='.' && S[i][j-1]=='.' && S[i][j+1]=='.'){
                            cout << "No" << endl;
                            return 0;
                        }
                    }
                }
                else if(i==H-1){
                    if(j==0){
                        if(S[i-1][j]=='.' && S[i][j+1]=='.'){
                            cout << "No" << endl;
                            return 0;
                        }
                    }
                    else if(j == W-1){
                        if(S[i-1][j]=='.' && S[i][j-1]=='.'){
                            cout << "No" << endl;
                            return 0;
                        }
                    }
                    else{
                        if(S[i-1][j]=='.' && S[i][j-1]=='.' && S[i][j+1]=='.'){
                            cout << "No" << endl;
                            return 0;
                        }
                    }
                }
                else{
                    if(j==0){
                        if(S[i-1][j]=='.' && S[i+1][j]=='.' && S[i][j+1]=='.'){
                            cout << "No" << endl;
                            return 0;
                        }
                    }
                    else if(j==W-1){
                        if(S[i-1][j]=='.' && S[i+1][j]=='.' && S[i][j-1]=='.'){
                            cout << "No" << endl;
                            return 0;
                        }
                    }
                    else{
                        if(S[i-1][j]=='.' && S[i][j-1]=='.' && S[i+1][j]=='.' && S[i][j+1]=='.'){
                            cout << "No" << endl;
                            return 0;
                        }
                    }
                }
            }
        }
        count++;
    }
    if(count == H) cout << "Yes" << endl;
}

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

f=1
ans = 1

al = [0 for i in range(10000)]

al[s]=1

while f>0:
    ans+=1
    
    if s%2==0:
        s=s//2
    else:
        s=3*s+1
       
    if al[s]==1:
        f=-1
    else:
        al[s]=1
        
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
  int n;
  scanf("%d", &n);

  vector<int> ar;

  for(int i=0; i<n; i++)
  {
    int temp;
    scanf("%d", &temp);
    ar.push_back(temp);
  }

  int l = 0;
  while(l!=n-1)
  {
    printf("%d ",ar[l]);
    l++;
  }
  printf("%d\n", ar[l]);

  for(int i=1; i<n; i++)
  {
    int medium = ar[i];
    int j = i-1;
    while(j>=0 && ar[j] >= medium)
    {
      ar[j+1] = ar[j];
      j--;
    }
    ar[j+1] = medium;

    int l = 0;
    while(l!=n-1)
    {
      printf("%d ",ar[l]);
      l++;
    }
    printf("%d\n", ar[l]);

  }
  return 0;
}



Measured memory_bytes: 3284
public class Main {
  private static void solve() {
    int a = ni();
    int b = ni();
    if (a <= 8 && b <= 8) {
      System.out.println("Yay!");
    } else {
      System.out.println(":(");
    }
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}




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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    string S;cin>>S;
    int ans=1001001001;
    for(int i=0;i+3<=S.size();i++){
        int n=(S[i]-'0')*100+(S[i+1]-'0')*10+S[i+2]-'0';
        chmin(ans,abs(753-n));
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define met(s) memset(s, 0, sizeof(s))
const int mod = 100000007;
const int maxn = 1000000;
const int inf = 0x3f3f3f3f;
char str[maxn];
int main()
{
    scanf("%s",str);
    int len=strlen(str);
    int now=2,i=0,ans=0;
    char a,b;
    while(i<len)
    {
        if(now==2)
        {
            now=1;
            a=str[i];
            i++;
        }
        else if(now==1)
        {
            if(a==str[i])
            {
                if(i+1>=len) break;
                a=str[i],b=str[i+1];
                i+=2;
                now=2;
            }
            else 
            {
                a=str[i];
                i++;
            }
        }
        ans++;
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 1020
#include<iostream>
using namespace std;
int main() {
    int A,B,K,a,min;
    a=0;

    
    cin >> A >> B >> K;
        min=A;
    
    if (A>B) min=B;
    
    
    while (a<K) {
    
        if (A%min==0 && B%min==0) a=a+1;
            
        min=min-1;
    
    }
    
    cout << min+1 <<endl;
    
}


Measured memory_bytes: 256
#include <iostream>
#include <bitset>
#include <fstream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
//#include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);


using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const Int MOD = 1000000007;

Int mod_pow(Int x, Int n) {
    Int res = 1;
    while(n > 0) {
        if(n & 1) res = (res * x) % MOD; //ビット演算(最下位ビットが1のとき)
        x = (x * x) % MOD;
        n >>= 1; //右シフト(n = n >> 1)
    }
    return res;
}

template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

int main(){
    int N, M; cin >> N >> M;
    if ((N+1)/2 >= M) cout << "YES" << endl;
    else cout << "NO" << endl;

}


Measured memory_bytes: 888
#include <stdio.h>
#include <stdbool.h>

int main(void)
{
  bool isPrime[1000000];
  int i,j;
  for(i=2; i<1000000; ++i){
    isPrime[i] = true;
  }
  int primeCount[1000000];

  for(i=2; i<1000000; ++i){
    if(isPrime[i]){
      primeCount[i] = primeCount[i-1]+1;
      if(i<1000){
        for(j=i*2; j<1000000; j+=i){
          isPrime[j] = false;
        }
      }
    }else{
      primeCount[i] = primeCount[i-1];
    }
  }
        
  int n;
  while(scanf("%d", &n) != EOF){
    printf("%d\n", primeCount[n]);
  }

  return 0;
}

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

int main(){
    int N;
    cin >> N;
    string s;
    cin >> s;
    int ans = 1;
    for (int i = 0; i < N -1; i++){
        if (s.at(i) != s.at(i+1)){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main
{
	static int aa[] = new int[10]; 
	public static void main(String arg[])
	{
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext())
		{
			String a =sc.next();
			for(int i=0; i<10; i++)
			{
				aa[i]= a.charAt(i)-48;
			}

			sumdi(9,aa);
		}
	}
	public static int sumdi(int n, int a[])
	{
		if(n==0)
			return 0;
		for(int i=0; i< n; i++)
			a[i] = (a[i]+a[i+1])%10;
		if(n==1)
			System.out.println(a[0]);
		return sumdi(n-1, a);
	}


}

Measured memory_bytes: 12000
#include <algorithm>
#include <array>
#include <bitset>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using namespace std;

struct BoolName : numpunct<char> {
  string t, f;
  BoolName (string t = "Yes", string f = "No") : t(t), f(f) {}
  string do_truename() const {return t;}
  string do_falsename() const {return f;}
};

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15) << boolalpha;
    cout.imbue(locale(cout.getloc(), new BoolName));
  }
} initializer;

template<typename T> istream& operator>>(istream &s, vector<T> &v) {
  for (T &t : v) s >> t;
  return s;
}

template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
  for (const T &t : v) s << t << endl;
  return s;
}

void set_bool_name(string t, string f) {
  cout.imbue(locale(cout.getloc(), new BoolName(t, f)));
}

template<typename T> bool chmin(T& a, T b) {return a > b ? a = b, true : false;}

template<typename T> bool chmax(T& a, T b) {return a < b ? a = b, true : false;}

template<typename T> void sort(vector<T>& v) {sort(v.begin(), v.end());}

class UnionFind {
private:
  int n;
  vector<int> a;
public:
  UnionFind(int n) : n(n), a(n, -1) {}
  int find(int x) {return a[x] < 0 ? x : (a[x] = find(a[x]));}
  bool equal(int x, int y) {return find(x) == find(y);}
  void unite(int x, int y) {
    x = find(x), y = find(y);
    if (x == y) return;
    if (a[x] > a[y]) swap(x, y);
    a[x] += a[y];
    a[y] = x;
    --n;
  }
  int size() {return n;}
  int size(int x) {return -a[find(x)];}
  bool isRoot(int x) {return find(x) == x;}
  vector<vector<int>> groups() {
    vector<vector<int>> r(a.size()), res;
    for (unsigned i = 0; i < a.size(); ++i) r[find(i)].emplace_back(i);
    for (auto&& i : r) if (!i.empty()) res.emplace_back(move(i));
    return res;
  }
};

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> p(n);
  cin >> p;
  UnionFind uf(n);
  for (int i = 0; i < m; ++i) {
    int x, y;
    cin >> x >> y;
    uf.unite(x - 1, y - 1);
  }
  int res = 0;
  for (int i = 0; i < n; ++i) {
    if (uf.equal(i, p[i] - 1)) ++res;
  }
  cout << res << endl;
}



Measured memory_bytes: 1024
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static Scanner in = new Scanner(System.in);
	
	public static void main(String[] args){
		int N = in.nextInt(), C  = in.nextInt(), K = in.nextInt();
		int[] t = new int[N];
		for(int i = 0; i < N; i++){
			t[i] = in.nextInt();
		}
		Arrays.sort(t);
		int bus = 0, time = 0, sum = 1;
		for(int i = 0; i < N; i++){
			if(i == 0){
				time = t[i];
				bus++;
			}else if(t[i] <= time + K && bus < C){
				bus++;
			}else{
				sum++;
				bus = 1;
				time = t[i];
			}
		}
		System.out.println(sum);
		
	}
}

Measured memory_bytes: 48836
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

signed main() {
    int n;
    cin >> n;
    vector<pair<ll, int>> v(n);
    ll a[n];
    rep(i, n) {
        cin >> a[i];
        v[i] = {a[i], i};
    }
    sort(ALL(v));
    reverse(ALL(v));
    ll dp[n + 1][n + 1];
    fill(dp[0], dp[n + 1], -LINF);
    dp[0][0] = 0;
    rep(i, n) {
        rep(j, n) {
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + v[i].first * (v[i].second - (i - j)));
            if (j - 1 < 0) continue;
            dp[i + 1][j] =
                max(dp[i + 1][j],
                    dp[i][j - 1] + v[i].first * (n - 1 - v[i].second - (j - 1)));
        }
    }
    ll ans = 0;
    rep(i, n + 1) {
        ans = max(ans, dp[n][i]);
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;

void setmax(ll& a, ll b){
    if(a < b){ a = b; }
}

int main(){
    ll n, w;
    cin >> n >> w;
    vector<ll> weight(n), value(n);
    for(int i = 0; i < n; ++i){
        cin >> weight.at(i);
        cin >> value.at(i);
    }

    vector<vector<ll>> dp(n + 1, vector<ll>(w + 1, 0));
    for(ll i = 1; i <= n; ++i){
        for(ll j = 0; j <= w; ++j){
            dp.at(i).at(j) = dp.at(i - 1).at(j);
            if(j > 0){
                setmax(dp.at(i).at(j), dp.at(i).at(j - 1));
            }
            if(j >= weight.at(i - 1)){
                setmax(
                    dp.at(i).at(j),
                    dp.at(i - 1).at(j - weight.at(i - 1)) + value.at(i - 1)
                );
            }
        }
    }
    cout << dp.at(n).at(w) << endl;
    return 0;
}

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

int main(){
	int n,x;
	cin >> n >> x;
	while(n!=0 || x!= 0) {
		int ans = 0;
		for (int i = 1; i <= n - 2; ++i) {
			for (int j = i + 1; j <= n - 1; ++j) {
				for (int k = j + 1; k <= n; ++k) {
					if (i + j + k == x) {
						ans++;
					}
				}
			}
		}
		cout << ans << endl;
		cin >> n >> x;
	}
	
    return 0;
}




Measured memory_bytes: 3092
def dfs(n):
    global t
    S[n] = t
    DP[n]=1
    for i in A[n][2:]:
        if not DP[i]:
            t += 1
            dfs(i)
    t += 1
    F[n] = t
n = int(input())
A = [0]*(n+1)
S = [0]*(n+1)
F = [0]*(n+1)
DP = [0]*(n+1)
for i in range(n):
    A[i+1] = [int(i) for i in input().split()]
t = 0
for i in range(1,n+1):
    if not DP[i]:
        t+=1
        dfs(i)
for i in range(1,n+1):
    tmp = "{} {} {}".format(i,S[i],F[i])
    print(tmp)


Measured memory_bytes: 5628
#include <bits/stdc++.h>
using namespace std;
 
int main(){
int N, x, sum;
x = 0;
sum = 0;  
cin >> N;
int L[N];
  for(int i = 0;i < N;i++){
  cin >> L[i];
  x = max(x, L[i]);  
  sum += L[i];  
  }
  
  if(sum - x > x) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 256
MOD = int(1e9) + 7

L = str(input())
dp_k = 0
dp_u = 1

for l in L:
    if l == "0":
        dp_k = (dp_k * 3) % MOD
    else:
        dp_k = (dp_k * 3 + dp_u) % MOD # (A, B) = (0, 0), (1, 0), (0, 1)
        dp_u = (dp_u * 2) % MOD # (A, B) = (0, 1) or (1, 0)

print((dp_k + dp_u) % MOD)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template <typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template <typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}




int main()
{
    int H,W;
    cin >> H >> W;
    ve<string> S(H);
    in(H,S);
    
    vvi A(H+1,vi(W+1,infi));
    vvi F(H+1,vi(W+1,0));
    A[0][0] = 0,A[0][1] = 0, A[1][0] = 0;
    
    rep(i,H){
        
        rep(j,W){
            
            if(S[i][j] == '.'){
                A[i+1][j+1] = min(A[i][j+1],A[i+1][j]);
            }else{
                F[i+1][j+1] = 1;
                if(F[i][j+1] == 1){
                    chmin(A[i+1][j+1],A[i][j+1]);
                }else{
                    chmin(A[i+1][j+1],A[i][j+1]+1);
                }
                
                if(F[i+1][j] == 1){
                    chmin(A[i+1][j+1],A[i+1][j]);
                }else{
                    chmin(A[i+1][j+1],A[i+1][j]+1);
                }

                
            }

            
        }
    }
    
    //outmat(A);
    cout << A[H][W] << endl;
    
    
    
    

    return 0;
}


Measured memory_bytes: 384