akhauriyash/Code-Regression huggingface dataset:
#if 0
Dinner
k回自炊するときを考える。まず一回のみ自炊すると考えると、等差数
列的に得られる幸福度が下がっていく自炊と、外食の差分を取って、も
っとも差がプラスとなるものを選ぶことになる。2回以上自炊する場合
を考えると、どのような順番で自炊するかに関わらず、Qが向上したこと
によるbonusが得られることに気づく。よって、先ほど取った差分をソ
ートし、kを1からNまで動かし、bonus変数との合計を取りながら得ら
れる差の0以上の最大値をとっていき、全て外食で済ませた場合との合計
をとれば、O(N)の計算量で済ますことができる。
bonus変数の計算については、いつ自炊したかに関わらず、自炊した回数
によって等差数列の和として計算することができる。
実装上の反省点としては、イテレーションを回すだけだとおもってint
で定義したiという変数をbonus変数の計算に使ったところ、オーバー
フローが発生してしまったので、油断せず全てlong longにした方が
良いかもしれないと感じた。
#endif
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <assert.h>
#include <complex>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
ll Max, N, P, Q;
ll C[501000];
ll diff_by_min[501000];
void setup() {
    cin >> N >> P >> Q;
    for (int i = 0; i < N; ++i) {
        cin >> C[i];
    }
}
void calc_diff_by_min() {
    for (int i = 0; i < N; ++i) {
        diff_by_min[i] = (Q - i) * P  - C[i];
    }
}
ll max_diff_by_jisui() {
    ll max_diff = 0;
    ll now_diff_by_min = 0;

    sort(diff_by_min, diff_by_min + N);

    for (ll i = 0; i < N; ++i) {
        now_diff_by_min += diff_by_min[N - i - 1];
        ll bonus = i * (i + 1) * P;

        max_diff = max(
            max_diff, now_diff_by_min + bonus);
    }

    return max_diff;
}
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    #define ll int

    setup();

    // Calculate the quality of life when he always eats out.
    for (int i = 0; i < N; ++i) {
        Max += C[i];
    }

    calc_diff_by_min();

    cout << Max + max_diff_by_jisui() << endl;

    return 0;
}


Measured memory_bytes: 11000
#include"bits/stdc++.h"
using namespace std;

void Main() {
  int A, B;
  cin >> A >> B;

  char grid[100][100];
  for (int i = 0; i < 50; i++) {
    for (int j = 0; j < 100; j++) {
      grid[i][j] = '#';
    }
  }
  for (int i = 50; i < 100; i++) {
    for (int j = 0; j < 100; j++) {
      grid[i][j] = '.';
    }
  }

  for (int j = 1; j < 100 && A > 1; j++) {
    if (grid[0][j - 1] == '#') {
      grid[0][j] = '.';
      A--;
    }
  }

  for (int i = 1; i < 49 && A > 1; i++) {
    for (int j = 1; j < 99 && A > 1; j++) {
      if (grid[i - 1][j - 1] == '#' && grid[i - 1][j] == '#' && grid[i - 1][j + 1] == '#' && grid[i][j - 1] == '#') {
        grid[i][j] = '.';
        A--;
      }
    }
  }

  for (int i = 51; i < 100 && B > 1; i++) {
    for (int j = 1; j < 99 && B > 1; j++) {
      if (grid[i - 1][j - 1] == '.' && grid[i - 1][j] == '.' && grid[i - 1][j + 1] == '.' && grid[i][j - 1] == '.') {
        grid[i][j] = '#';
        B--;
      }
    }
  }

  cout << 100 << " " << 100 << endl;
  for (int i = 0; i < 100; i++) {
    for (int j = 0; j < 100; j++) {
      cout << grid[i][j];
    }
    cout << endl;
  }
}

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



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
#define LL long long
#define STEP 0.0005
// sort(a.begin(), a.end(), std::greater<int>());

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main()
{
    string s;
    cin >> s;
    SORT(s);
    if (s == "abc")
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


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

int main(){
	int a ,b ,c;
	cin >> a >> b >> c;
	if(a + b < c){
		cout << "NA" << endl;
		return 0;
	}
	if(a >= c){
		cout << 0 << endl;
		return 0;
	}
	cout << c-a << endl;
	return 0;
}

Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int n;
  string s[2];
  cin>>n>>s[0]>>s[1];
  int ans=1;
  int MOD=1000000007;
  if(s[0][0]==s[1][0]) ans=3;
  else ans=6;
  for(int i=1;i<n;i++){
    if(s[0][i-1]==s[0][i]) continue;
    if(s[0][i]==s[1][i]){
      if(s[0][i-1]==s[1][i-1]) ans*=2;
      ans%=MOD;
      continue;
    }
    if(s[0][i-1]==s[1][i-1]) ans*=2;
    else ans*=3;
    ans%=MOD;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
def c_skip(N, X, Pos):
    from fractions import gcd
    diff = [abs(X - x) for x in Pos]
    ans = diff[0]
    for x in diff[1:]:
        ans = gcd(ans, x)
    return ans

N, X = [int(i) for i in input().split()]
Pos = [int(i) for i in input().split()]
print(c_skip(N, X, Pos))

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

typedef long long ll;

int T, fis;
ll A, B, ans;

int main()
{
	std::cin >> A >> B;
	if (A == B) return puts("1"), 0;
	for (T = 60; ((A >> T) & 1) == ((B >> T) & 1); T--);
	for (fis = T - 1; fis >= 0 && !((B >> fis) & 1); fis--); fis++;
	A &= (1ll << T) - 1; ans = (1ll << T) - A;
	ans += (1ll << T - fis) - (A >> fis) - 1 << fis;
	if (A >> fis)
	{
		A &= (1ll << fis) - 1; ans++;
		for (int i = fis - 1; i >= 0; i--)
			if (!((A >> i) & 1)) ans += 1ll << i;
	}
	return std::cout << ans + (1ll << fis) << std::endl, 0;
}

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

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

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

int f(int n) {
    if (n == 0) return 0;
    else return f(n%__builtin_popcount(n))+1;
}

int main(){
    int n;
    cin >> n;
    string x;
    cin >> x;
    vi xi(n);
    rep(i, n) xi[i] = x[i] - '0';
    int pc = 0;
    rep(i, n) if (xi[i] == 1) ++pc;
    vi ans(n);
    rep(b, 2) {
        int npc = (b==0?pc+1:pc-1);
        if (npc <= 0) continue;
        int pfx = 0;
        rep(i, n) {
            pfx = (pfx*2)%npc;
            pfx = (pfx+xi[i])%npc;
        }
        int k = 1;
        repr(i, n) {
            if (xi[i] == b) ans[i] = (b==0?f((pfx+k)%npc):f((pfx-k+npc)%npc))+1;
            k = (k*2)%npc;
        }
    }
    rep(i, n) cout << ans[i] << endl;
    return 0;
}


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

int main(){
int W , a ,b;
cin >> W >> a >> b;
if (b + W <= a) {
  cout << a - (b + W) << endl;
}
else if (b - (a + W) > 0) {
  cout << b - (a + W) <<endl;
}
else cout << 0 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

const int mod = 1e9 + 7;
const int MX = 110000;
ll inv[MX], f[MX], invf[MX];
void calc(){
	inv[0] = inv[1] = f[0] = f[1] = invf[0] = invf[1] = 1;
	for (int i = 2; i < MX; i++){
		inv[i] = mod - mod / i * inv[mod % i] % mod;
		f[i] = f[i - 1] * i % mod;
		invf[i] = invf[i - 1] * inv[i] % mod;
	}
}
inline ll C(ll n, ll k){
	return f[n] * invf[k] % mod * invf[n - k] % mod;
}

int n;
vi cs;
vector<vi> e;
int rec(int c, int p){
	int res = 1;
	bool ok = 1;
	for(int i : e[c]) if(i != p){
		int x = rec(i, c);
		res += x;
		if(2 * x > n) ok = 0;
	}
	if(ok && 2 * (n - res) <= n) cs.pb(c);
	return res;
}
int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	calc();
	
	cin >> n;
	e.resize(n);
	rep(i, n - 1){
		int a, b; cin >> a >> b; a--; b--;
		e[a].pb(b);
		e[b].pb(a);
	}
	rec(0, 0);
	
	if(cs.size() == 2){
		cout << f[n / 2] * f[n / 2] % mod << endl;
		return 0;
	}
	
	assert(cs.size() == 1);
	int c = cs[0];
	vi dp(1, 1), sz;
	for(int i : e[c]) sz.pb(rec(i, c));
	
	rep(i, e[c].size()){
		vi next(dp.size() + sz[i]);
		rep(j, dp.size()) rep(k, sz[i] + 1){
			(next[j + k] += dp[j] * C(sz[i], k) % mod * C(sz[i], k) % mod * f[k] % mod) %= mod;
		}
		dp = next;
	}
	ll ans = 0;
	rep(i, dp.size()) ans += (i & 1 ? -1 : 1) * dp[i] * f[n - i] % mod;
	ans = (ans % mod + mod) % mod;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3456
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <limits>
#include <string>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n); i > 0; i--)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
using namespace std;
using lint = long long;
using P = pair<int, int>;
constexpr int MOD = 1e9 + 7;

int A, B, C, F, H, I, J, K, L, M, N, S, T, U, W;
// lint A, B, F, H, I, J, K, L, M, N, S, T, U, W;
// string A, B;
int ans = 0;
vector<vector<int>> cnt(10, vector<int>(10, 0));

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

	cin >> N;

	rep1(i, N) {
		int f = to_string(i)[0] - '0';
		int l = i % 10;
		cnt[f][l]++;
	}

	rep1(i, 9) {
		rep1(j, 9) {
			ans += cnt[i][j] * cnt[j][i];
		}
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
# from functools import reduce
from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline

def resolve():
    N=int(input())
    A=list(map(int,input().split()))
    B=list(map(int,input().split()))[::-1]

    from itertools import accumulate


    AA = [0] + A
    AA = list(accumulate(AA))+[0]

    BB=[0]+B
    BB=list(accumulate(BB))+[0]# 累積和を格納したリスト作成
    ans=0
    # この問題は長さが1-Nの連続部分の和の最大値を出せというものなので以下の通り
    for i in range(1, N + 1):
        ans = max(AA[i]+BB[N-i+1],ans)
    print(ans)



resolve()

Measured memory_bytes: 38384
n = int(input())
ab_li=[list(map(int,input().split())) for _ in range(n)]

ab_li.sort(key=lambda x: x[1])
ab = []
a = 0
b = 0
h = 0
now = 0

for i in range(n):
    ab = ab_li[i]
    a = ab[0]
    b = ab[1]
    if b != h:
        h = b
    now += a
    if h < now:
        print("No")
        exit(0)

print("Yes")

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

typedef long long ll;
typedef unsigned long long ull;

#define pb push_back
#define mp(x,y) make_pair(x,y)
#define scd(n) scanf("%d",&n)
#define sclf(n) scanf("%lf",&n)
#define scl(n) scanf("%I64d",&n)
#define repi(a,b,c) for(int i=a;i<b;i+=c)
#define repis(a,b,c) for(int i=a-1;i>=b;i-=c)
#define repj(a,b,c) for(int j=a;j<b;j+=c)
#define repjs(a,b,c) for(int j=a-1;j>=b;j-=c)
#define repk(a,b,c) for(int k=a;k<b;k+=c)
#define repks(a,b,c) for(int k=a-1;k>=0;k-=c)
#define fi first
#define se second

/*
 fast I/O

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

 freeopen

 freopen("input.txt","r",stdin);
 freopen("output.txt","w",stdout);
 */

typedef pair<ll,ll> ii;
const int mx = 200100;
const int md = 1000000007;
const double EULER = 2.71828182845904523536;

int main() {
    int n,k,ans=1;
    cin >> n >> k;
    repi(0,n,1) {
        if(ans*2 < ans+k) ans *= 2;
        else ans += k;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    int N;
    cin >> N;
    ll A[N];
    rep(i, N) cin >> A[i];
    ll c = 0;
    rep2(i, 2, N-1) c ^= A[i];
    ll d = A[0]+A[1], x = d-c;
    if(x < 0) {cout << -1 << endl; return 0;}
    vector<int> memo;
    rep(i, 40){
        if(c&(1LL<<i)) continue;
        if(x&(1LL<<(i+1))) memo.pb(i), x &= ~(1LL<<(i+1));
    }
    if(x != 0) {cout << -1 << endl; return 0;}
    ll a = 0;
    for(auto &e: memo) a |= (1LL<<e);
    if(a > A[0]) {cout << -1 << endl; return 0;}
    rep3(i, 40, 0){
        if(c&(1LL<<i)){
            if(a+(1LL<<i) <= A[0]) a += (1LL<<i);
        }
    }
    if(a == 0) cout << -1 << endl;
    else cout << A[0]-a << endl;
}

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

vector <ll> v;
void find(string str){
    ll a=stoll(str);
    v.push_back(a);
    if(str.size()<=10){
        if(str[str.size()-1]=='9'){
        find(str+"8");
        find(str+"9");
        }
        else if(str[str.size()-1]=='0'){
        find(str+"0");
        find(str+"1");
        }
        else {
            rep(i, 3) {
                int now=str[str.size()-1]-'0';
                now+=(i-1);
                string tmp=to_string(now);
                find(str+tmp);
            }
        }
    }
}

int main(void){
    int k;
    cin>>k;
    v.push_back(0);
    for(int i=1;i<=9;i++) {
        string t=to_string(i);
        find(t);
    }
    sort(v.begin(), v.end());
    cout<<v[k]<<endl;
    return 0;
}

Measured memory_bytes: 10604
using System;
class Program
{
    static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());
        int[] l = InputIntArray();
        int count = 0;

        for (int a = 0; a < n; a++)
            for (int b = a + 1; b < n; b++)
                for (int c = b + 1; c < n; c++)
                {
                    int aa = l[a], bb = l[b], cc = l[c];
                    if (aa == bb || aa == cc || bb == cc)
                        continue;
                    if (aa + bb > cc && bb + cc > aa && cc + aa > bb)
                        count++;
                }
        Console.WriteLine(count);
    }


    public static int[] InputIntArray()
    {
        string[] strs = Console.ReadLine().Split(' ');
        int[] num = new int[strs.Length];
        for (int i = 0; i < num.Length; i++)
        {
            num[i] = int.Parse(strs[i]);
        }

        return num;

    }

}


Measured memory_bytes: 27512
A, B, C, D = map(int, input().split())

tt, at = 0, 0
while(A>0 and C>0):
  tt += 1
  C -= B
  if(C <= 0):
    break
  at += 1
  A -= D
if(tt > at):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 9032
#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
ll MOD=998244353;
#define INF 2*1e9
#define N 1000010
#define MAX_V 900010
using namespace std;
ll int inv[N],comb[N],prd[N],invprd[N];
void calc_inv(){
    inv[1]=1;
    rep2(i,2,N){
        inv[i]=((-(MOD/i)*inv[MOD%i])%MOD+MOD)%MOD;
    }
    return;
}
void calc_comb(ll int n){
    comb[0]=1;
    rep2(i,1,n){
        comb[i]=comb[i-1]*(n+1-i)*inv[i]%MOD;
    }
    return;
}
void calc_product(){
    prd[1]=1;
    prd[0]=1;
    invprd[0]=invprd[1]=1;
    rep2(i,2,N){
        prd[i]=i*prd[i-1]%MOD;
        invprd[i]=inv[i]*invprd[i-1]%MOD;
    }
    return ;
}
ll cmb(int a,int b){
    if(a<b)return 0;
    return prd[a]*invprd[b]%MOD*invprd[a-b]%MOD;
}
ll modpow(ll x,ll n){
    if(n==0) return 1;
    ll res=modpow(x*x%MOD,n/2);
    if(n&1) res=res*x%MOD;
    return res;
}
main(){
    int k,n;
    cin>>k>>n;
    calc_inv();
    calc_product();
    ll all=cmb(n+k-1,k-1);
    rep2(i,2,2*k){
        int count=0;
        rep2(j,1,k){
            if(i-j>0&&i-j<=k)count++;
        }
        count=(count+1)/2;
        ll ans=0;
        if(i%2){
            ll temp=1;
            rep2(i,1,count){
                ans=(ans+temp*cmb(n+k-1-2*i,k-1)*cmb(count,i)%MOD+MOD)%MOD;
                temp*=-1;
            }
        }
        else{
            count--;
            ll temp=1;
            rep2(i,1,count){
                ans=(ans+temp*cmb(n+k-2-2*i,k-2)*cmb(count,i)%MOD+MOD)%MOD;
                temp*=-1;
            }
            temp=1;
            rep2(i,1,count){
                ans=(ans+temp*cmb(n+k-3-2*i,k-2)*cmb(count,i)%MOD+MOD)%MOD;
                temp*=-1;
            }
            ans=(ans+cmb(n+k-3,k-1))%MOD;
        }
        printf("%d\n",(all-ans+MOD)%MOD);
    }
}

Measured memory_bytes: 25344
package main

import (
	"fmt"
)

func main() {
	var n, k int
	fmt.Scanf("%d %d", &n, &k)
	// start := time.Now()
	// maxForKList := make([]float64, n)
	probabilityHash := make(map[int]float64) // key maxForDice, value p
	probabilityList := make([]float64, n)
	accumulatedList := make([]float64, n)
	for i := 0; i < n; i++ {
		var maxForDice int
		fmt.Scanf("%d", &maxForDice)
		p := probabilityHash[maxForDice]
		if p == 0 {
			for j := maxForDice; j > 0; j-- {
				p += float64(j) / float64(maxForDice)
			}
			probabilityHash[maxForDice] = p
		}
		// for j := i - k + 1; j <= i; j++ {
		// 	if j < 0 {
		// 		continue
		// 	}
		// 	maxForKList[j] += p
		// }
		probabilityList[i] = p
		if i == 0 {
			accumulatedList[i] = p
		} else {
			accumulatedList[i] = accumulatedList[i-1] + p
		}

	}
	maxP := 0.0
	// fmt.Println(accumulatedList)
	for i := 0; i < n-k; i++ {
		p := accumulatedList[i+k] - accumulatedList[i]
		if maxP < p {
			maxP = p
		}
	}
	if n == k {
		maxP = accumulatedList[n-1]
	}
	// for i := 0; i < n; i++ {
	// 	if maxP < maxForKList[i] {
	// 		maxP = maxForKList[i]
	// 	}
	// }
	fmt.Printf("%f\n", maxP)
	// end := time.Now()
	// fmt.Println("Elapsed time: ", end.Sub(start))
}

/*
k = 3
i = 0, j = 0
i = 1, j = 0, 1
i = 2, j = 0, 1, 2
i = 3, j = 1, 2, 3
0 0 0
  1 1 1
	2 2 2
	  3 3 3
*/


Measured memory_bytes: 7808
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
#include<random>
#include<ctime>
#include<set>
using namespace std;


const long long int mod=1000000007;
const long long int INF=99999999999999999;


long long int n,res=0;
int main() {
	cout << fixed << setprecision(18);
	cin>>n;
    if(n%2==1){cout<<0<<endl;return 0;}
    n/=2;
    while(n>=5){
        res+=n/5;
        n/=5;
    }
	cout<<res;
} 

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
 
void turn(int *DICE,char com);
 
int main(void){
int i,j,q,top,front;
int DICE1[6],DICE2[6];
char com[105];
for(i=0;i<6;i++){scanf("%d",&DICE1[i]);}
for(i=0;i<6;i++){scanf("%d",&DICE2[i]);}
top=DICE1[0];front=DICE1[1];
i=0;
strcpy(com,"SSSSESSSS");
while(DICE2[1]!=front){
    if(com[i]=='\0'){printf("No\n");return 0;}
    turn(&DICE2[0],com[i]);
    i++;
    }
i=0;
strcpy(com,"EEEE");
while(DICE2[0]!=top){
    if(com[i]=='\0'){printf("No\n");return 0;}
    turn(&DICE2[0],com[i]);
    i++;
    }
for(i=2;i<6;i++){
    if(DICE1[i]!=DICE2[i]){printf("No\n");return 0;}
    }
printf("Yes\n");
return 0;
}
 
void turn(int *DICE,char com){
int temp;
switch(com){
    case 'N':
        temp     =*DICE;
        *DICE    =*(DICE+1);
        *(DICE+1)=*(DICE+5);
        *(DICE+5)=*(DICE+4);
        *(DICE+4)=temp;
        break;
    case 'S':
        temp     =*DICE;
        *DICE    =*(DICE+4);
        *(DICE+4)=*(DICE+5);
        *(DICE+5)=*(DICE+1);
        *(DICE+1)=temp;
        break;
    case 'E':
        temp     =*DICE;
        *DICE    =*(DICE+3);
        *(DICE+3)=*(DICE+5);
        *(DICE+5)=*(DICE+2);
        *(DICE+2)=temp;
        break;
    case 'W':
        temp     =*DICE;
        *DICE    =*(DICE+2);
        *(DICE+2)=*(DICE+5);
        *(DICE+5)=*(DICE+3);
        *(DICE+3)=temp;
        break;
    }
}


Measured memory_bytes: 2148
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>


int main()
{
  int n;
  int i;
  int x[1000];
  int y[1000];
  int z[1000];
  double dist1=1.0*0;
  double dist2=1.0*0;
  double dist2r = 1.0*0;
  double dist3 = 1.0*0;
  double dist3r = 1.0*0;
  double distma=1.0*0;
  double P = 1.0/3.0;

   for (i=0; i<1000; i++) {
   x[i]=0;
   y[i]=0;
   z[i]=0;
   }


    scanf("%d",&n);

    for (i = 0; i < n; i++) {
      scanf("%d",&x[i]);
    }
   for (i = 0; i < n; i++) {
    scanf("%d",&y[i]);
  }

// dist1 ????±??????????

   for(i = 0; i < n; i++) {
    dist1=fabs(x[i]-y[i])+dist1;
   }

// dist2 ????±??????????
   for(i = 0; i < n; i++) {
 dist2 = dist2+(pow(x[i]-y[i],2));
  }
  dist2r = sqrt(dist2);

// dist3 ????±??????????
 for(i = 0; i < n; i++) {
  dist3 = dist3+(pow(fabs(x[i]-y[i]),3));
 }

 dist3r = pow(dist3,P);


 //distma ????±??????????

 for(i = 0; i < n; i++) {
  z[i]=fabs(x[i]-y[i]);
}

 for(i = 0; i < n; i++) {
   if(distma<=z[i]){
     distma = z[i];
   }
 }



printf("%lf\n",dist1);
printf("%lf\n",dist2r);
printf("%lf\n",dist3r);
printf("%lf\n",distma);

  return(0);

}

Measured memory_bytes: 708
#include<cstdio>
#define ll long long
using namespace std;
ll a[51];
int main()
{
	ll n;
	scanf("%lld", &n);
	puts("50");
	for (int i = 0; i < 50; i++)
	{
		ll gap = n/50 + i;
		a[i] = gap;
	}
	ll ch = n % 50;
	for (int i = 49; i >= 0; i--)
	{
		if (ch)
		{
			a[i]++;
			ch--;
		}
	}
	for (int i = 0; i < 50; i++)
		printf("%lld ", a[i]);
}

Measured memory_bytes: 128
# -*- coding: utf-8 -*-
from collections import defaultdict
from pprint import pprint as pp
import itertools

N, K = map(int, input().split())
xy = [list(map(int, input().split())) for _ in range(N)]

rui = defaultdict(lambda: defaultdict(int))
sumnum = defaultdict(lambda: defaultdict(int))

for x,y in xy:
    rui[x][y] += 1

xlist = list(sorted(rui.keys()))
ylist = []
for x in xlist:
    ylist.extend(list(rui[x].keys()))
ylist = sorted(list(set(ylist)))

for x in xlist:
    tmp = 0
    for y in ylist:
        tmp += rui[x][y]
        sumnum[x][y] = tmp

for y in ylist:
    tmp = 0
    for x in xlist:
        tmp += sumnum[x][y]
        sumnum[x][y] = tmp

xdict = {v: i for i, v in enumerate(xlist)}
ydict = {v: i for i, v in enumerate(ylist)}

sqmin = -1
exy = list(itertools.product(xlist, ylist))
# print(f"len(exy)={len(exy)}")
for i, (x1, y1) in enumerate(exy[:-1]):
    # print(f"x1={x1},y1={y1}")
    # print(f"len(exy[i+1:])={len(exy[i+1:])}")
    for x2, y2 in exy[i+1:]:
        if x1 < x2 and y1 < y2:
            xd1 = xdict[x1] - 1
            yd1 = ydict[y1] - 1
            if xd1 < 0:
                xb = (10**9 + 1)*(-1)
            else:
                xb = xlist[xd1]
            if yd1 < 0:
                yb = (10**9 + 1)*(-1)
            else:
                yb = ylist[yd1]
            tmp = sumnum[x2][y2] - sumnum[xb][y2] - sumnum[x2][yb] + sumnum[xb][yb]
            if tmp >= K:
                area = abs(x2 - x1)*abs(y2 - y1)
                if sqmin > area or sqmin == -1:
                    sqmin = area

print(sqmin)


Measured memory_bytes: 47852
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n = I()
    aa = [LS() for _ in range(n)]
    xi = collections.defaultdict(lambda: inf)
    xa = collections.defaultdict(lambda: -inf)
    yi = collections.defaultdict(lambda: inf)
    ya = collections.defaultdict(lambda: -inf)
    km = 0
    for x,y,d in aa:
        x = int(x)
        y = int(y)
        if km < abs(x):
            km = abs(x)
        if km < abs(y):
            km = abs(y)
        if xi[d] > x:
            xi[d] = x
        if xa[d] < x:
            xa[d] = x
        if yi[d] > y:
            yi[d] = y
        if ya[d] < y:
            ya[d] = y

    ts = set([0])

    for d in [xi,xa,yi,ya]:
        ks = list(d.keys())
        for k in ks:
            for e in ks:
                ts.add(abs(d[k] - d[e]))
                ts.add(abs(d[k] - d[e]) / 2)

    def f(i):
        xxi = inf
        xxa = -inf
        yyi = inf
        yya = -inf
        for d,x in xi.items():
            if d == 'L':
                x -= i
            elif d == 'R':
                x += i
            if xxi > x:
                xxi = x
        for d,x in xa.items():
            if d == 'L':
                x -= i
            elif d == 'R':
                x += i
            if xxa < x:
                xxa = x
        for d,y in yi.items():
            if d == 'D':
                y -= i
            elif d == 'U':
                y += i
            if yyi > y:
                yyi = y
        for d,y in ya.items():
            if d == 'D':
                y -= i
            elif d == 'U':
                y += i
            if yya < y:
                yya = y

        return (xxa-xxi) * (yya-yyi)

    r = f(0)
    for i in ts:
        t = f(i)
        if r > t:
            r = t

    return '{:0.3f}'.format(r)


print(main())



Measured memory_bytes: 35852
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>

#include <cstdio>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
typedef long long ll;
typedef unsigned long long ull;

#define PI 3.1415926535897932384626433832795

int main()
{
	double a, b, x;
	double balanced;
	double ans = 0;

	cin >> a >> b >> x;

	balanced = atan(b / a) * 180 / PI;
	
	if (x == a * a * b / 2) {
		ans = balanced;
	} 
	else if (x > a * a * b / 2) {
		ans = atan((2 * a * a * b - 2 * x) / (a * a * a)) * 180 / PI;
	}
	else {
		ans = atan(a * b * b / (2 * x)) * 180 / PI;
	}

	printf("%.10lf\n", ans);

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
using namespace std;
using ll = long long;
#define pi 3.1415926

int a[3];

int main(){
    string s;
    cin >> s;
    if(s > "2019/04/30")
        cout << "TBD";
    else
        cout << "Heisei";
    
}
	


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int x[3];
    cin>>x[0]>>x[1]>>x[2];
    sort(x,x+3);
    int ans=(x[2]-x[1])+(x[1]-x[0]);
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 256
macro_rules! get {
    (Vec<$t:ty>) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let N = get!(usize);
    let a = get!(Vec<usize>);

    // a[i] = j を満たすiの個数を集計
    // 集計結果を用いて解を求める
    let mut dp = vec!(0; a.iter().max().unwrap() + 3);
    for x in a {
        dp[x] += 1;
        dp[x + 1] += 1;
        dp[x + 2] += 1;
    }
    let ans = dp.iter().max().unwrap();

    println!("{}", ans);
}

Measured memory_bytes: 6396
#include<bits/stdc++.h>
using namespace std;
void look(int,int,char);
void zen(int ,int ,char);
int w,h;
vector<vector <char> >a;
int cb;
int cw;
int cou;
int main(){
  while(1){
    cb=0;
    cw=0;
    cin >> w >> h;
    if(w==0&&h==0)break;
    a=vector<vector<char> >(h,vector<char>(w));
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	cin >> a[i][j];
      }
    }
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	if(a[i][j]=='W'){
	  look(i,j,'W');
	}
	else if(a[i][j]=='B'){
	  look(i,j,'B');
	}
      }
    }
    cout << cb << " " << cw << endl;
  }
  return 0;

}
void look(int I,int J,char cl){
  int lx[4]={-1,0,1,0};
  int ly[4]={0,-1,0,1};
  for(int i=0;i<4;i++){
    if(I+lx[i]<0||I+lx[i]>=h||J+ly[i]<0||J+ly[i]>=w)continue;
    if(a[I+lx[i]][J+ly[i]]=='.'){
      cou=0;
      zen(I+lx[i],J+ly[i],cl);
      if(cou!=-1){
	if(cl=='B')cb+=cou;
	else cw+=cou;
      }
    }
  }
}
void zen(int I,int J,char cl){
  if(a[I][J]=='.'){
    a[I][J]='l';
    if(cou>=0)cou++;
  }
  else if(a[I][J]==cl||a[I][J]=='l')return;
  else{
    cou = -1;
    return;
  }
  int lx[4]={-1,0,1,0};
  int ly[4]={0,-1,0,1};
  for(int i=0;i<4;i++){
    if(I+lx[i]<0||I+lx[i]>=h||J+ly[i]<0||J+ly[i]>=w)continue;
    zen(I+lx[i],J+ly[i],cl);
  }
}

    

Measured memory_bytes: 3140
#include<bits/stdc++.h>
//macros
using namespace std;
typedef long long ll;
typedef pair<int, int > Pii;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
typedef vector<ll> Vll;
#define pb push_back
#define rs resize 
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define repll(i, a, b) for(ll i=(a); i<(b); i++)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define COUT(a) cout << a << endl
#define ALL(a) (a).begin(),(a).end()
const long long int mod = 1e9 + 7;


int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false); 
    int A,B;
    cin >> A>> B;
    if(A>9 || B>9) COUT(-1);
    else COUT(A*B);


}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN=2010;
struct node
{
	int x,y;
}e[MAXN];
int head[MAXN],ver[MAXN<<1],nxt[MAXN<<1],deep[MAXN];
int n,k,tot;
void add(int x,int y)
{
	ver[++tot]=y;
	nxt[tot]=head[x];
	head[x]=tot;
}
void dfs(int x,int f,int dp)
{
	deep[x]=dp;
	for (int i=head[x];i;i=nxt[i])
	{
		int y=ver[i];
		if (y==f) continue;
		dfs(y,x,dp+1);
	}
}
int main()
{
	scanf("%d%d",&n,&k);
	for (int i=1;i<n;i++)
	{
		scanf("%d%d",&e[i].x,&e[i].y);
		add(e[i].x,e[i].y);
		add(e[i].y,e[i].x);
	}
	int ans=0x3f3f3f3f;
	if (k&1)
	{
		for (int i=1;i<n;i++)
		{
			int cnt=0;
			dfs(e[i].x,e[i].y,0);
			dfs(e[i].y,e[i].x,0);
			for (int j=1;j<=n;j++) if (deep[j]>(k-1)/2) cnt++;
			ans=min(ans,cnt);
		}
	}
	else 
	{
		for (int i=1;i<=n;i++)
		{
			int cnt=0;
			dfs(i,0,0);
			for (int j=1;j<=n;j++)
			if (deep[j]>k/2) cnt++;
			ans=min(ans,cnt);
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
import java.awt.event.ComponentAdapter;
import java.io.BufferedReader;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int first = Integer.parseInt(sc.next()); 
		Sub[] subList = new Sub[first];
		for(int i=0; sc.hasNext(); i++) {
			subList[i] = new Sub(Integer.parseInt(sc.next()), Integer.parseInt(sc.next()));
		}
		if(subList.length == 1) {
			System.out.println(1);
		}else {
			Arrays.sort(subList,new Com());
			ArrayList sa = new ArrayList<String>();
			ArrayList<Integer> count = new ArrayList<Integer>();
			
			StringBuffer br;
			
			for(int i=0; i<subList.length; i++){
				for(int j=0; j<subList.length; j++) {
					br = new StringBuffer();
					if(i==j) {
						continue;
					}
					br.append(String.valueOf(subList[j].a - subList[i].a));
					br.append(String.valueOf(subList[j].b - subList[i].b));
					int exist = sa.indexOf(br.toString());
					if(exist == -1) {
						sa.add(br.toString());
						count.add(1);
					}else {
						count.set(exist, count.get(exist)+1);
					}
				}
			}
			int res = Collections.max(count);
			System.out.println(first - res);
		}
	}
}
class Sub{
	int a;
	int b;

	Sub(int a,int b){
		this.a = a;
		this.b = b;
	}
}
class Com implements Comparator<Sub> {
	@Override
	public int compare(Sub c1, Sub c2) {
		int x = c1.a - c2.a;
		int y = c1.b - c2.b;
		if(x>0) {
			return 1;
		}else if(x<0) {
			return -1;
		}else if(y>0) {
			return 1;
		}else if(y<0) {
			return -1;
		}else {
			return 0;
		}
	}
}






Measured memory_bytes: 24148
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

int main()
{
	const static int ALPHABET_MAX = 26;
	const static int INPUT_MAX = 51;
	// 要素数
	int n = 0;
	cin >> n;

	// 最小記録
	char alphaSmall[ALPHABET_MAX];
	memset( alphaSmall, 0x7F, sizeof(alphaSmall) );

	// 現在記録
	char input[INPUT_MAX];
	char alphaCurrent[ALPHABET_MAX];
	for( int i = 0;i < n;++i )
	{
		// 初期化
		memset( input, 0, sizeof(input) );
		// 入力
		cin >> input;

		// 初期化
		memset( alphaCurrent, 0, sizeof(alphaCurrent) );
		
		// アルファベットカウント
		for( int j = 0;j < INPUT_MAX && input[j] != '¥0';++j )
		{
			alphaCurrent[(input[j] - 'a')] += 1;
		}
		
		// 最小のものを採用していく
		for( int j = 0;j < ALPHABET_MAX;++j )
		{
			if( alphaCurrent[j] < alphaSmall[j] )
			{
				alphaSmall[j] = alphaCurrent[j];
			}
		}
	}
	
	// 初期化
	memset( input, 0, sizeof(input) );
	int charIdx = 0;
	for( int i = 0;i < ALPHABET_MAX;++i )
	{
		for( int j = 0;j < alphaSmall[i];++j )
		{
			input[charIdx++] = 'a' + i;
		}
	}
	cout << input << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
#define repr(i, a, b) for (int i=a; i<(b); ++i)
#define reprev(i, n) for (int i=n-1; i>=0; --i)
#define reprrev(i, a, b) for (int i=b-1; i>=(a); --i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    // cout << fixed << setprecision(10);
    
    ll A; double B; cin >> A >> B;
    int B100 = B * 100 + 0.2;
    ll ans = A * B100 / 100;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3724
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <vector>

#define Flash ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0);
#define F first
#define S second
#define pb push_back
#define nl '\n'
#define NL cout << '\n';
#define EX exit(0)
#define all(s) s.begin(), s.end()
#define sz size()
#define mp make_pair
#define y1 asdf
#define rc(x) return cout << x, 0

const long long MXN = 2e3 + 1;
const long long MNN = 1e5 + 1;
const long long MOD = 1e9 + 7;
const int INF = 1e9 + 5;
const long long OO = 1e9 + 500;

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

int a, b;

void input(){

    cin >> a >> b;

}

int main() {
    input();
    if(a <= 0 && b >= 0) return cout << "Zero", 0;
    if(a > 0) return cout << "Positive", 0;
    if(a < 0) return cout << ((abs(a) - abs(b)) % 2 == 0 ? "Negative" : "Positive"), 0;
    EX;
}


Measured memory_bytes: 256
c = [list(map(int, input().split())) for _ in range(3)]

a = [0] * 3
b = [0] * 3

for i in range(3):
    b[i] = c[0][i] - a[0]

for i in range(1, 3):
    a[i] = c[i][0] - b[0]

ans = "Yes"

for i in range(3):
    for j in range(3):
        if a[i] + b[j] != c[i][j]:
            ans = "No"
            break
    else:
        continue
    break

print(ans)


Measured memory_bytes: 3064
{-# LANGUAGE BangPatterns #-}
import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.Array.Unboxed
import Data.Array.ST

-- Input: s t
-- Output: arr
--   arr ! (i,j) == length of lcs of (drop i s, drop j t)
lcsTable2 :: BS.ByteString -> BS.ByteString -> UArray (Int,Int) Int
lcsTable2 s t = runSTUArray $ do
  let !m = BS.length s
      !n = BS.length t
  arr <- newArray ((0,0),(m,n)) 0
  forM_ [m-1,m-2..0] $ \ !i -> do
    let !x = BS.index s i
    forM_ [n-1,n-2..0] $ \ !j -> do
      let !y = BS.index t j
      l <- if x == y
           then do l2 <- readArray arr (i+1, j+1)
                   return (l2 + 1)
           else do l0 <- readArray arr (i+1, j)
                   l1 <- readArray arr (i, j+1)
                   return (max l0 l1)
      writeArray arr (i,j) l
  return arr

main = do
  s <- BS.getLine
  t <- BS.getLine
  -- BS.length s <= 3000, BS.length t <= 3000, BS.all isAsciiLower s, BS.all isAsciiLower t
  let !table = lcsTable2 s t
      !m = BS.length s
      !n = BS.length t
  let recon !i !j | i >= m || j >= n = Nothing
                  | x == y = let !i' = i+1 ; !j' = j+1
                             in Just (x, (i', j'))
                  | table ! (i+1,j) >= table ! (i,j+1) = recon (i+1) j
                  | otherwise = recon i (j+1)
        where x = BS.index s i
              y = BS.index t j
      (result, _) = BS.unfoldrN (table ! (0,0)) (\(!i,!j) -> recon i j) (0,0)
  BS.putStrLn result


Measured memory_bytes: 71804
#include <bits/stdc++.h>
#define all(a) (a).begin(),(a).end()
#define rep(i,n) for(ll i=0,i##_len=(n);i<i##_len;i++)
#define rep2(i,a,b) for(ll i=(a),i##_len=(b);i<=i##_len;i++)
#define rrep(i,n) ll i=(n);ll now=-1;while(i--&&(now++||1))
#define Yes(n) cout<<((n)?Yes:No)
#define vll vector<ll>
#define pb push_back
using namespace std;
using ll = long long;

static inline void ignore_ret(int x) {x++;}
template<class T> inline bool chmax(T&a,const T&b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T&a,const T&b){if(a>b){a=b;return true;}return false;}
template<class T> inline T gcd_vec(vector<T>v){T r=v.at(0);for(T i=1;i<v.size();i++)r=gcd(r,v.at(i));return r;}
template<class T> inline T lcm_vec(vector<T>v){T r=v.at(0);for(T i=1;i<v.size();i++)r=lcm(r,v.at(i));return r;}
template<class T> inline T factorial(T n){if(n==0)return 1;T r=1;for(T i=2;i<=n;i++)r*=i;return r;}
template<class T> inline T nCr(T n,T k){if(n<k||n<0||k<0)return 0;T r=1;k=min(k,n-k);for(T i=n-k+1;i<=n;i++)r*=i;return r/factorial(k);}
template<class T> inline T dot_product(vector<T>u,vector<T>v){T r=0;for(T i=0;i<u.size();i++)r+=u.at(i)*v.at(i);return r;}
template<class T> inline T sum(vector<T>v){return reduce(all(v),0LL);}

// Template ends here

int main() {
    string A, B; cin >> A >> B;
    vector<string> words = {"EQUAL", "GREATER", "LESS"};
    int state = 0;

    if (A.size() > B.size()) state = 1;
    else if (A.size() < B.size()) state = 2;
    else {
        rep(i, A.size()) {
            if (A.at(i) > B.at(i)) {
                state = 1;
                break;
            }
            else if (A.at(i) < B.at(i)) {
                state = 2;
                break;
            }
        }
    }

    cout << words[state] << "\n";
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner

object Main {

  def solve(sc: => Scanner): Unit = {
    val A1 = math.min(sc.nextLong * 4, math.min(sc.nextLong * 2, sc.nextLong))
    val A2 = math.min(A1 * 2, sc.nextLong)
    val N = sc.nextLong
    println((N / 2: Long) * A2 + N % 2 * A1)
  }

  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    solve(sc)
  }
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 1e5;

int N, A[MAXN+10], B[MAXN+10], C[MAXN+10];
ll dp[MAXN+10][3];

int main()
{
    int i, j;
    scanf("%d", &N);
    for(i=1; i<=N; i++) scanf("%d%d%d", &A[i], &B[i], &C[i]);

    for(i=1; i<=N; i++)
    {
        dp[i][0]=max(dp[i-1][1], dp[i-1][2])+A[i];
        dp[i][1]=max(dp[i-1][0], dp[i-1][2])+B[i];
        dp[i][2]=max(dp[i-1][1], dp[i-1][0])+C[i];
    }
    printf("%lld", max({dp[N][0], dp[N][1], dp[N][2]}));
}


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

int main(){
    int h,w;
    while(1){
        cin>>h>>w;
        if(h==0 && w==0)break;
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++)cout<<"#";
            cout<<endl;
        }
        cout<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define db(...) " [" << #__VA_ARGS__ << ": " << __VA_ARGS__ << "] "
using ii=long long;
const int N = 1 << 17;
vector<int> v[N];
ii dp[N][2];
const ii mod = 1e9 + 7;
void h(int s, int e)
{
    dp[s][0] = dp[s][1] = 1;
    for (int u : v[s]) {
        if (u == e) continue;
        h(u, s);
        (dp[s][0] *= dp[u][1]) %= mod;
        (dp[s][1] *= (dp[u][0] + dp[u][1]) % mod) %= mod;
 
    }
}
int main()
{
    int n;
    cin >> n;
    for (int i = 2; i <= n; ++i) {
        int a, b;
        cin >> a >> b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    h(1, 1);
    cout << (dp[1][0] + dp[1][1]) % mod << "\n";
}


Measured memory_bytes: 14976
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int M1,D1,M2,D2;cin >> M1 >> D1 >> M2 >> D2;
  if(M1==M2)cout << 0 << endl;
  else cout << 1 << endl;
  return 0;
}


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

string ans = "";

void addstr(int c, string d) {
  for (int i = 0; i < c; i++) {
    ans = ans + d;
  }
}

int main() {
  int sx, sy, tx, ty, dx, dy;
  cin >> sx >> sy >> tx >> ty;

  dx = tx - sx;
  dy = ty - sy;
  addstr(dy, "U");
  addstr(dx, "R");
  addstr(dy, "D");
  addstr(dx + 1, "L");
  addstr(dy + 1, "U");
  addstr(dx + 1, "R");
  addstr(1, "D");
  addstr(1, "R");
  addstr(dy + 1, "D");
  addstr(dx + 1, "L");
  addstr(1, "U");

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 504
S = input()

deletes = -1
while len(S) + deletes > 0:
    # 削る
    test_s = S[:deletes]

    # 判定
    if len(test_s) % 2 == 0:
        l = test_s[:len(test_s) // 2]
        r = test_s[len(test_s) // 2:]

        if l == r:
            break

    deletes -= 1

# print(deletes, test_s, l, r)
print(len(test_s))


Measured memory_bytes: 2940
n = int(input())
A = input()
#print(len(A))
A = str(0) + A
count = 0
for i in range(1,n+1):
    if A[i]=='R': count+=1
#print(count)
ans = 0
for j in range(count+1,n+1):
    if A[j]=='R': ans+=1
print(ans)

Measured memory_bytes: 9480
N = int(input())
step = list(map(int, input().split()))
dp = [float('inf')] * N
dp[0] = 0
dp[1] = abs(step[0] - step[1])
for i, s in enumerate(step):
  if i < 2:
    continue
  dp[i] = min(dp[i - 2] + abs(step[i - 2] - step[i]), dp[i - 1] + abs(step[i - 1] - step[i]))
print(dp[N - 1])

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


long long int dp[201][100001];
long long int gen(int n,int W,vector<int>&arr,vector<int> &val)
{
    if(n==0 || W==0)
        return 0;
    if(dp[n][W]!=-1)
        return dp[n][W];
    if(arr[n-1]>W)
        return dp[n][W]=gen(n-1,W,arr,val);
    else
        return dp[n][W]=max(val[n-1]+gen(n-1,W-arr[n-1],arr,val),gen(n-1,W,arr,val));
}
int main()
{
    int n,W;
    cin>>n>>W;
    vector<int> arr(n),val(n);
    memset(dp,-1,sizeof(dp));
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        cin>>val[i];
    }
    //input part has been done
    long long int ans=gen(n,W,arr,val);
    cout<<ans;

}


Measured memory_bytes: 160648
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <set>
#include <map>
#include <unordered_set>
using namespace std;

int n, p;
int cnt0 = 0;
int cnt1 = 0;

int main() {
	ios_base::sync_with_stdio(0);
	//freopen("game.in", "r", stdin);
	//freopen("game.out", "w", stdout);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin >> n >> p;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		if (x & 1) {
			cnt1++;
		} else {
			cnt0++;
		}
	}
	long long ans = 1;
	
	for (int i = 0; i < cnt0; i++) {
		ans = ans * 2;
	}
	
	if (p == 1 && cnt1 == 0) {
		cout << 0;
		return 0;
	}
	
	cout << (1LL << cnt0) * (1LL << (max(0, cnt1 - 1)));
	
	
	return 0;
}

Measured memory_bytes: 256