akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
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; }

int n;
ll a[100010];

int main() {
    cin >> n;
    rep(i, n) cin >> a[i];

    int n_neg = 0;
    rep(i, n) {
        if (a[i] < 0) n_neg++;
    }

    ll ans = 0;
    if (n_neg % 2 == 0) {
        rep(i, n) ans += abs(a[i]);
    } else {
        ll amin = LLINF;
        rep(i, n) chmin(amin, abs(a[i]));
        rep(i, n) ans += abs(a[i]);
        ans -= 2 * amin;
    }
    cout << ans << endl;
}


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

using namespace std;

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

int main(){
  int a;
  string s;
  cin >> a >> s;
  cout << (a >= 3200 ? s : "red") << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
  int n,i,mi,c=0;
  cin>>n;
  vector<int> p(n);
  for(i=0;i<n;i++) {
    cin>>p.at(i);
    if (i==0) mi=p.at(i);
    else mi=min(mi,p.at(i));
    if (mi==p.at(i)) c++;
  }
  cout<<c<<endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define repeat(i,a,b) for(int i=(a),i##__end=(b);i<i##__end;i++)
#define repeat_back(i,a,b) for(int i=(b)-1,i##__end=(a);i>=i##__end;i--)
#define mst(a,x) memset((a),(x),sizeof(a))
#define pii pair<int,int>
#define N 100010
#define MAXN 1000000000000000000ll
#define mod 998244353
#define int ll
int n;
struct ST{//build(1,1,n) update(1,1,n,?,?,?) query(1,1,n,?,?)
	ll a[400010],lazy[400010];//四倍空间
	void build(int n,int l,int r){
		int lc=n*2,rc=n*2+1,m=(l+r)/2;
		lazy[n]=MAXN;
		if(l==r){
			a[n]=MAXN;
			return;
		}
		build(lc,l,m);
		build(rc,m+1,r);
		a[n]=min(a[lc],a[rc]);
	}
	void down(int n,int l,int r){
		int lc=n*2,rc=n*2+1,m=(l+r)/2;
		if(l<r){
			lazy[lc]=min(lazy[lc],lazy[n]);
			lazy[rc]=min(lazy[rc],lazy[n]);
		}
		a[n]=min(a[n],lazy[n]);
		lazy[n]=MAXN;
	}
	void update(int n,int l,int r,int x,int y,ll del){
		int lc=n*2,rc=n*2+1,m=(l+r)/2;
		x=max(x,l); y=min(y,r); if(x>y){down(n,l,r);return;}//!!
		if(x==l && y==r){
			lazy[n]=min(lazy[n],del);
			down(n,l,r);
			return;
		}
		down(n,l,r);
		update(lc,l,m,x,y,del);
		update(rc,m+1,r,x,y,del);
		a[n]=min(a[lc],a[rc]);
	}
	ll query(int n,int l,int r,int x,int y){
		int lc=n*2,rc=n*2+1,m=(l+r)/2;
		x=max(x,l); y=min(y,r); if(x>y)return MAXN;
		down(n,l,r);
		if(x==l && y==r)
			return a[n];
		return min(query(lc,l,m,x,y),query(rc,m+1,r,x,y));
	}
}st;
struct node{
	int l,r,w;
	bool operator<(node B)const{return l<B.l;}
};
node a[N];
signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int m;
	cin>>n>>m;
	repeat(i,0,m)
		cin>>a[i].l>>a[i].r>>a[i].w;
	sort(a,a+m);
	st.build(1,1,n);
	st.update(1,1,n,1,1,0);
	repeat(i,0,m){
		int s=st.query(1,1,n,a[i].l,a[i].l);
		st.update(1,1,n,1,a[i].r,s+a[i].w);
	}
	int s=st.query(1,1,n,n,n);
	if(s==MAXN)
		cout<<-1<<endl;
	else
		cout<<s<<endl;
	return 0;
}

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

/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
*/

using namespace std;

#if DEBUG && !ONLINE_JUDGE
    #include "debug.h"
#else
    #define debug(...)
#endif

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

#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
//#define fill(a,x) memset(a,x,sizeof(a))
#define ff first
#define ss second
#define trav(a, x) for(auto& a : x) 
#define FOR(i,a,b) for(int i = a; i<=b; ++i)
#define NFOR(i,a,b) for(int i = a; i>=b; --i)
const ll INF = 1e18;
const int mod =  998244353;
const int N = 1e5;
ll gcd(ll a,ll b){if (a==0) return b;return gcd(b%a,a);}
ll lcm(ll a,ll b){return a*(b/gcd(a,b));}
ll Abs(ll a){if(a>0)return a;return -a;}
ll Ceil(ll a,ll b){if(a%b==0)return a/b;else return a/b+1;}
double Abs(double a){if(a>0)return a;return -a;}

//*X.find_by_order(2) element at index=2
//X.order_of_key(1) how many elements strictly less than 1

/*
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
    tree_order_statistics_node_update>;
*/

inline int pow_(ll x, ll y,ll p){
  int r = 1; while(y){if(y & 1) r = r * x % p; y >>= 1; x = x * x % p;} return r;
}
inline int inv_(int x){return pow_(x, mod - 2, mod);}
inline int add(int a, int b){a += b; if(a >= mod) a -= mod; return a;}
inline int mul(int a, int b){return a * 1LL * b % mod;}
inline int sub(int a, int b){a -= b; if(a < 0) a += mod; return a;}


int main()
{
	#ifdef LOCAL_TEST
    freopen("in.txt","r",stdin);
    //freopen("out.txt", "w", stdout);
    #else
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    #endif
    ll n;
    cin>>n;
    ll h[100005] = {0};

    for(int i=1;i<=n;i++)cin>>h[i];
    ll dp[100005] = {0};
    dp[1] = 0;
    dp[2] = abs(h[2]-h[1]);
    for(int i=3;i<=n;i++)
    {
    	dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]) , dp[i-2]+abs(h[i]-h[i-2]));
    }

    cout << dp[n] << "\n";
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define int long long
using P = pair<int,int>;

signed main(){
  int n;
  cin >> n;
  vector<pair<int,P>> S(n);
  int a = 0;
  int b = 0;
  rep(i,n){
    cin >> S[i].second.first >> S[i].second.second;
    S[i].first = S[i].second.first+S[i].second.second;
    b += S[i].second.second;
  }
  sort(S.rbegin(),S.rend());
  //cout << b << endl;
  for(int i = 0;i < n;i+=2){
    a += S[i].second.first;
    b -= S[i].second.second;
  }
  cout << a - b << endl;
}

Measured memory_bytes: 2560
// C - Rally
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
template<class T>bool chmin(T &a, const T &b){if(b<a){a=b;return 1;}return 0;}
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}

int main(){
	int N; cin>>N;
	vi X(N);
	int minx = INT_MAX, maxx = INT_MIN;
	rp(i,0,N){
		cin>>X[i];
		chmin(minx, X[i]);
		chmax(maxx, X[i]);
	}
	int ans = INT_MAX;
	rp(p, minx, maxx+1){
		int wa = 0;
		for(auto x:X) wa += (x-p)*(x-p);
		chmin(ans, wa);
	}
	cout<< ans <<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		sc.close();
		
		int ans = (A + B) % 24;
		System.out.println(ans);
	}
}


Measured memory_bytes: 23892
#include <algorithm>
#include<iostream>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<set>
#include<string>
#include <sstream>
#include<bitset>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
const int INF = 0x7fffffff;
using lll = long long;
using ull = unsigned long long;
using namespace std;


int main(){
  lll ii,jj,kk;
  vector<int> ret;
  int n;
  string c;
  cin >> n;
  cin >> c;
  int red,white,cnt;

  red = 0;
  white = 0;
  cnt = 0;
  
  for(ii=0;ii<n;ii++){
    if(c[ii] == 'R'){
      red++;
    }
    else{

    }
  }
  int min = INF;
  int tmp;

  min = max(white,red);
  
  for(ii=0;ii<n;ii++){
    if(c[ii] == 'R'){
      red--;      
    }
    else{
      white++;
    }
    tmp = max(red,white);
    if(tmp < min){
      min = tmp;
    }
  }

  
  cout << min << endl;

  return 0;
}


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

using namespace std;

int main(){
	string sd,t;
	cin >> sd;
	cin >> t;
	int ls = sd.length();
	int lt = t.length();
	int res = 0;
	bool pos = false;
	for(int i=0;i<=ls-lt;++i){
		bool flag = true;
		string sub = sd.substr(i,i+lt);
		for(int j=0;j<lt;++j){
				if(sub[j]!='?'&&sub[j]!=t[j]){
				flag = false;
				break;
			}
		}
		if(flag){
			res = i;
			pos = true;
		}
	}
	if(pos){
		for(int i=0;i<ls;++i){
			if(sd[i] == '?'){
				if(i < res||i>=res+lt)sd[i] = 'a';
				else sd[i] = t[i-res];
			}
		}
		cout << sd << endl;
	}else{
		cout << "UNRESTORABLE" << endl;
	}
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
m = [0 for i in range(n)]
i = 0
while i <= n-1:
    m[0] += a[i]
    i += 2
i = 1
while i <= n-2:
    m[0] -= a[i]
    i += 2
print(m[0], end=" ")
for i in range(1, n-1):
    m[i] = 2*a[i-1] - m[i-1]
    print(m[i], end=" ")
m[n-1] = 2*a[n-2] - m[n-2]
print(m[n-1])

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

int main(){
    int h, w, k;
    cin >> h >> w >> k;
    vector<string> c(h);
    rep(i, h) cin >> c[i];

    int ans=0, cnt=0;
    for(int i=0; i<(1<<h); i++){
        for(int j=0; j<(1<<w); j++){
            cnt = 0;
            for(int m=0; m<h; m++){
                for(int n=0; n<w; n++){
                    if(i & (1<<m) || j & (1<<n)) continue;
                    if(c[m][n] == '#') cnt++;
                }
            }
            if(cnt == k) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3636
S = input()
N = len(S) + 1

A = [0 for _ in range(N)]

for i, s in enumerate(S):
    if i + 1 < N and s == '<':
        A[i + 1] = max(A[i + 1], A[i] + 1)

for i, s in zip(range(N)[::-1], S[::-1]):
    if i - 1 >= 0 and s == '>':
        A[i - 1] = max(A[i - 1], A[i] + 1)

print(sum(A))


Measured memory_bytes: 24100
import sys, math
import bisect, heapq
import collections

sys.setrecursionlimit(10 ** 6)

input = sys.stdin.readline

gets = lambda: input().rstrip()
getn = lambda: int(input())
getmul = lambda: (int(i) for i in input().split())
getlist = lambda: [int(i) for i in input().split()]

n, m = getmul()
H = [0] + getlist()
good = [1 for _ in range(n + 1)]
for _ in range(m):
    a, b = getmul()
    if H[a] <= H[b]:
        good[a] = 0
    if H[b] <= H[a]:
        good[b] = 0

print(sum(good) - 1)



Measured memory_bytes: 21200
#include<iostream>
#include<algorithm>
#include<math.h>
#include<stdio.h>
#include<string>
#include<vector>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

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

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


int A, B, Q;
vector<long long> s, t;

int main(){
    cin >> A >> B >> Q;
    for(int i = 0; i < A; i++){
        long long tmp;
        cin >> tmp;
        s.push_back(tmp);
    }
    for(int i = 0; i < B; i++){
        long long tmp;
        cin >> tmp;
        t.push_back(tmp);
    }
    for(int i = 0; i < Q; i++){
        long long x;
        cin >> x;
        long long ls, lt, rs, rt;
        if(lower_bound(s.begin(), s.end(), x) == s.begin()){
            ls = -2e10;
        }else{
            ls = *(lower_bound(s.begin(), s.end(), x) - 1);
        }
        if(lower_bound(t.begin(), t.end(), x) == t.begin()){
            lt = -2e10;
        }else{
            lt = *(lower_bound(t.begin(), t.end(), x) - 1);
        }

        if(lower_bound(s.begin(), s.end(), x) == s.end()){
            rs = 2e10;
        }else{
            rs = *lower_bound(s.begin(), s.end(), x);
        }

        if(lower_bound(t.begin(), t.end(), x) == t.end()){
            rt = 2e10;
        }else{
            rt = *lower_bound(t.begin(), t.end(), x);
        }

        long long ll = max(x - ls, x - lt);
        long long lr = min(2 * (x - ls) + (rt - x), 2 * (rt - x) + (x - ls));
        long long rl = min(2 * (x - lt) + (rs - x), 2 * (rs - x) + (x - lt));
        long long rr = max(rs - x, rt - x);

        long long ans = min(ll, min(lr, min(rl, rr)));

        cout << ans << endl;
        
    }
}


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

#define MAX_N 105

using namespace std;

int SelectionSort(int arr[], int N)
{
    int swapNum=0;
    for(int i=0; i<N-1; i++)
    {
        int minIdx=i;
        for(int j=i; j<N; j++)
        {
            if(arr[j]<arr[minIdx])
            {
                minIdx=j;
            }
        }
        if(minIdx!=i)
        {
            swap(arr[i], arr[minIdx]);
            swapNum++;
        }
    }
    return swapNum;
}

int main()
{
    int arr[MAX_N];
    int N;
    scanf("%d", &N);
    for(int i=0; i<N; i++)
        scanf("%d", arr+i);
    int res=SelectionSort(arr, N);
    printf("%d", arr[0]);
    for(int i=1; i<N; i++)
        printf(" %d", arr[i]);
    printf("\n");
    printf("%d\n", res);
    return 0;
}



Measured memory_bytes: 3216
while(True):
	score = [int(i) for i in input().split()]
	if score[:] == [-1,-1,-1]:
		break
	if score[0] == -1 or score[1] == -1:
		print('F')
	else:
		score_sum = score[0] + score[1]
		if score_sum >= 80:
			print('A')
		elif 80 > score_sum >= 65:
			print('B')
		elif 65 > score_sum >= 50:
			print('C')
		elif 50 > score_sum >= 30:
			if score[2] >= 50:
				print('C')
			else :
				print('D')
		elif 30 > score_sum:
			print('F')

Measured memory_bytes: 7680
#include <iostream>
using namespace std;
static const int MAX = 100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;
int M[MAX][MAX], n, tt = 0;
int d[MAX], f[MAX], color[MAX];

void dfs(int u)
{
    color[u] = GRAY;
    d[u] = ++tt;
    for (int i = 0; i != n; ++i)
    {
        if (M[u][i] && color[i] == WHITE)
        {
            dfs(i);
        }
    }
    color[u] = BLACK;
    f[u] = ++tt;
}

int main()
{
    int id, m, v;
    cin >> n;
    for (int i = 0; i != MAX; ++i)
    {
        d[i] = 0;
        f[i] = 0;
        color[i] = WHITE;
        for (int j = 0; j != MAX; ++j)
        {
            M[i][j] = 0;
        }
    }
    for (int i = 0; i != n; ++i)
    {
        cin >> id >> m;
        for (int j = 0; j != m; ++j)
        {
            cin >> v;
            M[id-1][v-1] = 1;
        }
    }
    for (int i = 0; i != n; ++i)
    {
        if (color[i] == WHITE) dfs(i);
    }

    for (int i = 0; i != n; ++i)
    {
        cout << i + 1 << " " << d[i] << " " << f[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 3140
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,(n+1)//2):
    j = 0
    while j + 2*i <= n-1:
        if s[j] != s[j+i] and s[j] != s[j+2*i] and s[j+i] != s[j+2*i]:
            ans -= 1
        j += 1
print(ans)

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

using namespace std;

typedef long long ll;

ll parent[1000000],Rank[1000000];

void initialize()
{
    for(ll i=1;i<=1000000;i++) {parent[i]=i;Rank[i]=1;}
}

ll Find(ll r)
{
    if(parent[r]==r) return r;

    parent[r]=Find(parent[r]);

    return parent[r];
}
ll component,ans=0;
void Union(ll x, ll y)
{
    ll u=Find(x);

    ll v=Find(y);

    if(u!=v) {//cout<<"The are different Component so that the include in the same component";

              component--;//first a sob gula alada component e chilo ar ekhon ekoi component e ene dichi tai comonent num ek ek kore komachi

            if(Rank[v]>Rank[u]){Rank[v]+=Rank[u];parent[u]=v;} //zetar child beshi setar sathe new child add korchi abong mot child num add korchi

            else {Rank[u]+=Rank[v];parent[v]=u;}

           // ll mx=max(Rank[u],Rank[v]);

            // ans=max(ans,mx);

          //  cout<<"u ="<<Rank[u]<<endl;

            //cout<<"v= "<<Rank[v]<<endl;


//ekoi componet e rakhlam

    }
    else {// cout<<"The are same component";


    }
}

int  main()
{
    initialize();

    ll N,E,u,v;

    cin>>N;
    cin>>E;
    component=N;
    for(ll i=1;i<=E;i++)
    {
        cin>>u>>v;

        Union(u,v);
    }
    cout<<component-1<<endl;
    //cout<<ans<<endl;



}


Measured memory_bytes: 19264
import Control.Monad (replicateM)
import Data.Array (Array,(!))
import qualified Data.Array.IO as IOArr

main = do
    [n,k] <- getLine >>= return . map read . words
    if all (==0) [n,k] then return () else do
        flags <- IOArr.newArray (0,n) False
            :: IO (IOArr.IOArray Int Bool)
        replicateM k (getLine >>= return . read >>=
            (\n -> IOArr.writeArray flags n True))
        flags <- IOArr.freeze flags
        print $ solve n flags 
        main 

solve :: Int -> Array Int Bool -> Int
solve n flags 
    | flags ! 0 == False    = maximum $ map fst $ sublist
    | flags ! 0 == True     = maximum $ map snd $ sublist
    where
    sublist :: [(Int,Int)]
    sublist = scanl update (0,0) [flags!i|i<-[1..n]]

    update :: (Int,Int) -> Bool -> (Int,Int)
    update (a,b) False = (0,a+1)
    update (a,b) True  = (a+1,b+1)

Measured memory_bytes: 36924
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>

using namespace std;

typedef long long ll;

typedef std::pair<int, int> ipair;
bool lessPair(const ipair& l, const ipair& r){return l.second < r.second;}
bool morePair(const ipair& l, const ipair& r){return l.second > r.second;}

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

const ll MOD = 1e9 + 7;
void add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; }

int main() {
   int a, b, c, d, e, k;
   cin >> a >> b >> c >> d >> e >> k;
   if (e - a > k) cout << ":(" << endl;
   else cout << "Yay!" << endl;
   return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define Q int tc; scanf("%d",&tc);cin.ignore(); for(int q=1;q<=tc;q++)
typedef long long int ll;
#define MAX 100000

int main()
{
    int n;
    cin>>n;
    vector<int>v;
    for(int i=0;i<n;i++){
        int xx;
        cin>>xx;
        v.push_back(xx);
    }
    sort(v.begin(),v.end());

    int mx=0,ans=0,cnt=0;
    for(int i=0;i<n;i++){
        int l=lower_bound(v.begin(),v.end(),v[i]-1)-v.begin();
        int u=upper_bound(v.begin(),v.end(),v[i]+1)-v.begin()-1;
        ans=max(ans,(u-l));
    }
    cout<<ans+1;
}



Measured memory_bytes: 3904
def main():
    N, K = (int(i) for i in input().split())
    P = [int(i) for i in input().split()]
    E = [(p*(p+1)//2)/p for p in P]
    S = [0]*(N+1)
    ma = 0
    for i in range(N):
        S[i+1] = S[i] + E[i]
    for i in range(N-K+1):
        ma = max(ma, S[K+i] - S[i])
    print(ma)


if __name__ == '__main__':
    main()


Measured memory_bytes: 81800
#pragma gcc optimize("Ofast")

#include "bits/stdc++.h"
using namespace std;
typedef int64_t lld;
typedef pair<int,int> pii;
typedef pair<lld,lld> pll;
typedef pair<int,pll> pip;
typedef pair<pll,int> ppi;
typedef pair<lld,pll> plp;
typedef pair<pll,lld> ppl;
typedef pair<pll,pll> ppp;
template<typename T>
using maxHeap = priority_queue<T,vector<T>,less<T>>;
template<typename T>
using minHeap = priority_queue<T,vector<T>,greater<T>>;
#define ff first
#define ss second
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define endl '\n'
#define jizz cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);
inline void input(int &_x) {
    _x = 0;
    int _tmp = 1; char _tc = getchar();
    while((_tc < '0' || _tc > '9') && _tc != '-') _tc = getchar();
    if(_tc == '-') _tc = getchar(), _tmp = -1;
    while(_tc >= '0' && _tc <= '9') _x = _x*10+(_tc-48), _tc = getchar();
    _x *= _tmp;
}
inline void output(int _x) {
    char _buff[20]; int _f = 0;
    if(_x == 0)putchar('0');
    while(_x > 0)
    {
        _buff[_f++] = _x%10+'0';
        _x /= 10;
    }
    for(_f-=1; _f >= 0; _f--)
        putchar(_buff[_f]);
    putchar('\n');
}
template<typename Iter>
ostream& _out(ostream &s, Iter b, Iter e) {
    s<<"[";
    for ( auto it=b; it!=e; it++ ) s<<(it==b?"":" ")<<*it;
    s<<"]";
    return s;
}
template<class T1,class T2>
ostream& operator<<(ostream& out, pair<T1,T2> p) {
    return out << '(' << p.first << ", " << p.second << ')';
}
template<typename T>
ostream& operator <<( ostream &s, const vector<T> &c ) {
     return _out(s,c.begin(),c.end());
 }
#ifdef erd1
    #define pprint(x) cerr<<__PRETTY_FUNCTION__<<":"<<__LINE__<<" - "<<(#x)<<"="<<(x)<<endl
#else
    #define pprint(x)
#endif

// code starts here
vector<vector<int>> G;
int dfs(int i, int p){
    int ans = 0;
    for(auto x: G[i])
        if(x != p)ans ^= dfs(x, i) + 1;
    return ans;
}
signed main(){
    int n;
    cin >> n;
    G.resize(n+1);
    for(int i = 1; i < n; i++){
        int a, b;
        cin >> a >> b;
        G[a].pb(b);
        G[b].pb(a);
    }
    cout << (dfs(1, 1)?"Alice":"Bob") << endl;
}


Measured memory_bytes: 10368
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

int main(){
    int n; cin >> n;
    int num = (n + 1) / 2;
    double ans = double(num)/n;
    printf("%.10f\n",ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int a, b, k;
	cin >> a >> b >> k;
	int mn = min(a, b);
	for(int i = mn; i > 0; i--){
		if(a % i == 0 && b % i == 0){
			// cerr << i << endl;
			k--;
		}
		if(k == 0){
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
function main(input){
  input = input.split('\n');
  var filterValue = input[0].split(' ').map(parseFloat)[1];
  var values = input[1].split(' ').map(parseFloat);
  console.log(values.filter(x => x >= filterValue).length);
}
main(require('fs').readFileSync('/dev/stdin','utf8'));

Measured memory_bytes: 28620
N = int(input())
p = list(map(int,input().split()))
ans = 0
for i in range(0,N):
    if p[i] == i+1:
        ans += 0
    else:
        ans += 1
if ans == 2:
    print("YES")
elif ans == 0:
    print("YES")
else:
    print("NO")

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

#define ll long long

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    
    ll n;
    cin>>n;
    double sum=0;
    for(ll i=0;i<n;i++)
    {
        ll k;
        cin>>k;
        sum+=(double)1/k;
    }
    cout<<setprecision(10)<<(double)1/sum<<endl;
    
	return 0;
}

Measured memory_bytes: 256
/*
  Contest 067
  B - Snake Toy
  Rakesh Kumar --> 01/09/2020
 */

#include <bits/stdc++.h>

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(0); std::cout.tie(0);

    int n = 0, k = 0;
    std::cin >> n >> k;
    std::vector<int> v;
    while (n--) {
        int l = 0;
        std::cin >> l;
        v.emplace_back(l);
    }
    std::sort(v.rbegin(), v.rend());
    int max = 0;
    for (int i = 0; i < k; ++i)
        max += v[i];
    std::cout << max << std::endl;

    return 0;
}


Measured memory_bytes: 3616
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;

int ary[110][110][110],X[2][60],Y[2][60],D[2][60];
int main(){
	ll N,K;
	vector<ll> sx,sy,sd;
	cin>>N>>K;
	for(int i=1;i<=N;i++){
		cin>>X[0][i]>>Y[0][i]>>D[0][i]>>X[1][i]>>Y[1][i]>>D[1][i];
		if(X[0][i]>X[1][i]) swap(X[0][i],X[1][i]);
		if(Y[0][i]>Y[1][i]) swap(Y[0][i],Y[1][i]);
		if(D[0][i]>D[1][i]) swap(D[0][i],D[1][i]);
		sx.push_back(X[0][i]);
		sx.push_back(X[1][i]);
		sy.push_back(Y[0][i]);
		sy.push_back(Y[1][i]);
		sd.push_back(D[0][i]);
		sd.push_back(D[1][i]);
	}
	sort(sx.begin(),sx.end());
	sort(sy.begin(),sy.end());
	sort(sd.begin(),sd.end());

	ll nx[2],ny[2],nd[2];
	for(int i=1;i<=N;i++){
		nx[0]=(lower_bound(sx.begin(),sx.end(),X[0][i])-sx.begin());
		nx[1]=(lower_bound(sx.begin(),sx.end(),X[1][i])-sx.begin());
		ny[0]=(lower_bound(sy.begin(),sy.end(),Y[0][i])-sy.begin());
		ny[1]=(lower_bound(sy.begin(),sy.end(),Y[1][i])-sy.begin());
		nd[0]=(lower_bound(sd.begin(),sd.end(),D[0][i])-sd.begin());
		nd[1]=(lower_bound(sd.begin(),sd.end(),D[1][i])-sd.begin());
		for(int j=nx[0];j<nx[1];j++){
			for(int k=ny[0];k<ny[1];k++){
				for(int l=nd[0];l<nd[1];l++){
					ary[j][k][l]++;
				}
			}
		}
	}

	ll res=0;
	for(int i=0;i<sx.size()-1;i++){
		for(int j=0;j<sy.size()-1;j++){
			for(int k=0;k<sd.size()-1;k++){
				if(ary[i][j][k]>=K){
					res+=(sx[i+1]-sx[i])*(sy[j+1]-sy[j])*(sd[k+1]-sd[k]);
				}
			}
		}
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 7420
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,m;
char mp[110][110];
int dp[110][110];
bool ok[110][110];
int main()
{
	scanf("%d %d",&n,&m);
	for(int i=0;i<n;++i)scanf("%s",mp[i]);
	memset(dp,0x3f,sizeof(dp));
	dp[n-1][m-1]=mp[n-1][m-1]=='#';
	for(int i=n-1;~i;--i)
		for(int j=m-1;~j;--j)
		{
			if(i)dp[i-1][j]=min(dp[i-1][j],dp[i][j]+(mp[i][j]=='.'&&mp[i-1][j]=='#'));
			if(j)dp[i][j-1]=min(dp[i][j-1],dp[i][j]+(mp[i][j]=='.'&&mp[i][j-1]=='#'));
		/*	int res=min(dp[i+1][j],dp[i][j+1])+(mp[i][j]=='#');
			memset(ok,0,sizeof(ok));
			ok[i][j]=1;
			for(int k=i;~k;--k)
				for(int l=j;~l;--l)
					if(ok[k][l])
					{
						dp[k][l]=min(dp[k][l],res);
						if(k&&mp[k-1][l]==mp[k][l])ok[k-1][l]=1;
						if(l&&mp[k][l-1]==mp[k][l])ok[l][k-1]=1;
					}*/
		}
	printf("%d",dp[0][0]);
	return 0;
}


Measured memory_bytes: 256
#pragma region
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()
#pragma endregion


int main()
{
	int h, w; cin >> h >> w;
	vector<string> a(h); rep(i, h)cin >> a[i];
	//step数のチェック
	int cnt = 0;
	rep(i, h)rep(j, w)
	{
		if (a[i][j] == '#')++cnt;
	}
	if (cnt != h + w - 1)
	{
		cout << "Impossible" << endl;
		return 0;
	}
	//ルートの存在チェック
	vector<vector<bool>> v(h, vector<bool>(w, false));
	queue<pair<int, int>> q;
	if (a[0][0] == '#')q.push({ 0,0 });
	while (!q.empty())
	{
		int x = q.front().first;
		int y = q.front().second;
		q.pop();
		int nx = x + 1;
		int ny = y;
		if (nx < h && ny < w && a[nx][ny] == '#')
		{
			v[nx][ny] = true;
			q.push({ nx,ny });
		}
		nx = x;
		ny = y + 1;
		if (nx < h && ny < w && a[nx][ny] == '#')
		{
			v[nx][ny] = true;
			q.push({ nx,ny });
		}
	}
	if (v[h - 1][w - 1])cout << "Possible" << endl;
	else cout << "Impossible" << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.awt.Point;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		while(true){
			int w = sc.nextInt();
			int h = sc.nextInt();
			if(w == 0 && h == 0) break;

			t = new char[h][w];

			trash = new HashMap<Point,Integer>();
			int count = 1;

			for(int i=0;i<h;i++){
				t[i] = sc.next().toCharArray();
				for(int j=0;j<w;j++){
					if(t[i][j] == 'o'){
						trash.put(new Point(j,i),0);
					}
					else if(t[i][j] == '*'){
						trash.put(new Point(j,i),count++);
					}
				}
			}

			map = new int[count][count];
			for(int[] tmp : map) Arrays.fill(tmp,-1);
			for(Point start : trash.keySet()){
				setMinCost(start);
			}

			ans = Integer.MAX_VALUE;
			solve(new boolean[count],0,0,count-1);
			System.out.println(ans == Integer.MAX_VALUE ? -1 : ans);
		}
	}

	private static HashMap<Point,Integer> trash;
	private static int[][] map;
	private static char[][] t;
	private static int dx[] = {0,0,1,-1};
	private static int dy[] = {1,-1,0,0};
	private static int ans;

	private static void solve(boolean[] used,int now,int cost,int rem){
		if(rem == 0){
			ans = Math.min(ans,cost);
			return;
		}

		used[now] = true;
		for(int i=1;i<map.length;i++){
			if(map[now][i] != -1 && !used[i]){
				solve(used,i,cost+map[now][i],rem-1);
			}
		}
		used[now] = false;

		return;
	}

	private static void setMinCost(Point p){
		PriorityQueue<State> open = new PriorityQueue<State>();
		HashSet<State> closed = new HashSet<State>();

		open.add(new State(p,0));

		while(!open.isEmpty()){
			State st = open.poll();
			if(closed.contains(st)) continue;
			closed.add(st);

			Point tmp = st.p;

			if(t[tmp.y][tmp.x] == 'o' || t[tmp.y][tmp.x] == '*'){
				map[trash.get(p)][trash.get(tmp)] = st.cost;
			}

			open.addAll(st.nexts());
		}
	}

	private static class State implements Comparable<State>{
		Point p;
		int cost;

		State(Point p,int cost){
			this.p = new Point(p.x,p.y);
			this.cost = cost;
		}

		List<State> nexts(){
			List<State> sts = new ArrayList<State>();

			for(int i=0;i<4;i++){
				int nx = p.x + dx[i];
				int ny = p.y + dy[i];

				if(nx >= 0 && nx < t[0].length && ny >= 0 && ny < t.length && t[ny][nx] != 'x'){
					sts.add(new State(new Point(nx,ny),cost+1));
				}
			}

			return sts;
		}

		public int compareTo(State st){
			return this.cost - st.cost;
		}

		public boolean equals(Object o){
			State st = (State)o;
			return p.x == st.p.x && p.y == st.p.y;
		}

		public int hashCode(){
			return p.x + 1000 * p.y;
		}
	}
}

Measured memory_bytes: 13000
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<cmath>
#include<ctime>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<bitset>
#define rint register int
#define debug(x) cerr<<#x<<"="<<x<<endl
#define fgx cerr<<"-------------"<<endl
typedef long long ll;
using namespace std;
int minn[67108865],f[200001],a[200001];
char c[200001];
const int inf=1e8;
int main()
{	scanf("%s",c+1);
	int n=strlen(c+1);
	for(rint i=1;i<=n;i++) a[i]=a[i-1]^(1<<(c[i]-'a'));
	int all=(1<<26)-1;
	for(rint i=1;i<=all;i++) minn[i]=inf;
	for(rint i=1;i<=n;i++)
	{	f[i]=minn[a[i]]+1;
		for(rint j=0;j<26;j++) f[i]=min(f[i],minn[a[i]^(1<<j)]+1);
		minn[a[i]]=min(minn[a[i]],f[i]);
	}
	cout<<f[n]<<endl;
 	return 0;
}


Measured memory_bytes: 264192
#include <iostream>
#include <algorithm>
using namespace std;
static const int MAX=200000;

int main ()
{
  int R[MAX],x;
  cin>>x;
  for(int i=0;i<x;i++)
    cin>>R[i];
  int maxa=-999999999;
  int mina=R[0];
  for(int i=1;i<x;i++)
    {
      maxa=max(maxa,R[i]-mina);
      mina=min(mina,R[i]);
    }

  cout << maxa << endl;

  return 0;
}
  



Measured memory_bytes: 3900
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <set>
#include <sstream>
using namespace std;
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
#define chmax(a, b) a = (((a)<(b))?(b):(a))
#define chmin(a, b) a = (((a)<(b))?(a):(b))

const int INF = 1001001001;
const ll MOD = 1e9+7;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){std::fill((T*)array, (T*)(array+N),val);}

class CompareDist
{
public:
    bool operator()(PLL n1,PLL n2) {
				if(n1.first!=n2.first) return n1.first<n2.first;
				else return n1.second<n2.second;
    }
};

#define lengthof(x) (sizeof(x) / sizeof(*(x)))


__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

bool contain(int mask, int position){
  if((mask&(1<<position))) return true;
  else return false;
}

// GCD,LCMを求める関数
ll gcd(ll a,ll b){
	if(a%b==0) return(b);
	else return(gcd(b,a%b));
}
ll lcm(ll a, ll b){
	return a*b/gcd(a,b);
}

double dabs(double a, double b){
  if(a>=b) return a-b;
  else return b-a;
}


signed main(){
	double n; cin>>n;
  double sum = 0;
  vector<double> a(n);
  rep(i,n){
    double b; cin>>b;
    sum+=b; a[i]=b;
  }
  double ave = sum/n;
  double dif = 100000.0;
  int idx = -1;
  rep(i,n){
    if(dabs(ave,a[i])<dif){
      dif = dabs(ave,a[i]);
      idx = i;
    }
  }
  cout << idx << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  ll n,a;
  vector<ll> v;
  set<ll> s;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a;
   	if(s.find(a)==s.end()){
      s.insert(a);
    }else{
      v.push_back(-a);
      s.erase(a);
    }
  }
  sort(v.begin(),v.end());
  cout<<(v.size()>=2?v[0]*v[1]:0)<<endl;
  return 0;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define SORT(c) sort((c).begin(),(c).end())
#define INF 1000000007
//S.size()

using namespace std;


typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<bool> VB;
typedef unsigned long long ll;



int main(void){
  int A,B,C,K;cin>>A>>B>>C>>K;

  int num = max({A,B,C});
  num *= pow(2,K);
  cout<<A + B + C + num - max({A,B,C});
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define vi vector<int>
#define vii vector<pair<int,int> >
#define inf 1000000000024;
using namespace std;
typedef long long ll;
int maxn = 100005;
ll dp[105][100005];

int N,W;

int main(){
    scanf("%d %d", &N, &W);
    for(int i = 0; i < 105; i++){
        for(int j = 0; j < maxn; j++){
            dp[i][j] = inf;
        }
    }
    dp[0][0] = 0;
    for(int i = 1; i <= N; i++){
        ll w,v;
        scanf("%lld %lld", &w, &v);
        for(int j = 0; j < maxn; j++){
            if(j-v >= 0){
                dp[i][j] = min(dp[i-1][j], w+dp[i-1][j-v]);
            }
            dp[i][j] = min(dp[i][j], dp[i-1][j]);
        }
    }

    for(int i = 100000; i >= 0; i--){
        if(dp[N][i] <= W){
            printf("%d\n", i);
            break;
        }
    }
	return 0;
}

Measured memory_bytes: 82432
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main()
{
	long long n, p;
	cin >> n >> p;

	if (n == 1) {
		cout << p << endl;
		return 0;
	}

	vector<pair<int, int>> a;
	long long now = p;
	int t = 0;
	for (int i = 2; i <= sqrtl(p) + 1; i++) {
		if (now < i) {
			break;
		}

		t = 0;
		while (now % i == 0) {
			t++;
			now /= i;
		}
		if (t) {
			a.emplace_back(make_pair(i, t));
		}
	}

	int ans = 1;
	for (auto & i : a) {
		for (int j = 0; j < i.second / n; j++) {
			ans *= i.first;
		}
	}
	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 < n; i++)
#define ll long long int
#define INF 1000000007
// cin.eof() 入力個数の問題
int main() {
  string s;
  cin>>s;
  int begin,end;
  rep(i,s.size()){
      if(s[i]=='A'){
          begin=i;
          break;
      }
  }
  for(int i=s.size()-1;i>=0;i--){
      if(s[i]=='Z'){
          end=i;
          break;
      }
  }
  cout<<end-begin+1<<endl;
    return 0;
}


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

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

using ll = long long;
constexpr ll INF = 10000000000;

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

using namespace std;

//fixed << setprecision(10)

/////////////////////////////////////////////////////////////////////////////////////////////////////////

ll gcd(ll a, ll b) {
	if (b == 0)return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}

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

	ll ans = 0;

	ans = lcm(a,b);

	cout << ans << endl;
}



Measured memory_bytes: 256
public class Main {


		public static void main(String[] args) {
		java.util.Scanner scan = new java.util.Scanner(System.in);
		int x;
		int y;
		int i;
		int t = 0;
		
		do{
		x = scan.nextInt();
		y = scan.nextInt();
		if(0<=x && x<=10000 && 0<=y && y<=10000){
			if(x == 0 && y == 0){
				break;
			}
			if(x<=y){
			System.out.println(x+" "+y);
			}else if(x>y){
				i = x;
				x = y;
				y = i;
				System.out.println(x+" "+y);
			}
		}
		t += 1;
		

	}while(t < 3000);
}
}

Measured memory_bytes: 35684
program main
  implicit none
  integer :: x, i, j, t, res
  read(*, *) x
  res = 1
  do i = 2, 1000
    do j = 2, 40
      t = i ** j
      if (t > x) exit
      res = max(res, t)
    end do
  end do

  write(*, "(i0)") res

end program main


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for(int i = a; i < n; i++)
#define per(i, a, n) for (int i = n-1; i >= a ; i--)
#define vi vector<long long int>
#define mii map<long long int, long long int>
#define pii pair<long long int, long long int>
#define pqmax priority_queue<long long int>
#define pqmin priority_queue<long long int, vector<long long int>, greater<long long int>>
#define setbits(x) __builtin_popcountll(x)
#define zerobits(x) __builtin_ctzll(x)
#define pb push_back
#define mp make_pair
#define sp(x, y) fixed<<setprecision(y)<<x
#define ll long long
#define MOD 1000000007

const int N = 100001;
void solve(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	int r = 0, g = 0, b = 0;
	for(int i = 0; i < n; i++){
		if(s[i] == 'R') r++;
		else if(s[i] == 'G') g++;
		else b++;
	}
	ll count = 1LL*r*g*b;
	// cout << count << endl;
	for(int i = 0; i < n-2; i++){
		for(int j = i+1; j < n-1; j++){
			int k = 2*j - i;
			if(k >= n) continue;
			if(s[i] != s[j] && s[j] != s[k] && s[i] != s[k]){
				count--;
				// cout << i << j << k << endl;
			}
		}
	}
	cout << count << "\n";
}

int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
   	solve();
    return 0;
}			


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

template<class T> ll llpow(T x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}

#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep2(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)

long long INF = 1LL<<60;
int main(){
    int n;
    int m;
    cin>>n>>m;
    using pbb=pair<bool,bool>;
    pbb manage[n+1];
    rep(i,m){
        int a,b;
        cin>>a>>b;
        if(a==1)manage[b].first=true;
        else if(b==n)manage[a].second=true;
    }
    for(int i=2;i<n;i++){
        if(manage[i].first&&manage[i].second){
            cout<<"POSSIBLE"<<endl;
            return 0;
        }
       }
    cout<<"IMPOSSIBLE"<<endl;
    return 0;
}




Measured memory_bytes: 640
#include <cstdio>
#include <cstring>

const int N = 1 << 20;
int n;
char s[N];

int main() {
	scanf("%s", s);
	n = strlen(s);
	long long ans = 0;
	int cnt = 0;
	for (int i = 0; i < n; ++ i) {
		if (s[i] == 'W') ans += cnt;
		else cnt ++;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 384
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

import math

t1,t2 = na()
a1,a2 = na()
b1,b2 = na()

p = a1*t1
q = b1*t1
x = p + a2*t2
y = q + b2*t2

if x < y:
  if p < q:
    print(0)
  elif p == q:
    print(1)
  elif p > q:
    print(int((p-q) / (y-x)) + math.ceil((p-q) / (y-x)))
elif x == y:
  print("infinity")
elif x > y:
  if p < q:
    print(int((q-p) / (x-y)) + math.ceil((q-p) / (x-y)))
  elif p == q:
    print(1)
  elif p > q:
    print(0)

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

ll inf=1e18;

vector<ll>par(2e5+10);
void init(ll n) {
  for(ll i=0;i<n;i++) {
    par[i]=i;
  }
}

ll root(ll x) {
  if(par[x]==x) {
    return x;
  }
  else {
    return par[x]=root(par[x]);
  }
}

bool same(ll x, ll y) {
  return root(x)==root(y);
}

void unite(ll x, ll y) {
  if(same(x,y)) return;
  par[root(x)]=root(y);
}

int main() {
  ll n,m;
  cin >> n;
  init(2*n);
  vector<set<ll>> v(n);
  vector<string> s(n);
  vector<vector<ll>> d(n,vector<ll> (n,inf));
  for(ll i=0;i<n;i++) {
    cin >> s[i];
  }
  for(ll i=0;i<n;i++) {
    for(ll j=i+1;j<n;j++) {
      if(s[i][j]=='1') {
        d[i][j]=1;
        d[j][i]=1;
        if(same(i,j)||same(i+n,j+n)) {
          cout << -1 << endl;
          return 0;
        }
        else {
          unite(i,j+n);
          unite(j,i+n);
        }
      }
    }
  }
  for(ll i=0;i<n;i++) {
    d[i][i]=0;
  }
  for(ll k=0;k<n;k++) {
    for(ll i=0;i<n;i++) {
      for(ll j=0;j<n;j++) {
        d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
      }
    }
  }
  ll ans=0;
  for(ll i=0;i<n;i++) {
    for(ll j=0;j<n;j++) {
      ans=max(ans,d[i][j]);
    }
  }
  cout << ans+1 << endl; 
}

Measured memory_bytes: 2176
// 1, 2, 5 10, 20, 50, 100, 200, 500, 2000

//change->137

#include <bits/stdc++.h>
using namespace std;
int main()
{
	int m1, d1; cin>>m1>>d1;
	int m2, d2; cin>>m2>>d2;
	int ref[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
	if(d1==ref[m1-1])
		cout<<1<<"\n";
	else
		cout<<0<<"\n";
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        List<Integer> list = Arrays.asList(scanner.nextInt(), scanner.nextInt());
        List<Integer> list1 = Arrays.asList(1, 3, 5, 7, 8, 10, 12);
        List<Integer> list2 = Arrays.asList(4, 6, 9, 11);
        List<Integer> list3 = Collections.singletonList(2);
        System.out.println(list1.containsAll(list) || list2.containsAll(list) || list3.containsAll(list) ? "Yes" : "No");
    }
}

Measured memory_bytes: 20820
n, m = map(int, input().split())
light = [
    tuple(map(int, input().split())) for i in range(m)
]
p = tuple(map(int, input().split()))

ans = 0
for i in range(2**n):
    x = str(bin(i))[2:]
    if len(x) < n:
        x = "0" * (n - len(x)) + x
    a = 1
    for j in range(m):
        check = 0
        for k in light[j][1:]:
            if x[k-1] == "1":
                check += 1
        if check % 2 != p[j]:
            a = 0
            break
    if a:
        ans += 1
print(ans)


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

using namespace std;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  vector<bool> selected(101, false);
  for (int i = 1; i < 1000; ++i) {
    int tmp = (b * i + c) % a;
    if (tmp == 0) {
      cout << "YES" << endl;
      break;
    }
    else if (selected[tmp]) {
      cout << "NO" << endl;
      break;
    }
    else {
      selected[tmp] = true;
    }
  }
}


Measured memory_bytes: 3616
#include <iostream>
#include <string>
#include <set>

using namespace std;

int main() {
    int N;
    string str;
    cin >> N;
    set<string> s;

    while (N--) {
        cin >> str;
        s.insert(str);
    }
    cout << s.size() << endl;
    return 0;
}

Measured memory_bytes: 19256
# https://atcoder.jp/contests/abc145/tasks/abc145_c

def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
INF = float("inf")
import itertools

N = INT()
xy = [tuple(MAP()) for _ in range(N)]

dist_list=[]
for i in itertools.permutations(xy, N):
    dist = 0
    for j in range(1, N):
        dist += ((i[j-1][0]-i[j][0])**2 + (i[j-1][1]-i[j][1])**2)**0.5
    dist_list.append(dist)

print(sum(dist_list)/len(dist_list))



Measured memory_bytes: 42092
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
#include <iomanip>

using namespace std;

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

  vector<pair<double, double>> vec;

  for (int i = 0; i < n; ++i) {
    double a, b;
    cin >> a >> b;
    vec.push_back(make_pair(a, b));
  }

  sort(vec.begin(), vec.end());

  int cnt = 0;
  double sum = 0.0;
  do {
    for (int i = 1; i < n; ++i)
      sum += sqrt(pow(vec[i].first - vec[i - 1].first, 2) +
                  pow(vec[i].second - vec[i - 1].second, 2));
    ++cnt;
  } while (next_permutation(vec.begin(), vec.end()));

  cout << fixed << setprecision(10) << sum / cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){	
	int N,W,w,v,res=0;
	map<int,int> dp;
	dp[0]=0;
	cin>>N>>W;
	while(N--){
		cin>>w>>v;
		for(auto it=dp.rbegin();it!=dp.rend();++it){
			int ws=w+it->first,vs=v+it->second;
			if(ws<=W){
				dp[ws]=max(dp[ws],vs);
				res=max(res,dp[ws]);
			}
		}
	}
	cout<<res<<endl;
}


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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#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 FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll n;
  cin >> n;
  string s,t;
  cin >> s >> t;

  REP(i, n)
    cout << s[i] << t[i];
  cout << endl;
}


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

ll n;

int main() {
	cin >> n;
	vector<int> ans;

	ll p = 1, ct = 0;
	while (2*p - 1 <= n) {
		p *= 2;
		ct++;
	}

	for (int i = 0; i < ct; ++i)
		ans.push_back(i);
	for (int i = 0; i < ct; ++i)
		ans.push_back(i);

	n -= (p-1);
	int k = 60;

	for (ll j = (1LL<<60); j >= 1; j /= 2, k--) {
		if ((n|j) == n) {
			ct++;
			ans.push_back(ct);
			ans.insert(ans.begin() + k, ct);
		}
	}

	cout << ans.size() << endl;
	for (int i : ans)
		cout << i + 1 << ' ';
	cout << endl;
}

Measured memory_bytes: 256