akhauriyash/Code-Regression huggingface dataset:
N = int(input())
A = list(map(lambda x: int(x) - 1, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

s = 0
last_ai = None
for ai in A:
    s += B[ai]
    if last_ai is not None and ai - last_ai == 1:
        s += C[last_ai]
    last_ai = ai

print(s)

Measured memory_bytes: 3060
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        #[allow(unused_mut)]
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[derive(Debug)]
struct Load {
    pub weight: i64,
    pub value: i64,
}

fn main() {
    input! {
        n: i64,
        w: i64,
        _loads: [(i64, i64); n as usize]
    }
    let mut loads = vec![];
    for l in _loads {
        loads.push(Load {
            weight: l.0,
            value: l.1,
        })
    }
    // [k][y] -> value
    let mut max_values = vec![vec![0; (w + 1) as usize]; n as usize];
    for k in 0..=(n - 1) {
        for y in 1..=w {
            let using = access(&max_values, k - 1, y - loads[k as usize].weight)
                .map(|s| s + loads[k as usize].value)
                .unwrap_or(0);
            let not_using = access(&max_values, k - 1, y).unwrap_or(0);
            max_values[k as usize][y as usize] = i64::max(using, not_using);
        }
    }
    println!("{}", max_values[(n - 1) as usize][w as usize])
}

fn access(max_values: &Vec<Vec<i64>>, k: i64, y: i64) -> Option<i64> {
    if y < 0 {
        None
    } else if k < 0 {
        Some(0)
    } else {
        Some(max_values[k as usize][y as usize])
    }
}


Measured memory_bytes: 80196
#include <bits/stdc++.h>
using namespace std;
#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n)-1;i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(b)-1;i>=(a);--i)
#define ALL(a) a.begin(),a.end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
    if (a < b) { a = b; return true; }
    return false;
}
template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
    if (a > b) { a = b; return true; }
    return false;
}
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const map<T1, T2> &mp) {
    os << "{";
    int a = 0;
    for (auto &tp : mp) {
        if (a) os << ", "; a = 1;
        os << tp;
    }
    return os << "}";
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    os << p.first << ":" << p.second;
    return os;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
    const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};

    for (;;) {
        int T, N; cin >> T >> N;
        if (T == 0 and N == 0) break;

        int k = 0;
        for (int n = N; n > 0; n /= 10) ++k;
        int ma = 0;
        vvi cands;
        REP(s, 1<<k-1) {
            int prev = 0;
            vi pieces;
            REP(i, k-1) if (s >> i & 1) {
                pieces.push_back(stoi(to_string(N).substr(prev, i - prev + 1)));
                prev = i+1;
            }
            pieces.push_back(stoi(to_string(N).substr(prev, k)));
            int sum = accumulate(ALL(pieces), 0);
            if (sum > T) continue;
            if (chmax(ma, sum)) {
                cands.clear();
                cands.push_back(pieces);
            } else if (ma == sum) {
                cands.push_back(pieces);
            }
        }

        if (ma == 0) {
            cout << "error" << endl;
        } else if (cands.size() > 1) {
            cout << "rejected" << endl;
        } else {
            cout << ma;
            for (int a : cands[0]) {
                cout << " " << a;
            }
            cout << endl;
        }

    }

    return 0;

}



Measured memory_bytes: 3236
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;

int a[500005];
const int MAX = 100000;
const int MAX_VAL = 1000000;
 
int sqrtn;
 
// 쿼리 정렬을 위한 쿼리 struct
struct Query{
    int s, e, n; // n은 쿼리 번호
    Query() {}
    Query(int s1, int e1, int n1): s(s1), e(e1), n(n1){}
    bool operator <(const Query &O)const{
        if(s/sqrtn != O.s/sqrtn) return (s/sqrtn < O.s/sqrtn);
        return (e < O.e);
    }
};
 

int main()
{
	int n, q; cin >> n >> q;
	for(int i=0;i<n;i++) scanf("%d", &a[i]);
	int l, r;
	sqrtn = sqrt(n);
    vector<Query> Q(q, Query());
	vector<int> cnt(n + 1), ans(q);
	for(int i=0;i<q;i++) {
		scanf("%d %d", &l, &r);
        Q[i] = Query(l-1, r, i);
    }
    sort(Q.begin(), Q.end());

    int s = Q[0].s, e = Q[0].e;
	int dcnt = 0;
    for(int i = s; i < e; ++i)
        if(cnt[a[i]]++ == 0) ++dcnt;
    ans[Q[0].n] = dcnt;
 
    for(int i=1; i<q; i++){
        while(Q[i].s < s) if(cnt[a[--s]]++ == 0) ++dcnt;
        while(e < Q[i].e) if(cnt[a[e++]]++ == 0) ++dcnt;
        while(Q[i].s > s) if(--cnt[a[s++]] == 0) --dcnt;
        while(e > Q[i].e) if(--cnt[a[--e]] == 0) --dcnt;
        ans[Q[i].n] = dcnt;
    }
 
    for(int i = 0; i < q; i++)
        printf("%d\n", ans[i]);
}


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;


int main() {
    string S; cin >> S;
    reverse(ALL(S));
    int i = 0;
    int N = S.size();
    while(i<N){
        if(N-i >= 5){
            string s = S.substr(i,5);
            if(s=="maerd" || s=="esare"){
                i += 5;
                continue;
            }
        }
        if(N-i >= 6){
            string s = S.substr(i,6);
            if(s=="resare"){
                i += 6;
                continue;
            }
        }
        if(N-i >= 7){
            string s = S.substr(i,7);
            if(s=="remaerd"){
                i += 7;
                continue;
            }
        }
        cout << "NO" << endl;
        return 0;
    }
    cout << "YES" << endl;
    return 0;
}

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

int main(void){
	int N,L;
    string s;
    cin >> N >> L;
  	vector<string> v_s;
    while(getline(cin, s)){
    	v_s.push_back(s);
    }
	sort(v_s.begin(),v_s.end());
	s = "";
    for(auto& t_s : v_s){
      s += t_s;
    }
    cout << s;
}


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

int main(){
    int n;
    cin>>n;
    int a[n];
    fori(i,n) cin>>a[i];
    int bit=0;
    fori(i,n) bit|=a[i];
    cout<<__builtin_ctz(bit)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 123456789
//0x3f3f3f3f
#define INFL 10000000000000000
using namespace std;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
typedef pair<int,pii> pdii;
long long int MOD = 1000000007;


int main(void){
	string str;
	cin>>str;
	if(
		str=="AKIHABARA"||str=="AKIHABAR"||str=="AKIHABRA"||str=="AKIHABR"||
		str=="AKIHBARA"||str=="AKIHBAR"||str=="AKIHBRA"||str=="AKIHBR"||
		str=="KIHABARA"||str=="KIHABAR"||str=="KIHABRA"||str=="KIHABR"||
		str=="KIHBARA"||str=="KIHBAR"||str=="KIHBRA"||str=="KIHBR"
	){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}
	
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		int n, a, min, max;
		long sum;
		   
		n = scan.nextInt();

		a = scan.nextInt();
		sum = min = max = a;
		for(int i = 1; i < n; i++){
			a = scan.nextInt();

			if(a < min)
				min = a;
			else if(a > max)
				max = a;
			sum += a;
		}
		System.out.println(String.format("%d %d %d", min, max, sum));
	}
}



Measured memory_bytes: 41212
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
using namespace std;

#define INF (1ll<<60)

long long M = 1000000007;

vector<long long> inv,fact,invfact;

long long choose(long long n, long long k){
    if(k<0||k>n)return 0;
    long long res = fact[n];
    res *= invfact[k];
    res %= M;
    res *= invfact[n-k];
    res %= M;
    return res;
}

vector<pair<int, int>> ps;

long long nu(int i, int k){
    if(ps[i].first>ps[k].first || ps[i].second>ps[k].second) return 0;
    else return choose(ps[k].first + ps[k].second - ps[i].first - ps[i].second, ps[k].first - ps[i].first);
}

int main(int argc, char const *argv[]) {
    int h,w,N;cin>>h>>w>>N;
    int n=h+w;
    ps = vector<pair<int, int>>(0);
    inv = vector<long long>(n+1);
    fact = vector<long long>(n+1);
    invfact = vector<long long>(n+1);
    inv[1]=1;
    fact[0]=1;
    invfact[0]=1;
    for(long long i=2;i<=n;++i){
        inv[i] = M - inv[M%i]*(M/i);
        inv[i] %= M;
        inv[i] += M;
        inv[i] %= M;
    }
    for(long long i=1;i<=n;++i){
        fact[i] = (fact[i-1]*i)%M;
        invfact[i] = (invfact[i-1]*inv[i])%M;
    }
    n = N;
    for(int i=0;i<n;++i){
        int r,c;cin>>r>>c;
        r--;
        c--;
        ps.push_back(pair<int,int>(r,c));
    }
    sort(ps.begin(),ps.end());
    ps.push_back(pair<int, int>(h-1,w-1));
    vector<vector<long long>> dp(n+1,vector<long long>(n+1,0));
    vector<long long> dp2(n+1);
    for(int i=0;i<=n;++i)dp2[i] = choose(ps[i].first + ps[i].second, ps[i].first);
    for(int i=1;i<=n;++i){
        dp[i][0] = (choose(ps[0].first + ps[0].second, ps[0].first) * nu(0,i))%M;
        dp2[i] -= dp[i][0];
        dp2[i] %= M;
    }
    for(int k=1;k<n;++k){
        for(int i=k+1;i<=n;++i){
            dp[i][k] = (dp2[k] * nu(k,i))%M;
            dp2[i] -= dp[i][k];
            dp2[i] %= M;
        }
    }
    cout<<(dp2[n]+M)%M<<endl;
    return 0;
}

Measured memory_bytes: 75392
#[allow(unused_macros)]
macro_rules! input_byline {
    ($($r:tt)* ) => {
        let stdin = std::io::stdin();
        let mut q = std::collections::VecDeque::new();
        let mut next = || {
            if q.is_empty() {
                let mut s = String::new();
                stdin.read_line(&mut s);
                for v in s.split_whitespace() {
                    q.push_back(v.to_string());
                }
            }
            q.pop_front().unwrap()
        };
        input_inner!{next, $($r)*}
    };

}

#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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)*}
    };

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

#[allow(unused_macros)]
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, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

trait Printable {
    fn p(&self);
}

impl<T: std::fmt::Display> Printable for T {
    fn p(&self) {
        println!("{}", self);
    }
}

impl<T: std::fmt::Display> Printable for [T] {
    fn p(&self) {
        for i in 0..self.len() {
            if i != 0 {
                print!(" ");
            }
            print!("{}", self[i]);
        }
        println!("");
    }
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap};

#[allow(dead_code)]
type Graph = Vec<Vec<usize>>;

fn solve(h: usize, w: usize) -> usize {
    let mut r = h * w;
    for i in 1..h {
        let h2 = (h - i) / 2;
        let h3 = h - i - h2;
        let v = vec![w * i, w * h2, w * h3];
        r = min(r, v.iter().max().unwrap() - v.iter().min().unwrap());
        let w2 = w / 2;
        let w3 = w - w2;
        let v = vec![w * i, w2 * (h - i), w3 * (h - i)];
        r = min(r, v.iter().max().unwrap() - v.iter().min().unwrap());
    }
    r
}

fn main() {
    input! {
        h: usize, w: usize
    }

    println!("{}", min(solve(h, w), solve(w, h)));
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

ll n,a[3];
ll dp[41][1<<16];

const ll mask=((1<<16)-1);

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

int main(){
  cin>>n;
  rep(i,3)cin>>a[i];
  dp[0][0]=1;
  rep(i,n){
    rep(S,1<<16){
      if(dp[i][S]==0)continue;
      vector<ll> b;
      ll sum=1;
      rep(j,16){
        if((S>>j)&1){
          b.push_back(sum);
          sum=1;
        }else sum++;
      }

      repl(nxt,1,11){
        sum=nxt;
        ll k=2;
        rep(j,b.size()){
          if(sum==a[k]){
            sum=0;
            k--;
            if(k==-1)break;
          }else if(sum>a[k])break;
          sum+=b[j];
        }
        if(k!=-1&&sum==a[k]){
          sum=0; k--;
        }
        if(k!=-1)(dp[i+1][(S<<nxt|1<<(nxt-1))&mask]+=dp[i][S])%=mod;
      }
    }
  }
  ll res=0;
  rep(S,1<<16)(res+=dp[n][S])%=mod;
  cout<<(mod_pow(10,n)-res+mod)%mod<<endl;
  return 0;
}


Measured memory_bytes: 19456
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
#define DBG(X) cout << #X << "=" << (X) << '\n';
#define SAY(X) cout << (X) << '\n';
#else
#define DBG(X)
#define SAY(X)
#endif

#define M_PI       3.14159265358979323846

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

std::string pad(int num)
{
    char buffer[4];
    std::snprintf(buffer, sizeof(buffer), "%03d", num);
    return buffer;
}

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif

int solve()
{
    int n, k;
    cin >> n >> k;

    string hands;
    cin >> hands;

    vector<int> count;

    // always starts with "stand on feet"
    if (hands[0] == '1')
        count.push_back(0);

    for (int i = 0; i < n; ++i)
    {
        char c = hands[i];
        int counter = 1;

        while (i + 1 < n && hands[i + 1] == c)
        {
            ++counter;
            ++i;
        }

        count.push_back(counter);
    }

    // always end with "stand on hands"
    if (hands.back() != '1')
        count.push_back(0);

    int ans = 0;
    int sum = 0;
    int commands = 0;

    for (int i = 0; i < count.size(); i += 2)
    {
        sum += count[i] + count[i + 1];
        ++commands;

        if (commands > k)
        {
            sum -= count[i - k * 2];
            
            if (i - k * 2 - 1 >= 0)
                sum -= count[i - k * 2 - 1];
        }

        ans = std::max(ans, sum);
    }

    cout << ans << endl;

    return 0;
}

int main()
{
    solve();

    return 0;
}

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

using namespace std;

int main(){
    int n, m;
    cin >> n >> m;
    long h[n];
    long ans[n];
    long a[m];
    long b[m];
    long sum = 0;
    for (int i=0; i<n; i++){
        cin >> h[i];
        ans[i] = 0;
    }
    for (int i=0; i<m; i++){
        cin >> a[i] >> b[i];
        if (h[a[i]-1] < h[b[i]-1] && ans[a[i]-1]==0){
            ans[a[i]-1] += 1;
            sum += 1;
        }
        else if (h[a[i]-1] > h[b[i]-1] && ans[b[i]-1]==0){
            ans[b[i]-1] += 1;
            sum += 1;
        }
        else if (h[a[i]-1]==h[b[i]-1] && ans[a[i]-1]==0 && ans[b[i]-1]==0){
            ans[a[i]-1] += 1;
            ans[b[i]-1] += 1;
            sum += 2;
        }
        else if (h[a[i]-1]==h[b[i]-1] && ans[a[i]-1]==0 && ans[b[i]-1]!=0){
            ans[a[i]-1] += 1;
            sum += 1;
        }
        else if (h[a[i]-1]==h[b[i]-1] && ans[a[i]-1]!=0 && ans[b[i]-1]==0){
            ans[b[i]-1] += 1;
            sum += 1;
        }
    }

    cout << n-sum << endl;
}

Measured memory_bytes: 6744
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)

var (
	reader io.Reader = os.Stdin
	writer io.Writer = os.Stdout
)

func main() {
	reader = os.Stdin
	writer = os.Stdout
	run()
}

func run() {
	var result string
	nums := readIntsFromStdin()[0]
	a, b := nums[0], nums[1]

	switch {
	case a > b:
		result = "a > b"
	case a < b:
		result = "a < b"
	case a == b:
		result = "a == b"
	}

	fmt.Fprintln(writer, result)
}

// ReadInts parses lines of inputs into 2D int array.
func readIntsFromStdin() [][]int {
	out := [][]int{}
	scanner := bufio.NewScanner(reader)

	for scanner.Scan() {
		var ints []int

		for _, s := range strings.Split(scanner.Text(), " ") {
			i, err := strconv.Atoi(s)

			if err != nil {
				fmt.Fprintln(os.Stderr, "Failed to parse string into int.", err)
				os.Exit(1)
			}

			ints = append(ints, i)
		}

		out = append(out, ints)
	}

	return out
}



Measured memory_bytes: 1128
x = gets 
until x.nil?
 y = x.split(" ")
 year = y[0].to_i
 month = y[1].to_i
 day = y[2].to_i
 koyomi = 0
 if year < 1868
  puts "pre-meiji"
 end
 
 if year > 1989
  koyomi = year - 1988
  puts "heisei #{koyomi} #{month} #{day}"
 end

 if year == 1868
  if month < 9
   puts "pre-meiji"
  elsif month == 9
    if day <= 7
     puts "pre-meiji"
    else
     koyomi = 1
     puts "meiji #{koyomi} #{month} #{day}"
    end
  else
    koyomi = 1
    puts "meiji #{koyomi} #{month} #{day}"
  end
 end
 
 if year > 1868 && year < 1912
  koyomi = year - 1867
  puts "meiji #{koyomi} #{month} #{day}"
 end

 if year == 1912
  if month < 7
   koyomi = year - 1867
   puts "meiji #{koyomi} #{month} #{day}"
  elsif month == 7
    if day <= 29
     koyomi = year - 1867
     puts "meiji #{koyomi} #{month} #{day}"
    else
     koyomi = 1
     puts "taisho #{koyomi} #{month} #{day}"
    end
  else
    koyomi = 1
    puts "taisho #{koyomi} #{month} #{day}"
  end
 end

 if year > 1912 && year < 1926
  koyomi = year - 1911
  puts "taisho #{koyomi} #{month} #{day}"

 end
 
 if year == 1926
  if month < 12
   koyomi = year - 1911
   puts "taisho #{koyomi} #{month} #{day}"
  elsif month == 12
    if day <= 24
     koyomi = year -1911
     puts "taisho #{koyomi} #{month} #{day}"
    else
     koyomi = 1
     puts "showa #{koyomi} #{month} #{day}"
    end
  else
    koyomi = 1
    puts "showa #{koyomi} #{month} #{day}"
  end
 end

 if year > 1926 && year < 1989
  koyomi = year - 1925
  puts "showa #{koyomi} #{month} #{day}"
 end

 if year == 1989
  if month < 1
   koyomi = year - 1925
   puts "showa #{koyomi} #{month} #{day}"
  elsif month == 1
    if day <= 7
     koyomi = year - 1925
     puts "showa #{koyomi} #{month} #{day}"
    else
     koyomi = 1
     puts "heisei #{koyomi} #{month} #{day}"
    end
  else
    koyomi = 1
    puts "heisei #{koyomi} #{month} #{day}"
  end
 end




 x = gets
end


Measured memory_bytes: 6888
#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
#define double long double
using namespace std;

ll prefr[4005], prefb[4005], prefg[4005], n, ans;
string s;
ll check(ll ind, char l, char r)
{
    ll top = 0;
    for (ll i = 1; i <= min(ind, n - 1 - ind); i ++)
        top += (s[ind - i] == l && s[ind + i] == r);
    return top;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    cin >> s;
    prefr[0] = (s[0] == 'R');
    prefg[0] = (s[0] == 'G');
    prefb[0] = (s[0] == 'B');
    for (int i = 1; i < n; i ++)
    {
        prefr[i] = prefr[i - 1] + (s[i] == 'R');
        prefg[i] = prefg[i - 1] + (s[i] == 'G');
        prefb[i] = prefb[i - 1] + (s[i] == 'B');
    }
    for (ll i = 1; i < n - 1; i ++)
    {
        if (s[i] == 'R')
        {
            ans += prefg[i - 1] * (prefb[n - 1] - prefb[i]);
            ans -= check(i, 'G', 'B');
            ans += prefb[i - 1] * (prefg[n - 1] - prefg[i]);
            ans -= check(i, 'B', 'G');
        }
        if (s[i] == 'G')
        {
            ans += prefr[i - 1] * (prefb[n - 1] - prefb[i]);
            ans -= check(i, 'R', 'B');
            ans += prefb[i - 1] * (prefr[n - 1] - prefr[i]);
            ans -= check(i, 'B', 'R');
        }
        if (s[i] == 'B')
        {
            ans += prefg[i - 1] * (prefr[n - 1] - prefr[i]);
            ans -= check(i, 'G', 'R');
            ans += prefr[i - 1] * (prefg[n - 1] - prefg[i]);
            ans -= check(i, 'R', 'G');
        }
    }
    cout << ans;
    return 0;
}


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

#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
const int MOD = 1e9 + 7;
const int maxn = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-8;
const double PI = acos(-1.0);

void header() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

ll a[maxn];

void solve() {
    ll n, m, x = 0;
    cin >> n >> m;
    for (int i = 1; i <= n; i++) cin >>a[i], x += a[i];
    sort(a +1, a +1 +n, greater<ll>());
    int f = 1;
    for (int i = 1; i <= m; i++) {
        if (a[i] * 4 * m < x) {
            f = 0;
            break;
        }
    }
    cout <<(f ?"Yes" :"No") <<endl;
}

int main() {
	header();
	solve();
	return 0;
}


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

typedef long long llint;
typedef long double ld;

#define inf 1e18
#define mod 1000000007
priority_queue<llint,vector<llint>,greater<llint> > que;
priority_queue<llint> Que;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int n;
vector<llint>A,B;
void solve(){
  cin >> n;
  A.resize(n);
  B.resize(n);
  for(int i=n-1;i>=0;i--){
      cin >> A[i] >> B[i];
  }
  llint ans=0;
  for(int i=0;i<n;i++){
      if((A[i]+ans)%B[i]==0)continue;
      llint x=B[i]-((A[i]+ans)%B[i]);
      ans+=x;
  }
  cout << ans << endl;

}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 4752
#ifndef LOCAL
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#else
#include <iostream>
#include <iomanip> 
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <memory>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair < b, c > d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; }
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds; 
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}
#define fix(a) fixed << setprecision(a)
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define len(V) (int)V.size()
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define endl '\n'



void solve(){
  string s;
  cin >> s;
  int n = len(s);
  int a = 0;
  int b = 0;
  forn(i, n){
    int c = s[i];
    if (i % 2){
      if (c == '0') a++;
      else b++;
    } else {
      if (c == '1') a++;
      else b++;
    }
  }
  cout << min(a, b);
}

int main() {
  ios::sync_with_stdio(false);
  // cin.tie(0); cout.tie(0);
  int t = 1;
  // cin >> t;
  forn(i, t){
    solve();
  }
}

/* 


*/

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

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

    int v[N],w[N];
    for(int i=0; i<N; i++){
        cin >> v[i] >> w[i];
    }

    int DP[N+1][W+1];

    for(int j=0; j<=W; j++){
        DP[0][j] = 0;
    }

    for(int i=1; i<=N; i++){
        for(int j=0; j<=W; j++){
            if(j<w[i-1]){
                DP[i][j] = DP[i-1][j];
            }else{
                if(DP[i-1][j]>DP[i][j-w[i-1]]+v[i-1])
                    DP[i][j] = DP[i-1][j];
                else
                    DP[i][j] = DP[i][j-w[i-1]]+v[i-1];
            }
        }
    }

    cout << DP[N][W] << endl;

    return 0;
}



Measured memory_bytes: 7072
#include<stdio.h>
int main()
{
  int a,b=1,c;
  while(1)
 {
    scanf("%d%d\n",&a,&b);
    if(a==0 && b==0)
    {
       break;
    }
    else if(a>b)printf("%d %d\n",b,a);
    else printf("%d %d\n",a,b);
    
  }
  return 0;
}


Measured memory_bytes: 1992
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define INF 2147483647
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
struct segmenttree{
  	vint  value;
  	int N;
  	segmenttree(int n){
      	N=1;
      	while(N<n){
          	N*=2;
        }
      	value = vector<int>(2*N-1,INF);
    }
  	void update(int i,int x){
      	i+=N-1;
      	value[i]=x;
      	while(i>0){
          	i=(i-1)/2;
          	value[i]=min(value[i*2+1],value[i*2+2]);
        }
    }
    int query(int a,int b,int k,int l,int r){
      	if(r<=a || b<=l){
          	return INF;
        }
      	else if(a<=l && r<=b){
          	return value[k];
        }
		else{
          	int c1=query(a,b,2*k+1,l,(l+r)/2);
          	int c2=query(a,b,2*k+2,(l+r)/2,r);
          	return min(c1,c2);
        }
    }
};
          
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
 	 int n,q;
  	cin>>n>>q;
  	segmenttree sg(n);
  	int com,x,y;
  	rep(i,q){
      	cin>>com>>x>>y;
      	if(com==0){
          	sg.update(x,y);
        }
      	else{
          	cout<<sg.query(x,y+1,0,0,sg.N)<<'\n';
        }
    }
  	return(0);
}



Measured memory_bytes: 3892
A,B,M = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

mini = min(a) + min(b)
for i in range(M):
    x,y,c = map(int,input().split())

    rei = a[x-1]
    den = b[y-1]
    coop = c

    if rei + den - coop < mini:
        mini = rei + den - coop

print(mini)

Measured memory_bytes: 24716
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> a;
  int tmp;
  for(int i = 0; i < n; i++){
    cin >> tmp;
    a.push_back(tmp);
  }
  sort(a.begin(), a.end());
  int ret = a[n-1] - a[0]; 
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int MOD=1000000007;

ll f(int* a,int n){
  int i,j,cnt=0;
  for(i=0;i<n;i++){
    for(j=i+1;j<n;j++){
      if(a[j]<a[i])cnt++;
    }
  }
  return cnt;
}

int main(){
  int i,j,cnt=0;
  int n;ll k;
  cin>>n>>k;
  int a[n];
  for(i=0;i<n;i++)cin>>a[i];
  int a2[2*n];
  for(i=0;i<n;i++)a2[i]=a[i];
  for(i=0;i<n;i++)a2[n+i]=a[i];
  ll t=f(a,n),kt=f(a2,2*n)-2*t;
  cout<<(t*k+(k*(k-1)/2)%MOD*kt)%MOD<<endl;
}

Measured memory_bytes: 256
k = int(input())
a,b = map(int,input().split())
i = 1
c = 0
if k > b:
    print('NG')
while k <= b:
    if a <= k*i<= b:
        print("OK")
        break
    elif k*i >b:
        c = 1
        break
    else:
        i += 1
if c == 1:
    print('NG')

Measured memory_bytes: 9100
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;

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

//最小公倍数
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

int main() {
    int N;
    ll t;
    cin >> N;
    ll X = 1;
    for(int i=0; i<N; i++) {
        cin >> t;
        X = lcm(X, t);
    }
    cout << X << endl;
}

Measured memory_bytes: 3568
from sys import stdin, setrecursionlimit


def main():
    mod = 10 ** 9 + 7
    input = stdin.buffer.readline
    n = int(input())
    a = list(map(int, input().split()))

    counts = [0] * 60

    for ai in a:
        for i in range(60):
            if ai & (1 << i):
                counts[i] += 1

    ans = 0
    base = 0

    for c in counts:
        ans += c * (n - c) * (1 << base)
        ans %= mod
        base += 1

    print(ans % mod)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Measured memory_bytes: 89712
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
#include <bitset> 
#include <iterator> 
#include <map>
#include <queue>
#include <set>
#include<deque>
#define rep(i,n) for(ll i=0;i<(n); ++i)
#define per(i,n) for(ll i=n-1;i>=0; --i)
#define all(x) (x).begin(),(x).end()
#define _GLIBCXX_DEBUG
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
typedef long long ll;
const ll MOD = 1000000007;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

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

	ll n;
	cin >> n;
	vector<ll>v(n);
	rep(i, n)cin >> v[i];
	vector<pair<ll, ll>>vE(pow(10, 6)), vO(pow(10, 6));
	rep(i, pow(10, 5)) {
		vE[i] = make_pair(0, i);
		vO[i] = make_pair(0, i);
	}
	rep(i, n) {
		if (i % 2 == 0)vE[v[i]].first++;
		else vO[v[i]].first++;
	}
	sort(all(vE));
	sort(all(vO));
	ll mvE = vE[vE.size() - 1].first;
	ll mvE2 = vE[vE.size() - 2].first;
	ll mvO = vO[vO.size() - 1].first;
	ll mvO2 = vO[vO.size() - 2].first;

	if (vE[vE.size() - 1].second != vO[vO.size() - 1].second)cout << n - mvE - mvO << endl;
	else cout << n - max(mvE + mvO2, mvO + mvE2) << endl;
}



Measured memory_bytes: 32256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace A
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var x = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            for (var i = 0; i < x.Length; i++)
            {
                if (x[i] == 0)
                {
                    Console.WriteLine(i + 1);
                    return;
                }
            }
        }
    }
}


Measured memory_bytes: 28304
S = list(input())
N = len(S)

marker = [0] * N
for i in range(1, N - 1):
    if S[i] == "R" and S[i + 1] == "L":
        marker[i] = 1
    elif S[i - 1] == "R" and S[i] == "L":
        marker[i] = 2
    else:
        marker[i] = 0
marker[0] = 1 if S[1] == "L" else 0
marker[-1] = 2 if S[-2] == "R" else 0

cp = list(range(N))
p_last = [-1] * N   # ループに入る最初の座標
steps = [0] * N     # p_lastに着くまでのステップ数
dests = [0] * N     # 1: p_lastがR; 2: L
for i in range(N):
    s = 0
    cp = i
    hist = []   # 訪れた座標
    hist_append = hist.append
    while True:
        if p_last[cp] >= 0:
            p_last[i] = p_last[cp]
            steps[i] = s + steps[cp]
            dests[i] = marker[p_last[cp]]
            break
        elif marker[cp] == 0:
            s += 1
            if S[cp] == "R":
                cp += 1
            else:
                cp -= 1
            hist_append(cp)
        else:
            p_last[i] = cp
            steps[i] = s
            dests[i] = marker[cp]
            break

    for j, h in enumerate(hist[::-1], 1):
        p_last[h] = p_last[i]
        steps[h] = steps[i] - j
        dests[h] = dests[i]

count = [0] * N
for i in range(N):
    pl = p_last[i]
    if dests[i] == 1:
        if steps[i] % 2 == 0:
            count[pl] += 1
        else:
            count[pl + 1] += 1
    else:
        if steps[i] % 2 == 0:
            count[pl] += 1
        else:
            count[pl - 1] += 1
print(" ".join(str(c) for c in count))


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

#define lld long long
#define pp pair<int,int>
#define y1 y11
#define INF 1000000000
#define pb push_back

using namespace std;

int N,ans;
char s[102],t[102];

int main(){
	scanf("%d",&N);
	scanf("%s%s",s,t);
	ans = N*2;
	for(int i=0; i<N; i++){
		int cnt = 0;
		for(int j=0; j<N; j++){
			if(i+j >= N) break;
			if(s[i+j] != t[j]) break;
			cnt++;
		}
		ans = min(ans,N*2-cnt);
	}
	printf("%d\n",ans);

	return 0;
}

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

#include <fstream>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  /*
  ifstream in("input.txt");
  cin.rdbuf(in.rdbuf());
  //*/
  int A, B;
  cin >> A >> B;
  cout << (A-1) * (B-1) <<endl;
}

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

import sys
import numpy as np


def check(N, M, V, P, As, i):
    # As = 3 2 2 1 1 0
    border = As[P - 1]
    a = As[i]
    # iはTop Pに入っている
    if a >= border:
        return True
    # iに全票入れてもTop Pに入れない
    if a + M < border:
        return False

    # iがTop Pに入るのを保てる最大の票数を計算
    num = M  # i番目に全票
    num += (P - 1) * M  # Top 1からP-1までには全票いれてよい
    num += (N - i - 1) * M # iよりあとのものにも全票いれてよい
    for j in range(P - 1, i): # Top Pからi-1まで、同票までOK
        num += (a + M - As[j])
    
    return num >= M * V


def solve(N, M, V, P, As):

    As = As[:]
    As.sort(reverse=True)

    # for j in range(N):
    #     print("j, check = ", j, check(N, M, V, P, As, j))

    # 二分探索がなりたたない場合を除外
    if check(N, M, V, P, As, N-1):
        return N

    ok = 0
    ng = N - 1
    while ng - ok > 1:
        mid = (ok + ng) // 2
        if check(N, M, V, P, As, mid):
            ok = mid
        else:
            ng = mid

    return ok + 1


def main():
    N, M, V, P = map(int, input().split())
    As = list(map(int, input().split()))
    print(solve(N, M, V, P, As))

main()

Measured memory_bytes: 23196
#include <iostream>
#include <string.h>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;
typedef long long ll;
const ll INF=100000000000000LL;

int main() {
	int n,a[101],ma=0,mi=1000;
	cin>>n;
	for(int i=0;i<n;++i){
		cin>>a[i];
		ma=max(ma,a[i]);
		mi=min(mi,a[i]);
	}
	cout<<ma-mi<<endl;
	return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
/*
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>


typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };
*/

using namespace std;

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

    int q;
    cin >> q;

    for (int i = 0; i < q; i++)
    {
        string cmd;
        cin >> cmd;
        int a, b;
        cin >> a >> b;
        if (cmd == "print")
        {
            for (int i = a; i <= b; i++)
                cout << str[i];
            cout << endl;
        }
        else if (cmd == "reverse")
        {
            string tmp = str;
            for (int i = a, j = 0; i <= b; i++, j++)
                str[i] = tmp[b - j];
        }
        else if (cmd == "replace")
        {
            for (int i = a; i <= b; i++)
            {
                char p;
                cin >> p;
                str[i] = p;
            }
        }
    }
}


Measured memory_bytes: 3164
#include<iostream>
#include<vector>
using namespace std;
#define int long long
#define V vector
#define vel V<int>
#define rep(i,n) for(int i=0;i<n;i++)
#define mkp make_pair
#define pin pair<int,int>
pin solve(V<pin>& ab, int ex) {
	if (!ex) { return mkp(0, 0); }
	V<V<pin>> qab(2);
	int sz = ab.size();
	qab[0].reserve(sz);
	qab[1].reserve(sz);
	for (pin& x : ab) {
		qab[x.second & 1].push_back(mkp(x.first / 2, x.second / 2));
		if (x.first & 1) { qab[(x.second + 1) & 1].push_back(mkp(x.first / 2, (x.second + 1) / 2)); }
	}
	int c = 0;
	for (pin& x : qab[0]) {
		int qc = (2 * x.first + x.second) % 3;
		c ^= (qc + 1);
	}
	if (!c) {
		pin ans = solve(qab[1], ex - 1);
		ans.first *= 2; ans.second *= 2; ans.second++;
		return ans;
	}
	pin ans = solve(qab[0], ex - 1);
  	c=0;
  	for (pin& x : qab[1]) {
		int qc = (2 * x.first + x.second) % 3;
		c ^= (qc + 1);
	}
  	if (!c) {
		ans.first *= 2; ans.second *= 2;
		return ans;
	}
	c = 0;
	for (pin& x : qab[1]) {
		int w = ans.second - x.second-1;
		if ((w & x.first) == w) { c ^= 1; }
	}
	ans.first *= 2; ans.first++; ans.second *= 2; ans.second -= c;
	return ans;
}
signed main() {
	cin.tie(0); ios::sync_with_stdio(false);
	long long inf = 1e17;
	int n; cin >> n;
	V<pin> ab(n);
	rep(i, n) {
		long long a, b; cin >> a >> b;
		ab[i] = { a + inf,b + inf };
	}
	pin ret = solve(ab, 59);
	cout << ret.first - inf << " " << ret.second - inf << "\n";
}


Measured memory_bytes: 10496
N = int(input())

fiz = N // 3
buz = N // 5
fizbuz = N // 15


fiz_m = 0
buz_m = 0
fizbuz_offset = 0


for i in range(1,fiz+1):
    fiz_m += i*3

for j in range(1,buz+1):
    buz_m += j*5

for l in range(1,fizbuz+1):
    fizbuz_offset += l*15

total = 0
for num in range(1,N+1):
    total += num

result = total - fiz_m - buz_m + fizbuz_offset
print(result)

Measured memory_bytes: 9228
def q2():
    N, K = (int(i) for i in input().split())
    H = [int(i) for i in input().split()]

    # dp配列の初期化 (最小化問題なので初期値をINFとする)
    dp = [float('inf')]*N
    dp[0] = 0
    dp[1] = abs(H[1] - H[0])

    for i in range(1, N):
        max_K = i if K > i else K
        for k in range(0, max_K + 1):
            step = dp[i-k] + abs(H[i] - H[i-k])
            dp[i] = min(dp[i], step)

    print(dp[N-1])


if __name__ == '__main__':
    q2()

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

int main() {
    int a, b;
    string s;
    cin >> a >> b >> s;

    if (s.length() == a+b+1) {
        int count = 0;
        for (int i = 0; i < s.length(); i++) {
            if (s[i] == '-')
                count++;
        }
        if (count == 1) {
            if (s[a] == '-') {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3600
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

struct Graph{
  int v_size;
  vector<vector<int>> adj;

  Graph(const int v_size):v_size(v_size){
    this->adj.resize(v_size);
  }

  void add_edge(const int s, const int t){
    this->adj[s].emplace_back(t);
  }
};

void tsort(const Graph& g)
{
  vector<int> indeg(g.v_size);
  for(const auto& u : g.adj){
    for(const auto& to : u){
      ++indeg[to];
    }
  }
  
  vector<bool> used(g.v_size);
  queue<int> q;

  vector<int> ans;
  ans.reserve(g.v_size);
  
  for(int i = 0; i < g.v_size; ++i){
    if(indeg[i] == 0 && !used[i]){
      q.push(i);
      used[i] = true;

      while(!q.empty()){
        auto u {q.front()};
        q.pop();
        
        ans.emplace_back(u);

        for(const auto& v : g.adj[u]){
          --indeg[v];

          if(indeg[v] == 0 && !used[v]){
            q.push(v);
            used[v] = true;
          }
        }        
      }
    }
  }

  for(const auto& v : ans){
    cout << v << endl;
  }
}

int main()
{
  int V, E;
  cin >> V >> E;

  Graph g(V);

  int s, t;
  for(int i = 0; i < E; ++i){
    cin >> s >> t;
    g.add_edge(s,t);
  }

  tsort(g);
}


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

const int END = -1;
struct StNod
{
  int m_nParnt;
  int m_nLeft;
  int m_nRigt;

  StNod() :
     m_nParnt(END), m_nLeft(END), m_nRigt(END)
  { }
};

enum EnDir
{
  D_Left,
  D_Right,
};

void fnInput(vector<int> &rvnPodr, vector<int> &rvnIodrSeq)
{
  int nMaxSiz;

  cin >> nMaxSiz;
  rvnPodr.resize(nMaxSiz);
  rvnIodrSeq.resize(nMaxSiz + 1);

  for (int i = 0; i < nMaxSiz; i++)
    cin >> rvnPodr[i];

  for (int i = 1; i < nMaxSiz + 1; i++)
  {
    int nNode;
    cin >> nNode;
    rvnIodrSeq[nNode] = i;
  }
}

void fnStructTree(const vector<int> &cnrvnPodr, const vector<int> &cnrvnIodrSeq, vector<StNod> &rvoNod)
{
  for (int i = 1; i < cnrvnPodr.size(); i++)
  {
    int nParnt = END;
    int nx = cnrvnPodr[0];
    EnDir enDir;
    while (nx != END)
    {
      nParnt = nx;
      if (cnrvnIodrSeq[ cnrvnPodr[i] ] < cnrvnIodrSeq[nx])
      {
        nx = rvoNod[nx].m_nLeft;
        enDir = D_Left;
      }
      else
      {
        nx = rvoNod[nx].m_nRigt;
        enDir = D_Right;
      }
    }

    rvoNod[ cnrvnPodr[i] ].m_nParnt = nParnt;
    if (enDir == D_Left)
      rvoNod[nParnt].m_nLeft = cnrvnPodr[i];
    else
      rvoNod[nParnt].m_nRigt = cnrvnPodr[i];
  }
}

void fnPostOrder(const vector<StNod> &cnrvoNod, int nx)
{
  static int stnPrt = 0;
  if (nx == END)  return;

  fnPostOrder(cnrvoNod, cnrvoNod[nx].m_nLeft);
  fnPostOrder(cnrvoNod, cnrvoNod[nx].m_nRigt);

  if (stnPrt++) cout << " ";
  cout << nx;
}

void fnResult(const vector<StNod> &cnrvoNod)
{
  int nx = 1;
  while (cnrvoNod[nx].m_nParnt != END)
    nx = cnrvoNod[nx].m_nParnt;

  fnPostOrder(cnrvoNod, nx);
  cout << endl;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<int> vnPodr, vnIodrSeq;
  vector<StNod> voNod;

  fnInput(vnPodr, vnIodrSeq);

  StNod oNod;
  voNod.resize(vnIodrSeq.size(), oNod);
  fnStructTree(vnPodr, vnIodrSeq, voNod);
  
  int nOCnt = 0;
  fnResult(voNod);
  return 0;
}

Measured memory_bytes: 1200