akhauriyash/Code-Regression huggingface dataset:
import std.stdio, std.conv, std.string, std.bigint;
import std.math, std.random, std.datetime;
import std.array, std.range, std.algorithm, std.container, std.format;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
/*

まず0の耳がない場合を考える

その場合は、端から端まで歩くとしてよい。各耳に1が入る
そして同じ箇所を往復することにより2ずつ石を入れれるので2で割った余りだけ見ればよい
(a[i] - 1) % 2

1 1 0 0 1 0 0 1 0 1 0 1 
などとなっている

両端から折り返して、どこかからどこかまでをカバーする
そこまでに含まれてしまう0の数と、真ん中に含まれてしまう1の数が、調整しなければならない個数
1 1 0 0 1 0 0 1 0 1 0 1 
~~~     *     ~~*~~~*~~

真ん中に含まれる0の数 - 真ん中に含まれる1の数 が最大になればよい
これは尺取り法でできる

--------------------------------------------------------------------------------

さて0の耳がある場合については…

0の場合にも対応できるように改良する

2をどんどん引いて、0、1、2のいずれかにする
1 1 0 0 1 2 0 1 2 1 2 1

0というのはもともとの0
1というのは先程の言い方でいう0
2というのは先程の言い方でいう1


外れた場合 これを基準とする
0→ペナ0
1→ペナa
2→ペナa

外側に入った場合 p
0→ペナ2 (+2)
1→ペナ1 (-(a-1))
2→ペナ0 (-a)

中央に入った場合 q
0→ペナ1 (+1)
1→ペナ0 (-a)
2→ペナ1 (-(a-1))


点iから始めて、左に行って帰ってくる場合の最良を x[i]
点j - 1から始めて、右に行って帰ってくる場合の最良を y[j]

x[i] = min(x[i - 1] + p[i], 0)
y[j] = min(y[j + 1] + p[j], 0)

点i以左から始めて、点iに帰ってくる場合の最良を x2[i]
点j以右から始めて、点jに帰ってくる場合の最良を y2[i]

x2[i] = min(x[i], x2[i - 1] + q[i]);
y2[i] = min(y[j], y2[j + 1] + q[j]),

求めるものは min(x2[i] + y2[i])

*/


void main(){
	long l = read.to!long;
	
	long[] as;
	foreach(i; 0 .. l) as ~= read.to!long;
	debug writeln("as:", as);
	
	long[] ps, qs;
	foreach(i; 0 .. l){
		long a = as[i];
		if(a == 0) ps~= 2, qs ~= 1;
		else if(a % 2 == 1) ps ~= -(a - 1), qs ~= -a;
		else ps ~= -a, qs ~= -(a - 1);
	}
	debug writeln("ps:", ps);
	debug writeln("qs:", qs);
	
	long[] xs = new long[](l + 1);
	xs[0] = 0;
	foreach(i; 1 .. l + 1) xs[i] = min(xs[i - 1] + ps[i - 1], 0);
	debug writeln("xs:", xs);
	
	long[] ys = new long[](l + 1);
	ys[l] = 0;
	foreach_reverse(i; 0 .. l) ys[i] = min(ys[i + 1] + ps[i], 0);
	debug writeln("ys:", ys);
	
	long[] x2s = new long[](l + 1);
	x2s[0] = xs[0];
	foreach(i; 1 .. l + 1) x2s[i] = min(x2s[i - 1] + qs[i - 1], xs[i]);
	debug writeln("x2s:", x2s);
	
	long[] y2s = new long[](l + 1);
	y2s[l] = ys[l];
	foreach_reverse(i; 0 .. l) y2s[i] = min(y2s[i + 1] + qs[i], ys[i]);
	debug writeln("y2s:", y2s);
	
	long sum;
	foreach(a; as) sum += a;
	debug writeln("sum:", sum);
	
	long ans = sum + 10;
	foreach(i; 0 .. l + 1) ans = min(ans, sum + x2s[i] + y2s[i]);
	
	ans.writeln;
	
}



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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
int main() {
	int n = ri();
	int a[n][n];
	for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) a[i][j] = ri();
	int64_t pre[1 << n];
	memset(pre, 0, sizeof(pre));
	for (int i = 0; i < 1 << n; i++)
		for (int j = 0; j < n; j++) for(int k = 0; k < j; k++) if ((i >> j & 1) && (i >> k & 1)) pre[i] += a[j][k];
	int64_t dp[1 << n];
	for (int i = 0; i < 1 << n; i++) dp[i] = -1000000000000000000;
	dp[0] = 0;
	for (int i = 0; i < 1 << n; i++) {
		int mask = ~i & ((1 << n) - 1);
		int cur = mask;
		do {
			dp[i | cur] = std::max(dp[i | cur], dp[i] + pre[cur]);
			cur = (cur - 1) & mask;
		} while (cur != mask);
	}
	std::cout << dp[(1 << n) - 1] << std::endl;
	return 0;
}


Measured memory_bytes: 1280
# import bisect
from collections import Counter, deque # https://note.nkmk.me/python-scipy-connected-components/
from copy import copy, deepcopy
# from functools import reduce
# from heapq import heapify, heappop, heappush
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    ans=10**4
    s=list(input())
    ss=Counter(s)
    if len(ss)==1:
        ans=0
    else:
        for k in ss.keys():
            l=copy(s)
            cnt=0

            while True:
                for i in range(len(l)-1):
                    if l[i]==k or l[i+1]==k:
                        l[i]=k
                    else:
                        continue
                l=l[:-1]
                cnt+=1
                if len(set(l))==1:
                    ans=min(ans,cnt)
                    break
    print(ans)




resolve()

Measured memory_bytes: 39408
#include <bits/stdc++.h>
#define FI(i,a,b) for(int i=(a);i<=(b);i++)
#define FD(i,b,a) for(int i=(b);i>=(a);i--)
#define len(a) int((a).size())
using namespace std;
using LL = long long;
using PII = pair<int, int>;

int D[10][10];

int main() {
    int h, w;
    scanf("%d%d", &h, &w);
    FI(i,0,9) FI(j,0,9) scanf("%d", &D[i][j]);
    FI(k,0,9) FI(i,0,9) FI(j,0,9) {
        if (i != j && i != k && j != k && D[i][j] > D[i][k] + D[k][j]) D[i][j] = D[i][k] + D[k][j];
    }
    LL ans = 0;
    FI(i,1,h) FI(j,1,w) {
        int x;
        scanf("%d", &x);
        if (x == -1) continue;
        ans += D[x][1];
    }
    printf("%lld\n", ans);
}

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

using namespace std;
#define MOD 1000000007
#define pi 3.1415926535897932384626433832795028841971693993751058209749445923078164062
#define ll long long
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define popb pop_back()
#define popf pop_front()
#define ff first
#define ss second
#define vl vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vll vector< pair<ll,ll> >
#define vii vector< pair<int,int> >
#define viii vector< tuple <int,int,int> >
#define vlll vector< tuple <ll,ll,ll> >
#define vvl vector<vector<ll>>
#define vv vector<vector<int>>
#define all(v) v.begin(),v.end()
#define sqrt sqrtl
#define cbrt cbrtl
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mapcl map<char,ll>
#define mapci map<char,int>
#define mapll map<ll,ll>
#define mapii map<int,int>
#define seti set<int>
ifstream fin("input.txt");
ofstream fout("output.txt");

int gcd(int a,int b){while (a&&b)a>b?a%=b:b%=a;return a+b;}
ll pows(int a , int b){ll res=1;for(int i=0; i<b; ++i){res*=a;}return res;}
ll logx(ll base, ll num){int cnt=0;while(num!=1){num/=base; ++cnt;}return cnt;}

vi vis(100001,0);
vi adj[100001];

int main()
{	
    std::ios::sync_with_stdio(false);
    //cin.tie(NULL);
    //cout.tie(NULL);
    int n,k,cnt=0;cin>>n>>k;
    string s;cin>>s;
    if(n==1)
    	cout<<0<<"\n";
    else
    {
    	for(int i=0; i<n; ++i)
    	{
    		if(s[i]=='R' && s[i+1]=='R' && (i+1<n))
    			++cnt;
    		else if(s[i]=='L'  && s[i-1]=='L' && (i-1>=0))
    			++cnt;
    	}
    	//cout<<cnt<<"\n";
    	cout<<min(n-1,cnt+2*k)<<"\n";
    }

}

Measured memory_bytes: 3280
// C++ program to find LCM of two numbers
#include <bits/stdc++.h>
using namespace std;
#define ll    long long
int main()
{
    ll n;
    cin>>n;

    vector <pair<ll,ll> >vec;

    for (int i=0;i<n;i++)
    {
        ll a,b;
        cin>>a>>b;

        vec.push_back(make_pair(b,a));
    }
    sort(vec.begin(),vec.end());

    bool test=true;

    ll sum=0;

    for (int i=0;i<vec.size();i++)
    {
        sum+=vec[i].second;
        if (sum>vec[i].first) {test=false;break;}
    }
    if (test) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;


    return 0;
}


Measured memory_bytes: 6512
#include <bits/stdc++.h>
using namespace std;
//#include "testlib.h"
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define int long long
#define ll long long
#define M 1000000007
#define MM 998244353
#define inputarr(a,n) for(int i=0;i<n;++i) cin>>a[i]
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) m*(n/GCD(m,n))
#define mii  map<ll ,ll >
#define sz(a) (int)a.size()
#define msi  map<string,ll >
#define rep(a,b)    for(ll i=a;i<b;i++)
#define rep0(n)    for(ll i=0;i<n;i++)
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#define vi vector<ll>
#define vs vector<string>
#define ppb pop_back
#define endl '\n'
#define asdf ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define r0 return 0;
#define FORD(i, a, b) for (int i = (int) (a); i >= (int) (b); --i)
#define inputoutput freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define Set(a, s) (a, s, sizeof (a))
#define FOR repi
#define pii pair<int,int>
#define REVERSE(v) reverse(all(v))
#define trav(a, x) for(auto& a : x)
#define display(x) trav(a,x) cout<<a<<" ";cout<<endl
#define debug cerr<<"bhau"<<endl
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
template<typename T, typename U> static inline void amin(T &x, U y) 
{ 
    if (y < x) 
        x = y; 
}
template<typename T, typename U> static inline void amax(T &x, U y) 
{ 
    if (x < y) 
        x = y; 
}
 
ll max(ll a, ll b) { return (a > b)? a : b;}
int min(int a, int b) { return (a < b)? a : b;} 


int solve(){
    int a,b;cin>>a>>b;
    // if(a*5!=b*4) return cout<<-1,0;

    for(int i=1;i<=100000;i++){
        int z=i*0.08;
        int l=i*0.1;
        if(z==a && l==b) return cout<<i,0;
    }
    cout<<-1;



    return 0;
}
signed main(){
    asdf
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#define DEBUG(x) std::cout << '>' << #x << ':' << x << '\n';
#define PRINTVEC(x) for (int i = 0; i < (int)x.size(); i++) std::cout << x[i] << ' '; std::cout << '\n';
#define PRINTP(x) for (int i = 0; i < (int)x.size(); i++) std::cout << x[i].first << ' ' << x[i].second << '\n'; std::cout << '\n';
#define io std::ios_base::sync_with_stdio(false);std::cin.tie(NULL);   
const int INF = 1<<29;
typedef long long ll;



int main()
{
	io;
    #ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin); 
    //freopen("output.txt", "w", stdout);  
    #endif

    int n;
    std::cin >> n;
    double th = (double)n / 3;
    double ans = th * th * th;
    std::cout << std::setprecision(12) << std::fixed << ans;
    

    #ifndef ONLINE_JUDGE   
    //std::cout << '\n' << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
    #endif
    return 0;
}


Measured memory_bytes: 256
#include<iostream>   
#include<cstdio>  
#include<algorithm>
#include<stack>
using namespace std;
const int maxx = 8;
// 行列、斜列
int row[maxx], col[maxx];
int dpos[maxx * 2 - 1], dneg[maxx * 2 - 1];

int x[maxx][maxx];

void init() {
	for (int i = 0; i < maxx; i++)
		row[i] = col[i] = 0;
	for (int i = 0; i < maxx * 2 - 1; i++)
		dpos[i] = dneg[i] = 0;
	for (int i = 0; i < maxx; i++)
		for (int j = 0; j < maxx; j++)
			x[i][j] = 0;
}
void print() {

	for (int i = 0; i < maxx; i++) {
		for (int j = 0; j < maxx; j++) {
			if (x[i][j] && row[i] != j)
				return;
		}
	}
	for (int i = 0; i < maxx; i++) {
		for (int j = 0; j < maxx; j++) {
			printf("%c", row[i] == j ? 'Q' : '.');
		}
		printf("\n");
	}
}
void recursive(int i) {
	if (i == maxx) {
		print();
		return;
	}

	for (int j = 0; j < maxx; j++) {
		// 不适合放在这里
		if (col[j] || dpos[i + j] || dneg[i - j + maxx - 1])
			continue;

		// 尝试放下这里
		row[i] = j; col[j] = dpos[i + j] = dneg[i - j + maxx - 1] = 1;
		recursive(i + 1);
		// 恢复刚才的操作继续其他的操作
		row[i] = col[j] = dpos[i + j] = dneg[i - j + maxx - 1] = 0;
	}
}
int main()
{
	int k;
	int r, c;
	scanf("%d", &k);
	for (int i = 0; i < k; i++){
		scanf("%d %d", &r, &c);
		x[r][c] = 1;
	}

	recursive(0);
	return 0;
}


Measured memory_bytes: 3144
import math
N, K = map(int, input().split())

B = [[] for _ in range(N)]
for i, a in enumerate(range(1, N+1)):
    B[i] = max(math.ceil(math.log2(K/a)), 0)
#print(B)

ans = 0
for b in B:
    ans += 1/2**b
print(ans/N)

Measured memory_bytes: 10264
import math


def solve():
    A, B, C, D = map(int, input().split())

    takagi = math.ceil(C / B)
    aoki = math.ceil(A / D)

    # print(takagi, ':', aoki)
    if takagi <= aoki:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    solve()


Measured memory_bytes: 9172
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

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

    int ans = 0;

    ans += min(a,k);
    k -= a + b;
    if(k > 0){
        ans -= k;
    }

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




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

int main(void){
	int sum = 0;
	int n;
	int a, b;
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> a >> b;
		sum += b - a + 1;
	}
	cout << sum << endl;
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  switch(n%10){
    case 0 : cout << "pon" << endl;break;
    case 1 : cout << "pon" << endl;break;
    case 2 : cout << "hon" << endl;break;
    case 3 : cout << "bon" << endl;break;
    case 4 : cout << "hon" << endl;break;
    case 5 : cout << "hon" << endl;break;
    case 6 : cout << "pon" << endl;break;
    case 7 : cout << "hon" << endl;break;
    case 8 : cout << "pon" << endl;break;
    case 9 : cout << "hon" << endl;break;
  }
}

Measured memory_bytes: 3600
a,b,m= map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
l=[]
for i in range(m):
        l.append(list(map(int, input().split())))
sa=sorted(a)
sb=sorted(b)
ans=sa[0]+sb[0]
for i in range(m):
        sm= a[l[i][0]-1] + b[l[i][1]-1] - l[i][2]
        if ans > sm:
                ans=sm
print(ans)

Measured memory_bytes: 40484
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            String[] d_str = Console.ReadLine().Split();

            List<int> d = new List<int>();
            for (int i = 0; i < n; i++) {
                d.Add(int.Parse(d_str[i]));
            }

            List<int> num = new List<int>();
            for (int i = 0; i < n; i++) {
                num.Add(0);
            }

            for (int i = 0; i < n ; i++) {
                num[d[i]]++;
            }

            double ans = 0;
            if (d[0] != 0) {
                ans = 0;
            } else if (num[0] != 1) {
                ans = 0;
            } else {
                ans = 1;
                for (int i = 0; i < n - 1; i++) {
                    for (int j = 0; j < num[i + 1]; j++) {
                        ans *= num[i] % 998244353;
                      ans %= 998244353;
                    }
                }
            }

            Console.WriteLine(ans % 998244353);

        }
    }

}


Measured memory_bytes: 20192
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <iomanip>
#include <stack>
#include <queue>
#include <deque>

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;

#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define pb push_back
#define ppb pop_back
#define mkp make_pair
#define F first
#define S second
#define show(a) cerr << #a <<" -> "<< a <<"\n"
#define fo(a, b, c, d) for(int (a) = (b); (a) <= (c); (a) += (d))
#define foo(a, b, c ,d) for(int (a) = (b); (a) >= (c); (a) -= (d))
#define int ll

const int N = 3e6;
const int MOD = 1e9 + 7;

int x, y, fact[N];

int binpow (int a, int n) {
	int res = 1;
	while (n) {
		if (n & 1) {
			res *= a;
			res %= MOD;
		}
		a *= a;
		a %= MOD;
		n >>= 1;
	}
	return res;
}

int c(int n, int m) {
	return (fact[n] * binpow((fact[m] * fact[n - m]) % MOD, MOD - 2) % MOD) % MOD;
}

main () {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> x >> y;
	fact[0] = 1;
	fo(i, 1, 1e6 + 1e5, 1) {
		fact[i] = fact[i - 1] * 1ll * i;
		fact[i] %= MOD;
	}
	int i = 0, j = 0, len = 1;
	bool ok = 0;
	for(; i <= 1e6 + 1e5; i++, j += 2, ++len) {
		if(i - x == y - j) {
			ok = 1;
			break;
		}
	}
	if(!ok || j - y + 1 > len || j - y < 0) {
		cout << 0;
		return 0;
	}
//	cout << i <<' '<< j - y <<'\n';
	cout << c(i, j - y);
	return 0;
}

Measured memory_bytes: 10496
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>

using namespace std;

char s[100];
int n,ans;

int main()
{
    for ( ; scanf("%s",s)!=EOF; )
    {
        n=strlen(s);
        if (n==1)
        {
            printf("%c\n",s[0]);
            continue;
        }
        bool flag=true;
        for (int i=1; i<n; i++) if (s[i]!='9') flag=false;
        if (flag)
        {
            ans=0;
            for (int i=0; i<n; i++) ans+=s[i]-'0';
        } else
        {
            ans=s[0]-'0'-1;
            for (int i=1; i<n; i++) ans+=9;
        }
        printf("%d\n",ans);
    }
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <cstdint>
#include <algorithm>
#include <utility>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
int N; cin >> N;
vector<string> S(N);
rep(i,N) cin >> S[i];
sort(S.begin(),S.end());
int count = 0;
for(int i = 1 ; i < N; i++){
  if(S[i-1] != S[i]){
    count++;
  }
}
cout << count + 1 << endl;
}

Measured memory_bytes: 9508
#include <cstdio>
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
#include <cmath>
#include <iomanip>
#include <regex>
#include <queue>
#include <set>
using namespace std;
using ll = long long;
using Lf = long double;
using plong = pair<ll,ll>;
const int mod = 1000000007;
 
vector<string>S;
vector<string> ss(vector<string>S,ll N){
    vector<string>res;
    for(ll j=0;j<S.size();j++){
        char _max='a';
        for(ll k=0;k<S[j].size();k++){
            _max = max(S[j][k],_max);
        }
        for(char c='a';c<=_max+1;c++){
            res.push_back(S[j]+c);
        }
    }
    return res;

}

int main(){
    ll N;
    cin>>N;
    S.push_back("a");
    for(ll i=2;i<=N;i++){
        S = ss(S,i);
    }

    sort(S.begin(),S.end());
    for(ll i=0;i<S.size();i++){
        cout<<S[i]<<"\n";
    }
 
}

Measured memory_bytes: 12108
#include <iostream>

using namespace std;

int main(void){
	int n;
	int min, max;
	int i;

	cin >> n;
	int *a = new int[n];

	for(i = 0; i < n; i++){
		cin >> a[i];
	}
	min = max = a[0] ;
	for(i = 1; i < n; i++){
		if(min > a[i]){
			min = a[i];
		}
		if(max < a[i]){
			max = a[i];
		}
	}

	cout << max - min;

	cout << '\n';
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
string a[10005];
int cnt;
int cnta,cntb;
int cntab;
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		for(int j=0;j<a[i].length()-1;j++){
			if(a[i][j]=='A'&&a[i][j+1]=='B'){
				cnt++;
			}
		}
		if(a[i][0]=='B'){
			cntb++;
//			cout<<"B"<<endl;
		}
		if(a[i][a[i].length()-1]=='A'){
			cnta++;
		}
		if(a[i][0]=='B'&&a[i][a[i].length()-1]=='A'){
			cntab++;
		}
	}
	cnt+=min(cnta,cntb);
	if(cntab==cnta&&cntab==cntb&&cntab!=0){
		cnt--;
	}
	cout<<cnt;
	return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define limit(x, l, r) max(l, min(x, r))
#define lims(x, l, r) (x = max(l, min(x, r)))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define show(x) cout << #x << " = " << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  string s, t;
  cin >> s >> t;
  int n = sz(s), m = sz(t);
  vector<vector<int>> is(26);
  rep(i,n) is[s[i]-'a'].push_back(i);
  rep(i,n) is[s[i]-'a'].push_back(i+n);
  ll ans = 0;
  int p = 0; // after p
  rep(i,m) {
    int c = t[i]-'a';
    if (sz(is[c]) == 0) {
      puts("-1");
      return 0;
    }
    p = *lower_bound(is[c].begin(), is[c].end(), p)+1;
    if (p >= n) {
      p -= n;
      ans += n;
    }
  }
  ans += p;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1724
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

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; }

using ll = long long;

const ll mod = 1000000007;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

std::map<int, int> prime_factor( int n )
{
  std::map<int, int> ret;

  for( int i = 2; i*i <= n; ++i )
  {
    while( n % i == 0 )
    {
      ++ret[i];
      n /= i;
    }
  }

  if( n != 1 )
    ++ret[n];

  return ret;
}

ll N, A[10010];
std::map<int, int> mp[10010], mamp, smp;

int main()
{
  scanf( "%lld", &N );
  rep( i, N )
  {
    scanf( "%lld", A+i );

    mp[i] = prime_factor( A[i] );

    for( auto it = mp[i].begin(); it != mp[i].end(); ++it )
      mamp[it->first] = std::max( mamp[it->first], it->second );
  }

  mint lcm = 1;
  for( auto it = mamp.begin(); it != mamp.end(); ++it )
    lcm *= mint(it->first).pow(it->second);

  mint ans = 0;

  rep( i, N )
    ans += lcm / mint(A[i]);

  printf( "%lld\n", ans.x );

  return 0;
}

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


ll mx = 0;
int N, M, Q;
vector<ll> a(52), b(52), c(52), d(52);

void dfs(vector<int> A){
    if (A.size() == N){
        ll d_sum = 0;
        rep(i, Q){
            if(A[b[i]] - A[a[i]] == c[i]) d_sum += d[i];
        }
        mx = max(mx, d_sum);
        return;
    }
    else{
        int A_max = A[A.size() - 1];
        for(int i = A_max; i <= M; i++){
            vector<int> tmp = A;
            tmp.push_back(i);
            dfs(tmp);
        }
    }
}


int main() {

  cin >> N >> M >> Q;
  rep(i, Q){
      cin >> a[i] >> b[i] >> c[i] >> d[i];
      a[i]--; b[i]--;
  }
rep(init, M){
    vector<int> init_vec = {init+1};
    dfs(init_vec);
}

cout << mx << endl;
}



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

int main(){
  vector<int> x(5);
  for(int i=0;i<5;i++){
    cin >> x.at(i);
  }
  for(int i=0;i<5;i++){
    if(x.at(i) == 0){
      cout << i+1 << endl;
      break;
    }
  }
  
  return 0;
}


Measured memory_bytes: 3548
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[9]={1,0,-1,0,1,1,-1,-1,0};
const ll dx[9]={0,-1,0,1,1,-1,1,-1,0};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    priority_queue<ll,vl,greater<ll>> r;
    priority_queue<ll,vl,less<ll>> l;
    ll lsum=0,rsum=0,con=0;
    ll n;cin >> n;
    while(n--){
        ll q;cin >> q;
        if(q==1){
            ll a,c;cin >>a >> c;con+=c;
            if(l.empty()||a<=l.top()) l.push(a),lsum+=a;
            else r.push(a),rsum+=a;
            if(l.size()<r.size()){
                ll x=r.top();r.pop();
                rsum-=x;
                l.push(x);lsum+=x;
            }
            if(l.size()==r.size()+2){
                ll x=l.top();l.pop();
                lsum-=x;
                r.push(x);rsum+=x;
            }
            //cout << lsum <<" " << rsum <<endl;
        }
        else{
            ll ans=(l.top()*l.size())-lsum;
            ans+=rsum-(l.top()*r.size());
            cout << l.top() <<" "<< ans+con <<endl;
        }
    }
}   

Measured memory_bytes: 5104
#include <iostream> 
using namespace std; 
int main()
{
 int a,b,c;
  cin>>a>>b>>c;
  if((a==b)&&(b==c)&&(a==c)){
   cout<<"No"; 
  }
  else if((a==b) || (b==c) || (c==a))
  {
   cout<<"Yes";
  }
  else
    cout<<"No";
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
  int n, k;
  cin >> n >> k;

  map<int, int> m;
  for (int i = 0; i < n; i++)
  {
    int a;
    cin >> a;
    if (m.find(a) == m.end())
    {
      m[a] = 1;
    }
    else
    {
      m[a]++;
    }
  }

  vector<int> v;
  for (auto iter = m.begin(); iter != m.end(); iter++)
  {
    v.push_back(iter->second);
  }
  sort(v.begin(), v.end());

  int res = 0;
  if (v.size() > k)
  {
    for (int i = 0; i < v.size() - k; i++)
    {
      res += v[i];
    }
  }

  cout << res << endl;
}

Measured memory_bytes: 10748
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <complex>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = int64_t;
using ull = uint64_t;
constexpr ll LL_MAX = numeric_limits<ll>::max();
constexpr ull ULL_MAX = numeric_limits<ull>::max();

template<typename T>
vector<T> make_vec_nd(T init, ll size) {
	return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, ll size, Args... rest) {
	auto inner = make_vec_nd(init, rest...);
	return vector<decltype(inner)>(size, inner);
}

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrep(i, a, b) for (ll i = (a)-1; i >= (b); i--)

ll count_zero_below(ll k, ll x) {
    ll ans = 0;
    ans += (x / ((ll)1 << (k+1))) * ((ll)1 << k);
    ans += min(x % ((ll)1 << (k+1)), ((ll)1 << k));
    return ans;
}

ll xor_below(ll x) {
    ll ans = 0;
    rep(k,0,63) {
        ll zero_cnt = count_zero_below(k, x);
        ll one_cnt = x - zero_cnt;
        if (one_cnt % 2 == 1) {
            ans += (ll)1 << k;
        }
    }
    return ans;
}

int main() {
    ll A, B;
    cin >> A >> B;
    cout << (xor_below(A) ^ xor_below(B+1)) << endl;
}


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

using namespace std;
int main()
{
    int N, W, H;
    cin >> N >> W >> H;
    vector<int> ximos(2 * W + 1, 0);
    vector<int> yimos(2 * H + 1, 0);

    for (int i = 0; i < N; i++) {
        int x, y, w;
        cin >> x >> y >> w;
        const int lx = max(0, x - w);
        const int rx = min(W, x + w);
        const int ly = max(0, y - w);
        const int ry = min(H, y + w);
        ximos[2 * lx]++;
        if (rx < W) {
            ximos[2 * rx + 1]--;
        }
        yimos[2 * ly]++;
        if (ry < H) {
            yimos[2 * ry + 1]--;
        }
    }
    for (int i = 1; i <= 2 * W; i++) {
        ximos[i] += ximos[i - 1];
    }
    for (int i = 1; i <= 2 * H; i++) {
        yimos[i] += yimos[i - 1];
    }

    bool ok = true;
    for (int i = 0; i <= 2 * W; i++) {
        if (ximos[i] <= 0) {
            ok = false;
            break;
        }
    }
    if (ok) {
        cout << "Yes" << endl;
        return 0;
    }
    for (int i = 0; i <= 2 * H; i++) {
        if (yimos[i] <= 0) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 4416
#!/usr/bin python3
# -*- coding: utf-8 -*-


def main():
    N, Y = map(int, input().split())
    ret = [-1] * 3
    for x in range(N+1):
        tY = Y - 10000 * x
        tN = N - x
        for y in range(tN+1):
            z = tN - y
            if tY == y * 5000 + z * 1000:
                ret = [x, y, z]
    print(*ret)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 1010

vector<int> G[SIZE];

bool connect[SIZE][SIZE];
bool dp[SIZE][SIZE];

int color[SIZE];
pair<int,int> dfs(int now, int back = -1, int c = 0) {
  pair<int,int> res = {0, 0};

  color[now] = c;

  if (c == 0)
    res.first += 1;
  else
    res.second += 1;

  for (int to : G[now]) {
    if (color[to] == -1) {
      auto p = dfs(to, now, !c);
      if (p.first == -1) return {-1, -1};
      res.first += p.first;
      res.second += p.second;
    }
    if (color[to] == c) {
      return {-1, -1};
    }
  }

  return res;
}

int main(){
  int N, M;

  scanf("%d%d", &N, &M);

  for (int i=0; i<M; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--; b--;
    connect[a][b] = connect[b][a] = true;
  }

  int c = 0;

  for (int i=0; i<N; i++) {
    for (int j=i+1; j<N; j++) {
      if (!connect[i][j]) {
        G[i].push_back(j);
        G[j].push_back(i);
        c++;
      }
    }
  }


  for (int i=0; i<N; i++)
    color[i] = -1;

  vector<pair<int,int>> vec;

  for (int i=0; i<N; i++) {
    if (color[i] == -1) {
      auto p = dfs(i);
      vec.push_back(p);

      debug(p);

      if (p.first == -1) {
        puts("-1");
        return 0;
      }
    }
  }

  dp[0][0] = true;

  for (int i=0; i<vec.size(); i++) {
    auto p = vec[i];
    for (int j=0; j<=N; j++) {
      if (p.first + j <= N)
        dp[i+1][p.first+j] |= dp[i][j];
      if (p.second + j <= N)
        dp[i+1][p.second+j] |= dp[i][j];
    }
  }

  int ans = INF;

  for (int i=0; i<=N; i++) {
    if (dp[vec.size()][i]) {
      ans = min(ans, i * (i-1) / 2 + (N-i) * (N-i-1) / 2);
    }
  }

  assert(ans != INF);

  cout << ans << endl;

  return 0;
}


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

using Int = long long;
using ll = long long;

template<class T1, class T2> inline void chmin(T1 &a, T2 b){if(a > b) a = b;}
template<class T1, class T2> inline void chmax(T1 &a, T2 b){if(a < b) a = b;}

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

  Int n,m;
  while(cin>>n>>m,n||m){
    vector<Int> bs(n,0);
    for(Int i=0;i<m;i++){
      for(Int j=0;j<n;j++){
        Int x;
        cin>>x;
        bs[j]+=x;
      }
    }
    cout<<*max_element(bs.begin(),bs.end())<<endl;
  }

  return 0;
}



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

typedef long long ll;

int const N = 305 * 2;
int const MOD = 1e9 + 7;

int pa[N];
ll f[N][N];
ll fac[N];
int sum[N];
int n, m;

int main() {
	std::ios::sync_with_stdio(0);
	std::cin >> n >> m;
	fac[0] = 1;
	for(int i = 1; i < N; ++i) if((i & 1) == 0) {
		fac[i] = fac[i - 2] * (i - 1) % MOD;
	}
	for(int i = 1; i <= m; ++i) {
		int x, y;
		std::cin >> x >> y;
		pa[x] = y;
		pa[y] = x;
	}

	n <<= 1;
	for(int i = 1; i <= n; ++i) {
		sum[i] = sum[i - 1];
		if(pa[i] == 0) 
			++sum[i];
	}

	ll ans = 0;
	for(int i = 1; i <= n; ++i) {
		for(int j = 1; j + i - 1 <= n; ++j) {
			int l = j, r = j + i - 1;
			bool flag = (sum[r] - sum[l - 1]) % 2;
			for(int k = l; k <= r; ++k) if(pa[k]) {
				if(pa[k] < l || pa[k] > r) {
					flag = 1;
					break;
				}
			}
			if(flag) continue;
			f[l][r] = fac[sum[r] - sum[l - 1]];
			for(int k = l; k < r; ++k) {
				int tmp = f[l][k] * fac[sum[r] - sum[k]] % MOD;
				tmp = (MOD - tmp) % MOD;
				f[l][r] = (f[l][r] + tmp) % MOD;
			}
			ans += f[l][r] * fac[n - m - m - (sum[r] - sum[l - 1])] % MOD;
			ans %= MOD;
		}
	}
	std::cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define lli long long int
#define pb push_back
#define mod 1000000007
#pragma GCC optimize ("-O2")
#define mod2 998244353
#define MAXN 1000000000
#define v32 vector<int>
#define v64 vector<lli>
#define v1024 vector <vector <int>>
#define v4096 vector <vector <lli>>
#define vt vector
#define f(x, y, z) for (lli x = y; x < z; x++)
#define fd(x, y, z) for (lli x = y; x > z; x--)
#define lb lower_bound
#define ld long double
#define m64 map<lli,lli>
#define m32 map<int,int>
#define m64it map<lli,lli>::iterator
#define m32it map<int,int>::iterator
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ist insert
#define endl "\n"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define p_q priority_queue 
#define min_p_q priority_queue <int,vt <int>,greater <int>>
using namespace std;
using namespace __gnu_pbds; 
template <typename T> 

void DEBUG_ARR(vt<T> a)
{
	f(i,0,a.size())cout<<a[i]<<" ";
	cout<<"\n";
}
lli power(lli x, lli y) 
{
    lli res = 1;  
   
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x)%mod; 
        y = y>>1; 
        x = (x*x)%mod;  
    }
    if(res<0)
       res+=mod; 
    return res; 
}
lli tmod(lli x,lli m){return (x%m+m)%m;}//USE AT YOUR OWN RISK
bool ok(lli val,vt <pair<lli,lli>> &A,lli n,lli k){
    lli cnt=0;
    f(i,0,n){
        if(A[i].first>val){
            lli temp=A[i].first/A[i].second;
            lli temp2=val/A[i].second;
            cnt+=temp-temp2;
        }
    }
    if(cnt>k)return 0;
    return 1;
}
int main() 
{ 
  fastio;
  lli n,k;
  cin>>n>>k;
  lli a[n];f(i,0,n)cin>>a[i];
  lli f[n];f(i,0,n)cin>>f[i];
  vt <pair<lli,lli>> A(n);
  sort(a,a+n);
  sort(f,f+n);
  reverse(f,f+n);
  f(i,0,n){
      A[i].first=a[i]*f[i];
      A[i].second=f[i];
  }
  lli l=0,r=1000ll*MAXN;
  while(l<r){
      lli mid=((l+r)>>1);
      if(ok(mid,A,n,k)) r=mid;
      else l=mid+1; 
  }  
//   f(i,0,12)
//   cout<<ok(i,A,n,k)<<"\n";
  cout<<l<<"\n";
  return 0; 	
}


Measured memory_bytes: 6528
#include <bits/stdc++.h> 
using namespace std; 
int main(){
    int N, K;
    cin >> N >> K;
    K--;
    int arr[N];
    int arr2[N-K];
    for (int i = 0; i < N; i++) {
        cin >> arr[i];
    }
    sort(arr, arr+N);
    for (int i = 0; i < N-K; i++) {
        arr2[i] = arr[i+K]-arr[i];
    }
    sort(arr2, arr2+(N-K));
    cout << arr2[0];


} 

Measured memory_bytes: 1024
// 16:46

#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
#define int long long
#define MOD 1000000007
typedef vector<int> vi;
typedef pair<int,int> pi;
#define inf 1e18
#define For(i,a,b) for (int i = a; i < b; i++)
#define Rep(i,a,b) for (int i = a; i <= b; i++)
#define ps(x,y) fixed << setprecision(y) << x 
#define pb push_back 
#define mp make_pair 
 
int32_t main()
{
    fast;
    double n, ans = -1; cin >> n;
    Rep(i, 1, n) {
        if((int) (i * 1.08) == n) ans = i;
    }

    if(ans != -1) cout << ans;
    else cout << ":(";
    
    
    
    return 0;
}

Measured memory_bytes: 3696
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <stdio.h>
using namespace std;

//typedefリスト
typedef vector<int> vint;
typedef vector<string> vstr;

int main(void) {
	int N, M, C,sum,ans;
	ans = 0;
	sum = 0;
	cin >> N >> M >> C;
	vint B(M);
	vint A(M*N);

	for (int i = 0; i < M; i++)cin >> B[i];
	for (int i = 0; i < M*N; i++)cin >> A[i];

	for (int i = 0; i < N; i++) {
		sum = 0;
		for (int j = 0; j < M; j++) {
			sum += A[i*M + j] * B[j];
		}
		if (sum + C > 0)ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
n,m = map(int, input().split())
h = list(map(int, input().split()))

ans = [1] * n

for i in range(m):
    a,b = map(int, input().split())
    if h[a-1] <= h[b-1]:
        ans[a-1] = 0
    if h[b-1] <= h[a-1]:
        ans[b-1] = 0

print(sum(ans))

Measured memory_bytes: 84896
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
/////////

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
//////////////

void solve() {
	vector<int> A(3);
	for (int i = 0; i < 3; ++i) {
		cin >> A[i];
	}
	sort(A.begin(), A.end());
	for (int i = 1; i < 3; ++i) {
		A[i] -= A[0];
	}
	int sum = 2*A[2]-0-A[1];
	if (sum % 2 == 0) {
		cout << sum / 2 << endl;
		return;
	}
	//奇数
	/*
	maxに1足して、他に１taus
	*/
	int ans = (sum + 1) / 2 + 1;
	cout << ans << endl;
	
}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
 using namespace std;
 using Graph = vector<vector<int>>;
 #define rep(i,n) for(int i=0;i<n;++i)
 #define all(v) v.begin(), v.end()
 typedef long long int ll;
 typedef unsigned long long ull;
 template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
 template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
 typedef pair<ll,ll> P;
 const long long MOD = 1e9+7;
 const ll INF = 1LL << 60;
 bool G[10][10];

 int main(){

    int n,m;
    cin >> n >> m;
    rep(i, m){
        int a,b;
        cin >> a >> b; --a, --b;
        G[a][b] = G[b][a] = true;
    }

    //順列
    vector<int> ord(n);
    for(int i = 0; i < n; i++){
        ord[i] = i;
    }

    //順列を全部試す
    int res = 0;

    do{
        if(ord[0] != 0)break;

        bool ok = true;

        for(int i = 0; i < n - 1; i++){
            int from = ord[i];
            int to = ord[i+1];

            if(!G[from][to]){//パスがないとき
                ok = false;
            }
        }
        if(ok)res++;
    }while(next_permutation(all(ord)));

    cout << res << endl;


 }


Measured memory_bytes: 3528
#[allow(unused_macros)]
macro_rules! p {
    ($x:expr $(, $tail:expr)*) => {
        let mut s = String::new();
        s.push_str(format!("{:?}", $x).as_str());
        $(
            s.push_str(format!(", {:?}", $tail).as_str());
        )*
        println!("{}", s);
    };
}

#[allow(unused_macros)]
macro_rules! pl {
    ($($x:expr), *) => {
        $(println!("{:?}", $x);)*
    };
}

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

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

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

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

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

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

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

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    println!("{}", solve(stdin!()));
}

fn solve(src: String) -> String {
    input! {
        source = src,
        a: usize, b: usize, c: usize
    }
    if a == b && b == c {
        "Yes"
    } else {
        "No"
    }.to_string()
}

// Test Code

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input.to_string()), $output);
            )*
        }
    };
}

test! {
    "2 2 2" => "Yes",
    "3 4 5" => "No",
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int n;
  cin >> n;
  VEC<LL> h(n+1,0);
  REP(i,1,n+1)cin>>h[i];
  LL inf = 1e9;
  VEC<LL> dp(n + 3, inf);
  dp[1]=0;
  REP(i, 1, n) {
    dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));
    dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));
  }
  // DUMP(dp);
  cout<<dp[n]<<endl;

  return 0;
}


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

string dog(ll n) {
  if(n == 0) return "";
  n--;
  return dog(n / 26) + string(1, 'a' + n % 26);
}

int main() {
  ll n;
  cin >> n;
  cout << dog(n) << endl;
}


Measured memory_bytes: 3580
N = int(input())
A, B = map(int,input().split())
P = list(map(int,input().split()))
a, b, c = 0, 0, 0
for p in P:
  if p <= A:
    a += 1
  elif A+1 <= p <= B:
    b += 1
  elif p >= B+1:
    c += 1
print(min(a, b, c))

Measured memory_bytes: 3064
## coding: UTF-8
import statistics
#import math

N = int(input())
#lq = [list(map(int, input().split())) for _ in range(N)]
#print(lq)

A = []
B = []
for i in range(N):
    a, b = map(int,input().split())
    A.append(a)
    B.append(b)
#print(A)
#print(B)

#l = [10, 1, 3, 7, 1]

#median = statistics.median(l)
#print(median)

if(N%2 == 1):
    lowest = statistics.median(A)
    highest = statistics.median(B)
    ans = highest - lowest + 1
else:
    lowest = statistics.median(A)
    highest = statistics.median(B)
    ans = (2 * highest) - (2 * lowest) + 1

print(int(ans))


Measured memory_bytes: 28944
import sys
read=sys.stdin.readline

A,B=map(int,read().split())

def factorization(n):
    arr=set([1])
    temp=n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.add(i)
    if temp!=1:
        arr.add(temp)
    if arr==[]:
        arr.add(n)
    return arr


print(len(factorization(A)&factorization(B)))

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

using lint = long long;
#define bit(n) ((lint)1 << n);
const int INF = 1e9;
const lint LINF = 1e18;

const lint MOD = 1e9 + 7;
// const lint MOD = 998244353;

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

    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }

    int ans = 0;
    for (int l = 0; l <= min(n, k); l++) {
        for (int r = 0; r <= min(n, k) - l; r++) {
            vector<int> take;
            for (int i = 0; i < l; i++) {
                take.push_back(v[i]);
            }
            for (int i = 0; i < r; i++) {
                take.push_back(v[n - 1 - i]);
            }
            sort(take.begin(), take.end());

            for (int i = 0; i < min((int)take.size(), k - l - r); i++) {
                take[i] = max(0, take[i]);
            }
            int cand = 0;
            for (int i = 0; i < l + r; i++) {
                cand += take[i];
            }
            ans = max(ans, cand);
        }
    }

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

Measured memory_bytes: 256