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

int main()
{
    int n, m, x;
    cin >> n >> m >> x;

    vector<ll> prices(n);
    vector<vector<ll>> points(n, vector<ll> (m));

    for(int i = 0; i < n; ++i)
    {
        for(int j = 0; j <= m; ++j)
        {
            if(j == 0)
                cin >> prices[i];
            else 
            {
                cin >> points[i][j-1];
            } 
        }
    }

    ll res = INT_MAX;
    for(int bit = 0; bit < 1 << n; ++bit)
    {
        ll p = 0;
        vector<ll> sum(m, 0);
        for(int i = 0; i < n; ++i)
        {
            if(bit & (1<<i))
            {
                p += prices[i];
                for(int j = 0; j < m; ++j)
                {
                    sum[j] += points[i][j];
                }
            }
        }

        bool check = true;
        for(auto j: sum)
            if(j < x)
                check = false;

        if(check)
            res = min(res, p);
    }

    cout << (res == INT_MAX ? -1 : res) << "\n";
    return 0;
}

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

public class Main {

	public static void main(String[] args) throws IOException{
		BufferedReader sc = new BufferedReader(new InputStreamReader(System.in));
		
		while(true) {
			String[] num = sc.readLine().split(" ");
			int a = Integer.parseInt(num[0]);
			int b = Integer.parseInt(num[2]);
			
			if(num[1].equals("+")) 
				System.out.println(a+b);
			else if(num[1].equals("-"))
				System.out.println(a-b);
			else if(num[1].equals("*")) 
				System.out.println(a*b);
			else if(num[1].equals("/")) 
				System.out.println(a/b);
			else 
				break;
			
		}
	}
}

Measured memory_bytes: 24516
n,m = map(int,input().split())
p,y = [],[]
for i in range(m):
    v1,v2 = map(int,input().split())
    p.append(v1)
    y.append(v2)
    
py = zip(p,y,range(m))
py = sorted(py)
p,y,index = zip(*py)

ans = []
start = p[0]
count = 1
for i in range(m):
    if start == p[i]:
        ans.append(str(p[i]).zfill(6) + str(count).zfill(6))
        count += 1
    else:
        count = 1
        start = p[i]
        ans.append(str(p[i]).zfill(6) + str(count).zfill(6))
        count += 1

ans1 = zip(index,ans)
ans1 = sorted(ans1)
index,ans = zip(*ans1)
for i in ans:
    print(i)

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

#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define lch (o << 1)
#define rch (o << 1 | 1)

typedef double db;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int, int> pint;
typedef tuple<int, int, int> tint;

const int INF = 0x3f3f3f3f;
const ll INF_LL = 0x3f3f3f3f3f3f3f3f;

int main() {
	ios::sync_with_stdio(0);

	ll ans = 0;
	int n;
	cin >> n;
	int pre = 0;
	for (int i = 1; i <= n; i++) {
		int a;
		cin >> a;
		if (a < pre) {
			ans += pre - a;
		}
		pre = max(pre, a);
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3648
object Main {

  def main(args: Array[String]): Unit = {
    import scala.io.StdIn._

//    val Array(n, m) = readLine().split(" ").map(_.toInt)
//    val KS: Array[(Int, Array[Int])] = (0 until m). map { i =>
//      val Array(k, s @ _*) = readLine().split(" ").map(_.toInt)
//      (k, s.toArray)
//    }. toArray
//    val P = readLine().split(" ").map(_.toInt)

    val Array(_n, _k) = readLine().split(" ").map(_.toInt)
    val N = _n
    val K = _k
    val V = readLine().split(" ").map(_.toInt)
    val dp = Array.fill(K+1, N, N)(Int.MinValue)

    //　K回目の操作の時に, Vl ~ Vrのうちから取り出す最大価値
    def solve(k: Int, l: Int, r: Int): Int =
      if (k <= 0 || l < 0 || l >= N || r < 0 || r >= N || l > r) 0 // 残り操作回数が0回以下なら0
      else if (dp(k)(l)(r) >= 0) dp(k)(l)(r)
      else {
        dp(k)(l)(r) = Math.max(
          Math.max(solve(k - 2, l + 1, r), solve(k - 1, l + 1, r) + V(l)),
          Math.max(solve(k - 2, l, r - 1), solve(k - 1, l, r - 1) + V(r)))
        dp(k)(l)(r)
      }

    println(solve(K, 0, N-1))
  }
}

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

#define LL long long

LL sqrt(LL n) {
    LL l = 1;
    LL r = min<LL>(3037000500, n);
    for(;1 < r - l;) {
        LL mid = (l + r)/2;
        if(n < mid*mid) {
            r = mid;
        }else if(mid*mid < n){
            l = mid;
        }else{
            return mid;
        }
    }
    return r;
}

LL digit(LL n) {
    if(n == 0)
        return 1;
    LL i;
    for(i = 0;0 < n;i++) {
        n /= 10;
    }
    return i;
}

int main() {
    LL N;
    cin >> N;
    LL sq = sqrt(N);
    LL res = 334;
    for(LL i = 1;i <= sq;i++) {
        if(N%i == 0) {
            res = min(digit(N/i), res);
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = [list(input().split()) for _ in range(N)]
x = input().strip()
for i in range(N):
    if A[i][0]==x:
        ind = i
        break
cnt = 0
for i in range(ind+1,N):
    cnt += int(A[i][1])
print(cnt)

Measured memory_bytes: 62044
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 1000007
#define INF63 1061109567
#define INF127 9187201950435737471
#define UINF 18446744073709551615
#define F first
#define S second
#define ll long long
#define N 1000010
using namespace std;
ll n,k,c,mst=0,sz,segt[N][2];
string s;
vector<ll> num[N];
void update(ll x,ll v,ll verd)
{
	segt[x][verd]=v;
	x/=2;
	while(x)
	{
		segt[x][verd]=max(segt[x][verd],v);
		x/=2;
	}
	return;
}
ll getans(ll l,ll r,ll verd)
{
	ll ret=-LINF;
	while(l<r)
	{
		if(l%2==1)
		{
			ret=max(ret,segt[l][verd]);
		}
		if(r%2==1)
		{
			ret=max(ret,segt[r-1][verd]);
		}
		l=(l+(ll)1)>>(ll)1;
		r>>=(ll)1;
	}
	return ret;
}
int main(){
	ll i,v;
	cin>>n>>k>>c>>s;
	s="!"+s+"!";
	for(i=1;i<=n;i++)
	{
		if(s[i]=='o')
		{
			mst++;
			i+=c;
		}
	}
	if(mst>k)
	{
		return 0;
	}
	for(sz=1;sz<2*(n+1);sz<<=1);
	memset(segt,-127,sizeof(segt));
	sz>>=(ll)1;
	update(sz,0,0);
	for(i=1;i<=n;i++)
	{
		v=(s[i]=='o')+getans(sz,max(sz+1,sz+i-c),0);
		update(sz+i,v,0);
	}
	update(sz+n+1,0,1);
	for(i=n;i>=1;i--)
	{
		v=(s[i]=='o')+getans(min(sz+n+1,sz+i+c+1),sz+n+2,1);
		update(sz+i,v,1);
	}
	for(i=1;i<=n;i++)
	{
		if(s[i]=='o')
		{
			v=getans(sz,max(sz+1,sz+i-c),0);
			if(v+getans(min(sz+n+1,sz+i+c+1),sz+n+2,1)==k-1)
			{
				num[v].push_back(i);
			}
		}
	}
	for(i=0;i<=k;i++)
	{
		if(num[i].size()==1)
		{
			cout<<num[i][0]<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 47040
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, accumulate, inner_product
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(int)>

#define rep(i,n) for(int i = 0; i < n; i++)
#define ENDL "\n"
#define print(i) std::cout << (i) << "\n"

#define int long long // at least int64 > 9*10^18
#define all(v) v.begin(), v.end()

signed main() {
	int n;
	std::cin >> n;
	std::vector<int> a(n);
	rep(i,n) std::cin >> a[i];
	std::sort(all(a));
	if(a[n-1]==0) {
		print("Yes");
		return 0;
	}
	if(n%3) {
		print("No");
		return 0;
	}
	int unique_count = 0;
	std::set<int> temp(all(a));
	unique_count = temp.size();
	if(unique_count == 2 && *temp.begin() == 0) {
		int ans = true;
		std::map<int,int> count;
		for(int i:a) {
			count[i]++;
		}
		if(count[0]!=n/3) ans = false;
		if(ans) {
			print("Yes");
			return 0;
		}
		print("No");
		return 0;
	}
	if(unique_count != 3) {
		print("No");
		return 0;
	}
	if((*temp.begin()^*(std::next(temp.begin())))!=*(std::next(std::next(temp.begin())))) {
		print("No");
		return 0;
	}
	std::map<int,int> count;
	for(int i:a) {
		count[i]++;
	}
	int ans = true;
	for(auto i:count) {
		if(i.second != n/3) ans = false;
	}
	if(ans) {
		print("Yes");
		return 0;
	}
	print("No");
	return 0;
}


Measured memory_bytes: 4480
#include <cstring>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <numeric>
#include <stack>

using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
typedef unordered_map<ll, ll> ump;
typedef pair<ll, ll> P;

ump mp;
ll dp[3010][3010];

int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
        mp = ump();
#pragma clang diagnostic pop
#endif
        string s, t;
        cin >> s >> t;

        rep(i, 3010) rep(j, 3010) dp[i][j] = 0;

        rep(i, s.size()) {
            rep(j, t.size()) {
                if (s[i] == t[j]) {
                    dp[i + 1][j + 1] = dp[i][j] + 1;
                } else {
                    dp[i + 1][j + 1] = max({dp[i + 1][j + 1], dp[i][j + 1], dp[i + 1][j]});
                }
            }
        }
        string ans;
        ll i = s.size(), j = t.size();
        while (i > 0 && j > 0) {
            if (dp[i][j] == dp[i - 1][j]) i--;
            else if (dp[i][j] == dp[i][j - 1]) j--;
            else {
                ans = s[i - 1] + ans;
                i--, j--;
            }
        }

        cout << ans << endl;


#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 71040
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define MOD 1000000007
#define EPS (1e-10)
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
#define int long long

int cnt[100000], a[100000], b[100000];
signed main() {
	int n; scanf("%lld", &n);
	rep(i, n) {
		scanf("%lld%lld", &a[i], &b[i]);
	}
	int p = 0;
	int cnt = 0;
	for (int i = n - 1; i >= 0; i--) {
		a[i] += p;
		if (a[i] % b[i] == 0)continue;
		int u = (a[i] / b[i] + 1)*b[i] - a[i];
		p += u;
	}
	printf("%lld\n", p);
}

Measured memory_bytes: 1792
from collections import Counter
N = int(input())
l = list(map(int, input().split()))
c = Counter(l)

t = int(sum([v * (v-1) / 2 for k, v in c.items() if v > 1]))
for k in range(N):
    c_k = c[l[k]]
    if c_k > 1:
        print(t-c_k+1)
    else:
        print(t)

Measured memory_bytes: 26780
#[allow(unused_imports)]
use proconio::{
   fastout, input,
   marker::{Bytes, Chars, Isize1, Usize1},
};

use std::collections::HashMap;

fn main() {
   input! {
      n:usize,
      a:[isize;n]
   }
   let mut map = HashMap::new();
   let mut v = vec![];
   let mut c = 0;
   for i in a {
      v.push(i - c);
      *map.entry(i - c).or_insert(0) += 1;
      c += 1;
   }
   let mut ans = 0_usize;
   let mut c = 0;
   for i in v {
      let s = i + c;
      if map.contains_key(&(-1 * s - c)) {
         ans += map[&(-1 * s - c)];
      }
      *map.entry(i).or_insert(0) -= 1;
      c += 1;
   }
   println!("{}", ans);
}


Measured memory_bytes: 12844
#include<bits/stdc++.h>
using namespace std;
int main ()
  {
     int n,x,t,a,b;
     cin>>n>>x>>t;
     a=n/x;
     b=a*t;
     if(n%x==0)
       {
         cout<<b<<endl;
       }
     else{
        cout<<b+t<<endl;
         }
   return 0;
  }

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

#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

constexpr ll mod = 1e9 + 7;

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

    VVL dp(L.size()+10, VL(2, 0));
    // dp[i][0] : 左からi桁目まで決めたときの(a, b)の組み合わせの数（exact := a+b == L)
    // dp[i][1] : 同上（smaller）

    // Lの先頭は1なので．
    dp[0][0] = 2; // (0, 1), (1, 0)
    dp[0][1] = 1; // (0, 0)

    // i = 1を考えると，
    // L[i] = 0のとき，
    // (0, 1) -> (00, 10), x(00, 11), x(01, 10), x(01, 11)
    // (0, 0) -> (01, 00), x(01, 01), (00, 00), (00, 01)
    // (1, 0) -> (10, 00), x(10, 01)
    // の遷移が考えられるが，まず，b=11はLより大きくなるので却下
    // また，(01, 10)もLより大きくなるので不可

    // まず，両方に1をつける操作は不可
    // L_i = 0/１ のとき，smaller は両方に1以外なら，なんでもたいして良い：3通り
    // L_i = 0 のとき，exactは末尾に0をつけることしかできない．
    // L_i = 1 のとき，exactは末尾に1をつけて，exactをKeepする2通りと，aかbの末尾に0をつけて，smallerに落とす1通りがある．

    rep(i, 1, L.size()){

        // smaller -> smaller
        dp[i][1] = 3 * dp[i-1][1];
        dp[i][1] %= mod;

        // exact -> smaller
        if(L[i] == '1'){
            dp[i][1] += dp[i-1][0];
            dp[i][1] %= mod;
        }

        // exact -> exact
        if(L[i] == '1'){
            dp[i][0] = 2 * dp[i-1][0];
            dp[i][0] %= mod;
        }else{
            dp[i][0] = dp[i-1][0];
        }
    }

    ll ans = dp[L.size()-1][0] + dp[L.size()-1][1];
    ans %= mod;

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

Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int w[n];
  for(int i=0;i<n;i++)cin>>w[i];
  int s1=0,s2=0;
  for(int i=0;i<n;i++)s1+=w[i];
  int ans=abs(s1-s2);
  for(int i=0;i<n;i++){
    s1-=w[i];
    s2+=w[i];
    ans=min(ans,abs(s1-s2));
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
/*COMPETITIVE PROGRAMMING C++ TEMPLATE */

#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <cmath>
#include <iostream>
#include <stack>
#include <queue>
#include <climits>
#include <iomanip>

#define all(x) x.begin(), x.end()
#define MOD 998244353

const long double PI = 3.141592653589793236L;

typedef long long int ll;
typedef long double ld;

using namespace std;

void solve()
{
    int x, n;
    cin >> x >> n;

    vector<int> p(n);

    for(int i = 0; i < n; i++)
    {
        cin >> p[i];
    }

    set<int> S;

    for(int i= 0; i < n; i++)
    {
        S.insert(p[i]);
    }

    if(S.find(x) == S.end())
    {
        cout << x << endl;
        return;
    }

    for(int i = 1; i < 1000; i++)
    {
        if(S.find(x - i) == S.end())
        {
            cout << x - i << endl;
            return;
        }

        if(S.find(x + i) == S.end())
        {
            cout << x + i << endl;
            return;
        }
    }
     
}

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

    int T = 1;
    //cin >> T;
    
    while (T--)
    {
        solve();
    }
    
    return 0;
}



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

int main(){
	int p1;
	int p2;
	int p3;
	int j1;
	int j2;
	cin >> p1 >> p2 >> p3 >> j1 >> j2;
	cout << min( p1, min (p2, p3)) + min( j1, j2 ) - 50 << endl;

	return 0;
}

Measured memory_bytes: 3032
use std::io::prelude::*;

fn main() {
    let scan = std::io::stdin();
    
    let mut line = String::new();
    let _ = scan.read_line(&mut line);
    let v: Vec<&str> = line.split_whitespace().collect();
    
    let _n: usize = v[0].parse().unwrap_or(0);
    let m: usize = v[1].parse().unwrap_or(0);

    let mut sum_a: Vec<u32> = vec![0; m];
    
    for line in scan.lock().lines() {
        let uline = line.unwrap();
        let vec: Vec<&str> = uline.split_whitespace().collect(); 
        let mut sum: u32 = 0;
        for (i, e) in vec.iter().enumerate() {
            let x: u32 = e.parse().unwrap_or(0);
            print!("{} ", x);
            sum += x;
            sum_a[i] += x;
        }
        println!("{}", sum);
    }
    let mut sum: u32 = 0;
    for e in sum_a {
        print!("{} ", e);
        sum += e;
    }
    println!("{}", sum);
}


Measured memory_bytes: 5036
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()
}

fn main() {
    let (h, a) = {
        let tmp = read_vec::<isize>();
        (tmp[0], tmp[1])
    };
    let ans = if (h % a) == 0 {
            h / a
    } else {
        h / a + 1
    };
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include<stdio.h>
int main(void)
{
	int n,k,x,y,i,sum;
	scanf("%d %d %d %d",&n,&k,&x,&y);
	sum=0;
	for(i=1;i<=n;i++){
			if(i<=k) sum+=x;
			else sum+=y;
	}
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 256
from math import ceil, log

n = int(input())
h = list(map(int, input().split()))
a = list(map(int, input().split()))


class SegmentTree(object):
    __slots__ = ["elem_size", "tree", "default", "op"]

    def __init__(self, a: list, default: int, op):
        real_size = len(a)
        self.elem_size = elem_size = 1 << ceil(log(real_size, 2))
        self.tree = tree = [default] * (elem_size * 2)
        tree[elem_size:elem_size + real_size] = a
        self.default = default
        self.op = op

        for i in range(elem_size - 1, 0, -1):
            tree[i] = op(tree[i << 1], tree[(i << 1) + 1])

    def get(self, x: int, y: int) -> int:  # [x, y)
        l, r = x + self.elem_size, y + self.elem_size
        tree, result, op = self.tree, self.default, self.op
        while l < r:
            if l & 1:
                result = op(tree[l], result)
                l += 1
            if r & 1:
                r -= 1
                result = op(tree[r], result)
            l, r = l >> 1, r >> 1

        return result

    def set(self, i: int, value: int) -> None:
        k = self.elem_size + i
        self.tree[k] = value
        self.update(k)

    def update(self, i: int) -> None:
        op, tree = self.op, self.tree
        while i > 1:
            i >>= 1
            tree[i] = op(tree[i << 1], tree[(i << 1) + 1])


dp = SegmentTree([0] * (n+1), 0, max)

for i in range(n):
    v = dp.get(0, h[i]) + a[i]
    if v > dp.get(h[i], h[i]+1):
        dp.set(h[i], v)

print(dp.get(0, n+1))

Measured memory_bytes: 120956
s = [len(x) for x in input().split('T')]
x, y = map(int, input().split())
len_s = len(s)
sx = [s[i] for i in range(len_s) if i % 2 == 0]
sy = [s[i] for i in range(len_s) if i % 2 == 1]

x -= sx[0]
sx = sx[1:]



def is_reachable(p, s):
    origin = 8000
    if origin+p < 0:
        return False
        
    n = len(s)
    reachable = [set() for i in range(n + 1)]
    reachable[0].add(origin)

    for i in range(n):
        for j in list(reachable[i]):
            if j - s[i] >= 0:
                reachable[i + 1].add(j - s[i])
            if j + s[i] <= origin * 2:
                reachable[i+1].add(j + s[i])
    return (origin+p) in reachable[n] or (origin-p) in reachable[n]


if is_reachable(x, sx) and is_reachable(y, sy):
    print('Yes')
else:
    print('No')


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

#define lpsbd(i, s, b, d) for(size_t i = s; i < b; i+=d)
#define lpsb(i, s, b) for(size_t i = s; i < b; i++)
#define lpn(i, n) for(size_t i = 0; i < n; i++)
#define fa(i, x) for(auto &i: x)
#define vcd(t, n, d) vector<t>(n, d)
#define vc(t, n) vector<t>(n)

using namespace std;
using ull = unsigned long long;

const ull MOD = 1000000007;

int main(void)
{
    int A, B;
    cin >> A >> B;
    cout << ((A >= 13) ? B : (A >= 6 ? B / 2 : 0)) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int N;
int L[111];
int bt[111];
ll dp[111][(1<<16)];
int main(){
  while( cin >> N && N ){
    for(int i=0;i<N;i++){
      int M;
      cin >> M >> L[i];
      bt[i] = 0;
      for(int j=0;j<M;j++){
        int s,e; cin >> s >> e;
        s-=6; e-=6;
        for(int k=s;k<e;k++){
          bt[i] |= (1<<k);
        }
      }
    }
    memset(dp,-1,sizeof(dp));
    dp[0][0] = 0LL;
    for(int i=0;i<N;i++){
      for(int j=0;j<(1<<16);j++){
        if( dp[i][j] == -1LL ) continue;
        if( !(j & bt[i]) ) 
          dp[i+1][j|bt[i]] = max(dp[i+1][j],
                                 dp[i][j] + L[i]);
          dp[i+1][j] = max(dp[i+1][j],dp[i][j]);
      }
    }  
    ll res = 0;
    for(int i=0;i<(1<<16);i++)
      res = max( res, dp[N][i] );
    cout << res << endl;
  }
}

Measured memory_bytes: 57996
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
typedef long long ll;

using namespace std;

// init {{{
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


const int NM = 101001;//ここを問題の制約を見ながらいじる．配列の確保に使う．
//int A[NM];//あまり褒められたことではないが関数の外側に配列を確保すると怒られにくい．


int permutationMethod(int n,int r){
    r = n - r;
    int sum = 1;
    int i;
    for (i=n;i>=r+1;i--)sum*=i;
    return sum;
}

// Main program
void solve(){
  int N;
  int Q[8],P[8];
  cin >> N ;
  
  for(int i=0;i<N;i++){
    cin >> P[i];
  }
  for(int i=0;i<N;i++){
    cin >> Q[i];
  }

    vector<int> v(N);
    iota(v.begin(), v.end(), 1);
    int Pnum=0;
    do {
        int i=0;
        bool flag=true;
        for(auto x : v) {
          if( x!=P[i]){ 
            flag=false;
          }
          i++;
        }
      Pnum++;

      if(flag){break;}      
    } while( next_permutation(v.begin(), v.end()) );

      vector<int> v2(N);
    iota(v2.begin(), v2.end(), 1);
    int Qnum=0;
    do {
        int i=0;
        bool flag=true;
        for(auto x : v2) {
          if( x!=Q[i]){ 
            flag=false;
          }
          i++;
        }
      Qnum++;
      if(flag){break;}      
    } while( next_permutation(v2.begin(), v2.end()) );
    
  //cout << Pnum;
  //  cout << Qnum;
  
  cout << abs(Pnum - Qnum);
  
  return;

}

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






Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define dl double long
#define rep(i, m, n) for(ll i = (ll)(m); i < (ll)(n); ++i)
#define rrep(i, m, n) for(ll i = (ll)(m); i > (ll)(n); --i)
const ll MOD = 1000000007;
const double pi = 3.14159265358979323846;

int main(void){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << (((a+d-1) / d >= (c+b-1) / b)?"Yes":"No") << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <stdio.h>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional> //operator[]
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define Rep(i,n) for(int i=1;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define Rrep(i,n) for(int i=n-1;i>0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
#define P pair<int,int>
#define Pll pair<ll,ll>
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main(){
    int k,a,b; cin >> k >> a >> b;
    rep(i,10000){
        if(a<=i*k&&i*k<=b){
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
}


Measured memory_bytes: 3620
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define EPS 1e-9
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1LL << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
signed main() {
	cin >> N >> M;
	vector< int > D(N + 1), P(N + 1);
	D[0] = 1;
	rep(i, N) D[i + 1] = D[i] * 2 + 3;
	P[0] = 1;
	rep(i, N) P[i + 1] = P[i] * 2 + 1;
	int ans = 0;
	int l = N;
	while (M > 0) {
		if (D[l] <= M) {
			M -= D[l];
			ans += P[l];
			if (M > 0) {
				M--;
				ans++;
			}
		} else {
			M--;
			l--;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
package main

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

var (
	readString func() string
	readBytes  func() []byte
	stdout     *bufio.Writer
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

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

func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

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

func max64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func abs64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func gcd64(a, b int64) int64 {
	if b == 0 {
		return a
	}
	return gcd64(b, a%b)
}

// readString() string
// readInt() int
// readInt64() int64
// readFloat64() float64

// -----------------------------------------------------------------------------

func main() {
	defer stdout.Flush()
	N := readInt()

	dp := make([]int, N+1)
	for i := range dp {
		dp[i] = 1000000007
	}
	dp[0] = 0
	dp[1] = 1
	for i := 6; i <= N; i *= 6 {
		dp[i] = 1
	}
	for i := 9; i <= N; i *= 9 {
		dp[i] = 1
	}
	for i := 1; i <= N; i++ {
		if 1 <= i {
			dp[i] = min(dp[i], dp[i-1]+1)
		}
		for j := 6; i+j <= N; j *= 6 {
			dp[i+j] = min(dp[i+j], dp[i]+1)
		}
		for j := 9; i+j <= N; j *= 9 {
			dp[i+j] = min(dp[i+j], dp[i]+1)
		}
	}

	println(dp[N])
}

// -----------------------------------------------------------------------------


Measured memory_bytes: 1408
#pragma GCC optimize(3,"Ofast","inline")
#include <bits/stdc++.h>

using namespace std;

int n, ans, minp, p;

int main()
{
	cin>>n;
	for(int i = 0; i < n; i ++)
	{
		cin>>p;
		if(i == 0)
		{
			ans ++;
			minp = p;
			continue;
		}
		else if(p <= minp)
		{
			ans ++;
			minp = p;
			//cout<<minp<<endl;
			continue;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    int A, B, C, K; scanf("%d%d%d%d", &A, &B, &C, &K);

    int sum = A + B + C, MAX = max({A, B, C});;

    for (int i = 0; i < K; i++) {
        sum += MAX; MAX *= 2;
    }

    printf("%d", sum);
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <tuple>

const int MAXN = 100004;
const int M = 1000000007;
const long long INF = 1e17;

typedef std::tuple<long long,int> ii;

int N, S, E;
long long dist[MAXN], dist2[MAXN];
int num[MAXN], num2[MAXN];
std::vector<int> edge[MAXN];
std::vector<int> cost[MAXN];

int main() {
  using namespace std;
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int q;
  cin >> N >> q;
  cin >> S >> E;

  for (int i = 0; i < q ; ++i) {
    int x, y, c;
    cin >> x >> y >> c;
    c <<= 1;
    edge[x].push_back(y);
    cost[x].push_back(c);
    edge[y].push_back(x);
    cost[y].push_back(c);
  }

  fill(dist, dist + N + 1, INF);
  dist[S] = 0;
  num[S] = 1;

  priority_queue<ii> pq;
  pq.emplace(0ll, S);

  do {
    long long nc;
    int np;
    std::tie(nc, np) = pq.top();
    nc = -nc;
    pq.pop();

    if (nc > dist[np]) continue;
    for (int i = 0; i < edge[np].size(); ++i) {
      const int xp = edge[np][i], xc = cost[np][i];
      if (nc + xc < dist[xp]) {
        dist[xp] = nc + xc;
        num[xp] = num[np];
        pq.emplace(-(nc + xc), xp);
      } else if (nc + xc == dist[xp]) {
        num[xp] = (num[xp] + num[np]) % M;
      }
    }
  } while(!pq.empty());

  fill(dist2, dist2 + N + 1, INF);
  dist2[E] = 0;
  num2[E] = 1;

  pq.emplace(0ll, E);

  do {
    long long nc;
    int np;
    std::tie(nc, np) = pq.top();
    nc = -nc;
    pq.pop();

    if (nc > dist2[np]) continue;
    for (int i = 0; i < edge[np].size(); ++i) {
      const int xp = edge[np][i], xc = cost[np][i];
      if (nc + xc < dist2[xp]) {
        dist2[xp] = nc + xc;
        num2[xp] = num2[np];
        pq.emplace(-(nc + xc), xp);
      } else if (nc + xc == dist2[xp]) {
        num2[xp] = (num2[xp] + num2[np]) % M;
      }
    }
  } while(!pq.empty());

  const long long ff = dist[E];
  const long long hf = (dist[E] >> 1);
  const int fn = num[E];
  long long ans = 0;
  for (int i = 1; i <= N; ++i) {
    if (dist[i] > hf) continue;
    if (dist[i] == hf) {
      const long long r1 = num[i] * (long long)num2[i] % M;
      const long long r2 = (M + fn - r1) % M;
      ans = (ans + (r1 * r2 % M)) % M;
      continue;
    }
    for (int j = 0; j < edge[i].size(); ++j) {
      const int xp = edge[i][j], xc = cost[i][j];
      if (dist[i] + dist2[xp] + xc != ff) continue;
      if (dist[i] + xc <= hf) continue;
      const long long r1 = num[i] * (long long)num2[xp] % M;
      const long long r2 = (M + fn - r1) % M;
      ans = (ans + (r1 * r2 % M)) % M;
    }
  }

  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 18028
<?php
fscanf(STDIN, "%d %d", $n, $k);
$array = explode(' ', trim(fgets(STDIN)));
 
$count = 0;
 
// 何種類か確認
$syurui = count(array_unique($array));
if (isClear($k, $syurui) == false) {
  $arrayCountValues = array_count_values($array);
  sort($arrayCountValues);
  $valueCount = count($arrayCountValues);
  for ($i = 0; $i < $valueCount; $i++) {
    $count = $count + $arrayCountValues[$i];
    $syurui = $syurui - 1;
    if (isClear($k, $syurui)) {
      break;
    }
  }
}
 
function isClear($k, $syurui) {
  if ($k >= $syurui) {
    return true;
  }
  return false;
}
 
echo $count;

Measured memory_bytes: 68880
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1);
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; }

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

int h, w, sy, sx, gy, gx;
string s[1010];
int dist[1010][1010];

int main() {
    cin >> h >> w;
    cin >> sy >> sx >> gy >> gx;
    sy--; sx--; gy--; gx--;
    rep(i, h) cin >> s[i];

    // BFS
    deque<pii> q;
    q.emplace_back(sy, sx);
    rep(y, h) rep(x, w) dist[y][x] = INF;
    dist[sy][sx] = 0;
    while (q.size()) {
        pii now = q.front(); q.pop_front();
        int y = now.first;
        int x = now.second;

        // move to an adjacent square
        rep(i, 4) {
            int ny = y + dy[i];
            int nx = x + dx[i];
            if (nx < 0 || nx >= w || ny < 0 || ny >= h) continue;
            if (s[ny][nx] == '#') continue;
            if (chmin(dist[ny][nx], dist[y][x])) q.emplace_front(ny, nx);
        }

        // warp
        for (int ry = -2; ry <= 2; ry++) {
            for (int rx = -2; rx <= 2; rx++) {
                int ny = y + ry;
                int nx = x + rx;
                if (nx < 0 || nx >= w || ny < 0 || ny >= h) continue;
                if (s[ny][nx] == '#') continue;
                if (chmin(dist[ny][nx], dist[y][x] + 1)) q.emplace_back(ny, nx);
            }
        }
    }

    int ans = dist[gy][gx];
    if (ans == INF) ans = -1;
    cout << ans << endl;
}


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

using namespace std;
#define long long long

int const N = 1e5 + 10;

int n, total;
long w[110], v[110], f[110][N];

int main()
{
//    freopen("tam.inp", "r", stdin);
    cin.tie(nullptr); ios_base::sync_with_stdio(false);

    cin >> n >> total;
    for (int i = 1; i <= n; ++i) cin >> w[i] >> v[i];

    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= total; ++j) {
            f[i][j] = f[i - 1][j];
            if (w[i] <= j) f[i][j] = max(f[i][j], f[i - 1][j - w[i]] + v[i]);
        }
    cout << f[n][total];

    return 0;
}


Measured memory_bytes: 79360
/**
 * Maximum Sum Sequence II
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

import static java.lang.Integer.parseInt;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;

		while ((line = br.readLine()) != null && !line.isEmpty()) {
			int n = parseInt(line);
			int[][] matrix = new int[n + 2][n + 2];

			for (int i = 1; i < n + 1; i++) {
				StringTokenizer st = new StringTokenizer(br.readLine());
				for (int j = 1; j < n + 1; j++) {
					matrix[i][j] = parseInt(st.nextToken()) + matrix[i - 1][j] + matrix[i][j - 1] - matrix[i - 1][j - 1];
				}
			}

			//
			int max = Integer.MIN_VALUE;
			for (int i = 0; i < n; i++) {
				for (int j = i + 1; j < n + 1; j++) {
					for (int k = 0; k < n; k++) {
						for (int l = k + 1; l < n + 1; l++) {
							max = Math.max(max, matrix[j][l] - matrix[j][k] - matrix[i][l] + matrix[i][k]);
						}
					}
				}
			}
			System.out.println(max);
		} //end while
	} //end main
}

Measured memory_bytes: 22940
#include <iostream>
#include <algorithm>
#include <vector>
#include <cassert>
#include <cmath>

int main(int argc, char **argv)
{
    std::vector<int> A(4);
    std::cin >> A.at(0) >> A.at(1) >> A.at(2) >> A.at(3);
    assert(A.at(0) < A.at(1));
    assert(A.at(2) < A.at(3));

    if(A.at(0) <= A.at(3) && A.at(2) <= A.at(1)){
        std::sort(A.begin(), A.end());
        std::cout << A.at(2) - A.at(1) << std::endl;
    }else{
        std::cout << 0 << std::endl;
    }
}


Measured memory_bytes: 256
#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
//#define int long long
/*---------------for_stuff-------------------*/
#define f(i,a,b) for (int i=a;i<=b;i++)
#define f_(i,a,b) for (int i=a;i>=b;i--)
/*---------------pair_stuff------------------*/
#define MP make_pair
#define ii pair<char,char>
#define fi first
#define se second
/*--------------vector_stuff-----------------*/
#define pb push_back
#define ppb pop_back
/*--------------const_stuff-----------------*/
const ll mod=1000000007;
const int N=100005;

string s,t;
int dem=0;
vector<int> v[30];
int find(int vtri,int chu) {
	if (vtri>v[chu][v[chu].size()-1]) {
		dem++;
		return v[chu][0];
	}
	if (vtri<=v[chu][0]) return v[chu][0];
	int l,r;
	l=0;
	r=v[chu].size()-1;
	while (l<r) {
		int mid=(l+r)/2;
//		 cout<<"fuck\n";
		if (v[chu][mid]<vtri) l=mid+1;
		else r=mid;
	}
	return v[chu][r];
}
signed main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin>>s>>t;
	for (int i=0;i<s.size();i++) {
		v[s[i]-'a'].pb(i);
	}
	int pos=0;
	for (int i=0;i<t.size();i++) {
		if (v[t[i]-'a'].size()==0) {
			printf("-1");
			return 0;
		}
		pos=find(pos,t[i]-'a')+1;
//		cout<<pos<<" ";
	}
	// cout<<"\n";
	cout<<pos+dem*s.size();
	// cout<<"\n"<<pos<<" "<<dem;
	return 0;
}

Measured memory_bytes: 1216
#include <stdio.h>

int main(){
	int n, cnt = 1;
	scanf("%d", &n);
	while (n){
		float s = 0, x0, y0, xa, xb, ya, yb;
		scanf("%f %f", &x0, &y0);
		xb = x0;
		yb = y0;
		for (int i = n - 1; i>0; i--){
			xa = xb;
			ya = yb;
			scanf("%f %f", &xb, &yb);
			s += (xb + xa)*(yb - ya);
		}
		s += (x0 + xb)*(y0 - yb);
		printf("%d %.1f\n", cnt++, s>0 ? s / 2 : (-s) / 2);
		scanf("%d", &n);
	}
	return 0;
}

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

count = [0] * (max(A)+1)
for i in range(len(A)):
    count[A[i]] += 1

ans = 0

for i in range(max(A)+1):
    if count[i] >= 2:
        ans += count[i] - 1

if ans%2 == 0:
    print(N - ans)
else:
    print(N - ans -1)

Measured memory_bytes: 14388
import java.util.*;

public class Main {

    public static void main(String[] args) {
	// write your code here
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        Stack<Character> stack = new Stack<>();
        for (char c : s.toCharArray()) {
            if (c == '0') {
                if (stack.size() > 0 && stack.peek() == '1') {
                    stack.pop();
                    continue;
                }

            }
            else {
                if (stack.size() > 0 && stack.peek() == '0') {
                    stack.pop();
                    continue;
                }
            }
            stack.push(c);
        }
        System.out.println(s.length() - stack.size());
    }
}


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

int main() {
  int A,B,K;

  cin >> A >> B >> K;
  int data;
  int counter = 0;
  
  for(int i = A;i > 0;i--){
    if(A % i == 0 && B % i == 0){
      data = i;
      counter++;
    }
    if(counter == K)break;
  }

  cout << data << endl;
}


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

int main(){
  int N,M = 0;
  cin >> N >> M;
  vector<int> count(M*2);
  
  for(int i=0;i<M*2;i++){
    cin >> count.at(i);
  }
  for(int i=1;i<=N;i++){
    int sum = 0;
    for(int j=0;j<M*2;j++){
      if(i == count.at(j)){
        sum++;
      }
    }
    cout << sum << endl;
  }
}

Measured memory_bytes: 3568
N,M = gets.split.map(&:to_i)
if N>=M
    puts '0'
    exit
end
X = gets.split.map(&:to_i).sort
Z = Array.new(N,false)
Y = Array.new(N-1)
(M-1).times do |i|
    Y[i]=X[i+1]-X[i]
end
s=Y.length-N+1
puts Y.sort[0..s-1].sum

Measured memory_bytes: 23996
N,M = map(int, input().split())
H = list(map(int, input().split()))
res = [1]*N
for i in range(M):
    a,b = map(int, input().split())
    if H[a-1] <= H[b-1]:
        res[a-1] = 0
    if H[b-1] <= H[a-1]:
        res[b-1] = 0
print(sum(res))

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

int n;

void dfs(string s, char mx){
    if(s.size() == n)cout << s << endl;
    else {
        for(char c = 'a';c<=mx;c++)dfs(s+c,((c==mx)?(char)(mx+1) : mx));
    }
}

int main(){
    cin >> n;
    dfs("", 'a');
}

Measured memory_bytes: 1536
#include<iostream>
using namespace std;
#define MAX 100000

int parent(int i){return i/2;}
int left(int i){return 2*i;}
int right(int i){return 2*i+1;}

int main(){
  int H, i, A[MAX+1];

  cin >> H;
  for(i=1; i<=H; i++) cin >> A[i];

  for(i=1; i<=H; i++){
    cout << "node " << i << ": key = " << A[i] << ", ";
    if(parent(i) >= 1) cout << "parent key = " << A[parent(i)] << ", ";
    if(left(i) <= H) cout << "left key = " << A[left(i)] << ", ";
    if(right(i) <= H) cout << "right key = " << A[right(i)] << ", ";
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 3108
n = int(input())
s = []
for i in range(n):
    s.append(input())

count = 0
for i in range(n):
    for j in range(len(s[i])-1):
        if s[i][j:j+2] == "AB":
            count += 1
a_end = 0
b_start = 0
both = 0
for i in range(n):
    if s[i][0] == "B":
        if s[i][-1] == "A":
            both += 1
        else:
            b_start += 1
    elif s[i][-1] == "A":
        a_end += 1
if a_end == 0 and b_start == 0:
    count += max(0,(both-1))
else:
    count += (both + min(a_end, b_start))
print(count)

Measured memory_bytes: 3700
#include <stdio.h>

int main(void)
{
  int a,b,c;
  scanf("%d",&a);
  scanf("%d",&b);
  scanf("%d",&c);
  
  if(a>=b && a>=c)
    printf("%d",b+c);
  else if(b>=a, b>=c)
    printf("%d",a+c);
  else
    printf("%d",a+b);
  
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <float.h>
#include <limits>
#include <vector> 
#include <string.h>
#include <iomanip>

#define rep(i,a,n) for(ll int (i) = (a);(i) < (n);(i)++)
#define urep(i,a,n) for(ll int (i) = (a);(i) > (n);(i)--)
#define MOD 1000000007
#define INF 2147483647
#define ll long long
#define asort(a) sort(a.begin(),a.end());//昇順ソート
#define usort(a) sort(a.rbegin(),a.rend());//降順ソート

using namespace::std;

int jo(ll int a, ll int b){//累乗
    ll int num=1;
    rep(i,0,b) num=num*a;
    return num;
}
char tobig(char s){//char大文字化
  return (s-0x20);
}
char tolow(char s){//char小文字化
  return (s+0x20);
}
int ctoi(char a){//char->int
  if('0'<=a&&a<='9') return (a-'0');
  return -1;
}

int gcd(ll int a,ll int b) {//最大公約数
  if(a<b) return gcd(b,a);
  int c;
  while ((c=a%b)) {
    a=b;
    b=c;
  }
  return b;
}
int lcm(ll int a,ll int b){//最小公倍数
 return (a*b)/gcd(a,b);
}


int main(){
  int A,B; cin>>A>>B;
  cout<<A-B+1;

}




// vector<vector<int>> 変数名(左の個数, vector<int>(右の個数));

//cout<<fixed<<setprecision(n);  //小数点n桁まで表示

//  vector<pair<int,int>> data(N);  //2つのデータを格納、.first/.secondで参照
// pairのソートはfirst優先の昇順


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

public class Main {
    public static void main(String[] args) {
        FastScanner fs=new FastScanner();
        char[] s=fs.next().toCharArray();
        char[]t=fs.next().toCharArray();
        int ans=t.length;
        for(int i=0;i<s.length-t.length+1;i++){
            int count =0;
            for(int j=0;j<=t.length-1;j++){
                if(s[j+i]!=t[j]){
                    count++;
                }
            }
            if(count<ans){
                ans=count;
            }
        }
        System.out.println(ans);
    }
    static class FastScanner {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer("");
        String next() {
            while (!st.hasMoreTokens())
                try {
                    st=new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }
        int[] readArray(int n) {
            int[] a=new int[n];
            for (int i=0; i<n; i++) a[i]=nextInt();
            return a;
        }
        long nextLong() {
            return Long.parseLong(next());
        }
    }
}


Measured memory_bytes: 32580
#include <stdio.h>
#include <algorithm>
using namespace std;
int main()
{
	long long n,a,b,c,d;
	scanf("%lld%lld%lld%lld%lld",&n,&a,&b,&c,&d);
	--n;
	if (c==0)
	{
		long long mxlow=a-n*d,mxhigh=a+n*d;
		if (b>=mxlow&&b<=mxhigh)
			printf("YES");
		else
			printf("NO");
		return 0;
	}
	long long tmp1=c*n-b+a,tmp2=d*n-b+a;
	long long tmp3=tmp1/(c+d)-5,tmp4=tmp2/(c+d)+5;
	for (long long i=max(tmp3,0LL);i<=tmp4&&i<=n;++i)
	{
		long long tmp=i*(c+d);
		if (tmp>=tmp1&&tmp<=tmp2)
		{
			printf("YES");
			return 0;
		}
	}
	printf("NO");
	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	int a[100010] ;
	cin >> n;
	for(int i=0;i<n;i++) {
		cin >> a[i] ;
	}
	int flag=1;
	for(int i=1;i<n;i++) {
		if(a[i-1]<a[i]) a[i]-=1;
		if(a[i-1]>a[i]) {
			flag=0;
			break;
		}
	}
	if(flag==1) cout <<"Yes"<<endl;
	else cout <<"No"<<endl;
	return 0;
}

Measured memory_bytes: 640