akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>

using namespace std;

int main() {
	string num;
	int sum;
	while (1) {
		getline(cin, num);
		if (num == "0") {
			break;
		}
		sum = 0;
		for (int i = 0; i < num.size(); i++) {
			sum += (num[i] - '0');
		}
		cout << sum << endl;
	}
	
	
	return 0;
}


Measured memory_bytes: 3172
// Fri Aug 21 19:35:37 IST 2020      
#include <bits/stdc++.h>        
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define forn(ii,a,b)       for(int ii = (int)a ; ii < (int)b  ; ii++ )
#define scan(any)          for(auto &i:any) cin>>i;
#define debug(x)           cerr << #x << " " << x << " -- \n"
#define I__O               ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define int64              long long   
#define all(x)             (x).begin(),(x).end() 
#define ff                 first
#define ss                 second
#define pppp               pair <int,int> 
#define flushOff           fflush(stdout) 
#define precise(x)         cout << fixed << setprecision(12) << x << '\n'; 
using namespace std ;    
// policy based   
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set ; 
 
const int MOD1 = 1e9+7;
const int MOD2 = 1e9+9;
const double pi = 3.141592653589793238;
const int N = 1e5+7; 
const int INF = 2e9;
const int64 reallyBig = 1e16+7;

struct compare{
    bool operator()(pair <int,int> A, pair <int,int> B){
        if(A.first == B.first)
            return A.second > B.second;
        return A.first > B.first;
    }
}; 

int tests(){    
    int n;
    cin >> n;
    vector <int> a(n);
    for(auto &x : a){
        cin >> x;
    }
    int64 ans = 0;
    int mex = a[0];
    forn(i,1,n){ 
        ans += (int64)max((int64)(mex-a[i]),0LL);
        mex = max(mex,a[i]);
    }
    cout << ans << '\n';
    return 0;
}
int main(){
    I__O ;      
    int cases = 1 ;  
    // cin >> cases ;
    while(cases--)
        tests(); 
    return 0 ; 
}
 

Measured memory_bytes: 3988
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	int A, B, M;
	cin >> A >> B >> M;
	vector<int> a(A);
	vector<int> b(B);
	vector<int> x(M);
	vector<int> y(M);
	vector<int> c(M);
	for (int i = 0; i < A; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < B; i++) {
		cin >> b[i];
	}
	for (int i = 0; i < M; i++) {
		cin >> x[i] >> y[i] >> c[i];
	}
	int value = 1000000;
	for (int i = 0; i < M; i++) {
		value = min(value, a[x[i] - 1] + b[y[i] - 1] - c[i]);
	}
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	value = min(value, a[0] + b[0]);
	cout << value << endl;
	return 0;
}

Measured memory_bytes: 5080
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int main(){
    cout.precision(10);
    cout << fixed;
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ld l;
    cin >> l;
    ld sol = l*l*l;
    sol = (sol/ld(27));
    cout << sol << endl;
}


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

using namespace std;
int main(){
  int n,m,c;
  cin >> n >> m >> c;
  vector<vector<int>> A(n,vector<int>(m));
  vector<int> B(m);
  for(int i = 0;i < m;i++){
    cin >> B.at(i);
  }
  for(int i = 0;i < n;i++){
    for(int j = 0;j < m;j++){
      cin >> A.at(i).at(j);
    }
  }
  int ans = 0;
  for(int i = 0;i < n;i++){
    int sum = 0;
    for(int j = 0;j < m;j++){
      sum += A.at(i).at(j) * B.at(j);
    }
    if(sum + c > 0){
      ans++;
    }
  }
  cout << ans << endl;

  return 0;
}

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

using namespace std;

#ifdef KACTL
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define sz(x) (int)(x).size()
#endif
#define all(x) begin(x), end(x)

using ll = int64_t;
using ld = long double;
using pii = pair<int32_t, int32_t>;
using vi = vector<int32_t>;

constexpr int MAXN = 55;
int n;
int a[MAXN], b[MAXN];

bool dp[2][MAXN][MAXN];

bool can(ll mask) {
    memset(dp, 0, sizeof(dp));
    for (int i = 0; i <= 50; ++i) {
        dp[0][i][i] = true;
    }

    for (ll j = 50; j > 0; --j) {
        if ((mask & (1LL << j)) == 0)
            continue;

        memcpy(dp[1], dp[0], sizeof(dp[1]));

        for (int x = 0; x <= 50; ++x) {
            for (int y = 0; y <= 50; ++y) {
                dp[1][x][y % j] |= dp[0][x][y];
            }
        }

        memcpy(dp[0], dp[1], sizeof(dp[0]));
    }

    for (int i = 0; i < n; ++i) {
        if (!dp[0][a[i]][b[i]])
            return false;
    }

    return true;
}

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

    // 50 => 24 => 11 => 5 => 2 => 1 => 0
    // longest chain is of length 6 or 7
    //
    // would you ever do an op twice? would you ever do x then y where x < y?

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

    ll mask = (1LL << 51LL) - 1;
    if (!can(mask)) {
        cout << -1 << '\n';
        return 0;
    }

    for (ll j = 50; j >= 0; --j) {
        if (can(mask ^ (1LL << j))) {
            mask ^= (1LL << j);
        }
    }

    cout << mask << '\n';

    return 0;
}


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

const int N = 110;

char str[N][N];

int frq[30];

int main() {
	
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	
	int n, m; cin >> n >> m;
	for (int i = 0; i < n; i++) cin >> str[i];
	
	for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) frq[str[i][j] - 'a']++;
	for (int i = 0; i < 30; i++) frq[i] %= 4;
	
	int cnt = 0;
	for (int i = 0; i < 30; i++) if (frq[i] & 1) cnt++;
	if (cnt > 1) {
		cout << "No\n";
		return 0;
	}
	int tot = 0;
	for (int i = 0; i < 30; i++) tot += frq[i];
	
	int chk = 0;
	if (m & 1) chk += n;
	if (n & 1) chk += m;
	if (m % 2 && n % 2) chk--;
	
	cout << ((chk >= tot) ? "Yes" : "No") << "\n";
	
	return 0;
}


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

using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++ )

int main()
{
  int a, b, c;
  cin >> a >> b >> c;
  if(b - a == c - b) cout << "YES\n";
  else cout << "NO\n";
}

Measured memory_bytes: 256
import collections
s = input()
anss = collections.defaultdict(int)
ans = 100
alp = 'abcdefghijklmnopqrstuvwxyz'
for i in alp:
    cnt = 0
    for j in s:
        if i == j:
            anss[i] = max(cnt, anss[i])
            cnt = 0
        else:
            cnt += 1
    anss[i] = max(cnt, anss[i])
    
for c in anss.values():
    if ans > c:
        ans = c
print(ans)

Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF 1000000000
#define MOD 1000000007

int main(){
    int N; cin >> N;
    vector<int> H(N);
    for(int &h:H)
        cin >> h;
    
    vector<int> dp(N);
    dp[1] = abs(H[1] - H[0]);
    for(int i=2; i<N; i++){
        dp[i] = min(dp[i-2]+abs(H[i]-H[i-2]), dp[i-1]+abs(H[i]-H[i-1]));
    }
    
    cout << dp[N-1] << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <numeric>

using namespace std;
long long l[87];
int m[4];
char o[3];

int main(){
   int n;
   cin>>n;
   m[3]=n%10;
   n/=10;
   m[2]=n%10;
   n/=10;
   m[1]=n%10;
   n/=10;
   m[0]=n;
   for(int b=0;b<(1<<3);b++){
      int sum=m[0];
      for(int i=0;i<3;i++){
         if(b&1<<i){
            sum+=m[i+1];
            o[i]='+';
         }
         else{
            sum-=m[i+1];
            o[i]='-';
         }
      }
      if(sum==7){
         cout<<m[0]<<o[0]<<m[1]<<o[1]<<m[2]<<o[2]<<m[3]<<'='<<7<<endl;
         return 0;
      }
   }
}

Measured memory_bytes: 256
MOD = 10 ** 9 + 7

X, Y = map(int, input().split())

m = 2 * X - Y
n = 2 * Y - X

if m % 3 or n % 3 or m < 0 or n < 0:
    print(0)
    quit()

m //= 3
n //= 3

factorial = [1] * (n + m + 1)
for i in range(n + m):
    factorial[i + 1] = factorial[i] * (i + 1) % MOD

print(factorial[m + n] * pow(factorial[m], MOD - 2, MOD) * pow(factorial[n], MOD - 2, MOD) % MOD)


Measured memory_bytes: 29300
import math


def solve(e):
    k = 2 ** 32
    for z in range(100, -1, -1):
        z3 = z * z * z
        if z3 > e:
            continue
        e2 = e - z3

        ylm = int(math.sqrt(e2))
        xzlm = 3 * z * z + 3 * z + 1

        for y in range(ylm, -1, -1):
            y2 = y * y
            if e2 > (y + 1) * (y + 1):
                break
            e3 = e2 - y2

            xylm = 2 * y + 1
            x = e3
            if x > xylm or x > xzlm:
                continue
            k = min(k, x + y + z)
    return k


def main():
    while True:
        a = int(input())

        if a == 0:
            break

        print(solve(a))


if __name__ == '__main__':
    main()



Measured memory_bytes: 5680
import sys
import math
from collections import deque
MAX_INT = int(10e15)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()
N, K = IL()
r, s, p = IL()
t = S()

judge = {'r':p,'s':r,'p':s}

ans = 0
for i in range(N):
  ans += judge[t[i]]

for n in range(K):
  tmp = ''
  cnt = 0
  for i in range(n,N,K):
    if t[i] == tmp:
      cnt += 1
    else:
      if tmp != '':
        ans -= judge[tmp] * (cnt//2)
      tmp = t[i]
      cnt = 1
  else:
    if tmp != '':
      ans -= judge[tmp] * (cnt//2)

print(ans)

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

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

#define mygc(c) (c)=getchar_unlocked()
#define mypc(c) putchar_unlocked(c)

#define ll long long
#define ull unsigned ll

void reader(int *x){int k,m=0;*x=0;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){*x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||k>'9')break;*x=(*x)*10+k-'0';}if(m)(*x)=-(*x);}
void reader(ll *x){int k,m=0;*x=0;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){*x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||k>'9')break;*x=(*x)*10+k-'0';}if(m)(*x)=-(*x);}
void reader(double *x){scanf("%lf",x);}
int reader(char c[]){int i,s=0;for(;;){mygc(i);if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF) break;}c[s++]=i;for(;;){mygc(i);if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF) break;c[s++]=i;}c[s]='\0';return s;}
template <class T, class S> void reader(T *x, S *y){reader(x);reader(y);}
template <class T, class S, class U> void reader(T *x, S *y, U *z){reader(x);reader(y);reader(z);}
template <class T, class S, class U, class V> void reader(T *x, S *y, U *z, V *w){reader(x);reader(y);reader(z);reader(w);}

void writer(int x, char c){int s=0,m=0;char f[10];if(x<0)m=1,x=-x;while(x)f[s++]=x%10,x/=10;if(!s)f[s++]=0;if(m)mypc('-');while(s--)mypc(f[s]+'0');mypc(c);}
void writer(ll x, char c){int s=0,m=0;char f[20];if(x<0)m=1,x=-x;while(x)f[s++]=x%10,x/=10;if(!s)f[s++]=0;if(m)mypc('-');while(s--)mypc(f[s]+'0');mypc(c);}
void writer(double x, char c){printf("%.15f",x);mypc(c);}
void writer(const char c[]){int i;for(i=0;c[i]!='\0';i++)mypc(c[i]);}
void writer(const char x[], char c){int i;for(i=0;x[i]!='\0';i++)mypc(x[i]);mypc(c);}
template<class T> void writerLn(T x){writer(x,'\n');}
template<class T, class S> void writerLn(T x, S y){writer(x,' ');writer(y,'\n');}
template<class T, class S, class U> void writerLn(T x, S y, U z){writer(x,' ');writer(y,' ');writer(z,'\n');}
template<class T> void writerArr(T x[], int n){int i;if(!n){mypc('\n');return;}rep(i,n-1)writer(x[i],' ');writer(x[n-1],'\n');}

char memarr[17000000]; void *mem = memarr;
#define MD 1000000007

int N; char S[200010];

int main(){
  int i, j, k;

  N = reader(S);
  k = 0;
  rep(i,N){
    if(S[i]=='S'){
      k++;
    } else if(k > 0){
      k--;
    }
  }
  writerLn(k*2);

  return 0;
}


Measured memory_bytes: 384
N=int(input())
A=list(map(int,input().split()))
dic={}
for a in A:
  if a in dic.keys():
    dic[a]+=1
  else:
    dic[a]=1
r=0
for a in dic.keys():
  c=dic[a]
  r+=c*(c-1)//2
for i in range(N):
  c=dic[A[i]]
  print(r - c*(c-1)//2 + (c-1)*(c-2)//2 )


Measured memory_bytes: 26268
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define INF 10000000001
#define DIM 200001
#define mod 1000000007
#define PI 3.1415926535897932384626433
#define se second
#define fi first
#define pb push_back
#define gg exit(0)
#define T true
#define F false
#define endl "\n"
typedef char ch;
typedef bool boll;
typedef string st;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef set < string > sst;
typedef set < long long > sl;
typedef queue < long long > que;
typedef vector < long long > vec;
typedef map < long long, long long > mll;
typedef pair < long long, long long > pll;
typedef vector < pair < long long, long long > > vpl;
typedef pair < long long, unsigned long long > pul;
ll n,z,a[11],b[11],c[11],x1,x2;
int main()
{
    cin>>n;
    for(int i=1; i<=n; i++)cin>>a[i],c[i]=i;
    z=1;
    while(next_permutation(c+1,c+1+n))
    {
        ll f=0;
        for(int i=1; i<=n; i++)
        {
            if(c[i]!=a[i])f=1;
        }
        if(f==0)
        {
            x1=z;
            break;
        }
        z++;
    }
    for(int i=1; i<=n; i++)cin>>b[i],c[i]=i;
    z=1;
    while(next_permutation(c+1,c+1+n))
    {
        ll f=0;
        for(int i=1; i<=n; i++)if(c[i]!=b[i])f=1;
        if(f==0)
        {
            x2=z;
            break;
        }
        z++;
    }
    cout<<abs(x1-x2)<<endl;
}


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

#define Abigail inline void
typedef long long LL;

const int N=100000,C=30,mod=1000000007;

int add(int a,int b){return a+b>=mod?a+b-mod:a+b;}
int sub(int a,int b){return a-b<0?a-b+mod:a-b;}
int mul(int a,int b){return (LL)a*b%mod;}
void sadd(int &a,int b){a=add(a,b);}
void ssub(int &a,int b){a=sub(a,b);}
void smul(int &a,int b){a=mul(a,b);}

int n,m;
int pr[C+9],cnt[C+9],cp;

void Get_pr(int n){
  int now=n;
  for (int i=2;i*i<=n;++i)
    if (now%i==0)
    	for (pr[++cp]=i;now%i==0;now/=i) ++cnt[cp];
  if (now>1) pr[++cp]=now,cnt[cp]=1;
}

int inv[N+C+9],fac[N+C+9],ifac[N+C+9];

void Get_inv(int n){
  inv[1]=1;
	fac[0]=fac[1]=1;
	ifac[0]=ifac[1]=1;
  for (int i=2;i<=n;++i){
  	inv[i]=mul(mod-mod/i,inv[mod%i]);
  	fac[i]=mul(i,fac[i-1]);
  	ifac[i]=mul(inv[i],ifac[i-1]);
	}
}

int Get_c(int n,int m){return mul(fac[n],mul(ifac[m],ifac[n-m]));}

int ans;

Abigail into(){
  scanf("%d%d",&n,&m);
}

Abigail work(){
  Get_pr(m);
  Get_inv(n+C);
  ans=1;
  for (int i=1;i<=cp;++i)
    smul(ans,Get_c(n+cnt[i]-1,cnt[i]));
}

Abigail outo(){
  printf("%d\n",ans);
}

int main(){
  into();
  work();
  outo();
  return 0;
}

Measured memory_bytes: 1536
main2(){
  int c,d,_d,x,i,j;
  char n[1001],u[51];
  for(x=d=-1,i=0;(c=getchar())!=' ';i++){
    if(c=='.'){i--;_d=d=i;continue;}
    if(x<0&&c!='0')x=i;
    n[i]=c;
  }
  if(d==-1)_d=d=i-1;

  scanf("%s",u);
if(!strcmp(u,"yotta"))d+=24;
if(!strcmp(u,"zetta"))d+=21;
if(!strcmp(u,"exa"))d+=18;
if(!strcmp(u,"peta"))d+=15;
if(!strcmp(u,"tera"))d+=12;
if(!strcmp(u,"giga"))d+=9;
if(!strcmp(u,"mega"))d+=6;
if(!strcmp(u,"kilo"))d+=3;
if(!strcmp(u,"hecto"))d+=2;
if(!strcmp(u,"deca"))d+=1;
if(!strcmp(u,"yocto"))d+=-24;
if(!strcmp(u,"zepto"))d+=-21;
if(!strcmp(u,"ato"))d+=-18;
if(!strcmp(u,"femto"))d+=-15;
if(!strcmp(u,"pico"))d+=-12;
if(!strcmp(u,"nano"))d+=-9;
if(!strcmp(u,"micro"))d+=-6;
if(!strcmp(u,"milli"))d+=-3;
if(!strcmp(u,"centi"))d+=-2;
if(!strcmp(u,"deci"))d+=-1;
  if(d!=_d)scanf("%s",u);
getchar();
  putchar(n[x]);
  if(x+1<i)putchar('.');
  for(j=x+1;j<i;j++)
    putchar(n[j]);
  printf(" * 10^%d %s\n",d-x,u);
  return 0;
}
main(n){for(scanf("%d",&n),getchar();n--;)main2();exit(0);}

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

using namespace std;


int main(){
	string S;
	int K;
	cin >>K>>S;
	if(S.size() <= K){
		cout <<S;
	}else{
		cout <<S.substr(0,K)<<"...";
	}
	cout <<endl;
	return 0;
}

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

typedef long long ll;

ll calc( vector<ll> &a, vector<ll> &b, ll x ) {
  ll ans = 1e18;
  for ( int j = 0; j < 2; j++ ) {
    int apos = lower_bound(a.begin(),a.end(),x)-a.begin();
    ll ax = a[apos-j];
    for ( int k = 0; k < 2; k++ ) {
      int bpos = lower_bound(b.begin(),b.end(),ax)-b.begin();
      ll bx = b[bpos-k];
      ll d = abs(x-ax)+abs(ax-bx);
      ans = min(d,ans);
    }
  }
  return ans;
}

int main() {
  int A,B,Q; cin >> A >> B >> Q;
  vector<ll>s(A+2),t(B+2);
  ll x[100010];
  s[0] = t[0] = -1e18;

  for ( int i = 1; i <= A; i++ ) cin >> s[i];
  for ( int i = 1; i <= B; i++ ) cin >> t[i];
  for ( int i = 0; i < Q; i++ ) cin >> x[i];

  s[A+1] = t[B+1] = 1e18;

  for ( int i = 0; i < Q; i++ ) {
    cout << min(calc(s,t,x[i]),calc(t,s,x[i])) << endl;
  }
  return 0;
}


Measured memory_bytes: 3712
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {
	
	static int w, h;
	static boolean[][] rWall, dWall;
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while (true) {
			w = sc.nextInt();
			h = sc.nextInt();
			if (w == 0 && h == 0) break;
			
			rWall = new boolean[h][w - 1];
			dWall = new boolean[h - 1][w];
			for (int i = 0; i < h - 1; i++) {
				for (int j = 0; j < w - 1; j++) {
					if (sc.nextInt() == 1) rWall[i][j] = true;
				}
				for (int j = 0; j < w; j++) {
					if (sc.nextInt() == 1) dWall[i][j] = true;
				}
			}
			for (int j = 0; j < w - 1; j++) {
				if (sc.nextInt() == 1) rWall[h - 1][j] = true;
			}
			
			System.out.println(bfs(0, 0, w - 1, h - 1));
		}
		
		sc.close();
	}
	
	static int bfs(int sx, int sy, int gx, int gy) {
		Deque<int[]> q = new ArrayDeque<>();
		boolean[][] visited = new boolean[h][w];
		q.offer(new int[] { sx, sy, 1 });
		while (!q.isEmpty()) {
			int[] now = q.poll();
			if (now[0] == gx && now[1] == gy) return now[2];
			visited[now[1]][now[0]] = true;
			if (0 <= now[0] - 1 && !visited[now[1]][now[0] - 1] && !rWall[now[1]][now[0] - 1]) {
				visited[now[1]][now[0] - 1] = true;
				q.offer(new int[] { now[0] - 1, now[1], now[2] + 1 });
			}
			if (now[0] + 1 < w && !visited[now[1]][now[0] + 1] && !rWall[now[1]][now[0]]) {
				visited[now[1]][now[0] + 1] = true;
				q.offer(new int[] { now[0] + 1, now[1], now[2] + 1 });
			}
			if (0 <= now[1] - 1 && !visited[now[1] - 1][now[0]] && !dWall[now[1] - 1][now[0]]) {
				visited[now[1] - 1][now[0]] = true;
				q.offer(new int[] { now[0], now[1] - 1, now[2] + 1 });
			}
			if (now[1] + 1 < h && !visited[now[1] + 1][now[0]] && !dWall[now[1]][now[0]]) {
				visited[now[1] + 1][now[0]] = true;
				q.offer(new int[] { now[0], now[1] + 1, now[2] + 1 });
			}
		}
		return 0;
	}
}

Measured memory_bytes: 67696
#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>
#define int long
#define ll long long
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define mk make_pair
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int N,M; cin >> N >> M;
    int ans = 0;
    ans += (4-N>0?(4-N)*100000:0)+(4-M>0?(4-M)*100000:0);
    if(N==1 && M==1) ans+=400000;
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <stdio.h>
 
int gcd(a,b){
  if (b==0){
    return a;
  }
  if (a<b){
    return gcd(a,b%a);
  }else{
    return gcd(b,a%b);
  }
}
 
int main()
{
  int a,b;
  scanf("%d",&a);
  scanf("%d",&b);
  printf("%d\n",gcd(a,b));
 
  return 0;
}



Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
typedef vector<int> VI;
typedef vector<ll> VLL;

int main(){
    int a,b;
    cin >> a >> b;
    if(b%a == 0)cout << a+b << endl;
    else cout << b-a << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <iterator>
#include <stack>
#include <string.h>
#include <cstdlib>
#include <queue>
#include <list>
#include <string>

using namespace std;

#define eps 0.0000004

int main()
{
    long double a,b,x;
    long double m;
    
    cin >> a >> b >> x;
    
    if (2*x ==  a*a*b){
        cout << 45.000000 << endl;
    }
    else if (2*x < a*a*b){
        long double l = 0;
        long double r = 90.0000000;
        while (r-l >= eps){
            m = (long double) (r+l)/2;
            if ((long double)2.0000000*(long double)x*(long double)tan(((long double)m*3.141592653589/((long double) 180.0000000))) > (long double)a*(long double)b*(long double)b){
                r = m;
            }
            else {
                l = m;
            }
        }
        printf("%.8Lf\n",l);
    }
    else if (x == a*a*b){
        cout << 0 << endl;
    }
    else {
        long double l = 0.0000000;
        long double r = 90.0000000;
        while (r-l >= eps){
            m = (long double) (l+r)/2;
            if ((long double)a*(long double)a*(long double)a*(long double)tan((long double)((long double)m*3.141592653589)/(long double) 180.00000000) > (long double)2.0000000*(a*a*b-x)){
                r = m;
            }
            else {
                l = m;
            }
        }
        printf("%.8Lf\n",l);
    }
}



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

using namespace std;

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

    int ans = 0;

    while(true) {
        bool exist_odd = false;
        for (int i = 0; i < n; ++i) {
            if (a[i] % 2 != 0) exist_odd = true;
        }

        if (exist_odd)  break;

        for (int i = 0; i < n; ++i) {
            a[i] /= 2;
        }
        ++ans;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdlib>  // abs() for integer 絶対値求めやつ
#include <cmath>    // abs() for float, and fabs()
#include <algorithm>
#include <vector>
#include <string>
#include<iomanip>//浮動小数点数を出力する制度の指定
//使い方　数値をnumとして　cout<<setprecision(n)<<num ;nは桁数
#define rep(i,n) for(int i = 0; i < (n);i++)
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
using namespace std;
using ll =long long;
using db = double;
#define INF 2000000000
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; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
/*覚えてないことメaモ
数値型から文字列に変換　to_string(number);これは簡単
文字列から数値型に変換　stoi(number)
文字列からllに変換　stoll(number)
__gcd(a,b)は最大公約数を取ってくれる、aとb
の大きい方をNとしたとき、計算量は log(N);
*/
const int mod = 1e9 + 7;

//ここから書き始める
int main(){
	int n ;// nは整数
	cin >> n; // 毎回入力するのをテンプレートに
	vector<int> v(n); //使うならrepで入力すること
	
	int b;  cin >> b;
	int now = n - 2*b;
	int ans = max(0, now);
	cout << ans << endl;
		
}


Measured memory_bytes: 256
import sys
import numpy as np


def count_water(np_arr):
  if not np_arr.any():
    return 0
  least = min(np_arr)
  div_p = np.where(np_arr == least)[0][0]
  np_arr -= least
  return least + count_water(np_arr[:div_p]) + count_water(np_arr[div_p + 1:])


def main():
  readline = sys.stdin.readline
  
  n = int(readline().rstrip())
  h = np.array(tuple(int(_) for _ in readline().rstrip().split()))
  
  print(count_water(h))

 
if __name__ == "__main__":
  main()


Measured memory_bytes: 12388
#include <stdio.h>

int main() {

	int A, B;
	int total = 0;

	scanf("%d %d", &A, &B);

	if (A > B) {
		total = A;
		total = total + (A - 1);
	}
	else if (A == B) {
		total = A;
		total = total + B;
	}
	else {
		total = B;
		total = total + (B - 1);
	}

	printf("%d\n", total);

	return 0;
}

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

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

    int n;
    cin >> n;

    vector<ll> a(n);
    REP(i, n) cin >> a[i];

    vector<ll> sumL(n + 1, 0);
    REP(i, n) sumL[i + 1] = sumL[i] + a[i];

    reverse(a.begin(), a.end());

    vector<ll> sumR(n + 1, 0);
    REP(i, n) sumR[i + 1] = sumR[i] + a[i];

    reverse(sumR.begin(), sumR.end());

    ll mini = INT_MAX;
    for (int i = 1; i < n; i++)
        mini = min(mini, abs(sumL[i] - sumR[i]));

    cout << mini << '\n';
    return 0;
}


Measured memory_bytes: 4992
#include <algorithm> // sort
#include <iostream>
 using namespace std;

 int N, K, p[1010];

 int main(){
 cin >> N >> K;
 for(int i = 0; i < N; ++i) cin >> p[i];
 sort(p, p + N);
 int ans = 0;
 for(int i = 0; i < K; ++i) ans += p[i];
 cout << ans << endl;
 }

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
main()
{
    long long int n,i,j,count=0;
    cin>>n;
    long long int a[n+1];
    for (i=0;i<n;i++) cin>>a[i];
    for (i=0;i<n;i++)
    {
        for (j=n-1;j>i;j--)
        {
            if (a[j]<a[j-1]) {
                    swap(a[j],a[j-1]);
                    count++;
            }
        }
    }
    for (i=0;i<n;i++) {
            if (i==n-1) cout<<a[i]<<endl;
        else cout<<a[i]<<" ";
    }
    cout<<count<<endl;
    return 0;
}

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

int main(void){
    vector<int> A(3);
    for(int i=0; i<3; i++){
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    int k; cin >> k;
    for(int i=0; i<k; i++){
        A[2]*=2;
    }

    cout << A[0]+A[1]+A[2] << endl;

}

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

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

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep_op(i, a, b) for (int i = a; i < b; i++)
#define rep_d(i, n) for (int i = n; i >= 0; i--)


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

const int MOD = 1000000007;

// int max = *std::max_element(vec.begin(), vec.end());
// int sum = accumulate(list, list + size, 0);

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    string s; cin >> s;
    ll n = s.length() + 1;
    vector<ll> a(n, 0);
    rep(i, n-1) {
        if (s[i] == '<') {
            a[i+1] = max(a[i+1], a[i]+1);
        }
    }
    rep_d(i, n-2) {
        if (s[i] == '>') {
            a[i] = max(a[i], a[i+1]+1);
        }
    }
    ll ans = 0;
    rep (i, n) ans += a[i];
    cout << ans << endl;
} 


Measured memory_bytes: 4764
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n-1); i >= 0; i--)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;

map<ll,ll>prime_factor(int m)
{
  map<ll,ll>res;
  ll sqrm=sqrt(m)+1;
  for(int i=2;i<sqrm+1;i++)
  {
    while(m%i==0){res[i]++;m/=i;}
    if(m==1)break;
  }
  if(m>1)res[m]++;
  return res;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,k;cin>>n>>k;
  vector<ll>a(n);
  ll sa=0;
  rep(i,n){
    cin>>a[i];
    sa+=a[i];
  }

  auto check=[&](ll num){
    map<ll,ll>cnt;
    rep(i,n){
      cnt[a[i]%num]++;
    }
    vector<pair<ll,ll>>cn;
    for(auto tp:cnt){
      cn.push_back(tp);
    }
    ll l=cn.size();
    ll ts=0;
    rep(i,l){
      if(2*cn[i].first>num)cn[i].first-=num;
      ts+=cn[i].first*cn[i].second;
    }
    ts/=num;
    sort(all(cn),[&](pair<ll,ll> a,pair<ll,ll> b){return abs(abs(2*a.first)-num)<abs(abs(2*b.first)-num);});
    ll tk=0;
    auto tcn=cn;
    rep(i,l)tcn[i].second=0;
    if(ts<0){
      rep(i,l){
        if(cn[i].first>0)continue;
        ll td=min(-ts,cn[i].second);
        ts+=td;
        cn[i].second-=td;
        tcn[i].first=cn[i].first+num;
        tcn[i].second=td;

        if(ts==0){
          break;
        }
      }
    }
    else if(ts>0){
      rep(i,l){
        if(cn[i].first<0)continue;
        ll td=min(ts,cn[i].second);
        ts-=td;
        cn[i].second-=td;
        tcn[i].first=cn[i].first-num;
        tcn[i].second=td;

        if(ts==0){
          break;
        }
      }
    }
    rep(i,l){
      tk+=abs(cn[i].first)*cn[i].second+abs(tcn[i].first)*tcn[i].second;
      ////cout<<cn[i].first<<" "<<cn[i].second<<" "<<tcn[i].second<<endl;
    }
    //cout<<"num "<<num<<" tk "<<tk<<endl;
    return tk<=k*2;

  };
  vector<ll>so;
  //cout<<sa<<endl;
  for(ll i=1;i*i<=sa;i++){
    if(sa%i==0){
      //cout<<i<<sa%i<<endl;
      so.push_back(i);
      if(i*i!=sa){
        so.push_back(sa/i);
      }
    }
  }
  sort(all(so));
  rrep(i,so.size()){
    ll res=so[i];
    if(check(res)){
      cout<<res<<endl;
      return 0;
    }
  }



  return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const long long INF=1e18+10;
const int inf=1e9+10,dx[]= {0,0,1,-1,1,-1,1,-1},dy[]= {1,-1,0,0,1,1,-1,-1};
ll MOD=1e9+7;
ld eps=1e-7,pi=acos(-1);

int n,m,x,y,dist[100100];
vector<int>adj[100100];

int dfs(int node)
{
if(dist[node])return dist[node];
int res=0;

for(auto nx:adj[node])
{
res=max(res,dfs(nx));
}

return dist[node]=res+1;
}

int main()
{

scanf("%d %d",&n,&m);

for(int i=0;i<m;i++)
{
scanf("%d %d",&x,&y);
adj[x].push_back(y);
}

int ans=0;

for(int i=1;i<=n;i++)
ans=max(ans,dfs(i));

printf("%d",ans-1);

return 0;
}


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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define dump(x)  cout << #x << " = " << (x) << endl;

typedef long long ll;
typedef pair<int, int> ii;
const int mod = 1e9+7;
const ll INF = 1e18;
const int inf = 1e9;

void solve()
{
  string s; cin>>s;
  vector<int> cnt(26, 0);
  for (int i=0; i<(int)(s.size()); i++) {
    cnt[s[i]-'a']++;
    if (cnt[s[i]-'a']>=2) {
      cout << "no" << endl;
      return;
    }
  }
  cout << "yes" << endl;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define PI (acos(-1))
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
 
const int MOD = 1e9+7;
const int INF = 1001001001;
const ll LINF = 1e18;
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

signed main()
{
  int n,k; cin>>n>>k;
  vi h(n);
  rep(i,n) cin>>h[i];
  vsort(h);
  int ans=INF;
  rep(i,n-k+1) chmin(ans, h[i+k-1]-h[i]);
  cout<<ans<<endl;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>
#include <queue>
#include <set>
#include <bitset>
#include <map>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<long long> vll;
typedef queue<int, int> qii;
typedef pair<int, int> pii;
typedef pair<string, int> psi;

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

//int型を受け取ってその桁数を返す
int check_digits(int n) {
	int digits = 0;
	while (n != 0) {
		n /= 10;
		digits++;
	}
	return digits;
}

//int型を受け取ってその各桁の和を返す
int sum_digits(int n) {
	int sum=0;
	int N = n;
	while (N) {
		sum += N % 10;
		N /= 10;
	}
	return sum;
}


//最大公約数を返す関数
int gcd(int n, int m) {
	while (n != 0) {
		if (n < m) swap(n, m);
		n = n % m;
	}
	return m;
}


//2点間の距離を返す
float dis(int x1, int y1, int x2, int y2) {
	return sqrt(pow(abs(x1 - x2), 2) + pow(abs(y1 - y2), 2));
}

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

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

int main() {
	int n;
	cin >> n;
	string s, t;
	cin >> s >> t;
	
	string ans = "";
	rept(i, s.size()) {
		ans =  ans + s[i] + t[i];
	}

	cout << ans << endl;

	system("pause");
	return 0;
}


Measured memory_bytes: 504
from collections import deque
 
h, w = map(int, input().split())
a = ['#' + input() +  '#' for _ in range(h)]
b = ['#' * (w + 1)] * 2
r = 0
for i in range(1, h + 1):
  for j in range(1, w + 1):
    if a[i - 1][j] == '.':
      b[1: -1] = map(list, a)
      q = deque()
      b[i][j] = 0
      q.append((i, j))
      while(q):
        i, j = q.popleft()
        r = max(r, b[i][j])
        d = 0
        for i1 in range(i - 1, i + 2):
          for j1 in range(j - d, j + 2, 2):                
            if b[i1][j1] == '.':
              b[i1][j1] = b[i][j] + 1
              q.append((i1, j1))
          d ^= 1
print(r)

Measured memory_bytes: 3316
//
//  main.cpp
//  A
//
//  Created by Yoshinao Itakura on 2020/08/29.
//  Copyright © 2020 Yoshinao Itakura. All rights reserved.
//


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <map>
#include <cmath>
#include <vector>
#include <set>
#include <algorithm>
#include <queue>
#include <iterator>
using namespace std;

int main(int argc, const char * argv[]) {
    long long D, T, S;
    cin >> D >> T >> S;
    if (D <= T*S) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3632
import itertools

def main():
    n = int(input())
    for _ in range(n):
        s = input()
        ssum = set()
        for i in range(len(s)):
            l = s[:i]
            rl = l[::-1]
            r = s[i:]
            rr = r[::-1]
            ssum.add(l+r)
            ssum.add(r+l)
            ssum.add(rl+r)
            ssum.add(r+rl)
            ssum.add(l+rr)
            ssum.add(rr+l)
            ssum.add(rl+rr)
            ssum.add(rr+rl)
        print(len(ssum))

if __name__ == '__main__':
    main()



Measured memory_bytes: 5728
// koch curve //
// 座席は右×中央 //
// 今回もあまり再帰関数というものと問題のつながりを考えずに図のヒントを頼りにとこうとしたので 
// 書いてる途中で書くべき関数の目標が見えなくなって迷走してしまった 
// アルゴリズムは初めて習うものばかりなので習ったアルゴリズムの意図と構造を把握してからコードを書くべきと反省した //
#include <iostream>
#include <cmath>
#include <cstdio> // printfか何かに必要らしい //
using namespace std;

// 参考にしたコードで構造体を使っていたので練習も兼ねて構造体を使って見る //
typedef struct {
  double x;
  double y;
} vec_t;

void koch(vec_t s, vec_t t, int n){
  if(n == 0){

  }
  else{
    vec_t c_1, c_2, c_3;
    c_1.x = (s.x * 2 / 3) + (t.x / 3);
    c_1.y = (s.y * 2 / 3) + (t.y / 3);
    c_3.x = (t.x * 2 / 3) + (s.x / 3);
    c_3.y = (t.y * 2 / 3) + (s.y / 3);
    c_2.x = (c_1.x + c_3.x) / 2 - (c_3.y - c_1.y) * pow(3, 0.5) / 2;
    c_2.y = (c_1.y + c_3.y) / 2 + (c_3.x - c_1.x) * pow(3, 0.5) / 2;

    koch(s, c_1, n-1);
    printf("%8f %8f\n", c_1.x, c_1.y);
    koch(c_1, c_2, n-1); //
    printf("%8f %8f\n", c_2.x, c_2.y);
    koch(c_2, c_3, n-1);
    printf("%8f %8f\n", c_3.x, c_3.y);
    koch(c_3, t, n-1);
    
    
    
    // この順番には意味があるのか？ //
  }
}

int main()
{
  int N;
  cin >> N;
  vec_t s, t;
  s.x = 0.0;
  s.y = 0.0;
  t.x = 100.0;
  t.y = 0.0;
  printf("%8f %8f\n", s.x, s.y); // はじめにスタート地点を表示 //
  koch(s, t, N);
  printf("%8f %8f\n", t.x, t.y); // 最後に終点の表示 //

  return 0;

}


Measured memory_bytes: 3212
import java.util.*

fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val d = LinkedHashMap<String, Long>()

    for (i in 0 until n) {
        val s = readLine()!!.toCharArray().sorted().joinToString("")
        d[s] = (d[s] ?: 0) + 1
    }
    println(d.values.map { it * (it-1) / 2 }.sum())
}

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

using namespace std;

#ifdef DGC
#include "debug.h"
#else
#define debug(...) 9715
#endif
typedef long long ll;
typedef long double ld;
typedef complex<double> point;
#define F first
#define S second



int main()
{
	#ifdef DGC
		//freopen("a.in", "r", stdin);
		//freopen("b.out", "w", stdout);
	#endif

	ios_base::sync_with_stdio(0), cin.tie(0);

	int a, b;
	cin >> a >> b;

	string c = "";
	string d = "";

	int aa = a, bb = b;
	while (bb--) c += to_string(a);
	while (aa--) d += to_string(b);

	if (c < d)
		cout << c << "\n";
	else
		cout << d << "\n";

	return 0;
}


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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  string s;
  cin>>s;
  string S; 
  bool c=false;
  for(int i=0;i<s.size();i++){
    if(c){
      c=false;
      continue;
    }
    if(i+1<=s.size()&&s[i]=='B'&&s[i+1]=='C'){
      S.push_back('D');
      c=true;
    }
    else S.push_back(s[i]);
  }
  ll memo=0;
  ll ans=0;
  for(int i=0;i<S.size();i++){
    if(S[i]=='A')memo++;
    else if(memo!=0&&S[i]=='D')ans+=memo;
    else memo=0;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 916
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<array>
#include<string>
#include<stack>
#include<queue>
#include<algorithm>
#include<cassert>
#include<functional>
#include<random>
#include<complex>
#include<bitset>
#include<chrono>
#include<boost/multiprecision/cpp_int.hpp>
#define int int64_t
#define uint uint64_t
#define REP(i, a, b) for (int64_t i = (int64_t)(a); i < (int64_t)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define EACH(i, a) for (auto i: a)
#define ITR(x, a) for (auto x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define Min(x) *min_element(ALL(x))
#define Max(x) *max_element(ALL(x))
#define Unique(L) (L.erase(unique(ALL(L)), L.end()))
#define veccat(v1, v2) std::copy((v2).begin(),(v2).end(),std::back_inserter(v1)/*v1の後ろにv2を入れる*/)
#define intmax (std::numeric_limits<int64_t>::max() / 4)
using namespace std;
typedef boost::multiprecision::cpp_int bigint;
const double EPS = 1e-9;
const double PI = acos(-1.0);


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

	int N, K;
	cin >> N >> K;
	string S;
	cin >> S;
	K--;

	if (S[K] == 'A')S[K] = 'a';
	if (S[K] == 'B')S[K] = 'b';
	if (S[K] == 'C')S[K] = 'c';
	cout << S << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n];
        for(int i =0; i<n; i++) {
            a[i] = sc.nextLong();
        }
        long num1 = 0;
        long tmp1 = 0;
        //+-+-
        for(int i=0; i<n; i++) {
            tmp1 += a[i];
            if(i % 2 == 0) {
                if(tmp1 <= 0) {
                    num1 += Math.abs(tmp1) + 1;
                    tmp1 += Math.abs(tmp1) + 1;
                }
            } else {
                if(tmp1 >= 0) {
                    num1 += Math.abs(tmp1) + 1;
                    tmp1 -= Math.abs(tmp1) + 1;
                }
            }
        }

        long num2 = 0;
        long tmp2 = 0;
        //-+-+
        for(int i=0; i<n; i++) {
            tmp2 += a[i];
            if(i % 2 == 0) {
                if(tmp2 >= 0) {
                    num2 += Math.abs(tmp2) + 1;
                    tmp2 -= Math.abs(tmp2) + 1;
                }
            } else {
                if(tmp2 <= 0) {
                    num2 += Math.abs(tmp2) + 1;
                    tmp2 += Math.abs(tmp2) + 1;
                }
            }
        }
        System.out.println(Math.min(num1,num2));
    }
}


Measured memory_bytes: 60188
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 a[] = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(str[i]);
		}
		System.out.println(mergeSort(a, 0, n));
	}

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

	public static long merge(int a[], int left, int mid, int right) {
		long count = 0;
		int n1 = mid - left;
		int n2 = right - mid;
		int L[] = new int[n1 + 1];
		int R[] = new int[n2 + 1];
		for (int i = 0; i < n1; i++) {
			L[i] = a[left + i];
		}
		for (int i = 0; i < n2; i++) {
			R[i] = a[mid + i];
		}
		L[n1] = 1000000000;
		R[n2] = 1000000000;

		for (int i = 0, j = 0, k = left; k < right; k++) {
			if (L[i] <= R[j]) {
				a[k] = L[i];
				i++;
			} else {
				a[k] = R[j];
				j++;
				count += n1 - i;
			}
		}
		return count;
	}

	public static long mergeSort(int a[], int left, int right) {
		long v1, v2, v3;
		if (left + 1 < right) {
			int mid = (left + right) / 2;
			v1 = mergeSort(a, left, mid);
			v2 = mergeSort(a, mid, right);
			v3 = merge(a, left, mid, right);
			return v1 + v2 + v3;
		} else
			return 0;
	}
}


Measured memory_bytes: 61516
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int main(){
  int H,W,D;
  cin>>H>>W>>D;
  int a[H+1][W+1];
  map<int,pair<int,int>>mp;
  for(int i=1; i<=H; i++){
    for(int j=1; j<=W; j++){
      cin>>a[i][j];
      mp[a[i][j]]=make_pair(i,j);
    }
  }
  ll S[H*W+1];
  for(int i=1; i<=H*W; i++){
      S[i+D]=S[i]+(abs(mp[i+D].first-mp[i].first)+abs(mp[i+D].second-mp[i].second));
  }
  int Q;
  cin>>Q;
  for(int i=0; i<Q; i++){
    int a,b;
    cin>>a>>b;
    cout<<S[b]-S[a]<<endl;
  }
}
  
  

Measured memory_bytes: 9216
#ABC156 C - Rally

n = int(input())
x = [int(x) for x in input().split(' ')]
    
min_len =  100**2 * n

for i in range(100):
    all_len = 0
    for j in range(n):
        all_len += (x[j] - (i+1))**2

    min_len = min(min_len,all_len)

print(min_len)

Measured memory_bytes: 3064
import java.io.*;
import java.util.*;

 
public class Main{
   public static void main(String[] args) {
      MyScanner sc = new MyScanner();
      out = new PrintWriter(new BufferedOutputStream(System.out));
      int N=sc.nextInt();
      int K=sc.nextInt();
      int R=sc.nextInt();
      int S=sc.nextInt();
      int P=sc.nextInt();
      String t=sc.next();
      int dp[]=new int[N+K];
      int ans=0;

      for(int i=0;i<N;i++){
          char op=t.charAt(i);
          int cand=0;
          switch (op) {
              case 'r':
                  cand=1;
                  break;
              case 's':
                  cand=2;
                  break;
              case 'p':
                  cand=3;
                  break;
          }
          if(dp[i]!=cand){
              dp[i+K]=cand;
              switch (cand) {
                  case 1:
                      ans+=P;
                      break;
                  case 2:
                      ans+=R;
                      break;
                  case 3:
                      ans+=S;
                      break;
              }
          }
      }
      
      out.println(ans);
      out.close();
   }

   //-----------PrintWriter for faster output---------------------------------
   public static PrintWriter out;
      
   //-----------MyScanner class for faster input----------
   public static class MyScanner {
      BufferedReader br;
      StringTokenizer st;
 
      public MyScanner() {
         br = new BufferedReader(new InputStreamReader(System.in));
      }
 
      String next() {
          while (st == null || !st.hasMoreElements()) {
              try {
                  st = new StringTokenizer(br.readLine());
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
          return st.nextToken();
      }
 
      int nextInt() {
          return Integer.parseInt(next());
      }
 
      long nextLong() {
          return Long.parseLong(next());
      }
 
      double nextDouble() {
          return Double.parseDouble(next());
      }
 
      String nextLine(){
          String str = "";
	  try {
	     str = br.readLine();
	  } catch (IOException e) {
	     e.printStackTrace();
	  }
	  return str;
      }
   }
}

Measured memory_bytes: 26452
/*
    Auther: ghoshashis545 Ashis Ghosh
    College: jalpaiguri Govt Enggineering College
    Date:13/06/2020
*/
#include<bits/stdc++.h>
#include<string>
#include<algorithm>
using namespace std;
#define ll long long
#define int long long
#define ld long double
#define ff first
#define ss string 
#define se second
#define alt(v) v.begin(),v.end()
#define pb emplace_back
#define mp make_pair
#define fab(i,a,b) for(ll i=(a);i<(b);i++)
#define fba(i,a,b) for(ll i=(b);i>=(a);i--)
#define arr(i,n) fab(i,0,n)
ll mod=1000000007;
int dx[]={-1,1,0,0};
int dy[]={0,0,1,-1};
bool test = 0;


void solve()
{
   
    int x=0,n,cnt=0;
    cin>>n;
    set<int>st;
    map<int,int>m;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        if(x==1)
        cnt++;
        m[x]++;
    }
    vector<int>v;
    int ans=0;
    for(auto it:m)
    {
        st.insert(it.ff);
        if(it.se>1)
        continue;
        v.pb(it.ff);
    }
        
    if(st.find(1)!=st.end())
    {
        if(cnt==1)
        cout<<1;
        else
        cout<<0;
        return;
    }
    for(auto it:v)
    {
        bool f=1;
        for(int j=2;j<=sqrt(it);j++)
        {
            if(it%j==0)
            {
                int x2=it/j;
                if(st.find(j)!=st.end() or st.find(x2)!=st.end())
                {
                    f=0;
                    break;
                }
            }
        }
        if(f)
        ans++;
    }
    
    cout<<ans;
}










signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int t=1;
    if(test)
    cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 26596
#include <stdio.h>
#include <string.h>

int main() {
  int a, b, flag = 0;
  scanf("%d %d", &a, &b);

  char num[a + b + 2];
  scanf("%s", num);

  int len = strlen(num);
  for(int i = 0; i < len; i++) {
    if((num[i] == '-' && i != a) || num[a] != '-') {
      flag = 1;
      break;
    }
  }

  if(!flag) printf("Yes");
  else printf("No");
  return 0;
}

Measured memory_bytes: 1700
#include<stdio.h>
int main(){
  int j,N,M,A[100000],i;
  j=0;
  scanf("%d%d",&N,&M);
  for(i=1;i<=M;i++){
  scanf("%d",&A[i]);
  }
  for(i=1;i<=M;i++){
     j=j+A[i];
  }
  if(N<j){
    printf("-1");
  }
  else if(N>=j){
    printf("%d",N-j);
  }
    return 0;
}



Measured memory_bytes: 1760