akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

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


namespace eratosthenes_sieve{
  constexpr int MAX = 300000;
  bool is_prime[MAX+1];

  __attribute__((constructor)) void init(){
    std::fill(is_prime, is_prime+MAX+1, true);
    is_prime[0] = is_prime[1] = false;

    for(int i = 2; i <= MAX; ++i){
      if(is_prime[i]){
        for(int j = 2*i; j <= MAX; j += i){
          is_prime[j] = false;
        }
      }
    }
  }
}



int main(){
  int x;
  while(cin >> x){

    int ans;
    FORE(i,x,300000){
      if(eratosthenes_sieve::is_prime[i]){
        ans = i;
        break;
      }
    }

    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define int long long // at least int64 > 9*10^18
#define ENDL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using namespace std;

signed main () {
  int N ;
  cin>>N;
  vector<int> vec(N);
  rep(i,N){
    cin>>vec.at(i);
  }
  int count = 0 ;
  rep(i,61){
    bool b = false ;
    rep(j,N){
      if(vec.at(j)%2==1){
        b = true;
        break;
      }
      vec.at(j) /= 2 ;
    }
    if(!b){
      count++;
    }
    else{
      break;
    }
  }
  cout<<count<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std; 
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
typedef long long ll;
typedef long double ld;


int main(){
  string s; cin>>s;
  ll K; cin >>K;
  int p = 0;
  REP(i,s.size() ){
    if(s[p]=='1'){p++;}
    else{break;}
  }
  char r;
  if(p>=K) r = '1';
  else r = s[p];
  cout<<r<<"\n";
}


Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;
class Main{
	public static void main(String[] args)throws NumberFormatException, IOException{
		//System.out.print(" ");
		Scanner scan = new Scanner(System.in);
		int n =scan.nextInt();
		int m =scan.nextInt();
		int l =scan.nextInt();
		int A[][] = new int[100][100];	//[???][?¨?]
		int B[][] = new int[100][100];
		long keisan = 0;

		for(int i =0; i<n; i++){	//??????A?????????
			for(int ii=0;ii<m;ii++){
				A[i][ii] = scan.nextInt();
			}
		}

		for(int i=0;i<m;i++){	//??????B?????????
			for(int ii=0;ii<l;ii++){
				B[i][ii] = scan.nextInt();
			}
		}

		for (int i=0; i<n; i++){	//?¨????????????????C???
			for(int ii=0; ii<l; ii++){
				keisan = 0;
				for(int iii=0; iii<m; iii++){
					keisan += A[i][iii] * B[iii][ii];
				}
				System.out.print(keisan);
				if(ii < l-1){
					System.out.print(" ");
				}
			}
			System.out.println("");
		}
	}
}

Measured memory_bytes: 55052
import itertools

n = int(input())
num1 = list(map(int, input().split()))
num2 = list(map(int, input().split()))

i = 0
for x in itertools.permutations(range(1,n+1)):
  i += 1
  if list(x)==num1:
    a = i
  if list(x)==num2:
    b = i

print(abs(a-b))

Measured memory_bytes: 3064
/*
 * Author:  xioumu
 * Created Time:  2012/10/9 14:23:22
 * File Name: g.cpp
 * solve: g.cpp
 */
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
#define sz(v) ((int)(v).size())
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repf(i, a, b) for (int i = (a); i <= (b); ++i)
#define repd(i, a, b) for (int i = (a); i >= (b); --i)
#define clr(x) memset(x,0,sizeof(x))
#define clrs( x , y ) memset(x,y,sizeof(x))
#define out(x) printf(#x" %d\n", x)
typedef long long lint;
const int maxint = -1u>>1;
const double esp = 1e-8;
const int maxn = 100 + 10;
int e[maxn][maxn];
int n, m, ans;
int v[maxn];
void dfs(int w) {
    if(w == n + 1) return;
    dfs(w + 1);
    repf (i, 1, w - 1)
        if(v[i] && e[i][w] == 0)
            return ;
    v[w] = 1;
    int res = 0;
    repf (i, 1, w) {
        if(!v[i]) continue;
        int h = maxint;
        repf (j, 1, w) {
            if(i == j) continue;
            if(v[j])
                h = min(e[i][j], h); 
        }
        if(h == maxint) h = 0;
        res += h;
    }
    ans = max(res, ans);
    dfs(w + 1);
    v[w] = 0;
}
int main() {
    while(scanf("%d%d", &n, &m) == 2) {
        memset(e, 0, sizeof(e));
        ans = 0;
        memset(v, 0, sizeof(v));
        rep (i, m) {
            int x, y, z;
            scanf("%d%d%d", &x, &y, &z);
            e[x][y] = e[y][x] = z;
        }
        dfs(1);
        printf("%d\n", ans);
    }
    return 0;
}

Measured memory_bytes: 1248
#include<iostream>
#include<string>
using namespace std;
int main(){
	int a[10];
	for(int i=0;i<10;i++)
		cin>>a[i];
	for(int i=0;i<9;i++){
      for(int j=9;j>i;j--){
	    if(a[j]>a[j-1]){
	    int t=a[j];
	    a[j]=a[j-1];
	    a[j-1]=t;
	   }
      }
    }
	cout<<a[0]<<endl;
	cout<<a[1]<<endl;
	cout<<a[2]<<endl;
	return 0;
}

Measured memory_bytes: 1164
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
	int R = 0;

	scanf("%d", &R);

	if (R < 1200) {
		printf("ABC");
	}
	else if (1200 <= R && R< 2800) {
		printf("ARC");
	}
	else if (2800 <= R) {
		printf("AGC");
	}

	return 0;
}

Measured memory_bytes: 128
M, D = [int(_) for _ in input().split()]

ans = 0
for m in range(1, M + 1):
    for d in range(22, D + 1):
        d10, d1 = [int(_) for _ in str(d)]
        if d1 < 2: continue

        ans += int(d1 * d10 == m)
print(ans)

Measured memory_bytes: 3060
#include<stdio.h>
int main(){

  char a[20];
  int i,j,mark=0,flag,n=0,m=0;

  for(i=0;i<20;i++){

    scanf("%c",&a[i]);
    n++;
    if(a[i]=='\n')break;

  }

  for(i=0;i<n;i++){

    if(mark==0 && a[i]=='A'){
      flag=0;
      for(j=i;j<n;j++){
	if(a[j]=='Z'){
	  flag=1;
	}
      }
      if(flag==1){
	printf("A");
	m=1;
	mark=1;
      }
    }else if(mark==1 && a[i]=='Z'){
      printf("Z");
      m=1;
      mark=0;
    }
  }
  if(m==0)printf("-1");
  printf("\n");

  return 0;
}

Measured memory_bytes: 524
#include <iostream>
#include <vector>
#include <set>

using namespace std;

typedef long long ll;

ll powmod(ll a,ll b,ll m)
{
	if(!b) return 1;
	ll x=powmod(a,b/2,m); x=(x*x)%m;
	if(b&1) x=(x*a)%m;
	return x;
}

int main()
{
	const int MOD=1e9+7;
	const int P=20130830;
	const int Q=powmod(P,MOD-2,MOD);
	
	vector<int> ps(300000,1);
	for(int i=1;i<ps.size();i++)
		ps[i]=(ll)ps[i-1]*P%MOD;
	
	for(int n,m;cin>>n>>m && n|m;){
		string s; cin>>s;
		
		set<pair<int,int> > hs; // len,hash
		int l=0,r=1;
		int hash=s[0];
		while(m--){
			string t; cin>>t;
			if(t=="L++")
				hash=((ll)hash-s[l++]+MOD)%MOD*Q%MOD;
			if(t=="L--")
				hash=((ll)hash*P+s[--l])%MOD;
			if(t=="R++"){
				hash=(hash+(ll)s[r]*ps[r-l])%MOD;
				r++;
			}
			if(t=="R--"){
				r--;
				hash=(hash-(ll)s[r]*ps[r-l]%MOD+MOD)%MOD;
			}
			hs.insert(make_pair(r-l,hash));
		}
		
		cout<<hs.size()<<endl;
	}
}

Measured memory_bytes: 16708
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
typedef long long lint;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
const lint MOD =998244353;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
typedef map<lint,lint> M;
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint 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(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    } 
    


  int main(){
      lint n,q;
      string s;
      char x;
      cin>>x;
      if('a'<=x&&x<='z')cout<<'a'<<endl;
      else cout<<'A'<<endl;
      
     }
     

  
 
  
      
      
    
 
  
          
  

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, lint> pll;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 100010;

typedef struct UnionFindTree{
    vector<int> par;

    UnionFindTree(int n){
        par.resize(n, -1);
    }

    bool is_root(int x){
        return par[x]<0;
    }

    int find(int x){
        if(is_root(x)) return x;
        return par[x] = find(par[x]);
    }

    int size(int x){
        return -par[find(x)];
    }

    bool unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y) return false;
        if(size(x) < size(y)) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }

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

int main(){
    int n, m;
    scanf("%d%d", &n, &m);
    UF uf(n);
    int ans = n;
    rep(i, m){
        int x, y, z;
        scanf("%d%d%d", &x, &y, &z);
        ans -= uf.unite(x-1, y-1);
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 640
#include <iostream>
#include "cstdio"
using namespace std;
long long a, b, k;
int main(int argc, char *argv[]) {
	cin>>a>>b>>k;
	if(k >= a)
	{
		k -= a;
		a = 0;
		b -= k;
		if(b < 0)	b = 0;
	}
	else
	{
		a -= k;
		if(a < 0)	a = 0;
	}
	printf("%lld %lld", a, b);
	return 0;
}

Measured memory_bytes: 256
n=int(input())
P=[]
M=[]
for i in range(n):
    x,y=map(int,input().split())
    P.append(x+y)
    M.append(x-y)
dP=abs(max(P)-min(P))
dM=abs(max(M)-min(M))
print(max(dP,dM))

Measured memory_bytes: 100364
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            int[] H = new int[N];
            for (int i = 0; i < N; i++) {
                H[i] = in.nextInt();
            }
            int count = 1;
            int max = H[0];
            for (int i = 1; i < N; i++) {
                if (max <= H[i]) {
                    count++;
                    max = H[i];
                }
            }
            out.println(count);
        }

    }
}



Measured memory_bytes: 24916
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}


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());

    int ans = INT_MAX;
    for (int i = 0; i < N - K + 1; i++) ans = min(ans, h[i + K - 1] - h[i]);

    cout << ans << endl;

}


























































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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

signed main(){

	lli n,m;
	cin>>n>>m;

	lli s[m];
	char c[m];
	REP(i,0,m){cin>>s[i]>>c[i];s[i]--;}

	REP(i,0,1000){
		string a = to_string(i);
		if(a.size()!=n)continue;
		bool flag=true;
		REP(j,0,m)if(a[s[j]] != c[j])flag = false;
		if(flag){
			cout<<i<<endl;
			return 0;
		}
	}
	cout<<-1<<endl;

	return 0;
}

Measured memory_bytes: 256
N,W=map(int,input().split())
I=[0]+[[*map(int,input().split())]for _ in[0]*N]
C=[[0]*-~W for _ in[0]*-~N]
for i in range(1,N+1):
 for w in range(1,W+1):
  C[i][w]=C[i-1][w]
  if w>=I[i][1]and I[i][0]+C[i-1][w-I[i][1]]>C[i-1][w]:
   C[i][w]=I[i][0]+C[i-1][w-I[i][1]]
print(C[N][W])


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

using ll=long long;



void solve(){
    int n,k;
    cin>>n>>k;
    if(k==1)cout<<0<<endl;
    else{
        n-=k;
        cout<<n<<endl;
    }   
}

signed main(){
    //while(1)
    solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll a, b, n;
  cin >> a >> b >> n;
  ll x = min(b-1, n);
  cout << a*x/b-a*(x/b) << endl;
  return 0;
}

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

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

cout<<a<<" "<<b<<" "<<c<<endl;
 
return 0;
}


Measured memory_bytes: 3120
#![allow(unused_imports)]
#![allow(unused_macros)]
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_variables)]
#![allow(unused_mut)]
#![allow(unused_assignments)]
use proconio::input;
use proconio::marker::Usize1;
use std::collections::*;
use std::cmp::*;
use std::f64::consts::*;

const MOD: u64 = 1000000007;
const INF: usize = std::usize::MAX / 4;

fn main() {
    input! {
        mut N: u64,
    }

    let mut ans = 0;
    let mut div = 2;

    while div * div <= N {
        let mut cnt = 0;
        while N % div == 0 {
            cnt += 1;
            N /= div;
        }
        let mut i = 1;
        while cnt >= i {
            ans += 1;
            cnt -= i;
            i += 1;
        }
        div += 1;
    }

    if N > 1 {
        ans += 1;
    }

    println!("{}", ans);
}


Measured memory_bytes: 2144
#include <iostream>
#include <math.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <stdlib.h>
#include <deque>  
#include <iomanip>

using namespace std;

using ll = long long;
#define INF 1e9
#define MOD 1e9 + 7
#define rep(i, n) for(int i = 0; i < n; i++)
#define loop(i, a, n) for(int i = a; i < n; i++)
#define all(in) in.begin(), in.end()
int main(){
    int a, b;
    cin >> a >> b;
    int ans = 0;
    if( a == b){
        ans = a + b;
    }else{
        ans = max(a, b) * 2 - 1;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds; 

#define int long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define f first
#define s second
#define sz(x) (int)x.size()
#define endl '\n'
#define forn(i,n) for(int i=0;i<n;++i)
#define fore(i,l,r) for(int i=int(l);i<=int(r);++i)
#define rep(i,begin,end) for(__typeof(end) i=(begin);i!=(end);i++)
#define fill(a,value) memset(a,value,sizeof(a));
#define gcd(a,b) __gcd((a),(b))
#define watch1(x) cout << (x) << endl
#define watch2(x,y) cout << (x) << " " << (y) << endl
#define watch3(x,y,z) cout << (x) << " " << (y) << " " << (z) << endl
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld; 
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update> oset;

// find_by_order(k) returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;

const int mod = 1e9 + 7;
const int inf = 9e18;
const int N = 1e5 + 5;

int i,x,a,b;

void solve(){
    cin>>x;
    map<int,int> mp;
    for(i=1;i*i*i*i*i<inf;++i){
        mp[i*i*i*i*i]=i;
    }
    for(i=1;i*i*i*i*i<inf;++i){
        if(mp[x+i*i*i*i*i]>0){
            cout<<mp[x+i*i*i*i*i]<<" "<<i;
            return;
        }
    }
    for(i=0;;--i){
        if(mp[x+i*i*i*i*i]>0){
            cout<<mp[x+i*i*i*i*i]<<" "<<i;
            return;
        }
    }
}

signed main(){
    fastio;
    int t;
    //cin>>t;
    t=1;
    while(t--){
        solve();
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 4416
# coding: utf-8
# Your code here!

import sys
from collections import deque, Counter
import bisect
import math
from itertools import accumulate, product, permutations, combinations, groupby
from fractions import gcd 
import heapq
sys.setrecursionlimit(10**6)
#input = sys.stdin.readline #文字列入力のときは注意

#n = int(input())
#s = input()
#a = [int(i) for i in input().split()]
#m = [[int(i) for i in input().split()] for j in range(n)] # 縦「n」行

n = int(input())
s = [input() for j in range(n)] # 縦「n」行
ans = 0
ba = 0
bc = 0
ca = 0
cc = 0
for ss in s:
    if ss[0]=="B" and ss[-1]=="A":
        ba += 1
    elif ss[0]=="B":
        bc += 1
    elif ss[-1]=="A":
        ca += 1
    else:
        cc += 1
    for i in range(len(ss)-1):
        if ss[i] == "A" and ss[i+1] == "B":
            ans +=1
#print(ans,ba,bc,ca)
if bc==0 and ca == 0:
    ans += max(ba - 1,0)
else:
    ans += min(bc,ca) + ba
    
print(ans)        





Measured memory_bytes: 71636
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <list>
#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=(ll)a.size()-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef long double ld;
using namespace std;
int main(){
	string s;
	cin >> s;
	string t = "";
	REP(i, s.size()){
		if(s[i] != 'x') t = t + s[i];
	}
	bool f = true;
	REP(i, t.size()){
		if(t[i] != t[t.size()-1-i]) f = false;
	}
	if(!f) cout << -1 << endl;
	else{
		int c[t.size()+1] = { };
		int cp = 0;
		REP(i, s.size()){
			if(s[i] == 'x') c[cp]++;
			else cp++;
		}
		int ans = 0;
		REP(i, t.size()+1){
			ans += abs(c[i] - c[t.size()-i]);
		}
		cout << ans/2 << endl;
	}
	return 0;
}


Measured memory_bytes: 1080
k = int(input())
arr = [0,1,2,3,4,5,6,7,8,9]

for i in range(1,k):
  num = arr[i]
  val = num*10 + num%10
  if val%10 != 0: arr.append(val - 1) #繰り下がりを回避
  arr.append(val)
  if val%10 != 9: arr.append(val + 1) #繰り上がりを回避

ans = arr[k]
print(ans)



Measured memory_bytes: 15764
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int llu;
#define vi vector<int>
#define vl vector<ll>
#define vp vector<pair<int,int>>
#define pb push_back
#define mp map<lli,lli>
#define INF 1000000000000000000
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
int main()
{
    int n;
    cin>>n;
    if(n%1000==0)
    {
        cout<<0;
    }
    else
    {
       cout<<1000-n%1000;   
    }
    return 0;
}


Measured memory_bytes: 3612
#include <stdio.h>

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

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

using namespace std;

#define sz(v)           ((int)((v).size()))
#define clr(v, d)       memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0; i<sz(v); ++i)
#define lp(i, n)        for(int i=0; i<(int)(n); ++i)
#define lpi(i, j, n)    for(int i=(j); i<(int)(n); ++i)
#define lpd(i, j, n)    for(int i=(j); i>=(int)(n); --i)
#define INF             1000000000

//#define DEBUG

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

int even[2], odd[2];

int main()
{
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	string str;
	cin >> str;
	n = sz(str);
	lp(i, n)
		if(i%2 == 0)
			++even[str[i] - '0'];
		else
			++odd[str[i] - '0'];
	cout << min(odd[0]+even[1], odd[1]+even[0]);
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 998244353;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
template< typename T >
T mod_pow(T x, T n, const T &p) {
  T ret = 1;
  while(n > 0) {
    if(n & 1) (ret *= x) %= p;
    (x *= x) %= p;
    n >>= 1;
  }
  return ret;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int n; cin >> n;
  map<int, int> mp;
  for(int i=0;i<n;++i) {
    int tmp; cin >> tmp;
    if(i == 0 && tmp != 0) {
      cout << 0 << endl;
      return 0;
    }
    mp[tmp]++;
  }
  if(mp[0] != 1) {
    cout << 0 << endl;
    return 0;
  }
  int now = 0;
  ll ans = 1;
  ll prev = -1;
  for(auto &e: mp) {
    if(e.first != now) {
      cout << 0 << endl;
      return 0;
    } else if(now != 0) {
      ans *= mod_pow<ll>(prev, e.second, MOD);
      ans %= MOD;
    }
    prev = e.second;
    now++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 4992
#include <iostream>
#include <map>
using namespace std;
 
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
 
    map<int, int> s;
    int n;
    for (cin >> n; n--;) {
        int x;
        cin >> x;
        s[x]++;
    }
    auto e = s.end(), i = s.find(1);
    int r = i != e && i->second == 1;
    if (s[1] == 0) {
        for (auto p : s) {
            if (p.second == 1) {
                int x = p.first;
                int i;
                for (i = 2; i * i <= x && (x % i || s.find(i) == e &&  s.find(x / i) == e); i++);
                if (i * i > x)
                    r++;
            }
        }
    }
    cout << r << '\n';
    return 0;
}


Measured memory_bytes: 12932
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
	string s,t;
	cin>>s>>t;
	
	for (int i=0;i<s.size();++i)
		if (t[i]==s[i])
			continue;
		else{
			cout<<"No"<<endl;
			return 0;
		}
		
	cout<<"Yes"<<endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <limits.h>
#include <bitset>
#define int long long
using namespace std;
using P = pair<int, int>;
using ll = long long;
using prique = priority_queue<int>;
const int MOD = 1000000007;
const int INF = LLONG_MAX/3;
const int MAX = 510000;

signed main(){
    int n,c;
    cin>>n>>c;
    int d[30][30];
    for(int i=0;i<c;i++){
        for(int j=0;j<c;j++){
            cin>>d[i][j];
        }
    }
    int g[500][500];
    int cnt[3][30]={};
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cin>>g[i][j];
            cnt[(i+j)%3][g[i][j]-1]++;
        }
    }
    int ans=INF;
    for(int i=0;i<c;i++){
        for(int j=0;j<c;j++){
            for(int k=0;k<c;k++){
                if(i==j||j==k||k==i)continue;
                int cn=0;
                for(int t=0;t<3;t++){
                    for(int s=0;s<c;s++){
                        if(t==0){
                            cn+=d[s][i]*cnt[t][s];
                        }else if(t==1){
                            cn+=d[s][j]*cnt[t][s];
                        }else{
                            cn+=d[s][k]*cnt[t][s];
                        }
                    }
                }
                ans=min(cn,ans);
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
typedef  long long int ll;
typedef pair<ll, ll> pll;
#define pb push_back
typedef long double ld;
#define fi first
#define se second
#define PI 3.14159265358979323846264338327950288419716939937510
#define mp make_pair
ll inf = 1e18;
ll p = 1e9 + 7;
ll power(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
ll pwr(ll x, ll y)
{
    ll res = 1;
    x = x ;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) ;
        y = y >> 1;
        x = (x * x) ;
    }
    return res;
}
ll modInverse(ll n, ll p)
{
    return power(n, p - 2, p);
}
int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll i, j, y, x,  z, w, g, key,  k, n, m, a, b;
    ll t2, t3, t4, t1, t5, t6;
    string s, t;

    cin >> n;
    ll arr[n];
    ll sum = 0;
    ll sq = 0;
    for (i = 0; i < n; i++)
    {
        cin >> arr[i];
        sum += arr[i];
        sq = (sq + arr[i] * arr[i]) % p;

    }
    sum %= p;
    sum = (sum * sum) % p;
    ll ans = ((sum - sq + p) % p) * modInverse(2, p);
    ans %= p;
    ans = (ans + p) % p;
    cout << ans;

    return 0;
}

Measured memory_bytes: 5220
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long 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;}

int main() {
    int n;
    cin >> n;
    vector<char>c(n);
    map<char,int>mp;
    rep(i,n) {
        cin >> c[i];
        mp[c[i]]++;
    }
    int ans = 0;
    
    rep (i,mp['R']) {
        if(c[i] == 'W')ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3624
#include <cstdio>

char s[200005], t[200005];

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


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

using namespace std;

#define all(x) x.begin(), x.end()
#define inf ((int) 1e9)
#define Linf ((long long) 1e18)

typedef long long ll;
typedef long double ld;

const int N = 123456;
const int M = 1234567;
const int P = 400004;
const int A = 256;

ll ncr(int n, int r){

	if(n < r)
		return 0;

	if(n < 0 || r < 0)
		return 0;

	if(n == r)
		return 1;

	return ncr(n - 1, r - 1) + ncr(n - 1, r);
}


void qsort(auto * a, int i, int j){

	if(i >= j) return;

	int l = i;
	int r = j;

	while(r > l){ 

		while(r > l && a[r] >= a[l]) r--;

		if(a[r] < a[l]){
			swap(a[r], a[l]);
		}

	}	

	qsort(a, i, r - 1);
	qsort(a, r + 1, j);

	return;
}


auto bpow(auto base, auto exp, auto MOD){

	ll ans = 1;
	for(; exp; exp>>=1){
		if(exp & 1)
			ans = (ans * base) % MOD;
		base = (base * 1ll * base) % MOD;
	}

	return ans;
}


int a[1111];
int gray, brown, green, cyan, blue, yellow, orange, red, uncharted;

int main(int argc, char const *argv[])
{
	
	#ifdef Cyborg1o1
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif	

	cin.sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;


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

		if(a[i] >= 1 && a[i] <= 399) gray++;
		else if(a[i] >= 400 && a[i] <= 799) brown++;
		else if(a[i] >= 800 && a[i] <= 1199) green++;
		else if(a[i] >= 1200 && a[i] <= 1599) cyan++;
		else if(a[i] >= 1600 && a[i] <= 1999) blue++;
		else if(a[i] >= 2000 && a[i] <= 2399) yellow++;
		else if(a[i] >= 2400 && a[i] <= 2799) orange++;
		else if(a[i] >= 2800 && a[i] <= 3199) red++;
		else uncharted++;
	}

	// sort(a, a + n);


	int CantChange = 0;

	CantChange = (gray? 1 : 0) + (brown ? 1 : 0) + (green ? 1 : 0) + (cyan ? 1 : 0) + (blue ? 1 : 0) + (yellow ? 1 : 0) + (orange ? 1 : 0) + (red ? 1 : 0);

	int mn = 0;
	int mx = 0;

	if(CantChange > 0)
		mn = mx = CantChange;

	if(uncharted > 0){
		if(CantChange == 0)
			mn = 1;
		mx = uncharted + CantChange;
	}

	cout << mn << " " << mx << endl;


	// int n;
	// cin >> n;

	// string str;
	// cin >> str;


	// stack<char> ss;

	// for(int i = 0; i < n; ++i){
	// 	if(str[i] == '(')
	// 		ss.push(str[i]);
	// 	else if(ss.size() && ss.top() != str[i])
	// 		ss.pop();
	// 	else
	// 		ss.push(str[i]);
	// }

	// if(!ss.empty()){

	// 	int left = 0, right = 0;
	// 	for(int i = 0; i < n; ++i)
	// 	{
	// 		if(str[i] == ')' && (!i || str[i - 1] != '(')) left++;
	// 		if(str[i] == '(' && (i == n - 1 || str[i + 1] != ')')) right++;
	// 	}


	// 	for(int i = 0; i < left; ++i)
	// 		str = '(' + str;

	// 	for(int i = 0; i < right; ++i)
	// 		str += ')';

	// }

	// cout << str << endl;

	return 0;					
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
    
#define int long long
    
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define FORR(i,m,n) for(int i=m;i>=n;i--)
#define pb(x) push_back(x) 
#define SORT(x) sort((x).begin(),(x).end())
#define INF 99999999999
    
using namespace std;
    
int dy[4]={1, 0, -1, 0};
int dx[4]={0, 1, 0, -1};

int v[4];

int srch(int u, vector<char> c, int n){
    if(n==3){
        if(u==7){
            cout << v[0];
            REP(i, 3) cout << c[i] << v[i+1];
            cout << "=7" << endl;
            return 1;
        }
        else return 0;
    }

    REP(i, 2){
        if(i==0){
            c[n]='+';
            if(srch(u+v[n+1], c, n+1)==1) return 1;
        }
        else{
            c[n]='-';
            if(srch(u-v[n+1], c, n+1)==1) return 1;
        }
    }
}

int32_t main(){
    string str;
    cin >> str;
    REP(i, 4) v[i] = str[i] - '0';

    vector<char> c(3, ' ');
    srch(v[0], c, 0);
}

Measured memory_bytes: 256
'use strict';

function Main(inputs) {
    const input = inputs.split(" ");
    const a = input[0];
    const b = input[1];
    let output = 'No';

    for (let c = 1; c <= 3; c++) {
        if ((a*b*c) % 2 == 1) {
            output = 'Yes';
            break;
        }
    }
    console.log(output);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long

using namespace std;
const int MAXN=100001;
int n,m;
int cnt[MAXN];
struct City{
	int num,P,Y,X;
}c[MAXN];
bool compY(City x,City y)
{
	return x.Y<y.Y;
}
bool comp(City x,City y)
{
	return x.num<y.num;
}
void out(int x)
{
	int sum=0,y=x;
	if(y==0)sum++;
	while(y)
	{
		sum++;
		y/=10;
	}
	for(int i=1;i<=6-sum;i++)
	{
		putchar('0');
	}
	printf("%d",x);
}
int main()
{
	scanf("%d%d",&n,&m);
	
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&c[i].P,&c[i].Y);
		c[i].num=i;
	}
	sort(c+1,c+m+1,compY);
	
	for(int i=1;i<=m;i++)
	{
		c[i].X=++cnt[c[i].P];
	}
	
	sort(c+1,c+m+1,comp);
	
	for(int i=1;i<=m;i++)
	{
		out(c[i].P);
		out(c[i].X);
		putchar('\n');
	}
	return 0;
}


Measured memory_bytes: 3456
n,y = map(int,input().split())
for i in range(n+1):
  for j in range(n+1):
    h = n-(i+j)
    if 10000 * i + 5000 * j + 1000 * h == y and h >= 0:
      print(i,j,h)
      exit()
print(-1,-1,-1)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pcc pair<char,char>
#define vi vector <int>
#define vl vector <ll>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d",x)
#define plld(x) printf("%lld",x)
#define pds(x) printf("%d ",x)
#define pllds(x) printf("%lld ",x)
#define pdn(x) printf("%d\n",x)
#define plldn(x) printf("%lld\n",x)
#define INF 2e9
#define INFLL 4e18
using namespace std;
ll powmod(ll base,ll exponent,ll mod){ // with mod < 1e9
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%mod;
		base=(base*base)%mod;
		exponent/=2;
	}
	return ans;
}
ll gcd(ll a, ll b){
	if(b==0) return a;
	else return gcd(b,a%b);
}
const int upperlimit = 1e6+100;
const int mod = 1e9+7;
ll arr[upperlimit];
int main() {
//	freopen(".in","r",stdin);freopen(".out","w",stdout);
	int n;
	sd(n);
	ll xr=0;
	for(int i = 1; i <= n; i++){
		slld(arr[i]);
		if(i>2) xr^=arr[i];
	}
	ll sm=arr[1]+arr[2];
	ll o=sm+xr;
	ll a=sm-xr;
	if(a&1){
		pd(-1);
		return 0;
	}
	o>>=1;a>>=1;
	ll check=o&a;
	if((check!=a)||(a>arr[1])){
		pd(-1);
		return 0;
	}
	int bits[60];
	for(int i = 0; i < 60; i++){
		bits[i]=(o&1);
		o>>=1;
	}
	for(int i = 59; i >= 0; i--){
		if(! bits[i]) continue;
		ll temp=1;
		for(int j = 1; j <= i; j++) temp<<=1;
		if(a&temp) continue;
		if((a^temp) <= arr[1]) a^=temp;
	}
	if(a) plld(arr[1]-a);
	else pd(-1);
	return 0;
}

Measured memory_bytes: 3820
N, M, X = map(int, input().split(' '))
price, exp, rst = [], [ [] for i in range(N) ], -1
for i in range(N):
    ls = list(map(int, input().split(' ')))
    price.append(ls[0])
    exp[i] = ls[1:]
for i in range(1 << N):
    price_combi, exp_combi, exp_sum, cnt_ls = [], [], [0] * M, []
    for j in range(N):
        if i >> j & 1:
            price_combi.append(price[j])
            exp_combi.append(exp[j])
    for s in exp_combi:
        for t in range(M):
            exp_sum[t] += s[t]
    [ cnt_ls.append(x) for x in exp_sum if x >= X ]
    if len(cnt_ls) == M:
        if rst == -1:
            rst = sum(price_combi)
        else:
            rst = min(rst, sum(price_combi))
print(rst)

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

char convert[256];

void init() {
	convert['r' + 'g'] = 'b';
	convert['g' + 'b'] = 'r';
	convert['b' + 'r'] = 'g';
}

string bfs(const string &worm) {
	typedef pair<string, int> state;

	const int n = worm.size();

	unordered_set<string> visited{worm};
	queue<state> que;
	que.push({worm, 0});


	while(!que.empty()) {
		const auto s = que.front().first;
		const auto d = que.front().second;
		que.pop();

		if(all_of(s.begin(), s.end(), [&](char c) { return c == s[0]; })) {
			return to_string(d);
		}

		for(int i = 0; i < n - 1; ++i) {
			if(s[i] != s[i + 1]) {
				string next(s);
				next[i] = next[i + 1] = convert[s[i] + s[i + 1]];

				if(!visited.count(next)) {
					visited.insert(next);
					que.push({next, d + 1});
				}
			}
		}
	}

	return "NA";
}

int main() {
	init();
	for(string worm; cin >> worm && worm != "0";) {
		cout << bfs(worm) << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 2436
#pragma GCC optimize(3)
#pragma GCC optimize("inline")
#pragma once
#include<bits/stdc++.h>
#define q register
typedef long long ll;
using namespace std;
ll a,b;
bool jud;
inline ll qread()
{
	q char ch=getchar();
	q ll v=0,sign=1;
	while(ch<'0'||ch>'9'){
		if(ch=='-')   sign=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		v=v*10+ch-'0';
		ch=getchar();
	}
	return v*sign;
}
inline void qwrite(ll v)
{
	if(v<0){
		putchar('-');
		v=-v;
	}
	if(v>9)   qwrite(v/10);
	putchar(v%10+'0');
}
inline bool jud_Num(ll h)
{
	return h%2;//是奇数 
}
inline ll Max(ll a,ll b)
{
	return a>b?a:b;
}
inline ll Min(ll a,ll b)
{
	return a<b?a:b;
}
int main()
{
	cin>>a>>b;
	if(a>0&&b>0){
		puts("Positive");
		   return 0;
	}
    if((a<=0&&b>=0)||(a>=0&&b<=0)){
    	puts("Zero");   
    	   return 0;
	}
	if((a<0&&b<0)||(a>0&&b>0)){
		ll a1=Max(a,b);
		ll b1=Min(a,b);
		jud=jud_Num(a1-b1);
		if(jud){
			puts("Positive");
			   return 0;
		}
		else{
			puts("Negative");
			   return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
// by Balloons
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define mpr make_pair
#define debug() puts("okkkkkkkk")
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)

using namespace std;

typedef long long LL;

const int inf = 1e9,mod=998244353;
char s[200005];
int dp[200005][4][4][2],n,a[200005];
int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	if(n<=3){
		if(n==2){
			if(s[1]==s[2])puts("1");
			else puts("2");
			return 0;
		}else{
			if(s[1]==s[2]&&s[2]==s[3])puts("1");
			if(s[1]==s[2]&&s[2]!=s[3])puts("6");
			if(s[1]!=s[2]&&s[2]==s[3])puts("6");
			if(s[1]!=s[2]&&s[1]==s[3])puts("7");
			if(s[1]!=s[2]&&s[2]!=s[3]&&s[1]!=s[3])puts("3");
		}
		return 0;
	}
	int su=0,ok=1,ok2=1;
	for(int i=1;i<=n;i++)a[i]=s[i]-'a',su+=a[i];
	for(int i=2;i<=n;i++)ok&=(a[i]!=a[i-1]),ok2&=(a[i]==a[i-1]);
	if(ok2)return puts("1"),0;
	for(int i=0;i<=2;i++)dp[1][i][i][0]=1;
//	for(int i=1;i<)
	for(int i=2;i<=n;i++){
		for(int j=0;j<=2;j++){
//			(dp[i][(j+a[i])%3][a[i]][1] += dp[i-1][j][a[i]][0]) %= mod; 
//			for(int l=0;l<=2;l++)
//				if(l!=a[i])(dp[i][(j+l)%3][l][0] += dp[i-1][j][a[i]][0]) %= mod;
			for(int l=0;l<=2;l++)
				for(int lst=0;lst<=2;lst++){
					if(l == lst)(dp[i][(j+l)%3][l][1] += dp[i-1][j][lst][0])%=mod;
					else (dp[i][(j+l)%3][l][0] += dp[i-1][j][lst][0])%=mod;
					(dp[i][(j+l)%3][l][1] += dp[i-1][j][lst][1]) %= mod;
				}
		}
	}
//	printf("2  %d\n",dp[2][])
	int ans=0;
	for(int i=0;i<=2;i++)(ans+=dp[n][su%3][i][1])%=mod;
	printf("%d\n",ans+ok);

	return 0;
}


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

long long patterns(int a){
  if(a == 0) return 1;
  else if(a == 1) return 1;
  else if(a == 2) return 2;
  else if(a % 2 == 0){
    return (patterns(a / 2) * patterns(a / 2) + patterns(a / 2 - 1) * patterns(a / 2 - 1)) % 1000000007;
  }
  else{
    return (patterns(a / 2) * patterns(a / 2 + 1) + patterns(a / 2 - 1) * patterns(a / 2)) % 1000000007;
  }
}

int main() {
  int n, m, i, skip = 1;
  long long ans = 1;
  cin >> n >> m;
  
  vector<int> a(m);
  for(i = 0; i < m; i++){
    cin >> a.at(i);
  }
  
  for(i = 1; i < m; i++){    
    if(a.at(i - 1) + 1 == a.at(i)){
      ans = 0;
      skip = 0;
      break;
    }
  }
  
  if(m == 0){
    ans = patterns(n);
    skip = 0;
  }
  
  if(m == 1){
    ans = patterns(a.at(0) - 1) * patterns(n - a.at(0) - 1);
    skip = 0;
  }
  
  if(skip){
    ans *= patterns(a.at(0) - 1);
    
    for(i = 1; i < m; i++){
      ans *= patterns(a.at(i) - a.at(i - 1) - 2);
      ans = ans % 1000000007;
    }
    
    ans *= patterns(n - a.at(m - 1) - 1);
  }
  
  cout << ans % 1000000007 << endl;
}


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

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<uint32_t> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cerr << #a << " = " << a << endl;

const double PI = acos(-1.0);
const LL INF = 1e9 + 47;
const LL LINF = INF * INF;
const int N = 100*1000+7;



int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	LL x,y;
	cin >> x >> y;
	if(x > y)
		swap(x,y);

	if(x+1 >= y)
		cout << "Brown";
	else
		cout << "Alice";

	return 0;
}


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

int main(){
    int n; cin >> n;
    vector<int> ingredients(n); for (int i=0;i<n;i++){cin >> ingredients[i];};
    sort(ingredients.begin(), ingredients.end());
    double m = ingredients[0];
    for (int i=1;i<n;i++){
        m = (m + ingredients[i]) / 2.0;
    }
    cout << m << endl;
}


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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a1, a2, a3;
  cin >> a1 >> a2 >> a3;
  if (a1 + a2 + a3 >= 22) {
    cout << "bust" << endl;
  } else {
    cout << "win" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/abc175/tasks/abc175_c
#include <iostream>
#include <vector>
#include <deque>
#include <tuple>
#include <algorithm>
#include <iterator> // std::back_inserter
#include <climits>
#include <sstream>

using namespace std;

typedef unsigned long ll;

ll n;

int main()
{
    ll AC=0, WA=0, TLE=0, RE=0;
    cin >> n;
    for (int i=0; i<n; i++) {
        string s;
        cin >> s;
        if (s == "AC") {
            AC++;
        }
        else if (s == "WA") {
            WA++;
        }
            else if (s == "TLE") {
            TLE++;
        }
        else if (s == "RE") {
            RE++;
        }
    }
    cout << "AC x " << AC << endl << "WA x " << WA << endl << "TLE x " << TLE << endl << "RE x " << RE <<endl;
}


Measured memory_bytes: 3588
#include <iostream>

using namespace std;

int main() {

  string s;
  
  cin >> s;
  
  string ans = "";
  
  for (int i = 0; i < s.size(); ++i) {
    if ((i + 1) % 2 != 0)
      ans += s[i];
  } 
  
  cout << ans << endl;

  return 0;
}

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

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
inline ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
int main() {
  int a, b;
  cin >> a >> b;
  cout << lcm(a, b) << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;

class Main{
        public static void main(String[] args){
                Scanner scn=new Scanner(System.in);
                int N=scn.nextInt();
                int[] a=new int[N+1];
                for(int i=0;i<N;i++){
                        a[i]=scn.nextInt();
                }
                a[N]=Integer.MAX_VALUE;
                Arrays.sort(a);
                a[N]=-1;
                int flag=1;
                int ans=0;
                for(int i=0;i<a.length-1;i++){
                        if(a[i]==a[i+1]){
                                flag++;
                        }else{
                                if(flag%2==1){
                                        ans++;
                                }
                                flag=1;
                        }
                }
                System.out.println(ans);
        }
}

Measured memory_bytes: 51872
import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = 0
for i in range(n):
    if b[i] - a[i] >= 0:
        ans += a[i]
        b[i] = b[i] - a[i]
        if b[i] - a[i+1] >= 0:
            ans += a[i + 1]
            a[i+1] = 0
        else:
            ans += b[i]
            a[i + 1] = a[i + 1] - b[i]
    else:
        ans += b[i]

print(ans)

Measured memory_bytes: 19228