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



int main(){

	int n; cin >> n;
	string c;
	int m;
	vector<int> S(13);
	vector<int> H(13);
	vector<int> C(13);
	vector<int> D(13);

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

		if(c=="S")
			S[m-1]=m;
		else if(c=="H")
			H[m-1]=m;
		else if(c=="C")
			C[m-1]=m;
		else
			D[m-1]=m;
	}


	for(int i=0; i<4; i++){
		for(int j=0; j<13; j++){
			if(i==0){
				if(S[j]==0)
					cout << "S" << " " << j+1 << endl;
			}
			else if(i==1){
				if(H[j]==0)
					cout << "H" << " " << j+1 << endl;
			}
			else if(i==2){
				if(C[j]==0)
					cout << "C" << " " << j+1 << endl;
			}
			else
				if(D[j]==0)
					cout << "D" << " " << j+1 << endl;
			
		}
	}




	return 0;
}

Measured memory_bytes: 3132
#include <iostream>
#include <cstdio>
#include <stack>

using namespace std;
int  tong(int a[], int n)
{
    int s = 0;
    for ( int i = 1; i <= n ; i++ )
        s += a[i];
    return s;
}

int main()
{
    //freopen("ee.inp","r",stdin);
    long long int n,w;
    cin >> n >> w;

    int m[n+1], v[n+1];
    for ( int i = 1 ; i <= n; i++ )
        cin >> m[i] >> v[i];
    int T = tong(v,n);
    long long int f[T+1];
    for ( int i = 1 ;i <= T ;i ++ )
        f[i]=1000000000;
    f[0] = 0;
    for ( int i = 1; i <= n; i++ )
    {
        for ( int t = T; t >= v[i] ; t-- )
            f[t] = min(m[i]+f[t-v[i]], f[t]);
    }
    for ( int i = T; i >= v[1] ; i-- )
    {
        if(f[i]<= w)
        {
            cout << i;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 1024
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())

if B > A:
    if T*(V-W) >= B - A:
        print("YES")
    else:
        print("NO")

if A > B:
    if T*(V-W) >= A - B:
        print("YES")
    else:
        print("NO")


Measured memory_bytes: 9180
#include<cstdio>
#include<cmath>
#include<climits>
#include<algorithm>
#include<sstream>
#include<iostream>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<list>
#include<map>
#include<vector>

using namespace std;


#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define ll long long

#define IMIN INT_MIN;
#define IMAX INT_MAX;

int maxelem(vector<int> src) {
	int dst = IMIN;
	rep(i, src.size()) {
		dst = (dst > src[i]) ? dst : src[i];
	}
	return dst;
}

int secondelem(vector<int> src) {
	int dst = IMIN;
	int dst2 = IMIN;
	rep(i, src.size()) {
		if (dst < src[i]) {
			dst2 = dst;
			dst = src[i];
		}
		else if (dst2 < src[i]) {
			dst2 = src[i];
		}
	}
	return dst2;
}

vector<int> count(vector<int> a) {
	int ma = maxelem(a);
	vector<int> count(ma+1, 0);
	rep(i, a.size()) {
		count[a[i]]++;
	}
	return count;
}

int find(vector<int> a, int b) {
	rep(i, a.size()) {
		if (a[i] == b) return i;
	}
	return -1;
}

int main(){
	int a, b, c;
	cin >> a >> b >> c;
	cout << a*b/2 << endl;

	return 0;
}




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

int main(){
    int n,k; cin >> n >> k;
    ll m0 = 0,m2 = 0;
    for(int i = 1; i <= n; i++){
        if(i%k == 0) m0++;
        if(i%k == k/2) m2++;
    }
    ll ans = m0*m0*m0;
    if(k % 2 == 0) ans += m2*m2*m2;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let n: isize = iter.next().unwrap().parse().unwrap();
    let l: isize = iter.next().unwrap().parse().unwrap();

    let mut sum = 0;
    for i in l..(l+n) {
        sum += i;
    }

    let mut abs_min = 10000000;
    for i in l..(l+n) {
        let t = sum - i;
        if (sum - abs_min).abs() > (sum - t).abs() {
            abs_min = t;
        }
    }

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


Measured memory_bytes: 4352
#include<stdio.h>

int main()
{

int a,b;


scanf("%d %d",&a,&b);


if(a < b){
printf("a < b\n");
}else if(a > b){
printf("a > b\n");
}else if(a == b){
printf("a == b\n");
}
return 0;

}

Measured memory_bytes: 580
var
a,b:longint;
s:string;
begin
read(s);
val(copy(s,1,pos(' ',s)-1),a);
delete(s,1,pos(' ',s));
val(copy(s,3,length(s)),b);
delete(s,2,length(s)-1);
if s='+' then writeln(a+b)
         else writeln(a-b);
end.

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>
#include <string>
#include <numeric>
#include <math.h>
#include <set>
#include <map>
#include <fstream>
#include <sstream>
#include <iterator>
#include <complex>
using namespace std;

long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcd(long long a,long long b){return a*b / gcd(a,b) / gcd(a,b);}

int main()
{
	long double a,b,x;
	cin>>a>>b>>x;

	long double y = 2*x / (a*b);
	long double result;
	if(y <= a)
	{
		long double r = sqrt(y*y + b*b);
		long double theta = asin(y/r);
		result = 90 - theta / M_PI * 180;
	}
	else
	{
		long double z = a*a*b -x;
		long double w = 2 * z / (a*a);
		long double r = sqrt(w*w + a*a);
		long double theta = asin(a / r);
		result = 90 - theta / M_PI * 180;
	}
	
	
	cout<<fixed << setprecision(10)<<result<<endl;
}

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

int kosu[8]={1,1,2,3,5,8,13,21};
long long sosu = 1000000007;

long long G(int X){
    if(0<=X && X<=7){
        return (long long)kosu[X];
    }else{
        return 1;
    }
}
//saikideyarutonagasugirukaradoutekikeikakuhoudekakinaosu

long long AN(int H, int K, int W){
    if(K<1 || K>W){
        return 0;
    }else if(H==1){
        if(K==2 || K==1) return G(W-K);
        else return 0;
    }else{
        return ((G(K-2)*G(W-K))*AN(H-1,K-1,W))%sosu
        +((G(K-1)*G(W-K))*AN(H-1,K,W))%sosu
        +((G(K-1)*G(W-K-1))*AN(H-1,K+1,W))%sosu;
    }
}



int main ()
{
    
    int H,W,K;
    cin >> H >> W >> K;
    long long DP[101][10];
    //initialization
    for(int i=0;i<101;i++){
        for(int j=0;j<10;j++){
            DP[i][j]=0;
        }
    }
    DP[0][1]=1;
    
    int KK;
     for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            KK=j+1;
            DP[i+1][j+1]=
            ((G(KK-2)*G(W-KK))*DP[i][KK-1])%sosu
            +((G(KK-1)*G(W-KK))*DP[i][KK])%sosu
            +((G(KK-1)*G(W-KK-1))*DP[i][KK+1])%sosu;
        }
    }
    cout << DP[H][K]%sosu << endl;
    return 0;
}








Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()

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

using namespace std;
int N,C;
int D[40][40];
int c[505][505];
int memo[40][3];// memo[i][j]:= i番目の色でj番目を塗った時のコスト


void calc(int a,int b){
	//a番目の色でb番目を塗る時のコストを計算する
	int ret = 0;
	for(int i=1;i<=N;i++)for(int j=1;j<=N;j++){
		if((i+j)%3!=b)continue;
		ret += D[c[i][j]][a];
	}
	memo[a][b] = ret;
}
int func(int x,int y,int z){
	int ret = 0;
	ret += memo[x][0];
	ret += memo[y][1];
	ret += memo[z][2];
	return ret;
}
int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N >> C;
	for(int i=1;i<=C;i++){
		for(int j=1;j<=C;j++){
			cin >> D[i][j];
		}
	}
	for(int i = 1;i<=N;i++){
		for(int j=1;j<=N;j++){
			cin >> c[i][j];
		}
	}
	//各マスについて塗る色は固定されている
	//各マスを何で塗るかcP3通り全列挙する	
	int ans = 1e9+7;
	for(int i=1;i<=C;i++)for(int j=0;j<=2;j++){
		calc(i,j);
	}
	for(int a =1;a<=C;a++){
		for(int b=1;b<=C;b++){
			for(int z=1;z<=C;z++){
				if(a==b || b==z || a==z)continue;
				ans = min(ans,func(a,b,z));
			}
		}
	}
	cout << ans << endl;
}

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

int main(){
	int n;
	cin >> n;
	vector<int> p(n), q(n);
	for(int i = 0; i < n; i++) cin >> p[i];
	for(int i = 0; i < n; i++) cin >> q[i];
	int a = -1, b = -1;
	vector<int> r(n);
	for(int i = 0; i < n; i++) r[i] = i + 1;
	int cnt = 0;
	do{
		if(r == p) a = cnt;
		if(r == q) b = cnt;
		cnt++; 
	}while(next_permutation(r.begin(), r.end()));
	cout << abs(a - b) << endl;
}

Measured memory_bytes: 256
#include <iostream>
using i64 = long long;

int main() {
    constexpr i64 mod = 1000000007;
    int n;
    std::cin >> n;

    i64 ret = 0, s = 0;
    for (int i = 0; i < n; i++) {
        i64 a;
        std::cin >> a;
        ret = (ret + a * s) % mod;
        s = (s + a) % mod;
    }

    std::cout << ret << std::endl;

    return 0;
}


Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
#define inf 1e9
#define ll long long int

int solve(int *h, int n)
{
  vector<int> dp(n+1);

  dp[1] = 0;

  int w1=0,w2=0;
  for(int i=2;i<=n;i++)
  {
    w1 = abs(h[i]-h[i-1])+dp[i-1];
    w2 = (i==2) ? inf : abs(h[i]-h[i-2])+dp[i-2];
    dp[i] = min(w1,w2);
  }
  return dp[n];
}
int main()
{
      int n;
      cin>>n;

      int h[n+1];

      for(int i=1;i<=n;i++)
      {
        cin>>h[i];
      }

      cout<<solve(h,n)<<"\n";
}


Measured memory_bytes: 1024
A, B, H, M = (int(i) for i in input().split())

from math import radians, cos, sqrt
h_degree = (360/12) * H + (360/12) * (M/60)
m_degree = (360/60) * M

diff_degree = abs(m_degree-h_degree)
use_degree = min(diff_degree, 360-diff_degree)

ans = A**2 + B**2 - (2*A*B*cos(radians(use_degree)))
print(sqrt(ans))

Measured memory_bytes: 9532
N = int(input())
T , A = map(int, input().split())
H = list(map(int, input().split()))

x = (T - A) / 0.006
dif = 10 ** 5
for i in H:
    v = abs(x - i)
    if v < dif:
        dif = v
        ans = H.index(i) + 1

print(ans)

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

constexpr int max_h = 100, max_w = 100, inf = 1e9;

struct Edge
{
    int dest, id, side;
    // weights[id][side] its weight of the edge
};

int h, w, s, t;
bool visited[max_h + max_w + 2];
string pond[max_h];
vector< array< int, 2 > > weights;
vector< Edge > graph[max_h + max_w + 2];

void add_edge(const int p, const int q, const int weight = 1, const bool directed = false)
{
    graph[p].push_back({q, (int)weights.size(), 0});
    graph[q].push_back({p, (int)weights.size(), 1});
    weights.push_back({weight, directed? 0 : weight});
}

vector< Edge > path;

int dfs(const int v, const int amount = inf)
{
    visited[v] = true;
    if (v == t)
        return amount;
    for (const auto& edge : graph[v])
        if (not visited[edge.dest] and weights[edge.id][edge.side])
        {
            path.push_back(edge);
            int returned_amount = 0;
            if ((returned_amount = dfs(edge.dest, min(amount, weights[edge.id][edge.side]))))
                return returned_amount;
            path.pop_back();
        }
    return 0;
}

int flow()
{
    int result = 0;
    int amount = 0;
    while ((amount = dfs(s)))
    {
        //cerr << "found flow: " << amount << '\n';
        for (const auto& edge : path)
        {
            //if (edge.dest == s)
            //    cerr << 's' << ' ';
            //if (edge.dest == t)
            //    cerr << 't' << ' ';
            //if (1 <= edge.dest and edge.dest <= h)
            //    cerr << "row: " << edge.dest - 1 << ' ';
            //if (h + 1 <= edge.dest and edge.dest <= h + w)
            //    cerr << "column: " << edge.dest - h - 1 << ' ';
            weights[edge.id][edge.side] -= amount;
            weights[edge.id][1 - edge.side] += amount;
        }
        //cerr << '\n';
        result += amount;
        path.clear();
        for (int i = 0; i < h + w + 2; ++i)
            visited[i] = false;
    }
    return result;
}

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

    cin >> h >> w;
    s = 0; t = h + w + 1;

    for (int i = 0; i < h; ++i)
        cin >> pond[i];

    for (int i = 0; i < h; ++i)
        for (int j = 0; j < w; ++j)
        {
            if (pond[i][j] == 'S')
            {
                add_edge(s, 1 + i, inf, true);
                add_edge(s, 1 + h + j, inf, true);
            }
            if (pond[i][j] == 'T')
            {
                add_edge(1 + i, t, inf, true);
                add_edge(1 + h + j, t, inf, true);
            }
            if (pond[i][j] == 'o')
                add_edge(1 + i, 1 + h + j);
        }

    int result = flow();
    cout << (result >= inf? -1 : result) << '\n';
}


Measured memory_bytes: 3916
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int A = Integer.parseInt(scanner.next());
        int B = Integer.parseInt(scanner.next());
        int C = Integer.parseInt(scanner.next());
        int D = Integer.parseInt(scanner.next());

        scanner.close();

        int abArea = A * B;
        int cdArea = C * D;

        int maxArea = Math.max(abArea, cdArea);
        System.out.println(maxArea);
    }
}


Measured memory_bytes: 21844
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int A = Integer.parseInt(sc.next());
		int B = Integer.parseInt(sc.next());
		sc.close();

		int sa = B-A-1;
		if(sa % 2 != 0) {
			System.out.println("Alice");
		}else {
			System.out.println("Borys");
		}
	}

}


Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>

int main(int argc, char *argv[]){
    int N;
    std::cin >> N;
    std::vector<int> A(N);
    for(auto &a : A){
        std::cin >> a;
    }
    std::vector<int> student(N);
    std::iota(student.begin(),student.end(),0);
    std::sort(student.begin(),student.end(),
        [&A](const auto &lhs, const auto &rhs){
            return A[lhs] < A[rhs];
        });
    for(const auto &s : student){
        std::cout << (s+1) << " ";
    }
    std::cout << std::endl;
    return 0;
}


Measured memory_bytes: 1664
#include<iostream>
#include<cstdio>
using namespace std;
int n,m;
char a[55][55];
int dx[9]={0,1,1,1,0,0,-1,-1,-1};
int dy[9]={0,1,0,-1,1,-1,1,0,-1};
int main()
{
	cin>>n>>m;
	for(int i=1; i<=n; i++)
	{
		for(int j=1; j<=m; j++)
		{
			cin>>a[i][j];
		}
	}
	for(int i=1; i<=n; i++)
	{
		for(int j=1; j<=m; j++)
		{
			if(a[i][j]=='#'){
				cout<<'#';continue;
			}
			int sum=0;
			for(int k=1; k<=8; k++)
			  if(a[i+dx[k]][j+dy[k]]=='#') sum++;
			cout<<sum;
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
#define INF 1e9
#define All(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;


int main() {
  int a,b,c,x;
  cin>>a>>b>>c>>x;
  int ans=0;
  for(int i=0;i<=a;i++){
    for(int j=0;j<=b;j++){
      int sum=x - 500 * i - 100 * j;
      //cout<<x<<endl;
      if(sum >= 0 && sum % 50 == 0 && sum / 50 <= c){
        ans++;
      }
    }
  }
  cout<<ans<<"\n";

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head

const int N = 1e6+10;
int n, a[N];

int main() {
	scanf("%d", &n);
	REP(i,1,n) scanf("%d", a+i);
	sort(a+1,a+1+n,greater<int>());
	REP(i,1,n) {
		int j = i;
		while (j<n&&a[j+1]==a[i]) ++j;
		if ((j-a[j])%2&&(i-1<=a[j]&&a[j]<=j||a[j+1]<=j&&j<=a[j])) return puts("First"),0;
		i = j;
	}
	puts("Second");
}









Measured memory_bytes: 640
#include<stdio.h>
#include<iostream>
#include<cmath>
#include<string>
#include<cassert>
using namespace std;
#define N 4
#define N2 16
#define LIMIT 100

static const int dx[4] = {0, -1, 0, 1};
static const int dy[4] = {1, 0, -1, 0};
static const char dir[4] = {'r', 'u', 'l', 'd'};
int MDT[N2][N2];

struct Puzzle { int f[N2], space, MD; };

Puzzle state;
int limit;
int path[LIMIT];

int getAllMD(Puzzle pz) {
  int sum = 0;
  for ( int i = 0; i < N2; i++ ) {
    if ( pz.f[i] == N2 ) continue;
    sum += MDT[i][pz.f[i] - 1];
  }
  return sum;
}

bool isSolved() {
  for ( int i = 0; i < N2; i++ ) if ( state.f[i] != i + 1 ) return false;
  return true;
}


bool dfs(int depth, int prev) {
  if ( state.MD == 0 ) return true;
  if ( depth + state.MD > limit ) return false;

  int sx = state.space / N;
  int sy = state.space % N;
  Puzzle tmp;

  for ( int r = 0; r < 4; r++ ) {
    int tx = sx + dx[r];
    int ty = sy + dy[r];
    if ( tx < 0 || ty < 0 || tx >= N || ty >= N ) continue;
    if ( max(prev, r)-min(prev, r) == 2 ) continue;
    tmp = state;
    state.MD -= MDT[tx * N + ty][state.f[tx * N + ty] - 1];
    state.MD += MDT[sx * N + sy][state.f[tx * N + ty] - 1];
    swap(state.f[tx * N + ty], state.f[sx * N + sy]);
    state.space = tx * N + ty;
    if ( dfs(depth + 1, r) ) { path[depth] = r; return true; }
    state = tmp;
  }

  return false;
}

string iterative_deepening(Puzzle in) {
  in.MD = getAllMD(in);

  for ( limit = in.MD; limit <= LIMIT; limit++ ) {
    state = in;
    if ( dfs(0, -100) ) {
      string ans = "";
      for ( int i = 0; i < limit; i++ ) ans += dir[path[i]];
      return ans;
    }
  }

  return "unsolvable";
}

int main() {
  for ( int i = 0; i < N2; i++ )
    for ( int j = 0; j < N2; j++ )
      MDT[i][j] = abs(i / N - j / N) + abs(i % N - j % N);

  Puzzle in;

  for ( int i = 0; i < N2; i++ ) {
    cin >> in.f[i];
    if ( in.f[i] == 0 ) {
      in.f[i] = N2;
      in.space = i;
    }
  }
  string ans = iterative_deepening(in);
  cout << ans.size() << endl;

  return 0;
}


Measured memory_bytes: 3192
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#define ll long long	
using namespace std;
int main()
{
	ll n;
	cin >> n;
	if (n % 2 == 0)
		cout << n;
	else
		cout << 2 * n;
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

const int MAX_N = 100010;

int par[MAX_N];
int Rank[MAX_N];
int size;

void init(int n) {
    for (int i = 0; i < n; i++) {
        par[i] = i;
        Rank[i] = 0;
    }
    size = n;
}

int find(int x) {
    if (par[x] == x) {
        return x;
    } else {
        return par[x] = find(par[x]);
    }
}

void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;

    size--;
    if (Rank[x] < Rank[y]) {
        par[x] = y;
    } else {
        par[y] = x;
        if (Rank[x] == Rank[y]) {
            Rank[x]++;
        }
    }
}
bool same(int x, int y) {
    return find(x) == find(y);
}
int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    int p[100010];
    init(N);
    rep(i, N) cin >> p[i];
    rep(i, N) p[i]--;
    rep(i, M) {
        int s, t; cin >> s >> t;
        s--; t--;
        unite(s, t);
    }
    multiset<pair<int, int>> s;
    rep(i, N) {
        s.insert({find(i), p[i]});
        s.insert({find(i), i});
    }
    int ans = 0;
    rep(i, N) {
        if (s.count({find(i), p[i]}) == 2) ans++;
        //cout << find(i) << " " << p[i] << "->" << s.count({find(i), p[i]})  << endl;
    }
    cout << ans << endl;
    

    return 0;
}


Measured memory_bytes: 10752
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let a = read::<usize>();
    let b = read::<usize>();
    let c = read::<usize>();
    let ans = [a + b, b + c, c + a].iter().cloned().min().unwrap();
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define oo 0x3f3f3f3f

int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll x,k,d;
    cin>>x>>k>>d;

    ll st = min(abs(x)/d, k);
    ll res = abs(x)+d;

    for(ll i=st; i<=st+1; i++){
        ll pos = x + (x > 0 ? -1 : 1)*st*d;
        ll left = (k-st)%2;
        if(left)pos+=(pos > 0 ? -1 : 1)*d;
        res=min(res, abs(pos));
    }
    cout<<res;
}


Measured memory_bytes: 3648
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;

int main() {
	char c[1001];
	int i, sum = 0;
	long long x;
	while (1) {
		cin >> c;
		if (c[0] == '0')break;
		for (i = 0; i < strlen(c); i++) {
			sum += c[i] - '0';
		}
		cout << sum << endl;
		sum = 0;
	}
	return 0;
}

Measured memory_bytes: 1140
#include <bits/stdc++.h>
using namespace std;
long long b[5010];
long long c[5010];
int main()
{
	
	long long n;
	cin >> n;
	for(long long i = 0; i < n ;i++){
		int t;
		cin >> t;
		c[t]++;
	}
	for(long long i = 1000; i >= 0; i--){
		b[i] = b[i + 1] + c[i];
	}
	long long ans = 0;
	for(int i = 1; i <= 1000; i++){
		ans += c[i] * (c[i] - 1) * (c[i] - 2) / 6;	
		ans += c[i] * (c[i] - 1) / 2 * (b[0] - b[2 * i] - c[i]);
	}
	for(long long i = 1; i <= 1000; i++){
		for(long long j = i + 1; j <= 1000; j++){
			ans += c[i] * c[j] * (b[j + 1] - b[i + j]);
		}
	}
	cout << ans <<endl;
	return 0;
}

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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;
// const int mod = 998244353;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


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

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

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

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

int main() {
  int N;
  cin >> N;
  vector< int > A(N);
  cin >> A;
  int64 ret = 1000;
  for(int i = 1; i < N; i++) {
    if(A[i - 1] < A[i]) {
      int64 buy = ret / A[i - 1];
      ret -= buy * A[i - 1];
      ret += buy * A[i];
    }
  }
  cout << ret << "\n";
}



Measured memory_bytes: 3652
#include<stdio.h>

int main()
{
  	int k;
	int a[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  	scanf("%d",&k);
  	printf("%d\n",a[k-1]);
   	return 0;
}


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

using namespace std;

typedef long long LL;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

int main(){
	int N,M; cin >> N >> M;
	vector<vector<int>> V(N+1);
	vector<int> c(N+1,0),ans(N+1,0);
	repp(i,0,N-1+M){
		int A,B; cin >> A >> B;
		V[A].push_back(B);
		++c[B];
	}
	queue<int> Q;
	repp(i,1,N+1) if(c[i] == 0) Q.push(i);
	while(!Q.empty()){
		int p = Q.front(); Q.pop();
		for(auto u : V[p]){
			ans[u] = p;
			--c[u];
			if(c[u] == 0) Q.push(u);
		}
	}
	repp(i,1,N+1) cout << ans[i] << endl;
	return 0;
}


Measured memory_bytes: 7040
require 'prime'

class Array
  def upper_bound(num)
    a = 0
    b = size

    while a < b
      c = ( a + b ) / 2

      if num < at(c)
        b = c
      else
        a = c+1
      end
    end

    at(b)
  end

  def lower_bound(num)
    a = 0
    b = size

    while a < b
      c = ( a + b ) / 2

      if num <= at(c)
        b = c
      else
        a = c + 1
      end
    end

    at(b-1)
  end
end

class Solver
  def initialize
    prime_list = Prime::instance.take(25000)

    loop do
      num = gets

      break unless num

      num = num.chomp.to_i

      puts [ prime_list.lower_bound(num), prime_list.upper_bound(num) ].join(' ')
    end
  end
end

Solver.new

Measured memory_bytes: 6444
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

class Main {
    int H, W;
    vector<string> S;
    vector<vector<int>> used;
    int di[4] = {1, 0, -1, 0};
    int dj[4] = {0, 1, 0, -1};

    P dfs(int i, int j) {
        used[i][j] = 1;
        int res[2] = {0};
        res[S[i][j] == '.'] = 1;
        REP(k, 4) {
            int a = i + di[k];
            int b = j + dj[k];
            if (a >= 0 && a < H && b >= 0 && b < W) {
                if (used[a][b] > 0) continue;

                if (S[a][b] != S[i][j]) {
                    int black, white;
                    tie(black, white) = dfs(a, b);
                    res[0] += black;
                    res[1] += white;
                }
            }
        }
        return {res[0], res[1]};
    }

    void input() {
        cin >> H >> W;
        S.resize(H);
        REP(i, H) { cin >> S[i]; }
    }
    void output() {
        used.assign(H, vector<int>(W));
        ll res = 0;
        REP(i, H) {
            REP(j, W) {
                if (used[i][j]) continue;
                ll black, white;
                tie(black, white) = dfs(i, j);
                res += black * white;
            }
        }
        cout << res << endl;
    }

public:
    Main() {
        input();
        output();
    }
};

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

    Main();

    return 0;
}


Measured memory_bytes: 18880
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    l = list(map(int, input()))
    n = len(l)
    dp = [[0]*2 for i in range(n+1)]
    dp[0][0] = 1
    for i in range(n):
        ni = i+1
        for j in range(2):
            x = 1 if j else l[i]
            for d in range(x+1):
                nj = j or d < l[i]
                if d:
                    dp[ni][nj] += 2*dp[i][j]
                else:
                    dp[ni][nj] += dp[i][j]
                dp[ni][nj] %= mod
    print(sum(dp[n])%mod)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 56668
#include <iostream>
#include <string>
#include <cmath>
#include <sstream>
#include <iomanip>

using namespace std;

int main(int argc, char* argv[]) {

	int a,b,c;
	int ans;

	cin >> a >> b >> c;

	if(a==b && b==c){
		ans=1;
	}else if((a==b && b!=c) || (a==c && c!=b) || (b==c && c!=a)){
		ans=2;
	}else{
		ans=3;
    }

	cout << ans << endl;

	return 0;

}

Measured memory_bytes: 256
a, b, k = map(int,input().split())
for i in range(k):
    if i%2 == 0:
        if a%2:
            a -= 1
        b += a // 2
        a //= 2
    else:
        if b % 2:
            b -= 1
        a += b // 2
        b //= 2

print(a, b)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=(a);i<=(b);++i)
#define rv(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
typedef long long LL;
const int M = 120000;
const int inf = 0x3f3f3f3f;
int n,m,v,p;
int a[M];
LL sum[M]={0};
bool exceed=0;
int need;
int cal(int l,int r,int num) {
	if(0==num) return a[r];
	a[r+1]=2*inf;
	int lo=l,hi=r+1;
	LL all=1ll*num*m;
	for(int mid=(lo+hi)>>1;lo<hi;mid=(lo+hi)>>1){
		LL now=all+sum[mid]-sum[l-1];
		LL val=now/(mid-l+1);
		LL ex=now%(mid-l+1);
		LL right=val+!!ex;
		if(right>a[mid+1])
			lo=mid+1;
		else if(right<a[mid])
			hi=mid;
		else {
			if(val>a[l]+m) {
				exceed=1;
				break;
			}
			return max((int)right,a[r]);
		}
	}
	return need;
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>n>>m>>v>>p;
	fo(i,1,n) cin>>a[i];
	sort(a+1,a+1+n);
	fo(i,1,n) {
		sum[i]=sum[i-1]+a[i];
	}
	int ans=p;
	rv(i,n-p,1) {
		int extra = max(0,v-(p-1)-i);
		if(!exceed) need=cal(i+1,n-p+1,extra);
		if(a[i]+m<need) break;
		++ans;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1408
import Control.Monad
import Control.Applicative
import Data.List

readInt :: IO Int
readInt = readLn

main :: IO ()
main = do
  [n, t'] <- (map read . words) <$> getLine
  lines <- replicateM n getLine
  let cts = map (map read . words) lines
  let cands = [c | [c, t] <- cts, t <= t']
  putStrLn $ if cands == [] then "TLE" else show $ minimum cands


Measured memory_bytes: 892
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define EACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
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 (b<a) { a=b; return 1; } return 0; }
template<class Value>using vec = vector< Value >;
using ll = long long;
using P = pair< long long, long long >;
#define fi first
#define se second
#define el endl
#pragma endregion
void Main();

int main(){
    std::cin.tie(nullptr);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}

bool f(string& S, int n){
    bool ret = true;
    REP(i, n){
        if(S[i] != S[i+n]){
            ret = false;break;
        }
    }
    return ret;
}

void Main(){
    ll A, B, C;
    cin >> A >> B >> C;
    REP(i, 1000000){
        if((B*i+C)%A == 0){
            cout << "YES" << el;return;
        }
    }
    cout << "NO" << el;return;
}



Measured memory_bytes: 3548
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;
 
public class Hello{
    public static void Main(){
        int[] num = inta();
        WriteLine(Min(num[1] / num[0] , num[2]));
        
    
    
    }
    //各種読取
    static string rstr(){
        return ReadLine();
    }
    static int rint(){
        return int.Parse(ReadLine());
    }
    static long rlong(){
        return long.Parse(ReadLine());
    }
    static string[] stra(){
        return ReadLine().Split(' ');
    }
    static int[] inta(){
        string[] read_str_array = ReadLine().Split(' ');
        int[] return_int_array = new int[read_str_array.Length];
        for(int countup_i=0;countup_i<read_str_array.Length;countup_i++){
            return_int_array[countup_i] = int.Parse(read_str_array[countup_i]);
        }
        return return_int_array;
    }
    static int[,] inta2(int num_array,int in_array){
        int[,] int_array2 = new int[num_array,in_array];
        for(int i=0;i<num_array;i++){
            int[] temp_array = inta();
            for(int j=0;j<in_array;j++){
                int_array2[i,j] = temp_array[j];
            }
        }
        return int_array2;
    }
    static long[] longa(){
        string[] read_str_array = ReadLine().Split(' ');
        long[] return_long_array = new long[read_str_array.Length];
        for(long countup_i=0;countup_i<read_str_array.Length;countup_i++){
            return_long_array[countup_i] = long.Parse(read_str_array[countup_i]);
        }
        return return_long_array;
    }
    static double[] doublea(){
        string[] read_str_array = ReadLine().Split(' ');
        double[] return_double_array = new double[read_str_array.Length];
        for(long countup_i=0;countup_i<read_str_array.Length;countup_i++){
            return_double_array[countup_i] = long.Parse(read_str_array[countup_i]);
        }
        return return_double_array;
    }
    // A/B小数点以下切上
    static long divideup(long divided,long divid){
        long temp_divide = divided/divid;
        if(divided % divid > 0){
            temp_divide++;
        }
        return temp_divide;
    }
    static long GCD(long a,long b){
        if(a < b){
            long temp = a;
            a = b;
            b = temp;
        }
        if(a % b == 0){ return b; }
        else{
            long temp = b;
            b = a%b;
            a = temp;
            return GCD(a,b);
        }
    }
    static long LCM(long a,long b){
        return a * b / GCD(a,b);
    }
}
//知見
// (string) hogestr -> (char[]) hoge
    // char hoge = hogestr.ToCharArray();
// (char[]) hoge -> (string) hogestr
    // string hoge = new string(hoge);
// Hashtable ×  Dictionary ○
// Dictionary hoge<string,int>
    // hoge.ContainsKey(string) -> return boolean
    // hoge[string] -> return int
    // hoge[int] -> CE
// Dictionary hoge<int1,int2>
    // hoge<int1,int2>: hoge[int1] -> return int2
    // KeyValuePair<int,int> k <-> k.Key == int1 / k.Value == int2
// SortedDictionary() > SortedList() ???
// キュー　-> 幅優先 ???
// スタック -> 深さ優先 ???

Measured memory_bytes: 11092
import Control.Applicative
import Control.Monad
import Data.List

multiplyMatirix :: [[Int]] -> [[Int]] -> [[Int]]
multiplyMatirix a b = map (\v -> map (sum . zipWith (*) v) (transpose b)) a

main :: IO ()
main = do
    [n, m, l] <- (map (read :: String -> Int) . words) <$> getLine
    a <- replicateM n ((map read . words) <$> getLine)
    b <- replicateM m ((map read . words) <$> getLine)
    putStr $ unlines $ map unwords $ (map (map show)) $ multiplyMatirix a b

Measured memory_bytes: 12404
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long n;cin>>n;
    double x=sqrt(n);
    long long y=sqrt(n);
    if((x-y)==0)
    cout<<n<<endl;
    else {
        long long i=n;
        while(true){
            i--;
        double x=sqrt(i);
           long long y=sqrt(i);
            if((x-y)==0){
                cout<<i<<endl;
                break;
            }
        }
    }

    return 0;
}






Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    int n,m,b,cur=0,i;
    ll a;
    cin>>n>>m;
    vector<pair<ll,int>> p;
    for (i=0;i<n;i++)
    {
        cin>>a>>b;
        p.pb(mp(a,b));
    }
    sort(p.begin(),p.end());
    ll ans=0;
    while (m)
    {
        if (m<=p[cur].ss)
        {
            ans+=m*p[cur].ff;
            m=0;
        }
        else
        {
            ans+=p[cur].ss*p[cur].ff;
            m-=p[cur].ss;
        }
        cur++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 2420
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <unordered_map>

#define REP(i, n) for (int i = 0; i < n; i++)
#define ll long long int

using namespace std;

int n, a, b, c;

int solver(int *l, int size)
{
  int mp = 10000000;
  if (size > 3)
  {
    REP(i, size)
    {
      for (int j = i + 1; j < size; j++)
      {
        int x[8] = {};
        x[0] = l[i] + l[j];
        int index = 1;
        REP(k, size)
        {
          if (k == i || k == j)
          {
            continue;
          }
          x[index] = l[k];
          index++;
        }
        int tmp = solver(x, size - 1) + 10;
        if (tmp < mp)
        {
          mp = tmp;
        }
      }
    }
  }
  int suba[8] = {};
  int subb[8] = {};
  int subc[8] = {};

  REP(i, size)
  {
    suba[i] = abs(a - l[i]);
    subb[i] = abs(b - l[i]);
    subc[i] = abs(c - l[i]);
  }

  REP(i, size)
  {
    REP(j, size)
    {
      REP(k, size)
      {
        if (k == i || k == j || i == j)
        {
          continue;
        }
        if (mp > suba[i] + subb[j] + subc[k])
        {
          mp = suba[i] + subb[j] + subc[k];
        }
      }
    }
  }

  return mp;
}

int main()
{
  int l[8];
  cin >> n >> a >> b >> c;
  REP(i, n)
  {
    cin >> l[i];
  }

  int mp = solver(l, n);
  cout << mp << endl;
}


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

int main() {
  int N;
  string S;
  cin >> N >> S;
  int ans = 0;
  for (int i = 0; i < N-1; i++) {
    vector<int> v1(26, 0), v2(26, 0);
    for (int j = 0; j < N; j++) {
      if (j <= i) v1[S[j] - 'a'] = 1;
      else v2[S[j] - 'a'] = 1;
    }
    int count = 0;
    for (int j = 0; j < 26; j++) {
      if (v1[j] && v2[j]) count++;
    }
    ans = max(ans, count);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <list>
#include <map>
#include <cmath>
#include <string>
#include <cstdio>
#include <vector>
 
using namespace std;

typedef long long ll;
typedef long double ld;
#define L(ID) ((ID*2)+1)
#define R(ID) ((ID*2)+2)
#define M(L,R) ((L+R)/2)
#define forr(start,end) for(int i = start; i < end; i++)
#define gap ' '
 
const int MAXN = 2e5+5;

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


int main() {
	string s;
	cin >> s;
	for(int i = 1; i <= s.length(); ++i){
		if(i % 2){
			cout << s[i-1];
		}
	}
	cout << endl;

    return 0;
}	

Measured memory_bytes: 512
#include <stdio.h>

int main(void)
{
    int number, pm, pe, pj, temp;
    while(1){
        scanf("%d", &number);
        if (number == 0){
            break;
        }
        for (int i = number; i > 0; i--){
            scanf("%d %d %d", &pm, &pe, &pj);
            if (pm == 100|| pe == 100|| pj == 100|| (pe + pm)/2 >= 90||(pe + pm + pj)/3 >= 80 ){
                printf("A\n");
            }else if((pe + pm + pj)/3 >= 70||((pe + pm + pj)/3 >= 50 && (pe >= 80|| pm >= 80))) {
                printf("B\n");
            }else{
                printf("C\n");
            }
        }
    }
    return 0;
}
        
    

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

int main(){
  int N;
  cin >> N;
  map<string,int> M;
  for(int i=0;i<N;i++){
    string s;
    cin >> s;
    M[s]++;
  }
  
  cout << "AC x " << M["AC"] << endl;
  cout << "WA x " << M["WA"] << endl;
  cout << "TLE x " << M["TLE"] << endl;
  cout << "RE x " << M["RE"] << endl;
  return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
#define task "tst"
using namespace std;
const ll N = 1e5 + 9;
const ll mod = 1e9 + 7;
typedef pair<ll,ll> LL;
set<ll> s;
ll n,a[N],i,ans[N];
unordered_map<ll,LL> mp;
int main(){
    //ios_base::sync_with_stdio(0);
    //cin.tie(0), cout.tie(0);
    if (fopen(task".inp", "r")){
        freopen(task".inp", "r", stdin);
        //freopen(task".out", "w", stdout);
    }
    s.insert(0);
    cin>>n;
    for (i = 1;i <= n;i++){
        cin>>a[i]; s.insert(a[i]);
    }
    for (i = n;i > 0;i--){
        mp[a[i]].fs = i;
        mp[a[i]].sc++;
    }
    mp[0].fs = mp[0].sc = 0;
    while(s.size() > 1){
        //cout<<1;
        ll t = *prev(s.end()); s.erase(t);
        ll p = *prev(s.end()),q = t - p;
        ll pos = mp[t].fs;
        //cout<<t<<" "<<pos<<"\n";
        ans[pos] += q*(mp[t].sc);
        mp[p].fs = min(mp[t].fs,mp[p].fs); mp[p].sc += mp[t].sc;
    }
    for (i = 1;i <= n;i++) cout<<ans[i]<<"\n";
}



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

int main(void){
	int debt=100000;
	int n;
	cin >> n;
	for(int i=0; i<n; i++){
		debt *= 1.05;
		if(debt%1000!=0) debt=(debt/1000)*1000+1000;
	}
	cout << debt << endl;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    istream& in(cin);
    ostream& out(cout);
    int n,a;
    in>>n;
    set<int> st;
    fr(i,n) in>>a,st.emplace(a);
    cout<<(st.size()==n?"YES":"NO")<<endl;
}

Measured memory_bytes: 9728
/*
ID: learnin7
TASK: test
LANG: C++                 
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include<bits/stdc++.h>

/*  Macros from Endagorion */
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;


int main(){
        
    ios_base::sync_with_stdio(0);
    
    //ofstream fout ("test.out");
    //ifstream fin ("test.in");
    //fin >> a >> b;
    //fout << a+b << endl;
    int n;
    cin>>n;
    int cnt_max = INT_MIN;
    int num_max = INT_MIN;
    if(n==1){
        cout<<1<<endl;
        return 0;
    }
    for(int i=2;i<=n;i++){
        int num=i;
        int cnt=0;
        while(num%2==0){
            cnt++;
            num /= 2;
        }
        if(cnt>cnt_max){
            cnt_max = cnt;
            num_max = i;
        }
    }
    cout<<num_max<<endl;
    return 0;
}



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

using namespace std;

int diff(string a, string b) {
  int d = 0;
  for(int i = 0; i < (int)a.size(); i++) {
    if(a[i]!=b[i]) d++;
  }
  return d;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s, t;
  cin >> s >> t;
  int n = s.size(), m = t.size();
  int ans = 2e9;
  for(int i = 0; i <= (n-m); i++) {
    string cur = s.substr(i, m);
    ans = min(ans, diff(cur, t));
  }
  cout << ans << '\n';
  return 0;
}


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

typedef long long ll;

typedef pair <int, int> ii;

const int mod = 1000000007;
const int Maxn = 200005;
const int Inf = 1000000007;

int fac[Maxn], inv[Maxn];
int n, x, y;
ii mn[2];
vector <int> seq[Maxn];
int cnt[Maxn];
int res = 1;

int toPower(int a, int p)
{
    int res = 1;
    while (p) {
        if (p & 1) res = ll(res) * a % mod;
        p >>= 1; a = ll(a) * a % mod;
    }
    return res;
}

int Inv(int a) { return toPower(a, mod - 2); }

int C(int n, int k)
{
    if (n < 0 || k < 0 || k > n) return 0;
    return ll(fac[n]) * inv[k] % mod * inv[n - k] % mod;
}

int main()
{
    fac[0] = inv[0] = 1;
    for (int i = 1; i < Maxn; i++) {
        fac[i] = ll(i) * fac[i - 1] % mod;
        inv[i] = Inv(fac[i]);
    }
    mn[0] = mn[1] = ii(Inf, -1);
    scanf("%d %d %d", &n, &x, &y);
    for (int i = 0; i < n; i++) {
        int c, w; scanf("%d %d", &c, &w);
        seq[c].push_back(w);
    }
    for (int i = 0; i < Maxn; i++) {
        sort(seq[i].begin(), seq[i].end());
        if (!seq[i].empty())
            if (seq[i][0] < mn[0].first) mn[1] = mn[0], mn[0] = ii(seq[i][0], i);
            else if (seq[i][0] < mn[1].first) mn[1] = ii(seq[i][0], i);
    }
    int cur = 0;
    for (int i = 0; i < Maxn; i++) if (!seq[i].empty()) {
        int got = mn[0].second == i? mn[1].first: mn[0].first;
        if (got + seq[i][0] <= y) {
            cnt[i]++;
            for (int j = 1; j < seq[i].size(); j++)
                if (seq[i][0] + seq[i][j] <= x || got + seq[i][j] <= y)
                    cnt[i]++;
            res = ll(res) * C(cur + cnt[i], cnt[i]) % mod;
            cur += cnt[i];
        }
    }
    printf("%d\n", res);
    return 0;
}


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

int main(){
  string s,s1="",s2="";
  int c1=0,c2=0,c=0;
  cin >> s;
  for(int i=0;i<(s.size()-1)/2;i++){
    s1+=s.at(i);
  }
  for(int i=(s.size()+1)/2;i<s.size();i++){
    s2+=s.at(i);
  }
  for(int i=0;i<double(s.size()-1)/2;i++){
    if(s.at(i)==s.at(s.size()-1-i)){
      continue;
    }
    else{
      c=1;
      break;
    }
  }

  for(int i=0;i<double(s1.size()-1)/2;i++){
    if(s1.at(i)==s1.at(s1.size()-1-i)){
      continue;
    }
    else{
      c1=1;
      break;
    }
  }
  for(int i=0;i<double(s2.size()-1)/2;i++){
    if(s2.at(i)==s2.at(s2.size()-1-i))
      continue;
    else{
      c2=1;
      break;
    }
  }
  if(c==0&&c1==0&&c2==0)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
  
}


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

int main(){
    
    int S;
    
    cin >> S;
    
    int h = S / 3600;
    int m = (S % 3600) / 60;
    int s = (S % 3600) % 60;
    
    cout << h << ":" << m << ":" << s << endl;

    return 0;
}


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

using namespace std;

int main()
{
    int data_num;

    while (cin >> data_num) {
        if (data_num == 0) break;

        int player1_ans = 0;
        int player2_ans = 0;
        
        for (int i = 0; i < data_num; ++i) {
            int data1, data2;
            
            cin >> data1 >> data2;
            
            if (data1 > data2) {
                player1_ans += data1 + data2;
            } else if (data1 == data2) {
                player1_ans += data1;
                player2_ans += data2;
            } else {
                player2_ans += data1 + data2;
            }

        }

        cout << player1_ans << " " << player2_ans << endl;

    }
    
    return 0;
}

Measured memory_bytes: 1156