akhauriyash/Code-Regression huggingface dataset:
def check(x, y, t):
    if t[x] == -1 or t[x] == y:
        return True
    return False


n = int(input())
r = [[] for _ in range(n)]
for i in range(n):
    a = int(input())
    for _ in range(a):
        x, y = map(int, input().split())
        r[i].append([x, y])

ans = 0
for p in range(2**n):
    b = p
    cnt = 0
    t = [-1] * (n + 1)
    for i in range(n):
        honest = b & 1
        b >>= 1
        if honest:
            if check(i+1, 1 ,t):
                t[i+1] = 1
                cnt += 1
            else:
                cnt = -10**5
                continue
            for x, y in r[i]:
                if t[x] == -1 or t[x] == y:
                    t[x] = y
                else:
                    cnt = -10**5
                    break
            else:
                continue

            break
        else:
            if check(i+1, 0, t):
                t[i+1] = 0
            else:
                cnt = -10**5
    ans = max(cnt, ans)
print(ans)






Measured memory_bytes: 3064
//
//  main.cpp
//  DPn
#include <iostream>
#include <vector>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll = long long;
const ll INF=1e18;
int a[410];
ll cum[410];
bool flag[410][410]={false};
ll dp[410][410];
ll f(int l ,int r){
    if(l==r) return 0; // コストゼロ
    ll cost=0; // 累積和を使った
    if(l==0) {
        cost=cum[r];
    }else{
        cost=cum[r]-cum[l-1];
    }
    ll mn=INF;
    ll now[400]={0}; // 配列は初期化してから使う
    for (int k=l; k<r; k++) {
       if(flag[l][k]==false){
            now[k]+=f(l,k);
        }else{
            now[k]+=dp[l][k];
        }
        if(flag[k+1][r]==false){
            now[k]+=f(k+1,r);
        }else{
            now[k]+=dp[k+1][r];
        }
        mn=min(mn,now[k]);
    }
    flag[l][r]=true;
    dp[l][r]=mn+cost;
    return mn+cost;
}
int main(int argc, const char * argv[]) {
    int n;
    cin>>n;
    rep(i,n) {
        cin>>a[i]; // 入力の時についでに、累積和も求める
        if(i==0){
            cum[i]=a[i];
        } else{
            cum[i]=a[i]+cum[i-1];
        }
    }
    cout<<f(0,n-1)<<endl;
    return 0;
}


Measured memory_bytes: 5876
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fsp(x) fixed << setprecision(x)
#define xout cerr
const ll inf = LLONG_MAX;
const long double pi = acosl(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	//const ll p = 1e9 + 7;
	//const ll p = 998244353;

	ll n;
	cin >> n;
	vector<ll> a(n);
	for (ll i = 0; i < n; i++) cin >> a[i];
	for (ll i = 0; i < n; i++) {
		if (a[i] == 0) {
			cout << 0 << endl;
			return 0;
		}
	}

	long double x = 1e18;
	for (ll i = 0; i < n; i++) x /= a[i];

	if (x >= 1) {
		ll ans = 1;
		for (ll i = 0; i < n; i++) ans *= a[i];
		cout << ans << endl;
	}
	else cout << -1 << endl;
}


Measured memory_bytes: 3980
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define INF 1e9
typedef long long ll;
using namespace std;

int main() {
    int a; cin >> a;
    int alice=0,bob=0;
    vector<int> v(a);
    rep(i,a) cin >> v[i];
    sort(v.rbegin(),v.rend());
    rep(i,a){
        if(i%2==0){
            alice += v[i];
        }else{
            bob += v[i];
        }
    }
    cout << alice-bob << endl;


    return 0;
}

Measured memory_bytes: 256
object Main extends App{
  val sc = new java.util.Scanner(System.in)
  val A,B,K = sc.nextInt
  val isOK:(Int) => Boolean =(N)=>{
    A%N + B%N == 0
  }
  val OKlist = (100 until 0).filter(isOK)
  val OKList2 = List.tabulate(100){x:Int=>x+1}.filter(isOK)
  val ans = OKList2(OKList2.size-K)
  println(ans)
}


Measured memory_bytes: 25680
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)
#define setp(X,Y) cout<<fixed<<setprecision(Y)<<X;
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N;
int H[100010];
int dp[100010];

signed main(){
	cin>>N;
	REP(i,N){
		cin>>H[i];
		dp[i]=INF;
	}
	dp[0]=0;
	for(int i=0;i<N;i++){
		dp[i+2]=min(dp[i+2],dp[i]+abs(H[i]-H[i+2]));
		dp[i+1]=min(dp[i+1],dp[i]+abs(H[i]-H[i+1]));
	}
	cout<<dp[N-1]<<endl;
	return 0;
}


Measured memory_bytes: 1792
package main

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

var sc = bufio.NewScanner(os.Stdin)
var w = bufio.NewWriter(os.Stdout)

func nextInt() int {
    sc.Scan()
    i, e := strconv.Atoi(sc.Text())
    if e != nil {
        panic(e)
    }
    return i
}

func main() {
    defer w.Flush()

    t := 100

    sc.Split(bufio.ScanWords)
    x := nextInt()

    n := 0
    for t < x {
        t = int(float64(t) * 1.01)
        n++
    }

    fmt.Fprintln(w, n)
}


Measured memory_bytes: 1764
#include <algorithm>
#include <iostream>
#include <vector>
#include <sstream>
#include <map>
using namespace std;

template<typename T>
struct WeightedUnionFind {
    vector<int> data;
    vector<T> ws;
    WeightedUnionFind(int sz) : data(sz, -1), ws(sz) { }
    bool merge(int x, int y, T w) {             // ws(y) = ws(x) + w
        w += weight(x); w -= weight(y);
        if ((x = root(x)) == (y = root(y))) return false;
        if (data[x] > data[y]) swap(x, y), w = -w;
        data[x] += data[y]; data[y] = x; ws[y] = w;
        return true;
    }
    bool find(int x, int y) { return root(x) == root(y); }
    T diff(int x, int y) { return weight(y) - weight(x); }
    T weight(int t) { root(t); return ws[t]; }
    int root(int k) {
        if (data[k] < 0) return k;
        int par = root(data[k]);
        ws[k] += ws[data[k]];
        return data[k] = par;
    }
};

template<typename F, typename T>
void convert(const F &f, T &t) { stringstream ss; ss << f; ss >> t; }

int main() {
    int N;
    while (cin >> N, N) {
        bool ok = true;
        WeightedUnionFind<int> wuf(200);
        map<string, int> str2id;
        int cnt = 0;
        for (int i = 0; i < N; ++i) {
            string one, unit1, equal, val, unit2;
            cin >> one >> unit1 >> equal >> val >> unit2;
            if (!str2id.count(unit1)) str2id[unit1] = cnt++;
            int id1 = str2id[unit1];
            if (!str2id.count(unit2)) str2id[unit2] = cnt++;
            int id2 = str2id[unit2];
            int diff;
            convert(val.substr(3), diff);
            if (wuf.find(id1, id2)) {
                int curdiff = wuf.diff(id1, id2);
                if (diff != curdiff) ok = false;
            } else {
                wuf.merge(id1, id2, diff);
            }
        }
        puts(ok ? "Yes" : "No");
    }
    return 0;
}


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

#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
#define FORA(i,I) for(const auto& i:I)
#define ALL(x) x.begin(),x.end() 
#define SIZE(x) ll(x.size()) 

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

    if (N >=30){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3632
#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 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 = 2e5 + 5;
int t;

int main()
{
//	freopen("in.txt", "r", stdin);
	int x, y;
	while (cin >> x >> y)
	{
		int fg = 0;
		f(i, 0, x)
		{
			int now = i * 2 + (x - i) * 4;
			if (now== y) { fg = 1;break; }
		}
		if (fg)puts("Yes");
		else puts("No");
	}
	return 0;
}

Measured memory_bytes: 3632
<?php

$field = array();
for ($i = 0; $i < 10; $i++) {
    $field[] = array();
    for ($j = 0; $j < 10; $j++) {
        $field[$i][] = 0;
    }
}

$dx = array(
    array(1, -1, 0, 0),
    array(1, 1, -1, -1),
    array(2, -2, 0, 0),
);
$dy = array(
    array(0, 0, 1, -1),
    array(1, -1, 1, -1),
    array(0, 0, 2, -2),
);

while (TRUE) {
    fscanf(STDIN, '%d,%d,%d', $x, $y, $size);
    if (feof(STDIN)) {
        break;
    }
    drop($x, $y, $size);
}

$max = 0;
$c = 0;
for ($i = 0; $i < 10; $i++) {
    for ($j = 0; $j < 10; $j++) {
        if ($field[$i][$j] > $max) {
            $max = $field[$i][$j];
        } elseif ($field[$i][$j] === 0) {
            $c++;
        }
    }
}

echo $c . PHP_EOL;
echo $max . PHP_EOL;

function drop($x, $y, $size) {
    global $field, $dx, $dy;
    $field[$y][$x]++;
    for ($i = 0; $i < $size; $i++) {
        for($j = 0; $j < 4; $j++) {
            $nx = $x + $dx[$i][$j];
            $ny = $y + $dy[$i][$j];
            if (isset($field[$ny][$nx])) {
                $field[$ny][$nx]++;
            }
        }
    }
}

Measured memory_bytes: 6700
#
# abc128 c
#

import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """2 2
2 1 2
1 2
0 1"""
        output = """1"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """2 3
2 1 2
1 1
1 2
0 0 1"""
        output = """0"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """5 2
3 1 2 5
2 2 3
1 0"""
        output = """8"""
        self.assertIO(input, output)


def resolve():
    N, M = map(int, input().split())
    S = [list(map(int, input().split())) for _ in range(M)]
    P = list(map(int, input().split()))

    ans = 0
    for bit in range(1 << N):
        m = 0
        for i in range(M):
            t = 0
            for j in range(1, S[i][0]+1):
                if bit & (1 << (S[i][j]-1)) != 0:
                    t += 1
            if t % 2 != P[i]:
                break
            else:
                m += 1
        if m == M:
            ans += 1
    print(ans)


if __name__ == "__main__":
    # unittest.main()
    resolve()


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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; const int inf = 0x3fffffff; const ll INF = 0x3fffffffffffffff;
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; }
//template end

vector<int> g[100010]; int x[100010],y[100010]={};
bool dfs(int v){
    bitset<5010> dp; dp[0]=1; ll sum=0;
    for(int to:g[v]){
        if(!dfs(to))return 0;
        dp=(dp<<x[to])|(dp<<y[to]);
        sum+=x[to]+y[to];
    }
    rrep(i,x[v],-1)if(dp[i]){
        y[v]=sum-i; return 1;
    }return 0;
}

int main(){
    int n; scanf("%d",&n);
    rep(i,1,n){
        int p; scanf("%d",&p); p--;
        g[p].push_back(i);
    }
    rep(i,0,n)scanf("%d",&x[i]);
    printf(dfs(0)?"POSSIBLE\n":"IMPOSSIBLE\n");
    return 0;
}

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

int main(){
    vector<int> n(3);
    cin >> n[0] >> n[1] >> n[2];
    sort(n.begin(), n.end());
    cout << n[0] << " " << n[1] << " " << n[2] << endl;
    return 0;
}

Measured memory_bytes: 3148
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define fore(x, c) for(auto &&x : c)
#define rep(i, a, n) for(int i = a, i##len = (int)(n); i < i##len; ++i)
#define rrep(i, a, n) for(int i = (int)(n - 1); i >= a; --i)
#define sz(c) ((int)c.size())
#define contains(c, x) (c.find(x) != end(c))
#define inseg(l, x, r) ((l) <= (x) && (x) < (r))
#define dump(...)
#define pb push_back
#define eb emplace_back
#define _ 0
const signed INF_ = 1001001001; const long long INF = 1001001001001001001LL;
const int DX[9] = {0,1,0,-1,1,1,-1,-1,0}, DY[9] = {-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os, const vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is, vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
  is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a, const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a, const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap = priority_queue<T, deque<T>, greater<T>>;
struct before_main_function {
  before_main_function() {
      cin.tie(nullptr); ios::sync_with_stdio(0);
      cout << setprecision(15) << fixed;
  }
} before_main_function;
// clang-format on
//------------------8<------------------------------------8<--------------------

signed main() {
  int A, B, C, K;
  cin >> A >> B >> C >> K;
  if (A + B >= K) {
    if (A >= K)
      cout << K << endl;
    else
      cout << A << endl;
  } else {
    cout << A - (K - (A + B)) << endl;
  }
  return (0 ^ _ ^ 0);
}



Measured memory_bytes: 3656
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;

int N;
int A[214514];
int ans;
set<int> seps;
vector<int> es;
map<int, vector<int>> aps;

bool check(int K) {
  vector<pii> st;
  reps(i, 1, N) {
    if (A[i-1] < A[i]) continue;
    while (!st.empty() && st.back().X > A[i]) {
      st.pop_back();
    }

    int target = A[i];
    while (!st.empty()) {
      if (st.back().X < target) {
        st.eb(pii(target, 1));
        break;
      }
      
      assert(st.back().X == target);
      st.back().Y++;
      if (st.back().Y == K) {
        st.pop_back();
        target--;
      } else break;
    }

    if (st.empty()) {
      if (target >= 1) {
        st.eb(pii(target, 1));
        continue;
      }
      return false;
    }
  }
  return true;
}

int main() {
  scanf("%d", &N);
  rep(i, N) {
    scanf("%d", &A[i]);
  }
  
  int cnt = 0;
  reps(i, 1, N) {
    if (A[i-1] < A[i]) cnt++;
  }
  if (cnt == N-1) {
    puts("1");
    return 0;
  }

  int low = 1;
  int high = N+1;
  while (high - low > 1) {
    int mid = (high+low)/2;
    if (check(mid)) high = mid;
    else low = mid;
  }
  printf("%d\n", high);
}


Measured memory_bytes: 1024
#!/usr/bin/env pytho3
n = int(input())
s = input()
# D - Lucky PIN
# N桁の数字から３桁だけを残して、左から読む時何種類できるか？
# 存在しうる数字は10**3なのでそれぞれの文字に対してO(n)ならいける
# 左から順番に目的の数字が出てくるまで操作すれば良い
ans = 0
for i in range(0,1000):
    number = str(i).zfill(3)
    digit = 0
    for j in s:
        if number[digit] == j:
            digit += 1
            if digit == 3:
                ans += 1
                break

print(ans)
"""
pos = [[0 for i in range(4)] for j in range(10)] # 0..9に対して、1,2,3番目に出現するposと何回出現しているか？
#print(pos)
for i in range(n):
    #print(pos)
    current_em = pos[int(s[i])][3]
    if current_em < 3:
        pos[int(s[i])][current_em] = i
        pos[int(s[i])][3] += 1
print(pos)
current_pos = -1
ans = 0
for i in range(10):
    if len([x for x in pos[i] if x > current_pos]) == 0:break
    current_pos = min([x for x in pos[i] if x > current_pos])
    for j in range(10):
        if len([x for x in pos[j] if x > current_pos]) == 0:break
        current_pos = min([x for x in pos[j] if x > current_pos])
        for k in range(10):
            if len([x for x in pos[k] if x > current_pos]) == 0:break
            ans += 1
print(ans)"""

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

int main()
{
	string s;
	cin>>s;
	
	int n,len=s.size();
	string left,right;
	
	if(len%2==0)
	{
		left=s.substr(0,len/2);
		right=s.substr(len/2,len);
	}
	else
	{
		left=s.substr(0,(len-1)/2);
		right=s.substr((len+1)/2,len);
	}
	
	int total=0;
	
	for(int i=0; i<left.size(); i++)
	{
		if(left[i]!=right[right.size()-i-1])
		total++;
	}
	
	cout<<total<< endl;
	return 0;
}

Measured memory_bytes: 256
import copy

def can_empty(A,y,x):
    A[y][x],A[y][x+1] = A[y][x+1],A[y][x]
    num = sum(W-a.count(".") for a in A)
    while 1:
        # Fall processing
        for w in xrange(W):
            seq = ("".join(A[h][w] for h in xrange(H))).replace(".","")
            seq += "."*(H-len(seq))
            for h in xrange(H):
                A[h][w] = seq[h]

        # Banish processing
        B = [[0]*W for _ in xrange(H)]
        for h in xrange(H):
            cnt = 1
            for w in xrange(1,W):
                if A[h][w] == A[h][w-1]: cnt += 1
                else:
                    if cnt >= n and A[h][w-1] != ".":
                        for wi in xrange(w-cnt,w): B[h][wi] = 1
                    cnt = 1
            if cnt >= n and A[h][W-1] != ".":
                for wi in xrange(W-cnt,W): B[h][wi] = 1
        for w in xrange(W):
            cnt = 1
            for h in xrange(1,H):
                if A[h][w] == A[h-1][w]: cnt += 1
                else:
                    if cnt >= n and A[h-1][w] != ".":
                        for hi in xrange(h-cnt,h): B[hi][w] = 1
                    cnt = 1
            if cnt >= n and A[H-1][w] != ".":
                for hi in xrange(H-cnt,H): B[hi][w] = 1

        banish = False
        for h in xrange(H):
            for w in xrange(W):
                if B[h][w]:
                    A[h][w] = "."
                    num -= 1
                    banish = True
        if not banish: return False
        if num == 0: return True
        

# Entry point
H,W,n = map(int,raw_input().split())
_A = [list(raw_input()) for _ in xrange(H)][::-1]
goal = [["."]*W for _ in xrange(H)]
ans = False
for h in xrange(H):
    A = copy.deepcopy(_A)
    for w in xrange(W-1):
        if A[h][w] == A[h][w+1]: continue
        if can_empty(copy.deepcopy(A),h,w):
            ans = True
            break
    if ans: break
print "YES" if ans else "NO"

Measured memory_bytes: 4468
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int n = in.nextInt();
			char[] s = in.nextString().toCharArray();

			int[] e = new int[n];
			int[] w = new int[n];

			for (int i = 0; i < n; i++) {
				if (s[i] == 'E') {
					e[i]++;
				} else if (s[i] == 'W') {
					w[i]++;
				}
			}
			for (int i = 1; i < n; i++) {
				e[i] += e[i-1];
				w[i] += w[i-1];
			}

			long ans = Math.min(e[n-1]-e[0], w[n-1]);

			for (int i = 1; i < n-1; i++) {
				ans = Math.min(ans, w[i-1]+e[n-1]-e[i]);
			}

			out.println(ans);

		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

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

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

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

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

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

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}

}


Measured memory_bytes: 31316
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>

static const int MOD = 1000000007;
using ll = int64_t;
using u32 = uint32_t;
using namespace std;

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

template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }

template<class T> void chmin(T &a, const T &b){ a = (a < b ? a : b); }
template<class T> void chmax(T &a, const T &b){ a = (a > b ? a : b); }

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> v(h);
    for (auto &&i : v) cin >> i;
    ll ans = 0;
    auto O = make_v(h, w, 0); auto I = O;
    for (int i = 0; i < h; ++i) {
        for (int j = w-1; j >= 0; --j) {
            if(j != w-1) O[i][j] += O[i][j+1];
            O[i][j] += v[i][j] == 'O';
        }

    }
    for (int i = h-1; i >= 0; --i) {
        for (int j = 0; j < w; ++j) {
            if(i != h-1) I[i][j] += I[i+1][j];
            I[i][j] += v[i][j] == 'I';
        }
    }
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if(v[i][j] == 'J') ans += O[i][j] * I[i][j];
        }
    }
    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 94044
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i, s, n) for (int i = s; i < n; i++)
#define repe(i, s, n) for(int i = s;i<=n;i++)
static const ll MOD = 1e9 + 7;

int main() {
	ll n; cin >> n;
	ll b[100001] = {};
	ll a;
	rep(i, 0, n) {
		cin >> a;
		b[a]++;
	}

	ll ans = 1;
	if (n & 1) {
		rep(i, 0, n) {
			if (i == 0) {
				if (b[i] != 1) {
					cout << 0 << endl;
					return 0;
				}
			}
			else if (i & 1) {
				if (b[i] != 0) {
					cout << 0 << endl;
					return 0;
				}
			}
			else {
				if (b[i] != 2) {
					cout << 0 << endl;
					return 0;
				}
			}
		}
	}
	else {
		rep(i, 0, n) {
			if (i & 1) {
				if (b[i] != 2) {
					cout << 0 << endl;
					return 0;
				}
			}
			else {
				if (b[i] != 0) {
					cout << 0 << endl;
					return 0;
				}
			}
		}
	}

	rep(i, 0, n / 2) {
		ans = (2 * ans % MOD);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long ,long long>pll;

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

const ll mod = 1e9 + 7;
const ll MOD = 998244353;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;
const ld pi = 3.141592653589793;

 long long modpow(long long n, long long k,long long mod)
{
if (k == 0) return 1;
long long r = modpow(n * n % mod, k >> 1, mod);
if (k & 1) r = r * n % mod;
return r;
}

void solve(){
    ll n,k;cin >> n >> k;
    vector<int>L(k+1,0),R(k+1,0);
    for(int i = 1;i<=k;i++){
        cin >> L[i] >> R[i];
    }
    vector<ll>dp(n+1,0);
    vector<ll>pre(n+1,0);
    dp[1] = 1;
    pre[1] = 1;
    for(int i = 2;i<=n;i++){
        for(int j = 1;j<=k;j++){
            int l = L[j];int r = R[j];
            if(i-l<1) continue;
            dp[i] += pre[i-l]-pre[max(0,i-r-1)]+MOD;
            dp[i] %= MOD;
        }
        pre[i] = (pre[i-1]+dp[i])%MOD;
    }
    cout << dp[n];
}

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

Measured memory_bytes: 6352
//============================================================================
//Everyone has a different way of thinking, so God Created us
//   Hope You Respect My Way..,Thank You ):
// Author      : Murad
// Online Judge: Codeforces.cpp & Atcoder.cpp
// Description : Problem name
//============================================================================
#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
using namespace std;
typedef long long LL;
#define pi 3.1415926536
#define forn(i,a,b)for(int i=a;i<b;i++)
#define ULL unsigned long long
#define MP make_pair
#define ff first
#define ss second
#define endl '\n'
#define INF LL(1e18);
#define _INF INT32_MIN
#define pq priority_queue
#define MM multimap
#define PB push_back
#define EMPP emplace_back
#define vii vector<int>
#define vll vector<LL>
#define ipair pair<int,int>
#define lpair pair<LL,LL>
#define El3zba ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define modd 1000000007
#define sf1(v) scanf("%I64d",&v);
#define sf2(v1,v2) scanf("%I64d %I64d",&v1,&v2)
#define sf3(v1,v2,v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
//std::transform(s1.begin(), s1.end(), s1.begin(),::tolower);
char alphz[27] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };
float Euclidean(LL x1, LL x2, LL y1, LL y2) {
	return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
}
LL GCD(LL a,LL b) {
	return !b ? a : GCD(b, a % b);
}
LL LCM(LL a, LL b) {
	return (a*b) / GCD(a, b);
}
void PrimeFactor(LL n)
{
	while (n % 2 == 0) {
		//printf("%d ", 2);
//		aa.insert(2);
		n /= 2;
	}
	for (int i = 3; i <= sqrt(n); i += 2)
	{
		if (n%i == 0) {
			//printf("%d ", i);
			//aa.insert(i);
			n /= i;
		}
	}
	if (n > 2){
		//printf("%d ", n);
	//	aa.insert(n);
	};
}
bool Is_Square(LL x) {
	LL l = 0, r = x;
	while (l <= r) {
		LL mid = l + (r - l) / 2;
		if (mid*mid == x)return true;
		if (mid*mid > x)r = mid - 1;
		else l = mid + 1;
	}
	return false;
}
LL Power(LL x, LL y)
{
	LL temp;
	if (y == 0)return 1;
	temp = Power(x, y / 2);
	if (y % 2 == 0)
		return temp*temp;
	else return x*temp*temp;
}
bool Is_Prime(int x) {
	if (x == 2)return 1;
	else if (x % 2 == 0 || x < 2)return 0;
	for (int i = 3; i*i <= x; i += 2)
		if (x%i == 0)return 0;
	return 1;
}
int main()
{
	El3zba;
	/***  بسم الله الرحمن الرحيم   ***/
	string s;
	int k;
	cin >> s >> k;
	set<string>vi;
	int n = (int)s.size();
	for (int i = 0; i <n ; i++)
	{
		for (int j = 1; j <= 5; j++)
		{
			if (j + i > n)continue;
			else
			{
				vi.insert(s.substr(i, j));
			}
		}
	}
	for (auto&x : vi)
	{
		k--;
		if (k == 0)
			return cout << x << endl, 0;
	}
	return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <tuple>
#include <cmath>
#include <map>
#include <climits>
#include <numeric>
using namespace std;
using Int = long long;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n,m) for(int i=n;i<m;i++)
int main()
{
    int N; cin >> N;
    vector<int> A(N), B(N), C(N), S(N);
    REP(i, N) cin >> A[i];
    REP(i, N) cin >> B[i];
    REP(i, N) cin >> C[i];
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    sort(C.begin(), C.end());
    for (int i = 0, j = 0; i < N; i++) {
        while (j < N && B[i] >= C[j]) j++;
        S[i] = N - j;
    }
    Int result = 0;
    Int pats = accumulate(S.begin(), S.end(), (Int)0);
    for (int i = 0, j = 0; i < N; i++) {
        while (j < N && A[i] >= B[j]) pats -= S[j], j++;
        result += pats;
    }
    cout << result << endl;
    return 0;
}

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

const int nIMPOS = -1;
struct StDist
{
  int m_nDist;
  int m_nDmy;

  StDist(int nDist) : m_nDist(nDist), m_nDmy(0)
  { }
};

void fnInput(vector<vector<int>>& rvvnAdjcy, vector<StDist>& rvoDist)
{
  int nxSiz;
  cin >> nxSiz;

  rvvnAdjcy.resize(nxSiz + 1, vector<int>(nxSiz + 1, 0));
  for (int i = 0; i < nxSiz; ++i)
  {
    int nx, nySiz;
    cin >> nx >> nySiz;
    for (int j = 0; j < nySiz; ++j)
    {
      int ny;
      cin >> ny;
      rvvnAdjcy[nx][ny] = 1;
    }
  }
  StDist oDist(nIMPOS);
  rvoDist.resize(nxSiz + 1, oDist);
}

void fnBreadthFirstSearch(const vector<vector<int>>& cnrvvnAdjcy, 
                          queue<int>& rqnBFSrch, vector<StDist>& rvoDist)
{
  while (rqnBFSrch.size())
  {
    int nx = rqnBFSrch.front(); rqnBFSrch.pop();
    for (int ny = 1; ny < cnrvvnAdjcy[nx].size(); ++ny)
    {
      if (!cnrvvnAdjcy[nx][ny])          continue;
      if (rvoDist[ny].m_nDist != nIMPOS) continue; 

      int nDist = rvoDist[nx].m_nDist + 1;
      rvoDist[ny].m_nDist = nDist;
      rqnBFSrch.push(ny);
    }
  }
}

void fnResult(const vector<StDist>& cnrvoDist)
{
  for (int i = 1; i < cnrvoDist.size(); ++i)
    cout << i <<  " " << cnrvoDist[i].m_nDist << endl;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<vector<int>> vvnAdjcy;
  queue<int>  qnBFSrch;
  vector<StDist> voDist;

  fnInput(vvnAdjcy, voDist);

  voDist[1].m_nDist = 0;
  qnBFSrch.push(1);
  fnBreadthFirstSearch(vvnAdjcy, qnBFSrch, voDist);
  fnResult(voDist);

  return 0;
}

Measured memory_bytes: 3164
N = int(input())
A = list(map(int,input().split()))
li = [A[0]]+[0]*(N-1)
min = 10**18
for i in range(1,N):
    li[i] = li[i-1]+A[i]
for j in range(N-1):
    tmp = abs(li[j]-(li[-1]-li[j]))
    if tmp<min:
        min = tmp
print(min)

Measured memory_bytes: 24800
import java.util.*;
public class Main{
  public static void main(String [] args){
    Scanner sc = new Scanner(System.in);
    int m_count = 10, ans_count = 3;
    int[] m = new int[m_count];
    int i;
    for(i = 0;i < m_count;i++){
      m[i] = sc.nextInt();
    }
    Arrays.sort(m);
    int t = 0;
    for (i = 0; i < m_count / 2; i++){
      t = m[i];
      m[i] = m[m_count - i - 1];
      m[m_count - i - 1] = t;
    }
    for(i = 0;i < ans_count;i++){
      System.out.println(m[i]);
    }
  }
}

Measured memory_bytes: 17364
#include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>
#include<climits>
#include<cfloat>
#include<cstdio>
#define all(c) (c).begin(),(c).end()
#define curr(P,i) P[(i)%P.size()]
#define next(P,i) P[(i+1)%P.size()]
#define prev(P,i) P[(i+P.size()-1)%P.size()]


using namespace std;

typedef double Real;

Real EPS = 1e-8;
const Real PI = acos(-1);

int sgn(Real a, Real b=0){return a<b-EPS?-1:a>b+EPS?1:0;}
Real sqr(Real a){return sqrt(max(a,(Real)0));}

struct Point{  
  Real add(Real a, Real b){
    if(abs(a+b) < EPS*(abs(a)+abs(b)))return 0;
    return a+b;
  }

  Real x, y;
  Point(){}
  Point(Real x,Real y) : x(x) , y(y){}

  Point operator + (Point p){return Point(add(x,p.x), add(y,p.y));}
  Point operator - (Point p){return Point(add(x,-p.x), add(y,-p.y));}
  Point operator * (Real d){return Point(x*d,y*d);}
  Point operator / (Real d){return Point(x/d,y/d);}
  bool operator == (Point p){return !sgn(dist(p));}
  //bool operator < (Point p)const{return (p.x!=x)?x<p.x:y<p.y;}
bool operator < (Point p)const{return (p.y!=y)?y<p.y:x<p.x;}
  Real norm(){return sqr(x*x+y*y);}
  Real dist(Point a){return (*this-a).norm();}
  Real dot(Point a){return x*a.x+y*a.y;}
  Real cross(Point a){return x*a.y-y*a.x;}
  //点pを中心に角度r(radius)だけ半時計回りに回転する
  Point rotate(Real r,Point p = Point(0,0)){
    Real ta=cos(r)*(x-p.x)-sin(r)*(y-p.y)+p.x;
    Real tb=sin(r)*(x-p.x)+cos(r)*(y-p.y)+p.y;
    return Point(ta,tb);
  }
  Real arg(){
    if(sgn(x)>0)return atan(y/x);
    if(sgn(x)<0)return atan(y/x)+PI;
    if(sgn(y)>0)return PI/2;
    if(sgn(y)<0)return 3*PI/2;
    return 0;
  }
};

//a -> b -> c
int ccw(Point a, Point b, Point c) {
  b = b-a; c = c-a;

  if (b.cross(c) > 0)   return +1;       // counter clockwise
  if (b.cross(c) < 0)   return -1;       // clockwise
  if (b.dot(c) < 0)     return +2;       // c--a--b on line
  if (b.norm() < c.norm()) return -2;    // a--b--c on line
  return 0;                              // a--c--b on line
}

struct Line{
  Point a,b;

  Line(){}
  Line(Point a,Point b):a(a),b(b){}

  bool on(Point c){return abs(ccw(a,b,c))!=1;}
  Real dist(Point c){return abs((b-a).cross(c-a))/(b-a).norm();}

  //射影
  Point project(Point p){
    Point base=b-a;
    Real t=(p-a).dot(base)/base.dot(base);
    return a+base*t;
  }
};


struct Polygon{
  //頂点。反時計回りに順番で与えられていること。
  vector<Point>v;
  
  Polygon(){}
  Polygon(int n){v.resize(n);}

  vector<Point>convexHull(){
    vector<Point>v1=v;
    sort(all(v1));
    int k=0;
    vector<Point> qs(v1.size()*2);
    
    for(int i=0;i<v1.size();i++){
      while(k>1 && (qs[k-1]-qs[k-2]).cross(v1[i]-qs[k-1])<0)k--;
      qs[k++]=v1[i];
    }
    
    for(int i=v.size()-2,t=k;i>=0;i--){
      while(k>t && (qs[k-1]-qs[k-2]).cross(v1[i]-qs[k-1])<0)k--;
      qs[k++]=v1[i];
    }
    qs.resize(k-1);
    return qs;
  }
};

int main(void){

  int n;
  cin >> n;
  Polygon p(n);

  for(int i=0;i<n;i++)
    cin >> p.v[i].x >> p.v[i].y;
  
  vector<Point>res=p.convexHull();

  cout << res.size() << endl;
  for(int i=0;i<res.size();i++)
    cout << res[i].x << " " << res[i].y << endl;

  return 0;
}

Measured memory_bytes: 7272
import sys
import numpy as np
from numba import njit, void, i8
input = sys.stdin.buffer.readline

def main():
    R, C, K = map(int, input().split())

    L_INF = int(1e17)
    dp = np.full((R+1, C+1, 4), -L_INF, dtype=np.int64)
    cell = np.full((R+1, C+1), 0, dtype=np.int64)

    for i in range(K):
        x, y, c = map(int, input().split())
        cell[x-1, y-1] = c

    f(dp, cell, R, C)

    print(dp[R, C, 3])

@njit(void(i8[:,:,:],i8[:,:],i8,i8))
def f(dp, cell, R, C):
    dp[0, 1, 0] = dp[1, 0, 0] = 0
    for i in range(1, R + 1):
        for j in range(1, C + 1):
            for k in range(4):
                if k > 0:
                    dp[i, j, k] = max(dp[i, j, k], dp[i, j, k-1])
                dp[i, j, k] = max(dp[i, j, k], dp[i, j-1, k])
                if k > 0:
                    dp[i, j, k] = max(dp[i, j, k], dp[i, j-1, k-1] + cell[i-1, j-1])
                if k == 1:
                    dp[i, j, k] = max(dp[i, j, 1], dp[i-1, j, 3] + cell[i-1, j-1])

if __name__ == "__main__":
    main()


Measured memory_bytes: 463456
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define Clear(a) a = decltype(a)();
typedef long long ll;
typedef pair<int,int> p;
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
if(x<y)return x;
else return y;
}
//const ll big=998244353;
const ll big=1000000007;
ll expm(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (expm(x,y-1)*x)%big;
    ll t=expm(x,y/2);
    return (t*t)%big;
}
ll exp(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||y==0)return x;
    if(y%2==1)return exp(x,y-1)*x;
    ll t=exp(x,y/2);
    return t*t;
}
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
ll in(ll x){
    return exp(x,big-2);
}


int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(0);
    /*--------------------------------*/
    
    string s;cin >> s;
    reverse(s.begin(),s.end());
    int k=exp(2,(int)s.size()-1);
    ll ans=0;
    rep(ii,k){
        bitset<9> a(ii);
        ans+=s[0]-'0';
        ll ten=1;
        rep2(i,1,(int)s.size()){
            if(a[i-1]){
                ans+=s[i]-'0';
                ten=1;
            }
            else{
                ten*=10;
                ans+=(s[i]-'0')*ten;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ll n,a,b,sum=0;
    cin >>n >> a >>b;
        ll k=a+b;
        sum+=((n/k)*a);
         n= n%(a+b);
         if(n>=a)sum+=a;
         else sum+=n;
        cout << sum << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int mod = 1e9+7;

typedef pair<ll, ll> pairs;
typedef vector<pairs> p;

struct Edge{
    ll to, weight;
    Edge(ll t, ll w) : to(t), weight(w){}
};
using graph = vector<vector<ll>>;
using Graph = vector<vector<Edge>>;


ll gcd(ll a,ll b){
    if(b == 0){
        return a;
    }else{
        return gcd(b, a%b);
    }
}

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

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

// 回文
bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

int main(){
    ll n;
    cin>>n;
    ll ans = 0;
    for(ll i=0;i<n;++i){
        ll a;
        cin>>a;
        while(a % 2 == 0){
            a /= 2;
            ans++;
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<cmath>
#include<map>

using namespace std;

#define rep(i,N) for(int i=0;i<N;i++) //0から


typedef long long ll;




ll binary_search(vector<ll> a, ll n, ll key){
    ll right = n, left = -1;
    ll md = (right + left) / 2;

    while(right - left > 1){
        if(a[md] <= key){
            right = md;
        }else{
            left = md;
        }
        md = (right + left) / 2;
    }
    if(left == -1) return -1; //無い場合
    return right;
}

vector<ll> prime;
void Prime(ll n){ //線形篩,素数列挙
    vector<ll> p(n,0);
    p[0]=1;
    p[1]=1;
    for(ll i=2;i<n;i++){
        if(p[i]==0){
            prime.push_back(i);
            p[i]=i;
        }
        ll k=prime.size();
        for(ll j=0;j<k && i*prime[j]<n && prime[j]<=p[i];j++){
            p[i*prime[j]]=prime[j];
        }
    }
}

ll gcd(ll a,ll b){
    if(a<b){
        swap(a,b);
    }
    //a>=b
    ll r=a%b;
    while(r!=0){
        a=b;
        b=r;
        r=a%b;
    }
    return b;
}

#define MOD ((ll)1e+9 + 7)



//cout<<fixed<<setprecision(10);
int main(){
    ll n;
    cin>>n;
    vector<ll> a(n+1),b(n);
    rep(i,n+1){
        cin>>a[i];
    }
    rep(i,n){
        cin>>b[i];
    }
    ll ans=0;
    rep(i,n){
        if(a[i]>b[i]){
            ans+=b[i];
        }
        else{
            ans+=a[i];
            b[i]-=a[i];
            ans+=min(a[i+1],b[i]);
            a[i+1]-=min(a[i+1],b[i]);
        }
    }
    cout<<ans<<endl;


    return 0;
}



Measured memory_bytes: 4840
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <cctype>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
#include <iomanip>
#include <limits>

#define roop(i, n) for(int i=0;i<n;i++)
#define DIV 1000000007
//static const long double pi = 3.1415926535897932;

using namespace std;
using ll = long long int;
using ull = unsigned long long;

char toSmall(char c) { // 大文字を小文字へ
	return (c + 0x20);
}

char toLarge(char c) { // 小文字を大文字へ
	return (c - 0x20);
}

float myPower(int a, int n) { // aのn乗の計算
	float x = 1;
	while (n > 0) { // 全てのbitが捨てられるまで
		if ( n & 1) { // 一番右のbitが１のとき
			x *= a;
		}
		a *= a;
		n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
	}
	return x;
}

ll combination(ll n, ll r) { // nCr の計算
	if (n < 0 || r < 0 || r > n) return -1;

	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> num(r);
	vector<ll> den(r);

	for (ll i = 0; i < r; i++) {
		num[i] = n - r + i + 1;
		den[i] = i + 1;
	}

	for (ll p = 2; p <= r; p++) {
		ll pivot = den[p - 1];
		if (pivot > 1) {
			ll offset = (n - r) % p;
			for (ll k = p - 1; k < r; k += p) {
				num[k - offset] /= pivot;
				den[k] /= pivot;
			}
		}
	}
	ll result = 1;
	for (ll k = 0; k < r; k++) {
		if (num[k] > 1) result *= num[k];
	}
	return result;
}

vector<string> split(const string& src, const char* delim = ",") { //カンマ区切り
	vector<string> vec;
	string::size_type len = src.length();

	for (string::size_type i = 0, n; i < len; i = n + 1) {
		n = src.find_first_of(delim, i);
		if (n == string::npos) {
			n = len;
		}
		vec.push_back(src.substr(i, n - i));
	}

	return vec;
}

bool check_int(string str)
{
	if (all_of(str.cbegin(), str.cend(), [](char ch) { return isdigit(ch);}))
	{
		return true;
	}
	return false;
}

struct rest {
	string s;
	int p;
	int num;

	/* -------------------------------------
	sort関数を使用したときのソートの定義をする。
	まずは文字列sでソートする。
	文字列sが同じだった場合、pでソートする。
	この条件を参考演算子で表現(ifでもOK)
	-------------------------------------*/
	bool operator<(const rest& right) const {
		return s == right.s ? p > right.p : s < right.s;
	}
};

int main() {
	int n;
	cin >> n;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		if (i % 2 == 0 && a % 2 != 0) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <cstdio>
using namespace std;
int main(void)
{
  double xa1, ya1, xa2, ya2, xb1, yb1, xb2, yb2;
  
  while(scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&xa1, &ya1, &xa2, &ya2, &xb1, &yb1, &xb2, &yb2) != EOF) {
    
    if(xa1 <= xb2 && xb1 <= xa2 && ya1 <= yb2 && yb1 <= ya2) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 0
h, w = map(int, input().split())
s = []
for i in range(h):
	ss = input()
	s.append(ss)

dx = [1,0,-1,0]
dy = [0,1,0,-1]
ans = 0
for i in range(h):
	for j in range(w):
		if s[i][j] == "#":
			continue
		visited = [[0 for ii in range(w)] for jj in range(h) ]
		st = [[i,j]]
		visited[i][j] = 1
		while st:
			x,y = st.pop(0)
			for k in range(4):
				p = x + dx[k]
				q = y + dy[k]
				if p < 0 or q < 0 or p >= h or q >= w or s[p][q] == "#" or visited[p][q] != 0:
					continue
				st.append([p,q])
				visited[p][q] = visited[x][y] + 1
		#print (visited)
		for a in range(h):
			for b in range(w):
				ans = max(ans,visited[a][b])
print (ans-1)

Measured memory_bytes: 3188
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>
#include <cassert>
#include <random>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll conbinationMemo[100][100];

void cmemoInit(){
    rep(i, 100){
        rep(j, 100){
            conbinationMemo[i][j] = -1;
        }
    }
}
 
ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
//-----------------------ここから-----------
template<class T> T fastpow(T a, T b){
    T res = 1;
    while(b > 0){
        if(b & 1){
            res *= a;
        }
        a *= a;
        b >>= 1;
    }
    return res;
}
int main(void){
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    multiset<ll> st;
    rep(i, n) st.insert(a[i]);
    ll ans = 0;
    while(st.size() > 0){
        auto itr = st.end();
        itr--;
        //cout << *itr << endl;
        ll p = 1;
        while(p <= *itr) p *= 2;
        auto itr2 = st.find(p - *itr);
        if(itr2 != st.end() && !(itr2 == itr && st.count(*itr) < 2)){
            st.erase(itr2);
            ans++;
        }
        st.erase(itr);
    }
    cout << ans << endl;
}

Measured memory_bytes: 14036