akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<stdlib.h> 
#include<cstring>
#include<map>
#include<list>
#include<stdio.h>
#include<cmath>
#include<iomanip>
#include<bitset>
#include<vector>
#include<time.h>
#include<algorithm> 
#include<queue>
#include<set>
#include<deque>
#define mod 1e9+7
#define inf 1e18 
typedef long long ll;
typedef long double ld;
using namespace std;
typedef list<ll> li;
typedef list<ll>::iterator lt;
li sh_r;
ll N,s;
vector<li>a;
bool dfs(ll step,ll x,ll f){
	if(x>N)cout<<f<<" "<<x<<endl;
	if(x==N){
	  s=step;
	  return true;
    }
	for(lt it=a[x].begin();it!=a[x].end();it++){
		if(*it==f)continue;
		if(dfs(step+1,*it,x)){
			sh_r.push_back(x);
			return true;
		}
	}
	return false;
}
ll num(ll x,ll f){
	ll n=1;
	for(lt it=a[x].begin();it!=a[x].end();it++){
		if(*it==f)continue;
		n+=num(*it,x);
	}
	return n;
}
int main(){	
    cin>>N;
    a.resize(N+10);
    for(ll K=1;K<N;K++){
    	ll x,y;
    	scanf("%lld%lld",&x,&y);
    	a[x].push_back(y);
    	a[y].push_back(x);
	}
	dfs(0,1,-1);
	s--;
	ll F=1,S=N;
	if(N!=2){
		ll j=s/2;
		for(lt it=sh_r.begin();it!=sh_r.end();it++){
			j--;
			if(j==0)S=*it;
			if(j==-1){
				F=*it;
				break;
			}
		}
	}
	ll Fen=num(F,S);
	ll Snu=num(S,F);
	if(Fen>Snu)printf("Fennec");
	else printf("Snuke");
	return 0;
}

Measured memory_bytes: 17408
import bisect
A, B, Q = map(int, input().split())
s = list(int(input()) for _ in range(A))
t = list(int(input()) for _ in range(B))

for i in range(Q):
    ans = 10 ** 19
    x = int(input())
    stmp1 = bisect.bisect_left(s, x)
    for j in range(2):
        if stmp1 == 0 and j == 1:
            continue
        if stmp1 == A and j == 0:
            continue
        ttmp1 = bisect.bisect_left(t, s[stmp1 - j])
        ktmp = 10 ** 11
        if ttmp1 != 0:
            ktmp = min(ktmp, abs(s[stmp1 - j] - t[ttmp1 - 1]))
        if ttmp1 != B:
            ktmp = min(ktmp, abs(s[stmp1 - j] - t[ttmp1]))
        total = abs(x - s[stmp1 - j]) + ktmp
        ans = min(ans, total)

    ttmp1 = bisect.bisect_left(t, x)
    for j in range(2):
        if ttmp1 == 0 and j == 1:
            continue
        if ttmp1 == B and j == 0:
            continue
        stmp1 = bisect.bisect_left(s, t[ttmp1 - j])
        ktmp = 10 ** 11
        if stmp1 != 0:
            ktmp = min(ktmp, abs(t[ttmp1 - j] - s[stmp1 - 1]))
        if stmp1 != A:
            ktmp = min(ktmp, abs(t[ttmp1 - j] - s[stmp1]))
        total = abs(x - t[ttmp1 - j]) + ktmp
        ans = min(ans, total)
    print(ans)

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

using ll=int64_t;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(),x.end()
auto& errStream=cerr;
#ifdef LOCAL
#define cerr (cerr<<"-- line "<<__LINE__<<" -- ")
#else
class CerrDummy{}cerrDummy;
template<class T>
CerrDummy& operator<<(CerrDummy&cd,const T&){
	return cd;
}
using charTDummy=char;
using traitsDummy=char_traits<charTDummy>;
CerrDummy& operator<<(CerrDummy&cd,basic_ostream<charTDummy,traitsDummy>&(basic_ostream<charTDummy,traitsDummy>&)){
	return cd;
}
#define cerr cerrDummy
#endif
#define REACH cerr<<"reached"<<endl
#define DMP(x) cerr<<#x<<":"<<x<<endl
#define ZERO(x) memset(x,0,sizeof(x))
#define ONE(x) memset(x,-1,sizeof(x))

using pi=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"{";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

ll read(){
	ll i;
	scanf("%"  SCNd64,&i);
	return i;
}

void printSpace(){
	printf(" ");
}

void printEoln(){
	printf("\n");
}

void print(ll x,int suc=1){
	printf("%" PRId64,x);
	if(suc==1)
		printEoln();
	if(suc==2)
		printSpace();
}

string readString(){
	static char buf[3341000];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341000];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}

template<class T,class U>
void chmin(T& a,U b){
	if(b<a)
		a=b;
}

template<class T>
T Sq(const T& t){
	return t*t;
}

#define CAPITAL
void Yes(bool ex=true){
	#ifdef CAPITAL
	cout<<"YES"<<endl;
	#else
	cout<<"Yes"<<endl;
	#endif
	if(ex)exit(0);
}
void No(bool ex=true){
	#ifdef CAPITAL
	cout<<"NO"<<endl;
	#else
	cout<<"No"<<endl;
	#endif
	if(ex)exit(0);
}

const ll infLL=LLONG_MAX/3;

#ifdef int
const int inf=infLL;
#else
const int inf=INT_MAX/2-100;
#endif

signed main(){
	int a=read(),b=read(),c=read();
	chmin(c,a+b+1);
	print(b+c);
}


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

int main(){
  int N;
  cin >> N;
  vector<long long> A(N,0);
  for (int i=0;i<N;i++)cin >> A[i];
  
  int count=0;
  long long m=0;
  for (int i=0;i<N;i++){
    if(A[i]>m){
      m=A[i];
      count = i;
    }
  }
  sort(A.begin(),A.end());
  for(int i=0;i<N;i++){
    if(i==count){
      cout << A[N-2] << endl;
    }
    else{
      cout << A[N-1]<<endl;
    }
  }
}




Measured memory_bytes: 3200
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		double a = 0.0;
		for(int i = 0; i < n; i++) {

			a += (1/sc.nextDouble());
		}
		System.out.println(1/a);
		sc.close();
	}
}


Measured memory_bytes: 25172
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#define pb push_back
#define int long long
#define MEM(x) memset(x,0,sizeof(x))
#define vc vector<int>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define inf 0x3f3f3f3f
#define t_case int tt; cin>>tt; while (tt--)
#define lnginf 9223372036854775807
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define For(i,j,k) for (int i=(int)(j);i<(int)(k);i++)
#define rFor(i,j,k) for (int i=(int)(k-1);i>=(int)(j);i--)
#define ins insert
#define in(x); { for (auto &i : x) cin >> i; }
#define out(x); { for (auto i : x) cout<<i<<' ' ; }
#define pi  pair<int,int>
#define ti tuple<int,int,int>
#define PI 3.14159265359
#define des(x) setprecision(x)
const long long LL_INF = (long long) 2e18 + 5;
using namespace std;
//void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
const int N=2e5+10,mod=1e9+7;
vector<int> div(int a) {
  vector<int> ans;
  for(int i=2;i*i<=a;i++){
    if(a%i==0){ 
      ans.pb(i);
      while(a%i==0)a/=i;
    }
  }
  if (a!=1)ans.pb(a);
  return ans;
  
}
void solve(){
   int n; cin>>n;
   bool cok=1;
   vector<int> v(n);in(v);
   int g=v[0];
   set<int> now;
   For(i,0,n){
    g=__gcd(v[i],g);
    if(!cok)continue;
    vector<int> prime=div(v[i]);
    for(auto p:prime){
      cok&=(!now.count(p));
      now.ins(p);
    }
  }
  if(cok){
    cout<<"pairwise coprime\n";
    return;
  }
  if(g==1){
    cout<<"setwise coprime\n";
    return;
  }
  cout<<"not coprime\n";
  
}
int32_t main() {

#ifndef ONLINE_JUDGE
   freopen("input.txt", "r", stdin);
   freopen("output.txt", "w", stdout);
#endif
   fastio
   //t_case

    solve();



}

Measured memory_bytes: 11096
//Deep Godhani
//DAIICT

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

#define N 100000000000
#define PI acos(-1)
#define INF LONG_LONG_MAX
#define NINF LONG_LONG_MIN
#define ll long long int
#define ld long double
#define precision(x,d) cout << fixed << setprecision(d) << x
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL))

void solve()
{
  ll d,t,s;
  cin >> d >> t >> s;

  ll ans = s*t;
  if(ans < d)
  {
    cout << "No" << endl;
  }
  else
  {
    cout << "Yes" << endl;
  }
}

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


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

vector<pair<int,int> > edge;
vector<int> ans;
int n, m, p[100005];
int f(int u){
	return (p[u] < 0 ? u : p[u] = f(p[u]));
}
void j(int u,int v){
	u = f(u); v = f(v);
	if(u == v) return;
	if(p[u] > p[v]) swap(u, v);
	p[u] += p[v];
	p[v] = u;
}
signed main(){
	cin >> n >> m;
	for(int i = 1 ; i <= n ; i ++)
		p[i] = -1;
	for(int i = 1 ; i <= m ; i ++){
		int u, v;
		cin >> u >> v;
		edge.push_back({u, v});
	}
	int cur = n*(n - 1)/2;
	ans.push_back(cur);
	for(int i = m - 1 ; i >= 1 ; i --){
		int u = edge[i].first, v = edge[i].second;
		u = f(u), v = f(v);
		if(u == v) {
			ans.push_back(cur);
		} else{
			cur -= p[u]*p[v];
			j(u, v);
			ans.push_back(cur);
		}
	}
	for(int i = ans.size() - 1 ; i >= 0 ; i --)
		cout << ans[i] << endl;
}

Measured memory_bytes: 5488
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>

using namespace std;

int main(){
  int h, w, n;
  cin >> h >> w >> n;
  int a = max(h, w);
  int b = min(h, w);
  cout << n/a + (n%a != 0) << endl;
}


Measured memory_bytes: 256
#[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, ( $($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);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($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!(s: chars);
    puts!("{}\n", if s[1] == 'R' { "ABC" } else { "ARC" });
}

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: 2192
x = list(map(int, input().split()))
a=[input() for i in range(x[0])]

for i in range(x[1]+2):
    print('#',end="")
print('')
for i in a:
    print('#{0}#'.format(i))
for i in range(x[1]+2):
    print('#',end="")
print('')


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define mp make_pair
#define pb push_back
#define ff first
#define ss second

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

	int n;
	cin>>n;
	int a[n],b[n],c[n];
	for(int i=0;i<n;i++)
		cin>>a[i]>>b[i]>>c[i];
	int dp[n+1][3];
	memset(dp,0,sizeof(dp));
	for(int i=0;i<n;i++){
		dp[i+1][0] = a[i]+max(dp[i][1],dp[i][2]);
		dp[i+1][1] = b[i]+max(dp[i][0],dp[i][2]);
		dp[i+1][2] = c[i]+max(dp[i][0],dp[i][1]);
	}
	cout<< max(dp[n][0],max(dp[n][1],dp[n][2])) << endl;
}

Measured memory_bytes: 2560
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
int getDigit(int n);            // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// class
// ------------------------------------------------
class Combi
{
  public:
    Combi();
    long long Combination(long long n, long long k);
  private:
    vector<vector<long long>> memo;
    long long n_num;
    long long k_num;
    void Resize(long long n, long long k);
};

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<long> vll;
// code
// ------------------------------------------------
int main() {

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

  ll once = 1900 * m + 100 * ( n - m );

  ll p = pow(2,m);

  cout << p * once << endl;

  return 0;
}
// funcの実体
// ------------------------------------------------
int getDigit(int n)
{
  int i = 1;
  while(1)
  {
    n = n / 10;
    if(n == 1)
      break;
    i++;
  }
  return i;
}
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Combi::Combi(){
  n_num = -1;
  k_num = -1;
};
ll Combi::Combination(ll n, ll k)
{
  Resize(n,k);

  ll ret;
  if(memo[n][k] != 0)
  {
    ret = memo[n][k];
  }
  else if(n == k || k == 0)
  {
    memo[n][k] = 1;
    ret = 1;
  }
  else
  {
    ret = Combination(n - 1, k - 1) + Combination(n - 1, k);
    memo[n][k] = ret;
  }
  return ret;
}

void Combi::Resize(ll n, ll k)
{
  if(n_num <= n || k_num <= k)
  {
    n_num = (n + 1) * 2;
    k_num = (k + 1) * 2;
    memo.resize(n_num);
    for(auto itr = memo.begin(); itr != memo.end(); ++itr)
    {
      itr->resize(k_num);
    }
  }
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
int N;
cin>>N;
int max=0,min=1000;
for(int i=0;i<N;i++){
    int a;
    cin>>a;
    if(a>max)
        max=a;
    if(a<min)
        min=a;
}
cout<<max-min<<endl;
}

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

using namespace std;

#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define ws(x) cerr << #x << " is " << x << endl
#define pb push_back
#define ats(x) cout << x << "\n"
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef pair <int, int> pii;
typedef vector<pii> vii;
typedef tuple<int, int, int> tiii;

const int INF = INT_MAX;


int main()
{
    FAST_IO;
    int n;
    cin >> n;
    string s;
    string ans = "";
    cin >> s;
    if (n < s.size()){
        for (int i = 0; i < n; i++){
            ans += s[i];
        }
        ans += "...";
        ats(ans);
    } else {
        ats(s);
    }
    return 0;
}



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

int main()
{
    bool overflow = false;
    int N;
    long double a;
    long double test_out = 1;

    cin >> N;
    for (int i = 0; i < N; i++){
        cin >> a;
        if (a == 0) {
            cout << 0;
            return 0;
        }
        else if (test_out * a > (long long)1000000000000000000){
            overflow = true;
        }else {
            test_out = test_out * a;
        }        
    }

    if (overflow) {
        cout << -1;
    }else{
        cout << (long long)test_out;
    }
    
    return 0;

}


Measured memory_bytes: 3732
fn main() {
	let mut s = String::new();
	use std::io::Read;
	std::io::stdin().read_to_string(&mut s).unwrap();
	let mut s = s.split_whitespace();
	let n: usize = s.next().unwrap().parse().unwrap();
	let k: usize = s.next().unwrap().parse().unwrap();
	let mut range = vec![];
	for _ in 0..k {
		let l: i32 = s.next().unwrap().parse().unwrap();
		let r: i32 = s.next().unwrap().parse().unwrap();
		range.push((l, r));
	}
	let mut dp = vec![0; n + 1];
	dp[1] = 1;
	const MOD: i64 = 998244353;
	let mut st = SegmentTree::construct(dp, 0i64, |a, b| (a + b) % MOD);
	for i in 2..=n {
		for &(il, ir) in range.iter() {
			let l = std::cmp::max(0, i as i32 - ir);
			let r = std::cmp::max(0, i as i32 - il + 1);
			let v = st.fold(l as usize, r as usize);
			let x = st.get(i).unwrap().clone();
			st.set(i, (v + x) % MOD);
		}
	}
	println!("{}", st.get(n).unwrap());
}

pub struct SegmentTree<T, F> {
	n: usize,
	data: Vec<T>,
	e: T,
	op: F,
}

impl<T, F> SegmentTree<T, F>
where
	T: Clone,
	F: Fn(T, T) -> T,
{
	pub fn new(n: usize, e: T, op: F) -> Self {
		Self {
			n: n,
			data: vec![e.clone(); n << 1],
			e: e,
			op: op,
		}
	}

	pub fn construct(src: Vec<T>, e: T, op: F) -> Self {
		let mut data = vec![e.clone(); src.len()];
		data.extend(src);
		for i in (1..data.len() / 2).rev() {
			data[i] = op(data[i << 1].clone(), data[i << 1 | 1].clone());
		}
		Self {
			n: data.len() / 2,
			data,
			e,
			op,
		}
	}

	pub fn fold(&self, l: usize, r: usize) -> T {
		let mut s = self.e.clone();
		let mut t = self.e.clone();
		let mut l = l + self.n;
		let mut r = r + self.n;
		while l < r {
			if l & 1 != 0 {
				s = (self.op)(s, self.data[l].clone());
				l += 1;
			}
			if r & 1 != 0 {
				t = (self.op)(self.data[r - 1].clone(), t);
			}
			l >>= 1;
			r >>= 1;
		}
		(self.op)(s, t)
	}

	pub fn set(&mut self, i: usize, v: T) {
		let mut i = i + self.n;
		self.data[i] = v;
		while {
			i >>= 1;
			i > 0
		} {
			self.data[i] = (self.op)(self.data[i << 1].clone(), self.data[i << 1 | 1].clone());
		}
	}

	pub fn get(&self, i: usize) -> Option<&T> {
		self.data.get(self.n + i)
	}

	pub fn len(&self) -> usize {
		self.n
	}
}


Measured memory_bytes: 5056
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
const int INF = 100000000;
using namespace std;
//2629198627

int solve(string s, int left, int right, bool sp){
    int cnt = 0;

    range(i,1,s.size()){
        //cout << left <<  ' ' << right << endl;
        //cout << sp <<  ' ' << s[i] << endl;
        if(sp){
            if(s[i] % 3 <= right){
                left = s[i] % 3;
                sp = 0;
            }else{
                right = s[i] % 3;
                cnt++;
            }
        }else{
            if(left <= s[i] % 3){
                right= s[i] % 3;
                sp = 1;
            }else{
                left= s[i] % 3;
                cnt++;
            }
        }
        //debug(cnt)
    }
    return cnt;
}

int main(){
    string s;
    while(cin >> s, s[0] != '#'){
        rep(i,s.size()) s[i] -= 1;
        cout << min(solve(s, (s[0] - '0') % 3, 1, 0), solve(s, 1, (s[0] - '0') % 3, 1)) << endl;
    }
}

Measured memory_bytes: 3252
import java.util.Scanner;
import java.util.ArrayList;
class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int num = sc.nextInt();
        
        ArrayList<Integer> list = new ArrayList<Integer>();
        for (int i = 1;i <= num; i++){
            if (num%i == 0) {
                
                list.add(i);
            }
        }

        ArrayList<Integer> listB = new ArrayList<Integer>();
        for (int j = 0;j < list.size(); j++){
            if (a <= list.get(j) && list.get(j)<= b) {
                listB.add(j);
            }
        }
        // listBの要素数が答えになる
        
        System.out.println(listB.size());
    }
}


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

#define lld long long
#define pp pair<int,int>
#define pb push_back
#define MOD 1000000007
#define left lleft
#define right rright
#define INF 2000000000
#define Linf 1000000000000000000LL
#define next nnext
#define minus mminus

using namespace std;

int N,M,Q,ans;
int sum1[100010],sum2[100010];
char s1[100010],s2[100010];

int change(pp x){
	if(x.first == x.second) return 0;
	if(x == pp(0,1) || x == pp(2,0) || x == pp(1,2)) return 1;
	return 2;
}

int main(){
	scanf("%s %s",s1,s2);
	N = strlen(s1); M = strlen(s2);
	for(int i=1; i<=N; i++){
		sum1[i] = sum1[i-1];
		if(s1[i-1] == 'A') sum1[i]++;
	}
	for(int i=1; i<=M; i++){
		sum2[i] = sum2[i-1];
		if(s2[i-1] == 'A') sum2[i]++;
	}
	scanf("%d",&Q);
	for(int i=1; i<=Q; i++){
		int s1,e1,s2,e2;
		scanf("%d %d %d %d",&s1,&e1,&s2,&e2);
		int cnta1,cntb1,cnta2,cntb2;
		cnta1 = sum1[e1]-sum1[s1-1];
		cntb1 = (e1-s1+1)-cnta1;
		cnta2 = sum2[e2]-sum2[s2-1];
		cntb2 = (e2-s2+1)-cnta2;
		cnta1 %= 3; cntb1 %= 3; cnta2 %= 3; cntb2 %= 3;
		int cnt1,cnt2;
		cnt1 = change({cnta1,cntb1});
		cnt2 = change({cnta2,cntb2});
		if(cnt1 == cnt2) ans = 1;
		else ans = 0;
		if(ans == 1) puts("YES");
		else puts("NO");
	}
	return 0;
}


Measured memory_bytes: 1536
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
using ll=long long;
#define rep(i,a,b) for(ll i=a;i<ll(b);i++)
#define repr(i,a,b) for(ll i=a;i>=ll(b);i--)
#define endl "\n"
#define ALL(x) x.begin(),x.end()
#define ALLR(x) x.rbegin(),x.rend()
#define INF 1e9
#define DEBUG(x) cout<<"debug: "<<x<<endl
using namespace std;

ll n, ans;
int main() {
	cin >> n;
	vector<ll> a(n);
	rep(i,0,n) cin>>a[i];
	
	ll maxA = a[0];
	rep(i,1,n){
		maxA = max(maxA,a[i]);
		ans += maxA-a[i];
	}
	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4464
#include <stdio.h>
#include <stdlib.h>

int fib(int);

int main(){
  int n;
  int fn;

  scanf("%d", &n);

  fn = fib(n);

  printf("%d\n", fn);
  
  return 0;
}

int fib(int n){
  int *F;
  int i;

  F = malloc(sizeof(int)*n + 1);

  F[0] = 1;
  F[1] = 1;

  for(i = 2; i < n; i++) F[i] = F[i - 2] + F[i - 1];

  if(n == 0 || n == 1) return F[n];

  else return F[i - 2] + F[i - 1];
}



Measured memory_bytes: 2112
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(int i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define print(x) (cout << (x) << endl)
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
#define fs first
#define sc second
// 多倍長
#include <boost/rational.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using boost::rational;
using boost::multiprecision::cpp_int;

const int INF = 1e9;
const ll LLINF = 1e16;
const ll MOD = 1e9+7;
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
 
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 

// 指定した文字cが文字列に何文字入ってるか
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}


// 割り算の切り上げ処理
template<typename T>
T rp(T a, T b) {
  return (a + b - 1) / b;
}

// 桁和
template<typename T>
T digsum(T n) {
    T res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

// 回文判定
bool kai (string s) {
    string t{s};
    reverse(begin(t), end(t));
    return s == t;
}

using pint = pair<int, int>;
using pll = pair<ll, ll>;


vector<string> split(const string &s, char delim) {
    vector<string> elems;
    string item;
    for (char ch: s) {
        if (ch == delim) {
            if (!item.empty())
                elems.push_back(item);
            item.clear();
        }
        else {
            item += ch;
        }
    }
    if (!item.empty())
        elems.push_back(item);
    return elems;
}


int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    ll x;
    cin >> x;
    REP(i, -1000, 1001){
        REP(j, -1000, 1001){
            ll a = i;
            ll b = j;
            if(a * a * a * a * a - b * b * b * b * b == x){
                print(i);
                print(j);
                return 0;
            }
        }
    }

}


Measured memory_bytes: 3580
N = int(input())
S = input()

r = S.count('R')
g = S.count('G')
b = S.count('B')


counter = 0
for i in range(N):
    for j in range(i+1, N):
        k = 2 *j - i
        if k >= N:
            break
        elif S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
            counter += 1

print(r * g * b - counter)
        

Measured memory_bytes: 9200
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    string S;
    cin >> S;
    int cnt = 0;
    int n = S.size();
    for(int i = 0; i < n/2; i++){
        if(S[i] != S[n-i-1]) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
hidari=-10**100
migi=10**100
keep=1
for i in range(m):
  l,r=map(int,input().split())
  if l>migi or r<hidari:
    keep=0
    break
  elif hidari<=l<=r<=migi:
    hidari=l
    migi=r
  elif l<=hidari<=migi<=r:
    pass
  elif l<=hidari<=r<=migi:
    migi=r
  elif hidari<=l<=migi<=r:
    hidari=l

if keep==1:
  res=migi-hidari+1       
  print(min(res,n))
else:
  print(0)
    


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

int main() {
  int N, A, B;
  string S;
  cin >> N >> A >> B >> S;
  int cnt = 0;
  int acnt = 0;
  for (char c : S) {
    if (c == 'a') {
      if (cnt < A + B) {
        cout << "Yes" << endl;
        cnt ++;
      }
      else {
        cout << "No" << endl;
      }
    }
    if (c == 'b') {
      acnt++;
      if (cnt < A + B) {
        if (acnt <= B) {
          cout << "Yes" << endl;
          cnt++;
        }
        else {
          cout << "No" << endl;
        }
      }
      else {
        cout << "No" << endl;
      }
    }
    if (c == 'c') {
      cout << "No" << endl;
    }
  }
}
      

Measured memory_bytes: 896
//#define NDEBUG
#include <cstddef>
#include <cstdint>
#include <vector>

namespace n91 {

	using i8 = std::int_least8_t;
	using i32 = std::int_least32_t;
	using i64 = std::int_least64_t;
	using u8 = std::uint_least8_t;
	using u32 = std::uint_least32_t;
	using u64 = std::uint_least64_t;
	using isize = std::ptrdiff_t;
	using usize = std::size_t;

	class rep {
		const usize f, l;

	public:
		class itr {
			friend rep;
			usize i;
			constexpr itr(const usize x) noexcept : i(x) {}

		public:
			void operator++() noexcept { ++i; }
			constexpr usize operator*() const noexcept { return i; }
			constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
		};
		constexpr rep(const usize first, const usize last) noexcept
			: f(first), l(last) {}
		constexpr itr begin() const noexcept { return itr(f); }
		constexpr itr end() const noexcept { return itr(l); }
	};
	class revrep {
		const usize f, l;

	public:
		class itr {
			friend revrep;
			usize i;
			constexpr itr(usize x) noexcept : i(x) {}

		public:
			void operator++() noexcept { --i; }
			constexpr usize operator*() const noexcept { return i; }
			constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
		};
		constexpr revrep(usize first, usize last) noexcept : f(--first), l(--last) {}
		constexpr itr begin() const noexcept { return itr(l); }
		constexpr itr end() const noexcept { return itr(f); }
	};
	template <class T> using vec_alias = std::vector<T>;
	template <class T> auto md_vec(const usize n, const T &value) {
		return std::vector<T>(n, value);
	}
	template <class... Args> auto md_vec(const usize n, Args... args) {
		return std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
	}
	template <class T> constexpr T difference(const T &a, const T &b) {
		return a < b ? b - a : a - b;
	}

} // namespace n91

#include <algorithm>
#include <iostream>
#include <utility>
#include <numeric>
#include<string>

namespace n91 {

	void main_() {
		std::string s;
		std::cin >> s;
		usize cnt = 0, ans = 0;
		for (const auto c : s) {
			if (c == 'A' || c == 'C' || c == 'G' || c == 'T') {
				++cnt;
			}
			else {
				cnt = 0;
			}
			ans = std::max(ans, cnt);
		}
		std::cout << ans;
	}

} // namespace n91

int main() {
	n91::main_();
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
using namespace std;
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2){
        if (num % i == 0) return false;
    }
    return true;
}

int main(void){
    int n,count=0,a=0;
    cin >> n;
    
    for(int i=1;i<=n;i++){
        count = 0;
        if(IsPrime(i)) continue;
        for(int j=1;j<=i;j++){
            if(i%j==0) count++;
        }
        if(count==8 && i%2!=0) a++;
    }
    cout << a;
    
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  char str[3];
  int i;
  scanf("%s",str);
  for(i = 0;i < 3;i++){
    if(str[i] == '7'){
      printf("Yes");
      break;
    }
  }
  if(i == 3){
    printf("No");
  }
  return 0;
}


Measured memory_bytes: 1728
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>

using namespace std;

typedef long long ll;
const ll nmax = 1e9 + 7;
const ll mod = 998244353;
const double PI = 2 * asin(1);

int main(){

  int X; cin >> X;

  for (int i = X; i < 1e7; i++){
    bool flag = true;
    for (int j = 2; j * j <= i; j++){
      if (i % j == 0){
        flag = false;
        break;
      }
    }
    if (flag == true){
      cout << i << endl;
      return 0;
    }
    
  }
  

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define rep11(i, n) for (int i = 1; i < (int)(n); ++i)
#define repo(i, o, n) for (int i = o; i < (int)(n); ++i)
#define repm(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1002000007
#define INF LONG_LONG_MAX
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b==c){
        cout<<"No"<<endl;
    }
    else if(a==c && a!=b){
        cout<<"Yes"<<endl;
    }
    else if(b==c && a!=c){
        cout<<"Yes"<<endl;
    }
    else if (a==b && a!=c){
    cout<<"Yes"<<endl;
    }
    else{
    cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using ll = long long;
int main() {
  ll N,K;
  cin >> N >> K;
  vector<ll> A(N);
  rep(i,N){
    cin >> A.at(i);
  }
  rep(i,N-K){
    if(A.at(i) < A.at(K + i)){
      cout << "Yes" << endl;
    }
    else{
      cout << "No" << endl;
    }
  }
  return 0;
}

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

using namespace std;

const int maxn=1e5+5;

struct sword
{
    int a,b;
} s[maxn];
bool cmp(sword x,sword y)
{
    return x.b<y.b;
}
int n,h;
int ans=0;
int main()
{

    cin>>n>>h;
    for(int i=1;i<=n;i++)
    {
        cin>>s[i].a>>s[i].b;
    }
    sort(s+1,s+n+1,cmp);
    int maxa=0;
    for(int i=1;i<=n;i++)
       maxa=max(maxa,s[i].a);
    int sum=0;
    for(int i=n;i>=1;i--)
    {
        if(s[i].b>maxa)
        {
            sum+=s[i].b;
            ans++;
            if(sum>=h)
            {
                cout<<ans<<endl;
                return 0;
            }
        }
    }
    h-=sum;
    if(!(h%maxa))
        cout<<ans+h/maxa<<endl;
    else
        cout<<ans+h/maxa+1<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstdint>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <utility>
#include <limits>
#include <list>
#include <type_traits>

/* template start */
 
#define rep(i, a, b) for (long long i = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()

#ifdef LOCAL
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  if(sizeof...(t)>0)std::cout<<" :";
  debug_out(t...);
}
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}

template<typename Num>
constexpr Num mypow(Num a, long long b) {
  if(b==0)return 1;
  if (a==0)return 0;
  Num x = 1;
  while (b > 0) {
    if(b & 1)x*=a;
    a*=a;
    b >>= 1;
  }
  return x;
}

/* template end */

using ll=std::int_fast64_t;
using u64=std::uint_fast64_t;

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

  ll n;
  std::cin>>n;

  std::vector<ll> a(n);
  for(auto&& e:a)std::cin>>e;

  std::sort(all(a));

  std::vector<ll> sum(n);

  std::inclusive_scan(all(a),sum.begin());

  for(ll i=n-2;i>=0;i--){
    if(sum[i]*2<a[i+1]){
      std::cout<<n-1-i<<"\n";
      return 0;
    }
  }

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

Measured memory_bytes: 4756
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <iostream>

#define ll long long
using namespace std;

ll x,k,d;

int main (){
    scanf("%lld %lld %lld",&x,&k,&d);
    if(x < 0){
	ll nowmove = (-x)/d;
	if(nowmove > k){
	    printf("%lld",abs(x + k*d));
	}
	else{
	    ll ans1 = x + nowmove * d;
	    if((k-nowmove)%2 == 1) ans1 = ans1 + d;
	    ans1 = abs(ans1);
	    printf("%lld",ans1);
	}
    }
    else{
	ll nowmove = x/d;
	if(nowmove > k){
	    printf("%lld",x - d*k);
	}
	else{
	    ll ans2 = x - nowmove * d;
	    if((k - nowmove )%2 == 1) ans2 = ans2 - d;
	    ans2 = abs(ans2);
	    printf("%lld",ans2);
	}
    }
    return 0;
}


Measured memory_bytes: 3824
def read():
    return raw_input()


def write(message):
    import sys
    print message
    sys.stdout.flush()


if __name__ == '__main__':
    a, b = map(int, read().split())
    n = b - a
    h_b = (n * (n + 1)) / 2
    write(h_b - b)


Measured memory_bytes: 2568
N, M = map(int, input().split())
Bridge= [[int(i) for i in input().split()] for _ in range(M)]
Parent = [int(i) for i in range(N)]
Rank = [1] * N
 
def find(x):
    if x == Parent[x]: return x
    else:
        Parent[x] = y = find(Parent[x])
        return y
 
def unite(x, y, Total):
    rx, ry = find(x), find(y)
    if rx == ry: return Total
    else:
      Total -= Rank[rx] * Rank[ry]
      if rx > ry:
        Parent[rx] = ry
        Rank[ry] += Rank[rx]
      else:
        Parent[ry] = rx
        Rank[rx] += Rank[ry]
      return Total
 
Total = N * (N - 1) // 2
Ans = [str(Total)] * M
for i in reversed(range(1, M)):
    A, B = Bridge[i]
    A -= 1
    B -= 1
    Total = unite(A, B, Total)
    Ans[i - 1] = str(Total)
 
print('\n'.join(Ans))

Measured memory_bytes: 36312
#include <bits/stdc++.h>
using namespace std;
using namespace std;
using ll = long long;
using ld = long double;
using p = pair<int, int>;
using Graph = vector<vector<char>>;
#define rep(i,n)  for(int i = 0; i < n ; i++)
int dx[4]{ -1,0,1,0 };
int dy[4]{ 0,1,0,-1 };
int main()
{
	int N;
	string S;
	cin >> N >> S;
	// 1つめの条件を満たす個数がrgb
	vector<int> a(N);
	rep(i, N) {
		if (S[i] =='R')
		{
			a[i] = 0;
		}
		if (S[i] == 'G')
		{
			a[i] = 1;
		}
		if (S[i] == 'B')
		{
			a[i] = 2;
		}
	}
	// それぞれの個数を集計する
	vector<ll> cnt(3);
	rep(i, N) {
		cnt[a[i]]++;
	}
	ll ans = 1;
	rep(i, 3) {
		ans *= cnt[i]; // rgbを求めている
	}
	rep(j, N)rep(i, j) {
		int k = j + (j - i);
		if (k < N)
		{
			if (a[i] == a[j]) { continue; }
			if (a[j] == a[k]) { continue; }
			if (a[k] == a[i]) { continue; }
          		ans--;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3612
class Main
{
    public static void main(String args[])
    {
        try{
            java.util.Scanner s1=new java.util.Scanner(System.in);
            String n=s1.next();
            if(n.length()>=4)
            {
                String s=n.substring(0,4);
                if(s.equals("YAKI"))
                    System.out.println("Yes");
                else
                    System.out.println("No");
            }
            else
                    System.out.println("No");
        }
        catch(Exception e)
        {
            
        }
    }
}

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

int main(){
  int n;
  cin >> n;
  ll a[n];
  rep(i,n) cin >> a[i];
  ll ans = 0;
  ll p = 0, q = 0;
  ll c = 0, d = 0;
  rep(i,n) {
    if(i % 2) {
      if(p + a[i] < 0) p += a[i];
      else {
        c += p + a[i] + 1;
        p = -1;
      }
    } else {
      if(p + a[i] > 0) p += a[i];
      else {
        c += 1 - (p + a[i]);
        p = 1;
      }
    }
  }
  rep(i,n) {
    if(i % 2 == 0) {
      if(q + a[i] < 0) q += a[i];
      else {
        d += q + a[i] + 1;
        q = -1;
      }
    } else {
      if(q + a[i] > 0) q += a[i];
      else {
        d += 1 - (q + a[i]);
        q = 1;
      }
    }
  }
  cout << min(c,d) << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
    int n, x, y;
    cin >> n >> x >> y;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    if (n == 1)
    {
        cout << abs(y - a[0]);
    }
    else
    {
       cout << max(abs(y - a.back()), abs(a[n - 2] - a.back()));
    }
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long n;
  cin >> n;
  long long a[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  long long dp[n+1];
  dp[0]=0;
  dp[1]=abs(a[0]-a[1]);
  for(int i=2;i<n;i++){
    dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]), dp[i-2]+abs(a[i]-a[i-2]));
  }
  cout << dp[n-1] << endl;
  return 0;
}

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
typedef pair<int,int> P;

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

const int INF=1e9;
int dx[]={0,-1,0,1};
int dy[]={-1,0,1,0};
int h,w;
int bt[35][35]; // right=8,down=4,left=2,up=1

int bfs(int sy,int sx,int gy,int gx)
{
    int d[35][35];
    REP(i,h) REP(j,w) d[i][j]=INF;
    queue<P> que;
    d[sy][sx]=1;
    que.push(P(sy,sx));

    while(!que.empty()){
	int y=que.front().first;
	int x=que.front().second;
	que.pop();
	if(y==gy && x==gx) break;
	REP(i,4){
	    if(bt[y][x]>>i&1) continue;
	    int ny=y+dy[i],nx=x+dx[i];
	    if(0<=ny && ny<h && 0<=nx && nx<w && d[ny][nx]==INF){
		d[ny][nx]=d[y][x]+1;
		que.push(P(ny,nx));
	    }
	}
    }
    return (d[gy][gx]==INF?0:d[gy][gx]);
}

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

    while(cin>>w>>h,w)
    {
	REP(i,h) REP(j,w) bt[i][j]=0;
	REP(i,2*h-1){
	    if(i%2==0){
		REP(j,w-1){
		    int t; cin>>t;
		    if(!t) continue;
		    bt[i/2][j]|=8;
		    bt[i/2][j+1]|=2;
		}
	    }else{
		REP(j,w){
		    int t; cin>>t;
		    if(!t) continue;
		    bt[i/2][j]|=4;
		    bt[i/2+1][j]|=1;
		}
	    }
	}
	cout<<bfs(0,0,h-1,w-1)<<endl;
    }
}



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

using namespace std;

int main() {
    unsigned int n;
    cin >> n;

    vector<int> vt(n);
    for (int i = 0; i < n; ++i) {
        cin >> vt[i];
    }
    sort(vt.begin(), vt.end());

    cout << vt[n / 2] - vt[n / 2 - 1] << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;
/*
signed main(){  
  int a, b ,c, d;
  cin >> a >> b >> c >> d;
  cout << max(a*b, c*d) << endl;
}
*/

signed main(){
  int n;
  cin>>n;
  string s;
  cin>>s;
  int a=0,b=0;
  r(i,n){
    if(s[i]=='I')b++;
    else b--;
    a=max(a,b);
  }
  cout<<a<<endl;
}


Measured memory_bytes: 256
A, B, C = map(int, input().split())
if (3 * max(A, B, C) - (A + B + C)) % 2 == 0:
    print((3 * max(A, B, C) - (A + B + C)) // 2)
else:
    print((3 * max(A, B, C) - (A + B + C)) // 2 + 2)


Measured memory_bytes: 2940
#include<stdio.h>
int main(){
  long long n,d[100010],a,ans=0,i;
  scanf("%lld",&n);
  for(i=0;i<n;i++)scanf("%lld",&d[i]);
  a=2;
  for(i=1;i<n;i++){
    if(d[i]>a)ans+=(d[i]-1)/a;//printf("%d\n",ans);
    if(d[i]==a)a++;//printf("%d %d %d\n",d[i],ans,a);
  }
  printf("%lld\n",ans+d[0]-1);
  return 0;
}
  


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

typedef long long int ll;
typedef double d;

#define tt int t; cin>>t; while(t--)
#define lo(i, a, b) for(int i=a; i<b; i++)
#define rlo(i, a) for(int i=a; i>0; i--)

#define be(a) a.begin(),a.end()
#define sz(x) x.size()

#define nl cout<<"\n";
#define sp cout<<" ";

#define su ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

int main()
{
    su;
    int n,k,a,s=0;
    cin>>n>>k;
    while(k--)
    {
        cin>>a;
        s+=a;
    }
    if(s>=n)
        cout<<"Yes";
    else
        cout<<"No";
    nl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#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;}

using pi = pair<int,int>;
const int N = 100000;

vector<int> G[N];

// ??°??£????????????????????????/??????
pi dp1[N];
void dfs(int v, int par)
{
    int res = 0;
    for(int nx:G[v])if(nx!=par)
    {
        dfs(nx,v);
        res += dp1[nx].fi+2;
    }

    int notback = res;
    for(int nx:G[v])if(nx!=par)
    {
        int t = res;
        t -= dp1[nx].fi+2;
        t += dp1[nx].se+1;
        notback = min(notback,t);
    }

    dp1[v] = {res,notback};
}

int ans[N];
void dfs2(int v, int par, pi d)
{

    // v????????¨???????????????????????¨????????¨?????¨????????±?????????
    vector<pair<pi,int>> c;
    // ???????????????
    for(int nx:G[v])if(nx!=par) c.pb({dp1[nx],nx});
    // ?????????
    c.pb({d,-1});

    int C = c.size();
    // ??¨??¨?????¨?????¨???????????????????????£?????°??£?????????????????¨???????????´???????????????
    int sum = 0;
    rep(i,C) sum += c[i].fi.fi+2;

    // second????????¶?????¨????????£?????????????????????(?°?????????????????¬???????)
    // (??????,??????)
    vector<pi> gain;

    // ??????v??????????????????????¨??????????
    ans[v] = sum;
    // ????????¨?????¨???"??°?????????"??????????????¨??¢?´¢
    rep(i,C)
    {
        // "??°??£?????????"??????"??°?????????"???????????????????????¨????????£????????????????????????
        int g = c[i].fi.se+1 - (c[i].fi.fi+2);

        ans[v] = min(ans[v],sum+g);
        gain.pb({g,c[i].se});
    }

    // ??????????????¨?????¨????????± d ?????´??°????????????????????????????????????
    sort(all(gain));
    rep(i,C)
    {
        int nx = gain[i].se;
        if(nx==-1) continue;

        pi nd;
        // "??°??£?????????"???????????????????????¨?????¨?????¶??????????????°??????
        nd.fi = sum - (dp1[nx].fi+2);

        // "??°?????????"???????????????????????¨?????¨??????????????????????????????????????§???????????§??´?????\?±????????????????
        // ??????????????????????????¨?????¨???"??°?????????"??????????????§????????????????????§?¬??????§????????¨?????????"??°?????????"??????????????????
        // ????????§???????????°??????????????¨?????¨???"??°?????????"???????????°??????
        nd.se = nd.fi;
        if(i==0)
        {
            if(C>1) nd.se += gain[1].fi;
        }
        else nd.se += gain[0].fi;

        dfs2(nx,v,nd);
    }
}

int main()
{
    int n;
    scanf(" %d", &n);
    rep(i,n-1)
    {
        int u,v;
        scanf(" %d %d", &u, &v);
        --u;
        --v;
        G[u].pb(v);
        G[v].pb(u);
    }

    dfs(0,-1);
    dfs2(0,-1,{-2,-1});
    rep(i,n) printf("%d\n", ans[i]);
    return 0;
}

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

#define F first
#define S second
#define pb push_back
#define ll long long
#define all(v) (v).begin(),(v).end()
#define endl '\n'

using namespace std;

const int N = 100005;
const int MOD = 1e9 + 7;
const int INF = 2000000000;
const ll INFLL = 1LL * INF * INF;

int main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    string s;
    cin >> s;
    int n = s.size();
    for (int i = 0; i < n; i++) {
        if (i + 1 < n && s[i] == s[i + 1]) {
            cout << i + 1 << " " << i + 2 << endl;
            return 0;
        }
        if (i + 2 < n && s[i] == s[i + 2]) {
            cout << i + 1 << " " << i + 3 << endl;
            return 0;
        }
    }
    cout << "-1 -1" << endl;
    return 0;
}


Measured memory_bytes: 512