akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define pi (acos(-1))
using namespace std;
/*todos
 * prime num gen
 * for macro
 * */
int main()
{   
    ll n, d;
    cin >> n >> d;
    ll x, y;
    ll ans = 0;
    for (ll i = 0; i != n; ++i)
    {
        cin >> x >> y;
        if (d * d >= x * x + y * y) { ans++; }
    }
    cout << ans << endl;
    return 0;
}  


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

int main() {
    int x, y, z;
    while (1) {
        cin >> x >> y >> z;
        if (x == -1 && y == -1 && z == -1) break;
        else if (x == -1 || y == -1 || x + y < 30) cout << "F" << endl;
        else if (x + y >= 80) cout << "A" << endl;
        else if (x + y >= 65) cout << "B" << endl;
        else if (x + y >= 50) cout << "C" << endl;
        else {
            if (z >= 50) cout << "C" << endl;
            else cout << "D" << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3092
N = int(input())

word = []

for i in range(N):
  A = int(input())
  B = []
  for i in range(A):
    x = list(map(int, input().split()))
    B.append(x)
  word.append(B)
answer = 0
for i in range(2**N):
  check = True
  a = format(i, 'b').zfill(N)
  count = 0
  for j in range(len(a)):
    if a[j] == "1":
      count += 1
      for x, y in word[j]:
        if not int(a[x-1]) == y:
          check = False
  if check == True:
    answer = max([answer, count])
print(answer)

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

int main() {
  int N;
  cin>>N;
  vector<int> A(N);
  for(int i=0; i<N; i++){
    cin>>A.at(i);
  }
  bool ans = true;
  sort(A.begin(),A.end());
  for(int i=0; i<N-1;i++){
    if(A.at(i)==A.at(i+1)){
      ans = false;
      break;
    }
  }
  if(ans){
    cout<<"YES"<<endl;
  }
  else{
    cout<<"NO"<<endl;
  }
}


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

int main() {
	int n,k;
    cin>>n>>k;
    int a[n];
    int i,j;
    for(i=0;i<n;i++)cin>>a[i];
    int dp[n]={0};
    for(i=1;i<n;i++){
        int t =  INT_MAX;
        for(j=i-1;j>=i-k && j>=0;j--){
            t = min(t,  dp[j] + abs(a[i]-a[j]));
        }
        dp[i] = t;
    }
    
    // for(i=0;i<n;i++)cout<<dp[i]<<" ";
    cout<<dp[n-1]<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAXN=2e5+5;
const ll MOD=1e9+7;
const ll MOD1=13;
ll L,R;
void solve()
{
    if(R-L+1>=5000)
    {
        printf("0\n");
    }
    else
    {
        ll ans=1e18;
        for(ll i=L;i<R;i++)
        {
            for(ll j=i+1;j<=R;j++)
            {
                ans=min(ans,(i*j)%2019);
            }
        }
        printf("%lld\n",ans);
    }
}
int main()
{
    scanf("%lld %lld",&L,&R);
    solve();
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(int argc, char* argv[]) {
  int N;
  cin >> N;
  vector<int> t(N + 1), x(N + 1), y(N + 1);
  t[0] = x[0] = y[0] = 0;
  for (int i = 1; i <= N; i++) {
    cin >> t[i] >> x[i] >> y[i];
  }

  for (int i = 0; i < N; i++) {
    int l1_dist = abs(x[i + 1] - x[i]) + abs(y[i + 1] - y[i]);
    int intarval = t[i + 1] - t[i];
    if (l1_dist > intarval || (intarval - l1_dist) % 2 != 0) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;

  return 0;
}

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

int main(){
    int n,t,a;
    cin>>n>>t>>a;
    vector<int> h(n);
    for(int i=0;i<n;i++){
        cin>>h[i];
    }

    int r=1e9,ans=-1;
    for(int i=0;i<n;i++){
        int k=1000*t-6*h[i];
        if(abs(k-a*1000)<r){
            ans=i+1;
            r=abs(k-a*1000);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int h,r;
	scanf("%d %d",&h,&r);
	if (h+r>0){
		printf("1\n");
	}
	else if (h+r<0){
		printf("-1\n");
	}
	else {
		printf("0\n");
	}
	return 0;
}


Measured memory_bytes: 2044
#include<iostream>
using namespace std;
int main()
{
  int  a[10000000] = {};
  int s;
  cin>>s;
  a[s] = 1;
  int q = s;
  for(int i = 2;i<1000000;i++)
  {
    if(q % 2 == 0)
    {
    	q = q / 2;
    }
    else
    {
        q = 3*q + 1;
    }
    
    if(a[q] == 1)
    {
      cout<< i<<endl;
      break;
    }
    else
    {
      a[q] = 1;
    }
  }
}

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

int main() {
  int n; cin>>n;
  ll k; cin>>k;
  vector<ll> A(n);
  rep(i, n) cin>>A[i];
  ll res=0;
  for (int i=40; i>=0; --i) {
    ll one=0;
    rep(j, n) one+=(1&(A[j]>>i));
    ll zero=n-one;
    if (k>=(1LL<<i)&&one<zero) {
      k-=1LL<<i;
      res+=zero<<i;
    }
    else res+=one<<i;
  }
  cout<<res<<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MAX_N = 100005;
int np[MAX_N],p[MAX_N];

int main()
{
	int N;
	cin >> N;
	int cntp = 0,cntnp = 0;
	rep(i,N)
	{
		int a;
		cin >> a;
		if (a > 0)
		{
			p[cntp] = a;
			cntp++;
		}
		else
		{
			np[cntnp] = a;
			cntnp++;
		}
	}

	sort(np,np+cntnp);
	sort(p,p+cntp);
	int sump = 0, sumnp = 0;
	rep(i,cntp)
	{
		sump += p[i];
	}
	rep(i,cntnp)
	{
		sumnp += np[i];
	}
	if (cntnp >= 1 && cntp >= 1)
	{
		cout << sump - sumnp << endl;
		rep(i,cntp-1)
		{
			cout << np[0] << " " << p[i] << endl;
			np[0] -= p[i];
		}

		rep(i,cntnp)
		{
			cout << p[cntp-1] << " " << np[i] << endl;
			p[cntp-1] -= np[i]; 
		}
		//cout << p[cntp-1] << endl;
		return 0;
	}
	else if (cntnp == 0)
	{
		cout << sump - p[0] * 2 << endl;
		rep(i,cntp-2)
		{
			cout << p[0] << " " << p[i+1] << endl;
			p[0] -= p[i+1];
		}

		cout << p[cntp-1] << " " << p[0] << endl;
		//cout << p[cntp-1] - p[0] << endl;
	}
	else
	{
		cout << sumnp * (-1) + np[cntnp-1] * 2 << endl;
		rep(i,cntnp-1)
		{
			cout << np[cntnp-1] << " " << np[i] << endl;
			np[cntnp-1] -= np[i];
		}
		//cout << np[cntnp-1] << endl;
	}
	return 0;
}

Measured memory_bytes: 2304
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int x = sc.nextInt();
        int a[] = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        Arrays.sort(a);
        int t = 0;
        for (int i = 0; i < n; i++) {
            if (x > 0) {
                x -= a[i];
                t++;
            } else break;
        }
        if (x != 0)
            t--;
            System.out.println(t);
    }
}



Measured memory_bytes: 23124
#include<bits/stdc++.h>
 #define mod 1000000007
 #define ll long long int
 #define ar array
 #define mp make_pair
 using namespace std;
 
 int main()
 {
 	ios::sync_with_stdio(false);
 	cin.tie(NULL);
 	string a;
 	getline(cin,a);
 	int b;
 	int c;
 	stringstream ss(a);
 	char ch;
 	ss>>b;
 	ss>>ch;
 	ss>>c;
 	if(ch=='+')
 		cout<<c+b<<endl;
	else
 		cout<<b-c<<endl;
 	return 0;
 }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vb=vector<bool>;
using vvb=vector<vb>;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pll = pair<ll,ll>;
using vpii = vector<pii>;
using vpli = vector<pli>;
using vpll = vector<pll>;

#define rep(i, n) for(int i=0;i<(int)n;i++)
#define rep2(i, s, n) for(int i=(s);i<(int)n;i++)
int INF=1e9+7;

int main() {
  string S;
  cin >> S;
  
  ll ten=1;
  int r=0;
  vi question;
  for(int i=S.size()-1;i>=0;i--) {
    if(S[i]=='?') question.push_back(ten);
    else r=(r+ten*(S[i]-'0'))%13;
    ten=ten*10%13;
  }
  
  int size=question.size();
  vvl rem(size+1,vl(13));
  rem[0][r]=1;
  rep(i,size) {
    rep(j,13) {
      rep(k,10) {
        rem[i+1][(j+question[i]*k)%13]+=rem[i][j];
        rem[i+1][(j+question[i]*k)%13]%=INF;
      }
    }
  }
  
  cout << rem[size][5] << endl;
}

Measured memory_bytes: 17040
n=gets.to_i
c=gets.split.map(&:to_i).sort.reverse
mod=1000000007

d=(n-1).times.inject(1){|s,r|s*4%mod}
p d.step(Float::INFINITY,d).lazy.drop(1).take(n).zip(c).map{|a,b|a*b%mod}.inject(:+)%mod


Measured memory_bytes: 23152
#include <stdio.h>

int main(void) {

	int x, cnt;
	
	cnt = 1;
	
	while (scanf("%d", &x), x){
		
		if (x == 0) break;
		
		printf("Case %d: %d\n", cnt, x);
		
		cnt++;
	}

	return 0;
}

Measured memory_bytes: 600
#include <algorithm>
#include <bitset>
#include <cmath>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(a) begin(a),end(a)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
ll gcd(ll a, ll b){
  if (b==0) return a;
  else return gcd(b,a%b);
}
int cans(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


#define MAX_V 100010


struct edge{
  int to;
  int cost;
};

int V;
vector<edge> G[MAX_V];
int d[MAX_V];

void dijkstra(int s) {
  priority_queue<P, vector<P>, greater<P> > que;
  fill(d, d+V, inf);
  d[s] = 0;
  que.push(P(0, s));

  while (!que.empty()) {
    P p = que.top();
    que.pop();
    int v = p.second;
    if (d[v] < p.first) continue;

    for (int i=0; i<G[v].size(); ++i) {
      edge e = G[v][i];
      if (d[e.to] > d[v] + e.cost) {
	d[e.to] = d[v] + e.cost;
	que.push(P(d[e.to], e.to));
      }
    }
  }
}

int main() {
  cin >> V;
  int E;
  cin >> E;
  int s;
  cin >> s;
  rep(i,E) {
    int a,b,c;
    cin >> a >> b >> c;
    edge e = {b,c};
    G[a].push_back(e);
  }
  dijkstra(s);

  rep(i,V) {
    if(d[i] == inf) cout << "INF" << endl; 
    else cout << d[i] << endl;
  }
  return 0;
}



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

int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   long long n;
   cin >> n;
   vector<long long> a(n+1);
   for (int i = 0; i < n + 1; i++) {
      cin >> a[i];
   }

   if (n == 0 && a[0] == 1) {
      cout << 1 << '\n';
      return 0;
   }
   else if (n == 0 && a[0] != 1) {
      cout << -1 << '\n';
      return 0;
   }
   else if (a[0] != 0) {
      cout << -1 << '\n';
      return 0;
   }

   vector<pair<long long,long long>> b(n+1);
   b[n].first = a[n];
   b[n].second = a[n];
   for (int i = n - 1; i >= 0; i--) {
      b[i].first = (b[i+1].first + 1) / 2 + a[i];
      b[i].second = b[i+1].second + a[i];
   }

   if (b[0].first <= 1 && 1 <= b[0].second);
   else {
      cout << -1 << '\n';
      return 0;
   }
   
   long long ans = 1;
   vector<long long> c(n);
   c[0] = 1;
   for (int i = 1; i < n; i++) {
      c[i] = min((c[i-1] - a[i-1]) * 2, b[i].second);
      ans += c[i];
   }
   ans += a[n];
   cout << ans << '\n';
   return 0;
}

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

int main(){
    string s;
    cin >> s;
    int k;
    cin >> k;
    int n = s.size();
    vector<string> v;
    int t = min(5, n);

    for (int i = 1; i <= t; i++){ 
        rep(j, n - i + 1){
            v.push_back(s.substr(j, i));
        }
    }

    sort(v.begin(), v.end());

    v.push_back(" ");

    int i = 0, cnt = 1;
    while (true)
{
        if (v[i] != v[i+1])
{
            if (cnt == k)
{
                cout << v[i] << endl;
                break;
            }
            cnt ++;
            i ++;
        }
        else i++;
    }
}


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

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

  // ここにプログラムを追記
  int count = 0;
  for (int i = A; i <= B; i++){
    int t = i;
    int a, b, c, d, e;
    a = t / 10000;
    t -= 10000 * a;
    b = t / 1000;
    t -= 1000 * b;
    c = t / 100;
    t -= 100 * c;
    d = t / 10;
    t -= 10 * d;
    e = t;
    
    if (a == e && b == d)
      count++;    
  }
  cout << count << endl;    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> pii;
typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update> tree_type;
const int maxn=100010;
tree_type dic;
int n,a[maxn],sum[maxn];
vector<int> as;
ll check(int mid){
	dic.clear();
	sum[0]=0;
	dic.insert(pii(sum[0],0));
	ll res=0;
	for(int i=1;i<=n;i++){
		int add=(a[i]<=mid?-1:1);
		sum[i]=sum[i-1]+add;
		auto it=dic.lower_bound(pii(sum[i]+1,-1));
		if(it!=dic.end()) res+=dic.size()-dic.order_of_key(*it);
		dic.insert(pii(sum[i],i));
	}
	return res;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",a+i);
		as.push_back(a[i]);
	}
	sort(as.begin(),as.end());
	as.erase(unique(as.begin(),as.end()),as.end());
	for(int i=1;i<=n;i++)
		a[i]=lower_bound(as.begin(),as.end(),a[i])-as.begin()+1;
	ll tot=(ll)(1+n)*n/2;
	int l=1,r=as.size();
	while(l!=r){
		int mid=(l+r)>>1;
		if(check(mid)*2>tot) r=mid;
		else l=mid+1;
	}
	printf("%d\n",as[r-1]);
	return 0;
}

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

using namespace std;

#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define Rrep(i, j) for(int i = j; i >= 0; --i)
#define INF (1 << 30)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

int dp[1001][1001];
int v[1000], w[1000];

int main() {
	int W, N;
	int c = 1;
	while(1) {
		scanf("%d", &W);
		if(W == 0) break;
		memset(dp, 0, sizeof(dp));
		scanf("%d", &N);
		int wans = 0;
		rep(i, N) scanf("%d,%d", &v[i], &w[i]);
		rep(i, N) rep(j, W + 1) {
			if(j < w[i]) dp[i + 1][j] = dp[i][j];
			else {
				dp[i+1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
			}
		}
		Rrep(i, W) if(dp[N][i] != dp[N][W]){
			printf("Case %d:\n", c++);
			printf("%d\n", dp[N][W]);
			printf("%d\n", i + 1);
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 7132
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
 
using namespace std;
 
 
int main()
{
  	int a[3][3];

  	for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 3; j++) {
        cin >> a[i][j];
      }
    }
  
  	int n;
    cin >> n;
  	for (int k = 0; k < n; k++) {
      	int v;
      	cin >> v;
        for (int i = 0; i < 3; i++) {
          for (int j = 0; j < 3; j++) {
            if (a[i][j] == v) {
              	a[i][j] = 0;
            }
          }
        }
    }
	bool flag = false;

  if ((a[0][0] == 0 && a[0][1] == 0 && a[0][2] == 0) ||
  (a[1][0] == 0 && a[1][1] == 0 && a[1][2] == 0) ||
  (a[2][0] == 0 && a[2][1] == 0 && a[2][2] == 0) ||

  (a[0][0] == 0 && a[1][0] == 0 && a[2][0] == 0) ||
  (a[0][1] == 0 && a[1][1] == 0 && a[2][1] == 0) ||
  (a[0][2] == 0 && a[1][2] == 0 && a[2][2] == 0) ||
  
  (a[0][0] == 0 && a[1][1] == 0 && a[2][2] == 0) ||
  (a[0][2] == 0 && a[1][1] == 0 && a[2][0] == 0)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
 
  
    return 0;
}

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

int main()
{
    int n,i ;
    scanf("%d",&n);
    long long a[n],b[n],c[n],low,high,sum=0;
    for (i=0;i<n;i++)
    {
                 scanf("%lld",&a[i]);
    }
    for (i=0;i<n;i++)
    {
                 scanf(" %lld",&b[i]);
    }
    for (i=0;i<n;i++)
    {
                 scanf(" %lld",&c[i]);
    }
    sort (a,a+n);
    sort (c,c+n);
    for (i=0;i<n;i++)
    {
                 long long ans = b[i];
                 low = lower_bound(a,a+n,ans)-a;
                 high = n - (upper_bound(c,c+n,ans) - c);
                 //printf("low is %lld high is %lld\n",low,high);
                 sum += (low*high);
    }
    printf("%lld\n",sum);
    return 0;
}


Measured memory_bytes: 6180
n = int(input())
a = [0] + list(map(int, input().split())) + [0]
d = []

for i in range(n + 1):
    d.append(abs(a[i] - a[i + 1]))

ref = sum(d)

for i in range(1, n + 1):
    ans = ref - sum(d[i - 1: i + 1]) + abs(a[i - 1] - a[i + 1])
    print(ans)

Measured memory_bytes: 14048
#include <iostream>
#include <vector>
int INF = 1e9;
std::vector<int> boroc(200);
void init(int n){
    for(int i = 0; i < n; i++) boroc[i] = i*(i + 1)*(i + 2) / 6;
}
int main(){
    int n = 1000000;
    init(200);
    int dp[n + 1], dp2[n + 1];
    for(int i = 0; i < n + 1; i++){
        dp[i] = INF;
        dp2[i] = INF;
    }
    dp[0] = 0;
    dp2[0] = 0;
    for(int i = 0; i < 200; i++){
        if(boroc[i] > n) break;
        dp[boroc[i]] = 1;
        if(boroc[i] % 2 == 1) dp2[boroc[i]] = 1;
    }
    for(int i = 1; i < 200; i++){
        int t = boroc[i];
        for(int j = 1; j + t < n; j++){
            dp[j + t] = std::min(dp[j] + 1, dp[j + t]);
        }
        if(t % 2 == 1){
            for(int j = 1; j + t < n; j++) dp2[j + t] = std::min(dp2[j] + 1, dp2[j + t]);
        }
    }
    while(1){
        int N;
        std::cin >> N;
        if(N == 0) break;
        std::cout << dp[N] << ' ' << dp2[N] << std::endl;
    }
}


Measured memory_bytes: 10904
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<bitset>
#include <climits>
#include<set>
#include<bitset>
using namespace std;

typedef long long ll;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define ff first
#define ss second
#define rep(i,n) for(int i = 0;i < n;i++)
   
#define MAX_N 200010
class UnionFind {
public:
	//UnionFind
	int par[MAX_N];
	int ufrank[MAX_N];
	int ufsize[MAX_N];
	UnionFind(int ufsize_of_tree) {
      
		for (int i = 0; i < ufsize_of_tree; i++)
		{
			par[i] = i;
			ufrank[i] = 0;
			ufsize[i] = 1;
		}
	}
	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;
		if (ufrank[x] < ufrank[y]) {
			par[x] = y;
			int sx = ufsize[x], sy = ufsize[y];
			ufsize[x] = ufsize[y] = sx + sy;
		}
		else {
			par[y] = x;
			if (ufrank[x] == ufrank[y]) ufrank[x]++;
			int sx = ufsize[x], sy = ufsize[y];
			ufsize[x] = ufsize[y] = sx + sy;
		}
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
};

int main(void){
   UnionFind UF(200010);
   int N,M;scanf("%d %d",&N,&M);
   const int MAX = 100000;
   
   for(int i = 0;i < N;i++){
      int k;scanf("%d",&k);
      for(int j = 0;j < k;j++){
         int l;scanf("%d",&l);
         UF.unite(i,l + MAX);
      }
   }
   
   for(int i = 0;i < N - 1;i++){
      if(!UF.same(i,i+1)){
         printf("NO\n");
         return 0;
      }
   }
   printf("YES\n");
   return 0;
}


Measured memory_bytes: 2560
ab = [[int(i) for i in input().split()] for _ in range(3)]

cnt = [0] * 4
for a, b in ab :
  cnt[a-1] += 1
  cnt[b-1] += 1
  
if cnt.count(1) == cnt.count(2) == 2 :
  print('YES')
else :
  print('NO')

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

int main(){
    int k,n,i,max = 0;
    int a[200000];
    cin>>k>>n;
    for(i=0;i<n;i++){
        cin>>a[i];
    }
    for(i=0;i<n-1;i++){
        if(a[i+1]-a[i] > max) max = a[i+1] - a[i];
    }
    if(k + a[0] - a[n-1] > max) max = k + a[0] - a[n-1];
    cout<<k-max<<endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
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;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> pw2(62,1);vector<ll> pw10(19,1);

vector<vector<char> > f(51,vector<char>(51));
ll H,W;
ll dx[4]={0,0,1,-1};
ll dy[4]={1,-1,0,0};

ll bfs(){
    queue<P> que;
    ll d[51][51];
    rep(i,51)rep(j,51) d[i][j]=INF;
    d[0][0]=0;
    que.push(P(0,0));
    while(sz(que)){
        P p=que.front(); que.pop();
        if(p==P(H-1,W-1)) return d[H-1][W-1];
        
        rep(i,4){
            ll X=p.a+dx[i],Y=p.b+dy[i];
            if(0<=X && X<H && 0<=Y && Y<W && f[X][Y]=='.' && d[X][Y]==INF){
                que.push(P(X,Y));
                d[X][Y]=d[p.a][p.b]+1;
            }
        }
    }
    return -1;
}

int main(){
    {rep1(i,61) pw2[i]=2*pw2[i-1];}
    {rep1(i,18) pw10[i]=10*pw10[i-1];}
    
    cin>>H>>W;
    rep(i,H){
        string tmp; cin>>tmp;
        rep(j,W) f[i][j]=tmp[j];
    }
    
    ll cnt=0;
    rep(i,H)rep(j,W){
        if(f[i][j]=='#') cnt++;
    }
    
    ll tmp=bfs();
    if(tmp!=-1){
        cout<<H*W-cnt-(tmp+1)<<endl;
    }
    else cout<<-1<<endl;
}


Measured memory_bytes: 3604
N=int(input())

alist=[]
for i in range(N):
  ai=int(input())
  ailist=[]
  for j in range(ai):
    xij,yij=map(int,input().split())
    if yij==0:
      ailist.append((xij-1,False))
    else:
      ailist.append((xij-1,True))
    
  alist.append(ailist)

#print(alist)
answer=0
for i in range(2**N):
  bin_str=format(i, '0'+str(N)+'b')
  dlist=list(map(int,list(bin_str)))
  #print(dlist)
  
  contra=False
  for j in range(N):
    #j in honest
    if dlist[j]==1:
      for aj in alist[j]:
        x,y=aj
        if y and dlist[x]==0:
          contra=True
          break
        elif not y and dlist[x]==1:
          contra=True
          break
    if contra:
      break
  else:
    #print(dlist)
    answer=sum(dlist)

print(answer)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int main(){
  int a,b,c,n;
  while(cin>>a>>b>>c&&a&&b&&c){
    int d[300];
    int e[1000],f[1000],g[1000],h;
    for(int i=0;i<300;i++)d[i]=2;
    cin>>n;
    int k=0;
    for(int i=0;i<n;i++){
      cin>>e[k]>>f[k]>>g[k]>>h;e[k]--;f[k]--;g[k]--;
      if(h==1)d[e[k]]=d[f[k]]=d[g[k]]=1;
      else k++;
    }
    for(int i=0;i<k;i++){
      int x=e[i],y=f[i],z=g[i];
      if(d[x]==1&&d[y]==1)d[z]=0;
      else if(d[y]==1&&d[z]==1)d[x]=0;
      else if(d[z]==1&&d[x]==1)d[y]=0;
    }
    for(int i=0;i<a+b+c;i++){
      cout<<d[i]<<endl;
    }
  }
}

Measured memory_bytes: 1172
function main(input) {
  input = input.trim();
  const list = input.split(" ");
  const animalsLength = Number(list[0])
  const legsLength = Number(list[1])
  const craneLegs = 2
  const turtleLegs = 4
  if (legsLength === 0 || legsLength % 2 === 1) {
    return console.log('No')
  }
  if (animalsLength * craneLegs <= legsLength && legsLength <= animalsLength * turtleLegs) {
    return console.log('Yes')
  }
  console.log('No')
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)

#define mod 1e9+7;
#define inf 1e18+7;

typedef long long ll;

int main() {
    int n;
    cin>>n;

    vector<int>cnt(9);
    rep(i,n){
        int a;
        cin>>a;
        if(a<400){
            cnt[0]++;
        }
        else if (a<800) {
            cnt[1]++;
        }
        else if (a<1200) {
            cnt[2]++;
        }
        else if (a<1600) {
            cnt[3]++;
        }
        else if (a<2000) {
            cnt[4]++;
        }
        else if (a<2400) {
            cnt[5]++;
        }
        else if (a<2800) {
            cnt[6]++;
        }
        else if (a<3200) {
            cnt[7]++;
        }
        else{
            cnt[8]++;
        }
    }

    int MIN=0,MAX=0;
    rep(i,8){
        if(cnt[i]>0){
            MIN++;
        }
    }


    MAX=MIN+cnt[8];

    cout<<max(MIN,1)<<" "<<MAX<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// (setq-default c-basic-offset 2)

int main() {
  long long x, k, d;
  cin >> x >> k >> d;
  x = abs(x);
  // k is small
  // x > k * d
  // x / d > k

  if (k < (x / d)) {
    cout << x - k * d << endl;
  } else {
    k -= (x / d);
    x -= (d * (x / d));
    if (k % 2 == 0) {
      cout << x << endl;
    } else {
      cout << abs(x - d) << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <cstdio>
#include <map>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
#define P pair<int,int>

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

const ll maxn=100000;

int main(){
    int n;
    string s;
    string l = "(";
    string r = ")";
    int cnt=0,x=INF;
    
    cin >> n>>s;
    
    rep(i,n){
        char now =s[i];
        if(now=='('){
            cnt++;
        }else{
            cnt--;
        }
        x = min(x,cnt);
    }
    
    
    rep(i,-x){
        s=l+s;
    }
    if(x<0)cnt-=x;
    rep(i,cnt){
        s=s+r;
    }
    
    
    cout << s<<endl;
    
    return 0;
}


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

int main() {
  string s;
  cin >> s;
  sort(s.begin(),s.end());
  s.erase(unique(s.begin(),s.end()),s.end());
  if(s.size() == 26) cout << "None" << endl;
  else {
    char c = 'a';
    for(int i = 0; i < s.size(); i++) {
      if(s[i] != c) {
        break;
      }
      c += 1;
    }
    cout << c << endl;
  }
}

Measured memory_bytes: 512
#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>;

int main() {
  int n;
  cin >> n;
  vector<int> h(n);
  rep(i, n) cin >> h[i];
  int ans = 0, cnt = 0, now = h[0];
  for (int i = 1; i < n; i++) {
    if (now < h[i]) {
      ans = max(ans, cnt);
      cnt = 0;
    } else {
      cnt++;
    }
    now = h[i];
  }
  ans = max(ans, cnt);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <nmmintrin.h>
#include <chrono>
#include <list>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589
#ifdef _MSC_VER
#define __builtin_popcount _mm_popcnt_u32
#define __builtin_popcountll _mm_popcnt_u64
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}
class Graph {
public:
	int vn;
	int sumcost = 0;
	vector<vector<pii>> g;

	Graph(int n) {
		vn = n;
		g.resize(n);
	}
	virtual void con(int a, int b, int w) = 0;
	int getWeight(int f, int t) {
		auto itr = lower_bound(ALL(g[f]), make_pair(t, INT_MIN));
		if (itr != g[f].end())
			return itr->second;
		return INT_MIN;
	}
	int Costsum() {
		return sumcost;
	}
	void scan(int edcount, bool oindexed, bool w) {
		REP(i, edcount) {
			int a, b, c = 1;
			scanf("%d %d", &a, &b);
			if (w)scanf("%d", &c);
			con(a - oindexed, b - oindexed, c);
		}
	}
};
class BiDGraph : public Graph {//無向
public:
	BiDGraph(int n) : Graph(n) {}

	void con(int a, int b, int w = 1) {
		g[a].push_back({ b,w });
		g[b].push_back({ a, w });
		sumcost++;
	}
};
template<class T>
vector<ll> Dijkstra(T g, int st) {
	priority_queue<pll, vector<pll>, greater<pll>> que;

	que.push({ 0, st });
	int kk = 0;
	vector<ll> res(g.vn, -1);
	while (kk < g.vn && que.size()) {
		pll cur = que.top();
		que.pop();
		if (res[cur.second] != -1)
			continue;
		res[cur.second] = cur.first;
		kk++;
		for (auto itr : g.g[cur.second]) {
			if (res[itr.first] == -1)
				que.push({ cur.first + itr.second,itr.first });
		}
	}
	return res;
}


signed  main() {
	int n;
	cin >> n;
	BiDGraph g(n);
	g.scan(n-1,1,1);

	int q, k;
	cin >> q >> k;
	vector<ll> dis(Dijkstra(g,k-1));

	int a, b;
	REP(i, q) {
		scanf("%d %d", &a, &b);

		printf("%lld\n", dis[a-1] + dis[b-1]);
	}
	return 0;

}


Measured memory_bytes: 15732
#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) for (int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x) cerr << #x << " = " << (x) << endl;
#define int long long
using namespace std;

template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}

template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}

template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
	rep(i, v.size()) { os << v[i] << (i == v.size() - 1 ? "" : " "); }
	return os;
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
	for (T& x : v) { is >> x; }
	return is;
}

typedef vector<vector<int>> Graph;

bool dfs(int cur, int pre, vector<bool> used, const Graph& g) {
	used[cur] = true;
	bool res  = false;
	for (auto to : g[cur]) {
		if (to == pre) continue;
		if (used[to]) return true;
		res |= dfs(to, cur, used, g);
	}
	return res;
}

bool hasLoop(const Graph& g) {
	int n = g.size();

	vector<bool> used(n, false);
	bool res = false;
	rep(i, n) {
		if (used[i]) continue;
		res |= dfs(i, -1, used, g);
	}
	return res;
}

vector<int> bfs(int s, const Graph& g) {
	queue<int> q;
	q.emplace(s);

	vector<int> dis(g.size(), 1e18);
	dis[s] = 0;

	vector<int> pre(g.size(), -1);
	while (not q.empty()) {
		int cur = q.front();
		q.pop();
		for (auto to : g[cur]) {
			if (dis[to] != 1e18) continue;
			pre[to] = cur;
			dis[to] = dis[cur] + 1;
			q.emplace(to);
		}
	}

	pair<int, int> p(1e18, 0);
	rep(i, dis.size()) {
		if (i == s) continue;
		for (auto to : g[i]) {
			if (to == s) p = min(p, make_pair(dis[i], i));
		}
	}

	if (p.first == 1e18) return vector<int>();

	// cout << pre << endl;

	vector<int> path{s};
	int cur = p.second;
	while (pre[cur] != -1) {
		path.emplace_back(cur);
		cur = pre[cur];
	}
	return path;
}

signed main() {
	int n, m;
	cin >> n >> m;

	Graph g(n);
	rep(i, m) {
		int u, v;
		cin >> u >> v;
		u--;
		v--;
		g[u].emplace_back(v);
	}
	//if (not hasLoop(g)) {
	//	cout << -1 << endl;
	//	return 0;
	//}

	vector<int> ans(n + 1);
	rep(i, n) {
		auto v = bfs(i, g);
		if (v.empty()) continue;
		if (v.size() < ans.size()) { ans = v; }
	}
	if(ans.size() == n + 1){
		cout << -1 << endl;
		return 0;
	}
	cout << ans.size() << endl;
	for (auto i : ans) { cout << i + 1 << endl; }
	return 0;
}


Measured memory_bytes: 384
using System;
using System.Collections.Generic;

class Program {

    static Dictionary<string, string> keyList = SetKeyList();

    static int Main(string[] args) {
        List<string> list = new List<string>();

        while (true) {
            string v = Console.ReadLine();
            if (string.IsNullOrEmpty(v) == true) { break; }

            list.Add(v);
        }

        for (int i = 0; i < list.Count; i++) {
            Decrypt(list[i]);
        }

        return 0;
    }

    static void Decrypt(string v) {
        for (int i = 0; i < 26; i++) {
            if (v.Contains("the") || v.Contains("this") || v.Contains("that")) { break; }
            v = DecryptOne(v);
        }

        Console.WriteLine(v);
    }

    static string DecryptOne(string v) {
        string r = "";

        for (int i = 0; i < v.Length; i++) {
            r += keyList[v.Substring(i, 1)];
        }
        return r;
    }

    static Dictionary<string, string> SetKeyList() {
        Dictionary<string, string> list = new Dictionary<string, string>();
        list.Add("a", "z");
        list.Add("b", "a");
        list.Add("c", "b");
        list.Add("d", "c");
        list.Add("e", "d");
        list.Add("f", "e");
        list.Add("g", "f");
        list.Add("h", "g");
        list.Add("i", "h");
        list.Add("j", "i");
        list.Add("k", "j");
        list.Add("l", "k");
        list.Add("m", "l");
        list.Add("n", "m");
        list.Add("o", "n");
        list.Add("p", "o");
        list.Add("q", "p");
        list.Add("r", "q");
        list.Add("s", "r");
        list.Add("t", "s");
        list.Add("u", "t");
        list.Add("v", "u");
        list.Add("w", "v");
        list.Add("x", "w");
        list.Add("y", "x");
        list.Add("z", "y");
        list.Add(" ", " ");
        list.Add(".", ".");
        return list;
    }
}

Measured memory_bytes: 9764
import java.util.*;	
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		String[] c = new String[n];
		for(int i = 0;i < n;i++) {
			c[i] = sc.next();
		}
		for(int i = 0;i < m+2;i++)System.out.print("#");
		System.out.println();
		for(int i = 0;i < n;i++) {
			System.out.println("#"+c[i]+"#");
		}
		for(int i = 0;i < m+2;i++)System.out.print("#");
		System.out.println();
	}

}

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

using namespace std;

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	if(a == b)cout << c << endl;
	else if(a == c)cout << b << endl;
	else if(b == c)cout << a << endl;

		return 0;
}


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

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

  int ans = 0;
  for (int i = 1; i <= N; i++) {
    if (((int)log10(i) + 1) % 2 == 1) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3892
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace ABC162
{
    class Program
    {
        static void Main(string[] args)
        {
 
            var N = int.Parse(Console.ReadLine());
            long o= 0;
            for(int i = 0; i <= N; i++)
            {
                if (i % 3 == 0 || i % 5 == 0) continue;
                o += i;
            }
            Console.WriteLine(o);
        }
    }
}

Measured memory_bytes: 27536
#include <bits/stdc++.h>
using namespace std;typedef long long ll;typedef string str;
typedef vector<str> vst;
typedef vector<ll> vll;
// ll gcd(ll a, ll b){if (b==0){return a;}return gcd(b, a%b);}
// for (ll i=0;i<n;i++) {
// sort(.begin(),.end());
int main(){
  ll n;
  cin>>n;
  vll w(n);
  for (ll i=0;i<n;i++) cin>>w[i];
  vll wf(n),wb(n);
  wf[0]=w[0];
  wb[n-1]=w[n-1];
  for (ll i=1;i<n;i++) {
    wf[i]=wf[i-1]+w[i];
    wb[n-1-i]=wb[n-i]+w[n-1-i];
  }
  
  vll ab(n-1);
  for (ll i=0;i<n-1;i++) {
    ab[i]=abs(wf[i]-wb[i+1]);
  }
  sort(ab.begin(),ab.end());
  cout<<ab[0];
}

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

int main() {
  int N, sum, answer, i;
  int sum1=0, sum2=0;
  cin >> N;
  vector<int> vec(N), compare(N-1);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  for (int i = 0; i < N-1; i++) {
    for (int j = 0; j <= i; j++) {
    sum1+=vec.at(j);
    }
    for (int j = i + 1; j <= N-1; j++) {
    sum2+=vec.at(j);
    }
    sum=sum1-sum2;
    if (sum<0){
    compare.at(i)=-1*sum;
    }
    else{
    compare.at(i)=sum;
    }
    sum1=0;
    sum2=0;
  }
  answer=compare.at(0);
  for (int i = 1; i <= N-2; i++) {
    if(answer>=compare.at(i)){
   	answer=compare.at(i);
    }
  }
  cout << answer << endl;
}



Measured memory_bytes: 256
n=int(input())
ab=[]
for i in range(n):
    a=[int(j) for j in input().split()]
    ab.append(a)

from operator import itemgetter
ab.sort(key=itemgetter(1))

p=0
for i in range(n):
    p+=ab[i][0]
    if ab[i][1]<p:
        print("No")
        import sys
        sys.exit()

print("Yes")

Measured memory_bytes: 41308
// -*- coding:utf-8-unix -*-

use proconio::input;

fn main() {
    input! {
        n: usize,
        m: usize,
        k: u64,
        a: [u64; n],
        b: [u64; m],
    }

    let mut ans = 0;
    let mut total_time: u64 = b.iter().sum();
    let mut b_idx = m;

    for a_idx in 0..a.len() + 1 {
        while b_idx > 0 && total_time > k {
            b_idx -= 1;
            total_time -= b[b_idx];
        }
        if total_time > k {
            break;
        }

        ans = ans.max(a_idx + b_idx);
        if a_idx == n {
            break;
        }

        total_time += a[a_idx];
    }
    println!("{}", ans);
}


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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define endl "\n"

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

  int N,M;
  cin>>N>>M;
  vector<int>H(N);
  for(int i=0;i<N;i++)cin>>H[i];
  vector<bool>A(N,true);
  for(int i=0;i<M;i++){
    int a,b;
    cin>>a>>b;
    a--,b--;
    if(H[a]<H[b])swap(a,b); //Ha>Hb
    if(H[a]==H[b])A[a]=false,A[b]=false;
    else A[b]=false;
  }
  int ans=0;
  for(auto it:A)ans+=it;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3732
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

int get_front(int v)
{
    int ret = 0;
    while (v > 0)
    {
        ret = v % 10;
        v /= 10;
    }
    return ret;
}

int get_back(int v) { return v % 10; }

int main()
{
    array<array<int64_t, 10>, 10> table;
    for (auto& v : table)
    {
        std::fill(v.begin(), v.end(), 0);
    }
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        const auto front = get_front(i);
        const auto back = get_back(i);
        table[front][back]++;
    }

    int64_t ans = 0;

    for (int i = 1; i <= 9; i++)
    {
        for (int j = 1; j <= 9; j++)
        {
            ans += table[i][j] * table[j][i];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] x = new int[n];
		int[] y = new int[n];
		for ( int i = 0; i < n; i++ ) {
			x[i] = in.nextInt();
			y[i] = in.nextInt();
		}

		// ベクトルとその個数を格納するマップ
		HashMap<String, Integer> vectorCnt = new HashMap<>();
		String vec = "";

		// 総当たりで2点間のベクトルを見ていく b:ball
		for ( int b1 = 0; b1 < n; b1++ ) {
			for ( int b2 = 0; b2 < n; b2++ ) {

				int dx = x[b2] - x[b1];
				int dy = y[b2] - y[b1];				
				vec = String.valueOf(dx) + "_" + String.valueOf(dy);
              	// ↑ 配列ではなく文字列に変換しないとマップのキーとして機能しなかった

				// 0移動はカウントしない
				if ( !(dx == 0 && dy == 0) ) {
					// ベクトルがマップにあったら個数を加算
					if ( vectorCnt.containsKey(vec) ) {
						vectorCnt.put(vec, vectorCnt.get(vec) + 1);
					}
					// 無かったら登録して個数は１
					else {
						vectorCnt.put(vec, 1);
					}
				}
			}
		}

		// 同種ベクトルの個数の最大値を取得
		int maxV = 0;
		for ( Integer val : vectorCnt.values() ) {
			if ( maxV < val ) maxV = val;
		}

		System.out.println(n - maxV);
		in.close();
	}
}


Measured memory_bytes: 25684
#include <bits/stdc++.h>
using namespace std;
typedef complex<double> cp;
const double pi = acos(-1);
const int maxn = 3000;
int n, l;
int a[maxn + 10];
cp ans;

int calc(int x) {
	return x < 0 ? x + l : x;
}

cp trans(double t) {
	return cp{cos(t / l * 2 * pi), sin(t / l * 2 * pi)};
}

void shift() {
	int tmp = a[1];
	for (int i = 1; i < n; ++i) a[i] = a[i + 1];
	a[n] = tmp;
}

void solve() {
	cp sum = 0; int cnt = 0;
	for (int i = n - 1; i >= 2; --i) {
		++cnt;
		sum += trans(-calc(a[1] - a[i + 1]) / 2.);
		cp mid = trans(a[1] + calc(a[i] - a[1]) / 2.);
		ans += (trans(a[1]) - mid) * sum + mid * cp(cnt);
	}
}

int main() {
	scanf("%d%d", &n, &l);
	for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
	for (int i = 1; i <= n; ++i) {
		solve(); shift();
	}
	ans = ans / cp((1ll * n * (n - 1) * (n - 2) / 2));
	printf("%.10lf %.10lf", ans.real(), ans.imag());
}


Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;

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

    if (a == 'H' && b == 'H') {
        cout << 'H' << endl;
    }
    else if (a == 'H' && b == 'D') {
        cout << 'D' << endl;
    }
    else if (a == 'D' && b == 'H') {
        cout << 'D' << endl;
    }
    else if (a == 'D' && b == 'D') {
        cout << 'H' << endl;
    }
}

Measured memory_bytes: 256
#include <cstdio>
#include <cctype>
#include <climits>
#include <vector>
using namespace std;

#define si static inline
#define gcu getchar_unlocked
si int in() {
	int c, n = 0;
	// bool minus = false; if ((c = gcu()) == '-') minus = true; else ungetc(c, stdin);
	while ((c = gcu()) >= '0' && c <= '9') n = 10 * n + (c - '0');
	return n; }
	// return minus ? -n : n; }
si void scan(char *s) {while (!isspace(*s++ = gcu()));}
#define pcu putchar_unlocked
#define svo si void out
template <typename T>
svo(T n) {
	static char buf[20];
	char *p = buf;
	//if(n < 0) pcu('-'), n *= -1;
	if (!n) *p++ = '0';
	else while (n) *p++ = n % 10 + '0', n /= 10;
	while (p != buf) pcu(*--p); }
svo(const char *s){while(*s)pcu(*s++);}
svo(char *s){while(*s)pcu(*s++);}
svo(char c){pcu(c);}
template <typename T>
//svo(vector<T> &v){for(T &x:v)out(' '),out(x);out('\n');}
svo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
template <typename head, typename... tail>
svo(head&& h, tail&&... t){out(h);out(move(t)...);}
#undef svo
#undef si

template <typename T>
struct heap{
	vector<T> h = {T()};

	void insert(T x) {
		h.push_back(x);
		int c = h.size() - 1;
		for (int p = c / 2; p; c = p, p /= 2)
			if (h[p] < x)
				h[c] = move(h[p]);
			else
				break;
		h[c] = move(x);
	}
	T extract() {
		T res = move(h[1]);
		h[1] = h.back();
		T v = move(h[1]);
		h.pop_back();

		int p = 1, H = h.size();
		for (int c = 2; c < H; p = c, c = p * 2) {
			if (c + 1 < H && h[c] < h[c + 1])
				c++;
			if (h[c] < v)
				break;
			h[p] = move(h[c]);
		}
		h[p] = move(v);

		return move(res);
	}

	bool empty() {
		return h.size() == 1;
	}
};

#define v vector
struct graph {
	struct node {int n, w;};
	v<v<node>> nodes;

	void read(int n) {
		nodes.resize(n);
		for (auto &x: nodes) {
			in();
			for (int k = in(); k--;) {
				int c = in();
				x.push_back({c, in()});
			}
		}
	}

	v<node> dks() {
		v<node> w(nodes.size(), {0, INT_MAX});
		w[0].w = 0;
		heap<node> q;
		q.insert({0, 0});
		while (!q.empty()) {
			node n = q.extract();
			if (w[n.n].n)
				continue;
			w[n.n].n = 1;
			for (node &x: nodes[n.n]) {
				int a = n.w + x.w;
				if (w[x.n].w > a) {
					w[x.n].w = a;
					q.insert({x.n, a});
				}
			}
		}
		return move(w);
	}
};

bool operator < (const graph::node &a, const graph::node &b) {
	return a.w > b.w;
}

int main() {
	graph g;
	g.read(in());
	int i = 0;
	for (auto &x: g.dks())
		out(i++, ' ', x.w, '\n');
}


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

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

typedef long long ll;
typedef pair<int, int> p;

struct UnionFind {
  // 要素に対応する値は自分の根。根は要素数の-1倍したものを代入する。
  // 根ならそのグループの要素数(負)が、子であれば親の番号が入る。初期値-1。
  vector<int> uni;
  UnionFind(){
    uni = vector<int>(100100, -1);
  }

  // 頂点aの所属するグループを調べる。
  int root(int a)
  {
    // uni[a]が負の値なら親はa自身
    if (uni[a] < 0) return a;
    // 正の値であれば、親ルートを調べ戻り値で根に直接つなぐ。
    else {
      uni[a] = root(uni[a]);
      return uni[a];
      // return uni[a] = root(uni[a]);
    }
  }

  // 頂点aとbをつなぐ、もともと同じグループの場合falseを返す。
  bool connect(int a, int b)
  {
    a = root(a);
    b = root(b);
    if (a == b) return false;

    // aを大きなグループにしたいので、逆であれば入れ替える。
    if (uni[a] > uni[b])
    {
      int hoge = a;
      a = b;
      b = hoge;
    }

    //aとbを結合し、bをaの親とする。
    uni[a] += uni[b];
    uni[b] = a;
    return true;
  }

  //  頂点a, bが同じグループか
  bool isConnect(int a, int b)
  {
    return root(a) == root(b);
  }

  // 頂点aを含むグループの頂点数を調べる
  int size(int a)
  {
    return -uni[root(a)];
  }

};

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<map<char, int>> v(n);
  for (int i = 0; i < n; i++) {
    string tmp;
    cin >> tmp;
    for(auto a : tmp){
      v[i][a]++;
    }
  }

  ll res = 0;
  map<map<char, int>, int> count;
  for (int i = 0; i < n; i++) {
    res += count[v[i]];
    count[v[i]]++;
  }

  cout << res << endl;
}


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

int main() {
    int N;
    string S;
    cin >> N >> S;

    int count = 0;
    for (int i = 0; i < N; i++) {
        if (S.substr(i, 3) == "ABC") count++;
    }

    cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
red,green,blue=map(int,input().split())
k=int(input())
for i in range(k+1):
  if red<green<blue:
    print('Yes')
    sys.exit()
  elif green<=red:
    green*=2
  elif blue<=green:
    blue*=2
print('No')  

Measured memory_bytes: 9148
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;


typedef long long i64;
const int inf = (int)1.05e9;

i64 compute_next(i64 v)
{
	assert(v > 0);
	for(int i = 61; i >= 0; --i) {
		if((1LL << i) & v) {
			return (1LL << (i + 1));
		}
	}
	return -1;
}

int main()
{
	int n;
	vector<i64> as;

	scanf("%d", &n);
	as.resize(n);
	for(int i = 0; i < n; ++i) {
		scanf("%lld", &as[i]);
	}

	sort(as.begin(), as.end());

	vector<pair<i64,int>> bs;

	for(int i = 0; i < n; ++i) {
		const i64 v = as[i];
		if(bs.size() > 0 && bs[bs.size() - 1].first == v) {
			bs[bs.size() - 1].second += 1;
		} else {
			bs.push_back({v, 1});
		}
	}

	int ans = 0;

	for(int it = bs.size() - 1; it >= 0; --it) {

		const i64 v = bs[it].first;
		const int c = bs[it].second;

		const i64 w = compute_next(v) - v;

		if(w > v) {
			continue;
		}

		if(w == v) {
			ans += c / 2;
			continue;
		}

		auto sv = make_pair(w, 0);
		int w_idx = lower_bound(bs.begin(), bs.end(), sv) - bs.begin();

		if(bs[w_idx].first != w) {
			continue;
		}

		int used = min(bs[w_idx].second, c);
		bs[w_idx].second -= used;
		ans += used;
	}

	printf("%d\n", ans);

	return 0;
}

/* waffle */


Measured memory_bytes: 7792