akhauriyash/Code-Regression huggingface dataset:
// #pragma GCC optimize("O3", "unroll-loops")
// #pragma GCC target("avx2")
 
#include <bits/stdc++.h>
using namespace std;
 
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;
// #define ost tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
 
#define    int                      long long int
#define    ld                       long double
#define    f(i,j,n)                 for(int i = j; i <= n; i++)
#define    r(i,n,j)                 for(int i = n; i >= j; i--)
#define    mod                      1000000007
#define    speed                    ios_base::sync_with_stdio(false);
#define    upp                      cin.tie(NULL),cout.tie(NULL);
#define    pb                       push_back
#define    mp                       make_pair
#define    T                        int ttt; cin >> ttt; while(ttt--)
#define    ff                       first
#define    ss                       second
#define    all(container)            container.begin() , container.end()
#define    sz(container)            (int)container.size()
#define    pii                      pair <int , int>
#define    sp(x)                    setprecision(x)
#define    bp(x)                    __builtin_popcount(x)
#define    endl                     "\n"
int power(int x, int y, int p)  
{  
    int res = 1;    
    x = x % p; 
    if (x == 0) return 0; 
    while (y > 0)  
    {     
        if (y & 1)  
            res = (res*x) % p;  
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res; 
}

int32_t main()
{
    speed upp
    int n,ans=0;
    cin>>n;
    int a[n+1];
    f(i,1,n)
        cin>>a[i];
    map<int,int>m;
    m[a[1]+1]=1;
    f(i,2,n)
    {
        if(m.find(i-a[i])!=m.end())
            ans+=m[i-a[i]];
        m[i+a[i]]++;
    }
    cout<<ans;
}


Measured memory_bytes: 17620
#include <cstdio>

int main() {
  //入力
  int W,H,x,y,r;
  std::scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
 
if(x-r>=0 && x+r<=W && y-r>=0 && y+r<=H){
    std::printf("Yes");
}

else if(!(x-r>=0 && x+r<=W && y-r>=0 && y+r<=H)){
    std::printf("No");
}
std::printf("\n");
  
  
  return 0;
}



Measured memory_bytes: 2748
#include"bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for (int i = b - 1; i >= a; i--)
#define RREP(i, n) RFOR(i, 0, n)
#define rep(i, a, b) for (auto i = a; i < b; i++)
#define rrep(i, a, b) for (auto i = a; i > b; i--)
#define range(i, a, b) (a <= i && i < b)
#define ll long long
#define fi first
#define fs sirst
#define se second
#define sc second
//#define int long long
using namespace std;
using vec = vector<int>;
using mat = vector<vec>;
typedef pair<int, int> P;
 
int n,m;
int riku[1111][1111], umi[1111][1111];
vec dp;
 
void solve() {
    REP(i, n) REP(j, n) riku[i][j] = umi[i][j] = 1 << 28;
    REP(i, n) riku[i][i] = umi[i][i] = 0;
 
    REP(_, m) {
        int x, y, c; char s;
        cin >> x >> y >> c >> s;
        x--; y--;
        if (s == 'L') riku[x][y] = min(riku[x][y], c), riku[y][x] = min(riku[y][x], c);
        else umi[x][y] = min(umi[x][y], c), umi[y][x] = min(umi[y][x], c);
    }
 
    int r;
    cin >> r;
    vec a(r,0);
    REP(i, r) cin >> a[i], a[i]--;
     
    REP(k, n) {
        REP(i, n) {
            REP(j, n) {
                riku[i][j] = min(riku[i][j],riku[i][k] + riku[k][j]);
                umi[i][j] = min(umi[i][j], umi[i][k] + umi[k][j]);
            }
        }
    }
 
    dp.assign(n, 1 << 28);
    dp[a[0]] = 0;
 
    REP(i, r-1) {
        vec tmp(n, 1 << 28);
        REP(j, n) {
            tmp[j] = min(tmp[j], dp[j] + riku[a[i]][a[i + 1]]);
 
            int base = riku[a[i]][j];
            REP(k, n) {
                tmp[k] = min(tmp[k], dp[j] + base + umi[j][k] + riku[k][a[i + 1]]);
            }
        }
        dp = tmp;
    }
    int ans = 1 << 30;
    REP(i, n) ans = min(ans, dp[i]);
 
    cout << ans << endl;
}
 
int main() {
    while (cin >> n >> m, n) solve();
}


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

typedef long long int ll;
typedef pair<int,int> pi;
priority_queue<pi, vector<pi>, greater<pi> > pq; //min heap

ll mini(ll a,ll b){	return a<b?a:b;}
ll maxi(ll a,ll b){	return a>b?a:b;}
ll gcd(ll a,ll b){	if(b == 0)	return a;return gcd(b,a%b);}
ll binpow(ll n,ll x){	ll ans = 1;while(x){if(x & 1)	ans *= n;n *= n;x >>= 1;}return ans;}

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

    int n;
    cin>>n;

    vector<int> tot(3,0);
    vector<int> vals(3,0);

    for(int i=0;i<n;++i){
        vector<int> cur(3,0);
        for(int j=0;j<3;++j)    cin>>vals[j];
        
        for(int i=0;i<3;++i){
            for(int j=0;j<3;++j){
                if(i!=j){
                    cur[j] = max(cur[j], tot[i] + vals[j]);
                }
            }
        }

        tot = cur;
    }

    cout<<max(tot[0], max(tot[1], tot[2]))<<"\n";

    return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<complex>
#include<cmath>
#include<utility>
#include<cstring>
#include<vector>
#include<queue>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define fs first
#define sc second
using namespace std;
typedef double D;
typedef complex<D> P;
typedef pair<P,P> L;
const D EPS = 1e-9;
const D PI = acos(-1);

D dot(P x,P y){return real(conj(x)*y);}
D cross(P x,P y){return imag(conj(x)*y);}
D arg(P a,P b,P c){return acos(dot(b-a,c-a)/(abs(b-a)*abs(c-a)));}

int c,w;
D x,y;
P p[110];
pair<int,int> l[330];
int g[330][2];
vector<int> wall[110];
int s,t;
int dis[1100];

int main(){
  while(cin >> c >> w, c){
    rep(i,c){
      cin >> x >> y; p[i] = P(x,y);
      wall[i].clear();
    }

    rep(i,w){
      cin >> s >> t; s--; t--;
      l[i] = make_pair(s,t);
      wall[s].push_back(t); wall[t].push_back(s);
    }

    rep(i,c){
      for(int j=1;j<(int)wall[i].size();j++){
	for(int k=j+1;k<(int)wall[i].size();k++){
	  D s1 = arg(p[i],p[wall[i][0]],p[wall[i][j]]);
	  if(cross(p[wall[i][0]]-p[i],p[wall[i][j]]-p[i])<EPS)s1 = 2*PI-s1;
	  D s2 = arg(p[i],p[wall[i][0]],p[wall[i][k]]); 
	  if(cross(p[wall[i][0]]-p[i],p[wall[i][k]]-p[i])<EPS)s2 = 2*PI-s2;
	  if(s1<s2)swap(wall[i][j],wall[i][k]);
	}
      }
    }
    /*
    rep(i,c){
      rep(j,wall[i].size())cout << wall[i][j] << " " ;cout << endl;
    }
    cout << endl;
    */

    memset(dis,-1,sizeof(dis));
    memset(g,-1,sizeof(g));
    int group = 0;

    rep(i,c){
      rep(j,wall[i].size()){
	int cur = -1, dir = -1;
	rep(k,w){
	  if(i == l[k].fs && wall[i][j] == l[k].sc){
	    cur = k; dir = 0; break;
	  }
	  if(i == l[k].sc && wall[i][j] == l[k].fs){
	    cur = k; dir = 1;  break;
	  }
	}
	if(g[cur][dir]>=0)continue;

	D area = 0;
	while(true){
	  //cout << cur+1 << " " << dir << endl;
	  g[cur][dir] = group;
	  
	  int node = dir?l[cur].fs:l[cur].sc;
	  int prv = dir?l[cur].sc:l[cur].fs;
	  //cout << "[" << prv+1 << ", " << node+1 << "]" << endl; 
	  rep(k,wall[node].size()){
	    if(wall[node][k] == prv){
	      int nxt = wall[node][(k+1)%wall[node].size()];
	      area += cross(p[prv]-p[node],p[nxt]-p[node]);
	      prv = node;
	      node = nxt;
	      break;
	    }
	  }

	  rep(k,w){
	    if(prv == l[k].fs && node == l[k].sc){
	      cur = k; dir = 0; break;
	    }
	    if(prv == l[k].sc && node == l[k].fs){
	      cur = k; dir = 1;  break;
	    }
	  }
	  if(g[cur][dir]>=0)break;
	}
	//cout << area << endl;
	//cout << endl;
	if(area>EPS)dis[group] = 0;
	group++;
      }
    }

    //cout << group << endl;

    bool adj[1100][1100];
    memset(adj,0,sizeof(adj));
    rep(i,w){
      adj[g[i][0]][g[i][1]] = adj[g[i][1]][g[i][0]] = 1;
    }

    /*
    rep(i,group){
      rep(j,group)cout << adj[i][j] << " ";cout << endl;
    }
    */

    queue<int> q;
    rep(i,group){
      if(dis[i] == 0)q.push(i);
    }

    int ans = 0;
    while(q.size()){
      int now = q.front(); q.pop();
      rep(i,group){
	if(adj[now][i] && dis[i]<0){
	  ans = dis[i] = dis[now] + 1;
	  q.push(i);
	}
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 2512
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
  ll h,n;
  cin>>h;
  cin>>n;
  ll a[n];
  ll sum=0;
  for(ll i=0;i<n;i++)
  {
    cin>>a[i];
    sum=sum+a[i];
  }
  if(sum>=h)
    cout<<"Yes"<<"\n";
  else
    cout<<"No"<<"\n";
  
return 0;
}

Measured memory_bytes: 1024
fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let n: usize = sc.read();
    let m: usize = sc.read();
    let mut wa = vec![0; n];
    let mut ac = vec![false; n];
    for _ in 0..m {
        let p = sc.read::<usize>() - 1;
        let s = sc.read::<String>();
        if &s == "AC" {
            ac[p] = true;
        } else {
            if !ac[p] {
                wa[p] += 1;
            }
        }
    }

    let mut wa_sum: usize = 0;
    for i in 0..n {
        if ac[i] {
            wa_sum += wa[i];
        }
    }
    let ac = ac.into_iter().filter(|&c| c).count();
    println!("{} {}", ac, wa_sum);
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352
import sys
def S(a,r,n):
    if r==1:return n*a
    a,r,n=map(float,[a,r,n])
    return a*(1.0-r**(n))/(1.0-r)
for line in sys.stdin.readlines():
    n=float(line.strip())
    print S(n,2.0/3.0,5)+S(n*2,2.0/3.0,5)

Measured memory_bytes: 4284
import sys
sys.setrecursionlimit(10**9)
INF=10**18
def input():
    return sys.stdin.readline().rstrip()

def main():
    N,Ma,Mb=map(int,input().split())
    a,b,c=[0]*N,[0]*N,[0]*N
    for i in range(N):
        a[i],b[i],c[i]=map(int,input().split())
    d={}
    ans=INF
    for i in range(2**(N//2)):
        ma,mb,cost=0,0,0
        for j in range(N//2):
            if (i>>j)&1:
                ma+=a[j]
                mb+=b[j]
                cost+=c[j]
        if ma!=0 and mb!=0 and ma*Mb==mb*Ma:
            ans=min(ans,cost)
        n=min(ma//Ma,mb//Mb)
        ma-=n*Ma
        mb-=n*Mb
        if (ma,mb) in d:
            d[(ma,mb)]=min(d[(ma,mb)],cost)
        else:
            d[(ma,mb)]=cost
    for i in range(1,2**(N-N//2)):
        ma,mb,cost=0,0,0
        for j in range(N-N//2):
            if (i>>j)&1:
                ma+=a[j+N//2]
                mb+=b[j+N//2]
                cost+=c[j+N//2]
        n=max(-(-ma//Ma),-(-mb//Mb))
        if (n*Ma-ma,n*Mb-mb) in d:
            ans=min(ans,cost+d[(n*Ma-ma,n*Mb-mb)])
    print(ans if ans!=INF else -1)

if __name__ == '__main__':
    main()


Measured memory_bytes: 46244
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; 
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T rtype(T)(){ return read.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;
T[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtype!real;

// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
	int a = rint, b = rint;
	
	int x = 1;
	int ans = 0;
	while(x < b) ans += 1, x += a - 1;
	
	ans.writeln;
}


Measured memory_bytes: 256
#frog1からジャンプの回数が変数kになった
n,k=map(int,input().split())
h=list(map(int,input().split()))
INF=float('INF')
dp=[INF]*n
dp[0]=0
for i in range(1,n):
    for j in range(1,k+1):
        if i-j<0:#out of indexを防ぐ
            continue
        dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]))#dp[i]と大小を比較する
print(dp[n-1])

Measured memory_bytes: 85840
from bisect import bisect_right

N = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))

ca = [0] * N
cb = [0] * N

for i in range(N):
  ca[i] = bisect_right(B, A[i])
  cb[i] = N - bisect_right(C, B[i])

cb.append(0)
for i in range(N, 0, -1):
  cb[i-1] += cb[i]

print(sum([cb[i] for i in ca]))

Measured memory_bytes: 27428
line = input().rstrip().split(' ')
h = int(line[0])
w = int(line[1])

# 2d array which represents glid input
glid = []

for i in range(h):
    glid.append(list(input()))

for y in range(h):
    for x in range(w):
        # if the square is bomb
        if glid[y][x] == '#':
            continue
        
        num = 0
        for dx,dy in ((-1,-1), (0,-1), (1,-1), (-1,0), (1,0), (-1,1), (0,1), (1,1)):
            ny = y + dy
            nx = x + dx
            if ny < 0 or nx < 0 or ny >= h or nx >= w:
                continue
            if glid[ny][nx] == '#':
                num += 1
        glid[y][x] = num

# output
for y in range(h):
    line = ''
    for x in range(w):
        line += str(glid[y][x])
    print(line)


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

vector<int> get_path(int a, int b, const vector<vector<int>>& adj) {
    int n = adj.size();
    vector<int> par(n, -1);
    auto dfs = [&](auto dfs, int v, int p) -> void {
        par[v] = p;
        for (int s : adj[v]) {
            if (s != p) {
                dfs(dfs, s, v);
            }
        }
    };
    dfs(dfs, a, -1);
    vector<int> ret;
    int v = b;
    while (v != -1) {
        ret.push_back(v);
        v = par[v];
    }
    return ret;
}

long long dp[50][1 << 20];

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

    int n;
    cin >> n;
    vector<vector<int>> adj(n);
    map<pair<int, int>, int> edge_id;
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
        edge_id[minmax(a, b)] = i;
    }

    int m;
    cin >> m;
    vector<vector<int>> constraints(m, vector<int>(n - 1));

    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        vector<int> path = get_path(u, v, adj);
        for (int j = 0; j < path.size() - 1; j++) {
            constraints[i][edge_id[minmax(path[j], path[j + 1])]] = 1;
        }
    }

    dp[0][0] = 1;

    for (int i = 0; i < n - 1; i++) {
        int cover = 0;
        for (int j = 0; j < m; j++) {
            if (constraints[j][i]) cover |= 1 << j;
        }
        for (int j = 0; j < 1 << m; j++) {
            dp[i + 1][j | cover] += dp[i][j];
            dp[i + 1][j] += dp[i][j];
        }
    }

    cout << dp[n - 1][(1 << m) - 1] << endl;
}


Measured memory_bytes: 401664
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		//数取得
		int H1 = sc.nextInt();
		int M1 = sc.nextInt();
		int H2 = sc.nextInt();
		int M2 = sc.nextInt();
		int K = sc.nextInt();
		sc.close();

		int OneTime = H1 * 60 + M1;
		int TwoTime = H2 * 60 + M2;

		System.out.println(TwoTime-OneTime-K);
	}

}


Measured memory_bytes: 35760
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  ll x,y,z;
  cin >> x >> y >> z;
  ll n=x+y+z;
  vec a(n),b(n),c(n);
  vector<pll> p(n);
  for(ll i=0;i<n;i++) {
    cin >> a[i] >> b[i] >> c[i];
    p[i]={a[i]-b[i],i};
  }
  sort(p.rbegin(),p.rend());
  vec ansl(n);
  priority_queue<ll> q;
  for(ll i=0;i<x+z;i++) {
    ll id=p[i].second;
    q.push(c[id]-a[id]);
    ansl[i]=a[id];
    if(i) ansl[i]+=ansl[i-1];
    if(i>=x) {
      ansl[i]+=q.top();
      q.pop();
    }
  }
  vec ansr(n);
  while(q.size()) q.pop();
  for(ll i=n-1;n-1-i<y+z;i--) {
    ll id=p[i].second;
    q.push(c[id]-b[id]);
    ansr[i]=b[id];
    if(i!=n-1) ansr[i]+=ansr[i+1];
    if(n-1-i>=y) {
      ansr[i]+=q.top();
      q.pop();
    }
  }
  ll ans=0;
  for(ll i=x-1;i<x+z;i++) {
    ans=max(ans,ansl[i]+ansr[i+1]);
  }
  cout << ans << endl;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

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

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

int main(){
	ll s;
	cin >> s;
	map<ll, ll> mp;
	ll now = s;
	for(ll i=1;i<2000000;i++){
		//dump(now)
		if(mp.find(now)!=mp.end()){
			cout << i << endl;
			return 0;
		}
		mp[now] = i;
		now = (now%2==0?now/2:3*now+1);
	}
    return 0;
}

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

using ll = long long;

const ll MOD = 1e9 + 7;

ll powmod(ll a, ll b) {
	ll r = 1;
	while (b) {
		if (b & 1) {
			r = r * a % MOD;
		}
		a = a * a % MOD;
		b /= 2;
	}
	return r;
}

const int MAXQ = 16;
int N, Q;
int adj[MAXQ];

vector<pair<int, ll>> extra[MAXQ];
ll coeff[1 << MAXQ];
ll dp[2][1 << MAXQ];

const ll i9 = powmod(9, MOD - 2);

int main() {
	vector<pair<int, int>> pts = {{0, 0}};
	scanf("%d %d", &N, &Q); Q++;
	for (int i = 1; i < Q; i++) {
		int l, r; scanf("%d %d", &l, &r); l--;
		pts.emplace_back(l, i);
		pts.emplace_back(r, i);
	}

	sort(pts.begin(), pts.end());
	ll ans = powmod(10, N - pts.back().first);

	for (size_t i = 0; i + 1 < pts.size(); i++) {
		int x = pts[i].second;
		int y = pts[i + 1].second;
		if (pts[i].first == pts[i + 1].first) {
			adj[x] |= 1 << y;
			adj[y] |= 1 << x;
		} else {
			ll base = i9 * (powmod(10, pts[i + 1].first - pts[i].first) - 1) % MOD;
			ans *= base;
			ans %= MOD;
			base = (base + 1) * powmod(base, MOD - 2) % MOD;
			extra[x].emplace_back(y, base);
		}
	}

	for (int m = 0; m < (1 << Q); m++) {
		coeff[m] = 1;
		for (int i = 0; i < Q; i++) {
			if (!(m & (1 << i))) continue;
			if ((adj[i] & m) != adj[i]) {
				coeff[m] = 0;
				break;
			}
			for (auto p : extra[i]) {
				if (m & (1 << p.first)) {
					coeff[m] *= p.second;
					coeff[m] %= MOD;
				}
			}
		}
	}

	int cur = 0, nxt = 1;
	dp[0][0] = 1;
	for (int x = 0; x < 9; x++, swap(cur, nxt)) {
		memset(dp[nxt], 0, sizeof(ll) * (1 << Q));
		
		for (int m = 0; m < (1 << Q); m++) {
			int cm = (1 << Q) - 1 - m;
			for (int s = cm; ; s = (s - 1) & cm) {
				if ((s & 1) || x) {
					dp[nxt][s | m] += dp[cur][m] * coeff[s];
					dp[nxt][s | m] %= MOD;
				}
				if (s == 0) break;
			}
		}
	}
	ans *= dp[cur][(1 << Q) - 1];
	ans %= MOD;

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

	return 0;
}

Measured memory_bytes: 1920
//////////////////////////////
// Author: whatisit
// Date: 2020-05-14 00:51 
//////////////////////////////
#include <bits/stdc++.h>
using namespace std;

const int N = 2e5+1;
int n, A[N], a;

void solve() {
	cin >> n;
	for (int i = 0; i < n-1; ++i) {
		cin >> a;
		++A[a];
	}
	for (int i = 1; i <= n; ++i) {
		cout << A[i] << endl;
	}
}

int main() {
	//cin.tie(0); ios_base::sync_with_stdio(0);
	solve();
	return 0;
}

Measured memory_bytes: 4404
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (int i = 0; i < sz(v); i++) {
        os << v[i];
        if (i < sz(v) - 1) os << " ";
    }
    return os;
}
int main() {
    int n;
    string s;
    cin >> n >> s;
    ll ans = 0;
    rep(j, n) {
        for (int i = j - 1; i >= 0; i--) {
            int k = j + (j - i);
            if (k >= n) break;
            if (s[i] != s[j] && s[j] != s[k] && s[k] != s[i]) ans--;
        }
    }
    // cout << ans << endl;
    vector<int> r, g, b;
    rep(i, n) {
        if (s[i] == 'R') r.push_back(i);
        if (s[i] == 'G') g.push_back(i);
        if (s[i] == 'B') b.push_back(i);
    }
    r.push_back(INF);
    g.push_back(INF);
    b.push_back(INF);
    // cout << r << endl;
    for (int j : r) {
        if (j == INF) continue;
        ll gl = (ll)(lower_bound(all(g), j) - g.begin());
        ll gr = (ll)(sz(g) - gl - 1);
        ll bl = (ll)(lower_bound(all(b), j) - b.begin());
        ll br = (ll)(sz(b) - bl - 1);
        ans += gl * br + gr * bl;
    }
    // cout << ans << endl;
    for (int j : g) {
        if (j == INF) continue;
        ll rl = (ll)(lower_bound(all(r), j) - r.begin());
        ll rr = (ll)(sz(r) - rl - 1);
        ll bl = (ll)(lower_bound(all(b), j) - b.begin());
        ll br = (ll)(sz(b) - bl - 1);
        ans += rl * br + rr * bl;
        // cout << rl << " " << rr << " " << bl << " " << br << endl;
    }
    // cout << ans << endl;
    for (int j : b) {
        if (j == INF) continue;
        ll gl = (ll)(lower_bound(all(g), j) - g.begin());
        ll gr = (ll)(sz(g) - gl - 1);
        ll rl = (ll)(lower_bound(all(r), j) - r.begin());
        ll rr = (ll)(sz(r) - rl - 1);
        ans += gl * rr + gr * rl;
        // cout << rl << " " << rr << " " << gl << " " << gr << endl;
    }
    cout << ans << endl;
}


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

int main() {
  ll L, R;
  cin >> L >> R;

  ll x = 2018;
  
  for (ll i = L; i < R; i++) {
    for (ll j = L + 1; j <= R; j++) {
      x = min((i % 2019) * (j % 2019) % 2019, x);
      if (x == 0) break;
    }
    if (x == 0) break;
  }
  if (x == 0) cout << 0 << endl;
  else cout << x << endl;
}


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

int main(){
	int n,m;
	cin >> n >> m;
	vector<int> a(n+1,1);
	int idx;
	rep(i,m){
		cin >> idx;
		a[idx] = -1;
	}
	vector<ll> dp(n+1);
	dp[0] = 1;
	for(int i(1);i<=n;++i){
		if(a[i] == -1){
			dp[i] = 0;
		}else{
			if(i == 1) dp[i] = dp[i-1];
			else dp[i] = (dp[i-1] + dp[i-2])%MOD;
		}
	}
	cout << dp[n] << endl;
	return 0;
}

Measured memory_bytes: 1536
module.exports=function(r){var e={};function t(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return r[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}return t.m=r,t.c=e,t.d=function(r,e,n){t.o(r,e)||Object.defineProperty(r,e,{enumerable:!0,get:n})},t.r=function(r){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(r,"__esModule",{value:!0})},t.t=function(r,e){if(1&e&&(r=t(r)),8&e)return r;if(4&e&&"object"==typeof r&&r&&r.__esModule)return r;var n=Object.create(null);if(t.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:r}),2&e&&"string"!=typeof r)for(var o in r)t.d(n,o,function(e){return r[e]}.bind(null,o));return n},t.n=function(r){var e=r&&r.__esModule?function(){return r.default}:function(){return r};return t.d(e,"a",e),e},t.o=function(r,e){return Object.prototype.hasOwnProperty.call(r,e)},t.p="",t(t.s=0)}([function(r,e,t){t(1)(t(2).readFileSync("/dev/stdin","UTF-8").split("\n"))},function(r,e){function t(r,e){return function(r){if(Array.isArray(r))return r}(r)||function(r,e){var t=[],n=!0,o=!1,u=void 0;try{for(var i,l=r[Symbol.iterator]();!(n=(i=l.next()).done)&&(t.push(i.value),!e||t.length!==e);n=!0);}catch(r){o=!0,u=r}finally{try{n||null==l.return||l.return()}finally{if(o)throw u}}return t}(r,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}r.exports=function(r){for(var e=t(r[0].split(" ").map(function(r){return Number(r)}),3),n=e[0],o=e[1],u=e[2],i=[],l=0;l<u;l++)i.push(Number(r[l+1])-1);for(var f=new Array(n).fill(o-u),a=0;a<u;a++)f[i[a]]+=1;for(var c=0;c<n;c++)f[c]>0?console.log("Yes"):console.log("No")}},function(r,e){r.exports=require("fs")}]);

Measured memory_bytes: 30336
parseInt(x) = parse(BigInt, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	p = 10^9+7
	l = readline() |> chomp
	n = length(l)
	dp = zeros(Int,n,2)
	dp[1,1] = l[1]=='1'?2:1
	dp[1,2] = l[1]=='1'?1:0
	for i in 2:n
		dp[i,1] = l[i]=='1'?dp[i-1,1]*2%p:dp[i-1,1]
		dp[i,2] = l[i]=='1'?(dp[i-1,2]*3%p+dp[i-1,1])%p:dp[i-1,2]*3%p
	end
	println((dp[n,1]+dp[n,2])%p)
end

main()

Measured memory_bytes: 197088
#include <bits/stdc++.h> 
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
#define MAX 100005
#define NIL -1
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;
using Field=vector<vector<int>>;

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

const double PI=(acos(-1));

int main(){
    ll n,k;
    cin>>n>>k;
    vector<ll> h(n);
    rep(i,n)cin>>h[i];
    sort(h.begin(),h.end());
    ll ans=h[k-1]-h[0];
    for(ll i=k;i<n;++i){
        ans=min(ans,h[i]-h[i-k+1]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3984
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int,int>
#define PIII pair<int,PII>
#define PLL pair<LL,LL>
#define PLII pair<LL,PII>
#define VI vector<int>
#define FF first
#define SS second
#define MP make_pair
#define PB push_back
#define MX 2010
#define EPS 0.00000000001
#define MOD 1000000007
#define PI acos(-1)
#define INF 100000000
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
using namespace std;

LL powmod(LL a,LL x)
{
    LL res = 1;
    while(x)
    {
        if(x & 1) res = (res * a)%MOD;
        x = x/2;
        a = (a * a)%MOD;
    }

    return res;
}

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

    int k,n;
    cin>>k>>n;

    LL ans = 0, tot = 0, g[n+1] = {0}, mn;
    int n1;
    rev_loop(i,n,2)
    {
        mn = g[i];
        g[i] = powmod(n/i,k);
        g[i] = (g[i] + MOD - mn) % MOD;
        tot = (tot + g[i]) % MOD;
        ans = (ans + (g[i] * i) % MOD) %MOD;

        n1 = sqrt(i);
        loop(j,2,n1+1)
        {
            if(i % j == 0)
            {
                g[j] = (g[j] + g[i]) % MOD;
                if(j*j != i) g[i/j] = (g[i/j] + g[i]) % MOD;
            }
        }
        //cout<<i<<' '<<g[i]<<' '<<ans<<'\n';
    }

    g[1] = powmod(n,k);
    g[1] = (g[1] + MOD - tot) % MOD;
    ans = (ans + g[1]) % MOD;
    //cout<<1<<' '<<g[1]<<'\n';
    cout<<ans<<'\n';

    return 0;
}


Measured memory_bytes: 4288
#define MOD_TYPE 1

#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
/*
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
using multiInt = boost::multiprecision::cpp_int;
using lld = boost::multiprecision::cpp_dec_float_100;
*/
/*
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
*/
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

constexpr ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
constexpr int INF = (int)1e9;
constexpr ll LINF = (ll)4e18;
constexpr ld PI = acos(-1.0);
constexpr ld EPS = 1e-11;
constexpr int Dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
constexpr int Dy[] = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define REPI(i, m, n) for (int i = m; i < (int)(n); ++i)
#define repi(i, n) REPI(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

inline void init_main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);
}
template <typename T>
inline bool chmin(T &a, T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
inline bool chmax(T &a, T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
inline ll CEIL(ll a, ll b)
{
  return (a + b - 1) / b;
}
template <typename A, size_t N, typename T>
inline void Fill(A (&array)[N], const T &val)
{
  fill((T *)array, (T *)(array + N), val);
}
#pragma endregion

int main()
{
  init_main();

  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  map<ll, ll> cnt;
  ll ans = 0;
  rep(i, n)
  {
    ans += cnt[i - a[i]];
    cnt[i + a[i]]++;
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 27452
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <list>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(d) string(1,d)
#define prll(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  ll c = 0;
  rep(i, 0, n) {
    ll d;
    cin >> d;
    if (d < a || d >= b) {
      c++;
    }
  }
  cout << c << endl;
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath> //abs();
using namespace std;

int main(void)
{
    long long int b,c,d,i,j,k,n,x[100];
    long double wa=0,seki=1,a;
    char C1,C2;
    string s;

    cin >> n;
    if(n==1){
        cin >>a;
        cout << a;
        return 0;
    }

    for(i=0;i<n;i++){
        cin >> x[i];
        seki *= x[i];
    }

    for(i=0;i<n;i++){
        wa += seki/x[i];
    }

    cout << seki/wa;

    return 0;
}

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

typedef long long ll;
typedef vector<int> vint;

int solve(int x)
{
    int ans = 0;
    while (x > 0)
    {
        int p = 0, tmp = x;
        while (tmp > 0)
        {
            p += (tmp % 2);
            tmp /= 2;
        }
        x %= p;
        ans++;
    }
    return ans;
}

int main()
{
    int N;
    cin >> N;
    string X;
    cin >> X;
    int pcnt = 0;
    for (size_t i = 0; i < N; i++)
    {
        if (X[i] == '1')
            pcnt++;
    }
    bool isZero = pcnt==1;
     ll xrem1 = 0, xrem2 = 0;
    vint rem1(N), rem2(N); // rem1[i] := 2^i % (pcnt-1) , rem2[i] := 2^i % (pcnt+1)
    if (pcnt != 1)
    {
        rem1[0] = 1 % (pcnt - 1);
        for (size_t i = 0; i < N; i++)
        {
            rem1[i + 1] = (rem1[i] * 2) % (pcnt - 1);
        }
        for (int i = N - 1; i >= 0; i--)
    {
        if (X[i] == '1')
        {
            xrem1 =(xrem1 + rem1[(N-1)-i])%(pcnt-1);
        }
    }
    }
    rem2[0] = 1 % (pcnt + 1);
    for (size_t i = 0; i < N; i++)
    {
        rem2[i + 1] = (rem2[i] * 2) % (pcnt + 1);
    }
    
   
    for (int i = N - 1; i >= 0; i--)
    {
        if (X[i] == '1')
        {
            xrem2 = (xrem2 + rem2[(N-1)-i]) % (pcnt+1);
        }
    }

    for (int i = 0; i < N; i++)
    {
        if (X[i] == '1' and !isZero)
        {
            int newP = pcnt - 1;
            ll nrem = ((xrem1 - rem1[N-1-i])%newP + newP)%newP;
            cout<<solve(nrem)+1<<"\n";
        }
        else if(X[i]=='1' and isZero)
        {
            cout<<0<<endl;
        }
        else
        {
            int newP = pcnt + 1;
            ll nrem = (xrem2 + rem2[N-1-i])%newP;
            cout<<solve(nrem)+1<<"\n";
        }
        
    }

    return 0;
}


Measured memory_bytes: 5144
#include<bits/stdc++.h>
using namespace std;
using lint = long long;
lint dp[100010][2][110];
const lint MOD = 1e9+7;

signed main(){
  lint D; string s; cin >> s >> D;
  dp[0][0][0] = 1;
  lint len = s.size();
  for(lint i = 0; i < len; i++){
    for(lint j = 0; j < 2; j++){
      for(lint amari = 0; amari < D; amari++){
        if(j == 1){
          for(lint k = 0; k <= 9; k++){
            dp[i + 1][j][(amari + k) % D] += dp[i][j][amari];
            dp[i + 1][j][(amari + k) % D] %= MOD;
          }
        }
        if(j == 0){
          lint lim = s[i] - '0';
          for(lint k = 0; k <= lim; k++){
            dp[i + 1][k != lim][(amari + k) % D] += dp[i][j][amari];
            dp[i + 1][k != lim][(amari + k) % D] %= MOD;
          }
        }
      }
    }
  }
  lint ans = (dp[len][0][0] + dp[len][1][0] - 1) % MOD;
  if(ans < 0) ans += MOD;
  cout << ans << endl;
}


Measured memory_bytes: 18688
N, M = map(int, input().split())
array = []
for i in range(N):
  elm = list(map(int, input().split()))
  array.append(elm)

array.sort(key=lambda x: x[0])
ans = 0
cnt = 0
for i in range(N):
  #何本買うか
  buy = min([array[i][1], M-cnt])
  cnt += buy
  ans += array[i][0]*buy

print(ans)

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

int main(){
  
  vector<int> A(3);
  
  cin >> A[0] >> A[1] >> A[2];
  sort(A.begin(),A.end());
  
  int ans = 0;
    
  ans += A[2] - A[1];
  ans += A[1] - A[0];
  
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc127_a
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int A = int.Parse(input[0]);
            int B = int.Parse(input[1]);
            
            if(A <= 5)
            {
                B = 0;
            }else if(A >= 6 && A <= 12)
            {
                B = B / 2;
            }
            Console.WriteLine(B);
            Console.Read();
        }
    }
}


Measured memory_bytes: 13140
//第8回シンデレラガール総選挙は是非本田未央ちゃんに投票をお願いします！
//ファンのことも他のアイドルの子たちのことも本当に大事にしてて、今まで周りに色んなものを与えてくれました。
//今度は私たちが未央ちゃんにお返しをする番です。みんなでガラスの靴を履かせてあげましょう！
// #本田未央を一番星に #本田未央を令和のシンデレラガールに #第8回シンデレラガール総選挙
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
typedef pair<lint,lint> pl;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
lint gcd( lint m, lint n )
{
	lint a=max(m,n),b=min(m,n);
	if(m==0) return n;if(n==0) return m;
	if(a%b==0) return b;
	return gcd(b,a-b*(a/b));
}
int n;
int a[100100];
bool cal(int x){
	int ng=0;
	rep(i,n){
		if(a[i]%x>0) ng++;
	}
	return ng<=1;
}
int main()
{
	int out=0;
	cin>>n;rep(i,n) cin>>a[i];
	REP(i,1,n) out=gcd(out,a[i]);
	REP(i,1,100010){
		if(a[0]%i>0) continue;
		if(cal(i)) out=max(out,i);
		if(cal(a[0]/i)) out=max(out,a[0]/i);
	}
	cout<<out<<endl;
}


Measured memory_bytes: 640
import java.util.*;
import java.io.*;
 
public class Main {
    static boolean[][] used;
    static int[] ans;
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        double w = sc.nextInt();
        double h = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();
        int bool = w/2 == x && h/2 == y ? 1 : 0;
        System.out.println((w*h/2)+" "+bool);
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}


Measured memory_bytes: 21076
N = int(input())
S = input()
turn = S.count('E')
min_turn = 300000
for i in range(N):
    if S[i] == 'E':
        turn -= 1
    if (S[i-1] == 'W') and (1 <= i):
        turn += 1
    if min_turn > turn:
        min_turn = turn
print(min_turn)

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

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

  if ((n - 1) % (k - 1) == 0) {
    cout << (n - 1) / (k - 1) << endl;
  } else {
    cout << (n - 1) / (k - 1) + 1 << endl;
  }
}


Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main{
    public static void main(String[] args) throws IOException{
        FastReader in = new FastReader();
        FastWriter out = new FastWriter();
        int a;
        a = in.nextInt();
        boolean good = false;
        for (int i = 1; i <= 9; i++){
            for (int j = 1; j <= 9; j++){
                if (i*j==a) good = true;
            }
        }
        out.pl(good ? "Yes" : "No");

        out.close();
    }

}
class FastReader{ 
    BufferedReader br; 
    StringTokenizer st; 
    public FastReader() { 
        br = new BufferedReader(new InputStreamReader(System.in)); 
    } 
    String next(){ 
        while (st == null || !st.hasMoreElements()) { 
            try{ 
                st = new StringTokenizer(br.readLine()); 
            }catch (IOException  e){ 
                e.printStackTrace(); 
            } 
        } 
        return st.nextToken(); 
    } 
    int nextInt(){ 
        return Integer.parseInt(next()); 
    } 
    long nextLong(){ 
        return Long.parseLong(next()); 
    } 
    double nextDouble(){ 
      return Double.parseDouble(next()); 
    } 
    String nextLine(){ 
        String str = ""; 
        try{ 
            str = br.readLine(); 
        } 
        catch (IOException e){ 
            e.printStackTrace(); 
        } 
        return str; 
    } 
}
class FastWriter{
    PrintWriter out;
    FastWriter(){
        out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
	out.flush();
    }
    void pl(Object o){
        out.write(o.toString());
	    out.write("\n");
        out.flush();
    }
    void pl(){
        out.write("\n");
    }
    void p(Object o){
        out.write(o.toString());
    }
    void close(){
        out.flush();
        out.close();
    }  
}


Measured memory_bytes: 32968
#include<stdio.h>

int main(void){

  int a;
  int b;

  scanf("%d",&a);
  scanf("%d",&b);

  if(a < b){
    printf("a < b\n");
  }
  else if(a > b){
    printf("a > b\n");
  }
  else if(a == b){
    printf("a == b\n");
  }

  return 0;
}



Measured memory_bytes: 2036
#include<stdio.h>
#include<stdlib.h>

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define INFTY 999999


int main(void){
    unsigned long a,b,c;
    scanf("%lu %lu %lu", &a, &b, &c);

    unsigned long ans;

    //もし毒入りクッキーより解毒剤クッキーの方が多ければ、
    //毒入り美味しいクッキーを全て食べられる+解毒剤美味しいクッキーも食べられる
    if(c<=a+b){
        ans=b+c;
    }
    //毒入りクッキーより解毒剤クッキーの方が少なければ
    else{
        unsigned long poison=a+b;
        ans=poison+b+1;
    }

    printf("%lu\n",ans);
    
    return 0;
    
}


Measured memory_bytes: 128
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)
fun <T> Array<Array<T>>.print() {
    this.forEach {
        println(it.joinToString(" "))
    }
}

@ExperimentalStdlibApi
fun main() {
    val s = readString()
    val q = readInt()
    val dq = ArrayDeque(s.toList())

    var reverseCount = 0
    for (i in 0 until q) {
        val query = readLine()!!.split(" ")
        if (query[0] == "1") {
            reverseCount++
        } else {
            val f = query[1].toInt()
            val c = query[2].toCharArray().first()

            if (f == 1) {
                if (reverseCount % 2 == 0) {
                    dq.addFirst(c)
                } else {
                    dq.addLast(c)
                }
            } else {
                if (reverseCount % 2 == 0) {
                    dq.addLast(c)
                } else {
                    dq.addFirst(c)
                }
            }
        }
    }
    
    if (reverseCount % 2 == 1) dq.reverse()
    println(dq.joinToString(separator = ""))
}


Measured memory_bytes: 64380
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)
const ll LINF = 1001002003004005006ll;

int main() {
    int n;
    cin >> n;
    cout << n * n * n << endl;
    return 0;
}


Measured memory_bytes: 3572
#include<stdio.h>
#include<string.h>

#define M 1046527/* your task*/
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key%M/* your task */; }
int h2(int key){ return 1+(key%(M-1))/* your task */; }

int h(int key,int i){ return (h1(key)+i*h2(key))%M;}

int find(char str[]){
    /* your task */
    long long key,i=0,j;
    key=getKey(str);
    while(1){
        j=h(key,i);
        if(strcmp(H[j],str)==0){
            return 1;
        }else if(strlen(H[j])==0){
            return 0;
        }
        i++;
    }
}

int insert(char str[]){
    /* your task */
    long long key,i=0,j;
    key=getKey(str);
    while(1){
        j=h(key,i);
        if(strcmp(H[j],str)==0)
            return 1;
        else if(strlen(H[j])==0){
            strcpy(H[j],str);
            return 0;
        }
        i++;
    }
}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);
	
	if ( com[0] == 'i' ){
	    insert(str);
	} else {
	    if (find(str)){
		printf("yes\n");
	    } else {
		printf("no\n");
	    }
	}
    }

    return 0;
}

Measured memory_bytes: 16056
#include<bits/stdc++.h>
#include<ext/rope>
#define ll long long
#define ld long double
#define ull unsigned long long
#define sc(x) scanf("%d",&x)
using namespace std;
using namespace __gnu_cxx;
const int N = 1e6 + 5;
const int mod = 998244353;
const ld pi = acos(-1.0);
int t,n,m,l,r,x,Case;
ll a[N],ans;
void run(){
    cin>>n>>a[0];
    for(int i=1;i<n;i++){
        cin>>a[i];
        if(a[i]<a[i-1]){
            ans+=a[i-1]-a[i];
            a[i]=a[i-1];
        }
    }
    cout<<ans<<'\n';
}
int main(){
#ifdef haosao
freopen("main.h", "r", stdin);
//freopen("out.txt","w",stdout);
#endif
    ios::sync_with_stdio(false);
//    while()
        run();
    return 0;
}


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

int main(){
	int a,b;
	cin>>a>> b;
	if(a<1 || a>9) cout<< -1;
    else if (b<1 || b>9) cout<< -1;
	else cout<< a*b;


	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<vector> //動的配列
#include<string> 
#include <list> //双方向リスト
#include <map> //連想配列
#include <set> //集合
#include <stack>
#include <queue>
#include <deque>
#include <cmath>


//小さい順から取り出すヒープ
//priority_queue<ll, vector<ll>, greater<ll> > pque1;

typedef long long ll;


using namespace std;

typedef pair<int, int> P;

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

const int N=1e5+10;
int n,m;
vector<vector<P>> G;
int dis[N]={};
bool check[N]={};
bool ok=true;

void dfs(int now){
    check[now]=true;
    for (int i=0;i<G[now].size();i++){
        int to=G[now][i].first;
        int cost=G[now][i].second;
        
        if (check[to]==false){
            dis[to]=dis[now]+cost;
            dfs(to);
        } else{
            if (dis[to]!=dis[now]+cost){
                ok=false;
            }
        }
    }
}


int main(){
    cin>>n>>m;
    G = vector<vector<P>>(n);
    for (int i=0;i<m;i++){
        int l,r,d;
        cin>>l>>r>>d;
        l--;r--;
        G[l].push_back({r,d});
        G[r].push_back({l,-d});
    }
    for (int i=0;i<n;i++){
        if (check[i]==false){
            dfs(i);
        }
    }
    
    if (ok==false){
        cout<<"No"<<endl;
    } else{
        cout<<"Yes"<<endl;
    }
    return 0;
}

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

int a,b;
int main()
{
	cin>>a>>b;
	if(a<=0&&b>=0)cout<<"Zero"<<endl;
	else if(a>0)cout<<"Positive"<<endl;
	  else
	  {
	  	if((b-a)%2==0)cout<<"Negative"<<endl;
	  	  else cout<<"Positive"<<endl;
	  }
}

Measured memory_bytes: 256