akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
const Int MOD = 998244353;
template <class T> void chadd(T &x, T y) { x = (x + y) % MOD; }
Int dp[300000][3][3][2];
int main() {
    string S; cin >> S;
    if (S.size() <= 3) {
        set<string> se;
        stack<string> st;
        se.insert(S); st.push(S);
        while (!st.empty()) {
            auto s = st.top(); st.pop();
            for (int i = 0; i < s.size() - 1; i++) {
                if (s[i + 1] != s[i]) {
                    string t = s;
                    t[i] = t[i + 1] = 'a' ^ 'b' ^ 'c' ^ s[i] ^ s[i + 1];
                    if (se.count(t) == 0) {
                        se.insert(t);
                        st.push(t);
                    }
                }
            }
        }
        cout << se.size() << '\n';
    } else {
        int eql = 0, diff = 0;
        for (int i = 0; i < S.size() - 1; i++) {
            if (S[i] == S[i + 1]) eql++;
            if (S[i] != S[i + 1]) diff++;
        }
        if (diff == 0) {
            cout << 1 << '\n';
        } else {
            dp[1][0][0][0] = dp[1][1][1][0] = dp[1][2][2][0] = 1;
            for (int i = 1; i < S.size(); i++) {
                for (int j = 0; j < 3; j++) {
                    for (int k = 0; k < 3; k++) {
                        for (int l = 0; l < 2; l++) {
                            for (int m = 0; m < 3; m++) {
                                chadd(dp[i + 1][(j + m) % 3][m][min(1, l + (k == m))], dp[i][j][k][l]);
                            }
                        }
                    }
                }
            }
            Int ans = 0, sum = 0;
            for (int i = 0; i < S.size(); i++) {
                sum = (sum + S[i] - 'a') % 3;
            }
            for (int k = 0; k < 3; k++) {
                ans = (ans + dp[S.size()][sum][k][1]) % MOD;
            }
            cout << (ans + (eql == 0)) % MOD << '\n';
        }
    }
    return 0;
}


Measured memory_bytes: 31804
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REP1(i,n) for(int i = 1; i < n+1 ;i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
using namespace std;
typedef long long ll;

int main(){
    ll n,a,b;
    cin >> n >> a >> b;
    ll sum = a+b ;
    ll ans =  n/sum  * a;
    ll rem = n % sum;
    ans += min(rem,a);
    cout << ans << endl;
    return 0;




}

Measured memory_bytes: 256
k, x = map(int, input().split())

min_x = x - (k - 1)
max_x = x + k

ans_list = []

for i in range(min_x, max_x):
    ans_list.append(i)

ans_str = [str(a) for a in ans_list]
ans = " ".join(ans_str)
print(ans)

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

int gcd(int a, int b) {
  while (1) {
    a = a % b;
    if (a == 0) return b;
    b = b % a;
    if (b == 0) return a;
  }
};

int main() {
  int a, b;
  cin >> a >> b;

  cout << gcd(a, b) << endl;
};


Measured memory_bytes: 3100
#!/usr/bin/env pytHon3
# -*- coding: utf-8 -*-


def main():
    N = int(input())
    A = list(map(int, input().split()))

    s = [A[0]]

    for i in range(1, N):
        s.append(s[-1] + A[i])

    cnt_a = 0
    base = 0
    for i in range(N):
        if ((base + s[i] >= 0) and (i % 2 == 1)) \
                or ((base + s[i] <= 0) and (i % 2 == 0)):
            cnt_a += (1 + abs(base + s[i]))
            base += (1 + abs(base + s[i])) * (-1) ** i

    cnt_b = 0
    base = 0
    for i in range(N):
        if ((base + s[i] <= 0) and (i % 2 == 1)) \
                or ((base + s[i] >= 0) and (i % 2 == 0)):
            cnt_b += (1 + abs(base + s[i]))
            base -= (1 + abs(base + s[i])) * (-1) ** i

    print(min(cnt_a, cnt_b))


if __name__ == "__main__":
    main()


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

using namespace std;

int main(){
	int N, K, ans = 0; cin >> N >> K;
	bool A[N];
	fill(A, A + N, false);
	A[0] = true;
	for(int i = 0; i < N; ++i){
		int x; cin >> x;
	}
	int right = 0;
	while(1){
		if(right + K - 1 < N){
			fill(A, A + right, true);
			ans++;
		}else{
			ans++;
			break;
		}
		right += K - 1;
		if(right == N - 1) break;
	}
	cout << ans << endl;
}

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

int main() {
  int a,b,c;
  cin>>a>>b>>c;
  int d=max(a,b);
  int e=min(a,b);
  int f=d%e;
  while(f>1){
    int temp=e;
    e=f;
    d=temp;
    f=d%e;
  }
  if(f==1) cout<<"YES"<<endl;
  else {
    if(c%e==0) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long LL;

int n;
LL k, ans;
LL a[60], b[60], f[60];

int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) {
    LL x;
    cin >> x;
    for (int j = 0; j < 50; ++j) {
      a[j] += (~x >> j) & 1;
      b[j] += (x >> j) & 1;
    }
  }
  for (int i = 0; i < 50; ++i) {
    a[i] *= 1LL << i;
    b[i] *= 1LL << i;
  }
  f[0] = max(a[0], b[0]);
  for (int i = 1; i < 50; ++i) {
    f[i] = f[i - 1] + max(a[i], b[i]);
  }
  LL now = 0;
  for (int i = 49; ~i; --i) {
    if (k >> i & 1) {
      ans = max(ans, now + b[i] + (i? f[i - 1] : 0));
      now += a[i];
    } else {
      now += b[i];
    }
  }
  ans = max(ans, now);
  cout << ans << endl;
  return 0;
}


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

using namespace std;

int main() {
	string s,t;
	cin >> s >> t;
	sort(s.begin(),s.end());
	sort(t.begin(),t.end());
	reverse(t.begin(),t.end());
	bool ans = s < t;
	if (ans) {
		cout << "Yes";
	} else {
		cout << "No";
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl


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

    if(a>=30){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


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

int main(){
#ifdef _DEBUG
	freopen("in" , "r", stdin );
	freopen("out", "w", stdout);
#endif
	ios::sync_with_stdio(0); cin.tie(0);
	int n, k, x, y; cin >> n >> k >> x >> y;
	if(n <= k) cout << n * x << '\n';
	else cout << k * x + (n - k) * y << '\n';
}


Measured memory_bytes: 256
package main

import (
  "fmt"
)

func main()  {
    var a string
    var index int
    var alpha string
    alpha = "abcdefghijklmnopqrstuvwxyz"
    vv := make([]string,0)
    fmt.Scan(&a)
    for i :=0; i < len(alpha); i++ {
        ii := i+1
        // vv[i] = alpha[i:ii]
        z := alpha[i:ii]
        vv = append(vv, z)
    }
    for j, v2 := range vv{
        if v2 == a {
            index = j + 1
        }
    }
    index2 := index +1
    fmt.Println(alpha[index:index2])
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;


int main() {
  int n;
  cin >> n;
  if (n%2!=0) n*=2;
  cout << n << endl;
}


Measured memory_bytes: 256
n = int(input())
li = list(map(int,input().split()))
ans = 0
cnt_li = [0]*(10**6+1)

import math
import bisect
import collections
c = collections.Counter(li)
li = list(set(li))
li.sort()

for l in li:
    for x in range(2,10**7):
        if x*l > (10**6):
            break
        else:
            cnt_li[x*l] += 1


while len(li)>0:
    ba = li.pop(-1)
    if c[ba]>1:
        continue
    if cnt_li[ba] == 0:
        ans += 1
print(ans)


Measured memory_bytes: 164232
#include <stdio.h>
#include <math.h>

int main(void) {
	double height, width, depth, hw, wd, dh, size;
	int n;
	const char *answer[] = {"NA", "OK"};

	while (1) {
		scanf("%lf %lf %lf", &height, &width, &depth);
		if (height == 0.0)
			break;

		hw = hypot(height, width);
		wd = hypot(width, depth);
		dh = hypot(depth, height);

		scanf("%d", &n);

		while (n--) {
			scanf("%lf", &size);
			size += size;
			puts(answer[size > hw || size > wd || size > dh]);
		}
	}
	return 0;
}

Measured memory_bytes: 624
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

int main(void){
	          int i;

	      	  cin.tie(0);  ios_base::sync_with_stdio(false);

	      	  int N,M;
	      	  cin >> N >> M;

	      	  int T=1900*M+100*(N-M);

	      	  int r=1;
	      	  for(i=1;i<=M;i++) r=2*r;

	      	  cout << r*T << endl;


	          return 0;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  int H[N + 5], maxh = 0;
  for (int i = 0; i < N; i++) {
    cin >> H[i];
    if (H[i] > maxh)
    	maxh = H[i];
  }

  int count = 0;
  for (int h = 1; h <= maxh; h++) {
  	bool flag = false;
  	for (int i = 0; i < N; i++) {
  	  if (H[i] >= h) {
 	  		if (flag)
	  			continue;
  	  	flag = true;
  	  	count++;
  	  } else {
  	  	flag = false;
  	  }
  	}
  }

	cout << count << '\n';
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    double M = sc.nextInt();
    double sum = 0;
    int ans = 0;
    double x = (4 * M);
    int A[] = new int[N];
    for (int i = 0; i < N; i++) {
      A[i] = sc.nextInt();
      sum = sum + A[i];
    }
    double y = sum / x;
    for (int i = 0; i < N; i++) {
      if (A[i] >= y) {
        ans++;
      }
    }

    if (ans >= M) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}

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

int main() {
  
  int N; cin >> N; double ans = 0.0;
  
  for (int i = 0; i < N; i++) {
    double x; string u; cin >> x >> u;
    if (u == "JPY") ans += x;
    else ans += x * 380000.0;
  }
  
  cout << fixed << setprecision(10);
  
  cout << ans << endl;
  
}

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

class Main{

public static void main(String args[]) throws java.io.IOException{
Scanner scan = new Scanner(System.in);
while(scan.hasNext()){
long a =scan.nextLong();
long b = scan.nextLong();
System.out.println(gcd(a,b)+" "+(a*b)/gcd(a,b));
}


}
public static long gcd(long a,long b){
if(b==0)return a;
return gcd(b,a%b);
}
}

Measured memory_bytes: 12000
import numpy as np

n,m,q=map(int, input().split())  
a=[list(map(int, input().split())) for i in range(m)]
b=[list(map(int, input().split())) for i in range(q)]

x=np.zeros((501, 501), dtype=np.int)

for i in range(m):
    x[a[i][0], a[i][1]]+=1

np.cumsum(x, axis=0, out=x)
np.cumsum(x, axis=1, out=x)

for i in range(q):
    v1=b[i][0]
    v2=b[i][1]
    
    a1=x[v2, v2]
    a2=x[v2, v1-1]
    a3=x[v1-1, v2]
    a4=x[v1-1, v1-1]
    print(a1-a2-a3+a4)


Measured memory_bytes: 78460
// C - Walk on Multiplication Table
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
	ll N; cin>>N;
	ll a = sqrt(N) + 1;
	while(a>1) if(N%--a == 0) break;
	cout<< a + N/a - 2 <<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ull=unsigned long long;
#define mod 1000000007
#define mod2 998244353 
#define PI 3.14159265
#define ll long long
#define ld long double
#define pi pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define sz size()
#define setbits(x)  __builtin_popcount(x)
#define fi first
#define se second
#define lz length()
#define all(x) (x).begin(),(x).end()
#define scf(x) scanf("%lld",&x)
#define rep(i,n) for(ll i=0;i<n;i++)
const int INF = (int)1e9;
const ll IINF=1LL<<62;
const int maxn=10000005;

//int divr[maxn];
/**/
/*void divisor()
{for(int i=2;i<sqrt(maxn);i++)
     {
          if(!divr[i])
          {
               for(int j=i*i;j<maxn;j+=i)if(!divr[j])divr[j]=i;     
          }
     }
     for(int i=1;i<maxn;i++)if(!divr[i])divr[i]=i;
}*/
 
/*const int N=1000005;
ll n;
struct line {
    long long m, c;
    long long eval(long long x) { return m * x + c; }
    long double intersectX(line l) { return (long double) (c - l.c) / (l.m - m); }
};
vector<pair<pi,ll>> rect;
deque<line> dq;
*/
ll modexpo(ll a,ll b)
{
     ll ans=1LL;
     while(b>0)
     {
          if(b&1)ans=(ans*a)%mod;
          a=(a*a)%mod;
          b>>=1;
     }
     return ans;
}
 
 
 
 
 
 
 
int n,m;
int dp[205][205];
int R;
ll res;
bool used[9];
vector<int> r(9);
void dfs(int c,int last,ll dist){
     if(c==R+1){
          if(res>dist)res=dist;
          return ;
     }
     for(int i=1;i<=R;i++){
          if(!used[i]){
               used[i]=true;
               if(last==-1)dfs(c+1,i,0);
               else dfs(c+1,i,dist+dp[r[last]][r[i]]);
               used[i]=false;
          }
          
     }
}
int main()
{
     cin>>n>>m>>R;
     for(int i=1;i<=R;i++)cin>>r[i];
     for(int i=0;i<=200;i++)for(int j=0;j<=200;j++)dp[i][j]=1e9;
     for(int i=0;i<=200;i++)dp[i][i]=0;
     for(int i=0;i<m;i++){
          int a,b,c;
          cin>>a>>b>>c;
          if(dp[a][b]>c){
               dp[a][b]=c;
               dp[b][a]=c;
          }
               
     } 
     for(int k=1;k<=n;k++){
          for(int i=1;i<=n;i++){
               for(int j=1;j<=n;j++){
                    dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
               }
          }
     }
     res=1LL<<30;
     dfs(1,-1,0);
     cout<<res;
}























Measured memory_bytes: 3736
#define _GLIBCXX_DEBUG//TLEの原因になるので注意！！！！！！！！！！！
#include<cmath>
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.sise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
//#define int long long

//cerrはコメントアウトしなくても通る//ただしTLEを引き起こすことがある

//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
//const ll INF = 1LL << 60;
//typedef pair<ll,ll> P;
typedef pair<int, int> P;
bool chmx(int &a, int b) {
	if (b > a) {
		a = b;
		return true;
	}
	return false;
}

bool chmn(int &a, int b) {
	if (b < a) {
		a = b;
		return true;
	}
	return false;
}

//int dp[200005];//i桁目まで見たときの２０１９の倍数の総数
//int tt[200005];
int temp[2020];//あまりがiである場合の数
int temp2[2020];

int main(){
    string s;
    cin >> s;
    ll ans=0;
    int n=s.size();
    rep(i,n){
        int k=s[i]-'0';
        temp2[k]++;
        rep(j,2019){
            temp2[(j*10+k)%2019]+=temp[j];
        }
        rep(j,2019){
            temp[j]=temp2[j];
            temp2[j]=0;
        }
        ans+=temp[0];
        /*
        rep(i,2019){
            if(temp[i]>0){
                cerr<<i<<' '<<temp[i]<<endl;
            }
        }
        */
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 3752
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
#![macro_use]

use std::cmp::*;
use std::collections::*;
use std::io::*;
use std::mem::*;
use std::num::*;
use std::slice::*;

fn main() {
    let (r, w, e) = (stdin(), stdout(), stderr());
    let mut io = IO::new(r.lock(), w.lock(), e.lock());
    // =============================================== //

    let n: usize = io.read();
    let a = io.readn::<usize>(n);

    let mut cnt = vec![0usize; 4];
    for &i in a.iter() {
        cnt[i] += 1;
    }
    // dp[i][j][k]:  3個がi枚, 2個がj枚, 1個がk枚のときのサイコロをふる回数
    let mut dp = vec![vec![vec![0f64; 302]; 302]; 302];
    for i in 0..n + 1 {
        for j in 0..n + 1 {
            for k in 0..n + 1 {
                let count = i + j + k;
                if count == 0 {
                    dp[i][j][k] = 0f64;
                    continue;
                }
                dp[i][j][k] = n as f64 / count as f64;
                dp[i][j][k] += if i > 0 {
                    dp[i - 1][j + 1][k] * i as f64 / count as f64
                } else {
                    0f64
                };
                dp[i][j][k] += if j > 0 {
                    dp[i][j - 1][k + 1] * j as f64 / count as f64
                } else {
                    0f64
                };
                dp[i][j][k] += if k > 0 {
                    dp[i][j][k - 1] * k as f64 / count as f64
                } else {
                    0f64
                };
            }
        }
    }
    io.writeln(dp[cnt[3]][cnt[2]][cnt[1]]);
}

// IO
struct IO<R: Read, W: Write, E: Write> {
    Read: R,
    Write: BufWriter<W>,
    Error: BufWriter<E>,
}
impl<R: Read, W: Write, E: Write> IO<R, W, E> {
    fn new(r: R, w: W, e: E) -> IO<R, W, E> {
        IO {
            Read: r,
            Write: BufWriter::new(w),
            Error: BufWriter::new(e),
        }
    }
    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
    {
        let next: String = self
            .Read
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect();
        next.parse().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
    fn readn<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect::<Vec<_>>()
    }
    fn readmat<T: std::str::FromStr>(&mut self, n: usize, m: usize) -> Vec<Vec<T>> {
        (0..n).map(|_| self.readn(m)).collect()
    }
    fn write<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
    }
    fn writeln<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
        self.Write.write(b"\n");
    }
    fn debug<S: std::fmt::Debug>(&mut self, val: S) {
        writeln!(self.Error, "(debug ) {:?}", &val);
    }
    fn debug2<S: std::fmt::Debug, T: std::fmt::Debug>(&mut self, val1: S, val2: T) {
        writeln!(self.Error, "(debug2) {:?} -> {:?}", val1, val2);
    }
}


Measured memory_bytes: 239868
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;


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

	cin >> N;
	vector<long long int>v(N);
	for (int i = 0; i < N; i++) {
		cin >> v[i];
	}
	vector<long long int>w(v);
	for (int i = 0; i < N; i++) {
		w[i] = w[i] * MOD + i;
	}
	sort(w.begin(), w.end());
	vector<int>ans(N);
	for (int i = 0; i < N / 2; i++) {
		ans[w[i] % MOD] = w[N / 2] / MOD;
	}
	for (int i = N / 2; i < N; i++) {
		ans[w[i] % MOD] = w[N / 2-1] / MOD;
	}
	for (auto i : ans) {
		cout << i << endl;
	}
	return 0;
}


Measured memory_bytes: 6144
#include <iostream>
#include <vector>

int main() {
  long n;
  std::cin >> n;
  std::vector<long> hVec(n);
  for (long i = 0; i < n; ++i)
    std::cin >> hVec[i];
  long min = hVec[n - 1];
  bool ans = true;
  for (long i = n - 2; i >= 0; --i) {
    if (hVec[i] > min + 1) {
      ans = false;
      break;
    }
    if (hVec[i] < min)
      min = hVec[i];
  }
  std::cout << (ans ? "Yes" : "No") << std::endl;

  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define NL '\n'
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define sz(x) x.size()
#define all(x) (x).begin(), (x).end()
#define mem(a, b) memset(a, b, sizeof(a))
#define rep(ii,aa,bb) for(ll (ii)=ll(aa);(ii)<(ll)(bb);++(ii))
#define _fastIO() ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0)

//#define LOCAL
vector<string>vec_spltr(string s){s+=',';vector<string>res;while(!s.empty())
res.push_back(s.substr(0, s.find(','))),s=s.substr(s.find(',')+1);return res;}
void dbg_out(vector<string>__attribute__((unused))args,__attribute__((unused))int idx,
__attribute__((unused))int LINE_NUM){cerr<<endl;}template<typename Head,typename... Tail>
void dbg_out ( vector <string> args, int idx, int LINE_NUM, Head H, Tail... T)
{if(idx>0)cerr<<", ";else cerr << "Line(" << LINE_NUM << ") ";stringstream ss;ss<<H;
cerr<<args[idx]<<" = "<<ss.str();dbg_out(args,idx+1,LINE_NUM, T...);}
#ifdef LOCAL
#define debug(...) dbg_out(vec_spltr(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 6660999
#endif

const int M = 1e5+9; 
int marked[(M>>6)+9];
vector<int>primes;
#define ifc(z, n) (z[n>>6]&(1<<((n>>1)&31))) 
#define isc(z, n) (z[n>>6]|=(1<<((n>>1)&31))) 
void sieve(int n){ 
    memset(marked, 0, sizeof marked);
    for(int i = 3; i*i <= n; i+=2) if(!ifc(marked, i)) 
        for(int j = i * i; j <= n; j += (i + i)) isc(marked, j); 
}


int cnt[M];


void absinthe() {
    sieve(M);
    cnt[3] = 1;
    for(int i = 5; i < M; i+=2) 
        if(!ifc(marked, i) && !ifc(marked, (i+1)/2) && ((i+1)/2)&1) cnt[i] = 1;
    rep(i, 1, M) cnt[i] += cnt[i-1];
    int q, l, r; cin >> q;
    while(q--){
        cin >> l >> r;
        cout << cnt[r] - cnt[l-1] << NL;
    }
}
 
int main(){
  _fastIO();
  int tx = 1; 
  //cin >> tx;
  while(tx--) absinthe();
}  

Measured memory_bytes: 1024
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

#define all(a) (a).begin(), (a).end()

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

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

    string s; cin>>s;
    int n = s.size();

    reverse(all(s));

    ll ans = 0;

    ll base = 1, cur = 0;
    vector<ll> mod(n);
    for(int i=0; i<n; i++){
        mod[i] = ((s[i] - '0') * base + cur) % 2019;
        cur = mod[i];
        base *= 10;
        base %= 2019;
    }

    vector<ll> cnt(2019, 0);
    cnt[0]++;
    for(int i=0; i<n; i++){
        cnt[mod[i]]++;
    }

    for(int i=0; i<2019; i++){
        ans += cnt[i] * (cnt[i] - 1) / 2;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5140
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;

int sumVector(vector<vector<int>>& c,int a, int n) {
	int res = 0;
	for (int i = a; i < n; ++i) {
		res += c[1][i];
	}
	return res;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<vector<int>> A(2, vector<int>(n));
	rep(i, n) cin >> A[0][i];
	rep(i, n) cin >> A[1][i];

	vector<int> res(n + 1);
	res[0] = A[0][0];
	for (int i = 1; i < n; ++i)res[i] = res[i - 1] + A[0][i];
	
	int ans = 0;
	rep(i, n) {
		ans = max(ans, res[i] + sumVector(A, i, n));
	}

	dunk(ans);

	return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
S = [int(i) for i in input().split()]
T = [int(i) for i in input().split()]
MOD = 10**9 + 7
ns = len(S)
nt = len(T)
dp = [[0] * (nt + 1) for i in range(ns + 1)]
for i in range(1, ns + 1):
    for j in range(1, nt + 1):
        if (S[i - 1] == T[j - 1]):
            dp[i][j] = (1 + dp[i][j - 1] + dp[i - 1][j]) % MOD
        else:
            dp[i][j] = (dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - 1]) %            MOD
print((dp[ns][nt] + 1) % MOD)

Measured memory_bytes: 73052
#include<stdio.h>
#include<string.h>
int main(){
  char str[1000];
  int a,i,j;
  fgets(str,sizeof(str),stdin);
  a=strlen(str);
  for(i=0;i<a;i++){
    if(str[i]>=97 && str[i]<=122){
      str[i]=str[i]-32;
    }
  }
  printf("%s",str);
  return 0;
}

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

const double pi = 3.14159265358979323846;
const ll mod = 1000000007;


int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int n; cin >> n;
	vector<int> A(n);
	rep(i,n) cin >> A.at(i);
	int x = 0;
	for(int i = 0; i < n; i++){
		x ^= A.at(i);
	}
	for(int i = 0; i < n; i++){
		int ans = x;
		ans ^= A.at(i);
		cout << ans << " ";
	}
} 

Measured memory_bytes: 3988
from collections import deque

N, M = map(int, input().split())

G = [[] for i in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)

ls = deque([0])
ans = [-1] * N
ans[0] = 0
while len(ls) > 0:
    v = ls.popleft()

    for next_v in G[v]:
        if ans[next_v] != -1:
            continue
        ans[next_v] = v
        ls.append(next_v)

if -1 in ans:
    print("No")
else:
    print("Yes")
    for i in range(1, N):
        print(ans[i]+1)

Measured memory_bytes: 34128
/*

                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                    prayer
*/

// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(_,v.size())cout<<" "<<v[_];cout<<endl;
#define show2d(v) rep(__,v.size()){rep(_,v[__].size())cout<<" "<<v[__][_];cout<<endl;}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
// typedef tuple<int,int,int> tp;
// typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};

signed main(){
	int n,t,a;
	cin>>n>>t>>a;
	vi in(n);
	rep(i,n)cin>>in[i];
	int it=-1;
	double mi=inf;
	rep(i,n){
		double w=t-0.006*in[i];
		if(mi>abs(w-a)){
			it=i;
			mi=abs(w-a);
		}
	}
	cout<<it+1<<endl;
}















Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#pragma warning(disable : 4996) //_CRT_SECURE_NO_WARNINGS

int gcd(int a, int b) {
	int temp;
	if (a < b) {
		temp = b;b = a;a = temp;
	}
	if (a % b == 0)return b;
	return gcd(b, a % b);
}

int main(void) {
	int k = 0;
	int sum = 0;
	scanf("%d", &k);
	for (int i = 1;i <= k;i++) {
		for (int j = 1;j <= k;j++) {
			int A = gcd(i, j);
			for (int l = 1;l <= k;l++) {
				sum += gcd(A, l);
			}
		}
	}
	printf("%d", sum);
	return 0;
}

Measured memory_bytes: 2152
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, s, n) for (int i = (s); i < (n); ++i)
#define rrep(i, n, g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define len(x) (int)(x).size()
#define dup(x, y) (((x) + (y)-1) / (y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int x, y;
  cin >> x >> y;
  set<int> s1 = {1, 3, 5, 7, 8, 10, 12};
  set<int> s2 = {4, 6, 9, 11};
  set<int> s3 = {2};
  if ((s1.count(x) == 1) && (s1.count(y) == 1))
    cout << "Yes";
  else if ((s2.count(x)) == 1 && (s2.count(y) == 1))
    cout << "Yes";
  else if ((s3.count(x)) == 1 && (s3.count(y) == 1))
    cout << "Yes";
  else
    cout << "No";
}

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  string s;
  cin>>s;
  string t="NWSE";
  ll n=s.size();
  
  map<char,ll> m;
  REP(i,n)m[s[i]] = 1;
  if(m[t[0]]==m[t[2]] && m[t[1]]==m[t[3]])
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
  
  
}

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

#define MAX 2000000
#define INFTY (1<<30)

int H, A[MAX+1];

void maxHeapify(int i){
  int l, r, largest, s;
  l = 2*i;
  r = 2*i+1;
  if(l<=H&&A[l]>A[i]) largest=l;
  else largest=i;
  if(r<=H&&A[r]>A[largest]) largest=r;
  if(largest!=i){
    //swap(A[i], A[largest]);
    s = A[i];
    A[i] = A[largest];
    A[largest] = s;
    maxHeapify(largest);
  }
}

int extract(){
  int maxv;
  maxv = A[1];
  A[1] = A[H--];
  maxHeapify(1);
  return maxv;
}

void increaseKey(int i, int key){
  int s;
  if(key<A[i]) return;
  A[i] = key;
  while(i>1&&A[i/2]<A[i]){
    //swap(A[i], A[i/2]);
    s = A[i];
    A[i] = A[i/2];
    A[i/2] = s;
    i = i/2;
  }
}

void insert(int key){
  H++;
  A[H] = -INFTY;
  increaseKey(H, key);
}

int main(){
  int key;
  char com[10];

  while(1){
    scanf("%s", com);
    //if(com[0]=='e'&&com[1]=='n') break;
    if(!strcmp(com, "end")) break;
    //if(com[0]=='i'){
    if(!strcmp(com, "insert")){
      scanf("%d", &key);
      insert(key);
    }
    else printf("%d\n", extract());
  }
  
  return 0;
}



Measured memory_bytes: 5640
N = gets.to_i
$str_memo = %w(a b c d e f g h i j k)
def rec(array, biggest)
  size = array.size
  if size == N
    puts array.join("")
    return
  end
  (size + 1).times do |i|
    # break if !array.empty? && array.last.ord < i + 96
    # next if i != 0 && array.last.ord > i + 98
    break if biggest < i - 1
    tmp_biggest = [biggest, i].max
    rec(array + [$str_memo[i]], tmp_biggest)
  end
end
rec([], -1)


Measured memory_bytes: 3196
n = int(input())
num = 1

def f(a,b):
    return max(len(str(b)), len(str(int(a/b))))

min_num = 100
while num < n ** (1/2) + 1:
    if n % num == 0:
        min_num = min(min_num, f(n, num))
    num += 1
print(min_num)        

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

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1000000000;
const ll LINF = (ll) 4000000000000000000;
const ll MOD = (ll) 1000000007;
const double PI = acos(1.0);
const int limit = 100010;

#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define rep2(i,n) REP(i,1,n+1)
#define rep3(i,n) REP(i,0,n+1)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define repll(i,n) REPLL(i,0,n)
#define repll2(i,n) REPLL(i,1,n+1)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define NP(v) next_permutation(v.begin(),v.end())
#define Size(s) (int) s.size()

//------------------------------------------------------
//union-find

const int MAX_V = 2 * limit;

int par_road[MAX_V], rank_road[MAX_V];

void init1(int n) {

    rep(i, n) {
        par_road[i] = i;
        rank_road[i] = 0;
    }
}

int root1(int x) {
    return par_road[x] == x ? x : par_road[x] = root1(par_road[x]); //経路圧縮
}

bool same1(int x, int y) {
    return root1(x) == root1(y);
}

void unite1(int x, int y) {
    x = root1(x);
    y = root1(y);
    if (x == y) return;

    if (rank_road[x] < rank_road[y]) {
        par_road[x] = y;
    } else {
        par_road[y] = x;
        if (rank_road[x] == rank_road[y]) rank_road[x]++;
    }
}

//------------------------------------------------------
//union-find

int par_railway[MAX_V], rank_raliway[MAX_V];

void init2(int n) {

    rep(i, n) {
        par_railway[i] = i;
        rank_raliway[i] = 0;
    }
}

int root2(int x) {
    return par_railway[x] == x ? x : par_railway[x] = root2(par_railway[x]); //経路圧縮
}

bool same2(int x, int y) {
    return root2(x) == root2(y);
}

void unite2(int x, int y) {
    x = root2(x);
    y = root2(y);
    if (x == y) return;

    if (rank_raliway[x] < rank_raliway[y]) {
        par_railway[x] = y;
    } else {
        par_railway[y] = x;
        if (rank_raliway[x] == rank_raliway[y]) rank_raliway[x]++;
    }
}

//------------------------------------------------------

int main() {
    int n, k, l;
    cin >> n >> k >> l;

    init1(n);
    init2(n);

    rep(i, k) {
        int p, q;
        cin >> p >> q;
        unite1(--p, --q);
    }

    rep(i, l) {
        int p, q;
        cin >> p >> q;
        unite2(--p, --q);
    }

    vector<pii> v;

    rep(i, n) v.push_back(MP(root1(i), root2(i)));
    sort(v.begin(), v.end());
    rep(i, n) cout << upper_bound(v.begin(), v.end(), MP(root1(i), root2(i)))
            - lower_bound(v.begin(), v.end(), MP(root1(i), root2(i))) << (i == n - 1 ? "\n" : " ");

    return 0;
}

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

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

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

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

void solve()
{
    LL N, K;
    cin >> N >> K;
    if (K >= 2 * N)
    {
        cout << N << endl;
        return;
    }

    if (K > N)
        swap(K, N);

    cout << min(N % K, K - N % K) << endl;
}

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


Measured memory_bytes: 256
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

h,w = mi()

a = []
for i in range(h):
    k = input()
    a.append([1 if k[j]=='#' else 0 for j in range(w)])

dp = [[200]*w for i in range(h)]

# 白から黒で+1
if a[0][0] == 0:
    dp[0][0] = 0
else:
    dp[0][0] = 1

for i in range(1,w):
    if a[0][i-1] == 0 and a[0][i] == 1:
        dp[0][i] = dp[0][i-1] + 1
    else:
        dp[0][i] = dp[0][i-1]

for i in range(1,h):
    if a[i-1][0] == 0 and a[i][0] == 1:
        dp[i][0] = dp[i-1][0] + 1
    else:
        dp[i][0] = dp[i-1][0]

for i in range(1,h):#y
    for j in range(1,w):#x
        # u = 200
        if(a[i][j] == 0):
            dp[i][j] = min(dp[i-1][j],dp[i][j-1])
        else:
            if a[i-1][j] == 1:
                u = dp[i-1][j]
            else:
                u = dp[i-1][j] +1

            if a[i][j-1] == 1:
                l = dp[i][j-1]
            else:
                l = dp[i][j-1] +1

            dp[i][j] = min(u,l)


print(dp[h-1][w-1])


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

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


int main() {
	
	int n, m;
	cin >> n >> m;
	vector<int> a(m+1);
	rep(i, m){
		cin >> a[i];
	}
	vector<mint> dp(n+1);
	dp[0] = 1;
	int j = 0;
	if(m == 0) a[j] = 0;
	
	for(int i=1; i<=n; i++){
		if(i == a[j]){
			dp[i] = 0;
			if(j < m-1) j++;
		}else{
			//1段
			dp[i] += dp[i-1];
			//2段
			if(i > 1) dp[i] += dp[i-2];
			
		}
	}
	
	cout << dp[n].x << endl;
	
	return 0;
}

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

a = list(map(int, input().split()))

if n == 0 and a[0]==1:
    print(1)
    exit(0)

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

b=1
count=1
asum =sum(a)
alim = asum

for i in range(n):
    if a[i+1] > 2*b:
        print(-1)
        exit(0)
    else:
        alim = alim - a[i+1]
        b= min(2*b-a[i+1], alim)

        count += b

print(count+ asum)

Measured memory_bytes: 20144
#[allow(unused_imports)]
use proconio::{
    fastout, input,
    marker::{Bytes, Chars, Isize1, Usize1},
};

#[allow(unused_macros)]
macro_rules! echo {
    ($($e:expr),+) => ( { $(println!("{}", $e))+ } );
}

fn main() {
    input! {
        n: usize,
        k: usize,
        a: [Usize1; n],
    }
    let mut routes = vec![];
    let mut gone = std::collections::HashMap::new();
    let mut next = 0;
    let mut loop_st = 0;

    for _ in 0..n {
        match gone.get(&next) {
            Some(n) => {
                loop_st = *n;
                break;
            }
            None => {
                routes.push(next);
                gone.insert(next, routes.len() - 1);
                next = a[next];
            }
        }
    }

    let loop_len = routes.len() - loop_st;

    let ans = if k < loop_st {
        routes[k]
    } else {
        let k = (k - loop_st) % loop_len;
        routes[(loop_st + k)]
    };

    echo!(ans + 1);
}


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

int main() {
  int n;
  cin >>n;
  string a,b,c;
  cin >> a>>b>>c;
  int ans=0;
  for(int i=0;i<n;i++){
    char A,B,C;
    A=a.at(i);
    B=b.at(i);
    C=c.at(i);
    if( A==B&&B==C){
      }
      
    else if(A==B||B==C||C==A ){
       ans++;
      }
    else {
       ans+=2;
    }
  }
  cout <<ans;
}

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

#define pai 3.1415926535


int main(void){

	char S[7];
	scanf("%s", S);
	int count = 0;
	for (int i = 0; i < strlen(S); i++) {
		if (S[i] == '1') {
			count++;
		}
	}
	printf("%d", count);

	return 0;


}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define ff first
#define ss second
#define file_se_input  freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define pp long long int
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define pb push_back
#define mp make_pair
#define pi 3.141592653589793238
#define eb emplace_back
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define zip(i,a,b) for(int i=a;i<b;i++)
#define rzip(i,a,b) for(int i=a;i>=b;i--)
#define ll unsigned long long int
#define test int t;cin>>t; while(t--)
#define um unordered_map
#define en '\n'
#define us unordered_set
typedef pair<int, int>     pii;
typedef pair<char, int>    pci;
typedef pair<char, char>   pcc;
typedef vector<pii>       vii;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define INF (1e18+5)
#define inf (1e9+5)
#define mod 1000000007


bool check_prime(long long n)
{
	int flag = 0;
	for (long long i = 2; i * i <= n; i++)
	{
		if (n % i == 0)
		{
			flag = 1;
			break;
		}
	}
	if (n == 1)
		return false;
	else if (flag == 0 || n == 2 || n == 3)
	{
		return true;
	}
	else
	{
		return false;
	}

}

int BE(int x, int n, int m) //function to calculate x raise to power n modulo m
{
	int result = 1;
	while (n > 0)
	{
		if (n % 2 == 1)
			result = result * x % m;
		x = x * x % m;
		n = n / 2;
	}
	return result;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	if (fopen("input.txt", "r"))
	{
		freopen ("input.txt" , "r" , stdin);
		freopen ("output.txt" , "w" , stdout);
	}
#endif
	//_______________________________-code starts-_______________________________________________

	int n, a, b, c, d, e;
	cin >> n >> a >> b >> c >> d >> e;
	int x = min({a, b, c, d, e});
	cout << (n + x - 1) / x + 4 << en;




	return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
// #include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
// #include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

/*
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
mt19937 g1.seed(seed1);
*/
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<pii, pii> ppiipii;
typedef pair<int, ppiipii> pippiipii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> ppiii;
typedef pair<int, ppiii> pippiii;
typedef pair<int, ll> pill;
typedef pair<int, double> pid;
// note to self, the below two triggers someone
typedef pair<ll, ll> pll;
typedef pair<ll, int> plli;
typedef long double ld;

int l[105];

int main() {
  int n;
  scanf("%d", &n);
  for(int i = 0; i < n; i++) {
    scanf("%d", &l[i]);
  }
  sort(l, l+n);
  printf("%d\n", l[n-1] - l[0]);
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>

#define STARTUP {(cin.tie(0));\
 (ios::sync_with_stdio(false));}

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).size()
#define MAX(list) std::max(list)
#define MIN(list) std::min(list)
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(),(list).rend())
#define VECCIN(vec) const int size = (vec).size(); REP(i,size) cin>>(vec)[i];

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

using ll = long long;
using namespace std;
ll mod = 1'000'000'007;

const int INF = 1'050'000'000;

int main() {
    STARTUP;
   
    int N;
    cin >> N;
    int x = 0;
    int n = N;
    while (n > 0) {
        x += n % 10;
        n /= 10;
    }
    YESNO(N%x == 0, "Yes", "No");

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i = n;i >= 0;--i)
#define FOR(i,m,n) for(int i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;

int main(void)
{
    int cnt = 0;
    int n;
    cin >> n;
    vector<vector<pair<int,int>>> xy(n);

    REP(i, n)
    {
        int a;
        cin >> a;
        REP(j,a){
            pair<int, int> d;
            cin >> d.first >> d.second;
            d.first--;
            xy[i].push_back(d);
        }
    }

    uint S = pow(2, n) - 1;
    for (uint T = S;; T = (T - 1) & S)
    {
        vector<int> tc(n,0);
        vector<int> fc(n,0);
        if (T == 0)
        {
            break;
        }
        int onenum = 0;
        int ic = 0;
        bool flag = false;

        for (uint i = 1; i <= S; i *= 2)
        {
            if(i&T){
                onenum++;
                REP(j, xy[ic].size())
                {
                    if(xy[ic][j].second == 1){
                        if ( T & (uint)pow(2, xy[ic][j].first))
                        {

                        }
                        else{
                            flag = true;
                            break;
                        }
                        tc[xy[ic][j].first] = 1;
                    }
                    else{
                        if ( T & (uint)pow(2, xy[ic][j].first))
                        {
                            flag = true;
                            break;
                        }
                        fc[xy[ic][j].first] = 1;
                    }
                    if(flag){
                        break;
                    }
                }
            }
            ic++;
        }

        REP(j, tc.size())
        {
            if(tc[j] * fc[j] > 0){
                flag = true;
            }
        }

        if(flag){
            continue;
        }

        cnt = max(cnt, onenum);

    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256