akhauriyash/Code-Regression huggingface dataset:
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

constexpr double PI = 3.14159265358979323846;
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

class ELeague {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      int n; cin >> n;
      vector<deque<int>> a(n, deque<int>());
      rep(i, n) {
        rep(j, n-1) {
          int t;
          cin >> t;
          t--;
          a[i].emplace_back(t);
          debug(i, t);
        }
      }

      int ans = 0;
      set<int> candidate;
      rep(i, n) {
        candidate.insert(i);
      }

      while(true) {
        set<int> remove;
        bool hasContent = false;
        for(auto i: candidate) {
          if (a[i].empty()) {
            continue;
          }
          hasContent = true;
          int k = a[i][0];
          debug(i, k, a[k][0]);
          if (a[k][0] == i) {
            debug(i, k);
            remove.insert(i);
            remove.insert(k);
          }
        }

        if (!hasContent) {
          break;
        }
        if (remove.empty()) {
          cout << -1 << endl;
          return;
        }
        candidate.clear();
        for(auto e: remove) {
          a[e].pop_front();
          candidate.insert(e);
        }
        ans++;
      }
      cout << ans << endl;
    }
};

signed main() {
  ELeague solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 4736
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

N = input()

A = []

for i in range(N):
    A.append(input())
A.sort()

if N % 2:
    pos = N / 2
    ans = 0
    for i in range(N):
        ans += abs(A[i] - A[pos]) * 2
    ans -= min(A[pos + 1] - A[pos], A[pos] - A[pos - 1])
    print ans
else:
    pos1 = N / 2 - 1
    pos2 = N / 2
    ans = (A[pos2] - A[pos1]) * (N - 1)
    for i in range(N):
        ans += min(abs(A[i] - A[pos1]), abs(A[i] - A[pos2])) * 2
    print ans

Measured memory_bytes: 11000
import sys

import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline


def searchPrimeNumber(N):
    N = N + 1
    is_prime = np.ones(N, dtype=bool)
    is_prime[:2] = 0
    N_max = int(np.sqrt(N))
    for j in range(2, N_max+1):
        if (is_prime[j]):
            is_prime[j*j::j] = False
    prime = np.arange(N)[is_prime]
    return prime


def main():
    Q = int(readline())
    m = map(int, read().split())
    LR = list(zip(m, m))
    A = searchPrimeNumber(10**5)
    B = np.zeros(10**5+3, dtype=np.int32)  # Bはゼロ始まり
    for a in A:
        if (a + 1) / 2 in A:
            B[a+1:] += 1  # like 2017の数より１つ大きい数から1増やす

    for l, r in LR:
        print(B[r+1] - B[l])


main()


Measured memory_bytes: 35280
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long
int p[100010], q[100010];

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int W, H;
    cin >> W >> H;
    rep(i, W) cin >> p[i];
    rep(i, H) cin >> q[i];
    sort(p, p + W);
    sort(q, q + H);
    int ans = 0;
    int i = 0, j = 0;
    while(i + j < W + H) {
        int P = INF, Q = INF;
        if (i < W) P = p[i];
        if (j < H) Q = q[j];
        int num = min(P, Q);
        if (P < Q) {
            i++;
            ans += ((H - j) + 1) * num;
        }
        else {
            j++;
            ans += ((W - i) + 1) * num;
        }
        //cout << ans << endl;
    }
    cout << ans << endl;

    return 0;
}


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

int main() {
  ll n;
  cin >> n;
  ll ans=0;
  rep(i,n) ans+=i;
  cout << ans << endl;
}


Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (lli i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (lli i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

lli uf[100001], size[100001];
lli n, m;
using P = pair<lli, lli>;
P e[100001];

lli root(lli i) { return i == uf[i] ? i : uf[i] = root(uf[i]); }
void unite(lli i, lli j) {
  lli ri = root(i), rj = root(j);
  lli a, b;
  if (size[ri] >= size[rj]) { a = ri; b = rj; }
  else { a = rj; b = ri; }
  uf[b] = a;
  size[a] += size[b];
  size[b] = 0;
}
bool same(lli i, lli j) { return root(i) == root(j); }

int main() {
  cin >> n >> m;
  for (lli i=0; i<m; ++i) {
    cin >> e[i].first >> e[i].second;
  }

  for (lli i=1; i<=n; ++i) {
    uf[i] = i;
    size[i] = 1;
  }

  lli scr = n*(n-1)/2;
  vector<lli> res;
  res.push_back(scr);
  for (lli i=m-1; i>0; --i) {
    lli u = e[i].first, v = e[i].second;
    
    if (!same(u, v)) {
      lli su = size[root(u)], sv = size[root(v)];
      scr -= su * sv;

      unite(u, v);
    }

    res.push_back(scr);
  }

  while (!res.empty()) {
    cout << res.back() << '\n';
    res.pop_back();
  }
  return 0;
}


Measured memory_bytes: 5364
#include <iostream>
#include <vector>
#include <numeric>
#include <string>

using namespace std;


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

    string s;
    cin >> s;

    int r = 0;
    char R = 'R';
    for (int i = 0; i < s.size(); i++)
    {
        if ( s[i] == R) r++;
    }


    string result = "No";

    if (r > s.size() - r)
    {
        result = "Yes";
    }
    
    cout << result;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define REP(i,a,n) for(int i=a;i<(n);i++)
using namespace std;
signed main()
{
	ios::sync_with_stdio(0);
    cin.tie(0);
	int n,x,a,cnt0,cnt1,ans=1;
	cnt0=0;
	cin>>n>>x;
	REP(i,0,n){
		cin>>a;
		cnt1=a+cnt0;
		cnt0=cnt1;
		if(cnt1<=x)ans++;
	}
	cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3632
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder.Contest.B
{
	static class Program
	{
		public static void Main(string[] args)
		{
			var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
			Console.SetOut(sw);

			var cin = new Scanner();
			long a = cin.NextLong();
			long v = cin.NextLong();
			long b = cin.NextLong();
			long w = cin.NextLong();
			long t = cin.NextLong();
			if (v <= w) Console.WriteLine("NO");
            else
            {
				if (Math.Abs(a - b) <= t * (v - w)) Console.WriteLine("YES");
                else Console.WriteLine("NO");
            }

			Console.Out.Flush();
		}
	}

	class Scanner
	{
		string[] s;
		int i;

		char[] cs = new char[] { ' ' };

		public Scanner()
		{
			s = new string[0];
			i = 0;
		}

		public string Next()
		{
			if (i < s.Length) return s[i++];
			string st = Console.ReadLine();
			while (st == "") st = Console.ReadLine();
			s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			if (s.Length == 0) return Next();
			i = 0;
			return s[i++];
		}

		public int NextInt()
		{
			return int.Parse(Next());
		}

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextInt() + add;
			}
			return Array;
		}

		public long NextLong()
		{
			return long.Parse(Next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextLong() + add;
			}
			return Array;
		}

		public double NextDouble()
		{
			return double.Parse(Next());
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextDouble() + add;
			}
			return Array;
		}
	}
}

Measured memory_bytes: 27536
n=int(input())
h=list(map(int,input().split()))
dp=[0]*n
dp[1]=abs(h[1]-h[0])
for i in range(2,n):dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
print(dp[-1])

Measured memory_bytes: 13908
#include <stdio.h>

void swap(long long  *x, long long  *y){long long  t = *x; *x = *y; *y = t;}

int main(){
  long long  n, a[101], i, j, c = 0;
   while(scanf("%lld", &n) && n){
    for(i = 0; i < n; i++) scanf("%lld\n", &a[i]);

    for(i = 0; i < n; ++i)
      for(j = n - 1; j > i; --j)
        if(a[j] < a[j - 1]){
          swap(&a[j], &a[j - 1]);
          c++;
        }

    printf("%lld\n", c);
    c = 0;
  }
  return 0;
}

Measured memory_bytes: 600
//#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"

using namespace std;

//------------------------------- Libraries --------------------------------//

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//akari : 1D, yukari : 2D, maki : 3D vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//akane : ascending order, aoi : decending order
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Dubug Functions ---------------------------//
inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}
//------------------------------- Solver ------------------------------------//

void solve()
{
    int n, q, l;
    cin >> n;
    akari<int> xs(n);
    for (int i = 0; i < n; i++)
    {
        cin >> xs[i];
    }
    cin >> l >> q;
    yukari<int> dp(n, akari<int>(21));
    for (int i = 0; i < n; i++)
    {
        dp[i][0] = distance(xs.begin(), upper_bound(xs.begin(), xs.end(), xs[i] + l)) - 1;
    }
    for (int k = 0; k < 20; k++)
    {
        for (int i = 0; i < n; i++)
        {
            dp[i][k + 1] = dp[dp[i][k]][k];
        }
    }
    while (q--)
    {
        int a, b;
        cin >> a >> b;
        if (a > b)
        {
            swap(a, b);
        }
        a--, b--;
        int ans = 0;
        for (int k = 20; k >= 0; k--)
        {
            if (dp[a][k] < b)
            {
                a = dp[a][k];
                ans |= 1 << k;
            }
        }
        ans++;
        cout << ans << '\n';
    }
}

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


Measured memory_bytes: 12928
"""
思い入れ:
これは、たしか僕がはじめて解こうとしたC問題であり、
はじめて解けなかったC問題でもある。
↓
解けなかった
"""
n = int(input())
Hs = list(map(int, input().split()))
ans = 'Yes'

for i in range(n-1):
    if Hs[i] > Hs[i+1] + 1:
        ans = 'No'
        break
    elif Hs[i] == Hs[i+1]+1:
        Hs[i+1] += 1

print(ans)

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

using namespace std;

long long sum;
int n,m,cnt;
pair <int, int> p[100005];
int main (){
	cin >> n >> m;
	for (int i = 1; i <= n; i++){
		cin >> p[i].first >> p[i].second;
	}
	sort(p + 1,p + n + 1);
	for (int i = 1; i <= n; i++){
		int cnti = 0;
		while (cnt != m){
			if (cnti == p[i].second){
				break;
			}
			else{
				sum += p[i].first;
			}
			cnt++;
			cnti++;
		}
	}
	cout << sum;
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main(){
  int n,k;
  cin >> n>>k;
  int d[k];
  for(int i=0;i<k;i++) cin >> d[i];
  int fla=0;
  for(int i=n;;i++){
    int p=i;
   while(1){
     if(p==0) break;
     int l=p%10;
     p/=10;
     for(int j=0;j<k;j++){
       if(d[j]==l) {
         fla=1;
         break;
       }
     }
     if(fla==1) break;
   }
   if(fla==0) {
     cout << i<<endl;
     return 0;
   }
   fla=0;
  }
}


Measured memory_bytes: 256
#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 <iomanip>
using namespace std;
#define int long long

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

    string s,t; cin >> s >> t;
    int n = s.size();
    int m = t.size();

    if(n < m){
        cout << "UNRESTORABLE" << endl;
        return 0;
    }

    for(int i = 0;i < n-m+1;i ++){
        if(s.substr(i,m) == t){
            for(int j = 0;j < n;j ++){
                if(s.at(j) == '?') s.at(j) = 'a';
            }
            cout << s << endl;
            return 0;
        }
    }

    for(int i = n-m;i >= 0;i --){
        int hantei = 1;
        for(int j = 0;j < m;j ++){
            if(!(s.at(i+j) == '?' || s.at(i+j) == t.at(j))){
                hantei = 0;
                break;
            }
        }

        if(hantei == 1){
            for(int j = 0;j < m;j ++){
                s.at(i+j) = t.at(j);
            }
            break;
        }

        if(i == 0 && hantei == 0){
            cout << "UNRESTORABLE" << endl;
            return 0;
        }
    }

    for(int i = 0;i < n;i ++){
        if(s.at(i) == '?') s.at(i) = 'a';
    }

    cout << s << endl;
}

Measured memory_bytes: 3628
#pragma comment(linker, "/stack:247474112")
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define RANGE(i, x, n) for(int i = x; i < n; ++i)
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;

void accelerate()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

int main()
{
    accelerate();
    int n;
    cin >> n;
    cout << 180ll*(n-2) << endl;
}


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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

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

    cout << (b - a) * (b - a + 1) / 2 - b << '\n';
    return (0);
}


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

#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
// #define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
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;}
map<string,bool> mp;

bool iscat(string s){
	auto itr = mp.find(s);
    if( itr != mp.end() ) return mp[s];
	if(s == "") return true;
	if(s[0] == 'm' && s[s.size()-1] == 'w'){
		//find e
		string ns = s.substr(1,s.size()-2);
		//if(ns[0] == 'm' && ns[ns.size()-1] == 'w') return iscat(ns);
		REP(i,ns.size()){
			if(ns[i] == 'e'){//0 1 2 3 4 5 ns.size() = 6 i = 2
				string lstr = ns.substr(0,i);
				string rstr = ns.substr(i+1,ns.size()-i-1);
				if(iscat(lstr)&&iscat(rstr)){
					mp[s] = true;
					return true;
				}
			}
			
		}
		mp[s] = false;
		return false;
	}else{
		return false;
	}
	//dummy
	return false;
}
int main(){
	string s;
	cin >> s;
	if(iscat(s)) cout << "Cat" << endl;
	else cout << "Rabbit" << endl;
}

Measured memory_bytes: 7668
#include <cstdio>
#include <vector>
using namespace std;
vector<int> a[100000], a2[100000];
int col = 0, c[100000], c2[100000];
void dfs(int cur){
    c[cur] = col;
    for (auto e : a[cur]) if (c[e] == -1) dfs(e);
}
void dfs2(int cur, int cc){
    c2[cur] = cc;
    for (auto e : a2[cur]) if (c2[e] == -1) dfs2(e, 1 - cc);
}
int main(){
    int n;
    scanf("%d", &n);
    int x[n], y[n], z[n];
    for (int i = 0; i < n - 1; i++){
        scanf("%d %d %d", &x[i], &y[i], &z[i]);
        x[i]--;
        y[i]--;
        z[i] %= 2;
        if (z[i] == 0){
            a[x[i]].push_back(y[i]);
            a[y[i]].push_back(x[i]);
        }
        c[i] = -1;
        c2[i] = -1;
    }
    c[n - 1] = -1;
    c2[n - 1] = -1;
    for (int i = 0; i < n; i++){
        if (c[i] == -1){
            dfs(i);
            col++;
        }
    }
    for (int i = 0; i < n - 1; i++){
        if (z[i] == 0) continue;
        a2[c[x[i]]].push_back(c[y[i]]);
        a2[c[y[i]]].push_back(c[x[i]]);
    }
    dfs2(0, 0);
    for (int i = 0; i < n; i++) printf("%d\n", c2[c[i]]);
}

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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    
	int ans = 0;
	int N;
	cin >> N;
	vector<int> A(N << 1);
	for (int& i : A) {
	    cin >> i;
	}
	sort(A.begin(), A.end());
	for (int i = 0; i < N; ++i) {
	    ans += A[i << 1];
	}
	cout << ans << "\n";
	return 0;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<string> vs;
#define fo(i, a, b) for (int i = a; i < b; i++)
#define re(i, n) fo(i, 0, n)
#define pb push_back
#define all(s) s.begin(), s.end()
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }

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

  bool gs = true;
  while(gs) {
    s.erase(s.size()-2);
    string a, b;
    a = s.substr(0, s.size()/2);
    b = s.substr(s.size()/2);
    if(a != b) gs = true;
    else gs = false;
  }
  cout << s.size() << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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;
}

//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}


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

	ll n;
	cin >> n;
	string s;
	cin >> s;
	ll ans = 0;
	REP(i, n - 2) {
		if (s.substr(i, 3) == "ABC") {
			ans++;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 384
#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 <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;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)
#define FORR(i,n,m) for(int i=n-1;i>=m;i--)
#define ARR(array) for(int i=0;i<array.size();i++)
#define all(in) in.begin(),in.end()
#define ALL(in,K) in,in+K
#define INF 1e18
#define MOD 1000000007
#define SIZE 10005
#define PI 	3.14159265358979323846

ll euclidean_gcd(ll a, ll b) {
  if(a < b) euclidean_gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int input(){
  ll a;
  cin >> a;
  return a;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a[200100]={0};
    int n;
    cin >> n;
    int sum=-input();
    REP(i,n){
      int b;
      cin >> b;
      if(!a[b])sum++;
      a[b]++;
    }
    sort(a,a+n+1);
    int ans=0;   
    for(int i=0;;i++){
      if(sum<=0)break;
      if(!a[i])continue;
      ans+=a[i];
      sum--;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
def Type_1(H,W):
    A=H//3
    B=(H+2)//3
    return (B-A)*W

def Type_2(H,W):
    M=float("inf")
    for x in range(1,H):
        P=x*W
        Q=(H-x)*(W>>1)
        M=min(M,max(P,Q,H*W-(P+Q))-min(P,Q,H*W-(P+Q)))
    return M

def Type_Merge(H,W):
    X=Type_1(H,W)
    Y=Type_2(H,W)
    return min(X,Y)

H,W=map(int,input().split())

print(min(Type_Merge(H,W),Type_Merge(W,H)))


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

using namespace std;

// Header files, namespaces,
// macros as defined above
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>


#define f first
//#define s second
#define db double
#define pb push_back
#define sz(c) (c).size()
#define all(c) (c).begin(),(c).end()

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

const ll mod = 1e9+7;
const int MAX = 2999+5;
const db eps = 1e-13;


db dp[MAX][MAX];


int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
    cout<<setprecision(11)<<fixed;
    int n;
    cin>>n;
    vector <db> v(n+1);

    for( int i = 1; i <= n ; i++ )
        cin>>v[i];

    dp[1][0] = 1;

    for( int i = 1; i <= n ; i++ )
        for( int j = 0 ; j <= n ; j++ ) {
            dp[i+1][j] += dp[i][j]*(1.0-v[i]);
            dp[i+1][j+1] += dp[i][j]*v[i];
        }
    db ans = 0;

    for( int j = n ; j >= (n/2+1) ; j-- )
        ans += dp[n+1][j];
    cout<<ans<<"\n";

}


Measured memory_bytes: 70656
use std::cmp::max;

const INF: i64 = 1 << 50;

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let n: usize = sc.read();
    let a: Vec<i64> = sc.vec(n);
    let odd = a
        .iter()
        .enumerate()
        .map(|(i, &a)| (max(a, 0), i))
        .filter(|t| t.1 % 2 == 1)
        .map(|t| t.0)
        .sum::<i64>();
    let even = a
        .iter()
        .enumerate()
        .map(|(i, &a)| (max(a, 0), i))
        .filter(|t| t.1 % 2 == 0)
        .map(|t| t.0)
        .sum::<i64>();

    let mut ans = vec![];
    if *a.iter().max().unwrap() < 0 {
        let i = a.iter().enumerate().max_by_key(|t| *t.1).unwrap().0;
        ans.push(i);
    } else if even > odd {
        for i in 0..n {
            if i % 2 == 0 && a[i] >= 0 {
                ans.push(i);
            }
        }
    } else {
        for i in 0..n {
            if i % 2 == 1 && a[i] >= 0 {
                ans.push(i);
            }
        }
    }

    assert!(ans.len() > 0);
    let mut operations = vec![];
    for i in 0..n {
        if i == ans[0] {
            break;
        }
        operations.push(0);
    }
    for i in 1..ans.len() {
        let prev = ans[i - 1];
        let cur = ans[i];
        let count = cur - prev - 1;
        assert_eq!(count % 2, 1);

        let t = (count + 1) / 2;
        for i in 0..t {
            operations.push(t - i);
        }
    }

    let count = n - (ans[ans.len() - 1] + 1);
    for i in 0..count {
        operations.push(count - i);
    }

    let sum = ans.iter().map(|&i| a[i]).sum::<i64>();
    println!("{}", sum);
    println!("{}", operations.len());
    for &o in operations.iter() {
        println!("{}", o + 1);
    }
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> Self {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
bool chmin(ll&a,ll b){if(a>b){a=b;return true;}return false;}
bool chmax(ll&a,ll b){if(a<b){a=b;return true;}return false;}
#define debg cout<<"debg"<<endl
#define out(a) cout<<(a)<<endl
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
signed main(){
  
  ll n;cin>>n;
  vector<ll> a(n);
  rep(i,n)cin>>a[i];

  ll ans=0;
  rep(i,n)ans+=a[i]-1;
  out(ans);

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define REPR(i,n) for(int i=n;i>=1;i--)
#define IFY 2000000000
#define MAX 500000
#define NIL -1
using namespace std;
int H,A[MAX+1];
void maxheapify(int i){
  int l,r,largest;
  l=2*i;r=2*i+1;
  if(l<=H&&A[l]>A[i]) largest=l;
  else largest=i;
  if(r<=H&&A[r]>A[largest]) largest=r;
  if(largest!=i){
    swap(A[i],A[largest]);
    maxheapify(largest);
  }
}
int main(){
  scanf("%d",&H);
  REPP(i,H) scanf("%d",&A[i]);
  REPR(i,H/2) maxheapify(i);
  REPP(i,H) printf(" %d",A[i]);
  printf("\n");
  return 0;
}

Measured memory_bytes: 5136
N, D = map(int, input().split(" "))
X = [list(map(int, input().split(" "))) for i in range(N)]
dist = []
n = 0
while n * n <= 16000:
    dist.append(n * n)
    n += 1


def Dis(x, y):
    return sum([(a - b)**2 for a, b in zip(x, y)])


cnt = 0
for i in range(N):
    for j in range(i + 1, N):
        dd = Dis(X[i], X[j])
        for d in dist:
            if dd == d:
                cnt += 1
                break
print(cnt)

Measured memory_bytes: 38768
N = raw_input()

def average(N):
    if N == "":
        return 'Yes'

    count = 0
    for i in range(len(N)):
        if N[0] == N[i]:
            count+=1

    if count % 2 == 1:
        return 'No'

    N = N.replace(N[0],"")
    return average(N)

print average(N)

Measured memory_bytes: 2568
#include <stdio.h>

int main(){
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    int max = 0;
    int min = 10001;
    int middle = 0;
    
    if(a > max) max = a;
    if(b > max) max = b;
    if(c > max) max = c;

    if(a < min) min = a;
    if(b < min) min = b;
    if(c < min) min = c;
    
    middle = (a+b+c) - max - min;

    printf("%d %d %d\n", min, middle, max);
}


Measured memory_bytes: 2108
import bisect
n = int(input())
a = list(map(int,input().split()))
q = int(input())
b = [0 for _ in range(q)]
c = [0 for _ in range(q)]
for i in range(q):
    b[i],c[i] = map(int,input().split())

cnt = [0 for _ in range(100001)]
for i in a:
    cnt[i] += 1

ans = sum(a)

for i in range(q):
    current = cnt[b[i]]*(c[i]-b[i])
    ans += current
    print(ans)
    cnt[c[i]] += cnt[b[i]]
    cnt[b[i]] = 0

Measured memory_bytes: 22800
n=int(input())
mod=10**9+7
a=list(map(int,input().split()))
ans=[0]*(10**5+1)
flag=False
if n%2==0:
  for i in range(len(a)):
    if a[i]%2==0:
      flag=True
      break
    ans[a[i]]+=1
    if ans[a[i]]>2:
      flag=True
      break
else:
  for i in range(len(a)):
    if a[i]%2==1:
      flag=True
      break
    ans[a[i]]+=1
    if ans[0]>1:
      flag=True
      break
    if ans[a[i]]>2:
      flag=True
      break
if flag==True:
  print(0)
else:
  print(pow(2,(n//2),mod))

Measured memory_bytes: 14008
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		int A = in.nextInt();	//1が書かれたカードの枚数
		int B = in.nextInt();	//0が書かれたカードの枚数
		int C = in.nextInt();	//-1が書かれたカードの枚数
		int K = in.nextInt();	//取る枚数
		int max = 0;		//最大値
 
		if(K<=A){
			max = K;
		}
		if(K>A){
			if(K<=(A+B)){
				max = A;
			}
			if(K>(A+B)){
				max = A - (K-A-B);
			}
		}
 
		System.out.println(max);
	}
}

Measured memory_bytes: 35788
#include<bits/stdc++.h>
using namespace std;
int main() {
    string s,p;
    cin >> s >> p;
    int ans=0;
    for(int i=0;i < s.size();i++)
        s[i] = tolower(s[i]);
    while(p!="END_OF_TEXT") {
        for(int i=0;i<p.size();i++)
            p[i] = tolower(p[i]);
        if(s == p)
            ans++;
        cin >> p;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3208
#include <stdio.h>

int main(void)
{
  int student[5], i, total = 0;

  for(i = 0; i < 5; i++){
    scanf("%d", &student[i]);
    if(student[i] < 40)
      student[i] = 40;

    total += student[i];
  }

  printf("%d\n", total/5);

  return 0;
}

Measured memory_bytes: 600
N = int(input())
input_line = []
for i in range(N):
    input_line.append(int(input()))

maxv = input_line[1] - input_line[0]
minv = input_line[0]
for j in range(1, N):
    maxv = max(maxv, input_line[j] - minv)
    minv = min(minv, input_line[j])
print(maxv)

Measured memory_bytes: 15608
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        char[] s = sc.next().toCharArray();
        char[] t = sc.next().toCharArray();

        StringBuffer answer = new StringBuffer();
        for (int i = 0; i < n; i++) {
            answer.append(s[i]);
            answer.append(t[i]);
        }

        System.out.println(answer);
    }
}


Measured memory_bytes: 21844
import sys

n = int(input())
htable = [0 for _ in range(16777216)]


def to_int(s):
    if s == 'A':
        return 1
    elif s == 'C':
        return 2
    elif s == 'G':
        return 3
    else:
        return 4


def to_hash(string):
    h = 0
    for i, s in enumerate(string):
        ints = to_int(s)
        h += 4**i * ints

    return h


def insert(string):
    h = to_hash(string)
    htable[h] = 1


def find(string):
    h = to_hash(string)
    if htable[h]:
        print('yes')
    else:
        print('no')


for line in sys.stdin:
    cmd, string = line.strip().split()

    if cmd == 'insert':
        insert(string)

    else:
        find(string)



Measured memory_bytes: 138492
from functools import reduce

def main():
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    # 1e10

    # 初期値用:十分小さい数(-100億)
    # -1e10
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]
    T = [
        ['d','r','e','a','m'],
        ['d','r','e','a','m','e','r'],
        ['e','r','a','s','e'],
        ['e','r','a','s','e','r']
    ]
    # S = list(_ for _ in input())
    S = input()
    S = S[::-1]
    # S.reverse()
    # S.sort(reversed=True)

    for i in range(4):
        T[i].reverse()
    while len(S)>0:
        if(''.join(S[0:len(T[0])]) == ''.join(T[0])):
            S = S[len(T[0]):]
            # for i in range(len(T[0])):
            #     S.pop(0)
        elif(''.join(S[0:len(T[1])]) == ''.join(T[1])):
            S = S[len(T[1]):]
            # for i in range(len(T[1])):
            #     S.pop(0)
        elif(''.join(S[0:len(T[2])]) == ''.join(T[2])):
            S = S[len(T[2]):]
            # for i in range(len(T[2])):
            #     S.pop(0)
        elif(''.join(S[0:len(T[3])]) == ''.join(T[3])):
            S = S[len(T[3]):]
            # for i in range(len(T[3])):
            #     S.pop(0)
        else:
            print('NO')
            break
        
    if(len(S) ==0):
        print('YES')

    
if __name__ == '__main__':
    main()


Measured memory_bytes: 3812
// Charan Sriramula
 
#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long int ll;
 
const ll lg=22;
const ll N=2e5+5;
const ll M=5e8;
const ll INF=1e18;
const ll mod=1e9+7;
const double PI = 3.14159265358979323846;
 
#define is(n) scanf("%d",&n)
#define io(n) printf("%d\n",n)
#define ls(n) scanf("%lld",&n)
#define lo(n) printf("%lld\n",n)
 
#define f first
#define s second
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define mp(x,y) make_pair(x,y)
#define GCD(a,b) __gcd((a),(b))
#define all(v) v.begin(),v.end()
#define bits(x) __builtin_popcount(x)
#define LCM(a,b) ((a)*(b))/GCD((a),(b))
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
template<typename T> T power(T x,T y,ll m){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}
 
inline ll mul(ll a, ll b, ll p){ return (a * 1ll * b) % p; }
inline ll sub(ll a, ll b, ll p){ ll c = a - b; if(c < 0) c += p; return c; }
inline ll add(ll a, ll b, ll p){ ll c = a + b; if(c > p) c -= p; return c; }
 
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

ll n,k;

int main()
{
  fast;
    cin>>n>>k;
    if(n==2)
    {
        if(k==0)
        {
            cout<<1<<endl;
            cout<<1<<" "<<2<<endl;
            exit(0);
        }
        cout<<-1<<endl;
        exit(0);
    }
    vector<pair<ll,ll> > ans;
    ll maxi=((n-2)*(n-1))/2;
    if(k>maxi){cout<<-1<<endl;exit(0);}
    for(ll i=2;i<=n;i++){ans.pb(mp(1,i));}
    if(k==maxi)
    {
        cout<<ans.size()<<endl;
        for(auto i:ans){cout<<i.f<<" "<<i.s<<endl;}
        exit(0);
    }
    ll rem=maxi-k;
    for(ll i=2;i<=n;i++)
    {
        if(rem==0){break;}
        for(ll j=i+1;j<=n;j++)
        {
            if(rem==0){break;}
            ans.pb(mp(i,j));
            rem--;
        }
    }
    cout<<ans.size()<<endl;
    for(auto i:ans){cout<<i.f<<" "<<i.s<<endl;}
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
ll a,b,c,i,j,k,l,m,n,ans,tmp,hoge,fuga,piyo;
ll x[10010],y[200200];
string s,str;
char ch;
int main(){
  cin>>a;
  b=0;
  for(int i=0;i<=a/500;i++){
    b=i*1000+(a-500*i)/5*5;
    if(ans<b)ans=b;
  }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#define push_back pb
int main()
{
   int n,k;
  cin>>n>>k;
  vector<int> v(n);
  for(int i=0;i<n;i++)
  cin>>v[i];
  vector<int>dp(n,INT_MAX);
dp[0]=0;
for(int i=0;i<n;i++){
  for(int j=i+1;j<=i+k;j++)
  if(j<n)
  {dp[j]=min(dp[j],dp[i]+abs(v[i]-v[j]));}
}

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

Measured memory_bytes: 1024
//By Tushar Gautam
#pragma GCC optimize ("-O2")
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define memreset(a) memset(a,0,sizeof(a))
#define testcase(t) int t;cin>>t;while(t--)
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define leadzero(a) __builtin_clz(a) // count leading zeroes
#define trailzero(a) __builtin_ctz(a) // count trailing zeroes
#define bitcount(a) __builtin_popcount(a) // count set bits (add ll)
#define ln "\n"
#define dbgarr(v,s,e) cerr<<#v<<" = "; forsn(i,s,e) cerr<<v[i]<<", "; cerr<<endl
#define inputfile freopen("input.txt", "r", stdin)
#define outputfile freopen("output.txt", "w", stdout)
#define dbg(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) { cerr<<endl; }
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << "\t"; err(++it, args...);
}
template<typename T1,typename T2>
ostream& operator <<(ostream& c,pair<T1,T2> &v){
	c<<"("<<v.fi<<","<<v.se<<")"; return c;
}
template <template <class...> class TT, class ...T>
ostream& operator<<(ostream& out,TT<T...>& c){
    out<<"{ ";
    forstl(x,c) out<<x<<" ";
    out<<"}"; return out;
}
typedef long long int  ll;
typedef long double  ld;
typedef pair<ll,ll> p64;
typedef pair<int,int> p32;
typedef pair<int,p32> p96;
typedef vector<ll> v64;
typedef vector<int> v32; 
typedef vector<v32> vv32;
typedef vector<v64> vv64;
typedef vector<p32> vp32;
typedef vector<vp32> vvp32;
typedef map<int,int> m32;
const int LIM = 1e5+5, MOD = 1e9+7;
int t,n,m,k,x,y;
vv32 v;
v32 vs;
v32 topo;
void dfs(int i){
	vs[i]=1;
	forstl(it,v[i]){
		if(!vs[it])  dfs(it);
	}
	topo.pb(i);
}
int main(){
	fastio;
	cin>>n>>m;
	v.assign(n,v32(0));
	forn(i,m){
		cin>>x>>y; --x,--y;
		v[x].pb(y);
	}
	vs.assign(n,0);
	forn(i,n){
		if(!vs[i]) dfs(i);
	}
	int dp[n]={0};
	int in[n]={0};
	//dbg(topo);
	forn(i,n){
		in[topo[i]]=i;
	}
	forn(i,n){
		int c=1;
		forstl(it,v[topo[i]]){
			c=max(c,1+dp[in[it]]);
		}
		dp[i]=c;
	}
	int ans=0;
	forn(i,n) ans=max(ans,dp[i]);
	cout<<ans-1<<ln;
	return 0;
}

Measured memory_bytes: 8828
#include <iostream>
#include <string>
#include <vector>
#include <cstring>
#include <numeric>

using namespace std;
using ll = long long;

ll gcd (ll a, ll b) {
    while (b) {
        a %= b;
        swap (a, b);
    }
    return a;
}

ll lcm (ll a, ll b) {
    return a / gcd (a, b) * b;
}

int main() {
    ll a, b;
    cin >> a >> b;
    cout << lcm(a, b) << "\n";


    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<string>
#include<set>
#include<vector>
#include<utility>
#include<algorithm>

using namespace std;

#define LL long long
#define MOD 1000000007

LL a, b, ans = 2019;

int main() {
	cin >> a >> b;
	if (b - a + 1 >= 2019) ans = 0;
	else {
		a %= 2019; b %= 2019;
		if (b < a) swap(a, b);
		for (LL i = a; i <= b; i++) {
			for (LL j = i + 1; j <= b; j++) {
				ans = min(ans, i*j % 2019);
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
main = interact $ put . sol . read

put = unlines . map (unwords . map show)

n = 50

sol :: Integer -> [[Integer]]
sol k = [[n],map (+ q) as]
  where
  (q,r) = k `quotRem` n
  as = replicate (fromIntegral r) n ++ replicate (fromIntegral (n-r)) (n-r-1)

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

int main()
{
  string r, a;
  int c1, c2;

  while (cin >> r >> a && r != "0"){
    c1 = c2 = 0;
    for (int i = 0; i < 4; i++){
      if (r[i] == a[i]){
        c1++;
      }
    }
    for (int i = 0; i < 4; i++){
      for (int j = 0; j < 4; j++){
        if (r[i] == a[j] && i != j){
          c2++;
        }
      }
    }

    cout << c1 << " " << c2 << endl;
  }
}

Measured memory_bytes: 1184
/* ****mittal**** */
#include<bits/stdc++.h>
#define ll          long long int 
#define pb          push_back
#define endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define jell        998244353
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define repr(i,a,b)   for(ll int i=a;i>=b;i--)
#define lbnd    lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define DEC(N)  cout << std::fixed; cout << setprecision(N);
using namespace std;
ll add(ll x,ll y)
{
return (x%hell+y%hell)%hell;
}
ll mul(ll x,ll y)
{
return ((x%hell)*(y%hell))%hell;
}
ll sub(ll x,ll y)
{
return (x-y+hell)%hell;
}
#define N  100005
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll t=1;
   //cin>>t;
    for(int ok=1;ok<=t;ok++)
    {
        
        ll x,y;
        cin>>x>>y;
        for(int i=0;i<=x;i++)
        {
             if(i*2+(x-i)*4==y)
             {
                cout<<"Yes";
                return 0;
             }
        }
        cout<<"No";
    }
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#define MOD 1000000007LL
using namespace std;

int main(){
	string s;
	cin >> s;
	int a = 2000000, z = -1;
	for(int i = 0; i < s.size(); i++){
		if(s[i] == 'A' && a > i) a = i;
		if(s[i] == 'Z' && z < i) z = i;
	}
	cout << z - a + 1 << endl;
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int count = 0;
  for(int i = 0; i+2 < s.size(); i++) {
    if(s.at(i)=='A' && s.at(i+1)=='B' && s.at(i+2)=='C') count++;
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
typedef long long int ll;
#define int long long int
typedef vector<int> vi;
typedef pair<int, int> ii; typedef vector<ii> vii;
#define INF numeric_limits<ll>::max()
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x.size())
ll powmod(ll a,ll l, ll md){ll res=1;while(l){if(l&1)res=res*a%md;l/=2;a=a*a%md;}return res;}
ll binpow(ll a,ll l){ll res=1;while(l){if(l&1)res=res*a;l/=2;a=a*a;}return res;}
ll invmod(ll a, ll md){return powmod(a,md-2,md);}
const ll inf = 0xFFFFFFFFFFFFFFFL;
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int n, x, m;
    cin>>n>>x>>m;
    vi pos(m, -1);
    int val = x;
    vi arr_a(0);
    int left = 0;
    int right = m-1;
    for (int i=0; i<m; i++){
        if (pos[val] ==-1){
            pos[val] = i;
            arr_a.push_back(val);
            val = (val*val)%m;
        }
        else{
            left = pos[val];
            right = i-1;
            break;

        }
    }
    if (n-1 < left){
        int ans = 0;
        for (int i=0; i<n; i++){
            ans += arr_a[i];
        }
        cout<<ans<<"\n";

    }
    else{
        int q = (n-left)/(right- left +1);
        int r = (n-left)%(right- left +1);
        int sum1 = 0;
        int sum2 = 0;
        if (q>0){
            for (int i=left; i<=right; i++){
                sum1+= arr_a[i];
            }
        }
        for (int i=0; i<r+left; i++){
            sum2+= arr_a[i];
        }
        int ans = q*sum1 + sum2;
        cout<<ans<<"\n";

    }
    // for (auto x: arr_a){
    //     cout<<x<<" ";
    // }
    // cout<<"\n"<<left<<" "<<right<<"\n";
    return 0;
}
 

Measured memory_bytes: 4604
var lines = [];
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
reader.on('line', function (line) {
  lines.push(line);
});
process.stdin.on('end', function () {
  var count = lines[0];
  var array = lines[1].split(' ');
  var ammount = 0;
  for (var i=0;i < count;i++) {
    ammount += 1 / array[i];
      
  }
  console.log(1 / ammount);
});

Measured memory_bytes: 7628