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

int main() {
    long a;
    string key[4] = {"AC", "WA", "TLE", "RE"};
    long res[4] = {0,0,0,0};
    cin >> a;
    for(long i = 0; i < a; i++ ) {
        string in;
        cin >> in;
        if(in == "AC") res[0]++;
        else if(in == "WA") res[1]++;
        else if(in == "TLE") res[2]++;
        else if(in == "RE") res[3]++;
    }
    for(int i = 0; i < 4; i++) {
        cout << key[i] << " x " << res[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define mod 1000000000000000000
 
using namespace std;
 
typedef long long ll;
typedef vector <int> vi;
typedef vector <ll> vl;
typedef pair <ll, ll> dl;
typedef pair <int, int> ii;
typedef vector <ii> vii;
typedef vector <vii> graph;
 
bool comp(int a, int b) {
	return a > b;
}
 
int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
 
	int n;
	cin >> n;
	ll p = 1;
	ll arr[n];
	ll in;
	for (int i = 0; i < n; i++) {
		cin >> in;
		arr[i] = in;
	}
	sort(arr, arr + n);
	for (int i = 0; i < n; i++) {
		if (p == 0) break;
		if (arr[i] > (mod / p)) {
			cout << -1 << "\n";
			return 0;
		}
		p *= arr[i];
	}
	cout << p << "\n";
	return 0;
}

Measured memory_bytes: 4404
#400
N,K = map(int,input().split())
p = list(map(int,input().split()))
q = [0 for _ in range(N)]

for i in range(N):
    q[i] = (1+p[i])/2

S = sum(q[0:K])
Smax = S
for i in range(N-K):
    S = S - q[i] + q[K+i]
    if S > Smax:
        Smax = S

print(Smax)

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

int main() {
  int N,ans=0;
  cin >> N;
  vector<int> vec(N);
  for(int i=0; i<N; i++) {
    cin >> vec[i];
  }
  while(true) {
    for(int i=0; i<N; i++) {
      if(vec[i]%2!=0) {
        cout << ans << endl;
        return 0;
      }
      else {
        vec[i]/=2;
      }
    }
    ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<utility>
#include<vector>
using namespace std;
class Operation {
  public:
    std::pair<int, int> from;
    std::pair<int, int> to;
    Operation(std::pair<int, int> from, std::pair<int, int> to);
};
 
class  Answer {
  public:
    int n;
    std::vector<Operation> operations;
    Answer(int n, std::vector<Operation> operations);
};
 
Operation::Operation(pair<int, int> f, pair<int, int> t) {
  from = f;
  to = t;
}
 
Answer::Answer(int nn, vector<Operation> ops) {
  n = nn;
  operations = ops;
}
 
Answer make_them_even(int h, int w, vector<vector<int>> a) {
  vector<Operation> ops;
  bool left_to_right = true;
  int c = 0, r = 0;
  while(true) {
    //cout << "c: " << c << " r: " << r << endl;
    if(c == w-1 && r==h-1 && left_to_right == true) {
      break;
    }
    if(c==0 && r==h-1 && left_to_right == false) {
      break;
    }
    if(left_to_right) {
      if(c<w-1) {
	if(a[r][c] % 2 == 1) {  
	  a[r][c] -= 1;		  	  	  
	  a[r][c+1] += 1;  
	  Operation o = Operation(make_pair(r+1, c+1), make_pair(r+1, c+1+1));
	  ops.push_back(o);
	}
	c++;
	continue;
      }
      if(a[r][c] % 2 == 1) {
	a[r][c] -= 1;
	a[r+1][c] += 1;
	Operation o = Operation(make_pair(r+1, c+1), make_pair(r+1+1, c+1));
	ops.push_back(o);
      }
      left_to_right = false;
      r++;
      continue;      
    }
    if(c > 0) {
      if(a[r][c] % 2 == 1) {
	a[r][c] -= 1;
	a[r][c-1] += 1;
	Operation o = Operation(make_pair(r+1, c+1), make_pair(r+1, c-1+1));
	ops.push_back(o);
      }
      c--;
      continue;
    }
    if(r < h-1) {
      if(a[r][c] % 2 == 1) {
	a[r][c] -= 1;
	a[r+1][c] += 1;
	Operation o = Operation(make_pair(r+1, c+1), make_pair(r+1+1, c+1));
	ops.push_back(o);
      }
      left_to_right = true;
      r++;
    }
  }
 
  Answer answer(ops.size(), ops);
  return answer;
}
 
int main() {
  int h, w;
  cin >> h;
  cin >> w;
  vector<vector<int>> a;
  for(int i=0;i<h;i++) {
    vector<int> aa;
    for(int j=0;j<w;j++) {
      int b;
      cin >> b;
      aa.push_back(b);
    }
    a.push_back(aa);
  }
  Answer answer = make_them_even(h, w, a);
  //cout << "#####" << endl;
  cout << answer.n << endl;
  vector<Operation> ops = answer.operations;
  for(int i=0;i<ops.size();i++) {
    cout << ops[i].from.first << " " << ops[i].from.second << " " << ops[i].to.first << " " << ops[i].to.second << endl;;
  }
}

Measured memory_bytes: 8872
#include <iostream>
#include <queue>
#include <vector>
#include <climits>
#include <algorithm>
using namespace std;

/*
 * union-find???????£??????\???????????????
 */
#define MAX_V 10001

typedef struct UF{
    int parent;
}UF;

UF uf[MAX_V + 1];

/*
 * ?????????idx???parent??¨???????????????????¨??????????
 */
void initialize(int num){
    int i ;
    
    for (i=1; i <= num; i++) {
        uf[i].parent = i;
    }
}
/*
 * ??????????±?????????°????????????????????????
 */
int find(int a){
    
    if (a == uf[a].parent) {
        return a;
    }
    
    return uf[a].parent = find(uf[a].parent);
}

int isSame(int a, int b){
    
    if (find(a) == find(b)) {
        return 1;
    }
    else{
        return 0;
    }
}

void unite(int a, int b){
    a = find(a);
    b = find(b);
    
    if (a == b) {
        return;
    }
    
    uf[b].parent = a;
    
}

/*
 * ??\??????Kruskal??????????????°??????(??????????????\????????¨??????????£?)
 * ?¢???????????????????X?????????????????¢???????????????X???????????????????????¨??§????°???¨?????¨????±???????
 */

#define MAX_V 10001
#define MAX_E 100001
#define INF INT_MAX

typedef struct edge{
    int from;
    int to;
    int cost;
}edge;

edge es[MAX_E];

// cost?????????????????¢??°
bool cmp(const edge& e1, const edge& e2){
    return e1.cost < e2.cost;
}

/*
 * e:???????????°
 * v:?????????????????°
 */
int Kruskal(int e, int v){
    
    int res = 0;
    
    //?????????????????????????????????
    sort(es, es + e, cmp);
    
    //union-find????????????
    initialize(v);
    
    for (int i = 0; i< e; i++) {
        edge e = es[i];
        if (!isSame(e.from, e.to)) {
            unite(e.from, e.to);
            res += e.cost;
        }
    }
    
    return res;
}

int main( ){
    
    int i, V, E, u, v, c, ans;
    cin >> V >> E;

    for (i = 0; i < E; i++) {
        cin >> u >> v >> c;
        es[i].from = u;
        es[i].to = v;
        es[i].cost = c;
    }
    
    ans = Kruskal(E, V);
    
    cout << ans << endl;
    
    
    return 0;
}

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

using namespace std;
typedef long long ll;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define INF (ll)2e9
#define MOD ((ll)1e9+7)
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((int)(x).size())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define bit(n) (1LL<<(n))

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

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

template<class InputIterator>
InputIterator adv(InputIterator x, typename std::iterator_traits<InputIterator>::difference_type n) {
    advance(x, n);
    return x;
}

class mod {
    static ll fact[];
public:

    template<class... A>
    static ll mul(A... args) {
        ll res = 1;
        for (ll i : std::initializer_list < ll > {args...}) {
            res = (res * i) % MOD;
        }
        return res;
    }

    static ll power(ll base, ll exp) {
        if (exp == 0) return 1;
        if (exp & 1) {
            return mul(base, power(base, exp - 1));
        } else {
            ll p = power(base, exp / 2);
            return mul(p, p);
        }
    }

    static ll factorial(int n) {
        if (fact[n] != 0) return fact[n];
        if (n == 0) return 1;
        return fact[n] = mul(n, factorial(n - 1));
    }

    static ll inverse(int n) {
        return power(n, MOD - 2);
    }

    static ll comb(int n, int r) {
        if (r < 0 || r > n) return 0;
        return mul(factorial(n), inverse(factorial(n - r)), inverse(factorial(r)));
    }

    template<class... A>
    static ll div(ll dividend, A... args) {
        ll res = dividend;
        for (ll i : std::initializer_list < ll > {args...}) {
            res = mul(res, inverse(i));
        }
        return res;
    }

    template<class... A>
    static ll add(A... args) {
        ll res = 0;
        for (ll i : std::initializer_list < ll > {args...}) {
            res = (res + i) % MOD;
        }
        return res;
    }

    template<class... A>
    static ll sub(ll l, A... args) {
        ll res = l;
        for (ll i : std::initializer_list < ll > {args...}) {
            res = (res - i + MOD) % MOD;
        }
        return res;
    }
};

ll mod::fact[(int) 1e6 + 1];

int ni() {
    int i;
    cin >> i;
    return i;
}

ll nll() {
    ll l;
    cin >> l;
    return l;
}

int main() {
    string s;
    cin >> s;
    int N = s.length();

    string words[] = {"dream", "dreamer", "erase", "eraser"};

    REPR(i, N-1) {
        REP(j, 4) {
            if (s.substr(i, s.length()) == words[j]) {
                s.erase(s.end()-words[j].length(), s.end());
                break;
            }
        }
    }

    cout << (s == "" ? "YES" : "NO") << endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, llint> P;

llint n, k;
bool used[105];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> k;
	llint d, a;
	for(int i = 1; i <= k; i++){
		cin >> d;
		for(int j = 0; j < d; j++){
			cin >> a;
			used[a] = true;
		}
	}
	
	llint ans = 0;
	for(int i = 1; i <= n; i++) if(!used[i]) ans++;
	cout << ans << endl;
	
	return 0;
}

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

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

typedef long long ll;
const ll MOD = 1e9 + 7;
const int MAX_N = 1e5;

int main() {
  int N;
  ll A[MAX_N], B[MAX_N];
  std::cin >> N;
  rep(i, N) std::cin >> A[i] >> B[i];

  ll ans = 0;
  ll cnt = 0;
  rep(i_, N) {
    int i = N - 1 - i_;
    A[i] += cnt;
    if(A[i] % B[i] != 0) {
      ans += B[i] - A[i] % B[i];
      cnt += B[i] - A[i] % B[i];
    }
  }
  std::cout << ans << '\n';
}


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

int _=[](){
    cin.tie(NULL);
    ios::sync_with_stdio(false);
    return 0;
}();

int main()
{
    int n,k;
    cin>>n;
    cin>>k;
    vector<int> si,damn;
    
    for(int i=0;i<n;i++)
    {
        int h;
        cin>>h;
        si.push_back(h);
    }
    damn.push_back(0);
    damn.push_back(abs(si[0]-si[1]));
    
    for(int i=2;i<n;i++)
    {
        int min_value=INT_MAX;
        for(int j= max(0,i-k);j<i;j++)
        {
            int x = damn[j] + abs(si[i]-si[j]);
            if(x<min_value)
                min_value=x;
        }
        damn.push_back(min_value);
    }
    
    cout<<damn[damn.size()-1]<<endl;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>

#define rep_ui(k,n)      for(ui  i = (k); i < (n); ++i)
#define rep_si(k,n)      for(int i = (k); i < (n); ++i)
#define rep_ul(k,n)      for(ul  i = (k); i < (n); ++i)
#define rep_sl(k,n)      for(ll  i = (k); i < (n); ++i)
#define rep_ui_down(k,n) for(ui  i = (k); i > (n); --i)
#define rep_si_down(k,n) for(int i = (k); i > (n); --i)
#define rep_ul_down(k,n) for(ul  i = (k); i > (n); --i)
#define rep_sl_down(k,n) for(ll  i = (k); i > (n); --i)

#define rep_uj(k,n)      for(ui  j = (k); j < (n); ++j)
#define rep_sj(k,n)      for(int j = (k); j < (n); ++j)
#define rep_uj_down(k,n) for(ui  j = (k); j > (n); --j)
#define rep_sj_down(k,n) for(int j = (k); j > (n); --j)

#define rep(k,n)         rep_ui(k,n)

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

template<class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vc)
{
  boost::for_each(vc, [&os, &vc](T value) {
    os << value;
    if (value != vc.back())
      os << ' ';
    });
  return os;
}

template<class T1, class T2>
inline
std::ostream&
operator<<(std::ostream& os, const std::pair<T1, T2>& p)
{
  return os << p.first << ' ' << p.second;
}

void solve(void)
{
  ui N{}; std::cin >> N;

  typedef std::vector<ui> Vector;
  Vector vc(N);
  rep(0, N) std::cin >> vc[i];

  Vector sorted{ vc };
  boost::sort(sorted);
  ui ans{ 0 };
  rep(0, N)
  {
    if (vc[i] != sorted[i])
      ++ans;
  }

  std::cout << (ans <= 2U ? "YES" : "NO") << '\n';

  return;
}

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}


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

def is_ok(k):
    length = 0
    mem = {}
    for a in A:
        if a > length:
            length = a
            continue
        dels = []
        for b in mem.keys():
            if b > a:
                dels.append(b)
        while a > 0:
            if a in mem and mem[a] >= k-1:
                dels.append(a)
            else:
                break
            a -= 1
        if a in mem:
            mem[a] += 1
        else:
            mem[a] = 1
        if a == 0 or mem[a] >= k:
            return False
        length = a
        for b in dels:
            del mem[b]
    return True

ng = 0
ok = N
while ok-ng > 1:
    m = (ok+ng+1)//2
    if is_ok(m):
        ok = m
    else:
        ng = m
print(ok)

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

int main(int argc, char **argv)
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);

#ifndef ONLINE_JUDGE
   // freopen("in.txt", "r", stdin);
#endif

   int n, k;
   cin >> n >> k;
   cout << (n % k != 0) << '\n';
   return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
#define DBG(X) cout << #X << "=" << (X) << '\n';
#define SAY(X) cout << (X) << '\n';
#else
#define DBG(X)
#define SAY(X)
#endif

#define M_PI       3.14159265358979323846

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

std::string pad(int num)
{
    char buffer[4];
    std::snprintf(buffer, sizeof(buffer), "%03d", num);
    return buffer;
}

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif

struct Hashing {
    ull seed, mod;
    vector <ull> hs, pw;

    Hashing(ull seed = 31, ull mod = 1000173169) :
        seed(seed),
        mod(mod) {}

    void build(int n, const string& s) {
        hs.assign(n + 1, 0);
        pw.assign(n + 1, 1);
        pw[0] = 1;

        for (int i = 1; i <= n; ++i)
            pw[i] = pw[i - 1] * seed % mod;
        for (int i = 1; i <= n; ++i)
            hs[i] = (hs[i - 1] * seed + s[i]) % mod;
    }

    ull hash(int l, int r) {
        return (hs[r] - hs[l - 1] * pw[r - l + 1] % mod + mod) % mod;
    }
};

int solve()
{
    int a, b, c;

    std::cin >> a >> b >> c;

    if ((a == b && b != c) || (a == c && b != c) || (b == c && a != b))
        cout << "Yes" << endl;
    else
        cout << "No" << endl; 

   
    return 0;
}

int main()
{
    solve();

    return 0;
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

struct Person{
  ll id,d;
  vector<ll> friends;
};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,m;
  while(cin >> n >> m && n && m){
    vector<ll> p[n+1];
    ll a, b;
    rep(i,m){
      cin >> a >> b;
      p[a].pb(b);
      p[b].pb(a);
    }
    set<ll> s;
    s.insert(1);
    rep(i,p[1].size()){
      s.insert(p[1][i]);
      for(auto N : p[p[1][i]]){
        s.insert(N);
      }
    }
    cout << s.size()-1<<endl;
  }
  return 0;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<string,int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;


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

    int n;
    cin >> n;
    vector<int> v(3*n);
    rep(i, n*3){
        cin >> v[i];
    }
    sort(all(v), greater<int>());

    ll ans = 0;
    for (int i = 0; i < 2*n; ++i) {
        if(i % 2 == 1){
            ans += v[i];
        }
    }


    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1408
import java.util.*;


public class Main {
    public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String text = sc.next().toUpperCase();
		int cnt = 0;
		while (true) {
		    String s = sc.next();
		    if ("END_OF_TEXT".equals(s)) {
		        break;
		    } 
		    if (text.equals(s.toUpperCase())) {
		        cnt++;
		    }
		}
		
        
		System.out.println(cnt);
		
    }
}




Measured memory_bytes: 26372
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

void end(){
  cout << "WA" << endl;
  exit(0);
}

int main(){
  str s;
  cin >> s;
  ll n = s.length();
  if(s[0]!='A') end();
  ll cnt = 0;
  REP(i,n){
    if(i>=2&&i<=n-2&&s[i]=='C'){
      cnt++;
    }else if(s[i]<'a'||s[i]>'z'){
      if(s[i]!='A'||i!=0){
        end();
      }
    }
  }
  if(cnt!=1){
    end();
  }else{
    cout << "AC" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
s = input()
n = len(s)

i = 0
is_r = True
rl_list = []
r, l = 0, 0
idx = None
for i in range(n):
  if s[i] == 'R':
    if not is_r:
      rl_list.append((r, l, idx))
      is_r = True
      r, l = 0, 0
    r += 1
  else:
    if is_r:
      is_r = False
      idx = i - 1
    l += 1
rl_list.append((r, l, idx))
children = [0] * n
for r, l, idx in rl_list:
  children[idx] = (r + 1) // 2 + l // 2
  children[idx + 1] = r // 2 + (l + 1) // 2
print(' '.join(map(str, children)))

Measured memory_bytes: 16096
#include<iostream>
#include<cmath>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int a,b,c,d,l;
	cin>>l>>a>>b>>c>>d;
	int la=a/c,ma=b/d;
	if(a%c!=0)la++;
	if(b%d!=0)ma++;
	cout<<l-max(la,ma)<<endl;
	return 0;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define MOD 1000000007
#define el endl
typedef long long ll;
typedef long double ld;

int main() {
    ll n, ans = 0;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(), a.end());
    
    ll sum = 0;
    int t = 0;
    rep(i, n-1){
        sum += a[i];
        if(2 * sum < a[i+1]) t = i+1;
    }
    ans = n - t;
    cout << ans << endl;
}


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

int main(){
	int n;
	cin >> n;
	for(int r=0; r<n; r++){
		string s;
		cin >> s;
		sort(s.begin(), s.end());
		int a=0,b=0;
		for(int i=0; i<8; i++){
			a = a*10 +s[i];
			b = b*10 +s[7-i];
		}
		cout << b-a << endl;
	}
	return 0;
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	int n, ans = 0;
	cin >> n;
	for (int i = 1; i <= n; i += 2)
	{
		int way = 0;
		for (int j = 1; j <= n; ++j)
		{
			way += (i % j == 0);
		}
		ans += (way == 8);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
tot = 0
for i in range(n):
    if a[i]+a[i+1] <= b[i]:
        tot += a[i]+a[i+1]
        a[i+1] = 0
    else:
        tot += b[i]
        a[i+1] = max(0, a[i+1] - max(0, b[i]-a[i]))

print(tot)



Measured memory_bytes: 19116
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<random>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
typedef vector<vt>vvt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

int gcd(int a,int b){
	if(!b)return a;
	return gcd(b,a%b);
}
int MOD=1000000007;
ll powmod(ll a,ll b,ll m=MOD){
	ll out=1;
	ll p=a%m;
	while(b){
		if(b&1)out=out*p%m;
		p=p*p%m;
		b>>=1;
	}
	return out;
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	map<pii,int>ma;
	int n;
	cin>>n;
	int c=0;
	rep(i,n){
		int a,b;
		cin>>a>>b;
		int g=gcd(abs(a),abs(b));
		if(b<0||a<0&&b==0)a*=-1,b*=-1;
		if(g==0)c++;
		else ma[{a/g,b/g}]++;
	}
	int out=1;
	for(auto it:ma){
		pii p=it.first;
		int t=(powmod(2,it.second))%MOD;
		if(ma.count({p.second,-p.first})){
			(t+=powmod(2,ma[{p.second,-p.first}])+MOD-1)%=MOD;
			ma[{p.second,-p.first}]=0;
		}
		(out*=t)%=MOD;
	}
	cout<<(out+MOD-1+c)%MOD<<endl;
}


Measured memory_bytes: 15916
n,k=map(int,input().split())
a=list(map(int,input().split()))
ans,l=0,0
for i in range(40)[::-1]:
  b=1<<i
  c=sum(bool(x&b) for x in a)
  if l+b<=k and c<n-c:
    l+=b
    ans+=b*(n-c)
  else:
    ans+=b*c
print(ans)


Measured memory_bytes: 14240
#include <stdio.h>
#define max 100000
#define NIL -1

typedef struct{
  int parent;
  int left;
  int right;
}node;

node T[max];
int n,D[max];

void print(int);
void rec(int, int);

int main(){
  int i,j,k,d,v,c,l,r,id;
  scanf("%d",&n);
  
  
  for(i=0;i<n;i++){
    T[i].parent = NIL;
    T[i].left = NIL;
    T[i].right = NIL;
  }
  for(i=0;i<n;i++){
   
    scanf("%d",&id);
    scanf("%d",&k);

    for(j=0;j<k;j++){
      scanf("%d",&c);
      if(j==0){
	T[id].left = c;
      }
      else T[l].right = c;
      l = c;
      T[c].parent = id;
    }
  }
 
  for(i = 0; i<n; i++){
    if(T[i].parent == NIL) r=i;
  }
  
  rec(r, 0);
  for(i=0;i<n;i++) print(i);
  
}

void print(int u){
  int i,c;
  printf("node %d: parent = %d, depth = %d, ",u,T[u].parent,D[u]);
  if(T[u].parent==NIL) printf("root, ");
  else if(T[u].left == NIL) printf("leaf, ");
  else printf("internal node, ");

  printf("[");
  for(i=0, c = T[u].left ;;i++){
    if(c!=NIL){printf("%d",c);
      c = T[c].right;
    }
    if(c == NIL) break;
    printf(", ");
  }
  printf("]\n");
}

void rec(int u,int p){
  D[u] = p;
  if(T[u].right != NIL) rec(T[u].right,p);
  if(T[u].left != NIL) rec(T[u].left,p+1);
}



Measured memory_bytes: 6536
import java.util.Scanner;

public class Main {
	public static void main(String arg[]) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		double a[] = new double[n];
		double s = 0;

		for (int i = 0; i < n; i++) {
			a[i] = 1 / sc.nextDouble();
			s += a[i];
		}
		sc.close();
		System.out.println(1 / s);
	}
}

Measured memory_bytes: 22228
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<math.h>
#include<cmath>
#include<string.h>
#include<algorithm>
#include<time.h>
#include<stdio.h>
using namespace std;
const int N=1100;

int main()
{
   int a,b,c,k;
   cin>>a>>b>>c>>k;
   int sum=0;
   for(;;){
    if(b<=a){
        b*=2;
        sum++;
    }
    else {
        break;
    }
    if(sum>k){
            break;
        }
   }
   for(;;){

    if(b>=c){
        c*=2;
        sum++;
    }
    else {
        break;
    }
    if(sum>k){
            break;
        }
   }
   if(sum>k){
    cout<<"No"<<endl;
   }
   else {
    cout<<"Yes"<<endl;
   }
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    
    printf("%.10f\n", (n + (n % 2)) / (2.0 * n));
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 using namespace std;
 #define rep(i,N) for(int i=0;i<int(N);++i)
 using ll = long long;
 const int INF = 2147483647;
 const ll MOD = 1000000007;
 // const ll INF = 1000000000000000000LL;
 
 ll modpow(ll x, ll n) {
     ll res = 1;
     while (n > 0) {
         if (n & 1) {  // nが奇数のとき
             res *= x;
             res %= MOD;
         }
         x *= x;
         x %= MOD;
         n >>= 1;
     }
     return res;
 }

 int main() {
   ll n,a,b;
   cin >> n >> a >> b;
   ll all = modpow(2,n);
   //aの分子
   ll a_u = 1;
   for(int i=1;i<=a;i++){
     a_u *= i;
     a_u %= MOD;
   }
   ll a_d = 1;
   //aの分母
   for(int i=0;i<a;i++){
     a_d *= n-i;
     a_d %= MOD;
   }
  //bの分子
   ll b_u = 1;
   for(int i=1;i<=b;i++){
     b_u *= i;
     b_u %= MOD;
   }
   ll b_d = 1;
   //bの分母
   for(int i=0;i<b;i++){
     b_d *= n-i;
     b_d %= MOD;
   }
   ll com_a,com_b;
   com_a = a_d * modpow(a_u,MOD-2) % MOD;
   com_b = b_d * modpow(b_u,MOD-2) % MOD;
   ll ans = all - com_a - com_b - 1;
   while(ans<0){
    ans+=MOD;
   }
  cout << ans << endl;
 }

Measured memory_bytes: 3632
N = int(input())
S = list(str(input()))

num2alpha = lambda c: chr(c+64)
#print(num2aipha(3))

alpha2num = lambda c: ord(c) - ord("A") + 1
#print(alpha2num("Y"))

#英文字を数字に変換
for i in range(len(S)):
    S[i] = alpha2num(S[i]) 

#数字を指示された分加算
def calc(n):
    return n + N 

S2 = list(map(calc, S))
#print(S2)

#数字から英文字に戻す
for j in range(len(S)):
    S2[j] = S2[j] % 26
    if S2[j] == 0:
        S2[j] = 26
    S2[j] = num2alpha(S2[j])
#print(S2)

#リストからつなげた文字列に変換
S3 = "".join(S2)
print(S3)






Measured memory_bytes: 3188
import numpy as np


def main():
    sx, sy, tx, ty = map(int, input().split())

    w = tx - sx
    h = ty - sy

    out = ''
    # s
    for _ in range(h):
        out += 'U'
    for _ in range(w):
        out += 'R'
    # t
    for _ in range(h):
        out += 'D'
    for _ in range(w):
        out += 'L'
    # s
    out += 'L'
    for _ in range(h+1):
        out += 'U'
    for _ in range(w+1):
        out += 'R'
    out += 'D'
    # t
    out += 'R'
    for _ in range(h+1):
        out += 'D'
    for _ in range(w+1):
        out += 'L'
    out += 'U'

    print(out)
 



if __name__ == '__main__':
    main()


Measured memory_bytes: 18736
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 100000000
#define rep(i,s,n) for (int i = (int)(s); i < (int)(n); i++)
#define repp(i,n,s) for (int i= (int)(n); i >= (int)(s); i--)
#define mp make_pair
ll mod = 1000000007;
ll mod2 = 998244353;

int main(){
	cin.tie(0);
    ios::sync_with_stdio(false);
    string s;cin>>s;
    s += "R";
    int n = s.size();
    vector<int> li(n),ans(n);
    int j = 1,f = 1,t = 0;
    char x = s[0];
    rep(i,1,n){
        if (x!=s[i]){
            if (f==1){
                rep(k,i-j,i){
                    li[k] = (i-k)*f;
                }
            }else{
                rep(k,i-j,i){
                    li[k] = (k-t)*f;
                }
            }
            t = i-1;
            f*=(-1);
            x = s[i];
            j = 1;
        }else{
            j++;
        }
    }
    rep(i,0,n-1){
        if (li[i]%2==0){
            ans[i+li[i]]++;
        }else{
            if (li[i]>0){
                ans[i+li[i]-1]++;
            }else{
                ans[i+li[i]+1]++;
            }
        }
    }
    rep(i,0,n-1){
        cout<<ans[i]<<endl;
    }
}

Measured memory_bytes: 4268
#include<stdio.h>
int main (void)
{
  int i,a,b;
char c[101][101];
  scanf("%d%d",&a,&b);
  for(i=0;i<a;i++)
    scanf("%s",&c[i]);
  for(i=0;i<a;i++)
    printf("%s\n%s\n",c[i],c[i]);
    
    return 0;
  
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
int main(){
    int n;
    signed int l;
    cin >> n >> l;
    vector<int> vec(n);
    int taste = 0;
    for(int i=0; i<n; i++) vec[i] = i + l;
    signed int mini = 101;
    int num =0;
    
    for(int i=0; i<n; i++){
        taste += vec[i];
        mini = min(mini, abs(vec[i]));
        if(mini == abs(vec[i])) num = i;
    }

    cout << taste - vec[num] << endl;
}

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

int R[5000],G[5000],B[5000];
char S[5000];
int main(){
    ll r=0,g=0,b=0,i,j,N;
    ll ans;
    scanf("%lld\n",&N);
    for(i=0;i<N;i++){
        scanf("%c",&S[i]);
        if(S[i]=='R') R[r++]=i;
        else if(S[i]=='G') G[g++]=i;
        else B[b++]=i;
    }
    //cout<<r<<' '<<g<<' '<<b<<endl;
    ans=r*g*b;
    for(i=0;i<r;i++){
        for(j=0;j<g;j++){
            int d=abs(G[j]-R[i]);
            int mi=min(G[j],R[i]),ma=max(G[j],R[i]);
            if(mi-d>=0&&S[mi-d]=='B') ans--;
            if(ma+d<N&&S[ma+d]=='B') ans--;
            if((mi+ma)%2==0&&S[mi+d/2]=='B') ans--;
        }//cout<<R[i]<<G[j]<<endl;
    }
    printf("%lld",ans);
}


Measured memory_bytes: 3840
def main():
    from bisect import bisect_left
    import sys
    sys.setrecursionlimit(10 ** 7)
    input = sys.stdin.readline

    inf = 1 << 30

    N = int(input())
    *a, = map(int, input().split())

    g = tuple(set() for _ in range(N))
    for _ in range(N - 1):
        u, v = (int(x) - 1 for x in input().split())
        g[u].add(v)
        g[v].add(u)

    ans = [0] * N
    lis = [inf] * N

    def dfs(v, p=-1):
        i = bisect_left(lis, a[v])
        prev_at_i = lis[i]
        lis[i] = a[v]
        ans[v] = bisect_left(lis, inf)
        for u in g[v]:
            if p == u: continue
            dfs(u, v)
        lis[i] = prev_at_i

    dfs(0)

    print(*ans, sep='\n')


if __name__ == '__main__':
    main()

# dp[i]=長さiの増加部分列の末尾としてありえる最小値
# というテーブルを持っておいて、数列を列を前から見ながら二分探索で更新箇所を探す


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

int main() {
  int n; 
  cin >> n;
  if(n%2 == 0) cout << n << endl;
  else cout << 2*n << endl;
  
  
  return 0;
}


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

using namespace std;

void c(){
    int n;
    cin >> n;
    map<int, int> a;
    for(int i = 0; i < n; i++)
    {
        int temp;
        cin >> temp;
        if(a.count(temp))
        {
            a[temp]++;
        }else{
            a[temp] = 1;
        }
    }
    int count = 0;
    for(auto elem : a) {
        if (elem.first != elem.second) {
            if (elem.first > elem.second) {
                count += elem.second;
            } else {
                count += elem.second - elem.first;
            }
        }
    }
    cout << count << endl;
}

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


Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
const int IINF = INT_MAX;
#define REP(i, n) for (int i = 0; i < n; i++)

int main() {
    int n, p[5005], a[5005], ans = IINF;
    cin >> n;
    REP(i,n){
        cin >> p[i];
    }
    for(int k=0;k<=p[0];k++){
        int cnt = 0;
        REP(i,n){
            a[i] = p[i];
        }
        cnt += k;
        a[0] -= k;
        for(int i=0;i<n-1;i++){
            cnt += a[i]*2;
            a[i+1] = max(0, a[i+1]-a[i]);
        }
        cnt += a[n-1];
        ans = min(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3144
import heapq


def solve(string):
    n, m, *ab = map(int, string.split())
    ab = sorted([(a, b) for a, b in zip(*[iter(ab)] * 2)])
    hq, index, cap, count, ans = [], 0, 1, m, 0
    while index < n:
        _a, _b = ab[index]
        if _a > m:
            break
        if _a <= cap:
            heapq.heappush(hq, -_b)
            index += 1
        else:
            ans -= heapq.heappop(hq) if len(hq) > 0 else 0
            count -= 1
            cap += 1
    ans += sum([-heapq.heappop(hq) for _ in range(count) if len(hq) > 0])
    return str(ans)


if __name__ == '__main__':
    n, m = map(int, input().split())
    print(solve('{} {}\n'.format(n, m) + '\n'.join([input() for _ in range(n)])))


Measured memory_bytes: 25704
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
int gcd(int a, int b) {return b == 0 ? a : gcd(b, a % b);}
using namespace std;
const int Max_N = 1e2+10;
const int Max_W = 1e5+10;
const int Max_value = 1e5+10;
long long v[Max_value];
int w[Max_W];
long long dp[Max_W];

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

    for (int i = 1; i <= N; i++) {
        cin >> w[i] >> v[i];
    }
    
    
    
    for (int i = 1; i <= N; i++) {
        
        for (int j = W ; j >= 0; j--) {
            if (j >= w[i]) {
                dp[j] = max(dp[j], dp[j-w[i]]+v[i]);
            }
            
            
        }
        
    }
    
    cout << dp[W];
    
    
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <numeric>
#include <mutex>
#include <cmath>
#include <set>
#include <climits>

#define mod 1e9+7
#define mp make_pair
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
using ll = long long;
using pii = pair<int, int>;
 
int main(){
	ll N;
	cin >> N ;
	ll c = N/100;
	if(c*100<=N && c*105>=N) cout << 1;
	else cout << 0 << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {

	public static void main(String[] args) throws IOException {
		Main mainObj = new Main();
		mainObj.solve();
	}

	public void solve() throws IOException {
		FastScanner fs = new FastScanner();
		int a = fs.nextInt();
		int b = fs.nextInt();
		
		String s = fs.next();
		
		String patternStr = String.format("[0-9]{%d}-[0-9]{%d}", a,b);
		Pattern pattern = Pattern.compile(patternStr);
		Matcher matcher = pattern.matcher(s);
		if(matcher.find()) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}

	

	public class FastScanner {

		BufferedReader reader;
		private StringTokenizer st;

		public FastScanner() {
			st = null;
			reader = new BufferedReader(new InputStreamReader(System.in));
		}

		public String next() throws IOException {
			if (st == null || !st.hasMoreElements()) {
				st = new StringTokenizer(reader.readLine());
			}
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			st = null;
			String readLine = null;
			readLine = reader.readLine();
			return readLine;
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		public int[] nextIntArr(int n) throws NumberFormatException, IOException {
			int[] retArr = new int[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextInt();
			}
			return retArr;
		}

		public long[] nextLongArr(int n) throws NumberFormatException, IOException {
			long[] retArr = new long[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextLong();
			}
			return retArr;
		}

		public void close() throws IOException {
			reader.close();
		}
	}

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 200000;
int n;
ll l, s1[maxn + 10], s2[maxn + 10], x[maxn + 10], now, ans;
int main() {
	scanf("%lld%d", &l, &n);
	for (int i = 1; i <= n; ++i) scanf("%lld", &x[i]);
	for (int i = 1; i <= n; ++i) s1[i] = s1[i - 1] + x[i];
	for (int i = n; i >= 1; --i) s2[i] = s2[i + 1] + l - x[i];
	for (int i = 1; i <= n; ++i) {
		int cnt = i + (n - i + 1) / 2 + (n - i + 1) % 2 - 1;
		ll now = (s1[cnt] - s1[i - 1]) * 2 + s2[cnt + 1] * 2;
		if ((n - i + 1) % 2 == 1) now -= x[cnt];
		else now -= l - x[cnt + 1];
		ans = max(ans, now);
	}
	for (int i = 1; i <= n; ++i) x[i] = l - x[i];
	reverse(x + 1, x + n + 1);
	for (int i = 1; i <= n; ++i) s1[i] = s1[i - 1] + x[i];
	for (int i = n; i >= 1; --i) s2[i] = s2[i + 1] + l - x[i];
	for (int i = 1; i <= n; ++i) {
		int cnt = i + (n - i + 1) / 2 + (n - i + 1) % 2 - 1;
		ll now = (s1[cnt] - s1[i - 1]) * 2 + s2[cnt + 1] * 2;
		if ((n - i + 1) % 2 == 1) now -= x[cnt];
		else now -= l - x[cnt + 1];
		ans = max(ans, now);
	}
	printf("%lld", ans);
}


Measured memory_bytes: 4992
#include <stdio.h>
#include <ctype.h>
int main(){
	
	char m[1201]={'0'},b[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' };
	int i,a[27]={0};
	
	i=0;
	/*while (scanf("%c", &m[i++]) != EOF){
	}
	*/
	for(i=0;scanf("%c",&m[i])!=EOF;i++){
	}
	
	for(int t=0;t<i;t++){
		if(isupper(m[t])){
			m[t]=tolower(m[t]);
		}
	}
	//printf("%s",m);
	for(int t=0;t<i;t++){
		if(m[t]>='a'&&m[t]<='z'){
			a[m[t]-'a']++;
		}
	}
	for(int t=0;t<26;t++){
		printf("%c : %d\n",b[t],a[t]);
	}
	return 0;
}

Measured memory_bytes: 2592
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい
// https://github.com/atcoder/live_library
// cppdbg: test.exeのterminalに標準入力を打てる

#define ALL(x) x.begin(),x.end()
#define get_tp(t,i) get<i>(t)
#define len(x) (ll)(x.size())
#define ub(a,x) (upper_bound(ALL(a),x)-a.begin())
#define lb(a,x) (lower_bound(ALL(a),x)-a.begin())
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef pair<long long,long long> pllll; //pair<ll,ll>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<ll, vector<ll>, greater<ll> > gpq; //逆順priority_queue
typedef priority_queue<ll> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const long double PI=3.1415926535897932;

int main(){
    int a,b,c,d;cin>>a>>b>>c>>d;
    if(abs(a-c)<=d){
        cout<<"Yes"<<endl;
    }else if(abs(a-b)<=d && abs(b-c)<=d){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 3596
N, Q = (int(x) for x in input().split())
S = input()
t = [0]*(N+1)
for i in range(N):
  if S[i:i+2] == "AC":
    t[i+1] = t[i] + 1
  else:
    t[i+1] = t[i]
for i in range(Q):
  l,r = (int(x) for x in input().split())
  print(t[r-1] - t[l-1])

Measured memory_bytes: 11436
#pragma GCC optimize("O3")
#define _CRT_SECURE_NO_WARNINGS
#define _CRT_DISABLE_PERFCRIT_LOCKS
#define POPCNTI(a) __builtin_popcount(a)
 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>


#include <bits/stdc++.h>
using namespace  __gnu_pbds; 
using namespace std;

 
// #ifndef _LOCAL_DEFINE
// inline int getchar_unlocked(){return _getchar_nolock();}
// inline void putchar_unlocked(char c) {_putchar_nolock(c);}
// #endif
 
typedef long long ll;  
typedef pair<int,int> pr; 
 
const ll OOl = LLONG_MAX;
const int N = 1e6+1, M = 1e6+1, OO = INT_MAX,OOmem = 0x4f4f4f4f, MOD = 1e9 + 7;

inline void WRITE_CHAR(char c)  {putchar_unlocked(c);}
 
template<typename T> 
inline bool READn (T &result) {
  int minus = 1;
  char ch;
  result=0;
  ch = (char) getchar_unlocked();
  if(ch!='-') while (!isdigit(ch) && ch!=EOF) ch= (char) getchar_unlocked(), minus = (ch == '-'? -1 : minus);
 
  if(ch==EOF) return false;
  while (isdigit(ch))  result = result*10 + (int) (ch - '0'),ch = (char) getchar_unlocked();
  
  result *= minus;
  return ch != '\n';
}
template<typename T>
inline void WRITEn(T x) {
  if (x < 0) {putchar_unlocked('-'); x = -x; }
  char writeBuffer[20], *writePtr = writeBuffer;
  do {
    *writePtr++ = (char)('0' + x % 10);
    x /= 10;
  }
  while (x);
  do  { putchar_unlocked(*--writePtr); }
  while (writePtr > writeBuffer);
}
inline bool Read_CHAR(char &c)
{
  char READ_CHARACTER = (char)getchar_unlocked();
  while ((READ_CHARACTER == '\n' || READ_CHARACTER == '\t' || READ_CHARACTER == ' ')) READ_CHARACTER = (char)getchar_unlocked();
  if(READ_CHARACTER == EOF) return false;
  c = READ_CHARACTER;
  return true;
} 
inline bool READ_CHAR_ARRAY(char (&x)[N]) {
  char READ_CHARACTER = (char)getchar_unlocked();
  while ((READ_CHARACTER == '\n' || READ_CHARACTER == '\t' || READ_CHARACTER == ' ')) READ_CHARACTER = (char)getchar_unlocked();
  if(READ_CHARACTER == EOF) return false;
  char *ptr = &x[0];
  while ((READ_CHARACTER != '\n' && READ_CHARACTER != '\t' && READ_CHARACTER != ' ' && READ_CHARACTER != EOF)) *ptr++ = READ_CHARACTER, READ_CHARACTER = (char)getchar_unlocked();
  *ptr = '\0';
  return true;
}
inline void WRITE_CHAR_ARRAY(const char *x) {
  while(*x != '\0')
    putchar_unlocked(*x++);
}
int n,k,arr[101];
int memo[N][2];
int solve(int pile=k,bool flag = 0)
{
  int &ret = memo[pile][flag];
  if(~ret) return !ret;

  ret = 0;
  for(int i=0;i<n;++i)
    if((pile-arr[i])>=0) ret = max(ret,solve(pile-arr[i],!flag)); 
    
  
  return !ret;
}
bool dp[N];
int main()
{
  
  memset(memo,-1,sizeof memo);
  READn(n),READn(k);
  for(int i=0;i<n;++i) READn(arr[i]);
  for(int pile = 0 ;pile<=k;++pile)
    for(int i=0;i<n;++i) 
      if(pile-arr[i]>=0) dp[pile] = max(dp[pile],!dp[pile-arr[i]]);
      
  
  if(dp[k]) WRITE_CHAR_ARRAY("First");
  else WRITE_CHAR_ARRAY("Second");

  
  return 0;
}




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


int main(){

  stack<int> st;

  string s;
  while(cin >> s){
    if(s == "+"){
      int a = st.top(); st.pop();
      int b = st.top(); st.pop();
      st.push(a+b);
    }
    else if(s == "*"){
      int a = st.top(); st.pop();
      int b = st.top(); st.pop();
      st.push(a*b);
    }
    else if(s == "-"){
      int a = st.top(); st.pop();
      int b = st.top(); st.pop();
      st.push(b-a);
    }
    else{
      int x = stoi(s);
      st.push(x);
    }
  }
  cout << st.top() << endl;
}

Measured memory_bytes: 3164
#include <stdio.h>

int main(void) {
  int N, Y, i, j, P;
  scanf("%d %d", &N, &Y);
  Y/=1000;
  P=0;
  for (i=0; i<=N; i++) {
    if (P==1) break;
    for (j=0; j<=N; j++) {
      if (P==1) break;
      if (10*i+5*j+(N-i-j) == Y && N-i-j>=0) {
        printf("%d %d %d", i, j, N-i-j);
        P=1;
        break;
      }
    }
  }
  if (P==0) printf("-1 -1 -1");
  return 0;
}

Measured memory_bytes: 128