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

// one-based numbering
struct UnionFind {
    vector<int> data;
    // i: (data[i] < 0) -> group size, (data[i] > 0) -> parent;
    UnionFind(int n) {
        data.resize(n+1, -1);
    }
    int find(int x) {
        if(data[x] < 0) return x;
        else return data[x] = find(data[x]);
    }
    int size(int x) {
        return -data[find(x)];
    }
    bool unite(int x, int y) {
        x = find(x); y = find(y);
        if(x == y) return false;
        if (data[x] > data[y]) swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return true;
    }
    bool same(int x, int y) {
        x = find(x); y = find(y);
        return x == y;
    }
};

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, a, b; cin >> n >> a >> b; a--, b--;
    vector<int> s(n), t(n);
    vector<long long> cnt(n, 0);
    set<pair<int, int>> sp, tp;
    vector<pair<int, int>> sv, tv;
    map<pair<int, int>, int> idx;
    for (int i = 0; i < n; i++) {
        int x, y; cin >> x >> y;
        s[i] = x + y, t[i] = x - y;
        idx[{s[i], t[i]}] = i;
        sp.emplace(s[i], t[i]), tp.emplace(t[i], s[i]);
        sv.emplace_back(s[i], t[i]), tv.emplace_back(t[i], s[i]);
    }
    sort(sv.begin(), sv.end()), sort(tv.begin(), tv.end());

    int x = max(abs(s[a]-s[b]), abs(t[a]-t[b]));
    auto calc = [&](auto &v, int x, int s, int t) {
        return upper_bound(v.begin(), v.end(), make_pair(s+x, t+abs(x))) 
                - lower_bound(v.begin(), v.end(), make_pair(s+x, t-abs(x)));
    };
    for (int i = 0; i < n; i++) {
        cnt[i] += calc(sv, x, s[i], t[i]) + calc(sv, -x, s[i], t[i]);
        cnt[i] += calc(tv, x, t[i], s[i]) + calc(tv, -x, t[i], s[i]);
        if (sp.count({s[i]-x, t[i]-x})) cnt[i]--;
        if (sp.count({s[i]-x, t[i]+x})) cnt[i]--;
        if (sp.count({s[i]+x, t[i]-x})) cnt[i]--;
        if (sp.count({s[i]+x, t[i]+x})) cnt[i]--;
    }
    
    UnionFind uf(n);
    auto erase = [&](int i) {
        sp.erase({s[i], t[i]}); tp.erase({t[i], s[i]});
    };
    uf.unite(a+1, b+1);
    queue<int> q; q.emplace(a), q.emplace(b);
    erase(a), erase(b);
    while (!q.empty()) {
        int i = q.front(); q.pop();
        auto f = [&](auto &sp, int x, int s, int t, bool sw) {
            auto b = sp.lower_bound(make_pair(s+x, t-abs(x)));
            auto e = sp.upper_bound(make_pair(s+x, t+abs(x)));
            vector<pair<int, int>> v;
            while (b != e) {
                auto d = *b;
                if (sw) swap(d.first, d.second);
                v.emplace_back(d);
                b++;
            }
            for (auto &x: v) {
                auto j = idx[x];
                erase(j);
                uf.unite(i+1, j+1);
                q.push(j);
            } 
        };
        f(sp, x, s[i], t[i], 0);
        f(sp, -x, s[i], t[i], 0);
        f(tp, x, t[i], s[i], 1);
        f(tp, -x, t[i], s[i], 1);
    }
    long long ans = 0;
    for (int i = 1; i <= n; i++) {
        if (uf.same(a+1, i)) {
            ans += cnt[i-1];
        }
    }
    cout << ans / 2 << "\n";
    return 0;
}

Measured memory_bytes: 20456
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> i_i;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
i_i dp[1002];
int parent[1002];
vector<int> children[1002];
int x[1002];

bool search(int now){
    //cout << now << endl;
    if(children[now].empty()){
        dp[now] = {x[now], 0};
        return true;
    }
    for(int i = 0; i < children[now].size(); i++){
        if(!search(children[now][i])){
            return false;
        }
    }
    vector<vector<int> > dp2;
    vector<int> in(5001);
    for(int i = 0; i <= 5000; i++){
        in[i] = INF;
    }
    dp2.push_back(in);
    dp2[0][0] = 0;
    for(int i = 0; i < children[now].size(); i++){
        //cout << "i "<< i << endl;
        dp2.push_back(in);
        int checker = i + 1;
        int a = dp[children[now][i]].first;
        int b = dp[children[now][i]].second;
        for(int j = 0; j <= x[now]; j++){
            int before = j - a;
            if(before >= 0){
                dp2[checker][j] = min(dp2[checker][j], dp2[checker - 1][before] + b);
            }
            before = j - b;
            if(before >= 0){
                dp2[checker][j] = min(dp2[checker][j], dp2[checker - 1][before] + a);
            }
        }
    }
    int checker = children[now].size();
    int mini = INF;
    for(int i = 0; i <= x[now]; i++){
        //cout << mini << endl;
        mini = min(mini, dp2[checker][i]);
    }
    if(mini == INF) return false;
    dp[now] = {mini, x[now]};
    return true;
}

int main() {
    //cout.precision(10)
    int n;
    cin >> n;
    for(int i = 2; i <= n; i++){
        int p;
        cin >> p;
        parent[i] = p;
        children[p].push_back(i);
    }
    for(int i = 1; i <= n; i++){
        cin >> x[i];
    }
    if(search(1)){
        cout << "POSSIBLE" << endl;
    } else {
        cout << "IMPOSSIBLE" << endl;
    }
    return 0;
}


Measured memory_bytes: 19840
// AOJ 1224: Starship Hakodate-maru
// 2017.10.15

#include <stdio.h>
#include <string.h>

int cubic[56];
int tetrahedral[98];
char f[153000];  // 152096 = 96*97*98/6

int main()
{
	int n, i, j;

	for (i = 1; i < 55; i++) cubic[i] = i*i*i;
	for (i = 1; i < 97; i++) tetrahedral[i] = i*(i+1)*(i+2)/6;
	for (i = 0; i < 55; i++) for (j = 0; j < 97; j++) {
		n = cubic[i]+tetrahedral[j];
		if (n < 152000) f[n] = 1;
	}

	while (scanf("%d", &n) && n > 0) {
		while (1) {
			if (f[n]) break;
			n--;
		}
		printf("%d\n", n);
	}
	return 0;
}

Measured memory_bytes: 1800
#include<bits/stdc++.h>
#define ll long long
#define f(i,l,r) for(int i=l;i<=r;i++)
#define debug(x) cout<<#x<<'='<<(x)<<endl
using namespace std;
template<class T> bool maxs(T& a,T& b)
{
    if(a<b)
    {
        T t;
        t=a;
        a=b;
        b=t;
        return true;
    }
    return false;
}
template<class T> bool maxi(T& a,T b)
{
    if(a<b)
    {
        a=b;
        return true;
    }
    return false;
}
template<class T> bool mini(T& a,T b)
{
    if(a>b)
    {
        a=b;
        return true;
    }
    return false;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,wi;
    cin>>n>>wi;
    ll w[n+1],v[n+1];
    f(i,1,n)
    {
        cin>>w[i]>>v[i];
    }
    ll dp[n+1][wi+1];
    f(i,0,n)
        f(j,0,wi)
            dp[i][j]=0;
    
    f(i,1,n)
    {
        f(j,0,w[i]-1)
            dp[i][j]=dp[i-1][j];
        f(j,w[i],wi)
            dp[i][j]=max(dp[i-1][j],v[i]+dp[i-1][j-w[i]]);
    }
    cout<<dp[n][wi];


    return 0;
}

Measured memory_bytes: 79232
use std::cmp::{max, min};
use std::collections::BTreeSet;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

macro_rules! read_value {
    ($next:expr, [graph1; $len:expr]) => {{
        let mut g = vec![vec![]; $len];
        let ab = read_value!($next, [(usize1, usize1)]);
        for (a, b) in ab {
            g[a].push(b);
            g[b].push(a);
        }
        g
    }};
    ($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, usize1) => (read_value!($next, usize) - 1);
    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        read_value!($next, [$t; len])
    }};
    ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

fn cost(w: usize, dpval: usize, st: usize, len: usize) -> usize {
    if dpval >= w {
        1 << 30
    } else {
        dpval - st + 1 - len
    }
}

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (let _ = write!(out,$($format)*););
    }
    input! {
        h: usize, w: usize,
        ab: [(usize1, usize1); h],
    }
    // (dp, st, len)
    let mut dp = BTreeSet::new();
    // (val, dp)
    let mut vals = BTreeSet::new();
    for i in 0..w {
        dp.insert((i, i, 1));
        vals.insert((0, i));
    }
    for i in 0..h {
        let (a, b) = ab[i];
        let rng = dp.range((a, 0, 0)..(b + 1, 0, 0));
        let rng: Vec<_> = rng.cloned().collect();
        let mut mist = w;
        let mut maen = 0;
        for ent in rng {
            let (dpval, st, len) = ent;
            dp.remove(&ent);
            vals.remove(&(cost(w, dpval, st, len), dpval));
            mist = min(mist, st);
            maen = max(maen, st + len);
        }
        if mist < maen {
            dp.insert((b + 1, mist, maen - mist));
            vals.insert((cost(w, b + 1, mist, maen - mist), b + 1));
        }
        let &(mi, _) = vals.iter().next().unwrap();
        if mi >= w {
            puts!("-1\n");
        } else {
            puts!("{}\n", mi + i + 1);
        }
    }
}


Measured memory_bytes: 22328
#[allow(dead_code)]
fn rd() -> String {
    let mut input = String::new();
    std::io::stdin().read_line(&mut input).unwrap();
    input.trim().to_owned()
}

/// 1行の文字を空白で分割してVec<T>にする。
#[allow(dead_code)]
fn rd_vec<T : std::str::FromStr>() -> Vec<T> {
    rd().split_whitespace().map(|x| x.parse().ok().unwrap()).collect()
}

/// 1つの要素を入力で受け取る
#[allow(dead_code)]
fn rd_one<T : std::str::FromStr>() -> T {
    rd().parse().ok().unwrap()
}

/// 複数回read_splitを行う
#[allow(dead_code)]
fn rd_vec_mul<T : std::str::FromStr>(count : i32) -> Vec<Vec<T>> {
    (0..count).map(|_| rd_vec()).collect()
}

/// Vecを1列で出力する
#[allow(dead_code)]
fn op_vec<T : std::fmt::Display>(item : Vec<T>, splitter : char) {
    let cnt = item.len();
    let mut c = 0;
    for i in item.iter() {
        c+=1;
        if cnt > c {print!("{}{}", i, splitter);} else {println!("{}", i);}
    }
}

fn main() {
    let input : Vec<char> = rd().as_str().chars().collect();
    let mut answer = true;
    let mut count = 0;
    for c in input {
        count+=1;
        let a : char;
        if count % 2 == 0 {
            a = 'L';
        } else {
            a = 'R';
        }
        if c == 'U' || c == 'D' || c == a{
            continue;
        }
        answer = false;
        break;
    }
    println!("{}", if answer {"Yes"} else {"No"});
}


Measured memory_bytes: 4352
import java.util.Scanner;


public class Main {

    static void solve() {
        Scanner scan = new Scanner(System.in);

        String s = scan.next();
        if(s.length() == 0) {
            System.out.println(0);
            return;
        }
        int max = 0;
        int cnt = 0;
        for(int i = 0;i<s.length();i++) {
            if(s.charAt(i) == 'R'){
                cnt++;
            } else{
                max = Math.max(max, cnt);
                cnt = 0;
            }
        }
        max = Math.max(max, cnt);
        System.out.println(max);

//        int t = scan.nextInt();
//        for (int i = 0; i < t; i++) {
//            int n = scan.nextInt();
//            int[] arr1 = new int[n];
//            for (int j = 0; j < n; j++) {
//                arr1[j] = scan.nextInt();
//            }
////            scase(n, arr1);
//        }


//        long t = scan.nextLong();

//        for (int i = 0; i < t; i++) {
//            int n = scan.nextInt();
////            scase(n);
//        }
    }


    static void solveCase(int t, int x, String s) {

    }

    static void scase(int[] arr1, int[] arr2) {
    }



    public static void main(String[] args) {
        solve();
    }


    static class LoggerNode {
        String message;
        int ts;
    }


    static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode(int x) {
            val = x;
        }
    }

    static class ListNode {
        int val;
        ListNode next;

        ListNode() {
        }

        ListNode(int val) {
            this.val = val;
        }

        ListNode(int val, ListNode next) {
            this.val = val;
            this.next = next;
        }
    }
}

Measured memory_bytes: 26832
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	m := scanInt()
	a := scanInts(m)

	b := []int{-1, 2, 5, 5, 4, 5, 6, 3, 7, 6}
	dp := make([][10]int, n+1)
	dp[0][0] = 1

	for k := 0; k < m; k++ {
		num := a[k]
		c := b[num]
		for i := 0; i < n; i++ {
			if i+c > n || dp[i][0] == 0 {
				continue
			}

			f := false
			if dp[i+c][0] <= dp[i][0]+1 {
				if dp[i+c][0] < dp[i][0]+1 {
					f = true
				}
				for j := 9; j > 0; j-- {
					if dp[i+c][j] > dp[i][j] {
						break
					}
					if dp[i+c][j] < dp[i][j] {
						f = true
					}
					if num == j && dp[i+c][j] < dp[i][j]+1 {
						f = true
					}
				}
				if f {
					for j := 0; j < 10; j++ {
						dp[i+c][j] = dp[i][j]
					}
					dp[i+c][0]++
					dp[i+c][num]++
				}
			}
		}
		// debug(num, c, dp[n])
	}

	for i := 9; i > 0; i-- {
		for j := 0; j < dp[n][i]; j++ {
			fmt.Fprint(wr, i)
		}
	}
	fmt.Fprintln(wr)
}


Measured memory_bytes: 1536
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<cstdint>
using namespace std;


int main()
{
  int a, b, c;

  cin >> a >> b >> c;
  int plus = a + b;
  int minus = a - b;
  int mul = a * b;

  cout << max(max(plus, minus), mul);

  return 0;
}



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

int main() {
    int n;
    cin >> n;

    map<string, int> mp;
    int max_cnt = 0;
    for (size_t i = 0; i < n; i++)
    {
        string s;
        cin >> s;
        mp[s]++;
        max_cnt = max(max_cnt, mp[s]);
    }

    vector<string> ans;
    for (auto &&e : mp)
    {
        if (e.second == max_cnt) {
            ans.push_back(e.first);
        }
    }

    sort(ans.begin(), ans.end(), [](const string lhs, const string rhs) {
        for (size_t i = 0; i < max(lhs.size(), rhs.size()); i++)
        {
            if (lhs[i] != rhs[i]) {
                return lhs[i] < rhs[i];
            }
        }
        return lhs.size() < rhs.size();
    });    
    for (auto &&e : ans)
    {
        cout << e << endl;
    }
    
}

Measured memory_bytes: 26868
#[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)*}
    };
}

#[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, usize1) => {
        read_value!($next, usize) - 1
    };

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

fn main() {
    input!{
        n:usize,
        m:usize
    }

    if n <= 8 && m <=8 {
        println!("Yay!")
    }else{
        println!(":(")
    }
}

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

using namespace std;

#define fastio cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(0)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> matrix;
typedef pair<int, int> pii;
typedef pair<int,pii> pip;
typedef pair<ll, ll> pll;
#define all(c) c.begin(),c.end()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define endl '\n'
const int MAX = 1e5+1;
const int INF = 0x3f3f3f3f;



int main(){
	ll n;
	fastio;
	cin>> n;

	ll res = n;

	for(ll i = 1; i <= sqrt(n) ; i++) if(n%i == 0) res = min(res, n/i);
	cout<< res+(n/res) - 2<< endl;
	return 0;
}

Measured memory_bytes: 256
N, M = list(map(int, input().split(" ")))

graph = [list() for _ in range(N+1)]

for _ in range(M):
    a, b = list(map(int, input().split(" ")))
    graph[a].append(b)
    graph[b].append(a)
    
for i in range(1, N+1):
    print(len(graph[i]))

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string>
#include<cmath>
using namespace std;
typedef long long LL;
#define maxn (50002)
int n,m;
int dir1[4]={0,0,-1,1};
int dir2[4]={1,-1,0,0};
char mp[52][52];
bool judge(int x,int y)
{
    if(x<0||x>=n) return false;
    if(y<0||y>=m) return false;
    return true;
}
bool check()
{
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
    {
        if(mp[i][j]!='#') continue;
        int k,flag=0;
        for( k=0;k<4;k++)
        {
            int x=i+dir1[k],y=j+dir2[k];
            if(!judge(x,y)) continue;
            if(mp[x][y]=='#') {flag=1;break;}
        }
        if(flag==0) return false;
    }
    return true;
}
int main()
{
    cin>>n>>m;
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
             cin>>mp[i][j];
    if(check()) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;
}

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

using ll = long long;
using namespace std;


inline int Calcu(int a,int b){
    return a + b;
}
class SegTree{
    public:
        int n;
        int g;
        std::vector<int> data;

        SegTree(std::vector<int> a, int _g){
            g = _g;
            for (n = 1; n < (int) a.size(); n *= 2);
            data.resize(n * 2, g);
            for (int i = 0; i < (int) a.size(); i++) data[i + n] = a[i];
            for (int i = n - 1; i >= 1; i--)
                data[i] = Calcu(data[i * 2], data[i * 2 + 1]);
        }
        int rec(int l, int r, int node, int node_l, int node_r) {
            if (node_r <= l || node_l >= r) return g;
            if (node_l >= l && node_r <= r) return data[node];
            int mid = (node_l + node_r) / 2;
            return Calcu(
                rec(l, r, node * 2, node_l, mid),
                rec(l, r, node * 2 + 1, mid, node_r));
        }

        int get(int l,int r){
            return rec(l,r,1,0,n);
        }

        void assign(int index, int val){
            data[index += n] = val;
            for(;index /= 2;)
                data[index] = Calcu(data[index * 2],data[index * 2 + 1]);
        }
};



int main()
{
    int n,q;
    string s;
    cin >> n >> s >> q;
    vector<SegTree> seg;
    for(auto &i : s)i -= 'a';

    for(int i = 0; i < 26; i++){
        vector<int> a(n);
        for(int j = 0; j < n; j++){
            if(s[j] == i)a[j]++;
        }
        seg.push_back(SegTree(a,0));
    }
    vector<int> ANS;

    for(int k = 0; k < q; k++){
        int flag; cin >> flag;
        //更新クエリ
        if(flag == 1){
            int t; char x; cin >> t >> x;
            t--; x -= 'a';
            seg[s[t]].assign(t,0);
            seg[x].assign(t,1);
            s[t] = x;
        }else{
            //取得クエリ
            int l,r; cin >> l >> r; l--;
            int ans = 0;
            for(int i = 0; i < 26; i++){
                if(seg[i].get(l,r))ans++;
            }
            ANS.push_back(ans);
        }
    }
    for(auto i : ANS)cout << i << endl;
}

Measured memory_bytes: 111292
#include <bits/stdc++.h>
#define SORT(x) sort(x.begin(),x.end())
#define ALL(x) x.begin(),x.end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
#define INF 1000000007
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;


void Main(){

  ll N,M;
  cin>>N>>M;

  cout << ( 2*N>=M ? M/2 : (2*N+M)/4 ) <<"\n";
}
//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


Measured memory_bytes: 256
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

def main():
    n,m = inpm()
    if n == 1 and m == 0:
        print(0)
        return
    check = [-1 for _ in range(n)]
    flag = True
    for _ in range(m):
        s,c = inpm()
        if check[s-1] == -1:
            check[s-1] = c
        elif check[s-1] == c:
            continue
        else:
            flag = False
    if not flag:
        print(-1)
        return
    if n > 1 and check[0] == 0:
        print(-1)
        return
    for i in range(n):
        if check[i] == -1:
            if i == 0:
                check[i] = str(1)
            else:
                check[i] = str(0)
        else:
            check[i] = str(check[i])
    print(''.join(check))

if __name__ == "__main__":
    main()

Measured memory_bytes: 39148
#include<iostream>
#include<string>
using namespace std;
int main() {
	int a;
	int b;
	int c;
	int d;
	int e;
	cin >> a >> b >> c;
	if (a + b == c || a + c == b || b + c == a) {
		cout << "Yes" << "\n";
	}
	else {
		cout << "No" << "\n";
	}
	cin >> e;
}

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

class Stack{
private:
 int sp;
 int S[100];
public:
 Stack(){ sp = 0; }
 bool isFull() const { return sp == 100; }
 bool isEmpty() const { return sp == 0; }
 void push(int d){
  if(isFull()) return;
  S[sp] = d;
  sp++;
 }
 int top(){
  if(isEmpty()) return -1;
  return S[sp-1];
 }
 void pop(){
  if(isEmpty()) return;
  sp--;
 }
};

int main(){
 Stack s;
 string expr;
 getline(cin, expr);
 istringstream is(expr);
 
 while(!is.eof()){
  string op;
  is >> op;
  int tmp1, tmp2;

  switch(op[0]){
   case '+':
    tmp1 = s.top(); s.pop();
    tmp2 = s.top(); s.pop();
    s.push(tmp1 + tmp2);
    break;
   case '-':
    tmp1 = s.top(); s.pop();
    tmp2 = s.top(); s.pop();
    s.push(tmp2 - tmp1);
    break;
   case '*':
    tmp1 = s.top(); s.pop();
    tmp2 = s.top(); s.pop();
    s.push(tmp1 * tmp2);
    break;
   default:
    istringstream is2(op);
    is2 >> tmp1;
    s.push(tmp1);
    break;
  }

 }
 
 cout << s.top() << endl;
 return 0;
}

Measured memory_bytes: 3132
//50
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>

using namespace std;

typedef pair<int,int> pii;


int main(){
  int n;
  cin>>n;
  pii r[1000];
  for(int i=0;i<n;i++){
    cin>>r[i].second>>r[i].first;
  }
  sort(r,r+n);
  int t[1001];
  fill(t,t+1001,1<<30);
  for(int i=0;i<n;i++){
    for(int j=n;j>=0;j--){
      int n=(j?t[j-1]:0)+r[i].second;
      if(n<=r[i].first){
	t[j]=min(t[j],n);
      }
    }
  }
  cout<<lower_bound(t,t+n+1,1<<30)-t<<endl;
  return 0;
}

Measured memory_bytes: 1172
import sys

n = int(sys.stdin.readline())
results = {
    "AC": 0,
    "WA": 0,
    "TLE": 0,
    "RE": 0,
}
for _ in range(n):
    res = input()
    results[res] += 1
for key, value in results.items():
    print("%s x %d" % (key, value))


Measured memory_bytes: 9180
import heapq
N = int(input())
P = list(map(int,input().split()))
heap = []
heapq.heappush(heap,10**6)
ans = 0 
m = 10 ** 6
for i in range(N):
    if heap[0] > P[i]:
        ans += 1
    heapq.heappush(heap,P[i])
print(ans)


Measured memory_bytes: 24872
#include <bits/stdc++.h>
#define pb push_back
#define INF 0x3f3f3f3
#define LINF 0x3f3f3f3f3f3f3f
#define MAXN int(2*(10e5+3))
#define fim '\n'
#define ll long long
#define f first
#define s second
#define debug(x) cout << "DEBUG " << x << endl
using namespace std;
typedef pair<int, int> pii;

int vet[MAXN], dp[MAXN];
int n, c, k;


int main(){
	cin.tie(NULL);
	cout.tie(NULL);
	ios::sync_with_stdio(false);
	int n, k;
	cin >> n >> k;
	for(int i = 1; i <= n; i++)
		cin >> vet[i];
	memset(dp, 0x3f3f3f3f, sizeof dp);
	dp[1] = 0;
	for(int i = 2; i <= n; i++) {
		for(int j = min(k, i-1); j >= 1; j--)
			dp[i] = min(dp[i], dp[i-j]+abs(vet[i]-vet[i-j]));
	}
	cout << dp[n] << endl;

}



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

int main() {
    int S;
    cin >> S;
    int before_s = -1;
    for (int i = 1;i < 10000;i *= 10) {
        int s = (S / (1000 / i)) % 10;
        if (s == before_s) {
            cout << "Bad" << endl;
            break;
        } else if (i == 1000) {
            cout << "Good" << endl;
        }
        before_s = s;
    }
}


Measured memory_bytes: 256
//Shejia Zhu
//2018-06-20

import java.util.*;

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

        int output = 0;
        switch (d) {
            case 0:
                if (n==100)
                    output = 101;
                else
                    output = n;
                break;
            case 1:
                if (n==100)
                    output = 10100;
                else
                    output = 100*n;
                break;
            case 2:
                if (n==100)
                    output = 1010000;
                else
                    output = 10000*n;
                break;
        }

        System.out.println(output);
    }
}

Measured memory_bytes: 21972
import scala.io.{StdIn => in}

object Main extends App {
  val out = new java.io.PrintWriter(System.out)
  val Array(r, d, x2000) = in.readLine.split(" ").map(_.toInt)

  var pre = x2000
  for(i <- 1 to 10) {
    val v = r * pre - d
    out.println(v)
    pre = v
  }

  out.flush
}

Measured memory_bytes: 25404
#include <iostream>
typedef long long ll;
using namespace std;

int main(void) {
    ll A,V;cin>>A>>V;
    ll B,W;cin>>B>>W;
    ll T;cin>>T;
    if (A < B) {
        if (V <= W) cout << "NO" << endl;
        else {
            if ((B - A) <= T * (V - W)) cout << "YES" << endl;
            else cout << "NO" << endl;
        }
    } else {
        if (V <= W) cout << "NO" << endl;
        else {
            if ((A - B) <= T * (V - W)) cout << "YES" << endl;
            else cout << "NO" << endl;
        }        
    }
    return 0;
}

Measured memory_bytes: 3124
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, m = map(int, readline().split())
a = list(map(int, readline().split()))
sum_a = sum(a)
cnt = 0
for i in range(n):
    if a[i] / sum_a >= 1 / (4 * m):
        cnt += 1
if cnt >= m:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3060
#include <stdio.h>

#define SIZE 10

int main(void)
{
    int i, j, max, tmp, arr[SIZE];

    for (i = 0; i < SIZE; i++)
        scanf("%d", arr + i);

    for (i = 0; i < 3; i++) {
        max = i;
        for (j = i + 1; j < SIZE; j++)
            if (arr[j] > arr[max])
                max = j;
        tmp = arr[i];
        arr[i] = arr[max];
        arr[max] = tmp;
    }

    printf("%d\n%d\n%d\n", arr[0], arr[1], arr[2]);

    return 0;
}


Measured memory_bytes: 2040
#include<bits/stdc++.h>
using namespace std;
vector<pair<int, int>> v1, v2, v3, v4;
bool comp(const pair<int, int> &v1, const pair<int, int> &v2) {
    return v1.first < v2.first;
}
int main(){
    int n, ma, mb; cin >> n >> ma >> mb;
    if (n == 1)v3.push_back(make_pair(0, 0));
    for (int i = 0; i < n/2; i++)
    {
        int a, b, c; cin >> a >> b >> c;
        v1.push_back(make_pair(b*ma-a*mb, c));
    }
    for (int i = n/2; i < n; i++)
    {
        int a, b, c; cin >> a >> b >> c;
        v2.push_back(make_pair(a*mb-b*ma, c));
    }
    for (int i = 0; i < (1<<(n/2)); i++)
    {
        int x = 0, y = 0;
        for (int j = i, k = 0; j > 0; j>>=1,k++){
            if(j & 1) {x += v1[k].first; y += v1[k].second;}
        }
        v3.push_back(make_pair(x, y));
    }
    for (int i = 0; i < 1<<(n-n/2); i++)
    {
        int x = 0, y = 0;
        for (int j = i, k = 0; j > 0; j>>=1,k++){
            if(j & 1) {x += v2[k].first; y += v2[k].second;}
        }
        v4.push_back(make_pair(x, y));
    }
    sort(v4.begin(), v4.end());
    int ans = 1000000000;
    for (int i = 0; i < v3.size(); i++)
    {
        vector<pair<int, int>>::iterator itr = lower_bound(v4.begin(), v4.end(), v3[i], comp);
        if ((*itr).second + v3[i].second == 0) itr++;
        if (itr == v4.end())continue;
        if ((*itr).first == v3[i].first){
            ans = min(ans, (*itr).second + v3[i].second);
        }
    }
    if (ans == 1000000000) cout << -1 << endl;
    else {
        cout << ans << endl;
    }
    
}

Measured memory_bytes: 22504
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define sbits(a) __builtin_popcount(a)
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
#define gcd __gcd
#define lcm(a, b) ((a * b) / gcd(a, b))
#define pq priority_queue
#define um unordered_map
#define us unordered_set
#define lb lower_bound
#define ub upper_bound
#define F first
#define E end()
#define ln length()
#define sz size()
#define S second
#define em empty()
#define nani(x) cerr << #x << " is " << x << endl;
#define ch(x) (x - 'a' + 1)
#define mp make_pair
#define pb push_back
#define loop(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define scan(x, n) loop(i, 0, n) cin >> x[i];
#define adde(g, u, v) g[u].pb(v), g[v].pb(u);
#define addew(g, u, v, w) g[u].pb({ v, w }), g[v].pb({ u, w });
#define print(x, n) loop(i, 0, n) cout << x[i] << " ";
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define inf 10000000000
#define mod 1000000007

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef pair<long, long> pll;
typedef vector<ii> vii;
typedef vector<pll> vll;
typedef um<int, int> umii;
typedef um<char, int> umci;
typedef map<char, int> mci;
typedef map<int, int> mii;

const int N = 1e5 + 1;
int A[N], B[N], C[N];

int main()
{
    fast;
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n;
    cin >> n;
    scan(A, n);
    scan(B, n);
    scan(C, n);

    ll s = 0;
    int prev = 0;

    for (int i = 0; i < n; i++) {
        s += B[A[i] - 1];
        if (prev && A[i] == prev + 1)
            s += C[A[i] - 2];
        prev = A[i];
    }

    cout << s;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define f first
#define s second
#define sort(v) sort(v.begin(),v.end())
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define mp make_pair
 
typedef long long ll;
const int MAXN=1e6+9;
ll dp[MAXN];
ll mod=1e9+7;
 
 
int main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    //freopen("paint.in","r",stdin);
    //freopen("paint.out","w",stdout);
 
 
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll ans=max(a*c,max(a*d,max(b*c,b*d)));
    cout<<ans;
 
}   


Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>

using namespace std;

int n;
int coins[100];
int dp[51][10001];
const int INF=1000000000;

int dfs(int pos,int money){
	if(pos==n){
		if(money==0)return 0;
		return INF;
	}
	if(dp[pos][money]!=-1)return dp[pos][money];
	int res=INF;
	// ¥¦éÈçÎ¥¤
	if(money-coins[pos]>=0){
		int tmp=dfs(pos,money-coins[pos]);
		if(tmp!=INF)
		res=min(res,tmp+1);
	}
	// ¡ñÍ¥¤àzðÏ¦é¾¯
	int tmp=dfs(pos+1,money);
	if(tmp!=INF)res=min(res,tmp);
	return dp[pos][money]=res;
}

int main(){
	int cnt=0;
	while(cin>>n&&n){
		bool con=false;
		cnt++;
		cout<<"Case #"<<cnt<<": ";
		for(int i=0;i<n;i++)cin>>coins[i];
		sort(coins,coins+n);
		memset(dp,-1,sizeof(dp));
		for(int j=1;j<=10000;j++)dfs(0,j);
		for(int i=1;i<=10000;i++){
			if(dp[0][i]==INF){
				cout<<"Cannot pay some amount"<<endl;
				con=true;
				break;
			}
		}
		if(con)continue;
		// »ê¼êÌàzðgreedyÅ¥¤
		for(int i=1;i<=10000;i++){
			int leftm=i;
			int allc=0;
			for(int j=n-1;j>=0;j--){
				int cnt=leftm/coins[j];
				leftm-=cnt*coins[j];
				allc+=cnt;
			}
			if(dp[0][i]!=allc){
				int a=dp[0][i];
				cout<<"Cannot use greedy algorithm"<<endl;
				con=true;
				break;
			}
		}
		if(con)continue;
		cout<<"OK"<<endl;
	}

	return 0;
}

Measured memory_bytes: 2860
from itertools import product
N,K = list(map(int,input().split(" ")))
Ds =  list(map(int,input().split(" ")))
nums = [0,1,2,3,4,5,6,7,8,9]
nums = list(set(nums) - set(Ds))

cand = []
for j in range(1,6):
    for i in product(nums, repeat=j):
        i = list(map(str,i))
        temp = "".join(list(i))
        temp = int(temp)
        cand.append(temp)
cand.sort()

for i in cand:
    if i >= N:
        print(i)
        break


Measured memory_bytes: 5976
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define INF 1000000007
//0=48,A=65,a=97

int main() {
    int n,d;cin >> d >> n;
    int ans=1;
    
    for(int i = 0; i < d; i++) {
        ans *= 100;
    }

    if(n!=100) cout << ans*n << endl;
    else cout << ans*101 << endl;

    return 0;
}

Measured memory_bytes: 3536
//
//  abc167_Colorful_Blocks.cpp
//  learningCplusplus
//
//  Created by Tran Duc Chinh on 2020/04/04.
//  Copyright © 2020 Tran Duc Chinh. All rights reserved.
//

#include <iostream>
#include <queue>
#include <map>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long ll;
ll mod = 998244353;
ll INF = 1000000007;
#define PI 3.14159265

std::map<int, int> factorization (int n) {
  std::map<int, int> f;
  for (int i = 2; i*i <= n; i++) {
    while (n%i == 0) {
      f[i] += 1;
      n /= i;
    }
  }
  if (n > 1) {
    f[n] += 1;
  }
  return f;
}

ll modpow (int x, int n) {
  if (n==0) return 1%mod;
  ll u = modpow(x, n/2);
  u = (u*u)%mod;
  if (n%2==1) u = (u*x)%mod;
  return u;
}

void dfs(vector<int> A, int n, int m)  {
  if  (A.size() > n) {
    for (int i = 1; i <= n; i++) {
      std::cout << A[i];
    }
    std::cout << std::endl;
    return;
  }
  A.push_back(A.back());
  while (A.back() <= m) {
    dfs(A, n, m);
    A.back()++;
  }
}

const int MAX = 510000;

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i=2; i<MAX; i++) {
        fac[i] = fac[i-1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

ll COM(int n, int k) {
    if(n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % mod) % mod;
}

ll HCOM(int n, int k) {
    return (n == 0 && k == 0) ? 1 : COM(n+k-1, k);
}

int main() {
  ll n, m, k;
  std::cin >> n >> m >> k;
  COMinit();

  ll sum = 0;
  for (int i = 0; i <= k; i++) {
    ll ans = (COM(n-1, i) * m) % mod;
    ans = (ans * modpow(m-1, n-1-i)) % mod;
    sum = (sum + ans) % mod;
  }

  std::cout << sum << std::endl;
  return 0;
}

Measured memory_bytes: 15580
import heapq
N, M = map(int, input().split())
P = [0 for i in range(M)]
Y = [0 for i in range(M)]
country = [[] for i in range(N+1)]
for i in range(M):
    P[i], Y[i] = map(int, input().split())
    heapq.heappush(country[P[i]], (Y[i],i))
cs = [0 for i in range(M)]
for i in range(N+1):
    ran = len(country[i])
    for j in range(ran):
        year, num = heapq.heappop(country[i])
        cs[num] = str(j+1).zfill(6)

for i in range(M):
    line = str(P[i]).zfill(6) + cs[i]
    print(line)

Measured memory_bytes: 39576
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<algorithm>

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<=n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define pb(x) push_back(x)
#define eb(x,y) emplace_back(x,y)
#define MOD 1000000007
#define MAX 1000000001
#define INF 1410065408
#define EPS 1e-9
 
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
struct edge{int from, to; ll cost;};

signed main(){
	int N, M, a, b;
	cin >> N >> M;
	vector<int> v(N, 0);

	rep(M){
		cin >> a >> b;
		v[a-1]++;
		v[b-1]++;
	}

	bool flag = true;
	rep(N){
		if(v[i] % 2){
			flag = false;
			break;
		}
	}
	cout << (flag?"YES":"NO");

}



Measured memory_bytes: 640
#include<stdio.h>
int A[1001];
int main()
{
    int N,c=1;

    scanf("%d",&N);

    for(int i=0;i<N;i++)
    {
        scanf("%d",&A[i]);

    }

    for(int i=0;i<N;i++)
    {

        if(A[i]%2==0)
        {
            if(A[i]%3!=0 && A[i]%5!=0)

            c=0;
        }
    }
    if(c==1)
        printf("APPROVED");
    else
        printf("DENIED");

    return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define int long long
//#define PI 3.14159265358979

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

typedef pair< int, int > pii;
typedef long long ll;

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(11);
	}
};
initializer _____;

int N, M, K, T, Q;
signed main() {
	cin >> N;
	vector< int > A(N);
	rep(i, N) cin >> A[i];
	int ans = 0;
	while (1) {
		int tmp = 0;
		rep(i, N) tmp += A[i] / N;
		if (tmp == 0)
			break;
		ans += tmp;
		rep(i, N) {
			A[i] += tmp - A[i] / N - A[i] / N * N;
		}
	}
	cout << ans << endl;
	return 0;
}

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define per(i, a, b) for(int i = (b)-1; i >= (a); --i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pii> vii;

int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);

  int a,b,c,k;
  cin >> a >> b >> c >> k;
  int ans = min(a,k);
  k -= min(a,k);
  k -= min(k,b);
  ans -= min(k,c);
  cout << ans << '\n';
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int n,m,x,ans=2e9+7;
int c[15],a[15][15],post[15];
int main()
{
cin>>n>>m>>x;
for(int i=1;i<=n;i++)
{
	cin>>c[i];
	for(int j=1;j<=m;j++)
	cin>>a[i][j];
}
while(post[0]==0)
{
	int in[15]={0},money=0;
	for(int i=1;i<=n;i++)
	{
		if(post[i]==1)
		{
			money+=c[i];
			for(int j=1;j<=m;j++)
			in[j]+=a[i][j];
		}
	}
	int flag=1;
	for(int i=1;i<=m;i++)
	{
		if(in[i]<x)
		{
			
			flag=0;
			break;
		}
	}
	if(flag)
	ans=min(ans,money);
	for(int i=n;i>=0;i--)
	{
		if(post[i]==1)
		post[i]=0;
		else
		{
			post[i]=1;
			break;
		}
		
	}
}
if(ans!=2e9+7)
cout<<ans;
else
cout<<-1;
return 0;

}

Measured memory_bytes: 3624
using System;
using System.IO;

namespace CA {
	class Prg {
		static void Main() {
			using(StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }){
				int i = 1, x;
				int n = int.Parse(Console.ReadLine());
				while (++i <= n) {
					x = i;
					if (x % 3 == 0 || x % 10 == 3) {
						sw.Write(" " + i);
						continue;
					}
					while (true) {
						x /= 10;
						if (x != 0) {
							if (x % 10 == 3) {
								sw.Write(" " + i);
								break;
							}
						} else break;
					}
				}
				sw.WriteLine();
			}
        }
	}
}

Measured memory_bytes: 9176
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

int main() {
	int day[] = {31,29,31,30,31,30,31,31,30,31,30,31};
	string date[] = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" };
	int m,d;
	while (cin>>m>>d,m){
		int n=2;
		REP(i,m-1)
			n += day[i];
		n+=d;
		cout<<date[n%7]<<endl;
	}
}

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

int main() {

  long long int n, w, h;
  cin >> n >> w >> h;

  vector< pair< long long int, long long int > > vx, vy;

  for ( long long int i = 0; i < n; i++ ) {

    long long int x, y, inw;
    cin >> x >> y >> inw;

    vx.push_back( make_pair( max( x - inw, 0LL ), min( x + inw - 1, w - 1 ) ) );
    vy.push_back( make_pair( max( y - inw, 0LL ), min( y + inw - 1, h - 1 ) ) );

  }

  sort( vx.begin(), vx.end() );
  sort( vy.begin(), vy.end() );

  long long int k = -1;
  for ( long long int i = 0; i < n; i++ ) {
    if ( k < vx[i].first - 1 ) break;
    k = max( k, vx[i].second );
  }
  if ( k == w - 1 ) {
    cout << "Yes" << endl;
    return 0;
  }

  k = -1;
  for ( long long int i = 0; i < n; i++ ) {
    if ( k < vy[i].first - 1 ) break;
    k = max( k, vy[i].second );
  }
  if ( k == h - 1 ) {
    cout << "Yes" << endl;
    return 0;
  }

  cout << "No" << endl;

  return 0;

}

Measured memory_bytes: 4456
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <string>
#include <algorithm>
#include <string>
#include <climits>

#define REP(i, n) for (int (i) = 0; (i) < (int)(n); (i)++)
#define REG(i, a, b) for (int (i) = ((int)(a)); (i) < ((int)(b)); i++)
#define ALL(V) (V).begin(), (V).end()
#define PRINT(STR) cout << (STR) << endl

typedef long long ll;
using namespace std;

int nextInt() {
	int n = -1;
	cin >> n;
	return n;
}

int main() {
	cin.tie(0); //対話型には使えない
	ios::sync_with_stdio(false); //printfと共には使えない
	vector<int> numbers (5);
	REP(i, 5) {
		numbers[i] = nextInt();
	}
	sort(ALL(numbers));
	reverse(ALL(numbers));
	REP(i, 4) {
		cout << numbers[i] << " ";
	}
	cout << numbers[4] << endl;

	return 0;
}

Measured memory_bytes: 1216
n = int(input())

x = list(map(int,input().split()))
y = list(map(int,input().split()))

dim_list = [1,2,3,float('inf')]

for dim in dim_list:
    D = [0]*n
    if dim == float('inf'):
        for i in range(n): 
            D[i] = abs(x[i] - y[i])
        print("{:.6f}".format(max(D)))
    else:
        for i in range(n):
            D[i] = abs(x[i] - y[i])**dim
        
        print("{:.6f}".format(sum(D)**(1/dim)))



Measured memory_bytes: 5656
Scanf.scanf "%d %d %d %d %d %d %d" (fun ai ao at aj al as_ az ->
    let k = ao in
    let f a = if a = 0 then 0 else 2 - a mod 2 in
    let v =
        match f ai * f aj * f al with
        | 1 | 2 -> 1
        | _ -> 0
    in

    let k = k + v * 3 in
    let ai = ai - v in
    let aj = aj - v in
    let al = al - v in
    let k = k + (ai / 2) * 2 in
    let k = k + (aj / 2) * 2 in
    let k = k + (al / 2) * 2 in
    Printf.printf "%d\n" k
)

Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main(){
	int a,b,c,d,p;
	cin>>a>>b>>c>>d>>p;
	int x=a*p,y=0;
	if(p>c){
		for(int i=p;i>c;i--){
			y+=d;
		}
	}
	y+=b;
	if(x>=y)cout<<y<<endl;
	else cout<<x<<endl;
}

Measured memory_bytes: 3096