akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

const int infI=1e9+5;
const long long infL=1e16;
const int MOD=998244353;
const int MAX=2e5+5;

#define mp make_pair
#define in &
#define pb push_back
#define ii pair<int,int>
#define iii pair<ii,int>
#define ll long long
#define pll pair<ll,ll>
#define vvl vector<vector<ll> >
#define vi vector<int>
#define vvi vector<vector<int> >
#define vl vector<ll>
#define eb emplace_back
#define forn(i,a,b) for(ll i=a;i<b;i++)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define endl '\n'
#define popb pop_back()
#define se second
#define fi first
#define test(t) int t;cin>>t;while(t--)
#define debug(x) cerr<<"=>"<<#x<<" = "<<x<<endl

ll power(ll a,ll b){
    if(b==0){
        return 1;
    }
    if(b==1){
        return a;
    }
    ll temp=power(a,b/2);
    temp=(temp*temp)%MOD;
    if(b%2){
        temp=(temp*a)%MOD;
    }
    return temp;
}

//only use if mod is prime
ll mod_inv(ll a,ll mod){
    a%=mod;
    return power(a,mod-2);
}

void extended_gcd(ll a,ll b,ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return;
    }
    ll x1,y1;
    extended_gcd(b,a%b,x1,y1);
    x=y1;
    y=x1-((a/b)*y1);
    return;
}

//TLE can also occur if vectors are not passed by reference
//priority_queue implements max heap by default

ll f[MAX],f_inv[MAX];

ll ncr(ll n,ll r){
    assert(n>=r);
    ll ans = (f[n]*f_inv[r])%MOD;
    ans = (ans*f_inv[n-r])%MOD;
    return ans;
}

int main(){
    fastio;
    ll n,m,k;
    cin>>n>>m>>k;
    f[0] = 1;
    forn(i,1,MAX){
        f[i] = (i*f[i-1])%MOD;
    }
    f_inv[MAX-1] = mod_inv(f[MAX-1],MOD);
    for(ll i = MAX-1;i>0;--i){
        f_inv[i-1] = (i*f_inv[i])%MOD;
    }
    ll ans = 0;
    forn(i,0,k+1){
        ll tmp = (ncr(n-1,i)*m)%MOD;
        // debug(ncr(n-1,k));
        tmp = (tmp*power(m-1,n-1-i))%MOD;
        ans = (ans+tmp)%MOD;
        // debug(tmp);
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 6744
#if 1
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <functional>
#include <set>
#include <map>
#include <numeric>
#include <cassert>
#include <iomanip>

using namespace std;
#define int long long
#define uint unsigned long long
constexpr int MOD = 1000000007;
constexpr int INF = 1145141919810893;

#define LOADVEC(type,name,N) std::vector<type>name(N); \
for (int nnn = 0; nnn < N; ++nnn) { \
	cin >> name[nnn]; \
}

#define LOADVEC2(type,name0,name1,N) std::vector<type>name0(N),name1(N); \
for (int nnn = 0; nnn < N; ++nnn) { \
	cin >> name0[nnn];cin >> name1[nnn]; \
}

#define LOADVEC3(type,name0,name1,name2,N) std::vector<type>name0(N),name1(N),name2(N); \
for (int nnn = 0; nnn < N; ++nnn) { \
	cin >> name0[nnn];cin >> name1[nnn];cin >> name2[nnn]; \
}

#define LOAD(type,name) type name; \
cin >> name;


void proc();

signed main() {
	ios::sync_with_stdio(false);
	proc();
	return 0;
}

/*
--------------------------------------------------------
--------------------------------------------------------
---------------    template      ----------------------
--------------------------------------------------------
--------------------------------------------------------
*/





namespace hnn {
template<class T = int>
class UnionFind {
	vector<T> data;
public:
	UnionFind(T sz) {
		data.assign(sz, -1);
	}
	bool unite(T x, T y) {
		x = root(x), y = root(y);
		if (x == y) return false;
		if (data[x] > data[y]) swap(x, y);
		data[x] += data[y];
		data[y] = x;
		return true;
	}
	T root(T k) {
		if (data[k] < 0) return k;
		return (data[k] = root(data[k]));
	}
	bool same(T k0, T k1) {
		return root(k0) == root(k1);
	}
	T size(T k) {
		return (-data[root(k)]);
	}
};
}//namespace hnn {




void proc() {
	LOAD(int, N);
	LOAD(int, M);
	hnn::UnionFind<int> uf(N);
	for (int i = 0; i < M; ++i) {
		int x, y, z;
		cin >> x >> y >> z;
		uf.unite(x - 1, y - 1);
	}
	unordered_set<int>s;
	int res = 0;
	for (int i = 0; i < N; ++i) {
		int r = uf.root(i);
		if (s.find(r) == s.end()) {
			s.insert(r);
			++res;
		}
	}
	cout << res << endl;

}


#endif


Measured memory_bytes: 5024
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> ipair;
typedef tuple<int, int, int> ituple;

// const ll INF = LLONG_MAX;
const int MOD = (int)1e9 + 7;
// const double EPS = 1e-10;
#define PI acosl(-1)
#define MAX_N 100000 + 5
int n;
int a[MAX_N];
int idx[MAX_N];
int from ,to;

#define rep(i, s, e) for(int i = s;i < e;i++)
#define MAX_FACT 100001 + 10
ll facts[MAX_FACT + 5];
void makeFacts(int n){
  facts[0] = 1;
  rep(i, 1, n + 1){
    facts[i] = i * facts[i-1] % MOD;
  }
}

// a x + b y = gcd(a, b)
int extgcd(int a, int b, int &x, int &y) {
  int g = a; x = 1; y = 0;
  if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x;
  return g;
}

// 1/a mod m
// 1/a mod m
int mod_inverse(int a){
  int x, y;
  extgcd(a, MOD, x, y);
  return (MOD + x % MOD) % MOD;
}

//nCk mod m
int _comb(int n, int k){
  ll l = 1, c = 1, ans;
  if(n < k) return 0;
  if(n - k < k) k = n - k;
  // printf("n = %d, k = %d\n", n, k);
  ans = facts[n];
  ans = ans * mod_inverse(facts[k]) % MOD;
  ans = ans * mod_inverse(facts[n - k]) % MOD;
  return (int)ans;
}

void exec(){
  makeFacts(MAX_N);
  cin >> n;
  int left, right;
  for (int i = 0; i < n + 1; i++){
    scanf("%d", &a[i]);
    if (idx[a[i]] == 0){
      // printf("idx[%d] = %d\n", a[i], i);
      idx[a[i]] = i+1;
    }
    else{
      from = idx[a[i]];
      to = i+1;
      left = from - 1;
      right = n - to + 1;
      // printf("left = %d, right = %d\n", left, right);
    }
  }

  // for (int k = 2; k <= 2; k++){
  for (int k = 1; k <= n+1; k++){
    // nCkを計算
    ll tmpSum = _comb(n+1, k);
    // printf("1: tmpSum = %lld\n", tmpSum);

    // (l+r)Ck-1を引く
    ll minus = _comb(left+right, k-1);
    ll fact = minus / MOD + 1;
    minus -= fact * MOD;
    tmpSum -= minus;
    // printf("2: tmpSum = %lld\n", tmpSum);
    tmpSum %= MOD;
    // printf("3: tmpSum = %lld\n", tmpSum);

    cout << tmpSum << endl;
  }


}

void solve(){
  int t = 1;
  // scanf("%d", &t);
  for (int i = 0; i < t; i++){
    exec();
  }
}

int main(){
  solve();
  return 0;
}


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  
  int a, b;
  cin >> a >> b;
  int n = b - a;
  cout << (n*(n-1)/2 - a) << endl;
  return 0;
}

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	for (auto &u : v) os << u << el;
	return (os);
}

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

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


void Main() {
	priority_queue<int> que;
	int N, M; cin >> N >> M;
	for (int i = 0; i < N; i++) {
		int A; cin >> A;
		que.push(A);
	}
	for (int i = 0; i < M; i++) {
		int q = que.top(); que.pop();
		que.push(q / 2);
	}
	ll ans = 0;
	while (!que.empty()) {
		ll q = que.top(); que.pop();
		ans += q;
	}
	cout << ans << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


Measured memory_bytes: 892
n = int(input())
s = []
ans = 0
c = [0, 0, 0]
for _ in range(n):
    tmp = input()
    if tmp[0] == "B" and tmp[-1] == "A":
        c[2] += 1
    elif tmp[0] == "B":
        c[1] += 1
    elif tmp[-1] == "A":
        c[0] += 1
    for i in range(len(tmp) - 1):
        if tmp[i:i+2] == "AB":
            ans += 1

p = min(c[:-1])
ans += p
p = max(c[:-1])-p
if c[0] == 0 and c[1] == 0:
    ans += max(c[2]-1, 0)
else:
    ans += c[2]
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string.h>
using namespace std;
const int inf = 1 << 30;
main()
{
    int n,k, dp[200000];
    cin >> n >> k ;
    vector< int > h(n);
    for( int i = 0; i < n; i++ )cin >> h[i];
    h.emplace_back(inf);
    h.emplace_back(inf);
    h.emplace_back(inf);
    h.emplace_back(inf);
    for( int i = 0; i < n;i++ ) dp[i] = inf;
    dp[0] = 0;
    for( int i = 0; i < n;i++ )
    {
        for( int j = 1; j <= k; j++ )
        {
            if( i + j < n )
            {
                dp[i + j] = min( dp[i + j], dp[i] + abs( h[i] - h[i + j] ) );
            }
        }
    }
    cout << dp[n - 1] << endl;
    return 0;
}

Measured memory_bytes: 1024
W, H, N = list(map(int, input().split(' ')))
xya_list = [list(map(int, input().split(' '))) for i in range(N)]
field = [[1 for j in range(W)] for i in range(H)]
#print(*field, sep='\n')
#print()

for jia in xya_list:
    if jia[2] == 1:
        for i in range(H):
            for j in range(jia[0]):
                field[i][j] = 0

    if jia[2] == 2:
        for i in range(H):
            for j in range(jia[0], W):
                field[i][j] = 0

    if jia[2] == 3:
        for i in range(jia[1]):
            for j in range(W):
                field[i][j] = 0

    if jia[2] == 4:
        for i in range(jia[1], H):
            for j in range(W):
                field[i][j] = 0
    #print(*field, sep='\n')
    #print()

sum_ = 0
for field_list in field:
    sum_ += sum(field_list)
print(sum_)

Measured memory_bytes: 3188
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <vector>
using namespace std;
int main()
{
	long long s,x1,x2,x3,y1,y2,y3;
	cin>>s;
	x1=0;
	y1=0;
	if(s>1000000000)
	{
		x2=1000000000;
		y3=s/1000000000+1;
		x3=x2*y3-s;
		y2=1;
	}
	else
	{
		x2=1;
		y2=0;
		x3=0;
		y3=s;
	}
	if(s==1000000000000000000)
	{
		x2=1000000000;
		y2=0;
		x3=0;
		y3=1000000000;
	}
	cout<<x1<<" "<<y1<<" "<<x2<<" "<<y2<<" "<<x3<<" "<<y3;
	return 0;
}

Measured memory_bytes: 256
/// kazuki08
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
//#define inf 1000000000
#define mod 1000000007
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
    return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
    o<<"{";
    for(const T& v:vc) o<<v<<",";
    o<<"}";
    return o;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MAX = 3000005;
int fac[MAX], inv[MAX], finv[MAX];

void pre(){
  inv[1]=1;
  for (int i = 2; i <MAX ; i++)
  {
    inv[i]=inv[mod%i]*(mod-mod/i)%mod;
  }
  fac[0]=finv[0]=1;
  for (int i = 1; i < MAX; ++i)
  {
    fac[i]=fac[i-1]*i%mod;
    finv[i]=finv[i-1]*inv[i]%mod;
  }
}
int ncr(int n, int r){
  if(r<0||r>n)return 0;
  return fac[n]*finv[r]%mod*finv[n-r]%mod;
}

signed main(){
IOS;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
  
  pre();
  int x1,x2,y1,y2;
  cin >> x1 >> y1 >> x2 >> y2;
  int ans = 0;
  for(int i=x1;i<=x2;i++){
    int cur = (y2+1)*ncr(i+y2+1,y2+1)%mod - y1*ncr(i+y1,y1)%mod;
    cur = (cur+mod)%mod;
    cur = cur*inv[i+1]%mod;
    ans = (ans+cur)%mod;
  }
  cout << ans << endl;


return 0;
}
///....


Measured memory_bytes: 70528
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;

#if DEBUG && !ONLINE_JUDGE
    ifstream input_from_file("input.txt");
    #define cin input_from_file
#else

#endif

const int MAXN = (1<<18) + 100;
const int MAXM = (1<<10) + 10;
const int MAXC = 1e5 + 10;


int N;
int V[MAXN], W[MAXN];

int din[MAXM][MAXC];


int risp(int v, int L) {
    if (v < MAXM) return din[v][min(L, MAXC-1)];
    int res = 0;
    res = risp(v/2, L);
    if (L >= W[v]) res = max(res, risp(v/2, L-W[v]) + V[v]);
    return res;
}



int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); // Togliere nei problemi con query online

    //~ for (int i = 0; i < MAXM; i++) for (int j = 1; j < MAXM; j++) din[i][j] = -1;

    cin >> N;
    for (int i = 1; i <= N; i++) cin >> V[i] >> W[i];
    
    for (int i = 1; i < MAXM; i++) {
        for (int j = 1; j < MAXC; j++) {
            din[i][j] = max(din[i][j-1], din[i/2][j]);
            if (j >= W[i]) din[i][j] = max(din[i][j], din[i/2][j-W[i]] + V[i]);
        }
    }

    int Q;
    cin >> Q;
    for (int q = 0; q < Q; q++) {
        int v, L;
        cin >> v >> L;
        cout << risp(v, L) << "\n";
        
    }

    
}


Measured memory_bytes: 409228
#include <iostream>
using namespace std;
int main(void){
    int s1,s2,s3,s4,s5,s6,s7,s8,s9,s10;
    cin>>s1;
    cin>>s2;
    cin>>s3;
    cin>>s4;
    cin>>s5;
    cin>>s6;
    cin>>s7;
    cin>>s8;
    cin>>s9;
    cin>>s10;
    cout<<s1+s2+s3+s4+s5+s6+s7+s8+s9+s10;
    cout<<endl;
}



Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const double PI = acos(-1);  

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

  ll tmp=b-a;
  
  cout << (1+tmp)*tmp/2-b << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define f(ii,ll,rr) for(int ii=ll;ii<=rr;ii++)
using namespace std;
vector<int>a,rs;
int n;
int main()
{   cin>>n;
int tam,x;
while(n--){
    cin>>tam;
    if(tam!=2)cin>>x;
    if(tam==2)a.pop_back();
    else if(tam==0)a.push_back(x);
    else if(tam==1)rs.push_back(a.at(x));
}
f(i,0,rs.size()-1)
cout<<rs.at(i)<<endl;
    return 0;
}



Measured memory_bytes: 3996
#include<bits/stdc++.h>
#define fr(i,x,y) for(int i=x;i<=y;++i)
#define rf(i,x,y) for(int i=x;i>=y;--i)
#define LL long long
using namespace std;
const int N=1e5+10;
int a[N],n,b[N],c[N];
LL all,kk=0;

void read(int &x){
	char ch=getchar();x=0;
	for(;ch<'0'||ch>'9';ch=getchar()) 2333;
	for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+(ch^48);
}

void merge(int l,int r){
	if(l==r) return ;
	int mid=(l+r)>>1;
	merge(l,mid),merge(mid+1,r);
	int head=l,tail=mid+1,nw=l;
	while(head<=mid&&tail<=r){
		if(b[head]>=b[tail]) {
			c[nw++]=b[tail++];
			kk+=head-l;
		} else c[nw++]=b[head++];
	}
	while(head<=mid) c[nw++]=b[head++];
	while(tail<=r) kk+=head-l,c[nw++]=b[tail++];
	fr(i,l,r) b[i]=c[i];
}

bool check(int x){
	fr(i,1,n){
		if(a[i]>x) b[i]=-1;
		else b[i]=1;
	}
	fr(i,1,n) b[i]+=b[i-1];
	//fr(i,1,n) printf("%d ",b[i]);
	kk=0,merge(0,n);
	//puts("");
	//fr(i,1,n) printf("%d ",b[i]);
	//printf("\n%d %lld %lld\n",x,kk,all/2+1);
	return kk>=(all/2+1);
}

int main(){
	read(n);
	int l=1e9,r=0;
	fr(i,1,n) {
		read(a[i]);
		l=min(l,a[i]),r=max(r,a[i]);
	}
	all=n*1LL*(n+1)/2;
	int ans=l;
	while(l<r){
		int mid=(l+r)>>1;
	//	printf("l=%d r=%d\n",l,r);
		if(!check(mid)) l=mid+1;
		else r=mid;
	}
	printf("%d\n",r);
	return 0;
}

Measured memory_bytes: 1408
import sys


def handler():
    l, r, d = [int(i) for i in input().strip().split()]
    sys.stdout.write('%d\n' % (r // d - (l - 1) // d))


def main():
    while True:
        try:
            handler()
        except ValueError:
            continue
        except EOFError:
            break


if __name__ == '__main__':
    main()

Measured memory_bytes: 61464
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <regex>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;
const int INF = 2147483647;

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//myfuncs
//素数判定
template<class T> inline T isPrime(T x) {
	bool ret = true;
	if (x < 2) {
		ret = false;
	}
	for (LL i = 2; i <= sqrt(x); i++) {
		if (x%i == 0) {
			ret = false;
		}
	}
	return ret;
}

//Union FInd
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

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

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

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

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

//main code

int main(int argc, char const* argv[])
{
    int a,b,x;
    cin >> a >> b >> x;
    if (a > x || a+b < x) {
        cout << "NO" << endl;
    }
    else {
        cout << "YES" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
local N, M, X = io.read("n","n","n")
local G = {}
for i=1,M do
  G[io.read("n")] = true
end
local left = 0
for i=X,0,-1 do
  if G[i] then
    left = left + 1
  end
end
local right = 0
for i=X,N do
  if G[i] then
    right = right + 1
  end
end
print(math.min(left,right))

Measured memory_bytes: 760
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

struct UnionFind {
  const int n;
  V<> t; // root ? -sz : par
  UnionFind(int n) : n(n), t(n, -1) {}
  int find(int v) { return t[v] < 0 ? v : t[v] = find(t[v]); }
  void unite(int u, int v) {
    if ((u = find(u)) == (v = find(v))) return;
    if (-t[u] < -t[v]) swap(u, v);
    t[u] += t[v];
    t[v] = u;
  }
  bool same(int u, int v) { return find(u) == find(v); }
  int size(int v) { return -t[find(v)]; }
};

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n, h, w; cin >> n >> h >> w;
  struct Edge {
    int u, v, w;
    bool operator<(const Edge& r) const { return w < r.w; }
  };
  V<Edge> es;
  while (n--) {
    int r, c, a; cin >> r >> c >> a, --r, --c;
    es.emplace_back(Edge{r, h + c, a});
  }
  sort(rbegin(es), rend(es));

  UnionFind uf(h + w + 1);
  lint res = 0;
  for (const auto& e : es) {
    if (uf.same(e.u, e.v)) {
      if (uf.same(e.u, h + w)) continue;
      uf.unite(e.u, h + w);
    } else {
      uf.unite(e.u, e.v);
    }
    res += e.w;
  }
  cout << res << '\n';
}

Measured memory_bytes: 2292
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<cmath>
#include<map>
#include<set>
using namespace std;
#define LL long long 
int main()
{
	LL a,b;
	while(cin>>a>>b)
	{
		LL c=b,l=1;
		while(c)
		{
			c/=10;
			l*=10;
		}
		if(l<10)l=10;
		a=a*l+b;
		l=sqrt(a);
		if(l*l==a)
		printf("Yes\n");
		else printf("No\n");
	}
	return 0;
}


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

string s;

int main() {
    cin >> s;
    if ((s[0] == s[s.size() - 1]) && (s.size() % 2 == 0))
        printf("First\n");
    else if ((s[0] != s[s.size() - 1]) && (s.size() % 2 == 1))
        printf("First\n");
    else printf("Second\n");
    return 0;
}


Measured memory_bytes: 512
#include <cstdio>
using namespace std;

const int maxn=2e3+5,pps=1e9+7;

int n,k,ans;
int f[maxn],fac[maxn*maxn],inv[maxn*maxn];

int read() {
    int x=0,f=1;char ch=getchar();
    for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;
    for(;ch>='0'&&ch<='9';ch=getchar())x=x*10+ch-'0';
    return x*f;
}

int quick(int a,int b) {
    int sum=1;
    while(b) {
        if(b&1)sum=1ll*sum*a%pps;
        a=1ll*a*a%pps;b>>=1;
    }
    return sum;
}

void prepare(int N) {
    fac[0]=inv[0]=1;
    for(int i=1;i<=N;i++)
        fac[i]=1ll*fac[i-1]*i%pps;
    inv[N]=quick(fac[N],pps-2);
    for(int i=N-1;i;i--)
        inv[i]=1ll*inv[i+1]*(i+1)%pps;
}

int C(int a,int b) {
    return 1ll*fac[a]*inv[b]%pps*inv[a-b]%pps;
}

int main() {
    n=read(),k=read()-1;
    if(!k) {puts("1");return 0;}
    prepare(n*k+n);f[0]=1;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=i;j++)
            f[j]=(f[j]+1ll*C(n*k+n-i-(j-1)*k-1,k-1)*f[j-1]%pps)%pps;
    ans=1ll*f[n]*fac[n]%pps;
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 31488
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    
    vector<int> a(N);
    vector<int> pushed(N);
    
    for(int i = 0; i < N; i++){
        cin >> a.at(i);
        a.at(i)--; //indexed 変換
    }
    
    int i = 0;
    int count = 0;
    while(1){
        if(a.at(i) == 1){
            cout << count + 1 << endl;
            break;
        }else if(pushed.at(i) == 1){
            cout << -1 << endl;
            break;
        }
        
        pushed.at(i) = 1;
        count++;
        i = a.at(i);
    }
    
    
}

Measured memory_bytes: 1024
/*  -*- coding: utf-8 -*-
 *
 * 2701.cc: Falling Block Puzzle
 */

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

/* constant */

const int MAX_N = 3;
const int MAX_H = 10 + 2 * MAX_N;

// Direction:          LU    U   RU    L  STAY   R   LD    D   RD
const int msks[9] = { 0x8, 0xc, 0x4, 0xa, 0xf, 0x5, 0x2, 0x3, 0x1 };
const int sfts[9] = {  -3,  -2,  -1,  -1,   0,   1,   1,   2,   3 };

/* typedef */

/* global variables */

int flds[MAX_H], bks[MAX_N][2];
int maxd;

/* subroutines */

inline int readblk() {
  int blk = 0;
  for (int i = 0, bi = 1; i < 4; i++, bi <<= 1) {
    char c;
    while ((c = getchar()) != '#' && c != '.');
    if (c == '#') blk |= bi;
  }
  return blk;
}

void check(int h) {
  int d = 0;
  for (int y = 0; y < h; y++)
    if (flds[y] == 0xf) d++;
  if (maxd < d) maxd = d;
  //printf("check(%d)=%d\n", h, d);
}

void rec(int k, int n, int h, int d) {
  //printf("rec(%d,%d,%d,%d)\n", k, n, h, d);
  if (k >= n) {
    if (maxd < d) maxd = d;
    return;
  }

  for (int di = 0; di < 9; di++) {
    const int &msk = msks[di], &sft = sfts[di];
    int bk0 = bks[k][0], bk1 = bks[k][1];
    if ((bk0 & msk) == bk0 && (bk1 & msk) == bk1) {
      if (sft > 0) bk0 = (bk0 << sft) & 0xf, bk1 = (bk1 << sft) & 0xf;
      else if (sft < 0) bk0 >>= -sft, bk1 >>= -sft;

      int h0 = h - 1;
      while (h0 >= 0 && (flds[h0] & bk0) == 0 && (flds[h0 + 1] & bk1) == 0)
	h0--;
      h0++;

      int tmpf[MAX_H];
      memcpy(tmpf, flds, sizeof(flds));

      flds[h0] |= bk0, flds[h0 + 1] |= bk1;
      int h1 = max(h, h0 + 2), d1 = d;
      for (int y = 0; y < h1; y++)
	if (flds[y] == 0xf) d1++, flds[y] = 0;
      int h2 = 0;
      for (int y = 0; y < h1; y++)
	if (flds[y] != 0) flds[h2++] = flds[y];
      for (int y = h2; y < h1; y++) flds[y] = 0;

      rec(k + 1, n, h2, d1);
      memcpy(flds, tmpf, sizeof(tmpf));
    }
  }
}

/* main */

int main() {
  for (;;) {
    int h, n;
    scanf("%d%d", &h, &n);
    if (h == 0) break;

    memset(flds, 0, sizeof(flds));
    memset(bks, 0, sizeof(bks));

    for (int y = 0; y < h; y++) flds[y] = readblk();

    for (int i = 0; i < n; i++) {
      for (int y = 0; y < 2; y++) bks[i][y] = readblk();
      if (bks[i][0] == 0) swap(bks[i][0], bks[i][1]);
    }

    maxd = 0;
    rec(0, n, h, 0);

    printf("%d\n", maxd);
  }
  return 0;
}

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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n;
    cin >> n;
    string c;
    cin >> c;
    int cnt = 0;
    rep(i, n) if (c[i] == 'R') ++cnt;
    int ans = 0;
    for (int i=cnt; i<n; ++i) if (c[i] == 'R') ++ans;
    cout << ans << endl;
    return 0;
}


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

constexpr int mod = 1e9 + 7;

int main() {
    int n; cin >> n;
    vector<int> c(n);
    vector<vector<int>> cs(1 << 18);
    for(int i = 0; i < n; ++i) {
        cin >> c[i];
        cs[c[i]].push_back(i);
    }

    vector<int> dp(n + 1);
    dp[0] = 1;
    for(int i = 0; i < n; ++i) {
        const int idx = lower_bound(begin(cs[c[i]]), end(cs[c[i]]), i) - begin(cs[c[i]]);
        if(idx + 1 < (int)cs[c[i]].size() && cs[c[i]][idx + 1] != i + 1) {
            (dp[cs[c[i]][idx + 1]] += dp[i]) %= mod;
        }
        (dp[i + 1] += dp[i]) %= mod;
    }
    cout << dp.back() << endl;
}

Measured memory_bytes: 14208
#include<iostream>

using namespace std;

int main(){
  int ax,bx;
  double a,b;
  cin >> a >> b;
  int ans=-1;
  for(int i=13;i<=1000;i++){
    ax=i*0.08;
    bx=i*0.1;
    if(bx==b && ax==a){
      ans=i;
      break;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import numpy as np
from collections import deque

N = int(input())
S = [input() for i in range(N)]

S0 = list(map(lambda s: s[0], S))
n_MARCH = []
n_MARCH.append(S0.count('M'))
n_MARCH.append(S0.count('A'))
n_MARCH.append(S0.count('R'))
n_MARCH.append(S0.count('C'))
n_MARCH.append(S0.count('H'))

ans = 0
for i in range(0, 3):
  for j in range(i+1, 4):
    for k in range(j+1, 5):
      ans += n_MARCH[i] * n_MARCH[j] * n_MARCH[k]
      
print(ans)

Measured memory_bytes: 19800
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func scanNums(len int) (nums []int) {
	var num int
	for i := 0; i < len; i++ {
		num = nextInt()
		nums = append(nums, num)
	}
	return
}

func max(a []int) int {
	max := a[0]
	for _, i := range a {
		if i > max {
			max = i
		}
	}
	return max
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	h := scanNums(n)

	num := make([]int, n)
	for i := range num {
		num[i] = 1
	}

	for i := 0; i < n; i++ {
		if i > 0 {
			if h[i] <= h[i-1] {
				num[i] += num[i-1]
			} else {
				num[i] = 1
			}
		}
	}
	fmt.Println(max(num) - 1)
}


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

int main() {
  string str="abcdefghijklmnopqrstuvwxyz";
  char C;
  cin >> C;
  for(int i=0;i<25;i++){
    if(C==str.at(i)){
      cout << str.at(i+1) << endl;
    break;
    }
  }
}


Measured memory_bytes: 256
#!/usr/bin/env python
# coding: utf-8

# In[7]:


import math


# In[13]:


N,D = map(int, input().split())
X = []
for _ in range(N):
    X.append(list(map(int, input().split())))


# In[14]:


ans = 0
for i in range(N-1):
    for j in range(i+1,N):
        dist = sum((X[i][k]-X[j][k])**2 for k in range(D))
        if math.sqrt(dist)%1 == 0:
            ans += 1
print(ans)


# In[ ]:






Measured memory_bytes: 3064
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
using namespace std;
          
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a = 0;
    string s;
    cin >> s;
    for ( int i = 0 ; i < s.length() - 1 ; i++ ) {
        if ( s[i] != s[i + 1] ) a++;
    }
    cout << a;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long ll;

typedef long double ld;
typedef pair<ll,ll> pp;
typedef tree<pp,null_type,less<pp>,rb_tree_tag,tree_order_statistics_node_update> super_set;

#define x1 dfds
#define y1 dsfdsfe
#define pb push_back
#define forn(i,n) for(ll i = 1;i<=n;++i)
#define fi first
#define sc second
#define endl '\n'
#define po(x) (1ll<<x)
#define log sdfdsfdsf

const ll DIM = 1E3+7;
const ll MOD = 1e9+7;
const ll M1 = 1e9+7;
const ll INF = 1E17;
const ld eps = 0.00000000000001;
const ld PI = 3.14159265358979323846;
int getInt(int a = 0, int b = INT_MAX){
	static mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	return uniform_int_distribution <int> (a, b)(rng);
}

ll gi(char ch){
    if (ch=='#')return 1;
    return 0;
}
ll dist[DIM][DIM];
ll A[DIM][DIM];
ll n,m;
deque<pp> Q;
void Check(ll x,ll y,ll ds){
    if (x<1 || x>n || y<1 || y>m || A[x][y]==1)return;
    if (dist[x][y]==-1 || dist[x][y]>ds){
        dist[x][y]=ds;
        if (Q.empty() || ds==dist[Q.front().fi][Q.front().sc])Q.push_front({x,y});
        else Q.push_back({x,y});
    }

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

    cin>>n>>m;
    pp start;
    cin>>start.fi>>start.sc;
    pp finish;
    cin>>finish.fi>>finish.sc;
    forn(i,n){
        forn(j,m){
            char ch;
            cin>>ch;
            A[i][j] = gi(ch);
        }
    }
    memset(dist,-1,sizeof(dist));
    dist[start.fi][start.sc] = 0;

    Q.pb(start);
    while(!Q.empty()){
        pp t = Q.front();
        //if (t==finish)break;
        Q.pop_front();
        Check(t.fi,t.sc-1,dist[t.fi][t.sc]);
        Check(t.fi,t.sc+1,dist[t.fi][t.sc]);
        Check(t.fi-1,t.sc,dist[t.fi][t.sc]);
        Check(t.fi+1,t.sc,dist[t.fi][t.sc]);
        for(ll i = -2;i<=2;++i){
            for(ll j = -2;j<=2;++j){
                Check(t.fi+i,t.sc+j,dist[t.fi][t.sc]+1);
            }
        }
    }
    cout<<dist[finish.fi][finish.sc]<<endl;

    return 0;
}


Measured memory_bytes: 19544
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define lld long double
#define REP(i,s,n) for(lli i=s;i<n;i++)
#define RREP(i,s,n) for(lli i=s;i>=n;i--)
#define MOD 1000000007
#define NUM 2520
#define DEBUG 1
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define INF (1LL<<50)
 
signed main(){
 
	lli n;
	cin>>n;
 
	vector<lli> d(n);
	REP(i,0,n){
		cin>>d[i];
		if(d[i]>12)d[i] = 24-d[i];
	}
 
	sort(d.begin(),d.end());
 
	vector<lli> ans;
 
	REP(i,0,n){
		if(i%2==0)ans.push_back(d[i]);
		else ans.push_back(24-d[i]);
	}
 
	sort(ans.begin(),ans.end());
 
	lli cnt = min(ans[0],24LL-ans[n-1]);
	REP(i,1,n){
		cnt = min(abs(ans[i]-ans[i-1]),cnt);
	}
	cout<<cnt<<endl;
 
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-6;
const double PI  = acos(-1.0);
const long INF=pow(2,31)-1;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
const long MOD=1e9+7;
const int MAX_N=1004;
int dp[MAX_N][MAX_N];
int main(){
	string S1,S2;
	cin>>S1>>S2;
	CLR(dp);
	FOR(i,1,MAX_N){
		dp[0][i]=dp[i][0]=i;
	}
	REP(i,SZ(S1)){
		REP(j,SZ(S2)){
			int cost=(S1[i]==S2[j])?0:1;
			dp[i+1][j+1]=min(min(dp[i][j+1]+1,dp[i+1][j]+1),dp[i][j]+cost);
		}
	}
	cout<<dp[SZ(S1)][SZ(S2)]<<endl;
	return 0;
}

Measured memory_bytes: 5132
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

struct UnionFind {
  vector<int> parent;  // parent[root] is the negative of the size.
  vector<ll> sum;
  UnionFind(const vector<ll>& vs)
      : parent(vs.size(), -1), sum(vs){};
  bool unite(int u, int v) {
    u = root(u);
    v = root(v);
    if (u == v) return false;
    if (parent[u] > parent[v]) swap(u, v);
    parent[u] += parent[v];
    parent[v] = u;
    sum[u] += sum[v];
    return true;
  }
  bool find(int u, int v) {
    return root(u) == root(v);
  }
  int root(int u) {
    return parent[u] < 0 ? u : parent[u] = root(parent[u]);
  }
  int size(int u) {
    return -parent[root(u)];
  }
  ll query(int x) {
    return sum[root(x)];
  }
};

struct Edge {
  int id, A, B;
  ll Y;
};

int main() {
  int N, M;
  while (cin >> N >> M) {
    vector<ll> X(N);
    for (int i = 0; i < N; i++) cin >> X[i];
    vec<Edge, 2> G(N);
    vector<Edge> edges;
    for (int i = 0; i < M; i++) {
      int A, B;
      ll Y;
      cin >> A >> B >> Y;
      --A;
      --B;
      G[A].push_back({i, A, B, Y});
      G[B].push_back({i, B, A, Y});
      edges.push_back({i, A, B, Y});
    }
    sort(edges.begin(), edges.end(), [&](auto& a, auto& b) {
      return a.Y < b.Y;
    });
    UnionFind uf(X);
    vector<Edge> remains;
    for (auto& e : edges) {
      uf.unite(e.A, e.B);
      if (uf.query(e.A) >= e.Y) {
        remains.push_back(e);
      }
    }
    vector<int> used(M, 0);
    function<void(int, ll)> dfs = [&](int v, ll c) {
      for (auto& e : G[v]) {
        if (e.Y <= c && !used[e.id]) {
          used[e.id] = 1;
          dfs(e.B, c);
        }
      }
    };
    reverse(remains.begin(), remains.end());
    for (auto& e : remains) dfs(e.A, e.Y);
    int res = count(used.begin(), used.end(), 0);
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 22832
def Comb(n,k):
    comb_ans=1
    for i in range(1,k+1):
        comb_ans*=(n-i+1)/i
    comb_ans=int(comb_ans)
    return comb_ans

N=int(input())
A=list(map(int,input().split()))
ans=0
B=set(A)
L=[0]*N
for i in range(N):
    L[A[i]-1]+=1
for i in B:
    ans+=Comb(L[i-1],2)
for i in range(N):
    pri=ans
    pri=ans-L[A[i]-1]+1
    print(pri)

Measured memory_bytes: 26140
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define MOD (int)(1e9 + 7)

int main()
{
    int n;
    cin >> n;
    ll vals[n];
    for (int q = 0; q < n; q++)
    {
        cin >> vals[q];
    }
    ll dp[n+5][n+5];
    for (int q = 0; q < n; q++)
    {
        for (int w = 0; w+q<n; w++)
        {
            if (q==0)
            {
                dp[w][w+q] = 0;
            }
            else
            {
                ll total = vals[w];
                dp[w][w+q]=dp[w][w]+dp[w+1][w+q];
                for (int e = w; e< w+q; e++)
                {
                    total += vals[e+1];
                    dp[w][w+q]=min(dp[w][w+q], dp[w][e]+dp[e+1][w+q]);
                }
                dp[w][w+q]+=total;
            }
        }
    }
    cout << dp[0][n-1];

    return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;
typedef long long LL;
typedef pair<int,int> P;

int main(){
	int N, K;
	cin >> N >> K;
	int p=(N-1)*(N-2)/2;
	if(p<K){
		cout << -1 << endl;
		return 0;
	}
	int M=N-1+(p-K);
	vector<P> ans;
	rep(i,N-1) ans.emplace_back(P(1,i+2));
	int u=2, v=3;
	rep(i,p-K){
		ans.emplace_back(P(u,v));
		v++;
		if(v>N) u++, v=u+1;
	}
	cout << M << endl;
	rep(i,M) cout << ans[i].first << " " << ans[i].second << endl;

	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

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

    vl a(n+1);
    exrep(i, 1, n) {
        cin >> a[i];
    }
    sort(a.begin() + 1, a.end());

    ll Q;  // aの0未満の要素の個数
    if(0 <= a[1]) {
        Q = 1;
    }
    else if(a[n] < 0) {
        Q = n-1;
    }
    else {
        exrep(i, 2, n) {
            if(0 <= a[i]) {
                Q = i-1;
                break;
            }
        }
    }

    vl x(n), y(n);
    exrep(i, Q+1, n-1) {
        x[i-Q] = a[1];
        y[i-Q] = a[i];
        a[1] -= a[i];
    }
    exrep(i, 1, Q) {
        x[(n-1) - Q + i] = a[n];
        y[(n-1) - Q + i] = a[i];
        a[n] -= a[i];
    }
    
    out(a[n]);
    exrep(i, 1, n-1) {
        cout << x[i] << " " << y[i] << "\n";
    }
    
    re0;
}

Measured memory_bytes: 4224
#include<algorithm>
#include<iostream>
using namespace std;
int N,a[100],x=0,y=0;
int main(void){
	cin>>N;
	for(int i=0;i<N;i++)cin>>a[i];
	sort(a,a+N);
	reverse(&a[0],&a[N]);
	for(int i=0;i<N;i++){
		if(i%2==0)x+=a[i];
		else y+=a[i];
	}
	cout<<x-y;
	return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		char[] yohouA   = new char[3];
		char[] zissaiA  = new char[3];

		String yohou  = scanner.nextLine();
		String zissai = scanner.nextLine();

		int count = 0;

		scanner.close();

		tenki(yohou,  yohouA);
		tenki(zissai, zissaiA);

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

			if(yohouA[i] == zissaiA[i]){

				count++;

			}else {

				continue;

			}

		}

		System.out.println(count);

	}

	public static void tenki(String tenki, char[] array) {

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

			array[i] = tenki.charAt(i);

		}

	}


}

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

def resolve():
    def main():
        n=int(input())
        s=input()
        sset=set(s)
        ans=0
        for i in range(1,n):
            x=s[:i]
            y=s[i:]
            cnt=0
            for j in sset:
                if j in x and j in y:
                    cnt+=1
                    if cnt==len(sset):
                        return cnt
            ans=max(ans,cnt)
        return ans
    print(main())
resolve()

Measured memory_bytes: 39924
import sys,collections as cl,bisect as bs,math 
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def prime_decomposition(n): #素因数分解
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(i)
    i += 1
  if n > 1:
    table.append(int(n))
  return table

def make_divisors(n): #約数列挙
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors




a,b,x = m()

if a * a * b == x:
    print(0)

elif x >= a*a*b/2:
    kkk = 2 * x / (a**2) - b

    on = b - kkk

    k = math.degrees(math.atan(a/on))
    print(90-k)
else:
    kkk = 2*x/(a*b)

    k = math.degrees(math.atan(b/kkk))
    print(k)







Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const int MAX = 510000;

// 十の位で切り上げ
int roundup_10(int i) {
  if (i%10==0) return i;
  else return (i/10+1)*10;
}

int main() {
  int A, B, C, D, E;
  cin >> A >> B >> C >> D >> E;
  vector<int> rem(5);
  rem[0] = 10-A%10;
  rem[1] = 10-B%10;
  rem[2] = 10-C%10;
  rem[3] = 10-D%10;
  rem[4] = 10-E%10;
  sort(rem.begin(), rem.end());
  reverse(rem.begin(), rem.end());
  int ans = roundup_10(A)+roundup_10(B)+roundup_10(C)+roundup_10(D)+roundup_10(E);
  for (int i=0; i<5; i++) {
    if (rem[i]!=10) {
      ans -= rem[i];
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
#include <bitset>
using namespace std;
#define fast_io ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  ret *= kaijo(n); ret %= MOD;
  ret *= gyaku_kaijo(r); ret %= MOD;
  ret *= gyaku_kaijo(n-r); ret %= MOD;
  return ret;
}


int main(void){
  fast_io
  cout<<fixed<<setprecision(15);

  ll n;cin>>n;
  vector<ll> X(n);
  rep(i,n){
    cin>>X[i];
  }
  ll ans = LINF;
  sort(all(X));
  rep(p,101){
    ll sum = 0;
    rep(i,n){
      sum += (X[i] - p) * (X[i] - p);
    }
    chmin(ans, sum);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {	
	int d;
	while(~scanf("%d", &d)) {
		int ans = 0;
		for(int i = 1; d * i <= 600; ++i) {
			ans += d * d * d * (i - 1) * (i - 1);
		}
		printf("%d\n", ans);
	}
	return 0;
} 

Measured memory_bytes: 1020
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader buff = null;
		buff = new BufferedReader(new InputStreamReader(System.in));

		int N = Integer.parseInt(buff.readLine());
		int[] num_box = new int[N];
		for(int i = 0; i < N; ++i){
			num_box[i] = Integer.parseInt(buff.readLine());
		}
		Arrays.sort(num_box);

		int pre = 0;
		int count = 0;
		for(int i = 0; i < N; ++i){
			if(pre < num_box[i]){
				count++;
				pre = num_box[i];
			}
		}
		System.out.println(count);
	}

	static long f() {
		long ans = 0;


		return ans;
	}
}

Measured memory_bytes: 23252