akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#pragma region Macro
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v) sort(v.begin(), v.end())
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define vvi vector<vector<int>>
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#pragma endregion

// auto mod int
// source : https://github.com/atcoder-live/library
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int MOD = 1000000007;
const int mod = 1000000007;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x=0):x((x%mod+mod)%mod){}
	mint operator-() const { return mint(-x);}
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod-a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
	mint operator+(const mint a) const { return mint(*this) += a;}
	mint operator-(const mint a) const { return mint(*this) -= a;}
	mint operator*(const mint a) const { return mint(*this) *= a;}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t>>1);
		a *= a;
		if (t&1) a *= *this;
		return a;
	}
	
	// for prime mod
	mint inv() const { return pow(mod-2);}
	mint& operator/=(const mint a) { return *this *= a.inv();}
	mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

#pragma region Debug
void debug_out() { cout << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cout << H << " ";
	debug_out(T...);
}

#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
#pragma endregion

// コンパイル時、エイリアス「debug」を使用 --> マクロが使えるように

void solve(){
	#define int ll
	// ここに処理を記述
	// コンパイル時はエイリアス「gpp」--> c++17でコンパイル
	
	ll n;
	cin >> n;

	if(n==1){
		cout << 0 << endl;
		return;
	}
	else{
		ll all = 1;
		rep(i,n){
			all *= 10;
			all = all % (mod);
		}
		ll half = 1;
		rep(i,n){
			half *= 9;
			half = half % (mod);
		}
		half = all - half;
		if(half < 0) half += mod;
		ll no = 1;
		rep(i,n){
			no *= 8;
			no = no % (mod);
		}
		no = all - no;
		if(no < 0) no += mod;

		ll ans = half;
		ans += half;
		ans = ans % (mod);
		ans -= no;
		if(ans < 0) ans += mod;

		cout << ans << endl;
	}

}

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

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
using ll = long long;
using ld = long double;
const int MOD = 1e9+7;
const ll INF = 1LL << 60;


int main() {
    string s; cin >> s;
    string t = s;
    reverse(ALL(t));
    if(s.size() == 2) cout << s << endl;
    else cout << t << endl;

    return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h> 
#define rep(i,n) for(int i=0; i<(n); ++i)
#define cout(x) cout<<x<<endl
#define all(v) v.begin(), v.end()
using namespace std;
//型エイリアス
using vi = vector<int>;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
const ll inf = 1e18;
const int N = 2e5 + 10;

int main(){
    string s;
    cin >> s;
    
    int a = (int)s[0] - '0';
    int b = (int)s[1] - '0';
    int c = (int)s[2] - '0';
    int d = (int)s[3] - '0';

    for(int i=0; i<(1<<3); ++i){
        int sum = a;
        bitset<3> t = i;
        if(t[2]==1) sum += b;
        else sum -= b; 
        if(t[1]==1) sum +=   c;
        else sum -=  c; 
        if(t[0]==1) sum +=   d;
        else sum -=  d; 

        if(sum==7){
            string u;
            u = (char)(a + '0');
            if(t[2]==1) u += '+';
            else u += '-';
            u += (char)(b + '0');
            if(t[1]==1) u += '+';
            else u += '-';
            u += (char)(c + '0');
            if(t[0]==1) u += '+';
            else u += '-';
            u += (char)(d + '0');
            u += "=7";
            cout(u); 
            break;
        }
    }



    return 0;

}

Measured memory_bytes: 256
N,K = list(map(int,input().split()))
A = list(map(int,input().split()))
A.sort(reverse=True)

ans = 0
sum = 0
cnt = 0
for i in range(N):
  a = A[i]
  if sum+a>=K:
    ans += cnt+1
    cnt = 0
  else:
    sum += a
    cnt += 1
    
print(N-ans)

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

using namespace std;

#define PH push
#define MP make_pair
#define PB push_back
#define fst first
#define snd second
#define FOR(i, x, y) for(int i = (x); i < (y); ++i)
#define REP(i, x, y) for(int i = (x); i <= (y); ++i)
typedef double db;
typedef long long ll;
typedef long double ldb;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9 + 7;
const int maxn = 1e5 + 5;
const int logn = 20;

class Edge{
public:
	int u, v, c, w;
}ed[maxn];

class Query{
public:
	int u, v, x, y;
}qry[maxn];

int n, q;
ll sum;
int dep[maxn];
ll totw[maxn], cnt[maxn], ans[maxn];
int par[maxn][logn];
vector<int> g[maxn];
vector<pii> qq[maxn];

void dfs(int u, int p){
	if(~p) dep[u] = dep[p] + 1;
	par[u][0] = p;
	FOR(i, 0, g[u].size()){
		Edge e = ed[g[u][i]];
		int v = ((e.u == u) ? (e.v) : (e.u));
		if(v == p) continue;
		dfs(v, u);
	}
	return;
}

void precalc(){
	dfs(0, -1);
	FOR(i, 1, logn) FOR(u, 0, n){
		if(~par[u][i - 1]) par[u][i] = par[par[u][i - 1]][i - 1];
		else par[u][i] = -1;
	}
	return;
}

int lca(int u, int v){
	if(dep[u] < dep[v]) swap(u, v);
	int d = dep[u] - dep[v];
	FOR(i, 0, logn) if(d & (1 << i)) u = par[u][i];
	if(u == v) return u;
	for(int i = logn - 1; i >= 0; --i){
		if(~par[u][i] && par[u][i] != par[v][i])
			u = par[u][i], v = par[v][i];
	}
	return par[u][0];
}

void calc(int u, int p){
	FOR(i, 0, g[u].size()){
		Edge e = ed[g[u][i]];
		int v = ((e.u == u) ? (e.v) : (e.u));
		if(v == p) continue;
		++cnt[e.c];
		totw[e.c] += e.w;
		sum += e.w;
		calc(v, u);
		--cnt[e.c];
		totw[e.c] -= e.w;
		sum -= e.w;
	}
	FOR(i, 0, qq[u].size()){
		int tp = qq[u][i].fst, id = qq[u][i].snd;
		ans[id] += tp * (sum - totw[qry[id].x] + cnt[qry[id].x] * qry[id].y);
	}
	return;
}

int main(){
	scanf("%d%d", &n, &q);
	FOR(i, 1, n){
		scanf("%d%d%d%d", &ed[i].u, &ed[i].v, &ed[i].c, &ed[i].w);
		--ed[i].u; --ed[i].v;
		g[ed[i].u].PB(i);
		g[ed[i].v].PB(i);
	}
	precalc();
	FOR(i, 0, q){
		scanf("%d%d%d%d", &qry[i].x, &qry[i].y, &qry[i].u, &qry[i].v);
		--qry[i].u; --qry[i].v;
		int r = lca(qry[i].u, qry[i].v);
		qq[qry[i].u].PB(MP(1, i));
		qq[qry[i].v].PB(MP(1, i));
		qq[r].PB(MP(-2, i));
	}
	calc(0, -1);
	FOR(i, 0, q) printf("%lld\n", ans[i]);
	return 0;
}

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

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


int main(){
	int n,m;
    ll k;
    vector<ll> a(200000),b(200000);

    cin >> n >> m >> k;
    for(int i=0;i<n;i++)cin >> a[i];
    for(int i=0;i<m;i++)cin >> b[i];

    vector<ll> suma(n+1),sumb(m+1);
    suma[0] = 0;
    sumb[0] = 0;
    for(int i=0;i<n;i++) suma[i+1] = suma[i] + a[i];
    for(int i=0;i<m;i++) sumb[i+1] = sumb[i] + b[i];

    int ans = 0;
    for(int i=0;i<=n&&suma[i]<=k;i++){
        int j = upper_bound(sumb.begin(),sumb.end(),k-suma[i]) - sumb.begin() -1;
        ans = max(i+j,ans);
    }

    cout << ans << endl;

	return 0;
}


Measured memory_bytes: 9512
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


# aとbの最大公約数
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


# aとbの最小公倍数
def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def main():
    g = defaultdict(list)
    for _ in range(3):
        a, b = map(int, input().split())
        g[a].append(b)
        g[b].append(a)

    for p in permutations([1, 2, 3, 4]):
        ok = True
        for i in range(3):
            a, b = p[i], p[i + 1]
            if b not in g[a]:
                ok = False
        if ok:
            print(YES)
            return
    print(NO)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3944
#include<bits/stdc++.h>
#define fi first
#define se second
#define show(x) cerr<<#x<<"="<<x<<"\n"
typedef long long ll;
using namespace std;
//const ll MOD=(ll)1e9+7;
const int inf=100000000;
const int dy[]={1,0,-1};
const int dx[]={1,0,-1};
int n,m,h,w;
string s;
vector<int> a,b;
int dp[1000001],dp2[1000001];

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout<<fixed;
#ifdef LOCAL_DEFINE
  FILE *stream1;
  //FILE *stream2;
  stream1=freopen("in","r",stdin);
  //stream2=freopen("out","w",stdout);
  if(stream1==NULL)return 0;
  //if(stream2==NULL)return 0;
#endif
  for(int i=1;i<200;i++){
    a.push_back(i*(i+1)*(i+2)/6);
    int temp=i*(i+1)*(i+2)/6;
    if(temp&1)b.push_back(temp);
  }
  for(int i=0;i<=1000000;i++)dp[i]=inf;
  dp[0]=0;
  for(int i=0;i<=1000000;i++){
    for(int j=0;j<(int)a.size();j++){
      if(i+a[j]<=1000000){
        dp[i+a[j]]=min(dp[i+a[j]],dp[i]+1);
      }
    }
  }
  for(int i=0;i<=1000000;i++)dp2[i]=inf;
  dp2[0]=0;
  for(int i=0;i<=1000000;i++){
    for(int j=0;j<(int)b.size();j++){
      if(i+b[j]<=1000000){
        dp2[i+b[j]]=min(dp2[i+b[j]],dp2[i]+1);
      }
    }
  }
  while(cin>>n,n){
    cout<<dp[n]<<" "<<dp2[n]<<endl;
  }
#ifdef LOCAL_DEFINE
  cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<"s.\n";
  fclose(stream1);
  //fclose(stream2);
#endif
  return 0;
}







Measured memory_bytes: 11028
from collections import Counter

n = int(input())
S = [input() for i in range(n)]
set_char = set([c for c in S[0]])
num_char = dict()
for s in S:
    set_tmp = set()
    for c in s:
        set_tmp.add(c)
    set_char = set_char & set_tmp
    cnt = Counter(s)
    for c in set_char:
        if c not in num_char:
            num_char[c] = cnt[c]
        elif cnt[c] < num_char[c]:
            num_char[c] = cnt[c]
res = str()
for c in set_char:
    for i in range(num_char[c]):
        res = res + c
print("".join(sorted(res)))

Measured memory_bytes: 3316
#include "bits/stdc++.h"

using namespace std;
typedef long long ll;
#define out(ans) cout << ans << endl;
const long long mod = 1e9 + 7;

int main() {
  string s;
  int c, f;
  cin >> s;
  c = s.find('C');
  f = s.rfind('F');
  if (c == string::npos || f == string::npos) {
    cout << "No" << endl;
  } else if (f < c) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main() {
 char S[4];
 char T[4];
 scanf("%s",S);
 scanf("%s",T);
 int n = 0;
 for (int i = 0; i < 3; i++) {
   if (S[i]==T[i]) {
     n++;
   }
 }
 printf("%d\n",n);


  return 0;
}


Measured memory_bytes: 128
const M: u64 = 1000_000_007;

fn main() {
    proconio::input! {
        n: u64,
        m: u64,
    }

    let c = Combination::new(m);
    let mut sign = false;
    let mut r = 0;
    for i in 0..=n {
        let k = c.comb(n, i) * c.perm(m - i, n - i) % M;
        if sign {
            if k > r {
                r += M;
            }
            r -= k;
        } else {
            r += k;
            if r > M {
                r -= M;
            }
        }
        sign ^= true;
    }

    println!("{}", r * c.perm(m, n) % M);
}

struct Combination {
    fact: Vec<u64>,
    inv_fact: Vec<u64>,
}

impl Combination {
    fn new(n: u64) -> Combination {
        let mut fact = vec![1; n as usize + 1];
        for i in 1..=n {
            fact[i as usize] = fact[i as usize - 1] * i % M;
        }
        let mut inv_fact = vec![1; n as usize + 1];
        inv_fact[n as usize] = pow(fact[n as usize], M - 2);
        for i in (1..=n).rev() {
            inv_fact[i as usize - 1] = inv_fact[i as usize] * i % M;
        }

        Combination {fact, inv_fact}
    }

    fn perm(&self, n: u64, r: u64) -> u64 {
        self.fact[n as usize] * self.inv_fact[(n - r) as usize] % M
    }
    
    fn comb(&self, n: u64, r: u64) -> u64 {
        self.perm(n, r) * self.inv_fact[r as usize] % M
    }
}

fn pow(mut a: u64, mut n: u64) -> u64 {
    let mut r = 1;
    while n > 0 {
        if n & 1 > 0 {
            r = r * a % M;
        }
        a = a * a % M;
        n >>= 1;
    }
    r
}


Measured memory_bytes: 9972
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX=200000;

int main(void){
	int R[MAX],n;
	
	cin>>n;
	for(int i=0;i<n;i++)cin>>R[i];
	
	int maxv=-2000000000;
	int minv=R[0];
	
	for(int i=1;i<n;i++){
		maxv=max(maxv,R[i]-minv);
		minv=min(minv,R[i]);
	}
	
	cout<<maxv<<endl;
	
	return 0;
}


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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    string t; cin >> t;
    int sn = s.size(); int tn = t.size();
    vector<int> sv(sn+1, 0), tv(tn+1, 0);
    for (int i = 0; i < sn; i++) {
        sv[i+1] = sv[i] + (s[i] - 'A' + 1);
    }
    for (int i = 0; i < tn; i++) {
        tv[i+1] = tv[i] + (t[i] - 'A' + 1);
    }
    int q; cin >> q;
    for (int qi = 0; qi < q; qi++) {
        int a, b, c, d; cin >> a >> b >> c >> d;
        if (((sv[b]-sv[a-1]) % 3) == ((tv[d]-tv[c-1]) % 3)) {
            cout << "YES\n";
        } else cout << "NO\n";
    }
    return 0;
}

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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rrep(i,n) for(int i=n;i>=0;i--)
#define rrepa(i,a,n) for(int i=n;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
#define cmax(a,b) a=max(a,b)
#define cmin(a,b) a=min(a,b)
#define vc vector

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,int> pi;

int main(){

    int h,n;
    cin>>h>>n;
    vi a(n),b(n);
    rep(i,n)cin>>a[i]>>b[i];

    vi dp(h+1,INT_MAX);
    dp[0]=0;

    rep(i,n){
        rep(j,h+1){
            if(j-a[i]>=0){
                dp[j]=cmin(dp[j],dp[j-a[i]]+b[i]);
            }else{
                dp[j]=cmin(dp[j],b[i]);
            }
            // cerr<<"dp["<<j<<"] = "<<dp[j]<<"\n";
        }
    }

    cout<<dp[h]<<"\n";

    return 0;
}

Measured memory_bytes: 256
(defun po (lst count)
  (if (every #'evenp lst)
      (po (mapcar (lambda (x) (/ x 2)) lst) (1+ count))
      count))

(defun read-po ()
  (read-line)
  (read-from-string (concatenate 'string "(" (read-line) ")")))

(princ (po (read-po) 0))

Measured memory_bytes: 14180
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pll;
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    ll a[n], ans = 0;
    map<ll, ll>mp;
    for(int i = 0;i < n;++i)
    {
        cin >> a[i];
        ++mp[i - a[i]];
    }
    for(int i = 0;i < n;++i)
    {
        --mp[i - a[i]];
        ans += mp[i + a[i]];
    }
    cout << ans;
    return 0;
}


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

int main() {
    string h;
    int m, n;
    while(cin >> h){
        if(h =="-") break;
        cin >> m;
        for(int i=0; i<m; i++){
            cin >> n;
            h+=h.substr(0,n);
            h=h.substr(n);
        }
        cout << h << endl;
    }
    return 0;
}

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

using namespace std;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	vector<int>v(n);
	long long sum=0;
	int mod = 1000000007;
	for (int i = 0; i < n; i++){
		cin >> v[i];
		sum += v[i];
		sum %= mod;
	}
	long long ans = 0;
	for (int i = 0; i < n; i++){
		sum -= v[i];
		if (0>sum)sum += mod;
		ans += sum *v[i];
		ans %= mod;
	}
	cout << ans;
	//system("pause");
	return 0;
}


Measured memory_bytes: 3960
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

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

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

N = I()
a = IL()
l = [int_log(x&-x,2) for x in a]
P(sum(l))

Measured memory_bytes: 43100
#include <stdio.h>

int main()
{
	int X;			/* ユーザーが指定する数値X */
	scanf("%d", &X);

	int is_prime;		/* 素数かどうかの判定を格納する */
	int Is_Prime(int);	/* 関数使用の宣言 */
	
	while(1){
		is_prime = Is_Prime(X);
		if(is_prime)
			break;

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

int Is_Prime(int X)
{
	int index;		/* ループのインデックス */
	for(index = 2; (index * index) < X; ++index){
		if(X % index == 0)
			return (0);
	}
	return (1);
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	int a[2][105];
	int f2[105],f1[105];
	while(cin>>n)
	{
		for(int i=0;i<2;i++)
		{
			for(int j=1;j<=n;j++)
			{
				cin>>a[i][j];
			}
		}
		f2[n]=a[1][n];
		for(int i=n-1;i>=1;i--)
		{
			f2[i]=a[1][i]+f2[i+1];
		}
		
		f1[n]=a[0][n]+f2[n];
		for(int i=n-1;i>=1;i--)
          {
          	f1[i]=max(f1[i+1]+a[0][i],f2[i]+a[0][i]);
		  }
		  cout <<f1[1]<<endl;
	}
}

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

int main() {

	int A,B;
	cin>>A>>B;
  if(A==B){cout<<"Draw"<<endl;}
	else if(A==1){cout<<"Alice"<<endl;}
  else if (B==1){cout<<"Bob"<<endl;}
  else if(A>B){cout<<"Alice"<<endl;}
  else{cout<<"Bob"<<endl;}
//	cout<< <<endl;
}



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

int main(){
	string in = "";
	cin>>in;
	if(in.size()!=6) cout<<"No"<<"\n";
	else{
		if(in[2]==in[3] && in[4] == in[5]){
			cout<<"Yes"<<"\n";
			}
		else cout<<"No"<<"\n";
		}
	
	
	return 0;
	}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define f(i,a,b) for(register int i=a;i<=b;++i)
#define ff(i,a,b) for(register int i=a;i>=b;--i)
#define debug(x) cerr << #x << " : " << x << " " << endl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
const ll mod = 1e9 + 7;
const ull mod1 = 2e18 + 7;
const int inf = 0x3f3f3f3f;
const double tiaohe = 0.57721566490153286060651209;
ll oula(ll x) { ll res = x;f(i, 2, x / i) { if (x % i == 0) { res = res / i * (i - 1);while (x % i == 0) x /= i; } }if (x > 1) res = res / x * (x - 1);return res; }
ll quickmod(ll a, ll n, ll m) { ll s = 1;while (n) { if (n & 1) { s = s * a % m; }a = (a*a) % m;n = n / 2; }return s; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
void ex_gcd(ll a, ll b, ll &x, ll &y, ll &d) { if (!b) { d = a, x = 1, y = 0; } else { ex_gcd(b, a % b, y, x, d);y -= x * (a / b); } }
ll inv(ll t, ll p) { ll d, x, y;ex_gcd(t, p, x, y, d);return d == 1 ? (x % p + p) % p : -1; }
bool isPrime(ll x) { if (x == 2)return true;if (x % 2 == 0)return false;for (ll i = 2;i*i <= x;i++) if (x % i == 0)return false; return true; }
//double a = log(n) +tiaohe + 1.0 / (2 * n);
double eqa = (1 + sqrt(5.0)) / 2.0;
const int N = 3e5 + 5;
int t;

int main()
{
	//freopen("in.txt", "r", stdin);
	int n, x;
	while (cin >> n)
	{
		int ans = 0;
		f(i, 1, n)
		{
			scanf("%d", &x);
			if ((x & 1) && (i & 1))ans++;
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3764
N = input()
N = int(N)

for a in range(0,100):
    n = N-10*a

    if n <=9:
        break;
        
if n == 2 or n == 4 or n == 5 or n == 7 or n == 9:
    print('hon')
elif n == 0 or n == 1 or n == 6 or n == 8:
    print('pon')
elif n == 3:
    print('bon')

Measured memory_bytes: 9192
import math
def lcm(x,y):
    return (x*y)//math.gcd(x,y)
a,b,c,d=map(int,input().split())
bc=b//c
bd=b//d
bcd=b//lcm(c,d)
x=b-(bc+bd-bcd)
a=a-1
ac=a//c
ad=a//d
acd=a//lcm(c,d)
y=a-(ac+ad-acd)
print(x-y)

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
template<class T,class Y>T LCM(T a,Y b){return (a*b)/GCD(a,b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

using vi=vector<int>;
using vii=vector<vi>;

#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()
#define decimal(x) fixed<<setprecision(x)

int main(){
    #define int long long
    int N;
    int Red=0,Green=0,Blue=0;
    string S;
    cin>>N>>S;
    rep(i,N){
        if(S[i]=='R')Red++;
        else if(S[i]=='G')Green++;
        else if(S[i]=='B')Blue++;
    }
    ll sum=Red*Green*Blue;
    //cout<<sum<<endl;
    rep(i,2000){
        rep(j,N){
            if(j-i<0||i+j>=N)continue;
            if(S[j]!=S[j-i]&&S[j]!=S[j+i]&&S[j+i]!=S[j-i]){
                //cout<<j-i<<" "<<j<<" "<<j+i<<endl;
                sum--;
            }
        }
    }

    cout<<sum<<endl;

    return 0;
}

//a=97,z=122


Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vp = vector<pii>;
using vs = vector<string>;
using qi = queue<int>;
using qp = queue<pii>;
using pqi = priority_queue<int>;
using pqim = priority_queue<pii, vector<pii>, greater<pii> >;
using ppp = pair<int, pair<int, int>>;
#define all(vec) vec.begin(), vec.end()
#define rall(vec) vec.rbegin(), vec.rend()
#define pb push_back
const ll mod = 998244353;
//const ll inf = 1e18;
const int inf = 1e9 + 7;
const int mxn = 2e5;


int n;
char c;
void input() {
	cin >> c;

}

void solve() {

	if (c >= 'a' && c <= 'z') {
		cout << 'a';
	}
	else cout << 'A';


	return;
}

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

	input();
	solve();
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
int ws(int n){
	int ws=0;
	while(n>0){
		ws++;
		n=n/10;
	}
	return ws;
}
int main(){
	int n;
	cin >> n;
	int num=0;
		for(int i=1;i<=n;i++){
			if(ws(i)%2==0){
				continue;
			}
			else{
				num++;
			}
		}
	cout << num;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
#include<cstring>

using namespace std;

#ifdef LDEBUG
#define debug(x) cout << #x << ":" << x << endl
#else
#define debug(...)
#endif

#define REP(i,n) for(int i=0; i<n; ++i)

typedef unsigned long long u64;
typedef long long i64;

int a,b,t;

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

        cin >> a >> b >> t;

        cout << b*(int)(t/a) << endl;



        return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <iomanip> 
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<bool> vb;
typedef vector<ull> vul;
typedef vector<pair<ll, ll>> vpl;
typedef pair<ll, ll> pl;
#define For(i, n) for(ll i = 0; i < n; i++)
#define len(n) (ll)(n).size()
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
long double dp[3010][3010];
vector<long double> p;
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n;
	cin >> n;
	p.resize(n);
	For(i, n) {
		cin >> p[i];
	}
	dp[1][0] = 1 - p[0];
	dp[1][1] = p[0];
	for (ll i = 2; i <= n; i++) {
		For(j, n + 1) {
			if (j == 0) {
				dp[i][j] = dp[i - 1][j] * (1 - p[i - 1]);
			}
			else {
				dp[i][j] = dp[i - 1][j] * (1 - p[i - 1]) + dp[i - 1][j - 1] * p[i - 1];
			}
			//cout << i << ' ' << j << ' ' << dp[i][j] << endl;
		}
	}
	long double ans = 0;
	cout.precision(10);
	For(i, n + 1) {
		if (i > n / 2) {
			//cout << ans << ' ' << dp[n][i] << endl;
			ans += dp[n][i];
		}
	}
	cout << fixed << ans;
	return 0;
}

Measured memory_bytes: 144880
#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=1e18;

int main() {
  ll n;
  cin >> n;
  map<ll,ll> a;
  for(ll i=0;i<n;i++) {
    ll tmp;
    cin >> tmp;
    a[tmp]++;
  }
  ll ans=0;
  for(auto p:a) {
    if(p.second>1) {
      ans=p.first;
    }
  }
  ll ans2=0;
  for(auto p:a) {
    if(p.first==ans&&p.second<4) continue;
    if(p.second>1) {
      ans2=p.first;
    }
  }
  cout << ans*ans2 << endl;
}

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

#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 SORTASC(c) sort((c).begin(), (c).end())
#define SORTDESC(c, t) sort((c).begin(), (c).end(), std::greater<t>());
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define VMAX(a) *max_element(ALL(a))
#define VMIN(a) *min_element(ALL(a))
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

const double PI = acos(-1.0);

using ll = long long;
using namespace std;

int main()
{
    string s, t, u;
    ll a, b;

    cin >> s >> t >> a >> b >> u;

    if (s==u){
        cout << a-1 << " " << b << endl;
    } else {
        cout << a << " " << b-1 << endl;
    }
    
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++)
  {
    cin >> a[i];
  }
  vector<int> cnt(1000005);
  int ans = 0;
  for(int x: a)
  {
    if(cnt[x] != 0)
    {
      cnt[x] = 2;
      continue;
    }
    for(int i = x; i < 1000005; i +=x) cnt[i]++;//約数
  }
  for(int x:a)
  {
    if(cnt[x] == 1)
    {
      ans++;
    }
  }
  cout << ans << endl;
  return (0);
}


Measured memory_bytes: 7944
#include <algorithm>
#include <cstring>
#include <cstdio>
#define int long long

const int N = 22;

int n, a[N];
int dfs(int l, int r, int x, int y) {
	int ans = 1e18;
	if (r - l <= 1) return 0;
	for (int k = l + 1; k <= r - 1; k++)
		ans = std::min(ans, dfs(l, k, x, x + y) + dfs(k, r, x + y, y) + (x + y) * a[k]);
	return ans;
}
signed main() {
	scanf("%lld", &n);
	for (int i = 1; i <= n; i++) scanf("%lld", a + i);
	printf("%lld", a[1] + a[n] + dfs(1, n, 1, 1));
}

Measured memory_bytes: 256
#include <stdio.h>
using namespace std;
int main()
{
    int a,b;scanf("%d%d",&a,&b);
    double ret=0;
    for(int i=1;i<=a;i++)
    {
        double t=1.0/a;
        int n=i;
        while(n<b)
        {
            n*=2;t/=2;
        }
        ret+=t;
    }
    printf("%.12f\n",ret);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define out(x) cout << x << endl;
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

signed main(){
	int d,g,a[10],b[10],mi = INF;
	cin >> d >> g; g /= 100;
	for(int i = 0;i < d;i++){
		cin >> a[i] >> b[i]; b[i] /= 100;
	}
	for(int i = 0;i < (1 << d);i++){
		int sum = 0,mon = 0;
		vector<int> vec;
		for(int j = d - 1;j >= 0;j--){
			if((i >> j) & 1){
				sum += a[j] * (j + 1) + b[j];
				mon += a[j];
			}else{
				for(int k = 0;k < a[j];k++) vec.pb(j + 1);
			}
		}
		for(int v : vec){
			if(sum >= g) break;
			sum += v;
			mon++;
		}
		chmin(mi,mon);
	}
	cout << mi << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#define N 200005
using namespace std;
typedef long long ll;

ll n, nfac=1, sz[N], num[N]={0,1}, M=1e9+7;
vector<ll> gr[N];

ll pow(ll p, ll q) {
	ll re = 1;
	while(q) {
		if(q&1) re = re * p % M;
		p = p * p % M;
		q >>= 1;
	}
	return re;
}

void dfs(int u, int pr) {
	sz[u] = 1;
	for(auto v:gr[u]) {
		if(v==pr) continue;
		dfs(v, u);
		sz[u] += sz[v];
	}
	(num[1] *= sz[u]) %= M;
}

void dfs2(int u, int pr) {
	for(auto v:gr[u]) {
		if(v==pr) continue;
		num[v] = num[u] * pow(sz[v], M-2) % M * (n-sz[v]) % M;
		dfs2(v, u);
	}
}

int main() {
	ll i, t1, t2;
	cin >> n;
	for(i=0; i<n-1; i++) {
		scanf("%lld%lld", &t1, &t2);
		gr[t1].push_back(t2);
		gr[t2].push_back(t1);
	}
	for(i=2; i<=n; i++)	(nfac *= i) %= M;
	dfs(1, 0);
	dfs2(1, 0);
	for(i=1; i<=n; i++) {
		printf("%lld\n", nfac * pow(num[i], M-2) % M);
	}
	return 0;
}

Measured memory_bytes: 17776
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>

using namespace std;

struct Block {
    int weight, solidness, value;

    bool operator<(const Block& that) const {
        return solidness + weight < that.solidness + that.weight;
    }
};

int main() {
    ios::sync_with_stdio(false);

    int N; cin >> N;
    vector<Block> blocks(N);
    for (int i = 0; i < N; ++i) {
        cin >> blocks[i].weight >> blocks[i].solidness >> blocks[i].value;
    }

    sort(blocks.begin(), blocks.end());

    // dp[i][j] = from first i blocks, make a tower of total weight j
    // dp[i][j] = max(dp[i - 1][j], dp[i][j - 1], dp[i - 1][j - weight] if i j - weight < solidness)

    int max_solidness = max_element(blocks.begin(), blocks.end(), [](Block a, Block b) {
        return a.solidness < b.solidness;
    })->solidness;

    int max_weight = max_element(blocks.begin(), blocks.end(), [](Block a, Block b) {
        return a.weight < b.weight;
    })->weight;

    vector<int64_t> dp(max_solidness + max_weight + 1, 0);
    for (auto &block : blocks) {
        vector<int64_t> next(max_solidness + max_weight + 1, 0);
        for (int i = 0; i <= max_solidness + max_weight; ++i) {
            next[i] = dp[i];
            if (i > 0)
                next[i] = max(next[i], next[i - 1]);
            if (i >= block.weight && i - block.weight <= block.solidness)
                next[i] = max(next[i], dp[i - block.weight] + block.value);
        }
        dp = std::move(next);
    }

    cout << dp.back() << "\n";
}


Measured memory_bytes: 640
#include<stdio.h>
int main(){
	int i,j,n,a,b,x[105][105]={0},flag=0,y[105][105]={0};
	char c[105][105];
	scanf("%d%d",&a,&b);
	for(i=0;i<a;i++){
		scanf("%s",&c[i]);	
	}
	for(i=0;i<a;i++){
		for(j=0;j<b;j++){
			if(c[i][j]=='#'){
				flag=1;
				break;
			}
		}
		if(flag==0){
			for(j=0;j<b;j++){
				x[i][j]=1;
			}
		}
		flag=0;
	}
	for(j=0;j<b;j++){
		for(i=0;i<a;i++){
			if(c[i][j]=='#'){
				flag=1;
				break;
			}
		}
		if(flag==0){
			for(i=0;i<a;i++){
				y[i][j]=1;
			}
		}
		flag=0;
	}
	int ok=0;
	for(i=0;i<a;i++){
		for(j=0;j<b;j++){
			if(x[i][j]!=1&&y[i][j]!=1){
				printf("%c",c[i][j]);
				ok=1;
			}
		}
		if(ok==1){
			printf("\n");
		}
		ok=0;
	}
	return 0;
} 

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

# from collections import deque

def linput(_t=int):
    return list(map(_t, input().split()))

def gcd(n,m):
    while m: n,m = m, n%m
    return n

def lcm(n,m): return n*m//gcd(n,m)

def main():
    # N = int(input())
    N,K = linput()
    # vH = linput()
    # vE = [linput() for _ in [0,]*M]

    # vH = [0,] + vH
    vV = [0,] + [0,]*N

    # res = 0
    # for s in S.split("-"):
    #     res = max(res, len(s))

    for i in range(K):
        X = int(input())
        vL = linput()
        for j in vL:
            vV[j] = 1
        
    res = N - sum(vV)


    # res = 0
    print(res)

    # print(("No","Yes")[res%2])


main()


Measured memory_bytes: 9192
n = gets.to_i
b = gets.split.map(&:to_i)
a = [10**5]*n
(n-1).times do |i|
    a[i] = b[i]   if b[i] < a[i]
    a[i+1] = b[i] if b[i] < a[i+1]
end
puts a.inject(:+)

Measured memory_bytes: 1788
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>

#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
#define inf 1e18+42
#define endl "\n"
#define pi 3.1415926535897932384626433832795028841971693993751058
#define maxn 100005

#define out1(a) cout<<#a<<" "<<a<<endl
#define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define fori(it,A) for(auto it=A.begin();it!=A.end();it++)

#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define pq priority_queue
#define all(x) (x).begin(),(x).end()
#define zero(x) memset(x,0,sizeof(x));
#define ceil(a,b) (a+b-1)/b
 
using namespace std;

int binpow(int a, int b) {
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

//START OF CODE ->->->->->->->

void solve()
{
    int n,k;
    cin>>n>>k;
    vector<int> a(n);
    rep(i,0,a.size()){
        cin>>a[i];
    }
    bool f = true;
    while(k--){
        vector<int> ans(n,0);
        bool ok = true;
        rep(i,0,a.size()){
            if ( a[i] < n ){
                ok = false;
                break;
            }
        }
        if(ok){
            f = false;
            break;
        }
        rep(i,0,a.size()){
            int l = max(i-a[i],(int)0);
            int r = min(i+a[i],(int)a.size()-1);
            ans[l] += 1;
            if ( r+1 < a.size() ){
                ans[r+1] -= 1;
            }
        }
        rep(i,1,ans.size()){
            ans[i] += ans[i-1];
        }
        a = ans;
    }
    if (!f){
        rep(i,0,n){
            cout<<n<<" ";
        }
        cout<<endl;
    }
    else{
        rep(i,0,a.size()){
            cout<<a[i]<<" ";
        }
        cout<<endl;
    }
}

//END OF CODE ->->->->->->->->

signed main()
{
    fast;
    int t = 1;
    // cin>>t;

    while(t--)
    {
        solve();
    }
    return 0;
}



Measured memory_bytes: 6368
#include<iostream>
using namespace std;
int f1,f2,f3,f4;
int main(){
	
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++){
		if(s[i]=='S')f1=1;
		if(s[i]=='E')f2=1;
		if(s[i]=='N')f3=1;
		if(s[i]=='W')f4=1;
		
	}
	if(f1==f3 && f2==f4)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;

}

Measured memory_bytes: 256
#include <atcoder/dsu>
#include <bits/stdc++.h>
using namespace atcoder;
using namespace std;
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;
}
#define DEBUG
#ifdef DEBUG
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << '{';
    for(int i = 0; i < (int)v.size(); i++) {
        if(i) {
            os << ',';
        }
        os << v[i];
    }
    os << '}';
    return os;
}
void debugg() { cerr << endl; }
template <class T, class... Args>
void debugg(const T &x, const Args &... args) {
    cerr << " " << x;
    debugg(args...);
}
#define debug(...)                                                             \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debugg(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

struct Setup {
    Setup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
    }
} __Setup;

using ll = long long;
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int main() {
    int N, Q;
    cin >> N >> Q;
    dsu uf(N);
    for(int _ = 0; _ < Q; _++) {
        int t, u, v;
        cin >> t >> u >> v;
        if(t == 0) {
            uf.merge(u, v);
        } else {
            cout << uf.same(u, v) << "\n";
        }
    }
}

Measured memory_bytes: 3840
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define mod 1000000007
using ll=long long;
const int INF=1000000000;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

struct IOSetup{
    IOSetup(){
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(12);
    }
} iosetup;

template<typename T1,typename T2>
ostream &operator<<(ostream &os,const pair<T1,T2>&p){
    os<<p.first<<" "<<p.second;
    return os;
}

template<typename T>
ostream &operator<<(ostream &os,const vector<T>&v){
    for(int i=0;i<(int)v.size();i++) os<<v[i]<<(i+1==v.size()?"":" ");
    return os;
}

template<typename Monoid>
struct SegmentTree{
    using F=function<Monoid(Monoid,Monoid)>;
    int sz;
    vector<Monoid> seg;
    const F f;
    const Monoid gen;
    SegmentTree(int n,const F f,const Monoid &gen):f(f),gen(gen){
        sz=1;
        while(sz<n)sz<<=1;
        seg.assign(2*sz,gen);
    }
    void set(int k,const Monoid &x){
        seg[k+sz]=x;
    }
    void build(){
        for(int k=sz-1;k>0;k--) seg[k]=f(seg[2*k],seg[2*k+1]);
    }
    void update(int k,const Monoid &x){
        k+=sz;
        seg[k]=x;
        while(k>>=1) seg[k]=f(seg[2*k],seg[2*k+1]);
    }
   // [a,b)
    Monoid query(int a,int b){
        Monoid L=gen,R=gen;
        for(a+=sz,b+=sz;a<b;a>>=1,b>>=1){
            if(a&1) L=f(L,seg[a++]);
            if(b&1) R=f(seg[--b],R);
        }
        return f(L,R);
    }
    Monoid operator[](const int &k)const {
       return seg[k+sz];
    }
};
ll segfunc(ll a,ll b){
    return a+b;
}



using P=pair<int,int>;

signed main(){
    int n;cin>>n;
    int m=2*n;
    vector<P> v(m);
    map<P,int> id;
    rep(i,m){
        char c;int a;cin>>c>>a;a--;
        v[i]=P(a,int(c=='B'));
        id[v[i]]=i;
    }

    SegmentTree<ll> seg(m,segfunc,0);
    rep(i,m) seg.set(i,1);
    seg.build();

    vector<vector<ll>> s0(n+1,vector<ll>(n+1,0)),s1(n+1,vector<ll>(n+1,0));
    rep(i,n+1){
        rep(j,n+1){
            if(i<n)s0[i][j]=seg.query(0,id[P(i,0)]);
            if(j<n)s1[i][j]=seg.query(0,id[P(j,1)]);
            if(j<n)seg.update(id[P(j,1)],0);
        }
        rep(j,n)seg.update(id[P(j,1)],1);
        if(i<n)seg.update(id[P(i,0)],0);
    }




    vector<vector<ll>> dp(n+1,vector<ll>(n+1,LINF));
    dp[0][0]=0;
    function<ll(int,int)> DP=[&](int b,int w){
        
        if(dp[b][w]<LINF) return dp[b][w];

        if(b>0) chmin(dp[b][w],DP(b-1,w)+s0[b-1][w]);
        if(w>0) chmin(dp[b][w],DP(b,w-1)+s1[b][w-1]);
        return dp[b][w];
    };
    cout<<DP(n,n)<<endl;
    return 0;
}


/*
4
B 2
B 3
B 4
W 4
W 3
W 2
W 1
B 1
*/

Measured memory_bytes: 97984
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;

public static class P
{
    public static void Main()
    {
        try
        {
            checked
            {
                var a = Console.ReadLine().Split().Select(long.Parse).ToArray();
                var res = a.Contains(0) ? 0 : a.Aggregate(1L, (x, y) => x * y);
                if (res > 1000000000000000000) throw new Exception();
                Console.WriteLine(res);
            }
        }
        catch
        {
            Console.WriteLine(-1);
        }
    }
}


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

void imos(int **table, int x, int y, int x2, int y2){
        ++table[x][y];
        --table[x][y2];
        --table[x2][y];
        ++table[x2][y2];
}

int main(void){

        int N,K;
        std::cin >> N >> K;

        int x,y;
        char c;

        int **table = new int*[2*K+1];
        for(int i=0;i<2*K+1;i++){
                table[i] = new int[2*K+1];
                for(int j=0;j<2*K+1;j++){
                        table[i][j] = 0;
                }
        }

        while(std::cin >> x >> y>> c){
                if(c == 'W') {y = y + K; c = 'B';}
                int posx = x%(2*K);
                int posy = y%(2*K);
                if( (posx<K && posy<K) || (posx>=K && posy>=K) ){
                        int x_ = x % K, y_ = y % K;
                        imos(table, 0, 0, x_ + 1, y_ + 1);
                        imos(table, x_ + K + 1, 0, 2 * K, y_ + 1);

                        imos(table, 0, y_ + K + 1, x_ + 1, 2 * K);
                        imos(table, x_ + K + 1, y_ + K + 1, 2 * K, 2 * K);

                        imos(table, x_ + 1, y_ + 1, x_ + K + 1, y_ + K + 1);
                }else{
                        int x_ = x % K, y_ = y % K;
                        imos(table, x_ + 1, 0, x_ + K + 1, y_ + 1);
                        imos(table, x_ + 1, y_ + K + 1, x_ + K + 1, 2 * K);

                        imos(table, 0, y_ + 1, x_ + 1, y_ + K + 1);
                        imos(table, x_ + K + 1, y_ + 1, 2 * K, y_ + K + 1);
                }
        }

        for(int i=0;i<2*K;i++){
                for(int j=1;j<2*K;j++){
                        table[i][j] += table[i][j-1];
                }
        }
        for(int i=1;i<2*K;i++){
                for(int j=0;j<2*K;j++){
                        table[i][j] += table[i-1][j];
                }
        }
        int max_count = 0;

        for(int i=0;i<2*K;i++){
                for(int j=0;j<2*K;j++){
                        if(max_count < table[i][j])
                                max_count = table[i][j];
                }
        }

        std::cout << max_count << std::endl;


        return 0;

}

Measured memory_bytes: 15872