akhauriyash/Code-Regression huggingface dataset:
package main

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

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func digitSum(n int) int {
	ret := 0
	for n > 0 {
		ret += n % 10
		n /= 10
	}
	return ret
}

func min(nums ...int) int {
	ret := nums[0]
	for _, v := range nums {
		if v < ret {
			ret = v
		}
	}
	return ret
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	ans := 100
	for i := 1; i <= n/2; i++ {
		a, b := i, n-i
		ans = min(ans, digitSum(a)+digitSum(b))
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define P pair<int,int>
#define PI 3.141592653589793
const int INF = 1001001001;
const ll MX = 1e18;
const int mod = 1000000007;

int main() {
	ll n, k;
	cin >> n>>k;
	vector<ll> p(n);
	vector<ll> c(n);
	rep(i, n) {
		cin >> p[i];
		p[i]--;
	}
	rep(i, n) cin >> c[i];
	//入力

	ll ans = -INF;

	rep(ci, n) {
		ll now = 0, maxnow = -INF;
		vector<ll> r;
		ll i = ci;
		bool ng = false;
		vector<int> che(n);
		rep(ni, n) {//一回ループ操作

			if (ni >= k) {
				ans = max(maxnow, ans);
				ng = true;
				break;
			}

			r.push_back(c[p[i]]);
			now += c[p[i]];
			//cout << c[p[i]] << endl;
			maxnow = max(now, maxnow);
			che[i] = 1;
			i = p[i];
			if (che[i] == 1) break;
		}
		
		if (ng)continue;
		if (now <= 0 && maxnow >= now) {
			ans = max(maxnow, ans);
			continue;
		}
		ll ni = r.size();
		ll na = now * (k / ni);
		if (now < maxnow) {
			ll nna = na - now + maxnow;
			ans = max(nna, ans);
		}
		ll aa = na;
		rep(i, k% ni) {
			aa += r[i];
			na = max(na, aa);
		}
		ans = max(na, ans);
		ans = max(maxnow, ans);
	}
	cout << ans << endl;
}


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

using namespace std;

int main() {

    int n;

    cin >> n;

    string s = to_string(n);

    int sum = 0;

    for(int i = 0;i < s.length();i++){
        char b = s[i];
        int a = b - '0';
        sum += a;
    }

    if(n % sum == 0) cout << "Yes" <<endl;
    else cout << "No" << endl;

    return 0;

}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Contents   : ARC D問題
Author     : Kitaura Hiromi
LastUpdate : 20180527
Since      : 20180526
"""
from operator import xor
from functools import reduce

N = int(input())
A = list(map(int, input().split()))

cnt = 0
r = 0
tmp = 0
for l in range(N):
    while r < N and tmp & A[r] == 0:
        # 区間の右端の要素を足す
        tmp ^= A[r]
        r += 1
    # print(l, r)
    cnt += (r - l)
    # 区間の左端の要素を引く
    tmp ^= A[l]
print(cnt)

Measured memory_bytes: 25340
n,m = map(int,input().split())
para_val = {}
for i in range(n):
    a, b = map(int,input().split())
    if a in para_val.keys() :
        para_val[a] += b

    else : para_val[a] = b
    
para_val  = sorted(para_val.items())
count = m
ans = 0

    
for i, j in para_val :
    if count > 0 :
        if j <= count :
            count = count - j 
            ans += i * j 
        else : 
            ans += count*i 
            count = 0
    else : break 
print(ans)


Measured memory_bytes: 23000
get_string(String) :-
  current_input(Input),
  read_string(Input, ' \n', '', _, String).
 
get_number(Number) :-
  get_string(String),
  number_string(Number, String).

for(A,B,A,B,X) :- X =:= A*A*A*A*A - B*B*B*B*B, !.
for(A,200,Ans_A,Ans_B,X) :-
  Next_A is A + 1,
  for(Next_A,-200,Ans_A,Ans_B,X).
for(A,B,Ans_A,Ans_B,X) :- 
  Next_B is B + 1,
  for(A,Next_B,Ans_A,Ans_B,X).

main :-
  get_number(X),
  for(-200,-200,A,B,X),
  write(A), write(' '), writeln(B).


Measured memory_bytes: 8280
# -*- coding: utf-8 -*-

import sys
from collections import defaultdict
from bisect import bisect_right

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

S = input()
T = input()
N = len(S)

d = defaultdict(list)
for i, s in enumerate(S):
    d[s].append(i)
for k, v in d.items():
    d[k].append(INF)

cur = -1
ans = 0
for i, t in enumerate(T):
    if t not in d:
        print(-1)
        exit()
    idx = bisect_right(d[t], cur)
    if d[t][idx] == INF:
        ans += N
        cur = d[t][0]
    else:
        cur = d[t][idx]
ans += cur+1
print(ans)


Measured memory_bytes: 7924
/*|In The Name of Allah|*/

#include <bits/stdc++.h>

using namespace std;

const int N = 1e5+5;

int n;
int k;
string s;
int Zers[N];
int Ones[N][2];
//0 for prefix
//1 for suffix

int main(){
    cin >> n >> k >> s;
    for(int i = n - 1; i >= 0; i--){
        if(s[i] == '0')
            continue;
        if(i == n - 1){
            Ones[i][1] = (s[i] == '1');
            continue;
        }
        Ones[i][1] = Ones[i + 1][1] + (s[i] == '1');
    }
    bool foundZ = 0;
    for(int i = 0; i < n; i++){
        foundZ = (s[i] == '0');
        if(s[i+1] == '1' && foundZ){
            Zers[i] = 1;
            foundZ = 0;
        }
        if(i)
            Zers[i] += Zers[i - 1];
    }
    int best = 0;
    for(int i = 0; i < n; i++){
        int l = i;
        int r = n - 1;
        while(l < r){
            int mid = (l + r) >> 1;
            if(Zers[mid] - ((i) ? Zers[i - 1] : 0) >= k){
                r = mid;
            } else {
                l = mid + 1;
            }
        }
        int ons = Ones[r + 1][1] + (r - i + 1);
        best = max(best , ons);
    }
    cout << best << endl;
    return 0;
}



Measured memory_bytes: 1664
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


n, m, d = MI()


def s():
    # a = n
    # if n - 2 * d >= 0:
    #     a += n - 2 * d
    # else:
    #     a += n - 2 * d
    # return a
    if d == 0:
        return 1
    return 2 * (n - d) / n

print(s() * (m - 1) / n)

Measured memory_bytes: 38384
import collections
from operator import mul
from functools import reduce

N = int(input())
words = ["".join(sorted(input())) for _ in range(N)]

c = collections.Counter(words)
nums = list(c.values())

def cmb(n,r):
    if n == 1: return 0
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

print(sum([cmb(i,2) for i in nums]))

Measured memory_bytes: 20028
#include <stdio.h>
#include <string.h>

typedef struct {
	char name[33];
	int num;
} WORD;

int main(void)
{
	WORD word[512];
	int i, j = 0, max_len = 511, max_num = 511;
	char str[33];
	
	word[511].name[0] = ' ';
	word[511].name[1] = '\0';
	word[511].num = 0;
	
	while (scanf("%s", str) != EOF){
		for (i = 0; i < j; i++){
			if (strcmp(str, word[i].name) == 0){
				word[i].num++;
				break;
			}
		}
		
		if (i == j){
			strcpy(word[j].name, str);
			j++;
			word[j].num++;
		}
	}

	for (i = 0; i < j; i++){
		if (strlen(word[max_len].name) < strlen(word[i].name)){
			max_len = i;
		}
		
		if (word[max_num].num < word[i].num){
			max_num = i;
		}
	}
	
	printf("%s %s\n", word[max_num].name, word[max_len].name);
	
	return (0);
}

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


int main() {
    int n;
    string s;
    cin >> n >> s;
    rep(i, s.size()) {
        if (s[i]+n <= 'Z') putchar(s[i]+n);
        else putchar(s[i]+n-'Z'+'A'-1);
    }
    printf("\n");

    return 0;
}

Measured memory_bytes: 3628
#include <stdio.h>
#include <memory.h>

void displayNum(char c, int num[]) {
    int i;
    for(i = 1; i <= 13; i++) {
        if(num[i] != 0) {
            printf("%c %d\n", c, num[i]);
        }
    }
}   

int main() {
    int n, i;
    char symbol[2] = {'\0'};
    int num = 0;
    int ans_numD[14] = {0};
    int ans_numH[14] = {0};
    int ans_numS[14] = {0};
    int ans_numC[14] = {0};

    for(i = 1; i <= 13; i++) {
        ans_numD[i] = i;
        ans_numH[i] = i;
        ans_numS[i] = i;
        ans_numC[i] = i;
    }

    scanf("%d", &n);
    for(i = 0; i < n; i++) {
        scanf("%s %d", symbol, &num);
        if(symbol[0] == 'D') {
            ans_numD[num] = 0;
        } else if (symbol[0] == 'H') {
            ans_numH[num] = 0;
        } else if (symbol[0] == 'S') {
            ans_numS[num] = 0;
        } else if (symbol[0] == 'C') {
            ans_numC[num] = 0;
        } else {
            // nothing to do
        }
        // printf("input %c: %d\n", symbol[0], num);
        memset(symbol, 0x00, sizeof(symbol));
        // printf("input %c: %d\n", symbol[0], num);
    }
    
    displayNum('S', ans_numS);
    displayNum('H', ans_numH);
    displayNum('C', ans_numC);
    displayNum('D', ans_numD);
    return 0;
}



Measured memory_bytes: 2060
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

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

  string s;
  cin >> s;

  string t;
  t.push_back(s[0]);
  t += to_string(s.length() - 2);
  t.push_back(s[s.length() - 1]);

  cout << t << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
using namespace std;
 
int main(){
  long N, K;
  cin >> N >> K;
 
  long res = 0;

  // b固定
  for (int i=1; i<=N; i++) {
    res += N/i * max(0L, i-K); // 繰り返し
    res += max(0L, N%i - max(0L, K - 1)); // 繰り返しからはみでた分
  }
  cout << res << endl;
}


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

using namespace std;

namespace mod {

template <class T, int M>
class MInt;

template <class T, int M>
MInt<T, M> Pow(const MInt<T, M> &base, T exp);

template <class T, int M>
MInt<T, M> Inv(const MInt<T, M> &n);

template <class T, int M>
class MInt {
  T n_;

 public:
  MInt() : n_(0) {}
  MInt(T n) : n_((n % M + M) % M) {}

  MInt &operator+=(const MInt &rhs) {
    n_ += rhs.n_;
    if (n_ >= M) {
      n_ -= M;
    }

    return *this;
  }

  MInt &operator-=(const MInt &rhs) {
    n_ += M - rhs.n_;
    if (n_ >= M) {
      n_ -= M;
    }

    return *this;
  }

  MInt &operator*=(const MInt &rhs) {
    n_ = n_ * rhs.n_ % M;
    return *this;
  }

  MInt &operator/=(const MInt &rhs) { return (*this) *= Inv(rhs); }

  T Get() { return n_; }
};

template <class T, int M>
MInt<T, M> operator-(const MInt<T, M> &lhs, const MInt<T, M> &rhs) {
  MInt<T, M> res(lhs);
  return res -= rhs;
}

template <class T, int M>
MInt<T, M> operator+(const MInt<T, M> &lhs, const MInt<T, M> &rhs) {
  MInt<T, M> res(lhs);
  return res += rhs;
}

template <class T, int M>
MInt<T, M> operator*(const MInt<T, M> &lhs, const MInt<T, M> &rhs) {
  MInt<T, M> res(lhs);
  return res *= rhs;
}

template <class T, int M>
MInt<T, M> operator/(const MInt<T, M> &lhs, const MInt<T, M> &rhs) {
  MInt<T, M> res(lhs);
  return res /= rhs;
}

template <class T, int M>
MInt<T, M> Pow(const MInt<T, M> &base, T exp) {
  if (exp == 0) {
    return 1;
  }

  auto a = Pow(base, exp / 2);
  a *= a;
  if (exp % 2 == 1) {
    a *= base;
  }

  return a;
}

template <class T, int M>
MInt<T, M> Inv(const MInt<T, M> &n) {
  return Pow(n, static_cast<T>(M - 2));
}
}  // namespace mod

const int md = 1e9 + 7;
using MInt = mod::MInt<long long, md>;
class BinCoef {
  vector<MInt> f;

 public:
  BinCoef(int n) : f(n + 1) {
    f[0] = f[1] = 1;
    for (int i = 2; i <= n; i++) {
      f[i] = MInt(i) * f[i - 1];
    }
  }

  MInt NCM(int n, int m) { return f[n] * mod::Inv(f[m] * f[n - m]); }
};

int main(int argc, const char *argv[]) {
  int x, y;
  cin >> x >> y;

  if ((x + y) % 3 != 0) {
    cout << "0\n";
    return 0;
  }

  // (i + 1, j + 2), (i + 2, j + 1) に移動する回数
  int m = (2 * x - y) / 3;
  int n = x - 2 * m;
  if (m < 0 || n < 0) {
    cout << "0\n";
    return 0;
  }
  BinCoef bc(m + n);
  cout << bc.NCM(m + n, n).Get() << "\n";
  return 0;
}

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

const long long mod = 1000000007;
const long long inv2 = (mod + 1) / 2;
vector<int> G[2020];

vector<long long> mul(vector<long long> &a, vector<long long> &b)
{
	vector<long long> r(a.size()+b.size()-1);
	for (int i=0;i<a.size();i++) for (int j=0;j<b.size();j++){
		r[i+j] = (r[i+j] + a[i] * b[j]) % mod;
	}
	return move(r);
}

vector<long long> add(vector<long long> &a, vector<long long> &b, int sig = 1)
{
	vector<long long> r(max(a.size(),b.size()));
	for (int i=0;i<a.size();i++) r[i] = a[i];
	for (int i=0;i<b.size();i++) r[i] = (r[i] + b[i] * sig % mod + mod) % mod;
	return move(r);
}

vector<vector<long long> > go(int x)
{
	vector<vector<long long> > r(3,vector<long long>(2,0));
	r[0][1] = 1;

	for (auto &y : G[x]){
		auto q = go(y);
		auto s = q[0];
		s = add(s,q[1]);
		s = add(s,q[2]);

		vector<vector<long long> > nr(3);
		for (int k=0;k<3;k++) nr[k] = mul(r[k],s);
		long long coeff[2][2] = {2,1,1,inv2};
		for (int i=0;i<2;i++) for (int j=0;j<2;j++){
			auto t = mul(r[i],q[j]);
			t.erase(t.begin());
			nr[i+1] = add(nr[i+1],t,-coeff[i][j]);
		}
		r = move(nr);
	}

	return move(r);
}

int main()
{
	int N; scanf ("%d",&N);
	for (int i=2;i<=N;i++){
		int p; scanf ("%d",&p);
		G[p].push_back(i);
	}

	auto r = go(1);

	long long ans = 0, f = 1;
	for (int i=1;i<=N;i++){
		f = f * i % mod;
		ans = (ans + (r[0][i] + r[1][i] + r[2][i]) * f) % mod;
	}
	printf ("%lld\n",ans);

	return 0;
}

Measured memory_bytes: 1408
n = int(input())
x = list(map(int, input().split()))

x_s = sorted(x)
med2 = x_s[n//2]
med1 = x_s[n//2-1]
for i in range(n):
    if x[i]<=med1:
        print(med2)
    else:
        print(med1)

Measured memory_bytes: 25220
#include<bits/stdc++.h>
using namespace std;
const int N=1e6;
int i,j,k,m,n,v,w,u,tot;
int ver[N],nxt[N],edge[N],head[N],col[N];
void add(int x,int y,int c)
{
	ver[++tot]=y;edge[tot]=c;nxt[tot]=head[x];head[x]=tot;
	ver[++tot]=x;edge[tot]=c;nxt[tot]=head[y];head[y]=tot;
}
void dfs(int x)
{
	for(int i=head[x];i;i=nxt[i])
	{
		if(col[ver[i]]<0)
		{
			if(edge[i]%2==0) col[ver[i]]=col[x],dfs(ver[i]);
			else col[ver[i]]=col[x]^1,dfs(ver[i]);
		}
	}
}
int main()
{
	tot=1;
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		col[i+1]=-1;
		scanf("%d%d%d",&u,&v,&w);
		add(u,v,w);
	}
	col[1]=1;
	dfs(1);
	for(int i=1;i<=n;i++) printf("%d\n",col[i]);
	return 0;
}

Measured memory_bytes: 17280
use proconio::*;

fn calc(mut a: Vec<(u32, i32)>, item: (u32, i32)) -> Vec<(u32, i32)> {
    let mut b = a.iter().map(|a| (a.0 + item.0, a.1 + item.1)).collect::<Vec<_>>();
    let mut c = Vec::with_capacity(a.len() * 2);
    while !(a.is_empty() || b.is_empty()) {
        if a.last().unwrap().1 >= b.last().unwrap().1 {
            c.push(a.pop().unwrap());
        } else {
            c.push(b.pop().unwrap());
        }
    }
    for p in a.into_iter().chain(b.into_iter()).rev() {
        c.push(p);
    }
    c.reverse();
    let mut val = 0;
    for c in c.iter_mut() {
        val = std::cmp::max(val, c.0);
        c.0 = val;
    }
    c
}

#[fastout]
fn run() {
    input! {
        n: usize,
        mut item: [(u32, i32); n],
        q: usize,
        ask: [(usize, i32); q],
    }
    item.insert(0, (0, 0));
    let mut memo = vec![vec![]; n + 1];
    memo[1] = vec![(0, 0), item[1]];
    let batch = 10;
    for i in 2..=std::cmp::min(n, 1 << batch) {
        memo[i] = calc(memo[i / 2].clone(), item[i]);
    }
    for (start, width) in ask {
        let ans = if start < (1 << batch) {
            memo[start].iter().filter(|p| p.1 <= width).max().unwrap().0
        } else {
            let mut dp = vec![(0, 0)];
            let mut pos = start;
            while pos >= (1 << batch) {
                dp = calc(dp, item[pos]);
                pos /= 2;
            }
            let mut ans = 0;
            for &(v, w) in memo[pos].iter() {
                while let Some(p) = dp.last() {
                    if p.1 + w > width {
                        dp.pop();
                    } else {
                        break;
                    }
                }
                if let Some(p) = dp.last() {
                    ans = std::cmp::max(ans, v + p.0);
                }
            }
            ans
        };
        println!("{}", ans);
    }
}

fn main() {
    run();
}


Measured memory_bytes: 21448
//ABC097B
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
using namespace std;

int main(){
	int x;
	cin >> x;
	if(x == 1){
		cout << 1 << endl;
		return 0;
	}
	int ans;
	for(int i=2;i<x;i++){
		int a = i;
		int count = 0;
		while(a <= x){
			a *= i;
			count++;
		}
		if(count > 1){
			a /= i;
			ans = max(a,ans);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
H, W, A, B = map(int, open(0).read().split())
MOD = 10**9+7

def modcomb(m, n, mod):
    if n > m - n:
        n = m - n
    p = 1
    q = 1
    for i in range(n):
        p = p * (m - i) % mod
        q = q * (i + 1) % mod
    result = p * pow(q, mod - 2, mod) % mod
    return result

total = modcomb(H + W - 2, W - 1, MOD)

tmp = modcomb(A + W - 2, W - 1, MOD)
total -= tmp

for i in range(B - 1):
    a = H - A + i
    b = i + 1
    c = W - i - 1
    d = W + A - 2 - i
#     print(a,b,c,d)
    tmp = tmp * a * c % MOD
    tmp = tmp * pow(b, -1, MOD) % MOD
    tmp = tmp * pow(d, -1, MOD) % MOD
#     print(tmp)
    total = (total - tmp) % MOD

print(total)

Measured memory_bytes: 9212
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <queue>

#define mp make_pair
#define pb push_back


typedef long long ll;
typedef long double ld;

using namespace std;

vector<ll> vv;
ll pr[120000];
int n;
ll a[120000];

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; ++i)
		scanf("%lld", a + i), vv.push_back(a[i]);
	sort(vv.begin(), vv.end());
	pr[0] = 0;
	for (int i = 0; i < vv.size(); ++i)
		pr[i + 1] = pr[i] + vv[i];
	ll mx = 0;
	for (int i = 0; i < n; ++i) {
		if (a[i] > mx) {
			int l = lower_bound(vv.begin(), vv.end(), mx + 1) - vv.begin();
			int r = lower_bound(vv.begin(), vv.end(), a[i] + 1) - vv.begin();
			ll ans = (a[i] - mx) * (vv.size() - r) + (pr[r] - pr[l] - mx * (r - l));
			printf("%lld\n", ans);
			mx = a[i];
		}
		else {
			printf("0\n");
		}
	}
	return 0;
}




Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    putchar_unlocked(c[i]);
  }
}
int main(){
  int R;
  rd(R);
  if(R<1200){
    wt_L("ABC");
    wt_L('\n');
  }
  else if(R<2800){
    wt_L("ARC");
    wt_L('\n');
  }
  else{
    wt_L("AGC");
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20190630-1

// --- original code ---
// {
//   int R;
//   rd(R);
//   wt( if[R<1200, "ABC", R<2800, "ARC", "AGC"] );
// }


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();

        int K_MAX = (int) (b == 0 ? 0 : Math.log(b) / Math.log(2)) + 1;
        long[] digits = new long[K_MAX];
        for (int k = 0; k < K_MAX; k++) {
            if (k == 0) {
                digits[k] = calcDigitFor0(a, b, k);
            } else {
                digits[k] = calcDigit(a, b, k);
            }
        }

        long ans = 0;
        for (int k = 0; k < K_MAX; k++) {
            ans += Math.pow(2, k) * digits[k];
        }
        System.out.println(ans);
    }

    static long calcDigit(long a, long b, int k) {
        long target = (long) Math.pow(2, k + 1);
        long center = (long) Math.pow(2, k);
        long restA = a % target;
        long restB = b % target;
        if (restA < restB) {
            if (restB < center) {
                return 0;
            } else if (restA < center && restB >= center) {
                return (restB - center + 1) % 2;
            } else {
                return (restB - restA + 1) % 2;
            }
        } else if (restA == restB) {
            if (restA >= center) {
                return 1;
            } else {
                return 0;
            }
        } else {
            if (restA < center) {
                return 0;
            } else if (restB < center && restA >= center) {
                return (target - restA) % 2;
            } else {
                return ((target - restA) + restB - center + 1) % 2;
            }
        }
    }


    static long calcDigitFor0(long a, long b, int k) {
        long target = (long) Math.pow(2, 2);
        long restA = a % target;
        long restB = b % target;
        if (restA == restB) {
            if (restA == 1 || restA == 3) {
                return 1;
            } else {
                return 0;
            }
        } else if (restA < restB) {
            if (restA == 0) {
                if (restB == 1) {
                    return 1;
                } else if (restB == 2) {
                    return 1;
                } else if (restB == 3) {
                    return 0;
                }
            } else if (restA == 1) {
                if (restB == 2) {
                    return 1;
                } else if (restB == 3) {
                    return 0;
                }
            } else if (restA == 2) {
                return 1;
            }
        } else {
            if (restA == 3) {
                if (restB == 2) {
                    return 0;
                } else if (restB == 1) {
                    return 0;
                } else if (restB == 0) {
                    return 1;
                }
            } else if (restA == 2) {
                if (restB == 1) {
                    return 0;
                } else if (restB == 0) {
                    return 1;
                }
            } else if (restA == 1) {
                return 0;
            }
        }
        return 0;
    }
}


Measured memory_bytes: 23764
x, n = map(int, input().split())
q = [i for i in range(-110, 210)]
if n != 0:
  p = list(map(int, input().split()))
  for i in p:
    q[i+110] = -500

if x in q:
  print(x)
  exit()

l = []

for i in range(100):
  if x+i in q:
    l.append(x+i)
    break
for j in range(100):
  if x-j in q:
    l.append(x-j)
    break

if abs(l[0]-x) < abs(l[1]-x):
  print(l[0])
elif abs(l[0]-x) > abs(l[1]-x):
  print(l[1])
else:
  print(l[1])

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

int main() {
    ll x;
    cin>>x;
    int a,b;
    for(ll i=-120;i<120;i++){
        for(ll j=i+1;j<121;j++){
            if(powl(j,5)-powl(i,5)==x){
                a=j,b=i;
                goto OUT;
            }
        }
    }
    OUT:
    cout<<a<<' '<<b<<endl;
}

Measured memory_bytes: 3688
<?php
  $n = intval(fgets(STDIN));

  $array = explode(" ",trim(fgets(STDIN)));

  $flag = true;
  for($i=0; $i<$n; $i++){
    $val = $array[$i];
    if($val%2==0){
      if($val%3!=0 && $val%5!=0){
        $flag = false;
        break;
      }
    }
  }

  if($flag){
    echo "APPROVED\n";
  }else{
    echo "DENIED\n";
  }

Measured memory_bytes: 4604
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]

    N,K = LI()
    A = LI()

    high = max(A)
    low = 0
    while high > low + 1:
        mid = (high+low) // 2
        cnt = 0
        for x in A:
            cnt += math.ceil(x/mid) - 1
        if cnt > K:
            low = mid
        else:
            high = mid
    print(high)



if __name__ == '__main__':
    main()

Measured memory_bytes: 100180
program sum_of_three_integers
  implicit none
  integer :: k, s, x, y, m
  read(*,*) k, s
  m = 0
  do x = 0, min(k,s)
    do y = 0, min(k,s-x)
      if (s-x-y.le.k) m = m+1
    end do
  end do
  write(*,'(i0)') m
  stop
end program sum_of_three_integers

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std ;

const int N = 200010 ;

int n ;
int m ;
int top ;
int cnt ;
char s[N] ;
int sz[N] ;
int stk[N] ;

int main(){
    cin >> (s + 1) ;
    n = strlen(s + 1) ;
    if (s[1] == '0') return puts("-1"), 0 ;
    if (s[n] == '1') return puts("-1"), 0 ;
    for (int i = 1 ; i < n ; ++ i)
        if (s[i] != s[n - i]) return puts("-1"), 0 ;
    /*
    for (int i = 1 ; i < n ; ++ i)
        if (s[i] == '1') stk[++ top] = i ;
    stk[++ top] = n ; int k ; cnt = 0 ;
    while (top) sz[++ cnt] = stk[top --] ;
    for (int i = 1 ; i < cnt ; ++ i)
        printf("%d %d\n", i, i + 1), sz[i] -= sz[i + 1] ;
    k = cnt ;
    for (int i = 1 ; i <= cnt ; ++ i)
        for (int j = 1 ; j <= sz[i] ; ++ j)
            printf("%d %d\n", i, ++ cnt) ;
    */
    m = 1 ;
    for (int i = 1 ; i < n ; ++ i){
        cout << i + 1 << " " << m << endl ;
        if (s[i] == '1') m = i + 1 ;
    }
    return 0 ;
}


Measured memory_bytes: 1536
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 998244353
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int main(){
  int N;cin>>N;
  int i,j;
  string s[N];
  string t[N];
  int score[N];
  int A[N];
  int B[N];
  rep(i,N){
    cin>>s[i]>>A[i];
    t[i]=s[i];
    B[i]=A[i];
  }
  sort(s,s+N);
  int cnt=1000000;
  rep(i,N){
    if(i>0 and s[i]==s[i-1]) continue;
    else cnt-=1000;
    rep(j,N){
      if(s[i]==t[j]) A[j]+=cnt;
    }
  }
  sort(A,A+N);
  rep(i,N){
    //cout<<A[i]<<endl;
  }
  for(i=N-1;i>=0;i--){
    rep(j,N){
      if(A[i]%1000==B[j]) cout<<j+1<<endl;
    }
  }

}


Measured memory_bytes: 256
a,b,k = map(int,input().split())
takahashi = 0
aoki = 0
if a >= k:
    takahashi = a-k
    aoki = b
else:
    takahashi = 0
    aoki = b-k+a
if aoki < 0:
    aoki = 0
print(takahashi,aoki)

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

int main()
{
    int M, K;
    cin>>M>>K;

    if (M==1)
    {
        if (K==0)
            cout<<"0 0 1 1"<<endl;
        else
            cout<<-1<<endl;
    }
    else
    {
        if (K<1<<M)
        {
            vector<int> a;
            for (int i=0; i<=K; i++)
                a.push_back(i);
            for (int i=K-1; i>=0; i--)
                a.push_back(i);
            for (int i=(1<<M)-1; i>=K; i--)
                a.push_back(i);
            for (int i=K+1; i<1<<M; i++)
                a.push_back(i);
            for (int i=0; i<1<<(M+1); i++)
                cout<<(i==0?"":" ")<<a[i];
            cout<<endl;
        }
        else
        {
            cout<<-1<<endl;
        }
    }


    /*
    vector<int> a;
    for (int i=0; i<1<<M; i++)
    {
        a.push_back(i);
        a.push_back(i);
    }
    do
    {
        bool ok = true;
        for (int i=0; i<1<<(M+1) && ok; i++)
        for (int j=0; j<i && ok; j++)
        if (a[j]==a[i])
        {
            int t = 0;
            for (int k=j; k<=i; k++)
                t ^= a[k];
            if (t != K)
                ok = false;
        }
        if (ok)
        {
            for (int i=0; i<1<<(M+1); i++)
                cout<<(i==0?"":" ")<<a[i];
            cout<<endl;
            return 0;
        }
    }
    while(next_permutation(a.begin(), a.end()));

    cout<<-1<<endl;
    */
}


Measured memory_bytes: 2932
n,m,l=map(int,input().split())
a = []
b = []
for i in range(n):
    a.append(list(map(int, input().split())))
for i in range(m): 
    b.append(list(map(int, input().split())))
lst3=[]
for i in range(n):
    for j in range(l):
        c=0
        for k in range(m):
            c+=a[i][k]*b[k][j]
        if j == l-1 :
            print(c)
        else :
            print(c,end=" ")


Measured memory_bytes: 6576
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <ctime>
#include <list>
#include <numeric>
#include <utility>
#include <ctime>
#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007
 
#define rep(i,n) for(int i=0;i<int(n);i++)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
 
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;
 
/*---------------------------------------------------*/

int main(){
  int m;
  cin>>m;
  cout<<24-m+24<<endl;
  return 0;
}


Measured memory_bytes: 256
//#include "pch.h"
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
#include <numeric>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = 3.14159265359;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };






signed main() {
	int x, y, z;

	cin >> x >> y >> z;

	swap(x, y);
	swap(x, z);

	cout << x << " " << y << " " << z << endl;



	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<list>
#include <array>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807
#define INF I64_MAX
#define MOD 1000000007
#define MEM_SIZE = 1e5+5;

template<typename T> void DEBUG(T e){std::cout <<"DEBUG>>"<< e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ DEBUG(v); } }

//-----CODE------//

void solve(void)
{
  int H,W;
  cin>>H>>W;
  int N;
  cin>>N;
  int A = max(H,W);
  int X = 1;
  if(N%A == 0)X=0;
  cout<<N/A+X<<endl;
  return;
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(8);
  solve();

 
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define For(i,a,b) for(i=(a);i<=(b);++i)
#define Forward(i,a,b) for(i=(a);i>=(b);--i)
#define Rep(i,a,b) for(register int i=(a);i<=(b);++i)
#define Repe(i,a,b) for(register int i=(a);i>=(b);--i)
using namespace std;
template<typename T>inline void read(T &x)
{
	T s=0,f=1;char k=getchar();
	while(!isdigit(k)&&(k^'-'))k=getchar();
	if(!isdigit(k)){f=-1;k=getchar();}
	while(isdigit(k)){s=s*10+(k^48);k=getchar();}
	x=s*f;
}
/*void init()
{
}
void solve()
{
}*/
char s[100];
void done()
{
	printf("NO\n");
	exit(0);
}
int main()
{
	//file();
	//init();
	//solve();
	scanf("%s",s);
	if(strlen(s)>9)done();
	int i=0;
	if(s[i]=='K')++i;
	else if(s[i]=='A'&&s[i+1]=='K')i+=2;
	else done();
	if(s[i]!='I')done();
	++i;
	if(i>=strlen(s))done();
	if(s[i]!='H')done();
	++i;
	if(i>=strlen(s))done();
	if(s[i]=='B')++i;
	else if(s[i]=='A'&&s[i+1]=='B')i+=2;
	else done();
	if(i>=strlen(s))done();
	if(s[i]=='R')++i;
	else if(s[i]=='A'&&s[i+1]=='R')i+=2;
	else done();
	if(i==strlen(s)||i==strlen(s)-1&&s[i]=='A')printf("YES\n");
	else done();
	return 0;
}



Measured memory_bytes: 256
N=int(input())
a=list(map(int,input().split()))
sum = int(0)
arai = int(0)
ans = int(0)
mini = float('inf')

for i in range(N):
	sum+=a[i]
for i in range(N-1):
	ans+=a[i]
	arai=sum-ans
	mini=min(mini,float(abs(ans-arai)))

print(int(mini))


Measured memory_bytes: 24832
# l = list(map(int,input().split()))
n = int(input())
digit = len(str(n))

if digit % 2 == 0:
        start_d = digit-1
        check = False
else:
        start_d = digit -2
        check = True
cn = 0
for d in range(start_d, 0, -2):
        mx = 10 ** d - 1
        mn = 10 ** (d-1) 
        cn += (mx - mn + 1)
        # print('for',cn)
if check:
        cn += n - 10**(digit-1) +1
# print('res',cn)
print(cn)


Measured memory_bytes: 3060
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

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

    double ans = ((n + 1) / 2) / (double)n;
    printf("%.10f\n", ans);

    return 0;
}


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

typedef long long ll;
typedef long double ld;
#define L(ID) ((ID*2)+1)
#define R(ID) ((ID*2)+2)
#define M(L,R) ((L+R)/2)
#define forr(start,end) for(int i = start; i < end; i++)
#define gap ' '
 
const int MAXN = 2e5+5;

int largest(int a, int b){
	return (a<b)?b:a;
}


int main() {
	string a,b,c;
	cin >> a >> b >> c;
	if(a[a.length()-1] == b[0] and b[b.length()-1] == c[0]){
		cout << "YES" << endl;
	}
	else{
		cout << "NO" << endl;
	}

    return 0;
}	

Measured memory_bytes: 256
c[];main(n,m,i){for(;scanf("%d%d",&m,&n)*m;puts("")){int q[1024]={i=0},t=1,p=m;for(;n--;){*c=!scanf("%s",c+3);++i%3||strcat(c,"Fizz");i%5||strcat(c,"Buzz");*c||sprintf(c,"%d",i);for(strcmp(c+3,c)&&p>1&&(q[t]=p--);q[t=t%m+1];);}for(t=i=0;m--;q[++i]||(t=printf(" %d"+!t,i)));}}

Measured memory_bytes: 636
n, k = map(int, input().split())
arr = [0 for _ in range(n)]

for i in range(k):
    d = int(input())
    a = list(map(int, input().split()))
    for v in a:
        arr[v-1] += 1
ans = 0
for i in arr:
    if i == 0:
        ans += 1
print(ans)


Measured memory_bytes: 67476
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  string s;
  in(s);
  s[3] = '8';
  out(s);
  memi;
}

Measured memory_bytes: 256
# coding: utf-8
M, D = map(int, input().split())
ans = 0
for m in range(1, M+1):
    for d in range(1, D+1):
        if len(str(d)) == 1:
            continue
        else:
            d1 = int(str(d)[0])
            d2 = int(str(d)[1])
            if d1*d2 == m and d1 >= 2 and d2 >= 2:
                ans += 1
print(ans)

Measured memory_bytes: 3060
import sys
from copy import copy
sys.setrecursionlimit(10**6)

#文字(数列)、最大数、何文字目か0からn-1、ゴールn n-1になったらプリント
def p(s,m,i,last):
    # a=97
    if i==last-1:
        print("".join([chr(97+j)for j in s]))
        return
    for k in range(m+2):
        S=copy(s)
        S.append(k)
        p(S,max(m,k),i+1,last)

def main():
    n=int(input())
    s=[0]
    p(s,0,0,n)

main()

Measured memory_bytes: 4908
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define IFOR(i, m, n) for(ll i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main(){
  ll N, K; cin >> N >> K;
  vector<ll> v(N);
  REP(i,N) cin >> v[i];
  ll ans = 0;
  //左からl,右からrとる
  REP(l,min(N,K)+1) REP(r,min(N,K)-l+1){
    vector<ll> b;
    REP(i,l) b.push_back(v[i]);
    FOR(i,N-r,N) b.push_back(v[i]);
    sort(ALL(b));
    ll t = 0;
    ll pass = K-(l+r);
    REP(i,SZ(b)){
      if(pass>0&&b[i]<0) pass--;
      else t += b[i];
    }
    ans = max(ans,t);
  }
  cout << ans << endl;
}



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

int main() {
	ios::sync_with_stdio(false);
	int A, B;
	cin >> A >> B;

	if (A == B) {
		cout << (A * 2) << "\n";
	}
	else {
		cout << (max(A, B) * 2 -1) << "\n";
	}
	return 0;
}

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

using namespace std;


int main() 
{
   


                
        
        


    int k;
    cin>>k;
    string s;
    cin>>s;
    if(s.length()<=k)cout<<s<<endl;
    else 
    {
        for(int i=0;i<k;i++)cout<<s[i];
            cout<<"..."<<endl;
    }
        
        
           
    




}

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

int main() {
	ll N,r=0,c=0;
	cin >> N;
	vector<ll> A(N),t;
	rep(i,N)
		cin >> A.at(i);
	sort(A.begin(), A.end(), greater<ll>());

	t.push_back(A.at(0));
	rep(i,N-1) {
		r += t.at(c++);
		t.push_back(A.at(i+1));
		t.push_back(A.at(i+1));
	}
	cout << r << endl;
}

Measured memory_bytes: 8952
fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim_right().to_owned()
}

fn to_vec(s: String, offset: u64) -> Vec<u64> {
    s.split_whitespace()
        .map(|s| s.parse::<u64>().unwrap() - offset)
        .collect()
}

fn flip(mut facings: Vec<bool>, l: usize, r: usize) -> Vec<bool> {
    let len = r - l + 1;
    for i in 0..((len + 1) / 2) {
        let c = l + i;
        facings[c] = !facings[c];
        if c != r - i {
            facings.swap(c, r - i);
            facings[c] = !facings[c];
        }
    }
    facings
}

fn count_edge(facings: &Vec<bool>) -> u64 {
    let last = facings.len() - 1;
    (!facings[0] && !facings[1]) as u64 + (facings[last - 1] && facings[last]) as u64
}

fn count_mid(facings: Vec<bool>) -> u64 {
    facings
        .windows(3)
        .map(|w| if w[1] && w[0] {
            1
        } else if !w[1] && !w[2] {
            1
        } else {
            0
        })
        .sum()
}

fn find_happy_factor(facings: &Vec<bool>, base: usize) -> Option<(usize, usize)> {
    let mut first: Option<(usize, bool)> = None;
    for i in base..(facings.len() - 1) {
        let w = [facings[i], facings[i + 1]];
        // LR
        if w[0] && !w[1] {
            // LR -> RL
            if let Some((l, is_lr)) = first {
                if !is_lr {
                    return Some((l, i));
                }
            } else {
                first = Some((i + 1, true));
            }
        }
        // RL
        else if !w[0] == w[1] {
            // RL -> LR
            if let Some((l, is_lr)) = first {
                if is_lr {
                    return Some((l, i));
                }
            } else {
                first = Some((i + 1, false));
            }
        }
    }

    if let Some((l, is_lr)) = first {
        let last = *facings.last().unwrap();
        if (is_lr && !last) || (!is_lr && last) {
            return Some((l, facings.len() - 1));
        }
    }

    None
}

fn main() {
    let v = to_vec(read_line(), 0);
    let (_, k) = (v[0], v[1]);
    let mut facings: Vec<bool> = read_line().chars().map(|c| c == 'L').collect();

    if facings.len() == 1 {
        println!("0");
        return;
    }

    let mut i = 0;
    for _ in 0..k {
        if let Some((l, r)) = find_happy_factor(&facings, i) {
            i = l;
            facings = flip(facings, l, r);
        } else {
            break;
        }
    }

    if facings.len() == 2 {
        println!("{}", count_edge(&facings));
    } else {
        println!("{}", count_edge(&facings) + count_mid(facings));
    }
}


Measured memory_bytes: 4352
#include<iostream>
using namespace std;
#define ll long long 
#define max 1e5+1

int n;
ll c[100001];
ll a,b;
ll l,r=1e9+10;

ll search(ll m){
  ll an=0;
  for(int i=0;i<n;i++){
    if(b*m>=c[i]);
    else{
      an+=(c[i]-b*m)/(a-b);
      if((c[i]-b*m)%(a-b)!=0) an++;
    }
  }
  return an;
}

int main(){
  cin>>n>>a>>b;
  for(int i=0;i<n;i++)
    cin>>c[i];

  while(r-l!=1){
    ll m = (r+l)/2;
    ll an = search(m);
    if(an<=m) r=m;
    else l = m;
  }

  cout<<r<<endl;

  return 0;
}



Measured memory_bytes: 1024
#include<stdio.h>
#include<string.h>
int main(void)
{
  int n,m=0,c,cc=0,ccc=0,cccc=0,i,j,t;
  char s[30],b[30];
  scanf("%s",s);  
  c=strlen(s);
  scanf("%d",&n);
  for(i=0;i<n;i++){
      scanf("%s",b);
      for(j=10;j<20;j++){
	b[j]=b[j-10];
      }
    for(j=0;j<20-c;j++){
	if(s[0]==b[j]){
	  for(t=0;t<c;t++){
	    if(s[t]==b[j+t])cc++;
	  }
	  if(cc==c)ccc++;
	}
	cc=0;
    }
    if(ccc>0)cccc++;
    ccc=0;
  }
  printf("%d\n",cccc);
  return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;
 
int main(void){
  int N, sum = 1;
  string input;
  vector<string> S;
  cin >> N;
  for(int i=0;i<N;i++){
    cin >> input;
    S.push_back(input);
  }
  sort(S.begin(), S.end());
  for(int i=0;i<N - 1;i++){
    if(S[i] != S[i+1]){
      sum++;
    }
  }

  cout << sum << endl;
  
  return 0;
}

Measured memory_bytes: 11660
//#define		FILE_INPUT_DEFINE
#ifdef		FILE_INPUT_DEFINE
#include	<fstream>
#endif		// FILE_INPUT_DEFINE

#include	<iostream>
#include	<cstdio>

#define		NIL			(-1)
#define		MAX			25

enum class RLI
{
	eRoot,
	eInternalNode,
	eLeaf
};

struct BinaryTree
{
	int		parent;
	int		left;
	int		right;
	int		depth;
	int		sibling;
	int		degree;
	int		height;
	RLI		rli;

	BinaryTree()
	{
		parent = left = right = sibling = height = NIL;
		degree = 0;
	}
};

BinaryTree		tree[MAX];

using namespace std;

int main()
{
#ifdef		FILE_INPUT_DEFINE
	// input from txt
	std::ifstream in(R"(C:\Temp\input.txt)");
	std::cin.rdbuf(in.rdbuf());
#endif		// FILE_INPUT_DEFINE

	int			n;
	cin >> n;

	int			id, left, right;

	for (int i = 0; i < n; i++)
	{
		cin >> id >> left >> right;
		tree[id].left = left;
		tree[id].right = right;

		if (NIL != left)
			tree[left].parent = id;
		if (NIL != right)
			tree[right].parent = id;
	}

	for (int i = 0; i < n; ++i)
	{
		if (NIL == tree[i].parent)
		{
			tree[i].rli = RLI::eRoot;
			tree[i].depth = 0;
		}
		else
		{
			if ((NIL == tree[i].right) && (NIL == tree[i].left))
			{
				tree[i].rli = RLI::eLeaf;
			}
			else
			{
				tree[i].rli = RLI::eInternalNode;
			}
		}

		if (RLI::eRoot != tree[i].rli)
		{
			int		index = i;
			int		depth = 0;
			while (NIL != tree[index].parent)
			{
				++depth;
				index = tree[index].parent;
			}
			tree[i].depth = depth;

			if (tree[tree[i].parent].right == i)
			{
				tree[i].sibling = tree[tree[i].parent].left;
			}
			else
			{
				tree[i].sibling = tree[tree[i].parent].right;
			}
		}

		if (NIL != tree[i].left)
		{
			++tree[i].degree;
		}

		if (NIL != tree[i].right)
		{
			++tree[i].degree;
		}

		if ((tree[i].rli == RLI::eLeaf) || (1 == n))
		{
			tree[i].height = 0;
		}
	}

	bool	isLoop = true;

	while (isLoop)
	{
		isLoop = false;

		for (int i = 0; i < n; ++i)
		{
			if (NIL == tree[i].height)
			{
				int	r = tree[tree[i].right].height;
				int l = tree[tree[i].left].height;

				if ((NIL != r) && (NIL != l))
				{
					if (r >= l)
					{
						tree[i].height = r + 1;
					}
					else
					{
						tree[i].height = l + 1;
					}
				}
				else
				{
					isLoop = true;
				}
			}
		}
	}
	
	for (int i = 0; i < n; ++i)
	{
		printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",
			i, tree[i].parent, tree[i].sibling, tree[i].degree, tree[i].depth, tree[i].height);
		switch (tree[i].rli)
		{
		case RLI::eRoot:
			printf("root\n");
			break;
		case RLI::eInternalNode:
			printf("internal node\n");
			break;
		case RLI::eLeaf:
			printf("leaf\n");
			break;
		default:
			break;
		}
	}


	return 0;
}

Measured memory_bytes: 3220
#include <iostream>
using namespace std;
int N, S;
int main () {
  while (cin >> N && N>0) {
    int sum = 0;
    int largest = 0;
    int smallest = 1000;
    for (int i=0; i<N; ++i) {
      cin >> S;
      sum += S;
      if (largest < S) largest = S;
      if (smallest > S) smallest = S;
    }
    int average = (sum - largest - smallest) / (N-2);
    cout << average << endl;
  }
}

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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  vector<int> ABC = {A, B, C};
  sort(ABC.begin(), ABC.end());
  int a=ABC.at(0), b=ABC.at(1), c=ABC.at(2);
  int ans = 0;
  if ((c-a)%2==0 && (c-b)%2==0) ans += (c-a)/2+(c-b)/2;
  else if ((c-a)%2==1 && (c-b)%2==1) ans += (c-a)/2+(c-b)/2+1;
  else ans += (c-a)/2+(c-b)/2+2;
  cout << ans << endl;
}

Measured memory_bytes: 256