akhauriyash/Code-Regression huggingface dataset:
import std.algorithm, std.conv, std.range, std.stdio, std.string;
import std.typecons;

void main()
{
  auto n = readln.chomp.to!size_t;

  auto ai = new card[](n);
  foreach (i; n.iota) {
    auto rd = readln.chomp.splitter(' ');
    auto suite = rd.front; rd.popFront;
    auto value = rd.front.to!int;
    ai[i] = card(suite, value);
  }
  auto bi = ai.dup;

  quicksort(ai, 0, n - 1);
  bi.sort!("a.value < b.value", SwapStrategy.stable);

  writeln(ai[] == bi[] ? "Stable" : "Not stable");
  foreach (a; ai)
    writefln("%s %d", a.suite, a.value);
}

size_t partition(ref card[] ai, size_t p, size_t r)
{
  auto x = ai[r];
  auto i = p - 1;

  foreach (j; p..r) {
    if (ai[j].value <= x.value) {
      ++i;
      swap(ai[i], ai[j]);
    }
  }
  swap(ai[i + 1], ai[r]);

  return i + 1;
}

void quicksort(ref card[] ai, size_t p, size_t r)
{
  if (p < r) {
    auto q = partition(ai, p, r);
    quicksort(ai, p, q - 1);
    quicksort(ai, q + 1, r);
  }
}

alias Tuple!(string, "suite", int, "value") card;

Measured memory_bytes: 11180
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 10000000000
using namespace std;
using ll = long long;
int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n){
        cin >> a[i];
    }
    sort(a.rbegin(), a.rend());
    int ans[2] = {};
    rep(i,n){
        ans[i % 2] += a[i];
    }
    cout << (ans[0] - ans[1]) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
  
using namespace std;
  
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
  
#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
  
#define ordered_set tree<int , null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> 
  
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
  
const int inf = int(1e9);
const int mod = inf + 7;
const int N = 1e6 + 555; // TL MB
const double PI = acos(-1.0);
 
void mul(ll &x, ll y){
	x *= y;
	if(x >= mod) x %= mod;
}
 
void add(ll &x, ll y){
	x += y;
	if(x >= mod) x -= mod;
	if(x < 0) x += mod;
}
ll bp(ll a, ll n){
	ll r = 1;
	while(n){
		if(n & 1) mul(r, a);
		mul(a, a);
		n >>= 1;
	}
	return r;
}


void solve()
{
	int ans = 1;
	int x;
	cin >> x;
	for(int i = 2; i <= 1000; ++i){
		for(int j = i * i; j <= 1000; j *= i){
			if(j <= x) ans = max(ans, j);
		}
	}
	cout << ans << '\n';
}


 // a b c a b c a b c a b c
 
int main()
{
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
    Red;
  	int T = 1;
  	//cin >> T;
  	for(int i = 1; i <= T; ++i){
  		solve();
  	}
  	return 0;

}

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

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <typename T> using vec = std::vector<T>;
using namespace std;

int main() {
  ll N, T;
  cin >> N >> T;
  vec<ll> t(N);
  REP(i, N) cin >> t[i];

  ll res = T;
  FOR(i, 0, N - 1) {
    const ll dt = t[i + 1] - t[i];
    res += min(dt, T);
  }
  cout << res << endl;
  return 0;
}


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

int n,m,k;
string s,t;

int main() {
  cin >> s;
  int n=s.size();
  int ans=1e9;
  for(char c='a';c<='z';c++){
    int cnt=0;
    string t=s;
    while(1){
      string u;
      if(count(all(t),c)==t.size()) break;
      rep(i,t.size()-1){
        if(t[i]==c || t[i+1]==c) u+=c;
        else u+="A";
      }
      t=u;
      cnt++;
    }
    chmin(ans,cnt);
  }
  cout << ans << endl;
}

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

using namespace std;

int main(){
	int n, ans = 0; cin >> n;
	int a[n];
	for(int i = 0; i < n; ++i) cin >> a[i];
	
	int now = 1, count = 0;
	for(int i = 0; i < n; ++i){
		if(a[i] == now){
			now++;
			count++;
		}
	}
	if(count == 0){
		cout << -1 << endl;
		return 0;
	}
	ans = n - count;
	cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


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

    string ans = "Yes";
    if (a==2 || b==2) ans = "No";
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
h, w, k = map(int, input().split())
table = [list(input()) for i in range(h)]

def get_bitset(n): #get n-length-bitset
    pattern = []
    for i in range(2**n):
        tmp = []
        for j in range(n):
            if i >> j & 1:
                tmp.append(1)
            else:
                tmp.append(0)
        pattern.append(tmp)
    return pattern

row = get_bitset(h)
col = get_bitset(w)
ans = 0
for i_l in row:
    for j_l in col:
        count = 0
        for i in range(h):
            for j in range(w):
                if i_l[i] == 0 and j_l[j] == 0:
                    if table[i][j] == "#":
                        count += 1
        if count == k:
            ans += 1

print(ans)

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

int main(){
  int N;
  cin >> N;
  vector<long long> S(N);
  for(int i = 0; i < N; ++i) cin >> S[i];
  long long ans = 0;
  for(int i = 1; i < N; ++i){
    vector<long long> A(1,0), B(1,0);
    int r = (N-1)%i;
    for(int j = 0; j <= (N-1)/i; ++j){
      A.push_back(S[j*i]);
      B.push_back(S[j*i+r]);
    }
    for(size_t i = 1; i < A.size(); ++i) A[i] += A[i-1], B[i] += B[i-1];
    int M = A.size();
    for(int j = 0; j < M; ++j){
      long long a = i*j+r, b = a - i;
      if(a <= b) continue;
      if(b <= 0) continue;
      if(r == 0 and (a/i-1)*i+a < N-1) continue;
      long long s = A[M-j-1] + B.back() - B[j];
      ans = max(ans,s);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 2924
#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
const long long INF = 1LL << 60;
// const int INF=1010101010;
using Graph = vector<vector<int>>;

int main() {
  ll n;
  cin >> n;
  ll ma = 200010;
  vector<ll> t(ma);
  vector<ll> b(ma);
  vector<bool> k(ma);
  vector<ll> p;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    if (a + i <= ma) {
      b[a + i]++;
      if (k[a + i] == false) {
        p.push_back(a + i);
        k[a + i] = true;
      }
    }

    if (i - a >= 0) {
      t[i - a]++;
      if (k[i - a] == false) {
        p.push_back(i - a);
        k[i - a] = true;
      }
    }
  }
  ll ans = 0;
  for (int i = 0; i < p.size(); i++) {
    ans += t[p[i]] * b[p[i]];
  }
  cout << ans << endl;
}


Measured memory_bytes: 8404
/*
  Motto - try hard to become an expert
*/
#include <bits/stdc++.h>
#include <map>
#include <algorithm>
#include <vector>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <chrono>
#include <thread>
#include <iomanip>
 
//define
#define rep(i,n)    for(int i=0;i<n;i++)
#define repu(i,k,n) for(int i=k;i<=n;i++)
#define repd(i,k,n) for(int i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define INF (int)INT_MAX
#define all(v)  v.begin(), v.end()
#define endl "\n"
 
//typedef
typedef long long  ll;
typedef long double ld;
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
typedef std::vector< pii > vii;
typedef std::vector< ll > vll;
typedef std::vector< std::pair < pii, int > > vpp;
 
const int N = 3*1e5 +5 ;
const long long MOD = 998244353;
const long long inf = 1e18;
 
using namespace std;
 

 
ll modpow(ll x,ll n){
    ll res=1;
    while(n>0){
        if(n&1) res=res*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return res;
}
 
ll modFact(ll n, ll p) 
{ 
    if (n >= p) 
        return 0; 
  
    ll result = 1; 
    for (ll i = 1; i <= n; i++) 
        result = (result * i) % p; 
  
    return result;  
} 
 
bool isPrime(int x)
{
    if(x%2==0)
        return 0;
    for(int i=3;i<=sqrt(x);i+=2)
    {
        if(x%i==0)
            return 0;
    }
    return 1;
}
float slope(float x1 , float y1  , float x2 , float y2){

	if(x1==x2) return 0 ;
	return (y2-y1)/(x2-x1) ;
}
void solve()
{
	char a  , b ,c ;
	cin>>a>>b>>c ; 
	if(a=='7'  || b=='7' || c=='7'){
		cout<<"Yes\n";
	}
	else{
		cout<<"No\n";
	}

}
 
int main() {
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif
    
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int t = 1;
    // cin>>t;
    while(t--)
    {
        solve();
    } 
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 3756
a = int(input())
b = [1,2,3,4,5,6,7,8,9]
x = 0
for i in range(9):
    for j in range(9):
        if a == b[i] * b[j]:
            x = 1
            break
if x == 0:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 3060
using System;
class wa
{
    static void Main()
    {
        int[] a = new int[200];
        int r=0;
        for(int i = 0; i <200; i++)
        {
            string b = Console.ReadLine();
            if (string.IsNullOrEmpty(b)) { break; }
            string[] c = b.Split(' ');
            long d = long.Parse(c[0]), e = long.Parse(c[1]);
            long f = d + e;
            b = f.ToString();
            a[i] = b.Length;
            r++;
        }
        for(int i = 0; i < r; i++)
        {
            Console.WriteLine(a[i]);
        }
        
    }
}

Measured memory_bytes: 9036
import sys

def main():
    N,*S = map(int, open(0).read().split())
    S = sorted(S)

    g = [S.pop(-1)]

    for gen in range(N):
        tmp = []
        for p in g[:2**gen]:
            while S:
                s = S.pop(-1)
                if p > s:
                    g.append(s)
                    break
                else:
                    tmp.append(s)
            else:
                print('No')
                sys.exit()
        S.extend(tmp[::-1])
        g.sort(reverse=True)
    print('Yes')

if __name__=='__main__':
    main()

Measured memory_bytes: 32044
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String ns = sc.next();
    String[] s = ns.split("");
    String[] abc = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};
    for (int i = 0; i < s.length; i++) {
      for (int j = 0; j < abc.length; j++) {
        if (s[i].equals(abc[j])) {
          abc[j] = "None";
        }
      }
    }
    String ans = "None";
    for (int i = 0; i < abc.length; i++) {
      if (!abc[i].equals("None")) {
        ans = abc[i];
        break;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 46052
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#include<ext/rope>
#define int long long
using namespace std;
using namespace __gnu_cxx;
typedef long long LL;
const int MAXN = 2e6+10;
const int MOD = 1e9+7;
const int INF = 0x3f3f3f3f;
signed main(){
	double n; cin>>n;
	double x = ceil(n*1.0/1.08);
	if(floor(x*1.08)==n) cout<<x<<endl;
	else puts(":(");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <queue>

template <class Cost = int>
struct Edge {
    int src, dst;
    Cost cost;
    Edge(int src = -1, int dst = -1, Cost cost = 1)
        : src(src), dst(dst), cost(cost){};

    bool operator<(const Edge<Cost>& e) const { return this->cost < e.cost; }
    bool operator>(const Edge<Cost>& e) const { return this->cost > e.cost; }
};

template <class Cost = int>
using Graph = std::vector<std::vector<Edge<Cost>>>;

const std::vector<int>
    dx{-1, 0, 1, 0},
    dy{0, -1, 0, 1};

bool solve() {
    int n, m;
    std::cin >> n >> m;
    if (n == 0) return false;

    int nn = n * m;
    auto enc = [&](int x, int y) { return x * m + y; };

    std::vector<std::string> ss(n);
    for (auto& s : ss) std::cin >> s;

    Graph<bool> graph(nn);
    for (int x = 0; x < n; ++x) {
        for (int y = 0; y < m; ++y) {
            if (ss[x][y] == '#') continue;

            int v = enc(x, y);

            for (int i = 0; i < 4; ++i) {
                int nx = x + dx[i],
                    ny = y + dy[i];

                if (nx < 0 || n <= nx ||
                    ny < 0 || m <= ny ||
                    ss[nx][ny] == '#') continue;

                int u = enc(nx, ny);
                graph[v].emplace_back(v, u, true);
            }
        }
    }

    std::vector<bool> ok(nn, true);
    auto reachable =
        [&](int s, int t) -> bool {
        std::vector<bool> visited(nn, false);
        std::queue<int> que;

        visited[s] = true;
        que.push(s);

        while (!que.empty()) {
            int v = que.front();
            que.pop();

            for (auto e : graph[v]) {
                int u = e.dst;
                if (visited[u] || !ok[u]) continue;

                visited[u] = true;
                que.push(u);
            }
        }

        return visited[t];
    };

    for (int r = 0; r < nn; ++r) {
        if (r == enc(0, 0) || r == enc(n - 1, m - 1) ||
            r == enc(n - 1, 0) || r == enc(0, m - 1)) continue;

        ok[r] = false;

        if (!reachable(enc(0, 0), enc(n - 1, m - 1)) ||
            !reachable(enc(n - 1, 0), enc(0, m - 1))) {
            std::cout << "NO" << std::endl;
            return true;
        }

        ok[r] = true;
    }

    std::cout << "YES" << std::endl;
    return true;
}

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

    while (solve()) {}

    return 0;
}



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

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef long long LL;
typedef double db;

int get(){
	char ch;
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	if (ch=='-'){
		int s=0;
		while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
		return -s;
	}
	int s=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
	return s;
}

const int N = 2e5+5;

int n;
int a[N];
map<LL,int>cnt,need;

int main(){
	n=get();
	fo(i,1,n)a[i]=get();
	sort(a+1,a+1+n);
	fo(i,1,n)cnt[a[i]]++;
	int ans=0;
	fd(i,n,1){
		if (need[a[i]])need[a[i]]--;
		else{
			cnt[a[i]]--;
			LL L=1;
			for(;L<=a[i];L=L<<1);
			LL x=L-a[i];
			if (cnt[x]){
				ans++;
				cnt[x]--;
				need[x]++;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

int main() {
    int N; cin >> N;
    priority_queue<int64> PQ;
    rep(i, 0, N) {
        int64 a; cin >> a;
        PQ.push(a);
    }
    int64 ans = 0;
    while(PQ.top() + ans > N - 1) {
        int64 t = PQ.top() + ans; PQ.pop();
        int64 a = t / N;
        ans += a;
        PQ.push(t % N - ans);
    }
    cout << ans << endl;
    return 0;
}


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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;

void solve(){
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    int res=0;
    if(a<=k){
    	res+=a;
    	k-=a;
    }
    else{
    	res+=k;
    	k=0;
    }
    if(b<=k){
    	k-=b;
    }
    else{
    	k=0;
    }
    if(c<=k){
    	res-=c;
    	k-=c;
    }
    else{
    	res-=k;
    	k=0;
    }
    cout<<res<<endl;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007ll
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define db(x) cout << #x << " = " << x << '\n'
#define sep cout << "********************************************\n"
#define fast ios_base::sync_with_stdio(false), cin.tie(NULL)
ll dp[3003][3003], n, s, a[3003], MOD = 998244353;
int main(int argc, char const *argv[])
{
	fast;
	cin >> n >> s;
	for (int i = 1; i <= n; ++i)
	{
		cin >> a[i];
	}
	dp[0][0] = 1;
	for (int i = 1; i <= n; ++i)
	{
		for (int j = 0; j <= s; ++j)
		{
			dp[i][j] = (2 * dp[i - 1][j]) % MOD;
		}
		for (int j = 0; j <= s - a[i]; ++j)
		{
			dp[i][j + a[i]] = (dp[i][j + a[i]] + dp[i - 1][j]) % MOD;
		}
		// for (int j = 1; j <= s; ++j)
		// {
		// 	cout << dp[i][j] << ' ';
		// }
		// cout << '\n';
	}
	cout << dp[n][s];
	return 0;
}

Measured memory_bytes: 74004
# -*- coding: utf-8 -*-
def main():
    N = int(input())
    D = list(map(int,input().split()))
    ans = 0
    for i in range(N):
        for j in range(i+1,N):
            ans += (D[i]*D[j])
    print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		while(sc.hasNext()){
			int x=sc.nextInt();
			int n=0;
			for(int i=1;n<x;i++){
				n+=i;
				if(n>=x){
					System.out.println(i);
					break;
				}
			}
		}
	}
}

Measured memory_bytes: 21972
#include<iostream>
const int N=100001;
using namespace std;
int main(){
	int n,x[N],y[N],t[N];
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>t[i]>>x[i]>>y[i];
	}
	for(int i=1;i<=n;i++)
		if(x[i]+y[i]>t[i]||(t[i]-x[i]-y[i])%2!=0)
			{cout<<"No";
			return 0;	}
			cout<<"Yes";
			return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <tuple>
#include <algorithm>
#include <array>
#include <cmath>
using namespace std;
using ll = long long;
#define rep(i,n) for(decltype(n) i=0; i<n; ++i)
inline constexpr ll Inf = (1ULL << 62) -1;

template <class T>
void updatemax(T& a, T b) { if (b > a) a = b; }

int main() {
    ll N, ans=0;
    cin >> N;
    const int M = sqrt(N)+1;
    for (int i=2; i<=M && N!=1; i += (i==2)?1:2) {
        int d=0;
        for (; !(N%i); d++)
            N /= i;
        for (int e=1; d>=e; d -= e++)
            ans++;
    }
    if (N != 1)
        ++ans;
    cout << ans << endl;
    return 0;
}


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

int main() {
	// your code goes here
	int n,k,i,d=0,s=0,ans;
	char ss[100005];
	cin >> n >> k >> ss;
	for(i=1;i<n;i++){
		if(ss[i-1]==ss[i]) s++;
		else d++;
	}
	if(2*k>=d) cout << s+d << endl;
	else cout << s+2*k << endl;
	return 0;
}

Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace IPT1_2C
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] StringArray = Console.ReadLine().Split(' ');
            int[] NumArray = Array.ConvertAll(StringArray, new Converter<string, int>(s => int.Parse(s)));

            Array.Sort(NumArray);
            Console.WriteLine(NumArray[0] + " "
                + NumArray[1] + " "
                + NumArray[2]);
        }
    }
}

Measured memory_bytes: 9240
def bubbleSort(a,n):
    flag = 1
    c=0
    while(flag):
        flag = 0
        for i in reversed(range(1,len(a))):
            if(a[i] < a[i-1]):
                a[i],a[i-1] = a[i-1],a[i]
                c += 1
                flag = 1
    return [a,c]

n = int(input())
a = list(map(int,input().split(' ')))
sa , c = bubbleSort(a, n)
str = " ".join([str(i) for i in sa])
print("{}\n{}".format(str,c))


Measured memory_bytes: 5608
#include <bits/stdc++.h>
using namespace std;
int main() {
   int n;cin>>n;
   vector<int > v(n);
    for (int i = 0; i < n; ++i)
        cin>>v[i];
    vector <int > p(v);
    if(prev_permutation(p.begin(),p.end())){
        for (int i = 0; i < n-1; ++i) {
            cout<<p[i]<<" ";
        }
        cout<<p[n-1]<<endl;
    }
        for (int i = 0; i < n-1; ++i) {
            cout<<v[i]<<" ";
        }
        cout<<v[n-1]<<endl;
    if(next_permutation(v.begin(),v.end())){
        for (int i = 0; i < n-1; ++i) {
            cout<<v[i]<<" ";
        }
        cout<<v[n-1]<<endl;
    }
    return 0;
}



Measured memory_bytes: 3160
N,K=map(int,input().split())
T=[x+1 for x in range(N)]
for y in range(K):
    a=int(input())
    b=list(map(int,input().split()))
    for z in range(a):
        if b[z] in T:
            T.remove(b[z])
print(len(T))
    


Measured memory_bytes: 67672
#include <iostream>
#include <fstream>
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <numeric>
#include <functional>
#include <string> 
#include <vector>
#include <bitset>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define REP(i,n) for(int i = 0; i < int(n); i++)
#define REREP(i,n) for(int i = int(n - 1); i >= 0; i--)
#define FOR(i, m, n) for(int i = int(m);i < int(n);i++)
#define REFOR(i, m, n) for(int i = int(n - 1);i >= int(m);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define fi first 
#define se second

#define VI vector<int>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>
#define VD vector<double>
#define VVD vector<vector<double>>
#define VVVD vector<vector<vector<double>>>
#define VL vector<ll>
#define VVL vector<vector<ll>>
#define VVVL vector<vector<vector<ll>>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define VVVB vector<vector<vector<bool>>>
#define VS vector<string>
#define VVS vector<vector<string>>
#define VVVS vector<vector<vector<string>>>

#define PII pair<int,int>
#define PDD pair<double,double>
#define PLL pair<ll,ll>
#define VPII vector<pair<int,int>>
#define VVPII vector<vector<pair<int,int>>>
#define VVVPII vector<vector<vector<pair<int,int>>>>
#define VPLL vector<pair<ll,ll>>
#define VVPLL vector<vector<pair<ll,ll>>>
#define VVVPLL vector<vector<vector<pair<ll,ll>>>>

const ll MOD = (ll)1e9 + 7;
const ll HINF = (ll)1e18;
const ll LINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;


void YN(bool flag) {
	cout << ((flag) ? "YES" : "NO") << endl;
}

void Yn(bool flag) {
	cout << ((flag) ? "Yes" : "No") << endl;
}

void yn(bool flag) {
	cout << ((flag) ? "yes" : "no") << endl;
}

int main() {
	int N, K; cin >> N >> K;
	VL x(N),R,L; REP(i, N) cin >> x[i];
	REP(i, N) if (x[i] >= 0) R.push_back(x[i]);
	REREP(i, N) if (x[i] < 0) L.push_back(abs(x[i]));

	ll ans = HINF;
	FOR(i, 0, K + 1) {
		if (i <= L.size() && K - i <= R.size()) {
			if(i == 0) ans = min( ans, R[K - 1]);
			else if(i == K) ans = min(ans, L[K - 1]);
			else ans = min({ans, L[i - 1] + 2 * R[K - i - 1], 2 * L[i - 1] + R[K - i -1] });
		}
	}
	cout << ans << endl;

	
	return 0;
}


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

int main(){
   string s;
   cin >> s;
   int a1=-1;
   int z1=-1;
   for (int i=0;i<s.size();i++){
      if (a1==-1&&s.at(i)=='A')a1=i;
      if (s.at(i)=='Z')z1=i;
   }
   cout << z1-a1+1 << endl;
}


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

#define _p(...) (void)printf(__VA_ARGS__)
#define forr(x,arr) for(auto&& x:arr)
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) _rep3(i,0,n)
#define _rep3(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2,)(__VA_ARGS__)
#define _rrep2(i,n) _rrep3(i,0,n)
#define _rrep3(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2,)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define bit(n) (1LL<<(n))
#define sz(x) ((int)(x).size())
#define fst first
#define snd second
using ll=long long;using pii=pair<int,int>;using vb=vector<bool>;
using vi=vector<int>;using vvi=vector<vi>;using vvvi=vector<vvi>;
using vl=vector<ll>;using vvl=vector<vl>;using vvvl=vector<vvl>;
using vd=vector<double>;using vvd=vector<vd>;using vvvd=vector<vvd>;
using vpii=vector<pii>;using vvpii=vector<vpii>;using vvvpii=vector<vvpii>;
template <typename T> T read() {T t; cin >> t; return t;}

const int mod = 1000000007;

template<int MOD>
struct Mint {
  int x;
  Mint() : x(0) {}
  Mint(int y) : x(y >= 0 ? y % MOD : MOD - (-y) % MOD) {}
  Mint(signed long long sll) : x(sll % MOD) { if (x < 0) x += MOD; }
  Mint &operator+=(const Mint &rhs){ if((x += rhs.x) >= MOD) x -= MOD; return *this; }
  Mint &operator-=(const Mint &rhs){ if((x += MOD - rhs.x) >= MOD) x -= MOD; return *this; }
  Mint &operator*=(const Mint &rhs){ x = 1LL*x*rhs.x % MOD; return *this; }
  Mint &operator/=(const Mint &rhs){ x = (1LL*x*rhs.inv().x) % MOD; return *this; }
  Mint operator-() const { return Mint(-x); }
  Mint operator+(const Mint &rhs) const { return Mint(*this) += rhs; }
  Mint operator-(const Mint &rhs) const { return Mint(*this) -= rhs; }
  Mint operator*(const Mint &rhs) const { return Mint(*this) *= rhs; }
  Mint operator/(const Mint &rhs) const { return Mint(*this) /= rhs; }
  bool operator<(const Mint &rhs) const { return x < rhs.x; }
  Mint inv() const {
    signed a = x, b = MOD, u = 1, v = 0, t;
    while(b){ t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); }
    return Mint(u);
  }
  Mint operator^(unsigned long long t) const {
    Mint e = *this, res = 1;
    for(; t; e *= e, t>>=1) if (t & 1) res *= e;
    return res;
  }
};
template<int MOD> ostream &operator<<(ostream &os, const Mint<MOD> &rhs) { return os << rhs.x; }
template<int MOD> istream &operator>>(istream &is, Mint<MOD> &rhs) { long long s; is >> s; rhs = Mint<MOD>(s); return is; };

using mint = Mint<mod>;
using vm=vector<mint>;using vvm=vector<vm>;using vvvm=vector<vvm>;

void Main() {
  int n = read<int>();
  int m = read<int>();

  vvvm dp(m+1, vvm(n+1, vm(n+1)));
  dp[0][1][1] = 1;

  rep(i, m) {
    rep(j, 1, n+1) rep(k, 1, j+1) if (dp[i][j][k].x != 0) {
      // 既に行っている町(町1には行けない)に行く
      dp[i+1][j][k] += dp[i][j][k] * (j - k);

      // 既に行っている町(町1に行ける)に行く
      dp[i+1][j][j] += dp[i][j][k] * k;

      // 新しい町に行く
      if (n - j) dp[i+1][j+1][k] += dp[i][j][k] * (n - j);
    }
  }

  cout << dp[m][n][n] << endl;;
}
int main() { cin.tie(nullptr); ios::sync_with_stdio(false); Main(); return 0; }


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

using namespace std;
typedef  long long int ll;
#define rep(i, n) for (int i = 0; i < (n); i++)



int main () {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    cout << max(a+b, max(a-b, a*b)) << endl;

    return 0;
 }


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define int long long
#define puts(x) cout<<x<<endl
#define inf 243000000000000001
#define minf -243000000000000001



signed main(){
    int n,k;
    cin>>n>>k;
    vector<int>v(n);
    vector<int>ans(n);
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    ans[0]=0;
    ans[1]=abs(v[1]-v[0]);
    for(int i=2;i<=n-1;i++){
        int val=inf;
        for(int j=i-1;j>=max((int)0,i-k);j--){
            val=min(val,ans[j]+abs(v[j]-v[i]));
        }
        ans[i]=val;
    }
    puts(ans[n-1]);
}
  

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

#define int long long

const int N = 55;
int a[N], b[N], c[N], d[N];
int n, m, q;
int ans = 0;

void rec(vector<int> temp) {
	if((int)temp.size() == n) {
		int tot = 0;
		for(int i = 1; i <= q; i++) {
			if(temp[b[i]-1] - temp[a[i]-1] == c[i]) {
				tot += d[i];
			}
		}
		ans = max(ans, tot);
		return;
	}

	int back = (temp.size()) ? temp.back() : 1;
	for(int i = back; i <= m; i++) {
		temp.push_back(i);
		rec(temp);
		temp.pop_back();
	}
}

int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	cin >> n >> m >> q;
	for(int i = 1; i <= q; i ++) {
		cin >> a[i] >> b[i] >> c[i] >> d[i];
	}

	vector<int> temp;
	rec(temp);
	cout << ans << '\n';					
	return 0;
}


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

using namespace std;

int recurse(int i, vector<int> &dp , vector<int> &height)
{
    if(i <= 0) return INT_MAX;
    else if(i == 1) return 0;
    else
    {
        if(dp[i] >= 0) return dp[i];
        else
        {
            // for (int i = 0; i < dp.size(); i++)
            // {
            //     cout << dp[i] << " ";
            // }
            // cout << endl;
            int x =  min(recurse(i-1,dp,height) + abs(height[i-1] - height[i-2]) ,recurse(i-2,dp,height) + abs(height[i-1] - height[i-3]) );
            //cout << i << " " << x << endl;
            return dp[i] = x; 
        }
    }
}

int main(int argc, char const *argv[])
{
    int n,temp;
    cin >> n;
    vector<int> height(n,0);
    vector<int> dp(n+1,-1);
    for (int i = 0; i < n; i++)
    {
        cin >> temp;
        height[i] = temp;
    }
    dp[1] = 0;
    dp[2] = abs(height[1] - height[0]);
    cout << recurse(n,dp,height) << endl;

    // for (int i = 0; i <= n; i++)
    // {
    //     cout << dp[i] << " ";
    // }
    
    return 0;
}


Measured memory_bytes: 4096
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		int x = scan.nextInt();
		System.out.println(ans(a, b, c, x));
	}
	static int ans(int a , int b, int c , int x) {
		int ans = 0;
		for(int i = 0; i <= a; i++) {
			for(int j = 0; j <= b; j++) {
				for(int k = 0; k <= c; k++) {
					int work = i * 500 + j * 100 + k * 50;
					if(work == x) ans++;
				}
			}
		}
		return ans;
	}
}


Measured memory_bytes: 21972
#include <stdio.h>
 
int main()
{
     unsigned long n, a, b;
     scanf("%lu %lu %lu", &n, &a, &b);
 
     int count = 0;
     if(a > b)
     {
          printf("%d\n", 0);
          return 0;
     }
     else if(n <= 2 && a == b)
     {
          printf("%d\n", 1);
          return 0;
     }
     else if(n == 2 && a < b)
     {
          printf("%d\n", 2);
          return 0;
     }
     else if(n <= 2)
     {
          printf("%d\n", 0);
          return 0;
     }
 
     printf("%lu\n", 1 + b * (n-2) - a * (n-2));
 
     return 0;
}


Measured memory_bytes: 128
// -----------------------------------
// Author     : MatsuTaku
// Country    : Japan
// Created    : 05/23/20 20:47:37
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

constexpr int dir[4][2] = {
    {1,0},
    {-1,0},
    {0,1},
    {0,-1}
};

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

  int n; cin>>n;

  int H[n][n];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      H[i][j] = min({
        i,n-1-i,
        j,n-1-j
      });
    }
  }
  bool exist[n][n];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      exist[i][j] = 1;
    }
  }

  int ans = 0;
  for (int i = 0; i < n*n; i++) {
    int p; cin>>p; p--;
    int row = p/n;
    int col = p%n;
    ans += H[row][col];
    exist[row][col] = false;

    deque<pair<int,int>> qs;
    qs.emplace_back(row, col);
    while (not qs.empty()) {
      auto [r,c] = qs.front(); qs.pop_front();
      auto h = H[r][c] + (exist[r][c] ? 1 : 0);
      for (auto d:dir) {
        auto nr = r+d[0];
        auto nc = c+d[1];
        if (nr < 0 or nr >= n or nc < 0 or nc >= n)
          continue;
        if (h >= H[nr][nc])
          continue;
        H[nr][nc] = h;
        if (exist[nr][nc]) {
          qs.emplace_back(nr,nc);
        } else {
          qs.emplace_front(nr,nc);
        }
      }
    }
  }
  cout << ans << endl;

  return 0;
}


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

using namespace std;

#define foru(i, l, r) for (register int i = l; i <= r; i++)
#define ford(i, r, l) for (register int i = r; i >= l; i--)

int N, M, A, B;
int mp[1003][1003];

int main() {
  //  freopen("a.in", "r", stdin);
  //  freopen("a.out", "w", stdout);
  scanf("%d%d%d%d", &N, &M, &A, &B);
  for (int i = 1; i <= A; i++) mp[1][i] = 1;
  for (int i = A + 1; i <= M; i++) mp[1][i] = 0;
  for (int i = 2; i <= B; i++) memcpy(mp[i], mp[1], sizeof(mp[1]));
  for (int i = 1; i <= A; i++) mp[B + 1][i] = 0;
  for (int i = A + 1; i <= M; i++) mp[B + 1][i] = 1;
  for (int i = B + 1; i <= N; i++) memcpy(mp[i], mp[B + 1], sizeof(mp[B + 1]));
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= M; j++) printf("%d", mp[i][j]);
    putchar('\n');
  }
  return 0;
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
#define For( i, j, k ) for( int i = j; i <= k; ++i )
using std::cin;
using std::cout;
using std::pair;
const int N = 5e5 + 5;
int n, L, t[ N ], v[ N ], hd = 1, tl = 0;
pair < int, double > q[ N ];
int main( )
{
 std::ios::sync_with_stdio( false );
 cout.tie( 0 );
 cin >> n >> L;
 For( i, 1, n )
  cin >> t[ i ] >> v[ i ];
 long long cur = 0;
 int sum = 0;
 cout.setf( std::ios::fixed );
 cout << std::setprecision( 7 );
 For( i, 1, n )
 {
  while( v[ i ] + sum > L )
  {
   int po = std::min( q[ hd ].first, v[ i ] + sum - L );
   sum -= po;
   q[ hd ].first -= po;
   cur -= 1LL * po * q[ hd ].second;
   if( !q[ hd ].first )
    ++hd;
  }
  q[ ++tl ] = std::make_pair( v[ i ], t[ i ] );
  sum = L;
  cur += 1LL * v[ i ] * t[ i ];
  while( hd < tl && q[ tl - 1 ].second > q[ tl ].second )
  {
   q[ tl - 1 ].second = ( q[ tl - 1 ].second * q[ tl - 1 ].first + q[ tl ].second * q[ tl ].first ) / ( q[ tl ].first + q[ tl - 1 ].first );
   q[ tl - 1 ].first += q[ tl ].first;
   tl--;
  }
  cout << ( double ) cur / L << '\n';
 }
 return 0;
}

Measured memory_bytes: 21236
#include <iostream> 
#include <vector>
#include <algorithm>
#include <cstdio>

using namespace std;

int main() {
    vector<int> a(4);
    int N;
    cin >> N;
    for (int i = 0; i < N; i++) {
        string S;
        cin >> S;
        if (S == "AC") {
            a[0] += 1;
        } else if (S == "WA") {
            a[1] += 1;
        } else if (S == "TLE") {
            a[2] += 1;
        } else if (S == "RE") {
            a[3] += 1;
        }
    }

    cout << "AC x " << a[0] << endl;
    cout << "WA x " << a[1] << endl;
    cout << "TLE x " << a[2] << endl;
    cout << "RE x " << a[3] << endl;
}

Measured memory_bytes: 3628
n, p = map(int, input().split())
s = list(map(int, input()))
ans = 0

if p == 2 or p == 5:
    for i, x in enumerate(s):
        if (p == 2 and not x % 2) or (p == 5 and (x == 0 or x == 5)):
            ans += i+1
    print(ans)
    exit()

s.reverse()
cum = [0] * (n+1)
for i in range(n):
    cum[i+1] = (cum[i] + s[i] * pow(10, i, p)) % p
t = [0] * p
for x in cum: t[x] += 1

for x in t:
    ans += x * (x-1) // 2
print(ans)


Measured memory_bytes: 12616
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(int i = 0; i < x; i++)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
const ll N = 1e9+7;
const int n_max = 1e5+10;

int main(){
    int n; cin >> n;
    string s[n];
    rep(i,n) cin >> s[i];
    vector<int> a[n];
    ll ans = 0;
    unordered_map<string, ll> ump;
    rep(i,n){
        sort(s[i].begin(), s[i].end());
        if(ump[s[i]] == 0){
            ump[s[i]] = 1;
        }
        else{
            ans += ump[s[i]];
            ump[s[i]]++;
        }
    }
    cout << ans << endl;
    // rep(i, n) cout << s[i] << " ";
    // cout << endl;
    return 0;

}

Measured memory_bytes: 20004
import java.util.HashMap

fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val input = readLine()!!
    val cmap = HashMap<Char, Int>()

    for (c in input) {
        // hashmap の初期化されていない値はnull になっている
        // cmap[c]?.let { cmap.put(c, it + 1) } ?: cmap.put(c, 1)
        if (cmap.containsKey(c)){
            cmap[c] = cmap[c]!! + 1
        } else {
            cmap[c] = 1
        }
    }

    var ans = 1L
    for (key in cmap.keys) {
        // ans の計算は愚直に最後まで行うとオーバーフローする
        // 合同式の考え方で常に余りを計算していく
        ans = ans * (cmap[key]!! + 1) % (Math.pow(10.0, 9.0).toLong() + 7)
    }
    print(ans-1)
}

Measured memory_bytes: 34808
import sys
input=sys.stdin.readline

n=int(input())
l=[]
for i in range(n):
    x,y=map(int,input().split())
    if x==y:
        l.append(1)
    else:
        l.append(0)

count=0
for i in range(n):
    if l[i]==1:
        count+=1
    else:
        count=0
    if count==3:
        print('Yes')
        sys.exit()
print('No')

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

int N, D, X;
int total=0;

main()
{
    cin >> N >> D >> X;

    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        for (int j = 1; j <= D; j+=a) {
            total += 1;
        }
    }

    cout << total + X << endl;
    return 0;
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 123456789
//0x3f3f3f3f
#define INFL 10000000000000000
using namespace std;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
typedef pair<int,pii> pdii;
long long int MOD = 1000000007;
vector<pii> graph[2525];
ll  H,W;
ll getnum(ll a,ll b,ll c){
	ll ma=max(a,max(b,c));
	ll mi=min(a,min(b,c));
	//cout<<ma-mi<<endl;
	return ma-mi;
	
}
ll check(ll x,ll y){
	ll xx=x/3,yy=y/2;
	ll ret1,ret2;
	ret1=getnum(xx*y,(x-xx)*yy,(x-xx)*(y-yy));
	xx++;
	ret2=getnum(xx*y,(x-xx)*yy,(x-xx)*(y-yy));
	return min(ret1,ret2);
}
int main(){
	cin>>H>>W;
	if(H%3==0||W%3==0)cout<<0<<endl;
	else cout<<min(min(H,W),min(check(H,W),check(W,H)))<<endl;
	
}



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

using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long INF = 1LL << 60;
long long dp[100100];

class UnionFind {
public:
    vector<int> Parent;

    UnionFind(int N) {
        Parent = vector<int> (N, -1);
    }

    int root(int X) {
        if(Parent[X] < 0) return X;
        return Parent[X] = root(Parent[X]);
    }

    int size(int X) {
        return -Parent[root(X)];
    }

    bool unite(int A, int B) {
        A = root(A);
        B = root(B);
        if(A == B) return false;

        if(size(A) < size(B)) swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;

    }

};

int main() {
    int N, M; cin >> N >> M;
    
    vector<int> A(M), B(M);
    for(int i = 0; i < M; i++) {
        cin >> A[i] >> B[i];
        A[i]--;
        B[i]--;
    }

    vector<long long> ans(M);
    ans[M-1] = (long long)N * (N-1) / 2;

    UnionFind Uni(N);

    for(int i = M-1; i >= 1; i--) {
        if (Uni.root(A[i]) != Uni.root(B[i])) {
            ans[i - 1] = ans[i] - (long long)Uni.size(A[i]) * Uni.size(B[i]);
            Uni.unite(A[i], B[i]);
        }    
        else ans[i - 1] = ans[i];
    }

    for(int i = 0; i < M; i++) {
        cout << ans[i] << endl;
    }               

    return 0;
}


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

int main(){
  int N,D,X;
  cin>>N>>D>>X;
  D--;
  for(int i=0;i<N;i++){
    int j;
    cin>>j;
    X+=D/j+1;
  }
  cout<<X<<endl;
}

Measured memory_bytes: 256
from fractions import gcd
class segtree():
    def segfunc(x,y):
        return min(x,y)
    #####単位元######
    ide_ele = -1
    n=1
    init_val=[0]*n
    #num:n以上の最小の2のべき乗
    num =2**(n-1).bit_length()
    seg=[ide_ele]*2*num
    
    def __init__(self,INIT_VAL,SEGFUNC,IDE_ELE):
        self.ide_ele=IDE_ELE
        self.init_val=[i for i in INIT_VAL]
        self.segfunc=SEGFUNC
        self.n=len(self.init_val)
        self.num =2**(self.n-1).bit_length()
        self.seg=[self.ide_ele]*2*self.num
 
        #set_val
        for i in range(self.n):
            self.seg[i+self.num-1]=self.init_val[i]    
        #built
        for i in range(self.num-2,-1,-1) :
            self.seg[i]=self.segfunc(self.seg[2*i+1],self.seg[2*i+2]) 
        
    def update(self,k,x):
        k += self.num-1
        self.seg[k] = x
        while k+1:
            k = (k-1)//2
            self.seg[k] = self.segfunc(self.seg[k*2+1],self.seg[k*2+2])
        
    def query(self,p,q):
        if q<=p:
            return self.ide_ele
        p += self.num-1
        q += self.num-2
        res=self.ide_ele
        while q-p>1:
            if p&1 == 0:
                res = self.segfunc(res,self.seg[p])
            if q&1 == 1:
                res = self.segfunc(res,self.seg[q])
                q -= 1
            p = p//2
            q = (q-1)//2
        if p == q:
            res = self.segfunc(res,self.seg[p])
        else:
            res = self.segfunc(self.segfunc(res,self.seg[p]),self.seg[q])
        return res
N=int(input())
A=[int(i) for i in input().split()]
B=segtree(A,gcd,0)
C=[gcd(B.query(0,i),B.query(i+1,N)) for i in range(N)]
print(max(C))


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

#define mod 1000000007

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

using namespace std;
typedef long long ll; 
 
int main(void){
	
	int H, W, h, w;
	
	cin >> H >> W;
	cin >> h >> w;
	
	cout << (H - h) * (W - w);
	
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <bitset>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
 
using namespace std;
typedef long long ll;
 
int main(){
  int N,D,A;
  cin >> N >> D >> A;
  vector<pair<int,int>> v(N+1);
  v[N]=make_pair(1000000010,0);
  for(int i=0;i<N;i++){
    cin >> v[i].first >> v[i].second;
    v[i].second=(v[i].second+A-1)/A;
  }
  
  sort(v.begin(), v.end());

  vector<int> d(N+1,0);

  int cur=0;
  ll ans=0;
  for(int i=0;i<N;i++){
    cur-=d[i];
    //cout << v[i].first << " " << cur;
    if(cur<v[i].second){
      ans+=v[i].second-cur;
      int n=distance(v.begin(),upper_bound(v.begin(),v.end(),make_pair(v[i].first+2*D+1,0)));
      d[n]+=v[i].second-cur;
      cur+=v[i].second-cur;
    }
    //cout << " " << ans << endl;
  }

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


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

int main() {
  int N, a, b, c, d;
  cin >> N ;
  a = N / 1000 ;
  b = (N -a * 1000 ) / 100 ;
  c = (N - a * 1000 - b * 100) / 10 ;
  d = N - a * 1000 - b * 100 - c * 10 ;
  if ((a == b && b == c) ||(b == c && c == d)) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}



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

using namespace std;

int main()
{
	int n;
	string s;
	int d[101];
	d[0]=0;
	int x=0;
	int cnt;
	cin>>n;
	cin>>s;
	for(int i=0;i<n;i++)
	{
		if(s[i]=='(')
		{
			d[i+1] = d[i]+1;
		}else if(s[i]==')'){
			d[i+1] = d[i]-1;
		}
		x = min(x,d[i+1]);
	}
	cnt = (-1)*x;
	for(int i=0;i<cnt;i++)
	{
		s.insert(0,"(");
	}
	cnt = d[n] - x;
	for(int i=0;i<cnt;i++)
	{
		s += ")";
	}
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		for(;;) {
			c-=b;
			if(c<=0) {
				System.out.println("Yes");
				break;
			}
			a-=d;
			if(a<=0) {
				System.out.println("No");
				break;
			}
		}
	}
}


Measured memory_bytes: 35772
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int[] array = new int[n];
		for(int i = 0; i < array.length; i++)
			array[i] = sc.nextInt();
		
		int count = 0;
		int max = array[0];
		
		for(int i = 0; i < array.length; i++) {
			if(array[i] >= max)
				count++;
			max = Math.max(max, array[i]);
		}
		
		System.out.println(count);
	}
}


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

struct Edge {
  int to;
  int index;
};

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

  vector<vector<Edge>> g(n);
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    g[a].push_back(Edge{b, i});
  }

  int k = 0;
  vector<bool> visited(n);
  queue<pair<int, int>> q;
  q.emplace(0, 0);

  vector<int> color(n - 1);
  while (!q.empty()) {
    int p = q.front().first;
    int c0 = q.front().second;
    q.pop();
    visited[p] = true;
    int cc = 1;
    for (Edge e : g[p]) {
      if (visited[e.to]) {
        continue;
      }
      while (cc == c0) {
        ++cc;
      }
      color[e.index] = cc;
      q.emplace(e.to, cc);
      k = max(k, cc);
      ++cc;
    }
  }

  cout << k << endl;
  for (int i = 0; i < n - 1; ++i) {
    cout << color[i] << endl;
  }
}

Measured memory_bytes: 5120
#include<cstdio>
#include<cstring>
int n,m; char c[510][510],a[510][510]; 
int main() {
	scanf("%d%d",&n,&m);
	for (int i=1; i<=n; ++i) scanf("%s",c[i]+1);
	memcpy(a,c,sizeof c);
	for (int i=1; i<=n; i+=2)
		for (int j=1; j<m; ++j) a[i][j]='#';
	for (int i=1; i<=n; ++i) a[i][1]='#',puts(a[i]+1);
	memcpy(a,c,sizeof c);
	for (int i=2; i<=n; i+=2)
		for (int j=2; j<m; ++j) a[i][j]='#';
	for (int i=1; i<=n; ++i) a[i][m]='#',puts(a[i]+1);
	return 0;
}

Measured memory_bytes: 1152