akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main() {
    ll n;
    cin >> n;
    string s;
    cin >> s;
    ll ans=0;
    for(ll i=0;i<1000;i++){
        ll c[3]={i/100,(i/10)%10,i%10};
        ll f=0;
        for(ll j=0;j<n;j++){
            if(s[j]==('0'+c[f])) f++;
            if(f==3) break;
        }
        if(f==3)ans++;
    }
    cout << ans << endl;
}

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

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)

#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define pii pair<int, int>
#define vi vector<int>

using namespace std;
template <class S, class T>
ostream& operator<<(ostream& o, const pair<S, T>& p)
{
    return o << "(" << p.first << "," << p.second << ")";
}
template <class T>
ostream& operator<<(ostream& o, const vector<T>& vc)
{
    o << "sz = " << vc.size() << endl
      << "[";
    for (const T& v : vc)
        o << v << ",";
    o << "]";
    return o;
}
using ll = long long;
constexpr ll MOD = 1000000007;

pii a[100000];

int main()
{
    int N;
    ll K;
    cin >> N >> K;
    rep(i, N)
    {
        int A, B;
        cin >> A >> B;
        a[i] = mp(A, B);
    }
    sort(a, a + N);
    ll sum = 0;
    rep(i, N)
    {
        sum += a[i].snd;
        if (K <= sum) {
            cout << a[i].fst << endl;
            return 0;
        }
    }

    return 0;
}


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

#pragma region Macros
using ll = long long;
#define int ll
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
template<class T = ll> using V = vector<T>;
template<class T = ll> using VV = V<V<T>>;
#define IOS\
    ios::sync_with_stdio(false);\
    cin.tie(0);\
    cout.tie(0);
#define FOR(i,l,r) for(ll i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(ll i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define SORT(name) sort(name.begin(), name.end())
#define RSORT(name)\
    SORT(name);\
    reverse(all(name));
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';}
inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';}
template <class T> inline void print(T x){ cout << x << '\n';}
template<typename T1,typename T2> inline void chmin(T1 &a, T2 b){ if(a > b) a = b; }
template<typename T1,typename T2> inline void chmax(T1 &a, T2 b){ if(a < b) a = b; }

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
#pragma endregion

#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const int MOD = 1000000007;
const int MAX_N = 100010;

int H, W, M;
map<int, int> row, col;
set<pii> exist;

signed main() {
    IOS;

    cin >> H >> W >> M;
    int max_h = 0, max_w = 0;
    REP(i, M) {
        int h, w;
        cin >> h >> w;
        row[h]++;
        col[w]++;
        exist.insert(mp(h, w));
        chmax(max_h, row[h]);
        chmax(max_w, col[w]);
    }
    V<> row_v, col_v;   // 最大値をもつ行と列
    for(auto b : row) {
        if(b.second == max_h) {
            row_v.pb(b.first);
        }
    }
    for(auto c : col) {
        if(c.second == max_w) {
            col_v.pb(c.first);
        }
    }

    int ans = max_h + max_w - 1;
    REP(i, row_v.size()) {
        REP(j, col_v.size()) {
            auto it = exist.find(mp(row_v[i], col_v[j]));
            if(it == exist.end()) {
                print(max_h + max_w);
                return 0;
            }
        }
    }
    print(ans);

    return 0;
}


Measured memory_bytes: 67784
n, s = map(int, input().split())
a = list(map(int, input().split()))
mod = 998244353

temp = [1] + [0] * s
for i in range(n):
    temp2 = [0] * (s + 1)
    for j in range(s + 1):
        temp2[j] += temp[j] * 2
        temp2[j] %= mod
    for j in range(s + 1 - a[i]):
        temp2[j + a[i]] += temp[j]
        temp2[j + a[i]] %= mod
    temp = temp2
print(temp[s])

Measured memory_bytes: 74304
#define DEBUG 0
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<class T>using numr=std::numeric_limits<T>;
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; }
const int INF = 1e9;
const ll LLINF = 1e16;
const int MOD = 1000000007;
const int MOD2 = 998244353;
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#if DEBUG
#define debug(...)\
    do {\
        std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
        debug_impl(__VA_ARGS__);\
        std::cerr << std::noboolalpha;\
    } while (false)
#else
#define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
    { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
os << "{";
    for (auto it = v.begin(); it != v.end(); it++)
        {os << (it != v.begin() ? "," : "") << *it;}
    return os << "}";
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    int x;
    cin >> x;
    if(x >= 30) cout << "Yes" << endl;
    else{
        cout << "No" << endl;
    }

}

Measured memory_bytes: 3648
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 a = sc.nextInt();
		int b = sc.nextInt();
		int sum = 0;
		for (int i = 1; i <= n; i++) {
			int c = i;
			int isum = 0;
			while(c > 0) {
				isum += c % 10;
				c = c / 10;
							
			}
			if (isum >= a && isum <= b)
				sum += i;
			
		}
		System.out.println(sum);
	}

}


Measured memory_bytes: 21844
def read_int():
    return int(input())

def read_int_map():
    return map(int,input().split(' '))

def read_int_list():
    return list(map(int,input().split(' ')))

def read_s_list_loop(n):
    return [input() for _ in range(n)]

N,K = read_int_map()
human = [1]*N
for i in range(K):
    d = read_int()
    An = read_int_list()
    for a in An:
        human[a-1] = 0
print(sum(human))

Measured memory_bytes: 67860
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)

int main(void){
  int n,p;
  while(cin>>n>>p){
    if(n==0) break;
    vector<int> a(n);
    int i=0;
    while(1){
      if(p){
        p--;
        a[i]++;
        if(p==0&&count(a.begin(),a.end(),0)==n-1){
          cout<<i<<endl;
          break;
        }
      }else{
        p = a[i];
        a[i] = 0;
      }
      i=(i+1)%n;
    }
  }
  return 0;
}

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

typedef long long ll;
typedef long double ld;

ll k;
int n;

ll a[200005];
ll f[200005];

bool check(ll x){
    ll sum = 0;
    for(int i=1; i<=n; i++){
        ll tr = x/f[i];
        sum += max(0LL, a[i]-tr);
    }
    return sum <= k;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    cin >> n >> k;
    for(int i=1; i<=n; i++){
        cin >> a[i];
    }
    for(int i=1; i<=n; i++){
        cin >> f[i];
    }
    sort(a+1, a+1+n);
    sort(f+1, f+1+n);
    ll mx = a[n]*f[n];
    reverse(f+1, f+1+n);
    ll l = 0, r = mx-1, res = mx;
    while(l <= r){
        ll mid = (l+r)/2;
        if(check(mid)){
            r = mid-1;
            res = mid;
        }
        else l = mid+1;
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 3328
#include <cmath>
#include<vector>
#define rep(i, n) for (int i=0;i<n;i++)
#include <map> 
#include<algorithm>
#include <numeric>
#include<iostream>
#include<deque>
#include<queue>
#include<string>
#include <iomanip>
using namespace std;
typedef long long ll;

int main(void){
    int n, k, q;
    cin>>n>>k>>q;
    vector<int> a(q);
    rep(i, q){
        cin>>a[i];
    }
    vector<int>point(n, k-q);
    
    rep(i,q){
        point[a[i]-1]++;
    }
    rep(i, n){
        
        if(point[i]>0){
            cout<<"Yes"<<endl;
        }
        else{
            cout<<"No"<<endl;
        }
    }
    return 0;

}

Measured memory_bytes: 1408
#include "bits/stdc++.h"

using namespace std;

using i64 = long long;

const i64 MOD = i64(1e9) + 7;
const i64 INF = i64(1e18) + 7;

bool solve(){
    int n, m, l;
    cin >> n >> m >> l;
    if(n == 0)
        return false;

    vector<int> a(m), b(m), d(m), e(m);

    for(int i = 0; i < m; ++i)
        cin >> a[i] >> b[i] >> d[i] >> e[i];

    struct Edge{
        int to, dist, enemy;
    };

    vector<vector<Edge>> edges(n);

    for(int i = 0; i < m; ++i){
        --a[i], --b[i];
        Edge ed{b[i], d[i], e[i]};
        Edge rev{a[i], d[i], e[i]};
        edges[a[i]].push_back(ed);
        edges[b[i]].push_back(rev);
    }

    vector<vector<i64>> dp(n, vector<i64>(l + 1, INF));
    dp[0][l] = 0;
    priority_queue<tuple<i64,int,int>, vector<tuple<i64,int,int>>, greater<tuple<i64,int,int>>> que;
    que.emplace(0, 0, l);

    auto chmin = [&](auto& x, auto y){
        if(x > y){
            x = y;
            return true;
        }
        return false;
    };

    while(!que.empty()){
        i64 val, pos, money;
        tie(val, pos, money) = que.top();
        que.pop();
        if(dp[pos][money] != val)
            continue;
        for(auto& ed : edges[pos]){
            if(chmin(dp[ed.to][money], dp[pos][money] + ed.enemy))
                que.emplace(dp[ed.to][money], ed.to, money);

            if(money >= ed.dist && chmin(dp[ed.to][money - ed.dist], dp[pos][money]))
                que.emplace(dp[ed.to][money - ed.dist], ed.to, money - ed.dist);
        }
    }
    i64 ans = *min_element(dp.back().begin(), dp.back().end());
    cout << (ans == INF ? -1 : ans) << endl;


    return true;
}

signed main(){
    while(solve());
}



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

int main(){

  int N;
    cin>>N;
    vector<int> S(N);
    if(N%2==0){
    for(int i=0;i<N;i++){
        int a;cin>>a;
        if(i%2==0){
            S[(N+i)/2]=a;
        }
        else{
            S[(N-1-i)/2]=a;
        }
    }
    }
    if(N%2==1){
        for(int i=0;i<N;i++){
            int a;cin>>a;
            if(i%2==0){
                S[(N-1-i)/2]=a;
            }
            else{
                S[(N+i)/2]=a;
            }
        }
    }
    for(int i=0;i<N-1;i++){
        cout<<S[i]<<" ";
    }
    cout<<S[N-1]<<endl;
    }


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

typedef long long ll;

int main(){
  int q;

  while(cin >> q){
    ll l = 0;
    ll r = 0;

    for(int i = 0; i < q; i++){
      ll p, n;
      char c;
      cin >> p >> c >> n;

      if(c == '('){
        l += n;
      }
      else{
        r += n;
      }

      if(l == r){
        cout << "Yes" << endl;
      }
      else{
        cout << "No" << endl;
      }
    }
  }
}

Measured memory_bytes: 1168
#include<bits/stdc++.h>
#define ll long long
using namespace std;


std::vector<int> vec;

bool judge(char ss){
	if(ss=='A') return 1;
	if(ss=='G') return 1;
	if(ss=='C') return 1;
	if(ss=='T') return 1;
	return 0;
}

int main (){
    string ss;cin>>ss;
    int ans=0;
    for(int i=0;i<(int)ss.size();){
		if(judge(ss[i])){
			int cnt=0;
			for(int j=i;j<(int)ss.size();j++){
				if(judge(ss[j])) i=j+1,cnt++;
				else { i=j;break;}
			}
			ans=max(cnt,ans);
		}
		else i++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<iomanip>
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 1e9+7
#define LINF (long long)4e18


int main(){
    int A,P;
    cin >> A >> P;
    int p = A*3 + P;
    int ans = p/2;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdlib>  // abs() for integer 絶対値求めやつ
#include <cmath>    // abs() for float, and fabs()
#include <algorithm>
#include <vector>
#include <string>
#include<iomanip>//浮動小数点数を出力する制度の指定
//使い方　数値をnumとして　cout<<setprecision(n)<<num ;nは桁数
#define rep(i,n) for(int i = 0; i < (n);i++)
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
using namespace std;
using ll =long long;
#define INF 2000000000
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; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
/*覚えてないことメa
数値型から文字列に変換　to_string(number);これは簡単
文字列から数値型に変換　stoi(number)
文字列からllに変換　stoll(number)*/

//ここから書き始める
int main(){
	int n;cin>>n;
	string s; cin >> s;
	vector<int> A(n+1);
	A[0]=0;
	ll count = 0;
	for(int i = 1 ; i < n+1  ; i++){
		if(s.at(i-1) == 'W' ){
			count++;
		}
		A[i] = count;
	}
	ll ans = n;
	//i番目まででWを向いてる人の数とi+1番目からEを向いてる人の数を足し合わせたものを求める
	int bef,aft;
	for(int i = 0 ; i < n ; i ++ ){
		bef = A[i];
		aft = ((n-1)-i)-(A[n]-A[i+1]);
		ll k = bef + aft;
		chmin(ans,k);
	}
	cout<<ans<<endl;
}



Measured memory_bytes: 1796
from scipy.sparse import*
f=csgraph.floyd_warshall
I=9e9
n,m,l,*t=map(int,open(0).read().split())
d=eval('[I]*-~n,'*-~n)
for a,b,c in zip(*[iter(t[:m*3])]*3):d[a][b]=c
d=f(d,0)
d[d>l]=I
d[d<I]=1
d=f(d)
for i in zip(*[iter(t[m*3+1:])]*2):
	print((I>d[i])*int(d[i])-1)

Measured memory_bytes: 40860
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn=1e6+5;
inline void exgcd(ll a,ll b,ll &g,ll &x,ll &y) { //a*x+b*y=gcd(a,b)
    if (!b) g=a,x=1,y=0;
    else exgcd(b,a%b,g,y,x),y-=x*(a/b);
}
int main() {
	int n;cin>>n;ll l,r;cin>>l>>r;
	for(int i=2;i<=n;i++) {
		ll a,b,x,y,g;cin>>a>>b;		
		ll k=max((l+a-1)/a,(r+b-1)/b);
		y=k*a-l;x=k*b-r;
		l=l+y;r=r+x;
	}
	cout<<l+r<<endl;
    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
  using namespace std;
  int main()
  {
    int n, q, num, m;
    int A[2001]={1};
      cin>>n;
    for(int i=0; i<n; i++){
      cin>>num;
      for(int j=2000-num; j>=0; j--){
        if(A[j]) A[j+num] = 1;
      }
    }

      cin>>q;
    for(int i=0; i<q; i++){
      cin>>m;
      if(A[m])
        cout<<"yes"<<endl;
      else
        cout<<"no"<<endl;
    }

    return 0;
  }



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

using namespace std;

int main(int argc,char* argv[]){
	int N,K;
	cin >> N >> K;
	int length,count=0;
	for(int i=0;i<N;i++) {
		cin >> length;
		if(length>=K) count++;
	}
	cout << count << endl;

	return 0;
}


Measured memory_bytes: 256
/**
 *   author: malviyanshiv
 *   created: 09 January 2019  23:27:27
**/

#include <bits/stdc++.h>

using namespace std;

#define REP(i, a, b) for(int i = a; i < b; i++)
#define RREP(i, a, b) for(int i = a-1; i >= b; i--)
#define PB push_back
#define MP make_pair
#define MOD 1000000007
#define INF 0x7fffffff
#define MAX 100005

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

void fastscan(int &x){
    bool neg=false;
    register int c;
    x =0;
    c=getchar();
    if(c=='-'){
        neg = true;
        c=getchar();
    }
    for(;(c>47 && c<58);c=getchar())
        x = (x<<1) + (x<<3) +c -48;
    if(neg)
        x *=-1;
}

void optimizeIO(){
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
}

vector< vector<int> > dp(3003, vector<int>(3003, -1));

int cal(string &a, string &b, int ai, int bi ){
    if( ai == 0 || bi == 0 )
        return dp[ai][bi] = 0;
    int &res = dp[ai][bi];
    if(res != -1 )
        return res;
    if( a[ai-1] == b[bi-1] )
        res = cal(a, b, ai-1, bi-1)+1;
    return res = max( res, max( cal(a, b, ai-1, bi), cal(a, b, ai, bi-1)));
}

int main(){
	optimizeIO();
    string a,b;
    int ai, bi;
    cin >> a;
    cin >> b;
    ai = a.size(), bi = b.size();
    int len = cal(a, b, ai, bi)-1;
    string res(len+1, 'x');
    while( ai > 0 && bi > 0 ){
        if( a[ai-1] == b[bi-1] ){
            res[len--] = a[ai-1];
            ai--, bi--;
        }else if( dp[ai-1][bi] > dp[ai][bi-1] )
            ai--;
        else
            bi--;
    }
    cout << res << endl;


	return 0;
}


Measured memory_bytes: 36352
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip> 
#include <bits/stdc++.h>
using namespace std;
double pi=3.14159265358979323846264338;
#include <bits/stdc++.h>
 
#ifndef LOCAL
#define cerr dolor_sit_amet
#endif
 
#define mp make_pair
#define sz(x) ((int)((x).size()))
#define X first
#define Y second
#define all(x) (x).begin(), (x).end()
 
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int , int > ipair;
typedef pair < ll , ll > lpair;
const int IINF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;
const double DINF = numeric_limits<double>::infinity();
const int MOD = 1000000007;
const double EPS = 1e-9;
const double PI = acos(-1.0);
const int DX[] = { 1,  0, -1,  0,  1, -1,  1, -1};
const int DY[] = { 0,  1,  0, -1,  1, -1, -1,  1};
 
template<typename T> T& updMin(T& a, T const& b) { if (b < a) a = b; return a; }
template<typename T> T& updMax(T& a, T const& b) { if (a < b) a = b; return a; }
 
// ========================================================================= //
//999977 17 499998
const int ind=6000000;
double h,c,t;
double tem(double cur){
	if((2*cur+3)*labs(t*(2*cur+1)-(cur*(h+c)+h))>(2*cur+1)*fabs(t*(2*cur+3)-((cur+1)*(h+c)+h))){
		return (2*cur+3);
	
	}else {
		if((2*cur-1)*labs(t*(2*cur+1)-(cur*(h+c)+h))<(2*cur+1)*fabs(t*(2*cur-1)-((cur-1)*(h+c)+h))){
			return(2*cur+1);
			//cout<<fabs(t-(cur*(h+c)+h)/(2*cur+1))<<" "<<fabs(t-((cur-1)*(h+c)+h)/(2*cur-1))<<endl;
		}else {
			//cout<<fabs(t-(cur*(h+c)+h)/(2*cur+1))<<" "<<fabs(t-((cur-1)*(h+c)+h)/(2*cur-1))<<endl;
			return (2*cur-1);
			
		}
	}
}
long long culc(){
	long long fr=0;
	long long ls=ind;
	long long mid;
	while(ls>=fr){
		mid=(fr+ls)/2;
		if ((mid*(h+c)+h)/(2*mid+1)<t)ls=mid-1; else if((mid*(h+c)+h)/(2*mid+1)>t)fr=mid+1; else return mid;
	}
	return mid;
}
 
 
 
int main() {
	int n;
	cin>>n;
	int arr[100005];
	for(int i=0;i<=n;i++)cin>>arr[i];
	long long arr2[100005],arr3[100005];
	long long ans=1;
	if((n==0&&arr[0]!=1)||(n!=0&&arr[0]!=0)){
		cout<<"-1"<<endl;
		return 0;
	}
	arr3[n]=arr[n];
	for(int i=n-1;i>=0;i--)arr3[i]=arr[i]+arr3[i+1];
	arr2[0]=1;
	for(int i=1;i<n;i++){
		arr2[i]=arr2[i-1]*2;
		arr2[i]=min(arr2[i],arr3[i]);
		ans+=arr2[i];
		if(arr2[i]<=arr[i]){
			cout<<"-1"<<endl;
          	//cout<<i<<" "<<arr2[i]<<" "<<arr[i]<<endl;
			return 0;
		}
		arr2[i]-=arr[i];
	}
	if(n!=0){
	arr2[n]=2*arr2[n-1];
	if(arr2[n]<arr[n]){
		cout<<"-1"<<endl;
		return 0;
	}
	arr2[n]=arr[n];
ans+=arr2[n];}
	cout<<ans<<endl;
	
	
  return 0;
}



Measured memory_bytes: 5528
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner stdIn = new Scanner(System.in);
        
        int w = stdIn.nextInt();
        int num[] = new int[w];
        
        for(int i = 0; i < w; i++){
            num[i] = i + 1;
        }
        
        int n = stdIn.nextInt();
        
        for(int i = 0; i < n; i++){
            String s = stdIn.next();
            String ss[] = s.split(",");
            int a = Integer.valueOf(ss[0]) - 1;
            int b = Integer.valueOf(ss[1]) - 1;
            
            int tmp = num[a];
            num[a] = num[b];
            num[b] = tmp;
            
        }
        
        for(int i = 0; i < w; i++){
            System.out.println(num[i]);
        }
    }
}



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

int main() {
  int x;
  cin >> x;
  string str = to_string(x);
  
  bool van=false;
  for (int i=0;i<str.size();i++){
    if(str[i]=='7'){
      van=true;
    }
  }
  
  if (van==true){
    cout << "Yes";
  }else{
    cout << "No";
  }
	return 0;
}
 

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

if 1<=n and n<10: ans = n
elif 10<=n and n<100: ans = 9
elif 100<=n and n<1000: ans = 9+(n-99)
elif 1000<=n and n<10000: ans = 909
elif 10000<=n and n<100000: ans = 909+(n-9999)
elif n==100000: ans = 90909

print(ans)


Measured memory_bytes: 2940
import java.util.*;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int count = 0;
    int ans = 1;

    for(int i=1; i<N+1; i++) {
      int challengeNum = i;
      int challengeCount = 0;
      while(challengeNum % 2 == 0){
        challengeCount++;
        challengeNum /= 2;
      }
      if(count < challengeCount) {
        count = challengeCount;
        ans = i;
      }
    }

    System.out.println(ans);
  }
}


Measured memory_bytes: 23764
#include<iostream>

using namespace std;
int a[100];
int main()
{
    int N;
    cin >> N;
    for (int i=0; i<N; i++){
        cin >> a[i];
    }


   bool done=true;
    for (int k=0; k<N-1; k++)
        if (a[k] > a[k+1]){
            done=false;
        }
    if (done)
    {
        cout << "YES\n";
        return 0;
    }


    for(int i=0; i<N-1; i++){
        for (int j=i+1; j<N; j++){
            swap(a[i], a[j]);
            bool done=true;
            for (int k=0; k<N-1; k++)
                if (a[k] > a[k+1]){
                    done=false;
                }
            if (done)
            {
                cout << "YES\n";
                return 0;
            }

            swap(a[i], a[j]);
        }
    }
    cout << "NO\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
main(){
    ll n,m;
    string s,t;
    cin>>n>>m>>s>>t;
    ll g=gcd(n,m);
    for(ll i=0;i<g;i++)if(s[i*n/g]!=t[i*m/g]){
        cout<<-1;
        return 0;
    }
    cout<<n*m/g;
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
using namespace std;

int main(){

    int n , a , b;
    cin >> n >> a >> b;

    if((b - a) % 2 == 1){
        cout << "Borys" << endl;
    }
    else if( (b - a) % 2 == 0) {
        cout << "Alice" << endl;
    }


    

}

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

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

void compress(vi const& vec, map<int, int>& zip, vi& unzip){
    unzip = vec;

    sort(begin(unzip), end(unzip));
    unzip.erase(unique(begin(unzip), end(unzip)), unzip.end());

    rep(i, unzip.size()) zip[unzip[i]] = 2 * i + 1;
}

using Rect = tuple<int, int, int, int>;

int w, h;
vvi field;

vi dx = { 1, 0,-1, 0};
vi dy = { 0,-1, 0, 1};

void dfs(int y, int x){
    if(field[y][x] == 0) field[y][x] = 1;
    else return;

    rep(i, 4){
        int ny = y + dy[i], nx = x + dx[i];

        if(ny < 0 or h <= ny or
           nx < 0 or w <= nx) continue;

        dfs(ny, nx);
    }
}

int main(void){
    for(int n; cin >> n, n;){
        vi xs, ys;
        vector<Rect> rects(n);
        rep(i, n){
            int l, a, r, b; cin >> l >> b >> r >> a;
            rects[i] = tie(l, a, r, b);

            xs.push_back(l); xs.push_back(r);
            ys.push_back(a); ys.push_back(b);
        }

        vi unzip_x, unzip_y;
        map<int, int> zip_x, zip_y;

        compress(xs, zip_x, unzip_x);
        compress(ys, zip_y, unzip_y);

        for(auto & e : rects){
            int l, a, r, b;
            tie(l, a, r, b) = e;

            l = zip_x[l], r = zip_x[r];
            a = zip_y[a], b = zip_y[b];

            e = tie(l, a, r, b);
        }

        w = 201, h = 201;
        field = vvi(h, vi(w));
        for(auto & e : rects){
            int l, a, r, b;
            tie(l, a, r, b) = e;

            range(y, a, b + 1){
                field[y][l] = field[y][r] = 1;
            }
            range(x, l, r + 1){
                field[a][x] = field[b][x] = 1;
            }
        }

        int res = 0;
        rep(y, h){
            rep(x, w){
                if(field[y][x] == 0){
                    dfs(y, x);
                    res++;
                }
            }
        }

        cout << res << endl;
    }

    return 0;
}

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

int main() {
  int n, c, k;
  cin>>n>>c>>k;
  int t[n];
  for (int i=0; i<n; i++) cin>>t[i];
  sort(t, t + n);

  int ans = 1;
  int t_start = t[0];
  int num_passenger = 1;
  for (int i=1; i<n; i++) {
    if (t_start + k >= t[i]) {
      ++num_passenger;
      if (num_passenger <= c) {
        continue;
      }
    }
    t_start = t[i];
    num_passenger = 1;
    ++ans;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
main(){
  int N,T;
  cin>>N>>T;
  vector<int>A(N),B(N);
  for(auto&x:A)cin>>x;
  int A_min=A[0];
  for(int i=1;i<N;++i){
    B[i]=A[i]-A_min;
    A_min=min(A_min,A[i]);
  }
  int B_max=*max_element(B.begin(),B.end());
  int n_max=0;
  for(auto x:B)n_max+=x==B_max;
  cout<<n_max<<endl;
}


Measured memory_bytes: 1024
from sys import stdin
data = []
N = int(stdin.readline().rstrip())
for _ in range(N):
    data.append(tuple(sorted(input())))


ans = dict()

for i in data:
    if i in ans:
        ans[i] += 1
    else:
        ans[i] = 1

from scipy.misc import comb
res = 0
for j in ans.values():
    res += comb(j, 2, exact=True)
print(res)

Measured memory_bytes: 33220
L, R = (int(i) for i in input().split())
Z = 2020
if R - L >= 2019:
  print(0)
else:
  for i in range(L,R+1):
    a = i % 2019
    for j in range(i+1,R+1):
      b = j % 2019
      c = (a*b) % 2019
      if c < Z:
        Z = c
  print(Z)

Measured memory_bytes: 3060
#define mod 1000000007
char buf[30];sz;
char out[10];osz=10;
int N,K;
long I[4<<17];
main()
{
	read(0,buf,30);
	for(;;)
	{
		char c=buf[sz++];
		if(c<'0')break;
		N=N*10+c-'0';
	}
	for(;;)
	{
		char c=buf[sz++];
		if(c<'0')break;
		K=K*10+c-'0';
	}
	long ans=0;
	long x=1,y=1,r;
	for(long i=1;i<=N&&i<=K+1;i++)
	{
		ans+=x*y%mod;
		I[i]=r=i<2?1:(mod-mod/i)*I[mod%i]%mod;
		x=x*(N-i+1)%mod*r%mod;
		y=y*(N-i)%mod*r%mod;
	}
	ans%=mod;
	do{
		out[--osz]=ans%10+'0';
	}while(ans/=10);
	write(1,out+osz,10-osz);
}


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

using namespace std;
typedef long long int lli;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef pair <lli,lli> pii;
#define all(vec) vec.begin(),vec.end()
#define ff first
#define ss second
#define inf 4e18
#define MOD 1000000007
#define pb push_back
#define for1(low,high,k) for(int i=low;i<high;i+=k)
#define for2(low,high,k) for(int j=low;j<high;j+=k)
#define rev(high,low,k) for(int i=high;i>=low;i-=k) 

int main(){
	fast;
	lli a,b,c,k,sum=0;
	cin>>a>>b>>c>>k;
	if (k<a) cout<<k<<endl;
	else{
		sum+=a;
		k-=a;
		if (k>b){
			k-=b;
			sum-=k;
		}
		cout<<sum<<endl;
	}
}

Measured memory_bytes: 3652
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
	int k,i,j,count=0;
	scanf("%d",&k);
	for(i=2;i<=k;i+=2){
		for(j=1;j<=k;j+=2){
			count++;
		}
	}
	printf("%d",count);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
const long long mod = 1e9+7;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
const int ddx[4] = {1,1,-1, -1};
const int ddy[4] = {1,-1,-1,1};
//////////////////////////////////

int main() {
    int a, b; cin >> a >> b;
    cout << max(a-2*b, 0) << endl;

    return 0;
}

// EOF


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b?gcd(b, a%b):a;}
ll lcm(ll a, ll b) { return a*b/gcd(a,b);}
ll MOD=1000000007;

int main(){
  int n,m;cin>>n>>m;
  map<int,int> ma;
  vector<string> an(n,"WA");
  int ans=0;
  int ans2=0;
  rep(i,m){
    int p;cin>>p;
    p--;
    string s;cin>>s;
    if(s=="WA"){
      ma[p]++;
    }else{
      if(an.at(p)!="AC"){
        ans+=ma[p];
        an.at(p)="AC";
        ans2++;
      }
    }
  }
  cout<<ans2<<' '<<ans<<endl;
}

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

int main(){
  int n, x, t;
  cin >> n >> x >> t;
  
  if(n%x == 0){
    cout << n/x * t << endl;
    return 0;
  }
  else{
	cout << (n/x+1) * t << endl;
    return 0;
  }
}

Measured memory_bytes: 3640
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

int main (int argc, char *argv[]) {
    string str;
    cin>>str;
    if (str.length() < 6) {
        cout<<"INVALID"<<endl;
        return 0;
    }
    bool contn = false;
    bool contb = false;
    bool conts = false;
    for (int i = 0; i < str.length(); ++i) {
        if ('0' <= str[i] && str[i] <= '9') contn = true;
        if ('A' <= str[i] && str[i] <= 'Z') contb = true;
        if ('a' <= str[i] && str[i] <= 'z') conts = true;
    }
    if (contn && contb && conts) {
        cout<<"VALID"<<endl;
    }
    else cout<<"INVALID"<<endl;
    return 0;
}


Measured memory_bytes: 3200
def mss()
  n = 1
  loop do
    a = []
    n = gets.to_i
    if n == 0
      break
    end
    a[0] = n
    for i in 1..a[0]
      a[i] = gets.to_i
    end
    b = []
    b[0] = a[1]
    for i in 1..a[0]-1
      c = [b[i-1]+a[i+1], a[i+1]]
      b[i] = c.max
    end
    s = b.max
    puts s
  end
end

mss()



Measured memory_bytes: 6940
#include <stdio.h>
/*ABC 139 B*/

int main(void)
{
  int A;
  int B;
  int plug = 0;
  int count = 1;

  scanf("%d%d", &A, &B);
  if (B == 1) {
    printf("0\n");
    return 0;
  }

  plug = B-A;
  while(plug > 0){
    plug -= (A-1);
    count++;
  }

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

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int f[10001][101][2];
char a[10001];
int main()
{
        int n,l,i,j,D,s=0;
        scanf("%s",a);
        n=strlen(a);
        f[0][0][1]=1;
        scanf("%d",&D);
        for(i=0;i<n;i++)
        {
                for(j=0;j<D;j++)
                {
                        for(l=0;l<=9;l++)
                        {
                                f[i+1][(j+l)%D][0]=(f[i][j][0]+f[i+1][(j+l)%D][0])%1000000007;
                        }
                        for(l=0;l<=a[i]-'0';l++)
                        {
                                if(l==a[i]-'0')
                                        f[i+1][(j+l)%D][1]=(f[i][j][1]+f[i+1][(j+l)%D][1])%1000000007;
                                else
                                        f[i+1][(j+l)%D][0]=(f[i][j][1]+f[i+1][(j+l)%D][0])%1000000007;
                        }
                }
        }
        printf("%d",(1000000006+f[n][0][0]+f[n][0][1])%1000000007);
        return 0;
}


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

using namespace std;

typedef double D;
typedef long long int LL;

#define st first
#define nd second
#define PLL pair <LL, LL>
#define PII pair <int, int>

const int N = 1e6 + 7;
const int M = 1007;

int n, all;
char instr[N];

int up[N];
int nxt[M];
int down[N];

int p;
int up_rv[M];
int up_val[M];

int q;
int cur[M];
vector <int> ids[M];

int get(int t){
	int ret = 0, tmp = 1;
	while(t){
		int r = t % 3;
		t /= 3;
		
		if(r)	r ^= 3;
		ret += tmp * r;
		tmp *= 3;
	}
	
	return ret;
}

void swap_all(){
	for(int i = 0; i < p; ++i)
		cur[i] = nxt[cur[i]];
	
	for(int i = 0; i < q; ++i){
		up_val[i] = nxt[up_val[i]];
		up_rv[up_val[i]] = i;
	}
}

void add(){
	for(int i = 0; i < p; ++i)
		if(cur[i] + 1 < p)
			++cur[i];
		else{
			cur[i] = 0;
			for(auto t: ids[i]){
				int me = up_val[up[t]];
				if(me + 1 < q)
					++me;
				else
					me = 0;
				up[t] = up_rv[me];
			}
		}
}

int main(){
	scanf("%d", &n);
	all = 1;
	for(int i = 1; i <= n; ++i)
		all *= 3;
	
	p = 1, q = 1;
	for(int i = 1; i <= (n + 1) / 2; ++i)
		p *= 3;
	
	for(int i = (n + 1) / 2 + 1; i <= n; ++i)
		q *= 3;

	for(int i = 0; i < p; ++i)
		nxt[i] = get(i);

	for(int i = 0; i < all; ++i){
		down[i] = i % p;
		up[i] = i / p;
		ids[down[i]].push_back(i);
	}
	
	for(int i = 0; i < p; ++i)
		cur[i] = i;
	for(int i = 0; i < q; ++i)
		up_val[i] = up_rv[i] = i;
	
	scanf("%s", instr + 1);
	int l = strlen(instr + 1);
	
	for(int v = 1; v <= l; ++v){
		if(instr[v] == 'R')
			add();
		else
			swap_all();

//		for(int i = 0; i < all; ++i)
//			printf("%d ", up_val[up[i]] * p + cur[down[i]]);
//		puts("");
	}
	
	for(int i = 0; i < all; ++i)
		printf("%d ", up_val[up[i]] * p + cur[down[i]]);
	puts("");
	return 0;
}

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

int main() {
  int n,m,sub,sub2,count = 0;
  cin >> n >> m;
  vector<int> food(m);
  for(int i = 0; i < n; i++){
    cin >> sub;
    for(int j = 0; j < sub; j++){
      cin >> sub2;
      food.at(sub2 - 1)++;
      if(food.at(sub2 - 1) == n)
        count++;
    }
  }
  cout << count << endl;
}


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

    if ((A%2 == 1) and (B%2 == 1)){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
}


Measured memory_bytes: 256
//C
//#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>


#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//Hang in there!

using namespace std;


int main() {
	int A, B;
	cin >> A >> B;
	if (B % A == 0) {
		cout << A + B << endl;
	}
	else {
		cout << B - A << endl;
	}
}
	



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

using namespace std;

#define max(a, b) a > b ? a : b;

int main() {
  int q;
  int i, j, k;
  string x, y;
  cin >> q;
  for (i = 0; i < q; i++) {
    int maxVal = 0;
    cin >> x;
    cin >> y;
    int lenx = x.size();
    int leny = y.size();
    x = ' ' + x;
    y = ' ' + y;
    int c[lenx + 1][leny + 1];
    for (j = 0; j <= lenx; ++j) {
      c[j][0] = 0;
    }
    for (j = 0; j <= leny; ++j) {
      c[0][j] = 0;
    }
    for (j = 1; j <= lenx; ++j) {
      for (k = 1; k <= leny; ++k) {
        if (x[j] == y[k]) {
          c[j][k] = c[j - 1][k - 1] + 1;
        } else {
          c[j][k] = max(c[j - 1][k], c[j][k - 1]);
        }
        maxVal = max(maxVal, c[j][k]);
      }
    }
    cout << maxVal << '\n';
  }

  return 0;
}



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

#define pb push_back

using VI = vector <int>;
using ll = long long;

const int MXT = 26;
const int MXD = 365;

int D;
int C[MXT+10], S[MXD+10][MXT+10];

VI best;
ll best_score;

void update(VI &current, ll &new_score) {
    if (best.empty() || best_score < new_score) {
        best_score = new_score;
        best = current;
    }
    return;
}

void input() {
	scanf("%d", &D);
	for (int i = 1; i <= MXT; i ++) scanf("%d", &C[i]);
	for (int i = 1; i <= D; i ++) {
		for (int j = 1; j <= MXT; j ++) scanf("%d", &S[i][j]);
	}
	return;
}
void output() {
    for (auto x : best) printf("%d\n", x);
}

namespace Greedy {
    int last[MXT+10];
    VI greedy() {
        fill_n(last, MXT+1, 0);
        ll delta[MXT + 1] = {0};
        VI greedy_ans;
        ll score = 0;
        for (int i = 1; i <= D; i ++) {
            ll sum = 0;
            for (int j = 1; j <= MXT; j ++) delta[j] += C[j];
			sum = accumulate(delta + 1, delta + MXT, 0ll);
            ll mx = -2e18;
            int ansd = -1;
            for (int j = 1; j <= MXT; j ++) {
                ll val = - sum + delta[j] + S[i][j];
				if (mx < val) mx = val, ansd = j;
            }
            score += mx;
            greedy_ans.pb(ansd);
        }
        update(greedy_ans, score);
        return greedy_ans;
    }
}

int main() {
    input();
    Greedy::greedy();
    output();
	return 0;
}


Measured memory_bytes: 3852
import java.util.*;
 
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    List<Integer> list = new ArrayList<>();
    int n = sc.nextInt();
    while(sc.hasNext()){
    	list.add(sc.nextInt());
    }
    
    int sum = 100000000;
    int challengeSum;
    for(int i = 0; i<101; i++){
     challengeSum = 0;
      for(int j=0; j<n; j++){
        challengeSum = challengeSum + (list.get(j) - i) * (list.get(j) - i);
      }
      if(sum>challengeSum){
        sum = challengeSum;
      }
    }
 
    System.out.println(sum);
  }
}

Measured memory_bytes: 23764
def main():
 from heapq import heappush, heappop
 import sys
 r=sys.stdin.readline
 def g(n,E,S,G):
  F=[1e7]*-~n;F[S],H=0,[(0,S)]
  while H:
   c,u=heappop(H)
   if u==G:return c
   for f,v in E[u]:
    t=c+f
    if t<F[v]:F[v]=t;heappush(H,(t,v))
  return-1
 def s(n,k):
  E=[[]for _ in[0]*-~n]
  for _ in[0]*k:
   f=r();p=map(int,f[2:].split())
   if'0'==f[0]:print(g(n,E,*p))
   else:c,d,e=p;E[c]+=[(e,d)];E[d]+=[(e,c)]
 for e in iter(r,'0 0\n'):s(*map(int,e.split()))
if __name__ == '__main__':
    main()


Measured memory_bytes: 6312
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var temp = Console.ReadLine().Split(' ');

            int n_even = temp.Count(ln => int.Parse(ln) % 2 == 0);
            int n_odd = n - n_even;

            int a = n_odd / 2;
            int b = n_odd % 2;

            n_odd = b;
            n_even += a;

            if (n_even > 1) { n_even = 1; }

            if ((n_odd + n_even) == 1)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }

        }
    }
}


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

int main (){
  int n;
  cin >> n;
  map<string,long long int> ans;
  for (int i=0;i<n;i++) {
    string s;
    cin >> s;
    sort(s.begin(),s.end());
    ans[s]++;
  }
  long long int sum=0;
  /*
  for(map<string,long long int>::iterator e=ans.begin();e!=ans.end();++e){
    long long int tmp = e->second*(e->second-1)/2;
    count += tmp;
  }
  */
  for(map<string,long long int>::iterator e=ans.begin();e!=ans.end();++e){
    long long int tmp = e->second*(e->second-1)/2;
    sum += tmp;
  }
  cout << sum << endl;
  return 0;
}


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

int main(){
  int n,a;
  multiset<int> s;
  cin>> n;
  for (int i=0; i<n; i++){
    cin>> a;
    s.insert(a);
    auto itr=s.lower_bound(a);
    if (itr!=begin(s)) s.erase(--itr); //値指定は一致した値全て消去する。単一要素の削除ならイテレータ指定が良い。
  }
  cout<< s.size() <<endl;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
const int INF=1e9,MOD=1e9+7;
using namespace std;
#define int long long
//template
#define N {cout<<"No"<<endl;continue;}
#define Y {cout<<"Yes"<<endl;continue;}
//main
signed main(){
  int T;cin>>T;
  std::vector<int> a(T),b(T),c(T),d(T);
  for(int i=0;i<T;i++)cin>>a[i]>>b[i]>>c[i]>>d[i];
  for(int i=0;i<T;i++){
    int A=a[i],B=b[i],C=c[i],D=d[i];
    if(A<B||D<B)N
    if(C>=B-1)Y
    int g=__gcd(B,D);
    C-=A%g;B-=A%g;
    int t=(B-1)/g;
    if(C<t*g)N
    Y
  }
}


Measured memory_bytes: 256
var
  n, digits: Integer;
  measure: String;

begin
  read(n);
  digits := n;

  digits := digits mod 10;

  if (digits = 0) or (digits = 1) or (digits = 6) or (digits = 8) then
  begin
    measure := 'pon';
  end

  else if digits = 3 then
  begin
    measure := 'bon';
  end

  else
  begin
    measure := 'hon';
  end;


  write(measure);

end.

Measured memory_bytes: 1372
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

signed main(){
    int n;
    cin >> n;
    ll sum = 0;
    ll a[n];
    REP(i,n){
        cin >> a[i];
        sum += a[i];
    }
    ll ans = LINF;
    ll now = 0;
    REP(i,n){
        now += a[i];
        ans = min(ans, abs((sum - now) - now));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
import itertools
n = int(input())
p = input().split()
q = input().split()
p = "".join(p)
q = "".join(q)
l = []
for i,x in enumerate(itertools.permutations(range(1,n+1))):
    l.append("".join(map(str,list(x))))
d = {}
l.sort()
for i,x in enumerate(l):
    d.update({x:i+1})
print(abs(d[p]-d[q]))

Measured memory_bytes: 8976
#include<bits/stdc++.h>
#define ll long long int
#define ul unsigned long long int
#define mp make_pair
#define endl "\n"
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define lb lower_bound
#define forn(i,n) for(ll i=0 ; i<n ; i++)
#define arr(a,n) for(ll i=0;i<n;i++){ cin>>a[i]; }
#define ub upper_bound
#define pb push_back
#define pi pair<int,int>
#define mod 1000000007
#define vectormax *max_element
#define vectormin *min_element
#define arraysize 1000000
#define setbit _builtin_popcountll
using namespace std;

ll ipow(ll x, ll n)
{
    ll result = 1;
    while (n) {
        if (n & 1)
            result = result * x ;
        n = n / 2;
        x = x * x;
    }
    return result;
}

int main() {
 ll a,b,c,d;
 cin>>a>>b>>c>>d;
 vector<ll>v;
 v.pb(a*c);
 v.pb(a*d);
 v.pb(b*c);
 v.pb(b*d);
sort(v.begin(),v.end(),greater<ll>());
cout<<v[0];
   return 0;
}


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

int main(){
    string S; cin >> S;
    int o0 = 0, o1 = 0, e0 = 0, e1 = 0;
    for(int i = 0; i < S.length(); i++){
        if(i % 2 == 1){
            if(S[i] == '0') o0++;
            else o1++;
        }else{
            if(S[i] == '0') e0++;
            else e1++;
        }
    }
    int ans = 0;
    ans += min(o0 + e1, o1 + e0);
    //cout << o0 << " " << o1 << " " << e0 << " " << e1 << endl;
    cout << ans << endl;
}

Measured memory_bytes: 512
N = int(input())
D = list(map(int, input().split()))

if D[0] != 0:
    print(0)
    exit()
D.sort()
d = {}
for i in range(D[-1] + 1):
    d[i] = 0

for i in D:
    d[i] += 1

if d[0] != 1:
    print(0)
    exit()

for i in range(1, D[-1] + 1):
    if d[i] == 0:
        print(0)
        exit()
ans = 1
for i in range(2, D[-1] + 1):
    ans *= (d[i-1]**d[i]) % 998244353
    ans = ans % 998244353
print(ans)


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

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

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

int main(){
	int n;
	cin>>n;
	int A[100];
	for(int i=0;i<n;i++)
		cin>>A[i];
	insertionSort(A,n);
	return 0;
}


Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
int n, m, cnt, tmp, freeDays;
int main() {
	cin >> n >> m;
	for(int i = 0; i < m; i++) {
		cin >> tmp;
		cnt += tmp;
	}
	freeDays = n - cnt;
	if(freeDays >= 0)	cout << freeDays << "\n";
	else	cout << "-1\n";
	return 0;
}

Measured memory_bytes: 3628
#include <stdio.h>

#include <new>

int main(void)
{
  int n,m;
  int i,j;
  

  scanf("%d%d",&n,&m);

  int** A = new int*[n]; //?????¨??????????????????????????????
  for(i=0; i<n; i++){
    A[i] = new int[m];
  }

  int* b = new int[m];
  int* c = new int[n];

  for(i=0; i<n; i++) //c??????????????¨??¨0???
    c[i] = 0;

  for(i=0; i<n; i++){
    for(j=0; j<m; j++)
      scanf("%d",&A[i][j]);
  }

  for(j=0; j<m; j++)
    scanf("%d",&b[j]);

  for(i=0; i<n; i++){
    for(j=0; j<m; j++)
      c[i] = c[i] + (A[i][j] * b[j]); //c????¨???????????????¶?????????
  }

  for(i=0; i<n; i++) //c??????????????¨???
    printf("%d\n",c[i]);
  
  for(i=0; i<n; i++){ //?¢?????????????????????¢??????????????????
    delete[] A[i];
  }
  delete[] A;
  
  delete[] b;
  delete[] c;

  return(0);
}

Measured memory_bytes: 1072
(let* ((n (read))
       (m (loop :repeat n :collect (read-line))))
  (princ (reduce (lambda (x y)
                   (concatenate 'string x y))
                 (loop :for k :from 97 :upto 122
                       :collect
                       (loop :repeat (reduce #'min (mapcar (lambda (x) (count (code-char k) x :test #'char=)) m))
                             :collect (code-char k))))))

Measured memory_bytes: 15972