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

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 998244353;
struct mint
{
    ll x; // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint &operator+=(const mint a)
    {
        if ((x += a.x) >= mod)
            x -= mod;
        return *this;
    }
    mint &operator-=(const mint a)
    {
        if ((x += mod - a.x) >= mod)
            x -= mod;
        return *this;
    }
    mint &operator*=(const mint a)
    {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const
    {
        if (!t)
            return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1)
            a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint &operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination
{
    vector<mint> fact, ifact;
    combination(int n) : fact(n + 1), ifact(n + 1)
    {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i)
            fact[i] = fact[i - 1] * i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i)
            ifact[i - 1] = ifact[i] * i;
    }
    mint operator()(int n, int k)
    {
        if (k < 0 || k > n)
            return 0;
        return fact[n] * ifact[k] * ifact[n - k];
    }
} c(200005);

int main()
{
    int n, m, k;
    cin >> n >> m >> k;
    mint ans = 0;
    mint col = m;
    for (int x = n - 1; x >= 0; x--)
    {
        mint now = col;
        now *= c(n - 1, x);
        if (x <= k)
            ans += now;
        col *= m - 1;
    }
    cout << ans << endl;
    return 0;
}


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

int main()
{
    int n;
    cin >> n;
    int a[n+2] = {0};
    int s = 0;
    for(int i = 1; i < n + 1; i++){
        cin >> a[i];
        s += abs(a[i] - a[i-1]);
    }

    s += abs(a[n+1] - a[n]);

    for(int i = 0; i < n; i++){
        int ans = 0;
        ans = s + abs(a[i] - a[i+2]) - abs(a[i+1] - a[i]) - abs(a[i+2] - a[i+1]);
        cout << ans << endl;   
    }
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int sum=0;
	for(int i=1;i<=n;i++)
	{
		if(i%2==1) sum++;
	}
	double ans;
	ans=sum*1.0/n;
	printf("%.10lf",ans);
	return 0;
}


Measured memory_bytes: 256
//                          VIVEK UPADHYAY
//                          MANIT, BHOPAL(M.P)
/**********************************************************************************************/
/**********************************************************************************************/
//                        $$ JAB-TAK TODEGA NHI,
//                           TAB -TAK CHODEGA NHI :D

// g++ -std=c++11 file_name.cpp
// ./file_name.out
#include<iostream>
#include<algorithm>
#include<vector>
#include<list>
#include<cstdlib>
#include<unistd.h>
#include<string>
#include<cstring>
#include<stack>
#include<queue>
#include<utility>
#include<cmath>
#include<set>
#include<unordered_map>
#include<cstdio>
#include<map>
#include<numeric>
using namespace std;
#define F first
#define S second
#define mk(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define LINE cout<<"\n" ;
#define ok cout<<"ok\n" ;
#define dbg(x) cout<<#x<<" = "<<(x)<<"\n";
#define fill(A, VAL) memset(A, VAL, sizeof(A))
#define sz(a) ((int) a.size())
typedef long long ll ;
const int MAXN = 5*1e5 + 10;
int main () {
    int N , M ;
    cin >> N >> M ;
    vector<int> a[M] ;
    for(int i = 0 ; i < M ;i++)
    {
        int K ;
        cin >> K ;
        for(int j = 0 ; j < K ;j++)
        {
            int x ;
            cin >> x;
            a[i].pb(x) ;
        }
    }
    int p[M] ;
    for(int i =0 ; i < M ;i++) cin >> p[i] ;
    int cnt =0 ;
    for(int mask = 0 ; mask < (1<<N) ;mask+=1){
        bool flag = true ;
        for(int j = 0 ; j < M ;j++){
            int c =0 ;
            for(int k = 0 ; k < sz(a[j]);k++)
                if((mask&(1<<(a[j][k] - 1)))) {
                    c++ ;
                }
            if(c%2 != p[j]) {
                flag = false ;
                break ;
            }
        }
        if(flag) cnt++ ;
    }
    cout<<cnt<<endl;;
    return 0 ;
}


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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

int main()
{

    lint a, b;
    cin >> a >> b;

    if ((a+b)%2!=0){
        cout << "IMPOSSIBLE"
             << "\n";
    }else{
        cout << (a+b)/2 << "\n";
    }

    return 0;
}

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

int main()
{
    int W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;

    if ( x < r || W < x + r ) {
        cout << "No\n";
    } else if (y < r || H < y + r) {
        cout << "No\n";
        
    } else {
        cout << "Yes\n";
    }

    return 0;
}


Measured memory_bytes: 3096
#include <stdio.h>

int main(void){
    
    int m, f, r;
    
    while (1) {
		scanf("%d%d%d", &m, &f, &r);
		if (m == -1 && f == -1 && r == -1) {
			break;
		}
		else if (m == -1|| f == -1) {
			printf("F\n");
		}
		else if (m + f >= 80) {
			printf("A\n");
		}
		else if (m + f >= 65 && m + f<80) {
			printf("B\n");
		}else if (m + f >= 50 && m + f<65) {
					printf("C\n");
				}

		
		else if ( m + f >= 30 && m + f<50) {
			if (r >= 50) {
				printf("C\n");
			}
			else {
				printf("D\n");
			}
		}
		else printf("F\n");

	}
    
    
    return 0;
}


Measured memory_bytes: 2108
n, q = gets.split.map(&:to_i)

a = gets.split.map(&:to_i)
x = gets.split.map(&:to_i)

x.each{|xi|
  sum = 0
  ans = 0
  l = 0
  n.times{|r|
    sum += a[r]
    while sum > xi
      sum -= a[l]
      l += 1
    end
    ans += (r-l+1)
  }
  p ans
}

Measured memory_bytes: 14692
#![allow(unused_imports)]
#![allow(unused_variables)]

use itertools::Itertools;
use proconio::{fastout, input};
use std::collections::HashMap;

#[fastout]
fn main() {
    input! {
        n: usize,
        ss: [String; n],
    }
    // annotate for rust-analyzer
    let ss: Vec<String> = ss;

    let mut map = HashMap::new();
    for s in ss {
        *map.entry(s).or_insert(0) += 1;
    }
    for k in vec!["AC", "WA", "TLE", "RE"] {
        let v = match map.get(k) {
            Some(&i) => i,
            None => 0,
        };
        println!("{} x {}", k, v);
    }
}


Measured memory_bytes: 7840
# -*- coding: utf-8 -*-
"""
Created on Tue Feb 12 15:50:41 2019

@author: shinjisu
"""

#import numpy as np
#import math
def getInt(): return int(input())
def getIntList(): return [int(x) for x in input().split()]

def zeros(n): return [0]*n
def zeros2(n, m): return [zeros(m)]*n # obsoleted zeros((n, m))で代替

def getIntLines(n): return [int(input()) for i in range(n)]

def getIntMat(n, m):  # n行に渡って、1行にm個の整数
    mat = zeros2(n, m)
    for i in range(n):
        mat[i] = getIntList()
    return mat


ALPHABET = [chr(i+ord('a')) for i in range(26)]
DIGIT = [chr(i+ord('0')) for i in range(10)]
N1097 = 10**9 + 7
INF = 10**18


class Debug():
    def __init__(self):
        self.debug = True

    def off(self):
        self.debug = False

    def dmp(self, x, cmt=''):
        if self.debug:
            if cmt != '':
                print(cmt, ':  ', end='')
            print(x)
        return x


def prob():
    d = Debug()
    d.off()
    N = getInt()
    A = getIntList()
    d.dmp(A)
    magicCount = 0
    i = 0
    while i < N-1:
        cont = 1
        while A[i] == A[i+cont]:
            cont += 1
            if i+cont == N:
                break
        d.dmp(cont,'cont')
        magicCount += cont//2
        d.dmp(magicCount,'magicCount')
        i += cont
    return magicCount


ans = prob()
if ans is None:
    pass
else:
    print(ans)
#elif ans[0] == 'col':
#    for elm in ans[1]:
#        print(elm)


Measured memory_bytes: 3064
n, m = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse=True)
a_rev = a[::-1]

ok, ng = 1, 200001
while ng-ok > 1:
	x = (ok+ng)//2
	num = 0
	cur = 0
	for i in range(n-1, -1, -1):
		while cur < n and a[i] + a[cur] >= x:
			cur += 1
		num += cur
	if num < m:
		ng = x
	else:
		ok = x
just = ok

ans = 0
larger_cnt = 0
cur = 0

a_cum = [0]
for i in range(n):
	a_cum.append(a_cum[-1] + a[i])

for i in range(n):
	while cur < n and a[i] + a_rev[cur] <= just:
		cur += 1
	larger_cnt += n - cur
	ans += (n - cur) * a[i] + a_cum[n - cur]

ans += just * (m - larger_cnt)
print(ans)

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

int main() {
  string S;
  cin >> S;
  S.push_back('#');
  int w = 0, b = 0;
  char c = S[0];
  rep(i, S.size()) {
    if (S[i] != c) {
      if (c == 'W')
        w++;
      else
        b++;
      c = S[i];
    }
  }
  cout << w + b - 1 << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define rep(i, j, k) for (auto i = j; i < k; i++)
#define rrep(i, j, k) for (auto i = j; i > k; i--)
using namespace std;

void solve(int &n, int &m, int &l, int &k, int &a, int &h) {
  bool save[101];
  vector<pair<int, int>> v[101];
  fill(save, save + 100, false);
  rep(i, 0, l) {
    int b; cin >> b; save[b] = true;
  }
  rep(i, 0, k) {
    int from, to, cost; cin >> from >> to >> cost;
    v[from].push_back({to, cost});
    v[to].push_back({from, cost});
  }
  int d[101][101];
  rep(i, 0, 101) rep(j, 0, 101) d[i][j] = INT_MAX;
  d[a][m] = 0;
  priority_queue<tuple<int, int, int>> q;
  q.push(make_tuple(0, a, m));
  while (!q.empty()) {
    int cost, now, nokori; tie(cost, now, nokori) = q.top(); q.pop();
    cost *= -1;
    if (d[now][nokori] < cost) continue;
    if (save[now] && nokori != m && d[now][nokori + 1] > d[now][nokori] + 1) {
      d[now][nokori + 1] = cost + 1;
      q.push(make_tuple(-d[now][nokori + 1], now, nokori + 1));
    }
    rep(i, 0, (int)v[now].size()) {
      int next = v[now][i].fi, nextc = v[now][i].se;
      if (nokori - nextc >= 0 && d[next][nokori - nextc] > d[now][nokori] + nextc) {
        d[next][nokori - nextc] = d[now][nokori] + nextc;
        q.push(make_tuple(-d[next][nokori - nextc], next, nokori - nextc));
      }
    }
  }
  int _min = INT_MAX;
  rep(i, 0, 101) _min = min(_min, d[h][i]);
  if (_min == INT_MAX) {
    cout << "Help!" << endl;
  } else {
    cout << _min << endl;
  }
}

int main() {
  int n, m, l, k, a, h;
  while (cin >> n >> m >> l >> k >> a >> h) {
    if (n == 0 && m == 0 && l == 0 && k == 0 && a == 0 && h == 0) break;
    solve(n, m, l, k, a, h);
  }
}

//////////////////////////////////////////////////////////////////////////
//NOTE
//////////////////////////////////////////////////////////////////////////
// 典型的拡張dijkstra
// 拡張dijkstraとはdijkstraをなんかすごいことさせたわけではなく、
// 拡張グラフに対して、dijkstra法を適用したという意味.
// だから、最短距離を保管する配列が1次元から2次元配列になっていたりする.
// d[i][j] := 残り時間j分の状態でi町にいるための、最短時間.
// 個人的に拡張dijkstraの問題を自分で解くのは初めてだけど、問題見たら拡張dijkstraだと
// わかったし、実装も大したことないので良い実装練習になった.
// 感想
// 面白かった.
// ローカル配列は初期化を忘れるなよ!!(忘れてWAをくらった)


Measured memory_bytes: 3164
int main() {
	int a, b;
	char op;
	while (1) {
		scanf("%d %c %d",&a, &op ,&b);
		if (op == '?') {
			break;
		}
		if (op == '+' ) {
			printf("%d\n", a + b);
		}
		if (op == '-') {
			printf("%d\n", a - b);
		}
		if (op == '*') {
			printf("%d\n", a * b);
		}
		if (op == '/') {
			printf("%d\n", a / b);
		}
	}
}


Measured memory_bytes: 2116
list = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
n = int(input())

print(list[n-1])

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

int main(){
    string S;
    string ans;
    int first, last;

    cin >> S;
    first = stoi(S)/100;
    last = stoi(S) - first*100;

    if(1 <= first && first <= 12){
        if(1<= last && last <= 12){
            ans = "AMBIGUOUS";
        }
        else{
            ans = "MMYY";
        }
    }
    else{
        if(1 <= last && last <= 12){
            ans = "YYMM";
        }
        else{
            ans = "NA";
        }
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
//#include "library/debug.cpp"

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<ll> wa(n + 1);
    vector<bool> ac(n + 1);
    rep(i, 0, m) {
        ll p;
        string s;
        cin >> p >> s;
        if (s == "AC") {
            ac[p] = true;
        } else {
            if (ac[p] == false) {
                wa[p]++;
            }
        }
    }
    ll ansa = 0, answ = 0;
    rep(i, 1, n + 1) if (ac[i]) {
        ansa++;
        answ += wa[i];
    }
    cout << ansa << ' ' << answ << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using boost::multiprecision::cpp_int;

typedef long long ll;
typedef pair<ll, ll> pll;

const ll INF = 1e17;
const ll MOD = 1e9+7;

// https://math.nakaken88.com/textbook/cp-binary-exponentiation-and-recursive-function/
ll modPow(long long a, long long n) {
  if (n == 1) return a % MOD;
  if (n % 2 == 1) return (a * modPow(a, n - 1)) % MOD;
  long long t = modPow(a, n / 2);
  return (t * t) % MOD;
}

ll comb(ll n, ll p) {
	if (p * 2 > n) p = n - p;
	if (p > n - p) p = n - p;
	ll a = 1, b = 1;
	for(int i=1; i< p+1; i++) {
		a = (a * (n - i + 1)) % MOD;
		b = (b * i) % MOD;
	}
	return a * (modPow(b, MOD - 2)) % MOD;
}

// https://gist.github.com/ww24/5517384
int gcdf(int a, int b)
{
    if (a < b) {
        a ^= b;
        b ^= a;
        a ^= b;
    }
    
    return b ? gcd(b, a % b) : a;
}

int main() {
    // input, ready
    int N;
    string S;
    cin >> N >> S;
    vector<bool> Rvecb(4001);
    vector<bool> Gvecb(4001);
    vector<bool> Bvecb(4001);

    vector<int> Rveci(4001);
    vector<int> Gveci(4001);
    vector<int> Bveci(4001);    

    int cnt = 1;
    for (auto s : S) {
        if (s == 'R') Rvecb[cnt] = true;
        else Rvecb[cnt] = false;
        if (s == 'G') Gvecb[cnt] = true;
        else Gvecb[cnt] = false;
        if (s == 'B') Bvecb[cnt] = true;
        else Bvecb[cnt] = false;
        cnt++;
    }

    int rcnt = 0;
    int gcnt = 0;
    int bcnt = 0;
    for (int i=N; i>=1; i--) {
        char s = S[i-1];
        if (s == 'R') rcnt++;
        if (s == 'G') gcnt++;
        if (s == 'B') bcnt++; 
        Rveci[i] = rcnt;
        Gveci[i] = gcnt;
        Bveci[i] = bcnt;                     
    }

    ll ans = 0;
    for (int i=1; i<=N; i++) {
        if (Rvecb[i]) {
            for (int j=1; j<=N; j++) {
                if (Gvecb[j]) {
                    int min_i = min(i,j);
                    int max_j = max(i,j);
                    ans+=bcnt;
                    if (max_j +(max_j-min_i) <=N && Bvecb[max_j +(max_j-min_i)]) ans--;
                    if (min_i - (max_j-min_i) >=1 && Bvecb[min_i - (max_j-min_i)]) ans--;
                    if ((max_j+min_i)%2==0 && Bvecb[(max_j+min_i)/2]) ans--;
                }
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3688
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

int a, b;

int main(){
	//IO("input.txt", "output.txt");
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> a >> b;
	if(a == 1) a = 14;
	if(b == 1) b = 14;
	if(a == b) cout << "Draw\n";
	else cout << ((a > b) ? "Alice\n" : "Bob\n");
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
M = int(input())
d = 0
c = 0
for _ in range(M):
    c1, d1 = map(int, input().split())
    d += d1
    c += c1 * d1

if c % 9 != 0:
    s = c // 9
else:
    s = c // 9 - 1

print((d - 1) + s)     

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

void bubbleSort(int* A,int N){
    int flag=1,j,tmp,count=0;
    while(flag){
        flag = 0;
        for(j=N-1;j>0;j--){
            if(A[j]<A[j-1]){
                tmp = A[j];
                A[j] = A[j-1];
                A[j-1] = tmp;
                count++;
                flag = 1;
            }
        }
    }
    for(j=0;j<N;j++){
        cout << A[j];
        if(j!=N-1){
            cout << " ";
        }
    }
    cout << endl << count << endl;
}

int main(){
    int N,*A,i;
    cin >> N;
    A = new int[N];
    for(i=0;i<N;i++){
        cin >> A[i];
    }
    bubbleSort(A,N);
    return 0;
}


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

ll l, a, b, mod;

template <class T> struct Matrix {
    vector<vector<T>> A;
    Matrix(int n, int m) : A(n, vector<T>(m)) {}
    Matrix(int n) : A(n, vector<T>(n)) {}
    int size() {
        return A.size();
    }
    inline vector<T> &operator[](int i) {
        return A[i];
    }
};

template <class T> Matrix<T> operator*(Matrix<T> A, Matrix<T> B) {
    Matrix<T> R(A.size(), B[0].size());
    for (int i = 0; i < A.size(); ++i)
        for (int j = 0; j < B[0].size(); ++j)
            for (int k = 0; k < B.size(); ++k)
                R[i][j] = (R[i][j] + (A[i][k] * B[k][j]) % mod) % mod;
    return R;
}

template <class T> Matrix<T> power(Matrix<T> X, ll n) {
    Matrix<T> R(X.size());
    for (int i = 0; i < X.size(); i++)
        R[i][i] = 1;
    while (n > 0) {
        if (n & 1)
            R = R * X;
        X = X * X;
        n >>= 1;
    }
    return R;
}

template <class T> void print(Matrix<T> A) {
    for (int i = 0; i < A.size(); ++i)
        for (int j = 0; j < A[0].size(); ++j)
            cout << A[i][j] << ((j != A[0].size() - 1) ? ' ' : '\n');
}

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

    cin >> l >> a >> b >> mod;
    Matrix<ll> z(1, 3);
    z[0][1] = a % mod;
    z[0][2] = 1;
    vector<ll> c(19);
    ll mn = 1, mx = 10;
    rep(i, 1, 19) {
        c[i] = min(l, (mx - a + b - 1) / b) - max(0ll, (mn - a + b - 1) / b);
        mn *= 10ll;
        mx *= 10ll;
    }

    mx = 1;
    rep(i, 1, 19) {
        mx *= 10ll;
        if (c[i] > 0) {

            Matrix<ll> p(3);
            p[1][0] = p[1][1] = p[2][2] = 1;
            p[0][0] = mx % mod;
            p[2][1] = b % mod;
            z = z * power(p, c[i]);
        }
    }
    cout << z[0][0] << endl;

    return 0;
}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

G = []

def dfs(n, string, next_usable):
    if n == 0:
        G.append(string)
        return
    for char in next_usable:
        new_string = string + char
        if char == next_usable[-1]:
            added_char = chr(ord(char) + 1)
            next_usable += added_char
        dfs(n-1, new_string, next_usable)

def main():
    N = I()
    string = 'a'
    dfs(N, '', 'a')
    for string in G:
        print(string)


main()



Measured memory_bytes: 15188
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main() {
	int K,S;
	cin>>K>>S;
	int X,Y,Z;
	int ans=0;
	for(int i=0; i<=K; i++){
		for(int j=0; j<=K; j++){
			if(((S-i-j)>=0)&&((S-i-j)<=K)){
				ans++;
			}
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
/*
lakshaygpt28
Lakshay Gupta
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using pll = pair < ll, ll >;
using vll = vector < ll >;

template < typename T > using OrderedSet = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;


#ifndef ONLINE_JUDGE
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
    cerr << name << " : " << arg1 << std :: endl;
}
template < typename Arg1, typename... Args >
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | ";
    __f(comma + 1, args...);
}
#else
#define debug(...)
#endif

#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define eb emplace_back
#define mp make_pair
#define pb push_back
#define mt make_tuple
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

const db PI = acos(-1);
const ll LINF = LLONG_MAX;
const int INF = INT_MAX, MOD = 1e9 + 7, N = 1e5 + 10;

ll a[N];

int main() {
    fast_io();
    ll n;
    cin >> n;
    for (ll i = 1; i <= n; i++) {
        cin >> a[i];
    }
    ll ans = 0;
    for (ll i = 2; i < n; i++) {
        vll v;
        v = {a[i - 1], a[i], a[i + 1]};
        sort(all(v));
        if (v[1] == a[i]) {
            ans++;
        }
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {
	
	public static String decipher(String s, int n) {
		char[] cs = s.toCharArray();
		for (int i = 0; i < s.length(); i++) {
			if ('a' <= cs[i] && cs[i] <= 'z') {
				int c = (int)cs[i] + n;
				if (c > (int)'z') {
					c = c - (int)'z' + (int)'a' - 1;
				}
				cs[i] = (char)c;
			}
		}
		return String.valueOf(cs);
	}
	
	public static Boolean check(String s) {
		if (s.indexOf("the") != -1) return true;
		if (s.indexOf("this") != -1) return true;
		if (s.indexOf("that") != -1) return true;
		return false;
	}

	public static void main(String[] args) throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String input;
		while((input = reader.readLine()) != null){
			for (int i = 0; i < 26; i++) {
				String s = decipher(input, i);
				if (check(s)) {
					System.out.println(s);
					break;
				}
			}
		}
	}

}

Measured memory_bytes: 16884
#include<bits/stdc++.h>
using namespace std;
struct val
{
	int v,id,type;
	bool operator<(const val &b)const{return v<b.v;}
	void read(int ID,int op){scanf("%d",&v);id=ID;type=op;}
}a[300001];
int n,vis[300001];
int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)a[i].read(i,1),a[i+n].read(i,-1);
	sort(a,a+2*n);
	long long ans=0;
	int x=0,y=0;
	for(int i=0;i<n;i++)
	{
		if(i&&a[i].type*a[i-1].type<0)y=1;
		if(vis[a[i].id])x=1;
		ans+=a[i].v;
		vis[a[i].id]=1;
	}
	if(x||!y)printf("%lld\n",ans);
	else printf("%lld\n",a[n-1].id==a[n].id?ans+min(a[n].v-a[n-2].v,a[n+1].v-a[n-1].v):ans-a[n-1].v+a[n].v);
}


Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define ff first
#define ss second
#define file_se_input  freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define pp long long int
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define pb push_back
#define mp make_pair
#define pi 3.141592653589793238
#define eb emplace_back
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define zip(i,a,b) for(int i=a;i<b;i++)
#define ll unsigned long long int
#define test long int t;cin>>t; while(t--)
#define um unordered_map
#define en '\n'
#define us unordered_set
#define mm 1000000007

bool check_prime(long long n)
{
	int flag = 0;
	for (long long i = 2; i * i <= n; i++)
	{
		if (n % i == 0)
		{
			flag = 1;
			break;
		}
	}
	if (n == 1)
		return false;
	else if (flag == 0 || n == 2 || n == 3)
	{
		return true;
	}
	else
	{
		return false;
	}

}

int binaryExponentiation(int x, int n) //function to calculate x raise to power n
{
	int result = 1;
	while (n > 0)
	{
		if (n % 2 == 1)
			result = result * x;
		x = x * x;
		n = n / 2;
	}
	return result;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	if (fopen("input.txt", "r"))
	{
		freopen ("input.txt" , "r" , stdin);
		freopen ("output.txt" , "w" , stdout);
	}
#endif
	//_______________________________-code starts-______________________________________________________________________________

	ll k;
	cin >> k;
	queue<ll>q;
	rep(i, 1, 9)
	{
		q.push(i);
	}
	ll x;
	while (k--)
	{
		x = q.front();
		q.pop();
		if (x % 10)
		{
			q.push(10 * x + x % 10 - 1);
		}
		q.push(10 * x + x % 10);
		if (x % 10 != 9)
		{
			q.push(10 * x + x % 10 + 1);
		}
	}
	cout << x << en;
	return 0;
}


Measured memory_bytes: 1792
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
#from numba import jit

INF = 1 << 50
EPS = 1e-8


def run():
    S = input()
    T = input()
    ans = INF
    for i in range(len(S) - len(T) + 1):
        part = S[i:i+len(T)]
        count = 0
        for a,b in zip(T, part):
            if a != b:
                count += 1
        ans = min(ans, count)
    print(ans)


if __name__ == "__main__":
    run()

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

#from collections import defaultdict
#from heapq import heappush, heappop
import sys
import numpy as np

sys.setrecursionlimit(10**6)
input = sys.stdin.buffer.readline
INF = 10 ** 9 + 1  # sys.maxsize # float("inf")
MOD = 10 ** 9 + 7


def debug(*x):
    print(*x, file=sys.stderr)


def solve(N, K, X):
    def modmul(x, y):
        ret = np.zeros(x.shape, np.int64)
        for i in range(N):
            for j in range(N):
                v = x[i, :] * y[:, j]
                v %= MOD
                ret[i, j] = v.sum() % MOD
        return ret

    powK = np.eye(N, dtype=np.int64)
    while K:
        if K & 1:
            powK = modmul(powK, X)
        X = modmul(X, X)
        K //= 2
    return powK.sum() % MOD


def main():
    # parse input
    N, K = map(int, input().split())
    X = np.int64(read().split())
    X = X.reshape((N, N))
    print(solve(N, K, X))


# tests
T1 = """
4 2
0 1 0 0
0 0 1 1
0 0 0 1
1 0 0 0
"""


def test_T1():
    """
    >>> as_input(T1)
    >>> main()
    6
    """


T2 = """
3 3
0 1 0
1 0 1
0 0 0
"""


def test_T2():
    """
    >>> as_input(T2)
    >>> main()
    3
    """


T3 = """
6 2
0 0 0 0 0 0
0 0 1 0 0 0
0 0 0 0 0 0
0 0 0 0 1 0
0 0 0 0 0 1
0 0 0 0 0 0
"""


def test_T3():
    """
    >>> as_input(T3)
    >>> main()
    1
    """


T4 = """
1 1
0
"""


def test_T4():
    """
    >>> as_input(T4)
    >>> main()
    0
    """


T5 = """
10 1000000000000000000
0 0 1 1 0 0 0 1 1 0
0 0 0 0 0 1 1 1 0 0
0 1 0 0 0 1 0 1 0 1
1 1 1 0 1 1 0 1 1 0
0 1 1 1 0 1 0 1 1 1
0 0 0 1 0 0 1 0 1 0
0 0 0 1 1 0 0 1 0 1
1 0 0 0 1 0 1 0 0 0
0 0 0 0 0 1 0 0 0 0
1 0 1 1 1 0 1 1 1 0
"""


def test_T5():
    """
    >>> as_input(T5)
    >>> main()
    957538352
    """
# add tests above


def _test():
    import doctest
    doctest.testmod()


def as_input(s):
    "use in test, use given string as input file"
    import io
    global read, input
    f = io.StringIO(s.strip())

    def input():
        return bytes(f.readline(), "ascii")

    def read():
        return bytes(f.read(), "ascii")


USE_NUMBA = False
if (USE_NUMBA and sys.argv[-1] == 'ONLINE_JUDGE') or sys.argv[-1] == '-c':
    print("compiling")
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('solve', solve.__doc__.strip().split()[0])(solve)
    cc.compile()
    exit()
else:
    input = sys.stdin.buffer.readline
    read = sys.stdin.buffer.read

    if (USE_NUMBA and sys.argv[-1] != '-p') or sys.argv[-1] == "--numba":
        # -p: pure python mode
        # if not -p, import compiled module
        from my_module import solve  # pylint: disable=all
    elif sys.argv[-1] == "-t":
        print("testing")
        _test()
        sys.exit()
    elif sys.argv[-1] != '-p' and len(sys.argv) == 2:
        # input given as file
        input_as_file = open(sys.argv[1])
        input = input_as_file.buffer.readline
        read = input_as_file.buffer.read

    main()


Measured memory_bytes: 27320
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>
#include<stack>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<string> vstring;
typedef vector<pint> vpint;

struct Edge{int to,from,cost;};

#ifdef DEBUG
#define debug cout
#else
stringstream __ss__;
#define debug __ss__
#endif

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) debug << *i << " "; debug << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

#define rep(i,n) for(int i=0;i<(n);++i)
#define repd(i,n) for(int i=(n)-1;i>=0;i--)
#define repn(i,m,n) for(int i=(m);i<=(n);++i)
#define repnd(i,m,n) for(int i=(n)-1;i>=(m);i--)
#define rep0(i,n) for(i=0;i<(n);++i)
#define all(n) n.begin(),n.end()
#define sz(n) ((int)(n).size())
#define IL for(;;)
#define MP make_pair
#define PB push_back
#define SS stringstream
#define X second
#define Y first
#define PUTLINE debug<<"LINE:"<<__LINE__<<endl;

const int INF = 2147483647/3;
const double EPS = 1e-10;
const double PI = acos(-1.0);

const int dx[]={1,-1,0,0,1,-1,1,-1,0};
const int dy[]={0,0,1,-1,1,-1,-1,1,0};

vpint a;

int main() {
	Int n,m;
	IL{
		cin>>n;
		if(n==0)break;
		if(n==1){
			cout<<1<<endl;
			continue;
		}
		m=n;
		a.clear();
		Int i;
		for(i=2;i*i<=n;i=(i==2)?3:i+2){
			if(n%i==0){
				int c=0;
				while(m%i==0){
					m/=i;
					++c;
				}
				a.PB(MP((int)i,c));
			}
		}
		if(m==n){
			cout<<2<<endl;
			continue;
		}
		if(m>1){
			a.PB(MP((int)m,1));
		}
		Int res=1;
		rep(i,sz(a)){
			res*=a[i].second*2+1;
		}
		res=res/2+1;
		cout<<res<<endl;
	}
	return 0;
}

Measured memory_bytes: 916
i = list(map(int, input().split()))
P = i[0]
Q = i[1]
R = i[2]

if P <= Q:
    if Q <= R:
        print(P+Q)
    else:
        print(P+R)
elif P <= R:
    print(Q+P)
else:
    print(Q+R)    

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

int main()
{
    int a, b, ans_num, num;
    string sa, sb, snum;

    //saとsbを入力
    cin >> sa >> sb;

    //saとsbを文字列として連結
    snum = sa + sb;

    //snumを整数に変換
    num = std::stoi(snum);

    //snumの平方根を代入
    ans_num = int((sqrt(num)));

    ans_num *= ans_num;

    if (num == ans_num)
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }

    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(250000)


def read():
    N, A, B, C, D = map(int, input().strip().split())
    S = input().strip()
    return N, A-1, B-1, C-1, D-1, S


def check_reachable(N, S, start):
    reachable = [False for s in S]
    reachable[start] = True
    
    def _bfs(x):
        for d in [1, 2]:
            nx = x + d
            if 0 <= nx < N and not reachable[nx] and S[nx] == ".":
                reachable[nx] = True
                _bfs(nx)
    
    _bfs(start)
    return reachable


def solve(N, A, B, C, D, S):
    r1 = check_reachable(N, S, A)
    r2 = check_reachable(N, S, B)
    if r1[B] and r2[D]:
        if C < D:
            return "Yes"
        else:
            for i in range(B, D+1):
                if r2[i] and 0 <= i-1 < N and 0 <= i+1 < N and r1[i-1] and r1[i+1]:
                    return "Yes"
    return "No"
        


if __name__ == '__main__':
    inputs = read()
    print(solve(*inputs))


Measured memory_bytes: 146932
import java.io.InputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	private List<Long> f2(long h, long w) {
		List<Long> result = new ArrayList<>();
		if (h % 2 == 0) {
			result.add(h / 2 * w);
			result.add(h / 2 * w);
			return result;
		}

		if (w % 2 == 0) {
			result.add(h * w / 2);
			result.add(h * w / 2);
			return result;
		}

		List<Long> l1 = new ArrayList<>();
		l1.add((h / 2) * w);
		l1.add(((h + 1) / 2) * w);

		List<Long> l2 = new ArrayList<>();
		l2.add(h * (w / 2));
		l2.add(h * ((w + 1) / 2));

		if (Math.abs(l1.get(0) - l1.get(1)) < Math.abs(l2.get(0) - l2.get(1))) {
			return l1;
		} else {
			return l2;
		}
	}

	private List<Long> f3(long h, long w) {

		// 1/3（切り捨て）を試す
		long h1 = h / 3;
		List<Long> l1 = f2(h - h1, w);
		l1.add(h1 * w);

		// 1/3 （切り上げ）を試す
		long h2 = (h + 2) / 3;
		List<Long> l2 = f2(h - h2, w);
		l2.add(h2 * w);

		long a1 = Collections.max(l1) - Collections.min(l1);
		long a2 = Collections.max(l2) - Collections.min(l2);

		if (a1 < a2) {
			return l1;
		} else {
			return l2;
		}
	}

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int H = sc.nextInt();
		int W = sc.nextInt();

		sc.close();

		List<Long> ans1 = f3(H, W);
		List<Long> ans2 = f3(W, H);

		long a1 = Collections.max(ans1) - Collections.min(ans1);
		long a2 = Collections.max(ans2) - Collections.min(ans2);

		out.println(Math.min(a1, a2));
	}

	public static void main(String[] args) {
		new Main()._main(args);
	}
}


Measured memory_bytes: 23760
class SCC:
  '''
  SCC class with non-recursive DFS.
  '''
  def __init__(self,N):
    self.N = N
    self.G1 = [[] for _ in range(N)]
    self.G2 = [[] for _ in range(N)]
  
  def add_edge(self,a,b):
    self.G1[a].append(b)
    self.G2[b].append(a)
    
  def scc(self):
    self.seen = [0]*self.N
    self.postorder=[-1]*self.N
    self.order = 0
    for i in range(self.N):
      if self.seen[i]:continue
      self._dfs(i)

    self.seen = [0]*self.N
    scclist = []
    for i in self._argsort(self.postorder,reverse=True):
      if self.seen[i]:continue
      cc = self._dfs2(i)
      scclist.append(cc)
    
    return scclist
    
  def _argsort(self,arr,reverse=False):
    shift = self.N.bit_length()+2
    tmp = sorted([arr[i]<<shift | i for i in range(len(arr))],reverse=reverse)
    mask = (1<<shift) - 1
    return [tmp[i] & mask for i in range(len(arr))]
  
  def _dfs(self,v0):
    todo = [~v0, v0]
    while todo:
      v = todo.pop()
      if v >= 0:
        self.seen[v] = 1
        for next_v in self.G1[v]:
          if self.seen[next_v]: continue
          todo.append(~next_v)
          todo.append(next_v)
      else:
        if self.postorder[~v] == -1:
          self.postorder[~v] = self.order
          self.order += 1
    return
  
  def _dfs2(self,v):
    todo = [v]
    self.seen[v] = 1
    cc = [v]
    while todo:
      v = todo.pop()
      for next_v in self.G2[v]:
        if self.seen[next_v]: continue
        self.seen[next_v] = 1
        todo.append(next_v)
        cc.append(next_v)
    return cc

def main():
  N,M = map(int,input().split())
  scc = SCC(N)
  for i in range(M):
    a,b=map(int,input().split())
    scc.add_edge(a,b)
  scclist = scc.scc()
  print(len(scclist))
  for cc in scclist:
    print(len(cc),*cc)
    
if __name__=="__main__":
  main()

Measured memory_bytes: 232232
#include <iostream>

using std::cin;
using std::cout;
using std::endl;

static int
solve(int N, int A, int B)
{
  int ret = 0;
  for (int x = 1; x <= N; x++)
  {
    int y = (x / 10000
             + x / 1000 % 10
             + x / 100 % 10
             + x / 10 % 10
             + x % 10);
    if (A <= y && y <= B)
    {
      ret += x;
    }
  }
  return ret;
}

int
main()
{
  int N, A, B;
  cin >> N >> A >> B;
  cout << solve(N, A, B) << endl;
  return 0;
}


Measured memory_bytes: 256
# coding: utf-8
import math
a, b, c = map(int, input().rstrip().split())
print("{0:.5f}".format(a*b*math.sin(math.pi*c/180)/2))
print("{0:.5f}".format(a + b + math.sqrt(a**2+b**2-2*a*b*math.cos(math.pi*c/180))))
print("{0:.5f}".format(b*math.sin(math.pi*c/180)))


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

long long n, sol, p;

int main() {
    cin >> n;
    if(n % 2) {
        cout << 0;
    } else {
        p = 10;
        while(p <= n) {
            sol += n / p;
            p *= 5;
        }
        cout << sol;
    }
    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for (int i = 0; i < (n); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin >> n;
    vector<int> p(n);
    vector<ll> l(n+1),r(n+1);
    for(int i=2;i<=n;i++){
        cout << "? " << 1 << " " << i << endl;
        cin >> l[i];
    }
    for(int i=1;i<=n-1;i++){
        cout << "? " << i << " " << n << endl;
        cin >> r[i-1];
    }
    for(int i=0;i<n;i++){
        ll u=l[i+1]-l[i];
        ll v=r[i]-r[i+1];
        p[i]=i-u+v;
    }
    cout << '!';
    for(int i=0;i<n;i++){
        cout << " " << p[i]+1;
    }
    cout << endl;
}



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

const int mod = 1000000007;

int main(){
    int n, m;
    cin >> n >> m;
    vector<pair<int, string>> ps;
    rep(i,m){
        int p;
        string s;
        cin >> p >> s;
        p--;
        ps.emplace_back(p, s);
    }
    vector<int> b(n);
    vector<int> c(n);
    ll cntAC = 0;
    ll cntWA = 0;
    rep(i, m)
    {
        if(b[ps[i].first]==0){
            if(ps[i].second=="AC"){
                b[ps[i].first]++;
                cntAC++;
            }
        }
    }
    rep(i, m)
    {
        if(c[ps[i].first]==0&&b[ps[i].first]==1){
            if(ps[i].second=="WA"){
                cntWA++;
            }else{
                c[ps[i].first]++;
            }
        }
    }
    cout << cntAC << endl;
    cout << cntWA << endl;
}


Measured memory_bytes: 7280
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let N: i64 = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };
    let K: i64 = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };
    let X: i64 = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };
    let Y: i64 = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };

    let ans = std::cmp::min(N, K) * X + std::cmp::max(0, N - K) * Y;

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

Measured memory_bytes: 4352
#include <stdio.h>
#include <stdlib.h>
#define bool int
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)

//プラキュー（二分ヒープ）（最低限バージョン）
ll heapN,heap[1<<20];
//int PQhikaku(int i,int j);//jの方が優先度が高いならtrueを返す
int PQhikaku(int i,int j){return heap[i]<heap[j];}
void heap_utod(int n){
	if(2*n>heapN)return;
	int rflag=(2*n+1<=heapN)&&(PQhikaku(2*n,2*n+1));
	if(PQhikaku(n,2*n+rflag)){
		ll temp=heap[2*n+rflag];
		heap[2*n+rflag]=heap[n];
		heap[n]=temp;
		heap_utod(2*n+rflag);
	}
}
void heap_dtou(int n){
	if(n==1||PQhikaku(n,n/2))return;
	ll temp=heap[n];
	heap[n]=heap[n/2];
	heap[n/2]=temp;
	heap_dtou(n/2);
}
ll PQpop(){
	ll rr=heap[1];
	heap[1]=heap[heapN--];
	heap_utod(1);
	return rr;
}
void PQpush(ll n){
	heap[++heapN]=n;
	heap_dtou(heapN);
}

ll a[100010];
ll ans[100010];
bool p[100010];
int main(){
	int n;
	scanf("%d",&n);
	rep(i,1,n+1)scanf("%lld",a+i);
	ll M=-1;
	rep(i,0,n+1)if(M<a[i]){
		p[i]=1;
		M=a[i];
	}
	
	ll cnt=0,bi=-1;
	for(ll i=n;i>=0;i--){
		if(p[i]){
			if(bi==-1){
			}else{
				ll temp=(a[bi]-a[i])*cnt;
				while(heapN>0&&heap[1]>=a[i])temp+=PQpop()-a[i],cnt++;
				ans[bi]=temp;
			}
			bi=i;
			cnt++;
		}else{
			PQpush(a[i]);
		}
	}
	rep(i,1,n+1)printf("%lld\n",ans[i]);
	return 0;
}

Measured memory_bytes: 2944
N, A, B = map(int, input().split())
X = list(map(int, input().split()))

ans = 0
for i in range(1, N):
    if((X[i]-X[i-1])*A < B):
        ans += (X[i]-X[i-1])*A
    else:
        ans += B
print(ans)    

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define fst first
#define sc second
#define snd second
#define sz(fst) (int)(fst).size()
#define forn(i, n) for (ll i = 0; i < ll(n); i++)
#define fornr(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define forab(i, a, b) for(int i = int(a); i < int(b); i++)
#define all(fst) fst.begin(), fst.end()

typedef long long ll;
typedef pair<int, int> pii;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef double dbl;
typedef long double ld;
typedef vector<int> vi;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(20);
    int n, k;
    cin >> n >> k;
    vi a(n);
    forn(i, n) cin >> a[i];
    vector<ll> pref(n + 1);
    ll ans = -1;
    forn(i, n) pref[i + 1] = pref[i] + a[i];
    forab(i, k, n + 1) ans = max(ans, pref[i] - pref[i - k]);
    ld res = (ans+k)*1.0/2.0;
    cout << res << "\n";
    return 0;
}

Measured memory_bytes: 2560
#include<stdio.h>
#include<math.h>
int main(void)
{
    int t,w,h;
    int k;
    int i,j;
    double mininaname;
    while(1){
        scanf("%d %d %d",&t,&w,&h);
        if(t == 0 && w == 0 && h == 0) break;
        if(t >= w && t >= h) t = 0;
        else if(w >= t && w >= h) w = 0;
        else if(h >= t && h >= w) h = 0;
        mininaname = sqrt((double)(t * t) + (double)(w * w) + (double)(h * h));

        scanf("%d",&k);
        int a[k];
        for(i = 0; i < k; i++){
            scanf("%d",&a[i]);
        }
        for(i = 0; i < k; i++){
            if(a[i] * 2 > mininaname) printf("OK\n");
            else printf("NA\n");
        }
    }
    return 0;
}

Measured memory_bytes: 584
#include <stdio.h>

void reset(int m[],int n){
    int i,j;
    for(i=0;i<15;i++){
        for(j=0;j<15;j++){
            m[i*15+j]=-1;
        }
    }
    
    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            m[i*n+j]=0;
        }
    }
}

void getM(int m[],int n){
    int x=1;
    int i=n/2 + 1;
    int j=n/2;
    
    while(x<=n*n){
        if(m[i*n+j]==0){
            m[i*n+j]=x;
            x++;
            i++;
            if(i>=n)i=0;
            j++;
            if(j>=n)j=0;
        }else{
            i++;
            if(i>=n)i=0;
            j--;
            if(j<0)j=n-1;
        }
    }
    
}

int main(void){
    int n;
    int m[15*15];
    int i,j;
    
    while(1){
        scanf("%d",&n);
        if(n==0)break;
        
        reset(m,n);
        
        getM(m,n);
        
        for(i=0;i<n;i++){
            for(j=0;j<n;j++){
                printf("%4d",m[i*n+j]);
            }
            printf("\n");
        }
    }

    return 0;
}



Measured memory_bytes: 2036
#include<bits/stdc++.h>
#define reg register int
#define il inline
#define fi first
#define se second
#define mk(a,b) make_pair(a,b)
#define numb (ch^'0')
#define pb push_back
#define solid const auto &
#define enter cout<<endl
#define pii pair<int,int>
using namespace std;
typedef long long ll;
template<class T>il void rd(T &x){
    char ch;x=0;bool fl=false;while(!isdigit(ch=getchar()))(ch=='-')&&(fl=true);
    for(x=numb;isdigit(ch=getchar());x=x*10+numb);(fl==true)&&(x=-x);}
template<class T>il void output(T x){if(x/10)output(x/10);putchar(x%10+'0');}
template<class T>il void ot(T x){if(x<0) putchar('-'),x=-x;output(x);putchar(' ');}
template<class T>il void prt(T a[],int st,int nd){for(reg i=st;i<=nd;++i) ot(a[i]);putchar('\n');}
namespace Modulo{
const int mod=1e9+7;
int ad(int x,int y){return (x+y)>=mod?x+y-mod:x+y;}
void inc(int &x,int y){x=ad(x,y);}
int mul(int x,int y){return (ll)x*y%mod;}
void inc2(int &x,int y){x=mul(x,y);}
int qm(int x,int y=mod-2){int ret=1;while(y){if(y&1) ret=mul(x,ret);x=mul(x,x);y>>=1;}return ret;}
}
using namespace Modulo;
namespace Miracle{
const int N=17;
const int M=(1<<16)+233;
int jie[M],inv[M];
int C(int n,int m){
    if(n<0||m<0||n<m) return 0;
    return mul(jie[n],mul(inv[m],inv[n-m]));
}
int f[N][1<<16];
int n,m;
int a[N];
int sz[1<<16];
bool cmp(int x,int y){
    return x>y;
}
int main(){
    rd(n);rd(m);
    for(reg i=1;i<=m;++i) rd(a[i]);
    sort(a+1,a+m+1,cmp);
    
    jie[0]=1;
    for(reg i=1;i<=(1<<n);++i) jie[i]=mul(jie[i-1],i);
    inv[1<<n]=qm(jie[1<<n]);
    for(reg i=(1<<n)-1;i>=0;--i) inv[i]=mul(inv[i+1],i+1);

    for(reg i=0;i<(1<<n);++i){
        sz[i]=sz[i>>1]*2+(i&1);
    }
    
    f[0][0]=1;
    for(reg i=1;i<=m;++i){
        // cout<<"i "<<a[i]<<endl;
        for(reg s=0;s<(1<<n);++s){
            if(f[i-1][s]==0) continue;
            f[i][s]=ad(f[i][s],f[i-1][s]);
            for(reg p=0;p<n;++p){
                if(!((s>>p)&1)){
                    // cout<<" fang "<<s<<" and "<<p<<" : "<<mul(f[i-1][s],C((1<<n)-a[i]-sz[s],(1<<p)-1))<<endl;
                    f[i][s|(1<<p)]=ad(f[i][s|(1<<p)],mul(f[i-1][s],C((1<<n)-a[i]-sz[s],(1<<p)-1)));
                    // cout<<"go "<<(s|(1<<p))<<" "<<f[i][s|(1<<p)]<<endl;
                }
            }
        }
    }
    ll ans=0;
    for(reg s=0;s<(1<<n);++s){
        int tmp=f[m][s];
        // cout<<" s "<<s<<" tmp "<<tmp<<endl;
        int re=(1<<n)-sz[s]-1;
        for(reg p=0;p<n;++p){
            if(!((s>>p)&1)){
                tmp=mul(tmp,C(re,(1<<p)));
                re-=(1<<p);
            }
        }
        // cout<<" after "<<tmp<<endl;
        if(__builtin_popcount(s)&1){
            tmp=mod-tmp;
        }
        ans=ad(ans,tmp);
    }
    // cout<<"ans1111 "<<ans<<endl;

    ans=mul(ans,(1<<n));
    for(reg i=0;i<n;++i){
        ans=mul(ans,jie[1<<i]);
    }
    ot(ans);
    return 0;
}

}
signed main(){
    Miracle::main();
    return 0;
}

/*
   Author: *Miracle*
*/

Measured memory_bytes: 4608
#include <stdio.h>
#define Max 100000
#define AMax 100000

int A[Max],n;

int partition(int q, int r){
    int x,i,j,kari;
    x=A[r];
    for(j=0;j<r;j++){
      if(A[j]<=x){
        kari=A[q];
        A[q]=A[j];
        A[j]=kari;
        q++;
      }
    }
    kari=A[q];
    A[q]=A[r];
    A[r]=kari;
    return q;
}

int main(int argc, char const *argv[]) {
  int i,s;
  scanf("%d\n",&n);
  for(i=0;i<n;i++) scanf("%d",&A[i]);

  s=partition(0,n-1);

  for(i=0;i<n;i++){
    if(i==n-1) printf("%d\n",A[i]);
    else {
      if(i==s) printf("[%d] ",A[i]);
      else printf("%d ",A[i]);
    }
  }
  return 0;
}

Measured memory_bytes: 988