akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i < b; i++)
typedef long long ll;

long long INF = 1e18;

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

        if(k <= a){
                cout << k << endl;
        }else if( k <= a+b){
                cout << a << endl;
        }
        else{
                int s;
                s = k - (a + b);
                cout << a - s << endl;
        }
        return 0;
}


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

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

    int L;
    if( K%7 == 0 ){
        L = 9*K/7;
    }
    else{
        L = 9*K;
    }

    if( L%2 == 0 ){
        cout << "-1" << endl;
    }
    else if( L%5 == 0 ){
        cout << "-1" << endl;
    }
    else{
       int res;
       res = 10%L;
       if( res == 1 ){
            cout << "1" << endl;
            return 0;
       }
       for(int i=2; ;i++){
            res = 10*res;
            res = res%L;
            if( res == 1 ){
                cout << i << endl;
                return 0;
            }
       } 
    }
    
}


Measured memory_bytes: 3604
// Last Change: 06/27/2019 18:29:18.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

namespace NS {
void LoopUntilZeroInpput() {
  int hogegegege = 0;
  while (cin >> hogegegege && hogegegege != 0) {
  }
}
} // namespace NS

int Solve(int n, int x) {
  int ans = 0;
  for (int i = 1; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      int k = x - i - j;
      if (k <= n and j < k) {
        ++ans;
      }
    }
  }
  return ans;
}

int main() {
  int n, x;
  while (cin >> n >> x and n > 0) {
    cout << Solve(n, x) << endl;
  }

  //NS::LoopUntilZeroInpput();
}



Measured memory_bytes: 3080
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstddef>
#include<queue>
#include<math.h>
#include<iomanip>
using namespace std;

int main()
{
    int n, a, ans = 0;
    cin >> n;
    for(int i = 0; i < n; ++i){
        cin >> a;
        ans += a -1;
    }

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

Measured memory_bytes: 3624
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, [graph1; $len:expr]) => {{
        let mut g = vec![vec![]; $len];
        let ab = read_value!($next, [(usize1, usize1)]);
        for (a, b) in ab {
            g[a].push(b);
            g[b].push(a);
        }
        g
    }};
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => (read_value!($next, usize) - 1);
    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        read_value!($next, [$t; len])
    }};
    ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (let _ = write!(out,$($format)*););
    }
    input! {
        n: usize,
        a: [i64; n],
    }
    const MOD: i64 = 1_000_000_007;
    let mut tot = 0;
    let mut sum = 0;
    for i in 0..n {
        tot += a[i] * a[i] % MOD;
        sum += a[i];
    }
    tot %= MOD;
    sum %= MOD;
    tot = (sum * sum - tot + MOD) % MOD;
    tot = tot * ((MOD + 1) / 2) % MOD;
    puts!("{}\n", tot);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 2676
package main

import "fmt"

func isEven(s string) bool {
	if len(s)%2 != 0 {
		return false
	}

	l := len(s)
	for i := 0; i < l/2; i++ {
		if s[i] != s[i+l/2] {
			return false
		}
	}
	return true
}

func main() {
	var s string
	fmt.Scan(&s)

	for i := len(s) - 1; i > 0; i-- {
		if isEven(s[0:i]) {
			fmt.Println(i)
			return
		}
	}

}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b,n;
  cin>>a>>b;
  string s;
  cin>>s;
  n=count(s.begin(),s.end(),'-');
  if(s[a]=='-'&&n==1)
  {
   cout<<"Yes"<<endl;
  }
  else
  {
    cout<<"No"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
# 4*Q < SならQを使ったほうがいいし以下略
q, h, s, d = map(int, input().split())
n = int(input())
x = min(4 * q, 2 * h, s)
if 2 * x <= d:
    ans = n * x
else:
    if n % 2 == 0:
        ans = (n // 2) * d
    else:
        ans = (n // 2) * d + x

print(ans)


Measured memory_bytes: 38384
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<int> A(N);
	int res = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}


	for (int i = 1; i < N - 1; i++) {
		int l = 0;
		int r = N - 1;
		int sum = 0;
		for (; l < N - 1; l += i, r -= i) {
			sum += A[l];
			sum += A[r];
			if (r - i > 0 && (r % i != 0 || r > l)) {
				//cerr << r << " " << r - i << " " << sum << endl;
				res = max(res, sum);
				//cerr << sum << endl;
			}
		}
	}

	cout << res << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define REP(i,a,b) for(int i=int(a);i<(int)b;++i)
#define Graph vector<vecctor<ll>>
#define pairs vector<pair<ll,ll>>
#define pb push_back



using namespace std;
using ll = long long;

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(void)
{
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<ll>ans(n);
    for(int k=1;k<=n;k++){
        
    for(int i=2; i*i < 2*k;i++){
        int les = 2*k-i*i;
        if(les%4 == 3)continue;
        for(int j=2;j*j < les;j++){
            int les2 = les-j*j;
            double r = sqrt(les2);
            int intr = int(r);
            if(intr*intr == les2){
                if(i+j-r > 1 && i+r-j > 1 && j+r-i > 1) ans[k-1]++;
            }
        }

    }
    cout << ans[k-1] << endl;
    }

    return 0;
   
}


Measured memory_bytes: 3644
#include <cmath>
#include <cstdint>
#include <iostream>

using namespace std;

int main() {
  int64_t X;
  cin >> X;
  
  long double money = 100;
  int year = 0;
  while (money < X) {
    money = floor(money * 1.01);
    ++year;
  }
  cout << year << endl;
  
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<int, int > pi;
typedef vector<ll> vi;

#define x first
#define y second
#define pb push_back
#define mp make_pair
#define FOR(a ,b) for(int i = a; i < b; i++) 
#define e "\n"


int main(){
	ll n, w;
	cin >> n >> w;
	
	vector<ll> dp(w+1,0);
	
	ll we,v;
	for(ll i = 0 ; i < n;i++){
		cin >> we >> v;
		for(ll wa = w-we; wa >= 0; wa--){
			dp[wa+we] = max(dp[wa+we] , dp[wa]+v);
		}
	}
	ll ans = 0;
	for(ll x : dp) ans = max(ans, x);
	cout << ans << e;
}


Measured memory_bytes: 1024
H,W,K=map(int,input().split())
c=[list(input()) for i in range(H)]
count=0
for bit in range(1<<(H+W)):
    black=0
    for shift_h in range(H):
        for shift_w in range(W):
            if c[shift_h][shift_w]=="#" and (bit>>W+shift_h)&1 and (bit>>shift_w)&1:
                black+=1
    if black==K:
        count+=1
print(count)

Measured memory_bytes: 9060
#include<cstdio>
int main () {
    int n;
    scanf("%d", &n);
    int sum = 0;
    for (int i = 0; i < n; ++i) {
        int f;
        scanf("%d", &f);
        sum += f;
    }
    sum -= n;
    printf("%d", sum);
}

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

using namespace std;

typedef long long ll;

const int INF = 1e9;

int main()
{
  string s;
  cin >> s;
  int n = s.size();
  stack<int> stk;
  int area = 0;
  vector<pair<int, int> > lakes;
  int beg = -1;
  for (int i = 0; i < n; ++i) {
    if (s[i] == '\\') {
      stk.push(i);
      if (area > 0) {
        lakes.push_back(make_pair(beg, area));
        area = 0;
        beg = -1;
      }
    }
    else if (s[i] == '/') {
      if (stk.empty()) {
        continue;
      }
      beg = stk.top(); stk.pop();
      area += (i - beg + 1) - 2 + 1;
    }
  }
  if (area > 0) {
    lakes.push_back(make_pair(beg, area));
  }
  int nlakes = lakes.size();
  int sum = 0;
  for (int i = nlakes - 1; i >= 0; --i) {
    for (int j = i - 1; j >= 0; --j) {
      if (lakes[j].second == 0) { continue; }
      if (lakes[i].first <= lakes[j].first) {
        lakes[i].second += lakes[j].second;
        lakes[j].second = 0;
      }
    }
    sum += lakes[i].second;
  }
  int cnt = 0;
  for (int i = 0; i < nlakes; ++i) {
    if (lakes[i].second != 0) { ++cnt; }
  }
  fprintf(stdout, "%d\n", sum);
  fprintf(stdout, "%d", cnt);
  for (int i = 0; i < nlakes; ++i) {
    if (lakes[i].second != 0) {
      fprintf(stdout, " %d", lakes[i].second);
    }
  }
  fprintf(stdout, "\n");
  return 0;
}

Measured memory_bytes: 1316
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String[] array=new String[n];
		String buff1="",buff2="";

		for(int i=0;i<n;i++) {
			array[i]=sc.next();
		}
		for(int i=0;i<n-1;i++) {
			for(int j=i+1;j<n;j++) {
				if(array[i].equals(array[j])) {
					System.out.println("No");
					System.exit(0);
				}
			}
		}
		for(int i=0;i<n-1;i++) {
			buff1=array[i].substring(array[i].length()-1,array[i].length());
			buff2=array[i+1].substring(0,1);
			if(!buff1.equals(buff2)) {
				System.out.println("No");
				System.exit(0);
			}
		}

		System.out.println("Yes");
	}
}




Measured memory_bytes: 21844
use proconio::input;

fn main() {
    input! {
        x: usize,
    }

    let mut dp = vec![false; x + 1];
    dp[0] = true;

    for i in 0..=x {
        for j in 100..=105 {
            if dp[i] && i + j <= x {
                dp[i + j] = true;
            }
        }
    }

    let ans = if dp[x] { 1 } else { 0 };

    println!("{}", ans);
}


Measured memory_bytes: 2208
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>
#include <cmath>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;


template<typename T, typename U>
std::enable_if_t<std::rank<T>::value == 0> fill_all(T& arr, const U& v) {
	arr = v;
}
template<typename ARR, typename U>
std::enable_if_t<std::rank<ARR>::value != 0> fill_all(ARR& arr, const U& v) {
	for (auto& i : arr) {
		fill_all(i, v);
	}
}

constexpr int64_t INF = 2000102000000000;

int32_t N;
int64_t A[200010];

int64_t sumR[200010];
int64_t sumL_[200010];
const auto sumL = sumL_ + 5;

int64_t dpR[200010];
int64_t funcR(int i)
{
	if (i == N) {
		return 0;
	}
	if (dpR[i] != INF) {
		return dpR[i];
	}
	dpR[i] = sumR[i + 1];
	if (A[i+1] == 0) {
		dpR[i] = std::min(dpR[i], 2 + funcR(i + 1));
	}
	else if(A[i+1]%2==0){
		dpR[i] = std::min(dpR[i],  funcR(i + 1));
	}
	else {
		dpR[i] = std::min(dpR[i], 1 + funcR(i + 1));
	}
	return dpR[i];
}
int64_t dpL[200010];
int64_t funcL(int i)
{
	if (i == 0) {
		return 0;
	}
	if (dpL[i] != INF) {
		return dpL[i];
	}
	dpL[i] = sumL[i];
	int64_t cost = 0;
	if (A[i] == 0) {
		cost = 2;
	}
	else if (A[i] % 2 == 0) {
		cost = 0;
	}
	else {
		cost = 1;
	}
	return dpL[i] = std::min(dpL[i], cost + funcL(i - 1));
}
int64_t dpL1[200010];
int64_t funcL1(int i)
{
	if (i == 0) {
		return 0;
	}
	if (dpL1[i] != INF) {
		return dpL1[i];
	}
	dpL1[i] = funcL(i);
	int64_t cost = 0;
	if (A[i] == 0) {
		cost = 1;
	}
	else if (A[i] % 2 == 0) {
		cost = 1;
	}
	else {
		cost = 0;
	}
	return dpL1[i] = std::min(dpL1[i], cost + funcL1(i - 1));
}
int64_t dpR1[200010];
int64_t funcR1(int i)
{
	if (i == N) {
		return 0;
	}
	if (dpR1[i] != INF) {
		return dpR1[i];
	}
	dpR1[i] = funcR(i);
	int64_t cost = 0;
	if (A[i + 1] == 0) {
		cost = 1;
	}
	else if (A[i + 1] % 2 == 0) {
		cost = 1;
	}
	else {
		cost = 0;
	}
	return dpR1[i] = std::min(dpR1[i], cost + funcR1(i + 1));
}

int main()
{
	fill_all(dpR, INF);
	fill_all(dpR1, INF);
	fill_all(dpL, INF);
	fill_all(dpL1, INF);

	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> N;
	for (int i = 1; i <= N; i++)
	{
		in >> A[i];
	}
	for (int i = 1; i <= N; i++)
	{
		sumL[i] = sumL[i-1] + A[i];
	}
	for (int i = N; i >= 0; i--)
	{
		sumR[i] = sumR[i+1] + A[i];
	}

	int64_t min = INF;
	for (int i = 0; i <= N; i++)
	{
		min = std::min({ min, funcL(i) + funcR1(i), funcL1(i) + funcR(i) });
	}
	out << min << endl;

	return 0;
}
#endif


Measured memory_bytes: 17536
process.stdin.on('data', (chunk: any) => {
  return main(normalize(chunk));
});

function main(S: string) {
  const chars = S.split('');

  // NOTE: 文字列が2種類であることを確認する
  const types = chars.filter((val, i, self) => self.indexOf(val) === i);
  if (types.length !== 2) {
    console.log('No');
    return;
  }

  // NOTE: 指定したtypeが、文字列Sにいくつ含まれるかを確認する
  const check = (type: string): number => {
    const regex = new RegExp(type, 'g');
    const matchedList = S.match(regex);
    return matchedList ? matchedList.length : 0;
  };

  console.log(types.every(type => check(type) === 2) ? 'Yes' : 'No');
}

function normalize(input: any): string {
  return input
    .toString()
    .replace('\n', '')
    .replace(' ', '');
}


Measured memory_bytes: 7500
#include <iostream>
#include <cstring>
using namespace std;
long long x[200005];
int main() {
	
	int n;
	cin>>n;
	
	for(int i = 0; i < n; i++)
	{
		cin>>x[i];
	}
	long long sum = 0;
	for(int i = 0; i < n-1; i++)
	{
		if(x[i+1] < x[i])
		{
			sum+=(x[i]-x[i+1]);
			x[i+1]+=(x[i]-x[i+1]);
		}
		
	}
	cout<<sum;
	return 0;
}

Measured memory_bytes: 5096
#include <iostream>
#include <vector>
#include <utility>
#include <numeric>
#include <functional>
#include <stdio.h>
#include <math.h>
#include <cmath>
#include <string>
#include <algorithm>
#include <deque>
#include <queue>
#include <map>
#include <chrono>
using namespace std;

using namespace std;
using ll = long long;

int main() {
	int n, t, a;
	cin >> n;
	cin >> t >> a;
	int ind = 0;
	double best = 99999999;
	for (int i = 0; i != n; ++i) {
		int h;
		cin >> h;
		double cost = abs(double(a) - (double(t) - double(h) * 0.006));
		if (cost < best) {
			best = cost;
			ind = i + 1;
		}
	}
	cout << ind << endl;
}



Measured memory_bytes: 384
# frozen_string_literal: true

n = gets.to_i
a, b = Array.new(n) { gets.split.map(&:to_i) }.transpose
cnt = 0

b.reverse_each.with_index do |i, idx|
  tmp = (a[-1 - idx] + cnt) % i
  cnt += tmp == 0 ? 0 : i - tmp
end

puts cnt

Measured memory_bytes: 13180
#include "bits/stdc++.h"
#define ff first
#define ss second
#define szof(_x) ((int) (_x).size())
#define TASK_NAME ""

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9 + 7;
const ll INFL = 1e18 + 123;
const double PI = atan2(0, -1);
mt19937 tw(960172);
ll rnd(ll x, ll y) { static uniform_int_distribution<ll> d; return d(tw) % (y - x + 1) + x; }


void solve() {
	int n;
	cin >> n;
	ll pref = 0;
	map<ll, int> amount;
	amount[pref]++;
	ll ans = 0;
	for (int i = 0; i < n; ++i) {
		int num;
		cin >> num;
		pref += num;
		ans += amount[pref];
		amount[pref]++;
	}
	cout << ans << "\n";
}


int main() {
	//freopen(TASK_NAME ".in", "r", stdin);
	//freopen(TASK_NAME ".out", "w", stdout);
	cerr << fixed << setprecision(15);
	cout << fixed << setprecision(15);
	ios::sync_with_stdio(false);

	int tests = 1;
	// cin >> tests;
	for (int it = 1; it <= tests; ++it) {
		solve();
	}
	
	#ifdef LOCAL
		cerr << "time: " << clock() << " ms\n";
	#endif
	return 0;
}

Measured memory_bytes: 12800
# # Make IO faster
# import sys
# input = sys.stdin.readline

# # get single (or) multiple str
# X = input()

# # get single int
# N = int(input())
# # get multiple int (e.g., 2)
# X, Y = map(int, input().split())
# # get multiple int (e.g., 2) for N lines
# XY = [list(map(int, input().split())) for _ in range(N)]

# from IPython import embed; embed(); exit();

# 全部入り
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A, B, C = MAP()
if (A + B >= C):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 27296
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
	// 入力
	int N;
	cin >> N;
	
	// 3桁のパスワードの数はNの3乗で個数が算出できる。
	int answer = pow(N, 3.0f);
	
	cout << answer << endl;
}

Measured memory_bytes: 384
#include<stdio.h>

int main(void){

  int S, sec, min, hou;

  scanf("%d",&S);
  
  hou = S / 3600;
  min = (S - hou*3600) / 60;
  sec = (S - 3600*hou - min*60) ;

  printf("%d:%d:%d\n",hou,min,sec);

  return 0;
}

Measured memory_bytes: 1796
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

const long MOD = 1000000007;
typedef pair<int, int> P;
typedef long long ll;

int main(){
    int H, W, K;
    cin >> H >> W >> K;

    string S[H];
    for(int i=0; i<H; i++){
        cin >> S[i];
    }

    int ans = 1000000005;
    for(int h=0; h<pow(2, H-1); h++){
        // cout << "--------------------" << endl;
        int row = 1;
        for(int i=0; i<H; i++){
            if(((h >> i)&1) == 1) row++;
        }
        // cout << h << endl;
        // cout << row << endl;

        int wc[row][W];
        for(int i=0; i<row; i++){
            for(int j=0; j<W; j++){
                wc[i][j] = 0;
            }
        }

        int tate = 0;
        for(int i=0; i<H; i++){
            for(int j=0; j<W; j++){
                if(S[i][j] == '1') wc[tate][j]++;
            }
            if(((h >> i)&1) == 1) tate++;
        }

        int cnt = 0;
        int sum[row][W+1];
        for(int i=0; i<row; i++){
            for(int j=0; j<=W; j++){
                sum[i][j] = 0;
            }
        }
        for(int j=1; j<=W; j++){
            int fl = 0;
            for(int i=0; i<row; i++){
                if(sum[i][j] == 0 && wc[i][j-1]>K){
                    fl = 2;
                    break;
                }
                // cout << i << " " << j-1 << " " << sum[i][j-1] << " " << wc[i][j-1] << endl;
                if(sum[i][j-1]+wc[i][j-1] > K) fl = 1;
            }

            if(fl == 2){
                cnt = 1000000005;
                break;
            }
            if(fl == 1){
                cnt++;
                for(int i=0; i<row; i++){
                    sum[i][j] = wc[i][j-1];
                }
                continue;
            }

            for(int i=0; i<row; i++){
                sum[i][j] = sum[i][j-1] + wc[i][j-1];
            }
        }
        // cout << cnt << endl;
        ans = min(ans, row-1+cnt);
    }

    cout << ans << endl;

    return 0;
}


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

using namespace std;

int main()
{
    int k, t;
    cin >> k >> t;

    int max = -1;
    int sum = 0;
    for (int i = 0; i < t; i++) {
        int a;
        cin >> a;

        if (a > max) max = a;
        sum += a;
    }

    sum -= max;
    if (sum >= max-1) {
        cout << 0 << endl;
    } else {
        cout << max-1 - sum << endl;
    }




    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

int dp[100010];
bool vis[100010];

int solve(int n)
{
    if (n == 0)
        return 0;
    if (vis[n])
        return dp[n];
    vis[n] = true;
    int res = solve(n - 1) + 1;
    for (int i = 6; i <= n; i *= 6)
        res = min(res, solve(n - i) + 1);
    for (int i = 9; i <= n; i *= 9)
        res = min(res, solve(n - i) + 1);
    return dp[n] = res;
}

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

    int n;
    cin >> n;
    cout << solve(n) << endl;
}

Measured memory_bytes: 4224
str = gets.chomp
gets.to_i.times{
	code = gets.split
	range = code[1].to_i..code[2].to_i
	case code[0]
	when 'print'
		puts str[range]
	when 'replace'
		str[range] = code[3]
	when 'reverse'
		str[range] = str[range].chars.reverse.join
	end
}

Measured memory_bytes: 8820
from sys import stdin


def main():
    lines = stdin.readlines()
    N, M = map(int, lines[0].split())
    X = [sum(1 << int(j) - 1 for j in i.split()[1:]) for i in lines[1:-1]]
    Z = lines[-1].split()
    print(sum([1 for i in range(1 << N) if sum([1 for x, y in zip(X, Z) if bin(i & x).count("1") % 2 == int(y)]) == M]))
    return


main()


Measured memory_bytes: 3188
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{
    internal class Solution
    {
        public int N;
        public List<List<int>> D;
        public void Run()
        {
            // Input
            N = Input.ReadInt();

            D = new List<List<int>>();
            for (int i = 0; i < N; i++)
            {
                D.Add(new List<int>());
            }

            for (int i = 1; i < N; i++)
            {
                var w = Input.ReadInt() - 1;
                int l = i;
                D[w].Add(l);
            }

            int ret = Depth(0);
            Console.WriteLine(ret);
        }

        public int Depth(int i)
        {
            int c = D[i].Count;
            if (c == 0) return 0;
            if (c == 1) return Depth(D[i][0]) + 1;
             
            int[] depths = new int[c];
            for (int j = 0; j < c; j++)
            {
                depths[j] = Depth(D[i][j]);
            }

            Array.Sort(depths);

            for (int d = 0; d < c; d++)
            {
                depths[d] += (c - d);
            }

            int ret = 0;
            for (int d = 0; d < c; d++)
            {
                ret = Math.Max(ret, depths[d]);
            }

            return ret;
        }

    }


    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

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

int main(){
  int l, r; cin >> l >> r;
  
  int mod = 2019;
  
  int cycle = min(2019, r - l + 1);
  
  for (int i = l; i < l + cycle; i++){
    
    int im = i % 2019;
    
    for (int j = i + 1; j < l + cycle; j++){
      
      int jm = j % 2019;
      
      mod = min(mod, (im * jm) % 2019);
      if (mod == 0) break;
      
    }
    if (mod == 0) break;
  }
  
  cout << mod << endl;
}

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

long long GCD(long long a, long long b){
	if(b==0) return a;
    else return GCD(b, a%b);
}

int main(){
  long long a,b;
  cin >> a >> b;
  
  cout << a*b/GCD(a,b) << endl;
  
}

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

public class Main{
	public static void main(String[] args){

	Scanner stdIn = new Scanner(System.in);
	BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
	try{
	String strS = input.readLine();
	String strT = input.readLine();

	char[] charArray = strS.toCharArray();
	String ans = "No";

	for(int i = 0;i < charArray.length;i++){
		char c = charArray[charArray.length - 1];

		for(int j = charArray.length - 1;j > 0;j--){
			charArray[j] = charArray[j - 1];
		}
		charArray[0] = c;
		String str = String.valueOf(charArray);

		if(str.equals(strT)){
			ans = "Yes";
			break;
		}
	}
	System.out.println(ans);
	}
	catch(IOException e){
	
	}
		



	}
}


Measured memory_bytes: 23252
#include <iostream>

using namespace std;

#define INF 2000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> P;


int main()
{
	int N, K;
	cin >> N >> K;

	int ans;
	ans = 1;

	for (int i = 0; i < N; i++) {
		if (i == 0) {
			ans *= K;
		} else {
			ans *= (K-1);
		}
	}
	cout << ans << "\n";
}


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

int main(){
  int n,a=0,b=0,o=0,ab=0;
  string s;

  while(scanf("%d,",&n)!=EOF){
    cin >> s;
    if(s == "A")a++;
    else if(s == "B")b++;
    else if(s == "O")o++;
    else if(s == "AB")ab++;
  }
  cout << a << endl << b << endl << ab << endl << o << endl;


}

Measured memory_bytes: 0
#include <iostream>
#include <string>

int main(void)
{
	int H,W = 0;
	int h,w = 0;
	std::cin >> H >> W;
	std::cin >> h >> w;

	// std::cout << "H:" << H << "W:"<< W << std::endl;
	// std::cout << "h:" << h << "w:"<< w << std::endl;
	std::cout << (H-h)*(W-w) << std::endl;

	return 0;
}

Measured memory_bytes: 256
def f(n):
    if n==3:
        A = [2,3,25]
    elif n%3==1:
        k = n//3
        A = [2*i for i in range(1,3*(k-1)+3)]
        A += [3,9]
    elif n%3==2:
        k = n//3
        A = [2*i for i in range(1,3*k+1)]
        A += [3,9]
    else:
        k = n//3
        A = [2*i for i in range(1,3*k-3)]
        A += [3,9,15,21]
    return A
    
N = int(input())
if N<15003:
    A = f(N)
else:
    A = f(15002)
    A.pop()
    A.pop()
    n = N-15002
    if n%2==1:
        n = (n+1)//2
        B = [3+6*i for i in range(2*n+2)]
        A.pop()
        A += B
    else:
        n = n//2
        B = [3+6*i for i in range(2*n+2)]
        A += B
print(*A)

Measured memory_bytes: 42096
#include<iostream>
#include<string>

using namespace std;

int main(){
  int a,b;
  string s;
  cin >> a >> b;
  cin >> s;
  bool ans=true;
  for(int i=0;i<s.length();i++){
    if(i!=a){
      if(s[i]=='-'){
        ans=false;
        break;
      }
    }
    else{
      if(s[i]!='-'){
        ans=false;
        break;
      }
    }
  }
  if(ans){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <utility>
#define maxn 55
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int n;
ll x,b[maxn],p[maxn];
ll calc(int n,ll x){
	if(n == 0) return x ? 1 : 0;
	ll nump = 0;
	if(x <= 1) return nump;
	--x;
	if(x < b[n - 1] + p[n - 1]) return nump + calc(n - 1,x);
	nump += p[n - 1], x -= b[n - 1] + p[n - 1];
	if(x <= 1) return nump + x;
	--x, ++nump;
	if(x < b[n - 1] + p[n - 1]) return nump + calc(n - 1,x);
	nump += p[n - 1], x -= b[n - 1] + p[n - 1];
	return nump;
}
int main(){
	scanf("%d%lld",&n,&x);
	b[0] = 0, p[0] = 1;
	for(int i=1;i<=n;i++){
		b[i] = 2 * b[i - 1] + 2, p[i] = 2 * p[i - 1] + 1;
	}
	printf("%lld\n",calc(n,x));
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#define N 200001

#define MAX 1000
#define MAXWEIGHTIJ 20000

struct MC {
	int cost,order;
};

void exchange( struct MC *px, struct MC *py )
{
  struct MC t;
	t=*px;
	*px=*py;
	*py=t;
}

int Partition( struct MC A[], int p, int r )
{

    struct MC x;
    int i=p-1;
    x=A[r];

    int j;

    for( j=p; j<r; j++ ) {
        if( A[j].cost < x.cost ) {
            i++;
            exchange( &A[i], &A[j] );
         }
    }
    exchange( &A[i+1], &A[r]);
    return i+1;
}
void QuickSort( struct MC A[], int p, int r )
{
    int q;
    if( p < r ) {
        q=Partition( A, p, r );
        QuickSort( A, p, q-1 );
        QuickSort( A, q+1, r );
    }
    return;
}

int tryChange( int n, struct MC W[] )
{
	int cnt, fixedcost,pro, from, to, togoal,cost,lowestCost,i,j,lowW,lowestW,low,high,lowest;
	lowestW=lowW=lowestCost=cost=MAXWEIGHTIJ;
	lowest=high=low=-1;
	for( i=0; i<n; i++ ) {
		if( i != W[i].order && W[i].cost < lowW ) {
			lowW=W[i].cost;
			low=i;
			for( j=0; j<n; j++ ) {
				if( low == W[j].order ) {
					high=j;
					break;
				}
			}
		}
		if( W[i].cost < lowestW ) {
			lowestW=W[i].cost;
			lowest=i;
		}
	}

	if( W[high].order == low && W[low].order == high ) {
		lowestCost = W[low].cost + W[high].cost;
	  }
    else if( low != lowest ) {
		fixedcost = W[low].cost + W[lowest].cost;
		pro = W[low].cost - W[lowest].cost;
		from=high;
		to=low;
		togoal = W[low].order;
		cnt=0;
		while( 1 ) {
			if( W[from].order == to ) {
				if( togoal == to ) { break; }
				to=from;
				cnt++;
			}
      else {
				break;
			}
			for( i=0; i<n; i++ ) {
				if( i != W[i].order ) {
					if( to == W[i].order ) {
						from=i;
						break;
					}
				}
			}
		}
		pro = ( pro * cnt ) - ( 2 * fixedcost );

		if( 0 < pro ) {
			high=low;
			low=lowest;
			lowestCost = fixedcost;
		}
	}

	if( W[high].order == low ) {
		lowestCost = W[low].cost + W[high].cost;
	}

    if( MAXWEIGHTIJ != lowestCost ) {
		exchange( &W[low], &W[high] );
	  }
    else {
    	lowestCost=0;
    }
	return lowestCost;
}


int main( void )
{
    int n,i,cost;
    struct MC W[MAX+1];

    scanf( "%d", &n );
    for( i=0; i<n; i++ ) {
        scanf( "%d", &W[i].cost );
        W[i].order=i;
    }
	QuickSort( W, 0, n-1 );
	cost=i=0;
	while( (i = tryChange( n, W ) ) ) {
		cost+=i;
	}
	printf( "%d\n", cost );
    return 0;
}



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

#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)

using namespace std;

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

int main() {
  string s, t;
  cin >> s >> t;
  bool res = t.substr(0, t.size() - 1) == s;
  cout << (res ? "Yes" : "No") << endl;
  return 0;
}


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

typedef long long ll;
int h,w,n,p;
bool board[1001][1001];
ll cnt[1001][1001];

int main() {
  while(cin>>h>>w>>n, h|w|n) {
    memset(board, false, sizeof(board));
    memset(cnt, 0, sizeof(cnt));
    cnt[0][0] = n-1;
    for (int i=0; i<h; ++i) {
      for(int j=0; j<w; ++j) {
        cin>>p;
        if (p) board[i][j] = true;
      }
    }
    for (int i=0; i<h; ++i) {
      for (int j=0; j<w; ++j) {
        if (cnt[i][j]%2 == 0) {
          if (j<w-1) cnt[i][j+1] += cnt[i][j]/2;
          if (i<h-1) cnt[i+1][j] += cnt[i][j]/2;
        } else {
          if (j<w-1) cnt[i][j+1] += cnt[i][j]/2 + ((board[i][j])?1:0);
          if (i<h-1) cnt[i+1][j] += cnt[i][j]/2 + ((!board[i][j])?1:0);
          board[i][j] ^= true;
        }
      }
    }

    int x=0,y=0;
    while(x<w && y<h) {
      if (board[y][x]) x++;
      else y++;
    }
    x++, y++;
    cout<<y<<" "<<x<<endl;
  }
}

Measured memory_bytes: 9972
#include <string.h>
int main(void)
{
          char s[100] ;
          gets(s) ;
          int x ;
          x = strlen(s) ;
          if( x != 6)
          {
                    printf("No") ;
                    return 0 ;
          }
          else if( s[0] != s[1] && s[2]== s[3] && s[4]==s[5])
          {
                    printf("Yes") ;
                    return 0 ;
          }
          else printf("No") ;
}


Measured memory_bytes: 128
n = int(input())
t, a = (int(i) for i in input().split())
h = [int(i) for i in input().split()] 


def c(T,X,A):
    return abs(A-(T-X*0.006))

h2 = []
ii = 1
for val in h:
    h2.append((ii, c(t, val, a)))
    ii = ii + 1

result = 1
minn = 10000000
for num , val in h2:
    if minn > val :
        minn = val
        result = num

print(result) 

Measured memory_bytes: 3188
/* #region template */
#![allow(unused_imports)]
use std::cmp::{max, min};
use std::io::{stdin, stdout, Bytes, Read, Stdin, StdinLock, Stdout, StdoutLock, Write};
use std::iter::{repeat, repeat_with};
use std::mem::swap;
use std::str::FromStr;
#[allow(dead_code)]
struct Io<'a> {
    reader: Bytes<StdinLock<'a>>,
    writer: StdoutLock<'a>,
    in_buf: [u8; BUF_SIZE],
}
#[allow(dead_code)]
impl<'a> Io<'a> {
    fn new(stdin: &'a Stdin, stdout: &'a Stdout) -> Io<'a> {
        Io {
            reader: stdin.lock().bytes(),
            writer: stdout.lock(),
            in_buf: [0; BUF_SIZE],
        }
    }
    fn r<T: FromStr>(&mut self) -> T {
        let mut count = 0;
        loop {
            match self.reader.next() {
                Some(Ok(b' ')) | Some(Ok(b'\n')) => break,
                Some(Ok(c)) => self.in_buf[count] = c,
                _ => panic!(),
            }
            count += 1;
        }

        let s = unsafe { std::str::from_utf8_unchecked(&self.in_buf[0..count]) };
        s.parse().unwrap_or_else(|_| panic!())
    }
    fn ru(&mut self) -> usize {
        self.r()
    }
    fn iter<'b, T>(&'b mut self) -> IoIter<'a, 'b, T> {
        IoIter::new(self)
    }
    fn c<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        self.iter().take(n).collect()
    }
    fn cu(&mut self, n: usize) -> Vec<usize> {
        self.c(n)
    }
    fn w<T: std::fmt::Display>(&mut self, v: T) {
        writeln!(self.writer, "{}", v).unwrap();
    }
    fn wn<T: std::fmt::Display>(&mut self, v: T) {
        write!(self.writer, "{}", v).unwrap();
    }
}
#[allow(dead_code)]
struct IoIter<'a: 'b, 'b, T> {
    io: &'b mut Io<'a>,
    m: std::marker::PhantomData<T>,
}
#[allow(dead_code)]
impl<'a: 'b, 'b, T> IoIter<'a, 'b, T> {
    fn new(io: &'b mut Io<'a>) -> IoIter<'a, 'b, T> {
        IoIter {
            io,
            m: std::marker::PhantomData,
        }
    }
}
impl<'a, 'b, T: FromStr> Iterator for IoIter<'a, 'b, T> {
    type Item = T;
    fn next(&mut self) -> Option<Self::Item> {
        Some(self.io.r())
    }
}
fn main() {
    let stdin = stdin();
    let stdout = stdout();
    let mut io = Io::new(&stdin, &stdout);
    unsafe {
        solve(&mut io);
    }
}
/* #endregion */

const BUF_SIZE: usize = 1024;

unsafe fn solve(io: &mut Io) {
    let n = io.ru();
    let m = io.ru();
    let h = io.cu(n);

    let mut t = vec![None; n];

    for ab in repeat_with(|| (io.ru() - 1, io.ru() - 1)).take(m) {
        if h[ab.0] > h[ab.1] {
            if t[ab.0].is_none() {
                t[ab.0] = Some(true);
            }
            t[ab.1] = Some(false);
        } else if h[ab.0] < h[ab.1] {
            if t[ab.1].is_none() {
                t[ab.1] = Some(true);
            }
            t[ab.0] = Some(false);
        } else {
            t[ab.0] = Some(false);
            t[ab.1] = Some(false);
        }
    }

    let count = t.iter().filter(|i| **i != Some(false)).count();
    io.w(count);
}


Measured memory_bytes: 2960
N = int(input())
S = [input() for i in range(N)]
d = {}
S_trans = [''.join(sorted(list(s))) for s in S]
count = 0
for s in S_trans:
  if s in d:
    count += d[s]
    d[s] += 1
  else:
    d[s] = 1
print(count)

Measured memory_bytes: 26640
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#include <string>

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

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

int main(void){
    int A, B;
    int answer = 0;

    cin >> A >> B;

    answer = max(A, B) + max(min(A, B), max(A, B) - 1);

    cout << answer << endl;

    return 0;
}

Measured memory_bytes: 384
s = input()
A, B, C, D = int(s[0]), int(s[1]), int(s[2]), int(s[3])
N = 3


for i in range(2**N):
    sum = int(s[0])
    f = s[0]
    for j in range(N):
        if i>>j & 1:
            sum += int(s[j+1])
            f += "+" + s[j+1]
        else:
            sum -= int(s[j+1])
            f += "-" + s[j+1]

    if sum == 7:
        print(f + "=7")
        break

Measured memory_bytes: 3064
#include<stdio.h>
int main()
{
	int i, W,H,l;
	while (1){
		scanf("%d %d", &H, &W);
		if (H == 0 && W == 0)break;

		for (i = 1; i <= H; i++)
		{
			for (l = 1; l <= W; l++)
				printf("#");
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}


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

#define For(i, l, r) for (register int i = (l), i##end = (int)(r); i <= i##end; ++i)
#define Fordown(i, r, l) for (register int i = (r), i##end = (int)(l); i >= i##end; --i)
#define Rep(i, r) for (register int i = (0), i##end = (int)(r); i < i##end; ++i)
#define Set(a, v) memset(a, v, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define debug(x) cout << #x << ": " << (x) << endl

using namespace std;

template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, T b) { return b > a ? a = b, 1 : 0; }

namespace pb_ds {   
    namespace io {
        const int MaxBuff = 1 << 15;
        const int Output = 1 << 23;
        char B[MaxBuff], *S = B, *T = B;
        #define getc() ((S == T) && (T = (S = B) + fread(B, 1, MaxBuff, stdin), S == T) ? 0 : *S++)
        char Out[Output], *iter = Out;
        inline void flush() {
            fwrite(Out, 1, iter - Out, stdout);
            iter = Out;
        }
    }

    template<class Type = int> inline Type read() {
        using namespace io;
        register char ch; register Type ans = 0; register bool neg = 0;
        while(ch = getc(), (ch < '0' || ch > '9') && ch != '-')     ;
        ch == '-' ? neg = 1 : ans = ch - '0';
        while(ch = getc(), '0' <= ch && ch <= '9') ans = ans * 10 + ch - '0';
        return neg ? -ans : ans;
    }

    template<class Type> inline void Print(register Type x, register char ch = '\n') {
        using namespace io;
        if(!x) *iter++ = '0';
        else
        {
            if(x < 0) *iter++ = '-', x = -x;
            static int s[100]; register int t = 0;
            while(x) s[++t] = x % 10, x /= 10;
            while(t) *iter++ = '0' + s[t--];
        }
        *iter++ = ch;
    }
}

using namespace pb_ds;

void File() {
#ifdef zjp_shadow
	freopen ("E.in", "r", stdin);
	freopen ("E.out", "w", stdout);
#endif
}

const int N = 5e5 + 1e3;

int n, d[N], pre[N], f[N];

int main () {

	File();

	n = read(); pre[0] = read(); f[n + 1] = 1;

	For (i, 1, n) 
		pre[i] = min(pre[i - 1], abs(pre[i - 1] - (d[i] = read())));
	Fordown (i, n, 1) 
		f[i] = f[i + 1] + ((f[i + 1] << 1) > d[i] ? d[i] : 0);

	For (i, 1, read()) {
		int x = read();
		if(pre[x - 1] >= f[x + 1])
			putchar ('Y'), putchar ('E'), putchar ('S'), putchar ('\n');
		else
			putchar ('N'), putchar ('O'), putchar ('\n');
	}

	return 0;

}

Measured memory_bytes: 8064
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
int arr[15];
int m,n;
vector<int> x;
vector<int> y;
void binary(int p)
{
    int i=0;
    int flag=1;
    while(i<10)
    {
        if(p&flag)
            x.push_back(arr[i]);
        else
            y.push_back(arr[i]);
        flag=flag<<1;
        i++;
    }
}
int panduan()
{
    for(int j=1;j<x.size();j++)
    {
        if(x[j]<x[j-1])
          return 0;
    }
    for(int i=1;i<y.size();i++)
    {
        if(y[i]<y[i-1])
          return 0;
    }
    return 1;
}
int solve()
{
    for(int i=0;i<1024;i++)
    {
        x.clear();
        y.clear();
        binary(i);
        if(panduan())
            return 1;
    }
    return 0;
}
int main()
{
    int n;
    scanf("%d",&n);
    while(n--)
    {
        for(int i=0;i<10;i++)
            scanf("%d",&arr[i]);
        if(solve())
        {
            printf("YES\n");
        }
        else
        {
            printf("NO\n");
        }
    }
    return 0;
}

Measured memory_bytes: 1032
//                   ********** YATIN KWATRA **********

// AC BAKSHI RABBA

#include <bits/stdc++.h>
#define ll                      long long 
#define ld                      long double
#define ull                     unsigned long long 
#define FIO                     ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl                    "\n"
#define fo(i,a,b)               for(int i = a; i<=b ; i++)
#define rfo(i,a,b)              for(int i = a; i>=b ; i--)
#define vii                      vector<int>
#define vll                     vector<ll>
#define pq                      priority_queue
#define uom                      unordered_map                
#define all(v)                  v.begin(),v.end()
#define mp                      make_pair
#define pb                      push_back
#define pob                     pop_back
#define ff                      first
#define ss                      second
#define pii                     pair<int,int> 
#define pll                     pair<long,long>
#define mll                     map<ll,ll>
#define mii                     map<int,int>
#define vvii                    vector<vii>
#define vvll                    vector<vll>
#define mod                     1000000007
#define pi                      3.1415926535897932384626433832795
// #define node                    Node


using namespace std;

void INPUT() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

}

/*
    
   -> Check For Overflows
   -> Out of Bounds
   -> Initialisations of global arrays and variables
   -> Its not Always Complex, Try to simplify
   -> write it down and try to solve
   -> Have Faith in urself and in ur approach
   -> If it seems totally out of reach, switch to next :)
   -> And Come Back later, if possible 
*/

const int N = 200005;
int v1[N];
int v2[N];



void solve()
{ 
        int n,m;
        ll t;
        cin >> n >> m >> t;
    
        fo(i,0,n-1) cin >> v1[i];
        fo(i,0,m-1) cin >> v2[i];

        ll sum = 0LL;
        int best = 0;

        int i = -1;
        while((i+1)<n)
        {
          if(((sum+v1[i+1])<=t)) sum += v1[++i];
          else break;
        }

        int j = -1;

          while((j+1)<m)
          {
            if(((sum+v2[j+1])<=t))  sum += v2[++j];
            else break;
          }

           best = max(best,(i+j+2));

         //  cout << i << ' ' << j << " " << best << endl;

        while( (j+1) < m and i>=0)
        {
           // cout << "Yes\n";
        //  cout << " sum : " << sum << " i: " << i << " j: " << j << endl;
          
              sum -= v1[i--];
  
              while((j+1) < m)
             {
               if(((sum+v2[j+1])<=t)) sum += v2[++j];
               else break;
             }
     
               best = max(best,(i+j+2));
        }

        cout << best << endl;

       
}
int main() {
    
    FIO
  //  INPUT();
    
    int t;
    t = 1;
 //   cin >> t;
    
    while(t--)
    {
       solve();
    }
    return 0;
}


Measured memory_bytes: 5148
list = input().split()
l = int(list[0])
r = int(list[1])
# print(l, r)
ans=2018
if r-l > 2019:
	min = 2019
else:
  min = r-l
for i in range(l,l+min):
  for j in range(l+1,l+min+1):
    if (i*j)%2019 < ans:
      ans = (i*j)%2019
      
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 2147483600123456LL

int main(){
  int n;
  cin>>n;
  vector<long> vec(3*n);
  rep(i,3*n) cin>>vec[i];

  vector<long> l(n+2,0), r(n+2,0);

  // l
  {
    long acc = 0;
    priority_queue<long> pq;
    rep(i,n){
      acc += vec[i];
      pq.push(-vec[i]);
    }
    l[0] = acc;
    rep(i,n){
      long t = pq.top(); pq.pop();
      t *= -1;
      acc -= t;
      t = max(t, vec[i+n]);
      pq.push(-t);
      acc += t;
      l[i+1] = acc;
    }
  }

  // r
  {
    long acc = 0;
    priority_queue<long> pq;
    rep(i,n){
      acc += vec[i+2*n];
      pq.push(vec[i+2*n]);
    }
    r[n+1] = acc;
    rep(i,n){
      long t = pq.top(); pq.pop();
      acc -= t;
      t = min(t, vec[2*n-1-i]);
      pq.push(t);
      acc += t;
      r[n-i] = acc;
    }
  }

  long ans = -INF;
  rep(i,n+1){
    ans  = max(ans, l[i] - r[i+1]);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 5992
#include <iostream>

int main(int argc, char const *argv[]) {
  int64_t a, b;
  std::cin >> a >> b;
  if (b > 0) {
    if (a <= 0) {
      std::cout << "Zero" << std::endl;
    } else {
      std::cout << "Positive" << std::endl;
    }
  } else if (b == 0) {
    std::cout << "Zero" << std::endl;
  } else {
    int c = b - a;
    if (c % 2 == 0) {
      std::cout << "Negative" << std::endl;
    } else {
      std::cout << "Positive" << std::endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256