akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
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; }

const ll mod = 1e9+7;


void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */

/* 注意 

    1LL<<60 * N とかのオーバーフローに気を付けろ
    制約がヒントになる、ちゃんと全ての制約を見ろ

*/

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

    int n; std::cin >> n;
    std::vector<int> p(n);
    rep(i, n) cin >> p[i];
    std::vector<int> dp(n+1, 0);
    int ans = 0;
    rep(i, n) { dp[p[i]] = dp[p[i]-1]+1; ans = std::max(ans, dp[p[i]]); }
    std::cout << n-ans << std::endl;
    
    
    return 0;
}

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

int main()
{
  int n ;
  cin >> n;
  int ans = 0;
ans = n / 3;
cout << ans << endl;
}


Measured memory_bytes: 256
// Last Change: 10/10/2019 18:44:19.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

int main() {
  string ipt;
  while (cin >> ipt) {
    ll joiCnt, ioiCnt;
    joiCnt = ioiCnt = 0;
    for (ll i = ipt.size() - 1; i >= 2; --i) {
      if (ipt[i] == 'I' and ipt[i - 1] == 'O') {
        if (ipt[i - 2] == 'J')
          ++joiCnt;
        else if (ipt[i - 2] == 'I') {
          ++ioiCnt;
        }
      }
    }
    cout << joiCnt << '\n' << ioiCnt << endl;
  }
}


Measured memory_bytes: 3148
#include<stdio.h>
#define MAX 100000
 
typedef struct{
  int p;
  int l;
  int r;
}id;
   
id A[MAX];
int n,B[MAX];
 
   
int rec(int x,int y){
  B[x] = y;
  if(A[x].r != -1) rec(A[x].r,y);
  if(A[x].l != -1) rec(A[x].l,y + 1);
}


int main(){
  int i,j,d,v,c,l,r,n,op;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    A[i].p = A[i].l = A[i].r = -1;
  }
  
  for(i=0;i<n;i++){
    scanf("%d%d",&v,&d);
    for(j=0;j<d;j++){
      scanf("%d",&c);
      if(j==0) A[v].l=c;
      else A[l].r = c;
      l=c;
      A[c].p = v;
    }
  }
  for(i=0;i<n;i++){
    if(A[i].p == -1) r=i;
  }
 
  rec(r,0);
 
  for(i=0;i<n;i++){
    
    printf("node %d: parent = %d, depth = %d,",i,A[i].p,B[i]);
    if(A[i].p == -1) printf(" root,");
    else if(A[i].l == -1 ) printf(" leaf,");
    else printf(" internal node,");
    printf(" [");
    op=A[i].l;
    for(j=0; op != -1;j++){
      if(j != 0) printf(", ");
      printf("%d",op);
      op = A[op].r;
    }
    printf("]\n");  
  }
 
  return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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);}

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
	string a,b;cin>>a>>b;
	while(a.size()<b.size()){
		a='0'+a;
	}
	while(a.size()>b.size()){
		b='0'+b;
	}
	if(a==b)cout<<"EQUAL"<<endl;
	if(a>b)cout<<"GREATER"<<endl;
	if(a<b)cout<<"LESS"<<endl;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def main():
    X = int(read())
    yokin = 100
    ans = 0
    while yokin < X:
        yokin = int(yokin * 1.01)
        ans += 1
    print(ans)
    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 9168
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

n,m,q = map(int, input().split())
abcd = [list(map(int, input().split())) for _ in range(q)]

ans = 0
def dfs(now,last,use):
    #print(now,last,use)
    if now == n:
        res = 0
        for a,b,c,d in abcd:
            if use[b-1] - use[a-1] == c:
                res += d
        return res
    res = 0
    for to in range(last,m+1):
        res = max(res, dfs(now+1, to, use + [to]))
    return res

print(dfs(0, 1, []))

Measured memory_bytes: 9228
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long S = sc.nextLong();

        //S= x1 * y2 - y1 * x2
        long max = 1_000_000_000;
        long x1=max, y1 = 1;

        //S= y2 * 10^9 - x2
        long y2 = S/x1;
        long x2 = y2*x1 -S;
        if(x2 < 0){
            y2++;
            x2 = y2*x1 -S;
        }

        System.out.println("0 0 "+ x1 +" "+ y1 +" "+x2 +" "+ y2);


    }

}


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

typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

#define ture ture
#define flase false
#define falg flag

#define REP(i, x) for (ll i = 0; i < (ll)(x); i++)
#define REPS(i, x) for (ll i = 1; i <= (ll)(x); i++)
#define RREP(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (ll i = ((ll)(x)); i > 0; i--)
#define all(x) (x).begin(), (x).end()

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;//llの最大9*10^18
const int INF = pow(2, 30) - 1;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

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

    ll N;
    string S;
    cin >> N;

    vector<ll> a(N);

    REP(i,N){
        cin >> a.at(i);
    }

    sort(a.begin(), a.end());
    ll a_end = a.at(N - 1);

    vector<bool> check(a_end+10);

    REP(i,check.size()){
        check.at(i) = flase;
    }

    REP(i,N-1){
        if(a.at(i)==a.at(i+1)){
            ll tmp2 = a.at(i);
            for (ll j = 1; tmp2 * j <= a_end; j++)
            {
                check.at(tmp2 * j) = true;
            }
        }
    }


    REP(i,N){
        ll tmp = a.at(i);
        if(check.at(tmp)==true){

        }
        else{
            for (ll j = 2; tmp*j<=a_end; j++)
            {
                check.at(tmp * j) = true;
            }
        }
    }

    ll ans = 0;

    REP(i,N){
        if(check.at(a.at(i))==false){
            ans++;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 5048
// D.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <set>
#include <map>
#include <bitset>

using namespace std;

typedef long long LL;

int main(int argc, char* argv[]) {
#ifdef _MSC_VER
	while (true)
#endif
	{
		LL n = -1, x, y;
		cin >> n >> x >> y;
		if (n < 0) return 0;
		vector<LL> ans(n - 1);
		LL d = y + 1 - x;
		for (LL k = 1; k <= d / 2; ++k) {
			ans[k - 1] = d;
		}
		if ((d % 2) == 0) {
			ans[d / 2 - 1] /= 2;
		}
		for (LL i = 1; i < x; ++i) {
			for (LL j = 2; j <= n; ++j) {
				LL d = j - i;
				if (j > x && j <= y) {
					d = min(d, x - i + 1 + (y - j));
				}
				if (j > y) {
					d = x - i + 1 + j - y;
				}
				if (d > 0) {
					ans[d - 1] += 1;
				}
			}
		}
		for (LL j = y + 1; j <= n; ++j) {
			for (LL i = x; i < j; ++i) {
				LL d = j - i;
				if (i >= x && i <= y) {
					d = min(d, i - x + 1 + j - y);
				}
				if (d > 0) {
					ans[d - 1] += 1;
				}
			}
		}
		for (auto x : ans) {
			cout << x << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    
   int H,W,i,j;
   
   while(1){
       scanf("%d %d",&H,&W);
       if(H==0 && W==0) break;
       else{
           for(i=0;i<H;i++){
               if(i==0 || i==H-1){
                   for(j=0;j<W;j++) printf("#");
                   printf("\n");
               }

               else{
                   for(j=0;j<W;j++){
                       if(j==0 || j==W-1) printf("#");
                       else printf(".");
                   }
                   printf("\n");
               }
           }
       }
       printf("\n");
   }
   
    return 0;
    
}


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



int main() {
   int ans = 0;
   string n;
   cin >> n;
   rep(i, n.length()) {
      ans += n[i] - '0';
   }
   if(ans % 9 == 0) {
      cout << "Yes" << endl;
   }else {
      cout << "No" << endl;
   }

   return 0;
}

Measured memory_bytes: 3700
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC omodtimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
using namespace __gnu_pbds;
using namespace std;
 
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<long long ,long long> ii; 	
typedef complex<long double> com;
 
const ll mod = 1e9+7;

struct store{
	ll a,b;
	bool operator<(const store& rhs) const{
		if (rhs.a == a){
			return b < rhs.b;
		}
		return (rhs.a)*(b+1) < a*(rhs.b+1);
	}
};

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n, t;
	cin >> n >> t;
    vector <store> arr(n);
	for (int z=0;z<n;z++){
		cin >> arr[z].a >> arr[z].b;
	}
	sort(arr.begin(),arr.end());
	vector<vector<ll>> dp(n);
	dp[0].push_back(0);
	dp[0].push_back(1+1*arr[0].a+arr[0].b);
	vector <ll> s;
	for (int z=1;z<n;z++){
		if(arr[z].a == 0){
			if (s.size() == 0) s.push_back(arr[z].b+1);
			else {
				s.push_back(arr[z].b+*(s.rbegin())+1);
			}
			continue;
		}
		bool ok = true;
		dp[z].push_back(0);
		dp[z].resize(dp[z-1].size());
		for (int x=1;x<dp[z-1].size();x++){
			dp[z][x] = min(dp[z-1][x],1+dp[z-1][x-1]+(dp[z-1][x-1]+1)*arr[z].a+arr[z].b);
			if (dp[z][x] > t) ok = false;
		}
		if (ok){
			ll l = *(dp[z-1].rbegin());
			dp[z].push_back(1+l+(l+1)*arr[z].a+arr[z].b);
		}
	}
	ll ans = 0;
	for (int z=0;z<n;z++){
		for (ll x=0;x<dp[z].size();x++){
			if (dp[z][x] <= t) ans = max(ans,x + ll(upper_bound(s.begin(),s.end(),t-dp[z][x])-s.begin()) );
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 58112
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
using namespace std;
int main() {
	string s;
	cin >> s;
	int n = s.size();
	for (int i = 0; i < n; i += 2) {
		if (s.substr(i, 2) != "hi") {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#define maxn 100005
#define maxm 20
using namespace std;
int n,l,q,x[maxn],fr[maxn][maxm],la;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&x[i]);
	scanf("%d%d",&l,&q);
	x[0]=x[1];
	la=0;
	for(int i=1;i<=n;i++)
	{
		while(x[la]+l<x[i]) la++;
		fr[i][0]=la;
	}
	for(int i=2;i<=n;i++)
		for(int j=1;(1<<j)<=i&&j<17;j++)
			fr[i][j]=fr[fr[i][j-1]][j-1];
	while(q--)
	{
		int a,b,ans=0;
		scanf("%d%d",&a,&b);
		if(a>b) swap(a,b);
		int t;
		for(t=0;(1<<t)<=b;t++); t--;
		for(;t>=0;t--)
			if(fr[b][t]>=a) b=fr[b][t],ans+=(1<<t);
		if(b>a) ans++;
		printf("%d\n",ans);
	}
}

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

int main() {
  ll n,ans=1;
  cin >> n;
  int s[n]={};
  
  r(i,n){
    int a;
    cin >> a;
    if(a) ans*=s[a-1]-s[a];
    else ans*=3-s[0];
    ans%=mod;
    s[a]++;
  }
  
  cout<<ans<<endl;
}

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

int main() {
	int n;
	while(cin >> n && n){
		int m, p, k, l[128] = {0};
		bool know[128][128] = {0};
		for(int i = 1; i <= n; ++i){
			cin >> m;
			for(int j = 0; j < m; ++j){
				scanf("%d", &p);
				know[i][p] = true;
			}
		}
		cin >> k;
		for(int i = 0; i < k; ++i){
			scanf("%d", &l[i]);
		}
		int cnt = 0, ans = 0;
		for(int i = 1; i <= n; ++i){
			for(int j = 0; j < k; ++j){
				if(!know[i][l[j]])
					break;
				if(j == k - 1){
					cnt++;
					ans = i;
				}
			}
		}
		if(cnt == 1)
			cout << ans << endl;
		else
			cout << "-1" << endl;
	}
	return 0;
}

Measured memory_bytes: 1264
import java.util.*;

class Main{
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    while(true) {
      int n = scan.nextInt();
      int m = scan.nextInt();
      if((n|m) == 0) return;
      Town[] towns = new Town[n];
      for(int i = 0; i < n; i++) towns[i] = new Town();
      List<List<Branch>> branches = new ArrayList<>(n);
      for(int i = 0; i < n; i++) branches.add(new ArrayList<Branch>());
      for(int i = 0; i < m; i++) {
          int u = scan.nextInt()-1;
          int v = scan.nextInt()-1;
          int d = scan.nextInt();
          int c = scan.nextInt();
          Branch _b1 = new Branch(u,v,d,c);
          Branch _b2 = new Branch(v,u,d,c);
          branches.get(u).add(_b1);
          branches.get(v).add(_b2);
      }
      TreeSet<Branch> set = new TreeSet<>();
      set.addAll(branches.get(0));
      int result = 0;
      int[] minLenArr = new int[n];
      while(!set.isEmpty()) {
/*
        for(Branch _b : set) {
          System.out.printf("[%d,%d,%d,%d]\n",_b.u,_b.v,_b.d,_b.c);
        }
*/
        Branch _b = set.pollFirst();
        Town t1 = towns[_b.u].getTown();
        Town t2 = towns[_b.v].getTown();
        if(t1==t2) continue;
        Town z0 = towns[0].getTown();
        int newTownIndex = _b.u;
        int oldTownIndex = _b.v;
        if(z0==t1) {
          newTownIndex = _b.v;
          oldTownIndex = _b.u;
        }
        Town nt = new Town();
        t1.parent = nt;
        t2.parent = nt;
        result += _b.c;
        minLenArr[newTownIndex] = _b.d;
        for(Branch bb : branches.get(newTownIndex)) {
          bb.d += minLenArr[newTownIndex];
        }
        //System.out.printf("(%d,%d)\n",newTownIndex,oldTownIndex);
        set.addAll(branches.get(newTownIndex));
      }
      System.out.println(result);
    }
  }
}

class Town{
  Town parent;
  Town(){}
  Town getTown() {
    return (parent==null)?this:parent.getTown();
  }
}

class Branch implements Comparable<Branch>{
  int u,v,d,c;
  Branch(int _u, int _v, int _d, int _c) {
    u = _u;
    v = _v;
    d = _d;
    c = _c;
  }
  @Override
  public int compareTo(Branch _b) {
    if(this==_b) return 0;
    if(this.d==_b.d) {
      if(this.c!=_b.c) return this.c-_b.c;
      return 1;
    }
    return this.d-_b.d;
  }
}

Measured memory_bytes: 162184
//----------BHAVIK DIWANI(PICT_COMP)---------------
#include<bits/stdc++.h>
#include<stdlib.h>
#include<stdio.h>
#define test ll t; cin>>t; while(t--)
#define FOR(p,n) for(ll i=p;i<(ll)n;i++)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define ll long long
#define int long long
#define ull unsigned long long
#define MAX 1000005
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define endl '\n'
#define vs vector<string>
#define mii map<int,int>
#define msi map<string,int>
#define vpii vector< pair<int, int > >
#define vpsi vector< pair< string ,int > >
#define forci(p,q) for(int i=p;i<q;i++)
ll gcd(ll a,ll b){ if(b==0) return a;    return gcd(b,a%b);}
ll lcm(ll a,ll b) { return (a/gcd(a,b)*b);}
ull power(ull a, ull b) {a %= mod;  ull res = 1;  while (b > 0) { if (b & 1) res = res * a % mod;  a = a * a % mod;  b >>= 1; }  return res%mod; }
ll modmul(ll x, ll y){return (x*y)%mod;}
ll modadd(ll x, ll y){return (x+y)%mod;}
ll modsub(ll x, ll y){return (x-y+mod)%mod;}
ll fact[1000007]={0};
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<100007;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[r],mod-2)))%mod; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
inline long long toint(const std::string &s) {std::stringstream ss; ss << s; long long x; ss >> x; return x;}
inline std::string tostring(long long number) {std::stringstream ss; ss << number; return ss.str();}
inline std::string tobin(long long x) {return std::bitset<63>(x).to_string();}
/*bool prime[MAX];
ull sieve(){memset(prime,true,sizeof(prime));for(ull p=2;p*p<MAX;p++){if(prime[p]==true){for(ull i=2*p;i<MAX;i+=p){prime[i]=false;}}}prime[0]=0;prime[1]=0;
}*/
using namespace std;
void solve()
{
	int a[3][3];
	for(int i=0;i<3;i++)
	{
		for(int j=0;j<3;j++)
			cin>>a[i][j];
	}
	set<int>g;
	int n;
	cin>>n;
	while(n--)
	{
		int x;
		cin>>x;
		g.insert(x);
	}
	int ans=0;
	for(int i=0;i<3;i++)
	{
		if(g.count(a[i][0]) && g.count(a[i][1]) && g.count(a[i][2]))
		{
			ans++;
			break;
		}
	}
	for(int i=0;i<3;i++)
	{
		if(g.count(a[0][i]) && g.count(a[1][i]) && g.count(a[2][i]))
		{
			ans++;
			break;
		}
	}
	if(g.count(a[0][0]) && g.count(a[1][1]) && g.count(a[2][2]))
		ans++;
	if(g.count(a[0][2]) && g.count(a[1][1]) && g.count(a[2][0]))
		ans++;
	if(ans)
		cout<<"Yes";
	else
		cout<<"No";
		

}
signed main()
{
	fastio;
//	test
		solve();
}




Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from copy import deepcopy

h, w = map(int, readline().split())
s = [input() for i in range(h)]
q = []
start = []
dist = [[False] * w for _ in range(h)]
for i in range(h):
    for j in range(w):
        if s[i][j] != '#':
            start.append((i, j))
        else:
            dist[i][j] = True
test = [(0, 1), (0, -1), (1, 0), (-1, 0)]
ans = []
while start:
    check = deepcopy(dist)
    q = [start.pop()]
    check[list(q)[0][0]][list(q)[0][1]] = True
    cnt = -1
    while q:
        cnt += 1
        qq = []
        memo = len(q)
        memo_cnt = 0
        for y, x in q:
            for dy, dx in test:
                yy, xx = y + dy, x + dx
                if xx < 0 or yy < 0 or xx > w - 1 or yy > h - 1 or check[yy][xx]:
                    memo_cnt += 1
                    continue
                else:
                    check[yy][xx] = True
                    qq.append((yy, xx))
        q = qq
    ans.append(cnt)
else:
    print(max(ans))


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

int main () {

    int k;
    std::cin >> k;
    std::string s;
    std::cin >> s;

    if (s.length() <= k) std::cout << s << std::endl;
    else std::cout << s.substr(0, k) + "..." << std::endl;

    return 0;
}

Measured memory_bytes: 3084
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
## dp ##
def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]
## math ##
def to_bin(x: int) -> str: return format(x,'b') # rev => int(res, 2)
def to_oct(x: int) -> str: return format(x,'o') # rev => int(res, 8)
def to_hex(x: int) -> str: return format(x,'x') # rev => int(res, 16)
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(n=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(n+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, n+1, i): is_prime[j] = False
    return [i for i in range(n+1) if is_prime[i]]
def prime_factor(n):
    """Return a list of prime factorization numbers of n"""
    res = []
    for i in range(2,int(n**0.5)+1):
        while n%i==0: res.append(i); n //= i
    if n != 1: res.append(n)
    return res
## const ##
MOD=10**9+7
## libs ##
import itertools as it
import functools as ft
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left
#======================================================#
def main():
    s = II()
    m = 10**9
    x3 = (m-s%m)%m
    y3 = (s+x3)//m
    print(0, 0, m, 1, x3, y3)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3700
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
#include <cassert>
#include <random>
int main() {
	int price; std::cin >> price;
	for (auto i = 0; i <= price; ++i) {
		if (i * 108 / 100 == price) {
			std::cout << i << '\n';
			return 0;
		}
	}
	std::cout << ":(\n";
}

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

using namespace std;

typedef long long ll;

const int N = 2e5 + 5;

vector <int> g[N];
int n;

int main() {
  cin >> n;
  for(int i = 0; i < n; i++) {
    int x; cin >> x;
    g[x].push_back(i);
  }
  int cur = -1;
  for(int i = 1; i <= n; i++) {
    auto p = lower_bound(g[i].begin(), g[i].end(), cur);
    if(p == g[i].end()) {
      if(i == 1) {
        puts("-1");
        return 0;
      }
      cout << n - (i - 1) << '\n';
      return 0;
    }
    cur = *p;
  }
  cout << 0 << '\n';
}

Measured memory_bytes: 11136
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<cmath>
#include<limits>
#define ll long long
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define pint_INF 2000000000
#define ll_INF 	9223372036854775807
#define MOD 1000000007
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvc vector<vector<char>>
#define vll vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
#define sysp system("PAUSE")
using namespace std;

int dist(int& i,int& j, int& x,int& y){
    int a = abs(i-j);
    int b = abs(x-i)+abs(y-j) + 1;
    int c = abs(x-j) + abs(y-i) + 1;

    return min({a,b,c});
}

int main(){
    int N,x,y; cin >> N >> x >> y;
    x--; y--;
    vi K(N);


    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            int index = dist(i,j,x,y);
            K[index]++;
        }
    }

    for(int i = 1; i < N; i++){
        cout << K[i] / 2 << endl;
    }

    sysp;
}


Measured memory_bytes: 504
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<P,P> PP;
const ll MOD=998244353;
const ll MAX_N=500010;
const ll INF=100100100100100;

int main(){
    int n;
    cin>>n;
    int cnt=0;
    vector<int> a(n),b(n);
    for(int i=0;i<n;i++){
        cin>>a[i]>>b[i];
    }
    for(int i=0;i<n;i++){
        if(a[i]==b[i]){
            cnt++;
        }else{
            cnt=0;
        }
        if(cnt==3){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    
}

Measured memory_bytes: 3128
x = tuple(input().split())
a = int(x[0])
b = int(x[1])
c = int(x[2])
k = 0
for n in range(1, c+1):
	if divmod(c, n)[1] == 0 and a <= divmod(c, n)[0] <= b:
		k += 1
print(k)

Measured memory_bytes: 7584
#include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a); i>n; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
class Dice{
public:
	vi n;
	int top;
	Dice(){
		n.resize(6);
		top = 0;
	}
	void roll(char c){
		int tmp = n[0];
		if( c == 'E' ){
			n[0] = n[3];
			n[3] = n[5];
			n[5] = n[2];
			n[2] = tmp;
		}else if( c == 'W' ){
			n[0] = n[2];
			n[2] = n[5];
			n[5] = n[3];
			n[3] = tmp;
		}else if( c == 'N' ){
			n[0] = n[1];
			n[1] = n[5];
			n[5] = n[4];
			n[4] = tmp;
		}else if( c == 'S' ){
			n[0] = n[4];
			n[4] = n[5];
			n[5] = n[1];
			n[1] = tmp;
		}
	}
	void input() {rep(i, 0, 6) cin >> n[i];}
	void output() {P(n[top]);}
};
vector<vi> saikoro = {
		{-1, 3, 1, 4, 2, -1},
		{2, -1, 5, 0, -1, 3},
		{4, 0, -1, -1, 5, 1},
		{1, 5, -1, -1, 0, 4},
		{3, -1, 0, 5, -1, 2},
		{-1, 2, 4, 1, 3, -1}
};
inline int f(Dice d) {
	int u, m; cin >> u >> m;
	rep(i, 0, 6) {
		if(d.n[i] != u) continue;
		rep(j, 0, 6) {
			if(d.n[j] != m) continue;
			return saikoro[j][i];
		}
	}
	return 0;
}
int main() {
	Dice d;
	d.input();
	int n; cin >> n;
	rep(i, 0, n) {
		P(d.n[f(d)]);
	}
	return 0;
}

Measured memory_bytes: 3176
import java.util.*;

class Main {
  public static void main (String[] args) {
    Scanner scanner = new Scanner(System.in);
    String out = "";
    while (scanner.hasNext()) {
      int n = scanner.nextInt();
      if (n == 0) {
        break;
      }
      Map<Integer, Integer> m = new HashMap<Integer, Integer>();
      int[] a = new int[n];
      int[] b = new int[n];
      for (int ii = 0; ii < n; ii++) {
        a[ii] = scanner.nextInt();
      }
      for (int cnt = 0; ; cnt++) {
        for (int ii = 0; ii < n; ii++) {
          if (m.containsKey(a[ii])) {
            m.put(a[ii], m.get(a[ii]) + 1);
          } else {
            m.put(a[ii], 1);
          }
        }
        for (int ii = 0; ii < n; ii++) {
          b[ii] = m.get(a[ii]);
        }
        if (!chk(a, b)) {
          for (int ii = 0; ii < n; ii++) {
            a[ii] = b[ii];
            m.clear();
          }
        } else {
          out += cnt + "\n";
          for (int ii = 0; ii < n; ii++) {
            out += b[ii];
            out += ii != n - 1 ? " " : "\n";
          }
          break;
        }
      }
    }
    System.out.print(out);
  }

  private static boolean chk (int[] a, int[] b) {
    for (int ii = 0; ii < a.length; ii++) {
      if (a[ii] != b[ii]) {
        return false;
      }
    }
    return true;
  }

}

Measured memory_bytes: 54168
#include <iostream>
#include <vector>
#include <algorithm> // sort
#include <map> // pair
#include <numeric> // accumulate(begin,end,初期値)

typedef long long ll;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<x<<endl;
#define rep(i,n) for(ll i = 0;i < n;++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SUM(vec) accumulate(all(vec),0);

const ll INF = 1e9+7;

// 各桁の和
template<typename T>
T digit(T num){
  T sum = 0;
  while(num){
    sum += num % 10;
    num /= 10;
  }
  return sum;
}

int main(){
  int A,B,C,X;cin>>A>>B>>C>>X;
  int ans = 0;
  rep(i,A+1){
    rep(j,B+1){
      rep(k,C+1){
        int tmp = 500*i + 100*j + 50*k;
        if(tmp == X)ans++;
      }
    }
  }
  
  print(ans)
  return 0;
}


Measured memory_bytes: 256
#define rep(i,n) for(ll i=0;i<(n);++i)

#include<bits/stdc++.h>
using ll = long long;
using namespace std;

int n;
vector<int> a;
    
void input(){
    cin>>n;
    a.resize(n);
    rep(i,n){cin>>a[i];}
}

void src(){
    int sum=0;
    rep(i,n){
        rep(j,n){
            if(i<j){
                sum += a[i]*a[j];
            }
        }
    }
    cout<<sum;
    return;
}

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

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int, K: int, h: "List[int]"):
    h.sort(reverse=True)
    count = 0

    for member_cm in h:
        if member_cm >= K:
            count += 1
        else:
            pass
        if member_cm < K:
            break
        else:
            pass
    print(count)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    h = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, h)


if __name__ == "__main__":
    main()


Measured memory_bytes: 12444
#include<cstdio>
using namespace std;
int main(){
    int n;
    scanf("%d",&n);
    for(int l = 1; l <= n; l++){
        int x;
        scanf("%d",&x);
        printf("Case %d:\n",l);
        for(int i = 0; i < 10; i++){
            x *= x;
            x = x/100%10000;
            printf("%d\n",x);
        }
    }
    return 0;
}

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

int main(){
    string s, t;
    cin >> s >> t;
    int ans = 0;
    for(int i = 0;i<s.size();i++){
        if(s[i] != t[i]) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3852
n, m = map(int, input().split())
X = [tuple(map(int, input().split())) for _ in range(n)]
Y = [tuple(map(int, input().split())) for _ in range(m)]


for x in X:
    d1 = sum(x)
    d2 = x[0] - x[1]
    z = 10 ** 9
    for i, y in enumerate(Y, 1):
        D1 = sum(y)
        D2 = y[0] - y[1]
        Z = max(abs(D1 - d1), abs(D2 - d2))
        if z > Z:
            z = Z
            ans = i
    print(ans)


Measured memory_bytes: 8944
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    s,w = LI()
    if s <= w:
        print("unsafe")
    else:
        print("safe")
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 65540
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
using namespace std;

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(itr,v) for(auto &(itr):(v))
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
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);}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;



int a, b;

signed main() {
	cin >> a >> b;
	cout << (a-1)*(b-1) << ln;
}

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

int main()
{
    int k;
    char s[100];
scanf("%i",&k);
scanf("\n");
scanf("%[^\n]%*c",s);

if (strlen(s)<=k){
    printf("%s\n",s);
}
else{
    for(int i=0;i<k;i++){
        printf("%c",s[i]);
    }
    printf("...");
}
    return 0;
}


Measured memory_bytes: 1684
#include<iostream>

using namespace std;

#define N 100001

int Partition(int a[],int p,int r){
  int x,i,j,st;

  x=a[r];
  i=p-1;

  for(j=p;j<=r-1;j++){
    if(a[j]<=x){
      i++;
      st=a[i];
      a[i]=a[j];
      a[j]=st;
    }
  }
    st=a[i+1];
    a[i+1]=a[r];
    a[r]=st;
    return i+1;

}

int main(){

  int a[N],n,i;
  int f;

  cin >>n;

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


  f=Partition(a,0,n-1);

  for(i=0;i<n;i++){
    if(i!=f)cout <<a[i];
    if(i==f)cout <<"["<<a[i]<<"]";
    if(i!=n-1)cout <<" ";
  }
  cout <<endl;

  return 0;
}

Measured memory_bytes: 1252
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
/* clang-format on */

const ll MOD = 1e9 + 7;

ll power(ll x, ll e) {
  ll v = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) {
      v = v * x % MOD;
    }
    x = x * x % MOD;
  }
  return v;
}

ll inverse(ll x) {
  return power(x, MOD - 2);
}

vector<ll> fact, factInv;
void initFact(int N) {
  fact.resize(N + 1);
  factInv.resize(N + 1);
  fact[0] = 1;
  for (int i = 1; i <= N; i++) {
    fact[i] = fact[i - 1] * i % MOD;
  }
  factInv[N] = inverse(fact[N]);
  for (int i = N - 1; i >= 0; i--) {
    factInv[i] = factInv[i + 1] * (i + 1) % MOD;
  }
}

ll choose(int n, int k) {
  if (k > n) {
    return 0;
  } else {
    return fact[n] * factInv[k] % MOD * factInv[n - k] % MOD;
  }
}

int main() {
  int N, H, W;
  while (cin >> H >> W >> N) {
    initFact(400000);
    vector<int> r(N + 2), c(N + 2);
    for (int i = 0; i < N; i++) cin >> r[i] >> c[i];
    r[N] = 1;
    c[N] = 1;
    r[N + 1] = H;
    c[N + 1] = W;
    N += 2;
    vector<int> ind(N);
    for (int i = 0; i < N; i++) ind[i] = i;
    sort(ind.begin(), ind.end(), [&](int a, int b) {
      if (r[a] != r[b]) return r[a] < r[b];
      return c[a] < c[b];
    });
    vector<ll> dp(N, 0);
    dp[0] = 1;
    for (int i = 1; i < N; i++) {
      int ii = ind[i];
      int dr = r[ii] - 1;
      int dc = c[ii] - 1;
      dp[i] = choose(dr + dc, dr);
      for (int j = 1; j < i; j++) {
        int jj = ind[j];
        if (r[jj] <= r[ii] && c[jj] <= c[ii]) {
          int dr = r[ii] - r[jj];
          int dc = c[ii] - c[jj];
          dp[i] = (dp[i] - choose(dr + dc, dr) * dp[j] % MOD + MOD) % MOD;
        }
      }
    }
    cout << dp.back() << endl;
  }
  return 0;
}


Measured memory_bytes: 6528
#include "bits/stdc++.h"
using namespace std;

int main()
{
  int a,b,c,ans;
  ans=0;
  cin>>a>>b>>c;
  for(int i=a;i<=b;i++)
  {
    if(i%c==0)
      ans++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3544
#include "bits/stdc++.h"
#include <random>
#define REP(i, n) for (ll i = 0; i < ll(n); ++i)
#define RREP(i, n) for (ll i = ll(n) - 1; i >= 0; --i)
#define FOR(i, m, n) for (ll i = m; i < ll(n); ++i)
#define RFOR(i, m, n) for (ll i = ll(n) - 1; i >= ll(m); --i)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

constexpr int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
constexpr int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vi v(n + 1);
  REP(i, n + 1) cin >> v[i];
  bool ok = true;
  ll ans = 1;
  if (n == 0) {
    if (v[0] != 1)
      ok = false;
  } else {
    if (v[0] != 0)
      ok = false;
  }
  vl rsum(n + 2);
  rsum[n + 1] = 0;
  RREP(i, n + 1) rsum[i] = v[i] + rsum[i + 1];
  ll rem = 1;
  FOR(i, 1, n+1) {
    if (v[i] > 2 * rem) {
      ok = false;
    }
    else if (rem > rsum[i]) {
      ok = false;
    }
    else {
      ans += v[i];
      ll k= min(2 * rem - v[i], rsum[i + 1]);
      rem = k;
      ans += k;
    }
  }
  if (ok)
    cout << ans << endl;
  else
    cout << -1 << endl;
}


Measured memory_bytes: 4500
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
//using Debug;
//using static System.Globalization.CultureInfo;
//using Edge = Pair<long, int>;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
        Solve();
        //WriteLine(Solve());
    }
    static void Solve()
    {
        //var num = Input.num;
        //var xy = Input.ar2D(num);
        var nk = Input.ar;
        if (nk[1] != 1)
            WriteLine(nk[0] - nk[1]);
        else WriteLine(0);
        //WriteLine(b ? "Yay!" : ":(");
    }
}

public class Input
{
    public static string read => ReadLine().Trim();
    public static int[] ar => read.Split(' ').Select(int.Parse).ToArray();
    public static int num => ToInt32(read);
    public static long[] arL => read.Split(' ').Select(long.Parse).ToArray();
    public static long numL => ToInt64(read);
    public static char[][] gred(int h)
        => Enumerable.Repeat(0, h).Select(_ => read.ToCharArray()).ToArray();
    public static int[] ar1D(int n)
        => Enumerable.Repeat(0, n).Select(_ => num).ToArray();
    public static long[] arL1D(int n)
        => Enumerable.Repeat(0, n).Select(_ => numL).ToArray();
    public static string[] strs(int n)
        => Enumerable.Repeat(0, n).Select(_ => read).ToArray();
    public static int[][] ar2D(int n)
        => Enumerable.Repeat(0, n).Select(_ => ar).ToArray();
    public static long[][] arL2D(int n)
        => Enumerable.Repeat(0, n).Select(_ => arL).ToArray();
    public static T getValue<T>(string g)
    {
        var t = typeof(T);
        if (t == typeof(int))
            return (T)(object)int.Parse(g);
        if (t == typeof(long))
            return (T)(object)long.Parse(g);
        if (t == typeof(string))
            return (T)(object)g;
        if (t == typeof(char))
            return (T)(object)char.Parse(g);
        if (t == typeof(double))
            return (T)(object)double.Parse(g);
        if (t == typeof(bool))
            return (T)(object)bool.Parse(g);
        return default(T);
    }
    public static string[] Make<T1, T2>(out T1 v1, out T2 v2)
    {
        var r = read.Split(' ');
        v1 = getValue<T1>(r[0]);
        v2 = getValue<T2>(r[1]);
        return r;
    }
    public static string[] Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3)
    {
        var r = Make(out v1, out v2);
        v3 = getValue<T3>(r[2]);
        return r;
    }
    public const long Inf = (long)1e18;
    public const double eps = 1e-6;
    public const string Alfa = "abcdefghijklmnopqrstuvwxyz";
    public const int MOD = 1000000007;
}


Measured memory_bytes: 13268
N, C, K = map(int, input().split())
T = sorted([int(input()) for _ in range(N)])

bus_num = 0
while T:
    passengers = 1
    t = T[0]
    T.pop(0)
    while T and passengers < C and T[0] <= t + K:
        T.pop(0)
        passengers += 1
    bus_num +=1
print(bus_num)


Measured memory_bytes: 8280
def binary_serch(target, num_list):
    ok = len(num_list)
    ng = -1

    while(abs(ok - ng) > 1):
        mid = int((ok + ng) / 2)
        mid_num = num_list[mid]
        if target < mid_num:
            ok = mid
        else:
            ng = mid

    return ok


if __name__ == '__main__':
    N = int(input())
    A = [int(i) for i in input().split()]
    B = [int(i) for i in input().split()]
    C = [int(i) for i in input().split()]

    A.sort()
    B.sort()
    C.sort()

    # index
    A2B = [binary_serch(a, B) for a in A]

    # 累積和
    B2C = []
    tmp = 0
    for b in B[::-1]:
        tmp = tmp + (N - binary_serch(b, C))
        B2C.append(tmp)

    B2C = B2C[::-1]

    ans = 0

    for i in range(N):
        if not A2B[i] == N:
            ans += B2C[A2B[i]]

    print(ans)


Measured memory_bytes: 25076
N = int(input())
A = list(map(int, input().split()))

def bubble_sort(A,N):
    flag = True
    cnt  = 0
    while flag:
        flag = False
        for j in range(N-1,1-1,-1): #j=N-1 to 1
            if A[j] < A[j-1]:
                A[j],A[j-1] = A[j-1],A[j]
                cnt += 1
                flag = True
    return A, cnt
    
sorted_A, cnt = bubble_sort(A,N)
print(*A)
print(cnt)


Measured memory_bytes: 5608
#include <stdio.h>

int main(){
	int panjangkata,kecilin;
	scanf("%d %d", &panjangkata,&kecilin);
	char huruf[panjangkata+5];
	scanf("%s",huruf);
	huruf[kecilin-1] += 32;
	printf("%s",huruf);
	
    return 0;
}

Measured memory_bytes: 1708
import numpy as np

A,B,M = list(map(int,input().split()))
valueA = list(map(int, input().split()))
#print(valueA)
valueB = list(map(int, input().split()))
#print(valueB)
tickets = np.zeros((M ,3))
for i in range(M):
    tickets[i,:] =  list(map(int, input().split()))
x1 = int(tickets[0,0])
y1 = int(tickets[0,1])
c1 = int(tickets[0,2])
min_ticket = valueA[x1-1] + valueB[y1-1] - c1
if M != 1:
    for i in range(1,M):
        xi = int(tickets[i,0])
        yi = int(tickets[i,1])
        ci = int(tickets[i,2])
        value = valueA[xi-1] + valueB[yi-1] - ci
        if value < min_ticket:
            min_ticket = value
"""
min_itself = valueA[0] + valueB[0]
# 全部やってるから時間かかる
for i in range(A):
    for j in range(B):
        value = valueA[i] + valueB[j]
        if value < min_itself:
            min_itself = value
min_all = min(min_itself, min_ticket)
"""
minA = min(valueA)
minB = min(valueB)
min_itself = minA + minB
min_all = min(min_itself, min_ticket)
print(min_all)


Measured memory_bytes: 29248
#include <stdio.h>
int main(void){
    int A, B, C;
    scanf("%d %d %d", &A, &B, &C);
    int kotae = B + C - A;
       if (kotae < 0){
          kotae = 0;
          
       }
    printf("%d\n", kotae);
return 0;
}

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

int main() {
  int a,b;
  cin >> a >> b;
  if(a == b) cout << "Draw" << endl;
  else if(a == 1) cout << "Alice" << endl;
  else if(b == 1) cout << "Bob" << endl;
  else if(a < b) cout << "Bob" << endl;
  else cout << "Alice" << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <vector>
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <functional>
#include <queue>

//AtCoderC++.cpp

using namespace std;



void Show(vector<bool>& Ps) {
	for (int i = 0; i < Ps.size(); i++) {
		if (Ps[i]) {
			cout << "T" << endl;
		} else {
			cout << "F" << endl;
		}
	}
}

void Show(vector<vector<int>>& Ns) {
	for (int i = 0; i < Ns.size(); i++) {
		for (int j = 0; j < Ns[i].size(); j++) {
			cout << Ns[i][j] << " ";
		}
		cout << endl;
	}
}


int main() {
	array<bool, 4> Arare;
	for (int i = 0; i < 4; i++) {
		Arare[i] = false;
	}
	int N;
	cin >> N;
	char c;
	for (int i = 0; i < N; i++) {
		cin >> c;
		switch (c) {
			case 'G':
				Arare[0] = true;
				break;
			case 'P':
				Arare[1] = true;
				break;
			case 'Y':
				Arare[2] = true;
				break;
			case 'W':
				Arare[3] = true;
				break;
			defaut:
				break;
		}
	}
	int Count = 0;
	for (int i = 0; i < 4; i++) {
		if (Arare[i])Count++;
	}
	if (Count == 3)	cout << "Three" << endl;
	if (Count == 4)	cout << "Four" << endl;
}

Measured memory_bytes: 256