akhauriyash/Code-Regression huggingface dataset:
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read_option<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok()
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let k: usize = read();
    let mut ans = 0;
    for _ in 0..n {
        let h: usize = read();
        if h >= k {
            ans += 1;
        }
    }
    println!("{}", ans);
}


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

using namespace std;

long long prime = 1000000007;

// for 0 <= l <= r. Gets all pairs (x,y) such that l <= x <= y <= r and y&x == x.
long long simple_calc(long long l, long long r) {
    if (l == 0 && (r+1)&(-r-1) == (r+1)) {
        long long ans = 1;
        while (r > 0) {
            ans = (ans * 3) % prime;
            r /= 2;
        }
        return ans;
    }
    int K = 60;
    vector<vector<long long>> count(K+1, vector<long long>(4, 0));
    count[K][0] = 1;
    // Consider the bits K-1, K-2, .., i bits of l and r, say they correspond to l_i, r_i. (l_i = floor(l/2^i)*2^i and same for r_i)
    // Now count[i][j] counts the number of pairs (x, y) that are divisible by 2^u such that l_i <= x <= y <= r_i with y&x == x and such that:
    // if j = 0 then l = x, y = r
    // if j = 1 then l < x, y = r
    // if j = 2 then l = x, y < r
    // if j = 3 then l < x, y < r
    // Now say we want to calculate it for i-1:
    // Now we have four cases depending on whether the i-1 bit is set in x and y.
    // count[i-1][0] = count[i][0] * (!bit_x || bit_y)
    // count[i-1][1] = count[i][1] * (1 + bit_y) + bit_y * (1 - bit_x) * count[i][0]
    // count[i-1][2] = count[i][2] * (2 - bit_x) + (1 - bit_x) * bit_y * count[i][0]
    // count[i-1][3] = count[i][3] * 3 + (1 - bit_x) * count[i][2] + bit_y * count[i][1]
    for (int i = K; i >= 1; --i) {
        bool bit_x = (l & (1LL << (i-1))) != 0;
        bool bit_y = (r & (1LL << (i-1))) != 0;
        count[i-1][0] = count[i][0] * (!bit_x || bit_y);
        count[i-1][1] = (count[i][1] * (1 + bit_y) + bit_y * (1 - bit_x) * count[i][0]) % prime;
        count[i-1][2] = (count[i][2] * (2 - bit_x) + (1 - bit_x) * bit_y * count[i][0]) % prime;
        count[i-1][3] = (count[i][3] * 3 + (1 - bit_x) * count[i][2] + bit_y * count[i][1]) % prime;
    }
    return count[0][0] + count[0][1] + count[0][2] + count[0][3];
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    long long l, r;
    cin >> l >> r;
    long long sum = 0;
    for (int bit = 60; bit >= 0; --bit) {
        // intersects interval with [2^bit, 2^(bit+1)-1]
        long long new_l = max(l, (1LL << bit));
        long long new_r = min(r, (1LL << (bit+1))-1);
        if (new_l <= new_r) {
            sum = (sum + simple_calc(new_l - (1LL << bit), new_r - (1LL << bit))) % prime;
        }
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define rep(i, n) for(int i=0; i<n; ++i)
using namespace std;

int main() {

  string S;
  cin >> S;

  vector<string> W = {"Sunny", "Cloudy", "Rainy", "Sunny"};

  rep(i, 3) {
	if (S == W[i]) {
	  cout << W[i+1] << endl;
	  break;
	}
  }

  return 0;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input! {
        r: i64,
    }

    let ans = 3 * r * r;

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


Measured memory_bytes: 4352
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
using llong = long long;

// i < j
// j - i == a_i + a_j
// j - a_j == a_i + i
// a_i + i == j - a_j

llong n;
llong a[200005];
map<llong, llong> s;

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

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

    cout << ans << endl;

    return 0;
}


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

int main()
{
  int N, K; cin >> N >> K;
  if (N <= K) {
    cout << 0 << endl;
    return 0;
  }
  priority_queue<int> H;
  ll ans = 0;
  for (int i = 0; i < N; ++i) {
    int h; cin >> h;
    H.push(h);
    ans += h;
  }
  for (int i = 0; i < K; ++i) {
    ans -= H.top();
    H.pop();
  }
  cout << ans << endl;
  
  return 0;
}



Measured memory_bytes: 1400
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n + 1];
        a[0] = 0;
        for (int i = 1; i <= n; i++) {
            a[i] = sc.nextInt();
        }
        int ans = 0;
        for (int i = 0; i <= n; i++) {
            ans += Math.abs(a[i] - a[(i + 1) % (n + 1)]);
        }
        for (int i = 1; i <= n; i++) {
            System.out.println(ans + Math.abs(a[i - 1] - a[(i + 1) % (n + 1)])
                    - (Math.abs(a[i - 1] - a[i]) + Math.abs(a[i] - a[(i + 1) % (n + 1)])));
        }
    }
}


Measured memory_bytes: 60888
import java.util.Scanner;

class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();

		int i = b - a;
		double high = 0.5 * i * (i + 1);

		int x = (int)high - b;

		System.out.println(x);
	}
}


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

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	sort(a.begin(), a.end());
	for (int i = 0; i < n - 1; ++i)
		if (a[i] == a[i + 1]) {
			cout << "NO\n";
			return 0;
		}
	cout << "YES\n";
	return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <limits>
#include <numeric>
#include <cmath>

using namespace std;

template<class T>
class Input {
public:
    auto operator()() const {
        T v;
        cin >> v;
        return v;
    }
};

template<class L, class R>
class Input<pair<L, R>> {
public:
    auto operator()() const {
        L l;
        R r;
        cin >> l >> r;
        return make_pair(l, r);
    }
};

template<class U>
class Input<vector<U>> {
public:
    auto operator()() const {
        Input<size_t> in{};
        auto n = in();
        return (*this)(n);
    }
    auto operator()(size_t n) const {
        vector<U> v;
        v.reserve(n);
        Input<U> in{};
        for (size_t i = 0; i < n; ++i) {
            auto u = in();
            v.emplace_back(move(u));
        }
        return v;
    }
};

template<class U>
class Input<vector<vector<U>>> {
public:
    auto operator()() const {
        Input<size_t> in{};
        auto n = in();
        auto m = in();
        return (*this)(n, m);
    }
    auto operator()(size_t n, size_t m) const {
        vector<vector<U>> v;
        v.reserve(n);
        Input<vector<U>> in{};
        for (size_t i = 0; i < n; ++i) {
            auto u = in(m);
            v.emplace_back(move(u));
        }
        return v;
    }
};

class InputType
{
public:
    template<class T>
    operator T() const {
        Input<T> i{};
        return i();
    }
};

class InputType2
{
public:
    InputType2(size_t n)
        : n_(n)
    {}
    template<class T>
    operator T() const {
        Input<T> i{};
        return i(n_);
    }
private:
    size_t n_;
};

auto input() {
    return InputType();
}

template<class... Args>
auto input(Args&&... args) {
    return InputType2(std::forward<Args>(args)...);
}

size_t bitcount(size_t n) {
    size_t c = 0;
    while (n) {
        if (n & 1ull)
            ++c;
        n >>= 1;
    }
    return c;
}

auto make_order(size_t n) {
    vector<size_t> a(n, 0);
    iota(begin(a), end(a), 0);
    return a;
}

template<class T>
auto next_permutation(T&& x) {
    using std::begin;
    using std::end;
    return next_permutation(begin(x), end(x));
}

using ll = long long;
using ull = unsigned long long;

auto gcd(size_t l, size_t r) {
    if (r == 0)
        return l;
    return gcd(r, l % r);
}

auto gcd(size_t a, size_t b, size_t c) {
    return gcd(a, gcd(b, c));
}

int main() {
    ll r = input();
    auto a = 2 * r * 3.14159265358979;
    cout << a << endl;
    return 0;
}


Measured memory_bytes: 3804
def func(S,x):
    for i in range(x,len(S)):
        if S[i-1] == "0":
            S[i] = "0"
        else:
            S[i] = chr(ord(S[i-1])-1)
    return S

K = int(input())
X = 0


for _ in range(K):
    X += 1
    S = list(str(X))

    i = len(S)-1
    while S[i] == '0':
        i -= 1
    S = func(S,i+1)
    d = len(S)
    for i in range(len(S)-1,0,-1):
        if ord(S[i]) - ord(S[i-1]) > 1:
            S[i-1] = chr(ord(S[i-1])+1)
            d = i
    X = int("".join(func(S,d)))

print(X)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<vector>
#include <map>
#include <set>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <cstring>
#include <cmath>
#include <sstream>
#define Endl endl
#define eof EOF
#define inf 0x3f3f3f3f
#define maxn 10005
 
using namespace std;
typedef long long  ll;
const double pi=acos(-1);
ll GCD(ll a,ll b){return b==0?a:GCD(b,a%b);}



int main(){
    
   
    vector<int>v={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};
    
    int n;cin>>n;
    n--;
    cout<<v[n]<<endl;
    return 0;
    
}


Measured memory_bytes: 256
/*#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <array>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <unordered_map>
#include <unordered_set>
*/

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

#define int long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())

typedef long long ll;
const ll INF = LLONG_MAX - 100;
const ll mod = 1e9 + 7;
const int MAX_N = 5e5 + 5;
int dx[] = { -1LL,0,1LL,0 }, dy[] = { 0,1LL,0,-1LL };
vector<ll> prime;

ll inv[MAX_N], fac[MAX_N];

template <class T = ll> T in() { T x; cin >> x; return (x); }
inline ll GCD(ll a, ll b) { ll c; while (b != 0) { c = a % b; a = b; b = c; }return a; }
inline ll LCM(ll a, ll b) { return a * b / GCD(a, b); }
inline ll POW(ll a, ll b) { ll c = 1LL; while (b > 0) { if (b & 1LL) { c = a * c%mod; }a = a * a%mod; b >>= 1LL; }return c; }
inline void _nCr() { fac[0] = 1LL; for (int i = 1LL; i < MAX_N; i++) { fac[i] = fac[i - 1LL] * i%mod; }for (int i = 0; i < MAX_N; i++) { inv[i] = POW(fac[i], mod - 2); } }
inline ll nCr(ll n, ll r) { return (fac[n] * inv[r] % mod)*inv[n - r] % mod; }
inline void PRI(ll n) { bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) { a[i] = 1LL; }for (int i = 2; i < n + 1LL; i++) { if (a[i]) { prime.pb(i); ll b = i; while (b <= n) { a[b] = 0; b += i; } } } }

typedef pair<int, pair<int, int>> edge;

class UnionFind {
private:
	vector<int> par;
public:
	UnionFind(int N) { par = vector<int>(N, -1LL); }
	int find(int x);
	ll size(int x);
	void unite(int x, int y);
	bool same(int x, int y);
};



class Kruskal {
private:
	UnionFind *uf;
	vector<edge> e;
public:
	vector<edge> mst;
	Kruskal(int N) { uf = new UnionFind(N); }
	void add(int x, int y, ll z);
	void run();
};



//----UnionFind-------------------------------
int UnionFind::find(int x) {
	if (par[x] < 0) return x;
	else return par[x] = find(par[x]);
}

ll UnionFind::size(int x) {
	return -par[find(x)];
}

void UnionFind::unite(int x, int y) {
	x = find(x);
	y = find(y);

	//大きい方に小さい方をくっ付ける
	if (size(x) < size(y)) swap(x, y);
	par[x] += par[y];
	par[y] = x;
}

bool UnionFind::same(int x, int y) {
	x = find(x);
	y = find(y);
	return x == y;
}



//----Kruskal-------------------------------
void Kruskal::add(int x, int y, ll z) {
	//x < y
	if (x > y) swap(x, y);
	e.push_back({ z,{x,y} });
}

void Kruskal::run() {
	sort(e.begin(), e.end());
	e.erase(unique(e.begin(), e.end()), e.end());
	for (auto x : e) {
		if (uf->same(x.second.first, x.second.second)) {
			continue;
		}
		else {
			mst.push_back(x);
			uf->unite(x.second.first, x.second.second);
		}
	}
}

void B() {cout << "Borys" << endl;}
void A() {cout << "Alice" << endl;}

signed main() {
	int n,a,b;
	cin >> n >> a >> b;
	if (a == 1 && b == 2) {
		B();
	} else if ((b - a) % 2 == 1) {
		B();
	} else {
		A();
	}
}

Measured memory_bytes: 256
import math
n, d = map(int, input().split())
x = []
for i in range(n):
    x.append(list(map(int, input().split())))
ans = 0
for i in range(n-1):
    for j in range(i+1, n):
        tmp = 0
        for k in range(d):
            tmp += (x[i][k] - x[j][k])**2
        if int(math.sqrt(tmp))**2 == tmp:
            ans += 1
print(ans)


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

int main() {
  int d, t, s;
  cin >> d >> t >> s;

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


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

int main()
{
    // 変数の宣言
    int a = 0;
    int b = 0;
    int x = 0;

    // 変数の入力を受け取る
    cin >> a;
    cin >> b;

    // あまりがあれば、xの小数点以下を切り上げる
    x = a + b;
    if (x % 2 != 0)
    {
        x = x / 2 + 1;
    }
    else
    {
        x = x / 2;
    }

    // 出力
    cout << x << endl;
}


Measured memory_bytes: 3592
# Here your code !
def kaizyo(a) (a>0)? (1..a).inject(:*) : 1 end
n,a,b = gets.chomp.split.map(&:to_i)
v = gets.chomp.split.map(&:to_i)
v.sort!{|a,b|b<=>a}
max = v[0..(a-1)].inject(:+)*1.0/a
hi = v[a-1]
c = v.count(hi)
cc = v[0..(a-1)].count(hi)
ccc = c - cc
dl = a - cc
puts max
ans = 0
ans += (kaizyo(c)/kaizyo(c-cc))/kaizyo(cc)
a += 1
if (cc == a-1 and a <= b)
    ((a)..[a+ccc-1,b].min).each.with_index(1) do |d,i|
    ans += (kaizyo(c)/kaizyo(c-cc-i))/kaizyo(cc+i)
    end
end
p ans

Measured memory_bytes: 3836
#include<bits/stdc++.h>
using namespace std;
long long lucas[101]={0,2,1};
int main()
{
    for(int i=3;i<100;i++)
        lucas[i]=lucas[i-1]+lucas[i-2];
    int n;
    while(cin>>n)
        cout<<lucas[n+1]<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stack>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <stdlib.h>
#include <tuple>
#include <iomanip>
#include <iterator>
#include <stdio.h>
#include <fstream>
#include <time.h>
using namespace std;
const double PI = 3.14159265358979323846;
const long long int MOD = 1000000000 + 7;

struct UnionFind {
    vector<int> parent;

    UnionFind(int N) : parent(N) {
        for (int i = 0; i < N; i++) {
            parent[i] = -1;
        }
    }

    int root(int i) {
        if (parent[i] < 0) {
            return i;
        }
        return (parent[i] = root(parent[i]));
    }

    bool unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx != ry) {
            parent[ry] += parent[rx];
            parent[rx] = ry;

            return true;
        }
        else {
            return false;
        }
    }

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

    int treeSize(int x) {
        

        return -parent[root(x)];
    }
};

long long int modpow(long long int base, long long int pow, long long int mod) {
    if (pow == 1) {
        return base;
    }
    else if (pow == 0) {
        return 1;
    }

    if (pow % 2 == 0) {
        auto temp = modpow(base, pow / 2, mod);
        return (temp * temp) % mod;
    }
    else {
        return base * modpow(base, pow - 1, mod) % mod;
    }
}

long long int moddiv(long long int X, long long int Y, long long int mod) {
    auto fermatDiv = modpow(Y, mod - 2, mod);

    return (X * fermatDiv) % mod;
}



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

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; i++)
#define REP(i, n) for (int i=1; i<=n; i++)
using namespace std;
using f=float; using ll=long long; using ld=long double;
using ull=unsigned long long; using vi=vector<int>; using pii=pair<int, int>;

int gcd(int a, int b) {
    int t;
    while ( b != 0 ) {
        t = a%b; a = b; b = t;
    }
    return a;
}

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;

    ll sum = 0;
    // Option 1 : 
    REP(i, n) if ( gcd(i, 3) == 1 and gcd(i, 5)==1 ) sum += i; 
    
    // Option 2 : Better 
    //REP(i, n) 
    //    if ( i % 3 == 0 || i % 5 == 0) ;
    //    else 
    //        sum += i;
//            if ( i < 100) cout << i << " " << sum << endl;
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3608
N,M,R= list(map(int,input().split()))
towns = list(map(int,input().split()))
for i in range(R):
    towns[i] += -1

G = [[] for i in range(N)]
for i in range(M):
    A,B,C = list(map(int,input().split()))
    G[A-1].append([C,B-1]) #重み、向かう先の順番
    G[B-1].append([C,A-1])

dists = [[float("inf")]*N for i in range(R)]

import heapq

for i in range(R):
    town = towns[i]
    dist = dists[i]
    dist[town] = 0
    used = [0]*N
    used[town] = 1

    nextlist = []
    for next in G[town]:
        heapq.heappush(nextlist,next)

    while len(nextlist):
        minnext = heapq.heappop(nextlist)
        if used[minnext[1]]==1:
            continue
        v = minnext[1]
        dist[v] = minnext[0]
        used[v] = 1
        for next in G[v]:
            if used[next[1]]==0:
                heapq.heappush(nextlist,[next[0]+dist[v],next[1]])

from itertools import permutations
townorders = list(permutations(towns))

out = float("inf")
for townorder in townorders:
    cand = 0
    for i in range(R-1):
        now = townorder[i]
        nowind = towns.index(now)
        next = townorder[i+1]
        cand += dists[nowind][next]
    if cand<out:
        out=cand
print(out)


Measured memory_bytes: 81368
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <queue>

#define mp make_pair
#define pb push_back


typedef long long ll;
typedef long double ld;

using namespace std;
const ll MOD = 1e9 + 7;
const ll MX = 4010;

ll dp[MX];
ll dp2[MX];

int main() {
	int n, m, k;
	cin >> n >> m >> k;
	int k2 = k - 1;
	ll ans = 0;
	dp[0] = 1;
	int it = (n + m - 1) / k2;
	for (int i = 1; i <= it; ++i) {
		for (int j = 0; j <= m; ++j)
			dp2[j] = 0;
		for (int j = 0; j <= m; ++j) {
			for (int l = 0; l < k && j + l <= m; ++l)
				dp2[j + l] = (dp2[j + l] + dp[j]) % MOD;
		}
		for (int j = 0; j <= m; ++j)
			dp[j] = dp2[j];
		for (int j = 1; j <= m; ++j) {
			int x = j;
			int y = i * k2 - x;
			++y;
			if (m >= x && (m - x) % k2 == 0 && n == y) {
				ans = (ans + dp[j]) % MOD;
			}
		}
	}
	cout << ans << "\n";
	return 0;
}




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

int main() {
  long long N, count = 0;
  cin >> N;
  long long A[N+1], B[N];
  for(long long i=0;i<N+1;i++){
    cin >> A[i];
  }
  for(long long i=0;i<N;i++){
    cin >> B[i];
    if((A[i]>=B[i])){
      count+=B[i];
    }
    else{
      count+=A[i];
      B[i]-=A[i];
      if(A[i+1]<=B[i]){
        count+=A[i+1];
        A[i+1] = 0;
      }
      else{
        A[i+1]-=B[i];
        count+=B[i];
      }
    }
  }
  cout << count;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>
#include <ios>
#include <cctype>
#include <cstdio>
#include <functional>
#include <cassert>
#include <fstream>
#include <ctime>

using namespace std;
using ll = long long;

#define REP(i, a) for (int i = 0; i < (a); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a)-1; i >= (b); --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define SIZE(obj) (int)(obj).sizeT()
#define YESNO(cond, yes, no) \
    { cout << ((cond) ? (yes) : (no)) << endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(), (list).rend())
#define ASSERT(cond, mes) assert(cond&& mes)

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template <typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())
    is >> v[i];
    return is;
}

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a)
        n = a;
    if (n > b)
        n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u / GCD(u, v) * v;
}

std::vector<int> enum_div(int n) {
    std::vector<int> ret;
    for (int i = 1; i * i <= n; ++i) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i != 1 && i * i != n) {
                ret.push_back(n / i);
            }
        }
    }
    return ret;
}

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

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

struct ToUpper {
    char operator()(char c) { return toupper(c); }
};

struct ToLower {
    char operator()(char c) { return tolower(c); }
};

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

    int a, b, c;
    cin >> a >> b >> c;
    YESNO((a + b + c >= 22), "bust", "win");
    {

    }
    return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func SomeSums(N, A, B int) int{
	var sum, tmp int
	for i := 1; i< N + 1; i++{
		n := i
		for n != 0{
			tmp += n % 10
			n /= 10
		}
		if A <= tmp && tmp <= B {
			sum += i
		}
		tmp = 0
	}
	return sum
}

func main() {
	var N, A, B int
	fmt.Scanln(&N, &A, &B)
	sums := SomeSums(N, A, B)
	fmt.Println(sums)
}

Measured memory_bytes: 512
#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>;
const int INF = 1000000001;
const int MOD = 1000000007;

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

int main() {
  int n;
  cin >> n;
  map<int, int> mp;
  rep(i, n){
    int a;
    cin >> a;
    mp[a]++;
  }

  for(int i = n-1; i >= 0; i -= 2){
    if(i != 0 && mp[i] == 2) continue;
    if(i == 0 && mp[i] == 1) continue;
    cout << 0 << endl;
    return 0;
  }

  ll ans = 1;
  for(int i = 0; i < n / 2; ++i){
    ans *= 2;
    ans %= MOD;
  }

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


Measured memory_bytes: 3200
grs = [
    [1,3,5,7,8,10,12],
    [4,6,9,11]
]
xy = gets.split.map(&:to_i)
if grs.any?{|gr| xy.all?{|z| gr.include?(z)}}
    puts 'Yes'
else
    puts 'No'
end

Measured memory_bytes: 1788
#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;

#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
int main(void)
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, ans = 0;
    cin>>n;
    ll a[n], i;
    for(i=0; i<n; i++)
    	cin>>a[i];
    ll cur = 1;
    for(i=0; i<n; i++)
    {
    	if(a[i] == cur)
    		cur++;
    	else
    		ans++;
    }
    if(ans == n)
    	cout<<-1<<endl;
    else
   		cout<<ans<<endl;
}

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

#define ll long long
#define pb push_back
#define MP make_pair
#define F first
#define S second
#define MAX 1e9
#define MIN -1e9
#define MOD 1000000007
#define println(x) cout << "[" << #x << ":" << x << "]\n"; 
#define print(x) cout << "[" << #x << ":" << x << "] "; 

int main(){
	ios::sync_with_stdio(0); 
    cin.tie(0); 
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	ll n;
	cin >> n;
	float val = (float)n/1000;
	ll x = ceil(val);
	ll ans = x*1000 - n;
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define ll long long
#define all(v) v.begin(),v.end()
#define PB push_back
#define PI 3.1415926535897932384626433832795
#define what(x) cout<<#x<<" is "<<x<<endl;
using namespace std;


template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifndef ONLINE_JUDGE
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

ll powmod(ll a,ll b,ll mod) {
    ll res=1;a%=mod;
    //assert(b>=0);
    for(;b;b>>=1){
        if(b&1)res=res*a%mod;a=a*a%mod;
    }
    return res;
}

void solve(){
	int n;
	cin>>n;
	ll ans=0,h=0;
	for(int vp,i=0;i<n;i++){
		cin>>vp;
		if(vp<=h){
			ans+=h-vp;
		}else{
			h=vp;
		}
	}
	cout<<ans<<'\n';
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int tc=1;
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	#endif
	// cin>>tc;
    while(tc--)solve();
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
const int N =1e5+6;
const int M =1e9+7;
const double eps =1e-7;
#define go_baby_go ios::sync_with_stdio(false);cin.tie(NULL);
#define ll long long
#define pb push_back
#define PQ priority_queue
#define pii pair<int,int>
#define vi vector<int>
int a[N],b[N];
int Int(){int x;scanf("%d",&x);return x;}
ll Lnt(){ll x;scanf("%I64d",&x);return x;}
#define Int Int()
#define Lin Lnt()
ll Bigmod(ll A,ll B,ll C)
{
     if(B==0LL)return 1LL;
     ll x=Bigmod(A,B/2LL,C);
     x=(x*x)%C;
     if(B%2==1)
     x=(x*A)%C;
     return x;
}
struct mar
{
     int i,j;
}cr[N];
bool cmp(mar a,mar b){
     if(a.i==b.i)
     return a.j<b.j;
     return a.i<b.i;
}
bool Cmp(int a,int b){return a>b;}
void print(int n){printf("%d\n",n);}
void Print(ll n){printf("%I64d\n",n);}
void debug(int n){printf("%d ",n);}
int polygon(int p,int n)
{
     int mx=INT_MIN;
     for(int i=1;i<=p;i++)
     {
          int u=0;
          for(int j=i;j<=n;j+=p)
          {
               u+=a[j];
          }
          if(n/p>2)
          mx=max(mx,u);
     }
     return mx;
}
int ispolygon(int n)
{
     int i,sqr=sqrt(n),mx=0;
     for(i=1;i<=sqr;i++)
     {
          if(n%i==0)
          {
               mx=max(mx,polygon(i,n));
               mx=max(mx,polygon(n/i,n));
          }  
     }
     return mx;
}
bool get(int l,string s)
{
     int x=l/2;
     for(int i=0;i<l/2;i++)
     {
          if(s[i]!=s[x++])
          return false;
     }
     return true;
}
int main()
{
     go_baby_go;
     string s;
     cin>>s;
     int n=s.size();
     if(n==2)
     return puts("0"),0;
     n-=2;
     while(n)
     {
          if(get(n,s))
          return print(n),0;
          n-=2;
     }
     puts("0");
     
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,k,result = 0;
  cin >> n >> k;

  for (int i = 0; i < n; i++){
    int tem;
    cin >> tem;
    if (tem<=k/2) result += 2*tem;
    else result += 2*(k-tem);
  }
  cout << result << endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;
	boolean eof;
	
	static class Edge {
		int to, val;

		public Edge(int to, int val) {
			this.to = to;
			this.val = val;
		}
	}
	
	List<Edge>[] g;
	
	static final long INF = Long.MAX_VALUE / 10;
	
	long minD1;
	long minD2;
	
	
	int[] base;
	long[] delta;
	
	boolean dfs(int v, int root, long rootDelta) {
		
		if (v < r) {
			minD1 = Math.min(minD1, rootDelta);
		} else {
			minD2 = Math.min(minD2, rootDelta);
		}
		
		base[v] = root;
		delta[v] = rootDelta;
		for (Edge e : g[v]) {
			if (base[e.to] == -1) {
				if (!dfs(e.to, root, e.val - rootDelta)) {
					return false;
				}
			} else {
				if (rootDelta + delta[e.to] != e.val) {
					return false;
				}
			}	
		}
		return true;
	}
	
	int r, c;

	void solve() throws IOException {
		r = nextInt();
		c = nextInt();
		int n = nextInt();
		
		g = new List[r + c];
		for (int i = 0; i < r + c; i++) {
			g[i] = new ArrayList<>();
		}
		
		for (int i = 0; i < n; i++) {
			int x = nextInt() - 1;
			int y = nextInt() - 1;
			int val = nextInt();
			g[x].add(new Edge(y + r, val));
			g[y + r].add(new Edge(x, val));
		}
		
		base = new int[r + c];
		delta = new long[r + c];
		
		Arrays.fill(base, -1);
		
		for (int i = 0; i < r + c; i++) {
			if (base[i] == -1) {
				minD1 = INF;
				minD2 = INF;
				if (!dfs(i, i, 0)) {
					out.println("No");
					return;
				}
				if (minD1 + minD2 < 0) {
					out.println("No");
					return;
				}
			}
		}
		
		out.println("Yes");
	}

	Main() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		
		Thread t = new Thread(null, new Runnable() {

			@Override
			public void run() {
				try {
					solve();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}, "pls", 1 << 26);
		
		t.start();
		try {
			t.join();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		out.close();
	}

	public static void main(String[] args) throws IOException {
		new Main();
	}

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				eof = true;
				return null;
			}
		}
		return st.nextToken();
	}

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			eof = true;
			return null;
		}
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
}

Measured memory_bytes: 78748
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>

using namespace std;

struct Node{
	int key;
	Node *right, *left, *parent;
};

Node *root, *NIL;

Node * treeminimum(Node *x){
	while(x->left!=NIL) x=x->left;
	return x;
}

Node *find(Node *u, int k){
	while(u!=NIL&&k!=u->key){
		if(k<u->key) u=u->left;
		else u=u->right;
	}
	return u;
}

Node * treesuccessor(Node *x){
	if(x->right!=NIL) return treeminimum(x->right);
	Node *y=x->parent;
	while(y!=NIL && x==y->right){
		x=y;
		y=y->parent;
	}
	return y;
}

void treedelete(Node *z){
	Node *y; //delete node
	Node *x; // child of y
	
	//determination of delete node
	if(z->left==NIL || z->right==NIL) y=z;
	else y=treesuccessor(z);
	
	//decide child x of y
	if(y->left!=NIL) x=y->left;
	else x=y->right;
	
	if(x!=NIL) x->parent = y->parent;
	
	if(y->parent==NIL) root=x;
	else{
		if(y==y->parent->left) y->parent->left = x;
		else y->parent->right = x;
	}
	
	if(y!=z) z->key = y->key;
	free(y);
}

void insert(int k){
	Node *y=NIL;
	Node *x=root;
	Node *z;
	
	z=(Node *)malloc(sizeof(Node));
	z->key=k;
	z->left=NIL;
	z->right=NIL;
	while(x!=NIL){
		y=x;
		if(z->key < x->key) x = x->left;
		else x = x->right;
	}
	z->parent=y;
	if(y==NIL) root=z;
	else{
		if(z->key < y->key) y->left = z;
		else y->right = z;
	}
}

void inorder(Node *u){
	if(u==NIL) return;
	inorder(u->left);
	printf(" %d",u->key);
	inorder(u->right);
}

void preorder(Node *u){
	if(u==NIL) return;
	printf(" %d",u->key);
	preorder(u->left);
	preorder(u->right);
}

int main(){
	int n, k;
	string com;
	
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		cin>>com;
		if(com[0]=='f'){//find
			scanf("%d",&k);
			Node *t = find(root,k);
			if(t!=NIL) printf("yes\n");
			else printf("no\n");
		}
		else if(com[0]=='i'){//insert
			scanf("%d",&k);
			insert(k);
		}
		else if(com[0]=='p'){//print
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		}
		else if(com[0]=='d'){//delete
			scanf("%d",&k);
			treedelete(find(root,k));
		}
	}
}

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

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

int main(){
  int k; cin >>k;
  long ans=0;
  long tmp=0;
  for (int i=1;i<=k;i++){
    for (int j=i; j<=k; j++){
      for(int l=j; l<=k; l++){
       // cout <<i <<j <<l <<endl;
        if(i==j && j==l) ans+=i;
        else if(i==j){
          ans += 3*gcd(l,j);
        }else if(j==l){
          ans += 3*gcd(l,i);
        }else if(i==l){
          ans += 3*gcd(j,i);
        }else{
          tmp=gcd(j,i);
          if(tmp>l) ans += 6*gcd(tmp,l);
          else if(tmp == l) ans += 6*l;
          else ans += 6* gcd(l,tmp);
        }
        
      }
    }
  }
  cout <<ans <<endl;
}

Measured memory_bytes: 3636
// AOJ 2019: Princess's Marriage
// 2017.9.30 bal4u@uu
// 2017.11.7 retry

#include <stdio.h>
#include <stdlib.h>

typedef struct { int d, p; } T;
T tbl[10003];

char buf[20], *p;
int getint()
{
	int n = 0;
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	return n;
}

int cmp(T *a, T *b) { if (b->p - a->p) return b->p - a->p; return a->d - b->d; }

int main()
{
	int n, m, i, sum, ans;

	while (fgets(p=buf, 20, stdin) && *buf != '0') {
		n = getint(), p++, m = getint();
		for (i = 0; i < n; i++) {
			fgets(p=buf, 20, stdin);
			tbl[i].d = getint(), p++, tbl[i].p = getint();
		}
		qsort(tbl, n, sizeof(T), cmp);
		for (ans = sum = 0, i = 0; i < n ; i++) {
			sum += tbl[i].d;
			if (sum > m) { ans = (sum - m) * tbl[i++].p; break; }
		}
		for ( ; i < n; i++) ans += tbl[i].d * tbl[i].p;
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 1844
#include <iostream>
#include <map>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;

// http://www.prefield.com/algorithm/container/union_find.html
struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};


int main() {
    int N,K,L;
    cin>>N>>K>>L;
    UnionFind ufR(N+1),ufT(N+1);
    for(int i=0;i<K;i++){
        int p,q;cin>>p>>q;ufR.unionSet(p,q);
    }
    for(int i=0;i<L;i++){
        int p,q;cin>>p>>q;ufT.unionSet(p,q);
    }
    map<int,set<int>>R,T;
    for(int i=1;i<N+1;i++){
        R[ufR.root(i)].insert(i);
        T[ufT.root(i)].insert(i);
    }
    int ans[N+1];
    for(int i=0;i<N+1;i++)ans[i]=0;
    for(int i=1;i<N+1;i++){
        if(ans[i]!=0)continue;
        set<int>& r=R[ufR.root(i)];
        set<int>& t=T[ufT.root(i)];
        set<int> s;
        set_intersection(r.begin(),r.end(),t.begin(),t.end(),inserter(s,s.begin()));
        for(auto c:s){
            ans[c]=s.size();
            r.erase(c);t.erase(c);
        }
    }
    for(int i=1;i<N+1;i++){
        cout<<ans[i]<<" ";
    }
    cout<<endl;
    
    return 0;
}

Measured memory_bytes: 51328
import math

INF = 1001001001

def resolve():
  n, m = map(int, input().split())
  s = []
  c = []

  for i in range(n):
    a, b = map(int, input().split())
    s.append([a, b])

  for i in range(m):
    a, b = map(int, input().split())
    c.append([a, b])

  for a in s:
    ans = 0
    dist = INF
    for i in range(m):
      if abs(a[0] - c[i][0]) + abs(a[1] - c[i][1]) < dist:
        dist = abs(a[0] - c[i][0]) + abs(a[1] - c[i][1])
        ans = i+1
    print(ans)
  return

if __name__ == "__main__":
  resolve()



Measured memory_bytes: 3064
A = [0] * 5
for i in range(5):
    A[i] = int(input())
k = int(input())

flag = False
for i in range(5):
    for j in range(5):
        if i == j:
            continue
        if abs(A[i] - A[j]) <= k:
            continue
        flag = True

if flag:
    print(":(")
else:
    print("Yay!")

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;

int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); }

#define CIN(T, x) T x; cin >> x;
#define CINS(T, x, N) vector<T> x(N); for(int i = 0; i < (N); i++) { cin >> x[i]; }
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << " "; } cout << "\n";
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << "\n";


ll solve ( ll H, ll W ) {

    ll MIN = 1e10;
    for (int h = 1; h < H; h++) {

        ll s1 = h * W, h2;

        h2 = H - h;
        if ( h2 > 0 ) {
            ll w2 = W / 2 + W % 2;
            ll w3 = W - w2;
            ll s2 = h2 * w2;
            ll s3 = h2 * w3;
            ll temp = max(max(s1, s2), s3) - min(min(s1, s2), s3);
            MIN = min( MIN, temp );
        }

        h2 = H - h;
        if ( h2 > 1 ) {
            h2 = h2 / 2 + h2 % 2;
            ll h3 = H - h - h2;
            ll s2 = h2 * W;
            ll s3 = h3 * W;
            ll temp = max(max(s1, s2), s3) - min(min(s1, s2), s3);
            MIN = min( MIN, temp );
        }
    }
    
    return MIN;
}

int main() {

    CIN(ll, H);
    CIN(ll, W);

    ll ans1 = solve(H, W);
    ll ans2 = solve(W, H);

    cout << min(ans1,ans2) << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int swap(int *p1, int *p2, int n){
  int pool;

  pool = *p1;
  *p1 = *p2;
  *p2 = pool;

  return n+1;
}

int main(){
  int n,i,j,min,count=0;
  int *parr;

  // input and allocation
  scanf("%d",&n);
  parr = (int *)malloc(sizeof(int) * n);
  for(i=0; i<n; i++) scanf("%d",&parr[i]);

  // sorting
  for(i=0; i<n; i++){
    min = i;
    for(j=i; j<n; j++){
      if(parr[j] < parr[min]) min = j;
    }
    if(min == i) continue;
    count = swap(&parr[i],&parr[min],count);
  }

  // output
  for(i=0; i<n; i++){
    printf("%d",parr[i]);
    if(i == n-1) break;
    printf(" ");
  }
  printf("\n%d\n",count);

  free(parr);

  return 0;
}

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

int main() {
  int n, max = 0, second = 0;
  cin >> n;
  vector<int> a(n);
  REP(i, n) {
    cin >> a[i];
    if (a[i] > max) { second = max; max = a[i]; }
    else if (a[i] > second) { second = a[i]; }
  }
  int ans;
  REP(i, n) {
    ans = (a[i] == max) ? second : max;
    cout << ans << endl;
  }
}

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

using namespace std;

long long n, k, ans = 0;

int main()
{
	scanf("%lld%lld", &n, &k);
	n++;
	for (long long i = k + 1; i < n; i++)
	{
		long long s = i - k;
		long long g = 0;
		ans += n / i * s + max(g, n - n / i * i - k);
	}
	printf("%lld\n", ans - (!k) * (n - 1));
	return 0;
}

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

int main() 
{
    int n;
    cin >> n;
    vector<vector<int>> v(n);
    if (n==1)
    {
        int a, b;
        cin >> a >> b;
        cout << a+b;
        return 0;
    }
        // return cout << v[0][0] + v[1][0], 0;
    
    for (int i=0; i<2; i++)
        for (int j=0; j<n; j++)
        {
            int a;
            cin >> a;
            // cout << "pst";
            v[i].push_back(a);
        }
    // cout << "pst";
    int maxx = 0, cnt = 0;
    int sum;
    while ( cnt < n )
    {
        sum = 0;
        for (int j=0; j<n; j++)
        {
            if (j<cnt)
                sum += v[0][j];
                // cout << v[0][j] << " ";
            else if (j>cnt)
                sum += v[1][j];
                // cout << v[1][j] << " ";
            else 
                sum += v[1][j] + v[0][j];
                // cout << v[0][j] << " " << v[1][j] << " ";
        }
        // cout << sum << endl;
        // cout << endl;
        cnt++;
        maxx = max(maxx, sum);
    }
    cout << maxx;
    return 0;
}

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

 using namespace std;
 typedef long long ll;

 int main() {
   int A, B, M;

   cin >> A >> B >> M;

   vector<int> a(A + 1);
   vector<int> b(B + 1);

   for (int i = 1; i <= A; i++) cin >> a.at(i);
   for (int i = 1; i <= B; i++) cin >> b.at(i);

   int min_A = 100000, min_B = 100000;
   for (int i = 1; i <= A; i++) {
     min_A = min(min_A, a.at(i));
   }
   for (int i = 1; i <= B; i++) {
     min_B = min(min_B, b.at(i));
   }

   int min_tmp;
   min_tmp = min_A + min_B;

   for (int i = 0; i < M; i++) {
     int x, y, c;
     cin >> x >> y >> c;
     min_tmp = min(min_tmp, a.at(x) + b.at(y) - c);
   }

   cout << min_tmp << endl;
 }


Measured memory_bytes: 1024
from collections import deque
n=int(input())
a=list(map(str,input().split()))
l=deque()
if n%2==0:
    for i in range(n):
        if i%2==1:
            l.appendleft(a[i])
        else:
            l.append(a[i])
    print(" ".join(map(str,l)))
else:
    for i in range(n):
        if i%2==0:
            l.appendleft(a[i])
        else:
            l.append(a[i])
    print(" ".join(map(str,l)))

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

int main()
{
	int n = 0;
	cin >> n;
	int maxTemp =0;
	int nextTemp = 0;
	int topIndex = 0;
	int temp = 0;
	for (int i =0; i < n; ++i) {
		cin >> temp;
		if (maxTemp < temp) {
			nextTemp = maxTemp;
			maxTemp = temp;
			topIndex = i;
		} else {
			if (nextTemp < temp) {
				nextTemp = temp;
			}
		}
	}
	for (int i = 0; i < n; ++i) {
		if (i == topIndex) {
			cout << nextTemp << endl;
		} else {
			cout << maxTemp << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1664
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
      Scanner sc = new Scanner(System.in);
      
      int a = sc.nextInt();
      int b = sc.nextInt();
      int c = sc.nextInt();
      
      if(a<=b&&b<=c){
          System.out.printf("%d %d %d\n",a,b,c);
      }else if(a<=c&&c<=b){
          System.out.printf("%d %d %d\n",a,c,b);
      }else if(b<=a&&a<=c){
          System.out.printf("%d %d %d\n",b,a,c);
      }else if(b<=c&&c<=a){
          System.out.printf("%d %d %d\n",b,c,a);
      }else if(c<=a&&a<=b){
          System.out.printf("%d %d %d\n",c,a,b);
      }else if(c<=b&&b<=a){
          System.out.printf("%d %d %d\n",c,b,a);
      }
      
      
       
    }
}




Measured memory_bytes: 26492
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n; cin >> n;
  string s; cin >> s;
  if(n % 2 == 1){
    cout << "No";
    return 0;
  }
  for(int i = 0; i < n/2; i++){
   // cout << s.at(i) << "  " << s.at(i+n/2) << endl;
    if(s.at(i) != s.at(i + n/2)){
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
}

Measured memory_bytes: 3612
# include <bits/stdc++.h>
# define rr
const int N=100010,INF=0x3f3f3f3f;
inline int read(void){
	int res,f=1;
	char c;
	while((c=getchar())<'0'||c>'9')
		if(c=='-')f=-1;
	res=c-48;
	while((c=getchar())>='0'&&c<='9')
		res=res*10+c-48;
	return res*f;
}
int main(void){
	printf("%d",read()*read());

	return 0;
}


Measured memory_bytes: 3764
#include <cstdio>
#include <vector>
using namespace std;

int binarySearch(int x, vector<int> s) {
  int left = 0;
  int right = s.size();
  while (left < right) {
    int mid = (left + right) / 2;
    if (s[mid] == x) {
      return 1;
    } else if (s[mid] > x) {
      right = mid;
    } else if (s[mid] < x) {
      left = mid + 1;
    }
  }
  return 0;
}

int main() {
  int n, q, tmp, count = 0;
  vector<int> S;
  vector<int> T;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &tmp);
    S.push_back(tmp);
  }
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    scanf("%d", &tmp);
    count += binarySearch(tmp, S);
  }

  printf("%d\n", count);
}


Measured memory_bytes: 3232
X = int(input())

#A**5,B**5でとり得る可能性のある数をあらかじめリストで用意する

N = [i**5 for i in range(1000)]
 
#A,Bで別々の処理をするため、変数はi,jの２種を用意する


for i in range(1000):
	for j in range(i, 1000):

#リストから２つの数を抽出し、Xになるか計算を繰り返す
#Xは正の整数であるため、Aが負になる可能性は除外

		if N[j] - N[i] == X:
			print(j, i)
			exit()

#Bが負の場合、符号が変わる可能性があるため、もう１パターン計算

		if N[j] + N[i] == X:
			print(j, -i)
			exit()

Measured memory_bytes: 9028