akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))

typedef long long LL;

#define INF 1000000000

int main(){
  int n,m;
  cin >> n >> m;
  vector<vector<int>> e(n,vector<int>(n,INF));
  vector<vector<int>> d(n,vector<int>(n,INF));
  int a,b,c;
  for(int i=0;i<n;i++) e[i][i]=d[i][i]=0;
  for(int i=0;i<m;i++){
    cin >> a >> b >> c;
    a--,b--;
    e[a][b]=e[b][a]=d[a][b]=d[b][a]=c;
  }
  vector<vector<int>> next(n,vector<int>(n));
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      next[i][j]=j;
    }
  }
  for(int k=0;k<n;k++){
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
        if(d[i][k]+d[k][j]<d[i][j]){
          d[i][j]=d[i][k]+d[k][j];
          next[i][j]=next[i][k];
        }
      }
    }
  }
  vector<vector<bool>> used(n,vector<bool>(n,false));
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      for(int s=i;s!=j;s=next[s][j]){
        used[s][next[s][j]]=true;
      }
    }
  }
  int ans=0;
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      if(e[i][j]!=INF&&!used[i][j]) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <array>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, a, n) for (int i = a; i < (n); i++)
#define all(in) in.begin(), in.end()
const int INF = 1e9;
const int MOD = 1e9 + 7;
int main() {
    long long ans = 0;
    int K, A, B;
    cin >> K >> A >> B;
    if (B - A <= 2) {
        ans = K + 1;
    } else {
        long long biscits = 1;
        loop(i, 1, K + 1) {
            if (biscits < A) {
                biscits++;
            } else if (i <= K - 1) {
                biscits += (B - A);
                i++;
            } else {
                biscits++;
            }
        }
        ans = biscits;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <bits/stdc++.h>
#include<stdio.h>
#include <stdlib.h>
#include<string>
#include<queue>
#include<algorithm>
#include<math.h>

#define MAX 1000000007
using namespace std;

int main(){
	long long int N,M,Nbik=1,Mbik=1;
	cin>>N>>M;
	if(labs(N-M)>1){
		cout<<"0"<<endl;
	}else{
		for(int i=N;i>=1;i--){
			Nbik*=i;
			Nbik=Nbik%MAX;
		}
		for(int i=M;i>=1;i--){
			Mbik*=i;
			Mbik=Mbik%MAX;
		}
		if(N==M){
			Nbik=(Nbik*Mbik*2)%MAX;
		}else{
			Nbik=(Nbik*Mbik)%MAX;
		}
		
		cout<<Nbik<<endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;


int main(int argc, char** argv) {
    int N, M, C;
    cin >> N >> M >> C;
    int cnt{0};
    std::vector<int> Bs(20);
    for (int m = 0; m < M; ++m) {
        cin >> Bs[m];
    }

    for (int n = 0; n < N; ++n) {
        int a, sum{0};
        for (int m = 0; m < M; ++m) {
            cin >> a;
            sum += a * Bs[m];
        }
        sum += C;
        if (sum > 0) ++cnt;
    }
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
#include <deque>
#include <iostream>

int main() {
    int q;
    std::cin >> q;

    std::deque<int> deq{};
    for (int i = 0; i < q; ++i) {
        int kind;
        std::cin >> kind;

        int is_back;
        switch (kind) {
            case 0:
                int value;
                std::cin >> is_back >> value;

                if (is_back == 1)
                    deq.push_back(value);
                else
                    deq.push_front(value);
                break;
            case 1:
                int idx;
                std::cin >> idx;

                std::cout << deq.at(idx) << std::endl;
                break;
            case 2:
                std::cin >> is_back;

                if (is_back == 1)
                    deq.pop_back();
                else if (is_back == 0)
                    deq.pop_front();
                else
                    std::cerr << "strange is_back; nor 1, 0" << std::endl;
                break;
            default:;
                std::cerr << "strange kind: " << kind << std::endl;
        }
    }
}


Measured memory_bytes: 4648
#include<iostream>
#include<algorithm>
#include<stdio.h>
using namespace std;
int table[10001];
int a;

int solve(int b){
	int serch=table[b];
	int left=b;
	int right=b+1;
	int ret=a;
	while(1){
		serch=table[left];
		int count=0;
		while(table[left]==serch&&left>=0){
			left--;
			count++;
		}
		while(table[right]==serch&&right<a){
			right++;
			count++;
		}
		if(count<4)break;
		else ret-=count;
	
	}
		return ret;
}
int main(){
	while(scanf("%d",&a),a){
		int ret=9999999;
		for(int i=0;i<a;i++)scanf("%d",&table[i]);
		for(int i=0;i<a;i++){
			int temp=table[i];
			table[i]=1;
			ret=min(solve(i),ret);
			table[i]=2;
			ret=min(solve(i),ret);
			table[i]=3;
			ret=min(solve(i),ret);
			table[i]=temp;
		}
		printf("%d\n",ret);
	}
	return 0;
	}

	 

Measured memory_bytes: 1224
#include <vector>
#include <map>
#include <set>
#include <sstream>
#include <iostream>
#include <limits>
#include <algorithm>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <cmath>


using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<pair<int, int>> vii;
typedef stringstream ss;
const int mii = numeric_limits<int>::min();
const int mai = numeric_limits<int>::max();
const ll mil = numeric_limits<long long>::min();
const ll mal = numeric_limits<long long>::max();

#define REP(i, a, b) for(long long i=a; i<=b; ++i)
#define RREP(i, a, b) for(long long i=a; i>=b; --i)
#define PB(x) push_back(x)
#define MP(x, y) make_pair(x, y)

string flushChars(vector<char> & pushFrontChars, vector<char> & pushBackChars, const string & s, bool prevQueryReverse) {
    ss str;

    vector<char> & back = prevQueryReverse ? pushFrontChars : pushBackChars;
    vector<char> & front = prevQueryReverse ? pushBackChars : pushFrontChars;


    if(!front.empty() && !back.empty())
        str  << string(front.rbegin(), front.rend()) << (prevQueryReverse ? string(s.rbegin(), s.rend()) : s) << string(back.begin(), back.end());
    else if(!front.empty())
        str  << string(front.rbegin(), front.rend()) << (prevQueryReverse ? string(s.rbegin(), s.rend()) : s);
    else if(!back.empty())
        str  << (prevQueryReverse ? string(s.rbegin(), s.rend()) : s) << string(back.begin(), back.end());

    pushFrontChars.clear();
    pushBackChars.clear();

    return str.str();
}

int main(int argc, char **argv) {
    string s;
    int q;
    cin >> s;
    cin >> q;
    string qu;
    bool prevQueryReverse = false;
    vector<char> pushFrontChars;
    vector<char> pushBackChars;

    REP(i, 1, q) {
        int ti;
        cin >> ti;
        if(ti == 1) {
            prevQueryReverse = !prevQueryReverse;
        }
        else {
            int fi;
            cin >> fi;
            char ci;
            cin >> ci;
            if(fi == 1) {
                if(!prevQueryReverse)
                    pushFrontChars.PB(ci);
                else
                    pushBackChars.PB(ci);
            }
            else {
                if(!prevQueryReverse)
                    pushBackChars.PB(ci);
                else
                    pushFrontChars.PB(ci);
            }
        }
    }

    if(prevQueryReverse || !pushFrontChars.empty() || !pushBackChars.empty())
        s = flushChars(pushFrontChars, pushBackChars, s, prevQueryReverse);

    cout << s << endl;
    return 0;
}

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

int main() {
  int h,w,k;
  cin >> h >> w >> k;
  vector<vector<char>> map(h,vector<char>(w));
  for (int i = 0;i < h;i++){
    for (int j = 0;j < w;j++){
      cin >> map[i][j];
    }
  }
  int ans = 0;
  
  for (int n = 0; n < (1 << h); n++){
    for (int m = 0; m < (1 << w); m++){
      vector<vector<char>> copy(h,vector<char>(w));
      copy = map;
      bitset<6> s(n);
      bitset<6> t(m);
      for (int i = 0;i < h;i++){
        if (s.test(i)){
          for (int j = 0;j < w;j++){
          copy[i][j] = 'r';
          }
        }
      }
      for (int j = 0;j < w;j++){
        if (t.test(j)){
          for (int i = 0;i < h;i++){
          copy[i][j] = 'r';
          }
        }
      }
      int c = 0;
      for (int i = 0;i < h;i++){
        for (int j = 0;j < w;j++){
          if (copy[i][j] == '#'){
          c++;
          }
        }
      }
      if (c == k){
      ans++;
      }
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

int main(){
  int n; cin >> n;
  vector<int> a(n+1), b(n+1), c(n+1), da(n+1, 0), db(n+1, 0), dc(n+1, 0);
  FOR(i, 1, n+1) cin >> a[i] >> b[i] >> c[i];

  FOR(i, 1, n+1){
    da[i] = max(db[i-1], dc[i-1]) + a[i];
    db[i] = max(da[i-1], dc[i-1]) + b[i];
    dc[i] = max(da[i-1], db[i-1]) + c[i];
  }

  cout << max(da[n], max(db[n], dc[n])) << endl;

  return 0;
}


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

int main(){
	int n;
	cin >> n;
	vector<int> a(n),b(n),c(n-1);
	for(int i=0;i<n;i++)
	{
		cin >> a[i];
		a[i]--;
	}
	for(int i=0;i<n;i++)
		cin >> b[i];
	for(int i=0;i<n-1;i++)
		cin >> c[i];
	
	int ans = 0;
	for(int i=0;i<n;i++) {
		ans += b[a[i]];
		if(a[i]+1 == a[i+1]) {
			ans += c[a[i]];
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
from collections import Counter

def prime_factorization(n):
    A = []
    while n % 2 == 0:
        n //= 2
        A.append(2)
    i = 3
    while i * i <= n:
        if n % i == 0:
            n //= i
            A.append(i)
        else:
            i += 2
    if n != 1:
        A.append(n)
    return A


n = int(input())

A = list(Counter(prime_factorization(n)).values())

ans = 0
e = 1
while True:
    cnt = 0
    for i in range(len(A)):
        if A[i] >= e:
            A[i] -= e
            cnt += 1
    if cnt == 0:
        break
    ans += cnt
    e += 1

print(ans)


Measured memory_bytes: 9352
#include<stdio.h>
int main(){
  int n,i,j;
  int Y,M,D,day;
  int a=196471;

  scanf("%d",&n);
  for(i=0,day=0;i<n;i++,day=0){
    scanf("%d %d %d",&Y,&M,&D);
    for(j=1;j<Y;j++){
      if(j%3==0){
	day+=200;
      }else{
	day+=195;
      }
    }
    for(j=1;j<M;j++){
      if(Y%3==0||j%2==1){
	day+=20;
      }else{
	day+=19;
      }
    }
    day+=D;
    printf("%d\n",a-day);
  }
  return 0;
}

Measured memory_bytes: 596
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

const int FAILED = -1;

vector<int> w[100005];
bool visited[100005];
int dist[3][100005];

void dfs(int start, int type)
{
  visited[start] = true;
  for (int x: w[start]) if (!visited[x]) {
    dist[type][x] = dist[type][start] + 1;
    dfs(x, type);
  }
  visited[start] = false;
}

int main()
{
  int n, u, v; cin >> n >> u >> v;
  for (int i = 0; i < n-1; ++i) {
    int a, b; cin >> a >> b;
    w[a].push_back(b); w[b].push_back(a);
  }
  
  dist[0][u] = dist[1][v] = 0;
  dfs(u, 0); dfs(v, 1);
  
  int dist_uv = dist[0][v], new_u;
  int dist_unu = (dist_uv-1)/2;
  for (int i = 1; i <= n; ++i) {
    if (dist[0][i] == dist_unu and dist[1][i] == dist_uv-dist_unu)
      new_u = i;
    if (dist[0][i] == dist_unu+1 and dist[1][i] == dist_uv-dist_unu-1)
      visited[i] = true;
  }
  
  dfs(new_u, 2);
  
  int mx = 0;
  for (int i = 1; i <= n; ++i) mx = max(mx, dist[2][i]);
  
  int ans = dist_unu + mx;
  if (dist_uv % 2 == 0) ++ans;
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 12160
a,b=[int(j) for j in input().split()]
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors
la=set(make_divisors(a))
lb=set(make_divisors(b))
l=list(la&lb)
def gcd(x,y):
    if y==0:
        return x
    else:
        return gcd(y,x%y)

ans=0
ll=set([1])
l.sort()
for i in l:
    if i==1:
        continue
    if set(make_divisors(i))&ll=={1}:
        ll.add(i)
print(len(ll))

Measured memory_bytes: 43352
#include <iostream>
#include <set>
#include <map>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <climits>
#include <fstream>
#include <cassert>
#include <unordered_map>
using namespace std;
#pragma warning(disable : 4996)
typedef long long ll;
typedef long double ld;
const ll MAXN = 1e6;
ll tAdd[4 * MAXN];
ll a[4 * MAXN];
ll t[4 * MAXN];


void push(ll v, ll tl, ll tr) {
	if (tAdd[v] != 0) {
		t[v] += (tr - tl + 1) * tAdd[v];
		tAdd[2 * v + 1] += tAdd[v];
		tAdd[2 * v + 2] += tAdd[v];
	}
	tAdd[v] = 0;
}


void build(ll v, ll tl, ll tr, ll a[]) {
	if (tl > tr) {
		return;
	}
	if (tl == tr) {
		t[v] = a[tl];
		return;
	}
	ll tm = (tl + tr) / 2;
	build(2 * v + 1, tl, tm, a);
	build(2 * v + 2, tm + 1, tr, a);
	t[v] = t[2 * v + 1] + t[2 * v + 2];
	return;
}

ll get(ll v, ll tl, ll tr, ll l, ll r) {
	push(v, tl, tr);
	if (l > tr || r < tl) {
		return 0;
	}
	if (l <= tl && r >= tr) {
		return t[v];
	}
	ll tm = (tl + tr) / 2;
	return get(2 * v + 1, tl, tm, l, r) + get(2 * v + 2, tm + 1, tr, l, r);
}

void update(ll v, ll tl, ll tr, ll l, ll r, ll add) {
	push(v, tl, tr);
	if (l > tr || r < tl) {
		return;
	}
	if (l <= tl && r >= tr) {
		tAdd[v] += add;
		push(v, tl, tr);
		return;
	}
	ll tm = (tl + tr) / 2;
	update(2 * v + 1, tl, tm, l, r, add);
	update(2 * v + 2, tm + 1, tr, l, r, add);
}


int main() {
#ifdef _DEBUG
	freopen("input1.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	ll n, d, at;
	cin >> n >> d >> at;
	vector<ll> coord(n);
	vector<pair<ll, ll>> kek(n);
	for (int i = 0; i < n; i++) {
		cin >> kek[i].first >> kek[i].second;
	}
	sort(kek.begin(), kek.end());
	for (ll i = 0; i < n; i++) {
		coord[i] = kek[i].first;
		a[i] = kek[i].second;
	}
	build(0, 0, n - 1, a);
	ll ans = 0;
	for (ll i = 0; i < n; i++) {
		ll cur = get(0, 0, n - 1, i, i);
		//cout << cur << "\n";
		if (cur <= 0)continue;
		ll cor = coord[i] + 2 * d;
		auto it = upper_bound(coord.begin(), coord.end(), cor);
		it--;
		ll r_bord = (it - coord.begin());
		ll now_at = (cur - 1) / at + 1;
		ans += now_at;
		update(0, 0, n - 1, i, r_bord, -now_at * at);
	}
	cout << ans;
}


Measured memory_bytes: 25472
#include<bits/stdc++.h>
#define ll long long 
#define ld long double
#define X first
#define Y second
#define pb push_back
#define max_el(x) max_element(x.begin(),x.end())-x.begin()
#define min_el(x) min_element(x.begin(),x.end())-x.begin()
#define mp make_pair
#define endl '\n'
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
// DONT USE MEMSET, USE VECTORS

void solve(){
	ll x;
	cin>>x;
	ll ans = 0;
	ll l = 0;
	ll h = 1e8;
	while(l<=h){
		ll m = l + (h-l)/2;
		if((m*(m+1))/2 >= x){
			ans = m;
			h = m-1;
		}
		else{
			l = m+1;
		}
	}
	cout<<ans<<endl;
}

int main(){
	fastread;
	int t = 1;
	// cin>>t;
	for(int i=1;i<=t;i++){
		// cout<<"Case #"<<i<<": ";
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
from collections import deque
S=deque(list(input()))
sign=1

for i in range(int(input())):
  ls=input().split()
  if ls[0]=='1':
    sign*=-1
  else:
    if sign*int(ls[1])==1 or sign*int(ls[1])==-2:
      S.appendleft(ls[2])
    else:
      S.append(ls[2])
if sign==-1:
  S.reverse()
print(*S,sep='')



Measured memory_bytes: 12256
from fractions import gcd
N, M = list(map(int, input().split()))
A = list(map(lambda x: int(x),input().split()))

cnt = [0 for _ in range(N)]
for i in range(N):
  a = A[i]
  while a%2 == 0:
    a = a // 2
    cnt[i] += 1

if max(cnt) > min(cnt):
  print(0)
  exit(0)
C = max(cnt)

A = list(map(lambda x: x // pow(2,C), A))
def gcd(a,b):
  if a<b:
    a,b = b,a
  while a%b > 0:
    a,b = b,a%b
  return b

def lcm(a,b):
  return a*b//gcd(a,b)

x = A[0]
for a in A[1:]:
  x = lcm(x,a)
x = x * pow(2,C-1)

print((M // x + 1) // 2)

Measured memory_bytes: 21860
#include <stdio.h>
#include <iostream>

using namespace std;

void suffle (int a, int b, int t[]) {
	int kari[50];
	int kari2[50];
	for (int i = 0; i < a-1; i++) {
		kari[i] = t[i];
	}
	for (int i = 0; i < b; i++) {
		kari2[i] = t[a-1+i];
	}

	for (int i = 0; i < b; i++) {
		t[i] = kari2[i];
	}

	for (int i = 0; i < a-1; i++) {
		t[b+i] = kari[i];
	}
	return;
}

int main() {
	int yama[50];
	int k,r;
	int a,b;

	while (cin >> k >> r) {
		if (k == 0 && r == 0) {
			break;
		}

		for (int i = 0; i < k; i++) {
			yama[i] = k-i;
		}

		for (int i = 0; i < r; i++) {
			cin >> a >> b;
			suffle(a,b,yama);
		}
		cout << yama[0] << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <map>
#include <queue>
#include <cmath>
#include <vector>
using namespace std;
const int num = 16, ud[] = { -1, 0, 1, 0 }, lr[] = { 0, -1, 0, 1 }, nd = 4;
const char wa[] = { 'u', 'l', 'd', 'r' };
int md[num][num];
vector<int> way;
int lm;
struct puzzle {
	int sp, p[num], mdp;
	string way;
	bool operator < (const puzzle &pu) const {
		for (int i = 0; i < num; i++) {
			if (p[i] == pu.p[i]) continue;
			return p[i] < pu.p[i];
		}
		return false;
	}
};
puzzle pu;
/*bool dfs(int de, int prev, puzzle pu) {
	if (pu.mdp + de> lm) return false;
	//cout << "prev" << prev << "pu.sp" << pu.sp << "mdp" <<  pu.mdp << endl;
	if (!pu.mdp) {return true; }
	int sx = pu.sp / nd;
	int sy = pu.sp % nd;
	int tx, ty, ns;
	//puzzle tmp = pu;
	puzzle tmp;
	for (int r = 0; r < nd; r++) {
		if (max(r, prev) - min(r, prev) == 2) continue;
		tx = sx + ud[r];
		ty = sy + lr[r];
		tmp = pu;
		if (tx >= nd || tx < 0 || ty >= nd || ty < 0) continue;
		ns = tx * nd + ty;
		pu.mdp = pu.mdp - md[ns][pu.p[ns]-1] + md[sx*nd + sy][pu.p[ns]-1];
		pu.sp = ns;
		swap(pu.p[ns], pu.p[pu.sp]);
		if (dfs(de + 1, r, pu)) { 
			cout << "r" << r << "sp" << pu.sp << endl;
			way.push_back(r);
			return true; 
		}
		pu = tmp;
	}
	return false;
}*/
bool dfs(int de, int pr) {
	if (de + pu.mdp > lm) return false;
	if (pu.mdp == 0) return true;
	int sx = pu.sp / nd;
	int sy = pu.sp % nd;
	int tx, ty, ns;
	puzzle tmp;
	for (int r = 0; r < nd; r++) {
		if (max(r, pr) - min(r, pr) == 2) continue;
		tx = sx + ud[r];
		ty = sy + lr[r];
		tmp = pu;
		if (tx >= nd || tx < 0 || ty >= nd || ty < 0) continue;
		ns = tx * nd + ty;
		pu.mdp -= md[ns][pu.p[ns]- 1];
		pu.mdp += md[pu.sp][pu.p[ns] - 1];
		pu.sp = ns;
		swap(pu.p[ns], pu.p[sx * nd + sy]);
		if (dfs(de + 1, r)) {
			way.push_back(r);
			return true;
		}
		pu = tmp;
	}
	return false;
}

int main() {
	puzzle p;
	int sum = 0;
	for (int i = 0; i < num; i++) {
		cin >> p.p[i];
		if (!p.p[i]) { p.sp = i; p.p[i] = num; }
	}
	for (int i = 0; i < num; i++)
		for (int j = 0; j < num; j++)
			md[i][j] = abs(i / nd - j / nd) + abs(i%nd - j%nd);
	for (int i = 0; i < num; i++) {
		if (p.p[i] == num) continue;
		sum += md[i][p.p[i] - 1];
	}
	p.mdp = sum;
	pu = p;
	for (lm = p.mdp; lm < 100; lm++) {
		if (dfs(0, -5/*, pu*/)) {
			cout << way.size() << endl; return 0;
		}
	}
}

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

using namespace std;

#define int long long

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    set<string> s;
    for (int i = 0; i < n; ++i)
    {
        string t;
        cin >> t;
        s.insert(t);
    }
    cout << s.size() << endl;
    return 0;
}


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

int main(){
	int n;
	cin >> n;
	bool res = false;
	for(int i = 0; i <= n; i+= 4){
		for(int j = 0; j <= n-i; j+= 7){
			if(i+j == n){
				res = true;
				break;
			}
		}
	}
	if(res)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
sl = []
for i in range(m):
    tmp = list(map(int, input().split()))
    sl.append(tmp[1:])
p = list(map(int, input().split()))

cnt = 0
for i in range(2**n):
    bi = format(i, "010b")[::-1]
    flag = True
    for j in range(len(sl)):
        c = 0
        for idx in sl[j]:
            c += int(bi[int(idx)-1])
        if c % 2 != p[j]:
            flag = False
            break
    if flag:
        cnt += 1
print(cnt)

Measured memory_bytes: 3064
s = io.read()
a, op, b = s:match("(%d+) (%+) (%d+)")
if a then
  print(tonumber(a) + tonumber(b))
else
  a, op, b = s:match("(%d+) (%-) (%d+)")
  print(tonumber(a) - tonumber(b))
end


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

int main() {
	int n, x;
	cin >> n >> x;
	vector<int> l(n);
	rep(i, n) cin >> l[i];
	int d = 0;
	int ans = 1;
	rep(i, n) {
		d += l[i];
		if(d <= x) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
def search_right(a, x, lo=0, hi=None, key=lambda x: x):
    if lo < 0:
        raise ValueError('lo must be non-negative')
    if hi is None:
        hi = len(a)
    while lo < hi:
        mid = (lo+hi)//2
        if x < key(a[mid]): hi = mid
        else: lo = mid+1
    return lo


def search_left(a, x, lo=0, hi=None, key=lambda x: x):
    if lo < 0:
        raise ValueError('lo must be non-negative')
    if hi is None:
        hi = len(a)
    while lo < hi:
        mid = (lo+hi)//2
        if key(a[mid]) < x: lo = mid+1
        else: hi = mid
    return lo


def get_fin_pos(s, td, golem_pos):
    for t, d in td:
        if 0 <= golem_pos < len(s) and s[golem_pos] == t:
            golem_pos += 1 if d == "R" else -1
    return golem_pos


n, q = map(int, input().split())
s = "_{}_".format(input())
spells = [input().split() for _ in range(q)]

left = search_right(range(len(s)), 0, key=lambda golem: get_fin_pos(s, spells, golem))
right = search_left(range(len(s)), len(s) - 1, key=lambda golem: get_fin_pos(s, spells, golem))

print(right - left)

Measured memory_bytes: 41400
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = [None]*n
for i in range(n):
    a[i] = int(input())
ans = 0
for i in range(n):
    num = a[i]
    if num%2==1:
        if i+1<n and a[i+1]>0:
            ans += 1
            a[i+1] -= 1
    ans += num//2
print(ans)

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

int a, b, c;
int me[2][3];

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

	if (a%2 == 0 && a == b && b == c) {
		cout << -1 << endl;
		return 0;
	}

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

	/*for (int i = 0; i < 2; i++) {
		for (int j = 0; j < 3; j++) {
			cout << me[i][j] << " ";
		}
		cout << endl;
	}*/

	int i = 0;
	bool flag = true;
	while (true) {
		for (int j = 0; j < 3; j++)me[i%2][j] = 0;

		for (int j = 0; j < 3; j++) {
			//cout << me[(i % 2 + 1) % 2][j] << endl;
			if (me[(i%2 + 1) % 2][j] % 2 != 0) {
				flag = false;
				break;
			}

			me[i%2][(j+1)%3] += me[(i%2 + 1) % 2][j] / 2;
			me[i%2][(j+2)%3] += me[(i%2 + 1) % 2][j] / 2;
		}

		//for (int j = 0; j < 3; j++)cout << me[i % 2][j] << " ";
		//cout << endl;
		
		if (!flag)break;

		i++;
	}

	cout << i << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
using namespace std;


int main(){
    int a,b;
    cin >> a >> b;
    if(a <= 5){
        cout << 0 <<endl;
    }else if(a <= 12){
        cout << b/2 <<endl;
    }else{
        cout << b <<endl;
    }
 
        
}

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 <cmath>         // sqrt
#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 <bits/stdc++.h> // isupper, islower, isdigit, toupper, tolower
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, n) for (int i = (a); i < (n); i++)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> Pl;
typedef pair<int, int> P;
typedef tuple<ll, ll, string> Tlls;

// Greatest Common Divisor (最大公約数)
ll gcd(ll a, ll b)
{
  // Eucledean algorithm
  while (a)
  {
    if (a < b)
    {
      std::swap(a, b);
    }
    a %= b;
  }
  return b;
}

// Least Common Multiple 最小公倍数
ll lcm(ll a, ll b)
{
  return a / gcd(a, b) * b;
}

// key: value of prime factor素因数分解
// value: number of prime factor
map<ll, ll> prime_factorization(ll n)
{
  map<ll, ll> prime_factors;
  for (ll i = 2; i * i <= n; i++)
  {
    while (n % i == 0)
    {
      prime_factors[i]++;
      n /= i;
    }
  }
  if (n != 1)
    prime_factors[n] = 1;
  return prime_factors;
}

// 約数リスト約数の列挙
vector<ll> get_divisors(const ll n)
{
  vector<ll> divs;
  for (ll i = 1; i < (ll)sqrt((ld)n) + 1; i++)
  {
    if (n % i == 0)
    {
      divs.push_back(i);
      if (i != n / i)
      {
        divs.push_back(n / i);
      }
    }
  }

  // 必要に応じてソート
  // sort(divs.begin(), divs.end());

  return divs;
}

int main()
{
  int N;
  cin >> N;
  int ans = N % 1000;
  // cout << ans << endl;
  if (ans != 0)
  {
    cout << 1000 - ans << endl;
  }
  else
  {
    cout << ans << endl;
  }

  return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  rep(i, N) cin >> a[i];
  
  int ans = 0;
  int n = 1;
  rep(i, N) {
    if(a[i] == n) n++;
    else ans++;
  }
      
  
  if(ans == N) cout << "-1" << endl;
  else cout << ans << endl;
}

Measured memory_bytes: 1152
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#define ll long long
#define INF 1e+18
#define MOD 1000000007
using namespace std;



int main(){
    ll N,M;
    cin >> N >> M;
    
    ll A[N-1+M], B[N-1+M];
    for(int i=0; i<N-1+M; i++){
        cin >> A[i] >> B[i];
        A[i]--;
        B[i]--;
    }
    
    ll num_p[N];
    for(int i=0; i<N; i++){
        num_p[i]=0;
    }
    for(int i=0; i<N-1+M; i++){
        num_p[B[i]]++;
    }
    
    ll root;
    for(int i=0; i<N; i++){
        if(num_p[i]==0){
            root=i;
            break;
        }
    }
    
    queue<ll> node;
    node.push(root);
    
    vector<ll> son[N];
    for(int i=0; i<N-1+M; i++){
        son[A[i]].push_back(B[i]);
    }
    
    ll p[N];
    for(int i=0; i<N; i++){
        p[i]=root;
    }
    ll depth[N];
    for(int i=0; i<N; i++){
        depth[i]=0;
    }
    p[root]=-1;
    depth[root]=0;
    
    
    while(!node.empty()){
        ll temp_p=node.front();
        
        for(int i=0; i<son[temp_p].size(); i++){
            ll temp_s=son[temp_p][i];
            
            if(depth[temp_s]<depth[temp_p]+1){
                depth[temp_s]=depth[temp_p]+1;
                p[temp_s]=temp_p;
            }
            
            num_p[temp_s]--;
            if(num_p[temp_s]==0){
                node.push(temp_s);
            }
        }
        
        
        node.pop();
    }
    
    
    for(int i=0; i<N; i++){
        cout << p[i]+1 << endl;
    }
    return 0;
}


Measured memory_bytes: 10240
var readable = process.stdin;
readable.resume();
readable.setEncoding( 'utf-8' );
readable.on( 'data', function( chunk ) {
  var n = parseInt( chunk );
  var i = 1;
  var output = [];
  do{
    var x = i;
    if( 0 == x%3 ) {
      output.push( " "+i );
    } else {
      do {
        if( 3 == x%10 ) {
          output.push( " "+i );
          break;
        } else {
          x /= 10;
          x = Math.floor(x);
        }
      } while( x );
    }
  } while( ++i <= n );
  
  console.log( output.join( '' ) );
});

Measured memory_bytes: 10204
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mod 1000000007
#define inf 1000000000000000007
#define eps 0.000000000001
#define pi 3.141592653589793
#define pii pair<int,int>
#define pdd pair<ld,ld>
#define pll pair<ll,ll>
#define ff first
#define ss second
#define vii vector<int>
#define vpl vector<pll>
#define vll vector<ll>
#define mseti multiset <ll>
#define msetd multiset <ll, greater <ll> >
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound 
#define stp setprecision(20)//use fixed before stp
#define endl '\n'
int main()
{  
    FAST
    ll n;
    cin>>n;
    cout<<(3*(n*n));
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  while(1){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(a+b+c+d==0)break;
    for(int i=0;i<100000;i++){
      if((a+d*i)/b>=c){
	cout<<i<<endl;
	break;
      }
    }
  }
  return 0;
}

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

using ll = long long;
using namespace std;

#define swap(a, b)    do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while(false)
#define repd(i, a, b) for(typeof(b) i = a; i < (b); ++i)
#define rep(i, n)     repd(i, 0, n)
#define dump(x)       cerr << #x << " = " << (x) << endl
#define debug(x)      cerr << "L" << __LINE__ << ": " << #x << " = " << (x) << endl
#define YN(x)         cout << ((x) ? "YES" : "NO") << endl
#define Yn(x)         cout << ((x) ? "Yes" : "No") << endl
#define yn(x)         cout << ((x) ? "yes" : "no") << endl
#define absi(x)       ( ((x) >= 0) ? (x) : (-(x)) )
#define debugvec(v)   rep(i, v.size()) cerr << "L" << __LINE__ << ": " << #v << "[" << i << "] = " << v[i] << endl;
#define debugvec2(v)  cerr << "L" << __LINE__ << ": " << #v << " = { "; rep(i, v.size()) cerr << v[i] << (i + 1 == v.size() ? "" : ", "); cerr << " }" << endl;

ll gcd(ll a, ll b) { return __gcd(a, b); }
ll lcm(ll a, ll b) { return (a == 0 || b == 0) ? 0 : (a / __gcd(a, b) * b); }

int main(int argc, const char* argv[]) {
	string s;
	cin >> s;

	vector<ll> ret(s.length(), 0);

	ll rstart = 0;
	ll rend = 0;
	repd(i, 1, s.length()) {
		if(s.at(i-1) == s.at(i)) continue;

		if(s.at(i-1) == 'R' && s.at(i) == 'L') {
			ret.at(i-1) = i - rstart;
			rend = i - 1;
		}

		if(s.at(i-1) == 'L' && s.at(i) == 'R') {
			ret.at(rend + 1) = i - rend - 1;
			rstart = i;
		}

		debug(rstart);
		debug(rend);
	}

	ret.at(rend + 1) = s.length() - rend - 1;

	rep(i, s.size()) {
		if(ret.at(i) > 0 && s.at(i) == 'R') {
			ll rnum = ret.at(i);
			ll lnum = ret.at(i+1);
			
			ret.at(i)   = ( (rnum % 2 == 0) ? rnum / 2 : rnum / 2 + 1 ) + (lnum / 2);
			ret.at(i+1) = ( (lnum % 2 == 0) ? lnum / 2 : lnum / 2 + 1 ) + (rnum / 2);
		}
	}

	cout << ret.at(0);
	repd(i, 1, ret.size()) {
		cout <<  " " << ret.at(i);
	}

	return 0;
}


Measured memory_bytes: 1408
n, m = gets.split.map(&:to_i)
xn = gets.split.map(&:to_i)
yn = gets.split.map(&:to_i)
M = (10**9) + 7

an = (1..n).map { |k| (k-1) * xn[k-1] - (n - k)* xn[k-1] }.inject(:+)
am = (1..m).map { |k| (k-1) * yn[k-1] - (m - k)* yn[k-1] }.inject(:+)
p (an * am) % M


Measured memory_bytes: 17176
function main(input) {
  const args = input.split(' ');
  var takagiHP = parseInt(args[0], 10);
  var takagiAK = parseInt(args[1], 10);
  var aokiHP = parseInt(args[2], 10);
  var aokiAK = parseInt(args[3], 10);

  while(takagiHP > 0 && aokiHP > 0) {
    aokiHP -= takagiAK;
    if(aokiHP <= 0) {
      break;
    }
    takagiHP -= aokiAK;
    if(takagiHP <= 0) {
      break;
    }
  }

  if(aokiHP <= 0){
    console.log('Yes')
  } else {
  	console.log('No')
  }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 29616
import sys
from collections import Counter
candnum=int(input())
candiff=list(map(int,input().split()))
pronum=int(input())
prodiff=list(map(int,input().split()))

candiff=Counter(candiff)
prodiff=Counter(prodiff)
if pronum>candnum:
    print("NO")
    sys.exit()
for k,v in prodiff.items():
    if k in candiff:
        if candiff[k]<v:
            print("NO")
            sys.exit()
    else:
        print("NO")
        sys.exit()
print("YES")

Measured memory_bytes: 55648
#include <bits/stdc++.h>
using namespace std;
string s;
int main() {
  cin >> s;
  unordered_map<int, int> mt;
  mt[0] = 0;
  const int n = s.size();
  vector<int> dp(n + 1);
  iota(dp.begin(), dp.end(), 0);
  int state = 0;
  for (int i = 1; i <= n; ++i) {
    const int cc = s[i - 1] - 'a';
    state ^= (1 << cc);

    for (int k = 0; k < 26; ++k) {
      int ps = state ^ (1 << k);
      if (mt.count(ps)) {
        dp[i] = min(dp[i], 1 + mt[ps]);
      }
    }

    if (mt.count(state)) {
      dp[i] = min(dp[i], 1 + mt[state]);
      mt[state] = min(dp[i], mt[state]);
    } else mt[state] = dp[i];
    // cout << dp[i] << endl;
  }

  cout << dp[n] << endl;
}

Measured memory_bytes: 9420
/*
 *  author : Atul Anand   
 *  created on : Thu Apr 02 2020
 */

import java.io.*;
import java.util.*;

public class Main{

    public static void main(String[] args) throws IOException {
        String S = in.next();
        HashMap<Character, Integer> map = new HashMap<>();
        for(int i = 0; i < 4; i++){
            map.put(S.charAt(i), map.getOrDefault(S.charAt(i), 0) + 1);
        }

        if(map.size() == 2){
            boolean flag = true;
            for(char c: map.keySet()){
                if(map.get(c) == 1){
                    flag = false;
                }
            }
            if(flag){
                println("Yes");
            }
            else{
                println("No");
            }
        }
        else{
            println("No");
        }
        
        in.close();
        out.close();
    }

    static int MIN = Integer.MIN_VALUE;
    static int MAX = Integer.MAX_VALUE;
    static Reader in = new Reader();
    static PrintWriter out = new PrintWriter(System.out);

    static void read(int arr[], int N) throws IOException { 
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.nextInt(); 
    	} 
    }
    
    static void read(long arr[], int N) throws IOException { 
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.nextLong(); 
    	} 
    }
    
    static void read(String arr[], int N) throws IOException { 
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.next(); 
    	} 
    }
    
    static void print(Object O) {  
    	out.print(O); 
    }
    
    static void println(Object O) { 
    	out.println(O); 
    }
    
    static void println(int arr[]) { 
    	for(int i = 0; i < arr.length; i++){ 
    		print(arr[i]+" "); 
    	} 
    	println(""); 
    }

    static void println(int arr[][]) { 
    	for(int i = 0; i < arr.length; i++){ 
    		println(arr[i]); 
    	}
    }
    
    static void debug(Object O) { 
    	System.out.println(O); 
    }
}

class Reader {
    BufferedReader reader;
    StringTokenizer tokenizer;

    Reader() {
        reader = new BufferedReader(new InputStreamReader(System.in));
        tokenizer = new StringTokenizer("");
    }

    String next() throws IOException {
        while (!tokenizer.hasMoreTokens() ) { 
            tokenizer = new StringTokenizer(reader.readLine()); 
        }
        return tokenizer.nextToken();
    }

    int nextInt() throws IOException { 
        return Integer.parseInt(next()); 
    }
    
    double nextDouble() throws IOException { 
        return Double.parseDouble(next());
    }
    
    long nextLong() throws IOException { 
        return Long.parseLong(next()); 
    }
    
    String nextLine() throws IOException { 
        return reader.readLine(); 
    }
    
    void close() throws IOException { 
        reader.close(); 
    }
}

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

typedef long long ll;
#define pa pair<int, int> 
#define pal pair<long long, long long>
#define pad pair<double, double>
#define pb push_back
#define mp make_pair
#define VIN(v) for(int64_t i=0;i<(v).size();i++){cin >> (v).at(i);}

typedef vector<bool> bvec;
typedef vector<int> ivec;
typedef vector<long long> lvec;
typedef vector<double> dvec;
typedef vector<pa> pvec;



typedef vector< vector<bool> > bmat;
typedef vector< vector<int> > imat;
typedef vector<string> svec;
typedef vector< vector<string> > smat;


double dist(double x, double xx, double y, double yy){
    return sqrt((double)(x-xx)*(x-xx) + (double)(y-yy)*(y-yy));
}

void dfs(int c, int p, double sum, int n, bvec v, const pvec &map, double &total){
    int cnt=n, i=0;
    double d=0;
    if (p>=0) {
        
        d = dist((double)map[c].first, (double)map[p].first, (double)map[c].second, (double)map[p].second);
    
    }
    if (n==0) {
        total += sum + d;
    }

    while(cnt){
        if(!v[i]) {
            bvec vv = v;
            vv[i] = true;
            dfs(i, c, sum+d, n-1, vv, map, total);
            cnt--;
        }
        i++;
    }
}

int fac(int n){
    if (n==1) return 1;
    else return n*fac(n-1);
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    pvec map;
    double total = 0;


    for(int i=0; i<n; i++) {
        int x, y;
        cin >> x >> y;
        map.push_back(pa(x,y));
    }

    for(int i=0; i<n; i++){
        bvec v(n, false);
        v[i] = true;
        dfs(i, -1, 0, n-1, v, map, total);
    }
    
    cout << std::setprecision(15) << (double)total/(double)fac(n) << endl;
    
    return 0;
}  


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int main() 
{
	int a=0,b=0,sum=0;
	scanf("%d%d",&a,&b);
	if(a>b)
		sum=2*a-1;
	else if(b>a)
		sum=2*b-1;
	else if(a==b)
		sum=a+b;
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>

using namespace std;

int main(){
	int n;
	int ans;
	while (cin >> n){
		ans = 0;
		for (int i = 0; i < 10; i++){
			for (int j = 0; j < 10; j++){
				for (int k = 0; k < 10; k++){
					for (int l = 0; l < 10; l++){
						ans += (i + j + k + l == n);
					}
				}
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll INF = 1LL << 60;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
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;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
//printf("%.10f\n", N);
/*
ll fibo(ll n){
    if(memo[n] != 0)return memo[n];
    if(n <= 1)return n;
    else return memo[n] = fibo(n - 1)+ fibo(n - 2);
}*/
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/
/*
    cout << fixed << setprecision(15);
    */
int main(){
    ll Q;
    cin >> Q;
    ll memo[100005];
    memo[0] = 0;
    memo[1] = 0;
    for(ll i = 2;i<100005;i++){
        if(isp(i) && isp((i + 1) / 2))memo[i] = memo[i - 1] + 1;
        else memo[i] = memo[i - 1];
    }
    vector<ll> l(Q);
    vector<ll> r(Q);
    rep(i,Q)cin >> l[i] >> r[i];
    rep(i,Q){
        cout << memo[r[i]] - memo[l[i] - 1] << endl;
    }
}


Measured memory_bytes: 2944
X = list(input())

q_num = X.count("?")
a_num = 0
c_num = X.count("C")
left_q_num = 0
right_q_num = q_num
ans = 0
len_x = len(X)
q_dict = []
b_ans = 0
q_ans = 0
q_dict = {}
q_dict[q_num - 1] = (3 ** (q_num - 1)) % (10 ** 9 + 7)
q_dict[q_num - 2] = (3 ** (q_num - 2)) % (10 ** 9 + 7)
q_dict[q_num - 3] = (3 ** (q_num - 3)) % (10 ** 9 + 7)
q_dict[q_num] = (3 ** (q_num)) % (10 ** 9 + 7)

if X[0] == "?":
    right_q_num -= 1
elif X[0] == "C":
    c_num -= 1
for i, x in enumerate(X):
    if x == "B" or x == "?":
        ans += (a_num * c_num)  * (q_dict[(left_q_num + right_q_num)])
        if left_q_num + right_q_num >= 2:
            ans += (right_q_num * left_q_num  + 3*(left_q_num * c_num) + 3*(right_q_num * a_num)) * (q_dict[(left_q_num + right_q_num - 2)])
        elif left_q_num + right_q_num == 1:
            ans += ((left_q_num * c_num) + (right_q_num * a_num)) * (q_dict[(left_q_num + right_q_num - 1)])
        ans = ans % (10 ** 9 + 7)
    if  i == len_x - 1:
        break
    if x == "A":
        a_num += 1
    elif x == "?":
        left_q_num += 1
    if X[i + 1] == "C":
        c_num -= 1
    elif X[i + 1] == "?":
        right_q_num -= 1

print(ans % (10 ** 9 + 7))



Measured memory_bytes: 49264
#include <cstdio>
#include <set>
typedef long long ll; 
int f[200005], cnt0[200005], cnt1[200005], fa[200005]; 
struct comper
{
	inline bool operator ()(const int &x, const int &y) const
	{
		if ((ll)cnt1[x] * cnt0[y] == (ll)cnt1[y] * cnt0[x])
			return x < y; 
		return (ll)cnt1[x] * cnt0[y] < (ll)cnt1[y] * cnt0[x]; 
	}
}; 
std::set<int, comper> se; 
int getfa(int u)
{
	if (u == f[u])
		return u; 
	return f[u] = getfa(f[u]); 
}
int main()
{
	// freopen("AGC023-F.in", "r", stdin); 
	int n;
	scanf("%d", &n); 
	for (int i = 1; i < n; i++)
	{
		scanf("%d", fa + i);
		fa[i]--;
	}
	for (int i = 0; i < n; i++)
	{
		f[i] = i; 
		int x; 
		scanf("%d", &x); 
		(x ? cnt1 : cnt0)[i]++; 
	}
	for (int i = 1; i < n; i++)
		se.insert(i); 
	ll ans = 0;
	while (!se.empty())
	{
		int u = *se.begin(); 
		se.erase(u); 
		int v = getfa(fa[u]); 
		f[u] = v; 
		if (v)
			se.erase(v); 
		ans += (ll)cnt1[v] * cnt0[u]; 
		cnt0[v] += cnt0[u]; 
		cnt1[v] += cnt1[u]; 
		if (v)
			se.insert(v); 
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 13824
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1001001001
#define LINF 1001001001001001001
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;
typedef long long ll;


const int k[3] = {2, 3, 5};
map<ll, ll> memo;
ll N, A[4];

ll solve(ll N) {
    if (N == 0) return 0;
    if (N == 1) return A[3];
    if (memo.find(N) != memo.end()) return memo[N];
    ll ans = 1e18;
    if (N < ans / A[3]) ans = N * A[3];
    rep(j,3) {
        ll next;
        next = N / k[j];
        ans = min(ans, abs(next * k[j] - N) * A[3] + A[j] + solve(next));
        next = (N + k[j] - 1) / k[j];
        ans = min(ans, abs(next * k[j] - N) * A[3] + A[j] + solve(next));
    }
    memo[N] = ans;
    return ans;
}

int main() {

    int T;
    cin >> T;
    rep(i,T) {
        memo.clear();
        cin >> N >> A[0] >> A[1] >> A[2] >> A[3];
        cout << solve(N) << endl;
    }
    
    return 0;
}

Measured memory_bytes: 4252
N = int(input())

ans = [0] * (N+1)

for x in range(1, 10**2):
    for y in range(1, 10**2):
        for z in range(1, 10**2):
            try:
                ans[(x+y+z)**2 - (x*y+y*z+z*x)] += 1
            except:
                pass

for i in range(1, N+1):
    print(ans[i])


Measured memory_bytes: 69140
#include <iostream>
#include <string>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <cassert>
using namespace std;
typedef long long ll;
typedef long double ld;
#define PI (ld)3.14159265358979324
#define mp make_pair 
#define pb push_back
#define ft first
#define sd second
#define sz(a) (ll)a.size()
#define pii pair<int,int>
#define pll pair<ll,ll>
#define loop(i, n) for(int (i) = 0; (i) < (n) ; ++ (i))
#define forn(i, l, r) for(int (i) = (l); (i) < (r) ; ++ (i))
#define vec vector 
#define str string
/*******************************************************/

void solve() {
    int n;
    string s,t;
    cin >> n >> s >> t;
    loop(i,n + 1) {
        str pref1 = s.substr(i,n - i);
        str pref2 = t.substr(0,n - i);
        if(pref1 == pref2) {
            str o = s.substr(0,i) + t ;
            cout << o.size()<<endl;
            return;
        }
    }

}

int main()
{
    // freopen("in.txt","r", stdin);
    ios_base::sync_with_stdio(false);   
    // cout << fixed;
    // cout.precision(3);

    solve();
    return 0;
}


Measured memory_bytes: 256
import math
import fractions
import collections
import itertools
from collections import deque
S=input()
N=len(S)
cnt=0
l=[]
"""
cnt=0
p=10**9+7
for i in range(K,N+2):
    cnt=(cnt+((N-i+1)*i)+1)%p
    #print(((N-i+1)*i)+1)
print(cnt)
"""
amari=[0]*(N+1)
num=0
for i in range(N):
    num=num+pow(10,i,2019)*int(S[N-1-i])
    amari[i+1]=num%2019
#print(amari)
c=collections.Counter(amari)
values=list(c.values())	#aのCollectionのvalue値のリスト(n_1こ、n_2こ…)
key=list(c.keys())	#先のvalue値に相当する要素のリスト(要素1,要素2,…)
#for i in range(len(key)):
#    l.append([key[i],values[i]])#lは[要素i,n_i]の情報を詰めたmatrix
#xprint(l)
for i in range(len(values)):
    cnt=cnt+(values[i]*(values[i]-1))//2
print(cnt)

Measured memory_bytes: 80656
#include<stdio.h>
int a[100002];
int main(){
	int n,ans=0,t;
	scanf("%d",&n);
	for(int i = 1;i <= n;i++)
		scanf("%d",&a[i]);
	for(int i = 1;i <= n;i++){
		if(a[i]==i){
			t=a[i];a[i]=a[i+1];a[i+1]=t;
			ans++;
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 512