akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include<algorithm>
#include<sstream>
#include<iomanip>
#include<deque>
#include<list>


using namespace std;

typedef long long ll;

typedef pair<int, int> pii;

const ll MOD_CONST = 1000000007;
const ll BIG_NUM = 1000000000000000000;
const int BIG_INT = 1000000000;


int gcd(int a, int b) {
	if (a == 0) {
		return b;
	}
	if (a > b) {
		swap(a, b);
	}
	
	return gcd(b%a, a);
}

int main() {
	int n, m;
	cin >> n >> m;
	ll lcm = 1LL * n * m / gcd(n, m);

	
	string s, t;
	cin >> s >> t;
	
	bool canConsist = true;
	
	for (ll i = 0; i < n;i += lcm/m) {
		if (s[i] != t[i*  (lcm / n)/(lcm/m)]) {
			canConsist = false;
		}
	}

	cout << (canConsist ? lcm : -1) << endl;
}



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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define fout(x) cout << fixed << setprecision(20) << x << endl
const int MOD = 1000000007;
const ll LINF = (ll)1e18 - 1;
const int INF = 1e9 - 1;
const double EPS = 0.000000001;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

auto print = [](auto &v) {
  for(auto x : v) {
    cout << x << " ";
  }
  cout << endl;
};

template <int mod = 1000000007>
struct Combination {
  std::vector<long long> fac, finv, inv;
  Combination(int n) : fac(n + 1, 0), finv(n + 1, 0), inv(n + 1, 0) {
    for (int i = 0; i < n + 1; ++i) {
      bool one_or_zero = i == 0 || i == 1;
      fac[i] = one_or_zero ? 1 : fac[i - 1] * i % mod;
      inv[i] = one_or_zero ? 1 : mod - inv[mod % i] * (mod / i) % mod;
      finv[i] = one_or_zero ? 1 : finv[i - 1] * inv[i] % mod;
    }
    inv[0] = 0;
  }
  int operator()(int n, int r) {
    if (n < r || n < 0 || r < 0)
      return 0;
    else if (n == r || r == 0)
      return 1;
    return fac[n] * (finv[r] * finv[n - r] % mod) % mod;
  }
};

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

  int n, k;
  cin >> n >> k;
  VL a(n);
  rep(i, n) cin >> a[i];

  Combination<> comb(n);

  sort(rall(a));
  ll ans = 0;
  rep(i, n) {
    ans = (ans + a[i] * comb((n - i - 1), (k - 1))) % MOD;
  }

  sort(all(a));

  rep(i, n) {
    ans = (ans - a[i] * comb((n - i - 1), (k - 1)) + MOD) % MOD;
  }

  out(ans % MOD);


  return 0;
}


Measured memory_bytes: 3456
(function(stdin) {
    // Define Function
    function Time(sec) {
        const ONE_HOUR_PAR_SECOND = 60 * 60;
        const ONE_MINITE_PAR_SECOND = 60;
        return {
            getHour: function() {
                return Math.floor(sec / (ONE_HOUR_PAR_SECOND)); },
            getMinite: function() {
                return Math.floor(sec % (ONE_HOUR_PAR_SECOND) / ONE_MINITE_PAR_SECOND); },
            getSecond: function() {
                return sec % ONE_MINITE_PAR_SECOND; },
            toString: function() {
                return [
                    this.getHour(), this.getMinite(), this.getSecond()
                ].join(':');
            }
        };
    }
    // Declare Variable
    const inputs = stdin.toString().trim().split('\n');

    // Main Procedure
    const result = (function(S) {
        const time = new Time(S);

        return time.toString();

    }(parseInt(inputs[0], 10)));

    // Display
    console.log(result);

}(require('fs').readFileSync('/dev/stdin', 'utf8')));

Measured memory_bytes: 15588
N = int(input())
INF = 1<<22
a = [int(c) for c in input().split()]+[INF]
l = 0
r = 1
s = a[l]
x = a[l]
ans = 0
for l in range(N):
  if l==r:
    r += 1
  while r<=N:
    if s!=x:
      break
#    print(a[r])
    s += a[r]
    x ^= a[r]
    r += 1
  s -= a[l]
  x ^= a[l]
  ans += r-l-1
#  print(l,r)
print(ans)

Measured memory_bytes: 79564
#include<iostream>
#include<math.h>
using namespace std;
int main(){
    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int sum =0;
    while(n>0){
        sum+=1;
        n-=k;
        if(n>0){
            n++;
        }
    }
    cout<<sum<<endl;
    return 0;
}   

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

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

    int fib[n+1];
    rep(i, n+1) fib[i] = 0;

    fib[0] = fib[1] = 1;
    rep(i, n+1)
    {
        if(i >= 2) fib[i] += fib[i-1] + fib[i-2];
    }
    
    cout << fib[n] << endl;
    return 0;
}


Measured memory_bytes: 3104
N = int(input())
mod = 10**9+7
# 素因数分解(小さい方から順に割っていく)
divisors = [0]*(N+1)
for j in range(2,N+1):
    s = 0
    L = j
    while s == 0:
        for i in range(2,N+1):
            if L % i == 0:
                divisors[i] += 1
                L //= i
                if L == 1:
                    s = 1 #1はこれ以上素因数を産まない
                break
cnt = 1
for div in divisors:
    if div > 0:
        cnt*=(div+1)
print(cnt%mod)

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

int main() {
  vector<int> prime(100001), sum(100000);
  for(int i = 2; i < 100001; i++) {
    prime[i] = 1;
  }
  for(int i = 2; i < sqrt(100001); i++) {
    if(prime[i]) {
      for(int j = 0; i * (j + 2) < 100001; j++) {
        prime[i * (j + 2)] = 0;
      }
    }
  }
  for(int i = 99999; i >= 0; i -= 2)
    if(!prime[(i + 1) / 2])
      prime[i] = 0;
  int tm = 0;
  for(int i = 1; i <= 99999; i += 2) {
    if(prime[i])
      tm++;
    sum[i] = tm;
  }

  int q;
  cin >> q;
  vector<int> l(q), r(q);
  for(int i = 0; i < q; i++)
    cin >> l.at(i) >> r.at(i);
  for(int i = 0; i < q; i++) {
    if(!l.at(i))
      cout << sum[r.at(i)] << endl;
    else
      cout << sum[r.at(i)] - sum[l.at(i) - 2] << endl;
  }
}

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

int main(){
    int n, c = 0;
    cin>>n;
    vector<int> arr,temp;
    for(int i=0,a;i<n;i++){
        cin>>a;
        arr.push_back(a);
    }
    temp = arr;
    sort(temp.begin(),temp.end());
    for(int i=0;i<n;i++){
        if(arr[i] != temp[i]){
            c++;
        }
    }
    if(c>2){
        cout<<"NO"<<endl;
    }
    else{
       cout<<"YES"<<endl;
    }
}


Measured memory_bytes: 256
n,d=map(int,input().split(" "))
a=[]
for i in range(1,n+1):
    a.append(i)
flag=True
co=0
while flag==True:
    if len(a)>2*d+1:
        a=a[2*d+1:]
        co+=1
    else:
        co+=1
        flag=False
print(co)
    

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

#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define ACC(c) (accumulate(ALL(c), 0LL))
#define PRINT(x) cout << (x) << "\n"

using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;

inline int in(int& a) {return scanf("%d", &a);}
auto pint_compare = [](pint x, pint y) -> bool{return (x.first < y.first);};

int N;
int A[1000][1000];
vector<int> edge[1000000];
bool loop = false;
bool visited[1000000];
int dist[1000000];

int dfs(int index){
    if(dist[index] > 0){
        return dist[index];
    }else if(visited[index]){
        loop = true;
        return -1;
    }
    visited[index] = true;
    int m = 1;
    for(auto next : edge[index]){
        m = max(m, dfs(next) + 1);
    }
    return dist[index] = m;
}

signed main(){
    cin >> N;
    REP(i, N) REP(j, N - 1){
        cin >> A[i][j];
        A[i][j]--;
    }
    REP(i, N){
        REP(j, N - 2){
            int a = min(i, A[i][j]), b = max(i, A[i][j]), c = min(i, A[i][j + 1]), d = max(i, A[i][j + 1]);
            edge[a * (N - 1) + b].push_back(c * (N - 1) + d);
        }
    }
    REP(i, N * N) dist[i] = -1, visited[i] = false;
    int ans = 0;
    REP(i, N){
        REP(j, N - 1){
            ans = max(ans, dfs(i * (N - 1) + j));
            if(loop){
                PRINT("-1");
                return 0;
            }
        }
    }
    PRINT(ans);
    return 0;
}

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

using namespace std;

int main() {
    int x;cin >> x;
    vector < int64_t> vec(87);
    vec[0] = 2;
    vec[1] = 1;

    for (int i = 0; i <= x; i++) {
        if (i >= 2) {
            vec[i] = vec[i - 1] + vec[i -2];
        }
    }

        cout << vec[x]<<endl;
    
}

Measured memory_bytes: 256
#include <algorithm>
#include<stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include<stack>
#include <queue>
#include<map>
#include <set>
#include<math.h>
using namespace std;
#define int long long
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define Rep(i,n) for(ll i=1;i<=n;++i)
#define loop(i,m,n) for(ll i=m;i<n;++i)
#define ggr getchar(); getchar();return 0;
#define pie 3.141592653589793238462643383279
#define elif else if
#define P pair<ll,ll>
#define prique priority_queue<ll>
const int mod = 1000000007;
const int mod2 = 998244353;
int bin(int bina) {
	int ans = 0;
	for (int i = 0; bina > 0; i++)
	{
		ans = ans + (bina % 2) * pow(10, i);
		bina = bina / 2;
	}
	return ans;
}
bool prime(int n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
long nCr(int n, int r) {
	int ans = 1;
	for (ll i = n; i > n - r; --i) {
		ans = ans * i;
	}
	for (ll i = 1; i < r + 1; ++i) {
		ans = ans / i;
	}
	return ans;
}
struct union_find {
	int par[200010], size_[200010];
	void init(int x) {
		rep(i, x) { par[i] = i; size_[i] = 1; }
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return;
		if (size_[x] < size_[y]) {
			par[x] = y;
			size_[y] += size_[x];
		}
		else {
			par[y] = x;
			size_[x] += size_[y];
		}
	}
};
vector<int>a[200010];
int sum[200010] = {};
bool b[200010] = {};
void ki(int n) {
	rep(i, a[n].size()) { 
		if (b[a[n][i]]==false) {
			sum[a[n][i]] += sum[n];
			b[a[n][i]] = true;
			ki(a[n][i]);
		}
	}
	return;
}
signed main() {
	int n, q;
	cin >> n >> q;
	rep(i, n - 1) {
		int s, d;
		cin >> s >> d;
		if (d < s)swap(s, d);
		s--; d--;
		a[s].push_back(d);
		a[d].push_back(s);
	}
	rep(i, q) {
		int w,e;
		cin >> w >> e;
		sum[w - 1] += e;
	}
	b[0] = true;
	ki(0);
	rep(i, n) {
		cout << sum[i] << ' ';
	}
}


Measured memory_bytes: 24448
local mce, mfl, msq, mmi, mma = math.ceil, math.floor, math.sqrt, math.min, math.max
local mod = 1000000007
local function getprimes(x)
  local primes = {}
  local allnums = {}
  for i = 1, x do allnums[i] = true end
  for i = 2, x do
    if(allnums[i]) then
      table.insert(primes, i)
      local lim = mfl(x / i)
      for j = 2, lim do
        allnums[j * i] = false
      end
    end
  end
  return primes
end

local function getdivisorparts(x, primes)
  local prime_num = #primes
  local tmp = {}
  local lim = mce(msq(x))
  local primepos = 1
  local dv = primes[primepos]
  while(primepos <= prime_num and dv <= lim) do
    if(x % dv == 0) then
      local asdf = {}
      asdf.p = dv
      asdf.cnt = 1
      x = x / dv
      while(x % dv == 0) do
        x = x / dv
        asdf.cnt = asdf.cnt + 1
      end
      table.insert(tmp, asdf)
      lim = mce(msq(x))
    end
    if(primepos == prime_num) then break end
    primepos = primepos + 1
    dv = primes[primepos]
  end
  if(x ~= 1) then
    local asdf = {}
    asdf.p, asdf.cnt = x, 1
    table.insert(tmp, asdf)
  end
  return tmp
end
local function bmul(x, y)
  local x1, y1 = x % 10000, y % 10000
  local x2, y2 = mfl(x / 10000) % 10000, mfl(y / 10000) % 10000
  local x3, y3 = mfl(x / 100000000), mfl(y / 100000000)
  local ret = (x1 * y1 + (x1 * y2 + x2 * y1) * 10000) % mod
  ret = (ret + (x1 * y3 + x2 * y2 + x3 * y1) * 10000 % mod * 10000 % mod) % mod
  ret = (ret + (x2 * y3 + x3 * y2) * 10000 % mod * 10000 % mod * 10000) % mod
  ret = (ret + x3 * y3 * 930000007) % mod
  return ret
end
local function bmul(x, y)
  local x1, y1 = x % 10000, y % 10000
  local x2, y2 = mfl(x / 10000) % 10000, mfl(y / 10000) % 10000
  local x3, y3 = mfl(x / 100000000), mfl(y / 100000000)
  local ret = (x1 * y1 + (x1 * y2 + x2 * y1) * 10000) % mod
  ret = (ret + (x1 * y3 + x2 * y2 + x3 * y1) * 10000 % mod * 10000 % mod) % mod
  ret = (ret + (x2 * y3 + x3 * y2) * 10000 % mod * 10000 % mod * 10000) % mod
  ret = (ret + x3 * y3 * 930000007) % mod
  return ret
end

local function modpow(src, pow)
  local res = 1
  while (0 < pow) do
    if (pow % 2 == 1) then
      res = bmul(res, src)
      pow = pow - 1
    end
    src = bmul(src, src)
    pow = mfl(pow / 2)
  end
  return res;
end

local function modinv(src)
  return modpow(src, mod - 2)
end

local function getConv(n, k)
  local ret = 1
  for i = 1, k do
    ret = bmul(ret, n + 1 - i)
    ret = bmul(ret, modinv(i))
  end
  return ret
end

local n, m = io.read("*n", "*n")
local primes = getprimes(mce(msq(m)))
local divisorparts = getdivisorparts(m, primes)
local pat = 1
for i = 1, #divisorparts do
  local c = divisorparts[i].cnt
  pat = bmul(pat, getConv(n + c - 1, c))
end
print(pat)


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

using namespace std;
using LL = long long;

constexpr int N = 1e5 + 5;

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	
	int n, k;
	cin >> n >> k;

	vector< int> dat(n + 1, 1);
	for (int i = 1; i <= k; i++) {
		int d;
		cin >> d;

		while (d--) {
			int x;
			cin >> x;
			dat[x] = 0;
		}
	}

	dat[0] = 0;
	cout << count(begin(dat), end(dat), 1) << endl;
}

Measured memory_bytes: 3660
#include<stdio.h>
#include<string.h>

#define STD 200
#define STATE_MAX 3000		/* max state = 6*0 + 6*1 + 6*2 + .... 6*30  < 3000*/
#define DIR 6
int objects[STD][STD], queue[STATE_MAX], visited[STD][STD], dir_x[DIR] = {1, 0, -1, -1, 0, 1}, dir_y[DIR] = {0, -1, -1, 0, 1, 1};
int top, bottom;

void put(int val)
{
  queue[bottom++] = val;
}

int get(void)
{
  return queue[top++];
}

int empty(void)
{
  return top == bottom;
}

int main(void)
{
  int turn, obj_n, x, y, nx, ny, getted_val, used_turn, i;
  while(1)
    {
      scanf("%d %d", &turn, &obj_n);
      if(turn == 0 && obj_n == 0)
	{
	  break;
	}
      top = bottom = used_turn = 0;
      memset(objects, 0, sizeof(objects));
      memset(visited, 0, sizeof(visited));
      while(obj_n--)
	{
	  scanf("%d %d", &x, &y);
	  objects[100 + x][100 + y] = 1;
	}
      scanf("%d %d", &x, &y);
      x += 100;
      y += 100;
      visited[x][y] = 1;
      put(x * 1000 + y);
      while(!empty())
	{
	  getted_val = get();
	  x = getted_val / 1000;
	  y = getted_val % 1000;
	  used_turn = visited[x][y];
	  for(i = 0; i < DIR; i++)
	    {
	      nx = x + dir_x[i];
	      ny = y + dir_y[i];
	      if(!objects[nx][ny] && !visited[nx][ny] && used_turn <= turn)
		{
		  visited[nx][ny] = used_turn + 1;
		  put(nx * 1000 + ny);
		}
	    }
	}
      printf("%d\n", top);
    }
  return 0;
}

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

const int MAXN = 100005;

int a[MAXN], n, K;

inline int gcd(int a, int b)
{ return b == 0 ? a : gcd(b, a%b); }

int main()
{
	ios::sync_with_stdio(false);
	cin >> n >> K;
	int g = -1;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		if (i == 1) g = a[i];
		else g = gcd(g, a[i]);
	}
	for (int i = 1; i <= n; i++)
		if (a[i] >= K && (a[i]-K)%g == 0) {
			cout << "POSSIBLE" << endl;
			return 0;
		}
	cout << "IMPOSSIBLE" << endl;
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
constexpr int INF = 1001001001;
using ll = long long;
using namespace std;

int bitCount(int bits){
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    int h, w, k;
    cin >> h >> w >> k;
    vector<vector<int>> s(h, vector<int>(w));
    for (int i = 0; i < h; i++) {
        string si;
        cin >> si;
        for (int j = 0; j < w; j++)
            s[i][j] = si[j] - '0';
    }

    int ans = INF;
    for (int bit = 0; bit < (1 << (h-1)); bit++) {
        //cout << "bit : " << bit << endl;
        int hcut = bitCount(bit), vcut = 0;
        vector<int> p(hcut+1, 0);
        int pre = 0;
        for (int pos = 0; pos < w; pos++) {
            //cout << "  pos : " << pos << endl;
            int id = 0;
            for (int i = 0; i < h; i++) {
                if (s[i][pos] == 1)
                    p[id]++;
                if (bit & (1 << i))
                    id++;
            }
            
/*             for (int j = 0; j < p.size(); j++)
                cout << p[j] << " ";
            cout << endl; */
            if (*(max_element(p.begin(), p.end())) > k) {
                if (pre == pos) {
                    vcut = INF;
                    break;
                }
                pre = pos;
                pos--;
                vcut++;
                for (int j = 0; j < p.size(); j++)
                    p[j] = 0;
            }
        }
        ans = min(ans, hcut + vcut);
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

MOD = 10**9 + 7
MAX_N = 10**6

fac = [1] + [0] * MAX_N
for i in range(1, MAX_N+1):
    fac[i] = fac[i-1] * (i) % MOD

fac_inv = [1] + [0] * MAX_N
fac_inv[MAX_N] = pow(fac[MAX_N], MOD-2, MOD)
for i in range(MAX_N, 1, -1):
    fac_inv[i-1] = fac_inv[i] * i % MOD

def mod_nCr(n, r):
    if n < r or n < 0 or r < 0:
        return 0
    tmp = fac_inv[n-r] * fac_inv[r] % MOD
    return tmp * fac[n] % MOD

n = int(input())
edge = [[] for _ in range(n)]
for _ in range(n-1):
    a, b = [int(item) - 1 for item in input().split()]
    edge[a].append(b)
    edge[b].append(a)

f_cnt = [0] * n
f_dp = [0] * n
def dfs1(p, v):
    val = 1
    cnt = 0
    for nv in edge[v]:
        if nv == p:
            continue
        ncnt, nval = dfs1(v, nv)
        val *= mod_nCr(cnt + ncnt, ncnt) 
        val *= nval
        val %= MOD
        cnt += ncnt
    f_cnt[v] = cnt + 1
    f_dp[v] = val
    return (cnt+1, val)

b_dp = [0] * n
def dfs2(p, v, pval):
    val = 1
    cnt = 0
    p_cnt = n - f_cnt[v]
    for nv in edge[v]:
        if nv == p:
            ncnt = p_cnt
            nval = pval
        else:
            ncnt, nval = f_cnt[nv], f_dp[nv]
        coef = mod_nCr(cnt + ncnt, ncnt) * nval % MOD
        val = val * coef % MOD
        b_dp[v] = val
        cnt += ncnt
    i = 0
    for nv in edge[v]:
        if nv == p:
            continue
        ncnt, nval = f_cnt[nv], f_dp[nv]
        coef = mod_nCr(n - 1, ncnt) * nval % MOD
        pp = val * pow(coef, MOD-2, MOD) % MOD
        i += 1
        dfs2(v, nv, pp)

dfs1(-1, 0)
dfs2(-1, 0, 1)
for item in b_dp:
    print(item)

Measured memory_bytes: 153872
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MOD 1000000007


int main (){
  int N,K;
  cin>>N>>K;
  vector<int>sunuke(N,0);
  rep(i,K){
    int d;
    cin>>d;
    rep(j,d){
      int a;
      cin>>a;
      sunuke[a-1]=1;
    }
  }
  int ans=0;
  rep(i,N){
    if(sunuke[i]==0) ans++;
  }
  cout<<ans;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int arr[100005];
int dp[100005];
int n,k;
int solve(int ind)
{
    if(ind==(n-1))
    return 0;
  if(dp[ind]!=-1)
    return dp[ind];
   int mini = 1e9+5;
    for(int i=ind+1;i<=min(n,ind+k);i++)
    mini = min(mini,abs(arr[ind]-arr[i])+solve(i));
    return dp[ind] = mini;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>k;
    for(int i=0;i<n;i++)
    cin>>arr[i];
    memset(dp,-1,sizeof(dp));
    cout<<solve(0);
}

Measured memory_bytes: 5760
# ANSHUL GAUTAM
# IIIT-D

from math import *
from copy import *					# ll = deepcopy(l)
from heapq import *					# heappush(hp,x)
from string import *				# alpha = ascii_lowercase
from random import *				# l.sort(key=lambda l1:l1[0]-l1[1]) => ex: sort on the basis difference
from bisect import *				# bisect_left(arr,x,start,end)  => start and end parameters are temporary
from sys import stdin				# bisect_left return leftmost position where x should be inserted to keep sorted
from sys import maxsize				# minn = -maxsize
from operator import *				# d = sorted(d.items(), key=itemgetter(1))
from itertools import *				# pre = [0] + list(accumulate(l))
from decimal import Decimal 		# a = Decimal(a)	# use this for math questions
from collections import Counter		# d = dict(Counter(l))
from collections import defaultdict # d = defaultdict(list)

'''
4 6
#..#..
.....#
....#.
#.#...

6 4
#..#
....
...#
#...
..#.
.#..

0 -> [[1,2][4,5]]
1 -> [[0,4]]
2 -> [[0,3],[5,5]]
3 -> [[1,1],[3,5]]

0 -> [[1,2]]
1 -> [[0,3]]
2 -> [[0,2]]
3 -> [[1,3]]
4 -> [[0,2],[3,3]]
5 -> [[0,0],[2,3]]

'''

def transpose(m):
	rez = [[m[j][i] for j in range(len(m))] for i in range(len(m[0]))] 
	return rez

def giveLightIntervals(L,h,w):
	l = [[] for i in range(h)]
	for i in range(h):
		s,e,c = '','',0
		for j in range(w):
			if(L[i][j] == '#'):
				if(c > 0):
					e = j
					l[i].append([s,e-1])
					c = 0
				s,e = '',''
			else:
				if(s == ''):
					s = j
				c += 1
		if(L[i][-1] == '.'):
			l[i].append([s,w-1])
	return l

def solve(L,h,w):
	T = transpose(L)
	l = giveLightIntervals(L,h,w)
	t = giveLightIntervals(T,w,h)

	H = [[0 for i in range(w)] for j in range(h)]
	W = [[0 for i in range(h)] for j in range(w)]

	for i in range(h):
		zz = 0
		for j in range(w):
			if(len(l[i]) > zz):
				s,e = l[i][zz]
				val = e - s + 1
				if(s <= j <= e):
					H[i][j] = val
				if(j == e):
					zz += 1
			else:
				break

	for i in range(w):
		zz = 0
		for j in range(h):
			if(len(t[i]) > zz):
				s,e = t[i][zz]
				val = e - s + 1
				if(s <= j <= e):
					W[i][j] = val
				if(j == e):
					zz += 1
			else:
				break

	ans = 0

	for i in range(h):
		for j in range(w):
			curr = H[i][j] + W[j][i] - 1
			ans = max(ans,curr)

	return ans


H,W = list(map(int, stdin.readline().rstrip().split()))
L = []
for m in range(H):
	L.append(list(input()))
ans = solve(L,H,W)
print(ans)



Measured memory_bytes: 498728
#include<bits/stdc++.h>
#define pi acos(-1)
#define ll long long
#define pii pair<ll,ll>
#define debug(a) cout<<a<<'\n'
#define maxn 100009 /// I wanna be the wind
#define MOD 1000000007
#define F first
#define S second
#define rep(i, a, b) for(ll i = a; i < (b); ++i)
#define per(i, b, a) for(ll i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (ll)(x).size()
using namespace std;
const ll INF = 1e17 + 9;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin>>n;
    cout<<((n+999)/1000)*1000-n<<"\n";
    return 0;  
}       

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n)-1; i >= 0; i--)
using namespace std;
typedef long long ll;
const int INF = 1e9;
int n;
long a[100010], b, c, t;

int main() {
  cin >> n;
  vector<ll> a(n + 1), b(n);
  rep(i, n + 1) cin >> a[i];
  rep(i, n) cin >> b[i];

  ll ans = 0;
  ll amari = 0;
  for (int i = 0; i < n; ++i) {
    int t = min(b[i], a[i]);
    ans += t;
    if (t <= b[i])
      amari = b[i] - t;
    else
      amari = 0;
    int t2 = min(amari, a[i + 1]);
    ans += t2;
    a[i + 1] -= t2;
  }
  cout << ans << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repd(i,a,b) for (int i = (a); i < (b); i++)
typedef long long ll;
int main(void)
{
	int n, a, q, b, m, e;
	vector<int> A;
	cin >> n;
	rep(i, n)
	{
		cin >> a;
		A.push_back(a);
	}
	
	cin >> q;
	rep(i, q)
	{
	    cin >> b >> m >> e;
	    rotate(A.begin() + b, A.begin() + m,  A.begin() + e);
	}
	
	rep(i, n)
	{
	    if (i)
	    {
	        cout << " ";
	    }
	    cout << A[i];
	}
	cout << endl;
}



Measured memory_bytes: 3176
#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 <iomanip>
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<long 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; }
#define INF 1LL<<60

int main() {
    int N, K;
    cin >> N >> K;
    vector<ll> H(N);
    REP(i, N) cin >> H[i];
    sort(ALL(H));
    reverse(ALL(H));

    ll ans = 0;
    REP(i, N) {
        if(i < K) continue;
        else ans += H[i];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
// solution is at the bottom

import kotlin.math.*

@JvmField val INPUT = System.`in`
@JvmField val OUTPUT = System.out

const val _BUFFER_SIZE = 1 shl 16
@JvmField val _buffer = ByteArray(_BUFFER_SIZE)
@JvmField var _bufferPt = 0
@JvmField var _bytesRead = 0

tailrec fun readChar(): Char {
    if(_bufferPt == _bytesRead) {
        _bufferPt = 0
        _bytesRead = INPUT.read(_buffer, 0, _BUFFER_SIZE)
    }
    return if(_bytesRead < 0) Char.MIN_VALUE
    else {
        val c = _buffer[_bufferPt++].toChar()
        if (c == '\r') readChar()
        else c
    }
}

fun readLine(): String? {
    var c = readChar()
    return if(c == Char.MIN_VALUE) null
    else buildString {
        while(true) {
            when(c) {
                '\n', Char.MIN_VALUE -> return@buildString
                else -> {
                    append(c)
                    c = readChar()
                }
            }
        }
    }
}
fun readLn() = readLine()!!

fun read() = buildString {
    var c = readChar()
    while(c <= ' ') {
        if(c == Char.MIN_VALUE) return@buildString
        c = readChar()
    }
    do {
        append(c)
        c = readChar()
    } while(c > ' ')
}
fun readInt() = read().toInt()
fun readDouble() = read().toDouble()
fun readLong() = read().toLong()
fun readStrings(n: Int) = List(n) { read() }
fun readLines(n: Int) = List(n) { readLn() }
fun readInts(n: Int) = List(n) { read().toInt() }
fun readIntArray(n: Int) = IntArray(n) { read().toInt() }
fun readDoubles(n: Int) = List(n) { read().toDouble() }
fun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }
fun readLongs(n: Int) = List(n) { read().toLong() }
fun readLongArray(n: Int) = LongArray(n) { read().toLong() }


fun main() {
    val (n, x, t) = readIntArray(3)
    var count = n / x
    if (n % x != 0) {
        count++
    }

    println(count * t)
}


Measured memory_bytes: 34072
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
using namespace std;
using P = pair<int,int>;
struct unionfindtree {
    vector<int> par,rank;
    unionfindtree(int n):par(n),rank(n,0) {
        rep(i,n) par[i] = i;
    }
    int root(int n) {
        if(par[n] == n) return n;
        else return par[n] = root(par[n]);
    }
    bool same(int i,int j) {
        return root(i) == root(j);
    }
    void unite(int i,int j) {
        int ri = root(i);
        int rj = root(j);
        if(ri == rj) return;

        if(rank[ri] < rank[rj]) {
            par[ri] = rj;
        } else {
            par[rj] = ri;
            if(rank[ri] == rank[rj]) rank[ri]++;
        }
    }
};

int main() {
    int n,k,l;
    cin >> n >> k >> l;
    unionfindtree road(n),rail(n);
    rep(i,k) {
        int p,q;
        cin >> p >> q;
        p--; q--;
        road.unite(p,q);
    }
    rep(i,l) {
        int r,s;
        cin >> r >> s;
        r--; s--;
        rail.unite(r,s);
    }
    map<P,vector<int>> m;
    rep(i,n) {
        P np = {road.root(i),rail.root(i)};
        if(m.count(np)) m[np].push_back(i);
        else m.insert({np,{i}});
    }
    vector<int> ans(n);
    for(auto a : m) {
        for(int i : a.second) {
            ans[i] = a.second.size();
        }
    }
    rep(i,n-1) cout << ans[i] << " ";
    cout << ans[n-1] << endl;
}

Measured memory_bytes: 24576
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <array>
#include <functional>
#include <algorithm>
#include <numeric>
#include <string>
#include <stack>

int main()
{
	//std::cout << std::fixed << std::setprecision(15);

	char c;
	std::cin >> c;

	std::cout << static_cast<char>(c + 1) << std::endl;

	return 0;
}

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

// Optimization

//#pragma GCC optimize("O3")
#define endl '\n'

// Shortcut

#define int long long
#define eb emplace_back
#define pb push_back
#define pob pop_back
#define mp make_pair
#define upb upper_bound
#define lwb lower_bound
#define fi first
#define se second
#define For(i, l, r) for (int i = l; i < r; i++)
#define ForE(i, l, r) for (int i = l; i <= r; i++)
#define Ford(i, r, l) for (int i = r; i > l; i--)
#define FordE(i, r, l) for (int i = r; i >= l; i--)
#define Fora(i, a) for (auto i : a)

// I/O & Debug

#define PrintV(a) Fora(iiii, a) cout << iiii << ' ';
#define PrintVl(a) Fora(iiii, a) cout << iiii << endl;
#define PrintA(a, l, r) for (int iiii = l; iiii <= r; iiii++) cout << a[iiii] << ' ';
#define PrintAl(a, l, r) for (int iiii = l; iiii <= r; iiii++) cout << a[iiii] << endl;
#define Ptest(x) return cout << x, 0;
#define gl(s) getline(cin, s);
#define setpre(x) fixed << setprecision(x)
/*
#define debug(args...){ string _sDEB = #args; replace(_sDEB.begin(), _sDEB.end(), ',', ' '); stringstream _ssDEB(_sDEB); istream_iterator<string> _itDEB(_ssDEB); DEB(_itDEB, args); }
void DEB(istream_iterator<string> it) {}
template<typename T, typename... Args>
void DEB(istream_iterator<string> it, T a, Args... args){
    cout << *it << " = " << a << endl;
    DEB(++it, args...);
}
*/

// Functions

//#define isvowel(a) (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define bend(a) a.begin(), a.end()
#define rbend(a) a.rbegin(), a.rend()
#define mset(a) memset(a, 0, sizeof(a))
#define mset1(a) memset(a, 1, sizeof(a))
#define msetn1(a) memset(a, -1, sizeof(a))
#define msetinf(a) memset(a, 0x3f, sizeof(a))
#define gcd __gcd
#define __builtin_popcount __builtin_popcountll
//mt19937 rando(chrono::steady_clock::now().time_since_epoch().count());

// Data Structure

#define pque priority_queue
#define mts multiset
#define y0 _y0_
#define y1 _y1_
#define div divi
typedef long long ll;
typedef long double ld;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <ld> vld;
typedef vector <string> vs;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <vi > vvi;
typedef vector <vll > vvll;
typedef vector <pii > vpii;
typedef vector <pll > vpll;

const int N = 3e5 + 5, M = 3e5 + 5, mod = 1e9 + 7, mod1 = 998244353, mod2 = 1e9 + 9, inf = 1e9 + 7;
const ll infll = 1e18 + 7;

int q = 1, n, m, k;
int x, y, z;
int ans, cnt, tmp, idx, sum, mn = inf, mx = 0;
int a[N], b[N];
string s, t;

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
//cin >> q;
while (q--){
    char c;
    cin >> c;
    c++;
    cout << (char)c << endl;
}
}

/*
==================================+
INPUT:                            |
------------------------------    |

------------------------------    |
==================================+
OUTPUT:                           |
------------------------------    |

------------------------------    |
==================================+
*/

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define io ios_base::sync_with_stdio(false); cin.tie(NULL);

#define nl "\n"
#define fr first
#define sc second
#define MP make_pair
#define pb push_back
#define VI vector<int>
#define VII vector<ll>
#define MAP map <int,int>
#define PI pair < int , int >
#define sz(v) (int)(v).size()
#define all(v) v.begin(),v.end()
#define mem(a,val) memset(a,val,sizeof(a))
#define precise(n) fixed(cout);cout<<setprecision(n)

const int N = (int)4e7;
const int MOD = (int)1e9 + 7;
const double pi = acos(-1);
const double eps = 1e-9;

typedef long long ll;
typedef double db;

using namespace std;

int main()
{
    io;
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);

    ///Let the showdown begin

    int x,y,h,m;
    cin >> x >> y >> h >> m;

    db ah1,ah2,am,temp1,temp2,ans;

    ah1 = pi*(1.0/6)*h;
    ah2 = pi*(1.0/360)*m;
    am =  pi*(1.0/30)*m;
    temp1= x*x;
    temp2= y*y;

    temp1+=temp2;
    temp1-=2*x*y*cos(ah1+ah2-am);

    precise(20);
    cout << sqrt(temp1) << nl;

    ///Happily DONE

    return 0;
}


Measured memory_bytes: 4116
//48
#include<iostream>

using namespace std;

int main(){
  for(int n,s;cin>>n>>s,n|s;){
    int r[20000];
    for(int i=0;i<n;i++){
      cin>>r[i];
    }
    int np=0;
    for(int i=0;i<n;i++){
      for(int j=i+1;j<n;j++){
	np+=r[i]+r[j]>s;
      }
    }
    cout<<np<<endl;
  }
  return 0;
}

Measured memory_bytes: 1204
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    int n, q;
    cin >> n >> q;
    int a[n+1];
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }

    long long psr[n+2], ps2[n+1];
    ps2[0] = 0, ps2[1] = a[1];
    for (int i = 2; i <= n; i++) {
        ps2[i] = ps2[i-2] + a[i];
    }
    psr[n+1] = 0;
    for (int i = n; i > 0; i--) {
        psr[i] = psr[i+1] + a[i];
    }

    for (int i = 0; i < q; i++) {
        int x;
        cin >> x;
        int l = 1, r = n + 1;
        while (r - l > 1) {
            int mid = (l + r) / 2;
            int l2 = 2 * mid - 1 - n;
            int r2 = mid - 1;
            if (l2 <= 1) {
                l = mid;
            } else if (a[l2-1] > x) {
                r = mid;
            } else if (a[r2] < x) {
                l = mid;
            } else if (x - a[l2-1] <= a[r2] - x) {
                r = mid;
            } else {
                l = mid;
            }
        }
        
        cout << psr[l] + (l * 2 - n - 2 > 0 ? ps2[l*2-n-2] : 0) << endl;
    }

    return 0;
}


Measured memory_bytes: 3712
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;


int a[5];

int main(){

	rep(i, 5) {
		cin >> a[i];
		if (a[i] < 40)a[i] = 40;
	}

	cout << (a[0] + a[1] + a[2] + a[3] + a[4]) / 5 << endl;

	return 0;
}


Measured memory_bytes: 3112
// #include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <set>
using namespace std;
#define rep(i, n) for(int i=0;i<n;i++)
#define irep(i, n) for(int i=n-1;i>=0;i--)
#define lrep(i, n) for(long long i=0;i<n;i++)
typedef long long ll;
typedef vector<long long> llv;
typedef vector<vector<long long> > llvv;

int main(){
    string s;
    cin >> s;
    ll ones = 0;
    ll zeros = 0;
    ll n = s.size();
    rep(i, n){
        if(s[i] == '0') zeros++;
        else ones++;
    }
    cout << 2 * min(ones, zeros) << endl;
}

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

pair<int, int> pd[10000];

void solve(int n, ll m) {
    ll ans = 0;
    for(int i = 0; i < n; i++) {
        cin >> pd[i].second >> pd[i].first;
        ans += pd[i].first * pd[i].second;
    }
    sort(pd, pd + n,
         [](auto const &l, auto const &r) { return l.first > r.first; });

    for(int i = 0; i < n; i++) {
        ll x = min(ll(pd[i].second), m);
        ans -= pd[i].first * x;
        m -= x;
        if(x == 0)
            break;
    }
    cout << ans << endl;
}

int main() {
    while(true) {
        int n;
        ll m;
        cin >> n >> m;
        if(n == 0)
            break;
        solve(n, m);
    }
}


Measured memory_bytes: 3168
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int main(){
	int n;
	while(1){
		cin >> n;
		if(n==0) break;
		int c = 0;
		for(int i=1;;i++){
			int a = 1;
			for(int j=0;j<i;j++) a*=5;
			int b = n/a;
			if(b==0) break;
			c += b;
		}
		cout << c << endl;
	}
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;
ll gcd(ll a, ll b);
ll power(ll n, ll k);
ll inv(ll n);
ll genfact(ll n, ll k);
ll fact(ll n);
ll nck(ll n, ll k);


ll gcd(ll a, ll b){
  if (a < b)
    return gcd(b, a);
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}

ll power(ll n, ll k){
  ll res = 1;
  while(k > 0){
    if (k & 1) 
      res = res * n % MOD;
    n = n * n % MOD;
    k >>= 1;
  }
  return res;
}

ll genfact(ll n, ll k){

  ll res = 1;
  while (k >= 0){
    res = (res * (n - k)) % MOD;
    k--;
  }

  return res;
}

ll inv(ll n){
  return power(n, MOD - 2);
}

ll fact(ll n){
  return genfact(n, n - 1);
}

ll nck(ll n, ll k){
  if (k == 0)
    return 1;
  if (n <= 0)
    return 0;

  return ((genfact(n, k) % MOD) * inv(fact(k))) % MOD;
}

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


  ll b1, b3;
  vector<int> a(n + 1, -1);
  for (int i = 0; i < n + 1; i++){
    ll c;
    cin >> c;
    if (a[c] == -1)
      a[c] = i;
    else {
      b1 = a[c];
      b3 = n - i;
    }
  }

  ll d1, d2 = 0, d3, d4;
  for (int i = 1; i <= n + 1; i++){
    if (i == 1){
      d1 = n - 1;
      d2 = 0;
      d3 = 1;
      d4 = 1;
    }
    else {
      if (i == 2){
        d2 = 1;
      }
      else {
        d2 = (d2 * (n - i + 2) % MOD) * inv(i - 2) % MOD;
      }
      d1 = (d1 * (n - i) % MOD) * inv(i) % MOD;
      d3 = (d3 * (n - i + 1) % MOD) * inv(i - 1) % MOD;
      if (b1 + b3 >= i - 1){
        d4 = (d4 * (b1 + b3 - i + 2) % MOD) * inv(i - 1) % MOD;
      }
      else 
        d4 = 0;
    }


    cout << (d1 + d2 + 2*d3 - d4 + MOD) % MOD << endl;
  }



  return 0;
}


Measured memory_bytes: 1664
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()
s=list(ss())
cnt=0
for i in range(n-2):

    if "".join(s[i:i+3])=="ABC":
        
        cnt+=1

print(cnt)

Measured memory_bytes: 63340
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int X = sc.nextInt();
		int Y = sc.nextInt();
		int total = 0;
		if(N <= K) total = N * X;
		else if(N > K) total = K * X + (N - K) * Y;
		System.out.println(total);
	}
}


Measured memory_bytes: 25044
#include<cstdio>
#include<algorithm>
int main(){
    int a,b;
    while(true){
        scanf("%d%d", &a, &b);
        if(a==0&&b==0)return 0;
        printf("%d %d\n", std::min(a,b), std::max(a,b));
    }
}


Measured memory_bytes: 2588
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <map>
#include <string>
#include <utility>
#include <algorithm>
#include <iostream>
#include <functional>
#include <cmath>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999

using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

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

  if(N%1110<10 || (N%1000)%111==0){
    printf("Yes\n");
  }else{
    printf("No\n");
  }

	return 0;
}


Measured memory_bytes: 256
let () =
  let n = read_int () in
  let tbl = Hashtbl.create 1000000 in
  for i=1 to n do
    begin match Scanf.scanf "%s %s\n" (fun a b -> a,b) with
        "insert",word -> Hashtbl.add tbl word 0
      | _,word ->
        Printf.printf "%s\n"
          (if Hashtbl.mem tbl word then "yes" else "no")
    end
  done

Measured memory_bytes: 44252
#if loc||local
#define _GLIBCXX_DEBUG
#endif

#include<bits/stdc++.h>
using namespace std;

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = int_fast64_t;
using pll = pair<ll,ll>;
constexpr ll INF = 1LL<<60;
constexpr ll MOD = 1e9+7;
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
#if loc||local
template<class T>void dump(T&& t){cerr<<t<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
void dump(){}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T,class U> ostream &operator<<(ostream& os,pair<T,U>const& p){os<<p.first<<","<<p.second;return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}

std::vector<std::pair<ll,ll>> prime_factorization(ll n){
  std::vector<std::pair<ll,ll>> factor;
  for(ll p=2;p*p<=n;++p){
    if(n%p!=0)continue;
    ll num=0;
    while(n%p==0){
      num++;
      n/=p;
    }
    factor.emplace_back(p,num);
    if(n==1)return factor;
  }
  if(n!=1)factor.emplace_back(n,1);
  return factor;
}

signed main(){

  int n;
  cin>>n;
  vector<ll> a(n);
  cin>>a;

  ll sum_gcd = 0;
  rep(i,n)sum_gcd = gcd(sum_gcd,a[i]);

  map<ll,ll> mp;
  for(auto const& ai:a)
    for(auto const&[k,v]:prime_factorization(ai))
      mp[k]++;

  bool f = true;
  for(auto const&[k,v]:mp)if(v>=2)f=false;

  if(f){
    cout<<"pairwise coprime"<<endl;
  }
  else if(sum_gcd==1){
    cout<<"setwise coprime"<<endl;
  }
  else{
    cout<<"not coprime"<<endl;
  }


}


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

int main(void)
{
    int n,m;

    cin >> n >> m;

    vector<int> vote;

    int sum = 0;
    int value = 0;
    int i,counter = 0;

    for(i = 0; i < n; i++)
    {
        cin >> value;
        vote.push_back(value);
        sum = sum + value;
    }

    sort(vote.begin(), vote.end(), greater<int>());

    double ans1 = 1.0/(4 * (double)m);
    double ans2;

    for(i = 0; i < m; i++)
    {
        ans2 = (double)vote[i]/(double)sum;
        if (ans2 >= ans1)
            counter++;
    }

    if (counter == m)
        cout << "Yes\n";
    else
        cout << "No\n";

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int a(int n)
{
	if(n == 0)
	{
		return 1;
	}
	else
	{
		return 2 * a(n - 1);
	}
}

int main()
{
	int n,m;
	cin >> n >> m;
	
	int ans = 0;
	ans = ((n-m)*100 + m*1900) * a(m);
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
A = input()
count = 0
if A[0]=="A":
    if A[2:-1].count("C")==1:
        A =A.replace("A","a",1)        
        SUM = A[0:2]+A[2:-1].replace("C","c") + A[-1]
        if SUM.islower():
            count = 1
            
print("AC") if count == 1 else print("WA")

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

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

	if(a > b){
		temp = a;
		a = b;
		b = temp;
	}

	if(a > c){
		temp = a;
		a = c;
		c = temp;
	}

	if(b > c){
		temp = b;
		b = c;
		c = temp;
	}

	cout << a << " " << b << " " << c << endl;

	return 0;
}

Measured memory_bytes: 3116
import java.util.*;
public class Main{
    public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      char[] s = sc.next().toCharArray();
      long MOD = 1000000007;
      long[][] dp = new long[s.length+1][13];
      dp[0][0]=1;
      for(int i=1;i<=s.length;i++){
        for(int j=0;j<10;j++){
          if(s[i-1]=='?'||s[i-1]-'0'==j){
            for(int k=0;k<13;k++){
              dp[i][(k*10+j)%13]+=dp[i-1][k];
              dp[i][(k*10+j)%13]%=MOD;
            }
          }
        }
      }
      System.out.println(dp[s.length][5]);
    }
}

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

int main()
{
    int arr[4];
    for(int i=0; i<3; i++)
    {
        cin>>arr[i];
    }
    sort(arr,arr+3);
    if(arr[0]==arr[1])
        cout<<arr[2]<<endl;
    else if(arr[0]==arr[2])
        cout<<arr[1]<<endl;
    else if(arr[1]==arr[2])
        cout<<arr[0]<<endl;



    return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
#define MAX 10000
#define NIL -1

typedef struct {
  int p;
  int l;
  int r;
} Node;

Node T[MAX];

void preParse(int u){
  if(u==NIL) return;
  printf(" %d",u);
  preParse(T[u].l);
  preParse(T[u].r);
}

void inParse(int u){
  if(u==NIL) return;
  inParse(T[u].l);
  printf(" %d",u);
  inParse(T[u].r);
}

void postParse(int u){
  if(u==NIL) return;
  postParse(T[u].l);
  postParse(T[u].r);
  printf(" %d",u);
  return;
}
	    
int main(){
  int i, j, k;
  int n;
  int id,l,r;
  int root = 0;
  scanf("%d", &n);
  for(i=0; i<n; i++) T[i].p=NIL;
  
  for(i=0; i<n; i++){
    scanf("%d%d%d", &id,&l,&r);
      T[id].l = l;
      T[id].r=r;
      if(l!=NIL) T[l].p = id;
      if(r!=NIL) T[r].p = id;
  }
  for(i=0; i<n; i++){
    if(T[i].p ==NIL) root = i;
  }
  printf("Preorder\n");
  preParse(root);
  printf("\n");
  printf("Inorder\n");
  inParse(root);
  printf("\n");
  printf("Postorder\n");
  postParse(root);
  printf("\n");
  return 0;
}
 


Measured memory_bytes: 2056