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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

    string s; cin >> s;
    int n = s.length();
    reverse(s.begin(), s.end());

    vector<int> dp(n + 1);
    dp[1] = 1;
    for (int i = 1; i < n; i++) dp[i + 1] = (dp[i] * 10) % 2019;
    for (int i = 0; i < n; i++) {
        (dp[i + 1] *= (s[i] - '0')) %= 2019;
        (dp[i + 1] += dp[i]) %= 2019;
    }
    // for (auto &e: dp) cout << e << ' ';
    // cout << '\n';
    vector<int> cnt(2019);
    for (int i = 0; i <= n; i++) cnt[dp[i]]++;

    ll ans = 0;
    for (auto &e: cnt) ans += (ll)e * (e - 1) / 2;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4420
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vs = vector<string>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string s;
    cin >> s;
    for (char c = 'a'; c <= 'z'; ++c) {
        if (s.find(c) == string::npos) {
            cout << c << endl;
            return 0;
        }
    }
    cout << "None" << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <utility>
using namespace std;
using ll = long long int;

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

	vector<int> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
if(A[0]!=0){cout << -1;return 0;}
	ll ans = A[N-1];
	int now = A[N-1];
	for (int i = N - 1; i >= 0; i--) {
		if (A[i] > now) {
			ans += A[i];
			now = A[i];
		}
		if (A[i] < now) {
			cout << -1;
			return 0;
		}
		now--;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back

signed main(){
    int n;
    cin>>n;

    vector<string> t(n+1);
    rep(i,n+1)cin>>t[i];

    vector<vector<int>> vv(n+1);
    rep(i,n+1){
        string tmp="";
        rep(j,t[i].size()){
            if( not isdigit(t[i][j]) ){
                if(tmp.size())vv[i].pb(stoi(tmp));
                   tmp="";
                vv[i].pb(10000000000ll+(int)(t[i][j]));
            }
            else{
                tmp+=t[i][j];
            }
        }
        if(tmp.size())vv[i].pb(stoi(tmp));
    }
    for(int i=1;i<=n;i++){
        // rep(j,vv[i].size())cout<<vv[i][j]<<" ";cout<<endl;

       if( vv[0]>vv[i] ){
           cout<<'-'<<endl;
       }else{
           cout<<'+'<<endl;
       }
    }


}



Measured memory_bytes: 3344
usrInput = input()
divisor = []
flag = []
finalFlag = False

for kuku in range(9):
    currentDivisor = kuku+1
    if int(usrInput) % currentDivisor == 0:
        divisor.append(currentDivisor)

for x in range(len(divisor)):
    anotherDivisor = int(usrInput) / divisor[x]
    if float.is_integer(anotherDivisor) == True and anotherDivisor <= 9 and anotherDivisor > 0 and int(divisor[x]) > 0:
        flag.append(True)
    else:
        flag.append(False)

for n in range(len(divisor)):
    if bool(flag[n]) == True:
        finalFlag = True

if finalFlag == True:
    print("Yes")
else:
    print("No")

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> v(n);
  for(int i = 0; i < n; i++) {
    int p;
    cin >> p;
    v.at(i) = p;
  }
  sort(v.begin(), v.end());
  int sum = 0;
  for(int i = 0; i < k; i++) {
    sum += v.at(i);
  }
  cout << sum << endl;
}

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

int main(){
    ll a, b;
    cin >> a >> b;
    rep(i, 1e9){
        if(abs(a-i) == abs(b-i)){
            cout << i << endl;
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
int N,M;
  
cin >> N;
vector<string> s(N);
for(int i = 0; i < N; i++){
    cin >> s[i];}
  
cin >> M;
vector<string> t(M);
for(int i = 0; i < M; i++){
    cin >> t[i];}
 
int coin = 0;
for(int i = 0; i < N; i++){
    int c = 0;
    for(int j = 0; j < N; j++){
        if(s[i] == s[j]){c++;}
    }
    for(int j = 0; j < M; j++){
        if(s[i] == t[j]){c--;}
    }
coin = max(coin , c);
}
 
cout << coin << endl;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PI 4*atan(1.0)
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
using namespace std;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
const int SIZE=100050;
//int arr[SIZE]={};
//ここまでテンプレ
int main(){
	char S[7];
	cin>>S;
	int ans=0;
	for(int i=0;i<6;i++){
		if(S[i]=='1')
			ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
// OBツ嘉ッツ嘉債宿2011 Day3 I : White Bird

#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

const double EPS = 1e-8;

double calc(double X, double Y, double V, double vy){
	return 2*vy*sqrt(V*V-vy*vy)*X-9.8*X*X-2*Y*(V*V-vy*vy);
}

void getVy(vector<double> &vd, double X, double Y, double V){
	double L = 0, R = V;
	for(int cnt=0;cnt<200;cnt++){
		double midA = (2*L+R)/3;
		double midB = (L+2*R)/3;
		if(calc(X, Y, V, midA) < calc(X, Y, V, midB)) L = midA;
		else                                          R = midB;
	}
	if(calc(X, Y, V, 0.5*(L+R)) < EPS) return ;
	double vl = 0, vr = 0.5*(L+R);
	for(int cnt=0;cnt<200;cnt++){
		double mid = 0.5*(vl+vr);
		if(calc(X, Y, V, mid) < 0) vl = mid;
		else                       vr = mid;
	}
	vd.push_back(0.5*(vl+vr));
	vl = 0.5*(L+R), vr = V;
	for(int cnt=0;cnt<200;cnt++){
		double mid = 0.5*(vl+vr);
		if(calc(X, Y, V, mid) > 0) vl = mid;
		else                       vr = mid;
	}
	vd.push_back(0.5*(vl+vr));
}

int main(){
	int N, V, X, Y;
	int L[50], B[50], R[50], T[50];
	while(cin >> N >> V >> X >> Y){
		vector<double> vd;
		getVy(vd, X, Y, V);
		int low = Y, high = 1000000007;
		for(int i=0;i<N;i++){
			cin >> L[i] >> B[i] >> R[i] >> T[i];
			L[i] = min(L[i], X);
			R[i] = min(R[i], X);
			getVy(vd, L[i], B[i], V);
			getVy(vd, R[i], B[i], V);
			getVy(vd, L[i], T[i], V);
			getVy(vd, R[i], T[i], V);
			if(L[i]<=X&&X<=R[i]&&B[i]>=high) high = min(high, B[i]);
		}
		bool clear = false;
		for(int i=0;i<vd.size();i++){
			double vx = sqrt(V*V-vd[i]*vd[i]);
			double vy = vd[i];
			bool ok = true;
			for(int j=0;j<N;j++){
				double my = vy*(L[j]/vx) - 4.9*(L[j]/vx)*(L[j]/vx);
				double My = vy*(R[j]/vx) - 4.9*(R[j]/vx)*(R[j]/vx);
				if(my > My) swap(my, My);
				if(L[j]+EPS < vx*vy/9.8 && vx*vy/9.8 < R[j]-EPS)
					My = vy*(vy/9.8) - 4.9*(vy/9.8)*(vy/9.8);
				if(min(My, (double)T[j]) - max(my, (double)B[j]) > EPS) ok = false;
			}
			if(!ok) continue;
			double y = vy*(X/vx) - 4.9*(X/vx)*(X/vx);
			if(low-EPS < y && y < high+EPS) clear = true;			
		}
		cout << (clear ? "Yes" : "No") << endl;
	}
}

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

vector<ll> ban(51);
vector<ll> paty(51);

long long dfs(ll n, ll x, ll sum){
  if(n == 0){
   	return sum+1; 
  }
  if(x == 1){
    return sum;
  }else if(1<x && x<ban[n]/2+1){
    return dfs(n-1, x-1, sum);
  }else if(x == ban[n]/2+1){
    return sum+paty[n-1]+1;
  }else if(ban[n]/2+1 < x && x < ban[n]){
    return dfs(n-1, x-(ban[n-1]+2), sum+paty[n-1]+1);
  }else if(x == ban[n]){
    return sum+paty[n];
  }
}

int main(){
  ll n, x;
  cin >> n >> x;
  ban[0] = 1;
  paty[0] = 1;
  for(ll i=1; i<=50; i++){
    ban[i] = ban[i-1]*2+3;
    paty[i] = paty[i-1]*2+1;
  }
  ll ans = dfs(n, x, 0);
  cout << ans << endl;
  return 0;
}
    
    

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
using namespace std;

int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  int mindata,maxdata;
  mindata=max(a,c);
  maxdata=min(b,d);
  if(maxdata>mindata) cout<<maxdata-mindata<<endl;
  else cout<<"0"<<endl;

}


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

int bubble(int n,int a[]) {
    int cnt=0;
    for(int i=0;i<n;i++) {
        for(int j=n-1;j>i;j--) {
            if(a[j]<a[j-1]) {
                swap(a[j],a[j-1]);
                cnt++;
            }
        }
    }
    return cnt;
}

int main() {
    int n;cin>>n;
    int a[100];
    for(int i=0;i<n;i++) {
        cin>>a[i];
    }
    int ans=0;
    ans=bubble(n,a);
    for(int i=0;i<n-1;i++) {
        cout<<a[i]<<" ";
    }
    cout<<a[n-1]<<endl;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3100
#include <iostream>
using namespace std;
int h[4][3][10] = {0}, b, f, r, v, n;
int i, j, k;
int main () {
    cin >> n;
    for (i = 1; i <= n; i++) {
        cin >> b >> f >> r >> v;
        h[b - 1][f - 1][r - 1] += v;
    }
    for (i = 0; i < 4; i++) {
        for (j = 0; j < 3; j++) {
            for (k = 0; k < 10; k++)
                cout << " " << h[i][j][k];
            cout << "\n";
        }
        if (i < 3)
            cout << "####################\n";
    }
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(){
  int N, M, X;
  cin >> N >> M >> X;
  vector<int>gate(M);
  int left = 0, right = 0;
  for(int i = 0; i < M; i++){
    cin >> gate.at(i);

  if(X > gate.at(i)){
    left += 1;
  }
  else{
    right += 1;
  }
  }
  cout << min(right, left) << endl;
}

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

int main() {
    int N, Q;
    cin >> N >> Q;
    
    string S;
    cin >> S;
    
    vector<int> l(Q), r(Q);
    for (int i=0; i<Q; i++) {
        cin >> l[i] >> r[i];
    }
    
    //与えられた文字列の中のACを見つけ印をつけておき、それが含まれるか調べるといけるな
    //累積和にしとくか
    vector<int> sum(N+1);
    for (int i=0; i<N-1; i++) {
        if (S[i] == 'A' && S[i+1] == 'C'){
            for (int j=i+1; j<N+1; j++) {
                sum[j]++;
            }
        }
    }
    
    for (int i=0; i<Q; i++) {
        int left = l[i] - 1, right = r[i] - 1;
        cout << sum[right] - sum[left] << endl;
    }

}

Measured memory_bytes: 2176
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;
#define mst(a,b) memset((a),(b),sizeof(a))
#define rush() int T;scanf("%d",&T);while(T--)

typedef long long ll;
const int maxn = 100005;
const int mod = 20090717;
const int INF = 0x3f3f3f;
const double eps = 1e-9;

int n,cnt;
int pre[maxn];
int head[maxn];
int Rank[maxn];

struct point
{
    int x,y,id;
}a[maxn];

struct node
{
    int u,v,next,val;
}e[maxn*2];

void add(int u,int v,int val)
{
    e[cnt].u=u;
    e[cnt].v=v;
    e[cnt].val=val;
    e[cnt].next=head[u];
    head[u]=cnt++;
}

bool cmpx(const point &a,const point &b)
{
    return a.x<b.x;
}

bool cmpy(const point &a,const point &b)
{
    return a.y<b.y;
}

bool cmp_val(const node &a,const node &b)
{
    return a.val<b.val;
}

int find(int x)
{
    int t,r=x;
    while(x!=pre[x])
    {
        x=pre[x];
    }
    while(r!=x)
    {
        t=pre[r];
        pre[r]=x;
        r=t;
    }
    return x;
}

void join(int a,int b)
{
    int A=find(a);
    int B=find(b);
    if(A==B) return ;
    if(Rank[A]<Rank[B])
    {
        pre[A]=B;
    }
    else
    {
        pre[B]=A;
        if(Rank[A]==Rank[B])
            Rank[A]++;
    }
}

int main()
{
    int x,y;
    while(~scanf("%d",&n))
    {
        cnt=0;
        mst(head,-1);
        mst(Rank,0);
        for(int i=1;i<=n;i++)
        {
            scanf("%d%d",&x,&y);
            pre[i]=i;
            a[i].x=x;
            a[i].y=y;
            a[i].id=i;
        }
        sort(a+1,a+1+n,cmpx);
        for(int i=1;i<n;i++)
        {
            add(a[i].id,a[i+1].id,a[i+1].x-a[i].x);
        }
        sort(a+1,a+1+n,cmpy);
        for(int i=1;i<n;i++)
        {
            add(a[i].id,a[i+1].id,a[i+1].y-a[i].y);
        }
        sort(e,e+cnt,cmp_val);
        ll ans=0;
        int num=0;
        for(int i=0;i<cnt;i++)
        {
            if(find(e[i].u)!=find(e[i].v))
            {
                join(e[i].u,e[i].v);
                num++;
                ans+=e[i].val;
            }
            if(num==n-1) break;
        }
        printf("%I64d\n",ans);
    }
    return 0;
}


Measured memory_bytes: 5632
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
using namespace std;

const ll MOD = 1e9 + 7;

int main(int argc, char const *argv[])
{
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    ll ans = 1;
    rep(i, n)
    {
        int aprev, bprev;
        if (i == 0)
        {
            aprev = 0;
        }
        else
        {
            aprev = a[i - 1];
        }
        if (i == n - 1)
        {
            bprev = 0;
        }
        else
        {
            bprev = b[i + 1];
        }
        //cerr << aprev << " " << bprev << endl;
        if (aprev == a[i] && bprev == b[i])
        {
            ans *= min({a[i], b[i]});
        }
        else if (aprev == a[i] && bprev != b[i])
        {
            ans *= (bprev <= a[i] ? 1 : 0);
        }
        else if (aprev != a[i] && bprev == b[i])
        {
            ans *= (aprev <= b[i] ? 1 : 0);
        }
        else if (aprev != a[i] && bprev != b[i])
        {
            ans *= (a[i] == b[i] ? 1 : 0);
        }
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<cstdlib>
#include<stack>
using namespace std;

int main(){
    stack<int> S;
    int a, b;
    string s;
    
    while( cin >> s ){
        if(s[0] == '+'){
            a = S.top();
            S.pop();
            b = S.top();
            S.pop();
            S.push(a + b);
        }
        else if(s[0] == '-'){
            a = S.top();
            S.pop();
            b = S.top();
            S.pop();
            S.push(b - a);
        }
        else if(s[0] == '*'){
            a = S.top();
            S.pop();
            b = S.top();
            S.pop();
            S.push(a * b);
        }
        else{
            S.push(atoi(s.c_str()));
        }
    }
    
    cout << S.top() << endl;
    
    return 0;
}


Measured memory_bytes: 3172
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include <ios> 
#include <iomanip>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
#define INF 1e7

typedef long long ll;
typedef long long int lli;

int main() {
	int A, B;
	cin >> A >> B;
    cout << max({(A+B), (A-B), (A*B)}) << endl;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

const ll INF=1e15;
struct Sieve{
    int n;
    vector<int> f, primes;
    //コンストラクタを定義
    Sieve(int n=1):n(n), f(n+1){//メンバ変数の初期化
        f[0]=f[1]=-1;
        for(ll i=2;i<=n;i++){
            if(f[i]) continue;
            primes.push_back(i);
            f[i]=i;
            for(ll j=i*i;j<=n;j+=i){
                if(!f[j]) f[j]=i;
            }
        }
    }
    bool isPrime(int x) { return f[x]==x;} //xが素数かどうかを判定
    vector<int> factorList(int x){//xの素因数を重複ありで小さい順に列挙
        vector<int> res;
        while(x!=1){
            res.push_back(f[x]);
            x/=f[x];
        }
        return res;
    }
    vector<pair<int,int>> factor(int x){//xの素因数と、その出現回数
        vector<int> fl=factorList(x);
        if(fl.size()==0) return {};
        vector<pair<int,int>> res(1,pair<int,int>(fl[0],0));
        for(int p : fl){
            if(res.back().first==p){
                res.back().second++;
            }else{
                res.emplace_back(p,1);
            }
        }
        return res;
    }
};

int main(){
    ios;
    ll n;
    cin >> n;
    Sieve sieve(1000000);
    ll ans=0;
    for(ll c=1;c<=n-1;c++){
        vector<pii> res=sieve.factor(n-c);
        ll cnt=1;
        for(auto [x,y]:res){
            cnt*=(y+1);
        }
        ans+=cnt;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 7760
n = int(input())

def make_divisors(n):
    x = 0
    i = 1
    while i*i <= n:
        if n % i == 0:
            x += 1
            if i != n // i:
                x += 1
        i += 1
    return x

s = 0

for i in range(1, n+1, 2):
    #print(make_divisors(i))
    if make_divisors(i) == 8:
        s += 1

print(s)

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

bool num(char x){
  int code = x - '0';
  if(code>=0 && code<=9){
    return true;
  }else{
    return false;
  }
}
int main(){
  int A,B;
  cin >> A >> B;
  string S;
  cin >> S;
  bool okay = true;
  //条件１　A+1文字目がハイフン
  if(S.at(A)!='-'){
    okay = false;
  }
  //条件２　その他が全て数字
  int N = S.size();
  for(int i=0;i<N;i++){
    if(i!=A){
      if(num(S.at(i))){
      }else{
        okay = false;
      }
    }
  }
  if(okay){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
def main():
    from functools import lru_cache
    from sys import setrecursionlimit
    setrecursionlimit(10**6)
    N = int(input())
    withdraws = []
    for i in range(N):
        if N < 9**i:
            break
        withdraws.append(9**i)
    for i in range(1, N):
        if N < 6**i:
            break
        withdraws.append(6**i)
    withdraws.sort(reverse=True)

    @lru_cache(maxsize=100000)
    def rec(cur):
        if cur == 0:
            return 0
        ret = cur
        for draw in withdraws:
            if cur < draw:
                continue
            ret = min(ret, rec(cur - draw) + 1)
        return ret

    print(rec(N))


if __name__ == '__main__':
    main()


Measured memory_bytes: 96088
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;

// Lib
//

int main(){
#ifdef MYLOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    int N; cin >> N;
    vector<ll> L(N * 2);

    for (int i = 0; i < N * 2; ++i){
        cin >> L[i];
    }

    sort(L.begin(), L.end());
    ll ans = 0;

    for (int i = 0; i < N * 2; i += 2){
        ans += L[i];
    }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll= long long ;
using P = pair<ll,ll>;
#define rep(i,n) for (ll i = 0; i<(ll)(n); i++)
#define mod 1000000007
#define pi 3.141592653589793
typedef vector<ll> vcl;

ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a, ll b){
    ll g=gcd(a,b);
    return a/g*b;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t =rep_jijo(n,x/2);
        return t*t%mod;
  }
  return n*rep_jijo(n,x-1)%mod;
}
ll c2(ll n){
    return n*(n-1)/2;
}

int main(){
    ll n;
    cin>>n;
    vcl a(n);
    ll sum=0;
    rep(i,n)cin>>a[i];

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

Measured memory_bytes: 4844
#include "bits/stdc++.h"
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define all(V) (V).begin(), (V).end() 
#define x first
#define y second

using namespace std;

typedef long long ll;
template <typename T> using V = vector <T>;

int main() {fio;
	int n;
	cin >> n;
	V <int> a(n), b(n), c(n), dp0(n), dp1(n), dp2(n);
	for(int i = 0; i < n; i++) {
		cin >> a[i] >> b[i] >> c[i];
	}
	dp0[0] = a[0], dp1[0] = b[0], dp2[0] = c[0];
	for(int i = 1; i < n; i++) {
		dp0[i] = max(dp1[i - 1], dp2[i - 1]) + a[i];
		dp1[i] = max(dp2[i - 1], dp0[i - 1]) + b[i];
		dp2[i] = max(dp1[i - 1], dp0[i - 1]) + c[i];
	}
	cout << max({dp0[n - 1], dp1[n - 1], dp2[n - 1]});
    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Graph= vector<vector<ll>>;
struct edge{ll to ; ll cost ;} ;
using graph =vector<vector<edge>> ;
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
#define fi first
#define se second 
#define set20 cout<<fixed<<setprecision(20) ;
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
double pi=acos(-1) ;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
 
 

 int main(){
  ll n ; cin>> n ;
  vector<ll> A(n) ;
  rep(i,n) cin>>A[i] ;
  bool flag=1 ;
  ll sum =0 ;
  rep(i,n) sum+= A[i] ;
  ll base = n*(n+1)/2 ;
  if((sum%base)!=0) flag=0 ;
  ll kai = sum/base ;
  ll u=0 ;
 
  rep(i,n){
    ll now=0 ;
   if(i==n-1) now = A[0]-A[n-1] ;
   else now= A[i+1]-A[i] ;
   ll kk = (kai-now)/(n) ;
   if( !((  (kai-now)%(n) ==0   ) && (0<=kk )&&(kk<=kai))) flag=0 ;
  
  u+= kk ;
  }

  if(u!=kai) flag=0 ;
  if(flag) cout<<"YES"<<endl ;
  else cout<<"NO"<<endl ;
  return 0 ;
}




Measured memory_bytes: 4020
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            int r = in.nextInt();
            int D = in.nextInt();
            int[] x = new int[11];
            x[0] = in.nextInt();
            for (int i = 1; i < x.length; i++) {
                x[i] = x[i - 1] * r - D;
                System.out.println(x[i]);
            }
        }
    }
}


Measured memory_bytes: 22100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define nl "\n"
#define rep(i,n) for(ll i=0; i<(n); i++)
typedef vector<ll> vl;
typedef vector<string> vs;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define sortup(V) sort(V.begin(), V.end())
#define sortdown(V) sort(V.rbegin(), V.rend())
#define MOD 998244353 //1000000007


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

    // solution comes here

    ll N, MAX=-1, MIN=1e11, A;
    cin >> N;
    rep(i, N) {
        cin >> A;
        MAX = max(A, MAX);
        MIN = min(A, MIN);
    }

    cout << MAX - MIN << nl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;i<n;i++)
#define ll long long
 
#define pi pair < ll , ll >
#define pb push_back
#define mp make_pair
#define F first
#define S second
 
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
 
#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
using namespace std;

const ll mod = 1e9+7;
ll power(ll x, ll y, ll m=mod) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2ll, m) % m; 
    p = (p * p) % m; 
    return (y%2 == 0)? p : (x * p) % m; 
} 

ll modInverse(ll a, ll m = mod) 
{ 
    return power(a, m-2ll, m); 
} 

/*void solve() {
    ll n, k, i, j, p, q, ans = 0;
    n = 3;
    cin>>k;
    ll a[k+1];
    Fo(i,1,k+1) {
        a[i] = power(k/i, n);
    }
    for(i=k;i>0;i--) {
        j = 2*i;
        while(j<=k) {
            a[i] = ( a[i] - a[j] + mod ) % mod;
            j += i;
        }
        ans = ( ans + a[i] * i ) % mod;
        // debug2(i,a[i]);
    }
    ans = (ans+mod)%mod;
    cout<<ans;
}*/

void solve() {
    ll n, i, j, k, ans = 0, r[4001], g[4001], b[4001];
    string s;
    cin>>n>>s;
    fo(i,n)r[i]=g[i]=b[i]=0;
    ans = n * ( n-1ll ) * ( n-2ll ) / 6ll;
    fo(i,n) {
        if(s[i]=='R') {
            r[i] = 1;
        }
        if(s[i]=='G') {
            g[i] = 1;
        }
        if(s[i]=='B') {
            b[i] = 1;
        }
        if(i>0) {
            r[i] += r[i-1];
            g[i] += g[i-1];
            b[i] += b[i-1];
        }
    }
    fo(i,n) {
        Fo(k,i+2,n) {
            if(s[i]==s[k]) {
                ans -= (k-i-1);
            } else {
                if(s[i]=='R')ans -= r[k-1] - r[i];
                if(s[i]=='G')ans -= g[k-1] - g[i];
                if(s[i]=='B')ans -= b[k-1] - b[i];
                if(s[k]=='R')ans -= r[k-1] - r[i];
                if(s[k]=='G')ans -= g[k-1] - g[i];
                if(s[k]=='B')ans -= b[k-1] - b[i];
            }
            if((k+i)%2==0) {
                j = (k+i)/2;
                if(s[i]!=s[j] and s[k]!=s[j] and s[i]!=s[k])ans--;
            }
        }
    }
    cout<<ans<<endl;
}

int main()
{
    fastIO;ll t=1;
    // cin>>t;
    while(t--)solve();
}

Measured memory_bytes: 3700
#![allow(unused_imports)]
use proconio::input;
use proconio::marker::*;
use std::collections::VecDeque;

fn main() {
  input!{
    n: usize,
    vals: [(isize,isize,isize);n],
  }
  let mut last = (0, 0, 0);
  for i in 0..n {
    let val = vals[i];
    let diff_t = val.0 - last.0;
    let need_val = (val.1 - last.1).abs() + (val.2 - last.2).abs();
    if diff_t < need_val {
      println!("No");
      return
    } else if (diff_t - need_val) % 2 == 1 {
      println!("No");
      return
    }
    last = val;
  }
  
  println!("Yes");
}

Measured memory_bytes: 5536
#include<stdio.h>
int main()
{

    int i,h,k,length,j,n,m;
    scanf("%d%d",&k,&h);
    m=0;
    j=k*h;
    i=k*h*j;
    if(i%2!=0){
        printf("Yes\n");
    }

    else {
        printf("No\n");
    }

    return 0;
}


Measured memory_bytes: 128
use std::io;

fn main() {
  let mut input = String::new();

  io::stdin().read_line(&mut input)
    .expect("failed to read line");


  let mut count = 0;
  let mut max = 0;

  for c in input.to_string().chars(){
    if c == 'A' || c == 'T' || c == 'C' || c == 'G' {
      count += 1;
    }
    else{
      if (count > max){
        max = count;
      }
      count = 0;
    }
  }
  if (count > max){
    max = count;
  }

  println!("{}", max);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
const int MAX = 800 + 10;
typedef long long i64;
using namespace std;
int H, W, K;
int moves[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
pair<int, int> que[MAX * MAX];
int dist[MAX][MAX];
bool vis[MAX][MAX];
char mat[MAX][MAX];
int bfs(int sx, int sy){
	int b = 0, e = 0;
	vis[sx][sy] = true;
	memset(dist, -1, sizeof(dist));
	dist[sx][sy] = 0;
	que[b++] = {sx, sy};
	while(e < b){
		auto cur = que[e++];
		if(cur.first == 1 or cur.second == W or cur.second == 1 or cur.first == H){
			return dist[cur.first][cur.second];
		}
		if(dist[cur.first][cur.second] == K)continue;
		for(int i = 0; i < 4; i++){
			pair<int, int> ncur;
			ncur.first = cur.first + moves[i][0], ncur.second = cur.second + moves[i][1];
			if(ncur.first < 1 or ncur.first > H or ncur.second < 1 or ncur.second > W)continue;
			if(vis[ncur.first][ncur.second])continue;
			if(mat[ncur.first][ncur.second] == '#')continue;
			que[b++] = ncur;
			vis[ncur.first][ncur.second] = true;
			dist[ncur.first][ncur.second] =dist[cur.first][cur.second] + 1;
		}
	}

	for(int i = 0; i < b; i++)dist[que[i].first][que[i].second] = K;

	e = 0;
	while(e < b){
		auto cur = que[e++];
		if(cur.first == 1 or cur.second == W or cur.second == 1 or cur.first == H){
			return dist[cur.first][cur.second];
		}

		for(int i = 0; i < 4; i++){
			pair<int, int> ncur;
			ncur.first = cur.first + moves[i][0], ncur.second = cur.second + moves[i][1];
			if(ncur.first < 1 or ncur.first > H or ncur.second < 1 or ncur.second > W)continue;
			if(vis[ncur.first][ncur.second])continue;
			//if(dist[cur.first][cur.second] < K and mat[ncur.first][ncur.second] == '#')continue;
			que[b++] = ncur;
			vis[ncur.first][ncur.second] = true;
			dist[ncur.first][ncur.second] =dist[cur.first][cur.second] + 1;
		}
	}
	assert(1 == 0);
	return 0;
}
int main() {

    #ifdef LOCAL_DEBUG
    freopen ("data.in", "r", stdin );
    freopen ("data.out", "w", stdout );
    #endif
    ios_base::sync_with_stdio(0); cin.tie(0);
    #define endl '\n'



    cin >> H >> W >> K;
    int sx, sy;
    for(int i = 1; i <= H; i++)
    	for(int j =1 ; j <= W; j++){
    		cin >> mat[i][j];
    		if(mat[i][j] == 'S'){
    			mat[i][j] = '.';
    			sx = i, sy = j;
    		}
    	}

    int ans = bfs(sx, sy);
    cout << (ans + K - 1) / K << endl;

}



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

#define rep(i, j) for (int i = 0; i < j; i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define debug(x) cerr << #x << " : " << x << endl;
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

template<class T,class U> void chmax(T& a, U b) {if(a<b)a=b;}
template<class T,class U> void chmin(T& a ,U b) {if(b<a)a=b;}

int main() {

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int n;
    cin>>n;
    vi p(n);
    rep(i, n) cin>>p[i];

    int ans = 1;
    int m = p[0];
    for(int i = 1; i < n; i++) {
        // cout << m << " " << p[i] << " " << (m > p[i]) << endl;
        if (m > p[i]) {
            ans++;
            m = p[i];
        }
    }

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


Measured memory_bytes: 1024
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

//vector string deque break continue
#define forn(i, s, f) for (int i = (int)s; i < (int)f; i++)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define fs first
#define sc second
#define pf push_front
#define pb push_back
#define pop_f pop_front
#define pop_b pop_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int n;
    cin >> n;
    forn (i, 0, 1e6)
        if ((i * 108 / 100) == n)
            return cout << i, 0;
    cout << ":(";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define popcnt(x) __builtin_popcount(x)
#define inf 0x3f3f3f3f
#define watch(x) cout << (#x) << " is " << (x) << endl
#define rand() (rand() << 15 | rand())
using namespace std;
typedef long long  ll;


int main(){
    ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    for(int &x : a)
        cin >> x;
    
    int ans = 0;
    for(int i = 0 ; i < n ; ++i){
        bool ok = true;
        for(int j = 0 ; j < i ; ++j){
            ok &= (a[j] <= a[i]);
        }
        ans += ok;
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#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; }
// template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    cout << n / 11 * 2 + (n % 11 >= 7) + (n % 11 >= 1) << "\n";
    return 0;
}

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

int main() {
	int h, w, n;
	cin >> h >> w >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	vector<vector<int>> ans(h, vector<int>(w));
	int c = 1;
	rep(i, h) {
		rep(J, w) {
			int j;
			if(i%2 == 0) j = J;
			else j = w-J-1;
			
			if(a[c-1] == 0) c++;
			ans[i][j] = c;
			a[c-1]--;
		}
	}
	rep(i, h) {
		rep(j, w) {
			cout << ans[i][j] << ((j == w-1) ? '\n' : ' ');
		}
	}
	return 0;
}

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

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

using namespace std;

int main() {

    int n,m,sum=0,counter=0;
    cin >> n >> m;

    int A[n];
    rep(i,n) cin >> A[i], sum+=A[i];

    rep(i,n) if(A[i]*4*m>=sum) counter+=1;

    if(n>=counter&&counter>=m) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
N = int(input())
S = input()
MOD = 10**9+7

alp = "qwertyuiopasdfghjklzxcvbnm"

ans = 1

for c in alp:
    n = 0
    for i in range(N):
        if S[i] == c:
            n += 1
    ans *= n+1
    ans = ans % MOD
    
print(ans-1)

Measured memory_bytes: 41196
#include<bits/stdc++.h>
using namespace std;
#define fastIO std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0)
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define endl '\n'
typedef vector<int> VI;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef double db;
//mt19937 mrand(random_device{}()); 
//int rnd(int x) { return mrand() % x;}
const ll mod=1000000007;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

const int maxn = 2e5 + 10; 

int main()
{
	fastIO;
	ll a; long double b;
	cin >> a >> b;
	long double ans = a * b;
	cout << (ll)ans << endl;	
	return 0;
}

Measured memory_bytes: 3748
#include <stdio.h>

// min
int main(void){
  int a = 0, b = 0;

  scanf("%d%d", &a, &b);

  if(a <= b*2){
    printf("0\n");
  }else{
    printf("%d\n", a - (b*2));
  }

  return 0;

}


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

int main(){

  string a,b,c;

  cin >> a >> b >> c;

  string  str = {a[0],b[0],c[0]};
  
  transform(str.begin(),str.end(),str.begin(), ::toupper);
  
  cout << str  << endl;

  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define ll long long
#define P pair<int, int>
#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define LAST(x) (x)[(x).size() - 1]
#define GI(name) \
  int(name);     \
  scanf("%d", &(name))
#define GI2(name1, name2) \
  int(name1), (name2);    \
  scanf("%d %d", &(name1), &(name2))
#define GI3(name1, name2, name3) \
  int(name1), (name2), (name3);  \
  scanf("%d %d %d", &(name1), &(name2), &(name3))
#define GVI(name, size)    \
  vector<int>(name)(size); \
  FOR(i, (size)) scanf("%d", &(name)[i])
#define GS(name) \
  string(name);  \
  cin >> (name);
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  FOR(i, v.size() - 1) { ret += to_string(v[i]) + ","; }
  if (v.size() > 0) {
    ret += to_string(LAST(v));
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

struct Edge {
  int a, b, cost;
  Edge(int _a, int _b, int _cost) {
    a = _a;
    b = _b;
    cost = _cost;
  }
  bool operator<(const Edge& o) const { return cost < o.cost; }
};
struct Union_Find {
  vector<int> data;
  Union_Find(int size) { data = vector<int>(size, -1); }
  bool union_set(int x, int y) {
    x = root(x);
    y = root(y);
    if (x != y) {
      if (data[y] < data[x])
        swap(x, y);
      data[x] += data[y];
      data[y] = x;
    }
    return x != y;
  }
  bool find(int x, int y) { return root(x) == root(y); }
  int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
  int size(int x) { return -data[root(x)]; }
};
int main() {
  GI(N);
  vector<P> xl(N), yl(N);
  FOR(i, N) {
    GI2(x, y);
    xl[i] = P(i, x);
    yl[i] = P(i, y);
  }
  sort(ALL(xl), [](const P& l, const P& r) { return l.second < r.second; });
  sort(ALL(yl), [](const P& l, const P& r) { return l.second < r.second; });
  vector<Edge> edges;
  FOR(i, N - 1) {
    edges.push_back(
        Edge(xl[i].first, xl[i + 1].first, xl[i + 1].second - xl[i].second));
    edges.push_back(
        Edge(yl[i].first, yl[i + 1].first, yl[i + 1].second - yl[i].second));
  }
  sort(ALL(edges));
  Union_Find uf(N);
  ll sum = 0;
  FOR(i, edges.size()) {
    Edge e = edges[i];
    if (uf.root(e.a) != uf.root(e.b)) {
      sum += e.cost;
      uf.union_set(e.a, e.b);
    }
  }
  print(sum);
  return 0;
}

Measured memory_bytes: 6516
function main(input) {
  input = input.trim()
  args = input.split('\n');
  text = (args.slice(-1)[0])
  isFlag = false
  ans = 0
  for (var i = 1; i < args.length -1 ; i++){
    baz = args[i].split(' ');
    if (isFlag) {
      ans += parseInt(baz[1], 10)
    }
    if (baz[0] == text) {
      isFlag = true
    }
  }
  console.log(ans)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21192
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#define INF 1000000001

using namespace std;

int n;

void counting_sort(vector<int>& A, vector<int>& B, int k) {
	vector<int> C(k,0);
	for (int i = 0; i < n; ++i) {
		++C[A[i]];
	}
	for (int i = 1; i < k; ++i) {
		C[i] += C[i-1];
	}
	for (int i = n-1; i >= 0; --i) {
		B[C[A[i]]-1] = A[i];
		--C[A[i]];
	}
	return;
}

int main(void) {
	int k = 0;
	cin >> n;
	vector<int> A(n),B(n);
	for (int i = 0; i < n; ++i) {
		cin >> A[i];
		k = max(A[i],k);
	}
	counting_sort(A,B,k+1);
	for (int i = 0; i < n; ++i) {
		cout << B[i];
		if (i < n-1) {
			cout << " ";
		}
	}
	cout << endl;
	return 0;
}



Measured memory_bytes: 18344
#include<bits/stdc++.h>
#define int long long
#define INF 1e18
using namespace std;
const int Maxn=410;
int N;
int A[Maxn],Pre[Maxn];
int Dp[Maxn][Maxn];
signed main()
{
	cin>>N;
	for(int i=1;i<=N;i++)
	{
		cin>>A[i];
		Pre[i]=Pre[i-1]+A[i];
	}
	for(int i=1;i<Maxn;i++)
	{
		for(int j=0;j<Maxn;j++)
		{
			if(i==j)
			{
				continue;
			}
			Dp[i][j]=INF;
		}
	}
	for(int Len=1;Len<N;Len++)
	{
		for(int i=1;i+Len<=N;i++)
		{
			int j=i+Len;
			int Interval=Pre[j]-Pre[i-1];
			for(int Turn=i;Turn<j;Turn++)
			{
				Dp[i][j]=min(Dp[i][j],Dp[Turn+1][j]+Dp[i][Turn]+Interval);
			}
		}
	}
	cout<<Dp[1][N]<<endl;
	return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <limits>
#include <sstream>
#include <fstream>
#include <climits>
#include <map>
#include <numeric>
#include <functional>
#include <utility>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;
typedef pair<int, int> P;

int main(void) {
  int k;
  cin >> k;
  string s;
  cin >> s;
  if (s.length() <= k) cout << s << endl;
  else cout << s.substr(0, k) << "..." << endl;

  return 0;
}


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

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

    char c;
    bool f = true;;
    for(int i=0; i<a; i++){
        cin >> c;
        if(c < '0' || c > '9'){
            f = false;
        }
    }
    cin >> c;
    if(c != '-'){
        f = false;
    }
    for(int i=0; i<b; i++){
        cin >> c;
        if(c < '0' || c > '9'){
            f = false;
        }
    }

    if(f){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
  
    return 0;
}


Measured memory_bytes: 256
function main()
  
  (N,K) = map(x -> parse(Int,x), split(readline()))
  
  h = map(x -> parse(Int,x), split(readline()))
  
  ans = 0
  
  for i in 1:N
    
    if h[i] >= K
      ans += 1
    end
    
  end
  
  println(ans)
  
end

main()

Measured memory_bytes: 158768
class SegTree
  attr_accessor(:node, :op, :e, :offset)
  
  def initialize(n, op, e)
    @op = op
    @e = e

    ofs = 1
    while ofs < n
      ofs <<= 1
    end
    
    @node = Array.new(2 * ofs - 1, @e) # 0-indexed
    @offset = ofs - 1 # log2(n).ceil - 1
  end

  def update(i, x) # 一点更新
    i += @offset
    @node[i] = x
    
    while i > 0
      i = (i - 1) >> 1
      @node[i] = @op.call(@node[(i << 1) + 1], @node[(i << 1) + 2])
    end
  end

  def query(l, r) # [l, r)
    l += @offset
    r += @offset

    res = @e
    while l < r
      if l & 1 == 0
        res = @op.call(res, @node[l])
      end
      if r & 1 == 0
        res = @op.call(res, @node[r - 1])
      end
      l = l >> 1
      r = (r - 1) >> 1
    end
    return res
  end
end

m = 3 * (10 ** 5)
chmax = -> (x, y) { (x > y)? x : y }
n, k = $stdin.readline.chomp.split.map(&:to_i)
seg = SegTree.new(m + 1, chmax, 0)

res = 0
n.times do
  a = $stdin.readline.to_i
  l = [0, a - k].max
  r = [m, a + k].min
  t = seg.query(l, r + 1) + 1
  res = (res < t)? t : res
  seg.update(a, t)
end
puts res

Measured memory_bytes: 22616
package main

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

func main(){
  scanner := bufio.NewScanner(os.Stdin)
  scanner.Scan()
  date := strings.Replace(scanner.Text(),"/","",2)
  diff,_ := strconv.Atoi(date)
  diff = diff-20190430
  if diff <= 0 {
    fmt.Println("Heisei")
  } else {
    fmt.Println("TBD")
  }
}

Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main() {//A問題
	int N;
	int A;
	bool flag;

	cin >> N;
	cin >> A;

	//判定
	if (N%500<=A) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    char[] tap = sc.nextLine().toCharArray();
    int len = tap.length;
    boolean flg = true;
    for(int i = 0; i < len; i++){
      if(i % 2 == 0){
        if(tap[i] == 'L'){
          flg = false;
      	}
      }
      else{
        if(tap[i] == 'R'){
          flg = false;
      	}
      }
    }
    
    if(flg){
      System.out.println("Yes");
    }
    else{
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
#define int long long
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

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

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

signed main() {
  int N, A, B;
  cin >> N >> A >> B;

  if (N == 1 && A != B) {
    cout << 0 << endl;
    return 0;
  }

  if (A > B) {
    cout << 0 << endl;
    return 0;
  }

  int mn = (N - 1) * A + B;
  int mx = (N - 1) * B + A;

  int ans = mx - mn + 1;
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());
		String str[] = br.readLine().split("");

		int wSum = 0;
		int eSum = 0;

		for (int i = 0; i < n; i++) {
			if (str[i].equals("W")) {
				wSum++;
			} else {
				eSum++;
			}
		}

		int ans = Integer.MAX_VALUE;

		int leftW = 0;
		int leftE = 0;

		for (int i = 0; i < n; i++) {
			int rightE = eSum - leftE;
			if (str[i].equals("E"))
				rightE--;

			ans = Math.min(ans, leftW + (rightE));

			if (str[i].equals("W")) {
				leftW++;
			} else {
				leftE++;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 53484