akhauriyash/Code-Regression huggingface dataset:
/*
ID: varunra2
LANG: C++
TASK: a
*/

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

#ifdef DEBUG
#include "lib/debug.h"
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define debug_arr(...) \
  cerr << "[" << #__VA_ARGS__ << "]:", debug_arr(__VA_ARGS__)
#pragma GCC diagnostic ignored "-Wsign-compare"
//#pragma GCC diagnostic ignored "-Wunused-parameter"
//#pragma GCC diagnostic ignored "-Wunused-variable"
#else
#define debug(...) 42
#endif

#define EPS 1e-9
#define IN(A, B, C) assert(B <= A && A <= C)
#define INF (int)1e9
#define MEM(a, b) memset(a, (b), sizeof(a))
#define MOD 1000000007
#define MP make_pair
#define PB push_back
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define x first
#define y second

const double PI = acos(-1.0);
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef map<int, int> MPII;
typedef multiset<int> MSETI;
typedef set<int> SETI;
typedef set<string> SETS;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef vector<string> VS;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define sz(x) (int)(x).size()
typedef pair<int, int> pii;
typedef vector<int> vi;
#pragma GCC diagnostic ignored "-Wsign-compare"
// util functions


int main() {
#ifndef ONLINE_JUDGE
  freopen("a.in", "r", stdin);
  freopen("a.out", "w", stdout);
#endif
  cin.sync_with_stdio(0); cin.tie(0);
  int n, x, t;
  cin >> n >> x >> t;

  cout <<  ((n + x - 1)/x) * t << endl;

  return 0;
}


Measured memory_bytes: 3576
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j,k;
  int h,w;
  string s;
  cin>>h>>w;
  vi a(26,0);
  rep(i,h){
    cin>>s;
    rep(j,w)a[s[j]-'a']++;
  }
  if(h==1&&w==1){
    cout<<"Yes"<<endl;
    return 0;
  }
  int n4=0,n2=0,n1=0;
  rep(i,26){
    n4+=a[i]/4;
    a[i]%=4;
    n2+=a[i]/2;
    a[i]%=2;
    n1+=a[i];
  }
  if(h%2&&w%2){//odd-odd
    if((h/2)*(w/2)<=n4&&n1==1)
      cout<<"Yes"<<endl;
    else 
      cout<<"No"<<endl;
  }else if(h%2||w%2){//odd-even
    if((h/2)*(w/2)<=n4&&n1==0)
      cout<<"Yes"<<endl;
    else
      cout<<"No"<<endl;
  }else{//even-even
    if(n1==0 && n2==0)
      cout<<"Yes"<<endl;
    else 
      cout<<"No"<<endl;
  }
}


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


int main(){
  ll N ,K;
  cin >> N >> K;
  vector<ll>H(N);
  
  rep(i,N)cin >> H[i];
  
  sort(H.begin(),H.end());
  
  ll mina = 1000000010;
  ll now = 0;
  
  for(int i = 0; i < N-K+1; i++){
    now = H[i+K -1] - H[i];
    mina = min(now,mina);

  }
  
  cout << mina << endl;
  return 0;
  
}

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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//以降 cin の入力元が 'input.txt' になる
//std::ifstream in("input.txt");
//std::cin.rdbuf(in.rdbuf());

signed main()
{   
    gearup;
    int n; cin >> n;
    vl a(n);
    vvl g(n);
    rep1(i,n){
        cin >> a[i];
        a[i]--;
        g[a[i]].push_back(i);
    }
    //rep(i,n)out(g[i].size());
    vl dp(n); //最小の高さ
    function< ll(ll) > dfs = [&](ll node){
        if(dp[node] != 0)return dp[node];
        vl node_list;
        for(auto nv:g[node]){
            node_list.push_back(dfs(nv));
        }
        sort(all(node_list));
        ll height = 0;
        rep(i,node_list.size()){
            if(height < node_list[i])height = node_list[i];
            height++;
        }

        return (dp[node] = height);
    };
    dfs(0);
    out(dp[0]);
}

Measured memory_bytes: 20960
/*
 * atcoder/abc133/d.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

/*
 * 各山に降った雨の量をX_iとおくと、X_1 + X_2 + ... + X_N = A_1 + A_2 + ... + A_N
 * X_N+1 = X_1とすると、(X_i + X_{i+1})/2 = A_i <=> X_i + X_{i+1} = 2 * A_i ①
 * X_1 = (A_1 + A_2 + ... + A_N) - (X_2 + X_3 + ... + X_N)
 *     = (A_1 + ... + A_N) - 2 * (A_2 + A_4 + ... + A_{N-1})
 *
 * X_2以降は、① よりX_{i+1} = 2 * A_i - X_i
 */
int N;
vector<ll> A;
void solve() {
  cin >> N;
  A.resize(N);
  ll x_1 = 0;
  loop(n,0,N) {
    cin >> A[n];
    x_1 += A[n];
    if (n % 2 == 1) x_1 -= 2 * A[n];
  }
  vector<ll> X;
  X.push_back(x_1);
  for (int i=1; i<N; i++) {
    X.push_back(2 * A[i-1] - X[i-1]);
  }

  for (auto&&x: X) cout << x << " ";
  cout << endl;
}
int main() {
  // cout.precision(15); cout << fixed;

  solve();

  return 0;
}


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
#define Sort(a) sort(a.begin(), a.end())
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
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 main(){
    ll k;
    cin >> k;
    vll d;
    int cnt = 0;
    REP(i, 10) d.push_back(i);
    while(d.size() <= k){
        rep(i, 3){
            int tmp = d.at(cnt)%10 + (i - 1);
            if(tmp >= 0 && tmp <= 9) d.push_back(d.at(cnt)*10+tmp);
        }
        ++cnt;
    }
    cout << d.at(k-1) << endl;
    return 0;
}

Measured memory_bytes: 1400
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>; 
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1001001001001001001;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
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(){
    int D; cin >> D;
    vector<int> C(26); rep(i, 26) cin >> C[i]; //満足度減少係数
    vector<vector<ll>> S(D, vector<ll>(26));
    rep(i, D)rep(j, 26)cin >> S[i][j];

    ll score = 0;
    vector<int> last(26);
    vector<ll> res(D);
    rep(i, D){
      int T; cin >> T; T--;
      last[T] = i+1;
      score += S[i][T];
      rep(j, 26){
        score -= C[j] * ((i+1) - last[j]);

      }
      res[i] = score;
    }
    for(ll tmp: res){
      cout << tmp << ln;
    }
}


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

int compress(vector<int>& xs, vector<int>& x) {
    const int N = x.size();
    sort(xs.begin(), xs.end());
    xs.erase(unique(xs.begin(), xs.end()), xs.end());
    for(int i=0; i<N; ++i) {
        x[i] = lower_bound(xs.begin(), xs.end(), x[i]) - xs.begin();
    }
    return xs.size();
}

int main() {
    int N;
    while(cin >> N, N) {
        vector<int> x(N), y(N);
        vector<int> xs, ys;
        vector<int> a(4), b(4);
        for(int i=0; i<N; ++i) {
            cin >> x[i] >> y[i];
            xs.push_back(x[i]);
            ys.push_back(y[i]);
        }
        for(int i=0; i<4; ++i) {
            cin >> a[i] >> b[i];
            xs.push_back(a[i]);
            ys.push_back(b[i]);
        }
        int W = compress(xs, x);
        int H = compress(ys, y);
        int cx1 = 10000, cx2 = 0, cy1 = 10000, cy2 = 0;
        for(int i=0; i<4; ++i) {
            a[i] = lower_bound(xs.begin(), xs.end(), a[i]) - xs.begin();
            b[i] = lower_bound(ys.begin(), ys.end(), b[i]) - ys.begin();
            cx1 = min(cx1, a[i]);
            cx2 = max(cx2, a[i]);
            cy1 = min(cy1, b[i]);
            cy2 = max(cy2, b[i]);
        }
        vector<vector<int>> flag(H, vector<int>(W));
        for(int i=0; i<N; ++i) {
            int i2 = (i+1)%N;
            if(x[i] != x[i2]) {
                continue;
            }
            int miny = min(y[i], y[i2]), maxy = max(y[i], y[i2]);
            for(int j=miny; j<maxy; ++j) {
                flag[j][x[i]] = 1;
            }
        }
        for(int i=cy1; i<cy2; ++i) {
            flag[i][cx1] |= 2;
            flag[i][cx2] |= 2;
        }
        for(int i=0; i<H; ++i) {
            for(int j=0; j+1<W; ++j) {
                flag[i][j+1] ^= flag[i][j];
            }
        }
        int res = 0;
        for(int i=0; i+1<H; ++i) {
            for(int j=0; j+1<W; ++j) {
                if(flag[i][j] == 1) {
                    res += (ys[i+1] - ys[i]) * (xs[j+1] - xs[j]);
                }
            }
        }
        cout << res << endl;
    }
}


Measured memory_bytes: 3156
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <queue>

using namespace std;

int n;
int a[101];
double b;
int r;
double v, e, f;

class State {
public:
  int pos;
  double sec;
  State();
  State(int pos, double sec) : pos(pos), sec(sec) {}
  bool operator <(const State &s) const {
    return sec > s.sec;
  }
};

double cost[101][101];

void make() {
  for(int i = 0; i <= n; ++i) {
    for(int j = i+1; j <= n; ++j) {
      double tmp = 0;
      int dist = a[j]-a[i];
      for(int x = 0; x < dist; ++x) {
	if(x >= r) {
	  tmp += 1.0/(v-e*(x-r));
	} else if(x < r) {
	  tmp += 1.0/(v-f*(r-x));
	}
      }
      cost[i][j] = tmp;
    }
  }
}

#define INF 9999999
double solve2() {
  double dp[101];
  fill(dp, dp+101, INF);
  dp[0] = 0;
  make();
  for(int i = 1; i <= n; ++i) {
    for(int j = 0; j < i; ++j) {
      double tmp = dp[j] + cost[j][i];
      if(j != 0) tmp += b;
      dp[i] = min(dp[i], tmp);
    }
  }
  return dp[n];
}

main() {
  while((cin >> n) && n) {
    a[0] = 0;
    for(int i = 1; i <= n; ++i) {
      cin >> a[i];
    }
    cin >> b;
    cin >> r >> v >> e >> f;
    printf("%.4f\n", solve2());
  }
}

Measured memory_bytes: 1060
#include <stdio.h>
int main(void){

  	int i, count=0;
  	char s[3],t[3];
	scanf("%s",s);
  	scanf("%s",t);
   	for (i=0; i<3; i++){
    	if(s[i] == t[i]) count += 1;
    }
  	printf("%d",count);
	return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

typedef long long LL;

int n,D,d[20],g[20];

LL ans,ten[20];

void dfs(int x,LL m,LL s)
{
	if (x==n/2)
	{
		if (m==D)
		{
			if (n&1) ans+=s*10;else ans+=s;
		}
		return;
	}
	for (int i=-9;i<10;i++)
	{
		LL cur=m+(ten[n-1-x]-ten[x])*i;
		if (D%ten[x+1]==(cur%ten[x+1]+ten[x+1])%ten[x+1])
		{
			int pl=g[i+9];
			if (x==0) pl--;
			dfs(x+1,cur,s*pl);
		}
	}
}

int main()
{
	scanf("%d",&D);
	ten[0]=1;
	for (int i=1;i<19;i++) ten[i]=ten[i-1]*10;
	for (int i=0;i<10;i++) for (int j=0;j<10;j++) g[i-j+9]++;
	for (n=1;n<=18;n++) dfs(0,0,1);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define endl "\n"
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);

    int s,w;
    cin >> s >> w;
    if (w>=s)
    {
        cout << "unsafe" << endl;
    }
    else
    {
        cout << "safe" << endl;
    }

    return 0;
}

Measured memory_bytes: 3640
#include<stdio.h>
int main(){
  int a,b,c,sum;
  while(1){
    scanf("%d%d%d",&a,&b,&c);
    if(a==-1 && b==-1 && c==-1)break;
    sum=(a+b);
     if(a==-1 ||b==-1)printf("F\n");
     else if(sum>=80)printf("A\n");
    else if(sum>=65)printf("B\n");
    else if(sum>=50)printf("C\n");
    else if(sum>=30 && sum<50){
       if(c>=50)printf("C\n");
      else printf("D\n");
    }
    else if(sum <30)printf("F\n");
  }
  return 0;
}



Measured memory_bytes: 2628
n = int(input())
a_str = input().split()
a = [int(x) for x in a_str]
prod = 1
flag = 1
for i in range(n):
    if a[i] == 0:
        print(0)
        flag = 0
if flag == 1:
    for i in range(n):
        prod *= a[i]
        if prod > 10**18:
            print(-1)
            flag = 0
            break
if flag == 1:
    print(prod)


Measured memory_bytes: 21572
n = int(input())
global count
count = 0
def dfs(s):
    if int(s) > n:
        return 0
    if set(list(s[1:])) == {'3','5','7'}:
        global count
        count += 1
    for i in '753':
        dfs(s + i)
dfs('0')
print(count)

Measured memory_bytes: 3060
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

N = int(input())
K = int(input())

def solve(n):
    if n == N:
        return 1

    v = solve(n + 1)
    return min(v * 2, v + K)

print(solve(0))

Measured memory_bytes: 9492
#![allow(unused_imports)]

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

use std::cmp::{min, max};
use std::collections::{HashMap, HashSet, VecDeque, BinaryHeap};

fn main() {
    input!{
        a: i64,
        v: i64,
        b: i64,
        w: i64,
        t: i64
    }
    if v <= w {
        println!("NO");
    } else if (v - w) * t < (a - b).abs() {
        println!("NO");
    } else {
        println!("YES");
    }
}


Measured memory_bytes: 2100
package main

import "fmt"

func memo(m [][]int, r, t, f int) {
	arr := []int{t, f, 7 - t, 7 - f, t}
	for i := 0; i < len(arr)-1; i++ {
		ti, fi := arr[i], arr[i+1]
		m[ti][fi] = r
	}
}

func main() {
	d := make([]int, 7)
	for i := 1; i < 7; i++ {
		var x int
		fmt.Scan(&x)
		d[i] = x
	}

	m := make([][]int, 7)
	for i := 0; i < 7; i++ {
		m[i] = make([]int, 7)
	}
	memo(m, 1, 4, 2)
	memo(m, 2, 1, 4)
	memo(m, 3, 1, 2)
	memo(m, 4, 2, 1)
	memo(m, 5, 4, 1)
	memo(m, 6, 2, 4)

	var q int
	fmt.Scan(&q)
	for i := 0; i < q; i++ {
		var t, f int
		fmt.Scan(&t, &f)
		var ti, fi int
		for i := 0; i < len(d); i++ {
			if t == d[i] {
				ti = i
			}
			if f == d[i] {
				fi = i
			}
		}
		fmt.Println(d[m[ti][fi]])
	}
}



Measured memory_bytes: 1124
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <bitset>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;

int main() {
  string s;
  map<string, char> m;
  m["101"] = ' ';
  m["000000"] = '\'';
  m["000011"] = ',';
  m["10010001"] = '-';
  m["010001"] = '.';
  m["000001"] = '?';
  m["100101"] = 'A';
  m["10011010"] = 'B';

  m["0101"] = 'C';
  m["0001"] = 'D';
  m["110"] = 'E';
  m["01001"] = 'F';
  m["10011011"] = 'G';
  m["010000"] = 'H';
  m["0111"] = 'I';
  m["10011000"] = 'J';

  m["0110"] = 'K';
  m["00100"] = 'L';
  m["10011001"] = 'M';
  m["10011110"] = 'N';
  m["00101"] = 'O';
  m["111"] = 'P';
  m["10011111"] = 'Q';
  m["1000"] = 'R';

  m["00110"] = 'S';
  m["00111"] = 'T';
  m["10011100"] = 'U';
  m["10011101"] = 'V';
  m["000010"] = 'W';
  m["10010010"] = 'X';
  m["10010011"] = 'Y';
  m["10010000"] = 'Z';


  while(getline(cin, s)){
    stringstream ss, ans;
    REP(i, s.length()){
      if(s[i] == ' ') ss << "11010";
      else if(s[i] == '.') ss << "11011";
      else if(s[i] == ',') ss << "11100";
      else if(s[i] == '-') ss << "11101";
      else if(s[i] == '\'') ss << "11110";
      else if(s[i] == '?') ss << "11111";
      else{
        bitset<5> bs(s[i] - 'A');
        ss << bs.to_string();
      }
    }
    int i = 0;
    s = ss.str();
    while(i + 1 < s.length()){
      bool f = false;
      for(auto v : m){
        int l = v.first.length();
        if(v.first == s.substr(i, l)){
          ans << v.second;
          i += l;
          f = true;
          break;
        }
      }
      if(!f) break;
    }
    cout <<ans.str() <<endl;
  }
  return 0;
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
typedef long long ll;
#define pb push_back

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifndef ONLINE_JUDGE

	// For getting input from input.txt file
	freopen("input1.txt", "r", stdin);

	// Printing the Output to output.txt file
	freopen("output1.txt", "w", stdout);

#endif
	/*Always stress test, for n=0, n=1, n=10^9,what if n<k and so on */
	/* Please remember 10^7 se bada array is not possible */
	/* Always use pen and paper, don't just look at the screen*/
	/* Try finding a pattern on pen and paper until y0u get it*/
	ll t = 1;
	while (t--)
	{
		ll n;
		cin >> n;
		string ans = "";
		while (n > 0)
		{
			n--;
			ans += 'a' + n % 26;
			n /= 26;
		}
		reverse(ans.begin(), ans.end());
		cout << ans << endl;
	}

}




Measured memory_bytes: 3548
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
pub const M: i32 = 1000000007;
fn main() {
    let ans = solve();
    println!("{}",ans );
}
fn solve() -> String{
    let mut abc = read_vec::<i32>();
    abc.sort();
    check(abc[0] + abc[1],abc[2])
}
fn check(x:i32,y:i32) -> String{
        let ans =  if x == y{
            "Yes".to_string()
        } else{
            "No".to_string()
        };
        ans
}


Measured memory_bytes: 4352
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <string.h>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#include <random>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define gep(i,g,j) for(int i = g.head[j]; i != -1; i = g.e[i].next)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcount
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define df(x) int x = in()
#define dame { puts("-1"); return 0;}
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,vector<T>,greater<T> >
#define bn(x) ((1<<x)-1)
#define newline puts("")
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');}
template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(vector<T>&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,vector<T>&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;



int main() {
  int n;
  scanf("%d",&n);
  vi a(n);
  rep(i,n) scanf("%d",&a[i]);
  int cnt = 0;
  rep(i,n) cnt += a[i]&1;
  if (cnt%2 == 0) puts("YES");
  else puts("NO");
  return 0;
}






















Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

int m;

int main(){
	//IO("input.txt", "output.txt");
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> m;
	cout << 48 - m << "\n";
	return 0;
}

Measured memory_bytes: 256
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;

typedef long long ll;
//typedef pair<int,int> Pint;
//typedef pair<ll, ll> P;
//typedef pair<ll, pair<ll, ll>> P;
//typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define revrep(i, n) for(ll i = n-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
const ll INFL = 1LL << 60;//10^18 = 2^60
const int INF = 1 << 30;//10^9
const ll MOD = 1e9 + 7;
//ll MOD  = 998244353;
vector<ll> dy = {0, 0, 1, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, -1, 0, 0, 1, -1, 1, -1, 0};

ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}
ll pow_mod(ll x, ll k){
  x %= MOD; x += MOD; x %= MOD;
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}
ll inverse(ll x){return pow_mod(x, MOD - 2);};
ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a % b);
}
ll lcm(ll x, ll y){return x / gcd(x, y) * y;};

int main(void){
  string S;
  cin >> S;
  vector<ll> cnt(3, 0);
  rep(i, S.size()){
    if(S[i] == 'a') cnt[0]++;
    else if(S[i] == 'b') cnt[1]++;
    else cnt[2]++;
  }
  sort(cnt.begin(), cnt.end());
  if(cnt[2] - cnt[0] <= 1){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 512
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
bool odd(const int &n) { return n & 1; }
bool even(const int &n) { return ~n & 1; }
template<typename T> int len(const T &v) { return v.size(); }
template<typename T = int> T in() { T x; cin >> x; return x; }
template<typename T = int> T in(T &&x) { T z(forward<T>(x)); cin >> z; return z; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> istream &operator>>(istream &is, pair<A, B> &p) { return is >> p.first >> p.second; }
template<typename T> ostream &operator<<(ostream &os, const vector<vector<T>> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : "\n"); return os; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : " "); return os; }
template<typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << p.first << ' ' << p.second; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
// clang-format on

main {
  int N, W;
  cin >> N >> W;
  vector<int> v(N), w(N), m(N);
  rep(i, N) cin >> v[i] >> w[i] >> m[i];
  vector<int> dp(W + 1);
  rep(i, N) {
    for (int k = 0; m[i]; k++) {
      int c = min(m[i], 1LL << k);
      m[i] -= c;
      for (int j = W; j - w[i] * c >= 0; j--) cmax(dp[j], dp[j - w[i] * c] + v[i] * c);
    }
  }
  cout << dp[W] << endl;
}



Measured memory_bytes: 3148
#include<stdio.h>

int main(){
  int i, n, m, x, count;

  while(1){
    scanf("%d", &m);
    if(m == 0) break;
    scanf("%d", &n);
 
    count = 0;
    for(i=m; i<=n; i++){
      x = i;

      while(1){
        if(x == 1){
          count++;
          break;
        }else if(x%2 == 0){
          x /= 2;
        }else if(x%3 == 0){
          x /= 3;
        }else if(x%5 == 0){
          x /= 5;
        }else{
          break;
        }
      }
    }

    printf("%d\n", count);
  }
  return 0;
}

Measured memory_bytes: 0
// B - String Palindrome
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

string S;

bool ok(int l, int r){
	if(l > r) return false;
	l--; r--;
	while(l < r){
		if(S[l] != S[r]) return false;
		l++; r--;
	}
	return true;
}

string solve(){
	int n = S.size();
	if(!ok(1, n)) return "No";
	if(!ok(1, (n-1)/2)) return "No";
	if(!ok((n+3)/2, n)) return "No";
	return "Yes";
}

int main(){
	cin>>S;
	cout<< solve() <<endl;
}

Measured memory_bytes: 256
main = do
    ss <- getLine
    let hw = map (\x -> read x :: Int) $ words ss
    let h = hw!!0
    let w = hw!!1
    if (h == 0 && w ==0)
        then return ()
        else do
            drawSquare h w
            main

drawSquare h w = do
    let l = replicate w '#'
    draw l h
    
draw l n = if (n<=0)
              then putStrLn ""
              else do
                  putStrLn l
                  draw l (n-1)


Measured memory_bytes: 4048
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    int a,b,ans=0;
    cin>>a>>b;
    repi(i,a,b+1){
        int rev=i%10*10000+(i%100/10)*1000+(i%1000/100)*100+(i%10000/1000)*10+i/10000;
        if(i==rev) ans++;
    }
    cout<<ans;
}

Measured memory_bytes: 3580
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstdio>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define pb push_back
#define pf push_front

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;

ll gcd(ll x, ll y) {
	ll r;
	while ((r = x % y) != 0) {
		x = y;
		y = r;
	}
	return y;
}
ll lcm(ll x, ll y) {
	x /= gcd(x, y);
	y /= gcd(x, y);
	return (x*y);
}

int main()
{
	int n, ans = 1;
	cin >> n;
	for (int i = 0; ans <= n; i++) {
		ans *= 2;
	}
	cout << ans / 2;
	return 0;
}

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

class stack{
public:
    int array[100];
    int top = -1;
    
    void push(int v) {
        top++;
        array[top] = v;
        return;
    }
    
    int pop() {
        top--;
        return array[top+1];
    }
    
    void show() {
        cout<<array[top]<<endl;
        return;
    }
};

int main() {
    
    stack s;
    int result, number;
    char v[10];

    while(1) {
        if( scanf("%s", &v) == EOF ) break;
      
        if(v[0] == '+') {
            s.push( s.pop() + s.pop() );
        }
        else if(v[0] == '-') {
            int a = s.pop();
            int b = s.pop();
            s.push(b-a);
        }
        else if(v[0] == '*') {
            s.push( s.pop() * s.pop() );
        }
        else {
            number = atoi(v);
            s.push(number);
        }
    }
    cout<< s.pop() <<endl;
  
  return 0;
}



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

int main()
{
    string ans;
    ll x, a, b;
    cin >> x >> a >> b;
    if (b <= a)
    {
        ans = "delicious";
    }
    else if (b - a <= x)
    {
        ans = "safe";
    }
    else
    {
        ans = "dangerous";
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))
#define BUF_SIZE 40
#define DIVISOR 1000000007

int get_int(void) {
  int num;
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return 0;
  sscanf(line, "%d", &num);
#else
#error
#endif
  return num;
}

int get_int2(int *a1, int *a2) {
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return -1;
  sscanf(line, "%d %d", a1, a2);
#else
#error
#endif
  return 0;
}

int get_int3(int *a1, int *a2, int *a3) {
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return -1;
  sscanf(line, "%d %d %d", a1, a2, a3);
#else
#error
#endif
  return 0;
}

#define VERTEX_MAX 100000

struct list {
    struct list *next;
    int dst;
    int length;
};

struct list *create_graph(int vs) {
    static struct list graph[VERTEX_MAX];
    int i;
    for(i = 0; i < vs; i++) {
        graph[i].next = &graph[i];
    }
    return graph;
}

void add_list(struct list *head, int dst, int length) {
    struct list *elem = malloc(sizeof(struct list));
    elem->next = head->next;
    elem->dst = dst;
    elem->length = length;
    head->next = elem;
}

void dfs(struct list *graph, int this, int parent, int length, uint64_t *out) {
    struct list *head = &graph[this];
    struct list *elem;
    if(parent != -1) {
        out[this] = out[parent] + length;
    }
    for(elem = head->next; elem != head; elem = elem->next) {
        if(elem->dst == parent) continue;
        dfs(graph, elem->dst, this, elem->length, out);
    }
    return;
}

#define QUERY_MAX 100000

int main(void) {
    int vs = get_int();
    int es = vs - 1;
    static uint64_t ans[QUERY_MAX];
    static int aidx = 0;
    struct list *graph = create_graph(vs);

    int i;
    for(i = 0; i < es; i++) {
        int v1, v2, length;
        get_int3(&v1, &v2, &length);
        // 1-indexed -> 0-indexed
        v1--; v2--;
        add_list(&graph[v1], v2, length);
        add_list(&graph[v2], v1, length);
    }

    int qs; int root;
    get_int2(&qs, &root);
    // 1-indexed -> 0-indexed
    root--;

    static uint64_t dist[VERTEX_MAX];
    dfs(graph, root, -1, 0, dist);

    for(i = 0; i < qs; i++) {
        int v1, v2;
        get_int2(&v1, &v2);
        // 0-indexed -> 1-indexed
        v1--; v2--;
        ans[aidx++] = dist[v1] + dist[v2];
    }

    for(i = 0; i < aidx; i++) {
        printf("%lld\n", ans[i]);
    }

    return 0;
}

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

char s[(int)1e5+10];
int a[4];
int main()
{
	scanf("%s",s);
	int len=strlen(s);
	for(int i=0;i<len;i++)
	{
		a[s[i]-'a']++;
	}
	sort(a,a+3);
	if(a[2]-a[0]<=1)
	{
		puts("YES");
	}
	else
	{
		puts("NO");
	}




}


Measured memory_bytes: 384
#include<stdio.h>
#define MAX 10000010

long long c[MAX+10];  /* 約数の数を記録する */
void calc(void)
{
  for (int i = 1; i <= MAX; i++) c[i] = 1;
  for (int j = 2; j <= MAX; j++) {
    for (int i = j; i <= MAX; i+=j) c[i]++;
  }
}

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

  calc();
  long long ans = 0;
  for (int i = 1; i < n+1; i++)
  {
    ans += i * c[i];
  }
  printf("%lld\n", ans);
  

}



Measured memory_bytes: 79852
#include <bits/stdc++.h>
#define Speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
using namespace std;

#define st              first
#define nd              second
#define pb              push_back
#define pf              push_front
#define all(a)          (a).begin(), (a).end()
#define lwb             lower_bound
#define upb             upper_bound
#define vvll            vector<vector<ll> >
#define Mset(s, n)      memset(s, n, sizeof(s))
#define Sz(a)           int((a).size())
#define Max(a, b, c)    max(max((ll)(a), (ll)(b)), (ll)(c))
#define Min(a, b, c)    min(min((ll)(a), (ll)(b)), (ll)(c))
#define Unique(a)       sort(all(a)); (a).resize(unique(all(a)) - (a).begin())

typedef long double ld;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

const ll MOD = 1e9 + 7;
const int oo = 2e9;
const ld PI = acos((ld) -1);
int Getbit(ll x, int k){return (x >> (k - 1)) & 1;}
ll Lcm(ll a, ll b) {return a / __gcd(a, b) * b;}
bool isPrime(ll n){for(ll i = 2; i * i <= n; i++){if(n % i == 0) return 0;} return (n > 1) ? 1 : 0;}
ll Powmod(ll n, ll k, ll p = MOD) {ll r = 1; for(; k; k /= 2, n = n * n % p){if(k & 1) r = r * n % p;} return r;}

const int N = 2e5 + 5;

ll n, m, k;
ll a[N];

void Solve(){
    cin >> n >> m;
    string a, b;
    for(int i = 1; i <= n; i++) a.pb(m + 48);
    for(int i = 1; i <= m; i++) b.pb(n + 48);
    if(a > b) swap(a, b);
    cout << a;
}

int main(){
    Speed;
    int query = 1;
//    cin >> query;
    while(query--) Solve();
}


Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<iterator>
#include<complex>
#include<stack>
#include "stdio.h"
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const long long mod_const = 1e9+7;
using MIte = multimap<long, long, greater<long> >::iterator;

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

	// long long?
	int N;
	cin >> N;

	vector<int> val;
	rep(i, N) {
		int tmp;
		cin >> tmp;
		val.push_back(tmp);
	}
	sort(val.begin(), val.end(), greater<int>());

	int total = val[0] / 2;
	for (int i = 1; i != N; ++i) {
		total += val[i];
	}

	cout << total << endl;
	return 0;

}

Measured memory_bytes: 256
#include<iostream>
#include<map>
using namespace std;
int main()
{
    int n;
    cin>>n;
    map<int,int> a;
    for(int i=0;i<n;i++)
    {
        int r;
        cin>>r;
        a[r]++;
    }
    for(auto p:a) if(p.second>=2)
    {
        cout<<"NO";
        return 0;
    }
    cout<<"YES";
}

Measured memory_bytes: 12988
#include <bits/stdc++.h>
using namespace std;
//うろ覚え要復習
int a[12][12];
int main(){
  int n,m,x;
  cin>>n>>m>>x;
  vector<int>c(n);
  for(int i=0;i<n;i++){
    cin>>c[i];
    for(int j=0;j<m;j++){
      cin>>a[i][j];
    }
  }
  long long kotae=LLONG_MAX;
  for(int s=0;s<(1<<n);s++){
    long long cost=0;
    vector<int>d(m,0);
    for(int i=0;i<n;i++){
      if(s>>i&1){
        cost+=c[i];
        for(int j=0;j<m;j++){
          d[j]+=a[i][j];
        }
      }
    }
    bool hantei=true;
    for(int j=0;j<m;j++){
      if(d[j]<x)hantei=false;
    }
    if(hantei==true){
      kotae=min(kotae,cost);
    }
  }
  if(kotae==LLONG_MAX)cout<<-1<<endl;
  else cout<<kotae<<endl;
  return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

typedef pair<long long,int> P;

int main(){
	char s[11];
	scanf("%s",s);

	char ans[11];
	int t = 0;
	for(int i=0;i<strlen(s);i++){
		if(s[i]=='0'){
			ans[t] = '0';
			t++;
		}else if(s[i]=='1'){
			ans[t] = '1';
			t++;
		}else if(s[i]=='B'){
			ans[t] = '\0';
			if(t>0)t--;
		}
	}
	ans[t] = '\0';

	printf("%s\n",ans);

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iterator>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const int MAXN = 234567;
char s[MAXN];

int main() {
    scanf("%s", s);
    int n = strlen(s);
    LL ans = 0, cnt = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'B') cnt++;
        else ans += cnt;
    }
    printf("%lld\n", ans);
}


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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T, class S> inline bool minup(T& m, S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, S x){ return m<(T)x ? (m=(T)x, true) : false; }

const int    INF = 1000000000;
const ll     MOD = 1000000007LL;
const double EPS = 1E-12;

const int MAX_N = 1000;
int n, m;
bool used[MAX_N];
int res;

int main()
{
  while(~scanf(" %d %d", &n, &m) && n && m){
    queue<int> que;
    rep(i, n) que.push(i);
    while(true){
      rep(i, m-1){
        que.push(que.front());
        que.pop();
      }
      res = que.front() + 1;
      que.pop();
      if(que.empty()) break;
    }
    printf("%d\n", res);
  }

  return 0;
}

Measured memory_bytes: 1212
n, m = map(int, input().split())
x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]
mod = 7 + 10**9

xtotal, ytotal = 0, 0
for i in range(n-1):
    xarea = x[i+1] - x[i]
    xright, xleft =  n - i - 1, i + 1
    xtotal += (xarea * xright * xleft) %mod
    xtotal %= mod
for j in range(m-1):
    yarea = y[j+1] - y[j]
    yup = m - j -1
    ydown = j + 1
    ytotal += (yarea * yup * ydown) % mod
    ytotal % mod

print((xtotal * ytotal) % mod)

Measured memory_bytes: 19648
q, h, s, d = gets.split.map(&:to_i)
n = gets.to_i

ans = 0
now = 0

a = []
a.push({b: q, l: q*8, n: 0.25})
a.push({b: h, l: h*4, n: 0.5})
a.push({b: s, l: s*2, n: 1.0})
a.push({b: d, l: d, n: 2.0})
a.sort!{ |x, y| x[:l] <=> y[:l] }

a.each do |aa|
  nn = (n - now) / aa[:n]
  next if nn < 1
  now += aa[:n] * nn.to_i
  ans += aa[:b] * nn.to_i
  break if now == n
end
puts ans.to_i


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define ri register int
typedef long long ll;
namespace io {
	const int SIZE = (1 << 21) + 1;
	char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
	// getchar
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	// print the remaining part
	inline void flush () {
		fwrite (obuf, 1, oS - obuf, stdout);
		oS = obuf;
	}
	// putchar
	inline void putc (char x) {
		*oS ++ = x;
		if (oS == oT) flush ();
	}
	// input a signed integer
	template <class I>
	inline void gi (I &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = (x << 1) + (x << 3) + (c & 15); x *= f;
	}
	// input a signed integer
	template <class I>
	inline void read (I &x, int p) {
		for (c = gc(); c < '0' || c > '9'; c = gc()) ;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = ( (x << 1) + (x << 3) + (c & 15) ) % p; 
	}
	// print a signed integer
	template <class I>
	inline void print (I x) {
		if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10;
		while (qr) putc (qu[qr --]);
	}
	// no need to call flush at the end manually!
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
} 
using io :: gi;
using io :: read;
using io :: putc;
using io :: print;
const int N=1e5+5;
int a[N],b[N],c[N],vis[N],fa[N],d[N],mx[N],p[N],pos[N],tot,head[N],nxt[N<<1],adj[N<<1];
inline int chmax(ri x,ri y){
	return pos[x]>pos[y]?x:y;
}
inline void addedge(ri x,ri y){
	nxt[++tot]=head[x];
	adj[head[x]=tot]=y;
}
inline int find(ri x){
	return fa[x]==x?x:fa[x]=find(fa[x]);
}
inline void merge(ri x,ri y){
	if(d[x]>d[y]) swap(x,y);
	if(d[x]==d[y]) ++d[y];
	fa[x]=y;
	mx[y]=chmax(mx[x],mx[y]);
}
struct graph{
	int tot,head[N],nxt[N],adj[N];
	ll f[N],s[N];
	inline void addedge(ri x,ri y){
		nxt[++tot]=head[x];
		adj[head[x]=tot]=y;
	}
	inline void dfs(ri x){
		ri y,i;
		s[x]=b[x];
		for(i=head[x];i;i=nxt[i])
			y=adj[i],
			dfs(y),
			s[x]+=s[y];
		f[x]=s[x]+c[x];
		for(i=head[x];i;i=nxt[i])
			y=adj[i],
			f[x]=min(f[x],s[x]-s[y]+max((ll)c[x],f[y]));
	}
}t;
int main(){
	ri n,m,i,j,x,y,fx,fy;
	gi(n);gi(m);
	for(i=1;i<=n;++i)
		gi(a[i]),gi(b[i]),
		a[i]=max(a[i],b[i]),
		c[i]=a[i]-b[i],
		p[i]=i,
		fa[i]=mx[i]=i;
	sort(p+1,p+1+n,[&](ri x,ri y){ return c[x]<c[y]; });
	for(i=1;i<=n;++i) pos[p[i]]=i;
	while(m--)
		gi(x),gi(y),
		addedge(x,y),
		addedge(y,x);
	for(j=1;j<=n;++j){
		x=p[j];
		vis[x]=1;
		for(i=head[x];i;i=nxt[i])
			if(vis[y=adj[i]]){
				fx=find(x);
				fy=find(y);
				if(fx==fy) continue;
				t.addedge(x,mx[fy]);
				merge(fx,fy);
			}
	}
	t.dfs(p[n]);
	printf("%lld\n",t.f[p[n]]);
    return 0;
}

Measured memory_bytes: 14720
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define se second
#define pi 2*acos(0)
#define PI 3.14159265358979323846264338

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

const int N = 100010;
const int MX = 123456;
const int mod = (int)1e9 + 7;
const int base = 1023456789;
const ull BS1 = 10000019ULL;
const int inf = (1 << 29);

template < class T > inline void fastScan(T &x) {
    register char c = getchar();
    int neg = 0; x = 0;
    for(   ; (c < 48 || c > 57) && (c != '-'); c = getchar());
    if(c == '-') { neg = 1; c = getchar(); }
    for(   ; c > 47 && c < 58; c = getchar()){
        x = (x << 1) + (x << 3) + c - 48;
    }
    if(neg) x = -x;
}

// OrderedSet
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template < typename T > using ordered_set = tree < T, null_type, greater < T >, rb_tree_tag, tree_order_statistics_node_update >;

char s[N + N];

int main(){
  scanf("%s", s);
  int cnt = 0;
  ll ans = 0;
  for(int i = 0; s[i] ; i++){
    if(s[i] == 'B'){
      cnt++;
    } else {
      ans += cnt;
    }
  }
  printf("%lld\n", ans);
}


Measured memory_bytes: 384