akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=55;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=2000000000;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;
/*
ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		else a=a*a%MOD;
		b>>=1;
	}
	return res;
}
*/


int a[maxn];
map<int,int> mp,mp2;
vector<pii> v;
int main()
{
	//IOS;
	int n,A;
	cin>>n;
	cin>>A;
	REP(i,n) cin>>a[i];
	REP(i,n) a[i]-=A;

	mp[0]=1,mp2[0]=1;

	for(int i=0;i<n/2;i++){
		v.clear();
		for(auto j:mp) v.pb(j);
		for(auto j:v){
			mp[j.F+a[i]]+=j.S;
		}
	}
	for(int i=n/2;i<n;i++){
		v.clear();
		for(auto j:mp2) v.pb(j);
		for(auto j:v){
			mp2[j.F+a[i]]+=j.S;
		}
	}
	ll ans=0;
	for(auto i:mp){
		ans+=1LL*i.S*mp2[-i.F];
	}
	cout<<ans-1<<'\n';

	return 0;
}


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

#define fi first
#define se second
#define pb push_back

const int N = 8080;

using namespace std;

int n , m;
int cnt , ans , sum  , a;
string s , s1;
int main()
{
        ios_base::sync_with_stdio(false);

        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
    cin >> s >> s1;
    s1.pop_back();
    if( s == s1 )
        cout << "Yes";
    else
        cout << "No";
}



Measured memory_bytes: 3640
n = int(input())
A, B = [], []
for _ in range(n):
  a, b = map(int, input().split())
  A.append(a)
  B.append(b)

A.sort()
B.sort()

if n % 2 == 1:
  ans = B[(n - 1) // 2] - A[(n - 1) // 2] + 1

else:
  ans = (B[n // 2] + B[n // 2 - 1]) - (A[n // 2] + A[n // 2 - 1]) + 1

print(ans)

Measured memory_bytes: 25524
N, M = map(int, input().split())
A = list(map(int, input().split()))
b = []
for i in range(M):
    b.append(list(map(int, input().split())))
ans = 0
A.sort()
b.sort(key=lambda x: x[1], reverse=True)
j = 0
for i in range(M):
    if j >= N or b[i][1] <= A[j]:
        break
    while j < N and b[i][0] and b[i][1] > A[j]:
        ans += b[i][1]
        b[i][0] -= 1
        j += 1
if j >= N:
    print(ans)
else:
    print(ans + sum(A[j:]))

Measured memory_bytes: 33004
#include<cstdio>
#include<algorithm>

using namespace std;

int p, q, a, n;

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

int counter(int p, int q, int m, int n, int minNumber) {
  if (minNumber > m) return 0;
  if (p * minNumber > q * n) return 0;
  int temp = gcd(q, minNumber);
  //if (temp > 
  int ans = 0;
  int p1 = p * minNumber, q1 = q * minNumber;
  for (int i = 0; i <= n; i++) {
    if (n <= 0 || m <= 0) break;
    if (p1 == 0) {
      ans++;
      break;
    } else if (p1 < 0) {
      break;
    } else {
      int g = gcd(p1, q1);
      ans += counter(p1 / g, q1 / g, m, n - i, minNumber + 1);
      p1 -= q;
      m /= minNumber;
    }
  }
  //printf("%d,%d(%d)=>%d\n", p, q, n,ans);
  return ans;
}

int main() {
  while (1) {
    scanf("%d%d%d%d", &p, &q, &a, &n);
    if (p == 0) break;
    int g = gcd(p, q);
    printf("%d\n", counter(p/g, q/g, a, n, 1));
  }
}


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

int main(){
  int n;
  string s;
  cin >> n;
  cin >> s;
  int r=0,g=0,b=0;
  rep(i,0,n){
    if(s[i]=='R') r++;
    else if(s[i]=='G') g++;
    else b++;
  }

  ll ans = 0;
  int Disr=0,Disg=0,Disb=0;
  rep(i,0,n){
    if(i!=0){
      if(s[i-1]=='R') Disr++;
      else if(s[i-1]=='G') Disg++;
      else Disb++;
    }
    int disr=0,disg=0,disb=0;
    rep(j,0,n){
      if(i>=j || s[i]==s[j]) continue;
      if(s[i]=='R'){
        if(s[j]=='G'){
          ans += b - disb - Disb;
          if(2*j-i<n && s[2*j-i]=='B') ans--;
          disg++;
        }
        if(s[j]=='B'){
          ans += g - disg - Disg;
          if(2*j-i<n && s[2*j-i]=='G') ans--;
          disb++;
        }
      }
      else if(s[i]=='G'){
        if(s[j]=='R'){
          ans += b - disb - Disb;
          if(2*j-i<n && s[2*j-i]=='B') ans--;
          disr++;
        }
        if(s[j]=='B'){
          ans += r - disr - Disr;
          if(2*j-i<n && s[2*j-i]=='R') ans--;
          disb++;
        }
      }
      else{
        if(s[j]=='R'){
          ans += g - disg - Disg;
          if(2*j-i<n && s[2*j-i]=='G') ans--;
          disr++;
        }
        if(s[j]=='G'){
          ans += r - disr - Disr;
          if(2*j-i<n && s[2*j-i]=='R') ans--;
          disg++;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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

ll gcd(ll a, ll b){
  return (b != 0) ? gcd(b, a%b) : a;
}

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n;
  ll y;
  cin >> n >> y;
  for(int i = 0; i <= n; ++i){
    for(int j = 0; j <= n-i; ++j){
      int k = n - i - j;
      if(10000*i+5000*j+1000*k == y){
        cout << i << " " << j << " " << k << "\n";
        return 0;
      }
    }
  }
  cout << -1 << " " << -1 << " " << -1 << "\n";
  
}  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for (int i = (a); i <= (b); ++i)
#define REPD(i,a,b) for (int i = (a); i >= (b); --i)
#define FORI(i,n) REP(i,1,n)
#define FOR(i,n) REP(i,0,int(n)-1)
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define SZ(x) int((x).size())
#define DBG(v) cerr << #v << " = " << (v) << endl;
#define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define fi first
#define se second

const int N = 100100;

int n,m,q,v;
int a[N], used[N], ord[N], pos[N], sor[N], prog[N];

int main() {
	scanf("%d%d%d", &n, &m, &q);
	FOR(i,q) scanf("%d", &a[i]);
	FOR(i,q) a[i]--;
	REPD(i,q-1,0) if (!used[a[i]]) {
		ord[v++] = a[i];
		used[a[i]]=1;
	}
	FOR(i,m) if (!used[i]) ord[v++] = i;
	sor[v-1]=sor[v]=1;
	REPD(i,v-2,0) sor[i] = sor[i+1] && (ord[i] < ord[i+1]);
	FOR(i,v) pos[ord[i]] = i;
	REPD(i,q-1,0) {
		int pp = upper_bound(prog, prog+n, pos[a[i]]) - prog - 1;
		if (pp >= 0 && prog[pp] == pos[a[i]]) {
			prog[pp]++;
		}
	}
	//FOR(i,n) printf("%d %d\n", i, prog[i]);
	bool ok = true;
	FOR(i,n) if (!sor[prog[i]]) ok = false;
	printf("%s\n", ok ? "Yes" : "No");
	return 0;
}


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

int main() {
int H, W;
  cin >> H >> W;
  vector<string> pix(H);
  for(int i = 0; i < H; i++){
    cin >> pix.at(i);
  }
  for(int i = 0; i < W + 2; i++){
    cout << '#';
  }
  cout << endl;
  for(int i = 0; i < H; i++){
    cout << '#' << pix.at(i) << '#' << endl;
  }
  for(int i = 0; i < W + 2; i++){
    cout << '#';
  }
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)

def run():
  N, M = map(int, input().split())
  g = {}
  for m in range(M):
    A, B = map(int, input().split())
    g.setdefault(B, []).append(A)
    g.setdefault(A, []).append(B)
  visited = [0]*N
  visited[0] = 1
  def dfs(now):
    for nxt in g[now]:
      if visited[nxt-1] == 0:
        visited[nxt-1] = visited[now-1]*(-1)
        if not dfs(nxt):
          return False
      else:
        if visited[nxt-1] != visited[now-1]*(-1):
          return False
    return True
  if dfs(1):
    print(visited.count(1)*visited.count(-1)-M)
  else:
    print(N*(N-1)//2-M)
  
if __name__ == '__main__':
  run()

Measured memory_bytes: 36904
//Name: Encryption System
//Level: 3
//Category: 全探索
//Note:

/**
 * アルファベット順で1つ前の文字にずらされるため、1つの文字は高々1回しか置換されない。
 * 文字列長が最大20文字と短いため、どの文字が置換されたかの候補をすべて試し、実際に変換してみて元に戻るかを確かめればよい。
 *
 * オーダーは O(2^|S| × |S|)。
 */
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <array>

using namespace std;

bool solve() {
    string str;
    if(!(cin >> str)) return false;
    if(str == "#") return false;

    const int N = str.size();
    vector<string> ans;
    array<int,26> first_pos;
    for(int i = 0; i < (1<<N); ++i) {
        string cand = str;
        bool ok = true;
        int popcnt = 0;
        for(int j = 0; j < N; ++j) {
            if(i & (1<<j)) {
                ++popcnt;
                if(cand[j] == 'z') {
                    ok = false;
                    break;
                }
                cand[j] = cand[j]+1;
            }
        }
        if(ok) {
            fill(begin(first_pos), end(first_pos), -1);
            for(int j = 0; j < N; ++j) {
                const char ch = cand[j] - 'a';
                if(first_pos[ch] != -1 && (i & (1<<j))) {
                    ok = false;
                    break;
                }
                if(first_pos[ch] == -1 && ch != 0) {
                    if(i & (1<<j)) {
                        --popcnt;
                    } else {
                        ok = false;
                        break;
                    }
                    first_pos[ch] = j;
                }
            }
            if(ok && popcnt == 0) {
                ans.push_back(cand);
            }
        }
    }

    sort(begin(ans), end(ans));
    ans.erase(unique(begin(ans), end(ans)), end(ans));
    cout << ans.size() << endl;
    if(ans.size() <= 10) {
        for(const string &s : ans) {
            cout << s << endl;
        }
    } else {
        for(int i = 0; i < 5; ++i) {
            cout << ans[i] << endl;
        }
        for(int i = 0; i < 5; ++i) {
            cout << *(ans.rbegin()+4-i) << endl;
        }
    }

    return true;
}

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

    while(solve()) ;
    return 0;
}

Measured memory_bytes: 2356
#!/usr/bin/env python3


def main():
    import sys

    input = sys.stdin.readline

    N = int(input())
    A = [int(x) for x in input().split()]

    limit = 10 ** 18
    ans = 1
    for i in range(N):
        if ans > limit:
            break
        ans *= A[i]
    
    if 0 in A:
        print(0)
    elif ans > limit:
        print(-1)
    else:
        print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 21580
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<queue>
#define _USE_MATH_DEFINES
#include<math.h>
#include<cmath>
#include<ctime>
#include<map>
#include<typeinfo>
#define R(i, n) for(int i = 0;i < n; i++)
#define S(a) scanf("%d", &a)
#define S2(a, b) scanf("%d%d", &a, &b)
#define S3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define SL(a) scanf("%lld", &a)
#define SL2(a, b) scanf("%lld%lld", &a, &b)
#define SL3(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
#define SA(i, n, a) R(i, n) scanf("%d", &a[i])
#define SAL(i, n, a) R(i, n) scanf("%lld", &a[i])
#define SC(a) scanf("%c", &a)
#define P(a) printf("%d", a)
#define PL(a) printf("%lld", a)
#define PY printf("YES")
#define PN printf("NO")
#define Py printf("Yes")
#define Pn printf("No")
using namespace std;
using ll = long long;
using PR = pair<int, int>;
const ll MOD = 1e+9 + 7;
const int INF = 1e+9;
const double PI = acos(-1);

int main() {
	int N;
	string ST;
	S(N);
	cin >> ST;
	int ans = 0;
	for (int split = 1; split < N; split++) {
		set<char> iset;
		set<char> jset;
		int ma = 0;
		for (int i = 0; i < split; i++) iset.insert(ST[i]);
		for (int j = split; j < N; j++) {
			if (jset.find(ST[j]) == jset.end()) {
				jset.insert(ST[j]);
				if (iset.find(ST[j]) != iset.end()) ma++;
			}
		}
		ans = max(ans, ma);
	}
	P(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, c) for (int i = 0; i < (int)c; i++)
int main()
{
	string s;
	cin >> s;
	rep(i, s.size() - 1) {
		if (s[i] == s[i + 1]) {
			printf("Bad\n");
			return 0;
		}
	}
	printf("Good\n");
	return 0;
}

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

int main(){
  int n , k;
  cin >> n >> k;
  vector<int> v(n);
  for(int i = 0; i < n; i++){
    cin >> v[i];
  }
  
  sort(v.rbegin(), v.rend());
  
  int sum = 0;
  for(int i = 0; i < k; i++){
    sum += v[i];
  }
  cout << sum << endl;
  
}
     

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

using namespace std;

vector<int>s;
bool dp[105][10005];

int main(){

	int N;

	scanf("%d",&N);

	int i,j,k;

	for(i=0;i<N;i++){
		int si;
		scanf("%d",&si);
		s.push_back(si);
	}

	sort(s.begin(),s.end());

	dp[0][0]=true;

	for(i=0;i<N;i++){
		for(j=0;j<=10000;j++){
			for(k=0;k<=1&&k*s[i]<=j;k++){
				dp[i+1][j]|=dp[i][j-k*s[i]];
			}
		}
	}

	int ans=0;

	for(i=0;i<=N;i++){
		for(j=0;j<=10000;j++){
			if(dp[i][j]&& j%10!=0 && ans<j){ans=j;}
		}
	}

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

	return 0;
}

Measured memory_bytes: 1280
main = do
    n <- readLn :: IO Int
    putStrLn $ if n == 0 then "0" else solve n

solve n =  concatMap show . reverse $ solve' n 1
     where solve' 0 _ = []
           solve' n k = a : solve' (n - a * (-2)^(k-1)) (k+1)
               where a | n `mod` (2^k) == 0 = 0
                       | otherwise = 1

Measured memory_bytes: 3884
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N = int(input())
    A = [int(x) for x in input().split()]

    MOD = 10 ** 9 + 7

    ruiseki = [0] * N

    for i in range(N):
        ruiseki[i] = ruiseki[i - 1] + A[i]

    ans = 0
    s = sum(A)
    for i in range(N):
        ans += A[i] * (s - ruiseki[i])
        ans %= MOD

    print(ans)

    

if __name__ == '__main__':
    main()



Measured memory_bytes: 31304
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>
#include <random>

#define FOR_LT(i, beg, end) for (int i = (int)(beg); i < (int)(end); i++)
#define FOR_LE(i, beg, end) for (int i = (int)(beg); i <= (int)(end); i++)
#define FOR_DW(i, beg, end) for (int i = (int)(beg); (int)(end) <= i; i--)
#define REP(n)              for (int repeat_index = 0; repeat_index < (int)n; repeat_index++)

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(20);

	int n; cin >> n;
	vector<int> anss(n + 1);
	FOR_LT(x, 1, n) {
		if (n <= x * x) break;
		FOR_LT(y, 1, n) {
			if (n <= y * y) break;
			FOR_LT(z, 1, n) {
				if (n <= z * z) break;

				int m = x * x + y * y + z * z + x * y + y * z + z * x;
				if (n < m) break;

				anss[m]++;
			}
		}
	}

	FOR_LE(i, 1, n) {
		cout << anss[i] << endl;
	}


	return 0;
}

Measured memory_bytes: 3604
N = int(input())
p = list(map(int, input().split()))
q = [0] * N
for i in range(N):
    q[p[i] - 1] = i
for i in range(N):
    print(30000 * i + 1, end = "")
    if i == N - 1:
        print()
    else:
        print(end = " ")
for i in range(N):
    print(30000 * (N - i) + q[i] + 1, end = "")
    if i == N - 1:
        print()
    else:
        print(end = " ")

Measured memory_bytes: 5540
#include<bits/stdc++.h>
using namespace std;
using I = long long;
int main() {
  int Q;
  cin >> Q;
  for(auto i=0; i<Q; ++i) {
    I A, B;
    cin >> A >> B;
    I S = A*B;
    I low = 1, high = S;
    while(high-low > 1) {
      I a = (low + high) / 2;
      I b = S/a;
      if(a*b==S) --b;
      if(a<=b) low  = a;
      else     high = a;
    }
    I r = low * 2;
    I a, b;
    a = low;
    b = S/a;
    if(a*b==S) --b;
    if(a==b) {
      r -= 2;
      if(a!=A&&b!=B) ++r;
    } else if(a==A) {
      r-=2;
      if(b!=A&&a!=B) ++r;
    }
    if(A < low) {
      a = A;
      b = S/a;
      r-=2;
      if(b!=A&&a!=B) ++r;
    }
    b = B;
    a = S/b;
    if(b<low) {
      r-=2;
      if(b!=A&&a!=B) ++r;
    }
    cout << r << endl;
  }
}


Measured memory_bytes: 256
package main
 
import (
  "fmt"
  "math"
)
 
func main() {
  var a, b, c, d int
  fmt.Scanf("%d %d %d %d", &a, &b, &c, &d)
  
  dac := math.Abs(float64(a - c))
  dab := math.Abs(float64(a - b))
  dbc := math.Abs(float64(b - c))
  
  ans := "No"
  if int(dac) <= d {
    ans = "Yes"
  }
  if int(dab) <= d && int(dbc) <= d {
    ans = "Yes"
  }
  
  fmt.Printf("%s\n", ans)
}

Measured memory_bytes: 1836
# include <bits/stdc++.h>
# define rep(i, n) for(ll i = 0; i < (n); ++i)
# define reps(i, n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(ll i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(ll i=((int)(n)); i>0; --i)
# define ll long long
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
# define P pair<int, int>
using namespace std;
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; }
ll lmax(ll a, ll b){if(a>= b) return a;return b;}
ll lmin(ll a, ll b){if(a>= b) return b;return a;}
static const ll INF = 1e18;

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

  if('z' - c <= 25) cout << 'a' << endl;
  else cout << 'A' << endl;

}


Measured memory_bytes: 3588
#include <stdio.h>

int main()
{
	int N;
	int ans1,ans2;

	scanf("%d",&N);

	ans1=N/10;
	ans2=N%10;

	if(ans1==9 || ans2==9){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}

	return 0;
}



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

using namespace std;
typedef long long ll;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    int k;
    k=min(a+b,a+c);
    k=min(k,b+c);
    cout<<k;
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	C_fix
# CreatedDate:  2020-06-29 12:19:58 +0900
# LastModified: 2020-06-29 12:34:39 +0900
#


import os
import sys
import numpy as np
# import pandas as pd


def main():
    n = int(input())
    p = list(map(int, input().split()))
    cnt = 1
    p_min = p[0]
    for i in range(1, n):
        if p_min > p[i]:
            cnt += 1
            p_min = p[i]

    print(cnt)


if __name__ == "__main__":
    main()


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

int main()
{
    int X ;
    int ans =0;
    cin >> X ;
    for(int i = 1 ; i <= 50 ; i++)
    {
        int num =i;
        for(int j =0;j<=20;j++){
            num*= i;
            if(num > X)break;
            ans = max(ans,num);
        }
    }
    cout << ans << endl ;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
  
int main() {
 
	int n, a[10000];
	int MIN = 1000000;
	int MAX = -1000000;
	long long SUM = 0;

	cin >> n;

	for(int i = 0; i < n; i++){
		cin >> a[i];
		MIN = min(MIN,a[i]);
		MAX = max(MAX,a[i]);
		SUM = SUM + a[i];
	}

	cout << MIN << " " << MAX << " " << SUM << endl;


    return 0;
} 


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

using namespace std;

typedef long long ll;

const int N = 405;

ll dp[N][N];
int n;
ll pref[N];

ll go(int l, int r) {
  if(l >= r) return 0;
  if(dp[l][r] != -1) return dp[l][r];
  ll cost = 1e18;
  for(int i = l; i < r; i++) {
    cost = min(cost, go(l, i) + go(i + 1, r) + pref[r] - pref[l - 1]);
  }
  return dp[l][r] = cost;
}

int main() {
  cin >> n; memset(dp, -1, sizeof dp);
  for(int i = 1; i <= n; i++) {
    ll x; cin >> x;
    pref[i] = pref[i - 1] + x;
  }
  cout << go(1, n) << '\n';
}

Measured memory_bytes: 1536
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main() {
	string s;
	cin >> s;
	if (s[s.size() - 1] == 's') {
		cout << s << "es" << endl;
	}
	else {
		cout << s << "s" << endl;
	}
	return 0;
}


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

const int MAX_NM = 35;
int A[MAX_NM];

int main()
{
	for (int i = 0; i < MAX_NM; ++i)
	{
		A[i] = 0;
	}
	int N,M;
	cin >> N >> M;
	for (int i = 0; i < N; ++i)
	{
		int K;
		cin >> K;
		for (int i = 0; i < K; ++i)
		{
			int temp;
			cin >> temp;
			temp--;
			A[temp]++;
		}
	}

	int ans = 0;

	for (int i = 0; i < M; ++i)
	{
		if (A[i] == N) ans++;
	}

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

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

int main(){
    int n;
    cin >> n;
    int x[n],y[n];
    rep(i,n) cin >> x[i];
    rep(i,n) cin >> y[i];
    double d1=0,d2=0,d3=0,dinf=0;

    rep(i,n){
        double tmp = abs(x[i]-y[i]);
        d1 += tmp;
        d2 += tmp*tmp;
        d3 += tmp*tmp*tmp;
        dinf = max(tmp,dinf);
    }

    printf("%.7f\n",d1);
    printf("%.7f\n",sqrt(d2));
    printf("%.7f\n",cbrt(d3));
    printf("%.7f\n",dinf);
    return 0;
}













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

int main(){

int N, s;
  cin >> N;
  s = N;
int cnt = 0;
  
  while(s){
  cnt += s % 10;
  s /= 10;  
  }
  
 if(N % cnt == 0) cout << "Yes" << endl;
  else cout << "No" << endl;  
  
return 0;
  
}

Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
# from fractions import gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    N, K = MAP()

    l = [1 for _ in range(N)]
    for _ in range(K):
        d = INT()
        A = LIST()

        for a in A:
            l[a-1] = 0

    print(sum(l))


if __name__ == '__main__':
    main()


Measured memory_bytes: 9992
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define FORq(i, m, n) for(int i = m;i <= n;i++)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef long long ll;
//////////////////////////////////////////////////////
int main(){
	int N; SCD(N);
	map<int,int>count;
	
	REP(i,N){
		int x; SCD(x);
		count[x] = count[x] + 1;
		count[x+1] = count[x+1] + 1;
		count[x-1] = count[x-1] + 1;
	}
	
	int ans = 0;
	REP(i,100002){
		ans = max(ans,count[i]);
	}
	
	PRINTD(ans);
	return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> v;
typedef pair<int,int>p;
typedef set<int>s;
#define ll long long
#define fr(i,a,b) for(int i=a;i<b;i++)
#define fre(i,a,b) for(int i=a;i<=b;i++)
#define FOR(i,a,b) for(int i=a;i>b;--i)
#define FORE(i,a,b) for(int i=a;i>=b;--i)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define bg begin()
#define en end()
/*note

*/
int main()
{

    int n,y,cnt=0;
    cin>>n;
    int ar[1000006],used[1000007]={0},br[1000007]={0};
    fr(i,0,n){cin>>ar[i];br[ar[i]]++;}

    for(int i=1;i<=1000000;i++){

        if(br[i]){
            if(br[i]>1){used[i]=1;}
            for(int j=i+i;j<=1000000;j+=i){
                used[j]=1;
            }
        }
    }

    fr(i,0,n){
    if(used[ar[i]]==0)++cnt;
    }
    cout<<cnt<<endl;








}





Measured memory_bytes: 12232
#include<iostream>
#include<math.h>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<bitset>
#include <climits>
using namespace std;
#define _GLIBCXX_DEBUG
#define pq priority_queue
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define vit vector<lint>::iterator
#define all(x) (x).begin(),(x).end()
#define rep(x) for(int i = 0;i < (x);i++)
#define repj(x) for(int j = 0;j < (x);j++)
#define REP(i,x) for(int (i) = 0;(i) < (x);(i)++)
#define rrep(x) for(int i = (x);i >= 0;i--)
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define mod 1000000007
#define graph_set(n) struct edge{int to,int cost;} vector<edge> G((n))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define range(x,y) ((x) >= 0 && (x) < h && (y) >= 0 && (y) < w)
#define pyes cout << "Yes" << endl
#define pno cout << "No" << endl
#define fin return 0
typedef vector<long long> vi;
typedef vector<pair<long long, long long>> vp;
typedef vector<vector<long long>> vvi;
typedef pair<long long, long long> pi;
typedef long long lint;
typedef long long ll;
lint qp(int a, ll b) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
lint qp(int a, ll b, int mo) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }
lint gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };
#define INF 10000000


//////////////////////////////////////////////////////////////////////
#define MAX_V 100010
typedef pair<int, int> pii;
struct edge
{
	int to, cost;
};
//pii.firstは最短距離、secondは頂点の番号
int N;//頂点数
vector<edge> G[MAX_V]; //隣接リスト
int d[MAX_V]; //最短距離
void dijkstra(int s) {
	//greater<pii>を指定することでfirstが小さい順に取り出せるようにする
	priority_queue<pii, vector<pii>, greater<pii>> que;
	/*次に使う頂点を探す最短距離が更新されるたびにqueから取り出し、入れなおすことでp_queの一番上に
	次に使うべき最短距離の頂点が保持され続ける*/
	fill(d, d + N, INF);
	d[s] = 0;
	que.push(pii(0, s));
	while (!que.empty()) {
		pii p = que.top(); que.pop();
		int v = p.second; // vは確定した頂点と同じ扱い
		// もともと決まってた仮距離よりも長かったら更新する意味がないのでskip
		if (d[v] < p.first) continue;
		for (int i = 0; i < G[v].size(); i++)
		{
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(pii(d[e.to], e.to));
			}
		}
	}
}
int solve(int k) {
	N = k;
	for (int i = 0; i < k; i++)
	{
      	edge e1 = { (i + 1) % k, 1 };
        edge e2 = { (10 * i) % k,0 };
		G[i].push_back(e1);
		G[i].push_back(e2);
	}

	dijkstra(1);
  	//for(int i = 0;i < k;i++) debug(d[i]);
	return d[0] + 1;
}
int main() {
	int k; cin >> k;
	cout << solve(k) << endl;
	return 0;
}

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

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

using namespace std;

int main(){
	int n; scanf("%d",&n);
	vector<int> a(n);
	rep(i,n) scanf("%d",&a[i]);

	vector<int> f(1000001);
	rep(i,n) f[a[i]]++;
	for(int x=1;x<=1000000;x++) if(f[x]>0) {
		for(int y=2*x;y<=1000000;y+=x) f[y]=0;
	}
	printf("%ld\n",count(f.begin(),f.end(),1));

	return 0;
}


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

int main()
{
  string L;
  cin >> L;
  float fL = stof(L);
//  double length = dL/3.0f;
  double retVal = (fL * fL * fL) / 27.0f;
  
  printf("%f\n", retVal);
  
  return 0;
}


Measured memory_bytes: 256
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)1e18;
const double PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

LL f(LL b,LL N){
	LL temp = N;
	
	LL sum = 0;
	while(temp){
		sum += (temp%b);
		temp /=b;
	}
	
	return sum;
}
void solve(){
	LL N,sum;
	cin >> N >> sum;
	if(N==sum){
		cout << N+1 << endl;
		return;
	}
	/*
	2から(√N)進数まで総当り。
	*/
	LL rN = sqrt(1.0*N)+1;
	for(LL b = 2; b <= rN;++b){
		LL temp = f(b,N);
		if( temp == sum ){
			cout << b << endl;
			return;
		}
	}
	/*
	√N進数より大きい進数では2桁しかない
	A1*b+A0 = N
	1<= A1 < b;//b進数の2桁の条件
	0<= A0 < b;
	A1+A0 = sum;//
	
	*/
	for(LL A1=rN;A1>=1;--A1){
		LL A0 = sum - A1;
		if( A0 < 0 ) continue;
		//int ans = (N-sum+A1)/A1;
		LL b = (N-sum)/A1 + 1;
		if( b < 2 ) continue;

		if( f(b,N) == sum ){
			cout << b << endl;
			return;
		}
	}
	cout << -1 << endl;
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	
	
	solve();
}
#pragma endregion //main()


Measured memory_bytes: 256
N, K = map(int, input().split())
H = list(map(int, input().split()))
dp = [10 ** 10] * N
dp[0] = 0
for i in range(1, N):
    for j in range(1, K + 1):
        if i - j < 0:
            break
        dp[i] = min(dp[i], dp[i - j] + abs(H[i - j] - H[i]))
print(dp[-1])

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

int gcd (int a, int b) {
  int tmp;
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }

  int r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }  
  return b;
}

int main () {

  int N, X;
  cin >> N >> X;

  int x[100010];

  for (int i=0; i<N; i++) {
    cin >> x[i];
  }
  x[N] = X;

  sort(x, x+(N+1));
  int y[100010];
  for (int i=0; i<N; i++) {
    y[i] = x[i+1] - x[i];
  }

  int ans;
  if (N==1) {
    ans = y[0];
  } else {
    ans = y[0];
    for (int i=1; i<N; i++) {
      ans = gcd(ans, y[i]);
    }
  }

  cout << ans << endl;

  return 0;
}


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


int main() {
  int N;
  string S;
  cin >> N >> S;
  int cnt;
  vector<int> dp(N);
  vector<bool> w(N, false);
  if (S[0] == 'W') {
    ++cnt;
    w[0] = true;
  }
  for (int i = 1; i < N; ++i) {
    if (S[i - 1] == 'W') {
      dp[i] = dp[i - 1] + 1;
    } else {
      dp[i] = dp[i - 1];
    }
    if (S[i] == 'W') {
      w[i] = true;
      ++cnt;
    }
  }
  int result = pow(10, 5) * 3 + 1;
  for (int i = 0; i < N; ++i) {
    result = min(result, dp[i] + (N - cnt) - (i + 1 - (dp[i] + w[i])));
  }
  cout << result << endl;
}

Measured memory_bytes: 1796
n = int(input())
A = list(map(int, input().split()))

ans = []
for num in range(101):
    cost1, cost2 = 0, 0
    for a in A:
        cost1 += (a-num)**2
        cost2 += (a-(-num))**2
    ans.append(cost1)
    ans.append(cost2)
print(min(ans))

Measured memory_bytes: 9132
N, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=False)
count = 0
for i in range(N):
    if x>=a[i]:
        count += 1
        x -= a[i]
    else:
        break
if (x!=0)and(count==N):
    count -= 1
print(count)

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


int main(){
    int k, n;
    cin>>k>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int ma = INT_MIN;
    for(int i=0;i<n-1;i++){
        ma = max(ma, a[i+1] - a[i]);
    }
    ma = max(ma, k-a[n-1] + a[0]);
    cout<<k - ma<<endl;
    return 0;
    
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v)) os<<*i<<(i==end(v)-1?"":"\n"); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
    is>>p.first>>p.second; return is; }
template <class T> bool chmax(T &a,const T &b) {if(a<b) {a=b;return 1;} return 0;}
template <class T> bool chmin(T &a,const T &b) {if(b<a) {a=b;return 1;} return 0;}
template <class T> using heap = priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int N,K;
    cin>>N>>K;
    vector<int> x(N);
    cin>>x;
    int ans=0;
    REP(i,N) ans+=min(x[i]*2,(K-x[i])*2);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
# solution

def f(mike, nim):
  return nim % mike + f(mike, nim // mike) if nim > 0 else 0

nim = int(input())
s = int(input())

for i in range(2, 5**8):
  if f(i, nim) == s:
    print(i)
    exit()

for i in range(nim - s >> 18, 0, -1):
  if f((nim - s) // i + 1, nim) == s:
    print((nim - s) // i + 1)
    exit()

print(nim + 1 if nim == s else -1)

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

#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;
 
const ll INF = 1LL<<60;
const int MINF = 1e9;
const int MOD = 1e9+7;

using vi = vector<int>;
using vii = vector<vi>;

template<typename T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

template<typename T>
T GCD(T a,T b){ return b ? GCD(b,a%b) : a ;}
template<typename T>
T LCM(T a,T b){ return a*b / GCD(a,b) ;}

template<typename T>//文字列の置換/Boost:replace_all()
T replace_str(T str, string target, string str_to) {
    string::size_type pos = 0;
    while (pos = str.find(target, pos), pos != string::npos) {
        str.replace(pos, target.length(), str_to);
        pos += str_to.length();
    }
    return str;
}

int main(){
    int n;cin >> n;
    string s;cin >> s;
    int ans = 0;
    for(int i=0;i<1000;i++){
        bool flag = false;
        int count = 0;
        int c[3] = {i/100,i/10%10,i%10};
        for(int j=0;j<s.size();j++){
            if(c[count]+'0' == s[j])count++;
            if(count==3)flag = true;
        }
        if(flag)ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
using ll = long long;
const int INF = 0x3f3f3f3f;
const int MAX_N = 200;

int N;
int a[MAX_N], b[MAX_N];

void solve()
{
	memset(a, 0x3f, sizeof(a));
	for(int i=0;i<N-1;++i){
		a[i]=min(a[i],b[i]);
		a[i+1]=min(a[i+1], b[i]);
	}
	for(int i=N-2;i>=0;--i){
		a[i]=min(a[i],b[i]);
		a[i+1]=min(a[i+1], b[i]);
	}
	int ans = 0;
	for(int i=0;i<N;++i) ans+=a[i];
	cout << ans << endl;
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> N;
	for(int i=0;i<N-1;++i)cin >> b[i];
	solve();
	return 0;
}

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

using namespace std;

int min_cost(vector<int>& costs) {
    const int INF = 10e5;
    int size = costs.size();
    vector<int> calc(size, INF);

    calc[0] = 0;
    for (int i = 1; i < size; ++i) {
        int cost_a = INF, cost_b = INF;
        if (i - 1 >= 0)
            cost_a = calc[i - 1] + abs(costs[i] - costs[i - 1]);
        if (i - 2 >= 0)
            cost_b = calc[i - 2] + abs(costs[i] - costs[i - 2]);
        calc[i] = min(cost_a, cost_b);
    }
    return calc[size - 1];
}

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

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

    cout << min_cost(h) << '\n';
}


Measured memory_bytes: 1024
//#include <ext/pb_ds/assoc_container.hpp>
#include <bits/stdc++.h>
using namespace std;
//using namespace __gnu_pbds;
//template <class c, class cmp = less<c> > using ordered_set = tree<c, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); 
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 
#endif
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}
template <typename T,typename U>pair<T,U> operator+(const pair<T,U> & l,const std::pair<T,U> & r) { return {l.first+r.first,l.second+r.second};}
typedef long long int ll;
const ll mod =1e9+7;
const int maxn = 2000005;
#define endl '\n'
#define int ll
#define ld long double
#define all(x) (x).begin(),(x).end()

int32_t main()
{ 
  IOS
    
  int n;
  cin>>n;
  int a[n+1];
  for(int i = 0;i<=n;i++) cin>>a[i];
  if(n == 0){
    if(a[0] == 1){
      cout<<1<<endl;
      return 0;
    }
    else{
      cout<<-1<<endl;
      return 0;
    }
  }
  if(a[0]!=0){
    cout<<-1<<endl;
    return 0;
  }
  int sum = 0;
  int cap[n+1];
  for(int i = n;i>=0;i--){
    sum += a[i];
    cap[i] = sum;
  }
  int cur = 1,ans = 1;
  for(int i  = 1;i<=n;i++){
    cur*=2;
    cur = min(cur,cap[i]);
    if(a[i] >cur){
      cout<<-1;
      return 0;
    }
    ans+=cur;
    cur-=a[i];
    
  }
  cout<<ans<<endl;
}
 

Measured memory_bytes: 5216
# Python template 
from collections import defaultdict 
import sys
import math 

def get_array(): return list(map(int , sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()


s = input()
t = input()


ans = math.inf 
for i in range(len(s)-len(t)+1):
    cnt = 0
    for j in range(len(t)):
        if t[j] != s[i+j]:
            cnt+=1
    ans = min(cnt,ans)
print(ans)

Measured memory_bytes: 9268
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

// int main() {
//   std::size_t n, m;
//   std::cin >> n >> m;
//
//   std::vector<std::size_t> a(n);
//   for (auto&& ai : a) std::cin >> ai;
//   std::sort(a.begin(), a.end());
//
//   std::vector<std::size_t> b(m), c(m), id(m);
//   for (std::size_t i = 0; i < m; ++i) std::cin >> b[i] >> c[i];
//   std::iota(id.begin(), id.end(), 0ULL);
//   std::sort(id.begin(), id.end(), [&c](auto i, auto j) { return c[i] > c[j];
//   });
//
//   std::size_t k = 0;
//   for (auto&& i : id) {
//     const auto bi = b[i];
//     const auto ci = c[i];
//     for (std::size_t j = 0; j < bi; ++j) {
//       if (a[k] < ci)
//         a[k++] = ci;
//       else
//         break;
//     }
//   }
//
//   const auto sum = std::accumulate(a.begin(), a.end(), 0ULL);
//   std::cout << sum << std::endl;
// }

struct Pair {
  std::size_t b;
  std::size_t c;
};

int main() {
  std::size_t n, m;
  std::cin >> n >> m;

  std::vector<std::size_t> a(n);
  for (auto&& ai : a) std::cin >> ai;
  std::sort(a.begin(), a.end());

  std::vector<Pair> pairs(m);
  for (auto&& p : pairs) std::cin >> p.b >> p.c;
  std::sort(pairs.begin(), pairs.end(),
            [](const auto& p1, const auto& p2) { return p1.c > p2.c; });

  std::size_t k = 0;
  for (auto&& p : pairs) {
    for (std::size_t j = 0; j < p.b; ++j) {
      if (a[k] < p.c)
        a[k++] = p.c;
      else
        break;
    }
  }

  const auto sum = std::accumulate(a.begin(), a.end(), 0ULL);
  std::cout << sum << std::endl;
}


Measured memory_bytes: 2560
from string import ascii_lowercase
n=int(input())
s=[]
for i in range(n):
  s.append(input())
ans={}
for i in ascii_lowercase:
  ans[i]=s[0].count(i)
for i in range(1,n):
  for j in ascii_lowercase:
    ans[j]=min(ans[j],s[i].count(j))
a=""
for i in ascii_lowercase:
  a+=i*ans[i]
print(a)

Measured memory_bytes: 3768
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) throws IOException {
		new Main().solve();
	}

	private void solve() throws IOException {
		try {
			//			solveA();
			solveB();
			//			 solveC();
			//			 solveD();
			//			 solveE();
			//			 solveF();
		} finally {
			if (in != null) {
				in.close();
			}
			if (out != null) {
				out.flush();
				out.close();
			}
		}

	}

	private void solveA() {
		int numN = nextInt();

		long res = 0;
		for (int i = 1; i <= numN; i++) {
			res += i;
		}

		out.println(res);
	}

	private void solveB() {
		char[] wk = next().toCharArray();

		List<Character> res = new ArrayList<Character>();
		for (char c : wk) {
			if (c != 'B') {
				res.add(c);
			} else {
				if (res.size() != 0) {
					res.remove(res.size() - 1);
				}
			}
		}

		StringBuilder builder = new StringBuilder();
		for (Character character : res) {
			builder.append(character);
		}
		out.println(builder.toString());
	}

	private void solveC() {
		int numN = nextInt();

		out.println("");
	}

	private void solveD() {
		int numN = nextInt();

		out.println("");
	}

	private void solveE() {
		int numN = nextInt();

		out.println("");
	}

	private void solveF() {
		int numN = nextInt();

		out.println("");
	}

	private final PrintWriter out = new PrintWriter(System.out);
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

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

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
}

Measured memory_bytes: 21460
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	int sum = a + b + c;
	if(sum == 2 * a || sum == 2 * b || sum == 2 * c) printf("Yes\n");
	else printf("No\n");
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
int main() {
  int n, h, a = 0, b = 0;
  cin >> n;
  rep(i,n)
  {
    cin >> h;
    if (b <= h) {
      a++;
      b = h;
    }
  }
  cout << a;
}

Measured memory_bytes: 256
from collections import Counter
def main():
    n = int(input())
    A = list(map(int, input().split()))
    c = Counter(A)
    B = sorted([(k, v) for k, v in c.items() if v >= 2], reverse = True, key = lambda x: x[0])
    if len(B) < 2:
        print(0)
    elif B[0][1] >= 4:
        print(B[0][0] ** 2)
    else:
        print(B[0][0] * B[1][0])

if __name__ == '__main__':
    main()


Measured memory_bytes: 22316
#ABC129-C
N,M=map(int,input().split())
a=[]
broke={} #N段目が壊れているか
broke[0]=0
for i in range(1,N+1):
    broke[i]=0

f={}
f[0]=0 #番号を段数と一致させるため
num=0 #N段までの行き方
check=0 #行けるかどうか

for i in range(M):
    a.append(int(input()))
    n=a[i]
    broke[n]=1 #ｎ段目が壊れていることを記憶
    f[n]=0

for i in range(M-1): #壊れている階段同士の差が１の場所があるか調べる。
    dif=a[i+1]-a[i]
    if dif==1:
        check=1
        break
        
if (1 in a)==True: #１が壊れているとき
    f[1]=0
else:
    f[1]=1
if (2 in a)==True: #２が壊れているとき
    f[2]=0
elif f[1]==0: #１が壊れているとき
    f[2]=1
else:
    f[2]=2

if check==0:
    for i in range(1,N-1): #1~N-2
        if broke[i+2]==1:
            continue
        f[i+2]=f[i+1]+f[i]
    num=f[N]

#for i in range(N+1):
    #print(str(i)+":"+str(f[i]))
print(num%1000000007)
#print(broke)

Measured memory_bytes: 477924
import sys
sys.setrecursionlimit(100000)

cnt = 0
num = ""
X = int(input())
def dfs(num,is3,is5,is7):
    global cnt
    if is3 and is5 and is7:
        cnt += 1 
    N = "357"
    for n in N:
        next_v = num + n
        if int(num+n) > X: continue #終了条件
        # 次の状態遷移
        dfs(next_v,is3 or n=="3",is5 or n=="5",is7 or n=="7")

dfs("0",0,0,0)
print(cnt)

Measured memory_bytes: 3188
#include<iostream>
#include<set>

int main(void){
    int n;
    std::cin >> n;
    std::string st;
    std::set<std::string> s;

    for(int i = 0; i < n; i++){
	std::cin >> st;
	s.insert(st);
    }
    std::cout << s.size() << std::endl;
    return 0;
}



Measured memory_bytes: 19204
#include<stdio.h>
int main(void){
    int in;
    int h, m, s;
    scanf("%d",&in);
    
    h =in/3600;
    in %=3600;
    
    m =in/60;
    in %=60;
    
    s = in;
    
    printf("%d:%d:%d\n",h,m,s);
    
}


Measured memory_bytes: 2104