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

int a[6], b[6];

double check(double k) {
	double res = 0;
	for (int i=0;i<6;i++) {
		res+=max(k*a[i],(1-k)*b[i]);
	}
	return res;
}

int main() {
	for (int i=0;i<6;i++) scanf("%d",&a[i]);
	for (int i=0;i<6;i++) scanf("%d",&b[i]);
	double low = 0;
	double high = 1;
	for (int r=0;r<80;r++) {
		double one = (low+low+high)/3;
		double two = (low+high+high)/3;
		if (check(one)>check(two)) low = one;
		else high = two;
	}
	printf("%1.9f\n",check(low)/100.);

	return 0;
}

Measured memory_bytes: 256
n = int(input())
dp = [[[[0 for k in range(4)]
           for j in range(4)]
           for i in range(4)]
           for m in range(n + 1)]
T = 0
A = 1
G = 2
C = 3
MOD = 10 ** 9 + 7

dp[0][T][T][T] = 1
for m in range(n):
    for i in range(4):
        for j in range(4):
            for k in range(4):
                for c in range(4):
                    # ijkc
                    #  AGC
                    # A_GC
                    #  GAC
                    #  ACG
                    # AG_C
                    if            j == A and k == G and c == C: continue
                    if i == A            and k == G and c == C: continue
                    if            j == G and k == A and c == C: continue
                    if            j == A and k == C and c == G: continue
                    if i == A and j == G            and c == C: continue
                    dp[m + 1][j][k][c] += dp[m][i][j][k]
                    dp[m + 1][j][k][c] %= MOD

ans = 0
for i in range(4):
    for j in range(4):
        for k in range(4):
            ans += dp[n][i][j][k]
            ans %= MOD

print(ans)

Measured memory_bytes: 3316
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>


typedef long double ld;
typedef long long ll;

using namespace std;

int main() {
	string s;
	cin >> s;
	int n = s.length();
	s += "#";
	for (int i = 0; i < n; i++) {
		for (int j = i; j <= n; j++) {
			string t = s.substr(0, i) + s.substr(j, n - j);
			if (t == "keyence") {
				cout << "YES" << endl;
				return 0;
			} 		
		}
	}
	cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 3548
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)
#define RREP(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define ALL(v) (v).begin(), (v).end()
template<class T>
using reverse_priority_queue = priority_queue<T, vector<T>, greater<T>>;

ll gcd(ll a, ll b) {
    if(a < b){
        return gcd(b, a);
    }
    ll r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

bool check_setwise(const vector<ll>& a){
    ll g = a.at(0);
    for(ll i = 1; i < a.size(); ++i){
        g = gcd(g, a.at(i));
    }
    return g == 1;
}

const ll MAXVAL = 1000000;
bool check_pairwise(const vector<ll>& a){
    vector<bool> is_prime(MAXVAL + 1, true);
    is_prime.at(0) = false;
    is_prime.at(1) = false;
    vector<ll> count(MAXVAL + 1, 0);
    for(ll ai : a){
        count.at(ai)++;
    }

    for(ll i = 2; i <= MAXVAL; ++i){
        if(!is_prime.at(i)){ continue; }
        ll x = count.at(i);
        for(ll j = 2 * i; j <= MAXVAL; j += i){
            is_prime.at(j) = false;
            x += count.at(j);
        }
        if(x >= 2){
            return false;
        }
    }
    return true;
}

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    REP(i, n){ cin >> a.at(i); }

    const bool is_setwise = check_setwise(a);
    if(!is_setwise){
        cout << "not coprime" << endl;
        return 0;
    }
    const bool is_pairwise = check_pairwise(a);
    if(is_pairwise){
        cout << "pairwise coprime" << endl;
    }else{
        cout << "setwise coprime" << endl;
    }
    return 0;
}


Measured memory_bytes: 19020
#include <iostream>

using namespace std;


  int main()
{
   int a, b;     
   cin >> a >> b;
   
   if (a == b)
      cout << "a == b" << endl;
   else if(a > b)
      cout << "a > b" << endl;
   else
      cout << "a < b" << endl;
   
   return 0;
}


Measured memory_bytes: 3096
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000009;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-4;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
typedef vector<vector<ll>> mat;
typedef vector<ll> vec;
mat mtmul(mat &A, mat &B) {
	mat C(A.size(), vec(B[0].size()));
	rep(i, (int)A.size()) {
		rep(k, (int)B.size()) {
			rep(j, (int)B[0].size()) {
				C[i][j] = (C[i][j] + (A[i][k] * B[k][j]) % mod) % mod;
			}
		}
	}
	return C;
}
mat mtpow(mat A, ll n) {
	mat B(A.size(), vec(A.size()));
	rep(i, (int)A.size()) {
		B[i][i] = 1;
	}
	while (n > 0) {
		if (n&(ll)1)B = mtmul(B, A);
		A = mtmul(A, A);
		n >>= 1;
	}
	return B;
}
int main() {

	int w; ll h; int n; int cnt = 1;
	while (cin >> w >> h >> n, w) {
		mat b;
		rep(i, w) {
			vec nex;
			rep(j, w) {
				if (abs(i-j)<=1) {
					nex.push_back(1);
				}
				else {
					nex.push_back(0);
				}
			}
			b.push_back(nex);
		}
		vector<LP> obs; int staobs = w;
		rep(i, n){
			ll x, y; cin >> x >> y; x--; y--;
			if (y == 0)staobs = min(staobs, (int)x);
			else obs.push_back({ y,x });
	    }
		sort(obs.begin(), obs.end());
		vec val;
		rep(i, w) {
			if (i < 1)val.push_back(1);
			else val.push_back(0);
		}
		ll now = 0;
		rep(i, obs.size()) {
			bool nouse[76] = {};
			ll ny = obs[i].first; nouse[obs[i].second] = true;
			while (i + 1 < obs.size() && ny == obs[i+1].first) {
				i++; nouse[obs[i].second] = true;
			}
			mat need = mtpow(b, ny - now - 1); now = ny;
			vec nextval;
			rep(i, w) {
				ll sum = 0;
				rep(j, w) {
					sum += need[i][j] * val[j]; sum %= mod;
				}
				nextval.push_back(sum);
			}
			val = nextval; nextval.clear();
			if (nouse[0])nextval.push_back(0);
			else nextval.push_back((val[0]+val[1])%mod);
			rep1(i, w - 1) {
				ll sum = val[i - 1] + val[i]; 
				if (i < w - 1)sum += val[i + 1];
				sum %= mod;
				if (nouse[i])sum = 0;
				nextval.push_back(sum);
			}
			val = nextval;
		}
		mat need = mtpow(b, h-1 - now);
		vec nextval;
		rep(i, w) {
			ll sum = 0;
			rep(j, w) {
				sum += need[i][j] * val[j]; sum %= mod;
			}
			nextval.push_back(sum);
		}
		val = nextval;
		cout << "Case " << cnt << ": ";
		cout << val[w - 1] << endl;
		cnt++;
	}
	return 0;
}


Measured memory_bytes: 3240
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;

#define ll long long
const long long llINF = 1LL << 60;
const int iINF = 1LL << 20;
template<class T> inline bool chmin(T& a, T b) { if (b < a) { 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; }

void execute();
int main() 
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);// cin と scanfの併用禁止
    cout << fixed << setprecision(15);
    execute();
    return 0;
}


int N, M, Q;
int a[50], b[50], c[50], d[50];
int A[10];
ll get_score(int depth)
{
    if(depth == N+1){
        ll score = 0;
        for(int i = 0; i < Q; i++){
            if(A[b[i]] - A[a[i]]==c[i]){
                score += d[i];
            }
        }

//        cout << A[0] << A[1] << A[2] << " " << score << endl;

        return score;
    }

    ll score = 0;
    for(int i = A[depth-1]; i <= M; i++){
        A[depth] = i;
        ll v = get_score(depth + 1);
        if(score < v) score = v;
    }
    return score;
}


void execute()
{
    cin >> N >> M >> Q;

    for(int i = 0; i < Q; i++){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--;
        b[i]--;
    }

    ll score = 0;
    for(int i = 1; i <= M; i++){
        A[0] = i;
        ll v = get_score(1);
        if(score < v) score = v;
    }

    cout << score << endl; 
}


Measured memory_bytes: 3648
/*
author: Apoorv Singh
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace std;
using namespace __gnu_pbds;

typedef vector <int> vi;
typedef vector <long long> vl;
typedef pair <int, int> pii;
typedef pair <long long, long long> pll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

#define ll long long
#define pb push_back   
#define all(c) c.begin(), c.end()
#define watch(x) cout << (#x) << " " << (x) << endl;
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = a; i > b; --i)
#define um unordered_map
#define F first
#define S second

ll modulo = 1e9 + 7;

template <class X>

void printarr(X arr[], int n)
{
    for (int i = 0; i < n; ++i)
        cout << arr[i] << " ";
    cout << endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,t;
    cin >> n >> t;
    int ans = INT_MAX;
    FOR(i,0,n)
    {
    	int c,x;
    	cin >> c >> x;
    	if (x <= t)
    		ans = min(ans, c);
    }
    if (ans == INT_MAX)
    	cout << "TLE" << endl;
    else
    	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}
func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0
	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 4
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}
	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner) + 1
	aa := make([]int64, n)
	dec := newDecomposition(n + 1)
	for i := 0; i < n; i++ {
		aa[i] = getNextInt64(scanner)
	}
	aa[n-1]--
	dec.rangeadd(0, n-1, 1)
	p := 0
	var ans int64
	ans = int64(n)
	for i := 0; i < n; i++ {
		for aa[i] > 0 {
			if p >= i {
				fmt.Fprintln(writer, -1)
				return
			}
			en := dec.get(p)
			if aa[i] < en {
				dec.rangeadd(p, p+1, -aa[i])
				dec.rangeadd(p+1, i, aa[i])
				ans += aa[i] * int64(i-p)
				aa[i] = 0
				continue
			}
			dec.rangeadd(p, p+1, -en)
			dec.rangeadd(p+1, i, en)
			aa[i] -= en
			ans += en * int64(i-p)
			p++
		}
	}
	fmt.Fprintln(writer, ans)
}

type decomposition struct {
	chunk  int
	bucket [][]int64
}

func newDecomposition(n int) decomposition {
	bucket := make([][]int64, 1)
	bucket[0] = make([]int64, n)
	chunk := 8
	for i := 0; n > 1; i++ {
		n = (n-1)/chunk + 1
		bucket = append(bucket, make([]int64, n))
	}
	return decomposition{
		chunk:  chunk,
		bucket: bucket,
	}
}
func (dec *decomposition) upleft(l int) int {
	return (l + dec.chunk - 1) / dec.chunk
}
func (dec *decomposition) upright(r int) int {
	return r / dec.chunk
}
func (dec *decomposition) get(index int) int64 {
	var value int64
	h := len(dec.bucket)
	for i := 0; i < h; i++ {
		value += dec.bucket[i][index]
		index /= dec.chunk
	}
	return value
}
func (dec *decomposition) rangeadd(l, r int, value int64) {
	dec.rangeaddh(l, r, 0, value)
}
func (dec *decomposition) rangeaddh(l, r, h int, value int64) {
	ll := dec.upleft(l)
	rr := dec.upright(r)
	for i := l; i < r && i < ll*dec.chunk; i++ {
		dec.bucket[h][i] += value
	}
	if ll < rr {
		dec.rangeaddh(ll, rr, h+1, value)
	}
	for i := rr * dec.chunk; i < r && ll <= rr; i++ {
		dec.bucket[h][i] += value
	}
}


Measured memory_bytes: 5296
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <deque>

using namespace std;

int main() {
	int n, q;
	string s;
	cin >> n >> q >> s;

	vector<char> t(q), d(q);
	for (int i = 0; i < q; i++) {
		cin >> t[i] >> d[i];
	}

	s = string("?") + s + string("?");
	int idx_l = 1;
	int idx_r = n;

	for (int i = q - 1; i >= 0; i--) {
		char c = t[i];
		if (d[i] == 'L') {
			if (s[idx_l] == c) {
				idx_l++;
			}
			if (s[idx_r + 1] == c) {
				idx_r++;
			}
		} else {
			if (s[idx_r] == c) {
				idx_r--;
			}
			if (s[idx_l - 1] == c) {
				idx_l--;
			}
		}

		if (idx_l > idx_r) {
			break;
		}
	}

	int ans = idx_r - idx_l + 1;
	cout << ans << endl;

	return 0;
}


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

int main(){
    int n, m, x;
    cin >> n >> m >> x;
    int a[n];
    for(int i = 0; i < m; i++) cin >> a[i];

    int left = 0;
    for(int i = 0; i < x; i++){
        for(int j = 0; j < m; j++){
            if(a[j] == i) left++;
        }
    }
    int right = 0;
    for(int i = x; i < n; i++){
        for(int j = 0; j < m; j++){
            if(a[j] == i) right++;
        }
    }
    int ans;
    ans = min(right, left);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;

char a[100000000 + 5],b[100000000 + 5];

int main(){
	scanf("%s",a + 1);
	long long lena = strlen(a + 1);
	scanf("%s",b + 1);
	long long lenb = strlen(b + 1);
	if(lena > lenb){ printf("GREATER");return 0;}
	else if(lena < lenb) {printf("LESS");return 0;}
	else{
		for(int i = 1;i <= lena;i++){
			if(a[i] > b[i]){
				printf("GREATER");
				return 0;
			}
			if(a[i] < b[i]){
				printf("LESS");
				return 0;
			}	 
			else continue;
		}
	}
	printf("EQUAL");
}

Measured memory_bytes: 2176
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var x = int.Parse(line[0]);
        var y = int.Parse(line[1]);
        Console.WriteLine(x + y - Gcd(x,y) + 1);
    }
    public static int Gcd(int a, int b)
    {
        if (a < b) return Gcd(b, a);
        while (b != 0)
        {
            var w = a % b;
            a = b;
            b = w;
        }
        return a;
    }
}


Measured memory_bytes: 9208
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(a) a.begin(),a.end()
typedef long long ll;
#define INF 1<<30

int main()
{
    string S;
    cin >> S;
    if(S=="AAA"||S=="BBB")cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);

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

  ll n, m;
  cin >> n >> m;
  vector<ll> h(n);
  rep(i, n) cin >> h[i];

  vector<bool> ok(n, true);

  rep(i, m) {
    ll a, b; cin >> a >> b;
    a--; b--;
    if (h[a] >= h[b]) ok[b] = false;
    if (h[a] <= h[b]) ok[a] = false;
  }

  ll ans = 0;
  for (int i = 0; i < n; i++) {
    if (ok[i]) ans++;
  }

  cout << ans << endl;

  return 0;
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define pii pair<int,int>
#define all(x) begin(x), end(x)
#define loop(i,n) for(int i=0; i<n; i++)
#define rep(i,a,b,c) for(int i=a; i<b; i+=c)
#define brep(i,a,b,c) for(int i=a; i>b; i-=c)
#define tc(t) int t; cin>>t; while(t--)
#define sz(v) int((v).size())
#define pb push_back


using namespace std;

void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {std::cout << x;}
void __print(unsigned x) {std::cout << x;}
void __print(unsigned long x) {std::cout << x;}
void __print(unsigned long long x) {std::cout << x;}
void __print(float x) {std::cout << x;}
void __print(double x) {std::cout << x;}
void __print(long double x) {std::cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i : x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
template <typename T> inline void inp(T &any) {cin >> any;} template <typename T, typename... U>inline void inp(T &a, U &...b) {cin >> a; inp(b...);}
#define rin(args...) ll args; inp(args);
#ifndef ONLINE_JUDGE
#define debug(x...) cout << "[" << #x << "] = ["; _print(x)
#define matdeb(mat,row,col) cout << #mat << "::" << endl; printmat(mat,row,col); printpartition;
#define debugv(v,n) cout << #v << ":" << endl; printv(v,0,n-1); printpartition;
#else
#define debug(x...)
#define matdeb(mat,row,col)
#define debugv(v,n)
#endif

const int maxm = 1000000000 + 7;

const ll MOD = 1e9 + 7;
const int INF = 55;
ll dp [INF] [INF * INF];

double startTime;
double getCurrentTime() {
    return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}


//----------->CODE BEGINS --------------->


int main()
{

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

    IOS;

    int k,s;
    cin>>k>>s;

    ll ans = 0;

    loop(i,k+1)
    {
        loop(j,k+1)
        {
            if(s-(i+j)>= 0 && s-(i+j) <= k){
                ans++;
            }
        }
    }

    cout<<ans<<endl;


}


Measured memory_bytes: 3608
n, k = map(int, input().split())
a = list(map(int, input().split()))


fi = 0
for i in range(n):
    if a[i] == 1:
        fi = i
        break

if (n - 1) % (k - 1) == 0:
    print((n - 1) // (k - 1))
else:
    print((n - 1) // (k - 1) + 1)


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

int main()
{
    ll n,t,a,b,c,d,e,p,q,cnt=0;
    map<ll,ll>mp;
    vector<ll>vec;
    string s,s1,s2;
    ll ac=0,tle=0,wa=0,re=0;
    cin>>n;
    ll arr[n+3];
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }

    sort(arr,arr+n);

    ll sum=0;
    sum=arr[n-1];
     ll track=n-2;
    for(int i=n-2;i>=0;i--){
        if(track==0){
            break;
        }
        sum+=arr[i];
        track--;
        if(track==0){
            break;
        }
        sum+=arr[i];
        track--;
    }
   cout<<sum<<endl;

}


Measured memory_bytes: 5196
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR1(i,n) for(int (i)=1;(i)<(n);(i)++)
#define eFOR(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define eFOR1(i,n) for(int (i)=1;(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i) sort((i).begin(),(i).end(), greater<int>());
#define YES(i) cout << ((i) ? "Yes" : "No") << endl;
#define F first
#define S second
constexpr auto INF = 1000000000;
constexpr auto LLINF = 9223372036854775807;
constexpr auto mod = 1000000007;
int main() {

	int r, g, b, n;
	cin >> r >> g >> b >> n;

	int R = n / r;

	int ans = 0;
	eFOR(i, R) {
		int nr = n - i * r;
		if (nr == 0) {
			ans++;
			continue;
		}
		int G = nr / g;
		eFOR(j, G) {
			int ng = nr - j * g;
			if (ng % b == 0) {
				ans++;
				continue;
			}
		}
	}

	cout << ans << endl;

	return 0;
}


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

int func_count(string S, int i, int count){
    if(S[i] == 'A' || S[i] == 'T' || S[i] == 'G' || S[i] == 'C'){
        return func_count(S, i + 1, count + 1);
    }
    else{
        return count;
    }
}

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

    int maxcount = 0;

    for (int i = 0; i < S.length(); i++)
    {
        int count = func_count(S, i, 0);
        if(count > maxcount){
            maxcount = count;
        }
    }
    cout << maxcount << endl;   
}

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

//#define int long long
struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;
using intpair = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()

vector<pair<char,int>> runlength(string s) {
    vector<pair<char,int>> v;
    v.push_back({s[0],1});
    for(int i = 1; i < s.length(); i++){
        if(v.back().first == s[i]){
            v.back().second++;
        }else{
            v.push_back({s[i],1});
        }
    }
    return v;
}

signed main() {
    string s;
    cin >> s;
    auto rlv = runlength(s);
    
    int ans = INT_MAX;
    reps(c, 'a', 'z'){
        int max_streak = 0, now = 0;
        for(auto p : rlv){
            if(p.first == c){
                now = 0;
            }else{
                now += p.second;
                max_streak = max(max_streak, now);
            }
        }
        ans = min(max_streak, ans);
    }
    
    cout << ans << endl;
}

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

  if(n/100==1) ans+=900;
  if(n/100==9) ans+=100;
  if((n/10)%10==1)ans+=90;
  if((n/10)%10==9)ans+=10;
  if(n%10==1)ans+=9;
  if(n%10==9)ans+=1;

  cout << ans << endl;
  return 0;
}

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

using namespace std;

vector<pair<pair<int, int>, int>> e;

void add(int u, int v, int d) {
    e.push_back(make_pair(make_pair(u, v), d));
}

int build(int next, int l) {
    if (l == 2) {
        add(next, next + 1, 0);
        add(next, next + 1, 1);
        return next + 1;
    }
    if (l == 3) {
        add(next, next + 1, 0);
        add(next, next + 1, 1);
        add(next, next + 1, 2);
        return next + 1;
    }
    if (l % 2 == 1) {
        add(next, -1, l - 1);
        l--;
    }
    add(next, next + 1, 0);
    add(next, next + 1, l / 2);
    return build(next + 1, l / 2);
}

int L;

int main(){
    cin >> L;
    int last = build(1, L);
    cout << last << " " << e.size() << endl;
    for (pair<pair<int, int>, int> ei : e) {
        int u = ei.first.first;
        int v = ei.first.second;
        if (v == -1) v = last;
        int d = ei.second;
        cout << u << " " << v << " " << d << endl; 
    }
}

Measured memory_bytes: 384
class Main
  def self.run
    time = read_time
    watch = Watch.new(time)
    puts watch.description
  end

  private

  def self.read_time
    gets.to_i
  end
end

class Watch
  def initialize(time)
    @time = time
  end

  def description
    "#{hours}:#{minutes}:#{seconds}"
  end

  private

  def hours
    @time / 3600
  end

  def minutes
    @time % 3600 / 60
  end

  def seconds
    @time % 60
  end
end

Main.run

Measured memory_bytes: 8604
from collections import Counter
import math
h, w = map(int, input().split())
data = ''
for _ in range(h):
    a = input()
    data += a
cnt = Counter(data)
data_list = list(cnt.values())
cnt_list = []
for hh in range(math.ceil(h / 2)):
    for ww in range(math.ceil(w / 2)):
        if (hh == math.floor(h / 2)) & (ww == math.floor(w / 2)):
            cnt_list.append(1)
        elif (hh == math.floor(h / 2)) | (ww == math.floor(w / 2)):
            cnt_list.append(2)
        else:
            cnt_list.append(4)
cnt_count = Counter(cnt_list)
ans = 'Yes'

cnt_4 = 0
while cnt_4 < cnt_count[4]:
    for c in range(len(data_list)):
        if ((data_list[c]) >= 4) & (data_list[c] > 0):
            data_list[c] -= 4
            cnt_4 += 1
        if cnt_4 == cnt_count[4]:
            break
    if cnt_4 == cnt_count[4]:
        ans = 'Yes'
        break
    if len([d for d in data_list if d >= 4]) == 0:
        ans = 'No'
        break

cnt_2 = 0
while cnt_2 < cnt_count[2]:
    for c in range(len(data_list)):
        if ((data_list[c] >= 2) & (data_list[c] > 0)):
            data_list[c] -= 2
            cnt_2 += 1
        if cnt_2 == cnt_count[2]:
            break
    if cnt_2 == cnt_count[2]:
        ans = 'Yes'
        break
    if len([d for d in data_list if d >= 2]) == 0:
        ans = 'No'
        break
    
cnt_1 = 0
while cnt_1 < cnt_count[1]:
    for c in range(len(data_list)):
        if (data_list[c] > 0):
            data_list[c] -= 1
            cnt_1 += 1
        if cnt_1 == cnt_count[1]:
            break
    if cnt_1 == cnt_count[1]:
        ans = 'Yes'
        break
    if len([d for d in data_list if d >= 1]) == 0:
        ans = 'No'
        break

if (sum(data_list) == 0) & (ans != 'No'):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3316
using System;

namespace Project
{
	class MainClass
	{
		public static void Main(string[] args)
		{
			string W = Console.ReadLine();
			string w = W.ToLower();
			int count = 0;
			while (true)
			{
				string T = Console.ReadLine();
				if (T == "END_OF_TEXT") break;
				string t = T.ToLower();
				string[] words = t.Split(' ', '.', ',');
				foreach (string word in words)
				{
					if (word == w) count++;
				}
			}
			Console.WriteLine(count);

		}
	}
}

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

#define ll long long int
int main()
{
	int n,a,mn,ans=0;
	double sum=0;
	cin>>n;
	vector<int>v;
	for(int i=1;i<=n;i++)
	{
		cin>>a;
		sum=sum+a;
		v.push_back(a);
	}
	sum=round(sum/n);
	for(int j=0;j<v.size();j++)
	{
		ans=ans+((sum-v[j])*(sum-v[j]));
	}
		
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  	int n, k;
  	cin >> n >> k;
  	string s;
  	cin >> s;
    
    for(int i = 0; i < n; i++){
     	if(i == k-1){
         cout <<(char)tolower(s[i]); 
        }
        else{
         cout << s[i]; 
        }
    }
	return 0;
}

Measured memory_bytes: 256
import sys
input=sys.stdin.readline
from collections import deque

class LCA:
    def __init__(self,v,Edges,root=0):
        self.v=v
        self.Edges=Edges
        self.maxLog=18
        self.Parent=[[-1]*v for _ in range(self.maxLog+1)]
        self.Depth=[0]*v
        self.__bfs(root)
        for i in range(self.maxLog):
            for j in range(v):
                if self.Parent[i][j]!=-1:
                    self.Parent[i+1][j]=self.Parent[i][self.Parent[i][j]]
    def __bfs(self,root):
        Visited=[False]*self.v
        Visited[root]=True
        q=deque([root])
        while q:
            fr=q.pop()
            for to in self.Edges[fr]:
                if Visited[to]:
                    continue
                self.Parent[0][to]=fr
                self.Depth[to]=self.Depth[fr]+1
                Visited[to]=True
                q.append(to)
    def lca(self,a,b):
        if self.Depth[a]>self.Depth[b]:
            a,b=b,a
        for i in range(self.maxLog):
            if (self.Depth[b]-self.Depth[a])&(1<<i):
                b=self.Parent[i][b]
        if a==b:
            return b
        for i in reversed(range(self.maxLog-1)):
            if self.Parent[i][a]!=self.Parent[i][b]:
                a=self.Parent[i][a]
                b=self.Parent[i][b]
        return self.Parent[0][a]
    def dist(self,a,b):
        lca=self.lca(a,b)
        return self.Depth[a]+self.Depth[b]-2*self.Depth[lca]

def main():
    n,u,v=map(int,input().split())
    u-=1; v-=1
    Edges=[[] for _ in range(n)]
    for _ in range(n-1):
        x,y=map(lambda i: int(i)-1,input().split())
        Edges[x].append(y)
        Edges[y].append(x)
    L=[]
    for i in range(n):
        if len(Edges[i])==1:
            L.append(i)
    lca=LCA(n,Edges,v)
    dist=lca.dist(u,v)
    ans=dist//2
    for l in L:
        m=lca.lca(u,l)
        if lca.dist(u,m)>=lca.dist(v,m):
            continue
        d_u=lca.dist(u,l)
        d_v=lca.dist(v,l)
        d=d_v-d_u
        cnt=d-1
        ans=max(ans,d_u+cnt)
    print(ans)
    
if __name__=='__main__':
    main()

Measured memory_bytes: 104352
def main():
    n = int(input())
    a = list(map(int,input().split()))
    res = [0 for i in range(n)]
    lres = []
    for i in range(n,0,-1):
        flag = 0
        t = i*2
        while t <= n:
            flag = flag ^ res[t-1]
            t = t+i
        if a[i-1] != flag:
            res[i-1] = 1
            lres.append(str(i))

    print(len(lres))
    if len(lres) != 0:
        print(" ".join(lres))

main()

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

//#define int long long

signed main() {
	string s;
	cin >> s;
	int k;
	cin >> k;

	char c = s[0];
	int ccnt = 0;
	for (int i = 0; i < s.size(); ++i) if (s[i] == c) ++ccnt;
	if (ccnt == s.size()) {
		long long a = (long long)k * ccnt / 2;
		cout << a << endl;
		return 0;
	}

	s.push_back('X');
	long long ans = 0;
	bool first = true;
	int cnt = 1, cntf = 0, cntb = 0;
	for (int i = 0; i < s.size() - 1; ++i) {
		if (s[i] == s[i + 1]) cnt++;
		else {
			if (first) {
				cntf = cnt;
				cnt = 1;
				first = false;
			}
			else if (s[i + 1] == 'X') {
				cntb = cnt;
			}
			else {
				ans += (long long) k * (cnt / 2);
				cnt = 1;
			}
		}
		//cout << i << "  " << ans << endl; 
	}

	

	//cout << cntf << " " << cntb << endl;
	//cout << ans << endl;



	if (s[0] != s[s.size() - 2]) ans += (long long)k * (cntf / 2 + cntb / 2);
	else ans += (long long)(k - 1) * ((cntf + cntb) / 2) + cntf / 2 + cntb / 2;

	cout << ans << endl;
	return 0;
}


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

using namespace std;

#define FOR(i,n) for(int i=0; i<n; ++i)
#define FORR(i,a,n) for(int i=a; i<n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
 
int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
void printfv(VI a){ int n = a.size(); FOR(i, n) cout << a[i] << " "; }

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

ll gcd(ll x, ll y) {
    while (x > 0 && y > 0) {
        if (x > y) x %= y;
        else y %= x;
    }
    return x + y;
}

int main(void){

	int n;
	cin >> n;

	ll a[n], l[n + 1], r[n + 1];
	ll ans = 0;
	
	FOR(i,n) {
		cin >> a[i];
	}

	l[0] = 0;
	for (int i = 0; i < n; i++) {
		l[i + 1] = __gcd(l[i], a[i]);
	}

	// FOR(i, n+1){
	// 	cout << l[i] << '\n';
	// }
	// return 0;
	r[n] = 0;
	for (int i = n - 1; i >= 0; i--) {
		r[i] = __gcd(r[i + 1], a[i]);
	}
 
 	FOR(i, n){
		ans = max(ans, __gcd(l[i], r[i + 1]));
	}

	cout << ans;
	return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long int
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define pci pair<char,int
#define mii map<int,int>
#define mll map<long long int,long long int>
#define mci map<char,int>
#define umii unordered_map<int,int>
#define umll unordered_map<long long int,long long int>
#define umci unordered_map<char,int>
#define F first
#define S second
#define pb push_back
#define endl '\n'
#define mod 1000000007
using namespace std;
//ll visit[100001]={0};
//vector<ll> adj[1000001];

    
int main(){
   IOS;
int t;t=1;//cin>>t;
while(t--){
ll n;cin>>n;
ll a[n];
for(ll i=0;i<n;i++) cin>>a[i];
ll ans=0;
ll suf[n];
suf[n-1]=a[n-1];
for(ll j=n-2;j>=0;j--){
    suf[j]=(a[j]+suf[j+1])%mod;
}
for(ll i=0;i<n-1;i++){
    ans=(ans+(a[i]*suf[i+1])%mod)%mod;
}
cout<<ans;
}
    
    

    
    





return 0;}


Measured memory_bytes: 6732
#include<bits/stdc++.h>
#define ll long long
using namespace std;
inline ll read(){
  char ch;ll f=1;
  while((ch=getchar())<'0'||ch>'9')
   if(ch=='-')f=-1;
  ll res=ch-48;
  while((ch=getchar())>='0'&&ch<='9')
   res=res*10+ch-48;
  return res*f;
} 
const int maxn=100005;
ll n,ans,v,m;
ll a[maxn],b[maxn],c[maxn],d[maxn],fa[maxn];
bool book[maxn];
ll getfa(ll x){
 if(fa[x]==0)return x;
 if(x!=fa[x])fa[x]=getfa(fa[x]);
 return fa[x];
}
map<ll,ll>mp;
int main(){
 n=read();
 for(ll i=1;i<=n;i++)a[i]=read(),v^=a[i],c[i]=a[i];
 a[n+1]=c[n+1]=v;v=0;
 for(ll i=1;i<=n;i++)b[i]=read(),v^=b[i],d[i]=b[i];
 b[++n]=d[n]=v;sort(c+1,c+1+n);sort(d+1,d+1+n);
 for(ll i=1;i<=n;i++){
  if(c[i]!=d[i]){puts("-1");return 0;}
  if(mp[c[i]]==0)mp[c[i]]=++m;
 }
 for(ll i=1;i<=n;i++){
  a[i]=mp[a[i]],b[i]=mp[b[i]];
  if(a[i]!=b[i]){
   if(i<n)ans++;
   ll fx=getfa(a[i]),fy=getfa(b[i]);
   fa[fx]=fy;book[a[i]]=1;book[b[i]]=1;
  }
 }
 if(ans==0)puts("0");
 else{
  book[a[n]]=book[b[n]]=1;
  for(ll i=1;i<=n;i++)
   if(book[i]&&i==getfa(i))
    ans++;
  cout<<ans-1;
 }
 return 0;
}


Measured memory_bytes: 12032
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */

int main() {
    int n;
    cin >> n;
    vector<int> T(n + 1), X(n + 1), Y(n + 1);
    rrep(i, n) {
        cin >> T[i] >> X[i] >> Y[i];
    }
    T[0] = 0;
    X[0] = 0;
    Y[0] = 0;
    bool ans = true;
    rrep(i, n) {
        int t = T[i] - T[i - 1];
        int sum = abs(X[i] - X[i - 1]) + abs(Y[i] - Y[i - 1]);
        if(t < sum || abs(sum - t) % 2 != 0) {
            ans = false;
            break;
        }
    }
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}

Measured memory_bytes: 1408
#!/usr/bin/env python3

import math


def rad_2_deg(theta):
    return 180.0 * theta / math.pi


def compute_angle(a, b, x):
    capacity = a * a * b
    if x == 0:
        rad_angle = math.pi / 2
    elif x == capacity:
        rad_angle = 0
    elif 2 * x > capacity:
        air_vol = capacity - x
        air_len = air_vol * 2 / a / a
        rad_angle = math.atan2(air_len, a)
    else:
        water_len = x * 2 / a / b
        rad_angle = math.atan2(b, water_len)
    res = rad_2_deg(rad_angle)
    return res


def main():
    a, b, x = (int(z) for z in input().split())
    res = compute_angle(a, b, x)
    print("{:.12f}".format(res))


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
#include <climits>
#include <cmath>

using namespace std;



int main(int argc, char *argv[])
{
	int a, b, c;


	//input
	cin >> a >> b >> c;
	


	//calc
	int ans;
	if (b / a < c){
		ans = b / a;
	}
	else{
		ans = c;
	}


	//ans
	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 256
/// kazuki08
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define ar array
//#define inf 1000000000
#define mod 1000000007
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
    return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
    o<<"{";
    for(const T& v:vc) o<<v<<",";
    o<<"}";
    return o;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MAXN = 303000;
int n,k,c;
string s;
int fw[MAXN],rw[MAXN];

signed main(){
IOS;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
  
  cin >> n >> k >> c;
  cin >> s;
  int days1 = 0, days2 = 0;
  int cur = 0;
  for(int i=0;i<n;i++){
    if(s[i]=='o' && !cur){
      cur = c;
      days1++;
      fw[i]=1;
    }
    else {
      cur--;
    }
    cur = max(cur,0LL);
  }
  reverse(all(s));
  cur = 0;
  for(int i=0;i<n;i++){
    if(s[i]=='o' && !cur){
      cur = c;
      rw[n-i-1]=1;
      days2++;
    }
    else {
      cur--;
    }
    cur = max(cur,0LL);
  }
  // cerr << days << endl;
  if(days1>k || days2>k){
    return 0;
  }
  int ans = 0;
  for(int i=0;i<n;i++){
    if(fw[i] && rw[i]){
      cout << i+1 << endl;
    }
  }


return 0;
}
///....


Measured memory_bytes: 5396
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Scanner;
import java.util.AbstractMap.SimpleEntry;

public class Main {

    static final int modnum = 1000000000 + 7;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        ArrayList<Integer> list = new ArrayList<Integer>(N);
        for(int i=0;i<N;i++){
            list.add(sc.nextInt());
        }
        list.sort(Comparator.naturalOrder());

        int a = list.get(N/2-1);
        int b = list.get(N/2);

        System.out.println(b-a);
    }
}

Measured memory_bytes: 62640
#include<stdio.h>
int main(){
  char s[3];
  scanf("%c%c%c",&s[0],&s[1],&s[2]);
  if(s[1]=='B'){
    s[1]='R';}
  else {s[1]='B';}
  printf("%c%c%c",s[0],s[1],s[2]);
  return 0;}

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

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

const long long INF = 1LL << 60;

int GCD(int a,int b){
	if(b==0) return a;
	return GCD(b,a%b);
}
int main(void){
	int n;cin >> n;
	string s;cin >> s;
	int sum_r=0,sum_g=0,sum_b=0;
	for(int i=0;i<n;i++){
		if(s[i]=='R')sum_r += 1;
		if(s[i]=='G')sum_g += 1;
		if(s[i]=='B')sum_b += 1;
	}
	ll ans=0;
	int r=0,g=0,b=0;
	for(int i=0;i<n;i++){
		if(s[i]=='R') r += 1;
		if(s[i]=='G') g += 1;
		if(s[i]=='B') b += 1;
		int tr=r,tg=g,tb=b;	
		for(int j=i+1;j<n;j++){
			
			if(s[j]=='R') tr += 1;
			if(s[j]=='G') tg += 1;
			if(s[j]=='B') tb += 1;
			if(s[i] == 'R'){
				if(s[j] == 'G'){
					ans += sum_b-tb;
					if(2*j-i < n && s[2*j-i] == 'B') ans--; 
				}
				if(s[j] == 'B'){
					ans += sum_g-tg;
					if(2*j-i < n && s[2*j-i] == 'G') ans--; 
				}
			}
			
			if(s[i] == 'G'){
				if(s[j] == 'B'){
					ans += sum_r-tr;
					if(2*j-i < n && s[2*j-i] == 'R') ans--; 
				}
				if(s[j] == 'R'){
					ans += sum_b-tb;
					if(2*j-i < n && s[2*j-i] == 'B') ans--; 
				}
			}
		
			if(s[i] == 'B'){
				if(s[j] == 'G'){
					ans += sum_r-tr;
					if(2*j-i < n && s[2*j-i] == 'R') ans--; 
				}
				if(s[j] == 'R'){
					ans += sum_g-tg;
					if(2*j-i < n && s[2*j-i] == 'G') ans--; 
				}
			}
		
		}
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 3640
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

#define V 5010
#define MAXP 100000000000000
ll dp[V][V];

int main()
{
	int n;cin >> n;
	
	REP(i,V)REP(j,V)
	{
		if(j != 0)
		{
			dp[i][j] = MAXP;
		}
	}
	
	vector<pair<ll,pair<int,int> > > v;
	
	REP(i,n)
	{
		ll h,p;cin >> h >> p;
		v.PB(MP(h+p,MP(h,p)));
	}
	
	sort(ALL(v));
	
	REP(i,n)
	{
		REP(j,n)
		{
			int a = i+1;
			int b = j+1;
			dp[a][b] = min(dp[a][b],dp[a-1][b]);
			
			if(dp[a-1][b-1] <= v[i].SE.FI)
			{
				dp[a][b] = min(dp[a][b],dp[a-1][b-1]+v[i].SE.SE);
			}
		}
	}
	
	//SHOW2d(dp,n+1,n+1);
	
	int ans = 0;
	REP(i,n+1)
	{
		if(dp[n][i] != MAXP)
		{
			ans = i;
		}
	}
	
	cout << ans << endl;
	 
	return 0;
}

Measured memory_bytes: 196608
#!/usr/bin/env python3
# -*- encoding: utf-8 -*-


def main():
    N = int(input())
    HS = list(map(int, input().split()))

    max_ = float('-inf')
    num = 0

    for h in HS:
        if max_ <= h:
            max_ = h
            num = num + 1

    print(num)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <limits>
#include <cmath>
#include <iomanip>
#include <functional>
#include <random>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using ll = long long;
namespace mp = boost::multiprecision;
ll BASE_NUM = 1000000007;

int solve(vector<ll> &candidate, vector<vector<ll>> &Qs, ll N, ll M)
{
  if (candidate.size() == N)
  {
    ll value = 0;
    for(auto q:Qs){
      if (candidate[q[1]-1] - candidate[q[0]-1] == q[2]){
        value += q[3];
      }
    }
    return value;
  }
  else
  {
    ll max_value = 0;
    for (int i = candidate.back(); i <= M; i++)
    {
      candidate.push_back(i);
      ll value = solve(candidate,Qs,N,M);
      max_value = max(max_value,value);
      candidate.pop_back();
    }
    return max_value;
  }
}

int main()
{
  // 整数の入力

  ll N, M, Q;
  cin >> N >> M >> Q;
  vector<vector<ll>> Qs;
  for (int i = 0; i < Q; i++)
  {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    Qs.push_back({a, b, c, d});
  }
  vector<ll> candidate = {1};
  cout << solve(candidate,Qs,N,M) << endl;
  return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define Maxn 100010

int n, m, h[Maxn], u, v;
bool Ban[Maxn];
vector<int >Edge[Maxn];

int main()
{
	scanf("%d%d", &n, &m);
	for (int i=1; i<=n; i++) scanf("%d", &h[i]);
	for (int i=1; i<=m; i++)
	{
		scanf("%d%d", &u, &v);
		Edge[u].push_back(v);
		Edge[v].push_back(u);
	}
	for (int i=1; i<=n; i++)
		if (!Ban[i])
		{
			for (auto v: Edge[i])
				if (h[v] < h[i]) Ban[v] = 1;
				else Ban[i] = 1;	
		}
	int Count = 0; for (int i=1; i<=n; i++) if (!Ban[i]) Count++;
	printf("%d\n", Count);
}

Measured memory_bytes: 9420
// C - Tests
#include <bits/stdc++.h>

using namespace std;

int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

	int n;
	long long x, pre = 0;
	cin >> n >> x;
	vector<long long> b(n), l(n), u(n);
	for (int i = 0; i < n; i++) {
		cin >> b[i] >> l[i] >> u[i];
		pre += -l[i] * b[i];
	}

	vector<pair<long long, int> > o(n);
	for (int i = 0; i < n; i++) o[i] = make_pair((x - b[i]) * u[i] + l[i] * b[i], i);
	sort(o.begin(), o.end(), greater<pair<long long, int> >());

	vector<long long> z(n);
	for (int i = 0; i < n; i++) z[i] = (i > 0 ? z[i - 1] : 0) + o[i].first;

	long long lo = 0, hi = n * x;
	while (lo < hi) {
		long long k = (lo + hi) / 2, q = k / x, r = k % x;
		bool found = false;
		for (int j = 0; j < n; j++) {
			int i = o[j].second;
			long long sum = pre + l[i] * b[i] + (r - b[i]) * (r < b[i] ? l[i] : u[i]);
			if (j <= q) sum += z[q] - o[j].first;
			else sum += z[q - 1];
			if (sum >= 0) {
				found = true;
				break;
			}
		}
		if (!found) lo = k + 1;
		else hi = k;
	}

	cout << lo << endl;

	return 0;
}


Measured memory_bytes: 4992
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    L=list(map(int,input().split()))
    L.sort()
    C=[0]*(3001)
    for l in L: C[l]+=1
    for i in range(3000): C[i+1]+=C[i]
    ans=0
    for i in range(n):
        for j in range(i+1,n):
            ans+=C[L[i]+L[j]-1]-j-1
    print(ans)
resolve()

Measured memory_bytes: 40688
#include <algorithm>
#include <climits>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <numeric>

#define int long long int
constexpr int INF = std::numeric_limits<int>::max();
constexpr int NINF = std::numeric_limits<int>::min();
using namespace std;

void solve() {
  int N;
  cin >> N;
  vector<int> P(N), Q(N);
  for (int &p: P) {
    cin >> p;
  }
  for (int &q: Q) {
    cin >> q;
  }

  vector<int> v(N);
  iota(v.begin(), v.end(), 1);
  int a = 0, b = 0;
  int i = 0;
  do {
    i++;
    if (v == P) {
      a = i;
    }
    if (v == Q) {
      b = i;
    }
  } while( next_permutation(v.begin(), v.end()) );

  cout << abs(a - b) << endl;
}

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


Measured memory_bytes: 256
#include <cstdio>
#include <map>
typedef long long ll;
typedef std::map<ll, ll> mll;
int main() {
    int n;
    ll a[200000];
    scanf("%d", &n);
    for (int i = 0; i < n; i++) scanf("%lld", &a[i]);
    ll res = 0;
    ll sum = 0;
    std::map<ll, ll> mp;
    mp[0] = 1;
    for (int i = 0; i < n; i++) {
        sum += a[i];
        if (mp.find(sum) != mp.end()) {
            res += mp[sum];
            mp[sum]++;
        } else {
            mp[sum] = 1;
        }
    }
    printf("%lld\n", res);
}


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

#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

int main() {
  string s;
  string t;
  cin >> s >> t;

  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());
  string ret;
  if (s < t) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256