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

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef unordered_set<int> si;
typedef pair<int, int> pp;
typedef vector<pp> vpp;
typedef unsigned int i64;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#define all(e) (e).begin(), (e).end()
#define pb push_back

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

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


template <typename T>
void printV(vector<T> A) {
  if (A.empty()) cerr << "EMTPY\n";
  else { 
    cerr << "[";
    for (int i = 0; i < A.size() -1 ; ++i) {
      cerr << A[i] << ", ";
    }
    if (A.size()) cerr << A.back() << "]\n";
  }
}


template <typename T>
void printVV(vector<vector<T>> A) {
  cerr << "[";
  for (auto v : A) {
    printV<T>(v);
  }
  cerr << "]";
}

template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << ": " << arg1 << endl;
}

template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&& ...args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

int main(int argc, char **argv) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,m; cin >> n >> m;
  vi a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a.begin(),a.end(),greater<int>());

  double target = accumulate(a.begin(),a.end(),0) * 1.0 / (4*m);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] < target) continue;
    ans += 1;
  }

  if (ans < m) cout << "No\n";
  else cout << "Yes\n";
  return 0;
}



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

int main() {
    double l;
    cin >> l;
    cout << fixed << setprecision(6) << l * l * l / 27 << endl;
    return 0;
}


Measured memory_bytes: 3772
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
cnt=0
for i in range(n):
  if a[i]>=b[i]:
    cnt+=b[i]
  elif a[i]+a[i+1]>=b[i]:
    cnt+=b[i]
    a[i+1]-=(b[i]-a[i])
  else:
    cnt+=a[i]+a[i+1]
    a[i+1]=0
print(cnt)


Measured memory_bytes: 18468
#include <bits/stdc++.h>
using namespace std;
int main() {
int N,A,B;
cin >> N >> A >> B;
int ans = 0;
for (int j = 1;j <= N;j++) {
  int i = j;
  int cnt = 0,a;
  a = i / 10000;
  cnt += a;
  i = i - a * 10000;
  a = i / 1000;
  cnt += a;
  i = i - a * 1000;
  a = i / 100;
  cnt += a;
  i = i - a * 100;
  a = i / 10;
  cnt += a;
  i = i - a * 10;
  cnt += i;
  if (cnt >= A && cnt <=B) ans += j;
}
cout << ans << endl;


return 0;
}

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

using namespace std;

void solve()
{
	string str;
	char c;
	while(cin >> str)
	{
		cin >> c;
		string Answer;
		int size = str.size();
		if(c == 'X')
		{
			break;
		}
		else if(c == 'L')
		{
			if('A' <= str[0] && str[0] <= 'Z')
			{
				Answer += str[0] - 'A' + 'a';
			}
			else if('a' <= str[0] && str[0] <= 'z')
			{
				Answer += str[0];
			}
			bool flag = false;
			for(int i = 1; i < size; ++i)
			{
				if(str[i] == '_')
				{
					flag = true;
					continue;
				}
				if(flag && 'a' <= str[i] && str[i] <= 'z')
				{
					Answer += str[i] - 'a' + 'A';
					flag = false;
					continue;
				}
				Answer += str[i];
				flag = false;
			}
		}
		else if(c == 'U')
		{
			if('A' <= str[0] && str[0] <= 'Z')
			{
				Answer += str[0];
			}
			else if('a' <= str[0] && str[0] <= 'z')
			{
				Answer += str[0] - 'a' + 'A';
			}
			bool flag = false;
			for(int i = 1; i < size; ++i)
			{
				if(str[i] == '_')
				{
					flag = true;
					continue;
				}
				if(flag && 'a' <= str[i] && str[i] <= 'z')
				{
					Answer += str[i] - 'a' + 'A';
					flag = false;
					continue;
				}
				Answer += str[i];
				flag = false;
			}
		}
		else if(c == 'D')
		{
			if('A' <= str[0] && str[0] <= 'Z')
			{
				Answer += str[0] - 'A' + 'a';
			}
			else if('a' <= str[0] && str[0] <= 'z')
			{
				Answer += str[0];
			}
			for(int i = 1; i < size; ++i)
			{
				if(str[i] == '_')
				{
					Answer += '_';
					continue;
				}
				if('A' <= str[i] && str[i] <= 'Z')
				{
					Answer += '_';
					Answer += str[i] - 'A' + 'a';
					continue;
				}
				Answer += str[i];
			}
		}
		cout << Answer << endl;
	}
}

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

Measured memory_bytes: 0
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using P = pair<ll,ll>;
using um = unordered_map<ll,ll>;
#define fl cout<<flush;
#define endl '\n'
template <typename T> inline void prt(T v){cout<<v<<'\n';}
template <typename T> inline bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> inline bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=(ll)1e9+7;
const ll MOD2=998244353;
const ld pi=3.14159265358979323846;
const ld eps=1e-10;

//すべて半閉区間で扱う
struct cBIT {
  vector<ll> v;
  ll n;
  cBIT(ll n) : n(n), v(n) {}
  void add(ll i, ll x) {
    i++;
    while (i <= n) {
      v[i - 1] += x;
      i += i & -i;
    }
  }
  ll sum(ll i) {
    ll r = 0;
    while (i >= 1) {
      r += v[i - 1];
      i -= i & -i;
    }
    return r;
  }
  ll sum(ll l, ll r){
    if(l>=r)return 0;
    return sum(r)-sum(l);
  }
  ll get(ll i){return sum(i+1)-sum(i);}
};
 
struct BIT {
  cBIT p, q;
  BIT(ll n) : p(n + 1), q(n + 1) {}
  void add(ll l, ll r, ll w) {
    p.add(l, -w * l);
    p.add(r, w * r);
    q.add(l, w);
    q.add(r, -w);
  }
  void add(ll i, ll w){
    add(i,i+1,w);
  }
  ll sum(ll r) {
    return p.sum(r) + q.sum(r) * r;
  }
  ll sum(ll l, ll r){
    if(l>=r)return 0;
    return sum(r)-sum(l);
  }
  ll get(ll i){return sum(i+1)-sum(i);}
};
//↑すべて半閉区間で扱う

signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll Q;
    cin >> Q;
    vector<ll> c(N,0);
    for(ll i=0;i<N;++i){cin>>c[i];c[i]--;}
    vector<ll> l(Q,0);
    vector<ll> r(Q,0);
    for(ll i=0;i<Q;++i){cin>>l[i]>>r[i];l[i]--;r[i]--;}
    vector<ll> last(N,-1);
    BIT tree(N);
    vector<vector<P>> ans(N, vector<P>(0));
    for(ll i=0;i<Q;++i){
        ans[r[i]].emplace_back(P(i,l[i]));
    }
    vector<ll> kotae(Q,0);
    for(ll i=0;i<N;++i){
        ll from=last[c[i]];
        last[c[i]]=i;
        ll to=i;
        if(from!=-1)
        tree.add(from,-1);
        tree.add(to,1);
        for(auto p: ans[i]){
            kotae[p.first]=tree.sum(p.second,N);
        }
    }
    for(auto p: kotae)prt(p);


    return 0;
}



Measured memory_bytes: 55964
#include<bits/stdc++.h>
using namespace std;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, t, a, ans; cin >> n >> t >> a;
    double mini = 1e9;
    for(int i = 0; i < n; ++i) {
        double x; cin >> x;
        double deff = abs(a - (t - x * 0.006));
        if(deff < mini) {
            ans = i+1;
            mini = deff;
        }
    }cout << ans;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <array>

using vector = std::vector<int>;
using iterator = std::vector<int>::iterator;

int dp[25][2005];
vector as;

bool solve(int i, int m)
{
  if (dp[i][m] != -1)
    return dp[i][m];

  if(i >= as.size())
    {
      return m == 0;
    }

  dp[i][m] = solve(i+1, m) || solve(i+1, m - as[i]);

  return dp[i][m];
}


int main ()
{
  int n, q;

  for (int i=0; i<25; ++i)
    {
      for (int j=0; j<2005; ++j)
        dp[i][j] = -1;
    }

  std::cin >> n;
  for (int i=0; i<n; i++)
    {
      int tmp;
      std::cin >> tmp;
      as.push_back(tmp);
    }
  std::cin >> q;

  int m;
  for (int i=0; i<q; i++)
    {
      std::cin >> m;
      if (solve(0, m))
        std::cout << "yes" << std::endl;
      else
        std::cout << "no" << std::endl;
    }
}



Measured memory_bytes: 3352
import math
import sys

# print('input >>')
N = int(input())

if N % 2 == 1 or N == 0:
    print(0)
    sys.exit()

ans = 0
warusu = math.log(N, 5)
warusu = int(warusu)

for i in range(warusu):
    ans += (N // (5 ** (i+1))) // 2

# print('-----output-----')
print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <string>
#include <string.h>
#include <queue>
#include <math.h>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <bitset>
#include <list>
#include <ctype.h>
#include <cassert>
#include <stack>
#include <fstream>
#include <unordered_map>
#include <unordered_set>
#include <ctime>
#include <functional>
#include <ctime>
#include <limits>
#include <tuple>
#include <complex>
#include <numeric>
#include <future>

using namespace std;

#define snd second
#define fst first
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define left _left
#define right _right

const ld pi = acos(-1.0);

template<typename T>
T abs(T x) {
    return x > 0 ? x : -x;
}

template<typename T>
T sqr(T x) {
    return x * x;
}

template<typename T>
bool chmin(T &x, T y) {
    if (x > y) {
        x = y;
        return true;
    }
    return false;
}

template<typename T>
bool chmax(T &x, T y) {
    if (x < y) {
        x = y;
        return true;
    }
    return false;
}

template<typename U, typename V>
ostream &operator<<(ostream &s, const pair<U, V> &x) {
    s << "(" << x.fst << ", " << x.snd << ")";
    return s;
}

template<typename U>
ostream &operator<<(ostream &s, const vector<U> &x) {
    s << "[";
    bool was = false;
    for (auto it : x) {
        if (was) {
            s << ", ";
        }
        was = true;
        s << it;
    }
    s << "]";
    return s;
}

template<typename U>
ostream &operator<<(ostream &s, const set<U> &x) {
    s << "{";
    bool was = false;
    for (auto it : x) {
        if (was) {
            s << ", ";
        }
        was = true;
        s << it;
    }
    s << "}";
    return s;
}

template<int sz>
ostream operator<<(ostream &s, const bitset<sz> &x) {
    for (int i = 0; i < sz; i++) {
        s << x[i];
    }
    return s;
}


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

string s;

const int maxn = 305;

int dp[maxn][maxn][maxn];

int f(int l, int r, int k) {
    if (l > r) {
        return 0;
    }
    if (dp[l][r][k] != -1) {
        return dp[l][r][k];
    }

    int& res = dp[l][r][k];
    res = 0;

    if (l == r) {
        return res = 1;
    } else if (s[l] == s[r]) {
        chmax(res, 2 + f(l + 1, r - 1, k));
    } else if (k) {
        chmax(res, 2 + f(l + 1, r - 1, k - 1));
    }
    chmax(res, f(l + 1, r, k));
    chmax(res, f(l, r - 1, k));
    return res;
}



int main() {

    srand(time(NULL));

#ifdef LOCAL
    //gen();
    freopen("a.in", "r", stdin);
    //freopen("a.in", "w", stdout);
#else
    //freopen("brackets.in", "r", stdin);
    //freopen("brackets.out", "w", stdout);
#endif


    cin >> s;
    for (int i = 0; i < maxn; i++) {
        for (int j = 0; j < maxn; j++) {
            for (int h = 0; h < maxn; h++) {
                dp[i][j][h] = -1;
            }
        }
    }
    int k;
    cin >> k;
    cout << f(0, s.size() - 1, k) << endl;

    return 0;
}

Measured memory_bytes: 111232
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MAXN 1000010
#define rep(i,n) for (int i = 0; i < (n); ++i)
const ll mod = 1e9+7;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

bool pairCompare(const P& firstElof, const P& secondElof)
{
    return firstElof.second < secondElof.second;
}

int main() {
    ll n, a, b;

    cin >> n >> a >> b;

    ll ab = a+b;

    ll ans = a*(n / ab);

    rep(i, min(a, n%ab)) {
        ans++;
    }

    cout << ans << endl;
}



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

int main() {
  int N;
  cin >> N;
  
  int l;
  int r;
  int sum = 0;
  
  for(int i = 0;i<N;i++){
	cin >> l >> r;
    sum = sum + r-l +1;
  }
	cout << sum;  
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	if(a <= b && b <= c){
		printf("%d %d %d", a, b, c);
	}else if(a <= c && c <= b) {
		printf("%d %d %d", a, c, b);
	}else if(b <= a && a <= c) {
		printf("%d %d %d", b, a, c);
	}else if(b <= c && c <= a) {
		printf("%d %d %d", b, c, a);
	}else if(c <= a && a <= b) {
		printf("%d %d %d", c, a, b);
	}else if(c <= b && b <= a) {
		printf("%d %d %d", c, b, a);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <vector>
#include <cassert>
#include <cstdlib>

class Hamburger {
  public:
    long long size;
    long long point;
};

int main()
{
  long long level, x;
  std::cin >> level >> x;
  std::vector<Hamburger> hamburger(level);
  hamburger.at(0).size  = 1;
  hamburger.at(0).point = 1;
  for (int i = 1; i < (int)hamburger.size(); i++) {
    hamburger.at(i).size = hamburger.at(i-1).size * 2 + 3;
    hamburger.at(i).point = hamburger.at(i-1).point * 2 + 1;
  }
  long long total_point = 0;
  long long rest = x;
  for (auto it = hamburger.rbegin(); it != hamburger.rend(); it++) {
    long long size = it->size;
    long long point = it->point;
    if (1 == rest) {
      break;
    } else if (1 < rest && rest <= size+1) {
      rest -= 1;
      if (size == 1) {
        total_point++;
        break;
      }
      continue;
    } else if (size+2 == rest) {
      total_point += point + 1;
      break;
    } else if (size+2 < rest && rest <= 2*size+2) {
      total_point += point + 1;
      rest -= size + 2;
      if (size == 1) {
        total_point++;
        break;
      }
      continue;
    } else if (2*size+3 == rest) {
      total_point += 2 * point + 1;
      break;
    } else {
      std::cerr << "Unexpected rest\n";
      exit(1);
    }
  }
  std::cout << total_point << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cctype>

using namespace std;

int a, b, c;
int ans;

int main() {

	cin >> a >> b >> c;
	if (a < b) {
		swap(a, b);
	}
	if (b < c) {
		swap(b, c);
	}
	if (a < b) {
		swap(a, b);
	}
	a = a * 10;
	ans = a + b + c;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
int y[50],r,n;

bool check(double cy){
  double x=sqrt(r*r-cy*cy);
  if(cy>=0)x=r;
  int L=-x-0.9999,R=x+0.9999,hb[101]={};

  for(int i=L+25;i<R+25;i++){
    int x1=i-24-i/25;
    double y1=y[i]-cy;
    if(x1*x1+y1*y1>=r*r)hb[i]++;
  }
  for(int i=L+25;i<R+25;i++)if(!hb[i])return 0;
  return 1;
}

int main(){
  while(1){
    cin>>r>>n;
    if(!r&&!n)break;
    for(int i=0;i<50;i++)y[i]=0;

    for(int i=0;i<n;i++){
      int x1,x2,h;
      cin>>x1>>x2>>h;
      for(int j=x1;j<x2;j++) y[j+25]=max(y[j+25],h);
    }
    double ans=0;
    while(check(ans-r))ans+=0.0009;
    cout << ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1244
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
//~ #define MOD 1000000007
#define MOD 1000003
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

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

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
template<class T> using V=vector<T>; 
#define all(v) (v).begin(),(v).end()
const ll mod=1000000007;
struct mint{
    using ull=unsigned long long int;
    ull v;
    mint(ll vv=0){s(vv%mod+mod);}
    mint& s(ull vv){
        v=vv<mod?vv:vv-mod;
        return *this;
    }
    //オーバーロード
    mint operator-()const{return mint()-*this;}//符号反転
    mint&operator+=(const mint&val){return s(v+val.v);}
    mint&operator-=(const mint&val){return s(v+mod-val.v);}
    mint&operator*=(const mint&val){
        v=ull(v)*val.v%mod;
        return *this;
    }
    mint&operator/=(const mint&val){return *this*=val.inv();}
    mint operator+(const mint&val){return mint(*this)+=val;}
    mint operator-(const mint&val){return mint(*this)-=val;}
    mint operator*(const mint&val){return mint(*this)*=val;}
    mint operator/(const mint&val){return mint(*this)/=val;}
    mint pow(int n)const{
        mint res(1),x(*this);
        while(n){
            if(n&1)res*=x;
            x*=x;
            n>>=1;
        }
        return res;
    }
    mint inv()const{return pow(mod-2);}
    //拡張ユークリッドの互除法
    /* mint inv()const{
        int x,y;
        int g=extgcd(v,mod,x,y);
        assert(g==1);
        if(x<0)x+=mod;
        return mint(x);
    }*/
    friend ostream& operator<<(ostream&os,const mint&val){
        return os<<val.v;
    }//出力
    bool operator<(const mint&val)const{return v<val.v;}
    bool operator==(const mint&val)const{return v==val.v;}
    bool operator>(const mint&val)const{return v>val.v;}
};
const ll MAX = 2000010;//設定
mint fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void init(){
    fac[0] = fac[1] = 1;
    for(int i=1;i<MAX;i++)fac[i]=fac[i-1]*i;
    finv[MAX-1]=fac[MAX-1].inv();
    for(int i=MAX-2;i>=0;i--)finv[i]=finv[i+1]*(i+1);
    for(int i=MAX-2;i>=1;i--)inv[i]=finv[i]+fac[i-1];
}
//階乗
mint factor(ll n,ll k){
  if (n<k) return 0;
  if (n<0 || k<0) return 0;
  return fac[n]*finv[k];
}
// 二項係数計算
mint COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * finv[k] * finv[n - k];
}
int main(){
 int n,k;
 cin>>n>>k;
 mint ans=0;
 init();
 V<ll> d(n); 
 for(int i=0;i<n;i++)cin>>d[i];
 sort(all(d));
 mint cnt=0;
 for(int i=0;i<n-k+1;i++){
        ans-=mint(d[i])*COM(n-i-1,k-1);
 }
reverse(all(d));
for(int i=0;i<n-k+1;i++){
        ans+=mint(d[i])*COM(n-i-1,k-1);
 }
cout<<ans<<endl;
}



Measured memory_bytes: 47872
/* ABC168_C
    Stuartyg */

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>
int snowfall(int a, int b);

int main(void){
        int west_height,east_height; /*a,bのこと*/
        scanf("%d %d",&west_height,&east_height); /*標準入力から受け取る*/

        printf("%d\n",snowfall(west_height,east_height));
        /*関数snow_fallにwest_heightの値とeast_heightの値を代入*/
        return 0;
}

int snowfall(int a, int b){
        int snow_amount; /*求める積雪量*/
        
        /*与えられた西側の塔が西からi番目にあるとすると、東側の塔との高さの差b-a = i+1
        だから、本来の西側の塔の高さは
        1/2* i * (i+1) = (b-a-1) * (b-a) / 2
        よって雪が積もった高さは　（本来の高さ）- a*/

        snow_amount = (b-a-1) * (b-a) / 2 - a;
        return snow_amount;
}


Measured memory_bytes: 128
import sys
# def input(): return sys.stdin.readline().rstrip()
# input = sys.stdin.readline
input = sys.stdin.buffer.readline

N = int(input())
A = sorted(zip(map(int, (input().split())) ,range(N)), reverse=True)

dp = [[0]*(N+1) for _ in range(N+1)]
ans = 0
for i in range(N):
    for j in range(i+1):
        dp[i+1][j]   = max(dp[i+1][j], dp[i][j] + A[i][0] * abs(A[i][1] - (N-1-(i-j))))
        dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] + A[i][0] * abs(A[i][1] - j))

for i in range(N):
    ans = max(ans, dp[N][i])

print(ans)


Measured memory_bytes: 100372
import math

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

def run():
    n, p = map(int, input().split())
    l = factorization(p)
    ans = 1
    for e in l:
        num, count = e
        t = count // n
        if t > 0:
            ans *= num ** t
    print(ans)

if __name__ == '__main__':
    run()


Measured memory_bytes: 9476
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF LLONG_MAX/10
#define rep(i,n) for(int i=0;i<n;i++)
#define krep(i,k,n,m) for(int i=k;i<n;i+=m)
#define erep(i,k,n) for(int i=k;i<n;i++)
#define mod 1000000007
//最大公約数
int gcd(int s,int b){
    if(b==0)return s;
    return gcd(b,s%b);
}
signed main(){
    int n;
    cin>>n;
    int a[n],b[n],c,d;
    rep(i,n){
        cin>>a[i];
        b[i]=a[i];
    }
    sort(b,b+n);
    c=b[n/2-1];
    d=b[n/2];
    rep(i,n){
        if(a[i]>=d){
            cout<<c<<endl;
        }
        else{
            cout<<d<<endl;
        }
    }
}


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

int gcd(int x , int y){
  if(x < y){
    swap(x,y);
  }
  if(y == 0){
    return x;
  }
  return(gcd(x%y , y));
}

int main(){
  int n;
  cin >> n;
  
  vector<int> cont(n+1),a(n),b(n);
  
  for(int i = 0 ; i < n ; i++){
    cin >> cont.at(i);
  }

  for(int i = 0 ; i < n-1 ; i++){
    a.at(i+1) = gcd(cont.at(i) , a.at(i));
  }
  for(int i = n-1 ; i >= 1 ; i--){
    b.at(i-1) = gcd(cont.at(i),b.at(i));
  }
  
  int ans = 0;
  for(int i = 0 ; i < n ; i++){
    ans = max(ans,gcd(a.at(i),b.at(i)));
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 1408
n, m, l = gets.split(" ").map(&:to_i)

a = []
b = []

for i in 1..n
  a.push(gets.split(" ").map(&:to_i))
end

for i in 1..m
  b.push(gets.split(" ").map(&:to_i))
end

for i in 0..n-1
  rr = []
  for k in 0..l-1
    d = 0
    for j in 0..m-1
      d += a[i][j] * b[j][k]
    end
    rr.push(d)
  end
  puts rr.join(" ")
end



Measured memory_bytes: 9176
import sys
input = sys.stdin.readline

L = int(input())
ans = [[1,2,0],[1,2,1]]#L=2の答え
S=1
T=2
def recursion(x):
    global T
    if x == 2:
        return
    
    if x%2==1:
        recursion(x-1)
        ans.append([S,T,x-1])
        
    else:
        recursion(x//2)
        for i in range(len(ans)):
            ans[i][2] = 2*ans[i][2]
        T += 1
        ans.append([T-1,T,0])
        ans.append([T-1,T,1])
    return

recursion(L)
print(T,len(ans))
for i,j,k in ans:
    print(i,j,k)
        




Measured memory_bytes: 3064
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func oneInt() int {
	var a int
	fmt.Scan(&a)
	return a
}
func oneStr() string {
	var a string
	fmt.Scan(&a)
	return a
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func scanNums() (nums []int) {
	s := nextLine()
	numStr := strings.Split(s, " ")

	for _, n := range numStr {
		i, _ := strconv.Atoi(n)
		nums = append(nums, i)
	}
	return nums
}

func scanStrings() (strs []string) {
	s := nextLine()
	list := strings.Split(s, " ")
	strs = append(strs, list...)
	return strs
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func sortAsc(a []int) []int {
	sort.Ints(a)
	return a
}

func sortDesc(a []int) []int {
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	return a
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	if a == 0 && b == 0 {
		return 0
	}
	return a * b / gcd(a, b)
}


func main() {
	N := oneInt()
	var nums []int
	for index := 0; index < N; index++ {
		nums = append(nums, oneInt())
	}

	var counter = 0
	for i := 1; i < N-1; i++ {
		var target = nums[i]
		if target < nums[i-1] {
			if target > nums[i+1] {
				counter++
			}
		}

		if target > nums[i-1] {
			if target < nums[i+1] {
				counter++
			}
		}
	}

	fmt.Print(counter)

}


Measured memory_bytes: 640
a = input()
b = int(a[:2])
c = int(a[2:])
def judge(num):
  if num > 0 and num <= 12:
    return True
  else:
    return False
if judge(b) and judge(c):
  print("AMBIGUOUS")
elif judge(b):
  print("MMYY")
elif judge(c):
  print("YYMM")
else:
  print("NA")

Measured memory_bytes: 38384
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a = LI()
    a.sort()
    print(a[0]*a[1]//2)  
    return

#B
def B():
    d = defaultdict(int)
    s = II()
    def f(n):
        if n % 2:
            return 3 * n + 1
        return n // 2
    i = 1
    while not d[s]:
        d[s] = 1
        s = f(s)
        i += 1
    print(i)
    return

#C
def C():
    n = II()
    h = LI()
    ans = h[0]
    for i in range(n - 1):
        ans += max(0, h[i + 1] - h[i])
    print(ans)
    return

#D
def D():
    return

#Solve
if __name__ == '__main__':
    C()


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

int main(){
  int n,ans;
  cin >> n;
  vector<int> a(n);
  for(int i = 0;i < n;i++){
    cin >> a.at(i);
  }
  int maxA,cnt;
  maxA = 0; cnt = 0;
  for(int i = 0;i < n;i++){
    if(maxA == a.at(i)){
      cnt++;
    }else if(maxA < a.at(i)){
      cnt = 1;
      maxA = a.at(i);
    }
  }
  
  vector<int> b(n);
  b = a;
  sort(b.begin(),b.end());
  reverse(b.begin(),b.end());

  for(int i = 0;i < n;i++){
    if(a.at(i) < maxA){
      cout << maxA << endl;
    }else if(a.at(i) == maxA && cnt > 1){
      cout << maxA << endl;
    }else{
      cout << b.at(1) << endl;
    }
  }

    return 0;
}

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

int main(){
    int w, a, b; cin >> w >> a >> b;
    if (a==b){
        cout << 0 << endl;
    } else if (a<b){
        if (b<=a+w){
            cout << 0 << endl;
        } else {
            cout << b-(a+w) << endl;
        }
    } else {
        if (a<=b+w){
            cout << 0 << endl;
        } else {
            cout << a-(b+w) << endl;
        }
    }
}

Measured memory_bytes: 3552
#include <bits/stdc++.h>
#pragma GCC optimize("O3")

#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define mp make_pair
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define endl '\n'

#define si(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) 
#define rep2(i, n, m) for (ll i = n; i <= (ll)(m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (ll)(m); --i)

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

using ll = long long;
using ld = long double;
using namespace std;

constexpr ll MOD = 1000000007;

signed main()
{
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);

  map<int,int> s;

  rep(i, 3) {
    int a, b; cin >> a >> b;
    ++s[a];
    ++s[b];
  }

  int cnt = 0;
  for (auto c : s) if (c.se >= 2) ++cnt;

  if (cnt >= 2) cout << "YES\n";
  else cout << "NO\n";

  return (0);
}


Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main()
{
	string s, p;
	int count = 0;
	cin >> s;
	transform(s.begin(), s.end(), s.begin(), ::tolower);

	while (cin >> p) {
		transform(p.begin(), p.end(), p.begin(), ::tolower);
		if (p == "END_OF_TEXT") {
			break;
		}
		if (s == p) {
			count++;
		}
	}
	cout << count << endl;
	return 0;
}

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

using namespace std;

int main()
{
    int dis[5],k;
    for(int i=0;i<5;++i){cin>>dis[i];}
    cin>>k;
    int flag=1;
    for(int i=0;i<5&&flag;++i)
    {
        for(int j=i+1;j<5&&flag;++j)
        {
            if(abs(dis[i]-dis[j])>k){flag=0;}
        }
    }
    puts(flag?"Yay!":":(");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}


/*
[check]条件の見逃し
最終系はTTTSSSになる
STTSTTS => TTS
何回消去が起きるか
TSSSTTS
T{ST}T
*/

int main()
{
    string s;
    cin >> s;
    int tmp = 0;
    int cnt_s = 0;
    int cnt_t = 0;
    int ans = 0;
    rep(i, s.size()){
        if (s[i] == 'S'){
            cnt_s++;            
        } else {
            if (cnt_s > 0){
                ans++;
                cnt_s--;
            }
        }
    }
    ans = s.size() - ans*2;
    cout << ans << endl;
}



Measured memory_bytes: 640
#include <bits/stdc++.h> //全ての標準ライブラリ
#define rep(i,n) for(int i = 0;i < n;i++)
using namespace std;
int sumVector (const std::vector<int>& v){ //int配列計算
    int sum = 0;
    rep(i, v.size()) sum += v.at(i);
    return sum; 
}
int main(void){
    int x,y,z,temp;
    cin >> x >> y >> z;
    temp = x;
    x = y;
    y = temp;
    
    temp = x;
    x = z;
    z = temp;
    cout << x <<' '<< y <<' '<< z;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define MOD (int) (1e9+7)
#define INF (int) 2e9
#define LLINF (ll) 2e18

int main(){
    int n;
    string s;
    cin >> n >> s;
    rep(i, s.size()){
        char tmp = s[i] + n;
        // printf("%d\n", tmp);
        if(tmp > 'Z'){
            cout << (char)(tmp - 26);
        }else{
            cout << tmp;
        }
    }
    cout << endl;
    return 0;
}

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

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main()
{
  int A, P;
  cin >> A >> P;

  cout << (P + A * 3) / 2 << endl;

  return 0;
}


Measured memory_bytes: 256
<?php
  fscanf(STDIN, "%d %d %d", $P, $Q, $R);

  // A->B P, B->C Q, C->A R
  // A->B->C PQ
  // B->C->A QR
  // C->A->B RP
  echo min($P + $Q, $Q + $R, $R + $P);


Measured memory_bytes: 4728
a, b, c = [int(str) for str in input().split(" ")]
counter5 = 0
counter7 = 0

for num in [a, b, c]:
  if num == 5:
    counter5 += 1
  elif num == 7:
    counter7 += 1

if (counter5 == 2) and (counter7 == 1):
  print("YES")
else:
  print("NO")

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

const int OP_LEN = 20;

typedef struct _node {
  int num;
  struct _node *left;
  struct _node *right;
} node;

node *tree = NULL;

node *make_node(int num)
{
  node *v = (node *)malloc(sizeof(node));
  v->num = num;
  v->left = NULL;
  v->right = NULL;
  return v;
}

void insert_body(node *tree, int num)
{
  node *l = tree->left;
  node *r = tree->right;
  if (num <= tree->num) {
    if (l == NULL)
      tree->left = make_node(num);
    else
      insert_body(l, num);
  } else {
    if (r == NULL)
      tree->right = make_node(num);
    else
      insert_body(r, num);
  }
}

void insert(int num)
{
  if (tree == NULL)
    tree = make_node(num);
  else
    insert_body(tree, num);
}

void print_tree(node *tree)
{
  if (tree == NULL) {
    printf("*");
  } else {
    printf("(%d ", tree->num);
    print_tree(tree->left);
    printf(" ");
    print_tree(tree->right);
    printf(")");
  }
}

void inorder(node *tree)
{
  if (tree == NULL) return;
  inorder(tree->left);
  printf(" %d", tree->num);
  inorder(tree->right);
}

void preorder(node *tree)
{
  if (tree == NULL) return;
  printf(" %d", tree->num);
  preorder(tree->left);
  preorder(tree->right);
}

void print()
{
  // print_tree(tree); printf("\n");
  inorder(tree); printf("\n");
  preorder(tree); printf("\n");
}

bool find(node *tree, int num)
{
  if (tree == NULL) return false;
  if (tree->num == num) return true;
  if (num <= tree->num) return find(tree->left, num);
  return find(tree->right, num);
}

node *next_node(node *tree, int num, node *candidate)
{
  if (tree == NULL) return candidate;
  if (num < tree->num) {
    if (candidate == NULL || tree->num < candidate->num)
      candidate = tree;
    return next_node(tree->left, num, candidate);
  } else {
    return next_node(tree->right, num, candidate);
  }
}

void delete_node(node *parent, node *tree, int num)
{
  if (tree==NULL) return;
  if (tree->num == num) {
    if (parent == NULL) {
      tree = NULL;
    } else {
      int sz = (tree->left==NULL?0:1) + (tree->right==NULL?0:1);
      if (sz == 0) {
        node **t = parent->left == tree?&parent->left:&parent->right;
        *t = NULL; free(tree);
      } else if (sz == 1) {
        node **t = parent->left == tree?&parent->left:&parent->right;
        node *c = (tree->left==NULL?tree->right:tree->left);
        *t = c; free(tree);
      } else {
        node *r = next_node(tree, num, NULL);
        int tmp = r->num;
        delete_node(NULL, tree, tmp);
        tree->num = tmp;
      }
    }
  } else if (num < tree->num) {
    delete_node(tree, tree->left, num);
  } else {
    delete_node(tree, tree->right, num);
  }
}

int main()
{
  int n; scanf("%d", &n);
  while (n--) {
    char op[OP_LEN]; scanf("%s", op);
    if (op[0] == 'i') {
      int num; scanf("%d", &num);
      insert(num);
    } else if (op[0] == 'f') {
      int num; scanf("%d", &num);
      printf("%s\n", find(tree, num)?"yes":"no");
    } else if (op[0] == 'd') {
      int num; scanf("%d", &num);
      delete_node(NULL, tree, num);
    } else {
      print();
    }
  }
  return EXIT_SUCCESS;
}




Measured memory_bytes: 15660
H, W, M = map(int, input().split())
hw = [list(map(int, input().split())) for _ in range(M)]
hw_set = set()
for bomb in hw:
    hw_set.add((bomb[0], bomb[1]))
h_value = [0]*(H+1)
w_value = [0]*(W+1)
# exist = [ [0 for _ in range(W+1)] for _ in range(H+1)]

for coordinate in hw:
    h_value[coordinate[0]] += 1
    w_value[coordinate[1]] += 1
    

h_max = max(h_value)
w_max = max(w_value)

h_max_ind = list()
w_max_ind = list()
h_max_ind_num = 0
w_max_ind_num = 0

for i in range(H+1):
    if h_value[i] == h_max:
        h_max_ind.append(i)
        h_max_ind_num += 1


for i in range(W+1):
    if w_value[i] == w_max:
        w_max_ind.append(i)
        w_max_ind_num += 1

# print("put", h_max_ind, w_max_ind)
flag = False
if (h_max_ind_num * w_max_ind_num) > M:
    flag = True
else:
    for h in h_max_ind:
        for w in w_max_ind:
            if not (h, w) in hw_set:
                flag = True
                break

if flag:
    print(h_max + w_max)
else:
    print(h_max + w_max - 1)



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

int main()
{
  int a[3];
  rep(i,3){
    cin >> a[i];
  }
  sort(a, a + 3);
  cout << a[2] * 10 + a[1] + a[0] << endl;
  return 0;
}

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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);

    int n; string s;
    vector<char> alf(53);
    for(int i = 0; i < 26; i++) {
        alf[i] = 'A' + i;
        alf[i + 26] = 'A' + i;    
    }
    cin >> n >> s;
    for(int i = 0; i < (int) s.size(); i++) {
        //cout << (s[i] - 'A') + n << "\n";
        s[i] = alf[(s[i] - 'A') + n];        
    }
    cout << s << "\n";
    
    return 0;    
}


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

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
char chlit(char c){return c+32;}
char chbig(char c){return c-32;}

int main(){
  int n;cin >> n;
  cout << n*800-200*(n/15) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <fstream>
using namespace std;

//#define FILE_INPUT
//#define DEBUG_MODE

void DebugPrint(int a[], int n)
{
#ifdef DEBUG_MODE
	for (int i = 0; i < min(20, n); ++i) {
		cout << a[i] << ",";
	}
	cout << endl;
#endif
}

int dp[3000][3000];
int bt[3000][3000];

int main()
{
#ifdef FILE_INPUT
	ifstream in("test3.txt");
	cin.rdbuf(in.rdbuf());
#endif	/* FILE_INPUT */  

	string s, t;
	cin >> s >> t;

	for (int j = 0; j < (int)t.length(); ++j) {
		if (s[0] == t[j]) {
			dp[0][j] = 1;
			bt[0][j] = -2;
		}
		else {
			bt[0][j] = -1;
		}
	}
	DebugPrint(dp[0], t.length());
	DebugPrint(bt[0], t.length());
	for (int i = 1; i < (int)s.length(); ++i) {
		int max_l = 0;
		int max_p = -1;
		for (int j = 0; j < (int)t.length(); ++j) {
			if (s[i] == t[j]) {
				dp[i][j] = max_l + 1;
				bt[i][j] = max_p;
			}
			else {
				dp[i][j] = dp[i - 1][j];
				bt[i][j] = -1;
			}
			if (max_l < dp[i - 1][j]) {
				max_l = dp[i - 1][j];
				max_p = j;
			}
		}
		DebugPrint(dp[i], t.length());
		DebugPrint(bt[i], t.length());
	}
	int max_l = 0;
	int max_j = -1;
	int i = (int)(s.length()) - 1;
	vector<char> lcs;
	for (int j = 0; j < (int)t.length(); ++j) {
		if (max_l < dp[i][j]) {
			max_l = dp[i][j];
			max_j = j;
		}
	}
	if (max_j >= 0) {
		lcs.push_back(t[max_j]);
		//cout << i << " " << max_j << " " << t[max_j] << endl;
		for (int i = (int)s.length() - 1; i >= 0; --i) {
			if (bt[i][max_j] == -2) {
				break;
			}
			if (bt[i][max_j] >= 0) {
				max_j = bt[i][max_j];
				lcs.push_back(t[max_j]);
				//cout << i << " " << max_j << " " << t[max_j] << endl;
			}
		}
	}

	reverse(lcs.begin(), lcs.end());
	for (int i = 0; i < (int)lcs.size(); ++i) {
		cout << lcs[i];
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 70528
import java.util.*;
import java.lang.Math;
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        while(true){
            int n = sc.nextInt();
            if(n==0){
                break;
            }
            int sum=0;
            int[] data = new int [n];
            for(int i=0;i<n;i++){
                
                data[i]=sc.nextInt();
            }
            Arrays.sort(data);
            for(int i=1;i<n-1;i++){
                sum+=data[i];
            }
            System.out.println(sum/(n-2));
        }
        
        sc.close();
    }
}



Measured memory_bytes: 28976
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b;
  int c[36] = {1,2,3,4,5,6,7,8,9,10,12,14,15,16,18,20,21,24,25,27,28,30,32,35,36,40,42,45,48,49,54,56,63,64,72,81};
  cin >> a;
  for(int i=0;i<36;i++){
    if(c[i] == a){
      cout << "Yes";
      return 0;
    }
  }
  cout << "No";
  return 0;
}

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

typedef long long ll;

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

	vector<int> R,G,B;
	rep(i,N){
		if(S[i]=='R'){ R.push_back(i+1); }
		if(S[i]=='G'){ G.push_back(i+1); }
		if(S[i]=='B'){ B.push_back(i+1); }
	}

	ll ans = 0;
	for(int i=0; i<(int)R.size(); i++){
		for(int j=0; j<(int)G.size(); j++){
			int rg = abs(R[i]-G[j]);
			int mn = min(R[i],G[j]);
			int mx = max(R[i],G[j]);
			int s = B.size();
			auto itr1 = find(B.begin(),B.end(),mn-rg);
			if(itr1!=B.end()) { s--;}
			auto itr2 = find(B.begin(),B.end(),mx+rg);
			if(itr2!=B.end()){ s--;}
			if(abs(mn+mx)%2==0){
			auto itr3 = find(B.begin(),B.end(),(mn+mx)/2);
			if(itr3!=B.end()) { s--;}
			}
			ans += s;
		}
	}

	cout << ans << endl ;
}


Measured memory_bytes: 3644
#include <iostream>

using namespace std;

long int R[1000000];

int main(){
    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        int r;
        cin >> r;
        R[i] = r;
    }
    long min = R[0];
    long max = R[1] - R[0];
    for(int i = 1; i < n; i++){
        if(max < R[i] - min){
            max = R[i] - min;
        }
        if(R[i] < min){
            min = R[i];
        }
    }
    cout << max << endl;
    return 0;
}


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

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int r =0;
  rep(i,n){
    if (s.substr(i,1)=="R"){
      r++;
    }
  }
  int a=0;
  rep(i,r){
    if (s.substr(i,1)=="R"){
      a++;
    }
  }
  cout << r-a << endl;
  return 0;
}


Measured memory_bytes: 3752
N = int(input())
s_list = [input() for _ in range(N)]
from collections import defaultdict
def combination(n, r):
    """
    :param n: the count of different items
    :param r: the number of select
    :return: combination
    n! / (r! * (n - r)!)
    """
    r = min(n - r, r)
    result = 1
    for i in range(n, n - r, -1):
        result *= i
    for i in range(1, r + 1):
        result //= i
    return result

di = defaultdict(int)
for S in s_list:

    tmp = defaultdict(int)
    for s in S:
        tmp[s] += 1
    T = ""
    tmp = sorted(tmp.items())
    for t, t2 in tmp:
        T += t+ str(t2)
    di[T] += 1
ans = 0
for k, v in di.items():
    if v > 1:
        ans += combination(v, 2)
print(ans)


Measured memory_bytes: 25880
// C.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

int main(int argc, char* argv[]) {
	int n, k;
	long long sum = 0;
	cin >> n >> k;
	vector<int> h(n);
	for (int i = 0; i < n; ++i) {
		cin >> h[i];
	}
	sort(h.rbegin(), h.rend());
	for (int i = 0; i < n; ++i) {
		if (i >= k) {
			sum += h[i];
		}
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;
using pll=pair<ll,ll>;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define MOD 1000000007

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

int main() {
	int n;
	cin >> n;
	vector<pii> coor(n);
	vector<int> t(n);
	rep(i,n) {
		cin >> t[i] >> coor[i].fi >> coor[i].se;
	}
	rep(i,n) {
		if(i==0) {
			if (coor[i].fi + coor[i].se > t[0]) {
				cout << "No" << endl;
				return 0;
			}
			else if ((t[0] - (coor[i].fi + coor[i].se)) % 2 == 1) {
				cout << "No" << endl;
				return 0;
			}
		}
		else {
			if(abs(coor[i].fi - coor[i-1].fi) + abs(coor[i].se - coor[i-1].se) > t[i]-t[i-1]) {
				cout << "No" << endl;
				return 0;
			}
			else if((t[i]-t[i-1])-abs(coor[i].fi - coor[i-1].fi) + abs(coor[i].se - coor[i-1].se) % 2 == 1) {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
	
	

  return 0;
}


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

// Loops
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define _rrep(i, n) rrepi(i, n, 0)
#define rrepi(i, a, b) for (int i = int(a) - 1; i >= int(b); --i)

#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define rrep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(xi, x) for (auto &&xi : x)
// Note: we can use rep(i,N) or rep(i,from,to)

// typedef
template <class T> using vec = vector<T>;
using ll = long long;
using vi = vec<ll>;
using vvi = vec<vi>;
using vvvi = vec<vvi>;
using pii = pair<ll, ll>;

// Constants

// Shorter repr for frequently used terms
#define pb push_back
#define mp make_pair

// Algorithms
#define all(x) (x).begin(), (x).end()
#define uniq(v) v.erase(unique(all(v)), v.end())
#define perm(c)                                                                \
  sort(all(c));                                                                \
  for (bool c##p = 1; c##p; c##p = next_permutation(all(c)))

template <class T> pair<T, size_t> max(vector<T> &x) {
  auto it = max_element(all(x));
  return mp(*it, it - x.begin());
}
template <class T> pair<T, size_t> min(vector<T> &x) {
  auto it = min_element(all(x));
  return mp(*it, it - x.begin());
}

template <class T> inline bool chmax(T &maxval, const T &newval) {
  if (maxval < newval) {
    maxval = newval;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &minval, const T &newval) {
  if (minval > newval) {
    minval = newval;
    return 1;
  }
  return 0;
}

// Utilities
// Grid world utilities
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
#define inside(H, W, y, x) 0 <= (x) && (x) < (W) && 0 <= (y) && (y) < (H)

// Debug
#ifdef LOCAL
#include "dump.hpp"
#define debug(x) cerr << #x << ": " << x << '\n'
#else
#define dump(...)
#define debug(x)
#endif

// Yes or No
void yesno(bool ok, string yes = "Yes", string no = "No") {
  cout << (ok ? yes : no) << endl;
}

// Paste snippets here!!

//

pair<ll,ll> rotate(pair<ll,ll> x){
  // ベクトルを時計回りに90度回転する
  return mp(x.second, -x.first);
}

void solve(std::vector<long long> x, std::vector<long long> y) {
  ll x1, x2, y1, y2;
  x1 = x[0]; x2 = x[1];
  y1 = y[0]; y2 = y[1];
  ll ippen = max(abs(x[0]-x[1]), abs(y[0]-y[1]));
  pair<ll,ll> v = mp(x[0]-x[1], y[0]-y[1]);
  ll x3, x4, y3, y4;

  v = rotate(v);
  x3 = x2 + v.first;
  y3 = y2 + v.second;

  v = mp(x2-x3, y2-y3);
  v = rotate(v);
  x4 = x3 + v.first;
  y4 = y3 + v.second;
  
  cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false); // Magic for faster cin
  cout.precision(12);
  std::vector<long long> x(2);
  std::vector<long long> y(2);
  for (int i = 0; i < 2; i++) {
    std::cin >> x[i];
    std::cin >> y[i];
  }
  solve(std::move(x), std::move(y));
  return 0;
}


Measured memory_bytes: 3596