akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
  	int cnt = 0;
    int sum = 0;
    rep(i, 0, n){
        cin >> a[i];
        sum += abs(a[i]);
        if(a[i] < 0) cnt++;
    }
    if(cnt % 2){
        int MIN = INF;
        rep(i, 0, n) MIN = min(MIN, abs(a[i]));
        sum -= 2 * MIN;
    }
    cout << sum << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int a[100005];
bool cmp(int x,int y)
{
    return x>y;
}
int main()
{
   //freopen("t5.in","r",stdin);
   //freopen("t5.out","w",stdout);
   //ios::sync_with_stdio(false);
   //cin.tie(0); cout.tie(0);
    int i,j,n,m,p;
    cin>>n>>m>>p;
    cout<<p<<" "<<n<<" "<<m;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1LL << 60;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)
#define INF INT_MAX/2


int main() {
	ll n;
	cin >> n;
	vector<ll>a(n);
	priority_queue<ll>q;
	rep(i, 0, n) {
		cin >> a[i];
		q.push(a[i]);
	}

	rep(i, 0, n) {
		if (q.top() == a[i]) {
			q.pop();
			puts(q.top());
			q.push(a[i]);
		}
		else {
			puts(q.top());
		}
	}


	return 0;
}


Measured memory_bytes: 4848
#include <iostream>
#include <cmath>
using namespace std;
 
int main(){
    int x, a, b;
    cin >> x >> a >> b;
 
    if ( abs(a - x) < abs(b -x) )cout << "A" << endl;
    if ( abs(a - x) > abs(b -x) )cout << "B" << endl;
    
}

Measured memory_bytes: 256
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
/*
//#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
*/

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
/*
//#if __cplusplus >= 201103L
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
*/
using namespace std;
#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX/3
#define MAX_N 1000

void solve(){
   cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin>>s;
  if((s.size()%2==0 && s[0]!= s[s.size()-1]) || (s.size()%2==1 && s[0] == s[s.size()-1])){
   cout<<"Second"<<endl;
    }else{
     cout<<"First"<<endl;
}
 }
int main(){
  solve();
  return 0;
}


Measured memory_bytes: 512
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        a: i32,
        b: i32,
    }
    if a - 2 * b >= 0 {
        println!("{}", a - 2 * b);
    } else {
        println!("{}", 0);
    }
}


Measured memory_bytes: 4352
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)

int main(){
    int N;
    cin >> N;
    long long x[N], y[N], h[N];
    long long X, Y, H;
    bool flag;
    rep(i, N){
        scanf("%lld%lld%lld", &x[i],& y[i], &h[i]);
    }
    for(int i = 0; i <= 100; i++){
        for(int j = 0; j <= 100; j++){
            flag = true;
            for(int k = 0; k < N; k++){
                if(h[k] != 0){
                    H = h[k] + abs(i - x[k]) + abs(j - y[k]);
                    break;
                }
            }
            for(int k = 0; k < N; k++){
                if(h[k] != 0){
                    if(H != h[k] + abs(i - x[k]) + abs(j - y[k]) )break;
                }else{
                    if(H > abs(i - x[k]) + abs(j - y[k]) )  break;
                }
                if(k == N - 1) cout << i << " " << j << " " << H << endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

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

    ll N;
    cin >> N;
    vector<ll> cnt(13, 0);
    Rep (i, N) {
        ll d;
        cin >> d;
        if (d > 13) d = 24 - d;
        cnt[d]++;
    }
    cnt[0]++;

    ll ans = 24;
    set<ll> time;
    bool flag = true;
    Rep (i, 13) {
        if (i == 0 || i == 12) {
            if (cnt[i] >= 2) ans = 0;
            else if (cnt[i] == 1) time.insert(i);
        }
        if (cnt[i] >= 3) ans = 0;
        else if (cnt[i] == 2) {
            time.insert(i);
            time.insert(24-i);
        }
        else if (cnt[i] == 1) {
            if (flag) {
                time.insert(i);
                flag = false;
            } else {
                time.insert(24-i);
                flag = true;
            }
        }
    }

    vector<ll> check;
    for (auto e : time) check.push_back(e);
    check.push_back(24);
    Rep (i, check.size()-1) {
        ans = min(ans, check[i+1] - check[i]);
    }

    cout << ans << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
const int MAXL = 128;
const int Q = 850;
int L;
const string chars = 
		"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
		"abcdefghijklmnopqrstuvwxyz"
		"0123456789";
vector<int> cnts(62);
int query(string s){
	cout<<"? "<<s<<endl;
	int v; cin>>v; return v;
}
bool is_subseq(string s){
	return (int)s.size()+query(s)==L;
}
string combine(string a,string b){
	if(!a.size()||!b.size()) return a+b;
	string ret="";
	for(int i=0,j=0,s1=a.size(),s2=b.size();i<s1||j<s2;)
		if(i<s1&&(j==s2||is_subseq(a.substr(0,i+1)+b.substr(j)))) ret+=a[i++];
		else ret+=b[j++];
	return ret;
}
string solve(int l,int r){
	if(l==r) return string(cnts[l],chars[l]);
	int mid=(l+r)>>1;
	return combine(solve(l,mid),solve(mid+1,r));
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0);
	for(int i=0;i<62;i++) cnts[i]=128-query(string(128,chars[i])),L+=cnts[i];
	string ans = solve(0, 61);
	cout << '!' << ' ' << ans << '\n';
}

Measured memory_bytes: 3808
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

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

    string s;
    cin >> s;

    if (a >= 3200)
    {
        cout << s << endl;
    }
    else
    {
        cout << "red" << endl;
    }
    
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!

import sys
readline = sys.stdin.readline
read = sys.stdin.read

n,*p = map(int,read().split())
N = n*n

dist = [0]*N

for a in range(n):
    for b in range(n):
        dist[a*n+b] = min(a,n-1-a,b,n-1-b)

#print(dist)


#ans = [0]*N
ans = 0
iru = [1]*N

for pi in p:
    pi -= 1

    ans += dist[pi]
    iru[pi] = 0

    q = [pi]
    #更新
    
    while q:
        #print(q)
        v = q.pop()
        for i in [-n,-1,1,n]:
            if i==1 and v%n==n-1: continue
            if i==-1 and v%n==0: continue
            nv = v+i
            if 0 <= nv < N and dist[nv] > dist[v] + iru[v]:
                q.append(nv)
                dist[nv] = dist[v] + iru[v]
        
                    
    #print(dist)        

print(ans)









Measured memory_bytes: 170280
#include <bits/stdc++.h>
#include <math.h>
#define uint unsigned long long
#define ll long long
#define db double
#define ls rt << 1
#define rs rt << 1 | 1
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define X first
#define Y second
#define pcc pair<char, char>
#define vi vector<int>
#define vl vector<ll>
#define rep(i, x, y) for(int i = x; i <= y; i ++)
#define rrep(i, x, y) for(int i = x; i >= y; i --)
#define ept 1e-9

using namespace std;
inline int read()
{
		int x = 0, f = 1; char ch = getchar();
		while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
		while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
		return x * f;
}
const int N = 3e5 + 10;
const int mod = 1e9 + 7;
int n;
ll ans = 1;
string s[3];
vector<int> pos;
int main()
{
	cin >> n;
	cin >> s[1] >> s[2];
	s[1] = " " + s[1];
	s[2] = " " + s[2];
	rep(i, 1, n)
		if (s[1][i] == s[2][i]) pos.pb(0);
        else pos.pb(1), i ++;
    int nn = pos.size() - 1;
    rep(i, 0, nn)
	{
        if (pos[i] == 0) 
        {  
            if (i == 0) ans = 3;
            else if (pos[i - 1] != 1) ans *= 2, ans %= mod;
        } 
        else 
        { 
            if (i == 0) ans = 6;
            else if (pos[i - 1] == 0) ans *= 2, ans %= mod;
            else ans *= 3, ans %= mod;
        }
    }
	cout << ans;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
static const int MAX = 200000;

void trace(int data[], int n) {
  cout << data[0];
  for (int i = 1; i < n; i++) {
    cout << " " << data[i];
  }
  cout << endl;
}

class Dtree {
public:
  vector<int> rank, parent;

  Dtree(int size) {
    rank.resize(size, 0);
    parent.resize(size, 0);
    for (int i = 0; i < parent.size(); i++)
      parent[i] = i;
    for (int i = 0; i < rank.size(); i++)
      rank[i] = 0;
  }
  int unite(int x, int y) {
    while (1) {
      int pre = parent[y];
      parent[y] = label(x);
      if (y == pre)
        break;
      y = pre;
    }
  }
  int same(int x, int y) { return label(x) == label(y); }
  int label(int x) {
    while (x != parent[x]) {
      x = parent[x];
    }
    return x;
  }
};

int main() {
  int data[MAX];
  int n, nquery;
  cin >> n;
  cin >> nquery;
  Dtree dt = Dtree(n);
  for (int i = 0; i < nquery; i++) {
    int x, y, command;
    cin >> command >> x >> y;
    if (command == 0) {
      dt.unite(x, y);
    } else if (command == 1) {
      cout << (dt.same(x, y) ? 1 : 0) << endl;
    }
  }
}

Measured memory_bytes: 3132
#include<bits/stdc++.h>
using namespace std;
int main(){
int N,K;
  cin>>N>>K;
  
  long ans=1;
  for(int i=0; i<N; i++){
   if(i==0){ans*=K;}
   else{ans*=K-1;} 
  }
  
  cout<<ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstring>
#include <limits>
using namespace std;
#define ll long long int
#define lli long long int
#define fw(i, s, e) for (ll i = s; i < e; ++i)
#define fe(i, s, e) for (ll i = s; i <= e; ++i)
#define fb(i, e, s) for (ll i = e; i >= s; --i)
#define L(T)  \
    ll T;     \
    cin >> T; \
    while (T--)
#define FASTIO                   \
    ios::sync_with_stdio(false); \
    cin.tie(nullptr);            \
    cout.tie(nullptr);
#define mem(a, i) memset(a, i, sizeof(a))
#define ld long double
#define endl "\n"
#define in(P) \
    ll P;     \
    cin >> P;
int main()
{
    FASTIO
    // L(T)
    {
        string s;
        string en = "";
        string bg = "";

        cin >> s;
        in(q);
        ll val = 0;
        fw(i, 0, q)
        {
            in(n);
            if (n == 1)
            {
                if (val)
                    val = 0;
                else
                {
                    val = 1;
                }
            }
            if (n == 2)
            {
                in(f);
                string y;
                cin >> y;

                if (val)
                {
                    if (f == 1)
                    {
                        en = en + y;
                    }
                    else
                    {
                        bg = y + bg;
                    }
                }
                else
                {
                    if (f == 1)
                    {
                        bg = y + bg;
                    }
                    else
                    {
                        en += y;
                    }
                }
            }
        }
        if (val)
        {
            s = bg + s + en;
            reverse(s.begin(), s.end());
            cout << s << endl;
        }
        else
        {
            // reverse(bg.begin(), bg.end());
            // reverse(s.begin(), s.end());
            cout << bg << s << en << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 4260
#include "bits/stdc++.h"
// Custom Header {{{
#define ALL(x) x.begin(), x.end()
#define rep(i, s, n)      for(int i(s); i < int(n); ++i)
#define endl '\n'
#ifndef YDK
#define eprintf(...)
#endif
using namespace std;
using i64 = long long;
using pii = pair<i64, i64>;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr const int INF  = 0x3f3f3f3f;
constexpr const i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr const int MOD  = int(1e9) + 7;
// }}}

// Library {{{
template<class Container, class InputIt>
Container countTable(InputIt first, InputIt last)
{
    Container cnt;
    for (; first != last; ++first) { ++cnt[*first]; }
    return cnt;
}
// }}}


signed main()
{
    string s; cin >> s;

    auto slv = [](string s, char ch) {
        int ans = 0;
        while(count(ALL(s), ch) < s.length()) {
            ++ans;
            for (int i = 1; i < s.length(); ++i) {
                if (s[i] == ch) s[i-1] = ch;
            }
            s.pop_back();
        }
        return ans;
    };

    int ans = INF;
    for (char c : s) {
        chmin(ans, slv(s, c));
    }

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <string.h>

using namespace std;

namespace {

const size_t kHashSize = 244140624;

class Dictionary {
 public:
  Dictionary() : table_(new int[kHashSize]) {}
  ~Dictionary() { delete[] table_; }

  void insert(const char* k, size_t n) {
    const size_t i = Encode(k, n);
    table_[i] = 1;
  }

  bool find(const char* k, size_t n) const {
    return table_[Encode(k, n)] > 0;
  }

 private:
  static int Id(char c) {
      switch (c) {
        case 'A':
          return 1;
        case 'C':
          return 2;
        case 'G':
          return 3;
        case 'T':
          return 4;
      }
      // should not reach here.
      return 0;
  }

  size_t Encode(const char* k, size_t n) const {
    size_t h = 0;
    size_t p = 1;
    for (size_t i = 0; i < n; ++i) {
      h += p * Id(k[i]);
      p *= 5;
    }
    return h;
  }

  int* table_;
};

} // namespace

int main() {
  int n;
  scanf("%d", &n);

  Dictionary d;
  char op[7];
  char str[13];
  for (int i = 0; i < n; ++i) {
    scanf("%s %s", op, str);
    const char c = op[0];
    const size_t len = strnlen(str, 13);
    if (c == 'i') {
      d.insert(str, len);
      continue;
    }

    if (d.find(str, len)) {
      printf("yes\n");
    } else {
      printf("no\n");
    }
  }

  return 0;
}

Measured memory_bytes: 40420
# A - Shik and Stone

H, W = map(int, input().split())
now = 0
judge = 0

for h in range(H):
    route = input()
    w = 0
    while w<W and route[w]=='.':
        w += 1
    if w!=now:
        break
    while w<W-1 and route[w+1]=='#':
        w += 1
    now = w
    while w<W-1 and route[w+1]=='.':
        w += 1
    if w<W-1:
        break
    if h==H-1 and now==W-1:
        judge = 1

ans = ['Impossible', 'Possible']
print(ans[judge])

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <climits>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <map>
#include <tuple>
#include <iostream>
#include <deque>
#include <array>
#include <set>
#include <functional>
#include <memory>
#include <stack>
#include <numeric>
#include <climits>
#include <cfloat>

std::vector<long long int> prime_factors(long long int value) {
	std::vector<long long int> result;
	for (long long int p = 2; p * p <= value; ++p) {
		if (value % p == 0) {
			result.push_back(p); 
			result.push_back(value / p);
		}
	}
	result.push_back(value);
	return result;
}
bool can_make(const std::vector<long long int>& number, const long long int gcd, const long long int count) {
	std::vector<long long int> rest(number.size()); std::transform(number.begin(), number.end(), rest.begin(), [gcd](const long long int& value) {return value % gcd; });
	std::sort(rest.begin(), rest.end());
	int left_next = 0;
	int right_next = rest.size() - 1;
	int neg = 0;
	int pos = 0;
	while (left_next <= right_next) {
		if (neg < pos) {
			neg += rest[left_next++];
		}
		else {
			pos += gcd - rest[right_next--];
		}
	}
	return neg == pos && neg <= count;
}
int main() {
	int n, k; std::cin >> n >> k;
	std::vector<long long int> number(n); for (auto& a : number) std::cin >> a;
	auto sum = std::accumulate(number.begin(), number.end(), 0LL);
	auto factors = prime_factors(sum); std::sort(factors.begin(), factors.end()); std::reverse(factors.begin(), factors.end());
	long long int max = 1LL;
	for (const auto f : factors) {
		if (can_make(number, f, k)) {
			max = f;
			break;
		}
	}
	std::cout << max << std::endl;
}

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

int main() {
	string s; cin >> s;
	for (int i = 0; i < s.size(); ++i) {
		if (s[i] == 'U' || s[i] == 'D')continue;
		if ((i + 1) % 2)if (s[i] != 'R') { cout << "No" << endl; return 0; } else;
		else if(s[i] != 'L') { cout << "No" << endl; return 0; }
	}
	cout << "Yes" << endl;
}

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

using namespace std;
typedef pair<int, int> pii;

int main(){
        while(true){
                int n, m, h, k;
                cin >> n >> m >> h >> k;
                if(n == 0 && m == 0 && h == 0 && k == 0){ break; }
                vector<int> points(n);
                for(int i = 0; i < n; ++i){ cin >> points[i]; }
                vector<pii> lines(m);
                for(int i = 0; i < m; ++i){ cin >> lines[i].second >> lines[i].first; }
                sort(lines.begin(), lines.end());
                vector<int> dest(n);
                for(int i = 0; i < n; ++i){ dest[i] = i; }
                set<pii> swapTable;
                for(int i = 0; i < m; ++i){
                        swap(dest[lines[i].second - 1], dest[lines[i].second]);
                        swapTable.insert(pii(
                                min(dest[lines[i].second - 1], dest[lines[i].second]),
                                max(dest[lines[i].second - 1], dest[lines[i].second])
                        ));
                }
                vector<int> scores(n);
                for(int i = 0; i < n; ++i){ scores[dest[i]] = points[i]; }
                int sum = 0, answer = 0;
                for(int i = 0; i < k; ++i){ sum += scores[i]; }
                answer = sum;
                for(
                        set<pii>::iterator it = swapTable.begin();
                        it != swapTable.end(); ++it
                ){
                        if(it->first >= k || it->second < k){ continue; }
                        answer = min(answer, sum - scores[it->first] + scores[it->second]);
                }
                cout << answer << endl;
        }
        return 0;
}

Measured memory_bytes: 2044
import sys
import collections
import numpy as np
input = sys.stdin.readline
import sys
import collections
import numpy as np
input = sys.stdin.readline
N, K = [int(x) for x in input().split()]
R, S, P = [int(x) for x in input().split()]
score = {}
score["r"] = P
score["s"] = R
score["p"] = S
T = list(input().rstrip())
ans = 0
for i in range(K):
    temp = T[i::K]
    ans += score[temp[0]]
    if len(temp) != 1:
        flag = 1
        for j in range(1, len(temp)):
            if temp[j] == temp[j-1]:
                if flag:
                    flag = 0
                else:
                    ans += score[temp[j]]
                    flag = 1
            else:
                ans += score[temp[j]]
                flag = 1
print(ans)


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

int main(void){
	int N,M;
	char s[100][11];
	char t[100][11];
	scanf("%d",&N);
	int i,j;
	for(i=0;i<N;i++){
		scanf("%s",&s[i]);
	}
	scanf("%d",&M);
	for(i=0;i<M;i++){
		scanf("%s",t[i]);
	}
	//まずsをチェックします。
	int ans=0,x;
	for(i=0;i<N;i++){
		x=1;
		for(j=i+1;j<N;j++){
			if(strcmp(s[i],s[j])==0){
				x++;
			}
		}
		for(j=0;j<M;j++){
			if(strcmp(s[i],t[j])==0){
				x--;
			}
		}
		if(ans < x){
			ans =x;
		}
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
long mod=1e9+7;
long power(long a,long b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}
long A,B,C,N;
long invc[2<<17];
long inv100[2<<17];
long AA[2<<17],BB[2<<17];
long F[2<<17],I[2<<17];
main()
{
	cin>>N>>A>>B>>C;
	long ans=0;
	F[0]=1;
	for(int i=1;i<2<<17;i++)F[i]=F[i-1]*i%mod;
	I[(2<<17)-1]=power(F[(2<<17)-1],mod-2);
	for(int i=(2<<17)-1;i--;)I[i]=I[i+1]*(i+1)%mod;
	invc[0]=1;
	long AB=power(A+B,mod-2);
	inv100[0]=1;
	AA[0]=BB[0]=1;
	long I100=power(100,mod-2);
	for(int i=1;i<2<<17;i++)
	{
		invc[i]=invc[i-1]*100%mod*AB%mod;
		inv100[i]=inv100[i-1]*I100%mod;
		AA[i]=AA[i-1]*A%mod;
		BB[i]=BB[i-1]*B%mod;
	}
	for(long i=0;i<N;i++)
	{
		long k=i+N;
		ans=(ans+F[i+N-1]*I[N-1]%mod*I[i]%mod*AA[N]%mod*inv100[N]%mod*BB[i]%mod*inv100[i]%mod*k%mod*invc[k+1]%mod)%mod;
		ans=(ans+F[i+N-1]*I[N-1]%mod*I[i]%mod*BB[N]%mod*inv100[N]%mod*AA[i]%mod*inv100[i]%mod*k%mod*invc[k+1]%mod)%mod;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 12544
#include<stdio.h>

void trace(int A[],int N){
    int i;
    for (i=0;i<N;i++){
        if(i>0) {
            printf(" ");
        }
    printf("%d",A[i]);
    }
    printf("\n");
}

void insertionSort(int A[],int N)
{
    int j,i,v;
    for(i=1;i<N;i++)
    {
        v=A[i];
        j=i-1;
        while(j>=0 && A[j]>v)
        {
            A[j+1]=A[j];
            j--;
        }
    A[j+1]=v;
    trace(A,N);
    }
}

int main(){
    int N,j,i;
    int A[100];
    
    scanf("%d",&N);
    for(i=0;i<N;i++)
    {scanf("%d",&A[i]);
    }
        trace(A,N);
        insertionSort(A,N);
    
    
    return 0;
}



Measured memory_bytes: 2100
#include <bits/stdc++.h>
#define ld long double
#define ll long long
#define ull unsigned ll
#define pll pair<ll, ll>
#define itr(a) begin(a), end(a)
#define pb push_back
#define x first
#define y second
#define endl '\n'
#define FAST cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
#define FILES(namein, nameout) freopen(namein, "r", stdin); freopen(nameout, "w", stdout);
#define M 1000000007
#define N 66
#define INF 101111111111111
using namespace std;
main(){
    FAST;
    ll s;
    cin >> s;
    ll o = 1000*1000*1000;
    ll x = (o - s%o)%o;
    ll y = (s+x)/o;
    cout << "0 0 1000000000 1 " << x << " " << y << endl;;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define vll vector<ll>
#define mll map<ll,ll>
#define sll set<ll>
#define fo(i,n) for(i=0;i<n;i++)
#define MOD 1000000007
using namespace std;

int main()
{
    ios::sync_with_stdio(false);


    ll n,i,j,k,t;
    string s,s2="";
    cin>>n>>s;

    stack<char> st;
    fo(i,s.length())
    {
        if(s[i]=='(')
        {
            st.push(s[i]);
            s2+=s[i];
        }
        if(s[i]==')')
        {
            if(st.empty())
            {
                s2='('+s2+')';
            }
            else
            {
                s2+=')';
                st.pop();
            }
        }
    }

    while(!st.empty())
    {
        st.pop();
        s2+=')';
    }

    cout<<s2;
    return 0;
}


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

long solve(const std::string& s, const std::string& t)
{
  long result = 0;
  for (auto i = 0u; i < s.size(); ++i) {
    if (s.at(i) != t.at(i)) ++result;
  }
  return result;
}

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

  std::cout << std::setprecision(20);
  std::cout << solve(s, t) << std::endl;
}


Measured memory_bytes: 3848
#include <iostream>

const int ms = 200200;

int freq[ms];

int main() {
	int n;
	std::cin >> n;
	int ans = 0;
	while(n--) {
		int temp;
		std::cin >> temp;
		if(temp >= ms) {
			ans++;
		} else {
			freq[temp]++;
		}
	}
	for(int i = 0; i < ms; i++) {
		if(freq[i] >= i) {
			freq[i] -= i;
		}
		ans += freq[i];
	}
	std::cout << ans << '\n';
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
    return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
    return a > b && (a = b, true);
}
/*-------------------------------------------*/

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

    int n;
    ll l[100];
    cin >> n;
    rep(i, n) cin >> l[i];

    ll ans = 0;
    rep(a, n) rep(b, a) rep(c, b) {
        if(l[a] != l[b] && l[b] != l[c] && l[c] != l[a]) {
            ll mx = max({l[a], l[b], l[c]});
            ll sum = l[a] + l[b] + l[c];
            if(sum - mx > mx) ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())
#define put(a) ((cout) << (a) << (endl))
#define putf(a, n) ((cout) << (fixed) << (setprecision(n)) << (a) << (endl))

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;

static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class T> static inline T gcd(T a, T b);
template <class T> static inline T lcm(T a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);

int main(int argc, char* argv[]) {
  double a, b, x;
  cin >> a >> b >> x;

  if ((a * a * b) / 2 >= x) {
    double h = (2 * x) / (a * b);
    double theta = atan2(h, b) * 180.0 / PI;
    putf(90.0 - theta, 10);
    return 0;
  }

  double e = (2 * x) / (a * a) - b;
  double theta = atan2(a, b - e) * 180.0 / PI;
  putf(90.0 - theta, 10);
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

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

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

template <class T> inline T gcd(T a, T b) { return __gcd(a, b); }

template <class T> inline T lcm(T a, T b) { return (a * b) / gcd(a, b); }

template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cstring>
#include <map>
#include <set>
#include <cmath>
#define FOR(i, a, b) for (ll i = (a); i < (b); ++i)
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define INF 1e9
typedef long long int ll;
using namespace std;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
    for (T &x : vec)
        is >> x;
    return is;
}

ll gcd(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    while (m != n)
    {
        if (m > n)
            m = m - n;
        else
            n = n - m;
    }
    return m;
}

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

int main(){
    ll N;
    cin >> N;

    int ans = to_string(N).size();

    for(ll A=1; A*A<=N; A++){
        if(N%A!=0)  continue;
        const ll B = N/A;
        const int res = max(to_string(A).size(), to_string(B).size());
        if(ans>res){
            ans = res;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;class Main{public static void main(String[] a){Scanner s=new Scanner(System.in);int n=s.nextInt();int d=s.nextInt();int k=0;for(;n>0;n--){if(Math.sqrt(Math.pow(s.nextInt(),2)+Math.pow(s.nextInt(),2))<=d)k++;}System.out.print(k);}}

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

# define p(s) std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;

int main()
{
    int n;cin >> n ;
    map<string,int> m;

    string s;cin >>s;
    m[s]++;
    string pre=s.substr(s.size()-1,1);
    bool flg=true;
    for(int i=0;i<n-1;i++){
        cin >>s;
        if(m[s]++>0) flg=false;
        if(pre!=s.substr(0,1)) flg=false;
        pre=s.substr(s.size()-1,1);
    }
    Yes(flg)
} 

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

ll pos[2][200005];

int main() {
  int N;
  cin>>N;
  vector<int> arr(N);
  int a;
  for(int i=0;i<N;++i){
    cin>>a;
    a--;
    arr[a] = i;
  }
  set<int> st;
  auto l=st.begin(), m=st.begin(), r=st.begin();
  for(int i=0;i<N;++i){
    st.insert(arr[i]);
    m = st.find(arr[i]);
    if(m!=st.begin()){
      l = prev(m);
      pos[0][i] = *l + 1;
    }
    if(next(m)==st.end()){
      pos[1][i] = N;
    }
    else{
      r = next(m);
      pos[1][i] = *r;
    }
  }
  ll ans = 0;
  for(ll i=0;i<N;++i){
    ans += (i+1)*(arr[i]-pos[0][i]+1)*(pos[1][i]-arr[i]);
  }
  cout<<ans<<endl;
}


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

int main() {
    int l=0;
    int ans =0;int v =9;
    rep(i,5){
        int a;cin>>a;       
        if(a%10 == 0) {
            l++;
          	ans+=a;
        }
        else {
          ans+=((a+10)/10)*10;
          v=min(v,a%10);
    }
    }
  if(l==5){
    cout<<ans<<endl;
  }
  else{  ans = ans - 10 + v;
    cout << ans << endl;}
  
    return 0;
}

Measured memory_bytes: 256
[a, b, c] = [int(x) for x in input().split(" ")]
k = int(input())
a_b_flg = False if a >= b else True
b_c_flg = False if b >= c else True

for kdx in range(0, k):
  if not a_b_flg:
    b = b*2
  elif not b_c_flg:
    c = c*2
  a_b_flg = False if a >= b else True
  b_c_flg = False if b >= c else True
  if a_b_flg and b_c_flg:
    print('Yes')
    break
if not (a_b_flg and b_c_flg):
  print('No')

Measured memory_bytes: 9220
def sol():
    h,w,d=map(int,input().split())
    a=[[int(i) for i in input().split()] for i in range(h)]
    t={}
    for i in range(h):
        for j in range(w):
            t[a[i][j]]=(i,j)
    ans=[0]*(h*w+1)
    for i in range(h*w,d,-1):
        o,p=t[i]
        ans[i-d]=ans[i]+abs(o-t[i-d][0])+abs(p-t[i-d][1])
    q=int(input())
    for i in range(q):
        l,r=map(int,input().split())
        print(ans[l]-ans[r])

if __name__=="__main__":
    sol()

Measured memory_bytes: 68060
n = int(input())
h = list(map(int, input().split()))

ans=0
cnt=0
bk=h[-1]
for hight in reversed(h[:-1]):
    if hight>=bk:
        cnt+=1
    else:
        ans=max(cnt, ans)
        cnt=0
    bk=hight
print(max(ans,cnt))

Measured memory_bytes: 14252
#include <cstdio>
using namespace std;
int main()
{
    int a,b;
    scanf("%d%d",&a,&b);
    if (a<=0&&b>=0) {puts("Zero");return 0;}
    if (a>0||(b-a)%2==1) puts("Positive"); else puts("Negative");
    return 0;
}

Measured memory_bytes: 128
#include <cmath>
#include <stdio.h>
using namespace std;

int main(void){
    double p=0.0;
    long long N,K;
    scanf("%lld %lld",&N,&K,stdin);
    long long kaisuu;
    for(long long i=1;i<=N;i++){
        kaisuu=fmax((int)ceil(log(K/(double)i)/log(2)),0);
        p+=pow(0.5,kaisuu)/N;
    }
    printf("%.10lf",p);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__)
#define File(x) freopen(x".in","r",stdin); freopen(x".out","w",stdout)

using namespace std;

typedef long long LL;
typedef pair <int, int> PII;
typedef pair <int, PII> PIII;

inline int gi()
{
	int f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

inline LL gl()
{
	LL f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

const int INF = 0x3f3f3f3f, N = 200003, M = N << 1;

int main()
{
	//File("");
    string s;
    getline(cin, s);
    if (s[2] == s[3] && s[4] == s[5]) puts("Yes");
    else puts("No");
	return 0;
}

Measured memory_bytes: 256
from functools import reduce

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

def gcd_multi(*numbers):
    return reduce(gcd, numbers)

n, x = list(map(int, input().split()))
x_list = list(map(int, input().split()))
x_list.append(x)
x_list.sort()
dif_list = []
for i in range(n):
  dif_list.append(x_list[i+1] - x_list[i])

print(gcd_multi(*dif_list))

Measured memory_bytes: 14596
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <utility>
#include <deque>
#include <stack>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<ll> vl;
typedef queue<int> qi;
typedef queue<ll> ql;
typedef pair<ll,ll> pll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
#define rep(i,n) for (int i=0;i<n;i++)
#define mp make_pair
#define pb push_back
#define pf push_front
#define F first
#define S second
#define INF 200000009
class DSU{
public:
	int fa[200005];
	inline void init(){
		for (int i=0;i<200005;++i) fa[i]=i;
	}
	inline int f(int x){
		return fa[x]==x? x:fa[x]=f(fa[x]);
	}
	inline void u(int x,int y){
		x=f(x);y=f(y);
		if (x==y) return;
		fa[x]=y;
	}
	inline bool same(int x,int y){
		return (f(x)==f(y)); 
	} 
}dsu;

typedef pair<ll,pii> Edge;
vector<Edge> edges;
ll a[200005];ll d;
int n;
inline void solve(int l,int r){
	if (l==r) return;
	if (l==r-1){
		edges.pb(mp(a[l]+a[r]+d,mp(l,r)));
		return;
	}
	int m=(l+r)>>1;
	solve(l,m);solve(m+1,r);
	int bestl,bestr;
	ll mincostl=1e18;
	for (int i=l;i<=m;++i){
		if (a[i]-d*i<mincostl){
			mincostl=a[i]-d*i;bestl=i;
		}
	}
	ll mincostr=1e18;
	for (int i=m+1;i<=r;++i){
		if (a[i]+d*i<mincostr){
			mincostr=a[i]+d*i;bestr=i;
		}
	}
	for (int i=l;i<=m;++i){
		edges.pb(mp(mincostr+a[i]-d*i,mp(i,bestr)));
	}
	for (int i=m+1;i<=r;++i){
		edges.pb(mp(mincostl+a[i]+d*i,mp(bestl,i)));
	}
	return;
}
int main(){
	ios::sync_with_stdio(false);
	cin>>n>>d;
	for (int i=1;i<=n;++i) cin>>a[i];
	if (n==1){
		cout<<0<<endl;return 0;
	}
	solve(1,n);
	sort(edges.begin(),edges.end());// smaller to bigger
	reverse(edges.begin(),edges.end());// bigger to smaller
	dsu.init();
	ll ans=0;
	while(!edges.empty()){
		Edge E=edges.back();edges.pop_back();
		ll u=E.S.F,v=E.S.S,cost=E.F;
		if (dsu.same(u,v)) continue;
		dsu.u(u,v);
		ans+=cost;
	}
	cout<<ans;
	return 0; 
}

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

int main()
{
    int a,b,c;
    cin >> a >> b >> c;
    int ans;
    if(a == b) ans = c;
    if(b == c) ans = a;
    if(a == c) ans = b;
    cout << ans << endl;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
// typedef __int128 int128_t;
// typedef unsigned __int128 uint128_t;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<char, int> pci;
typedef tuple<int, int, int> ti3;
typedef tuple<ll, ll, ll> tl3;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

#define ff          first
#define ss          second

#define pb(x)       push_back(x)
#define ppb()       pop_back()
#define pf(x)       push_front(x)
#define ppf()       pop_front()
#define mp(x,y)     make_pair(x, y)
#define all(v)     begin(v),end(v)
#define gcd(x, y)   __gcd(x, y)

// pbds and ordered set
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template <class T, class cmp = less<T> >
// using ordered_set = tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;

// for fast I/O
#define endl '\n'
#define FASTIO() ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

const int N = 2e5;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
const ll INF = INT_MAX-1;

ll solve(const vl& a, int n) {
  ll sum = 0;
  for (int i = 0; i <= n; i++) {
    sum += a[i];
  }
  ll ans = 0, space = 1;
  for (ll i = 0; i <= n; i++, space *= 2, space = min(space, sum)) {
    // cout << min(sum, space) << endl;
    ans += min(sum, space);
    sum -= a[i];
    space -= a[i];
    if (space < 0) return -1;
  }
  return ans;
}

int main() {
  FASTIO();

  int n;
  cin >> n;

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

  cout << solve(a, n) << endl;
  
  return 0;
}



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

using Edge = pair<int, long long>;
using Graph = vector<vector<Edge> >;

long long N;
Graph G;
vector<int> res;

void dfs(int v, int p, int c) {
    res[v] = c;
    for (auto e : G[v]) {
        if (e.first == p) continue;
        if (e.second & 1) {
            dfs(e.first, v, 1 - c);
        }
        else
        {
            dfs(e.first, v, c);
        }
    }
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    scanf("%lld",&N);
    G.assign(N, vector<Edge>());
    for(int i = 0 ; i < N-1 ; i++){
        int u,v;
        long long w;
        cin >> u >> v >> w;
        --u;
        --v;
        G[u].push_back(Edge(v, w));
        G[v].push_back(Edge(u, w));
    }
    res.assign(N, 0);
    dfs(0, -1, 0);
    for (auto e : res) cout << e << endl;
    return 0;
}


Measured memory_bytes: 10496
#include <iostream>

using namespace std;
int main()
{

    int r,m,a;
    cin>>r>>m>>a;
    if(a<m && a>r){

        cout<<"Yes";
    }
    else if(a==r && a==m){
        cout<<"Yes";
    }


        else{
        cout<<"No";
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string>
typedef long long ll;
const int mod = 1e9 + 7;
using namespace std;

void solve() {
	int n = 5, x; 
	vector<int> arr(n, 0);
	for(int i = 0; i < n; ++i) {cin >> arr[i]; if(arr[i] == 0) x = i;}
	cout << x + 1 << endl;
	return;
}

int main() {
	ios_base :: sync_with_stdio(0);
	cin.tie(0);
	cout.precision(20);
	int t;
		solve();
	return 0;
}
 















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

using namespace std;

int main(){
  long long n,x,happy=0,dum;
  priority_queue<long long> candy;
  cin >> n >> x;
  while(n--){
    cin >> dum;
    candy.push(-1*dum);
  }
  while(x>0 && !candy.empty()){
    
    dum=candy.top();candy.pop();
    
    x+=dum;
    //cout << x << "   " << dum << "\n";
    if(x>=0) happy++;
    
  }
  if(x>0) happy--;
  cout << happy << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define B2(x) (63-__builtin_clzll(x))
#define  For(i,a,b) for(int i=a,i##E=b;i<=i##E;++i)
using namespace std;
const int N=100007;
inline void read(int &x)
{
	x=0;char ch=getchar();
	while(!isdigit(ch))ch=getchar();
	while( isdigit(ch))x=x*10+ch-'0',ch=getchar();
}
int n,ans,l[N],r[N],dp[N][2];
int main()
{
	int x;
	read(n);
	For(i,1,n)
	{
		read(x);
		l[i]=B2(x);
		r[i]=l[i]+((1<<l[i])!=x);
		ans+=r[i];
		dp[i][0]=max(dp[i-1][0]+min(r[i-1],l[i]),dp[i-1][1]+min(l[i-1],l[i]));
		dp[i][1]=max(dp[i-1][0]+min(r[i-1],r[i]),dp[i-1][1]+min(l[i-1],r[i]));
	}
	printf("%d\n",ans-max(dp[n][0],dp[n][1]));
	return 0;
}


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

int main() {
    int n, m, l;
    cin >> n >> m >> l;
    int a[100][100], b[100][100];
    long long c[100][100];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> a[i][j];
        }
    }
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < l; j++) {
            cin >> b[i][j];
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < l; j++) {
            c[i][j] = 0;
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < l; j++) {
            for (int k = 0; k < m; k++) {
                c[i][j] += a[i][k] * b[k][j];
            }
        }
    }
    for (int i = 0; i < n; i++) {
        cout << c[i][0];
        for (int j = 1; j < l; j++) {
            cout << " " << c[i][j];
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3220
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  string s,t;
  cin >> s >> t;
  int ans = 0;
  bool exist = true;
  
  for(int i=0; i<N; i++){
    int x = i;
   if(exist){
    for(int j=0; j<N; j++){
      if(s.at(i) == t.at(j)){
        if(N-x == j+1){
          ans = 2*N - j -1;
          exist = false;
          break;
        }
        i++;
        continue;
      }
      if(s.at(i) != t.at(j)){
        i = x;
        break;
      }
    }
     
   }
  }
  
  if(exist){
    ans = 2*N;
  }
  cout << ans << endl;
}

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

int calc_dist (int x, int y, int x_1, int y_1){
	int dist = abs(x_1 - x) + abs(y_1 - y);
    return dist;
}
 
int main() {
    int A, B;
    cin >> A >> B;
    if(A == 1 && B == 2) cout << 3 <<endl;
    if(A == 1 && B == 3) cout << 2 <<endl;
    if(A == 2 && B == 1) cout << 3 <<endl;
    if(A == 2 && B == 3) cout << 1 <<endl;
    if(A == 3 && B == 1) cout << 2 <<endl;
    if(A == 3 && B == 2) cout << 1 <<endl;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    from itertools import accumulate
    acc = [a for a in accumulate([0] + A)]
    ans = acc[-1]
    for i in range(1, N+1):
        a = acc[i]
        b = acc[N] - acc[i]
        v = abs(a-b)
        ans = min(ans, v)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 26220