akhauriyash/Code-Regression huggingface dataset:
/**
 *    author:  tourist
 *    created: 23.01.2020 03:51:26       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(17);
  int n, l;
  cin >> n >> l;
  vector<pair<long double, long double>> a;
  long double res = 0;
  int i = 0;
  for (int it = 0; it < n; it++) {
    long double t, v;
    cin >> t >> v;
    long double rm = (it == 0 ? 0 : v);
    while (i < (int) a.size()) {
      if (rm > a[i].second) {
        rm -= a[i].second;
        res -= a[i].first * a[i].second;
        ++i;
      } else {
        a[i].second -= rm;
        res -= a[i].first * rm;
        break;
      }
    }
    res += t * v;
    while (i < (int) a.size() && a.back().first > t) {
      t = (t * v + a.back().first * a.back().second) / (v + a.back().second);
      v += a.back().second;
      a.pop_back();
    }
    a.emplace_back(t, v);
    cout << res / l << '\n';
  }
  return 0;
}


Measured memory_bytes: 30180
#include <iostream>
#include <assert.h>
#include <algorithm>
#include <vector>
#include <cmath>


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

  int64_t A, B , K;
  std::cin >> A >> B >> K;
  int64_t resA = std::max((int64_t)0, A - K);
  int64_t resB = std::max((int64_t)0, B - (K - A));
  if (resA != 0) {
    resB = B;
  }
  std::cout << resA << " " << resB << std::endl;
  return 0;
}


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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

class mint{
	static const int MOD=1e9+7;
	int x;
public:
	mint():x(0){}
	mint(long long y){ x=y%MOD; if(x<0) x+=MOD; }

	mint& operator+=(const mint& m){ x+=m.x; if(x>=MOD) x-=MOD; return *this; }
	mint& operator-=(const mint& m){ x-=m.x; if(x<   0) x+=MOD; return *this; }
	mint& operator*=(const mint& m){ x=1LL*x*m.x%MOD; return *this; }
	mint& operator/=(const mint& m){ return *this*=inverse(m); }
	mint operator+(const mint& m)const{ return mint(*this)+=m; }
	mint operator-(const mint& m)const{ return mint(*this)-=m; }
	mint operator*(const mint& m)const{ return mint(*this)*=m; }
	mint operator/(const mint& m)const{ return mint(*this)/=m; }
	mint operator-()const{ return mint(-x); }

	friend mint inverse(const mint& m){
		int a=m.x,b=MOD,u=1,v=0;
		while(b>0){ int t=a/b; a-=t*b; swap(a,b); u-=t*v; swap(u,v); }
		return u;
	}

	friend istream& operator>>(istream& is,mint& m){ long long t; is>>t; m=mint(t); return is; }
	friend ostream& operator<<(ostream& os,const mint& m){ return os<<m.x; }
	int to_int()const{ return x; }
};

mint operator+(long long y,const mint& m){ return m+y; }
mint operator*(long long y,const mint& m){ return m*y; }

mint pow(mint m,long long k){
	mint res=1;
	for(;k>0;k>>=1,m*=m) if(k&1) res*=m;
	return res;
}

int main(){
	int n,m; scanf("%d%d",&n,&m);
	vector<pair<int,int>> Ev[301];
	rep(i,m){
		int l,r,c; scanf("%d%d%d",&l,&r,&c); l--;
		Ev[r].emplace_back(l,c);
	}

	// dp[i][j][k] = (最も右にある赤, 緑, 青マスがそれぞれ i, j, k マス目 (1-indexed) であるような塗り方の数)
	static mint dp[301][301][301];
	dp[0][0][0]=1;
	rep(i,n) rep(j,n) rep(k,n) {
		int next=max({i,j,k})+1;
		dp[next][j][k]+=dp[i][j][k];
		dp[i][next][k]+=dp[i][j][k];
		dp[i][j][next]+=dp[i][j][k];

		for(auto p:Ev[next]){
			int l,c; tie(l,c)=p;
			int cnt;
			cnt=1;
			if(j>=l+1) cnt++;
			if(k>=l+1) cnt++;
			if(cnt!=c) dp[next][j][k]=0;
			cnt=1;
			if(i>=l+1) cnt++;
			if(k>=l+1) cnt++;
			if(cnt!=c) dp[i][next][k]=0;
			cnt=1;
			if(i>=l+1) cnt++;
			if(j>=l+1) cnt++;
			if(cnt!=c) dp[i][j][next]=0;
		}
	}

	mint ans=0;
	rep(j,n) rep(k,n) ans+=dp[n][j][k];
	rep(i,n) rep(k,n) ans+=dp[i][n][k];
	rep(i,n) rep(j,n) ans+=dp[i][j][n];
	cout<<ans<<'\n';

	return 0;
}


Measured memory_bytes: 106880
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
int h,w,i,j,k,l,x,t,kk,cnt,ans,a[15][1005],s[15][1005],q[15];
bool f;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
    	if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
inline void print(int x)
{
    if (x<0)
        putchar('-'),x=-x;
    if (x>9)
        print(x/10);
    putchar(x%10+'0');
}
signed main(void)
{
	read(h),read(w),read(kk);
	for (i=1;i<=h;i++)
		for (j=1;j<=w;j++)
		{
			char c=getchar();
			while (c!='1' && c!='0')
				c=getchar();
			a[i][j]=c-48;
		}
	for (i=1;i<=h;i++)
		for (j=1;j<=w;j++)
			s[i][j]=s[i][j-1]+a[i][j];
	ans=inf;
	for (i=0;i<1<<(h-1);i++)
	{
		l=t=0;
		for (j=1;j<=w;j++)
		{
			f=false;
			cnt=1,x=i;
			memset(q,0,sizeof(q));
			for (k=1;k<=h;k++)
			{
				q[cnt]+=s[k][j]-s[k][l];
				if (x%2 && k!=h)
					cnt++;
				x/=2;
			}
			for (k=1;k<=cnt;k++)
				if (q[k]>kk)
				{
					if (l==j-1)
						f=true;
					l=j-1;
					j-=1;
					t++;
					break;
				}
			if (f)
				break;
		}
		if (!f)
			ans=std::min(ans,cnt-1+t);
	}
	print(ans);
	return 0;
} 

Measured memory_bytes: 384
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair
#define ll long long

inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}

vector<int> edges[100001];
int dst[100001];

int main(){
    std::ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    for(int i=0;i<m;++i)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        edges[a].push_back(b);
        edges[b].push_back(a);
    }
    for(int i=0;i<n;++i)
    {
        dst[i] = -1;
    }
    
    deque<int> q;
    q.push_back(0);
    dst[0] = 0;

    while(!q.empty())
    {
        int current = q.front();
        q.pop_front();

        for(int next: edges[current])
        {
            if(dst[next] != -1)
            {
                // already visited
                continue;
            }

            dst[next] = current;
            q.push_back(next);
        }
    }

    cout << "Yes" << endl;
    for(int i=1;i<n;++i)
    {
        cout << (dst[i] + 1) << endl;
    }
}

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

int main()
{
  int N,count=0;
  int  s,t;
  cin>>s;
  if(s%10==3){
    cout<<"bon";

  }else if(s%10==0||s%10==1||s%10==6||s%10==8){
    cout<<"pon";


  }else{
    cout<<"hon";

  }
  
  return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int n;
int limit;
vector<double> p;
vector<vector<double> > dp;//
double solve(int i,int h){
	if(h>n-i) return 0;
	else if(dp[i][h]!=-1) return dp[i][h];
	else{
		dp[i][h]=solve(i+1,h)*(1-p[i])+solve(i+1,h-1)*p[i];
	}
	return dp[i][h];	
}
		
int main(){
	cin>>n;
	p.assign(n,0);
	for(int i=0;i<n;i++){
		cin>>p[i];
	}
	double ans=0;
	dp.assign(n,vector<double>(n+1,-1));
	dp[n-1][0]=1-p[n-1];
	dp[n-1][1]=p[n-1];
	for(int i=n/2+1;i<=n;i++){
		ans+=solve(0,i);
	
	}

	cout<<fixed<<setprecision(9)<<ans;
}


Measured memory_bytes: 70912
#include <stdio.h>
#include <string.h>
int main() {
    char S[11],T[12];
    long len_S,len_T;
    scanf("%s",S);
    scanf("%s",T);
    len_S = strlen(S);
    len_T = strlen(T);
    if (strncmp(S,T,len_S) == 0){
            printf("Yes\n");
        }else{
            printf("No\n");
        }
    return 0;
}


Measured memory_bytes: 1680
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <cctype>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <complex>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cwchar>
#include <cwctype>
#include <exception>
#include <locale>
#include <numeric>
#include <new>
#include <stdexcept>
#include <limits>
#include <valarray>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <list>
#include <utility>
#include <bitset>
#include <algorithm>
#include <functional>
using namespace std;
int a[2][105];
int dp[2][105];
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<2;i++)
	{
		for(int j=0;j<n;j++)
		{
			cin>>a[i][j];
		}
	}
	for(int i=0;i<2;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(i>0 and j>0)
			{
				dp[i][j]=max(dp[i-1][j],dp[i][j-1])+a[i][j];
			}
			else if(i==0)
			{
				dp[i][j]=dp[i][j-1]+a[i][j];
			}
			else
			{
				dp[i][j]=dp[i-1][j]+a[i][j];
			}
		}
	}
	cout<<dp[1][n-1];
	return 0;
}

Measured memory_bytes: 256
/**
 *    author        : Trisha 
 *    created       : July 11, 2020 4:31 PM
 *    Problem Name  : A - Station and Bus
 *    Problem Limit : 2000 ms , 1024 MB
 *    Problem Url   : https://atcoder.jp/contests/abc158/tasks/abc158_a
**/

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

int main(){
    ios_base::sync_with_stdio(false);

    string s;
    cin >> s;

    if (s == "AAA" || s == "BBB")
        cout <<"No"<<endl;
    else cout <<"Yes" << endl;

    return 0 ;
}


Measured memory_bytes: 3616
N = int(input())
H = list(map(int, input().split()))

cnt = 0
cntmax = 0

for i in range(N-1):
    if H[i] >= H[i+1]:
        cnt += 1
    else:
        if cnt > cntmax:
            cntmax = cnt
        cnt = 0
        
if cnt > cntmax:
    cntmax = cnt
    
print(cntmax)

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

int main(){
  int N, M;
  cin >> N >> M;
  vector<int> a(M), broken(N,0);
  for(int i=0; i<M; i++){
    cin >> a.at(i);
    broken.at(a.at(i))++;
  }
  vector<int> mtd(N+1,0);
  const int MOD = 1000000007;
  if((N>=2 && broken.at(1)==0) || N==1){
    mtd.at(1) = 1;
  }
  if((N>=3 && broken.at(2)==0) || N==2){
    mtd.at(2) = mtd.at(1)+1;
  }
  for(int i=3; i<N; i++){
    if(broken.at(i)==0){
      mtd.at(i) = mtd.at(i-2)*(1-broken.at(i-2))+
        			mtd.at(i-1)*(1-broken.at(i-1));
    }
    if(mtd.at(i)>=MOD){
      mtd.at(i) %= MOD;
    }
    if(i==N-1){
      mtd.at(N) = (mtd.at(N-2)*(1-broken.at(N-2))+
        		mtd.at(N-1)*(1-broken.at(N-1))) % MOD;
    }
  }
  cout << mtd.at(N);
  return 0;
}

Measured memory_bytes: 4580
#include <cstdio>
#include <algorithm>

#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

int n, m;
vector<int> g[500];
int x[500];

int dfs(int i, int k){
	if(k >= 0){
		x[i] = 1;
	}
	if(k > 0){
		for(int v: g[i]){
			dfs(v, k - 1);
		}
	}
}

int main(){
	while(1){
		scanf("%d%d", &n, &m);
		if(n == 0 && m == 0){
			break;
		}

		rep(i, m){
			int a, b;
			scanf("%d%d", &a, &b);
			--a;
			--b;
			g[a].push_back(b);
			g[b].push_back(a);
		}

		dfs(0, 2);

		int s = 0;
		rep(i, n){
			s += x[i];
		}
		printf("%d\n", s - 1);

		rep(i, n){
			g[i].clear();
		}
		fill(x, x + n, 0);
	}
	return 0;
}

Measured memory_bytes: 2700
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextint() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextFloat() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

func Maxint(x, y int) int {
	if x < y {
		return y
	}
	return x
}

func Minint(x, y int) int {
	if x <= y {
		return x
	}
	return y
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextint()
	max_ := math.MinInt32
	min_ := math.MaxInt32
	sum_ := 0
	for i := 0; i < n; i++ {
		tmp := nextint()
		sum_ += tmp
		max_ = Maxint(max_, tmp)
		min_ = Minint(min_, tmp)
	}
	fmt.Printf("%v %v %v\n", min_, max_, sum_)
}



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

using namespace std;

#define fcout(d) cout << fixed << setprecision(d)
#define repU(i,s,t) for(int i = (s); i <= (t); ++i)
#define repD(i,t,s) for(int i = (t); i >= (s); --i)
#define rep(i,n) repU(i,0,n - 1)
#define rep1(i,n) repU(i,1,n)
#define all(v) begin(v),end(v)
#define l_bnd lower_bound
#define u_bnd upper_bound
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define mkp make_pair
#define mkt make_tuple
#define fir first
#define sec second
#define q_ceil(n,d) ((n - 1) / (d) + 1)
#define parity(a,b) (((a)^(b)) & 1 ^ 1)

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<int,int> pii;

const pair<int,int> DIR[] = { {1,0},{0,1},{-1,0},{0,-1},{1,1},{-1,1},{-1,-1},{1,-1} };
const int INF_32 = (1 << 30) - 1;
const ll INF_64 = (1LL << 62) - 1;
const int MOD = 1e9 + 7;

int N,A,B;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	cin >> N >> A >> B;
	if(N == 1){
		if(max(A,B) > 1) cout << -1 << endl;
		else cout << 1 << endl;
		return 0;
	}
	if(A + B > N + 1 || N > (ll)A * B){
		cout << -1 << endl;
		return 0;
	}
	if(A == 1){
		rep(i,N) cout << N - i << ' ';
		cout << endl;
		return 0;
	}
	if(B == 1){
		rep1(i,N) cout << i << ' ';
		cout << endl;
		return 0;
	}
	int q = (N - B) / (A - 1);
	int r = (N - B) % (A - 1);
	rep(i,B) cout << B - i << ' ';
	int cur = B;
	rep(i,A - 1){
		int k = q;
		if(0 < r--) ++k;
		repD(j,k,1) cout << cur + j << ' ';
		cur += k;
	}
	cout << endl;
}





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


int main() {
	char a[21] = {0};
	cin.getline(a, 21);
	for (int i = 0; i < 21; i++) {
		if (a[20 - i] == '\0')
			continue;
		cout << a[20 - i];
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 3036
// Problem : E - Red Scarf
// Contest : AtCoder - AtCoder Beginner Contest 171
// URL : https://atcoder.jp/contests/abc171/tasks/abc171_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	ll i,j,k,m,n,t,q;
	cin>>n;
	ll ar[n];
	for(i=0;i<n;i++)
	cin>>ar[i];
	ll pre[n],suf[n];
	pre[0]=ar[0];
	for(i=1;i<n;i++)
	{
		pre[i]=pre[i-1]^ar[i];
	}
	suf[n-1]=ar[n-1];
	for(i=n-2;i>=0;i--)
	{
		suf[i]=suf[i+1]^ar[i];
	}
	cout<<suf[1]<<' ';
	for(i=1;i<n-1;i++)
	cout<<(suf[i+1]^pre[i-1])<<' ';
	cout<<pre[n-2]<<' ';
}

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

int main(){
  int N;
  cin>> N;
  vector<int> d(N);
  for(int i= 0;i<N;i++)
    cin>>d[i];
  int ans= 0;
  for(int i=0;i<N;i++){
  for(int j= i+1;j< N; j++){
    ans+=d[i]*d[j];
  }
  }
  cout<< ans<< endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const long double EPS = 1e-9;
const ll mod = 1e9 + 7;
const ll INF = 1e9;

#define rep(i, n) for(ll i = 0; i < n ; i++ )
#define For(i, a, b) for(ll i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

const ll MAX_N = 1000;

int main(void){
    ll N, T, A;
    ll answer = 0;
    double T_opt = double(INF);

    cin >> N >> T >> A;
    rep(i, N){
        ll h;
        cin >> h;
        double Th_diff = abs( double(A) - double(T) + 0.006 * double(h));
        if (Th_diff < T_opt){
            answer = i + 1;
            T_opt = Th_diff;
        } 
    }


    cout << answer << endl;
    
    return 0;
}

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

using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0; i<n; i++)
#define rep2(i,a,b) for(ll i=a; i<=b; i++)
#define drep2(i,a,b) for(ll i=a; i>=b; i--)
#define pb push_back



ll getNum(int l, int r, string& s)
{
  ll result = 0;
  rep2(i,l,r) {
    result = (s[i] - '0') + result * 10;
  }
  return result;
}
int main ()
{
  string S;
  cin >> S;
  ll ans = 0;
  for (int i =0; i <= (1<<(S.size()-1))-1; i++) {
    //printf("max: %d\n", 1<<(S.size()-1));
    //printf("i : %d\n", i);
    ll sum = 0;
    ll l = 0;
    ll bs = i;
    rep(j, S.size()-1) {
      //printf("S[%d] : %c\n", j, S[j]);
      if (bs & 1 == 1) {
        sum += getNum(l, j, S);
        l = j+1;
      }
      bs >>= 1;
      
    }

    sum += getNum(l, S.size()-1, S);
    //printf("sum : %d\n", sum);

    ans += sum;
  }
  cout << ans << endl;
  
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

// https://atcoder.jp/contests/abc167/tasks/abc168_a
func main() {

	data := readLines()

	num := data[0][0]

	n, _ := strconv.Atoi(num[len(num)-1:])

	if n == 3 {
		fmt.Println("bon")
	} else if n == 0 || n == 1 || n == 6 || n == 8 {
		fmt.Println("pon")
	} else {
		fmt.Println("hon")
	}

}

func readLines() [][]string {
	var result [][]string
	for i := 0; ; i++ {
		line, e := readLine()
		if e != nil {
			break
		}
		result = append(result, strings.Split(line, " "))
	}
	return result
}

func readLine() (string, error) {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			return "", e
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf), nil
}


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

#define st first
#define nd second
#define all(x) (x).begin(), (x).end()

using namespace std;
using namespace placeholders;

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

template <class T> void mini(T &l, T r){l = min(l, r);}
template <class T> void maxi(T &l, T r){l = max(l, r);}

template <class TH> void _dbg(const char *sdbg, TH h){cerr << sdbg << "=" << h << "\n";}
template <class TH, class ...TA> void _dbg(const char *sdbg, TH h, TA... a){
	while (*sdbg != ','){cerr << *sdbg++;}cerr << "=" << h << ","; _dbg(sdbg + 1, a...);
}
template <class T> ostream &operator <<(ostream &os, vector<T> V){
	os << "["; for (auto vv: V) os << vv << ","; return os << "]";
}
template <class L, class R> ostream &operator <<(ostream &os, pair<L, R> P){
	return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef SFIC
	#define eput(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
	#define eput(...) 218
#endif

const int N = 2E3 + 10;

int n;
int a[N], b[N];

int main(){
	int n, K, Q;
	scanf("%d%d%d", &n, &K, &Q);
	for (int i = 0; i < n; ++i)
		scanf("%d", a + i);
	int ans = 2e9;
	for (int i = 0; i < n; ++i){
		vector<int> c;
		for (int j = 0; j < n; ++j){
			if (a[j] < a[i])
				continue;
			int k = j + 1;
			for (; k < n && a[k] >= a[i]; ++k);
			int len = k - j;
			eput(i, j, k);
			if (K <= len){
				copy(a + j, a + k, b);
				sort(b, b + len, greater<int>());
				for (int l = K - 1; l < len; ++l)
					c.push_back(b[l]);
			}
			j = k - 1;
		}
		sort(all(c));
		if (c.size() >= Q)
			mini(ans, c[Q - 1] - c[0]);
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 256
MAX = 10**18

_ = gets # discard n
as = gets.chomp.split(' ').map(&:to_i)

if as.any? { |e| e == 0 }
  puts "0"
else
  ans = 1
  as.each do |a|
    ans *= a
    if ans > MAX
      break
    end
  end

  if ans > MAX
    puts "-1"
  else
    puts ans
  end
end


Measured memory_bytes: 23580
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned ll;
using ld = long double;
using pll = pair<ll, ll>;
using pss = pair<string, string>;
using pdd = pair<ld, ld>;
using graph = vector<vector<int>>;

const ll MOD = 1000000007;
const ld EPS = 1e-9;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ex[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const int ey[8] = {0, 1, 1, 1, 0, -1, -1, -1};

template <class T>
void chmin(T &a, T b) { a = min(a, b); }
template <class T>
void chmax(T &a, T b) { a = max(a, b); }

ll intabs(ll a)
{
    if (a >= 0)
        return a;
    else
        return -a;
}

ll intpow(ll a, ll b, ll p = LLONG_MAX)
{
    ll ret = 1;
    while (b != 0)
    {
        if ((b & 1) == 1)
            ret *= a;
        a *= a;
        if (a >= p)
            a %= p;
        if (ret >= p)
            ret %= p;
        b = b >> 1;
    }
    return ret;
}

int digit(ll a, ll b = 10)
{
    int ret = 0;
    while (a != 0)
    {
        a /= b;
        ret++;
    }
    return ret;
}

ll gcd(ll x, ll y)
{
    while (y != 0)
    {
        ll cnt = x % y;
        x = y;
        y = cnt;
    }
    return x;
}

ll modinv(ll a, ll m)
{
    ll b = m, u = 1, v = 0;
    while (b)
    {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0)
        u += m;
    return u;
}

class UnionFind
{
    vector<int> par, sz;

public:
    UnionFind(int n) : par(n), sz(n)
    {
        for (int i = 0; i < n; i++)
        {
            par[i] = i;
            sz[i] = 1;
        }
    }
    int root(int x)
    {
        if (par[x] == x)
            return x;
        return par[x] = root(par[x]);
    }
    void unite(int x, int y)
    {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry)
            return;
        par[rx] = ry;
        sz[ry] += sz[rx];
    }
    bool same(int x, int y)
    {
        return root(x) == root(y);
    }
    int size(int x)
    {
        return sz[root(x)];
    }
};

vector<bool> seen;
void dfs(const graph &g, int v)
{
    seen[v] = true;
    for (auto i : g[v])
    {
        if (seen[i])
            continue;
        dfs(g, i);
    }
}

int main()
{
    int i, j, k, cnt;
    int n;
    cin >> n;
    int p[n];
    for (i = 0; i < n; i++)
        cin >> p[i];
    int m = p[0];
    cnt = 1;
    for (i = 1; i < n; i++)
    {
        if (m >= p[i])
        {
            cnt++;
            m = p[i];
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main()
{

    string s, t;
    cin >> s >> t;

    int sum = 0, tmp;
    for (int i = 0; i < s.length() - t.length() + 1; i++)
    {
        tmp = 0;
        for (int j = 0; j < t.length(); j++)
        {

            if (s[i + j] == t[j])
            {
                tmp++;
            }
        }
        if (sum < tmp)
        {
            sum = tmp;
        }
    }
    cout << t.length() - sum << endl;
    return 0;
}

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

#define rep(i, a) for (int i = 0; i < (a); ++i)
#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define vi vector<int>

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define debug_1(x1) cerr << #x1 << ": " << x1 << endl
#define debug_2(x1, x2) cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define debug_3(x1, x2, x3) cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << endl
#define debug_4(x1, x2, x3, x4) cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << endl
#define debug_5(x1, x2, x3, x4, x5) cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#define debug(...) CHOOSE((__VA_ARGS__, debug_5, debug_4, debug_3, debug_2, debug_1, ~)) (__VA_ARGS__)

using namespace std;
using ll = long long;
using P = pair<int, int>;

// auto mod int
const int mod = 1000000007;
#pragma GCC diagnostic ignored "-Wshadow"
struct mint {
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  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;
  }
};
istream& operator>>(istream& is, const mint& a) {return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) {return os << a.x;}
#pragma GCC diagnostic warning "-Wshadow"

void Main() {
  int n, k;
  cin >> n >> k;
  mint ans = 0;
  vector<mint> d(k+1, 0);
  for (int i=k; i>=1; --i) {
    d[i] = mint(k/i).pow(n);
    REP(j, 2, (k/i)+1) {
      d[i] -= d[i*j];
    }
    ans += d[i]*i;
  }
  cout << ans << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


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

int main(){
  int n;
  cin >> n;
  string a[n];
  int b[26];
  for(int i=0;i<26;i++) b[i]=100;
  for(int i=0;i<n;i++) cin >> a[i];
  for(int i=0;i<n;i++){
    int c[26]={};
    for(int j=0;j<a[i].size();j++) c[a[i].at(j)-97]++;
    for(int k=0;k<26;k++) b[k] = min(b[k],c[k]);
  }
  for(int i=0;i<26;i++){
    for(int j=0;j<b[i];j++) cout << char(97+i);
  }
  cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
typedef long long ll;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
typedef vector<vector<char>> vvc;
typedef vector<char> vc;
typedef pair<ll,ll> pll;
typedef priority_queue<string> priquest;
typedef priority_queue<string,vector<string>,greater<string>> rpriquest;
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
  return x+y-max(x,y);
}

const ll big=1000000007;
ll exp(ll a, ll b){
  if(b==0)return 1;
  if(a==1||a==0)return a;
  if(b%2==0){
    int t =exp(a,b/2);
    return t*t%big;
  }
  else return exp(a,b-1)*a%big;
}

bool prime(int x){
    if(x==1)return false;
    for(int i=2;i*i<=x;i++)
        if(x%i==0)return false;
    return true;
}
bool like(int k){
    if(k%2==0)return false;
    if(prime(k)&&prime((k+1)/2))return true;
    return false;
}

int main(){
    int q;
    cin >> q;
    vector<int> l(q);
    vector<int> r(q);
    vector<ll> num(100001,0);
    num[1]=0;num[2]=0;
    rep2(i,3,100001){
        if(like(i))num[i]=num[i-1]+1;
        else num[i]=num[i-1];
    }
    rep(i,q){
        cin >> l[i] >> r[i];
        printf("%lld\n",num[r[i]]-num[l[i]-1]);
    }
}

Measured memory_bytes: 2176
const input = require('fs').readFileSync('/dev/stdin', 'utf8');
const lines = input.split("\n");
const n = Number(lines[0]);
const ary = lines[1].split(" ").map(Number);
let i, j, v;

console.log(ary.join(" "));
for (i = 1; i < n; i++) {
	v = ary[i];
	j = i - 1;
	while (j >= 0 && ary[j] > v) {
		ary[j + 1] = ary[j];
		j--;
	}
	ary[j + 1] = v;
	console.log(ary.join(" "));
}


Measured memory_bytes: 16560
N = int(input())
T,A = list(map(int,input().split()))
H =list(map(int,input().split()))

cand1 = 10**9
for i in range(N):
    cand2 = abs(T-H[i]*0.006-A)
    if cand2<cand1:
        out = i+1
        cand1 = cand2
print(out)


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

typedef long long ll;

int main () {
	int K;
	char S[105] = {0};
	cin >> K >> S;
	if (S[K] != '\0') {
		S[K] = S[K+1] = S[K+2] = '.';
		S[K+3] = '\0';
	}
	cout << S << endl;
	return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <iomanip>
#include <map>
#include <cstdio>
#include <sstream>
#define ll long long
#define ld long long double
using namespace std;

int main(){
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);   cout.tie(NULL);
   int a,b;
   cin >> a >> b;

   for(int i=0;i<max(a,b);i++)
      cout << min(a,b);
   cout << '\n';
}
/* 


*/

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG

#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>

#include <cmath>

#define int long long

using namespace std;

signed main() {
  int a, b;

  cin >> a >> b;

  int t = 1;
  int ans = 0;
  while (t < b) {
    t -= 1;
    t += a;
    ans++;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;
/* ---------------------------------------------------------------------------------------------------- */

int N;
vector<pii> G[100010];
int dis[100010];

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

  cin >> N;
  REP(i,N-1) {
    int u,v,w;
    cin >> u >> v >> w;
    u--; v--;
    G[u].emplace_back(v,w);
    G[v].emplace_back(u,w);
  }
  MINUS(dis);
  dis[0] = 0;
  queue<int> que;
  que.push(0);
  while (!que.empty()) {
    int cur = que.front(); que.pop();
    for (auto e : G[cur]) {
      if (dis[e.first] < 0) {
        dis[e.first] = dis[cur]+e.second;
        que.push(e.first);
      }
    }
  }
  REP(i,N) cout << dis[i] % 2 << endl;

  return 0;
}

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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define P pair<int,int>
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7;
const ll LINF = 1e18;

//while(x!=0){
            //sum+=x%10;
           // x/=10;
        //}
        //各桁の和

//pair<int,int> p[100000];
//P r[100000];
//cin >> tmp;
//p[i]=make_pair(tmp,i);
//cout << p[i].second+1 << endl;//ペアの右側つまりiを出力

//s.find(w[i])==string::npos
//findの使い方

//for(int i=0;i<n;i++){
   // b[i]=x%2;
    //x/=2;
  //}二進数

long long int n,cnt=0,ans=0,a,b,c,cmp,data,m,h,w,x[10000000],y,xcmp,ycmp,sum=0;
                                                                             //x[i]までj枚kになる
string s;

vector<int> z;

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

       cin >> n >> a;
       long long int dp[n+1][n+1][50*a+1];
       rep(i,n){
           cin >> x[i];
       }
       rep(i,n+1){
           rep(j,50*a+1){
               dp[0][i][j]=0;
           }
       }
       dp[0][0][0]=1;
       rep(i,n){
           rep(j,n+1){
               rep(k,50*a+1){
                   if(k>=x[i]){
                       dp[i+1][j][k]=dp[i][j][k]+dp[i][j-1][k-x[i]];
                   }
                   else{
                       dp[i+1][j][k]=dp[i][j][k];
                   }
               }
           }
       }
           rrep(j,1,n+1){
               ans+=dp[n][j][j*a];
           }
       Cout(ans);
return 0;
}


Measured memory_bytes: 51072
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
bool ok(vector<ll> &a, double x, int k) {
	int k0;
	for (int d : a) {
		k0 = ceil(d / (x )) - 1;
// 		if (round(d / (k0 + 1)) > x) {
// 			k0++;
// 		}
		k -= k0;
	}
	return k >= 0;
}
 
int main() {
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
 
    ll l = 0;
    ll r = 1000000001;
    ll m;
    while (l < r - 1) {
    	m = l + (r - l) / 2;
    	if (ok(a, m, k)) {
    		r = m;
    	} else {
    		l = m;
    	}
    }
    cout << r << endl;
}

Measured memory_bytes: 4792
fun main(args: Array<String>) {
    val list = readLine()!!.split(' ').map(String::toLong).sorted()

    if ((list[0] == list[1] && list[0] != list[2]) || (list[2] == list[1] && list[0] != list[2])) {
        println("Yes")
    } else {
        println("No")
    }
}


Measured memory_bytes: 36340
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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; }

const int mod=1000000007;
const int INF=1001001001;


int main() {
  int N;
  cin>>N;
  bool ok=false;
  for(int i=1;i<=9;i++){
    if(N%i==0&&N/i<=9){ok=true;}
  }
  if(ok){cout<<"Yes"<<endl;}
  else{cout<<"No"<<endl;}
  return 0;  
}

Measured memory_bytes: 3636
N = int(input())
q = 0
flug = 0
while q <= N :
	if N%7 == 0:
		flug = 1
		break
	
	if (N-q)%4 == 0:
		flug = 1
		break
	q = q + 7
 
if flug == 1:
	print("Yes")
else:
	print("No")

Measured memory_bytes: 2940
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<cstdio>
#include<string>
//#include<string>
//#include<sstream>
using namespace std;

int main()
{
	int n,i,l;
	char a[100005];
	scanf("%s",&a);
	l=strlen(a);
	n=1;
	for(i=0;i<l-1;i++)
	{
		if(a[i]!=a[i+1])
			n++;
	}
	printf("%d\n",n-1);
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

int main() {
    

    ll a,b;
    cin >> a >> b;
    cout << ceil(double(b-1) / double(a-1)) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main (){
  int n,m,flag[21]={},a[20],b[200],i,j,k,tmp=0,l_flag[200]={};
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  scanf("%d",&m);
  for(i=0;i<m;i++){
    scanf("%d",&b[i]);
  }
  
  while(flag[n]!=1){
    for(i=0;i<n;i++){
      if(flag[i])tmp+=a[i];
    }
    for(i=0;i<m;i++){
      if(tmp==b[i])l_flag[i]=1;
    }
    flag[0]+=1;
    for(i=0;i<n;i++){
      if(flag[i]==2){
	flag[i+1]+=1;
	flag[i]=0;
      }
    }
    tmp=0;
  }
  
    
  for(i=0;i<m;i++){
    if(l_flag[i]) printf("yes\n");
    else printf("no\n");
  }
  return 0;
}



Measured memory_bytes: 2048
# ABC081 B

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

    result = 0
    flag = 0
    
    while True:
        for i in range(len(A)):
            if A[i] % 2 == 0:
                A[i] = A[i] // 2
            else:
                flag = 1
                break
        
        if flag == 1:
            break

        result += 1
    
    print(result)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
def zero(s,l):
    dif=0
    num=0
    for i in range(l):
        if s[i] != str(num):
            dif+=1
        num=(num+1)%2
    return dif

def one(s,l):
    dif=0
    num=1
    for i in range(l):
        if s[i] != str(num):
            dif+=1
        num=(num+1)%2
    return dif

s=input()
l=len(s)
print(min(zero(s,l),one(s,l)))

Measured memory_bytes: 3188
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())


def main():

    X = in_n()

    if 400 <= X <= 599:
        ans = 8
    elif 600 <= X <= 799:
        ans = 7
    elif 800 <= X <= 999:
        ans = 6
    elif 1000 <= X <= 1199:
        ans = 5
    elif 1200 <= X <= 1399:
        ans = 4
    elif 1400 <= X <= 1599:
        ans = 3
    elif 1600 <= X <= 1799:
        ans = 2
    elif 1800 <= X <= 1999:
        ans = 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9296
# coding: utf-8
# Your code here!

n,k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]

q = [0]*45
qm = [0]*45

for i in range(45):
    z=0
    for aa in a:
        if (aa&(2**i))==0:
            z+=1
    q[i] = z
    qm[i] = max(z,n-z)

#print(qm)


def keta(nn):
   r = 0
   while nn:
       nn = nn// 2
       r+=1
   return r


def fmax(x,dg):
    if dg < 0:
        return 0
    ke=keta(x)-1
    if ke<dg:
        return fmax(x,dg-1)+(2**dg)*(n-q[dg])
    keee=keta(x-2**ke)
    c = fmax(x-2**ke,dg-1) + (2**dg)*q[dg]
    d = sum([(2**i)*qm[i] for i in range(ke)])+(2**ke)*(n-q[ke])
#    print(x,dg,c,d)
    return max(c, d)



#ss=sum([(2**i)*(n-q[i]) for i in range(keta(k)+1,45)])
#print(ss)
print(fmax(k,44))

Measured memory_bytes: 14620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I=ll(A);I<ll(B);++I)

const int Xx = 'x'-'X';
const int xX = 'X'-'x';

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

	string s,p;
	cin >> s >> p;
	int sl = s.size();
	int pl = p.size();
	FOR(i,0,sl){
		s = s[sl-1]+s.substr(0,sl-1);
		if(s.substr(0,pl)==p){
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}


Measured memory_bytes: 3240
import java.util.Scanner
import scala.math._

object Main extends App {
  val sc = new Scanner(System.in)
  val N = sc.nextInt
  val abc = Array.fill(N, 3)(sc.nextInt)

  val dp = Array.fill(N, 3)(0)

  dp(0) = abc(0)
  for (i <- 1 until N) {
    dp(i)(0) = max(dp(i-1)(1), dp(i-1)(2)) + abc(i)(0)
    dp(i)(1) = max(dp(i-1)(0), dp(i-1)(2)) + abc(i)(1)
    dp(i)(2) = max(dp(i-1)(0), dp(i-1)(1)) + abc(i)(2)
  }
  println(dp.last.max)
}


Measured memory_bytes: 112364
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;
#define int ll

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;cin >> s;
    ll n = s.size();
    const ll MOD = 2019;
    map<ll, ll> mp;
    reverse(all(s));
    ll ans = 0;
    ll sum = 0;
    vector<ll> dp(n+1);
    dp[0] = 1;
    mp[0] = 1;
    rep(i,n)dp[i+1] = dp[i] * 10 % MOD;
    rep(i,n){
        ll t = s[i] - '0';
        sum += dp[i] * t;
        sum %= MOD;
        ans += mp[sum];
        mp[sum]++;
        // debug(sum);
    }
    cout << ans << endl;
}

Measured memory_bytes: 5224
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <cstdio>
#include <algorithm>
#include <map>
#include <queue>
using namespace std;

#define next '\n'
#define rep(i, n) for(int (i) = (0); (i) < (n); (++i))
#define FOR(i, start, end) for(int (i) = (start); (i) < (end); (++i))
using ll = long long;
using ull = unsigned long long;

vector<int> v;

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

    int n;
    cin >> n;
    rep(i, n){
        int p; cin >> p;
        v.push_back(p);
    }

    int count = 0;
    rep(i, n){
        if(v[i] != (i + 1)){
            count++;
        }
    }

    if(count <= 2){
        cout << "YES";
    }else{
        cout << "NO";
    }

    cout << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<algorithm>
#include<string>
using namespace std;
const int BUF = 55;
const long long INF = 1LL << 60;


int nStr;
string s[BUF];
int cost[BUF];

void read() {
    cin >> nStr;
    for (int i = 0; i < nStr; ++i) {
        cin >> s[i] >> cost[i];
    }
}


bool isPalindrome(string &str) {
    for (int i = 0; i < str.size() / 2; ++i) {
        if (str[i] != str[str.size() - 1 - i]) {
            return false;
        }
    }
    return true;
}


bool aStartsWithB(string &a, string &b) {
    return a.size() >= b.size() && a.substr(0, b.size()) == b;
}


bool aEndsWithB(string &a, string &b) {
    return a.size() >= b.size() && a.substr(a.size() - b.size()) == b;
}


long long rec(string bgn, string end, map<pair<string, string>, long long> &dp) {
    if (dp.count(make_pair(bgn, end))) {
        return dp[make_pair(bgn, end)];
    }

    if ((bgn.empty() && isPalindrome(end)) || (end.empty() && isPalindrome(bgn))) {
        return dp[make_pair(bgn, end)] = 0;
    }

    dp[make_pair(bgn, end)] = INF;
    long long ret = INF;

    if (bgn.empty()) {
        for (int i = 0; i < nStr; ++i) {
            string &str = s[i];
            if (aEndsWithB(str, end)) {
                string nextBgn = str.substr(0, str.size() - end.size());
                reverse(nextBgn.begin(), nextBgn.end());
                ret = min(ret, rec(nextBgn, "", dp) + cost[i]);
            } else if (aEndsWithB(end, str)) {
                ret = min(ret, rec("", end.substr(0, end.size() - str.size()), dp) + cost[i]);
            }
        }
    } else {
        for (int i = 0; i < nStr; ++i) {
            string &str = s[i];
            if (aStartsWithB(str, bgn)) {
                string nextEnd = str.substr(bgn.size());
                reverse(nextEnd.begin(), nextEnd.end());
                ret = min(ret, rec("", nextEnd, dp) + cost[i]);
            } else if (aStartsWithB(bgn, str)) {
                ret = min(ret, rec(bgn.substr(str.size()), "", dp) + cost[i]);
            }
        }        
    }
    

    return dp[make_pair(bgn, end)] = ret;
}


void work() {
    long long minV = INF;
    
    map<pair<string, string>, long long> dp;
    for (int i = 0; i < nStr; ++i) {
        string nextEnd = s[i];
        reverse(nextEnd.begin(), nextEnd.end());
        minV = min(minV, rec("", nextEnd, dp) + cost[i]);
    }

    cout << (minV == INF ? -1 : minV) << endl;
}


int main() {
    read();
    work();
    return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll h, w, k;
  cin >> h >> w >> k;
  vector<vc> g(h, vc(w));
  rep(i, h) rep(j, w) cin >> g[i][j];
  ll ans = 1e18;
  rep(i, 1 << (h - 1)) {
    vl d;
    rep(j, h - 1) if(i >> j & 1) d.push_back(j);
    d.push_back(h - 1);
    ll n = d.size();
    ll now = n - 1;
    bool ok = true;
    vl total(n, 0);
    rep(j, w) {
      vl cnt(n, 0);
      ll div = 0;
      rep(a, h) {
        if(g[a][j] == '1') cnt[div]++;
        if(a == d[div]) div++;
      }
      bool nok = true;
      rep(a, n) {
        if(total[a] + cnt[a] > k) {
          nok = false;
          if(total[a] == 0) ok = false;
        }
      }
      if(!nok) {
        total = cnt;
        now++;
      } else
        rep(a, n) total[a] += cnt[a];
    }
    if(ok) ans = min(ans, now);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3616
def mod_kaijou(n,MOD = 10 ** 9 + 7 ):
    ans = 1
    for i in range(1,n + 1):
        ans *= i
        ans %= MOD
    return ans
# def pow_r(x, n,MOD = 1):
#     """
#     O(log n)
#     """
#     if n == 0:  # exit case
#         return 1
#     if n % 2 == 0:  # standard case ① n is even
#         return pow_r(x ** 2, n // 2) % MOD
#     else:  # standard case ② n is odd
#         return x * pow_r(x ** 2, (n - 1) // 2) % MOD

def 逆元_一覧(n,MOD = 10 ** 9 + 7):
    li = [0]
    for i in range(1,n+ 1):
        li.append(pow(i,MOD-2,MOD))
    return li


def mod_nCr(n,r,MOD = 10 ** 9 + 7 ):
    ans = 1
    mul = n
    li = 逆元_一覧(r + 1)
    for i in range(r ):
        ans *= mul
        ans *= li[i + 1]
        mul -= 1
        ans %= MOD
    return ans


MOD= 10 ** 9 + 7
n,a,b = list(map(int,input().split()))
all = pow(2,n,MOD)  - 1
all %= MOD
A = mod_nCr(n,a,MOD)
all -= A
all %= MOD
B = mod_nCr(n,b,MOD)
all -= B
all %= MOD
print(all)

Measured memory_bytes: 55792
import math

_ = input().rstrip()
A = list(map(int, input().rstrip().split(" ")))

cnt = 0

def merge(A, left, mid, right):
    global cnt
    L, R = [], []
    for a in A[left:mid]:
        L.append(a)
    for a in A[mid:right]:
        R.append(a)
    L.append(math.inf)
    R.append(math.inf)
    
    i, j = 0, 0
    for k in range(left, right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
            cnt += len(L) - 1 - i
            
            
def mergeSort(A, left, right):
    if right - left > 1:
        mid = (right + left) // 2
        mergeSort(A, left, mid)
        mergeSort(A, mid, right)
        merge(A, left, mid, right)
mergeSort(A, 0, len(A))
print(cnt)


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

using namespace std;
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef long long ll;
const int N=1e9+5;///1e18+5

void solve()
{
    int x;
    cin>>x;
    if(x==1)cout<<0<<endl;
    else if(x==0)cout<<1<<endl;

}


int main()
{
    IO;
    int tc=1;
    //cin>>tc;
    while(tc--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3636
def main():
    D = []
    n = int(input())
    for i in range(n):
        d = list(map(int, input().split()))
        D.append(d)
        
    for i in range(n):
        flag = 0
        for j in range(n-i):
            if D[i+j][0] == D[i+j][1]:
                flag += 1
            else:
                break
        if flag == 3:
            print('Yes')
            exit()
    
    print('No')


    
if __name__ == "__main__":
    main()

Measured memory_bytes: 9196
#include <cstdio>
#include <vector>

using namespace std;

int main() {
  int n;
  vector<int> vec;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    int x;
    scanf("%d", &x);
    vec.push_back(x);
  }

  double sum = 0.0;
  for (int i : vec) {
    sum += 1.0 / (double)i;
  }
  printf("%lf\n", 1.0 / sum);
  return 0;
}


Measured memory_bytes: 256
n = input()
n = int(n)
list = []

i = 0
while(i<n):
	x = input()
	x = int(x)
	list.append(x)
	i = i + 1

maxv = -2000000000
minv = list[0]
i = 1
while(i<n):
        maxv = max(maxv, list[i]-minv)
        minv = min(minv, list[i])
        i = i + 1
	
print(maxv)



Measured memory_bytes: 13588