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

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
template<class T> inline int chkmin(T& a, const T& val) {return val < a ? a = val, 1 : 0;}
template<class T> inline int chkmax(T& a, const T& val) {return a < val ? a = val, 1 : 0;}
template<class T> inline T isqrt(T k) {T r = sqrt(k) + 1; while (r * r > k) r--; return r;}
template<class T> inline T icbrt(T k) {T r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}

const int maxn = 100000 + 10;
int n, x;
int a[maxn];

void solve() {
	cin >> n >> x;
	FOR(i, 0, n) cin >> a[i];
	long long ans = 0;
	FOR(i, 1, n) {
		long long tot = a[i - 1] + a[i];
		if (tot > x) {
			if (a[i - 1] <= x) {
				ans += tot - x;
				a[i] -= tot - x;
			}
			else {
				ans += a[i];
				ans += a[i - 1] - x;
				a[i] = 0;
				a[i - 1] = x;
			}
		}
	}
	cout << ans << "\n";
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef _LOCAL_
	freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout);
#endif
	solve();
#ifdef _LOCAL_
	//printf("\nTime elapsed: %dms", 1000 * clock() / CLOCKS_PER_SEC);
#endif
	return 0;
}

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

using namespace std;

#define int long long
#define ar array
#define vt vector
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()

#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)

template<class T>
bool umin(T &a, const T &b) {
    return b < a ? a = b, 1 : 0;
}

template<class T>
bool umax(T &a, const T &b) {
    return a < b ? a = b, 1 : 0;
}

template<class A>
void read(vt<A> &v);

template<class A, size_t S>
void read(ar<A, S> &a);

template<class T>
void read(T &x) {
    cin >> x;
}

void read(double &d) {
    string t;
    read(t);
    d = stod(t);
}

void read(long double &d) {
    string t;
    read(t);
    d = stold(t);
}

template<class H, class... T>
void read(H &h, T &... t) {
    read(h);
    read(t...);
}

template<class A>
void read(vt<A> &x) {
    EACH(a, x)read(a);
}

template<class A, size_t S>
void read(array<A, S> &x) {
    EACH(a, x)read(a);
}

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

string to_string(vt<bool> v) {
    string res;
    FOR(sz(v))res += char('0' + v[i]);
    return res;
}

template<size_t S>
string to_string(bitset<S> b) {
    string res;
    FOR(S)res += char('0' + b[i]);
    return res;
}

template<class T>
string to_string(T v) {
    bool f = 1;
    string res;
    EACH(x, v) {
        if (!f)
            res += ' ';
        f = 0;
        res += to_string(x);
    }
    return res;
}

template<class A>
void write(A x) {
    cout << to_string(x);
}

template<class H, class... T>
void write(const H &h, const T &... t) {
    write(h);
    write(t...);
}

void print() {
    write("\n");
}

template<class H, class... T>
void print(const H &h, const T &... t) {
    write(h);
    if (sizeof...(t))
        write(' ');
    print(t...);
}

template<class T, class U>
void vti(vt<T> &v, U x, size_t n) {
    v = vt<T>(n, x);
}

template<class T, class U>
void vti(vt<T> &v, U x, size_t n, size_t m...) {
    v = vt<T>(n);
    EACH(a, v)vti(a, x, m);
}

const int M = 1e9 + 7, mxN = 1e5;

int fact[mxN + 1];

void solve() {
    int n, m;
    read(n, m);
    
    fact[0] = 1;
    fact[1] = 1;
    
    FOR(i, 2, max(n, m) + 1) {
        fact[i] = (fact[i - 1] * i) % M;
    }
    
    
    if (abs(n - m) > 1) {
        print(0);
    }
    else if (abs(n - m) == 1) {
        print((fact[m] * fact[n]) % M);
    }
    else{
        print((fact[m] * fact[n] * 2) % M);
    }
}

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int tt = 1;
    //read(tt);
    FOR(tt) {
        //write("Case #", i + 1, ": ");
        solve();
        
    }
    
}



Measured memory_bytes: 4428
#include<bits/stdc++.h>
#pragma O3
#define int long long
using namespace std;
const int mod=998244353;
int n,a,b,k,ca,cb,ans;
int gt[3000005],rgt[3000005];
int binpow(int x,int mu){
	if(mu==1) return x%mod;
	else{
		int tmp=binpow(x,mu/2);
		if(mu%2==1) return ((tmp*tmp%mod)*x)%mod;
		else return tmp*tmp%mod;
	}
}
signed main(){
//	freopen(".inp","r",stdin);
//	freopen("testout.txt","w",stdout);
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin>>n>>a>>b>>k;
	gt[0]=1;
	for(int i=1;i<3000004;i++){
		gt[i]=(gt[i-1]%mod*(n-i+1)%mod)*(binpow(i,mod-2)%mod)%mod;
	}
	for(int ca=0;ca<=n;ca++){
		cb=(k-ca*a)/b;
		if(cb*b+ca*a!=k||cb<0) continue;
		ans=(gt[ca]*gt[cb]%mod+ans)%mod;
	}
	cout<<ans;
}


Measured memory_bytes: 24576
def getN(P,i):
    n=0
    P1=sorted(P)
    for p in range(i-1):
        n *=(i-p)
        n += (P1.index(P[p]))
        P1.remove(P[p])
    return n

n = int(input())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))

p = getN(P,n)
q = getN(Q,n)

print(abs(p-q))

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

int n;
const int INF = 1e9;

struct edge {
	int to, tm;
};

int main()
{
	cin >> n;

	while (n > 0) {
		int a, b, c, m, mc, md, t = 0;
		int d[10];
		typedef pair<int, int> P;
		vector<edge> G[10];

		for (int i = 0; i < n; i++) {
			cin >> a >> b >> c;
			
			edge e;
			e.to = b;
			e.tm = c;
			G[a].push_back(e);
			e.to = a;
			G[b].push_back(e);

			t = max(t, max(a, b));
		}

		md = INF;

		for (int i = 0; i <= t; i++) {
			mc = 0;
			fill(d, d + 10, INF);
			d[i] = 0;

			priority_queue<P, vector<P>, greater<P>> Q;
			Q.push(P(0, i));

			while (!Q.empty()) {
				P p = Q.top();
				Q.pop();

				int u = p.second;
				if (d[u] < p.first)
					continue;

				for (edge e : G[u]) {
					if (d[e.to] > d[u] + e.tm) {
						d[e.to] = d[u] + e.tm;
						Q.push(make_pair(d[e.to], e.to));
					}
				}
			}

			for (int i = 0; i <= t; i++)
				if(d[i] < INF)
					mc += d[i];

			if (mc < md) {
				m = i;
				md = mc;
			}
		}

		cout << m << " " << md << endl;
		cin >> n;
	}
}



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

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

const int mod = 1000000007;
const int inf = 1000000007;

int main() {
  int n, q;
  cin >> n;
  vector<int> a(n);
  vector<int> cnt(100005);
  ll sum = 0;
  rep(i, n) {
    cin >> a[i];
    cnt[a[i]]++;
    sum += a[i];
  }
  cin >> q;
  vector<ll> bc(q + 1);
  for (int i = 1; i <= q; i++) {
    int b, c;
    cin >> b >> c;
    bc[i] = (c - b) * cnt[b];
    // cout << (c - b) * cnt[b] << '/';
    cnt[c] += cnt[b];
    cnt[b] = 0;
  }
  // cout << endl;
  vector<ll> ans(q);
  ans[0] = bc[1] + sum;
  for (int i = 1; i < q; i++) {
    ans[i] = ans[i - 1] + bc[i + 1];
  }
  rep(i, q) cout << ans[i] << endl;
}


Measured memory_bytes: 5556
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#define _GLIBCXX_DEBUG // check []
#define DIVISOR 1000000007

using namespace std;
typedef pair<int,int> pii;
typedef pair<int64_t, int64_t> pII;

template<typename T>
void cins(vector<T>& arr) { for(T& e: arr) cin >> e; }

#ifdef DEBUG
#define debug(fmt, ...) \
    printf("[debug: %s] " fmt, __func__, __VA_ARGS__)
#define ps(arr) \
    for(auto e: arr) cout << e << " "; \
    cout << endl;
#else
#define debug(fmt, ...)
#define ps(arr)
#endif

int main(void) {
    int num;
    cin >> num;
    vector<int> arr(num);
    vector<int> map(5);
    for(int i = 0; i < num; i++) {
        int val;
        cin >> val;
        if(val%4 == 0) {
            map[4]++;
        } else if (val%2 == 0){
            map[2]++;
        } else {
            map[1]++;
        }
    }
    // 222...414141..
    if(map[2]) {
        cout << ((map[4] >= map[1]) ? "Yes" : "No") << endl;
    } else {
        // 1 4 1 4 1
        cout << ((map[4]+1 >= map[1]) ? "Yes" : "No") << endl;
    }
    return 0;
}

Measured memory_bytes: 3788
N, M, C = map(int,input().split())

bl = list(map(int,input().split()))
al = []
for i in range(N):
    al.append(list(map(int,input().split())))

cnt = 0
for i in range(N):
    wa = 0
    for j in range(M):
        wa += al[i][j]*bl[j]
    if wa + C > 0:
        cnt += 1

print(cnt)

Measured memory_bytes: 9200
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 40;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
char s[MAXN], a[MAXN], b[MAXN];
int n, dp[MAXN][MAXN]; ll ans;
void work(int pos, int la, int lb) {
	if (pos == n) {
		memset(dp, 0, sizeof(dp)), dp[n][la] = 1;
		for (int i = n; i >= 1; i--)
		for (int j = max(0, i - lb), k = i - j; j <= la && j <= i; j++, k--) {
			if (s[i] == a[j]) dp[i - 1][j - 1] += dp[i][j];
			if (s[i] == b[k]) dp[i - 1][j] += dp[i][j];
		}
		ans += dp[0][0];
		return;
	}
	a[la + 1] = s[pos];
	work(pos - 1, la + 1, lb);
	b[lb + 1] = s[pos];
	work(pos - 1, la, lb + 1);
}
int main() {
	read(n), scanf("%s", s + 1);
	work(n * 2, 0, 0);
	writeln(ans);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
	char s[105];scanf("%s",s);
	for(register int i=0;s[i];i++) if(s[i]=='C') for(register int j=i+1;s[j];j++) if(s[j]=='F') return puts("Yes"),0;
	puts("No");
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long 
#define ld long double
#define X first
#define Y second
#define pb push_back
#define max_el(x) max_element(x.begin(),x.end())-x.begin()
#define min_el(x) min_element(x.begin(),x.end())-x.begin()
#define mp make_pair
#define endl '\n'
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

int main(){
	int n,x;
	cin>>n>>x;
	vector<int> a(n+1);
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	for(int i=1;i<=n;i++){
		a[i] += a[i-1];
	}

	int k = upper_bound(a.begin(), a.end(),x)-a.begin();

	cout<<k<<endl;

	
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>

using namespace std;

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

deque<char> plus1(deque<char> const& a) {

  if(a == deque<char>{'0'}) { return {'1'}; }

  deque<char> ret; ret.push_back('0');
  copy(a.begin(), a.end(), back_inserter(ret));
  ret.back() += 1;
  int N = ret.size();
  int idx = N-1;
  while(ret[idx] == '9' + 1) {
    ret[idx] = '0';
    ret[--idx] += 1;
  }

  deque<char> ans;
  bool ok = false;
  REP(i, 0, N) {
    if(ok || (ret[i] != '0')) {
      ok = 1;
      ans.push_back(ret[i]);
    }
  }

  return ans;
}

deque<char> zeroclear(deque<char>& s) {
  deque<char> ret;
  bool ok = false;
  rep(i, s.size()) {
    if(ok || s[i] != '0') {
      ok = 1;
      ret.push_back(s[i]);
    }
  }
  if(ret.empty()) { ret.push_back('0'); ; }
  return ret;
}
struct comp {
bool operator() (deque<char> const& a, deque<char> const& b) {
  int asize = a.size(), bsize = b.size();
  if(asize != bsize) { return asize < bsize; }
  for(int i=0; i<asize; i++) {
    if(a[i] != b[i]) {
      return a[i] < b[i];
    }
  }
  return 0;
}
};

int main() {

  int N; cin >> N;
  string S;
  rep(i, N) {
    char ch; cin >> ch;
    S.push_back(ch);
  }

  set<deque<char>, comp> vs;
  rep(i, N) {
    deque<char> s;
    REP(j, i, N) {
      if(j - i > 7) { continue; }
      s.push_back(S[j]);
      vs.insert(zeroclear(s));
    }
  }

//  int cc = 0;
//  for(auto& s: vs) { if(++cc >= 15) { break; } rep(i, s.size()) { cout << s[i]; } cout << endl; }cout << endl;
//  rep(i, v.size()) {  cout << v[i] << endl; }cout << endl;

  deque<char> curr; curr.push_back('0');
  for(auto& s: vs) {
    if(curr != s) {
      rep(i, curr.size()) { cout << curr[i]; }
      cout << endl;
      exit(0);
    }
    curr = plus1(curr);
//    cout << "---\n";   cout << curr << endl;
  }

  rep(i, curr.size()) { cout << curr[i]; }
  cout << endl;

  return 0;
}

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

int main() {
    int n, d;
    cin >> n >> d;
    int ans = 0;
    rep(i,n) {
        double x, y;
        cin >> x >> y;
        double l = sqrt(x*x + y*y);
        if(l <= d) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3792
using System;

public class hello
{
    public static void Main()
    {
        while (true)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            if (line[1] == "?") goto readend;
            var a = int.Parse(line[0]);
            var b = int.Parse(line[2]);
            switch(line[1])
            {
                case "+":
                    Console.WriteLine(a + b);
                    break;
                case "-":
                    Console.WriteLine(a - b);
                    break;
                case "*":
                    Console.WriteLine(a * b);
                    break;
                case "/":
                    Console.WriteLine(a/ b);
                    break;
                default:
                    break;
            }
        }
        readend:;
    }
}

Measured memory_bytes: 9192
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <stdlib.h>
#include <stdio.h>

using namespace std;
using Graph = vector<vector<int>>;


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

int myAbs(int num) {
    if (num > 0)
        return num;
    else
        return -num;
}

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

/*vector<bool> seen;
void dfs(const Graph& G, int v, int count) {
    seen[v] = true;
    count = 0;
    for (auto next_v : G[v]) {
        if (seen[next_v]) continue;
        if (count > 2) continue;
        count++;
        cout << count << ":" << next_v << endl;
        dfs(G, next_v, count);
    }
}*/

const int INF = 100000000;
const int MOD = 1000000007;
typedef pair<int, int> P;

/*using Maze = vector<vector<char>>;
using D = vector<vector<int>>;
int maze_solve(int N, int M, int sx, int sy, int gx, int gy) {
    queue<P> que;
    que.push(P(sx, sy));
    //配列はNとMの最大値+1くらいをとっておく
    int D[51][51];
    char Maze[51][51];
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < M; j++) {
            cin >> Maze[i][j];
            D[i][j] = INF;
        }
    }
    int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
    D[sx][sy] = 0;
    Maze[sx][sy] = 0;
    //ここから処理
    while (que.size()) {
        P p = que.front();
        que.pop();
        if (p.first == gx && p.second == gy) break;
        for (int i = 0; i < 4; i++) {
            int nx, ny;
            nx = p.first + dx[i]; ny = p.second + dy[i];
            if (nx >= 0 && nx < N && ny >= 0 && ny < M && D[nx][ny] == INF && Maze[nx][ny] != '#') {
                que.push(P(nx, ny));
                D[nx][ny] = D[p.first][p.second] + 1;
            }
        }
    }
    /*for (int i = 0; i < N; i++) {
        for (int j = 0; j < M; j++) cout << D[i][j];
        cout << endl;
    }
    return D[gx][gy];
}*/



int main() {
    int N; cin >> N;
    long long ans = 1;
    for (int i = 1; i <= N; i++) {
        ans = (ans * i)%MOD;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<unordered_map>
#include<algorithm>
#include<functional>
#include<cmath>


using namespace std;

class Main{
  using T = unsigned long long;
public:
  void input();
  void setup();
  void tmp();
  void run();
private:
  T N;
  T sN;
  vector<T> prime;
  vector<T> p;
};

void Main::input(){
  cin >> N;
  sN = sqrt(N)+1;
  p.reserve(sN);
  // setup();
  return;
}

// void Main::setup(){
//   vector<long> table(sN+1, 0);
//   prime.reserve(sN+1);
//   prime.emplace_back(2);
//   for( int i = 2; i < sN; i += 2 ){ table[i] = 1; }
//   for( int i = 3; i < sN; i += 2 ){
//     if( table[i] != 0 ){ continue; }
//     prime.emplace_back(i);
//     for( int j = 2*i; j < sN; j+=i ){ table[j] = 1; }
//   }
//   return;
// }

// void Main::tmp(){
//   int c = 0;
//   for( int m = 1; m < N; ++m ){
//     if( N/m == N%m ){
//       cout << m << ":" << N/m << "," << N%m << endl;
//       ++c;
//     }
//   }
//   cout << c << endl;
//   return;
// }

void Main::run(){
  T sum = 0;
  for( T i = 1; i <= sN; ++i ){
    if( N % i == 0 ){ p.emplace_back(i); }
  }
  for( const auto &x : p ){
    T m = (N-x)/x;
    if( m == 0 ){ continue; }
    // cout << x << "," << m << endl;
    if( N/m != N%m ){ continue; }
    sum += m;
  }
  cout << sum << endl;
  return;
}

int main(){
  Main m;
  m.input();
  // m.tmp();
  m.run();
  return 0;
}



Measured memory_bytes: 256
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!(
        D : i32, // mondai suu
        G : i32, // soudou tokuten
        arr : [(i32, i32); D],
    );

    let mut ans =100000;
    let arr: Vec<(i32, i32)> = arr;
    for mask in 0..(1 << D) {
        let mut sum = 0;
        let mut pcount = 0;
        let mut rest_max = 0;
        for i in 0..D {
            // zenbu toku
            if mask >> i & 1 == 1 {
                sum += arr[i as usize].0 * 100 * (i as i32 + 1) + arr[i as usize].1;
                pcount += arr[i as usize].0;
            } else {
                rest_max = i;
            }
        }
        if sum < G {
            let s1 = 100 * (rest_max as i32 + 1); // max point
            let need = (G - sum + s1 - 1) / s1;
            if need >= arr[rest_max as usize].0 {
                continue;
            }
            pcount += need;
        }
        ans = if pcount < ans { pcount } else { ans };
    }
    println!("{}",ans);
}

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

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    vector<int> A(4);
    for (int i = 0; i < 4; i++) {
        cin >> A[i];
    }
    sort(all(A));
    if (A[0] == 1 && A[1] == 4 && A[2] == 7 && A[3] == 9) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

int main() {
    #ifdef LOCAL_ENV
    cin.exceptions(ios::failbit);
    #endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    
    solve();

    #ifdef LOCAL_ENV
    assert(cin.rdstate() & ios_base::eofbit);
    #endif
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
vector<int>g[100010];
int dis[100010],ans[100010];
bool vis[100010];
priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > >q;
int main()
{
	int n,m,i,u,v;
	cin>>n>>m;
	for(i=0;i<m;i++)
	{
		cin>>u>>v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	fill(dis,dis+n+5,2147483647);
	q.push(make_pair(0,1));
	dis[1]=0;
	while(q.size())
	{
		int f=q.top().second;
		q.pop();
		if(vis[f])
			continue;
		vis[f]=true;
		for(i=0;i<g[f].size();i++)
			if(dis[g[f][i]]>dis[f]+1)
			{
				dis[g[f][i]]=dis[f]+1;
				q.push(make_pair(dis[f]+1,g[f][i]));
				ans[g[f][i]]=f;
			}
	}
	for(i=2;i<=n;i++)
		if(dis[i]==2147483647)
		{
			cout<<"No";
			return 0;
		}
	cout<<"Yes\n";
	for(i=2;i<=n;i++)
		cout<<ans[i]<<endl;
	return 0;
}

Measured memory_bytes: 11224
#include <bits/stdc++.h>
#include <sstream>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define srt(i) sort(i.begin(), i.end())
#define rvt(i) sort(i.begin(), i.end(), greater<int>())


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

    if(s=="RRR") cout << 3 << endl;
    else if(s=="RRS" || s=="SRR") cout << 2 << endl; 
    else if(s=="SSS") cout << 0 << endl;
    else cout << 1 << endl;

}


Measured memory_bytes: 3592
#include <stdio.h>

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

  scanf ( "%d%d", &a, &b );
  if ( a < b )
  {
    puts ( "a < b" );
  }
  else if ( a > b )
  {
    puts ( "a > b" );
  }
  else
  {
    puts ( "a == b" );
  }

  return ( 0 );
}

Measured memory_bytes: 0
def make(s1):
    i = 0
    l1 = []
    while i < len(s1):
        if s1[i] == '"':
            for k in range(i + 1, len(s1)):
                if s1[k] == '"':
                    l1.append((s1[i + 1:k], 1))
                    i = k + 1
                    break
        elif s1[i] == ";":
            for k in range(i, len(s1)):
                if s1[k] == ';':
                    l1.append((s1[i + 1:k],0))
                    i = k + 1
                    break
                if s1[k] == '"':
                    l1.append((s1[i + 1:k], 0))
                    i = k 
                    break
            else:
                l1.append((s1[i + 1:], 0))
                i = k + 1
        else:
            for k in range(i, len(s1)):
                if s1[k] == ';':
                    l1.append((s1[i:k], 0))
                    i = k + 1
                    break
                if s1[k] == '"':
                    l1.append((s1[i:k], 0))
                    i = k
                    break
            else:
                l1.append((s1[i:], 0))
                i = k + 1
    return l1

def main():
    s1 = input()
    s2 = input()
    l1 = make(s1)
    l2 = make(s2)
    if len(l1) != len(l2):
        print("DIFFERENT")
        return
    f = 0
    for i in range(len(l1)):
        if l1[i] != l2[i]:
            if l1[i][1] == 0:
                f += 1
            f += 1
    if f == 0:
        print("IDENTICAL")
    elif f == 1:
        print("CLOSE")
    else:
        print("DIFFERENT")



for i in range(100):
    main()


Measured memory_bytes: 5588
#include <stdio.h>

int main() {
	int a[100] = { 0 };
	int number;
	int count;
	int i, j;
	int temp;

	scanf("%d", &number);
	for (i = 0; i < number; i++) {
		scanf("%d", &a[i]);
	}

	count = 0;
	for (i = 0; i < number; i++) {
		for (j = number - 1; j > i; j--) {

    		if (a[j] < a[j - 1]) {
	    		temp = a[j];
		    	a[j] = a[j - 1];
		    	a[j - 1] = temp;
				count++;
		    }
		}
	}

	for (i = 0; i < number - 1; i++) {
		printf("%d ", a[i]);
	}
	printf("%d", a[number - 1]);
	printf("\n%d\n", count);

	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

ll N, A, B, C, D;

bool check(ll m)
{
    return (C * (N - m - 1) - D * m <= B - A) && (B - A <= (N - m - 1) * D - C * m);
}

int main()
{
    cin >> N >> A >> B >> C >> D;
    for (ll i = 1; i < N; i++)
    {
        if (check(i) == true)
        {
            cout << "YES\n";
            return 0;
        }
    }
    cout << "NO\n";
}

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

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    //good luck kittu!
    int a, b, c, k;
    cin>>a>>b>>c>>k;
    if(k<=a) cout<<k<<"\n";
    else if(k<=a+b) cout<<a<<"\n";
    else if(k<=a+b+c) cout<<a-(k-a-b)<<"\n";
    else cout<<a-c<<"\n";
    return 0;
}


Measured memory_bytes: 3664
n=int(input())
h=[int(i) for i in input().split()]
res = 0
cur = 0
prev = 0
for i in h:
    if i > prev:
        res = max(res, cur)
        cur = 0
    else:
        cur += 1
    prev = i
res = max(res, cur)
print(res)


Measured memory_bytes: 63984
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin>>N;
    vector<char>S(N+1);
    for(int i=0;i<N;i++)cin>>S[i];
     sort(S.begin(),S.end());
    int sum=0;
    for(int i=0;i<N;i++){
       if(i==0)continue;
       if(S[i]!=S[i-1]){
           sum++;
       }
   } 
   if(sum==3)cout<<"Three"<<endl;
   else cout<<"Four"<<endl;
}

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

using namespace std;

const int maxn = 1e5 + 10;

vector<int> adj[maxn];
int dp[maxn];
int ans = -1;

int dfs(int u)
{
    if (dp[u] != -1)
        return dp[u];
    int ans = 0;
    for(auto elem : adj[u]){
        ans = max(1 + dfs(elem), ans);
    }
    return dp[u] = ans;
}

int main()
{
    int n, m, x, y;
    cin >> n >> m;
    memset(dp, -1, sizeof dp);
    for(int i = 0; i < m; i++){
        cin >> x >> y;
        adj[x].push_back(y);
    }
    for(int i = 1; i <= n; i++){
        if (dp[i] == -1){
            dfs(i);
        }
    }
    for(int i = 1; i <= n; i++){
        ans = max(dp[i], ans);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 8192
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <cctype>
#define rep(i, m, n) for(int i = m;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define ll long long
#define ull unsigned long long
#define push(a) push_back(a)
#define pop(a) pop_back(a)
#define debug(x) cout<<#x<<": "<<x<<endl
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int main(){
  int n,l;
  string s[101],ans="";
  cin>>n>>l;
  rep(i,0,n) cin>>s[i];
  sort(s,s+n);
  rep(i,0,n) cout<<s[i];
  cout<<endl;
}


Measured memory_bytes: 256
m = 10**9+7
n,a,b = map(int,input().split())
def cb(k):
  v = 1
  w = 1
  for i in range(k):
    v = v*(n-i)%m
    w = w*(i+1)%m
  return (v*pow(w,m-2,m)%m)
print((pow(2,n,m)-1-cb(a)-cb(b))%m)

Measured memory_bytes: 9152
n=int(input())
a=[]

x,y,k=-1,-1,-1
t=-1
for o in range(n):
    a.append(list(map(int,input().split())))
    if a[o][2] != 0:
        t=o
for i in range(101):
    for j in range(101):
        h=a[t][2]+abs(a[t][0]-i)+abs(a[t][1]-j)
        d=True

        for l in range(n):
            if a[l][2] > 0 and h != a[l][2]+abs(a[l][0]-i)+abs(a[l][1]-j):
                d=False
            if a[l][2]==0 and h>abs(a[l][0]-i)+abs(a[l][1]-j):
                d=False
            
        if d:
            x,y,k=i,j,h
            print(x,y,k)
            exit()



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

typedef long long ll;
const int maxn = 100005;

inline ll read() {
    reg ll s = 0, t = 0; reg char ch = getchar();
    while (!isdigit(ch)) t |= ch == '-', ch = getchar();
    while (isdigit(ch)) s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
    return t ? -s : s;
}

int n, m, a[maxn], d[maxn], x[maxn], pos[maxn], Stack[maxn], top;
ll k, ans[maxn];
bool used[maxn];

int main() {
    ios::sync_with_stdio(false);
    n = read();
    for (reg int i = 1; i <= n; i++) x[i] = read();
    for (reg int i = 1; i <= n; i++) d[i] = x[i] - x[i - 1];
    m = read(), k = read();
    for (reg int i = 1; i <= m; i++) a[i] = read();
    for (reg int i = 1; i <= n; i++) pos[i] = i;
    for (reg int i = 1; i <= m; i++) swap(pos[a[i]], pos[a[i] + 1]);
    for (reg int i = 1; i <= n; i++)
        if (!used[i]) {
            top = 0;
            for (reg int j = i; !used[j]; j = pos[j]) Stack[++top] = j, used[j] = true;
            for (reg int j = 1; j <= top; j++)
                ans[Stack[j]] = d[Stack[(k + j - 1) % top + 1]];
        }
    for (reg int i = 1; i <= n; i++) ans[i] += ans[i - 1], printf("%lld\n", ans[i]);
    return 0;
}


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

int main(){
    int flag=1;
    int ans=0,sum=0;
    int n,m;
    
    cin >>n;
    if(n==1){
        cout << "Yes" <<endl;
        return 0;
    }
    int a[n];

    for (int i = 0; i < n; i++){
        cin >>a[i];
    }
    
    //if(a[0] > a[1]+1)flag=0;

    int mx=a[0];
    for (int i = 0; i < n; i++){
        mx = max(mx,a[i]);
        if(mx > a[i] + 1){
            flag=0;
            break;
        }
    }
    


    //cout <<fixed<<setprecision(16)<< << endl;
    //cout << ans << endl;

    if(flag==1)cout << "Yes" <<endl;
    else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 640
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

using namespace std;

#define MAX 100000
#define INF 2140000000
#define MOD 1000000007

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

	if (a >= 13) {
		cout << b << endl;
	}
	else if(a >= 6) {
		cout << b / 2 << endl;
	}
	else {
		cout << 0 << endl;
	}

	return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> C(N);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    C.at(a - 1)++;
    C.at(b - 1)++;
  }
  
  for (int i=0; i<N; i++) {
    cout << C.at(i) << endl;
  }
}


Measured memory_bytes: 256
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 a[][] = new int[M][2];
		for(int i = 0; i < M; i++) {
			a[i][0] = sc.nextInt();
			a[i][1] = sc.nextInt();
		}
		Arrays.sort(a, Comparator.comparingInt(o -> o[1]));
		Arrays.sort(a, Comparator.comparingInt(o -> o[0]));
		
		int min = Integer.MAX_VALUE;
		int ans = 0;
		for(int i = 0; i < M; i++) {
			if(a[i][0] >= min) {
				ans++;
				min = a[i][1];
			} else {
				min = Math.min(min, a[i][1]);
			}
		}
		ans++;
		
		System.out.println(ans);
	}
}


Measured memory_bytes: 91588
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;
 
ll calc(ll a, int x, ll y){
  if(a == 0) return y;
  return (a%2==0)?x:1-x;
}
 
void solve(int L, const vector<ll>& v, vector<vector<ll>>& dp){
  vector<ll> sum(L+1);
  sum[0] = v[0];
  REP(i,1,v.size()){
    sum[i] = sum[i-1] + v[i];
  }
 
  rep(i,v.size()){
    //右から入って左へ
    dp[i][0] = ((i>0)?dp[i-1][0]:0) + calc(v[i],0,2);
    ///前までを捨てる
    dp[i][0] = min(dp[i][0], ((i>0)?sum[i-1]:0) + calc(v[i],0,0));
    //左から入って左へ
    dp[i][1] = ((i>0)?(min(dp[i-1][0], dp[i-1][1])):0) + calc(v[i],1,1);
    ///前までを捨てる
    dp[i][1] = min(dp[i][1], ((i>0)?sum[i-1]:0) + calc(v[i],1,1));
  }
}
 
int main(){
  int L;
  cin >> L;
  vector<ll> v;
  rep(i,L){
    ll a;
    cin >> a;
    v.push_back(a);
  }

  vector<vector<ll>> dp1(200005, vector<ll>(2));
  vector<vector<ll>> dp2(200005, vector<ll>(2));
  solve(L, v, dp1);
  reverse(ALLOF(v));
  solve(L, v, dp2);
  reverse(ALLOF(v));

  ll ret = 1e18;
  rep(i,L){
    ret = min(ret, dp1[i][0] + dp2[L-1-i][0]);
    ret = min(ret, dp1[i][1] + dp2[L-1-i][0]);
    ret = min(ret, dp1[i][0] + dp2[L-1-i][1]);
    ret = min(ret, dp1[i][1] + dp2[L-1-i][1]);
  }

  cout << ret << endl;
  
  return 0;
}

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

using namespace std;

int main(int argc, char**argv) {
  unsigned long n;
  cin >> n;
 
  vector<unsigned long> orig;
  orig.resize(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> orig[i];
  }
  unsigned long m;
  cin >> m;
  for (int i = 0; i < m; i++) {
    unsigned long p, x;
    cin >> p >> x;

    unsigned long o = orig[p];
    orig[p] = x;

    cout << accumulate(orig.begin(), orig.end(), 0) << endl;

    orig[p] = o;
  }

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

	public static void main(String[] args) {
		while (true) {
			int N = sc.nextInt();
			if (N == 0) break;
			sc.nextLine();
			int[] enter = new int[1000];
			int[] sum = new int[1000];
			for (int i = 0; i < N; ++i) {
				char[] line = sc.nextLine().toCharArray();
				int h = (line[6] - '0') * 10 + line[7] - '0';
				int m = (line[9] - '0') * 10 + line[10] - '0';
				int time = h * 60 + m;
				boolean in = line[12] == 'I';
				int id = (line[14] - '0') * 100 + (line[15] - '0') * 10 + line[16] - '0';
				if (in) {
					enter[id] = time;
				} else {
					if (id == 0) {
						for (int j = 1; j < 1000; ++j) {
							if (enter[j] != 0) {
								sum[j] += time - Math.max(enter[j], enter[0]);
							}
						}
					} else {
						if (enter[id] != 0 && enter[0] != 0) {
							sum[id] += time - Math.max(enter[id], enter[0]);
						}
					}
					enter[id] = 0;
				}
			}
			int ans = 0;
			for (int i = 0; i < 1000; ++i) {
				ans = Math.max(ans, sum[i]);
			}
			System.out.println(ans);
		}
	}

}

Measured memory_bytes: 52192
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;
vector<int> f(500);
int fib(int n){
	if((n == 1) || (n == 0)){
		return 1;
	}
	else if(f[n] != 0){
		return f[n];
	}
	else{
		f[n] = fib(n - 1) + fib(n - 2);
		return f[n];
	}
}
int main(){
	int n;cin>>n;
	cout << fib(n) << endl;
	return 0;
	
}


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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

// 3乗で通したお詫びにO(NlogN)で通します
// 参考 : https://twitter.com/SayakaAmemiya/status/1249515024541859842

template<int mod, int proot> struct NTT {
	int get_mod() { return mod; }
	int pow(int a, int b) {
	int res = 1;
		for (; b; b >>= 1) {
			if (b & 1) res = (int64_t) res * a % mod;
			a = (int64_t) a * a % mod;
		}
		return res;
	}
	int inv(int i) { return pow(i, mod - 2); }
	void ntt(std::vector<int> &a, bool inverse) {
		int n = a.size();
		assert((n & -n) == n);
		int h = pow(proot, (mod - 1) / n);
		if (inverse) h = inv(h);
		
		for (int i = 0, j = 1; j < n - 1; j++) {
			for (int k = n >> 1; k > (i ^= k); k >>= 1);
			if (j < i) std::swap(a[i], a[j]);
		}
		for (int i = 1; i < n; i <<= 1) {
			int base = pow(h, n / i / 2);
			int w = 1;
			
			std::vector<int> ws(i);
			for (int j = 0; j < i; j++) ws[j] = w, w = (int64_t) w * base % mod;
			
			for (int j = 0; j < n; j += i << 1) {
				for (int k = 0; k < i; k++) {
					int u = a[k + j];
					int d = (int64_t) a[k + j + i] * ws[k] % mod;
					a[k + j] = u + d >= mod ? u + d - mod : u + d;
					a[k + j + i] = d > u ? u + mod - d : u - d;
				}
			}
		}
		if (inverse) {
			int ninv = inv(a.size());
			for (auto &i : a) i = (int64_t) i * ninv % mod;
		}
	}
};

int main() {
	int n = ri();
	int back[3] = { 0 };
	int forward[3] = { 0 };
	std::vector<int> a(n);
	{
		std::string tmp;
		std::cin >> tmp;
		for (int i = 0; i < n; i++) {
			a[i] = tmp[i] == 'R' ? 0 : tmp[i] == 'G' ? 1 : 2;
			back[a[i]]++;
		}
	}
	
	int64_t res = 0;
	// j - i != k - jを無視したの
	for (int j = 0; j < n; j++) {
		back[a[j]]--;
		res += forward[(a[j] + 1) % 3] * back[(a[j] + 2) % 3];
		res += forward[(a[j] + 2) % 3] * back[(a[j] + 1) % 3];
		forward[a[j]]++;
	}
	// j - i == k - jで相異なるものを引く
	int n2 = 1;
	for (; n2 < n + n - 1; n2 <<= 1);
	NTT<998244353, 3> ntt;
	std::vector<int> count[3];
	for (auto &i : count) i.resize(n2);
	for (int i = 0; i < n; i++) count[a[i]][i]++;
	for (auto &i : count) ntt.ntt(i, false);
	
	std::vector<int> conved[3]; // conved count[i], count[(i + 1) % 3]
	for (int i = 0; i < 3; i++) {
		auto &cur = conved[i];
		cur.resize(n2);
		for (int j = 0; j < n2; j++) cur[j] = (int64_t) count[i][j] * count[(i + 1) % 3][j] % 998244353;
		ntt.ntt(cur, true);
	}
	for (int j = 0; j < n; j++) res -= conved[(a[j] + 1) % 3][j + j];
	
	printf("%" PRId64 "\n", res);
	
	return 0;
}


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

using namespace std;
typedef long long ll;
#define int ll

template<typename T1,typename T2> inline void chmin(T1 &a, T2 b){ if(a > b) a = b; }
template<typename T1,typename T2> inline void chmax(T1 &a, T2 b){ if(a < b) a = b; }

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
const int MAX_N = 200010;

string S, T;
// i 以降にあるアルファベット j のうち一番手前のものの位置
// ない場合 -1
int pos[MAX_N][30];

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

    cin >> S >> T;

    // pos の作成
    string S2 = S + S;
    MINUS(pos);
    for(int i = S2.length() - 1; i >= 0; i--) {
        REP(j, 30) {
            pos[i][j] = pos[i+1][j];
        }
        int cur = S2[i] - 'a';
        pos[i][cur] = i;
    }

    // t を順番に見ていく
    int ans = 0;
    int cur = 0;
    REP(i, T.length()) {
        // T[i] は S[cur] から何番目にあるか
        int next_cur = pos[cur][T[i] - 'a'];
        if(next_cur < 0) {
            ans = -1;
            break;
        }
        ans += (next_cur - cur) + 1;
        //DBG("T[i]: %c cur: %lld next_cur: %lld -> ", T[i], cur, next_cur);
        if(next_cur + 1 < S.length()) {
            cur = next_cur + 1;
        }
        else {
            cur = next_cur + 1 - S.length();
        }
        //DBG("%lld\n", cur);
    }
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 50744
#include<bits/stdc++.h>
using namespace std;
 
/*
*****************code written By**********************
..................Marajul islam.......................
...................BSMRSTU,CSE........................
*/ 
 
int sc1() {int x; scanf("%d", &x); return x;}
 
long long sc2() {long long x; scanf("%lld", &x); return x;}
 
 
 
#define  gcd(a,b)         __gcd(a,b)
#define  lcm(a,b)         (a*b)/gcd(a,b)
#define  Int              sc1()
#define  LL               sc2()
#define  For(n)           for(int i=0;i<n;i++)
#define  Forj(n)          for(int j=0;j<n;j++)
#define  Fork(n)          for(int k=0;k<n;k++)
#define  For1(n)          for(int i=1;i<=n;i++)
#define  ll               long long
#define  vi               std::vector<int>
#define  vll              std::vector<ll>
#define  qui              qu
#define  pb               push_back
#define  mpsi             std::map<string, int>
 
 
const int mod           = 1e9 + 7;
const int inf           = (int)2e9 + 5;
const ll  Inf           = (ll)1e18 + 5;
const int N             = 5e6 + 5;
 
inline int add(int a, int b) {a += b; return a >= mod ? a - mod : a;}
inline int sub(int a, int b) {a -= b; return a < 0 ? a + mod : a;}
inline int mul(int a, int b) {return (ll)a * b % mod;}
 

 
 
int solve() {
 
	int a=Int;
	int b=Int;
	for(int i=1;i<=1e5;i++){
		int x=(i*.08);
		int y=(i*.1);
		if(x==a && y==b) {cout<<i<<endl;return 0;}
	}
	puts("-1");
 
	return 0;
}
 
 
 
 
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
 
	int test = 1, tc = 0;
	//scanf("%d", &test);
	//cin >> test;
	while (test--) {
		//printf("Case %d: ", ++tc);
		solve();
	}
 
	return 0;
 
 
 
 
}




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

int main() {
	string S; long long K;
	cin >> S >> K;
	for (int i = 0; i < min((long long)S.size(), K); i++) {
		if (S[i] >= '2') { cout << S[i] << endl; return 0; }
	}
	cout << '1' << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

using ll = long long;

void read();
template<typename First, typename... Rest> void read(First& first, Rest&... rest);
void write();
template<typename First, typename... Rest> void write(First first, Rest... rest);
template<typename T> void write_vec(vector<T>& v, char divider);

constexpr int MOD = 1000000007;
ll modpow(ll n, ll r, ll mod) {
    if(r == 0) return 1;
    if(n == 0) return 0;
    if(r % 2 == 0) {
        ll tmp = modpow(n, r / 2, mod);
        return tmp * tmp % mod;
    }
    else {
        return n * modpow(n, r - 1, mod) % mod;
    }
}

int main(){
    int N;
    read(N);
    vector<int> W(N);
    for(int i = 0; i < N; i++){
        read(W[i]);
    }
    int S1 = accumulate(W.begin(), W.end(), 0);
    int S2 = 0;
    int ans = INT_MAX;
    for(int i = 0; i < N; i++){
        S1 -= W[i];
        S2 += W[i];
        ans = min(ans, abs(S2 - S1));
    }
    write(ans);
    return 0;
}

//配列以外の入力を受け取る
void read(){

}
template<typename First, typename... Rest>
void read(First& first, Rest&... rest){
    cin >> first;
    read(rest...);
}
//
//配列以外を出力する
void write(){

}
template<typename First, typename... Rest>
void write(First first, Rest... rest){
    cout << first << " ";
    write(rest...);
}
//
//配列を区切って出力する
template<typename T>
void write_vec(vector<T>& v, char divider){
    for(size_t i = 0; i < v.size(); i++){
        cout << v[i] << divider;
    }
}
//

Measured memory_bytes: 256