akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
struct Dinic {
	struct Edge {
		int u, v;
		long long cap, flow;
		Edge() {}
		Edge(int u, int v, long long cap): u(u), v(v), cap(cap), flow(0) {}
	}; 
	int N;
	vector<Edge> E;
	vector<vector<int>> g;
	vector<int> d, pt;

	Dinic(int N): N(N), E(0), g(N), d(N), pt(N) {}

	void AddEdge(int u, int v, long long cap) {
		if (u != v) {
			E.emplace_back(Edge(u, v, cap));
			g[u].emplace_back(E.size() - 1);
			E.emplace_back(Edge(v, u, 0));
			g[v].emplace_back(E.size() - 1);
		}
	}

	bool BFS(int S, int T) {
		queue<int> q({S});
		fill(d.begin(), d.end(), N + 1);
		d[S] = 0;
		while(!q.empty()) {
			int u = q.front(); q.pop();
			if (u == T) break;
			for (int k: g[u]) {
				Edge &e = E[k];
				if (e.flow < e.cap && d[e.v] > d[e.u] + 1) {
		 			d[e.v] = d[e.u] + 1;
		 			q.emplace(e.v);
		    	}
		  	}
		}
		return d[T] != N + 1;
	}

	long long DFS(int u, int T, long long flow = -1) {
		if (u == T || flow == 0) return flow;
		for (int &i = pt[u]; i < g[u].size(); ++i) {
			Edge &e = E[g[u][i]];
			Edge &oe = E[g[u][i]^1];
			if (d[e.v] == d[e.u] + 1) {
				long long amt = e.cap - e.flow;
				if (flow != -1 && amt > flow) amt = flow;
				if (long long pushed = DFS(e.v, T, amt)) {
					e.flow += pushed;
					oe.flow -= pushed;
					return pushed;
				}
			}
		}
		return 0;
	}

	long long MaxFlow(int S, int T) {
		long long total = 0;
		while (BFS(S, T)) {
			fill(pt.begin(), pt.end(), 0);
			while (long long flow = DFS(S, T))
				total += flow;
		}
		return total;
	}
};
int main(){
	ios_base::sync_with_stdio(0);
	long long n,a[105],sum=0;
	cin>>n;
	Dinic d(105);
	for(int i=1;i<=n;++i){
		cin>>a[i];
		if(a[i]>=0) {
			sum+=a[i];
			d.AddEdge(0,i,a[i]);
		}
		else{
			d.AddEdge(i,102,-a[i]);
		}
	}
	for(int i=1;i<=n;++i)
		for(int j=2*i;j<=n;j+=i)
			d.AddEdge(j,i,1e18);
	cout<<sum-d.MaxFlow(0,102);
}

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

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    int sum=0;
    int count=0;
    if(a > b){
        cout << 0 << endl;
        return 0;
    }
    while(true){
        sum = count*a;
        if(b < sum){
            count--;
            break;
        }
        if(c == count)
            break;
        count++;
    }
    cout << count << endl;
}

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

using namespace std;

int main(){
    int n;
    cin >> n;
    
    vector<int> v(n);
    int mx = 0, sum = 0;
    
    for(int i = 0; i < n; i++){
        cin >> v[i];
        mx = max(mx, v[i]);
        sum += v[i];
    }
    
    if(sum > 2 * mx)
    cout << "Yes";
    else
    cout << "No";
}

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

using namespace std;
#define int long long int
constexpr int INF = std::numeric_limits<int>::max();
constexpr int MOD = 1000000007;
constexpr int SIZE = 100100;

void solve() {
  int N;
  cin >> N;

  vector<tuple<string, int, int>> v;

  for (int i = 1; i <= N; i++) {
    char c[20];
    int score;
    scanf("%s %lld", c, &score);
    v.emplace_back(c, INF - score, i);
  }

  sort(v.begin(), v.end());
  for (auto &t: v) {
    cout << get<2>(t) << endl;
  }
}

signed main() {
  solve();
  return 0;
}


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

template<typename T,typename F>
struct SegmentTree {
private:
    int n;
    vector<T> node;
    T id;
    F f;
public:
    SegmentTree(vector<T> v,F func,T identity):id(identity),f(func) {
        int sz = v.size();
        n = 1;
        while (n < sz) n *= 2;
        node.resize(2*n-1,id);
        for (int i = 0;i < sz;++i) node[i+n-1] = v[i];
        for (int i = n-2;i >= 0;--i) node[i] = f(node[2*i+1],node[2*i+2]);
    }

    void update(int x,T val) {
        x += (n-1);
        node[x] = val;
        while (x > 0) {
            x = (x-1)/2;
            node[x] = f(node[2*x+1],node[2*x+2]);
        }
    }

    T getval(int a,int b,int k = 0,int l = 0,int r = -1) {
        if (r < 0) r = n;
        if (r <= a || b <= l) return id;
        if (a <= l && r <= b) return node[k];
        return f(getval(a,b,2*k+1,l,(l+r)/2),getval(a,b,2*k+2,(l+r)/2,r));
    }
};

int main() {
    int n,q;
    cin >> n >> q;
    auto f = [&](int a,int b)->int{return a+b;};
    SegmentTree<int,decltype(f)> sum(vector<int>(n,0),f,0);
    for (int i = 0;i < q;++i) {
        int c,x,y;
        cin >> c >> x >> y;
        if (c) cout << sum.getval(x-1,y) << endl;
        else sum.update(x-1,f(y,sum.getval(x-1,x)));
    }
    return 0;
}


Measured memory_bytes: 4164
#include <stdio.h>

int main(void)
{
    int n, i, ans = 0;
    scanf("%d", &n);
    char a[n], b[n], c[n];
    scanf("%s", a);
    scanf("%s", b);
    scanf("%s", c);

    for (i = 0; i < n; i++) {
        int ax = a[i] - 'a', bx = b[i] - 'a', cx = c[i] - 'a';
        if (ax - bx == 0 || ax - cx == 0) {
            if (bx - cx != 0)
                ans++;
        }
        else if (bx - cx == 0 && ax - bx != 0)
            ans++;
        else
            ans += 2;
    }

    printf("%d", ans);

    return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
#include<algorithm>
#define r(i,n)for(int i=0;i<n;i++)
main(){int c[10][10],H,W,t,a;scanf("%d%d",&H,&W);r(i,10)r(j,10)scanf("%d",&c[i][j]);r(k,10)r(i,10)r(j,10)c[i][j]=std::min(c[i][j],c[i][k]+c[k][j]);r(h,H)r(w,W){scanf("%d",&t);if(t>=0)a+=c[t][1];}printf("%d\n",a);}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF 2147483647//int max
const int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;


int main() {
    int n,k;
    cin >> n >> k;
    vector<int> x(n,0);
    rep(i,n)cin >> x.at(i);
    int ans = 0;
    rep(i,n){
        ans += min(2*x[i],2*(k-x[i]));
    }
    cout << ans << endl;
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

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

struct Node {
    int index = -1;
    int depth = -1;
    int parent = -1;
    vector<int> child;
};

int get_depth(Node *node, int index) {
    if (node[index].parent < 0) {
        return 0;
    } else if (node[index].depth > 0){
        return node[index].depth;
    } else {
        int d = get_depth(node, node[index].parent) + 1;
        for (int i : node[node[index].parent].child) { node[i].depth = d; }
        return node[index].depth;
    }
}

int main() {
    int n;
    cin >> n;
    Node a[n];
    
    for (int i = 0; i < n; ++i) {
        int x, y;
        cin >> x >> y;
        a[x].index = x;
        for (int j = 0; j < y; ++j) {
            int b;
            cin >> b;
            a[x].child.push_back(b);
            a[b].parent = x;
        }
    }
    
    for (Node i : a) {
        string child = "";
        for (int j : i.child) {
            string c = child == "" ? "" : ", ";
            child += c + to_string(j);
        }
        cout << "node " << i.index << ": ";
        cout << "parent = " << i.parent << ", ";
        cout << "depth = " << get_depth(a, i.index) << ", ";
        cout << (i.parent < 0 ? "root" : (i.child.size() < 1 ? "leaf" : "internal node")) << ", ";
        cout << "[" << child << "]" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 8636
a= gets.to_i
for i in 0...a
  ans = []
  q,w,e = gets.split(" ").map(&:to_i) ; ans.push(q,w,e) 
  ans.sort!
  if ans[0]**2+ans[1]**2 == ans[2]**2 
    puts "YES" 
  else 
    puts "NO"
  end
end

Measured memory_bytes: 5596
#include <stdio.h>

int main() {
    int P, Q, R, a, b ,c;
    scanf("%d %d %d", &P, &Q, &R);
    a=P+Q;
    b=R+Q;
    c=P+R;
    if(a < b){
        if(a < c){
            printf("%d", a);
        }else{
            printf("%d", c);
        }
    }else{
        if(b < c){
            printf("%d", b);
        }else{
            printf("%d", c);
        }
    }
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <random>

int last(int d, int i, int *t)
{
    int l = 0;
    for (int j = 1; j <= d; j++)
    {
        if (t[j] == i)
        {
            l = j;
        }
    }
    return l;
}

int rand_int(int max)
{
    std::random_device rd;
    std::mt19937 gen(rd());
    std::uniform_int_distribution<> dis(1, max);

    return dis(gen);
}

int main(void)
{
    int D;
    int c[27];

    scanf("%d", &D);
    for (int i = 1; i <= 26; i++)
    {
        scanf("%d", &c[i]);
    }

    int **s;
    s = new int *[D + 1];
    for (int i = 1; i <= D; i++)
    {
        s[i] = new int[27];
    }

    for (int d = 1; d <= D; d++)
    {
        for (int i = 1; i <= 26; i++)
        {
            scanf("%d", &s[d][i]);
        }
    }

    int *T = new int[D + 1];

    for (int d = 1; d <= D; d++)
    {
        T[d] = rand_int(26);
    }

    int score = 0;
    for (int d = 1; d <= D; d++)
    {
        score += s[d][T[d]];
        for (int i = 1; i <= 26; i++)
        {
            score -= c[i] * (d - last(d, i, T));
        }
    }

    int d_new, t_new, t_old, score_old, res;

    for (int sample = 0; sample < 1000; sample++)
    {
        score_old = score;
        score = 0;

        d_new = rand_int(D);
        t_new = rand_int(26);

        t_old = T[d_new];
        T[d_new] = t_new;

        for (int d = 1; d <= D; d++)
        {
            score += s[d][T[d]];
            for (int i = 1; i <= 26; i++)
            {
                score -= c[i] * (d - last(d, i, T));
            }
        }

        res = score - score_old;

        if (res < 0)
        {
            T[d_new] = t_old;
            score = score_old;
        }

        // printf("step = %d, score = %d\n", sample, score);
    }

    // printf("%d\n", score);

    for (int d = 1; d <= D; d++)
    {
        printf("%d\n", T[d]);
    }

    return 0;
}


Measured memory_bytes: 3412
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
#define se cout << "test ok" << endl;
#define sp << " " <<
using namespace std;
using ll = long long;
using ld = long double;
ll mod = ll(1e9)+7;
ll inf = ll(5e18);
template<typename T1, typename T2> ll ceill(T1 a, T2 b){ return (a+b-1)/b; }
void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b){a=b; return true;} return false; }
template<typename T> inline bool chmin(T &a, T b){ if(a>b){a=b; return true;} return false; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ fill((T*)array, (T*)(array+N), val); }
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

#include <iostream>
#include <vector>
#include <map>
using namespace std;

namespace dbg {
    using ll = long long;

    class Debug {
    public:
        Debug(){}
        template<typename T>
        void vd(vector<T> vec);
        template<typename T>
        void vd2(vector<vector<T>> vec);
        template<typename T>
        void ad(T *arr, ll n);
        template<typename T, size_t N>
        void ad2(T (&arr)[N], ll n);
        template<typename T>
        void md(T mp);
    };

    template<typename T>
    void Debug::vd(vector<T> vec) {
        for (auto vv : vec) cout << vv << " ";
        cout << endl;
    }

    template<typename T>
    void Debug::vd2(vector<vector<T>> vec) {
        for (auto vv : vec) for (auto vvv : vv) cout << vvv << " ";
        cout << endl;
    }

    template<typename T>
    void Debug::ad(T *arr, ll n) {
        for (int i = 0; i <= n; i++) cout << arr[i] << " ";
        cout << endl;
    }

    template<typename T, size_t N>
    void Debug::ad2(T (&arr)[N], ll n) {
        for (int i = 0; i <= N; i++) for (int j = 0; j <= n; j++) cout << arr[i][j] << " ";
        cout << endl;
    }

    template<typename T>
    void Debug::md(T mp) {
        cout << "key : value" << endl;
        for (auto const &m : mp) cout << m.first << " : " << m.second << endl;
        cout << endl;
    }

}

#endif //INCLUDE_DEBUG_HPP

using dbg::Debug;
Debug debug;

class CTaxIncrease {
public:
	void solve(std::istream& in, std::ostream& out) {
	    ll a, b;
	    in >> a >> b;

	    ll res = -1;
	    for(int i=1; i<=10000; i++){
            ll s = i * 0.08;
            ll t = i * 0.10;
            if(s == a && t == b){
                res = i;
                break;
            }
	    }

	    out << res << endl;
	}
};


int main() {
	CTaxIncrease solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
K = int(input())
S = '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'
A = S.split(', ')
print(A[K-1])


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

using namespace std;
int main(){
    int a;
    cin>>a;
    vector<int> v(a,0);
    for(int i=0;i<a;++i)cin>>v[i];
   sort(v.begin(),v.end());
//   for(int d:v)cout<<d;
   int c=0;
   for(int i=0;i<a;++i){
       for(int j=i+1;j<a;++j){
           for(int k=j+1;k<a;++k){
//               cout<<v[i]<<' '<<v[j]<<' '<<v[k]<<'\n';
               if((v[i]+v[j])>v[k] &&
                       (v[i]+v[k])>v[j] &&
                       (v[k]+v[j])>v[i] )++c;

           }
       }
   }

    cout<<c;
    return 0;
}


Measured memory_bytes: 256
import std.stdio;
import std.algorithm;
import std.conv;
import std.datetime;
import std.numeric;
import std.math;
import std.string;

string my_readln() { return chomp(readln()); }

void main()
{
	auto tokens = split(my_readln());
	auto S = to!string(tokens[0]);

	if (S.length == 2)
		writeln(S);
	else
	{
		foreach_reverse(e; S)
			write(e);
		writeln();
	}
	stdout.flush();
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <list>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <stack>
#include <fstream>
#include <queue>
#include <iomanip>
#include <iterator>
#include <map>
#include <unordered_map>
#include <set>
#define fast ios_base::sync_with_stdio(false)
#define mxn (ll)1e5
#define mod (ll)(1e9+7)
#define mod1 (ll)(998244353)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vvi vector<vi >
#define pi pair<ll,ll>
#define vvpi vector<vector<pi > >
#define vpi vector<pi >
#define vppi vector<pair<ll,pi > >
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define fs first
#define se second
#define crz(v,n) v.clear(),v.resize(n+1,0)
#define print(v) for(ll it=0;it<v.size();it++) cout<<v[it]<<" ";cout<<endl
#define printp(v) for(ll it=0;it<v.size();it++) cout<<v[it].first<<" "<<v[it].second<<endl
using namespace std;
int main(){
	ll n,i,c=0;cin>>n;for(i=1;i<=n;i++) if(i%3&&i%5) c+=i;
	cout<<c<<endl;
}


Measured memory_bytes: 3636
using System;
using System.Linq;

class Program {
    static void Main(string[] args) {
        int N = cin.ni();
        int K = cin.ni();
        long ans = 0;
        ans += K;

        for (int i = 1; i < N; i++) {
            ans *= K - 1;
        }
        Console.WriteLine(ans);
    }
}


public class cin {
    private static string[] s = new string[0];
    private static int i = 0;

    private static char[] cs = new char[] { ' ' };

    public static string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        i = 0;
        return next();
    }

    public static int ni() {
        return int.Parse(next());
    }

    public static long nextLong() {
        return long.Parse(next());
    }

    public static double nextDouble() {
        return double.Parse(next());
    }

}


Measured memory_bytes: 2648
#include<bits/stdc++.h>
using namespace std;
struct edge{int to,cost;};
vector<edge>G[100000];
int color[100000];
void dfs(int v,int c){
    color[v]=c;
    for(int i=0;i<G[v].size();i++){
        if(color[G[v][i].to]==-1)
            dfs(G[v][i].to,(c+G[v][i].cost)%2);
    }
}
int main(){
    int n,u,v,w;
    cin>>n;
    while(cin>>u>>v>>w){
        G[u-1].push_back((edge){v-1,w});
        G[v-1].push_back((edge){u-1,w});
    }
    memset(color,-1,sizeof(color));
    dfs(0,0);
    for(int i=0;i<n;i++)
        cout<<color[i]<<endl;
}


Measured memory_bytes: 8448
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

a.sort()
b.sort()
c.sort()

ans = 0
i = []
k = []
for j in range(n):
    left = n - 1
    right = 0
    a_mid = n // 2
    while left >= right:
        if a[a_mid] >= b[j]:
            left = a_mid - 1
        else:
            right = a_mid + 1
        a_mid = (left + right) // 2
    i.append(a_mid + 1)
    
for j in range(n):
    left = n - 1
    right = 0
    c_mid = n // 2
    while left >= right:
        if c[c_mid] > b[j]:
            left = c_mid - 1
        else:
            right = c_mid + 1
        c_mid = (left + right) // 2
    k.append(n - c_mid - 1)

ans = sum(x * y for x, y in zip(i, k))
print(ans)

Measured memory_bytes: 23556
using System;
using System.Linq;
using static System.Console;

namespace b {

static class Extensions {
   public static int ToInt(this string str) {
      return int.Parse(str);
   }
}

class Program {
   public static void Main(string[] args) {
      var tarr = ReadLine().Split(' ').Select(x => x.ToInt()).ToArray();
      var n = tarr[0];
      var m = tarr[1];
      var c = tarr[2];
      var b = ReadLine().Split(' ').Select(x => x.ToInt()).ToArray();
      
      int [][] arr = new int[n][];
      for (int i = 0; i < n; i++) {
         arr[i] = ReadLine().Split(' ').Select(x => x.ToInt()).ToArray();
      }

      int count = 0;
      for (int i = 0; i < n; i++) {
         int sum = c;
         for (int j = 0; j < m; j++) {
            sum += arr[i][j] * b[j];
         }
         if (sum > 0) count++;
      }

      WriteLine(count);
   }
}

}

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

int main(){
    int a,b;cin>>a>>b;
    if(b%a==0)cout<<a+b;
    else cout<<b-a;
    
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define uni(e) e.erase(unique(e.begin(),e.end()),e.end())
#define double long double
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; }
int INF=1e10;
int MOD=1e9+7;
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
}
int kurai(int a,int b){
  int m=pow(10,b),n=pow(10,b-1);
  return (a%m)/n;
}
int ketawa(int a){
  int k=0;
  rep(i,keta(a)){
  k+=kurai(a,i+1);
  }
  return k;
}
int gcd(int a,int b){
  if(a%b==0)
    return b;
  return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
int mid(int a,int b,int c){
  vector<int> k(3);
  k[0]=a;k[1]=b;k[2]=c;
  sort(all(k));
  return k[1];
}
bool sosuu(int a){
  bool b=1;
  if(a<=1)
    return 0;
  else{
  rep1(i,sqrt(a)-1){
  if(a%(i+1)==0)
  b=0;
  }
  return b;
  }
}
int modpow(int a,int b,int m=MOD){
 if(!b)return 1; if(b&1)return modpow(a,b-1,m)*a%m;
 int memo = modpow(a,b>>1,m);
 return memo*memo%m;
}
int fact_mod(int n) {
    int f=1; 
for(int i=2;i<n+1;i++) f=f*(i%MOD)% MOD;
    return f;
}
int mod_pow(int x,int n) {
    int res=1;
    while(n>0){
        if(n&1) res=(res*x)%MOD; 
        x=(x*x)%MOD;        
n>>=1; 
    }
    return res;
}
int c_mod(int n, int r) {
    if(r>n-r) r=n-r;
    if(r==0) return 1;
    int a=1;
    rep(i,r) 
a=a*((n-i)%MOD)%MOD;
    int b=mod_pow(fact_mod(r), MOD-2);
    return (a%MOD)*(b%MOD)%MOD;
}
signed main(){
  int a;
  cin>>a;
  vector<int> b(a);
  rep(i,a)
    cin>>b[i];
  double c=0;
  rep(i,a)
    c+=b[i];
  int d=0,e;
  rep(i,a){
    d+=b[i];
  if(d>=c/2){
    
    e=min(abs(2*d-c),abs(2*(d-b[i])-c));
  break;
  }
  }
  out(e);
}


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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define RREP0(i, n) for (int i = (n)-1; i >= 0; --i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define RREP1(i, n) for (int i = (n); i >= 1; --i)

typedef long long LL;
typedef pair<int, int> pii;

const int INTINF = int(1e9) + 1;
const LL LLINF = LL(1e18) + 1;
long double eps = 1.0E-14;
#define pow10(n) int(1e##n + n)

void solve()
{
    LL S;
    LL e9 = 1e9;
    cin >> S;
    cout << 0 << " " << 0 << " ";
    if (S != LL(1e18))
    {
        cout << e9 << " " << 1 << " ";
        cout << e9 - S % e9 << " " << S / e9 + 1 << endl;
    }
    else
    {
        cout << e9 << " " << 0 << endl;
        cout << 0 << " " << e9 << endl;
    }
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(20);
    solve();
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define FI first.first
#define SE first.second
#define TH second
#define fi first
#define se second
#define th second

using namespace std;

template<typename T>
string to_string(const vector<T>& vc, int w) {
	if(vc.empty()) return "";
	if(w + 1 == vc.size()) return to_string(vc[w]);
	return to_string(vc[w]) + "," + to_string(vc, w + 1);
}

template<typename T>
string to_string(const vector<T>& vc) {
	return "{" + to_string(vc, 0) + "}";
}

void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

class DebugStream {}LOG;
template <typename T>DebugStream &operator<<(DebugStream &s, const T&) { return s; }
#ifdef DEBUG
#define LOG clog
#endif

typedef long long ll;
typedef pair<ll, ll> ii;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 335, lg = 20, bs = 29;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifdef DEBUG
	freopen("input.txt", "r", stdin);
	#endif

	int x;
	cin >> x;
	cout << (x >= 30? "Yes": "No") << '\n';
}



Measured memory_bytes: 3652
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long LL;
template <typename F, typename S> std::ostream& operator<<(ostream& os, const pair<F,S>& p) {
    os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for(const T& a: v){ os << a << ", "; } os << "]"; return os; }
template <typename K, typename V> ostream& operator<<(ostream& os, const map<K,V>& m) {
    os << "{"; for(const auto& p: m){ os << p.first <<":"<< p.second << ", "; } os << "]"; return os; }


// import here

struct ModInt{
    static const LL MOD = 1e+9 + 7;
    LL v;
    ModInt():v(0){}
    ModInt(LL op):v(op){}
    ModInt operator+(ModInt op) const{ return (v + op) % MOD; }
    ModInt operator-(ModInt op) const{ return (v - op + MOD) % MOD; }
    ModInt operator*(ModInt op) const{ return (v * op) % MOD; }
    ModInt operator/(ModInt op) const{ return (v * op.inverse()) % MOD; }
    ModInt operator%(LL op) = delete;
    ModInt operator+=(ModInt op){ return v = (v + op) % MOD; }
    ModInt operator-=(ModInt op){ return v = (v - op + MOD) % MOD; }
    ModInt operator*=(ModInt op){ return v = (v * op) % MOD; }
    ModInt operator/=(ModInt op){ return v = (v * op.inverse()) % MOD; }
    ModInt operator-() const{ return MOD - v; }
    bool operator==(ModInt op) const{ return v == op.v; }
    bool operator!=(ModInt op) const{ return v != op.v; }
    ModInt inverse() const{ return pow(MOD-2); }
    ModInt pow(LL n) const{
        if(n < 0) return pow(MOD-1 + n);
        if(n == 0) return 1;
        ModInt res = pow(n/2);
        return res * res * ((n&1)?ModInt(v): ModInt(1));
    }
private:
    operator LL() const{ return v; }
};
istream& operator>>(istream& st, ModInt& m){ st>>m.v; return st; }
ostream& operator<<(ostream& st, const ModInt& m){ st<<m.v; return st; }


vector<ModInt> factorial(LL n){
    vector<ModInt> res(n, 1);
    for(LL i = 2; i < n; ++i) res[i] = res[i-1] * ModInt(i);
    return res;
}

ModInt permutation(LL n, LL m, vector<ModInt>& factorial){
    if(m < 0 || n < m) return 0;
    if(m == 0) return 1;
    return factorial.at(n) / factorial.at(n-m);
}

ModInt combination(LL n, LL m, vector<ModInt>& factorial){
    if(m < 0 || n < m) return 0;
    if(m == 0) return 1;
    return factorial.at(n) / factorial.at(n-m) / factorial.at(m);
}

int main(){
    LL n;
    cin >> n;
    if(n == 2){
        cout << 1 << endl;
        return 0;
    }
    if(n == 3){
        cout << 4 << endl;
        return 0;
    }
    vector<ModInt> fact = factorial(n+1);
    vector<ModInt> equal_or_less(n+1);
    for(LL k = 1; k <= n-1; ++k){
        equal_or_less[k] = fact.at(k) * fact.at(n-1-k) * combination(k-1, n-1-k, fact);
    }
    ModInt ans = 0;
    for(LL k = (n+1)/2; k <= n-1; ++k){
        assert(k-1 >= n-k-1);
        ans += (equal_or_less.at(k) - equal_or_less.at(k-1)) * ModInt(k);
    }
    cout << ans << endl;
    return 0;
}



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

int main() {
  int N;
  cin>>N;
  vector<int64_t> p(N);
  vector<int64_t> imos(N+1);
  vector<vector<int64_t>> dp(N,vector<int64_t>(N));
  for(int i=0;i<N;i++){
    cin>>p[i];
    imos[i+1]=p[i];
    imos[i+1]+=imos[i];
  }
  for(int i=1;i<N;i++){
    for(int j=i;j<N;j++){
      int a=j-i,b=j;
      int64_t A=167167167167167;
      for(int k=a;k<b;k++){
        A=min(A,dp[a][k]+dp[k+1][b]);
      }
      dp[a][b]=A+imos[b+1]-imos[a];
    }
  }
  cout<<dp[0][N-1]<<endl;
}

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

int main() {
	int a,b;
	cin >> a >> b;
	string N = "Negative";
	string P = "Positive";
	string Z = "Zero";
	
	if(a<=0 && b>=0) cout << Z << endl;
	else if(a>0){
		cout << P << endl;
	}
	else {
		if((b-a)%2==0) {
			cout << N << endl;
		}
		else cout << P << endl;
		
	}
	
	
	return 0;
}



Measured memory_bytes: 256
while True:
    n,m=map(int,input().split())
    if n==0 and m==0:
        break
    st=[int(input()) for t in range(n)]
    sh=[int(input()) for h in range(m)]
    st.sort()
    sh.sort()
    x=0
    y=0
    for i in range(len(st)):
        if y==1:
            break
        for j in range(len(sh)):
            if sum(st)-st[i]+sh[j]==sum(sh)+st[i]-sh[j]:
                print(st[i],sh[j])
                y=1
                break
            else:
                x+=1
    if x==len(st)*len(sh):
        print('-1')


Measured memory_bytes: 5604
#include<stdio.h>
main(){
	int n,i;
	int j=0;
	char a[51];
	scanf("%d",&n);
	scanf("%s",a);
	for(i=0;a[i]!='\0';i++){
		if(a[i]=='A'&&a[i+1]=='B'&&a[i+2]=='C'){
			j++;
		}	
	}	
	printf("%d",j);
}

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

# from pprint import pprint

def recur(parr, curp, curi, heads):
    # if dp[curi][heads] != -1:
    # return dp[curi][heads]
    if curi >= len(parr):
        if heads >= len(parr)//2 + 1:
            return curp
        else:
            return 0

    return (recur(parr, curp*parr[curi], curi+1, heads+1)
            + recur(parr, curp*(1-parr[curi]), curi+1, heads))

n = int(input())

parr = [float(i) for i in input().split(' ')]

# print(recur(parr, 1, 0, 0))

dp = [[0]*(n+1) for i in range(n+1)]
dp[0][0] = 1

for i in range(1, n+1):
    for j in range(i, -1, -1):
        # heads
        heads = dp[i-1][j-1] if j > 0 else 0
        # tails
        tails = dp[i-1][j]
        dp[i][j] = heads*parr[i-1] + tails*(1-parr[i-1])

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


Measured memory_bytes: 213972
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc=new Scanner(System.in);
		
		int n=sc.nextInt();
		
		int count=0;
		for(int i=1;i<=n;i++) {
			int s= String.valueOf(i).length();
			if(s%2!=0) {
				count++;
			}
		}
		System.out.println(count);

	}

}


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

int main(void){
	int a[1000];
	int N;

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

	// バブルソート, うしろから見ていく
	for(int i=0; i<N; ++i){
		for(int j=N-1; j>i; --j){
			if (a[j] < a[j-1]) {
				int temp = a[j];
				a[j] = a[j-1];
				a[j-1] = temp;
			}
		}
	}

	// ソート結果確認
	//for(int i=0; i<N; ++i){
	//	cout << a[i] << ",";
	//}
	//cout << endl;
	
	// 交互にとる=ソート後に1つ飛ばしで加算
	// Alice
	int point_Alice = 0;
	for(int i=N-1; i>=0; i=i-2){
		point_Alice += a[i];
	}
	//cout << point_Alice << endl;

	// Bob
	int point_Bob = 0;
	for(int i=N-2; i>=0; i=i-2){ // N-2からのスタートに注意
		point_Bob += a[i];
	}
	//cout << point_Bob << endl;
	
	cout << (point_Alice - point_Bob) << endl;
}

Measured memory_bytes: 256
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <fstream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
using namespace std;
#define     loop(n,i,a)     for(ll i=a;i<n;i++)
#define     loopR(n,i,a)    for(ll i=n-1;i>=a;i--)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     pii             pair<ll,ll>
#define     vi              vector<int>
#define     vll             vector<ll>
#define     vii             vector<pair<ll,ll>>
#define     sz(x)           (int)x.size()
#define     pb              push_back
#define     endl            "\n"
#define     Endl            "\n"
#define     f               first
#define     s               second
#define     mem(dp,n)       memset(dp,n,sizeof dp)
int dx[] = { 1 , 0 ,-1 , 0 ,-1 ,-1 , 1 , 1 };
int dy[] = { 0 , 1 , 0 ,-1 ,-1 , 1 ,-1 , 1 };
int KnightI[] = { 2, 1, -1, -2, -2, -1, 1, 2 };
int KnightJ[] = { 1, 2, 2, 1, -1, -2, -2, -1 };
template<typename T>
void max_self(T &a,T b){
    a=max(a,b);
}
template<typename T>
void min_self(T &a,T b){
    a=min(a,b);
}
void fast(){
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
        vector<string> __attribute__ ((unused)) args,
        __attribute__ ((unused)) int idx,
        __attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
const ll mxN=2e4+10,oo=0x3f3f3f3f,MOD=998244353;
const double PI = acos(-1);

void solve(){
    ll x;
    cin>>x;
    loop(2e2,i,-2e2){
        loop(2e2,j,-2e2)
            if(i*i*i*i*i-j*j*j*j*j==x){
                cout<<i<<' '<<j<<endl;
                return;
            }
    }
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    fast();
    solve();
}

Measured memory_bytes: 3636
N, M = map(int, input().split(" "))
height = list(map(int, input().split(" ")))
cand = [1] * N
for i in range(M):
    a, b = map(int, input().split(" "))
    a -= 1
    b -= 1
    if height[a] <= height[b]:
        cand[a] = 0
    if height[a] >= height[b]:
        cand[b] = 0
print(sum(cand))

Measured memory_bytes: 20080
A,B= map(int, input().split())


import math

X1=math.ceil(A/0.08)
X2=math.ceil(B/0.1)

Y1=math.ceil((A+1)/0.08)-1
Y2=math.ceil((B+1)/0.1)-1

if X1>Y2 or X2>Y1:
    print(-1)
else:
    print(max(X1,X2))

Measured memory_bytes: 3064
#include<stdio.h>
int main(){
  while(1){
    int m,f,r;
     scanf("%d%d%d",&m,&f,&r);
    if(m==-1 && f==-1 && r==-1) break;
    if(m==-1 || f==-1) printf("F\n");
    else if((m+f)>=80) printf("A\n");
    else if((f+m)>=65) printf("B\n");
    else if((f+m)>=50) printf("C\n");
    else if((f+m)>=30){
      if(r>=50)printf("C\n");
      else printf("D\n");
    }
    else printf("F\n");
  }
  return 0;
}



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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

#define UF_NUM 505050

li cnt[2];

int main() {
    li h, w, hh, ww;
    cin >> h >> w >> hh >> ww;
    cout << (h - hh)*(w - ww) << endl;


    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long n,k;
  cin>>n>>k;
  long long d1=n/k;
  long long d2=d1+1;
  long long a1=abs(n-(d1*k));
  long long a2=abs(n-(d2*k));
  cout<<min(a1,a2);
}

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

int main() {
  long long a,b; cin >> a >> b; 
  if(a>b) cout << a*2-1 << endl;
  else if(b>a) cout << b*2-1 << endl;
  else if(a==b) cout << a+b << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<cassert>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<bitset>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
typedef long long ll;
typedef long double ld;
#define str string
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
const ll gosenchou = 5000000000000000;
short gh[2][4] = { { 0,0,-1,1 },{ -1,1,0,0 } };
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct E {//辺の情報を入れる変数
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	ll x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(H a, H b) {
	return sqrt(pow(a.x - b.x, 2.0) + pow(a.y - b.y, 2.0));
}//rad＝座標上の2点間の距離
ll ari(ll a, ll b, ll c) {
	return (a + b)*c / 2;
}//等差数列の和
ll fact(ll x, ll k, ll p) {//最大値、個数、あまり
	ll sum = 1;
	for (int i = 0; i < k; i++) {
		sum *= (x--);
		sum %= p;
	}
	return sum;
}//階乗(正）
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x%p;
		x = x * x%p;
		n >>= 1;
	}
	return res;
}//x^n%p
short ctos(char a) {
	return (int)(a - '0');
}
const long long Inf = 4523372036854775807;
const int inf = 15000000000;
//----------------------------------------------------
//++++++++++++++++++++++++++++++++++++++++++++++++++++
set<string>a;
signed main() {
	int n;
	cin >> n;
	string pre = "a";
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		if (a.find(s) != a.end() || (i > 0 && pre[pre.size() - 1] != s[0])) {
			cout << "No\n";
			goto loop;
		}
		a.insert(s);
		pre = s;
	}
	cout << "Yes\n";
loop:;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p;

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;
const int INF = pow(2, 30) - 1;

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

  vector<ll> vec;
  
  ll tmp = N;
  ll tmp2;
  ll flag = 0;

  if(N==1){
    cout << 1 << endl;
  }
  else{
    while (tmp > 1)
    {
      if (tmp % 2 == 0)
      {
        tmp /= 2;
        if (flag == 0)
        {
          vec.push_back(1);
          flag = 1;
        }
        else
        {
          tmp2 = vec.at(vec.size() - 1);
          vec.push_back(tmp2 * 2);
        }
      }

      else
      {
        tmp = (tmp - 1) / 2;
        if (flag == 0)
        {
          vec.push_back(1);
          flag = 1;
        }
        else
        {
          tmp2 = vec.at(vec.size() - 1);
          vec.push_back(tmp2 * 2);
        }
      }
    }
    tmp2 = vec.at(vec.size() - 1);
    vec.push_back(tmp2 * 2);

    ll sum = 0;
    for (ll i = 0; i < vec.size(); i++)
    {
      sum += vec.at(i);
    }

    cout << sum << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
    
int main() {
    long N,H[20];
    long result;
    int i,max;
    cin >> N;
    for(i=0;i<N;i++){
        cin >> H[i];
    }
    max = H[0];
    result = 1;
    for(i=1;i<N;i++){
        if(H[i]>=max){
            result++;
            max = H[i];
        }
    }

    cout << result << endl;
}





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

struct Card {
    string suit;
    int num;
};

vector<Card> S;

void merge(vector<Card>& A, int left, int mid, int right) {
    int n1 = mid - left;
    int n2 = right - mid;
    vector<Card> L(n1+1);
    vector<Card> R(n2+1);
    int i;
    rep(i, n1) {
        L[i] = A[left + i];
    }
    rep(i, n2) {
        R[i] = A[mid + i];
    }
    L[n1].num = 1000000001;
    R[n2].num = 1000000001;
    int x = 0, y = 0;
    for (int k = left; k < right; k++) {
        if (L[x].num <= R[y].num) {
            A[k] = L[x];
            x++;
        } else {
            A[k] = R[y];
            y++;
        }
    }
}

void mergeSort(vector<Card>& A, int left, int right) {
    if (left + 1 < right) {
        int mid = (left + right) / 2;
        mergeSort(A, left, mid);
        mergeSort(A, mid, right);
        merge(A, left, mid, right);
    }
}

int partition(vector<Card>& A, int p, int r) {
    int x = A[r].num;
    int i = p - 1;
    for (int j=p; j<r; j++) {
        if (A[j].num <= x) {
            i++;
            Card temp = A[i];
            A[i] = A[j];
            A[j] = temp;
        }
    }
    Card temp = A[i+1];
    A[i+1] = A[r];
    A[r] = temp;
    return i+1;
}

void quickSort(vector<Card>& A, int p, int r) {
    if (p < r) {
        int q = partition(A, p, r);
        quickSort(A, p, q-1);
        quickSort(A, q+1, r);
    }
}

int main() {
    int n;
    cin >> n;
    int i;
    rep(i, n) {
        string inputSuit;
        int inputNum;
        cin >> inputSuit >> inputNum;
        Card input = {inputSuit, inputNum};
        S.push_back(input);
    }

    vector<Card> T(S.size());
    copy(S.begin(), S.end(), T.begin());

    quickSort(S, 0, n-1);
    mergeSort(T, 0, n);

    bool flag = true;
    rep(i, n) {
        if (S[i].suit != T[i].suit)
            flag = false;
    }

    if (flag) cout << "Stable" << endl;
    else cout << "Not stable" << endl;

    rep(i, n) {
        cout << S[i].suit << " " << S[i].num << endl;
    }

    return 0;
}



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

int n;
int a[30], b[30], c[30];
int res = 0;

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

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main()
{
    int a,b,k;

    cin >> k;
    cin >> a >> b;

    int x, y;
    x = b % k;
    y = a + x;

    if(y <= b) cout << "OK" << endl;
    else cout << "NG" << endl;
}

Measured memory_bytes: 3652
#include "bits/stdc++.h"
#define rep(i, j) for (int i = 0; i < j; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using ull = unsigned long long;

ll gcd(ll x, ll y);
int fac(ll n, vector<int> num);

const int INF = 1001001001;

//mint�p�̕ϐ� (10��9��)
const int mod = 1000000007;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }

int main() {
    int n;
    cin >> n;
    ll ans = 0;
    vector<int> bai(n + 1, 1);

    for (ll k = 1; k <= n; k++) {
        ll num = 1;
        if (k != 1) {
            for (int i = k; i <= n; i += k) {
                bai[i]++;
            }
        }
        ans += k * bai[k];
    }

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

/*���C�u�����ő����*/
//���[�O���b�h�̌ݏ��@
ll gcd(ll x, ll y) {
    ll num[3];
    num[0] = (x > y) ? x : y;
    num[1] = (x <= y) ? x : y;
    num[2] = num[0] % num[1];

    while (num[2]) {
        num[0] = num[1];
        num[1] = num[2];
        num[2] = num[0] % num[1];
    }

    return num[1];
}

/*�f��������*/
//���색�C�u����
int fac(ll n, vector<int> num) {
    ll kazu = n;
    for (int i = 2; i <= sqrt(n); i++) {
        while (1) {
            if (kazu % i != 0) break;

            kazu /= i;
            num[i]++;
        }
    }
    if (kazu == n && n != 1) return 1;
    int ans = 0;
    if (kazu != 1) ans++;
    for (int i = 2; i <= sqrt(n); i++) {
        for (int j = 1; j <= num[i]; j++) {
            num[i] -= j;
            ans++;
        }
    }
    return ans;
}

Measured memory_bytes: 42268
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
struct each{
	long long b,c;
}a[N];
bool com(each x,each y){
	return x.b-x.c>y.b-y.c;
}
int n,x,y,z;
long long ans,res,pre[N],suf[N];
priority_queue<long long,vector<long long>,greater<long long> >que;
int main(){
	scanf("%d%d%d",&x,&y,&z),n=x+y+z;
	for(int i=1,A;i<=n;i++){
		scanf("%lld%lld%lld",&A,&a[i].b,&a[i].c);
		a[i].b-=A,a[i].c-=A,ans+=A;
	}
	sort(a+1,a+n+1,com);
	for(int i=1;i<=y;i++)	que.push(a[i].b),res+=a[i].b;

	pre[y]=res;
	for(int i=y+1;i<=n;i++){
		if(a[i].b>que.top()){
			res+=a[i].b-que.top();
			que.pop(),que.push(a[i].b);
		}
		pre[i]=res;
	}	res=0;
	while(!que.empty())	que.pop();
	for(int i=n;i>n-z;i--)	que.push(a[i].c),res+=a[i].c;
	suf[n-z+1]=res;
	for(int i=n-z;i;i--){
		if(a[i].c>que.top()){
			res+=a[i].c-que.top();
			que.pop(),que.push(a[i].c);
		}
		suf[i]=res;
	}	res=-LLONG_MAX;
	for(int i=y;i<=n-z;i++)	res=max(res,pre[i]+suf[i+1]);
	printf("%lld\n",ans+res);
	return 0;
}


Measured memory_bytes: 3456
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#define ll long long int
using namespace std;
int n,x,f[100005],top,pd,d[100005];
ll ans=0x3f3f3f3f;
ll gcd(int a,int b){
    if(b==0)return a;
    else
    return (long long)gcd(b,a%b);
}
int main(){
	ans=ans*100000;
    scanf("%d%d",&n,&f[1]);
    for(int i=2;i<=n+1;i++)
    scanf("%d",&f[i]);
    sort(f+1,f+n+2);
    for(int i=2;i<=n+1;i++){
        d[i-1]=f[i]-f[i-1];
		if(n==1)ans=d[i-1];
    }
	if(n!=1)
    for(int i=2;i<=n;i++){
        ans=min(ans,gcd(d[i],d[i-1]));
    }
    printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 1024