akhauriyash/Code-Regression huggingface dataset:
//In the name of Allah :)
#include <bits/stdc++.h>
using namespace std;
string to_string(char c) { return string(1,c); }
string to_string(bool b) { return b ? "true" : "false"; }
string to_string(const char* s) { return (string)s; }
string to_string(string s) { return s; }
template<class A> string to_string(complex<A> c) { 
	stringstream ss; ss << c; return ss.str(); }
string to_string(vector<bool> v) { 
	string res = "{"; for(int i = 0; i < (int)v.size(); i++) res += char('0'+v[i]);
	res += "}"; return res; }
template<size_t SZ> string to_string(bitset<SZ> b) {
	string res = ""; for(size_t i = 0; i < SZ; i++) res += char('0'+b[i]);
	return res; }
template<class A, class B> string to_string(pair<A,B> p);
template<class T> string to_string(T v) { // containers with begin(), end()
	bool fst = 1; string res = "{";
	for (const auto& x: v) {
		if (!fst) res += ", ";
		fst = 0; res += to_string(x);
	}
	res += "}"; return res;
}
template<class A, class B> string to_string(pair<A,B> p) {
	return "("+to_string(p.first)+", "+to_string(p.second)+")"; }
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {
	cerr << to_string(h); if (sizeof...(t)) cerr << ", ";
	DBG(t...); }
#ifdef LOCAL // compile with -DLOCAL
#define wis(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "] : [", DBG(__VA_ARGS__)
#else
#define wis(...) 0
#endif
typedef long long ll;
const int MOD = 1e9 + 7, INF = 1e9 + 5;
const ll LONG_INF = 1e18 + 10;
inline ll powmod(ll a, ll b){ll res=1;for(;b;b>>=1,a=a*a%MOD)if(b&1)res=res*a%MOD;return res;}
inline ll power(ll a, ll b){ll res=1;for(;b;b>>=1,a=a*a)if(b&1)res=res*a;return res;}

const int MAXN = 2e5 + 10;

int main(){
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
        int n;
        string s;
        cin >> n >> s;
        int cntr = count(s.begin(), s.end(), 'R'), ans = cntr;
        for(int i = 0; i < cntr; i++){
                if(s[i] == 'R')
                        ans--;
        }
        cout << ans << '\n';

}


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

int main() {
	int n;
	cin>>n;
	int sum=0;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
		sum+=a[i];
	}
	cout<<sum-n<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define ul unsigned long long int
#include<vector>
#define endl "\n"
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define lb lower_bound
#define ub upper_bound
#define mod 1000000007
using namespace std;

int main(){
	int n;
	cin>>n;
	string a,b;
	cin>>a>>b;
	string c;
	for(int i=0;i<n;i++){
		c+=a[i];
		c+=b[i];
	}
	cout<<c;
return 0;
}

Measured memory_bytes: 256
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXC=2000000;
const int MOD=1000000007;
typedef struct P { int x,y; } P;
P p[6];

int inv[MAXC+1];
int fac[MAXC+1];
int ifac[MAXC+1];

int C(int n,int k) { if(!(n<=MAXC&&k>=0&&k<=n)) { printf("C(%d,%d)\n",n,k); return 0; } return (ll)fac[n]*ifac[k]%MOD*ifac[n-k]%MOD; }

int calc(P s,P a,P b,P t) {
	//printf("(%d,%d)-rect-(%d,%d)\n",s.x,s.y,t.x,t.y);
	int dx=t.x-s.x,dy=t.y-s.y,ax=a.x-s.x,bx=b.x-s.x,ay=a.y-s.y,by=b.y-s.y;
	ll ret=0;
	FORE(x,ax,bx) ret-=(ll)C(x+ay-1,x)*C(dx-x+dy-ay,dx-x)%MOD*(x+ay)%MOD;
	FORE(y,ay,by) ret-=(ll)C(y+ax-1,y)*C(dy-y+dx-ax,dy-y)%MOD*(y+ax)%MOD;
	FORE(x,ax,bx) ret+=(ll)C(x+by,x)*C(dx-x+dy-by-1,dx-x)%MOD*(x+by+1)%MOD;
	FORE(y,ay,by) ret+=(ll)C(y+bx,y)*C(dy-y+dx-bx-1,dy-y)%MOD*(y+bx+1)%MOD;
	ret%=MOD; if(ret<0) ret+=MOD;
	//printf("=%lld\n",ret);
	return ret;
}

void run() {
	inv[1]=1; FORE(i,2,MAXC) inv[i]=(ll)(MOD-MOD/i)*inv[MOD%i]%MOD;
	fac[0]=1; FORE(i,1,MAXC) fac[i]=(ll)fac[i-1]*i%MOD;
	ifac[0]=1; FORE(i,1,MAXC) ifac[i]=(ll)ifac[i-1]*inv[i]%MOD;

	REP(i,6) scanf("%d",&p[i].x); REP(i,6) scanf("%d",&p[i].y);
	int ret=0;
	REP(i,4) REP(j,4) {
		P s; s.x=i/2==0?p[0].x-1:p[1].x; s.y=i%2==0?p[0].y-1:p[1].y; int ms=i==0||i==3?+1:-1;
		P t; t.x=j/2==0?p[4].x:p[5].x+1; t.y=j%2==0?p[4].y:p[5].y+1; int mt=j==0||j==3?+1:-1;
		int cur=calc(s,p[2],p[3],t);
		ret=((ll)ret+ms*mt*cur+MOD)%MOD;
	}
	printf("%d\n",ret);
}

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


Measured memory_bytes: 23808
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int ,int> P;
#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
template <class T> void cumulative_sum( T array, size_t N );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;

int main( void ){
	string S;
	cin >> S;
	vector<bool> array(26, false);
	rep(i,0,S.length()){
		int index = ((char)S[i] - (char)'a');
		if (!array[index])
			array[index] = true;
	}
	rep(i,0,26){
		if (!array[i]){
			cout << (char)(i+(char)'a') << endl;
			return 0;
		}
	}
	cout << "None\n";
}

int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
template <class T> void cumulative_sum( T array, size_t N ) {
	rep( i, 1, N + 1 ){
		array[ i ] += array[ i - 1 ];
	}
}
template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define INF (1 << 30) - 1
#define LINF 1LL << 60
const int MOD = 1000000007;
using ll = long long;
using P = pair<int, int>;

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

  vector<vector<int>> c_cusum(h + 1, vector<int>(w, 0));
  for(int j = 0; j < w; ++j){
  	for(int i = 0; i < h; ++i){
  		c_cusum[i + 1][j] = c_cusum[i][j] + s[i][j];
  	}
  }

  int ans = INF;
  for(int b = 0; b < 1 << (h - 1); ++b){
  	int cnt = 0;
  	vector<int> h_lines;
  	h_lines.push_back(0); 
  	for(int i = 0; i < h - 1; ++i){
  		if(b & (1 << i)){
  			++cnt;
  			h_lines.push_back(i + 1); 
  		}
  	}
  	h_lines.push_back(h); 
  	vector<int> block(h_lines.size() - 1, 0);
  	bool flg = true;
  	for(int x = 0; x < w; ++x){
  		for(int y = 0; y < block.size(); ++y){
  			int idx = h_lines[y];
  			int idx2 = h_lines[y + 1];
  			int block_sum = c_cusum[idx2][x] - c_cusum[idx][x];
  			block[y] += block_sum;
  			if(block[y] > k){
  				if(block[y] == block_sum){
  					flg = false;
  					break;
  				}
  				block = vector<int>(h_lines.size() - 1, 0);
  				--x;
  				++cnt;
  				break;
  			}
  		}
  		if(!flg){
  			cnt = INF;
  			break;
  		}
  	}

  	ans = min(ans, cnt);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 384
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

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

        int a = Integer.parseInt(scan.next());
        ArrayList<Integer> list = new ArrayList<>();
        int count = 0;
        boolean tall = false;
        for (int i = 0; i < a; i++) {
            list.add(Integer.parseInt(scan.next()));
        }
        for (int i = 1; i < a; i++) {
            for(int h = 0;h<i;h++){
                if(list.get(i)>=list.get(h)){
                    tall = true;
                }else{
                    tall = false;
                }
                if(!tall){
                    break;
                }
            }
            if(tall){
                count += 1;
            }
        }
        count += 1;
        PrintWriter out = new PrintWriter(System.out);
        out.println(count);
        out.flush();
        scan.close();
    }
}

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


int main() {
    int N;cin >> N;
    vector<int> T(N);
    int S;
    for (int i = 0;i < N;i++){
        int t;cin >> t;
        T.at(i) = t;
        S+=t;
    }
    int M;cin >> M;
    for (int i = 0;i < M;i++){
        int p,x;cin >> p >> x;
        int d;
        d = T.at(p-1)-x;
        cout << S-d << endl;
    }



}       

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
// std::cout << std::setprecision(2) << 3.141; // "3.1"
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;

static const int giga = pow(10,9);
// double pi = 3.141592653589793238463;

int main(void){
  int H,W;
  cin >> H >> W;
  int h,w;
  cin >> h >> w;

  cout << H*W-(h*W+w*H-h*w) << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <assert.h>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,a) for(ll i=ll(a-1);i>=0;--i)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}

const ll INF = 1e10;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ll EPS = 1e-10;
int sgn(const double a){
    return (a < -EPS ? -1 : (a > EPS ? +1 : 0));
}
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> tri;
typedef pair<double,double> point;
typedef complex<double> Point;
const ll MAX = 30000;
constexpr ll nx[8] = {1,0,-1,0,1,-1,1,-1};
constexpr ll ny[8] = {0,1,0,-1,1,1,-1,-1};
vector<bool> is_prime(101,1);
void init(){
    is_prime[0] = is_prime[1] = 0;
    rep(i,2,101){
        if (is_prime[i]){
            for (ll j = 2*i;j < 101;j += i){
                is_prime[j] = 0;
            }
        }
    }
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    init();
    ll n;
    cin >> n;
    vector<ll> factor(101,0);
    rep(i,1,n+1){
        ll b = i;
        rep(j,i+1){
            if (is_prime[j]){
                while (b%j == 0){
                    factor[j]++;
                    b /= j;
                }
            }
        }
    }
    // 3 5 15 25 75
    vector<ll> cnt(5);
    rep(i,n+1){
        if (factor[i] >= 2) cnt[0]++;
        if (factor[i] >= 4) cnt[1]++;
        if (factor[i] >= 14) cnt[2]++;
        if (factor[i] >= 24) cnt[3]++;
        if (factor[i] >= 74) cnt[4]++;
    }
    ll ans = cnt[4]+cnt[3]*max(cnt[0]-1,0ll)+cnt[2]*max(cnt[1]-1,0ll)+cnt[1]*(cnt[1]-1)/2*max(cnt[0]-2,0ll);
    PRINT(ans);
}



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

int main ()
{
    int n, m;
    while (cin >> n >> m, n || m) {
        vector<int> x(n);
        vector<int> y(m);

        for (auto &i : x) {
            cin >> i;
        }

        for (auto &i : y) {
            cin >> i;
        }

        vector<int> dis_x;
        for (int i = 0; i < n; i++) {
            int dis = 0;
            for (int j = i; j < n; j++) {
                dis += x[j];
                dis_x.push_back(dis);
            }
        }

        vector<int> dis_y;
        for (int i = 0; i < m; i++) {
            int dis = 0;
            for (int j = i; j < m; j++) {
                dis += y[j];
                dis_y.push_back(dis);
            }
        }

        sort(dis_x.begin(), dis_x.end());
        sort(dis_y.begin(), dis_y.end());

        int res = 0;
        for (int i = 0; i < dis_x.size(); i++) {
            int count_x = 1;
            while (dis_x[i + count_x] == dis_x[i]) count_x++;

            auto up =  upper_bound(dis_y.begin(), dis_y.end(), dis_x[i]);
            auto lo =  lower_bound(dis_y.begin(), dis_y.end(), dis_x[i]);
            if (up != dis_y.end() || lo != dis_y.end())
                res += count_x * (up - lo);

            i += count_x - 1;
        }

        cout << res << endl;
    }


    return 0;
}

Measured memory_bytes: 21136
import fractions as frc
N,M=map(int,input().split())
S = input()
T = input()
L = (N*M)//frc.gcd(N,M)
n = L//N
m = L//M
d = {}
for i in range(N):
    d[n*i] = S[i]
for i in range(M):
    if m*i in d:
        if d[m*i] != T[i]:
            print(-1)
            exit()
print(L)

Measured memory_bytes: 17576
#include <algorithm>
#include <string.h>
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;

string s;

int main() {
	cin >> s;

	if (s[0] == s[1] && s[1] == s[2])
		puts("No");
	else
		puts("Yes");

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
  string s;
  cin>>s;
  if(s=="SUN"){
      cout<<7<<endl;
  }
  else if(s=="MON"){
      cout<<6<<endl;
  }
  else if(s=="TUE"){
      cout<<5<<endl;
  }
  else if(s=="WED"){
      cout<<4<<endl;
  }
  else if(s=="THU"){
      cout<<3<<endl;
  }
  else if(s=="FRI"){
      cout<<2<<endl;
  }
  else {
      cout<<1<<endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(i=0;i<N;i++)
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL;
  typedef pair<ll,char> PLC;
  typedef pair<char,ll> PCL;

int main(void){
  int N;cin >> N;
  vector<vector<int> > to(N),cost(N);
  int i;
  REP(i,N-1){
    int a,b,w; cin >> a >> b >> w;
    a--;b--;
    to[a].push_back(b);cost[a].push_back(w%2);
    to[b].push_back(a);cost[b].push_back(w%2);
  }
  vector<int> ans(N,-1);
  queue<int> que;
  ans[0] = 0;
  que.push(0);
  while(!que.empty()){
    int v = que.front();que.pop();
    REP(i,to[v].size()){
      int u = to[v][i];
      int w = cost[v][i];
      if(ans[u] != -1)continue;
      ans[u] = (ans[v]+w)%2;
      que.push(u);
    }
  }
  REP(i,N){
    cout << ans[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 11904
import java.util.*;
import java.lang.*;
import java.io.*;
class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int a = sc.nextInt();
			char op = sc.next().charAt(0);
			int b = sc.nextInt();
			if(op == '+') {
				System.out.println(a + b);
			}
			if(op == '-') {
				System.out.println(a - b);
			}
			if(op == '*') {
				System.out.println(a * b);
			}
			if(op == '/') {
				System.out.println(a / b);
			}
			if(op == '?') {
				break;
			}
		}
	}
}


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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
using ll = long long;
using ld = long double;
const int MOD = 1e9 + 7;

int main() {
    int n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    string s; cin >> s;

    s = '#' + s + '#';
    for(int i = a; i + 1<= c; i++){
        if(s[i] == '#' && s[i + 1] == '#'){
            cout << "No" << endl;
            return 0;
        }
    }
    for(int i = b; i + 1 <= d; i++){
        if(s[i] == '#' && s[i + 1] == '#'){
            cout << "No" << endl;
            return 0;
        }
    }
    if(d < c){
        bool flag = false;
        for(int i = b; i <= d; i++){
            if(s[i - 1] == '.' && s[i] == '.' && s[i + 1] == '.'){
                flag = true;
            }
        }
        if(!flag){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 3884
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.ascii;


void main()
{
  auto s = readln.chomp;
  auto w = ["Sunny", "Cloudy", "Rainy"];

  foreach (i; 0..3) {
    if (s == w[i]) {
      w[(i+1)%3].writeln;
    }
  }
}


Measured memory_bytes: 256
S = input()

N_Flag = True if 'N' in S else False
E_Flag = True if 'E' in S else False
W_Flag = True if 'W' in S else False
S_Flag = True if 'S' in S else False

if ((N_Flag is S_Flag) and (E_Flag is W_Flag)):
    print ("Yes")
else:
    print ("No")

Measured memory_bytes: 3064
def main():
    N, K = (int(i) for i in input().split())
    ans = 0
    for i in range(1, N+1):
        cur = i
        cur_p = 1/N
        while cur < K:
            cur *= 2
            cur_p /= 2
        ans += cur_p
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38896
import sys
n = int(input())
a = list()
for i in range(n):
    a.append(input())
b = list()
for i in range(n):
    if a[i] not in b:
        b.append(a[i])
    else:
        continue
if len(b) != len(a):
    print("No")
    sys.exit()
for i in range(len(b)-1):
    if b[i][-1] == b[i+1][0]:
        pass
    else:
        print("No")
        break
else:
    print("Yes")

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

struct union_find{
    union_find(int n){
        for(int i=0; i<=n; i++){
            par.push_back(i);
            depth.push_back(0);
        }
    }

    int find(int x){
        if(par[x]==x) return x;
        else return par[x] = find(par[x]);
    }
    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y) return;

        if(depth[x] < depth[y]){
            par[x] = y;
        }else{
            par[y] = x;
            if(depth[x] == depth[y]) depth[x]++;
        }
    }
    bool find(int x, int y){
        return find(x) == find(y);
    }

    private:
        vector<int> par, depth;
};

int main(){
    int N, K, L;  cin >> N >> K >> L;
    union_find road(N), rail(N);
    for(int i=0; i<K; i++){
        int p, q;  cin >> p >> q;
        road.unite(p,q);
    }
    for(int i=0; i<L; i++){
        int p, q;  cin >> p >> q;
        rail.unite(p,q);
    }

    vector<pair<int,int>> cap(N+1);
    map<pair<int,int>, int> ans;
    for(int i=1; i<=N; i++){
        cap[i].first = road.find(i);
        cap[i].second = rail.find(i);
        if(ans.find(cap[i]) == ans.end()) ans[cap[i]] = 1;
        else ans[cap[i]]++;
    }

    for(int i=1; i<=N; i++){
        cout << ans[cap[i]] << " ";
    }cout << endl;
}


Measured memory_bytes: 16660
#include <iostream>
#include <string>
using namespace std;
// const string S = "(1+1)*2";
string S;
int cur = 0;
int digit();
int number();
int factor();
int term();
int _term(int m);
int exp();
int _exp(int m);
int parse();
bool isdigit(char);
bool is_plu_min(char);
bool is_tim_div(char);
int main() {
  int N;
  cin >> N;
  for (int i=0;i<N;i++) {
    cin >> S;
    cur = 0;
    S.resize(S.size()-1);
    cout << parse() << endl;
  }
  return 0;
}
int digit() {
  int n = S[cur] - '0';
  cur++;
  return n;
}
int number() {
  int n = digit();
  while (cur < S.size() && isdigit(S[cur]))
    n = n*10 + digit();
  return n;
}
bool isdigit(char c) {
  if (c <= '9' and c >= '0') return true;
  else return false;
}
bool is_plu_min(char c) {
  if (c == '+' || c == '-') return true;
  else return false;
}
bool is_tim_div(char c) {
  if (c == '*' || c == '/') return true;
  else return false;
}
// exp    = term exp`
// exp`   = + term exp` | eps
// term   = factor term`
// term`  = * factor term` | eps
// factor = ( exp ) | num
int term() {
  int n = factor();
  return _term(n);
}
int _term(int m) {
  int n = m;
  switch (S[cur]) {
    case '*':
      cur++;
      n *= factor();
      return _term(n);
    case '/':
      cur++;
      n /= factor();
      return _term(n);
    default:
      return n;
  }
}
int factor() {
  if (S[cur] != '(') return number();
  else {
    cur++;
    int n = exp();
    cur++;
    return n;
  }
}
int exp() {
  int n = term();
  return _exp(n);
}
int _exp(int m) {
  int n = m;
  switch (S[cur]) {
    case '+':
      cur++;
      n += term();
      return _exp(n);
    case '-':
      cur++;
      n -= term();
      return _exp(n);
    default:
      return n;
  }
}
int parse() {
  return exp();
}

Measured memory_bytes: 3036
#include <bits/stdc++.h>
using namespace std;
 
//long long
using ll = long long;
 
// pair<int, int>
using PII = pair<int, int>;
 
//最大値、mod
const int MOD = 1000000007;
const int INF = 1000000000;
const long long LINF = 1e18;
const int MAX = 510000;
 
//出力系
#define print(x) cout << x << endl
#define prints(x) cout << fixed << setprecision(10) << x << endl
#define printc(x) cout << setw(2) << setfill('0') << x << endl;
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()
 
//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
 
//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
 
// 最小公倍数
unsigned lcm(unsigned a, unsigned b){
    return a / gcd(a, b) * b; 
}
 
// a = max(a, b), a = min(a, b)
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; }
 
// 階乗(MODをとる)
ll pow_mod(ll num, ll pow, ll mod) {
    ll prod = 1;
    num %= mod;
    while (pow > 0) {
        if (pow & 1) prod = prod * num % mod;
        num = num * num % mod;
        pow >>= 1;
    }
    return prod;
}
 
 
 
// 二項係数(MODとる、1 ≦ k ≦ n ≦ 10^7 程度)
// COMinit()
// COM(x, y)
// とコンビで使う
 
// テーブルを作る前処理
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long 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] % MOD) % MOD;
}

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



struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};




int main(){
  int a, b, c;
  cin >> a >> b >> c;
  cout << c << ' '<< a << ' ' << b;
  return 0; 
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main()
{
	int c,x,y,a,b;
	scanf("%d%d%d",&c,&x,&y);
	a=abs(x-c);
	b=abs(y-c);
	if(a<b)
		printf("A\n");
	else if(b<a)
		printf("B\n");

	return 0;
}


Measured memory_bytes: 128
from sys import stdin
import numpy as np
import math

N = int(input())
A = [int(input()) for i in range(5)]

time = 4 + math.ceil(N/min(A))
print(time)



"""
# 題意をそのまま表したコード（超遅い）
place = np.zeros(6)
place[0] = N
cnt = 0
while(True):
  cnt += 1
  place[5] += min(A[4], place[4])
  place[4] += min(A[3], place[3]) - min(A[4], place[4])
  place[3] += min(A[2], place[2]) - min(A[3], place[3])
  place[2] += min(A[1], place[1]) - min(A[2], place[2])
  place[1] += min(A[0], place[0]) - min(A[1], place[1])
  place[0] -= min(A[0], place[0])
  if int(place[5]) == N:
    break
    
ans = cnt  
print(ans)
"""




Measured memory_bytes: 12432
N = int(input())
a = []
 
for _ in range(N):
    a.append(int(input()) - 1)

i, count = 0, 0
success = False
for _ in range(N):
    i = a[i]
    count += 1

    if i == 1:
        success = True
        break
 
if not success:
    count = -1
 
print(count)

Measured memory_bytes: 12788
#include"bits/stdc++.h"
using namespace std;
#define LL long long

LL N,M,K,ans,r;
LL a, b;
string s;
int main() {

	cin >> s;
	LL ch=s.size()-1;
	while (1) {
		if (ch < 4)break;
		if (s.substr(ch - 4, 5)=="dream"|| s.substr(ch - 4, 5) == "erase"){

			ch -= 5;
		}
		else if ( s.substr(ch - 5, 6) == "eraser") {

			ch -= 6;
		}
		else if (s.substr(ch - 6, 7) == "dreamer") {

			ch -= 7;
		}
		else {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES"<<endl;

	return 0;

}


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

using namespace std;
const int INF = 99999999;

void solve()
{
	int n, m, s, g1, g2;
	while(cin >> n >> m >> s >> g1 >> g2, n || m || s || g1 || g2)
	{
		--s;
		--g1;
		--g2;
		int d[101][101];
		for(int i = 0; i < n; ++i)
		{
			for(int j = 0; j < n; ++j)
			{
				d[i][j] = INF;
			}
			d[i][i] = 0;
		}
		for(int i = 0; i < m; ++i)
		{
			int From, To, Cost;
			cin >> From >> To >> Cost;
			--From;
			--To;
			d[From][To] = Cost;
		}
		for(int k = 0; k < n; ++k)
		{
			for(int i = 0; i < n; ++i)
			{
				for(int j = 0; j < n; ++j)
				{
					d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
				}
			}
		}
		int Min = INF;
		for(int i = 0; i < n; ++i)
		{
			Min = min(Min, d[s][i] + d[i][g1] + d[i][g2]);
		}
		cout << Min << endl;
	}
}

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

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>  // Including tree_order_statistics_node_update

using namespace __gnu_pbds;
using namespace std;

#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define tr(c, i) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define present(c, x) ((c).find(x) != (c).end())
#define cpresent(c, x) (find(all(c), x) != (c).end())
#define minei(x) min_element(x.begin(), x.end()) - (x).begin()
#define maxei(x) max_element(x.begin(), x.end()) - (x).begin()
#define LSOne(S) (S & (-S))

#define uns(v) sort((v).begin(), (v).end()), v.erase(unique(v.begin(), v.end()), v.end())
#define acusum(x) accumulate(x.begin(), x.end(), 0)
#define acumul(x) accumulate(x.begin(), x.end(), 1, multiplies<int>());
#define bits(x) __builtin_popcount(x)
#define oo INT_MAX
#define inf 1000000000
#define MAXN 1000007
#define MOD 1000000007

const double pi = acos(-1.0);
const double eps = 1e-11;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

int main() {
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    char c;
    cin >> c;
    if (c >= 'a' && c <= 'z')
        cout << "a\n";
    else
        cout << "A\n";

    return 0;
}


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

int main() {
  int n,m;
  cin >> n >> m;
  if(n == m) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

using namespace std;

template <class TH> void _dbg(const char *sdbg, TH h){cerr<<sdbg<<"="<<h<<"\n";}
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')
    cerr<<*sdbg++;
  cerr<<"="<<h<<","; 
  _dbg(sdbg+1, a...);
}

template<class T> ostream & operator<<(ostream & os, vector<T> V){
  os<<"[";
  for(auto vv: V) os << vv <<",";
  return os << "]";
}
template<class L, class R> ostream & operator <<(ostream & os, pair<L,R> P){
  return os <<"("<<P.first <<","<<P.second <<")";
}

#ifdef DEBUG
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

const int N = 1000005;

int x, n;
int A[N];
int cnt[N];
int bad[N];

int main() {
    
    scanf("%d", &n);
    int mx = 0;
    for (int i = 1; i <= n; i++) {
        scanf("%d", &A[i]);
        mx = max(mx, A[i]);
        cnt[A[i]]++;
    }
    
    for (int i = 1; i <= mx; i++) {
        if (cnt[i]) {
            for (int j = 2 * i; j <= mx; j += i) {
                bad[j] = true;
            }
        }
    }
    
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        if (cnt[A[i]] == 1 && !bad[A[i]]) {
            ans++;
        }
    }
    
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 12220
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>

using namespace std;

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

static const double eps = 10e-6;

struct Edge{
	int b;
	int x;
	int y;
};

vector<int> get_path(int t,int* prev){
	vector<int> path;
	for(; t!=-1; t = prev[t]) path.push_back(t);
	reverse(path.begin(),path.end());
	return path;
}

vector<int> dijkstra(int src,int dst, const vector<Edge>& edge){
	
	double d[1001];
	int prev[1001];
	bool used[1001];

	fill((double*)d,(double*)d+1001,10000000.0);
	fill((bool*)used,(bool*)used+1001,false);
	fill((int*)prev,(int*)prev+1001,-1);

	d[src] = 0.0;	

	while(true){

		int v = -1;
		for(int u=0;u<edge.size();u++){
			if(!used[u] && (v == -1 || d[u] < d[v])) v = u;
		}

		if(v == -1) break;
		used[v] = true;

		int srcX = edge[v].x;
		int srcY = edge[v].y;

		for(int u=0;u<edge.size();u++){
			if(u==v) continue;
			double cost = sqrt((double)(edge[u].x - srcX) * (double)(edge[u].x - srcX)
				+ (double)(edge[u].y - srcY) * (double)(edge[u].y - srcY));
			if(cost > 50.0) continue;

			if(d[u] > d[v] + cost){
				d[u] = d[v] + cost;
				prev[u] = v;
				//printf("u:%d v:%d\n",u+1,v+1);
			}
		}
	}
/*
	for(int i=0;i<edge.size();i++){
		printf("d[%d]=%d ",i+1,d[i]);
	}
	cout << endl;
*/
	return get_path(dst,prev);
}

int main(){
	string str;

	int n;
	while(~scanf("%d",&n)){
		if(n==0) break;
		vector<Edge> edge;
		for(int i=0;i<n;i++){
			int b,x,y;
			scanf("%d %d %d",&b,&x,&y);
			Edge e = {b,x,y};
			edge.push_back(e);
		}
		int m;
		scanf("%d",&m);

		for(int i=0;i<m;i++){
			int src,dst;
			scanf("%d %d",&src,&dst);
			int src_idx,dst_idx;
			for(int i=0;i<edge.size();i++){
				if(edge[i].b == src){
					src_idx = i;
				}
				if(edge[i].b == dst){
					dst_idx = i;
				}
			}

			vector<int> route = dijkstra(src_idx,dst_idx,edge);

			if(route[0] == src_idx && route[route.size()-1] == dst_idx){
				for(int j=0;j<route.size();j++){
					printf("%d%s",edge[route[j]].b,j == route.size() -1 ? "\n" : " ");
				}
			}
			else cout << "NA" << endl; 
		}
	}
}

Measured memory_bytes: 0
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<unordered_map>
#include<unordered_set>
#include<deque>
#include<cstdio>
using namespace std;
typedef long long int ll;
const int N = 1000000;
const int INF = 1 << 30;
#define rep(i,n) for(int i=(ll)0;i<(ll)n;++i)
#define ALL(x) x.begin(),x.end()
#define pp pair<ll,ll>
string YN(bool b) { return(b ? "YES" : "NO"); }
string yn(bool b) { return(b ? "Yes" : "No"); }
ll h, w, v[110][110],ct=0;
int main(){
	ll n, cts[5] = {},ans=0;
	cin >> n;
	string s;
	rep(i, n){cin >> s;
	if (s[0] == 'M')cts[0]++;
	if (s[0] == 'A')cts[1]++;
	if (s[0] == 'R')cts[2]++;
	if (s[0] == 'C')cts[3]++;
	if (s[0] == 'H')cts[4]++;
	}
	rep(i, 5)for (int j = i + 1; j < 5; ++j)for (int k = j + 1; k < 5; ++k)ans +=(ll)cts[i] * cts[j] * cts[k];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#pragma region header
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cctype>
#include <assert.h>
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
#include <cstring>
#include <array>
using namespace std;
using lint = long long;
using ld = long double;
const int dx[] = { 1,0,-1,0 };
const int dy[] = { 0,1,0,-1 };
#pragma endregion

const lint INF = 1ll << 60;
const int mod = 1000000007;

int n;
vector<pair<int, int>> d;
vector<char> e;
vector<vector<pair<int, char>>> data1;
vector<vector<pair<int, char>>> data2;

void rotation() {
	for (int i = 0; i < n; i++) {
		int s = d[i].first;
		d[i].first = d[i].second;
		d[i].second = 200000 - s;
		if (e[i] == 'U') {
			e[i] = 'R';
			continue;
		}
		if (e[i] == 'R') {
			e[i] = 'D';
			continue;
		}
		if (e[i] == 'D') {
			e[i] = 'L';
			continue;
		}
		if (e[i] == 'L') {
			e[i] = 'U';
			continue;
		}
	}
}
int solve(vector<pair<int, int>>& d, vector<char>& e) {
	data1.resize(200010);
	data2.resize(400010);
	for (int i = 0; i < n; i++) {
		if (e[i] == 'U' || e[i] == 'D') {
			data1[d[i].first].push_back({ d[i].second,e[i] });
		}
		if (e[i] == 'U' || e[i] == 'R') {
			data2[d[i].first + d[i].second].push_back({ d[i].second,e[i] });
		}
	}
	int cnt = mod;
	for (int i = 0; i < 200002; i++) {
		sort(data1[i].begin(), data1[i].end());
		for (int j = 0; j < (int)data1[i].size() - 1; j++) {
			if (data1[i][j].second == 'U' && data1[i][j + 1].second == 'D') cnt = min(cnt, data1[i][j + 1].first - data1[i][j].first);
		}
	}
	int c = mod;
	for (int i = 0; i < 400005; i++) {
		sort(data2[i].begin(), data2[i].end());
		for (int j = 0; j < (int)data2[i].size() - 1; j++) {
			if (data2[i][j].second == 'U' && data2[i][j + 1].second == 'R') c = min(c, data2[i][j + 1].first - data2[i][j].first);
		}
	}

	data1.clear();
	data2.clear();
	if (cnt == mod && c == mod) return mod;
	else return min(cnt * 5, c * 10);
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin >> n;
	d.resize(n);
	e.resize(n);
	for (int i = 0; i < n; i++) {
		cin >> d[i].first >> d[i].second >> e[i];
	}
	int answer = mod;
	for (int i = 0; i <= 4; i++) {
		answer = min(solve(d, e), answer);
		rotation();
	}
	if (answer == mod) puts("SAFE");
	else cout << answer << endl;

	return 0;
}

Measured memory_bytes: 31316
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    ll n;
    cin>>n;
    ll ans=1;
    while(ans*ans<=n){
        ans++;
    }
    ans--;
    cout<<ans*ans;
}

Measured memory_bytes: 3628
import scala.io.StdIn

object Main extends App {

  val n = StdIn.readLine().toInt
  private val a: Array[Int] = Array.ofDim(45)
  a(0) = 1
  a(1) = 1
  
  def fib(k: Int): Int = {
    if(a(k) != 0){
      a(k)
    } else {
      a(k) = fib(k-1) + fib(k-2)
      a(k)
    }
  }

  println(fib(n))
}


Measured memory_bytes: 43732
s = input()
sm = list(s)
sm1 = [sm[0], sm[1]]
sm2 = [sm[2], sm[3]]
a = int(''.join(sm1))
b = int(''.join(sm2))

if (a >= 1 and a<= 12)and(b >= 1 and b<=12):
    print("AMBIGUOUS")
elif (a >=1 and a<=12) and (b == 0 or b>=13):
    print("MMYY")
elif (a == 0 or a>=13) and (b>=1 and b<=12):
    print("YYMM")
else:
    print("NA")


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    int c[2]={},ch=0,ans=0;
    for(int i=0;i<n;++i){
      string s; cin>>s;
      if(s=="lu" || s=="ru"){
        if(ch==1){
          ans++;
          ch=0;
        }else ch=1;
      }else if(s=="ld" || s=="rd"){
        if(ch==-1){
          ans++;
          ch=0;
        }else ch=-1;
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 3068
#include <iostream>
#include <vector>
using namespace std;
int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  if (n % 2 == 0)
  {
    for (int i = n - 1; i >= 1; i -= 2)
    {
      if (i != n - 1)
        cout << " ";
      cout << a[i];
    }
    for (int i = 0; i < n; i += 2)
      cout << " " << a[i];
  }
  else
  {
    for (int i = n - 1; i >= 0; i -= 2)
    {
      if (i != n - 1)
        cout << " ";
      cout << a[i];
    }
    for (int i = 1; i < n; i += 2)
      cout << " " << a[i];
  }
  cout << '\n';
  return 0;
}

Measured memory_bytes: 2944
#include<iostream>
using namespace std;
int main(){
	int size;
	string s;
	cin>>size>>s;
	long long int r=0,g=0,b=0;
	for(int i=0;i<size;i++){
		if(s[i]=='R')r++;
		else if(s[i]=='G')g++;
		else if(s[i]=='B')b++;
	}
	long long int sum = r*g*b;
	for (int i=0;i<size;i++){
		for(int j=0;i+2*j<size;j++){
			if(s[i]!=s[i+j]&&s[i+j]!=s[i+j*2]&&s[i+j*2]!=s[i])sum--;
		}
	}
	/*
	for(int i=0;i<size;i++){
		for(int j=i+1;j<size;j++){
			for(int k=j+1;k<size;k++){
				if(j-i==k-j){
				}else{
					if(s[i]!=s[j]&&s[j]!=s[k]&&s[k]!=s[i])sum++;
				}
			}
		}
	}
	*/
	cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 3632
def solve():
  m, n = map(int,input().split())
  k = int(input())
  mp = [input() for i in range(m)]
  dp = [[[0] * 3 for j in range(n + 1)] for i in range(m + 1)]
  dic = {"J":0, "O":1, "I":2}

  for i in range(1, m + 1):
    dpi = dp[i]
    dpi_1 = dp[i - 1]

    for j in range(1, n + 1):
      dpij = dpi[j]
      dpij_1 = dpi[j - 1]
      dpi_1j = dpi_1[j]
      dpi_1j_1 = dpi_1[j - 1]

      for p in range(3):
        #dp[i][j][p] = dp[i][j - 1][p] + dp[i - 1][j][p] - dp[i - 1][j - 1][p]
        dpij[p] = dpij_1[p] + dpi_1j[p] - dpi_1j_1[p]

      #dp[i][j][mp[i - 1][j - 1]] += 1
      dpij[dic[mp[i - 1][j - 1]]] += 1
     

  for i in range(k):
    x1,y1,x2,y2 = map(int,input().split())
    dpx2 = dp[x2]
    dpx1 = dp[x1 - 1]
    dpx2y2 = dpx2[y2]
    dpx2y1 = dpx2[y1 - 1]
    dpx1y2 = dpx1[y2]
    dpx1y1 = dpx1[y1 - 1]
    #print(dp[x2][y2][0] - dp[x1 - 1][y2][0] - dp[x2][y1 - 1][0] + dp[x1 - 1][y1 - 1][0], dp[x2][y2][1] - dp[x1 - 1][y2][1] - dp[x2][y1 - 1][1] + dp[x1 - 1][y1 - 1][1], dp[x2][y2][2] - dp[x1 - 1][y2][2] - dp[x2][y1 - 1][2] + dp[x1 - 1][y1 - 1][2])
    print(dpx2y2[0] - dpx1y2[0] - dpx2y1[0] + dpx1y1[0], dpx2y2[1] - dpx1y2[1] - dpx2y1[1] + dpx1y1[1], dpx2y2[2] - dpx1y2[2] - dpx2y1[2] + dpx1y1[2])
solve()


Measured memory_bytes: 195744
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();
        int [] xi = input(sc,n);
        int [] yi = input(sc,m);
        if( judge(x,y,xi,yi) ) {
            System.out.println("No War");
        } else {
            System.out.println("War");
        }
    }
    
    static int[] input(Scanner sc, int len) {
        int [] num = new int [len];
        for(int i = 0; i < len; i++) {
            num[i] = sc.nextInt();
        }
        Arrays.sort(num);
        return num;
    }
    
    static boolean judge(int x, int y, int [] xi, int [] yi) {
        int xMax = xi[xi.length-1];
        int yMin = yi[0];
        if(xMax >= y) {
            return false;
        } else if(yMin <= x) {
            return false;
        } else if(xMax >= yMin) {
            return false;
        }
        return true;
    }
}

Measured memory_bytes: 23124
// ⣿⣿⣿⣿⣿⣿⣿⡿⡛⠟⠿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
// ⣿⣿⣿⣿⣿⣿⠿⠨⡀⠄⠄⡘⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
// ⣿⣿⣿⣿⣿⣿⠿⠨⡀⠄⠄⡘⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
// ⣿⣿⡿⠛⡧⠁⡴⣦⣔⣶⣄⢠⠄⠄⠹⣿⣿⣿⣿⣿⣿⣿⣤⠭⠏⠙⢿⣿⣿⣿⣿⣿
// ⣿⡧⠠⠠⢠⣾⣾⣟⠝⠉⠉⠻⡒⡂⠄⠙⠻⣿⣿⣿⣿⣿⡪⠘⠄⠉⡄⢹⣿⣿⣿⣿
// ⣿⠃⠁⢐⣷⠉⠿⠐⠑⠠⠠⠄⣈⣿⣄⣱⣠⢻⣿⣿⣿⣿⣯⠷⠈⠉⢀⣾⣿⣿⣿⣿
// ⣿⣴⠤⣬⣭⣴⠂⠇⡔⠚⠍⠄⠄⠁⠘⢿⣷⢈⣿⣿⣿⣿⡧⠂⣠⠄⠸⡜⡿⣿⣿⣿
// ⣿⣇⠄⡙⣿⣷⣭⣷⠃⣠⠄⠄⡄⠄⠄⠄⢻⣿⣿⣿⣿⣿⣧⣁⣿⡄⠼⡿⣦⣬⣰⣿
// ⣿⣷⣥⣴⣿⣿⣿⣿⠷⠲⠄⢠⠄⡆⠄⠄⠄⡨⢿⣿⣿⣿⣿⣿⣎⠐⠄⠈⣙⣩⣿⣿
// ⣿⣿⣿⣿⣿⣿⢟⠕⠁⠈⢠⢃⢸⣿⣿⣶⡘⠑⠄⠸⣿⣿⣿⣿⣿⣦⡀⡉⢿⣧⣿⣿
// ⣿⣿⣿⣿⡿⠋⠄⠄⢀⠄⠐⢩⣿⣿⣿⣿⣦⡀⠄⠄⠉⠿⣿⣿⣿⣿⣿⣷⣨⣿⣿⣿
// ⣿⣿⣿⡟⠄⠄⠄⠄⠄⠋⢀⣼⣿⣿⣿⣿⣿⣿⣿⣶⣦⣀⢟⣻⣿⣿⣿⣿⣿⣿⣿⣿
// ⣿⣿⣿⡆⠆⠄⠠⡀⡀⠄⣽⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
// ⣿⣿⡿⡅⠄⠄⢀⡰⠂⣼⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
//        ああ、あなたは私に近づいています
// You thought you would find code here? But it was me DIO
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
#ifdef BOI
#include "debug.h"
#else
#define debug(args...)
#endif
#define all(x) begin(x), end(x)
#define sz(x) (int) x.size()
typedef long long ll;
#define endl '\n'

const ll mod = 1e9 + 7;

bool ok(ll a, ll b, ll c) {
    return a + b > c && b + c > a && c + a > b;
}

int main () {
    cin.tie(0)->sync_with_stdio(0), cin.exceptions(cin.failbit);
// #ifdef BOI
//     freopen("in.txt", "r", stdin);
//     freopen("out.txt", "w", stdout);
// #endif
    ll x, k, d; cin >> x >> k >> d;
    x = abs(x);
    if (x / d >= k) {
        cout << abs(x - k * d);
    } else {
        k -= x / d;
        if (k & 1 ^ 1) x -= d * (x / d);
        else x -= d * (x / d + 1);
        cout << abs(x);
    }
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, m, n) for (int i = m; i <= n; ++i)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;

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

  int n; cin >> n;
  ll a;
  ll sum = 0;
  rep(i, n) {
    cin >> a;
    sum += a;
  }

  if( sum % 2 == 0 ) cout << "YES" << endl;
  else cout << "NO" << endl;

  return 0;
}

Measured memory_bytes: 256
data=[0]*4
pt=[]
for i in range(4):
  data[i]=int(input())

cnt = 0
for i in range(data[2]+1):
    res = data[3]
    for j in range(data[1]+1):
        for k in range(data[0]+1):
            res=50*i+100*j+500*k
            if res==data[3]:
                cnt+=1
                pt.append([i,j,k])
                continue
print(cnt)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI pair<int,int>
#define ff first
#define ss second
#define endl '\n'
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL)
//#include "debug.cpp"
const int inf=1e9;
int n,h;
vector<PI>a;
int32_t main()
{
	boost;

     int h,n;
     cin>>h>>n;
     a.push_back({0,0});
     for(int i=0;i<n;i++){
     	int u,v;
     	cin>>u>>v;
     	a.push_back({u,v});
     }

     int dp[n+1][h+1];
     memset(dp,0,sizeof dp);
    for(int i=1;i<=h;i++)
    	dp[0][i]=inf;
    for(int i=1;i<=n;i++){
    	for(int j=1;j<=h;j++){
    		if(i==1)
    			dp[i][j]=inf;
    		else
    			dp[i][j]=dp[i-1][j];
    		if(j-a[i].ff>=0){
    			dp[i][j]=min(dp[i][j],dp[i-1][j-a[i].ff]+a[i].ss);
    			dp[i][j]=min(dp[i][j],dp[i][j-a[i].ff]+a[i].ss);
    		}
    		else
    			dp[i][j]=min(dp[i][j],a[i].ss);
    	}
    }
    cout<<dp[n][h]<<endl;
}


Measured memory_bytes: 78464
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		
		BigDecimal otosidama = new BigDecimal(0.0);
		for (int i=0; i<num; i++) {
			BigDecimal a = new BigDecimal(sc.next());
			String b = sc.next();
			
			if ("JPY".equals(b)) {
				otosidama = otosidama.add(a);
			} else {
				BigDecimal btc2yen = a.multiply(BigDecimal.valueOf(380000.0));
				otosidama = otosidama.add(btc2yen);
			}
		}
		System.out.println(otosidama.stripTrailingZeros().toPlainString());
	}
}


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

int main(){
  int n, a, b;
  cin >> n >> a;
  b = n % 500;
  if (a >= b){
    cout << "Yes" <<endl;
  }
  else{
    cout << "No" <<endl;
  }
}
  
  
  


Measured memory_bytes: 256
#https://atcoder.jp/contests/abc129/tasks/abc129_b
n = int(input())
w = [int(i) for i in input().split()]
tmp = 100
for t in range(n):
    s1 = 0
    s2 = 0
    for i in range(t+1):
        s1 += w[i]
    for i in range(t+1,len(w)):
        s2 += w[i]
    if abs(s1 - s2) < tmp:
        tmp = abs(s1 - s2)
print(tmp)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define debug(x)   cerr<<#x<<" = "<<x<<endl
#define pii pair<int,int>
#define endl '\n'
#define pb push_back
#define fi first
#define se second 
#define mp make_pair
#define int long long
const int inf = 1e18 + 5;
const int nax = 404;
int arr[nax];
int dp[nax][nax];
int sum[nax][nax];
signed main()
{
    IOS
    int n; cin>>n;
    for(int i=1;i<=n;i++) cin>>arr[i];
    for(int i=1;i<=n;i++)
    {
      for(int j=i;j<=n;j++)
      {
        int s = 0;
        for(int k=i;k<=j;k++) s += arr[k];
        sum[i][j] = s;
      }
    }
    for(int i=1;i<=n;i++)
    {
      for(int j=i;j<=n;j++)
      {
        int s = 0;
        for(int k=i;k<=j;k++) s += arr[k];
        sum[i][j] = s;
      }
    }
    for(int i=n;i>=1;i--)
    {
      for(int j=i;j<=n;j++)
      {
        if(i == j) dp[i][j] = 0;
        else{
          dp[i][j] = inf;
          for(int k=i;k<j;k++)
          {
            dp[i][j] = min(dp[i][j] , dp[i][k] + dp[k+1][j] + sum[i][k] + sum[k+1][j]);
          }
        }
      }
    }
    cout<<dp[1][n]<<endl;
    return 0;
}

Measured memory_bytes: 2816
#include <iostream>
#include <string>
using namespace std;
int main(){
	string base,a,b,c;
	int n;
	int f[27];
	for(cin>>n;n>0;n--){
		cin>>base;
		a=b=c="";
		for(int i=0;i<=26;i++)f[i]=0;
		for(int i=0;i<base.size();i+=3){
			if(f[base[i]-96]==0){
				f[base[i]-96]=1;
				if(a.size()==0)a+=base[i];
				else{
					if(base[i-1]=='>')a+=base[i];
					else{
						b=a;
						a="";
						a+=base[i];
						a+=b;
					}
				}
			}
			
		}
		cout<<a<<endl;
		
	}
	
	return 0;
}


Measured memory_bytes: 1212