akhauriyash/Code-Regression huggingface dataset:
/*input
3 4 10 40
*/

#include <bits/stdc++.h>
using namespace std;
 
 
 
#define int long long int
#define rep(i,n) \
    for(int i = 0; i < n; i++)
#define rep2(i, a, b) \
    for(int i = a; i < b; i++)
#define all(c) \
    c.begin(), c.end()
#define init(arr, num) \
    memset(arr, num, sizeof(arr))
#define fast\
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define inputFile \
    freopen("input.txt", "r", stdin); 
#define outputFile \
    freopen("output.txt", "w", stdout);
#define modM 1000000007
#define PI 3.1415926535897932
 
#ifdef Voneone
#define TRACE
#endif
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cout << name << " : " << arg1 << std::endl;
 
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ','); 
    cout.write(names, comma - names) << " : " << arg1 << " | "; 
    __f(comma + 1, args...);
}
#else
#define trace(...)
#endif
 
 
typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef pair< int, int > ii;
typedef unordered_set<int> usi;
 

 


 
void solve() 
{ 

int n, m;
cin>>n>>m;
vector <int> v[n+1];
int par[n+1];
init(par,0);
for(int i=0;i<m;i++)
{   
    int j, k;
    cin>>j>>k;
    v[j].push_back(k);
    v[k].push_back(j);

}  

queue<int> q;
int vis[n+1];
init(vis,0);
q.push(1);
vis[1]=1;
par[1]=1;

while(!q.empty())
{
    int k=q.front();
    q.pop();
    for(int i=0;i<v[k].size();i++)
    {
        if(vis[v[k][i]]==0)
        {vis[v[k][i]]=1;
            par[v[k][i]]=k;


            q.push(v[k][i]);


        }
    }
}
for(int i=2;i<=n;i++)
{if(par[i]==0)
    {
        cout<<"No";
        return;
   // cout<<par[i]<<" ";
    }
}
cout<<"Yes\n";
for(int i=2;i<=n;i++)
{
    cout<<par[i]<<"\n";
}



 
} 
 
 
 
 
signed main()
{
 
    
    #ifdef _DEBUG
    inputFile;
    #endif
    #ifndef __CINP
    fast;
    #endif
 
 
    int T = 1;
    // cin >> T;
    while(T--){
        solve();
        cout << endl;
        
        
 
    }
    
    
    return 0;
 
}
 



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

int main()
{
	int a, b, c,n=0;
	cin >> a >> b >> c;
	for (int i = 0; i < 10000; i++)
	{
		if ((b*i+c) % a == 0)
		{
			cout<<"YES";
			return 0;
		}
	}
	cout << "NO";
	return 0;
}

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

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

    if (N % 500 <= A)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
    return 0;
}

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

int main()
{
    char c;
    cin >> c;
    if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o')
    {
        cout << "vowel" << endl;
    }
    else
    {
        cout << "consonant" << endl;
    }
}

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

int main(){
  int N,M;
  cin >> N >> M;
  int mm=1;
  for(int i=0;i<M;i++)
    mm*=2;
  //期待値mmで合ってるかな？
  //int c = (1900*M+100*(N-M))*mm;
  int c = (1800*M+100*N)*mm;
  cout << c;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int n,l,m,sum=0;
  scanf("%d%d",&n,&l);
  m=l;
  for(int i=1;i<=n;i++){
  sum+=m;
  m++;
  }
  for(int i=1;i<=n;i++){
    if(l>=0){
    	printf("%d",sum-l);
      	return 0;
    }
  l++;
  }
  printf("%d",sum-l+1);
  return 0;
}


Measured memory_bytes: 128
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rrep(i,n) for(ll i##_len=(n) ,i=i##_len-1;i>=0;--i)
#define repi(i,a,b) for(ll i=ll(a);i<=ll(b);++i)
#define ALL(f,x,...) ([&](decltype((x)) xxxx) { return (f)(begin(xxxx), end(xxxx), ## __VA_ARGS__); })(x)
#define lim 1000000007ll
#define Yes(flag) cout<<((flag)? "Yes":"No");
#define YES(flag) cout<<((flag)? "YES":"NO");
#define MSG(msg1,msg2,flag) cout<<((flag)? msg1:msg2);

#include<bits/stdc++.h>
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = std::pair<ll,ll>;
using namespace std;
template<class T>T 
chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T>T 
chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template <class T> T 
gcd(T a, T b){if (a < b) {a ^= b;b ^= a;a ^= b;} return b ? gcd(b, a % b) : a;}
template <class T> T 
lcm(T a, T b){return a * b / gcd(a, b);}
vector<char> 
string_to_vector_char(const string& input){vector<char> out(input.length());rep(i,input.length()){out[i]=input[i];}return out;}
template <class T> map<T,int> 
count_same_elements(const vector<T>& v){map<T,int>cmap; for_each(v.begin(),v.end(),[&cmap](auto x){cmap[x]++;}); return cmap; }
template<class A,class B> vector<B> 
mapf(const vector<A>& v,const function<B(A)>& func){vector<B> v_(v.size());rep(i,v.size()){ v_[i]=func(v[i]); }return v_;}
template<class A,class B> vector<B> 
adjacent_map(const vector<A>& v,const function<B(A,A)>& func){vector<B> v_(v.size()-1);rep(i,v.size()-1){ v_[i]=func(v[i+1],v[i]); }return v_;}
template<class A> bool
all_of(const vector<A>& v){bool flag=true;rep(i,v.size()){ if(v[i]<1){flag=false;}; }return flag;}
template<class A> bool
any_of(const vector<A>& v){bool flag=false;rep(i,v.size()){ if(v[i]>0){flag=true; break;}; }return flag;}
template<class A> bool
none_of(const vector<A>& v){bool flag=true;rep(i,v.size()){ if(v[i]>0){flag=false;}; }return flag;}
template<class T>
void scan_vector(long long size,vector<T>& vector){
    vector.resize(size);
    for(long long i=0;i<size;++i){
        cin>>vector[i];
    }
}
int n;
vector<int> c,v;
void input(){
    cin>>n;
    scan_vector(n,v);
    scan_vector(n,c);
}
void src(){
    int ans=0;
    rep(i,n){
        if(v[i]-c[i]>0) ans+=v[i]-c[i];
    }
    cout<<ans;
}   

int main(int argc,char* argv[]){
    ios::sync_with_stdio(false);
 //   ifstream in( argv[1] ); cin.rdbuf(in.rdbuf());
    input();
    src();    
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define INF 99999999
using namespace std;

typedef int Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;

Weight visit(const Graph &g, Graph& T, int i, int j) {
  if (T[i][j].weight >= 0) return T[i][j].weight;
  T[i][j].weight = g[i][j].weight;
  int u = T[i][j].dst;
  REP(k, T[u].size()) {
    if (T[u][k].dst == i) continue;
    T[i][j].weight = max(T[i][j].weight, visit(g,T,u,k)+g[i][j].weight);
  }
  return T[i][j].weight;
}
Array height(const Graph& g) {
  const int n = g.size();
  Graph T(g); // memoise on tree
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < T[i].size(); ++j)
      T[i][j].weight = -1;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < T[i].size(); ++j)
      if (T[i][j].weight < 0)
        T[i][j].weight = visit(g, T, i, j);

  Array ht(n); // gather results
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < T[i].size(); ++j)
      ht[i] = max(ht[i], T[i][j].weight);
  return ht;
}

int main(){
	int i,V,E,s,t,e;
	//for(scanf("%d",&T);T;putchar(--T?' ':'\n')){
		scanf("%d",&V);
		Graph g(V);
		for(i=0;i<V-1;i++)scanf("%d%d%d",&s,&t,&e),g[s].push_back(Edge(s,t,e)),g[t].push_back(Edge(t,s,e));
		Array r=height(g);
		for(i=0;i<V;i++)printf("%d\n",r[i]);
	//}
}

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

int main() {
  int N, S, sum = 0, A = 100000000;
  cin >> N;
  int L = N;
  for (int i = 0; i < 9; i++) {
  S = L / A;
  sum += S;
  L = L % A;
  A /= 10;
  }
   
  if ((N % sum) == 0)
  cout << "Yes";
  else
  cout << "No";
}


Measured memory_bytes: 384
'use strict'

function main(input) {

    input = input.split(/\n/)
    const n = ~~input[0]
    const cards = input[1].split(/\s/).map(v => ~~v).sort((a, b) => b - a)

    let a = 0
    let b = 0
    for (let i = 0; i < n; i++) {

        if (i % 2 === 0) a += cards[i]
        else b += cards[i]
    }

    console.log(a - b)
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main(void)
{
    ll x, y,a,b,c;
    cin >> x >> y >> a >> b >> c;

    vector<ll> p(a), q(b), r(c),l;

    rep(i, a){
        cin >> p.at(i);
    }
    rep(i, b)
    {
        cin >> q.at(i);
    }
    rep(i, c)
    {
        cin >> r.at(i);
    }

    sort(p.begin(), p.end(), greater<ll>());
    sort(q.begin(), q.end(), greater<ll>());

    copy(p.begin(), p.begin() + x, back_inserter(l));
    copy(q.begin(), q.begin() + y, back_inserter(l));
    copy(r.begin(), r.end(), back_inserter(l));
    sort(l.begin(), l.end(), greater<ll>());

    ll ans=0;
    
    rep(i,x+y){
        ans+=l.at(i);
    }

    cout << ans << endl;

    return 0;
}


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

typedef int_fast32_t int32;
typedef int_fast64_t int64;

const int32 inf = 1e9+7;
const int32 MOD = 1000000007;
const int64 llinf = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define all(obj) (obj).begin(),(obj).end()
#define rall(obj) (obj).rbegin(),(obj).rend()
#define fi first
#define se second
#define pb(a) push_back(a)
typedef pair<int32,int32> pii;
typedef pair<int64,int64> pll;

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  REP(i,4){
    cout << s[i];
  }
  cout << " ";
  FOR(i,4,12)cout << s[i];
  cout << endl;
  return 0;
}

Measured memory_bytes: 3592
// Trick or Treat

func main() {
    let nk = readLine()!.split(separator: " ").map{Int($0)!}
    let n = nk[0]
    let k = nk[1]

    var counts = Array(repeating: 0, count: n + 1)
    for _ in 1...k {
        readLine()!
        readLine()!.split(separator: " ").forEach { s in
            let i = Int(s)!
            counts[i] += 1
        }
    }
    let result = (1...n).filter{counts[$0] == 0}.count
    print(result)
}

main()

Measured memory_bytes: 8304
from collections import defaultdict
factors = defaultdict(int)
N = int(input())
for i in range(2,N+1):
    target = i
    d = 2
    while d**2 <=target:
        if target % d == 0:
            factors[d] += 1
            target //= d
        else:
            d += 1

    if target != 1:
        factors[target] += 1
ans = 1
for v in factors.values():
    ans *= (v+1)
mod = 10**9 +7
print(ans%mod)


Measured memory_bytes: 39152
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_s(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;

int main() {
  int a, b;
  string s, t, u;
  cin >> s >> t >> a >> b >> u;
  a -= (s == u ? 1 : 0);
  b -= (t == u ? 1 : 0);

  cout << a << " " << b << endl;
}


Measured memory_bytes: 256
n,m = map(int,input().split())
A = list(map(int,input().split()))
A.sort(reverse=True)
sortedA = list()
sum_of_votes = 0
for i in A : 
    sum_of_votes += i
for i in range(m) : #人気商品候補のsortedAリスト
    sortedA.append(A[i])
isOK = True
for i in sortedA: #人気商品候補のうち選べないものはないか？
    if i < sum_of_votes * (1/(4*m)) :
        isOK = False
if isOK == True :
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<math.h>
#include<complex>
#include<queue>

using namespace std;
#define rep(i,n) for(int i = 0 ; i < n ; ++i)
using ll = long long;
const ll inf = 1ll<<32;

int n,m;
vector<ll> a,b;

vector<ll> solve(int k, int l, int r){
    int nxt = *upper_bound(a.begin(),a.end(),l);
    vector<ll> ret(n+1,inf);
    if(nxt<r){
        auto vl = solve(k+1,l,(l+r)/2);
        auto vr = solve(k+1,(l+r)/2,r);
        rep(i,n+1){
            ret[i]=min(ret[i],vl[i]+vr[k]);
            ret[i]=min(ret[i],vl[k]+vr[i]);
        }
    }
    else {
        int idx = upper_bound(a.begin(),a.end(),l) - a.begin();
        --idx;
        int cur = b[idx];
        ll res = 0;
        int sz = 0;
        while((1ll<<sz)<r-l){
            if(k+sz!=cur)res += 1ll<<sz;
            ++sz;
        }
        rep(i,n+1){
            ret[i]=res;
            if(cur!=i)++ret[i];
        }
    }
    return ret;
}
 
int main(){
    cin>>n>>m;
    a.resize(m+1);
    b.resize(m);
    rep(i,m+1){
        cin>>a[i];
    }
    rep(i,m)cin>>b[i];
    auto ans = solve(1,0,1<<n);
    cout<<ans[0]<<endl;
}


Measured memory_bytes: 3228
#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
//    freopen("f.in","r",stdin);
//    freopen("f.out","w",stdout);
    long long x,n;
    scanf("%I64d",&x);
    n=(sqrt((8*x+1))-1)/2;
    if((2*n+1)*(2*n+1)<(8*x+1))
        n++;
    printf("%I64d\n",n);
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main()
{
int n,s,R;
while(cin>>n>>s&&n!=0||s!=0)
{
	R=0;
	if(s<=45)
	{
		for(int j=0;j<10;j++)
		{	
			if(n>=2)
			{
				for(int k=j+1;k<10;k++)
				{		
					if(n>=3)
					{
						for(int l=k+1;l<10;l++)
						{
							if(n>=4)
							{
								for(int m=l+1;m<10;m++)
								{	
									if(n>=5)
									{
										for(int o=m+1;o<10;o++)
										{
											if(n>=6)
											{
												for(int p=o+1;p<10;p++)
												{
													if(n>=7)
													{
														for(int q=p+1;q<10;q++)
														{
															if(n>=8)
															{
																for(int r=q+1;r<10;r++)
																{
																	if(n>=9)
																	{
																		for(int t=r+1;t<10;t++)
																		{
																		if(j+k+l+m+o+p+q+r+t==s)
																		{
																		R++;	
																		}	
																		}
																	}
																	else if(j+k+l+m+o+p+q+r==s)
																	{
																	R++;	
																	}
																}
															}
															else if(j+k+l+m+o+p+q==s)
															{
															R++;	
															}
														}
													}
													else if(j+k+l+m+o+p==s)
													{
													R++;	
													}
												}	
											}
											else if(j+k+l+m+o==s)
											{
											R++;	
											}
										}
									}
									else if(j+k+l+m==s)
									{
									R++;	
									}
								}
							}
							else if(j+k+l==s)
							{
							R++;	
							}
						}				
					}
					else if(j+k==s)
					{
					R++;	
					}	
				}	
			}
			else if(j==s)
			{
			R++;	
			}	
		}
	}		
	cout<<R<<endl;
}
return 0;
}

Measured memory_bytes: 3096
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#define REP(i, N) for(int i = 0; i < N; ++i)
#define REEP(i, N) for(int i = N - 1; i >= 0; --i)
using namespace std;

int main(){
    int M, N;
    bool g = false;
    cin >> N >> M;
    vector<string> A(N);
    vector<string> B(M);
    REP(i, N) {
        cin >> A[i];
    }
    REP(i, M) {
        cin >> B[i];
    }
    REP(i, N - M + 1) {
        REP(j, N - M + 1) {
            if(A[i][j] == B[0][0]) {
                bool f = true;
                for(int k = i; k < i + M; ++k) {
                    for(int l = j; l < j + M; ++ l) {
                        if(A[k][l] != B[k - i][l - j]) {
                            f = false;
                            break;
                        }
                    }
                    if(!f) break;
                }
                if(f) {
                    g = true;
                    break;
                }
            }
        }
        if(g) break;
    }
    if(g) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>
#include <stack>
#include <bitset>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

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

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

  int n,d;
  string s;

  cin >> n >> d;

  cout << ceil((double)n/(1+2*d)) << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <queue>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;
#define PB push_back
const int N=1e2+10;
int p[N];
int find(int n){return p[n]==n?n:p[n]=find(p[n]);}
struct point{
    int x;
    int y;
    int num;
    void in(){
        scanf("%d%d",&x,&y);
        return ;
    }
    point operator -(point a){
        return {x-a.x,y-a.y};
    }
    double dis(){
        return sqrt(x*x+y*y);
    }
    
};
struct side{
    int from;
    int to;
    double len;
    void pull(){
        from=find(from);
        to=find(to);
    }
};
struct cmp{
    bool operator()(const side& a,const side& b){
        return a.len>b.len;
    }
};
vector<int> graph[N];
double dis(point a,point b){
    return (a-b).dis();
}
bool ccmp(point a,point b){
    return a.x<b.x;
}
int cross(point a,point b){
    return a.x*b.y-a.y*b.x;
}
bool cross(point a,point b,point c){
    return cross(b-a,c-b)<0;
}
int main(){
    point a[N],b[N];
    vector<int> v;
    int n,m,l,r,last;
    double ans=0;
    side nxt;
    priority_queue<side,vector<side>,cmp>pq;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++){
        p[i]=i;
        a[i].in();
        b[i]=a[i];
        b[i].num=i;
    }
    while(m--){
        scanf("%d%d",&l,&r);
        graph[l].PB(r);
        graph[r].PB(l);
        pq.push({l,r,(a[l]-a[r]).dis()});
    }
    sort(b+1,b+n+1,ccmp);
    v.PB(b[1].num);
    for(int i=2;i<=n;i++){
        while(v.size()>1){
            if(cross(a[v[v.size()-2]],a[v[v.size()-1]],b[i]))v.pop_back();
            else break;
        }
        v.PB(b[i].num);
    }
    for(int i=n-1;i>=1;i--){
        while(v.size()>1){
            if(cross(a[v[v.size()-2]],a[v[v.size()-1]],b[i]))v.pop_back();
            else break;
        }
        v.PB(b[i].num);
    }
    l=v[0];
    last=l;
    for(int i:v){
        ans+=dis(a[last],a[i]);
        last=i;
        r=find(i);
        if(r!=l)p[r]=l;
    }
    while(!pq.empty()){
        nxt=pq.top();
        pq.pop();
        nxt.pull();
        if(nxt.from!=nxt.to){
            p[nxt.to]=nxt.from;
            ans+=nxt.len;
        }
    }
    printf("%lf\n",ans);
}



Measured memory_bytes: 2760
def is_prime(n):
    if n < 2:
        return False
    elif n == 2:
        return True
    if n % 2 == 0:
        return False

    for i in range(3, int(n ** 0.5) + 1):
        if n % i == 0:
            return False

    return True

def solve():
    N = int(input())
    ans = 0
    for i in range(10**3):
        if is_prime(N+i):
            ans = N+i
            break
    return ans

print(solve())

Measured memory_bytes: 3064
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt
from copy import deepcopy


def main():
    n = input()
    ans = 0
    for i in n:
        ans += int(i)
    if ans%9 == 0:
        print("Yes")
    else:
        print("No")
    
if __name__ == '__main__':
	main()


Measured memory_bytes: 9792
# -*- coding: utf-8 -*-
import bisect

n = int(input())
a = [0 for _ in range(n)]
for i in range(n):
    a[i] = -int(input())


LIS = list()
for i in a:
    j = bisect.bisect_right(LIS, i)
    if len(LIS) == j:
        LIS.append(i)
    else:
        LIS[j] = i

print(len(LIS))

Measured memory_bytes: 49440
#include <iostream>
#include <iterator>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
  int64_t N;
  cin >> N;
  vector<int64_t> A(N);
  copy_n(istream_iterator<int64_t>(cin), N, A.begin());
  int64_t result = 1;
  for (auto a : A) {
    if (a == 0) {
      result = 0;
    } else if (result == -1) {
      continue;
    } else if ((double)1000000000000000000LL < (double)result * (double)a) {
      result = -1;
    } else if (1000000000000000000LL < result * a) {
      result = -1;
    } else {
      result *= a;
    }
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 4000
#include<bits/stdc++.h>
        using namespace std;
        #include <ext/pb_ds/assoc_container.hpp>
        #include <ext/pb_ds/tree_policy.hpp>
        using namespace __gnu_pbds;
        #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
        #define ll long long
        #define int long long
        #define lb long double
        #define f(i,a,b) for(int i=(a);i<=(b);i++)
        #define fd(i,a,b) for(int i=a;i>=b;i--)
        #define vi vector<int>
        #define mii map<int,int>
        #define pii pair<int,int>
        #define si set<int>
        #define pb push_back
        #define mk make_pair
        #define fi first
        #define se second
        #define fv(i,v) for(auto i=v.begin();i!=v.end();++i)
        #define fdv(i,v) for(auto i=v.rbegin();i!=v.rend();++i)
        #define print(a,n) f(i,1,n) cout<<a[i]<<" "; cout<<endl;
        #define printv(v) for(auto iv: v) cout<<iv<<" "; cout<<endl;
        #define all(v) v.begin(),v.end()
        #define r(a,n) ll a[n+1]; f(i,1,n) cin>>a[i];
        #define pi 3.141592653589793238
        const int mod=1e9+7;
        const int inf=1e18;
        int parent[26];
        int size[26];
        const int A=26;
        //bool vis[1000+1]={};
        const int MAXN=2*1e6+1;
        int spf[MAXN];
        ll power(ll x, unsigned ll y)
        {
            ll res = 1;
            while (y > 0)
            {
                if (y & 1)
                    res = res*x;
                y = y>>1;
                x = x*x;
            }
            return res;
        }

        bool isPrime(int n)
        {
            if (n <= 1)
                return false;
            if (n <= 3)
                return true;

            if (n % 2 == 0 || n % 3 == 0)
                return false;

            for (int i = 5; i * i <= n; i = i + 6)
                if (n % i == 0 || n % (i + 2) == 0)
                    return false;

            return true;
        }
        void sieve()
        {
            spf[1] = 1;
            for (int i=2; i<MAXN; i++)
                spf[i] = i;
            for (int i=4; i<MAXN; i+=2)
                spf[i] = 2;
            for (int i=3; i*i<MAXN; i++)
            {
                if (spf[i] == i)
                {
                    for (int j=i*i; j<MAXN; j+=i)
                        if (spf[j]==j)
                            spf[j] = i;
                }
            }
        }

        int lcm(int a, int b)
        {
            return (a*b)/__gcd(a,b);
        }

        signed main()
        {
            ios_base::sync_with_stdio(false);
            cin.tie(0);
            int t=1;
            //cin>>t;
            while(t--)
            {
                int a;
                cin>>a;
                cout<<a+a*a+a*a*a<<endl;
            }
        }


Measured memory_bytes: 3632
#include <stdio.h>

int main(){
  int i,n,k,a[200005],m=0,c=0;
  double mm;
  scanf("%d",&n);
  scanf("%d",&k);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
    c+=a[i];
    if(i>=k) c-=a[i-k];
    if(c>m){
      m=c;
    }
  }
  mm=m+k;
  printf("%f",mm/2);
  return 0;
}

Measured memory_bytes: 896
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#include <functional>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<ll, ll, ll, ll> tlglglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
typedef unsigned int uint;
typedef unsigned long long ull;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
template <class T> using VVV = V<VV<T>>;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;
void yesno(bool ok, string yes = "Yes", string no = "No") {
    if (ok) {
        cout << yes << endl;
    } else {
        cout << no << endl;
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, K;
    cin >> N >> K;
    ll A[N];
    REP(i, 0, N) {
        cin >> A[i];
    }
    REP(i, K, N) {
        yesno(A[i] > A[i - K]);
    }
}


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

const int c = 100000;

int main(){
    
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int x,y;
    cin >> x >> y;
    
    int ans = 0;
    if(x == 1) ans += 3 * c;
    if(x == 2) ans += 2 * c;
    if(x == 3) ans += 1 * c;
    if(y == 1) ans += 3 * c;
    if(y == 2) ans += 2 * c;
    if(y == 3) ans += 1 * c;
    if(x == 1 and y == 1) ans += 4 * c;
    
    cout << ans << endl;
    
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repl(i, a, n) for(int i = ((int) a); i < ((int) n); i++)
#define rep(i,n) repl(i,0,n)
#define INF INT_MAX/3
#define fi first
#define se second
typedef pair<int,int> P;
typedef pair<P,int> PPI;

struct state {
  int i,j,dist,cost;
};
bool operator<(const state& a,const state& b){
  return a.cost>b.cost;
}

int h,w;
bool wall[33][33][33][33];
int dd[]={-1,0,1,0,-1};

int fail[33][33][5];
int dp[33][33][2000];

int bfs(int y,int x){
  int dist[33][33];
  rep(i,33)rep(j,33)dist[i][j]=INF;

  queue<PPI> que;
  que.push(PPI(P(h-1,w-1),0));
  while(que.size()){
    PPI p=que.front(); que.pop();
    int i=p.fi.fi,j=p.fi.se; int nd=p.se;
    if(dist[i][j]!=INF)continue;
    dist[i][j]=nd;
    rep(dir,4){
      int ni=i+dd[dir],nj=j+dd[dir+1];
      if(ni>=0&&ni<h&&nj>=0&&nj<w&&!wall[i][j][ni][nj]){
        que.push(PPI(P(ni,nj),nd+1));
      }
    }
  }
  return dist[y][x];
}

int main(void) {
  while(1) {
    cin>>h>>w;
    if(h==0)break;
    memset(wall,0,sizeof(wall));
    rep(i,2*h-1){
      int ii=i/2;
      if(i%2==0){
        rep(j,w-1){
          cin>>wall[ii][j][ii][j+1];
          wall[ii][j+1][ii][j]=wall[ii][j][ii][j+1];
        }
      }else{
        rep(j,w){
          cin>>wall[ii][j][ii+1][j];
          wall[ii+1][j][ii][j]=wall[ii][j][ii+1][j];
        }
      }
    }

    rep(i,33)rep(j,33)rep(dir,4)fail[i][j][dir]=INF;
    rep(i,h)rep(j,w){
      rep(dir,4){
        int ni=i+dd[dir],nj=j+dd[dir+1];
        if(ni>=0&&ni<h&&nj>=0&&nj<w&&!wall[i][j][ni][nj]){
          wall[i][j][ni][nj]=wall[ni][nj][i][j]=true;
          fail[i][j][dir]=bfs(i,j);
          wall[i][j][ni][nj]=wall[ni][nj][i][j]=false;
        }
      }
    }

    int ans=-1;
    priority_queue<state> que;
    que.push((state){0,0,0,0});
    rep(i,33)rep(j,33)rep(k,2000)dp[i][j][k]=INF;
    while(que.size()) {
      state s=que.top(); que.pop();
      int i=s.i,j=s.j,dist=s.dist,cost=s.cost;
      if(i==h-1&&j==w-1){
        ans=cost;
        break;
      }
      if(dp[i][j][dist]!=INF)continue;
      dp[i][j][dist]=cost;
      rep(dir,4) {
        int ni=i+dd[dir],nj=j+dd[dir+1];
        if(ni>=0&&ni<h&&nj>=0&&nj<w&&!wall[i][j][ni][nj]&&dist+1<2*h*w&&fail[i][j][dir]!=INF) {
          que.push((state){ni,nj,dist+1,max(dist+fail[i][j][dir],cost)});
        }
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 12992
#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define dec(i, n)  decID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define FR front()
#define BA back()
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)
#define IN(T, ...) T __VA_ARGS__; IN_(__VA_ARGS__);
void IN_() { };
template<typename T, typename ... U> void IN_(T & a, U & ... b) { cin >> a; IN_(b ...); };
template<typename T> void OUT(T && a) { cout << a << endl; }
template<typename T, typename ... U> void OUT(T && a, U && ... b) { cout << a << " "; OUT(b ...); }

// ---- ----

template<typename T> T MV(T v) { return v; }
template<typename T, typename ... U> auto MV(T v, int a, U ... b) { return vector<decltype(MV(v, b ...))>(a, MV(v, b ...)); }

int main() {
	IN(int, n);
	vector<pair<LL, LL>> v;
	inc(i, n) {
		IN(LL, a);
		v.EB(a, i);
	}
	sort(RALL(v));
	
	auto dp = MV<LL>(0, n + 1, n + 1);
	inc(k, n) {
		incII(i, 0, k) {
			int j = k - i;
			setmax(dp[i + 1][j], dp[i][j] + v[k].FI * abs(v[k].SE - i));
			setmax(dp[i][j + 1], dp[i][j] + v[k].FI * abs(v[k].SE - (n - 1 - j)));
		}
	}
	LL ans = 0;
	incII(i, 0, n) { setmax(ans, dp[i][n - i]); }
	OUT(ans);
}


Measured memory_bytes: 34680
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
 
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}
 
long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
//using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

int main(){
  using namespace std;
  int n;
  cin>>n;
  string s;
  cin>>s;
  typedef pair<string, string> P;
  map<P, long long> mp;
  REP(k, 1<<n){
    string s1 = "", s2 = "";
    REP(i, n){
      if(k>>i&1){
        s1 += s[i];
      }else{
        s2 = s[i] + s2;
      }
    }
    mp[P(s1, s2)]++;
  }
  long long ans = 0;
  REP(k, 1<<n){
    string s1 = "", s2 = "";
    REP(i, n){
      if(k>>i&1){
        s1 = s[i + n] + s1;
      }else{
        s2 += s[i + n];
      }
    }
    ans += mp[P(s1, s2)];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 87040
#shoping street
n=int(input())
lists=[]
shoplist=[]
for i in range(n):
    lists.append(list(map(int,input().split())))
for j in range(n):
    shoplist.append(list(map(int,input().split())))
maxi=-10**10
for _ in range(1,2**10):
    string=format(_,"0%ib"%10)
    empty=[0 for i in range(n)]
    for i in range(n):
        some=lists[i]
        counter=0
        for k in range(10):
            if some[k]==1 and int(string[k])==1:
                counter+=1
        empty[i]=counter
    how=0
    for i in range(n):
        how+=shoplist[i][empty[i]]
    maxi=max(maxi,how)
print(maxi)

Measured memory_bytes: 3192
#include <algorithm>
#include <cstring>
#include <iostream>
#include <limits.h>
#include <map>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
const int inf = 1 << 30;
const int INF = INT_MAX;

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, l[100], m = 0, sum = 0;
  cin >> n;
  for(int i = 0; i < n; ++i) {
    cin >> l[i];
    m = max(m, l[i]);
    sum += l[i];
  }
  sum -= m;
  cout << (m < sum ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<stack>
#include<queue>
#include<algorithm>

using namespace std;

class P{
    public:
    int cnt;
    int bef;
    stack< int > S[3];
};

int main(){
    int n,m;
    while(scanf("%d%d",&n,&m),(n|m)){
        P f;
        for(int i = 0;i < 3; i++){
            int x;
            scanf("%d",&x);
            for(int j = 0; j < x; j++){
                int tmp;
                scanf("%d",&tmp);
                f.S[i].push(tmp);
            }
        }
        f.cnt = 0;
        f.bef = -1;
        queue< P > Q;
        Q.push(f);
        bool flg = true;
        while( !Q.empty()){
            P p = Q.front();Q.pop();
            if(p.cnt > m){
                flg = false;
                break;
            }
            bool h = false;
            for(int i = 0; i < 3; i++){
                if(i == 1)continue;
                if(p.S[i].size() == n){
                    printf("%d\n",p.cnt);
                    h = true;
                }
            }
            if( h ){
                break;
            }
            int top0 = (p.S[0].size()>0)?p.S[0].top() : 0;
            int top1 = (p.S[1].size()>0)?p.S[1].top() : 0;
            int top2 = (p.S[2].size()>0)?p.S[2].top() : 0;
            int copy0 = top0 , copy1 = top1 , copy2 = top2;
            P sub;
            sub.cnt = p.cnt+1;
            if(top0 < top1 && p.bef != 0){
                p.S[1].pop();
                p.S[0].push(top1);
                for(int i = 0; i < 3; i++)sub.S[i] = p.S[i];
                sub.bef = 1;
                Q.push(sub);
                p.S[0].pop();
                p.S[1].push(copy1);
            }
            if(top0 > top1 && p.bef != 1) {
                p.S[0].pop();
                p.S[1].push(top0);
                for(int i = 0; i < 3; i++)sub.S[i] = p.S[i];
                sub.bef = 0;
                Q.push(sub);
                p.S[1].pop();
                p.S[0].push(copy0);
            }
            if(top1 < top2 && p.bef != 2){
                p.S[2].pop();
                p.S[1].push(top2);
                for(int i = 0;i < 3; i++)sub.S[i] = p.S[i];
                sub.bef = 3;
                Q.push(sub);
                p.S[1].pop();
                p.S[2].push(copy2);
            }
            if(top1 > top2 && p.bef != 3){
                p.S[1].pop();
                p.S[2].push(top1);
                for(int i = 0; i < 3; i++)sub.S[i] = p.S[i];
                sub.bef = 2;
                Q.push(sub);
                p.S[2].pop();
                p.S[1].push(copy1);
            }
        }
        if( !flg )puts("-1");
    }
    return 0;
}

Measured memory_bytes: 1084
#include<stdio.h>

int main(){
  int N,surface,max,i;
  scanf("%d",&N);

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

  surface=0;
  max=1;
  for(i=0; i<N; i++){
    if(A[i]==1)
      surface++;
    else if(A[i]==0){
      if(max<surface+1)
	max=surface+1;
      surface=0;
    }
    if(max<surface+1)
      max=surface+1;
  }
  printf("%d\n",max);
  return 0;
}



Measured memory_bytes: 2760
#include <iostream>
#include <algorithm>
using namespace std;
int a[101];
int main()
{
  int n,alice=0,bob=0;
  cin >> n;
  for(int i=0;i<=n;i++)
    cin >> a[i];
  sort(a,a+n, greater<int>());
  for(int i=0;i<n;i++)
  {
    alice+=a[2*i];
    bob+=a[2*i+1];
  }
  int s=alice-bob;
  cout << s;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int N;
    while(cin >> N){
        long long res = 0;
        int prev = 0;
        for(int i=0;i<N;i++){
            int A; cin >> A;
            res += (A+prev)/2;
            prev = (A > 0 ? (A+prev)%2 : 0);
        }
        cout << res << endl;
    }
}

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

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

	public Main() {
		FastScanner fs = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		System.err.println("");

		int h1 = fs.nextInt(), s1 = fs.nextInt();
		int h2 = fs.nextInt(), s2 = fs.nextInt();
		
		boolean wins = false;
		while(h1 > 0 && h2 > 0) {
			h2 -= s1;
			if(h2 <= 0) {
				wins = true;
				break;
			}
			h1 -= s2;
		}
		
		if(wins) out.println("Yes");
		else out.println("No");
		
		out.close();
	}

	class FastScanner {
		public int BS = 1<<16;
		public char NC = (char)0;
		byte[] buf = new byte[BS];
		int bId = 0, size = 0;
		char c = NC;
		double num = 1;
		BufferedInputStream in;

		public FastScanner() {
			in = new BufferedInputStream(System.in, BS);
		}

		public FastScanner(String s) {
			try {
				in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
			}
			catch (Exception e) {
				in = new BufferedInputStream(System.in, BS);
			}
		}

		public char nextChar(){
			while(bId==size) {
				try {
					size = in.read(buf);
				}catch(Exception e) {
					return NC;
				}                
				if(size==-1)return NC;
				bId=0;
			}
			return (char)buf[bId++];
		}

		public int nextInt() {
			return (int)nextLong();
		}

		public long nextLong() {
			num=1;
			boolean neg = false;
			if(c==NC)c=nextChar();
			for(;(c<'0' || c>'9'); c = nextChar()) {
				if(c=='-')neg=true;
			}
			long res = 0;
			for(; c>='0' && c <='9'; c=nextChar()) {
				res = (res<<3)+(res<<1)+c-'0';
				num*=10;
			}
			return neg?-res:res;
		}

		public double nextDouble() {
			double cur = nextLong();
			return c!='.' ? cur:cur+nextLong()/num;
		}

		public String next() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c>32) {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public String nextLine() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c!='\n') {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public boolean hasNext() {
			if(c>32)return true;
			while(true) {
				c=nextChar();
				if(c==NC)return false;
				else if(c>32)return true;
			}
		}
		
		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for(int i = 0; i < n; i++) res[i] = nextInt();
			return res;
		}
		
	}

}

Measured memory_bytes: 32456
#include <cmath>
#include <iostream>
#include <vector>

long long dp[109][109][309];

int main(){
  long long N,W;
  std::cin >> N >> W;

  std::vector<long long> w_arr(N), v_arr(N);
  for(int i = 0; i < N; i++) std::cin >> w_arr[i] >> v_arr[i];

  for(int n = 0; n < N; n++){
    for(int i = 1; i <= n+1; i++){
      for(int w = 0; w < 3*N; w++){
        if(w-(w_arr[n]-w_arr[0]) < 0) dp[n+1][i][w] = dp[n][i][w];
        else{
          dp[n+1][i][w] = std::max(dp[n][i][w], dp[n][i-1][w-(w_arr[n]-w_arr[0])]+v_arr[n]);
        }
      }
    }
  }

  long long ans = 0;
  for(int n = 0; n <= N; n++){
    long long w = W-n*w_arr[0];
    if(w < 0) continue;
    if(w > 3*N) w = 3*N-1;
    ans = std::max(ans, dp[N][n][w]);
  }

  std::cout << ans << std::endl;

  return 0;
}



Measured memory_bytes: 24960
import java.io.*;
import java.util.*;
import java.util.regex.*;


public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static long cnt=0;
	public static PrintWriter pw = new PrintWriter(System.out);
	public static void main(String[] args) throws Exception {
		solutionC(args);
		if(in!=null){
			in.close();
		}
		pw.flush();
		pw.close();
	}

	public static void solutionA(String[] args) throws Exception{
		int H1=nextInt();
		int M1=nextInt();
		int H2=nextInt();
		int M2=nextInt();
		int K=nextInt();

		int t1=H1*60+M1;
		int t2=H2*60+M2;

		pw.println(t2-t1-K);
	}
	public static void solutionB(String[] args) throws Exception{
		pw.println(nextString().replaceAll("\\?","D"));
	}
	public static void solutionC(String[] args) throws Exception{
		int N=nextInt();
		int[] A = new int[N+2];
		for(int i=1;i<=N+1;i++) {
			A[i]=nextInt();
		}
		long sum=0;
		for(int i=0;i<A.length;i++) {
			sum+=A[i];
		}
		long ans=1;
		//葉ではないノードの数
		long[] s = new long[N+2];
		s[0]=1;

		for(int i=1;i<=N;i++) {
			long tmp = s[i-1]-A[i];
			sum-=A[i];
			if(tmp<=0) {
				pw.println(-1);
				return;
			}
			//残りの葉の数
			long sub=sum-tmp;
			//この階層で何個ノードを作っても矛盾しないか（2倍以内）
			if(sub<0) {
				pw.println(-1);
				return;
			}else {
				tmp=Math.min(tmp*2, tmp+sub);
			}
			s[i]=tmp;
			ans+=tmp;
		}
		if(s[N]!=A[N+1]) {
			pw.println(-1);
			return;
		}
		pw.println(ans);
	}
	public static void solutionD(String[] args) throws Exception{


	}



	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}

}



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

int main() {
  int a, b;
  cin >> a >> b;
  
  for (int i = 0; i <= 11000; i++) {
    if (2 * i / 25 == a && i / 10 == b) {
      cout << i << endl;
      break;
    }
    else if (i == 11000) {
      cout << -1 << endl;
    }
  }
}


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

typedef struct _node {
  int key;
  struct _node *next, *prev;
} NODE, *PHODE;
PHODE root;

void init() {
  root = (NODE *)malloc(sizeof(NODE));
  root->next = root;
  root->prev = root;
}

void insert(int key) {
  PHODE t = (NODE *)malloc(sizeof(NODE));
  t->key = key;
  t->next = root->next;
  t->prev = root;
  root->next->prev = t;
  root->next = t;
}

void deleteNode(NODE *cur) {
  cur->next->prev = cur->prev;
  cur->prev->next = cur->next;
  free(cur);
}

void _delete(int key) {
  PHODE cur = root->next;
  while (cur != root) {
    if (cur->key  == key) {
      deleteNode(cur);
      break;
    }
    else {
      cur = cur->next;
    }
  }
}

void deleteFirst() {
  if (root != root->next)
    deleteNode(root->next);
}

void deleteLast() {
  if (root != root->prev)
    deleteNode(root->prev);
}

void printNodes() {
  PHODE cur = root->next;
  while (1) {
    printf("%d", cur->key);
    if ((cur = cur->next) == root) {
      printf("\n");
      break;
    }
    else {
      printf(" ");
    }
  }
}

int main() {
  init();
  int n, f, key;
  char command[255];
  scanf("%d", &n);
  while (n--) {
    f = 0;
    scanf("%s", command);
    if ('i' == command[0]) {
      scanf("%d", &key);
      insert(key);
    }
    else {
      if ('F' == command[6]) {
        deleteFirst();
      } else if ('L' == command[6]) {
        deleteLast();
      } else {
        scanf("%d", &key);
        _delete(key);
      }
    }
  }
  printNodes();
  return 0;
}

Measured memory_bytes: 31788
#include <stdio.h>
int count_divisor(int a, int b, int c)
{
    int j = 0;
    for (int i = a; i <= b; i++)
    {
        if (c % i == 0)
        {
            j++;
        }
    }
    return j;
}

int main(void)
{
    int a, b, c;

    scanf("%d %d %d", &a, &b, &c);

    printf("%d\n", count_divisor(a, b, c));

    return 0;
}


Measured memory_bytes: 2716
#include<bits/stdc++.h>
using namespace std;
int dp[100005];
int main()
{
    int n,k;
    cin>>n>>k;
    int arr[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    dp[0]=0;
    for(int i=1;i<n;i++)
    {dp[i]=1000000006;;
        for(int j=1;j<=k;j++){
            if(i<j)
            continue;
        dp[i]=min(dp[i],abs(arr[i-j]-arr[i])+dp[i-j]);
    }
    }
    cout<<dp[n-1]<<endl;
}

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

const int N = 300005;
const int MOD = 1000000007;

int n, m, k;

int hori[N], vert[N];

int solve() {
  scanf("%d %d %d", &n, &m, &k);
  set<pair<int, int>> s;

  for (int i = 0; i < k; ++i) {
    int x, y;
    scanf("%d %d", &x, &y);
    --x, --y;
    ++hori[x], ++vert[y];
    s.insert({x, y});
  }

  vector<pair<int, int>> H(n), V(m);
  for (int i = 0; i < n; ++i) H[i] = {hori[i], i};
  for (int i = 0; i < m; ++i) V[i] = {vert[i], i};
  sort(H.begin(), H.end(), greater<pair<int, int>>());
  sort(V.begin(), V.end(), greater<pair<int, int>>());

  for (int i = 0; i < H.size(); ++i) {
    if (H[i].first != H[0].first) break;
    for (int j = 0; j < V.size(); ++j) {
      if (V[j].first != V[0].first) break;
      if (s.find({H[i].second, V[j].second}) == s.end()) {
        return 0 * printf("%d\n", H[0].first + V[0].first);
      }
    }
  }

  return 0 * printf("%d\n", H[0].first + V[0].first - 1);
}

int main() {
  int t = 1;
  // scanf("%d", &t);
  for (int tc = 0; tc < t; ++tc) {
    // printf("Case #%d: ", tc+1);
    solve();
  }
  return 0;
}


Measured memory_bytes: 24392