akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using BitArray = System.Collections.BitArray;
using BigInteger = System.Numerics.BigInteger;

namespace AtCoderProject
{
    public class Program
    {
        public object Calc()
        {
            var N = consoleReader.Int;
            var strs = consoleReader.Repeat(N).String.Select(s => new string(s.OrderBy(c => c).ToArray())).ToArray();
            var items = strs.ToLookup(s => s).Select(g => (long)g.Count());
            long count = 0;

            foreach (var i in items)
            {
                if (i > 1)
                {
                    count += i * (i - 1) / 2;
                }
            }
            return count;
        }

        #region いつもの
        private readonly ConsoleReader consoleReader;
        public Program(ConsoleReader consoleReader) { this.consoleReader = consoleReader; }
        static void Main() => Console.WriteLine(new Program(new ConsoleReader()).Calc()); static string AllLines<T>(IEnumerable<T> source) => string.Join("\n", source);
        #endregion
    }

#pragma warning disable
    public class ConsoleReader { public class SplitLine { string[] splited; public SplitLine(string line) { splited = line.Split(); } public string[] String => splited.ToArray(); public int[] Int => splited.Select(int.Parse).ToArray(); public long[] Long => splited.Select(long.Parse).ToArray(); public ulong[] ULong => splited.Select(ulong.Parse).ToArray(); public double[] Double => splited.Select(double.Parse).ToArray(); } public class RepeatLine { ConsoleReader reader; int num; public RepeatLine(ConsoleReader reader, int num) { this.reader = reader; this.num = num; } public IEnumerable<string> String { get { for (int i = 0; i < num; i++) yield return reader.String; } } public IEnumerable<int> Int { get { for (int i = 0; i < num; i++) yield return reader.Int; } } public IEnumerable<long> Long { get { for (int i = 0; i < num; i++) yield return reader.Long; } } public IEnumerable<string[]> SplitString { get { for (int i = 0; i < num; i++) yield return reader.Split.String; } } public IEnumerable<int[]> SplitInt { get { for (int i = 0; i < num; i++) yield return reader.Split.Int; } } } public virtual string String => Console.ReadLine(); public int Int => int.Parse(String); public long Long => long.Parse(String); public ulong ULong => ulong.Parse(String); public double Double => double.Parse(String); public SplitLine Split => new SplitLine(String); public RepeatLine Repeat(int count) => new RepeatLine(this, count); }
}

Measured memory_bytes: 32624
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <functional>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define REP(i, n) for (int i = 1; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr int inf = 1000000000;
constexpr ll INF = 5000000000000000000;

int main() {
    ll x;
    cin >> x;
    ll ans = 0;
    ans += x / 11 * 2;
    x -= x / 11 * 11;
    if (x >= 1 && x <= 6) ans += 1;
    if (x >= 7) ans += 2;
    cout << ans << "\n";
}


Measured memory_bytes: 3580
/*******************************
 * written by Koki Riho
 * Rih0z https://github.com/Rih0z
 *******************************/

#include<iostream>
#include<map>
#include<vector>
#include<string>
#include<numeric>
#include<algorithm>

#define DEBUG false

#define FOR(i , a, b) for(size_t i = a ; i < b ; i++ )
#define REP(i,b) FOR(i , 0 , b)
#define RFOR(i,a,b) for(size_t i = a-1 ; i >= b ; i--)
#define RREP(i,a) RFOR(i,a,0)



typedef long long ll;
using namespace std;

int scanInt(void);
string scanString(void);

void scanLlArr(ll *a , int n);
void scanCharArr(char *string);

void printInt(int p);
void printLlArr(ll *a);
void printCharArr(char *string);


void perSum(ll *a , ll *sum ,int n);

/*************Global variable  **************/
int N ;
char str[26];
std::map<char,int> M ;
/*******************************/

int main(){
  if (DEBUG){
    std::printf("******debug mode********\n");
  }
  cin >> N ;
  int a[N];
    REP(i,N){
      cin >> a[i];
    }
    int maxs = 0 ;
    int mins = 1999999999;
    for(int i = 0 ; i < N ; i++)
    {
      mins = min(mins,a[i]);
      maxs = max(maxs,a[i]);
    }
    cout << abs(maxs-mins) << endl;
  if (DEBUG){
    std::printf("******debug********\n");

    std::printf("******debug********\n");
  }
  return 0 ;
}

//各地点までの部分和を計算する
void perSum(ll *a , ll *sum ,int n){
  int i ;
  sum[0] = a[0];
  for(i = 1 ; i < n ; i++){
    sum[i] = a[i] + sum[i-1];
  }

}


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

int main(void) {
    string S,T;

    cin >> S >> T;
    if(((S.size()+1) == T.size()) && (strncmp(&S[0],&T[0],S.size()) == 0)) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
    return 0;
}


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

int main() {
  int a,b;
  cin>>a>>b;
  
  bool flag=0;
  vector<int> v={0,1,3,1,2,1,2,1,1,2,1,2,1};
  if(v[a]==v[b])puts("Yes");
  else puts("No");
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define pob pop_back
#define ff first
#define ss second
#define endl "\n"
#define all(a) a.begin(),a.end()
#define debug(x) cout << x << endl;
#define int long long
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

using namespace __gnu_pbds;
using namespace std;
using LD = long double;

const int N = 2e7+1;
const int mod = 1e9+7;
const int INF = 1e9;

void solve() {
	int n;
	cin >> n;
	int a[n];
	for(int i=0;i<n;i++)
		cin >> a[i];
	sort(a,a+n);
	int i = 0,sum = a[n-1],k = n-2;
	while(i < n-2) {
		if(i + 1 < n-2) {
			sum += 2*a[k];
			i += 2;
		}
		else {
			sum += a[k];
			i++;
		}
		k--;
	}
	cout << sum << endl;
}
 
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int t = 1,i = 1;
    //cin >> t;
    while(t--) {
        //cout << "Case #" << i << ": ";
        solve();
        //i++;
    }
    return 0;
}


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

#define int long long

signed main() {
	map <string, int> M;
	int n;
	cin >> n;
	while(n--){
		string s;
		cin >> s;
		M[s]++;
	}
	cout << "AC x " << M["AC"] << '\n';
	cout << "WA x " << M["WA"] << '\n';
	cout << "TLE x " << M["TLE"] << '\n';
	cout << "RE x " << M["RE"] << '\n';
}

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

int main(int argc, char const *argv[])
{
	string n;
	cin>>n;
	for (int i = 0; i < 3; ++i)
	{
		if (n[i]=='1')
		{
			n[i]='9';
		}
		else if (n[i]=='9')
		{
			n[i]='1';
		}
	}
	cout<<n<<endl;
	return 0;
}


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

using namespace std;

using ll = long long;

const ll INF = 1LL << 60;

int main() {
    int N;
    cin >> N;
    vector<ll> a(N);
    for (int i = 0; i < N; ++i) cin >> a[i];
    vector<ll> cum_sum(N + 1, 0);
    for (int i = 0; i < N; ++i) {
        cum_sum[i + 1] = cum_sum[i] + a[i];
    }
    ll ans = INF;
    for (int i = 1; i < N; ++i) {
        ll abs_sum = abs((cum_sum[N] - cum_sum[i]) - cum_sum[i]);
        if (abs_sum < ans) ans = abs_sum;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3328
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<map>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  int N;
  string s;
  cin >> s;
  if(s[s.size()-1] == s[0]){
    cout << (s.size() %2 ? "Second" : "First") << endl; 
  }else
    cout << (s.size() % 2 ? "First" : "Second") << endl;;

  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int N, K;
int a[200010];
ll b[200010];
pair<ll, int> p[200010];
ll bit[200010];

void add(int i, ll x) {
  while (i <= N) {
    bit[i] += x;
    i += i & -i;
  }
}

ll sum(int i) {
  ll res = 0;
  while (i > 0) {
    res += bit[i];
    i -= i & -i;
  }
  return res;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    a[i] -= K;
  }
  for (int i = 0; i < N; i++) {
    b[i+1] = a[i] + b[i];
  }
  for (int i = 0; i <= N; i++) {
    p[i] = make_pair(b[i], i);
  }
  sort(p, p+N+1);

  ll cnt = 0;
  bool zero = false;
  for (int i = 0; i <= N; i++) {
    if (p[i].second == 0) {
      cnt += i;
      zero = true;
    } else {
      cnt += i - sum(p[i].second) - zero;
      add(p[i].second, 1);
    }
  }
  cout << (ll)N*(N+1) / 2 - cnt << endl;

  return 0;
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define pii pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define mp make_pair
#define bit(n) (1LL<<(n))
#define F first
#define S second
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll INF = 1LL<<60;
const ll mod = (int)1e9 + 7;

int main() {
    int n,k;
    cin >> n >> k;
    int r,s,p;
    cin >> r >> s >> p;
    int sum=0;
    string t;
    cin >> t;
    rep(i,n){
        if(i<k){
            if(t[i]=='r')sum+=p;
            else if(t[i]=='s')sum+=r;
            else sum+=s;
        }
        else{
            if(t[i]==t[i-k])t[i]='!';
            else{
                if(t[i]=='r')sum+=p;
                else if(t[i]=='s')sum+=r;
                else sum+=s;
            }
        }
    }
    cout << sum;
    


}

/*



 */


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
#define ITR(v,c) for(auto v=begin(c);v!=end(c);v++)
#define FOR(v,a,n) for(int v=a;v<(int)(n);v++)
#define FORE(x,arr) for(auto &x:arr)
#define REP(v,n) FOR(v,0,n)
#define ALL(c) begin(c),end(c)
const int DX[4]={0,1,0,-1}, DY[4]={-1,0,1,0};
const int INF = 1e9;
template<class T,class U>ostream&operator<<(ostream &os,const pair<T,U> &p){
    os<<"("<<p.first<<","<<p.second<<")";return os;}
template<class T>ostream&operator<<(ostream &os,const vector<T> &v){
    ITR(i,v)os<<*i<<(i==end(v)-1?"":"\n");return os;}
//------------------------------------------------------------------------------

int main(int argc, char const *argv[]) {
    int N;
    cin>>N;
    int ans=0;
    REP(i,N) {
        ans+=i+1;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import collections
n=int(input())
l=[]
for i in range(n):
    l.append(int(input()))

l_set=list(set(l))
counter=collections.Counter(l)
ans=0
for i in range(len(l_set)):
    if counter[l_set[i]]%2!=0:
        ans+=1
print(ans)

Measured memory_bytes: 62416
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        String str=scanner.next();
        StringBuilder stringBuilder1=new StringBuilder();
        StringBuilder stringBuilder2=new StringBuilder();
        for(int j=0;j<(str.length()-1)/2;j++){
            stringBuilder1.append(str.charAt(j));
        }
        StringBuilder stringBuilder=new StringBuilder();
        for(int j=((str.length()-1)/2)+1;j<str.length();j++){
            stringBuilder2.append(str.charAt(j));
            stringBuilder.append(str.charAt(j));
        }
//        StringBuilder stringBuilder=stringBuilder2;
        StringBuilder ss=stringBuilder2.reverse();
        //stringBuilder2=stringBuilder2.reverse();
//        System.out.println(ss.toString());
//        System.out.println(stringBuilder.toString());
        if(stringBuilder1.toString().equals(ss.toString())){
            int ff=0;
            for(int j=0;j<stringBuilder1.length();j++){
                if(stringBuilder1.charAt(j)!=stringBuilder1.charAt(stringBuilder1.length()-1-j)){
                    ff=1;
                    break;
                }
            }
            for(int j=0;j<stringBuilder.length();j++){
                if(stringBuilder.charAt(j)!=stringBuilder.charAt(stringBuilder.length()-1-j)){
                    ff=1;
                    break;
                }
            }
            if(ff==1){
                System.out.println("No");
            }
            else{
                System.out.println("Yes");
            }


        }
        else{
//            System.out.println(stringBuilder1.toString());
//            System.out.println(stringBuilder2.toString());
            System.out.println("No");
        }


    }

}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,count=0,j;
  cin>>A>>B;
  for(int i=0;i<(B-A+1);i++){
    j=A+i;
    int a,b,c,d,e;
    e=j%10,a=j-j%10000,b=j-a-j%1000,c=j-a-b-j%100,d=j-a-b-c-e;
    if(e==a/10000&&b/1000==d/10){
    count++;
    }    
  }
  cout<<count<<endl;
}

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

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	unsigned long long n; cin >> n;
	unsigned long long ans{};
	for(int i = 1; i <= n; i++)
	{
		if (i % 3 != 0 && i % 5 != 0)
			ans += i;
	}
	cout << ans;
}

Measured memory_bytes: 3620
import heapq
N, M = [int(s) for s in input().split(' ')]
A = [int(s) for s in input().split(' ')]
q = []
for a in A:
    heapq.heappush(q, (-a, a))
for y in range(M):
    _, a = heapq.heappop(q)
    a //= 2
    heapq.heappush(q, (-a, a))

print(sum([a for _, a in q]))


Measured memory_bytes: 21316
import numpy as np
n = int(input())
v = np.array(list(map(int, input().split())))
c = np.array(list(map(int, input().split())))

v_c = v -c
v =np.sort(v_c)[::-1]
ans = 0
for i in range(n):
    if v[i]>=0:
        ans += v[i]

print(ans)


Measured memory_bytes: 14424
//#define _GLIBCXX_DEBUG
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
//const ll MOD=998244353;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);
int dx[9] = {1, 0, -1, 0, 1, 1, -1, -1, 0};
int dy[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()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  // cout << fixed << setprecision(15);

  ll T; cin>>T;
  rep(i,T){
    ll N,M,A,B; cin>>N>>M>>A>>B;
    cout<<floor_sum(N,M,A,B)<<'\n';
  }
  
  return 0;
}

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

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

    int a, b, c, d;
    a = (4 * x - y) % 2;
    b = (y - ( 2 * x) ) % 2;
    c = (4 * x - y);
    d = (y - (2 * x));


    if (a == 0 && b == 0 && c >= 0 && d >= 0) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3632
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(_,v.size())cout<<" "<<v[_];cout<<endl;
#define show2d(v) rep(_,v.size()){rep(__,v[_].size())cout<<" "<<v[_][__];cout<<endl;}cout<<endl;
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef ll Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
// typedef tuple<int,int,int> tp;
// typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 1e18+10 : 1e9+10;
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,1,-1,1,-1};//RDLU
int n,m;
vvi G;
vi used;
ll co1=0,co2=0,co3=0;
bool h;
void dfs(int a,int b){
	used[a]=b;
	rep(i,G[a].size()){
		int to=G[a][i];
		if(used[to]==-1)dfs(to,b^1);
		else if(used[to]==b)h=false;
	}
}
int main(){
	cin>>n>>m;
	G=vvi(n);
	rep(i,m){
		int a,b;
		cin>>a>>b;
		a--;b--;
		G[a].pb(b);
		G[b].pb(a);
	}
	used=vi(n,-1);
	rep(i,n)if(used[i]==-1){
		if(G[i].size()==0)co1++;
		else{
			h=true;
			dfs(i,0);
			if(h)co2++;
			else co3++;
		}
	}
	cout<<2*co1*n-co1*co1+2*co2*co2+2*co2*co3+co3*co3<<endl;
	
	
	
	/*
	int n,l,t,co=0;
	cin>>n>>l>>t;
	
	vvi in(n,vi(2));
	rep(i,n)rep(j,2)cin>>in[i][j];
	rep(i,n)if(in[i][1]==2)in[i][1]=-1;
	
	vvi g(n,vi(2));
	rep(i,n){
		if(in[0][1]!=in[i][1]){
			ll w=t;
			co+=w/l;
			w%=l;
			ll dis=(l+in[i][0]-in[0][0])%l;
			if(in[0][1]==-1)dis=(l+in[0][0]-in[i][0])%l;
			if(dis<=2*w)co++;
		}
		g[i]={(in[i][0]+t*in[i][1])%l,in[i][1]};
	}
	if(in[0][1]==-1)co=n-1-co%n;
	else co%=n;
	cout<<co<<endl;
	show2d(in);
	show2d(g);
	
	*/
}







Measured memory_bytes: 12416
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> VI;
typedef pair <int,int> ii;
typedef long long LL;
#define pb push_back
const int INF = 2147483647;
const int N = 1000005;

int n, i, ex, res, tab[N];
char t[N];

int get(int x) {
	int res = 0;
	int l = 2;
	while (l <= x) {
		res += x / l;
		l *= 2;
	}
	return res;
}

bool odd(int a, int b) {
	return get(a) - get(b) - get(a - b) == 0;
}

int main() {
scanf("%d", &n);
scanf("%s", t);
for (i=0;i<n;i++) {
	tab[i] = int(t[i]) - '0' - 1;
	if (tab[i] == 1) {
		ex = 1;
		if (odd(n - 1, i)) res = 1 - res;
		//printf("%d %d\n", i, res);
	}
}

if (res) printf("1\n"); else if (ex) printf("0\n"); else {
	for (i=0;i<n;i++) if (tab[i] == 2 && odd(n - 1, i)) res = 1 - res;
	if (res) printf("2\n"); else printf("0\n");
}
return 0;
}





Measured memory_bytes: 5120
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
 
    char a, b; cin >> a >> b;

    string res = string(b-'0', a);
    if(a > b){
        res = string(a-'0', b);
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 384
def cal_a(a_prev):
    """Calculate a[i] when i > 1, according to below formula
    f(n) = n/2 if n is even, and f(n) = 3n + 1 if n is odd.
    """
    return a_prev // 2 if a_prev % 2 == 0 else a_prev * 3 + 1

a_cur = int(input())
found = {}
index = 1
while a_cur not in found:
    found[a_cur] = index
    a_cur = cal_a(a_cur)
    index += 1

print(index)

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main(){
    long long A, B, K; cin >> A >> B >> K;
    if(A < K){
        long long X = K-A;
        A = 0;
        B = B - X;
        if(B < 0){
            cout << 0 << " " << 0;
        }
        else cout << A <<" " << B << endl;

    }
    else{
        cout << A-K << " " << B << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP2(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(v) (v).begin(),(v).end()
#define INF 2e9
typedef long long ll;

int main()
{
  int n,k,r,s,p;
  string t;
  cin>>n>>k>>r>>s>>p>>t;

  int score=0;
  vector<bool> f(n,0);
  REP(i,n){
    if(i>=k && t[i]==t[i-k] && f[i-k]==0){
      f[i]=1;
      continue;
    }
    if(t[i]=='r') score+=p;
    else if(t[i]=='s') score+=r;
    else if(t[i]=='p') score+=s;
  }

  cout<<score<<endl;

  return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>
#define PI 3.141592653589793238462643383279


void change(int *x, int *y){
	int z;
	z = *x;
	*x = *y;
	*y = z;
}
int compare_int(const void *a, const void *b){
	return *(int*)a - *(int*)b;
}

int gcd(int a, int b)
{
    int c;
    if (a < b) {
        a+=b; b=a-b; a-=b;
    }
    while (b != 0) {
        c = a % b;
        a = b;
        b = c;
    }
    return a;
}
int main(void){	
	int n, x;
  scanf("%d %d", &n, &x);
  int l[n];
  for(int i=0;i<n;i++){
    scanf("%d", &l[i]);
  }
  int z = 0;
  int ans=1;
  for(int i=0;i<n+1;i++){
    z+=l[i];
    if(z>x){
      ans+=i;
      break;
    }
    if(i==n)	ans+=i;
  }
  printf("%d", ans);
	
			
	return 0;
}

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

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n)  FOR(i, 0, n)
#define ASC(c) sort((c).begin(), (c).end())
#define DESC(c) sort((c).begin(), (c).end(), greater<int>())

#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

typedef long long ll;
typedef unsigned long long ull;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
    ll w, h, x, y; cin >> w >> h >> x >> y;
    int ans = 0;
    if ((2 * x == w) && (2 * y == h)) ans = 1;
    printf("%lf %d\n", double(w) * double(h) / 2, ans);
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int a,b,i,ans=0;
  scanf("%d%d",&a,&b);
  for(i=0;i<2;i++){
    if(a>b){
      ans+=a;
      a--;
    }
    else{
      ans+=b;
      b--;
    }
  }
    printf("%d",ans);
    return 0;
  }

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#define REP(i, a, b) for(i = a; i < b; i++)
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

string s;

signed main() {
	int i, j, k;
	
	cin >> s;
	if (s == "keyence") {
		cout << "YES" << endl;
		return 0;
	}
	
	for (i = 0; i < s.length(); i++) {
		for (j = i; j < s.length(); j++) {
			string t;
			for (k = 0; k < s.length(); k++) {
				if (i <= k && k <= j) continue;
				t += s[k];
			}
			if (t == "keyence") {
				cout << "YES" << endl;
				return 0;
			}
		}
	}
	cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<string>
#include<vector>
#include<iostream>
# define ll int64_t
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl
using namespace std;

bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) (x*=i)%=mod;
    return x;
}

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

ll lcm(ll a,ll b)
{
   return a/gcd(a,b)*b;
}

//累乗だってさ
ll modpow(ll a,ll n,ll mod1) {
    ll res=1;
    while(n>0){
        if(n&1) res=res*a%mod1;
        a = a*a%mod1;
        n >>= 1;
    }
    return res;
}
//逆元だってさ
ll modinv(ll a,ll mod1) {
    return modpow(a, mod1 - 2, mod1);
}

const ll MAX = 1000000;
const ll MOD = 1000000007;

ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n,m;
    cin>>n>>m;
    vector<ll> a(n+1),dp(n+10,0),b(n+1,true);
    rep(i,m) {
        ll c;
        cin>>c;
        b[c]=false;
    }
    rep(i,n) a[i]=i;
    dp[0]=1;
    if(b[1]==true) dp[1]=1;
    else dp[1]=0;
    for(ll i=2;i<=n;i++) {
        if(b[i]) dp[i]=(dp[i-1]+dp[i-2])%mod;
    }
    cout<<dp[n]%mod<<endl;
    return 0;
}


Measured memory_bytes: 2560
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
const int INF = 1e9;
const long long LINF = 1e18;


int main(){
  int N,K;cin >> N >> K;
  vector<int> x(N);
  for(int i = 0; i < N; i++){
    cin >> x[i];
  }
  int ans = 0;
  int time1 = 0;
  int minTime1 = INF;
  int time2 = 0;
  int minTime2 = INF;
  if(x[N-1] <= 0){
      ans = -x[N-K];
  }
  else if(x[0] >= 0){
      ans = x[K-1];
  }
  else{
    for(int i = 0; i < N-K+1; i++){
      time1 = abs(x[i])*2 + abs(x[i+K-1]);
      minTime1 = min(minTime1,time1);
      time2 = abs(x[i]) + abs(x[i+K-1])*2;
      minTime2 = min(minTime2,time2);

    
    }
    ans = min(minTime1,minTime2);
  }
  
  cout << ans <<endl;

}



Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
/*
また論理積とか
1,1で終わる bit和とか
和積排bit
1 1 0 2   1,1=B
2 0 2 3   1,2= 1,1= A
1 1 0 4   2,2= 0,3= 1,1= B
2 1 1 5   2,3= 3,1= 2,1= 1,1= A
2 1 1 3   1,3= 1,2= 1,1= B
2 0 2 2   1,4= 1,3= 1,2= 1,1= A

ああ、ルールちがうな･･･
1 1 0 2   1,1=B
2 0 2 3   1,2= 2,0= 1,1= B
1 1 0 4   2,2= 0,3= 1,1= B
2 1 1 5   2,3= 0,4= 1,2= 2,0= 1,1=B
2 1 1 5   2,3= 0,4= 2,0= 0,1= Axx
2 1 1 5   2,3= 3,1= 1,2= 2,0= 1,1=B
2 0 2 2   1,4= 2,2= A
2 0 2 2   1,4= 3,0= 1,1=Bxx

|X-Y|<=1を受けたほうがまけ。
だけど0,0 0,1 1,0 1,1だったらB
*/
int main(){
  ll X,Y; cin>>X>>Y;
  if(X+Y<=1 || abs(X-Y)<=1){
    cout<<"Brown"<<endl;
    return 0;
  }
  cout<<"Alice"<<endl;
}

Measured memory_bytes: 256
sx,sy,tx,ty = map(int,input().split())
ans = ""

#座標の差分
dx = tx - sx
dy = ty - sy

#s->t(1回目)
for i in range(dx):
    ans += "R"
for i in range(dy):
    ans += "U"
#t->s(2回目)
for i in range(dx):
    ans += "L"
for i in range(dy):
    ans += "D"

#s->t(2回目)
ans += "D"
for i in range(dx+1):
    ans += "R"
for i in range(dy+1):
    ans += "U"
ans += "L"
#t->s(2回目)
ans += "U"
for i in range(dx+1):
    ans += "L"
for i in range(dy+1):
    ans += "D"
ans += "R"

print(ans)

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

int main(){// 連鎖の結果,少ない方の色は全部消える
  string str;
  cin >> str;
  int Nb= 0;
  int Nr= 0;
  for(int i=0; i<str.size(); i++){
    if(str.at(i)=='1') Nb++;
    else               Nr++;
  }

  cout << 2*min(Nb, Nr) << endl;
}

Measured memory_bytes: 512
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        long k = sc.nextLong();
        long a = sc.nextLong();
        long b = sc.nextLong();
        if((b-a) <= 2){
            pw.println(k+1);
        }else{
            long first = a-1;
            if(k <= first){
                pw.println(k+1);
            }else{
                long pow = (k-first)/2;
                long mod = (k-first)%2;
                pw.println(a+(b-a)*pow+mod);
            }
        }
        pw.flush();
    }

    static class GeekInteger {
        public static void save_sort(int[] array) {
            shuffle(array);
            Arrays.sort(array);
        }
 
        public static int[] shuffle(int[] array) {
            int n = array.length;
            Random random = new Random();
            for (int i = 0, j; i < n; i++) {
                j = i + random.nextInt(n - i);
                int randomElement = array[j];
                array[j] = array[i];
                array[i] = randomElement;
            }
            return array;
        }
 
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
    }
    
    public String[] nextArray(int n) {
        String[] a = new String[n];
        for (int i = 0; i < n; i++)
            a[i] = next();
        return a;
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}


Measured memory_bytes: 32960
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>

using namespace std;
typedef long long ll;
int N;
ll K;
vector<ll> arr;

int main(){
	scanf("%d%lld", &N, &K);
	for(int i=0; i<N; i++){
		ll x;
		scanf("%lld", &x); arr.push_back(x);
	}
	ll two = 1;
	ll ans = 0;
	for(int i=0; i<50; i++)	two*=2;
	for(int i=50; i>=0; i--){
		int cnt = 0;
		for(int i=0; i<arr.size(); i++){
			if((two&arr[i])!=0)	cnt++;
		}
		if(cnt<(N-cnt)){
			if(ans+two<=K){
				ans+=two;
			}
		}
		two/=2;
	}//cout<<ans<<endl;
	ll answer = 0;
	for(int i=0; i<N; i++){
		answer += (ans^arr[i]);
	}
	printf("%lld", answer);
	return 0;
}

Measured memory_bytes: 1400
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std, core.bitop;
// dfmt on

void main()
{
    long N, K;
    scan(N, K);
    long ans;
    foreach (k; K .. N + 2)
    {
        long m = k * (k - 1) / 2;
        long M = N * (N + 1) / 2 - (N - k + 1) * (N - k) / 2;
        ans += max(M - m + 1, 0);
        ans %= 1000000007;
    }
    writeln(ans);
}


Measured memory_bytes: 3692
#include<iostream>
using namespace std;
int main(){
    int W,H,x,y,r;
    cin >> W>>H>>x>>y>>r;

    if(x<W && y<H){
        if(x+r<=W && x-r>=0 && y+r<=H && y-r>=0){
            cout << "Yes\n";
        }
        else{
            cout << "No\n";
        }
    }
    else{
        cout << "No\n";
    }
}

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

#define LL                      long long
#define Ulong                   unsigned long long
#define REP(i,n)                for(long long i=0; i < n ; i++ )
#define mp                      make_pair
#define pb                      push_back
#define all(x)                  (x).begin(),(x).end()
#define PI                      acos(-1.0)
#define EPS                     1e-14
#define F                       first
#define S                       second
#define di(x)                   int x; input(x)
#define in(x)                   input(x)
#define in2(x,y)                in(x),in(y)
#define in3(x,y,z)              in(x),in2(y,z)
#define lc                      ((n)<<1)
#define rc                      ((n)<<1|1)
#define db(x)                   cout << #x << " -> " << x << endl
#define nl                      cout<<endl
#define ms(ara_name,value)      memset(ara_name,value,sizeof(ara_name))
#define IO                      ios_base::sync_with_stdio(0);cin.tie(0)
#define READ                    freopen("/home/matrixcode/Desktop/in.txt","r",stdin)
#define WRITE                   freopen("out.txt","w",stdout)
template<class T> inline void input(T &x) {
  register char c = getchar();x = 0;
  int neg = 0;
  for(; ((c<48 || c>57) && c != '-'); c = getchar());
  if(c=='-'){neg = 1;c = getchar();}
  for(; c>47 && c<58 ; c = getchar()){x = (x<<1) + (x<<3) + c - 48;}
  if(neg) x = -x;
}
inline long long bigmod(long long p,long long e,long long M){
  long long ret = 1;
  for(; e > 0; e >>= 1){
    if(e & 1) ret = (ret * p) % M;
    p = (p * p) % M;
  } return ret;
}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}

/***************************** END OF TEMPLATE *******************************/

const int N = 3e3+5;

double dp[N][N];
double p[N];

int main()
{
  int n;
  in(n);
  for(int i = 1; i <= n; i ++) cin >> p[i];

  dp[0][0] = 1;
  for(int i = 1; i <= n; i ++) {
    for(int j = 0; j < i; j ++) {
      int h = j;
      int t = i - 1 - h;
      dp[h+1][t] += dp[h][t] * p[i];
      dp[h][t+1] += dp[h][t] * (1- p[i]);
    }
  }
  double sum = 0;
  for(int i = 1; i <= n; i ++) {
    int j = n - i;
    if(i > j)  sum += dp[i][j];
  }
  printf("%.15lf", sum );
}


Measured memory_bytes: 70016
#include<iostream>
#include<string>
using namespace std;
int main()
{
	string s, t;
	int a, b;
	cin >> s >> t;
	cin >> a >> b;
	string u;
	cin >> u;
	if (s == u) {
		a--;
	}
	else {
		b--;
	}
	cout << a << " " << b << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>/*{{{*/
#include <bits/stdc++.h>
#define rep(i, x) for(int i = 0; i < (int)(x); i++)
#define reps(i,x) for(int i = 1; i <= (int)(x); i++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define RFOR(i, m, n) for(int i = m;i >= n;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define fill(x,y) memset(x,y,sizeof(x))
#define pb(a) push_back(a)
#define debug(x)                 cerr << __LINE__ << ": " << #x << " -> " << x << '\n'
#define debug2(x, y)             cerr << __LINE__ << #x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define debug3(x, y, z)          cerr << __LINE__ << #x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define debug4(a, b, c, d)       cerr << __LINE__ << #a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define debug5(a, b, c, d, e)    cerr << __LINE__ << #a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define debug6(a, b, c, d, e, f) cerr << __LINE__ << #a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define INF 999999999
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef vector<vii> vvii;
typedef tuple<int,int,int> iii;
typedef set<int> si;
typedef complex<double> pnt;
typedef vector<pnt> vpnt;
typedef priority_queue<pii,vii,greater<pii> > spq;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};/*}}}*/

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

  int n,l;cin>>n>>l;
  string s[n];
  rep(i,n)cin>>s[i];
  sort(s, s+n);

  rep(i,n)cout<<s[i];
  cout << endl;

  return 0;
}


Measured memory_bytes: 256
import math

a, b, C = map(int, input().split())

S = (a*b*math.sin(math.radians(C)))/2
c = math.sqrt(a**2+b**2-2*a*b*math.cos(math.radians(C)))
L = a + b + c
h = b*math.sin(math.radians(C))

print(f'{S:.8f}')
print(f'{L:.8f}')
print(f'{h:.8f}')


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;





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

    int res = 0;


    auto count = [&](string s) {
	int n = s.length();
	int res = 0;
	for (int i=0; i+1<n; i++) {
	    if (s[i]=='A' && s[i+1]=='B') res++;
	}
	return res;
    };

    int n;
    cin>>n;
    int A = 0; //...A
    int B = 0; //B...
    int BA = 0;
    while (n--) {
	string s;
	cin>>s;
	res += count(s);
	if (s[0]=='B' && s.back()=='A') {
	    BA++;
	} else if (s[0]=='B') {
	    B++;
	} else if (s.back()=='A') {
	    A++;
	}
    }


    bool aloaded = false;
    while (true) {
	if (!aloaded) {
	    if (A>0) {
		aloaded = true;
		A--;
	    } else if (BA>0) {
		BA--;
		aloaded = true;
	    } else {
		break;
	    }
	} else {
	    if (BA>0) {
		res++;
		BA--;
		aloaded = true;
	    } else if (B>0) {
		res++;
		B--;
		aloaded = false;
	    } else {
		break;
	    }
	}
    }

    cout<<res<<endl;    
    return 0;
}


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

void Main() {
	int A, B, C, X;
	cin >> A >> B >> C >> X;
	int ans = 0;
	for(int a = 0; a <= A; a++)
		for(int b = 0; b <= B; b++)
			for (int c = 0; c <= C; c++) {
				if (500 * a + 100 * b + 50 * c == X) ans++;
			}
	cout << ans << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	Main();
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace MyProject
{
    class Program
    {
        static void Main(string[] args)
        {
#if Local
            var sw = new Stopwatch();
            sw.Start();
            Console.SetIn(new StreamReader("input.in"));
#endif

            var solver = new Solver();
            solver.Solve();
#if Local
            Console.WriteLine($"{sw.ElapsedMilliseconds}ms");
#endif
        }
    }

    class Solver
    {
        public void Solve()
        {
            var N = int.Parse(Console.ReadLine());
            var answer = 0;
            while (true)
            {
                if (N <= 0)
                {
                    break;
                }

                N -= 2;
                answer++;
            }

            Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 13140
#include<iostream>
#include<algorithm>
#include<cstring>
#include<stack>
using namespace std;
typedef long long ll;
#define N 1005

int main(){
    int n;
    cin>>n;
    n=-n;
    while(n<0){
        n+=1000;
    }
    cout<<n;
    return 0;
}


Measured memory_bytes: 3644
#include <cstdio>
typedef long long ll;

ll ans[55];
int n;
/*bool check(ll lim)
{
	ll btm=n-1-lim;
	ll res=0;
	for(int i=1;i<=n;i++)
		if(ans[i]>btm)
			res+=(ans[i]-btm-1)/(n+1)+1;
	printf("res %lld lim %lld\n",res,lim);
	return res>=lim;
}
*/

int main()
{
	scanf("%d\n",&n);
	for(int i=1;i<=n;i++)
		scanf("%lld",&ans[i]);
	ll res=0;
	while(1)
	{
		int flag=0;
		for(int i=1;i<=n;i++)
			if(ans[i]>=n)
			{
				flag=1;
				ll mns=ans[i]/n;
				res+=mns;
				ans[i]%=n;
				for(int j=1;j<=n;j++)
					if(i!=j)
						ans[j]+=mns;
//				break;
			}
		if(!flag) break;
	}
	printf("%lld\n",res);
/*	ll l=0,mid;
	while(l<r-1)
	{
		mid=(l+r)>>1;
		if(check(mid)) r=mid;
		else l=mid;
	}
	printf("%lld\n",l);
	*/
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
        int t = sc.nextInt();
        while (t > 0) {
            int n = sc.nextInt();
            Map<Integer, ArrayList<Camel>> map = new HashMap<>();
            for (int i = 0; i < n; i++) map.put(i, new ArrayList<>());
            Camel[] c = new Camel[n];
            long base = 0;
            for (int i = 0; i < n; i++) {
                int split = sc.nextInt();
                long l = sc.nextInt();
                long r = sc.nextInt();
                c[i] = new Camel(l - r, split - 1);
                map.get(c[i].split).add(c[i]);
                base += Math.min(l, r);
            }
            Arrays.sort(c, Comparator.comparingInt(a -> a.split));
            PriorityQueue<Long> pq = new PriorityQueue<>();
            for (int i = 0; i < n; i++) {
                for (Camel camel : map.get(i)) {
                    if (camel.dif < 0) continue;
                    pq.add(camel.dif);
                    base += camel.dif;
                }
                while (pq.size() > i + 1) {
                    long bestRemove = pq.poll();
                    base -= bestRemove;
                }
            }
            pq = new PriorityQueue<>();
            for (int i = n - 1; i >= 0; i--) {
                for (Camel camel : map.get(i)) {
                    if (camel.dif >= 0) continue;
                    pq.add(-camel.dif);
                    base += -camel.dif;
                }
                while (pq.size() > n - i - 1) {
                    long bestRemove = pq.poll();
                    base -= bestRemove;
                }
            }
            out.println(base);
            t--;
        }
        out.close();
    }

    static class Camel {
        long dif; int split;
        Camel(long dif, int split) {
            this.dif = dif; this.split =split;
        }
    }


    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }


    }

}

Measured memory_bytes: 88488
N, M = map(int, input().split())
INF = 10 ** 9
dist = [[INF]*N for _ in range(N)]
for i in range(N):
    dist[i][i] = 0

mem = []
for i in range(M):
    a, b, c = map(int, input().split())
    a, b = a-1, b-1
    mem.append((a,b,c))
    dist[a][b] = c
    dist[b][a] = c

for k in range(N):
    for i in range(N):
        for j in range(N):
            dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j])

ans = 0

for i in range(M):
    a, b, c = mem[i]
    if c != dist[a][b]:
        ans += 1

print(ans)


Measured memory_bytes: 3424
#include <bits/stdc++.h>
    using namespace std;
    typedef long long lint;
    typedef pair<int,int> pint;
    typedef vector<int> vint;
    #define rep(i, n) for(int i = 0; i < n; i++)
    #define rep2(elem, vec) for(auto elem: vec)
    #define SORT(V) sort((V).begin(),(V).end())
    #define RSORT(V) sort((V).rbegin(), (V).rend())
    lint gcd(int a,int b){return b?gcd(b,a%b):a;}
    lint lcm(int a,int b){return a*b/gcd(a,b);}
    lint comb(int a,int b){return b?comb(a-1,b-1)*a/b:1;}
    int dx[4] ={1,0,-1,0},dy[4] = {0,1,0,-1};
    int MOD = 1e9+7;

int main(){
    int H,N;
    cin >> H >> N;
    int A,S=0;
    rep(i,N){
        cin >> A;
        S+=A;
    }
    if(S<H)cout << "No";
    else cout << "Yes";
    return 0;
}


Measured memory_bytes: 256
import math

x=int(input())

ans=0
if 400<= x and x<=599:
	ans=8
if 600<=x and x<=799:
	ans=7
if 800<=x and x<=999:
	ans=6
if 1000<=x and x<=1199:
	ans=5
if 1200<=x and x<=1399:
	ans=4
if 1400<=x and x<=1599:
	ans=3
if 1600<=x and x<=1799:
	ans=2
if 1800<=x and x<=1999:
	ans=1
print(ans)

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

int main(){
  int N;
  scanf("%d",&N);
  vector<int64_t> luka(N+1,0LL);
  luka.at(0)=2LL;
  luka.at(1)=1LL;
  for(int i=0;i<N-1;i++){
    luka.at(i+2)=luka.at(i)+luka.at(i+1);
  }
  printf("%ld",luka.at(N));
}

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

int main() {
  
  string s, t;
  cin >> s >> t;
  
  int ans = 0;
  REP(i,s.size()) {
    if (s[i] != t[i]) ans++;
  }    
  
  cout << ans << endl;
  
}


Measured memory_bytes: 3916