akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Stack;

public class Main {
	public static void main(String[] args) throws IOException {
		new Main().run();
	}
	private void run() throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String input = reader.readLine();
		reader.close();
		int sum = 0;
		Stack<Integer> st1 = new Stack<Integer>();
		Stack<int[]> st2 = new Stack<int[]>();
		for (int i = 0; i < input.length(); i++) {
			char c = input.charAt(i);
			if (c == '\\') {
				st1.add(i);
			} else if (c == '/' && !st1.isEmpty()) {
				int j = st1.pop();
				int area = i - j;
				sum += area;
				int prev = 0;
				while (!st2.isEmpty() && st2.peek()[0] > j) {
					prev += st2.pop()[1];
				}
				st2.add(new int[]{j, area + prev});
			}
		}
		
		System.out.println(sum);
		System.out.print(st2.size());
		for (int i = 0; i < st2.size(); i++) {
			System.out.print(" " + st2.get(i)[1]);
		}
		System.out.println();
	}
}



Measured memory_bytes: 26452
#include <bits/stdc++.h>
#define RI register int
typedef long long LL;

#define FILEIO(name) freopen(name".in", "r", stdin), freopen(name".out", "w", stdout);

using namespace std;

int const MAXN = 5e5 + 5, mod = 998244353;
LL frac[MAXN], invfrac[MAXN];

inline LL qpow(LL a, LL k) {
  LL re = 1;
  for (; k; k >>= 1, a = a * a % mod)
    if (k & 1) re = re * a % mod;
  return re;
}
inline LL C(int n, int m) { return frac[n] * invfrac[m] % mod * invfrac[n - m] % mod; }

int main() {

#ifdef LOCAL
  FILEIO("a");
#endif

  LL n, k, ans = 0; cin >> n >> k;
  frac[0] = 1;
  for (RI i = 1; i <= k; ++i) frac[i] = frac[i - 1] * i % mod;
  invfrac[k] = qpow(frac[k], mod - 2);
  for (RI i = k; i; --i) invfrac[i - 1] = invfrac[i] * i % mod;
  for (RI i = max(n, (k + 1) / 2); i <= k; ++i) {
    int R = i, B = k - i;
    int D = R - (n - 1);
    if (R == B) ans = (ans + C(k - 1, R) - C(k - 1, R + D)) % mod;
    else if (D > B) ans = (ans + C(k, R)) % mod;
    else ans = (ans + C(k, R) - C(k, R + D)) % mod;
  }
  cout << (ans + mod) % mod << endl;

  cerr << (double)(clock()) / CLOCKS_PER_SEC * 1000 << "ms" << endl;

  return 0;
}

// created by Daniel yuan

Measured memory_bytes: 8064
#include <stdio.h>

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template <typename T, typename V>
void __print(const pair<T, V> &x) {
    cerr << '{';
    __print(x.first);
    cerr << ',';
    __print(x.second);
    cerr << '}';
}
template <typename T>
void __print(const T &x) {
    int f = 0;
    cerr << '{';
    for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
    cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
    __print(t);
    if (sizeof...(v)) cerr << ", ";
    _print(v...);
}
#ifdef LOCAL
#define debug(x...)               \
    cerr << "[" << #x << "] = ["; \
    _print(x)
#else
#define debug(x...)
#endif

#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)

typedef long long ll;

const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    long double L;
    cin >> L;

    cout << setprecision(20) << (L / 3) * (L / 3) * (L / 3) << endl;

    return 0;
}


Measured memory_bytes: 256
N,A,B,C = map(int,input().split())
l = [int(input()) for i in range(N)]
INF = 10**9+7

def dfs(count,a,b,c):
	if count == N:
		if min(a,b,c) > 0:
			return abs(a-A)+abs(b-B)+abs(c-C)-30
		else:
			return INF
	non = dfs(count+1,a,b,c)
	useA = dfs(count+1,a+l[count],b,c)+10
	useB = dfs(count+1,a,b+l[count],c)+10
	useC = dfs(count+1,a,b,c+l[count])+10
	return min(non,useA,useB,useC)

print(dfs(0,0,0,0))

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

typedef struct{
  bool st;
  double time;
  int ch;
}rec;

vector<rec> v;
map<int, int> simul_map;

bool rec_sort(rec r, rec s) {
  return(r.time < s.time);
}

int main(){
  int n, c;
  cin >> n >> c;
  for (int i=0;i<n;i++) {
    double s, t;
    int tmp_ch;
    cin >> s >> t >> tmp_ch;
    rec r_start = {true, s-0.5, tmp_ch};
    rec r_end = {false, t, tmp_ch};
    v.push_back(r_start);
    v.push_back(r_end);
  }
  sort(v.begin(), v.end(), rec_sort);
  int simul = 0;
  int max_simul = 0;
  int vsize = v.size();
  for (int i=0;i<vsize;i++) {
    if (v[i].st) {
      simul_map[v[i].ch]++;
      if (simul_map.size() > max_simul) {
	max_simul = simul_map.size();
      }
    } else {
      simul_map[v[i].ch]--;
      if (simul_map[v[i].ch] == 0) {
	map<int, int>::iterator it = simul_map.find(v[i].ch);
	simul_map.erase(it);
      }
    }
  }
  cout << max_simul << endl;
  return(0);
}


Measured memory_bytes: 8432
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<functional>
#include<map>
#include<set>
#include <string>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
map<int, int> mp;
map<int, int>mm;
#define ll long long
#define ld long double
#define PI 3.14159265358979l
int main() {
    int n, k;
    cin >> n >> k;
    if (k * 2 - 1 <= n)cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int x,y,z,a,b,c;
	scanf("%d",&z);
	for(x=0;x<15;x++)
	{
		for(y=0;y<25;y++)
		{
			if (7*x + 4*y == z) 
			{
				printf("Yes");
				return 0;
			}
		}
	}
	printf("No");
	return 0;
}

Measured memory_bytes: 128
n = int(input())

for _ in range(n):
  out_cnt = 0
  runner = 0
  point = 0
  while out_cnt < 3:
    event = input()
    if event == "HIT":
      runner += 1
      if runner >= 4:
        point += 1
        runner = 3

    elif event == "HOMERUN":
      point += (runner + 1)
      runner = 0

    else:
      out_cnt += 1

  print(point)




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

#define H 250

int parent(int);
int left(int);
int right(int);

int main()
{
	int Num[H];
	int i,n,l,r;

	scanf("%d",&n);	

	for(i = 1;i <= n;i++)
	{
		scanf("%d",&Num[i]);
	}

	for(i = 1;i <= n;i++)
	{
		printf("node %d: key = %d, ",i,Num[i]);
		if(i != 1) printf("parent key = %d, ", Num[parent(i)]);
		if(left (i) <= n) printf("left key = %d, ",Num[left(i)]);
		if(right(i) <= n) printf("right key = %d, ",Num[right(i)]);
		printf("\n");
	}

	return 0;
}

int parent(int i)
{
	int j;
	j = i / 2;
	return j;
}

int left(int i)
{
	int j;
	j = 2 * i;
	return j;
}

int right(int i)
{
	int j;
	j = (2 * i) + 1;
	return j;
}

Measured memory_bytes: 600
import Data.Maybe
import Data.List

data Dubious a = Fixed a | Unfixed deriving Show


main = do
  s <- getLine >>= return . (map (\x -> if x=='?' then Unfixed else (Fixed x))) :: IO [Dubious Char]
  t <- getLine >>= return . (map (\x -> Fixed x)) :: IO [Dubious Char]

  let
    lent = length t
    lens = length s

  
  putStrLn $ func3 (sort (map (map func2) (catMaybes [func s t i | i<-[0..lens-lent]])))


  where
    equalDubious :: Eq a => Dubious a -> Dubious a -> Bool
    equalDubious Unfixed y = True
    equalDubious x Unfixed = True 
    equalDubious (Fixed x) (Fixed y) = if x/=y then False else True
    

    fix :: Eq a => Dubious a -> Dubious a -> Dubious a
    fix Unfixed (Fixed a) = Fixed a
    fix (Fixed a) Unfixed = Fixed a
    fix Unfixed Unfixed = Unfixed
    fix (Fixed a) (Fixed b) = if a/=b then Unfixed else Fixed a



    func s t i = if and (zipWith equalDubious t s') then (Just r) else Nothing
      where
        lt = length t
        ls = length s
        s' = take lt (drop i s)
        r = zipWith fix s ((take i (repeat Unfixed)) ++ t ++ (take (ls-i-lt) (repeat Unfixed)))

    func2 :: Dubious Char -> Char
    func2 (Fixed x) = x
    func2 Unfixed = 'a'

    func3 :: [String] -> String
    func3 [] = "UNRESTORABLE"
    func3 xs = head xs


Measured memory_bytes: 764
'use strict';
(function(stdin) {
  var inputs  = stdin.toString();
  var flines = inputs.split('\n')[0].split(' ').map(Number);
  var a = flines[0];
  var b = flines[1];
  var area = a * b;
  var periphery = 2 * (a + b);
 
  console.log(area,periphery);
 
}(require('fs').readFileSync('/dev/stdin', 'utf8')));

Measured memory_bytes: 7376
#include <iostream>
#include <vector>
using namespace std; 
int main(void){

  int n;
  cin >> n;
  
  vector<int> vec(n);
  for (int i = 0; i < n; i++) {
    cin >> vec.at(i);
  }
  
  int result = 0;
  
  for(int i = 0; i < n; i++){
    for(int j = i; j < n; j++){
      if (i == j){
        continue;
      }
      result += vec.at(i) * vec.at(j);
    }
  }
   
  cout << result << endl;
  return 0;
}


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

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;

int main()
{
    int ans, a, b;
    cin >> a >> b;

    ans = a * b - b - a + 1;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
# tree diameter if (currDia <= k) true else shorten() while (dia >= k) O(n) dia readjust 
# multiple pairs . centroid of tree --> on largest path find centroid --> maintain a heap ?

from collections import deque

def main():

    n, d = map(int, input().split())

    adj = [[] for i in range(n)]

    edges = []

    for i in range(n-1):

        a, b = map(int, input().split())

        adj[a-1].append(b-1)

        adj[b-1].append(a-1)

        edges.append((a-1, b-1))


    ans = 1000000

    if (d % 2 == 0):
        for i in range(n):
            ans = min(ans, compute(adj, i, d))
    else:
        for i in range(n-1):
            ans = min(ans, computeEdges(adj, edges[i], d-1))

    print(ans)

def compute(adj, u, dia):

    vis = [False]*len(adj)

    dis = [0]*len(adj)

    q = deque()

    q.append(u)
    vis[u] = True

    while (len(q) > 0):

        elem = q.popleft()

        for v in adj[elem]:

            if (vis[v] == False):
                q.append(v)

                vis[v] = True

                dis[v] = dis[elem] + 1

    count = 0

    for a in dis:

        if (a > dia/2):
            count += 1

    return count


def computeEdges(adj, edge, dia):

    vis = [False]*len(adj)

    dis = [0]*len(adj)

    q = deque()

    q.append(edge[0])
    q.append(edge[1])
    vis[edge[0]] = True
    vis[edge[1]] = True

    while (len(q) > 0):

        elem = q.popleft()

        for v in adj[elem]:

            if (vis[v] == False):
                q.append(v)

                vis[v] = True

                dis[v] = dis[elem] + 1

    count = 0

    for a in dis:

        if (a > dia/2):
            count += 1

    return count

main()


Measured memory_bytes: 50904
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
//typedef vector<unsigned int>vec;
typedef vector<ll>vec;
typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

//const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
//const ll MOD = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


bool dx[2][2*8000], dy[2][2*8000];
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    int x, y;
    cin >> S >> x >> y;
    vector<vector<int>> a(2);
    int d = 0;
    REP(i,S.size()){
        int t=0;
        while(S[i]=='F'&&i<S.size()) t++,i++;
        a[d].push_back(t);
        d = 1-d;
    }
    int g = 8000;
    REP(i,2) REP(j,2*g){
        dx[i][j] = false;
        dy[i][j] = false;
    }
    dx[0][g] = true, dy[0][g] = true;
    REP(i,a[0].size()){
        REP(j,2*g){
            if(dx[i%2][j]){
                dx[(i+1)%2][j+a[0][i]] = true;
                if(i > 0) dx[(i+1)%2][j-a[0][i]] = true;
                dx[i%2][j] = false;
            }
        }
    }
    REP(i,a[1].size()){
        REP(j,2*g){
            if(dy[i%2][j]){
                dy[(i+1)%2][j+a[1][i]] = true;
                dy[(i+1)%2][j-a[1][i]] = true;
                dy[i%2][j] = false;
            }
        }
    }
    int a0 = a[0].size(), a1 = a[1].size();
    if(dx[a0%2][g+x] && dy[a1%2][g+y]) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String str = scan.nextLine();
		int indA = str.indexOf('A');
		int indZ = str.lastIndexOf('Z');
		System.out.println(indZ-indA + 1);
	}
}


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

int main(void){
   int A,B,C,X;
   cin>>A>>B>>C>>X;
   int count=0;
   for(int i=0;i<=A;i++){
      for(int j=0;j<=B;j++){
         for(int k=0;k<=C;k++){
            if(500*i+100*j+50*k==X) count++;
         }
      }
   }
   cout<<count<<endl;
   return 0;
}



Measured memory_bytes: 256
// skip until line 65
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <istream>
#include <iterator>
#include <sstream>
#include <list>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iomanip>
using namespace std;

#define BR "\n"
#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define ALL(cont) begin(cont),end(cont)
#define AS_MOD(a, b) ((((a) % (b) ) + (b)) % (b))
#define FEACH(it, cont) for(auto (it) = begin(cont); it!=end(cont);++it)
#define FEACHR(it, cont) for(auto (it) = rbegin(cont); it!=rend(cont);++it)
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define getll() ([](){ll s;scanf("%lld", &s);return s;})()
#define getld() ([](){ld s;scanf("%Lf", &s);return s;})()
#define prl(P) printf("%lld", P)
#define prd(P) printf("%.10Lf", P)
#define pr(P) printf(P)
#define MAX(V, T) V=max(V,T)
#define MIN(V, T) V=min(V,T)

#define DumpArray(cont, from, to) for(int __i=from;__i<to;++__i) {cout<<"(" <<__i<<": " << cont[__i]<<")";} cout<<endl;

/*
 * ***_bound(6)
 * 5 6 6 6 6 6 7 7 7
 *   ^lower    ^upper
 * void reverse(c.begin(), c.end())
 *
 * graph
 * seg tree
 * dp
 * brute force
 */
struct Comparator{
    int operator()(int l, int r) const {
        return r<l;
    }
};
struct Vec;
//set<int, Comparator> S;

// solution below
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
int main() {

    cout.precision(10);
    cout<<fixed;
    ll K,N;
    vector<ll> As;
    cin >>K>>N;
    As.resize(N);
    REP(i,N)
        cin>>As[i];
    As.pb(As[0]+K);
    ll m=0;
    REP(i,N+1)
        m=max(m,As[i+1]-As[i]);
    cout<<K-m<<endl;

}

struct Vec{
    double v[2];
    string to_s(){
        return "("+to_string(v[0])+","+to_string(v[1])+")";
    }
    double& operator[](int t){
        return v[t];
    }
    Vec operator+(Vec t) {
        return {v[0]+t[0],v[1]+t[1]};
    }
    Vec& operator+=(Vec t) {
        v[0]+=t[0];v[1]+=t[1];
        return *this;
    }
    Vec operator-(Vec t) {
        return {v[0]-t[0],v[1]-t[1]};
    }
    Vec& operator-=(Vec t) {
        v[0]-=t[0];v[1]-=t[1];
        return *this;
    }
    Vec operator*(double t) {
        return {v[0]*t,v[1]*t};
    }
    Vec& operator*=(double t) {
        v[0]*=t;v[1]*=t;
        return *this;
    }
    double operator*(Vec t) {
        return v[0]*t[0]+v[1]*t[1];
    }
    Vec operator-(){
        return {-v[0],-v[1]};
    }
    static Vec Z;
};
Vec Vec::Z={0,0};


Measured memory_bytes: 4864
import static java.util.Arrays.deepToString;

import java.util.Arrays;
import java.util.Scanner;

import javax.swing.plaf.basic.BasicComboBoxUI.ComboBoxLayoutManager;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}
	void tr(Object... os) {
		System.err.println(deepToString(os));
	}

	Scanner sc = new Scanner(System.in);
	public void run() {
		int T = sc.nextInt();
		for (int t = 1; t <= T; t++) {
			System.out.printf("Case %d:\n", t);
			solve();
		}
	}
	void solve() {
		int x = sc.nextInt();
		int n = 4;
		for (int step = 0; step < 10; step++) {
			String s = String.format("%08d", x * x).substring(2, 6);
			x = Integer.parseInt(s, 10);
			System.out.println(x);
		}
	}
}

Measured memory_bytes: 17320
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int H = sc.nextInt();
            int W = sc.nextInt();
            if(H == 0 && W == 0){
                break;
            }
            for(int i=0;i<H;i++){
                for(int j=0;j<W;j++){
                    System.out.printf("#");
                }
                System.out.printf("\n");
        }
        System.out.printf("\n");
    }
}
}


Measured memory_bytes: 64216
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
using namespace std;
typedef long long ll;

#define _ { \
	ios_base::sync_with_stdio(false); \
    cin.tie(NULL); \
}

int main(){
   _;
   vector<int> v={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
   int n;cin>>n;
   cout<<v[n-1];
  
}

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

struct Node{
    int key;
    Node *right, *left, *parent;
};

Node *root, *NIL;

void insert(int key){
    Node *y = NIL;
    Node *x = root;
    Node *z;

    z = (Node*)malloc(sizeof(Node));
    z->key = key;
    z->left = NIL;
    z->right = NIL;

    while(x!= NIL){
        y = x;
        if(z->key < x->key) x = x->left;
        else x = x->right;
    }
    z->parent = y;
    if(y == NIL) root = z;
    else{
        if(z->key < y->key) y->left = z;
        else y->right = z;
    }
}

void inorder(Node *u){
    if(u==NIL) return;
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
}
void preorder(Node *u){
    if(u==NIL) return;
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
}

int main(){
    int n, x;
    string com;

    cin >> n;
    for(int i=0;i<n;i++){
        cin >> com;
        if(com == "insert"){
            cin >> x;
            insert(x);
        }
        else if(com == "print"){
            inorder(root);
            cout << endl;
            preorder(root);
            cout << endl;
        }
    }
    return 0;
}




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

using namespace std;
typedef long long int ll;
typedef long double ld;
#define REP(i, n) for(ll i = 0LL; i < (ll)(n); i++)
#define REPR(i, n) for (ll i = (ll)(n) - 1; i >= 0; i--)
#define FOR(i, n, m) for(ll i = (ll)n; i < (ll)(m); i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1LL << 62)

#define PI (acos(-1))
#define PRINT(x) std::cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll countDigit(ll n) { return floor(log10(n) + 1); } 
typedef pair <ll,ll> P;
static const ll dx[8] = {0,1,0,-1, 1, -1, 1, -1}, dy[8] = {1,0,-1,0,1,1,-1,-1};

template <typename T> 
ostream& operator<<(ostream& os, const vector<T>& v) 
{ 
    for (int i = 0; i < (int)v.size(); ++i) os << v[i] << " ";  
    return os; 
}

template <typename T1, typename T2> 
ostream& operator<<(ostream& os, const map<T1, T2>& m) 
{ 
    for (auto p : m) os << "<" << p.first << ", " << p.second << "> "; 
    return os; 
}

int main()
{ 
  ll N;
  cin >> N;
  
  vector<ll> A(N+1);
  ll sum = 0;
  REP(i, N+1) { 
      cin >> A[i];
      sum += A[i];
  }
  ll notleaf = 1 - A[0];
  if (notleaf < 0) {
    PRINT(-1);
    return 0;
  }
  sum -= A[0];
  if (notleaf > sum) {
    PRINT(-1);
    return 0;
  }

  ll ans = 1;
  FOR(i, 1, N+1) {
    ll tmp = 2*notleaf - A[i];
    if (tmp < 0) {
      PRINT(-1);
      return 0;
    }
    sum -= A[i];
    if (tmp > sum) {
      tmp = sum;
    }
    notleaf = tmp;
    ans += A[i] + notleaf;
  }
  PRINT(ans);
  return 0;
} 


Measured memory_bytes: 4112
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int n,i,j,b,m=0,sum=0;
    cin>>n;
    char a[n];
    cin>>a;

    for(i=0;i<n;i++)
    {
        if(a[i]!=a[i+1])
        {
            m++;
        }


    }
    cout<<m<<endl;

}


Measured memory_bytes: 384
A = int(input())
B = int(input())
C = int(input())
X = int(input())

flg = 0
count = 0
for i in range(A+1):
    if 500 * i > X:
        break
    for j in range(B+1):
        if 500 * i + 100 * j > X:
            break
        for k in range(C+1):
            _sum = 500 * i + 100 * j + 50 * k
            if _sum > X:
                break
            if _sum == X:
                count += 1
print(count)

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

const int size = 200000;
int_t n;
int_t a[size];
int_t b[size];

bool input() {
  if (cin >> n) {
    rep (i, n) cin >> a[i];
    rep (i, n) cin >> b[i];
    return true;
  }
  return false;
}

const int psize = 50;
int_t p[psize];
int_t t[psize][size];

int count(int k, int_t ai) {
  int res = 0;
  auto tk = t[k];
  int c1 = lower_bound(tk, tk+n, p[k] - ai) - lower_bound(tk, tk+n, p[k-1] - ai);
  int c2 = lower_bound(tk, tk+n, p[k+1] - ai) - lower_bound(tk, tk+n, p[k] + p[k-1] - ai);
  return c1 + c2;
}

void solve() {
  p[0] = 1;
  rep (k, psize-1) {
    p[k+1] = p[k] * 2LL;
  }

  int_t mask = 1;
  rep (k, psize) if (k > 0) {
    rep (i, n) t[k][i] = b[i] & mask;
    sort(t[k], t[k]+n);
    mask = (mask << 1LL) | 1LL;
  }

  int cnt[psize];
  fill(cnt, cnt+psize, 0);
  int_t mask2 = 1;
  rep (k, psize-1) if (k > 0) {
    rep (i, n) {
      cnt[k] += count(k, a[i] & mask2);
    }
    mask2 = (mask2 << 1LL) | 1LL;
  }

  int_t res = 0;
  rep (k, psize) if (k > 0) {
    if (cnt[k] % 2) {
      res += 1LL << (k-1);
    }
  }
  cout << res << endl;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  while (input()) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 80000
#include<bits/stdc++.h>
using namespace std;
char s[110];
int n,pos,maxn;
int main(){
    scanf("%d%s",&n,s+1);
    for(int i=1;i<=n;++i){
        if(s[i]=='I') ++pos;
        else --pos;
        maxn=max(maxn,pos);
    }
    printf("%d\n",maxn);
    return 0;
}

Measured memory_bytes: 256
n=int(input())

l=list(map(float,input().split()))
k=[0]*(n+1)
k[0]=1
for p in l:
    for j in range(n,-1,-1):
        k[j]*=(1-p)
        if j!=0:k[j]+=k[j-1]*p

print(sum(k[n//2+1:]))

Measured memory_bytes: 43384
#include<bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
struct Node
{
    double x, y;
    Node(double xx = 0, double yy = 0){
        x = xx; y = yy;
    }

    Node operator + (Node b){
        return Node(x+b.x, y+b.y);
    }
    Node operator - (Node b){
        return Node(x-b.x, y-b.y);
    }
    Node operator * (double a){
        return Node(a*x, a*y);
    }
    Node operator / (double a){
        return Node(x/a, y/a);
    }

    double norm(){return x*x+y*y;}
    double len(){
        return sqrt(norm());
    }

    bool operator < (const Node &p) const{
        return x!=p.x ? x<p.x : y<p.y;
    }

    bool operator == (const Node &p) const {
        return fabs(x-p.x)<eps && fabs(y-p.y)<eps;
    }
};

typedef Node vtr;

struct line{
    Node a, b;
    line(Node x, Node y){
        a = x, b = y;
    }
};

//向量点积
double dot(vtr a, vtr b){
    return a.x*b.x+a.y*b.y;
}

//向量叉积
double cross(vtr a, vtr b){
    return a.x*b.y-a.y*b.x;
}

//投影 求垂足坐标
//点p在直线p1p2上的投影
Node project(line s, Node p)
{
    vtr base = s.b-s.a;
    double r = dot(p-s.a, base)/base.norm();
    return s.a+base*r;
}


int main()
{
    Node p1, p2, p;
    cin >> p1.x >> p1.y >> p2.x >> p2.y;
    line t = line(p1, p2);

    int q; scanf("%d", &q);
    while(q--)
    {
        cin >> p.x >> p.y;
        p = project(t, p);
        printf("%.10f %.10f\n", p.x, p.y);
    }
    return 0;
}



Measured memory_bytes: 3280
module Main where

import Control.Applicative

getInt :: IO Int
getInt = head <$> getInts

getInts :: IO [Int]
getInts = map read . words <$> getLine

main :: IO ()
main = do
  { [a, b, c] <- getInts
  ; if a < b then if b < c then putStrLn "Yes"
                  else putStrLn "No"
    else putStrLn "No"
  }


Measured memory_bytes: 3604
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int k = Integer.parseInt(sc.next());
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = Integer.parseInt(sc.next());
        }

        // 主処理
        int len = a.length - k;
        int count = 1;
        while (0 < len) {
            len -= k - 1;
            count++;
        }
        int result = count;

        // 出力
        System.out.println(result);
        sc.close();
    }
}


Measured memory_bytes: 51032
#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <queue>
#include <stack>
#include <deque>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <iomanip>
using namespace std;

int main()
{
    int num;
    cin >> num;
    for(int i=0;i<50010;i++){
        if((int)((double)i*(double)1.08)==num){
            cout << i << endl;
            return 0;
        }
    }
    cout << ":(\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define PRINT(v) for (auto x : (V)) cout <<x <<" " <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }


int main() {
  string s; cin >>s;
  int n = s.size();
  vector<int> res(n);
  rep(i, n){
    if (s[i] == 'L') if (s[i-1] != 'R') continue;
    if (s[i] == 'R') if (s[i+1] != 'L') continue;
    // RL.
    // .RL
    int j = i;
    while (true){
      j++; if (j >= n) break; if (s[j] != 'L') break;
      j++; if (j >= n) break; if (s[j] != 'L') break;
      res[i]++;
    }
    j = i;
    while (true){
      j--; if (j < 0) break; if (s[j] != 'R') break;
      j--; if (j < 0) break; if (s[j] != 'R') break;
      res[i]++;
    }
    // .RL  RL.  どちらの状況でも最初にその位置にいた子供もここに泊まる
    res[i]++;
  }
  rep(i, n){
    cout <<res[i];
    if (i == n-1) cout <<endl;
    else cout <<" ";
  }
}

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

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

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod 1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int main() {
  int a[100001] = {};
  int n;
  cin >> n;
  rep(i, 0, n) {
    int b, c;
    cin >> b >> c;
    rep(j, b, c + 1) {
      a[j] = 1;
    }
  }

  int ans = 0;
  rep(i, 0, 100001) {
    if(a[i]) ans++;
  }

  cout << ans << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,f,e) for(int (i)=(f); (i)<(e); (i)++)
#define repr(i,e,f) for(int (i)=(e-1); (i)>=(f); (i)--)

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

// vector<tuple<long,long>> items; // (value, weight)
// auto item = items[i];
// long v = get<0>(item);
// long w = get<1>(item);
// long v, w;
//   for( int i = 0; i < N; i++ ){
//     cin >> v >> w;
//     items.push_back( make_tuple(v, w) ); // item : (value, weight)
//   }

int main(){
    string S;
    cin >> S;
    if(S[2]==S[3] && S[4]==S[5]) cout << "Yes";
    else cout << "No"; 
    
    return 0;
}

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

typedef struct F{
  string name;
  int price;
  int a, b, c, d, e, f;
  int s;
  int m;
}f;

bool comp(const f &a, const f &b){
  double va, vb, ta, tb;
  va=a.f*a.s-a.price; vb=b.f*b.s-b.price;
  ta=a.a+a.b+a.c+a.d+a.e; tb=b.a+b.b+b.c+b.d+b.e;
  for(int i=0; i<a.m-1; i++){va+=a.f*a.s; ta+=(a.d+a.e);}
  for(int i=0; i<b.m-1; i++){vb+=b.f*b.s; tb+=(b.d+b.e);}
  if((va/ta)==(vb/tb))return a.name<b.name;
  return (va/ta)>(vb/tb);
}

int main(){
  int n;
  while(cin>>n, n!=0){
    vector<f> v;
    for(int i=0; i<n; i++){
      f tmp;
      cin>>tmp.name>>tmp.price>>tmp.a>>tmp.b>>tmp.c>>tmp.d>>tmp.e>>tmp.f>>tmp.s>>tmp.m;
      v.push_back(tmp);
    }
    sort(v.begin(), v.end(), comp);
    for(int i=0; i<n; i++)
      cout<<v[i].name<<endl;
    cout<<"#"<<endl;
  }
  return 0;
}

Measured memory_bytes: 1224
s = input()
K = int(input())
l = [chr(i) for i in range(97, 97+26)]
selected = []
for i in l:
  if i in s:
    index = []
    for ind, j in enumerate(s):
      if i == j:
        index.append(ind)
    for j in index:
      temp = []
      for k in range(5):
        if j+k == len(s) or len(temp)>=K:
          break
        selected.append(s[j:j+k+1])
    selected=list(set(selected))
    selected.sort()
    if len(selected)>=K:
      print(selected[K-1])
      break


Measured memory_bytes: 4552
from sys import stdin, stdout

int_in = lambda: int(stdin.readline())
arr_in = lambda: [int(x) for x in stdin.readline().split()]
mat_in = lambda rows: [arr_in() for y in range(rows)]
str_in = lambda: stdin.readline().strip()
out = lambda o: stdout.write("{}\n".format(o))
arr_out = lambda o: out(" ".join(map(str, o)))
bool_out = lambda o: out("YES" if o else "NO")
tests = lambda: range(1, int_in() + 1)


def solve(s):
    start_up = s[0] == "<"
    curr_up = start_up
    counts = [1]
    for c in s[1:]:
        if curr_up == (c == "<"):
            counts[-1] += 1
        else:
            curr_up = not curr_up
            counts.append(1)

    curr_up = start_up
    result = counts[0]*(counts[0]-1)//2
    if not curr_up:
        result += counts[0]
    for i in range(1, len(counts)):
        if curr_up:
            result += max(counts[i-1], counts[i])
        result += counts[i]*(counts[i]-1)//2
        curr_up = not curr_up
    if curr_up:
        result += counts[-1]

    return result


if __name__ == "__main__":
    s = str_in()
    out(solve(s))

Measured memory_bytes: 54560
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>  
#include <functional>
#define ll long long int
#define ld long double
#define pb push_back
#define pll pair<ll,ll>
#define pint pair<int,int>
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define mod 1000000007
#define MAX 100009
//#define endl '\n'
#define mp make_pair
#define INF 1000000000
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define ff first
#define ss second
#define ps(x,y) fixed<<setprecision(y)<<x
#define setbits(x) __builtin_popcountll(x)			//counts no of ones in binary representation
#define w(t) 	int t; cin>>t; while(t--)
#define pi 3.141592653589793238
#define sortt(v)  sort(v.begin(),v.end())
#define lb(v,x) std::lower_bound(v.begin(),v.end(),x)
#define ub(v,x) std::upper_bound(v.begin(),v.end(),x)
#define Vi		  vector<int>

using namespace std;

int main(){
	fast;
	ll a,b,v,w,t;
	cin>>a>>v>>b>>w>>t;
	ll d1=v*t,d2=w*t;
	if(a==b)	cout<<"YES";
	else if(a>b){
		if(b-d2<a-d1)	cout<<"NO";
		else	cout<<"YES";
	}
	else{
		if(b+d2>a+d1)	cout<<"NO";
		else	cout<<"YES";
	}
}

Measured memory_bytes: 3648
a = int(input())
if a<10:
    print(a)
elif a < 100:
    print(9)
elif a < 1000:
    print(9 + a - 99)
elif a < 10000:
    print(909)
elif a < 100000:
    print(909 + a - 9999)
else:
    print(90909)

Measured memory_bytes: 2940
def main():
    N = int(input())
    B = list(map(int, input().split()))


    ok = True
    r = []
    while len(B) != 0:
        match = []
        for i, bi in enumerate(B):
            n = i+1
            if n == bi:
                match.append(i)

        if len(match) == 0:
            ok = False
            break

        t = match[-1]
        r.append(t)
        B.pop(t)
        match = []

    if ok:
        for ri in r[::-1]:
            print(ri + 1)
    else:
        print(-1)



if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
/*--Input//////////////////////////////////////////////////*/
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
#define SS(T, ...)      T __VA_ARGS__; IN(__VA_ARGS__);
#define SV(type,c,n) vector<type> c(n);for(auto& i:c)cin >> i;
/*--Output/////////////////////////////////////////////////*/
inline int p(void){cout << endl; return 0;}
template<class Head> int p(Head&& head){cout << head;p();return 0;} template<class Head,class... Tail> int p(Head&& head,Tail&&... tail){cout<<head<<" ";p(forward<Tail>(tail)...);return 0;}
struct ProconInit {
    static constexpr bool AUTOFLUSH = false;
    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvvl vector<vector<vector<ll>>>
#define debug(x) cerr<<#x<<" "<<x<<'\n';
#define all(x) (x).begin(),(x).end()
#define bit(n) (1LL<<(n))
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; }
bool cmp(pair<ll,ll> a, pair<ll,ll> b) { return a.second < b.second; }

const int MOD = 1000000007;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

signed main() {
  SS(string,s)
  bool c=false,ans=false;
  rep(i,s.size()){
      if(s[i]=='C')c=true;
      if(c&&s[i]=='F')ans=true;
  }
  Yes(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef pair<int,int > pp;
typedef long long ll;
 
#define sz(x) (int)x.size() 
int const N=3e5+10,oo=1e9;
ll const OO=2e18;
double const eps=1e-8,PI=acos(-1);
int mod=oo+7;

int n,m,vis[1002][1002];
char cc[1002][1002];
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
bool valid(int r,int c){
    return r>-1&&r<n&&c>-1&&c<m;
}
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin>>n>>m;
  for(int i=0;i<n;i++)cin>>cc[i];
  queue<pp > q;
  for(int i=0;i<n;i++){
      for(int j=0;j<m;j++){
          if(cc[i][j]=='#'){
              q.push({i,j});
              vis[i][j]=1;
          }
      }
  }
  int an=1;
  while(!q.empty()){
      pp cur=q.front();
      q.pop();
      for(int i=0;i<4;i++){
          int nr=cur.first+dy[i];
          int nc=cur.second+dx[i];
          if(valid(nr,nc)&&!vis[nr][nc]){
              vis[nr][nc]=vis[cur.first][cur.second]+1;
              an=max(an,vis[nr][nc]);
              q.push({nr,nc});
          }
      }
  }
  cout<<an-1<<endl;
  return 0;
}


Measured memory_bytes: 13328
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int k = sc.nextInt();
		
		// 計算
		int result = 1;
		if(n%k == 0) result = 0;
		
		// 出力
		System.out.println(result);
	}
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
#define start_routine cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false); int begtime = clock();
#define end_routine int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
#define PB push_back
#define MP make_pair
#define MOD (int)1e9 + 7
#define int long long
#define maxn 100000
#define inf (int) 3e18
#define eps (double)1e-8
#define forn(a, b, i) for (int i = a; i < b; i += 1)
#define vi vector<int>
#define all(v) v.begin(), v.end() 
#define pii pair<int, int>
#define mii map<int, int> 
#define print(stuff) cout << stuff << endl
#define len(stuff) stuff.size()

vi f(maxn + 1, 0);
vi tree(4*maxn + 1, 0);
vi arr(maxn + 1);

void add (int idx, int val) {
	while (idx <= maxn) {
		f[idx] += val;
		idx += idx & -idx;
	}
}

int query (int idx) {
	int ans = 0;
	while (idx > 0) {
		ans += f[idx];
		idx -= idx & -idx;
	}
	return ans;
}

void build (int node, int l, int r) {
	if (l == r) {
		tree[node] = arr[l];
		return;
	}
	int mid = (l + r) >> 1;
	build (2*node + 1, l, mid);
	build (2*node + 2, mid + 1, r);
	tree[node] = max(tree[2*node + 2], tree[2*node + 1]);
}

int find_max (int node, int l, int r, int lq, int rq) {
	if (l == r && lq <= l && l <= rq) return tree[node];
	if (l > rq || r < lq) return -1;
	if (l >= lq && r <= rq) return tree[node];
	int mid = (l + r) >> 1;
	return max(find_max(2*node + 1, l, mid, lq, rq), find_max(2*node + 2, mid + 1, r, lq, rq));
}

signed main() {	
	start_routine;
	#ifndef ONLINE_JUDGE
	//freopen("input.txt", "r", stdin);
	#endif
	
	string s;
	cin >> s;

	int a = 0;
	for (int i = 0; i < len(s); ++i) {
		if (s[i] == '+') a += 1;
		else if (s[i] == '-') a -= 1;
	}
	print(a);
	end_routine;
}

Measured memory_bytes: 4992
n = int(input())
l = [int(i) for i in input().split()]
l2 = sorted(l)

ans_list = [l2[(n//2)-1],l2[n//2]]

for i in l:
    if i > ans_list[0]:
        print(ans_list[0])
    else:
        print(ans_list[1])


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

using namespace std;

int main() {
  int n;
  cin>>n;
  int d = n %10;
  if(d == 3)
    cout<<"bon\n";
  else if( d == 0 || d == 1 || d == 6 || d ==8)
    cout<<"pon\n";
else
    cout<<"hon\n";
}

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

using namespace std;

typedef long long tint;

const tint INF = 2e14+1;
const long double PI = 3.141592;
const int MOD =  998244353;
 
#define forsn(i, s, n) for(int i=s;i<int(n);i++)
#define forn(i, n) forsn(i, 0, n)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define NACHO ios_base::sync_with_stdio(0);cin.tie(NULL);
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
 
int main(){
	NACHO;
	int a, b, c; cin >> a >> b >> c;
	int res = min(a+b+1, c);
	cout << res+b << "\n";	
}


 



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;



int main(){
    int N; cin >> N;
    vector<int> A(N);
    rep(i,N) cin >> A[i];
    multiset<int> st;
    rep(i,N) st.insert(A[i]);
    int ans = 0;
    while(!st.empty()){
        auto p = st.end();
        p--;
        int x = *p;
        int k = x;
        int cnt = 0;
        while(k > 0){
            k /= 2;
            cnt++;
        }
        int d = (1<<cnt)-x;
        st.erase(p);
        auto p2 = st.find(d);
        if(p2 != st.end()){
            st.erase(p2);
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 10368
#include <bits/stdc++.h>
using namespace std;
 
struct edge {int /*from,*/to,cost;};
typedef long long ll;
typedef pair<int,int> P;
typedef pair<pair<int,int>,int> PP;
typedef vector<int> VI;
typedef vector<long long int> VL;
typedef vector<edge> VE;
static const int MOD = 1000000007;
static const int INF = 2147483647;
//static const long long INF = 9223372000000000000;
//static const long long INF = 9223372000000000000/2;
//static const int INF = 1000010000;
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define np next_permutation
#define pq priority_queue
#define SZ(a) int((a).size())
#define LEN(a) int((a).length())
#define MAX(a,b,c) max((a),max((b),(c)))
#define MIN(a,b,c) min((a),min((b),(c)))
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REP1(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREP1(i,x) for(int i=((int)(x));i>0;i--)
#define int ll

int fact[114514];

void f(){
    fact[0] = 1;
    REP1(i,114513){
        fact[i] = (fact[i-1] * i) % MOD;
    }
}

signed main(){
    int n;
    scanf("%lld",&n);
    f();
    printf("%lld\n",fact[n]);
    return 0;
}

Measured memory_bytes: 1152
//ABC043 A問題
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

using ll = long long;

#define bil ((ll)1e9)
#define mod ((ll)1e9+7)

int main(int argc,char* argv[]){
    int n;
    cin >>n;

    int ans = (n*(n+1))/2;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int r, D, x;
	cin >> r >> D >> x;
	for (int i = 0; i < 10; ++i)
	{
		int res = r*x - D;
		cout << res << endl;
		x = res;
	}

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(void){
  int n;
  scanf("%d",&n);
  char s[n][11];
  for(int i=0;i<n;i++){
	scanf("%s",s[i]);
  }
  qsort(s,n,sizeof(char)*11,strcmp);
  int c=1;
  for(int i=0;i<n-1;i++){
	if(strcmp(s[i],s[i+1])!=0)c++;
  }
  printf("%d",c);
  return 0;
}

Measured memory_bytes: 5736
#include <stdio.h>
#include <string.h>
#define lop(i, n) for(i=0; i<n; i++)

int compare_int(const void *a, const void *b) { //sort
  return *(int*) a-*(int*) b;
}

int main()
{
	int n, m, i, ans=0;
	scanf("%d %d", &n, &m);
	int x[100000], l[100000];
	lop(i, m){ scanf("%d", &x[i]); }
	
	if(n>=m){ printf("0"); return 0; }
	
	qsort(x, m, sizeof(int), compare_int);
	
	lop(i, m-1){ l[i]=x[i+1]-x[i]; }
	qsort(l, m-1, sizeof(int), compare_int);
	lop(i, m-n){ ans+=l[i]; }
	
	printf("%d", ans);
	
return 0;
}

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

int main() {
  string s;
  cin>>s;
  int n=s.size();
  int c=0;
  /////////////////
  rep(i,n/2){
    if(s[i]!=s[n-i-1]){
      c++;
    }
  }
  cout<<c<<endl;
}





Measured memory_bytes: 256
H, W = map(int, input().split())
S = [0 for j in range(H)]
for i in range(H):
    S[i] = list(str(input()))
TF = [[False for i in range(W)] for j in range(H)]
first = [0,0]
for j in range(H):
    for i in range(W):
        if S[j][i] == '#':
            TF[j][i] = True
        else:
            first = [j,i]
distance = [[0 for i in range(W)] for j in range(H)]
def bfs(s):
    Q = []
    TF[s[0]][s[1]] = True
    Q.append(s)
    while Q:
        v = Q.pop(0)
        next = [[v[0], v[1]+1], [v[0], v[1]-1],[v[0]+1, v[1]], [v[0]-1,v[1]]]
        for u in next:
            if u[0] >= 0 and u[0] <= H-1 and u[1] >= 0 and u[1] <= W-1:
                if TF[u[0]][u[1]] == False:
                    distance[u[0]][u[1]] = distance[v[0]][v[1]] + 1
                    TF[u[0]][u[1]] = True
                    Q.append(u)

maxd = 0
for k in range(H):
    for l in range(W):
        if S[k][l] == '.':
            first = [k,l]
            TF = [[False for i in range(W)] for j in range(H)]
            for j in range(H):
                for i in range(W):
                    if S[j][i] == '#':
                        TF[j][i] = True
            distance = [[0 for i in range(W)] for j in range(H)]
            bfs(first)
            #print(first)
            #print(distance)
            for j in range(H):
                for i in range(W):
                    maxd = max(maxd,distance[j][i])

print(maxd)


Measured memory_bytes: 3316
int_list = list(map(int, input().split(' ')))

max_int = max(int_list)

cnt = 0
for i in range(3):
    if i < max_int:
        cnt_tmp = (max_int - int_list[i]) // 2
        int_list[i] += 2 * cnt_tmp
        cnt += cnt_tmp

min_int = min(int_list)
int_list2 = sorted([i - min_int for i in int_list])

if int_list2 == [0, 0, 0]:
    print(cnt)
elif int_list2 == [0, 0, 1]:
    print(cnt + 1)
else:
    print(cnt + 2)

Measured memory_bytes: 3064
#include<iostream>
#include<stdio.h>
#include<cmath>
using namespace std;
int main(){
    int n;
    double p1 = 0;
    double p2, p3;
    double P = 0;
    double sp2 = 0;
    double sp3 = 0;
    
    
    cin >> n;
    
    int X[n];
    int Y[n];
    
    for(int i = 0; i < n; i++){
        cin >> X[i];
    }
    
    for(int i = 0; i < n; i++){
        cin >> Y[i];
    }
    
    for(int i = 0; i < n; i++){
        p1 += fabs(X[i] - Y[i]);
    }
    
    for(int i = 0; i < n; i++){
        sp2 += (X[i] - Y[i]) * (X[i] - Y[i]);
    }
    
    p2 = sqrt(sp2);
    
    for(int i = 0; i < n; i++){
        sp3 += pow(fabs(X[i] - Y[i]), 3);
    }
    
    p3 = cbrt(sp3);
    
    for(int i = 0; i < n; i++){
        if(P < (fabs(X[i] - Y[i]))){
            P = fabs(X[i] - Y[i]);
        }
    }
    
    printf("%.7lf\n", p1);
    printf("%.7lf\n", p2);
    printf("%.7lf\n", p3);
    printf("%.7lf\n", P);
}


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

using namespace std;

int main()
{	
	long long int a , b , c , k;
	cin >> a >> b >> c >> k;
	if(abs(a - b) > pow(10,18))cout << "Unfair";
	else if(k % 2 == 0)
	{
		cout << (a - b);
	}
	else if(k % 2 != 0)
	{
		cout << -(a - b);
	}
}

Measured memory_bytes: 768