akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#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 vv vector<vi>
#define pb push_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 INF 1000000000
#define eps 1e-7
#define mod 1000000007
#define int ll
using namespace std;

int D, G;
int p[20];
int c[20];

signed main(void) {
    cin >> D >> G;
    rep(i, D) {
        cin >> p[i] >> c[i];
    }

    int ans=INF;
    //どの点数帯をcompleteするかのbit全探索
    rep(i, pow(2, D)) {
        int score=0;
        int num=0;
        rep(j, D) {
            if (i & (1LL<<j)) {
                score += (j+1)*100 * p[j] + c[j];
                num += p[j];
            }
        }
        if (score < G) { //まだ足りない
            int k=D-1;
            while (k>=0) {
                if ((i & (1LL<<k)) == 0) { //まだ解いてないやつ
                    if (score + (k+1)*100 * (p[k]-1) >= G) { //全完しないで足りる
                        int needed = (G-score + ((k+1)*100-1)) / ((k+1)*100);
                        num += needed;
                        break;
                    } else if (score + (k+1)*100 * p[k] + c[k] >= G) { //全完すれば足りる
                        num += p[k];
                        break;
                    } else { //足りない
                        num += p[k];
                    }
                }
                k--;
            }
        }
        ans = min(num, ans);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
S = input()
T = input()
ans = 2000
SLEN = len(S)
TLEN = len(T)
for i in range(SLEN-TLEN+1):
    cnt = 0
    for j in range(TLEN):
        if(T[j]!=S[i+j]):
            cnt += 1
    ans = min(ans,cnt)
print(ans)




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

int main(){
  ll N,K;cin>>N>>K;
  vector<ll> x(N);rep(i,N) cin>>x[i];
  ll ans=1e9;
  for(ll i=0;i+K-1<N;++i){
    ans = min(ans,min(abs(x[i+K-1])+x[i+K-1]-x[i],abs(x[i])+abs(x[i+K-1]-x[i])));
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<cmath>

int main(void) {
	int a, b, c, d, e, f;
	double x, y;
	while (scanf("%d%d%d%d%d%d", &a, &b, &c, &d, &e, &f) != EOF) {
		x = (double)(c*e - b*f) / (a*e - b*d);
		y = (double)(c*d - a*f) / (b*d - a*e);
		if (fabs(x) < 1e-3) x = 0;
		if (fabs(y) < 1e-3) y = 0;

		printf("%.3f %.3f\n", x, y);
	}
	return 0;
}

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

const ll p = 1e9+7;
ll dp[4][1000000];

int main() {
  string s; cin>>s;
  int n = s.size();
  dp[0][0] = 1;
  dp[1][0] = 0;
  dp[2][0] = 0;
  dp[3][0] = 0;
  for(int i=0; i<n; i++) {
    if(s[i]=='A') {
      dp[0][i+1] = dp[0][i];
      dp[1][i+1] = dp[0][i]+dp[1][i];
      dp[2][i+1] = dp[2][i];
      dp[3][i+1] = dp[3][i];
    } else if(s[i]=='B') {
      dp[0][i+1] = dp[0][i];
      dp[1][i+1] = dp[1][i];
      dp[2][i+1] = dp[2][i]+dp[1][i];
      dp[3][i+1] = dp[3][i];
    } else if(s[i]=='C') {
      dp[0][i+1] = dp[0][i];
      dp[1][i+1] = dp[1][i];
      dp[2][i+1] = dp[2][i];
      dp[3][i+1] = dp[3][i]+dp[2][i];
    } else { // s[i]=='?'
      dp[0][i+1] = dp[0][i]*3;
      dp[1][i+1] = dp[1][i]*3+dp[0][i];
      dp[2][i+1] = dp[2][i]*3+dp[1][i];
      dp[3][i+1] = dp[3][i]*3+dp[2][i];
    }
    dp[0][i+1]%=p;
    dp[1][i+1]%=p;
    dp[2][i+1]%=p;
    dp[3][i+1]%=p;
  }
  cout << dp[3][n] << endl;
  return 0;
}


Measured memory_bytes: 11520
N, M = map(int,input().split())
X = list(map(int,input().split()))
if len(X)<2:
    print(0)
else:    
    X.sort()

    diffs = []
    for i in range(M-1):
        diffs.append(abs(X[i+1]-X[i]))
    diffs.sort(reverse=True)
    print(X[M-1]-X[0]-sum(diffs[:N-1]))

Measured memory_bytes: 20516
// #pragma GCC target("avx")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
// #define BEGIN_STACK_EXTEND(size) void * stack_extend_memory_ = malloc(size);void * stack_extend_origin_memory_;char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);*stack_extend_dummy_memory_ = 0;asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
// #define END_STACK_EXTEND asm volatile("mov %%rax, %%rsp"::"a"(stack_extend_origin_memory_));free(stack_extend_memory_);

#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<unordered_map>
#include<complex>
using namespace std;
const long long mod=998244353;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double INF=1e+10;
const long double PI=acos(-1.0);
const int C_SIZE = 3100000;
const int UF_SIZE = 3100000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
	int UF[UF_SIZE];
	void init_UF(int n){
		for(int i=0;i<n;i++)UF[i]=-1;
	}
	int FIND(int a){
		if(UF[a]<0)return a;
		return UF[a]=FIND(UF[a]);
	}
	void UNION(int a,int b){
		a=FIND(a);b=FIND(b);if(a==b)return;
		// if(UF[a]>UF[b])swap(a,b);
		UF[a]+=UF[b];UF[b]=a;
	}
}
// ここから編集しろ
int p[5100];
int nx[5100][14];
int cost[5100][14];
int main(){
	int a,b;scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++)scanf("%d",p+i);

	for(int i=0;i<b;i++){
		int n,x,m;
		scanf("%d%d%d",&n,&x,&m);
		long long sum=x%m;
		for(int j=0;j<a;j++){
			long long T=0;
			T=(n-1+a-j-1)/a;
			if(T<0)T=0;
			long long ks=p[j]%m;
			if(ks==0)ks+=m;
			sum+=ks*T;
		}
		long long yk=sum/m;
		printf("%lld\n",n-1-yk);
	}
}

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

using namespace std;

int n;
char arr[510][510];

int solve(int rid) {
	int ans = 0;
	bool spok = false;
	bool uu = false;
	int sans = 0;
	for (int c = 0; c < n; ++c) {
		if (arr[rid][c] == '#') {
			spok = true;
			break;
		}
	}
	for (int c = 0; c < n; ++c) {
		if (arr[rid][c] == '#') continue;
		bool ok = false;
		for (int r = 0; r < n; ++r) {
			if (arr[r][rid] == '#') {
				ok = true;
				break;
			}
		}
		if (ok) ++ans;
		else if(spok) {
			sans += 2;
			uu = true;
		}
		else return -1;
	}
	ans *= 2;
	for (int c = 0; c < n; ++c) {
		if (arr[rid][c] == '.') continue;
		bool w = false;
		for (int r = 0; r < n; ++r) {
			if (r == rid) continue;
			if (arr[r][c] == '.') {
				w = true;
				break;
			}
		}
		if (w) ++ans;
	}
	return ans + sans + uu;
}

int sol1() {
	int ans = -1;
	for (int i = 0; i < n; ++i) {
		int myans = solve(i);
		if (myans != -1) {
			if (ans == -1) ans = myans;
			else ans = min(ans, myans);
		}
	}
	
    return ans;
}

int sol2() {
	set<int> used;
	queue<pair<int, int>> q;
	int cur = 0;
	for (int r = 0; r < n; ++r) {
		for (int c = 0; c < n; ++c) {
			cur = cur * 2 + (arr[r][c] == '#');
		}
	}
	used.insert(cur);
	q.emplace(0, cur);
	while (!q.empty()) {
		int cur = q.front().second;
		int s = q.front().first;
		q.pop();
		if (cur == (1<<16) - 1) return s;
		char arr[4][4];
		int id = cur;
		for (int r = n - 1; r >= 0; --r) {
			for (int c = n - 1; c >= 0; --c) {
				arr[r][c] = ".#"[id & 1];
				id >>= 1;
			}
		}
		char f[4][4];
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < n; ++j) {
				memcpy(f, arr, sizeof(f));
				char tmp[4];
				for (int k = 0; k < n; ++k) {
					tmp[k] = f[i][k];
				}
				for (int k = 0; k < n; ++k) {
					f[k][j] = tmp[k];
				}
				cur = 0;
				for (int r = 0; r < n; ++r) {
					for (int c = 0; c < n; ++c) {
						cur = cur * 2 + (f[r][c] == '#');
					}
				}
				if (used.find(cur) ==used.end()) {
					used.insert(cur);
					q.emplace(s + 1, cur);
				}
			}
		}
	}
	return -1;
}

void test() {
	
	n = 4;
	for (int i = 0; i < (1 << 16); ++i) {
		int id = i;
		for (int j = 0 ; j < 4; ++j) arr[j][4] = '\0';
		for (int r = 0; r < 4; ++r)
			for (int c = 0; c < 4; ++c) {
				arr[r][c] = ".#"[id & 1];
				id >>= 1;
			}
		if (sol1() != sol2()) {
			printf("%d %d\n", sol1(), sol2());
			for (int j = 0; j < 4; ++j) puts(arr[j]);
			//return 0;
		}
	}
	
	puts("OK");
}

int main() {
	scanf("%d", &n);
	
	for (int i = 0; i < n; ++i) {
		scanf("%s", arr[i]);
	}
	
	printf("%d\n", sol1());
	
	return 0;
}


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

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

	int ans[a+b] = { 0 };	int j = 0;	int x = 0;	int y = 0;
	for (int i = 1; i <= a; i++) {
		x = a % i;
		y = b % i;
		if ((x == 0)&&(y == 0)) {
			ans[j] = i;
			j += 1;
		}
	}
	
	cout << ans[j-k] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

int n, k;
int maxCon;

//用邻接矩阵表示
bool isConnected[110][110];

struct Edge
{
	int u, v;
};
std::vector<Edge> edges;

int main()
{
	scanf("%d%d", &n, &k);
	
	maxCon = (n - 1) * (n - 2) / 2;
	
	if (k > maxCon)
	{
		printf("-1\n");
		return 0;
	}
	
	for (int i = 1 ; i <= n ; i++)
		for (int j = 1 ; j <= n ; j++)
			isConnected[i][i] = false;
	
	//首先，原始邻接矩阵的对角线一定是相连的
	for (int i = 1 ; i <= n ; i++)
		isConnected[i][i] = true;
	 
	//一定保证和最大的那个点链接，然后就可以乱涂乱画了 
	int p = 0;
	for (int i = 1 ; i <= n - 1 ; i++)
	{
		if (p >= k)
			break;
		
		for (int j = i + 1 ; j <= n - 1 ; j++)
		{
			isConnected[i][j] = true;
			isConnected[j][i] = true;	//正反都要做，当然其实我们实际只考虑上半区 
			p++; 
			
			if (p >= k)
				break;
		}
		if (p >= k)
			break;
	}
	
	edges.clear();
	Edge newEdge;
	
	for (int i = 1 ; i <= n ; i++)
	{
		for (int j = i + 1 ; j <= n ; j++)
		{
			if (isConnected[i][j] == false)
			{
				newEdge.u = i;
				newEdge.v = j;
				edges.push_back(newEdge);
			}
		}
	}
	
	printf("%d\n", edges.size());
	for (int i = 0 ; i < edges.size() ; i++)
	{
		printf("%d %d\n", edges[i].u, edges[i].v);
	}
	
	return 0;
}

//链接数就是总个数，然后求反图 
//但必须保证整个图联通，所以最大有上限，上限(N-1)(N-2)/2 

Measured memory_bytes: 384
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>

using namespace std;

int n;
char s[12];
long long a[12],num[12];
long long ans;

void work(int tmp)
{
	for(int i=1;i<=tmp;i++)ans+=num[i];
}

void dfs(int x,int tmp)
{
	if(x>n){work(tmp);return;}
	num[tmp]=num[tmp]*10+a[x];
	dfs(x+1,tmp+1);
	dfs(x+1,tmp);
	num[tmp]/=10;
}

int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	for(int i=1;i<=n;i++)
		a[i]=s[i]-48;
	dfs(1,1);
	printf("%lld\n",ans/2);
}

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

using namespace std;
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int mod = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  
template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n, ans=0;
	map<char, int> mp;
	cin >>n;
	
	rep(i,n){
		char s;
		cin>>s;
		mp[s]++;
	}
	cout << (sz(mp)==3?"Three":"Four") <<"\n";
	return 0;
	
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
  		if(N>81){
          System.out.println("No");
      	  return;
        }
		for(int i=1; i < 10; i++){
          if((N%i==0)&&((N/i)<10)){
          	System.out.println("Yes");
          	return;
          }
        }
		System.out.println("No");
      	return;
	}
}


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

typedef long long ll;
int N, K, Xn;
vector<int> arr;
vector<ll> X;
map<ll, int> dx;

struct BIT {
    vector<int> tree;
    void init() {
        tree = vector<int>(4*Xn, 0);
    }
    void upd(int idx, int val, int l, int r, int n) {
        if(idx < l || r < idx) return;
        if(l == r) {
            tree[n] += val;
            return;
        }
        int m = (l + r)>>1;
        upd(idx, val, l, m, 2*n);
        upd(idx, val, m + 1, r, 2*n + 1);
        tree[n] = tree[2*n] + tree[2*n + 1];
    }
    int quer(int a, int b, int l, int r, int n) {
        if(b < l || r < a) return 0;
        if(a <= l && r <= b) return tree[n];
        int m = (l + r)>>1;
        int L = quer(a, b, l, m, 2*n);
        int R = quer(a, b, m + 1, r, 2*n + 1);
        return L + R;
    }
} bit;

int main() {
    scanf("%d %d", &N, &K);
    arr.resize(N);
    for(int i = 0; i < N; i++) {
        scanf("%d", &arr[i]);
        arr[i] -= K;
    }
    X.resize(N);
    for(int i = N - 1; i >= 0; i--) {
        X[i] = -arr[i];
        if(i != N - 1) X[i] += X[i + 1];
    }
    X.push_back(0);
    sort(X.begin(), X.end());
    X.resize(unique(X.begin(), X.end()) - X.begin());
    Xn = X.size();
    for(int i = 0; i < Xn; i++) dx[ X[i] ] = i;

    bit.init();
    ll offset = 0;
    ll ans = 0;

    for(int i = N - 1; i >= 0; i--) {
        bit.upd(dx[ -offset ], 1, 0, Xn - 1, 1);
        offset += arr[i];
        ans += bit.quer(dx[ -offset ], Xn - 1, 0, Xn - 1, 1);
    }

    printf("%lld", ans);
}


Measured memory_bytes: 19556
import java.io.*;
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a, b;
        a = sc.nextInt(); b = sc.nextInt();
        System.out.print(a*b);
        System.out.print(' ');
        System.out.println(2*(a+b));
    }
}

Measured memory_bytes: 12000
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin,(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int n,m;
    cin >> n >> m;
    int l,r;
    int L[m],R[m];
    REP(i,m){
        cin >> L[i] >> R[i];
    }
    l=L[0];
    r = R[0];
    FOR(i,1,m){
        if(l > R[i] || r < L[i]){
            cout << 0 << endl;
            return 0;
        }
        l = max(l,L[i]);
        r = min(r,R[i]);
    }
    cout << r-l+1 << endl;
    return 0;
}

Measured memory_bytes: 1024
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
from collections import deque

class Graph():
    def __init__(self, v):
        from heapq import heappop, heappush
        self.v = v
        self.graph = [[] for _ in range(v)]
        self.INF = 10 ** 9
    
    def addEdge(self, start, end, edge):
        self.graph[start].append((end, edge))
        self.graph[end].append((start, edge))

def do():
    n=INT()
    g=Graph(n)
    for i in range(n-1):
        a,b=INTM()
        a-=1
        b-=1
        g.addEdge(a,b,i)

    
    que=deque()
    check=[True]*n
    clrs=[0]*(n-1)
    que.append([0,0])
    check[0]=False
    while que:
        clr=1
        now,clr_f=que.popleft()
        if clr_f==1:
            clr=2
        for next,i in g.graph[now]:
            if check[next]:
                check[next]=False
                que.append([next,clr])
                clrs[i]=clr
                clr+=1
                if clr==clr_f:
                    clr+=1
    
    print(max(clrs))
    for i in range(n-1):
        print(clrs[i])








if __name__=='__main__':
    do()

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

int main()
{
    int k, x;
    cin >> k >> x;
    int t = 2 * k - 1;
    int a = x - (k - 1);
    rep(i, t)
    {
        cout << (a + i) << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s1,s2,s3;
  cin >>s1>>s2;
  if(s1[0]==s2[2]&&s1[1]==s2[1]&&s1[2]==s2[0])cout << "YES"<<endl;
  else cout << "NO" << endl;
}


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

using namespace std;

using ll = long long;
using ld = long double;

inline ll ceil_ll(ll x, ll y) { return (x + y - 1) / y; }

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    // cout << setprecision(8) << setiosflags(ios::fixed);

    ll L, R;
    cin >> L >> R;

    ll min_v = 2018;
    for (ll i = L; i < L + 2019 && i < R; ++i) {
        for (ll j = i + 1; j < i + 2020 && j <= R; ++j) {
            min_v = min(min_v, (i * j) % 2019);
        }
    }

    cout << min_v << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
     
#define pll pair <long long,long long>
#define pb push_back
#define ll long long
#define ff first
#define ss second
#define vll vector <ll>
#define NFS ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl '\n'
#define M 1000000007   
using namespace std;

void solve()
{
	ll a,b,n;
	cin>>a>>b>>n;
	ll ans=0;
	if(n<b)
	{
		cout<<(a*n)/b;
	}else{
		cout<<(a*(b-1))/b;
	}
	//cout<<(a*n)/b - (a*(n/b));
}
 
int main()
{
    NFS
 	int t=1;
 	//cin>>t;
 	while(t--)
 	{
 		solve();
 	}
    return 0;
}

Measured memory_bytes: 3608
/*input
aaaccacabaababc
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define eb emplace_back
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define EL cout<<'\n'
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
template<typename T>
ostream& operator<<(ostream& out,vector<T> V){
	REP(i,SZ(V)) out<<V[i]<<((i!=SZ(V)-1)?" ":"");
	return out;
}
#define version 20190814
//}}}
const ll maxn=300005;
const ll maxlg=20;
const ll INF64=1e18;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

set<string> st;

int main(){
	IOS;
	string s;
	cin>>s;
	int ans=SZ(s);
	for(int i=0;i<SZ(s);i++){
		if(i!=SZ(s)-1&&s[i]==s[i+1]){
			ans--;
			i+=2;
		}
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 720
// ----- In the name of ALLAH, the Most Gracious, the Most Merciful -----

#include<bits/stdc++.h>
using namespace std;

#define NINJA ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;i<n;i++)
#define for1(i,n) for(int i=1;i<=n;i++)
#define dloop(i,n) for(int i=n-1;i>=0;i--)
#define iii tuple<int,int,int>
#define vi vector<int>
#define ii pair<int,int>
#define vii vector<ii>
#define int long long
#define ld long double
#define pb push_back
#define endl "\n"
#define setbits __builtin_popcountll
#define mp map<int,int>
#define F first
#define S second
#define sz(v) (int)v.size()
#define mod 1000000007
#define inf (int)1e18

int32_t main(){
	NINJA;

	int n,d; cin >> n >> d;
	int cnt =0 ;
	fo(i,n){
		ld x,y; cin >> x >> y;
		cnt += ((x*x + y*y) <= d*d ? 1 : 0);
	}
	cout << cnt << endl;
	
	return 0;
}

Measured memory_bytes: 3792
N = gets.to_i
V = gets.split.map &:to_i
C = gets.split.map &:to_i

arr = []
sum = 0
(0..N-1).each do |i|
    arr << V[i].to_i - C[i].to_i
end

arr.each do |j|
    if j && j >= 1
        sum+=j.to_i
    end
end

puts sum

Measured memory_bytes: 1788
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

const int mod = 1000000007;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}

    mint &operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }

    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }

    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }

    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const {
        return pow(mod - 2);
    }

    mint &operator/=(const mint a) {
        return (*this) *= a.inv();
    }

    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }

    friend std::istream &operator>>(std::istream &in, mint &o) {
        ll a;
        in >> a;
        o = a;
        return in;
    }

    friend std::ostream &operator<<(std::ostream &out, const mint &o) {
        out << o.x;
        return out;
    }

};


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

    int n = l.size();
    vector<vector<mint>> dp(n + 1, vector<mint>(2));
    dp[0][0] = 1;
    rep(i, n) {
        {
            if (l[i] == '0') {
                dp[i + 1][0] += dp[i][0];
                dp[i + 1][1] += dp[i][1];
            } else {
                dp[i + 1][1] += dp[i][0] + dp[i][1];
            }
        }
        {
            if (l[i] == '0') {
                dp[i + 1][1] += dp[i][1] * 2;
            } else {
                dp[i + 1][0] += dp[i][0] * 2;
                dp[i + 1][1] += dp[i][1] * 2;
            }
        }
    }

    mint ans = dp[n][0] + dp[n][1];
    cout << ans << endl;


}


Measured memory_bytes: 8800
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long int ll;
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) { a = b; return 1; }return 0; }
#define all(a)  (a).begin(),(a).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
const ll INF =1LL << 62;

int main(){
  int N; cin >> N;
  ll a[1000000][3] ;
  rep(i,N){
    rep(j,3){
      cin >> a[i][j] ;
    }
  }
  ll dp[1000000][3] ;
  rep(i,N){
    rep(j,3){
      rep(k,3){
        if(j != k){
          chmax(dp[i+1][k] ,dp[i][j] +a[i][k]) ;
        }
      }
    }
  }
  cout << max({dp[N][0],dp[N][1],dp[N][2]}) << endl;
}

Measured memory_bytes: 9600
import java.io.PrintWriter
import java.util.*
import java.math.*
import java.lang.*
import kotlin.comparisons.*

val pw = PrintWriter(System.out)
val MOD: Long = (1e+9 + 7).toLong()

fun main(args: Array<String>) {
    val o = read()
    val e = read()
    val pass = o.zip(e).map { p -> listOf(p.first, p.second) }.flatMap { it }.joinToString(separator="") + if(o.length > e.length) o.last() else ""
    println(pass)
    pw.flush()
}

/****** Declared Functions and Data Structures ******/
// IO
fun read() = readLine()!!
fun readInt() = read().toInt()
fun readLong() = read().toLong()
fun readDouble() = read().toDouble()
fun readListOfString() = read().split(" ")
fun readListOfInt() = readListOfString().map { it.toInt() }
fun readListOfLong() = readListOfString().map { it.toLong() }
fun readListOfDouble() = readListOfString().map { it.toDouble() }

fun Double.format(digits: Int) = String.format("%.${digits}f", this)
fun Float.format(digits: Int) = String.format("%.${digits}f", this)

fun print(value: Any) { pw.print(value) }
fun println(value : Any) { pw.println(value) }


// Extensions
fun<T> List<T>.toBuckets(bucketKeys: List<T>): Map<T, Int> {
    val buckets = bucketKeys.associate { t -> Pair(t, 0) }.toMutableMap()
    this.forEach { t ->
        buckets[t] = buckets[t]!! + 1
    }
    return buckets
}

fun <K, V> Map<K, V>.toMutableMap(): MutableMap<K, V> = HashMap(this)

// Util Functions
fun<T> permutations(src: List<T>): List<List<T>> {
    if(src.size == 1) return listOf(src)
    val perms = mutableListOf<List<T>>()
    val insertElement = src[0]
    permutations(src.drop(1)).forEach { perm ->
        for(i in 0..perm.size) {
            val newPerm = perm.toMutableList()
            newPerm.add(i, insertElement)
            perms.add(newPerm.toList())
        }
    }
    return perms
}

// return nCr, if you want nCr, please access v[n][r]
fun combinations(n: Long): List<List<Long>> {
    val v = (0..n).map { (0..n).map{0L}.toMutableList() }.toMutableList()
    for(i in 0 until v.size) {
        v[i][0] = 1L
        v[i][i] = 1L
    }
    for(i in 0 until v.size) {
        for(j in 1 until i) {
            v[i][j] = (v[i-1][j-1] + v[i-1][j]) % MOD
        }
    }
    return v.map { it.toList() }.toList()
}

// should be a >= b
fun gcd(a: Long, b: Long): Long = 
    if(b == 0L) a else gcd(b, a % b)

// shoud be a >= b
fun lcm(a: Long, b: Long): Long = 
    a / gcd(a, b) * b

fun sumDigits(num_: Long): Long {
    var num = num_
    var rtn: Long = 0
    while(num != 0.toLong()) {
        val tmp = num % 10
        rtn += tmp
        num /= 10
    }
    return rtn
}

fun Double.isDecimal(): Boolean = ((this - Math.floor(this)) != 0.0)

// Data Structures
class Stack<T>(private var st: MutableList<T> = mutableListOf<T>()) {
    fun isEmpty() = st.isEmpty()
    fun top(): T = st.last()
    fun push(e: T) { st.add(e) }
    fun pop() { st = st.dropLast(1).toMutableList() }
}

class Queue<T>(private var que: MutableList<T> = mutableListOf<T>()) {
    fun isEmpty() = que.isEmpty()
    fun top(): T = que.first()
    fun push(e: T) { que.add(e) }
    fun pop() { que = que.drop(1).toMutableList() }
}


Measured memory_bytes: 37900
S = input()


def judge(sent):
    tmp = sent[1]
    tmp_last = sent[-1]
    if sent[0] != 'A' or tmp.isupper() or tmp == 'C' or tmp_last.isupper() or tmp_last == 'C':
        return False

    part = list(sent[2:-1])
    if sum(['C' in s for s in part]) != 1:
        return False
    idx = part.index('C')
    part.pop(idx)
    if any([s.isupper() for s in part]):
        return False
    return True


if judge(S):
    print('AC')
else:
    print('WA')


Measured memory_bytes: 3064
#include <iostream>
using namespace std;
class Dice{
public:
    int n1,n2,n3,n4,n5,n6;
    
    void East(){
        int t = n1;
        n1 = n4;
        n4 = n6;
        n6 = n3;
        n3 = t;
    }
    void West(){
        int t = n1;
        n1 = n3;
        n3 = n6;
        n6 = n4;
        n4 = t;
    }
    void South(){
        int t=n1;
        n1 = n5;
        n5 = n6;
        n6 = n2;
        n2 = t;
    }
    void North(){
        int t=n1;
        n1 = n2;
        n2 = n6;
        n6 = n5;
        n5 = t;
    }
    void Rotation(){
        int t=n2;
        n2 = n3;
        n3 = n5;
        n5 = n4;
        n4 = t;
    }
};

int main(){
    Dice d[100];
    int n;
    
    cin>>n;
    for(int i=0; i<n; i++){
        cin>>d[i].n1>>d[i].n2>>d[i].n3>>d[i].n4>>d[i].n5>>d[i].n6;
    }
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            if(j==i)continue;
            for(int k=0; k<6; k++){
                if(k==4){
                    d[i].East();
                }
                if(k==5){
                d[i].East();
                d[i].East();
                }
                for(int l=0; l<4; l++){
                    d[i].Rotation();
                    if(d[i].n1==d[j].n1 && d[i].n2==d[j].n2 && d[i].n3==d[j].n3 &&
                       d[i].n4==d[j].n4 && d[i].n5==d[j].n5 && d[i].n6==d[j].n6){
                        cout<<"No"<<endl;
                        return 0;
                    }
                }
            }
            
        }
        
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define fr(i,n) for(i=0;i<n;i++)
#define F first
#define S second
#define fast std::ios_base::sync_with_stdio(false)
#define mod 1000000007
#define pi 3.14159265
int main() {
    fast;
    lli k;
    cin>>k;
    lli i,num=0;
    for(i=1;i<=1000000;i++)
    {
        num=num*10+7;
        num=num%k;
        if(num==0)
        {
            cout<<i<<"\n";
            return 0;
        }
    }
    cout<<-1;
    
    return 0;
}

Measured memory_bytes: 3648
N=int(input())
c=0
d=10000000000000
rN=int(N**0.5)

for i in range(rN):
    if (N%(i+1)==0) :
        x=i+1
        y=int(N/(i+1))
        if d>(x+y):
            d=x+y

print(d-2)

Measured memory_bytes: 40300
#include <algorithm>
#include <cassert>
// #include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
// #include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

/*
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
mt19937 g1.seed(seed1);
*/
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<pii, pii> ppiipii;
typedef pair<int, ppiipii> pippiipii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> ppiii;
typedef pair<int, ppiii> pippiii;
typedef pair<int, ll> pill;
typedef pair<int, double> pid;
typedef pair<string, string> pss;
// note to self, the below two triggers someone
typedef pair<ll, ll> pll;
typedef pair<ll, int> plli;
typedef long double ld;

int ret[100];

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  while(m--) {
    int a, b;
    scanf("%d%d", &a, &b);
    ret[a]++;
    ret[b]++;
  }
  for(int i = 1; i <= n; i++) {
    printf("%d\n", ret[i]);
  }
}


Measured memory_bytes: 256
use std::io;
use std::str;

// fn printnum(x: i32){
//     println!("{}", x);
// }

// fn sum(x: i32, y: i32) -> i32{
//     x + y
// }

fn readnum() -> i32{
    let mut x = String::new();
    io::stdin().read_line(&mut x).expect("read_line error");
    let x = x.trim().parse().expect("parse error");
    x
}

fn readstr() -> String{
    let mut x = String::new();
    io::stdin().read_line(&mut x).expect("read_line error");
    x
}

fn readnumvec() -> Vec<i32> {
    let mut s = String::new();
    io::stdin().read_line(&mut s).ok();
    let mut s: Vec<&str> = s.split_whitespace().collect();
    let mut v: Vec<i32> = vec![];
    for i in (0..s.len()) {
        v.push(s[i].trim().parse().expect("parse error"));
    }
    v
}

fn main() {
    let mut v = readnumvec();
    println!("{}", if v[0]*v[1]<v[2] {v[0]*v[1]} else { v[2] });
}


Measured memory_bytes: 4352
//https://atcoder.jp/contests/panasonic2020/tasks/panasonic2020_b
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
const ll LINF = 0x1fffffffffffffff;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
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 main() {

  ll H,W; cin>>H>>W;
  ll x0=(H+1)/2;
  ll x1=(H)/2;
  ll y0=(W+1)/2;
  ll y1=(W)/2;  
  ll ans=x0*y0+x1*y1;
  if(H==1||W==1) ans=1;
  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#define MAX 1000001

int a[ MAX ] = {0};

int main( void ){
	int n;
	int counter;
	
	
	for( int i = 2; i <= MAX; i++ ){
		if( a[ i ] ){ continue; }
		for( int j = i * 2; j <= MAX; j += i ){
			a[ j ] = 1;
		}
	}
	
	while(1){
		scanf( "%d", &n ); 
		if(!n){break;}
		counter = 0;
		for( int i = 2; i <= n / 2; i++ ){
			int comp = n - i;
			if( !a[ i ] && !a[ comp ] ){
				counter++;
			}
		}
		printf( "%d\n", counter );
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>
#include<deque>

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

using namespace std;


//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用


int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	string s[2];
	cin >> s[0] >> s[1];
	if (s[0][0] == s[1][2] && s[0][1] == s[1][1] && s[0][2] == s[1][0])
	{
		cout << "YES";
	}
	else
	{
		cout << "NO";
	}
	cout << endl;

}

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

typedef long long int ll;

vector <ll> input;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
 
	ll i,j,t,k,l,m,n,x,y,z,c,a;

	cin >> n;

	for(i=0;i<n;i++)
	{
		cin >> k;
		input.push_back(k);
	}

	// sort(input.begin(),input.end());

	// for(i=0;i<n;i++)
	// 	cout << input[i] << " ";
	// cout << '\n';


	ll ans = 0;

	for(i=0;i<n;i++)
	{
		for(j=i+1;j<n;j++)
		{
			if(input[i] == input[j])
				continue;
			for(l=j+1;l<n;l++)
			{
				if(input[i]+input[j] > input[l] && input[i]+input[l] > input[j] && input[l]+input[j] > input[i])
				{
					if(input[i] != input[l])
					{
						if(input[j] != input[l])
						{
							// cout << i+1 << " " << j+1 << " " << l+1 << '\n';
							ans++;
						}
					}
					// ans++;
				}
			}


			// l = l-1;
			// if(input[i] == input[l])
			// 	continue;
			// if(input[j] == input[l])
			// 	continue;

			// ans += l-j;
		}
	}

	cout << ans << '\n';



 
	
	
 
}

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

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

	int l[100];
	for (int i = 0; i < n; i++){
		int k;
		cin >> k;
		l[i] = k;
	}
	for (int i = 0; i < n-1; i++){
		for (int j = 1; j <= n - i-1; j++){
			int tmp = l[j];
			l[j] = l[j - 1];
			l[j - 1] = tmp;

		}
	}

	for (int i = 0; i < n-1; i++)cout << l[i] << " ";
	cout << l[n - 1] << endl;

	return 0;
	}




Measured memory_bytes: 3092
k, n = map(int, input().split())
A = list(map(int, input().split()))
dis = []
for i in range(n):
    if i == 0:
        chk = k - A[n-1] + A[i]
        dis.append(chk)
    else:
        chk = A[i] - A[i-1]
        dis.append(chk)
dis_max = max(dis)
dis.remove(dis_max)
print(sum(dis))

Measured memory_bytes: 86352
#include<iostream>
#include<algorithm>
#include<string>
#include<functional>
#include<utility>
#include<stack>
#include<queue>
#include<cmath>
#include<list>
#include<cstdint>
#include<vector>
#include<map>
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
using namespace std;

unsigned long long int a = 0, b = 0, c = 1, x = 0, y = 0, z = 0, maxy = 0, mini = 9999, counter = 0;
std::vector<unsigned long long int> vec{}, vecsec{};
unsigned long long int iremono[101][101];
std::vector<std::string>str{};

bool okada = false;
std::string output, output2, input, nyahhoi;
char kakunou[101][101] = {};
int kakunou2[50][50] = {};
int ctoi(const char c) {
	if ('0' <= c && c <= '9') return (c - '0');
	return -1;
}
unsigned long long int LCM(unsigned long long int a, unsigned long long int b) {
	unsigned long long int i, j;
	i = a; j = b;
	while (true) {

		c = i % j;
		i = j;
		if (c != 0) {

			j = c;

		}
		else {
			break;
		}
	}
	return j * (a / j) * (b / j);
}
int main()
{
	cin >> a >> b>>c;
	cout << a * b / 2 << endl;
	}









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

#define ll long long

#define fr(i,a,b) for (ll i = (a), _b = (b); i <= _b; i++)
#define frr(i,a,b) for (ll i = (a), _b = (b); i >= _b; i--)
#define rep(i,n) for (ll i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (ll i = n - 1; i >= 0; i--)
#define fill(ar,val) memset(ar, val, sizeof(ar))
#define fill0(ar) fill((ar), 0)
#define debug(x) cout<<#x<<": "<<x<<endl

#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<ii> vii;
typedef vector<int> vi;

#define INF 1000000000000000000
#define PI 3.14159265358979323846L

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

    ll n;
    cin >> n;	
    string s[n];

    ll x = 0;
    ll y = 0;
    ll z = 0;

    ll ans = 0;

    rep(i,n)
    {
    	cin >> s[i];
    	ll m = s[i].length();
    	if(s[i][0]=='B' && s[i][m-1]=='A')
    		z++;
    	else if(s[i][0]=='B')
    		y++;
    	else if(s[i][m-1]=='A')
    		x++;

    	bool hu = 0;
    	rep(j,m)
    	{
    		if(s[i][j]=='A')
    		{
    			hu = 1;
    		}
    		else if(s[i][j]=='B')
    		{
    			if(hu)
    				ans++;
    			hu = 0;
    		}
    		else
    		{
    			hu = 0;
    		}
    	}
    }

    if(z>0)
    {
   		ans = ans + z-1;
   		if(x>0)
	   	{
	   		ans++;
	   		x--;
	   	}
	   	if(y>0)
	   	{
	   		ans++;
	   		y--;
	   	}
    }
   	
   	ans = ans + min(x,y);

    cout << ans << endl;
}


Measured memory_bytes: 768
#include<stdio.h>
int main(void)
{
	int n,a,b,c,d;
	scanf("%d",&n);
	scanf("%d",&a);
	scanf("%d",&b);
	d=n*a;
	if(d>b){
	c=b;
	}
	else{
	c=d;
	}
	printf("%d\n",c);
	return 0;
}

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

int main()
{
    long long int n,weight;
    cin>>n>>weight;
    long long int ar[n],w[n];
    for(int i=0;i<n;i++)
    {
        cin>>w[i]>>ar[i];
    }
    long long int dp[n+1][weight+1];
    long long int i,j;
    for(i=0;i<=n;i++)
    {
        for(j=0;j<=weight;j++)
        {
            if(i==0 || j==0)
                dp[i][j]=0;
        }
    }
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=weight;j++)
        {
            dp[i][j]=dp[i-1][j];
            if(j>=w[i-1])
            {
                dp[i][j]=max(dp[i][j],ar[i-1]+dp[i-1][j-w[i-1]]);
            }
        }
    }
    cout<<dp[n][weight];
    return 0;
}


Measured memory_bytes: 82332
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
using namespace std;

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,-1,0,0,1,1,-1,-1};
vector<ll>dy={0,0,1,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>&p){
  return os << p.first << " " << p.second;
}
//mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll n;cin>>n;
  string s;cin>>s;
  reverse(ALL(s));
  ll cnt=0;
  for(auto c:s)if(c=='1')cnt++;
  ll k1=0,k2=0,n1=1,n2=1;
  vector<ll>b1(n),b2(n);
  rep(i,0,n){
    if(cnt>=1)b1[i]=n1;
    if(cnt>=3)b2[i]=n2;
    if(s[i]=='1'){
      if(cnt>=1)k1=(k1+n1)%(cnt+1);
      if(cnt>=3)k2=(k2+n2)%(cnt-1);
    }
    n1=(n1*2)%(cnt+1);
    if(cnt>=2)n2=(n2*2)%(cnt-1);
  }
  vector<ll>a(n),ret(n);
  rep(i,0,n){
    if(s[i]=='0'){
      a[i]=(k1+b1[i])%(cnt+1);
      ret[i]=1;
    }
    else{
      if(cnt==1){
        a[i]=0;
        ret[i]=0;
      }
      else{
        a[i]=(k2-b2[i]+cnt-1)%(cnt-1);
        ret[i]=1;
      }
    }
  }
  rrep(i,0,n){
    while(a[i]){
      ll tmp=__builtin_popcountll(a[i]);
      a[i]%=tmp;
      ret[i]++;
    }
    cout<<ret[i]<<endl;
  }
  return 0;
}

Measured memory_bytes: 9656
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int go(int direction)
{
    if(direction == 0 )
    {
        return 1;
    }else if(direction == 1)
    {
        return 1;
    } else if(direction == 2)
    {
        return  -1;
    }else if(direction == 3)
    {
        return  -1;
    }
};

pair<int, int> nextDirection(int direction)
{
    if(direction == 0)
    {
        return {1, 3};
    }else if(direction == 1)
    {
        return {2, 0};
    }else if(direction == 2)
    {
        return {3, 1};
    }else if(direction == 3)
    {
        return {0, 2};
    }
};

void d()
{
    string s;
    cin >> s;
    int x, y;
    cin >> x >> y;
    vector<int> xaxis, yaxis;
    bool state = true;
    int count = 0;
    for (int i = 0; i < s.size(); ++i) {
        if(s[i] == 'T')
        {
            if(state)
            {
                xaxis.push_back(count);
            }else{
                yaxis.push_back(count);
            }
            count = 0;
            state = !state;
        }else{
            count++;
        }
    }
    if(state)
    {
        xaxis.push_back(count);
    }else{
        yaxis.push_back(count);
    }
    vector<int> dpx(16001, 0);
    vector<int> dpy(16001, 0);
    dpx[0 + 8000] = 1;
    dpx[0 + 8000 + xaxis[0]] = 1;
    for(int i = 1; i < xaxis.size(); i++)
    {
        vector<int> next(16001, 0);
        for(int j = 0; j <= 16000; j++)
        {
            if(dpx[j] == 1) {
                next[j + xaxis[i]] = 1;
                next[j - xaxis[i]] = 1;
            }
        }
        dpx = next;
    }
    dpy[0 + 8000] = 1;
    for(int i = 0; i < yaxis.size(); i++)
    {
        vector<int> next(16001, 0);
        for(int j = 0; j <= 16000; j++)
        {
           if(dpy[j] == 1)
           {
               next[j + yaxis[i]] = 1;
               next[j - yaxis[i]] = 1;
           }
        }
        dpy = next;
    }
    if(dpx[x + 8000] == 1 && dpy[y + 8000] == 1)
    {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

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


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ll long long
const int maxn=1e5+10;
using namespace std;
int n,m,k,t;
char a[maxn];
bool flag;
int l=-1,r=-1;
int main()
{
    int i,j;
    scanf("%s",a);
    int len=strlen(a);
    for(i=0;i<len-1;i++)
    {
        if(i<len-2&&a[i]==a[i+2])flag=true,l=i+1,r=i+3;
        if(a[i]==a[i+1])flag=true,l=i+1,r=i+2;
        if(flag)break;
    }
    printf("%d %d\n",l,r);
    //system("pause");
    return 0;
}


Measured memory_bytes: 384
//
// Created by 吉川純平 on 2019-12-01.
//

#include <bits/stdc++.h>
using namespace std;
//using ll = long long;
//using ull = unsigned long long;
#define ll long long
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 (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll tmp1,tmp2,tmp3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;
void swap(ll *x,ll *y){
  ll tmp;
  tmp = *x;
  *x = *y;
  *y = tmp;
}
ll ans;
void merge(vector<ll>&A,ll left,ll mid,ll right){
  ll n1 = mid - left;
  ll n2 = right - mid;
  vector<ll> L(n1+1),R(n2+1);
  rep(i,n1){
    L[i] = A[left+i];
  }
  rep(i,n2){
    R[i] = A[mid+i];
  }
  L[n1] = INFLONG;
  R[n2] = INFLONG;
  ll i = 0;
  ll j = 0;
  for(ll k = left;k < right;k++){
    if(L[i] <= R[j]){
      A[k] = L[i];
      i++;
    }else{
      A[k] = R[j];
      j++;
    }
    ans++;
  }
}

void mergeSort(vector<ll> &vec, ll left, ll right){
//  rep(i,10){
//    cout << vec[i];
//    if(i != 10-1){
//      cout << " ";
//    }
//  }
  //cout << endl;
  if(left+1 < right){
    ll mid = (left+right) / 2;
    mergeSort(vec,left,mid);
    mergeSort(vec,mid,right);
    merge(vec,left,mid,right);
  }
}

int main(){
  ll n;
  cin >> n;
  vector<ll> vec(n);
  rep(i,n){
    cin >> vec[i];
  }
  ans = 0;
  mergeSort(vec,0,n);
  rep(i,n){
    cout << vec[i];
    if(i != n-1){
      cout << " ";
    }
  }
  cout << endl;
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 10572