akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <iomanip>
#include <map>
#include <queue>
#include <list>

#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
//#define RREP(i, n ,N) for(ll i = (N-1); i >= (n); i--)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
#define INF 1e9
#define vint vector<int>

using namespace std;
typedef long long  ll;

const long long MOD = 1e9+7;

int a[20];
int x[20][20];
int y[20][20];

int bit_counter(int x) {
    if(x == 0) return 0;
    return bit_counter(x >> 1) + (x & 1);
}

int main(){
    int n;
    cin >> n;
    for(int i=1;i<=n;i++){
        cin >> a[i];
        for(int j=1; j <= a[i]; j++){
            cin >> x[i][j] >> y[i][j];
        }
    }

    int ans = 0;
    //bit全探索
    for(int bits=1; bits < (1 << n); bits++){
        bool flag = true;
        for(int i=1; i <= n; i++){
            if(!(bits & (1 << (i-1)))) continue;
            // i番目の人(ビット)が1(正直のである)とするとき
            for(int j=1; j<=a[i]; j++){
                // i番目の人の証言が全て正しいか確認
                // i番目の人(ビット)が1について
                    // (bits & (1 << (i-1))と同じ(ビットを戻しる)
                if(((bits >> (x[i][j]-1)) & 1) ^ y[i][j]) flag = false;
                                        //　排他的論理和
                                        // 証言と一致していないならFalse
            }
        }
        if(flag) ans = max(ans, bit_counter(bits));
    }

    cout << ans << endl;
}

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

struct Order {
  int t;
  int id;
  int dest;
};

struct State {
  State() = default;
  explicit State(State* other)
    : t(other->t),
      position(-1),
      orders(other->orders),
      pick_up(other->pick_up),
      score(other->score),
      prev(other) {}

  int t = 0;
  int position = 0;
  vector<int> orders;
  int pick_up = 0;

  int score = 0;
  double estimation = 0;
  shared_ptr<State> prev;
};

int main() {
  int V, E;
  cin >> V >> E;
  vector<vector<int>> distance(V, vector<int>(V, -1));
  vector<vector<int>> neighbors(V);
  for (int i = 0; i < V; ++i)
    distance[i][i] = 0;
  for (int i = 0; i < E; ++i) {
    int u, v, d;
    cin >> u >> v >> d;
    --u;
    --v;
    distance[u][v] = d;
    distance[v][u] = d;
    neighbors[u].push_back(v);
    neighbors[v].push_back(u);
  }

  int T_max;
  cin >> T_max;
  vector<Order> orders;
  for (int t = 0; t < T_max; ++t) {
    int N;
    cin >> N;
    for (int i = 0; i < N; ++i) {
      int id, dest;
      cin >> id >> dest;
      orders.emplace_back(Order {t, id, dest - 1});
    }
  }

  mt19937 prg;
  int pos = 0;
  for (int t = 0; t < T_max;) {
    int next = neighbors[pos][prg() % neighbors[pos].size()];
    int d = distance[pos][next];
    for (int i = 0; i < d && t + i < T_max; ++i)
      cout << next + 1 << "\n";
    pos = next;
    t += d;
  }

  return 0;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    cout.tie(nullptr);
    lli i,n,a,b,c=0;
    cin>>n>>a>>b;
    c+=(n/(a+b))*a;
    n%=(a+b);
    if(n>a)
        c+=a;
    else
        c+=n;
    cout<<c;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/



typedef long long ll;
#define INF 1LL << 60
ll H, W;
//---------------------------------------------------------------------------------------------------
ll f(ll a, ll b, ll c) {
    ll ma = max(a, max(b, c));
    ll mi = min(a, min(b, c));
    return ma - mi;
}
//---------------------------------------------------------------------------------------------------
ll solA() {
    ll res = INF;
    if (2 < H) {
        ll h = H / 3;
        if (H % 3 == 0) return 0;
        res = min(res, W);
    }

    if (2 < W) {
        ll w = W / 3;
        if (W % 3 == 0) return 0;
        res = min(res, H);
    }

    return res;
}
//---------------------------------------------------------------------------------------------------
ll solB() {
    ll res = INF;

    rep(x, 1, W) {
        ll xx = x;

        ll b = H / 2;
        res = min(res, f(xx * b, xx * (H - b), (W - xx) * H));
    }

    rep(y, 1, H) {
        ll yy = y;

        ll b = W / 2;
        res = min(res, f(yy * b, yy * (W - b), (H - yy) * W));
    }

    return res;
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> H >> W;

    ll ans = min(solA(), solB());
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a,n,A[10000];
double now;
int main() {
	scanf("%d",&n);
	for(int i=1; i<=n; i++)
		scanf("%d",&A[i]);
	sort(A+1,A+n+1);
	now=A[1];
	for(int i=2; i<=n; i++)now=(now+A[i])/2.0;
	printf("%lf",now);
	return 0;
}

Measured memory_bytes: 256
n = int(input())
c = [[0 for j in range(10)] for i in range(10)]

for i in range(1,n+1):
    t = str(i)
    c[int(t[0])][int(t[-1])] += 1
    
ans = 0
for i in range(1,10):
    for j in range(1,10):
        ans += c[i][j]*c[j][i]
print(ans)

Measured memory_bytes: 9212
from collections import defaultdict as dd
N,M = map(int,input().split())
HH = list(map(int,input().split()))

make = set([])

hs_dic = dd(list)

for m in range(M):
    a,b = input().split()
    ah = HH[int(a)-1]
    bh = HH[int(b)-1]
    if ah > bh:
        make.add(b)
    elif ah < bh:
        make.add(a)
    
    hs_dic[a].append(b)
    hs_dic[b].append(a)

yoi = 0

keys = hs_dic.keys()
yoi += N - len(list(keys))

# print(yoi)

kkeys = set(keys) - make

# print(hs_dic.items())
# print(kkeys)

for kk in kkeys:
    bs = hs_dic[kk]
    ah = HH[int(kk)-1]
    ismax = 1
#     print("ah:",ah)
    for b in bs:
        bh = HH[int(b)-1]
#         print("---:",bh)
        if bh >= ah:
            ismax = 0
            break
    yoi += ismax
    
print(yoi)



Measured memory_bytes: 123160
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};
int main() {
  int N;
  cin >> N;
  bool t = false;
  for (int i = 1; i <= N; i++) {
    int price = i * 108;
    price /= 100;
    if (price  == N){
      cout << i << endl;
      return 0;
      t = true;
    }
  }
  if(!t){
    cout << ":(" << endl;
  }
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

int main() {
    int n;
    cin >> n;
    string s;
    s = to_string(n);
    int w = 0;
    for (int i = 0; i < s.size(); i++) {
        w += s[i] - '0';
    }

    if (n % w == 0) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
//#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n;
ll mod;
ll dp[100005];
vector<int>edge[100005];
ll ans[100005];
void dfs(int v,int u){
	dp[v] = 1;
	for(int i=0;i<edge[v].size();i++){
		int to = edge[v][i];
		if(to == u) continue;
		dfs(to,v);
		dp[v] = dp[v]*dp[to]%mod;
	}
	dp[v] = (dp[v]+1LL)%mod;
}
void dfs2(int v,int u,ll um){
	ans[v] = (dp[v]+mod-1)%mod*um%mod;
	vector<ll>vec,vec2;
	ll x = 1LL;
	for(int i=0;i<edge[v].size();i++){
		int to = edge[v][i];
		if(to == u) continue;
		x = x*dp[to]%mod;
		vec.pb(x);
	}
	x = 1LL;
	for(int i=0;i<edge[v].size();i++){
		int to = edge[v][edge[v].size()-1-i];
		if(to == u) continue;
		x = x*dp[to]%mod;
		vec2.pb(x);
	}
	int num = 0;
	for(int i=0;i<edge[v].size();i++){
		int to = edge[v][i];
		if(to == u) continue;
		ll vvv = um;
		if(num && num <= vec.size()) vvv = vvv*vec[num-1]%mod;
		int sz = vec2.size();
		if(sz-2-num >= 0) vvv = vvv*vec2[sz-2-num]%mod;
		vvv = (vvv+1LL)%mod;
		dfs2(to,v,vvv);
		num++;
	}
}
int main(){
	scanf("%d%lld",&n,&mod);
	for(int i=1;i<n;i++){
		int a,b; scanf("%d%d",&a,&b);
		edge[a].pb(b);
		edge[b].pb(a);
	}
	dfs(1,-1);
	dfs2(1,-1,1);
	for(int i=1;i<=n;i++) printf("%lld\n",(ans[i]%mod+mod)%mod);
}

Measured memory_bytes: 24064
#include <bits/stdc++.h>
using namespace std;
#define ref(i,x,y)for(int i=x;i<=y;++i)
#define def(i,x,y)for(int i=x;i>=y;--i)
#define pb push_back
#define fi first
#define se second
#define SZ(x) ((int)x.size())
typedef vector<int> vint;
typedef pair<int,int> PII;
int read(){
	char c=getchar();int d=0,f=1;
	for(;c<'0'||c>'9';c=getchar())if(c=='-')f=-1;
	for(;c>='0'&&c<='9';d=d*10+c-48,c=getchar());
	return d*f;
}
const int N=200010;
const int mod=998244353;
int n,m,a[N+1];
PII mk[N+1];
int main(){
	n=read();m=read();
	ref(i,1,n)a[i]=read();
	set<int> S;S.clear();
	ref(i,1,m)S.insert(a[i]);S.insert(1e9);
	int ri=0;
	for(int i=1;i<=n-m+1;++i){
		if(ri<i)ri=i-1;
		int la=-1e9;if(ri>=i)la=a[ri];
		while(ri<n&&a[ri+1]==*S.upper_bound(la))ri++,la=a[ri];
		mk[i].fi=ri+1;
		S.erase(a[i]);
		if(i+m<=n){
			S.insert(a[i+m]);
			while(ri>=i&&a[ri]>a[i+m])ri--;
		}
	}
	S.clear();
	ref(i,n-m+1,n)S.insert(a[i]);S.insert(-1e9);S.insert(1e9);
	int le=n+1;
	for(int i=n;i>=m;--i){
		if(le>i)le=i+1;
		int la=1e9;if(le<=i)la=a[le];
		while(le>1&&a[le-1]==*--S.lower_bound(la))le--,la=a[le];
		mk[i-m+1].se=le-1;
		S.erase(a[i]);
		if(i>m){
			S.insert(a[i-m]);
			while(le<=i&&a[le]<a[i-m])le++;
		}
	}
	ref(i,1,n-m+1)if(mk[i].fi>mk[i].se)mk[i].fi=mk[i].se=-1;
	sort(mk+1,mk+n-m+1 + 1);
	int ans=0;
	ref(i,1,n-m+1)if(mk[i]!=mk[i-1])ans++;
	cout<<ans<<endl;
}

Measured memory_bytes: 10368
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int,int> P;
int main()
{
  int N, M;
  cin >> N >> M;
  vector<int> A(N);
  long Max = 0;
  rep(i,N){
    cin >> A.at(i);
    Max += A.at(i);
  }
  int num = 0;
  rep(i,N){
    int a = A.at(i);
    double asigiri = (double)Max / (4 * (double)M);
    if(asigiri<=a)
      num++;
  }
  if(M<=num){
    puts("Yes");
  }else{
    puts("No");
  }
}

Measured memory_bytes: 256
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac
import bisect
import sys
import logging
import heapq
logging.basicConfig(level=logging.DEBUG)

input = sys.stdin.readline

setrecursionlimit(1000000)

def main():
    S=input()

    A=[0]*(len(S)-1)
    mode="L"
    s=0
    b=0
    e=0
    l=0
    for i in range(len(S)):
        c=S[i]
        if mode=="L" and c==mode:
            mode="R"
            b=i-1
        elif mode=="R" and c==mode:
            mode="L"
            e=i-1

            calc(A,s,b,e)
            
            s=i
        elif c=="\n":
            e=i-1
            calc(A,s,b,e)

    print(*A)

def calc(A, s, b, e):
    l=e-s+1

    A[b]=(b-s)//2+(e-b)//2+1
    A[b+1]=l-A[b]

main()

Measured memory_bytes: 77624
#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 =1000000007;
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);
    } 
    lint x[1005][5000];
  int main(){
     lint n,m;
     cin>>n>>m;
     lint a[m];
     lint b[m];
     rep(i,m){
         lint A,B;
         cin>>A>>B;
         a[i]=A;
         lint count=0;
         rep(j,B){
            lint c;
            cin>>c;
            --c;
            count+=pow(2,c);
         }
        b[i]=count;
     }
     rep(i,1005){
         rep(j,5000){
            if(j==0) x[i][j]=0;
            else x[i][j]=INF;
         }
     }

     rep(i,m){
         rep(j,5000){
             if((j|b[i])>4999)continue;    
             x[i+1][j|b[i]]=min(x[i+1][j|b[i]],x[i][j]+a[i]);
             x[i+1][j]=min(x[i][j],x[i+1][j]);
         }
     }
 
    if(x[m][(lint)pow(2,n)-1]==INF)cout<<-1<<endl;
    else cout<<x[m][(lint)pow(2,n)-1]<<endl;
    }
      
    
  

Measured memory_bytes: 43324
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

struct UnionFind{
    vector<int> par;
    vector<int> rank;
    vector<int> sz;
    int uf_size;

private:
    void init(int n = 1){
        par.resize(n);
        rank.resize(n);
        sz.resize(n);
        uf_size = n;
        for(int i=0; i<n; i++){
            par[i] = i;
            rank[i] = 0;
            sz[i] = 1;
        }
    }

public:
    UnionFind(int n = 1){
        init(n);
    }

    int find(int x){
        if(par[x] == x) return x;
        else return par[x] = find(par[x]);
    }
    
    bool same(int x, int y){
        return find(x) == find(y);
    }

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

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

int kruskal(int n, vector<T> &edge){
    sort(edge.begin(), edge.end());
    UnionFind uf(n);
    int res = 0;
    for(int i=0; i<edge.size(); i++){
        int cost, cv, nv;
        tie(cost, cv, nv) = edge[i];
        if(!uf.same(cv, nv)){
            uf.unite(cv, nv);
            res += cost;
        }
    }

    return res;
}

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

    int v, e; cin>>v>>e;
    vector<T> edge(e);
    for(int i=0; i<e; i++){
        int s, t, w; cin>>s>>t>>w;
        edge[i] = T(w, s, t);
    }

    cout << kruskal(v, edge) << endl;

    return 0;
}


Measured memory_bytes: 4276
import java.util.Scanner;
import java.util.ArrayList;

public class Main {
	Scanner sc = new Scanner(System.in);
	public void run(){
		while(true){
			int m = sc.nextInt();
			int t = sc.nextInt();
			int p = sc.nextInt();
			int r = sc.nextInt();
			if(m==0 && t==0 && p==0 && r==0) break;
			calc(m, t, p, r);
		}
	}
	public void calc(int m, int t, int p, int r){
		int[][] ptimes = new int[50][10];
		int[] rtimes = new int[50];
		int[] rnum = new int[50];
		
		for(int k = 0; k < r; k++){
			int mk = sc.nextInt();
			int tk = sc.nextInt();
			int pk = sc.nextInt();
			int jk = sc.nextInt();
			
			if(jk == 0){
				rtimes[tk-1] += mk + ptimes[tk-1][pk-1];
				rnum[tk-1] += 1;
			}
			else{
				ptimes[tk-1][pk-1] += 20;
			}
		}
		
		int beforetimes = 0;
		int beforenum = 0;
		int mintimes = Integer.MAX_VALUE;
		int maxnum = -1;
		int team = 0;
		int flug = 0;
		for(int i = 0; i < t; i++){
			for(int k = t; k > 0; k--){
				if(rnum[k-1] > maxnum){
					maxnum = rnum[k-1];
					mintimes = rtimes[k-1];
					team = k;
				}
				else if(rnum[k-1] == maxnum && rtimes[k-1] < mintimes){
					maxnum = rnum[k-1];
					mintimes = rtimes[k-1];
					team = k;
				}
			}
			if(flug == 0){
				flug = 1;
			}
			else{
				if(beforenum == maxnum && beforetimes == mintimes) System.out.print("=");
				else System.out.print(",");
			}
			System.out.print(team);
			beforetimes = mintimes;
			beforenum = maxnum;
			mintimes = Integer.MAX_VALUE;
			maxnum = -1;
			rnum[team-1] = -1;
			rtimes[team-1] = Integer.MAX_VALUE;
		}
		System.out.println();
	}
	
	public static void main(String[] args){
		new Main().run();
	}
	
}

Measured memory_bytes: 67664
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1LL<<60;
const int inf = 1e5;
//typedef long double ld;
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 dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
ll mo = 998244353;
map<ll,ll> ma;
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; }
int main(){
  ll l,r; cin >> l >> r;
  ll ans = INF;
  if(r-l+1>=2019){
    ans = 0;
  }else{
    rep(i,l,r+1){
      rep(j,i+1,r+1){
        chmin(ans, (i*j)%2019);
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
  int N;
  int A[210];
  int i;
  bool a=false;
  int count=0;
  cin >> N;
  for(i=0;i<N;i++){
      cin >> A[i];
  }
  while(a==false){
    for(i=0;i<N;i++){
        if(A[i]%2==1){
            a=true;
        }
        A[i]=A[i]/2;
    }
      count++;
  }
    cout << count-1 << endl;
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define pi 3.14159265359
#define all(i) i.begin(),i.end()
using namespace std;
const long long INF=1e9+7;
const string alp="abcdefghijklmnopqrstuvwxyz"; //26
const string ALP="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
//const ll MOD=998244353LL;
//const ll MOD=1777777777LL;


int main() {
  string s;
  cin>>s;
  ll ans=0;
  if(s=="RRR") ans=3;
  if(s=="SRR"||s=="RRS") ans=2;
  if(s=="RSS"||s=="SRS"||s=="SSR"||s=="RSR") ans=1;
  cout<<ans<<endl;
}


Measured memory_bytes: 3640
#![allow(non_snake_case)]

use std::io;
use std::cmp::min;

macro_rules! parse_tuple {
    ($($t: ty),+) => ({
        let mut a_str = String::new();
        io::stdin().read_line(&mut a_str).expect("read error");
        let mut a_iter = a_str.split_whitespace();
        (
            $(
                a_iter.next().unwrap().parse::<$t>().expect("parse error"),
            )+
        )
    })
}

fn main() {
    let (N,) = parse_tuple!(usize);

    let sum_digits = |x: usize| {
        let mut t = x;
        let mut sum = 0;
        while t > 0 {
            sum += t % 10;
            t /= 10;
        }
        return sum;
    };

    let mut min_sum = usize::max_value();

    for A in 1..N {
        min_sum = min(min_sum, sum_digits(A) + sum_digits(N - A));
    }

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

Measured memory_bytes: 4352
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn main() {
    let o: String = read();
    let e: String = read();

    let mut os = o.chars();
    let mut es = e.chars();

    loop {
        if let Some(l) = os.next() {
            print!("{}", l);
        } else {
            break;
        }

        if let Some(l) = es.next() {
            print!("{}", l);
        } else {
            break;
        }
    }
    println!("");
}


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

const double pi = 3.14159265358979323846;
const ll mod = 1000000007;


int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int n; cin >> n;
	vector<int> L(n);
	rep(i,n) cin >> L.at(i);
	sort(L.begin(), L.end());
	ll ans = 0;
	for(int i = n - 1; i >= 0; i--){
		for(int j = i - 1; j >= 0; j--){ //小さい辺となる2本を固定した(iの方がでかい)
			auto itr = lower_bound(L.begin(), L.end(), L.at(i) + L.at(j));
			ll ng = L.end() - itr;
			ans += (n - 1 - i) - ng;
		}
	} 
	cout << ans << endl;
} 

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<iterator>
#include<cmath>
#include<string>
#include<algorithm>
#include<sstream>
#include<queue>
#include<list>
#include<deque>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<chrono>


/*  auto start = high_resolution_clock::now();
auto stop = high_resolution_clock::now();
auto duration = duration_cast<milliseconds>(stop - start);
pr(duration.count());    */


#define FastIO      ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define pb          push_back
#define siz         100009
#define mp          make_pair
#define ll          long long int
#define inf         1000000007
#define fileout     freopen("output.txt","w",stdout)
#define filein      freopen("input.txt","r",stdin)
#define pi          acos(-1.0)
#define all(x)      x.begin(),x.end()
#define ull		    unsigned long long int
#define m(a)	    memset(a,0,sizeof(a))
#define f(i,n)	    for(ll i=0;i<n;i++)
#define sc(a)	    scanf("%lld",&a)
#define pr(a)	    printf("%lld\n",a)
using namespace std;
int main()
{
	FastIO;
	ll a,b,c,d,i;
	cin >> a>>b;
	d = 0;
	while (b--)
	{
		cin >> i;
		d = d + i;
	}
	if (d > a)
		cout << -1 << endl;
	else
		cout << a-d << endl;
	return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 100000000000000000


int main(){
	
	string s,t;
	cin>>s>>t;
	
	sort(s.begin(),s.end());
	sort(t.begin(),t.end(),greater<char>());
	
	if(s<t){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
	
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
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; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};
// int d[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  ll n;
  cin >> n;
  ll res = 0;
  for(ll i=1;i<=n;i++){
    ll x = n/i;
    res+=x*(x+1)*i/2;
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 3580
import bisect
n,m,k = map(int,input().split())
a= list(map(int,input().split()))
b= list(map(int,input().split()))
at=[0]
bt=[]
temp=0
for i in a:
    temp+=i
    at.append(temp)
temp=0
for i in b:
    temp+=i
    bt.append(temp)
ans=0
for i in range(len(at)):
    if at[i]>k:
        break
    ind= bisect.bisect_right(bt,k-at[i])
    ans= max(ans, ind+i)
print(ans)


Measured memory_bytes: 47536
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var S = cin.Read;
            var ans = 0;
            for(int i=0;i<S.Length/2; ++i){
                if(S[i]!=S[S.Length-1-i])ans++;
            }
            WriteLine(ans);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}


Measured memory_bytes: 13268
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		List<Long> tree = new ArrayList<>();
		for(int i = 0; i < N; i++) {
			tree.add(sc.nextLong());
		}
		Collections.sort(tree);
		long min = (long) Math.pow(10, 9);
		for(int i = 0; i < N - (K - 1); i++) {
			long tmp = tree.get(i + K - 1) - tree.get(i);
			min = Math.min(min, tmp);
		}
		System.out.println(min);
	}

}


Measured memory_bytes: 62660
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 +c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
int N;
struct node {
    int to,next;
}E[MAXN * 2];
int head[MAXN],sumE,col[MAXN];
bool flag = 0;
void add(int u,int v) {
    E[++sumE].to = v;
    E[sumE].next = head[u];
    head[u] = sumE;
}
void dfs(int u,int fa) {
    int s = 0;
    for(int i = head[u] ; i ; i = E[i].next) {
	int v = E[i].to;
	if(v != fa) {
	    dfs(v,u);
	    s += col[v];
	}
    }
    if(s == 0) col[u] = 1;
    if(s >= 2) flag = 1;
}
void Solve() {
    read(N);
    int a,b;
    for(int i = 1 ; i < N ; ++i) {
	read(a);read(b);
	add(a,b);add(b,a);
    }
    dfs(1,0);
    if(col[1] || flag) puts("First");
    else puts("Second");
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
}


Measured memory_bytes: 2560
import sys
import numpy as np
input = sys.stdin.readline

def main():
    N = int(input())
    v = np.array(list(map(int, input().split())))
    c = np.array(list(map(int, input().split())))

    tmp = sorted(v - c, reverse=True)
    ans = 0
    for i in range(N):
        if tmp[i] > 0:
            ans += tmp[i]
        else:
            break
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 13084
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <math.h>


using namespace std;


int main() {

	string s;
	int cnt = 0;
	int cot = 0;
	cin >> s;

	if (s[0] != 'A') {
		cout << "WA" << endl;
		return 0;
	}

	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'C') {
			cnt++;
		}
		if (cnt > 1) {
			cout << "WA" << endl;
			return 0;
		}
	}

	for (int i = 0; i < s.size(); i++) {
		if (s[i] >= 'A' && s[i] <= 'Z' ) {
			cot++;
		}
		if (cot > 2) {
			cout << "WA" << endl;
			return 0;
		}
	}

	for (int i = 2; i < s.size() - 1; i++) {
		if (s[i] == 'C') {
			cout << "AC" << endl;
			return 0;
		}
	}
	cout << "WA" << endl;

	return 0;

}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using AnsType = long long int;
const AnsType MOD = 1000000007;

const int MAXN = 100010;
AnsType dp[MAXN], N, K;
vector<int> G[MAXN];

void solve(int cur, int par=-1, int depth=1) {
    int m = max(0LL, K - min(depth, 2));
    for(auto to : G[cur]) {
        if(to == par) continue;
        dp[to] = m--;
        solve(to, cur, depth + 1);
    }
}

int main() {
    cin >> N >> K;
    for(int i=0; i<N-1; i++) {
        int u, v; cin >> u >> v;
        u--; v--;
        G[u].emplace_back(v);
        G[v].emplace_back(u);
    }

    dp[0] = K;
    solve(0);

    AnsType ans = 1;
    for(int i=0; i<N; i++) {
        (ans *= dp[i]) %= MOD;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = (0); i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define DEBUG(val) cout << #val << " : " << val << endl
#define MOD 1000000007

int main() {
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  int score = 0;
  REP(i, n - 1) {
    if (s[i] == s[i + 1]) score++;
  }
  cout << min(score + 2 * k, n - 1) << endl;
}

Measured memory_bytes: 3736
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        long[] A = new long[N];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextLong();
        }

        long L[] = new long[N + 1];
        long R[] = new long[N + 1];

        for (int i = 0; i < N; i++) {
            L[i + 1] = gcd(A[i], L[i]);
            R[N - i - 1] = gcd(A[N - i - 1], R[N - i]);
        }

        long[] MAX = new long[N];
        long max = 0;
        for (int i = 0; i < N; i++) {
            MAX[i] = gcd(L[i], R[i + 1]);

            if (max < MAX[i]) {
                max = MAX[i];
            }
        }

        System.out.println(max);
    }

    private static long gcd(long i, long j) {
        if (j == 0) {
            // recursive divide complete
            return i;
        }
        if (i % j == 0) {
            return j;
        } else {
            return gcd(j, i % j);
        }
    }
}


Measured memory_bytes: 62648
using System;
using System.Collections.Generic;
using System.Linq;
class Ho{
  static void Main(){
    var aho = Console.ReadLine().Split();
    var a =int.Parse(aho[0]);
    var b = int.Parse(aho[1]);
    if(a<b){
      for(var i = 0;i<b;i++){
        Console.Write(a);
      }
    }
    else{
    for(var i = 0;i<a;i++){
     Console.Write(b);
    }
    }
  }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MOD 1000000007
#define pr pair<int,int>
signed main()
{
    SPEED;
    int n,cnt=0;
    cin>>n;
    map <int,int> m;
    for(int i=2;i*i<=n;i++)
    {
        while(n%i==0)
        {
            m[i]++;
            n/=i;
        }
    }
    if(n>1)
    m[n]++;
    for(auto x:m)
    {
        int p=x.second;
        for(int i=1;i<=p;i++)
        {
            ++cnt;
            p-=i;
        }
    }
    cout<<cnt;
}

Measured memory_bytes: 3600
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

if a[0] + b[1] == a[1] + b[0] and a[2] + c[0] == a[0] + c[2] and b[2] + c[1] == b[1] + c[2]:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
/*********************************************************************************************/
/**                                                                                          //
//                            _ooOoo_                                                        //
//                           o8888888o                                                       //
//                           88" . "88                                                       //
//                           (| -_- |)                                                       //
//                            O\ = /O                                                        //
//                        ____/`---'\____                                                    //
//                      .   ' \\| |// `.                                                     //
//                       / \\||| : |||// \                                                   //
//                     / _||||| -:- |||||- \                                                 //
//                       | | \\\ - /// | |                                                   //
//                     | \_| ''\---/'' | |                                                   //
//                      \ .-\__ `-` ___/-. /                                                 //
//                   ___`. .' /--.--\ `. . __                                                //
//                ."" '< `.___\_<|>_/___.' >'"".                                             //
//               | | : `- \`.;`\ _ /`;.`/ - ` : | |                                          //
//                 \ \ `-. \_ __\ /__ _/ .-` / /                                             //
//         ======`-.____`-.___\_____/___.-`____.-'======                                     //
//                            `=---='                                                        //
//                                                       //                                  //
//         .............................................                                     //
//                  ·ð×æ±£ÓÓ             ÓÀÎÞBUG                                            //
********************************************************************************************/
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std;
const long long MOD=1000000009;
const long long mod = 1e5+50;
typedef long long ll;
long long a[mod],b[mod];
int main()
{
    long long t;
    cin>>t;
    while(t--)
    {
        long long a,b;
        cin>>a>>b;
        long long l=sqrt(a*b),cnt=0;
        cnt=(l-1)*2;
        if(l!=min(a,b)&&l*l<a*b)
        {
            cnt+=1;
        }
        if((a*b-1)/l>l)
            cnt+=1;
        if(l>min(a,b))
            cnt=cnt-1;
        cout<<cnt<<endl;
    }
    return 0;
}



Measured memory_bytes: 256
N, M = map(int, input().split())
L_ans = 1
R_ans = N
for _ in range(M):
    L, R = map(int, input().split())
    L_ans = max(L, L_ans)
    R_ans = min(R, R_ans)
    if L_ans > R_ans:
        print(0)
        exit()
print(R_ans - L_ans + 1)

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

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

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  string s;
  cin >> s;
  vector<string> e = {"dreamer", "eraser",
                      "dream", "erase"};
  int cur = s.size();
  while (cur > 0) {
    bool ok = false;
    string eee;
    for (string ee : e) {
      bool ok2 = true;
      for (int j = 0; j < ee.size(); j++) {
        if (cur - (int) ee.size() < 0) {
          ok2 = false;
          break;
        }
//        if (cur + j >= s.size()) {
//          ok2 = false;
//          break;
//        }
        if (s.at(cur - (int) ee.size() + j) != ee.at(j)) {
          ok2 = false;
          break;
        }
      }
      if (ok2) {
        eee = ee;
        ok = true;
        break;
      }
    }
    if (ok) {
      cur -= eee.size();
    } else {
      break;
    }
  }
  cout << (cur == 0 ? "YES" : "NO") << endl;
  return 0;
}


Measured memory_bytes: 512
package main

import (
    "fmt"

)



func main() {
	var N int
	var S, s1, s2 string
	fmt.Scan(&N, &S)
	i := 0
	j := N-1
	res := 0
	for {
		for {
			s1 = S[i: i+1]
			if (s1 == "W") {
				break
			}
			i++
			if (i > N-1){
				break
			}
		}
		if (i > N-1){
			break
		}

		
		for {
			s2 = S[j: j+1]
			if (s2 == "R") {
				break
			}
			j--
			if (j < 0) {
				break
			}
		}

		if i > j || j < 0{
			break
		} 



		res++
		i++
		j--
		
		
	}
	fmt.Println(res)

}


Measured memory_bytes: 3188
import bisect
N,M=map(int,input().split())
P=[]
Y=[]
li=[[] for i in range(N)]

for i in range(M):
    p,y=map(int,input().split())
    li[p-1].append(y)#p市の集合に追加
    P.append(p)
    Y.append(y)

for i in range(N):
    li[i].sort()

for p,y in zip(P,Y):
    zenhan="0"*(6-len(str(p)))+str(p)
    x=bisect.bisect_left(li[p-1], y)+1
    kouhan="0"*(6-len(str(x)))+str(x)
    print(zenhan+kouhan)




Measured memory_bytes: 75424
#include <iostream>

using namespace std;

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

    int dp[101][101];
    int N[101];
    for (int i = 1; i <= n; ++i) {
        cin >> N[i- 1] >> N[i];
    }

    for (int i = 1; i <= n; ++i) {
        dp[i][i] = 0;
    }

    for (int len = 2; len <= n ; ++len) {
        for (int i = 1; i <= n - len + 1; ++i) {
            int j = i + len - 1;
            dp[i][j] = (1 << 21);
            for (int k = i; k <= j - 1; ++k) {
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j] + N[i - 1] * N[k] * N[j]);
            }
        }
    }

    cout << dp[1][n] << endl;
    return 0;
}


Measured memory_bytes: 3124
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using Pair = pair<int64_t, int64_t>;
constexpr int64_t kInf = INT64_MAX / 2L;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int64_t N, M;
  cin >> N >> M;
  map<int64_t, int64_t> m;

  auto Add = [&](const int64_t value) {
    if (m.find(value) == m.end()) {
      m[value] = 1;
    } else {
      ++m[value];
    }
  };

  for (int64_t i = 0; i < N; ++i) {
    int64_t a;
    cin >> a;
    Add(a);
  }
  for (int64_t i = 0; i < M; ++i) {
    int64_t b, c;
    cin >> b >> c;
    while (b > 0) {
      auto itr = m.begin();
      const int64_t reduce = min(itr->second, b);
      if (c <= itr->first) {
        break;
      }
      b -= reduce;
      itr->second -= reduce;
      if (itr->second == 0) {
        m.erase(itr);
      }
      if (m.find(c) == m.end()) {
        m[c] = reduce;
      } else {
        m[c] += reduce;
      }
    }
  }
  int64_t result = 0;
  for (auto a : m) {
    result += a.first * a.second;
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 9816
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
  int N;
  cin >> N;
  vector<string> s(N);
  int cnt = 0;
  int typeA = 0; // Aでおわる
  int typeB = 0; // Bではじまる
  int typeC = 0; // BではじまってAでおわる
  for(int i=0; i<N; ++i)
  {
    string s;
    cin >> s;
    for(int n=0; n<s.size()-1; ++n)
    {
      if(s.substr(n,2) == "AB")
      {
        ++cnt;
      }
    }
    if(*s.begin() == 'B' && *(s.end()-1) == 'A')
    {
      ++typeC;
    }
    else
    {
      if(*s.begin() == 'B')
      {
        ++typeB;
      }
      if(*(s.end()-1) == 'A')
      {
        ++typeA;
      }
    }
  }
  bool endA = false;
  for(int i=0;;++i)
  {
    // 先頭
    if(i==0)
    {
      if(typeA)
      {
        --typeA;
        endA = true;
      }
      else if(typeC)
      {
        --typeC;
        endA = true;
      }
      else
      {
        break;
      }
    }
    else
    {
      // typeCを先に使う
      if(typeC)
      {
        --typeC;
        ++cnt;
      }
      // typeCがなくなったら交互に
      else if(endA && typeB)
      {
        typeB--;
        ++cnt;
        endA = false;
      }
      else if(typeA)
      {
        typeA--;
        endA = true;
      }
      else
      {
        // 使える部品がなくなったら終了
        break;
      }
    }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Debug_array(a,n) for (ll i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (ll i=(s); i<=(e); i++)
#define Fod(i,s,e) for (ll i=(s)-1; i>=(e); i--)
#define pii pair<ll,ll>
#define fi first
#define se second
#define endl "\n"
#define mp make_pair
#define big_prime 15486277
#define bigger_prime 179424697
#define biggest_prime 32416188691
//#define random_shuffle(indices.begin(), indices.end());
//std::random_device rd;
//std::mt19937 g(rd());
//std::shuffle(v.begin(), v.end(), g);
using namespace __gnu_pbds; 
using namespace std;
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
// template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 0
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE


typedef long long ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set; 

#define Mod 1000000007
#define MAX 5102

ll p = 31;
ll n;
string s;
ll S[MAX];

ll power(ll a,ll b){
	if(b==0) return 1;
	ll temp = power(a,b/2)%Mod;
	if(b%2==0){
		return (temp*temp)%Mod;
	}else{
		return (a*((temp*temp)%Mod))%Mod;
	}
}

bool check(ll k){
	ll hash = 0;
	ll x = 1;
	For(i,0,k){
		ll temp = (x*S[i])%Mod;
		hash = (hash+temp)%Mod;
		x = (x*p)%Mod;
	}

	queue<ll> q;
	q.push(hash);

	set<ll> s;

	For(j,k,n){
		if(q.size()==k){
			s.insert(q.front());
			q.pop();
		}
		hash = (hash-S[j-k]+Mod)%Mod;
		hash = (hash*power(p,Mod-2))%Mod;
		ll temp = (power(p,k-1)*S[j])%Mod;
		hash = (hash+temp)%Mod;

		if(s.find(hash)!=s.end()) return 1;
		q.push(hash);
	}
	return 0;
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	cin>>n;
	cin>>s;

	For(i,0,n){
		S[i] = (ll) s[i];
	}

	ll start = 1 , end = n;
	ll ans = 0;
	while(start<=end){
		ll mid = (start+end)/2;
		if(check(mid)){
			ans = mid;
			start = mid+1;
		}else{
			end = mid-1;
		}
	}
	cout<<ans<<endl;






























	
}

Measured memory_bytes: 592
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    // Your code here!
    int N, M, count = 0;
    int food[30][30] = {};
    
    cin >> N >> M;
    for(int i = 0; i < N; i++){
        int k;
        cin >> k;
        for(int j = 0; j < k; j++){
            int temp_food;
            cin >> temp_food;
            food[i][temp_food-1] = 1;
        }
    }

    for(int i = 0; i < M; i++){
        int temp_count = 0;
        for(int j = 0; j < N; j++){
            temp_count += food[j][i];
        }
        if(temp_count == N)
            count++;
    }
    
    cout << count << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <string.h>
#include <cmath>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int h[n];
    for (int i=0; i<n; i++) cin >> h[i];
    int d[n+1] = {0};
    d[0] = 0;
    for (int i=1; i<=n; i++) {
        if (h[i] <= h[i-1]) d[i] = d[i-1] + 1;
        else d[i] = 0;
    }
    int ans = *max_element(d, d+n);
    cout << ans << '\n';
    
    return 0;
}

Measured memory_bytes: 4348