akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"; return os;}
template<class T,size_t n> ostream& operator<<(ostream &os, const array<T,n> &t) {os<<"{"; rep(i,n) {os<<t[i]<<",";} os<<"}"; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const ll INF = 1e9+7;


int main(){
	ios_base::sync_with_stdio(false);
	ll X, Y, A, B, C, ans=0;
	ll p[100005], q[100005], r[100005];

	cin >> X >> Y >> A >> B >> C;
	rep(i,A) cin >> p[i];
	rep(i,B) cin >> q[i];
	rep(i,C) cin >> r[i];

	sort(p, p+A);
	sort(q, q+B);
	sort(r, r+C);
	reverse(p, p+A);
	reverse(q, q+B);
	reverse(r, r+C);

	vector<ll> v;
	rep(i,X) v.push_back(p[i]);
	rep(i,Y) v.push_back(q[i]);
	sort(all(v));
	sort(all(v));

	ll sum = 0;
	for(auto a: v) sum += a;
	chmax(ans, sum);
	rep(i,min<int>(v.size(), C)){
		sum += r[i] - v[i];
		chmax(ans, sum);
	}

	cout << ans << endl;

	return 0;
}

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

int n, x, m, smax = -1;
vector<int> a, l, r, s, ans;

bool rec(int k){
    if(k == 0){
        bool ok = true;
        for(int i=0;i<m;i++){
            int sum = 0;
            for(int j=l[i]-1;j<r[i];j++){
                sum += a[j];
            }
            if(sum != s[i]) ok = false;
        }
        if(ok){
            int sum = 0;
            for(int i=0;i<n;i++) sum += a[i];
            if(sum > smax){
                ans = a;
            }
        }
        return ok;
    }
    else{
        bool ok = false;
        for(int i=0;i<=x;i++){
            a[k-1] = i;
            ok |= rec(k-1);
        }
        return ok;
    }
}

int main(){
    cin >> n >> x >> m;
    a.resize(n);
    l.resize(m);
    r.resize(m);
    s.resize(m);
    for(int i=0;i<m;i++){
        cin >> l[i] >> r[i] >> s[i];
    }
    if(rec(n)){
        for(int i=0;i<n;i++){
            cout << ans[i] << " \n"[i==n-1];
        }
    }
    else cout << -1 << endl;
    return 0;
}


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

void Bubble(char a[37][3], int n);
void Selection(char a[37][3], int n);
void Trace(char a[37][3], int n);

char card[37][3];

int main(void){
	int n;
	char t1[37][3];
	char t2[37][3];

	cin >> n;
	for(int i=0; i<n; i++){
		scanf("%s", card[i]);
		strcpy(t1[i], card[i]);
		strcpy(t2[i], card[i]);
	}

	Bubble(t1, n);
	Selection(t2, n);
	Trace(t1, n);
	Trace(t2, n);

	return 0;
}

void Bubble(char a[37][3], int n){
	for(int i=0; i<n; i++){
		for(int j=n-1; j>i; j--){
			if(a[j][1] < a[j-1][1]){
				char temp[3];
				strcpy(temp, a[j]);
				strcpy(a[j], a[j-1]);
				strcpy(a[j-1], temp);
			}
		}
	}
}

void Selection(char a[37][3], int n){
	for(int i=0; i<n; i++){
		int mini = i;
		for(int j=i; j<n; j++){
			if(a[j][1] < a[mini][1]){
				mini = j;
			}
		}
		char temp[3];
		strcpy(temp, a[mini]);
		strcpy(a[mini], a[i]);
		strcpy(a[i], temp);
	}
}

void Trace(char a[37][3], int n){
	int before = -1;
	int before_id = -1;
	int f = true;
	for(int i=0; i<n; i++){
		if(before == a[i][1] - '0'){
			for(int j=0; j<n; j++){
				if(strcmp(card[j], a[i]) == 0){
					if(j < before_id) f = false;
				}
			}
			//printf("%d\n", before_id);
		}
		if(i!=n-1) printf("%s ", a[i]);
		else printf("%s\n", a[i]);

		before = a[i][1] - '0';
		for(int j=0; j<n; j++){
			if(strcmp(card[j], a[i]) == 0){
				before_id = j;
			}
		}

	}
	if(f) printf("Stable\n");
	else printf("Not stable\n");
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n; cin >> n;
  map<int, int, greater<int>> cnt;
  for (int i = 0; i < n; i++) {
    int a; cin >> a;
    (cnt.find(a) != cnt.end()) ? cnt[a]++ : cnt[a] = 1;
  }
  long long y = 0, x = 0;
  for (auto &lc : cnt) {
    auto l = lc.first;
    auto c = lc.second / 2;
    if (!y && c) {y = l; c--;}
    if (!x && c) {x = l; break;}
  }
  cout << y * x << '\n';
  return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

int main(){
	ll N;
	cin >> N;
	REP(i, 100){
		REP(j, 100){
			if(4*i+7*j==N){
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define dofloat cout<<fixed<<setprecision(8)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bitcount __builtin_popcount
#define all(vec) vec.begin(),vec.end()
#define rall(vec) vec.rbegin(),vec.rend()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<long long> vl;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long> > vll;
typedef vector<pair<int,int> > vii;
typedef vector<int> vi;
typedef pair<int,int> ii;
const long long MOD=1000000007;
const long long MAX=100005;
const long double PI=3.14159265359;
const long double G=9.807;
const long long INF=1e18;
const long double EPS=1e-6;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
bool isprime(ll a){
  if(a==2)return 1;
  if(!(a&1))return 0;
  for(ll i=3;i*i<=a;i+=2)
    if(a%i==0)return 0;
  return 1;
}
ll mpow(ll base,ll exponent,ll modulus){
  if(modulus==1)return 0;
  long long result = 1;
  base=base%modulus;
  while(exponent){
    if(exponent%2 == 1)
	  result=(result*base)%modulus;
	  exponent=exponent>>1;
	  base=(base*base)%modulus;
  }
  return result;
}
ll minv(ll a,ll mod){
  ll _gcd=gcd(a,mod);
  assert(_gcd==1);
  return mpow(a,mod-2,mod);
}


/*
ll ncr(ll N,ll K){
	if(N<K)return 0;
	if(K==0)return 1;
	if(N==0)return 0;

	ll den=1;
	for(ll i=1;i<=K;i++)den*=i;
	ll num=1;
	while(K--){
		num*=N;
		if(num%den==0){
			num/=den;
			den=1;
		}
		N--;
	}

	return num;
}
*/
ll n;
ll a[2*MAX],b[2*MAX];
ll ans = 0;
int main(){FAST;
cin>>n;
for(ll i=1;i<=n;i++){
	cin>>a[i];
}
for(ll i=1;i<=n;i++){
	cin>>b[i];
}
for(ll i=1;i<=n;i++){
	if(b[i]<a[i]){
		cout<<-1;
		return 0;
	}
}
vl unfinished;
queue<ll>chains;
for(ll i=1;i<=n;i++){
	if(b[i]!=a[i]){
		unfinished.pb(i);
		ll A = (i-1 == 0)?n:i-1;
		ll B = (i+1 == n+1)?1:i+1;	
		if(b[i]>b[A] and b[i]>b[B]){
			chains.push(i);
		}
	}
}
while(!chains.empty()){
	ll f = chains.front();chains.pop();
	if(b[f] == a[f])continue;
	ll A = (f-1 == 0)?n:f-1;
	ll B = (f+1 == n+1)?1:f+1;
	if(b[f]>b[A] and b[f]>b[B]){
		ll add = b[A]+b[B];
		if(add>b[f]){
			cout<<-1;
			return 0;
		}
		ll x;
		if(a[A] == b[A] and a[B] == b[B]){
			if((b[f]-a[f])%add){
				cout<<-1;
				return 0;
			}
			ans+=(b[f]-a[f])/add;
			b[f] = a[f];
		}
		else{
			x = (b[f]-max(b[A],b[B])+add-1)/add;
			ans+=x;
			b[f]-=add*x;
		}
	}
	ll AA = (A-1 == 0)?n:A-1;
	ll BB = (B+1 == n+1)?1:B+1;
	if(b[AA]<b[A] and b[f]<b[A]){
		chains.push(A);
	}
	if(b[BB]<b[B] and b[f]<b[B]){
		chains.push(B);
	}
}
for(ll i=1;i<=n;i++){
	if(a[i]!=b[i]){
		cout<<-1;
		return 0;
	}
}
cout<<ans;
return 0;
}

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

#define PI 3.14159265358979323846264338327950288419

using namespace std;

int len;
char str[29];
bool app[128];

int main(){
	scanf("%s", str);
	len = strlen(str);
	if(len == 26){
		for(int i = 25; i > 0; i--){
			if(str[i - 1] < str[i]){
				// choose next largest for str[i - 1]
				// sort the rest
				int select = -1;
				for(int j = i; j < 26; j++){
					if(str[j] > str[i - 1]){
						if(select == -1 || str[j] < str[select]){
							select = j;
						}
					}
				}
				swap(str[i - 1], str[select]);
				str[i] = 0;
				puts(str);
				return 0;
			}
		}
		printf("-1\n");
	}
	else{
		for(int i = 0; i < len; i++){
			app[str[i]] = true;
		}
		for(int i = 'a'; i <= 'z'; i++){
			if(!app[i]){
				printf("%s%c\n", str, i);
				return 0;
			}
		}
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<boost/multiprecision/cpp_int.hpp>
using namespace std;
using namespace boost::multiprecision;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define rep(I,N) for(auto I=0;I<(N);++I)
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define pt pop_front
#define pk pop_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
// #define int cpp_int
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T>inline void                                      in(T &p){cin>>p;}
template<class T1,class T2>inline void                            in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void                   in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void          in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T1,class T2,class T3,class T4,class T5>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4,T5 &p5){cin>>p1>>p2>>p3>>p4>>p5;}
template<class T>inline void                             out(T p){cout<<p<<endl;}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<endl;}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<endl;}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<endl;}
inline                                              void out(double p){printf("%.10f\n",p);}
long dp[1<<17],mod=(long)1e9+7;
inline void solve(void){
  long N,M;
  in(N,M);
  long a;
  dp[0]=dp[1]=1;
  rep(i,M){
    in(a);
    dp[a]=-1;
  }
  up(i,2,N){
    if(dp[i]==-1)continue;
    if(dp[i-1]!=-1)dp[i]+=dp[i-1],dp[i]%=mod;
    if(dp[i-2]!=-1)dp[i]+=dp[i-2],dp[i]%=mod;
  }
  out(dp[N]);
}
int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 1024
n,m=map(int,input().split())
AB=[]
for i in range(n):
  a,b=map(int,input().split())
  AB.append([a,b])
AB=sorted(AB)
i=0
amount=0
cost=0
while True:
  if amount+AB[i][1]<m:
    amount+=AB[i][1]
    cost+=AB[i][0]*AB[i][1]
    i+=1
  else:
    cost+=(m-amount)*AB[i][0]
    print(cost)
    break

Measured memory_bytes: 22864
#include <bits/stdc++.h>
using namespace std;
int main(void) {
    int a=1,N,K;
    cin>>N>>K;
    for (int i=0;i<N;i++) {
        if (a>=K) {
            a=a+K;
        } else {
            a=a*2;
        }
    }
    cout<<a<<endl;
}


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

lld prod(lld val)
{
    if(val % 10 >= 2 && (val / 10) >= 2)
        return (val % 10) * (val / 10);
    return -1;
}

int main()
{
    std::ios::sync_with_stdio(false);
    lld t = 1;
    //cin >> t;
    while(t--) {
        lld m, d;
        cin >> m >> d;

        lld ans = 0;
        for(lld j = 1; j <= m; j++) {
            for(lld i = 22; i <= d; i++) {
                if(prod(i) == j) {
                    ans++;
                }
            }
        }
        cout << ans << "\n";
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm> // sort
#include <map> // pair
 
using namespace std;
 
int main(){
    int64_t N,Q;
 
    cin >> N;
    int64_t countnum[100002]={};
    int64_t sum=0;
 
    for(int i=0;i<100002;++i){
        countnum[i]=0;
    }
	  
  
    for(int64_t i=0;i<N;i++){
        int64_t temp;
        cin >> temp;
        sum+=temp;
        countnum[temp]+=1;
    }
 
    cin >> Q;
 
    int64_t Bi[100001];
    int64_t Ci[100001];
    for(int64_t i=0;i<Q;i++){
        cin >> Bi[i]>>Ci[i];
    }
 
 
    for(int64_t i=0;i<Q;++i){
        sum -= Bi[i] *countnum[Bi[i]];
        sum += Ci[i] *countnum[Bi[i]];
 
        cout<<sum <<endl;
        countnum[Ci[i]] +=countnum[Bi[i]];
        countnum[Bi[i]] =0;
 
    }
 
 
}

Measured memory_bytes: 5832
#include <iostream>

#include <vector>

#include <cstring>



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



using namespace std;



typedef vector<int> vi;



int va[12];

int vb[12];



int dp[12][12][2];



int solve(int i, int k, int borrow){

  if(i == 12) return 0;

  int& d = dp[i][k][borrow];

  if(d != -1) return d;



  int x = va[i] - borrow - vb[i];

  if(x >= 0) return 10 * solve(i+1, k, 0) + x;

  int ans = 10 * solve(i+1, k, 1) + x + 10;

  if(k != 0) ans = max(ans, 10 * solve(i+1, k-1, 0) + x + 10);

  return d = ans;

}



int main(){

  int a,b,k;

  cin >> a >> b >> k;



  rep(i, 12){

    va[i] = a % 10; a /= 10;

    vb[i] = b % 10; b /= 10;

  }

  

  memset(dp, -1, sizeof(dp));

  

  cout << solve(0, k, 0) << endl;

  

  return 0;

}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define SZ(x) ((int)(x).size())
#define rep(i,n) for(int i=0;i<(n);++i)
#define fore(i,a) for(auto &i:a)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define ALL(x) (x).begin(),(x).end()
signed _main(); signed main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> using v = vector<T>;
template<class T> using vv = vector<v<T>>;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
using P=pair<int,int>;
/*素数判定*/int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}

signed _main(){
  int N,M,X; cin >> N >> M >> X;
  vv<int> A(N,v<int>(M));
  v<int> C(N);
  rep(i,N){
    cin >> C[i];
    rep(j,M){
      cin >> A[i][j];
    }
  }
  int ans=INF;
  for (int bit = 0; bit < (1 << N); ++bit) {
    int sum = 0;
    v<int> skill(M,0);
    for (int i = 0; i < N; ++i) {
      if (bit & (1 << i)){
        sum+=C[i];
        rep(j,M){
          skill[j]+=A[i][j];
        }
      }
    }
    int cnt=0;
    rep(j,M){
      if(skill[j]>=X) cnt++;
    }
    if(cnt==M) chmin(ans,sum);
  }
  if(ans>=INF/2) cout << -1 << endl;
  else cout << ans << endl;
  return 0;
}


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

#define maxn 5005
#define N 100000
#define inf (int) 2e9
#define ll long long
#define ii pair <int, int>
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define REP(i, a, b) for(int i = a; i >= b; i--)

char s[maxn], t[maxn];
char res[maxn];
int f[maxn][maxn], slx = 0;

int main() {
    //freopen("main.inp", "r", stdin);
    cin >> s + 1 >> t + 1;
    int n = strlen(s + 1), m = strlen(t + 1);
    FOR(i, 1, n)
       FOR(j, 1, m) {
           f[i][j] = max(f[i - 1][j], f[i][j - 1]);
           if(s[i] == t[j])
               f[i][j] = max(f[i][j], f[i - 1][j - 1] + 1);
       }
    int ans = 0, u = 0, v = 0;
    FOR(i, 1, n)
       FOR(j, 1, m)
          if(f[i][j] == f[n][m]) {
              u = i, v = j;
              goto L1;
          }
    L1:;
    while(u > 0 && v > 0) {
        if(f[u][v] == f[u - 1][v]) u--;
        else if(f[u][v] == f[u][v - 1]) v--;
        else {
            res[++slx] = s[u];
            u--, v--;
        }
    }
    REP(i, slx, 1) cout << res[i];
}


Measured memory_bytes: 50652
#include<bits/stdc++.h>
#define pb push_back
#define sz(v) (v).size()
#define all(v) (v).begin(),(v).end()
#define inf 1000000007
#define mod inf
using namespace std;
template <typename T> void chmax(T &x,T y){x=x>y?x:y;return;}
template <typename T> void chmin(T &x,T y){x=x<y?x:y;return;}
typedef long long ll;
typedef unsigned long long ull;

int n;
char c[4005];
ll r,g,b,ans;

int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>c[i];
		if(c[i]=='R') r++;
		if(c[i]=='G') g++;
		if(c[i]=='B') b++;
	}
	ans=r*g*b;
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
			if(c[i]!=c[j])
			{
				int k=j+j-i;
				if(k>n) continue;
				if(c[i]!=c[k]&&c[j]!=c[k])
					ans--;
			}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3588
import math

line = input().split()
a = int(line[0])
b = int(line[1])
x = int(line[2])

if x >= a**2 * b / 2:
    theta = math.degrees(math.atan(2 * b / a - 2 * x / a**3))
else:
    theta = math.degrees(math.atan(a * b**2 / x / 2))

print(theta)

Measured memory_bytes: 3060
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif

#define int long long
#define FILE_IO freopen("input.txt","r",stdin)/#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define bp __builtin_popcount
#define debug(x) cerr << #x << " = " << x << endl;

const int MOD = 1e9 + 7;
const int INF = 1000000000;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>void print(T t){for(auto &it : t)cout<<it<<" ";}
inline int powerexp(int a, int b, int m = MOD){ int res = 1;while(b){if(b&1)res = res * a % m;a = a * a % m,b >>= 1;}return res % m;}
inline int modinv(int a){ return powerexp(a,MOD-2,MOD);}
inline int lcm(int a, int b){ int g = __gcd(a,b);return a/g*b;}
inline int add(int x, int y){ x += y; if (x >= MOD) x -=  MOD; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % MOD;}
inline int sub(int x, int y){ x -= y; if (x<0) x += MOD; return x ;}

//-------------------< start here >-------------------------// 

const int N = 1e5 + 11;
int p[N], sz[N];

int get(int x){
  if (p[x] == x) return x;
  return p[x] = get(p[x]);	
}

void unite(int x, int y){
  x = get(x), y = get(y);
  if (x == y) return;
  if (sz[x] < sz[y]) swap(x, y);
  sz[x] += sz[y];
  p[y] = x;	
}

void solve(){
  int n, m;
  cin >> n >> m;
  for(int i = 0; i < n; i++){
	  p[i] = i;
	  sz[i] = 0;  
	}	
  int a[n];
  for(int i = 0; i < n; i++) {cin >> a[i]; a[i]--;}
  for(int i = 0; i < m; i++){
	  int x, y;
	  cin >> x >> y;
	  x--, y--;
	  unite(x, y);  
	}
  int ret = 0;
  for(int i = 0; i < n; i++){
	  if (get(a[i]) == get(i)) ret++;  
	}
  cout << ret << endl;
}

//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
   IOS;
   solve();
   //find();
   #ifdef LOCAL_DEFINE
   cerr << "time elapsed " << (double)clock()/CLOCKS_PER_SEC << endl;
   #endif
}


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

ll gcd(ll a, ll b) { return (b?gcd(b, a%b):a); }

const int M = 1000000007;
ll mul(ll a, ll b) { return (a*b)%M; }
ll mod_pow(ll a, ll b) {
  ll r = 1;
  while (b) {
    if (b&1) r = mul(r, a);
    b >>= 1;
    a = mul(a, a);
  }
  return r;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int n, zero = 0;
  cin >> n;
  map<pair<ll, ll>, P> mp;
  rep(i, n) {
    ll x, y;
    cin >> x >> y;
    if (x == 0 && y == 0) {
      ++zero;
      continue;
    }
    ll g = gcd(x, y);
    x /= g;
    y /= g;
    if (y < 0) { x = -x, y = -y; }
    if (x == 0) y = 1;
    if (y == 0) x = 1;
    if (x > 0) mp[{x, y}].first++;
    else mp[{y, -x}].second++;
  }
  ll ans = 1;
  for (auto k : mp) {
    ll now1 = mod_pow(2, k.second.first);
    ll now2 = mod_pow(2, k.second.second);
    ans = mul(ans, (now1+now2-1+M)%M);
  }
  ans += zero-1;
  ans = (ans+M)%M;
  cout << ans << endl;
}

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

using ll = long long;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	ll k;
	cin >> n >> k;
	vector<ll> a(n), b(n);
	for(int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for(int i = 0; i < n; i++) {
		cin >> b[i];
	}
	
	sort(a.rbegin(), a.rend());
	sort(b.begin(), b.end());
	vector<pair<ll, ll>> arr(n);
	for(int i = 0; i < n; i++) {
		arr[i] = make_pair(a[i] * b[i], b[i]);
	}
	
	ll lo = 0, hi = 1e12;
	
	auto can = [&](ll x) {
		ll tmp = k;
		for(int i = 0; i < n; i++) {
			if(arr[i].first <= x) continue;
			ll take = arr[i].second;
			ll ops = (arr[i].first - x + take - 1) / take;
			
			if(ops > tmp) {
				return false;
			} else {
				tmp -= ops;
			}
		}
		
		return true;
	};
	
	while(lo < hi) {
		ll mid = lo + (hi - lo)/2;
		
		if(can(mid)) {
			hi = mid;
		} else {
			lo = mid + 1;
		}
	}
	
	cout << hi << endl;
}


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

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

// 最小公倍数
ll lcm(ll a, ll b){
    return a/gcd(a, b) * b;
}

int main()
{
    cout << fixed << setprecision(15);
    ll N; 
    string S;
    cin >> N;
    cin >> S;

    vector<ll> white(N, 0);
    vector<ll> black(N, 0);

    ll whitetotal = 0;
    ll blacktotal = 0;

    REP(i, N){
        if(i != 0){
            white[i] = white[i-1];
            black[i] = black[i-1];
        }
        if(S[i] == '.'){
            white[i]++;
            whitetotal++;
        }
        else{
            black[i]++;
            blacktotal++;
        }
    }

    ll ans = LINF;
    REP(i, N-1){
        ans = min(ans, black[i] + (whitetotal - white[i]));
    }

    ans = min(ans, blacktotal);
    ans = min(ans, whitetotal);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6800
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    n = ni()
    a = na()

    whole = sum(a)

    if n == 0 and a[0] == 0:
        print(-1)
        exit(0)

    ans = 0
    base = 1
    for i in range(n + 1):
        ans += base
        base -= a[i]
        whole -= a[i]
        base = min(base * 2, whole)
        if (base <= 0 and i != n) or (i == n and base != 0):
            print(-1)
            exit(0)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 21788
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>

#define pb push_back
#define mp make_pair
#define taskname "A"

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef tree <int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

const int maxn = 3e3 + 5;
const int mod = 1e9 + 7;
const int div2 = (mod + 1) / 2;

int n , m , a[maxn];
int dp[maxn][maxn];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname".INP","r")){
		freopen(taskname".INP", "r",stdin);
		freopen(taskname".OUT", "w",stdout);
    }
    cin >> n >> m;
    for(int i = 1 ; i <= n ; ++i)cin >> a[i];
    for(int i = 1 ; i <= n ; ++i){
        for(int j = 1 ; j <= n ; ++j){
            dp[i][j] = (a[i] > a[j]);
        }
    }
    int p = 1;
    while(m--){
        p = p * 2 % mod;
        int i , j;cin >> i >> j;
        dp[i][j] = dp[j][i] = (ll)(dp[i][j] + dp[j][i]) * div2 % mod;
        for(int t = 1 ; t <= n ; ++t){
            if(i == t || j == t)continue;
            dp[i][t] = dp[j][t] = (ll)(dp[i][t] + dp[j][t]) * div2 % mod;
            dp[t][i] = dp[t][j] = (ll)(dp[t][i] + dp[t][j]) * div2 % mod;
        }
    }
    int res = 0;
    for(int i = 1 ; i <= n ; ++i){
        for(int j = i ; j <= n ; ++j){
            res += dp[i][j];
            if(res>=mod)res -= mod;
        }
    }
    cout << (ll)res * p % mod;
}


Measured memory_bytes: 35584
#include <bits/stdc++.h>
using namespace std;
#define mp(a,b) make_pair(a,b)
#define ff first
#define setp(a) setprecision(a)<<fixed
#define ss second
#define fori(v) for(ll i=0; i<v; i++)
#define forj(v) for(ll j=0; j<v; j++)
#define fork(v) for(ll k=0; k<v; k++)
#define forl(v) for(ll l=0; l<v; l++)
#define fort(v) for(ll t=0; t<v; t++)
#define forz(v) for(ll z=0; z<v; z++)
#define forx(v) for(ll x=0; x<v; x++)
#define fory(v) for(ll y=0; y<v; y++)
#define ll long long
#define pb(a) push_back(a)
typedef long double ld;
typedef complex<ld> pt;
typedef vector<pt> pol;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<ld> vd;
typedef vector<vd> vvd;
typedef pair<ll, ll> pii;
typedef vector<pii> vpii;
const ll INF = 0x3f3f3f3f;
const ll inf =  pow(10,18);
ll modulo = pow(10,9) + 7;
#define MAX (int)(2*pow(10,5) + 10)

ll pow_mod(ll a, ll b){
	a = a%modulo;
	ll has = 1;
	for(ll i = 62; i>-1; i--){
		has*=has;
		has%=modulo;
		if(((ll)1<<i)&b)
			has*=a, has%=modulo;
	}
	return has;
}

ll inv(ll a){
	return pow_mod(a, modulo-2);
}


ll fkt[MAX];
ll inv_fkt[MAX];

void pre(){
	fkt[0] = 1;
	inv_fkt[0] = 1;
	for(ll i = 1; i<MAX; i++){
		fkt[i] = fkt[i-1] * i;
		fkt[i] %= modulo;
		inv_fkt[i] = inv(fkt[i]);
	}
}

ll kmb(ll i, ll j){
	return fkt[i]*inv_fkt[j]%modulo*inv_fkt[i-j]%modulo;
}

vector<ll> active(set<ll> all){
	return vector<ll>(all.begin(), all.end());
}

void deal(){
	pre();
	ll h ,w , badcount;
	cin>>h>>w>>badcount;
	vector<pair<ll,ll> > bad;
	vector<ll> save;
	fori(badcount){
		ll x,y;
		cin>>x>>y;
		bad.pb(mp(x,y));
	}
	sort(bad.begin(), bad.end());
	ll ans = kmb(h-1+w-1, h-1);
	fori(bad.size()){
		ll x = bad[i].ff, y = bad[i].ss;
		ll cur = kmb(x-1+y-1, x-1);
		forj(i){
			ll x1 = bad[j].ff, y1 = bad[j].ss;
			if(x1 <= x && y1 <= y){
				ll minus = save[j] * kmb(x-x1+y-y1, x-x1);
				minus %= modulo;
				cur -= minus;
				cur += modulo;
				cur %= modulo;
			}
		}
		save.pb(cur);
		ll mult = kmb(h-x+w-y, h-x);
		mult *= cur;
		mult %= modulo;
		ans-=mult;
		ans+=modulo;
		ans%=modulo;
	}
	cout<<ans;
}

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	deal();
}    

















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

int main()
{
int n,an=INT_MAX,s;cin>>n;
int a[n];
for(int i=0;i<n;i++)cin>>a[i];
for(int k=-100;k<=100;k++)
{s=0;
	for(int i=0;i<n;i++)
	s+=(a[i]-k)*(a[i]-k);
	an=min(an,s);
}
cout<<an<<endl;


}



Measured memory_bytes: 3580
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		boolean flag = true;
		int x1 = 0, y1 = 0, time = 0;	
		for(int i = 0; i < n; i++) {
			int t = sc.nextInt();
			int sa = t - time;
			int x2 = sc.nextInt();
			int y2 = sc.nextInt();
			int dist = Math.abs(x1 - x2) + Math.abs(y1 - y2);
			if (dist > sa || sa % 2 != dist % 2) {
				flag = false;
				break;
			}
			x1 = x2;
			y1 = y2;
			time = t;
		}
		System.out.println(flag ? "Yes" : "No");
	}
}

Measured memory_bytes: 84968
#pragma region header
#include <bits/stdc++.h>
#define int long long
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr int inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */
#pragma endregion
signed main() {
    int n;cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];
    sort(all(a));
    /*vi rui(n+1);
    rui[0] = 0;
    rep(i, n) {
        rui[i+1] = a[i]+rui[i];
    }
    for(auto p:rui)cout << p << ' ';
    cout << endl;*/
    int count = 0;
    /*for(int i = 3;i<=n;i++) {
        if(rui[i]-rui[i-1]<rui[i-1]-rui[i-3]) count++;
    }*/
    /*for(int i = 3;i<=n;i++) {
        for(int j = 2;j<=i-1;j++) {
            if(rui[i]-rui[i-1]<rui[j]-rui[j-2]) {
                count++;
                cout << rui[i]-rui[i-1] << ' ' << rui[j]-rui[j-1] << ' ' << rui[j-1]-rui[j-2] << endl;
            }
        }
    }*/
    for(int i = 2;i<n;i++) {
        for(int j = 1;j<i;j++) {
            for(int l = 0;l<j;l++) {
                if(a[l]+a[j]>a[i]) count++;
            }
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3628
S = input()
N = len(S)

dp = [0 for _ in range(N)]

dp[0] = 1
dp[1] = 2 if S[0] != S[1] else 1

for i in range(2, N):
    if S[i] != S[i - 1]:
        dp[i] += dp[i - 1] + 1
    else:
        dp[i] += dp[i - 3] + 2

print(dp[-1])


Measured memory_bytes: 11368
#include <iostream>
#include <string>
using namespace std;
int main(){
    int i,j,n,cnt=0;
    string s,u;
    cin >> n >> s;
    for(i=0;i<n;i++){
        u = "";
        for(j=i;j<i+3;j++){
            u+=s[j];
        }
        if(u=="ABC"){
            cnt++;
        }
    }
    cout << cnt;
}

Measured memory_bytes: 384
fun main(args: Array<String>) {
    val (N, K, Q) = listOfInt()
    val A = Array<Int>(Q) { nextInt(-1) }
    val W = Array<Int>(N) { K - Q }
    A.forEach { W[it] += 1 }
    W.forEach { println(if (it > 0) "Yes" else "No") }
}
fun next() = readLine()!!
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta
fun listOfString() = next().split(" ")
fun listOfInt(delta: Int = 0) = listOfString().map { Integer.parseInt(it) + delta }


Measured memory_bytes: 48428
# Q1
n = int(input())
a = list(map(int, input().split()))

a.append(999)
magic = 0
series = 1
prev=0
for x in a:
#     print('prev:{} current:{}'.format(prev,x))
    if prev>0:
        if prev==x:
            series+=1
#             print('series:',series)
        else:
            magic+=int(series/2)
            series=1
#             print('magic:',magic)
    prev=x
print(magic)

Measured memory_bytes: 3060
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

int main()
{
	long int x, y;

	std::cin >> x >> y;

	int length = 1;

	while (true)
	{
		x *= 2;
		if (x <= y)length += 1;
		else break;
	}

	std::cout << length;

    return 0;
}

Measured memory_bytes: 256
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
  Name:- OMHARI 
  Institution:- UNIVERSIT OF CALCUTTA(INFORMATION TECHNOLOGY)
  Email:- omharicu@gmail.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
#include<bits/stdc++.h>
using namespace std; 

#define ull unsigned long long
#define ll long long
#define ul unsigned long
#define db double
#define pb push_back
#define mp make_pair
#define el "\n"
#define vll vector <ll>
#define vi vector <int>
#define all(v) (v.begin(), v.end()) 
#define rall(v) (v.rbegin(), v.rend()) 
const ll mod = 1e9+7;

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
     #endif
    /***************-Code starts from here-***************/
    ll n,sum=0,q;
    cin>>n;
    vll v(n),ans(100001,0);
    for(ll i=0; i<n; i++)
    {
        cin>>v[i];
        ans[v[i]]++;
        sum+=v[i];
    }
    cin>>q;
    vector< pair<ll, ll>> qu(q);
    
    for(ll i=0; i<q; i++)
    {
        ll x,y;
        cin>>x>>y;
        qu[i]=mp(x,y);
    }
    
    for(ll i=0; i<q; i++)
    {
        ll temp=ans[qu[i].first];
        ans[qu[i].first]=0;
        ans[qu[i].second]+=temp;
        sum=sum+temp*qu[i].second-temp*qu[i].first;
        cout<<sum<<el;
    }
    return 0; 
} 


Measured memory_bytes: 6360
h,n = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n)]
inf = 10000000000
dp = [inf for _ in range(h+1)]
dp[0] = 0
for i in range(1,h+1):
    m = inf
    for a,b in ab:
        if i <= a:
            m = min(m,b)
        else:
            m = min(m,dp[i-a]+b)
    dp[i] = m
print(dp[-1])

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

int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  
  for (int i = 0; A > 0 && C > 0; i++) {
    C -= B;
    A -= D;
  }
  if (C <= 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define forn(i, n)             for(int i = 0; i < n; i ++)
#define forn1(i, n)            for(int i = 1; i <= n; i ++)
#define loop(i, sta, end, inc) for(int i = sta; i <= end; i += inc)
#define itr(it, l)             for(auto it = l.begin(); it != l.end(); it ++)
#define in(a, b, c)            assert( b <= a && a <= c)
#define pb push_back
#define ll long long int
#define fi first
#define se second
#define ii  pair<long long int, long long int>
#define vi  vector <long long int>
#define vii vector <pair <long long int, long long int > >
#define all(cont)  cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define what_is(x) cerr<<#x<<" ="<<x<<" ";
#define error(args...)  { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define LINT_MAX  9223372036854775807
#define LINT_MIN -9223372036854775808
#define EPS 1e-9
#define MOD 1000000007
#define mod 998244353
#define DEBUG 1
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define range 200010
#ifndef LOCAL
#pragma GCC optimize ("Ofast")
#define endl '\n'
#endif

template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
void err(istream_iterator<string> it) { cerr<<endl;}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    if(DEBUG == 0)return;
	cerr << *it << " = " << a <<" ";
	err(++it, args...);
}


int main(){

	//freopen("test.txt","r",stdin);
	ios :: sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	int k,x;
	cin>>k>>x;
	for(int i=x-k+1;i<=x+k-1;i++)cout<<i<<" ";cout<<endl;

	
	
    return 0;
}


Measured memory_bytes: 256
N, M, K = map(int, input().split())
chess = [input() for i in range(N)]
ans = [[0 for i in range(M)] for j in range(N)]
index = 0


def ok(r, h, t):
    for i in range(h, t+1):
        if ans[r][i] or chess[r][i] == '#':
            return False
    return True


def color(r, h, t):
    for i in range(h, t+1):
        ans[r][i] = index


# mother fucker
for i in range(N):
    j = 0
    while j < M:
        if chess[i][j] == '.':
            j += 1
            continue
        index += 1
        l = j - 1
        while l >= 0 and chess[i][l] == '.' and ans[i][l] == 0:
            l -= 1
        l += 1
        r = j + 1
        while r < M and chess[i][r] == '.' and ans[i][r] == 0:
            r += 1
        r -= 1
        # [l,r]
        # color
        color(i, l, r)
        for k in range(i-1, -1, -1):
            if ok(k, l, r):
                color(k, l, r)
            else:
                break
        for k in range(i+1, N):
            if ok(k, l, r):
                color(k, l, r)
            else:
                break
        j = r + 1

for i in range(N):
    for j in range(M-1):
        print(ans[i][j], end='')
        print(' ', end='')
    print(ans[i][M-1], end='')
    print("")


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

int main() {
  int N;
  string S;
  cin >>N >>S;
  for(int i=0;i<S.size();i++){
    
    for(int j=0;j<N;j++){
      char X = S.at(i);
      if(X=='A'){
        S.at(i)='B';
      }
      else if(X=='B'){
        S.at(i)='C';
      }
      else if(X=='C'){
        S.at(i)='D';
      }
      else if(X=='D'){
        S.at(i)='E';
      }
      else if(X=='E'){
        S.at(i)='F';
      }
      else if(X=='F'){
        S.at(i)='G';
      }
      else if(X=='G'){
        S.at(i)='H';
      }
      else if(X=='H'){
        S.at(i)='I';
      }
      else if(X=='I'){
        S.at(i)='J';
      }
      else if(X=='J'){
        S.at(i)='K';
      }
      else if(X=='K'){
        S.at(i)='L';
      }
      else if(X=='L'){
        S.at(i)='M';
      }
      else if(X=='M'){
        S.at(i)='N';
      }
      else if(X=='N'){
        S.at(i)='O';
      }
      else if(X=='O'){
        S.at(i)='P';
      }
      else if(X=='P'){
        S.at(i)='Q';
      }
      else if(X=='Q'){
        S.at(i)='R';
      }
      else if(X=='R'){
        S.at(i)='S';
      }
      else if(X=='S'){
        S.at(i)='T';
      }
      else if(X=='T'){
        S.at(i)='U';
      }
      else if(X=='U'){
        S.at(i)='V';
      }
      else if(X=='V'){
        S.at(i)='W';
      }
      else if(X=='W'){
        S.at(i)='X';
      }
      else if(X=='X'){
        S.at(i)='Y';
      }
      else if(X=='Y'){
        S.at(i)='Z';
      }
      else{
        S.at(i)='A';
      }
      
    }
  }
  cout << S ;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
flag=list(range(n+1))
flagnum=[0]*(n+1)

#以下でフラグ建設 フラグが同じなら同じチームである
def takeflag(p):
    stock=[]
    while flag[flag[p]]!=flag[p]:
        stock.append(p)
        p=flag[p]
    p=flag[p]
    for i in stock:
        flag[i]=p
    return p
for i in range(m):
    a,b = map(int,input().split())
    a,b = map(takeflag,(a,b))
    a,b = min(a,b),max(a,b)
    flag[a]=b
for i in range(n+1):
    flag[i]=takeflag(i)
    flagnum[flag[i]]+=1 #チームの人数を知りたいときこの行を使う
print(max(flagnum))

Measured memory_bytes: 19888
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S chmax(S &a, T b){
  if(a<b){
    a=b;
  }
  return a;
}
int X;
int main(){
  int i, j, res;
  rd(X);
  res = 1;
  for(i=2;i*i<=X;i++){
    j = i * i;
    for(;;){
      chmax(res, j);
      j *= i;
      if(j > X){
        break;
      }
    }
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190721-1

// --- original code ---
// int X;
// {
//   int i, j, res;
// 
//   rd(X);
// 
//   res = 1;
//   for(i=2;i*i<=X;i++){
//     j = i * i;
//     for(;;){
//       res >?= j;
//       j *= i;
//       if(j > X) break;
//     }
//   }
// 
//   wt(res);
// }


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

int g_bm = 1000000007;

int modl(_LL a)
{
    a %= g_bm;
    if( a < 0 ) a += g_bm * ( 1 - (a + 1) / g_bm );
    return a;
}

int modadd(_LL a, _LL b)
{
    return modl(a + b);
}

int modminus(_LL a, _LL b)
{
    return modl(a - b);
}

int modmul(_LL a, _LL b)
{
    return modl(a * b);    
}

int modpow(_LL a, _LL b)
{
    int prebit = modl(a);
    int ans = 1;
    for( int bit = 0; (long unsigned int) b >= (1UL << bit); bit++ )
    {
        if( bit > 0 ) prebit = modmul(prebit, prebit);
        if( b & (1UL << bit) ) ans = modmul(ans, prebit);
    }
    return ans;
}

int modcalcsub(_LL a, _LL b, char c)
{
    switch(c)
    {
        case '+':
            return modadd(a, b);
        case '-':
            return modminus(a, b);
        case '*':
            return modmul(a, b);
    }
    return 0;
}

int modsublevel(char c)
{
    switch(c)
    {
        case '+':
        case '-':
            return 0;
        case '*':
            return 1;
    }
    return 0;
}

int modinv(_LL a) 
{
    _LL b = g_bm, u = 1, v = 0;
    while (b) 
    {
        _LL t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    return modl(u);
}

int modcalc(_LL a1, char c1, _LL a2, char c2 = 0, _LL a3 = 0, char c3 = 0, _LL a4 = 0, char c4 = 0, _LL a5 = 0, char c5 = 0, _LL a6 = 0, char c6 = 0, _LL a7 = 0, char c7 = 0)
{
    char c[8] = {c1, c2, c3, c4, c5, c6, c7, '0'};
    _LL a[8] = {a1, a2, a3, a4, a5, a6, a7, 0};
    int ans[4];
    char prec[4];
    int level = 0;
    int index = 0;
    ans[0] = 0;
    prec[0] = '+';
    // 3 + 4 * 8 + 3
    while( prec[level] != '\0' )
    {
        int nlevel = modsublevel(c[index]);
        while( level < nlevel )
        {
            ans[level + 1] = 0;
            prec[level + 1] = '+';
            level++;
        }        
        ans[level] = modcalcsub( ans[level], a[index], prec[level]);
        while( nlevel < level )
        {
            ans[level - 1] = modcalcsub( ans[level - 1], ans[level], prec[level - 1]);
            level--;
        }
        prec[level] = c[index++];
    }
    return ans[0];
}

int getCombination(_LL n, _LL r)
{
    _LL ans;
    ans = 1;
    rep(i, r) ans = modmul(ans, n - i);
    _LL inv = 1;
    rep(i, r) inv = modmul(inv, i + 1);
    return modmul(ans, modinv(inv));
}

int main()
{
    _LL n, a, b;
    cin >> n >> a >> b;

    int ans = modcalc(modpow(2, n), '-', 1, '-', getCombination(n, a));
    if( a != b) ans = modminus(ans, getCombination(n, b));
    cout << ans;
}

Measured memory_bytes: 3592
read a b c
g=0
n=0
if [ $a -eq 5 ]
  then g=$((g+1))
  else if [ $a -eq 7 ]
    then n=$((n+1))
  fi
fi
if [ $b -eq 5 ]
  then g=$((g+1))
  else if [ $b -eq 7 ]
    then n=$((n+1))
  fi
fi
if [ $c -eq 5 ]
  then g=$((g+1))
  else if [ $c -eq 7 ]
    then n=$((n+1))
  fi
fi
if [ $g -eq 2 -a $n -eq 1 ]
  then echo YES
  else echo NO
fi

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

int main() {
	int n,m,i,j,k,ans=0,cur,res;
	string s;
	cin >> s;
	n=s.size();
	for(i=0; i<n/2; i++){
		if(s[i]!=s[n-1-i]){
			ans++;
		}
	}
	cout << ans;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC_A
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int n = int.Parse(input[0]);
            int m = int.Parse(input[1]);

            int[] a = new int[m];
            int[] b = new int[m];
            for (int i = 0; i < m; i++)
            {
                string[] line = Console.ReadLine().Split(' ');
                a[i] = int.Parse(line[0]);
                b[i] = int.Parse(line[1]);

            }

            city[] cities = new city[n];
            for (int i = 0; i < n; i++)
            {
                cities[i] = new city();

            }
            for (int i = 0; i < m; i++)
            {
                cities[a[i] - 1].add(b[i] - 1);
                cities[b[i] - 1].add(a[i] - 1);
            }

            foreach (var v in cities)
            {
                v.dispRoadNum();
            }
            return;
        }



        class city
        {
            List<int> connectedCityIndex;

            public city()
            {
                connectedCityIndex = new List<int>();

            }
            public void add(int b)
            {
                connectedCityIndex.Add(b);
                
            }
            public void dispRoadNum()
            {
                Console.WriteLine(connectedCityIndex.Count);
            }
           
        }
    }


}


Measured memory_bytes: 11220
//
// Created by 田代真生 on 2019-10-09.
//

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

long n, m;
long a, b;

bool search(vector<long> ls, long n, vector<vector<long>> _map){
    for(long i=0; i< n-1; i++){
        if(_map[ls[i]][ls[i+1]] == 0){
            return false;
        }
    }
    return true;
}
int main(){
    cin >> n >> m;
    bool res;
    long cnt = 0;
    vector<vector<long>> _map(n, vector<long>(n, 0));
    vector<long> list(n);
    for(int i=0; i<m; i++){
        cin >> a >> b;
        a--;
        b--;
        _map[a][b] = 1;
        _map[b][a] = 1;
    }
    for(int i=0; i<n; i++){
        list[i] = i;
    }
    do{
        res = search(list, n, _map);
        if(res){
            cnt++;
        }
    } while (
        next_permutation(list.begin()+1, list.end())
    );
    cout << cnt << endl;
}

Measured memory_bytes: 256