akhauriyash/Code-Regression huggingface dataset:
/*

                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                    prayer
*/

// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(_,v.size())cout<<" "<<v[_];cout<<endl;
#define show2d(v) rep(__,v.size()){rep(_,v[__].size())cout<<" "<<v[__][_];cout<<endl;}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
// typedef tuple<int,int,int> tp;
// typedef vector<tp> vt;
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;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};


signed main(){
	int n,m;
	cin>>n>>m;
	vi in(n);
	rep(i,n)cin>>in[i];
	sort(all(in));
	int out=inf;
	rep(i,n-m+1)out=min(out,in[i+m-1]-in[i]);
	cout<<out<<endl;
	
}


















Measured memory_bytes: 1024
#include "bits/stdc++.h"

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define ALL(v) v.begin(),v.end()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cout<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct Edge{ll from, to, cost;};
struct node{ll cost, to;
  bool friend operator>(node a, node b){
    return a.cost>b.cost;
  }
};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

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

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}
ll A,B,C,D,E,F;

bool dp[40][4000];
ll v[40][4000];

bool dpf(ll wat, ll sug){
  if(v[wat][sug]){
    return dp[wat][sug];
  }else{
    v[wat][sug]=1;
    if(wat*E<sug){
      dp[wat][sug]=false;
      return dp[wat][sug];
    }else if(wat==0){
      if(sug==0)dp[wat][sug]=true;
      else dp[wat][sug]=false;
      return dp[wat][sug];
    }else{
      dp[wat][sug]=false;
      if(wat-A>=0)dp[wat][sug]= dp[wat][sug] or dpf(wat-A, sug);
      if(wat-B>=0)dp[wat][sug]= dp[wat][sug] or dpf(wat-B, sug);
      if(sug-C>=0)dp[wat][sug]= dp[wat][sug] or dpf(wat, sug-C);
      if(sug-D>=0)dp[wat][sug]= dp[wat][sug] or dpf(wat, sug-D);
      return dp[wat][sug];
    }
  }
}

struct sw{
  ll w, s;
  ld d;
};

/**************************************
 ** A main function starts from here  **
 ***************************************/
int main(){
  cin >> A >> B >> C >> D >> E >> F;
  sw ans;
  ans.w = 0;
  ans.s = 0;
  ans.d=0;
  FOR(i,0, 31){
    FOR(j,0,3001){
      if(dpf(i, j) and i*100+j<=F and i*100+j>=A*100){
        if(i==0 and j==0)continue;
        ld d = j /(ld)(i*100. + j);
        if(d>=ans.d){
          ans.w = i*100;
          ans.s = j;
          ans.d = j /(i*100. + j);
        }
      }
    }
  }
  cout <<(ll)ans.w+ans.s << " " <<(ll) ans.s<<endl;
  return 0;
}


Measured memory_bytes: 1280
use proconio::{input, fastout};

#[fastout]
fn main() {
    let az = [  'a','b','c','d','e',
                'f','g','h','i','j',
                'k','l','m','n','o',
                'p','q','r','s','t',
                'u','v','w','x','y',
                'z'];
    input! {
        mut n: u64,
    }
    let mut name: Vec<u8> = Vec::new();
    while n > 0 {
        n = n - 1;
        name.push((&n % 26)as u8 );
        n /= 26;
    }
    loop {
        match name.pop() {
            None => break,
            Some(e) => {
                let ee = e as usize;
                print!("{}",az[ee]);
            },
        };
    }
    println!("");
}


Measured memory_bytes: 2184
#include <iostream>

using namespace std;

int main()
{   
    int i, pk, cls, rock ,dklm ;
    cin >> pk >> cls >> rock ;
    dklm = 0;
    for ( i = pk; i <= cls; i++) 
    {
        if(rock%i == 0)
        dklm++ ;
    }
    cout << dklm << endl;
}
 


Measured memory_bytes: 3116
class Segtree():

    def __init__(self, n):
        self.num = 1 << (n - 1).bit_length()
        self.tree = [0] * 2 * self.num
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = max(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, k, x):
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = max(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, l, r):
        res = 0
        l, r = l + self.num, r + self.num
        while l < r:
            if l & 1:
                res = max(res, self.tree[l])
                l += 1
            if r & 1:
                res = max(res, self.tree[r - 1])
            l, r = l >> 1, r >> 1
        return res


n, k = map(int, input().split())
a = [int(input()) for _ in range(n)]

# 解説AC
segmax = max(a) + 1
seg_dp = Segtree(segmax)
for ai in a:
    tmp = seg_dp.query(max(ai - k, 0), min(ai + k + 1, segmax))
    seg_dp.update(ai, tmp + 1)
print(max(seg_dp.tree))


Measured memory_bytes: 138868
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <functional>
#include <complex>
#include <stack>
#include <tuple>

#define ll long long int

using namespace std;

const int INF = (1<<30) - 1;

//d, node, velocity, parent
typedef tuple<double, int, int, int> State;

class Edge{
public:
    int to, cost, limit;
    Edge(int to, int cost, int limit): to(to), cost(cost), limit(limit){};
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int N, M;
    while (cin>>N>>M, N|M) {
        int S, G; cin >> S >> G; S--; G--;
       
        vector<vector<Edge>> Glaph(N);
        for(int i=0; i<M; i++){
            int x, y, d, c;
            cin >> x >> y >> d >> c; x--; y--;
            Glaph[x].push_back(Edge(y, d, c));
            Glaph[y].push_back(Edge(x, d, c));
        }
        
        //?????????-1????????????
        //node, velocity, parent
        vector<vector<vector<double>>> dp(N, vector<vector<double>>(30, vector<double>(N, INF)));
        priority_queue<State, vector<State>, greater<State>> que;
        
        dp[S][0][S] = 0;
        que.push(State(0, S, 0, S));
        while (!que.empty()) {
            double d; int node, velocity, parent;
            tie(d, node, velocity, parent) = que.top(); que.pop();
            if(dp[node][velocity][parent] < d)
                continue;
            
            for(Edge &e: Glaph[node]) if(e.to != parent){
                for(int i=-1; i<=1; i++){
                    int nv = velocity + i;
                    if(node == S && parent == S && nv != 0)
                        continue;
                    if(nv < 0 || 30 <= nv || e.limit <= nv)
                        continue;
                    if(dp[e.to][nv][node] > d + e.cost / double(nv+1)){
                        dp[e.to][nv][node] = d + e.cost / double(nv+1);
                        que.push(State(dp[e.to][nv][node], e.to, nv, node));
                    }
                }
            }
        }
        double ans = INF;
        int p = -1;
        for(int i=0; i<N; i++){
            if(dp[G][0][i] < ans){
                ans = dp[G][0][i];
                p = i;
            }
        }
        if(ans == INF)
            cout << "unreachable" << endl;
        else
            cout << ans << endl;
    }
    
    return 0;
}

Measured memory_bytes: 2140
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int MOD = 998244353;
const int N = 20001;
ll fact[N];
ll inv[N];
ll pow1(ll n, int p){
  ll cur = n, res = 1;

  while(p){
    if(p & 1)
      (res *= cur) %= MOD;
    p /= 2;
    (cur *= cur) %= MOD;
  }
  return res;
}
void init(){
  fact[0] = inv[0] = 1;
  for(int i = 1;i < N;i++){
    fact[i] = fact[i - 1] * i % MOD;
    inv[i] = pow1(fact[i], MOD - 2);
  }
}
ll C(int n, int k){
  if(k > n)return 0;
  return fact[n] * inv[k] % MOD * inv[n - k] % MOD;
}
ll stars(int n, int k){
  return C(n + k - 1 ,n);
}
ll solve(int n, int k, int ter){
  if(ter % 2 == 1){
    int s = ter / 2;
    s = min(s, k - s);
    ll res = 0;
    for(int i = 0;i <= min(n, s);i++){
      res += pow1(2, i) * stars(n - i, k - 2 * s + i) % MOD * C(s, i) % MOD;
//      cout << stars(n, k - ter + 1 + i) << endl;
      res %= MOD;
    }
    return res;
  }else{
    ll res = 0;
    int s = ter / 2 - 1;
    s = min(s, k - s - 1);
    for(int i = 0;i <= min(n, s);i++){
      res += pow1(2, i) * stars(n - i, k - 2 * s - 1 + i) % MOD * C(s, i) % MOD;
      res %= MOD;
      res += pow1(2, i) * stars(n - 1 - i, k - 2 * s - 1 + i) % MOD * C(s, i) % MOD;
      res %= MOD;
    }
    return res;
  }
}
void solve1(int k, int n){
  for(int i = 2;i <= 2 * k;i++){
    cout << solve(n, k, i) << endl;
  }

}
int main() {
//  freopen("in.txt", "r", stdin);
//  freopen("out.txt", "w", stdout);
  int n, k;
  cin >> k >> n;
  init();
  solve1(k, n);
}



Measured memory_bytes: 640
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <stack>
#include <queue>

using namespace std;
#define Fill(a, b) memset(a, b, sizeof(a))
#define Debug(x) cout << #x << "=" << (x) << endl;
typedef long long LL;
const LL inf = 1LL << 61;
const LL mod = 1000000007;
#define DEBUG
#ifdef DEBUG
#endif

int main()
{
    std::ios::sync_with_stdio(false);
    char maze[55][55];
    char mazei[55][55];
    int h, w;
    scanf("%d%d", &h, &w);
    getchar();
    for(int i = 1; i <= h; i++)
    {
    	for(int j = 1; j <= w; j++)
    	{
    		maze[i][j] = getchar();
    	}
    	getchar();
    }
    for(int i = 1; i <= h; i++)
    {
    	for(int j = 1; j <= w; j++)
    	{
    		char ch = maze[i][j];
    		if(ch == '#')mazei[i][j] = ch;
    		else
    		{
    			int sum = 0;
    			for(int s = i-1; s <= i+1; s++)
    			{
    				for(int t = j-1; t <= j+1; t++)
    				{
    					if(maze[s][t]=='#')sum++;
    				}
    			}
    			mazei[i][j] = sum+'0';
    		}
    	}
    }
    for(int i = 1; i <= h; i++)
    {
    	for(int j = 1; j <= w; j++)
    	{
    		printf("%c", mazei[i][j]);
    	}
    	puts("");
    }






















    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#define INF 1000000000
#define mod 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define all(x) (x).begin(),x.end()
using namespace std;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;

int main(){
  int h,w;
  string s[100];
  cin>>h>>w;
  rep(i,h)cin>>s[i];
  for(int i=0;i<=h+1;i++){
    if(i==0||i==h+1){
      rep(j,w+2)cout<<'#';
      cout<<endl;
    } else{
      cout<<'#'<<s[i-1]<<'#'<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 256
from collections import Counter

H, W, N, *AB = map(int, open(0).read().split())

C = Counter()
for a, b in zip(*[iter(AB)] * 2):
    C.update(
        (a - i, b - j)
        for i in range(-1, 2) for j in range(-1, 2)
        if 2 <= a - i <= H - 1 and 2 <= b - j <= W - 1
    )

D = Counter(v for _, v in C.items())

print((H - 2) * (W - 2) - sum(D.values()))
for i in range(1, 10):
    print(D[i])


Measured memory_bytes: 178260
N, K = map(int, input().split())
S = list(input())

ttl = []
prev = S[0] # 0
cnt = 1
if S[0] == '0':
    ttl.append(0)
for i in range(1, N):
    if S[i] == prev:
        cnt += 1
    else:
        ttl.append(cnt)
        cnt = 1
    prev = S[i]
if cnt != 0:
    ttl.append(cnt)
if S[-1] == '0':
    ttl.append(0)
l = len(ttl)
sums = [0] * (l + 1)
for i in range(l):
    sums[i+1] = sums[i] + ttl[i]

cnt_width = 2 * K + 1
ans = 0
chk_l = len(sums)
for left in range(0, chk_l, 2):
    right = left + cnt_width
    if right >= chk_l:
        right = chk_l - 1
    ans = max(ans, sums[right] - sums[left])
    if left >= chk_l - 1 - cnt_width:
        break
print(ans)

Measured memory_bytes: 8568
#include <iostream>
#include <vector>

using namespace std;

int binary_search(vector<int>& v, int key) {
    int left = 0;
    int right = v.size() - 1;

    while (left <= right) {
        int mid = (left + right) / 2;
        if (v[mid] == key)
            return mid;
        else if (v[mid] < key)
            left = mid + 1;
        else
            right = mid - 1;
    }
    return -1;
}

int main() {
    int n;
    cin >> n;
    vector<int> s(n);
    for (int i = 0; i < n; ++i)
        cin >> s[i];

    int q;
    cin >> q;
    vector<int> t(q);
    for (int i = 0; i < q; ++i)
        cin >> t[i];

    int count = 0;
    for (int i = 0; i < q; ++i) {
        if (binary_search(s, t[i]) != -1)
            ++count;
    }
    cout << count << '\n';
}



Measured memory_bytes: 3352
package main

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

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func main() {
	N := readInt()
	M := readInt()
	A := make([]int, N)
	for i := 0; i < N; i++ {
		A[i] = readInt()
	}

	sort.Sort(sort.Reverse(sort.IntSlice(A)))
	U := A[0] * 2
	L := A[N-1] * 2

	// cgs[i] は パワーがi以上のゲストの数
	cgs := make([]int, U+1)
	for _, a := range A {
		cgs[a]++
	}
	for i := U; i > 0; i-- {
		cgs[i-1] += cgs[i]
	}

	isOk := func(n int) bool {
		m := 0
		for _, a := range A {
			m += cgs[max(n-a, 0)]
		}
		return m >= M
	}

	ok := L
	ng := U + 1
	for ng-ok != 1 {
		m := ok + (ng-ok)/2
		if isOk(m) {
			ok = m
		} else {
			ng = m
		}
	}

	// cps[i] は A[0]～A[i] の累積和
	cps := make([]int, N)
	cps[0] = A[0]
	for i := 1; i < N; i++ {
		cps[i] = A[i] + cps[i-1]
	}

	result := 0
	for _, a := range A {
		guests := cgs[max(ok-a, 0)]
		if guests != 0 {
			result += a*guests + cps[guests-1]
			M -= guests
		}
	}
	result += ok * M
	fmt.Println(result)
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}


Measured memory_bytes: 5376
#include<iostream>
#include<string>
//#include<array>
#include<algorithm>
//#include<deque>
#include<vector>
//#include<utility>
//#include<set>
//#include<map>
//#include<list>

int main(void) {
	using namespace std;
	int x, y, z;
	cin >> x >> y >> z;
	x -= z;
	int res = x / (y + z);
	cout << res << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
priority_queue<int>p;
int main(){
 	int n,m;
 	cin>>n>>m;
 	while(n--)
 	{
 		ll d;
 		cin>>d;
 		p.push(d);
	 }
	 while(m--)
	 {
	 	if(p.top()==0){
	 		cout<<0;
	 		return 0;
		 }
		 ll d=p.top()/2;
		 p.pop();
		 p.push(d);
	 }
	 ll ans=0;
	 while(!p.empty())
	 {
	 	ll i=p.top();
	 	p.pop();
	 	if(i==0){
	 		cout<<ans;
	 		return 0;
		 }
		 ans+=i;
	 }
	 cout<<ans;
}

Measured memory_bytes: 892
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
long long int dp[100000][30] = {0};
using namespace std;
int main(){
    int n;
    scanf("%d",&n);

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

    memset(dp,0,sizeof(dp));

    dp[0][a[0]] = 1;
    int v = 0;
    for(int i = 1;i < n-1; i++){
        for(int j = 0;j <= 20; j++){
            if(dp[i-1][j] > 0){
                v = j + a[i];
                if(v <= 20){
                    dp[i][v] += dp[i-1][j];
                }
                v = j-a[i];
                if(v >= 0){
                    dp[i][v] += dp[i-1][j];
                }
            }
        }
    }
    printf("%lld\n",dp[n-2][a[n-1]]);
    return 0;
}

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

int main() {

	string s;
	cin >> s;
	int cnt = 0;
	
	if (s[0] == '1')++cnt;
	if (s[1] == '1')++cnt;
	if (s[2] == '1')++cnt;
	   
	cout << cnt << endl;
}


Measured memory_bytes: 256
import sys
import bisect

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N, M, K = [int(x) for x in input().split()]
    A = [int(x) for x in input().split()]
    B = [int(x) for x in input().split()]

    ruisekia = [0] * N
    ruisekib = [0] * M

    for i, a in enumerate(A):
        ruisekia[i] = ruisekia[i - 1] + a

    for i, b in enumerate(B):
        ruisekib[i] = ruisekib[i - 1] + b

    ruisekia = [0] + ruisekia
    ruisekib = [0] + ruisekib


    ans = 0
    for i in range(N + 1):
        nokori = K - ruisekia[i]
        if nokori == 0:
            ans = max(ans, i)
            continue
        elif nokori <= 0:
            continue

        x = bisect.bisect_right(ruisekib, nokori)
        ans = max(ans, x + i - 1)

    print(ans)





if __name__ == '__main__':
    main()



Measured memory_bytes: 48976
import sys
import math
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

n = ni()
s = ns()

for si in s:
    num = ((ord(si) - ord("A") + n) %26) + ord("A")
    print(chr(num), end="")

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

int main()
{
    int A, B;
    cin >> A >> B;
    if(A == 1) { A = 14; }
    if(B == 1) { B = 14; }
    if(A == B) {
        cout << "Draw" << endl;
    } else if(A > B) {
        cout << "Alice" << endl;
    } else {
        cout << "Bob" << endl;
    }
    return 0;
}

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

struct mint {
  ll x;
  mint(ll x = 0): x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; }
  mint& operator-=(const mint a) { if ((x += mod - a.x) >= mod) x -= mod; return *this; }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

struct cominit {
  vector<mint> fact, ifact;
  cominit(int n): fact(n + 1), ifact(n + 1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; i++) fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; i--) ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int r) {
    if (n < r or r < 0) return 0;
    return fact[n] * ifact[r] * ifact[n - r];
  }
};


int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int &i : a) cin >> i;
  mint ans = 1;
  if (n == k) {
    for (int i = 0; i < n; i++) ans *= a[i];
    cout << ans << endl;
    return 0;
  }
  vector<int> s, t;
  for (int i = 0; i < n; i++) {
    if (a[i] > 0) s.push_back(a[i]);
    else t.push_back(a[i]);
  }
  if (s.size() == 0 && k % 2 == 1) {
    sort(a.rbegin(), a.rend());
    for (int i = 0; i < k; i++) ans *= a[i];
    cout << ans << endl;
    return 0;
  }
  sort(s.begin(), s.end());
  sort(t.rbegin(), t.rend());
  if (k % 2 == 1) {
    ans *= s.back();
    s.pop_back();
    k--;
  }
  vector<ll> mul;
  while (s.size() >= 2) {
    ll x = s.back();
    s.pop_back();
    x *= s.back();
    s.pop_back();
    mul.push_back(x);
  }
  while (t.size() >= 2) {
    ll x = t.back();
    t.pop_back();
    x *= t.back();
    t.pop_back();
    mul.push_back(x);
  }
  sort(mul.rbegin(), mul.rend());
  for (int i = 0; i < k / 2; i++) ans *= mul[i];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6316
#include <bits/stdc++.h>
using namespace std;
constexpr int md = 1e9 + 7;
inline void mad (int &a, int b) {
  a += b; if (a >= md) a -= md;
}
inline void msb (int &a, int b) {
  a -= b; if (a < 0) a += md;
}
inline int vad (int a, int b) {
  mad(a, b); return a;
}
inline int vsb (int a, int b) {
  msb(a, b); return a;
}
inline int mul (int a, int b) {
  return (int)((long long)a * b % md);
}
inline int mow (int a, long long b) {
  int res = 1;
  for (; b; b >>= 1) {
    if (b & 1) res = mul(res, a);
    a = mul(a, a);
  }
  return res;
}
inline int inv (int a) {
  a %= md;
  if(a < 0) a += md;
  int b = md, u = 0, v = 1;
  while (a) {
    int t = b / a;
    b -= a * t; swap(a, b);
    u -= v * t; swap(u, v);
  }
  assert(b == 1);
  if(u < 0) u += md;
  return u;
}
int main() {
  cin.tie(0); cin.sync_with_stdio(false);
  int n, q;
  cin >> n >> q;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  vector<vector<int>> dp(n, vector<int>(n));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      dp[i][j] = a[i] > a[j] ? 1 : 0;
    }
  }
  int inv2 = inv(2);
  int coeff = mow(2, q);
  while (q--) {
    int x, y;
    cin >> x >> y;
    x--; y--;
    auto half = [&] (int& a, int& b) -> void {
      mad(a, b);
      a = b = mul(a, inv2);
    };
    half(dp[x][y], dp[y][x]);
    for (int z = 0; z < n; z++) if (z != x && z != y) {
      half(dp[x][z], dp[y][z]);
      half(dp[z][x], dp[z][y]);
    }
  }
  int ret = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      dp[i][j] = mul(dp[i][j], coeff);
      mad(ret, dp[i][j]);
    }
  }
  cout << ret << endl;
  return 0;
}

Measured memory_bytes: 35584
#include <bits/stdc++.h>
using namespace std;
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(false), cout << fixed << setprecision(20);
#define int long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(...) _overload(__VA_ARGS__, repi, _rep)(__VA_ARGS__)
#define _rev(i, n) revi(i, n, 0)
#define revi(i, a, b) for(int i = (int)(a - 1); i >= (int)(b); i--)
#define rev(...) _overload(__VA_ARGS__, revi, _rev)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
void in(){}
template<typename F, typename... R>
bool in(F& f, R&... r){
    if(cin >> f){in(r...);return true;}
    else return false;
}
#define out(x) cout << (x)
#define space() cout << " "
#define indent() cout << '\n'
void print(){}
template<typename F, typename... R>
void print(F f, R... r){out(f), indent(), print(r...);}
#define debughead(x) cerr << "Line " << __LINE__ << ": " << #x << ": "
#define debugout(x) cerr << (x) << " "
#define debugindent() cerr << '\n'
#define debug(x) debughead(x), debugout(x), debugindent()
const int INF = 1e18, MOD = 1e9 + 7;
template<typename T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<typename T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}

main(){
    INCANT;
    int n, m, q, l, r, tmp, res = 0;
    string s;
    in(n, m, q);
    int p[n + 1][n + 1] = {};
    rep(i, m){
        in(l, r);
        p[l][r]++;
    }
    rep(i, 1, n + 1){
        rep(j, 1, n + 1){
            p[i][j] += p[i - 1][j];
        }
    }
    rep(i, 1, n + 1){
        rep(j, 1, n + 1){
            p[i][j] += p[i][j - 1];
        }
    }
    rep(i, q){
        in(l, r);
        print(p[r][r] + p[l - 1][l - 1] - p[l - 1][r] - p[r][l - 1]);
    }
}


Measured memory_bytes: 2944
#include <iostream>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>

using namespace std;

int main(){
    int n, k, q; cin >> n >> k >> q;
    vector<int> ps(n);
    for(int i=0; i<q; ++i){
        int a; cin >> a;
        --a;
        ++ps[a];
    }
    for(int i=0; i<n; ++i){
        cout << (k-(q-ps[i])>0 ? "Yes" : "No") << endl;
    }
    return 0;
}


Measured memory_bytes: 1024
# coding: UTF-8
alfa_list = [chr(i) for i in range(97, 97+26)]
lines = []
count = 0
while(1):
    try:
        lines.append(str(raw_input()).lower())
    except:
        break
for ch in alfa_list:
    print "{0} : {1}".format(alfa_list[count],str(lines).count(ch))
    count += 1



Measured memory_bytes: 4644
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <utility>
#include <cstdlib>
#include <memory>
#include <queue>
#include <cassert>
#include <cmath>
#include <ctime>
#include <complex>
#include <bitset>
#include <fstream>
#include <unordered_map>
#include <unordered_set>
#include <numeric>

using namespace std;

#define ws ws_____________________
#define y1 y1_____________________
#define y0 y0_____________________
#define left left_________________
#define right right_______________
#define next next_________________
#define prev prev_________________
#define hash hash_________________

#define pb push_back
#define fst first
#define snd second
#define mp make_pair 
#define sz(C) ((int) (C).size())
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define ford(i, n) for (int i = int(n) - 1; i >= 0; --i)
#define all(C) begin(C), end(C)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef long double ld;
typedef complex<double> cd;

#define FILE_NAME "a"


int n, k;
vi a;

bool read() {
	if  (scanf("%d%d", &n, &k) < 2) {
		return 0;
	}
	a.resize(n);
	forn(i, n) {
		scanf("%d", &a[i]);
	}
	return 1;
}

struct FenwTree {
	vi t;

	FenwTree(int n = 0) {
		t.assign(n, 0);
	}

	int get(int r) {
		int ans = 0;
		for (int i = r; i >= 0; i &= i + 1, --i) {
			ans += t[i];
		}
		return ans;
	}

	void inc(int pos, int val) {
		for (int i = pos; i < sz(t); i |= i + 1) {
			t[i] += val;
		}
	}
};

vll pref;
vll c;
FenwTree T;

int get_pos(ll sum) {
	int pos = lower_bound(all(c), sum) - c.begin();
	assert(pos < sz(c) && c[pos] == sum);
	return pos;
}

ll solve() {
	pref.resize(n + 1, 0);
	forn(i, n) {
		pref[i + 1] = pref[i] + (a[i] - k);
	}
	T = FenwTree(n + 1);

	c = pref;
	sort(all(c));
	c.resize(unique(all(c)) - c.begin());

	T.inc(get_pos(pref[0]), +1);

	ll ans = 0;
	forn(i, n) {	
		int pos = get_pos(pref[i + 1]);
		ans += T.get(pos);
		T.inc(pos, +1);
	}

	return ans;
}

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

	while (read()) {
		cout << solve() << endl;
	}

#ifdef LOCAL
	cerr.precision(5);
	cerr << "Time: " << fixed << (double) clock() / CLOCKS_PER_SEC << endl;
#endif
	return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

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

	ll ans = 0LL;
	for(int i = 0; i < n; ++i) {
		ll a;
		cin >> a;
		ans += a - 1LL;
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int n,a;
    cin>>n;
    a=n%10;
    if(a==3)
        cout<<"bon"<<endl;
    else if(a==0 || a==1 || a==6 || a==8)
        cout<<"pon"<<endl;
    else
        cout<<"hon"<<endl;
    return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
int main(){
      string s,t;
      cin>>s>>t;
      int count = 0;
      if(s[0]==t[0])count++;
      if(s[1]==t[1])count++;
      if(s[2]==t[2])count++;  
        cout << count << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main()
{
  int N;
  int max=0;
  cin >> N;
  vector<int> a(N);
  for(int i=0; i<N; ++i)
  {
    cin >> a[i];
    if(a[i] > max) max = a[i];
  }
  int ans = 0;
  for(int i=0; i<N; ++i)
  {
    ans += a[i]-1;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
vector<long> v[100009];
bool visited[100009];
long dist[100009];
long indeg[100009];

void dfs(long a){
    visited[a]=true;
    for(auto b:v[a]){
        dist[b]=max(dist[b],dist[a]+1);
        indeg[b]--;
        if(indeg[b]==0){
            dfs(b);
        }
    }
}

int main(){
    long n,m;cin>>n>>m;
    long a,b;
    for(int i=0;i<m;i++){
        cin>>a>>b;
        v[a].push_back(b);
        indeg[b]++;
    }
    for(int i=1;i<=n;i++){
        if(visited[i]==false && indeg[i]==0){
            dfs(i);
        }
    }
    long ans=0;
    for(int i=1;i<=n;i++){
        ans=max(ans,dist[i]);
    }
    cout<<ans;



}


Measured memory_bytes: 10496
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define d(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define MAX 100000
LL N,t,x,y,prex=0,prey=0,d;

int main(void){
    cin>>N;
    REP(i,N){
        cin>>t>>x>>y;
        d=t-(abs(prex-x)+abs(prey-y));
        if((d>=0)&&(d % 2 == 0)) continue;
        cout<<"No"<<endl;
        return 0;
    }
    cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
typedef long long int ll;
int N;
vector<int>X;
int main()
{
	scanf("%d",&N);
	int M=N;
	for(int i=2;i*i<=M;i++){
		while(true){
		
		if(N%i==0){
			
			X.push_back(i);
			N/=i;
		}
		else break;
		}
	}
	if(N!=1)X.push_back(N);
	printf("%d:",M);
	for(int i=0;i<X.size();i++){
		printf(" %d",X[i]);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 1212
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstring>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

int main()
{
    int z;
    while(cin >> z && z)
    {
        int xy_3 = 0;
        REP(z)rep(j,z)if( z * z * z -(i * i * i + j * j *j) >= 0) xy_3 = max(xy_3, (i * i * i + j * j *j));

        cout << z * z * z - xy_3 << endl;
    }

    return 0;
}

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

using namespace std;

int main()
{
	int N;
	cin >> N;

	int n = N % 1000;

	if (n != 0) {
		cout << 1000 - n << endl;
	}
	else {
		cout << 0 << endl;
	}

}





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

int main(){
    int A, B, M;
    cin >> A >> B >> M;
    vector<int> a(A), b(B);
    int x[M], y[M], c[M];
    for(int i = 0; i < A; i++){
        cin >> a.at(i);
    }
    for(int i = 0; i < B; i++){
        cin >> b.at(i);
    }
    for(int i = 0; i < M; i++){
        cin >> x[i] >> y[i] >> c[i];
    }

    int ans = 200000;

   for(int i = 0; i < M; i++){
        if(ans > a.at(x[i] - 1) + b.at(y[i] - 1) - c[i])ans = a.at(x[i] - 1) + b.at(y[i] - 1) - c[i];
    }

    sort(a.begin(), a.end());
    sort(b.begin(), b.end());

    if(ans > a.at(0) + b.at(0))ans = a.at(0) + b.at(0);

    cout << ans << endl;
}

Measured memory_bytes: 2176
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1012345678;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

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

int main(){
  int N, K;
  cin >> N >> K;
  string s;
  cin >> s;
  int ans = 0;
  int x = 0;
  if(s[0] == s[N-1]){
    rep(i,N-1){
      if(s[i] == s[0] && s[i+1] != s[0] && x < K){
	x++;
      }
      if(s[i] == s[i+1]) ans++;
    }
    if(K > x) ans = ans + (x*2 + 1);
    else ans = ans + x*2;
  }
  
  else{
    rep(i,N-1){
      if(s[i] == s[0] && s[i+1] != s[0] && x < K){
	x++;
      }
      if(s[i] == s[i+1]) ans++;
    }
    ans = ans + (x*2);
  }
  if(ans == N) cout << ans -1 << endl;
  else cout << ans << endl;
  //cout << x << endl;
}




Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define db double
#define ld long double
#define pii pair<int,int>
#define vvi vector<vector<int> >
#define vpi vector<pii>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define INF 0x7fffffff
#define LINF 0x7fffffffffffffff
#define MOD 1000000007
#define mod 998244353
#define lowbit(x) x&(-x)
#define HS 173LL
using namespace std;
int read()
{
	int x=0;
	char ch=getchar();
	while(!isdigit(ch))
		ch=getchar();
	while(isdigit(ch))
	{
		x=x*10+ch-'0';
		ch=getchar();
	}
	return x;
}
int main()
{
	int D=read(),T=read(),S=read();
	if(T*S>=D)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl; 
	return 0;
}

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

// 組合せを素数で割った値を求める
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for(int i = 2; i < MAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n, m;
  cin >> n >> m;
  
  int m2 = m;
  vector<int> x(50009, 0);
  for(int i = 2; i * i <= m; i++){
    if(m2 % i == 0){
      x.at(i)++;
      m2 /= i;
      i--;
    }
  }
  
  COMinit();
  
  long long ans = 1;
  if(m2 >= 2) ans *= n;
  
  for(int i = 0; i < x.size(); i++){
    ans *= COM(x.at(i) + n - 1, x.at(i));
    ans %= MOD;
  }
  
  cout << ans << '\n';
}

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

int main() {
  int N;
  cin >> N;
  int a = N % 10;
  
  if(a == 2 || a == 4 || a == 5 || a == 7 || a == 9){
    cout << "hon" << endl;
  }
  else if(a == 0 || a == 1 || a == 6 || a == 8){
    cout << "pon" << endl;
  }
  else if(a == 3){
    cout << "bon" << endl;
  }
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
//typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define UNIQUE(c) sort(ALL(c)), c.erase(unique(ALL(c)), c.end())

const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};
const int INF = 1e8;

int dfs(int v, vector<vector<int>>& edges, vector<int>& dp, vector<bool>& used) {
  if (dp[v] > 0) {
    return dp[v];
  }
  if (used[v]) {
    return INF;
  }
  used[v] = true;
  int ret = 0;
  for (int c : edges[v]) {
    ret = max(ret, dfs(c, edges, dp, used));
  }
  return dp[v] = ret + 1;
}

int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N; cin >> N;
  map<pair<int, int>, int> mp;
  int cnt = 0;
  REP(i, N) REP(j, N) {
    if (i < j) {
      mp[make_pair(i, j)] = mp[make_pair(j, i)] = cnt;
      //cout << '(' << i << ',' << j << ")=" << cnt << endl;
      cnt++;
    }
  }

  vector<vector<int>> edges(cnt);
  REP(i, N) {
    vector<int> A(N-1); REP(j, N-1) cin >> A[j], A[j]--;
    REP(j, N-2) {
      int from = mp[make_pair(i, A[j])], to = mp[make_pair(i, A[j+1])];
      //cout << from << "->" << to << endl;
      edges[from].push_back(to);
    }
  }
  vector<int> dp(cnt, 0);
  vector<bool> used(cnt, false);
  int ans = 0;
  REP(i, cnt) {
    ans = max(ans, dfs(i, edges, dp, used));
  }
  cout << (ans >= INF ? -1 : ans) << endl;
  return 0;
}


Measured memory_bytes: 92328
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string S, Ans;
  cin >> S;
  int N = S.size();
  for (int i = 0; i < N; i++){
    if (S[i] == 'B'){
      if (i != 0){
        for (int j = i; j >= 0; j--){
          if (S[j] != 'B' && S[j] != '?'){
            S[j] = '?';       
            break; 
          }
        }
      }
    }
  }
  for (int i = 0; i < N; i++)
    if (S[i] != '?' && S[i] != 'B')
      Ans += S[i];
  cout << Ans << endl;
  return 0;
}

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

#define REP(i ,n) for(int i=0 ;i < n; i++)
#define REPB(i ,n) for(int i=n; i >= 0; i--)
#define FOR(i ,m ,n) for(int i=m; i < n; i++)
#define FORB(i, m, n) for(int i=m; i>= n; i--)
#define ll long long
#define pb push_back
#define popb pop_back
#define debug(i) cout << i << endl
using namespace std;
int main(){
    int n, k, q;
    cin >> n >> k >> q;
    int norma = q - k + 1;
    int pt[n] = {};


    REP(i,q){
        int a;
        cin >> a;
        pt[a-1]++;
    }
    REP(i,n){
        if(pt[i] >= norma) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    //REP(i,n) cout << pt[i] << endl;
}

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

int main(){
    vector<vector<int>> grid(3,vector<int>(3));
    for(int i=0;i <3; i++){
        for(int j=0; j<3; j++){
            cin >> grid[i][j];
        }
    }
    bool info = true;
    int b2sub=grid[0][1] - grid[0][0];
    int b3sub=grid[0][2] - grid[0][1];
    int a2sub=grid[1][0] - grid[0][0];
    int a3sub=grid[2][0] - grid[1][0];
    for(int i=1; i<3; i++){
        if(grid[i][1]-grid[i][0]-b2sub != 0){
            info = false;
        }
        if(grid[i][2]-grid[i][1]-b3sub != 0){
            info = false;
        }
        if(grid[1][i]-grid[0][i]-a2sub != 0){
            info = false;
        }
        if(grid[2][i]-grid[1][i]-a3sub != 0){
            info = false;
        }
    }

    if(info){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

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

int main() {
	int n;
	cin >> n;
	int count = 0;
	int count_temp = 0;

	for(int i=1; i<n+1; i++) {
		for(int j=1; j<i+1; j++) {
			if(i%j == 0)
				count_temp++;
		}
		if(i%2 == 1 && count_temp == 8)
			count++;
		count_temp=0;
	}
	cout << count << endl;
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define   sz(s)         s.size()
#define   ll            long long int
#define   ull           unsigned ll
#define   ld            long double
#define   print(v)      for(ll i=0;i<v.size();i++)cout<<v[i]<<" "
#define   printpair(v)  for(ll i=0;i<v.size();i++)cout<<v[i].first<<" "<<v[i].second<<"\n"
#define   bmd           1000000007
#define   bmd1          998244353
#define   umll          unordered_map<ll,ll>
#define   mll           map<ll,ll>
#define   mcl           map<char,ll>
#define   pll           pair<ll,ll>
#define   F             first
#define   S             second
#define   setp(x)       setprecision(x)
#define   pb            push_back
#define   all(v)        v.begin(),v.end()
#define   tr(a)         for(auto it=a.begin();it!=a.end();it++)
#define   trr(a)        for(auto it1=a.begin();it1!=a.end();it1++)
#define   vll           vector<long long int>
#define   sorty(v)      sort(v.begin(),v.end())
#define   rsort(v)      sort(v.rbegin(),v.rend())
#define   PI            3.1415926535897932384626
#define   db()          cout<<"\n"<<"here"<<"\n"
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;


//---------------------------------------------------------------------------
const int MOD = bmd;
const int N=2e5+100;
inline  ll sqr(ll x){return x*x;}
inline  void normal(ll &a) { a = (a+MOD)%MOD; }
inline  ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline  ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline  ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline  ll modPow(ll b, ll p) { ll r = 1;b=b%MOD; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline  ll modInv(ll a) { return modPow(a, MOD-2); }
inline  ll modDiv(ll a,ll b) { return modMul(a, modInv(b)); }
//---------------------------------------------------------------------------

void solve()
{
    ll n,wt;
    cin>>n>>wt;
    ll w[n+1],v[n+1];
    for(ll i=1;i<=n;i++){
        cin>>w[i]>>v[i];
    }
    ll dp[n+2][wt+2];
    memset(dp,0,sizeof(dp));
    for(ll i=1;i<=n;i++)
    {
        ll x=w[i];
        for(ll j=1;j<=wt;j++)
        {
            if(j-w[i]>=0){
                dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
            }
            else dp[i][j]=dp[i-1][j];
        }
    }
    cout << dp[n][wt] <<"\n";
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);//first give all input then gives output
    ll t=1;
    //cin>>t;
    while(t--){
        solve();
    }

    return 0;
}


Measured memory_bytes: 80000
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a, b;
  char op;
  while (true) {
    cin >> a >> op >> b;
    switch (op) {
      case '+':
        cout << (a + b) << endl;
        break;
      case '-':
        cout << (a - b) << endl;
        break;
      case '*':
        cout << (a * b) << endl;
        break;
      case '/':
        cout << (a / b) << endl;
        break;
      case '?':
        return 0;
    }
  }
}



Measured memory_bytes: 3092
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

int main(int argc, char const *argv[]) {
    int n;cin>>n;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    vector<ll> dp(n+10,LINF);

    rep(i,n) *lower_bound(dp.begin(), dp.end(), a[i]) = a[i];

    int ans = (int)(lower_bound(dp.begin(), dp.end(), LINF)-dp.begin());

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


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

using namespace std;

void run (long long & res, vector <long long> & a, long long i, int k) {
    if (i < 0)
        return;

    long long cnt = 0;
    for (; i >= 0; i--) {
        vector <long long> cur;
        for (int j = 0; j < a.size(); j++) {
            if ((a[j] >> i) & 1)
                cur.push_back(a[j]);
        }
        if (cur.size() >= k) {
            res += ((long long)1 << i);
            run(res, cur, i - 1, k);
            break;
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    long long n, k;
    cin >> n >> k;
    vector <long long> a(n), b;
    for (int j = 0; j < n; j++) {
        cin >> a[j];
    }
    for (int j = 0; j < n; j++) {
        long long s = 0;
        for (int i = j; i < n; i++) {
            s += a[i];
            b.push_back(s);
        }
    }
    long long res = 0;
    run(res, b, 40, k);
    cout << res;
}


Measured memory_bytes: 6512
#include <bits/stdc++.h>
#define REP(i, n) for(long long 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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;



int main() {
    string s;
    cin >> s;
    int ans = 1;
    REP(i,(s.size()/2 - 1)) {
        if (s[i] != s[s.size()-1-i]) {
            ans = 0;
        }
    }
    REP(i, (s.size()/4)) {
        if(s[i] != s[(s.size()/2) -  1 - i]) {
            ans = 0;
        }
        if(s[s.size() - i - 1] != s[s.size()/2 + 1 + i]) {
            ans = 0;
        }
    }
    if (ans == 1) {
        cout << "Yes";
    }else {
        cout << "No";
    }
}

Measured memory_bytes: 256