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

using namespace std;
int n,m,a,b,t,p,q,x,y;
char s[maxn][maxn];

int main()
{
    scanf("%d%d%d%d",&n,&m,&a,&b);
    for (int i=0;i<n;i++) for (int j=0;j<m;j++) s[i][j]='.';
    if (a+b>n*m/2||a>n*(m/2)||b>m*(n/2)) {printf("NO\n");return 0;}
    if (n&1){
        for (int i=m&1;i<m;i+=2)
        {
            if (!a) break;
            s[0][i]='<'; s[0][i+1]='>'; a--;
        }
    }
    if (m&1){
        for (int i=n&1;i<n;i+=2)
        {
            if (!b) break;
            s[i][0]='^'; s[i+1][0]='v'; b--;
        }
    }
    for (int i=n&1;i<n;i+=2)
        for (int j=m&1;j<m;j+=2){
            if (!a&&!b) break;
            if (a){
                if (a==1) x=i+1,y=j;
                if (a) s[i][j]='<',s[i][j+1]='>',a--;
                if (a) s[i+1][j]='<',s[i+1][j+1]='>',a--;
            }
            else if (b){
                if (b) s[i][j]='^',s[i+1][j]='v',b--;
                if (b) s[i][j+1]='^',s[i+1][j+1]='v',b--;
            }
        }
    if (b){
        if ((n&1)&&(m&1)){
            s[x][y]='<'; s[x][y+1]='>';
            s[0][0]='<'; s[0][1]='>'; s[1][1]='.'; s[0][2]='^'; s[1][2]='v';
        }
        else {printf("NO\n");return 0;}
    }
    printf("YES\n");
    for (int i=0;i<n;i++) printf("%s\n",s[i]);
    return 0;
}


Measured memory_bytes: 2176
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <chrono>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <sstream>
#include <queue>
#include <bitset>

using namespace std;
using ll = long long;
using triplet = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using pi = pair<int, ll>;
using vpi = vector<pi>;

int N;

map<pair<int, int>, ll> mem;

ll MaxValue(int W, int i, const vpi& w)
{
    if (i == N) return 0;
    auto it = mem.find(make_pair(W, i));
    if (it != mem.end()) return it->second;
    ll result = max(W >= w[i].first ? MaxValue(W-w[i].first, i+1, w) + w[i].second : 0ll, MaxValue(W, i+1, w));
    mem[make_pair(W, i)] = result;
    return result;
}

int main()
{
#ifdef LOCAL_TEST
    freopen("data.txt", "r", stdin);
#endif
    int W;
    scanf("%d %d\n",&N, &W);
    vpi w(N);
    for (int i = 0; i < N; ++i)
    {
        scanf("%d %lld\n", &w[i].first, &w[i].second);
    }
    
    printf("%lld\n", MaxValue(W, 0, w));
    return 0;
}


Measured memory_bytes: 6272
n=int(input())
b=list(map(int,input().split()))
ans=b[0]
a=0
for i in range(n-2):
    if b[i]>=b[i+1]:
        a=b[i+1]
    else:
        a=b[i]
    ans=ans+a
ans=ans+b[len(b)-1]
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <numeric>

using namespace std;

int calc_index(const vector<int>& ary)
{
    int idx = 1;
    
    vector<int> cp_ary(ary.size());
    iota(cp_ary.begin(), cp_ary.end(), 1);
    
    do{
        bool eq = true;
        for( int ii = 0; ii < ary.size(); ++ii ){
            if( ary[ii] != cp_ary[ii] ){
                eq = false;
                break;
            }
        }
        if( eq ){
            break;
        }
        ++idx;
    } while( next_permutation(cp_ary.begin(), cp_ary.end()) );
        
    return idx;
}

int main()
{
    int N;
    vector<int> P, Q;
    
    cin >> N;
    for( int ii = 0; ii < N; ++ii ){
        int p;
        cin >> p;
        P.push_back(p);
    }
    for( int ii = 0; ii < N; ++ii ){
        int q;
        cin >> q;
        Q.push_back(q);
    }

    auto a = calc_index(P);
    auto b = calc_index(Q);
    
    cout << abs(a-b) << endl;
    
    return 0;
}

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

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long int
#define INF 1000000007
#define llINF 1000000000000000007
#define v(i) vector<i>
#define vv(i) vector<vector<i>>
// cin.eof() 入力個数の問題
// int num = atoi(string.c_str()); 文字列の整数変換
int keta(ll n){int ans=0;while(n>0){n /= 10; ans++;}return ans;}
ll _pow(ll a,ll b){ll ans = 1;rep(i,b){ ans *= a;}return ans;}

int main() {
int x;
  cin>>x;
  if(x>=30){
    cout<<"Yes"<<endl;
  }else
  {
    cout<<"No"<<endl;}
    return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    typedef vector<int> vi;
    typedef vector<long long> vll;
    typedef vector<pair<int , int>> vpii;
    typedef pair<int , int> pii;
    typedef pair<long long  , long long> pll;
    typedef pair<double , double> pdd;
    #define eb emplace_back;
    #define mp make_pair;
     
    int main(){
        int x;
        cin>>x;
        cout<<x/2 + x%2;
        return 0;
    }

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<P> VP;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e18+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define dbgmint(n,arr) rep(i,n){cerr<<arr[i].x<<" ";}cerr<<endl;
#define out(a) cout<<a<<endl
#define out2(a,b) cout<<a<<" "<<b<<endl
#define vout(v) rep(i,v.size()){cout<<v[i]<<" ";}cout<<endl
#define Uniq(v) v.erase(unique(v.begin(), v.end()), v.end())
#define fi first
#define se second

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

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,v.size())i>>v[j];return i;}

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);

    ll n;
    cin>>n;
    Vec a(n);
    cin>>a;
    ll sz =1e5;

    Vec c(sz,0);
    rep(i,n){
        c[a[i]]++;
    }
    ll ans=0;
    REP(i,1,sz){
        chmax(ans,c[i-1]+c[i]+c[i+1]);
    }

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


Measured memory_bytes: 1792
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto S = RD!string;
	auto K = RD;
	/*string S;
	foreach (i; 0..3)
	{
		S ~= cast(char)(uniform(0, 3) + 'a');
	}
	long _ans;
	auto K = uniform(1, 4);
	{
		string T;
		foreach (i; 0..K)
			T ~= S;
		long i = 1;
		while (i < T.length)
		{
			if (T[i] == T[i-1])
			{
				++_ans;
				i += 2;
			}
			else
			{
				++i;
			}
		}
		debug writeln("S:", S);
		debug writeln("K:", K);
		debug writeln("T:", T);
		debug writeln("ans:", _ans);
	}*/

	long cnt;
	long i = 1;
	while (i < S.length)
	{
		if (S[i] == S[i-1])
		{
			++cnt;
			i += 2;
		}
		else
		{
			++i;
		}
	}

	debug writeln(cnt);

	long ans;
	if (S.length == 1)
	{
		ans = K/2;
	}
	else
	{
		if (S[0] != S[$-1])
		{
			ans = cnt*K;
		}
		else
		{
			long cnt2, cnt3;
			foreach (c; S)
			{
				if (S[0] != c) break;
				++cnt2;
			}
			foreach_reverse (c; S)
			{
				if (S[0] != c) break;
				++cnt3;
			}
			if (cnt2 == S.length)
			{
				ans = S.length * K / 2;
			}
			else if (cnt2 % 2 == 1 && cnt3 % 2 == 1)
			{
				ans = cnt*K+K-1;
			}
			else
			{
				ans = cnt*K;
			}
		}
	}

	writeln(ans);
	stdout.flush();
	debug readln();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll INF = 1ll<<30;
const ll MOD = 1000000007;
const double EPS = 1e-9;
const bool debug = 0;
//---------------------------------//

int N;
vector<pii> g[112345];
int col[112345];

void dfs(int u, int par, int gk) {
	col[u] = gk;
	for (pii v : g[u]) {
		if (v.fi == par) continue;
		dfs(v.fi, u, gk ^ (v.se % 2));
	}
}

int main() {
	cin >> N;
	REP(i, N - 1) {
		int u, v, w;
		scanf("%d %d %d", &u, &v, &w);
		u--; v--;
		g[u].push_back(pii(v, w));
		g[v].push_back(pii(u, w));
	}
	
	memset(col, -1, sizeof(col));
	dfs(0, -1, 0);
	
	REP(i, N) printf("%d\n", col[i]);
	
	return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v.at(i);
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int b, e, k, cnt = 0;
    cin >> b >> e >> k;
    for (int j = b; j < e; j++) {
      if (v.at(j) == k)
      cnt++;
    }
    cout << cnt << endl;
  }
}


Measured memory_bytes: 3088
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
#define inf 1000000007

int main(void){
    long long int x;
    cin >> x;
    long long int ans = (x/11)*2;
    if(x%11<=6&&x%11!=0) ans++;
    else if(x%11>=7) ans+=2;
    cout << ans << endl; 
    return 0;
}

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

const int INF = 3000;

struct memo {
    int dist;
    int fromX;
    int fromY;
};

using P = pair<int, int>;

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

void bfs(vector<vector<char>> &grid, vector<vector<memo>> &m, int h, int w) {
    queue<P> que;

    que.push(P(0, 0));
    m.at(0).at(0).dist = 0;
    
    while (que.size()) {
        P p = que.front(); que.pop();

        if (p.first == h - 1 && p.second == w - 1) break;

        for (int i = 0; i < 4; i++)
        {
            int nx = p.first + dx[i], ny = p.second + dy[i];

            if (0 <= nx && nx < h && 0 <= ny && ny < w && grid.at(nx).at(ny) == '.' && m.at(nx).at(ny).dist == INF) {
                que.push(P(nx, ny));
                m.at(nx).at(ny).dist = m.at(p.first).at(p.second).dist + 1;
                m.at(nx).at(ny).fromX = p.first;
                m.at(nx).at(ny).fromY = p.second;
            }
        }
        
    }
}

int main() {
    int h,w;
    cin >> h >> w;
    vector<vector<char>> grid(h, vector<char>(w));
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            cin >> grid.at(i).at(j);
        }
        
    }

    memo t;
    t.dist = INF;
    vector<vector<memo>> m(h, vector<memo>(w, t));

    bfs(grid, m, h, w);

    if (m.at(h - 1).at(w - 1).dist == INF) {
        cout << -1 << endl;
        return 0;
    }
    
    int x = h - 1;
    int y = w - 1;
    for (int i = 0; i <= m.at(h - 1).at(w - 1).dist; i++)
    {
        grid.at(x).at(y) = '#';
        int tx = x;
        x = m.at(x).at(y).fromX;
        y = m.at(tx).at(y).fromY;
    }
    
    int sum = 0;
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            if (grid.at(i).at(j) == '.') sum++;
        }
        
    }
    cout << sum << endl;
}


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

int main()
{

        int N;
        int T;
        cin >> N >> T;
        vector<int> t(N);
        for (int i = 0; i < N; ++i) {
                cin >> t[i];
        }
        long long start = -1;
        long long end = 0;
        long long ans = 0;

        for (int i = 0; i < N; ++i) {

                if (start == -1) {
                        start = t[i];
                        end = t[i] + T;
                        ans += (end - start);
                }
                else {

                        if (t[i] <= end) {
                                ans += (t[i] + T - end);
                                end = t[i] + T;
                        }
                        else {
                                start = t[i];
                                end = t[i] + T;
                                ans += (end - start);
                        }
                }
        }
        cout << ans << endl;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <string.h>
#include <stack>
#include <cmath>
using namespace std;

#define ISEQ(c) (c).begin(), (c).end()
typedef long long ll;

int main() {
  const double pi = acos(-1);
  double arg = pi / 2;
  double x = 0, y = 0;
  while (true) {
    double a, b;
    scanf("%lf,%lf", &a, &b);
    if (a == 0 and b == 0) break;
    x += a * cos(arg);
    y += a * sin(arg);
    arg += -2 * pi * b / 360;
  }
  printf("%d\n%d\n", (int)x, (int)y);
}

Measured memory_bytes: 1200
n = int(input())
l = list(map(int, input().split()))
c = 0

l.sort()

for i in range(n):
  for j in range(i+1, n):
    for k in range(j+1, n):
      if l[i] < l[j] < l[k] and l[i] + l[j] > l[k]:
        c += 1

print(c)

Measured memory_bytes: 68112
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int main() {
 int n,m;
  cin>>n>>m;
  vin a(n);
  rep(i,0,n) cin>>a[i];
  priority_queue<int> pq;
  rep(i,0,n) pq.push(a[i]);
  rep(i,0,m){
    int b=pq.top();
    b/=2;
    pq.pop();
    pq.push(b);
  }
  ll ans=0;
  rep(i,0,n){
   ans+=pq.top();
    pq.pop();
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1276
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
#define ll long long
using namespace std;
ll n,res,a[200010],s[200010];
int main()
{
	while(~scanf("%lld",&n))
	{
		res=0;
		for(ll i=1;i<=n;i++)scanf("%lld",&a[i]),s[i]=s[i-1]+a[i],a[i]^=a[i-1];
//		for(int i=1;i<=n;i++)cout << s[i] << " " << a[i] << endl;
		for(ll i=1;i<=n;i++)
		{
			ll l=i,r=n,ans=i;
			while(l<=r)
			{
//				cout << l << " " << r << " " << ans << endl;
				ll mid=(l+r)>>1;
				if((a[mid]^a[i-1])==(s[mid]-s[i-1]))l=mid+1,ans=mid;
				else r=mid-1;
			}
//			cout << ans << endl;
			res+=ans-i+1;
		}
		printf("%lld\n",res);
	}
	return 0;
}

Measured memory_bytes: 3328
#include <iostream>

using namespace std;

int main() {
    int x1, y1, x2, y2, x3, y3, x4, y4;
    cin >> x1 >> y1 >> x2 >> y2;

    x3 = x2 - (y2 - y1);
    y3 = y2 + (x2 - x1);
    x4 = x3 - (x2 - x1);
    y4 = y3 - (y2 - y1);

    cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;

    return 0;
}

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

const ll MAX = 1000000;
const ll MOD = 1000000007;

ll fac[MAX];

// テーブルを作る前処理
/*
void COMinit() {
    fac[0] = fac[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
    }
}
*/

ll pow_kai(ll a,ll n){//aのn乗を計算します。
  ll x = 1;
  while(n > 0){//全てのbitが捨てられるまで。
    if(n&1){//1番右のbitが1のとき。
      x = x*a%MOD;
    }
    a = a*a%MOD;
    n >>= 1;//bit全体を右に1つシフトして一番右を捨てる。
  }
  return x;
}

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    ll tmp=1;
    for(ll i=n;i>=n-k+1;i--) tmp = (tmp*i)%MOD;

    return (tmp * pow_kai(fac[k],MOD-2)) % MOD;
}



int main()
{
    string S,T;
    cin >> S >> T;

    ll lS=S.length(),lT=T.length(),bit=1;

    if(lS+1!=lT){
        cout << "No" << endl;
        return 0;
    }

    rep(i,lS){
        if(S[i]!=T[i]){
            bit=0;
        }
    }

    if(bit==1){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

 
    return 0;

}

Measured memory_bytes: 3600
import math
import numpy as np
from operator import mul

# 整数Nを桁ごとのリストにする
# l = [int(x) for x in list(str(N))]

# 入力が文字のリスト
# S = list(input().split())

#入力が数字のリスト
# A = list(map(int, input().split()))

# 入力がリストのリスト
# S = [list(input()) for i in range(H)]


# リストliから重複を削除したリストli_uniqを作成
#li_uniq = []
#for i in li:
#    if x not in li_uniq:
#        li_uniq.append(x)

# 複数行のinput - list版
#list = [list(map(int, input().split())) for i in range(N)]
# 複数行のinput - dictionary版
# key = a, value = b
#for i in range(N):
#    a, b = map(int, input().split())
#    dict[a] = b


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

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

value += abs(A[N-1])

print(value - abs(A[0]) - abs(A[1] - A[0]) + abs(A[1]))

for i in range(1, N-1):
    print(value - abs(A[i] - A[i-1]) - abs(A[i+1] - A[i]) + abs(A[i+1] - A[i-1]))

print(value - abs(A[N-1] - A[N-2]) - abs(A[N-1]) + abs(A[N-2]))

        
    

Measured memory_bytes: 22848
#include<map>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
using namespace std;

int a[105],n,ans,vis[105],cnt;

int main(){
	cin >> n;
	for(int i = 0;i < n;i++){
		cin >> a[i];
		vis[a[i]] ++;
	}
	for(int i = 0;i < 105;i++)
		if(vis[i] != 0) ans++;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int P=998244353;
inline void upd(R int &x,R int y){(x+=y)>=P?x-=P:0;}
inline int inc(R int x,R int y){return x+y>=P?x+y-P:x+y;}
inline int dec(R int x,R int y){return x-y<0?x-y+P:x-y;}
inline int mul(R int x,R int y){return 1ll*x*y-1ll*x*y/P*P;}
int ksm(R int x,R int y){
	R int res=1;
	for(;y;y>>=1,x=mul(x,x))(y&1)?res=mul(res,x):0;
	return res;
}
const int N=1e7+5;
int fac[N],ifac[N],bin[N],n,res;
inline int C(R int n,R int m){return m>n?0:1ll*fac[n]*ifac[m]%P*ifac[n-m]%P;}
int main(){
	scanf("%d",&n);
	fac[0]=ifac[0]=1;fp(i,1,n)fac[i]=mul(fac[i-1],i);
	ifac[n]=ksm(fac[n],P-2);fd(i,n-1,1)ifac[i]=mul(ifac[i+1],i+1);
	bin[0]=1;fp(i,1,n+1)bin[i]=mul(bin[i-1],2);
	res=ksm(3,n);
	fp(i,(n>>1)+1,n)upd(res,P-mul(C(n,i),bin[n-i+1]));
	printf("%d\n",res);
	return 0;
}

Measured memory_bytes: 117376
#include<bits/stdc++.h>
#define p 1000000007
#define pii pair<int,int>
#define f first
#define s second
using namespace std;
int dp1[100001];
int dp(int i,int a[],int n){
	if(i==n-1)return 0;
	if(i>n-1)return 100000;
	if(dp1[i]!=-1)return dp1[i];
	return dp1[i]=min(max(a[i]-a[i+1],a[i+1]-a[i])+dp(i+1,a,n),max(a[i]-a[i+2],a[i+2]-a[i])+dp(i+2,a,n));
}
int main()
{	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin>>n;
	int a[n];
	memset(dp1,-1,sizeof(dp1));
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	cout<<dp(0,a,n);
    return 0;
}

Measured memory_bytes: 4992
n,x,y=map(int,input().split())
x,y=x-1,y-1
adj=[[float("inf")]*n for i in range(n)]
adj[x][y]=adj[y][x]=1
for i in range(n):
    for j in range(n):
        adj[i][j]=min(abs(i-j),abs(i-x)+1+abs(y-j),abs(i-y)+1+abs(y-j))
ans=[0 for i in range(n)]
for i in range(n-1):
    for j in range(i+1,n):
        ans[adj[i][j]]+=1
for i in range(1,n):
    print(ans[i])

Measured memory_bytes: 136944
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>

#define INF 100000001

using namespace std;

int DP[101][101];
int *p;

int rec(int r,int c){
    int Min = INF;
    int num = c - r;
    
    for (int i = 0; i < num; i++) {
        Min = min(Min , DP[r][r+i] + DP[r+i+1][c] + p[r-1]*p[r+i]*p[c]);
    }
    return Min;
}

int main(){
    int N;
    cin >> N;
    for (int i = 1; i <= N; i++) DP[i][i] = 0;
    
    p = (int *)malloc(sizeof(int)* (N+1));
    
    cin >> p[0];
    cin >> p[1];
    int bb;
    for (int i = 2; i <= N; i++) {
        cin >> bb;
        cin >> p[i];
    }
    
    for (int i = 1; i < N; i++) DP[i][i+1] = p[i-1]*p[i]*p[i+1];
    
    
    for (int j = 0; j <= N-3 ; j++) {//?????????????????????
        for (int i = 3+j; i <= N; i++) {//????????°???????????????
            DP[i-2-j][i] = rec(i-2-j,i);
        }
    }
    
    cout << DP[1][N] << endl;
    
    return 0;
}

Measured memory_bytes: 1228
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
import itertools as it
from collections import Counter
#======================================================#
def main():
    n = II()
    aa = MII()
    cum = list(it.accumulate([0]+aa))
    c = Counter(cum)
    print(sum([(n*(n-1))//2 for n in c.values() if n>1]))

if __name__ == '__main__':
    main()

Measured memory_bytes: 41612
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
using namespace std;

typedef struct{
	int x;
	int y;
}point;

long d[1000][1000]={0};

int main(){
	int h, w, n;
	char f[1001][1001];
	point start, goal[9];
	
	scanf(" %d %d %d", &h, &w, &n);
	for(int i=0; i<h; ++i){
		for(int j=0; j<w; ++j){
			scanf(" %c", &f[i][j]);
			
			if(f[i][j]=='S'){
				start.x=j;
				start.y=i;	
			}
			else if('1'<=f[i][j] && f[i][j]<='1'+n-1){
				goal[f[i][j]-'1'].x=j;
				goal[f[i][j]-'1'].y=i;	
			}
		}
	}
	
	int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};
	int now=0;
	long ans=0;
	while(now<n){
		memset(d, -1, sizeof(d));
		
		queue<point> que;
		d[start.y][start.x]=0;
		que.push(start);
		
		while( !que.empty() ){
			point v=que.front();
			que.pop();
			for(int i=0; i<4; ++i){
				int nx=v.x+dx[i], ny=v.y+dy[i];
				if(nx>=0 && nx<w && ny>=0 && ny<h && f[ny][nx]!='X' && d[ny][nx]==-1){
					d[ny][nx]=d[v.y][v.x]+1;
					point tmp;
					tmp.x=nx; tmp.y=ny;
					que.push(tmp);
				}
			}	
		}
		
		ans+=d[goal[now].y][goal[now].x];
		start=goal[now];
		now++;
	}
	
	printf("%ld\n", ans);
}

Measured memory_bytes: 10000
#include <iostream>
#include <queue>
#include <map>
#include <bitset>
#include <string>
#include <set>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <ctime>
//#include <unordered_map>
#include <stack>
#include <cstdlib>
#include <numeric>
#include <cassert>
#include <complex>
using namespace std;
#define maxn 3000007
#define maxm 400007
#define maxq 1000007
#define maxl 1234
#define modn 998244353
#define scan(a) scanf("%d",&a)
#define scanl(a) scanf("%lld",&a)
#define scanl2(a,b) scanf("%lld%lld",&a,&b)
#define scans(a) scanf("%s",a)
#define scans2(a,b) scanf("%s%s",a,b)
#define scand(a) scanf("%lf",&a)
#define scan2(a,b) scanf("%d%d",&a,&b)
#define scand2(a,b) scanf("%lf%lf",&a,&b)
#define scan3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define scan4(a,b,c,d) scanf("%d%d%d%d",&a,&b,&c,&d)
#define scan5(a,b,c,d,e) scanf("%d%d%d%d%d",&a,&b,&c,&d,&e)
#define print(a) printf("%d\n",a);
#define printl(a) printf("%lld\n",a);
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define rrep(i,a,b) for(int i=a;i>= b;i--)
#define fscan(a) fscanf(stream,"%d", &a);
#define mp      make_pair	
#define pb      push_back
#define eb      emplace_back
#define mm(a,b) memset(a,b,sizeof a)
#define log2(n) (double)(log(n) / log(2.0))
#define _crt_disable_perfcrit_locks
#define bll __int128
typedef long long ll;
typedef unsigned long long ull;
const int inf = 0x3f3f3f3f;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef map <ll, ll> mll;
typedef pair <ll, ll> pll;
typedef map <int, int> mii;
typedef pair <int, int> pii;
typedef map <char, int> mci;
typedef map <char, char> mcc;
typedef pair <char, int> pci;
typedef complex<double> cd;
typedef vector<complex<double> > vcd;

const double eps = 1e-8;
const double PI = 2 * acos(0.0);

int cc, bb; char ch; inline int F() {
	while (ch = getchar(), (ch < 48 || ch> 57) && ch != '-'); ch == '-' ? cc = bb = 0 : (cc = ch - '0', bb = 1);
	while (ch = getchar(), ch > 47 && ch < 58)cc = (cc << 1) + (cc << 3) + (ch ^ 48); return bb ? cc : -cc;
}
void write(int x) {
	int y = 10, len = 1;
	while (y <= x) { y *= 10; len++; }
	while (len--) { y /= 10; putchar(x / y + 48); x %= y; }
}
int main() {
	//ios::sync_with_stdio(0);
	//cin.tie(0);
	//FILE* stream = fopen("L:/20.in", "rb+")
	string s;
	cin >> s;
	if (s[2] == s[3] && s[4] == s[5]) {
		cout << "Yes" << endl;
	}
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <limits>
#include <cmath>

#define pf printf
// #define DEBUG true
#define DEBUG false
#define IFD if(DEBUG)
#define FOR(i,ii,n) for(long long i=ii; i<n; i++)
#define FORREV(i,ii,n) for(long long i=n-1; i>=ii; i--)
#define INF ((ll)1e15)

using namespace std;
typedef long long ll;

ll const NMAX = 1000001;
// ll mod = 998244353;
ll mod = 1e9 + 7;
ll fact[NMAX];
ll finv[NMAX];
ll comb(ll n,ll a){
	return fact[n] * finv[a] % mod * finv[n-a] % mod;
}
ll pow(ll a,ll n){
	ll prd = 1;
	ll exp = a;
	while(n > 0){
		if((n&1)==1){
			prd *= exp;
			prd %= mod;
		}
		exp *= exp;
		exp %= mod;
		n >>= 1;
	}
	return prd;
}

ll gcd(ll a,ll b){
	if(a<b){
		ll tmp = b;
		b = a;
		a = tmp;
	}
	ll r = a % b;
	if(r==0) return b;
	return gcd(b,r);
}
ll lcm(ll a,ll b){
	return a*b/gcd(a,b);
}

ll numk[NMAX];
int main(){
	ll N;
	cin >> N;
	// init
	fact[0] = 1;
	finv[0] = 1;
	FOR(i,1,N+1){
		fact[i] = fact[i-1] * i % mod;
		finv[i] = pow(fact[i], mod-2);
	}
	// main
	// ll least = ceil(N*1.0/2)
	ll least = ceil(N*1.0/2);
	FOR(k,least,N){
		numk[k] = comb(k-1, N-1-k) % mod * fact[k] % mod * fact[N-1-k] % mod;
	}
	ll sum = least * numk[least];	FOR(i,least+1,N){
		sum += i * (numk[i] - numk[i-1]);
		sum %= mod;
	}
	if(sum < 0) sum+=mod;
	pf("%lld", sum);
}



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

int main()
{
    int N;
    int ans = 0;
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        int l, r;
        cin >> l >> r;
        ans += r - l + 1;
    }
    cout << ans << endl;
}

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

using namespace std;
using ll = int64_t;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using mii = map<int, int>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using tpi = tuple<int, int, int>;

using vqi = vector<queue<int>>;
using vpi = vector<pii>;
using bs = bitset<60>;
using vbi = vector<bs>;

ll gcd(ll a, ll b) {
    if (a < b) {
        swap(a, b);
    }

    /* ユークリッドの互除法 */
    ll r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

constexpr int64_t __pow_mod(int64_t n, int64_t p, int64_t mod) noexcept {
    if (p == 0) {
        return 1;
    }
    if (p % 2 == 0) {
        int64_t t = __pow_mod(n, p / 2, mod);
        return (t * t) % mod;
    }
    return (n * (__pow_mod(n, p - 1, mod) % mod)) % mod;
}

constexpr int64_t pow_mod(int64_t n, int64_t p, int64_t mod) noexcept {
    int64_t res = __pow_mod(n, p, mod);
    if (res == 0) {
        res = mod;
    }
    return res;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
    int N;
    cin >> N;
    //vi A(N);
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        if (a % 2 == 0) {
            if (a % 3 == 0 || a % 5 == 0) {
                continue;
            } else {
                cout << "DENIED" << endl;
                return 0;
            }
        }
    }

    cout << "APPROVED" << endl;
    return 0;
}


Measured memory_bytes: 256
N,M=map(int,input().split())
S = [list(map(int, input().split())) for i in range(N)]
S.sort()
a=0
for i in range(N):
        if M>S[i][1]:
                a+=S[i][1]*S[i][0]
                M-=S[i][1]
        else:
                a+=M*S[i][0]
                break
print(a)

Measured memory_bytes: 27756
<?php
// Your code here!
    $string = trim(fgets(STDIN));
    $num = intval(trim(fgets(STDIN)));
    while($line = trim(fgets(STDIN))){
        $line = explode(" ",$line);
        if($line[0]== "print"){
            $string_a = substr($string,$line[1],$line[2]-$line[1]+1);
            echo $string_a."\n";
        }elseif($line[0]== "replace"){
            $string = substr_replace($string,$line[3],$line[1],$line[2]-$line[1]+1);
        }elseif($line[0]== "reverse"){
            $line_a = substr($string,$line[1],$line[2]-$line[1]+1);
            $line_a = strrev($line_a);
            $string = substr_replace($string,$line_a,$line[1],$line[2]-$line[1]+1);
        }
    }
?>


Measured memory_bytes: 9276
use strict;
use warnings;
use utf8;

my @x;
my ($aa) = split /\s/, <STDIN>;
my ($bb) = split /\s/, <STDIN>;
my ($cc) = split /\s/, <STDIN>;
my ($dd) = split /\s/, <STDIN>;
my ($ee) = split /\s/, <STDIN>;
my ($kk) = split /\s/, <STDIN>;

push @x, $aa, $bb, $cc, $dd, $ee;


my $ng = 0;
for (my $i = 0; $i < @x - 1; $i++) {
    for (my $j = $i + 1; $j < @x; $j++) {
        if ($x[$j] - $x[$i] > $kk) {
            $ng = 1;
        }
    }
}


if ($ng == 1) {
    print ":(\n";
} else {
    print "Yay!\n";
}


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

int main() {

	int n; cin >> n;
	vector<int> v(n), c(n);
	for (int i = 0; i < n; i++) {
		cin >> v[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> c[i];
	}
	int ans = 0;	
	for (int i = 0; i < n; i++) {
		ans += max(v[i] - c[i], 0);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
char s[102];
char t[103];
int main(void)
{
    int N;
    cin>>N;
    for(int i = 0; i < N;i ++)
    {
        cin>>s[i];
    }
    for(int i = 0; i < N;i ++)
    {
        cin>>t[i];
    }

    for(int i = 0; i < N;i ++)
    {
        cout<<s[i]<<t[i];
    }
    cout<<endl;
    return 0;
}



Measured memory_bytes: 256
import fractions
a,b=map(int, input().split())
f=fractions.gcd(a,b)


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
if f==1:
  print(1)
  exit()
else:
  temp=factorization(f)
  temps=set([])
  for item in temp:
    temps.add(item[0])
  if 1 in temps:
    print(len(temps))
  else:
    print(len(temps)+1)
  

Measured memory_bytes: 5176
import sys
def input():
	return sys.stdin.readline().strip()

H, W, A, B = list(map(int, input().split()))

ans = []

for i in range(H):
	if i < 2*B:
		if i % 2 == 0:
			x = [1]*A
			x.extend([0]*(W - A))
		else:
			x = [0]*A
			x.extend([1]*(W - A))
	else:
		x = [1] * A
		x.extend([0] * (W - A))
	ans.append(x)

for i in range(H):
	for j in range(W):
		ans[i][j] = str(ans[i][j])


for i in range(H):
	print("".join(ans[i]))

Measured memory_bytes: 121564
#include <bits/stdc++.h>
using namespace std;
int main(){
  int x,f,i,m1,m2,m3,m4,m5,m6,m7,m8,m9;
  cin >> x;
  m1=x/100000000;m2=(x-m1*100000000)/10000000;
  m3=(x-m1*100000000-m2*10000000)/1000000;
  m4=(x-m1*100000000-m2*10000000-m3*1000000)/100000;
  m5=(x-m1*100000000-m2*10000000-m3*1000000-m4*100000)/10000;
  m6=(x-m1*100000000-m2*10000000-m3*1000000-m4*100000-m5*10000)/1000;
  m7=(x-m1*100000000-m2*10000000-m3*1000000-m4*100000-m5*10000-m6*1000)/100;
  m8=(x-m1*100000000-m2*10000000-m3*1000000-m4*100000-m5*10000-m6*1000-m7*100)/10;
  m9=x-m1*100000000-m2*10000000-m3*1000000-m4*100000-m5*10000-m6*1000-m7*100-m8*10;
  f=m1+m2+m3+m4+m5+m6+m7+m8+m9;
  if(x%f==0){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	if (a == b)cout << a + b << endl;
	else if (a > b)cout << 2 * a - 1 << endl;
	else cout << 2 * b-1 << endl;
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}


int main() {
  int N,M,X;
  cin>>N>>M>>X;
  int C[100];
  int A[100][100];
  for(int i=0;i<N;i++){
      cin>>C[i];
      for(int j=0;j<M;j++){
         cin>>A[i][j];
      }
  }
  int ans=10000000;
  for(int s=0;s<(1<<N);s++){
      int p=0;
      vector<int>table(M);
      for(int i=0;i<N;i++){
          if((s>>i)&1){
             for(int j=0;j<M;j++){
                 table[j]+=A[i][j];
             }
             p+=C[i];}
      }
      bool ok=true;
      for(int j=0;j<M;j++){
          if(table[j]<X){ok=false;}
          //cout<<table[j];
      }//cout<<endl;
      if(ok){ans=min(ans,p);}
  }
  if(ans==10000000){cout<<-1<<endl;}
  else{cout<<ans<<endl;}
  return 0;
}

Measured memory_bytes: 3604
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????


		Scanner scan = new Scanner(System.in);
		ArrayList<Integer[]> list = new ArrayList<Integer[]>();

		Integer[] ary;

		while(scan.hasNext()){

			ary = new Integer[2];
			//???H
			ary[0] = scan.nextInt();
			//?¨?W
			ary[1] = scan.nextInt();

			if(ary[0] != 0 && ary[1] != 0){

				list.add(ary);
			}else{
				scan.close();
				break;
			}

		}

		String[] mark;

		for(int i = 0; i < list.size(); i++){

			ary = list.get(i);
			//???
			for(int j = 0; j < ary[0]; j++){


				//?¨?
				if(j % 2 == 0){
				//?\???°???

					for(int k = 0; k < ary[1]; k++){

						if(k % 2 == 0){
						//?\???°???
							System.out.print("#");
						}else{
						//??¶??°???
							System.out.print(".");
						}
					}
					System.out.println("");

				}else{
				//??¶??°???

					for(int k = 0; k < ary[1]; k++){

						if(k % 2 == 0){
						//?\???°???
							System.out.print(".");
						}else{
						//??¶??°???
							System.out.print("#");
						}
					}
					System.out.println("");
				}


			}
			System.out.println("");
		}
	}
}

Measured memory_bytes: 25752
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename t, typename u, typename Comp=less<>>
bool chmax(t& xmax, const u& x, Comp comp={}) { if(comp(xmax, x)) { xmax = x; return true; } return false;}
template<typename t, typename u, typename Comp=less<>>
bool chmin(t& xmin, const u& x, Comp comp={}) { if(comp(x, xmin)) { xmin = x; return true;} return false;}
const int INF = 1e8;
const ll infl = 1LL << 60;
///////
struct UnionFind{
  vector<int> d;
  UnionFind(int n=0):d(n,-1){}
  int find(int x){
    if(d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x,int y){
    x = find(x); y = find(y);
    if(x == y) return false;
    if(d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x,int y){ return find(x) == find(y);}
  int size(int x) {return -d[find(x)];}
};
/*struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};*/

int p[1000003];
int main(){
  int N,M;
  cin >> N >> M;
  UnionFind uf(N);
  for(int i=0;i<N;i++) cin >> p[i],p[i]--;
  rep(i,M){
    int x,y; cin >> x >> y;x--,y--;
    uf.unite(x,y);
  }
  ll ans = 0;
  for(int i=0;i<N;i++){
    if(uf.same(i,p[i])) ans++;
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <stack>
#include <set>
#include <map>
#define sf scanf
#define pf printf
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
const int inf=1e9;
int n,k;
ll t[maxn];
int check(ll p)
{
    int i=0;
    for(int j=0;j<k;j++)
    {
        ll s=0;
        while(s+t[i]<=p)
        {
            s+=t[i];
            ++i;
            if(i==n)return n;
        }
    }
    return i;
}
ll solve()
{
    ll l=1,r=10000*100000;
    ll ans=r;
    while(r>=l)
    {
        ll m=(l+r)/2;
        ll v=check(m);
        if(v>=n)ans=m,r=m-1;
        else l=m+1;
    }
    return ans;
}
int main()
{
    cin>>n>>k;
    for(int i=0;i<n;i++)
        cin>>t[i];
    ll ans=solve();
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 3868
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    long long ans=0;
    long long flag=0;
    for(int i=0;i<s.size();i++){
        if (s[i] == 'B') {
            flag++;
        }
        else {
            ans += flag;
        }
    }
    cout << ans;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<string.h>
int main(void)
{
	char a[20];
	int i,s;
	scanf("%s",a);
	s=strlen(a);
	for(i=s-1;i>=0;i--){
		printf("%c",a[i]);
	}
	printf("\n");
	return 0;
}

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

using namespace std;

long long int ncr[51][51];

long long int Rec(int n, int r)
{
    if(n==r || r == 0) return 1;

    if(ncr[n][r] == -1)
    {
        ncr[n][r] = Rec(n-1,r-1) + Rec(n-1, r);
    }

    return ncr[n][r];
}

int main()
{
    memset(ncr,-1, sizeof(ncr));
    int n, p;
    cin>>n>>p;

    int x, one = 0, zero = 0;

    for(int i = 0; i < n; i++)
    {
        cin>>x;

        if(x%2) one++;
        else zero++;


    }

    long long int ans = 0;


    if(p==0)
    {

        for(int i = 0; i <= zero; i++) ans += Rec(zero,i);
        long long temp = ans;

        //cout<<temp<<endl;

        for(int i = 2; i <= one; i+=2) ans+= (temp*Rec(one, i));

    }

    else
    {
        for(int i = 1; i <= one ;i+=2)
        {
            ans += Rec(one,i);
        }



        long long temp = ans;

        //cout<<temp<<endl;

        for(int i = 1; i <= zero; i++) ans +=(temp* Rec(zero, i));
    }

    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define all(var) var.begin(), var.end()
#define input freopen("input", "r", stdin)
#define output freopen("output", "w", stdout)
#define Fast ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL)
typedef long long ll;
using namespace std;

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

int main(){
    double n, x, t; cin >> n >> x >> t;
    ll ans = ceil(n/x) * t;
    cout << ans << endl;
}



Measured memory_bytes: 3716
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N , M ,sum=0;
  string test;
  cin >> N;
  vector<int> point(N);
  vector<string> B(N);
  for(int i=0;i<N;i++){
    cin >> B.at(i);
  }  
  
  cin >> M;
  vector<string> R(M);
  for(int i=0;i<M;i++){
    cin >> R.at(i);
  }

  for(int i=0;i<N;i++){
    test = B.at(i);
  for(int j=0;j<N;j++){
  	if(test == B.at(j))
      point.at(i)++;
  }
  for(int j=0;j<M;j++){
  	if(test == R.at(j))
      point.at(i)--;
  }
    if(sum<point.at(i))
      sum = point.at(i);
  }  
  cout << sum << endl;
  return 0; 
}

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

int main(){
  int n,m;cin>>n>>m;
  long long s=0;
  for(int i=0;i<n;i++){int x;cin>>x;s+=x;}
  long long t=0;
  for(int j=0;j<m;j++){int x;cin>>x;t+=x;}
  cout<<(s*t)<<endl;
}


Measured memory_bytes: 3124
// Last Change: 12/28/2018 23:35:37.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

int dp[50];

ll Fib(int n) {
  if (dp[n] == 0) {
    dp[n] = Fib(n - 1) + Fib(n - 2);
  }
  return dp[n];
}

int main() {
  dp[0] = dp[1] = 1;
  int n;
  cin >> n;
  cout << Fib(n) << endl;
}



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

int main()
{
  string a, b;
  cin >> a >> b;

  if (a.length() != b.length() - 1)
    cout << "No";
  else
  {
    int t = 0;
    for (int i = 0; i < a.length(); i++)
    {
      if (a[i] != b[i])
        t = 1;

    }
    if (t == 0)
      cout << "Yes";
    else
      cout << "No";
  }

}


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

using namespace std;
using ll =long long;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }
//Write From this Line

int main()
{
	int n; 
	cin >> n; 
	cout << (n + 1) / 2 << endl;
}


Measured memory_bytes: 256
fn main() {
    let buf = io::read_string();
    let mut sc = io::Scanner::new(&buf);
    let n: usize = sc.read();
    let m: u64 = sc.read();
    let a: Vec<u64> = sc.read_vec(n as usize);
    let mut b = vec![0u64; n + 1];
    for i in 0..n as usize {
        b[i + 1] += b[i] + a[i];
        b[i + 1] %= m;
    }
    b.sort();

    let mut res = 0u64;
    let mut cnt = 1u64;
    for i in 1..n+1 {
        if b[i] == b[i - 1] {
            cnt += 1;
        } else {
            res += cnt * (cnt - 1) / 2;
            cnt = 1;
        }
    }
    if cnt != 1 {
        res += cnt * (cnt - 1) / 2;
    }

    println!("{}", res);
}

#[allow(dead_code)]
mod io {
    use std;
    use std::io::Read;
    use std::str::{FromStr, SplitWhitespace};
    pub struct Scanner<'a> {
        pub iter: SplitWhitespace<'a>,
    }
    impl<'a> Scanner<'a> {
        pub fn new(s: &'a str) -> Scanner<'a> {
            Scanner {
                iter: s.split_whitespace(),
            }
        }
        pub fn read<T: FromStr>(&mut self) -> T {
            self.iter
                .next()
                .unwrap()
                .parse()
                .ok()
                .expect("parsing failed")
        }
        pub fn read_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.read()).collect()
        }
    }
    pub fn read_string() -> String {
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }
}


Measured memory_bytes: 6396
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <utility>
#include <string>
#include <math.h>
#include <algorithm>
#include <cstring>
#include <cctype>

typedef long long int lli;

using namespace std;

int main() {

   lli X;
   cin >> X;
   lli n;
   n=100;
   int cnt=0;
   while(n<X){
    cnt++;
    n=n*1.01;
   }
   cout << cnt << endl;
    
}

Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <fstream>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    string s;
    int z = 0;
    cin >> s;
    for (int i = 0; i + i < s.length(); i++) if (s[i] != s[s.length() - i - 1]) z++;
    cout << z;
}


Measured memory_bytes: 3564