akhauriyash/Code-Regression huggingface dataset:
import copy

N, K = map(int, input().split())
A = list(map(int, input().split()))

mod = 10**9 + 7

Am, Ap = [], []
pm = [0, 0]
B = []

def ans(A):
  ans = 1
  for x in A:
    ans *= x
    ans %= mod
  return ans

if N == K:
  print(ans(A))
  exit()

for x in A:
  if x < 0:
    Am.append(-x)
    B.append((-x, 1))
    pm[0] += 1
  else:
    Ap.append(x)
    B.append((x, 0))
    pm[1] += 1

Am.sort()

if pm[0] == N:
  if K%2 == 0:
    print(ans(Am[N-K:]))
  else:
    print((-1 * ans(Am[:K]))%mod)
  exit()

P = []
B.sort(reverse = True)

cnt = 0

p_min = (-1, -1)
m_min = (-1, -1)

for i in range(K):
  P.append(B[i][0])
  cnt ^= B[i][1]
  if B[i][1] == 0:
    p_min = (B[i][0], i)
  else:
    m_min = (B[i][0], i)

if cnt == 0:
  print(ans(P))
  exit()

P1 = copy.deepcopy(P)
P2 = copy.deepcopy(P)

p_max = (-1, -1)
m_max = (-1, -1)

for i in range(K, N):
  if B[i][1] == 0:
    p_max = (B[i][0], i)
    break

for i in range(K, N):
  if B[i][1] == 1:
    m_max = (B[i][0], i)
    break

Flag1 = False
Flag2 = False

if p_min[1] != -1 and m_max[1] != -1:
  Flag1 = True
  P1[p_min[1]] = 1
  P1.append(m_max[0])
  ans1 = ans(P1)

if m_min[1] != -1 and p_max[1] != -1:
  Flag2 = True
  P2[m_min[1]] = 1
  P2.append(p_max[0])
  ans2 = ans(P2)

if Flag1 and Flag2:
  if m_min[0]*m_max[0] > p_min[0]*p_max[0]:
    print(ans1)
  else:
    print(ans2)
elif Flag1:
  print(ans1)
else:
  print(ans2)

Measured memory_bytes: 51060
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;
typedef pair<double, int> Pdi;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);

class BIT
{
public:
    vector<int> bit;
    int M;

    BIT(int M):
        bit(vector<int>(M+1, 0)), M(M) {}

    int sum(int i) {
        if (!i) return 0;
        return bit[i] + sum(i-(i&-i));
    }

    void add(int i, int x) {
        if (i > M) return;
        bit[i] += x;
        add(i+(i&-i), x);
    }
};

double calcans(int N, vector<double> &A, vector<double> &B, vector<double> &C){
    //傾き順にソート
    vector<Pdi> p(N);
    REP(i, N) p[i] = Pdi(-1.0 * A[i] / B[i], i);
    SORT(p);
    vector<int> invp(N);
    //傾きの順位(1~N)
    REP(i, N) invp[p[i].second] = i + 1;

    int N_tot = N * (N - 1) / 2;

    double x1 = -1.0e10, x2 = 1.0e10;
    while(x2 - x1 > max(1.0e-12, min(abs(x1), abs(x2)) * 1.0e-12)){
        double x = (x1 + x2) / 2.0;
        vector<Pdi> y(N);
        //y(x)でソート
        REP(i, N) y[i] = Pdi(-1.0 * A[i] / B[i] * x + C[i] / B[i], i);
        SORT(y);
        int count = 0;
        BIT b(N);
        REP(i, N){
            int i0 = y[i].second;
            count += b.sum(invp[i0]);
            b.add(invp[i0], 1);
        }
        if(count >= (N_tot + 1) / 2) x2 = x;
        else x1 = x;
    }
    return x2;
}

signed main(){

    int N; cin >> N;
    vector<double> A(N), B(N), C(N);
    REP(i, N) cin >> A[i] >> B[i] >> C[i];
    cout << setprecision(15) << calcans(N, A, B, C) << " " << calcans(N, B, A, C);
    
    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

Measured memory_bytes: 3104
//??????????????????
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N;
	cin>>N;
	vector<int> A(N);
	for(int i=0; i<N; ++i){
		cin>>A[i];
	}
	
	for(int i=1;i<N;++i){
		for(int k=0; k<N-1;++k){
			cout<<A[k]<<" ";
		}
		cout<<A[N-1]<<endl;
		int v=A[i];//???????????????????????£?????????
		int j=i-1;
		while(j>=0 && A[j]>v){//i?????????????????????????????????????????¨??????????????????????????????
			A[j+1]=A[j];
			j--;
		}
		A[j+1]=v;
	}

	for(int i=0; i<N-1;++i){
		cout<<A[i]<<" ";
	}
	cout<<A[N-1]<<endl;
}

Measured memory_bytes: 3104
namespace Coder {
  class Scanner {
    private buffer: string = '';
    private stdinQueue: any = [];

    constructor() {
      process.stdin.resume();
      process.stdin.setEncoding('utf8');
      process.stdin.on(
        'data',
        (chunk): void => {
          this.buffer += chunk;
          while (this.stdinQueue.length > 0) {
            const i = this.buffer.indexOf('\n');
            if (i < 0) {
              break;
            }
            let line = this.buffer.substr(0, i);
            if (line.endsWith('\r')) {
              line = line.slice(0, -1);
            }
            this.buffer = this.buffer.substr(i + 1);
            this.stdinQueue.shift()(line);
          }
        },
      );
    }
    public getLine(): Promise<string> {
      return new Promise((resolve, reject) => {
        const i = this.buffer.indexOf('\n');
        if (i >= 0 && this.stdinQueue.length === 0) {
          let line = this.buffer.substr(0, i);
          if (line.endsWith('\r')) {
            line = line.slice(0, -1);
          }
          this.buffer = this.buffer.substr(i + 1);
          resolve(line);
        } else {
          this.stdinQueue.push(resolve);
        }
      });
    }

    public close(): void {
      process.stdin.pause();
    }
  }

  async function solve() {
    const sc = new Scanner();
    const N: number = +(await sc.getLine());
    const H: number[] = (await sc.getLine()).split(' ').map((x) => +x);
    let max = H[0];
    let ans = 1;
    for (let i = 1; i < N; i += 1) {
      if (H[i] >= max) {
        ans += 1;
      }
      max = Math.max(max, H[i]);
    }
    console.log(ans);
    sc.close();
  }

  solve();
}


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

using namespace std;

#define Rep(i,N) for(int i = 0;i < N;i++)

int main(){

  int N;

  vector<int> data(5005,0);

  vector<int> temp(5005,0);

  cin >> N;

    Rep(i,N)cin >> data[i];

    temp = data;

    int sum = INT_MAX;

    Rep(p,data[0] + 1){

      int ans = 0;

      data[0] -= p;

      ans += p;

      Rep(i,N - 1){

        ans += data[i] * 2;

        data[i + 1] -= data[i];

        data[i] = 0;

        if(data[i + 1] < 0)data[i + 1] = 0;

      }

      ans += data[N - 1];

      sum = min(ans,sum);

      data = temp;

    }

    cout << sum << endl;


  return 0;

}

Measured memory_bytes: 3156
#include <stdio.h>

int		main()
{
	double	A, B, K;
	int		r;

	A = 0;
	B = 0;
	K = 0;
	r = scanf("%lf %lf %lf\n", &A, &B, &K);
	if (r == -1)
		return (0);
	A = A - K;
	if (A < 0)
	{
		B += A;
		A = 0;
	}
	if (B < 0)
		B = 0;
	printf("%.0f %.0f\n", A, B);
	return (0);
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)) {

			int n = sc.nextInt();
			String s = sc.next();
			
			int result = 1;
			
			char current = s.charAt(0);
			
			for(int i = 1 ; i < n ; i++ ) {
				if ( current != s.charAt(i)) {
					result++;
					current = s.charAt(i);
				}
			}
			
			
			System.out.println(result);
			
		}
	}
}



Measured memory_bytes: 25488
#[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!(a: chars, b: chars);
    puts!("{}\n", if a == &b[..a.len()] { "Yes" } else { "No" });
}

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: 2252
import java.util.*;

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

        Scanner sc = new Scanner(System.in);
        
        String O = sc.next();
        String E = sc.next();
        int Olen = O.length();
        int Elen = E.length();
        
        for(int i = 0; i < Elen; i++){
            System.out.print(O.charAt(i));
            System.out.print(E.charAt(i));
        }
        if(Olen> Elen) System.out.print(O.charAt(Olen -1 ));
    }
}
 

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

vector<int> prime;

// n以下の素数を列挙
void enum_prime(int n) {
  vector<bool> is_prime(n+1, true);
  is_prime[0] = false;
  is_prime[1] = false;
  for (int i = 2; i <= n; ++i) {
    if (is_prime[i] == false) continue;
    prime.push_back(i);
    for (int j = 2 * i; j <= n; j += i) {
      is_prime[j] = false;
    }
  }
  return;
}

int main() {
  ll n, p;
  cin >> n >> p;
  if (n == 1) {
    cout << p << endl;
    return 0;
  }
  
  enum_prime((int)1e6);

  map<int, int> factor;
  int pi = 0;
  while (pi < prime.size()) {
    if (p % prime[pi] != 0) {
      ++pi;
      continue;
    }
    p /= prime[pi];
    ++factor[prime[pi]];
  }

  ll g = 1;
  for (auto itr = factor.begin(); itr != factor.end(); ++itr) {
    rep(i, itr->second / n) g *= itr->first; 
  }

  cout << g << endl;

  return 0;
}

Measured memory_bytes: 4008
import std.stdio, std.string, std.conv, std.array, std.range, std.algorithm;

void main() {
    long n, m;
    readf("%d %d\n", &n, &m);
    auto xs = new long[](n+1);

    foreach (_; 0..m) {
        long l, r;
        readf("%d %d\n", &l, &r);
        xs[l-1] += 1;
        xs[r] -= 1;
    }

    auto ans = 0;
    auto cur = 0;
    foreach (x; xs) {
        cur += x;
        if (cur == m) {
            ans++;
        }
    }
    writeln(ans);
}


Measured memory_bytes: 3068
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <cmath>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define ENDL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
/* libraries */

signed main() {
	std::string s;
	std::cin >> s;
	int y=std::stoi(s.substr(0,4));
	int m=std::stoi(s.substr(5,2));
	int d=std::stoi(s.substr(8,2));
	if(y<2019) print("Heisei");
	else if(y==2019) {
		if(m<4) print("Heisei");
		else if(m==4) {
			if(d<=30) print("Heisei");
			else print("TBD");
		} else print("TBD");
	} else print("TBD");
	return 0;
}


Measured memory_bytes: 256
a, b = [ int(v) for v in input().split() ]

if b == 1:
    print(0)
elif a >= b:
    print(1)
else:
    t = 1
    b -= a
    for i in range(100):
        t += 1
        b -= (a-1)
        if b <= 0:
            print(t)
            break 


Measured memory_bytes: 38256
#pragma once

#include <bits/stdc++.h>

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;

#define rep(a,n) for(int a = 0;a < n;a++)
#define repi(a,b,n) for(int a = b;a < n;a++)

const ull mod = 1000000007;

ll gcd(ll a, ll b) { while (b) a %= b, swap(a, b); return abs(a); }

ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main(void)
{
	int a,b;
	cin >> a >> b;
	cout << lcm(a,b) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(a) int((a).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
template<class T, class U> inline void add_self(T &a, U b){a += b;if (a >= mod) a -= mod;if (a < 0) a += mod;}
template<class T, class U> inline void min_self(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void max_self(T &x, U y) { if (y > x) x = y; }

#define _deb(x) cout<<x;
void _print() {cerr << "]\n";} template <typename T, typename... V>void _print(T t, V... v) {_deb(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
template <class T, class U> void print_m(const map<T,U> &m, int w=3){if(m.empty()){cout<<"Empty"<<endl; return;}for(auto x: m)cout<<"("<<x.first<<": "<<x.second<<"),"<<endl;cout<<endl;}
template<class T, class U>void debp(const pair<T, U> &pr, bool end_line=1){cout<<"{"<<pr.first<<" "<<pr.second<<"}"; cout<<(end_line ? "\n" : ", ");}
template <class T> void print_vp(const T &vp, int sep_line=0){if(vp.empty()){cout<<"Empty"<<endl; return;}if(!sep_line) cout<<"{ ";for(auto x: vp) debp(x,sep_line);if(!sep_line) cout<<"}\n";cout<<endl;}
template <typename T>void print(const T &v, bool show_index = false){int w = 2;if(show_index){for(int i=0; i<sz(v); i++)cout<<setw(w)<<i<<" ";cout<<endl;}for(auto &el: v) cout<<setw(w)<<el<<" ";cout<<endl;}
template <typename T>void print_vv(const T &vv){if(sz(vv)==0) {cout<<"Empty"<<endl; return;} int w = 3;cout<<setw(w)<<" ";for(int j=0; j<sz(*vv.begin()); j++)cout<<setw(w)<<j<<" ";cout<<endl;int i = 0;for(auto &v: vv){cout<<i++<<" {";for(auto &el: v) cout<<setw(w)<<el<<" ";cout<<"},\n";}cout<<endl;}

int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    while(cin>>n){
        string s; cin>>s;
        int cnt = 0;
        int l = 0, r = n-1;
        while(l<r){
            while(l<r && s[l]!='W') ++l;
            while(r>l && s[r]!='R') --r;
            if(l<r && s[l]=='W' && s[r]=='R'){
                swap(s[l], s[r]);
                ++cnt;
            }
        }
        // print(s);
        cout<<cnt<<"\n";
    }
    return 0;
}

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

int main() {
	int n, a, b; cin >> n >> a >> b;
	
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		int tmp = i;
		int sum_tmp = 0;
		for (int j = 0; j < 5; j++)sum_tmp += tmp % 10, tmp /= 10;
		if (a <= sum_tmp && sum_tmp <= b)ans += i;
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	// Code for A - RGB Cards
	var r, g, b int
	fmt.Scanf("%d %d %d", &r, &g, &b)

	ans := 100*r + 10*g + b
	if ans%4 == 0 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


Measured memory_bytes: 1836
N,A,B=map(int,input().split())
S=input()

Pass=0
count=0
for s in S:
    if s=='a' and Pass<A+B:
        Pass+=1
        print('Yes')
    elif s=='b':
        count+=1
        if Pass<A+B and count<B+1:
            Pass+=1
            print('Yes')
        else:
            print('No')
    else:
        print('No')

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

N, M, X = map(int, input().split())
A = list(map(int, input().split()))

L = []
for i in range(1, N):
    if i in A:
        L.append(True)
    else:
        L.append(False)

index = X - 1

ans1 = L[:index].count(True)
ans2 = L[index+1:].count(True)

if ans1 < ans2:
    print(ans1)
else:
    print(ans2)



Measured memory_bytes: 9092
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long int ll;
#define pb push_back
typedef pair<ll,ll> pp;

ll mod = 1e9+7;
ll INF = 1e15;

ll powm(ll a , ll b , ll mod)
{
  ll res = 1;
  while(b)
  {
    if(b & 1)
    res = (res *a)%mod;
    a = (a*a)%mod;
    b>>1;
  }
  return res;
}
ll gcd(ll a , ll b);
ll power(ll x , ll y , ll m);

ll modInverse(ll a , ll m)
{
  ll g = gcd(a,m);
  if(g != 1)
  return 1;
  else
  return power(a,m-2,m);

}

ll power(ll x , ll y , ll m)
{
  if(y == 0)
  return 1;
  ll p = power(x , y/2 , m)%m;
  p = (p*p)%m;

  return (y%2 == 0) ? p : (x *p) % m;
}

ll gcd(ll a , ll b)
{
  if(a == 0)
  return b;
  return gcd(b%a , a);
}





void solve()
{
  string s;
  cin>>s;
  if(s == "ARC")
  cout<<"ABC\n";
  else cout<<"ARC\n";


}



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


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

  

  
                                            


Measured memory_bytes: 3064
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0 for _ in range(n+1)]
        self.size = [1 for _ in range(n+1)]

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def get_size(self, x):
        x = self.find(x)
        return self.size[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)


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

ab = []
for i in range(m):
    ab.append([int(i) for i in input().split()])

ab.reverse()
uf = UnionFind(n)
ans = n * (n-1) // 2
anss= [ans]
for i in range(m-1):
    a,b = ab[i]
    if not uf.same(a,b):
        ans -= uf.get_size(a) * uf.get_size(b)
        uf.union(a,b)
    anss.append(ans)
anss.reverse()
for i in range(m):
    print(anss[i])

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

int main(){
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        if (i == n - 1) {
            cout << a[n - 1 - i];
        } else {
             cout << a[n - 1 - i] << " ";
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3084
import numpy as np

N, Q = map(int, input().split())
S = "0" + input()
q = list()
for _ in range(Q):
    l, r = map(int, input().split())
    q.append((l, r))

cnt = [0] * (N + 1)
for i in range(1, N + 1):
    if S[i] == "C":
        if S[i - 1] == "A":
            cnt[i] = 1

cumsum = np.cumsum(cnt)
for l, r in q:
    print(cumsum[r] - cumsum[l])


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

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef pair<int, int> pi;
typedef long long ll;
typedef unsigned long long ull;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MKP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

int A,B;


int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
cin >> A >> B;
if (A <= 8 && B <= 8) {
cout << "Yay!" << endl;
}
else {
cout << ":(" << endl;
}
return 0;
	
}


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


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

void solve() {
    ll X; cin >> X;
    ll uresi = 0;

    ll a = X/500;

    uresi += a * 1000;
    ll b = (X-(a*500))/5;

    uresi += b * 5;

    cout << uresi << "\n";
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

Measured memory_bytes: 256
from sys import stdin
f_i = stdin

mod = 10 ** 9 + 7

N = int(f_i.readline())

C = map(int, f_i.readline().split())
C = sorted(C)

x = (C_i * i % mod for i, C_i in zip(range(N + 1, 1, -1), C))

ans = pow(4, N - 1, mod) * sum(x) % mod

print(ans)

Measured memory_bytes: 25744
n = int(input())
H = list(map(int, input().split()))

c = 0
max_c = 0
for i in range(n - 1):
   if H[i] >= H[i+1]:
      c += 1
   else:
      c = 0
   if c > max_c:
      max_c = c

print(max_c)

Measured memory_bytes: 20448
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  int h,w,p;
  cin>>h>>w;
  char a[h][w];
  rep(i,h){
    rep(j,w){
      cin>>a[i][j];
    }
  }
  int co[h],co2[w];
  rep(i,h){
    co[i]=0;
  }
  rep(i,w){
    co2[i]=0;
  }
   rep(i,h){
    rep(j,w){
      if(a[i][j]=='#'){
        break;
      }else{
        co[i]++;
      }
    }
   }
   rep(j,w){
    rep(i,h){
      if(a[i][j]=='#'){
        break;
      }else{
        co2[j]++;
      }
    }
   }
  p=0;
  rep(i,h){
    rep(j,w){
      if(co[i]!=w&&co2[j]!=h){
        cout<<a[i][j];
      }
      if(co[i]!=w){
        p=1;
      }
    }
    if(p==1){
      cout<<endl;
      p=0;
    }
  }     
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int main(){
	int a,b,c,d,sum=0;
	cin>>a>>b>>c>>d;
	if(d>a&&d>0) {
		d-=a;
		sum+=a;
	}
	else if(d<=a&&d>0) {
		sum+=d;
		d=0;
	}
	if(d>b&&d>0) {
		d-=b;
	}
	else if(d<=c&&d>0) {
		d=0;
	}
	if(d>c&&d>0) {
		d-=c;
		sum-=c;
	}
	else if(d<=c&&d>0) {
		sum-=d;
		d=0;
	}
	cout<<sum<<endl;
	return 0;
} 

Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <stack>
#include <math.h>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <vector>

using namespace std;






int main()
{
	for (int i = 1; i <= 9; i++) {
		for (int j = 1; j <= 9; j++) {
			cout << i << 'x' << j << '=' << i*j << endl;
		}
	}
	return 0;
	
}

Measured memory_bytes: 1112
def main():
    N = int(input())
    W = list(map(int, input().split()))
    diff = float('inf')
    for i in range(1, N):
        S1 = sum(W[:i])
        S2 = sum(W[i:])
        if diff > abs(S2 - S1):
            diff = abs(S2 - S1)
    print(diff)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <set>
 
using namespace std;
 
int main() {
	string n;
	cin >> n;
    int sum =0;
    for(int i=0; i<n.size(); i++){
        int num = n[i]-'0';
        sum += num;
    }
    if(sum%9==0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
	return 0;
}

Measured memory_bytes: 3748
n = gets.to_i
a = gets.split(" ").map(&:to_i)
b = gets.split(" ").map(&:to_i)
c = gets.split(" ").map(&:to_i)
ans = b[a[0]-1]
1.upto(n-1) do |i|
  ans += b[a[i]-1]
  ans += c[a[i]-2] if a[i] == a[i-1] + 1
end
puts ans

Measured memory_bytes: 1788
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef pair<int,int> P;
int N,M,H,K;
int S[1000];
P ab[100000];
bool F[1000][1000];
int now[1000];
int point[1000];
int ans;
int main()
{
	while(true){
	scanf("%d%d%d%d",&N,&M,&H,&K);
	if(N==0)return 0;
	for(int i=0;i<N;i++)now[i]=i;
	for(int i=0;i<N;i++)scanf("%d",&S[i]);
	for(int i=0;i<M;i++){
		int A,B;
		scanf("%d%d",&A,&B);
		A--;
		ab[i].first=B;ab[i].second=A;
	}
	sort(ab,ab+M);
	for(int i=0;i<M;i++){
		F[now[ab[i].second]][now[ab[i].second+1]]=true;
		swap(now[ab[i].second],now[ab[i].second+1]);
	}
	for(int i=0;i<N;i++){
		point[now[i]]=S[i];
	}
	int cou=0;
	for(int i=0;i<K;i++)cou+=point[i];
	ans=cou;
	for(int i=0;i<N;i++){
		for(int j=i+1;j<N;j++){
			if(F[i][j]){
				if(j<K)continue;
				if(i>=K)continue;
				int cou1=cou;
				cou1+=point[j];cou1-=point[i];
				ans=min(ans,cou1);
			}
		}
	}
	printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 2956
#include <stdio.h>
 
int main()
{
  char S[40];
  scanf("%s", S);
 
  switch (S[0])
  {
    case 'S':
      printf("Cloudy\n");
      break;
    case 'C':
      printf("Rainy\n");
      break;
    case 'R':
      printf("Sunny\n");
      break;
  }
  return 0;  
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1LL << 60;
const int MOD = (int) 1e9 + 7;

signed main() {
    vector<int> v(3);
    cin >> v[0] >> v[1] >> v[2];
    sort(v.begin(), v.end());
    int cnt = 0;
    cnt += v[2] - v[1];
    v[0] += v[2] - v[1];
    v[1] = v[2];
    if ((v[1] - v[0]) % 2 == 0) {
        cnt += (v[1] - v[0]) / 2;
    }
    else {
        cnt += (v[1] - v[0]) / 2 + 2;
    }
    cout << cnt << "\n";
}

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

#define rep(i,n) for(int i=0; i<n; i++)
int main(){
	char s[21];
	int n;
	scanf("%s", s);
	rep(i, 21) if(s[i]=='\0') n=i-1;
	for(int i=n; i>=0; i--) cout << s[i];
	cout << endl;
    return 0;
}

Measured memory_bytes: 1144
#include <stdio.h>

int main ()
{
	int a,b,c,d,e;
	scanf ("%d %d %d",&a,&b,&c);
	d=(a-b);
	e=c-d;
	
	if (e<0)
	{
		printf ("%d\n",e=0);
	}
	else
	{
		printf ("%d\n",e);
	}
	
	return 0;
}

Measured memory_bytes: 128
/*
 * Author: .-O_O-.
 */
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define rep0(a,b) for(int a=0;a<b;a++)
#define rep1(a,b) for(int a=1;a<=b;a++)
#define repp(a,b,c) for(int a=b;a<c;a++)
#define in insert
#define len length()
#define si size()
#define lb lower_bound
#define ub upper_bound
#define beg begin()
#define en end()
#define f first
#define s second
#define pr(a) cout<<a
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define nx cout<<"\n"
#define int long long
// 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 << "]"<<endl;}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
const ll mod = 1000000007;
const ll N = 100005;
const ll mm = 1e+18;
void solve()
{
    int k,s;
    cin>>k>>s;
    int ans=0;
    rep0(i,k+1){
        rep0(j,k+1){
            int x=s-i-j;
            if(x>=0&&x<=k) ans++;
        }
    }
    pr(ans);
}
signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
    //cin>>t;
    rep1(_i,t){
        //cout<<"Case #"<<_i<<": ";
        solve();
        //nx;
    }
    return 0;
}

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

int main(){
int N;  cin >> N;
string S; cin >> S;
int ans = 0;

for (int i = 0; i < N; i++) {
    int count = 0;
    for (char s = 'a'; s <= 'z'; s++) {
        bool left = false, right = false;
        for (int j = 0; j < i; j++) {
            if (S.at(j) == s) {
                left = true;
            }
        }
        for (int j = i; j < N; j++) {
            if (S.at(j) == s) {
                right = true;
            }
        }
        if (left == true && right == true) {
            count++;
        }
    }
    ans = max(ans, count);
}
cout << ans << endl;
}

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

using namespace std;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int k, x;
	scanf("%d %d", &k, &x);
	if (k*500 >= x) printf("%s", "Yes");
	else  printf("%s", "No");
	return 0;
}


Measured memory_bytes: 256
using System;
 
public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        Ans(n);
    }
    static void Ans(int n)
    {
        var ans = 0;
        for (int i = 0; i < n; i++){
            for (int j = 0; j < n; j++){
                for (int k = 0; k < n; k++){
                    ans += gcd(i + 1, j + 1, k + 1);
                }
            }
        }
        Console.WriteLine(ans);
    }
    static int gcd(int a, int b, int c) => gcd(a, gcd(b, c));
 
    static int gcd(int a, int b)
    {
        if (a < b) return gcd(b, a);
        while (b != 0)
        {
            var w = a % b;
            a = b;
            b = w;
        }
        return a;
    }
}

Measured memory_bytes: 17568
#include<iostream>
using namespace std;
//Dinic O(EV^2)
#include<algorithm>
#include<utility>
#include<vector>
#include<queue>
#include<limits>
template<typename T>
struct MF{
	struct edge{
		int to,rev;
		T cap;
	};
	vector<vector<edge> >G;
	vector<int>level,iter;
	MF(int n_=0):G(n_),level(n_),iter(n_){}
	void add_edge(int from,int to,T cap)
	{
		G[from].push_back({
			to,(int)G[to].size(),cap
		});
		G[to].push_back({
			from,(int)G[from].size()-1,0
		});
	}
	T dfs(int u,int t,T f)
	{
		if(u==t)return f;
		for(;iter[u]<G[u].size();iter[u]++)
		{
			edge&e=G[u][iter[u]];
			if(e.cap>0&&level[u]<level[e.to])
			{
				T d=dfs(e.to,t,min(f,e.cap));
				if(d>0)
				{
					e.cap-=d;
					G[e.to][e.rev].cap+=d;
					return d;
				}
			}
		}
		return 0;
	}
	T max_flow(int s,int t)
	{
		T ret=0;
		for(;;)
		{
			fill(level.begin(),level.end(),-1);
			queue<int>P;
			level[s]=0;
			P.push(s);
			while(!P.empty())
			{
				int u=P.front();P.pop();
				for(edge&e:G[u])
				{
					if(e.cap>0&&level[e.to]<0)
					{
						level[e.to]=level[u]+1;
						P.push(e.to);
					}
				}
			}
			if(level[t]<0)return ret;
			fill(iter.begin(),iter.end(),0);
			for(T f;(f=dfs(s,t,numeric_limits<T>::max()))>0;)ret+=f;
		}
	}
};
main()
{
	int N,E;
	cin>>N>>E;
	MF<int>mf(N);
	for(int i=0;i<E;i++)
	{
		int u,v,c;cin>>u>>v>>c;
		mf.add_edge(u,v,c);
	}
	cout<<mf.max_flow(0,N-1)<<endl;
}


Measured memory_bytes: 3200
import fractions

A,B,C,D=map(int,input().split())


kobaisu=C//fractions.gcd(C,D)*D


ans=B -(B//C+B//D-B//kobaisu)

ans2=(A-1)-((A-1)//C +(A-1)//D - (A-1)//kobaisu)

print(int(ans-ans2))

Measured memory_bytes: 5472
#include <bits/stdc++.h>
using namespace std;
#define rep(i, seisu) for(int i = 0; i < (int)(seisu); i++)
typedef long long ll;
///vector<pair<string, int>>;

int main(){
  string s, t;
  cin >> s >> t;
  int check = 0, same = 0;
  int ls = s.length(), lt = t.length();
  rep(i, ls){
    rep(j, lt){
      int ns = s[i] - '0', nt = t[j] - '0';
      if(ns < nt) {
        check = 1;
        break;
      }
    }
    if(t.find(s[i])!= string::npos) same++;
    if(check) break;
  }
  if (ls < lt && same == ls) check = 1;
  if(check) cout << "Yes" << endl;
  else cout << "No" << endl;
}


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

int main(){
  vector<int> C(3);
  cin >> C[0] >> C[1] >> C[2];
  int sum = 0;
  int max_cost = 0;
  for(auto& c : C){
    sum += c;
    max_cost = max(max_cost, c);
  }
  cout << sum - max_cost << endl;
  return 0;
}


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

int main()
{
    int n;
    string s;
    
    cin >> s;
    
    n = s.size();
    
    int a = 0, z = n-1;
    
    while(s[a] != 'A') {
        a++;
    }
    
    while(s[z] != 'Z') {
        z--;
    }
    
    cout << z-a+1 << "\n";
    
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstring>
#include <cassert>
#include <unordered_map>
using namespace std;
#define rep(i,a,n) for (int i=a;i<(int)(n);i++)
#define per(i,a,n) for (int i=(n)-1;i>=(int)(a);i--)
template<typename T> ostream& operator<<(ostream& s, vector<T> t) {rep(i, 0, t.size()) s << (i ? " " : "") << t[i]; return s;}
template<typename T> istream& operator>>(istream& s, vector<T> &t) {rep(i, 0, t.size()) s >> t[i]; return s;}
template<typename T, typename U> ostream& operator<<(ostream& s, pair<T, U> t) {s << "(" << t.first << "," << t.second << ")"; return s;}
template<typename T, typename U> istream& operator>>(istream& s, pair<T, U> &t) {s >> t.first >> t.second; return s;}
typedef long long ll;


int main() {
    ios_base::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<ll> a(n);
    cin>>a;
    unordered_map<ll,int> occ;
    for (auto x : a) {
        occ[x]++;
    }
    vector<ll> pairs;
    for (auto &x : occ) {
        if(x.second >= 2) {
            pairs.push_back(x.first);
        }
        if(x.second >= 4) {
            pairs.push_back(x.first);
        }
    }
    sort(pairs.begin(), pairs.end());
    if (pairs.size() < 2) {
        cout << 0 << endl;
        return 0;
    }
    reverse(pairs.begin(), pairs.end());
    cout << (pairs[0] * pairs[1]) << endl;
}


Measured memory_bytes: 5156
import sys
from heapq import heappush, heappop, heapreplace

def solve():
    file_input = sys.stdin
    N, R, L = map(int, file_input.readline().split())
    
    pq = [[0, i] for i in range(1, N + 1)]
    m = dict(zip(range(1, N + 1), pq))
    time = [0] * (N + 1)
    INVALID = -1
    
    pre_t = 0
    for line in file_input:
        d, t, x = map(int, line.split())
        top_team = pq[0]
        time[top_team[1]] += t - pre_t
        pre_t = t
        
        if top_team[1] == d:
            top_team[0] -= x
            if x < 0:
                heapreplace(pq, top_team)
        else:
            scored_team = m[d][:]
            scored_team[0] -= x
            heappush(pq, scored_team)
            m[d][1] = INVALID
            m[d] = scored_team
        
        while pq[0][1] == INVALID:
            heappop(pq)
    time[pq[0][1]] += L - pre_t
    print(time.index(max(time)))

solve()


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

typedef long long ll;

int n;
int a[200002];
ll sum[200002];

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		sum[i] = sum[i-1]+a[i];
	}
	ll ans = 1e18;
	int l = 1, r = 3;
	for (int i = 2; i <= n-2; i++) {
		while (abs(sum[i]-sum[l]-sum[l]) > abs(sum[i]-sum[l+1]-sum[l+1])) {
			l++;
		}
		while (abs(sum[n]-sum[r]-(sum[r]-sum[i])) > abs(sum[n]-sum[r+1]-(sum[r+1]-sum[i]))) {
			r++;
		}
		ans = min(ans, max({ sum[i]-sum[l],sum[l],sum[n]-sum[r],sum[r]-sum[i] })-min({ sum[i]-sum[l],sum[l],sum[n]-sum[r],sum[r]-sum[i] }));
	}
	
	printf("%lld\n", ans);
	
	return 0;
}

Measured memory_bytes: 2560
n=int(input())
s=input()
S=list(s)
S.sort()
count=0
if n==1:
    if S[0]=='B':
        print('No')
    else:
        print('Yes')
else:
    for i in range(n-1):
        if S[i]!=S[i+1]:
            count=i+1
            break
        if i==n-2:
            count=n-1
    if count>=(n+1)//2:
        print('No')
    else:
        print('Yes')

Measured memory_bytes: 3064
n=int(input())
a=list(map(int, input().split()))

def f(presum, x, fugo):
  if (presum+x)*fugo<=0:
    sa=fugo-presum-x
    prosum=fugo
  else:
    sa=0
    prosum=presum+x
  return sa, prosum

out1=0
y=0
for i in range(n):
  x, y=f(y, a[i], (-1)**i)
  out1+=abs(x)
  
out2=0
y=0
for i in range(n):
  x, y=f(y, a[i], -(-1)**i)
  out2+=abs(x)
  
print(min(out1, out2))

Measured memory_bytes: 14468
N, T = map(int,input().split())
ct = [list(map(int, input().split())) for i in range(N)]
clst=[]
for i in range(N):
    if ct[i][1] <= T:
        clst.append(ct[i][0])
if len(clst) == 0:
    ans = 'TLE'
else:
    ans = min(clst)
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <cmath>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

template<typename Type> class RangeMin {
private:
	int size_;
	std::vector<Type> dat;
public:
	RangeMin() : size_(0), dat(std::vector<Type>()) {};
	RangeMin(int size__) {
		for (size_ = 1; size_ < size__; ) size_ <<= 1;
		dat.resize(size_ << 1, std::numeric_limits<Type>::max());
	}
	template<class T>
	RangeMin(T begin_, T end_) {
		int n = end_ - begin_;
		for (size_ = 1; size_ < n; size_ <<= 1); dat.resize(size_ << 1, std::numeric_limits<Type>::max());
		for (int i = 0; i < n; i++) dat[i + size_] = *(begin_ + i);
		for (int i = size_ - 1; i > 0; i--) dat[i] = std::min(dat[i << 1], dat[(i << 1) + 1]);
	}
	inline unsigned size() { return size_; }
	inline void update(int i, Type x) {
		i += size_; dat[i] = x;
		while (i > 1) {
			i >>= 1;
			dat[i] = std::min(dat[i << 1], dat[i << 1 | 1]);
		}
	}
	inline Type query(int l, int r) {
		Type ret = std::numeric_limits<Type>::max();
		l += size_; r += size_;
		while (l != r) {
			if (l & 1) ret = std::min(ret, dat[l++]); l >>= 1;
			if (r & 1) ret = std::min(ret, dat[--r]); r >>= 1;
		}
		return ret;
	}
};

int N, M, dp[100009];
string S;
RangeMin<int> V;
vector<int> E[100009];

int main() {
	cin >> N >> M >> S;
	V = RangeMin<int>(N + 2);
	for (int i = 0; i < N; i++) dp[i] = (1 << 30);
	for (int i = 0; i <= N; i++) V.update(i, dp[i]);

	for (int i = N - 1; i >= 0; i--) {
		if (S[i] == '1') continue;
		int r = V.query(i + 1, min(N + 1, i + M + 1));
		dp[i] = min(dp[i], r + 1);
		V.update(i, dp[i]);
	}
	for (int i = 0; i <= N; i++) {
		if (dp[i] < (1 << 30)) E[dp[i]].push_back(i);
	}
	if (dp[0] == (1 << 30)) {
		cout << "-1" << endl;
		return 0;
	}

	int cx = 0; vector<int> vec;
	for (int i = dp[0] - 1; i >= 0; i--) {
		int pos1 = lower_bound(E[i].begin(), E[i].end(), cx) - E[i].begin();
		vec.push_back(E[i][pos1] - cx);
		cx = E[i][pos1];
	}

	for (int i = 0; i < vec.size(); i++) {
		if (i) cout << " "; cout << vec[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 7932
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let k: u64 = sc.read();
    let a: u64 = sc.read();
    let b: u64 = sc.read();

    if b >= a + 2 && k > a - 1 {
        let diff = b - a;
        let change = (k - (a - 1)) / 2;
        let rest = k - (a - 1) - change * 2;
        println!("{}", change * diff + a + rest);
    } else {
        println!("{}", k + 1);
    }
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352
import sys

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

res = 1
n = ni()
a = nl()
a.sort()
for x in a:
    res *= x
    if res > 10**18:
        print(-1)
        exit()
print(res)


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  // set<int> s;
  // rep(i,n) s.insert(a[i]);
  // if (s.size() == n) cout << "YES" << endl;
  // else cout << "NO" << endl;
  sort(a.begin(), a.end());
  a.erase(unique(a.begin(), a.end()), a.end());
  if (a.size() == n) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ii pair<int,int>
#define mp make_pair
#define int long long int
using namespace std;

int32_t main(){
	int n,c=0;
	cin>>n;
	vector<int> a(n),b(n);
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<n;i++)cin>>b[i];
	
	set<ii> data;
	for(int i=0;i<n;i++){
		data.insert(mp(b[i],i));
	}
	while(!data.empty()){
		int j=data.rbegin()->second;
		data.erase(--data.end());
		int q=b[(j+1)%n]+b[(j-1+n)%n];
		if((b[j]-a[j])%q==0){
			c+=(b[j]-a[j])/q;
			b[j]=a[j];
		}
		else{
			if(b[j]<q){cout<<-1;return 0;}
			c+=b[j]/q;
			b[j]%=q;
			if(b[j]<a[j]){cout<<-1;return 0;}
			data.insert(mp(b[j],j));
		}
	}
	cout<<c;
}


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

int main() {
  int N;
  cin >> N;
  
  vector<int> bottun(N);
  bool flag = true;
  for (int i = 0; i < N; i++) {
    cin >> bottun.at(i);
  }
  
  int count = 0;
  int next = 1;
  vector<int> history(1, 1);
  
  while (flag) {
    count++;
    next = bottun.at(next - 1);
    if (next == 2) {
      break;
    }
    if (count > N) {
      flag = false;
      break;
    }
    history.push_back(next);
  }
  if (flag) cout << count << endl;
  else cout << -1 << endl;
}


Measured memory_bytes: 1276
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cassert>
#include <cmath>
#include <sstream>
#include <stack>
//#include <unordered_map>
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<unsigned, unsigned> uu;
typedef pair<ll, ll> l4;


#define pb push_back
#define mp make_pair

const int maxn = 1e2+1;
const int maxm = maxn*maxn;

int h, w, n;
int a[maxm];
int ans[maxn][maxn];

int x = 0, y = 0, d = 1;
inline void paint(const int c)
{
  ans[x][y] = c;
  y += d;
  if (y < 0)
    {
      y = 0;
      x += 1;
      d *= -1;
    }
  else if (y == w)
    {
      y = w-1;
      x += 1;
      d *= -1;
    }
}
int main()
{
  scanf("%d %d %d", &h, &w, &n);
  for (int i = 1; i <= n; ++i)
    {
      int x;
      scanf("%d", &x);
      for (int j = 0; j < x; ++j)
	paint(i);
    }
  for (int i = 0; i < h; ++i)
    {
      for (int j = 0; j < w; ++j)
	{
	  if (j)
	    printf(" ");
	  printf("%d", ans[i][j]);
	}
      puts("");
    }
}


Measured memory_bytes: 384
#include <cstdio>
#include <algorithm>
using namespace std;
#define Nil -1

struct Tree
{
  int parent, left, right;
};

int setHeight(int id, int h[], Tree t[])
{
  int leftHeight = 0, rightHeight = 0;
  if (t[id].left != Nil)
    leftHeight = setHeight(t[id].left, h, t) + 1;
  if (t[id].right != Nil)
    rightHeight = setHeight(t[id].right, h, t) + 1;

  return h[id] = max(leftHeight, rightHeight);
}

void setDepth(int depth, int id, int d[], Tree t[])
{
  d[id] = depth;
  if (t[id].left != Nil)
    setDepth(depth + 1, t[id].left, d, t);
  if (t[id].right != Nil)
    setDepth(depth + 1, t[id].right, d, t);
}

void print(int id, Tree t[], int dep[], int height[])
{
  int p = t[id].parent;
  printf("node %d: ", id);
  printf("parent = %d, ", p);

  if (p == Nil || t[p].left == Nil || t[p].right == Nil)
    printf("sibling = -1, ");
  else if (t[p].left == id)
    printf("sibling = %d, ", t[p].right);
  else
    printf("sibling = %d, ", t[p].left);

  bool l = t[id].left != Nil;
  bool r = t[id].right != Nil;
  int degree = (l && r) ? 2 : ((l || r) ? 1 : 0);
  printf("degree = %d, ", degree);
  printf("depth = %d, ", dep[id]);
  printf("height = %d, ", height[id]);

  if (t[id].parent == Nil)
    printf("root\n");
  else if (t[id].left != Nil || t[id].right != Nil)
    printf("internal node\n");
  else
    printf("leaf\n");
}

int main()
{
  int n, dep[25], height[25];
  Tree trees[25];
  scanf("%d", &n);

  for (int i = 0; i < 25; i++)
  {
    trees[i].parent = trees[i].left = trees[i].right = Nil;
    dep[i] = 0;
    height[i] = 0;
  }

  for (int i = 0; i < n; i++)
  {
    int id, left, right;
    scanf("%d%d%d", &id, &left, &right);
    trees[id].left = left;
    trees[id].right = right;
    if (left != Nil)
      trees[left].parent = id;
    if (right != Nil)
      trees[right].parent = id;
  }

  int root;
  for (int i = 0; i < n; i++)
    if (trees[i].parent == -1)
      root = i;

  setHeight(root, height, trees);
  setDepth(0, root, dep, trees);

  for (int i = 0; i < n; i++)
    print(i, trees, dep, height);

  return 0;
}

Measured memory_bytes: 2728
N,x = map(int,input().split())
a = map(int,input().split())
ret = 0
for i,n in enumerate(sorted(a)):
  if i == N-1 and n == x:
    x -= n
    ret += 1
  elif i < N-1 and n <= x:
    x -= n
    ret += 1
  else:
    break
print(ret)

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
int main(){
    int n,d,x,i,j,ans;
    cin >> n >> d >> x;
    vector<int> a(n);
    for(i=0;i<n;i++) cin >> a.at(i);
    ans = x;
    for(i=0;i<n;i++){
        j=0;
        while(j*a.at(i)+1 < d+1){
            ans++; j++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>

int main()
{
  long long n;
  scanf("%lld", &n);
  long long nc = 0;
  long long min = 1e10;
  long long sum = 0;
  for (long long i = 0; i < n; ++i)
  {
    long long a;
    scanf("%lld", &a);
    if (a < 0)
    {
      ++nc;
      sum -= a;
      if (min > -a) min = -a;
    }
    else
    {
      sum += a;
      if (min > a) min = a;
    }
  }
  printf("%lld\n", sum - ((nc & 1) != 0 ? 2 * min : 0));
  return 0;
}

Measured memory_bytes: 128