akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0;i<(n);i++)
#define REP1(i,n) for(int i=1;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using Pint = pair<int, int>;
const ll mod = 1e9+7;

struct mint {
  ll x;
  mint(ll x=0): x((x%mod+mod)%mod) {}
  mint operator-() const {return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};

struct combination {
  vector<mint> fact, ifact;
  combination(int n): fact(n+1),ifact(n+1) {
    assert(n<mod);
    fact[0] = 1;
    REP1(i,n+1) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for(int i=n; i>=1; i--) ifact[i-1]=ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if(k<0 || k>n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} comb((int)2e6+5);

mint g(int r, int c) {
  return comb(r+c+2, r+1)-1;
}

int main(int argc, char const* argv[])
{
  int r1, c1, r2, c2;
  cin>>r1>>c1>>r2>>c2;
  r1--; c1--;
  mint ans = g(r2,c2) - g(r1,c2) - g(r2,c1) + g(r1,c1);
  cout << ans.x << endl;

  return 0;
}

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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    ll a, b;
    cin >> a >> b;
    cout << a*b << endl;
    return 0;
}


Measured memory_bytes: 3636
N = int(input())
A = list(map(int, input().split()))


def hantei(x):
    t = True
    for i in x:
        if (i % 2 != 0):
            t = False
            break
    return t


def calc_hanbun(x):
    return x // 2


if not (hantei(A)):
    print(0)
    exit()

count = 0
while True:
    if hantei(A):
        A = list(map(calc_hanbun, A))
        count += 1
    else:
        print(count)
        exit()


Measured memory_bytes: 3064
import numpy as np
N, D = map(int, input().split())
x = []
for i in range(N):
  x.append(list(map(int, input().split())))
x = np.array(x)
ans = 0
for i in range(N-1):
  for j in range(i+1,N):
    tmp = sum((x[i]-x[j])**2)
    for k in range(1,tmp+1):
      if tmp == k**2:
        ans += 1
        break
print(ans)

Measured memory_bytes: 12488
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
int n, d, e[1005][1005], l, r, m, s, o, p;
bool h[1005], w[1005], bt[1005][1005];
int main(){
	scanf("%d%d", &n, &d);
	rep(i,n){
		scanf("%d%d", &l, &r);
		m = max(m,++e[l%d][r%d]);
	}
	for(s=1; s*s < m; s++);
	rep(i,d) rep(j,d){
		if(s*(s-1) < e[i][j]) h[i] = w[j] = true;
		else if((s-1)*(s-1) < e[i][j]) bt[i][j] = true;
	}
	l=0;r=d;
	while(l+1 < r){
		int c[1005] = {}, o = 0;
		bool ok = false;
		m = (l+r) / 2;
		rep(i,d){
			for(; o < i+m && !h[o%d]; o++) rep(j,d) if(bt[o%d][j]) c[j]++;
			if(o < i+m){
				rep(j,d) c[j] = 0;
				i = o++;
				continue;
			}
			int p = 0;
			rep(j,d){
				for(; p < j+m && !w[p%d] && !c[p%d]; p++);
				if(p < j+m) j = p++;
				else ok = true;
			}
			rep(j,d) if(bt[i][j]) c[j]--;
		}
		(ok ? l : r) = m;
	}
	printf("%d\n", s*d-l-1);
}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF 2147483647//int max
const int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;

int func(int n){
    if(n%2 == 0){
        return n/2;
    }else{
        return 3*n + 1;
    }
}

int main() {
    int s;
    cin >> s;
    vector<int> a(1000000,0);
    int cnt = 0;
    int memo = 0;
    for(int i = 0;;i++){
        if(i == 0)a[i] = s;
        else {
            a[i] = func(a[i-1]);
        }
        if(a[i] == 4)cnt++;
        if(cnt == 2){
            memo = i;
            break;
        }
    }
    if(s == 1)cout << memo;
    else if(s == 2)cout << memo -1;
    else cout << memo+1;
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 4096
#include <iostream>
#include <map>
#include <string>

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

    std::map<std::string, int> my_map{};
    for (int i = 0; i < q; ++i) {
        int kind;
        std::string key;
        std::cin >> kind >> key;

        int x;
        decltype(my_map)::iterator iter;
        switch (kind) {
            case 0:
                std::cin >> x;
                iter = my_map.find(key);
                if (iter != my_map.end())
                    my_map[key] = x;
                else
                    my_map.insert(std::make_pair(key, x));
                break;
            case 1:
                std::cout << my_map.at(key) << std::endl;
                break;
            default:
                std::cerr << "kind: ?";
        }
    }
}


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

int main(){
    int total_area = 0;

    string geo; cin >> geo;
    stack<int> s;
    stack<pair<int, int>> s2;

    for(int i = 0; i < geo.size(); i++){

        if(geo.at(i) == '\\'){
            s.push(i);

        }else if(geo.at(i) == '/'){
            if(s.size() > 0){ // 初期標高よりも低い場合
                int left = s.top(); s.pop(); // 上り/に対応する下り\の座標
                int area = i - left; // right/とleft\に挟まれた面積
                
                // 水たまりの総面積
                total_area += area;

                // 水たまりの統合
                while(s2.size() > 0 && s2.top().first > left){
                    area += s2.top().second;
                    s2.pop();
                }
                s2.push(make_pair(left, area));
            }
        }
   }
    cout << total_area << endl;


    int size = s2.size();
    vector<int> ans;

    for(int i = 0; i < size; i++){
        ans.push_back(s2.top().second);
        s2.pop();
    }
    reverse(ans.begin(), ans.end());

    cout << size;
    for(int i = 0; i < ans.size(); i++){
        cout << " ";
        cout << ans.at(i);
    }
    cout << endl;
    return 0;
}



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

using namespace std;
#define ll long long int


int main()
{
    int n;
    cin >> n;
    bool ok = false;
    while(n>0){
        if(n%10==7){
            cout << "Yes" << endl;
            return 0;
        }
        n/=10;
    }
cout << "No" << endl;
}


Measured memory_bytes: 3624
#pragma region
#include <bits/stdc++.h>	
#define pb push_back
typedef long long ll;
const int inf = 2e9;
using namespace std;
#pragma endregion


char T[60][60];
int n,m,ans=0,t,b=0;


bool ord(int a, int b){
	return a>b;
}


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

    for (int i = 0; i < n; ++i)
    {
    	scanf("%s",T[i]);
    }


    for (int i = 0; i < n; ++i)
    {
    	for (int j = 0; j < m; ++j)
    	{
    		if(T[i][j]=='#'){

    			if(!(i-1>-1 && T[i-1][j]=='#') &&
    			 !(i+1<n && T[i+1][j]=='#') &&
    			 !(j-1>-1 && T[i][j-1]=='#') &&
    			 !(j+1<m && T[i][j+1]=='#')) return !printf("No\n");
    		}

    	}
    }	

    
    return !printf("Yes\n");
    
       
}

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

int main(){
    string S; cin >> S;
    int f = -1;
    int c = S.size();
    
    for(int i=0; i<S.size(); i++){
        if(S[i] == 'C')
            c = min(c, i);
        if(S[i] == 'F')
            f = max(f, i);
    }
    
    cout << (c < f? "Yes": "No") << endl;
    
    return 0;
}

Measured memory_bytes: 256
//最初：max(Aj - Ai) (j < i) をMとすると, M * [T/2]円が最適。
//妨害コスト： Aj - Ai = Mとなる(i, j)組の個数が最小。
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#define int long long
using namespace std;

int n, t;
int a[100000];
int maxR[100000];	//maxR[i] = max(a[i..n))

signed main() {
	int i, j;
	
	cin >> n >> t;
	for (i = 0; i < n; i++) cin >> a[i];
	
	maxR[n - 1] = a[n - 1];
	for (i = n - 2; i >= 0; i--) maxR[i] = max(maxR[i + 1], a[i]);
	
	int maxi = 0;
	for (i = 0; i < n; i++) maxi = max(maxi, maxR[i] - a[i]);

	int ans = 0;
	for (i = 0; i < n; i++) if (maxR[i] - a[i] == maxi) ans++;
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <iostream>
#include <vector>
#include <inttypes.h>
using namespace std;

#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
    int N; scanf("%d", &N);
    vector<pair<int64_t, int64_t>> points(N);
    REP(i, N) {
        int64_t a, b; scanf("%" SCNd64 "%" SCNd64, &a, &b);
        points[i] = {a, b};
    }

    vector<vector<int64_t>> f(N);
    REP(i, N) {
        auto [x, y] = points[i];
        f[i] = {x-y, x+y};
    }

    int64_t ans = numeric_limits<int64_t>::min();
    REP(d, 2) {
        auto m1 = numeric_limits<int64_t>::max();
        auto m2 = numeric_limits<int64_t>::min();
        REP(i, N) m1 = min(m1, f[i][d]);
        REP(i, N) m2 = max(m2, f[i][d]);
        ans = max(ans, m2 - m1);
    }
    cout << ans << endl;
}


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

using namespace std;

const int INF = numeric_limits<int>::max() / 2;

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

    int n, m;
    cin >> n >> m;
    int imos_w[n + 2] = {0}, imos_e[n + 2] = {0}, wsum = 0, esum = 0;
    for (int i = 0; i < m; i++)
    {
        string s;
        cin >> s;
        for (int j = 1; j <= n; j++)
        {
            if (s[j - 1] == 'W')
            {
                imos_w[j]++;
                wsum++;
            }
            else
            {
                imos_e[j]++;
                esum++;
            }
        }
    }
    for (int i = 1; i <= n; i++)
    {
        imos_w[i] += imos_w[i - 1];
        imos_e[i] += imos_e[i - 1];
    }
    int res, dif_min = INF;
    for (int i = 0; i <= n; i++)
    {
        int tmp = imos_e[i] + (wsum - imos_w[i]);
        //cout<<tmp<<endl;
        if (dif_min > tmp)
        {
            dif_min = tmp;
            res = i;
        }
    }
    cout << res << " " << res + 1 << endl;
}


Measured memory_bytes: 3332
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(void)
{
	int a,b,c,d,e;
	scanf("%d %d %d %d %d",&a,&b,&c,&d,&e);
	if(c>=min(a,b)){
	printf("%d\n",min(a,b)+min(d,e)-50);
	}else{printf("%d\n",c+min(d,e)-50);}
	return 0;
}


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

int main(){
  ll n,k;
  std::cin >> n>>k;

  //様子見。
  // ll temp=n;
  // ll mi=100100100100100101;
  //
  // ll sa;
  // rep(i,10){
  //   std::cout << "temp" <<temp<<'\n';
  //   if(abs(temp-k)==mi)break;
  //   sa =temp-abs(temp-k);
  //   std::cout << "sa" << sa<<'\n';
  //   if(sa<0)break;
  //   temp=abs(temp-k);
  //   if(mi==-1)mi=n;
  //   else  mi =min(mi,temp);
  //
  //   std::cout << temp <<":"<<sa<<'\n';
  // }
  //
  // std::cout << min(temp,n) << '\n';

  //それっぽいもの
  // if(n-k!=0)std::cout << min(n%min(abs(n-k),k),n) << '\n';
  // else std::cout << 0 << '\n';

  //真面目に考察

  
  std::cout << min(n-n/k*k,abs(n-n/k*k-k)) << '\n';



  return 0;
}


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

int main() {
	int n;
	scanf("%d", &n);
	vector<int> t(n);
	int total = 0;
	for(int i = 0; i < n; i++) {
		scanf("%d", &t[i]);
		total += t[i];
	}
	int m;
	scanf("%d", &m);
	vector<int> p(m);
	vector<int> x(m);
	for(int i = 0; i < m; i++) {
		scanf("%d %d", &p[i], &x[i]);		
	}
	for(int i = 0; i < m; i++) {
		int ans = total;
		ans -= t[p[i] - 1] - x[i];
		printf("%d\n", ans);
	}
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let c: i64 = read();
    let mut xseq = vec![0 as i64; n];
    let mut vseq = vec![0 as i64; n];
    let mut maxs = vec![vec![0 as i64; n]; 2];
    for i in 0..n {
        xseq[i] = read();
        vseq[i] = read();
    }
    let mut ans = 0;
    for iter in 0..2 {
        let mut sum = 0;
        let mut prev = if iter == 0 { 0 } else { c };
        for i in 0..n {
            let index = if iter == 0 { i } else { n - 1 - i };
            let d = (xseq[index] - prev).abs();
            sum += vseq[index] - d;
            maxs[iter][index] = std::cmp::max(maxs[iter][index], sum);
            if i != n - 1 {
                let nindex = if iter == 0 { i + 1 } else { n - 2 - i };
                maxs[iter][nindex] = maxs[iter][index];
            }
            prev = xseq[index];
            // println!("{} {} {}", index, xseq[index], sum);
            ans = std::cmp::max(ans, sum);
        }
        // println!("");
    }
    for iter in 0..2 {
        let start = if iter == 0 { 0 } else { c };
        for i in 0..n - 1 {
            let index = if iter == 0 { i } else { n - 1 - i };
            let nindex = if iter == 0 { i + 1 } else { n - 2 - i };
            let d = (start - xseq[index]).abs();
            let sum = maxs[iter][index] - d + maxs[iter ^ 1][nindex];
            // println!("{} {}", index, sum);
            ans = std::cmp::max(ans, sum);
        }
        // println!("");
    }
    println!("{}", ans)
}


Measured memory_bytes: 8444
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

#include <set>
#include <map>
#include <iomanip>

using namespace std;

#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define rrep(i, n) for(long long i = (long long)(n - 1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()

using ll = long long;

int main()
{
	ll A;
	string B;
	cin >> A >> B;

	vector<ll> digits;
	rep(i, B.size())
	{
		if (B[i] != '.')
		{
			digits.push_back(B[i] - '0');
		}
	}

	ll C = digits[2] + digits[1] * 10 + digits[0] * 100;
	
	cout << A * C / 100 << endl;

	return 0;
}

Measured memory_bytes: 3564
//***********************
//Author:kibi11
//Quarantine Days
//***********************

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define MOD 1000000007
#define dd double
#define fr(i, n) for(int i = 0; i < n; i++)
#define fr1(i,a,b) for(int i=a;i<b;i++)
#define frr(i,a,k) for(int i=a;i>=k;i--)
#define same int t;cin>>t;while(t--)
#define check(x) cout << (#x) << " is " << (x) << endl
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define f first
#define s second
#define XOX

//////////////////////////////////////////////////////////////////////////
/////////////////DEBUGING ZONE//////////////////////////////

vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
///////////////////////////////////////////////////////////////////////////
 
ll powermod(ll base, ll exp, ll mod) {
	ll result = 1;
	while (exp != 0) {
		if ((exp % 2) == 1) {
			result = (result * base) % mod;
		}
		base = (base * base) % mod;
		exp /= 2;
	}
	return result;
}

///////////////////////////////////////////////////////////////////////////
//Fuctions if any:





///////////////////////////////////////////////////////////////////////////
int main() 
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int tt = clock();
//ios_base& scientific (ios_base& str);
	// #ifndef ONLINE_JUDGE
	// 	freopen("C:\\Users\\arpan\\Documents\\prog c++\\IN.txt","r",stdin);
	// 	freopen("C:\\Users\\arpan\\Documents\\prog c++\\OUT.txt","w",stdout);
	// 	freopen("C:\\Users\\arpan\\Documents\\prog c++\\Error.txt","w",stderr);
	// #endif
int a,b;
cin>>a>>b;
cout<<a*b<<endl;
cerr << "TIME = " << (double) 1.0 * (clock() - tt) / CLOCKS_PER_SEC << " seconds" << endl;
return 0;
}

Measured memory_bytes: 3848
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int dfs(vector<VI>& g, int now) {
    VI a;
    each(to, g[now])a.push_back(dfs(g, to));
    rSORT(a, greater<int>());
    int ret = 0;
    FOR(i, 0, a.size())chmax(ret, a[i] + i + 1);
    return ret;
}

int main() {
    init();

    int n; cin >> n;
    auto g = vec<VI>(n);
    FOR(i, 1, n) {
        int a; cin >> a;
        g[--a].push_back(i);
    }
    cout << dfs(g, 0) << "\n";
}

Measured memory_bytes: 13568
n = int(input())
s = input()
r = s.count("R")
g = s.count("G")
b = s.count("B")
ans = r * g * b
for i in range(1, 1+n//2):
    for j in range(1, n-i*2+1):
        if s[j-1] != s[j+i-1] and s[j-1] != s[j+i*2-1] and s[j+i-1] != s[j+i*2-1]:
                ans -= 1
print(ans)


Measured memory_bytes: 9204
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<functional>
using namespace std;
#define INF 1e15
#define MOD 1000000007
typedef pair<int, int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
typedef long long ll;
#define END system("PAUSE");return 0
int a, b, c, d, e, f, g;
signed main() {
	cin >> a >> b >> c >> d >> e >> f >> g;
	//A:2個で+2
	//D:2個で+2
	//E:2個で+2
	//B:1個で+1
	//A1個+D1個+E1個で+3(高々1個まで)
	if (a&&d&&e)cout << max(b + ((a - 1) / 2 * 2) + ((d - 1) / 2 * 2) + ((e - 1) / 2 * 2) + 3, b + (a / 2 * 2) + (d / 2 * 2) + (e / 2 * 2)) << endl;
	else cout<< b + (a / 2 * 2) + (d / 2 * 2) + (e / 2 * 2) << endl;
	END;
}


Measured memory_bytes: 504
#pragma GCC target("avx2,avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//using i128 = __int128_t;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
constexpr char ln = '\n';
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) {if (a < b) {a = b; return true;} return false;}
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) {if (a > b) {a = b; return true;} return false;}
inline int topbit(int x) {return x == 0 ? -1 : 31-__builtin_clz(x);}
inline int topbit(long long x) {return x == 0 ? -1 : 63-__builtin_clzll(x);}
inline int botbit(int x) {return x == 0 ? 32 : __builtin_ctz(x);}
inline int botbit(long long x) {return x == 0 ? 64 : __builtin_ctzll(x);}
inline int popcount(int x) {return __builtin_popcount(x);}
inline int popcount(long long x) {return __builtin_popcountll(x);}
inline void print() {cout << "\n";}
template<class T>
inline void print(const vector<T> &v) {
    for (auto itr = v.begin(); itr != v.end(); ++itr) cout << *itr << " ";
    print();
}
template<class T, class... Args>
inline void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
#ifdef MINATO_LOCAL
#define dump(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
inline void debug() {cerr << endl;}
template<class T>
inline void debug(const vector<T> &v) {
    for (auto itr = v.begin(); itr != v.end(); ++itr) cerr << *itr << " ";
    debug();
}
template<class T, class... Args>
inline void debug(const T &x, const Args &... args) {
    cerr << x << " ";
    debug(args...);
}
#else
#define dump(x) void(0)
inline void debug() {}
template<class T> inline void debug(const vector<T> &v) {}
template<class T, class... Args> inline void debug(const T &x, const Args &... args) {}
#endif
struct Fast_ios {Fast_ios() {cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20);};} fast_ios;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    const int K = 38;
    const int N = K*K-K+1;
    print(N,K);

    vector<vector<int>> ans(N, vector<int>(K));
    const int p = K-1;
    rep(i,K) {
        ans[0][i] = p*p+1+i;
        rep(j,K-1) {
            ans[i*(K-1)+1+j][0] = p*p+1+i;
        }
    }
    rep(i,p) rep(j,p) ans[i+1][j+1] = i*p+j+1;
    rep(i,p) {
        int offset = p*(i+1)+1;
        rep(j,p) {
            rep(k,p) {
                ans[(i*k+j)%p+offset][k+1] = ans[k+1][j+1];
            }
        }
    }

    rep(i,N) print(ans[i]);
}


Measured memory_bytes: 3748
#include <stdio.h>
int main(void){
  int N,A,B;
  scanf("%d %d %d",&N,&A,&B);
  int S;
  S=N*A;
  if(S>B){
    printf("%d\n",B);
  }
  else{
    printf("%d\n",S);
  }
  return 0;
}

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

int main()
{
    int n,m;
    cin >> n >> m;
    int a[n][m],b[m];
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            cin >> a[i][j];
        }
    }
    for(int i=0;i<m;i++)
    {
        cin >> b[i];
    }
    int c[n]={};
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            c[i]+=a[i][j]*b[j];
        }
        cout << c[i] << endl;
    }
}


Measured memory_bytes: 3136
#pragma region includes, macros
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <map>
#include <set>
#include <list>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <limits>

using namespace std;

typedef int64_t i64;
typedef pair<i64, i64> P;

static const i64 MOD = 1000000007;

//int dx[5] = {-1,0,0,0,1}, dy[5] = {0,-1,0,1,0};
//int dx[8] = {-1,0,1,1,1,0,-1,-1}, dy[8] = {1,1,1,0,-1,-1,-1,0};
//int dx[9] = {-1,0,1,1,1,0,-1,-1,0}, dy[9] = {1,1,1,0,-1,-1,-1,0,0};

struct edge {
    i64 from, to, cost;
    edge(i64 to, i64 cost) : from(-1), to(to), cost(cost) {}
    edge(i64 src, i64 to, i64 cost) : from(src), to(to), cost(cost) {}
};

// http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
    for (auto& e : t) fill_v(e, v);
}
//

#pragma endregion

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

int main() {
    i64 n, m;
    cin >> n >> m;
    i64 al = 1, ar = n;
    for (int i = 0; i < m; ++i) {
        i64 l, r;
        cin >> l >> r;
        al = max(l, al);
        ar = min(r, ar);
    }
    if(ar - al + 1 >= 0) cout << ar - al + 1 << endl;
    else cout << 0 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef double dnt;
template <class T> inline void read(T &x) {
	x = 0; int c = getchar(), f = 1;
	for (; !isdigit(c); c = getchar()) if (c == 45) f = -1;
	for (; isdigit(c); c = getchar()) (x *= 10) += f*(c-'0');
}
int n; dnt p[3000], f[3000][3000];
int main() {
	read(n), f[0][0] = 1;
	for (int i = 1; i <= n; i++)
		scanf("%lf", p+i);
	for (int i = 1; i <= n; i++)
		for (int j = 0; j <= i; j++) {
			if (j) f[i][j] += f[i-1][j-1]*p[i];
			if (i-j) f[i][j] += f[i-1][j]*(1-p[i]);
		}
	dnt ans = 0;
	for (int i = (n+1)/2; i <= n; i++)
		ans += f[n][i];
	return printf("%.12lf\n", ans), 0;
}


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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

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

//-----------------------------------------------------------------------------

int a,b,c,x;
int ans;

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

	cin>>a>>b>>c>>x;
	a++,b++,c++;
	REP(i,a) REP(j,b) REP(k,c) if(i*500+j*100+k*50==x) ans++;
	cout<<ans<<endl;

	return 0;
}


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

int main() {
  int n;
  cin >> n;
  std::vector<int> vec(n);
  rep(i,n) {
    cin >> vec.at(i);
  }
  int minv = 1e9;
  int ans = 0;
  rep(i,n) {
    minv = min(minv, vec.at(i));
    if (minv == vec.at(i)) {
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 4016
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
int main(){
  ll n;
  string s, t;
  cin >> n >> s >> t;
  
  ll color, ans;
  for (ll i = 0; i < n; i++) {
    if (s[i] == t[i]) {
      if (i == 0) ans = 3;
      else if (color == 1) {
        ans *= 2;
        ans %= mod;
      }
      color = 1;
    }
    else {
      if (i == 0) ans = 6;
      else if (color == 1) {
        ans *= 2;
        ans %= mod;
      }
      else {
        ans *= 3;
        ans %= mod;
      }
      color = 2;
      i++;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
module gcdMod
      implicit none
      
      !reference!
!https://blog.pixela.co.jp/2017/11/16/ユークリッドの互除法/
      
      contains
      recursive function gcd( a,b ) result( c )
        implicit none
        integer(16),intent(in) :: a,b
        integer(16) :: c,bigger,smaller
        integer(16) :: r
        
        bigger = max( a,b )
        smaller= min( a,b )
        
        r = mod(bigger,smaller)
        if( r==0 )then
          c = smaller
        else
          c = gcd( r,smaller )
        end if
      end function
      
      subroutine sort( array )
        implicit none
        integer(16),intent(inout) :: array(3)
        integer(16) :: i,j,buffer
        
        do i = 1,2
          do j = 2,3
            if( array(i)<=array(j) )then
              buffer = array(i)
              array(i) = array(j)
              array(j) = buffer
            end if
          end do
        end do
      end subroutine
        
      end module
      
      
      PROGRAM piyo
      use gcdMod
      IMPLICIT NONE
      integer(16) :: k,ans=0
      integer(16) :: a,b,c, x,y,z,buffer1
      integer(16) :: array(3),table(200,200,200)=0
      
      read*,k
      
      do x = 1,k
        do y = 1,k
          do z = 1,k
            array(1) = x
            array(2) = y
            array(3) = z
            call sort( array )
            table(array(1),array(2),array(3)) = &
              & table(array(1),array(2),array(3)) + 1
          end do
        end do
      end do
      
      
      do x = 1,k
        do y = 1,k
          do z = 1,k
            
            if(table(x,y,z)/=0)then
              buffer1 = gcd(x,y)
              ans = ans + table(x,y,z) * gcd(buffer1,z)
            end if
          end do
        end do
      end do
      
      print*,ans
      
      
      
      
      END PROGRAM

Measured memory_bytes: 66092
#include<bits/stdc++.h>
using namespace std;
long long x,k,d;
int main(){
	cin>>x>>k>>d;
	long long step=abs(x)/d,ans;
	if(step>k){
		ans=abs(x)-k*d;
	}
	else {
		if((k-step)%2==0){
			ans=abs(x)%d;
		}
		else ans=d-abs(x)%d;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3584
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
#include <cassert>
#include <memory>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
//#define MOD 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
typedef vector<tint> vtint;
typedef vector<vint> vvint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=200050;
//↑templete
signed main(){

    int N;
    cin>>N;
    vll A;
    map<ll, ll> pam;
    ll sum=0;
    for(int i=0;i<N;i++){
        int a;
        cin>>a;
        A.pb(a);
        pam[a]++;
        sum+=a;
    }

    int Q;
    cin>>Q;
    while(Q--)
    {
        ll b, c;
        cin>>b>>c;
        sum-=pam[b]*b;
        sum+=pam[b]*c;
        pam[c]+=pam[b];
        pam[b]=0;
        cout<<sum<<endl;
    }

    return 0;
}


Measured memory_bytes: 9900
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std; using ll = long long; using ld = long double;  using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vlll = vector<vll>; using vpll = vector<pll>;
using vs = vector<string>; using tll = tuple<ll, ll, ll>; using vtll = vector<tll>;
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 (b < a) { a = b; return 1; } return 0; }
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define co(i) cout << i << endl;
#define co2(i,j) cout << i << " " << j << endl;
#define co3(i) cout << i << " ";
#define po(i) cout << i.first << " " << i.second << endl;
void in() {}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.second > secondElof.second;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop, bitSearch, bitList, nod, LIS, digitDP, treeDP, Rerooting//
//gcdlcm, isPrime, eratos, primeFactorize, Npow, combination, divisor, modinv, doubling//
//dfs, bfs, dijkstra, WarshallFloyd, BellmanFord, UnionFind, Kruskal, RMQ, LCA, FordFulkerson//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R, Q, T;
ll MOD = 1000000007, INF = 1LL << 60, ans = 0, z = 0, o = 1;
vl flag, D; vector<vpll> path; vll A;
//***********//
int main() {
	ll D;
	cin >> N >> D;
	for (i = 0; i < N; i++) {
		ll x, y;
		cin >> x >> y;
		if (x * x + y * y <= D * D) ans++;
	}
	co(ans);
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
 
int main() {
  string s;
  cin >> s;
  int sum=0;
  for(int i=0;i<4;i++){
    if(s.at(i)=='+') sum++;
    else sum--;
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n;
  scanf("%d",&n);
  int i,w[n],s[n],s0=0;
  for(i=0;i<n;i++){
    scanf("%d",&w[i]);
    s0+=w[i];
    s[i]=s0;
  }
  int a=s0/2;
  i=0;
  while(s[i]<=a)i++;
  int ans=2*s[i]-s0;
  if(i==0)printf("%d",ans);
  else{
    int tmp=s0-2*s[--i];
    printf("%d",tmp<ans?tmp:ans);
  }
}
  

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

const int mn=2e5+7;
int a[mn],n,vis[mn];
vector<int> to;
long long k;

int main()
{
	scanf("%d%lld",&n,&k);
	for(int i=1;i<=n;++i) scanf("%d",a+i);
	int s=1,cnt=0;
	while(!vis[s]) cnt++,to.push_back(s),vis[s]=cnt,s=a[s];
	int lp=cnt+1-vis[s];
	if(k<cnt) {
		printf("%d",to[k]);
	}
	else {
		k-=cnt;
		k%=lp;
		printf("%d",to[vis[s]+k-1]);
	}
}

Measured memory_bytes: 5800
N, Y = [int(x) for x in input().split()]

for x in range(Y // 10000 + 1): # 1万円札の枚数
    for y in range((Y - 10000 * x) // 5000 + 1): # 5千円札の枚数
        if 10000 * x + 5000 * y + 1000 * (N - x - y) == Y:
            print(x, y, N - x - y)
            break
    else:
        continue
    break
else:
    print(-1, -1, -1)

Measured memory_bytes: 9192
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.IO;


namespace SolutionCS
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split('/');
            int y = int.Parse(s[0]);
            int m = int.Parse(s[1]);
            int d = int.Parse(s[2]);

            string ans = "TBD";

            if (y < 2019)
            {
                Console.WriteLine("Heisei");
                return;
            }
            if ( y > 2019)
            {
                Console.WriteLine("TBD");
                return;
            }

            if ( m <= 4)
            {
                Console.WriteLine("Heisei");
                return;
            }

            Console.WriteLine("TBD");
        }
    }
}


Measured memory_bytes: 11092
N = int(input())
sticks = dict()
for a in map(int, input().split()):
    sticks[a] = sticks.get(a, 0) + 1
sticks = sorted([(k, v) for k, v in sticks.items() if v >= 2], reverse=True)
if len(sticks) == 0 or (len(sticks) == 1 and sticks[0][1] < 4):
    print(0)
elif sticks[0][1] >= 4:
    print(sticks[0][0] ** 2)
else:
    print(sticks[0][0] * sticks[1][0])


Measured memory_bytes: 23692
#include <iostream>
#include <cmath>
using namespace std;
typedef double D;

const D rd = M_PI/180.0;
const D r = 6378.1;

int solve(D y1, D x1, D y2, D x2){
    D x = abs(x1-x2); if(x > 180.0) x = 360.0 - x;
    D d = r * acos(sin(y1*rd)*sin(y2*rd) + cos(y1*rd)*cos(y2*rd) * cos(x*rd));
    return (int)(d + 0.5);
}

int main(){
    D a,b,c,d;
    while(cin >> a >> b >> c >> d){
        if(a < 0 && b < 0 && c < 0 && d < 0) break;
        cout << solve(a,b,c,d) << endl;
    }
    return 0;
}

Measured memory_bytes: 1288
def i():
	return int(input())
def i2():
	return map(int,input().split())
def s():
	return str(input())
def l():
	return list(input())
def intl():
	return list(int(k) for k in input().split())

a,b,c,k = i2()
if k%2 == 0:
	print(a - b)
else:
	print(b - a)

Measured memory_bytes: 9052
#include <bits/stdc++.h>
using namespace std;
    #define fio ios_base::sync_with_stdio(false), cin.tie(NULL)
    #define ll long long
    #define int long long 
    #define ull unsigned long long 
    #define ld long double
    #define sb __builtin_popcount
    #define vi vector<int>
    #define vc vector<char>
    #define ii pair<int, int>
    #define pq priority_queue<ii, vector<ii>, greater<ii>>
    #define vii vector<ii>
    #define sz(a) int((a).size())
    #define f(a, b) for (int i = a; i < b; i++)
    #define fr(a, b) for (int i = a - 1; i >= b; i--)
    #define tr(x, m) for (auto x : m)
    #define in(a, b) (b.find(a) != string::npos)
    #define minin(a) *min_element(all(a))
    #define maxin(a) *max_element(all(a))
    #define X first
    #define Y second
    #define fill(a, x) memset(a, x, sizeof(a))
    #define pb push_back
    #define pf push_front
    #define mp make_pair
    #define all(v) v.begin(), v.end()
    #define rall(v) reverse(v.begin(), v.end())
    #define unq(v) v.erase(unique(all(v)), v.end())
    #define el "\n"
    #define mx3(a, b, c) max(max(a, b), c)
    #define mn3(a, b, c) min(min(a, b), c)
    #define S(v) accumulate(all(v), (ll)0)
    #define SP(n) cout.precision(n)
    const ld PI = atan(1.0) * 4.0;
    const ll MOD = 1e9 + 7;
    const ll INF = 1e18;
    const ld EPS = 0.0000001;
    const ll MD = 998244353;
    
    int32_t main() {
        fio;
        string a,b;
        cin>>a>>b;
        for(int i=0;i<a.size();i++){
            if(a[i]!=b[i]){
                cout<<"No";
                return 0;
            }
        }
        cout<<"Yes";
        return 0;
    }


Measured memory_bytes: 3612
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define fi first
#define se second
ll sieve[1000001]={0},i,j;
ll power(ll p, ll k)
{
ll a=1;
while(k)
{
if(k&1)
a=(a*p);
p=(p*p);
k>>=1;
}
return a;
}
using namespace std;
  ll countDivisors(ll n) 
{ 
    ll cnt = 0; 
    for (ll i = 1; i <= sqrt(n); i++) { 
        if (n % i == 0) { 
            if (n / i == i) 
                cnt++; 
  
            else 
                cnt = cnt + 2; 
        } 
    } 
    return cnt; 
} 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 int tc=1;
//cin>>tc;
ll cas=1;
 while(tc--)
 {
	 ll n;
	 string s;
	 cin>>n;
	 cin>>s;
	 ll ans=0;
	 ll r[n+1]={0},g[n+1]={0},b[n+1]={0};
	 for(i=n-1;i>=0;i--)
	 {
		 if(s[i]=='R')
		 r[i]=r[i+1]+1;
		 else
		 r[i]=r[i+1];	
		  if(s[i]=='G')
		 g[i]=g[i+1]+1;
		 else
		 g[i]=g[i+1];  
	      if(s[i]=='B')
		 b[i]=b[i+1]+1;
		 else
		 b[i]=b[i+1];
	 }
	 for(i=0;i<n;i++)
	 for(j=i+1;j<n;j++)
	 {
		 if((s[i]=='R' && s[j]=='G')|| (s[i]=='G' && s[j]=='R'))
		 {
			 ans+=b[j+1];
			 if((2*j-i)<n && s[2*j-i]=='B' && b[j+1])
			 ans--;
		 }
	  else if((s[i]=='R' && s[j]=='B')|| (s[i]=='B' && s[j]=='R'))
		 {
			 ans+=g[j+1];
			 if((2*j-i)<n && s[2*j-i]=='G' && g[j+1])
			 ans--;
		 }
	else if((s[i]=='B' && s[j]=='G')|| (s[i]=='G' && s[j]=='B'))
		 {
			 ans+=r[j+1];
			 if((2*j-i)<n && s[2*j-i]=='R' && r[j+1])
			 ans--;
		 }
	 }
	 cout<<ans;
	 	   cout<<"\n"; 
 } 
}


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

int main()
{
  int X,Y,Z ;
  cin>>X>>Y>>Z ;
  
  int num ;
  for(num=1;;num++){
    if(X-num*Y-(num+1)*Z==0){
      cout<<num<<endl ;
      return 0 ;
    }else if(X-num*Y-(num+1)*Z<0) break ;
  }
  cout<<num-1<<endl ;
  return 0 ;
}

Measured memory_bytes: 256
//buttons
#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
	int a,b;
	cin>>a>>b;
	int sum = 0;
	for (int i = 0; i < 2; ++i)
	{
		if (a > b)
		{
			sum += a;
			a--;
		}else{
			sum += b;
			b--;
		}
	}
	cout<<sum<<endl;
	return 0;
}

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

using ll = long long;
#define REP(i,n) for(int i = 0;i < n;i++)
#define debug(arr) cout << #arr << " = " << arr << '\n';
template<class T> ostream &operator << (ostream& out, const vector<T>& arr) {
	cout << "{";
	for (int i = 0; i < arr.size(); i++)cout << (!i ? "" : ", ") << arr[i];
	cout << "}";
	return out;
}
template<class T> ostream &operator << (ostream& out, const vector<vector<T> >& arr) {
	cout << "{\n";
	for (auto& vec : arr)cout << "  " << vec << ",\n";
	cout << "}";
	return out;
}
template<class T> istream &operator >> (istream& in, vector<T>& arr) {
	for (auto& i : arr)cin >> i; return in;
}

int n, k;
string s;

bool all_same(string& s) {
	for (int i = 0; i < n; i++) {
		if (s[i] != s[0])return false;
	}
	return true;
}
string func(string& s) {
	string t = s; reverse(t.begin(), t.end());
	s += t;
	vector<string> f(n + 1);
	for (int i = 0; i <= n; i++)f[i] = s.substr(i, n);
	for (int i = 0; i <= n; i++)reverse(f[i].begin(), f[i].end());
	string res = *min_element(f.begin(), f.end());
	reverse(res.begin(),res.end());
	return res;
}
string get_ans(string& s){
	string t = s; reverse(t.begin(), t.end());
	s += t;
	vector<string> f(n + 1);
	for (int i = 0; i <= n; i++)f[i] = s.substr(i, n);
	string res = *min_element(f.begin(), f.end());
	return res;
}
int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n >> k >> s;

	REP(i, k - 1) {
		if (all_same(s)) {
			break;
		} else {
			s = func(s);
		}
	}
	if(!all_same(s)){
		s = get_ans(s);
	}

	cout << s << '\n';
	return 0;
}


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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 11451419194545;

int main() { 

    ll N, Q;
    string S;
    cin >> N >> S >> Q;
    S = S;
    //cout << S << endl;
    //26文字分Setを用意してアルファベットの現れる位置を管理する
    //初期化->番兵追加
    vector<set<ll > > D(26, set<ll >({-1, INF}));
    //setに追加
    for(ll i = 0; i < N; i++){
        D[S[i]-'a'].insert(i);
    }

    vector<ll > ans;
    for(ll i = 0; i < Q; i++){
        ll t; cin >> t;
        if(t == 1){
            ll idx;
            char to_ch;
            cin >> idx >> to_ch;
            idx--;
            //検索->ないものを探そうとするととんでもないことになる（ミスった）
            D[S[idx] - 'a'].erase(idx);
            D[to_ch - 'a'].insert(idx);
            S[idx] = to_ch;
            //cout << S << endl;
        }else{
            //cout << S << endl;
            ll s, e; cin >> s >> e;
            ll cn = 0;
            --s;
            for(ll j = 0; j < 26; j++){
                if(D[j].empty()) continue;
                ll st = *D[j].lower_bound(s);
                ll et = *D[j].lower_bound(e);
                if(et > st){
                    cn++;
                }
                //cout << st << " " << et << endl;
            }
            ans.push_back(cn);
            //cout << cn << endl;
        }
    }

    for(ll i = 0; i < ans.size(); i++){
        cout << ans[i] << endl;
    }

}

Measured memory_bytes: 24708