akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int h,w;
string mp[2005];
int res[2005][2005];
int res2[2005][2005];

int solve(int x, int y, int dx, int dy, int t){
  int nx = x + dx;
  int ny = y + dy;

  if(0 <= nx && nx < w && 0 <= ny && ny < h && mp[ny][nx]=='.') {
    t = solve(nx, ny, dx, dy, t + 1);
  }

  if (dx==1)
    res[y][x] = t;
  else
    res2[y][x] = t;
  return t;
}

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

  cin>>h>>w;
  for(int y=0;y<h;y++){
    cin>>mp[y];
  }
  for(int y=0;y<h;y++){
    for(int x=0;x<w;x++){
      if(mp[y][x]=='.' && !res[y][x])
        solve(x, y, 1, 0, 1);
    }
  }
  for(int x=0;x<w;x++){
    for(int y=0;y<h;y++){
      if(mp[y][x]=='.' && !res2[y][x])
        solve(x, y, 0, 1, 1);
    }
  }
  int ans=0;
  for(int y=0;y<h;y++){
    for(int x=0;x<w;x++){
      ans = max(ans, res[y][x] + res2[y][x]);
    }
  }

  cout<<ans-1<<endl;



  return 0;
}


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

int main(){
	int n, m, max, min;
	cin >> n >> m >> max >> min;
	for(int i = 0; i < n; i++){
		int temp;
		cin >> temp;
		if(temp > max)
			max = temp;
	}
	for(int i = 0; i < m; i++){
		int temp;
		cin >> temp;
		if(temp < min)
		min = temp;
	}
	if(max < min)
		cout << "No War\n";
	else
		cout << "War\n";
}

Measured memory_bytes: 256
def solve(string):
    n, *axy = map(int, string.split())
    i = 0
    h = [set() for _ in range(n)]
    u = [set() for _ in range(n)]
    for j in range(n):
        a = axy[i]
        for x, y in zip(*[iter(axy[i + 1:i + 2 * a + 1])] * 2):
            if y == 1:
                h[j].add(x - 1)
            else:
                u[j].add(x - 1)
        i += 2 * a + 1

    def search(checking, honest, unkind):
        if len(honest & unkind) > 0:
            return 0
        if len(checking) == 0:
            return len(honest)
        t = checking.copy()
        c = t.pop()
        return max(search(t, honest | {c} | h[c], unkind | u[c]), search(t, honest, unkind | {c}))

    return str(search(set(range(n)), set(), set()))


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    int q;
    cin >> q;
    while(q--)
    {
        ll a, b;
        cin >> a >> b;
        ll l = min(a, b);
        ll h = max(a, b);
        if(l == 1 && h == 1)
        {
            cout << 0 << endl;
            continue;
        }
        else if(l == 1 && h == 2)
        {
            cout << 0 << endl;
            continue;
        }
        if(a == b)
        {
            cout << 2 * (a-1) << endl;
            continue;
        }

        ll x = sqrt(a*b) / 1;
        if(x * (x+1) < a * b)
        {
            cout << 2 * x - 1 << endl;
        }
        else
        {
            if(x * x == a * b) cout << 2 * x - 3 << endl;
            else cout << 2 * x - 2 << endl;
        }
    }
}


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

int main() {
  int n, d;
  cin >> n >> d;
  
  vector<int> x(n);
  vector<int> y(n);
  for(int i = 0; i < n; i++){
  cin >> x.at(i) >> y.at(i);
  }
  int cnt = 0;
  for(int i = 0; i < n; i++){
  //cout << x.at(i) << " "<<y.at(i) << endl;
   double answer = sqrt(pow(x.at(i), 2)+pow(y.at(i), 2));
      if(answer <= d) cnt++;
   // cout << answer << endl;
  }
  
cout << cnt << endl;
}


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

int main() {
  int n, x, a[105];
  cin >> n >> x;
  for (int i = 0; i< n; i++) cin >> a[i];
  sort(a, a + n);
  
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (i == n - 1) {
      if (a[i] == x) ans++;
    }
    else if (x - a[i] >= 0) {
      ans++;
      x -= a[i];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#define ALL(a) (a).begin(), (a).end()

const ll mod = 1000000007;
const ll LINF = 1e13;
const ll LLINF = 1e18;
const ll ALPHABET = 26;

template <class T>
void Swap(T &r, T &l)
{
    T tmp = r;
    r = l;
    l = tmp;
}

template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
    for (T &x : vec)
        is >> x; //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいい
    return is;
}

int main()
{
    ll n;
    cin >> n;
    vector<ll> v(n);
    cin >> v;

    
    sort(v.begin(),v.end());
    double ans = v[0];

    for (ll i = 1; i < n; i++)
    {   cerr << ans <<endl;
        ans = (double)(ans + (double)v[i]) /2.0;
    }
    


    cout<< setprecision(7)<< fixed <<ans<<endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define BUF 1e5
#define INF 1 << 30
constexpr ll mod = 1e9 + 7;
using namespace std;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

int main() {
    cin >> N;
    vector<ll> a(N);
    for (int i = 0; i < N; i++)
        cin >> a[i];
    ll tmp = 0;
    for (int i = 0; i < N - 1; i++) {
        tmp = 2 * a[i] - tmp;
    }
    vector<ll> m(N);
    m[0] = (2 * a[N - 1] - tmp) / 2;
    for (int i = 0; i < N - 1; i++) {
        m[i + 1] = 2 * a[i] - m[i];
    }
    for (int i = 0; i < N; i++) {
        cout << m[i] << " ";
    }
}

Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template<typename T>
vector<T> dijkstra(int s,vector<vector<pair<int,T>>> &G){
    const T INFINF=numeric_limits<T>::max();
    using P=pair<T,int>;
    int n=G.size();
    vector<T> d(n,INFINF);
    vector<int> b(n,-1);//previous point
    priority_queue<P,vector<P>,greater<P>> q;
    d[s]=0;
    q.emplace(d[s],s);
    while(!q.empty()){
        P p=q.top();q.pop();
        int v=p.second;
        if(d[v]<p.first) continue;
        for(auto& e:G[v]){
            int u=e.first;
            T c=e.second;
            if(d[u]>d[v]+c){
                d[u]=d[v]+c;
                b[u]=v;
                q.emplace(d[u],u);
            }
        }
    }
    return d;
}

 
////////////////////
template< typename T>
struct SparseTable{
    vector<vector<T> > st;
    vector<int> lookup;
    T op(T a,T b){
        //max , min or etc...
        return min(a,b);
    }
 
    SparseTable(const vector<T> &v){
        int b=0;
        while((1<<b)<=v.size()) b++;
        //resize  st[k][i]:iの2^k先までの範囲の
        st.assign(b,vector<T>(1<<b));
        for(int i=0;i<v.size();i++) st[0][i]=v[i];
        for(int i=1;i<b;i++){
            for(int j=0;j+(1<<i)<=(1<<b);j++){
                st[i][j]=op(st[i-1][j],st[i-1][j+(1<<(i-1))]);
            }
        }
        lookup.resize(v.size()+1);
        for(int i=2;i<lookup.size();i++){
            lookup[i]=lookup[i>>1]+1;
        }
    }
    //[)
    T f(int l,int r){
        assert(l<=r);
        //a[l~l+2^k],a[r-2^k~r]が区間を覆うように
        int b=lookup[r-l];
        return op(st[b][l],st[b][r-(1<<b)]);
    }
};
//////////////


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

    int n,m,s,t;
    cin>>n>>m>>s>>t;s--,t--;
    vector<vector<pair<int,ll>>> gy(n),gs(n);
    rep(_,m){
        int u,v;ll yen,snk;
        cin>>u>>v>>yen>>snk;
        u--,v--;
        gy[u].push_back(make_pair(v,yen));
        gy[v].push_back(make_pair(u,yen));
        gs[u].push_back(make_pair(v,snk));
        gs[v].push_back(make_pair(u,snk));
    }
    auto v1=dijkstra(s,gy);
    auto v2=dijkstra(t,gs);

    //両替所をiとするときの旅行コストcost[i]
    vector<ll> cost(n);
    rep(i,n){
        cost[i]=v1[i]+v2[i];
    }
    SparseTable<ll> st(cost);
    rep(i,n){
        cout<<((ll)1e15-st.f(i,n))<<endl;
    }
    return 0;
}

Measured memory_bytes: 37372
N = int(input())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))
C_list = list(map(int, input().split()))
add = 0

for i in range(N-1):
    target = A_list[i]
    if (A_list[i+1] - target) == 1:
        add += C_list[target - 1]

print(sum(B_list) + add)

Measured memory_bytes: 3064
using DataStructures

parseInt() = parse(Int,readline())
parseLine() = parse.(Int,split(readline()))

const MOD = 10^9+7

function solve()
    N = parseInt()
    cnt = counter(Rational{Int})
    zero = 0
    for i in 1:N
        a, b = parseLine()
        if (a==0 && b==0)
            zero+=1
        else
            inc!(cnt,a//b)
        end
    end

    pow2 = Vector{Int}(undef,N+1)
    pow2[1] = 1
    for i in 2:N+1
        pow2[i] = mod(pow2[i-1]*2,MOD)
    end

    ans = 1
    for (r,c) in cnt
        inv = r==0//1 ? 1//0 : -1/r
        ans *= pow2[c+1] + pow2[cnt[inv]+1] - 1
        reset!(cnt, inv)
        ans %= MOD
    end
    ans = mod(ans+(zero-1)+MOD, MOD)
    println(ans)
end

solve()

Measured memory_bytes: 250792
while True:
    n = 1
    a,b = input().split()
    if a == "0" and b == "0":
        break
    for num1 in range(int(a)):
        if n % 2 != 0:
            m = 0
        elif n % 2 == 0:
            m = 1
        for num2 in range(int(b)):
            if m == 0:
                print("#",end="")
                m = 1
                continue
            if m == 1:
                print(".",end="")
                m = 0
                continue
        print()
        n += 1
    print()


Measured memory_bytes: 7008
#include <bits/stdc++.h>
#define rep(i,s,n) for(int i=s;i<n;i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define all_acc(x) (x).begin(),(x).end(),0LL
#define int long long
using namespace std;
using P=pair<int,int>;
using Graph=vector<vector<int>>;
using ll=long long;

int accumulate(int* a,int n){
    return accumulate(a,a+n,0LL);
}

int accumulate(vector<int> a){
    return accumulate(a.begin(),a.end(),0LL);
}

signed main(){ 
    int n; cin>>n;
    vector<int> A(20000000,0);
    int a[n];
    for(int i=0;i<n;i++){
        int ai; cin>>ai;
        a[i]=ai;
        A[ai]+=1;
    }
    int result=accumulate(a,n);

    int q; cin>>q;
    
    vector<int> scores;

    for(int i=0;i<q;i++){
        int b,c;
        cin>>b>>c;
        result=result+(c-b)*A[b];
        A[c]+=A[b];
        A[b]=0;

        scores.push_back(result);
    }

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

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

int main() {

	int n, a, b;
	cin >> n >> a >> b;

	int res = 0;
	for (int i = 1; i <= n; i++) {
		int wk = i;
		int wa = 0;
		while (wk > 0) {
			wa = wa + wk % 10;
			wk /= 10;
		}
		wa += wk;
		if (a <= wa && wa <= b) {
			res += i;
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 256
from __future__ import division, print_function

''' Hey stalker :) '''
INF = 10 ** 10
TEST_CASES = False

def main():
    get_int()
    li = get_list()
    res = 1
    if 0 in li:
        print(0)
        return
    limit = 10**18
    for i in li:
        res *= i
        # print(res)
        if res > limit:
            print(-1)
            return
    print(res)
''' FastIO Footer: PyRival Library, Thanks @c1729 and contributors '''
import os
import sys
from bisect import bisect_left, bisect_right
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip
BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
# else:
#     sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")
get_int = lambda: int(input())
get_list = lambda: list(map(int, input().split()))
if __name__ == "__main__":
    if TEST_CASES:
        [main() for _ in range(int(input()))]
    else:
        main()


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

using namespace std;

int main(){
	int N,M;
	cin>>N>>M;
	if(N%2==1)
	{	
	for(int i = 1,j=N;M;i++,j--,M--)
	{
		cout<<i<<" "<<j<<endl;
	} 
    }
    else{
      int p = N/2;
      int l = 1 ,r = p-1;
      while(l<r&&M)
      {
      	cout<<l<<" "<<r<<endl;
      	l++;
      	r--;
      	M--;
	  }
	  l = p+1,r=N;
	  while(M && l<r)
	  {
	  	cout<<l<<" "<<r<<endl;
	  	l++;
	  	r--;
	  	M--;
	  }
	    }
	return 0;
}

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

//region Template
#include "ext/pb_ds/assoc_container.hpp"

using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const int MOD = 1000000007;
using namespace std;
#define finish(x) cout << x; exit(0);
#define fastIO cin.tie(0); cin.sync_with_stdio(false);
#define endl '\n'

void setIn(string s) { freopen(s.c_str(), "r", stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }

//const string USCAO_TAG = "mountains";
void usaco(const string& USACO_TAG) { setIn(USACO_TAG + ".in"); setOut(USACO_TAG + ".out"); }
void print() {}
template<typename T, typename... Args>
void print(T firstArg, Args... args) {
	#ifdef LOCAL
	cout << firstArg << " ";
	print(args...);
	#endif
}
//endregion

/* Notes:
 * Farah </3
 */

const int MAXN = 1e6 + 5;

vector<pair<int, int>> e;

map<pair<int, int>, int> col;

vector<ll> pw;

ll a[MAXN], cnt[MAXN];
int main() {
	//usaco("milkvisits");

	#ifdef LOCAL
	setIn("in.txt");
	setOut("out.txt");
	#endif

	ll pwt = 1;
	for(int i = 0; i < 61; i++){
		pw.push_back(pwt);
		pwt *= 2;
	}

	ll n;
	cin >> n;


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

		for(int j = 0; a[i]; j++, a[i] >>= 1ll){
			if(a[i] & 1ll){
				cnt[j]++;
			}
		}
	}

	//cout << cnt[1] << endl;
	ll ans = 0;
	for(int i = 0; i < 61; i++){
		ans = ans + (n - cnt[i]) * (((cnt[i] % MOD) * (pw[i] % MOD)) % MOD);
		ans %= MOD;
	}

	cout << ans;
}

Measured memory_bytes: 4352
#include <stack>
#include <utility>
#include <iostream>
#include <string>
#include <set>
#include <algorithm>
#include <vector>
#include <queue>
#include <functional>
#include <string.h>
#include <cstdio>
using namespace std;
struct edge { int to, cap, rev; };
vector<edge>map[103];
bool used[103];
int dfs(int v,int t,int f){
    if (v == t)return f;
    used[v] = true;
    for (int i = 0; i < map[v].size(); i++) {
        edge &e = map[v][i];
        if (!used[e.to] && e.cap>0) {
            int d = dfs(e.to, t, min(f, e.cap));
            if (d > 0) {
                e.cap -= d;
                map[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}
int main()
{
    int V, E;
    int a, b, c;
    cin >> V >> E;
    for (int i = 0; i < E; i++) {
        cin >> a >> b >> c;
        edge ed = { b,c,map[b].size() };
        map[a].push_back(ed);
        edge edg = { a,0,map[a].size() - 1 };
        map[b].push_back(edg);
    }int ans = 0;
    for (;;) {
        memset(used, 0, sizeof(used));
        int f = dfs(0, V - 1, 9999999);
        if (f == 0)break;
        ans += f;
    }
    cout << ans<<endl;
}

Measured memory_bytes: 3152
S=[list(map(int, input().split())) for i in range(3)]

T1=[]
T2=[]

for i in range(3):
    T1.append(S[1][i]-S[0][i])
for i in range(3):
    T2.append(S[2][i]-S[1][i])


if T1[0]==T1[1]==T1[2] and T2[0]==T2[1]==T2[2]: print("Yes")
else: print("No")


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

using namespace std;

const int N = 100005;

int main() {
	int m, n;
	scanf("%d %d", &m, &n);

	vector<int> a(n);

	for(int &x: a) scanf("%d", &x);

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

	int ans = 0;
	for(int i = 0; i + 1 < n; i++) {
		ans = max(ans, a[i + 1] - a[i]);
	}
	ans = max(ans, a[0] + m - a[n - 1]);

	printf("%d\n", m - ans);
}


Measured memory_bytes: 3944
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <climits>
#include <map>
using namespace std;

int main() {
    int a, b;
    
    cin >> a >> b;
    
    if ( a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0 ) {
        cout << "Possible" << endl;
    } else {
        cout << "Impossible" << endl;
    }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner stdin = new Scanner(System.in);
		if(stdin.nextInt()%500-stdin.nextInt()<=0) {
			System.out.println("Yes");
		}else {
			System.out.println("No");

		}


	}

}


Measured memory_bytes: 21584
using System;
					
public class Program
{
	public static void Main()
	{
		while(true) {
			var n = int.Parse(Console.ReadLine());
			
			if(n == 0)	break;
			
			var s = Console.ReadLine().Split(' ');
			
			var val = Array.ConvertAll(s, x=>int.Parse(x));
			
			var sum = 0.0;
			foreach(var v in val) {
				sum += v;
			}
			
			var ave = sum / val.Length;
			
			var devSum = 0.0;
			foreach(var v in val) {
				devSum += (v-ave)*(v-ave);
			}
			
			Console.WriteLine( Math.Sqrt(devSum / val.Length) );
		}
	}
}

Measured memory_bytes: 9244
#include "bits/stdc++.h"
using namespace std;

int main() {
	static long long N, K, A, AS[1010] = {}, SUM[500100] = {}, COUNT = 0, ANS = 0;
	cin >> N >> K;
	for (int i = 0; i < N; i++) {
		cin >> A;
		AS[i + 1] = AS[i] + A;
	}
	for (int i = 0; i <= N; i++) {
		for (int j = i + 1; j <= N; j++) {
			SUM[COUNT] = AS[j] - AS[i];
			COUNT++;
		}
	}
	for (int i = 40; i >= 0; i--) {
		long long X = 1LL << i, KCOUNT = 0;
		X += ANS;
		for (int j = 0; j < COUNT; j++) {
			if ((X & SUM[j]) == X) KCOUNT++;
		}
		if (KCOUNT >= K) ANS += 1LL << i;
	}
	cout << ANS << endl;
}

Measured memory_bytes: 4096
import math
inp = input().split()

a = int(inp[0])
b = int(inp[1])
k = int(inp[2])


def cookie(giver,getter):
    if giver%2 == 0:
        sub = math.floor(giver/2)
        giver = giver - sub
        getter = getter + sub
    else:
        tmp = giver - 1
        sub = math.floor(tmp/2)
        giver = giver - 1 - sub
        getter = getter +  sub


for i in range(k):
    if i%2 == 0:
        if a%2 == 0:
            sub = math.floor(a / 2)
            a = a - sub
            b = b + sub
        else:
            tmp = a - 1
            sub = math.floor(tmp / 2)
            a = a - 1 - sub
            b = b + sub
    else:
        if b%2 == 0:
            sub = math.floor(b/ 2)
            b = b - sub
            a = a + sub
        else:
            tmp = b - 1
            sub = math.floor(tmp / 2)
            b = b - 1 - sub
            a = a + sub


print(a,b)


Measured memory_bytes: 3064
N = input()
K = int(input())
n = len(N)
dp = [[[0]*(K+1) for _ in range(2)] for _ in range(n+1)]
dp[0][0][0] = 1

for i in range(1, n+1):
    l = int(N[i-1])
    for k in range(K+1):
        dp[i][1][k] += dp[i-1][1][k]
        if l != 0:
            dp[i][1][k] += dp[i-1][0][k]
        else:
            dp[i][0][k] += dp[i-1][0][k]
        if k-1 >= 0:
            dp[i][1][k] += dp[i-1][1][k-1]*9
            if l != 0:
                dp[i][0][k] += dp[i-1][0][k-1]
                dp[i][1][k] += dp[i-1][0][k-1]*(l-1)
                
print (dp[n][0][K]+dp[n][1][K])

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)

ll S[100100];
ll T[100100];

ll hS[100100];
ll hT[100100];
int main(){
    int A, B, Q;
    cin >> A >> B >> Q;
    S[0] = -1e12;
    T[0] = -1e12;
    S[A+1] = 1e12;
    T[B+1] = 1e12;
    REP(i,A){
        ll s;
        cin >> s;
        S[i+1] = s;
    }
    REP(i,B){
        ll t;
        cin >> t;
        T[i+1] = t;
    }


    REP(i,Q){
        ll ans = LLONG_MAX;
        ll x;
        cin >> x;
        int sidx = lower_bound(S, S+A+2, x) - S;
        int tidx = lower_bound(T, T+B+2, x) - T;

        ll ah = S[sidx];
        ll al = S[sidx-1];
        ll bh = T[tidx];
        ll bl = T[tidx-1];

        //printf("(ah, al) = (%lld, %lld)\n", ah, al);
        //printf("(bh, bl) = (%lld, %lld)\n", bh, bl);
        ans = min(ans, x - min(al, bl));
        ans = min(ans, max(ah, bh) - x);
        ans = min(ans, 2*(x-al) + (bh-x));
        ans = min(ans, 2*(x-bl) + (ah-x));
        ans = min(ans, 2*(ah-x) + (x-bl));
        ans = min(ans, 2*(bh-x) + (x-al));

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


Measured memory_bytes: 2944
// i hope i get better                                                           
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int sz=1e2+9;
ll n;
ll tot5;

int main(){
	cin>>n;
	if(n&1){
		cout<<0;
		return 0;
	}
	ll t=10;
	while(n>=t){
		tot5+=n/t;
		t*=5;
	}
	cout<<tot5;
	return 0;
}


// 1000000000000000000
// 124999999999999995
// 124999999999999945
// 999996185302734375


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 3e2 + 10;
using pi = pair <int, int>;
vector <pi> e[N];
int cnt[N], fue[N];
bool inq[N];
int ans[N][N];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m, l;
    cin >> n >> m >> l;
    for (int i = 1; i <= m; ++i)
    {
        int u, v, w;
        cin >> u >> v >> w;
        e[u].emplace_back(make_pair(v, w));
        e[v].emplace_back(make_pair(u, w));
    }
    for (int s = 1; s <= n; ++s)
    {
        queue <int> q;
        memset(cnt, 0x3f, sizeof(cnt));
        memset(fue, 0x3f, sizeof(fue));
        memset(inq, 0, sizeof(inq));
        cnt[s] = fue[s] = 0;
        for (q.emplace(s); !q.empty(); q.pop())
        {
            int u = q.front();
            inq[u] = 0;
            for (auto i : e[u])
            {
                int v = i.first, w = i.second;
                if (w > l)
                    continue;
                int t = cnt[u], f = fue[u] + w;
                if (f > l)
                {
                    f = w;
                    ++t;
                }
                if (t < cnt[v] || (t == cnt[v] && f < fue[v]))
                {
                    fue[v] = f;
                    cnt[v] = t;
                    if (!inq[v])
                    {
                        inq[v] = 1;
                        q.emplace(v);
                    }
                }
            }
        }
        for (int t = 1; t <= n; ++t)
            ans[s][t] = cnt[t] == 0x3f3f3f3f ? -1 : cnt[t];
    }
    int q;
    cin >> q;
    while (q--)
    {
        int s, t;
        cin >> s >> t;
        cout << ans[s][t] << endl;
    }
}


Measured memory_bytes: 2048
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Object o = run();
        if (o != null)
            System.out.println(o);
    }

    static Object run() {
        try (Scanner sc = new Scanner(System.in)) {
            int r = sc.nextInt();
            int g = sc.nextInt();
            return r + (g - r) * 2;
        }
    }
}

class ChenNumberUtil {
    static Collection<Integer> getDivisors(int n) {
        ArrayList<Integer> al = new ArrayList<>();
        for (int i = 1; i * i <= n; i++) {
            if (n % i == 0) {
                al.add(i);
                if (n / i != i)
                    al.add(n / i);
            }
        }
        Collections.sort(al);
        return al;
    }
}

class ChenBitUtil {
    static int popCount(int bit) {
        return Integer.bitCount(bit);
    }

    static boolean isFlag(int bit, int i) {
        return 0 != (bit & (1 << i));
    }

    static int setTrue(int bit, int i) {
        return bit |= (1 << i);
    }

    static int setFalse(int bit, int i) {
        return bit &= ~(1 << i);
    }

    static int setReverse(int bit, int i) {
        return isFlag(bit, i) ? setFalse(bit, i) : setTrue(bit, i);
    }

    static int reverseAll(int bit) {
        return ~bit;
    }
}


Measured memory_bytes: 26960
s = input()
n=len(s)
ans=0
for i in range(2**(n-1)):
    bit=i
    a = []
    for k in range(n-1):
        a.append(bit % 2)
        bit //= 2
    t = ""
    for j in range(n-1):
        t += s[j]
        if (a[j]):
            t += "+"
    t+=s[-1]
    #print(t)
    ans += eval(t)
print(ans)



Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;
#define mp  std::make_pair
#define ll long long int
#define abs(n) ((n>0)?(n):((n)*(-1)))
#define CEIL(a,b) (((a) + ((b)-1)) / (b))
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
#define VREP_ll(v) for(std::vector<ll>::iterator itr = (v).begin(); itr != (v).end();itr++)
#define VREP_int(v) for(std::vector<int>::iterator itr = (v).begin(); itr != (v).end();itr++)
#define VALL(v) ((v).begin(),(v).end())
#define errln(v) cerr << (v) << endl;
#define println(v) cout << (v) << endl;

int main(int argc, const char * argv[]) {
	int r,d,x;
	cin >> r >> d >> x;
	REP(i,10){
		x = x*r-d;
		println(x);
	}
	return 0;
}


Measured memory_bytes: 256
let n, w = Scanf.scanf " %d %d" @@ fun a b -> a, b
let wvs = Array.init n @@ fun _ -> Scanf.scanf " %d %d" @@ fun a b -> a, b
let dp = Array.make_matrix n (w + 1) 0
let _ =
  for i = 0 to w do let (w', v) = wvs.(0) in if w' <= i then dp.(0).(i) <- v done;
  for i = 1 to n - 1 do
    for j = 0 to w do
      dp.(i).(j) <- dp.(i - 1).(j);
      let w', v = wvs.(i) in
      if w' <= j then dp.(i).(j) <- max dp.(i).(j) @@ dp.(i - 1).(j - w') + v done done;
  Printf.printf "%d\n" @@ dp.(n - 1).(w)

Measured memory_bytes: 81272
#include <iostream>
#include <cstdio>
using namespace std;
char maps[1001][1001];
int n;
bool rectn(int y,int x,int k){
	for(int i=0;i<k;i++)if(i+y>=n||i+x>=n||maps[y+k-1][i+x]=='*'||maps[i+y][x+k-1]=='*')return false;
	return true;
}
int rect(int y,int x){
	for(int k=1;1;k++)if(k-1>=n||!rectn(y,x,k))return k-1;
}
void solve(){
	int ans=0;
	for(int i=0;i<n;i++){
		if(ans>=n-i)break;
		for(int j=0;j<n;j++){
			if(maps[i][j]=='.')ans=max(ans,rect(i,j));
		}
	}
	cout<<ans<<endl;
}

int main(){
	while(cin>>n&&n){
		for(int i=0;i<n;i++)cin>>maps[i];
		solve();
	}
	return 0;
}

Measured memory_bytes: 1636
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)n;i++)
using Graph = vector<vector<int> >;
using GraphC = vector<vector<char> >;
typedef pair<int, int> P;
const int MAX_N = 10000;
const int MAX_L = 100000000;
const int MAX_SQRT_B = 10000;
const int INF = 1000000000;
typedef int64_t ll;
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; }

int N, K;

int main() {
	cin >> N >> K;
	int ans = K;
	for (int i = 0; i < N-1; i++)
	{
		ans *= (K - 1);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3616
#include<cstdio>
    #include<cstdlib>
    #include<cmath>
    #include<iostream>
    #include<string>
    #include<stack>
    #include<queue>
    #include<vector>
    #include<map>
    #include<set>
    #include<algorithm>
     
    #define rep(n) for(int i=0;i<n;i++)
    #define repp(j, n) for(int j=0;j<n;j++)
    #define reppp(i, m, n) for(int i=m;i<=n;i++)
    #define all(c) c.begin(), c.end()
    #define rall(c) c.rbegin(), c.rend()
    #define pb(x) push_back(x)
    #define eb(x, y) emplace_back(x, y)
    #define MOD 1000000007
    #define MAX 1000000001
    #define INF 1410065408
    #define EPS 1e-9
     
    using namespace std;
    typedef long long ll;
    typedef pair<ll, ll> P;
    struct edge{int from, to; ll cost;};
     
    signed main(){
    	int n;
    	cin >> n;
    	vector<ll> x, y;
    	map<ll, ll> mx, my;
    	vector<P> xy;
    	rep(n){
    		ll xx, yy;
    		cin >> xx >> yy;
    		if(xx > yy) swap(xx, yy);
    		x.pb(xx);
    		y.pb(yy);
    		xy.eb(xx, yy);
    		mx[xx]++;
    		my[yy]++;
    	}
    	sort(all(xy));
    	
    	ll rmax = mx.rbegin()->first, rmin = mx.begin()->first;
    	ll bmax = my.rbegin()->first, bmin = my.begin()->first;
    	ll ans = (rmax - rmin) * (bmax - bmin);
    	
    	rep(n){
    		ll xx = xy[i].first, yy = xy[i].second;
    		mx[xx]--; mx[yy]++;
    		my[yy]--; my[xx]++;
    		if(mx[xx] == 0) mx.erase(xx);
    		if(my[yy] == 0) my.erase(yy);
    		rmax = mx.rbegin()->first, rmin = mx.begin()->first;
    		bmax = my.rbegin()->first, bmin = my.begin()->first;
    		ans = min(ans, (rmax - rmin) * (bmax - bmin));
    	}
    	cout << ans;
    }

Measured memory_bytes: 31952
#include<bits/stdc++.h>
using namespace std;
#define nl '\n'
int main()
{
    string a,b,c;
    cin>>a>>b>>c;
    cout<<char(toupper(a[0]))<<char(toupper(b[0]))<<char(toupper(c[0]));
    cout<<nl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <complex>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::to_string;
using std::vector;
using std::set;
using std::queue;
using std::priority_queue;

using std::min;
using std::max;
using std::min_element;
using std::max_element;
using std::sort;
using std::count;
using std::abs;

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

    vector<bool> a(8);
    int wild = 0;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;

        if (1 <= x && x <= 399) {
            a[0] = true;
        } else if (400 <= x && x <= 799) {
            a[1] = true;
        } else if (800 <= x && x <= 1199) {
            a[2] = true;
        } else if (1200 <= x && x <= 1599) {
            a[3] = true;
        } else if (1600 <= x && x <= 1999) {
            a[4] = true;
        } else if (2000 <= x && x <= 2399) {
            a[5] = true;
        } else if (2400 <= x && x <= 2799) {
            a[6] = true;
        } else if (2800 <= x && x <= 3199) {
            a[7] = true;
        } else {
            wild++;
        }
    }

    int cnt = count(a.begin(), a.end(), true);
    cout << max(cnt, 1) << " " << (cnt + wild) << endl;

    return 0;
}


Measured memory_bytes: 256
import std.conv, std.functional, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.container, std.math, std.numeric, std.range, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }


enum L = 26;

int N, Q;
string S;
char[] T, D;

int calc(int x) {
  foreach (q; 0 .. Q) {
    if (S[x] == T[q]) {
      x += ((D[q] == 'L') ? -1 : +1);
      if (!(0 <= x && x < N)) {
        return x;
      }
    }
  }
  return x;
}

void main() {
  try {
    for (; ; ) {
      N = readInt();
      Q = readInt();
      S = readToken();
      T = new char[Q];
      D = new char[Q];
      foreach (q; 0 .. Q) {
        T[q] = readToken()[0];
        D[q] = readToken()[0];
      }
      
      debug {
        foreach (x; 0 .. N) {
          writeln("calc ", x, " = ", calc(x));
        }
      }
      int ansL, ansR;
      {
        int lo = -1, hi = N;
        for (; lo + 1 < hi; ) {
          const mid = (lo + hi) / 2;
          ((calc(mid) >= 0) ? hi : lo) = mid;
        }
        ansL = hi;
      }
      {
        int lo = -1, hi = N;
        for (; lo + 1 < hi; ) {
          const mid = (lo + hi) / 2;
          ((calc(mid) < N) ? lo : hi) = mid;
        }
        ansR = lo;
      }
      int ans = ansR - ansL + 1;
      chmax(ans, 0);
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}


Measured memory_bytes: 3964
import java.util.*;

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

		// 文字列の入力
		String s = sc.next();
		String t = sc.next();

		List<String> sArray = new ArrayList<String>();
		for (int i = 0; i < s.length(); i++) {
			sArray.add(s.substring(i, i + 1));
		}
		Collections.sort(sArray);
		String cs = "";
		for (String string : sArray) {
			cs = cs + string;
		}
		List<String> tArray = new ArrayList<String>();
		for (int i = 0; i < t.length(); i++) {
			tArray.add(t.substring(i, i + 1));
		}
		Collections.sort(tArray);
		String ct = "";
		for (String string : tArray) {
			ct = string + ct;
		}

		if (cs.compareTo(ct) < 0) {
			System.out.println("Yes");

		} else {
			System.out.println("No");

		}

	}
}

Measured memory_bytes: 23764
#include<stdio.h>
int main()
{
	int n,a[100010];
	while(~scanf("%d",&n))
	{
		long long b;
		if(n==1)
		{
			scanf("%lld",&b);
			if(b==1)
			{
				printf("0\n");
			}
			else
			{
				printf("1\n");
			}
			continue;
		}
		for(int i=0;i<100010;i++)
		a[i]=0;
		int s=0;
		for(int i=0;i<n;i++)
		{
			scanf("%lld",&b);
			if(b>100000)
			{
				s++;
			}
			else
			{
				a[b]++;
			}
		}
		for(int i=0;i<=100000;i++)
		{
			if(a[i]>i)
			{
				s+=a[i]-i;
			}
			else if(a[i]<i)
			{
				s+=a[i];
			}
		}
		printf("%d\n",s);
	}
}


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

int n;
int nums[25];
bool dp[25][40005] = {false};

int main(){
    cin >> n;
    for(int i = 0; i < n; i++){
    cin >> nums[i];    
    }
    dp[0][0] = true;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 40005; j++){
            dp[i + 1][j] |= dp[i][j];
            if(j >= nums[i]) dp[i + 1][j] |= dp[i][j - nums[i]];
        }
    }
    int q; cin >> q;
    for(int i = 0; i < q; i++){
        int m; cin >> m;
        if(dp[n][m]) cout << "yes" << endl;
        else cout << "no" << endl;
    }
}


Measured memory_bytes: 3912
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
from bisect import bisect_left
 
N = int(input())
a = [int(i) for i in input().split()]
vec = [[] for _ in range(N)]
for _ in range(N - 1) :
  u, v = map(int, input().split())
  vec[u - 1].append(v - 1)
  vec[v - 1].append(u - 1)
 
lis = [a[0]]
ret = [0] * N
def dfs(cur, pre) :
  for nex in vec[cur] :
    if nex == pre : continue
    if a[nex] > lis[-1] :
      lis.append(a[nex])
      ret[nex] = len(lis)
      dfs(nex, cur)
      lis.pop()
    else :
      pos = bisect_left(lis, a[nex])
      v = lis[pos]
      lis[pos] = a[nex]
      ret[nex] = len(lis)
      dfs(nex, cur)
      lis[pos] = v
 
dfs(0, -1)
 
ret[0] = 1
for i in range(N) :
  print(ret[i])

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

using namespace std;
typedef long long ll;

const ll INF = 4e18;
const int MN = 16;
const int MS = 1 << 16;
int n;
int a[MN][MN];
ll dp[MS], sum[MS];

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

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

    int u = (1 << n) - 1;
    for (int t = 0; t <= u; t++) {
        for (int i = 0; i < n; i++) {
            if (!(t & 1 << i)) continue;
            for (int j = i + 1; j < n; j++) {
                if (!(t & 1 << j)) continue;
                sum[t] += a[i][j];
            }
        }
    }

    fill(dp + 1, dp + u + 1, -INF);
    for (int t = 0; t <= u; t++) {
        for (int s = t; s != 0; s = (s - 1) & t) {
            dp[t] = max(dp[t], dp[t - s] + sum[s]);
        }
    }

    cout << dp[u] << endl;
    return 0;
}

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

int main() {
    int a,b;
    int total = 0;
    cin >> a >> b;
    if (a>b) {
        total += a;
        a--;
    }
    else{
        total += b;
        b--;
    }
    if (a>b) {
        total += a;
        a--;
    }
    else{
        total += b;
        b--;
    }
    cout << total;
}



Measured memory_bytes: 256
import java.util.*;
import java.io.*;
//267630EY
public class Main
{
  static PrintWriter out=new PrintWriter(System.out);

  public static void main(String[] args) throws IOException
  {
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int[] a=sc.nextIntArray(n);
    int[] dp=new int[n+1];
    dp[1]=0;
    dp[2]=Math.abs(a[1]-a[0]);
    for(int i=3;i<=n;i++)
    {
      dp[i]=Math.min(dp[i-1]+Math.abs(a[i-1]-a[i-2]),dp[i-2]+Math.abs(a[i-1]-a[i-3]));
    }
    out.println(dp[n]);
    out.flush();

        
   
      
      
                
    
  }
  
  static class Scanner
  {
    BufferedReader br;
    StringTokenizer tk=new StringTokenizer("");
    public Scanner(InputStream is) 
    {
      br=new BufferedReader(new InputStreamReader(is));
    }
    
    public boolean hasNext()
    {
      

      boolean result=false;
      
      try 
      {
        result = br.ready();
      } 
      catch (IOException e)
      {
        System.err.println(e);
      }
      return result;
    }
    
    public int nextInt() throws IOException
    {
      if(tk.hasMoreTokens())
        return Integer.parseInt(tk.nextToken());
      tk=new StringTokenizer(br.readLine());
      return nextInt();
    }
    public long nextLong() throws IOException
    {
      if(tk.hasMoreTokens())
        return Long.parseLong(tk.nextToken());
      tk=new StringTokenizer(br.readLine());
      return nextLong();
    }
    public String next() throws IOException
    {
      if(tk.hasMoreTokens())
        return (tk.nextToken());
      tk=new StringTokenizer(br.readLine());
      return next();
    }
    public String nextLine() throws IOException
    {
      tk=new StringTokenizer("");
      return br.readLine();
    }
    public double nextDouble() throws IOException
    {
      if(tk.hasMoreTokens())
        return Double.parseDouble(tk.nextToken());
      tk=new StringTokenizer(br.readLine());
      return nextDouble();
    }
    public char nextChar() throws IOException
    {
      if(tk.hasMoreTokens())
        return (tk.nextToken().charAt(0));
      tk=new StringTokenizer(br.readLine());
      return nextChar();
    }
    public int[] nextIntArray(int n) throws IOException
    {
      int a[]=new int[n];
      for(int i=0;i<n;i++)
        a[i]=nextInt();
      return a;
    }
    public long[] nextLongArray(int n) throws IOException
    {
      long a[]=new long[n];
      for(int i=0;i<n;i++)
        a[i]=nextLong();
      return a;
    }
    public int[] nextIntArrayOneBased(int n) throws IOException
    {
      int a[]=new int[n+1];
      for(int i=1;i<=n;i++)
        a[i]=nextInt();
      return a;
    }
    public long[] nextLongArrayOneBased(int n) throws IOException
    {
      long a[]=new long[n+1];
      for(int i=1;i<=n;i++)
        a[i]=nextLong();
      return a;
    }
  }
}



Measured memory_bytes: 32088
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
#define fir first
#define sec second
#define pb push_back
#define lowbit(x) ((x)&(-(x))) 

int n, k; 
string s; 

int main() {
	cin>>n>>k>>s; ;
	int num = 1;  
	for (int i = 1; i < n; ++i)
		if (s[i] != s[i-1]) num++; 
	cout<<n-max(1,(num-2*k))<<endl;  
}


Measured memory_bytes: 512
def solve(N, data):
   ret = N
   data.sort(key=lambda x: x[0] - x[1])
   most_right = float("-inf")
   for idx, d in enumerate(data):
       l, r = d[0] - d[1], d[0] + d[1]
       if not idx:
           most_right = r
           continue
       if most_right <= l:
           most_right = r
           continue
       ret -= 1
       most_right = min(r, most_right)
   return ret

if __name__ == "__main__":
    N = int(input())
    data = []

    for _ in range(N):
        data.append(list(map(int, input().split())))
    print(solve(N, data))

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

int main(){
  int a,b,count=0;
  char op;
  int results[20000];
  while(true){
    scanf("%d %c %d", &a, &op, &b);
    if(op == '?'){
      break;
    }

    switch(op){
     case '+':
       results[count] = a+b;
       break;
     case '-':
       results[count] = a-b;
       break;
     case '*':
       results[count] = a*b;
       break;
     case '/':
       results[count] = a/b;
       break;
    }
    count++;
  }
  for(int i=0; i < count; i++){
    printf("%d\n", results[i]);
  }
}



Measured memory_bytes: 2724
import java.util.*;

public class Main {

    public static void main(String[] args) {

    	Scanner sc = new Scanner(System.in);

    	int N = sc.nextInt();
        int[] A = new int[N+1];
        int[] B = new int[N+1];
        int[] C = new int[N];
        int ans = 0;

        A[0] = 100;
        B[0] = 0;
        C[0] = 0;

        for (int i = 1; i <= N; i++) {
            A[i] = sc.nextInt();
        }

        for (int i = 1; i <= N; i++) {
            B[A[i]] = sc.nextInt();
        }

        for (int i= 1; i < N; i++) {
            C[i] = sc.nextInt();
        }

        for (int i = 1; i < N; i++) {
            ans += B[i];
            if (A[i+1] - A[i] == 1) {
                ans += C[A[i]];
            }
   	    }
   	    ans += B[N];
        System.out.println(ans);
    }
}

Measured memory_bytes: 22612
#include <iostream>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cfloat>
#include <algorithm>
#include <numeric>
#include <vector>
#include <iterator>
#include <set>
#include <map>
using namespace std;

const double PI=acos(-1);

int main(){
    string s, t, u;
    cin >> s >> t;
    u = t;
    u.erase(u.end()-1);
    if(s == u) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3632
chomp($n = <>);

$s = int($n / 1.08);

if(int($s * 1.08) == $n){
	printf "$s\n";
}elsif(int(($s - 1) * 1.08) == $n){
	printf ($s - 1) . "\n";
}elsif(int(($s + 1) * 1.08) == $n){
	printf ($s + 1) . "\n";
}else{
	print ":(\n";
}


Measured memory_bytes: 384
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    int quantity[] = {200, 300, 500};
    int value[] = {380, 550, 850};
    int unit[] = {5, 4, 3};
    int discount[] = {20, 15, 12};

    vector<int> cost(51, INT_MAX/2);
    cost[0] = 0;
    for(int i=1; i<=50; ++i){
        for(int j=0; j<3; ++j){
            int k = i - quantity[j]/100;
            if(k >= 0)
                cost[i] = min(cost[i], cost[k] + value[j]);

            k = i - quantity[j]/100 * unit[j];
            if(k >= 0)
                cost[i] = min(cost[i], cost[k] + value[j] * unit[j] * (100-discount[j]) / 100);
        }
    }

    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;
        cout << cost[n/100] << endl;
    }
}

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

int main(){
    int n,j=0;
    string s;
    cin>>n>>s;
    if(n%2==1){
        cout<<"No";
    }
    else
    {for(int i=0;i<n/2;i++){
        if(s[i]==s[n/2+i]){j+=1;}
        else{j=0;}
    }
    if(j==n/2){cout<<"Yes";}
    else{cout<<"No";}}}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int c[105][105];
int main(){
	int n;
	cin>>n;
	for(int i=1;i<=100;i++){
		for(int j=1;j<=100;j++){
			c[i][j]=(i+j)*(i+j);
		}
	}
	for(int i=1;i<=n;i++){
		int d=i<<1;
		int cnt=0;
		for(int x=1;x<=sqrt(i);x++){
			for(int y=x;y<=sqrt(i);y++){
				for(int z=y;z<=sqrt(i);z++){
					if(c[x][y]+c[x][z]+c[y][z]==d){
						if(x==y&&y==z) cnt++;
						else if(x!=y&&y!=z&&x!=z) cnt+=6;
						else cnt+=3;
					}
				}
			}
		}
		cout<<cnt<<endl;
	}
	return 0;
}

Measured memory_bytes: 3588
#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;
using vi = vector<int>;
using vii = vector<vi>;
using in6 = int64_t;
using ind = double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
    int a,b,c;
    cin >> a >> b >> c;
    if(a < b && b < c) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 3108