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

constexpr int MAX = 200010;

ll subcalc(ll x) { return x * (x + 1) / 2; }

int n;
int c[MAX];
vector<int> G[MAX];

int sz[MAX];
stack<int> last[MAX];
ll ans[MAX];

// 部分木のサイズを求める
void dfs1(int v, int p) {
    sz[v] = 1;
    for(int u : G[v]) {
        if(u != p) {
            dfs1(u, v);
            sz[v] += sz[u];
        }
    }
}

// 答えの計算
void dfs2(int v, int p) {
    if(v == 0) {
        for(int i = 1; i <= n; i++)
            last[i].push(n);
        dfs2(1, 0);
        for(int i = 1; i <= n; i++)
            ans[i] += subcalc(last[i].top());
    } else {
        last[c[v]].top() -= sz[v];

        for(int u : G[v]) {
            if(u != p) {
                last[c[v]].push(sz[u]);
                dfs2(u, v);
                ans[c[v]] += subcalc(last[c[v]].top());
                last[c[v]].pop();
            }
        }
    }
}

int main() {
    cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> c[i];
        last[i].push(n);
    }
    for(int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    dfs1(1, 0);
    dfs2(0, 0);

    for(int i = 1; i <= n; i++)
        cout << subcalc(n) - ans[i] << endl;

    return 0;
}

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

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;

#define deb(x) cerr<<#x<<":"<<x<<"\n";
#define dvi(x) for(ll i=0;i<x.size();i++)cerr<<#x<<"["<<i<<"]:"<<x[i]<<" ";
#define iter(v) for(auto it:v)
#define wt ll t;cin>>t;while(t--)
#define rl(x) ll x;cin>>x;
#define rvi(x,n) vi x(n);for(ll i=0;i<n;i++) cin>>x[i];
#define rs(x) string x;cin>>x;
#define w(x) cout<<x<<endl;
#define wvi(x) for(ll i=0;i<x.size();i++) cout<<x[i]<<" ";cout<<endl;
#define ws(x) cout<<x<<endl;
#define all(v) v.begin(),v.end()
#define pb push_back
#define ppb pop_back
#define pll pair<ll, ll>
#define fo(i,n) for(ll i=0;i<n;i++)
#define forr(i,a,b) for(ll i=a;i<b;i++)
#define yes cout<<"YES\n";
#define no cout<<"NO\n";
const ll N = pow(2,32);

map<long long, long long> factorize(long long n) {	//returns map containing factor and multiplicity, Eg: 60 = {{2,2},{3,1},{5,1}}
	map<long long, long long> ans;
	for (long long i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ans[i]++;
			n /= i;
		}
	}
	if (n > 1) {
		ans[n]++;
		n = 1;
	}
	return ans;
}

void FAST() {	//FAST Input Output, DONT use both scnaf,prllf / cin,cout , Use any ONE system
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

long long binpow(long long a, long long b, long long m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
    //    freopen("output.txt", "w", stdout);
    #endif
	FAST();
	rl(n)
    rvi(a,n)
    ll ans=0;
    forr(i,1,n)
    {
        if(a[i]>=a[i-1])continue;
        ans+=a[i-1]-a[i];
        a[i]=a[i-1];
    }
    cout<<ans;
}

Measured memory_bytes: 4780
#include <iostream>
using namespace std;
int count = 0;

int binarySearch(int arr[], int l, int r, int x)
{
    if (r >= l) {
        int mid = l + (r - l)/2;
        if (arr[mid] == x) {
            count++;
            return mid;
        }if (arr[mid] > x) return binarySearch(arr, l, mid-1, x);
        return binarySearch(arr, mid+1, r, x);
    }
    return -1;
}

int main() {
    int m, n;
    cin >> m;
    int array1[m] = {};
    for (int i = 0; i < m; i++) cin >> array1[i];
    cin >> n;
    int array2[n] = {};
    for (int j = 0; j < n; j++) cin >> array2[j];
    for (int i = 0; i < n; i++) binarySearch(array1, 0, m - 1, array2[i]);
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3696
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll a, b, c;std::cin >> a >> b >> c;
  std::cout << (b-a==c-b?"YES":"NO") << '\n';
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll read(){
	ll a=0,b=getchar(),c=1;
	while(!isdigit(b))c=b=='-'?-1:1,b=getchar();
	while(isdigit(b))a=a*10+b-'0',b=getchar();
	return a*c;
}
string s,t;
int main(){
	cin >> s >> t;
	cout << t << s;
	return 0;
}

Measured memory_bytes: 764
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
using namespace std;
char a[205], b[205];
int main(){
	scanf("%s", a + 1);
	scanf("%s", b + 1);
	int len1 = strlen(a + 1);
	int len2 = strlen(b + 1);
	if(len1 > len2) printf("GREATER\n");
	else if(len1 < len2) printf("LESS\n");
	else{
		for(int i = 1; i <= len1; i++){
			if(a[i] > b[i]){
				printf("GREATER\n");
				return 0;
			}
			else if(a[i] < b[i]){
				printf("LESS\n");
				return 0;
			}
		}
		printf("EQUAL\n");
	}
	return 0;
}
			


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


int main() {

  long long N, A, B, C, D, E;
  cin >> N >> A >> B >> C >> D >> E;

  long long min_ = A;
  
  min_ = min(min_, B);
  min_ = min(min_, C);
  min_ = min(min_, D);
  min_ = min(min_, E);

  long long answer = ceil((double) (N - min_) / min_) + 5;

  cout << answer << endl;

  return 0;

}

Measured memory_bytes: 256
n,m,x = map(int,input().split())
a = list(map(int,input().split()))
S1 = 0
S2 = 0
for i in a:
    if i in range(x,n):
        S1 += 1
    if i in range(1,x):
        S2 += 1
print(min(S1,S2))

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

int main() {
    double A, B, H, M, s, t, ans;
    cin >> A >> B >> H >> M;

    t = M*6;
    s = 30*H+30*(M/60);

    ans = A*A+B*B-2*A*B*cos(abs(t-s)*M_PI/180);
    ans = sqrt(ans);

    printf("%.10f\n", ans);
} 




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

#ifdef ONLINE_JUDGE
#define freopen \
  if (0) freopen
#define cerr \
  if (0) cerr
#endif

#define fi first
#define se second

#define pb push_back
#define pp pop_back
#define mp make_pair

#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)

#define sqr(a) ((a)*1ll * (a))
#define sz(a) (int)a.size()
#define len(a) (int)a.length()
#define all(a) a.begin(), a.end()
#define nl '\n'

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pi;

const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
const ll linf = (ll)1e18 + 7;

int n, c;
int dp[500][500];
int a[500], b[500];
int p[500][500], pw[500][500];

void solve() {
  cin >> n >> c;
  rep(i, 1, n) cin >> a[i];
  rep(i, 1, n) cin >> b[i];

  rep(i, 1, 500) {
    pw[i][0] = 1;
    rep(j, 1, 500) {
      pw[i][j] = (pw[i][j - 1] * 1ll * i) % mod;
    }
  }

  rep(i, 1, n) {
    rep(j, 0, c) {
      rep(k, a[i], b[i]) {
        p[i][j] += pw[k][j];
        p[i][j] %= mod;
      }
    }
  }

  dp[0][0] = 1;
  rep(i, 1, n) {
    dp[i][0] = b[i] - a[i] + 1;
    rep(j, 1, i - 1) {
      dp[i][0] = (dp[i][0] * 1ll * (b[j] - a[j] + 1)) % mod;
    }
  }

  rep(i, 1, n) {
    rep(j, 1, c) {
      rep(k, 0, j) {
        dp[i][j] += (dp[i - 1][j - k] * 1ll * p[i][k]) % mod;
        dp[i][j] %= mod;
      }
    }
  }

  cout << dp[n][c];
}

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

  freopen(".in", "r", stdin);

  solve();

  return 0;
}

Measured memory_bytes: 6116
# -*- coding: utf-8 -*-
"""
Created on Mon Jul 29 02:06:58 2019

@author: matsui
"""


N=int(input())


P=input().split()

count=0
for i in range(N):
    if i+1 != int(P[i]):
        count+=1
        
if count==2 or count==0:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <string> 
#include <vector>
#include <iomanip>
using namespace std;

int main()
{
	string s;
	cin >> s;
	int size = s.size();
	cout << s.at(0) << size - 2 << s.at(size - 1) << endl;
}

Measured memory_bytes: 256
N=int(input())
from collections import defaultdict
branch=defaultdict(dict)
for i in range(N-1):
    u,v,w=map(int,input().split())
    branch[u-1][v-1]=w
    branch[v-1][u-1]=w
dist=[float('inf')]*N
dist[0]=0
check={0}
while len(check)>0:
    now=check.pop()
    for nex,w in branch[now].items():
        if dist[nex]>dist[now]+w:
            dist[nex]=dist[now]+w
            check|={nex}
color=[d%2 for d in dist]
for i in range(N):
    print(color[i])

Measured memory_bytes: 58516
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <string>
#include <limits>
#include <algorithm>
#include <map>
#include <sstream>

using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
static ull tenq = 1000000000;
static ull mod = tenq + 7;

using namespace std;

int main()
{
  ll N;
  cin >> N;
  vector<vector<ll>> ss(2, vector<ll>(0));
  ll n = 2;
  ll cur = 2;
  ll partner = 0;
  ss[0] = {1};
  ss[1] = {1};
  while (n <= N) {
    if (cur >= ss.size()) ss.push_back(vector<ll>());
    ss[cur].push_back(n);
    ss[partner].push_back(n);
    partner++;
    n++;
    if (partner == cur) {
      cur++;
      partner = 0;
    }
  }
  if (ss.size() == cur && partner == 0) {
    cout << "Yes" << endl;
    cout << ss.size() << endl;
    for (auto i = 0; i < ss.size(); i++) {
      cout << ss[i].size();
      for (auto j = 0; j < ss[i].size(); j++) {
        cout << " " << ss[i][j];
      }
      cout << endl;
    }

  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 3200
from functools import reduce

def g(a,b):
    while b:
        a, b = b, a % b
    return a

def l(a,b):
    return a*b//g(a,b)
    
def g_list(nums):
    return reduce(g, nums)

def l_list(nums):
    return reduce(l, nums, 1)


input()
li = input().split()
ili = []
for a in li:
    ili.append(int(a))
ll = l_list(ili)
ans = 0
for i in ili:
    ans += (ll-1) % i
print(ans)

Measured memory_bytes: 3812
import math

k = int(input())

ans = 0

IJ = [[0 for j in range(k+1)] for i in range(k+1)]

for i in range(1, k+1):
    for j in range(1, k+1):
        IJ[i][j] = math.gcd(i, j)

for i in range(1, k+1):
    for j in range(1, k+1):
        for h in range(1, k+1):
            ans += math.gcd(IJ[i][j], h)


print(ans)


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

int main(){
  int64_t N;
  cin >> N;
  if(N==1){
    cout << 0 << endl;
    return 0;
  }
  map<int64_t,int> m;
  int64_t a=2;
  int64_t n=N;
  while(a*a<=n){
    if(n%a==0){
      n/=a;
      if(m.count(a)){
        m.at(a)++;
      }else{
        m[a]=1;
      }
    }else{
      a++;
    }
  }
  if(m.count(n)){
    m.at(n)++;
  }else{
    m[n]=1;
  }
  int64_t ans=0;
  for(auto p:m){
    for(int i=1;;i++){
      ans++;
      p.second-=i;
      if(p.second<=i){
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define MOD(x) ((x)%mod)
int n;
int a[200];
int sum;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		sum+=a[i];
	}
	sort(a+1,a+1+n);
	if(sum%10==0)
	{
		for(int i=1;i<=n;i++)
		{
			if(a[i]%10!=0)
			{
				printf("%d",sum-a[i]);
				return 0;
			}
		}
	}
	if(sum%10==0) printf("0");
	else printf("%d",sum);
	return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)
	var ans, c int
	for i := 0; i < len(s); i++ {
		if s[i] == 'R' {
			c++
		} else {
			c = 0
		}
		if ans < c {
			ans = c
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1768
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define ld long double
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))
#define pii pair<int,int>
#define pll pair<ll,ll>
#define INF 1e9
#define INFL 1e18
#define mod 1000000007
//#define mod 998244353
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
using namespace __gnu_pbds; 
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> os;
typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update> os_pair;

ll power(ll x,ll n){ll res =1;while(n>0){if(n%2==1){res=res*x;}x=x*x;n=n/2;}return res;}
ll powm(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

//cout<< fixed << setprecision(10)
//__builtin_popcountll()

int main(){

    fast;
    int T;
    T=1;
    //cin>>T;
    while(T--){
    	ll n,i,j;
    	cin>>n;
    	ll a[n];
    	for(i=0;i<n;i++)
    	{
    		cin>>a[i];
		}
		ll ans=0;
		for(i=1;i<n;i++)
		{
			if(a[i]<a[i-1])
			{
				ans=ans+a[i-1]-a[i];
				a[i]=a[i-1];
			}
		}
		cout<<ans<<"\n";

    }

}

Measured memory_bytes: 5164
n = int(input())
s = input()

e = [0 for _ in range(n)]
w = [0 for _ in range(n)]

for i in range(1, n):
    w[i] = w[i - 1] + 1 if s[i - 1] == 'W' else w[i - 1]
    e[-i - 1] = e[-i] + 1 if s[-i] == 'E' else e[-i]

res = [0 for _ in range(n)]

for i in range(n):
    res[i] = w[i] + e[i]

print(min(res))


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

int main() {
  int para = 0;
  int num =0, dig=0, sum =0;

  cin >> para;
  num = para;
  while(num){
    dig = num % 10;
    sum += dig;
    num /= 10;
  }
  if(para % sum == 0){
     cout << "Yes";    
  } else {
     cout << "No";
  }
  
}


Measured memory_bytes: 256
#include<stdio.h>
#include<queue>
#include<assert.h>
#include<tuple>
#include<string>
#include<algorithm>
#include<iostream>
#include<map>
#include<string.h>
#include<vector>
#include<math.h>
#include<stdlib.h>
#include<set>
#include<ctype.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef tuple<int,int,int> t3;

const int MX = 1 << 18;
const int MM = 1000000007;

double D[MX];

int main()
{
	int N, d, x;
	scanf("%d%d%d", &N, &d, &x);
	double t = 1;
	D[1] = 1;
	for(int i = 2; i <= N; i++) D[i] = D[i-1] + 1.0 / i * D[i-1] + 1;
	printf("%.10lf\n", D[N] * (2*d + (2*N-1)*x) / 2.0);
}


Measured memory_bytes: 1792
using System;

namespace _2629
{
	class Program
	{
		static void Main(string[] args)
		{
			double d = double.Parse(Console.ReadLine());
			double ret = d * Math.Sqrt(2);
			Console.WriteLine(Math.Max(ret, Math.Ceiling(d + 0.0001)));
		}
	}
}


Measured memory_bytes: 15976
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
 
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define C(i) cin>>i
#define C2(i,j) cin>>i>>j
#define C3(i,j,k) cin>>i>>j>>k
#define C4(i,j,k,m) cin>>i>>j>>k>>m
////////////////////////////////////////////////////////////

int main(){
  int n,a;
  cin >> n >>a;
  cout << n*n - a << endl;
  ret 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef vector<int> vec1;
typedef vector<string> vec2;
typedef vector<double> vec3;

int main() {
  
  int n, m, x, y;
  cin >> n >> m >> x >> y;
  vec1 z(n);
  for(int i = 0; i < n; i++) cin >> z.at(i);
  vec1 b(m);
  for(int i = 0; i < m; i++) cin >> b.at(i);

  int c = 0;
  for(int i = x+1; i <= y; i++) {
    c = 0;
    for(int j = 0; j < n; j++) {
      if(z.at(j) < i) {
        continue;
      } else {
        c++;
        break;
      }
    }
    if(c == 1) continue;
    c = 0;
    for(int j = 0; j < m; j++) {
      if(b.at(j) >= i) {
        continue;
      } else {
        c++;
        break;
      }
    }
    if(c == 0) {
      cout << "No War" << endl;
      return 0;
    }
  }
  cout << "War" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
	int a,b,d,r;
	double f2;
	scanf("%d %d",&a,&b);
	d=a/b;
	r=a%b;
	f2=1.0*a/b;
	printf("%d %d %f\n",d,r,f2);
	return 0;
}

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

//#define int long long
#define ll long long
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    int n; cin >> n;
    vl c(n-1),s(n-1),f(n-1);
    rep(i,n-1)cin >> c[i] >> s[i] >> f[i];
    rep(i,n){
        ll t = 0;
        exrep(j,i,n-1){
            if(t <= s[j])t=s[j];
            else if(t%f[j] == 0);
            else t+=f[j]-(t%f[j]);
            t+=c[j];
        }
        out(t);
    }
}


Measured memory_bytes: 256
n,k=map(int,input().split())
A = list(map(int,input().split()))
lA = len(A)
mod=10**9+7
cnt1=0
for i in range(lA):
    for j in range(i+1,lA):
        if A[i] > A[j]:
            cnt1+=1
cnt2=0
for i in range(lA):
    for j in range(lA):
        if A[i] > A[j]:
            cnt2+=1
print((cnt1*k+cnt2*(k*(k-1)//2))%mod)

Measured memory_bytes: 3188
#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, M, tmp;
    cin >> N >> M;
    vector<int> k(M), p(M);
    vector<vector<int>> s(M);
    rep(i,M) {
        cin >> k.at(i);
        rep(j,k.at(i)) {
            cin >> tmp;
            s.at(i).push_back(tmp);
        }
    }
    rep(i,M) cin >> p.at(i);

    int ans = 0;
    for (int bit = 0; bit < (1<<N); bit++) {
        bool ok = true;
        rep(i,M) {
            //電球Mについて調べる
            int count = 0;
            rep(j,k.at(i)) {
                if (bit & (1<<s.at(i).at(j)-1)) {
                    ++count;
                }
            }
            if (count % 2 != p.at(i)) {
                ok = false;
                break;
            }
        }
        if (ok) ++ans;
    }
    cout << ans << endl;
}


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

int main () {
    vector<vector<vector<int>>> tenant(4, vector<vector<int>>(3, vector<int>(10)));

    int n, b, f, r, v;
    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> b >> f >> r >> v;
        tenant[b-1][f-1][r-1] += v;
    }
    for (int i = 0; i < tenant.size(); i++) {
        for (int j = 0; j < tenant[i].size(); j++) { 
            for (int k = 0; k < tenant[i][j].size(); k++) {
                printf(" %d", tenant[i][j][k]);
            }
            printf("\n");
        }
        if (i != tenant.size() - 1)
            printf("####################\n");
    }
}


Measured memory_bytes: 3272
#include <bits/stdc++.h>
 
using namespace std;
 
#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
 
int const MAX = 200011;
 
typedef long long ll;
 
class Union_Find {
public:
  int par[MAX], rank[MAX], size[MAX], gnum;
     
  Union_Find(int N) {
    gnum = N;
    for (int i = 0; i < N; i++) {
      par[i] = i;
      rank[i] = 0;
      size[i] = 1;
    }
  }
 
  int find(int x)
  {
    if (par[x] == x) {
      return x;
    }
    return par[x] = find(par[x]);
  }
 
  void unite(int x, int y)
  {
    x = find(x);
    y = find(y);
    if (x == y) return;
         
    if (rank[x] < rank[y]) {
      par[x] = y;
      size[y] += size[x];
    } else {
      par[y] = x;
      size[x] += size[y];
      if (rank[x] == rank[y]) {
    rank[x]++;
      }
    }
    gnum--;
  }
 
  bool same(int x, int y)
  {
    return (find(x) == find(y));
  }
 
  int getSize(int x)
  {
    return size[find(x)];
  }
 
  int groups()
  {
    return gnum;
  }
};
 
int main()
{
   
  int N; cin >> N;
  Union_Find uf(N);
 
  vector<tuple<ll, int, int>> vs;
 
  rep(i, N) {
    int a, b; ll c; cin >> a >> b >> c;
    vs.emplace_back(c, a, b);
  }
 
  sort(vs.begin(), vs.end());
 
  ll sum = 0;
   
  rep(i, vs.size()) {
    ll c; int a, b; tie(c, a, b) = vs[i];
    if(!uf.same(a, b)) {
      sum += (ll)uf.getSize(a) * uf.getSize(b) * c;
      uf.unite(a, b);
    }
  }
   
  cout << sum << endl;
   
  return 0;
}

Measured memory_bytes: 9336
#include <iostream>
#include <string>
#include <cmath>
#include <utility>
#include <algorithm>
#include <vector>

using namespace std;
typedef std::pair<long, long> P;

bool comp(P& lhs, P& rhs) {
    return lhs.second < rhs.second;
}

int main() {
    int N;
    cin >> N;
    
    vector<P> pair_vec;

    long a, b;

    for (int i = 0; i < N; i++) {
        cin >> a >> b;
        pair_vec.push_back(P(a, b));
    }
    
    sort(pair_vec.begin(), pair_vec.end(), comp);

    long limit_time = 0;
    long work_time = 0;

    bool flag = true;

    for (int i = 0; i < N; i++) {
        limit_time = pair_vec[i].second;
        work_time += pair_vec[i].first;
        if (limit_time < work_time) {
            flag = false;
            break;
        }
    }

    if (flag) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long

#define MAX_V 105

#define MAX_N 100
#define MAX_M 100

int main() {
    string s;
    cin >> s;

    REP(i, s.size()) {
        if(s[i] == '7') {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3612
# 問題文：長さNの偶数からなる正の整数列A=a1,a2,...,aNと、整数Mが与えられます。
#        任意のk(1≤k≤N)に対して以下の条件を満たす正の整数XをAの「半公倍数」と定義します。
#        X=ak×(p+0.5)を満たす負でない整数pが存在する。
#        1以上M以下の整数のうちのAの半公倍数の個数を求めてください。
# 入力 : 以下の形式で標準入力から与えられる。
#       N M
#       a1 a2 ... aN
# 出力 : 1 以上 M 以下の整数のうちの A の半公倍数の個数を出力せよ。

# 半公倍数の個数を求める
def n_hankobaisu(M, min_hankobaisu):
    q = M // min_hankobaisu
    if q % 2 == 1:
        q += 1
    return int(q/2)

# nが何回2で割り切れるかを求める
def nankai_2de_warikireruka(n):
    i = 0

    # nは最大10^9 処理速度を上げるため、2^10で割る
    for i in range(0,99999999999):
        if n >= 1024 and n % 1024 == 0:
            n = n / 1024
            i += 10
        else:
            break

    for i in range(0,9999999999999999999):
        if n > 1:
            n, mod = divmod(n, 2)
            if mod == 1:
                break
                i += 1
        else:
            break

    return i

# 最小半公倍数を求める
def min_hankobaisu(A, M):
    result = 1
    for i in range(9999999999999):
        result = A[0] * (0.5 + i)

        if len(A) == 1:
            return result

        if result > M:
            print(0)
            exit(0)

        for j in range(1, len(A)):
            q, mod = divmod(result, A[j]/2)
            if q % 2 == 1 and mod == 0:
                # 数列要素すべての半公倍数であるので、最小半公倍数として返却する
                if j == len(A)-1:
                    return int(result)
                continue
            else:
                break # 半公倍数としてふさわしくないので、次の半公倍数候補を求める
    return int(result)

# 正の整数列Aの長さN, 半公倍数の上限M
N, M = map(int, input().split())

# 正の整数列A
A = list(set(list(map(int, input().split()))))
A.sort(reverse=True)
# hankobaisu_list = []

# 2で割り切れる回数が異なる→半公倍数はない
# → その場で終了
p = nankai_2de_warikireruka(A[0])

if N == 1:
    print(n_hankobaisu(M, min_hankobaisu(A, M)))
    exit(0)

for i in range(1, len(A)):
    pi = nankai_2de_warikireruka(A[i])
    if pi != p:
        print(0)
        exit(0)

# 半公倍数の最小値を求める

# 範囲内にいくつの半公倍数があるか求める
#print('最小半公倍数：{}'.format(min_hankobaisu))
#print(int(M/min_hankobaisu)//2 + 1)
print(n_hankobaisu(M, min_hankobaisu(A, M)))


Measured memory_bytes: 14244
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Int32;
using static System.Math;

class Program
{
    struct Position : IComparable<Position>
    {
        public int X;
        public int Y;

        public static int H;
        public static int W;

        public int CompareTo(Position other)
        {
            if (X != other.X) return X - other.X;
            return Y - other.Y;
        }

        public bool IsValid => 0 <= X && X < W && 0 <= Y && Y < H;
    }

    static void Main(string[] args)
    {
        label:
        var sp = ReadLine().Split();
        int h = Position.H = Parse(sp[0]);
        int w = Position.W = Parse(sp[1]);
        var array = new string[h];
        for (int i = 0; i < h; ++i)
        {
            array[i] = ReadLine();
        }
        var watching = new SortedSet<Position>();
        var pos = new Position();
        watching.Add(pos);
        var hosu = new int[h, w];
        hosu[0, 0] = 1;
        while (0 < watching.Count)
        {
            var min = pos = watching.Min;
            Action Check = () =>
              {
                  if (pos.IsValid && array[pos.Y][pos.X] == '.')
                  {
                      int nei = hosu[pos.Y, pos.X];
                      if (nei == 0 || hosu[min.Y, min.X] + 1 < nei)
                      {
                          hosu[pos.Y, pos.X] = hosu[min.Y, min.X] + 1;
                          watching.Add(pos);
                      }
                  }
              };
            --pos.X;
            Check();
            pos.X += 2;
            Check();
            --pos.X;
            --pos.Y;
            Check();
            pos.Y += 2;
            Check();
            watching.Remove(min);
        }
        if (hosu[h - 1, w - 1] == 0) WriteLine(-1);
        else
        {
            int result = 0;
            foreach(var line in array)
            {
                result += line.Count(c => c == '.');
            }
            WriteLine(result - hosu[h - 1, w - 1]);
        }
    }
}


Measured memory_bytes: 13524
import numpy as np

N, X, Y = map(int, input().split())
X -= 1
Y -= 1

ans = [0] * (N-1)

for i in range(N - 1):
    for j in range(i + 1, N):
        d1 = abs(j - i)
        d2 = abs(X - i) + 1 + abs(j - Y)
        ans[min(d1, d2) - 1] += 1

[print(ans[i]) for i in range(N - 1)]


Measured memory_bytes: 22152
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#define MAX 114514
using std::cout;
using std::cin;
using std::endl;

void countingSort(int *A, int *B, int n, int k){
  int C[MAX];
  for(int i=0;i<=k;i++) C[i]=0;
  for(int i=0;i<n;i++) C[A[i]]++;
  for(int i=1;i<=k+1;i++) C[i]=C[i]+C[i-1];     
  for(int j=n-1;j>=0;j--){
    B[C[A[j]]]=A[j];    C[A[j]]--;
  }
  for(int i=1;i<=n;i++){
    if(i-1) cout << " ";
    cout << B[i];
  }
  cout << endl;
}

int main(){
  int n,max=0;
  cin >> n;
  int a[n],b[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
    if(max<a[i]) max=a[i];
    b[i]=0;
  }
  countingSort(a,b,n,max);
  return 0;
}


Measured memory_bytes: 18692
#include <bits/stdc++.h>
#define vec vector<int>
using namespace std;
int main(){
	int n;
	//cin>>n;
	while(cin>>n){
	    vec v;
	for(int i=0;i<n;i++){
		int t;
		cin>>t;
		v.push_back(t);		
	}
	sort(v.begin(),v.end());
	//for(auto x:v)cout<<x<<' ';

	//cout<<endl;
	int mid;
	mid = (n/2);
	//cout<<mid<<' ';
	//auto loc = upper_bound(v.begin(),v.end(),mid);
	//cout<<loc-v.begin()<<' ';

	//auto p1 =(loc - v.begin());
	int p1 = mid-1;
	if(v[mid]>v[p1]){
		//cout<<p1<<' '<<p2<<' ';
		cout<<(v[mid]-v[p1])<<endl;	
	}
	else{
		cout<<0<<endl;
	}
		

	}
	
}

Measured memory_bytes: 892
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];puts("");}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
// int dx[]={0,1,0,-1};
// int dy[]={1,0,-1,0};//RDLU
#define yes puts("YES")
#define no puts("NO")

ll gcd(ll a,ll b){
	return b==0?a:gcd(b,a%b);
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n;
	cin>>n;
	int t=0;
	rep(i,n){
		int a;cin>>a;
		t=gcd(t,a);
	}
	cout<<t<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

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

	int x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;

	int diff_x = x2 - x1;
	int diff_y = y2 - y1;
	int x3 = x2 - diff_y;
	int y3 = y2 + diff_x;
	int x4 = x1 - diff_y;
	int y4 = y1 + diff_x;
	cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
}


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

string s[1000] = {};
int main() {
	int H, W;
	cin >> H >> W;
	for (int i = 0; i < H; i++) cin >> s[i];
	for (int i = 0; i < H + 2; i++) {
		if (i == 0||i==H+1) {
			for (int j = 0; j < W + 2; j++) cout << "#";
		}
		else cout << "#" + s[i-1] + "#";
		cout << endl;
	}
	
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
char S[1100000];
char T[1100000];
int p[1100000];
int q[1100000];
int r[1100000];
int dp[1100000];
int L[1100000];
int R[1100000];
int main(){
	int a;scanf("%d",&a);
	scanf("%s%s",S,T);
	int at=a-1;
	for(int i=a-1;i>=0;i--){
		while(at>=0&&(at>i||S[at]!=T[i])){
			at--;
		}
		p[i]=at;
		q[at]=1;
		r[at]=max(i,r[at]);
	}
	//for(int i=0;i<=a;i++)q[i+1]+=q[i];
	bool ok=true;
	for(int i=0;i<a;i++)if(S[i]!=T[i])ok=false;
	if(ok){
		printf("0\n");return 0;
	}
	if(at<0){
		printf("-1\n");return 0;
	}
	int ret=0;
	int cur=0;
	int last=999999999;
	int sz=0;
	for(int i=0;i<a;i++){
		if(q[i]){
			L[sz]=i;
			R[sz++]=r[i];
		}
	}
	for(int i=0;i<sz;i++){
		if(L[i]==R[i])continue;
		int left=0;
		int right=sz-i;
		while(left+1<right){
			int M=(left+right)/2;
			if(L[i+M]-M>=R[i]){
				right=M;
			}else left=M;
		}
		ret=max(ret,right);
	}
	printf("%d\n",ret);
}

Measured memory_bytes: 25856
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
# define mod 1000000007
# define INF (1 << 29)
# define MAX_N 1000010
/* ちゃんと考えてわかって実装 */

int main(void){
    int a,b;
    cin >> a >> b;
    if(a < b){
        for(int i=0; i<b; i++){
            cout << a;
        }
    }
    else{
        for(int i=0; i<a; i++){
            cout << b;
        }
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		
		long[] lucas = new long[n + 1];
		lucas[0] = 2;
		lucas[1] = 1;
		for (int i = 2; i <= n; i++) {
			lucas[i] = lucas[i - 1] + lucas[i - 2];
		}
		
		System.out.println(lucas[n]);
		
		sc.close();
	}
}




Measured memory_bytes: 27080
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var headTmp = nextLine()
	var bodyTmp = nextLine()

	var body = strings.Split(bodyTmp, " ")

	var N int
	N, _ = strconv.Atoi(headTmp)
	var V []int

	for i := 0; i < N; i++ {
		var v int
		v, _ = strconv.Atoi(body[i])
		V = append(V, v)
	}

	sort.Sort(sort.IntSlice(V))

	// var A []int
	var x float32
	var VV []float32
	for i := 0; i < N; i++ {
		var vv float32
		vv = float32(V[i])
		// vv, _ = strconv.Atoi(V[0])
		VV = append(VV, vv)
	}

	for i := 0; i < N-1; i++ {

		x = (VV[0] + VV[1]) / 2
		VV = delete(VV, 0)
		// fmt.Println(VV)
		pos := 1
		VV = append(VV[:pos+1], VV[pos:]...)
		VV[pos] = x
		VV = delete(VV, 0)
		// fmt.Println(VV)
	}
	fmt.Println(VV[0])

}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func delete(s []float32, i int) []float32 {
	x := append(s[:i], s[i+1:]...)
	return x
}


Measured memory_bytes: 640
s = input()
t = input()
dp = [[0]*(len(t)+1) for _ in range(len(s)+1)]
for i in range(len(s)):
    for j in range(len(t)):
        if s[i]==t[j]:
            dp[i+1][j+1] = dp[i][j]+1
        else:
            if dp[i+1][j] < dp[i][j+1]:
                dp[i+1][j+1] = dp[i][j+1]
            else:
                dp[i+1][j+1] = dp[i+1][j]

i = len(s)-1
j = len(t)-1
ans = ''                
while i>=0 and j>=0:
    if s[i]==t[j]:
        ans += t[j]
        i -= 1
        j -= 1
    else:
        if dp[i][j+1]>dp[i+1][j]:
            i -= 1
        else:
            j -= 1
print(ans[::-1])

Measured memory_bytes: 143904
import java.util.*;

public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int N, a;
		int i, j, k, tmp;
		int[] A = new int[100];
		
		N = sc.nextInt();
		for(i = 0; i < N; i++){
			A[i] = sc.nextInt();
		}
		
		for(k = 0; k < N - 1; k++){
				System.out.print(A[k] + " ");
			}
			System.out.println(A[k]);
		
		for(i = 1; i < N; i++){
			tmp = A[i];
			
			j = i - 1;
			while(j >= 0 && A[j] > tmp){
				A[j + 1] = A[j];
				j --;
			}
			A[j + 1] = tmp;
			
			for(k = 0; k < N - 1; k++){
				System.out.print(A[k] + " ");
			}
			System.out.println(A[k]);
		}
	}
}

Measured memory_bytes: 32212
//15
#include<iostream>
#include<vector>
#include<algorithm>
#include<complex>
#include<cmath>

using namespace std;

typedef complex<double> P;

int crs(P a,P b){
  double cr=a.real()*b.imag()-a.imag()*b.real();
  return (fabs(cr)<1e-9)?1:
    (cr<0)?0:2;
}

int main(){
  for(int n[2];cin>>n[0]>>n[1],n[0]|n[1];){
    vector<P> v[2];
    int mx[2][2]={},mn[2][2];
    fill(mn[0],mn[2],10000);
    for(int i=0;i<2;i++){
      for(int j=0;j<n[i];j++){
	int x,y;
	cin>>x>>y;
	mx[i][0]=max(mx[i][0],x);
	mx[i][1]=max(mx[i][1],y);
	mn[i][0]=min(mn[i][0],x);
	mn[i][1]=min(mn[i][1],y);
	v[i].push_back(P(x,y));
      }
    }
    for(int i=0;i<2;i++){
      for(int j=0;j<2;j++){
	if(mx[i][j]<mn[!i][j]){
	  cout<<"YES"<<endl;
	  goto next;
	}
      }
    }
    if(max(v[0].size(),v[1].size())==1){
      cout<<"YES"<<endl;
    }else{
      for(int o=0;o<2;o++){
	swap(v[0],v[1]);
	for(int i=0;i<v[0].size();i++){
	  for(int j=0;j<i;j++){
	    bool f[2][3]={{}};
	    for(int k=0;k<2;k++){
	      for(int l=0;l<v[k].size();l++){
		f[k][crs(v[0][i]-v[0][j],v[k][l]-v[0][j])]=true;
	      }
	    }
	    if((!f[0][0]||!f[0][2])&&(!f[1][0]||!f[1][2])&&!f[1][1]&&!(f[0][2]&&f[1][2])&&!(f[0][0]&&f[1][0])){
	      cout<<"YES"<<endl;
	      goto next;
	    }
	  }
	}
      }
      cout<<"NO"<<endl;
    }
  next:
    ;
  }
  return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef greater<int> gt;
typedef priority_queue<int, vector<int>, gt> minq;
typedef long long ll;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

int main() {
  int n; cin >> n;
  vi a(3*n);
  rep(i, 3*n) cin >> a[i];
  sort(a.begin(), a.end(), [](int a, int b) {return a>b;} );
  ll sum =0;
  rep(i, 2*n) {
    if (i&1) {
      sum += a[i];
    }
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 1408
import java.util.*;
public class Main
{
	public static void main(String[] args) {
	    Scanner sc = new Scanner(System.in);
	    int K = Integer.parseInt(sc.nextLine());
	    String S = sc.nextLine();
	    if(S.length()<=K){
	        System.out.println(S);
	    }else{
	        System.out.println(S.substring(0,K)+"...");
	    }
	}
}


Measured memory_bytes: 38560
#include<cstdio>

using namespace std;

const int N=2e5+10;
const long long mod=1e9+7ll, inf=0x7fffffffll;


struct EDGE {
	int y, nex;
} edge[N<<5];

int c[N], head[N], mih[N], tot[N], cnt, n;
long long w[N], C1[N], C2[N], min[N], X, Y, ans;
bool vis[N];

inline void add(int x,int y) {
	edge[++cnt].y=y;
	edge[cnt].nex=head[x];
	head[x]=cnt;
}

long long fast_pow(long long a,long long b) {
	long long ans=1,base=a;
	while(b) {
		if(b&1) ans=(ans*base)%mod;
		base=(base*base)%mod, b>>=1;
	}
	return ans;
}

inline void Prepare() {
	C1[0]=1;
	for(int i=1; i<=n; i++) C1[i]=(C1[i-1]*i)%mod, min[i]=inf;
	C2[n]=fast_pow(C1[n],mod-2);
	for(int i=n; i>=1; i--)C2[i-1]=(i*C2[i])%mod;
}

void dfs(int x) {
	vis[x]=true;
	for(int i=head[x]; i; i=edge[i].nex) if(!vis[edge[i].y]) dfs(edge[i].y);
}

long long C(long long n,long long k){
    return(((C1[n]*C2[n-k])%mod)*C2[k])%mod;
}

int main() {
	scanf("%d%lld%lld", &n, &X, &Y); Prepare();
	for(int i=1; i<=n; i++) scanf("%d%lld", &c[i], &w[i]);
	for(int i=1; i<=n; i++) if(min[c[i]]>w[i]) mih[c[i]]=i, min[c[i]]=w[i];
	for(int i=1; i<=n; i++) if(w[i]+min[c[i]]<=X&&i!=mih[c[i]]) add(i,mih[c[i]]), add(mih[c[i]],i);
	int fmin=inf, smin=inf;
	int first=0, second=0;
	for(int i=1; i<=n; i++) if(w[i]<fmin) fmin=w[i], first=i;
	for(int i=1; i<=n; i++) if(w[i]<=smin&&c[i]!=c[first]) smin=w[i], second=i;
	for(int i=1; i<=n; i++)
		if(i!=first) {
			if(c[i]!=c[first]&&w[i]+w[first]<=Y) add(i, first), add(first, i);
			if(second&&c[i]!=c[second]&&w[i]+w[second]<=Y) add(i, second), add(second, i);
		}
	dfs(first), cnt=0;
	for(int i=1; i<=n; i++) if(vis[i]) cnt++, tot[c[i]]++; ans=1;
	for(int i=1; i<=n; i++) if(tot[i]) ans=(ans*C(cnt, tot[i]))%mod, cnt-=tot[i];
	printf("%d", ans);
	return 0;
}


Measured memory_bytes: 16640
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

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

    vector<int64> right(n+1,0);
    vector<int64> left(n+1,0);
    for (int i=0; i<n; i++) {
        left[i+1] = left[i] + a[i];
        right[n-i-1] = right[n-i] + a[n-i-1];
    }

    int64 ans = LONG_MAX;
    for (int i=1; i<n; i++) ans = min(ans, abs(right[i] - left[i]));
    cout << ans << endl;
    debug(left);
    debug(right);
}

Measured memory_bytes: 4992
//T1 
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<map>
#include<iostream>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<vector>
using namespace std;
#define ll long long
#define f(i,a,b) for(int i=a;i<=b;i++)
inline ll read(){
   int s=0,w=1;
   char ch=getchar();
   while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
   return s*w;
}
#define d read()
ll l,r,k;
int main(){
	k=d,l=d,r=d;
	f(i,l,r)
		if(i%k==0){cout<<"OK";return 0;}
	cout<<"NG";
	return 0;
}


Measured memory_bytes: 3632
#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(X, Y) for (int(X) = 0; (X) < (Y); ++(X))
#define rrep(X, Y) for (int(X) = (Y)-1; (X) >= 0; --(X))
#define itrep(X, Y) for (auto(X) = (Y).begin(); (X) != (Y).end(); (X)++)
#define all(X) (X).begin(), (X).end()
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define print(x) cout << x << endl

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

void solve(std::string s) {
  ll ans = 10000;
  for (char c = 'a'; c <= 'z'; c++) {
    ll num = 0;
    ll pre = -1;
    rep(i, s.size()) {
      if (s[i] == c) {
        num = max(num, i - pre - 1);
        pre = i;
      }
    }
    if (pre != -1) {
      num = max(num, (ll)s.size() - pre - 1);
      ans = min(ans, num);
    }
  }
  print(ans);
}

int main() {
  std::string s;
  std::cin >> s;
  solve(s);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>

using namespace std;
using lli = long long int;
// #define DEBUG
#ifdef DEBUG
#define debug(var) cout << (#var) << ": " << (var) << endl;
template<class T> void dump_array_impl(const T& a) {
  bool first = true;
  for (auto&& x : a) {
    if (!first) { cout << ", "; first = false; }
    cout << x;
  }
}
#define debug_array(a) cout<<(#a)<<": ";dump_array_impl(a);cout<<endl
#else
#define debug(var) {}
#define debug_array(a) {}
#endif
template<class T> void read_n(vector<T>& v, size_t n) {
  v = vector<T>(n);
  for (lli i=0; i<n; ++i) cin >> v[i];
}

lli n;
vector<lli> a;
int main() {
  cin >> n;
  read_n(a, n);
  string ans = "second";
  for (auto x : a) {
    if (x % 2 == 1) {
      ans = "first";
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#pragma GCC optimize("O3")
#include <bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
class UF{
public:
	vector<int> par,num;
	int find(int v){
		return (par[v]==v)? v: (par[v]=find(par[v]));
	}
	explicit UF(int N):par(N),num(N,1){
		iota(all(par),0);
	}
	void unite(int u,int v){
		u=find(u),v=find(v);
		if(u==v)return;
		if(num[u]<num[v])swap(u,v);
		num[u]+=num[v];
		par[v]=u;
	}
	bool same(int u,int v){
		return find(u)==find(v);
	}
	bool ispar(int v){
		return v=find(v);
	}
	int size(int v){
		return num[find(v)];
	}
};
int main(){
    int n,m;
    cin>>n>>m;
    UF uf(n);
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        --a;--b;
        uf.unite(a,b);
    }
    V<int> d;
    for(int i=0;i<n;i++){
        if(uf.find(i)!=i)continue;
        d.emplace_back(uf.size(i));
    }
    sort(all(d),greater<ll>());
    cout<<d[0]<<"\n";
}


Measured memory_bytes: 5732
#include"bits/stdc++.h"

using namespace std;

int main() {
	vector<int>a(3);
	for (int i = 0; i < 3; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	int ans = a[0];
	ans += a[1];
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (ll i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<ll, ll> P;
int main()
{
    ll N, K;
    cin >> N >> K;

    vector<ll> P(N), C(N);
    rep(i, N) cin >> P[i];
    rep(i, N) cin >> C[i];

    ll ans = -INF;
    rep(i, N) chmax(ans, C[i]);
    rep(i, N) {
        vector<ll> path(N, -1), c;
        ll to = P[i] - 1;
        while (path[to] == -1) {
            c.emplace_back(C[to]);
            path[to] = 1;
            to = P[to] - 1;
        }
        /*
        rep(i, c.size()) {
            cout << c[i] << " ";
        }
        cout << endl;
        */
        ll len = (ll)c.size();
        vector<ll> sum(len + 1, 0);
        rep(i, len) {
            sum[i + 1] += sum[i] + c[i];
            if (i < K) {
                chmax(ans, sum[i + 1]);
            }
        }
        /*
        rep(i, sum.size()) {
            cout << sum[i] << " ";
        }
        cout << endl;
        */
        if (sum[len] > 0) {
            ll cnt = (K - 1) / len;
            if (cnt == 0) continue;
            ll di = K - (cnt * len);
            ll res = sum[len] * cnt;
            ll plus = -INF;
            rep(i, di) {
                chmax(plus, sum[i + 1]);
            }
            if (plus > 0) res += plus;
            chmax(ans, res);
        }
    }

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

Measured memory_bytes: 3808