akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <set>
#include <map>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <climits>
#include <fstream>
#include <cassert>
#include <unordered_map>
using namespace std;
#pragma warning(disable : 4996)
typedef long long ll;
typedef long double ld;



int main() {
#ifdef _DEBUG
	freopen("input1.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n, k;
	cin >> n >> k;
	vector<ll> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	ll ans = 0;
	for (int i = 0; i < n - k; i++) {
		ans += a[i];
	}
	cout << ans;
}

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

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

    int n;
    std::cin >> n;

    std::vector<int> a(n);
    for (int &i : a) std::cin >> i;

    int64_t ans = 0;
    for (int i = 1; i < n; i++) {
        if (a[i - 1] > a[i]) {
            ans += a[i - 1] - a[i];
            a[i] = a[i - 1];
        }
    }

    std::cout << ans;

    return 0;
}



Measured memory_bytes: 3944
N,M = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(M)]
ab.sort(key=lambda x: x[1])
ans = 0
pos = 0
for i in range(M):
  if pos<ab[i][0]:
    ans+=1
    pos=ab[i][1]-1
print(ans)

Measured memory_bytes: 28588
x, y = map(int, input().split())
money = [300000, 200000, 100000]
if x == 1 and y == 1:
    print(1000000)
elif x <= 3 and y <= 3:
    print(money[x - 1] + money[y - 1])
elif x <= 3:
    print(money[x - 1])
elif y <= 3:
    print(money[y - 1])
else:
    print(0)

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

int main()
{
    string input;
    cin >> input;
    sort(input.begin(), input.end());
    if (input[0] == input[1] && input[2] == input[3]&&input[0]!=input[3])
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3652
#include <iostream>

using namespace std;

int main() {
    double w, h, x, y;
    cin >> w >> h >> x >> y;

    cout << w * h / 2.0 << ' ';
    if (2 * x == w && 2 * y == h)
        cout << "1\n";
    else
        cout << "0\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
pair<int,int>a[200009];
bool cmp(pair<int,int> x,pair<int,int> y) {
	return x.first>y.first;
}
int main() {
	cin>>n;
	for(int i=0;i<n;i++) {
		cin>>a[i].first;
		a[i].second=i;
	}
	sort(a,a+n,cmp);
	for(int i=0;i<n;i++) {
		int j=0;
		while(a[j].second==i) j++;
		cout<<a[j].first<<endl;
	}
	return 0;
}

Measured memory_bytes: 3200
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>; 
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1001001001001001001;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){
    int n; cin >> n;
    vector<ll> A(n); rep(i, n) cin >> A[i];
    if(n==1 || n==2)cout << 1 << ln;
    else{
        int cnt = 1, bef = A[1], up;
        if(A[0]<A[1])up = true;
        else if(A[0]>A[1])up = false;
        else up = -1;
        rept(i, 2, n){
            //cout << cnt << " ";
            int a = A[i];   
            //cout << bef << "->" << A[i] << ln;
            if(up==1 && bef > A[i]){
                up = -1;
                cnt++;
            }else if(up==0 && bef < A[i]){
                up = -1;
                cnt++;
            }else{
                if(bef<A[i])up = true;
                else if(bef>A[i])up = false;
            } 
            bef = A[i]; 
        }
        cout << cnt << ln;
    }
}


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

int main()
{
    int a,b,c,d,e;
    cin>>a>>b>>c;
    d=a-b;
    e=c-d;
    if(e>=0)
    {
        cout<<e<<endl;
    }
    else
    {
        cout<<"0\n";
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <utility>
#include <algorithm>
#include <functional>
#include <deque>
#define INF 1e9
#define MOD 1000000007
#define mod(x) ((x % MOD) + MOD) % MOD
#define MAX_N 2001

using namespace std;

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

int N, K, Q;
int A[MAX_N];
int sorted_A[MAX_N];

int get_max(int a) {

  priority_queue<int, vector<int>, greater<int> > que1;
  priority_queue<int, vector<int>, greater<int> > que;

  for (int j = 0; j < N; j++) {
    if (A[j] >= a) {
      que.push(A[j]);
      continue;
    }
    while (que.size() >= K) {
      que1.push(que.top()); que.pop();
    }
    que = priority_queue<int, vector<int>, greater<int> >();
  }
  while (que.size() >= K) {
    que1.push(que.top()); que.pop();
  }

  if (que1.size() >= Q) {
    for (int i = 1; i < Q; i++) {
      que1.pop();
    }

    return que1.top();
  } else {
    return -1;
  }
}


int main() {
  cin >> N >> K >> Q;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    sorted_A[i] = A[i];
  }

  sort(sorted_A, sorted_A + N);

  int ans = INF;
  for (int i = 0; i < N; i++) {
    int a = sorted_A[i];
    int M = get_max(a);
    if (M != -1) {
      ans = min(ans, M - a);
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <string.h>
#include <cmath>
#include <set>
#include<list>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e9
typedef long long ll;
using namespace std;

int main() {
    int a, b; cin >> a >> b;
    cout << (a+b) / 2 << endl;

    return 0;
}


Measured memory_bytes: 3136
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MOD	1000000007
#define int	long long
#define pii pair<int,int> 
#define vi vector<int>
using namespace std;

int32_t main(){
	int a, b;
	cin >> a >> b;
	if(a >= 1 && a <= 9 && b >= 1 && b <= 9){
		cout << a*b;
	}
	else
		cout << -1;

	return 0;
}



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

ans = 0
left = 0
right = 0
ex = 0
while left <= N-1:
    right = max(left, right)
    while right <= N-1:
        if ex + A[right] == ex ^ A[right]:
            ex += A[right]
            right += 1
        else:
            ex -= A[left]
            break
    ans += right - left
    left += 1
print(ans)


Measured memory_bytes: 25684
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.nextLine());
        int keta = getRigidNum(N);
        int result = 0;
        for (int i = 1; i < keta+1; i++) {
        	if (i % 2 == 1 && i < keta) {
        		result += (nijyou(10, i) - 1) - nijyou(10, i-1) + 1;
        	}else if (i % 2 == 1 && i == keta) {
        		result += N - nijyou(10, i-1) + 1;
        	}
        }


        System.out.println(result);
    }

    private static int getRigidNum(int n) {
    	int i = 1;
    	while (n / nijyou(10, i) > 0) {
    		i++;
    	}
    	return i;
    }

    private static int nijyou(int n, int i) {
    	if (i == 0) {
    		return 1;
    	}
    	else if (i == 1) {
    		return n;
    	}else {
        	return n*nijyou(n, i - 1);
    	}

    }



}

Measured memory_bytes: 21716
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    s = input()
    WORD = 'keyence'

    l = len(s)
    for i in range(l):
        for j in range(i, l):
            if s[:i] + s[j:] == WORD:
                print('YES')
                exit()
    print('NO')
    
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define fi first
#define se second
#define bigger (char)toupper
#define smaller (char)tolower
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef unsigned long long ull;

int main() {
    string A,B;
    cin>>A>>B;
    if(A.size()>B.size()) cout<<"GREATER"<<endl;
    else if(A.size()<B.size()) cout<<"LESS"<<endl;
    else {
        int N=A.size();
        bool ok=true;
        int counter=0;
        for(int i=N-1; i>=0; i--) {
            if(A[i]==B[i]) counter++;
            ok=A[i]>B[i] ? true : false;
        }
        if(counter==N) cout<<"EQUAL"<<endl;
        else if(ok) cout<<"GREATER"<<endl;
        else cout<<"LESS"<<endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5;
#define mst(a) memset(a,0,sizeof a)
vector<int>e[N];
int n,m,ans[N];
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1,u,v;i<=m;i++){
		scanf("%d%d",&u,&v);
		e[u].push_back(v),e[v].push_back(u);
	}
	ans[1]=1;
	queue<int>q;
	q.push(1);
	while(q.size()){
		int u=q.front();q.pop();
		for(auto v:e[u])
			if(!ans[v]) ans[v]=u,q.push(v); 
	}
	puts("Yes");
	for(int i=2;i<=n;i++) printf("%d\n",ans[i]);
	return 0;
} 

Measured memory_bytes: 10532
// Online C++ compiler to run C++ online.
// Write C++ code in this online editor and run it.

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll fun(ll arr[],ll n)
{
    ll dp[n+1];
    dp[0]=dp[1]=0,dp[2]=abs(arr[0]-arr[1]);
    for(int i=3;i<=n;i++){
        ll a=abs(arr[i-1]-arr[i-2])+dp[i-1];
        ll b=abs(arr[i-1]-arr[i-3])+dp[i-2];
        dp[i]=min(a,b);
    }
    return dp[n];
}
int main() {
   ll n;
   cin>>n;
   ll arr[n];
   for(ll i=0;i<n;i++)
     cin>>arr[i];
   cout<<fun(arr,n)<<endl;
    return 0;
}

Measured memory_bytes: 5180
# AOJ ITP1_11_B

# サイコロ。

def intinput():
    a = input().split()
    for i in range(len(a)):
        a[i] = int(a[i])
    return a

class dice:
    def __init__(self):
        self.data = [0 for i in range(8)]
        a = intinput()
        for i in range(1, 7): self.data[i] = a[i - 1]  # 1, 2, 3, 4, 5, 6.
        for i in range(6): self.data[0] += a[i]  # 各位の和を0に。
        self.data[7] = a[0] * a[5] + a[1] * a[4] + a[2] * a[3]  # 対面同士の積の和。
        # dataの1, 2, 3, 4, 5, 6というindexが位置を示す。
        # 回転するとそれらの位置にある数が変化するイメージ。

    def d_read(self, a):
        # aはたとえば5, 1, 2, 6のような配列
        b = []
        for i in range(len(a)): b.append(self.data[a[i]])
        return b

    def d_write(self, b, c):
        # cはたとえば1, 2 ,6, 5のような配列で、そこにbの中身を落とす。
        if len(b) != len(c): return     # 要求と異なる。
        for i in range(len(b)): self.data[c[i]] = b[i]

    def roll(self, direction):
        # directionが'S', 'E', 'W', 'N'.
        # 'S', 'N'では3と4が不変。 'E'と'W'では2と5が不変。
        if direction == ' ': return
        if direction == 'S':
            self.d_write(self.d_read([5, 1, 2, 6]), [1, 2, 6, 5])
            
        elif direction == 'N':
            self.d_write(self.d_read([2, 6, 5, 1]), [1, 2, 6, 5])
            
        elif direction == 'W':
            self.d_write(self.d_read([3, 6, 4, 1]), [1, 3, 6, 4])
            
        elif direction == 'E':
            self.d_write(self.d_read([4, 1, 3, 6]), [1, 3, 6, 4])

    def get_label(self, i):  # i番の面の数を返す。
        return self.data[i]

    def get_index(self, n):  # nが書かれた面のindexを返す。
        for i in range(1, 7):
            if self.data[i] == n: return i
        return 0  # 見つからない場合。

def main():
    d = dice()
    q = int(input())
    command = ["", ' ', 'N', 'W', 'E', 'S', 'S']
    get_ans = [-1, -1, 3, 5, 2, 4]
    for i in range(q):
        x = intinput()
        a = x[0]; b = x[1]
        # aが上面、bが前面。答えるのは右側面。aとbは整数(indexではない).
        upper = d.get_index(a)
        d.roll(command[upper])  # aが上面に来るように回転。
        if upper == 6: d.roll('S')  # 6の場合はもう一回。
        front = d.get_index(b)   # 前面にくる数のindex.
        print(d.get_label(get_ans[front]))  # 答えを出力。

if __name__ == "__main__":
    main()


Measured memory_bytes: 5624
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
int n, k;
vector<vector<int>> G;
struct UF {
    int n, val;
    vector<int> par, siz, cnt;
    unordered_map<int, int> mp;
    UF() {
        n = 0;
        val = 0;
    }
    void add(int v) {
        par.emplace_back(n);
        siz.emplace_back(1);
        cnt.emplace_back(0);
        mp[v] = n;
        ++n;
    }
    int find(int x) {
        if (par[x] == x) {
            return x;
        }
        return par[x] = find(par[x]);
    }
    void unite(int u, int v) {
        if (!mp.count(u)) {
            add(u);
        }
        if (!mp.count(v)) {
            add(v);
        }
        u = mp[u], v = mp[v];
        u = find(u), v = find(v);
        if (u == v) {
            if (cnt[u] == siz[u] - 1) {
                val++;
            }
            cnt[u]++;
            return;
        }
        if (siz[u] < siz[v]) {
            swap(u, v);
        }
        val -= min(cnt[u], siz[u]);
        val -= min(cnt[v], siz[v]);
        siz[u] += siz[v];
        cnt[u] += cnt[v] + 1;
        val += min(cnt[u], siz[u]);
        par[v] = u;
    }
};
UF uf[100000];
vector<P> es[100000];
int id[100000], res[100000];
int merge(int u, int v) {
    u = id[u], v = id[v];
    if (es[u].size() < es[v].size()) {
        swap(u, v);
    }
    for (auto &e : es[v]) {
        uf[u].unite(e.first, e.second);
        es[u].emplace_back(e);
    }
    return u;
}
void dfs(int i, int p) {
    uf[i].unite(es[i][0].first, es[i][0].second);
    id[i] = i;
    int b = i;
    for (auto &e : G[i]) {
        if (e == p) {
            continue;
        }
        dfs(e, i);
        b = merge(b, id[e]);
    }
    res[i] = uf[b].val;
    id[i] = b;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> k;
    G.resize(n);
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    for (int i = 0; i < n; i++) {
        int c, d;
        cin >> c >> d;
        --c;
        --d;
        es[i].emplace_back(P(c, d));
    }
    dfs(0, -1);
    for (int i = 0; i < n; i++) {
        cout << res[i] << endl;
    }
}


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

const int N=2000010;
char s[N];
int a[N];
int main(){
    scanf("%s",s);
    int n=strlen(s);
    long long mmh=1LL*n*(n+1)/2;
    for (int i=0;i<n;i++){
    	a[s[i]]++;
    	mmh-=a[s[i]];
	}
    printf("%lld\n",mmh+1);
}


Measured memory_bytes: 2176
import std.algorithm;
import std.array;
import std.bigint;
import std.bitmanip;
import std.conv;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T diff(T)(const ref T a, const ref T b) { return a > b ? a - b : b - a; }

T[] readToArray(T)() {
    return readln.split.to!(T[]);
}

void readInto(T...)(ref T ts) {
    auto ss = readln.split;
    foreach(ref t; ts) {
        t = ss.front.to!(typeof(t));
        ss.popFront;
    }
}

void main() {
    ulong n;
    readInto(n);
    auto ds = sort(readToArray!(ulong));
    ulong mid = n/2;
    ulong cnt = ds[mid] - ds[mid-1];
    writeln(cnt);
}


Measured memory_bytes: 4416
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#define INF 1000000;

using namespace std;

int main() {
   int a[3];
   for(int i=0; i<3; i++) cin >> a[i];
   cout << a[2] << ' ' << a[0] << ' ' << a[1] << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;

int main()
{
    long long n,m,i,temp1,temp2;
    cin >> n >> m;
    vector<pair<long long,long long>> c;
    for(i = 0;i < n;++i){
        cin >> temp1 >> temp2;
        c.emplace_back(temp1,temp2);
    }
    sort(c.begin(),c.end());
    i = 0;
    long long ans = 0;
    while(m){
        if(m < c.at(i).second){
            ans += c.at(i).first*m;
            break;
        }else{
            ans += c.at(i).first*c.at(i).second;
            m -= c.at(i).second;
            ++i;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2420
import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

N,X,T = LI()

a = N // X
b = N % X

if b == 0:
    print(a*T)
else:
    print((a+1)*T)

Measured memory_bytes: 9184
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
if sum(a)<sum(b):
    print(-1)
    exit()
c = []
s = 0
cnt = 0
for i in range(n):
    if a[i]-b[i]>=0:
        c.append(a[i]-b[i])
    else:
        s+= a[i]-b[i]
        cnt+=1
c = sorted(c)[::-1]
for i in c:
    if s>=0:
        break
    s+=i
    cnt+=1
print(cnt)


Measured memory_bytes: 18356
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

int main(){
    int n,k;
  cin>>n>>k;
  int test=1;
  for(int i=0;i<n;i++){
    if(test>k){
      test=test+k;
    }else{
      test=2*test;
    }
  }
  cout<<test;
    return 0;
}

Measured memory_bytes: 256
from itertools import product
X, Y, Z, K = map(int, input().split())
AB = []
for ab in product(map(int, input().split()), map(int, input().split())):
    AB.append(ab[0] + ab[1])
AB.sort(reverse=True)
AB = AB[:K]
ABC = []
for abc in product(AB, map(int, input().split())):
    ABC.append(abc[0]+abc[1])
ABC.sort(reverse=True)
for i in range(K):
    print(ABC[i])


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

int main() {
    int n,l; cin >> n >> l;
    string s[100];
    rep(i,n) cin >> s[i];
    sort(s,s+n);
    string ans;
    for (const auto& i : s) {
        ans += i;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define f first
#define s second
#define go ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
/*bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
} */
int main()
{
     ll t,v,sum=0,a;
     cin>>t>>a;
     for(int i=0;i<a;i++)
     {
         cin>>v;
         sum+=v;
     }
     if(sum>t)
        cout<<"-1"<<endl;
     else
        cout<<t-sum<<endl;
}


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

int main() {
  int N, A, B, C;
  cin >> N >> A >> B >> C;
  vector<string> S(N);
  for (int i = 0; i < N; i++) cin >> S.at(i);
  
  if (A + B + C == 0) {
    cout << "No" << endl;
  }
  
  else if (A + B + C == 1) {
    string ans = "";
    for (int i = 0; i < N; i++) {
      if (S.at(i) == "AB") {
        if (A == 1) {
          ans += 'B';
          A--;
          B++;
        }
        else if (B == 1) {
          ans += 'A';
          B--;
          A++;
        }
        else {
          ans = "No";
          break;
        }
      }
      else if (S.at(i) == "AC") {
        if (A == 1) {
          ans += 'C';
          A--;
          C++;
        }
        else if (C == 1) {
          ans += 'A';
          C--;
          A++;
        }
        else {
          ans = "No";
          break;
        }
      }
      else {
        if (B == 1) {
          ans += 'C';
          B--;
          C++;
        }
        else if (C == 1) {
          ans += 'B';
          C--;
          B++;
        }
        else {
          ans = "No";
          break;
        }
      }
    }
    if (ans == "No") cout << ans << endl;
    else {
      cout << "Yes" << endl;
      for (int i = 0; i < ans.size(); i++) {
        cout << ans.at(i) << endl;
      }
    }
  }
  
  else {
    string ans = "";
    for (int i = 0; i < N; i++) {
      if (S.at(i) == "AB") {
        if (A == 0 && B == 0) {
          ans = "No";
          break;
        }
        else if (A > B) {
          ans += 'B';
          A--;
          B++;
        }
        else if (B > A) {
          ans += 'A';
          B--;
          A++;
        }
        else {
          if (i < N - 1 && S.at(i + 1) == "AC") {
            ans += 'A';
            B--;
            A++;
          }
          else {
            ans += 'B';
            A--;
            B++;
          }
        }
      }
      else if (S.at(i) == "AC") {
        if (A == 0 && C == 0) {
          ans = "No";
          break;
        }
        else if (A > C) {
          ans += 'C';
          A--;
          C++;
        }
        else if (C > A) {
          ans += 'A';
          C--;
          A++;
        }
        else {
          if (i < N - 1 && S.at(i + 1) == "AB") {
            ans += 'A';
            C--;
            A++;
          }
          else {
            ans += 'C';
            A--;
            C++;
          }
        }
      }
      else {
        if (B == 0 && C == 0) {
          ans = "No";
          break;
        }
        else if (B > C) {
          ans += 'C';
          B--;
          C++;
        }
        else if (C > B) {
          ans += 'B';
          C--;
          B++;
        }
        else {
          if (i < N - 1 && S.at(i + 1) == "AC") {
            ans += 'C';
            B--;
            C++;
          }
          else {
            ans += 'B';
            C--;
            B++;
          }
        }
      }
    }
    if (ans == "No") cout << ans << endl;
    else {
      cout << "Yes" << endl;
      for (int i = 0; i < ans.size(); i++) {
        cout << ans.at(i) << endl;
      }
    }
  }
}

Measured memory_bytes: 6696
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int n;
	cin>>n;
	string s;
	cin>>s;
	int a[4040];
	for(int i=0; i<n; i++){
		if(s[i]=='R') a[i]=0;
		else if(s[i]=='G') a[i]=1;
		else a[i]=2;
	}
	int c[3][4040]={};
	for(int i=0; i<n; i++){
		for(int j=0; j<3; j++) c[j][i+1]=c[j][i];
		c[a[i]][i+1]++;
	}
	ll ans=0;
	for(int i=0; i<n; i++){
		for(int j=i+1; j<n; j++){
			if(s[i]==s[j]) continue;
			int x=3^a[i]^a[j];
			ans+=c[x][i];
			int d=j-i;
			if(i-d>=0 && a[i-d]==x) ans--;
		}
	}
	cout<<ans<<endl;
	return 0;
}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

int main(void){
	int a[3];
	rep(i,3) cin >> a[i];
	sort(a,a+3);
	if(a[0]==5 and a[1]==5 and a[2]==7)
		puts("YES");
	else
		puts("NO");
	return 0;
}

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

int cnt_i[200], cnt_j[200];
int main()
{
    int h, w;
    cin >> h >> w;
    char mass[h][w];
    rep(i, h)
    rep(j, w)
    {
        cin >> mass[i][j];
        if (mass[i][j] == '#')
        {
            cnt_i[i]++;
            cnt_j[j]++;
        }
    }

    rep(i, h)
    {
        if (cnt_i[i] == 0) continue;

        rep(j, w)
        {
            if (cnt_j[j] == 0) continue;
            cout << mass[i][j];
        }
        cout << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop

import collections

n = int(input())
d = [int(input()) for i in range(n)]
d.sort(reverse= True)
cnt = 1
for i in range(n-1):
    if d[i+1] < d[i]:
        cnt+=1
print(cnt)

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

#define f(i, a, b, c) for(int i = a ; i < b ; i += c)
#define fr(i, a, b, c) for(int i = a ; i >= b ; i -= c)
#define fit(it, v) for(auto it = v.begin() ; it != v.end() ; ++it)
#define frit(it, v) for(auto it = v.rbegin() ; it != v.rend() ; ++it)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define eb emplace_back
#define pb push_back
#define lli long long int
#define modn 998244353
#define NL '\n'

using namespace std;

typedef vector< int > vi;
typedef vector< char > vc;
typedef vector< bool > vb;
typedef vector< string > vs;
typedef vector< lli > vli;
typedef vector< vector< char > > vvc;
typedef vector< vector< int > > vvi;
typedef pair< int, int > ii;
typedef vector< ii > vii;
typedef pair< lli, int> pli;
typedef pair< lli, lli> pll;
typedef set< int > si;
typedef set< ii > sii;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	
	#ifdef LOCAL_TEST
		clock_t z = clock();
    	ifstream h("in");
	    ofstream g("out");
	#else
	    #define h cin
	    #define g cout
	#endif // LOCAL_TEST

	lli hr;
	h >> hr;
	int temp = log2(hr);
	lli ans = pow(2, temp + 1) - 1;
	g << ans;

	#ifdef LOCAL_TEST
		cerr << "Time taken is: " << fixed << double(clock() - z) / CLOCKS_PER_SEC << NL;
		h.close();
		g.close();
	#endif // LOCAL_TEST
}




Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <functional>
using namespace std;

typedef pair<int, int> P;

vector<P> edge[100000];
priority_queue<P, vector<P>, greater<P>> que;
int cost[100000];
int V, E, r;
const int INF = 999999999;


int main()
{
	cin >> V >> E >> r;

	for (int i = 0; i < E; i++)
	{
		int from, to, d;
		cin >> from >> to >> d;
		edge[from].push_back(P(to, d));
	}

	for (int i = 0; i < 100000; i++)
	{
		cost[i] = INF;
	}

	cost[r] = 0;
	que.push(P(r, 0));

	while (!que.empty())
	{
		P now = que.top();
		que.pop();

		for (int i = 0; i < edge[now.first].size(); i++)
		{
			int to = edge[now.first][i].first;
			int c = now.second + edge[now.first][i].second;
			if (cost[to] > c)
			{
				cost[to] = c;
				que.push(P(to, c));
			}
		}
	}

	for (int i = 0; i < V; i++)
	{
		if (cost[i] == INF)
		{
			cout << "INF" << endl;
			continue;
		}
		cout << cost[i] << endl;
	}

	return 0;
}

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

using namespace std;

int main() {
    int n, q;
    cin >> n >> q;
    long a[n];
    for (auto &ai:a) cin >> ai;
    int i = (n+1)%2,
        j = n/2;
    long border[n], sum[n];
    sum[j] = 0;
    for (int k=j; k<n; k++) sum[j] += a[k];
    for ( ; j<n-1; j++) {
        sum[j+1] = sum[j] - a[j] + a[i];
        border[j] = (a[i] + a[j]) / 2;
        i += 2;
    }
    border[n-1] = (long)1e9 + 1;
    for (int k=0; k<q; k++) {
        long x;
        cin >> x;
        long ans = lower_bound(border+n/2, border+n, x) - border;
        cout << sum[ans] << '\n';
    }
    return 0;
}

Measured memory_bytes: 3328
import java.math.BigInteger

fun main(args: Array<String>) {
    abc059b()
}

fun abc059b() {
    val a = BigInteger(readLine()!!)
    val b = BigInteger(readLine()!!)

    when {
        a > b -> println("GREATER")
        a < b -> println("LESS")
        else -> println("EQUAL")
    }
}


Measured memory_bytes: 33596
#include "bits/stdc++.h"
using namespace std;
int main()
{
	int n;
	scanf("%d", &n);
	for(long long i = 1, j; ; ++i)
	{
		j = i * (i + 1) / 2;
		if(n == j)
		{
			printf("Yes\n%d\n", i + 1);
			vector<vector<int>> a(i + 1, vector<int>(i, 0));
			int f = 0, o = 1;
			for(; o <= n; )
			{
				for(int k = f; k < i; ++k)
				{
					a[f][k] = o + k - f;
				}
				for(int k = f + 1; k <= i; ++k)
				{
					a[k][f] = o + k - f - 1;
				}
				o += i - f++;
			}
			for(int k = 0; k <= i; ++k)
			{
				printf("%d ", i);
				for(int m = 0; m < i; ++m)
				{
					printf("%d", a[k][m]);
					if(m != i - 1)
					{
						printf(" ");
					}
				}
				printf("\n");
			}
			break;
		}
		else if(n < j)
		{
			printf("No\n");
			break;
		}
	}
}


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

int main() {
  int64_t n;
  std::cin >> n;
  std::vector<std::map<int64_t, int64_t>> t(n, std::map<int64_t, int64_t>());
  for (int64_t i = 0; i < n - 1; i++) {
    int64_t a, b, c;
    std::cin >> a >> b >> c;
    t[a - 1].insert({b - 1, c});
    t[b - 1].insert({a - 1, c});
  }

  int64_t q, k;
  std::cin >> q >> k;
  k--;

  std::vector<int64_t> d(n, 0);
  d[k] = 0;
  std::multimap<int64_t, std::pair<int64_t, int64_t>> queue;
  for (const auto &i : t[k]) {
    queue.insert({i.second, {k, i.first}});
  }

  while (!queue.empty()) {
    const auto &v = *queue.cbegin();
    if (d[v.second.second] == 0) {
      d[v.second.second] = v.first;
      for (const auto &i : t[v.second.second]) {
        queue.insert({d[v.second.second] + i.second,
          {v.second.second, i.first}});
      }
    }
    queue.erase(queue.begin());
  }

  for (int64_t i = 0; i < q; i++) {
    int64_t x, y;
    std::cin >> x >> y;
    std::cout << d[x - 1] + d[y - 1] << std::endl;
  }
  return 0;
}


Measured memory_bytes: 31744
#include<stdio.h>
int main(void)
{
  int left=0,right,up,down=0,x,y,num,a,ans;
  char str[100];
  fgets(str,sizeof(str),stdin);
  sscanf(str,"%d %d %d",&right,&up,&num);
  
  for(int i=0;i<num;i++)
  {
    fgets(str,sizeof(str),stdin);
    sscanf(str,"%d %d %d",&x,&y,&a);
    
    switch(a)
    {
      case 1:
        if(left<x) left=x;
        break;
      case 2:
        if(right>x) right = x;
        break;
      case 3:
        if(down<y) down = y;
        break;
      default:
        if(up > y) up = y;
        break;
    }
  }
  if((right>left)&&(up>down))
  {
    ans = (right-left) * (up-down);
  }else
  {
    ans = 0;
  }
  
  printf("%d",ans);
  
  return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

typedef long long ll;

const int MAX_N = 100;

ll l[MAX_N];

int main() {

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

   int ans = 0;
   for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
         for (int k = j + 1; k < n; k++) {
            if (l[i] == l[j] || l[j] == l[k] || l[i] == l[k]) continue;
            ll biggest = max(max(l[i], l[j]), l[k]);
            ll sumSmaller = l[i] + l[j] + l[k] - biggest;
            if (sumSmaller > biggest) ans++;
         }
      }
   }

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

   return 0;
}


Measured memory_bytes: 1732
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>
#include <climits>
#include <list>
#include <queue>

using namespace std;

static const int INFTY = 2001;

int H;
int A[101];
int NodeNum[101];
int IndexInA[100];


int parent(int i) {
	return i / 2;
}

int left(int i) {
	return 2 * i;
}

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

void minHeapify(int i) {
	int l = left(i);
	int r = right(i);
	int smallest = i;
	if (l <= H && A[l] < A[i]) {
		smallest = l;
	}
	if (r <= H && A[r] < A[smallest]) {
		smallest = r;
	}
	if (smallest != i) {
		int temp = A[i];
		A[i] = A[smallest];
		A[smallest] = temp;
		temp = NodeNum[i];
		NodeNum[i] = NodeNum[smallest];
		NodeNum[smallest] = temp;
		IndexInA[NodeNum[i]] = i;
		IndexInA[NodeNum[smallest]] = smallest;

		minHeapify(smallest);
	}
}

void insert(int d, int nodeNum) {
	int i = ++H;
	A[i] = d;
	NodeNum[i] = nodeNum;
	IndexInA[nodeNum] = i;
	int p = parent(i);
	while (i > 1 && A[p] > A[i]) {
		int temp = A[p];
		A[p] = A[i];
		A[i] = temp;
		temp = NodeNum[p];
		NodeNum[p] = NodeNum[i];
		NodeNum[i] = temp;
		IndexInA[NodeNum[p]] = p;
		IndexInA[NodeNum[i]] = i;
		i = p;
		p = parent(i);
	}
}

int heapExtractMinNodeNum() {
	int minNodeNum = NodeNum[1];
	A[1] = A[H];
	NodeNum[1] = NodeNum[H];
	IndexInA[NodeNum[1]] = 1;
	H--;
	minHeapify(1);

	return minNodeNum;
}

void decrese(int i, int value) {
	A[i] = value;
	int p = parent(i);
	while (i > 1 && A[p] > A[i]) {
		int temp = A[p];
		A[p] = A[i];
		A[i] = temp;
		temp = NodeNum[p];
		NodeNum[p] = NodeNum[i];
		NodeNum[i] = temp;
		IndexInA[NodeNum[p]] = p;
		IndexInA[NodeNum[i]] = i;
		i = p;
		p = parent(i);
	}
}

int main() {
	//int Dist[101];
	int Dist[100];
	int AdjacenceyList[100][100];
	int AdjacenceyWeightList[100][100];
	int Degree[100];
	int i, j;
	int N;
	int W;
	int Deg;
	int MinTotalWeight = 0;
	int u, v;
	bool inT[100];

	cin >> N;

	for (i = 0; i < N; i++) {
		inT[i] = false;
		Dist[i] = INFTY;
		Deg = -1;
		for (j = 0; j < N; j++) {
			cin >> W;
			if(W != -1){
				AdjacenceyList[i][++Deg] = j;
				AdjacenceyWeightList[i][Deg] = W;
			}
		}
		Degree[i] = Deg + 1;
	}
	//Dist[100] = INFTY;



	H = 0;
	u = 0;
	inT[u] = true;
	Dist[u] = 0;
	for (i = 1; i <= N - 1; i++) {
		for (j = 0; j < Degree[u]; j++) {
			v = AdjacenceyList[u][j];
			if (inT[v] == false) {
				W = AdjacenceyWeightList[u][j];
				if (Dist[v] == INFTY) {
					Dist[v] = W;
					insert(W, v);
				}
				else if (W < Dist[v]) {
					Dist[v] = W;
					decrese(IndexInA[v], W);
				}
			}
		}

		int minNodeNum = heapExtractMinNodeNum();
		inT[minNodeNum] = true;
		MinTotalWeight += Dist[minNodeNum];
		u = minNodeNum;

	}

	printf("%d\n", MinTotalWeight);

	return 0;
}

Measured memory_bytes: 1224
import sys
def I(): return int(sys.stdin.readline())
def LI(): return [int(x) for x in sys.stdin.readline().split()]

def main():
    N,M = LI()
    WA = [0] * N
    AC = [False] * N

    for _ in range(M):
        P,S = input().split()
        p = int(P)-1
        if S == 'AC':
            AC[p] = True
        if not(AC[p]):
            WA[p] += 1

    for i in range(N):
        if not(AC[i]):
            WA[i] = 0
    print(sum(AC),sum(WA))


if __name__ == "__main__":
    main()


Measured memory_bytes: 46936
#include<bits/stdc++.h>
using namespace std;
int main(){
    int s;
    cin>>s;
    int arr[1000001];
    arr[1]=s;
    for(int i=2;i<1000001;i++){
        if (arr[i-1]%2==0){
            arr[i]=arr[i-1]/2;
        }
        else if (arr[i-1]%2==1){
            arr[i]=(arr[i-1]*3)+1;
        }
    }
    for(int i=2;i<1000001;i++){
        for(int j=0;j<i;j++){
            if (arr[i]==arr[j]){
                cout<<i<<endl;
    return 0;
            }
        }
    }
}

Measured memory_bytes: 7500
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  string s, t;
  cin >> s >> t;
  for (int i = 0; i < (int) s.size(); i++) {
    if (s[i] != t[i]) {
      cout << "No\n";
      return 0;
    }
  }
  cout << "Yes\n";
  return 0;
}

Measured memory_bytes: 3636
H, W, K = gets.chomp.split(" ").map(&:to_i)
C = []
H.times{
  C << gets.chomp.chars
}

ans = 0
(0...(1<<H)).each{|i|
  (0...(1<<W)).each{|j|
    wk = 0
    (0...H).each{|x|
      (0...W).each{|y|
        wk += 1 if i[x] == 1 && j[y] == 1 && C[x][y] == '#'
      }
    }
    ans += 1 if wk == K
  }
}

puts ans


Measured memory_bytes: 14324
N = int(input())
A = list(map(int,input().split()))
A = [0] + A + [0]
B  = [abs(A[i] - A[i+1]) for i  in range(len(A)-1)]
sum = sum(B)
for i in range(N):
    ans = sum - B[i] - B[i+1] + abs(A[i+2]-A[i])
    print(ans)

Measured memory_bytes: 14176
n = int(input())
A = list(map(int, input().split()))
ans = A[0]
i = 1
if 0 in A:
    print(0)
else:
    while (i < n) and (ans <= 10**18):
        ans *= A[i]
        i += 1
    if (ans <= 10**18) and i == n:
        print(ans)
    else:
        print(-1)

Measured memory_bytes: 21792
import java.util.*;
import static java.lang.Math.*;

public class Main {

	// 定数
	static final String a  = "dream";
	static final String b  = "dreamer";
	static final String c  = "erase";
	static final String d  = "eraser";

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

		// 入力
		String s = sc.next();// 文字列

		// チェック
		String result = "";

		if(check(s)){
			result = "YES";
		}else{
			result = "NO";
		}

		// 出力
		System.out.println(result);
	}

	static boolean check(String s){
		return s.matches("(dream|dreamer|erase|eraser)+");
	}

}




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

map <long long, long long> X, Y;
vector <vector <long long>> adjx, adjy;
vector <bool> markx, marky;

pair <long long, long long> dfs(bool f, long long v){
	long long ans[2] = {0, 0};
	ans[f] ++;
	if (!f)
		markx[v] = true;
	else
		marky[v] = true;
	if (!f)
	for (auto u: adjx[v]){
		if (!f && !marky[u]){
			auto Y = dfs(!f, u);
			ans[0] += Y.first;
			ans[1] += Y.second;
		}
		if (f && !markx[u]){
			auto Y = dfs(!f, u);
			ans[0] += Y.first;
			ans[1] += Y.second;
		}
	}
	else
	for (auto u: adjy[v]){
		if (!f && !marky[u]){
			auto Y = dfs(!f, u);
			ans[0] += Y.first;
			ans[1] += Y.second;
		}
		if (f && !markx[u]){
			auto Y = dfs(!f, u);
			ans[0] += Y.first;
			ans[1] += Y.second;
		}
	}
	return {ans[0], ans[1]};
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, k;
	cin >> n >> k;
	if (k > (n - 1) * (n - 2) / 2){
		cout << -1;
		return 0;
	}
	int ans = (n - 1) * (n - 2) / 2;
	cout << n - 1 + ans - k << '\n';
	for (int i = 2; i <= n; i++){
		cout << "1 " << i << '\n';
	}
	for (int i = 2; i <= n; i++){
		for (int j = i + 1; j <= n; j++){
			if (ans == k)
				break;
			cout << i << ' ' << j << '\n';
			ans --;
		}
	}
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int a[100][100];
    int b[100];
    int n, m;
    int i, j, d;
    int ans;
    
    scanf(" %d %d", &n, &m);
    for(i = 0; i < n; i++){
        for(j = 0; j < m; j++){
            scanf(" %d", &d);
            a[i][j] = d;
        }
    }
    
    for(j = 0; j < m; j++){
        scanf("%d", &d);
        b[j] = d;
    }
    
    for(i = 0; i < n; i++){
        for(j = 0; j < m; j++){
            ans += (a[i][j] * b[j]);
        }
        printf("%d\n",ans);
        ans = 0;
    }
     return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Main mainObj = new Main();
		mainObj.solve();
	}
	
	public void solve() {
		
		Scanner sc = new Scanner(System.in);
		String sequence = sc.nextLine();
		sc.close();
		
		
		int rCount = 0;
		int lCount = 0;
		int[] childCntArr = new int[2];
		
		StringBuilder resultBuilder = new StringBuilder();
		
		int childCnt = 0;
		
		// 0 or 1 
		int rIndex = 0;
		// 0 or 1
		int lIndex = 0;
		
		char beforeChar = 'R';
		childCntArr[0] = 1;
		childCnt++;
		rCount++;
		
		for(int i = 1; i < sequence.length(); i++) {
			if(sequence.charAt(i) == 'R') {
				if(beforeChar == 'L') {
					
					resultBuilder.append(makeSubStr(rCount, lCount, childCntArr, rIndex, lIndex).toString());
					rCount = 1;
					lCount = 0;
					childCntArr[0] = 1;
					childCntArr[1] = 0;
					childCnt = 1;
					
				}else {
					
					rCount++;
					childCntArr[childCnt % 2]++;
					childCnt++;
					
				}
				beforeChar = 'R';
			}else if(sequence.charAt(i) == 'L') {
				if(beforeChar == 'R') {
					
					rIndex = (childCnt + 1) % 2;
					lIndex = childCnt % 2;
					childCntArr[childCnt % 2]++;
					childCnt++;
					lCount++;
					
				}else {
					
					childCntArr[childCnt % 2]++;
					childCnt++;
					lCount++;
					
				}
				beforeChar = 'L';
			}
		}
		
		resultBuilder.append(makeSubStr(rCount, lCount, childCntArr, rIndex, lIndex).toString());
		System.out.println(resultBuilder.substring(0, resultBuilder.length() - 1));
  	}
	
	public StringBuilder makeSubStr(int rCount, int lCount, int[] childCntArr, int rIndex, int lIndex) {
		
		StringBuilder retBuilder = new StringBuilder();
		for(int i = 0; i < rCount - 1; i++) {
			retBuilder.append("0 ");
		}
		retBuilder.append(childCntArr[rIndex]+" ");
		retBuilder.append(childCntArr[lIndex]+" ");
		for(int i = 0; i < lCount - 1; i++) {
			retBuilder.append("0 ");
		}
		
		//System.out.println(retBuilder.toString());
		return retBuilder;
		
	}
}


Measured memory_bytes: 39112
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;

int main() {
    int n;
    cin >> n;
    int ans = 0;
    auto cnt = [](int n) {
        int ret = 0;
        while(n > 0) {
            ret++;
            n /= 10;
        }
        return ret;
    };
    rep2(i,1,n+1) {
        if(cnt(i)%2 == 1) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
const int N=1e6+10;
int main()
{
    FASTINOUT;
    int q;
    cin>>q;
    map<string,int>m;
    bool b=true;
    string s,last="?";
    cin>>s;
    m[s]=1;
    last=s;
    q--;
    while (q--){
        cin>>s;
        if (m[s])
        b=false;
        if (last.back()!=s.front())
            b=false;
        m[s]=1;
        last=s;
    }
    cout<<(!b?"No\n":"Yes\n");
    return 0;
}


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

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

int main(void) {
    int n, x, ans = 0;

    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> x;
    vector<int> l(n), d(n + 1);
    d[0] = 0;
    REP(i, n) {
        cin >> l[i];
        d[i + 1] = d[i] + l[i];
    }
    REP(i, n + 1) {
        if (d[i] <= x) {
            ans++;
        }
    }

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

Measured memory_bytes: 256
#include <stdio.h>

int N,M,X,A[12][12],C[12];

int main()
{
    int sum_p=0,sum_m=2e8,sum_m_new=0,u=0;
    scanf("%d %d %d",&N,&M,&X);
    for(int i=0;i<N;i++){
	scanf("%d",&C[i]);
	for(int j=0;j<M;j++)
	    scanf("%d",&A[i][j]);
    }
    for(int i=0;i<2;i++){
	for(int j=0;j<2;j++){
	    for(int k=0;k<2;k++){
		for(int l=0;l<2;l++){
		    for(int m=0;m<2;m++){
			for(int n=0;n<2;n++){
			    for(int o=0;o<2;o++){
				for(int p=0;p<2;p++){
				    for(int q=0;q<2;q++){
					for(int r=0;r<2;r++){
					    for(int s=0;s<2;s++){
						for(int t=0;t<2;t++){
						    sum_m_new=i*C[0]+j*C[1]+k*C[2]+l*C[3]+m*C[4]+n*C[5]+o*C[6]+p*C[7]+q*C[8]+r*C[9]+s*C[10]+t*C[11];
						    for(u=0;u<M;u++){
							sum_p=i*A[0][u]+j*A[1][u]+k*A[2][u]+l*A[3][u]+m*A[4][u]+n*A[5][u]+o*A[6][u]+p*A[7][u]+q*A[8][u]+r*A[9][u]+s*A[10][u]+t*A[11][u];
							if(sum_p<X)
							    break;
						    }

						    if(u==M && sum_m_new<sum_m)
							sum_m=sum_m_new;
						}
					    }
					}
				    }
				}
			    }
			}
		    }
		}
	    }
	}
    }

    if(sum_m==2e8)
	puts("-1");
    else 
	printf("%d\n",sum_m);

    return 0;
}






Measured memory_bytes: 1732
n=int(input())
a=list(map(int,input().split()))
q=int(input())

bc=[map(int,input().split()) for _ in range(q)]
b,c=[list(i) for i in zip(*bc)]
a.sort
count=[0 for _ in range(1000000)]
sum=0
for i in range(n):
  count[a[i]]=count[a[i]]+1
  sum=sum+a[i]
for i in range(q):
  sum=sum+(c[i]-b[i])*count[b[i]]
  print(sum)
  count[c[i]]=count[c[i]]+count[b[i]]
  count[b[i]]=0


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

int main(){
	int A,B,C,K;
	cin >> A >> B >> C >> K;
	
	ll ans = 0;
	if(A+B<K){
		ans = A;
		ans -= (K-A-B);
	}else{
		ans = min(A,K);
	}

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

Measured memory_bytes: 3624
#include <iostream>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
const int MOD = 1000000007;

int main(){
  int N;
  cin >> N;
  int count = 0;
  for(int i=N;i>=1;i--) {
    if((int)(log(i)/log(10)+0.0000001)%2 == 0) count++;
  }
  cout << count;  
}


Measured memory_bytes: 256
num_v,num_e=input().split()

edges=[]
verticies=[]

for i in range(int(num_e)):
    v,u,w=input().split()
    e=(v,u,int(w))
    edges.append(e)


for v in range(int(num_v)):
    v=str(v)
    verticies.append(v)

#for i in range(num_e):
#    e=(e_list[i*3],e_list[i*3+1],int(e_list[i*3+2]))
#    edges.append(e)

graph={
    'verticies':verticies,
    'edges':edges
}


parent={}
g_len={}

def group(v):
    parent[v]=v
    g_len[v]=0

def my_parent(v):
    if parent[v]!=v:
        parent[v]=my_parent(parent[v])
    return parent[v]
    
    
def union(v, u): 
    g_v=my_parent(v)
    g_u=my_parent(u)
    if g_v != g_u:
        if g_len[g_v] >= g_len[g_u]:
            parent[g_u]=parent[g_v]
            g_len[g_v] +=1
        else:
            parent[g_v]=parent[g_u]
            g_len[g_u] +=1
            

def kruskal(graph):
    g_list=[]
    sum_w=0
    
    for v in graph['verticies']:
        group(v)
        
    edges=graph['edges']
    edges.sort(key=lambda edges:edges[2])
    
    for edge in edges:
        v, u, weight =edge
        
        if my_parent(v) != my_parent(u):
            union(v,u)
            g_list.append(edge)
            sum_w=sum_w + weight
            
    return sum_w
    

print(kruskal(graph))


Measured memory_bytes: 30372
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
v = LIST()
v.sort()
ans = v[0]

for x in v:
	ans = (ans+x)/2

print(ans)

Measured memory_bytes: 5144