akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
const ll mod = 1e9 + 7;

int main() {
  string s;
  cin >> s;
  if (s.compare("SUN") == 0) cout << 7 << endl;
  if (s.compare("MON") == 0) cout << 6 << endl;
  if (s.compare("TUE") == 0) cout << 5 << endl;
  if (s.compare("WED") == 0) cout << 4 << endl;
  if (s.compare("THU") == 0) cout << 3 << endl;
  if (s.compare("FRI") == 0) cout << 2 << endl;
  if (s.compare("SAT") == 0) cout << 1 << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define sz(v) (int)v.size()
#define pb push_back

using namespace std;
int n;
vector<int> a,b,c;
int main(){
    cin >> n;
    int t = 4;
    a.pb(0),b.pb(0);
    while(t <= 100) a.pb(t), t+=4;
    t = 7;
    while(t <= 100) b.pb(t), t+=7;
    rep(i,a.size()) rep(j,b.size()) c.pb(a.at(i)+b.at(j));
    sort(ALL(c));
    if(binary_search(ALL(c),n)) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

using namespace std;
#define sz(a) int(a.size())
#define ll  long long
#define mod int(1e9+7)
#define endl '\n'
#define ENGZ ios::sync_with_stdio(0);ios_base::sync_with_stdio(0);cin.tie(0) , cout.tie(0) ;
#define pi (acos(-1))
#define S second
#define F first
ll fp(ll n , ll p )
{
    if(p==0)
        return 1;
    if(p==1)
        return n ;
    ll res = fp(n,p/2) ;
    res=((res)*(res)) ;
    if(p%2)
        res=(res*n) ;
    return res ;
}

int main()
{
    ENGZ;
    map<string, int> mp;
    int n , mx = 0;
    string s ;
    cin>>n ;
    for(int i=0 ; i<n ; i++)
    {
        cin>>s ;
        mp[s]++;
        mx = max(mx,mp[s]);
    }
    for(auto i:mp)
    {
        if(i.S == mx)cout<<i.F <<endl ;
    }
    return 0;
}


Measured memory_bytes: 23808
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	int n, i;
	long long ans = 0;
	vector <int> v;
	
	scanf("%d", &n);
	
	for (i = 0; i < n * 3; i++) {
		int x;
		
		scanf("%d", &x);
		
		v.push_back(x);
	}
	
	sort(v.begin(), v.end());
	reverse(v.begin(), v.end());
	
	for (i = 0; i < n; i++) ans += v[i * 2 + 1];
	
	printf("%lld\n", ans);
	
	return 0;
}


Measured memory_bytes: 2420
#include<bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long int
#define fi first
#define se second
#define pub push_back
#define pi pair<int,int>
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for(int i=(int)(l);i<(int)(r);i++)
#define repd(i, l, r) for (int i=(int)(l);i>=(int)(r);i--)
#define clrg(i, l, r) for(int i=(int)(l);i<(int)(r);i++)vis[i]=0,v[i].clear();
int power(int x, unsigned int y){int res = 1;while (y > 0){ if (y & 1){res = res*x;} y = y>>1;x = x*x;}return res;}
int powermod(int x, unsigned int y, int p){int res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1; x = (x*x) % p;}return res;}
#define print2d(mat,n,m){for(int i=0;i<(int)(n);i++){for(int j=0;j<(m);j++){cout<<mat[i][j]<<" ";}cout<< endl;}}
#define clr(a,x) memset(a,x,sizeof(a))
#define rr(v) for(auto &val:v)
#define print(v) for (const auto itr : v){cout<<itr<<' ';}cout<<"\n";
#define ln length()
#define sz size()
#define mod 1000000007
#define elif else if
int dp[1000006][2][2];
   int n;
int solve(int i,int fn, int fo){
  if(i==n){
    return (fn and fo?1:0);
  }
  if(dp[i][fn][fo]!=-1)return dp[i][fn][fo];
  int ans=0;
  rep(j,0,10){
    if(j==0){
      ans+=solve(i+1,fn,1);
    }
    elif(j==9){
      ans+=solve(i+1,1,fo);
    }
    else ans+=solve(i+1,fn,fo);
    ans%=mod;
  }
  dp[i][fn][fo]=ans;
  return ans;
}
int32_t main(){
  clr(dp,-1);
    cin>>n;
  cout<<solve(0,0,0);
   return 0;
}
/*
Edge cases? n=1? a[i]<=0?
long vs int? 1LL? 64bits?
Re-read problem. Is it as easy as it seems?
KEEP CORRECTING AND SUBMITTING!
*/


Measured memory_bytes: 112788
from collections import deque
from copy import deepcopy

h,w = map(int,input().split())
s = [list(input()) for i in range(h)]
t = ((0,1),(1,0),(-1,0),(0,-1))
m = 0
for sy in range(h):
    for sx in range(w):
        if s[sy][sx] == "#":
            continue
        ss = deepcopy(s)
        ss[sy][sx] = "#"
        q = deque([(0,sy,sx)])
        max_cost = 0
        my,mx = 0,0
        while(q):
            cost,y,x = q.popleft()
            max_cost = max(max_cost,cost)
            cost += 1
            for i,j in t:
                ny = y+i
                nx = x+j
                if 0 <= ny < h and 0 <= nx < w:
                    if ss[ny][nx] == ".":
                        q.append((cost,ny,nx))
                        ss[ny][nx] = "#"
        m = max(m,max_cost)
print(m)

Measured memory_bytes: 9508
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);

    int N = sc.nextInt();
    int K = sc.nextInt();
    int[] x = new int[N];

    for (int i = 0; i < N; i++) {
      x[i] = sc.nextInt();
    }

    sc.close();

    int count = 0;

    for (int i = 0; i < N; i++) {
      if (x[i] < Math.abs(K - x[i])){
        count += x[i] * 2;
      } else {
        count += Math.abs(K - x[i]) * 2;
      }
    }

    System.out.println(count);

  }

}

Measured memory_bytes: 23764
#include<cstdio>
#include<algorithm>
#include<numeric>
using namespace std;
int main()
{
	int n,m,i,a[10000],b[10000],c[20000],d[20000];
	while(scanf("%d%d",&n,&m),m||n)
	{
		for(i=0;i<n;++i)scanf("%d",&a[i]);
		for(i=0;i<m;++i)scanf("%d",&b[i]);
		merge(a,a+n,b,b+m,c);
		adjacent_difference(c,c+n+m,d);
		printf("%d\n",*max_element(d,d+m+n));
	}
	return 0;
}

Measured memory_bytes: 0
#include "algorithm"
#include "cmath"
#include "iostream"
#include "numeric"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
using namespace std;
typedef long long ll;

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

  ll N;
  cin >> N;

  rep(i, N + 1) {
    ll res = floor(i * 1.08);
    if (res == N) {
      cout << i << endl;
      return 0;
    }
  }

  cout << ":(" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
// #include <atcoder/all>

using namespace std;
// using namespace atcoder;

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

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

#else
#define print(...)
#endif

void solve() {
    ll H, N;
    cin >> H >> N;
    vector<P> items(N);
    rep(i, N) cin >> items[i].first >> items[i].second;
    vector<ll> dp(H + 1, INF);
    dp[H] = 0;
    rrep(i, H, 0) {
        rep(j, N) {
            ll a = items[j].first;
            ll b = items[j].second;
            ll v = max(0LL, i - a);
            dp[v] = min(dp[v], dp[i] + b);
        }
    }
    print(dp);
    cout << dp[0] << '\n';
}

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


Measured memory_bytes: 3712
#include<stdio.h>
int main (){

  int a,b;
  char op;
  int i;

  for(i=0;;i++){

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

  int c;

  if(op=='+'){
    c=a+b;
  }
  if(op=='-'){
    c=a-b;
  }
  if(op=='*'){
      c=a*b;
  }
   if(op=='/'){
        c=a/b;
      }
   if(op=='?') break;
   printf("%d\n",c);
  }



  return 0;
}

Measured memory_bytes: 600
import sys

sys.setrecursionlimit(10**6)

n = int(input())
g = [list() for _ in range(n)]
edge = list()
d = dict()
for _ in range(n-1):
    a,b = map(int, input().split())
    a -= 1; b -= 1
    g[a].append(b)
    g[b].append(a)
    if a > b:
        a,b = b,a
    edge.append((a,b))
k = max(len(g[i]) for i in range(n))

q = [(0,-1,-1)]
while q:
    v,p,c = q.pop()
    cc = 1
    for x in g[v]:
        if x == p:
            continue
        if cc == c:
            cc += 1
        if v < x:
            d[(v,x)] = cc
        else:
            d[(x,v)] = cc
        q.append((x,v,cc))
        cc += 1
print(k)
for x in edge:
    print(d[x])


Measured memory_bytes: 43360
n,m = map(int,input().split())
def div(x,y):
    if x%y!=0:
        return 0
    else:
        return 1+div(int(x/y),y)

p=[]
q=[]

def fact(s):
    if len(p)!=0:
        k=p[-1]
    else:
        k=2
    for i in range(2,max(int(s**0.5) +2,2)):
        a=div(s,i)
        if a==0:
            0
        else:
            p.append(a)
            q.append(i)
            s=int(s/i**a)
    if s!=1:
        p.append(1)
            
fact(m)
def comb(nn,rr):
    rr=min(rr,nn-rr)
    rt=1
    for i in range(rr):
        #rt=rt*(nn-i)/(rr-i)
        rt*=(nn-i)
    for i in range(rr):
        rt//=(rr-i)
    return int(rt)
#print(p,q,m)
mo=10**9 +7
ans=1
if len(p)==0:
    ans=1
else:
    for i in p:
        ans*=comb(i+n-1, i) % mo
print(ans % mo)

Measured memory_bytes: 3192
import bisect

N = int(input())
A = sorted([int(s) for s in input().split()])
B = sorted([int(s) for s in input().split()])
C = sorted([int(s) for s in input().split()])

cnt = 0

for b in B:
    insert_index1 = bisect.bisect_left(A, b)
    insert_index2 = bisect.bisect_right(C, b)

    cnt += insert_index1 * (N - insert_index2)

print(cnt)


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

using namespace std;

typedef long long ll;

ll mod;

ll powimod(ll x,ll n,ll mod){
    ll res=1;
    while(n){
        if(n&1) res=(res*x)%mod;
        x=(x*x)%mod;
        n>>=1;
    }
    return res;
}

ll powi(ll x,ll n){
    ll res=1;
    while(n){
        if(n&1) res*=x;
        x*=x;
        n>>=1;
    }
    return res;
}

vector<int> z_function(string s) {
    int n = (int) s.length();
    vector<int> z(n);
    for (int i = 1, l = 0, r = 0; i < n; ++i) {
        if (i <= r)
            z[i] = min (r - i + 1, z[i - l]);
        while (i + z[i] < n && s[z[i]] == s[i + z[i]])
            ++z[i];
        if (i + z[i] - 1 > r)
            l = i, r = i + z[i] - 1;
    }
    return z;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int x;
    cin>>x;
    int hcf=__gcd(360,x);
    int ans;
    ans=360/hcf;
    cout<<ans;
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
#define retunr return
#define pb push_back
#define mp make_pair
#define null NULL
#define sc(x) scanf("%d", &x)
#define sc64(x) scanf("%I64d", &x)
#define pr(x) printf("%d", (x))
#define sp putchar(' ')
#define ln putchar('\n')
#define pr64(x) printf("%I64d", (x))
#define rep(i,l,r) for (int i = l, lim = r;i <= lim; ++i)
#define repr(i,l,r) for (int i = r, lim = l;i >= lim; --i)
#define fi first
#define se second
#define SET(__set, val) memset(__set, val, sizeof __set)
#define prf(x) printf("%.20f", x)
typedef unsigned int uint;
typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define N 100010
#define M 1024
#define MOD 1000000007
void _add(int &a, int b){a = (a+b)%MOD;}
void _sub(int &a, int b){a = (a+MOD-b)%MOD;}
void _mul(int &a, int b){a = (ll)a*b%MOD;}
void _max(int &a, int b){a = max(a,b);}
void _min(int &a, int b){a = min(a,b);}
ll gcd(ll a, ll b){if(!b)return a;return gcd(b,a%b);}
ll pw(ll a, ll b){ll res(1);while(b){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
ll pwM(ll a, ll b, ll mod){ll res(1);while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}

const int infi = 2147483647;
const ll infl = 9223372036854775807ll;
const db PI = 3.14159265358979323846;

/*
struct E{
	int v, w, n;
}G[N];
int cnt, point[N];
void adde(int u, int v, int w = 0){
	G[++cnt]=(E){v,w,point[u]},point[u]=cnt;
	G[++cnt]=(E){u,w,point[v]},point[v]=cnt;
}
void Ginit(){
	cnt = 0;
	SET(point,0);
}
*/
/*
struct hh{
	int a, b;
	bool operator < (const hh &x) const{
		if(a==x.a)return b<x.b;
		return a<x.a;
	}
}a[N];
*/
int n,  k,q,a[N];
ll m;
// m%a[i] = m - (m/a[i])a[i]
// m*n - a[i](m/a[i])
int main(){
//	freopen("1", "r", stdin);
	sc(n);
	int ans = 0;
	rep(i,1,n)sc(a[i]),ans+=a[i]-1;
//	rep(i,1,n){
//	rep(j,1,1000000000){
//		ll res = 0;
//		m = j;
//		rep(k,1,n)res+=m%a[k];
//		if(res>ans){
//			rep(k,1,n)pr64(m%a[k]),sp;
//			pr64(m),ln;
//		}
//		ans=max(ans,res);
//		}
	pr64(ans);
/*
	int Case;
	sc(Case);
	rep(ca, 1, Case){
	    printf("Case #%d: ", ca);
	}
*/
	return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using P   = pair<ll, ll>;
using mat = vector<vector<ll>>;

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
const ld EPS = 1e-12;

template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}
ll powm(ll a, ll b, ll c) {
	if (b == 0)
		return 1;
	else if (b % 2 == 0) {
		ll d = powm(a, b / 2, c);
		return (d * d) % c;
	} else
		return (a * powm(a, b - 1, c)) % c;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

//ll dx[4] = {1, 0, -1, 0};
//ll dy[4] = {0, 1, 0, -1};

vector<ll> k[12];

int main() {
	IOS();
	ll n, m;
	cin >> n >> m;
	vector<ll> p(m);
	for (int i = 0; i < m; i++) {
		ll t;
		cin >> t;
		for (int j = 0; j < t; j++) {
			ll tmp;
			cin >> tmp;
			k[i].push_back(--tmp);
		}
	}
	for (int i = 0; i < m; i++) {
		cin >> p[i];
	}
	//return 0;
	ll ans = 0;
	for (ll i = 0; i < (1ll << n); i++) {
		vector<int> on(n);
		ll x = i;
		for (int j = 0; j < n; j++) {
			on[j] = x % 2;
			//cout << on[j] << " ";
			x /= 2;
		}
		bool ok = true;
		for (int j = 0; j < m; j++) {
			ll size = k[j].size();
			ll cnt  = 0;
			for (int l = 0; l < size; l++) {
				if (on[k[j][l]]) cnt++;
			}
			//cout << cnt << " ";
			ok &= (cnt % 2 == p[j]);
		}
		//cout << (ok ? "unko" : "ng") << endl;
		if (ok) ans++;
	}
	dump(ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=110000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

ll gcd(ll x, ll y){
  if(x%y==0)return y;
  return gcd(y,x%y);
}
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}
ll n,m;
ll s,t;
ll dist[110000][3];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  cin >> n >> m;
  vector<vector<ll>> G(n); 
  rep(i,m){
    ll u,v;
    cin >> u >> v;
    u--;
    v--;
    G[u].push_back(v);
  }
  cin >> s >> t;
  s--;
  t--;
  
  
  rep(i,n){
    rep(j,3){
      dist[i][j]=-1;
    }
  }
  dist[s][0]=0;
  queue<P>q;
  q.push({s,0});
  while(!q.empty()){
    auto now=q.front();
    q.pop();
    ll v=now.first;
    ll p=now.second;
    for(auto nv:G[v]){
      ll np=(p+1)%3;
      if(dist[nv][np]==-1){
        dist[nv][np]=dist[v][p]+1;
        q.push({nv,np});
      }
    }
  }
  if(dist[t][0]==-1){
    cout << -1 << endl;
    return 0;
  }
  cout << dist[t][0]/3 << endl;
    
  
}

Measured memory_bytes: 8064
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a/gcd(a,b)*b;
}

class SegTree{

private:

    int n;
    vector<int> seg;
    int init = 0; //初期化の値（単位元）
    int combine(int a, int b){
        return max(a,b);
    }

public:

    SegTree (){}

    SegTree(int size){
		n=1;
		while(n<size)n<<=1;
		seg=vector<int>(2*n,init);
	}

	SegTree(const vector<int> &in){
		n=1;
		while(n<in.size())n<<=1;
		seg=vector<int>(2*n,init);
		for(int i=n-1+in.size()-1;i>=0;i--){
			if(n-1<=i)seg[i]=in[i-(n-1)];
			else seg[i]=combine(seg[i*2+1],seg[i*2+2]);
		}
	}


    //k-th(0-indexd) を a
    void update(int k,int a){
      k+=n-1;
      seg[k]=a;
      while(k>0){
        k=(k-1)/2;
        seg[k]=combine(seg[k*2+1],seg[k*2+2]);
      }
    }

    //[a,b)について調べる
    int query(int a,int b,int k=0,int l=0,int r=-1){
        if(r==-1)r=n;
        if(r<=a || b<=l)return init;
        if(a<=l &&r<=b)return seg[k];

        int vl=query(a,b,k*2+1,l,(l+r)/2);
        int vr=query(a,b,k*2+2,(l+r)/2,r);

        return combine(vl,vr);
    }
};

signed main(void) {
    int n;
    cin >> n;
    vi h(n),a(n);
    rep(i,n)cin >> h[i], h[i]--;
    rep(i,n)cin >> a[i];
    vi ord(n);
    rep(i,n)ord[h[i]] = i;
    vi dp(n);
    SegTree st(n);
    rep(i,n){
        int ind = ord[i];
        dp[i] = st.query(0,ind) + a[ind];
        //cout << ind << " " << dp[i] << endl;
        st.update(ind,dp[i]);
    }
    cout << st.query(0,n) << endl;
}


Measured memory_bytes: 10624
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define out(a) cout<<a<<" "
#define all(a) (a).begin(), (a).end()
#define upper_index(v, a) (int)distance(v.begin(), upper_bound((v).begin(), (v).end(), a))
#define lower_index(v, a) (int)distance(v.begin(), lower_bound((v).begin(), (v).end(), a))
typedef long long ll;
const long long INF = 1e17;
struct cont {ll d=0,m=0,dm=0;};

int main() {
  ll n,q;
  string s;
  cin>>n>>s>>q;
  rep(i,q){
    ll k;
    cin>>k;
    vector<cont> cnt(n);
    ll ans=0;
    rep(j,n){
      if (j!=0){
        cnt[j].d=cnt[j-1].d;
        cnt[j].m=cnt[j-1].m;
        cnt[j].dm=cnt[j-1].dm;
      }
      if (s[j]=='D'){
        cnt[j].d+=1;
      }else if (s[j]=='M'){
        cnt[j].m+=1;
        cnt[j].dm+=cnt[j].d;
      }
      if (j>=k) {
        if (s[j-k]=='D'){
          cnt[j].d-=1;
          cnt[j].dm-=cnt[j].m;
        }else if (s[j-k]=='M'){
          cnt[j].m-=1;
        }
      }
    }
    rep(j,n) if (s[j]=='C') ans+=cnt[j].dm;
    
    cout<<ans<<endl;
    
  }
  return 0;
}


Measured memory_bytes: 24836
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;
vector<vi> res;int n,m,q;
int cnt  =0;
void dfs( vi a ,int y){
    if(a.size()==n){
        res.push_back(a);
        cnt++;
        return;
    }
    if(y>m)return;
    rep2(i,y,m+1){
        a.push_back(i);
        dfs(a,i);
        a.pop_back();
    }
}
int main(){
    cin>>n>>m>>q;
    ll a[q],b[q],c[q],d[q];
    rep(i,q){
        cin>>a[i]>>b[i]>>c[i]>>d[i];
    }
    ll ans =0;
    rep(i,m){
        string s =to_string(i+1);
        vi x;
        x.push_back(i+1);
        dfs(x,i+1);
    }
    //cout<<cnt<<endl;
    rep(i,res.size()){
        //int v = res[i];
        vi s =res[i];
        ll sum =0;

        rep(j,q){
            if(s[b[j]-1]-s[a[j]-1]==c[j])sum+=d[j];
        }
        ans=max(ans,sum);
    }

    cout<<ans<<endl;

    }

Measured memory_bytes: 9832
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<stack>
#include<map>
#include<deque>
#include<cstdio>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define ll __int64
#define __int64 long long
#define P pair<int,int>
#define PP pair<P,int>

int n;
int a[222222];



int main(){
    cin>>n;
    rep(i,n)cin>>a[i];
    sort(a,a+n);
    rep(i,n-1){
        if(a[i]==a[i+1]){
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <float.h>
#include <cfloat>
#include <string>
#include <ctype.h>
#include <algorithm>
#include <errno.h>
#include <cerrno>
#include <assert.h>
#include <cassert> 
#include <map>
#include <memory.h>
#include <cctype>
#include <ctype.h>
#include <math.h>
#include <vector> 
#include <cstdio> 
#include <set>
#include <string.h>
#include <stdio.h>
#include <new>
#include <memory>
#include <cmath>
#include <queue>
#include <cstring>
#define ll long long
#define fo(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define br break
#define ct continue
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define pii pair<int,int>  
#define em empty()
#define vei vector<int>
#define ves vector<string>
#define qui queue<int> 
#define qu queue
using namespace std;
int main()
{int n,ans=0;
 cin>>n;
 fo(i,1,n+1)
 if(i==105 || i==135 || i==165 || i==189 || i==195)
 ans++;
 cout<<ans<<endl;
 system("pause");
 return 0;
}

Measured memory_bytes: 504
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int s = sc.nextInt();
		int w = sc.nextInt();
		if (w >= s) {
			System.out.println("unsafe");
		} else {
			System.out.println("safe");
		}
	}
}


Measured memory_bytes: 35752
#include <cstring>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <fstream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <algorithm>
#include <vector>
#include <set>
#include <complex>
#include <list>
#include <climits>
#include <cctype>
#include <bitset>
using namespace std;

#define PI 3.14159265359
#define all(v) v.begin(),v.end()
#define sortva(v) sort(all(v))
#define sortvd(v) sort(v.rbegin(),v.rend())
#define sortaa(a,n) sort(a,a+n)
#define sortad(a,n) sort(a,a+n),reverse(a,a+n)
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1,v2) scanf("%d %d",&v1,&v2)
#define sfi3(v1,v2,v3) scanf("%d %d %d",&v1,&v2,&v3)
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1,v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1,v2,v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
#define sfstr(v) scanf("%s", v);
#define sz(v) (int)v.size()
#define ndl puts("")
#define SS stringstream
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };

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

void PLAY() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	cout << fixed << setprecision(10);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

int a[4];

int solve(int idx, int sum) {
	if (idx == 4) return sum == 7;
	int ret = solve(idx + 1, sum + a[idx]);
	ret |= solve(idx + 1, sum - a[idx]);
	return ret;
}

void out(int idx, int sum) {
	if (idx == 4) return;
	int ret1 = solve(idx + 1, sum + a[idx]);
	int ret2 = solve(idx + 1, sum - a[idx]);
	if (ret1) {
		cout << '+';
		cout << a[idx];
		out(idx + 1, sum + a[idx]);
	}
	else {
		cout << '-';
		cout << a[idx];
		out(idx + 1, sum - a[idx]);
	}
}
int main() {
	//PLAY();
	cout << fixed << setprecision(10);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	string s;
	cin >> s;
	for (int i = 0; i < 4; i++)
		a[i] = s[i] - '0';
	solve(1, a[0]);
	cout << a[0];
	out(1, a[0]);
	cout << "=7";
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	
	int n,k,s,N[100],x;
	char c[100];
	
	x=0;
	c[1]='p';
	c[2]='q';
	
	scanf("%d\n",&n);
	
	for(k=1;k<=n;k++){
		
		for(s=1;s<=100;s++){
			
			scanf("%c",&c[s]);
			if(c[s]==10)break;
			
		}
		
		if(c[1]=='A'){
			N[k]=1;
		}else if(c[1]=='U'&&c[2]=='n'){
			N[k]=0;
		}/*else{
			N[k]=2;
		}*/
		
	}
	
	
	for(k=1;k<=n;k++){
		
		if(N[k]==1){
			
/*			if(N[k-1]==0&&x!=0){
				printf("NO\n");
				break;
			}*/
			x++;
			
		}else if(N[k]==0){
			x--;
		}/*else{
			printf("NO\n");
			break;
		}*/
		
		if(x<0){
			printf("NO\n");
			break;
		}
		
		if(k==n){
			if(x==0){
				printf("YES\n");
			}else{
				printf("NO\n");
			}
		}
	}
	
	return 0;
}


Measured memory_bytes: 2116
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int>>
#define vb vector<bool>
#define vpli vector<pair<long long,int>>
#define deb(x) cout<<x<<endl;
ll MOD = 1e9+7;
void solve()
{
    int n,q,b,c;
    cin>>n;
    unordered_map<int,int> occ;
    ll sum =0;
    int x;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        occ[x]++;
        sum+=x;
    } 
    cin>>q;
    while (q--)
    {
        cin>>b>>c;
        occ[c] += occ[b];
        sum += (c-b)*(ll)occ[b];
        occ[b] = 0;
        cout<<sum<<endl;
    }
}
int main()
{
    solve();
    return 0;
}

Measured memory_bytes: 7132
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n,x,y,a[3000];
	cin>>n>>x>>y;
	for(int i=1;i<=n;i++)cin>>a[i];
	if(n==1)cout<<abs(a[1]-y)<<endl;
	else cout<<max(abs(a[n]-y),abs(a[n]-a[n-1]))<<endl;
	return 0;
}


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

//Coding below.
int main (){
    string S;
    cin >> S;
    if(S == "Sunny"){
        cout << "Cloudy";
    }else if (S == "Cloudy")
    {
        cout << "Rainy";
    }else{
        cout << "Sunny";
    }
    
}

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

int main(){
  int N,K,X,Y;
  cin >> N >> K >> X >> Y;
  int sum=0; 
  
  int date;
  if(N<K){
    date=N;
    for(int i=0; i < date; i++){
    sum += X;
    }
  }
  else{
    date=K;
    for(int i=0; i < date; i++){
    sum += X;
    }
    for(int i=K; date-1<i && i<N; i++){
    sum += Y;
    }
  }
    cout << sum << endl;
}

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

using namespace std;

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

  int num = 0, last = 2147483647;
  for (auto &x : s)
  {
    if (x - 'a' != last)
    {
      ++num;
      last = x - 'a';
    }
  }
  cout << num << endl;

  return 0;
}

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

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

typedef long long LL;
const LL mod=1000000007;
#define MAX 10000
#define NIL -1
const double PI  = acos(-1.0);
const int INF = 1e9 + 7;
//-------------------------------------------


LL n,k;
bool syu;
LL cnt;

LL a,b,c;





int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> n >> k;
    LL std = 0;

    if( k % 2 == 0){ syu = true;}
    else{ syu = false;}

    std = k / 2;
    a = std;
    b = std;

    if( syu != 0){

        for(LL i = a; i <= n; i += k){

                cnt += ((n - std) /k + 1 )* ((n - std) /k + 1 );
                //dump(i);
                //dump(j);
                //dump(cnt);
        }

    }

    for(LL i = k; i <= n; i += k){
            cnt += (n / k) * (n/k);

    }


    cout << cnt  << endl;






    return 0;
}


Measured memory_bytes: 256
package main

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

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func main() {
	X := readInt()
	Y := readInt()
	A := readInt()
	B := readInt()
	C := readInt()

	p := make([]int, A+1)
	q := make([]int, B+1)
	r := make([]int, C+1)

	for i := 0; i < A; i++ {
		p[i+1] = readInt()
	}
	for i := 0; i < B; i++ {
		q[i+1] = readInt()
	}
	for i := 0; i < C; i++ {
		r[i+1] = readInt()
	}

	sort.Sort(sort.Reverse(sort.IntSlice(p[1:])))
	sort.Sort(sort.Reverse(sort.IntSlice(q[1:])))
	sort.Sort(sort.Reverse(sort.IntSlice(r[1:])))

	for i := 1; i < A; i++ {
		p[i+1] += p[i]
	}
	for i := 1; i < B; i++ {
		q[i+1] += q[i]
	}
	for i := 1; i < C; i++ {
		r[i+1] += r[i]
	}

	result := 0
	for i := max(0, X-C); i <= X; i++ {
		ok := max(0, Y-(C-(X-i))) - 1
		ng := Y
		for ng-ok != 1 {
			m := ok + (ng-ok)/2
			t0 := q[m] + r[(X-i)+(Y-m)]
			t1 := q[m+1] + r[(X-i)+(Y-(m+1))]
			if t0 < t1 {
				ok = m
			} else {
				ng = m
			}
		}
		j := ok + 1
		result = max(result, p[i]+q[j]+r[(X-i)+(Y-j)])
	}

	fmt.Println(result)
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}


Measured memory_bytes: 8192
N, X = map(int, input().split())
x = list(map(int, input().split()))

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)  #ユークリッドの互除法

def gcdlist(L):
    a = L[0]-X
    for i in L:
        a = gcd(a, abs(i-X))
    return a
    
    
print(gcdlist(x))

Measured memory_bytes: 62576
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define V vector<int>
#define VLL vector<long long>
#define VV vector<vector<int>>
#define be(x) begin(x),end(x)
#define For(a) for(int i=0;i<a;i++)
#define Forin(a,b) for(int j=a;j<b;j++)
#define len(a) a.size()
#define pb push_back 
#define mp make_pair

ll solve();
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie();
    #ifndef ONLINE_JUDGE 
        freopen("input.txt", "r", stdin); 
        freopen("output.txt", "w", stdout); 
    #endif 
    
    /*int t;
    cin>>t;
    while(t--)
    {*/
        //solve();cout<<"\n";
        cout<<solve()<<endl;
    //}
return 0;
}
ll solve()
{
    ll n;
    cin>>n;
    VLL v(n);
    For(n) cin>>v[i];
    ll stool=0;
    Forin(1,n)
    {
        if(v[j-1] > v[j])
        {
            stool+=v[j-1]-v[j];
            v[j]=v[j-1];
        }
        
    }
    return stool;
}

Measured memory_bytes: 4836
n = int(input())
s = "SHCD"
used = [[0] * 13 for i in range(4)]
for i in range(n):
  a, b = input().split()
  used[s.find(a)][int(b) - 1] = 1
for i in range(4):
  for j in range(13):
    if used[i][j] == 0:
      print(s[i], j + 1)


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

int main(){
    string s, t;
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());   reverse(t.begin(), t.end());
    if(s < t) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using psi=pair<string,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
#define MOD ((ll)1e9+7)
void get(){}template<class H,class...T>void get(H&h,T&...t){cin>>h;get(t...);}
template<class T>void geti(T&a){for(auto&_:a)cin>>_;}
template<class T>void getii(T&a){for(auto&_:a)geti(_);}
void put(string d){}template<class H,class...T>void put(string d,H&h,T&...t){cout<<h;if(sizeof...(t))cout<<d;put(d,t...);}
template<class T>void puti(T&a,string d=" "){bool f=1;for(auto&_:a)cout<<(exchange(f,0)?"":d)<<_;cout<<endl;}
template<class T>void putii(T&a,string d=" "){for(auto&_:a)puti(_,d);}
#define dcl(...) ll __VA_ARGS__;get(__VA_ARGS__)
#define dclt(t,...) t __VA_ARGS__;get(__VA_ARGS__)
template<class F,class S>void add(map<F,S>&mp,F f,S s){if(mp.find(f)==mp.end())mp[f]=F();mp[f]+=s;}
 
int main(){
    int h,v;
    using data=pair<int,int>;
    
    while(cin>>h>>v, h or v){
        int tv[]={-3,-1,1,3};
        int tc[]={v,h,h,v};
        int p10[]={100000000,10000000,1000000,100000,10000,1000,100,10,1};
        array<int,9> a,b;
        geti(a);
        geti(b);
        int sa=0,sb=0;
        for(auto i:a)sa=sa*10+i;
        for(auto i:b)sb=sb*10+i;
    
        unordered_map<int,int> s;

        priority_queue<data> q;
        q.emplace(0,sa);
        
        while(1){
            int cost=q.top().fs;
            int board=q.top().sc;
            q.pop();
            if(board==sb){
                cout<<-cost<<endl;
                break;
            }
            int index=to_string(board).find('0');
            if(index==-1)index=0;
            rep(i,4){
                int fixed=(index+tv[i]+9)%9;
                int next=board;
                int fx=next/p10[fixed]%10;
                next-=p10[fixed]*fx;
                next+=p10[index]*fx;
                if(s.find(next)==s.end() || (s[next]<cost-tc[i] && cost-tc[i]>-3000)){
                    q.emplace(cost-tc[i], next);
                    s[next]=cost-tc[i];
                }
            }
        }
    }
}



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

typedef pair<int, int> Ipair;

int main()
{
    int N; ll K;
    scanf("%d %lld", &N, &K);
    Ipair op[N];
    for(int i = 0; i < N; ++i) scanf("%d %d", &op[i].first, &op[i].second);
    //for(int i = 0; i < N; ++i) printf("%d %d\n", op[i].first, op[i].second);

    sort(op, op + N, [](Ipair &a, Ipair &b){ return a.first < b.first; });
    //for(int i = 0; i < N; ++i) printf("%d %d\n", op[i].first, op[i].second);
    ll cur = 0;
    for(int i = 0; i < N; ++i) {
        cur += (ll)op[i].second;
        if(cur >= K) { printf("%d\n", op[i].first); return 0;}
    }
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long int ll;

struct Edge{
	int to; ll dist;
	Edge(){}
	Edge(int to,ll dist):to(to),dist(dist){}
};

template <class E>
using Graph = vector<vector<E>>;
 
template<class D, D INF>
struct Dijkstra {
    vector<D> res; //res[i] = sからiまでの最短距離
    
    template<class E>
    Dijkstra(const Graph<E> &g, int s) {
        int V = (int)g.size();
        res = vector<D>(V, INF);
        
        using P = pair<D, int>;
        priority_queue<P, vector<P>, greater<P>> q;
        q.push(P(0, s));
        res[s] = 0;
        while (!q.empty()) {
            P p = q.top(); q.pop();
            if (res[p.second] < p.first) continue;
            for (E e: g[p.second]) {
                if (p.first+e.dist < res[e.to]) {
                    res[e.to] = p.first+e.dist;
                    q.push(P(res[e.to], e.to));
                }
            }
        }
    }
};

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n,m,s,t; cin >> n >> m >> s >> t;
	s--; t--;
	Graph<Edge> g(n),h(n);
	for(int i=0;i<m;i++){
		int x,y; cin >> x >> y;
		x--; y--;
		ll a,b; cin >> a >> b;
		g[x].push_back(Edge(y,a));
		g[y].push_back(Edge(x,a));
		h[x].push_back(Edge(y,b));
		h[y].push_back(Edge(x,b));
	}
	Dijkstra<ll,(ll)1e16> di(g,s),di2(h,t);
	vector<ll> ans(n+1,1e16);
	for(int i=n-1;i>=0;i--){
		ans[i]=min(ans[i+1],di.res[i]+di2.res[i]);
	}
	ll tmp=1e15;
	for(int i=0;i<n;i++){
		cout << tmp-ans[i] << endl;
	}
}


Measured memory_bytes: 19016
#include<bits/stdc++.h>
using namespace std ;
#define Next( i, x ) for( register int i = head[x]; i; i = e[i].next )
#define rep( i, s, t ) for( register int i = (s); i <= (t); ++ i )
#define drep( i, s, t ) for( register int i = (t); i >= (s); -- i )
#define re register
#define int long long
int gi() {
	char cc = getchar() ; int cn = 0, flus = 1 ;
	while( cc < '0' || cc > '9' ) {  if( cc == '-' ) flus = - flus ; cc = getchar() ; }
	while( cc >= '0' && cc <= '9' )  cn = cn * 10 + cc - '0', cc = getchar() ;
	return cn * flus ;
}
const int N = 2e5 + 5 ; 
const int P = 2019 ; 
int A, B ;
signed main()
{
	A = gi(), B = gi() ;
	( A <= B ) ? puts("unsafe") : puts("safe") ;
	return 0 ;
}


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

int main(){
  int N,t,i,A=0,p=1;
  cin >> N;
  for(i=0;i<N;i++){
    cin >> t;
    while(t>1){
      if(t%2) break;
      t /= 2;
      A++;
    }
  }
  cout << A << endl;
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val s = sc.next()
    val t = sc.next()
    println(problem076c(s, t))
}

fun problem076c(s: String, t: String): String {
    val s = s.toCharArray()
    val t = t.toCharArray()
    var count = 0
    var tStart = -1
    var i = 0
    while (i < s.size) {
        if (count == 0 && (s[i] == t[0] || s[i] == '?' )) {
            count++
        } else if (count != 0 && (s[i] == t[0 + count] || s[i] == '?')) {
            count++
        } else {
            count = 0
        }
        if (count == t.size) {
            tStart = i - count + 1
            i = tStart
            count = 0
        }
        i++
    }
    if (tStart == -1) {
        return "UNRESTORABLE"
    }
    var res = ""
    for (i in 0 until s.size) {
        val si = s[i]
        if (i >= tStart && i < tStart + t.size && si == '?') {
            res += t[i - tStart]
        } else if (si == '?') {
            res += 'a'
        } else {
            res += si
        }
    }
    return res
}


Measured memory_bytes: 29468
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//(a+b-1)/b
//priority_queue<ll, vector<ll>, greater<ll>> q;
const int D = 60;
ll to[D][200005];

signed main(){
	//cout << fixed << setprecision(10);
	int n; cin>>n;
	int a,b;
	a=n/3600;
	n%=3600;
	b=n/60;
	n%=60;
	cout<<a<<":"<<b<<":"<<n<<endl;

	return 0;
}


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

int main() {
  int A, B;
  cin >> A >> B;
  string S;
  cin >> S;
  
  int C = B - 1;
  
  if (S[C] == 'A') {
    S[C] = 'a';
    cout << S << endl;
  } else if (S[C] == 'B') {
    S[C] = 'b';
    cout << S << endl;
  } else if (S[C] == 'C') {
    S[C] = 'c';
    cout << S << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  
  int64_t a, b, c, d;
  cin >> a >> b >> c >> d;
  
  int64_t g, s, t, u;
  int64_t i = b - a + 1;
  
  s = (b / c) - ((a-1) / c);
  t = (b / d) - ((a-1) / d);
  
  if(c < d)
    swap(c, d);
  
  int64_t x = c * d;
  int64_t r = c % d;
  
  while(r!=0){
    c = d;
    d = r;
    r = c % d;
  }
  
  g = x / d;
  
  u = (b / g) - ((a-1) / g);
  
  cout << (i - s - t + u) << endl;
}
    

Measured memory_bytes: 256
#include<cstdio>
const int MaxN=200010;
int N,B[MaxN];
long long A[MaxN],S[MaxN][2];
struct item{int i;bool v;item*last,*next;}items[MaxN],*stk[MaxN];
bool chk(item*it){
	int i=it->i,l=it->last->i,r=it->next->i;
	double El=(A[l]+A[i]*(i-l-1.0)-2*(S[i][1]-S[l+1][1]-l*(S[i][0]-S[l+1][0])))/(i-l),
		   Er=(A[r]+A[i]*(r-i-1.0)-2*(r*(S[r][0]-S[i+1][0])-S[r][1]+S[i+1][1]))/(r-i);
	//printf("chk i=%d l=%d r=%d El=%lf Er=%lf res=%d\n",i,l,r,El,Er,(El+Er)/2-B[i]>A[i]);
	return(El+Er)/2-B[i]>A[i];
}
int main(){
	scanf("%d",&N);
	int s=0;
	for(int i=0;i<N;i++)scanf("%lld",A+i),A[i]>A[s]?s=i:1;
	for(int i=0;i<=N;i++)*S[i]=A[(i+s)%N];
	for(int i=0;i<=N;i++)A[i]=*S[i],*S[i]=0,items[i]=(item){i,1,i?items+i-1:0,i<N?items+i+1:0},i&&i<N?stk[i-1]=items+i,1:1;
	for(int i=0;i<N;i++)scanf("%d",B+(i+N-s)%N);
	for(int i=0;i<N;i++){
		S[i+1][0]=S[i][0]+B[i];
		S[i+1][1]=S[i][1]+1ll*i*B[i];
	}
	s=N-1;
	while(s){
		item*it=stk[--s];it->v=0;
		if(chk(it)){
			it->last->next=it->next;
			it->next->last=it->last;
			if(!it->last->v)stk[s++]=it->last,it->last->v=1;
			if(!it->next->v)stk[s++]=it->next,it->next->v=1;
		}
	}
	double ans=0;
	item*l=items,*r=l->next;
	for(;r;l=l->next,r=r->next){
		//printf("l=%d r=%d\n",l->i,r->i);
		ans+=(A[l->i]+A[r->i])*0.5/N*(r->i-l->i);
		for(int i=l->i;++i<r->i;)ans-=B[i]*1.0/N*(i-l->i)*(r->i-i);
	}
	printf("%.12lf\n",ans);
}


Measured memory_bytes: 14880
@S=(0)x1e5;$i=1;$S[$i]=($S[$i-1]+2*/A/-1)%3,$i++for<>=~/./g;
@T=(0)x1e5;$i=1;$T[$i]=($T[$i-1]+2*/A/-1)%3,$i++for<>=~/./g;
<>;
	($a,$b,$c,$d)=glob,
	print+($S[$b]-$S[$a-1])%3==($T[$d]-$T[$c-1])%3?YES:NO,$/
for<>


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

struct node { int parent,depth; vector<int> child; };

vector<node> tree;

void dfs(int num){
	if(tree[num].child.size() == 0) return;
	for(int i = 0;i < tree[num].child.size();i++){
		tree[tree[num].child[i]].depth = tree[num].depth + 1;
		dfs(tree[num].child[i]);
	}
}

int main(){
	int n,m,now,t;
	cin >> n;
	tree.resize(n);
	for(int i = 0;i < n;i++){
		cin >> now >> m;
		vector<int> vec;
		for(int j = 0;j < m;j++){
			cin >> t;
			vec.push_back(t);
		}
		tree[now] = {-1,0,vec};
	}
	for(int i = 0;i < n;i++){
		for(int j = 0;j < tree[i].child.size();j++) tree[tree[i].child[j]].parent = i;
	}
	int par;
	for(int i = 0;i < n;i++){
		if(tree[i].parent == -1) par = i;
	}
	dfs(par);
	for(int i = 0;i < n;i++){
		cout << "node " << i << ": parent = " << tree[i].parent << ", depth = " << tree[i].depth;
		if(tree[i].parent == -1) {
			cout << ", root, [";
			if(tree[i].child.size() != 0) cout << tree[i].child[0];
			for(int j = 1;j < tree[i].child.size();j++) cout << ", " << tree[i].child[j];
			cout << "]" << endl;
		}
		else if(tree[i].child.size() == 0) cout << ", leaf, []" << endl;
		else {
			cout << ", internal node, [" << tree[i].child[0];
			for(int j = 1;j < tree[i].child.size();j++) cout << ", " << tree[i].child[j];
			cout << "]" << endl;
		}
		
	}
	return 0;
}

Measured memory_bytes: 7092
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MM 1000000000
#define MOD MM+7
#define MAX 101000
#define MAP 110
#define initial_value -1
#define Pair pair<int,int>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
ll dp[10010][51];

int main(){
    ll N,W; cin >> N >> W;
    ll w[110],v[110];
    ll dp[111][100100];
    for(ll i = 1; i <= N; i++){
        cin >> w[i] >> v[i];
        dp[i][0] = 0;
    }
    dp[0][0] = 0;
    for(ll i = 0; i < N; i++){
        for(ll j = 0; j <= W; j++){
            dp[i+1][j] = dp[i][j];
            if(j >= w[i+1]){
                dp[i+1][j] = max(dp[i][j-w[i+1]] + v[i+1], dp[i+1][j]);
            }
        }
    }
    ll ans = 0;
    for(ll i = 0; i <= W; i++){
        ans = max(dp[N][i], ans);
    }
    cout << ans << endl;
}



Measured memory_bytes: 80512
#include<iostream>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
using ll = long long;
ll h[100000];
ll dp[100010];
int main(){
  ll n;
  cin>>n;
  rep(i,n){
    cin>>h[i];
    dp[i]=10000000000;
  }
  dp[0]=0;
  rep(i,n){
    dp[i+1]=min(dp[i+1],dp[i]+abs(h[i]-h[i+1]));
    dp[i+2]=min(dp[i+2],dp[i]+abs(h[i]-h[i+2]));
  }
  cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMod = 1e9 + 7;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  string S;
  cin >> S;

  ll count = 0;
  REP(i, 0, (S.size() / 2 / 2)) {
    count++;
    if (S[i] != S[(S.size() / 2) - 1 - i]) {
      cout << "No" << endl;
      return 0;
    }
  }

  REP(i, 0, count) {
    if (S[S.size() - i - 1] != S[S.size() / 2 + i + 1]) {
      cout << "No" << endl;
      return 0;
    }
  }

  REP(i, 0, S.size() / 2) {
    if (S[i] != S[S.size() - i - 1]) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
x_s = list(map(int, input().split()))



if n >= m:
    print(0)
else:
    x_s.sort()
    b=[]
    for i in range(m-1):
        b.append(x_s[i+1]-x_s[i])
    b.sort()
    ans = 0
    for i in range(m-n):
        ans += b[i]
    print(ans)


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

const int INF = 2e9;
const ll MOD = 1e9+7;

int main(){
    ll n,k;
    cin >> n >> k;
    vector<int> b(n);
    rep(i,n) cin >> b[i];
    ll ans = 0;
    rep(i,n){
        ll a = b[i];
        ll l = 0;
        ll r = 0;
        for(int j = 0; j < n;j++){
            if(j < i && b[j] > a)l++;
            if(b[j] > a)r++;
        }
        ans += l * k % MOD;
        ans %= MOD;
        ans += k * (k-1) / 2 % MOD * r % MOD;
        ans %= MOD;
    }
    cout << ans << endl;
}

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

using namespace std;

int main()
{
    int K, X;
    cin >> K >> X;
    if(500 * K >= X)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 888