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

int mygcd(int a,int b){
    if(b==0)return a;
    return mygcd(b,a%b);
}

int main(){
    int n,x;
    cin>>n>>x;
    vector<int> c(n);
    for (int i = 0; i < n; ++i) {
        cin>>c[i];
        c[i]=abs(c[i]-x);
    }
    sort(c.begin(),c.end(),greater<int>());
    vector<int> ans;
    ans.push_back(mygcd(c[0],c[1]));
    for (int i = 0; i < n-2; ++i) {
        ans.push_back(mygcd(ans[i],c[i+2]));
    }
    cout<<ans[ans.size()-1]<<endl;
    return 0;
}

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

using namespace std;

 int main(int argc, char const *argv[])
{
	string s1, s2,s3;

	cin>>s1>>s2;

	bool f = false;

	if(s1 == s2) {
		cout<<"EQUAL"<<endl;

		return 0;
	}

	if(s1.size()>s2.size()) f = true;
	else if(s1.size() == s2.size() && (s1>s2)) f = true;

	if(f)
	{
		cout<<"GREATER";
		return 0;
	}
	else
	{
		cout<<"LESS";
		return 0;
	}



}


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

using namespace std;

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

    float num, sum;
    sum = 0;
    string S;
    for(int i=0; i<N; i++){
        cin >> num >> S;
        if(S == "JPY") sum += num;
        else sum += num * 380000;
    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;

vector<long long> fact_inv, inv, Com;

void init_nCk(int n, int SIZE) {
    fact_inv.resize(SIZE + 5);
    inv.resize(SIZE + 5);
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < SIZE + 5; i++) {
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % MOD;
    }
    Com.resize(SIZE + 5);
    Com[0] = 1;
    for (int i = 1; i < SIZE + 5; i++) {
        Com[i] = Com[i - 1] * ((n - i + 1) * inv[i] % MOD) % MOD;
    }
}
 
long long nCk(int k) {
    assert(!(k < 0));
    return Com[k];
}

int main()
{
  int X,Y;
  cin >> X >> Y;

  if((X+Y)%3!=0){
    cout << 0 << endl;
  }else{
    int n = (X+Y)/3;
    if(2*n-X<0||2*n-X>n){
      cout << 0 << endl;
    }else{
      int k = 2*n-X;
      init_nCk(n,k);
      cout << nCk(k) << endl;
    }
  }
}

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

int main() {
  int N,K,Z=0;
  cin>>N>>K;
  vector<int> p(N);
  for(int i=0;i<N;i++){
    cin>>p.at(i);
  }
  vector<int> r=p;
  for(int i=0;i<K;i++){
    vector<int> q(N+1,0);
    for(int j=0;j<N;j++){
      q.at(max(0,j-r.at(j)))++;
      q.at(min(N,j+r.at(j)+1))--;
    }
    if(q.at(0)==N&&q.at(N)==N*-1){
      Z++;
    }
    for(int j=0;j<N;j++){
      r.at(j)=q.at(j);
      q.at(j+1)+=q.at(j);
    }
    if(Z==1){
      break;
    }
  }
  for(int i=0;i<N;i++){
    cout<<r.at(i);
    if(i!=N-1){
      cout<<" ";
    }
    else{
      cout<<endl;
    }
  }
}

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

typedef long long ll;
const int N = 2e5;

int n;
ll k;
ll a[N+5],f[N+5];

ll cek(ll x){
	ll ret = 0;
	for(int i=1;i<=n;i++){
		if(x == 0){
			ret+=a[i];
			continue;
		}
		ll tmp = x/f[i];
//		cout << f[i] << " WITH " << x << " equal to " << tmp << endl;
//		cout << tmp << "  -  " << a[i] << endl;
		ret += max(0ll,a[i]-tmp);
	}
	return ret;
}

int main(){
	scanf("%d%lld",&n,&k);
	for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
	for(int i=1;i<=n;i++) scanf("%lld",&f[i]);
	sort(a+1,a+n+1);
	sort(f+1,f+n+1);
	reverse(a+1,a+n+1);
	ll l = 0;
	ll r = 1e12;
	ll ret = r;
	while(l<=r){
		ll mid = (l+r)/2;
//		cout << mid << " >> " << cek(mid) << endl;
		if(cek(mid) <= k){
			ret = mid;
			r = mid-1;
		} else {
			l = mid+1;
		}
	}
	printf("%lld\n",ret);
	return 0;
}

Measured memory_bytes: 3328
N = int(input())
S = input()

# 平文
PLAIN = S

# 秘密鍵
KEY = N

# 以下に、記述してください。
enc = ""

for c in list(PLAIN):
    ASCII = ord(c)
    # print(ASCII)
    num = ASCII - 65
    num = (num + KEY) % 26
    ASCII = num + 65
    enc += chr(ASCII)

print(enc)

Measured memory_bytes: 3060
P=[1 for i in range(55556)]
P[0]=0
P[1]=0
for i in range(2,55556):
    if P[i]==1:
        for j in range(2,55556):
            if i*j<=55555:
                P[i*j]=0
            else:
                break

ans=[]
for i in range(55556):
    if P[i]==1 and i%10==1:
        ans.append(i)
N=int(input())
print(*ans[:N])

Measured memory_bytes: 3608
#include <iostream>
#include <sstream>
#include <cstdio>
#include <stdlib.h>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
#define MAX 100002

int p[MAX];
int diff_w[MAX];
int r[MAX];

int root(int x){
    if(p[x]==x)return x;
    int r = root(p[x]);
    diff_w[x] += diff_w[p[x]];
    return p[x] = r;
}

void diff(int x,int y){
  if(root(x)==root(y))cout<<diff_w[y] - diff_w[x]<<endl;
  else cout<<"?"<<endl;
}
bool same(int x,int y){
  return root(x)==root(y);
}
void Union(int x,int y){
  p[x]=y;
}

void merge(int x,int y,int w){
  int rx = root(x);
  int ry = root(y);
  w = w + diff_w[x] - diff_w[y];
  if(r[rx]<r[ry]) {
    swap(rx,ry);
    w = -w;
  }
  r[rx]+=r[ry];
  p[ry] = rx;
  diff_w[ry] = w;
  //cout<<"w:"<<w<<endl;
}

int main(){
  int n,q,x,y,z,rx,ry,flag;
  cin>>n>>q;
  for(int i=0;i<n+1;i++){
    p[i] = i;
    r[i] = 1;
  }
  for(int i=0;i<q;i++){
    cin>>flag>>x>>y;
    if(flag==1){
      diff(x,y);
    }
    else{
      cin>>z;
      merge(x,y,z);
    }
  }
  //for(int i=0;i<n+1;i++)cout<<i<<" root:"<<p[i]<<" diff_w:"<<diff_w[i]<<" rank:"<<r[i]<<endl;
  return 0;
}



Measured memory_bytes: 4272
#include <iostream>
#include <algorithm>
using namespace  std;
int rg[200005] = { 0 };
int main() {
	int n, h;	long sum = 0;
	cin >> h >> n;
	for (int i = 1; i <= n; i++) {
		int k;
		cin >> k;
		sum += k;
	}	
	if (sum >= h)cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 10;
int n, m, q, cnt[N][N], dg[N][N], dx[] = {-1, 0}, dy[] = {0, -1}, r[N][N], c[N][N];
string s[N];
bool isval(int x, int y) {
	if (x >= 0 && y >= 0 && x < n && y < m)
		return true;
	return false;
}
int main() {
	cin >> n >> m >> q;
	for (int i = 0; i < n; i++)
		cin >> s[i];
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			r[i][j + 1] = r[i][j];
			c[j][i + 1] = c[j][i];
			if (s[i][j] == '1') {
				if (isval(i - 1, j) && s[i - 1][j] == '1')
					r[i][j + 1] += 1;
				if (isval(i, j - 1) && s[i][j - 1] == '1')
					c[j][i + 1] += 1;
			}
			cnt[i + 1][j + 1] = cnt[i][j + 1] + cnt[i + 1][j] - cnt[i][j] + (int) (s[i][j] == '1');
			int tmp = 0;
			if (s[i][j] == '1') {
				for (int k = 0; k < 2; k++) {
					int x = i + dx[k], y = j + dy[k];
					if (isval(x, y))
						tmp += (int) (s[x][y] == '1');
				}
			}
			dg[i + 1][j + 1] = dg[i][j + 1] + dg[i + 1][j] - dg[i][j] + tmp * 2;
		}
	}
	while (q--) {
		int x, y, xx, yy;
		cin >> x >> y >> xx >> yy;
		if (x >= xx && y >= yy)
			swap(x, xx), swap(y, yy);
		if (x > xx)
			swap(x, xx);
		if (y > yy)
			swap(y, yy);
		x--, y--;
		int b = cnt[xx][yy] - cnt[xx][y] - cnt[x][yy] + cnt[x][y], d = dg[xx][yy] - dg[xx][y] - dg[x][yy] + dg[x][y];
		d -= (2 * (r[x][yy] - r[x][y]) + 2 * (c[y][xx] - c[y][x]));
		int dif = (2 * b - 2 - d) / 2;
		cout << dif + 1 << endl;
	}	
	return 0;
}


Measured memory_bytes: 68992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
const ll INF=1e9+7;
const ll N = 1002;
ll n,ans=1,x=0,y=0,t[60];
string s1,s2;


int main(){
	cin>>n>>s1>>s2;
	FOR(i,0,n){
		if(s1[i]==s2[i]){
			t[i]=1;
		}else{
			t[i]=2;
		}
	}
	ll b=1;
	if(t[0]==1){
		ans*=3;
	}else{
		ans*=6;
		b=2;
	}
	FOR(i,b,n){
		if(b==1&&t[i]==2){
			ans*=2;
			b=2;
			i++;
		}else if(b==1&&t[i]==1){
			ans*=2;
			b=1;
		}else if(t[i]==2){
			ans*=3;
			b=2;
			i++;
		}else{
			b=1;
		}
		ans%=INF;
	}
	cout<<ans<<endl;
	return 0;
}

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

int main(){
  int i,j,n,m,k[30],cou[31]={0},ans=0,tmp;
  scanf("%d%d",&n,&m );
  for(i=0;i<n;i++){
    scanf("%d",&k[i]);
    for(j=0;j<k[i];j++){
      scanf("%d",&tmp);
      cou[tmp]++;
    }
  }
  for(i=0;i<m+1;i++)
  if(cou[i]==n)
    ans++;

  printf("%d",ans);

}


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

int main() {
	int D, N;
	cin >> D >> N;
	if (N == 100) N++;
	int ans;
	if (D == 0)ans = N;
	if (D == 1)ans = N * 100;
	if (D == 2) ans = N * 10000;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <deque>
#include <climits> 


int main()
{
    long N;
    std::cin >> N;
    std::vector<long> A;
    long minuscount=0;
    for(long i=0; i<N; i++){
        long temp;
        std::cin >> temp;
        if(temp<0){
            minuscount++;
            temp=(-1)*temp;
        }
        A.push_back(temp);
    }
    std::sort(A.begin(),A.end());
    if(minuscount%2==1){
        A[0]=A[0]*(-1);
    }

    long result=0;
    for(long i=0; i<N; i++){
        result+=A[i];
    }
    std::cout << result << std::endl;
    return 0;
}

Measured memory_bytes: 1400
n = int(input())
#a, b = map(int,input().split())
al = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
dic = {}
for ai in al:
    dic[ai] = dic.get(ai, 0)+1

edges = sorted(dic.items(), reverse=True)
ans = 0
partial = False
temp = 0
for tup in edges:
    e, num = tup
    if num == 1:
        continue
    elif num == 2 or num == 3:
        if partial:
            ans = temp*e
            break
        else:
            partial = True
            temp = e
    else:
        if partial:
            ans = temp*e
            break
        else:
            ans = e**2
            break
print(ans)


Measured memory_bytes: 25812
using System;
using System.Collections.Generic;
using System.Linq;

public class Solution
{
    public static void Main()
    {
        var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var n = vals[0];
        var r = vals[1];
        var rate = 0;
        if (n >= 10)
        {
            rate = r;
        }
        else
        {
            rate = r + 100 * (10 - n);
        }

        Console.WriteLine(rate);
    }
}

Measured memory_bytes: 11348
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
const int INF=1e9+7;
void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}
#define trace1(x)                    cerr<<#x<<": "<<x<<endl
#define trace2(x, y)                 cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)                 cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)             cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)         cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f)     cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}



int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin >> n;
    for(ll i=9; i>=1; i--){
        if(n%i==0){
            if(i<=9 && n/i<=9 && n/i>=1){
                cout << "Yes";
                return 0;
            }
        }
    }
    cout << "No";
    return 0;
}
/* The judge is never wrong! Your code is buggy
   Look for:
 * * Read the problem carefully.
 * * Don't forget to sort(), mod, ll!!!!
 * * Initial value = +/- infinity instead of zero!!!
 * * an easier and alternate approach
 * * read the problem statement carefully
 * * if concept is correct and still WA, try with a different implementation
 * * special cases (n=1?)
 * * if you have no idea just guess the appropriate well-known algorithm instead of doing nothing :/
 */


Measured memory_bytes: 256
from sys import stdin
S = (stdin.readline().rstrip())
ans = [0] * len(S)
R = [i for i in S.split("L") if i != ""]
L = [i for i in S.split("R") if i != ""]
ind = 0
for i,j in zip(R,L):
    r = 0
    l = 0
    r_len = len(i)
    l_len = len(j)
    ind = ind + r_len
    # 連続したRの要素のうち奇数番目のものがR,偶数番目のものがLに足される
    r += ((r_len+1)//2)
    l += (r_len//2)
    # 連続したLの要素のうち奇数番目のものがL,偶数番目のものがRに足される
    r += (l_len//2)
    l +=( (l_len+1)//2)
    
    ans[ind] = l
    ans[ind-1] = r
    
    ind = ind + l_len
for k in ans:
    print(k,end=" ")

"""
R R R L L
★☆★〇●

　★☆★
 　 〇●

　　★☆
  　★〇
    ●

"""

Measured memory_bytes: 6888
def sum(i):
    return (i * (i + 1)) // 2

n = int(input())
fizz_num = n // 3
buzz_num = n // 5
fizzbuzz_num = n // 15
ans = sum(n) - 3 * sum(fizz_num) - 5 * sum(buzz_num) + 15 * sum(fizzbuzz_num)
print(ans)  

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

int main(){
  int n;
  cin >> n;
  vi a(n);
  rep(i,n) cin >> a[i];
  sort(a.rbegin(),a.rend());
  int len = a[0];
  vi cnt(len+1);
  for(auto x : a){
    for(int i=x; i<=len; i+=x){
      cnt[i]++;
    }
  }
  int ans=0;
  for(auto x : a){
    if(cnt[x] == 1) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 7980
line = list(map(int, input().split(" ")))
N = line[0]
L = line[1]
sum = 0
for i in range(N):
	sum = sum + L+i

if L>=0:
	print(sum-L)
elif L+N-1<=0:
	print(sum-(L+N-1))
else:
	print(sum)


Measured memory_bytes: 2940
from collections import defaultdict
from bisect import bisect

s = input()
S = len(s)
t = input()
T = len(t)
D = defaultdict(list)
Dc = defaultdict(int)
Exists = True

for i in range(S):
  D[s[i]].append(i+1)
  Dc[s[i]] += 1

ans = 0
temp = 0
for i in range(T):
  if D[t[i]] == []:
    Exists = False
    break
  j = bisect(D[t[i]], temp)
  if j == Dc[t[i]]:
    ans += S - temp + D[t[i]][0]
    temp = D[t[i]][0]
  else:
    ans += D[t[i]][j] - temp
    temp = D[t[i]][j]

if Exists:
  print(ans)
else:
  print(-1)

Measured memory_bytes: 13848
#include <iostream>
#include <vector>
#include <bitset>
#include <map>
#include <algorithm>

using namespace std;

#define all(v) v.begin(), v.end()
#define F first
#define S second
#define FOR(i, n) for(int i = 0; i < (int) n; i++)

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

const ll MOD = 1000000000+7;

ll binPow(ll x, ll p){
	ll ans = 1;
	while(p){
		if(p&1)
			ans = (ans*x)%MOD;
		x = (x*x)%MOD;
		p>>=1;
	}
	return ans;
}

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

	vi primes;
	bitset<1000000> b;
	b.set();
	for(int i = 2; i*i <= 1000000; i++){
		if(b[i]){
			for(int j = i*i; j <= 1000000; j+=i)
				b[j] = 0;
		}
	}

	for(int i = 2; i <= 1000000; i++)
		if(b[i]) primes.push_back(i);

	int n; cin >> n;
	vector<ll> v(n);
	map<int,int> pow;
	for(auto& p: v){
		cin >> p;
		int aux = p;
		for(int j = 0; j < (int) primes.size() && aux; j++){
			if(b[aux] == 1){
				pow[aux] = max(pow[aux], 1);
				break;
			}
			int primo = primes[j];
			if(aux%primo == 0){
				int cnt = 0;
				while(aux%primo == 0){
					cnt++;
					aux/=primo;
				}
				pow[primo] = max(pow[primo], cnt);
			}
		}		
	}

	ll multi = 1;
	for(auto& p: pow){
		ll add = binPow(p.F, p.S);
		multi = multi * add % MOD;
	}

	ll ans = 0;
	FOR(i, n){
		ll add = multi * binPow(v[i], MOD-2) % MOD;
		ans = (ans + add) % MOD;
	}

	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 1272
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a,b,x;
  cin >> a >> b >> x;
  long long A;
  if (a > 0){
    A = b/x - (a-1)/x;
  }
  else {
    A = b/x + 1;
  }
  cout << A << endl;
}

Measured memory_bytes: 3588
import sys
from bisect import *
from heapq import *
from collections import *
from itertools import *
from functools import *
from math import *
from fractions import *

sys.setrecursionlimit(100000000)
input = lambda: sys.stdin.readline().rstrip()

A, B, K = map(int, input().split())
X = [i for i in range(100, 0, -1) if A % i == 0 and B % i == 0]
print(X[K - 1])


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

int main(){
    int n,d,x;
    cin >>n>>d>>x;
    int a[n];
    rep(i,n) cin >> a[i];
    int ans = n;
    for(int i = 0;i <n;i++){
        int cnt = 1;
        int j = 1;
        while(j*a[i]+1 <= d){
            cnt = j*a[i]+1;
            ans++;
            j++;
        }
    }
    cout << ans + x << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define EB emplace_back
#define MP make_pair
#define all(o) (o).begin(), (o).end()
#define mset(m,v) memset(m,v,sizeof(m))
#define fr(i,n) for(lli i=0;i<n;++i)
#define rep(i,a,b) for(lli i=a;i<=b;++i)
#define remin(a,b) (a=min((a),(b)))
#define remax(a,b) (a=max((a),(b)))
#define endl '\n'
typedef long long int lli;
typedef long double ld;
typedef pair< lli,lli > ii;
typedef vector<lli> vi;
typedef vector<ii> vii;
typedef vector<vi> graph;
lli MOD=1000000007;long double EPS=1e-9;


void pre(){

}

void solve(){
	lli arr[3];
	fr(i,3)cin>>arr[i];
	sort(arr,arr+3);
	lli mincost=MOD*MOD;
	do{
		lli temp=abs(arr[1]-arr[2])+abs(arr[1]-arr[0]);
		remin(mincost,temp);
	}while(next_permutation(arr,arr+3));
	cout<<mincost<<endl;

}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	pre();
	int t=1;
	//cin>>t;
	for(int i=1;i<=t;i++){
		//cout<<"Case #"<<i<<": ";
		solve();
	}
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()

int main(int argc, char** argv) {
  int n;
  cin >> n;
  uint64_t a[n];
  rep(i, n) cin >> a[i];

  vector<int> sorted; // contains max values. sorted.

  rep(i, n) {
    auto it = lower_bound(all(sorted), a[i]);

    if (it == sorted.begin()) {  // The lowest
      sorted.insert(sorted.begin(), a[i]);  // Push front
    } else {
      --it;
      *it = a[i];
    }
  }

  cout << sorted.size() << endl;
}

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

int main(void){
    int n, m;
    cin >> n >> m;
    
    if(n >= m){//n>=mのとき０
        cout << 0 << endl;
        return 0;
    }
    
    vector<int> x(m);
    rep(i, m){
        cin >> x.at(i);
    }
    sort(x.begin(), x.end());
    
    vector<int> d(m-1);
    rep(i, m-1){
        d.at(i) = x.at(i+1) - x.at(i);
    }
    
    sort(d.begin(), d.end());
    int res = x.at(m-1) - x.at(0);
    rep(i, n-1){
        res -= d.at(m-i-2);
    }
    
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <vector>
#include <cassert>
#include <functional>

template<typename T>
struct BinaryIndexedTree {
	using value_type = T;
	using const_reference = const value_type &;
	using F = std::function<value_type(const_reference, const_reference)>;
	using size_type = std::size_t;
	
	BinaryIndexedTree(size_type n_, const F & f, const_reference id_elem) : n(n_), f(f), id_elem(id_elem) {
		node.resize(n + 1, id_elem);
	}
	
	size_type size() const noexcept {
		return n;
	}
	
	void add(size_type i, const_reference x) {
		assert(i < size());
		++i;
		for (; i <= size(); i += i & -i) node[i] = f(node[i], x);
	}
	
	// [0, i)
	value_type sum(size_type i) const {
		assert(i <= size());
		value_type res = id_elem;
		for (; i > 0; i -= i & -i) res = f(res, node[i]);
		return res;
	}
	
	// sum[0, r] \leq x を満たす最小の r を返す (存在しなければ size())
	size_type lower_bound(const_reference x) const {
		size_type res = 0;
		size_type s = id_elem, w = 1;
		while (w < size()) w <<= 1;
		for (; w > 0; w >>= 1) {
			if (res + w <= size()) {
				value_type cur = f(s, node[res + w]);
				if (cur < x) {
					res += w;
					s = cur;
				}
			}
		}
		return res;
	}
	
private:
	size_type n;
	F f;
	value_type id_elem;
	std::vector<value_type> node;
};


#include <vector>
#include <cassert>
#include <functional>

template<typename T, template<typename> class U>
struct BinaryIndexedTree_RangeAdd {
	using bit_type = U<T>;
	using value_type = typename bit_type::value_type;
	using const_reference = typename bit_type::const_reference;
	using size_type = typename bit_type::size_type;
	
	BinaryIndexedTree_RangeAdd(size_type n) : n(n) {
		bit.resize(2, bit_type(n, [](auto && x, auto && y) { return x + y; }, 0));
	}
	
	size_type size() const noexcept {
		return n;
	}
	
	// [l, r) += x
	void add(size_type l, size_type r, const_reference x) {
		assert(l < r);
		assert(r <= size());
		bit[0].add(l, x);
		bit[0].add(r - 1, -x);
		bit[1].add(l, -x * (static_cast<value_type>(l) - 1));
		bit[1].add(r - 1, x * (r - 1));
	}
	
	// \Sum_{ k = [0, i) } a_k
	value_type sum(size_type i) {
		assert(i <= size());
		return bit[0].sum(i) * (static_cast<value_type>(i) - 1) + bit[1].sum(i);
	}
	
	// \Sum_{ k = [l, r) } a_k
	value_type sum(size_type l, size_type r) {
		assert(l < r);
		assert(r <= size());
		return sum(r) - sum(l);
	}
	
private:
	size_type n;
	std::vector<bit_type> bit;
};

#include <cstdio>
int main() {
	int n, q;
	scanf("%d %d", &n, &q);
	
	using ll = long long;
	
	BinaryIndexedTree_RangeAdd<ll, BinaryIndexedTree> bit(n);
	while (q--) {
		int query, s, t;
		scanf("%d %d %d", &query, &s, &t);
		--s;
		if (query == 0) {
			int x;
			scanf("%d", &x);
			bit.add(s, t, x);
		}
		else {
			printf("%lld\n", bit.sum(s, t));
		}
	}
	return 0;
}


Measured memory_bytes: 4764
a,b,c,d,e,f=map(int,input().split())
a*=100
b*=100
x=set()
for i in range(0,f+1,a):
    for j in range(0,f+1,b):
        if 0<(i+j)<=f:
            x.add(i+j)
y=set()
for i in range(0,f+1,c):
    for j in range(0,f+1,d):
        if 0<(i+j)<=f:
            y.add(i+j)

ans=[]
for n in x:
    for m in y:
        if n+m>f:
            continue
        if n*e<m*100:
            continue
        ans.append([n+m,m,m/n])
if not ans:
    print(a,0)
    exit()
ans.sort(key=lambda x:x[2], reverse=True)

print(ans[0][0],ans[0][1])


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

int main(){
    int n;
    cin >> n;
    vector<P> p(n);
    // string ans = "Yes";
    for (int i = 0 ;i < n;i++){
        cin >> p[i].second >> p[i].first;       
    }
    //Bの値でそーとしたいからBをfirstに入れる;
    sort(p.begin(),p.end());
    //pairのそーとはまずfirstみて同値ならsecondで昇順そーと;
    long long t = 0;
    for (int i = 0;i < n;i++){
        t += p[i].second;
        if(t > p[i].first){
            // ans = "No";
            puts("No");
            return 0;
        }
    }
    // cout << ans << endl;
    puts("Yes");
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define N 100009
using namespace std;

int n,sa[N],sb[N]; ll A,B,p[N]; bool va[N],vb[N];
int main(){
	scanf("%d%lld%lld",&n,&A,&B);
	int i,j,fa,fb,ka,kb,x,y;
	for (i=1; i<=n; i++) scanf("%lld",&p[i]);
	memset(va,1,sizeof(va));
	memset(vb,1,sizeof(vb));
	for (i=2,fa=fb=ka=kb=1; i<=n; i++){
		for (; ka+1<i && p[i]-p[ka]>=A; ka++);
		for (; kb+1<i && p[i]-p[kb]>=B; kb++);
		x=sb[ka-1]+fb; y=sa[kb-1]+fa;
		if (p[i]-p[i-1]<A){
			fa=0;
			for (j=i-2; j && va[j]; j--){
				va[j]=0; sa[j]=0;
			}
		}
		if (p[i]-p[i-1]<B){
			fb=0;
			for (j=i-2; j && vb[j]; j--){
				vb[j]=0; sb[j]=0;
			}
		}
		sa[i-1]=(sa[i-2]+x)%mod; sb[i-1]=(sb[i-2]+y)%mod;
	}
	printf("%d\n",(sa[n-1]+sb[n-1]+fa+fb)%mod);
	return 0;
}


Measured memory_bytes: 2048
//c++ テンプレ
#include<bits/stdc++.h>
using namespace std;

typedef long long llint;
typedef unsigned long LInt;
typedef long double ld;

#define inf 1e18
constexpr long long INFLL = 1e18;
#define mod 1000000007
priority_queue<llint,vector<llint>,greater<llint> > que;
priority_queue<llint> Que;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

map<llint,llint>mp;
bool prime[1000005];

void solve(){
    llint n;
    cin >> n;
    
    for(int i = 2; i <1000005 ; i++){
		if(prime[i]) continue;
		for(int j = 2*i; j < 1000005; j+=i) prime[j] = true;
	}
    
    for(int i=2;i<1000005;i++){
        if(prime[i])continue;
        while(n%i==0){
            mp[i]++;
            n/=i;
        }
    }
    if(n>1)mp[n]++;
    llint ans=0;
    for(auto it = mp.begin(); it != mp.end(); it++){
		for(int i = 1; ; i++){
			if(it->second >= i){
				ans++;
				it->second -= i;
			}
			else break;
		}
	}
	cout << ans << endl;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 4612
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////
ll n,x;

int main(){
    cin >> n >> x;
    
    set<ll> s;
    s.it(x);
    
    rep(i,0,n){
        ll a;
        cin >> a;
        s.it(a);
    }

    vector<ll> b;
    for(auto i : s)b.pb(i);

    //rep(i,0,sz(b))PS(b[i]);
    //cout << endl;
    
    ll ans = b[1]-b[0];
    rep(i,1,sz(b)){
        ans = gcd(ans,b[i]-b[i-1]);
    }
    P(ans);
	return  0;
}

Measured memory_bytes: 6136
#include <stdlib.h>
#include<iostream>
#include<bits/stdc++.h>
#include<cmath>
#define ll long long
const ll INF=0x3f3f3f3f;
#define mod 1000000007
using namespace std;
//priority_queue
const ll Maxn=1e5;
ll gcd(ll a,ll b)
{
    return b==0?a:gcd(b,a%b);
}
ll kc(ll a,ll b)
{
    ll c=1;
    while(b)
    {
        if(b&1)c=(c*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return c;
}
bool cmp(double x,double y)
{
    return x>y;
}
ll s[100003];
ll ss[100003];
int main()
{
    ios::sync_with_stdio(false);
 ll n;
 cin>>n;
 ll sum=0;
 for(ll i=1;i<=n;i++)
    cin>>s[i];
    ll z=1;
    for(ll i=n;i>=1;i--)
    {
        sum+=z*s[i];
        z*=-1;
    }sum/=2;
    for(int i=1;i<=n;i++)
    { cout<<sum*2;
        if(i!=n)cout<<" ";
        sum=s[i]-sum;
        //cout<<s[i]<<endl;
    }


}


Measured memory_bytes: 2176
import math
Q = int(input())
ans = []

for i in range(Q):
    a,b = map(int,input().split())
    if a>b:
        a,b = b,a
    if a == b:
        ans.append((a-1)*2)
        continue
    c = math.ceil((a*b)**0.5-1)
    
    ans.append(c*2-1)
    if a <= c:
        ans[-1] -= 1
    if c*(c+1) < a*b and a != c+1 != b:
        ans[-1] +=1
for i in ans:
    print(i)


Measured memory_bytes: 3064
n=int(input())
t ,a=list(map(int, input().split()))
h = list(map(int,input().split(' ')))

min=100000000000000
min_index=n+1
for i in range(len(h)):
  v = abs(t - h[i]*0.006-a)
  if v < min:
    min=v
    min_index=i
print(min_index+1)


Measured memory_bytes: 3060
n, m = gets.chomp.split.map(&:to_i)
answer = Array.new(m, 0)

n.times do
  array = gets.chomp.split.map(&:to_i)
  array.delete_at(0)
  array.each do |i|
    answer[i-1] += 1
  end
end

k = 0
answer.each do |i|
  if i == n
    k += 1
  end
end

puts k

Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

int main() {
	vector<int> vec(3);
	int tri; int rig = 0; int acu = 0; int obt = 0;
	while (cin >> vec[0] >> vec[1] >> vec[2]) {
		sort(vec.begin(), vec.end());
		if (vec[0] + vec[1] > vec[2]) {
			for (int i = 0; i < 3; i++) vec[i] = pow(vec[i], 2);
			if (vec[0] + vec[1] == vec[2]) rig++;
			else if (vec[0] + vec[1] > vec[2]) acu++;
			else if (vec[0] + vec[1] < vec[2]) obt++;
		}
		else break;
	}
	tri = rig + acu + obt;
	cout << tri << " " << rig << " " << acu << " " << obt << endl;
	return 0;
}


Measured memory_bytes: 3148
q=0
while True:
   try:
      x = input()
      c = 0
      if len(x)%2==0:
         for i in range(len(x)//2):
            if x[i] == x[len(x)-i-1]:
               c += 1
            else:
               pass
         if c == len(x)//2:
            q += 1
      else:
         for j in range((len(x)-1)//2):
            if x[j] == x[len(x)-j-1]:
               c += 1
            else:
               pass
         if c == (len(x)-1)//2:
            q += 1
   except EOFError:
      break
print(q)


Measured memory_bytes: 5564
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <bitset>

using namespace std;
typedef pair<int, int> Pi;
typedef long long ll;
#define pii Pi
#define pll PL
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) ((int)(x).size())
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) (x).begin(), (x).end()
typedef tuple<int, int, int> t3;
typedef pair<ll, ll> PL;
typedef long double ldouble;

int A[5050][5050], B[5050][5050], P[5050], N;

void solve(){
	int K;
	scanf("%d%d", &N, &K);
	for(int i=1;i<=N;i++)scanf("%d", P+i);
	A[0][0] = 1;
	for(int i=1;i<=N;i++){
		for(int j=0;j<=K;j++)A[i][j] = A[i-1][j];
		for(int j=P[i];j<=K;j++)A[i][j] |= A[i-1][j-P[i]];
	}
	B[N+1][0] = 1;
	for(int i=N;i;i--){
		for(int j=0;j<=K;j++)B[i][j] = B[i+1][j];
		for(int j=P[i];j<=K;j++)B[i][j] |= B[i+1][j-P[i]];
	}
	int ans = 0;
	for(int i=1;i<=N;i++){
		int l = max(0, K - P[i]);
		int r = K - 1;
		vector <int> v;
		for(int j=K;j>=0;j--)if(A[i-1][j])v.pb(j);
		int ok = 0;
		for(int j=0, a=0;j<=K;j++)if(B[i+1][j]){
			while(a < sz(v) && v[a] + j > r)++a;
			if(a < sz(v) && v[a] + j >= l){
				ok = 1; break;
			}
		}
		ans += !ok;
	}
	printf("%d\n", ans);
}

int main(){
	int Tc = 1; //scanf("%d\n", &Tc);
	for(int tc=1;tc<=Tc;tc++){
		solve();
	}
	return 0;
}

Measured memory_bytes: 198912
#include<iostream>
#include <string.h>
#include<stdio.h>
#include <vector>
#include <math.h>


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


int main(){
	string S, T;
	int ans = 0;

	cin >> S >> T;

	int n = S.size();

	rep(i, n) {
		if (S[i] != T[i]) {
			ans++;
		}
	}

	cout << ans << endl;

return 0;
}


Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef pair<ll, ll> P;

int main(){
    ll k, x;
        cin >> k >> x;
    k--;
    ll l = max(x-k,-1'000'000LL);
    ll r = min(x+k, 1'000'000LL);
    for(int i=l; i<=r; i++){
        cout << i;
        if(i<r) cout << ' ';
    }
    cout << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,a,b,c=0,d=0;
  string s;
  cin>>n>>a>>b>>s;
  for(int i=0;i<n;++i){
    if(s[i]=='a'){
      if(c<a+b){
        cout << "Yes" << endl;
        c++;
      }else cout << "No" << endl;
    }else if(s[i]=='b'){
      if(c<a+b&&d<b){
        cout << "Yes" << endl;
        c++;
        d++;
      }else cout << "No" << endl;
    }else cout << "No" << endl;
  }
  return 0;
}

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

to = [[] for _ in range(110000)]
ans = [0] * 110000
queue = []
passed = [0] * 110000
passed[1] = 1

def search(i):
  global queue
  global passed
  global ans
  for j in to[i]:
    if passed[j] == 0:
      queue.append(j)
      passed[j] = 1
      ans[j] = i
  


for _ in range(m):
  a, b = map(int, input().split())
  to[a].append(b)
  to[b].append(a)

search(1)
queue.append(1)

while queue:
  que = queue.pop(0)
  search(que)


print("Yes")
for i in ans[2:n + 1]:
  print(i)

Measured memory_bytes: 36104
use proconio::*;

fn run() {
    input! {
        n: usize,
        a: [u32; n],
    }
    let xor = a.iter().fold(0, |s, a| s ^ *a);
    for a in a {
        println!("{}", a ^ xor);
    }
}

fn main() {
    run();
}

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

using namespace std;
using ll = long long;

template <typename K,typename V>
using umap = unordered_map<K,V>;
template <typename V>
using uset = unordered_set<V>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define REP(i,n) for(int i=0;i<n;i++)
#define REPD(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(v) v.begin(),v.end()

#define endl "\n"
#define INF 1'000'000'000'000 //10^12
#define MOD 1'000'000'007
//グリッドグラフの範囲チェック
bool range_validation(int y,int x,int h,int w){
    return y>=0 && y<h && x>=0 && x < w;
}
//ビットカウント
int popcount(long bits){
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

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

vector<ll> sieve(ll n){
  vector<bool> is_prime(n+1,true);
  vector<ll> res;
  for(int i=2;i<=n;i++){
    if(is_prime[i]){
      res.push_back(i);
      for(int j=2*i;j<=n;j+=i){
        is_prime[j] = false;
      }
    }
  }
  return res;
}

vector<ll> divisor(ll n){
  vector<ll> list;
  for(int i=1;i*i<=n;i++){
    if(n%i==0){
      list.push_back(i);
      if(n/i != i){
        list.push_back(n/i);
      }
    }
  }
  return list;
}

umap<int,int> prime_factor(ll n){
  umap<int,int> fac;
  for(int i=2;i*i<=n;i+=2){
    if(n%i == 0){
      int count = 0;
      while(n%i == 0){
        count++;
        n /= i;
      }
      fac[i] = count;
    }
  }
  if(n!=1)fac[n] = 1;
  return fac;
}

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  int n;
  cin >>n;
  vector<string> s(n);
  int countA = 0;
  int countB = 0;
  int countAB = 0;
  REP(i,n){
	cin >> s[i];
    int len = (int)s[i].length();
    if(s[i][0]=='B' && s[i][len-1] == 'A'){
      countAB++;
    }else if(s[i][0] == 'B'){
      countB++;
    }else if(s[i][len-1] == 'A'){
      countA++;
    }
    
  }
  int count = 0;
  REP(i,n){
    int len = (int)s[i].length();
    REP(j,len-1){
      if(s[i][j] == 'A' && s[i][j+1] == 'B'){
        count++;
      }
    }
  }
  
  if(countAB > 0){
    count += countAB-1;
    if(countA > 0){
      countA--;
      count++;
    }
    if(countB > 0){
      countB--;
      count++;
    }
  }
  
  count += min(countA,countB);
  
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 3748
#include<iostream>
#include<vector>
#include<iomanip>
#include<cmath>

using namespace std;

int main(){
  int N; cin >> N;
  vector<int> x(N), y(N);
  
  for(int i = 0; i < N; ++i){
    cin >> x[i] >> y[i];
  }
  
  double ans = 0.0;
  
  for(int i = 0; i < N; ++i){
    for(int j = i+1; j < N; ++j){
      double d = sqrt(pow(abs(x[j]-x[i]), 2) + pow(abs(y[j]-y[i]), 2));
      ans += d * 2 / N;
    }
  }
  
  cout << setprecision(10) << ans << endl;
  
  return 0;
}
    
  


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

using namespace std;

const int maxn=500005;
typedef long long ll;

int read()
{
	int f=0; char c=getchar();
	while(c>'9' || c<'0') c=getchar();
	while(c<='9' && c>='0') {f=f*10+c-'0'; c=getchar();}
	return f;
}

int a,b,c,d;
double r;

int main()
{
//	while(1) cout<<read()<<endl;
	cin>>r;
	cout<<r*3.1415926*2<<endl;
	return 0;
}

Measured memory_bytes: 3784
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#pragma GCC optimize(2)
#include<iostream>
#include<algorithm>
using namespace std;
const int N=1000010;
int a[N],cnt[N];
int n;
int gcd(int a,int b)
{
    return b?gcd(b,a%b):a;
}
void divide(int x)
{
    for(int i=2;i<=x/i;i++)
    {
        if(x%i==0) 
        {
            cnt[i]++;
            while(x%i==0) x/=i;
        }
    }
    if(x>1) cnt[x]++;
}
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=1;i<=n;i++) divide(a[i]);
    int d=a[1];
    for(int i=2;i<=n;i++) d=gcd(d,a[i]);
    bool ok=1;
    for(int i=1;i<N;i++)
        if(cnt[i]>1) 
        {
            ok=0;
            break;
        }
    if(ok) cout<<"pairwise coprime"<<endl;
    else if(d==1) cout<<"setwise coprime"<<endl;
    else cout<<"not coprime"<<endl;
    return 0;
}

Measured memory_bytes: 11340
using System;
using System.Runtime.InteropServices;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;

namespace AGC_026_A
{
    internal class Program
    {
        public static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] a = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

            int cur = -1;
            int ans = 0;
            for (int i = 0; i < n; i++)
            {
                if (a[i] == cur)
                {
                    cur = -1;
                    ans++;
                    continue;
                }

                cur = a[i];
            }
            
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 11092
h, w = map(int, input().split())
s = [str(input()) for _ in range(h)]
data = [[0] * w for _ in range(h)]

direc = [-1, 0, 1]

for i in range(h):
    for j in range(w):
        if s[i][j] == '.':
            for x in direc:
                for y in direc:
                    if 0 <= i + x < h and 0 <= j + y < w:
                        if s[i+x][j+y] == '#':
                            data[i][j] += 1
        else:
            data[i][j] = '#'

for i in range(h):
    for j in range(w):
        if data[i][j] != '#':
            data[i][j] = str(data[i][j])

for i in range(h):
    print((''.join(data[i])))

Measured memory_bytes: 3192
/*
　　こんにちは。あたしはｶｳｶﾞｰﾙ。
　　redcoderになるためAtCoderを巡る旅をしてます。

　　　 　 ＿_
　　　 ヽ|＿_|ノ　　　　ﾓｫ
　　　　||‘‐‘||ﾚ　　_)_, ―‐ 、
　　　　/(Ｙ (ヽ＿ /・ ヽ　　 ￣ヽ
　　　　∠ ＿ ゝ　 ｀^ヽ ﾉ.::::_(ノヽ
　　　　 _/ヽ　 　　  /ヽ￣￣/ヽ
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1
#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(v) (v).begin() , (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define COUT(x) cout << (x) << endl

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 main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    vector<ll> a(3);
    cin >> a[0] >> a[1] >> a[2];
    sort(ALL(a));
    int flg = 0;
    ll ans = 0;
    if(a[2] & 1) flg = 1;
    if(flg) ans = a[1] * a[0];
    else ans = 0;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using ll=long long;
using namespace std;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}
int dh[4] = {-1, 0, 0, 1};
int dw[4] = {0, -1, 1, 0}; 
using P = pair<int, int>;
const double pi = acos(-1.0);

int main(){
  ll n,k;
  cin>>n>>k;
  vector<ll>a(n);
  vector<ll>cnt(200010);
  rep(i,n){
    cin>>a[i];
    cnt[a[i]]++;
  }
  sort(all(cnt));
  reverse(all(cnt));
  int ans=0;
  Rep(i,k,200010){
    if(cnt[i]==0)break;
    ans+=cnt[i];
  }
  
  

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


Measured memory_bytes: 6388
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cctype>
using namespace std;
void _2();
void _3();
int main(){

    int n;
    scanf("%d",&n);

    (n == 2) ? _2() : _3();

    return 0;
}
void _2(){

    int a,b;
    scanf("%d%d",&a,&b);
    int mi = min(a,b);
    for(int i = 1; i <= mi; i++){
        if(a % i == 0 && b % i == 0){
            printf("%d\n",i);
        }
    }
    return;
}
void _3(){
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    int mi = min(a,min(b,c));
    for(int i = 1; i <= mi; i++){
        if(a % i == 0 && b % i == 0 && c % i == 0){
            printf("%d\n",i);
        }
    }
    return;
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>

using namespace std;

class cSort
{
public:
	void sort( int* arr, int len )
	{
		int mi, mx, z = 0; findMinMax( arr, len, mi, mx );
		int nlen = ( mx - mi ) + 1; int* temp = new int[nlen];
		memset( temp, 0, nlen * sizeof( int ) );

		for( int i = 0; i < len; i++ ) temp[arr[i] - mi]++;

		for( int i = mi; i <= mx; i++ )
		{
			while( temp[i - mi] )
			{
				arr[z++] = i;
				temp[i - mi]--;
			}
		}

		delete [] temp;
	}

private:
	void findMinMax( int* arr, int len, int& mi, int& mx )
	{
		mi = INT_MAX; mx = 0;
		for( int i = 0; i < len; i++ )
		{
			if( arr[i] > mx ) mx = arr[i];
			if( arr[i] < mi ) mi = arr[i];
		}
	}
};

void printv(int v[], int len) {
	int ifs = 1;
	for (int i = 0; i < len; i++) {
		if (ifs == 0)
			cout << " ";
		cout << v[i];
		ifs = 0;
	}
	cout << endl;
}

int main() {
	int n;
	cin >> n;
	int *A = new int[n];
	for (int i = 0; i < n; i++)
		cin >> A[i];
	cSort s; s.sort(A, n);
	printv(A, n);
	return 0;
}

Measured memory_bytes: 9056
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let N = read!(usize);
    let T = read![String, i64; N];

    let mut R = (0..N).collect::<Vec<_>>();
    R.sort_by(|&l, &r| {
        let &(ref l_city, l_point) = &T[l];
        let &(ref r_city, r_point) = &T[r];

        let ord = l_city.cmp(&r_city);
        if ord != Ordering::Equal {
            return ord;
        }

        // 評価点は降順でソートなので左右を逆にしている
        r_point.cmp(&l_point)
    });

    for i in R {
        println!("{}", i + 1)
    }
}


Measured memory_bytes: 4352
#include <stdio.h>

int main() {
    int a, b;

    scanf("%d", &a);

    scanf("%d", &b);
    
    if (a < b){
        printf("a < b\n");
    }
    else if (a > b) {
        printf("a > b\n");
    }
    else {
        printf("a == b\n");
    }
    return 0;
}


Measured memory_bytes: 2696