akhauriyash/Code-Regression huggingface dataset:
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <cstdlib>
#include <iomanip>
#define rep(i,x) for(ll i=0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
using ld = long double;
using ll = long long;
const ll INF = 10010010010;
typedef pair<ll, ll> P;
using graph = vector<vector<ll>>;
const ll mod = 1000000007;
ll gcd(ll a, ll b) {//a>b
    if (a < b)swap(a, b);
    if (a % b == 0) return b;
    else return gcd(b, a % b);
}/*フィボナッチテンプレ
ll memo[50];
ll fibo(ll n) {
    if (memo[n] != 0)return memo[n];
    if (n <= 1)return memo[n] = n;
    else return memo[n] = fibo(n - 1) + fibo(n - 2);
}
*/
bool isp(ll n) {
    bool res = true;
    for (ll i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            res = false;
            break;
        }
    }
    return res;
}
ll ctoi(char c) {
    if (c == '0')return 0;
    else if (c == '1')return 1;
    else if (c == '2')return 2;
    else if (c == '3')return 3;
    else if (c == '4')return 4;
    else if (c == '5')return 5;
    else if (c == '6')return 6;
    else if (c == '7')return 7;
    else if (c == '8')return 8;
    else if (c == '9')return 9;
    else return -1;
}

int main() {
    ll N, M;
    cin >> N >> M;
    if (N == 1 || M == 1) {
        if (N > M)swap(N, M);
        if (M == 1)cout << "1" << endl;
        else cout << M - 2 << endl;
    }
    else {
        cout << (N - 2) * (M - 2) << endl;
    }
}

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

typedef long long ll;
typedef pair<int,int> P;
#define INF 1000000100
#define rep(i,n) for (int i=0;i<n;i++)

int main(){
    int N;
    cin >> N;
    ll ans = 0;
    for(int i=1;i<=N;i++){
        ll y= N/i;
        ans += y*(y+1)*i/2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3100
using System;
 
class Program {
 
    private static int Main() {
        var input = Console.ReadLine();
        var chars = input.ToCharArray();
 
        for( int i = 0; i < chars.Length; ++i ) {
            var c = chars[ i ];
            if( char.IsLower( c ) ) {
                chars[ i ] = char.ToUpper( c );
            } else if( char.IsUpper( c ) ) {
                chars[ i ] = char.ToLower( c );
            }
        }
 
        Console.WriteLine( chars );
 
        return 0;
    }
 
}

Measured memory_bytes: 5568
#include<bits/stdc++.h>
#include<cxxabi.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define mp make_pair
#define fi first
#define se second
#define All(x) (x).begin(),(x).end()
#define TYPEVS(x) typeid(x).name()
#define TYPEGC(x) abi::__cxa_demangle(typeid(x).name(), 0, 0, 0)
#define Y1 "YES"
#define N1 "NO"
#define ENDL '\n'
#define count2(x) _builtin_popcount(x)
ll nums[6001];
ll sat[4001][3001],ans;
ll mod=998244353;
int main(){
	ll n,s;
	cin>>n>>s;
	sat[0][0]=1;//sat[i][j]表示选择其中不超过i个数，和为j的方案 
	for(ll i=1;i<=n;++i)
	cin>>nums[i];
	for(ll i=1;i<=n;++i){
		for(int j=0;j<=3000;j++){
			//若和比num[i]大，方案数是sat[i-1][j]*2+sat[i-1][j-nums[i]]
			if(j>=nums[i])sat[i][j]=(sat[i-1][j]*2+sat[i-1][j-nums[i]])%mod;
			else sat[i][j]=(sat[i-1][j]*2)%mod;
		}
	}
	cout<<sat[n][s];
}


Measured memory_bytes: 73988
#include <iostream>
using namespace std;
int main()
{
    int a,b;
    cin >> a >> b;
    if (a < b){
        cout << "a < b" << endl;
    }
    else if (a > b){
        cout << "a > b" << endl;
    }
    else if (a == b){
        cout << "a == b" << endl;
    }
}


Measured memory_bytes: 3100
#include "bits/stdc++.h"
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define INF 1e9
using ll = std::int64_t;

template <class T>bool chmax(T &a, const T &b);
template <class T>bool chmin(T &a, const T &b);
//最大公約数
std::int64_t gcd(std::int64_t a, std::int64_t b);
std::int64_t gcd_s(std::int64_t aa, std::int64_t bb);
//ラングレス圧縮
std::vector<std::pair<char, std::int64_t>> rle(std::string str);
//素数判定
bool is_prime(std::int64_t n);
// 約数の列挙
std::vector<std::int64_t> divisor(std::int64_t n);
// 素因数分解
std::map<std::int64_t,std::int64_t> prime_factor(std::int64_t n);

//10^9 + 7
#define yojo 1000000007
#define MAX_NUM 200001

void Main()
{
  int r, g, b;
  cin >> r >> g >> b;
  int num = r * 100 + g * 10 + b;
  if (num % 4 == 0)
  {
    std::cout << "YES" << std::endl;
  }
  else
  {
    std::cout << "NO" << std::endl;
  }

  return;
}

int main()
{
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}

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

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

//最大公約数
std::int64_t gcd(std::int64_t a, std::int64_t b)
{
  // a >= b && b != 0
  std::int64_t c;
  do
  {
    c = a % b;
    a = b;
    b = c;
  } while (c);

  return a;
}

//最大公約数安全版
std::int64_t gcd_s(std::int64_t aa, std::int64_t bb)
{
  std::int64_t a = max(aa, bb);
  std::int64_t b = min(aa, bb);
  std::int64_t c;
  if (b == 0)
  {
    return -1;
  }
  do
  {
    c = a % b;
    a = b;
    b = c;
  } while (c);

  return a;
}

//ラングレス圧縮
std::vector<std::pair<char, std::int64_t>> rle(std::string str)
{
  std::vector<std::pair<char, std::int64_t>> data;
  char now = str[0];
  std::int64_t count = 0;
  for (std::int64_t i = 0; i < str.size() + 1; i++)
  {
    if (i == str.size())
    {
      data.push_back(make_pair(str[i - 1], count));
      break;
    }
    else if (now != str[i])
    {
      data.push_back(make_pair(now, count));
      now = str[i];
      count = 0;
    }
    count++;
  }

  return data;
}

//素数判定
bool is_prime(std::int64_t n)
{
  for (std::int64_t i = 0; i * i <= n; i++)
  {
    if (n % i == 0)
    {
      return false;
    }
  }
  
  return n != 1;
}

//約数の列挙
std::vector<std::int64_t> divisor(std::int64_t n)
{
  std::vector<std::int64_t> res;
  for (int i = 0; i < n; i++)
  {
    if(n % i == 0){
      res.push_back(i);
      if (i != n / i) res.push_back(n / i);
    }
  }
  return res;
}

// 素因数分解
std::map<std::int64_t, std::int64_t> prime_factor(std::int64_t n)
{
  std::map<std::int64_t, std::int64_t> res;
  for (int i = 2; i * i <= n; i++)
  {
    while (n % i == 0)
    {
      ++res[i];
      n /= i;
    }
  }

  if (n != 1)
  {
    res[n] = 1;
  }
  
  return res;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//String s = sc.next();
		long n = sc.nextLong();
		//long m = sc.nextLong();

		if(n/10==9||n%10==9) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
		//System.out.println((n-1)*(m-1));
	}
}




Measured memory_bytes: 21844
#include<bits/stdc++.h>                   // below comment for pbds
#include<ext/pb_ds/assoc_container.hpp>   // to use it make ordered_set
#include<ext/pb_ds/tree_policy.hpp>       // all set fnct + = 1. order_of_key(x); //number 
#define ll long long                      //of element strictly smaller than it;
#define ld long double                    // 2. find_by_order(x),pointer el at x pos after 
using namespace std;                      // sort use as s.f();
using namespace __gnu_pbds;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.flush();
	ll t=1;
//	cin>>t;
	while(t--)
	{
	ll x;
	cin>>x;
	ll ans=0;
	ll p1=x%500;
	x=x/500;
	ans+=(2*x)*500;
	x=p1/5;
	ans=ans+(x*5);
	
	cout<<ans<<endl;
	}
	
return 0;
}


Measured memory_bytes: 256
const input=require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/);let input_i=-1;const tn=():number=>{input_i++;return Number(input[input_i])};const tnn=(n:number):number[]=>{const a=[];for(let i=0;i<n;i++){a.push(tn())}return a};const ts=():string=>{input_i++;return String(input[input_i])};const tss=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(ts())}return a};const to=(...arg)=>{console.log(...arg)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const floor=(a)=>{return Math.floor(a)};const asc=(ar:number[])=>{const t=[...ar];return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{const t=[...ar];return t.sort((a,b)=>{return b-a})};const sw=(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length-1;i+=2){if(eval(a+op+arr[i])){return arr[i+1]}}return arr[arr.length-1]};const near=(n:number,arr:number[]):number=>{let ne=arr[0],ni=0;for(let i=1;i<arr.length;i++){if(Math.abs(n-ne)>Math.abs(n-arr[i])){ne=arr[i];ni=i}}return ni};const deduplicate=(a:any[]):any[]=>{return Array.from(new Set(a))}
const main=()=>{
  let s=ts().split('')
  s.pop()
  let m=s.length;
  for(let i=0;i<m;i++){
    if(s.length%2==1){
      s.pop()
      continue
    }
    if((s.slice(0,s.length/2)).join('')==(s.slice(s.length/2)).join('')){
      to(s.length)
      return
    }
    s.pop()
  }
}
main()

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

struct Edge{
  int to,cost;
  bool operator<(const Edge&a)const{
    return cost>a.cost;
  }
};
struct Graph{
  Graph(int n):E(n),T(n),N(n){}
  vector<vector<Edge>>E,T;
  int N;
  void add_edge(int a,int b,int c){
    E[a].push_back({b,c});
    E[b].push_back({a,c});
  }
  void prim(int s){
    bool visited[N];
    priority_queue<pair<Edge,int>>Q;
    memset(visited,0,N);
    Q.push({{s,0},-1});
    while(Q.size()){
      Edge e=Q.top().first;
      int from=Q.top().second;Q.pop();
      if(visited[e.to])continue;
      visited[e.to]=1;
      if(from+1)T[from].push_back(e),T[e.to].push_back({from,e.cost});
      for(auto&a:E[e.to])
      if(!visited[a.to])Q.push({a,e.to});
    }
  }
  int get_cost(){
    int ret=0;
    for(auto&a:T)for(auto&b:a)ret+=b.cost;
    return ret/2;
  }
  vector<Edge>* get_MST(){
    return T.data();
  }
};

main(){
  int V,E,a,b,c;
  cin>>V>>E;
  Graph G(V);
  for(int i=0;i++<E;G.add_edge(a,b,c))cin>>a>>b>>c;
  G.prim(0);
  cout<<G.get_cost()<<endl;
}

Measured memory_bytes: 7736
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define takeline cin.ignore();
#define sc second
#define N 3000005
#define endl "\n"
#define mod 1000000007
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
int main(){
	
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll i,j,k,l,n;
	cin>>n;
	ll s=0;
	ll ar[n+1];
	for(i=1;i<=n;i++){
		cin>>ar[i];
		s+=ar[i];
	}
	k=0;
	ll mn=1e18;
	for(i=1;i<n;i+=1){
		s-=ar[i]; k+=ar[i];
	//	cout<<s<<" "<<k<<" "<<(abs(k-s))<<endl;
		mn=min(mn,abs(k-s));
	}
	cout<<mn;
	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;
const int inf=2147483647,dx[]={-1,0,1,0},dy[]={0,-1,0,1};
const long long llinf=9223372036854775807ll;
const int N=100005;
long long lay[55],pat[55],used,x,ans,n,le;
void go(long long l)
{
	if(le==0)
	{
		cout<<ans;
		exit(0);
	}
	if(le>=lay[l])
		le-=lay[l],ans+=pat[l];
	else
	{
		le--;
		if(le==0)
		{
			cout<<ans;
			exit(0);
		}
		go(l-1);
		if(le==0)
		{
			cout<<ans;
			exit(0);
		}
		le--,ans++;
		if(le==0)
		{
			cout<<ans;
			exit(0);
		}
		go(l-1);
		if(le==0)
		{
			cout<<ans;
			exit(0);
		}
		le--;
		if(le==0)
		{
			cout<<ans;
			exit(0);
		}	
	}
}
int main(){
	cin>>n>>x;
	lay[0]=pat[0]=1;
	for(int i=1;i<=n;i++)
		lay[i]=lay[i-1]*2ll+3ll,pat[i]=pat[i-1]*2ll+1ll;
	le=x;
	go(n);
	cout<<ans;
	return 0;
}

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

using namespace std;

#define C_MAX(a, b) ((a)>(b)?(a):(b))

long long GCD(long long x, long long y) {
    return y == 0 ? x : GCD(y, x % y);
}

long long LCM(long long x, long long y) {
    return x * y / GCD(x, y);
}

int main() {

    long long N, M;
    cin >> N >> M;

    string S, T;
    cin >> S >> T;

    if (S.size() < T.size()) swap(S, T);

    long long lcm = LCM(N, M);
    map<long long, char> MAP;

    bool good = true;
    for (int i = 0; i < S.size(); i++) MAP[(lcm / S.size()) * i] = S[i];
    for (int i = 0; i < T.size(); i++)
        if (MAP.count((lcm / T.size()) * i) == 1 && MAP[(lcm / T.size()) * i] != T[i])good = false;

    if (good) cout << lcm << endl;
    else cout << -1 << endl;

    return 0;
}




























Measured memory_bytes: 6400
N,M=map(int,input().split())
H=list(map(int,input().split()))
L=[[] for i in range(N)]
for i in range(M):
  A,B=map(int,input().split())
  A-=1
  B-=1
  L[A].append(B)
  L[B].append(A)
ans=0
for i in range(N):
  flag=True
  for j in L[i]:
    if H[i]<=H[j]:
      flag=False
      break
  if flag:
    ans+=1
print(ans)

Measured memory_bytes: 29440
import sys

def InputToInt():
    A = input().split()
    for i in range(len(A)):
        A[i] = int(A[i])
    return A
    
if __name__ == '__main__':
    N, M = InputToInt()

    n = int(N/2019)
    m = int(M/2019)

    if n != m:
        print('0')
        sys.exit()

    n = N%2019
    m = M%2019

    a = 2018
    for i in range(n, m):
        for j in range(i+1, m+1):
            a = min(a, (i*j)%2019)
    print(a)


Measured memory_bytes: 3064
r, c = gets.chomp.split(" ").map(&:to_i)
spreadsheet = []
r.times do |i|
  spreadsheet[i] = gets.chomp.split(" ").map(&:to_i)
end
spreadsheet.each do |line|
  line.push line.inject(&:+)
end
spreadsheet.push spreadsheet.transpose.map { |e| e.inject(&:+) }
spreadsheet.each do |line|
  puts line.join(" ")
end

Measured memory_bytes: 9112
def dfs(i, sum, count, nokori):
    global ans
    if i == d:
        # G 点に満たなければ nokori のうち一番大きいものを解く
        if sum < g:
            use = max(nokori)
            # 解く問題が問題数を超えないように注意
            n = min(pc[use - 1][0], -(-(g - sum) // (use * 100)))
            count += n
            sum += n * use * 100

        if sum >= g:
            ans = min(ans, count)
    else:
        # 総合スコア、解いた問題数、まだ解いてない問題を更新
        dfs(i + 1, sum, count, nokori)
        dfs(i + 1, sum + pc[i][0] * (i + 1) * 100 + pc[i][1], count + pc[i][0], nokori - {i + 1})


d, g = map(int, input().split())
pc = [list(map(int, input().split())) for i in range(d)]

ans = float("inf")

dfs(0, 0, 0, set(range(1, d + 1)))
print(ans)

Measured memory_bytes: 9100
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
int n;
ll ans;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		if(n%i==0)
			ans+=n/i-1;
		else ans+=n/i;
	}
	printf("%lld\n",ans);
	return 0;
}

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

int main(){
    int n,m,cnt = 0;
    
    while(1){
        cin >> n >> m;
        cnt = 0;
        
        if(n+m == 0) break;
        
        rep(i,1,n-1){
            rep(j,i+1,n){
                rep(k,j+1,n+1){
                    if(i+j+k == m) cnt++;
                }
            }
        }
        
        cout << cnt << endl;
    }
    return 0;
}


Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int r,g,b;
    cin>>r>>g>>b;
    if(((r*100)+(g*10)+b)%4 == 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;

int main() {
    string s;
    cin >> s;
    vector<int> at(s.length()+1);
    at[0] = 0;
    for(int i=0; i<s.length(); i++){
        if (s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T'){
            at[i+1] = at[i] + 1;
        }else{
            at[i+1] = 0;
        }
    }
    cout << *max_element(at.begin(), at.end()) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a,b,k,i,max,count=0,m;
    scanf("%d %d %d",&a,&b,&k);
    if(a>=b)
    {
        max = a;
    }else{
        max = b;
    }
    for(i=max;i>=1;i--)
    {
        if(a%i==0 && b%i==0)
        {
            count++;
        }
        if(count == k)
        {
            m = i;
            break;
        }
    }

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


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

const int SIZE=300010;
vector<int> G[SIZE];
int visited[SIZE];
int cnt;

void dfs(int v)
{
  visited[v]=true;
  cnt++;
  for(int u:G[v]){
    if(!visited[u]){
      dfs(u);
    }
  }
}

signed main()
{
  int N,R; cin>>N>>R;
  vector<int> p(N);
  for(int i=0;i<N;i++){
    cin>>p[i]; p[i]--;
  }

  for(int i=0;i<N;i++){
    G[p[i]].push_back(i);
  }
  R=min(R,N-R);

  bitset<SIZE/2> dp;
  dp[0]=1;
  for(int i=0;i<N;i++){
    if(!visited[i]){
      cnt=0;
      dfs(i);
      dp|=(dp<<cnt);
    }
  }
  cout<<(dp[R]? "Yes":"No")<<endl;;
}




Measured memory_bytes: 31960
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;

#define ll long long
//typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define revrep(i, n) for(ll i = n-1; i >= 0; i--)
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll Mypow(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}


ll INFL = 1LL << 60;//10^18 = 2^60
int INF = 1 << 30;//10^9
ll MOD  = 1000000007;
//vector<int> dy = {0,0,1,-1};
//vector<int> dx = {1,-1,0,0};

ll H, W, N;

int main(){
  cin >> H >> W >> N;
  vector<ll> A(N), B(N);
  set<pair<int, int>> ab;
  rep(i, N){
    cin >> A[i] >> B[i];
    A[i]--, B[i]--;
    ab.insert({A[i], B[i]});
  }

  set<pair<ll, ll>> s;//正方形の左上を保存
  rep(i, N){
    ll a = A[i]-2, b = B[i]-2;
    rep(h, 3){
      rep(w, 3){
        if(0 <= a+h && a+h+2 < H && 0 <= b+w && b+w+2 < W) s.insert({a+h, b+w});
      }
    }
  }
  vector<ll> ans(10, 0);
  for(auto itr = s.begin(); itr != s.end(); ++itr){
    pair<ll, ll> z = *itr;
    ll y = z.first, x = z.second;
    ll cnt = 0;
    rep(h, 3){
      rep(w, 3){
        if(ab.count({y+h, x+w})) cnt++;
      }
    }
    ans[cnt]++;
  }
  ll sum = 0;
  rep(i, 10) sum += ans[i];
  ans[0] = (H-2) * (W-2) - sum;
  rep(i, 10) cout << ans[i] << endl;


}


Measured memory_bytes: 62720
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main(void){
    int x, n;
    cin >> x >> n;
    set<int> st;
    REP(i,n) st.insert(in());
    int mi = 1e9, ans = -1;
    FOR(y,-100,200){
        if (st.count(y)) continue;
        int d = abs(x - y);
        if (d < mi || (d == mi && y < ans)){
            mi = d;
            ans = y;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3676
a = input()
b = input()
c = input()

A = [0]*3
ca = 0
cb = 0
cc = 0
for d in a:
    ca +=1
    if(ca == 1):
        A[0] = d

for e in b:
    cb +=1
    if(cb == 2):
        A[1] = e
for f in c:
    cc +=1
    if(cc == 3):
        A[2] = f 

print(A[0]+A[1]+A[2])

Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <string>

using size_type = std::string::size_type;

size_type solve(const std::string& s)
{
  const std::string acgt = "ACGT";
  size_type result = 0u;
  size_type first = 0u;
  size_type last = 0u;
  do {
    first = s.find_first_of(acgt, last);
    if (first == s.npos) return result;
    last = s.find_first_not_of(acgt, first);
    const auto len = last == s.npos ? s.size() - first : last - first;
    result = std::max(result, len);
  } while (last != s.npos);
  return result;
}

int main()
{
  std::string s;
  std::cin >> s;

  std::cout << solve(s) << std::endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define res(i,n) for(int i=n;;i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define REV(i,n) for(int i=n-1;i>0;i--)
#define req(i,n,m) for(int i=n;i<m;i++)
#define REQ(i,n,m,l) for(int i=n;i<m;i+=l) 
#define _GLIBCXX_DEBUG
int INF = 1e9 + 7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
    unsigned day;
    if (dow < dow1) dow += 7;
    day = dow - dow1;
    day += 7 * n - 6;
    return day;
}
signed gcd(long long x, long long y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
signed lcm(long long x, long long y) {
    return x / gcd(x, y) * y;
}
unsigned DayToWeekNumber(unsigned day)
{
    return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
    return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main() {
  int N; cin>>N;
  vector<pair<int,int>>A(N);
  rep(i,N){
    int a,b; cin>>a>>b;
    A[i].first=b;
    A[i].second=a;
  }
  sort(A.begin(),A.end());
  cout<<A[0].first+A[0].second<<endl;
}

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

def do():
    n=INT()
    dic=[]
    for i in range(n):
        s=STR()
        dic.append(s)
    ctd=Ct(dic)
    ctm=max(ctd.values())
    ans=[]
    for key,value in ctd.items():
        if value==ctm:
            ans.append(key)
    
    ans=sorted(ans)

    for i in ans:
        print(i)


if __name__=='__main__':
    do()

Measured memory_bytes: 38780
#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(){
	vector<int>a={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int K;
	cin>>K;
	cout<<a.at(K-1);
return 0;}

/*compile
g++ code.cpp
./a.out
run*/

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
#include <string>
#include <bitset>
#include <queue>
#include <tuple>
#include <cmath>
#include <map>
#include <cstring>

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

using namespace std;

using ll = long long;
using ull = unsigned long long;

using Pint = pair<int, int>;
using Pll  = pair<ll, ll>;
using Pull = pair<ull, ull>;

#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple

#define F first
#define S second

#define rep( i, n ) for ( int i = 0; i < (int)( n ); ++i )
#define reps( i, n ) for ( int i = 1; i <= (int)( n ); ++i )
#define rrep( i, n ) for ( int i = (int)( ( n ) - 1 ); i >= 0; --i )
#define rreps( i, n ) for ( int i = (int)( ( n ) ); i > 0; --i )
#define arep( i, v ) for ( auto &&i : ( v ) )

template<typename T> T gcd( const T a, const T b ) { return ( b ? gcd( b, a % b ) : a ); }

#define ALL( c ) ( c ).begin(), ( c ).end()
#define RALL( c ) ( c ).rbegin(), ( c ).rend()
#define UNIQUE( c ) ( c ).erase( unique( ( c ).begin(), ( c ).end() ), ( c ).end() )

constexpr ll MOD = 1000000007LL;

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev

template<typename T = ll> class UnionFind {
public:
	UnionFind( T n ) { rep( i, n ) { par.resize( n ); siz.resize( n ); par[i] = i; siz[i] = 1; } }
	T find( T x ) { if ( x == par[x] ) return ( x ); else return( par[x] = find( par[x] ) ); }
	void unite( T x, T y ) { T xx = find( x ); T yy = find( y ); if ( xx == yy ) return;
		if ( siz[xx] <= siz[yy] ) swap( xx, yy ); par[yy] = xx; siz[xx] += siz[yy]; }
private:
	vector<T> par, siz;
};

template<typename T = ll> T power( T a, T b, T m = MOD ) {
	T res = 1;
	while ( b > 0 ) { if ( b & 1 ) res = res * a % m;
		a = a * a % m; b >>= 1; }
	return ( res );
}

/*
constexpr ll MAX = 500010;
ll fact[MAX];
ll inv[MAX];
ll inv_fact[MAX];

template<typename T> void initComb( T n, T m = MOD )
{
	fact[0] = fact[1] = inv_fact[0] = inv_fact[1] = 1;
	inv[1] = 1;
	for ( int i = 2; i < n; i++ ) {
		fact[i] = ( fact[i - 1] * i ) % m;
		inv[i] = m - inv[m % i] * ( m / i ) % m;
		inv_fact[i] = inv_fact[i - 1] * inv[i] % m;
	}
}

template<typename T> T comb( T n, T r, T m = MOD )
{
	if ( n < r ) return ( 0 );
	if ( n < 0 || r < 0 ) return ( 0 );
	return ( fact[n] * ( inv_fact[r] * inv_fact[n - r] % m ) % m );
}
*/

void replace( string &s, string t, string r ) {
	string::size_type p = 0;
	while ( ( p = s.find( t, p ) ) != string::npos ) {
		s.replace( p, t.length(), r );
		p += r.length();
	}
}


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

	vector<int> v( N );
	rep( i, N ) cin >> v[i];

	sort( ALL( v ), []( int a, int b ) { return ( a > b ); } );
	UNIQUE( v );

	cout << v.size() << endl;

	return ( 0 );
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);
    Map<Integer, Integer> map = new HashMap<>();

    public static void main(String[] args) {
        new Main().run();
    }

    void run() {

        int n = sc.nextInt();
        long[] arr = new long[n+1];
        arr[0] = 2;
        arr[1] = 1;

        long ans = 0;

        for (int i=2; i<=n; i++) {
            arr[i] = arr[i-1]+arr[i-2];
        }

        System.out.println(arr[n]);
    }

}


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

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

using ll = long long;
vector<int> dx = {1,0,-1,0};
vector<int> dy = {0,1,0,-1};

int main(){
  int h,w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i,h)cin>>s.at(i);

  rep(i,h){
    rep(j,w){
      if(s.at(i).at(j)=='#'){
        int flag = 0;//周囲に#の存在を確認する。
        for(int dir = 0; dir < 4; dir++){
          int x = j + dx.at(dir), y = i + dy.at(dir);
          if(x<0||x>=w||y<0||y>=h)continue;//場外
          if(s.at(y).at(x)=='#')flag = 1;//調査続行
        }
        if(!flag){
          cout<<"No"<<endl;
          return 0;
        }
      }
    }
  }
  cout<<"Yes"<<endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
Q = int(input())
bc = [list(map(int,input().split())) for _ in range(Q)]

p = [0]*100001
for i in range(N):
    p[A[i]] += 1

cnt = 0
for j in range(100001):
    cnt += p[j]*j

for i in range(Q):
    cnt = cnt + (bc[i][1]- bc[i][0]) * p[bc[i][0]]

    p[bc[i][1]] += p[bc[i][0]]
    p[bc[i][0]] = 0

    print(cnt)

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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;


//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

int a[30][30];
ll dp[25][3000000];
const ll MOD = 1e9 + 7;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    rep(i,n) rep(j,n) cin >> a[i][j];
    dp[0][0] = 1;

    rep(j,1<<(n)){
        int i = 0;
        rep(x,n){//bitが立っている数
            if(j&(1<<x)) i++;
        }
        rep(k,n){
            if(a[i][k] && ((j & (1<<k)) == 0) ){
                (dp[i+1][j|(1<<k)] += dp[i][j])%= MOD;
            }

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


Measured memory_bytes: 332032
#include<iostream>
using namespace std;
 
typedef long long int ll;
typedef pair<ll,ll> P;
 
int main(){
    int n;
    cin>>n;
    ll sum=0;
    for(int i=1;i<=n;i++){
        if(i%3&&i%5){
            sum+=i;
        }
    }
    cout<<sum<<endl;
 
    return 0;
}

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}


vector<P<char,char>> abc;
int N;
bool Rec(ll a,ll b,ll c,int n,vector<char>&v){
  if(a < 0 || b < 0 || c < 0) return false;
  if(n == 0) return true;
  auto [c1,c2] = abc[N-n];
  if(c1 == 'A' && c2 == 'B'){
    v.emplace_back('A');
    if(Rec(a+1,b-1,c,n-1,v)) return true;
    v.pop_back();
    v.emplace_back('B');
    if(Rec(a-1,b+1,c,n-1,v)) return true;
    v.pop_back();
  }
  if(c1 == 'A' && c2 == 'C'){
    v.emplace_back('A');
    if(Rec(a+1,b,c-1,n-1,v)) return true;
    v.pop_back();
    v.emplace_back('C');
    if(Rec(a-1,b,c+1,n-1,v)) return true;
    v.pop_back();
  }
  if(c1 == 'B' && c2 == 'C'){
    v.emplace_back('B');
    if(Rec(a,b+1,c-1,n-1,v)) return true;
    v.pop_back();
    v.emplace_back('C');
    if(Rec(a,b-1,c+1,n-1,v)) return true;
    v.pop_back();
  }
  return false;
}

void Solve(ll a,ll b,ll c,int n){
  vector<char> v;
  v.reserve(n);
  for(int i = 0; i < n; ++i){
    char c1,c2; cin >> c1 >> c2;
    abc.emplace_back(c1,c2);
  }
  if(Rec(a,b,c,n,v)){
    cout << "Yes" << endl;
    for(auto e:v)cout << e << endl;
  } else {
    cout << "No" << endl;
  }
}

int main(){
  int n; cin >> n;
  N = n;
  map<char,ll> mp;
  {
    ll a,b,c; cin >> a >> b >> c;
    // if(a == 1 && b == 1 && c == 0){Solve(a,b,c,n);return 0;}
    // if(a == 1 && b == 0 && c == 1){Solve(a,b,c,n);return 0;}
    // if(a == 0 && b == 1 && c == 1){Solve(a,b,c,n);return 0;}
    // if(a == 1 && b == 0 && c == 0){Solve(a,b,c,n);return 0;}
    // if(a == 0 && b == 1 && c == 0){Solve(a,b,c,n);return 0;}
    // if(a == 0 && b == 0 && c == 1){Solve(a,b,c,n);return 0;}
    if(a + b + c < 3){Solve(a,b,c,n); return 0;}
    mp['A'] = a;
    mp['B'] = b;
    mp['C'] = c;
  }
  vector<char> v;
  bool f = true;
  for(int i = 0; i < n; ++i){
    char c1,c2; cin >> c1 >> c2;
    if(mp[c1] > mp[c2]){
      v.emplace_back(c2);
      mp[c1]--;
      mp[c2]++;
    } else {
      v.emplace_back(c1);
      mp[c1]++;
      mp[c2]--;
    }
    for(auto e:mp)if(e.second < 0)f = false;
  }
  if(f){
    cout << "Yes" << endl;
    for(auto e:v)cout << e << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    LL a, b, c, k;
    cin >> a >> b >> c >> k;
    if(k%2 == 0){
        cout << a-b << endl;
    }else{
        cout << -a+b << endl;
    }
    return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector<double> v(n);
    rep(i, n) cin >> v.at(i);
    sort(v.begin(), v.end());
    double ans = v.at(0);
    for(int i = 1; i < n; i++) {
        ans += v.at(i) * pow(2, i - 1);
    }
    ans /= pow(2, n-1);
    cout << fixed << setprecision(10) << ans << endl;
    return 0;
}


Measured memory_bytes: 512
package main

import "fmt"

func getEven(N int) int {
	if N == 0 {
		return 0
	}
	if N == 1 {
		return 0
	}
	if N == 2 {
		return 1
	}

	return N*(N-1)/2
}

func main(){
	var N,M int
	fmt.Scanf("%d%d",&N,&M)

	fmt.Println(getEven(N) + getEven(M))

}


Measured memory_bytes: 512
fun main(arr: Array<String>) {
    if(getAns()) {
        println("Yes")
    } else {
        println("No")
    }
}

fun getAns():Boolean {
    val count = readLine()!!.toInt()
    val log = (1..count).map { readLine()!! }
    val memo = mutableSetOf(log.first())
    for(i in (1 until count)) {
        if(log[i-1].last() != log[i].first()) {
            return false
        }
        if(memo.contains(log[i])) {
            return false
        }
        memo.add(log[i])
    }
    return true
}


Measured memory_bytes: 41228
import java.util.Scanner;
  
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
 
        int n = scan.nextInt();
 
        double[] x = new double[n];
        for(int i = 0; i < n; i++) {
            x[i] = scan.nextDouble();
        }
  
        double[] y = new double[n];
        for(int i = 0; i < n; i++) {
            y[i] = scan.nextDouble();
        }
  
        double p1_sum = 0;
        double p2_sum = 0;
        double p3_sum = 0;
        double p4_max = 0;
        for(int i = 0; i < n; i++) {
            double diff = Math.abs(x[i] - y[i]);
            p1_sum += diff;
            p2_sum += Math.pow(diff, 2);
            p3_sum += Math.pow(diff, 3);
            if(diff > p4_max) {
                p4_max = diff;
            }
        }
  
        System.out.println(p1_sum);
        System.out.println(Math.sqrt(p2_sum));
        System.out.println(Math.cbrt(p3_sum));
        System.out.println(p4_max);
    }
}


Measured memory_bytes: 28848
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);



int main(){

  string s;
  cin >> s;

  int ans = 700;

  REP(i, s.size()){
    if(s[i] == 'o') ans += 100;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3564
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <string>

using namespace std;

#define LL long long

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

int main() {
	int n;
	string s;
	cin >> n;
	cin >> s;
	int res = 0;
	for (int i = 0; i < n - 2; ++i) {
		if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') {
			++res;
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

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

    int n;
    ll C;
    cin >> n >> C;
    ll X[n], V[n];
    for (int i = 0; i < n; i++) {
        ll x, v;
        cin >> X[i] >> V[i];
    }

    ll forward[n], backward[n];
    forward[0] = V[0] - X[0];
    backward[n-1] = V[n-1] - C + X[n-1];
    for (int i = 1; i < n; i++) {
        forward[i] = forward[i-1] + V[i] - X[i] + X[i-1];
        backward[n-i-1] = backward[n-i] + V[n-i-1] + X[n-i-1] - X[n-i];
    }

    ll forward_and_return[n], backward_and_return[n];
    ll fmx = 0LL, bmx = 0LL;
    for (int i = 0; i < n; i++) {
        fmx = max(fmx, forward[i] - X[i]);
        forward_and_return[i] = fmx;
        bmx = max(bmx, backward[n-i-1] - C + X[n-i-1]);
        backward_and_return[n-i-1] = bmx;
    }

    ll ret = 0LL;
    for (int i = 0; i < n-1; i++) {
        ret = max(ret, forward[i] + backward_and_return[i+1]);
    }
    ret = max(ret, forward[n-1]);

    for (int i = 1; i < n; i++) {
        ret = max(ret, backward[i] + forward_and_return[i-1]);
    }
    ret = max(ret, backward[0]);

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

Measured memory_bytes: 4992
use List::Util qw(max min sum);

my ($n, $m, $q) = split(/\s+/, <>);
my (@a, @b, @c, @d);
for (1..$q) {
    ($a[$_],$b[$_],$c[$_],$d[$_]) = split(/\s+/, <>);
}

my @x;
for (0..$m) { $x[$_] = 1; }

sub ans {
    my $ret = 0;
    for (1..$q) {
	if ($x[$b[$_]]-$x[$a[$_]]==$c[$_]) {
	    $ret += $d[$_];
	}
    }
    return $ret;
}

my $max = 0;
sub loop {
    my ($level) = @_;
    if ($level == $n) {
	$max = max($max, ans());
	#print join(" ", @x), " max=$max\n";
	return;
    }
    for ($x[$level]..$m) {
	$x[$level+1] = $_;
	loop($level+1);
    }
    $x[$level+1] = $x[$level];
}

loop(0);
print "$max\n";


Measured memory_bytes: 5436
#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() {
    int N;
    string S;
    cin >> N >> S;
    int ans = 1;
    rep(i,N-1) {
        if (S.at(i) != S.at(i+1)) ++ans;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3756
use proconio::input;

fn main() {
    input! {
        s: String,
    }

    let s = s.replace("BC", "D");

    let v = s.chars().collect::<Vec<_>>();

    let mut count = 0usize;
    let mut a_count = 0usize;

    for c in v {
        match c {
            'A' => {
                a_count += 1;
            },
            'D' => {
                count += a_count;
            },
            _ => {
                a_count = 0;
            }
        }
    }

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


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

using namespace std;
using ll = long long;

int main() {
  string* s;
  int* t;
  int n, ans = 0;
  cin >> n;
  s = new string[n];
  t = new int[n];
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    cin >> t[i];
    }
    string x;
    cin >> x;
    for (int i = 0; i < n;++i){
        ans += t[i];
        if(s[i] == x) ans = 0;
    }
    cout << ans;
}

Measured memory_bytes: 256
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};

#[fastout]
fn main() {
    input! {//
        p:usize,q:usize,r:usize
    }
    println!("{}", p + q + r - max(max(p, q), r));
}


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

ll f(ll n);
void dig(ll n, ll d[]);
ll make_l(ll n);
ll make_s(ll n);
bool isOK(ll n);

ll dp[10005];

int main()
{
    for (int i = 0; i <= 10005; i++) {
        dp[i] = -1;
    }
    dp[6174] = 0;

    ll n;
    
    while (scanf("%lld", &n), n != 0) {
        if (!isOK(n)) {
            printf("NA\n");
        }
        else {
            printf("%lld\n", f(n));
        }
    }

    return 0;
}

ll f(ll n)
{
    if (dp[n] != -1) {
        return dp[n];
    }

    ll l = make_l(n);
    ll s = make_s(n);

    return dp[n] = f(l - s) + 1;
}

void dig(ll n, ll d[])
{
    d[n % 10]++;
    d[(n / 10) % 10]++;
    d[(n / 100) % 10]++;
    d[(n / 1000) % 10]++;
}

ll make_l(ll n)
{
    ll d[10] = {};
    ll ret = 0;

    dig(n, d);

    for (int i = 9; i >= 0; i--) {
        while (d[i]) {
            d[i]--;
            ret *= 10;
            ret += i;
        }
    }

    return ret;
}

ll make_s(ll n)
{
    ll d[10] = {};
    ll ret = 0;

    dig(n, d);

    for (int i = 0; i <= 9; i++) {
        while(d[i]) {
            d[i]--;
            ret *= 10;
            ret += i;
        }
    }

    return ret;
}

bool isOK(ll n)
{
    ll d[10] = {};

    dig(n, d);
    for (int i = 0; i <= 9; i++) {
        if (d[i] == 4) {
            return false;
        }
    }

    return true;
}



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



signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
    
    
    string s;
    int d;
    cin>>s>>d;
    int n = s.size();
    ll mod = 1e9+7;
    ll dp[n+1][d][2]={};
    dp[0][0][0]=1;
    for(int i=0;i<n;i++){
        for(int j=0;j<d;j++){
            for(int k=0;k<10;k++){
                dp[i+1][(j+k)%d][1] += dp[i][j][1];
                if(s[i]=='0'+k){
                    dp[i+1][(j+k)%d][0] += dp[i][j][0];

                }
                if(s[i]>'0'+k){
                    dp[i+1][(j+k)%d][1] += dp[i][j][0];
                }
                dp[i+1][(j+k)%d][1] %= mod;
                dp[i+1][(j+k)%d][0] %= mod;
            }
        }
    }
    ll ans = dp[n][0][0] + dp[n][0][1];
    ans += mod - 1;
    ans %= mod;
    cout << ans << endl;
}

Measured memory_bytes: 15872
#ifndef ___Class_RMQ
#define ___Class_RMQ

#include <limits>
#include <vector>
#include <algorithm>

using namespace std;

template <typename Type> class RMQ
{
private:

	int size;

	vector<Type> minvalue;

	Type _query(int a, int b, int k, int l, int r)
	{
		if (r <= a || b <= l) { return INF; }
		if (a <= l && r <= b) { return minvalue[k]; }

		Type vl = _query(a, b, 2 * k, l, (l + r) / 2);
		Type vr = _query(a, b, 2 * k + 1, (l + r) / 2, r);

		return min(vl, vr);
	}

public:

	Type INF;

	RMQ(int size_)
	{
		INF = numeric_limits<Type>::max();

		for (size = 1; size < size_;) { size <<= 1; }

		minvalue = vector<Type>(size * 2, INF);
	}

	void update(int i, const Type& x)
	{
		i += size;

		minvalue[i] = x;

		while (i > 1)
		{
			i = i / 2;

			minvalue[i] = min(minvalue[2 * i], minvalue[2 * i + 1]);
		}
	}

	Type query(int s, int t)
	{
		return _query(s, t, 1, 0, size);
	}
};

#endif


// ------ main ------ //

#include <cstdio>

#pragma warning(disable: 4996)

int n, q, com, x, y;

int main()
{
	scanf("%d", &n);
	scanf("%d", &q);

	RMQ<int> r(n);

	for (int i = 0; i < q; i++)
	{
		scanf("%d", &com);
		scanf("%d", &x);
		scanf("%d", &y);

		if (com == 0) 
		{
			r.update(x, y);
		}
		if (com == 1) 
		{
			printf("%lld\n", r.query(x, y + 1));
		}
	}

	return 0;
}

Measured memory_bytes: 3464
use proconio::{fastout, input};
use std::io::*;
use std::str::FromStr;

use std::cmp::{max, min};

fn main() {
    input! {
        n: usize,
        d: usize,
        x: [[i64; d]; n],
    }

    let mut ok: Vec<bool> = vec![false; 16_001];
    let mut tmp = 1;

    while tmp * tmp < 16_001 {
        ok[tmp * tmp] = true;
        tmp += 1;
    }
    let mut cnt = 0;

    for i in 0..x.len() {
        for j in i..x.len() {
            let a = &x[i];
            let b = &x[j];
            let mut sum = 0;

            for i in 0..a.len() {
                sum += (a[i] - b[i]).abs() * (a[i] - b[i]).abs();
            }

            if ok[sum as usize] {
                cnt += 1;
            }
        }
    }

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


Measured memory_bytes: 2212