akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++) 
#define all(v) begin(v),end(v)
using ll = long long;

int main() {
  int n;cin>>n;
  rep(i,26)rep(j,15){
    int ans=i*4+j*7;
    if(ans==n){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
}

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

#define gcu getchar_unlocked
#define pcu putchar_unlocked
#define _T template <typename T>
#define _HT template <typename H, typename... T>
#define _il inline
#define _in _il int in
#define _sc _il bool scan
_T T in(int c){T n=0;bool m=false;if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0');return m?-n:n;} //&&c<='9'
_in() {return in<int>(gcu());}
_T T scan(T &n){int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_sc(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#endif
_HT _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _vo _il void out
#define _vl _il void outl
_vo(const char *s){while(*s)pcu(*s++);}
_vo(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_vo(string s){for(char c:s)pcu(c);}
#endif
_T _vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
_vl(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);outl();}
#endif
_HT _vo(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _vl(T&&... t){out(move(t)...);outl();}

int main() {
	for (int i = 0, e = 1 << in(); i < e; i++) {
		out(i, ':');
		for (int j = 0, t; (t = i >> j); j++)
			if (t & 1)
				out(' ', j);
		outl();
	}
}


Measured memory_bytes: 2544
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

int main(){
    ll N;
    cin >> N;
    
    rep(n,1,N+1){
      	ll ans = 0;
        rep(i,1,n/3+1){
            rep(j,i,n/3+1){
                int x = i;
                int y = j;
                int k = 4*n - 2*x*y -3*(x*x + y*y);
                if(k < 0) break;
                int rk = sqrt(k);
                if(rk*rk != k) continue;
                if(rk-(x+y) < 2) continue;
                int m = rk-(x+y);
                int mdiv2 = m/2;
                if(mdiv2*2 != m) continue;
                
                int z = mdiv2;
              	if(z < y) break;
                
                if(x!=y && y!=z && z!=x)ans+=6;
                else if(x==y && y!=z && z!=x)ans+=3;
                else if(x!=y && y==z && z!=x)ans+=3;
                else if(x==y && y==z && z==x)ans+=1;
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

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

typedef long long LL;
const int MV=1e5+5;
const int MB=20;

struct Edge
{
	int v,c,d;
	Edge(int v=0,int c=0,int d=0)
		:v(v),c(c),d(d){}
};
vector<Edge> g[MV];

int dfn[MV*2],pos[MV];
int n,q;

vector<int> id[MV];
vector<LL> sum[MV];
vector<LL> cnt[MV];
int ndfn=0;

void init()
{
	for(int i=0;i<=n;i++)
	{
		id[i].push_back(0);
		sum[i].push_back(0);
		cnt[i].push_back(0);
	}
	ndfn=0;
}

LL dis[MV];
void dfs(int u,int fa,int c,int d,LL nd)
{
	//cout<<u<<" "<<c<<endl;
	dfn[++ndfn]=u;
	pos[u]=ndfn;
	id[c].push_back(ndfn);
	sum[c].push_back(sum[c].back()+d);
	cnt[c].push_back(cnt[c].back()+1);
	dis[u]=nd;
	//cout<<u<<endl;
	for(Edge e:g[u])
	{
		int v=e.v;
		if(v==fa) continue;
		dfs(v,u,e.c,e.d,nd+e.d);
	}
	id[c].push_back(++ndfn);
	sum[c].push_back(sum[c].back()-d);
	cnt[c].push_back(cnt[c].back()-1);
}

int fa[MV][MB],dep[MV];
void dfs_fa(int u,int f,int depth)
{
	dep[u]=depth;
	for(Edge e:g[u])
	{
		int v=e.v;
		if(v==f) continue;
		if(fa[v][0]==-1)
		{
			fa[v][0]=u;
			dfs_fa(v,u,depth+1);
		}
	}
		
}
void init_lca(int root)
{
	memset(fa,-1,sizeof(fa));
	dfs_fa(root,0,0);
	for(int j=1;j<MB;j++)
		for(int i=1;i<=n;i++)
			fa[i][j]=fa[fa[i][j-1]][j-1];
}
int lca(int a,int b)
{
	if(dep[a]>dep[b]) swap(a,b);
	int k=dep[b]-dep[a];
	for(int i=0;(1<<i)<=k;i++)
		if(k&(1<<i)) b=fa[b][i];
	if(a==b) return a;
	for(int i=MB-1;i>=0;i--)
	{
		if(fa[a][i]!=fa[b][i])
		{
			a=fa[a][i];
			b=fa[b][i];
		}
	}
	return fa[a][0];
}

inline LL getsum(int u,int c,int d)
{
	int p=upper_bound(id[c].begin(),id[c].end(),pos[u])-id[c].begin()-1;
	//cout<<p<<endl;
	LL ans=dis[u]-sum[c][p]+cnt[c][p]*d;
	//cout<<u<<" "<<dis[u]<<" "<<sum[c][p]<<" "<<cnt[c][p]<<" "<<ans<<endl;
	return ans;
}

int main()
{
	//freopen("F_in.txt","r",stdin);
	scanf("%d%d",&n,&q);
	int u,v,c,d;
	for(int i=1;i<n;i++)
	{
		scanf("%d%d%d%d",&u,&v,&c,&d);
		g[u].emplace_back(v,c,d);
		g[v].emplace_back(u,c,d);
	}
	init();
	dfs(1,0,0,0,0);
	// for(int i=1;i<=n;i++)
	// 	cout<<dis[i]<<" ";
	// cout<<endl;
	// for(int i=1;i<=n;i++)
	// 	cout<<pos[i]<<" ";
	// cout<<endl;
	// for(int i=0;i<=n-1;i++)
	// {
	// 	cout<<"id "<<i<<":";
	// 	for(int j:id[i])
	// 		cout<<" "<<j;
	// 	cout<<endl;
	// 	cout<<"sum "<<i<<":";
	// 	for(int j:sum[i])
	// 		cout<<" "<<j;
	// 	cout<<endl;
	// 	cout<<"cnt "<<i<<":";
	// 	for(int j:cnt[i])
	// 		cout<<" "<<j;
	// 	cout<<endl;
	// }
	init_lca(1);
	while(q--)
	{
		scanf("%d%d%d%d",&c,&d,&u,&v);
		int l=lca(u,v);
		//cout<<l<<endl;
		printf("%lld\n",getsum(u,c,d)+getsum(v,c,d)-2*getsum(l,c,d));
	}
	return 0;
}

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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//Write From this Line

int main()
{
	string s;
	cin >> s;
	int n = s.size();
	string sei = "CODEFESTIVAL2016";
	int ans = 0;
	rep(i,16){
		if(s[i] != sei[i]){
			ans ++;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define endl "\n"
#define pii pair<int,int> 
#define ff first
#define ss second
#define mii map<int,int>
#define si set<int>
#define sti stack<int>
#define qi queue<int>
#define vi vector<int>
#define pq priority_queue<int>
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int M=1e9+7;
int cnt=0;
  
bool check(vi v[],int n,int mid,int k){
	int ans=0;
	if(mid>=0){
		ans+=v[0].size()*v[1].size();
		ans+=(v[0].size()+v[1].size())*cnt;
		ans+=(cnt*(cnt-1))/2;
	}
	for(int i=0;i<2;i++){
		for(int j=0;j<v[i].size();j++){
			if(mid>=0){
				int x=(mid)/v[i][j];
				int y=(upper_bound(v[i].begin()+j+1,v[i].end(),x)-v[i].begin())-1;
				ans+=y-j;
			}
			else{
				if(i==1) break;
				int x=(abs(mid)+v[i][j]-1)/v[i][j];
				ans+=v[i+1].size()-(lower_bound(v[i+1].begin(),v[i+1].end(),x)-v[i+1].begin());
			}
		}
	}
	if(ans<k) return true;
	else return false;
}

int32_t main(){
    IOS;
    int n,k;
    cin>>n>>k;
    vector<int> v[2];
    for(int i=0;i<n;i++){
    	int x; cin>>x;
    	if(x>0) v[0].pb(x);
    	else if(x<0){v[1].pb(-x);}
    	else cnt++;
    }
    sort(v[0].begin(),v[0].end());
    sort(v[1].begin(),v[1].end());
	int l=-1e18+2,h=1e18+2;
	int ans=-1e18+5;
	while(l<=h){
		int mid=(l+h)/2;
		if(check(v,n,mid,k)){
			ans=max(ans,mid);
			l=mid+1;
		}
		else{
			h=mid-1;
		}
	}
	cout<<ans+1<<endl;
}

Measured memory_bytes: 2420
import collections
n = int(input())
s = []
for _ in range(n):
    s.append(input())
c = collections.Counter(s)
print('AC x {}'.format(c['AC']))
print('WA x {}'.format(c['WA']))
print('TLE x {}'.format(c['TLE']))
print('RE x {}'.format(c['RE']))

Measured memory_bytes: 16616
fun main(){
    val N = readLine()!!.toInt()
    val S = readLine()!!

    var r: Long = 0
    var g: Long = 0
    var b: Long = 0
    for(c in S){
        if (c == 'R') {
            r += 1
        } else if (c == 'G'){
            g += 1
        } else{
            b += 1
        }
    }
    
    var sub: Long = 0
    for(i in 0 until N){
        for(j in i+1 until N){
            if (S[i] == S[j]) continue
            val k = 2 * j - i
            if (k >= N || S[i] == S[k] || S[j] == S[k]) continue;
            sub += 1
        }
    }

    val ans: Long = r * g * b - sub
    println(ans)

}

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

#define FOR(i,j,k) for(int i = j; i < k; ++i)
#define reps(i,j,k) FOR(i,j,k)
#define rep(i,j) reps(i,0,j)

class team{ 
public:
	int id;
	int solved;
	int score;
	vector < int > problem;
	team(){}
	team(int id, int solved, int score, vector<int> problem) {
		this->id = id;
		this->solved = solved;
		this->score = score;
		this->problem = problem;
	}

	bool operator<(const team &a)const{
		return solved == a.solved ? score == a.score ? id < a.id : score > a.score : solved < a.solved;
	}
};

int main(){
	while(true){
		int M,T,P,R;
		scanf("%d%d%d%d",&M,&T,&P,&R);
		if(M ==0 && T == 0 && P == 0 && R == 0){
			break;
		}
	
		vector<team> teams;
		vector<int> clr(10);
		rep(i,T) {
			teams.emplace_back(team(i+1,0,0,clr));
		} 

		rep(i,R){
			int m,t,p,j;
			scanf("%d%d%d%d",&m,&t,&p,&j);
			--t;--p;
			if(j == 0) {
				teams[t].solved++;
				teams[t].score += m + 20*teams[t].problem[p];
				teams[t].problem[p] = -1;
			}
			else {
				teams[t].problem[p]++;
			}
		}

		sort(teams.rbegin(), teams.rend());
		
		cout << teams[0].id;
		
		reps(i,1,T) {
			if(teams[i].solved < teams[i-1].solved){
				cout << "," << teams[i].id ;
			}
			else if(teams[i].score != teams[i-1].score) {
				cout << "," << teams[i].id;
			}
			else{
				cout << "=" << teams[i].id;
			}
		}

		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3264
#include <bits/stdc++.h>
#define int long long
#define pii pair<int, int>

using namespace std;
const int inf = 1e9 + 7;
const int max_n = 2e5 + 7;
vector<int> gr[max_n];
map<int, int> dp[max_n], sz[max_n];
int fact[max_n];

inline int mul(int a, int b) {
	return a * b % inf;
}

inline int power(int a, int b) {
	int res = 1;
	while(b) {
		if (b & 1) res = mul(res, a);

		a = mul(a, a);

		b >>= 1;
	}

	return res;
}

inline int inv(int a) {
	return power(a, inf - 2);
}

inline int C(int n, int k) {
	return mul(fact[n], inv(mul(fact[k], fact[n - k])));
}


int iter = 0;

set<pii> temp;


void fuck(int v) {
	int c_sz = 0;
	int res = 1;
	for(int j : gr[v]) {
		c_sz += sz[j][v]; 
		res = mul(res, mul(dp[j][v], C(c_sz, sz[j][v])));
	}
	
	//cout << v << ":" << '\n';

	//cout << c_sz << " " << res << '\n';

	for(int j : gr[v]) {
		dp[v][j] = mul(res, inv(mul(dp[j][v], C(c_sz, sz[j][v]) ) ) );
		sz[v][j] = c_sz - sz[j][v] + 1;

		//cout << j << " " << dp[v][j] << " " << sz[v][j] << " " << dp[j][v] << " " << sz[j][v] << '\n';
	}

	//cout << '\n' << '\n';

}


void dfs(int v, int pr) {
	if (dp[v].size() >= 2) {
		fuck(v);
		return;
	}


	iter++;
	if (iter > 2 * max_n) {
		int aa = 0;
		fact[0] /= aa;
	}
	//temp.emplace(v, pr);


	sz[v][pr] = 0;
	dp[v][pr] = 1;

	for(int i : gr[v]) {
		if (i == pr) continue;
		if (dp[i].find(v) == dp[i].end()) dfs(i, v);
		sz[v][pr] += sz[i][v];
		dp[v][pr] = mul(dp[v][pr], mul(dp[i][v], C(sz[v][pr], sz[i][v])));
	}
	sz[v][pr]++;
}

inline void solve() {
	fact[0] = 1;
	for(int i = 1;i < max_n;i++) fact[i] = mul(fact[i - 1], i);

	int n;
	cin >> n;
	for(int i = 0;i < n - 1;i++) {
		int v1, v2;
		cin >> v1 >> v2;
		v1--; v2--;
		gr[v1].emplace_back(v2);
		gr[v2].emplace_back(v1);
	}


	//cout << "scan" << endl;


	for(int i = 0;i < n;i++) {
		for(int pr : gr[i]) {
			if (dp[i].find(pr) == dp[i].end()) dfs(i, pr);
		}
	}

	//cout << "dfs" << endl;

	for(int i = 0;i < n;i++) {
		int c_sz = 0;
		int res = 1;
		for(int j : gr[i]) {
			c_sz += sz[j][i]; 
			res = mul(res, mul(dp[j][i], C(c_sz, sz[j][i])));
		}

		cout << res << '\n';
	}

}







signed main() {
	/*freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);*/

 	cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);


    solve();
}

Measured memory_bytes: 84976
package main

import "fmt"

func main() {
	var n,y int
	notFound := true
	fmt.Scan(&n,&y)
	if n * 10000 >= y {
		for yukichi := 0; yukichi <= n; yukichi++ {
			for ichiyo := 0; yukichi + ichiyo <= n; ichiyo++ {
				hideyo := n - yukichi - ichiyo
				if 10000*yukichi + 5000*ichiyo + 1000*hideyo == y {
					notFound = false
					fmt.Println(yukichi,ichiyo,hideyo)
					break
				}
			}
			if !notFound {
				break
			}
		}
	}
	if notFound {
		fmt.Println("-1 -1 -1")
	}

}


Measured memory_bytes: 512
N = gets.to_i

current = [0, 0]

lt = 0
N.times do
  t, x, y = gets.split.map(&:to_i)

  xdiff = (current[0] - x).abs
  ydiff = (current[1] - y).abs
  tdiff = t - lt

  if xdiff + ydiff > tdiff
    puts 'No'
    exit
  end

  if tdiff.odd? && (xdiff + ydiff).odd? || tdiff.even? && (xdiff + ydiff).even?
    current = [x, y]
    lt = t
  else
    puts 'No'
    exit
  end
end

puts 'Yes'

Measured memory_bytes: 1788
import numpy as np

if __name__ == "__main__":
    w, h, n = map(int, input().split())
    mp = np.zeros((h, w))

    for i in range(n):
        tmp = list(map(int, input().split()))
        if tmp[2] == 1:
            mp[0:h, 0:tmp[0]] = 1
        elif tmp[2] == 2:
            mp[0:h, tmp[0]:w] = 1
        elif tmp[2] == 3:
            mp[0:tmp[1], 0:w] = 1
        else:
            mp[tmp[1]:h, 0:w] = 1

    print(w*h - np.count_nonzero(mp))


Measured memory_bytes: 12504
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <time.h>
#define int long long
#define endl '\n'
#define INF 1000000000000000000
#define EPS 1e-10
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define fi first
#define se second
#define pb push_back
#define double long double
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
template<class T, class S> bool chmax(T &a, const S &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class S> bool chmin(T &a, const S &b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	//modcalc();

	int k, n;
	cin >> k >> n;
	if (k == 1) {
		n = (n + 1) / 2;
		rep(i, n) {
			cout << 1 << ' ';
		}
		cout << endl;
		return 0;
	}
	if (k % 2 == 0) {
		cout << k / 2 << ' ';
		rep(i, n - 1) {
			cout << k << ' ';
		}
		cout << endl;
		return 0;
	}
	else {
		int m = n / 2;
		vector<int> ans(n, k / 2 + 1);
		rep(i, m) {
			if (ans[n - 1] != 0) ans[n - 1]--;
			else {
				int p;
				for (int j = n - 2; j >= 0; j--) {
					if (ans[j] != 0) {
						p = j;
						break;
					}
				}
				int q;
				for (int j = p; j >= 0; j--) {
					if (ans[j] != 1) {
						q = j;
						break;
					}
				}
				bool ok = true;
				if (ans[p] != 1) ok = false;
				for (int j = p + 1; j < n; j++) {
					if (ans[j]) ok = false;
				}
				if (ok) ans[p]--;
				else {
					ans[q]--;
					for (int j = q + 1; j < n; j++) {
						ans[j] = k;
					}
				}
			}
		}
		rep(i, n) {
			if (ans[i]) cout << ans[i] << ' ';
		}
		cout << endl;
	}
} 

Measured memory_bytes: 4608
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
const double PI = acos(-1.0);
#define MOD 1000000007LL
#define endl "\n"

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N, K;
  cin >> N >> K;
  vll A(N+1);
  for(int i = 0; i < N; i++){
    cin >> A.at(i);
  }
  set<ll> se;
  for(int i = 0; i < K; i++){
    vll imos(N+1, 0LL);
    for(int j = 0; j < N; j++){
      ll a = A.at(j);
      ll left = max(0LL, j - a);
      ll right = min(N, j + a + 1);
      imos.at(left)++;
      imos.at(right)--;
    }
    for(int j = 0; j <= N; j++){
      if(j != 0) imos.at(j) += imos.at(j-1);
      if(j != N){
        if(imos.at(j) == N) se.insert(j);
      }
    }
    A = imos;
    if(sz(se) == N) break;
  }
  for(int i = 0; i < N; i++){
    cout << A.at(i);
    if(i == N-1) cout << endl;
    else cout << ' ';
  }
}

Measured memory_bytes: 15752
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#define p pair<int,int>
#define P pair<p,int>
using namespace std;

int parse(string a) {
	int b = 0;
	for (char c : a)b = b * 10 + c - 48;
	return b;
}
int main() {
	int a, b;
	while (cin>>b>>a, a | b) {
		p G;
		vector<P>d[20000];
		int MAX = 0;
		for (int e = 0; e < a; e++) {
			for (int g = 0; g < b; g++) {
				string o;
				cin >> o;
				if (o=="S")d[0].push_back(P(p(e,g), 0));
				else if (o=="G")G = p(e, g);
				else if (o!=".") {
					d[parse(o)].push_back(P(p(e, g), 0));
					MAX = max(MAX, parse(o));
				}
			}
		}
		for (int i = 1; i <= MAX; i++) {
			for (int j = 0; j < d[i].size();j++) {
				int MIN = 1 << 29;
				for (int k = 0; k < d[i - 1].size(); k++) {
					MIN = min(MIN, d[i - 1][k].second + abs(d[i][j].first.first- d[i - 1][k].first.first) + abs(d[i][j].first.second - d[i - 1][k].first.second));
				}
				d[i][j].second = MIN;
			}
		}
		int MINCOST = 1 << 29;
		for (P s : d[MAX]) {
			MINCOST = min(MINCOST, s.second + abs(G.first-s.first.first) + abs(G.second-s.first.second));
		}
		cout << MINCOST << endl;
	}
}

Measured memory_bytes: 3600
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		String s = sc.next();

		int cnt = 0;
	
		for (int i = 1; i < n; i++) {
			if (s.charAt(i) == 'E') {
				cnt++;
			}
		}
		int num = cnt;

		for (int i = 1; i < n; i++) {
			int tmp = 0;
			if (s.charAt(i - 1) == 'W') {
				tmp++;
			}
			if (s.charAt(i) == 'E') {
				tmp--;
			}
			num = num + tmp;
			cnt = Math.min(cnt, num);
			// System.out.println(num+" "+cnt);
		}

		System.out.println(cnt);
		sc.close();
	}

}

Measured memory_bytes: 30884
#!/usr/bin/env ruby

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

A, B = get_ints

if A == B
  puts A
else
  stock = []
  first = A
  last = B
  if A % 2 != 0
    stock << A
    first = A + 1
  end
  if B % 2 == 0
    stock << B
    last = B - 1
  end
  ones = (last + 1 - first) / 2
  stock << 1 if ones % 2 != 0
  ans = 0
  stock.each do |x|
    ans = ans ^ x
  end
  puts ans
end


Measured memory_bytes: 14436
// finish date: 2019/06/29

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>> vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, pair<int, int>> plii;
const int bigmod = 998244353;
const int INF = 1050000000;
const long long INFll = 100000000000000000;


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

    vi p(n);
    rep(i, n) {
        cin >> p[i];
    }
    int cnt = 0;
    FOR(i, 1, n - 1) {
        if ((p[i - 1] < p[i] && p[i] <= p[i + 1]) || (p[i + 1] < p[i] && p[i] <= p[i - 1])) cnt++;
    }
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

pub fn read_n<T: FromStr>(n: usize) -> Vec<T> {
    read_n_logic::<T>(n, vec![])
}

pub fn read_n_logic<T: FromStr>(n: usize, mut a: Vec<T>) -> Vec<T> {
    match n {
        0 => a,
        _ => {
            a.push(read::<T>());
            read_n_logic(n - 1, a)
        }
    }
}
use std::cmp::{max, min};

fn main() {
    let a: String = read();
    let alf = "abcdefghijklmnopqrstuvwxyz";
    let alf_char: Vec<char> = alf.chars().collect();
    let next = alf_char
        .iter()
        .position(|&x| x == a.chars().nth(0).unwrap())
        .unwrap();
    println!("{}", alf_char[next + 1]);
}


Measured memory_bytes: 4352
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String W = in.readLine();

		long num = Long.parseLong(W);
		long ans =Long.MAX_VALUE;
		for(long i = 1;i*i<=num;i++){
			if(num%i==0){
				ans = Math.min(ans, (i+num/i)-2);
			}
        }

		System.out.println(ans);

	}


}


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

int main(){
    int N;
    std::string S;
    std::vector<char> v,x;

    std::cin >> N >> S;
    for(int i = 0; i < N; i++){
        v.push_back(S[i]);
    }

    for(int i = 0; i < N; i++){
        if(i == N - 1){
            x.push_back(v.at(i));
            break;
        }
        if(v.at(i) == v.at(i + 1)){
            continue;
        }else{
            x.push_back(v.at(i));
        }
    }
    
    /*for(int i = 0; i < x.size(); i++){
        std::cout << x.at(i);
    }
    std::cout << std::endl; */

    std::cout << x.size() << std::endl;
}
   

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

int main(){
  int N;
  scanf("%d", &N);
  std::vector<int > a(3*N);
  for (int i=0; i<3*N; i++){
    scanf("%d", &a[i]);
  }
  std::vector<long long > left(3*N), right(3*N);
  long long left_sum = 0;
  long long right_sum = 0;
  std::priority_queue<long long, std::vector<long long >, std::greater<long long > > queue_left;
  std::priority_queue<long long > queue_right;
  for (int i=0; i<N; i++){
    left_sum += a[i];
    queue_left.push(a[i]);
  }
  left[N] = left_sum;
  for (int i=3*N-1; i>=2*N; i--){
    right_sum += a[i];
    queue_right.push(a[i]);
  }
  right[N] = right_sum;

  for (int i=N; i<2*N; i++){
    queue_left.push(a[i]);
    left_sum += a[i];
    long long val = queue_left.top();
    queue_left.pop();
    left_sum -= val;
    left[i+1] = left_sum;
  }

  for (int i=N; i<2*N; i++){
    queue_right.push(a[3*N-i-1]);
    right_sum += a[3*N-i-1];
    long long val = queue_right.top();
    queue_right.pop();
    right_sum -= val;
    right[i+1] = right_sum;
  }

  long long ans = -1e18;
  for (int i=N; i<=2*N; i++){
    //printf("left[%d]-right[%d] = %lld-%lld = %lld\n",i,3*N-i,left[i],right[3*N-i],left[i]-right[3*N-i]);
    ans = std::max(left[i]-right[3*N-i], ans);
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 8436
#include<queue>
#include<stack>
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
#include<functional>
#include<deque>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  int i;
  string s;
  cin >> s;
  for(i=0;i<s.size()-1;i++){
    if(s[i]=='?' && s[i+1]=='D'){
      s[i]='D';
    }
    else if(s[i]=='?' && s[i+1]=='P'){
      s[i]='D';
    }
    else if(s[i]=='?' && s[i+1]=='?'){
      s[i]='D',s[i+1]='D';
      i++;
    }
  }
  if(s[s.size()-1]=='?'){
    s[s.size()-1]='D';
  }
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 3688
import sys

def main():
    n,d,x = map(int, sys.stdin.readline().split())

    pp = []
    for i in range(d):
        pp.append( list(map(int,sys.stdin.readline().split())) )

    dp = [0] * 100001
    curr_x = x
    for k in range(d - 1):
        next_x = curr_x
        for i in range(curr_x + 1):
            dp[i] = 0
        for i in range(n):
            for j in range(curr_x + 1):
                if j - pp[k][i] >= 0:
                    dp[j] = max(dp[j], dp[j - pp[k][i]] + pp[k + 1][i])
                next_x = max(next_x, (curr_x - j) + dp[j])
        curr_x = next_x

    print(curr_x)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9072
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    string S;
    cin >> S;
    ll ans = -1;
    for(int i=0;i<S.size();i++){
        char t = S[i];
        while(i<S.size()-1 && S[i+1] == t){
            i++;
        }
        ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
/*
 _____ _             _              _           _ 
|_   _| |__   ___   / \   _ __  ___| |__  _   _| |
  | | | '_ \ / _ \ / _ \ | '_ \/ __| '_ \| | | | |
  | | | | | |  __// ___ \| | | \__ \ | | | |_| | |
  |_| |_| |_|\___/_/   \_\_| |_|___/_| |_|\__,_|_|                                                

*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<ll,ll>
#define msi         map<string,ll>
#define mis         map<ll, string>
#define rep(i,a,b)    for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=b-1;i>=a;i--)
#define trav(a, x) 	for(auto& a : x)
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pair<ll, ll>>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define max(a,b)	(a>b?a:b)
#define min(a,b)	(a<b?a:b)

/*	For Debugging	*/
#define DEBUG 		cerr<<"\n>>>I'm Here<<<\n"<<endl;
#define display(x) trav(a,x) cout<<a<<" ";cout<<endl;
#define what_is(x)  cerr << #x << " is " << x << endl;

std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define TIME        cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
#define DECIMAL(n)  cout << fixed ; cout << setprecision(n);
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace __gnu_pbds;
using namespace std;
#define PI 3.141592653589793
#define N  100005
string s;
ll dp[10005][2][105];
void solve()
{
	ll d;
	cin>>s>>d;
	ll n=s.length();
	rep(i,0,10)
	dp[n-1][0][(i%d)]+=1;
	rep(i,0,s[n-1]-'0'+1)
	dp[n-1][1][i%d]+=1;
	repr(i,0,n)
	{
		rep(j,0,d)
		{
			rep(k,0,10)
			{
				dp[i][0][j]=(dp[i][0][j]+dp[i+1][0][(j-k+10*d)%d])%hell;
			}
			rep(k,0,s[i]-'0')
			{
				dp[i][1][j]=(dp[i][1][j]+dp[i+1][0][(j-k+10*d)%d])%hell;
			}
			dp[i][1][j]=(dp[i][1][j]+dp[i+1][1][(j-(s[i]-'0')+10*d)%d])%hell;
		}
	}
	// rep(i,0,n)
	// {
	// 	rep(j,0,d)
	// 	{
	// 		rep(k,0,2)
	// 		cout<<dp[i][k][j]<<" ";
	// 		cout<<" -- ";
	// 	}
	// 	cout<<endl;
	// }
	ll ans=0;
	cout<<(dp[0][1][0]-1+hell)%hell<<endl;
	return;
}
int main()
{
	FAST
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		solve();
	}
	TIME
	return 0;
}

Measured memory_bytes: 16640
#include <stdio.h>

int main(void){
    
    int n,s;
    s=0;
    scanf("%d",&n);
    
    for(int i=1; i<=n; i*=10){
        if(i==1)
            s+=n%(i*10);
        else
            s+=n%(i*10)/i;
    }
    if(n%s==0)
        printf("Yes");
    else
        printf("No");
}


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

using ll = long long;
// #define int long long

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, r, n) for(int i = (n); i >= (r); --i) // from n to r
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))


bool checkIfHappy(string s, int i) {
  if(i == 0 && s[i] == 'L') return false;
  else if (i == s.size()-1 && s[i] == 'R') return false;
  
  if(s[i] == 'R') {
    return s[i+1] == 'R';
  } else {
    return s[i-1] == 'L';
  }
}

/***** MAIN *****/
signed main() {
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  if(n == 1) {
    cout << 0 << endl;
    return 0;
  }
  int ans = 0;
  REP(i,n) if(checkIfHappy(s, i)) ++ans;
  ans += k*2;
  ans = min(ans, n-1);
  cout << ans;
  cout << "\n";
  return 0;
}
/***** MAIN *****/


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

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

  if (N%10 == 7) {
    cout << "Yes" << endl;
  }
  else if (N/100 == 7) {
    cout << "Yes" << endl;
  }
  else if ((N/10)%10 == 7) {
  cout << "Yes" << endl;
  }
  else cout << "No" << endl;
}



Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int gcd(int a,int b)
{
if(a==0)
return b;
if(b==0)
return a;
return gcd(b,a%b);
}
int gcd1(int a,int b,int c)
{
return gcd(gcd(a,b),c); 
}
int main()
{
int k;
cin>>k;
long long int sum(0);
for(int i=1; i<=k; ++i)
{
for(int j=1; j<=k; ++j)
{
for(int n=1; n<=k; ++n)
sum+=gcd1(i,j,n);
}
}
cout<<sum;
return 0;
}

Measured memory_bytes: 3636
class Node
  attr_accessor :parent, :rank, :weight, :diff_weight

  def initialize
    @parent = -1 # Positive value means its parent,and Negative value means its size.
    @rank = 0
    @diff_weight = 0
  end
end

class UnionFindTree
  
  def initialize(n)
    @nodes = (0...n).to_a.map { |i| Node.new }
  end

  def find(x)
    
    if @nodes[x].parent < 0
      x
    else
      y = find(@nodes[x].parent)
      @nodes[x].diff_weight += @nodes[@nodes[x].parent].diff_weight # 累積和をとる
      @nodes[x].parent = y
    end
  end

  def unite(a, b, w)
    
    # x と y それぞれについて、 root との重み差分を補正
    # p weight(b)
    w += weight(a)
    w -= weight(b)
    
    a = find(a)
    b = find(b)
    
    return w == diff(a, b) ? true : false if a == b

    if @nodes[a].rank < @nodes[b].rank
      @nodes[b].parent += @nodes[a].parent
      @nodes[a].parent = b
      @nodes[a].diff_weight = -w
    else
      @nodes[a].parent += @nodes[b].parent
      @nodes[b].parent = a
      @nodes[a].rank += 1 if @nodes[a].rank == @nodes[b].rank
      @nodes[b].diff_weight = w
    end
    
    
  end
  
  # def unite(a, b)
  # 
  #   a = find(a)
  #   b = find(b)
  #   return if a == b
  # 
  #   if @nodes[a].rank < @nodes[b].rank
  #     @nodes[b].parent += @nodes[a].parent
  #     @nodes[a].parent = b
  #   else
  #     @nodes[a].parent += @nodes[b].parent
  #     @nodes[b].parent = a
  #     @nodes[a].rank += 1 if @nodes[a].rank == @nodes[b].rank
  #   end
  # end

  def same?(a, b)
    find(a) == find(b)
  end
  
  def size(a)
    -@nodes[find(a)].parent
  end
  
  def weight(x)
    find(x); # 経路圧縮
    return @nodes[x].diff_weight;
  end
  
  def diff(x, y)
    return nil unless same?(x, y) # つながってなければ距離を測れないのでnilを返すことにした(2019/03/10)
    weight(y) - weight(x)
  end
  
  # 確認用。アルゴリズムとは関係無い
  def parents 
    @nodes.map(&:parent)
  end
end

# class Bridge
#   attr_accessor :first, :second

#   def initialize
#     @first = nil
#     @second = nil
#   end
  
#   def nodes=(a)
#     a[0], a[1] = a[1], a[0] if a[0] > a[1]
#     @first = a[0]
#     @second = a[1]
#   end
  
# end

n, m = gets.split.map(&:to_i)

uft = UnionFindTree.new(n)

m.times do |i|
  
  query = gets.split.map(&:to_i)
  if true
    a, b, w = query
    a -= 1
    b -= 1
    if !uft.unite(b,a,w)
      puts "No"
      exit
    end  
    # p uft
  elsif query[0] == 1
    a, b = query[1,2]
    puts uft.diff(a, b) || ??
  else
    p "Error!"
  end
end

puts "Yes"

# bridges = (0...M).to_a.map { Bridge.new }

# M.times do |i|
#   bridge = gets.split.map(&:to_i)
#   bridge.map! { |n| n - 1 }
#   bridges[i].nodes = bridge
# end
# p bridges

# ans = Array.new(M, 0)

# inco = N * ( N - 1 ) / 2 # inconvenience

# n = N
# q = M

# uft = UnionFindTree.new(n)

# q.times do |i|
  
#   j = (M-1)-i
#   ans[j] = inco
  
#   x, y = bridges[j].first, bridges[j].second
  
#   inco -= uft.size(x) * uft.size(y) if !uft.same?(x, y)
#   break if inco == 0
  
#   uft.unite(x, y)
# end

# puts ans


Measured memory_bytes: 12188
// Author : MohamedSameh
#include <bits/stdc++.h>
typedef long long ll ;
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SZ(a) (int)a.size()
void fo (){fflush(stdout);}
using namespace std;
bool pal (int x )
{
  int ar[10];
  int id =0 ;
  while (x)
  {
    ar[id++] = x%10;
    x/=10;
  }
  id--;
  for (int i= 0 ; i < id ;i++,id--)if (ar[i] != ar[id])return false ;
  return true ;
}
int main ()
{
  int a , b;
  cin >> a >> b ;
  int ans =0 ;
  while (a <= b )
  {
    ans += pal(a);
    a++;
  }
  cout << ans <<"\n";
  //cerr << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}


Measured memory_bytes: 256
/*************************************************************************

       Author:            palayutm
       Created Time :     Mon 10 Oct 2016 12:50:17 PM CST

       File Name:         d.cc
       Description:       new style, new life

 ************************************************************************/
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main(int argc, const char *argv[])
{
  int n;
  cin >> n;
  ll ans = 0;
  int now = 1;
  for (int i = 1; i <= n; i ++) {
    ll t;
    cin >> t;
    ans += (t-1)/now;
    if (i == 1 || t == now) {
      now ++;
    }
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 384
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;

public class Main {
	static Set<Long> getDivisors(long A){
		Set<Long> ret = new HashSet<Long>();
		ret.add(1L);
		long Amax = A;
		for(long i = 2 ; i * i <= Amax ; ++i){
			if(A % i == 0){			
				ret.add(i);
				while(A % i == 0){
					A = A / i;
				}
			}
		}
		ret.add(A);
		return ret;
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long A = sc.nextLong();
		long B = sc.nextLong();
		Set<Long> AS = getDivisors(A);		
		Set<Long> common = new HashSet<Long>();
		for(long a : AS){
			if(B % a == 0){
				common.add(a);
			}
		}
//		System.out.println(common);
		System.out.println(common.size());
		// 1 , 2 , 3, 5 , 11
	}
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);

#define endl '\n'
#define D(x) cout << #x << " = " << (x) << endl;

vector<vector<int>> mark;
vector<vector<long double>> dp;
vector<long double> p;

long double f(int i, int cnt) {
  if (i == -1) {
    return cnt > (p.size() / 2);
  }

  if (mark[i][cnt] == 0) {
    mark[i][cnt] = 1;
    dp[i][cnt] = p[i] * f(i - 1, cnt + 1) + (1 - p[i]) * f(i - 1, cnt);
  }

  return dp[i][cnt];
}

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

  p.resize(n);
  for (auto &x : p) cin >> x;

  mark.resize(n);
  for (auto &v : mark) {
    v.resize(n + 1);
    fill(v.begin(), v.end(), 0);
  }

  dp.resize(n);
  for (auto &v : dp) {
    v.resize(n + 1);
  }

  long double ans = f(n - 1, 0);
  cout << fixed << setprecision(10) << ans << endl;

  return 0;
}


Measured memory_bytes: 176512
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>

using namespace std;


template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};
using mint = Fp<1000000007>;


void solve() {
    int N; cin >> N;
    vector<int> zeros(60), ones(60);
    
    for (int i = 0; i < N; i++) {
        long long a; cin >> a;

        for (int d = 0; d < 60; d++) {
            if (a & 1LL<<d) ones[d]++;
            else zeros[d]++;
        }
    }

    mint ans = 0;

    for (int d = 0; d < 60; d++) {
        ans += modpow((mint)2, d) * ones[d] * zeros[d];
    }

    cout << ans << endl;
}


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

Measured memory_bytes: 3620
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <array>
#include <list>
#include <set>
#include <map>
#include <cmath>
#include <iterator>
using namespace std;

typedef long long ll;

int main() {
    ll n, y;
    cin >> n >> y;
    int maney[3] = {10000, 5000, 1000};
    vector<int> ans = {-1, -1, -1};
    bool flag = 0;

    if (1000 * n <= y && y <= 10000 * n) {
        for (int a = 0; a <= n; a++) {
            for (int b = 0; b <= n - a; b++) {
                for (int c = 0; c <= n - a - b; c++) {
                    if (a + b + c == n && 10000 * a + 5000 * b + 1000 * c == y) {
                        flag = 1;
                        cout << a << " " << b << " " << c << endl;
                        goto end;
                    }
                }
            }
        }
    }
    end:

    if (!flag)
        copy(ans.begin(), ans.end(), ostream_iterator<int> (cout, " "));
}

Measured memory_bytes: 256
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <ctime>
#include <map>
#include <stack>
#include <sstream>
#include <set>
#include <fstream>
#include <cmath>

using namespace std;

int main(void)
{
	long long int x, t;

	cin >> x >> t;

	if (x > t)
	{
		cout << x - t << endl;
	}
	else
	{
		cout << "0" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>

using namespace std;

main(){
  int h1,h2,m1,m2,s1,s2,h,m,s;

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

  cin >> h1 >> m1 >> s1;
  cin >> h2 >> m2 >> s2;

  if(s2-s1 < 0){
    s2+=60;
    m2-=1;
  }
  if(m2-m1 < 0){
    m2+=60;
    h2-=1;
  }

  cout << h2-h1 << " " << m2-m1 << " " << s2-s1 << endl;

  }
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <cstdio>
#include <stack>
#include <cstring>
#include <queue>
#include <algorithm>
#include <cmath>
//#include <unordered_map>
#define N 1000010
//#define lson x<<1
//#define rson x<<1|1
//#define mid ((lt[x].l+lt[x].r)/2)
//#define ID(x, y) ((x)*m+(y))
//#define CHECK(x, y) ((x)>=0 && (x)<n && (y)>=0 && (y)<m)
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL INF=0x3f3f3f3f;
void Open()
{
    #ifndef ONLINE_JUDGE
        freopen("F:/in.txt","r",stdin);
        //freopen("F:/my.txt","w",stdout);
    #endif // ONLINE_JUDGE
}
LL n, ans;
LL d[N];
int w[N];
vector<LL> G[N];
vector<LL> lis[N];
queue<LL> que;
int main()
{
//    Open();
    scanf("%lld", &n);
    for(LL i = 0; i < n; i++){
        LL l;
        scanf("%lld%lld", &w[i], &l);
        if(l != -1) G[i].push_back(l), d[l]++;
    }
    for(LL i = 0; i < n; i++)
    {
        if(d[i] == 0) que.push(i);
    }
    while(!que.empty())
    {
        LL u = que.front();que.pop();
        for(LL i = 0; i < G[u].size();i++)
        {
            LL v = G[u][i];
            lis[v].push_back(w[u]);
            w[v] += w[u];
            d[v]--;
            if(d[v] == 0) que.push(v);
        }
    }
    ans = 0;
    for(LL i = 0; i < n; i++)
    {
        sort(lis[i].begin(), lis[i].end());
        LL siz = lis[i].size();
        for(LL j = siz-2, cnt = 1; j >= 0; j--, cnt++)
        {
            ans += lis[i][j] * cnt;
        }
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 122544
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMaximum(Node x){
  while(x->right != NIL)x = x->right;
  return x;

}

Node treeMinimum(Node x){
  while(x->left != NIL)x = x->left;
  return x;
}

Node treeSearch(Node u, int k){
  while(u != NIL && k != u->key){
    if(k < u->key ) u = u->left;
    else u = u->right;
  }
  return u;
}

Node treeSuccessor(Node x){
  if(x->right != NIL) return treeMinimum(x->right);
  Node y = x->parent;
  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y; 
  Node x; 

  if(z->left == NIL || z->right == NIL) y = z;
  else y = treeSuccessor(z);

  if(y->left != NIL){
    x = y->left;
  }
  else{
    x = y->right;
  }

  if(x != NIL){
    x->parent = y->parent;
  }

  if(y->parent == NIL){
    root = x;
  }
  else{
    if(y == y->parent->left){
      y->parent->left = x;
    }
    else{
      y->parent->right = x;
    }
  }

  if(y != z){
    z->key = y->key;
  }

  free(y);
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key){
      x = x->left;
    }
    else{
      x = x->right;  
    }
  }

  z->parent = y;
  if(y == NIL){
    root = z;
  }
  else{
    if(z->key < y->key){
      y->left = z;
    }
    else{
      y->right = z;
    }
  }
}

void inorder(Node u){
  if(u == NIL) return ;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}

void preorder(Node u){
  if(u == NIL) return ;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 20452
n = int(input())
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(reverse=True)
    return divisors

l = make_divisors(n)
min_ = float('inf')
for i in range(len(l)):
    min_ = min(min_, l[i]-1+n//l[i]-1)
print(min_)


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

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

    int count = 0;
    for(int i=0; i<n; i++){
        int a;
        cin >> a;
        
        if(a % 2 == 1) count += 1;
    }

    if(count % 2 == 1) cout << "NO" << endl;
    else cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 3648
#include <stdio.h>
 
int digit_sum(int num) {
  int sum = 0;
  while(num > 0) {
    sum += num % 10;
    num /= 10;
  }
  return sum;
}
 
int main(void) {
  int i, N, A, B;
  int sum = 0;
  scanf("%d %d %d", &N, &A, &B);
  for(i = 1; i <= N; ++i) {
    int k = digit_sum(i);
    if (A <= k && k <= B) sum += i;
  }
  printf("%d\n", sum);
  return 0;
}


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

int main(){
    int n;
    scanf("%d",&n);
    vector<int> A(n);
    for(int i=0;i<n;i++){
        scanf("%d",&A.at(i));
    }
    sort(A.begin(),A.end());
    int temp = A.at(0);
    for(int i=0;i<n-1;i++){
        if(temp == A.at(i+1)){
            cout << "NO" << endl;
            return 0;
        }
        temp = A.at(i+1);
    }
    cout << "YES" << endl;
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  int d, g, p[10], c[10];
  cin >> d >> g;
  rep(i, d) cin >> p[i] >> c[i];
  ll ans = INF;

  for (int i = 0; i < (1 << d); ++i) {
    ll ta = 0, num = 0, rest_mx = -1;
    for (int j = 0; j < d; ++j) {
      if (i & (1 << j)) {
        ta += c[j] + 100 * (j + 1) * p[j];
        num += p[j];
      } else
        rest_mx = j;
    }

    if (ta < g) {
      int add = (rest_mx + 1) * 100;
      int need = (g - ta) / add;
      if ((g - ta) % add != 0) need++;
      if (need >= p[rest_mx]) continue;
      num += need;
    }
    ans = min(ans, num);
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
  int a,b,c,tmp;
  scanf("%d %d %d",&a,&b,&c);
  if(a > b){
    tmp = a;
    a = b;
    b = tmp;
  }
  if(b > c){
    tmp = b;
    b = c;
    c = tmp;
  }
  if(a > b){
    tmp = a;
    a = b;
    b = tmp;
  }
  printf("%d %d %d\n",a,b,c);

  return 0;
}

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

using namespace std;

int main(){
  int n, m;
  cin >> n >> m;
  map<int, vector<int>> v;
  for(int i = 0; i < n; i++){
    int a, b;
    cin >> a >> b;
    v[a].push_back(b);
  }
  
  int p = 0;
  priority_queue<int> q;
  for(int i = 1; i <= m; i++){
    for(int j = 0; j < v[i].size(); j++){
      q.push(v[i][j]);
    }
    if(!q.empty()){
      p += q.top();
      q.pop();
    }
  }
  
  cout << p << endl;
  
  return 0;
}

Measured memory_bytes: 10880