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

int main()
{
    string s; cin>>s; int g=0,p=0,w=0,l=0;
    for(int i=0; i<s.size(); i++)
    {
        if(s[i]=='g')
        {
            if(g>p)
            {
                w++;
                p++;
            }
            else g++;
        }
        else if(s[i]=='p')
        {
            if(g>p) p++;
            else
            {
                g++;
                l++;
            }
        }
    }
    cout<<w-l<<endl;
    return 0;
}


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

int main()
{
    int n,sum=0;
    cin>>n;
    int a[n]={};
    for(int i=0;i<n-1;i++)
        scanf("%d",&a[i]);
    for(int i=1;i<n-1;i++)
        sum+=min(a[i],a[i-1]);
    sum+=a[0]+a[n-2];
    cout<<sum;
}




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

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

Measured memory_bytes: 3604
#include<stdio.h>

int main(void){
    int L,N;
    scanf("%d %d", &N,&L);
    if (L>0) {
        printf("%d", ((2*L+N-1)*N)/2-L);
        return 0;
    }
    else if(L+N-1<0){
        printf("%d", ((2*L+N-1)*N)/2-(L+N-1));
        return 0;
    }
    else{
        printf("%d", ((2*L+N-1)*N)/2);
        return 0;       
    }
}

Measured memory_bytes: 2088
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin>>n;
  vector<pair<string,int>> a(n);
  for(int i=0;i<n;i++){
    cin>>a.at(i).first>>a.at(i).second;
  }
  for(int i=0;i<n;i++){
    int k=0;
    while(a.at(k).second<0){
      k++;
    }
    for(int j=0;j<n;j++){
      if(k==j)continue;
      else if(a.at(j).second<0){
        continue;
      }
      else if(a.at(k).first>a.at(j).first){
        k=j;
      }
      else if(a.at(k).first==a.at(j).first){
        if(a.at(k).second<a.at(j).second){
          k=j;
        }
      }
    }
    cout<<k+1<<endl;
    a.at(k).second=-1;
  }
}

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

int main(){
    int n, k, d, a;
    cin >> n >> k;
    bool arr[n];
    for(int i = 0; i < n; i++) arr[i] = 0;
    for(int i = 0; i < k; i++){
        cin >> d;
        for(int j = 0; j < d; j++){
            cin >> a;
            a--;
            arr[a] = 1;
        }
    }
    int r = 0;
    for(int i = 0; i < n; i++){
        r += !arr[i];
    }
    cout << r << '\n';
}


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

int main(){
    string t;
    cin>>t;
    rep(i,t.size()){
        if(t[i]=='?') t[i]='D';
    }
    cout<<t<<endl;
    return 0;
}

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
using ll = long long;
using ld = long double;
const int MOD = 1e9+7;


int main() {
    int n; cin >> n;
    V<ll> a(n), b(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < n; i++) cin >> b[i];

    ll o = 0, s = 0;
    V<ll> v;
    for(int i = 0; i < n; i++){
        if(a[i] <= b[i]) s += b[i] - a[i];
        else{
            o += a[i] - b[i];
            v.push_back(a[i] - b[i]);
        }
    }

    if(o < s){
        cout << -1 << endl;
        return 0;
    }
    if(s == 0){
        cout << 0 << endl;
        return 0;
    }

    ll ans = n;
    ll x = o - s;
    if(0 < x){
        int m = v.size();
        sort(ALL(v));
        for(int i = 0; i < m; i++){
            if(0 <= x - v[i]){
                ans--;
                x -= v[i];
            }
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 5480
N = int(input())
nums = list(map(int, input().split()))
cnt = 0
xor = 0
sum_n = 0
lb = 0
rb = 0
while rb < N:
  if sum_n+nums[rb] == xor^nums[rb]:
    sum_n += nums[rb]
    xor ^= nums[rb]
    cnt += rb-lb+1
    rb += 1
  else:
    sum_n -= nums[lb]
    xor ^= nums[lb] 
    lb += 1
print(cnt)

Measured memory_bytes: 23560
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
#include <cmath>
using namespace std;
using ll = long long;
#define rep(i, j, n) for(int i = (j); i < (n); ++i)
#define rrep(i, j, n) for(int i = (n) - 1; (j) <= i; --i)
constexpr ll MOD = 1000000007;
constexpr ll INF = 1LL << 60;

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


	int k, s; cin >> k >> s;
	int ans = 0;
	rep(i, 0, k + 1) {
		rep(j, 0, k + 1) {
			int sum = s - i - j;
			if (0 <= sum && sum <= k) ++ans;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3640
#include <iostream>
using namespace std;
typedef pair<int, int> utime;

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0298

int main() {
	int n;
	cin >> n;
	utime a[n];
	for (int i = 0; i < n; i++) {
		int h, m;
		cin >> h >> m;
		a[i] = make_pair(h, m);
	}
	int l;
	cin >> l;
	utime b[l];
	for (int i = 0; i < l; i++) {
		int h, m;
		cin >> h >> m;
		b[i] = make_pair(h, m);
	}
	
	int i = 0, j = 0;
	int am = a[i].first * 60 + a[i].second;
	int bm = b[j].first * 60 + b[j].second;
	if (am >= bm) {
		cout << b[j].first << ":" << (b[j].second < 10 ? "0" : "") << b[j].second;
		if (am == bm) i++;
		j++;
	} else {
		cout << a[i].first << ":" << (a[i].second < 10 ? "0" : "") << a[i].second;
		i++;
	}
	
	while (i < n || j < l) {
		bool same = false;
		bool left;
		if (i == n) left = false;
		else if (j == l) left = true;
		else {
			int am = a[i].first * 60 + a[i].second;
			int bm = b[j].first * 60 + b[j].second;
			if (am == bm) same = true;
			else if (am < bm) left = true;
			else left = false;
		}

		if (same || !left) {
			cout << " " << b[j].first << ":" << (b[j].second < 10 ? "0" : "") << b[j].second;
			if (same) i++;
			j++;
			continue;
		}
		cout << " " << a[i].first << ":" << (a[i].second < 10 ? "0" : "") << a[i].second;
		i++;
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 1164
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<stack>
#include<queue>
#include<map>
#include<cmath>
#include<bitset>
using namespace std;
#define ll long long
#define N 100003
#define INF 0x3f3f3f3f
#define mod 998244353
#define mkp make_pair
template <typename T> inline void read(T &x){char c; bool nega=0; while((!isdigit(c=getchar()))&&(c!='-')); if(c=='-'){nega=1; c=getchar();} x=c-48; while(isdigit(c=getchar())) x=x*10+c-48; if(nega) x=-x;}
template <typename T> inline void writep(T x){if(x>9) writep(x/10); putchar(x%10+48);}
template <typename T> inline void write(T x){if(x<0){ putchar('-'); x=-x;} writep(x);}
template <typename T> inline void writeln(T x){write(x); putchar('\n');}
int n, a[N];
int main(){
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int i, j, t;
	
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	cin>>n;
	cout<<n*n*n<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
const ll MOD = 1e9 + 7;
const long long INF = 1LL << 60;

int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    s += "A";

    if (n == 1)
    {
        cout << 1 << endl;
        return 0;
    }

    map<char, int> mp;
    for (int i = 0; i < n; i++)
    {
        mp[s.at(i)]++;
    }

    ll answer = 1;
    for (auto itr = mp.begin(); itr != mp.end();itr++)
    {
        int value = itr->second;
        answer = (answer * ((value + 1) % MOD)) % MOD;
    }
    answer--;

    cout << answer << endl;
}

Measured memory_bytes: 512
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int vis[11];
int check(int n)
{
	while(n)
	{
		if(vis[n%10]==1)
			return 0;
		n/=10;
	}
	return 1;
}
int main()
{
	int n,k;
	int x;
	scanf("%d%d",&n,&k);
 
        for(int i=0;i<k;i++)
	    {
		   cin>>x;
		   vis[x]=1;
	    }
	    for(int i=n;i>0;i++)
	    {
		   if(check(i))
		   {
                       cout<<i<<endl;
                        return 0;
 
                   }
	    }
 
 
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct H {
    int a;
    int b;
    int c;
};
int dp[100010][3];
int main () {
    int N;
    cin >> N;
    vector<struct H> A(N+1);
    for (int i = 1; i <= N; i++) {
        cin >> A[i].a >> A[i].b >> A[i].c;
    }
    dp[0][0] = dp[0][1] = dp[0][2] = 0;
    for (int i = 1; i <= N; i++) {
        dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + A[i].a;
        dp[i][1] = max(dp[i-1][2], dp[i-1][0]) + A[i].b;
        dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + A[i].c;
    }
    cout << max({dp[N][0], dp[N][1], dp[N][2]}) << endl;
}

Measured memory_bytes: 2560
#include <iostream>
typedef long long ll;
#define rep(i,n) for(int i = 0; i < (n); ++i )

using namespace std;
const long long INF = 1LL << 60;

int N,M;
ll l_max = -1, r_min = INF;
ll L[100010][2];
int main(){
  cin >> N >> M;
  rep(i,M){
    cin >> L[i][0] >> L[i][1];
    if(l_max < L[i][0]) l_max = L[i][0];
    if(r_min > L[i][1]) r_min = L[i][1];
  }
  if(l_max > r_min){
    cout << "0" << endl;
    return 0;
  }
  cout << r_min - l_max + 1 << endl;
  return 0;
}


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

typedef long long ll;

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

int main() {
    int n;
    ll ans = 0;
    cin >> n;
    vector<int> a(n);
    for (int i = 0;i < n;++i) {
        int b;
        cin >> b;
        a[b-1] = i;
    }
    set<int> b;
    b.insert(n);
    b.insert(-1);
    for (int i = 0;i < n;++i) {
        auto it = b.lower_bound(a[i]);
        int c = *it-a[i],d = a[i]-*(--it);
        ans += (ll)c*d*(i+1);
        b.insert(a[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 10368
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> VI;
typedef pair <int,int> ii;
typedef long long LL;
#define pb push_back
const int INF = 2147483647;
const LL INFF = 1000000000000000000LL;
const int N = 105;

int val[3] = {2, 3, 5};
int cost[3];
map<LL, LL> mapa;
LL n;
int d, z;

LL go(LL n) {
	if (n == 1) return d;
	if (n == 0) return 0;
	if (mapa.find(n) != mapa.end()) return mapa[n];
	LL minn = INFF;
	if ((n * d) / d == n && n * d > 0) minn = min(minn, n * d);
	for (int i=0;i<3;i++) {
		int k = n % val[i];
		minn = min(minn, go(n / val[i]) + cost[i] + d * 1LL * k);
		if (k != 0) minn = min(minn, go(n / val[i] + 1) + cost[i] + d * 1LL * (val[i] - k));
	}
	mapa[n] = minn;
	return minn;
}

int main() {
scanf("%d", &z);
while (z--) {
	scanf("%lld %d %d %d %d", &n, &cost[0], &cost[1], &cost[2], &d);
	mapa.clear();
	printf("%lld\n", go(n));
}	
return 0;
}





Measured memory_bytes: 4584
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N;
    cin >>N;
    vector<int>vec(N);
    for(int i=0;i<N;i++){
        cin >> vec.at(i);
    }
    int count=0;
    for(int i=0;i<N;i++){
        if((i+1)%2==1){
            if(vec.at(i)%2==1){
                count++;
            }
        }
    }
    cout << count<<endl;
}

Measured memory_bytes: 3628
a,b,c,d,e,f = map(int, input().split())
mx=0
swmx=a*100
smx=0
 
for i in range(0,31):
    for j in range(0,31):
        for k in range(0,1000):
            for l in range(0,1000):
                w=0
                s=0
                w+=100*a*i+100*b*j
                s+=c*k+d*l
                targ=w+s
                if targ>f:
                    break
                if targ==0:
                    break
                if  s<=e*w/100  and mx<s/(w+s):
                    mx=s/targ
                    swmx=targ
                    smx=s
print(swmx,smx)

Measured memory_bytes: 73624
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	int n,a[101010]={};
	cin>>n;
	FOR(i,0,n){
		cin>>a[i];
	}
	sort(a,a+n);
	int idx=0,ans=0;
	FORD(i,n,0){
		if(idx==0){
			ans+=a[i];
			idx=1;
		}else{
			ans-=a[i];
			idx=0;
		}
	}
	cout<<ans<<endl;
    return 0;
}


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

int main(){
  int N; cin >> N;
  double otoshidama=0;
  for(int i=0; i<N; i++){
    double x; string u;
    cin >> x >> u;
    if(u=="BTC") x*=380000;
    otoshidama+=x;
  }
  cout << otoshidama << endl;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
ans = [0]*2
tmp = [0]*n
false = [0]*n
for _ in range(m):
    p,s = map(str,input().split())
    p = int(p)
    if tmp[p-1] == 0:
        if s == 'AC':
            ans[0] += 1
            tmp[p-1] += 1
            ans[1] += false[p-1]
        elif s == 'WA':
            false[p-1] += 1
print(*ans)

Measured memory_bytes: 4596
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        int ret = 0;
        vector<int> satisfaction(1<<16, 0);
        for(int i=0; i<n; ++i){
            int m, l;
            cin >> m >> l;
            bitset<16> bs;
            for(int j=0; j<m; ++j){
                int s, e;
                cin >> s >> e;
                for(int k=s; k<e; ++k)
                    bs[k-6] = true;
            }

            for(int j=0; j<(1<<16); ++j){
                if(!(j & bs.to_ulong())){
                    int k = j | bs.to_ulong();
                    satisfaction[k] = max(satisfaction[k], satisfaction[j] + l);
                    ret = max(ret, satisfaction[k]);
                }
            }
        }

        cout << ret << endl;
    }
}

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

using namespace std;

typedef long long int ll;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl "\n"

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
 
    string s;
    cin >> s;

    ll cnt = 0;
    for(ll i=1; i<sz(s); i++)
    {
        if(s[i]!=s[i-1])
        {
            cnt++;
        }
    }   

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		String s1 = scan.next();
		String s2 = scan.next();
		String s3 = scan.next();

		String s =s1.substring(0,1);
		s+=s2.substring(0,1);
		s+=s3.substring(0,1);

		String S =s.toUpperCase();
		System.out.println(S);
	}

}


Measured memory_bytes: 23760
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

void seeMap(const int &H,const int &W,vector<vector<char>> m){
    REP(i,H+2) {
        REP(j,W+2) {
            cout << m[i][j];
        }
        cout << endl;
    }
}


int main() {
    int H,W;
    cin >> H >> W;
    vector<vector<char>> m(H+2,vector<char>(W+2,'.'));
    REP(i,H) {
        string s;
        cin >> s;
        REP(j,W) {
            m[i+1][j+1]=s[j];
        }
    }
    // seeMap(H,W,m);
    REP(i,H) {
        REP(j,W) {
            if (m[i+1][j+1]=='#') {
                bool a = m[i][j+1] == '#';
                bool b = m[i+1][j] == '#';
                bool c = m[i+2][j+1] == '#';
                bool d = m[i+1][j+2] == '#';
                if (!(a || b || c || d)) {
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}


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

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

int64_t lcm(int64_t a, int64_t b) {
  int64_t d = gcd(a, b);
  return a / d * b;
}

int64_t solve(std::string &S, std::string &T) {
  int64_t slen = S.size(), tlen = T.size();
  int64_t L = lcm(slen, tlen);
  int64_t sstride = L / slen;
  int64_t tstride = L / tlen;
  for(int64_t i = 0; i * sstride * tstride < L; i++){
    if (S[i * tstride] != T[i * sstride]) return -1;
  }
  return L;
}

int main(int argc, char *argv[]) {
  int64_t N, M;
  std::string S, T;
  std::cin >> N >> M >> S >> T;
  std::cout << solve(S, T) << std::endl;
  return 0;
}


Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main(string[] args)
    {
        var line = Console.ReadLine().Split(' ').ToArray();
        int A = int.Parse(line[0]);
        int B = int.Parse(line[2]);
        string op = line[1];

        if (op == "-")
        {
            Console.WriteLine(A - B);
        }
        else if (op == "+")
        {
            Console.WriteLine(A + B);
        }
    }
}

Measured memory_bytes: 11220
k, s = map(int, input().split())

if s==3*k:
    print(1)
else:
    ans=0
    for i in range(k+1):
        if i>s:
            break
        for j in range(k+1):
            if i+j+k>=s and s-i-j>=0:
                ans+=1


    print(ans)

Measured memory_bytes: 3060
#include <stdio.h>

int main() {
	int n, a, pos, left, right, mid, ans[100010], size = 1;
	scanf("%d %d", &n, &a);
	ans[0] = a;
	for (int i = 1; i < n; i++) {
		scanf("%d", &a);
		if (ans[size - 1] >= a)
			ans[size++] = a;
		else {
			left = 0;
			right = size - 1;
			while (left <= right) {
				mid = (left + right) / 2;
				if (ans[mid] < a) {
					pos = mid;
					right = mid - 1;
				}
				else
					left = mid + 1;
			}
			ans[pos] = a;
		}
	}
	printf("%d\n", size);
	return 0;
}


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

int main() {
    long n, ans = 0, cr = 0, cg = 0, cb = 0;
    string str;
    cin >> n >> str;
    vector<long> r(n, 0l), g(n, 0l), b(n, 0l), sr(n, 0l), sg(n, 0l), sb(n, 0l);
    rep(i, n) {
        if(str.at(i) == 'R') {
            r.at(i) = 1;
            cr++;
        }
        if(str.at(i) == 'G') {
            g.at(i) = 1;
            cg++;
        }
        if(str.at(i) == 'B') {
            b.at(i) = 1;
            cb++;
        }
    }
    int t = 0;
    if(str.at(0) == 'R') sr.at(0) = 1;
    if(str.at(0) == 'G') sg.at(0) = 1;
    if(str.at(0) == 'B') sb.at(0) = 1;
    rep(i, n - 1) {
        if(r.at(i + 1)) sr.at(i + 1) = sr.at(i) + 1;
        else sr.at(i + 1) = sr.at(i);
        if(g.at(i + 1)) sg.at(i + 1) = sg.at(i) + 1;
        else sg.at(i + 1) = sg.at(i);
        if(b.at(i + 1)) sb.at(i + 1) = sb.at(i) + 1;
        else sb.at(i + 1) = sb.at(i);
    }
    for(long i = 0; i < n; i++) {
        for(long j = i + 1; j < n; j++) {
            if(str.at(i) == str.at(j)) continue;
            if(str.at(i) + str.at(j) == 'R' + 'G') {
                ans += cb - sb.at(j);
                if(2 * j - i < n && b.at(2 * j - i)) ans--;
            }
            if(str.at(i) + str.at(j) == 'G' + 'B') {
                ans += cr - sr.at(j);
                if(2 * j - i < n && r.at(2 * j - i)) ans--;
            }
            if(str.at(i) + str.at(j) == 'B' + 'R') {
                ans += cg - sg.at(j);
                if(2 * j - i < n && g.at(2 * j - i)) ans--;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3704
using System;
using System.Linq;


namespace Contest
{
    class Scanner
    {
        private string[] line = new string[0];
        private int index = 0;

        public string Next()
        {
            if (line.Length <= index)
            {
                line = Console.ReadLine().Split(' ');
                index = 0;
            }

            var res = line[index];
            index++;
            return res;
        }

        public int NextInt()
        {
            return int.Parse(Next());
        }

        public long NextLong()
        {
            return long.Parse(Next());
        }

        public ulong NextUlong()
        {
            return ulong.Parse(Next());
        }

        public string[] Array()
        {
            line = Console.ReadLine().Split(' ');
            index = line.Length;
            return line;
        }

        public int[] IntArray()
        {
            var array = Array();
            var result = new int[array.Length];
            for (int i = 0; i < array.Length; i++)
            {
                result[i] = int.Parse(array[i]);
            }

            return result;
        }

        public long[] LongArray()
        {
            var array = Array();
            var result = new long[array.Length];
            for (int i = 0; i < array.Length; i++)
            {
                result[i] = long.Parse(array[i]);
            }

            return result;
        }
    }

    struct MyStruct
    {
        public long N;
        public int Cnt;
    }

    class Program
    {
        private int N;
        private int W;
        private long[] w, v;
        void Scan()
        {
            var sc = new Scanner();
            N = sc.NextInt();
            W = sc.NextInt();
            w = new long[N];
            v = new long[N];
            for (int i = 0; i < N; i++)
            {
                w[i] = sc.NextInt();
                v[i] = sc.NextLong();
            }
        }

        public void Solve()
        {
            Scan();
            var dp = new long[W + 1];
            for (int i = 0; i < N; i++)
            {
                for (int j = W; j >= 0; j--)
                {
                    if (j + w[i] > W) continue;
                    dp[j + w[i]] = Math.Max(dp[j + w[i]], dp[j] + v[i]);
                }
            }
            Console.WriteLine(dp.Max());
        }



        static void Main() => new Program().Solve();
    }


}

Measured memory_bytes: 11744
#include <bits/stdc++.h>
#define rep(i, a) for(int i = 0; i < a; i++)
#define all(v) v.begin(), v.end()
#define dcout cout << fixed << setprecision(15)
#define arep(i, a) for(auto i : a)
#define F first
#define S second
#define VE vector<int>
#define pb(x) push_back(x)
#define MOD 1000000007
#define INF 10000000000
#define int long long
#define KETA(n) floor(log10(n) + 1)
using namespace std;
signed main() {
    int a, b;
    cin >> a >> b;
    if(a < b * 2)
        cout << 0;
    else
        cout << a - b * 2;
    return 0;
}

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

int main() {
  cout <<fixed <<setprecision(9);
  double w,h,x,y; cin >>w >>h >>x >>y;
  double s = w*h/2;
  int ans = 0;
  if (x==w/2 && y==h/2){
    ans = 1;
  }
  cout <<s <<" ";
  
  cout <<ans;
  cout <<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
const ll MOD=998244353;

vector<int> to[101010];
bool visited[101010];
deque<int> ans;

void DFSa(int a){
  visited[a] = true;
  for(int v: to[a]){
    if(!visited[v]){
      ans.push_back(v);
      DFSa(v);
      return;
    }
  }
}

void DFSb(int a){
  visited[a] = true;
  for(int v: to[a]){
    if(!visited[v]){
      ans.push_front(v);
      DFSb(v);
      return;
    }
  }
}
    

int main(){
  int n, m; cin >> n >> m; 
  rep(i, m){
    int a, b; cin >> a >> b;
    a--; b--;
    to[a].push_back(b); to[b].push_back(a);
  }
  ans.push_back(0);
  DFSa(0); DFSb(0);
  cout << ans.size() << endl;
  while(ans.size()){
    cout << ans.front()+1;
    ans.pop_front();
    if(ans.size()) cout << " ";
  }
}

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


int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  int num_b,num_w,w_all;
  num_b=0;
  num_w=0;
  w_all=0;
  for(int i=0;i<n;++i){
    if(s[i]=='.'){
      w_all++;
    }
  }
  int ans=w_all;
  for(int i=0;i<n;++i){
    int cal=0;
    if(s[i]=='.'){
      num_w++;
    }else{
      num_b++;
    }
    cal=num_b+w_all-num_w;
    ans=min(ans,cal);
  }

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


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int i, j, ans = 0;
		int sum = 0;
		int A[] = new int[n + 1];
		int B[] = new int[n + 1];
		int C[] = new int[n];
		for (i = 1; i <= n; i++)
			A[i] = sc.nextInt();
		for (i = 1; i <= n; i++)
			B[i] = sc.nextInt();
		for (i = 1; i <= n - 1; i++)
			C[i] = sc.nextInt();

		for (i = 1; i <= n; i++) {
			sum += B[A[i]];
			if (i > 0 && A[i] - A[i - 1] == 1) {
				sum += C[A[i - 1]];
			}
		}
		ans = sum;
		System.out.println(ans);
	}
}

Measured memory_bytes: 21716
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define deb(x) cout<<#x<<" "<<x<<endl;
#define print(arr,n) for(int i=0;i<n;++i) { cout<<arr[i]<<" "; } cout<<endl;
#define ub(x,el) upper_bound(x.begin(),x.end(),el) - x.begin()
#define lb(x,el) lower_bound(x.begin(),x.end(),el) - x.begin();
#define bs(x,el) binary_search(x.begin(),x.end(),el)
#define MOD 1000000007
#define finish return 0
#define all(x) x.begin(),x.end()
using namespace std;
using namespace __gnu_pbds; 
typedef long long int ll;
typedef tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
template<int D, typename T> struct Vec : public vector<Vec<D - 1, T>> { static_assert(D >= 1, "Vector dimension must be greater than zero!"); template<typename... Args> Vec(int n = 0, Args... args) : vector<Vec<D - 1, T>>(n, Vec<D - 1, T>(args...)) { }}; template<typename T> struct Vec<1, T> : public vector<T> { Vec(int n = 0, T val = T()) : vector<T>(n, val) { } };
inline ll mod(ll x) { return (x%MOD + MOD)%MOD; }
ll gcd(ll a, ll b, ll &x, ll &y){if(a == 0){x = 0, y = 1; return b;} ll x1, y1;  ll d = gcd(b%a, a, x1, y1); x = y1 - (b/a) * x1; y = x1; return d;}
ll power(ll x,ll y, ll p) { ll res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res*x) % p; y = y>>1; x = (x*x) % p;   } return res; } 
ll power(ll x,ll y) { ll res = 1; while (y > 0) { if (y & 1) res = (res*x); y = y>>1; x = (x*x);   } return res; } 
ll mod(ll num, ll den){ return mod(mod(num) * power(den,MOD-2,MOD)); }
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	ll n;
    cin>>n;
    ll r = n%10;
    n = r;
    if(n==2 || n==4|| n==5 || n==7 || n == 9) cout<<"hon"<<endl;
    else if(n==3) cout<<"bon"<<endl;
    else cout<<"pon"<<endl;
}

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

int main () {
 int h,w;

 while (1) {
  cin >> h >> w;

  if (h == 0 && w == 0) {
   break;
  }
 
  for (int i = 0; i < h ;i++) {
   for (int j = 0 ; j < w ;j++) {
    cout << "#" ;
   }
  cout << endl;
  }
  cout << endl; 
 }

 return 0;
}

Measured memory_bytes: 1152
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int n = sc.nextInt();
            int x = sc.nextInt();
            int a = 0;
            if (n == 0 && x == 0)
                break;
            int i, j, k;
            for (i = x / 3; i <= n; i++) {
                for (j = 1; j < i; j++) {
                    for (k = 1; k < j;k++) {
                        if (i + j + k == x)
                            a++;
                    }
                }
            }
            System.out.println(a);
        }
    }
}
                    

        


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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

const int MAX_N = 305;
const int MAX_M = 305;

int N, M;
int A[MAX_N][MAX_M];

int ans = 1145141919;

unordered_set<int> us;

int tmpM[MAX_M];

void solve()
{
  if(us.size()==0) {
    return;
  }
  
  memset(tmpM, 0, sizeof(tmpM));

  for(int i = 0; i < N; i++) {
    int j = 0;
    for(; j < M; j++) {
      if(us.find(A[i][j]) != us.end()) {
	break;
      }
    }
    tmpM[A[i][j]]++;
  }

  int s = 0;
  int index = -1;
  for(int i = 0; i < M; i++) {
    if(s < tmpM[i]) {
      s = tmpM[i];
      index = i;
    }
  }

  ans = min(ans, s);
  us.erase(index);
  solve();
}

int main()
{
  cin >> N >> M;
  for(int n = 0; n < N; n++) {
    for(int m = 0; m < M; m++) {
      cin >> A[n][m]; A[n][m]--;
    }
  }

  for(int i = 0; i < M; i++) {
    us.insert(i);
  }

  solve();

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int MAXN = 200000 + 10;
const int INF = 2*MAXN;
int n;
int pos[MAXN];

struct Tree {
    vector<int> t;
    int siz;

    void build(vector<int> p) {
        int n = p.size();
        siz = 1;
        while (siz < n) siz *= 2;
        t.resize(2*siz);

        for (int i = 0; i < n; i++) {
            t[i+siz] = p[i];
        }

        int x = siz/2;

        while (x) {
            for (int i = x; i < 2*x; i++) {
                t[i] = min(t[2*i], t[2*i+1]);
            }
            x/=2;
        }

    }
    int query(int a, int b) {
        a += siz;
        b += siz;

        int res = min(t[a], t[b]);
        while (a / 2 != b / 2) {
            if (a%2 == 0) res = min(res, t[a+1]);
            if (b%2 == 1) res = min(res, t[b-1]);

            a/=2;
            b/=2;
        }

        return res;
    }
};

Tree t[2];


int32_t main() {
    ios_base::sync_with_stdio(0);
    cin >> n;

    vector<int> p[2];
    p[0].resize(n, INF);
    p[1].resize(n, INF);

    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        x--;
        pos[x] = i;
        if (i%2 == 0) p[0][i] = x;
        else p[1][i] = x;
    }

    t[0].build(p[0]);
    t[1].build(p[1]);

    set<int> mins;
    set<pair<pair<int,int>, int>> inter;

    mins.insert(t[0].query(0, n-1));
    inter.insert({{0, n-1},0});

    for (int i = 0; i < n/2; i++) {
        int q = *mins.begin();
        int poz = pos[q];
        mins.erase(mins.begin());
        
        auto init = inter.lower_bound({{poz, INF},INF});
        init--;
        auto in = *init;

        int a = in.first.first;
        int b = in.first.second;
        int typ = in.second;
        

        int r = t[1-typ].query(poz+1, b);
        int poz2 = pos[r];

        inter.erase(init);

        if (a < poz-1){
            inter.insert({{a, poz-1}, typ});
            mins.insert(t[typ].query(a, poz-1));
        }
        if (poz+1 < poz2-1) {
            inter.insert({{poz+1, poz2-1}, 1-typ});
            mins.insert(t[1-typ].query(poz+1, poz2-1));
        }
        if (poz2+1 < b) {
            inter.insert({{poz2+1, b}, typ});
            mins.insert(t[typ].query(poz2+1, b));
        }

        cout << q + 1 << " " << r + 1 << " ";
    }

    cout << "\n";



    return 0;
}


Measured memory_bytes: 18916
import Queue
n,k = map(int,raw_input().split())
arr = map(int,raw_input().split())

counts = {}
for i in arr:
	if i not in counts:
		counts[i] = 1
	else :
		counts[i] += 1

queue = Queue.PriorityQueue()

for i in counts.values():
	queue.put(i)

ans = 0
while queue.qsize() > k :
	ans += queue.get()

print ans

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

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

int H,W,K;
char t[1000][1000];
int d[1000][1000];

int si,sj;

void bfs(){

  int ans=1e9;
  
  for(int i=0;i<H;i++)
    for(int j=0;j<W;j++)
      d[i][j]=1e9;
  
  queue<int> qy,qx;
  qy.push(si);
  qx.push(sj);
  d[si][sj]=0;
  
  while(!qy.empty()){
    int y=qy.front();
    qy.pop();
    int x=qx.front();
    qx.pop();

    if(d[y][x]>K)continue;
    
    int f=min(y,x);
    f=min(f,H-1-y);
    f=min(f,W-1-x);

    if(f==0)ans=1;
    
    ans=min(ans,1 + (f+K-1)/K);
    for(int i=0;i<4;i++){
      int ny=y+dy[i];
      int nx=x+dx[i];
      if(ny<0||nx<0||ny>=H||nx>=W)continue;
      if(t[ny][nx]=='#')continue;
      int ncost=d[y][x]+1;
      if(d[ny][nx]>ncost){
        d[ny][nx]=ncost;
        qy.push(ny);
        qx.push(nx);
      }
    }
  }
  /*
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cout<<d[i][j]<<' ';
    }
    cout<<endl;
  }
  */
  cout<<ans<<endl;
}

int main(){
  cin>>H>>W>>K;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin>>t[i][j];
      if(t[i][j]=='S'){
        si=i;
        sj=j;
      }
    }
  }
  bfs();
  return 0;
}


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


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

for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
        sum=sum+a[i]*a[j];
    }
}
cout<<sum<<endl;
return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int page[101][101];
    int r,c;
    int i,j;
    int sum;
    
    for(i = 0;i < 101;i++){
        for(j = 0;j < 101;j++){
            page[i][j] = 0;
        }
    }
    
    cin >> r >> c;
    
    for(i = 0;i < r;i++){
        for(j = 0;j < c;j++){
            cin >> page[i][j];
        }
    }
    
    for(i = 0;i < r;i++){
        sum = 0;
        for(j = 0;j < c;j++){
            sum = sum + page[i][j];
        }
        page[i][j] = sum;
    }
    
    for(j = 0;j < c;j++){
        sum = 0;
        for(i = 0;i < r;i++){
            sum = sum + page[i][j];
        }
        page[i][j] = sum;
    }
    
    sum = 0;
    
    for(j = 0;j < c;j++){
        sum = sum + page[r][j];
    }
    page[r][c] = sum;
    
    for(i = 0;i <= r;i++){
        for(j = 0;j <= c;j++){
            if(j == c){
                cout << page[i][j];
            }else{
                cout << page[i][j] << ' ';
            }
        }
        
        cout << endl;
        
    }
    
    
}


Measured memory_bytes: 3120
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main()
    {
        int s = int.Parse(Console.ReadLine());

        if (s == 1 || s == 2)
        {
            Console.WriteLine(4);
            return;
        }

        int ans = 1;
        while (s > 1)
        {
            if (s % 2 == 1) s = 3 * s + 1;
            else s = s / 2;
            ans++;
        }

        Console.WriteLine(ans + 1);
    }
}

Measured memory_bytes: 13140
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

const int MOD = 1000000007, INF = 1111111111;
using namespace std;
using lint = long long;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (int i = 0; i < (int)vec.size(); i++) {
		os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	}
	return os;
}

#ifdef _DEBUG
template <class Head>
void dump(const char* str, Head &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + 1, t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;

	vector<int> a(N);
	for (int i = 0; i < N; i++) {
		int tmp;
		cin >> tmp;
		tmp--;
		a[i] = tmp;
	}

	int idx = 0;
	for (int i = 0; i < N; i++) {
		if (a[idx] == 1) {
			cout << i + 1 << "\n";
			return 0;
		}
		else idx = a[idx];
	}

	cout << -1 << "\n";

	return 0;
}

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

int main()
{
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if (a + b > c + d)
  	cout << "Left" << endl;
  else if (a + b == c + d)
    cout << "Balanced" << endl;
  else
    cout << "Right" << endl;
}

Measured memory_bytes: 256
import Text.Regex

main::IO()
main = do
  nab<-getLine
  let n:a:b:[] = map read (words nab)::[Int]
  dat<-getLine
  print_n (solver (a+b) b dat)

solver :: Int -> Int -> [Char] -> [String]
solver  _ _ []=[]
solver  x y ('c':rest) = "No":(solver x y rest)
solver  x y ('b':rest) = if (y>0)&&(x>0) then "Yes":(solver (x-1) (y-1) rest) else "No":(solver x y rest)
solver  x y ('a':rest) = if x>0 then "Yes":(solver (x-1) y rest) else "No":(solver x y rest)

print_n :: [String] -> IO()
print_n []=return()
print_n (str:rest) = do
           putStr str
           putStr "\n"
           print_n rest

Measured memory_bytes: 5372
import java.util.*;

class Main {
    public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      int a = sc.nextInt();
      int b = sc.nextInt();
      if((a*b)%2 == 0){
      	System.out.println("Even");
      }else{
      	System.out.println("Odd");
      }
        
    }
}

Measured memory_bytes: 35656
while True:
    n, x = map(int, input().split())
    if n == 0 and x == 0: break
    count = 0
    for a in range(1, n+1):
        for b in range(a+1, n+1):
            for c in range(b+1, n+1):
                if a + b + c == x:
                    count += 1
    print(count)



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

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

    vector<pair<pair<int,int>,int>> data(n);
    for (int i = 0; i < n; i++) {
        cin >> data[i].first.first >> data[i].first.second;
        data[i].second = i;
    }
    sort(data.begin(), data.end());

    vector<pair<int,int>> count(n); int id = 0;
    dsu check(n);
    for (int i = 0; i < n; i++) {
        if (id == 0) count[id++] = make_pair(data[i].first.second, data[i].second);
        else {
            auto save = count[id - 1];
            bool change = false;
            while (id > 0 && count[id - 1].first < data[i].first.second) {
                check.merge(count[--id].second, data[i].second);
                change = true;
            }
            if (change) count[id++] = save;
            else count[id++] = make_pair(data[i].first.second, data[i].second);
        }
    }

    for (int i = 0; i < n; i++) cout << check.size(i) << endl;
    return 0;
}

Measured memory_bytes: 8032
#include <iostream>
#include <vector>
using namespace std;
 
#define INF 2147483647 // 2^31-1
 
vector<int> value; // ノードの値を持つ配列
int N;             // 葉の数
 
void update(int i, int x) {
    // i 番目の葉の値を x に変える
    i += N - 1; // i 番目の葉のノード番号
    value[i] = x;
    while (i > 0) {
        i = (i - 1) / 2; // ノード i の親ノードの番号に変える
        value[i] = min(value[i * 2 + 1],
                       value[i * 2 + 2]); // 左右の子の min を計算しなおす
    }
}
 
int query(int a, int b, int k, int l, int r) {
    // [a, b) の区間に対するクエリについて
    // ノード k （区間 [l, r) 担当）が答える
    if (r <= a || b <= l) return INF; // 区間が被らない場合は INF を返す
    if (a <= l && r <= b)
        return value[k]; // ノード k の担当範囲がクエリ区間 [a, b)
                         // に完全に含まれる
    else {
        int c1 = query(a, b, 2 * k + 1, l, (l + r) / 2); // 左の子に値を聞く
        int c2 = query(a, b, 2 * k + 2, (l + r) / 2, r); // 右の子に値を聞く
        return min(c1, c2); // 左右の子の値の min を取る
    }
}
 
int main(void) {
    int n, q;
    cin >> n >> q;
    N = 1;
    while (N < n) N *= 2; // 葉の数を計算（n以上の最小の2冪数）
 
    value = vector<int>(2 * N - 1, INF);
 
    for (int j = 0; j < q; j++) {
        int c;
        cin >> c;
        if (c == 0) {
            // update(i, x)
            int i, x;
            cin >> i >> x;
            update(i, x);
        } else {
            // find(s, t)
            int s, t;
            cin >> s >> t;
            cout << query(s, t + 1, 0, 0, N) << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 4988
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int minIndex = -1, maxIndex = 0;
		for(int i = 0; i < s.length(); i++) {
			char c = s.charAt(i);
			if(c == 'A' && minIndex < 0) minIndex = i;
			else if(c == 'Z' && i > maxIndex) maxIndex = i;
		}
		System.out.println(maxIndex - minIndex + 1);
	}

}


Measured memory_bytes: 26604
let n = 50

let () =
  let k = read_int () in
  let d = k / n in
  let m = k mod n in
  Printf.printf "%d\n" n;
  for i = 0 to n - 1 do
    Printf.printf
      (if i = 0 then "%d" else " %d")
      (d + if i < m then n else n - 1 - m)
  done;
  print_newline ()

Measured memory_bytes: 384
#include <iostream>

 

using namespace std;

 

int main() 
{
    int w, h, x, y, r;
    cin >> w >> h >> x >> y >> r;
    
    if(x-r >= 0 && x+r <= w && y-r >= 0 && y+r <= h)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define int long long int
#define N 200005
void fast(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

main()
{
  int n;
  cin>>n;
  int x=1;
  for(int i=1;i<=n;i++)x*=i;
  double a[100],b[100];
  for(int i=1;i<=n;i++){
    cin>>a[i]>>b[i];
  }
  double ans=0;
  for(int i=1;i<=n;i++){
    for(int j=1;j<=n;j++){
      if(i!=j){
        double aa=sqrt((a[i]-a[j])*(a[i]-a[j])+(b[i]-b[j])*(b[i]-b[j]));
        ans+=aa;
        // cout<<ans<<endl;
      }
    }
  }
  ans*=(x)/(n);
  // cout<<ans<<" "<<x<<endl;
  ans=ans/(double)x;
  printf("%.10lf\n",ans);
}

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

using namespace std;

typedef long long int ll;

int main(){
  vector <ll> x(5);
  int pos{};
  for(int i = 0;i<5;i++){
    cin>>x[i];
    if (x[i]==0) pos = i+1;
  }
  cout<<pos<<endl;
}

Measured memory_bytes: 3624
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] a = new int[n];
    int b = 0;
    int[] c = new int[n-1];
    int bonus = 0;
    for(int i = 0; i < n; i++){
      a[i] = sc.nextInt();
    }
    for(int i = 0; i < n; i++){
      b += sc.nextInt();
    }
    for(int i = 0; i < n - 1; i++){
      c[i] = sc.nextInt();
    }
    for(int i = 0; i < n - 1; i++){
      if(a[i + 1] - a[i] == 1){
        bonus += c[a[i] - 1];
      }
    }
    System.out.println(b + bonus);
  }
}


Measured memory_bytes: 22868
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if (x < y) x = y; }

string solve(int A, int B, int C, int D) {
	amax(C, 0);
	amin(D, A + B);
	if (C >= D) return "";
	if (A < B) {
		string S = solve(B, A, A + B - D, A + B - C);
		for (auto &c : S) c = c == 'A' ? 'B' : 'A';
		reverse(S.begin(), S.end());
		return S;
	}
	int x = (A + B) / (B + 1);
	string S;
	reu(i, C, D) {
		S += i % (x + 1) == x ? 'B' : 'A';
	}
	auto fillChar = [&S,A,B,C,D](int num, int len, char c) {
		if (len <= 0) return;
		int L = A + B - num - len, R = A + B - num;
		reu(i, max(L, C), min(R, D)) {
			S[i - C] = c;
		}
	};
	//cerr << S << endl;
	int rem = B - (A + B) / (x + 1);
	if (rem != 0) {
		int t = rem / (x - 1), u = rem % (x - 1);
		// k > (A + B - D) / (x + 1)
		int kL = max(0, (A + B - D) / (x + 1));
		if ((A + B) % (x + 1) != x) {
			reu(k, kL, min(t, kL + (D - C))) {
				fillChar(k * (x + 1), x, 'B');
			}
			int m = (A + B - 1 - (u - 1)) % (x + 1);
			if(m + (u - 1) >= x) ++ u;
			fillChar(t * (x + 1), u, 'B');
		} else {
			reu(k, kL, min(t, kL + (D - C))) {
				fillChar(k * (x + 1), x + 1, 'B');
				fillChar(k * (x + 1) + (u == 0 && k == t - 1 ? x - 1 : x), 1, 'A');
			}
			fillChar(t * (x + 1), u, 'B');
		}
	}
	return S;
}

int main() {
	int T;
	scanf("%d", &T);
	for (int ii = 0; ii < T; ++ ii) {
		int A; int B; int C; int D;
		scanf("%d%d%d%d", &A, &B, &C, &D), -- C;
		string ans = solve(A, B, C, D);
		puts(ans.c_str());
	}
	return 0;
}


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

using namespace std ;

int  main () {

    long n,m;

    cin >> n>>m;
    vector<vector<long>> arr(n);

    for (int i=0;i<n;i++) {

        long a;
        cin >> a;
        arr[i].push_back(a);
    }

    for (int i =0;i<m;i++) {
        long a ,b ;
        cin >> a >>b;
        arr[a-1].push_back(b-1);
        arr[b-1].push_back(a-1);
        // if(arr[a-1][1]==0) {
        //     arr[a-1][1] = b-1;
        // } 
        // else if(arr[a-1][1]!=(b-1))  arr[a-1][2] = b-1;
        
        // if(arr[b-1][1]==0) {
        //     arr[b-1][1] = a-1;
        // } 
        // else if (arr[b-1][1]!=( a-1)) arr[b-1][2] = a-1;
    }

    long count =0;

    for( int i =0; i<n;i++) {
    //     long a,b;
    //     a =arr[i][1];
    //     b = arr[i][2];

    //     if(a ==0) count ++;
    //     else if (a!=0 && b!=0) {
    //         if ( (arr[i][0] > arr[a][0])  && (arr[i][0] > arr[b][0])) count ++;
    //     }
    //     else if (a!=0) {
    //         if ( (arr[i][0] > arr[a][0])) count++;
    //     }
            int j;
        for (  j =1 ;j <arr[i].size();j++) {
            if((i!=arr[i][j]) && arr[i][0] <= arr[arr[i][j]][0]) break;
        }
        if (j == arr[i].size()) count++;
    }
    cout << count;
    return 0;
}

Measured memory_bytes: 10916