akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[9]={1,0,-1,0,1,1,-1,-1,0};
const ll dx[9]={0,-1,0,1,1,-1,1,-1,0};
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;
}

struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) {}

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};

int main(){
    ll n,q;cin >> n >>q;
    UnionFind uf(n);
    rep(i,q){
        ll a,b;cin >>a >> b;a--;b--;
        if(!uf.same(a,b))uf.merge(a,b);
    }
    ll ans=0;
    rep(i,n)chmax(ans,(ll)uf.size(i));
    cout << ans <<endl;
}

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

int main(void) {
    int x, y, z, k;
    cin >> x >> y >> z >> k;

    vector<long> a(x), b(y), c(z);
    for(auto &x: a) cin >> x, x = -x;
    for(auto &x: b) cin >> x, x = -x;
    for(auto &x: c) cin >> x, x = -x;

    sort(a.begin(), a.end());
    sort(b.begin(), b.end());

    int mx = min(k,x), my = min(k,y), mz = min(k,z);

    vector<long> t(mx*my);
    for(int i=0; i<mx; i++)
        for(int j=0; j<my; j++)
            t[i*my + j] = a[i]+b[j];

    sort(t.begin(), t.end());
    
    int mt = min(mx*my, k);

    vector<long> u(mt*mz);
    for(int i=0; i<mt; i++)
        for(int j=0; j<mz; j++)
            u[i*mz + j] = t[i]+c[j];

    sort(u.begin(), u.end());

    for(int i=0; i<k; i++)
        cout << -u[i] << endl;
}


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

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v),v.end()));
#define DUMP(v) REP(i, (v).size()) { cout << v[i]; if (i != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
///(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)///

void make_comb(vvl &comb) {
	REP(i, comb.size())comb[i][0] = 1;
	REP(i, comb.size()-1) {
		REP(j, comb[0].size()-1) {
			comb[i + 1][j + 1] = comb[i][j] + comb[i][j + 1];
		}
	}
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	vvl comb(55, vl(55, 0));
	make_comb(comb);

	int n, a, b;
	cin >> n >> a >> b;
	vl v(n);
	REP(i, n)cin >> v[i];
	sort(ALL(v), greater<ll>());
	ll cnt = 0;
	__int128 ansa=0, ansb=INF;
	FOR(i, a, b + 1) {
		ll sum = 0;
		REP(j, i)sum += v[j];
		int cntal = 0, cntin = 0;
		REP(j, n)if (v[j] == v[i - 1])cntal++;
		REP(j, i)if (v[j] == v[i - 1])cntin++;
		ll p = comb[cntal][cntin];

		if (sum*ansb>=i*ansa) {
			if (sum*ansb == i*ansa)cnt += p;
			else cnt = p;
			ansa=sum;
			ansb = i;
		}

	}
	cout << fixed << setprecision(12) << (long double)(ansa)/ansb << endl;
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val x = readLine()!!.split(" ").map { it.toInt() }
    val x2 = x.first()
    val line = readLine()
    if (line.isNullOrBlank()) {
        return println(x2)
    }
    val p = line!!.split(" ").map { it.toInt() }
    for (i in 0..Int.MAX_VALUE)
        if (!p.contains(x2 - i)) {
            return println(x2 - i)
        } else if (!p.contains(x2 + i)) {
            return println(x2 + i)
        }
    }



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

using i64 = long long;
using pii = pair<int, int>;

const int N = 305;

int n, m, mx, ant;

int a[N][N], d[N], f[N];
bool del[N];

int main() {
#ifdef HOME
	freopen("agc18b.in", "r", stdin);
	freopen("agc18b.out", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);

	cin >> n >> m;
	for (int i = 1; i <= n; ++i) {
		d[i] = 1;
		for (int j = 1; j <= m; ++j)
			cin >> a[i][j]; }

	ant = n;
	for (int it = 1; it < m; ++it) {
		memset(f, 0x00, sizeof f);
		mx = 0;
		for (int i = 1; i <= n; ++i) {
			while (del[a[i][d[i]]])
				++d[i];

			if (d[i] <= m)
				mx = max(mx, ++f[a[i][d[i]]]); }

		for (int i = 1; i <= m; ++i) if (f[i] == mx) {
			del[i] = true;
			break; }

		ant = min(ant, mx); }

	cout << ant << endl;

	return 0; }


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
 
template <typename T>
struct Knap_Big_Weight{
    T W;
    int N,max_v;
    vector<int> v;
    vector<T> w;
    vector< vector<T> > dp;
    Knap_Big_Weight(int N_, T W_ ,int max_v_){
        W = W_;
        N = N_;
        max_v = max_v_;
        v.resize(N);
        w.resize(N);
        dp = vector< vector<T> >(2,vector<T>(max_v*N+1,W+1));
    }
    int calc(){
        dp[0][0] = dp[1][0] = 0;
        for(int i=1;i<=N;i++){
            for(int j=0;j<=N*max_v;j++){
                int k = i%2;
                int l = 1-k;
                if(j<v[i-1]){
                    dp[k][j] = dp[l][j];
                }else{
                    dp[k][j] = min(dp[l][j],dp[l][j-v[i-1]]+w[i-1]);
                }
            }
        }
        int k = N%2;
        for(int i=N*max_v;i>=0;i--){
            if(dp[k][i] < W+1){
                return i;
            }
        }
    }
};
 
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    long long W;
    int N;
    cin >> N >> W;
    Knap_Big_Weight<long long> kbw(N,W,1001);
    for(int i=0;i<N;i++){
        cin >> kbw.w[i] >> kbw.v[i];
    }
    cout << kbw.calc() << endl;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll n ,m , k , c[20],A[20][20];
int main (){
    cin >> n >> m >> k;
    for(int i=0;i<n;i++){
        cin >> c[i];
        for(int j=0;j<m;j++)cin >> A[i][j];
    }
    int mask = 1,good=0;
    ll res=1e18;
    while(mask< (1<<n)){
        int skills[m+4];
        memset(skills,0,sizeof skills);
        ll cost=0;
        for(int i=0;i<n;i++){
            if( mask & (1<<i)){
                    cost+= c[i];
                    for(int j=0;j<m;j++)
                        skills[j]+=A[i][j];
            }
        }
        int g=1;
        for(int i=0;i<m;i++){
            if(skills[i]<k){g=0;break;}
        }
        if(g){
            good=1;
            res=min(res,cost);
        }
        mask++;
    }
    if(good==0)cout<<"-1";
    else{
            cout<<res<<endl;
    }
    return 0;
}


Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {

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

		String a = sc.next();
		String b = sc.next();
		String ans = "";

		if (a.equals(b)) {
			ans = "H";
		} else {
			ans = "D";
		}

		System.out.println( ans );
	}
}

Measured memory_bytes: 21716
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp> 
//using namespace __gnu_pbds;
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define f0(i,a,b) for(int i=a;i<b;i++)
#define f1(i,a,b) for(int i=a;i<=b;i++)
#define f2(i,a,b) for(int i=a;i>b;i--)
#define f3(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define int long long
#define fi first
#define se second
#define ncr(n,r) fact[n]*modInv(fact[r])*modInv(fact[n-r])
#define modInv(a) binExp(a,mod-2)
#define mod 1000000007
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
//#define os_find(k) find_by_order(k)
//#define os_order(k) order_of_key(k)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define make_graph(k) int x,y; f0(i,0,k){cin>>x>>y; adj[x].pb(y);}
#define test int t;cin>>t;while(t--)

vector<int> adj[100001];
int vis[100001];
int depth[100001];

void dfs(int);

signed main()
{
    fast

    int n,m;
    cin>>n>>m;

    f1(i,0,n)
    {
        vis[i] = 0;
        depth[i] = 0;
    }

    make_graph(m);

    f1(i,1,n)
    {
        if(!vis[i])
        {
            dfs(i);
        }
    }

    int ans = 0;
    f1(i,1,n) ans = max(ans, depth[i]);
    cout<<ans;
}

void dfs(int v)
{
    vis[v] = 1;
    for(auto x : adj[v])
    {
        if(!vis[x])
        {
            dfs(x);
        }
        depth[v] = max(depth[v], depth[x]+1);
    }
}

Measured memory_bytes: 13284
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
#define ff first
#define ss second
#define pb push_back
#define debug(val) cerr << "The value of " << #val << " is = " << val << '\n';
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 922337203685477;
const ll mininf = -922337203685477;
const ll nax = 1e5 + 5;
ll n;

int main(){
	IOS
	cin >> n;
	string c="";
	while(n){
		n--;
		c+=(n%26)+'a';
		n/=26;
	}
	for(int i=c.size()-1;i>=0;i--){
		cout << c[i];
	}
	cout << '\n';
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
constexpr long double EPS = 1e-11;
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(){
    ll n;
    cin >> n;
    vector<ll> x(n), y(n), aftx(n), afty(n);
    for (ll i = 0; i < n;i++){
        cin >> x[i] >> y[i];
        aftx[i] = x[i] - y[i];
        afty[i] = x[i] + y[i];
    }
    ll ans = 0;
    ll xmax = *max_element(aftx.begin(), aftx. end());
    ll ymax = *max_element(afty.begin(), afty. end());
    ll xmin = *min_element(aftx.begin(), aftx. end());
    ll ymin = *min_element(afty.begin(), afty. end());
    ans = max(xmax - xmin, ymax - ymin);
    cout << ans << endl;
}

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

int main() {
	string s;
	cin >> s;
	int cnt1 = count(s.begin(), s.end(), 'A');
	int cnt2 = count(s.begin(), s.end(), 'B');
	if (cnt1 > 0 && cnt2 > 0) puts("Yes");
	else puts("No");
	return 0;
}

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

int main(){
    int x,y;
    cin >> x >> y;

    for(int i = 0; i <= x; i++){
        int a = x - i;
        if(2*i+a*4 == y){
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;



}


Measured memory_bytes: 3572
"""
author : halo2halo
date : 16, Jan, 2020
"""

import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

A, B, K = map(int, readline().split())
lis=[]
for i in range(1, min(A, B) + 1):

    if A % i == 0 and B % i == 0:
        lis.append(i)
lis.reverse()
print(lis[K-1])


Measured memory_bytes: 12396
n=int(input())
y=input().split()
x=[]
for i in range(n):
    if y[i] not in x:
        x.append(y[i])
    #計算量を減らす
    if len(x)==4:
        break

if len(x)==3:
    print("Three")
else:
    print("Four")


Measured memory_bytes: 2940
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
 
int main(void){
    int a,b;
    scanf("%d%d",&a,&b);
    if (a+b==15){
        printf("+\n");
    } else if (a*b==15){
        printf("*\n");
    } else {
        printf("x\n");
    }
	return 0 ;
}

Measured memory_bytes: 128
/*
	Name:
	Author: xiaruize
	Date:
*/

#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define MOD 1000000007
#define ALL(a) (a).begin(), (a).end()
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define ll long long
#define form(i,j,n) for(int i=int(j);i<=int(n);i++)
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define pis pair<int,string>
#define sec second
constexpr ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
constexpr ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

long long a,b,c[200005],n,d,ans,x[200005],y[200005],l,k;

struct node{
    long long x,y;
} w[200005];

inline bool cmp(node x,node y)
{
    return x.x<y.x;
}

int main()
{
    cin>>n>>d>>a;
    d*=2;
    for(int i=1; i<=n; ++i)
    {
       cin>>w[i].x>>w[i].y;
        w[i].y=(w[i].y+a-1)/a;
    }
    sort(w+1,w+n+1,cmp);
    l=1;
    for(int i=1; i<=n; ++i)
    {
        while(l<i&&w[i].x-w[l].x>d)
		{
        	k-=c[l];
        	l++;
		}
        c[i]=w[i].y-k;
        if(c[i]<0)
        {
        	c[i]=0;
		}   
        ans+=c[i];
        k+=c[i];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 5888
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input!(
    n: i32,
    m: usize,
    a: [i32; m]
    );
    let s: i32  = a.into_iter().sum();
    let ans:i32 = if n >= s  { n - s} else { -1 };
    println!("{}", ans);
}


Measured memory_bytes: 2140
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    istream& in(cin);
    ostream& out(cout);
    int n;
    in>>n;
    vector<int> x(n);
    for(auto&i:x) in>>i;
    int ans{INT_MAX};
    fr(i,102){
        int tmp{};
        for(auto&j:x) tmp+=(j-i)*(j-i);
        ans=min(ans,tmp);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = a; i <= b; i++)
using namespace std;
int n, z, w, a[5000];
int main() {
    cin >> n >> z >> w;
    FOR(i, 1, n) {
        cin >> a[i];
    }
    if (n == 1) {
        cout << llabs(a[n] - w);
    }
    else {
        cout << max(llabs(a[n] - a[n-1]), llabs(a[n] - w));
    }
}

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

using namespace std;

int main() {
    int n,res,mn;
    int a[200001];
    cin>>n;
    res = 0;
    mn = INT_MAX;
    for(int i=0 ; i<n ; i++){
        cin>>a[i];
        if(mn >= a[i]){
            mn = a[i];
            res++;
        }
    }
    cout<<res<<endl;
}

Measured memory_bytes: 1024
"""
Writer:SPD_9X2

木を2色で塗り分ける(交互に)

mod3で、
赤/青
10/20
20/10
120/0
0/120s
の4通りの分け方を試せばよい

絶対OKな証明
入る場合→入れればよい
入らない場合→mod0は必ずmod1,mod2以下の数。
mod0を入れても空きがあるとまずいけど、差は1以下なのでその場合はmod1が必ず入る
→おわり

"""


import sys
from collections import deque
def NC_Dij(lis,start):

    ret = [float("inf")] * len(lis)
    ret[start] = 0
    
    q = deque([start])
    plis = [i for i in range(len(lis))]

    while len(q) > 0:
        now = q.popleft()

        for nex in lis[now]:

            if ret[nex] > ret[now] + 1:
                ret[nex] = ret[now] + 1
                plis[nex] = now
                q.append(nex)

    return ret,plis

N = int(input())

lis = [[] for i in range(N)]
for i in range(N-1):

    a,b = map(int,input().split())
    a -= 1
    b -= 1

    lis[a].append(b)
    lis[b].append(a)

dis,plis = NC_Dij(lis,0)

use = [1,2,3]

flag = True
ans = []
for i in range(N):

    nex = use[dis[i] % 2]
    use[dis[i] % 2] += 3
    if nex > N:
        nex = use[2]
        use[2] += 3

    if nex > N:
        flag = False
        break
    ans.append(nex)

if flag:
    print (" ".join(map(str,ans)))
    sys.exit()

use = [2,1,3]
flag = True
ans = []
for i in range(N):

    nex = use[dis[i] % 2]
    use[dis[i] % 2] += 3
    if nex > N:
        nex = use[2]
        use[2] += 3

    if nex > N:
        flag = False
        break
    ans.append(nex)

if flag:
    print (" ".join(map(str,ans)))
    sys.exit()

use = [3,1,2]
flag = True
ans = []
for i in range(N):

    nex = use[dis[i] % 2]
    use[dis[i] % 2] += 3
    if nex > N and nex % 3 == 1:
        nex = use[2]
        use[2] += 3
    if nex > N and nex % 3 == 2:
        nex = use[0]
        use[0] += 3

    if nex > N:
        flag = False
        break
    ans.append(nex)

if flag:
    print (" ".join(map(str,ans)))
    sys.exit()


use = [1,3,2]
flag = True
ans = []
for i in range(N):

    nex = use[dis[i] % 2]
    use[dis[i] % 2] += 3

    if nex > N and nex % 3 == 1:
        nex = use[2]
        use[2] += 3
    if nex > N and nex % 3 == 2:
        nex = use[1]
        use[1] += 3

    if nex > N:
        flag = False
        break
    ans.append(nex)

if flag:
    print (" ".join(map(str,ans)))
    sys.exit()



print (-1)



Measured memory_bytes: 127424
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    ll n; cin >> n;
    ll k; cin >> k;
    string s; cin >> s;
    ll gyaku = 0;
    REP(i, n-1){
        if (s[i] != s[i+1]){
            gyaku++;
        }
    }
    dump(gyaku)
    dump(n)
    dump(k)
    ll ans = n - 1;
    ans += min(ll(0), k*2 - gyaku);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;

int main() {
    int N, A, B;
    cin >> N >> A >> B;
    int ans = 0;
    int sum, num;
    for (int i = 1; i < N + 1; i++) {
        sum = 0;
        num = i;
        while (true) {
            sum += num % 10;
            if (num < 10) {
                break;
            }
            num /= 10;
        }
        if (A <= sum && B >= sum) {
            ans += i;
        }
    }
    cout << ans << endl;
}

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

using namespace std;

using ll = long long;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int main () {
  cin.tie(0);
  cout << fixed << setprecision(10);

  string s, t; cin >> s >> t;
  int szs = s.size(), szt = t.size();
  vector<int> ss(szs+1), st(szt+1);
  for(int i=0;i<szs;++i) {
    int tmp = (s[i] == 'A') ? 2 : 1;
    ss[i+1] = ss[i] + tmp;
    ss[i+1] %= 3;
  }
  for(int i=0;i<szt;++i) {
    int tmp = (t[i] == 'A') ? 2 : 1;
    st[i+1] = st[i] + tmp;
    st[i+1] %= 3;
  }
  // printv(ss);
  // printv(st);

  int q; cin >> q;
  for(int i=0;i<q;++i) {
    int a, b, c, d; cin >> a >> b >> c >> d;
    int tmps = ((ss[b] - ss[a-1]) + 3) % 3;
    int tmpt = ((st[d] - st[c-1]) + 3) % 3;
    if(tmps == tmpt) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
Apparently, the tree supports the same operations as the set 
(at least I haven't any problems with them before), but also there are two new features — 
find_by_order() — The first returns an iterator to the k-th largest element (counting from zero)
order_of_key() — the number of items in a set that are strictly smaller than our item. 
https://codeforces.com/blog/entry/11080
using namespace __gnu_pbds; */
using namespace std;
#define test() int t;cin>>t;for(int test=1;test<=t;test++)
#define int long long
#define MOD 1000000000000000000
#define pb push_back 
#define ins insert
#define fast(); ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ld long double
#define endl '\n'
int m(int a) {
    return ((a%MOD)+MOD)%MOD;
}
int p(int a, int b) {
    int res = 1;
    while(b > 0){
        if(b&1) res = m(m(res)*m(a));
        a = m(m(a)*m(a));
        b >>= 1;
    }
    return res;
}
// vector<int> fac; //precompute fac array
// fac.resize(n+1);
// fac[0] = 1; 
// for (int i=1; i<=n; i++)   fac[i] = m(m(fac[i-1])*m(i));
// int modInverse(int n){ 
// return p(n, MOD-2); 
// }  
// int nCrModPFermat(int n, int r){   
//     if(r == 0)  return 1; 
//     return m(m(m(fac[n])*m(modInverse(fac[r])))*m(modInverse(fac[n-r]))); 
// } 
signed main(){
    fast();
    ld a, b;
    cin >> a >> b;
    a *= b;
    int ans = a;
    cout << ans << endl;
    cerr << "\nTime elapsed : " << 1000 * clock() / CLOCKS_PER_SEC << " ms\n";
}

Measured memory_bytes: 3752
#include <stdio.h>
#include <math.h>

int main() {
int n;
int swap;
int a, b = 0;

scanf("%d %d", &a, &b);
if(b>=100) n = a*1000+b;
else if(b>=10) n = a*100+b;
else n = a*10+b;
swap = (int)sqrt((double)n);
if (swap*swap == n) {
    printf("Yes\n"); 
} else {
    printf("No\n"); 
}

return 0;
}

Measured memory_bytes: 128
M, D = map(int, input().split())
seki = 0
for m in range(1, M + 1):
    for d in range(1, D + 1):
        d10, d1 = divmod(d, 10)
        if d10 >= 2 and d1 >= 2 and d10 * d1 == m:
            seki += 1
print(seki)

Measured memory_bytes: 3060
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define FOR(i,n,a) for(int i = a;i<n;i++)
#define rep(i,n) FOR(i,n,0)
#define UNFOR(i,n,a) for(int i = a;i>n;i--)
#define unrep(i,n) UNFOR(i,0.n)
typedef long long ll;
using namespace std;
int main(){
	int N, M;
	int X;
	cin >> N >> M >> X;
	vector<int> A(M);
	for (auto & i : A) cin >> i;
	int index = lower_bound(A.begin(), A.end(), X) - A.begin();
	cout << min(index, M - index) << endl;
	

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define int long long
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int a, b;

signed main() {
	cin >> a >> b;
	if (a != 1 && b != 1)cout << 1 << endl;
	else if (a != 2 && b != 2)cout << 2 << endl;
	else cout << 3 << endl;
}

Measured memory_bytes: 256
#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 FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;
const int n = 100005;

vector<bool> IsPrime;

void sieve(int max) {
  if (max+1 > IsPrime.size()) {
    IsPrime.resize(max+1, true);
  }
  IsPrime[0] = false;
  IsPrime[1] = false;

  for (int i = 2; i*i <= max; i++) {
    if (IsPrime[i]) {
      for (int j = 2; i*j <= max; j++) {
        IsPrime[i*j] = false;
      }
    }
  }
}

int main() {
  sieve(n);

  vector<int> s(n, 0);
  for (int i = 1; i < n; i += 2) {
    if (IsPrime[i] && IsPrime[(i + 1) / 2]) s[i]++;
  }
  rep(i, n - 1) s[i + 1] += s[i];

  int q;
  cin >> q;
  rep(i, q) {
    int l, r;
    cin >> l >> r;
    cout << (l == 1 ? s[r] : s[r] - s[l - 2]) << endl;
  }


  
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
vector<vector<ll>> ady;
ll alt[100005];
ll bfs(ll v){
    ll s=0;
    for(int i=0;i<ady[v].size();i++){
        if(alt[ady[v][i]]>=alt[v]){s++;}
    }
return s;
}
int main(){
    //    cout<<fixed<<setprecision(2);
//cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
ll k,t,n,m,a,b;
cin>>n>>m;
ady.resize(n+1);
for(int i=1;i<=n;i++){cin>>alt[i];}

for(int i=0;i<m;i++){cin>>a>>b;ady[a].pb(b);ady[b].pb(a);}
ll s=0;
for(ll i=1;i<=n;i++){
    if(bfs(i)==0){
       s++;
    }
}
cout<<s;
}


Measured memory_bytes: 9836
import sys
read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N = int(input())

    ans = [0] * (N+1)

    for x in range(1,int(N**0.5)):
        for y in range(1,int(N**0.5)):
            for z in range(1,int(N**0.5)):
                tmp = x**2+y**2+z**2+x*y+y*z+z*x
                if tmp<=N:
                    ans[tmp] += 1

    for a in ans[1:]:
        print(a)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9724
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;

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

int main()
{
	vector<int> nums;
	int n;
	while (cin >> n) {
		nums.push_back(n);
	}
	sort(nums.begin(), nums.end());
	reverse(nums.begin(), nums.end());
	rep(i, 3)
		cout << nums[i] << endl;
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <time.h>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <string>
#include <bitset>
using namespace std;
#define rep(I,N) for(int I = 0; I < (int)(N); I++)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 30)
typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, -1, 1};
string IntToStr(int);


int main(void){
	int h, w;
	while(cin >> h >> w, h){
		char S[103][103];
		int map[102][102];
		fill_n(*map, 102*102, -1);
		rep(i, h){
			cin >> S[i];
			rep(j,w){
				if(S[i][j] == '>')map[i][j] = 0;
				else if(S[i][j] == '<')map[i][j] = 1;
				else if(S[i][j] == '^')map[i][j] = 2;
				else if(S[i][j] == 'v')map[i][j] = 3;
			}

		}
		int memo[102][102];
		fill_n(*memo, 102*102, 0);
		int x = 0;
		int y = 0;
		int cnt = 0;
		while(1){
			if(S[y][x] == '.'){
				cout << x << " " << y << endl;
				break;
			}
			if(memo[y][x] == 1 && cnt != 0){
				FIN("LOOP");
				break;
			}
			int dir = map[y][x];
			memo[y][x] = 1;
			x += dx[dir];
			y += dy[dir];
			cnt++;
		}
	}

	return 0;
}



int StrToInt(string s){
	stringstream ss;
	ss << s;
	int val;
	ss >> val;
	return val;
}
string IntToStr(int i){
	stringstream ss;
	ss << i;
	return ss.str();
}

Measured memory_bytes: 1264
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int x = sc.nextInt();
      	int y = x / 100;
        int d = x % 100;

      	for(int i = 1;i <= y; i++){
          if(d >= 5){
            d -= 5;
          }else if(d >= 4){
            d -= 4;
          }else if(d >= 3){
            d -= 3;
          }else if(d >= 2){
            d -= 2;
          }else if(d >= 1){
            d -= 1;
          }
        }
    	if(d == 0){
           System.out.println(1);  
        }else{
           System.out.println(0);  
        }
    }
}

Measured memory_bytes: 35636
import numpy as np

N, L = [int(j) for j in input().split()]

taste = [L + i - 1 for i in range(1, N+1)]
abs_taste = [abs(i) for i in taste]
min_t_i = abs_taste.index(min(abs_taste))

print(sum(taste)-taste[min_t_i])


Measured memory_bytes: 21444
#include<iostream>
#include<string>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<vector>
#include<iomanip>
#include<map>
#include<set>
#include<utility>
#include<iterator>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
//#define t ll t;cin>>t;while(t--)
#define nn cout<<endl;
#define ff(a,n) for(ll i=a;i<n;i++)
#define cY cout<<"YES\n"
#define cN cout<<"NO\n"
#define cy cout<<"Yes\n"
#define cn cout<<"No\n"
#define sc second
#define fs first
#define c(a) cout<<a<<endl

void solve()
{
	ll a,b; cin>>a>>b;
	ll x=1;
	ll i=0;
	while(1)
	{
		if(x>=b)break;
		x+=a-1;
		i++;
	}
	cout<<i;
}

int main()
{
	solve();
}

Measured memory_bytes: 3636
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
template <typename T> using posteriority_queue = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
template <typename T> void unique(vector<T> &a) { a.erase(unique(ALL(a)), a.end()); }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  ll n, m; cin >> n >> m;
  m >>= 1;
  cout << (min(n, m) + m) / 2 << '\n';
  return 0;
}


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

using namespace std;

#define fi first
#define se second

typedef pair<int,int> ii;
typedef vector<ii> vii;

int N;
vii adjList[100005];

int dist[100005];
priority_queue< ii,vector<ii>,greater<ii> > pq;

ii dijkstra(int s){                 // return pair: max_dist, max_dist vertex
    
    memset(dist,-1,sizeof(dist));

    dist[s] = 0; pq.push(ii(0,s));
    while (!pq.empty()){
        ii front = pq.top(); pq.pop();

        int u = front.se;
        int d = front.fi;

        if (d > dist[u]) continue;

        for (int i=0; i<adjList[u].size(); i++){
            int vv = adjList[u][i].se;
            int vd = adjList[u][i].fi;

            if (dist[vv] == -1 || dist[vv] > dist[u] + vd){
                dist[vv] = dist[u] + vd; pq.push(ii(dist[vv],vv));
            }
        }
    }

    int max_dist = 0, max_vert;
    for (int i=0; i<N; i++){
        if (max_dist < dist[i]){
            max_dist = dist[i];
            max_vert = i;
        }
    }

    return ii(max_dist,max_vert);
}

int main(){

    ios_base::sync_with_stdio(0);

    /*
     *  N   nodes
     *  N-1 edges
     */

    cin >> N;

    int u, v, w;
    for (int i=1; i<N; i++){
        cin >> u >> v >> w;
    
        adjList[u].push_back(ii(w,v));
        adjList[v].push_back(ii(w,u));
    }

    int S = dijkstra(0).se;
    int diameter = dijkstra(S).fi;

    cout << diameter << endl;

    return 0;
}

Measured memory_bytes: 7980
package main

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

var (
	sc = bufio.NewScanner(os.Stdin)
)

func main() {
	x := nextInt()
	if 30 <= x {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

func nextInt() int {
	i, err := strconv.Atoi(nextLine())
	pnc(err)
	return i
}

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

func pnc(err error) {
	if err != nil {
		panic(err)
	}
}


Measured memory_bytes: 1776
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

#define INF 1e9
#define MAXN 100005
#define MAXM 100005
#define MOD 1000000007
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pii pair<int, int>

ll ans = 0;
int A,B,C,K;

void solve(){
    ans += 1*min(A, K);
    K -= A;

    K -= B;

    if(K > 0){
        ans -= min(C, K);
    }

    cout << ans << endl;
}

int main(){
    cin >> A >> B >> C >> K;

    solve();
}


Measured memory_bytes: 3636
#include <stdio.h>
#include <stdlib.h>

unsigned long long s[100000];

int binary_search(unsigned long long val_t,unsigned long long min,unsigned long long max)
{
	int i = min;
	int j = max;
	int p;
	while(i<=j){
		p = (i+j)/2;
		if(s[p] > val_t){
			j = p - 1;
		}
		else if(s[p] < val_t){
			i = p + 1;
		}
		else if(s[p] == val_t){
			return 1;
		}
	}
	return 0;
}
int main()
{
	unsigned long long i;
	unsigned long long n;
	unsigned long long q;
	
	scanf("%lld",&n);
	for(i=0;i<n;i++){
		scanf("%lld",&s[i]);
	}

	scanf("%lld",&q);
	unsigned long long t[q];

	for(i=0;i<q;i++){
		scanf("%lld",&t[i]);
	}

	unsigned long long cnt=0;
	for(i=0;i<q;i++){
		if(binary_search(t[i],0,n) == 1){
			cnt++;
		}
	}

	printf("%lld\n",cnt);
	return 0;	
}


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

int64_t str_mod(const string &str, int64_t m) {
    int64_t res = 0;
    for(int i = 0; i < str.size(); ++i)  {
        int n = str[i] - '0';
        res = (res * 10 + n) % m;
    }
    return res;
}

int main() {
    string S; cin >> S;
    auto m = str_mod(S, 9);
    cout << (m == 0 ? "Yes" : "No") << '\n';
    return 0;
}


Measured memory_bytes: 3764
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = (a);i < (b);++i)
#define FORR(i, b, a) for (int i = (b) - 1;i >= 0;--i)
#define REP(i, n) for(int i = 0;i < (n);++i)
#define REPR(i, n) for(int i = (n) - 1;i >= 0;--i)
#define ITER(itr, v) for(auto itr = v.begin();itr != v.end();++itr)
#define SORT(v) sort(v.begin(), v.end())
#define REV(v) reverse(v.begin(), v.end())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

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

	string s, t;
	cin >> s >> t;
	vector<vector<int>> memo(26);
	int n = s.size();
	REP(i, n) {
		memo[s[i] - 'a'].emplace_back(i);
	}
	ll res = 1;
	int k = -1;
	for (const auto &c : t) {
		if (memo[c - 'a'].empty()) {
			cout << -1 << endl;
			return 0;
		}
		auto ub = upper_bound(memo[c - 'a'].begin(), memo[c - 'a'].end(), k);
		if (ub != memo[c - 'a'].end()) k = *ub;
		else {
			k = memo[c - 'a'].front();
			res += n;
		}
	}
	cout << res + k << endl;

	return 0;
}

Measured memory_bytes: 1228
#include<stdio.h>
#define N 102
#define INFTY 10000000

int n, M[N][N];
int d[N];

int q[N];
int head = 0, tail = 0;

void push(int x) {
	q[tail] = x;
	tail++;
}

int pop() {
	int x = q[head];
	head++;
	return x;
}


void bfs(int s) {
	int u, k, v, i, j;
	push(s);
	for (i = 1; i <= n; i++) d[i] = INFTY;
	d[s] = 0;
	while (head != tail) {
		u = pop();
		for (v = 1; v <= n; v++) {
			if (M[u][v] == 0) continue;
			if (d[v] != INFTY) continue;
			d[v] = d[u] + 1;
			push(v);
		}
	}
	for (i = 1; i <= n; i++) printf("%d %d\n", i, ((d[i] == INFTY) ? (-1) : d[i]));
}

int main() {
	int u, k, v, i, j;

	scanf("%d", &n);
	for (i = 1; i <= n; i++) {
		for (j = 1; j <= n; j++) M[i][j] = 0;
	}

	for (i = 1; i <= n; i++) {
		scanf("%d%d", &u, &k);
		for (j = 1; j <= k; j++) {
			scanf("%d", &v);
			M[u][v] = 1;
		}
	}

	bfs(1);

	return 0;
}


Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define init(a,i) for(int k=0;k<(i);k++)(a)[k]=0
#define in(a,i) for(int k=0;k<(i);k++)cin>>(a)[k]
#define all(a)  (a).begin(),(a).end()
#define el(a) (a).end()-(a).begin()
#define mod 1000000007
#define inf 2147483647
#define range(x,a,b) (a)<=x&&x<=(b)
ll mod_pow(ll a,ll b){
	if(b==0)return 1;
	ll next=mod_pow(a,b/2);
	int num=1;
	if(b%2) num=a*(b%2)%mod;
	return num*(next*next%mod)%mod;
}
ll factorial[500001];
ll inv[500001];
ll invfactorial[500001];
void prefactorial(){
	factorial[0]=1;
	inv[1]=1;
	invfactorial[0]=1;
	rep(i,500000)factorial[i+1]=factorial[i]*(i+1)%mod;
	rep(i,499999)inv[i+2]=mod-inv[mod%(i+2)]*(mod/(i+2))%mod;
	rep(i,500000)invfactorial[i+1]=invfactorial[i]*inv[i+1]%mod;
	return;
}
int main(){
	prefactorial();
	ll s;
	cin>>s;
	ll rest,ans=0;
	for(int i=1;i<=s/3;i++){
		rest=s-i*3;
		ans=(ans+factorial[rest+i-1]*invfactorial[rest]%mod*invfactorial[i-1]%mod)%mod;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 15352
//        THIS IS MY NINJA WAY
#include<bits/stdc++.h>
#include<ctime>
#include<vector>
#include<algorithm>

#define str string
#define dbl double
#define ll long long
#define vl vector<ll> 
#define vs vector<str>
#define pll  pair<ll,ll> 
#define vll vector<pll>
#define sl set<ll>
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
#define fr(i,a,b) for(long long i=a; i<b; i++)
#define nfr(i,a,b) for(long long i=a; i<=b; i++)
#define psl pair<str,ll>
#define pls pair<ll,str>
#define pss pair<str,str>
#define ALL(a) a.begin(),a.end()
#define stl stack<ll>
#define coml complex<ll>
#define INF 0x3f3f3f3f3f3f3f3f
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
const ll MOD = 1e9+7;


using namespace std;
int main()
{
	fast
	/*#ifndef ONLINE_JUDGE
		freopen("input.txt", "r" , stdin);
		freopen("output.txt", "w" , stdout);
	#endif*/
    
 	ll n;
 	cin>>n;
 	vector<vl> v(n,vl(3));
 	fr(i,0,n){
 		fr(j,0,3)cin>>v[i][j];
 	}
 	vector<vl> dp(n,vl(3,0));
 	dp[0]=v[0];
 	fr(i,1,n){
 		fr(j,0,3){
 			fr(k,0,3){
 				if(j!=k)
 					dp[i][k]=max(dp[i][k],dp[i-1][j]+v[i][k]);
 			}
 		}
 	}
 	cout<<*max_element(ALL(dp[n-1]));
 	return 0;
 }

Measured memory_bytes: 11264
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<queue>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if((a-b)==(b-c))cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
} 

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

int main() {
    int N;
    string S, T;
    cin >> N >> S >> T;

    for (int i = 0; i < N; i++) {
        bool flag = true;
        for (int j = i; j < N; j++) {
            if (S[j] != T[j - i])
                flag = false;
        }
        if (flag) {
            cout << N + i << endl;
            return 0;
        }
    }

    cout << 2 * N << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);++(i))
#define all(x) (x).begin(),(x).end()
#define dump(x) cout << #x << " = " << (x) << endl

using namespace std;
using ll = long long;

vector<pair<ll, ll>> prime_factorize(ll n) {
  vector<pair<ll, ll>> res;
  for (ll a = 2; a * a <= n; ++a) {
    if (n % a != 0) continue;
    ll ex = 0;
    while (n % a == 0) {
      ++ex;
      n /= a;
    }
    res.emplace_back(a, ex);
  }
  if (n != 1) res.emplace_back(n, 1ll);
  return res;
}


int main() {
  ll n; cin >> n;
  vector<pair<ll, ll>> res = prime_factorize(n);

  ll ans = 0;

  map<ll, ll> cnt;
  for (auto e: res) cnt[e.first] = 0;

  for (auto e: res) {
    while (true) {
      ll previous = cnt[e.first];
      e.second -= (previous + 1);
      if (e.second < 0) break;
      cnt[e.first]++;
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3580
#include <iostream>
using namespace std;
typedef long long ll;
ll n,q,t[100001],u[100001],a[100000],x;
int main(void){
  cin>>n>>q;
  for(int i=0;i<n;i++){
    cin>>a[i];
    t[i+1]=t[i]+a[i];
    u[i+1]=(i?u[i-1]:0)+a[i];
  }
  while(q--){
    cin>>x;
    ll ub=0,lb=n+1,m;
    while(ub+1<lb){
      m=(lb+ub)/2;
      if(abs(a[n-m]-x)>abs(a[n-(m+1)/2]-x))lb=m;
      else ub=m;
    }
cout<<t[n]-t[n-(ub+1)/2]+u[max(n-ub-(ub&1),0LL)]<<endl;
  }
}

Measured memory_bytes: 4096
#include<bits/stdc++.h>
#define dbug printf("I am here\n");
#define Fast ios_base::sync_with_stdio(false); cin.tie(0);
#define vs           v.size()
#define sot(v)       sort(v.begin(),v.end())
#define rev(v)       reverse(v.begin(),v.end())
#define yes          cout<<"Yes"<<endl
#define no           cout<<"No"<<endl
#define ii           pair<int, int>
#define int          long long
#define ull          unsigned long long
#define pb           push_back
#define mpp          make_pair
#define Okay         0
#define pi           3.14159

const int inf = 1e6;
const int cont = 1e18;
const int mod = 1e9+7;
using namespace std;

void solve(){
   int n;
   cin>>n;
   int ans = n*800;
   int ans2 = (n/15)*200;
   cout<<ans - ans2<<endl;
}

int32_t main() {
    Fast;
    solve();
    return Okay;
}


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

public class Main {

	/**
	 * @param args
	 * @throws IOException
	 */
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String[] ia;

		while (true) {
			ia = in.readLine().split(" ");
			int h = Integer.parseInt(ia[0]);
			int w = Integer.parseInt(ia[1]);
			if(h == 0 && w == 0){
				break;
			}
			int value = h * h + w * w;
			int x = 200;
			int y = 200;
			int ans = 200 * 200 + 200 * 200;
			boolean yet = true;
			for (int i = 1; i <= 150; ++i) {
				for (int j = i + 1; j <= 150; ++j) {
					int tmp = i * i + j * j;
					if (value < tmp && tmp < ans) {
						x = j;
						y = i;
						ans = tmp;
					} else if (value == tmp) {
						if (yet && h < i) {
							x = j;
							y = i;
							ans = tmp;
							yet = false;
						}
					}
				}
			}
			System.out.println("" + y + " " + x);
		}
	}

}

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

int main(){
    int N, A[1000];
    cin >> N;
    for(int i = 0; i < N; i++) cin >> A[i];

    for(int i=0; i < N; i++){
        int v = A[i];
        int j = i - 1;
        while(j >= 0 && A[j] > v){
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;
        for(int i=0; i < N; i++){
            if(i < N-1) cout << A[i] << " ";
            else cout << A[i] <<"";
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3092
#include <iostream>

using namespace std;

int main(void){
  char c;
  char c_before = '\0';

  for(int i = 0; (c = getchar()) != '\n'; ++i){
    if(c == c_before){
      cout << "Bad" << endl;
      return 0;
    }else{
      c_before = c;
    }
  }
  cout << "Good" << endl;
  return 0;
}

Measured memory_bytes: 256