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

int main(){
  int N;
  cin >> N;
  vector<long> A(N);
  for(int i=0; i<N; i++){
    cin >> A[i];
  }
  
  vector<int> AN(N,0);
  for(int i=0; i<N; i++){
    if(i%2){
      AN[0]-=A.at(i);
    }
    else{
      AN[0]+=A.at(i);
    }
  }
  cout << AN[0];
  for(int i=1; i<N; i++){
    AN.at(i)=A.at(i-1)*2-AN[i-1];
    cout << ' ' << AN[i];
  }
  cout << endl;
}

Measured memory_bytes: 2432
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String S = sc.next();
		String T = sc.next();
		String ans = "";
		for (int i = 0; i < N; i++) {
			ans += S.substring(i, i + 1);
			ans += T.substring(i, i + 1);
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 19924
n = int(input())
s = input()
A = list(map(int,s.split()))
flag = 1
cnt = 0

while(flag == 1):
    flag = 0
    for j in range(n-1,0,-1):
        if A[j] < A[j-1]:
            tmp = A[j]
            A[j] = A[j-1]
            A[j-1] = tmp
            flag = 1
            cnt += 1

for k in range(0,len(A)-1):
    print(A[k],end=" ")
print(A[len(A)-1])
print (cnt)

Measured memory_bytes: 7616
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <cstdlib>
using namespace std;


bool match(string &s1,string &s2){
    if(s1.size()<s2.size())
        return false;
    int idx=0;
    for(int i = 0; i <= s1.size()-s2.size(); i++){
        if(s1[i]==s2[0]){
            bool f=true;
            for(int j = 0; j < s2.size(); j++){
                if(s1[i+j]!=s2[j]){
                    f=false;
                    break;
                }
            }
            if(f)
                return true;
        }
    }
    return false;
}


// iツ氾板姪堋づ個陳クツ点ツづーjツづ個湘ウツ妥板づ訪ツづェツつスツづつォツづ個催渉ャツ陳キツつウツづ個閉カツ篠堋療ア
string dp[11][1<<10];
vector<string> ss;
int matchSize[11][11];
string matchStr[11][11];
int n;

string rec(int idx,int s){
    if(s==(1<<n)-1)
        return"";
    if(dp[idx][s]!="")
        return dp[idx][s];
    string res;
    for(int i = 0; i < n; i++){
        if(i==idx)continue;
        if((s>>i)&1)continue;
        int ns=s|(1<<i);
        string ts=matchStr[idx][i]+rec(i,ns);
        if(res==""||ts.size()<res.size())
            res=ts;
        else if(ts.size()==res.size()&&ts<res)
            res=ts;
    }
    return dp[idx][s]=res;
}

int main(){
    while(cin>>n&&n!=0){
        for(int i = 0; i < 11; i++)
            for(int j = 0; j < (1<<10); j++)
                dp[i][j]="";
        ss.clear();
        vector<string> tmp;
        memset(matchSize,0,sizeof(matchSize));
        for(int i = 0; i < n; i++){
            string s;
            cin>>s;
            tmp.push_back(s);
        }
        bool ok[21];
        fill(ok,ok+21,true);
        for(int i = 0; i < n; i++){
            if(!ok[i])continue;
            for(int j = 0; j < n; j++){
                if(i==j)continue;
                if(match(tmp[i],tmp[j])){
                    ok[j]=false;
                }
            }
        }
        for(int i = 0; i < n; i++)
            if(ok[i])
                ss.push_back(tmp[i]);
        n=ss.size();
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                if(i==j)
                    continue;
                matchStr[i][j]=ss[j];
                for(int k = min(ss[i].size(),ss[j].size()); k >= 1; k--){
                    if(ss[i].substr(ss[i].size()-k,k)==ss[j].substr(0,k)){
                        matchSize[i][j]=k;
                        matchStr[i][j]=ss[j].substr(k);
                        break;
                    }
                }
            }
        }
        string res;
        for(int i = 0; i < n; i++){
            string s=ss[i]+rec(i,(1<<i));
            if(res==""||s.size()<res.size())
                res=s;
            else if(s.size()==res.size()&&s<res)
                res=s;
        }
        cout<<res<<endl;
    }
    return 0;
}

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

int main() {
    int a[10];
    for(int i=0; i<10; i++) cin >> a[i];
    sort(a, a+10);
    for(int i=9; i>6; i--) cout << a[i] << endl;
    return 0;
}

Measured memory_bytes: 1176
#include<bits/stdc++.h>
using namespace std;
#define pow107 int(pow(10,9) + 7)

bool comp(pair<int, int> a, pair<int, int> b){
    if(a.first != b.first) return a.first > b.first;
    else return a.second < b.second;
}

long int jou(long int x, long int y){
    long int f = 1;
    for(int i = 0; i < y; ++i){
        f = f * x % pow107;
    }
    return f;
}

bool pn(long int x){
    if(x != 2 && x % 2 == 0)
        return false;
    for(int i = 3; i < x; ++i){
        if(x != i && x % i == 0)
            return false;
    }
    return true;
}

long int factorial(long int n){
    long int f = 1;
    for(long int i = 1; i <= n; ++i){
        f = f * i % pow107;
    }
    return f;
}

long int Func2(long int n,long int m){
    long int s2 = 1,
        r = 1;
    for(long int i = 1; i <= m; ++i){
        s2 = (s2*(n - (i - 1))/i) % (pow107);
    }
    return s2;
}

bool secsort(pair<int, int> a, pair<int, int> b){
    if(a.second == b.second)return a.first > b.first;
    else return a.second > b.second;
}

long int GCD(long int a,long int b){
    if(b == 0)return a;
    return GCD(b,a%b);
}

long int LCM(long int a,long int b){
    return a/GCD(a,b)*b;
}

void warfl(vector<vector<int> > &dist, int n){
  for(int k=0; k<n; k++){
    for(int i=0; i<n; i++){
      for(int j=0; j<n; j++){
        dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
      }
    }
  }
  return;
}
#define long long long

const int MAX = 1000000;
const int MOD = 1e9+7;

long mpow(long x, long n){
    long ans = 1;
    while(n != 0){
        if(n%2==1) ans = ans*x % MOD;
        x = x*x % MOD;
        n = n/2;
    }
    return ans;
}

long mfact(long n){
  long ans = 1;
  for(long i=2; i<=n; i++){
    ans = ans*i % MOD;
  }
  return ans;
}

long mcomb(long n, long m){ //aCbをmod計算
    if(n == 0 && m == 0) return 1;
    if(n < m || n < 0) return 0;
    long ans = mfact(n)*mpow(mfact(m), MOD-2) %MOD;
    ans = ans*mpow(mfact(n-m), MOD-2) %MOD;
    return ans;
}

int main(){
    int n;
    cin >> n;
    for(int i = 1; i <= 50000;++i){
        if(int(i*1.08) == n){
            cout << i << endl;
            return 0;
        }
    }

    cout << ":(" << endl;

}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
using namespace std;
typedef long long ll;

int main(){
  ll n, k;
  cin >> n >> k;
  ll h[n];
  REP(i,n) cin >> h[i];
  ll cost[n];
  fill(cost,cost+n,-1);
  cost[0] = 0;
  for(ll i = 0; i < n-1; i++){
    for(ll j = i+1; j <= min(i+k,n-1); j++){
      if(cost[j]<0){
        cost[j] = cost[i] + abs(h[j]-h[i]);
      }else{
        cost[j] = min(cost[j],cost[i]+abs(h[j]-h[i]));
      }
    }
  }
  cout << cost[n-1] << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	int total = 0;
	int duration;

	int min = 10;

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

		cin >> duration;
		total += ((duration + 9) / 10) * 10;

		int m = duration % 10;
		if (m == 0) {
			continue;
		}
		if (min > m) {
			min = m;
		}

	}
	total -= 10 - min; 
	

	cout << total << endl;

	return 0;
}

Measured memory_bytes: 256
from math import ceil
N, A, B = map(int,input().split())
h = []
for k in range(N):
    h.append(int(input()))

def check(t):
    s = t
    for k in range(N):
        if h[k] > B*t:
            s -= ceil((h[k]-B*t)/(A-B))
        if s < 0:
            return False
    return True

lo = 0
hi = max(h)+1

while hi - lo > 1:
    mid = (hi+lo)//2
    if check(mid):
        hi = mid
    else:
        lo = mid

print(hi)

Measured memory_bytes: 7068
#include<bits/stdc++.h>
using namespace std;
#define MAX 100000

int A[MAX];
int N;

void solve() {
    multiset<int> M;

    for (int i=0; i<N; i++) {
        auto itr = M.lower_bound(A[i]);
        if (itr!=M.begin()) M.erase(--itr);
        M.insert(A[i]);
    }
    cout << M.size() << endl;
}

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

    solve();

    return 0;
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n)  for (int i = 0; i < (int) (n); i++)
#define REP1(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x)     (x).begin(), (x).end()
#define SZ(x)      ((int) (x).size())
using ll = long long;
#define pint pair <int, int>
int main() {
  string s;
  cin >> s;
  string s0 = ""; // front
  string s1 = ""; // back
  bool flg  = true;
  int q;
  cin >> q;
  REP(i, q) {
	int t;
	cin >> t;
	if (t == 1) {
		flg = !flg;
	  } else {
		int f;
		string c;
		cin >> f >> c;
		if (f == 1) {
			if (flg) {
				s0 = s0 + c;
			  } else {
				s1 = s1 + c;
			  }
		  } else {
			if (flg) {
				s1 = s1 + c;
			  } else {
				s0 = s0 + c;
			  }
		  }
	  }
  }
  string ans;
  if (flg) {
	  reverse(all(s0));
	  ans = s0 + s + s1;
	} else {
	  reverse(all(s1));
	  reverse(all(s));
	  ans = s1 + s + s0;
	}
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1708
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Control.Arrow
import Data.List
import Data.Maybe
import Data.Char
import qualified Data.ByteString.Char8 as B
import Text.Printf

readInt = ( readLn :: IO Int )
readInts = map ( read :: String -> Int ) . words <$> getLine

getList = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = do
	x :: Integer <- readLn
	print $ x `div` 11 * 2 + ( x `mod` 11 + 5 ) `div` 6


Measured memory_bytes: 508
n,m = map(int,input().split())

l = [[0,0,0] for _ in range(n)]
res = []

for i in range(n):
    l[i][0],l[i][1],l[i][2] = map(int,input().split())

for i in range(8):
    i1 = (i&1)*2-1
    i2 = ((i>>1)&1)*2-1
    i3 = ((i>>2)&1)*2-1
    l.sort(key = lambda x:(-1)*(i1*x[0]+i2*x[1]+i3*x[2]))
    tmp = 0
    for j in range(m):
        tmp += i1*l[j][0]+i2*l[j][1]+i3*l[j][2]
    res.append(tmp)

print(max(res))

Measured memory_bytes: 3188
def combination(n, r, mod):
    n1, r = n+1, min(r, n-r)
    numer = denom = 1
    for i in range(1, r+1):
        numer = numer * (n1-i) % mod
        denom = denom * i % mod
    return numer * pow(denom, mod-2, mod) % mod


x,y = map(int,input().split())
diff = abs(x-y)
mod = 10**9 + 7
if (x+y) % 3 != 0:
    print("0")
    exit()
else:
    cir = (min(x,y) - diff) // 3
    if cir < 0:
        print("0")
        exit()
    all_step = (x+y) // 3
    print(combination(all_step, cir, mod))


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define vec vector
#define vi vec<int>
#define vvi vec<vec<int>>
#define ALL(a) begin(a), end(a)
#define RALL(a) rbegin(a), rend(a)
#define SORT(a) stable_sort(ALL(a))
#define RSORT(a) stable_sort(RALL(a))
#define REV(a) reverse(ALL(a))
#define UNIQUE(a) a.erase(unique(ALL(a)), end(a))
#define lambda(i) [](auto& i)
#define compare(i, j) [](auto& i, auto& j)
#define min_of(a) *min_element(ALL(a))
#define max_of(a) *max_element(ALL(a))
#define sum(a) accumulate(ALL(a), 0)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define SZ(a) (int)(a).size()
#define REP(i, n) for (decltype(+n) i = 0; i < (n); i++)
#define RREP(i, n) for (auto i = n - 1; i != static_cast<decltype(i)>(-1); i--)
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define RFOR(i, a, b) for (auto i = b - 1; i != a; i--)
#define EACH(i, a) for (auto&& i: (a))
using namespace std;

const int INF = 1e18;
const int MOD = 1e9 + 7;

struct union_find {
  vi data;
  union_find(int size) : data(size, -1) { }
  bool union_set(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool find_set(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};

vi cum(vi V) {
  vi U(SZ(V));
  partial_sum(ALL(V), begin(U));
  return U;
}

void solve() {
  int n;
  int ans = 0;

  cin >> n;
  // vi v(n);
  // REP(i, n) {
  //   cin >> v[i];
  // }
  ans = (n / 11) * 2;
  ans += n % 11 > 6 ? 2 : n % 11 > 0 ? 1 : 0;

  cout << ans << endl;
  // REP(i, n) {
  //   cout << v[i];
  // }
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout << fixed << setprecision(15);
  solve();
}


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

int main(){

    ll n;
    cin >> n;

    vector<pair<ll,ll> > a(n);
    vector<ll> s(n);
    ll su=0;

    rep(i,n){
        cin >> a[i].first >> a[i].second;
        s[i]=a[i].first+a[i].second;
        su+=a[i].second;
    }
    sort(s.begin(),s.end());
    ll ans =0;
    while(s.size()!=0){
        ans+=s.back();
        s.pop_back();
        if(s.size()==0) break;
        s.pop_back();
    }

    cout << ans-su << endl;

    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <cstdint>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <algorithm>

int main(void)
{
    std::string S, T;

    std::cin >> S >> T;

    T.erase(T.end()-1);

    std::cout << (S == T ? "Yes" : "No") << std::endl;

    return 0;
}

Measured memory_bytes: 3628
def main():
    N, M = map(int, input().split(' ')) # Nにちかん ，Mこ
    An = list(map(int, input().split(' '))) # An日かかる
    
    if sum(An) > N:
        print('-1')
        return
    
    out = []
    for a in An:
        if a <= 24:
            out.append(a)
        else:
            t = a // 24
            m = a % 24
            for _ in range(t):
                out.append(24)
            out.append(m)
    nissuu = len(out)
    # print(out, nissuu, sum(out))
    
    print(N - sum(out))
            
    
    
    
    
main()

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

long long calc(long long A, long long B, long long i){
  return ((A*i)/B) - A * (i / B);
}

void solve(long long A, long long B, long long N){
  cout << max(calc(A, B, N), calc(A, B, (B*(N/B))-1)) << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long A;
  scanf("%lld",&A);
  long long B;
  scanf("%lld",&B);
  long long N;
  scanf("%lld",&N);
    solve(A, B, N);
    return 0;
}


Measured memory_bytes: 3660
import java.util.Scanner;
class Main{
public static void main(String[] args){
 Scanner scan = new Scanner(System.in);
 
 int b = 0;
 int N = scan.nextInt();
 int M = scan.nextInt();  
	for (int i = 0; i < M; i++){
      int a = scan.nextInt();
      b = a + b;
    }
  if (N - b >= 0){
    System.out.println(N-b);
  }
  else{
    System.out.println("-1");
  }
   
 }
}

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

using ll = long long;

int main() {
    ll N, maxa = 0, maxi = 0;
    cin >> N;
    vector<ll> a(N);
    rep(i, N) {
        cin >> a[i];
        if (abs(a[i]) > maxa) {
            maxa = abs(a[i]);
            maxi = i;
        }
    }
    vector<int> x, y;
    ll maxb = maxa, maxj = maxi;
    rep(i, N) {
        if (a[i] == a[maxi]) continue;
        x.push_back(maxi + 1);
        y.push_back(i + 1);
        a[i] += a[maxi];
        if (abs(a[i]) > maxb) {
            maxb = abs(a[i]);
            maxj = i;
        }
    }
    if (a[0] > 0) {
        rep(i, N - 1) {
            if (a[i + 1] >= a[i]) continue;
            x.push_back(maxj + 1);
            y.push_back(i + 2);
            a[i + 1] += a[maxj];
            if (abs(a[i + 1]) > maxb) {
                maxb = abs(a[i + 1]);
                maxj = i + 1;
            }
        }
    } else {
        rep(i, N - 1) {
            if (a[N - i - 2] <= a[N - i - 1]) continue;
            x.push_back(maxj + 1);
            y.push_back(N - i - 1);
            a[N - i - 2] += a[maxj];
            if (abs(a[N - i - 2]) > maxb) {
                maxb = abs(a[N - i - 2]);
                maxj = N - i - 2;
            }
        }
    }
    cout << x.size() << endl;
    rep(i, x.size()) {
        cout << x[i] << " " << y[i] << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
char c[111111];

int main(){

    // 1. 入力情報取得.
    scanf("%s", c);
    int l = strlen(c);
    deque<char> dq;
    for(int i = 0; i < l; i++) dq.push_back(c[i]);
    
    // 2. 回文を生成していく.
    int ans = 0;
    char f, e;
    while(dq.size() > 1){
        // 先頭, 末尾取得.
        f = dq.front(), e = dq.back();
        
        // 先頭, 末尾比較.
        if(f == e){
            dq.pop_front(), dq.pop_back();
        }else if(f == 'x'){
            dq.pop_front(), ans++;
        }else if(e == 'x'){
            dq.pop_back(), ans++;
        }else{
            break;
        }
    }
    
    // 3. 回文判定.
    bool ok = true;
    if(dq.size() > 2) ok = false;
    if(dq.size() == 2){
        f = dq.front(), e = dq.back();
        if(f != e) ok = false;
    }
    
    // 4. 出力
    if(ok) printf("%d\n", ans);
    else   printf("%d\n", -1);
    return 0;
    
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<string>
#include<cmath>


using namespace std;



int main() {
	int S;
	int W;
	
	
	cin >> S >> W;

	if (W >= S) {
		cout << "unsafe";
	}
	else
	{
		cout<<"safe";
	}
}

Measured memory_bytes: 3624
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for(int i=0; i<n; i++){
            a[i] = sc.nextInt();
        }

        int ans = 0;
        for(int i=1; i<n; i++){
            if(a[i] == a[i-1]){
                ans++;
                a[i] = -1;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21588
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin >> S;
    ll z = stoll(S);
    int N = S.length();
    int cnt = 1;
    ll ans = 0;
    if (N == 1) {
        cout << S << endl;
        return 0;
    }
    rep(k, N) {
        cnt = 1;
        rep(i, N-2) cnt *= 2;
        rep(i, N) {
            int tmp = S[k] - '0';
            ll times = 1;
            rep(r, min(N-k-1, i)) times *= 10;
            //dump(times);
            rep(j, cnt) {
                ans += tmp * times;
                //dump(ans);
            }
            cnt /= 2;
        }
        //dump(ans);
    }
    cout << ans + z << endl;
    return 0;
}


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


int main()
{
  
   int r,c,n;
   cin>>r>>c>>n;

  int count=0;
  int ans=0;

  int big=max(r,c);

  while(count<n)
 {
    count+=big;
     ans++;
  }
  cout<<ans;


   return 0;
 }
  

  


 


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  string s;
  cin >> s;
  int sl = sz(s);
  ll cnt = 0;
  int i = 0;
  while(i < sl-2) {
    if(s[i] == 'A') {
      int Anum = 1;
      i++;
      while(true) {
        if(i >= sl-2) break;
        if(s[i] == 'A') {
          i++;
          Anum++;
        } else {
          break;
        } 
      }
      int BCnum = 0;
      while(true) {
        if(i >= sl-1) break;
        if(s[i] == 'B' && s[i+1] == 'C') {
          BCnum++;
          i += 2;
        } else {
          break;
        }
      }
      cnt += (ll)Anum * (ll)BCnum;
      if(BCnum > 0) {
        for(int j = i-Anum;j < i;j++) {
          s[j] = 'A';
        }
        i -= Anum;
      }
      
    } else {
      i++;
    }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define SZ(x) ((int) (x).size())
using namespace std;

typedef long long i64;

const int MOD = (int) 1e9 + 7;

int Pow(int x, int y) {
    int ret = 1;
    for (; y > 0; y /= 2) {
        if (y & 1) {
            ret = (int64_t) ret * x % MOD;
        }
        x = (int64_t) x * x % MOD;
    }
    return ret;
}

vector<int> getDivs(int n) {
    vector<int> divs;
    for (int i = 1; i * i <= n; ++i) {
        if (n % i == 0) {
            divs.push_back(i);
            if (i * i < n) {
                divs.push_back(n / i);
            }
        }
    }
    return divs;
}

int main() {
    #ifdef LOCAL_RUN
    freopen("task.in", "r", stdin);
    freopen("task.out", "w", stdout);
    //freopen("task.err", "w", stderr);
    #endif // ONLINE_JUDGE
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, k;
    cin >> n >> k;

    int ans = 0;

    vector<int> divs = getDivs(n);
    sort(divs.begin(), divs.end());
    vector<int> dp(SZ(divs));
    dp[0] = k;
    for (int i = 1; i < SZ(divs); ++i) {
        dp[i] = Pow(k, (divs[i] + 1) / 2);
        for (int j = 0; j < i; ++j) {
            if (divs[i] % divs[j] == 0) {
                dp[i] -= dp[j];
                dp[i] %= MOD;
            }
        }
    }
    for (int i = 0; i < SZ(divs); ++i) {
        int p = divs[i];
        int val = dp[i];
        if (p % 2 == 0) {
            int mul = (int64_t) p * Pow(2, MOD - 2) % MOD;
            // cerr << p << ' ' << mul << ' ' << val << endl;
            ans = (ans + (int64_t) mul * val) % MOD;
        } else {
            int mul = p;
            ans = (ans + (int64_t) mul * val) % MOD;
        }
    }

    ans %= MOD;
    if (ans < 0) {
        ans += MOD;
    }
    cout << ans << '\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin >> a >> b;
  int count=0;
  
  for (int i=a; i <= b; i++){
    if(i/10000 == i%10 && i%10000/1000 == i%100/10 ){count ++;}
  }
	cout << count << endl;
}
    



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repe(i, n) for (int i = 0; i <= (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define ANS cout << ans << endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))
#define KOZYUN(a) sort(all(a),greater<int>())
#define int ll
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORe(i, m, n) for(int i = m;i <= n;i++)
#define VIin(a) for(int i=0; i<a.size(); i++) cin >> a[i]
#define OUT(a) cout << a << endl
#define IN(a) cin >> a
#define INT(a) int a; cin >> a
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
/*最大公約数*/int gcd(int x, int y) { return y ? gcd(y,x%y) : x;}
/*最小公倍数*/int lcm(int a, int b) { int g = gcd(a, b); return a / g * b; }
/*素数判定*/int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*約数列挙*/vector<int> getDivisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------------------------------------
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    char s; cin >> s;
    cout << char(s+1) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
typedef long long   ll;
#define pb                push_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define mem(a,h)          memset(a, (h), sizeof(a))
#define fi first
#define se second
#define por(a,b) (((a%MOD) * (b%MOD))%MOD)
#define forg(i, b, e, c)    for (ll i = (ll)b; i < (ll)e; i+=c)
#define forr(i, b, e)    for (ll i = b; i < e; i++)
 
 
using namespace std;
//using namespace __gnu_pbds;
typedef double lldb;
typedef pair<ll, ll>  ii;
typedef pair<ll, ii>  iii;
typedef vector<ll>     vi;
typedef vector<vi>     vvi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const ll INF = 1e9;
const double PI = acos(-1);
#define offset 
const ll MOD= 1e9+7;
#define initseg ll new_nodo=(nodo*2),mid=(iz+der)/2;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define tam 223455
ll n;
ll arr[tam],v[tam];
ll A,B;
int f(ll num)
{
    forr(i,0,n){
        arr[i]=v[i]-num*B;
        //cout<<arr[i]<<" ";
    }

    ll cant=0;
    forr(i,0,n)
    {
        if (arr[i]<=0)continue;
        cant+=((arr[i])/(A-B))+((arr[i]%(A-B))!=0);
    }
    //cout<<cant<<endl;
    return cant<=num;
}
int  main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    
    cin>>n;
    cin>>A>>B;
    forr(i,0,n)
        cin>>v[i];
    sort(v,v+n);
    //cout<<f(800000000-1)<<endl;
    //return 0;
    ll iz=0,der=1e9,mid;
    while(iz+1<der)
    {
        mid=(iz+der)/2;
        if (f(mid)==0)
            iz=mid;
        else
            der=mid;
    }
    cout<<der<<endl;
}
// PLUS ULTRA!ac

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

typedef pair<int, int> II;
typedef vector< II > VII;
typedef vector<int> VI;

#define endl "\n"
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ll long long
#define fr(i,n) for(i=0;i<n;i++)


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    cout<<48-n<<endl;
    return 0;
}


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

int N;
ll ans = 0;
ll a[10000];

int main(){
    cin >> N;
    rep(i,N) cin >> a[i];
    bool can = true;
    rep(i,N){
        if (a[i] % 2 == 0){
            while (a[i] % 2 == 0){
                ans++;
                a[i] /= 2;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
x = int(input())
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors
num = make_divisors(x)
n = len(num)
for i in range(n):
    p = num[i]
    q = x//num[i]
    for b in range(-150,150):
        a = b+p
        if a**4 + (a**3)*b + (a*b)**2 + a*(b**3) + b**4 == q:
            print(a,b)
            break
    


Measured memory_bytes: 68224
#include <bits/stdc++.h>
#define FIXED_FLOAT(x) std::fixed <<std::setprecision(2)<<(x)
#define what_is(x) cerr << #x << " is " << x << endl;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define inf std::numeric_limits<int>::max();
#define highest_2_pow(n)  __builtin_clzll((long long)0)- __builtin_clzll((long long)n) - 1
//-----------------------------------------------------------------------------------------------------
#define lli long long int 
#define int long long
#define all(x)            (x).begin(),(x).end()
#define uniq(v)           (v).erase(unique(all(v)),(v).end())
#define sz(x)             (int)((x).size())
#define fr                first
#define sc                second
#define pii               pair<int,int>
#define vi vector<int>
#define vlli vector<long long int>
#define si set<int>
#define slli set<long long int>
#define mt make_tuple
#define mp make_pair
#define eb emplace_back
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define ppc               __builtin_popcount
#define ppcll             __builtin_popcountll
//---------------------------------------------------
using namespace std;
// GCD and LCM are available
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << endl;
err(++it, args...);
}

void faster(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}
void solve(){
    int sx,sy,tx,ty;
    cin>>sx>>sy>>tx>>ty;
    int dx = tx-sx;
    int dy = ty-sy;
    rep(i,0,dy) cout<<"U";
    rep(i,0,dx) cout<<"R";
    rep(i,0,dy) cout<<"D";
    rep(i,0,dx) cout<<"L";
    cout<<"L";
    rep(i,0,dy+1) cout<<"U";
    rep(i,0,dx+1) cout<<"R";
    cout<<"D";
    cout<<"R";
    rep(i,0,dy+1) cout<<"D";
    rep(i,0,dx+1) cout<<"L";
    cout<<"U"<<endl;

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

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

using namespace std;

typedef long long int lli;

const lli DIV = 1000000007;

int main(int argc, char const *argv[]) {
  lli n;
  cin >> n;
  vector<lli> a(n);
  vector<int> cnt(n,0);
  lli ans = 1;
  for (size_t i = 0; i < n; i++) {
    cin >> a[i];
    cnt[a[i]]++;
    if (a[i]==0) {
      if (cnt[0]>1) ans=0;
    }
    else {
      if (cnt[a[i]]>2) ans = 0;
      else if (cnt[a[i]]==1) {
        ans *= 2;
        ans %= DIV;
      }
    }
  }

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


Measured memory_bytes: 1408
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

	public static void main(String args[]) {
		ConsoleScanner cin = new ConsoleScanner();
		PrintWriter cout = new PrintWriter(System.out);
		solve(cin, cout);
		cout.flush();
	}

	static long now() {
		return System.currentTimeMillis();
	}

	static void trace(Object... objects) {
		assert null != System.out.format("trace:%s\n", Arrays.deepToString(objects));
	}

	private static void solve(ConsoleScanner cin, PrintWriter cout) {
		int n = cin.nextInt();

		long start = now();

		boolean ans = solve(n);

		if (ans)
			cout.println("Yes");
		else
			cout.println("No");
		trace("elapsed", now() - start);
	}

	private static boolean solve(int n) {
		return n / 100 == n % 10;
	}

	static class ConsoleScanner {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");

		String next() {
			try {
				while (!st.hasMoreElements())
					st = new StringTokenizer(br.readLine());
				return st.nextToken();
			} catch (IOException e) {
				throw new AssertionError(e);
			}
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}
	}

}


Measured memory_bytes: 21076
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
typedef long long ll;
long long mod = 1e9 + 7;
const int iINF = 0x3f3f3f3f;
const long long INF = 1LL << 60;
using namespace std;

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

int main()
{
  string s, t;
  cin >> s >> t;

  char s_henkan[30], t_henkan[30];
  rep(i, 30)
  {
    s_henkan[i] = -1;
    t_henkan[i] = -1;
  }

  rep(i, s.size())
  {
    if (s_henkan[s[i] - 'a'] < 0)
    {
      s_henkan[s[i] - 'a'] = t[i];
    }
    else if (s_henkan[s[i] - 'a'] != t[i])
    {
      cout << "No" << endl;
      return 0;
    }
  }

  rep(i, s.size())
  {
    if (t_henkan[t[i] - 'a'] < 0)
    {
      t_henkan[t[i] - 'a'] = s[i];
    }
    else if (t_henkan[t[i] - 'a'] != s[i])
    {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;

  return 0;
}

Measured memory_bytes: 776
#include <stdio.h>
#include <stdlib.h>

int main(){
	int H, W, i, j;
	scanf("%d%d", &H, &W);
	int **a = (int **)malloc(sizeof(int *) * H);
	for(i = 0; i < H; i++){
		a[i] = (int *)malloc(sizeof(int) * W);
		for(j = 0; j < W; j++){
			scanf("%d", &a[i][j]);
		}
	}
	int *x = (int *)malloc(sizeof(int) * H * W);
	int *y = (int *)malloc(sizeof(int) * H * W);
	int *_x = (int *)malloc(sizeof(int) * H * W);
	int *_y = (int *)malloc(sizeof(int) * H * W);
	int k = 0;
	for(i = 0; i < H; i++){
		for(j = 0; j < W - 1; j++){
			if(a[i][j] % 2 == 1){
				x[k] = i;
				y[k] = j;
				_x[k] = i;
				_y[k] = j + 1;
				k++;
				a[i][j]--;
				a[i][j + 1]++;
			}
		}
	}
	for(i = 0; i < H - 1; i++){
		if(a[i][j] % 2 == 1){
			x[k] = i;
			y[k] = j;
			_x[k] = i + 1;
			_y[k] = j;
			k++;
			a[i][j]--;
			a[i + 1][j]++;
		}
	}
	printf("%d\n", k);
	for(i = 0; i < k; i++){
		printf("%d %d %d %d\n", x[i] + 1, y[i] + 1, _x[i] + 1, _y[i] + 1);
	}
	return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <stack>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
template<class T> inline bool chmax(T& a, T b){ if(a < b) { a=b; return 1; }return 0;}
template<class T> inline bool chmin(T& a, T b){ if(a > b) { a=b; return 1; }return 0;}
const long long INF = 1LL << 60;

// --------write my code!!!!!----------//

int main(){
    string s; cin >> s;
    int num[2]={0};
    rep(i,s.length()){
        if(s[i]=='0') num[0]++;
        else num[1]++;
    }
    cout << 2*min(num[0],num[1]) <<endl;
}


Measured memory_bytes: 512
#include <algorithm>
#include <iostream>

int main(int argc, char *argv[]) {
  int n;
  std::cin >> n;
  long long a[1001];
  for (int i = 0; i < n; ++i)
    std::cin >> a[i];
  int q;
  std::cin >> q;
  for (int i = 0; i < q; ++i) {
    int b, e;
    std::cin >> b >> e;
    std::reverse(a + b, a + e);
  }

  for (int i = 0; i < n; ++i) {
    if (i > 0)
      std::cout << " ";
    std::cout << a[i];
  }
  std::cout << std::endl;
}



Measured memory_bytes: 3108
n,k = map(int,input().split())
h = []
for i in range(n):
    h.append(int(input()))
h.sort()
h_max = 0
h_min = 0
r = 0
ans = []
#print(h)
for i in range(r,n-k+1):
    if n - r < k: 
        break
    h_max = h[r+k-1]
    #print(h[r:k])
    h_min = h[r]
    ans.append(h_max - h_min)
    r += 1
print(min(ans))


Measured memory_bytes: 11292
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <cmath>
#include <unordered_map>
#include <cstdio>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long ll;

ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}
ll kai(ll x, ll y, ll m) {
	ll res = 1;
	for (ll i = x - y + 1; i <= x; i++) {
		res *= i; res %= m;
	}
	return res;
}
ll mod_pow(ll x, ll y, ll m) {
	ll res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

ll comb(ll x, ll y, ll m) {
	if (y > x)return 0;
	return kai(x, y, m) * mod_pow(kai(y, y, m), m - 2, m) % m;
}

char c;

signed main() {
	cin >> c;
	if (c == 'A')cout << 'T' << endl;
	if (c == 'T')cout << 'A' << endl;
	if (c == 'C')cout << 'G' << endl;
	if (c == 'G')cout << 'C' << endl;
}

Measured memory_bytes: 3584
stdin.ReadLine()
|> int
|> function
   | x when x < 10 -> x
   | x when x < 100 -> 9
   | x when x < 1000 -> x - (99 - 9)
   | x when x < 10000 -> 909
   | x when x < 100000 -> x - (9999 - 909)
   | x when x = 100000 -> 90909
|> printfn "%d"

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

#define N 100005
#define smax(X, Y) ((X) > (Y) ? (X) : (Y))
int n, a[N], dp[N], r, ans;

int main(){
    cin >> n;
    for (int i=1; i<=n; i++) cin >> a[i];
    for (int i=1; i<=n; i++) dp[i] = __gcd(dp[i-1], a[i]);
    for (int i=n; i; i--){
        ans = smax(ans, __gcd(dp[i-1], r));
        r = __gcd(r, a[i]);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 1024
#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 n;
    cin >> n;
    bool flag = false;
    for (int i = 1; i < 10; ++i) {
        if (n%i == 0 && n/i < 10) {
            flag = true;
            break;
        }
    }
    if (flag) puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 3612
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#define MAX_K 200100

int main() {
  int N, K, cur = 0;
  cin >> N >> K;

  vector<int> A(N, 0);
  vector<int> cnt(MAX_K, 0);

  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (!cnt[A[i]]) cur++;
    cnt[A[i]] += 1;
  }

  sort(cnt.begin(), cnt.end());
  int ans = 0, diff = cur - K;
  for (int i = 0; i < cnt.size(); i++) {
    if (diff <= 0) break;
    if (cnt[i]) {
      ans += cnt[i];
      diff--;
    }
  }
  cout << ans << endl;
  return 0;
}

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

n = int(input())
nums = [int(s) for s in input().split()]

cost = 100000001
for i in range(-100, 101):
    costMin = 0
    for j in nums:
        costMin += (i -j)**2
    if costMin < cost:
        cost = costMin        

print(cost)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
 
ll H, W;

ll func1(){
    ll ans = LLONG_MAX;
    for(int i = 1; i <= H - 2; ++i){
        ll a = i * W;
        ll b = (H - i) / 2 * W;
        ll c = H * W - a - b;
        ll mx = max({a, b, c});
        ll mn = min({a, b, c});
        ans = min({ans, mx - mn});
    }
    return ans;
}

ll func2(){
    ll ans = LLONG_MAX;
    for(int i = 1; i <= H - 1; ++i){
        ll a = i * W;
        ll b = W / 2 * (H - i);
        ll c = H * W - a - b;
        ll mx = max({a, b, c});
        ll mn = min({a, b, c});
        ans = min({ans, mx - mn});
    }
    return ans;
}

ll func3(){
    ll ans = LLONG_MAX;
    for(int i = 1; i <= W - 2; ++i){
        ll a = i * H;
        ll b = (W - i) / 2 * H;
        ll c = H * W - a - b;
        ll mx = max({a, b, c});
        ll mn = min({a, b, c});
        ans = min({ans, mx - mn});
    }
    return ans;
}

ll func4(){
    ll ans = LLONG_MAX;
    for(int i = 1; i <= W - 1; ++i){
        ll a = i * H;
        ll b = H / 2 * (W - i);
        ll c = H * W - a - b;
        ll mx = max({a, b, c});
        ll mn = min({a, b, c});
        ans = min({ans, mx - mn});
    }
    return ans;
}

int main(void){
	
	scanf("%lld %lld", &H, &W);
	ll a = func1(), b = func2(), c = func3(), d = func4();
	printf("%lld\n", min({a, b, c, d}));
	
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse = True)
# 一番でかいのは一回、それ以外は二回まで寄与できる
# 上から貪欲
left = N-1
index = 0
ans = 0
while left > 0:
    if index == 0:
        ans += A[index]
        left -= 1
        index += 1
    else:
        if left == 1:
            ans += A[index]
            left -= 1
            index += 1

        else:
            ans += A[index]*2
            left -= 2
            index += 1
print(ans)

Measured memory_bytes: 31536
#include <iostream>
#include <cstring>
#include <string>

class Dice
{
public:
	Dice(int* pValue)
	{
		memcpy(m_value, pValue, sizeof(int) * 6);
	}

public:
	Dice Roll(char direction) const
	{
		Dice d = (*this);

		switch (direction)
		{
		case 'N':
		{
			d.m_value[0] = m_value[1];
			d.m_value[1] = m_value[5];
			d.m_value[4] = m_value[0];
			d.m_value[5] = m_value[4];
		}
		break;
		case 'E':
		{
			d.m_value[0] = m_value[3];
			d.m_value[2] = m_value[0];
			d.m_value[3] = m_value[5];
			d.m_value[5] = m_value[2];
		}
		break;
		case 'W':
		{
			d.m_value[0] = m_value[2];
			d.m_value[2] = m_value[5];
			d.m_value[3] = m_value[0];
			d.m_value[5] = m_value[3];
		}
		break;
		case 'S':
		{
			d.m_value[0] = m_value[4];
			d.m_value[1] = m_value[0];
			d.m_value[4] = m_value[5];
			d.m_value[5] = m_value[1];
		}
		break;
		default:
			break;
		}

		return d;
	}

	Dice Spin() const
	{
		Dice d = (*this);

		d.m_value[1] = m_value[2];
		d.m_value[2] = m_value[4];
		d.m_value[3] = m_value[1];
		d.m_value[4] = m_value[3];

		return d;
	}

	int GetTop() const
	{
		return m_value[0];
	}

	int GetFront() const
	{
		return m_value[1];
	}

	int GetRight() const
	{
		return m_value[2];
	}

private:
	int m_value[6];
};

Dice FindTop(const Dice& dice, int top)
{
	if (dice.GetTop() == top)
	{
		return dice;
	}

	Dice d = dice.Roll('S');
	for (int i = 0; i < 3; ++i)
	{
		if (d.GetTop() == top)
		{
			return d;
		}

		d = d.Roll('S');
	}

	d = dice.Roll('E');
	if (d.GetTop() == top)
	{
		return d;
	}

	d = dice.Roll('W');
	if (d.GetTop() == top)
	{
		return d;
	}
	
	return dice;
}

Dice FindFront(const Dice& dice, int front)
{
	Dice d = dice;
	for (int i = 0; i < 4; ++i)
	{
		if (d.GetFront() == front)
		{
			return d;
		}

		d = d.Spin();
	}

	return d;
}

int main(int argc, char** argv)
{
	int val[6];
	std::cin >> val[0] >> val[1] >> val[2] >> val[3] >> val[4] >> val[5];
	int q;
	std::cin >> q;

	Dice d = Dice(val);

	for (int i = 0; i < q; ++i)
	{
		int top, front;
		std::cin >> top >> front;

		d = FindTop(d, top);
		d = FindFront(d, front);

		std::cout << d.GetRight() << std::endl;
	}

	return 0;
}


Measured memory_bytes: 3104
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
const int INF = 1000100000;
#define rep(i,n) for(int i=0;i<n;++i)


int main(){
  int n;
  cin >>n;
  int dp[100100]={};
  dp[1]=1;
  int res;
  for(int x=1;x<=n;x++){
    int waru6=0,waru9=0;
    int a=x,b=x;
    while(a>0){
      a/=6;
      if(a==0)break;
      waru6++;
    }
    while(b>0){
      b/=9;
      if(b==0)break;
      waru9++;
    }
    res=dp[x-1];
    int power6=1,power9=1;
    if(waru6>0){
      rep(p,waru6){
        power6*=6;
        res=min(res,dp[x-power6]);
      }
    }
    if(waru9>0){
      rep(q,waru9){
        power9*=9;
        res=min(res,dp[x-power9]);
      }
    }
    dp[x]=res+1;
  }
  cout << dp[n] << endl;
}


Measured memory_bytes: 640
import math

A,B,DEGREE = map(int,input().split())

rad = math.radians(DEGREE)

S = A*B*math.sin(rad)/2.0
C = math.sqrt(A*A+B*B-2*A*B*math.cos(rad))
h = 2*S/A

print("%.10f %.10f %.10f"%(S,A+B+C,h))


Measured memory_bytes: 5712
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;


long int W = 1e+9+7;
int main(void){
    int n,m;
    cin >> n >> m;
    cout << (n-1)*(m-1) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    string str;
    cin>>str;
    if(n%2==0)
    {
        int x=n/2;
        string a=str.substr(0,x);
        string b=str.substr(x,n-1);
        //cout<<a<<" "<<b<<endl;
        if((a.compare(b))==0)
        {
            cout<<"Yes"<<endl;
        }
        else
        {
            cout<<"No"<<endl;
        }
    }
    else{
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int H = Integer.parseInt(sc.next());
        int N = Integer.parseInt(sc.next());
        int res = 0;
        for(int i=0;i<N;i++){
            res += Integer.parseInt(sc.next());
        }
        String str = res >= H ? "Yes" : "No";
        System.out.println(str);
    }
}


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

int main() {
    int n;
    cin>>n;
    int a[n],b[n],c[n-1];
    for (int i=0;i<n;i++) {
        cin>>a[i];
        a[i]--;
    }
    for (int i=0;i<n;i++)
        cin>>b[i];
    for (int i=0;i<n-1;i++)
        cin>>c[i];
    int sm=b[a[0]];
    for (int i=1;i<n;i++) {
        sm+=b[a[i]];
        if (a[i-1]+1==a[i])
            sm+=c[a[i-1]];
    }
    cout<<sm<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Eric
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DHandstand solver = new DHandstand();
        solver.solve(1, in, out);
        out.close();
    }

    static class DHandstand {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            int K = in.nextInt();
            String S = in.next();

            int res = shortSolve2(S, K);
            out.println(res);
        }

        private int shortSolve2(String s, int K) {
            int n = s.length();
            int i = 0;
            int j = 0;
            int res = 0;
            int k = 0;
            while (j < n) {
                while (j < n && s.charAt(j) == '1')
                    j++;
                res = Math.max(res, j - i);

                while (j < n && s.charAt(j) == '0')
                    j++;
                while (j < n && s.charAt(j) == '1')
                    j++;
                k++;
                if (k > K) {
                    while (i < n && s.charAt(i) == '1')
                        i++;
                    while (i < n && s.charAt(i) == '0')
                        i++;
                }
                res = Math.max(res, j - i);
            }
            return res;
        }

    }
}



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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
   float x;
   cin>>x;
   if(x==0)
   cout<<1<<endl;
   else if(x==1)
  cout<<0<<endl;
}

Measured memory_bytes: 3800
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int mod=1e9+7;
const int mxN=2001;
ll dp[mxN+1];
int main(){
	ll n;
	dp[0]=1;
	cin>>n;
	for(int i=3;i<=n;i++){
		dp[i]=(dp[i-3]+dp[i-1]+dp[i])%mod;
	}
	cout<<dp[n];
}

Measured memory_bytes: 3648
N = int(input())
a = list(map(int, input().split()))

even = [x for x in a if x % 2 == 0]

ans = 0
for e in even:
    while True:
        if e / 2 != e // 2:
            break
        e /= 2
        ans += 1
        if e == 1:
            break
print(ans)


Measured memory_bytes: 4148