akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int ll
#define pb push_back
#define setbits(x)          __builtin_popcountll(x)
#define endl "\n"
typedef long long ll;
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin>>n;
string str;
cin>>str;
int dp[n+1][3]={};
if(str[0]=='R')
{
    dp[0][0]=1;
}
else if(str[0]=='B')
{
    dp[0][1]=1;
}
else
    dp[0][2]=1;
for(int i=1;i<n;i++)
{
    if(str[i]=='R')
{
    dp[i][0]=1;

}
else if(str[i]=='B')
{
    dp[i][1]=1;
}
else
    dp[i][2]=1;

    dp[i][0]+=dp[i-1][0];
    dp[i][1]+=dp[i-1][1];
    dp[i][2]+=dp[i-1][2];
}

int ans=0;

/// r b g
for(int i=0;i<n;i++)
{
    for(int j=i+1;j<n-1;j++)
    {
        if(str[i]!=str[j])
        {
            int k=j-i;
           k+=j;
           if(str[i]=='R')
           {
               if(str[j]=='B')
               {
                   ans+=dp[n-1][2]-dp[j][2];
                   if(k<n&&str[k]=='G')
                   {
                       ans-=1;
                   }
               }
               else
               {
                   ans+=dp[n-1][1]-dp[j][1];
                    if(k<n&&str[k]=='B')
                   {
                       ans-=1;
                   }
               }
           }
           else if(str[i]=='B')
           {
               if(str[j]=='R')
               {
                   ans+=dp[n-1][2]-dp[j][2];
                   if(k<n&&str[k]=='G')
                   {
                       ans-=1;
                   }
               }
               else
               {
                    ans+=dp[n-1][0]-dp[j][0];
                     if(k<n&&str[k]=='R')
                   {
                       ans-=1;
                   }
               }
           }
           else
           {
               if(str[j]=='R')
               {
                   ans+=dp[n-1][1]-dp[j][1];
                    if(k<n&&str[k]=='B')
                   {
                       ans-=1;
                   }
               }
               else
               {
                ans+=dp[n-1][0]-dp[j][0];
                if(k<n&&str[k]=='R')
                   {
                       ans-=1;
                   }
               }
           }


        }
    }
}

cout<<ans<<endl;














    return 0;
}


Measured memory_bytes: 3696
#![allow(
    non_snake_case,
    unused_variables,
    unused_assignments,
    unused_mut,
    unused_imports,
    dead_code
)]
//use permutohedron::LexicalPermutation as _;
use proconio::{fastout, input, marker::*};
use std::cmp::*;
use std::collections::*;
//use std::num;
//use petgraph::unionfind::UnionFind;

#[fastout()]
fn main() {
    input! {
        N:usize,M:usize,
        LR:[(Usize1,Usize1);M]
    }
    let mut maxL = 0;
    let mut minR = N;
    for &(l, r) in LR.iter() {
        maxL = max(maxL, l);
        minR = min(minR, r);
    }
    if minR >= maxL {
        println!("{}", minR - maxL + 1);
    } else {
        println!("0");
    }
}


Measured memory_bytes: 4648
#include<bits/stdc++.h>
using namespace std;
const int SZ = 100005;
priority_queue<int> pq;
int arr[SZ];
int main(void){
	int n,m; scanf("%d %d",&n,&m); n--;
	for(int i=0;i<m;i++) scanf("%d",&arr[i]);
	sort(arr,arr+m);
	int ans = arr[m-1]-arr[0];
	for(int i=1;i<m;i++){
		pq.push(arr[i]-arr[i-1]);
	}
	while(!pq.empty() && n>0){
		int t = pq.top(); pq.pop();
		ans -= t;
		n--;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 1276
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/math/common_factor_rt.hpp>
using namespace boost::multiprecision;
using namespace std;
using LL = long long;
int main()
{
    LL N;cin >> N;
    vector<cpp_int> A,B;
    for(int a = 0;a < N;a++){
        cpp_int b;cin >> b;
        A.push_back(b);
    }
    for(int a = 0;a < N;a++){
        cpp_int b ;cin >> b;
        B.push_back(b);
    }
    cpp_int can = 0;
    for(int a = 0;a < N;a++){
        if(A.at(a)<B.at(a)){
        if((B.at(a)-A.at(a))%2!=0){
        cpp_int s = (B.at(a)-A.at(a))/2*2+2;
        can += (B.at(a)-A.at(a))/2+1;
        A.at(a) += s;
        }else{
            cpp_int s =(B.at(a)-A.at(a))/2*2;
            can += (B.at(a)-A.at(a))/2;
            A.at(a)+=s;
        }
        }
       //cout<<A.at(a)<<" "<<B.at(a)<<endl;
    }
    //cout<<can<<endl;
    cpp_int sa=0,sb=0;
    for(int a = 0;a < N;a++){
        sa += A.at(a);
        sb += B.at(a);
    }
    can = can-(sa-sb);
    //cout<<can<<endl;
    if(can < 0){
        cout<<"No"<<endl;
        return 0;
    }
    if(can == 0){
        cout<<"Yes"<<endl;
        return 0;
    }
    if(can > 0){
        cout<<"Yes"<<endl;
        return 0;
    }
    return 0;
}


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

#define ll long long

using namespace std;

int r, g, b;

int main()
{
    cin >> r >> g >> b;
    cout << ((100 * r + 10 * g + b) % 4 == 0 ? "YES" : "NO") << endl;
    return 0;
}

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

using namespace std;

inline int ctoi(char c) { if(c < '0' || '9' < c) throw invalid_argument("ctoi error"); return c - '0'; }
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

template <typename T>
inline T gcd(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("gcd error: x <= 0 or y <= 0");
	
	if(x < y) swap(x, y);
	T r = x % y;

	while(r != 0){
		x = y;
		y = r;
		r = x % y;
	}

	return y;
}
template <typename T>
inline T lcm(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("lcm error: x <= 0 or y <= 0");

	return x * y / gcd(x, y);
}

int main(){
	int n;
	cin >> n;
	int *a = new int[n];
	int *b = new int[n-1];

	for(int i = 0; i < n-1; i++) cin >> b[i];

	a[0] = b[0];
	a[n-1] = b[n-2];

	for(int i = 1; i < n-1; i++){
		a[i] = min(b[i-1], b[i]);
	}

	int ans = 0;
	rep(i, n){
		ans += a[i];
	}
	cout << ans << endl;

	delete a, b;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000003//1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

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


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

const int MAX = 1000003;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void comb_init() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long comb(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll mod_pow(ll x, ll n, ll mod){
    ll res = 1;
    while(n > 0){
        if(n & 1) res = res * x % mod;//最下位ビットが立っているときにx^(2^i)をかける
        x = x * x % mod; //xを順次二乗していく
        n >>= 1;
    }
    return res;
}

ll mod_inv(ll x) {
    return mod_pow(x,MOD-2,MOD);
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll Q;
    cin>>Q;
    comb_init();
    ll mod = 1000003;
    REP(i,Q){
        ll x, d, n;
        cin>>x>>d>>n;
        if(d==0){
            cout<<mod_pow(x,n,mod)<<endl;
            continue;
        }
        if(n>mod) cout<<0<<endl;
        else{
            ll res = fac[n] * comb(mod - x * mod_inv(d) % mod,n) % mod * mod_pow(mod-d,n,mod) % mod;
            cout<<res%mod<<endl;
        }
    }
    
}

Measured memory_bytes: 24448
N, M = map(int, input().split())
K = [list(map(int, input().split())) for _ in range(M)]
P = list(map(int, input().split()))

a = 0
for bit in range(1 << N):
    flag = True
    for i in range(M):
        c = 0
        for j in K[i][1:]:
            if bit & (1 << (j - 1)):
                c += 1
        if c % 2 != P[i]:
            flag = False
            break
    if flag:
        a += 1

print(a)



Measured memory_bytes: 9108
L, R = map(int, input().split())

tmp = R - L + 1
if tmp >= 2019:
    print(0)
    exit()
else:
    start = L % 2019
    end = R % 2019
    candidate = []
    for i in range(start, end + 1):
        candidate.append(i % 2019)
    candidate.sort()
    ans = []
    for i in range(len(candidate)):
        if i == (len(candidate) - 1):
            continue
        for j in range(i + 1, len(candidate)):
            if i == j:
                continue
            else:
                ans.append((candidate[i] * candidate[j]) % 2019)
    ans.sort()
    print(ans[0])


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

def is_even(a):
    for num in a:
        if num % 2 != 0:
            return False
    return True

cnt = 0

while is_even(a):
    a = [num / 2 for num in a]
    cnt += 1

print(cnt)

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

int main() {
  // ここにプログラム
  int n, a, b, x, ans;
  cin >> n >> a >> b;
  int cou1, cou2, cou3 = 0;
  for(int i = 0; i < n; i++) {
    cin >> x;
    if(x <= a) cou1++;
    else if(a < x && x <= b) cou2++;
    else if(b < x) cou3++;
  }
  ans = min(cou1, min(cou2, cou3));
  cout << ans << endl;

  
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
using namespace std;
#define rep(i, n) for (int i=0; i<(int) (n);i++)
using ll = long long;
using P = pair<int, int>;

void solve_1() {//14m
	int a, b;
	cin >> a >> b;
	int total;
	int n = 0;
	while (!((a-1)*n + 1 >= b)) {
		n++;
	}
	cout << n << endl;

}

void solve_2() {//30m
	int n;
	cin >> n;
	vector<int> x;
	int total = 0;
	rep(i, n) {
		int tmp;
		cin >> tmp;
		x.push_back(tmp);
		total += tmp;
	}
	int p1 = (double(total)/double(n)*2 - 1.0) / 2;
	int p2 = (double(total)/double(n)*2 - 1.0) / 2 + 1;
	int point_sum1 = 0, point_sum2= 0;
	rep(i, n) {
		point_sum1 += pow(x[i] - p1, 2);
		point_sum2 += pow(x[i] - p2, 2);
	}
	cout << min(point_sum1, point_sum2) << endl;

}

void solve_2re() {
	int n;
	cin >> n;
	vector<int> x(n);
	int total = 0;
	rep(i, n) {
		cin >> x[i];
		total += x[i];
	}
	int p1 = total / n;
	int p2 = total / n + 1;
	int point_sum1 = 0, point_sum2 = 0;
	rep(i, n) {
		point_sum1 += pow(x[i] - p1, 2);
		point_sum2 += pow(x[i] - p2, 2);
	}
	cout << min(point_sum1, point_sum2) << endl;
}

void solve_3() {//17m
	int n, a, b;
	cin >> n >> a >> b;
	string s;
	cin >> s;
	int sum = a + b;
	rep(i, n) {
		if (s[i] == 'a') {
			cout << (sum > 0 ? "Yes" : "No") << endl;
			if (sum>0) {
				sum--;
			}
		}
		else if (s[i] == 'b') {
			cout << (sum > 0 && b > 0 ? "Yes" : "No") << endl;
			if (sum > 0 && b > 0) {
				if (b>0) {
					sum--;
					b--;
				}
				else {
					sum--;
				}
			}
		}
		else if (s[i] == 'c') {
			cout << "No" << endl;
		}
	}
}

void solve_4() {

}

void solve_5() {

}

void solve_6() {

}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//solve_1();
	//solve_2();
	//solve_2re();
	solve_3();
	//solve_4();
	//solve_5();
	//solve_6();
	return 0;
}

Measured memory_bytes: 848
/**
 *    author:  tourist
 *    created: 21.01.2020 23:57:15       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  int low = 0, high = n - 1;
  while (low < high) {
    int mid = (low + high) >> 1;
    int s = a[mid];
    bool fail = false;
    for (int i = 0; i < n; i++) {
      if (i == mid) {
        continue;
      }
      if (a[i] > 2 * s) {
        fail = true;
        break;
      }
      s = min(s + a[i], a[n - 1]);
    }
    if (fail) {
      low = mid + 1;
    } else {
      high = mid;
    }
  }
  cout << n - low << '\n';
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define ld long double
#define pll pair<ll, ll>
#define pii pair<int, int>
#define f first
#define se second
#define pb push_back
 
 
using namespace std;
 
 
const int N =  2e5 + 123;
const int MAXN = 2e5;
const int brd = 32;
const ull inf = 1e18 + 7;
 
 
int main() {
    string s;
    cin >> s;
    int n = s.size();
    if (s[0] == '0' || s[n - 1] == '1')
        return cout << -1, 0;
    s = "0" + s;
    for (int i = 0; i <= n; i++) {
        if (s[i] != s[n - i])
            return cout << -1, 0;
    }
    vector <int> c, a;
    for (int i = 1; i <= n; i++) {
        if (s[i] == '1')
            c.pb(i);
    }
    c.pb(n);
    for (int i = c.size() - 1; i >= 0; i--) {
        if (i == 0)
            a.pb(c[i]);
        else
            a.pb(c[i] - c[i - 1]);
    }
    reverse(a.begin(), a.end());
    int cur = 1;
    vector <pair<int, int> > edg;
    for (int i = 0; i < a.size(); i++) {
        int root = cur;
        for (int j = 1; j <= a[i]; j++) {
            if (cur + j <= n)
                edg.pb({cur + j, root});
        }
        cur += a[i];
    }
    for (int i = 0; i < edg.size(); i++)
        cout << edg[i].f << " " << edg[i].se << endl;
}


Measured memory_bytes: 3184
# -*- coding: utf-8 -*-
"""
https://abc060.contest.atcoder.jp/tasks/abc060_b

"""
import sys
from sys import stdin
input = stdin.readline


def solve(A, B, C):
    rem = []
    i = 1
    while True:
        t = (A*i) % B
        if not t in rem:
            rem.append(t)
        i += 1
        if i > 100000:
            break
    if C in rem:
        return 'YES'
    else:
        return 'NO'


def main(args):
    A, B, C = map(int, input().split())
    ans = solve(A, B, C)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 3064
#include <iostream>
#include <map>
using namespace std;
typedef long long ll;

int main() {
	int N, M;
	cin >> N >> M;
	map<int, int> mii;

	for (int i = 0; i < N; i++) {
		int A;
		cin >> A;
		mii[A]++;
	}

	for (int i = 0; i < M; i++) {
		auto last = mii.rbegin();
		++mii[last->first/2];
		if (last->second == 1) mii.erase(last->first);
		else --last->second;
	}

	ll total = 0;
	auto end = mii.end();
	for (auto itr = mii.begin(); itr != end; itr++) {
		total += (ll)itr->first * itr->second;
	}

	cout << total << endl;

	return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define rep2l(i, s, n) for (ll i = (ll)(s); i < (ll)n; i++)

int main() {
    int H1, M1, H2, M2, K;
    cin >> H1 >> M1 >> H2 >> M2 >> K;
    int wake;
    if (M2 >= M1) {
        wake = 60*(H2-H1) + (M2-M1);
    }
    else {
        wake = 60*(H2-1-H1) + (M2+60-M1);
    }
    cout << wake - K << endl;
}

Measured memory_bytes: 3632
#include <iostream>
using namespace std;
int n, m, q;
int a[50], b[50], c[50], d[50];

int A[11];
int f(int x, int y){
    int res = 0;
    A[x] = y;
    if(x == n+1){
        for(int i=0;i<q;i++){
            if(A[b[i]] - A[a[i]] == c[i]) res += d[i];
        }
    }else{
        for(int i=y;i<=m;i++){
            res = max(res, f(x+1, i));
        }
    }
    return res;
}

int main(void){
    cin >> n >> m >> q;
    for(int i=0;i<q;i++) cin >> a[i] >> b[i] >> c[i] >> d[i];

    int ans = 0;
    for(int i=1;i<=m;i++) ans = max(ans, f(1, i));
    cout << ans << endl;

}


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

#define FOR(i, a, b) for (int i = a, _b = b; i <= _b; ++i)
#define FORD(i, a, b) for (int i = a, _b = b; i >= _b; --i)
#define REP(i, a) for (int i = 0, _a = a; i < _a; ++i)
#define llint long long
#define sz(x) (x.size())
#define LL(x) (x * 2)
#define RR(x) (x * 2 + 1)
#define fi first
#define se second
#define db(x) cout << #x << " = " << x << endl;
#define BIT(x, i) ((x >> i) & 1)
#define MASK(i) (1ll << i)
#define times clock() * 1.0 / CLOCKS_PER_SEC

void openFile() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifdef Tr___
	freopen("test.inp", "r", stdin);
	freopen("test.out", "w", stdout);
	#endif
}

const int maxN = 300 + 5;
const int maxM = 1e6 + 5;
const llint INF = 1e9 + 7;

int N, M;
vector<pair<int, int> > lef[maxN];
int dp[maxN][maxN][maxN];

void enter() {
	scanf("%d%d", &N, &M);
	FOR(i, 1, M) {
		int l, r, x;
		scanf("%d%d%d", &l, &r, &x);
		lef[r].push_back({l, x});
	}
}

inline bool ok(int r, int g, int b) {
	int rig = max(r, max(g, b));
	for (auto l : lef[rig]) {
		if ((r >= l.fi) + (g >= l.fi) + (b >= l.fi) != l.se) return false;
	}
	return true;
}

inline void add(int &x, int y) {
	x = (x + y);
	if (x >= INF) x -= INF;
}

void solve() {
	dp[1][0][0] = 1;
	dp[0][1][0] = 1;
	dp[0][0][1] = 1;
	for (auto l : lef[1]) {
		if (l.se != 1) {
			printf("0");
			return;
		}
	}

	FOR(k, 1, N - 1) {
		//R
		FOR(g, 0, k - 1) if (g == 0 || (g != k)) {
			FOR(b, 0, k - 1) if (b == 0 || (b != g && b != k)) {
				if (ok(k + 1, g, b)) add(dp[k + 1][g][b], dp[k][g][b]);
				if (ok(k, k + 1, b)) add(dp[k][k + 1][b], dp[k][g][b]);
				if (ok(k, g, k + 1)) add(dp[k][g][k + 1], dp[k][g][b]);
			}
		}
		//G
		FOR(r, 0, k - 1) if (r == 0 || (r != k)) {
			FOR(b, 0, k - 1) if (b == 0 || (b != r && b != k)) {
				if (ok(r, k + 1, b)) add(dp[r][k + 1][b], dp[r][k][b]);
				if (ok(k + 1, k, b)) add(dp[k + 1][k][b], dp[r][k][b]);
				if (ok(r, k, k + 1)) add(dp[r][k][k + 1], dp[r][k][b]);
			}
		}
		//B
		FOR(r, 0, k - 1) if (r == 0 || (r != k)) {
			FOR(g, 0, k - 1) if (g == 0 || (g != r && g != k)) {
				if (ok(r, g, k + 1)) add(dp[r][g][k + 1], dp[r][g][k]);
				if (ok(k + 1, g, k)) add(dp[k + 1][g][k], dp[r][g][k]);
				if (ok(r, k + 1, k)) add(dp[r][k + 1][k], dp[r][g][k]);
			}
		}
	}

	int res = 0;

	FOR(i, 0, N) {
		FOR(j, 0, N) {
			FOR(k, 0, N) {
				if (i == N || j == N || k == N) {
					add(res, dp[i][j][k]);
				}
			}
		}
	}

	printf("%d\n", res);
}

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


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

using namespace std;

int n,k;
const int inf = int(1e9);
int s[100005];

int dp[1000000];


int main() {
    cin >> n>>k;
    for(int i=0;i<n;i++){
        cin>> s[i];
    }

    for(int i=1;i<n;i++){
        dp[i]=inf;
    }
    for(int i=0;i<n;i++){
        for(int j = 1;j<=k;j++){
            dp[i+j]=min(dp[i+j],dp[i]+abs(s[i]-s[i+j]));
        }
    }

    cout << dp[n-1]<<endl;

    return 0;
}

Measured memory_bytes: 2944
using System;

namespace ABC159
{
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = Console.ReadLine();
            var l = int.Parse(s);

            var p = new ProblemC();
            Console.WriteLine(p.GetAnswer(l));
        }
    }

    public class ProblemC
    {
        public double GetAnswer(double l)
        {
            var x = l / 3;
            return x * x * x;
        }
    }
}


Measured memory_bytes: 11092
s = input()
if s[0] == s[len(s) - 1]:
    # a bab a
    if len(s) % 2 == 0:
        print("First")
    else:
        print("Second")
else:
    # a baba b
    if len(s) % 2 == 1:
        print("First")
    else:
        print("Second")

Measured memory_bytes: 3316
use text_io::*;

fn main(){
  let n:usize = read!();
  
  let mut acc = 0;
  for i in 1..=(n-1){
    if i*i>(n-1){break;}
    else if i*i==(n-1){acc+=1;}
    else if (n-1)%i==0{acc+=2;}
  }
  
  acc-=1;
  
  let m=n;
  let mut ac=0;
  
  for i in 1..m{
    if i*i>n{break;}
    else if i*i==n{if judge(n,i){ac+=1;}}
    else if m%i==0{
      let j = m/i;
      if judge(n,i){ac+=1;}
      if judge(n,j){ac+=1;}
    }
  }
    
    println!("{}",acc+ac);
}

fn judge(n:usize,i:usize)->bool{
  if i==1{false}
  else if n%i==0{judge(n/i,i)}
  else {n%i==1}
}

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

int main(){
    using namespace std;
    unsigned long N, M;
    cin >> N >> M;
    vector<unsigned long> A(N);
    for(auto& i : A)cin >> i;
    sort(A.begin(), A.end());

    vector<unsigned long> tap(N), ans(N);
    {
        vector<pair<unsigned long, unsigned long>> T(M);
        for(auto &i : T)cin >> i.second >> i.first;
        sort(T.rbegin(), T.rend());
        unsigned long idx{0};
        for(const auto& i : T){
            idx += i.second;
            idx = min(idx, N);
            tap[idx - 1] = i.first;
            if(idx == N)break;
        }
    }
    partial_sum(tap.rbegin(), tap.rend(), tap.rbegin(), [](auto a, auto b){return max(a, b);});
    transform(A.begin(), A.end(), tap.begin(), ans.begin(), [](auto a, auto b){return max(a, b);});
    cout << accumulate(ans.begin(), ans.end(), 0UL) << endl;
    return 0;
}

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

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


int main()
{
    long long N, K;
    cin >> N >> K;

    cout << min(N%K, abs(N%K-K)) << endl;

    return 0;
}

Measured memory_bytes: 256
s = input()
ans = 0
center = len(s) // 2

if len(s) % 2 == 1:
  s2 = s[center+1:]
else:
  s2 = s[center:]

s1 = s[:center]
s2 = "".join(reversed(s2))
for str1 , str2 in zip(s1,s2):
  if str1 != str2:
    ans += 1
print(ans)

Measured memory_bytes: 8968
N, A, B = gets.split.map &:to_i
S = gets.chomp.chars
sum_a = 0
sum_b = 0

S.each do |e|
  case e
  when 'a'
    if sum_a + sum_b < A + B
      puts 'Yes'
      sum_a += 1
    else
      puts'No'
    end
  when 'b'
    if sum_a + sum_b < A + B && sum_b < B
      puts 'Yes'
      sum_b += 1
    else
      puts 'No'
    end
  else
    puts 'No'
  end
end


Measured memory_bytes: 22544
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pii pair<int,int>
inline int read()
{
	int x=0;
	bool pos=1;
	char ch=getchar();
	for(;!isdigit(ch);ch=getchar())
		if(ch=='-')
			pos=0;
	for(;isdigit(ch);ch=getchar())
		x=x*10+ch-'0';
	return pos?x:-x;
}
char buf[100001];
int a,b,c;
int main()
{
	scanf("%d/%d/%d",&a,&b,&c);
	if(a>2019)
		return puts("TBD")&1;
	if(b>4)
		return puts("TBD")&1;
	if(c>30)
		return puts("TBD")&1;
	puts("Heisei");
	return 0;
}


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

int main() {
  int r, g, b;
  cin >> r >> g >> b;

  int n = r * 100 + g * 10 + b;
  if (n % 4 == 0)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

ll gcd(ll a,ll b){
	if(!b) return a;
	return gcd(b,a%b);
}

int n,x;

int main(){
	cin>>n>>x;
	int g=0;
	for(int i=0;i<n;i++){
		int a;
		cin>>a;
		g=gcd(g,abs(a-x));
	}
	cout<<g<<endl;
}

Measured memory_bytes: 256
X = input()
l = []
for i in range(len(X)):
    if X[i] == "S":
        l.append("S")
    elif X[i] == "T":
        if len(l) > 0 and l[-1] == "S":
            l.pop(-1)
        #  lが空 or lの末尾がT
        else:
            l.append("T")
ans = len(l)
print(ans)


Measured memory_bytes: 10508
#逆元しない場合

from fractions import gcd

n=int(input())

a=list(map(int,input().split()))
mod=10**9+7




L=a[0]
def lcm(x,y):
    return x//gcd(x,y)*y

for i in a:
    L=lcm(L,i)


print(sum([L//i for i in a])%mod)

Measured memory_bytes: 264672
#include <stdio.h>
 
int main() {
	long long int N, K, a, count = 0, ans;
 
	scanf("%lld %lld", &N, &K);
 
	for (a = K; a <= N; a += K) {
		count++;
	}
	ans = count * count * count;
 
	if (K % 2 == 0) {
		count = 0;
		for (a = K / 2; a <= N; a += K) {
			count++;
		}
		ans += count * count * count;
	}
 
	printf("%lld", ans);
 
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
using namespace std;
int main(){
    string s;
    cin >> s;
    string s2 = s.substr(0,4) + s.substr(5,2) + s.substr(8,2);
    if ( atoi(s2.c_str()) <= 20190430 ){
        printf("Heisei");
    }
    else{
        printf("TBD");
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
#define PB push_back
#define EB emplace_back
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

int main(){
	int a, b; scanf("%d%d", &a, &b);
	if(b%a==0) printf("%d\n", a+b);
	else printf("%d\n", b-a);
}


Measured memory_bytes: 256
A,B,C,K=map(int,input().split())
#print(A,B,C,K)
#a a <A
#b b <B
#c K-a-b <C 
if K < A:
    ans=K
elif K-A <= B and K>=A:
    ans=A
else :
    ans=A-(K-A-B)
print(ans)

Measured memory_bytes: 8904
#include <bits/stdc++.h>
using namespace std;
long long a,b,res;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#ifdef LOCAL
    freopen("test.inp","r",stdin);
    freopen("test.out","w",stdout);
#endif // LOCAL
    cin>>a>>b;
    if(a==1) res+=300000;
    if(a==2) res+=200000;
    if(a==3) res+=100000;
    if(b==1) res+=300000;
    if(b==2) res+=200000;
    if(b==3) res+=100000;
    if(a==1 && b==1) res+=400000;
    cout<<res;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <queue>
using namespace std;
#define sosu 1000000
bool so[1000002];
int n,x,c[51];
bool his[1000002];
int ans;
queue <int> Q;
int count =0;

void hantei() {
  so[0] = so[1] = 1;
  for(int i=2;i*i<=1000001;i++) 
    if(so[i] == 0) 
      for(int j=2;j<=1000001/i;j++)so[i*j] = 1;
}

void saiki(int sum) {
  cout <<"count " << count++ << endl;
  his[sum] = 1;
  if(so[sum] == 0 && ans < sum) ans = sum;
   cout <<sum <<endl;
   
  for(int i=0;i<n;i++) 
    if(c[i]+sum <= x && his[c[i]+sum] == 0) 
      saiki(c[i]+sum);

}

void bfs() {
  
  Q.push(0);
  ans = 0;
  while(!Q.empty()) {
    //cout <<"count " << count++ << endl;
    int t = Q.front();
    Q.pop();
    if(his[t] == 1){
      //  cout << "err "<<t<<endl;
      continue;
    }
    his[t] = 1;
    //cout <<"t "<<  t << endl;
    
    if(ans < t && so[t] == 0) ans = t;
    
    for(int i=0;i<n;i++) 
      if(t+c[i] <= x &&  his[t+c[i]] == 0)
	Q.push(t+c[i]);
    
    
  } 
}



int main() {
  hantei();

  while(1){
    cin >> n >> x;
    if(n == 0 && x == 0) break;

    for(int i=0;i<n;i++) cin >> c[i];
    for(int i=0;i<=x+1;i++) his[i] = 0;
    
    ans = 0;
    //saiki(0);
       bfs();
    if(ans == 0) cout <<"NA"<<endl;
    else cout << ans << endl;
    
  }
  
  return 0;
}

Measured memory_bytes: 4292
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception{
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(bf.readLine());
        System.out.println(N*N*N);
    }

}

Measured memory_bytes: 21076
# D
from math import sqrt
def sieve(n:int)->list:
    """エラトステネスの篩"""
    if n<2:  return [False]*(n+1)
    is_prime = [True]*(n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(sqrt(n))+1):
        if is_prime[i]:
            for j in range(i*2, n+1, i):
                is_prime[j] = False
    
    return is_prime


N = int(1e5)
is_prime = sieve(N)
# like-2017
cnt = [0]*(N+1)
for i in range(1, N+1):
    cnt[i] += cnt[i-1]
    if is_prime[i] and is_prime[(i+1)//2]:
        cnt[i] += 1
    
Q = int(input())
for _ in range(Q):
    l,r = map(int, input().split())
    print(cnt[r]-cnt[l-1])

Measured memory_bytes: 7284
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;

/*BigInteger
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/rational.hpp>
namespace xxx = boost::multiprecision;
using Bint = xxx::cpp_int;
using Real = xxx::number<xxx::cpp_dec_float<1024>>;
*/

#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0, sizeof(x))
#define mm(x) memset((x), -1, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define bit(n) (1LL << (n))
#define bitset(a, b) (a) |= (1 << (b))
#define bitunset(a, b) (a) &= ~(1 << (b))
#define bitcheck(a, b) ((((a) >> (b)) & 1) == 1)
#define bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
constexpr int INF = (int)1e18;
constexpr int MOD = (int)1e9 + 7;
constexpr double PI = (double)acos(-1);
constexpr double EPS = (double)1e-10;
constexpr int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
constexpr int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
template <typename T>
void chmax(T &a, T b) { a = max(a, b); }
template <typename T>
void chmin(T &a, T b) { a = min(a, b); }
//
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
};

int N;
int a[20][20];

int score[bit(16) + 10];
int dp[bit(16) + 10];

void calc() {
  for (int bit = 0; bit < bit(N); bit++) {
    for (int i = 0; i < N; i++) {
      for (int j = i + 1; j < N; j++) {
        if (bitcheck(bit, i) && bitcheck(bit, j)) {
          score[bit] += a[i][j];
        }
      }
    }
  }
  return;
}

signed main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      cin >> a[i][j];
    }
  }

  calc();

  int ans = -INF;
  for (int bit = 0; bit < bit(N); bit++) {
    for (int a = bit;; a = (a - 1) & bit) {
      dp[bit] = max(dp[bit], dp[bit & ~a] + score[a]);
      if (!a) break;
    }
    ans = max(ans, dp[bit]);
  }

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


Measured memory_bytes: 1280
import java.util.Map.Entry;
import java.util.*;
import java.math.*;
import org.w3c.dom.css.Counter;
  
public class Main{
    public static void main(String[] args){
        Scanner s = new Scanner(System.in);
        //モンスターの体力
        int H = Integer.valueOf(s.next());
        //魔法の種類
        int N = Integer.valueOf(s.next());
        //体力減少
        int[] HPdown = new int[N+1];
        //魔法減少
        int[] MPcost = new int[N+1];
        //未到達の値
        int noRoot = 999999999;
		for(int i = 0; i < N; i++) {
			HPdown[i] = Integer.valueOf(s.next());
			MPcost[i] = Integer.valueOf(s.next());
        }
    
		//動的
        long[] dp = new long[20000];
        //整頓
        Arrays.fill(dp, noRoot);
        //初期値(0)設定
		dp[0] = 0;
        //魔法の種類だけくり返す
		for(int i = 0; i < N; i++) {
            //i=0
            //十分な数繰り返す
			for(int j = 0; j < 10000; j++) {
                //そのHPへの到達方法がある場合
                if(dp[j]!= noRoot){
                    //あるHP値への到達方法に対して
                    //既存の方法と、新しい方法、より低コストな方を選択
                    dp[j+HPdown[i]] =
                    Long.min(dp[j+HPdown[i]], dp[j] + MPcost[i]);
                }
			}
        }
        //目標値以上の到達方法のなかから、最小のものを選択
		for(int i = 10001; i >= 0; i--) {
			dp[i] = Long.min(dp[i], dp[i+1]);
		}
		System.out.println(dp[H]);
    }
}
    


    

Measured memory_bytes: 39044
N = int(input())

A = []

maxi = 0
sec = 0

for i in range(N):

    a = int(input())
    A.append(a)


    if A[maxi] <= a:
        maxi = i

B = A.copy()

del B[maxi]

sec = max(B)




for i in range(N):

    if i == maxi:
        print (sec)

    else:
        print (A[maxi])


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

int main() {
  int N, M;
  cin >> N;
  vector<string> s(N);
  for(int i = 0; i < N; i++)
    cin >> s.at(i);
  cin >> M;
  vector<string> t(M);
  for(int i = 0; i < M; i++)
    cin >> t.at(i);
  int max = 0;
  for(int i = 0; i < N; i++) {
    int p = 0;
    for(int j = 0; j < N; j++)
      if(s.at(i) == s.at(j))
        p++;
    for(int j = 0; j < M; j++)
      if(s.at(i) == t.at(j))
        p--;
    if ( max < p )
      max = p;
  }
  cout << max << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<math.h>

#define rep(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define rrep(i,a,n) for(int (i)=(a);(i)>=(n);(i)--)

#define INF 100000000

typedef  long long ll;

using namespace std;

double euclid_distance(double a,double b){
    return sqrt(a*a+b*b);
}

int gcd(long long int a,long long int b){
    long long int r;
    if(a < b){
        int tmp;
        tmp = a;
        a = b;
        b = tmp;
    }
    while(r != 0){
        r = a % b;
        a = b;
        b = r;
    }
    return r;
}

void Integer_factorization(long long int b,long long int n){
    long long int a = 2;
    long long int count = 0;
    long long int ans = 1;
    long long int ndash = n;
    if(b == 1) cout << n << endl;
    else{
    while(ndash >= a*a){
        if(n % a  == 0){
            count++;
            n/=a;

        if(count % b == 0){
            ans *= a;
        }
        }else{a++;count = 0;}
    }

    cout<<  ans << endl;
    }
}

void ys(){
    cout << "Yes" << endl;
}

void yb(){
    cout << "YES" << endl;
}

void ns(){
    cout << "No" << endl;
}

void nb(){
    cout << "NO" << endl;
}
//A  40s
//B  30min(+30min)
//C  
//D
 string ans;
void solve(void){
    int n;
    cin >> n;
    int a[n];
    rep(i,0,n)cin >> a[i];
    int mna = INF,mxa=-INF;
    rep(i,0,n){
        mna = min(mna,a[i]);
        mxa = max(mxa,a[i]);
    }
    if(mna == mxa) cout << 0<< endl;
    else{
        ll ans = (ll)INF*1000;
        rep(i,mna,mxa){
            ll tmp = 0;
            rep(j,0,n){
                tmp+=(a[j]-i)*(a[j]-i);
            }
            ans = min(ans,tmp);
        }
        cout << ans << endl;
    }
}

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


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


using namespace std;

int main()
{
    long N=0, M=0;  cin >> N; cin >> M;
    vector<long> X(M);
    vector<long> Y(M-1);
    long ans = 0;

    for(int i=0; i<M; i++){
        cin >> X[i];
    }

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

    for(int i=0; i<M-1; i++){
        Y[i] = X[i+1] - X[i];
    }

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

    for(int i=0; i<M-N; i++){
        ans += Y[i];
    }

    cout << ans;

    return 0;
}

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

#define PI 3.14159265358979323846264338327950288419

using namespace std;

int mina, minb;

int a, b, m;
int pa[100005];
int pb[100005];

int main(){
	scanf("%d %d %d", &a, &b, &m);
	for(int i = 1; i <= a; i++){
		scanf("%d", &pa[i]);
		if(i == 1 || pa[i] < mina){
			mina = pa[i];
		}
	}
	for(int i = 1; i <= b; i++){
		scanf("%d", &pb[i]);
		if(i == 1 || pb[i] < minb){
			minb = pb[i];
		}
	}
	int ans = mina + minb;
	for(int i = 1; i <= m; i++){
		int x, y, c;
		scanf("%d %d %d", &x, &y, &c);
		ans = min(ans, pa[x] + pb[y] - c);
	}
	printf("%d\n", ans);
	return 0;
}

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

N = int(input().strip())+2
A = list(map(int,input().split()))+[N-1,N]
INF = N
dp = [[-INF for j in range(N)] for i in range(N)]
dpmax = -INF
dpmaxj = [-INF for i in range(N)]
score = 0
a,b,c,d,e = [i-1 for i in sorted(A[:5])]

if a == b == c:
  dp[d][e] = dp[e][d] = dpmaxj[d] = dpmaxj[e] = dpmax = 1
elif b == c == d:
  dp[a][e] = dp[e][a] = dpmaxj[a] = dpmaxj[e] = dpmax = 1
elif c == d == e:
  dp[a][b] = dp[b][a] = dpmaxj[a] = dpmaxj[b] = dpmax = 1
else:
  L = [a,b,c,d,e]
  for i in range(5):
    for j in range(i+1,5):
      p,q = L[i],L[j]
      dp[p][q] = dp[q][p] = dpmaxj[p] = dpmaxj[q] = 0
  dpmax = 0 

def update(i,j):
  dpmaxj[i] = max(dpmaxj[i],dp[i][j])
  dpmaxj[j] = max(dpmaxj[j],dp[i][j])

for i in range(N-3):
  prevdpmax = dpmax
  prevdpmaxj = dpmaxj[:]
  dpd = [dp[k][k] for k in range(N)]
  a,b,c = A[i*3+5:i*3+8]
  a -= 1
  b -= 1
  c -= 1
  prevdpka = [dp[i][a] for i in range(N)]
  prevdpla = [dp[a][i] for i in range(N)] 
  prevdpkb = [dp[i][b] for i in range(N)]
  prevdplb = [dp[b][i] for i in range(N)] 
  if a == b == c:
    score += 1
    continue
  elif a == b:
    for k in range(N):
      dp[k][c] = max(dp[k][c],max(prevdpka[k],prevdpla[k]) + 1); update(k,c)
      dp[c][k] = max(dp[c][k],max(prevdpka[k],prevdpla[k]) + 1); update(c,k)
      dpmax = max(dpmax,dp[k][c],dp[c][k])
  elif a == c:
    for k in range(N):
      dp[k][b] = max(dp[k][b],max(prevdpka[k],prevdpla[k]) + 1); update(k,b)
      dp[b][k] = max(dp[b][k],max(prevdpka[k],prevdpla[k]) + 1); update(b,k)
      dpmax = max(dpmax,dp[k][b],dp[b][k])
  elif b == c:
    for k in range(N):
      dp[k][a] = max(dp[k][a],max(prevdpkb[k],prevdplb[k]) + 1); update(k,a)
      dp[a][k] = max(dp[a][k],max(prevdpkb[k],prevdplb[k]) + 1); update(a,k)
      dpmax = max(dpmax,dp[k][a],dp[a][k])
  
  dp[b][c] = max(dp[b][c],dpd[a] + 1); update(b,c)
  dp[c][b] = max(dp[c][b],dpd[a] + 1); update(c,b)
  dp[a][c] = max(dp[a][c],dpd[b] + 1); update(a,c)
  dp[c][a] = max(dp[c][a],dpd[b] + 1); update(c,a)
  dp[a][b] = max(dp[a][b],dpd[c] + 1); update(a,b)
  dp[b][a] = max(dp[b][a],dpd[c] + 1); update(b,a)
  dpmax = max(dpmax,dp[b][c],dp[a][c],dp[a][b],dp[c][b],dp[c][a],dp[b][a])
  
  dp[a][b] = max(0,dp[a][b],prevdpmax); update(a,b)
  dp[b][a] = max(0,dp[b][a],prevdpmax); update(b,a)
  dp[b][c] = max(0,dp[b][c],prevdpmax); update(b,c)
  dp[c][b] = max(0,dp[c][b],prevdpmax); update(c,b)
  dp[a][c] = max(0,dp[a][c],prevdpmax); update(a,c)
  dp[c][a] = max(0,dp[c][a],prevdpmax); update(c,a)

  for j in range(N):
    dp[j][a] = max(dp[j][a],prevdpmaxj[j]); update(j,a)
    dp[j][b] = max(dp[j][b],prevdpmaxj[j]); update(j,b)
    dp[j][c] = max(dp[j][c],prevdpmaxj[j]); update(j,c)
    dp[a][j] = max(dp[a][j],prevdpmaxj[j]); update(a,j)
    dp[b][j] = max(dp[b][j],prevdpmaxj[j]); update(b,j)
    dp[c][j] = max(dp[c][j],prevdpmaxj[j]); update(c,j)
    
print(max(dp[N-2][N-1],dp[N-1][N-2])+score)

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

int main() {
	char S[4];
	cin >> S;
	int ans = 0;

	for (int i = 0; i < 3; i++) {
		if (S[i] == S[i + 1]) {
			ans++;
		}
	}
	if (ans == 0) {
		cout << "Good" << endl;
	}else{
		cout << "Bad" << endl;
	}

	return 0;

}

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

int main(){
    int n;
    cin >> n;
    string s = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51,";
    string ans = "";
    int cnt = 0;
    int i = -1;
    while(cnt < n){
        i++;
        switch(s[i]){
            case ',':
                cnt++;
                if(cnt < n) ans = "";
            case ' ':
                break;
            default:
                ans += s[i];
                break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys
import math

def parse_input(lines_as_string = None):

    lines = []
    if lines_as_string is None:
        for line in sys.stdin:
            lines.append(line)
    else:
        lines = [e for e in lines_as_string.split("\n")][1:-1]

    params = lines[0].split(" ")
    a = int(params[0])
    b = int(params[1])

    return (a, b)


def solve(a, b):

    result = 0
    if b % a == 0:
        result = a + b
    else:
        result = b - a

    return result

def main():
    # 出力

    print("%d" % solve(*parse_input()))

if __name__ == '__main__':

    main()


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

using namespace std;

typedef long long ll;

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

	int a, b, c, d;
	cin >> a >> b >> c >> d;
	
	if(abs(a - c) <= d || (abs(a - b) <= d && abs(b - c) <= d)){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <utility>
#include <map>
#include <vector>
#include <cmath>
using namespace std;

typedef long long ll;


int N;
vector<vector<ll>> P;
map<ll, int> M;
vector<ll> Ans(3);


bool check(int i, int j){
    ll H = M.begin()->first;
    for(int k=0; k<N; k++)
        if(P[k][2]==0 && H - abs(P[k][0]-i) - abs(P[k][1]-j) > 0)
            return false;

   return true;
}


void solve(){
    for(int i=0; i<=100; i++){
        for (int j=0; j<=100; j++){
            for(int k=0; k<N; k++){
                if(P[k][2]!=0){
                    ll H = P[k][2] + abs(P[k][0]-i) + abs(P[k][1]-j);
                    M[H]++;
                }
            }

            if(M.size() == 1 && check(i, j)){
                Ans[0] = i;
                Ans[1] = j;
                Ans[2] = M.begin()->first;
            }
            M.clear();
        }
    }
}



int main() {
    cin >> N;
    P.resize(N);
    for(vector<ll> &v:P)
        v.resize(3);

    for(vector<ll> &v:P)
        for(ll &ll:v)
            cin >> ll;

    solve();
    cout << Ans[0] << " " << Ans[1] << " " << Ans[2] << endl;
    

    return 0;
}


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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 1e5 + 5;

ll my_sqrt(ll v){
	ll a = (ll)sqrt(v + 0.5);
	while(a * a <= v){
		a++;
	}
	a--;
	return a;
}

void solve(){
	ll a, b;
	cin >> a >> b;
	if (a > b){
		swap(a, b);
	}
	ll x = my_sqrt(a * b);
	ll ans = 2ll * (x - 1ll);
	if (a == x){
		if (b > a + 1){
			ans++;
		}
	} else {
		ans--;
		if (x * (x + 2) < a * b){
			ans += 3;
			if (b <= x + 2){
				ans--;
			}
		} else if (x * (x + 1) < a * b){
			ans += 2;
			if (b <= x + 1){
				ans--;
			}
		} else if (x * x < a * b){
			ans++;
		}	
	}
	cout << ans << endl;
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    cin >> t;
    while(t--){
        solve();    
    }
}


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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second

#define DUMP(x) cout<<#x<<":"<<(x)<<endl
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class T>
istream& operator>>(istream& is, vector<T>& xs){
  for(auto& x: xs)
	is >> x;
  return is;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& xs){
  for(unsigned int i=0;i<xs.size();++i)
	os << (i?" ":"") << xs[i];
  return os;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

const int MAX = 200010;
int N, dat[2*MAX];
struct segtree {
    segtree() {}
    segtree(int n) {
        N = 1;
        while(N < n) N *= 2;
        for(int i = 0; i < 2*N-1; i++)
            dat[i] = 0;
    }
    // update k th element
    void update(int k, int a) {
        k += N-1; // leaf
        dat[k] += a;
        while(k > 0) {
            k = (k - 1) / 2;
            dat[k] = dat[k*2+1] + dat[k*2+2];
        }
    }
    // min [a, b)
    int query(int a, int b) { return query(a, b, 0, 0, N); }
    int query(int a, int b, int k, int l, int r) {
        if(r <= a or b <= l) return 0;
        if(a <= l and r <= b) return dat[k];
        int m = (l + r) / 2;
        return (query(a, b, k*2+1, l, m) + query(a, b, k*2+2, m, r));
    }
};


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

  int N, M;
  cin >> N >> M;
  
  vector<PII> xs(M);
  REP(i,M){
    cin >> xs[i].SS >> xs[i].FF;
    xs[i].SS--;
    xs[i].FF--;
  }
  SORT(xs);

  int ans = 0;
  segtree seg(N);
  for(int i=0;i<M;++i){
    if(seg.query(xs[i].SS, xs[i].FF) == 0){
      seg.update(xs[i].FF-1, 1);
      ++ans;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 2048
def main():
    import bisect
    n = int(input())
    s = input()
    r,g,b = 0,0,0
    for i in range(n):
        if s[i]=='R':
            r+=1
        elif s[i]=='G':
            g+=1
        else:
            b+=1
    ans = r*g*b
    for i in range(n-1):
        for j in range(i+1,n):
            k = 2*(j+1)-(i+1)-1
            if k>n-1:
                continue
            if s[i]!=s[j] and s[i] != s[k] and s[j]!=s[k]:
                ans -= 1
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 9148
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <tuple>
#include <cassert>

using namespace std;

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define mp(a,b) make_pair((a), (b))
#define mt(a,b,c) make_tuple((a),(b),(c))

typedef long long ll;

int main(){
    int n,m; cin >>n >> m;
    vector<long long int> a(n); rep(i,n) cin >> a[i];
    vector<pair<long long int, long long int>> p(m);
    rep(i,m){
         ll b,c; cin >> b >> c;
         p[i].second = b; p[i].first = c;
    }
    sort(all(p)); sort(all(a));
    int pos = m-1;
    rep(i,n){
        if(a[i] < p[pos].first){
            a[i] = p[pos].first;
            p[pos].second--;
            if(p[pos].second==0){
                if(pos==0) break;
                else pos--;
            }
        }
    }
    ll ans = 0;
    rep(i,n) ans += a[i];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560