akhauriyash/Code-Regression huggingface dataset:
/********************/
/* K B G D E L T A */
/*     DA-IICT      */
/********************/
 
#include<bits/stdc++.h>
using namespace std; 
using   ll=long long;
#define fast           ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl           "\n"
#define F(i,n)         for(ll i=0;i<n;i++)
#define rep(i,a,b)     for(ll i=a;i<b;i++)
#define repp(i,a,b)    for(ll i=a;i>=b;i--)
#define pb             push_back
#define mp             make_pair
#define vll            vector<ll>
#define f              first
#define s              second
#define pll            pair<ll,ll>
#define ALL(v)         v.begin(),v.end()
#define ALLR(v)        v.rbegin(),v.rend()
#define pii            3.14159265358979323
#define mod            1000000007
 
void solve()
{
    ll n,a,b;

    cin>>n>>a>>b;

    vll p(n);

    F(i,n)
    {
        cin>>p[i];
    }

    sort(ALL(p));

    ll a1=0,a2=0,a3=0;

    for(int i=0;i<n;i++)
    {
        if(p[i]<=a)                 a1++;

        else if(p[i]>a && p[i]<=b)  a2++;

        else                        a3++;
    }

    cout<<min({a1,a2,a3});

}
 
signed main(){
 
    fast;
 
    ll t=1;
 
    while(t--)
    {
        solve();
    }
 
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <cstring>
#include <string>
#include <cctype>
#include <cassert>
#include <queue>
#include <unordered_set>
#include <unordered_map>

using namespace std;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,b,e) for(int i = (b); i <= (e); i++)
#define INF (1001001001)
#define EPS (1e-15)

#define pr(x) do{cerr << (#x) << " = " << (x) << endl;}while(0)
#define pri(x,i) do{cerr << (#x) << "[" << i << "] = " << (x[i]) << endl;}while(0)
#define pra(x) do{rep(__i,(x).size()) pri(x,__i);}while(0)
#define pran(x,n) do{rep(__i,n) pri(x,__i);}while(0)
#define pral(x) do{cerr << (#x) << " =";rep(__i,(x).size()) cerr<<" "<<(x[__i]);cerr<<endl;}while(0)
#define prar(x,b,e) do{repr(__i,b,e) pri(x,__i);}while(0)

typedef long long ll;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;

template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class T,size_t n> ostream& operator<<(ostream &os, const array<T,n> &t) {os<<"{"; rep(i,n) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class T> inline bool CHMAX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool CHMIN(T &l,const T &r){return l>r?l=r,1:0;}

ll MOD = 1000000007;

function<void(int,int)> tensi_no_3p=[&](int v,int d){
};

int in() {
	int a;
	scanf("%d ", &a);
	return a;
}

int main() {
	int N; cin >> N;
	vint A(N); rep(i, N) cin >> A[i];
	//A[N] = 0;
	int num = 0;
	vint to(N);
	int right = 0;
	rep(i, N) {
		if (right <= i) {
			right = i + 1;
			num ^= A[i];
		}
		while (right < N && (num & A[right]) == 0) {
			num ^= A[right];
			right++;
		}
			
		to[i] = right;
		num ^= A[i];
	}
	//pra(to);
	ll ans = 0;
	rep(i, N) ans += to[i] - i;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include<algorithm>
#include<string>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#include <iomanip>
#pragma region Macros
#define int long long
#define double long double
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define LAST(x) x[x.size()-1]
#define ALL(x) (x).begin(),(x).end()
#define swap(a,b) (a += b,b = a - b,a -= b)
#define CEIL(a,b) ((a+b-1)/b)
int FACT(int a) {
	if (a == 0)
		return 1;
	else
		return a * FACT(a - 1);
}
int nPr(int n, int r) {
	int s = n - r + 1;
	int sum = 1;
	for (int i = s; i <= n; i++)
		sum *= i;
	return sum;
}
//int nCr(int n, int r)
int nCr2(int n, int r) {
	return FACT(n) / (FACT(r) * FACT(n - r));
}
int GCD(int a, int b) // assuming a,b >= 1
{
	if (a < b)
		swap(a, b);
	if (b == 0)
		return a;
	if (a % b == 0)
		return b;
	return GCD(b, a % b);
}
int LCM(int a, int b) // assuming a,b >= 1
{
	return  a * b / GCD(a, b);
}
double LOG(int a, int b) {
	return log(b) / log(a);
}
inline bool BETWEEN(int x, int min, int max) {
	if (min <= x && x <= max)
		return true;
	else
		return false;
}
inline bool PRIMEOR (int x) {
	if (x ==1)
		return false;
	if (x == 2)
		return true;
	if (x%2==0)
		return false;
	double sqrtx = sqrt(x);
	for (int i = 3; i <= sqrtx; i += 2) {
		if (x % i == 0)
			return false;
	}
	return true;
}

using namespace std;
#pragma endregion

signed main() {
	int N,x,odd=0,even=0;
	cin >> N;
	rep(i, N) {
		cin >> x;
		if (x % 2 == 0)
			even++;
		else
			odd++;
	}
	if (odd % 2 == 0)
		cout << "YES";
	else
		cout << "NO";
}

Measured memory_bytes: 256
/*
* welcome to my code!
* ------------------------------------------
* author : lynmisakura(twitter : @andoreiji11)
*/

#include<bits/stdc++.h>
using namespace std;

using ll = long long;

// macro templates

#define rrep(i,n) for(int i = n - 1;i >= 0;i--)
#define rep(i,n) for(int i = 0;i < n;i++)
#define dv(TYPE,VAL) TYPE VAL;cin >> VAL;
#define vi(TYPE,NAME,SIZE,INIT) vector<TYPE> NAME(SIZE,(INIT))
#define vin(TYPE,NAME,SIZE) vector<TYPE> NAME(SIZE);rep(i,SIZE)cin >> NAME[i]
#define vout(ARRAY) for(auto i : ARRAY)cout << i << ' ';cout << '\n'
#define vvi(TYPE,NAME,LOW,COL,INIT) vector<vector<TYPE>> NAME(LOW,vector<TYPE>(COL,INIT))
#define vpi(T1,T2,NAME,SIZE,I1,I2) vector<pair<T1,T2>> NAME(SIZE,make_pair(I1,I2))
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define dup(x,y) (x + y - 1)/(y)
#define sz(v) (int64_t)v.size()
#define CUM(arr,cum) vector<ll> cum(sz(a)+1,0); rep(i,sz(a)) cum[i+1] = cum[i] + 1
#define PY(COND) if(COND){cout << "YES" << '\n';return;}
#define PN(COND) if(COND){cout << "NO" << '\n';return;}
#define PYN(COND) cout << ((COND) ? "YES" : "NO") << '\n';
#define Py(COND) if(COND){cout << "Yes" << '\n';return;}
#define Pn(COND) if(COND){cout << "No" << '\n';return;}
#define Pyn(COND) cout << ((COND) ? "Yes" : "No") << '\n';return

#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pi acos(-1)
#define fi first
#define se second
#define pq priority_queue

#define MULTITEST; int t;cin >> t;rep(_,t)main2();
#define IOB; cin.tie(0);ios::sync_with_stdio(false);

template<class T> bool chmin(T& a,T b){if(a>b){a=b;return 1;}else return false;}
template<class T> bool chmax(T& a,T b){if(a<b){a=b;return 1;}else return false;}

// templates end
struct Sieve{

    // MAX : 1e7
    int n,p = 0;
    vector<int> prime;
    vector<bool> is_prime;

    Sieve(int n):n(n),is_prime(n+1,true){
        is_prime[0] = is_prime[1] = false;
        for(int i = 2;i <= n;i++){
            if(is_prime[i]){
                prime.push_back(i);
                p++;
                for(int j = 2 * i;j <= n;j += i) is_prime[j] = false;
            }
        }
    }

    map<int,int> prime_factor(int n){
        map<int,int> res;

        for(int i : prime){
            if(i > n) break;
            if(n % i == 0){
                int cnt = 0;
                while(n % i == 0){
                    cnt++;
                    n /= i;
                }
                res[i] = cnt;
            }
        }

        if(n != 1) res[n] = 1;

        return res;
    }

};

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

    int64_t n;cin >> n;
    vector<int64_t> a(n);
    rep(i,n)cin >> a[i];
    sort(all(a));
    map<int64_t ,vector<int>> M;
    rep(i,n) M[a[i]].pb(i);
    vector<bool> used(n,true);
    rep(i,n){
        if(!used[i])continue;
        if(M[a[i]].size() > 1) for(auto k : M[a[i]]) used[k] = false;
        for(int j = 2;j * a[i] <= 1e6;j++){
            if(M[j * a[i]].size()){
                for(auto k : M[j * a[i]]) used[k] = false;
            }
        }
    }
    int64_t ans = 0;
    rep(i,n)ans += used[i];
    cout << ans << '\n';
}

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

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

    int x;
    cin >> x;

    int i = 1;
    while(((i*(i+1)) / 2 ) < x) {
        ++i;
    }

    int ans = i;
    cout << ans << endl;
    return 0;
}

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

int main()
{
    string s;
    cin >> s;
    int a[26] = {0};
    for (size_t i = 0; i < s.length(); i++)
    {
        a[s[i] - 'a']++;
    }
    for (size_t i = 0; i < 26; i++)
    {
        if (a[i] % 2 == 1)
        {
            cout << "No" << endl;
            return 0;
        }
        /* code */
    }
    cout << "Yes" << endl;

    return 0;
}

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



signed main() {
  int h;cin>>h;
  cout << h/2 * ((h+1)/2) << endl;
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=4010;
int n,A,B,fa[N];
int find(int x){return x==fa[x]?x:fa[x]=find(fa[x]);}
void unit(int x,int y){fa[find(x)]=find(y);}
bool query(int x,int y){
	printf("? %d %d\n",x,y);
	fflush(stdout);
	static char str[10];
	scanf("%s",str);
	return str[0]=='Y';
}
int q[2][N],*x=q[0],*y=q[1];
bool res[N],calc[N];
void solve(int n){
	if (n==1){
		int S=find(x[1]);
		res[S]=calc[S]=1;
		for (int i=0;i<A+B;i++)
		if (i==fa[i]&&!calc[i]){
			res[i]=query(x[1],i);
			calc[i]=1;
		}
		printf("! ");
		for (int i=0;i<A+B;i++) printf("%d",res[find(i)]?1:0);
		puts("");
		fflush(stdout);
		return;
	}
	int size=0;
	for (int i=2;i<=n;i+=2){
		bool tp1=query(x[i-1],x[i]);
		bool tp2=query(x[i],x[i-1]);
		if (tp1&&tp2) y[++size]=x[i],unit(x[i-1],x[i]);
	}
	if ((size&1)==0&&(n&1)) y[++size]=x[n];
	swap(x,y);
	solve(size);
}
int main()
{
	scanf("%d%d",&A,&B);
	if (A<=B){
		puts("Impossible");
		fflush(stdout);
		return 0;
	}
	n=A+B;
	for (int i=0;i<n;i++) x[i]=fa[i]=i;
	solve(n);
	return 0;
}

Measured memory_bytes: 848
#include<bits/stdc++.h>
using namespace std;
struct flow
{
	static const int N=200005,INF=1e9;
	int n,s,t;
	struct edge
	{
		int v,w,f,c,nxt;
	}e[N];
	int head[N],cur[N],cnt;
	void addedge(int u,int v,int w,int f,int c)
	{
		cnt++;
		e[cnt].v=v,e[cnt].w=w,e[cnt].f=f,e[cnt].c=c;
		e[cnt].nxt=head[u];
		head[u]=cnt;
	}
	void add(int u,int v,int w,int c=0)
	{
		addedge(u,v,w,w,c);
		addedge(v,u,w,0,-c);
	}
	int dep[N],q[N];
	int bfs()
	{
		for(int i=1;i<=n;i++)
			dep[i]=-1,cur[i]=head[i];
		dep[s]=0;
		int l=0,r=1;
		q[0]=s;
		while(l<r)
		{
			int u=q[l++];
			for(int i=head[u];i;i=e[i].nxt)
			{
				if(dep[e[i].v]==-1&&e[i].f>0)
				{
					dep[e[i].v]=dep[u]+1;
					q[r++]=e[i].v;
				}
			}
		}
		return dep[t]!=-1;
	}
	int dfs(int u,int lim)
	{
		if(u==t||lim==0)
			return lim;
		int flow=0,f;
		for(int i=cur[u];i;i=e[i].nxt)
		{
			cur[u]=i;
			if(dep[e[i].v]==dep[u]+1&&(f=dfs(e[i].v,min(lim,e[i].f))))
			{
				flow+=f;
				lim-=f;
				e[i].f-=f;
				e[(i-1^1)+1].f+=f;
				if(!lim)
					break;
			}
		}
		return flow;
	}
	int max_flow()
	{
		int mf=0;
		while(bfs())
			mf+=dfs(s,INF);
		return mf;
	}
	int h[N],dis[N],pre[N],pu[N];
	priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>pq;
	int min_cost(int f)
	{
		int res=0;
		for(int i=1;i<=cnt;i+=2)
			e[i].f=e[i].w;
		for(int i=2;i<=cnt;i+=2)
			e[i].f=0;
		while(f>0)
		{
			for(int i=1;i<=n;i++)
				dis[i]=INF;
			dis[s]=0;
			pq.emplace(0,s);
			while(!pq.empty())
			{
				auto p=pq.top();
				pq.pop();
				int u=p.second;
				if(dis[u]<p.first)
					continue;
				for(int i=head[u];i;i=e[i].nxt)
				{
					int v=e[i].v,c=e[i].c,f=e[i].f;
					if(f>0&&dis[v]>dis[u]+c+h[u]-h[v])
					{
						dis[v]=dis[u]+c+h[u]-h[v];
						pre[v]=i,pu[v]=u;
						pq.emplace(dis[v],v);
					}
				}
			}
			if(dis[t]==INF)
				return -1;
			for(int i=1;i<=n;i++)
				h[i]+=dis[i];
			int d=f;
			for(int u=t;u!=s;u=pu[u])
				d=min(d,e[pre[u]].f);
			f-=d;
			res+=d*h[t];
			for(int u=t;u!=s;u=pu[u])
			{
				e[pre[u]].f-=d;
				e[(pre[u]-1^1)+1].f+=d;
			}
		}
		return res;
	}
}g;
const int N=55;
int n,m,k,c,dp[N][N];
char a[N][N];
void sol(int x,int y)
{
	g.add(g.s,c,1,0);
	for(int i=0;i<=n;i++)
		for(int j=0;j<=m;j++)
			dp[i][j]=-1;
	dp[x][y]=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			if(a[i][j]=='#')
				continue;
			if(dp[i-1][j]!=-1)
				dp[i][j]=max(dp[i][j],dp[i-1][j]+1);
			if(dp[i][j-1]!=-1)
				dp[i][j]=max(dp[i][j],dp[i][j-1]+1);
			if(dp[i][j]!=-1)
				g.add(c,k+(i-1)*m+j,1,-dp[i][j]);
		}
	}	
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		scanf("%s",a[i]+1);
		for(int j=1;j<=m;j++)
			if(a[i][j]=='o')
				k++;
	}
	g.n=k+n*m+2,g.s=k+n*m+1,g.t=k+n*m+2;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			g.add(k+(i-1)*m+j,g.t,1,0);
			if(a[i][j]=='o')
			{
				c++;
				sol(i,j);
			}
		}
	}
	printf("%d\n",-g.min_cost(g.max_flow()));
	return 0;
}

Measured memory_bytes: 6528
#include<stdio.h>
#define MAX 100000
#define NIL -1

struct Node{
  int parent;
  int left;
  int right;
};

struct Node T[MAX];
int n,D[MAX],H[MAX];

void setDepth(int u,int d){
  if(u==NIL) return;
  D[u]=d;
  setDepth(T[u].left,d+1);
  setDepth(T[u].right,d+1);
}

int setHeight(int u){
  int h1=0,h2=0;
  if(T[u].left!=NIL) h1=setHeight(T[u].left)+1;
  if(T[u].right!=NIL) h2=setHeight(T[u].right)+1;
  if(h1>h2){
    H[u]=h1;
    return H[u];
  }
  else{
    H[u]=h2;
    return H[u];
  }
}

int getSibling(int u){
  if(T[u].parent==NIL) return NIL;
  if(T[T[u].parent].left!=u && T[T[u].parent].left!=NIL) return T[T[u].parent].left;
  if(T[T[u].parent].right!=u && T[T[u].parent].right!=NIL) return T[T[u].parent].right;
  return NIL;
}

void print(int u){
  int deg=0;
  printf("node %d: ",u);
  printf("parent = %d, ",T[u].parent);
  printf("sibling = %d, ",getSibling(u));
  if(T[u].left!=NIL) deg++;
  if(T[u].right!=NIL) deg++;
  printf("degree = %d, ",deg);
  printf("depth = %d, ",D[u]);
  printf("height = %d, ",H[u]);

  if(T[u].parent==NIL){
    printf("root\n");
  }else if(T[u].left==NIL && T[u].right==NIL){
    printf("leaf\n");
  }else{
    printf("internal node\n");
  }
}

int main(){
  int i,v,l,r,root=0;
  scanf("%d",&n);

  for(i=0;i<n;i++){
    T[i].parent=NIL;
  }
  for(i=0;i<n;i++){
    scanf("%d%d%d",&v,&l,&r);
    T[v].left=l;
    T[v].right=r;
    if(l!=NIL) T[l].parent=v;
    if(r!=NIL) T[r].parent=v;
  }
  for(i=0;i<n;i++){
    if(T[i].parent==NIL) root=i;
  }

  setDepth(root,0);
  setHeight(root);

  for(i=0;i<n;i++){
    print(i);
  }
  return 0;
}



Measured memory_bytes: 2104
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ST first
#define ND second
#define ll long long
#define ld long double
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using namespace std;
using namespace __gnu_pbds;
 
// replace ll  with pair if multiset needed
typedef tree<ll , null_type, greater<ll >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ordered_set secik;
 
const ll  INF = 1e9 + 9;
const ll  MOD = 1e9 + 7;
const long long LINF = (ll)1e18 + 3;
 
// secik.insert({x, t++});
// secik.erase(secik.lower_bound({x,-1}));
// *secik.find_by_order(x)).first << "\n";
// secik.order_of_key(x)
 
//random_device device;
//mt19937 gener(device());
//uniform_int_distribution<ll > gen(0,n-1);
//gen(gener); // generate random number

	
int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
 
	ll a,v1,b,v2,t; cin >> a >> v1 >> b >> v2 >> t;
	if(a == b){
		cout << "YES\n";
		return 0;
	}
	if(a < b){
		if(a + t * v1 >= b + t * v2) cout << "YES\n";
		else cout << "NO\n";
	} else {
		if(a - t * v1 <= b - t * v2) cout << "YES\n";
		else cout << "NO\n";
	}
		
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,a[1299710]={1,2,0,0},c,i,j;
	for(i=4;i<1299710;i++){
		for(j=2,c=0;j*j<=i;j++)if(i%j==0)c++;
		if(c)a[i]+=a[i-1]+1;
	    else a[i]=0;
	}
	for(i=1299709;i>=0;i--){
		if(a[i]){for(j=0,c=a[i];j<c;j++)a[i--]=c+1;i++;}
	}
	while(cin>>n,n)cout<<a[n]<<endl;
}

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

const string YES = "Yes";
const string NO = "No";

void solve(int N, std::vector<int> L){
    int temp1=0,temp2=0;
    for(auto it=L.begin();it !=L.end();++it){
        if(temp1<*it){
            temp1=*it;
        }
        temp2+=*it;
        //printf("temp1%d\n",temp1);
        //printf("temp2%d\n",temp2);

    }
    if(temp2>2*temp1){
        printf("Yes\n");
    }else{
        printf("No\n");
    }


}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    int N;
    scanf("%d",&N);
    std::vector<int> L(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%d",&L[i]);
    }
    solve(N, std::move(L));
    return 0;
}


Measured memory_bytes: 384
n = int(input())
l = list(map(int,input().split()))

ans = 0
for c in range(1,n):
    now = 0
    pas = set()
    for k in range(1,n):
        if k * c > n-1 or n-1-k*c <= c:
            break
        if n-1-k*c in pas or k*c in pas or n-1 == 2*k*c:
            break 
        now += l[n-1-k*c] + l[k*c]
        pas.add(n-1-k*c)
        pas.add(k*c)
        ans = max(ans,now)
        
print(ans)


Measured memory_bytes: 17468
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), l = sc.nextInt(), i;
		String[] s = new String[n];
		
		for(i = 0; i < n; i++) s[i] = sc.next();
		Arrays.sort(s);
		for(String str : s) System.out.print(str);
	}
}

Measured memory_bytes: 21972
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
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;}

//AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC
int main(){
    int n;cin>>n;
    vector<lint> a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    vector<lint> ruiseki(n+1);
    for(int i=1;i<n+1;i++)ruiseki[i]=a[i-1];
    for(int i=1;i<n+1;i++)ruiseki[i]+=ruiseki[i-1];
    map<lint,int> s;
    for(int i=0;i<n+1;i++)s[ruiseki[i]]++;
    lint ans=0,x;
    for(auto p:s){
        x=p.second;
        ans+=x*(x-1)/2;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 18712
from collections import deque
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

def solve():
  h,w,d  = (int(i) for i in input().split())
  a = [list(map(int, input().split())) for _ in range(h)]
  query = [False]*(h*w)
  distance = [0]*(h*w+1)
  for i in range(h):
    for j in range(w):
      query[a[i][j] - 1] = (i,j)
  q = int(input())
  
  for i in range(d,h*w):
    leftx,lefty = query[i-d]
    rightx,righty = query[i]
    distance[i] = distance[i-d]+abs(rightx-leftx)+abs(righty-lefty)
  #print(distance)
  ans = deque([])
  for i in range(q):
    l,r = (int(m) for m in input().split())
    ans.append(str(distance[r-1]-distance[l-1]))
  print("\n".join(ans))
solve()

Measured memory_bytes: 27216
#include <bits/stdc++.h>
using namespace std;
namespace UnionFind {
template <typename T>
int root(vector<T> &u, int x) {
    if (x < 0 || u.size() <= x) return -1;
    if (u[x].parent == x)
        return x;
    else
        return u[x].parent = root(u, u[x].parent);
}
template <typename T>
bool connect(vector<T> &u, int a, int b) {
    a = root(u, a), b = root(u, b);
    if (a == b || a < 0 || b < 0) return false;
    { /* do something */
    }
    u[b].parent = a;
    return true;
}
// O(u.size())
template <typename T>
void count(vector<T> &u, map<int, int> &ret) {
    for (int i = 0; i < u.size(); i++) {
        int tmp = u[i].parent;
        if (!ret.count(tmp)) {
            ret[tmp] = 0;
        }
        ret[tmp]++;
    }
}
};  using namespace UnionFind;

struct Node { int parent; };

using P =pair<set<int>, set<int>>;

// 方針: union-find でまとめていく。
int main() {
    #ifdef DEBUG
    std::ifstream in("/home/share/inputf.in");
    std::cin.rdbuf(in.rdbuf());
    #endif
    int N, M;
    cin >> N >> M;
    vector<int> p(N);
    vector<Node> tree(N);
    vector<int> x(M), y(M);
    map<int, P> m;
    for(int i = 0; i < N; i++) {
        tree[i] = {i};
        cin >> p[i];
        p[i]--;
    }
    for(int i = 0; i < M; i++) {
        cin >> x[i] >> y[i];
        x[i]--, y[i]--;
        connect(tree, x[i], y[i]);
    }
    for(int i = 0; i < N; i++) {
        int r = root(tree, i);
        if(!m.count(r)) {
            m[r] = P();
        }
        m[r].first.insert(i);
        m[r].second.insert(p[i]);
    }
    int ans = 0;
    for(auto itor = m.begin(); itor != m.end(); itor++) {
        auto &x = itor->second.first;
        auto &y = itor->second.second;
        set<int> o;
        set_intersection(x.begin(), x.end(),
                         y.begin(), y.end(),
                         inserter(o, o.end()));
        ans += o.size();
    }
    cout << ans << endl;
}

Measured memory_bytes: 25216
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include <iterator>
#include <algorithm>

using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define reprrev(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); i++)
#define reprev(i, n) reprrev(i, 0, n)

#define PI M_PI
#define INF 100000000
#define NINF -100000000

typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;



int main()
{
	int N;
	cin >> N;
	vi a(N, 0);
	rep(i, N) cin >> a[i];
	sort(a.begin(), a.end());

	int ans = 0;
	int ptr = 0;
	while (ptr < N) {
		int now = a[ptr], num = 0;

		while (ptr < N && a[ptr] == now)num++, ptr++;
		ans += num % 2;
	}

	cout << ans << endl;

	return 0;
}



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

int main() {
	int n;
	cin >> n;
	n--;
	vector<int> a(n + 1), b(n);
	for (int i = 0; i < n; i++)
	{
		cin >> b[i];
	}
	a[0] = b[0], a[1] = b[0];
	for (int i = 1; i < n; i++)
	{
		a[i + 1] = b[i];
		if (b[i] < b[i - 1]) a[i] = b[i];
	}
	long long sum = 0;
	for (int i = 0; i < n + 1; i++)
	{
		sum += a[i];
	}
	cout << sum;
}

Measured memory_bytes: 256
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy

# If you use recursive call, uncomment this code
#sys.setrecursionlimit(10**6)

def main():
    s = input()
    print("ARC" if s == "ABC" else "ABC")

if __name__ == '__main__':
    main()


Measured memory_bytes: 10336
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int type= sc.nextInt();
		if (type==1) {
			System.out.println("Hello World");
		} else {
			int A= sc.nextInt();
			int B = sc.nextInt();
			System.out.println(A+B);
		}
	}
}

Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
int main(){
  #define int long long
  int H, W;
  cin >> H >> W;
  vector<vector<int>> vec(10, vector<int>(10));
  vector<vector<int>> tree(10, vector<int>(0));
  vector<int> mp(10);
  for (int i = 0; i <= 9; i++) {
    for (int j = 0; j <= 9; j++) {
      if (i != j) {
        tree.at(i).push_back(j);
      }
    }
  }
  for (int i = 0; i <= 9; i++) {
    for (int j = 0; j <= 9; j++) {
      cin >> vec.at(i).at(j);
    }
  }
  for (int i = 0; i <= 9; i++) {
    if (i == 1) {
      continue;
    }
    vector<int> dist(10,-1);
    queue<int> que;
    que.push(i);
    dist.at(i) = 0;
    while (!que.empty()) {
      int v = que.front();
      que.pop();
      if (v == 1) {
        continue;
      }
      for (int j = 0; j < (int) tree.at(v).size(); j++) {
        int nv = tree.at(v).at(j);
        if (dist.at(nv) != -1 && dist.at(nv) <= dist.at(v) + vec.at(v).at(nv)){
          continue;
        }
        //cout << v << " " << dist.at(v) << "   " << nv << " " << dist.at(nv) << endl;
        dist.at(nv) = dist.at(v) + vec.at(v).at(nv);
        que.push(nv);
      }
    }
    mp.at(i) = dist.at(1);
  }
  int answer = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      int a;
      cin >> a;
      if (a == -1) {
        continue;
      }
      answer += mp.at(a);
    } 
  }
  cout << answer << endl;
}

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll A[100005];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    REP(i, N) {
        cin >> A[i];
    }
    ll ans = INF;
    {
        ll t = 0;
        ll s = 0;
        REP(i, N) {
            s += A[i];
            if (i % 2 == 0) {
                if (s <= 0) {
                    t += 1 - s;
                    s = 1;
                }
            }
            else {
                if (s >= 0) {
                    t += s + 1;
                    s = -1;
                }
            }
        }
        ans = std::min(ans, t);
    }
    {
        ll t = 0;
        ll s = 0;
        REP(i, N) {
            s += A[i];
            if (i % 2 == 1) {
                if (s <= 0) {
                    t += 1 - s;
                    s = 1;
                }
            }
            else {
                if (s >= 0) {
                    t += s + 1;
                    s = -1;
                }
            }
        }
        ans = std::min(ans, t);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    H, W = LI()
    a = []
    excrow = set()
    exccol = set()
    for _ in range(H):
        a.append(S())
    for row in range(H):
        all_white = True
        for c in a[row]:
            if c == '#':
                all_white = False
                break
        if all_white:
            excrow.add(row)

    for col in range(W):
        all_white = True
        for r in range(H):
            if a[r][col] == '#':
                all_white = False
                break
        if all_white:
            exccol.add(col)

    newA = []
    for row in range(H):
        if row in excrow:
            continue
        newA.append(a[row])

    newnewA = []
    for row in range(len(newA)):
        string = ''
        for col in range(W):
            if col in exccol:
                continue
            string += newA[row][col]
        newnewA.append(string)
    print('\n'.join(newnewA))


main()



Measured memory_bytes: 83872
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N ;
    cin >> N ;
    vector<double> A(N);
    vector<double> B(N-1);
    for (int i = 0 ; i < N ; i++) {
        cin >> A.at(i) ;
    }
    //いつもの入力パターン
    sort(A.begin(),A.end());
    
     B.at(0) = ( A.at(0) + A.at(1) ) / 2 ;
    
    for (int i = 1 ; i < N - 1 ; i++) {
      B.at(i)  =  ( B.at(i-1) + A.at(i+1) ) / 2 ;
    }
    cout << fixed << setprecision(15) << B.at(N-2);
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <cstring>
#define ll long long int
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define PI 3.141592653589793
using namespace std;

int main() {
    int N,M,ans=0;

    cin >> N >> M;
    vector<int> X(M);
    vector<int> d(M-1);
    REP(i,M) cin >> X[i];

    sort(ALL(X));
    REP(i,M-1) d[i] = X[i+1] - X[i];

    sort(ALL(d));
    REP(i,M-N) ans += d[i];

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    a = S()
    n = len(a)
    ans = (len(a)+1) * len(a) // 2
    d = defaultdict(int)
    for i in range(n):
        d[a[i]] += 1
    for val in d.values():
        ans -= val * (val + 1) // 2
    print(ans+1)
    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 40688
#include <iostream>

//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <tuple>
#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 <climits>

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<long long> VL;
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 (auto i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

//repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);

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

int N;

int main()
{
    cin >> N;

    VI H;
    REP(i, N)
    {
        int h;
        cin >> h;

        H.push_back(h);
    }

    VL min_costs(N, 1'000'000'000'000);

    min_costs[0] = 0;
    min_costs[1] = abs(H[1] - H[0]);

    FOR(i, 2, N) //3つ目に行くところからの一般化
    {
        min_costs[i] = min(
            min_costs[i - 2] + abs(H[i] - H[i - 2]),
            min_costs[i - 1] + abs(H[i] - H[i - 1]));
    }

    cout << min_costs[N - 1] << endl;
}

Measured memory_bytes: 1528
#include <bits/stdc++.h>
using namespace std;
int n,k,a[100005],dp[100005];
int solve(int idx){
    if(idx >= n - 1)
        return 0;
    int &ans = dp[idx];
    if(ans != -1)
        return ans;
    ans = 1e9;
    for(int i = 1; i <= k; i++){
        if(idx + i < n)
            ans = min(ans, abs(a[idx] - a[idx + i]) + solve(idx + i));
    }
    return ans;
}
int main()
{
    ios::sync_with_stdio(0);
    cin >> n >> k;
    memset(dp , -1, sizeof dp);
    for(int i = 0; i < n; i++)
        cin >> a[i];
    cout << solve(0) << endl;
    return 0;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

ll dp[105][2][105];

void Main() {
    string N;
    ll K;
    cin >> N >> K;
    ll n = N.size();
    dp[0][0][0] = 1;
    rep(i, n) {
        int d = N[i] - '0';
        rep(j, 2) {
            if (j == 1) {
                d = 9;
            }
            rep(k, K + 1) {
                rep(m, d + 1) {
                    if (m == 0) {
                        dp[i + 1][j == 1 || m < d][k] += dp[i][j][k];
                    } else {
                        dp[i + 1][j == 1 || m < d][k + 1] += dp[i][j][k];
                    }
                }
            }
        }
    }
    cout << dp[n][1][K] + dp[n][0][K] << '\n';
}

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


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define EPS      (double)1e-9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
template<class Type_a,class Type_b> bool chmax(Type_a &a,const Type_b &b){if(a<b){a=b;return true;}return false;}
template<class Type_a,class Type_b> bool chmin(Type_a &a,const Type_b &b){if(a>b){a=b;return true;}return false;}
template<class Type> void line(const Type &a){int cnt=0;for(const auto &elem:a){if(cnt++)cout<<' ';cout<<elem;}cout<<endl;}

template<class Type,class Type_k>
Type ipow(Type n,Type_k k){//n^k. (O(log n))
	if(k==0) return 1;
	Type res=ipow(n*n,k/2);
	if(k&1) res*=n;
	return res;
}

int main(){
	llong a,b,c;
	cin>>a>>b>>c;
	
	bool ans;
	if(a-b>c){
		ans=false;
		goto Exit;
	}
	
	ans=(4*a*b<ipow(c-a-b,2));
	
Exit:	
	cout<<(ans?"Yes":"No")<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String str = sc.next();
		int count = 0;
		for (int i = 0; i < str.length(); i++)
			if (str.charAt(i) == 'o')
				count++;
		System.out.println(700 + (count * 100));
	}

}

Measured memory_bytes: 26924
#include <stdio.h>
#include <string.h>
#define a(a,b,c) for(LL i=a;i<=b;i+=c) ans(i)
typedef long long LL;
const double eps=1e-15;
int k;
LL lst=0;
void ans(LL i){
	if(k) printf("%lld\n",i),k--;
}
int main(){
	scanf("%d",&k);
	a(1,9,1);
	a(19,99,10);
	a(199,1999,100);
	a(2999,29999,1000);
	a(39999,399999,10000);
	a(499999,4999999,100000);
	a(5999999,59999999,1000000);
	a(69999999,699999999,10000000);
	a(799999999,7999999999,100000000);
	a(8999999999,89999999999,1000000000);
	a(99999999999,999999999999,10000000000);
	a(1099999999999,9999999999999,100000000000);
	a(10999999999999,109999999999999,1000000000000);
	a(119999999999999,999999999999999,10000000000000);
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    cin >> n;
    cin.ignore();
    for (int _ = 0; _ < n; ++_) {
        string s;
        getline(cin, s);
        for (int i = 0; i+6 < s.size(); ++i) {
            if(s.substr(i, 7) == "Hoshino"){
                s[i+6] = 'a';
            }
        }
        cout << s << "\n";
    }
    return 0;
}


Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n;
    cin >> n;
    map<int, int> mp;
    int ans = 0;
    rep(i, 0, n) {
        int a;
        cin >> a;
        mp[a]++;
    }
    for (auto x : mp) {
        if (x.second < x.first) ans += x.second;
        else ans += (x.second - x.first);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4736
import java.util.*;
import static java.lang.Math.*;

public class Main {
	public static void main(String[] args) {
		int i;
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		sc.close();
		sc = null;
		int cnt1=0;
		int cnt2=0;
		char[] zerone = {'0', '1'};
		for(i=0; i < s.length(); i++) {
			if(s.charAt(i) == zerone[i%2]) {cnt1++;}
			else {cnt2++;}
		}
		System.out.println(min(cnt1, cnt2));
	}
}

Measured memory_bytes: 25812
#[allow(unused_imports)]
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::{Chars, Usize1};
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused)]
const ALPHA_SMALL: [char; 26] = [
    'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
    't', 'u', 'v', 'w', 'x', 'y', 'z',
];
#[allow(unused)]
const ALPHA: [char; 26] = [
    'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
    'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
];
#[allow(unused)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(unused)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(unused)]
fn read_touple<T: std::str::FromStr + Copy>() -> (T, T) {
    let v: Vec<T> = read_vec();
    assert_eq!(v.len(), 2);
    (v[0], v[1])
}
fn main() {
    input!(N: usize, M: usize);
    let mut g = vec![vec![]; N];
    for _ in 0..M {
        input!((x, y, z): (Usize1, Usize1, Usize1));
        g[x].push(y);
        g[y].push(x);
    }

    let mut visit = vec![false; N];
    let mut ans = 0;
    for i in 0..N {
        if visit[i] == false {
            bfs(N, &g, i, &mut visit);
            ans += 1;
        }
    }

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

//単一視点から目的のノードまでの最短距離、ただし全ての辺の重みが等しいグラフに限る
fn bfs(n: usize, g: &Vec<Vec<usize>>, start: usize, visit: &mut Vec<bool>) {
    let mut q = std::collections::VecDeque::new();

    //init
    visit[start] = true;
    q.push_back(start);

    while let Some(now) = q.pop_front() {
        for &e in &g[now] {
            if !visit[e] {
                visit[e] = true;
                q.push_back(e);
            }
        }
    }
}


Measured memory_bytes: 10732
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;

class Main {

	public static void main(String[] args) throws Exception {

		try {

			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

			String[] dailyColors = br.readLine().split("\\s");

			int sizeOfColorList = getSizeOfColorList(dailyColors);

			System.out.println(sizeOfColorList);

		} catch (IOException | NumberFormatException e) {
			e.printStackTrace();
			System.exit(0);
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(0);
		}

	}

	public static int getSizeOfColorList(String[] dailyColors) {
		
		Set<String> colorList = new HashSet<>();
		
		for(String color : dailyColors) {
			colorList.add(color);
		}
		
		return colorList.size();
	}
}

Measured memory_bytes: 21204
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rItr(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define Itr(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define setp(n) fixed << setprecision(n)
#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>
#define All(a) (a.begin()),(a.end())
#define rAll(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;

#define BIT 380000.0

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n; cin>>n;
	lf ans=0.0;
	rep(i,n){
		lf m;
		string s;
		cin>>m>>s;
		if (s=="JPY")
			ans+=m;
		else
			ans+=BIT*m;
	}
	cout<<setp(8)<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int kansu(long int, int, int, int);

long int N;
int ans=0;

int main(){
    scanf("%ld", &N);

    printf("%d\n", kansu(0,0,0,0));

    return 0;
}

int kansu(long int a, int b, int c, int d){
    if(a > N)
        return ans;
    if((b+c+d) == 3)
        ans++;

    kansu(a*10+3, 1, c, d);
    kansu(a*10+5, b, 1, d);
    kansu(a*10+7, b, c, 1);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define bitrep(X,N) for(ll X = 0; X < (1 << (N)); X++)
#define PI (acos(-1.0))
#define sorta(V) sort(V.begin(), V.end())
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end() 
#define CERR if(false) cerr

using namespace std;

bool palindromeq(int n){

    int d1 = n / 10000;
    int d5 = n % 10;
    int d2 = (n / 1000) % 10;
    int d4 = (n % 100) / 10;

    return d1 == d5 && d2 == d4;

}


int main(){

    int a,b;
    cin >> a >> b;

    int ans = 0;

    for(int i = a; i <= b; i++){
        if(palindromeq(i)) ans++;
    }

    cout << ans << endl;

    return 0; 
}

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

int main(){
	int n,k;	cin>>n>>k;
	int h[n];	for(int i=0;i<n;i++)cin>>h[i];
	sort(h, h+n);

	int ans=1000000000;
	for(int i=0;i<n-k+1;i++){
		ans=min(ans, h[i+k-1]-h[i]);
	}

	cout<<ans<<endl;

	return 0;
}


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

#define FOR(a, b) for(int i=a; i<b; i++)
int grid[21][21];

struct Point
{
    int x;
    int y;
};

struct queueNode
{
    Point pt;
    int dist;
};

bool isValid(int row, int col, int ROW, int COL)
{

    return (row >= 0) && (row < ROW) &&
           (col >= 0) && (col < COL);
}

int rowNum[] = {-1, 0, 0, 1};
int colNum[] = {0, -1, 1, 0};

int BFS(Point src, Point dest, int ROW, int COL)
{

    if (!grid[src.x][src.y] || !grid[dest.x][dest.y])
        return -1;

    bool visited[ROW][COL];
    memset(visited, false, sizeof visited);

    visited[src.x][src.y] = true;

    queue<queueNode> q;

    queueNode s = {src, 0};
    q.push(s);

    while (!q.empty())
    {
        queueNode curr = q.front();
        Point pt = curr.pt;

        if (pt.x == dest.x && pt.y == dest.y)
            return curr.dist;

        q.pop();

        for (int i = 0; i < 4; i++)
        {
            int row = pt.x + rowNum[i];
            int col = pt.y + colNum[i];

            if (isValid(row, col, ROW, COL) && grid[row][col] &&
               !visited[row][col])
            {
                visited[row][col] = true;
                queueNode Adjcell = { {row, col},
                                      curr.dist + 1 };
                q.push(Adjcell);
            }
        }
    }

    return -1;
}

int main()
{
    int h, w, j;
    cin >> h >> w;
    FOR (0, h)
    {
        string buf;
        cin >> buf;
        for (j=0; j<w; j++)
        {
            if (buf[j] == '.')
                grid[i][j] = 1;
            else if (buf[j] == '#')
                grid[i][j] = 0;
        }
    }

    int ans = 0;
    FOR (0, h)
    {
        for(j=0; j<w; j++)
        {
            if (grid[i][j] == 1)
            {
                Point source = {i, j};
                for (int k=0; k<h; k++)
                {
                    for (int l=0; l<w; l++)
                    {
                        if ((i!=k || j!=l) && grid[k][l] == 1)
                        {
                            Point dest = {k, l};
                            int temp = BFS(source, dest, h, w);
                            //cout <<  temp << " " << i << " " << j <<" " << k << " " << l <<endl;
                            if (temp != INT_MAX)
                                ans = max(ans, temp);
                        }
                    }
                }
            }
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(clippy::many_single_char_names)]
#![allow(clippy::suspicious_arithmetic_impl)]

// using Rust(1.42.0)
// My Library Repo is at "https://github.com/Loptall/prcn_lib"
// check available crates on AtCoder at "https://atcoder.jp/contests/language-test-202001"

/*
    AtCoder Language Update 2020204 お疲れ様でした! 有難いです
*/


// Dep crates are...
use std::cmp::{max, min, Ordering};
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet, VecDeque};
use std::mem::swap;
use std::ops::*;
use std::{i32, i64, isize, u32, u64, usize};

use itertools::*;
use itertools_num::*;
use lazy_static::lazy_static;
use maplit::{btreemap, btreeset, hashmap, hashset};
use num_bigint::{BigInt, BigUint};
use num_integer::{binomial, gcd, lcm, Integer};
use permutohedron::Heap;
use proconio::{fastout, input, is_stdin_empty, marker::*};
use rand::random;

const MOD: usize = 1_000_000_007;

// code...
#[fastout]
fn main() {
    input! {
        n: usize, k: usize
    }

    let mut ans = 0usize;

    let mut acum = vec![0usize; n + 2];
    for i in 0..=n {
        acum[i + 1] = acum[i] + i;
    }

    for choose in k..=n+1 {
        let min = acum[choose];
        // println!("{}", acum[n + 1]);
        // println!("{}", acum[n + 1 - choose]);
        let max = acum[n + 1] - acum[n + 1 - choose];
        ans += max - min + 1;
        ans %= MOD;
    }

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


Measured memory_bytes: 3524
#include <bits/stdc++.h>
using namespace std;
 
int main () {
  int N, K;
  cin >> N >> K;
  int ans = 0;
  for (int i = 0; i < N; i++) {
    int A;
    cin >> A;
    if (A >= K) {
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3628