akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
using namespace std;

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

const int MAX = 210000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int 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;
    }
}
long long COM(int n, int 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() {
    int N, M;
    COMinit();
    cin >> N >> M;
    auto vec = prime_factorize(M);
    long long res = 1;
    for (auto pa : vec) {
        int num = pa.second;
        long long tmp = COM(num+N-1, N-1);
        res = (res * tmp) % MOD;
    }
    cout << res << endl;
}          

Measured memory_bytes: 5120
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
typedef long long ll;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
typedef vector<vector<char>> vvc;
typedef vector<char> vc;
typedef pair<ll,ll> pll;
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
  return x+y-max(x,y);
}


int main() {
  string s;
  cin >> s;
  int n=s.size();
  ll m=100000;
  rep(i,n-2){
    string t;
    int l=100*(s[i]-'0')+10*(s[i+1]-'0')+s[i+2]-'0';
    l-=753;
    if(l<0)l*=-1;
    m=min(l,m);
  }
  cout << m << endl;
}

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

int main() {
	int train_normal, train_unlimited, bus_normal, bus_unlimited;
	cin >> train_normal >> train_unlimited >> bus_normal >> bus_unlimited;
	int train_budget = 0, bus_budget = 0;
	train_normal < train_unlimited ? train_budget = train_normal : train_budget = train_unlimited;
	bus_normal < bus_unlimited ? bus_budget = bus_normal : bus_budget = bus_unlimited;
	cout << train_budget + bus_budget << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
long N, X;
long A[2000];
long T[2000];

int main() {
  cin >> N >> X;
  for(int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  
  long ans = 1ll << 62;
  fill(T, T + N, 1ll << 62);
  
  for(int i = 0; i < N; ++i) {
    long sub = X * i;
    for(int j = 0; j < N; ++j){
      sub += T[j] = min(T[j], A[(i + j) % N]);  
    }
    ans = min(ans, sub);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
using System;

class Program {
  static void Main() {
    var s = Console.ReadLine();
    int a = 0, z = 0;
    for (int i = 0; i < s.Length; i++) {
      if (s[i] == 'A') {
        a = i;
        break;
      }
    }
    for (int i = s.Length - 1; i >= 0; i--) {
      if (s[i] == 'Z') {
        z = i;
        break;
      }
    }
    Console.WriteLine(z - a + 1);
  }
}

Measured memory_bytes: 11616
from collections import deque
N, K = map(int, input().split())
V = list(map(int, input().split()))
R = min(N, K)
ans = 0
for A in range(R+1):
    for B in range(R+1):
        d = deque(V)
        if A + B > R:
            continue
        x = []
        for _ in range(A):
            if 0 < len(d):
                x.append(d.popleft())
        for _ in range(B):
            if 0 < len(d):
                x.append(d.pop())
        x.sort()
        drop = K - (A + B)
        for _ in range(drop):
            if 0 < len(x) and x[0] < 0:
                x.pop(0)
        ans = max(ans, sum(x))
print(ans)

Measured memory_bytes: 3316
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]

sa = sum(a)

for i,b in enumerate(b):
	c = min(a[i],b)
	a[i] -= c
	a[i+1] -= min(a[i+1],b-c)

print(sa-sum(a))

Measured memory_bytes: 19648
#include<bits/stdc++.h>
using namespace std;
#define int long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
// #define MOD 998244353 
#define MEM_SIZE 100010
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }




void solve(void)
{
  int H,W;
  cin>>H>>W;
  vector<vector<char> > MAZE(H,vector<char>(W));
  pair<int,int> START,GOAL;
  int cnt_w = 0;
  for (int h = 0; h < H; h++)
  {
    for (int w = 0; w < W; w++)
    {
      cin>>MAZE[h][w];
      if(MAZE[h][w] == 'S')
      {
        START.first = h;START.second=w;
        MAZE[h][w] = '.';
      }

      if(MAZE[h][w] == 'G')
      {
        GOAL.first = h;GOAL.second=w;
        MAZE[h][w] = '.';  
      }
      if(MAZE[h][w] =='.')cnt_w++;      
    }
  }
  START = make_pair(0,0);
  GOAL = make_pair(H-1,W-1);
  vector<int> dx = {1,0,-1,0};
  vector<int> dy = {0,1,0,-1};
  vector<vector<int> > dist(H,vector<int>(W,INF));

  queue<pair<int,int> > q;
  q.push(START);
  dist[START.first][START.second] = 0;
  while(! q.empty())
  {
    pair<int,int> point = q.front();
    q.pop();
    if(point == GOAL) break;

    for (int i = 0; i < 4; i++)
    {
      int nx = point.second + dx[i];
      int ny = point.first + dy[i];
      if(nx >= 0 && ny >= 0 && nx < W && ny <H && MAZE[ny][nx] != '#' &&dist[ny][nx] == INF)
      {
        q.push(pair<int,int>(ny,nx));
        dist[ny][nx] = dist[point.first][point.second] + 1;
      }
    }
  }
    
  int C = dist[GOAL.first][GOAL.second];
  if(C >= INF)
  {
    cout<<-1<<endl;
    return;
  }
  C++;
  cout<<cnt_w - C<<endl;
  return;
}
int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(11);
  solve();

  return 0;
}


Measured memory_bytes: 3668
from collections import deque


def solve(S, s):
    if S[s[0]][s[1]] != ".":
        return -1
    queue = deque([s])
    visited = [[-1 for _ in range(W)] for _ in range(H)]
    visited[s[0]][s[1]] = 0
    while queue:
        y, x = queue.popleft()
        for j, k in ([1,0], [-1,0], [0,1], [0,-1]):
            new_y, new_x = y+j, x+k
            if new_x in range(W) and new_y in range(H) and S[new_y][new_x] == "." and visited[new_y][new_x] == -1:
                visited[new_y][new_x] = visited[y][x] + 1
                queue.append([new_y, new_x])
#    for v in visited:
#        print(v)
    return max(map(max,visited))


H, W = map(int, input().split())
S = [input() for _ in range(H)]
ans = -1
for i in range(H):
    for l in range(W):
        ans = max(ans, solve(S, [i, l]))
print(ans)


Measured memory_bytes: 46316
import sys
input = lambda: sys.stdin.readline().rstrip()

n,q = map(int, input().split())

parents = [-1] * n

def find(x):
    if parents[x] < 0:
        return x
    else:
        parents[x] = find(parents[x])
        return parents[x]

def union(x,y):
    x = find(x)
    y = find(y)

    if x == y:
        return

    if parents[x] > parents[y]:
        x,y = y, x

    parents[x] += parents[y]
    parents[y] = x     

def same(x,y):
    return find(x) == find(y)

for i in range(q):
    com,x,y = map(int, input().split())

    if com == 0:
        union(x, y)
    else:
        if same(x, y):
            print(1)
        else:
            print(0)        



Measured memory_bytes: 6424
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<(n);i++)
#define Rep(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define eb emplace_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n;
    cin>>n;
    vi x(n),l(n);
    rep(i,n)cin>>x[i]>>l[i];
    vp a(n);
    rep(i,n)a[i]=pi(x[i]+l[i],x[i]-l[i]);
    SORT(a);
    int ans=0;
    int m=-inf;
    rep(i,n){
        if(m<=a[i].se){
            ans++;
            m=a[i].fi;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin>>n>>k;
  int h[n+1];
  h[0]=0;
  for(int i=1;i<=n;i++) cin>>h[i];
  long long int cost[n+1];
  for(int i=0;i<=n;i++) cost[i]=1000000000;
  cost[0]=0;
  cost[1]=0;
  for(int i=2;i<=n;i++){
    for(int j=1;j<=k;j++){
      if(i-j>=1) cost[i]=min(cost[i],cost[i-j]+abs(h[i]-h[i-j]));
    }
  }
  cout<<cost[n];
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int n,a[100002][27],start=0,end=0;
int main(){
	string s;
	cin>>s;
	n=s.size();
	for(int i=1;i<n;i++){
		if(s[i]==s[i-1]){
			cout<<i<<" "<<i+1;
			return 0;
		}
	}
	for(int i=2;i<n;i++){
		if(s[i]==s[i-2]){
			cout<<i-1<<" "<<i+1;
			return 0;
		}
	}
	cout<<"-1 -1";
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = numeric_limits<int>::max() /4;
const ll linf = numeric_limits<ll>::max() /4;
const ull ulinf = numeric_limits<ull>::max()/4;
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 P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); 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) sort(v.end(), v.begin());
#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);}

///////////////////////////////////////////////////////////////////////////



int main(){
    string s;
    cin >> s;
    int c = 0;
    rep(i,0,sz(s))if(s[i] == '1')c++;
    P(c);
	return  0;
}

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

#define flin            freopen("input.txt", "r", stdin); 
#define flout           freopen("output.txt", "w", stdout);
#define ll              long long
#define ull             unsigned long long
#define fastio          ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define nl              '\n'
#define nll             '\0'
#define pb              push_back
#define bdyptb          return 0;
#define sorted(x)       sort(x.begin(), x.end())
#define reversed(x)     reverse(x.begin(), x.end())
#define all(x)          x.begin(), x.end()
#define mset(a, b)      memset(a, b, sizeof(a));
#define testcase        ll t,tt; cin>>tt; for(t=1;t<=tt;t++)

#define pi acos(-1.00)   
#define mx 1000007

using namespace std;
int gcd(int x,int y)
{        
    return x ? gcd(y%x,x) : y;   
}  

int main()
{
    fastio;
    int n;
    cin>>n;
    int p[n+1];
    for(int i=1; i<=n; i++)
    cin>>p[i];
    int x=n+1;
    int a[n+1],b[n+1];
    for(int i=1; i<=n; i++)
    {
        a[i]=(i*x);
        b[i]=((n-i)*x);
    }

    for(int i=1; i<=n; i++)
    b[p[i]]+=i;


    for(int i=1; i<=n; i++)
    cout<<a[i]<<' ';
    cout<<nl;
    
    for(int i=1; i<=n; i++)
    cout<<b[i]<<' ';
    cout<<nl;

    bdyptb;
}

Measured memory_bytes: 3864
#include <stdio.h>
#include <algorithm>
using namespace std;
int main(){
	char c, a;
	scanf("%c",&c);
	switch(c){
		case 'A':
			a='T';
			break;
		case 'T':
			a='A';
			break;
		case 'G':
			a='C';
			break;
		case 'C':
			a='G';
			break;
	}
	printf("%c",a);
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Main mainObj = new Main();
		mainObj.exec();
	}
	
	public void exec() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.close();
		
		for(int i = 1; i <= 9; i++) {
			
			if(n % i == 0) {
				if((n / i) < 10) {
					System.out.println("Yes");
					return;
				}
			}
		}
		
		System.out.println("No");
			
	}
}

Measured memory_bytes: 23124
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, n)       for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, s, t)   for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(Type, ...)  Type __VA_ARGS__; input(__VA_ARGS__)
#ifndef DBG
#define trace(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
inline i64  sigma(i64 n)            { return (n * (n + 1) >> 1); }
inline i64  updiv(i64 a, i64 b)     { return (a + b - 1) / b; }
inline i64  sqr(i64 n)              { return n * n; }
inline string to_string(char c)     { return string(1, c); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> make_v(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}
template <class T, class... Args>
inline auto make_v(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initValue, args...))>(sz, make_v<T>(initValue, args...));
}

inline void input() {}
template <class Head, class... Tail>
inline void input(Head &head, Tail&... tail) { cin >> head; input(tail...); }

inline void print() { cout << "\n"; }
template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &out, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) out << e << delim[&e == &vec.back()];
    return out;
}

template <typename Func>
struct FixPoint : Func {
    inline constexpr FixPoint(Func &&f) noexcept : Func(forward<Func>(f)) {}

    template <typename... Args>
    inline decltype(auto) operator()(Args &&... args) const {
        return Func::operator()(*this, forward<Args>(args)...);
    }
};

template< typename Func >
inline decltype(auto) makeFixPoint(Func &&f) {
    return FixPoint< Func >{forward< Func >(f)};
}
// }}} End Header

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

    var(string, s);

    bool yes = true;

    rep(i, s.length()) {
        const char c = s[i];
        if ((i + 1)  & 1) {
            yes &= (c != 'L');
        } else {
            yes &= (c != 'R');
        }
    }

    print((yes) ? "Yes" : "No");

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

main()
{
	int a, b, c, d;
	int p, q; // times of tolerance, player p and q

	scanf("%d %d %d %d", &a, &b, &c, &d);
	p = (a + d - 1) / d;
	q = (c + b - 1) / b;
	if(p >= q) {
		printf("Yes");
	} else {
		printf("No");
	}
}

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

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

	string ans = "";
	for (int i = 0; i < 3; i++)
	{
		ans += n[0];
	}

	if (ans >= n)
	{
		cout << ans;
	}
	else
	{
		for (int i = 0; i < 3; i++)
		{
			cout << (ans[i] - '0') + 1;
		}
	}
	cout << endl;
}

Measured memory_bytes: 256
#include<cassert>
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#define FL "a"
using namespace std;
typedef long long ll;
const int N=1e6+10;
const int mod=1e9+7;
inline ll read(){
  ll d=0,w=1;char ch=getchar();
  while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
  if(ch=='-')w=-1,ch=getchar();
  while(ch<='9'&&ch>='0')d=d*10+ch-48,ch=getchar();
  return d*w;
}
inline void file(){
  freopen(FL".in","r",stdin);
  freopen(FL".out","w",stdout);
}

int n,t[26],ans;char s[N];
inline void upd(int &a,int b){a+=b;if(a>=mod)a-=mod;}
inline void dec(int &a,int b){a-=b;if(a<0)a+=mod;}
int main()
{
  n=read();scanf("%s",s+1);ans=1;
  for(int i=1;i<=n;i++)upd(t[s[i]-'a'],1);
  for(int i=0;i<26;i++)ans=1ll*(t[i]+1)*ans%mod;
  dec(ans,1);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 384
n=int(input())
A=list(map(int,input().split()))
choice=[0]*n
ans=[]
cnt=0
for i in range(n-1,-1,-1):
    a=i+1
    c=0
    a+=i+1
    while a<=n:
        c+=choice[a-1]
        a+=i+1
    if c%2!=A[i]:
        choice[i]+=1
        ans.append(i+1)
        cnt+=1
if cnt==0:
    print(0)
else:
    print(cnt)
    ans.sort()
    print(*ans, sep=' ')

Measured memory_bytes: 14116
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
#include <map> 
#include <set>
#include <string>
#include <functional>
#include <list>
#include <random>
#include <time.h>
#include <iomanip>
#include <assert.h>
#include <numeric>
#define int long long
#define double long double
#define oku7 1000000007
#define MAXN (int)1e+5 * 2+1
#define LL_MAX 9223372036854775807	//ない環境用
#define LL_HALFMAX 9223372036854775807 / 2	//ない環境用

using namespace std;
std::mt19937 mt((int)time(0));

int dx[4] = { 0, 1, 0, -1 }; // x軸方向への変位
int dy[4] = { 1, 0, -1, 0 }; // y軸方向への変位

int x[101], y[101], h[101];

int a[2001], b[2001][2001], sum[100001];
signed main() {
	int N, x;
	cin >> N >> x;
	int ans = 0;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
		b[0][i] = a[i];
		ans += a[i];
	}
	//魔法をk回使うと固定、b[k][i]でk回使うときのi番目のスライムの最小コストを表す
	for (int k = 1; k <= N; k++) {
		int score = 0;
		for (int i = 0; i < N; i++) {
			int before = i - k;
			if (before < 0) before = N + before;
			b[k][i] = min(a[before],b[k - 1][i]);
			score += b[k][i];
		}
		ans = min(ans, score + x * k);
	}
	cout << ans << "\n";


	return 0;
}

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

int main() {
  int N;   cin >> N;
  vector<int> L(N);
  for(int i = 0; i<N; i++){
    cin >> L[i];
  }int ans=0;
  for(int i=0; i<N-2; i++){
    for(int j =i+1; j<N-1; j++){
      for(int k=j+1; k<N; k++){
        if(max({L[i],L[j],L[k]})*2<L[i]+L[j]+L[k]){
          ans++;
        }
      }
    }
  }cout << ans << endl;
}
 
      

  

Measured memory_bytes: 256
n,m,l = map(int, tuple(input().split(' ')))
A = [[int(s) for s in input().split(' ')] for _ in range(n)]
B = [[int(s) for s in input().split(' ')] for _ in range(m)]
rslt = []
for i in range(n):
	wl = []
	for j in range(l):
		wa = 0
		for k in range(m):
			wa += A[i][k] * B[k][j]
		wl.append(wa)
	rslt.append(wl)
for row in rslt: print(' '.join(map(str, row)))


Measured memory_bytes: 8976
N = int(input())
A = list(map(int, input().split()))

ans = A[0]
for i in range(1,N):
    bns = A[i]
    l = max(ans, bns)
    s = min(ans, bns)
    while l % s != 0:
        l, s = s, l % s
    ans = s

print(ans)


Measured memory_bytes: 14252
#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <cmath>
#include <algorithm>
#include <functional>
inline double dist(int x, int y) {
	return std::sqrt(x * x + y * y);
}
inline double dist(std::pair<int, int> pos) {
	return std::sqrt(pos.first * pos.first + pos.second * pos.second);
}
inline double dist(int x, int y, std::pair<int, int> pos) {
	return std::sqrt((x - pos.first) * (x - pos.first) + (y - pos.second) * (y - pos.second));
}

std::vector<std::pair<int, int>> crystal;
int n, x, y, mx, my;
bool Solve(double day = 0, std::vector<std::pair<int, int>> got = {});
bool isClear = false;
int main()
{
	std::vector<std::string> results;
	while (1) {
		std::cin >> n >> x >> y >> mx >> my;
		if (!x && !y && !n && !mx && !my) break;
		crystal.clear();
		for (int i = 0; i < n; i++) {
			int cx, cy;
			std::cin >> cx >> cy;
			cx -= mx; cy -= my;
			crystal.push_back(std::make_pair(cx, cy));
		}
		x -= mx; y -= my;
		mx = 0; my = 0;
		isClear = false;
		Solve();
		results.push_back(isClear ? "YES" : "NO");
	}

	for (auto& x : results) {
		std::cout << x << std::endl;
	}

	return 0;
}

bool Solve(double day, std::vector<std::pair<int, int>> got)
{
	if (isClear) return true;
	bool ok = false;
	int posX, posY;
	if (got.empty()) {
		posX = x;
		posY = y;
	}
	else {
		posX = got.back().first;
		posY = got.back().second;
	}
	//??¨??£??????????????´?????¨??????????????????????????£?????????
	for (auto& x : crystal) {
		//???????????????????¨????(?????¢???????????????????????????)
		double pass = dist(posX, posY, x);
		double next = day + pass;
		//?????£?????????crystal?????????????????????????????????????????????
		if (next < dist(x)) {
			//??´?°????????????¨??????????¨????
			if (std::find(got.begin(), got.end(), x) == got.end()) {
				got.push_back(x);
				if (got.size() == n) {
					isClear = true;
				}
				ok = ok | Solve(next, got);
			}
		}
	}
	return ok;
}

Measured memory_bytes: 3104
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <cassert>
#include <unordered_map>

#define _(x) { cout << #x << " = " << x << " "; }

const double E = 1e-8;
const double PI = acos(-1);

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a,b,c;
    cin >> a >> b >> c;
    if (a+b+c >= 22) {
        cout << "bust\n";
        return 0;
    }

    cout << "win\n";
    return 0;
}



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

int main (){
  int A,B,C;
  cin >> A >> B >> C;
  
  if(A==B){
    cout << C;
  }
  else if (A==C){
    cout << B;
  }
  else {
    cout << A;
  }
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")

#include <bits/stdc++.h>   
#include <stdio.h>    
 
using namespace std;
     
#define F first
#define S second
#define lb lower_bound               
#define ub upper_bound
#define pb push_back
#define pf push_front    
#define ppb pop_back
#define mp make_pair
#define bpp __builtin_popcountll                                                                                        
#define sqr(x) ((x) * (x)) 
#define al 0x3F3F3F3F
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
//#define int long long
                                    
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
 
const int mod = (int)1e9 + 7;
const int N = (int)2e5 + 123;
const ll inf = (ll)3e18 + 1;

const double pi = acos (-1.0);
const double eps = 1e-7;
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

vector <int> pos[26];
set <pii> t;
char s[N];

inline void boost () {                    
   ios_base :: sync_with_stdio (NULL);
   cin.tie (NULL), cout.tie (NULL);          
}                                                     

inline void Solve () {
   cin >> s + 1;
   int n = strlen (s + 1);
   for (int i = 0; i < 26; i ++) pos[i].pb (-1);
   for (int i = 1; i <= n; i ++) pos[s[i] - 'a'].pb (i);
   for (int c = 0; c < 26; c ++) {
      for (int i = 1; i < sz (pos[c]); i ++) {
         if (sz (t) && t.ub ({pos[c][i] - 2 * i - 1, mod}) != t.end ()) {
            auto it = t.ub ({pos[c][i] - 2 * i - 1, mod});
            cout << pos[c][it -> S] << ' ' << pos[c][i], exit (0);         
         }
         t.in ({pos[c][i] - 2 * i, i});            
      }
      t.clear ();
   }
   cout << "-1 -1";
}                                     

main () {                                       
// freopen (".in", "r", stdin);    
// freopen (".out", "w", stdout);              
   boost ();
   int tt = 1;
// cin >> tt;   
   while (tt --) {
      Solve ();
   }                                               
   return 0;      
}


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

using namespace std;
using ll = long long;

struct C {
    ll N_{};
    vector<pair<ll, ll>> v_{};
    vector<vector<ll>> map_{};
    vector<vector<ll>> t_{};
    vector<ll> num_children_{};
    vector<ll> path_to_N_{};
    bool path_creation_finished_ = false;

    // visit cur from previous prev, count returns # of nodes including cur
    ll dfs(ll prev, ll cur) {
        ll count = 0;
        t_[prev].emplace_back(cur);
        if (!path_creation_finished_) {
            path_to_N_.emplace_back(cur);
            if (cur == N_) {
                path_creation_finished_ = true;
            }
        }
        ll childs{};
        for(ll next : map_[cur]) {
           if (next != prev) {
               count += dfs(cur, next);
           }
        }
        num_children_[cur] = count;
        count++;
        if (!path_creation_finished_) {
            path_to_N_.pop_back();
        }
        return count;
    }
    explicit C(vector<pair<ll, ll>> v) : v_(move(v)){
        N_ = v_.size()+1; // number of nodes
        map_.resize(N_+1); // node number is 1-origin
        t_.resize(N_+1);
        num_children_.resize(N_+1);
        for(auto p : v_) {
            map_[p.first].emplace_back(p.second);
            map_[p.second].emplace_back(p.first);
        }
        dfs(0, 1);
    }
    // true if Feneck wins
    bool resolve() {
        ll L = path_to_N_.size();
        ll sunuke_last_position = path_to_N_[(L+1)/2];
        ll sunukes = 1+num_children_[sunuke_last_position];
        ll fenecks = N_ - sunukes;
        return fenecks > sunukes;
    }
};

int main() {
    ll N;
    cin >> N ;
    vector<pair<ll, ll>> v{};
    for (int i=0; i < N-1; ++i) {
        ll x;
        ll y;
        cin >> x >> y;
        v.emplace_back(make_pair(x,y));
    }
    C c{move(v)};
    cout << (c.resolve() ? "Fennec" : "Snuke") << endl;
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> p(N);
  vector<int> b(N);
  bool can=true;
  for(int i=0;i<N;i++)cin >> b[i];
  for(int i=0;i<N && can;i++){
    for(int j=b.size()-1;j>=0;j--){
      if(b[j]==j+1){
        b.erase(b.begin()+j);
        p[i]=j+1;
        break;
      }
      else if(j==0){
        can=false;
        break;
      }
    }
  }
  if(can){
    for(int i=N-1;i>=0;i--)cout << p[i] << endl;
  }
  else cout << -1;
}

Measured memory_bytes: 256
import sys
N, K = map(int,input().split())
A = [int(x) for x in input().split()]

def solve(N, K, A):
    """
    N <= 200,000
    """
    for i in range(K,N):
        prev = A[i-K]
        P = A[i]
        if prev >= P:
            print("No")
        else:
            print("Yes")

solve(N, K, A)



Measured memory_bytes: 31752
#include <bits/stdc++.h>
#define fr(i, n) for (int i = 0; i < n; i++)
#define frab(i, a, b) for (int i = a; i < b; i++)
#define pb push_back

using namespace std;

typedef long long ll;
typedef long double ld;

const ll MOD = 1e9 + 7;
const ll INF = 2e15 + 10;
const ll MAX = 1e14 + 10;
const ld EPS = 1e-9;
const int N = 1e3 + 10;
const int M = 1e5 + 10;

ll d[N][N];

char ch[N][N];

void add(ll& x, ll y) {
    x += y;
    if (x >= MOD)
        x -= MOD;
}

void solve() {
    int n, m;
    scanf("%d %d", &n, &m);
    fr(i, n) {
        scanf("%s", &ch[i]);
    }

    d[0][0] = 1;
    fr(i, n)
        fr(j, m) {
            if (i)
                add(d[i][j], d[i - 1][j]);
            if (j)
                add(d[i][j], d[i][j - 1]);
            if (ch[i][j] == '#')
                d[i][j] = 0;
        }
    cout << d[n - 1][m - 1];

}



int main() {
    //freopen("a.in", "r", stdin);
    ios_base::sync_with_stdio(false);
    solve();
}


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

struct RollingHash {
    static const int base1 = 1007, base2 = 2009;
    static const int mod1 = 1000000007, mod2 = 1000000009;
    vector<long long> hash1, hash2, power1, power2;

    // construct
    RollingHash(const vector<long long> &S) {
        int n = (int)S.size();
        hash1.assign(n + 1, 0);
        hash2.assign(n + 1, 0);
        power1.assign(n + 1, 1);
        power2.assign(n + 1, 1);
        for (int i = 0; i < n; ++i) {
            hash1[i + 1] = (hash1[i] * base1 + S[i]) % mod1;
            hash2[i + 1] = (hash2[i] * base2 + S[i]) % mod2;
            power1[i + 1] = (power1[i] * base1) % mod1;
            power2[i + 1] = (power2[i] * base2) % mod2;
        }
    }

    // get hash of S[left:right]
    inline pair<long long, long long> get(int l, int r) const {
        long long res1 = hash1[r] - hash1[l] * power1[r - l] % mod1;
        if (res1 < 0) res1 += mod1;
        long long res2 = hash2[r] - hash2[l] * power2[r - l] % mod2;
        if (res2 < 0) res2 += mod2;
        return {res1, res2};
    }

    // get LCP (Longest Common Prefix) of S[a:] and S[b:]
    inline int getLCP(int a, int b) const {
        int len = min((int)hash1.size() - a, (int)hash1.size() - b);
        int low = 0, high = len;
        while (high - low > 1) {
            int mid = (low + high) >> 1;
            if (get(a, a + mid) != get(b, b + mid))
                high = mid;
            else
                low = mid;
        }
        return low;
    }

    // get LCP (Longest Common Prefix) of S[a:] and T[b:]
    inline int getLCP(const RollingHash &T, int a, int b) const {
        int len = min((int)hash1.size() - a, (int)hash1.size() - b);
        int low = 0, high = len;
        while (high - low > 1) {
            int mid = (low + high) >> 1;
            if (get(a, a + mid) != T.get(b, b + mid))
                high = mid;
            else
                low = mid;
        }
        return low;
    }
};

int main() {
    int n;
    cin >> n;
    vector<ll> a(n), b(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    vector<long long> da(n * 2), db(n * 2);
    for (int i = 0; i < n * 2; ++i) {
        int j = i % n;
        int k = (i + 1) % n;
        da[i] = a[j] ^ a[k];
        db[i] = b[j] ^ b[k];
    }

    RollingHash A(da), B(db);
    for (int k = 0; k < n; ++k) {
        int len = A.getLCP(B, k, 0);
        if (len >= n) {
            cout << k << " " << (a[k] ^ b[0]) << endl;
        }
    }
}

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

int main(){
  int n,a,b;

  while(cin >> n ,n){
    vector<int> v[n];
    for(int i = 0 ; i < n ; i++){
      cin >> a;
      for(int j = 0 ; j < a ; j++){
	cin >> b;
	v[i].push_back(b);
      }
    }

    int check[101] = {0};
    int cnt[101] = {0};
    int ans;

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

    int t = 0;
    while(true){
      if(t == n) break;
      
      for(int i = 0 ; i < a ; i++){
	vector<int>::iterator pos;
	pos = find(v[t].begin(),v[t].end(),check[i]);
	if(pos == v[t].end()){
	  break;
	}
	else{
	  cnt[t]++;
	}
      }
      t++; 
    }

    int cnt1 = 0;
    for(int i = 0 ; i < n ; i++){
      if(cnt[i] == a){
	ans = i+1;
	cnt1++;
      }

    }
    if(cnt1 == 1) cout << ans << endl;
    else cout << "-1" << endl;   
  }

  return 0;
}

Measured memory_bytes: 1268
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;

int main(){
    ll n;
    cin >> n;
    ll ans = 0;
    for(ll i = 1; i <= n; i++){
        ll cnt = n / i;  // i を約数に含む数が何個あるか
        ans += cnt * (cnt + 1) / 2 * i; // i + 2*i + 3*i + ... + cnt*i を足す
    }
    cout << ans << endl;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,k;
    cin >>n>>k;
    vector<int>h(n);
    for(int i=0;i<n;i++)cin>>h[i];
    sort(h.begin(),h.end());
    long long ans=0,a;
    a = n-k;
    for(int i=0;i<a;i++)ans += h[i];
    cout<<ans<<endl;
    
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;

namespace cswork
{
    class Program
    {
        class Scanner
        {
            string[] s;
            int i;

            char[] cs = new char[] { ' ' };

            public Scanner()
            {
                s = new string[0];
                i = 0;
            }

            public string next()
            {
                if (i < s.Length) return s[i++];
                string st = Console.ReadLine();
                while (st == "") st = Console.ReadLine();

                s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
                i = 0;
                return next();
            }

            public int nextInt()
            {
                return int.Parse(next());
            }

            public long nextLong()
            {
                return long.Parse(next());
            }

            public double nextDouble()
            {
                return double.Parse(next());
            }
        }

        public Program() { }

        static void Main(string[] args)
        {
            new Program().Omame();
        }

        Scanner cin;
        const int MAXIN = 1024;
        bool[] used = new bool[MAXIN];
        int[] perm = new int[MAXIN];

        List<int[]> permList = new List<int[]>();

        public void Permutation(int pos, int n, int length)
        {
            if (pos == n)
            {
                permList.Add((int[])perm.Clone());
            }

            for (int i = 0; i < n; i++)
            {
                if (!used[i])
                {
                    perm[pos] = i;
                    used[i] = true;
                    Permutation(pos + 1, n, length);
                    used[i] = false;
                }
            }
        }

        public static List<long> GeneratePrime(long max)
        {
            long prime;
            double sqrtMax = Math.Sqrt(max);
            var primeList = new List<long>();

            List<long> searchList = new List<long>();
            for (long i = 2; i <= max - 1; i++)
            {
                searchList.Add(i);
            }

            do
            {
                prime = searchList.First();
                primeList.Add(prime);
                searchList.RemoveAll(n => n % prime == 0);
            } while (prime < sqrtMax);

            primeList.AddRange(searchList);

            return primeList;
        }

        void Omame()
        {
            cin = new Scanner();
            int D = cin.nextInt();
            int N = cin.nextInt();

            int x = 1;
            if(D == 1)
            {
                x *= 100;
            }else if (D == 2)
            {
                x *= 10000;
            }

            long ans = x * N;
            if (N == 100) ans += x;


            Console.WriteLine(ans);
        }

    }
}


Measured memory_bytes: 11220
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
using namespace std;

int w, h, n;

int x, y, a;

int area[101][101];

int main() {
    ios_base::sync_with_stdio(false);

    cin >> w >> h >> n;

    for (int i = 0; i < n; i++) {
        cin >> x >> y >> a;
        if (a == 1) {
               //x < xi
            for (int xx = 0; xx < x; xx++)
                for (int yy = 0; yy < h; yy++)
                    area[yy][xx] = 1;

        } else if (a == 2) {
            for (int xx = x; xx < w; xx++)
                for (int yy = 0; yy < h; yy++)
                    area[yy][xx] = 1;


        } else if (a == 3) {
        for (int yy = 0; yy < y; yy++)
                for (int xx = 0; xx <w; xx++)
                    area[yy][xx] = 1;

        } else if (a == 4) {
        for (int yy = y; yy < h; yy++)
                for (int xx = 0; xx < w; xx++)
                    area[yy][xx] = 1;
        }
    }
     int ans = 0;
     for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            //cout << area[i][j] << " ";
            if (area[i][j] == 0)
                ans++;
        }
        //cout << endl;
    }

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 384
def main():
    N,M=map(int,input().split())

    k_list=[]
    swiches=[]
    for i in range(M):
        inp=list(map(int,input().split()))
        k_list.append(inp[0])
        swiches.append(inp[1:])
    P=list(map(int,input().split()))

    res=0
    for SwichStatus in range(pow(2,N)):
        flag=0
        for i in range(M):
            Link=0
            for swich in swiches[i]:
                Link+=1<<(swich-1)
            OnSwich=SwichStatus&Link
            OnCounter=0
            while OnSwich!=0:
                OnCounter+=OnSwich&1
                OnSwich>>=1
            if OnCounter%2!=P[i]:
                flag=1
                break
        if flag!=1:
            res+=1
    print(res)
if __name__=="__main__":
    main()



Measured memory_bytes: 3064
function Main(input) {
    var A = parseInt(input[0], 10);
    var B = parseInt(input[1], 10);

    var list = [1, 2, 3];
    var result = list.filter(n => n !== A && n !== B);

    console.log(result[0]);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split(/\n|\s/));

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

#define FOR(i,a,b)    for (int i=(a)  ;i<(b) ;i++)
#define RFOR(i,a,b)   for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)      for (int i=0    ;i<(n) ;i++)
#define RREP(i,n)     for (int i=(n)-1;i>=0  ;i--)
#define EACH(i,a,b)   for (int i=(a)  ;i<=(b);i++)
#define REACH(i,a,b)  for (int i=(b)  ;i>=(a);i--)
#define ALL(a)        (a).begin(),  (a).end()
#define RALL(a)       (a).rbegin(), (a).rend()
#define YES()         printf("YES\n")
#define NO()          printf("NO\n")
#define Yes()         printf("Yes\n")
#define No()          printf("No\n")
#define in(a,x,b)     ((a) <= (x) && (x) < (b))

const int MOD = 1e9 + 7;
const int INF = 1 << 29;
const double EPS = 1e-10;

using ll = long long;
using P = pair<int,int>;
template<class T = int> using V = vector<T>;

template<class T> bool inline chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool inline chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T = int> T inline input() { T x; cin >> x; return (x); }
template<class T> void inline print(T& x) { cout << x << '\n'; }
#define debug(x) cerr << #x << ": " << x << endl;

const int dxs[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
const int dys[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

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

  int H,W;
  cin >> H >> W;
  string A[H];
  REP(i,H) cin >> A[i];

  REP(y,H) {
    REP(x,W) {
      if (A[y][x] == '#') {
        if (in(0,y+1,H) && in(0,x+1,W) && A[y][x+1] == '#' && A[y+1][x] == '#'
          || in(0,y-1,H) && in(0,x-1,W) && A[y-1][x] == '#' && A[y][x-1] == '#') {
          cout << "Impossible" << endl;
          return 0;
        }
      }
    }
  }

  cout << "Possible" << endl;

  return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
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; }

int count_AB(string s, int l){
  int ans = 0;
  for (int i=0; i<l-1; i++){
    if (s[i] == 'A' && s[i+1] == 'B'){
      ans++;
      i++;
    }
  }
  return ans;
}

int main(){
  int N;
  cin >> N;
  vector<string> S(N);
  int ans = 0;
  int start_B = 0;
  int end_A = 0;
  int both = 0;
  for (int i=0; i<N; i++){
    cin >> S[i];
    int l = S[i].length();
    // S[i] に AB が含まれる個数を数えて足し合わせていく
    ans += count_AB(S[i], l);
    // Bで始まるやつとAで終わるやつとその両方のやつをそれぞれ数える
    if (S[i][0] == 'B'){
      start_B++;
    }
    if (S[i][l-1] == 'A'){
      end_A++;
    }
    if (S[i][0] == 'B' && S[i][l-1] == 'A'){
      both++;
    }
  }

  //　並び替えで ABが生まれうるのはB で始まるやつとAで終わるやつが存在するとき
  if (start_B == end_A){
    if (both == start_B){
      if (start_B != 0){
        ans += start_B - 1;
      }
    } else{
      ans += start_B;
    }
  } else{
    chmin(start_B, end_A);
    ans += start_B;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 768
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
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;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
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; }
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    ll count = 0;
    rep(i, s.size())
    {
        count += (s[i] - '0');
    }
    if (count % 9)
        no;
    else
        yes;
}


Measured memory_bytes: 3736
#include<iostream>
using namespace std;
typedef long long ll;

int main()
{
    ll n;
    ll sum = 0;
    cin >> n;
    for( ll i = 1; i <= n; i++ ){
        if( i % 3 == 0 || i % 5 == 0 ){
            continue;
        }
        sum += i;
    }
    cout << sum << endl;
    return 0;
}



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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int w,h,x,y; cin>>w>>h>>x>>y;
	cout<<(double)w*h/2<<" "s<<(x*2!=w||y*2!=h?0:1)<<"\n"s;
}


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

#define int long long
#define fi first
#define se second
struct Edge {
  int a, b, cost;
  bool operator < (const Edge d) const {
    return (cost < d.cost);
  }
};

typedef pair <int , int> Pi;

struct UF {
  
  int parent[100005];
  
  UF()
  {
    for(int i = 0; i < 100005; i++) {
      parent[i] = i;
    }
  }

  bool unite(int a, int b)
  {
    a = getp(a); b = getp(b);
    if(a == b) return (true);
    parent[b] = a;
    return (false);
  }

  int getp(int x)
  {
    if(parent[x] == x) return (x);
    return (parent[x] = getp(parent[x]));
  }
};
int n;

Pi ynear[100005], xnear[100005];
vector < Edge > ed;
UF tree;
main()
{
  
  cin >> n;
  for(int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    ynear[i] = Pi(y, i);
    xnear[i] = Pi(x, i);
  }

  sort(ynear, ynear + n);
  sort(xnear, xnear + n);

  for(int i = 0; i < n - 1; i++) {
    ed.push_back( (Edge) { ynear[i].se, ynear[i + 1].se, ynear[i + 1].fi - ynear[i].fi } );
    ed.push_back( (Edge) { xnear[i].se, xnear[i + 1].se, xnear[i + 1].fi - xnear[i].fi } );
  }

  sort(ed.begin(), ed.end());
  int sum = 0;
  for(int i = 0; i < ed.size(); i++) {
    if(!tree.unite(ed[i].a, ed[i].b)) {
      sum += ed[i].cost;
    }
  }

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

Measured memory_bytes: 12400
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<vector<ll> > mat;


int main()
{ios_base::sync_with_stdio(false);
ld r;
cin>>r;
ld ans=acos(-1)*2*r;
cout<<fixed<<setprecision(20)<<ans;
return 0;
}



Measured memory_bytes: 3808