akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
const int N=2e5+100;
int main()
{
    FASTINOUT;
    int x;
    cin>>x;
    if (x==25)
        cout<<"Christmas";
    else if (x==23)
        cout<<"Christmas Eve Eve";
    else if (x==24)
        cout<<"Christmas Eve";
    else
        cout<<"Christmas Eve Eve Eve";
    return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printe(*x):print("## ",*x,file=sys.stderr)
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    #N = int(input())
    N, M = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列

    edge = [[] for i in range(N)]
    for i in range(M):#木の場合M=N-1
        a,b = map(int,input().split())
        edge[a-1].append(b-1)
    S, T = map(int, input().split())
    S-=1;T-=1

    def dfs():
        q=deque([(0,S)])
        visited=[[False]*N for _ in range(3)]
        while len(q):
            
            d,e=q.popleft()#ここをpopleftにすると幅優先探索BFSになる
            
            if visited[d%3][e]:continue
            elif d%3==0:
                if e==T:
                    print(d//3)
                    return 
            visited[d%3][e]=True
            
            for ne in edge[e]:
                q.append((d+1,ne))
        print(-1)
    dfs()
    




if __name__ == "__main__":
    main()

Measured memory_bytes: 92664
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s,t;
  cin>>s>>t;
  int cnt=0;
  for(int i=0;i<s.size();i++){
    if(s[i]!=t[i])cnt++;
  }
  cout<<cnt<<endl;
  return 0;
}


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

int main() {
	// your code goes here
	int k, n;
	cin >> n >> k;
	int a[n];
	for(int i = 0 ;i  <n;++i)cin >> a[i];
	sort(a,a+n);
	int ans = 0;
	for(int i = 0;i <k;++i)ans += a[i];
	cout << ans <<endl;
	return 0;
}

Measured memory_bytes: 3640
#include<stdio.h>

int kotae(char);

int main(){
  int n,q,i,j,l,r,k;
  scanf("%d%d",&n,&q);
  int a[n];
  char s[n+1];
  scanf("%s",s);
  a[0]=0;
  for(i=1;i<n;i++){
    if(s[i-1]=='A'&&s[i]=='C'){
      a[i]=a[i-1]+1;
    }else{
      a[i]=a[i-1];
    }
  }
  for(k=0;k<q;k++){
    scanf("%d%d",&l,&r);
    if(l==0){l=1;}
    printf("%d\n",a[r-1]-a[l-1]);
  }
  return 0;
}


Measured memory_bytes: 1280
#include<stdio.h>
int main(){
	int a,b,c,d,n,i=0;

	while(1){


	scanf("%d",&n);
	if(getchar()==EOF)break;
	for(a=0;a<10;a++){
		for(b=0;b<10;b++){
			for(c=0;c<10;c++){
				for(d=0;d<10;d++){
					if(n==(a+b+c+d)){
						i++;
					}
				}
			}
		}
	}

			
	printf("%d\n",i);
	i=0;
}
	return 0;

}

Measured memory_bytes: 0
#include<iostream>
#include<fstream>
#include<string>
#include<stack>
#include<algorithm>

using namespace std;

struct item {
    int left;
    int area;
};

stack<int> leftNums;
stack<item> info;

int main()
{
    string input;
    cin >> input;
    for (int i = 0; i < input.length(); i++) {
        if ('\\' == input[i]) {
            leftNums.push(i);
        }
        else if (('/' == input[i]) && (!leftNums.empty())) {
            int currentLeft = leftNums.top();
            leftNums.pop();
            int currentArea = i - currentLeft;
            while ((!info.empty()) && (info.top().left > currentLeft)) {
                currentArea += info.top().area;
                info.pop();
            }
            item tempItem;
            tempItem.left = currentLeft;
            tempItem.area = currentArea;
            info.push(tempItem);
        }
    }

    int sum = 0;
    stack<int> output;
    while (!info.empty()) {
        item temp = info.top();
        info.pop();
        sum += temp.area;
        output.push(temp.area);
    }
    cout << sum << endl;
    cout << output.size();
    while (!output.empty()) {
        cout << " " << output.top();
        output.pop();
    }
    cout << endl;
    
    return 0;
}

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

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

  int min = INT_MAX;
  rep(i, N) {
    int A;
    cin >> A;

    int cnt = 0;
    for (int j = 1; A / (int)pow(2, j) >= 1; j++) {
      if (A % (int)pow(2, j) != 0) {
        break;
      }
      cnt++;
    }
    if (cnt < min) {
      min = cnt;
    }
  }

  cout << min << endl;
}



Measured memory_bytes: 256
use std::vec::Vec;
use std::cmp::max;

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 read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn read_touple<T: std::str::FromStr + Copy>() -> (T, T) {
  let v: Vec<T> = read_vec();
  assert_eq!(v.len(), 2);
  (v[0], v[1])
}

fn read_touple_3<T: std::str::FromStr + Copy>() -> (T, T, T) {
  let v: Vec<T> = read_vec();
  assert_eq!(v.len(), 3);
  (v[0], v[1], v[2])
}

// 0: r, 1: s, p: 2
fn main() {
    let (n, K) = read_touple::<usize>();
    let (r, s, p) = read_touple_3::<usize>();
    let mut t: Vec<char> = read::<String>().chars().collect();
    let rsp = vec![r, s, p];
    let mut kv = vec![Vec::new(); K];

    let u: Vec<usize> = t.into_iter()
         .map(|c| {
           if c == 'r' {
             2
           } else if c == 's' {
             0
           } else {
             1
           }
         }).collect();

    for i in 0..n {
      let j = i % K;
      kv[j].push(u[i]);
    }

    let mut ans: usize = 0;

    for i in 0..K {
      let x = dp_solve(&kv[i], &rsp);
      ans += x;
    }
    println!("{}", ans);
}

fn dp_solve(kv: &Vec<usize>, rsp: &Vec<usize>) -> usize {
  let n = kv.len();
  let mut dp = vec![vec![0; 3]; n];


  // init
  for i in 0..n {
    for j in 0..3 {
      if j == kv[i] {
         dp[i][j] = rsp[j];
      }
    }

    if i > 0 {
       dp[i][0] += max(dp[i-1][1], dp[i-1][2]);
       dp[i][1] += max(dp[i-1][0], dp[i-1][2]);
       dp[i][2] += max(dp[i-1][1], dp[i-1][0]);
    }
  }
  max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2]))
}

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

int main() {
    int N;
    cin >> N;
    vector<int>A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }

    for (int i = 0; i < N; ++i) {
        if (A[i] > i) {
            cout << -1 << "\n";
            return 0;
        }
    }

    ll ans = A.back();
    for (int i = N - 1; i > 0; --i) {
        if (A[i] - 1 > A[i-1]) {
            cout << -1 << "\n";
            return 0;
        } else if (A[i] - 1 == A[i-1]) {
            continue;
        } else {
            ans += A[i-1];
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 1152
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size)
#define MOD 1000000007
const long long mod = 1e9+7;
typedef vector<long long> Vl;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef long long ll;

int main(){
    int a=0,b=0,d=0,n=0,y=0;
    double c=0;
    string s,s1,s2;
    cin >> n >> d;
    VVI x(n,vector<int>(d,0));

    rep(i,n){
        rep(j,d){
            cin >>x[i][j];
        }
    }

    for (int i=0;i<n-1;i++){
        for (int j=i+1;j<n;j++){
            for (int k=0;k<d;k++){
                c += abs(x[i][k] - x[j][k]) * abs(x[i][k] - x[j][k]);
            }
            c = sqrt(c);
            if (ceil(c) == floor(c)){
                y++;
            }
            c=0;
        }
    }

    cout << y <<endl;

    return 0;
} 

Measured memory_bytes: 256
N, M = map(int, input().split())
M2 = M // N + 1 #最低2

ans = 1

for i in reversed(range(1, M2)):
  #print(i)
  if M % i == 0:# iがMの約数のとき、最大公約数となる可能性がある。
    Sho = M // i
    if Sho >= N:
      ans = i
      print(i)
      quit()
      
print(ans)



        

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

using namespace std;

typedef long long ll;

const int N = (int) 1e5;
int n, l[N], r[N], a[N], b[N];

int dist(int l, int r)
{
    if (l <= r)
    {
        return r - l + 1;
    }
    else
    {
        return 0;
    }
}

pair<int, int> v[N];

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

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

    ///freopen ("input", "r", stdin);

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

    if (n == 2)
    {
        cout << dist(l[0], r[0]) + dist(l[1], r[1]) << "\n";
        return 0;
    }

    vector<int> ls(n), rs(n);

    for (int i = 0; i < n; i++)
    {
        ls[i] = l[i];
        rs[i] = r[i];
    }

    sort(ls.rbegin(), ls.rend());
    sort(rs.begin(), rs.end());

    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        bool ok_l, ok_r;
        ok_l = (l[i] != ls[0] || ls[0] == ls[1]);
        ok_r = (r[i] != rs[0] || rs[0] == rs[1]);
        if (ok_l && ok_r)
        {
            ans = max(ans, dist(l[i], r[i]));
        }
    }

    ans += dist(ls[0], rs[0]);

    for (int i = 0; i < n; i++)
    {
        v[i].first = dist(ls[0], r[i]);
        v[i].second = dist(l[i], rs[0]);
    }
  ///  return 0;

    sort(v, v + n, cmp);

    multiset<int> sc;
    for (int i = 0; i < n; i++)
    {
        sc.insert(v[i].second);
    }

    int mnp = (1 << 30);
    for (int i = 0; i < n; i++)
    {
        auto it = sc.find(v[i].second);
        sc.erase(it);
        int mn = mnp;
        if (i == 0)
        {
            mn = min(mn, *sc.begin());
        }
        ans = max(ans, mn + v[i].first);
        mnp = min(mnp, v[i].second);
    }


    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 7296
s=list(input())
t=list(input())
cnt=0
newT=[]
ans=[]
for i in range(len(s)):
    try:
        cnt=0
        for j in range(len(t)):
            if s[j+i]==t[j]:
                cnt+=1
        
        ans.append(len(t)-cnt)
    except:
        break

print(min(ans))
    

Measured memory_bytes: 9104
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <deque>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <set>
using namespace std;
int main(void){
    string s;
    cin >> s;
    long long g=0,p=0;
    long long ans=0;
    for(int i=0;i<s.length();i++){
        if(s[i]=='g'){
            if(p+1<=g){
                p++;
                ans++;
            }else{
                g++;
            }
        }else{
            if(p+1<=g){
                p++;
            }else{
                g++;
                ans--;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d;
void check(){
	long long numc=b/c-a/c;
	long long numd=b/d-a/d;
	if(a%c==0)numc++;
	if(a%d==0)numd++;
	long long gbs=c/__gcd(c,d)*d;
	long long numgbs=b/gbs-a/gbs;
	if(a%gbs==0)numgbs++;
	long long ans=(b-a+1)-(numd-numgbs+numc);
	cout<<ans<<endl;
	return ;
}
int main()
{
	cin>>a>>b>>c>>d;
	if(c==1||d==1){
		cout<<0;
		return 0;
	}
	check();
	return 0;
}

Measured memory_bytes: 256
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    a, b, c = map(int, input().split())
    if ~a&1 or ~b&1 or ~c&1:
        print(0)
    else:
        print(min(a * b, b * c, c * a))
resolve()

Measured memory_bytes: 61756
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef double db;
#define fi first
#define se second
#define pb push_back
#define vi vector<int>
#define SZ(x) (int)(x.size())
#define sci(x) scanf("%d",&(x))
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define syn ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
ll modpow(ll x,ll n,ll mod){ll res=1;for(;n;n>>=1,x=x*x%mod)if(n&1)res=res*x%mod;return res;}
const db eps=1e-8,PI=acos(-1.0);
const int N=4e3+10,M=1e6+10,INF=0x3f3f3f3f,mod=1e9+7;//998244353
ll n,ans,pr[N],cnt;
ll fac(ll x){
	ll up=sqrt(x),ans=1;
	rep(i,2,up){
		if(x%i==0){
			int cnt=0;
			while(x%i==0)x/=i,cnt++;
			ans*=(cnt+1);
		}
	}
	if(x>1)ans*=2;
	ans--;
	return ans;
}
int main(){
	scanf("%lld",&n);
	if(n<=M){
		rep(k,2,n){
			ll x=n;
			while(x>=k){
				while(x%k==0)x/=k;
				x%=k;
			}
			ans+=(x==1);
		}
		printf("%lld\n",ans);
	}
	else{
		ans=1+fac(n-1);//n n-1
		ll up=(ll)sqrt(n);
		rep(k,2,up){
			if((n-1)%k==0)continue;
			ll x=n;
			while(x>=k){
				while(x%k==0)x/=k;
				x%=k;
			}
			ans+=(x==1);
		}
		printf("%lld\n",ans);
	}
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import functools
import itertools
import math
import sys

INF = float('inf')


def solve(S: str):
    return sum(S[i] != S[-(1 + i)] for i in range(len(S)//2))


def main():

    sys.setrecursionlimit(10 ** 6)

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    print(f'{solve(S)}')


if __name__ == '__main__':
    main()


Measured memory_bytes: 75100
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define INIT    \
    cin.tie(0); \
    ios::sync_with_stdio(false);

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

ll const INF = 1LL << 60;
ll const MOD = 1000000007;

int main() {
    INIT;
    ll H, W, K;
    cin >> H >> W >> K;
    vector<string> c(H);
    rep(i, H) cin >> c[i];

    vector<string> tmpc = c;
    ll ans = 0;
    ll cnt = 0;
    for (ll bh = 0; bh < (1 << H); bh++) {
        for (ll bw = 0; bw < (1 << W); bw++) {
            tmpc = c;
            rep(i, H) {
                if (bh & (1 << i)) {
                    for (ll j = 0; j < W; j++) {
                        tmpc[i][j] = 'R';
                    }
                }
            }

            rep(k, W) {
                if (bw & (1 << k)) {
                    for (ll m = 0; m < H; m++) {
                        tmpc[m][k] = 'R';
                    }
                }
            }

            cnt = 0;
            // cout << "---" << endl;
            rep(i, H) {
                rep(j, W) {
                    if (tmpc[i][j] == '#') {
                        cnt++;
                    }
                }
            }

            if (cnt == K) {
                ans++;
            }
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3648
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
class Program
{
    static void Main()
    {
        //入力
        //int n = 100;
        /*
        long n = long.Parse(Console.ReadLine());
        long[] input = new long[5];
        for(int a = 0; a < 5; a++)
        {
            input[a]=long.Parse(Console.ReadLine());
        }
        */
        int[] input = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray();
        Console.WriteLine(input[2] - input[1] - input[0]<=0 ? "Yes":"No");


        /*
        //処理速度計測
        var sw = new System.Diagnostics.Stopwatch();
        sw.Start();
        //解法
 
        //処理速度表示
        sw.Stop();
        TimeSpan ts = sw.Elapsed;
        Console.WriteLine((int)(Math.Floor((ts).TotalMilliseconds))+"ms");
        */
        Console.ReadLine();

    }
}

Measured memory_bytes: 13396
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let s = get!(String).chars().collect::<Vec<_>>();
    let mut count = 0usize;
    let mut i = 0;
    let mut anum = 0;
    let mut bcnum = 0;
    while i < s.len()-1 {
        match s[i] {
            'A' => {
                count += anum*bcnum;
                anum += 1;
                bcnum = 0;
                i += 1;
            },
            'B' => {
                if s[i+1] == 'C' {
                    bcnum += 1;
                    i += 2;
                } else {
                    count += anum * bcnum;
                    anum = 0;
                    bcnum = 0;
                    i += 1;
                }
            },
            'C' => {
                count += anum * bcnum;
                anum = 0;
                bcnum = 0;
                i += 1;
            },
            _ => (),
        }
    }
    println!("{}", count+anum*bcnum);
}


Measured memory_bytes: 8572
#include <cstdio>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <iostream>
#include <vector>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;
typedef long long ll;

struct UF {
  vector<int> data;
  int nDistinct;
  UF() {}
  UF(int n) : data(n, -1), nDistinct(n) {}
  void init(int n) { data.assign(n, -1); nDistinct = n; }
  int size(void) const { return nDistinct; }
  int rootOf(int a) { return data[a] >= 0 ? data[a] = rootOf(data[a]) : a; }
  int count(int a) { return -data[rootOf(a)]; }
  bool isSameGroup(int a, int b) { return rootOf(a) == rootOf(b); }
  bool unify(int a, int b) {
    int ra = rootOf(a), rb = rootOf(b);
    if(ra == rb) return false;
    if(data[ra] < data[rb]) swap(ra, rb);
    data[rb] += data[ra]; data[ra] = rb; --nDistinct;
    return true;
  }
};

struct E {
  int a, b;
};
E es[100000+10];

ll ans[100000+10];

int main(void) {
  int nNode, nEdge;
  scanf("%d%d", &nNode, &nEdge);
  REP(iEdge, nEdge) {
    E &e = es[iEdge];
    scanf("%d%d", &e.a, &e.b);
    e.a--;
    e.b--;
  }

  ans[nEdge] = ll(nNode) * (nNode - 1) / 2;
  UF uf(nNode);
  for(int i = nEdge-1; i >= 0; --i) {
    int a = es[i].a;
    int b = es[i].b;
    ll sa = uf.count(a);
    ll sb = uf.count(b);
    ans[i] = ans[i+1];
    if(uf.unify(a, b)) {
      ans[i] -= sa*sb;
    }
  }
  REP(i, nEdge) {
    printf("%lld\n", ans[i+1]);
  }
  
  return 0;
}


Measured memory_bytes: 3328
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
lint mo=1000000007;
lint gcd( lint m, lint n )
{
	lint a=max(m,n),b=min(m,n);
	if(m==0) return n;if(n==0) return m;
	if(a%b==0) return b;
	return gcd(b,a-b*(a/b));
}
lint zyo(lint x,lint y){
    lint ret=1,a=x;
    while(y>0){
    	if(y%2==1) ret=(ret*a)%mo;
    	a=(a*a)%mo;y/=2;
    }
    return ret;
}
int gya(int x){
	int ret=0;
	for(int i=1;i*i<=x;i++){
		if(x%i>0) continue;
		if(i%2==0) ret++;
		if(i*i<x && ((x/i)%2)==0) ret++;
	}
	return ret;
}
lint cal(lint x,lint y){
	lint ret=zyo(2,x)+zyo(2,y)-1;
	//if(x%2==0 && y%2==0) ret+=2;
	//lint gx=gya(x),gy=gya(y);
	//ret+=2*gx*gy;
	lint g=gcd(x,y);
	ret+=zyo(2,g)-2;ret+=mo;
	return ret%mo;
}
int main()
{
	lint h,w,t;
	cin>>h>>w>>t;
	lint gh=gcd(h,t),gw=gcd(w,t);
	cout<<zyo(cal(h/gh,w/gw),gw*gh)%mo<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

template <class T>
inline bool chmin(T &a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}

ll gcd(ll n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;


void solve()
{
	string t;
	cin>>t;
	int n=t.size();
	rep(i,n){
		if(t[i]=='?')t[i]='D';
	}
	cout<<t<<endl;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 3772
N=int(input())
b=[int(i) for i in input().split()]
ans=[]
M=N
while(M>0):
    j=-1
    for i in range(M)[::-1]:
        if b[i]==i+1:
            j=i
            break
    if j==-1:
        print(-1)
        exit()
    a=[]
    for i in range(M):
        if j!=i:
            a.append(b[i])
    ans.append(b[j])
    b=[i for i in a]
    M=len(b)
for line in ans[::-1]:
    print(line)


Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
using namespace std;
int A[128],N;
int main() {
	A[0] = 1;
	for (int i=1; i<=32; ++i){
		A[i] = A[i-1];
		if (i>=2) A[i] += A[i-2];
		if (i>=3) A[i] += A[i-3];
	}
	while(cin >> N && N) {
		cout << ((A[N]+9)/10+364)/365 <<endl;
	}
}

Measured memory_bytes: 1160
#include <stdio.h>
#define AMAX 100000

int partition(int*, int, int);
int main(){

  int i,n,A[AMAX],b;

  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&A[i]);

  b=partition(A,0,n-1);
  for(i=0;i<n-1;i++){
    if(i==b){
      printf("[%d] ",A[i]);
    }
    else printf("%d ",A[i]);
    
  }
  printf("%d",A[n-1]);
  printf("\n");
  
  return 0;
}

int partition(int* A, int p, int r){
  int tmp1,tmp2,x,i,j;
  
  x = A[r];
  i = p-1;
  for(j=p;j<r;j++){
    if(A[j]<=x){
      i = i+1;
      tmp1=A[j];
      A[j]=A[i];
      A[i]=tmp1;
    }
  }
  tmp2=A[i+1];
  A[i+1]=A[r];
  A[r]= tmp2;
  
  return i+1;
}


      



Measured memory_bytes: 2112
ls = []
ls2=[]
r,c = map(int,input().split())
for i in range(0, r):
    ls.append(list(map(int,input().split())))

for j in range(0, r):
    ls[j].append(sum(ls[j]))

for j in range(0, c+1):
    num = 0
    for k in range(0, r):
        num += ls[k][j]
    ls2.append(num)
ls.append(ls2)
for z in range(0, r+1):
    print(*ls[z])

Measured memory_bytes: 8212
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<set>
#include<vector>
#include<queue>
#include<ctime>
#define ll long long
#define pr(x) cerr<<#x<<"="<<x<<endl
using namespace std;
#define N 1000100
#define inf 100000000
#define ls (rt<<1)
#define rs (rt<<1|1)
struct node
{
	int a,b,id;
}p[N];
bool operator < (node x,node y)
{
	if (x.a==y.a) return x.b>y.b;
	return x.a>y.a;
}
priority_queue<node> que;
int n,i,a[N],cnt,pos[N],minn1[N<<3],minn2[N<<3];
vector<int> e[N],ans;
void build1(int rt,int l,int r)
{
	if (l==r)
	{
		minn1[rt]=inf;
		if (l&1) minn1[rt]=a[l];
		return ;
	}
	int mid=(l+r)/2;
	build1(ls,l,mid);
	build1(rs,mid+1,r);
	minn1[rt]=min(minn1[ls],minn1[rs]);
}
void build2(int rt,int l,int r)
{
	if (l==r)
	{
		minn2[rt]=inf;
		if ((l&1)==0) minn2[rt]=a[l];
		return ;
	}
	int mid=(l+r)/2;
	build2(ls,l,mid);
	build2(rs,mid+1,r);
	minn2[rt]=min(minn2[ls],minn2[rs]);
}
int query1(int rt,int l,int r,int x,int y)
{
	if (x<=l&&r<=y) return minn1[rt];
	int mid=(l+r)/2;
	int ret=inf;
	if(x<=mid) ret=min(ret,query1(ls,l,mid,x,y));
	if (y>=mid+1) ret=min(ret,query1(rs,mid+1,r,x,y));
	return ret;
}
int query2(int rt,int l,int r,int x,int y)
{
	if (x<=l&&r<=y) return minn2[rt];
	int mid=(l+r)/2;
	int ret=inf;
	if(x<=mid) ret=min(ret,query2(ls,l,mid,x,y));
	if (y>=mid+1) ret=min(ret,query2(rs,mid+1,r,x,y));
	return ret;
}
int solve(int l,int r)
{
	int tmpa,tmpb;
	if (l&1)
	{
		tmpa=query1(1,1,n,l,r);
		tmpb=query2(1,1,n,pos[tmpa],r);
	}
	else
	{
		tmpa=query2(1,1,n,l,r);
		tmpb=query1(1,1,n,pos[tmpa],r);
	}
	int posa=pos[tmpa],posb=pos[tmpb];
	p[++cnt].a=tmpa,p[cnt].b=tmpb,p[cnt].id=cnt;
	int cntt=cnt;
	if (posa!=l)
	{
		e[cntt].push_back(solve(l,posa-1));
	}
	if (posa+1!=posb)
	{
		e[cntt].push_back(solve(posa+1,posb-1));
	}
	if (posb!=r)
	{
		e[cntt].push_back(solve(posb+1,r));
	}
	return cntt;
}
int main()
{
	scanf("%d",&n);
	for (i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		pos[a[i]]=i;
	}
	build1(1,1,n);
	build2(1,1,n);
	solve(1,n);
	que.push(p[1]);
	/*for (i=1;i<=cnt;i++)
	{
		for (int j=0;j<(int)e[i].size();j++)
		{
			printf("%d->%d\n",i,e[i][j]);
		}
	}
	for (i=1;i<=cnt;i++)
	{
		printf("%d a=%d b=%d\n",i,p[i].a,p[i].b);
	}*/
	while (!que.empty())
	{
		int x=que.top().id;
		que.pop();
		printf("%d %d ",p[x].a,p[x].b);
		for (i=0;i<(int)e[x].size();i++)
		{
			que.push(p[e[x][i]]);
		}
	}
	return 0;
}

Measured memory_bytes: 56960
import sys

sys.setrecursionlimit(10 ** 7)

N = int(input())
A = list(map(int, input().split()))


ans = True
for a in A:
    if a % 2 == 0:
        if not (a % 5 == 0 or a % 3 == 0):
            ans = False
            break


if ans:
    print('APPROVED')
else:
    print('DENIED')


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
const int MOD = (int)1e9 + 7;
const double PI = acos(-1.0);


int32_t main(){
	int m[1000] = {0};
	int n, k;
	cin >> k >> n;
	for(int i = 0; i < n; i++){
		int x;
		cin >> x;
		m[x] = 1;
	}
	int val = 200, dis = 200;
	for(int i = 0; i <= 200; i++){
		if(m[i] == 0){
			if(abs(i-k) < dis){
				dis = abs(i-k);
				val = i;
			}
		}
	}
	cout << val << endl;
	
	
	return 0;
}


Measured memory_bytes: 3636
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvvl vector<vector<vector<ll>>>

int main() {
    long long n, m, ans = 0; cin >> n >> m;
    if (n * 2 >= m) { ans += m / 2; m -= m; }
    else { ans = n; m -= n * 2; }
    if (m >= 4)ans += m / 4;
    cout << ans << endl;
    return 0;
}

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

int main(){
  ll n, a, b, c, d;
  cin >> n >> a >> b >> c >> d;
  n--;
  if (a > b) {
    swap(a, b);
  }
  b -= a;
  for (ll i = 0LL; i <= n; i++) {
    if (b <= (n - i) * d - i * c && b >= (n - i) * c - i * d) {
      puts("YES");
      return 0;
    }
  }
  puts("NO");
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
 
typedef long long ll;
using namespace std;
 
ll gcd(ll a, ll b){
  		return b? gcd(b,a%b):a;
}
 
ll lcm(ll a, ll b){
        return a/gcd(a,b)*b;
}
 
ll N, M;
char S[100001];
char T[100001];
map<ll,char> m;
int main(){
        scanf("%lld %lld",&N,&M);
        scanf("%s",S);
        scanf("%s",T);
 
        ll l = lcm(N,M);
        //printf("%lld\n",l);
 
 
        for(ll i = 0; i < N; i++){
                m[i*(l/N)] = S[i];
        }
 
        for(ll j = 0; j < M; j++){
                if(m[j*(l/M)] != 0 && m[j*(l/M)]!= T[j]){
                        puts("-1");
                        return 0;
                }
        }
        printf("%lld\n",l);
 
}

Measured memory_bytes: 10752
#include <cstdio>
#include <algorithm>
using namespace std; 

int n,a[100005],ans=0,f[100005],d[100005];

int main(void){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	scanf("%d",&a[i]);
	f[0]=a[1];
	for(int i=1;i<=n;i++)
	f[i]=__gcd(f[i-1],a[i]);
	d[n+1]=a[n];
	for(int j=n;j>=1;j--)
	d[j]=__gcd(d[j+1],a[j]);
	for(int i=1;i<=n;i++){
		int s;
		if(i-1>0&&i+1<=n)
		s=__gcd(f[i-1],d[i+1]);
		if(i-1<=0)
		s=d[i+1];
		if(i+1>n)
		s=f[i-1];
		if(s>ans)ans=s;
	}
	printf("%d",ans);
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define LL long long
using namespace std ;
void Read ( LL &x, char c = getchar(), bool f = 0 ) {
	for ( x = 0 ; !isdigit(c) ; c = getchar() ) if (c == '-') f = 1 ;
	for ( ;isdigit(c) ; c = getchar() ) x = 10*x + c - '0' ;
	if (f) x = -x ;
}
const LL maxn = 1e5+5 ;
LL n, m, p[maxn], L[maxn], R[maxn] ;
int main() {
	Read(n) ;
	LL i ;
	for ( i = 1 ; i <= n ; i ++ )
		Read(p[i]) ;
	p[0] = p[n+1] = 0 ;
	for ( i = 1 ; i <= n ; i ++ )
		L[i] = L[i-1] + abs(p[i]-p[i-1]) ;
	for ( i = n ; i ; i -- )
		R[i] = R[i+1] + abs(p[i]-p[i+1]) ;
	for ( i = 1 ; i <= n ; i ++ )
		printf ( "%lld\n", L[i-1]+R[i+1]+abs(p[i-1]-p[i+1]) ) ;
	return 0 ;
}


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

#define F first
#define S second
#define PB push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 100010, M = 1010, INF = 0x3f3f3f3f;

int n, m;
int a[N];
set<int> S;

int main()
{
	scanf("%d%d", &n, &m);
	
	int mina = INF, maxd = -INF;
	for (int i = 0; i < n; i ++ )
	{
		scanf("%d", &a[i]);
		
		mina = min(mina, a[i]);
		maxd = max(maxd, a[i] - mina);
	}
	
	int res = 0;
	for (int i = 0; i < n; i ++ )
	{
		S.insert(a[i]);
		if (S.count(a[i] - maxd)) res ++ ;
	}
	
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 5376
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a,i = 0;
        while(true){
            i++;
            a = sc.nextInt();
            if(a==0) break;
            System.out.println("Case "+i+": "+a);
        }
        sc.close();
    }
}


Measured memory_bytes: 41476
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
 
 
void swap (int *x, int *y) {
  int temp;    
 
  temp = *x;
  *x = *y;
  *y = temp;
}
 
int gcd(int a,int b){
  if(a<b){
    swap(&a,&b);
  }
 
  if(b==0){
    return a;
  }
 
  int r=a%b;
  while(r!=0){
    a = b;
    b = r;
    r = (a%b);
  }
 
  return b;
}
 
/* クイックソート */
int dn(const void*a,const void*b){return*(int*)b-*(int*)a;}
 
 
int modpow(int a,int n,int mod){
  int ans=1;
  while(n>0){
    if(n & 1){
      ans=ans*a%mod;
    }
    a=a*a%mod;
    n/=2;
  }
  return ans;
}
 
int max(int a,int b){
  if(a<b){
    return b;
  }
  else{
    return a;
  }
}
 
int min(int a,int b){
  if(a<b){
    return a;
  }
  else{
    return b;
  }
}
 
void chmax(int *a,int b){
  if(*a < b){
    *a = b;
  }
 
  return;
}
 
void chmin(int *a,int b){
  if(*a > b){
    *a =b;
  }
 
  return;
}
 

int main(void){
  int n;
  scanf("%d",&n);
  int l[n];
  int max=0;
  int sum=0;
  for(int i=0;i<n;i++){
    scanf("%d",&l[i]);
    chmax(&max, l[i]);
    sum+=l[i];
  }
  sum-=max;
  if(max<sum){
    printf("Yes\n");
    return 0;
  }else{
    printf("No\n");
    return 0;
  }
}

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

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
typedef long long int ll;
using namespace std;
#define  ios ios_base::sync_with_stdio(false);

int main() {
    ios
    string s;
    vector <string> v;
    ll t;
   // cin>>t;

   // while(t--) {
        cin >> s;
        ll zro=0,on=0;
      for(int i=0;i<s.length();i++){
          if(s[i]=='0')
              zro++;
          else on++;
      }
      cout<<2*min(zro,on)<<endl;



  //  }


}


Measured memory_bytes: 512
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func readInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func readString() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)

	n, k := readInt(), readInt()
	a := make(map[int]int, n)
	for i := 0; i < k; i++ {
		d := readInt()
		for j := 0; j < d; j++ {
			ak := readInt()
			a[ak]++
		}
	}
	fmt.Println(n - len(a))
}


Measured memory_bytes: 1764
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <algorithm>

using namespace std;

#define mp make_pair
#define pb push_back
#define x first
#define y second

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vpii;

const int N=100010;
const int inf=1000000000;

int ans,dp[N][4];
vi e[N];
bool v[N];

void dfs(int k)
{
	v[k]=1;
	int t[8];for (int i=0;i<8;i++) t[i]=inf;t[6]=0;
	for (vi::iterator r=e[k].begin();r!=e[k].end();r++)
		if (!v[*r])
		{
			dfs(*r);int g[8];
			for (int i=0;i<8;i++) g[i]=inf;
			for (int i=0;i<8;i++)
			{
				int x=i&1,y=(i&2)>>1,z=(i&4)>>2;
				for (int j=0;j<4;j++)
				{
					int p=j&1,q=(j&2)>>1;
					if ((!z)&&(!p)) continue;
					g[(x|p)+((y|p)&(x|q))*2+(z&p)*4]=min(g[(x|p)+((y|p)&(x|q))*2+(z&p)*4],t[i]+dp[*r][j]);
				}
			}
			for (int i=0;i<8;i++) t[i]=g[i];
		}
	for (int i=0;i<4;i++) dp[k][i]=inf;
	for (int i=0;i<8;i++)
	{
		int x=i&1,y=(i&2)>>1,z=(i&4)>>2;
		dp[k][x+(y&z)*2]=min(dp[k][x+(y&z)*2],t[i]);
		dp[k][1+z*2]=min(dp[k][1+z*2],t[i]+1);
		if (k==0) ans=min(ans,t[i]+((!x)|(!y)));
	}
}

int main()
{
	int n;scanf("%d",&n);
	for (int i=1;i<n;i++)
	{
		int x,y;scanf("%d%d",&x,&y);
		e[x].pb(y);e[y].pb(x);
	}
	ans=inf;
	dfs(0);
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 18176
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int gcd(int a, int b) {  
  return b != 0 ? gcd(b, a % b) : a;
}//MAX
int lcm(int a, int b) { 
   return a * b / gcd(a, b);
   }
//MIN
 main() {
   ll l,r,ans = 2020;
   cin >> l >>r;
   if((r-l)+1>=2019)return cout << 0,0;
   for(ll j=l;j<=r;j++){
     for(ll i=l;i<j;i++)
       ans = min(ans,(i*j)%2019);
     
   }
   cout << ans;
 }
 


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <queue>
#include <cmath>
#include <cstring>
using namespace std;

#ifdef ENABLE_LL
#define int long long
#endif

#ifdef ENABLE_LL
#define I "%lld"
#define II "%lld%lld"
#define III "%lld%lld%lld"
#define IIII "%lld%lld%lld%lld"
#define IN "%lld\n"
#define IIN "%lld%lld\n"
#define IIIN "%lld%lld%lld\n"
#define IIIIN "%lld%lld%lld%lld\n"
#else
#define I "%d"
#define II "%d%d"
#define III "%d%d%d"
#define IIII "%d%d%d%d"
#define IN "%d\n"
#define IIN "%d%d\n"
#define IIIN "%d%d%d\n"
#define IIIIN "%d%d%d%d\n"
#endif

#ifdef __LOCALE__
#define see(a) std::cout << #a << "=" << a << std::endl
#define ses(a) std::cout << #a << "=" << a << " " 
#else
#define see(a) //std::cout << #a << "=" << a << std::endl
#define ses(a)
#endif
#define repe(a,b) for (int a=0;a<(int)b.size();a++)
#define rep(i,n) for (int i=0;i<n;i++)
#define repa(i,n) for (int i=1;i<=n;i++)
#define repi(i,a,b) for (int i=a;i<=b;i++) 
#define repb(i,a,b) for (int i=a;i>=b;i--)
typedef pair < int , int > pr;
typedef pair < pr  , int > prr;
#define L first
#define R second
template <class T> inline bool checkMin(T& a , T b) { return (a > b ? a=b,1 : 0); }
template <class T> inline bool checkMax(T& a , T b) { return (a < b ? a=b,1 : 0); }
class Scanner{ private: istream& ist;public: Scanner(istream& in):ist(in){} string next(){ string r; ist >> r; return r; } string nextLine(){ string r; getline(ist,r); return r; } int nextInt(){ int r; ist >> r; return r; } double nextDouble(){ double r; ist >> r; return r; }};
Scanner sc(cin);


void init() {
     
}

void solve() {
    int n; scanf(I,&n);
    string s; cin >> s;
    int ans=0;
    rep (i,(int)s.size()) if (s.substr(i,3)== "ABC") ans++;
    printf(IN,ans);
}


#ifdef ENABLE_LL
#undef int
#endif
int main(){
    init();
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
using namespace std;
using cd = complex <double>;

const long long INF = 1e15;
const int mod = 998244353;//1e9 + 7;//786433;
const double Pi = acos(-1);

void Fastio()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

struct Edge{
	int u, v;
	long long cap, flow = 0;
	Edge(int u, int v, long long cap) : u(u), v(v), cap(cap) {};
};

int n;
int s, t;
long long sum = 0;
long long a[105];
vector <Edge> E;
vector <int> Adj[105];

void AddEdge(int u, int v, long long c)
{
	Adj[u].eb(E.size());
	E.eb(u, v, c);
	Adj[v].eb(E.size());
	E.eb(v, u, 0);
}

int Level[105];

long long DFS(int node, long long flow)
{
	if(node == t or flow == 0)
	{
		return flow;
	}
	for(auto x : Adj[node])
	{
		if(Level[E[x].v] != Level[node] + 1 or E[x].cap == E[x].flow)
		{
			continue;
		}
		int temp = DFS(E[x].v, min(E[x].cap - E[x].flow, flow));
		if(temp > 0)
		{
			E[x].flow += temp;
			E[x ^ 1].flow -= temp;
			return temp;
		}
	}
	return 0;
}

signed main()
{
	Fastio();
	cin >> n;
	s = 0, t = n + 1;
	for(int i = 1; i <= n; i++)
	{
		cin >> a[i];
		if(a[i] <= 0)
		{
			AddEdge(s, i, -a[i]);
		}
		else
		{
			sum += a[i];
			AddEdge(i, t, a[i]);
		}
	}
	for(int i = 1; i <= n; i++)
	{
		for(int j = 2 * i; j <= n; j = j + i)
		{
			AddEdge(i, j, INF);
		}
	}
	while(true)
	{
		for(int i = 0; i <= n + 1; i++)
		{
			Level[i] = -1;
		}
		Level[s] = 0;
		queue <int> BFS;
		BFS.push(s);
		while(BFS.empty() == false)
		{
			int node = BFS.front();
			BFS.pop();
			for(auto x : Adj[node])
			{
				if(E[x].cap > E[x].flow and Level[E[x].v] == -1)
				{
					Level[E[x].v] = Level[node] + 1;
					BFS.push(E[x].v);
				}
			}
		}
		if(Level[t] == -1)
		{
			break;
		}
		long long f;
		while(f = DFS(0, INF))
		{
			sum -= f;
		}
	}
	cout << sum;
}

Measured memory_bytes: 3672
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long int
#define INF 1e9
#define LINF 1e18
#define MOD 1000000007
#define PI 3.14159265359
#define EPS 1e-10
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll, ll>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

/**
 * Usage:
 * 
 * G[from].push_back(Edge(to, weight));
 * using Graph = vector<vector<Edge>>;
 * 
 */ 
struct Edge {
  int to;     
  ll weight; 
  Edge(int t, ll w) : to(t), weight(w) { }
};

/**
 * Usage:
 * 
 * chmin(old, new);
 * chmax(old, new);
 * 
 */ 
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

template<typename T>
void printv(vector<T>& v) {
  if (v.size() == 0) {
    cout << "\n";
    return;
  }

  Rep(i, v.size()) {
    cout << v[i] << ((i + 1 < v.size()) ? ' ' : '\n');
  }
}



int N;
ll a[110000];
ll b[110000];
ll c[110000];
ll dp[110000][3];

int main () {
  cin >> N;
  rep(i, N) {
    cin >> a[i] >> b[i] >> c[i];
  }

  dp[1][0] = a[1];
  dp[1][1] = b[1];
  dp[1][2] = c[1];

  for (int k=2;k<=N;++k) {
    chmax(dp[k][0], max(dp[k-1][1] + a[k], dp[k-1][2] + a[k]));
    chmax(dp[k][1], max(dp[k-1][2] + b[k], dp[k-1][0] + b[k]));
    chmax(dp[k][2], max(dp[k-1][0] + c[k], dp[k-1][1] + c[k]));
  }

  ll ans = 0;
  Rep(j, 3) {
    chmax(ans, dp[N][j]);
  }

  cout << ans << "\n";
}

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

int main() {
  int n;
  cin >> n ;
  string s;
  bool ans=true;
  for (int i = 0; i < n; i++)
  {
    cin>>s;
    if (s=="Y"){
        ans=false;
        cout<<"Four"<<endl;
        break;
    }
  }
  if (ans){
      cout<<"Three"<<endl;
  } 
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
long dp[100][100001];

int main(){
    int N, W;
    cin >> N >> W;
    int w, v;
    
    for(int i = 0; i < N; i++){
        for(int j = 0; j <= W; j++){
            dp[i][j] = -1;
        }
    }
    cin >> w >> v;
    dp[0][w] = v;
    dp[0][0] = 0;
    for(int i = 1; i < N; i++){
        dp[i][0] = 0;
        cin >> w >> v;
        dp[i][w] = v;
        for(int j = 0; j <= W; j++){
            if(dp[i-1][j] >= 0) dp[i][j] = max(dp[i][j], dp[i-1][j]);
            if(j >= w && dp[i-1][j-w] >= 0) dp[i][j] = max(dp[i][j], dp[i-1][j-w] + v);
        }
    }
    /*
    for(int i = 0; i < N; i++){
        for(int j = 0; j <= W; j++){
            cout << dp[i][j] << ' ';
        }
        cout << endl;
    }
    */
    long ans = 0;
    for(int i = 0; i <= W; i++){
        ans = max(ans, dp[N-1][i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 78464
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as C
import Debug.Trace
import Data.List
import Control.Monad
import Data.Ord


r :: Int -> IO (U.Vector Int)
r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine

rp :: IO (Int,Int)
rp  = toTup . unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine

toTup [a,b] = (a,b)



main :: IO ()
main = do
    ls <- r'
    print $ length $ nub ls



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

int main(){
  string S;
  cin >> S;
  bool check = true;
  
  for(int i = 0; i < (S.size()-1)/2; i++){
    int n = S.size()-1;
    if(S[i] != S[n-i]){
      check = false;
    }
    if(S[i] != S[(n-2)/2-i]){
      check = false;
    }
    if(S[(n+2)/2+i] != S[n-i]){
      check = false;
    }
  }
  
  if(check)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
  return 0;
  
}

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

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

    int n;
    cin >> n;
    
    int h[n], c[n];
    rep(i, n) cin >> h[i];

    c[0] = 0;
    c[1] = abs(h[1] - h[0]);
    for(int i = 2; i < n; ++i){
        c[i] = min(c[i-2] + abs(h[i] - h[i-2]), c[i-1] + abs(h[i] - h[i-1]));
    }

    cout << c[n-1] << endl;

    return 0;
}

Measured memory_bytes: 1024