akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000000000000007LL
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;
int n,a[200005],dp[200005][4][2];
int go(int pos,int cnt,int last){
	if(cnt<-1) return -hell;
	if(pos==n) return 0;
	int &ans=dp[pos][cnt+2][last];
	if(ans!=-1) return ans;
	ans=go(pos+1,cnt-1,0);
	if(last==0) ans=max(ans,go(pos+1,cnt+1,1)+a[pos]);
	return ans;
}
void solve(){
    cin>>n;
    rep(i,0,n) cin>>a[i];
    memset(dp,-1,sizeof dp);
    cout<<go(0,n%2,0)<<endl;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 33336
#![allow(dead_code)]
#![allow(unused_variables)]
use std::collections::BTreeSet;
 
const MOD: i64 = 1e9 as i64 + 7;
 
fn main(){
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let n: usize = sc.read();
    let a: Vec<u64> = sc.vec(n);

    let mut st = BTreeSet::<u64>::new();
    for v in a {
        st.insert(v);
    }
    if st.len() == n {
        println!("YES");
    }
    else{
        println!("NO");
    }
}
 
pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);
 
impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .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: 8444
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n); for(ll i = 0; i < (ll)n; i++)

int main() {
  int n; cin >> n;
  vector<int> v(n);
  rep(i,n) cin >> v[i];
  
  int tall = 0;
  int ans = 0;
  
  rep(i,n){
    if(v[i] >= tall){
      ans++;
      tall = v[i];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

typedef long long ll;

int main(void) {

    int N, T; cin >> N >> T;
    vector<ll> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];

    map<ll, ll> subs; // (sub, count)
    int f_idx = 0;
    for (int i = 1; i < N; i++) {
        if (A[f_idx] >= A[i]) {
            f_idx = i;
        } else {
            ll sub = A[i] - A[f_idx];
            // cout << "A[" << i << "] - A[" << f_idx << "]: " << sub << endl;
            subs[sub]++;
        }
    }

    ll max_sub = -1;
    for (auto it = subs.begin(); it != subs.end(); it++) {
        max_sub = max(max_sub, it->first);
    }

    cout << subs[max_sub] << endl;

    return 0;
}

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



int main() {
  int n,a,b;
  cin >> n >> a >> b;
  cout << min(n*a,b) << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void)
{
	int i,flg[30]; 
	char s[100001],x[30];
	scanf("%s",s);
	for(i=0;i<=25;i++) flg[i]=0;
	for(i=0;i<strlen(s);i++){
		flg[s[i]-97]=1;
	}
	//for(i=0;i<=25;i++) printf("%d",flg[i]);
	for(i=0;i<=25;i++){
		if(flg[i]==0){
			printf("%c\n",i+97);
			break;
		}
	}
	if(i==26) printf("None\n");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define loop(i,x,z) for (int i=x;i<z;i++)
using ll = long long;
ll a, b, v, w, t;
int main()
{
	cin >> a >> v >> b >> w >> t;
	if (w >= v)cout << "NO";
	else
	{
      ll m;
		m =__gcd(w,v);
      	v-=w;
		if (a > b)swap(a, b);
		b -= a;
      	a=b/v;
      if(b%v!=0)a++;
		if (b % m == 0 and a<=t)cout << "YES";
		else cout << "NO";
	}
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1000003;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

template<class T> inline bool chmin(T &a,T b){
    if (a>b){
        a=b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T &a,T b){
    if (a<b){
        a=b;
        return true;
    }
    return false;
}

const ll MAX=100010;

int main(){
    ll N,W;
    cin >> N >> W;
    vector<ll> w(N),v(N);
    rep(i,N) cin >> w[i] >> v[i];
    vector<vector<ll>> dp(N+1,vector<ll>(MAX,IINF));
    dp[0][0]=0;
    rep(i,N){
        rep(j,MAX){
            chmin(dp[i+1][j],dp[i][j]);
            if (j-v[i]>=0) chmin(dp[i+1][j],dp[i][j-v[i]]+w[i]);
        }
    }
    ll ans=0;
    rep(i,MAX){
        if (dp[N][i]<=W) ans=i;
    }
    cout << ans << endl;
}

Measured memory_bytes: 80256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pi;

ll d;
ll p[20];
int dx1[20], dx2[20];
vector<ll> v;

void dfs(int s, int e, vector<pi> &w, ll val, ll cnt){
	if(s == e){
		w.push_back(pi(-val, cnt));
		return;
	}
	for(int i=-9; i<=9; i++){
		dfs(s+1, e, w, val + i * v[s], cnt * (s == 0 ? dx2[i + 10] : dx1[i + 10]));
	}
}

ll solve(int l){
	v.clear();
	for(int i=0; l-1-i > i; i++){
		v.push_back(p[l-1-i] - p[i]);
	}
	vector<pi> v1, v2;
	dfs(0, (v.size()+1) / 2, v1, 0, 1);
	dfs((v.size()+1) / 2, v.size(), v2, 0, 1);
	ll ans = 0;
	map<ll, ll> mp;
	for(auto &i : v2) mp[i.first] += i.second;
	for(auto &i : v1){
		ans += mp[d-i.first] * i.second;
	}	
	if(l % 2 == 1) ans *= 10;
	return ans;
}

int main(){
	p[0] = 1;
	for(int i=1; i<20; i++) p[i] = p[i-1] * 10;
	for(int i=0; i<10; i++){
		for(int j=0; j<10; j++){
			dx1[i-j+10]++;
		}
	}
	for(int i=1; i<10; i++){
		for(int j=0; j<10; j++){
			dx2[i-j+10]++;
		}
	}
	cin >> d;
	ll ans = 0;
	for(int i=2; i<=18; i++) ans += solve(i);
	cout << ans << endl;
}


Measured memory_bytes: 206072
// In the name of God

#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>

using namespace std;

#define rep(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

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

typedef long long LL;
#define int long long
const int N = (int) 1e6 + 6, mod = (int) 0;
int n;
struct seg {
	int mn[N << 2];
	seg() { memset(mn, 63, sizeof mn); }
	void update(int pos, int x, int v = 1, int b = 0, int e = n) {
		if (b + 1 == e) {
			mn[v] = min(x, mn[v]);
			return;
		}
		int m = b + e >> 1, l = v << 1, r = l | 1;
		if (pos < m) {
			update(pos, x, l, b, m);
		} else {
			update(pos, x, r, m, e);
		}
		mn[v] = min(mn[l], mn[r]);
	}
	int query(int i, int j, int v = 1, int b = 0, int e = n) {
		if (i >= e || b >= j) return 1e18;
		if (i <= b && e <= j) return mn[v];
		int m = b + e >> 1, l = v << 1, r = l | 1;
		return min(query(i, j, l, b, m), query(i, j, r, m, e));
	}
} sa, sb;
int32_t main() {
	int q, sta, stb;
	cin >> n >> q >> sta >> stb;
	--sta, --stb;
	sa.update(sta, -sta);
	sb.update(sta, +sta);
/*	
	sa.update(stb, -stb);
	sb.update(stb, +stb);
*/	
	int last = stb, lval = 0, add_all = 0;
	for (int j = 0; j < q; ++j) {
		int pos;
		cin >> pos;
		--pos;
		int cur_val = 1e18;
		//lval + abs(pos - last);
		cur_val = min(cur_val, sa.query(0, pos) + pos + add_all);
		cur_val = min(cur_val, sb.query(pos, n) - pos + add_all);
		
		add_all += abs(pos - last);
		sa.update(last, cur_val - add_all - last);
		sb.update(last, cur_val - add_all + last);
		cur_val = min(cur_val, lval + abs(pos - last));
//		cout << " hi " << j << ' ' << cur_val << ' ' << lval + abs(pos - last) << endl;
		last = pos;
		lval = cur_val;
	}
	cout << lval << endl;
}





Measured memory_bytes: 62720
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <cmath>
#include <climits>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;

// 2^k
int dval(int s, int k){
  return (s >> k) % 2;
}

bool used[21];

void fill_bit(int x){
  for(int i = 0; i < 21; i++){
    if(dval(x, i) == 1)used[i] = true;
  }
}

void remove_bit(int x){
  for(int i = 0; i < 21; i++){
    if(dval(x, i) == 1)used[i] = false;
  }
}

bool check(int x){
  for(int i = 0; i < 21; i++){
    if(dval(x, i) == 1 && used[i])return false;
  }
  return true;
}

int main(int argc, char const* argv[])
{
  int n;
  cin >> n;
  vector<int> a;
  for(int i = 0; i < n; i++){
    int x;
    cin >> x;
    a.pb(x);
  }
  ll res = 0;
  int r = 1;
  fill_bit(a[0]);
  for(int i = 0; i < n; i++){
    if(r == i){
      fill_bit(a[i]);
      r++;
    }
    while(r < n){
      if(check(a[r]))r++;
      else break;
      fill_bit(a[r - 1]);
    }
    res += r - i;
    remove_bit(a[i]);
  }
  cout << res << endl;
	return 0;
}


Measured memory_bytes: 1400
n, l = map(int, input().split())

mi = 300
choice = 0

for i in range(1, n+1):
  tmp = abs(l + i - 1)
  if tmp < mi:
    mi = tmp
    choice = i
    
ans = 0

for i in range(1, n+1):
  if i == choice:
    continue
  ans += l + i - 1
  
print(ans)

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

int main()
{
long long K,A,B,C;
cin>>A>>B>>C>>K;
if(A>=K){
    cout<<K<<endl;
}
else if(A+B>=K){
    cout<<A<<endl;
}
else{
    cout<<(A)-(K-A-B)<<endl;
}
    return 0;
}


Measured memory_bytes: 3624
def ans(n,s):
    p = [[] for i in range(n)]
    h = []
    i = 0
    while True:
        if s == []:
            break
        c = s.pop(0)
        if c == 'M':
            if p[i] == []:
                p[i] = [c]
            else:
                p[i].append(c)
        elif c == 'L':
            if p[i] == []:
                p[i] = [c]
            else:
                p[i].append(c)
            if h != []:
                p[i] += h
            h = []
        elif c == 'S':
            if h == []:
                h = [c]
            else:
                h.append(c)
            if p[i] != []:
                h += p[i]
            p[i] = []
        
        i = (i+1) % n
    pp = list(sorted(map(len,p)))
    hh = len(h)
    pp.append(hh)
    
    return " ".join(map(str,pp))

while True:
    n = int(input())
    if n == 0:
        break
    s = list(input())
    o = ans(n,s)
    print(o)

Measured memory_bytes: 7832
N,M = list(map(int,input().split()))
A = list(map(int,input().split()))
B =  sorted(A)
C = list()
total = 0
if N >= M:
    total = 0
else:
    for i in range(M-1):
        C.append(B[i+1]-B[i])
    D = sorted(C)
    E = D[0:(M-N)]
    total = sum(E)
print(total)

Measured memory_bytes: 13968
n = int(input())
a = []
b = []
for i in range(n):
    x, y = map(int, input().split())
    a.append([x, y])
    b.append([y, x])
a.sort()
b.sort()
L = (a[1][0] - a[0][0]) ** 2 + (a[1][1] - a[0][1]) ** 2
for i in range(n - 1):
    dis = (a[i+1][0] - a[i][0]) ** 2 + (a[i+1][1] - a[i][1]) ** 2
    if L > dis:
        L = dis
for i in range(n - 1):
    dis = (b[i+1][0] - b[i][0]) ** 2 + (b[i+1][1] - b[i][1]) ** 2
    if L > dis:
        L = dis
print(L)



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

// aを常に小さい値にする　大きい値にする
template<class T> bool chmin(T &a, T b){ if(a>b) a = b; }
template<class T> void chmax(T &a, T b){ if(a<b) a = b; }

// 二分探索 前方のindexを返すもの（自分自身を含む） 前方: -INF側のこと
template<class T> int former(const vector<T> &v, T x){
    return upper_bound(v.begin(), v.end(), x) - v.begin() -1; // upper_bound : keyより大きい要素の内の一番左側のイテレータを返す
}
// 二分探索 後方のindexを返すもの（自分自身を含む）後方: INF側のこと
template<class T> int latter(const vector<T> &v, T x){
    return lower_bound(v.begin(), v.end(), x) - v.begin(); // lower_bound : key以上の要素の内の一番左側のイテレータを返す
}

// 最大公約数を求める GCD
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }


// 素因数分解 pair
vector<pair<ll, ll> > prime_factorize(ll n) {
    vector<pair<ll, ll> > res;
    for (ll p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) {
            ++num;
            n /= p;
        }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

const int MAX = 210000;
const int MOD = 1000000007;

//  二項係数の計算nCk セット
//  https://drken1215.hatenablog.com/entry/2018/06/08/210000
//  使い方としては、最初に一度前処理として COMinit() をしておけば、あとは COM(n, k) 関数を呼べばよい
//  前処理 COMinit(): O(n)
//　クエリ処理 COM(n, k): O(1)
ll fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

/*
 * 2 進法展開や 10 進法展開なら N進法で割ってやるのを繰り返すのが基本
 * -2 進法になっても同じ。
 *
 *
引き算も基本的には一緒で「計算の途中過程で積極的にあまりをとってよい」という感じなのですが、「負の数のあまり」について少しだけ注意が必要です。
−17 を 5 で割ったあまり
は正しくは 3 になります。そもそも「a を b で割ったあまり」というのは「a に b の倍数を足し引きして得られる数のうち、
 0 以上 b 未満のもの」を表しています。
 −17 に 5 の倍数である 20 を足すと 3 になります。しかし C++ ではあまりの定義が少しだけ変なことになります:
−17 を 5 で割ったあまりはマイナスをつけて −2 となるつまり割った数を足して3にしてやればよいことになる

 *
 * */

int main() {

    int N; cin >> N;
    string str = "";
    while (N != 0) {
        /* N を 2 で割ったあまりを求める */
        int r = N % 2;
        if (r < 0) r += 2; // N がマイナスだと r がマイナスになったりするので 2 を足す

        /* N から余りを取り除いて -2 で割る */
        N = (N - r) / (-2);

        /* 答えに追加 */
        str += (char)('0' + r);
    }
    /* 向きが逆なので反転 */
    reverse(str.begin(), str.end());
    if (str == "") str = "0"; // N = 0 のときは空文字列になってしまうので例外処理
    cout << str << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(ll i=0;i<n;i++)
#define ll long long
#define ggr getchar();getchar();return 0;
#define prique priority_queue
#define inf 1000000007
#define double long double
using namespace std;
typedef pair<ll, ll>P;
bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
ll lcm(ll x, ll y) {
	return x * y / gcd(x, y);
}
ll mod_pow(ll x, ll n, ll mod) {
	ll bit = 1;
	while (n) {
		if (n & 1)bit = bit * x % mod;
		x = x * x % mod;
		n /= 2;
	}
	return bit;
}
ll C(ll a, ll b) {
	ll x = 1, y = 1;
	rep(i, b) {
		x = x * (a - i) % inf;
		y = y * (b - i) % inf;
	}
	rep(i, inf) {
		if (x == y * i % inf) {
			return i;
		}
	}
}
signed main() {
	ll n, memo = 0;
	string s;
	cin >> n >> s;
	if (n % 2 == 1)puts("No");
	else {
		rep(i, n / 2) {
			if (s[i + n / 2] == s[i])memo++;
		}
		if (memo == n / 2)puts("Yes");
		else puts("No");
	}
	ggr
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef pair<ll,ll> p;
const int inf=(1<<30);
#define rep(i,a,n)	for(int i=a;i<n;i++)
#define rrep(i,a,n) for(int i=(a-1);i>=n;i--)
	int main(){
		rep(i,0,5){
			ll a;
			cin>>a;
			if(a==0)cout<<i+1<<endl;
		}
	}

Measured memory_bytes: 3568
// https://atcoder.jp/contests/abc115/tasks/abc115_d
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define EPS (1e-9)
#define INF (1e9)
#define INFL (1e18)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = (n - 1); i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define BIT(n) (1LL << (n))
// ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
// ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }

ll blen[51], plen[51];
ll rec(ll n, ll x) {
    ll len = blen[n - 1];
    ll num = plen[n - 1];
    if (n == 0)
        return 1;
    if (x == 1)
        return 0;
    else if (x <= len + 1)
        return rec(n - 1, x - 1);
    else if (x == len + 2)
        return num + 1;
    else if (x <= (len + 1) * 2)
        return num + 1 + rec(n - 1, x - len - 2);
    else
        return num * 2 + 1;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n, x;
    cin >> n >> x;
    blen[0] = 1;
    plen[0] = 1;
    REP(i, 50) {
        blen[i + 1] = blen[i] * 2 + 3;
        plen[i + 1] = plen[i] * 2 + 1;
    }
    cout << rec(n, x) << endl;

    return 0;
}


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

typedef pair<int, int> pii;
typedef long long ll;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

#ifdef LOCAL
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else 
#define dump(x) true
#endif

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; }
template<class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; }

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

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

int main() {
	int N, Z, W; cin >> N >> Z >> W;
	V<int> a(N); rep(i, N) cin >> a[i];
	int ans = abs(W - a[N-1]);
	if (N >= 2) {
		chmax(ans, abs(a[N-2] - a[N-1]));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
      	//数値の入力
		int a = scn.nextInt();
		int b = scn.nextInt();
      	int k = scn.nextInt();
      	//重複する場合
      	if(k>(a+b)/2-a){
        	for(int i=0; i<b-a+1; ++i){
				System.out.println(a+i);
			}
        }else if(a==b){
          System.out.println(a);
        }else{
          	//重複しない場合
         	for(int i=a; i<=a+k-1; ++i){
				System.out.println(i);
			}
          	for(int i=b-k+1; i<=b; ++i){
				System.out.println(i);
			}
        }
	}
}

Measured memory_bytes: 36248
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
#define int long long
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}

int n;
string s[100000];
int a[5], ta;

signed main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> s[i];
		if (s[i][0] == 'M')a[0]++;
		if (s[i][0] == 'A')a[1]++;
		if (s[i][0] == 'R')a[2]++;
		if (s[i][0] == 'C')a[3]++;
		if (s[i][0] == 'H')a[4]++;
	}
	for (int i = 0; i < 3; i++) {
		for (int j = i + 1; j < 4; j++) {
			for (int k = j + 1; k < 5; k++) {
				ta += a[i] * a[j] * a[k];
			}
		}
	}
	cout << ta << endl;
	getchar(); getchar();
	return 0;
}

Measured memory_bytes: 6144
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

using namespace std;

#define MAX 100000
#define INF 2140000000
#define MOD 1000000007

int main() {
	int n, k;
	cin >> n >> k;
	vector<int> v(n);

	for (int i = 0; i < n; ++i) {
		cin >> v[i];
	}
	int ans = 0;

	for (int i = 1; i < k + 1; ++i) {
		if (i >= n) {
			vector<int> negs;
			int sum = 0;
			for (int j = 0; j < n; ++j) {
				sum += v[j];
				if (v[j] < 0) {
					negs.push_back(v[j]);
				}
			}

			sort(negs.begin(), negs.end());

			for (int j = 0; j < k - i && j < (int) negs.size(); ++j) {
				sum -= negs[j];
			}

			ans = max(ans, sum);
		}
		else {
			for (int kk = 0; kk <= i; ++kk) {
				vector<int> negs;
				int sum = 0, front = kk, back = i - kk;

				for (int j = 0; front--; ++j) {
					sum += v[j];
					if (v[j] < 0) {
						negs.push_back(v[j]);
					}
				}

				for (int j = n - 1; back--; --j) {
					sum += v[j];
					if (v[j] < 0) {
						negs.push_back(v[j]);
					}	
				}

				sort(negs.begin(), negs.end());

				for (int j = 0; j < k - i && j < (int) negs.size(); ++j) {
					sum -= negs[j];
				}

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

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return int(stdin.readline())

N = li()
a = li()
b = li()
c = li()
d = li()
e = li()

bottle_neck = min([a, b, c, d, e])
red = (N - 1) // bottle_neck
print(5 + red)


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

int main(){
  int i,ans;
  string a,b,c,d;
  cin >> a>> b;
  ans=0;
  for(i=1;i<=3;i++){
    c=a.substr(0,1);
    d=b.substr(0,1);
  	if(c==d)ans=ans+1;
    a.erase(0,1);
    b.erase(0,1);
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
//#include<sstream>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define clr(a) memset(a, 0, sizeof(a))
#define set(a) memset(a, -1, sizeof(a))
#define pb push_back
#define sz(a) ((ll)a.size())
#define all(a) a.begin(), a.end()
#define mp make_pair
#define rep(i, a, y) for (ll i = a; i <= y; i++)
#define rep2(i, b) for (int i = 0; i < b; i++)
#define repl(i, a, b) for (ll i = a; i <= b; i++)
#define ppi pair<int, int>
#define scl(x) scanf("%d", &x)
#define pcl(x) printf("%d", x)
#define FastRead                  \
    ios_base::sync_with_stdio(0); \
    cin.tie(0)
/*

     ██╗██╗   ██╗██╗  ██╗ █████╗ ███╗   ██╗
     ██║██║   ██║██║  ██║██╔══██╗████╗  ██║
     ██║██║   ██║███████║███████║██╔██╗ ██║
██   ██║██║   ██║██╔══██║██╔══██║██║╚██╗██║
╚█████╔╝╚██████╔╝██║  ██║██║  ██║██║ ╚████║
 ╚════╝  ╚═════╝ ╚═╝  ╚═╝╚═╝  ╚═╝╚═╝  ╚═══╝

*/

int main()
{
    FastRead;
    string s;
    cin >> s;
    ll cnt = 0,cnt1=0;
    for (ll i = 0; i < s.size(); i++)
    {
        if(s[i]=='B')
        {
            cnt++;
        }
        else
        {
            cnt1+=cnt;
        }
    }
    cout<<cnt1<<endl;
    return 0;
}

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

int a,key;

int main(){
	cin >> a;
	int A[a];
	for(int i=0; i<a; ++i){
		cin >> A[i];
	}
	
	for(int i=0; i<a-1; ++i){
		printf("%d ", A[i]);
	}
	printf("%d\n", A[a-1]);
	
	for(int i=1; i<a; ++i){
		key = A[i];
		int j = i-1;
		while(j>=0 && A[j] > key){
			A[j+1] = A[j];
			--j;
		}
		A[j+1] = key;
		
		for(int i=0; i<a-1; ++i){
			printf("%d ", A[i]);
		}
		printf("%d\n", A[a-1]);
	}
}


Measured memory_bytes: 3228
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt() - (i + 1);
        }
        
        Arrays.sort(a);

        long b = 0;
        if (n % 2 == 0) {
            b = a[n / 2 - 1];
            b += a[n / 2];
            b /= 2;
        } else {
            b = a[n / 2];
        }

        long ans = 0;
        for (int i = 0; i < n; i++) {
            ans += Math.abs(a[i] - b);
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 59868
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    int N;
    ll A,B,C;
    cin >> N >> A >> B >> C;
    vector<string> S(N);
    for (int i = 0; i < N; i++) {
        cin >> S[i];
    }

    vector<string> ans;
    REP(i, N){
        bool flag = false;
        if(S[i]=="AB"){
            if(A==1&&B==1){
                if(i!=N-1&&S[i+1]=="BC"){
                    B++;A--;ans.pb("B");
                }else{
                    A++;B--;ans.pb("A");
                }
            }else if(A==0&&B==0){
                flag = true;
            }else if(A<B){
                A++;B--;ans.pb("A");
            }else{
                B++;A--;ans.pb("B");
            }
        }else if(S[i]=="AC"){
            if(A==1&&C==1){
                if(i!=N-1&&S[i+1]=="BC"){
                    C++;A--;ans.pb("C");
                }else{
                    A++;C--;ans.pb("A");
                }
            }else if(A==0&&C==0){
                flag = true;
            }else if(A<C){
                A++;C--;ans.pb("A");
            }else{
                C++;A--;ans.pb("C");
            }
        }else{
            if(B==1&&C==1){
                if(i!=N-1&&S[i+1]=="AC"){
                    C++;B--;ans.pb("C");
                }else{
                    B++;C--;ans.pb("B");
                }
            }else if(B==0&&C==0){
                flag = true;
            }else if(B<C){
                B++;C--;ans.pb("B");
            }else{
                C++;B--;ans.pb("C");
            }
        }   
        if(flag){
            pr("No");
            return 0;
        }
    }

        pr("Yes");
    for(auto&& s : ans){
        pr(s);
    }
}

Measured memory_bytes: 10596
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod=1e9+7;

int main(){
    int N;
    cin >> N;
    double ans=0;
    for(int i=0; i<N; i++){
        double num;
        cin >> num;
        ans += 1/num;
    }
    cout << 1/ans;
}

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

signed main() {
  int N;
  cin >>N;
  vector<long long> A(N);
  for(int i=0; i<N; i++) cin >> A[i];

  for(int i=0; i<N; i++) {
    if(A[i] == 0) {
      puts("0");
      return 0;
    }
  }

  long long ans = 1;

  for(int i=0; i<N; i++) {
    if(ans > 1000000000000000000 / A[i]){
      puts("-1");
      return 0;
    }
    ans *= A[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 4052
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout <<(#x)<<" is "<<(x)<<endl
#define debug cout <<"hi"<<endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD=1e9+7;
const int INF32=1<<30;
const ll INF64=1LL<<60;

void solve(){
  ll a,b,c,d; cin >>a >>b >>c >>d;
  ll l=c*d/__gcd(c,d); a--;
  cout <<(b-a)-(b/c-a/c)-(b/d-a/d)+(b/l-a/l);
}

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

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

int main(){
  int n,k;cin>>n>>k;
  vector<int> v(n);
  for(int i=0;i<n;i++)cin>>v[i];
  sort(v.begin(),v.end());
  int ans=0;
  for(int i=0;i<k;i++)ans+=v[i];
  cout<<ans<<endl;
}


Measured memory_bytes: 3608
taro = 0
hanako = 0

n = int(input())
for i in range(n):
    t, h = input().split()
    if t < h:
        hanako += 3
    elif t == h:
        taro += 1
        hanako += 1
    elif h < t:
        taro += 3
print("%d %d" % (taro, hanako))



Measured memory_bytes: 5600
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds; 
using namespace std;

#define int           long long 
#define S             second
#define F             first
#define pb            push_back
#define all(c)        (c).begin(),(c).end()
#define rall(c)       (c).rbegin(),(c).rend() 
#define lb            lower_bound
#define ub            upper_bound
#define si(c)         (int)((c).size())
#define lcm(a, b)      (a * (b / __gcd(a,b)))  
#define inf           (int)(4e18)
#define endl          '\n'
#define mp            make_pair
#define time(s)       (double(clock()-s)/double(CLOCKS_PER_SEC))
#define debug(args...)    _F(#args, args)
#define vi            std::vector<int>
#define pii           pair<int, int> 
#define vpi           vector<pii>
#define ordered_set   tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

clock_t start;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());

template<typename T> void _F(const char *name, T arg1){ cerr << name << " = " << arg1 << endl;}
template<typename T, typename... Args> void _F(const char *names, T arg1, Args... args)
{ const char *name = strchr(names, ',');cerr.write(names, name-names) << " = " << arg1 << endl;_F(name+2, args...);}

template< typename T1, typename T2 > istream& operator>>(istream& in, pair<T1, T2> &q){ in >> q.F >> q.S; return in;}
template< typename T1, typename T2 > ostream& operator<<(ostream& out, pair<T1, T2> &q){ out << q.F << " " << q.S; return out;}
template< typename T1, typename T2 > pair<T1, T2> operator+(pair<T1, T2> p1, pair<T1, T2> p2){ return {p1.F+p2.F, p1.S+p2.S};}
template< typename T1, typename T2 > pair<T1, T2> operator-(pair<T1, T2> p1, pair<T1, T2> p2){ return {p1.F-p2.F, p1.S-p2.S};}
template< typename T1, typename T2 > bool operator<(pair<T1, T2> p1, pair<T1, T2> p2){ return p1 < p2 ;}

template<typename T> void Unique(vector<T> &v) {
    sort(all(v)), v.resize(distance(v.begin(), unique(all(v))));
}


void solve() {
	int n; 
	cin >> n;
	int a[n];
	for(int i = 0; i < n; i++)
		cin >> a[i];
	string s; 
	cin >> s;
	vi basis;
	for(int i = n-1; i >= 0; i--) {
		for(auto u : basis)a[i] = min(a[i], a[i]^u);
		if(a[i] > 0) {
			if(s[i] == '0')basis.pb(a[i]);
			else {
				cout << 1 << endl;
				return;
			}
		}
	}
	cout << 0 << endl;
}

signed main(){

    ios_base::sync_with_stdio(0); 
    cin.tie(0); cout.tie(0);   
    start = clock(); 

  
    int test = 1;
    cin >> test;
    
    cout << fixed << setprecision(2);
     
    for(int i = 1; i <= test; ++i){
    	solve();
    }

    cerr << time(start);
    return 0;
}


Measured memory_bytes: 3840
#include <stdio.h>

#define NUM 100000

int main()
{
	int H[NUM], W[NUM], i = 0, j, k;
	
	while(1) {
		scanf("%d %d", &H[i], &W[i]);
		if ((H[i] == 0) && (W[i] == 0)) {
			break;
		}
		i++;
	}
	
	i = 0;
	while(1) {
		if ((H[i] == 0) && (W[i] == 0)) {
			break;
		}
		for(k = 1; k <= H[i]; k++) {
			for (j = 1; j <= W[i]; j++) {
				printf("#");
			}
			printf("\n");
		}
		i++;
		printf("\n");
	}
	
	return 0;
}

Measured memory_bytes: 584
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextLong();
        }
        Arrays.sort(a);
        long ans = 0L;
        int m, sm;
        if(n % 2 == 0){
            m = n/2;
            sm = m-1;
        }else{
            m = n/2;
            sm = Math.abs(a[m-1]-a[m]) < Math.abs(a[m+1]-a[m])
                    ? m-1 : m+1;
        }
        for (int i = 0; i < n; i++) {
            ans += Math.abs(a[m] - a[i]) * 2;
        }
        ans -= Math.abs(a[m] - a[sm]);
        System.out.println(ans);
        sc.close();

    }

}


Measured memory_bytes: 62064
#include<bits/stdc++.h>
using namespace std;
int n,k,a[1000][100];
int main(){
	k=42,n=k*(k-1)+1;
	printf("%d %d",n,k);
	for(int i=1;i<=k;++i){
		printf("\n1 ");
		for(int j=(i-1)*(k-1)+2,p=1;p<=k-1;p++,j++)
			printf("%d ",j),a[i][p-1]=j;
	}
	for(int i=0;i<k-1;++i){
		for(int j=0;j<k-1;++j){
			printf("\n%d ",i+2);
			for(int l=2,ptr=j;l<=k;l++,ptr=(ptr+i)%(k-1))
				printf("%d ",a[l][ptr]);
		}
	}
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

ll A[100010], B[100010], C[100010];
ll BC[100010];
int main()
{
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) cin >> A[i];
	for (int i = 0; i < N; i++) cin >> B[i];
	for (int i = 0; i < N; i++) cin >> C[i];
	sort(A, A + N);
	sort(B, B + N);
	sort(C, C + N);
	ll ans = 0, sum = 0;
	int j = 0;
	for (int i = 0; i < N; i++) {
		while (C[j] <= B[i]) {
			if (j == N) break;
			j++;
		}
		BC[i] = N - j;
		sum += BC[i];
	}
	j = 0;
	for (int i = 0; i < N; i++) {
		while (B[j] <= A[i]) {
			if (j == N) break;
			sum -= BC[j];
			j++;
		}
		ans += sum;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3328
import java.util.*;

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

	public Main() {
		new AOJ0244().doIt();
	}
	
	class AOJ0244{
		int[][] cost;
		int n;
		int result;
		void dikstra(int s){
			result = -1;
			int[][]memo = new int[n][2];
			for(int i=0;i<n;i++)Arrays.fill(memo[i],Integer.MAX_VALUE/2);	
			PriorityQueue<State> q = new PriorityQueue<State>();
			q.add(new State(s, 0, 1));
			memo[0][1] = 0;
			while(q.size()>0){
				State now = q.remove();
				int v = now.v;
				if(now.v==n-1){
					result = now.cost;break;
				}
				for(int i=0;i<n;i++)if(cost[v][i]>0){
					//普通に次にいく場合
					int ncost = now.cost+cost[v][i];
					if(memo[i][now.ticket] <= ncost)continue;
					memo[i][now.ticket] = ncost;
					q.add(new State(i, ncost, now.ticket));
				}
				if(now.ticket==0)continue;
				for(int i=0;i<n;i++)if(cost[v][i]>0){
					for(int k=0;k<n;k++)if(i!=k&&cost[i][k]>0){
						if(memo[k][0] <= now.cost)continue;
						memo[k][0] = now.cost;
//						System.out.println(i+" "+k);
						q.add(new State(k, now.cost, 0));
					}
				}
			}
		}
		
		int solve(int n,int m){
			this.n = n;
			cost = new int[n][n];
			for(int i=0;i<m;i++){
				int from = in.nextInt()-1;
				int to = in.nextInt()-1;
				cost[from][to] = cost[to][from] = in.nextInt();
			}
			dikstra(0);
			return result;
		}
		void doIt(){
			while(true){
				int n = in.nextInt();
				int m = in.nextInt();
				if(n+m==0)break;
				System.out.println(solve(n, m));
			}
		}
	}
	class State implements Comparable<State>{
		int v,cost,ticket;
		public State(int v,int cost,int ticket) {
			this.v = v;
			this.cost = cost;
			this.ticket = ticket;
		}
		public int compareTo(State o) {
			return this.cost-o.cost;
		}
	}
	
}

Measured memory_bytes: 31628
import itertools

n, k = map(int, input().split())
dices = map(int, input().split())
dices_EV = list(map(lambda x:(x+1)/2, dices))
dices_EV_accumulate = list(itertools.accumulate(dices_EV))
dices_EV_sums = [dices_EV_accumulate[i+k] - dices_EV_accumulate[i] for i in range(n-k)]
dices_EV_sums.append(dices_EV_accumulate[k-1])
print(max(dices_EV_sums))

Measured memory_bytes: 23616
package main

import "fmt"

func main() {
	var n, y int
	fmt.Scan(&n, &y)
	for i := 0; i <= n; i++ {
		for j := 0; i+j <= n; j++ {
			if 10000*i+5000*j+1000*(n-i-j) == y {
				fmt.Println(i, j, n-i-j)
				return
			}
		}
	}
	fmt.Println(-1, -1, -1)
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;
typedef long long ll;

int main(){
	int N;
	cin >> N;
	vector<int> A(N);
	for(int i = 0; i < N; ++i) {
		cin >> A[i];
	}
	for(int i = 0; i < N; ++i) {
		if (A[i] > i || (i > 0 && A[i] - A[i-1] > 1)) {
			cout << -1 << endl;
			return 0;
		}
	}
	ll cnt = 0;
	int P = N;
	for(int i = N-1; i >= 0; --i) {
		if(A[i] == 0) continue;
		if(A[i] == i - P + 1) continue;
		cnt += A[i];
		P = i - A[i] + 1;
	}
	cout << cnt << endl;
	return 0;
}


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

int main(void)
{
    int d;
    while (cin >> d) {
        int sum = 0;
        for (int i = 0; i < 600 / d; ++i)
            sum += d*d*d*i*i;
        cout << sum << endl;
    }
    return 0;
}






Measured memory_bytes: 3092
#include <algorithm>
#include <queue>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <set>
#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

using namespace std;

int main(){
  const int n = getInt();
  const int m = getInt();

  set<int> s;
  vector<int> v(n);

  REP(i,n) v[i] = getInt();
  reverse(v.begin(), v.end());

  for(int i = 0; i < n; i++){
    if((int) s.size() < m && s.count(v[i]) == 0){
      printf("%d\n", v[i]);
      s.insert(v[i]);
    }
  }

  return 0;
}

Measured memory_bytes: 3908
#include<iostream>
#include<string>
#include<vector>

using namespace std;

string convert(string s)
{
	for(int i = 0; s[i] != '\0'; i++)
	{
		if(s[i] >= 'A' && s[i] <= 'Z')
		{
			s[i] = 'a' + (s[i] - 'A');
		}
		
		else if(s[i] == '.')
		{
			s.erase(s.begin() + i);
		}
		
	}
	return s;
}

int main()
{
	string word = "";
	int count = 0;
	
	cin >> word;
	word = convert(word);
	while(true)
	{
		string check = "";
		cin >> check;
		
		if(check == "END_OF_TEXT")
		{
			break;
		}

		check = convert(check);

		if(check == word)
		{
			count += 1;
		}
	}

	cout << count << endl;
}



Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()
#define let auto const

vector<i64> grn(101010, -1);

i64 N, K;
vector<i64> a;
i64 grundy(i64 k) {
  if(grn[k] != -1) return grn[k];
  set<i64> st;
  for(auto x: a) {
    if(k - x >= 0) st.insert(grundy(k - x));
  }
  for(int i = 0;i <= K + 1;i++) {
    if(!st.count(i)) return i;
  }
  return K + 1;
}

int main() {
  cin >> N >> K;
  a.resize(N);
  for(int i = 0;i < N;i++) cin >> a[i];
  for(i64 k = 0;k <= K;k++) {
    set<i64> st;
    for(auto x: a) {
      if(k - x >= 0) st.insert(grn[k - x]);
    }
    grn[k] = K + 1;
    for(int i = 0;i <= K + 1;i++) {
      if(!st.count(i)) {
        grn[k] = i;
        break;
      }
    }
  }
  if(grundy(K)) {
    cout << "First" << endl;
  }
  else {
    cout << "Second" << endl;
  }
}


Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

typedef unsigned long long ull;

struct Item {
  int v;
  int w;
  char t;
  ull d;
  char s[25];
};

bool comp(const Item x, const Item y) {
  if (x.v < y.v) return true;
  else if (x.v == y.v) {
    if (x.w < y.w) return true;
    else if (x.w == y.w) {
      if (x.t < y.t) return true;
      else if (x.t == y.t) {
        if (x.d < y.d) return true;
        else if (x.d == y.d) {
          if (strcmp(x.s,y.s) < 0) return true;
        }
      }
    }
  }
  return false;
}

int main() {
  int N;
  Item items[100100];

  scanf("%d",&N);
  for (int i = 0; i < N; ++i) {
    scanf("%d %d %c %llu %s",
          &items[i].v,&items[i].w,&items[i].t,&items[i].d,&items[i].s);
  }

  sort(items,items + N, comp);

  for (int i = 0; i < N; ++i) {
    printf("%d %d %c %llu %s\n",
           items[i].v,items[i].w,items[i].t,items[i].d,items[i].s);
  }

  return 0;
}




Measured memory_bytes: 8252
fn main() -> Result<(), Box<dyn std::error::Error>> {
    let n: i32 = read_line().parse()?;
    let rem = n % 1000;
    let ans = if rem > 0 {
        1000 - rem
    } else {
        0
    };
    println!("{}", ans);
    Ok(())
}

fn read_line() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string()
}


Measured memory_bytes: 2104
fn s(n: i64) -> i64 {
    if n == 0 {
        0
    } else {
        n%10 + s(n/10)
    }
}

fn g(n: i64) -> f64 {
    n as f64 / s(n) as f64
}


fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let k: usize = sc.read();

    let mut x: i64 = 0;

    for _ in 0..k {
        x += 1;
        let mut pow = 1;
        while pow < x {
            while g(x + pow) < g(x) {
                x += pow;
            }
            pow *= 10;
        }
        println!("{}", x);
    }
}

// thanks, ir5
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}


Measured memory_bytes: 4352
import bisect
def put(a,b):
    l=max(len(a),len(b))
    a="0"*l+a
    b="0"*l+b
    s=""
    for i in range(-1,-l-1,-1):
        s+=a[i]+b[i]
    s=s[-1::-1]
    ind=s.find("1")
    print(s[ind:])

def quad(i):
    s=""
    while i>0:
        s+=str(i%4)
        i//=4
    return s[-1::-1]

l=[0,1]
for i in range(1,18):
    l+=[4**i+j for j in l]

n=int(input())
if n==0:
    print(0)
else:
    for i in range(len(l)):
        if (n-l[i])%2==0:
            ind=bisect.bisect_left(l,(l[i]-n)//2)
            if l[i]-2*l[ind]==n:
                put(quad(l[i]),quad(l[ind]))
                break


Measured memory_bytes: 58224
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
a = [list(map(int, input().split())) for _ in range (n)]
ans = 0

for i in range(n):
    calc = 0
    for j in range(m):
        calc += a[i][j]*b[j]
    if calc + c > 0:
        ans += 1

print(ans)

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
using ll=long long;
#define print(n) cout<<n<<endl
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vi vector<int>
#define vvl vector<vector<ll>>
#define vvi vector<vector<int>>
const int M=200111;
const int inf=1000000007;
const int MOD=1000000007;
const double PI = 3.1415926535897932384626433;
const long long INF=1e18;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
int ddx[8]={1,-1,0,0,1,-1,-1,1},ddy[8]={0,0,1,-1,1,-1,1,-1};


struct UnionFind {
	vector<int> par;
	UnionFind(int n) : par(n, -1) { }

	int root(int x) {
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool same(int x, int y) {
		return root(x) == root(y);
	}

	bool merge(int x, int y) {
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y); // merge technique
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x) {
		return -par[root(x)];
	}
};

vvl comb(int n) {
	vvl v(n + 1,vl(n + 1, 0));
	for (int i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (int j = 1; j < v.size(); j++) {
		for (int k = 1; k < j; k++) {
			v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
		}
	}
	return v;
}

void sosu(ll x,bool f[]){
	ll y=x;
	for(ll i=2;i<=sqrt(y);i++){
		if(x%i==0){
			x/=i;
			f[i]=true;
			i--;
		}
	}
}

ll __gcd(ll x,ll y){
	if(x<y)swap(x,y);
	while(1){
		ll tmp=x%y;
		x=y;
		y=tmp;
		if(y==0)break;
	}
	return x;
}

int keta(ll a){
	int ke=1;
	while(a/=10)ke++;
	return ke;
}

vector<long long> enum_divisors(long long N) {
	vector<long long> res;
	for (long long i = 1; i * i <= N; ++i) {
		if (N % i == 0) {
			res.push_back(i);
			// 重複しないならば i の相方である N/i も push
			if (N/i != i) res.push_back(N/i);
		}
	}
	// 小さい順に並び替える
	sort(res.begin(), res.end());
	return res;
}

ll zyou(ll x,ll n){
	ll y=1;
	rep(i,0,n){
		y*=x;
	}
	return y;
}

int main() {
	int a,b;
	cin>>a>>b;
	if(a+b>=10)print("error");
	else print(a+b);

}


Measured memory_bytes: 256
// writed 2020/03/25
// bit全探索
import java.util.Scanner;
class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String num = scanner.next();
        scanner.close();
        String[] numString = num.split("");
        int[] numInt = new int[4];
        for(int x=0;x<numString.length;x++) {
            numInt[x] = Integer.parseInt(numString[x]);
        }        
        int opnum = 3;

        for(int i=0;i<(1<<opnum);i++) {
            int sum = numInt[0];
            int count = 0;
            StringBuilder sb = new StringBuilder(num);
            for(int j=0;j<opnum;j++) {
                if((1&i>>j) == 1) {
                    sum += numInt[j+1];
                    sb.insert(j+1+count, "+");
                    count++;
                }else {
                    sum -= numInt[j+1];
                    sb.insert(j+1+count, "-");
                    count++;
                }
            }
            if(sum==7) {
                System.out.println(sb.toString() + "=7");
                return;
            }
        }
    }
}

Measured memory_bytes: 22864