akhauriyash/Code-Regression huggingface dataset:
/*
Rathin Bhargava
IIIT Bangalore

*/
#include<bits/stdc++.h>
#define mt make_tuple
#define mp make_pair
#define pu push_back
#define INF 1000000001
#define MOD 1000000007
#define EPS 1e-6
#define ll long long int
#define ld long double
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define pr(v) { for(int i=0;i<v.size();i++) { v[i]==INF? cout<<"INF " : cout<<v[i]<<" "; } cout<<endl;}
#define t1(x)                cerr<<#x<<" : "<<x<<endl
#define t2(x, y)             cerr<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<endl
#define t3(x, y, z)          cerr<<#x<<" : " <<x<<" "<<#y<<" : "<<y<<" "<<#z<<" : "<<z<<endl
#define t4(a,b,c,d)          cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<endl
#define t5(a,b,c,d,e)          cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<" "<<#e<<" : "<<e<<endl
#define t6(a,b,c,d,e,f)          cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<" "<<#e<<" : "<<e<<" "<<#f<<" : "<<f<<endl
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define t(...) GET_MACRO(__VA_ARGS__,t6,t5, t4, t3, t2, t1)(__VA_ARGS__)
#define _ cerr<<"here"<<endl;
#define __ {ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}

using namespace std;
template<class A, class B> ostream& operator<<(ostream& out, const pair<A, B> &a){ return out<<"("<<a.first<<", "<<a.second<<")";}
template <int> ostream& operator<<(ostream& os, const vector<int>& v) { os << "["; for (int i = 0; i < v.size(); ++i) { if(v[i]!=INF) os << v[i]; else os << "INF";if (i != v.size() - 1) os << ", "; } os << "]\n"; return os; } 
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { os << "["; for (int i = 0; i < v.size(); ++i) { os << v[i]; ;if (i != v.size() - 1) os << ", "; } os << "]\n"; return os; } 


int main()
{
  __;
  int n,m,k;
  cin >> n >> m >> k;
  vector<vector<int> > v(n,vector<int> (m));

  int counter = 1;
  for(int i=0;i<n;i++)
  {
    string s;
    cin >> s;
    for(int j=0;j<s.size();j++)
    {
      if(s[j] == '#') 
      {
        v[i][j] = counter;
        counter++;
      }
    }
  }

  for(int i=0;i<n;i++)
  {
    int prev = 0;
    for(int j=0;j<m;j++)
    {
      if(!v[i][j]) v[i][j] = prev;
      else prev = v[i][j];
    }
    prev = 0;
    for(int j=m-1;j>=0;j--)
    {
      if(!v[i][j]) v[i][j] = prev;
      else prev = v[i][j];
    }
  }

  for(int i=n-1;i>=0;i--)
  {
    for(int j=0;j<m;j++)
    {
      if(v[i][j] == 0 && i<n-1 && v[i+1][j]) v[i][j] = v[i+1][j];
    }
  }


  for(int i=0;i<n;i++)
  {
    for(int j=0;j<m;j++)
    {
      if(v[i][j] == 0 && i>0 && v[i-1][j]) v[i][j] = v[i-1][j];
    }
  }
  for(int i=0;i<n;i++)
  {
    for(int j=0;j<m;j++) cout << v[i][j] << " "; 
    cout << endl;
  }


  return 0;
}



Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define MAXN 1000010
vector<int> edge[MAXN];
int n,sg[MAXN],u,v;
void dfs(int u,int fa)
{
    sg[u]=0;
    for(auto v : edge[u])
    {
        if(v==fa)continue;
        dfs(v,u);
        sg[u]^=sg[v]+1;
    }
}

int main()
{
    scanf("%d",&n);
    for(int i=1;i<n;++i)
    {
        scanf("%d%d",&u,&v);
        edge[u].push_back(v);
        edge[v].push_back(u);
    }
    dfs(1,0);
    puts(sg[1]?"Alice":"Bob");
}

Measured memory_bytes: 35328
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ppb pop_back()
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;

signed main(){
    string s; cin >> s;
    int ans=0;
    for(int i=1;2*i<s.size();i++){
        if(s.substr(0,i)==s.substr(i,i)) chmax(ans,2*i);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
while True:
    n = int(input())
    if n == 0:
        break
    arr = [[0 for r in range(n+2)]for c in range(n+2)]
    
    for r in range(n):
        arr[r] = list(map(int, input().split()))
        arr[r].append(sum(arr[r]))

    for c in range(n+1):
        s = 0
        for r in range(n):
            s += arr[r][c]
        arr[n][c] = s
    
    for r in range(n+1):
        for c in range(n+1):
            print(format(arr[r][c],'5d'), end ='')
        print()


Measured memory_bytes: 5640
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned ll
#define db double
#define pint pair<int,int>
#define mk make_pair
#define pb push_back
#define eb emplace_back
#define ins insert
#define fi first
#define se second
#define Rep(x,y,z) for(int x=y;x<=z;x++)
#define Red(x,y,z) for(int x=y;x>=z;x--)
using namespace std;
const int MAXN=1e5+5;
char buf[1<<12],*pp1=buf,*pp2=buf,nc;int ny;
inline char gc() {return pp1==pp2&&(pp2=(pp1=buf)+fread(buf,1,1<<12,stdin),pp1==pp2)?EOF:*pp1++;}
//inline char gc(){return getchar();}
inline int read(){
	int x=0;for(ny=1;nc=gc(),(nc<48||nc>57)&&nc!=EOF;)if(nc==45)ny=-1;if(nc<0)return nc;
	for(x=nc-48;nc=gc(),47<nc&&nc<58&&nc!=EOF;x=(x<<3)+(x<<1)+(nc^48));return x*ny;
}
int n,c[2][MAXN],Mxp[2],Mxx[2];
int main(){
//	freopen("std.in","r",stdin);
//	freopen("std.out","w",stdout);
	n=read();
	Rep(i,1,n)c[i&1][read()]++;
	Rep(t,0,1)Rep(i,1,1e5)if(c[t][i]>c[t][Mxp[t]])Mxx[t]=Mxp[t],Mxp[t]=i;else if(c[t][i]>c[t][Mxx[t]])Mxx[t]=i;
	if(Mxp[0]==Mxp[1]){
		cout<<n-max(c[0][Mxp[0]]+c[1][Mxx[1]],c[1][Mxp[1]]+c[0][Mxx[0]]);
	}else cout<<n-c[0][Mxp[0]]-c[1][Mxp[1]];
	return 0;
}





Measured memory_bytes: 4364
package main

import (
	"fmt"
)

func main() {
	var n, y int
	fmt.Scan(&n, &y)
	for i := 0; i <= n; i++ {
		for j := 0; j <= (n - i); j++ {
			k := n - i - j
			if i*10000+j*5000+k*1000 == y {
				fmt.Println(i, j, k)
				return
			}
		}
	}
	fmt.Println(-1, -1, -1)
}


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

using namespace std;

#define fastio ios_base::sync_with_stdio(0);cin.tie(NULL);
#define INF 0x3f3f3f3f
#define pb push_back
#define MAXN 100005
#define MOD 1000000007

typedef long long ll;

int a[MAXN], b[MAXN], c[MAXN];
int dp[2][3];

int32_t main(){
    fastio
    int n;
    cin >> n;

    for(int i = 1; i <= n; i++){
        cin >> a[i] >> b[i] >> c[i];
    }

    dp[1][0] = a[1], dp[1][1] = b[1], dp[1][2] = c[1];

    for(int i = 2; i <= n; i++){
        dp[i & 1][0] = max(dp[~i & 1][1], dp[~i & 1][2]) + a[i];
        dp[i & 1][1] = max(dp[~i & 1][0], dp[~i & 1][2]) + b[i];
        dp[i & 1][2] = max(dp[~i & 1][0], dp[~i & 1][1]) + c[i];
    }

    cout << max(dp[n & 1][0], max(dp[n & 1][1], dp[n & 1][2])) << endl;

    return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;

int main() {
    int n, k; cin >> n >> k;
    vector<int> h(n);
    for (int i = 0; i < n; i++) cin >> h[i];

    sort(h.begin(), h.end());

    int ans = 1000000001;
    for (int i = 0; i <= n - k; i++) {
        ans = min(ans, abs(h[i] - h[i + k - 1]));
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
import math

class Vector:
    def __init__(self,x,y):
        self.x = x
        self.y = y
        
    def norm_2(self):
        return dot(self,self)
    
    def norm(self):
        return math.sqrt(self.norm_2())
    
def v_sum(v1,v2):
    return Vector(v1.x+v2.x,v1.y+v2.y)
def v_diff(v1,v2):
    return Vector(v1.x-v2.x,v1.y-v2.y)
def scalar_multi(k,v):
    return Vector(k*v.x,k*v.y)
    
def dot(vector1,vector2):
    return vector1.x*vector2.x+vector1.y*vector2.y

def cross(vector1,vector2):
    return vector1.x*vector2.y+vector1.y*vector2.x

x1,y1,x2,y2 = map(int,input().split())
p1 = Vector(x1,y1)
p2 = Vector(x2,y2)

d = v_diff(p2,p1)

q = int(input())
for i in range(q):
    x,y = map(int,input().split())
    v = v_diff(Vector(x,y),p1)
    u = v_sum(scalar_multi(dot(v,d)/d.norm_2(),d),p1)
    print('{} {}'.format(round(u.x,9),round(u.y,9)))


Measured memory_bytes: 5700
#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
  int n,w;
  cin>>n>>w;
  vector<vector<long long>> dp(n);
  for (int i=0;i<n;i++)
  {
    vector<long long> v1(w+1);
    dp[i]=v1;
  }
  vector<vector<long long>> v;
  for (int i=0;i<n;i++)
  {
    vector<long long> v2;
    int a,b;
    cin>>a>>b;
    v2.push_back(a);
    v2.push_back(b);
    v.push_back(v2);
  }
  sort(v.begin(),v.end());
  for (int i=0;i<w+1;i++)
  {
    if (i>=v[0][0])
    dp[0][i]=v[0][1];
  }
  for (int i=1;i<n;i++)
  {
    for (int j=0;j<w+1;j++)
    {
      if (j>=v[i][0])
      {
        dp[i][j]=max(dp[i][j],max(dp[i-1][j-v[i][0]]+v[i][1],dp[i-1][j]));
      }
      else
      {
        dp[i][j]=max(dp[i-1][j],dp[i][j]);
      }
    }
  }
//   for (int i=0;i<n;i++)
//   {
//       for (int j=0;j<w+1;j++)
//       {
//           cout<<dp[i][j]<<" ";
//       }
//       cout<<endl;
//   }
  cout<<dp[n-1][w];
}

Measured memory_bytes: 81856
#pragma comment(linker, "/STACK:102400000,102400000")
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <map>
#include <set>
#include <queue>

#define LL long long

using namespace std;

int n;
int d[105];

int main()
{
	//freopen("test_in.txt", "r", stdin);
	//freopen("test_out.txt", "w", stdout);
	cin>>n;
	for(int i = 1; i <= n; i++)
		cin>>d[i];
	sort(d+1, d+n+1);
	int cnt=1;
	for(int i = n-1; i >= 1; i--)
		if(d[i]!=d[i+1])
			cnt++;
	cout<<cnt<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()


int main(){
    string s;
    cin>>s;

    int n=s.size();
    vector<int> ans(n);

    int cnt=0;
    rep(i,n){
        if(s[i]=='R') cnt++;
        else{
            ans[i]+=cnt/2;
            ans[i-1]+=(cnt+1)/2;
            cnt=0;
        }
    }

    cnt=0;
    for(int i=n-1;i>=0;i--){
        if(s[i]=='L') cnt++;
        else{
            ans[i]+=cnt/2;
            ans[i+1]+=(cnt+1)/2;
            cnt=0;
        }
    }

    rep(i,n) cout<<ans[i]<<" ";
    cout<<endl;
}


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

namespace FibonacciSample
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            var A = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var B = Console.ReadLine().Split().Select(int.Parse).ToArray();

            // 下から順番に倒せるだけ倒す
            int remainPower = 0;
            long killCnt = 0;
            for (int i = 0; i < n; i++)
            {
                //killCnt += Math.Min(A[i], B[i]);
                if (A[i] < B[i] + remainPower)
                {
                    killCnt += A[i];
                    remainPower = B[i] - Math.Max(A[i] - remainPower, 0);
                }
                else
                {
                    // A[i] >= B[i] + remainPower
                    killCnt += B[i] + remainPower;
                    remainPower = 0;
                }

                if (i + 1 == n && remainPower > 0) killCnt += Math.Min(remainPower, A[i + 1]);

                // 1. B[i] + remainPower ( A[i] >= ( B[i] + remainPower))
                // 2. A[i] ( A[i] < (B[i] + remainPower) )
                // 2.の場合remainPowerにB[i] - (A[i] - remainPower)を代入し、次回に持ち越す
                // 1.の場合はremainPowerを0にする
            }

                Console.WriteLine(killCnt);

        }

    }
}


Measured memory_bytes: 38212
#include <bits/stdc++.h>
using namespace std;
typedef long int li;
typedef long long ll;

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

    ll a, b, c, k; cin >> a >> b >> c >> k;

    if (a<k) {
        if (b<(k-a)) {
            cout << a - (k - a - b) << "\n";
            return 0;
            
        }
        else{
            cout << a << "\n";
            return 0;
        }
    }

    else cout << k << "\n";

    return 0;
}

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

int i = 0,j = 0,k = 0;
#define INT             long long
#define mod             1000000007
#define inf             (int)1e18
#define endl            "\n"
#define FOR(a, b)       for (int i = a; i < b;i++)
#define inpArr(vec)          for(auto &it:vec) cin>>it
#define outArr(vec)          for(auto &it:vec) cout<<it<<" ";cout<<endl;
#define read(n) 			INT n;cin >> n;
#define readTwo(x, y) 		INT x, y;cin>>x>>y;
#define readThree(x, y, z) 	INT x, y, z;cin>>x>>y>>z;
#define readFour(x, y, z,a) INT x, y, z, a;cin>>x>>y>>z>>a;

using namespace std;
int sol(int x){
	int count = 0;
	int i = 1;
	int flag = 0;
	while(i*i<=x){
		if(x%i==0){
			if(i==x/i)
				flag = 1;
			count++;
		}
		i++;
	}
	if (flag){
		return 2 * count - 1;
	}
	return 2 * count;
}
void solve(){
	read(n);
	INT ans = 0;
	for (int i = 1; i < n; i++)
	{
		ans += sol(i);
	}
	cout << ans << endl;
}

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

int t=1;
// cin >> t;
while(t--){
	solve();
}

return 0;
	
}

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

int dp[3001][3001];

int main(){
	string s,t,r="";
	cin >> s >> t;
	int n=s.length();
	int m=t.length();
	for(int i=0;i<=n;i++)
		dp[i][0]=0;
	for(int i=1;i<=m;i++)
		dp[0][i]=0;
	for(int i=1;i<=s.length();i++){
		for(int j=1;j<=t.length();j++){
			if(s[i-1]==t[j-1])
				dp[i][j]=dp[i-1][j-1]+1;
			else
				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
		}
	}
	//cout<<dp[n][m];
	while(n&&m){
		if(dp[n][m]==dp[n-1][m])
			n--;
		else if(dp[n][m]==dp[n][m-1])
			m--;
		else{
			r=s[n-1]+r;
			n--;
			m--;
		}
	}
	cout<<r;
}


Measured memory_bytes: 38800
#include <bits/stdc++.h>
#pragma GCC optimize ("O3,unroll-loops")
#define f first
#define s second
#define ri register int
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using vi = vector<int>;
using ii = pair<int, int>;
using vii = vector<ii>;
#define MAXN 100000
vi G[MAXN];
int path[MAXN];
void dfs(int v) {
	int max_path = 0;
	path[v] = 0;
	for(int u : G[v]) {
		if(path[u] == -1)
			dfs(u);
		max_path = max(max_path, path[u]);
	}
	if(!G[v].empty())
		path[v] = 1 + max_path;
}
int main() {
	ios_base :: sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int n, m;
	cin >> n >> m;
	for(int k = 0; k < n; ++k)
		path[k] = -1;
	for(int k = 0; k < m; ++k) {
		int u, v;
		cin >> u >> v;
		G[u - 1].push_back(v - 1);  
	}
	for(int k = 0; k < n; ++k) {
		if(path[k] == -1)
			dfs(k);
	}
	cout << *max_element(path, path + n) << '\n';
    return 0;
}

Measured memory_bytes: 8192
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <cassert>
#define REP(i,n) for(long (i)=0;(i)<(n);(i)++)
#define REPI(i,a,b) for(long (i)=(a);(i)<(b);(i)++)
#define INF numeric_limits<double>::infinity()
constexpr long MOD = 998244353;
using namespace std;
using P = pair<long, long>;
using VI = vector<long>;

int main() {
    long n, k;
    cin >> n >> k;
    VI as;
    REP(i,n) {
        long a;
        cin >> a;
        as.push_back(a);
    }
    
    long maxscore = 0;
    long rangesum = 0;
    for (int i = 0; i < k; i++) {
        rangesum += as[i];
    }
    long selectable = 0;
    for (int i = k; i < n; i++) {
        if (as[i] > 0) selectable += as[i];
    }
    maxscore = max({maxscore, rangesum + selectable, selectable});
    for (int i = 1; i < n - k + 1; i++) {
        rangesum += -as[i - 1] + as[i + k - 1];
        if (as[i - 1] > 0) selectable += as[i - 1];
        if (as[i + k - 1] > 0) selectable -= as[i + k - 1];
        maxscore = max({maxscore, rangesum + selectable, selectable});
    }
    
    cout << maxscore << endl;
}


Measured memory_bytes: 1400
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 300000
#define mod 1000000007
#define INF2 10000000000000000
#define int long long
int A[100010];
int N, M;
int sum[100010];
bool isOk(int x) {
    int cnt = 0;
    rep(i, N) {
        cnt += A + N - lower_bound(A, A + N, x - A[i]);
    }
    return cnt >= M;
}

int binary_search() {
    int ok = 0;
    int ng = INF;
    while(abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;
        if(isOk(mid)) ok = mid;
        else ng = mid;
    }
    int ret = 0;
    int cnt = M;
    rep(i, N) {
        int idx = A + N - lower_bound(A, A + N, ok - A[i]) - 1;
        if(idx >= 0) {
            ret += sum[idx] + A[i] * (idx + 1);
            cnt -= idx + 1;
            //cout << ret << " " << cnt << " " << sum[idx] << " " << A[i] * idx << " " << idx << endl;
        }
    }
    //cout << cnt << " " << ret << endl;
    return ret + cnt*ok;
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin >> N >> M;
    
    rep(i, N) cin >> A[i];
    sort(A, A + N, greater<int>());
    rep(i, N) sum[i] = A[i];
    rep(i, N) sum[i + 1] += sum[i];
    sort(A, A + N);
    cout << binary_search() << endl;
    

    return 0;
}
//   34 33 19 14 10
//34 68 67 53 48 44
//33 67 66 52 47 43
//19
//14
//10


Measured memory_bytes: 1792
import math
N = input()
pnum_count = N
for _ in range(N):
    n = input()
    if n == 2:
        continue
    if n % 2 == 0:
        pnum_count -= 1
        continue
    i = 2
    while i <= math.sqrt(n):
        if n % i == 0:
            pnum_count -= 1
            break
        i += 1
print pnum_count

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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

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


lli d[100100];

void func(long long N, std::vector<long long> A){

    for(lli i=N;i>0;i--){
        d[i-1] = d[i]+A[i];
    }

    lli now = 1;
    lli ans = 0;
    REP(i,0,N+1){
        LOG4(i,now,ans,d[i]);
        ans += now;
        now -= A[i];
        if(now<0){
            cout<<-1<<endl;
            return;
        }
        now = min(now*2,d[i]);
    }
    ans += now;
    cout<<ans<<endl;

}

int main(){
    // cout << fixed << setprecision(5);

    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N-0+1);
    for(int i = 0 ; i < N-0+1 ; i++){
        scanf("%lld",&A[i]);
    }
    func(N, std::move(A));
    return 0;
}


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

class Main {

	void solve () {

		int a = in.nextInt(), b = in.nextInt();
		if (a <= 9 && b <= 9) System.out.println(a*b);
		else System.out.println(-1);
		
	}

	public static PrintWriter out = new PrintWriter(System.out);
	public static Scanner in = new Scanner(System.in);
	public static void main(String[] args) {
		new Main().solve();
		out.flush();
	}

}

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

int main() {
    int a, b;
  	char op;
  	for(int i=0;i<1000;){
  	cin >> a >> op >> b;
      if(op == '+')cout << a + b << endl;
      if(op == '-')cout << a - b << endl;
      if(op == '*')cout << a * b << endl;
      if(op == '/')cout << a / b << endl;
      else if(op == '?') break;
    }
}


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

int main() {
	long long N, M, A, ANS = 0;
	priority_queue<long long> PQ;
	cin >> N >> M;
	for (int i = 0; i < N; i++) cin >> A, PQ.push(A);
	for (int i = 0; i < M; i++) {
		long long X = PQ.top();
		PQ.pop();
		X /= 2;
		PQ.push(X);
	}
	for (int i = 0; i < N; i++) {
		long long X = PQ.top();
		ANS += X;
		PQ.pop();
	}
	cout << ANS << endl;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll inf = 1e9;
int pre[200010];
vector<int> G[200010];
int d[200010];

int n,m;

int main() {
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int a,b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    for (int i = 1; i <= n; i++) d[i] = inf;
    d[1] = 0;
    priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> pq;
    pq.push({0,1});
    while (!pq.empty()) {
        pair<int,int> tp = pq.top();
        pq.pop();
        int v = tp.second;
        int dd = tp.first;
        if (dd > d[v]) continue;
        for (int i = 0; i < G[v].size(); i++) {
            int to = G[v][i];
            if (d[to] > d[v] + 1) {
                d[to] = d[v] + 1;
                pre[to] = v;
                pq.push({d[to], to});
            }
        }
    }
    for (int i = 2; i <= n; i++) {
        if (d[i] == inf) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    for (int i = 2; i <= n; i++) {
        cout << pre[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 13424
#include <stdio.h>
#include <stdlib.h>
 
int main()
{
    int r, c, i, j, x;
    int **s;
    scanf("%d %d", &r, &c);
    s = (int**)malloc((r+1)*sizeof(int*));
    *s = (int*)malloc((r+1)*(c+1)*sizeof(int));
    for(i=1; i<=r; i++) s[i] = *s + (c+1)*i;
 
    for(i=0; i<r; i++) {
        for(j=0; j<c; j++) {
            scanf("%d", &s[i][j]);
        }
    }
 
    for(j=0; j<c; j++) {
        s[r][j] = 0;
        for(i=0; i<r; i++) {
            s[r][j] += s[i][j];
        }
    }
    for(i=0; i<=r; i++) {
        s[i][c] = 0;
        for(j=0; j<c; j++) {
            s[i][c] += s[i][j];
        }
    }
 
    for(i=0; i<=r; i++) {
        for(j=0; j<c; j++) {
            printf("%d ", s[i][j]);
        }
        printf("%d\n", s[i][c]);
    }
 
    free(*s);
    free(s);
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
using namespace std;

int main(){
	long Q,H,S,D,N;
	cin >> Q >> H >> S >> D >> N;

	double ql = 0.25,
		   hl = 0.5,
		   sl = 1,
		   dl = 2;

	vector<long> l1 = {Q*4, H*2, S};
	vector<long> l2 = {Q*8, H*4, S*2, D};
	sort(l1.begin(), l1.end());
	sort(l2.begin(), l2.end());

	double nowl = 0;
	long nowM = 0;

	while(nowl <= N-2){
		nowl += 2;
		nowM += l2[0];
		//cout << nowl << ":" << nowM << endl;
	}

	if(N%2 == 1){
		nowM += l1[0];
	}
	cout << nowM << endl;
}


Measured memory_bytes: 888
/*****************************************************/
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <cstdlib>
#include <iostream>
#include <algorithm>

using namespace std;

#define   offcin        ios::sync_with_stdio(false)
#define   DEBUG         freopen("#.txt", "r", stdin)
#define   sigma_size    26
#define   lson          l,m,v<<1
#define   rson          m+1,r,v<<1|1
#define   slch          v<<1
#define   srch          v<<1|1
#define   ll            long long
#define   ull           unsigned long long
#define   lowbit(x)     (x&-x)

const int    INF    = 0x3f3f3f3f;
const ll     INFF   = 1e18;
const double pi     = acos(-1.0);
const double inf    = 1e18;
const double eps    = 1e-9;
const ll     mod    = 1e9+7;
const int    maxmat = 10;
const ull    BASE   = 133333331;

/*****************************************************/
inline void RI(int &x) {
      char c;
      while((c=getchar())<'0' || c>'9');
      x=c-'0';
      while((c=getchar())>='0' && c<='9') x=(x<<3)+(x<<1)+c-'0';
}
inline ll bits(ll x) {
      return !x ? x : bits(x - lowbit(x)) + 1;
}
/*****************************************************/

int main(int argc, char const *argv[]) {
    char a, b;
    cin>>a>>b;
    if (a == 'H') cout<<b<<endl;
    else {
        if (b == 'H') cout<<"D"<<endl;
        else cout<<"H"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define double long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define pii pair<int,int>
#define ff first
#define ss second
#define frr(i,n) for(int i=0;i<n;i++)
#define td(v) v.begin(),v.end()
#define inf 1000000000 // 1e9
#define M   1000000007 // 1e9 + 7
using namespace std;
inline int mod(int n, int m){ int ret = n%m; if(ret < 0) ret += m; return ret; }
int gcd(int a, int b){return (b == 0 ? a : gcd(b, a%b));}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int exp(int a,int b,int m){
    if(b==0) return 1;
    if(b==1) return mod(a,m);
    int k = mod(exp(a,b/2,m),m);
    if(b&1){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);
}
int dp[101][100011];
int n,k;
vector<int> a;
int32_t main(){
    fastio;
    cin >> n >> k;
    a.resize(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    if(n==1){
        cout << (a[0] == k) << endl;
        return 0;
    }
    ms(dp,0);
    for(int i=0;i<=k;i++){
        dp[0][k-i] = 1+dp[0][k-i+1];
        if(i>a[0]) dp[0][k-i]--;
        dp[0][k-i] = mod(dp[0][k-i],M);
    }
    
    for(int i=1;i<n;i++){
        for(int j=0;j<=k;j++){
            if(j > a[i]){
                dp[i][k-j] = mod(dp[i-1][k-j] - dp[i-1][k-j+a[i]+1],M);
            }
            else{
                dp[i][k-j] = dp[i-1][k-j];
            }
            
        }
        if(i==n-1){
            cout << dp[i][0] << endl;
            return 0;
        }
        for(int j=1;j<=k;j++){
            dp[i][k-j] = mod(dp[i][k-j] + dp[i][k-j+1],M);
        }
    }
}

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

int main() {
  int N;
  cin >> N;
  
  int A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  bool flag = false;
  
  for (int i = 0; i < N; i++) {
    if (A[i] % 2) continue;
    if (A[i] % 3 == 0 || A[i] % 5 == 0) {
      continue;
    } else {
      flag = true;
      break;
    }
  }
  
  if (flag) {
    cout << "DENIED" << endl;
  } else {
    cout << "APPROVED" << endl;
  }
}

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


int main()
{
  	int A, B;
	cin >> A >> B;
	if (A >= 13){
		cout << B << endl;
		return 0;	
	}
	else if (A < 6){
		cout << 0 << endl;
		return 0;	
	}
	else{
		cout << B/2 << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
N, M, C = tuple(map(int, input().split()))
b_list = list(map(int, input().split()))
a_list = [list(map(int, input().split())) for _ in range(N)]
correct = 0
for a in a_list:
  mul = sum([x * y for x, y in zip(b_list, a)])
  if mul + C > 0:
    correct += 1
print(correct)

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <cassert>
#include <random>
#include <time.h>
#include <unordered_set>
//#include <boost/multiprecision/cpp_int.hpp>



using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const double EPS = 1e-10;
long long const MOD = 998244353;

long long mod_pow(long long x, long long n) {
    long long res = 1;
    for (int i = 0;i < 60; i++) {
        if (n >> i & 1) res = res * x % MOD;
        x = x * x % MOD;
    }
    return res;
}

template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

void fastInput() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int main(void) {
    int N; cin >> N;
    string s; cin >> s;
    if (N%2) {
        cout << "No" << endl;
        return 0;
    } else {
        int n = N/2;
        for (int i = 0; i < n; i++) {
            if (s[i] != s[n+i]) {
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
    }
}




Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    char s[100];
    cin >> s;
    int n = strlen(s);
    for(int i = 0;i < n;i++)
    {
        if(s[i] == 'h' && s[i+1] == 'i')
        {
            i++;
        }
        else
        {
            cout << "No" << endl;
            return 0;
        }

    }
    cout << "Yes" << endl;
    return 0;

}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading;

using Pair = System.Collections.Generic.KeyValuePair<int, int>;

class Program
{
	public Program() { }

	static void Main(string[] args)
	{
		new Program().prog();
	}
	Scanner cin;
	const int MOD = 1000000007;
	const int INF = int.MaxValue - 10;
	const long INFL = long.MaxValue - 10;
	const double EPS = 1e-7;
	const double PI = 3.1415926536;

	int N;

	void prog()
	{
		cin = new Scanner();
		int[,] dir8 = new int[8, 2] { { -1, -1 }, { -1, 0 }, { -1, 1 }, { 0, -1 }, { 0, 1 }, { 1, -1 }, { 1, 0 }, { 1, 1 } };
		int[,] dir4 = new int[4, 2] { { -1, 0 }, { 0, -1 }, { 0, 1 }, { 1, 0 } };

		int H = cin.nextInt();
		int W = cin.nextInt();
		for (int i = 0; i < H; i++)
		{
			for (int j = 0; j < W; j++)
			{
				string s = cin.next();
				if (s == "snuke")
				{
					Console.Write((char)('A'+j));
					Console.WriteLine(i+1);
					return;
				}
			}
		}
	}
}

class Scanner
{
	string[] s;
	int i;

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

	public Scanner()
	{
		s = new string[0];
		i = 0;
	}

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

	public int nextInt()
	{
		return int.Parse(next());
	}

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

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

Measured memory_bytes: 2904
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;

 
int main() {
  string s,t;
  cin >> s >> t;
  int n = s.size(),m = t.size();
  string ans = "UNRESTORABLE";
  rep(i,n-m+1){
    bool ok = true;
    string now = "";
    rep(j,n){
      if(j < i){
        if(s.at(j) == '?') now += "a";
        else now += s.at(j);
      }
      else if(j < i + m){
        if(s.at(j) == t.at(j-i)){
          now += s.at(j);
        }else if(s.at(j) == '?'){
          now += t.at(j-i);
        }else{
          ok = false;
          break;
        }
      }else{
        if(s.at(j) == '?') now += "a";
        else now += s.at(j);
      }
    }
    if(ok && ans == "UNRESTORABLE") ans = now;
    else if(ok) ans = min(ans,now);
  }
  
  cout << ans << endl;   

  return 0;
}



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

typedef long long ll;

using namespace std;

int N;

struct Edge {
    int to, weight;
};
vector< vector<Edge> > adj;
vector<bool> Nodes;

bool vis[200000];
void dfs(int src, bool color){
	vis[src] = 1;
	Nodes[src] = color;
	for(auto v : adj[src]){
		if(!vis[v.to]){
			if(v.weight % 2 == 0){
				//cout << src << " " << v.to << " "  << color << " " << v.weight << endl;
				dfs(v.to, color);
			}else{
				//cout << src << " " << v.to << " "  << color << " " << v.weight << endl;
				dfs(v.to, !color);
			}
		}
	}
}

int main(){
	cin >> N;
	adj = vector< vector<Edge> >(N + 1);
	Nodes = vector<bool>(N + 1);
	for(int i = 0; i < N - 1; i ++){
		int u, v, w;
		cin >> u >> v >> w;
		adj[u].push_back({v, w});
		adj[v].push_back({u, w});
	}
	dfs(1, 0);
	for(int i = 1; i <= N; i++){
		cout << Nodes[i] << endl;
	} 
	return 0;
}

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

const int INF = 1001001001;

int main(){
    string s;
    cin >> s;
    vector<int> ans(s.size(),0);
    int rtmp, ltmp;
    int rl = s.find("RL");
    int lr = s.find("LR");
    rl++, lr++;
    if(lr == 0){
        lr = s.size();
    }
    if(rl % 2 == 1){
        ans[rl-1] += 1;
    }
    if((lr-rl)%2 == 1){
        ans[rl] += 1;
    }
    ans[rl-1] += (rl / 2 + (lr-rl) / 2);
    ans[rl] +=  (rl / 2 + (lr-rl) / 2);
    if(lr != 0){
        while(true){
            int searchNum = lr;
            rl = s.find("RL", searchNum);
            lr = s.find("LR",searchNum);
            rl++, lr++;
            if(rl == 0)break;
            rtmp = rl-searchNum;
            if(lr == 0){
                ltmp = s.size() - searchNum;
            }else{
                ltmp = lr - searchNum;
            }
            if(rtmp % 2 == 1){
                ans[rl-1] += 1;
            }
            if((ltmp-rtmp) % 2 == 1){
                ans[rl] += 1;
            }
            ans[rl-1] += (rtmp / 2 + (ltmp-rtmp) / 2);
            ans[rl] +=  (rtmp / 2 + (ltmp-rtmp) / 2);
            if(lr == 0)break;
        }
    }
    for(int i = 0;i < s.size(); i++){
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
using P = pair<int, int>;
template<typename T, typename U>
istream& operator>>(istream& in, pair<T, U>& p) {
    in >> p.first >> p.second;
    return in;
}
int gcd(int a,int b){
    if(a%b==0)return b;
    return gcd(b,a%b);
}
signed main(signed argc, char* argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    const int MOD = 1e9+7;
    int n,m;
    string s,t;
    cin>>n>>m>>s>>t;
    int l=n*m/gcd(n,m);
    map<int,char> x;
    rep(i,n){
        x[l/n*i]=s[i];
    }
    rep(i,m){
        if(x.count(l/m*i)&&x[l/m*i]!=t[i]){
            cout<<-1<<endl;
            return 0;
        }
    }
    cout<<l<<endl;
}


Measured memory_bytes: 6144
N, M = list(map(int, input().split()))
st = [list(map(int, input().split())) for _ in range(M)]

R = {}
for s, t in st:
  s -= 1
  t -= 1
  if s in R:
    R[s].append(t)
  else:
    R[s] = [t]

DP = [0] * N
ans = N
D = [0] * N
for i in range(N - 2, -1, -1):
  ma = 0
  su = 0
  le = len(R[i])
  for j in R[i]:
    su += DP[j]
    ma = max(ma, DP[j])

  DP[i] = su / le + 1 
  if le == 1:
    D[i] = 0
  else:
    D[i] = DP[i] - (((su - ma) / (le - 1)) + 1)

P = [0] * N 
P[0] = 1
ma = 0
man = -1
for i in range(N - 1):
  t = P[i] / len(R[i])
  for j in R[i]:
    P[j] += t 
  t = P[i] * D[i]
  R[i].sort()
  if ma < t:
    ma = t
    man = i
 
if ma == -1:
  print(DP[0])
else:
  print(DP[0] - ma)


Measured memory_bytes: 48444
#pragma GCC diagnostic ignored "-Wunused-result"
#define NDEBUG

#include <algorithm>
#include <cassert>
#include <cinttypes>
#include <cstdio>
#include <vector>
#include <tuple>

#ifdef NDEBUG
#  define debug(...)
#else
#  define debug(...)                                \
  do {                                              \
    fprintf(stderr, "%s:%d: ", __FILE__, __LINE__); \
    fprintf(stderr, __VA_ARGS__);                   \
    fputc('\n', stderr);                            \
  } while (false)
#endif

using namespace std;

int main() {
  int L;
  scanf("%d", &L);
  int r = 0;
  while (1<<(r+1) <= L) r++;
  const int N = r + 1;
  vector<tuple<int, int, int>> edges;
  for (int i = 1; i <= N-1; i++) {
    edges.emplace_back(i, i+1, 0);
    edges.emplace_back(i, i+1, 1<<(i-1));
  }
  for (int t = N-1; t > 0; t--) {
    int L0 = L - (1<<(t-1));
    if (L0 >= 1<<r) {
      edges.emplace_back(t, N, L0);
      L = L0;
    }
  }
  printf("%d %lu\n", N, edges.size());
  for (auto & uvw: edges) {
    int u, v, w;
    tie(u, v, w) = uvw;
    printf("%d %d %d\n", u, v, w);
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using lint=int64_t;
using namespace std;

const lint INF=1e18;

int main()
{
	lint N;

	cin >> N;

	lint ans=INF;
	for(lint i=1;i*i<=N;i++)
	{
		if(N%i==0)
		{
			ans=min(ans,i-1+N/i-1);
		}

	}

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



Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int N,M;
  cin >> N >> M;
  vector<int> a(M);
  vector<int> b(M);
  vector<vector<int>> c(M);
  vector<bool> canopen(N,false);
  rep(i,M){
    cin >> a[i] >> b[i];
    c[i].resize(b[i]);
    rep(j,b[i]){
      cin >> c[i][j];
      c[i][j]--;
      canopen[c[i][j]] = true;
    }
  }
  rep(i,(int)canopen.size()){
    if(canopen[i] == false){ cout << -1 << endl; return 0; }
  }
  vector<vector<int>> dp(M,vector<int>(pow(2,N), 1e9));
  rep(i,M) dp[i][0] = 0;
  rep(i,pow(2,N)){
    if(i==0) continue;
    int num = 0;
    rep(j,b[0]) num += pow(2,c[0][j]);
    //cout << num << endl;
    if((i|num) <= num) dp[0][i] = a[0];
  }
  /*
  rep(i,M){
    rep(j,pow(2,N)){
      cout << dp[i][j] << " ";
    }
    cout << endl;
  }
  */

  for(int i=1;i<M;i++){
    rep(j,(int)dp[i].size()) dp[i][j] = dp[i-1][j];
    int num = 0;
    rep(j,b[i]) num += pow(2,c[i][j]);
    rep(j,(int)dp[i].size()){
      dp[i][j|num] = min(dp[i][j|num], dp[i-1][j] + a[i]);
    }
  }
  /*
  rep(i,M){
    rep(j,pow(2,N)){
      cout << dp[i][j] << " ";
    }
    cout << endl;
  }
  */
  cout<< dp[M-1][pow(2,N)-1] << endl;

  return 0;
}


Measured memory_bytes: 16384
import Data.Vector.Unboxed ((!),unfoldr,elemIndex,iterateN)
import qualified Data.ByteString.Lazy.Char8 as C
import Data.Maybe

main = C.interact $ put . sol . get

get = unfoldr (C.readInt . C.dropWhile (<'0'))

put = C.pack . show

sol v = fromMaybe (-1) . elemIndex 2 $ iterateN (v!0) (v!) 1

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

using namespace std;

#define Rep(b, e, i) for (int i = b; i <= e; i++)
#define Repr(e, b, i) for (int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n - 1, i)
#define repr(n, i) Repr(n - 1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)), (v).end())
#define bitcnt(x) __builtin_popcount(x)
#define fst first
#define snd second
#define Pqaz(T) priority_queue<T, vector<T>, greater<T>>
#define Pqza(T) priority_queue<T>
#define put(x) cout << x;
#define putsp(x) cout << x << ' ';
#define putbd cout << "---------------------------------------------" << endl;
#define putln(x) cout << x << endl;
#define debug(x) cerr << #x << "=" << x << endl;
#define ENJYU std::ios::sync_with_stdio(false) std::cin.tie(0);

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef complex<double> comp;
typedef vector<int> vec;
typedef vector<ll> vecll;
typedef vector<double> vecd;
typedef vector<vec> mat;
typedef vector<vecll> matll;
typedef vector<vecd> matd;

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

const int MAX = 200020;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1 << 29;
const ll INFL = 1e18;
const ll MOD = 1000000007;

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

//********************************template END****************************************//

void solve()
{
	int N, M, K;
	cin >> N >> M >> K;
	Rep(0, N, n) Rep(0, M, m)
	{
		int b = n * M + m * N - 2 * m * n;
		if (b == K)
		{
			cout << "Yes" << endl;
			return;
		}
	}
	cout << "No" << endl;
}

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 256
N,T=map(int,input().split())
c=[list(map(int,input().split())) for i in range(N)]
mincost=10**5
for i in range(N):
    if c[i][1]>T:
        continue
    else:
        if c[i][0]<mincost:
            mincost=c[i][0]
print(mincost if mincost!=10**5 else 'TLE')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

int n;
vector <int> a, b;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    a.resize(n);
    b.resize(n);
    bool ok = 1;
    for(int i = 0 ; i < n ; i++){
        cin >> a[i] >> b[i];
        ok &= a[i] == b[i];
    }
    if(ok) finish(0);
    ll sum = 0;
    for(auto &i : a) sum += i;
    ll ans = 0;
    for(int i = 0 ; i < n ; i++){
        if(b[i] < a[i]){
            ans = max(ans, sum - b[i]);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3776
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define INF 10000000000000
#define MOD 1000000007LL
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
// input vector
template<typename T>
void invec(vector<T> &A){for(T& a : A) cin >> a;}


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

int N; 
string S;
cin >> N >> S;

int cnt = 0;
rep(i, 0, N-2)
    if (S.substr(i, 3) == "ABC") ++cnt;

cout << cnt << "\n";

}
// 書いて考える．場合分け
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，次にDP
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性，二分探索
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり
// 実行エラー：vector添え字超え．0割り．



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using ll = long long;
int main() {
    int x; cin >> x;
    if(x >= 30) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
int main(){
  while (1){
    string s;
    cin >> s;
    if (s == "#"){
      break;
    }
    int n = s.size();
    reverse(s.begin(), s.end());
    int num = 0;
    int denom = 1;
    if (s[3] == 'w'){
      num = 90;
    }
    for (int i = 5; i < n; i++){
      if (s[i] == 'n'){
        num = num * 2 - 90;
        denom *= 2;
      }
      if (s[i] == 'w'){
        num = num * 2 + 90;
        denom *= 2;
      }
    }
    while (num % 2 == 0 && denom % 2 == 0){
      num /= 2;
      denom /= 2;
    }
    if (denom == 1){
      cout << num << endl;
    } else {
      cout << num << '/' << denom << endl;
    }
  }
}


Measured memory_bytes: 3220
process.stdin.resume();
process.stdin.setEncoding('utf8');

// 標準入力取込
let gInput = '';
process.stdin.on('data', (chunk) => (gInput += chunk));
process.stdin.on('end', () => main(gInput.split(/\r?\n/)));

// 解答
function main(inputs: string[]): void {
  const str: string[] = inputs[0].split(' ');

  changeStr(str, 0, 1);
  changeStr(str, 0, 2);

  console.log(str.join(' '));
}

function changeStr(str: string[], index1: number, index2: number): string[] {
  let temp = str[index1];
  str[index1] = str[index2];
  str[index2] = temp;

  return str;
}


Measured memory_bytes: 7500
#include<stdio.h>

#define	LIM		(100000+1)
#define MAX(NUM,NUM2)	(((NUM)>(NUM2))?(NUM):(NUM2))

int GCD(int x, int y)
{
  if(y==0)
    return x;
  else
	return GCD(y, x%y);
}

int main(void)
{
  unsigned int n, a[LIM], r[LIM]={}, l[LIM]={};
  int i;
  unsigned int ans = 1;
  
  scanf("%d", &n);

  for(i=0; i<n; i++){
	scanf("%d", &a[i]);
    r[i+1] = GCD(a[i], r[i]);
  }
  
  for(i=n-1; i>0; i--)
	l[i-1] = GCD(a[i], l[i]);

  for(i=0; i<n; i++)
	ans = MAX(ans, GCD(r[i], l[i]));
    
  printf("%d\n", ans);
  
  return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ll n,w;
	cin>>n>>w;
	ll wt[n];
	ll val[n];
	for(ll i=0;i<n;i++)
	cin>>wt[i]>>val[i];
	ll va=*max_element(val,val+n);
	ll max_val=accumulate(val,val+n,0);
	ll dp[n+5][n*va+5];
	dp[0][0]=0;
	for(ll i=1;i<=max_val;i++)
	dp[0][i]=1e18;
	ll ans=0;
	for(ll i=0;i<n;i++)
	{
		for(ll j=0;j<=max_val;j++)
		{
			if(j>=val[i])
			dp[i+1][j]=min(dp[i][j],dp[i][j-val[i]]+wt[i]);
			else
			dp[i+1][j]=dp[i][j];
			if(dp[i+1][j]<=w)
			ans=max(ans,j);
		}
	}
	cout<<ans<<"\n";
	return 0;
}


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

int main() {
    int N;
    cin >> N;
    vector<int> L(N);
    for(int i = 0;i < N;i++){
        cin >> L.at(i);
    }
    int sum = 0;
    for(int c : L) {
        sum += c;
    }
    sort(L.begin(), L.end());
    if(2 * L.at(N - 1) < sum){
        cout << "Yes" << endl;
    }else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int N = 9e4;
const int K = 15;
int n , k;
int arr[K];
int inp;
int a[N];
int cur;
bitset < N > dp;
bool allowed(int num){
	while(num){
		if(!arr[num % 10]){
			return 0;
		}
		num /= 10;
	}
	return 1;
}
int main(){
	cin >> n >> k;
	for(int i = 0 ; i < K ; ++i){
		arr[i] = 1;
	}
	for(int i = 1 ; i <= k ; ++i){
		cin >> inp;
		arr[inp] = 0;
	}
	cur = 0;
	int big;
	for(int i = n ; i < N ; ++i){
		if(allowed(i)){
			big = i;
			break;
		}
	}
	printf("%d\n" , big);
}

Measured memory_bytes: 256
#include<stdio.h>

void trace(int A[],int N)
{
  int i;
  for(i = 0 ; i < N ; i++)
    {
      if(i > 0)printf(" ");
      printf("%d", A[i]);
    }
  printf("\n");
}


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

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

  trace(A,N);
  insertionSort(A,N);
  
  return 0;
}

Measured memory_bytes: 604