akhauriyash/Code-Regression huggingface dataset:
//Coded by Abhijay Mitra
#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <numeric>
#include <vector>
#include <iterator> 
#include <map>
#include <set>
#include <climits>
#include <queue>
#include <cmath>
#include <stack>
#include <cctype>
#include <bitset>
// #include <bits/stdc++.h>
#define double long double
#define int long long int
#define ll int
#define ibs ios_base::sync_with_stdio(false)
#define cti cin.tie(0)
#define bp __builtin_popcount
#define pb push_back
#define res(v) v.resize(unique(v.begin(), v.end()) - v.begin());
#define cnt_res(v) std::distance(v.begin(),std::unique(v.begin(), v.end())); 
#define timer cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using pii = std::pair<int,int>;
using vpii = std::vector<pii>;
using vvpii = std::vector<vpii>;
#define mp         make_pair
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define per(i,b,a) for (int i = b; i >= a; i--)
#define all(x)     x.begin(), x.end()
using namespace std;
const int N=2e6+10;
const int inf = /*0x3f3f3f3f*/1e18+10;
// const ll M = 998244353 ; // Mulo
// const int M = 1e9+7 ; // Mulo
const double Pi = 3.14159265;
#define F first
#define S second
int n,k;vi v,dp;
int f(int i){
  if(i<0)return inf;
  if(dp[i]!=-1)return dp[i];
  int mi=inf;
  for(int j=1;j<=k;j++)
    mi=min(abs(v[i-j]-v[i])+f(i-j),mi);
  return dp[i]=mi;
}
void solve(){
  cin>>n>>k;v=vi(n,0);dp=vi(n,-1);dp[0]=0;
  rep(i,0,n-1)cin>>v[i];
  cout<<f(n-1);
}
int32_t main()
{
  ibs;cti;
  solve()
  /*,cout<<"\n"*/;
  // cout<<"\n";
  int xx=0;
  // int t;cin>>t;while(t--){/*xx++;cout<<"Case "<<xx<<":\n"*/;solve();cout<<"\n";}
  return 0;
}

Measured memory_bytes: 8064
N, T = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
X.sort()
dp = [-1 for _ in range(T+X[-1][0]+10)]
dp[0] = 0
for i in range(N):
  for j in range(T, 0, -1):
    if dp[j-1] != -1:
      dp[j-1+X[i][0]] = max(dp[j-1+X[i][0]], dp[j-1] + X[i][1])
print(max(dp))


Measured memory_bytes: 74912
#include <bits/stdc++.h>
#define yes { cout << "YES" << endl; exit(0); }
#define no { cout << "NO" << endl; exit(0); }
#define impossible { cout << "Impossible" << endl; exit(0); }

using namespace std;

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

const int Nmax = 1e6 + 5;
char S[Nmax];
string v[Nmax];


ll gauss(int n)
{
    return (ll) n * (n+1) / 2;
}

ll solve(string &S)
{
    int nr1 = 0, nr2 = 0;

    for(auto it : S)
        if(it == '<') ++nr1;
            else ++nr2;
    
    if(nr1 < nr2) return gauss(nr2) + gauss(nr1 - 1);
        else return gauss(nr1) + gauss(nr2 - 1);
}

int main()
{
    //freopen("inputA", "r", stdin);
    // freopen("output", "w", stdout);
    cin.sync_with_stdio(false); cin.tie(0);
    
    int n;

    cin >> (S+1);
    n = strlen(S+1);

    int i, nr;

    nr = 1;
    for(i=1; i<=n; ++i)
    {
        if(S[i] == '<' && S[i-1] == '>') ++nr;
        v[nr].push_back(S[i]);
    }
    
    ll ans = 0;
    for(i=1; i<=nr; ++i) ans += solve(v[i]);
    cout << ans << '\n';

    return 0;
}



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

using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
typedef long long ll;
#define INF 1e9            //リテラル　 10の９乗を表す

int main(){
    int n; cin >> n;
    char c[5] = {'M','A', 'R', 'C', 'H'};
    map<char, ll> mp;
    rep(i,n){
        string s; cin >> s;
        rep(i,5){
            if(s[0] == c[i]){
                mp[c[i]]++;
            }
        }
    }
   
    ll ans = 0;
    char c1,c2,c3;
    
    for(int i=0; i<3; i++){
        for(int j=i+1; j<4; j++){
            for(int k=j+1; k<5;k++){
                c1 = c[i];
                c2 = c[j];
                c3 = c[k];
                ans += mp[c1]*mp[c2]*mp[c3];
            }
        }
    }
    cout << ans << endl;


    
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, N) for (int i = 0; i < N; i++)
using namespace std;
int main()
{
    string S;
    cin >> S;
    vector<char> A(26);
    int j = 0;
    for (char i = 'a'; i <= 'z'; i++)
    {
        A[j] = i;
        j++;
    }
    rep(i, S.size())
    {
        rep(k, 26)
        {
            if (S[i] == A[k])
            {
                A[k] = '0';
            }
        }
    }
    rep(k, 26)
    {
        if (A[k] != '0')
        {
            cout << A[k] << endl;
            return 0;
        }
    }
    cout << "None" << endl;
}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    LL X, Y;
    cin >> X >> Y;

    if(llabs(X - Y) <= 1) {
        cout << "Brown" << endl;
    } else {
        cout << "Alice" << endl;
    }

    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int w = 0,h = 0,x = 0,y = 0,r = 0;
  scanf("%d %d %d %d %d",&w,&h,&x,&y,&r);

  //  x = x + r;
  //  y = y + r;

  if((0 <= x - r && x + r <= w) && (0 <= y - r && y + r <= h)){
    puts("Yes");
  }else {
    puts("No");
  }
  return 0;
}

Measured memory_bytes: 584
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<ll,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

const ll M = 1000000007;

ll modpow(ll x,ll k){
	if(k == 0)return 1;
	ll ret = modpow(x,k/2);
	ret *= ret; ret %= M;
	if(k&(ll)1){ ret *= x; ret %= M; }
	return ret;
}
ll inv(ll x){
	return modpow(x,M-2);
}

const int MAX_N_math_C = 220002;
ll fact[MAX_N_math_C],fact_inv[MAX_N_math_C];
void math_C_init(){
	fact[0] = 1; fact_inv[0] = 1;
	rep1(i,MAX_N_math_C-1){
		fact[i] = fact[i-1] * i; fact[i] %= M;
		fact_inv[i] = inv(fact[i]);
	}
}
ll math_C(ll n,ll k){
	ll ret = fact[n]*fact_inv[k]; ret %= M;
	ret *= fact_inv[n-k]; ret %= M;
	return ret;
}

int main(){
	math_C_init();
	
	ll n,m,k;
	cin >> n >> m >> k;
	
	static ll dp[2][10002];
	int t = 0 , t_ = 1;
	static ll dp_[10002];
	rep(i,2)rep(j,10002)dp[i][j] = 0;
	dp[t][0] = 1;
	rep(i,2*k){
		if(t == 0)dp_[i/2] = dp[t][0]%M;
		rep(j,k+1)dp[t_][j] = 0;
		rep(j,k+1){
			dp[t][j] %= M;
			if(j > 0)dp[t_][j-1] += dp[t][j];
			dp[t_][j+1] += dp[t][j];
		}
		swap(t,t_);
	}
	
	ll ret = 0;
	rep(i,k+1){
		ll sum0 = 0,sum1 = 0;
		rep(j,i){
			sum0 += dp_[j] * math_C(n+2*i-2*j-1,i-1-j);
			sum0 %= M;
		}
		rep(j,k-i){
			sum1 += dp_[j] * math_C(m+2*(k-i)-2*j-1,(k-i)-1-j);
			sum1 %= M;
		}
		ll a = math_C(n+2*i,i)-sum0; if(a < 0)a += M;
		ll b = math_C(m+2*(k-i),k-i)-sum1; if(b < 0)b += M;
		a *= b; a %= M;
		a *= math_C(n+m+2*k,n+2*i); a %= M;
		ret += a;
		ret %= M;
	}
	cout << ret << endl;
}
	

Measured memory_bytes: 4832
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
#define dame { printf("No\n"); return 0;}
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e17)


signed main(){
    int a;
    cin >> a;
    int mae = a / 100;
    int usiro = a % 100;
    if( 1 <= mae and mae <= 12 ){
        if( 1 <= usiro and usiro<= 12){
            cout <<  "AMBIGUOUS" << endl;
        }
        else cout << "MMYY" << endl;
    }
    else{
        if( 1 <= usiro and usiro <= 12){
            cout <<  "YYMM" << endl;
        }
        else cout << "NA" << endl;
    }

}


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

using namespace std;

int main(){
	char n;
	cin>>n;
	char array[]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
	for(int i=0 ; i<25;i++){
		
	
		if(array[i]==n){
			cout<<array[i+1]<<endl;
			
		}
	}
	
	
	
	return 0;
}

Measured memory_bytes: 256
N, C, K = map(int, input().split())
T = sorted([int(input()) for _ in range(N)])

ans = 1
bus = 0
before = T[0]

for i in T:
    if bus+1 > C or i - before > K:
        bus = 1
        ans += 1
        before = i
    else:
        bus += 1
    
    # print(f"i{i} bus{bus} ans{ans}")
print(ans)


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

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;

int main() {

    int n;
    cin >> n;
    vector<int> ds(n);
    rep(i, n) {
        int d;
        cin >> d;
        ds[i] = d;
    }
    int dsum = 0;
    for (int x = 0; x < n; x++) {
        for (int y = 0; y < n; y++) {
            if (x == y) {
                continue;
            }
            dsum += (ds[x] * ds[y]);
        }
    }

    cout << (dsum / 2) << endl;

}



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

int main(){
    long long a, b, c; cin >> a >> b >> c;
    long long d = c - a - b;
    if(d * d > 4 * a * b && d > 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

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

x = [0]*51
for a in range(10):
    for b in range(10):
        for c in range(10):
            for d in range(10):
                x[a+b+c+d] += 1

array = []
for i in sys.stdin:
    array.append(i)

for k in range(len(array)):
    n = array[k]
    print(x[int(n)])

Measured memory_bytes: 7508
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <tuple>
#include <cstring>
#include <map>
#include <iomanip>
#include <ctime>
#include <complex>
#include <cassert>
#include <climits>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define _ << " " <<
#define all(X) (X).begin(), (X).end()
#define len(X) (X).size()
#define Pii pair<int, int>
#define Pll pair<ll, ll>
#define Tiii tuple<int, int, int>
#define Tlll tuple<ll, ll, ll>

ll pw(ll x, ll y, ll mod) {
    if (y == 0) return 1;
    else if (y == 1) return x % mod;
    else if (y % 2 == 0) {
        ll p = pw(x, y / 2, mod);
        return p * p % mod;
    }
    else {
        ll p = pw(x, y / 2, mod);
        return p * p % mod * x % mod;
    }
}

ll dv(ll x, ll y, ll mod) {
    x %= mod;
    y %= mod;
    return x * pw(y, mod - 2, mod) % mod;
}
 
ll comb(ll n, ll r, ll mod) {
    ll v = 1;
    if (n < r || n < 0 || r < 0) return 0;
    for (int i = 1; i <= r; i++) {
        v = v * dv(n - i + 1, i, mod) % mod;
    }
    return v;
}

int main() {
    ll n, k, mod = 1e9 + 7;
    cin >> n >> k;

    cout << pw(k, n, mod) << endl;
}



Measured memory_bytes: 3112
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <string>

typedef long long int ll;
typedef unsigned long long int ull;

using namespace std;

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

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

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b;cin >> a >> b;
	if(b<10) a*=10;
	else if(b<100) a*=100;
	else a*=1000;
	a+=b;
	for(int i=1;i*i<=110000;++i){
		if(a%i==0 && a/i==i){
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int number = input.nextInt();
        int[] array = new int[number];
        for (int i = 0; i < array.length; i++) {
            array[i] = input.nextInt();
        }
        
        int min = array[0];
        int max = array[0];
        long total = 0;
        for (int i = 0; i < array.length; i++) {
            if (min > array[i]) {
                min = array[i];
            }
            if (max < array[i]) {
                max = array[i];
            }
            total += array[i];
        }
        
        System.out.println(min + " " + max + " " + total);
    }
}


Measured memory_bytes: 43188
from collections import defaultdict, deque
import sys
import heapq
import bisect
import itertools
import queue
import copy
import time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7

def inp(): return int(sys.stdin.readline())

def inpl(): return list(map(int, sys.stdin.readline().split()))

def inpl_str(): return list(sys.stdin.readline().split())

def inpl_strl(): return list(sys.stdin.readline())

n = inp()
s = inpl()
b = 1
if s.count(1) == 0:
    print(-1)
else:
    for i in range(n):
        if s[i] == b:
            b += 1
    print(n-(b-1))

Measured memory_bytes: 26984
///#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
///#pragma GCC target("sse,sse2,sse3,ssse3,sse4,abm,mmx,popcnt,avx,avx2,tune=native")

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

/*
    zet:
        find_by_order(k): k-stat [k > 0]
        order_of_key(k) : {el < k}

    gp_hash_table<key, val, custom_hash>

    rope<T>:
        iterators: mutable_begin, ..
        methods  : erase, insert, substr, ..
*/

#define all(x) (x).begin(), (x).end()
#define size(x) (int)((x).size())
#define em_back emplace_back

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<typename T>
using zet = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

mt19937 eng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 1e5 + 4;

int res, n, k, del[N], deg[N], h[N], p[N];
set<int> g[N];

set<pii> q;

void dfs(int u, int d = 0) {
    h[u] = d;
    if (size(g[u]) == 0) {
        q.emplace(d, u);
    }
    for (int to : g[u]) {
        dfs(to, d + 1);
    }
}

void cdfs(int u) {
    for (int to : g[u]) {
        cdfs(to);
    }
    if (size(g[u]) == 0) {
        q.erase(pii(h[u], u));
    } else {
        g[u].clear();
    }
}

void prepare() {
    dfs(1);
}

void solve() {
    cin >> n >> k;
    for (int i = 1; i <= n; ++i) {
        cin >> p[i];
        if (i == 1) {
            res += (p[i] != 1);
            p[i] = 1;
        } else {
            g[p[i]].emplace(i);
        }
    }

    prepare();

    while (size(q)) {
        int l = q.rbegin()->second;
        for (int i = 0; i < k - 1; ++i) {
            l = p[l];
            if (l == 1) {
                return;
            }
        }
        if (p[l] == 1) {
            return;
        }
        cdfs(l);
        g[p[l]].erase(l);
        if (size(g[p[l]]) == 0) {
            q.emplace(h[p[l]], p[l]);
        }
        ++res;
    }
}

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

    int z = 1;
    /// cin >> z;

    while (z--) {
        solve();
        cout << res << "\n";
    }

    return 0;
}



Measured memory_bytes: 19916
url = "https://atcoder.jp/contests/abc044/tasks/abc044_b"

def main():
    param = list(input())
    count_d = {}
    for p in param:
        count_d.setdefault(p, 0)
        count_d[p] += 1

    for v in count_d.values():
        if v % 2 != 0:
            print('No')
            exit(0)
    print('Yes')


if __name__ == '__main__':
    main()




Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <string>
#include <numeric>
#include <functional>
using namespace std;

int main()
{
	int N;
	cin >> N;
	vector<long long> a(3*N);
	long long res = 0;
	for (int i = 0;i < 3*N;i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end(),greater<long long>());
		for (int i = 1;i < 2*N;i+=2) {
			res += a[i];
		}
	cout << res << endl;
}

Measured memory_bytes: 2560
#include<stdio.h>
const int N = 10000;

int main()
{
	int a[N] = {0} , maxn = -1000000 , minn = 1000000 , n;
	long long sum = 0;
	scanf("%d" , &n);
	for(int i = 0 ; i < n ; i++)
	{
		scanf("%d" , &a[i]);
		if(a[i] > maxn)
		{
			maxn = a[i];
		}
		if(a[i] < minn)
		{
			minn = a[i];
		}
		sum += a[i];
	}
	printf("%d %d %ld\n" , minn , maxn , sum);
	
	return 0;
} 


Measured memory_bytes: 2756
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define ld long double
#define mod 1000000007LL
#define eps 1e-13
// #define PI 3.141592653589793238L
#define INF 1000000011
#define INFLL 1000000000000000011LL
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define mp make_pair
#define F first
#define S second
#define pb push_back
#define fo(i,a,n) for(i = (a); i < (n); i++)
#define gtl(x) getline(cin, (x))
#define flsh fflush(stdout)
#define sws ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define gcd __gcd
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)((a).size())
#define io_file freopen("D:/Coding Problems/Contest/input_file.in", "r", stdin); freopen("D:/Coding Problems/Contest/output_file.out", "w", stdout)

ll modx(ll Base, ll exponent)
{
	ll ans = 1;
	if(Base == 1)
		return Base;
	while(exponent)
	{
		if(exponent & 1)
			ans = (ans * Base)%mod;
		Base = (Base * Base)%mod;
		exponent = exponent >> 1;
	}
	return ans;
}

ll inmodx(ll num)
{
	return (modx(num, mod-2LL));
}

bool cmp(pii a, pii b)//true for a before b
{
	if(a.S < b.S)
		return 1;
	if(a.S > b.S)
		return 0;
	if(a.F <= b.F)
		return 1;
	return 0;
}

const int N = (2e2) + 9;
const int M = (672*672) + 9;
const int LOGN = ((int)log2(N)) + 3;
const int LOGM = ((int)log2(M)) + 3;
const int BUCK = 900;

inline ll func(ll l, ll r, ll x)
{
	return ((r/x) - ((l+x-1LL)/x) + 1LL);
}

void solve()
{
	ll a, b, c, d, ans = 0, g, l;
	cin >> a >> b >> c >> d;
	g = gcd(c,d);
	l = c*(d/g);
	ans = func(a,b,c) + func(a,b,d) - func(a,b,l);
	ans = (b-a+1LL) - ans;
	cout << ans << '\n';
	return;
}

int main()
{
	sws;
	clock_t clk;
	clk = clock();
	// io_file;
	// srand(clock());

	//Code here
	int t = 1, cs;
	cout << fixed << setprecision(15);
	// cin >> t;
	fo(cs,1,t+1)
	{
		// cout << "Case #" << cs << ": ";
		solve();
	}
	// Code ends here

	clk = clock() - clk;
	cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
	return 0;
}

Measured memory_bytes: 256
//url:
//problem name:

#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
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;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    int r,D,x; cin >> r >> D >> x;
    REP(i,10) {
        cout << r * x - D << endl;
        x = r * x - D;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
 
#define  rep(i, n) for(int i = 0; i < (int)(n);    i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i>=0; i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;

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


int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  std::string S; std::cin >> S;

  int ans = 0;
  for(int i=1; (2*i)<sz(S); i++) {
    auto base = S.substr(0,i);
    if ( S.substr(0,2*i) == base+base ) ans = sz(base)*2;
  }
  std::cout << ans << std::endl;
  return 0;
}


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

int main(){
	int n;
	bool if_p[10000];
	for(int i=0; i<10000; i++)
		if_p[i] = true;
	if_p[0] = false; if_p[1] = true;
	for(int lim = 1; lim < 10000; lim = lim * (lim + 2)){
		for(int iter = 0; iter <= lim; iter++){
			if(if_p[iter])
				for(int i = 2; i * (iter + 1) <= 10000; i++)
					if_p[i*(iter+1)-1] = false;
		}
	}
	std::cin >> n;
	int count = 0;
	for(;n--;){
		int input;
		std::cin >> input;
		bool b = true;;
		for(int i = 0; i <= sqrt(input) - 1; i++){
			if(if_p[i] && !(input % (i + 1))){
				b = false;
				break;
			}
		}
		if(b)
			count++;
	}
	std::cout << count << std::endl;
	return 0;
}

Measured memory_bytes: 1168
#include <iostream>
#include <cstdlib>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long INF = 1LL << 60;

int N;
long long h[100010];

// DP テーブル
long long dp[100010];

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

    for (int i = 0; i < N; ++i) cin >> h[i];

    // 初期化 (最小化問題なので INF に初期化)
    for (int i = 0; i < 100010; ++i) dp[i] = INF;

    // 初期条件
    dp[0] = 0;

    for(int i = 0; i < N; i++){
        for(int j = 0; j <= K; j++){
            chmin(dp[i + j], dp[i]+ abs(h[i] - h[i + j]));
        }
    }

    // 答え
    cout << dp[N-1] << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end()) // ちゃんとユニークな配列にする。連続した値を除去して切り出す。
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

int main() {
  int N;
  cin >> N;
  set<int> D;
  rep(i, N) {
    int di;
    cin >> di;
    D.insert(di);
  }
  cout << D.size() << endl;
}


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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define fi first
#define se second
#define setpre(x) cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , ";
    logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 200005;

/* ...o(^-^)o... */

map<lint, lint> prime_factorization(lint x){
    map<lint, lint> fac;
    for(lint k = 2; k*k <= x; k++){
        while(x % k == 0){
            fac[k]++;
            x /= k;
        }
    }
    if(x != 1) fac[x]++;
    return fac;
}

int main(){
    lint n; cin >> n;
    lint ans = 1;
    
    auto pf = prime_factorization(n-1);
    for(auto p : pf){
        ans *= (lint)(p.se + 1);
    }
    ans--;

    vector<lint> yks;
    for(lint x = 1; x*x <= n; x++){
        if(n % x == 0){
            yks.push_back(x);
            if(x*x != n) yks.push_back(n / x);
        }
    }

    for(lint x : yks){
        if(x == 1) continue;
        lint m = n;
        while(m % x == 0){
            m /= x;
        }
        if(m % x == 1){
            ans++;
        }
    }

    out(ans);
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  string s;
  cin >> s;
  int pw = 0;
  ll cnt = 0;
  for(int i=0;i<s.size();i++){
    if(s[i] == 'W'){
      cnt += i-pw++;
    }
  }
  cout << cnt << endl;
}

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

using namespace std;

int main()
{
    vector<int> v, dist;
    int n;
    cin>>n;
    v.resize(n + 1);
    dist.resize(n + 1);

    for(int i = 1 ; i <= n ; i++){
        cin>>v[i];
    }

    dist[1] = 0;
    dist[2] = abs(v[2] - v[1]);

    for(int i = 3 ; i <= n ; i++){
        dist[i] = min(dist[i - 1] + abs(v[i] - v[i - 1]), dist[i - 2] + abs(v[i] - v[i - 2]));
    }
    cout<<dist[n];

    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h> 
using namespace std; 
#define ll long long
#define MOD 1000000007

const ll inf = 1e18L + 5;

void max_self(int& a, int b ){
    a = max(a, b);
}

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

    string s, t;
    cin>>s>>t;
    t.pop_back();

    if( s == t )
        cout<<"Yes";
    else 
        cout<<"No";
    return 0;
}

Measured memory_bytes: 3596
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

//

fn gcd(a: u64, b: u64) -> u64 {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}

fn run() {
    input! {
        a: u64,
        b: u64,
        c: u64,
        d: u64,
    }
    let calc = |a: u64| -> u64 {
        let x = c * d / gcd(c, d);
        a / c + a / d - a / x
    };
    let ans = (b - a + 1) - (calc(b) - calc(a - 1));
    println!("{}", ans);
}

fn main() {
    run();
}


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



int main() {
    int r;
    cin >> r;
    
    cout << r * r << endl;
    
    
    return 0;
}


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

int main() {
  char c;
  cin >> c;

  if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
    cout << "vowel" << endl;
  }
  else {
    cout << "consonant" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,d;
int main()
{
	cin>>n>>d;
	int i,x,y,tt=0;
	for(i=1;i<=n;++i)
	{
		cin>>x>>y;
		double s=sqrt(1ll*x*x+1ll*y*y);
		if(s<=d)
			tt++;
	}
	cout<<tt;
	return 0;
}

Measured memory_bytes: 3652
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<unordered_map>
#include<set>
#include<cstring>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;

using namespace std;
typedef long long ll;
const ll INF = 1e9 + 6;
const ll MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define Pint pair<int, int>
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
/* -- template -- */
int cnt[35]; //各桁に出現する1の数
vector<bool> K_b;
void toBinary(ll x) {
    while(x > 0) {
        if(x % 2) K_b.pb(1);
        else K_b.pb(0);
        x /= 2;
    }
    reverse(all(K_b));
}
int main() {
    ll N, K; cin >> N >> K;
    ll A[N]; rep(i, N) cin >> A[i];
    rep(i, N) {
        int j = 0;
        ll tmp = A[i];
        while(tmp > 0) {
            if(tmp % 2 == 1) cnt[j]++;
            ++j;
            tmp /= 2;
        }
    }
    ll ans = 0;
    toBinary(K);
    ll pow2 = pow(2, K_b.size() - 1);
    bool smaller = false;
    for(int i = 0; i < K_b.size(); ++i) {
        if(!smaller) {
            if(K_b[i]) {
                if((N - cnt[K_b.size() - 1 - i] > N / 2)) {
                    ans += pow2;
                }else {
                    smaller = true;
                }
            }
        }else {
            if((N - cnt[K_b.size() - 1 - i] > N / 2)) {
                ans += pow2;
            }
        }
        pow2 /= 2;
    }

    ll res = 0;
    rep(i, N) {
        res += ans ^ A[i];
    }
    cout << res << endl;
}


Measured memory_bytes: 1024
import java.util.Scanner

object Main{
  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)

    val Array(totalH, totalW) = sc.nextLine.split(" ").map(_.toInt)
    val Array(h, w) = sc.nextLine.split(" ").map(_.toInt)
    val totalTiles: Int = totalH * totalW
    println(totalTiles - (h * totalW + w * totalH - h * w))
  }
}

Measured memory_bytes: 25924
#include<bits/stdc++.h>
using namespace std;
int N,A,B,sum=0,ans=0;

int main(){
  cin >> N >> A >> B;
  for(int i=1;i<=N;i++){
    sum=0;
    string s=to_string(i);
    for(int j=0;j<s.size();j++){
      sum+=s[j]-'0';
    }
    if(sum>=A && sum <=B) ans+=i;
  }
  cout << ans << endl;
  return 0;
}


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

//#define int long long
#define DEBUG 0
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) if(DEBUG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DEBUG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
using ll = long long; using ull = unsigned long long; using pii = pair<int, int>;
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
static const int MOD = 1e9 + 7;

signed main() {
	int n, m; cin >> n >> m;
	int ans = m;
	rep(i, 0, n) {
		int a, b; cin >> a >> b;
		m = m + a - b;
		if (m < 0) {
			cout << 0 << endl;
			return 0;
		}
		ans = max(ans, m);
	}
	cout << ans << endl;
	return 0;
}

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

vector<double> num;
int n;
int k;
double dp[3001][3001];

int main () {
    cin >> n;
    k = n/2;

    for(int i=0; i<n; i++){
        double x;
        cin>>x;
        num.push_back(x);
    }

    double sum = 0;
    memset(dp, 0, sizeof(dp));
    
    dp[1][0] = 1.0 - num[0];
    for(int i=2; i<=n; i++){
        dp[i][0] = dp[i-1][0]*(1.0-num[i-1]);
    }
    
    dp[1][1] = num[0];

    for(int i=2; i<=n; i++){
        dp[i][i] = dp[i-1][i-1]*num[i-1];
    }

    for(int i=1; i<=n; i++){
        for(int j=1; j<i; j++){
                dp[i][j] += dp[i-1][j-1]*num[i-1];
                dp[i][j] += dp[i-1][j]*(1.0-num[i-1]);
        }
    }

    for(int i=k+1; i<=n; i++){
        sum += dp[n][i];
    }

    // solve(1, 1, num[0], sum);
    // solve(1, 0, 1-num[0], sum); 
    cout<<fixed<<setprecision(10)<<sum<<endl;

    return 0;
}

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


int main() {
  int A,B,sum=0;
  cin>>A>>B;
  int a=A,b=B;
  int s[5];
  rep(i,b-a+1){
    int t=A;
    rep(i,5){
      s[i]=t%10;
      t/=10;
    }
    if(s[0]==s[4]&&s[1]==s[3]){
      sum++;
    }
    A++;
  }
  cout << sum << endl; 
}

Measured memory_bytes: 256
import java.io.*
import java.util.*

fun solve(N: Int, S: String) {
    val westSum = S.map { if (it == 'W') 1 else 0 }.scanLeft(0) { a, b -> a + b }.toList()
    val eastSum = S.map { if (it == 'E') 1 else 0 }.scanLeft(0) { a, b -> a + b }.toList()
    val ans = (0 until N)
        .map { westSum.getOrElse(it - 1) { 0 } + eastSum[N - 1] - eastSum.getOrElse(it) { 0 } }
        .min()
    println(ans)
    return
}

fun <T, R> Iterable<T>.scanLeft(initial: R, operation: (acc: R, T) -> R): Sequence<R> {
    var last = initial
    return this.asSequence().map { last = operation(last, it); last }
}

fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toInt()
    val S = sc.next()
    solve(N, S)
}


Measured memory_bytes: 79784
let () = Scanf.scanf "%d %d" @@ fun m d ->
  Printf.printf "%d\n" @@
  Array.fold_left (Array.fold_left ( + )) 0 @@
  Array.init m @@ fun i ->
    Array.init d @@ fun j ->
      if
        2 <= (j + 1) mod 10 &&
        2 <= (j + 1) / 10 &&
        ((j + 1) mod 10) * ((j + 1) / 10) = i + 1
      then 1
      else 0

Measured memory_bytes: 2432
import sys

blood = [0,0,0,0]
for line in sys.stdin:
    b = line.split(',')[1].rstrip()
    if b == 'A':
        blood[0] = blood[0] + 1
    elif b == 'B':
        blood[1] = blood[1] + 1
    elif b == 'AB':
        blood[2] = blood[2] + 1
    elif b == 'O':
        blood[3] = blood[3] + 1
else:
    for num in blood:
        print num

Measured memory_bytes: 4208
#include <stdio.h>

int main(void)
{

   char b;

   scanf("%s",&b);

   if (b=='A'){
         printf("T");
      }
   else if (b=='T'){
         printf("A");
         }
   else if (b=='C'){
         printf("G");
         }
   else if (b=='G'){
         printf("C");
         }

   return 0;
}                       

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
using namespace std;
int a[61],f[61][61][201][2];
int main ()
{
	int n,m,i,j,k;
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;++i) scanf("%d",&a[i]);
	for(k=1;k<=m;++k)
	  for(i=1;i<=n;++i)
	    for(j=i;j<=n;++j)
	    {
	    	if(k!=1)
	    	{
	    		f[i][j][k][0]=max(f[i+1][j][k-2][0],f[i+1][j][k-2][1]);
	    		f[i][j][k][1]=max(f[i][j-1][k-2][0],f[i][j-1][k-2][1]);
			}
			f[i][j][k][0]=max(f[i][j][k][0],f[i+1][j][k-1][0]+a[i]);
			f[i][j][k][0]=max(f[i][j][k][0],f[i+1][j][k-1][1]+a[i]);
			f[i][j][k][1]=max(f[i][j][k][1],f[i][j-1][k-1][0]+a[j]);
			f[i][j][k][1]=max(f[i][j][k][1],f[i][j-1][k-1][1]+a[j]);
		}
	printf("%d",max(f[1][n][m][0],f[1][n][m][1]));
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int SOD(int n){
	int sum = 0;
	while(n > 0){
		sum += n % 10;
		n /= 10;
	}
	return sum;
}

int main(){
	int n;
	cin >> n;
	if(n % SOD(n) == 0) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    import heapq

    N = int(input())
    edges = [[] for _ in range(N+1)]
    for _ in range(N-1):
        u,v,w = map(int,input().split())
        edges[u].append((v,w))
        edges[v].append((u,w))
    
    colors = [-1]*(N+1)
    que = [(0,1)]
    heapq.heapify(que)
    while que:
        c,n = heapq.heappop(que)
        if colors[n] == -1:
            colors[n] = c
            for nx,w in edges[n]:
                if w%2==0:
                    nxC = c
                else:
                    nxC = (c+1)%2
                heapq.heappush(que,(nxC,nx))

    for i in range(1,N+1):
        print(colors[i])

main()

Measured memory_bytes: 87216
n, m = gets.split.map(&:to_i)

ca = Array.new(n, 0)
penalty = Array.new(n, 0)
buf_penalty = Array.new(n, 0)

m.times do
  num, result = gets.split
  num = num.to_i
  if result == 'AC'
    if ca[num-1] == 0
      ca[num-1] += 1
      penalty[num-1] = buf_penalty[num-1]
    end
  else
    buf_penalty[num-1] += 1
  end
end

puts "#{ca.inject(:+)} #{penalty.inject(:+)}"

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

using namespace std;

#define range(i, m, n) for(int i = m; i < n; i++)
#define husk(i, m, n) for(int i = m; i > n; i--)

template <typename T, class F = function<T(const T&, const T&)>>
class SparseTable {
 public:
  int n;
  vector<vector<T>> mat;
  F func;

  SparseTable(const vector<T>& a, const F& f) : func(f) {
    n = static_cast<int>(a.size());
    int max_log = 32 - __builtin_clz(n);
    mat.resize(max_log);
    mat[0] = a;
    for (int j = 1; j < max_log; j++) {
      mat[j].resize(n - (1 << j) + 1);
      for (int i = 0; i <= n - (1 << j); i++) {
        mat[j][i] = func(mat[j - 1][i], mat[j - 1][i + (1 << (j - 1))]);
      }
    }
  }

  T get(int from, int to) const {
    assert(0 <= from && from <= to && to <= n - 1);
    int lg = 32 - __builtin_clz(to - from + 1) - 1;
    return func(mat[lg][from], mat[lg][to - (1 << lg) + 1]);
  }
};

int n, k;

int main() {
  cin >> n >> k;
  vector<int> p(n);
  range(i, 0, n) scanf("%d", &p[i]);
  SparseTable<int> st(p, [&](int x, int y){ return max(x ,y); });
  SparseTable<int> sp(p, [&](int x, int y){ return min(x, y); });
  vector<int> to(n);
  husk(i, n - 1, -1) {
    if(i < n - 1 && p[i] < p[i + 1]) to[i] = to[i + 1];
    else to[i] = i;
  }
  int res = 0;
  range(i, 0, n) if(to[i] >= i + k - 1) res = 1;
 /* vector<int> pos;
  range(i, 0, n - k) if(to[i] < i + k - 1) pos.push_back(i);
  while(pos.size()) {
    res++;
    int u = pos.back();
    pos.pop_back();
    while(pos.size()) {
      int v = pos.back();
      if(v + k - 1 < u) break;
      int mx = st.get(u, v + k - 1);
      int mn = sp.get(u, v + k - 1);
      if(to[v + k] >= u + k - 1 && to[v] >= u - 1 && p[v + k] > mx && p[u - 1] < mn) {
        pos.pop_back();
      } else break;
    }
  }*/
  range(i, 0, n - k + 1) {
    if(to[i] >= i + k - 1) continue;
    if(i && p[i - 1] == sp.get(i - 1, i + k - 2) && p[i + k - 1] == st.get(i, i + k - 1)) continue;
    res++;
  }
  cout << res;
  return 0;
}


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

int main(){
  string S0, S1;
  cin >> S0;
  long long int N = S0.size();
  bool f1, f2;
  f1 = f2 = false;
  
  S1 = S0;
  reverse(S1.begin(), S1.end());
  if(S0 == S1) f1 = true;
  
  if(S0.substr(0, (N - 1) / 2) == S1.substr((N + 3) / 2 - 1)) f2 = true;
  
  if(f1 && f2) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
signed main(){
  ll a,b,c,d,lc,ans;
  cin >> a >> b >> c >> d;
  lc = c/gcd(c,d)*d;
  ans = (b/c)-(a/c) + (b/d)-(a/d);
  if(a%c==0) ans++;
  if(a%d==0) ans++;
  ans -= (b/lc)-(a/lc);
  if(a%lc==0) ans--;
  ans = b-a+1-ans;
  cout << ans << endl;
}


Measured memory_bytes: 256
n = int(input())
s = input()

r_count = s.count('R')
g_count = s.count('G')
b_count = s.count('B')

discount = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        k = i + 2*(j-i)
        if k > n-1:
            break
        if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
            discount += 1

print(r_count*g_count*b_count-discount)

Measured memory_bytes: 9212
#include <iostream>

using namespace std;

int main(){
  int ans = 0, mx = 0;
  string s; cin >> s;
  for (int i = 0; i < 3; i++){
    if (s[i] == 'R') ans++;
    else ans = 0;
    mx = max(mx, ans);
  }
  cout << mx << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
typedef long long int ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
const ll LINF = 9000000000000000000ll;
const int INF = 2000000000;
const ll MOD = 1e9+7;

int main() {
    int n, m;
    cin >> n >> m;
    vint y(m), p(m);
    map<int, int> mp;
    map<int, string> mp2;
    vint data(n, 0);
    rep(i, m) {
        cin >> p[i] >> y[i];
        mp[y[i]] = p[i];
    }
    string id, pi, xi;
    for (auto x: mp) {
        data[x.se - 1]++;
        pi = to_string(x.se);
        while(pi.length() < 6) pi = "0" + pi;
        xi = to_string(data[x.se - 1]);
        while(xi.length() < 6) xi = "0" + xi;
        mp2[x.fi] = pi + xi;
    }
    rep(i, m) {
        cout << mp2[y[i]] << endl;
    }
    return 0;
}

Measured memory_bytes: 19584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ll l,r;
  cin >> l >> r;
  r=min(r,l+4038);
  int ans=2018;
  for(ll i=l;i<r+1;++i) {
    for(ll j=i+1;j<r+1;++j) {
      int x=i*j%2019;
      ans=min(ans,x);
    }
  }
  cout << ans << endl;
  return 0;
}
      

Measured memory_bytes: 256
x, y = map(int, input().split())
a = [1, 3, 5, 7, 8, 10, 12]
b = [4, 6, 9, 11]
c = [2]

for g in (a, b, c):
  if x in g and y in g:
    print('Yes')
    exit()
print('No')

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

void myupdate_tree(vector<long long int>& mytree, int index, int l, int r, int target_l, int target_r, long long int val) {
    if (r < target_l || target_r < l) return;
    if (l == r && l >= target_l && r <= target_r) {
        mytree[index] = min(val, mytree[index]);
        return;
    }
    if (l >= target_l && r <= target_r) {
        mytree[index] = min(val, mytree[index]);
        return;
    }

    int m = (l + r) / 2;
    myupdate_tree(mytree, index * 2 + 1, l, m, target_l, target_r, val);
    myupdate_tree(mytree, index * 2 + 2, m + 1, r, target_l, target_r, val);
    // mytree[index] = min(val, min(mytree[index * 2 + 1], mytree[index * 2 + 2]));   
}

long long int myquery_tree(vector<long long int>& mytree, int index, int l, int r, int target_l, int target_r) {
    if (r < target_l || l > target_r) return 0x3f3f3f3f;
    if (l >= target_l && r <= target_r) return mytree[index];

    int m = (l + r) / 2;
    long long int res = min(myquery_tree(mytree, index * 2 + 1, l, m, target_l, target_r), myquery_tree(mytree, index * 2 + 2, m + 1, r, target_l, target_r));    
    res = min(res, mytree[index]);
    return res;
}

int main() {
    int n, q;
    cin >> n >> q;
    long long int nn = n - 2;
    long long int res = nn * nn;
    
    vector<long long int> v1(4 * nn, nn), v2(4 * nn, nn);
    for (int i = 0; i < q; i++) {
        int t, x;
        cin >> t >> x;
        x -= 2;
        int index = 0;
        if (t == 1) {
            index = myquery_tree(v1, 0, 0, nn - 1, x, x);

            res -= index;
            if (index > 0) {
                myupdate_tree(v2, 0, 0, nn - 1, 0, index - 1, x);
            }
            
        } else {
            index = myquery_tree(v2, 0, 0, nn - 1, x, x);

            res -= index;
            if (index > 0) {
                myupdate_tree(v1, 0, 0, nn - 1, 0, index - 1, x);
            }
        }
    }
    cout << res << endl;
}






Measured memory_bytes: 15572