akhauriyash/Code-Regression huggingface dataset:
#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"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i,n) for(int i = 0; i < n; i++)
const int INF = 1001001001;

int main() {
	int h, w;
	cin >> h >> w;
	vector<vector<char>> pic(h, vector<char>(w));
	rep(i, h) {
		rep(j, w) cin >> pic[i][j];
	}
	rep(i, 2 * h) {
		for (char c : pic[i / 2]) cout << c;
		cout << endl;
	}
 	return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			while(sc.hasNext()) {
				int n=sc.nextInt();
				int p=sc.nextInt();
				int[] stone=new int[n+1];
				if(n+p==0) break;
				int num=p;
				while(true) {
					int end=0;
					for(int i=0; i<n; i++) {
						if(num==1 && stone[i]==p-1) {
							System.out.println(i);
							end=1;
							break;
						}
						if(num>0) {
							stone[i]++;
							num--;
						}
						else if(num==0 && stone[i]>0) {
							num+=stone[i];
							stone[i]=0;
						}
					}
					if(end==1) break;
				}

			}
			
		}
	}
}


Measured memory_bytes: 27108
N,K = list(map(int,input().split()))
X = list(map(int,input().split()))
l = 0
r = K-1
outs = []
while r<=N-1:
    A = X[l]
    B = X[r]
    if A<0 and B<0:
        out = -1*A
    if A<0 and B>=0:
        out = min(-1*A*2+B,-1*A+2*B)
    if A>=0 and B>=0:
        out = B
    outs.append(out)
    l+=1
    r+=1
print(min(outs))


Measured memory_bytes: 62576
#include <cstdio>
using namespace std;

int main()
{
    int N, K, X, Y;
    scanf("%d %d %d %d", &N, &K, &X, &Y);

    if (K < N)
    {
        printf("%d\n", X * K + (N - K) * Y);
    }
    else
    {
        printf("%d\n", X * N);
    }

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include<stack>
#include <queue>
#include<map>
#include <set>
#include<math.h>
using namespace std;
#define int long long
#define ll long long
#define double long double
#define rep(i,n) for(ll i=0;i<n;++i)
#define loop(i,m,n) for(ll i=m;i<n;++i)
#define ggr getchar(); getchar();return 0;
#define pie 3.141592653589793238462643383279
#define INF 1000000007
#define elif else if
int bin(int bina) {
	int ans = 0;
	for (int i = 0; bina > 0; i++)
	{
		ans = ans + (bina % 2) * pow(10, i);
		bina = bina / 2;
	}
	return ans;
}
bool prime(int n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int jo(int n) {
	int ans = 1;
	rep(i, n) {
		ans *= 2;
	}
	return ans;
}
int a[5];
signed main() {
	int n;
	cin >> n;
	rep(i, 5) {
		cin >> a[i];
	}
	sort(a, a + 5);
	cout << (n - 1) / a[0] + 5 << endl;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long N;
  cin >> N;
  vector<long> P(N);
  for(int i=0; i<N; i++){
    cin >> P.at(i);
  }

  long min = P.at(0);
  long ans = 1;
  for(int i=1; i<N; i++){
    if(min >= P.at(i)){
      ans++;
    }
    min = std::min(min, P.at(i));
  }

  cout << ans << endl;
}

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


const int MAX_N=400010;
const int mod=1000000007;
ll fact[MAX_N+1];
ll inv[MAX_N+1],finv[MAX_N+1];
int inv_init(ll n,ll p){
    inv[1]=1;
    FOR(i,2,n+1) inv[i]=p-(p/i)*inv[p%i]%p;
    fact[0]=finv[0]=1;
    FOR(i,1,n+1){
        fact[i]=fact[i-1]*i%p;
        finv[i]=finv[i-1]*inv[i]%p;
    }
    return 0;
}
ll comb_mod(ll n,ll k,ll p){
    if(k<0||n<k) return 0;
    return finv[k]*finv[n-k]%p*fact[n]%p;
}
int n,k;
int main(){
    cin>>n>>k;
    inv_init(n*2+2,mod);
    ll ans=0;
    rep(i,min(k+1,n)){
        ll tmp=comb_mod(n,i,mod);
        tmp*=comb_mod(i+n-i-1,i,mod);
        ans+=tmp%mod;
        ans%=mod;
    }
    cout<<ans<<endl;
    return 0;
}

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

#define LENGTH 256

int main(void) {
    char input[LENGTH];
    int r, i, cmp;
    int count1 = 0;
    int count2 = 0;
    char n[4];
    fgets(input, LENGTH-1, stdin);
    sscanf(input, "%s", n);

    for(i = 0; i < 4; i++){
        for(r = i + 1; r < 4; r++){
            if(n[i] == n[r]){
                if(count1 == 0 && count2 == 0){
                    count1++;
                }else{
                    count2++;
                } 
            }
        }
    }
    if(count1 == 1 && count2 ==1){
        printf("%s\n","Yes");
    }else{
        printf("%s\n","No");
    }
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using LL=long long;
#define rep(i,n) for(int i=0; i<n; i++)
#define rep1(i,n) for(int i=1; i<n; i++)
#define all(a) (a).begin(),(a).end();

int main(){
  int d;
  cin >> d;
  cout << "Christmas";
  rep(i, 25-d) cout << " Eve";
  cout << endl;
}


Measured memory_bytes: 256
import java.lang.ArithmeticException

fun str() = readLine()!!
fun int() = str().toInt()
fun long() = str().toLong()

fun read(d:String = " ") = str().split(d)
fun <T> list(d:String = " ",f:String.()->T) = read(d).map {f(it)}
fun list() = list {toInt()}.toIntArray()

fun <T> T.print() = this.also(::println)

fun main() {
	abc000X()
}

fun abc000X() {
	val n = int()
	val a = list {toLong()}
	var r = 1L
	if(a.contains(0L)) {
		println(0)
		return
	}
	try {
		for(i in a)
			r = Math.multiplyExact(r,i)
		if(r>1000_000_000_000_000_000)
			throw ArithmeticException()
	} catch(e:ArithmeticException) {
		println(-1)
		return
	}
	println(r)
}


Measured memory_bytes: 62948
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    int n;
    cin >> n;
    vector<vector<ll>> d(n+1, vector<ll>(n+1));
    ll ans = 0;
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= n; j++)
        {
            ll a;
            cin >> a;
            d[i][j] = a;
            ans += a;
        }
    }
    vector<vector<ll>> rec(n+1, vector<ll>(n+1));
    ll del = 0;
    for(int k = 1; k <= n; k++)
    {
        for(int i = 1; i <= n; i++)
        {
            for(int j = 1; j <= n; j++)
            {
                if(d[i][j] > d[i][k] + d[k][j])
                {
                    cout << -1 << endl;
                    return 0;
                }
                else if(d[i][j] == d[i][k] + d[k][j] && i!=k && k!=j && rec[i][j] == false) 
                {
                    del += d[i][j];
                    rec[i][j] = true;
                }
            }
        }
    }
    cout << (ans - del) / 2L << endl;
}



Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	string s;
	cin>>s;ll ans=0;
	ll now=0;
	for(int i=0;i<s.size();i++){
		ll ch=s[i]-'0';
		if(now!=ch){
			ans++;
		}
		now=1-now;
	}
	ll ans2=0;
	now=1;
	for(int i=0;i<s.size();i++){
		ll ch=s[i]-'0';
		if(now!=ch){
			ans2++;
		}
		now=1-now;
	}
	cout << min(ans,ans2);
	// your code goes here
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <limits>
#include <algorithm>

using namespace std;

int compute_digits(int n){
    int counter = 0;
    while(n != 0){
        ++counter;
        n /= 10;
    }
    return counter;
}

int main(int argc, char const *argv[])
{
    long long N;
    cin >> N;
    int answer = numeric_limits<int>::max();
    for(int i = 1 ; 1LL * i * i <= N ; ++i){
        if(N % i == 0){
            int A = i;
            int B = N / i;
            int dA = compute_digits(A);
            int dB = compute_digits(B);
            answer = min(answer, max(dA, dB));
        }
    }
    cout << answer << '\n';
    return 0;
}


Measured memory_bytes: 3592
'use strict'
const main = (input: string) => {
    // 2d+1で取れそう
    const [n, d] = input.split(' ').map(Number)
    const r: number = 2 * d + 1
    if (n % r === 0) {
        console.log(n / r)
    } else {
        console.log(Math.ceil(n / r))
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8')); 


Measured memory_bytes: 7372
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <deque>
#include <numeric>
using lint = long long;

int main()
{
    lint n, k;
    scanf("%lld", &n);
    scanf("%lld", &k);

    std::string s;
    std::cin >> s;

    lint base = 0;

    char cur = '0';

    for (int i = 0; i < n; ++i)
    {
        if (cur == s[i])
        {
            base++;
        }
        cur = s[i];
    }

    lint change_num = 0;

    cur = s[0];

    lint change_flag = -1;
    lint ans = base;

    for (int i = 1; i < n; ++i)
    {
        if (cur != s[i])
        {
            change_flag *= (-1);
            if (change_flag < 0)
            {
                ans += 2;
                change_num++;
            }
        }
        cur = s[i];
        if (change_num == k)
        {
            break;
        }
    }

    if (change_num != k && s.front() != s.back())
    {
        ans++;
    }

    std::cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 512
/**
 *    author:  erekle
 *    created: 19.09.2020 12:42:35
**/
#include <bits/stdc++.h>

using namespace std;

#define fastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define swap2(x,y) x=x^y; y=x^y; x=x^y;

int main() {
	fastIO
	
	string s; cin >> s;
	if (s[(int)s.size()-1] == 's') cout << s << "es" << endl;
	else cout << s << "s" << endl;
	return 0;
}


Measured memory_bytes: 3660
g=0
x=0
w=[input() for i in range(int(input()))]
if len(set(w))==len(w):
   n=w[0][::-1][0]
   for i in range(1,len(w)):
      if w[i][0]==n:
         n=w[i][::-1][0]
      else:break
      x=i
if x==len(w)-1:g=1

print(["No","Yes"][g])

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

using namespace std;
typedef long long LL;
const double pi = acos(-1.0);
const double eps = 1e-7;
const LL N = 10001;

LL T,n,m,i,j,k,t,a,b,c,d,e,f,maxw,maxs,ff[3010]={0};
double mmax=0;

void dfs(LL vol)
{
    ff[vol]=1;
    if(vol+100*a<=f && !ff[vol+100*a])dfs(vol+100*a);
    if(vol+100*b<=f && !ff[vol+100*b])dfs(vol+100*b);
    if(vol){
        LL ub=min(vol/100*e,f-vol),tmax=0;
        LL dp[3010]={1,0};
        for(i=0;i<=ub;i++){
            if(dp[i]){
                if(i+c<=ub){
                    dp[i+c]=1;
                    tmax=max(tmax,i+c);
                }
                if(i+d<=ub){
                    dp[i+d]=1;
                    tmax=max(tmax,i+d);
                }
            }
        }
        if(((double)tmax)/((double)vol+(double)tmax)>mmax){
            mmax=((double)tmax)/((double)vol+(double)tmax);
            maxw=vol;
            maxs=tmax;
        }
    }
}

int main()
{
    scanf("%lld%lld%lld%lld%lld%lld",&a,&b,&c,&d,&e,&f);
    dfs(0);
    if(!maxw)maxw=100*a;
    printf("%lld %lld\n",maxw+maxs,maxs);
    //system("pause");
    return 0;
}


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

int main(){
    using namespace std;
    size_t n;
    cin >> n;
    vector<size_t> in(n), invpre(n), hoge(n);
    for(size_t i = 0, a; i < n; ++i){
        cin >> a;
        invpre[--a] = i;
    }
    for(size_t i = 0; i < n; ++i){
        cin >> in[i];
        hoge[i] = invpre[in[i] - 1];
    }
    vector<size_t> ans;
    stack<pair<size_t, size_t>> st;
    st.emplace(0, n);
    while(!st.empty()){
        auto a = st.top().first, b = st.top().second;
        st.pop();
        if(a == b)continue;
        auto k = min_element(hoge.begin() + a, hoge.begin() + b) - hoge.begin();
        ans.push_back(in[k]);
        st.emplace(a, k);
        st.emplace(k + 1, b);
    }
    for(auto i = n; i; cout << " \n"[!i])cout << ans[--i];
}


Measured memory_bytes: 3156
exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']

require 'prime'

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

def big(a,b) return (a>b)? a:b end

def small(a,b) return (a<b)? a:b end

m1,d1 = inp
m2,d2 = inp
puts (m1 == m2)? 0 : 1



Measured memory_bytes: 6200
#include <iostream>
#include <string>
using namespace std;
int main(){
  int N, M;
  cin >> N >> M;
  int p[1000000];
  int k[1000000] = {};
  string s[1000000];
  int acsum =0;
  int wasum =0;
  int w[1000000] ={};
  for(int i=0;i<M;++i) {
    cin >> p[i] >> s[i];
    if(k[p[i]-1] == 0) {
      if(s[i] == "AC") {
        k[p[i]-1] = 1;
        ++acsum;
        wasum += w[p[i] -1];
      }
      if(s[i] == "WA") ++w[p[i]-1];
    }
    if(k[p[i]-1] == 1) continue;
  }
  cout << acsum << " " << wasum;
}


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

int main(){
  int x,d,c,i;
  cin>>x;
  d=(x-9)%7;
  c = abs(d);
  if(x<=9){    
    string P[7]={"sat","fri","thu","wed","tue","mon","sun"};
    cout<<P[c]<<endl;
  }else{
    string P[7]={"sat","sun","mon","tue","wed","thu","fri"};
    cout<<P[c]<<endl;
  }
  return 0;
}



Measured memory_bytes: 3208
N,K=map(int,input().split())
xlist=list(map(int,input().split()))

dist_list=[]
for i in range(N-K+1):
  #print(xlist[i+K-1]-xlist[i])
  if xlist[i+K-1]<0:
    dist_list.append(-xlist[i])
  elif xlist[i]>0:
    dist_list.append(xlist[i+K-1])
  else:
    dist_list.append(xlist[i+K-1]-xlist[i]+min(-xlist[i],xlist[i+K-1]))
    
#print(dist_list)
print(min(dist_list))

Measured memory_bytes: 15020
#include<bits/stdc++.h>
#define int long long
using namespace std;

const int inf=1e18;
const int N=1e6+5;
int n,a,b,c,d;
map<int,int>dp;

int calc(int n)
{
    if(n==0) return 0;
    if(n==1) return d;
    if(dp.count(n)) return dp[n];
    int res=inf;
    if(n<res/d) res=n*d;
    int v=n/2;
    res=min(res,d*abs(v*2-n)+a+calc(v));
    if(v+1!=n) res=min(res,d*abs((v+1)*2-n)+a+calc(v+1));
    v=n/3;
    res=min(res,d*abs(v*3-n)+b+calc(v));
    if(v+1!=n) res=min(res,d*abs((v+1)*3-n)+b+calc(v+1));
    v=n/5;
    res=min(res,d*abs(v*5-n)+c+calc(v));
    if(v+1!=n) res=min(res,d*abs((v+1)*5-n)+c+calc(v+1));
    dp[n]=res;
    return res;
}

main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin>>t;
    while(t--)
    {
        dp.clear();
        cin>>n>>a>>b>>c>>d;
        cout<<calc(n)<<endl;
    }
}


Measured memory_bytes: 4716
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ll N;
  cin >> N;
  vector<ll> A(N+2);
  for(ll i = 1;i<N+1;i++){
    cin >> A[i];
  }
  ll summoto = 0;
  for(ll i = 0;i<N+1;i++){
    summoto += abs(A[i]-A[i+1]);
  }

  vector<ll> ans(N);
  for(ll i = 1;i<N+1;i++){
    ans[i-1] = summoto - (abs(A[i-1]-A[i]) +abs(A[i]-A[i+1])) + abs(A[i-1]-A[i+1]);
  }
   for(ll i = 0;i<N;i++){
     cout << ans[i] << endl;
   }
                                     
}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
// increment
#define rep_n(_1, _2, _3, NAME, ...) NAME
#define rep_2(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep_3(i, initial, n) for (int i = (int)(initial); i < (int)(n); ++i)
#define repeat(...) rep_n(__VA_ARGS__, rep_3, rep_2, rep_1)(__VA_ARGS__)
// decrement
#define rep_r_n(_1, _2, _3, NAME, ...) NAME
#define rep_r_2(i, n) for (int i = (int)(n); i > 0; i--)
#define rep_r_3(i, initial, n) for (int i = (int)(initial); i > (int)(n); i--)
#define repeat_r(...) rep_r_n(__VA_ARGS__, rep_r_3, rep_r_2)(__VA_ARGS__)
// define variable
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const double EPS = numeric_limits<double>::epsilon();
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main()
{
	int N = 0;
	cin >> N;

	vector<ll> l(N, 0), s_l(N, 0);

	repeat(i, N) {
		ll x = 0;
		cin >> x;
		l[i] = x;
		s_l[i] = x;
	}

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

	int mid = N/2;
	ll val_1 = s_l[mid], val_2 = s_l[mid-1];
	map<ll, ll> ans;

	repeat(i, N) {
		ans[ s_l[i] ] = (i < mid) ? val_1 : val_2;
	}

	repeat(i, N) {
		cout << ans[ l[i] ] << endl;
	}

	return 0;
}


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

using ll =long long;

//最大公約数
ll gcd(ll a, ll b){
   if (a%b == 0){
       return(b);
   }else{
       return(gcd(b, a%b));
   }
}
//最小公倍数
ll lcm(ll a, ll b){
   return a * b / gcd(a, b);
}

//文字列→数列
//string S;int A=atoi(S.c_str());
//数列→文字列
//int A;string S=to_string(A);
//数字判定　isdigit(a)
//pair宣言　pair<int,int> p(5,7);
//

int main(){
cout<<fixed<<setprecision(10);
  
  
  string S,T;
  int A,B;
  string U;
  cin>>S>>T>>A>>B>>U;
  if(U==S){
    cout<<A-1<<" "<<B;}
  else{cout<<A<<" "<<B-1<<endl;
      }
  
  
  
  
  
}


Measured memory_bytes: 256
#![allow(unused_parens)]
#![allow(unused_imports)]
#![allow(non_upper_case_globals)]
#![allow(non_snake_case)]
#![allow(unused_mut)]
#![allow(unused_variables)]
#![allow(dead_code)]

use itertools::Itertools;
use proconio::input;
use proconio::marker::{Chars, Usize1};

#[allow(unused_macros)]
#[cfg(debug_assertions)]
macro_rules! mydbg {
    //($arg:expr) => (dbg!($arg))
    //($arg:expr) => (println!("{:?}",$arg));
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
      }
}
#[cfg(not(debug_assertions))]
macro_rules! mydbg {
    ($($arg:expr),*) => {};
}

macro_rules! echo {
    ($($a:expr),*) => {
          $(println!("{}",$a))*
      }
}

use std::cmp::*;
use std::collections::*;
use std::ops::{Add, Div, Mul, Sub};

#[allow(dead_code)]
static INF_I64: i64 = 92233720368547758;
#[allow(dead_code)]
static INF_I32: i32 = 21474836;
#[allow(dead_code)]
static INF_USIZE: usize = 18446744073709551;
#[allow(dead_code)]
static M_O_D: usize = 1000000007;
#[allow(dead_code)]
static PAI: f64 = 3.1415926535897932;

trait IteratorExt: Iterator {
    fn toVec(self) -> Vec<Self::Item>;
}

impl<T: Iterator> IteratorExt for T {
    fn toVec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

trait CharExt {
    fn toNum(&self) -> usize;
    fn toAlphabetIndex(&self) -> usize;
    fn toNumIndex(&self) -> usize;
}
impl CharExt for char {
    fn toNum(&self) -> usize {
        return *self as usize;
    }
    fn toAlphabetIndex(&self) -> usize {
        return self.toNum() - 'a' as usize;
    }
    fn toNumIndex(&self) -> usize {
        return self.toNum() - '0' as usize;
    }
}

trait VectorExt {
    fn joinToString(&self, s: &str) -> String;
}
impl<T: ToString> VectorExt for Vec<T> {
    fn joinToString(&self, s: &str) -> String {
        return self
            .iter()
            .map(|x| x.to_string())
            .collect::<Vec<_>>()
            .join(s);
    }
}

trait StringExt {
    fn get_reverse(&self) -> String;
}
impl StringExt for String {
    fn get_reverse(&self) -> String {
        self.chars().rev().collect::<String>()
    }
}

trait UsizeExt {
    fn pow(&self, n: usize) -> usize;
}
impl UsizeExt for usize {
    fn pow(&self, n: usize) -> usize {
        return ((*self as u64).pow(n as u32)) as usize;
    }
}

fn main() {
    use itertools_num::ItertoolsNum as _;
    input! {
       mut A: usize,
       mut B:usize,
       mut C:usize,
       K:usize,
    }

    let mut ans: usize = 0;
    for _ in 0..K + 1 {
        mydbg!(A, B, C);
        if B > A && C > B {
            echo!("Yes");
            return;
        }
        if B <= A {
            B *= 2;
        } else if C <= B {
            C *= 2;
        }
    }

    echo!("No");
}


Measured memory_bytes: 2136
/* C/C++ program to remove invalid parenthesis */
#include <bits/stdc++.h> 
using namespace std; 
#define ll long long int
#define inf 1e9+1
int main() 
{ 
   ll n,W;
   cin>>n>>W;
   ll w[n+1],v[n+1];
   for(ll i=1;i<=n;i++)
   cin>>w[i]>>v[i];
   ll range=n*1000;
   ll dp[n+1][range+1];
   for(int i=0;i<=range;i++)
    dp[1][i]=inf;
   
   dp[1][0]=0;
   dp[1][v[1]]=w[1];
   for(int i=2;i<=n;i++)
   {
       for(int j=0;j<=range;j++)
       {
           dp[i][j]=dp[i-1][j];
           if(j>=v[i])
           {
               dp[i][j]=min(dp[i][j],dp[i-1][j-v[i]]+w[i]);
           }
       }
   }
   int ans=0;
   for(int i=0;i<=range;i++){
       if(dp[n][i]<=W)
       ans=i;
   }
   cout<<ans;
	return 0; 
} 


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

Measured memory_bytes: 572
#include <iostream>
#include <queue>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

#include <set>

using namespace std;

int a[500][500];


int main(){
  const int h = getInt();
  const int w = getInt();
  REP(i,h) REP(j,w) a[i][j] = getInt();

  vector<pair<int, int> > v;
  REP(i,h) REP(j,w-1) if(a[i][j] % 2 == 1){
    a[i][j]--; a[i][j + 1]++;
    v.push_back(make_pair(i, j));
  }

  REP(i,h-1) if(a[i][w - 1] % 2 == 1){
    a[i][w - 1]--; a[i + 1][w - 1]++;
    v.push_back(make_pair(i, w - 1));
  }

  printf("%d\n", (int)v.size());
  for(const auto p : v){
    const int x = p.second + 1;
    const int y = p.first + 1;
    if(x == w) printf("%d %d %d %d\n", y, x, y + 1, x);
    else printf("%d %d %d %d\n", y, x, y, x + 1);
  }

  return 0;
}

Measured memory_bytes: 4212
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long ans = 0;
        for(int i = 0; i < n; i++) {
            long l = sc.nextInt();
            long count = 0;
            while(l%2==0) {
                l/=2;
                count++;
            }
            ans += count;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 34012
def main_C1():

  N = int(input())
  a = [[int(item) for item in input().split()] for i in range(N)]
  
  dp = [[0, 0, 0] for i in range(N+1)]

  for i in range(N):
    for j in range(3):
      for k in range(3):
        if j == k:
          continue
        dp[i+1][k] = max(dp[i+1][k], dp[i][j] + a[i][k])
  
  print(max(dp[-1]))

if __name__ == "__main__":
  main_C1()
  # print(list(input_gen()))


Measured memory_bytes: 44092
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

int main() {
    int N;cin >> N;
    ll ans = 0LL;
    for (int i = 0; i < N; ++i) {
        ll a; cin >> a;
        ans += a - 1LL;
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 504
n,a,b=map(int,input().split())

if (a-b)%2 ==0:
    print((b-a)//2)
else:
    cand1=max(n-a,n-b)
    cand2=max(a-1,b-1)
    cand_edge = min(cand1,cand2)
    
    cand_reflect_right = n-b+1+(b-a-1)//2
    cand_reflect_left  = a    +(b-a-1)//2
    
    print( min( cand_edge,cand_reflect_left,cand_reflect_right))

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

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

  int freq[26];
  memset(freq, 0, sizeof(freq));
  for(char ch : s) freq[ch-'a']++;

  long long ans = 1ll * s.size() * (s.size()-1) / 2;
  for(int i=0; i<26; i++){
    ans -= 1ll * freq[i] * (freq[i]-1) / 2;
  }
  ans++;

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

Measured memory_bytes: 3724
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>
#include <bitset>
 
using namespace std;
 
/* template */
 
using ll = long long;
 
void debug_out() { std::cout << std::endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}
 
#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif
 
#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n-1ll)); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
struct Edge{
    int to;
    ll weight;
    Edge(int t, ll w) : to(t), weight(w){ }
};
 
struct edge{
    int from;
    int to;
    ll weight;
    edge(int f,int t,ll w) : from(f), to(t), weight(w){ }
};
 
 
using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;
 
template <class T>
inline bool chmin(T &a, T b){
    if (a > b){
        a = b;
        return true;
    }
    return false;
}
 
template <class T>
inline bool chmax(T &a, T b){
    if (a < b){
        a = b;
        return true;
    }
    return false;
}
 
template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}
 
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
 
constexpr ll LNF = 1LL<<50;
 
constexpr int INF = 1e9+7;
 
const long double PI=3.14159265358979323846;
 
 
vector<int> dx = {1,0,-1,1,-1,0};
vector<int> dy = {1,1,1,0,0,-1};
 
/* template */

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll x,k,d; cin >> x >> k >> d;
    x = abs(x);
    ll p = x/d;
    chmin(p,k);
    x -= d*p;
    if(p<k){
        if((k-p)%2==0){
            cout << x << endl;
        }
        else{
            cout << abs(x-d) << endl;
        }
    }
    else{
        cout << x << endl;
    }
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
// O(n loglog n)
void eratosthenes(long long n, vector<bool>& table, vector<long long>& primes)
{
	table.resize(n+1);
	fill(table.begin(), table.end(), true);
	if (n >= 0)
		table[0] = false;
	if (n >= 1)
		table[1] = false;
	for (int i = 2; i*i <= n; i++) {
		if (table[i] == false)
			continue;
		for (int j = i+i; j <= n; j+=i) {
			table[j] = false;
		}
	}
	for (int i = 0; i < n+1; i++) {
		if (table[i])
			primes.push_back(i);
	}
}
int main(void)
{
	int n;
	cin >> n;
	vector<bool> table;
	vector<long long> primes;
	eratosthenes(55555, table, primes);
	vector<long long> p1, p2, p3, p4;
	for (int i = 0; i < primes.size(); i++) {
		if (primes[i]%5 == 1)
			p1.push_back(primes[i]);
		else if (primes[i]%5 == 2)
			p2.push_back(primes[i]);
		else if (primes[i]%5 == 3)
			p3.push_back(primes[i]);
		else if (primes[i]%5 == 4)
			p4.push_back(primes[i]);
	}
	for (int i = 0; i < 4; i++) {
		switch (i) {
			case 0:
				if (p1.size() >= n) {
					for (int i = 0; i < n; i++)
						printf("%lld ", p1[i]);
					cout << endl;
					return 0;
				}
				break;
			case 1:
				if (p2.size() >= n) {
					for (int i = 0; i < n; i++)
						printf("%lld ", p2[i]);
					cout << endl;
					return 0;
				}
				break;
			case 2:
				if (p3.size() >= n) {
					for (int i = 0; i < n; i++)
						printf("%lld ", p3[i]);
					cout << endl;
					return 0;
				}
				break;
			case 3:
				if (p4.size() >= n) {
					for (int i = 0; i < n; i++)
						printf("%lld ", p4[i]);
					cout << endl;
					return 0;
				}
				break;
		}
	}
	return 0;
}

Measured memory_bytes: 3804
#define _DEBUG 1
#define _GLIBCXX_DEBUG

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

using ll = long long;

#ifdef _DEBUG
#define dump(x) cerr << #x << "=" << x << endl
#define dump2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define dump3(x, y, z)                                                         \
  cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z     \
       << endl
#define check(s) cerr << s << endl
#else
#define dump(x)
#define dump2(x, y)
#define dump3(x, y, z)
#define check(s)
#endif

#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());

void yes() { cout << "Yes" << endl; }
void no() { cout << "No" << endl; }
void yesOrNo(bool flg) {
  if (flg)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

bool isKaibun(string S) {
  int i = 0;
  int j = sz(S) - 1;

  while (i < j) {
    if (S.at(i) == S.at(j)) {
      i++;
      j--;
    } else {
      return false;
    }
  }
  return true;
}

void solve(std::string S) {
  bool result = false;

  if (isKaibun(S)) {
    ll N = sz(S);
    string s1 = S.substr(0, (N - 1) / 2);
    if (isKaibun(s1)) {
      string s2 = S.substr((N + 3) / 2 - 1, (N - 1) / 2);
      result = isKaibun(s2);
    }
  }

  yesOrNo(result);
}

int main() {
  std::string S;
  std::cin >> S;
  solve(S);
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define M 500000
int c;
void merge(int left,int mid,int right,int A[]){
  int i,j=0,k;
  int n1 = mid-left;
  int n2 = right-mid;
  int L[n1],R[n2];
  for(i = 0;i<n1;i++)L[i]=A[left+i];
  for(i = 0;i<n2;i++)R[i]=A[mid+i];
   
    L[n1]=R[n2]=999999999;
  i=0;
  for(k = left;k< right;k++){
   c++;
   if(L[i]<=R[j])A[k]=L[i++];
    else A[k]=R[j++];
  }
   
}
void mergeSort(int left,int right,int A[]){
  if(left >= right-1 )return;
  int mid = (left+right)/2;
  mergeSort(left,mid,A);
  mergeSort(mid,right,A);
  merge(left,mid,right,A);
   
}
int main (void){
  int size,A[M];
  int i;
  scanf("%d",&size);
  for(i = 0;i<size;i++)scanf("%d",&A[i]);
  mergeSort(0,size,A);
  for(i = 0;i<size;i++){
    if(i==0)printf("%d",A[i]);
    else printf(" %d",A[i]);
  }
  printf("\n%d\n",c);
   
   
  return 0;
}



Measured memory_bytes: 5632
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
#define PI 3.14159265359
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int R;
  cin >> R;
  double ans = 2 * PI * R;
  cout << ans << endl;
 
  return 0;
}

Measured memory_bytes: 3792
#include <stdio.h>

int main()
{   int n;
    scanf("%d",&n);
    int a[n+1],b[n];
    for(int i=0;i<n+1;i++){
        scanf("%d",&a[i]);
        }
    for(int i=0;i<n;i++){
        scanf("%d",&b[i]);
    }
    long long ans=0;
    for(int i=0;i<n;i++){
        if(b[i]<=a[i]){
            ans+=b[i];
        }else{
            b[i]-=a[i];
            ans+=a[i];
            if(b[i]<=a[i+1]){
                a[i+1]-=b[i];
                ans+=b[i];
            }else{
                ans+=a[i+1];
                a[i+1]=0;
            }
        }
    }
    printf("%lld",ans);

    return 0;
}


Measured memory_bytes: 896
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    
    List<List<Integer>> nodes = new ArrayList<>();
    for (int i = 0; i <= N; i++) {
      nodes.add(new ArrayList<>());
    }
    for (int i = 0; i < M; i++) {
      int a = sc.nextInt();
      int b = sc.nextInt();
      nodes.get(a).add(b);
    }
    
    // dfs
    boolean success = dfs(1, N, 0, nodes);
    
    System.out.println(success ? "POSSIBLE" : "IMPOSSIBLE");
  }
  
  private static boolean dfs(int from, int to, int depth, List<List<Integer>> nodes) {
    
    if (depth > 2) {
      return false;
    }
    if (from == to) {
      return true;
    }
    
    List<Integer> nextNodes = nodes.get(from);
    for (int nextNode : nextNodes) {
      if (dfs(nextNode, to, depth+1, nodes)) {
        return true;
      }
    }
    
    return false;
  }
}

Measured memory_bytes: 123008
#!/usr/bin/env python
"""<https://github.com/cheran-senthil/PyRival>"""
from __future__ import division, print_function

import collections
import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip
else:
    _str = str
    str = lambda x=b"": x if type(x) is bytes else _str(x).encode()


def main():
    N, Q = read_int_array()
    add, delete = [], []
    for i in range(N):
        S, T, X = read_int_array()
        add.append((S - X, X))
        delete.append((T - X, X))

    active = []
    to_delete = collections.defaultdict(int)
    import heapq
    heapq.heapify(add)
    heapq.heapify(delete)
    for _ in range(Q):
        x = read_int()
        while add and add[0][0] <= x:
            coord, val = heapq.heappop(add)
            heapq.heappush(active, val)

        while delete and delete[0][0] <= x:
            coord, val = heapq.heappop(delete)
            to_delete[val] += 1

        while active and to_delete[active[0]] > 0:
            to_delete[active[0]] -= 1
            heapq.heappop(active)

        print(active[0] if active else -1)


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._buffer = BytesIO()
        self._fd = file.fileno()
        self._writable = "x" in file.mode or "r" not in file.mode
        self.write = self._buffer.write if self._writable else None

    def read(self):
        if self._buffer.tell():
            return self._buffer.read()
        return os.read(self._fd, os.fstat(self._fd).st_size)

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self._buffer.tell()
            self._buffer.seek(0, 2), self._buffer.write(b), self._buffer.seek(ptr)
        self.newlines -= 1
        return self._buffer.readline()

    def flush(self):
        if self._writable:
            os.write(self._fd, self._buffer.getvalue())
            self._buffer.truncate(0), self._buffer.seek(0)


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", b" "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", b"\n"))
    if kwargs.pop("flush", False):
        file.flush()


sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip(b"\r\n")

# endregion


def read():
    return input()


def read_array(sep=None, maxsplit=-1):
    return read().split(sep, maxsplit)


def read_int():
    return int(read())


def read_int_array(sep=None, maxsplit=-1):
    return [int(a) for a in read_array(sep, maxsplit)]


if __name__ == "__main__":
    main()


Measured memory_bytes: 132348
#include <iostream>

using namespace std;

long long int X;

int main(void) {

	cin >> X;

	long long int sum = 0;

	long long int I;
	for (I = 1;; I++) {
		sum += I;
		if (sum >= X) { break; }
	}

	cout << I << endl;

	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<cmath>
#include<cstdlib>
using namespace std;
using lli = long long int;

int main() {
    int x;
    cin >> x;
    int m = 100010;
    vector<bool> p(m, true);
    p[0] = p[1] = false;
    for (int i = 2; i < (int)sqrt(m); i++) {
        if (p[i] == false) {
            continue;
        }
        for (int j = i * 2; j < m; j += i) {
            p[j] = false;
        }
    }
    for (int i = x; i < m; i++) {
        if (p[i]) {
            cout << i << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k,x,y,c=1,i,sum=0;
    cin>>n>>k>>x>>y;
    for(i=0;i<n;i++)
    {
        if(c<=k){
           sum+=x;
           c++;
        }
        else
            sum+=y;
    }
    cout<<sum<<endl;


}


Measured memory_bytes: 384
n=int(input())
h=list(map(int,input().split()))
dp=[0]*n
dp[0]=0
dp[1]=abs(h[1]-h[0])
for i in range(2,n):
    dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
print(dp[n-1])

Measured memory_bytes: 13928
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Vec2(T, n, m, xs) vector<vector<T>> xs(n, vector<T>(m))
#define Sum(a) accumulate(Range(a), 0)
#define Cusum(T, n, xs, sxs) vector<T> sxs(n+1); For(i, n) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) for(const auto &e : xs) cout << e << "\n"; cout << "\n"
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")

int main(void){
    Cin(string, s);
    unordered_map<char, int> m;
    For(i, (int)s.size()) m[s[i]] ++;
    
    bool f = true;
    for(const auto &e : m){
        if(e.second % 2 == 1){ f = false; break; }
    }
    CoutYn(f);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
ll n, k;
ll solve(ll x) {
    return x * x * x;
}
int main() {
    srand(time(0));
    ios_base::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    cin >> n >> k;
    if (k & 1) cout << solve(n / k);
    else cout << solve(n / k) + solve((n + k / 2) / k);
    return 0;
}

Measured memory_bytes: 256
import numpy as np
from copy import deepcopy


def main():
    height, width = map(int, input().split())
    grid = [list(input()) for _ in range(height)]
    grid = (np.array(grid) == ".") * 1
    left = np.zeros((height, width), dtype=int)
    right = deepcopy(left)
    upper = deepcopy(left)
    down = deepcopy(left)

    for i in range(height):
        if i == 0:
            upper[i] = grid[i]
        else:
            upper[i] = (upper[i - 1] + 1) * grid[i]

    for i in range(width):
        if i == 0:
            left[:, i] = grid[:, i]
        else:
            left[:, i] = (left[:, i - 1] + 1) * grid[:, i]

    for i in range(width - 1, -1, -1):
        if i == width - 1:
            right[:, i] = grid[:, i]
        else:
            right[:, i] = (right[:, i + 1] + 1) * grid[:, i]

    for i in range(height - 1, -1, -1):
        if i == height - 1:
            down[i] = grid[i]
        else:
            down[i] = (down[i + 1] + 1) * grid[i]

    print(np.max(left + right + upper + down - 3))


if __name__ == '__main__':
    main()



Measured memory_bytes: 266604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> P3;
const ll MOD = 1000000007;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e4 + 5);
const double EPS = 1e-11;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

int main() {
    int n, m;
    P smax[MAX_N], smin[MAX_N];
    while(cin >> n >> m, n){
        REP(i,n){
            smax[i] = {0,i};
            smin[i] = {0,i};
        }
        REP(i,m){
            int s, k;
            cin >> s >> k;
            REP(j,k){
                int c;
                cin >> c;
                c--;
                smax[c].first += s;
                if(k==1)smin[c].first += s;
            }
        }
        sort(smin,smin+n);
        sort(smax,smax+n);
        reverse(smax,smax+n);
        if(smax[0].second!=smin[0].second){
            cout << smax[0].first-smin[0].first+1 << endl;
        }
        else{
            cout << max(smax[0].first-smin[1].first, smax[1].first-smin[0].first)+1 << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3244
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<n;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 ALL(a) a.begin(),a.end()
typedef long long ll;
#define INF 1<<30

int main()
{
    float N,X;
    int T;
    cin >> N >> X >> T;
    cout << (int)ceil(N/X)*T << endl;
    return 0;
}

Measured memory_bytes: 3716
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
double distance(double x, double y, double z){
  return sqrt(x*x+y*y+z*z);
}

int main(){
  int N;
  while(cin>>N && N){
    double sx[500], sy[500], sz[500];
    double sd[500];
    bool sight[500] = {};
    REP(i, N) {
      cin>>sx[i]>>sy[i]>>sz[i];
      sd[i] = distance(sx[i], sy[i], sz[i]);
    }
    int M;
    cin>>M;
    int ans = 0;
    REP(iter, M){
      double tx, ty, tz, tp;
      cin>>tx>>ty>>tz>>tp;
      double Q = distance(tx, ty, tz);
      REP(i, N)if(!sight[i]){
        double P = sd[i];
        double R = distance(sx[i] - tx, sy[i] - ty, sz[i] - tz);
        double theta = acos((P*P + Q*Q - R*R)/(2.0*P*Q));
        if(theta < tp) {
          ans ++;
          sight[i] = true;
        }
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1312
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

s = input()
n = len(s)
ans = 0
lst = ['A','T','G','C']
for i in range(n):
    if s[i] not in lst:
        continue
    cnt = 0
    for j in range(i,n):
        if s[j] not in lst:
            break
        cnt += 1
    ans = max(ans,cnt)
print(ans)

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

const int INF = 100;
const int MAX = 50;
const int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
int field[MAX][MAX];
bool visited[MAX][MAX][MAX][MAX];

typedef pair<int, int> P;
typedef pair<P, P> Q;
typedef pair<int, Q> S;

bool check(int x, int y, int w, int h)
{
    return(x >= 0 && x < w && y >= 0 && y < h && field[y][x] == 0);
}

int main()
{
    int w, h, tx, ty, kx, ky;
    while(cin >> w >> h && w) {

        cin >> tx >> ty >> kx >> ky;
        for(int i = 0; i < h; i++) {
            for(int j = 0; j < w; j++) {
                cin >> field[i][j];
                for(int k = 0; k < h; k++) 
                    for(int l = 0; l < w; l++)
                        visited[i][j][k][l] = false;
            }
        }

        queue<S> que;
        int min = INF;
        que.push(S(0, Q( P(tx - 1, ty - 1), P(kx - 1, ky - 1))));
        while(!que.empty()) {
            S s = que.front(); que.pop();
            int x1, y1, x2, y2, step;
            step = s.first;
            x1 = s.second.first.first;
            y1 = s.second.first.second;
            x2 = s.second.second.first;
            y2 = s.second.second.second;
            
            if(x1 == x2 && y1 == y2) {
                min = step;
                break;
            }

            for(int k = 0; k < 4; k++) {
                int nx1, ny1, nx2, ny2;
                nx1 = x1 + dx[k];
                ny1 = y1 + dy[k];
                nx2 = x2 - dx[k];
                ny2 = y2 - dy[k];
                if(!check(nx1, ny1, w, h)) {
                    nx1 = x1;
                    ny1 = y1;
                }
                if(!check(nx2, ny2, w, h)) {
                    nx2 = x2;
                    ny2 = y2;
                }

                if(visited[nx1][ny1][nx2][ny2])
                    continue;
                visited[nx1][ny1][nx2][ny2] = true;
                que.push(S(step + 1, Q(P(nx1, ny1), P(nx2, ny2))));
            }
        }
        if(min == INF)
            cout << "NA" << endl;
        else 
            cout << min << endl;
    }
    
}

Measured memory_bytes: 7352
//#define NDEBUG

#include <bits/stdc++.h>
#include <bits/extc++.h>

#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define iter(a) a.begin(), a.end()
#define riter(a) a.rbegin(), a.rend()
#define lsort(a) sort(iter(a))
#define gsort(a) sort(riter(a))
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define pf(a) push_front(a)
#define pob pop_back()
#define pof pop_front()
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
#define mt make_tuple
#define gt(t, i) get<i>(t)
#define iceil(a, b) (((a) + (b) - 1) / (b))
#define tomax(a, b) ((a) = max((a), (b)))
#define printv(a, b) {bool pvaspace=false; \
for(auto pva : a){ \
    if(pvaspace) b << " "; pvaspace=true;\
    b << pva;\
}\
b << "\n";}

//#define TEST

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;
using tiii = tuple<int, int, int>;

const ll MOD = 1000000007;
const ll MAX = 2147483647;

template<typename A, typename B>
ostream& operator<<(ostream& o, pair<A, B> p){
    return o << '(' << p.F << ',' << p.S << ')';
}

vector<ll> sz, p;

ll f(ll n, ll x){
    if(n == 0) return 1;
    if(x == sz[n]) return p[n];
    ll sum = 0;
    if(x > 1) sum += f(n - 1, min(x - 1, sz[n - 1]));
    if(x > sz[n] / 2 + 1) sum += f(n - 1, min(x - (sz[n] / 2 + 1), sz[n - 1]));
    if(x >= sz[n] / 2 + 1) sum += 1;
    return sum;
}

int main(){
    StarBurstStream

    ll n, x;
    cin >> n >> x;

    sz.resize(51);
    p.resize(51);
    sz[0] = 1; p[0] = 1;
    for(int i = 1; i <= 50; i++) sz[i] = sz[i - 1] * 2 + 3, p[i] = p[i - 1] * 2 + 1;
    cout << f(n, x) << "\n";

    return 0;
}

Measured memory_bytes: 256