akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <unordered_map>
#include <map>
#include <list>
#include <valarray>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using lint = long long;
using namespace std;

typedef double number;
typedef valarray<number> point;
const int dim = 3;

const int MOD = 1000000007;

number dot(const point& a, const point& b) {
  return (a * b).sum();
}
point cross(const point& a, const point& b) {
  return a.cshift(+1)*b.cshift(-1)
       - a.cshift(-1)*b.cshift(+1);
}
number dist2(const point& a, const point& b) {
  return dot(a-b, a-b);
}

struct min_ball {
  point center;
  number radius2;
  void add(const point& p) {
    ps.push_back(p);
  }
  void compile() {
    m = 0;
    center.resize(dim, 0);
    radius2 = -1;
    make_ball(ps.end());
  }
  template <class OUT>
  void support(OUT out) {
    copy(ps.begin(), supp_end, out);
  }
  min_ball() {
    for (int i = 0; i <= dim; ++i) {
      c[i].resize(dim, 0);
      v[i].resize(dim, 0);
    }
  }
private:
  list<point> ps;
  list<point>::iterator supp_end;
  int m;
  point v[dim+1], c[dim+1];
  number z[dim+1], r[dim+1];
  void pop() { --m; }
  void push(const point& p) {
    if (m == 0) {
      c[0] = p; r[0] = 0;
    } else {
      number e = dist2(p, c[m-1]) - r[m-1];
      point delta = p - c[0];
      v[m] = p - c[0];
      for (int i = 1; i < m; ++i)
        v[m] -= v[i] * dot(v[i], delta) / z[i];
      z[m] = dot(v[m], v[m]);
      c[m] = c[m-1] + e*v[m]/z[m]/2;
      r[m] = r[m-1] + e*e/z[m]/4;
    }
    center  = c[m];
    radius2 = r[m]; ++m;
  }
  void make_ball(list<point>::iterator i) {
    supp_end = ps.begin();
    if (m == dim + 1) return;
    for (list<point>::iterator k = ps.begin(); k != i; ) {
      list<point>::iterator j = k++;
      if (dist2(*j, center) > radius2) {
        push(*j); make_ball(j); pop();
        move_to_front(j);
      }
    }
  }
  void move_to_front(list<point>::iterator j) {
    if (supp_end == j) ++supp_end;
    ps.splice (ps.begin(), ps, j);
  }
};

int main() {
    int N;
    cin >> N;
    min_ball res;
    rep(i, N) {
        double x, y;
        cin >> x >> y;
        point pos(0.0, 2);
        pos[0] = x;
        pos[1] = y;
        res.add(pos);
    }
    res.compile();

    long double r = res.radius2;
    r = sqrt(r);

    cout << fixed << setprecision(10) << r << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
	return os << "(" << x.first << "," << x.second << ")";
}
typedef long long ll;
typedef long double ld;
int main() {
	int l, r, d;
	scanf("%d%d%d", &l, &r, &d);
	printf("%d\n", r / d - (l - 1) / d);
}


Measured memory_bytes: 3760
#pragma GCC optimize("Ofast","inline","-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
//#define int long long
using namespace __gnu_pbds;
using namespace std;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

signed main()
{
	ios::sync_with_stdio(false);
	string s,t;
	cin>>s>>t;
	int ans=t.size(); 
	for(int i=0;i<s.size()-t.size()+1;i++){
		int cnt=0;
		for(int j=0;j<t.size();j++) cnt+=(t[j]!=s[j+i]);
		ans=min(ans,cnt);
	}
	cout<<ans<<endl;
	return 0;
}

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

public class Main {

	public static void main(String[] args) throws IOException {

		int a, b;

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String input = br.readLine();

//		1??????????????§???????????????????????????????????????????????????????´??????????
		String[] strArray = input.split(" ");

		a = Integer.parseInt(strArray[0]);
		b = Integer.parseInt(strArray[1]);

		if (a < b) {
			System.out.println("a < b");
		} else if (a > b) {
			System.out.println("a > b");
		} else {
			System.out.println("a == b");
		}
	}
}

Measured memory_bytes: 24356
// AOJ - ALDS1
// ALDS1_2_D - Shell sort
// https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/2/ALDS1_2_D

package main

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

func isorts(a []int, g int) (mv int) {
	// fmt.Printf("isorts(a %v, g %v) en:\n", a, g)
	n := len(a)
	for i := g; i < n; i++ { // 一定距離g離れたところから開始する
		v := a[i]
		j := i - g
		// fmt.Println("g", g, "i", i, "start", "a", a, "v", v)
		for j >= 0 && a[j] > v {
			a[j+g] = a[j]
			j = j - g
			mv++
		}
		a[j+g] = v
		// fmt.Println("g", g, "i", i, "done ", "a", a)
	}
	// fmt.Printf("isorts(a %v, g %v) ex:\n", a, g)
	return
}

func shellsort(a, G []int) (ret int) {
	for i := 0; i < len(G); i++ {
		ret += isorts(a, G[i])
	}
	return
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n := nextInt(sc)
	a := make([]int, n)
	for i := range a {
		a[i] = nextInt(sc)
	}
	G := make([]int, 0)
	gn := 1 // g(n+1) = 3*g(n)+1 を利用する
	// G = append(G, gn)
	for i := 0; gn <= n; i++ {
		G = append(G, gn)
		gn = 3*gn + 1
	}
	sort.Sort(sort.Reverse(sort.IntSlice(G)))
	cnt := shellsort(a, G)

	wtr := bufio.NewWriter(os.Stdout)
	fmt.Fprintln(wtr, len(G)) // m
	for i := 0; i < len(G); i++ {
		if i > 0 {
			fmt.Fprint(wtr, " ")
		}
		fmt.Fprint(wtr, G[i])
	}
	fmt.Fprintln(wtr)
	fmt.Fprintln(wtr, cnt)
	for i := 0; i < len(a); i++ {
		fmt.Fprintln(wtr, a[i])
	}
	wtr.Flush()
}
func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	t, _ := strconv.Atoi(sc.Text())
	return t
}



Measured memory_bytes: 17460
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using vll = vector<ll> ;
#define all(v) v.begin(),v.end()

struct UnionFind {
  vector<ll> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

  UnionFind(ll N) : par(N) { //最初は全てが根であるとして初期化
    for(ll i = 0; i < N; i++) par[i] = i;
  }

  ll root(ll x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }

  void unite(ll x, ll y) { // xとyの木を併合
    ll rx = root(x); //xの根をrx
    ll ry = root(y); //yの根をry
    if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
    par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
  }

  bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す
    ll rx = root(x);
    ll ry = root(y);
    return rx == ry;
  }
};

int main(){
  ll N,M;cin>>N>>M;
  UnionFind tree(N);
  ll ans=0;
  rep(i,M){
    ll a,b;cin>>a>>b;a--,b--;
    tree.unite(a,b);
  }
  for(ll i=0;i<N;++i){
    if(tree.same(0,i)!=1){
      ans++;
      tree.unite(0,i);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 4080
from sys import stderr, setrecursionlimit
setrecursionlimit(2147483647)
def getInt():
    return int(input())
def getInts():
    return [int(i) for i in input().split()]
def getIntLines(n=1):
    res = []
    for _ in range(n):
        res.append(getInt())
    return res
def getIntsLines(n=1):
    res = []
    for _ in range(n):
        res.append(getInts())
    return res
def debug(*args, **kwargs):
    print(*args, file=stderr, **kwargs)

n = getInt()
ast = input()
bst = input()
cst = input()

ans = 0

for a, b, c in zip(ast,bst,cst):
    if a == b == c:
        continue
    elif a == b or b == c or c == a:
        ans += 1
    else:
        ans += 2
print(ans)

Measured memory_bytes: 3064
using System;

namespace volume
{
    class Program
    {
        static void Main(string[] args)
        {
            for (int i = 0; i < 9; i++)
            {
                for (int j = 0; j < 9; j++)
                    Console.WriteLine("{0}{1}{2}{3}{4}", i+1, "x", j+1, "=", (i+1) * (j+1));
            }
        }
    }
}



Measured memory_bytes: 15824
#include "bits/stdc++.h"
using namespace std;
#define long int64_t

struct Solver {
	void solve() {
		array<int, 5> x;
		for( auto& v: x ) { cin >> v; }
		for( int i = 0; i < 5; ++i ) {
			if( x[i] == 0 ) {
				cout << i+1 << endl;
			}
		}
	}
};

int main() {
	ios::sync_with_stdio( false );
	cout << fixed << setprecision( 10 );
	Solver().solve();
	return 0;
}


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

int main() {
    int H, W, D;
    cin >> H >> W >> D;
    vector<string> S(H);
    for(auto &e : S) cin >> e;
    vector<vector<int>> row(H, vector<int>(W));
    vector<vector<int>> col(H, vector<int>(W));
    rep(i, H) rep(j, W) {
        row[i][j] = S[i][j] == '.';
        col[i][j] = S[i][j] == '.';
    }
    rep(i, H) {
        for(int j = 1; j < W; ++j) {
            if(S[i][j] == '#') continue;
            row[i][j] = row[i][j - 1] + 1;
        }
    }
    rep(j, W) {
        for(int i = 1; i < H; ++i) {
            if(S[i][j] == '#') continue;
            col[i][j] = col[i - 1][j] + 1;
        }
    }
    int ans = 0;
    rep(i, H) rep(j, W) {
        if(row[i][j] >= D) ans++;
        if(col[i][j] >= D) ans++;
    }
    cout << ans << '\n';
    return 0;
}



Measured memory_bytes: 3248
#include<bits/stdc++.h>
using namespace std;
long long n, a[405], ans[405][405], ac[405];

int main(){
    scanf("%lld", &n);
    for(int i = 0; i < n; i++){
        scanf("%lld", a+i);
        ac[i+1] = ac[i] + a[i];
    }
    for(int i = 2; i <= n; i++){
        for(int j = 0; j <= n-i; j++){
            ans[j][j+i] = 1e15;
            for(int k = 1; k < i; k++){
                ans[j][j+i] = min(ans[j][j+i], ans[j][j+k] + ans[j+k][j+i]);
            }
            ans[j][j+i] += ac[j+i] - ac[j];
        }
    }
    printf("%lld\n", ans[0][n]);
}

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

int main() {
string s,m;
cin >> s >> m ;
if(s[0] == m[2] && s[1] == m[1] && s[2] == m[0]){
	cout << "YES" <<endl;
}
else{
	cout << "NO" << endl;
	
}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
const int MAXN=3010;
int n;
int a[MAXN];
ll dp[2][MAXN][MAXN];
ll solve(int pl,int lo,int hi){
	if(lo>hi) return 0;
	ll &ret=dp[pl][lo][hi];
	if(ret) return ret;
	if(!pl) ret=max(solve(1,lo+1,hi)+a[lo],solve(1,lo,hi-1)+a[hi]);
	if(pl) ret=min(solve(0,lo+1,hi)-a[lo],solve(0,lo,hi-1)-a[hi]);
	return ret;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	cout<<solve(0,0,n-1)<<"\n";
	return 0;
}

Measured memory_bytes: 141696
#include<bits/stdc++.h>
#define ll long long int
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define rep(n) for(ll i2=0;i2<n;i2++)
#define vmp(v,a,b) v.push_back(make_pair(a,b))
#define si(a) scanf("%lld",&a)
#define pi(a) printf("%lld",a)
#define aset(a,n,k) for(ll i3=0;i3<n;i3++)a[i3]=k; 	
#define mod 1000000007
#define mp(a,b) make_pair(a,b)
#define f first
#define s second 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,greater_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_orde(ind)
using namespace std;
int main()
{
	sync;
	ll a,b,k,cnt=0;
	cin>>a>>b>>k;
	for(ll i=__gcd(a,b);i>=1;i--)
	if(__gcd(a,b)%i==0)
	{
		cnt++;
		if(cnt==k)
		{
			cout<<i;
			break;
		}
	}
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	
	int a,b,c,tmp;

	scanf("%d %d %d\n",&a,&b,&c);

	if(a>b){
		tmp = a;
		a = b;
		b = tmp;
	}
	if(b>c){
		tmp = b;
		b = c;
		c = tmp;
	}
	if(a>b){
		tmp = a;
		a = b;
		b = tmp;
	}
	printf("%d %d %d\n",a,b,c);

	return 0;
}

Measured memory_bytes: 1028
#include<bits/stdc++.h>
/*	#include <boost/math/common_factor.hpp>  boost::math::lcm(10,20) ---> use it to find lcm.*/
using namespace std;
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long ll;
// #define int long long 
#define PI pair<int , int >
#define mpr make_pair
#define ff first
#define ss second
#define endl "\n"
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define FO(i,a,b) for(int i = (int)a;i < (int)b;++i)
#define FE(i,a,b) for(int i = (int)a;i <= (int)b;++i)
const int MOD = 1e9+7;
const int MAXN = 1e5+3;
const int inf = 2e9;
int max(int a,int b){	if(a > b)return a; else return b; }
int min(int a, int b){	if(a < b)return a; else return b; }
int dx[] = {1,-1,0,0};
int dy[] = {0,0,-1,1};
bool cmp(PI p1,PI p2){
	if(p1.ff < p2.ff)return true;	// You should not be writing p1.ss <= p2.ss !!!
	else if(p1.ff == p2.ff){ if(p1.ss < p2.ss)return true; return false; }
	return false;
}
/*		1. Take all the inputs
		4. Whenever you do multiplication and division in the same line, beware.
*/
void solve(){
	// int main  or  int32_t main ...
	int k,sum = 0,tmp;
	cin >> k;
	FE(i,1,k){
		FE(j,1,k){
			FE(l,1,k){
				tmp = __gcd(i,__gcd(j,l));
				//cout << i << " " << j << " " << l << " " << tmp << endl;
				sum += tmp;
			}
		}
	}
	cout << sum << endl;
}
/*	memset() can be used to set all values as 0 or -1 for integer data types.*/

int main(){
	IO;
	#ifndef ONLINE_JUDGE
	//freopen("input.txt", "r", stdin);
	#endif // ONLINE_JUDGE
	// std::cout << std::setprecision(15); std::cout << std::fixed;
	int t; t = 1;
	// cin >> t;
	while(t--){ solve(); }
	return 0;
}



Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9;
using namespace std;
using ll = long long;
int main() {
    int a , b , h;
    cin >> a >> b >> h;
    cout << (a + b) * h / 2 << endl;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ALL(a) (a).begin(), (a).end()
const ll mod = 1e9 + 7;

int main()
{
    int n;
    cin >> n;
    vector<ll> d(n);
    rep(i, n) cin >> d[i];
    int m;
    cin >> m;
    vector<ll> t(m);
    rep(i, m) cin >> t[i];
    sort(ALL(d));
    sort(ALL(t));
    int i = 0, j = 0;
    while (i < n || j < m)
    {
        if (d[i] == t[j])
        {
            i++;
            j++;
        }
        else if (d[i] < t[j])
        {
            i++;
        }
        else
        {
            break;
        }
    }
    if (j == m)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(long long i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }


int main(){
    while(true){
        ll n, q; cin >> n >> q;
        if(n == 0 && q == 0) break;
        vector<ll> tree(n+1, -1);
        map<ll,ll> ismarked;
        tree[1] = 0;
        rep(i, n-1){
            ll p; cin >> p;
            tree[i+2] = p;
        }
        ismarked[1] = 1;
        ll res = 0;
        rep(i, q){
            char id; cin>>id;
            ll v; cin >> v;
            if(id == 'M'){
                ismarked[v] = 1;
            }else{
                if(ismarked[v] > 0){
                    res += v;
                    continue;
                }
                ll w = tree[v];
                while(ismarked[w] == 0){
                    w = tree[w];
                }
                res += w;
            }
        }
        cout << res << endl;
    }
    return 0;
}


Measured memory_bytes: 9660
#include<iostream>

using namespace std;

int n, A[50];
int solve(int i,int m){
	if(m==0)return 1;
	if(i>=n)return 0;
	bool sum=solve(i+1,m) || solve(i+1,m-A[i]);
	return sum;
}

int main(void){
	int q,m,i;
	cin >> n;
	for(i = 0; i < n; i++)cin >> A[i];
	
	cin >> q;
	for(i = 0; i < q; i++){
		cin >> m;
		if(solve(0,m))cout << "yes" << endl;
		else cout << "no" << endl;
	}
	
	return 0;
}


Measured memory_bytes: 3108
A, B, M = map(int, input().split())

A = list(map(int, input().split()))
B = list(map(int, input().split()))
xyc = [list(map(int, input().split())) for i in range(M)]

ans = min(A)+min(B)

for i in range(M):
    if A[xyc[i][0]-1]+B[xyc[i][1]-1]-xyc[i][2] < ans:
        ans = A[xyc[i][0]-1]+B[xyc[i][1]-1]-xyc[i][2]

print(ans)

Measured memory_bytes: 38568
# https://atcoder.jp/contests/abc123/tasks/abc123_c

n = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())


MIN = min([a, b, c, d, e])
if n % MIN == 0:
    ans = 5 + n // MIN - 1
else:
    ans = 5 + n // MIN
print(ans)

Measured memory_bytes: 61868
#include <stdio.h>
#define mod 1000000007
typedef long long ll;

ll rev(ll a) {
  ll ans = 1, now = mod - 2;
  while(now) {
    if(now & 1) ans *= a, ans %= mod;
    a *= a, a %= mod, now >>= 1;
  }
  return ans;
}

int main(void) {
  ll i, j, k, n, sum = 0, ans, a, b;
  scanf("%lld%lld", &n, &k);
  ll cnt[n], fact[k + 1];
  for(i = 0; i < n; ++i) cnt[i] = 0;
  fact[0] = 1;
  for(i = 1; i <= k; ++i) fact[i] = fact[i - 1] * i, fact[i] %= mod;
  for(i = 1; i < n; ++i) scanf("%lld%lld", &a, &b), cnt[--a]++, cnt[--b]++;
  if(cnt[0] >= k) {
    printf("0");
    return 0;
  }
  ans = fact[k] * rev(fact[k - cnt[0] - 1]);
  ans %= mod;
  for(i = 1; i < n; ++i) {
    if(cnt[i] >= k) {
      printf("0");
      return 0;
    }
    ans *= fact[k - 2];
    ans %= mod;
    ans *= rev(fact[k - cnt[i] - 1]);
    ans %= mod;
  }
  printf("%lld", ans);
  return 0;
}

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

#define ll long long int
#define f(i, a, b) for(ll i=a;i<b;i++)
#define fi(i, a, b) for(ll i=b-1;i>=a;i--)
#define pb push_back
#define vi vector<int>
#define vl vector<ll>
#define ml map<ll,ll>
#define pll pair<ll,ll>
int main(){
  int n;
  cin>>n;


  string s;
  cin>>s;

  int i=0,j=n-1;
  int count =0;
  while(i<j){
       while(i<n  &&  s[i]=='R')
       i++;
       while(j>=0  && s[j]=='W')
       j--;

       if(j<=i)
       break;
       i++;
       j--;
       count++;
    }

    cout<<count;
 }


Measured memory_bytes: 3736
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
ll p[20];
int m;
int main()
{
    ll n; cin>>n;
    ll c[20];
    c[0]=0;
    p[0]=1, p[1]=26;
    for(int i=2; ; i++){
        p[i]=p[i-1]*26;
        if(p[i]>n){
            m=i;
            break;
        }
    }
    for(int i=1; i<=m; i++) c[i]=c[i-1]+p[i];
    for(int i=1; i<=m; i++){
        if(c[i]>=n){
            m=i;
            break;
        }
    }
    n-=c[m-1];
    string ans;
    for(int i=0; i<m; i++){
        for(int j=0; j<26; j++){
            if(n<=(j+1)*p[m-1-i]){
                n-=j*p[m-1-i];
                ans+=(char)('a'+j);
                break;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3612
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
using namespace std;

const long long int INF=99999999999999,inf=199999;
const long long int mod=1000000007;

long double x1,y,x2,y2,x3,y3,a,b,c,s,r,S,mymax;
int main() {
    
	cout << fixed << setprecision(10);
	cin>>x1>>y>>x2>>y2>>x3>>y3;
	a=sqrt((x2-x1)*(x2-x1)+(y2-y)*(y2-y));
	b=sqrt((x2-x3)*(x2-x3)+(y2-y3)*(y2-y3));
	c=sqrt((x3-x1)*(x3-x1)+(y3-y)*(y3-y));
	s=(a+b+c)/2;
	S=sqrt(s*(s-a)*(s-b)*(s-c));
	r=S/s;
	mymax=max({a,b,c});
	cout<<mymax/(2+mymax/r)<<endl;
} 


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
    	Scanner input = new Scanner(System.in);
      	int N = input.nextInt();
      	int K = input.nextInt();
      	int[] X = new int[N];
      	int smallGap = 1000000000;
      
      	for (int i = 0; i < N; i++) {
        	X[i] = input.nextInt();
        }

      	for (int i = 0; i < N - K + 1; i++) {
        	int min = X[i];
          	int max = X[i + K - 1];
          	int gap1;
          	int gap2;
          	int gap = 1000000000;
          	if (min < 0 && max > 0) {
            	gap1 = max - (min * 2);
            	gap2 = (max * 2) - min;
              	gap = Math.min(gap1, gap2);
            } else if (max <= 0) {
            	gap = - min;
            } else {
              	gap = max;
            }
          	if (gap < smallGap) {
              	smallGap = gap;
            }
        }
      
      System.out.print(smallGap);

    }
}


Measured memory_bytes: 48908
#include <bits/stdc++.h>
 
using namespace std;
 
#define MAX 3001
  
int N, S, T, a[MAX], b[MAX];
int dp[MAX][MAX], ans;
  
void solve(){
    for(int i = 1 ; i <= N ; i++){
	for(int j = 1 ; j <= T ; j++){
	    dp[i][j] = max(dp[i][j-1], dp[i-1][j]);;
	    int k = j - b[i];
	    if(k >= 0 && !(j-b[i] < S && S < j)){
		dp[i][j] = max(dp[i][j], dp[i-1][k] + a[i]);
	    }
	}
    }
    ans = -1;
    for(int i = 1 ; i <= T ; i++){
	ans = max(ans, dp[N][i]);
    }
    cout << ans << endl;
}
  
int main(){
    cin >> N >> T >> S;
    for(int i = 1 ; i <= N ; i++){
	cin >> a[i] >> b[i];
    }
    solve();
    return 0;
}

Measured memory_bytes: 38288
n,m = map(int,input().split())

dp = [0] * n
mod = 10**9 + 7


if n == 1:
    print((m-n) * m % mod)
elif n == 2:
    ans = (m - n)**2 + (m - n + 1)
    for i in range(2):
        ans *= (m - i)
        ans %= mod
    print(ans)
else:
    dp[0] = m - n
    dp[1] = (m - n)**2 + (m - n + 1)


    for i in range(2, n):
        dp[i] = (dp[i-1] + dp[i-2]) * i + dp[i-1] * (m - n)
        dp[i] %= mod

    ans = dp[-1]

    for i in range(n):
        ans *= (m - i)
        ans %= mod

    print(ans)


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

int main () {
  int h, w;
  cin >> h >> w;
  string board[50];

  for (int i = 0; i < h; ++i) cin >> board[i];

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

  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (board[i][j] == '#') continue;

      int num = 0;
      for (int d = 0; d < 8; ++d) {
        const int ni = i + dy[d];
        const int nj = j + dx[d];

        if (ni < 0 or ni >= h) continue;
        if (nj < 0 or nj >= w) continue;
        if (board[ni][nj] == '#') num++;
      }
      board[i][j] = char(num + '0');
    }
  }
  for (int i = 0; i < h; ++i) cout << board[i] << endl;
}


Measured memory_bytes: 256
n=int(input())

h=list(map(int,input().split()))
dp=[0]*n
dp[0]=0
dp[1]=abs(h[1]-h[0])
for i in range(1,n-1):
  dp[i+1]=min(dp[i-1]+abs(h[i+1]-h[i-1]),dp[i]+abs(h[i+1]-h[i]))

print(dp[n-1])



Measured memory_bytes: 20356
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;
typedef long long ll;

int main(){
    ll n, m;
    cin >> n >> m;
    vector<ll>a(m, 0);
    REP(i, m) cin >> a[i];

    sort(ALL(a));

    vector<ll> dist(m-1, 0);

    REP(i, m-1){
        dist[i] = a[i+1] - a[i];
    }

    sort(ALL(dist), greater<int>());

    ll ans = 0;

    FOR(i, n-1, m-1){
        ans += dist[i];
    }

    cout << ans << endl;


}


Measured memory_bytes: 4700
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <list>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <fstream>
#include <sstream>
#include <unordered_map>
#include <ctime>
using namespace std;

const unsigned long long BASE = (unsigned long long)(1e9 + 7);

#define FROM_0(i, n) for(int i = 0; i < (n); i++)
#define FROM_S(i, s, e) for(int i = (s); i < (e); i++)
#define ITER_BEGIN_END(iter, vec) for(auto iter = vec.begin(); iter != vec.end(); iter++)

int main()
{
    char b;
    cin >> b;
    if (b == 'A')
        cout << 'T' << endl;
    else if (b == 'T')
        cout << 'A' << endl;
    else if (b == 'C')
        cout << 'G' << endl;
    else if (b == 'G')
        cout << 'C' << endl;
    return 0;
}


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

int prime(int X){
  for(int i=2;i<X;i++){
    if(X%i==0){
      return 0;
    }
  }
  return 1;
}

int main(){
  int X;
  cin >> X;
  while(1){
    if(prime(X)==1){
      cout << X << endl;
      break;
    }
    X++;
  }
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		
		String line1[] = sc.nextLine().split("");
		String line2[] = sc.nextLine().split("");
		String kekka = "NO";
		if (line1[0].equals(line2[2]) && line1[1].equals(line2[1]) && line1[2].equals(line2[0])) {
			kekka = "YES";
		}
       System.out.println(kekka);
	}
}

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

using namespace std;

typedef long long LL;

int main() {
    int h, w;
    cin >> h >> w;
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    vector<int> v;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < a[i]; j++) {
            v.push_back(i);
        }
    }

    vector< vector<int> > vv(h, vector<int>(w));
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            vv[i][j] = v[i * w + j];
        }
        if (i % 2 != 0) {
            reverse(vv[i].begin(), vv[i].end());
        }
    }

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cout << vv[i][j] + 1 << " ";
        }
        cout << endl;
    }

    return 0;
}


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

const int mod = 1000000007;
typedef long long LL;
void reduce(int & x) { x += x >> 31 & mod; }
int mul(int a, int b) { return (LL) a * b % mod; }
int pow(int a, int b, int res = 1) {
	for (; b; b >>= 1, a = mul(a, a)) if (b & 1) res = mul(res, a);
	return res;
}
const int MAXN = 100010;
int n, K, li[MAXN], bak, f[MAXN];
int main() {
	std::ios_base::sync_with_stdio(false), std::cin.tie(0);
	std::cin >> n >> K;
	for (int i = 1; i * i <= n; ++i)
		if (n % i == 0) {
			li[++bak] = i;
			if (i * i != n) li[++bak] = n / i;
		}
	std::sort(li + 1, li + 1 + bak);
	int ans = 0;
	for (int i = bak; i; --i) {
		f[i] = pow(K, n / li[i] + 1 >> 1);
		for (int j = i + 1; j <= bak; ++j)
			if (li[j] % li[i] == 0)
				reduce(f[i] -= f[j]);
		int r = n / li[i];
		reduce(ans += mul(f[i], r & 1 ? r : r >> 1) - mod);
	}
	std::cout << ans << std::endl;
	return 0;
}


Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10, gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
#from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = False

k = INT()
ans = 0
for a in range(1, k + 1):
    for b in range(a, k + 1):
        for c in range(b, k + 1):
            g = gcd(gcd(a, b), c)
            t = 6
            if a == b or b == c:
                t = 3
            if a == b == c:
                t = 1
            debug(g, t, a, b, c)
            ans += g * t
print(ans)

Measured memory_bytes: 69828
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100500;
int n = 0, m = 0, fir[maxn], nxt[maxn << 1], to[maxn << 1], dis[maxn];
int p = 0, q = 0;
bool dfs(int x, int las) {
	if(x == p) return true;
	if(x == q) return false;
	bool ok = false;
	for(int i = fir[x]; i; i = nxt[i]) {
		int y = to[i];
		if(y == las) continue;
		ok |= dfs(y, x);
	} return ok;
}
signed main() {
	ios::sync_with_stdio(false);
	cin >> n >> m;
	for(int i = 1, j = 0; i <= m; i++) {
		int a = 0, b = 0;
		cin >> a >> b;
		dis[a]++, dis[b]++;
		j++, nxt[j] = fir[a], fir[a] = j, to[j] = b;
		j++, nxt[j] = fir[b], fir[b] = j, to[j] = a;
	}
	for(int i = 1; i <= n; i++) {
		if(dis[i] & 1) {
			cout << "No" << endl;
			return 0;
		}
	}
	for(int i = 1; i <= n; i++) {
		if(dis[i] > 4) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	for(int i = 1; i <= n; i++) {
		if(dis[i] > 2) {
			if(q) {
				cout << "Yes" << endl;
				return 0;
			}
			if(p) q = i;
			else p = i;
		}
	}
	if(not q) {
		cout << "No" << endl;
		return 0;
	}
	for(int i = fir[p]; i; i = nxt[i]) {
		int x = to[i];
		if(dfs(x, p)) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3840
#include<bits/stdc++.h>
using namespace std;
int n[2],m[2];
vector<string> bo[2];
vector<vector<int> > adj[2];
int main(){
  for(int i=0;i<2;++i){
    cin >> n[i] >> m[i];
    bo[i].resize(n[i]);
    for(int j=0;j<n[i];++j)
      cin >> bo[i][j];
    adj[i].assign(n[i],vector<int>());
    for(int j=0;j<m[i];++j){
      int a,b;
      cin >> a >> b;
      adj[i][a-1].push_back(b-1);
    }
  }
  int pt[128][128];
  for(int i=0;i<n[0];++i)
    for(int j=0;j<n[1];++j)
      pt[i][j]=0;
  stack<tuple<int,int,int> > q;
  for(int i=0;i<n[0];++i)
    for(int j=0;j<n[1];++j)
      q.push(make_tuple(i,j,0));
  int answer=0;
  while(!q.empty()){
    int aki,maki,p;
    tie(aki,maki,p)=q.top();
    q.pop();
    if(p>100){
      cout << -1 << endl;
      return 0;
    }
    if(bo[0][aki]==bo[1][maki]){
      ++p;
      answer=max(answer,p);
      if(p<=pt[aki][maki])
	continue;
      pt[aki][maki]=p;
      for(int i=0;i<adj[0][aki].size();++i)
	for(int j=0;j<adj[1][maki].size();++j)
	  q.push(make_tuple(adj[0][aki][i],adj[1][maki][j],p));
    }
    else{
      if(p<=pt[aki][maki])
	continue;
      pt[aki][maki]=p;
      for(int i=0;i<adj[0][aki].size();++i)
	q.push(make_tuple(adj[0][aki][i],maki,p));
      for(int j=0;j<adj[1][maki].size();++j)
	q.push(make_tuple(aki,adj[1][maki][j],p));
    }
  }
  cout << answer << endl;
  return 0;
}

Measured memory_bytes: 11612
#include <iostream>
using namespace std;
int main(){
	int a,b,c;
	int con=0,num=0;
	cin>>a>>b>>c;
	if(a==5)con++;
	else{
		num++;
	}
	if(b==5)con++;
	else{
		num++;
	}
	if(c==5)con++;
	else{
		num++;
	}
	if(con==2)cout<<"YES"<<endl;
	else{
		cout<<"NO"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <string>
#include<algorithm>
#include <set>
#include <cmath>
using namespace std;
typedef long long lint;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rep0(i,n) rep(i,0,n)

int main(void) {
	ios::sync_with_stdio(false);
	string A;
	cin >> A;
	if (A == "Sunny") A = "Cloudy";
	else if (A == "Cloudy") A = "Rainy";
	else if (A == "Rainy") A = "Sunny";
	cout << A;
	return 0;
}

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

using namespace std;

const int INF = 1e9 + 7;

int r, g, b;

void solve()
{
  cin >> r >> g >> b;
  if((g * 10 + b) % 4) {
    cout << "NO\n";
  }else {
    cout << "YES\n";
  }
}

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

Measured memory_bytes: 256
N, W = gets.split.map(&:to_i)
value = []
weight = []
N.times do |i|
  value[i], weight[i] = gets.split.map(&:to_i)
end
dp = Array.new(N+1){Array.new(W+1, 0)}
(0...N).each do |i|
  (0..W).each do |j|
    if j < weight[i]
      dp[i+1][j] = dp[i][j]
    else
      dp[i+1][j] = [dp[i][j - weight[i]] + value[i], dp[i][j]].max
    end
  end
end
p dp[N][W]


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

int main() {
	int N, Y;
	cin >> N >> Y;
	for (int i = 0; i <= N; i++) {
		for (int j = 0; j <= N - i; j++) {
			int k = (Y - 10000 * i - 5000 * j) / 1000;
			if (k == N - i - j) {
				cout << i << " " << j << " " << k << endl;
				return 0;
			}
		}
	}
	cout << "-1 -1 -1" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define F first
#define S second

using namespace std;
typedef pair<int,int> P;

const int MOD=1000000007;
int INF=100100100100100;

signed main(){
  int n;cin>>n;
  string s;cin>>s;
  int sum=0;
  int ans=0;
  rep(i,n){
    if(s[i]=='#')sum++;
  }
  ans=sum;
  for(int i=n-1;i>=0;i--){
    if(s[i]=='#')sum--;
    else sum++;
    ans=min(ans,sum);
  }
  cout<<ans<<endl;
  return 0;
}

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

int s[110];
int main()
{
	int n;
	while(~scanf("%d", &n))
	{
		int sum = 0;
		int Min = 10010;
		for(int i=1;i<=n;i++)
		{
			scanf("%d", &s[i]);
			sum += s[i];
			if(s[i] < Min && s[i]%10 != 0)
			Min = s[i];
		}
		if(sum % 10 != 0)
		printf("%d\n", sum);
		else 
		{
			if(Min < sum)
			printf("%d\n",sum - Min);
			else 
			printf("0\n");
		}
		
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

static const ll MOD = 1e9 + 7;
ll s[501][501];

int main()
{
	ll n, m, q; cin >> n >> m >> q;

	rep(i, 0, m) {
		ll l, r; cin >> l >> r;
		s[r][l]++;
	}
	repe(i, 1, n)repe(j, 1, n) {
		s[i][j] += s[i][j - 1];
	}
	repe(j, 1, n)repe(i, 1, n) {
		s[i][j] += s[i - 1][j];
	}

	rep(i, 0, q) {
		ll P, Q; cin >> P >> Q;
		ll ans = s[Q][Q] - s[Q][P - 1] - s[P - 1][Q] + s[P - 1][P - 1];
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 2944
#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>;

const int MAX_N = 200005;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} comb(MAX_N);

vector<int> to[MAX_N];

struct DP {
  mint dp;
  int t;
  DP(mint dp=1, int t=0):dp(dp),t(t) {}
  DP operator+(const DP& a) const {
    return DP(dp*a.dp*comb(t+a.t, t), t+a.t);
  }
  DP addRoot() const {
    return DP(dp, t+1);
  }
};

vector<DP> dp[MAX_N];
DP ans[MAX_N];

DP dfs(int v, int p=-1) {
  DP dpSum;
  dp[v] = vector<DP>(to[v].size());
  rep(i,to[v].size()) {
    int u = to[v][i];
    if (u == p) continue;
    dp[v][i] = dfs(u,v);
    dpSum = dpSum + dp[v][i];
  }
  return dpSum.addRoot();
}
void bfs(int v, const DP& dpP=DP(), int p=-1) {
  int deg = to[v].size();
  rep(i,deg) if (to[v][i] == p) dp[v][i] = dpP;

  vector<DP> dpLeft(deg+1);
  rep(i,deg) dpLeft[i+1] = dpLeft[i] + dp[v][i];
  
  vector<DP> dpRight(deg+1);
  for (int i = deg-1; i >= 0; --i)
    dpRight[i] = dpRight[i+1] + dp[v][i];
  
  ans[v] = dpLeft[deg].addRoot();

  rep(i,deg) {
    int u = to[v][i];
    if (u == p) continue;
    DP d = dpLeft[i] + dpRight[i+1];
    bfs(u, d.addRoot(), v);
  }
}

int main() {
  int n;
  cin >> n;
  rep(i,n-1) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  dfs(0);
  bfs(0);
  rep(i,n) cout << ans[i].dp << endl;
  return 0;
}

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

int main()
{
    int n, a, b;
    cin >> n >> a >> b;

    vector<char> s(n);
    rep(i, n)
        cin >> s.at(i);

    int c = 0, cb = 0;

    rep(i, n) {
        if (s.at(i) == 'a') {
            if (c < (a + b)) {
                cout << "Yes" << endl;
                c++;
            } else {
                cout << "No" << endl;
            }
        } else if (s.at(i) == 'b') {
            if (c < (a + b) && cb < b) {
                cout << "Yes" << endl;
                c++;
                cb++;
            } else {
                cout << "No" << endl;
            }
        } else {
            cout << "No" << endl;
        }
    }
}

Measured memory_bytes: 3652
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <iomanip>
#include <string>
#include <queue>
#include <numeric>
#include <functional>
#include <array>
#include <map>
#include <set>

#define INF 1000000007 //1000000000000000003
#define MOD 1000000007

using namespace std;
using P = pair<long, long>;
using T = tuple<int, int, int>;
using edge = struct { int to; long long dist; };

vector<edge>tree[100010];
long long dist[100010];
long long dp[100005][4];

bool compare_by_second(pair<int, int> a, pair<int, int> b) {
	if (a.second != b.second) {
		return a.second < b.second;
	}
	else {
		return a.first < b.first;
	}
}

void dfs(int place,int root, long long cost) {
	dist[place] = cost;
	for (edge next : tree[place]) {
		if (next.to == root)continue;
		dfs(next.to, place, cost + next.dist);
	}
}

int main() {

	int N;
	cin >> N;

	for (int i = 0; i < N-1;++i) {
		long long a, b, c;
		cin >> a >> b >> c;
		tree[--a].push_back({--b, c});
		tree[b].push_back({a, c});
	}

	int Q, K;
	cin >> Q >> K;
	dfs(--K, -1, 0);

	for (int i = 0; i < Q; ++i) {
		int x, y;
		cin >> x >> y;
		cout << dist[--x]+dist[--y] << endl;
	}
}


Measured memory_bytes: 15360
N,M = map(int,input().split())

l = 0
r = 10**12+1

while r-l>1:
    s = (r+l)//2#作るべきsとc
    c = 2*s
    t = s

    S,C = N,M
    s-=S#Sは全部使った
    if s > 0:
        C-=2*s
    if C < c:
        r = t
    else:
        l = t
    
print(l)

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

   typedef long long ll;
   typedef pair<ll, ll> Pii;
   typedef vector<ll> Vi;
   typedef vector<Vi> VVi;

   const double EPS = (1e-7);
   const ll INF =(1e13);
   const double PI = (acos(-1));
   const ll MOD = ll(1e9) + 7;

   #define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
   #define REPR(i, n) for(ll i = n; i > -1; i--)
   #define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
   #define ALL(x) (x).begin(),(x).end()
   #define SORT(x) sort((x).begin(), (x).end())
   #define RSORT(x) sort((x).rbegin(), (x).rend())
   #define REVERSE(x) reverse((x).begin(), (x).end())
   #define SZ(x) ((ll)(x).size())
   #define pb push_back
   #define mp make_pair

   //chmax(a, b): a>bならaをbで更新　更新したときにtrueを返す
   //chmin(a, b): a<bならaをbで更新　更新したときにtrueを返す
   template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
   template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

   #define dump(x) cerr<< #x << "= " << (x) << endl;

   ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
   ll pow(ll a, ll b){if (b == 0) return 1; else if (b % 2 == 0) return pow(a * a, b / 2); else return pow(a * a, b / 2) * a;}
   ll pow(ll a, ll b, ll m){if (b == 0) return 1; else if (a == 0) return 0; else if (b % 2 == 0) return (pow((a * a) % m, b / 2, m) % m); else return (pow((a * a) % m, b / 2, m) * a) % m;}
   ll residue(ll a, ll m){return ((a % m) + m) % m;};

   ll dx[4]={1,0,-1,0};
   ll dy[4]={0,1,0,-1};

int main(){
  ll r, g, b, n; cin >> r >> g >> b >> n;
  ll ans = 0;
  for(ll x = 0; x * r <= n; x++){
    for(ll y = 0; x * r + y * g <= n; y++){
      if((n - x * r - y * g) % b == 0) {
//        printf("x = %lld, y = %lld, z = %lld\n", x, y, (n - x * r -y * g) / b);
        ans++;
      }
    }
  }
  cout << ans << endl;
}


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

using namespace std;

#define MOD 1000000007

enum status_t {
  Start,
  Vertical,
  Horizontal,
};

int32_t main()
{
  uint32_t N;
  cin >> N;

  string str1, str2;
  cin >> str1;
  cin >> str2;

  status_t status = Start;
  uint32_t index = 0;
  uint64_t count = 1;
  while(index < N){
    if(str1[index] == str2[index]){
      if(status == Start){
        count *= 3;
      } else if (status == Vertical){
        count *= 2;
      } else {
        count *= 1;
      }
      status = Vertical;
      index++;
    } else {
      if(status == Start){
        count *= 6;
      } else if (status == Vertical){
        count *= 2;
      } else {
        count *= 3;
      }
      status = Horizontal;
      index += 2;
    }
    count %= MOD;
  }

  count %= MOD;

  cout << count << endl;

  return 0;
}


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

const ll MAXN = 200000;
const ll INF = 1001001001;
const ll MOD = 1000000007;

ll N, ans=0, tmp=INF;
vector<ll> A, B;

signed main(){
    cin >> N;
    for(int i=0;i<N;i++) {
        ll a, b;
        cin >> a >> b;
        A.push_back(a);
        B.push_back(b);
        ans += b;
    }
    for(int i=0;i<N;i++) {
        if(A[i]!=B[i]) break;
        if(i==N-1) {
            cout << 0 << endl;
            return 0;
        }
    }
    for(int i=0;i<N;i++) {
        if(A[i]>B[i]) {
            tmp = min(tmp,B[i]);
        }
    }
    cout << ans-tmp << endl;
    return 0;
}

Measured memory_bytes: 3788
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=a; i<=b; i++)
#define ll long long
using namespace std;
int n,m;
int a[100005];
int main(){
    
    cin>>n>>m;
    int sum=0;
    FOR(i,1,m) cin>>a[i],sum+=a[i];
    if (n-sum<0){cout<<-1;} else cout<<n-sum;
}


Measured memory_bytes: 3648
using System;
using System.IO;
using System.Linq;

class A
{
	static int[] Read() => Console.ReadLine().Split().Select(int.Parse).ToArray();
	static void Main()
	{
		Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });

		var h = Read();
		var n = h[0];

		var uf = new UF(n);

		for (int i = 0; i < h[1]; i++)
		{
			var q = Read();
			if (q[0] == 0)
				uf.Unite(q[1], q[2]);
			else
				Console.WriteLine(uf.AreUnited(q[1], q[2]) ? 1 : 0);
		}
		Console.Out.Flush();
	}
}

class UF
{
	int[] p;
	public UF(int n) { p = Enumerable.Range(0, n).ToArray(); }

	public void Unite(int a, int b) { if (!AreUnited(a, b)) p[p[b]] = p[a]; }
	public bool AreUnited(int a, int b) => GetRoot(a) == GetRoot(b);
	public int GetRoot(int a) => p[a] == a ? a : p[a] = GetRoot(p[a]);
}


Measured memory_bytes: 23168
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

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

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

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

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


template <typename T>
T amarinasi(T a,T b){
    if(a%b==0)
{
    return a/b;
}
else if(a%b>0)
{
    return a/b+1;
}
else
{
    return a/b-1;
}
}

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

//----------------------------------------------------------------

int main(){
ll r,d,x;
cin>>r>>d>>x;
for(int i=0;i<10;i++){
    cout<<r*x-d<<endl;;
    x=r*x-d;
}
}











Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}
const ll INF = 1LL << 60;


int main() {
    int n; cin >> n;
    int ans = 0;
    rep(i, n) {
        int a; cin >> a;
        if(i % 2 == 0 && a % 2 != 0) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3648