akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);cout.precision(20);}} fast;

/* define */
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) (upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X))
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto xXx:v)cerr<<xXx<<' ';cerr<<endl;
#define Yes(X) if(X){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define YES(X) if(X){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define ctoi(C) (C-'0')
#define pow2(x) ((long long)((long long)1<<x))

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int,int>;
using pl = pair<long long,long long>;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1,0,-1,0};
const long long dy[] = {0,1,0,-1};
const long long dx8[] = {1,1,0,-1,-1,-1,0,1};
const long long dy8[] = {0,1,1,1,0,-1,-1,-1};
const long long dx9[] = {1,1,0,-1,-1,-1,0,1,0};
const long long dy9[] = {0,1,1,1,0,-1,-1,-1,0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
long long max(long long x,int y){return max(x,(long long)y);}
long long max(int x,long long y){return max((long long)x,y);}
long long min(long long x,int y){return min(x,(long long)y);}
long long min(int x,long long y){return min((long long)x,y);}

/* liblary */



/* main */

signed main(){
    ll N,C;
    cin >> N >> C;
    vector<tuple<ll,ll,ll>> v,v2;
    FOR(i,0,N){
        ll s,t,c;
        cin >> s >> t >> c;
        v2.push_back(make_tuple(c,s,t));
    }
    sort(ALL(v2));
    v.push_back(v2[0]);
    FOR(i,1,N){
        if(get<0>(v[v.size()-1]) == get<0>(v2[i])){
            if(get<2>(v[v.size()-1]) == get<1>(v2[i])){
                get<2>(v[v.size()-1]) = get<2>(v2[i]);
                continue;
            }
        }
        v.push_back(v2[i]);
    }
    ll imos[200019] = {0};
    FOR(i,0,v.size()){
        
        imos[2*get<1>(v[i])-1] += 1;
        imos[2*get<2>(v[i])] -= 1;
    }
    FOR(i,0,200018)imos[i+1] += imos[i];
    ll ans = 0;
    FOR(i,0,200019)chmax(ans,imos[i]);
    cout << ans << endl;
}

Measured memory_bytes: 8560
#include <iostream>

using namespace std;

int main() {
	int N, X, Y;
	int* R;
	int buf, buf2;
	cin >> N;
	cin >> X;
	cin >> Y;

	R = (int*)malloc((N - 1) * sizeof(int));
	for (int h = 0; h < N - 1; h++) R[h] = 0;

	X--;
	Y--;

	for (int i = 0; i < N ; i++) {
		for (int j = N-1; j > i; j--) {
			buf2 = j - i;

			if (i <= X) {
				if (j >= Y) {
					buf = (X - i) + 1 + (j - Y);
				}
				else {
					buf = (X - i) + 1 + (Y - j);
				}
			}
			else {
				buf = (i - X) + 1;
				if (Y - j > 0) buf += (Y - j);
				else buf += (j - Y);
			}

			if (buf > buf2) R[buf2 - 1]++;
			else R[buf - 1]++;
			
		}
	}

	for (int k = 0; k < N - 1; k++)  cout << R[k] << endl;

	return 0;
}


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

#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ll long long
#define vi vector< int > 
#define pii pair< int, int >
#define mii map< int , int > 
#define F(start,stop) for(int i=start; i<stop; i++)
#define FRev(start,stop) for(int i=start; i>=stop; i--)
#define MOD1 1000000007
#define MOD2 998244353

int main()
{

	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

	IOS

	int n,x;
	cin >> x >> n;


	int map[105] = {0};
	int arr[n];
	F(0,n){ 
		cin >> arr[i];
		map[arr[i]]++;
	}


	int min_dif = INT_MAX;
	int ans = -1;

	for(int i=0; i<105; i++){
		if(map[i] == 0){
			if(abs(x - i) < min_dif){
				min_dif = abs(x-i);
				ans = i;
			}
		}
	}
	cout << ans << endl;

}

Measured memory_bytes: 3620
N,M,X,Y=map(int,input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
x.sort()
y.sort()
if x[-1]<y[0] and y[0]>X and x[-1]<Y:
    print('No War')
else:
    print('War')

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

int main(){
    int n;
    cin >> n;
    vector<P> d;
    rep(i,n){
        int x,y;
        cin >> x >> y;
        d.emplace_back(x,y);
    }
    vector<int> v;
    rep(i,n) v.push_back(i);
    double sum = 0;
    cout << setprecision(10);
    do{
        rep(i,n-1){
            auto p1 = d.at(v.at(i));
            auto p2 = d.at(v.at(i+1));
            double dx = abs(p2.first - p1.first);
            double dy = abs(p2.second - p1.second);
            double dis = sqrt(dx*dx + dy*dy);
            sum += dis;
        }
    }while(next_permutation(v.begin(),v.end()));
    int num = 1;
    for(int i = 1; i <= n;i++) num *= i;
    cout << sum / num << endl;
}

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


#define INF 1000000000000

signed main()
 {
int x,m;
cin>>x;
m=100;
int ans=0;
while(m<x){
  m*=1.01;
  ans++;
}
cout<<ans;

}


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

#define rep(i, n) for(int i=0; i < n; i++)
#define REP(i, n, m) for(int i=n; i < m; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

using namespace std;
using ll=long long;

const ll INF = 1LL << 60;

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


int main() {
  int x,a,b;cin>>x>>a>>b;
  int s=abs(x-a);
  int t=abs(x-b);
  cout<<(s>t?'B':'A');
}


Measured memory_bytes: 256
#pragma region template
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9 + 7, MAX = 1e18, larg = 1e5, INF = -1e9;
long long A, B, C, D, E, F, G, H, I, J, K, L, N, M, O, P, Q, R, S, T, U, V, W, x, y, z;
long long max_value = INF, max_index = -1;
long long min_value = MAX, min_index = -1;
typedef long long ll;
typedef pair<ll, ll> Pa;

int arr[200000];
int arr2[200000];
int main() {
	cin >> A >> B >> C;
	int sum = A+B+C;
	int goal = ((max(A, max(B, C))*3 - sum)%2 == 0)? max(A, max(B, C)) : max(A, max(B, C)) + 1;
	cout << (goal*3 - sum)/2;
}



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

#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define MAXX 1005

#define PI 3.14159265358979323846264338327950

#define ll  int
vector<ll> v;
ll p[MAXX];
multiset<ll> ms;
multiset<ll>::iterator it;
signed main()
{
	FAST;
	ll   h = 0, t = 0; ll ans = 0;
	ll a, b, c;
	cin >> a >>  b >> c;
	for(ll i = 1; i <= c; i++){
		if(a*i > b){
			cout << i-1;
			return 0;
		}
	}
	
	cout << c;
}

Measured memory_bytes: 256
//g++ -std=c++14 test.cpp -o test.out
//入出力：http://kaitei.net/cpp/iostream/
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
using namespace std;

long long int N,A,B;
long long int ans = 0;

void solve(){
	long long int diff = B-A;
	if(diff%2==0) ans = (diff)/2;
	else{
		if(A-1<N-B){
			ans = (A+B-1)/2;
		}else{
			ans = N-(A+B-1)/2;
		}
	}
}

int main(){
	cin >> N >> A >>B;

	solve();

	cout << ans;
	return 0;
}

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

# define M_PI           3.14159265358979323846
#define ll long long
const ll mod=1e9 +7;
vector<ll> f(200009);
int main()
{
    ll n;
    cin>>n;
    set<string> m;
    for(ll i=0;i<n;i++)
    {
        string s;
        cin>>s;
        m.insert(s);
    }
    cout<<m.size();
    return 0;
}

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

int main() {
    int n; cin >> n;
    vector<int> p(n);
    for (int &i: p) cin >> i;
    sort(p.begin(), p.end());
    int ans = 0;
    for (int i=0; i<n-1; ++i) {
        ans += p[i];
    }
    ans += p[n-1] / 2;
    cout << ans << endl;
}

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

#define sswap(x, y) { x+=y; y=x-y; x-=y; }
#define LSOne(S) ((S) & (-S))

#define EPS 1e-6
#define MOD 1000000007

#define fi first
#define se second
#define pb push_back
#define ende '\n'

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define mset(x, y) memset(&x, (y), sizeof(x))

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
	ll n, s = 0;
	cin >> n;
	for (int i = 1; i <= n; i++)
		if ((i % 3) && (i % 5)) s += i;
	cout << s << ende;
  return 0;
}


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

int main(){

    vector<vector<int>> A(3, vector<int>(3));
    for (int i = 0; i < 3; i++){
        for (int j = 0; j < 3; j++){
            cin >> A.at(i).at(j);
        }
    }

    int N;
    cin >> N;

    vector<int> b(N);
    for (int i = 0; i < N; i++){
        cin >> b.at(i);
    }

    for (int i = 0; i < 3; i++){
        for (int j = 0; j < 3; j++){
            for (int k = 0; k < N; k++){
                if (A.at(i).at(j) == b.at(k)){
                    A.at(i).at(j) = -1;
                }
            }
        }
    }

    bool bingo = false;

    if (A.at(0).at(0) == -1 && A.at(0).at(1) == -1  && A.at(0).at(2) == -1) bingo = true;
    if (A.at(1).at(0) == -1 && A.at(1).at(1) == -1  && A.at(1).at(2) == -1) bingo = true;
    if (A.at(2).at(0) == -1 && A.at(2).at(1) == -1  && A.at(2).at(2) == -1) bingo = true;
    if (A.at(0).at(0) == -1 && A.at(1).at(0) == -1  && A.at(2).at(0) == -1) bingo = true;
    if (A.at(0).at(1) == -1 && A.at(1).at(1) == -1  && A.at(2).at(1) == -1) bingo = true;
    if (A.at(0).at(2) == -1 && A.at(1).at(2) == -1  && A.at(2).at(2) == -1) bingo = true;
    if (A.at(0).at(0) == -1 && A.at(1).at(1) == -1  && A.at(2).at(2) == -1) bingo = true;
    if (A.at(2).at(0) == -1 && A.at(1).at(1) == -1  && A.at(0).at(2) == -1) bingo = true;
    
    if (bingo) cout << "Yes" << endl;
    else cout << "No" << endl;
 

}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define min(x,y) ((x<y)?x:y)
int r[10005][10005];
int e[10005][10005];
int v[10005],used[10005],prev[10005],con[10005];
int main(){
	int n,m,i,j,a,b,d,c,x,y,s1,s2;
	while(1){
		scanf("%d%d",&n,&m);
		if(n==0 && m==0)break;
		for(i=1;i<=n;i++){
			v[i]=con[i]=1000000000;
			used[i]=0;prev[i]=-1;
			for(j=1;j<=n;j++)r[i][j]=e[i][j]=1000000000;
		}
		s1=s2=0;
		for(i=0;i<m;i++){
			scanf("%d%d%d%d",&a,&b,&d,&c);
			r[a][b]=r[b][a]=d;
			e[a][b]=e[b][a]=c;
			s1+=c;
		}
		v[1]=0;con[1]=0;
		while(1){
			x=-1;
			for(i=1;i<=n;i++){
				if(used[i]==0 && (x==-1 || v[i]<v[x]))x=i;
			}
			if(x==-1)break;
			used[x]=1;
			for(i=1;i<=n;i++){
				//v[i]=min(v[i],v[x]+r[x][i]);
				if(v[x]+r[x][i]<v[i]){
					v[i]=v[x]+r[x][i];
					con[i]=con[x]+e[x][i];
					prev[i]=x;
				}else if(v[x]+r[x][i]==v[i]){
					if(e[x][i]<con[i]-con[prev[i]]){
						con[i]=con[x]+e[x][i];
						prev[i]=x;
					}
				}
			}
			//printf("v[%d]:%d\n",x,v[x]);
		}
		for(i=1;i<=n;i++){
			if(prev[i]>0 && r[prev[i]][i]<=1000){
				s2+=e[prev[i]][i];
				r[prev[i]][i]=10000;
			}
		}
		printf("%d\n",s2);
	}
	return 0;
}

Measured memory_bytes: 0
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
using namespace std;

typedef struct Node {
	int key;
	struct Node *prev, *next;
} Node;

void insert(Node *ban, int key) {
	Node *newNode = (Node *)calloc(1, sizeof(Node));
	newNode->key = key;
	newNode->prev = ban;
	newNode->next = ban->next;
	ban->next->prev = newNode;
	ban->next = newNode;
	if(ban->prev == ban) {
		ban->prev = newNode;
	}
}

void deleteNode(Node *ban, int key) {
	Node *node = ban->next;
	while(node->key != -1) {
		if(node->key == key) {
			node->prev->next = node->next;
			node->next->prev = node->prev;
			free(node);
			break;
		}
		node = node->next;
	}
}

void deleteFirst(Node *ban) {
	Node *d = ban->next->next->prev;
	ban->next->next->prev = ban;
	ban->next = ban->next->next;
	free(d);
}

void deleteLast(Node *ban) {
	Node *d = ban->prev->prev->next;
	ban->prev->prev->next = ban;
	ban->prev = ban->prev->prev;
	free(d);
}

int main() {
	Node ban = {-1, NULL, NULL};
	ban.prev = &ban;
	ban.next = &ban;
	int n;
	cin >> n;
	for (size_t i = 0; i < n; i++)
	{
		char s[20];
		int key;
		scanf("%s", s);
		if(strcmp(s, "insert") == 0) {
			scanf("%d", &key);
			insert(&ban, key);
		} else if(strcmp(s, "deleteFirst") == 0) {
			deleteFirst(&ban);
		} else if(strcmp(s, "deleteLast") == 0) {
			deleteLast(&ban);
		} else {
			scanf("%d", &key);
			deleteNode(&ban, key);
		}
	}
	Node *node = ban.next;
	while(node->key != -1) {
		if(node->next == &ban) {
			printf("%d", node->key);
		} else {
			printf("%d ", node->key);
		}
		node = node->next;
	}
	cout << endl;
	return 0;
}



Measured memory_bytes: 34368
#include<iostream>
#include<string.h>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#define ll long long int
#define ld long double
#define INF 1000000000
#define EPS 0.0000000001
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;

typedef complex<double> P;

struct L : public vector<P>{//??´???
  L(const P &a, const P &b){
    push_back(a);push_back(b);
  }
};

struct C{//???
  P c; double r;
  C(const P &c,double r): c(c),r(r){}
};

namespace std{//??????????????????
  bool operator < (const P& a,const P& b){
    return real(a)!= real(b) ? real(a) < real(b) : imag(a) < imag(b);
    //return imag(a) != imag(b) ? imag(a) < imag(b) : real(a) < real(b)
  }
  bool operator == (const P& a,const P& b){
    return a.real()==b.real()&&a.imag()==b.imag();
  }
}

double dot(P a,P b){
  return real(conj(a)*b);
}

double cross(P a,P b){
  return imag(conj(a)*b);
}

int ccw(P a, P b, P c){
  b-=a;c-=a;
  if(cross(b,c)>0)   return +1;// counter clockwise 
  if(cross(b,c)<0)   return -1;// clockwise 
  if(dot(b,c)<0)     return +2;// c-a-b on line
  if(norm(b)<norm(c))return -2;// a-b-c on line
  return 0;                    // a-c-b on lone
}

int main()
{
  double xp1,yp1,xp2,yp2;
  int q;
  int i,j;

  cin>>xp1>>yp1>>xp2>>yp2;
  cin>>q;

  P p1(xp1,yp1),p2(xp2,yp2);

  rep(i,q){
    double xp,yp;
    cin>>xp>>yp;
    P p(xp,yp);
    P t=dot(p2-p1,p-p1)/norm(p2-p1)*(p2-p1);
    P ans=p1+t;
    printf("%.10f %.10f\n",ans.real(),ans.imag());
  }

}

Measured memory_bytes: 3340
from operator import itemgetter


n, k = map(int,input().split())
info = [list(map(int, input().split())) for i in range(n)]

info = sorted(info, key = itemgetter(1), reverse = True)

selected = info[0:k]
selected_only = []
selected_chohuku = []
unselected_only = []
memo = {}
for t, d in selected:
    if t not in memo:
        memo[t] = 1
        selected_only.append(d)
    else:
        selected_chohuku.append(d)

cnt_type = len(memo)
for t, d in info[k:]:
    if t not in memo:
        memo[t] = 1
        unselected_only.append(d)


sum_select = sum(selected_chohuku) + sum(selected_only) 
ans = cnt_type*cnt_type + sum_select

unselected_only = unselected_only[::-1]
for i in range(min(len(selected_chohuku), len(unselected_only))):
    cnt_type += 1
    sum_select += unselected_only[-1]
    sum_select -= selected_chohuku[-1]
    del unselected_only[-1]
    del selected_chohuku[-1]
    tmp = cnt_type*cnt_type + sum_select
    ans = max(ans, tmp)
print(ans)

  

Measured memory_bytes: 38608
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define idfc ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
//#define ll long long
#define pb emplace_back
#define mp make_pair
#define nt _int128
#define ld long double
long double PI =3.14159265358979323846;
using ll = long long;



const ll modo=1000000000;
const ll inf=LONG_LONG_MAX;
const ll ms=(1e5)+5;


vector<int> vv[ms];
int vis[ms]={0};
int par[ms]={0};


int main()
{
    idfc;
    int n,m;
    cin>>n>>m;
    int u,v;
    while(m--)
    {
        cin>>u>>v;
        vv[u].pb(v);
        vv[v].pb(u);
    }
    queue<int> qq;
    qq.push(1);
    vis[1]=1;
    while(!qq.empty())
    {
        u=qq.front();
        qq.pop();

        for(int ii:vv[u])
        {
            if(!vis[ii])
            {
                vis[ii]=1;
                qq.push(ii);
                par[ii]=u;
            }
        }
    }
    int i;
    for(i=1;i<=n;i++)
    {
        if(!vis[i]){cout<<"No";return 0;}
    }
    cout<<"Yes\n";
    for(i=2;i<=n;i++)cout<<par[i]<<"\n";

    return 0;
}

Measured memory_bytes: 10940
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;

int n, a, b, c;
int ans;
vector<int> l(8);

void dfs(int mp, int aa, int bb, int cc, int sum){
	if (sum == n){
		if (aa == 0 || bb == 0 || cc == 0){
			return;
		}
		ans = min(ans, abs(aa-a) + abs(bb-b) + abs(cc-c) + mp);
		return;
	}
	dfs(mp+min(10, aa*100), aa+l[sum], bb, cc, sum+1);
	dfs(mp+min(10, bb*100), aa, bb+l[sum], cc, sum+1);
	dfs(mp+min(10, cc*100), aa, bb, cc+l[sum], sum+1);
	dfs(mp, aa, bb, cc, sum+1);
	return;
}

int main(){
	cin >> n >> a >> b >> c;
	for (int i = 0; i < n; i++){
		cin >> l[i];
	}
	ans = MOD;
	dfs(0, 0, 0, 0, 0);
	cout << ans << endl;
 	return 0;
 }

Measured memory_bytes: 256
n,k,q = map(int,input().split())
a = [0 for i in range(n)]
for i in range(q):
    a0 = int(input())
    a[a0-1] += 1
for i in range(n):
    if k - q + a[i] > 0:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 4708
#include <iostream>
using namespace std;
typedef long long ll;

const ll MOD = 1000000007;

ll modpow(ll x, ll n){
    ll res = 1, r = x;
    while(n){
        if(n % 2) res = res * r % MOD;
        r = r * r % MOD;
        n /= 2;
    }
    return res;
}

int main()
{
    ll n;
    cin >> n;
    cout << (modpow(10, n) - modpow(9, n) * 2 + modpow(8, n) + MOD * 2) % MOD << endl;
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

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

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

int main() {
//	cout << fixed << setprecision(15);
	int n;
	cin >> n;
	vi d(n, 0);
	rep(i, n) cin >> d[i];
	sort(d.begin(), d.end());

	vi cnt(13, 0);
	rep(i, n) cnt[d[i]]++;

	if(cnt[0] > 0) {cout << 0 << endl; return 0; }
	rep1(i, 11) if(cnt[i] >= 3)  {cout << 0 << endl; return 0; }
	if(cnt[12] > 1) {cout << 0 << endl; return 0; }

	vector<bool> f(24, false);
	f[0] = true;
	rep1(i, 11) if(cnt[i] == 2) {f[i] = f[24-i] = true; }
	if(cnt[12] == 1) f[12] = true;

	bool right = true;
	rep1(i, 11) if(cnt[i] == 1) {
		if(right) f[i] = true;
		else f[24-i] = true;
		right = !right;
	}

	int pre = 0;
	int ans = 24;
	for(int i = 1; i < 24; i++) {
		if(f[i]) {
			ans = min(i - pre, ans);
			pre = i;
		}
	}
	ans = min(24 - pre, ans);
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<math.h>
#include<iostream>
using namespace std;
typedef long long ll;
const double pi=acos(-1.0);
double a,b;
int h,m; 
int main(){
	cin>>a>>b>>h>>m;
	double jm=m/30.0*pi,jh=h/6.0*pi+m/360.0*pi;
	double jd=fabs(jm-jh);
	double len=sqrt(a*a+b*b-2*a*b*cos(jd));
	printf("%.20f",len);
	return 0;
}


Measured memory_bytes: 4136
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import Data.List (unfoldr)
import Data.Maybe (catMaybes)

main :: IO ()
main = do
  let
    primeFactors :: Int -> [Int]
    primeFactors = catMaybes . unfoldr next . (,) 2
      where
        next :: (Int, Int) -> Maybe (Maybe Int, (Int, Int))
        next (_, 1)             = Nothing
        next (d, m) | m < d * d = Just (Just 1, (0, 1))
                    | otherwise = Just $ (,) (succ d) <$> ord d m
        ord :: Int -> Int -> (Maybe Int, Int)
        ord d = go 0
          where
            go :: Int -> Int -> (Maybe Int, Int)
            go c m | r == 0 = go (succ c) m'
              where
                (m', r) = m `divMod` d
            go 0 m = (Nothing, m)
            go c m = (Just c, m)
    f :: Int -> Int
    f m = unsafeBinaryMaxInt p (1, 8)
      where
        unsafeBinaryMaxInt :: (Int -> Bool) -> (Int, Int) -> Int
        unsafeBinaryMaxInt p = check
          where
            check :: (Int, Int) -> Int
            check ij@(_, j) | p j       = j
                            | otherwise = search ij
            search :: (Int, Int) -> Int
            search = fst . until ((==) <$> fst <*> pred . snd) halve
              where
                halve :: (Int, Int) -> (Int, Int)
                halve (i, j) | p m       = (m, j)
                             | otherwise = (i, m)
                  where
                    m = (i + j) `div` 2
        p :: Int -> Bool
        p = (<= 2 * m) . ((*) <$> id <*> succ)
  n <- unsafeTextToInt <$> T.getLine :: IO Int
  print . sum . map f . primeFactors $ n

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n
{-# INLINE unsafeTextToInt #-}


Measured memory_bytes: 4864
# coding: utf-8
# Your code here!

a = []
a.append(list(input().split()))
a.append(list(input().split()))
a.append(list(input().split()))

def kezuru(b):
    for i in range(len(a)):
        for j in range(len(a[i])):
            if b == a[i][j]:
                a[i][j] = '*'
        

n = int(input())
for i in range(n):
    b = input()
    kezuru(b)
    
def check():
    for i in range(3):
        if a[i][0] == a[i][1] and a[i][0] == a[i][2]:
            return 'Yes'
    for i in range(3):
        if a[0][i] == a[1][i] and a[0][i] == a[2][i]:
            return 'Yes'
    if a[0][0] == a[1][1] and a[0][0] == a[2][2]:
        return 'Yes'
    if a[0][2] == a[1][1] and a[0][2] == a[2][0]:
        return 'Yes'
    return 'No'
    
print(check())

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

using namespace std;

int main() {
  int N, T;
  cin >> N >> T;
  
  int res = -1;
  int c, t;
  for (int i = 0; i < N; i++) {
    cin >> c >> t;
    if (t <= T && (res == -1 || c < res)) {
      res = c;
    }
  }
  
  if (res == -1) {
    cout << "TLE" << endl;
  } else {
    cout << res << endl;
  }

  return 0;
}


Measured memory_bytes: 256
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

H,W = LI()
c = []
for i in range(10):
    temp = LI()
    c.append(temp)

A = []
for i in range(H):
    temp = LI()
    A.append(temp)

def WF(E,n):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                E[i][j] = min(E[i][j],E[i][k]+E[k][j])
    return E

E = [[float('inf')]*10 for _ in range(10)]
for i in range(10):
    E[i][i] = 0         #自分との距離は0にしておく
for i in range(10):
    for j in range(10):
        E[i][j] = c[i][j]

dist = WF(E,10)

ans = 0
for i in range(H):
    for j in range(W):
        if A[i][j] != -1:
            ans += dist[A[i][j]][1]

print(ans)

Measured memory_bytes: 41820
import sys
from collections import deque
import time
import bisect
def input():
    return sys.stdin.readline()[:-1]
mod=1000000007
h,w,k=map(int,input().split())
n=2**(w-1)
if w==1:
    print(1)
    exit()

dp=[[0]*w for i in range(h+1)]
dp[0][0]=1

# print(tyuo)
# print(haji)
for l in range(h):
    for i in range(1<<w-1):
        a = str(bin(i))[2:].zfill(w-1)
        if a.count('11') >= 1:
            continue
        for j in range(w):
            if j==0:
                if i & (1<<w-2):
                    dp[l+1][j+1]+=dp[l][j]
                else:
                    dp[l+1][j]+=dp[l][j]
            elif j==w-1:
                if i & 1:
                    dp[l+1][j-1]+=dp[l][j]
                else:
                    dp[l+1][j]+=dp[l][j]
            else:
                if i & (1<<j-1):
                    dp[l+1][j-1]+=dp[l][j]
                elif i & (1<<j):
                    dp[l+1][j+1]+=dp[l][j]
                else:
                    dp[l+1][j]+=dp[l][j]
            # print(i,dp[l+1])
# print(dp)
print(dp[h][k-1]%mod)

Measured memory_bytes: 45292
#include <iostream>


using namespace std;

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    if (A == 7) {
        if (B == 5 && C == 5) {
             cout << "YES" << endl;
         } else {
         cout << "NO" << endl;
         }
    } else if ( B == 7) {
        if(A == 5 && C == 5) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    } else if (C == 7) {
        if(A == 5 && B == 5) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    } else {
        cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
/* while(!cin.eof()) */
 
#include<bits/stdc++.h>
using namespace std; 
#define int long long 
#define mod (int)(1e9+7)
#define MAXI (int)(1e17+100)
#define N 1000005



// Driver code to test above functions
int32_t main()
{
    
 
    
     
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);

    
    int n;
    cin >> n;

    int a[n];
    for(int i=0;i<n;i++)
        cin >> a[i];

    int flag = 1;
    for(int i=0;i<n;i++)
    {
        if(a[i]%2==0)
        {
            if(a[i]%3!=0 and a[i]%5!=0)
                flag = 0;
        }
    }


    if(flag==1)
        cout << "APPROVED";
    else
        cout << "DENIED";
        


    return 0;
    
} 



Measured memory_bytes: 256
S = input()

if S[0]==S[1] !=S[2] ==S[3]:
  print('Yes')
elif S[0]!=S[1] ==S[2] !=S[3] and S[0]==S[3]:
  print('Yes')
elif S[0]==S[2] !=S[1] ==S[3]:
  print('Yes')
  
else:
  print('No')

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

#define forn(i,n) for(int i=0;i<(int)(n);i++)
#define si(c) ((int)(c).size())
#define forsn(i,s,n) for(int i = (int)(s); i<((int)n); i++)
#define dforsn(i,s,n) for(int i = (int)(n)-1; i>=((int)s); i--)
#define all(c) (c).begin(), (c).end()
#define D(a) cerr << #a << "=" << (a) << endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

const int INF = 1e9;
const int N = 2e5 + 10;
const int OFF = 1<<18;

int n, t, d[N], f[N], p[N], ord[N];
vi adj[N];

void dfs1(int u, int p) {
    ord[t] = u;
    d[u] = t++;
    ::p[u] = p;
    for (int v : adj[u]) if (v != p) {
        dfs1(v,u);
    }
    f[u] = t;
}

pii st[2*OFF];
pii query(int l, int r) {
    l += OFF; r += OFF;
    pii ans(INF,INF);
    while (l < r) {
        if (l&1) ans = min(ans, st[l++]);
        if (r&1) ans = min(ans, st[--r]);
        l /= 2; r /= 2;
    }
    return ans;
}

void upd(int p, int v) {
    p += OFF;
    st[p] = mp(v,p);
    p /= 2;
    while (p) {
        st[p] = min(st[p+p], st[p+p+1]);
        p /= 2;
    }
}

int cnt;
bool in[N];

void add(int u) {
    assert(!in[u]);
    in[u] = 1; cnt++;
    upd(d[u], INF);
    for (int v : adj[u]) if (v != p[u]) {
        upd(d[v], v);
    }
}

void del(int u) {
    assert(in[u]);
    in[u] = 0; cnt--;
    upd(d[u], u);
    for (int v : adj[u]) if (v != p[u]) upd(d[v], INF);
}

int ans[N];
void dfs2(int u, int p, int big) {
    vi mod;
    if (!in[u]) { add(u); mod.pb(u); }
    while (true) {
        auto q = query(d[u], f[u]);
        if (q.first == INF || q.first >= big) break;
        if (!in[q.first]) {
            add(q.first);
            mod.pb(q.first);
        }
    }
    ans[u] = cnt-1;
    for (int v : adj[u]) if (v != p) {
        dfs2(v,u, max(big, u));
    }
    reverse(all(mod));
    for (auto v : mod) del(v);
}


int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n;
    forn(_,n-1) {
        int u,v; cin >> u >> v;
        u--; v--;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    dfs1(0,0);
    fill_n(st, 2*OFF, mp(INF,INF));
    dfs2(0,0,-1);
    forn(i,n-1) cout << ans[i+1] << ' ';

    return 0;
}


Measured memory_bytes: 42728
from collections import deque
while True:
    W,H = map(int, input().split())
    if W == 0: break
    es = [[] for i in range(W*H)]
    for y in range(H):
        walls_h = list(map(int, input().split()))
        for x in range(W-1):
            if walls_h[x]: continue
            es[y*W + x].append(y*W + x+1)
            es[y*W + x+1].append(y*W + x)
        if y == H-1: break
        walls_v = list(map(int, input().split()))
        for x in range(W):
            if walls_v[x]: continue
            es[y*W + x].append((y+1)*W + x)
            es[(y+1)*W + x].append(y*W + x)
    q = deque([0])
    dist = [0] * (W*H)
    dist[0] = 1
    while q:
        fr = q.popleft()
        for to in es[fr]:
            if dist[to] == 0:
                dist[to] = dist[fr] + 1
                q.append(to)
    print(dist[-1])

Measured memory_bytes: 6232
object Main extends App {
	val temp = scala.io.StdIn.readLine.split(" ").map(_.toInt)
	
	val N = temp(0)
	var a = temp(1)
	var b = temp(2)

	var flag = true
	var tx = "Draw"

	while(flag){
		if(a+1 < b && a+1 <= N){
			a += 1
		}else if(a-1 >= 1){
			a -= 1
		}else{
			flag = false
			tx = "Borys"
		}

		if(flag){

			if(b-1 > a && b-1 >= 1){
				b -= 1
			}else if(b+1 <= N){
				b += 1
			}else{
				flag = false
				tx = "Alice"
			}
		}
	}
	

	println(tx)
}

Measured memory_bytes: 25500
package main 

import (
        "fmt"
)

func main () {
        var n, k int
        fmt.Scan(&n,&k)
        x := 1

        for i := 0 ; i < n ; i++ {
                 if  x * 2 <= x + k {
                        x = x * 2
                        
                } else if x * 2 > x + k {
                        x = x + k
                }
        }
        fmt.Println(x)
}


Measured memory_bytes: 512
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

n,m=map(int,input().split())
ab=[list(map(int, input().split())) for _ in range(m)]
uf=UnionFind(n)
for i in range(m):
  uf.union(ab[i][0]-1,ab[i][1]-1)
print(max([uf.size(x) for x in range(n)]))

Measured memory_bytes: 120532
#include<bits/stdc++.h>
using namespace std;
int n,k,l,a[200005],b[200005],i,u,v;
map<pair<int,int>,int>mp;
int f(int p,int x[]){
	if(x[p]==p)return p;
	return x[p]=f(x[p],x);
}
int main(){
	scanf("%d%d%d",&n,&k,&l);
	for(i=1;i<=n;i++)a[i]=b[i]=i;
	while(k--){
		scanf("%d%d",&u,&v);
		u=f(u,a),v=f(v,a);
		if(u!=v)a[u]=v;
	}
	while(l--){
		scanf("%d%d",&u,&v);
		u=f(u,b),v=f(v,b);
		if(u!=v)b[u]=v;
	}
	for(i=1;i<=n;i++){
		u=f(i,a),v=f(i,b);
		mp[{u,v}]++;
	}
	for(i=1;i<=n;i++){
		u=f(i,a),v=f(i,b);
		printf("%d ",mp[{u,v}]);
	}
	return 0;
}


Measured memory_bytes: 13568
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <queue>
using namespace std;

int main(){
	int n;
	string s;
	cin >> n >> s;
	if(n >= 3200) cout << s << endl;
	else cout << "red" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define N 100
int main()
{
  int A[N],n,i,j,min=0,minj,c,count=0;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&A[i]);
  for(i=0;i<=n-1;i++)
    {
      minj=i;//ソート順１かい目０、２かい目１。。。
      for(j=i;j<=n-1;j++)
	{
	  if(A[j]<A[minj]){
	    minj=j;//最小値のある要素番号更新
	  }
	}
      //ソート終の次の要素と最小値交換
      if(minj!=i)
	{
	  c=A[i];
	  A[i]=A[minj];
	  A[minj]=c;
	  count++;
	}
    }
  for(i=0;i<n;i++)
    {
      printf("%d",A[i]);
      if(i!=n-1)
	printf(" ");
    }
  printf("\n");
  printf("%d",count);
  printf("\n");
  return 0;
}



Measured memory_bytes: 2144
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
using namespace std;
int main()
{
	int N,ANS=0;
	cin >> N;

	for(int i=1;i<(N/2)+1;i++){
		if(i!=N-i&&i<N-i){
			ANS++;
		}
	}
	cout << ANS << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<int>>;
using dou =long double;
string Yes="Yes";
string YES="YES";
string NO="NO";
string No="No";
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define res resize
#define as assign
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
 
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 9223372036854775806ll;
const int mod = 1000000007ll;
const ll  MOD = 1000000007LL;
const double pi=3.1415926535897932384626;
int main(){
    int n,wm;
    std::cin >> n>>wm;
    std::vector<ll> w(n),v(n);
    rep(i,n)std::cin >> w[i]>>v[i];
    vvector(dp,ll,n+1,wm+1,0);
    rep(i,n){rep(j,wm+1){
        if(j-w[i]>=0){
            dp[i+1][j]=max(dp[i][j],dp[i][j-w[i]]+v[i]);
            //std::cout << i+1<<' '<<j<<' '<<dp[i+1][j] << std::endl;
        }
        else dp[i+1][j]=dp[i][j];
    }}
    ll ans=0ll;
    rep(i,wm+1){
        ans=max(ans,dp[n][i]);
    }
    std::cout << ans << std::endl;
}

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

using namespace std;

typedef unsigned long long ull;

ull A[200002];
unordered_map<ull, ull> I, J;
set<ull> X;

int main(){
    ull N;
    cin >> N;
    for(ull i=1; i<=N; i++){
        cin >> A[i];
        I[A[i] + i] += 1;
        J[i - A[i]] += 1;
        X.insert(A[i]+i);
    }

    ull cnt = 0;
    for(auto itr = X.begin(); itr!=X.end(); itr++){
        ull x = *itr;
        // cout << x << " " << I[x] << " "<< J[x]<< endl;
        cnt += I[x] * J[x];
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 36596
#include <stdio.h>

int mod(int x,int y){
    int ret;

    if((ret=x%y) < 0){
        ret += x;
    }
}
int pow2(int x, int y){
    if (y == 0)
    {
        return 1;
    }
    int base = x;
    while (y > 1)
    {
        x *= base;
        y--;
    }
    return x;
}

int main(){
    int sum = 0, n;
    scanf("%d",&n);
    //桁数の把握
    int ret=n,k = 1;

    while ((ret = ret / 10) > 0)
    {
        k++;
    }
    //printf("k=%d\n", k);
    if (k % 2 == 1)
    {
        sum += n - pow2(10, k-1) + 1;
        k--;
    }
    //printf("sum=%d\n", sum);
    while (k != 0)
    {
        if (k % 2 == 1)
        {
            sum += 9*pow2(10, k-1);
        }
        k--;
    }
    printf("%d", sum);
}



Measured memory_bytes: 128
#include<stdio.h>

int main( void )
{
	int H ,W ;
	scanf( "%d %d\n" ,&H ,&W ) ;

	char weather ;

	int i ,j ;
	for( i = 0 ; i < H ; ++i )
	{
		scanf( "%c" ,&weather ) ;

		int out = -1 ;
		for( j = 1 ; j <= W ; ++j )
		{
			if( weather == 'c' )
			{
				out = 0 ;
			}

			else
			{
				++out ;

				if( out < 1 )
				{
					out = -1 ;
				}
			}

			printf( "%d" ,out ) ;

			if( j == W )
			{
				printf( "\n" ) ;
			}
			else
			{
				printf( " " ) ;
			}

			scanf( "%c" ,&weather ) ;
		}
	}

	return 0 ;
}


Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
#define debug(n,v) cout<<#v<<":";for(int i=0;i<n;i++)cout<<v[i]<<" ";cout<<endl; 
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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; }

int main(){
    string s;
    stack<char> st;
    cin>>s;
    rep(i,s.size()){
        if(s[i]=='B'&&!st.empty()) st.pop();
        else if(s[i]!='B') st.push(s[i]);
    }
    string ans="";
    while(!st.empty()){
        ans.push_back(st.top());
        st.pop();
    }
    reverse(ALL(ans));
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
/* 2018-05-12-17.41.09*/

#include<bits/stdc++.h>
#define ll long long int
#define N 100010
using namespace std;

struct wunionfind
{
    int id[N],sz[N];
    void initial(int n)
    {
        int i;
        for(i=0;i<=n;i++) id[i]=i,sz[i]=1;
    }
    int root(int idx)
    {
        int i=idx;
        while(i!=id[i]) id[i]=id[id[i]],i=id[i];
        return i;
    }
    void uni(int a,int b)
    {
        int i=root(a),j=root(b);
        if (i!=j)
        {
            if(sz[i]>=sz[j]) id[j]=i,sz[i]+=sz[j],sz[j]=0;
            else id[i]=j,sz[j]+=sz[i],sz[i]=0;
        }
    }
    bool check(int a,int b)
    {
        if(root(a)==root(b)) return true;
        else return false;
    }
}W;

int main()
{
    int n,m;
    scanf("%d %d",&n,&m);
    int I[n+1];
    for(int i=1;i<=n;i++)
    {
        int temp;
        scanf("%d",&temp);
        I[temp]=i;
    }
    W.initial(n);
    for(int i=0;i<m;i++)
    {
        int x,y;
        scanf("%d %d",&x,&y);
        W.uni(x,y);
    }
    int cnt=0;
    for(int i=1;i<=n;i++) if(W.check(i,I[i])) cnt++;
    printf("%d\n",cnt);
    return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <regex>
#include <map>
#include <set>
using namespace std;
int main(){
    string S;
    cin >> S;
    
    for(int i=0;i<4;i++){
        if(S[i] == S[i+1]){
            cout << "Bad" << endl;
            return 0;
        }
    }
    cout << "Good" << endl;
    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>
#define rep(i,l,r)for(int i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

int x[110],y[110],h[110];
int main(){
	int n;
	scanf("%d",&n);
	rep(i,0,n)scanf("%d%d%d",x+i,y+i,h+i);
	rep(i,0,101)rep(j,0,101){
		int ans=1e9;
		rep(k,0,n){
			int d=abs(x[k]-i)+abs(y[k]-j);
			if(h[k])ans=d+h[k];
			else ans=min(ans,d);
		}
		int flag=1;
		rep(k,0,n){
			int d=abs(x[k]-i)+abs(y[k]-j);
			flag&=(h[k]==max(0,ans-d));
		}
		if(flag){
			printf("%d %d %d\n",i,j,ans);
			return 0;
		}
	}
}

Measured memory_bytes: 128
#include <stdio.h>
#include <math.h>
int sosuu(void);

int main()
{
  int kazu,i,count=0;
  scanf("%d",&kazu);

  for(i=0;i<kazu;i++)
    {
      if(sosuu()==1)count++;
    }
  printf("%d\n",count);
  return 0;
}

int sosuu(void)
{
  int a,j=3;
  scanf("%d",&a);
  if(a==2){return 1;}
  if(a%2==0||a<2){return 0;}
  while(j<=sqrt(a))
    {
      if(a%j==0)return 0;
      j=j+2;
    }
  return 1;
}



Measured memory_bytes: 2108
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main() {
    string L;    cin >> L;
    int l = L.length();
    long long mod = 1e9+7;

    vector<vector<long long> > dp(l+1, vector<long long>(2, 0));
    dp[0][0] = 1;

    for (int i = 0; i < l; i++) {
        if (L[i] == '0') {
            dp[i+1][0] = dp[i][0];
            dp[i+1][1] = 3*dp[i][1]%mod;
        }
        else {
            dp[i+1][0] = 2*dp[i][0] % mod;
            dp[i+1][1] = (3*dp[i][1] % mod + dp[i][0]) % mod;
        }
    }

    /*
    for (int i = 0; i <= l; i++) {
        cout << dp[i][0] << " " << dp[i][1] << endl;
    }
    */

    cout << (dp[l][1] + dp[l][0]) % mod << endl;

    return 0;
}

Measured memory_bytes: 8796
import java.util.Scanner;

public class Main {
    public static void main (String[] args) {
        try {
            int m, i, j, k, wl;
            Scanner sc = new Scanner(System.in);
            String s;
            String[] r = new String[10];
            char[] t = new char[200];
            int[] h = new int[100];

            for (i = 0; true; i++) {
                s = sc.nextLine();
                if (s.equals("-")) break;

                wl = s.length();

                char[] w = new char[wl];

                for (j = 0; j < wl; j++) {
                    w[j] = s.charAt(j);
                }

                s = sc.nextLine();
                m = Integer.parseInt(s);

                for (j = 0; j < m; j++) {
                    s = sc.nextLine();
                    h[j] = Integer.parseInt(s);
                }

                for (j = 0; j < m; j++) {
                    for (k = 0; k < h[j]; k++) {
                        t[k] = w[k];
                    }
                    for (k = h[j]; k < wl; k++) {
                        w[k-h[j]] = w[k];
                    }
                    for (k = wl-h[j]; k < wl; k++) {
                        w[k] = t[k-wl+h[j]];
                    }
                }
                r[i] = new String(w);
            }
            sc.close();

            int I = i;

            for (i = 0; i < I; i++) {
                System.out.println(r[i]);
            }
        }
        catch (NumberFormatException e) {
            System.out.println(e);
        }
    }
}


Measured memory_bytes: 26284
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;

typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;
typedef vector<string> vstring;

typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<double, double>> vpdouble;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vpint> vvpint;
typedef vector<vpll> vvpll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<string>> vvstring;
typedef vector<vector<bool>> vvbool;

typedef vector<vector<vector<ll>>> vvvll;

const int c_YET = -1;
const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const ll MAX = 1e9;
const double PI = 3.14159265358979323846264338327950288;
//========================================================================





int main() {

	////==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	////==================================
	

	ll A, B, C;
	cin >> A >> B >> C;

	if (C - A - B > 0)
	{

		if (4 * A * B < (C - A - B) * (C - A - B))
		{
			cout << "Yes" << endl;
		}
		else
		{
			cout << "No";
		}

	}
	else
	{
		cout << "No";
	}





}





Measured memory_bytes: 256
//Name: Circle and Points
//Level: 3
//Category: 幾何,円
//Note:

/*
 * 半径が固定なので，円周上に2点が乗っているときが境界状態．
 * すべての2点の組み合わせについて中心の来る場所（2点）を求め，内包判定を行う．
 * N=1のケースと，全ての点が互いに距離2以上離れているケースに注意．
 *
 * オーダーは O(N^3)．
 */
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <utility>

using namespace std;

typedef complex<double> Point;

bool inCircle(const Point &p, const Point &center, double radius) {
    double dist2 = norm(p-center);
    double rad2 = radius*radius;
    return dist2 < rad2+1e-9;
}

int check(const Point &center, const vector<Point> &points) {
    const int N = points.size();
    int cnt = 0;
    for(int i = 0; i < N; ++i) {
        if(inCircle(points[i], center, 1)) ++cnt;
    }
    return cnt;
}

int test(int a, int b, const vector<Point> &points) {
    const Point v(points[a]-points[b]);
    if(abs(v) >= 2) return 1;
    const double hlen = abs(v)/2;

    const double arg = acos(hlen);
    const Point unit = v / abs(v);
    return max(check(points[b] + unit*polar(1.0, arg), points), check(points[b] + unit*polar(1.0, -arg), points));
}

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

    while(true) {
        int N;
        cin >> N;
        if(!N) break;

        vector<Point> points(N);
        for(int i = 0; i < N; ++i) {
            cin >> points[i].real() >> points[i].imag();
        }
        int ans = 0;
        for(int i = 0; i < N; ++i) {
            for(int j = 0; j < i; ++j) {
                ans = max(ans, test(i, j, points));
            }
        }
        if(N == 1) ans = 1;
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1328
import java.util.Scanner;

public class Main {
	
	static int[] s;
	static int tt;
	static int ans;
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		s = new int[n];
		for (int i = 0; i < n; i++) {
			s[i] = sc.nextInt();
		}
		int q = sc.nextInt();
		int[] t = new int[q];
		for (int i = 0; i < q; i++) {
			t[i] = sc.nextInt();
		}
		
		ans = 0;
		for (int i = 0; i < q; i++) {
			tt = t[i];
			binarySearch(0, n - 1);
		}
		System.out.println(ans);
	}
	
	private static void binarySearch(int startIndex, int endIndex) {
		int index = (startIndex + endIndex) / 2;
		if (s[index] == tt) {
			ans++;
			return;
		} else if (startIndex == endIndex) {
			return;
		} else if (s[index] > tt) {
			binarySearch(startIndex, index);
		} else if (s[index] < tt) {
			binarySearch(index + 1, endIndex);
		}
	}
}

Measured memory_bytes: 81436
// Vicfred
// https://atcoder.jp/contests/abc047/tasks/arc063_a
// greedy
import std.stdio;
import std.string;

void main() {
    string s = readln.strip;
    long n = s.length;

    long count = 0;
    for(long i = 0; i < s.length-1; i++) {
        if(s[i] != s[i + 1]) count += 1;
    }
    count.writeln;
}


Measured memory_bytes: 2776