akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stdio.h>
using namespace std;
const int UP=0;
const int FLONT=1;
const int RIGHT=2;
const int LEFT=3;
const int BACK=4;
const int DOWN=5;
class Dice{
 public:
  Dice();~Dice();
  int num[6];
  void set_num(int n,int i);
  void spin(char c);
  void spin_n(int n);
  int get_num(int n);
};
Dice::Dice(){}
Dice::~Dice(){}
void Dice::set_num(int n,int i){num[i]=n;}
int Dice::get_num(int n){return num[n];}
void Dice::spin(char c){
  int temp;
  if(c=='S'){
    temp=num[0];
    num[0]=num[4];
    num[4]=num[5];
    num[5]=num[1];
    num[1]=temp;
  }if(c=='N'){
temp=num[0];
    num[0]=num[1];
    num[1]=num[5];
    num[5]=num[4];
    num[4]=temp;
  }if(c=='W'){
    temp=num[0];
    num[0]=num[2];
    num[2]=num[5];
    num[5]=num[3];
    num[3]=temp;
  }if(c=='E'){
temp=num[0];
    num[0]=num[3];
    num[3]=num[5];
    num[5]=num[2];
    num[2]=temp;
  }if(c=='X'){
    temp=num[1];
    num[1]=num[2];
    num[2]=num[4];
    num[4]=num[3];
    num[3]=temp;
  }
}
void Dice::spin_n(int n){
  if(n>=0&&n<4)spin('S');
  else spin('E');
}
bool check(int a[],int b[],int n){
  for(int i=0; i<n; i++){
    if(a[i]!=b[i])break;
    if(i==n-1)return true;
  }
  return false;
}
int main(){                                                  
  int q,a,b=0,ans;
  Dice *m_Dice;
  m_Dice=new Dice;
  Dice *m_Dice2;
  m_Dice2=new Dice;
  for(int i=0; i<6; i++){
    int n;
    cin>>n;
    m_Dice->set_num(n,i);
  }
  for(int i=0; i<6; i++){
    int n;
    cin>>n;
    m_Dice2->set_num(n,i);
  }
   // for(int i=0; i<4; i++){
   //  if(m_Dice->get_num(0)==m_Dice2->get_num(0))break;
   //  m_Dice2->spin('S');
   //  //printf("%d %d\n",m_Dice->get_num(0),m_Dice2->get_num(0));
   // }
   // for(int i=0; i<4; i++){
   //  if(m_Dice->get_num(0)==m_Dice2->get_num(0))break;
   //  m_Dice2->spin('E');
   //  //printf("%d %d\n",m_Dice->get_num(0),m_Dice2->get_num(0));
   // }
   // for(int i=0; i<4; i++){
   //  if(m_Dice->get_num(FLONT)==m_Dice2->get_num(FLONT))break;
   //  m_Dice2->spin('X');
   //  //printf("%d %d\n",m_Dice->get_num(1),m_Dice2->get_num(1));
   // }
   // for(int i=0; i<6; i++){
   //  //printf("%d %d\n",m_Dice->get_num(i),m_Dice2->get_num(i));
   //  if(m_Dice->get_num(i)!=m_Dice2->get_num(i))break;
   //  if(i==5)b=1;
   // }
   // if(b)printf("Yes\n");
   // else printf("No\n");
  for(int i=0; i<7; i++){
    if(check(m_Dice->num,m_Dice2->num,6)){b=1; break;}
    m_Dice2->spin_n(i);
    for(int j=0; j<4; j++){
      if(check(m_Dice->num,m_Dice2->num,6)){b=1; break;}
      m_Dice2->spin('X');
    }
    if(b)break;
  }
  if(b)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  delete m_Dice;
  delete m_Dice2;
  return 0;
}

Measured memory_bytes: 1192
#include<iostream>
#include<string>
#include <cmath>
#include <ctype.h>
#include<vector>
using namespace std;
int N, M;
vector<string> A;
vector<string> B;

int main() {
    cin >> N >> M;
    cin.ignore();
    for(int i=0; i<N; ++i){
        string str; 
        getline(cin, str);
        A.push_back(str);
    }
    for(int i=0; i<M; ++i){
        string str; 
        getline(cin, str);
        B.push_back(str);
    }
    bool flag=false;
    for(int i=0; i<N; ++i){
        for(int j=0; j<N; ++j){
            if(i+M-1>=N or j+M-1>=N) continue;
                bool match=true;
                for(int k=0; k<M; ++k){
                    for(int l=0; l<M; ++l){
                        if(B[k][l]!=A[i+k][j+l]) match = false;
                    }
                }             
                if(match) flag = true;
        }
    }
    if(flag) cout <<"Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
#define vec(s) vector
;
#define vvec(s) vector<vector
> ;
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout<<(bool x?"Yes":"No")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " ";
#define INF 10000000000
#define all(s) s.begin(),s.end()
void vout(vector<int> v){
    for(int i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    lli n;
    cin>>n;
    lli i=1;
    vi fr,ba;
    while(i<=n){
        lli a;
        cin>>a;
        if(i%2==1){
            ba.push_back(a);
        }
        else{
            fr.push_back(a);
        }
        i++;
    }
    if(n%2==1){
        reverse(all(ba));
        rep(i,ba.size()){
            cout<<ba[i]<<" ";
        }
        rep(i,fr.size()){
            cout<<fr[i];
            if(i==fr.size()-1){
                cout<<endl;
            }
            else{
                cout<<" ";
            }
        }
    }
    else{
        reverse(all(fr));
        rep(i,fr.size()){
            cout<<fr[i]<<" ";
        }
        rep(i,ba.size()){
            cout<<ba[i];
            if(i==ba.size()-1){
                cout<<endl;
            }
            else{
                cout<<" ";
            }
        }
    }
}

Measured memory_bytes: 3948
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const long long infll = (long long) 1.01e18;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

int n;
string s;
char tmp[100];

int read() {
  if (scanf("%s", tmp) < 1) {
    return false;
  }
  s = tmp;
  n = sz(s);
  return true;
}

void solve() {
  int res = 0;
  for (int i = 0; i < n; i++) {
    res += (s[i] - '0');
  }
  for (int i = 0; i < n; i++) {
    if (s[i] == '0') {
      continue;
    }
    int cur = 0;
    for (int j = 0; j < i; j++) {
      cur += (s[j] - '0');
    }
    cur += (s[i] - '0') - 1;
    for (int j = i + 1; j < n; j++) {
      cur += 9;
    }
    res = max(res, cur);
  }
  printf("%d\n", res);
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 764
n = int(raw_input())

root_n = int(n ** 0.5)

ans = 0
for i in range(1, root_n + 1):
    if n % i == 0:
        a = i
        b = n / i

        m = a - 1
        k = b
        if 0 < k < m:
            ans +=m

        m = b - 1
        k = a
        if 0 < k < m:
            ans += m

print(ans)


Measured memory_bytes: 34436
// 15:03-

#include <bits/stdc++.h>

#include <iostream>
using namespace std;

#define EACH(i, a) for (auto &&i : a)
#define FOR(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RFOR(i, a, b) for (int i = (int)b - 1; i >= (int)a; --i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREPS(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(x) (x).begin(), (x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define debug(x) cout << #x << ": " << x << endl

#define pb push_back
#define mp make_pair
#define F first
#define S second

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define INF (1L << 30)
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

template <class T>
void pv(T a, T b) {
  for (T i = a; i != b; ++i) cout << *i << " ";
  cout << endl;
}
template <class T>
void pvp(T a, T b) {
  for (T i = a; i != b; ++i)
    cout << "(" << i->first << ", " << i->second << ") ";
  cout << endl;
}
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;
}
int in() {
  int x;
  scanf("%d", &x);
  return x;
}

using ll = long long;
#define int ll

//***** basic func *****//
int power_mod(int a, int b) {
  // return (a**b)%MOD (O(log b))
  int res = 1;
  while (b > 0) {
    if (b & 1) {
      res *= a;
      res %= MOD;
    }
    a *= a;
    a %= MOD;
    b >>= 1;
  }
  return res;
}

// int fact[510000], fact_inv[510000];  // n!, (n!)^-1 mod MOD
// // calc fact (in main routine)
// fact[0] = 1;
// REP(i, n) { fact[i + 1] = fact[i] * (i + 1) % MOD; }
// fact_inv[n] = power_mod(fact[n], MOD - 2);
// RREP(i, n) { fact_inv[i] = fact_inv[i + 1] * (i + 1) % MOD; }
// int comb_mod(int n, int r) {
//   return ((fact[n] * fact_inv[r]) % MOD * fact_inv[n - r] % MOD);
// }

//**********

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

  int N, M;
  int x[1000], y[1000], z[1000];
  cin >> N >> M;
  REP(i, N) { cin >> x[i] >> y[i] >> z[i]; }

  int ans = 0;
  int total[8][1000];
  REP(i, N) {
    REP(j, 8) {
      if (j & 4) {
        total[j][i] = x[i];
      } else {
        total[j][i] = -x[i];
      }
      if (j & 2) {
        total[j][i] += y[i];
      } else {
        total[j][i] += -y[i];
      }
      if (j & 1) {
        total[j][i] += z[i];
      } else {
        total[j][i] += -z[i];
      }
    }
  }
  REP(i, 8) { sort(total[i], total[i] + N); }
  REP(i, 8) {
    // debug(i);
    int sum = 0;
    REP(j, M) {
      sum += total[i][N - 1 - j];
      // debug(total[i][N - 1 - j]);
    }
    chmax(ans, sum);
    // debug(sum);
  }

  cout << ans << endl;

  return 0;
};


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n], b[n], d[n-1];
    for(int i=0; i<n; i++)
    {
        cin>>a[i];
    }
    for(int i=0; i<n; i++)
    {
        cin>>b[i];
    }
    for(int i=0; i<n-1; i++)
    {
        cin>>d[i];
    }
    int c=b[a[0]-1];
    for(int i=1; i<n; i++)
    {
        c+=b[a[i]-1];
        if(a[i-1]+1==a[i])
        {
            c+=d[a[i-1]-1];
        }
    }
    cout<<c<<endl;
}

Measured memory_bytes: 3616
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int maxn = 1e5 + 100;
char S[maxn], S2[maxn];
int main()
{
    cin>>S;
    int L = strlen(S), L2 = 0;
    for(int i = 0; i < L; i++) if(S[i] != 'x') S2[L2++] = S[i];
    int fail = 0;
    for(int i = 0; i < L2; i++)
        if(S2[i] != S2[L2-i-1]) { fail = 1; break;}
    if(fail){
        cout<<"-1"<<endl;
        return 0;
    }
    int i = 0, j = L-1, ans = 0, l = 0, r = 0;
    while(i <= j){
        if(S[j] == 'x') { j--; continue; }
        if(S[i] == 'x') { i++; continue; }
        int x = i+l, y = L-j-1+r;
        if(x == y) { i++; j--; continue; }
        if(x < y){
            l += y-x;
            ans += y-x;
        } else {
            r += x-y;
            ans += x-y;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 384
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Objects;
import java.util.Scanner;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
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);
        DGatheringChildren solver = new DGatheringChildren();
        solver.solve(1, in, out);
        out.close();
    }

    static class DGatheringChildren {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // R..RL..Lの塊を探す
            char[] s = in.next().toCharArray();

            ArrayList<Vec2i> rl = new ArrayList<>();
            int r = 1;
            int l = 0;


            for (int i = 1; i < s.length; i++) {
                if (s[i] == 'R' && s[i - 1] == 'L') {
                    rl.add(new Vec2i(r, l));
                    r = 1;
                    l = 0;
                } else if (s[i] == 'R') {
                    r++;
                } else {
                    l++;
                }
            }
            rl.add(new Vec2i(r, l));

            int index = -1;
            int[] ans = new int[s.length];

            for (Vec2i v : rl) {
                index += v.x;
                ans[index++] = MathUtil.ceil(v.x, 2) + v.y / 2;
                ans[index] = v.x / 2 + MathUtil.ceil(v.y, 2);
                index += v.y - 1;
            }

            for (int i = 0; i < ans.length; i++) {
                out.print(ans[i] + (i == ans.length - 1 ? "\n" : " "));
            }


        }

    }

    static class Vec2i {
        public int x;
        public int y;

        public Vec2i(int x, int y) {
            this.x = x;
            this.y = y;
        }

        public String toString() {
            return "Vec2i{" +
                    "x=" + x +
                    ", y=" + y +
                    '}';
        }

        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            Vec2i vec2i = (Vec2i) o;
            return x == vec2i.x &&
                    y == vec2i.y;
        }

        public int hashCode() {
            return Objects.hash(x, y);
        }

    }

    static class MathUtil {
        public static int ceil(int i1, int i2) {
            return (i1 - 1 + i2) / i2;
        }

    }
}



Measured memory_bytes: 43740
// 解説後
#include <algorithm>
#include <iostream>
#include <unordered_map>
#include <vector>

// 試合の識別子を作る関数
// a<bのときをb優先で数えたときの値を返す
inline uint32_t make_id(uint32_t a, uint32_t b, uint32_t N) noexcept {
  if (a > b) std::swap(a, b);
  const uint32_t offset = a + 1 + a * (a + 1) / 2;  // a>=bのときを数えないためのオフセット。初項1、公差1の等比数列のn=a+1までの和
  return a * N + b - offset;
}

// 全日程を完遂するには試合日程の前後関係が矛盾しなければ良い
// => 試合日程の前後関係をグラフにしたとき、閉路が存在しなければ良い
//
// 全試合の日数はそれ以前にやるべき試合がないものから順にこなしていくことで計算できる
// => 試合日程の前後関係のグラフにおいて、入次数が0の頂点を順々にグラフから切り離していく操作に相当する
// => 全試合の日数は最大経路の頂点数に等しい
int solve_E() {
  uint32_t N = 0;  // 選手の人数
  std::cin >> N;
  const uint32_t num_ids = (N - 1) + (N - 1) * (N - 2) / 2;
  const uint32_t max_id = num_ids - 1;

  // 試合日程の前後関係の有向グラフを作る
  std::unordered_map<uint32_t, std::vector<uint32_t>> graph;
  for (uint32_t i = 0; i < N; ++i) {
    uint32_t a;
    std::cin >> a;
    for (uint32_t j = 1; j <  N - 1; ++j) {
      uint32_t b;
      std::cin >> b;
      graph[make_id(i, a - 1, N)].push_back(make_id(i, b - 1, N));
      a = b;
    }
  }

  // 試合日程の前後関係のグラフの最長経路を調べる
  std::vector<uint32_t> stack;
  stack.reserve(num_ids);
  std::vector<bool> visited(num_ids);
  std::vector<bool> finished(num_ids);
  std::vector<size_t> distances(num_ids);  // idから終点までの経路長
  size_t result = 0;  // 経路の最大長
  for (uint32_t start_id = 0; start_id < num_ids; ++start_id) {
    // 頂点が訪問済みでなければ、そこからの最長経路を計算する
    if (!visited[start_id]) {
      // 深さ優先探索
      stack.push_back(start_id);
      visited[start_id] = true;
      while (true) {
        const uint32_t id = stack.back();

        // 子供を調べる
        bool all_visited = true;  // すべての子供が訪問済みかどうか
        size_t max_distance = 0;  // 子供の経路の最大長
        for (auto child : graph[id]) {
          // 未訪問でれば、それに訪問する
          if (!visited[child]) {
            stack.push_back(child);
            visited[child] = true;
            all_visited = false;
            break;
          }

          // 閉路が存在すれば、その日程は完遂できない
          if (!finished[child]) {
            std::cout << "-1";
            return 0;
          }

          // 子から終点までの最大長を計算する
          max_distance = std::max(max_distance, distances[child]);
        }

        // すべての子供に訪問済みであれば、ひとつ前に戻る
        if (all_visited) {
          stack.pop_back();
          finished[id] = true;
          distances[id] = max_distance + 1;
          if (stack.empty()) break;
        }
      }
    }

    // グラフ全体での経路の最大長を計算する
    result = std::max(result, distances[start_id]);
  }

  // 結果発表
  std::cout << result;
  return 0;
}

int main() { return solve_E(); }


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion
#pragma region chminmax
template <typename T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <typename T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
#pragma endregion

vector<int> dp(100005, -1);
vector<vector<int>> g(100005, vector<int>());

int dfs(int v)
{
    if (dp[v] != -1)
    {
        return dp[v];
    }
    int maxLen = 0;
    for (int child : g[v])
    {
        chmax(maxLen, dfs(child) + 1);
    }

    return dp[v] = maxLen;
}

int main()
{
    int n, m;
    cin >> n >> m;
    rep(i, m)
    {
        int from, to;
        cin >> from >> to;
        from--;
        to--;
        g[from].emplace_back(to);
    }
    int ans = 0;
    rep(i, n)
    {
        chmax(ans, dfs(i));
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 8192
/* [Template].cpp 
Example code to use when starting new code. This particular problem was problem 
977A_Wrong_Subtraction from CodeForces

Compile: g++  -o A_AC_or_WA.exe A_AC_or_WA.cpp 
Execute: ./A_AC_or_WA
*/ 

#include <cstdio>
#include <iostream>
#include <cmath> 
#include <iomanip>
using namespace std;

int main() { 	
	int N, M;
	cin >> N >> M;
	
	if( N == M ) { 
		cout << "Yes" << endl; 
	} else { 
		cout << "No" << endl; 
	} 
	
	return 0; 
} 


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    string s;
    while(getline(cin, s)){
        stringstream in;
        in << s;
        stack<double> S;
        while(!in.eof()){
            string x;
            in >> x;
            if(x == "+" || x == "*" || x == "/" || x == "-"){
                double b = S.top(); S.pop(); double a = S.top(); S.pop();
                if(x == "+") S.emplace(a+b);
                else if(x == "*") S.emplace(a*b);
                else if(x == "/") S.emplace(a/b);
                else S.emplace(a-b);
            }else {
                S.emplace(stod(x));
            }
        }
        printf("%.10lf\n", S.top());
    }
    return 0;
}


Measured memory_bytes: 3260
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;

namespace AtCoder.Abc
{
    public class QuestionA
    {
        public static void Main(string[] args)
        {
            int[] LRd = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            int L = LRd[0], R = LRd[1], d = LRd[2];
            int count = 0;
            for (int i = L; i <= R; i++) {
                if (i % d == 0) {
                    count++;
                }
            }
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 28288
#include <iostream>
#include <vector>
#include <string>
#include <sstream>

std::vector<std::string> split(std::string &str, char delim) {
	std::vector<std::string> result;
	std::istringstream is(str);
	std::string buf;
	while (getline(is, buf, delim)) {
		result.push_back(buf);
	}
	return result;
}

bool inputDataSet(std::vector<int> *l, int *v1, int *v2) {
	std::string line;
	if (!getline(std::cin, line)) { return false; }
	std::vector<std::string> tokens = split(line, ',');
	if (tokens.size() != 12) { return false; }
	for (int i = 0; i < 10; ++i) {
		std::istringstream is(tokens[i]);
		if (!(is >> (*l)[i])) { return false; }
	}
	std::istringstream is1(tokens[10]), is2(tokens[11]);
	if (!((is1 >> *v1) && (is2 >> *v2))) { return false; }
	return true;
}

template <class Iterator>
int sum(Iterator first, Iterator last) {
	int sum = 0;
	for (; first != last; ++first) { sum += *first; }
	return sum;
}

int main() {
	std::vector<int> l(10);
	int v1, v2;
	while (inputDataSet(&l, &v1, &v2)) {
		const int x1 = 0, x2 = sum(l.begin(), l.end());
		v2 = -v2;
		if (v1 == v2) { continue; }	// ツ堕環妥篠堕ャツ度 0 ツづ按づァツ古ーツ債キツつオツづ按つ「
		const double x = static_cast<double>(x1) + static_cast<double>(-(x1 - x2) * v1) / static_cast<double>(v1 - v2);	// ツ渉ャツ青板つェツ静伉偲個づつウツづェツづゥツづ債「ツづゥ
		int n = 0, sum = 0;
		for (std::vector<int>::iterator it = l.begin(); it != l.end() && static_cast<double>(sum) < x; ++it) {
			sum += *it;
			++n;
		}
		std::cout << n << std::endl;
	}
	return 0;
}

Measured memory_bytes: 0
a, b, c, k = map(int, input().split())

if k % 2 == 1:
    x = -a + b
    if abs(x) > 1e18:
        print("Unfair")
    else:
        print(x)
else:
    x = a - b
    if abs(x) > 1e18:
        print("Unfair")
    else:
        print(x)

Measured memory_bytes: 2940
n = int(input())
a = list(map(int, input().split()))
#n, x, t = map(int, input().split())
#n = input
ans = 0
max = a[0]
if n == 1:
  ans = 0
else:
  for i in range(n-1):
    if a[i+1] >= max:
      max = a[i+1]
    else:
      ans += (max - a[i+1])
print(ans)

Measured memory_bytes: 32232
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
#define INF 10000;


int main() {
    int N, A, B, C;
    cin >> N >> A >> B >> C;
    vector<int>l(N);
    for (int i = 0; i < N; i++) {
        cin >> l[i];
    }

    int ans = INF;
    for (int i = 0; i < 1 << (N*2); i++) {
        int la = 0, lb = 0, lc = 0;
        int a = 0, b = 0, c = 0;
        for (int j = 0; j <N; j++) {
            switch (0b11&(i>>(j*2))){
            case 0:
                break;
            case 1:
                la += l[j];
                a++;
                break;
            case 2:
                lb += l[j];
                b++;
                break;
            case 3:
                lc += l[j];
                c++;
                break;
            }
        }
        if (!(a&&b&&c))continue;
        int prov = abs(A - la) + abs(B - lb) + abs(C - lc) + 10 * (a + b + c - 3);
        if (prov < ans)ans = prov;
    }
    
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
    
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
    
#define int long long
#define double long double
    
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
    
#define ff first
#define ss second
#define mp make_pair
         
#define pb push_back
#define endl "\n" 
         
#define f(i,l,r) for(int i=l;i<=r;i++)
#define rf(i,r,l) for(int i=r;i>=l;i--)    

#define bp __builtin_popcountll
#define inf 1e18
    
const int N=1e6+5;
const int M=1e9+7;
void solve()
{
	string s;
	cin>>s;
	cout<<s[0]<<s[1]<<s[2];
}
signed main()  
{
	FAST
    int t=1;
    // cin>>t;
    for(int tc=1;tc<=t;tc++)
    {
    	// cout<<"Case #"<<tc<<": ";
    	solve();
    }
}


Measured memory_bytes: 3612
// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 06/21/20 20:55:02
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  int n; cin>>n;
  map<int,int> amap;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    int a; cin>>a;
    amap[a]++;
    sum += a;
  }
  int q; cin>>q;
  while (q--) {
    int b,c; cin>>b>>c;
    auto cnt = amap[b];
    amap[b] = 0;
    amap[c] += cnt;
    sum += (long long)(c-b) * cnt;
    cout << sum << endl;
  }

  return 0;
}


Measured memory_bytes: 8012
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); ++i)
using ll = long long;
using pll = pair<ll,ll>;
const ll INF64 = 1LL << 60;
const int INF = (1 << 29);

int main(){
    int n,m; cin >> n >> m;
    priority_queue<ll> que;
    rep(i,n){
        ll a; cin >> a;
        que.push(a);
    }

    rep(_,m){
        ll x = que.top(); que.pop();
        x /= 2;
        que.push(x);
    }

    ll ans = 0;
    while(!que.empty()){
        ll x = que.top(); que.pop();
        ans += x;
    }

    cout << ans << endl;
}

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

public class Main {

	void solve() {
		out.println(in.nextToken().contains("AC") ? "Yes" : "No");
	}

	FastScanner in;
	PrintWriter out;

	void run() {
		in = new FastScanner();
		out = new PrintWriter(System.out);
		solve();
		out.close();
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		public FastScanner(String s) {
			try {
				br = new BufferedReader(new FileReader(s));
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		public String nextToken() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
				}
			}
			return st.nextToken();
		}

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

		public long nextLong() {
			return Long.parseLong(nextToken());
		}

		public double nextDouble() {
			return Double.parseDouble(nextToken());
		}
	}

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


Measured memory_bytes: 21076
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>

using namespace std;

typedef long long ll;
typedef long double ld;

#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#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(c) c.begin(),c.end()
#define psb push_back
#define ppb pop_back

const int I_INF = 1001001001;
const ll LL_INF = 1001001001001001001;
const ld EPS = 0.001;

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

    vl p(N);
    rep (i, N) cin >> p[i];

    sort(all(p));
    ll sum = 0;
    rep (i, K) sum += p[i];

    cout << sum << endl;
}


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

#define int				long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define FORE( i, m, n ) FOR( i, m , n + 1 )
#define REP( i, n )     FOR( i, 0, n )
#define REPE( i, n )	FOR( i, 0, n + 1 )
#define FORR( i, m )	for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )	FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()             
#define MP( a, b )		make_pair( (a), (b) )
#define fi				first
#define se				second

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( a > b ) { a = b; return 1; } return 0; }

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

signed main() {
	int N, M; cin >> N >> M;

	int a, b, amax = 0, bmin = INF,res = 0;
	REP( i, M ) {
		cin >> a >> b;
		chmax( amax, a );
		chmin( bmin, b );
	}

	res = bmin - amax;
	if( res >= 0 ) res++;
	chmin( res, N );
	if( res < 0 ) res = 0;

	cout << res << endl;

}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef vector<int>::iterator vit;

ll a[100001];
ll m[100001];
map<int,int> ma;
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; ll t;
	cin>>n>>t;
	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
		ma[a[i]]++;
	}
	ll maxdiff = 0; int ans = 0; int ans2 = 0;
	for(int i = n - 1; i >= 0; i--)
	{
		m[i] = a[i];
		if(i<n-1) m[i]=max(m[i],m[i+1]);
	}
	set<int> s;
	for(int i = 0; i < n - 1; i++)
	{
		ma[a[i]]--;
		ll m2 = m[i+1];
		if(m2 - a[i] > maxdiff)
		{
			s.clear();
			maxdiff = m2 - a[i];
			ans = ma[m2];
			s.insert(m2);
			ans2 = 1;
		}
		else if(m2 - a[i] == maxdiff)
		{
			ans2++;
			if(s.find(m2)==s.end())
			{
				s.insert(m2);
				ans += ma[m2];
			}
		}
	}
	cout<<min(ans,ans2)<<'\n';
}


Measured memory_bytes: 8832
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<string>
#include<vector>
#include<queue>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> PP;
#define INF (1<<25)
int N,M;
struct edge{
  int to,c;
  edge(int to,int c) : to(to),c(c) {}
};

vector<edge> G[102];
int H[102][3];

void solve(){
  priority_queue<PP,vector<PP>,greater<PP> > q;
  while(!q.empty()) q.pop();
  for(int i=0;i<102;i++){
    H[i][0]=INF; H[i][1]=INF; H[i][2]=INF;
  }

  q.push( PP(0,P(1,0)) );
  while(!q.empty()){
    PP p = q.top(); q.pop();
    int ind = p.second.first;
    int in = p.second.second;
    int cost = p.first;
    for(int i=0;i<(int)G[ind].size();i++){
      edge e = G[ind][i];
      if(in == 0){
	if(H[e.to][1] > cost){
	  q.push( PP(cost,P(e.to,1)) );
	  H[e.to][1] = cost;
	}
	if(H[e.to][in] > cost + G[ind][i].c){
	  q.push( PP(cost+G[ind][i].c,P(e.to,in)) );
	  H[e.to][in] = cost+G[ind][i].c;
	}
      }else if(in == 1){
	if(H[e.to][2] > cost){
	  q.push( PP(cost,P(e.to,2)) );
	  H[e.to][2] = cost;
	}
      } else {
	if(H[e.to][in] > cost + G[ind][i].c){
	  q.push( PP(cost+G[ind][i].c,P(e.to,in)) );
	  H[e.to][in] = cost+G[ind][i].c;
	}
      }
    }
  }
}

int main(){
  while(1){
    scanf("%d %d",&N,&M);
    if(!N && !M) break;
    for(int i=0;i<M;i++){
      int a,b,c;
      scanf("%d %d %d",&a,&b,&c);
      G[a].push_back(edge(b,c));
      G[b].push_back(edge(a,c));
    }
    solve();
    printf("%d\n",min(H[N][0],H[N][2]));
    for(int i=0;i<102;i++) G[i].clear();
  }
}

Measured memory_bytes: 1208
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    //cout.precision(10);
    string s;
    cin >> s;
    int w;
    cin >> w;
    for(int i = 0; i < s.size(); i++){
        if(i % w == 0){
            cout << s[i];
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#include <numeric>
#define IINF 1000000000
#define INF 9223372036854775807
#define MOD 1000000007
#define mod 998244353
#define INT_MAX_ 2147483647
#define EPS (1e-10)
#define REP(i, a, n) fo-r (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
//#define rep(i,n)for (ll i = 0; i < (ll)(n); i++)
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
#define me memset
#define bit(n,k) ((n>>k)&1)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T> >;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp1(pair<ll,ll> a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi>b.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_t=clock();
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //------------------------------
    ll ans=0;
    ll n;cin>>n;
    for(ll i=1;i<=n;i++){
        ll j =n/i;
        ll k = j*i;
        ans+=(i+k)*j/2;
    }
    cout<<ans<<endl;
    //------------------------------
    //fclose(stdin);
    //fclose(stdout);
    //ll end_t=clock();cout<<"time="<<end_t-begin_t<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------








































Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <cmath>
#include <iomanip>
#include <vector>
#include <queue>
#include <functional>
#include <random>
#include <ctime>

using namespace std;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef long long int ll;
typedef pair<ll, ll> P;

struct UnionFind {
    vector<int> par;
    vector<int> sizes;

    UnionFind(int n) : par(n), sizes(n, 1) {
        REP(i, n) par[i] = i;
    }

    int find(int x) {
        if (x == par[x]) return x;
        return par[x] = find(par[x]);
    }

    void unite(int x, int y) {
        x = find(x);
        y = find(y);

        if (x == y) return;

        if (sizes[x] < sizes[y]) swap(x, y);

        par[y] = x;
        sizes[x] += sizes[y];
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }
};

int main() {
    int a, b;
    cin >> a >> b;
    vector<int> c;
    c.resize(a);
    REP(i, a) {
        int d;
        cin >> d;
        c[i] = d - 1;
    }
    UnionFind uni(a);
    REP(i, b) {
        int d, e;
        cin >> d >> e;
        uni.unite(d - 1, e - 1);
    }
    int ans = 0;
    REP(i, a) {
        if (uni.same(i, c[i])) ans++;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 1408
//#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<cmath>
#include<map>
#include<unordered_map>
#include<functional>
#include<queue>
#include<set>
#include<stack>
#include<iomanip>
#include<algorithm>
#include<numeric>
#include<memory>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a)   a.begin(),a.end()
template<typename T =ll> using v = vector<T>;
template<typename T =ll> using vv = v<v<T>>;
template<typename T =ll,typename U =ll> using p = pair<T,U>;
template<typename T> T chmin(T &a,T b) {return a=min(a,b);}
template<typename T> T chmax(T &a,T b) {return a=max(a,b);}
const ll INF = (ll)1e9;
template <int MOD>
struct ModInt {
    using lint = long long;
    int val;

    // constructor
    ModInt(lint v = 0) : val(v % MOD) {
        if (val < 0) val += MOD;
    };

    // unary operator
    ModInt operator+() const { return ModInt(val); }
    ModInt operator-() const { return ModInt(MOD - val); }
    ModInt inv() const { return this->pow(MOD - 2); }

    // arithmetic
    ModInt operator+(const ModInt& x) const { return ModInt(*this) += x; }
    ModInt operator-(const ModInt& x) const { return ModInt(*this) -= x; }
    ModInt operator*(const ModInt& x) const { return ModInt(*this) *= x; }
    ModInt operator/(const ModInt& x) const { return ModInt(*this) /= x; }
    ModInt pow(lint n) const {
        auto x = ModInt(1);
        auto b = *this;
        while (n > 0) {
            if (n & 1) x *= b;
            n >>= 1;
            b *= b;
        }
        return x;
    }

    // compound assignment
    ModInt& operator+=(const ModInt& x) {
        if ((val += x.val) >= MOD) val -= MOD;
        return *this;
    }
    ModInt& operator-=(const ModInt& x) {
        if ((val -= x.val) < 0) val += MOD;
        return *this;
    }
    ModInt& operator*=(const ModInt& x) {
        val = lint(val) * x.val % MOD;
        return *this;
    }
    ModInt& operator/=(const ModInt& x) { return *this *= x.inv(); }
    //
    ModInt operator++(int) {
        auto t = *this;
        *this += 1;
        return t;
    }

    ModInt operator--(int) {
        auto t = *this;
        *this -= 1;
        return t;
    }
    ModInt operator<<(const int n){
        return ModInt(*this)*ModInt(2).pow(n);
    }
    // compare
    bool operator==(const ModInt& b) const { return val == b.val; }
    bool operator!=(const ModInt& b) const { return val != b.val; }

    // I/O
    friend std::istream& operator>>(std::istream& is, ModInt& x) noexcept { return is >> x.val; }
    friend std::ostream& operator<<(std::ostream& os, const ModInt& x) noexcept { return os << x.val; }
};

constexpr int MOD = 1e9 + 7;
using mint = ModInt<MOD>;

void a(){
    auto A = v<>(3,0);
    cin >> A[0] >> A[1] >> A[2];
    sort(all(A));
    rep(i,3){
        if(A[i]%2==0){
            cout << 0 << endl;
            return ;
        }   
    }

    cout << abs(A[2]/2 -(A[2]+1)/2)*A[0]*A[1] << endl;
 
}

int main(){
    a();
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

const int N = 200005;

int n, fen[N];
string s;
vector <int> v[26];

int query(int ind){
    ind++;
    int ret = 0;
    while(ind >= 1){
        ret += fen[ind];
        ind -= ind & -ind;
    }
    return ret;
}
void update(int ind, int val){
    ind++;
    while(ind <= n){
        fen[ind] += val;
        ind += ind & -ind;
    }
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> s;
    n = s.size();
    for(int i = 0 ; i < n ; i++){
        v[s[i] - 'a'].push_back(i);
    }
    int f = -1;
    for(int i = 0 ; i < 26 ; i++){
        if(v[i].size() % 2){
            if(f != -1) finish(-1);
            f = i;
        }
    }
    vector <int> p(n, -1);
    if(f != -1){
        p[v[f][v[f].size() / 2]] = n / 2;
    }
    int idx = 0;
    for(int i = 0 ; i < n ; i++){
        auto &cur = v[s[i] - 'a'];
        int c = lower_bound(cur.begin(), cur.end(), i) - cur.begin();
        if(c >= (int)cur.size() / 2) continue;
        p[cur[c]] = idx;
        p[cur[(int)cur.size() - c - 1]] = n - idx - 1;
        idx++;
    }
    ll ans = 0;
    for(int i = n - 1 ; i >= 0 ; i--){
        ans += query(p[i]);
        update(p[i], 1);
    }
    cout << ans << endl;
}


Measured memory_bytes: 5992
#pragma region template
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template <typename T>
using pqrev = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for (ll i = 0, i##_end = (n); i < i##_end; i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for (ll i = (a), i##_end = (b); i < i##_end; i++)
#define reprb(i, a, b) for (ll i = (b)-1, i##_end = (a); i >= i##_end; i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
//*
constexpr ll MOD = 1e9 + 7;
/*/
constexpr ll MOD = 998244353;
//*/
constexpr ll INF = 1e+18;
constexpr ld EPS = 1e-12L;
constexpr ld PI = 3.14159265358979323846L;
constexpr ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
constexpr ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
template <typename S, typename T>
constexpr bool chmax(S &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename S, typename T>
constexpr bool chmin(S &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif
template <typename T>
bool print_(const T &a) {
  cout << a;
  return true;
}
template <typename T>
bool print_(const vector<T> &vec) {
  for (auto &a : vec) {
    cout << a;
    if (&a != &vec.back()) {
      cout << " ";
    }
  }
  return false;
}
template <typename T>
bool print_(const vector<vector<T>> &vv) {
  for (auto &v : vv) {
    for (auto &a : v) {
      cout << a;
      if (&a != &v.back()) {
        cout << " ";
      }
    }
    if (&v != &vv.back()) {
      cout << "\n";
    }
  }
  return false;
}
void print() { cout << "\n"; }
template <typename Head, typename... Tail>
void print(Head &&head, Tail &&... tail) {
  bool f = print_(head);
  if (sizeof...(tail) != 0) {
    cout << (f ? " " : "\n");
  }
  print(forward<Tail>(tail)...);
}
#pragma endregion

void Pr(bool f){
  cout << (f ? "Yes" : "No") << "\n";
  exit(0);
}
void M1(){
  cout << "-1\n";
  exit(0);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  ll n;
  cin >> n;
  n++;
  vll a(n);
  rep(i, n){
    cin >> a[i];
  }
  vll ma1(n), ma2(n);
  ma1[0] = 1;
  repr(i, 1, n){
    ma1[i] = (ma1[i-1]-a[i-1])*2;
    if(ma1[i] >= INF) ma1[i] = INF;
    if(ma1[i] <= 0){
      M1();
    }
  }
  ma2[n-1] = a[n-1];
  repb(i, n-1){
    ma2[i] = ma2[i+1]+a[i];
  }
  dump(ma1);
  dump(ma2);
  {
    ll m = 0;
    repb(i, n){
      m += a[i];
      if(m > ma1[i]){
        print(-1);
        return 0;
      }
      m = (m+1)/2;
    }
    dump(m);
  }
  ll ans = 0;
  rep(i, n){
    ans += min(ma1[i], ma2[i]);
  }
  print(ans);
}


Measured memory_bytes: 5848
def f_calc1(u1, d1, ans):
  u1.sort()
  d1.sort()

  i=0
  for x1, y1 in u1:
    while i < len(d1):
      x2, y2 = d1[i]
      if x1 < x2:
        break
      if x1 == x2:
        if y1 < y2:
          ans = min(ans, (y2-y1)*5)
          break
        i += 1
      else:
        i += 1
  return ans

def f_calc2(u1, d1, ans):
  u1.sort()
  d1.sort()

  i=0
  for x1, y1 in u1:
    while i < len(d1):
      x2, y2 = d1[i]
      if x1 < x2:
        break
      if x1 == x2:
        if y1 < y2:
          ans = min(ans, (y2-y1)*10)
          break
        i += 1
      else:
        i += 1
  return ans

n = int(input())

u1 = []
u2 = []
u3 = []
d1 = []
d2 = []
d3 = []
r1 = []
r2 = []
r3 = []
l1 = []
l2 = []
l3 = []

for _ in range(n):
  x,y,u = input().split()
  x = int(x)
  y = int(y)
  if u == 'U':
    u1.append([x, y])
    u2.append([x+y, y])
    u3.append([x-y, y])
  elif u == 'D':
    d1.append([x, y])
    d2.append([x+y, x])
    d3.append([x-y, x])
  elif u == 'R':
    r1.append([y, x])
    r2.append([x+y, y])
    r3.append([x-y, x])
  else:
    l1.append([y, x])
    l2.append([x+y, x])
    l3.append([x-y, y])
  
ans = 10**8
ans = f_calc1(u1, d1, ans)
ans = f_calc1(r1, l1, ans)
ans = f_calc2(u2, r2, ans)
ans = f_calc2(d2, l2, ans)
ans = f_calc2(u3, l3, ans)
ans = f_calc2(r3, d3, ans)

print(ans if ans < 10**8 else "SAFE")

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

int main() {
  int a, b;
  cin >> a >> b;
  if((a+b)%2 == 0) {
    std::cout << (a+b)/2 << endl;
  } else {
    std::cout << (a+b)/2+1 << '\n';
  }
  
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <stack>
#include <functional>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <numeric>

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF (int)1e9
#define INFL 1e18
#define MOD 1e9+7
#define pb push_back
#define MP make_pair
typedef long long int ll;
typedef std::pair<int,int> P;
int D=0;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

using namespace std;

typedef struct gotutiyan{
    vector<int> rank,par;
    void init(int n){
        rep(i,0,n){
            rank.pb(0);
            par.pb(i);
        }
    }
    
    int find(int x){
        if(par[x]==x)return x;
        else return par[x]=find(par[x]);
    }
    
    void unite(int x,int y){
        x=find(x);
        y=find(y);
        if(x==y)return;
        
        if(rank[x]<rank[y])par[x]=y;
        else {
            par[y]=x;
            if(rank[x]==rank[y])rank[x]++;
        }
    }
}UF;
int main() {
    int N,M;
    int ans=0;
    cin>>N>>M;
    vector<int> a(M),b(M);
    rep(i,0,M)cin>>a[i]>>b[i];
    rep(i,0,M){
        UF u;
        u.init(N);
        rep(j,0,M){
            if(i!=j)u.unite(a[j]-1,b[j]-1);
        }
        set<int> st;
        rep(j,0,N){
            st.insert(u.find(j));
            if(D)cout<<u.find(j)<<endl;   
        }
        if(st.size()>1)ans++;
        if(D)cout<<endl;
    }
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <cmath>
#include <stdio.h>

//void Aoj_learning8();
//void Aoj_learning8sub(int, int, int*, int*);
void Aoj_learning9();

int main()
{
	Aoj_learning9();

	return 0;
}

void Aoj_learning9()
{
	std::string sInput;
	std::istringstream ss;	// 汎用文字列ストリーム
	int* iStuck;			// 数値スタック
	iStuck = new int[200];
	int iStuckNum = 0;		// スタックの最後尾番号

	// ループはEOFを踏むまで
	while ( std::cin.eof() == 0 )
	{
		std::cin >> sInput;
		if (sInput == "+")
		{
			iStuck[iStuckNum - 2] = iStuck[iStuckNum - 2] + iStuck[iStuckNum - 1];
			iStuckNum--;
		}
		else if (sInput == "-")
		{
			iStuck[iStuckNum - 2] = iStuck[iStuckNum - 2] - iStuck[iStuckNum - 1];
			iStuckNum--;
		}
		else if (sInput == "*")
		{
			iStuck[iStuckNum - 2] = iStuck[iStuckNum - 2] * iStuck[iStuckNum - 1];
			iStuckNum--;
		}
		else
		{
			ss = std::istringstream(sInput);
			ss >> iStuck[iStuckNum];
			iStuckNum++;
		}
	}
	//最後に計算結果を出力
	std::cout << iStuck[0] << std::endl;
}


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

int main(){
    int n,k;
    cin>>n>>k;
    vector<int> H(n),dp(n,INF);
    dp[0]=0;
    for(int i=0; i<n; ++i) cin>>H[i];
    for(int i=0; i<n; ++i){
        for(int j=1;j<=k; ++j){
            if(i+j<n){
                dp[i+j]=min(dp[i+j], dp[i]+abs(H[i]-H[i+j]));
            }
        }
    }
    cout<<dp[n-1]<<"\n";
}


Measured memory_bytes: 1024