akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
int main(void) {
  int x, y;
  cin >> x >> y;
  if (y % 2 == 0 && y >= 2 * x && y <= 4 * x) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3636
# frozen_string_literal: true

# induce sort (internal routine)
def sa_is_induce(s, ls, sum_l, sum_s, lms)
  n = s.size
  sa = [-1]*n

  buf = sum_s.dup
  lms.each{ |lms|
    if lms != n then
      sa[buf[s[lms]]] = lms
      buf[s[lms]] += 1
    end
  }

  buf = sum_l.dup
  sa[buf[s[-1]]] = n-1
  buf[s[-1]] += 1
  sa.each{ |v|
    if v>=1 && !ls[v-1] then
      sa[buf[s[v-1]]] = v-1
      buf[s[v-1]] += 1
    end
  }

  buf = sum_l.dup
  sa.reverse_each{ |v|
    if v>=1 && ls[v-1] then
      buf[s[v-1]+1] -= 1
      sa[buf[s[v-1]+1]] = v-1
    end
  }

  return sa
end

# SA-IS (internal routine)
def sa_is(s, upper)
  n = s.size

  return [] if n == 0
  return [0] if n == 1

  ls = [false]*n
  (n-2).downto(0){ |i|
    ls[i] = s[i]==s[i+1] ? ls[i+1] : s[i]<s[i+1]
  }

  sum_l = [0]*(upper+1)
  sum_s = [0]*(upper+1)
  n.times{ |i|
    if ls[i] then
      sum_l[s[i]+1] += 1
    else
      sum_s[s[i]] += 1
    end
  }
  0.upto(upper){ |i|
    sum_s[i] += sum_l[i]
    sum_l[i+1] += sum_s[i] if i<upper
  }

  lms = (1 ... n).select{ |i| !ls[i-1] && ls[i] }
  m=lms.size
  lms_map = [-1]*(n+1)
  lms.each_with_index{ |lms, id| lms_map[lms] = id }

  sa = sa_is_induce(s, ls, sum_l, sum_s, lms)

  return sa if m == 0

  sorted_lms = sa.select{ |sa| lms_map[sa] != -1 }
  rec_s = [0]*m
  rec_upper = 0
  rec_s[lms_map[sorted_lms[0]]] = 0
  1.upto(m-1){ |i|
    l, r = sorted_lms[i-1, 2]
    end_l = lms[lms_map[l]+1]||n
    end_r = lms[lms_map[r]+1]||n
    same = true
    if end_l-l != end_r-r then
      same = false
    else
      while l < end_l do
        break if s[l] != s[r]
        l+=1
        r+=1
      end
      same = false if l==n || s[l]!=s[r]
    end
    rec_upper += 1 if not same
    rec_s[lms_map[sorted_lms[i]]] = rec_upper
  }

  sa_is(rec_s, rec_upper).each_with_index{ |rec_sa, id|
    sorted_lms[id] = lms[rec_sa]
  }

  return sa_is_induce(s, ls, sum_l, sum_s, sorted_lms)
end

# suffix array for array of integers or string
def suffix_array(s, upper = nil)
  if not upper then
    case s
    when Array
      # compression
      n = s.size
      idx = (0 ... n).sort_by{ |i| s[i] }
      t = [0]*n
      upper = 0
      t[idx[0]] = 0
      1.upto(n-1){ |i|
        upper += 1 if s[idx[i-1]] != s[idx[i]]
        t[idx[i]] = upper
      }
      s = t
    when String
      upper = 255
      s = s.bytes
    end
  else
    s.each{ |s|
      raise ArgumentError if s<0 || upper<s
    }
  end
  return sa_is(s, upper)
end

# frozen_string_literal: true

# lcp array for array of integers or string
def lcp_array(s, sa)
  s = s.bytes if s === String

  n = s.size
  rnk = [0]*n
  sa.each_with_index{ |sa, id|
    rnk[sa] = id
  }

  lcp = [0]*(n-1)
  h = 0
  n.times{ |i|
    h -= 1 if h > 0
    next if rnk[i] == 0
    j = sa[rnk[i]-1]
    h += 1 while j+h<n && i+h<n && s[j+h]==s[i+h]
    lcp[rnk[i]-1] = h
  }
  return lcp
end

s = gets.chomp
lcp = lcp_array(s, suffix_array(s))
ans = s.size*(s.size+1)/2
lcp.each{ |lcp| ans -= lcp }
puts ans


Measured memory_bytes: 63448
def main():
    n,m=map(int,input().split())
    ab=[list(map(int,input().split())) for _ in [0]*m]
    g=[[] for _ in [0]*n]
    [g[a-1].append(b-1) for a,b in ab]
    s,t=map(int,input().split())
    visit=[[False]*3 for _ in [0]*n]
    s-=1
    t-=1
    visit[s][0]=True
    cnt=0
    q=[s]
    while q:
        qq=[]
        cnt+=1
        c=cnt%3
        for i in q:
            for j in g[i]:
                if visit[j][c]==False:
                    visit[j][c]=True
                    qq.append(j)
        q=qq
        if visit[t][0]:
            print(cnt//3)
            break
    else:
        print(-1)
main()

Measured memory_bytes: 49092
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] heights = new int[n];
		for(int i=0;i<n;i++) {
			heights[i] = in.nextInt();
		}
		
		int[] cost = new int[heights.length];
		
		for(int i=1;i<heights.length;i++) {
			if(i-2>=0) {
				cost[i] += Math.min(cost[i-1] + Math.abs(heights[i-1]-heights[i]),cost[i-2]+ Math.abs(heights[i-2]-heights[i]));
			}
			else if(i-1>=0) {
				cost[i] += cost[i-1] + Math.abs(heights[i-1]-heights[i]);
			}
		}
		System.out.println(cost[heights.length-1]);

	}

}


Measured memory_bytes: 50176
#include<stdio.h>
#include<string.h>
int main()
{
  int i;
  int j;
  int n=0;
  int l=0;
  while( (n<1)||(l<1) )
	  scanf("%d %d",&n,&l);

  char word[n][l+1];
  char cng[l+1];
  for(i=0;i<n;i++)
    scanf("%s",word[i]);

  for(i=0;i<n-1;i++){
    for(j=1;j<n-i;j++){
      if(strcmp(word[j-1],word[j])>0){
        strcpy(cng,word[j-1]);
      	strcpy(word[j-1],word[j]);
       	strcpy(word[j],cng);
      }
    }
  }
  for(i=0;i<n;i++)
	  printf("%s",word[i]);
  printf("\n");
  return 0;
}

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

void fnInput(int &rnTrkSiz, vector<int> &rvnLod)
{
  int nLodSiz;
  cin >> nLodSiz >> rnTrkSiz;

  rvnLod.resize(nLodSiz);
  for (int i = 0; i < nLodSiz; i++)
    cin >> rvnLod[i];
}

int fnSimuAlloc(const vector<int> &cnrvnLod, int nTrkSiz, int nLimLod)
{
  int nCurLod;
  int nCntTrk = 0;

  for (int i = 0; i < cnrvnLod.size();    )
  {
    if (cnrvnLod[i] > nLimLod)  return 0;

    nCntTrk++;
    nCurLod = 0;
    while (i < cnrvnLod.size())
    {
      nCurLod += cnrvnLod[i];
      if (nCurLod > nLimLod)  break;

      i++;
    }
  }
  return (nCntTrk <= nTrkSiz);
}

void fnAlloc(const vector<int> &cnrvnLod, int nTrkSiz, int &rnMinLod)
{
  const int cnnMinLod = 0;
  const int cnnMaxLod = 1000000000;

  int nLow  = cnnMinLod;
  int nHigh = cnnMaxLod;
  rnMinLod = cnnMaxLod;

  while (nLow < nHigh)
  {
    int nLimLod = (nLow + nHigh) / 2;
    if (fnSimuAlloc(cnrvnLod, nTrkSiz, nLimLod))
    {
      rnMinLod = min(rnMinLod, nLimLod);
      nHigh = nLimLod;
    }
    else
      nLow = nLimLod + 1;
  }
}

void fnReSult(int nMinLod)
{
  cout << nMinLod << endl;
}

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

  int nTrkSiz, nMinLod = 0;
  vector<int> vnLod;

  fnInput(nTrkSiz, vnLod);
  fnAlloc(vnLod, nTrkSiz, nMinLod);
  fnReSult(nMinLod);

  return 0;
}

Measured memory_bytes: 1524
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt(),m=sc.nextInt(),x=sc.nextInt();
		int[] road= new int[n+1];
		int left=0,right=0;

		for(int i=0; i<m; i++) {
			int a=sc.nextInt();
			road[a]=1;
		}

		for(int i=x;0<=i;i--) {
			left+=road[i];
		}
		for(int i=x;i<=n;i++) {
			right+=road[i];
		}
		System.out.println(left<right?left:right);

	}
}

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

int main()
{
      string s;
      cin >> s;
      int count = 0;
      int max_substr = 0;
      for(char c : s) {
        if (c == 'A' || c == 'C' || c == 'G' || c == 'T') {
          count++;
          max_substr = max(max_substr, count);
        } else {
          count = 0;
        }
      }
      cout << max_substr << endl;
      return 0;
}


Measured memory_bytes: 256
N = gets.chop.to_i
A = gets.chop.split.map(&:to_i)

hash = {}
flag = true

A.each do |i|
  hash[i] ||= 0
  hash[i] += 1

  if hash[i] > 1
    flag = false
    break
  end
end

puts flag ? 'YES' : 'NO'


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

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

  vector<float> A(N);
  for(int i=0;i<N;i++) {
    cin >> A.at(i);
  }

  sort(A.begin(), A.end(), greater<int>());

  float div, ans=0;
  for(int i=0;i<N;i++) {
    if (i+1==N-1 || i+1==N) div = pow(2, N-1);
    else div = pow(2, (i+1));
    ans += A.at(i) / div;
  }

  cout << ans << endl;

  return (0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    int n; cin >> n;
    int m; cin >> m;
    int c[m];
    rep(i,m)cin >> c[i];

    int dp[n+1] = {};
    rep(i,n+1)dp[i] = i;

    rep(i,m){
        rep(j,n+1){
            if(c[i] <= j){
                dp[j] = min(dp[j], dp[j-c[i]] + 1);
            }
        }
    }

    cout << dp[n] << endl;
    
    return 0;
}
 
 



Measured memory_bytes: 3308
# -*- coding: utf-8 -*-
# 標準入力を取得
A, B = list(map(int, input().split()))

# 求解処理
ans = str()
if (A <= 8) and (B <= 8):
    ans = "Yay!"
else:
    ans = ":("

# 結果出力
print(ans)


Measured memory_bytes: 9032
#include<iostream>
#include<string>
#include <vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#include<cmath>
#include<iomanip>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define vsort(v) sort(v.begin(), v.end())
#define rv(v) reverse(v.begin(), v.end())
#define ll long long
const ll MOD = 1e9 + 7;

int main() {
	int n, m;
	cin >> n >> m;
	vi city(n+1);
	rep(i, m) {
		int s, t;
		cin >> s >> t;
		city[s]++;
		city[t]++;
	}
	for (int i = 1; i <= n; i++) cout << city[i] << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <map>
#include <queue>
#include <set>
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep1(i,n) for(int i = 1; i <= n; i++)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
using namespace std;
ll mod = 1e9 + 7;

int main()
{
	ll n;
	cin >> n;
	ll ans = n + 1;
	for (ll i = 1; i*i <= n; i++)
	{
		if (n % i == 0)
		{
			ll a = n / i;
			ans = min(ans, a + i);
		}
	}
	co(ans - 2);
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;

int main()
{
    cin.tie(0);

    int k;
    cin >> k;
    vector<int64_t> as(k);
    for (auto& a : as)
        cin >> a;
    reverse(as.begin(), as.end());

    int64_t ma = 2, mi = 2;
    bool err = false;
    for (auto& a : as) {
        int64_t ni = (mi + a - 1) / a * a;
        int64_t na = ma / a * a + a - 1;
        if (ni > na)
            err = true;

        ma = na;
        mi = ni;
    }

    if (err) {
        cout << -1 << endl;
    } else {
        cout << mi << " " << ma << endl;
    }

    return 0;
}

Measured memory_bytes: 1024
/** 
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

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

typedef long long ll;
//#define endl "\n"
#define fori(n) for(ll i=0; i<(n); i++)

#define cins(s) string s; cin>>s;
#define cini(i) int i; cin>>i;
#define cinll(l) ll l; cin>>l;
#define cinai(a, n) vi a(n); fori(n) { cin>>a[i]; }
#define cinall(a, n) vll a(n); fori(n) { cin>>a[i]; }
#define cinas(s, n) vs s(n); fori(n) { cin>>s[i]; }

typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<string> vs;
typedef vector<ll> vll;

int main() {
cin.tie(nullptr);
std::ios::sync_with_stdio(false);
    cini(n);

    typedef vector<set<pii>> vspii;

    const int cnt=n*(n-1)/2;
    vector<vspii> adj(n+1, vspii(n+1));; // adj[i][j]== set of matches happen after match i,j
    vector<vspii> adjR(n+1, vspii(n+1)); // adjR[i][j]== set of matches happen before match i,j

/* create a graph
 * Edges are dependencies, vertices are matches.
 * Remove on every day all vertices without incoming dependencies.
 * Repeat.
 */

    for(int i=1; i<=n; i++) {
        vpii row;
        pii prev;
        for(int j=0; j<n-1; j++) {
            int op;
            cin>>op;
            int p1=min(i, op);
            int p2=max(i, op);
            pii curr={ p1, p2 };
            if(j>0) {
                adj[prev.first][prev.second].insert(curr);
                adjR[curr.first][curr.second].insert(prev);
            }
            prev=curr;
        }
    }

    vpii rem;   // list of matches on current day
    for(int i=1; i<=n; i++) {
        for(int j=i+1; j<=n; j++) {
            if(adjR[i][j].size()==0)
                rem.push_back({i,j});
        }
    }

    int day=0;
    int c=0;
    while(true) {
        vpii rem2;
        if(rem.size()==0)
            break;
        for(pii p : rem) {
            c++;
            for(pii p2 : adj[p.first][p.second]) {
                adjR[p2.first][p2.second].erase(p);
                if(adjR[p2.first][p2.second].size()==0)
                    rem2.push_back(p2);
            }
        }
        rem.swap(rem2);
        day++;
    }

    if(c!=cnt) 
        cout<<-1<<endl;
    else
        cout<<day<<endl;
}



Measured memory_bytes: 187904
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int n;
	cin>>n;
	int ans=0;
	vector<vector<int>> x(n),y(n);
	rep(i,n){
		int a;
		cin>>a;
		rep(j,a){
			int b,c;
			cin>>b>>c;
			b--;
			x[i].push_back(b);
			y[i].push_back(c);
		}
	}
	rep(S,1<<n){
		int now=__builtin_popcount(S);
		bool flag=true;
		rep(i,n){
			if(S & (1<<i)){
				rep(j,x[i].size()){
					if(y[i][j]){
						if(!(S & (1<<x[i][j]))){
							flag=false;
						}
					}else{
						if(S & (1<<x[i][j])){
							flag=false;
						}
					}
				}
			}
		}
		if(flag) chmax(ans,now);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
use std::cmp;
use std::collections::*;
use std::i32;
use std::io::{self, Read};
use std::mem;

const MOD: usize = 1000000007;

fn main() {
    let stdin = io::stdin();
    let mut sc = Scanner::new(stdin.lock());

    let x1: i32 = sc.read().unwrap();
    let y1: i32 = sc.read().unwrap();
    let x2: i32 = sc.read().unwrap();
    let y2: i32 = sc.read().unwrap();

    // 辺 (x1, y1) - (x2, y2) のベクトル v
    let vx = x2 - x1;
    let vy = y2 - y1;

    let x3 = x2 - vy;
    let y3 = y2 + vx;

    let x4 = x3 - vx;
    let y4 = y3 - vy;

    println!("{} {} {} {}", x3, y3, x4, y4);
}

struct Scanner<R: Read> {
    reader: R,
}

impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader }
    }

    fn read<T: std::str::FromStr>(&mut self) -> Option<T> {
        self.reader
            .by_ref()
            .bytes()
            .map(|b| b.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse()
            .ok()
    }

    fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Option<Vec<T>> {
        (0..n).map(|_| self.read()).collect()
    }

    fn read_vec2d<T: std::str::FromStr>(&mut self, m: usize, n: usize) -> Option<Vec<Vec<T>>> {
        (0..m).map(|_| self.read_vec(n)).collect()
    }

    fn read_board(&mut self, n: usize) -> Option<Vec<Vec<char>>> {
        (0..n)
            .map(|_| {
                self.read::<String>()
                    .map(|s| s.chars().collect::<Vec<char>>())
            })
            .collect()
    }
}


Measured memory_bytes: 4352
#include <stdio.h>
#include <vector>
#include <utility>
#include <algorithm>

#define ii pair<int, int>

using namespace std;

int main() {
	int n, m, p, y, city;
	vector<ii> data[100010];
	ii id[100010];
	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; i++) {
		scanf("%d %d", &p, &y);
		data[p].push_back(make_pair(y, i));
	}
	for (int i = 1; i <= n; i++) {
		sort(data[i].begin(), data[i].end());
		for (int j = 0; j < (int) data[i].size(); j++) {
			city = data[i][j].second;
			id[city] = make_pair(i, j + 1);
		}
	}
	for (int i = 0; i < m; i++)
		printf("%.6d%.6d\n", id[i].first, id[i].second);
	return 0;
}

Measured memory_bytes: 7808
#include <cstdio>
#include <cmath>
using namespace std;
const int N=205;
int n;
int a[N];
int ans,chk;
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		chk=1;
		for (int j=1;j<i;j++)
			chk&=(a[j]<=a[i]);
		ans+=chk;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1696
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

int main() {
	ll n, k;
	cin >> n >> k;
	vector<ll> a(n);
	rep(i, n) {
		cin >> a[i];
		a[i]--;
	}

	vector<ll> suba(n + 1);
	suba[0] = 0;
	rep(i, n) {
		suba[i + 1] = suba[i] - a[i];
		suba[i + 1] = suba[i + 1] % k;
		if(suba[i + 1] < 0) suba[i + 1] += k;
	}

	ll ans = 0;
	map<ll, ll> mp;
	rep(i, n) {
		mp[suba[i]]++;
		if(i >= k - 1) mp[suba[i - k + 1]]--;
		ans += mp[suba[i + 1]];
	}
	cout << ans << endl;
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
#define dum(x) cout<<#x<<'='<<x<<endl
#define ll long long
using namespace std;

int main() {
  ll a, b, c;
  int k;
  cin >> a >> b >> c >> k;
  ll tmp = max({a, b, c});
  ll ans = a + b + c - tmp;
  for (int i = 0; i < k; i++) {
    tmp *= 2;
  }
  ans += tmp;
  cout << ans << endl;
}


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

#include <vector>


using namespace std;

long long  MOD = 1000000007;

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

	vector<int> r;

	cin >> s0 >> s1;


	if (n == 1) {
		cout << 3 << endl;
		return 0;
	}



	for (int i = 1; i < n; i++) {
		int prev = s0.at(i - 1);
		int cur = s0.at(i);

		if (i == 1) {
			if (prev != cur) {
				r.push_back(1);	
			}

		}

		if (i == n - 1) {
			if (prev == cur) {
				r.push_back(2);
			} else {
				r.push_back(1);				
			}
			continue;
		}


		if (prev == cur) {
			r.push_back(2);
			continue;
		}

		int next = s0.at(i + 1);
		if (next != cur) {
			r.push_back(1);
		}
	}



	long long ans = (r[0] == 1) ? 3 : 6;
	int prev = r[0];

	for (int i = 1; i < r.size(); i++) {
		if (prev == 2 && r[i] == 1) {
			prev = r[i];
			continue;
		}
		
		if (prev == 2 && r[i] == 2) {
			ans *= 3;
		} else {
			ans *= 2;
		}
		prev = r[i];

		ans %= MOD;

	}
	cout << ans << endl;


	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
using namespace std;

char a[200005];

int main(void)
{
	int n, i;

	scanf("%d %s", &n, a + 1);

	int red = 0, white = 0;

	for (i = 1; i <= n; i++)
		if (a[i] == 'R')
			red++;
		else
			white++;

	int badr = 0, badw = 0;

	for (i = 1; i <= n; i++)
	{
		if (i <= red) // only red
		{
			if (a[i] != 'R')
				badr++;
		}
		else          // only white
		{
			if (a[i] != 'W')
				badw++;
		}
	}

	int ans = min(badr, badw);

	badr -= ans;
	badw -= ans;

	printf("%d", ans + badr + badw);
	return 0;
}

Measured memory_bytes: 1920
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#define N 1000005
#define LL long long
#define oo (1<<30)
using namespace std;
int n,q,ans,f[27][N],F[20][N]; char st[N];
int main()
{
	int i,j,l,r;
	scanf("%s",st+1);
	n = strlen(st+1);
	for(i=1;i<=n;i++)
		f[st[i]-'a'][i]=i+1;
	for(i=n-1;i>=1;i--){
		for(j=st[i]-'a'+1;j<=26;j++)
			f[j][i]=f[j-1][f[j-1][i]];
		for(j=0;j<st[i]-'a';j++)
			f[j][i]=f[j][f[26][i]];
	  }
	for(i=1;i<=n;i++) F[0][i]=f[26][i];
	for(i=1;i<20;i++)
		for(j=1;j<=n;j++)
			F[i][j]=F[i-1][F[i-1][j]];
	scanf("%d",&q);
	while(q--){
		scanf("%d %d",&l,&r),ans=0;
		for(i=19;i>=0;i--)
			if(F[i][l]<=r+1&&F[i][l])
				l=F[i][l];
		if(l>r) printf("Yes\n");
		else printf("No\n");
	  }
	return 0;
}


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

using namespace std;

int main()
{
  string s,t;
  cin>>s;
  cin>>t;

  int n=s.size();
  int m=t.size();
  int dp[n+1][m+1];
  for(int i=0;i<=m;i++)dp[0][i]=0;
  for(int i=0;i<=n;i++)dp[i][0]=0;

  for(int i=1;i<=n;i++){
    for(int j=1;j<=m;j++){
       if(s[i-1]==t[j-1]){
         dp[i][j]=1+dp[i-1][j-1];
       }else{
         dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
       }
    }
  }


  //PRINTING THE COMMON SUBSEQUECE
  string ans="";
  int i=n,j=m;
  while(i>0 && j>0){
    if(s[i-1]==t[j-1]){
        ans+=s[i-1];
        i--;
        j--;
    }else if(dp[i-1][j] > dp[i][j-1]){
      i--;
    }else{
      j--;
    }
  }

  reverse(ans.begin(),ans.end());
  cout<<ans<<endl;
}


Measured memory_bytes: 35456
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)

using namespace std;

void solve(int N, int D, vector<vector<int>> X) {
  auto dist = [&](const vector<int>& P0, const vector<int>& P1) {
    int sum(0);
    REP(d, D)
    sum += (P0[d] - P1[d]) * (P0[d] - P1[d]);
    return sqrt(sum);
  };

  int ans(0);
  REP(j, N)
    REP(i, j) {
    double d = dist(X[i], X[j]);
    if (d - int(d) < numeric_limits<double>::epsilon())
      ans++;
  }
  cout << ans << endl;
}

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

  int N, D;
  cin >> N >> D;
  vector<vector<int>> X(N, vector<int>(D));
  REP(i, N)
    REP(j, D)
      cin >> X[i][j];

  solve(N, D, move(X));

  return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <bitset>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <numeric>
#include <array>
#include <queue>
#include <set>
using namespace std;
using ll = long long int;
#define REP(i,n) for(int i=0;i<n;i++)

int main()
{
    int X, A;
    cin >> X >> A;

    if (X < A)
    {
        cout << 0 << endl;
    }
    else if (X >= A)
    {
        cout << 10 << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define df 0

int main(){
  if(df) printf("*debug mode*\n");
  int n,t; cin >> n >> t;
  int prev; cin >> prev; 
  long int s=t;
  for(int i=1;i<n;i++){
    int temp; cin >> temp;
    if(temp<prev+t){
      s-=prev+t-temp;
    }
    s+=t;
    prev=temp;
  }
  cout << s;
}

/// confirm df==0 ///


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

using namespace std;

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

void Main(){
  string s;
  cin>>s;
  replace(s.begin(),s.end(),',',' ');
  cout<<s<<endl;
}

int main(){
  std::cin.tie(nullptr);                  // 標準入出力高速化
  std::ios_base::sync_with_stdio(false);  // SとS++の入出力出力を非同期
  Main();
}

Measured memory_bytes: 256
/// Thank you tanakh!!!
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

use std::cmp;

fn main() {
    let mut count0 = vec![0; 100001];
    let mut count1 = vec![0; 100001];
    input!(n: usize, v: [usize; n]);
    for i in 0..n {
        if i % 2 == 0 {
            count0[v[i]] += 1;
        } else {
            count1[v[i]] += 1;
        }
    }

    let max0 = *count0.iter().max().unwrap();
    let max1 = *count1.iter().max().unwrap();

    let mut m0 = vec![];
    let mut m1 = vec![];
    for i in 0..100001 {
        if count0[i] == max0 {
            m0.push(i);
        }
        if count1[i] == max1 {
            m1.push(i);
        }
    }

    if m1.len() == 1 && m0.len() == 1 && m1[0] == m0[0] {
        count0[m0[0]] = 0;
        count1[m1[0]] = 0;
        let sub0 = *count0.iter().max().unwrap();
        let sub1 = *count1.iter().max().unwrap();

        println!("{}", cmp::min(n - max0 - sub1, n - max1 - sub0));
    } else {
        println!("{}", n - max0 - max1);
    }
}


Measured memory_bytes: 10492
#include<cstdio>
#include<iostream>
using namespace std;
double a,cnt1,cnt2,n,m,d;
int main()
{
	cin>>n>>m>>d;
	if(n<2*d+1)
	{
		cnt1=n;
		cnt2=0;
	}
	else 
	{
		cnt1=2*d;
		cnt2=n-2*d;
	}
	if(d==0)a=n*(2/n/n+2*(m-2)/n/n);
	else a=cnt1*(2/n/n+2*(m-2)/n/n)+cnt2*(4/n/n+4*(m-2)*(n-2)/n/n/n+8*(m-2)/n/n/n);
	a/=(double)2;
	printf("%.10f",a);
	return 0;
}

Measured memory_bytes: 256
def modnotzero(m, n):
	if m % n != 0: return 1
	else: return 0
N, K = map(int, raw_input().split())
A = map(int, raw_input().split())
pos = 0
for i in range(0, N):
	if A == 1: pos = i
left = pos
right = N - 1 - pos

min = N+1

for i in range(0, K):
	L = left - i
	R = right - K + 1 + i
	if L >= 0 and R >= 0:
		cnt = L/(K-1)+R/(K-1)+modnotzero(L, (K-1))+modnotzero(R, (K-1))
		if cnt < min: min = cnt

print min + 1

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

int main(){
  int n, O[2] = {0, 0}, P[2] = {0};
  cin >> P[0] >> P[1] >> n;
  
  int x, y, a;
  for(int i = 0; i < n; i++){
    cin >> x >> y >> a;
    if(a == 1){
      O[0] = max(O[0], x);
    }else if(a == 2){
      P[0] = min(P[0], x);
    }else if(a == 3){
      O[1] = max(O[1], y);
    }else if(a == 4){
      P[1] = min(P[1], y);
    }
  }
  
  if(O[0] >= P[0] || O[1] >= P[1]){
    cout<< 0 << endl;
  }else{
    cout << (P[0] - O[0]) * (P[1] - O[1]) << endl;
  }
}

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

int prime_factorize(long long int N) {
  vector<long long int> res;
  res.push_back(1);
  for (long long int a = 2; a * a <= N; a++) {
    if (N % a != 0) continue;
    while (N % a == 0) N /= a;
    res.push_back(a);
  }
  if (N != 1) res.push_back(N);
  return res.size();
}

int main() {
  long long int A, B, G;
  cin >> A >> B;
  G = __gcd(A, B);
  cout << prime_factorize(G) << endl; 
}

Measured memory_bytes: 256
from itertools import count, takewhile

def calc(N, d={}):
    if N < 6:
        return N
    if N in d:
        return d[N]

    max9 = max(takewhile(lambda x: x<=N, (9**i for i in count())))
    max6 = max(takewhile(lambda x: x<=N, (6**i for i in count())))

    d[N] = min(calc(N-max9), calc(N-max6))+1
    #print(N, ':', d[N])
    return d[N]

print(calc(int(input())))


Measured memory_bytes: 3060
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
//typedef pair<int,int> P;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef pair<ll, pair<int, int>> P;
//typedef tuple<int,int,int> T;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2147483600;//10^9
int INFM =100000000;
ll MOD  = 1000000007;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main(){
    int N,K;
    cin >> N >> K;
    if(N % K){
        cout << 1 << endl;
    }else{
        cout << 0 << endl;
    }
    
    
    
    
}

Measured memory_bytes: 256
import numpy as np
n=123456
q = int(input())

is_prime = np.ones(n+1,dtype=int)
is_prime[0]=0
is_prime[1]=0

for i in range(2,n+1):
    if(is_prime[i]==1):
        j=i+i
        while j <= n:
            is_prime[j] = 0
            j += i

cnt = [is_prime[x]*is_prime[(x+1)//2] for x in range(0,n+1)]

for i in range(1,n+1):
    cnt[i]+=cnt[i-1]

for i in range(q):
    l,r = map(int, input().split())
    print(cnt[r]-cnt[l-1])

Measured memory_bytes: 20324
// https://atcoder.jp/contests/abc161/tasks/abc161_d
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int K;
    cin >> K;
    queue<int> q;
    FOR(i, 1, 10) q.push(i);
    int cnt = 0;
    while (!q.empty()) {
        int t = q.front();
        q.pop();
        cnt++;
        if (cnt >= K) {
            cout << t << endl;
            return 0;
        }
        vector<int> v;
        FOR(i, t % 10 - 1, t % 10 + 2) {
            if (i >= 0 && i <= 9) {
                v.push_back(i);
            }
        }
        for (auto &x : v) {
            q.push(t * 10 + x);
        }
    }

    return 0;
}


Measured memory_bytes: 1792
n, k = map(int,input().split())
d = []
a = []
for _ in range(k):
    d.append(int(input()))
    a.append(list(map(int,input().split())))
check = [False] * n
for i in range(k):
    for j in a[i]:
        check[j-1] = True

ans = 0
for i in range(n):
    if not check[i]:
        ans += 1
print(ans)

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

void fnInput(int& rnBasTmpr, int& rnTrgTmpr, vector<int>& rvnPosHeight)
{
  int nPosSiz;
  cin >> nPosSiz;
  cin >> rnBasTmpr >> rnTrgTmpr;

  rvnPosHeight.resize(nPosSiz);
  for (int& rnPosHeight : rvnPosHeight)
    cin >> rnPosHeight;
}

int fnTmprCheck(int nBasTmpr, int nTrgTmpr, const vector<int>& cnrvnPosHeight)
{
  double nMinDiff = DBL_MAX;
  int nMinPos;

  for (int n = 0; n < cnrvnPosHeight.size(); n++)
  {
    double nPosDiff = abs(nBasTmpr - cnrvnPosHeight[n] * 0.006 - nTrgTmpr);
    if (nPosDiff < nMinDiff)
    {
      nMinDiff = nPosDiff;
      nMinPos  = n;
    }
  }
  return nMinPos + 1;
}

int main()
{
  int nBasTmpr, nTrgTmpr;
  vector<int> vnPosHeight;

  fnInput(nBasTmpr, nTrgTmpr, vnPosHeight);
  cout << fnTmprCheck(nBasTmpr, nTrgTmpr, vnPosHeight) << endl;

  return 0;
}

Measured memory_bytes: 256
import itertools

l = [int(input()) for i in range(5)]
l2 = list(itertools.permutations(l))
min = float("INF")
for i in range(120):
    ans = 0
    for j in range(4):
        if l2[i][j] % 10 == 0:
            ans += l2[i][j]
        else:
            ans += (l2[i][j] // 10 + 1) * 10
    ans += l2[i][4]
    if min > ans:
        min = ans
print(min) 

Measured memory_bytes: 3064
function main(standardInput) {
    var lenghtList = standardInput.split(' ');
    var varticalLength = parseInt(lenghtList[0]);
    var horizonLength = parseInt(lenghtList[1]);

    console.log(varticalLength * horizonLength + ' ' + 2 * (varticalLength + horizonLength));
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));



Measured memory_bytes: 15120
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll, vl/*, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, n) for(ll i = 1; i <= ll(n); i++)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); i++)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); i++)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  string s;
  cin >> s;
  rep(i, 3) if(s[i]==s[i+1]) {cout << "Bad" << newl; return 0;}
  cout << "Good" << newl;
  return 0;
}


Measured memory_bytes: 256
/**
 *  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_6_A
 */
#include <iostream>
#include <sstream>
#include <vector>

using namespace std;

void
printv(const vector<int> a)
{
    stringstream ss;
    for (auto it = a.cbegin(); it != a.cend(); it++) {
        if (it != a.begin()) {
            ss << ' ';
        }
        ss << *it;
    }
    cout << ss.str() << endl;
}

vector<int>
countingsort(const vector<int> a, const int k)
{
    vector<int> C(k + 1);
    for (auto& it : a) { C[it]++; }

    for (int i = 0; i < k; i++) { C[i + 1] += C[i]; }

    vector<int> B(a.size());
    for (auto it = a.crbegin(); it != a.crend(); it++) {
        B[--C[*it]] = *it;
    }
    return B;
}

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

    int n;
    cin >> n; cin.ignore();

    vector<int> A(n);
    int k = 0;
    for (int i = 0; i < n; i++) {
        cin >> A[i]; cin.ignore();
        if (A[i] > k) { k = A[i]; }
    }

    vector<int> B = countingsort(A, k);
    printv(B);

    return 0;
}

Measured memory_bytes: 53268
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
ll solve(ll a,ll b,ll num){
	ll first = a/num;
	ll second = b/num;
	if(a%num==0)	first--;
	return second-first;
}
int main()
{
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	ll val = __gcd(c,d);
	ll mul = (val)*(c/val)*(d/val);
	ll num =0;
	num+= solve(a,b,c);
	// cout<<num<<endl;
	num+= solve(a,b,d);
	// cout<<num<<endl;
	num-= solve(a,b,mul);
	// cout<<num<<endl;
	ll ans = (b-a+1)-num;
	cout<<ans<<"\n"; 
	return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val S = readLine()!!

    val e = Array (S.length) { 1 }
    val o = Array (S.length) { 0 }

    for (i in S.indices) {
        if (S[i] == 'R') {
            e[i + 1] += o[i]
            o[i + 1] += e[i]
            o[i] = 0
            e[i] = 0
        }
    }

    for (i in S.indices.reversed()) {
        if (S[i] == 'L') {
            e[i - 1] += o[i]
            o[i - 1] += e[i]
            o[i] = 0
            e[i] = 0
        }
    }

    println(S.indices.map { if (S[it] == 'R') e[it] else o[it - 1] }.joinToString(" "))
}


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

int main(){
    long long A,B,N;
    cin >> A >> B >> N;
    long long num;
    if(B-1>N){
        num = N;
    }else{
        num = B-1;
    }
    long long f=((A*num)/B)-A*(num/B);
    cout << f << endl;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
#include<queue>
using namespace std;
const int dx[]={1,0,-1,0};//position prepare
const int dy[]={0,1,0,-1};//position prepare
int n,m,k;
int d[1050][1050];//record distance
int sx,sy,x,y;
int xx,yy;
char c[1050][1050];
queue<pair<int,int> > q;
bool check(int a,int b){//check if the grid is in use
	return a>=0&&a<n&&b>=0&&b<m&&c[a][b]!='#';
}
int minidis(int i,int j){
	int r=i;
	r=min(r,j);
	r=min(r,n-1-i);
	r=min(r,m-1-j);
	return r;
}
/*void bfs(){//bfs
	while(!q.empty()){
		x=q.front().first;
		y=q.front().second;
		q.pop();
		for(int i=0;i<4;i++){//check distance
			xx=x+dx[i];
			yy=y+dy[i];
			if(check(xx,yy)&&d[xx][yy]<0){
				d[xx][yy]=d[x][y]+1;
				q.push(make_pair(xx,yy));
			}
		}
	}
}
*/
int main(){
	cin>>n>>m>>k;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cin>>c[i][j];
			if(c[i][j]=='S'){
				sx=i;
				sy=j;
			}
		}
	}
	memset(d,-1,sizeof(d));
	d[sx][sy]=0;
	q.push(make_pair(sx,sy));
	while(!q.empty()){
		x=q.front().first;
		y=q.front().second;
		q.pop();
		for(int i=0;i<4;i++){//check distance
			xx=x+dx[i];
			yy=y+dy[i];
			if(check(xx,yy)&&d[xx][yy]<0){
				d[xx][yy]=d[x][y]+1;
				q.push(make_pair(xx,yy));
			}
		}
	}
	int res=1<<20;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(d[i][j]>=0&&d[i][j]<=k){
				res=min(res,1+((minidis(i,j)+k-1)/k));
			}
		}
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 5376
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <iomanip>
#include <queue>
#include <stack>
#include <deque>
#include <functional>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,s) for(int i=s;i>=0;i--)

using ll = long long;
using namespace std;

const ll INF = 1010101010;
const ll MOD = 1000000007;

int main() {
	ll add = 0, q = 0;
	string s;
	char ans[20];
	cin >> s;
	rep(i, s.size()) {
		if (s[i] != 'B') {
			ans[add] = s[i];
			add++;
			q = 0;
		}
		else if (add != 0) {
			ans[add - 1 - q] = 'i';
			q++;
		}
	}
	rep(i, add)
		if (ans[i] != 'i')
			cout << ans[i];
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

struct Edge
{
    public int to;
    public int dist;
}
struct FC
{
    public int now;
    public int from;
    public bool color;
}
class Program
{
    static void Main()
    {
        var N = int.Parse(ReadLine());
        var u = new int[N - 1];
        var v = new int[N - 1];
        var w = new int[N - 1];
        for (int i = 0; i < N - 1; i++)
        {
            var line = ReadLine().Split(' ');
            u[i] = int.Parse(line[0]) - 1;
            v[i] = int.Parse(line[1]) - 1;
            w[i] = int.Parse(line[2]);
        }

        var tree = new List<Edge>[N];
        for (int i = 0; i < tree.Length; i++)
        {
            tree[i] = new List<Edge>();
        }
        for (int i = 0; i < u.Length; i++)
        {
            tree[u[i]].Add(new Edge { to = v[i], dist = w[i] });
            tree[v[i]].Add(new Edge { to = u[i], dist = w[i] });
        }

        var vis = new bool[N];
        var col = new bool[N];
        var q = new Queue<FC>();
        q.Enqueue(new FC { from = -1, color = false });
        vis[0] = true;
        while (q.Count != 0)
        {
            var n = q.Dequeue();
            if (n.from != -1)
            {
                col[n.now] = n.color;
            }
            foreach (var s in tree[n.now])
            {
                if (!vis[s.to])
                {
                    q.Enqueue(new FC { now = s.to, color = s.dist % 2 == 0 ? n.color : !n.color });
                    vis[s.to] = true;
                }
            }
        }

        for (int i = 0; i < N; i++)
        {
            WriteLine(col[i] ? "0" : "1");
        }
    }
}


Measured memory_bytes: 30328
#include<iostream>
#include<string>
#include<vector>
 
using namespace std;
 
int main() {
	string s;
	cin >> s;
	int k; cin >> k;
	int l = s.length();
	for (int i = 0; i < l; i++) {
                if(s[i] == 'a')continue;
		if ('z' - s[i] + 1 <= k) {
			k -= 'z' - s[i] + 1;
			s[i] = 'a';
		}
	}
	s[l - 1] += k % (26);
	cout << s << endl;
}


Measured memory_bytes: 512
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

"""
[memo]
-9の例
N = ... + (-2)**i + ...の形をしている
1桁目
N = X + (-2)**0 or N = X + 0であり,このときXは必ず2の倍数
よって,N = X + 0 = -9は成り立たないので,N = X + (-2)**0 の形であり,1桁目は1
また,このときN = X + (-2)**0 = -9よりX = -10.
2桁目
X = Y + (-2)**1 or X = Y + 0であり,このときYは必ず4の倍数
よって,X = Y + 0 = -10は成り立たないので, X = Y + (-2)**1の形であり,2桁目は1
また,このときX = Y + (-2)**1 = -10よりY = -8.
3桁目
Y = Z + (-2)**2 or Y = Z + 0であり,このときZは必ず8の倍数
よって,Y = Z + (-2)**2 = -8は成り立たないので, Y = Z + 0の形であり,3桁目は0
また,このときY = Z + 0 = -8よりZ = -8.
4桁目
Z = W + (-2)**3 or Z = W + 0であり,このときWは必ず16の倍数
よって,Z = W + 0 = -8は成り立たないのおで, Z = W + (-2)**3の形であり,4桁目は1
また,このときZ = W + (-2)**3 = -8よりW = 0.
同様にするとこれ以降の桁は常に0なので,答1011
"""
n = I()
ans = ''
m = 2
cnt = 0
x = n
while 1:
    if x % m:
        ans += '1'
        x -= (-2)**(cnt)
    else:
        ans += '0'
    cnt += 1
    m *= 2
    if x == 0:
        break
print(ans[::-1])
    

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;;
#define llong long long
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
int main(){
    int n; cin >> n;
    set<llong> s;
    llong tmp;
    for(int i=0; i<n; i++){
        cin >> tmp;
        if(!s.erase(tmp)){
            s.insert(tmp);
        }
    }
    cout << s.size() << endl;
}

Measured memory_bytes: 4864
def main():
    N = int(input())
    D = [int(i) for i in input().split()]
    from collections import Counter, defaultdict
    D_c = defaultdict(int, Counter(D))
    M = int(input())
    T = [int(i) for i in input().split()]
    for t in T:
        if D_c[t] > 0:
            D_c[t] -= 1
        else:
            return print("NO")
    print("YES")


if __name__ == '__main__':
    main()


Measured memory_bytes: 46428
#pragma once
#include <stdio.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>

using namespace std;

long long N,a,b;
long long A;
long long B;
long long C[200001] = {};
long long result=0;
string S,SN,bufS;
vector <long long>vl;
vector <long> v;
//typedef pair<long long, long long> pl;



int main() {

	cin >>N;

	for (int i = 0; i < N; i++) {
		cin >> C[i];
		v.push_back(C[i]);
	}

	sort(v.begin(), v.end());
	A = v[(N / 2)-1];
	B = v[(N / 2)];

	for (int i = 0; i < N; i++) {
		if (A >= C[i]) {
			cout << B << endl;
		}
		else {
			cout << A << endl;
		}
	}

	

return 0;
}

Measured memory_bytes: 5488
#include <bits/stdc++.h>
using namespace std;
int i,a[60],n,b[60];
vector<int>vv;
int dp[60][60];
int calc(int u,int v){
	if(u==v)return 1;
	if(v>u)return 0;
	int &ret=dp[u][v];
	if(ret!=-1)return ret;
	ret=0;
	for(int j=1;j<i&& j<=u;j++){
		
		ret|=calc(u%j,v);
	}
	for(int j=0;j<vv.size();j++){
		if(vv[j]>u)continue;
		ret|=calc(u%vv[j],v);
	}
	return ret;
}
int main() {
cin>>n;
for(int i=0;i<n;i++)scanf("%d",&a[i]);
for(int i=0;i<n;i++)scanf("%d",&b[i]);
long long ans=0;
for( i=51;i>=1;i--){
	memset(dp,-1,sizeof dp);
	bool f=1;
	
	for(int j=0;j<n;j++){
		if(!calc(a[j],b[j])){
			f=0;break;
		}
	}
	if(!f && i == 51){
		puts("-1");
		return 0;
	}
	if(f){
		continue;
	}
	vv.push_back(i);
	ans+=1LL<<i;
}

cout<<ans<<endl;

	return 0;
}

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

const int INF = 0x3f3f3f3f;

int N, M;
vector<int> A, B;

void solve(){
    int smin = INF;
    int aans = -1, bans = -1;
    
    for(int a=0; a<N; a++){
        for(int b=0; b<M; b++){
            int s1 = 0, s2 = 0;
            
            for(int i=0; i<N; i++) if(i != a)
                s1 += A[i];
            for(int i=0; i<M; i++) if(i != b)
                s2 += B[i];
            
            s1 += B[b];
            s2 += A[a];
            
            if(s1 == s2 && A[a] + B[b] < smin){
                smin = A[a] + B[b];
                aans = A[a];
                bans = B[b];
            }
        }
    }
    if(smin == INF)
        cout << -1 << endl;
    else
        cout << aans << " " << bans << endl;
}

int main(){
    while(cin >> N >> M, N|M){
        A.resize(N);
        B.resize(M);
        
        for(auto &v: A)
            cin >> v;
        for(auto &v: B)
            cin >> v;
        
        solve();
    }
}

Measured memory_bytes: 3104
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
constexpr auto INF = 1000000000;
constexpr auto LLINF = 1LL << 62;
constexpr auto mod = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }

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

    int n, m;
    cin >> n >> m;
    int k;
    vector<VI> s(m);
    FOR(i, 0, m) {
        cin >> k;
        s[i].resize(k);
        FOR(j, 0, k)cin >> s[i][j], s[i][j]--;
    }
    VI p(m);
    FOR(i, 0, m)cin >> p[i];

    int ans = 0;
    FOR(i, 0, 1 << n) {
        vector<bool> on(n, 0);
        FOR(j, 0, n)if (i & (1 << j))on[j] = 1;
        bool all_light = 1;
        FOR(j, 0, m){
            int cnt = 0;
            for (int a : s[j]) {
                if (on[a])cnt++;
            }
            if (cnt % 2 != p[j])all_light = 0;
        }
        if (all_light)ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <random>

#define _overload(a, b, c, d, ...) d
#define _rep1(X, A, Y) for (int (X) = (A);(X) <= (Y);++(X))
#define _rep2(X, Y) for (int (X) = 0;(X) < (Y);++(X))
#define rep(...) _overload(__VA_ARGS__, _rep1, _rep2)(__VA_ARGS__)
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define all(X) (X).begin(),(X).end()
#define _size(X) (int)((X).size())
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

ll N, A, B;
ll mi, ma;

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

  cin >> N >> A >> B;

  if (A > B) {
      cout << 0 << endl;
      return 0;
  }
  if (N == 1 && A != B) {
      cout << 0 << endl;
      return 0;
  }
  mi = (N-1)*A + B;
  ma = (N-1)*B + A;

  cout << ma - mi + 1 << endl;

  return 0;
}


Measured memory_bytes: 256