akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

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

int cans(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}



int main() {
  string S,T;
  cin >> S >> T;
  int ans = 0;
  rep(i,S.size()-T.size()+1) {
	int tmp = 0;
	rep(j,T.size()) {
	  //	  cout << S[i+j];
	  if(S[i+j] == T[j]) tmp++;
	}
	//	cout << endl;
	ans = max(ans,tmp);
  }
  cout << T.size() - ans << endl;
}



Measured memory_bytes: 3180
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
using namespace std;

typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int KN = 505;

int h, w;
string mat[KN];

int main() {
	ios::sync_with_stdio(false);
	cin >> h >> w;
	for (int i = 0; i < h; ++i)
		cin >> mat[i];
	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) {
			if (j == 0)
				cout.put('.');
			else if (j == w - 1)
				cout.put('#');
			else if (i & 1)
				cout.put('#');
			else if (mat[i][j] == '#' && !(i & 1))
				cout.put('#');
			else 
				cout.put('.');
		}
		cout.put('\n');
	}
	cout.put('\n');
	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) {
			if (j == 0)
				cout.put('#');
			else if (j == w - 1)
				cout.put('.');
			else if (!(i & 1))
				cout.put('#');
			else if (mat[i][j] == '#' && (i & 1))
				cout.put('#');
			else
				cout.put('.');
		}
		cout << "\n";
	}
	cout << flush;
	return 0;
}

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

int main() {
    int N, K, Q, t;
    int seikai[100005] = {};
    cin >> N >> K >> Q;
    for (int i = 0; i < Q; i++) {
        cin >> t;
        seikai[t-1]++;
    }
    for (int i = 0; i < N; i++) {
        if (K - (Q - seikai[i]) > 0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}

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

int main() {
  int N; cin >> N;
  vector<ll> a(N);
  for(int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  ll count = 0;
  for(int i = 0; i < N; i++) {
    for(int j = 0; ; j++) {
      if(a.at(i) % 2 == 0) {
        a.at(i) /= 2;
        count++;
      } else {
        break;
      }
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 384
package main

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

func main() {
	parseProblem(os.Stdin)
}

func parseProblem(r io.Reader) {
	const (
		initialBufSize = 100000
		maxBufSize     = 1000000
	)
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	a, b, n := scanInt(sc), scanInt(sc), scanInt(sc)

	fmt.Println(exp(a, b, min(b-1, n)))
}

func exp(a, b, x int) int {
	return a * x / b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1764
#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 setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ld, ld> pdd;
const ll MOD = 1e6+3;
//const ll MOD = 998244353;
const int inf = 1e8;
const ll INF = 1e16;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

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

//mpow(x,n)で(x^n)をO(log(n))で計算
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;
}

//setcomb()でfac,ifac,invを全て計算
void setcomb(){
    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;
    }
}

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

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

int main(){
    setcomb();
    int Q;
    cin >> Q;
    rep(i, Q){
        ll x, d, n;
        cin >> x >> d >> n;
        if(d == 0){
            cout << mpow(x, n) << endl;
            continue;
        }
        ll k = (x*inv[d])%MOD;
        if(k+n-1 >= MOD) cout << 0 << endl;
        elif(k == 0) cout << 0 << endl;
        else{
            ll ans = (mpow(d, n) * perm(k+n-1, n)) % MOD;
            cout << ans << endl;
        }
    }
}

Measured memory_bytes: 24320
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
using namespace std;
using namespace __gnu_pbds;
#define int long long int
#define pb push_back
#define vec vector<int>
#define fo(i, n) for (int i = 0; i < n; i++)
#define foo(i, a, b) for (int i = a; i < b; i++)
#define mp make_pair
#define deb(x) cout << #x << " --> " << x << endl;
#define deb1a(v)                  \
    cout << #v << "--->" << endl; \
    for (auto it : v)             \
        cout << it << " ";        \
    cout << endl;
#define deb2a(v)                  \
    cout << #v << "--->" << endl; \
    for (auto it : v)             \
    {                             \
        for (auto it1 : it)       \
        {                         \
            cout << it1 << " ";   \
        }                         \
        cout << endl;             \
    }
#define deb3a(v)                               \
    cout << #v << "-->" << endl;               \
    for (auto it : v)                          \
    {                                          \
        cout << it.fi << " " << it.se << endl; \
    }
#define mod 1000000007
#define so(v) sort(v.begin(), v.end())
#define fi first
#define se second
#define db1(x) cout << #x << "=" << x << endl
#define db2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
int power(int x, unsigned int y, int p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
int mI(int a, int m)
{
    return power(a, m - 2, m);
}
vector<vector<int>> dir = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}, {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};

#define MAXN 10000001
#define double long double


void solve()
{
    int n;
    cin >> n;
    vec v1(n), v2(n);
    fo(i,n){
        int x, y;
        cin >> x >> y;
        v1[i] = x + y;
        v2[i] = x - y;
    }
    so(v1);
    so(v2);
    int ans = abs(v1[0] - v1.back());
    ans = max(ans, abs(v2[0] - v2.back()));
    cout << ans;
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    srand(time(0));

    // FILE *fin = freopen("ip.txt","r",stdin);
    // FILE *fout = freopen("op.txt","w",stdout);
    int t = 1, nn = 1;
    //cin >> t;
    while (t--)
    {
        // cout << "Case #" << nn << ":"
        //      << " ";
        // nn++;
        
        solve();
    }
}

Measured memory_bytes: 6368
#include <iostream>
#include <algorithm>
#include <functional>
#include <set>
#include <vector>
#include <array>
#include <cmath>
#include <queue>
#include <numeric>

#define r(i, v, n) for(int i = v; i < n; i++)
#define re(i, v, n) for(int i = v; i <= n; i++)
#define rr(e, v) for(auto&& (e) : (v))

using namespace std;
using ll = long long;
using ul = unsigned long;

void combination(vector<vector<int>> &v, int n, int r)
{
    std::string bit_mask(r, 1);
    bit_mask.resize((unsigned long)n, 0);

    int c = 0, j;
    do {
        j = 0;
        for (int i = 0; i < n; ++i) {
            v[c][j++] = bit_mask[i];
        }
        c++;
    } while (std::prev_permutation(bit_mask.begin(), bit_mask.end()));
}

long ncr(int n, int r) {
    long a = 1;
    r = r > n - r ? n - r : r;
    for(int i = 1;  i <= r ; i++, n--) {
        if(n % i == 0) {
            a *= n / i;
        } else if (a % i == 0) {
            a = a / i * n;
        } else {
            a = (a * n) / i;
        }
    }
    return a;
}

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

    int n, m;
    cin >> n >> m;
    auto k = vector<int>(m);
    auto s = vector<vector<int>>(m);
    auto p = vector<int>(m);
    r(i, 0, m) {
        cin >> k[i];
        auto v = vector<int>(k[i]);
        r(j, 0, k[i]) {
            cin >> v[j];
        }
        s[i] = v;
    }
    r(i, 0, m) {
        cin >> p[i];
    }

    vector<vector<int>> ra;
    r(i, 0, n + 1) {
        int iv = ncr(n, n - i);
        auto ra_tmp = vector<vector<int>>(iv, vector<int>(n));
        combination(ra_tmp, n, (n - i));
        copy(ra_tmp.begin(), ra_tmp.end(), back_inserter(ra));
    }

    r(i, 0, m) {
        vector<vector<int>> rr;
        copy_if(ra.begin(), ra.end(), back_inserter(rr), [p, i, s, n, k](vector<int> v) {
            int sum = 0;
            r(j, 0, k[i]) {
                sum += v[s[i][j] - 1];
            }
            return p[i] == sum % 2;
        });
        ra = rr;
    }

    cout << ra.size() << endl;

    return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long int ll;
typedef unsigned long long int ull;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> o_set; 

#define     int                 ll
#define     pb                  push_back
#define     mp                  make_pair
#define     xx                  first
#define     yy                  second    
#define     all(a)              a.begin(),a.end()
#define     vi                  vector<int>
#define     vpi                 vector<pii>
#define     pii                 pair<int, int>
#define     present(DT, val)    (DT.find(val) != DT.end()) //for set and map
#define     cpresent(DT, val)   (find(all(DT),val) != DT.end()) //vectors
#define     input               "/home/pollution/Desktop/WorkSpace/C++/Files/input.txt"
#define     output              "/home/pollution/Desktop/WorkSpace/C++/Files/output1.txt"
#define     error               "/home/pollution/Desktop/WorkSpace/C++/Files/error.txt"
#define     IO()                ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define     INF                 2e18
#define     MOD                 1000000007
#define     clr(x)              memset(x, 0, sizeof(x))
#define     init(x, a)          memset(x, a, sizeof(x))
#define     out(a)              for (auto i: a) cout<<i<<' '; cout<<'\n'
#define     cpy(a,b)            memcpy(a,b,sizeof(b))
#define     is(a)               to_string(a)
#define     ci(a,c)             a-c
#define     db(i)               cout<<"point :"<<i<<'\n';
#define     setd(val,n)         cout<<fixed<<setprecision(n)<<val<<'\n'

void solve(){
    int n,m, sum = 0, val; cin>>n>>m;
    for(int i = 0; i < m; ++i) cin>>val, sum+=val;
    if(n<sum) cout<<"-1\n";
	else cout<<n-sum<<'\n';
}

signed main() { 
    IO();
    
    int t=1;
    // cin>>t;
    while(t--) solve();
    return 0; 
}

Measured memory_bytes: 3652
N, A, B, C = map(int, input().split())
l = [int(input()) for i in range(N)]
INF = 10**9

def dfs(cur, a, b, c):
    if cur == N:
        return abs(a-A)+abs(b-B)+abs(c-C)-30 if min(a,b,c)>0 else INF
    ret0 = dfs(cur+1, a,b,c)#何も選ばない
    ret1 = dfs(cur+1, a+l[cur], b, c)+10 #Aに使用する竹にaを追加
    ret2 = dfs(cur+1, a, b+l[cur], c)+10 
    ret3 = dfs(cur+1, a, b, c+l[cur])+10
    return min(ret0, ret1, ret2, ret3)
print(dfs(0,0,0,0))

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

int main() {
    string s;
    cin >> s;
    int n=s.size();
    string comp="";
    rp(i,n) comp=comp+to_string(i%2);
    int change=0;
    rp(i,n){
        if(s.at(i)!=comp.at(i)) change++;
    }
    cout << min(change,n-change) << endl;
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define llenar(a,val)   memset(a,val,sizeof(a))
#define pb          push_back 
#define endl        "\n"
#define mostrar(x,y) cout<<x<<" "<<y<<endl;
#define f           first
#define s           second
#define mod         1000000007
#define EPS         1e-9
using namespace std;
typedef pair<int,int> ii;
typedef pair<pair<int,int>,int> iii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef long long ll;
typedef vector< pair<pair<int,int>,int> > viii;




int main(){
    ofstream out("output.txt");
    			
	int n;
	cin>>n;
	ll res = 0;
	for(int i =1;i<=n-1;i++){
		res+=i;
	}
	cout<<res<<endl;
    return 0;
}

 
 







Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <stack>
#include <string>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <list>
#include <string.h>
#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

struct node{
	int key;
	node *parent, *left, *right;
};

node *root, *NIL;

void insert(int k) {
	node *y = NIL;
	node *x = root;
	node *z;

	z = (node *)malloc(sizeof(node));
	z->key = k;
	z->left = NIL;
	z->right = NIL;

	while( x != NIL) {
		y = x;
		if( z->key < x->key) x = x->left;
		else x = x->right;
	}
	z->parent = y;
	if( y == NIL) {
		root = z;
	} else if( z->key < y->key){
		y->left = z;
	} else {
		y->right = z;
	}
}

string find(int k) {
	node *x = root;
	node *y = NIL;
	while( x != NIL && k != x->key) {
		if( k < x->key) x = x->left;
		else if( k > x->key) x = x->right;
	}
	if( x == NIL) return "no";
	else return "yes";
}


void Preorder(node *t) {
	if( t == NIL) return;
	printf(" %d", t->key);
	Preorder(t->left);
	Preorder(t->right);
}

void Inorder(node *t) {
	if( t == NIL) return;
	Inorder(t->left);
	printf(" %d", t->key);
	Inorder(t->right);
}

void Postorder(node *t) {
	if( t == NIL) return;
	Postorder(t->left);
	Postorder(t->right);
	printf(" %d", t->key);
}

int main(){
	int x, n;
	string st;
	cin >> n;
	for( int i = 0; i < n; i++) {
		cin >> st;
		if(st[0] == 'i') {
			cin >> x;
			insert(x);
		} else if(st[0] == 'p'){
			Inorder(root);
			cout << endl;
			Preorder(root);
			cout << endl;
		} else {
			cin >> x;
			cout << find(x) <<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 19976
def main():
    X,Y = map(int, input().split())
    # X=a+bかつY=2a+4bとなるようなa,bが存在するかどうか
    for a in range(X+1):
        b = X-a
        if Y==(2*a+4*b):
            print('Yes')
            return
    print('No')

main()


Measured memory_bytes: 9104
#include <bits/stdc++.h>
#define rep(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define repr(i, n, m) for (int i = (int)(n) - 1; i >= (int)(m); i--)
using namespace std;
using ll = int64_t;
const int MOD = 1000000007; // 10^9+7

int main() {
    string S;
    int Q;
    cin >> S >> Q;
    bool nr = true; // Sが反転されていない状態の時true

    rep(i, 0, Q)
    {
        int T;
        cin >> T;
        if (T == 1)
        {
            nr = !nr;
        }
        else
        {
            int F;
            string C;
            cin >> F >> C;
            if (nr)
            {
                if (F == 1)
                {
                    S.insert(0, C);
                }
                else
                {
                    S.insert(S.size(), C);
                }
            }
            else
            {
                if (F == 1)
                {
                    S.insert(S.size(), C);
                }
                else
                {
                    S.insert(0, C);
                }
            }
            
        }
    }

    if(!nr) reverse(S.begin(), S.end());
    cout << S << endl;
}


Measured memory_bytes: 900
use std::io::stdin;

fn main() {
    let mut input = String::new();
    stdin().read_line(&mut input);
    let mut stack = [0; 2];
    for (i, j) in input.split_whitespace().enumerate() {
        stack[i] = j.parse().unwrap()
    }
    let mut times = stack[0] / stack[1];
    if stack[0] % stack[1] != 0 && stack[1] != 1 {times+=1}
    if stack[0] < stack[1] { times = 1};
    println!("{}", times);
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main(){
    int A, B, C, D, N, K, H, X, Y, ans=0;
    string S;
    cin >> N >> K >> X >> Y;

    ans = (A+B)*H/2;


    for(int i=1;i<=N;i++){
	if(i<=K)
	    ans+=X;
	else
	    ans+=Y;
    }
    
    cout <<ans<<endl;
    
    // if(A<B)
    // 	cout << 0<<endl;
    // else
    // 	cout <<10<<endl;
    

    // string S;
    // cin >>S;
    // cout << S + "pp"<<endl;

    // if(S[0]==S[1] && S[1]==S[2] && S[2]==S[3])
    // 	puts("SAME");
    // else
    // 	puts("DIFFERENT");    
    	
}


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

using namespace std;
using ll = long long;
#define int ll
using PII = pair<int, int>;
template <typename T> using V = vector<T>;
template <typename T> using VV = vector<V<T>>;
template <typename T> using VVV = vector<VV<T>>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll INF = (1LL<<60);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

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

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

  int n, m, x;
  cin >> n >> m >> x;
  V<int> t(n);
  REP(i, n) cin >> t[i];
  VV<PII> g(n);
  REP(i, m) {
    int a, b, d;
    cin >> a >> b >> d, a--, b--;
    g[a].PB({b, d});
    g[b].PB({a, d});
  }

  // d[i][j][k] = (頂点iを最後に通ってtypeKを通ってからj分経った)
  VVV<int> d(n, VV<int>(x+1, V<int>(2, INF)));
  d[0][0][0] = 0;
  priority_queue<V<int>, VV<int>, greater<V<int>>> que;
  que.push({d[0][0][0], 0, 0, 0});

  while(que.size()) {
    V<int> v = que.top(); que.pop();
    int cost = v[0], ver = v[1], time = v[2], type = v[3];
    if(d[ver][time][type] < cost) continue;
    // cout << v << endl;
    for(auto i: g[ver]) {
      if((type == 0 && t[i.first] == 2 && time+i.second < x)
        || (type == 1 && t[i.first] == 0 && time+i.second < x)) continue;

      int ntype;
      int ntime;
      if(t[i.first]==0 || t[i.first]==2) ntime = 0;
      else ntime = min(x, time+i.second);
      if(t[i.first]==0) ntype=0;
      else if(t[i.first]==1) ntype=type;
      else if(t[i.first]==2) ntype=1;

      if(d[i.first][ntime][ntype] > d[ver][time][type] + i.second) {
        d[i.first][ntime][ntype] = d[ver][time][type] + i.second;
        que.push({d[i.first][ntime][ntype], i.first, ntime, ntype});
      }
    }
  }

  int ans = INF;
  REP(i, x+1) REP(j, 2) chmin(ans, d[n-1][i][j]);
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 114660
#include <iostream>
#include <deque>
#include <vector>
using namespace std;
int main()
{
	int n;
	cin >> n;
	deque<int> v;
	for (int i = 1;i <= n;i++)
	{
		int a;
		cin >> a;
		if (i % 2 == n % 2)
		{
			v.push_front(a);
		}
		else
			v.push_back(a);
	}
	for (int i = 0;i < n;i++)
	{
		cout << v.front()<<" ";
		v.pop_front();
	}
	//system("pause");
	return 0;
}

Measured memory_bytes: 2944
#include <iostream>
#include <climits>
#include <cmath>
#include <vector>
#include <map>
#include <set>
 
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

#define MOD 1000000007LL

map<ll, ll> t;

int T;
ll N, A, B, C, D;
ll minc;

ll count(ll, ll, ll);

int main()
{
  ll ans;

  cin >> T;

  for (int i=0; i<T; i++) {
    minc = LLONG_MAX;
    cin >> N >> A >> B >> C >> D;
    ans = count(N, 0, 0);
    cout << ans << endl;
//printf("t.size()=%lu\n", t.size());
/*
for (auto it=t.begin(); it!=t.end(); it++) {
  printf("t[%lld]=%lld, ", it->first, it->second);
}
printf("\n");
*/
    t.clear();
  }

  return 0;
}

ll count(ll num, ll coins, ll d) {
  ll a1, a2;
  decltype(t)::iterator itt;

//printf("%*scount(%lld, %lld, %lld)\n", (int)d, "", num, coins, d);

  if (num == 1) {
    if (coins+D<minc) minc = coins+D;
//printf("%*scount(%lld, %lld, %lld)=%lld\n", (int)d, "", num, coins, d, D);
    return D;
  }
  if (num == 0) {
    if (coins<minc) minc = coins;
//printf("%*scount(%lld, %lld, %lld)=0\n", (int)d, "", num, coins, d);
    return 0;
  }

//  num*D < LLONG_MAX
//  num < LLONG_MAX/D
  if (num < LLONG_MAX/D) {
    a1 = num*D;
  } else {
    a1 = LLONG_MIN;
  }
  itt = t.find(num);  //num から0までの最小値（確定値）
  if (itt != t.end()) {
//printf("%*scount(%lld, %lld, %lld)=%lld m\n", (int)d, "", num, coins, d, itt->second);
    return itt->second;
  }

// 2で割る
  if (num%2 == 0) {
    a2 = count(num/2, coins+A, d+1)+A;
    if (a1 < 0 || a2 < a1) a1 = a2;
  } else {
    a2 = count((num+1)/2, coins+D+A, d+1)+D+A;
    if (a1 < 0 || a2<a1) a1 = a2;
    a2 = count((num-1)/2, coins+D+A, d+1)+D+A;
    if (a1 < 0 || a2<a1) a1 = a2;
  }
  
//3で割る
  switch (num%3) {
  case 0:
    a2 = count(num/3, coins+B, d+1)+B;
    if (a1 < 0 || a2 < a1) a1 = a2;
    break;
  case 1:
    a2 = count((num-1)/3, coins+D+B, d+1)+D+B;
    if (a1 < 0 || a2 < a1) a1 = a2;
    break;
  case 2:
    a2 = count((num+1)/3, coins+D+B, d+1)+D+B;
    if (a1 < 0 || a2 < a1) a1 = a2;
    break;
  }

//5で割る
  switch (num%5) {
  case 0:
    a2 = count(num / 5, coins+C, d+1)+C;
    if (a1 < 0 || a2 < a1) a1 = a2;
    break;
  case 1:
    a2 = count((num-1) / 5, coins+D+C, d+1)+D+C;
    if (a1 < 0 || a2 < a1) a1 = a2;
    break;
  case 2:
    a2 = count((num-2) / 5, coins+D*2+C, d+1)+D*2+C;
    if (a1 < 0 || a2 < a1) a1 = a2;
    break;
  case 3:
    a2 = count((num+2) / 5, coins+D*2+C, d+1)+D*2+C;
    if (a1 < 0 || a2 < a1) a1 = a2;
    break;
  case 4:
    a2 = count((num+1) / 5, coins+D+C, d+1)+D+C;
    if (a1 < 0 || a2 < a1) a1 = a2;
    break;
  }

  if (a1 < 0) {
//printf("%*scount(%lld, %lld, %lld)=%lld\n", (int)d, "", num, coins, d, a1);
    return LLONG_MIN;
  }

  itt = t.find(num);
  if (itt != t.end()) {
    if (itt->second > a1) {
      t.erase(num);
      t.emplace(num, a1);
//printf("x memo(%lld, %lld)\n", num, a1);
    }
  } else {
    t.emplace(num, a1);
//printf("memo(%lld, %lld) %lu\n", num, a1, t.size());
  }

//printf("%*scount(%lld, %lld, %lld)=%lld\n", (int)d, "", num, coins, d, a1);
  return a1;
}

/*
  A,B,C,Dのどれかを使って枚数を増やしていく
  ちょうどNになる
  Nを超える→NになるまでDで減らす
  */


Measured memory_bytes: 4204
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int h, w; cin >> h >> w;
  V<string> s(h); for (auto&& e : s) cin >> e;
  constexpr array<int, 4> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
  auto in = [&](int i, int j) -> bool { return 0 <= i and i < h and 0 <= j and j < w; };
  queue< pair<int, int> > que;
  VV<> d(h, V<>(w, -1));
  for (int i = 0; i < h; ++i) for (int j = 0; j < w; ++j) if (s[i][j] == '#') {
    d[i][j] = 0;
    que.emplace(i, j);
  }
  while (!que.empty()) {
    int i, j;
    tie(i, j) = que.front(); que.pop();
    for (int k = 0; k < 4; ++k) {
      int ni = i + dx[k], nj = j + dy[k];
      if (!in(ni, nj) or d[ni][nj] != -1) continue;
      d[ni][nj] = d[i][j] + 1;
      que.emplace(ni, nj);
    }
  }
  int res = 0;
  for (int i = 0; i < h; ++i) for (int j = 0; j < w; ++j) res = max(res, d[i][j]);
  cout << res << '\n';
}

Measured memory_bytes: 13456
def solve(a,b):
    cnt=0
    for x in range(len(a)):
        if a[x]!=b[x]:
            cnt+=1
    return cnt        
s=input()
t=input()
k=len(t)
ans=k
for x in range(len(s)-len(t)+1):
    ans=min(ans,solve(s[x:x+k],t))
print(ans)

Measured memory_bytes: 9056
// 国内予選 2012 A ミレニアム
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        for (int i = 0; i < n; i++) {
            int y = sc.nextInt();
            int m = sc.nextInt();
            int d = sc.nextInt();
            
            int ans = length(y, m, d);
            System.out.println(ans);
        }
    }
    
    public static int length(int y, int m, int d) {
        int length = 0;
        
        length += lengthOfMonth(y, m) - d + 1;
        
        for (int i = m + 1; i <= 10; i++) {
            length += lengthOfMonth(y, i);
        }
        
        for (int i = y + 1; i < 1000; i++) {
            length += lengthOfYear(i);
        }
        
        return length;
    }
    
    public static int lengthOfMonth(int y, int m) {
        if (y % 3 == 0 || m % 2 == 1) {
            return 20;
        } else {
            return 19;
        }
    }
    
    public static int lengthOfYear(int y) {
        int length = 0;
            for (int i = 1; i <= 10; i++) {
                length += lengthOfMonth(y, i);
            }
        
        return length;
    }
}

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

const double ESP = 1e-6;

class Point
{
public:
	double x, y;

	Point(double x = 0, double y = 0) : x(x), y(y) {}

	Point operator + (Point a) { return Point(x + a.x, y + a.y); }
	Point operator - (Point a) { return Point(x - a.x, y - a.y); }
	Point operator * (double a) { return Point(x * a, y * a); }

	double abs() { return sqrt(norm()); }
	double norm() { return x * x + y * y; }
};

typedef Point Vector;

struct Segment
{
	Point p1, p2;
};

typedef Segment Line;

bool equals(double a, double b)
{
	return fabs(a - b) < ESP;
}

double dot(Vector a, Vector b)
{
	return a.x * b.x + a.y * b.y;
}

double cross(Vector a, Vector b)
{
	return a.x * b.y - a.y * b.x;
}

Point cross_Point(Segment s1, Segment s2)
{
	Vector base = s2.p2 - s2.p1;
	double d1 = abs(cross(base, s1.p1 - s2.p1));
	double d2 = abs(cross(base, s1.p2 - s2.p1));
	double t = d1 / (d1 + d2);
	return s1.p1 + (s1.p2 - s1.p1) * t;
}

void read_P(Point& a)
{
	scanf("%lf%lf", &a.x, &a.y);
}

void read_S(Segment& a)
{
	read_P(a.p1), read_P(a.p2);
}

int main()
{
	int q;
	scanf("%d", &q);
	while (q--)
	{
		Segment s1, s2;
		read_S(s1), read_S(s2);
	
		Point ans = cross_Point(s1, s2);
		printf("%.10lf %.10lf\n", ans.x, ans.y);
	}
}


Measured memory_bytes: 3244
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String w = br.readLine();
        int sum = 0;
        String line="";
        while (!(line = br.readLine()).equals("END_OF_TEXT")) {
            for(String s:line.split(" ")){
                if(s.equalsIgnoreCase(w)){
                    sum++;
                }
            }
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 24380
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<double,double> pii;
const int N = 2e5+5;
const int M = 2e5+5;
const int Mod = 1e8;
#define pi acos(-1)
#define INF 1e8
#define INM INT_MIN
#define pb(a)  push_back(a)
#define mk(a,b) make_pair(a,b)
#define dbg(x) cout << "now this num is " << x << endl;
#define met0(axx) memset(axx,0,sizeof(axx));
#define metf(axx) memset(axx,-1,sizeof(axx));
#define sd(ax) scanf("%d",&ax)
#define sld(ax) scanf("%lld",&ax)
#define sldd(ax,bx) scanf("%lld %lld",&ax,&bx)
#define sdd(ax,bx) scanf("%d %d",&ax,&bx)
#define sddd(ax,bx,cx) scanf("%d %d %d",&ax,&bx,&cx)
#define sfd(ax) scanf("%lf",&ax)
#define sfdd(ax,bx) scanf("%lf %lf",&ax,&bx)
#define pr(a) printf("%d\n",a)
#define plr(a) printf("%lld\n",a)
int n,a[N],b[N],c[N],vis[N];
LL k,t = -1,cnt = 0;
void dfs(int x)
{
	if(vis[x] == 2) return ;
	if(vis[x] == 0) b[++t] = x;
	else if(vis[x] == 1) c[cnt++] = x;
	vis[x]++;
	dfs(a[x]);
}
int main()
{
	cin >> n >> k;
	for(int i=1;i<=n;++i) sd(a[i]);
	dfs(1);
	if(k <= t) pr(b[k]);
	else 
	{
		k -= t;
		k--;
		int ma = 1LL*k%cnt;
		pr(c[ma]);
	}
	//system("pause");
	return 0;
}

/*
6 5
6 5 2 5 3 2
*/

Measured memory_bytes: 6764
#include<string>
#include<iostream>
#include<algorithm>

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

using namespace std;

int main(){
	int n; cin>>n;
	string s[256];
	rep(i,n) cin>>s[i];

	int q; cin>>q;
	bool b=true;
	while(q--){
		string t; cin>>t;
		if(count(s,s+n,t)==0) cout<<"Unknown "<<t<<endl;
		else{
			cout<<(b?"Opened by ":"Closed by ")<<t<<endl;
			b^=true;
		}
	}

	return 0;
}

Measured memory_bytes: 1216
use proconio::input;

fn main() {
    input! {
        mut n: usize,
    }

    let mut ans:Vec<char> = vec![];
    let temp = vec!['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
                    'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
                    'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
                    'y', 'z'];
    loop {
        n -= 1;
        let res = n % 26;
        ans.push(temp[res]);
        n /= 26;
        if n == 0 { break };
    }

    ans.reverse();
    for c in ans {
        print!("{}", c);
    }
    println!();

}


Measured memory_bytes: 2136
/*
─────────────────────
───────────████████──
──────────███▄███████
──────────███████████
──────────███████████
──────────██████─────
──────────█████████──
█───────███████──────
██────████████████───
███──██████████──█───
███████████████──────
███████████████──────
─█████████████───────
──███████████────────
────████████─────────
─────███──██─────────
─────██────█─────────
─────█─────█─────────
─────██────██────────
─────────────────────
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define int long long
#define read(a) int a; cin >> a;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define reads(s) string s; cin >> s;
#define readarr(a, n) int a[(n) + 1] = {}; fori (i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; fori (i, 1, n) {fori (j, 1, m) cin >> a[i][j];}

#define print(a) cout << a << endl;
#define printarr(a, n) fori (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) fori (i, 1, n) {fori (j, 1, m) cout << a[i][j] << " "; cout << endl;}
#define all(v) v.begin(), v.end()
#define sz(s) (int)(s.size())
#define pb push_back
#define fi first
#define se second
#define rz resize
#define fori(i, a, b) for (int i = (a); i <= (b); i++)
#define ford(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
#define setprec(x) cout << fixed << setprecision(x);
 
using namespace std;
using namespace __gnu_pbds; 
 
typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair <int, int>> vpi;
typedef vector < vector <int> > vvi;
 
const int INF = 4e18;
const int mod = 1e9+7; 

     
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    //start from here

    reads(s);

    for (char c : s)
    	if(c == '?') cout << 'D';
    	else cout << c;


    return 0;
}


Measured memory_bytes: 3788
#include <bits/stdc++.h>
using namespace std;
long long n;
long long w;
long long x[101];
long long y[101];
int main()
{
    cin>>n>>w;
    long long i,j;
    for(i=1;i<=n;i++)
        cin>>x[i]>>y[i];
    long long k[n+1][w+1];
    for(i=0;i<=n;i++) k[i][0]=0;
    for(i=0;i<=w;i++) k[0][i]=0;
    for(i=1;i<=n;i++)
        for(j=1;j<=w;j++)
        {
          if(j<x[i])
          {
            k[i][j]=k[i-1][j];
          }
          else
          k[i][j]=max(k[i-1][j],k[i-1][j-x[i]]+y[i]);
        //  cout<<k[i][j]<<' '<<i<<' '<<j<<endl;
        }
    cout<<k[n][w];
    return 0;
}


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

int num;

int main()
{
	scanf("%d", &num);
	int f = num / 100;
	int a = num % 100;
	if(f>=1 && f<=12 && a>=1 && a<=12) printf("AMBIGUOUS\n");
	else if(f>=0 && f<=99 && a>=1 && a<=12) printf("YYMM\n");
	else if(f>=1 && f<=12 && a>=0 && a<=99) printf("MMYY\n");
	else printf("NA\n");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
const int maxn=(2e5)+10;
int n,K,C,nxt[maxn],to[maxn];
char s[maxn];
int dp[maxn],f[maxn];
int in[maxn];
void solve() {
	memset(to,0,sizeof(to));
	memset(in,0,sizeof(in));
	memset(dp,0,sizeof(dp));
	nxt[n+1]=n+1;
	for (int i=n;i>=1;i--)
		if (s[i]=='x') nxt[i]=nxt[i+1];
		else nxt[i]=i;
	for (int i=1;i<=n;i++)
		if (i+C<=n&&nxt[i+C]<=n&&s[i]=='o') {
			to[i]=nxt[i+C];
			in[to[i]]++;
		}
	for (int i=1;i<=n;i++) if (s[i]=='o'&&!in[i]) dp[i]=1;
	for (int i=1;i<=n;i++) {
		dp[i]=max(dp[i],dp[i-1]);
		if (to[i]) dp[to[i]]=max(dp[to[i]],dp[i]+1);
	}
}
int main() {
	//freopen("1.txt","r",stdin);
	read(n); read(K); read(C); C++;
	scanf("%s",s+1);
	solve();
	for (int i=1;i<=n;i++) f[i]=dp[i];
	reverse(s+1,s+n+1);
	solve();
	reverse(dp+1,dp+n+1);
	reverse(s+1,s+n+1);
	for (int i=1;i<=n;i++) {
		if (s[i]=='x') continue;
		if (f[i-1]+dp[i+1]<K) printf("%d\n",i);
	}
	return 0;
}
/*
  0. Enough array size? Enough array size? Enough array size? Interger overflow?
  
  1. Think TWICE, Code ONCE!
  Are there any counterexamples to your algo?
    
  2. Be careful about the BOUNDARIES!
  N=1? P=1? Something about 0?
    
  3. Do not make STUPID MISTAKES!
  Time complexity? Memory usage? Precision error?
*/

Measured memory_bytes: 5632
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=1e9+7;
int main(){
    ll n;cin>>n;
    if(n==2){
        cout<<2<<endl;
        cout<<0<<endl;
        cout<<11<<endl;
    }
    else if(n==1){
        cout<<1<<endl;
        cout<<0<<endl;
    }
    else{
        cout<<n-1<<endl;
        rep(i,n-1){
            cout<<0;
            rep(j,i){
                cout<<1;
            }
            cout<<0<<endl;
        }
    }
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define st first
#define nd second
#define pii pair<int,bool>
#define mp make_pair

using namespace std;

const int nax = 2e5 + 5;

const int mod = 998244353;
int n,k;

int lo[11];
int hi[11];

ll dp[nax];
ll sum[nax];

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

    cin>>n>>k;
    for(int i=1;i<=k;i++)
    {
        cin>>lo[i]>>hi[i];
    }

    dp[1] = 1;
    sum[1] = 1;

    for(int i=2;i<=n;i++)
    {
        for(int j=1;j<=k;j++)
        {
            int alo = lo[j];
            int ahi = hi[j];
            if(alo > i) continue;
            ahi = min(ahi,i);

            ll cnt = sum[i-alo];
            if(ahi < i) cnt -= sum[i-ahi-1];
            if(cnt < 0) cnt += mod;
            dp[i] += cnt;
            dp[i] %= mod;
        }
        sum[i] = sum[i-1] + dp[i];
        sum[i] %= mod;
    }


    cout<<dp[n];

    return 0;
}


Measured memory_bytes: 6660
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 810114514
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define int long long 

signed main(){
    string s;
    string G[100000];
    int Gle=0;
    int num=0;
    int K;
    cin >> s >> K;
    REP(i,26){
        Gle=0;
        REP(j,s.size()){
            if(s[j]==(char)('a'+i)){
                for(int k=j;k<s.size() && k-j<5 ;k++){
                    G[Gle]=s.substr(j,k-j+1);
                   // cout <<j <<"sub  "<< G[Gle] << endl;
                    Gle++;
                }
            }
        }
        sort(G,G+Gle);
        //cout << "GLEM " ;REP(k,Gle){cout << G[k] << "   ";}cout << endl;
        REP(j,Gle){
            if(j==0 || (j!=0 && G[j]!=G[j-1])){
                num++;
                //cout << num << "  " << G[j] << endl;
            }
            if(num==K){
                cout << G[j] << endl;
                return 0;
            }
        }
    }
	return 0;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1000000007;

ll pd[500010];
ll rd[500010];
ll Ep(int x, int y){
  if(y == 0) return 1;
  if(y == 1) return x;
  ll r = Ep(x,y/2);
  if(y%2 == 1) return r *r%MOD *x%MOD;
  else return r *r%MOD;
}
ll Ftl(ll x){
  if(x == 1 || x == 0) return 1;
  if(pd[x] != 0) return pd[x];
  return pd[x] = Ftl(x-1) *x%MOD;
}
ll invFtl(ll x){
  if(x == 1 || x == 0) return 1;
  if(rd[x] != 0) return rd[x];
  return rd[x] = invFtl(x-1)*Ep(x,MOD-2)%MOD;
}
ll comb(ll m, ll n){
  if(m < n) return 0;
  return Ftl(m) *invFtl(n)%MOD *invFtl(m-n)%MOD;
}



int main(){
  int n, m;
  cin >> n >> m;
  ll ans = Ftl(m) *invFtl(m-n) %MOD;
  ans = ans *ans %MOD;
  //cout << "ans:" << ans << endl;
  for(int i=1; i<=n; ++i){
    ll x = Ftl(m-i) *invFtl(m-n) %MOD;
    x = x *x %MOD *Ftl(m) %MOD *invFtl(m-i) %MOD *comb(n,i) %MOD;
    if(i%2) ans -= x;
    else ans = (ans +x) %MOD;
    if(ans <0) ans += MOD;
    //cout << "i:" << i << " x:" << x << " ans:" << ans << endl;
  }
  cout << ans << endl;
}

Measured memory_bytes: 19076
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
const ll mod = 0;
struct H {
	ll x, y;
	bool operator<(const H &b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H &b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H &b) const { return x == b.x&&y == b.y; }
	bool operator!=(const H &b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P &b) const { return cost < b.cost; }
	bool operator>(const P &b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E &b) const { return cost < b.cost; }
	bool operator>(const E &b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T &a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T &a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j%i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
//#define int unsigned long long
//----------------------------------------------------
string s;
int dp[300000];
int bit[1 << 26];
signed main() {
	cin >> s;
	for (int i = 1; i < 1ll << 26; i++) {
		bit[i] = inf;
	}
	ll res = 0;
	for (int i = 0; i < s.size(); i++) {
		int t = (int)(s[i] - 'a');
		res ^= 1 << t;
		int sum = bit[res];
		for (int j = 0; j < 26; j++) {
			sum = min(sum, bit[res ^ (1 << j)]);
		}
		bit[res] = min(bit[res], sum + 1);
		dp[i] = sum + 1;
	}
	cout << dp[s.size() - 1] << endl;
}

Measured memory_bytes: 263556
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll dp[100050];
const ll inf = 100000000000000;
int a[150][2];
int main(){
    int n,w;
    for(int i=0;i<100050;i++)dp[i]=inf;
    cin>>n>>w;
    for(int i=0;i<n;i++)cin>>a[i][0]>>a[i][1];
    dp[0]=0;
    for(int i=0;i<n;i++){
        for(int j=100040-a[i][1];j>=0;j--){
            int k=j+a[i][1];
            if(dp[j]+a[i][0]>w)continue;
            dp[k]=min(dp[k],dp[j]+1LL*a[i][0]);
        }
    }
    
    
    for(int i=100040;i>=0;i--){
        if(dp[i]<=w){
            cout<<i;
            break;
        }
    }
    
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
// define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (((a)%mod) * ((b)%mod)) % mod
#define rollcall cout << "I'm Sucu." << endl;
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define fi first
#define se second
// debug
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p){
  os << "(" << p.first << "," << p.second << ")";return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for (auto it = v.begin();it != v.end();++it){
    if(it != v.begin())os << " ";os << *it;
  }return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &mp){
  for(auto x: mp)os << "(" << x.first << "," << x.second << ")" << endl;
  return os;
}
template<typename T, int SIZE>
int array_length(const T (&)[SIZE]){return SIZE;}
template<typename T, int N>
void PRINTF(const T (&a)[N], int s = N, int t = -1, bool f = true){
	if(t == -1){rep(i,s){if(i)cout << " ";cout << a[i];}}
	else repi(i,s,t){if(i!=s)cout << " ";cout << a[i];}
	if(f)cout << "\n";
}
template<typename T, int N1, int N2>
void PRINTF(const T (&a)[N1][N2], int h = N1, int w = N2){
	rep(i,h){rep(j,w){cout << a[i][j] << " \n"[j==w-1];}}
}
string substr(const string &str, int S1, int S2 = -1){
  if(S2 == -1)return str.substr(S1);
  return str.substr(S1, S2-S1);
}
// typedef
typedef complex<double> Point;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;
// int sum = accumulate(a, a+n, 0LL);
// int mx = max_element(a, a+n);
// int mn = min_element(a, a+n);
// int cnt = count(a, a+n, k);

//Date and Integer
int length_of_year(int y){ // 1-indexed
  if(y%400 == 0 || ((y%100 != 0) && (y%4 == 0)))return 366;
  return 365;
}

int length_of_month(int y, int m){ // 1-indexed
  int monthes[12] = {31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    if(m != 2)return monthes[m-1];
    if(length_of_year(y) == 366)return 29;
    return 28;
}

int date_to_int(string date){ //ex) 2018/08/05
    int y = stoi(date.substr(0, 4)), m = stoi(date.substr(5, 2)), d = stoi(date.substr(8, 2));
    int ans = 0;
    repi(i,1,y)ans += length_of_year(i);
    repi(i,1,m)ans += length_of_month(y, i);
    return ans + d;
}
signed main(){
  string str;
  cin >> str;
  int d1 = date_to_int("2019/04/30");
  int d2 = date_to_int(str);
  if(d2 <= d1)cout << "Heisei" << endl;
  else cout << "TBD" << endl;
  return 0;
}






Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
	Scanner scan = new Scanner(System.in);

	int s = scan.nextInt();

	int tmp = s;
	int sn = 0;
	while(tmp != 0){
	    sn += tmp % 10;
	    tmp /= 10;
	}

	if(s % sn == 0){
	    System.out.println("Yes");
	}else{
	    System.out.println("No");
	}
    }
}

	    
	


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

int main() {
    int stack[100];
    int head = 0;
    char symbol[7];
    while(scanf("%s", symbol) != EOF) {
        if('0' <= symbol[0] && symbol[0] <= '9') {
            stack[head] = atoi(symbol);
            head++;
        } else {
            switch(symbol[0]) {
                case '+':
                    stack[head-2] += stack[head-1];
                    break;
                case '-':
                    stack[head-2] -= stack[head-1];
                    break;
                case '*':
                    stack[head-2] *= stack[head-1];
                    break;
            }
            head--;
        }
    }
    printf("%d\n", stack[0]);
}

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

#if ((_WIN32 || __WIN32__) && __cplusplus < 201103L)
#define lld I64d
#else
#define lld lld
#endif

//{{{
using namespace std;
typedef long long LL;
typedef vector<int> VI;
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define clr(a, b) memset(a, b, sizeof(a))
// clang-format off
#define debug(args...) {vector<string> _v = split(#args, ','); err(_v.begin(), args); cerr<<endl;}
vector<string> split(const string& s, char c) {vector<string> v; stringstream ss(s); string x; while
(getline(ss, x, c)) v.push_back(x); return v;} void err(vector<string>::iterator) {}
template<typename T, typename... Args> void err(vector<string>::iterator it, T a, Args... args)
{cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << ", "; err(++it, args...);}
// clang-format on
//}}}

const int N = 400 + 10;
const int mod = 1e9 + 7;
int n;
LL a[N];
LL s[N];
LL cals(int l, int r)
{
    LL ret = s[r] - s[l - 1];
    return ret;
}

LL dp[N][N];

LL dfs(int l, int r)
{
    if (l == r) return 0;
    if (dp[l][r] != -1) return dp[l][r];

    LL ret = 9e18;
    LL cur = cals(l, r);
    for (int i = l; i + 1 <= r; i++)
    {
        LL v1 = dfs(l, i);
        LL v2 = dfs(i + 1, r);
        ret = min(ret, v1 + v2 + cur);
    }
    return dp[l][r] = ret;
}

int main()
{
#ifdef LOCAL
    freopen("in", "r", stdin);
// freopen("out", "w", stdout);
#endif

    while (cin >> n)
    {
        for (int i = 1; i <= n; i++) cin >> a[i];
        s[0] = 0;
        for (int i = 1; i <= n; i++) s[i] = s[i - 1] + a[i];

        clr(dp, -1);

        LL ans = dfs(1, n);
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 4932
n = int(input())
v = [int(x) for x in input().split()]

v1 = v[0::2]
v2 = v[1::2]

# print(v1)
# print(v2)

d1, d2 = dict(), dict()


for num in v1:
    d1[num] = d1.get(num, 0) + 1

for num in v2:
    d2[num] = d2.get(num, 0) + 1

# for key, val in d1.items():
#    print("{} -> {}".format(key, val))

v1tmp1 = [(key, val) for key, val in d1.items()]
V1 = sorted(v1tmp1, key=lambda x: x[1], reverse=True)

v2tmp1 = [(key, val) for key, val in d2.items()]
V2 = sorted(v2tmp1, key=lambda x: x[1], reverse=True)

# print(tmp2)

ret = 0

if (V1[0][0] != V2[0][0]):
    ret = n - V1[0][1] - V2[0][1]
else:
    t1 = n - V1[0][1] - (V2[1][1] if len(V2) >= 2 else 0)
    t2 = n - (V1[1][1] if len(V1) > 2 else 0) - V2[0][1]
    ret = min(t1, t2)

print(ret)

Measured memory_bytes: 22336