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

int main() {
    int d, n; cin >> d >> n;
    //if (n == 100) minv = pow(100, d-1);
    long long minv = pow(100, d);
    /*
    int cnt = 1;
    while (cnt != n) {
        if (cnt%100 == 0) continue;
        cnt++;
    }
    */
    if (n == 100) cout << minv * 101 << endl;
    else cout << minv * n << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); ++i)
using ll = long long;
const ll INF = 100100100;
template <typename T> inline bool chmin(T& a, T b) { 
  if(a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> inline bool chmax(T& a, T b) {
  if(a < b) {
    a = b;
    return true;
  }
  return false;
}



long long dp[100010][3];
int main() {
    int N; cin >> N;
    long long a[100010][3]; // a[i], b[i], c[i] をそれぞれまとめて a[i][0], a[i][1], a[i][2] にしてしまう

   
    
    for (int i = 0; i < N; ++i) for (int j = 0; j < 3; ++j) cin >> a[i][j];

    // 初期化は既に 0 に初期化される
    // 初期条件も既に 0 で OK

    // ループ
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < 3; ++j) {
            for (int k = 0; k < 3; ++k) {
                if (j == k) continue;
                chmax(dp[i + 1][k], dp[i][j] + a[i][k]);
            }
        }
    }

    // 答え
    long long res = 0;
    for (int j = 0; j < 3; ++j) chmax(res, dp[N][j]);
    cout << res << endl;
}

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 1e5 + 5;

void solve(){
	ll h, w;
	cin >> h >> w;
	ll ans = h * w;
	REP(i, 0, 2) {
		REP(i, 1, h) {
			ll h1 = h - i;
			ll a = i * w;
			ll b = max(h1 / 2 * w, w / 2 * h1);
			ll c = h1 * w - b;
			ans = min(ans, max(abs(a - b), max(abs(a - c), abs(b - c))));
		}
		swap(h, w);
	}
	cout << ans << endl;
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    string s;
    int q;
    cin >> n >> s >> q;
    rep(qi,q){
        int k;
        cin >> k;
        int sta = -1;
        while(++sta < n){
            if(s[sta] == 'D') break;
        }
        if(sta == n){
            cout << 0 << endl;
            continue;
        }
        int j = min(sta + k, n);
        ll score = 0, cnt_c = 0, cnt_m = 0;
        for(int i = sta; i < j; ++i){
            if(s[i] == 'C'){
                score += cnt_m;
                ++cnt_c;
            }
            if(s[i] == 'M') ++cnt_m;
        }
        ll ans = score;
        for(int i = sta+1; i < n; ++i){
            if(s[i] == 'D'){
                int nj = min(i+k, n);
                for(int l = j; l < nj; ++l){
                    if(s[l] == 'C'){
                        score += cnt_m;
                        ++cnt_c;
                    }
                    if(s[l] == 'M') ++cnt_m;
                }
                ans += score;
                j = nj;
            }
            if(s[i] == 'C') --cnt_c;
            if(s[i] == 'M'){
                score -= cnt_c;
                --cnt_m;
            }
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 4272
#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(x) push_back(x)
#define all(x) x.begin(), x.end()
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 = 1e9;
const ll INF = 1e18;
const ld EPS = 1e-10;

const int MAX_N = 1e5;
ll fac[MAX_N+1], ifac[MAX_N+1], inv[MAX_N+1];

ll mpow(ll x, ll n){
    ll res = 1, now = x;
    while(n > 0){
        if(n & 1) res *= now, res %= MOD;
        now *= now, now %= MOD;
        n >>= 1;
    }
    return res;
}

void init(){
    rep2(i, 1, MAX_N){
        inv[i] = mpow(i, MOD-2);
    }
    //i!とi!の逆元
    fac[0] = 1, ifac[0] = 1;
    rep2(i, 1, MAX_N){
        fac[i] = (fac[i-1]*i) % MOD;
        ifac[i] = (ifac[i-1]*inv[i]) % MOD;
    }
}

ll comb(int n, int k){
    ll c = fac[n];
    c *= ifac[n-k], c %= MOD;
    c *= ifac[k], c %= MOD;
    return c;
}

ll perm(int n, int k){
    return(fac[n]*ifac[n-k])%MOD;
}

const int MAX_V = 5e3;
vector<int> es[MAX_V];
int subtree_size[MAX_V], max_size[MAX_V];

int dfs(int now, int pre, int size){
    int m = 0, s = 1;
    for(auto &e: es[now]){
        if(e == pre) continue;
        int tmp = dfs(e, now, size);
        s += tmp;
        m = max(m, tmp);
    }
    m = max(m, size-s);
    max_size[now] = m;
    subtree_size[now] = s;
    return s;
}

int main(){
    init();
    int N; cin >> N;
    rep(i, N-1){
        int u, v; cin >> u >> v; u--, v--;
        es[u].pb(v), es[v].pb(u);
    }
    dfs(0, -1, N);
    int g = -1;
    rep(i, N){
        if(max_size[i] <= N/2){
            if(g == -1) g = i;
            else{
                cout << (fac[N/2]*fac[N/2]) % MOD << endl;
                return 0;
            }
        }
    }
    vector<int> v;
    for(auto &e: es[g]) v.pb(dfs(e, g, N));
    int n = v.size();
    ll dp[n+1][N];
    fill(dp[0], dp[n+1], 0);
    dp[0][0] = 1;
    rep(i, n){
        rep(j, N){
            rep(k, v[i]+1){
                if(j+k >= N) break;
                dp[i+1][j+k] += dp[i][j]*((comb(v[i], k)*perm(v[i], k)) % MOD);
                dp[i+1][j+k] %= MOD;
            }
        }
    }
    ll ans = 0;
    rep(i, N){
        ll tmp = (fac[N-i]*dp[n][i]) % MOD;
        if(i&1) ans += MOD-tmp;
        else ans += tmp;
        ans %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 198272
#文字列比較はそのままできる
#(ex)"a" < "b" をif文で比較したらtrue.
N,L = gets.chomp.split(" ").map(&:to_i)
S = []
ans = ""
for i in 0..N-1 do
    S.push(gets.chomp.to_s)
end
S.sort! #比較のために整列
for i in 0..N-1 do
    ans = ans + S[i]
end
puts ans

Measured memory_bytes: 2300
#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;
const ll inf = 1e15;



int main(){FIN

    ll n;cin>>n;
    vll a(n); REP(i,n) cin>>a[i];
    ll gcd = a[0];
    REP(i,n-1) gcd = __gcd(gcd,a[i+1]);
    
    cout<<gcd<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
#include <string>
#include <algorithm>


using namespace std;

int main() {
    int K, A, B;
    cin >> K >> A >> B;
    for (int i = A; i <= B; i++) {
        if (i % K == 0) {
            cout << "OK" << endl;
            return 0;
        }
    }

    cout << "NG" << endl;
    return 0;
}

Measured memory_bytes: 3600
n=int(input())
lst=[]
for i in range(n):
    a=int(input())
    b=[]
    for j in range(a):
        x,y=map(int,input().split())
        x-=1
        b.append([x,y])
    lst.append(b)
ans=0
for i in range(2**n):
    on=[]
    switch=0
    for j in range(n):
        if ((i>>j)&1):
            on.append(j)
    for j in on:
        judge=lst[j]
        for k in judge:
            if k[1]==1:
                if not k[0] in on:
                    switch=1
            else:
                if k[0] in on:
                    switch=1
    if switch==0:
        ans=max(ans,len(on))

print(ans)

Measured memory_bytes: 73712
#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
    int a,b,c,z;
    scanf("%d %d %d",&a,&b,&c);
    z=a*100+b*10+c;
    if(z%4)cout <<"NO\n";
    else cout << "YES\n";
    return 0;
}

Measured memory_bytes: 256
#include <cstddef>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <array>
#include <list>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <valarray>
#include <utility>
#include <tuple>
#include <cmath>
#include <memory>
#include <random>
#include <fstream>
#include <locale>
#include <regex>
#include <complex>

using ll = long long;
using ull = unsigned long long;
using ld = long double;

//vector
template <class T>
using vec = std::vector<T>;

template <class T>
using vvec = vec<vec<T>>;

constexpr std::size_t operator""_sz(ull n) { return std::size_t(n); }

int main()
{
    using namespace std;
    // cerr.rdbuf(nullptr);

    int N, W;
    cin >> N >> W;
    vec<pair<double, int>> cosp(N);
    vec<int> v(N);
    vec<int> w(N);

    for (int i= 0; i < N; ++i)
    {
        cin >> v[i] >> w[i];

        cosp[i].first = v[i] / (double)w[i];
        cosp[i].second = i;
    }

    sort(cosp.rbegin(), cosp.rend());
    
    int remain = W;
    double ans = 0;

    for (auto e : cosp)
    {
        auto v = e.first;
        auto i = e.second;

        if (remain > 0)
        {
            if (remain >= w[i])
            {
                ans += v * w[i];
                remain -= w[i];
            }
            else
            {
                ans += v * remain;
                remain -= remain;
            }
        }

        //cout << v << " : " << ans << endl;
    }

    cout << fixed << ans << endl;

    return 0;
}


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

using namespace std;

#define ll long long
#define endl '\n'

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s;
    cin >> s;
    if (s[2] == s[3] && s[4] == s[5]) cout << "Yes";
    else cout << "No";
    return 0;
}

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

using namespace std;
using Int = long long int;

Int l, k;
vector<Int> dp;

Int dfs(int n) {
    if (n <= 0) return 0;
    if (dp[n] != -1) return dp[n];

    Int ret = n == 1 || n == k;
    ret += dfs(n - 2) + dfs(n - k - 1);

    return dp[n] = ret;
}

int main() {

    cin >> l >> k;
    dp.resize(l + 1, -1ll);
    Int ans = 0;
    for (int i = 0; i <= l; ++i) {
        ans += dfs(i);
    }
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 3096
#include <iostream>
using namespace std;
#define int long long

int fun(int a, int b, int c, int k) {
  int s = 0;
  if (a >= k) return k;
  else {
    k -= a;
    s += a;
  }
  //cout<<k<<"\n";
  if(b >= k) {
    //cout<<k<<"\n";
    return s;
  }
  else {
    k -= b;
    //cout<<k<<" "<<s<<"\n";
  }
  
  s -= (k);
  return s;
}

signed main() {
  int a, b, c, k;
  cin>>a>>b>>c>>k;
  cout<<(fun(a, b, c, k))<<"\n";
  return 0;
}
   

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

int n, l, r, s;
int main()
{
	cin >> n;
	while (n--) {
		scanf("%d %d", &l, &r);
		s += r - l + 1;
	}
    cout << s << endl;
    return 0;
}

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

b_list = []

c_list = []
cnt = 0
for a in a_list:
    if a <= 0:
        cnt += 1
    c_list.append(abs(a))

if cnt % 2 != 0:
    print(sum(c_list) - 2 * min(c_list))
else:
    print(sum(c_list))
# print(sum(b_list))


Measured memory_bytes: 14412
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto N = readln.chomp.to!int;
    auto memo = new long[][](10, 10);
    foreach (n; 1..N+1) {
        auto y = n%10;
        int x;
        while (n) {
            x = n;
            n /= 10;
        }
        ++memo[x][y];
    }

    long r;
    foreach (i; 1..10) {
        foreach (j; 1..10) {
            r += memo[i][j] * memo[j][i];
        }
    }
    writeln(r);
}

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

using namespace std;

int main() {
	char sh[150];
	int a,b,c,i,k,f,cal1,cal2,cal3;
	while (cin >> sh) {
		for (i=0;i<10;i++) {
		for (a=0;sh[a]!='+';a++);
		for (b=0;sh[b]!='=';b++);
		c=strlen(sh)-1; a--; b--; k=0; f=0;
		if (i==0) if ((sh[0]=='X' && sh[1]!='+') || (sh[a+2]=='X' && sh[a+3]!='=') || (sh[b+2]=='X' && sh[b+3]!='\0')) continue;
		while(a<200 || b<200){
			if (a>200) cal1=0; else if (sh[a]=='X') cal1=i; else cal1=sh[a]-'0';
			if (b>200) cal2=0; else if (sh[b]=='X') cal2=i; else cal2=sh[b]-'0';
			if (cal1+cal2+k>=10) {cal1=cal1+cal2+k-10; k=1;} else { cal1=cal1+cal2+k; k=0;}
			if (sh[c]=='X') cal3=i; else cal3=sh[c]-'0';
			if (cal1!=cal3) { f=1; break;}
			a=(a==0) ? 999 : a-1;
			b=(sh[b-1]=='+') ? 999 : b-1;
			c--;
		}
		if ((k==0 && sh[c]!='=') || (k==1 && ((sh[c]!='1' && sh[c]!='X') || sh[c-1]!='='))) f=1;
		if (f==0) { cout << i << endl; break;}
		}
        if (f==1) cout << "NA" << endl;
	}
	return 0;
}

Measured memory_bytes: 1140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
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 (a>b) { a=b; return 1; } return 0; }

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

    int N; cin >> N;
    string s,t; cin >> s >> t;


    int ans = 0;
    rep(i,N) {
        bool flag = true;
        rep(j,N-i) {
            if(s[i+j] != t[j]) {
                flag = false;
                break;
            }
        }
        if(flag) {
            ans = N-i;
            break;
        }
    }
    cout << 2 * N - ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using Tup = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define prt(v) cout<<(v)<<"\n";
#define fl cout<<flush;
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
#define endl "\n"
template <typename T> bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld pi=3.141592653589793238;

signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    string s;
    cin >> s;
    string t;
    cin >> t;
    vector<vector<ll>> dp(s.size()+1, vector<ll>(t.size()+1, 0));
    for(ll i=1;i<=s.size();++i)
        for(ll j=1;j<=t.size();++j){
            if(s[i-1]==t[j-1])dp[i][j]=dp[i-1][j-1]+1;
            else {
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
        }
    deque<char> ans;
    ll markS=s.size();
    ll markT=t.size();
    while(markS&&markT){
        if(dp[markS][markT]==dp[markS-1][markT])markS--;
        else if(dp[markS][markT]==dp[markS][markT-1])markT--;
        else {
            ans.emplace_front(s[markS-1]);
            markS--;markT--;
        }
    }
    for(auto p: ans)cout<<p;cout<<endl;
    return 0;
}


Measured memory_bytes: 70784
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define Would
#define you
#define please

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

	int H, W;
	cin >> H >> W;
	int A[52][52] = {};
	int white = 0;
	rep1(i, H) {
		string S;
		cin >> S;
		rep1(ii, W) {
			if (S[ii - 1] == '.') {
				A[i][ii] = 1;
				white++;
			}
		}
	}

	int B[52][52] = {};
	vector<pair<int, int>> que[2501];
	que[1].push_back(make_pair(1, 1));

	rep1(i, 2500) {
		for (pair<int, int> P : que[i]) {
			int x = P.first;
			int y = P.second;
			if (B[x][y] == 0 && A[x][y]) {
				B[x][y] = i;
				que[i + 1].push_back(make_pair(x - 1, y));
				que[i + 1].push_back(make_pair(x + 1, y));
				que[i + 1].push_back(make_pair(x, y - 1));
				que[i + 1].push_back(make_pair(x, y + 1));
			}
		}
	}

	if (B[H][W] == 0) co(-1);
	else co(white - B[H][W]);
	Would you please return 0;
}

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

using namespace std;
using ll = long long;
using P = pair<int, int>;

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;

bool comp(P a, P b) { return a.second < b.second; }

int main() {
#ifdef MYLOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
     int n, m; cin >> n >> m;
     vector<P> a(m);
     for (int i = 0; i < m; ++i){
         cin >> a[i].first >> a[i].second;
     }
     sort(a.begin(), a.end(), comp);

     int ans = 0, end = 0;
     for (int i = 0; i < m; ++i) {
         if (a[i].first >= end) {
             end = a[i].second;
             ++ans;
         }
     }
     cout << ans << endl;
}



Measured memory_bytes: 1024
//k_tourist
#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>
#define mod 1000000007
#define ll long long
#define mx 405
#define non __builtin_popcount
#define ml map<ll, ll> 
#define uml unordered_map<ll, ll>
#define ms map<string , ll> 
#define all(a) (a).begin(),(a).end()
#define ff first
#define ss second
#define pl pair<ll, ll>
#define vl vector<ll>
#define vll vector<pl>
#define tpl pair<ll, pl>
#define vlll vector<tpl>
#define vs vector<string>
#define pb push_back
#define mk make_pair
#define M_PI 3.14159265358979323846
#define endl '\n'
#define fst ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%I64d",&x)
#define inf ((ll)1e18 + 1)
#define bs binary_search
#define pq priority_queue
#define ub upper_bound
#define lb lower_bound
#define pow powr
#define sp(a) setprecision(a)
#define rep(i,a,b)  for (i=(a);i<(b);i++)
#define nrep(i,a,b) for (i=(a);i>(b);i--)
using namespace std;
using namespace __gnu_pbds;  

typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>  ordered_set;
 
ll powr(ll a,ll b)
{
	ll res=1;
	while(b)
	{
		if(b&1)res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res;
}

void flag(ll fl){

	if(fl)
	cout<<"NO";
	else
	cout<<"YES";
}

ll n, a[mx], dp[mx][mx], sum[mx];

ll slime(ll x, ll y){

    if(x == y)
    return 0;

    if(dp[x][y] != -1)
    return dp[x][y];

    ll i, j, ans= inf;

    rep(i, x, y)
    {
        ll tmp= sum[y]- sum[x-1] + slime(x, i) + slime(i+1, y);
        ans= min(ans, tmp);
    }

    return dp[x][y]= ans;

}
void bta_de_yarr(){

	ll i, j, fl=0, ans, m;
    cin>>n;

    rep(i, 0, n+1)
	rep(j, 0, n+1)
	dp[i][j]= -1;

    rep(i, 1, n+1)
    {
        cin>>a[i];

        sum[i]= sum[i-1] + a[i];
    }
	
    ans= slime(1, n);
	cout<<ans;
	// flag(fl);
	cout<<endl;
}

int main(){
    fst

	// freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
	ll t;
    t= 1;
	//cin>>t;
    while(t--){
        bta_de_yarr();
    }
    return 0;
}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Measured memory_bytes: 1536
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  int n;
  scanf("%d", &n);
  int ret = 0;
  while (n--) {
    int x;
    scanf("%d", &x);
    int cnt = 0;
    while (x % 2 == 0) {
      x /= 2;
      ++cnt;
    }
    ret += cnt;
  }
  printf("%d\n", ret);
  return 0;
}


Measured memory_bytes: 256
implicit none
integer:: n, i, j, a, b, count_1, count_2, count_3
integer,allocatable,dimension(:):: p

read(5,*) n, a, b
allocate(p(n))
read(5,*) (p(i),i=1,n)

count_1 = 0
count_2 = 0
count_3 = 0

do i = 1, n
    if (p(i) <= a) then
        count_1 = count_1 + 1
    else if (p(i) <= b) then
        count_2 = count_2 + 1
    else
        count_3 = count_3 + 1
    endif
enddo

write(6,*) min(count_1, count_2, count_3)

end

Measured memory_bytes: 256
#include <stdio.h>

int main (void){
    int N;
    scanf("%d", &N);

    int ans = 0;

    for (int i = 0;i < N; i++){
        int a[2];
        scanf("%d %d ",&a[0],&a[1]);
        ans += a[1] - a[0] + 1;
    }

    printf("%d", ans);

    return 0;
}

Measured memory_bytes: 128
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0);
#define END return EXIT_SUCCESS;
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR((I),0,(N))
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP((I),(N)) cin>>(V[I])
#define INS2(I,N,V1,V2) REP((I),(N)) cin>>(V1[I])>>(V2[I]);
#define INS3(I,N,V1,V2,V3) REP((I),(N)) cin>>(V1[I])>>(V2[I])>>(V3[I]);
#define OUT(P) cout<<(P)<<endl
#define OUT2(P1,P2) cout<<(P1)<<" "<<(P2)<<endl
#define OUT3(P1,P2,P3) cout<<(P1)<<" "<<(P2)<<" "<<(P3)<<endl
#define OUTS(I,N,V) REP((I),(N)) cout<<(V[i])<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}

int N,M,i,a,b;
deque<int> g[50];
inline void solve(){
  IN2(N,M);
  REP(i,M){
    IN2(a,b);
    a--;b--;
    g[a].pb(b);
    g[b].pb(a);
  }
  REP(i,N)OUT(g[i].size());
}

int main(int argc,char**argv){
  BEGIN
  solve();
  END
}


Measured memory_bytes: 256
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
using PLL = pair<LL, LL>;
using VI = vector<int>;
using VVI = vector<vector<int>>;
const int INF = 1e9;
const int MXN = 1e5 + 5;
const int MXV = 0;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define FOR(i, L, R) for (int i = L; i < (int)R; ++i)
#define FORD(i, L, R) for (int i = L; i > (int)R; --i)
#define IOS                                                                    \
    cin.tie(nullptr);                                                          \
    cout.tie(nullptr);                                                         \
    ios_base::sync_with_stdio(false);

int main()
{
    IOS;
    int N, W;
    vector<LL> dp(MXN);
    cin >> N >> W;
    fill(dp.begin(), dp.end(), 0);
    FOR(i, 0, N)
    {
        LL v;
        int w;
        cin >> w >> v;
        FORD(j, W, w - 1) { dp[j] = max(dp[j], dp[j - w] + v); }
    }
    cout << *max_element(dp.begin(), dp.begin() + W + 1) << '\n';
}


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

const int M = 50005;
vector< pair< int, pair< int, int> > > Ve;
int n, m;
int need[M];
vector< int> spt;
int link[505];

int find(int a) {
    return a == link[a] ? a : link[a] = find(link[a]);
}

int unite(int a, int b) {
    a = find(a);
    b = find(b);
    link[b] = a;
}

bool same(int a, int b) {
    return find(a) == find(b);
}


void init() {
    for(int i = 0; i <= 500; ++i) link[i] = i;
}


int main() {
    scanf("%d %d", &n, &m);
    for(int i = 0; i < m; ++i) {
        int u, v, w;
        scanf("%d %d %d", &u, &v, &w);
        Ve.push_back(make_pair(w, make_pair(u, v)));
    }

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

    int weight = 0;
    init();

    for(int i = 0; i < m; ++i) {
        int a = Ve[i].second.first, b = Ve[i].second.second;
        if(!same(a, b)) {
            unite(a, b);
            spt.emplace_back(i);
            weight += Ve[i].first;
        }
    }


    int res = 0, sum = 0;
    for(int i: spt) {
        int edge_used = 0;
        int tree_weight = 0;
        init();

        for(int j = 0; j < m; ++j) if(j != i) {
           int a = Ve[j].second.first, b = Ve[j].second.second;
           if(!same(a, b)) {
            unite(a, b);
            edge_used ++;
            tree_weight += Ve[j].first;
           }
        }

        if(edge_used != n - 1 or tree_weight != weight) {
            res ++;
            sum += Ve[i].first;
        }
    }

    cout << res << " " << sum << endl;
}



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

int main() {
	uint32_t N, K;
	cin >> N >> K;
	
	vector<uint32_t>a(N);
	for(uint32_t i=0; i<N; i++) cin >> a[i];
	
	sort(a.begin(), a.end());
	
	vector<bool> dp(K+1);

	for(uint32_t i=1; i<=K; i++) {
		for(uint32_t j=0; j<N; j++) {
			if(a[j] > i) break;
			
			if(!dp[i-a[j]]) {
				dp[i] = true;
				break;
			}
		}
	}
	
	string ans = dp[K] ? "First" : "Second";
	cout << ans;
	
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main(void){
    int i,n,*val,*cost,ans=0;
    scanf("%d",&n);
    val=(int*)malloc(sizeof(int)*n);
    cost=(int*)malloc(sizeof(int)*n);
    for(i=0;i<n;i++){
        scanf("%d",&val[i]);
    }
    for(i=0;i<n;i++){
        scanf("%d",&cost[i]);
    }
    for(i=0;i<n;i++){
        if(val[i]-cost[i]>0){
            ans+=val[i]-cost[i];
        }
    }
    printf("%d\n",ans);
    free(val);
    free(cost);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
int main(void) {
    long N;
    long M[5] = {0, 0, 0, 0, 0};
    long ans = 0;
    char cap[] = {'M', 'A', 'R', 'C', 'H'};
    std::string buf;
    // stdin
    std::cin >> N;
    for(int i = 0; i < N; i++) {
        std::cin >> buf;
        for(int j = 0; j < 5; j++) {
            if(buf[0] == cap[j]) {
                M[j] += 1;
            }
        }
    }
    // calc
    for(int i = 0; i < 5; i++) {
        for(int j = i + 1; j < 5; j++) {
            for(int k = j + 1; k < 5; k++) {
                ans += M[i] * M[j] * M[k];
            }
        }
    }
    // stdout
    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 256
program hrn;
 var
  i,j,t,a,b,c,x,s:longint;
 begin
  read(a,b,c,s);
  for i:=0 to a do
   for j:=0 to b do
    for t:=0 to c do
     if((i*500)+(j*100)+(t*50)=s)then inc(x);
   writeln(x);
  end.

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define int long long int
#define endl "\n"
#define mod 1000000007
#define ps(x,noOfDecimal) fixed<<setprecision(noOfDecimal)<<x

using namespace std;

signed main()
{
    if (fopen("input.txt", "r")) {
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    }
    std::ios::sync_with_stdio(false);
    int t = 1;
    // cin >> t;
    while (t--) {
        int n;
        cin >> n;
        int x = n / 2;
        if ((n) % 2 != 0) x++;
        long double y = (long double)x / (long double)n;
        cout << ps(y, 6);
    }
    return 0;
}

Measured memory_bytes: 3788
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    if(n/100==n%10) cout << "Yes";
    else cout << "No";
    cout << endl;
    return 0;
}



Measured memory_bytes: 256
D, G = map(int, input().split())
pi = []
ci = []
for _ in range(D):
    p, c = map(int, input().split())
    pi.append(p)
    ci.append(c)

ans =  float('inf')


for bit in range(1 << D ):
    sum = 0
    count = 0
    nokori = set(range(1, D + 1))

    for i in range(D):
        # if bit & (1 << D)で、bitにiが含まれているか（フラグが立っているか）を判定してくれるらしい
        #今回は、i×100点の問題を全て解く場合の処理を書く
        if bit & (1 << i):
            sum +=  100 * (i + 1) * pi[i] + ci[i]
            count += pi[i]
            nokori.discard(i + 1)

    if (sum < G ):
        use = max(nokori)
        n = min(pi[use-1], -(-(G- sum )// (use * 100) ) )
        count += n
        sum   += n * 100 * use 

    if  (sum >= G):
        ans = min(count, ans)

print(ans)



Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
using namespace std;
int main(void){
    int n,k,i,j;
    double ans=0,p;
    cin >> n >> k;
    for(i=1;i<=n;i++){
        j = i;
        p = 1;
        while(j<k){
            p*=0.5;
            j*=2;
        }
        ans += p;
    }
    cout << fixed << setprecision(10) << ans/n;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 10000000000
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

int main() {
  int N;
  cin >> N;
  bool F[N][10];
  vector<vector<ll> > P(N, vector<ll>(10));
  vector<ll> sum(10, 0);
  REP(i, N) { REP(j, 10) cin >> F[i][j]; }
  REP(i, N) { REP(j, 11) cin >> P[i][j]; }

  ll ans = -INF;
  for (int mask = 1; mask < (1 << 10); mask++) {
    ll sum = 0;
    REP(i, N) {
      int cnt = 0;
      REP(j, 10) if (mask & 1 << j) if (F[i][j]) cnt++;
      sum += P[i][cnt];
    }
    ans = max(ans, sum);
  }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const ll inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

template <typename T>
struct edge
{
    int src, to;
    T cost;

    edge(int to, T cost) : src(-1), to(to), cost(cost) {}

    edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

    edge &operator=(const int &x)
    {
        to = x;
        return *this;
    }

    operator int() const { return to; }
};

//Weighted edge set
template <typename T>
using Edges = vector<edge<T>>;

//Weighted graph
template <typename T>
using WeightedGraph = vector<Edges<T>>;

template <typename T>
vector<T> dijkstra(WeightedGraph<T> &g, int s)
{
    const auto INF = numeric_limits<T>::max();
    vector<T> dist(g.size(), INF);

    priority_queue<pair<T, int>, vector<pair<T, int>>, greater<pair<T, int>>> que;
    dist[s] = 0;
    que.emplace(dist[s], s);
    while (que.empty() != true)
    {
        T cost;
        int idx;
        tie(cost, idx) = que.top();
        que.pop();
        if (dist[idx] < cost)
            continue;
        for (auto &e : g[idx])
        {
            auto next_cost = cost + e.cost;
            if (dist[e.to] <= next_cost)
                continue;
            dist[e.to] = next_cost;
            que.emplace(dist[e.to], e.to);
        }
    }
    return dist;
}

int N, Q, K, a, b;

int main()
{
    cin >> N;
    WeightedGraph<ll> G(N);
    for (int i = 0; i < N - 1; i++)
    {
        ll c;
        cin >> a >> b >> c;
        a--, b--;
        G[a].emplace_back(b, c);
        G[b].emplace_back(a, c);
    }
    cin >> Q >> K;
    K--;
    auto dist = dijkstra(G, K);
    for (int i = 0; i < Q; i++)
    {
        cin >> a >> b;
        a--, b--;
        cout << dist[a] + dist[b] << "\n";
    }
}

Measured memory_bytes: 11120
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
using ll = long long;
using P = tuple<ll,ll,int>;

int main(){
    int h1,m1,h2,m2,k; cin >> h1 >> m1 >> h2 >> m2 >> k;
    cout << h2*60+m2-h1*60-m1-k << endl;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
const int64_t INF=9999999999999999;

int main() {
  int H,W;
  cin>>H>>W;
  char s[55][55];
  for(int i=1;i<=H;i++){
     for(int j=1;j<=W;j++){
        cin>>s[i][j];
     }
  }
  char t[55][55];
  
  for(int i=1;i<=H;i++){
     for(int j=1;j<=W;j++){
        int count2=0;
        if(s[i][j]=='.'){if(s[i-1][j]=='#'){count2++;}
                         if(s[i+1][j]=='#'){count2++;}
                         if(s[i][j-1]=='#'){count2++;}
                         if(s[i][j+1]=='#'){count2++;}
                         if(s[i+1][j+1]=='#'){count2++;}
                         if(s[i-1][j-1]=='#'){count2++;}
                         if(s[i-1][j+1]=='#'){count2++;}
                         if(s[i+1][j-1]=='#'){count2++;}
        t[i][j]=(char)(count2+'0');
        }
        else{t[i][j]='#';}
     }
  }
    

  for(int i=1;i<=H;i++){
     for(int j=1;j<=W;j++){
        cout<<t[i][j];
     }cout<<endl;
  }
return 0;}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>

using namespace std;

int main()
{
    int A = 0;
    int B = 0;

    cin >> A >> B;

    int result = 0;

    for (int i=0; i<2; i++) {
        if (A < B) {
            result += B;
            B -= 1;
        } else {
            result += A;
            A -= 1;
        }
    }

    cout << result;

    return 0;
}   


Measured memory_bytes: 256
a,b,c = gets.split.map(&:to_i)
if a == 7 && b == 5 && c == 5
puts "YES"
elsif a == 5 && b == 7 && c == 5
puts "YES"
elsif a == 5 && b == 5 && c == 7
puts "YES"
else
puts "NO"
end

Measured memory_bytes: 1788
N = gets
arr = gets.split.map(&:to_i)

if arr[0] != 0
  puts 0
  exit
end

points = arr.sort.group_by { |i| i }.map{|k, v| [k, v.count]}.to_h
if points[0] != 1
  puts 0
  exit
end

counter = 1
points.each_with_index do |(length, count), index|
  next if index == 0
  if length != index
    puts 0
    exit
  end

  counter *= points[index - 1] ** count
end

puts counter % 998244353

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

using namespace std;

int main() {
    string s;
    int K;
    set<string> set_;
    vector<string> vec_;

    cin >> s;
    cin >> K;

    for(int i = 0; i < s.size(); i++) {
        for(int j = K; j > 0 ; j--) {
            set_.insert(s.substr(i, j));
            vec_.push_back(s.substr(i,j));
        }
    }

    {
        //setを使った実装
        auto itr = set_.begin();
        for(int i = 1; i < K; i++ ) {
            itr++; //setはbidirectional iteratorを返すので、直接+Kみたいなことはできない。vectorはrandom iteratorなので出来る。
        }
        //cout << *(itr)<< endl;
    }

    {
        //uniqueを使った実装（隣り合う重複要素を削除する、隣り合ってない場合は削除されない。事前ソートが必要。勝手にコンテナから要素が削除されることは無いので、自前で削除する必要がある。）
        sort(vec_.begin(), vec_.end());
        auto itr = unique(vec_.begin(), vec_.end());
        vec_.erase(itr, vec_.end());

        cout << *(vec_.begin() + K -1) << endl;
    }
}

Measured memory_bytes: 3068
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF (1<<30)-1
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
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; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int n;  
bool used[110];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> n;
    vector<Pii> red(n), blue(n);
    rep(i, 0, n) {
        int x, y; cin >> x >> y;
        red[i] = mp(x, y);
    }
    rep(i, 0, n) {
        int x, y; cin >> x >> y;
        blue[i] = mp(x, y);
    }
    int ans = 0;
    sort(all(red)); sort(all(blue));
    rep(i, 0, n) {
        int y = -1, itr = -1;
        rep(j, 0, n) {
            if (!used[j] && red[j].first < blue[i].first && red[j].second < blue[i].second) {
                if (y < red[j].second) {
                    y = red[j].second;
                    itr = j;
                }
            }
        }
        if (itr == -1) continue;
        else {
            used[itr] = true;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
	int N;
	long MOD = 1000000007L;
	String[] TOKENS = { "A", "C", "G", "T" };
	Map<String, Long>[] memo;

	Main() {
		Scanner in = new Scanner(System.in);
		N = in.nextInt();
		in.close();
		this.memo = new Map[N + 1];
		for (int i = 0; i < this.memo.length; ++i) {
			this.memo[i] = new HashMap<String, Long>();
		}
	}

	long calc() {
		return dfs(0, "TTT");
	}

	boolean isOK(String last4) {
		if (last4.contains("AGC")) {
			return false;
		}
		for (int i = 0; i < 3; ++i) {
			// 交換する
			char[] vals = last4.toCharArray();
			vals[i] = last4.charAt(i + 1);
			vals[i + 1] = last4.charAt(i);
			String s = new String(vals);
			if (s.contains("AGC")) {
				return false;
			}
		}
		return true;
	}

	long dfs(int current, String last3) {
		if (this.memo[current].containsKey(last3)) {
			return (Long) (this.memo[current].get(last3));
		}
		if (current == N) {
			return 1;
		}
		long result = 0;
		for (String c : TOKENS) {
			if (isOK(last3 + c)) {
				result = (result + dfs(current + 1, last3.substring(1, last3.length()) + c)) % MOD;
			}
		}
		memo[current].put(last3, result);
		return result;
	}

	public static void main(String[] args) {
		Main ins = new Main();
		System.out.println(ins.calc());
	}

}


Measured memory_bytes: 34380
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define INF 1100000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define Decimal fixed << setprecision(20)
#define SHOWP(x) cerr<<"["<<(x).FI<<", "<<(x).SE<<"]";
#define SHOWX(x) cerr<<#x<<": "<<x<<endl;
#define SHOWVEC(v, e) REP(i, e) cerr << (v[i]) << ' '; cerr << endl;
#define SHOW2D(a, h, w) REP(i, h){REP(j, w)cerr<<setw(3)<<(a[i][j])<<' ';cerr<<endl;}

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


int main()
{
  int N, K; cin >> N >> K;
  vector<ll> a(N);
  REP(i, N) cin >> a[i];
  vector<ll> ps(a), as(a);
  REP(i, N) ps[i] = max(0LL, ps[i]);
  REP(i, N - 1) {
    as[i + 1] += as[i];
    ps[i + 1] += ps[i];
  }

  auto psum = [](vector<ll>& v, int l, int r)->ll {
    if (r < l) return 0;
    else if (l == 0) return v[r];
    else return v[r] - v[l - 1];
  };
  ll ans = 0;
  for (int i = 0; i + K - 1 < N; i++) {
    ll x = psum(ps, 0, i - 1);
    ll y = max(0LL, psum(as, i, i + K - 1));
    ll z = psum(ps, i + K, N - 1);
    ans = max(ans, x + y + z);
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

int main()
{
	string s;
	cin >> s;
	int ans = 0;
	for(int i = 0 ; i < s.size() / 2 ; i++)
	   ans+=(s[i] != s[s.size() - i - 1]);
	
	cout << ans ;
}

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

string s;
bool exist[26];

int main() {
	cin >> s;
	for(int i = 0; i < 26; ++i) {
		exist[i] = false;
	}
	for(int i = 0; i < s.length(); ++i) {
		exist[s[i] - 'a'] = true;
	}
	for(int i = 0; i < 26; ++i) {
		if(exist[i] == false) {
			cout << (char)(i + 'a') << endl;
			break;
		}
		else if(i == 25) {
			cout << "None" << endl;
		}
	}
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        
        if(a * b > c * d){
            System.out.println(a * b);
        }else if(a * b < c * d){
            System.out.println(c * d);
        }else if(a * b == c * d){
            System.out.println(a * b);
        }
    }
}

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

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

  if( (n[0]==n[1] && n[1]==n[2]) || (n[1]==n[2] && n[2]==n[3]) ) 
    cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
W = {'m':1000,'c':100,'x':10,'i':1}
K = ['m','c','x','i']
for i in range(int(input())):
    x = input()
    tmp = 1
    r = 0
    for w in list(x):
        if w == ' ':continue
        if w in K:
            r += W[w] * tmp
            tmp = 1
        else:
            tmp = int(w)

    div = 1000
    res = ''
    for i in range(4):
        d,r = divmod(r,div)
        if d > 0:
            res += ('' if d == 1 else str(int(d))) + K[i]
        div /= 10

    print(res)

Measured memory_bytes: 6732
/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=1e18;
using P=pair<int,int>;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int n,m,a[55]={},b[55]={},ans=0,par[55]={},f;
struct unionfind {
  vector<int> par;
  unionfind(int n) : par(n,-1) {}
  void init(int n) {par.assign(n,-1);}
  int find(int x) {
    if (par[x]<0) return x;
    else return par[x]=find(par[x]);
  }
  bool issame(int x,int y) {
    return find(x)==find(y);
  }
  bool unit(int x,int y) {
    x=find(x),y=find(y);
    if (x==y) return false;
    if (par[x]>par[y]) swap(x, y); 
    par[x]+=par[y];
    par[y]=x;
    return true;
  }
  int size(int x) {
    return -par[find(x)];
  }
};
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for(int i=0; i<m; i++) {
    cin >> a[i] >> b[i];
    a[i]--,b[i]--;
  }
  for(int i=0; i<m; i++) {
    unionfind uf(n);
    for(int j=0; j<n; j++) {
      par[j]=j;
    }
    for(int j=0; j<m; j++) {
      if(i!=j) {
        uf.unit(a[j],b[j]);
      }
    }
    f=0;
    for(int i=0; i<n-1; i++) {
      if(!uf.issame(i,i+1)) {
        f=1;
      }
    }
    if(f) {
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<vector>
using namespace std;
#define read freopen("in.in","r",stdin)
#define write freopen("out.out","w",stdout)
#define FastIO ios::sync_with_stdio(0)
typedef long long ll;
int n, m;
vector<vector<int>>grid;
int memo[100005]; 
int solve(int idx) {
	int &ret = memo[idx];
	if (ret != -1)return ret;
	ret = 0;
	for (int i = 0; i < grid[idx].size(); i++)
		ret = max(ret, solve(grid[idx][i]) + 1);
	return ret;
}
int main() {
	FastIO;
#ifndef ONLINE_JUDGE
	//write; read;
#endif 
	memset(memo, -1, sizeof memo);
	cin >> n >> m;
	grid.resize(n + 1);
	int x, y;
	for (int i = 0; i < m; i++) {
		cin >> x >> y;
		grid[x].push_back(y);
	}
	int mx = 0;
	for (int i = 1; i <=n; i++)
		mx = max(mx, solve(i));
	cout << mx << endl;
		
	return 0;
}

Measured memory_bytes: 7424
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;
typedef long long ll;
int main() {
	int n;
	ll W;
	cin >> n >> W;
	int w1;
	ll v;
	cin >> w1 >> v;
	vector<ll> V[4];
	V[0].push_back(v);
	for (int i = 1; i < n; i++) {
		int w;
		ll v;
		cin >> w >> v;
		V[w - w1].push_back(v);
	}
	for (int i = 0; i < 4; i++) {
		sort(V[i].begin(), V[i].end());
	}
	vector<ll> S[4];
	for (int i = 0; i < 4; i++) {
		ll sum = 0;
		S[i].push_back(sum);
		for (int j = V[i].size()-1; j >=0; j--) {
			sum += V[i][j];
			S[i].push_back(sum);
		}
	}
	ll ans = 0;
	for (ll i = 0; i < S[0].size();i++) {
		for (ll j = 0; j < S[1].size(); j++) {
			for (ll k = 0; k < S[2].size(); k++) {
				for (ll l = 0; l < S[3].size(); l++) {
					if (i*w1 + j*(w1 + 1) + k*(w1 + 2) + l*(w1 + 3) <= W) {
						ans = max(ans, S[0][i] + S[1][j] + S[2][k] + S[3][l]);
					}
				}
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256