akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <cmath>
#include <climits>
using namespace std;

int main(void){
    // Your code here!
    long long n, max_value = 0, min_value = LLONG_MAX;
    vector<long long> x;
    
    cin >> n;
    for(long long i = 0; i < n; i++){
        long long temp;
        cin >> temp;
        x.push_back(temp);
        max_value = max(max_value, temp);
    }
    
    for(auto i:x){
        if(abs((double)max_value / 2 - min_value) >= abs((double)max_value / 2 - i))
            min_value = i;
    }
    
    cout << max_value << ' ' << min_value << endl;
    
    return 0;
}


Measured memory_bytes: 1400
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <map>

typedef long long ll;
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ALL(a) begin(a), end(a)
#define mii map<int, int>
#define msi map<string, int>
#define vi vector<int>
#define vl vector<ll>
#define MOD 1000000007
#define INF 1e9
using namespace std;
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;
}
int main() {
    int N;
    cin >> N;
    vi a(N);
    rep(i, 0, N) {
        cin >> a[i];
    }
    int answer = 0;
    while (*max_element(a.begin(), a.end()) > 0) {
        int i = 0;
        while (i < N) {
            if (a[i]  == 0) {
                ++i;
            } else {
                while(i < N && a[i] > 0) {
                    --a[i];
                    ++i;
                }
                ++answer;
            }
        }
    }

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

Measured memory_bytes: 256
// D - Digit Dum Replace

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int main() {
	int M;
	cin >> M;

	ll d, c;
	ll q = 0;
	ll r = -1;
	ll D = 0;
	for (int i=0; i<M; i++) {
		cin >> d >> c;
		q += (d * c + r) / 9;
		r = (d * c + r) % 9;
		D += c;
	}

	ll ans = (D - 1) + q;

	cout << ans << endl;

	return 0;
}

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

const int maxn=500005;
const int mod=998244353;
int n,k;
int fac[maxn],ifac[maxn];

int binom(int a,int b){
	if(a<b||a<0||b<0)return 0;
	return 1LL*fac[a]*ifac[b]%mod*ifac[a-b]%mod;
}

int calc(int a,int b){
	if(a<n||a<b)return 0;
	if(a-b>=n)return binom(a+b,a);
	return (binom(a+b-(a==b),a)-binom(a+b-(a==b),2*a-n+1)+mod)%mod;
} 

int main(){
	scanf("%d%d",&n,&k);
	fac[0]=ifac[0]=fac[1]=ifac[1]=1;
	for(int i=2;i<=k;i++){
		fac[i]=1LL*fac[i-1]*i%mod;
		ifac[i]=1LL*ifac[mod%i]*(mod-mod/i)%mod;
	}
	for(int i=1;i<=k;i++)ifac[i]=1LL*ifac[i-1]*ifac[i]%mod;
	int ans=0;
	for(int i=0;i<=k;i++)ans=(ans+calc(i,k-i))%mod;
	printf("%d\n",ans);
	return 0;
}

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

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs

using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <class It> bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It> bool any(It f,It l){return std::any_of(f,l,id<bool>);}
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }

int main()
{
  fastio();

  int n; cin >> n;

  for (int i = 1; i < 10; i++)
    for (int j = 1; j < 10; j++)
      if (i * j == n) {
        cout << "Yes" << endl;
        return 0;
      }

  cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
fun main() {
    var (n, k) = readLine()!!.split(" ").map { it.toInt() }
    val dislikeList = readLine()!!.split(" ")
    var canPurchase = false
    while (!canPurchase) {
        var count = 0
        for (i in 0 until k) {
            if (n.toString().contains(dislikeList[i])) {
                count++
            }
        }
        if (count == 0) {
            canPurchase = true
        }
        n++
    }
    println(n - 1)
}

Measured memory_bytes: 53492
rectArray = []

h, w = input().split()
h = int(h)
w = int(w)

while h != 0 and w != 0:
    rectArray.append([h, w])
    h, w = input().split()
    h = int(h)
    w = int(w)

for x in rectArray:
    for i in range(x[0]):
        for j in range(x[1]):
            print("#", end = '')
        print("")
    print("")

Measured memory_bytes: 9052
{-# LANGUAGE LambdaCase #-}

module Main where

import           Control.Monad.Trans.State
import Control.Monad
import Data.List
import Control.Arrow

type Scanner = State [String]

runScanner :: Scanner a -> String -> a
runScanner = runScannerWith $ concat . map words . lines

runScannerWith :: (String -> [String]) -> Scanner a -> String -> a
runScannerWith t s = evalState s . t

str :: Scanner String
str = get >>= \case { s:ss -> put ss >> return s }

int :: Scanner Int
int = read <$> str

numberOf :: Scanner a -> Scanner [a]
numberOf s = int >>= flip replicateM s

showListMy :: Show a => [a] -> String
showListMy = foldr (\x y-> show x ++ " " ++ y) "" 

main = interact $
    runScanner (numberOf int) >>> flip zip [1..] >>> sort >>> map snd >>> showListMy

Measured memory_bytes: 28284
#include <bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define pll pair<ll,ll>
#define pint pll
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

map<pint,ll> cnt,refe;
map<pint,bool> used;

long long modpow(long long a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a) {
    return modpow(a, mod - 2);
}

int main(){
  int n;
  cin >> n;
  ll ans=1,zero=0;
  rep(i,n){
    ll x,y;
    cin >> x >> y;
    if(x==0 && y==0){
      zero++;
      continue;
    }
    if(x<0){
      x*=-1;
      y*=-1;
    }
    ll z=__gcd(x,y);
    cnt[{x/z,y/z}]++;
    refe[{x/z,y/z}]++;
  }
  for(auto i : cnt){
    pint p=i.first;
    ll nx=p.first,ny=p.second;
    if(used[{nx,ny}])continue;
    ll temp=modpow(2,refe[{nx,ny}]);
//    cout << temp << 'y' << endl;
    used[{nx,ny}]=true;
    if(ny<0){
      ny*=-1;
      nx*=-1;
    }
    nx*=-1;
    ll g=__gcd(nx,ny);
    nx/=g;
    ny/=g;
    used[{ny,nx}]=true;
    ll nc=refe[{ny,nx}];
//    cout << nc << 'u' << endl;
    temp+=(modpow(2,nc));
    temp--;
//    cout << temp << endl;
    temp%=mod;
    ans*=temp;
    ans%=mod;
  }
//  ans*=modinv(2);
//  ans%=mod;  
  ans+=mod-1;
  ans%=mod;
  ans+=zero;
  ans%=mod;
  cout << ans << endl;
return 0;}

Measured memory_bytes: 65908
#include<cstdio>
#define MAX_A 1000000
#define MIN_A -1000000

int n, a;

int main(void){
	scanf("%d", &n);

	int min = MAX_A + 1;
	int max = MIN_A - 1;
	long long int sum = 0;
	for( int i = 1 ; i <= n ; i++ ){
		scanf("%d", &a);
		
		if(a < min) min = a;
		if(a > max) max = a;
		sum += a;
	}

	printf("%d %d %lld\n", min, max, sum);

	return 0;
}

Measured memory_bytes: 2752
def BubleSort(l):
    cnt = 0

    for idx in range(len(l), 0, -1):
        for jdx in range(1, idx):
            if l[jdx] < l[jdx-1]:
                l[jdx-1], l[jdx] = l[jdx], l[jdx-1]
                cnt += 1

    print(" ".join(map(str, l)))
    print(cnt)

def main():
    _ = input()
    in_list = list(map(int, input().split(' ')))
    BubleSort(in_list)

main()


Measured memory_bytes: 5596
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <iomanip>
using namespace std;
using Int = long long;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,f,t) for(int i=f;i<t;i++)
#define P(r) do{cout<<#r": ";for(const auto &i:r){cout<<i<<" ";}cout<<endl;}while(0)
int main()
{
    int N; cin >> N;
    int maxcnt = 0, result = 1;
    FOR(i, 1, N + 1) {
        int k = i;
        int cnt = 0;
        while (k % 2 == 0) {
            k /= 2;
            cnt++;
        }
        if (cnt > maxcnt) maxcnt = cnt, result = i;
    }
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
#define PI 3.14159265358979
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repp(i, s, e) for(int i = (s); i <= (e); ++i)
#define sz(x) ((int)x.size())
#define all(x) x.begin(), x.end()
#define FAST_IO() ios::sync_with_stdio(0); cin.tie(0)
template<typename T>
ostream& operator<<(ostream &os, const vector<T> &v) { for (auto x : v) os << x << " "; return os << "\n"; }
template<class U, class V>
ostream& operator<<(ostream &os, const pair<U, V> &p) { return os << "(" << p.first << "," << p.second << ")";}
 
int main() {
	int N;
	string S; cin >> S;
	N = sz(S);
	vector<int> cnt(N, 0);
	rep(i, N - 1) {
	    if(S[i] == 'R' && S[i + 1] == 'L') {
	        int s = i, e = i + 1;
	        while(s >= 0 && S[s] == 'R') --s;
	        while(e < N && S[e] == 'L') ++e;
	        // R : i - s, L : e - i - 1, R + L : e - s - 1
	        if(i % 2 == 0) repp(j, s + 1, e - 1) {
                if(j % 2 == 0) cnt[i]++;
                else cnt[i + 1]++;
	        }
	        else repp(j, s + 1, e - 1) {
                if(j % 2 == 0) cnt[i + 1]++;
                else cnt[i]++;
	        }
	    }
	}
	cout << cnt;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxx = 1e5 + 7;
const int Inf = 1 << 30;
const ll INF = 1ll << 60;
ll a, b;

int main() {
	cin >> a >> b;
	if(!(a & 1)) {
		if(b & 1) {
			ll ln = b - a + 1;
			if((ln / 2) & 1) cout << 1 << endl;
			else cout << 0 << endl;
		}
		else {
			ll ln = (b - 1) - a + 1;
			ll ans;
			if((ln / 2) & 1) ans = b ^ 1;
			else ans = b ^ 0;
			cout << ans << endl;
		}
	}
	else {
		if(b & 1) {
			ll ln = b - (a + 1) + 1;
			ll ans;
			if((ln / 2) & 1) ans = a ^ 1;
			else ans = a ^ 0;
			cout << ans << endl;
		}
		else {
			ll ln = (b - 1) - (a + 1) + 1;
			ll ans;
			if((ln / 2) & 1) ans = a ^ 1 ^ b;
			else ans = a ^ 0 ^ b;
			cout << ans << endl;
		}
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<string>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<limits.h>
#include<cmath>
#include<queue>
#include<stack>
#define rep(i,n) for(ll i = 0; i < (ll)n; i++)
#define swap(a,b) a^=b;b^=a;a^=b;
#define chmax(a,b) {if(a < b) a = b;}
#define chmin(a,b) {if(a > b) a = b;}
using namespace std;
typedef long long ll;
ll gcd(ll, ll);
vector<bool> to_binary(int);
int sum(vector<int>);
int min(vector<int>);
int max(vector<int>);
ll nCr(ll n, ll r);

const ll INF = 1LL << 60;

typedef tuple<ll, ll> mtupl;

bool mycomp(mtupl x, mtupl y) {
	return get<1>(x) < get<1>(y);
}

vector<vector<ll>> memo;

ll get(int x, int y) {
	if (memo[x][y] != -1)
		return memo[x][y];

	if (x == 0) return 1;
	if (y < x) return 0;

	memo[x][y] = get(x, y - 1) + get(x - 1, y - 1);
	return memo[x][y];
}

ll mpow(ll a, ll b) {
	ll ans = 1;
	for (ll i = 0; i < b; i++) {
		ans *= a;
		ans %= 1000000007;
	}
	return ans;
}

ll nCr(ll n, ll r) {
	ll res = 1;
	for (int i = 0; i < r; i++) {
		res *= (n - i);
	}
	for (int i = 1; i <= r; i++) {
		res /= i;
	}
	return res;
}

int vsum(vector<int> v) {
	int res = 0;
	for (auto it = v.begin(); it != v.end(); it++)
		res += *it;
	return res;
}
int vmin(vector<int> v) {
	int min = INT32_MAX;
	for (auto it = v.begin(); it != v.end(); it++)
		min = std::min(min, *it);
	return min;
}
int vmax(vector<int> v) {
	int max = INT32_MIN;
	for (auto it = v.begin(); it != v.end(); it++)
		max = std::max(max, *it);
	return max;
}

ll gcd(ll A, ll B) {
	if (A == 0 || B == 0) return max(A, B);
	int r = A % B;
	while (r != 0) {
		A = B;
		B = r;
		r = A % B;
	}
	return B;
}

ll _gcd(ll A, ll B) {
	return (B == 0) ? A : gcd(A % B, B);
}

vector<bool> to_binary(int x) {
	vector<bool> res;
	while (x != 0) {
		res.push_back(x % 2);
		x /= 2;
	}
	return res;
}

template<int index>
bool comp(tuple<ll, ll, ll, ll> a, tuple<ll, ll, ll, ll> b) {
	return get<index>(a) < get<index>(b);
}

int vector_finder(std::vector<ll> vec, ll number) {
	auto itr = std::find(vec.begin(), vec.end(), number);
	size_t index = std::distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return index;
	}
	else { // 発見できなかったとき
		return 0;
	}
}


int len(int x) {
	return (int)log10(x) + 1;
}

int same_vec(vector<int> a, vector<int> b) {
	int res = 1, num = a.size();
	for (int i = 0; i < num; i++) {
		if (a[i] != b[i]) {
			res = 0;
			break;
		}
	}
	return res;
}


ll fibs[100] = { 0 };
ll fib(int n) {
	if (fibs[n] == 0) {
		return fibs[n] = fib(n - 1) + fib(n - 2);
	}
	return fibs[n];
}



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

	int N;
	cin >> N;

	for (int i = 1; i < 10; i++) {
		for (int j = 1; j < 10; j++) {
			if (N == i * j) {
				cout << "Yes" << endl;
				goto ProgramEndPointLabel;
			}
		}
	}
	cout << "No" << endl;

ProgramEndPointLabel:;

	//Program End
#ifndef DEBUG
	system("pause");
#endif // !DEBUG


	return 0;
}




Measured memory_bytes: 504
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
const ll M = 1e9+7;

/*
ll fact(int n)
{
	if (n == 0)
	{
		return 1;
	}
	else
	{
		ll ans = 1;
		for (int i = 1; i <= n; ++i)
		{
			ans *= i;
		}
		return ans;
	}
}

ll comb(int n, int k) //nCk
{
	if (k == 0)
	{
		return 1;
	}
	else
	{
		ll ans;
		ans = ((fact(n) / fact(n-k)) / fact(k)) % M;
		return ans;
	}
}
*/

ll P[2005][2005];

void init()
{
	for (int i = 0; i < 2005; ++i)
	{
		for (int j = 0; j < 2005; ++j)
		{
			P[i][j] = 0;
		}
	}
	P[0][0] = 1;
	for (int i = 0; i < 2004; ++i)
	{
		for (int j = 0; j <= i; ++j)
		{
			P[i+1][j] += P[i][j];
			P[i+1][j] %= M;
			P[i+1][j+1] += P[i][j];
			P[i+1][j+1] %= M;
		}
	}
}

ll pascal(int n,int k)
{	
	if (n < k)
	{
		return 0;
	}
	else if ((n < 1)||(k < 1))
	{
		return 1;
	}

	return P[n][k];
}

int main()
{
	init();
	int N,K;
	cin >> N >> K;
	int ans;
	for (int i = 1; i <= K; ++i)
	{
		if (i > N-K+1)
		{
			cout << 0 << endl;
		}
		else
		{
			//cout << pascal(N-K+1,i) << " " << pascal(K-1,i-1)<< " ";
			ans = (pascal(N-K+1,i) % M) * (pascal(K-1,i-1) % M) % M;
			cout << ans << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 32248
#include<iostream>
#include<string>
#include<vector>
#include<string.h>
#include<map>
#include<queue>
using namespace std;

#define INF 100000


int w,h;
int dist[11][11];
vector<string> M;
map<pair<int,int>,int> Idx;
pair<int,int> point[11];
bool visit[400][400];
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};

void calc_dist(int num){
	for(int i=0;i<num;i++){
		queue<pair<pair<int,int>,int> > Q;
		Q.push(make_pair(point[i],0));
		memset(visit,false,sizeof(visit));
		while(!Q.empty()){
			pair<int,int> now=Q.front().first;
			int cost=Q.front().second;
			Q.pop();
			if(now.first>=w || now.second>=h || now.first<0 || now.second<0) continue;
			if(M[now.second][now.first]=='x') continue;
			if(visit[now.second][now.first]) continue;
			visit[now.second][now.first]=true;
			if(Idx.count(now))
				dist[i][Idx[now]]=cost;

			for(int r=0;r<4;r++)
				Q.push(make_pair(make_pair(now.first+dx[r],now.second+dy[r]),cost+1));
		}
	}
}

int main()
{
	while(cin>>w>>h && w!=0){
		M.clear();
		int start=0;
		Idx.clear();
		int count=1;
		for(int i=0;i<h;i++){
			string s; cin>>s; M.push_back(s);
			for(int n=0;n<s.size();n++){
				if(s[n]=='o'){
					Idx[make_pair(n,i)]=0;
					point[0]=make_pair(n,i);
				}
				else if(s[n]=='*'){
					Idx[make_pair(n,i)]=count;
					point[count]=make_pair(n,i);
					count++;
				}
			}
		}
		memset(dist,-1,sizeof(dist));
		calc_dist(count);
		int ans=INF;

		for(int i=0;i<count;i++){
			for(int j=0;j<count;j++){
				if(dist[i][j]<0){
					ans=-1;
				}
			}
		}

		int dp[1<<11][11];
		for(int i=0;i<11;i++)
			for(int b=0;b<(1<<11);b++)
				dp[b][i]=INF;

		dp[(1<<count)-1][0]=0;

		if(ans>=0){
			for(int S=(1<<count)-2;S>=0;S--){
				for(int v=0;v<count;v++){
					for(int u=0;u<count;u++){
						if(!(S>>u&1)){//à¤Â¢Äéæ
							dp[S][v]=min(dp[S][v],dp[S | 1<<u][u]+dist[v][u]);
						}
					}
				}
			}


			for(int i=0;i<count;i++)
				ans=min(ans,dp[0][i]);
		}
		cout<<ans<<endl;

	}
}

Measured memory_bytes: 1184
use std::io::*;
use std::str::FromStr;
use utils::*;

pub fn main() {
    let i = stdin();
    let mut o = Vec::new();
    run(i.lock(), &mut o);
    stdout().write_all(&o).unwrap();
}

fn run<R: BufRead, W: Write>(i: R, o: &mut W) {
    let mut i = CpReader::new(i);
    let (n, m, x, y) = i.read4::<usize, usize, isize, isize>();
    let mut xs = i.read_vec::<isize>(n);
    let mut ys = i.read_vec::<isize>(m);
    xs.push(x);
    ys.push(y);

    let x_max = xs.into_iter().max().unwrap();
    let y_min = ys.into_iter().min().unwrap();

    let r = if x_max < y_min { "No War" } else { "War" };

    writeln!(o, "{}", r).unwrap();
}

mod utils {
    use super::*;

    pub struct CpReader<R: BufRead> {
        r: R,
        s: String,
    }

    macro_rules! fn_read {
        { $f:ident($($t:ident),*) } => {
            #[allow(dead_code)]
            pub fn $f<$($t: FromStr),*>(&mut self) -> ($($t),*) {
                let i = &mut self.read_line().split(' ');
                ($(read_next::<$t,_>(i)),*)
            }
        };
    }

    impl<R: BufRead> CpReader<R> {
        pub fn new(r: R) -> Self {
            CpReader {
                r: r,
                s: String::new(),
            }
        }
        pub fn read_line(&mut self) -> &str {
            self.s.clear();
            self.r.read_line(&mut self.s).unwrap();
            self.s.trim()
        }

        fn_read! { read2(T1, T2) }
        fn_read! { read3(T1, T2, T3) }
        fn_read! { read4(T1, T2, T3, T4) }
        fn_read! { read5(T1, T2, T3, T4, T5) }

        pub fn read_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            self.read_line()
                .split(' ')
                .take(n)
                .map(|x| x.parse().ok().unwrap())
                .collect()
        }
    }
    fn read_next<'a, T: FromStr, I: Iterator<Item = &'a str>>(i: &mut I) -> T {
        i.next().unwrap().parse().ok().unwrap()
    }
}


Measured memory_bytes: 4352
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;


void main() {
    int n;
    string s;
    scan(n);
    scan(s);
    s = "0" ~ s ~ "0";

    auto dp = new int[](n + 1);

    foreach (i ; 3 .. n + 1) {
        dp[i] = max(dp[i], dp[i - 1]);

        if (s[i - 2] == '1' && s[i - 1] == '0' && s[i] == '1') {
            foreach_reverse (j ; 0 .. i - 1) {
                if (s[j] == '1') {
                    dp[i] = max(dp[i], dp[j - 1] + i - j - 1);
                }
                else {
                    break;
                }
            }

            foreach (j ; i .. n + 2) {
                if (s[j] == '1') {
                    dp[j] = max(dp[j], dp[i - 3] + j - i + 1);
                }
                else {
                    break;
                }
            }
        }
    }

    debug {
        writeln(dp);
    }

    writeln(dp[n]);
}


void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

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

using namespace std;
int main(){
	int N;
	cin >> N;

	int mod2 = 0;
	int mod4 = 0;
	int modX = 0;

	vector<unsigned int> A(N);
	for(int i=0; i<N; i++){
		cin >> A[i];
		if(A[i] % 4 == 0) mod4++;
		else if(A[i] % 2 == 0) mod2++;
		else modX++;
	}

	if((mod2==0 && mod4>=modX-1) || (mod2>0 && mod4>=modX)){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	
	return 0;
}

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

using namespace std;

int n, x, y, ar[1000001];


int main()
{
    cin >> n >> x >> y;

    for(int i = 1; i <= n; i++)
        cin >> ar[i];

    int ans = 0;
    ans = max(abs (ar[n] - y), ans);
    if(n > 1)
        ans = max(abs (ar[n - 1] - ar[n]), ans);
    if(n > 2)
        ans = max(min(abs(ar[n - 2] - ar[n]), abs(ar[n - 1] - ar[n])), ans);

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


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>

#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll,ll> pll;
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
#define ARRAY_MAX 205

const int INF = 1e9+7;
const ll MOD = 1e9+7;

ll dp[200005][10];//dp[i][j]:=i文字まで見てABCのうちj番目まで確定している場合

int main(){

    string s;
    cin >> s;
    memset(dp,0,sizeof(dp));
    dp[0][0] = 1;//空文字の場合(とりあえず何か埋め込む)
    ll siz = s.size();

    for(int i = 0;i < siz;i++){

        for(int j = 0;j <= 3;j++){
            //遷移しないケース
            if(s[i] == '?'){
                //i文字目が?だった場合
                //ABCの３通り埋め込める
                dp[i+1][j] = dp[i][j]*3%MOD;
            }else{
                //そのまま埋め込む
                dp[i+1][j] = dp[i][j]%MOD;
            }
        }

        //遷移するケース
        if(s[i] == '?' || s[i] == 'A'){
            //Aか?の場合、Aを埋め込んでAに遷移できる
            dp[i+1][1] += dp[i][0];
            dp[i+1][1] %= MOD; 
        }
        if(s[i] == '?' || s[i] == 'B'){
            //Bか?の場合、Bを埋め込んでBに遷移できる
            dp[i+1][2] += dp[i][1];
            dp[i+1][2] %= MOD;
        }
        if(s[i] == '?' || s[i] == 'C'){
            //Cか?の場合、Cを埋め込んでCに遷移できる
            dp[i+1][3] += dp[i][2];
            dp[i+1][3] %= MOD;
        }
    }
    cout << dp[siz][3] << endl;
    return 0;
}

Measured memory_bytes: 16128
#include <bits/stdc++.h>
#define forn(i, n) for (int i = 0; i<(int)n; ++i)
#define forr(i, t, n) for (int i = t; i<n; ++i)
#define rmod(x, y) (((x%y)+y)%y)
#define pb push_back
#define emp emplace_back
#define ppb pop_back
#define len(v) int(v.size())
#define all(v) (v).begin(),(v).end()
#define ri(x) scanf("%d",&(x))
#define rii(x,y) scanf("%d %d",&(x),&(y))
#define riii(x,y,z) scanf("%d %d %d",&(x),&(y),&(z))
#define rl(x) scanf("%lld",&(x))
#define rll(x,y) scanf("%lld %lld",&(x),&(y))
#define rlll(x,y,z) scanf("%lld %lld %lld",&(x),&(y),&(z))
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
void fastio(){ios_base::sync_with_stdio(false); cin.tie(0);}

const long double PI = acos(-1);
const long long MOD = 1000000000 +7;
const int maxn = 1024;

int main() {
	fastio();
	string s;
	cin >> s;
	int n = s.size();
	if (n == 1){
		puts("0");
		return 0;
	}
	int l = (n/2)-1, r = n/2;
	if (n%2)r++;
	int ans = 0;
	while (l>=0 and r<n){
		if (s[l] != s[r]) ans++;
		l--, r++;
	}
	printf("%d\n", ans);

	
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

//  const int MOD = 1e9 + 7;

//unsigned seed1= chrono::system_clock::now().time_since_epoch().count();
//mt19937 rng (seed1);

vector<int> days = {31,28,31,30,31,30,31,31,30,31,30,31};
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);

  int m1,d1,m2,d2;
  cin >> m1 >> d1 >> m2 >> d2;

  cout << (d1 == days[m1-1] and !(d2 == 31 and m2 == 12)) << endl;


  
  return 0;
}

Measured memory_bytes: 256
operators = ['+', '-', '*', '/']
stack = list(input().split())
# stack = list(open('input.txt').readline().split())


def calc(ope):
    c = stack.pop()
    a = c if c not in operators else calc(c)
    c = stack.pop()
    b = c if c not in operators else calc(c)
    return str(eval(b+ope+a))

print(calc(stack.pop()))

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

#define MOD (1000 * 1000 * 1000 + 7)
typedef long long ll;
typedef long double ld;

int main() {
	
	string str;
	getline(cin, str);
	char arr[3];
	
	if(str.size() == 2) {
		if(str[0] == str[1]) {
			printf("1 2\n");
		} else {
			printf("-1 -1\n");
		}
		return 0;
	}
	
	
	for(int i = 0; i <= str.size() - 3; ++i) {
		for(int j = 0; j < 3; ++j)
			arr[j] = str[i + j];
		if(arr[0] == arr[1] || arr[1] == arr[2] || arr[0] == arr[2]) {
			printf("%d %d\n", i + 1, i + 3);
			return 0;
		}
	}
	
	printf("-1 -1\n");
	
	
	return 0;
}


Measured memory_bytes: 512
// D - Non-decreasing
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define irp(i,s,e) for(int i=(s);i>(e);--i)

int main(){
	int N; cin>>N;
	int ix = 1, minmaxA = 0;
	rp(i, 1, N+1){
		int a; cin>>a;
		if(abs(minmaxA) < abs(a)){ minmaxA = a; ix = i; }
	}
	cout<< 2*N-1 <<endl;
	rp(i, 1, N+1) cout<< ix <<" "<< i <<endl;
	if(minmaxA<0) irp(i, N, 1) cout<< i <<" "<< i-1 <<endl;
	else rp(i, 1, N) cout<< i <<" "<< i+1 <<endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int n; scanf("%d",&n);
  int a[n],min=200001,count=0;
  for(int i=0; i<n; i++){
    scanf("%d",&a[i]);
    if (a[i]<min){
      min = a[i];
      count ++;
    }
  }
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define int long long
#define N 110
using namespace std;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
vector<vector<int> >D;

signed main(){
  
  while(1){
    int n;
    cin>>n;
    if(!n) break;
    D.clear(); D.resize(25);
    for(int i=0;i<25;i++) D[i].resize(i,0);
    
    for(int i=0;i<n;i++){
      int d,t;
      cin>>d>>t;
      for(int j=0,a;j<d;j++) cin>>a, D[d][(j-t+d)%d]+=a;
    }
    
    vector<vector<int> > dp(N);
    dp[1].push_back(0);
    for(int i=1;i<=24;i++){
      int d = dp[i].size();
      if(i == 13 || i == 17 || i == 19 || i == 23) {
        int mx = 0;
        for(int j=0;j<i;j++) Max(mx,D[i][j]);
        dp[i+1].resize(d);
        for(int j=0;j<d;j++) dp[i+1][j] = dp[i][j] + mx;
        continue;
      }
      int lcm = d * i / __gcd(d,i);
      dp[i+1].resize(lcm);
      for(int j=0;j<lcm;j++) dp[i+1][j] = dp[i][j%d] + D[i][j%i];
    }
    int ans = 0;
    for(int a:dp[25]) Max(ans,a);
    cout<<ans<<endl;
  }  
  return 0;
}

Measured memory_bytes: 7832
#include <iostream>
#include <iomanip>
#include <math.h>
#include <algorithm>
#include <map>
#include <vector>
#include <queue>
#include <set>
#include <list>
#include <string>
#include <memory.h>
#include <bitset>
#include <stack>
#include <assert.h>
using namespace std;
#define ll long long
#define ppi pair<int, int>
#define mp make_pair
const int N = 2e5 + 2, K = 20;
const int mod = 1e9 + 7 , inf = 2e9;
int dp[N], arr[N];
inline int dis(int a, int b)
{
	return abs(arr[a] - arr[b]);
}
int main()
{
#ifndef ONLINE_JUDGE
//	freopen("inp.txt", "r", stdin);
#endif
	int n , k;
	cin >> n >> k;
	for (int i = 0; i < n; i++)
		scanf("%d", arr + i);
	for (int i = n - 2; i >= 0; i--)
	{
		dp[i] = inf;
		for (int j = i + 1; j < i + k + 1; j++)
		{
			if (j == n) break;
			dp[i] = min(dp[i], dp[j] + dis(i, j));
		}
	}
	cout << dp[0];
	return 0;
}

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

int main(void){
	char s[500001];
	int a[500000], b[500000];
	scanf("%s", s);
	int n=strnlen(s, 500000)+1, i;
	a[0]=0;
	for(i=0; i<=n-2; i++){
		if(s[i]=='<'){
			a[i+1] = a[i]+1;
		}else{
			a[i+1] = 0;
		}
	}
	b[n-1]=0;
	for(i=n-2; i>=0; i--){
		if(s[i]=='>'){
			b[i] = b[i+1]+1;
		}else{
			b[i] = 0;
		}
	}
	long sum=0;
	for(i=0; i<n; i++){
		sum+=a[i]<b[i]?b[i]:a[i];
	}
	printf("%ld\n", sum);
}



Measured memory_bytes: 4608
#include <stdio.h>

int main(void){
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    if(a == b && a == c){
        printf("%s\n", "Yes");
        return 0;
    }
    else printf("%s\n", "No");
    return 0; 
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace OJcsharp
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] hit = new int[10000];
            int[] blow = new int[10000];
            int count = 0;
            string str=Console.ReadLine();
            do
            {
                hit[count]=0;
                blow[count]=0;
                string []a_s=str.Split(' ');
                string []b_s=Console.ReadLine().Split(' ');
                int[] a = new int[4];
                int[] b = new int[4];
                for(int n=0;n<4;n++)
                {
                    a[n]=int.Parse(a_s[n]);
                    b[n]=int.Parse(b_s[n]);
                    if(a[n]==b[n])
                        hit[count]++;
                }
                for(int n=0;n<4;n++)
                {
                    for(int m=0;m<4;m++)
                    {
                        if(a[n]==b[m]&&n!=m)
                            blow[count]++;
                    }
                }
                count++;
                str=Console.ReadLine();
            }while(string.IsNullOrEmpty(str)==false);
            for (int n = 0; n < count; n++)
            {
                Console.WriteLine(hit[n] + " " + blow[n]);
            }
        }
    }
}

Measured memory_bytes: 5688
N = int(input())
A = [int(i) for i in input().split()]

count = 0
for i in range(N):
  if A[i] <0:
    count = count + 1
    A[i] = A[i] * -1

if 0 in A:
  ans = sum(A)
else:
  if count%2 == 0:
    ans = sum(A)
  else:
    ans = sum(A) - 2*min(A)

print(ans)


Measured memory_bytes: 14412
#include<iostream>
#include <cmath>
#include<vector>
#define rep(i, n) for (int i=0;i<n;i++)
#include <map> 
#include<algorithm>
using namespace std;
typedef long long ll;

int main(void){
    int  w, h, x, y;
    cin>>w>>h>>x>>y;
    double ans1=(double)w*h/2;
    int ans2=0;
    if (x*2==w&&y*2==h){
        ans2=1;
    }
   cout<<ans1<<" "<<ans2<<endl;
}

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

int w[400];
int memo[400][400];

int max(int i, int j){
	int max = 0;
	for(int k = i ; k < j ; k++){
		int a = memo[i][k] + memo[k+1][j];
		if(a > max){
			max = a;
		}
	}
//	if((j - i) % 2 == 0){
		if(w[i] - w[j] <= 1 && w[j] - w[i] <= 1 && memo[i+1][j-1] == j - i - 1){
			max = j - i + 1;
//			max += 2;
// 		}
	}
	return max;
}

int main() {
	int n;
	while(true){
		cin >> n;

		if(n == 0) break;
		for(int k = 0 ; k < n ; k++){
			cin >> w[k];
//			cout << "w[" << k << "] = " << w[k] << "\n";
		}

		for(int k = 0 ; k < n - 1; k++){
			memo[k][k] = 0;
//			cout << "memo[" << k << "][" << k << "] = " << memo[k][k] << "\n";
		}

		for(int k = 0 ; k < n - 1; k++){
			memo[k][k+1] = (w[k] - w[k+1] <= 1 && w[k+1] - w[k] <= 1) ? 2 : 0;
//			cout << "memo[" << k << "][" << k + 1 << "] = " << memo[k][k + 1] << "\n";
		}

		for(int b = 2 ; b < n ; b++){ //???
			for(int k = 0 ; k < n - b ; k++){
				memo[k][k + b] = max(k, k + b);
//				cout << "memo[" << k << "][" << k + b << "] = " << memo[k][k + b] << "\n";
			}
		}
//		cout << "memo[" << 0 << "][" << n - 1 << "] = " << memo[0][n-1] << "\n";
		cout << memo[0][n-1] << "\n";
	}
		return 0;
}

Measured memory_bytes: 3528
let n = stdin.ReadLine() |> int

let a =
  stdin.ReadLine().Split(' ') |> Array.map int

let ans =
  [-100 .. 100]
  |> List.map (fun i -> a |> Array.sumBy (fun x -> (x - i) * (x - i)))
  |> List.min

ans |> stdout.WriteLine

Measured memory_bytes: 11348
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mt make_tuple
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector <long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> >
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
const int inf = 1e9 + 5;
const ll inf64 = 1e18 + 5;

int main()
{
	boost;
	int n, x, i;
	cin >> n;
	int ans = 0;
	foe(i, 1, n) {
		cin >> x;
		if(i & 1) {
			if(x & 1)
			++ans;
		}
	}
	cout << ans;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b;
    cin>>a>>b;
    if(a+b==15){
        cout<<'+';
        return 0;
    }
    if(a*b==15){
        cout<<'*';
        return 0;
    }
    cout<<'x';
    return 0;
}

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

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

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

    vector<vector<ll>> v(n, vector<ll>(m+1,0));
    for (int i=0; i<n; i++) {
        for (int j=0; j<=m; j++) {
            cin >> v[i][j];
        }
    }

    ll ans = 12*100000+1;

    for (int bit=0; bit<(1<<n); bit++) {
        
        vector<ll> tmp(m+1, 0);
        for (int i=0; i<n; i++) {
            if (bit&(1<<i)) {
                for (int j=0; j<=m; j++) {
                    tmp[j] += v[i][j];
                }
            }
        }

        bool check = true;
        for (int j=1; j<=m; j++) if (!(tmp[j]>=x)) check = false;
        if (check) ans = min(ans, tmp[0]);

    }

    if (ans==12*100000+1) ans = -1;

    cout << ans << "\n";    

    return 0;
}

Measured memory_bytes: 3656
#include<cstdio>
#define RI register int
#define CI const int&
using namespace std;
const int N=3000005,mod=998244353;
int n,m,fact[N],inv[N],ans,tp;
inline void inc(int& x,CI y)
{
	if ((x+=y)>=mod) x-=mod;
}
inline void dec(int& x,CI y)
{
	if ((x-=y)<0) x+=mod;
}
inline int quick_pow(int x,int p=mod-2,int mul=1)
{
	for (;p;p>>=1,x=1LL*x*x%mod) if (p&1) mul=1LL*mul*x%mod; return mul;
}
inline int C(CI n,CI m)
{
	if (n<m) return 0; return 1LL*fact[n]*inv[m]%mod*inv[n-m]%mod;
}
inline void init(CI n)
{
	RI i; for (fact[0]=i=1;i<=n;++i) fact[i]=1LL*fact[i-1]*i%mod;
	for (inv[n]=quick_pow(fact[n]),i=n-1;~i;--i) inv[i]=1LL*inv[i+1]*(i+1)%mod;
}
int main()
{
	RI i; scanf("%d%d",&n,&m); init(n+3*m);
	for (i=0;i<=m;++i) if (!((3*m-i)&1))
	tp=(3*m-i)/2,inc(ans,1LL*C(n,i)*C(tp+n-1,n-1)%mod);
	for (i=2*m+1;i<=3*m;++i) dec(ans,1LL*n*C(3*m-i+n-2,n-2)%mod);
	return printf("%d",ans),0;
}

Measured memory_bytes: 22656
#include<stdio.h>
#include<string.h>
int a[10],n,t,i;
int main()
{
	for(;scanf("%d",&n),n;)
	{
		for(memset(a,0,40);n--;a[t]++)
			scanf("%d",&t);
		for(i=0;i<10;i++)
		{
			if(a[i]==0)
				puts("-");
			else
				for(;a[i]--;printf("*%s",a[i]==0?"\n":""));
		}
	}
}

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

using namespace std;
#define inf             0x3f3f3f3f
#define INF             2e18
#define eps             1e-9

#define FastRead        ios_base::sync_with_stdio(0);cin.tie(0)
#define fRead           freopen("input.txt","r",stdin)
#define fWrite          freopen("output.txt","w",stdout)

#define LL              long long
#define ull            unsigned long long
#define PI              acos(-1.0)
#define pb              push_back
#define mk              make_pair
#define pii             pair<int,int>
#define pLL             pair<LL,LL>
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define SQR(a)          ((a)*(a))
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(min(a,b),min(c,d))
#define max4(a,b,c,d)   max(max(a,b),max(c,d))
#define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))
#define vi              vector <int>
#define vL              vector <LL>
#define LB(a,x)         (lower_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which does not compare less than val.
#define UB(a,x)         (upper_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which compares greater than val.
#define prec(n)         fixed << setprecision(n)

#define MEM(a,x)        memset(a,x,sizeof(a))
#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#define Unique(a)       sort(all(a)),a.erase(unique(all(a)),a.end())

#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define IT(it,x)	    for(it=x.begin();it!=x.end();it++)
int main()
{
  LL a,b,k;
  cin>>a>>b>>k;
  LL x=min(a,k);
  a-=x;
  k-=x;
  b-=min(b,k);
  cout<<a<<" "<<b;

}


Measured memory_bytes: 3576
/*
g++ -std=c++11 -o2 -Wall ABC100D.cpp -o ./out/ABC100D.out
./out/ABC100D.out
*/

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

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define tr(c, i) for (iter(c) != (c).begin(); i != (c).end(); ++i)
#define pb push_back
#define mp make_pair

typedef long long ll;

ll a[1001];
ll b[1001];
ll c[1001];
ll d[1001];

int main(){
//    freopen("./input/input.txt", "r", stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; ++i) {
      cin >> a[i] >> b[i] >> c[i];
    }
    int ad[] = {-1, 1};
    int bd[] = {-1, 1};
    int cd[] = {-1, 1};
    ll ans = -1;
    for (int i = 0; i < 2; ++i) {
      for (int j = 0; j < 2; ++j) {
        for (int k = 0; k < 2; ++k) {
          for (int l = 0; l < n; ++l) {
            d[l] = ad[i]*a[l]+bd[j]*b[l]+cd[k]*c[l];
          }
          sort(d,d+n,greater<ll>());
          ll temp = 0;
          for (int l = 0; l < m; ++l) {
            temp += d[l];
          }
          ans = max(ans, temp);
        }
      }
    }
    cout << ans << "\n";
}


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

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

    string str = to_string(n);
    char c = str.at(str.length() - 1);
    if (c == '2' || c == '4' || c == '5' || c == '7' || c == '9') {
        cout << "hon" << endl;
    } else if (c == '0' || c == '1' || c == '6' || c == '8') {
        cout << "pon" << endl;
    } else {
        cout << "bon" << endl;
    }
}

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

int main(){
	int N;
	while(1){
		int s = 0;
		cin>>N;
		if(N == 0) break;
		for(int i = N + 1; i <= N * 2; i++){
			int k = 0;
			for(int j = 2; j * j <= i; j++){
					
				if(i % j == 0){
					k = 1;
					break;
				}
			}
			if(k == 0) s++;
		}
		cout<<s<<endl;
		
	}
	return 0;
}



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

int main() {
    string S;
    cin >> S;
    int ans = 0;
    int cnt = 0;
    rep(i, S.size()) {
        if (S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T') {
            ++cnt;
        } else
            cnt = 0;
        ans = max(ans, cnt);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3612
a, b, c, d = map(int, input().split())


x = b // c
y = b // d


import fractions
e = int(c * d / fractions.gcd(c,d))


z = b // e

x2 = (a-1) // c
y2 = (a-1) // d


e2 = int(c * d / fractions.gcd(c,d))


z2 = (a-1) // e2


print((b - (x + y - z)) - (a - 1 - (x2 + y2 - z2)))


Measured memory_bytes: 5104
n = gets.to_i
hash = {}
n.times do |i|
  ary = gets.split(' ')
  hash[i+1] = ary
end

sorted = hash.sort do |a, b|
  (a[1][0] <=> b[1][0]).nonzero? || (b[1][1].to_i <=> a[1][1].to_i)
end

sorted.each do |a|
  print("#{a[0]}\n")
end

Measured memory_bytes: 1788
import sys


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

for i in range(N+1):
    for j in range(N+1-i):
        k = N - i -j
        if i*10000 + j*5000 + 1000*k == Y:
            print(i, j, k)
            sys.exit()

print(-1, -1, -1)

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main() {
	int a[500] = { 0 }, b[500] = { 0 }, sum[500] = { 0 }, d[500] = { 0 }, k[500] = { 0 };
	int i = 0;
	while (1) {
		cin >> a[i] >> b[i];
		if (a[i] == 0 && b[i] == 0)break;
		sum[i] = a[i] + b[i];
		while (sum[i]) {
			sum[i] /= 10;
			k[i]++;
		}
		i++;
	}
	for (int j = 0; j <i;j++) {
		cout << k[j] << endl;
	}
	return 0;
}

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

void bubbleSort(vector<int> &A, int N, int &count) {
  bool flag = 1;
  while (flag) {
  	flag = 0;
    for(int j = N - 1; j >= 1; j--){
      if(A[j] < A[j-1]) {
      	int tmpJ = A[j];
        A[j] = A[j -1];
        A[j - 1] = tmpJ;
        flag = 1;
        count ++;
      }
    }
  }
}

int main() {
  int N;
  int count = 0;
  cin >> N;
  vector<int> A(N);
  rep (i, N) cin >> A.at(i);
  bubbleSort(A, N, count);
  rep (i, N) {
    cout << A.at(i);
    if (i != A.size() - 1) {
    	cout << " ";
    }
  }
  cout << endl;
  cout << count << endl;
}


Measured memory_bytes: 3124
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

void _main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];
    vector<int> v, w;
    for (int i = 0; i < n; i += 2) v.push_back(a[i]);
    for (int i = 1; i < n; i += 2) w.push_back(a[i]);
    if (n % 2 == 1) swap(v, w);
    reverse(w.begin(), w.end());
    for (int i = 0; i < w.size(); ++i) cout << w[i] << " ";
    for (int i = 0; i < v.size(); ++i) cout << v[i] << " \n"[i + 1 == v.size()];
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

Measured memory_bytes: 7136
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, gcd, lcm 
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <string> // string
#include <vector> // vector
#include <queue> // queue
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)
#include <cstdint> // int64_t, int_fast64_t

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

#define INF 10101010

typedef std::int_fast64_t ll; // at least int64 > 9*10^18
typedef std::uint_fast64_t ull; // at least uint64

int n,ma,mb;
struct Medicine
{
  int a,b,c,val;
  Medicine(int a,int b,int c) : a(a),b(b),c(c) {
    val = ma*b-mb*a;
  }
};

int main() {
  std::cin >> n >> ma >> mb;
  std::vector<Medicine> meds;
  meds.reserve(n);
  rep(i,n) {
    int a,b,c;
    std::cin >> a >> b >> c;
    meds.emplace_back(a,b,c);
  }
  std::unordered_map<int,int> map;
  std::unordered_map<int,int> tmap;
  map.reserve(101010);
  map[0] = 0;
  int mincost = INF;
  for(auto m:meds) {
    tmap = map;
    for(auto i:tmap) {
      int next = i.first + m.val;
      if(next == 0) mincost = std::min(mincost,i.second+m.c);
      else {
        if(map.count(next)==0) map[next] = i.second+m.c;
        else map[next] = std::min(map[next],i.second+m.c);
      }
    }
  }
  if(mincost==INF) mincost = -1;
  std::cout << mincost << ENDL;
  return 0;
}

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

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

  ll n = s.size();
  vector<ll> num(n+1, 0);
  for(int i = 1; i <= n; i++){
    num[i] = s[i-1] - '0';
  }

  ll cnt = 0;
  for(ll i = 1; i <= n; i++){
    if(num[i] != 1)break;
    cnt++;
  }

  if(k <= cnt){
    cout << 1 << endl;
  }else{
    cnt++;
    cout << num[cnt] << endl;
  }

  return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
#define M 1000000007
int main(){
  string s;
  cin>>s;
  map<char,int> m;
  for(int i=0;i<4;i++){
    m[s[i]]++;
  }
  for(int i=0;i<4;i++){
    if(m[s[i]]!=2){
      cout<<"No";
      return 0;
    }
  }
  cout<<"Yes";
}

Measured memory_bytes: 256
S=input()
N=len(S)

def is_palindrome(s):
    return s==s[::-1]

S_all=is_palindrome(S)
S_forward=is_palindrome(S[:(N-1)//2])
S_rear=is_palindrome(S[(N+3)//2-1:])

if (S_all==True  and S_forward==True)  and S_rear==True:
    print("Yes")
else:
    print("No")

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

int main(){
    int n, m;
    while( cin >> n >> m, n||m ){
        vector<int> ring(0);
        for(int i = 1; i <= n; i++){
            ring.push_back(i);
        }
        int j = 0;
        while( ring.size() > 1 ){
            j = (j + m - 1) % ring.size();
            ring.erase(ring.begin()+j);
        }
        cout << ring[0] << endl;
    }
    return 0;
}

Measured memory_bytes: 1228
s = input()
ans = 0
ds = []
tmp = 0
b = ""
while tmp < len(s):
    if s[tmp] == 'A':
        b += 'A'
        tmp += 1
    elif s[tmp:tmp+2] == "BC":
        b += 'D'
        tmp += 2
    else:
        ds.append(b)
        b = ""
        tmp += 1
ds.append(b) if b else None
ans = 0
def inver(s):
    tmp = 0
    res = 0
    for i in s:
        if i == 'A':
            tmp += 1
        else:
            res += tmp
    return res
for i in ds:
    ans += inver(i)
print(ans)

Measured memory_bytes: 5428
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int k,a,b;
    cin>>k>>a>>b;
    if(b-a<=2||k<=a){cout<<1+k<<endl;}
    else{
        ll ans=0;
        ans+=a;
        ll x=k-a+1;
        if(x%2!=0)ans++;
        x/=2;
        ans+=(b-a)*x;
        cout<<ans<<endl;
    }
}


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

int main()
{
    int m, n;
    scanf("%d%d", &n, &m);
    vector<pair<int,int>> diffs;
    for(int i=1; i<=m; ++i) diffs.push_back(make_pair(i, n-i));
    vector<int> difs;
    for(auto x : diffs) difs.push_back(x.first&1?x.second:x.first);
    sort(difs.begin(), difs.end());
    for(int i=1; i<=m; ++i){
        printf("%d %d\n", i, i+difs[m-i]);
    }
}

Measured memory_bytes: 4740
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)
#define FORR(i,n,m) for(int i=n-1;i>=m;i--)
#define ARR(array) for(int i=0;i<array.size();i++)
#define all(in) in.begin(),in.end()
#define ALL(in,K) in,in+K
#define INF 1e18
#define MOD 1000000007
#define SIZE 10005
#define PI 	3.14159265358979323846

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; } //最小公倍数

long double input(){
  ll a;
  cin >> a;
  return a;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    long double a=0; 
    REP(i,n)a+=1/input();
    printf("%.12Lf\n",1/a);
}

Measured memory_bytes: 256