akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

// Aの下からKbit目(0-indexed)を返す
inline int kthbit(int A, int K) { return (A >> K) & 1; }

// Aの下からKbitを取り出す
inline int mask(int A, int K) { return A & ((1 << K) - 1); }

// wbit整数Aをkbitだけ左に回す
// kが負なら右に回す
inline int slide(int A, int w, int k) {
    if (k >= 0) {
        return (mask(A, w - k) << k) + (A >> (w - k));
    } else {
        return (A >> (-k)) + (mask(A, -k) << (w - (-k)));
    }
}

// [0, 2^N)全体を回るようなサイクル(グレイコード)を作る
vector<int> cycle(int N) {
    static vector<int> dp[20];

    if (N == 0) return {0};
    if (!dp[N].empty()) return dp[N];

    // 1つ下のグレイコードを求める
    vector<int> head = cycle(N - 1);
    vector<int> tail = head;

    // 一方を反転させ、先頭bitを変えてくっつける
    reverse(tail.begin(), tail.end());
    for (int& t : tail) t |= (1 << (N - 1));

    copy(tail.begin(), tail.end(), back_inserter(head));
    return dp[N] = head;
}

vector<int> solve(int A, int B, int N) {
    if (N == 1) return {A, B};

    int k;
    for (k = 0; k < N; ++k) {
        if (kthbit(A, N - 1 - k) != kthbit(B, N - 1 - k)) break;
    }
    // 先頭bitが異なるように、左にkだけslideする
    A = slide(A, N, k), B = slide(B, N, k);

    // bit長N-1のグレイコード
    vector<int> head = cycle(N - 1);
    for (int& a : head) a ^= A;

    // 末尾からBまでの答えをマージする
    vector<int> tail = solve(mask(head.back(), N - 1), mask(B, N - 1), N - 1);
    // 先頭bitをBと一致させる
    for (int& a : tail) a ^= B & (1 << (N - 1));
    copy(tail.begin(), tail.end(), back_inserter(head));

    // kだけ右に回して元に戻す
    for (int& a : head) a = slide(a, N, -k);
    return head;
}

int main() {
    int N, A, B;
    cin >> N >> A >> B;

    if (__builtin_popcount(A ^ B) % 2 == 0) {
        cout << "NO" << endl;
        return 0;
    }

    cout << "YES" << endl;
    auto ans = solve(A, B, N);

    for (auto a : ans) cout << a << " ";
    cout << endl;
    return 0;
}


Measured memory_bytes: 2320
#include <iostream>
#define MAX_NUM 10000

using namespace std;

int inputnumber(int *n){
	cin >> *n;
	return 0;
}

int inputnumbers(int n,int *x){
	for(int i=0;i<n;i++){
		cin >> *(x+i);
	}
	return 0;
}


int printdata(int n, int *x){
	for(int i=0;i<n-1;i++)
		cout << *(x+i) << ' ';
	cout << *(x+n-1) << endl;
	return 0;
}

int insertion(int n,int val,int *x){
	int j=n-1;
	while(j>=0 && *(x+j)>val){
		//cout << *(x+j+1) << ' ' << *(x+j) << " val=" << val << endl;
		*(x+j+1)=*(x+j);
		j--;
	}
	*(x+j+1)=val;
	return 0;
}

int insertionSort(int n, int *x){
	for(int i=1;i<n;i++){
		insertion(i,*(x+i),x);
		printdata(n,x);
	}

	return 0;
}


int main() {
	int n, x[MAX_NUM];

	inputnumber(&n);
	inputnumbers(n, x);
	printdata(n,x);
	insertionSort(n, x);


	return 0;
}



Measured memory_bytes: 3096
#include <iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include <iomanip>
using namespace std;

int main(){
    int a,b;
    cin>>a>>b;
    if(a<=5){
        cout<<"0"<<endl;
        return 0;
    }else if(a<13){
        cout<<b/2<<endl;
        return 0;
    }else{
        cout<<b<<endl;
        return 0;
    }
}

Measured memory_bytes: 256
N,D = map(int,input().split())
X = []
for i in range(N):
  x = list(map(int,input().split()))
  X.append(x)
Count = 0
for i in range(N-1):
  for j in range(i+1,N):
    k = 0
    for t in range(D):
      k += (X[i][t]-X[j][t])**2
    k = k**(1/2)
    if k == int(k):
      Count += 1
print(Count)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ull uint64_t
#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mx5 100005
#define mx6 1000005
#define mod 1000000007
#define nfs ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;


void dfs (int u, bool vis[], vector < vector <int> >& gr, int dp[]) {
    vis[u] = 1;
    for (int v:gr[u]) {
        if (!vis[v]) {
            dfs(v, vis, gr, dp);
        }
        dp[u] = max(dp[u], dp[v] + 1);
    }
}

int main() {
    nfs
    int n, m, dp[mx5] = {}, ans = 0;
    bool vis[mx5] = {};
    vector < vector <int> > gr(mx5);

    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        gr[u].pb(v);
    }

    for (int i = 1; i <= n; i++) {
        if(!vis[i]) {
            dfs(i, vis, gr, dp);
            ans = max(ans, dp[i]);
        }
    }
    cout <<  ans;
}

Measured memory_bytes: 12548
#import sys
#input = sys.stdin.buffer.readline
#input = sys.stdin.readline

# mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
# import numpy as np


def main():
	n=int(input())
	s=[]
	t=[]
	for i in range(n):
		a,b=input().split()
		s.append(a)
		t.append(int(b))
	x=input()
	for i in range(n):
		if x==s[i]:
			ans=sum(t[i+1:])
			print(ans)
			exit(0)


if __name__ == "__main__":
	main()


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

int main(){
    int a,b,c,x,y,i,tmp=0,ans=0;
    cin >> a >> b >> c >> x >> y;
    for(i=0;i<=max(x,y);i++){
        tmp = 2*c*i + a*max(x-i,0) + b*max(y-i,0);
        if(i==0){ans=tmp;}
        else {if(ans>tmp)ans=tmp;}
        tmp=0;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
typedef pair<int,int> P; typedef pair<Int,Int> Pl;
const int mod = 1e9+7;
#define END {cout<<ans<<'\n'; return 0;}
#define ALL(v) v.begin(),v.end()
#define Pr(type) priority_queue<type>
#define gPr(type) priority_queue<type,vector<type>,greater<type>>
#define V(type) vector<type>
#define rep(i,n) for(int i=0; i<n; i++)
#define rer(i,st,en) for(int i=st; i<en; i++)
#define eb emplace_back
#define pri1(a) cout<<a<<'\n'
#define pri2(a,n) rep(i,n)cout<<a[i]<<'\n'
#define pri3(a,n) rep(i,n-1)cout<<a[i]<<' '; cout<<a[n-1]<<'\n'
template<class T> inline bool cmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool cmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



double n,m,_,x,y,q;
string s,sb;
bool ok;

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

  cin>>n>>m>>q;
  cout<<setprecision(7)<<(q?(n-q)*2/(n*n):1/n)*(m-1)<<'\n';
}

Measured memory_bytes: 256
let n = Scanf.sscanf (read_line ()) "%d" @@ fun n -> n

let arr = Array.make 10001 0

let () =
  for i = 1 to 500 do
    for j = 1 to 500 do
      for k = 1 to 500 do
        let t = i * i + j * j + k * k + i * j + j * k + k * i in
        if t <= 10000 then arr.(t - 1) <- arr.(t - 1) + 1;
      done
    done
  done;
  for i = 1 to n do
    Printf.printf "%d\n" arr.(i - 1)
  done

Measured memory_bytes: 5524
/*
 * Pawan Harendra Mishra
 */

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

#define X first
#define Y second
typedef long long ll;
typedef pair<ll,ll> pll;

int main(int argc, char const *argv[])
{
    //ios::sync_with_stdio(false);
    //cin.tie(NULL);

    unordered_map<string, ll> m({
        {"Sunny", 0}, {"Cloudy", 1}, {"Rainy", 2}
    });
    string s, n[] = {"Sunny", "Cloudy", "Rainy"};

    cin >> s;
    ll q = m[s];
    cout << n[(q+1)%3] << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define mp(a,b) make_pair(a,b)
#define pb(x) push_back(x)
const ll mod = 1e9 + 7;
ll inf = 1e16;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)

int main()
{
   fastio;
   string s1,s2;
   cin>>s1>>s2;
   int m,n;
   m = s1.length(), n = s2.length();
   int dp[m+1][n+1];
   for(int i=0;i<=m;++i){
   	for(int j=0;j<=n;++j){
   		 if(i==0||j==0){
   		 	dp[i][j] = 0;
			}else{
				if(s1[i-1]==s2[j-1]){
					dp[i][j] = 1 + dp[i-1][j-1];
				}else{
				  dp[i][j] = max(dp[i-1][j], dp[i][j-1]);	
				}
			}
	   }
   }
   //cout<<dp[m][n]<<endl;
   string ans = "";
   int i = m;
   int j = n;
   while(i>0 && j>0){
   	   if(s1[i-1]==s2[j-1]){
   	   	    ans = s1[i-1] + ans;
   	   	    i-=1;
   	   	    j-=1;
		  }else{
		  	 if(dp[i-1][j]> dp[i][j-1]){
		  	 	i = i-1;
			   }else{
			   	j = j-1;
			   }
		  }
   }
   cout<<ans<<endl;
   
	return 0;
}



Measured memory_bytes: 38852
import math
elements = [int(x) for i in range(5) for x in input().split()]
sum = 0
elements = sorted(elements,key=lambda x: x%10 if(x%10==0) else 10-x%10)
for i in range(len(elements)):

    if(elements[i]%10 == 0 or i == 4):
        sum+= elements[i]
    else:
        sum+= elements[i] + 10 - elements[i]%10
print(sum)




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

int main() {
  ll X;
  string ans;
  cin >> X;
  
  if(X>=30) ans="Yes";
  else ans="No";
 
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3524
#include <bits/stdc++.h>
using namespace std;
struct ios_accelerate { ios_accelerate() { ios::sync_with_stdio(false); cin.tie(nullptr); } } CALL;

#define REP(i, n) for(auto (i) = (n)*0; (i) < (n); (i)++)
#define RNG(i, a, b) for(auto (i) = (a); (i) < (b); (i)++)
#define RBF(i, v) for(auto& (i) : (v))
#define ALL(x) (x).begin(), (x).end()

using LL = long long;
using UL = unsigned long;
using ULL = unsigned long long;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
template<typename T> using P = pair<T, T>;

const double PI = 3.141592653589793;
const int MOD = 1000000007;
const LL INF64 = static_cast<LL>(1e18) + 2;
const int INF = static_cast<int>(1e9) + 2;

template<typename T> inline void upsort(vector<T>& x) { sort(x.begin(), x.end()); }
template<typename T> inline void downsort(vector<T>& x) { sort(x.begin(), x.end(), greater<T>()); }
template<typename T> inline void col(T x) { cout << x << '\n'; }
template<> inline void col(double x) { cout << fixed << setprecision(12) << x << '\n'; }

int64_t mod_pow(int64_t x, int64_t n, int64_t mod) {
	int64_t res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % mod; // 最下位ビットが立っているときにx^(2^i)をかける
		x = x * x % mod;
		n >>= 1;
	}
	return res;
}

std::vector<int64_t> inv, fact_inv, com;
void combination_init(int64_t k_max, int64_t mod, int64_t n = -1) {
	int64_t size = k_max + 5;
	inv = std::vector<int64_t>(size);
	fact_inv = std::vector<int64_t>(size);
	inv[1] = 1;
	fact_inv[0] = fact_inv[1] = 1;
	for (int64_t i = 2; i < size; i++) {
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
	}
	if (n >= 0) {
		com = std::vector<int64_t>(size);
		com[0] = 1;
		for (int64_t i = 1; i < size; i++) {
			com[i] = com[i - 1] * ((n - i + 1) * inv[i] % mod) % mod;
		}
	}
}
int64_t combination(int64_t n, int64_t k, int64_t mod) {
	if (inv.empty()) {
		combination_init(k, mod);
	}

	int64_t ans = 1;
	for (int64_t i = n; i >= n - k + 1; i--) {
		ans *= i;
		ans %= mod;
	}
	return ans * fact_inv[k] % mod;
}

signed main() {
	LL n, a, b;
	cin >> n >> a >> b;

	LL ans = mod_pow(2, n, MOD);
	LL ncb = combination(n, b, MOD);
	LL nca = combination(n, a, MOD);
	ans = ans - nca - ncb - 1;
	while (ans < 0) {
		ans += MOD;
	}

	col(ans);
	return 0;
}


Measured memory_bytes: 6332
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define all(a) (a).begin(),(a).end()
#define lb(s,x) lower_bound(all(s),x)-s.begin()
#define ub(s,x) upper_bound(all(s),x)-s.begin()
#define uniq(a) a.erase(unique(all(a)),a.end())
#define debug(x) cout<<#x<<": "<<x<<endl
template<class T,class U>
ostream& operator<<(ostream& o, const pair<T,U> &p){
    o<<"("<<p.first<<", "<<p.second<<")";
    return o;
}
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
typedef long long ll;
const int INF = 1e9;

char solve(){
    string s;
    ll k;
    cin>>s>>k;
    if(k==1) return s[0];
    int n = s.size();
    if(n<k){
        rep(i,n){
            if(s[i]!='1') return s[i];
        }
    }else{
        rep(i,k){
            if(s[i]!='1') return s[i];
        }
    }
    return '1';
}
int main(void){
    cout<<solve()<<endl;
    return 0;
}


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

int main() {

  string S;
  cin>>S;
  
  for(int i=0;i<S.size();i++)
    for(int j=i+1;j<S.size();j++)
      if(S.at(i)!=S.at(j)) continue;
      else {cout <<"no"<< endl;return 0;}
  cout <<"yes"<< endl;
}

Measured memory_bytes: 256
class Battle:
    def __init__(self, A, B, C, D):
        self.A = A
        self.B = B
        self.C = C
        self.D = D

    def result(self):
        while self.A > 0 or self.C > 0:
            self.C -= self.B
            if self.C <= 0:
                return "Yes"
            self.A -= self.D
            if self.A <= 0:
                return "No"


def atc_164b(ABCD: str) -> str:
    A, B, C, D = map(int, ABCD.split(" "))
    battle = Battle(A, B, C, D)
    return battle.result()


ABCD_input = input()
print(atc_164b(ABCD_input))


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

using namespace std;

int main(void) {
    vector< vector<int> > A(3, vector<int>(3));
    vector< vector<int> > ans(3, vector<int>(3));
    for(int i=0; i<3; i++) {
        for(int j=0; j<3; j++) {
            cin >> A[i][j];
        }
    }
    int N;
    cin >> N;
    while(N--) {
        int b;
        cin >> b;
        for(int i=0; i<3; i++) {
            for(int j=0; j<3; j++) {
                if(A[i][j] == b) {
                    ans[i][j] = 1;
                }
            }
        }
    }

    bool flag = false;
    for(int i=0; i<3; i++) {
        int cnt = 0;
        for(int j=0; j<3; j++) {
            cnt += ans[i][j];
        }
        if(cnt == 3) {
            flag = true;
        }
    }
    for(int i=0; i<3; i++) {
        int cnt = 0;
        for(int j=0; j<3; j++) {
            cnt += ans[j][i];
        }
        if(cnt == 3) {
            flag = true;
        }
    }

    if(ans[0][0] + ans[1][1] + ans[2][2] == 3) {
        flag = true;
    }
    if(ans[0][2] + ans[1][1] + ans[2][0] == 3) {
        flag = true;
    }

    if(flag) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import sys
n = int(input())
a = list(map(int, input().split()))
b = [0 for _ in range(n)]

for i in range(n) :
  j = n - (i+1)
  if j == 0 :
    if a[0] == 1 and sum(b)%2 == 0 :
      b[0] = 1
    if a[0] == 0 and sum(b)%2 == 1 :
      b[0] = 1
  elif n//(j+1) == 1 :
    if a[j] == 1 :
      b[j] = 1
  else :
    k = 2
    b_sum = 0
    while n >= k*(j+1) :
      b_sum += b[k*(j+1)-1]
      k += 1
    if a[j] == 1 and b_sum%2 == 0 :
      b[j] = 1
    if a[j] == 0 and b_sum%2 == 1 :
      b[j] = 1
      
print(sum(b))

ans = []
if sum(b) != 0 :
  for i in range(n) :
    if b[i] == 1 :
      ans.append(str(i+1))
  print(*ans)

Measured memory_bytes: 17208
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int> h(n), dp(n);
    for (auto & x : h)
        cin >> x;
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    for (int i = 2; i < n; ++i)
        dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]),
                    dp[i - 2] + abs(h[i] - h[i - 2]));
    cout << dp[n - 1] << endl;
}


Measured memory_bytes: 1024
S = list(input())
k = 0
N = len(S)
mod = 10**9+7

for i in range(N):
    if S[i] == "0":
        k += 1
    else:
        break

dp = [ [0]*13 for _ in range(N+1)]
dp[k][0] = 1

for i in range(k+1,N+1):
    for j in range(13):
        for l in range(10):
            if S[i-1] == "?" or S[i-1] == str(l):
                dp[i][(j*10+l)%13] += dp[i-1][j]
                dp[i][(j*10+l)%13] = dp[i][(j*10+l)%13] % mod
print(dp[N][5])

Measured memory_bytes: 65400
#include <cstdio>
#include <algorithm>
#include <array>
#include <vector>
#include <iostream>

using namespace std;

int main() {

  const array<int, 6> coins = { 500, 100, 50, 10, 5, 1 };

  while(true) {
    int n;
    cin >> n;
    if ( n == 0 ) break;

    n = 1000 - n;
    int count = 0;
    for ( auto coin : coins ) {
      if ( n >= coin ) {
    	count += (n / coin);
    	n %= coin;
      }
    }
    cout << count << endl;
  }
  return 0;  
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define dump(x) cout << #x << " = " << (x) << endl;
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<tuple<string, int, int>> a;
  for(int i = 1; i <= N; i++) {
    string s;
    int p;
    cin >> s >> p;
    p = -p;
    a.emplace_back(s, p, i);
  }
  sort(a.begin(), a.end());
  for(auto x : a) {
    string s;
    int p, id;
    tie(s, p, id) = x;
    cout << id << endl;
  }
  return 0;
}

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

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
		String strN = bufferedReader.readLine();
		int n = Integer.parseInt(strN);
		int a = n;
		while(a>0) {
			if((int) Math.sqrt(a) == Math.sqrt(a)) {
				break;
			}
			a--;
		}

		System.out.println(a);

	}

}


Measured memory_bytes: 21332
n,m=map(int,input().split())
## DAG graph , making using dict
in_degree=[0]*n ## number of incoming edges 
graph = {} ## graph [ u ] defines edge from u to v
for i in range(m):
    u, v=map(int,input().split()) 
    if u not in graph:
        graph[u]=[v]
    else :
        graph[u].append(v)
    in_degree[v-1]+=1
dist=[0]*n
curr_stack=[] ## starting from nodes with 0 incoming edges
for i in range(n):
    if in_degree[i]==0:
        curr_stack.append(i+1)
def dfs (curr_stack):
    while curr_stack:
        u=curr_stack.pop()
        if u not in graph:
            continue
        for item in graph[u]:
            dist[item-1]=max(dist[item-1],dist[u-1]+1)
            in_degree[item-1]-=1
            if in_degree[item-1]==0:
                curr_stack.append(item)
dfs(curr_stack)
print(max(dist))



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

int main(){
    int n,tmp;
    cin >> n;

    tmp = n;
    int sum=0;
    while(tmp){
        sum += tmp%10;
        tmp /= 10;
    }

    string ans = n % sum ? "No" : "Yes";
    cout << ans << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // std::ifstream in("input.txt");
    // std::cin.rdbuf(in.rdbuf());
    ll n;
    cin >> n;
    if (n % 2 == 1) {
        cout << 0 << endl;
        return 0;
    }
    ll cnt = 0;
    n /= 2;
    while(n > 0) {
        cnt += n / 5;
        n /= 5;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <cassert>
using namespace std;
typedef long long ll;
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;
const double EPS = 1e-9;


int main(int argc, const char * argv[]) {
  ll N; cin >> N;
  ll ans = INF;
  
  for(ll i=1; i*i<=N; i++){
    if(N%i == 0){
      ans = min(ans, N/i + i - 2);
    }
  }
  
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
fun c88(args: Array<String>) {
    // a1 + b1, a1 + b2, a1 + b3
    // a2 + b1, a2 + b2, a2 + b3
    // a3 + b1, a3 + b2, a3 + b3
    val numList = args.map { it.split(" ").map { it.toInt() } }
    val satisfiable = (1..100)
            .any {
                val a1 = it
                val b1 = numList[0][0] - a1
                val b2 = numList[0][1] - a1
                val b3 = numList[0][2] - a1
                val a2 = numList[1][0] - b1
                val a3 = numList[2][0] - b1
                a1 + b1 == numList[0][0]
                        && a1 + b2 == numList[0][1]
                        && a1 + b3 == numList[0][2]
                        && a2 + b1 == numList[1][0]
                        && a2 + b2 == numList[1][1]
                        && a2 + b3 == numList[1][2]
                        && a3 + b1 == numList[2][0]
                        && a3 + b2 == numList[2][1]
                        && a3 + b3 == numList[2][2]
            }

    println(if (satisfiable) "Yes" else "No")
}

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

fun readLineList(): Array<String> {
    val lineList = mutableListOf<String>()
    while (true) {
        val line = readLine()
        if (line.isNullOrBlank()) {
            break
        } else {
            lineList.add(line!!)
        }
    }
    return lineList.toTypedArray()
}

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

#define whole(f, x, ...)                                 \
  ([&](decltype((x)) whole) {                            \
    return (f)(begin(whole), end(whole), ##__VA_ARGS__); \
  })(x)

using namespace std;
using ll = long long;

void solve() {
  int n;
  string s;
  cin >> n >> s;
  int p = -1, cnt = 0;

  do {
    p = s.find("ABC", p + 1);
    ++cnt;
  } while (p != string::npos);
  cout << cnt - 1 << endl;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);

  solve();
  return 0;
}


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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> a(3*n);
    for (int i = 0; i < 3*n; i++) cin >> a[i];
    sort(a.rbegin(), a.rend());
    long long ans = 0;
    for (int i = 1; i < 2*n; i += 2) {
        ans += a[i];
    }
    cout << ans << "\n";
    return 0;
}

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

using namespace std;
#define pii pair <int, int>
#define F first
#define S second
const int N = 60, LOG = 7;
int par[N][LOG], A[N], h[N], qu[N], qv[N], qAnc[N], cnt = 0;
vector <pii> g[N];

int DFS(int v, int p = 0)
{
    h[v] = h[p] + 1;
    par[v][0] = p;
    for (int i = 1; i < LOG; i++) par[v][i] = par[par[v][i - 1]][i - 1];
    for (auto u : g[v]) if (u.F != p) DFS(u.F, v);
}

int getpar(int v, int height)
{
    for (int i = 0; height; height>>=1, i++) if (height & 1) v = par[v][i];
    return v;
}

int LCA(int u, int v)
{
    if (h[u] > h[v]) swap(u, v);
    v = getpar(v, h[v] - h[u]);
    if (u == v) return v;
    for (int i = LOG - 1; i >= 0; i--) if (par[v][i] != par[u][i]) u = par[u][i], v = par[v][i];
    return par[v][0];
}

int dfs(int v, int p = 0, int id = 0)
{
    for (auto u : g[v]) if (u.F != p) {
        dfs(u.F, v, u.S);
        A[v] += A[u.F];
    }
    if (id > 0 && A[v] > 0) cnt--;
}

int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n; cin >> n;
    for (int i = 1; i <= n - 1; i++) {
        int u, v; cin >> u >> v;
        g[u].push_back({v, i});
        g[v].push_back({u, i});
    }
    DFS(1);
    int m; cin >> m;
    for (int i = 0; i < m; i++) cin >> qu[i] >> qv[i], qAnc[i] = LCA(qu[i], qv[i]);
    long long ans = 0;
    for (int mask = 0; mask < (1 << m); mask++) {
        cnt = n - 1;
        for (int i = 1; i <= n; i++) A[i] = 0;
        for (int i = 0; i < m; i++) if ((mask>>i) & 1) A[qu[i]]++, A[qv[i]]++, A[qAnc[i]]-=2;
        dfs(1);
        if (__builtin_popcount(mask)&1) ans -= (1ll << cnt);
        else ans += (1ll << cnt);
    }
    cout << ans << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)

using namespace std;

namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;

using ll = long long;
ll mod = pow(10, 9) + 7;

template <typename T> void output(T, ll);
ll gcd(ll, ll);
ll lcm(ll, ll);
Bint comb(Bint, Bint);
void prime_map(map<ll, ll> &, ll);

int main() {
    // source
    int n;
    cin >> n;
    int h[n];
    rep(i, n) { cin >> h[i]; }

    bool ans = true;
    repd(i, 1, n) {
        if (h[i - 1] > h[i]) {
            ans = false;
            break;
        } else if (h[i - 1] == h[i]) {
        } else {
            h[i] -= 1;
        }
    }

    if (ans) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Bint comb(Bint a, Bint b) {
    Bint ans = 1;

    if (a < b) {
        return 0;
    }

    rep(i, b) {
        ans *= a - i;
        ans /= i + 1;
    }

    return ans;
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

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

ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

void prime_map(map<ll, ll> &m, ll num) {
    ll cache = num;
    repd(i, 2, sqrt(num) + 2) {
        if (num % i == 0) {
            if (m[i] == 0) {
                m[i] = 1;
            } else {
                m[i]++;
            }

            num /= i;
            break;
        }
    }

    if (cache == num) {
        if (m[num] == 0) {
            m[num] = 1;
        } else {
            m[num]++;
        }
        return;
    } else {
        prime_map(m, num);
    }
}


Measured memory_bytes: 640
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		String s = sc.next();
		int[] arr = new int[n + 1];
		for (int i = 0; i < s.length() - 1; i++) {
			if (s.charAt(i) == 'A' && s.charAt(i + 1) == 'C') {
				arr[i + 1]++;
			}
		}
		for (int i = 1; i <= n; i++) {
			arr[i] += arr[i - 1];
		}
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			sb.append(arr[r - 1] - arr[l - 1]).append("\n");
		}
		System.out.print(sb);
	}
}


Measured memory_bytes: 74484
#include <stdio.h>

int cunt(int s,int* S,int t,int* T)
{
    int i,j;
    int cnt=0;
    for(i=0;i<t;i++)
    {
        for(j=0;j<s;j++)
        {
            if(T[i] == S[j])
            {
                cnt++;
                break;
            }
        }
    }
    return cnt;
}


int main(void)
{
    int s,S[10000],t,T[500];
    int i;
    
    scanf("%d",&s);
    for(i=0;i<s;i++) scanf("%d",&S[i]);
    scanf("%d",&t);
    for(i=0;i<t;i++) scanf("%d",&T[i]);
    printf("%d\n",cunt(s,S,t,T));
}



Measured memory_bytes: 2100
// J'aime
// Chemise Blanche

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl

void MAIN() {
  int n; cin >> n;
  cout << n / 2 + n % 2 << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


Measured memory_bytes: 3624
//minamoto
#include<bits/stdc++.h>
#define R register
#define inline __inline__ __attribute__((always_inline))
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
char buf[1<<21],*p1=buf,*p2=buf;
inline char getc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
int read(){
    R int res,f=1;R char ch;
    while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
    for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0');
    return res*f;
}
int read(char *s){
	R int len=0;R char ch;while(((ch=getc())!='.'&&ch!='#'));
	for(s[++len]=ch;(ch=getc())=='.'||ch=='#';s[++len]=ch);
	return s[len+1]='\0',len;
}
const int N=2e5+5;
char s[N];int n,res,sum[N][2];
int main(){
//	freopen("testdata.in","r",stdin);
	n=read(),read(s),res=0x3f3f3f3f;
	fp(i,1,n){
		sum[i][0]=sum[i-1][0],sum[i][1]=sum[i-1][1];
		++sum[i][s[i]=='#'];
	}
	fp(i,0,n)cmin(res,sum[i][1]+sum[n][0]-sum[i][0]);
	printf("%d\n",res);
	return 0;
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
#define ll long long
#define here cout<<"here\n"
#define pb push_back
#define mp make_pair
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define pf printf
#define pfi(x) printf("%d\n",x)
#define pfl(x) printf("%lld\n",x)
using namespace std;

const ll mod = 1e9+7;

const int MAX = 500005;

ll modexp(ll x, ll n)
{
    if(n==0)
        return 1LL;
    if(n%2==0)
    {
        ll y = modexp(x,n/2)%mod;
        return (y*y)%mod;
    }
    return (x*modexp(x,n-1)%mod)%mod;
}

ll powr(ll x, ll n)
{
    ll ans = 1;
    for(int i=1;i<=n;i++)
        ans=ans*x;
    return ans;
}

int main()
{

    int a,b,c;
    si(a),si(b),si(c);
    int now = 0;
    for(int i=min(a,b);i>=1;i--)
    {
        if(a%i==0&&b%i==0)
        {
            now++;
            if(now==c)
                return 0*pfi(i);
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int N,K;
  cin >> N >> K;
  int h[N];
  int result = 0;
  for(int a = 0;a < N;a++){
   cin >> h[a];
    if(h[a] >= K)result++;
  }

  
  cout <<result<< endl;
 
}

Measured memory_bytes: 640
#include <cstdio>
#include <cmath>
int main()
{
	int x,y,m;
      scanf("%d",&x);
      y=(int)sqrt(x);
      if (x==y*y){
      	  printf("%d",x);
	  }
      	  else{
      	  	  m=y*y;
      	  	 printf("%d",m);
}
}

Measured memory_bytes: 128
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;

namespace AtCoderWorkspace
{
    public class Solver
    {
        public void Solve()
        {
            var cin = new Scanner();
            
            var n = cin.nextInt();
            var a = cin.ArrayInt(n);
            var ans = long.MaxValue;
            for (int p = 1; p <= 100; p++)
            {
                var sum = 0L;
                for (int i = 0; i < n; i++)
                {
                    sum += (a[i] - p) * (a[i] - p);
                }
                ans = Math.Min(ans, sum);
            }
            
            Console.WriteLine(ans);
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public int[] DPArrayInt(int N, int ex)
        {
            int[] Array = new int[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt();
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public long[] DPArrayLong(int N, int ex)
        {
            long[] Array = new long[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong();
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }

    class Program
    {
        static void Main(string[] s) => new Solver().Solve();
    }
}


Measured memory_bytes: 11092
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#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 rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0
#define addf(T) [](T a, T b){return (a + b);}
#define minf(T) [](T a, T b){return min(a, b);}
#define maxf(T) [](T a, T b){return max(a, b);}


using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const long double PI = acos(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

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

ll lcm(ll number1, ll number2) {
	return number1 / gcd(number1, number2) * number2;
}

ll LSB(ll n) { return (n & (-n)); }

/*-----------------------------------------ここからコード-----------------------------------------*/


int main() {

	int a, b, c;
	scanf("%d%d%d", &a, &b, &c);
	printyn((!(a xor b) xor !(b xor c) xor !(c xor a)) and !(a == b && b == c));
	
	Please AC;
}


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

using namespace std;

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

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

    for (int i = 0; i < s.size() - 8; i++) {
        cout << s[i];
    }
    cout << endl;

    return 0;
}


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

int bfs(int k){
  deque<int> x;
  x.push_back(1);
  int dist[100001];
  for(int i = 0;i < k;i++)
    dist[i] = 10000;
  dist[1] = 1;
  while(x.size()){
    int u = x.front();x.pop_front();
    if(u == 0)
      return dist[u];
    if(dist[u] < dist[10 * u % k]){
      x.push_front(10 * u % k);
      dist[10 * u % k] = dist[u];
    }
    if(dist[u] + 1 < dist[(u + 1) % k]){
      dist[(u + 1) % k] = dist[u] + 1;
      x.push_back((u + 1) % k);
    }
  }
}
int main()
{
//  freopen("in.txt", "r", stdin);
//  freopen("out.txt", "w", stdout);
  int k;
  cin >> k;
  cout << bfs(k);
}


Measured memory_bytes: 820
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+10,mod=1e9+7;

int n,ans=1;
int t[N],a[N],vs[N],d[N],dr[N],f[N];
bool cir[N];

inline int ad(int x,int y){x+=y;return x>=mod?x-mod:x;}

void sol(int x)
{
	int nw=0,fi=0,sc,pre;
	for(;cir[x];x=a[x]){
		++nw;cir[x]=false;
		if(!dr[x]) continue;
		if(!fi) {fi=sc=nw;pre=dr[x];}
		else{
			if(nw-sc<dr[x]) ans=0;
			else if(nw-sc>dr[x]) ans=ad(ans,ans);
			sc=nw;
		}
	}
	if(!fi) t[nw]++;
	else{
		nw=fi-sc+nw;
		if(nw<pre) ans=0;
		else if(nw>pre) ans=ad(ans,ans);
	}
}

int main(){
	int i,j,k;
	
	scanf("%d",&n);
	for(i=1;i<=n;++i) {scanf("%d",&a[i]);d[a[i]]++;}
	for(i=1;i<=n;++i) if(!vs[i]){
		vs[i]=i;
		for(j=a[i];!vs[j];j=a[j]) vs[j]=i;
		if(vs[j]^i) continue;
		for(;!cir[j];j=a[j]) cir[j]=true;
	}
	
	for(i=1;i<=n;++i)
	 if((cir[i] && d[i]>2)||((!cir[i])&& d[i]>1))
	   {puts("0");return 0;}
	
	for(i=1;i<=n;++i) if(!d[i]){
		for(k=0,j=i;(!cir[j]);j=a[j]) k++;
		dr[j]=k;
	}
	
	for(i=1;i<=n;++i) if(cir[i]) sol(i);
	if(!ans) {puts("0");return 0;}
	
	f[0]=1;
	for(i=1;i<=n;++i) if(t[i]){
		for(j=1;j<=t[i];++j){
			if(i>1 && (i&1)) f[j]=ad(f[j-1],f[j-1]);
			else f[j]=f[j-1];
			if(j>1) f[j]=ad(f[j],(ll)f[j-2]*(j-1)*i%mod);
		}
		ans=(ll)ans*f[t[i]]%mod;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 1920
# import bisect
# import copy
# import fractions
# import math
# import numpy as np
# from collections import Counter, deque
# from itertools import accumulate,permutations, combinations,combinations_with_replacement,product

def resolve():
    O=list(input())
    E=list(input())
    p=[]
    for i in range(len(O)):
        p.insert(i*2,O[i])
    for j in range(len(E)):
        p.insert(1+j * 2, E[j])

    print(''.join(p))

resolve()

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

int main()
{
  int K, A, B;
  cin >> K >> A >> B;
  
  int KK = A % K;
  if(KK==0)
    cout << "OK" << endl;
  else
  {
    A = A + (K-KK);
    if(A<=B)
      cout << "OK" << endl;
  else
    cout << "NG" << endl;    
  }
}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    string s;
    cin >> s;
    if(s == "AAA" || s == "BBB") cout << "No";
    else cout << "Yes";
    cout << endl;

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <string>
#include <cmath>
#include <sstream>
#include <istream>
#include <iomanip>
#include <typeinfo>
#include <stack>
#include <map>

using namespace std;
typedef long long int ll;

int main(){

    ll N, K;
    string S;
    cin >> N >> K >> S;
    vector <ll > packing;

    //バグらせないように後ろに一つつけておく
    if(S[S.length()-1] == 'R'){
        S.push_back('L');
    }else{
        S.push_back('R');
    }

    //幸福度
     ll ans = 0;

    //前処理
    ll tmp = 0;
    //最大何箇所変更できるか
    ll changeable = 0;
    for(ll i = 0; i < S.length() - 1; i++){
        //Lのときはプラスで揃える
        if(S[i] == 'L'){
            tmp++;
            if(S[i+1] == 'R'){
                packing.push_back(tmp);
                ans += tmp - 1;
                tmp = 0;
                changeable++;
            }
        }
        //Rのときはマイナスに揃える 
        if(S[i] == 'R'){
            tmp++;
            if(S[i+1] == 'L'){
                packing.push_back(-1 * tmp);
                ans += tmp - 1;
                tmp = 0;
                changeable++;
            }
        }
    }
    //一つ分余計
    changeable--;
    //cout << changeable << endl;

    if(changeable == 0){
        //変更可能な箇所がない　幸福度は人数に応じる
        cout << ans << endl;
    }else{
        //cout << changeable << endl;
        //向きを変えても２人分の幸福度しか最大で増えない
        ans += 2 * min(changeable / 2, K);
        K -= changeable / 2;
        if(K > 0 && changeable % 2 == 1){
            ans += 1;
        }
        cout << ans << endl;
    }

   
    //cout << ans << endl;

} 

Measured memory_bytes: 1528
import java.io.{BufferedReader, InputStream, InputStreamReader, PrintWriter}
import java.util.StringTokenizer

import scala.collection.mutable
import scala.util.Sorting
import math.{abs, max, min}
import scala.collection.mutable.{ArrayBuffer, ListBuffer}
import scala.reflect.ClassTag

object Main {
  val MOD = 1000000007
  val out = new PrintWriter(System.out)
  def solve(): Unit = {
    val sc = new InputReader(System.in)
    val A, B, C, D, E, F = sc.nextInt()

    def waters: Array[Int] = {
      val set = mutable.HashSet[Int]()
      for {
        a <- 0 to F / A / 100
        b <- 0 to F / B / 100
      } {
        val w = a * A + b * B
        if (w * 100 <= F && w > 0) set += w
      }
      set.toArray
    }

    def sugars: Array[Int] = {
      val set = mutable.HashSet[Int]()
      for {
        c <- 0 to F / C
        d <- 0 to F / D
      } {
        val s = c * C + d * D
        if (s <= F) set += s
      }
      set.toArray
    }

    val (w, s) = (for {
      w <- waters
      s <- sugars
      if w * 100 + s <= F && s <= w * E
    } yield (w * 100, s)).maxBy(x => x._2.toDouble / (x._1 + x._2))

    out.println(s"${s + w} $s")
  }


  def main(args: Array[String]): Unit = {
    solve()
    out.flush()
  }


  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = null

    def next: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next.toInt
    def nextLong(): Long = next.toLong
    def nextChar(): Char = next.charAt(0)
  }

  private def rep(n: Int)(f: Int => Unit): Unit = (0 until n) foreach f

  private def map[@specialized A: ClassTag](n: Int)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    (0 until n) foreach (i => res(i) = f(i))
    res
  }

  private implicit class ArrayOpts[A](val as: Array[A]) extends AnyVal {
    def maxByOpt[B: Ordering](f: A => B): Option[A] = {
      if (as.nonEmpty) Some(as.maxBy(f)) else None
    }

    def grpBy[K](f: A => K): mutable.Map[K, ArrayBuffer[A]] = {
      val map = mutable.Map.empty[K, ArrayBuffer[A]]
      rep(a => map.getOrElseUpdate(f(a), ArrayBuffer()) += a)
      map
    }

    def rep(f: A => Unit): Unit = {
      as.indices foreach (i => f(as(i)))
    }

    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      var sum = num.zero
      rep(a => sum = num.plus(sum, f(a)))
      sum
    }
  }

  private implicit class IterableOpts[A](val as: Iterable[A]) extends AnyVal {
    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      as.foldLeft(num.zero)((acc, a) => num.plus(acc, f(a)))
    }
  }

}


Measured memory_bytes: 40264
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

struct UnionFind {
  vector<int> d;
  UnionFind(int n=0): d(n,-1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y);}
  int size(int x) { return -d[find(x)];}
};

int main() {
    int n, q;
    cin >> n >> q;
    UnionFind uf = UnionFind(n);
    vector<int> command(q), x(q), y(q);
    REP(i, q) cin >> command[i] >> x[i] >> y[i];
    REP(i, q) {
        int c = command[i], z1 = x[i], z2 = y[i];
        if(c == 0) {
            uf.unite(z1, z2);
        } else {
            cout << uf.same(z1, z2) << endl;
        }
    }
    return 0;
}


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


int main() {

/*
N×N のマス目があります。

このマス目の各マスを白色または黒色に塗ることにしました (すべてのマスをどちらか片方の色に塗ります)。

ちょうど A マスを白色に塗るとき、黒色に塗ることになるマスはいくつあるでしょうか。
*/

	int N;
	int A;

	cin >> N;
	cin >> A;

	int C = N*N - A;

	cout << C;

}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main(){
  int a,b,c,d,i,j;
  int sum1=0,sum2=0;
  int sum3=0,sum4=0;
  int min;
  scanf("%d",&a);
  int bel[a];
  for(i=0;i<a;i++){
    scanf("%d",&bel[i]);
  }

  for(j=0;j<a;j++){
    sum1 += bel[j];
  }
   min = sum1;

  for(i=0;i<a;i++){
    for(j=0;j<i;j++){
      sum2 += bel[j];      //s1
    }

    sum3 = abs(sum1-sum2);  //s2
    sum4 = abs(sum2-sum3);

    if(min > sum4){
      min = sum4;
    }

    sum2 = 0;
  }

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


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
set<pair<int,int>>s;
int main(){
	long long n,d;
	scanf("%lld %lld",&n,&d);
	int ans=0;
	for(int i=1;i<=n;i++){
		long long x,y;
		scanf("%lld %lld",&x,&y);
		if(x*x+y*y<=d*d){
			ans++;
		}
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

void ABC161E()
{
	int N, K, C;
	cin >> N >> K >> C;
	string S;
	cin >> S;
	++C;
	vi X(N), Y(N);
	X[0] = S[0] == 'x' ? 0 : 1;
	Y[N - 1] = S[N - 1] == 'x' ? 0 : 1;

	for (int i = 1; i < N; ++i)
	{
		if (i < C)
		{
			X[i] = max(X[i - 1], S[i] == 'x' ? 0 : 1);
			Y[N - 1 - i] = max(Y[N - i], S[i] == 'x' ? 0 : 1);
		}
		else
		{
			X[i] = max(X[i - 1], X[i - C] + (S[i] == 'x' ? 0 : 1));
			Y[N - i - 1] = max(Y[N - i], Y[N - i + C-1] + (S[N - i - 1] == 'x' ? 0 : 1));
		}
	}
	if (X[N - 1] != K)
		return;

	//for (int i = 0; i < 4; ++i)
	//{
	//	if(X[i] == 1 && Y[i] == K-1)
	//}

	for (int i = 0; i < N; ++i)
	{
		if (S[i] == 'x')
			continue;

		if((i == 0 || X[i] > X[i-1]) && (i == N-1 || Y[i] > Y[i+1]))
			cout << i + 1 << endl;
	}

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


Measured memory_bytes: 3332
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int n = s.length();
        for (int i = 0 ; i < n ; i++) {
            System.out.print("x");
        }
        System.out.print("\n");
    }

}


Measured memory_bytes: 21844