akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define m0(x) memset(x,0,sizeof(x))
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

map<ll, ll> primeFactors(ll n)
{
    map<ll, ll> ret;
    while (n % 2 == 0)
    {
        if( ret.find(2) != ret.end() ) {
            ret[2]++;
        }
        else
        {
            ret[2] = 1;
        }
        n = n / 2;
    }
    for (ll i = 3; i <= sqrt(n); i = i+2)
    {
        while (n%i == 0)
        {
            if( ret.find(i) != ret.end() ) {
            ret[i]++;
        }
        else
        {
            ret[i] = 1;
        }
            n = n / i;
        }
    }
    if (n > 2)
        {
            if( ret.find(n) != ret.end() ) {
            ret[n]++;
        }
        else
        {
            ret[n] = 1;
        }
        }
    return ret;
}

void print_map(map<ll, ll> mp){
    for(auto itr = mp.begin(); itr != mp.end(); ++itr) {
        std::cout << "key = " << itr->first           // キーを表示
                        << ", val = " << itr->second << "\n";    // 値を表示
    }
}

// Returns nCr % p
ll nCrModp(ll n, ll r, ll p)
{
    ll C[r+1];
    memset(C, 0, sizeof(C));

    C[0] = 1;

    for (ll i = 1; i <= n; i++)
    {
        for (ll j = min(i, r); j > 0; j--)
            C[j] = (C[j] + C[j-1])%p;
    }
    return C[r];
}

ll hantokei(ll a, ll b, ll L) {
    ll count = 0;
    while (a % L != b)
    {
        a++;
        count++;
    }
    return count;
}

ll  tokei(ll a, ll b, ll L) {
    ll count = 0;
    while (a != b) {
        if (a == 0) {
            a = L;
        }
        a--;
        count++;
    }
    return count;
}

int main()
{
    ll N, A, B;
    cin >> N >> A >> B;
    vector<ll> vec(N);
    rep(i, N)
    {
        cin >> vec.at(i);
    }
    sort(vec.begin(), vec.end());
    vector<ll> v(3);
    rep(i, vec.size())
        {
            if (vec.at(i) <= A){
                v.at(0)++;
                continue;
            } else if (A < vec.at(i) & vec.at(i) <= B){
                v.at(1)++;
            } else if (B < vec.at(i)){
                v.at(2)++;
            }
        }
    sort(v.begin(), v.end());
    cout << v.at(0) << endl;
    return 0;
}



Measured memory_bytes: 256
package main

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

const mod = 1000000007

// 1MB
const ioBufferSize = 1 * 1024 * 1024

var sc = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	sc.Split(bufio.ScanWords)
	return sc
}()

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	n := nextInt()
	v := make([]float64, n)

	for i := 0; i < n; i++ {
		v[i] = float64(nextInt())
	}

	for len(v) > 1 {
		sort.Float64s(v)
		s := (v[0] + v[1]) / 2
		v = v[2:]
		v = append(v, s)
	}

	fmt.Println(v[0])
}


Measured memory_bytes: 640
from sys import stdin


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    H, W = list(map(int,_in[0].split(' ')))  # type:list(int)
    s_arr = []
    for i in range(H):
        _ = [_ for _ in _in[i+1]]   # type:list(str)
        s_arr.append(_)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    TF = 'Yes'
    for i in range(H):
        if TF == 'Yes':
            for j in range(W):
                if s_arr[i][j] == '#':
                    adjacent = []
                    if i>0:   
                        if s_arr[i-1][j] == '#':
                            continue
                    if i<H-1: 
                        if s_arr[i+1][j] == '#':
                            continue
                    if j>0:   
                        if s_arr[i][j-1] == '#':
                            continue
                    if j<W-1: 
                        if s_arr[i][j+1] == '#':
                            continue
                    TF = 'No'
                    break
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(TF)


Measured memory_bytes: 39280
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int main(){
	int x,a;cin>>x>>a;
	if(x<a)puts("0");
	else puts("10");
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdint>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

const int MAX = 3000;
int dp[MAX + 1][MAX + 1] = {0};

int main() {
    string s, t, res;
    res = "";
    cin >> s >> t;

    for (int i = 1; i <= s.size(); i++) {
        for (int j = 1; j <= t.size(); j++) {
            if (s[i - 1] == t[j - 1])
                dp[i][j] = dp[i - 1][j - 1] + 1;
            else 
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
        }
    }

    int i = s.size();
    int j = t.size();

    while (i > 0 && j > 0) {
        if (dp[i][j - 1] == dp[i][j])
            j--;
        else if (dp[i - 1][j] == dp[i][j]) 
            i--;
        else {
            res = s[i - 1] + res;
            i--; j--;
        }
    }

    cout << res;

    return 0;
}



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

int main() {
  string s;
  cin >> s;
  bool bad = false;

  for(int i = 0; i < 3; i++){
    if(s[i] == s[i + 1]){
        bad = true;
        i = 4;   
        }
    }
 if (bad == false){ 
 cout << "Good";
 }
 if (bad == true){
    cout << "Bad";
 }
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import static java.lang.Math.*;

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

    public void solve(String[] args) {
        MyScanner scanner = new MyScanner();
        long N = scanner.nextLong();
        String s = "" + N;
        long a = 0;
        for (int i = 0; i < s.length(); i++) {
            a += s.charAt(i) - '0';
        }
        String ret = (N % a) == 0 ? "Yes" : "No";
        System.out.println(ret);
    }


    private class MyScanner {
        String[] s;int i;BufferedReader br;String reg = " ";
        MyScanner () { s = new String[0];i = 0;br = new BufferedReader(new InputStreamReader(System.in)); }
        public String next() {
            try {
                if (i < s.length) return s[i++]; String line = br.readLine();
                while (line.equals("")) {line = br.readLine();}
                s = line.split(reg, 0); i = 0;return s[i++];
            } catch (Exception e) {e.printStackTrace();}
            return null;
        }
        public int nextInt() {
            try {return Integer.parseInt(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public double nextDouble() {
            try {return Double.parseDouble(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public long nextLong()  {
            try {return Long.parseLong(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
    }
}


Measured memory_bytes: 21204
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<limits>
#include<iomanip>
#include<cmath>
#include<climits>

using namespace std;

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

const int mod=1e9+7;

bool judge(char c){
    return (c=='A'||c=='T'||c=='G'||c=='C'?true:false);
}

int main(){
    string s;
    cin >> s;
    int ans=0;
    for(int i=0;i<s.size();i++){
        int cnt=1;
        if(!judge(s[i])){
            continue;
        }else if(i<s.size()-1&&judge(s[i])&&!judge(s[i+1])){
            ans=max(ans,1);
            continue;
        }
        while(i<s.size()-1&&judge(s[i])&&judge(s[i+1])){
            cnt++;
            i++;
        }
        ans=max(ans,cnt);
    }
    cout << ans << endl;
    return 0;
}


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

#define F first
#define S second 
#define pb push_back
#define ll long long
#define int long long

using namespace std ;

const int MAXN = 101 * 1001 ;

int32_t main()
{
    ios::sync_with_stdio(0) ;
    cin.tie(0) ;
    int n , a , b , x , y ;
    cin >> n >> a >> b ;
    for(int i = 1 ; i < n ; i ++ )
    {
        cin >> x >> y ;
        int q = (a+x-1) / x ;
        int w = (b+y-1) / y ; 
        q = max(q,w) ;
        a = q * x ;
        b = q * y ;
    }
    cout<<a+b<<'\n';
 
 
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vector<ll> a(n), b(n), c(m), d(m);
	rep(i,n) cin >> a[i] >> b[i];
	rep(i,m) cin >> c[i] >> d[i];
	rep(i,n){
		ll mindist = 1e18;
		int idx = 0;
		rep(j,m){
			ll dist = llabs(a[i] - c[j]) + llabs(b[i] - d[j]);
			if(dist < mindist){
				mindist = dist;
				idx = j+1;
			}
		}
		cout << idx << endl;
	}
	return 0;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
vector<int>hasher[105];

int main(){
	int n;
	cin>>n;
	long long ret = 0;
	
	for(int i=1; i<=n; i++){
		if(i%10==0) continue;
		int curr = 1;
		while(curr*10<=i) curr*=10;
		int fir = i/curr;
		int sec = i%10;
		hasher[fir*10+sec].push_back(i);
	}
	for(int i=1; i<=n; i++){
		if(i%10==0) continue;
		int curr = 1;
		while(curr*10<=i) curr*=10;
		int fir = i/curr;
		int sec = i%10;
		ret+=hasher[sec*10+fir].size();

	}
	cout<<ret;
}

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

int main() {

  int N, M;
  cin >> N >> M;
  
  vector<int> H(N);
  for (int i = 0; i < N; i++) {
    cin >> H[i];
  }

  vector<int> mx(N);
  for (int i = 0; i < M; i++) {
    int A, B;
    cin >> A >> B;
    --A;
    --B;
    mx[A] = max(H[B], mx[A]);
    mx[B] = max(H[A], mx[B]);
  }

  int answer = 0;

  for (int i = 0; i < N; i++) {
    if (mx[i] < H[i]) {
      answer++;
    }
  }

  cout << answer << endl;

  return 0;

}

Measured memory_bytes: 4052
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using vec = vector<ll>;
using vect = vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i, n) for (ll i = 0; i < n; i++)
#define Loop(i, m, n) for (ll i = m; i < n; i++)
#define pool(i, n) for (ll i = n; i >= 0; i--)
#define Pool(i, m, n) for (ll i = n; i >= m; i--)
#define mod 1000000007ll
#define flagcount __builtin_popcount
#define flag(x) (1 << x)
#define flagadd(bit, x) bit |= flag(x)
#define flagpop(bit, x) bit &= ~flag(x)
#define flagon(bit, i) bit &flag(i)
#define flagoff(bit, i) !(bit & (1 << i))
#define all(v) v.begin(), v.end()
#define low2way(v, x) lower_bound(all(v), x)
#define high2way(v, x) upper_bound(all(v), x)
#define idx_lower(v, x) (distance(v.begin(), low2way(v, x)))  //配列vでx未満の要素数を返す
#define idx_upper(v, x) (distance(v.begin(), high2way(v, x))) //配列vでx以下の要素数を返す
#define idx_lower2(v, x) (v.size() - idx_lower(v, x))         //配列vでx以上の要素数を返す
#define idx_upper2(v, x) (v.size() - idx_upper(v, x))         //配列vでxより大きい要素の数を返す
#define putout(a) cout << a << endl
#define Gput(a, b) G[a].push_back(b)
#define Sum(v) accumulate(all(v), 0ll)
#define gcd(x, y) __gcd(x, y)
ll ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return 0;
}
template <typename T>
T lcm(T x, T y)
{
    T z = gcd(x, y);
    return x * y / z;
}
template <typename T>
bool primejudge(T n)
{
    if (n < 2)
        return false;
    else if (n == 2)
        return true;
    else if (n % 2 == 0)
        return false;
    double sqrtn = sqrt(n);
    for (T i = 3; i < sqrtn + 1; i++)
    {
        if (n % i == 0)
        {
            return false;
        }
        i++;
    }
    return true;
}
//場合によって使い分ける
//const ll dx[4]={1,0,-1,0};
//const ll dy[4]={0,1,0,-1};
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//2次元配列の宣言
//vector<vector<ll>> field(h, vector<ll>(w));

int main()
{
    ll a1, b1, a2, b2, k;
    cin >> a1 >> b1 >> a2 >> b2 >> k;
    putout(60 * (a2 - a1) + (b2 - b1) - k);
    return 0;
}


Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;

int main(){
	int n,ans=0,i,d;
	cin>>n;
	for(i=1;i<=5;i++){
		if(n<pow(10,i)){
			if(i%2==1){
				ans+=n-pow(10,i-1)+1;
			}
			break;
		}
		if(i%2==1){
			ans+=pow(10,i)-pow(10,i-1);
		}
	}
	cout<<ans;
	return 0;
}



Measured memory_bytes: 256
#include <assert.h>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using ll = long long;
using P = std::pair<ll, ll>;

#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug "<< i << std::endl

// const ll MOD = 998244353;
const ll MOD = 1e9 + 7;

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  //問題文中の添え字が0-indexか1-indexか確認!

  ll n;
  std::cin>>n;

  std::vector<ll> b(n-1);

  rep(i,0,n-1)std::cin>>b[i];

  ll ans=0,prev=b[0];

  rep(i,1,n-1){
    ans+=std::min(prev,b[i]);
    prev=b[i];
  }

  ans+=(b[0]+b[n-2]);

  std::cout<<ans;

  return 0;
}


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

const int N = 410;
const int M = 100010;

bool set[N][N], flag[N];
int n, m;
int x[M], y[M];

int main(){
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= m; ++ i){
		scanf("%d%d", &x[i], &y[i]);
	}
	for (int i = 1; i <= n; ++ i){
		set[i][i] = true;
		for (int j = m; j; -- j){
			if (set[i][x[j]] && set[i][y[j]]){
				flag[i] = true;
				break;
			}
			if (!set[i][x[j]] && !set[i][y[j]]){
				continue;
			}
			set[i][x[j]] = set[i][y[j]] = true;
		}
	}
	int ans = 0;
	for (int i = 1; i <= n; ++ i){
		for (int j = i + 1; j <= n; ++ j){
			if (flag[i] || flag[j]){
				continue;
			}
			bool _flag = true;
			for (int k = 1; k <= n; ++ k){
				if (set[i][k] && set[j][k]){
					_flag = false;
					break;
				}
			}
			ans += _flag;
		}
	}
	return printf("%d\n", ans), 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <string>
#include <math.h>

using namespace std;

int main()
{
	int a, b;
	cin >> a >> b;
	if (a + b < 24)
	{
		cout << (a + b) << endl;
 	}
	else
	{
		cout << (a + b) - 24 << endl;
	}
	
    return 0;
}

Measured memory_bytes: 256
use std;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}
fn e_multiplication_4() {
    let nk = read_vec::<usize>();
    let n = nk[0];
    let k = nk[1];
    let mut a = read_vec::<i64>();
    let (mut s, mut t): (Vec<i64>, Vec<i64>) = a.iter().partition(|&e| *e >= 0);
    const DIV: i64 = 1000000007;
    s.sort();
    t.sort();
    a.sort_by_key(|e| e.abs());

    let is_certainly_negative = s.len() == 0 && k % 2 == 1;

    let ans: i64 = if n == k {
        a.iter()
            .fold(1, |acc, e| (acc * e).rem_euclid(DIV))
    } else if is_certainly_negative {
        a.iter()
            .take(k)
            .fold(1, |acc, e| (acc * e).rem_euclid(DIV))
    } else {
        let init = if k % 2 == 1 { s.pop().unwrap() } else { 1 };
        let mut products: Vec<i64> = vec![];
        let mut s_products = s.rchunks(2).map(|e| e.iter().product()).collect();
        let mut t_products = t.chunks(2).map(|e| e.iter().product()).collect();
        products.append(&mut s_products);
        products.append(&mut t_products);
        products.sort_by_key(|&e| std::cmp::Reverse(e));
        products.iter()
            .take(k / 2)
            .map(|e| e.rem_euclid(DIV))
            .fold(init, |acc, e| (acc * e).rem_euclid(DIV))
    };

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

fn main() {
    e_multiplication_4();
}


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

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

    for(int i = 0; i < a; ++i)
    {
        sa += (char (b + 48));
    }

    for(int i = 0; i < b; ++i)
    {
        sb += (char (a + 48));
    }

    cout << (sa < sb ? sa : sb) << "\n";
    return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <iomanip>
#include <bitset>
using namespace std;

typedef long long ll;



int main() {
	int n; cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	double m = 0;
	for (int i = 0; i < n; i++) m += a[i];
	m /= n;
	double mi = 1e9;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (abs(m - a[i]) < mi) {
			mi = abs(m - a[i]);
			ans = i;
		}
	}
	cout << ans << endl;
	return 0;
}


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

#define INF 1e9
#define MAX 100005
#define xx first
#define yy second
#define pb push_back
#define mp make_pair
#define ull long long
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define nl '\n'
#define zai <<' '<<
#define all(a) a.begin(),a.end()
#define pc __builtin_popcount
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int n;
	cin >> n;
	cout << (n-2)*180;
	return 0;
}

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

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx,avx2")

using namespace std;

#define int long long
#define sz(a) (int) (a).size()
#define all(a) (a).begin(), (a).end()
#define x first
#define y second

const int inf = 5e18;
const int maxn = 2e5 + 10;

int dp[maxn][3];

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    int n;
    cin >> n;
    vector<int> a(n);
    for (auto &el : a) {
        cin >> el;
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 3; j++) {
            dp[i][j] = -inf;
        }
    }
    for (int i = 0; i < n; i++) {
        if (i == 0) {
            dp[i][0] = a[i];
        } else {
            for (int j = 0; j <= 2; j++) {
                for (int k = 0; k <= 2; k++) {
                    if (j + k > 2) continue;
                    if (i - k <= 0) {
                        dp[i][j + k] = max(dp[i][j + k], a[i]);
                    } else {
                        if (i - k - 2 < 0 || dp[i - k - 2][j] == -inf) continue;
                        dp[i][j + k] = max(dp[i][j + k], dp[i - k - 2][j] + a[i]);
                    }
                }
            }
        }
    }
    int ans;
    if (n % 2 == 0) {
        ans = max(dp[n - 1][1], dp[n - 2][0]);
    } else {
        ans = max(dp[n - 1][2], dp[n - 2][1]);
    }
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 9508
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}
 
int main() {
    int n;
    cin >> n;
    for (int i = 0; i <= n; ++i) {
        if (int(double(i)*1.08) == n) {
            cout << i << "\n";
            return 0;
        }
    }   
    cout << ":(" << "\n";
    return 0;
}

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

int main() {
  string s;
  vector<int> x(N);
  int sum = 0;

  rep(i,N){
    cin >> s;
  }

  rep(i,N){
    x.at(i) = s.at(i)-'0';
  }

  rep(tmp,1 << N-1){
    bitset<N-1> index(tmp);

    sum = x.at(0);
    rep(i,3){
      if(index.test((N-2)-i)){
        sum += x.at(i+1);
      }
      else{
        sum -= x.at(i+1);
      }
    }
    if(sum == 7){
      cout << s.at(0);
      rep(i,3){
        if(index.test((N-2)-i)){
          cout << '+';
          cout << s.at(i+1);
        }
        else{
            cout << '-';
            cout << s.at(i+1);
        }
      }
      cout << "=7" << endl;
      return 0;
    }
  }

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int k, d[10];

bool judge(int n)
{
    while (n){
        for(int i=0; i<k; i++){
            if(d[i] == n % 10) return false;
        }
        n /= 10;
    }

    return true;
}
int main()
{
    int n;
    cin >> n >> k;
    for(int i=0; i<k; i++) cin >> d[i];

    bool like = false;
    while (!like){
        like = judge(n);
        n++;
    }

    cout << n - 1 << endl;

    return 0;
}


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

int main() {
	int n,m,count=0;
	cin>> n >>m;
	vector<int>v;
	for(int i=0;i<m;i++){
		int h;
		cin>>h;
		v.push_back(h);
		count += v[i];
	}
	if(count > n)
	cout<<"-1"<<endl;
	
	else
	cout<<n-count<<endl;
	return 0;
}

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

int main(int, char**) {
  int N;
  cin >> N;
  int h[N];
  for (int i = 0; i < N; ++i) cin >> h[i];
  int p[N];
  for (int i = 0; i < N; ++i) p[i] = 100000000000;
  
  
  p[0] = 0;
  p[1] = abs(h[1] - h[0]);
  for (int i = 1; i < N; ++i) {
    p[i] = min(p[i], p[i-1] + abs(h[i - 1] - h[i]));
    if (i > 1)
      p[i] = min(p[i], p[i-2] + abs(h[i - 2] - h[i]));
  }
  cout << p[N-1] << endl;
}


Measured memory_bytes: 1024
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef long long ll;

int main(){
    int n , m ;
    cin >> n >> m ;
    vector<vector<int> > graph(3*n) ;
    for(int i=0;i<m;i++){
        int x , y ;
        cin >> x >> y ;
        x--, y-- ;
        graph[x].push_back(y+n) ;
        graph[x+n].push_back(y+2*n) ;
        graph[x+2*n].push_back(y) ;
    }
    int s , t ;
    cin >> s >> t ;
    s--,t-- ;
    vector<int> dist(n*3,-1) ;
    queue<int> q ;
    dist[s] = 0 ;
    q.push(s) ;
    while(!q.empty()){
        int f = q.front() ; q.pop() ;
        for(int c : graph[f]){
            if ( dist[c] == -1 ){
                dist[c] = dist[f] + 1 ;
                if ( c == t ){
                    cout << dist[c]/3 << endl;
                    return 0 ;
                }
                q.push(c) ;
            }
        }
    }
    cout << -1 << endl;
    return 0 ;
}


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

public class Main {
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/2;
    public static final int inf = Integer.MAX_VALUE/2;
    //abc109 d
    static void solve(InputReader in, PrintWriter out){
        int h = in.ni(), w = in.ni();
        int[][] a = new int[h][w];
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                a[i][j] = in.ni();
            }
        }
        StringBuilder sb = new StringBuilder();
        long ans = 0;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w-1; j++) {
                if(a[i][j]%2==1){
                    a[i][j] -= 1;
                    a[i][j+1] += 1;
                    sb.append((i+1)+" "+(j+1)+" "+(i+1)+" "+(j+2));
                    sb.append("\n");
                    ans++;
                }
            }
        }
        for (int i = 0; i < h-1; i++) {
            if(a[i][w-1]%2==1){
                a[i][w-1] -= 1;
                a[i+1][w-1] += 1;
                sb.append((i+1)+" "+w+" "+(i+2)+" "+w);
                sb.append("\n");
                ans++;
            }
        }
        out.println(ans);
        out.println(sb.toString());
    }

    public static void main(String[] args){
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public double nd(){
            return Double.parseDouble(ns());
        }
        public char nc(){
            return ns().toCharArray()[0];
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

Measured memory_bytes: 51376
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<cmath>
#include<set>
using namespace std;
typedef long long LL;
const int N=100010;
int n,m;
struct node
{
    int d;
    int p;
} a[N];
struct cmp
{
    bool operator() (int &x,int &y)
    {
        return a[x].p>a[y].p;
    }
};
priority_queue<int,vector<int>,cmp> q;
bool cmp(node x,node y)
{
    return x.d<y.d;
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1; i<=n; i++)
    {
        scanf("%d%d",&a[i].d,&a[i].p);
        if(a[i].d>m) a[i].d=0;
        else
        a[i].d=m-a[i].d+1;
    }
    sort(a+1,a+1+n,cmp);
    while(!q.empty()) q.pop();
    int x;
    LL ans=0;
    for(int i=1; i<=n; i++)
    {
        if(a[i].p>0)
        {
            q.push(i);
            ans+=a[i].p;
        }
        while(q.size()>a[i].d)
        {
            x=q.top();
            ans-=a[x].p;
            q.pop();
        }
    }
    printf("%lld\n",ans);
    return 0;
}


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

using namespace std;
using ll = long long;

int main() {
    ll n; cin >> n;
    ll ans = n + 2;
    for (ll i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ll x = i;
            ll y = n / i;
            x -= 1, y -= 1;
            ans = min(ans, x + y);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
mod = 998244353
S, K = input().split()
a = [len(x) for x in S.split("0")]
K = min(int(K), sum(a)+1)

# f[i][j][k] : 右からi個目の区間まで見て、これまでにj個の1をpick upして、そのうちk個の置き場所が確定しているような操作を行った後の"状態数"
# ans -> f[len(a)][0][0] + f[len(a)][1][1] + ... + f[len(a)][K][K]


def solve_naive():  # TLE解
    f = [[[0 for k in range(K+1)] for j in range(K+1)]
         for i in range(len(a)+1)]

    for i in range(len(a)+1):
        if i == 0:
            # 区間を一つも見ていないので、1を選ぶことができない
            f[i][0][0] = 1
        else:
            for j in range(K+1):
                for k in range(j+1):
                    # 1. 右からi番目の区間a[-i]では何もしない（i.e. a[-i]から1を取らないし、持ってる1をa[-i]に置かない）
                    f[i][j][k] += f[i-1][j][k]
                    f[i][j][k] %= mod

                    # 2. a[-i]に1をいくつか置く
                    for num in range(1, j-k+1):
                        if k + num > K:
                            break
                        f[i][j][k+num] += f[i-1][j][k]  # a[-i]に1をnum個置く
                        f[i][j][k+num] %= mod

                    # 3. a[-i]から1をいくつか取る。
                    # 注: a[-1]に1を「置く」と「取る」を両方することは考えなくてよい。より少ない回数の操作で同じ状態が実現されるので。
                    for num in range(1, a[-i]+1):
                        if j + num > K:
                            break
                        f[i][j+num][k] += f[i-1][j][k]  # a[-i]から1をnum個取る
                        f[i][j+num][k] %= mod
    ans = 0
    for num in range(K+1):
        ans += f[len(a)][num][num]
        ans %= mod
    return ans


def solve():
    f = [[[0 for k in range(K+1)] for j in range(K+1)]
         for i in range(len(a)+1)]

    for i in range(len(a)+1):
        if i == 0:
            # 区間を一つも見ていないので、1を選ぶことができない
            f[i][0][0] = 1
        else:
            for j in range(K+1):
                cum2 = 0
                for k in range(j+1):
                    # 1. 右からi番目の区間a[-i]では何もしない（i.e. a[-i]から1を取らないし、持ってる1をa[-i]に置かない）
                    f[i][j][k] += f[i-1][j][k]
                    f[i][j][k] %= mod

                    # 2. a[-i]に1をいくつか置く
                    # f[i][j][k] += f[i-1][j][0] (a[-i]にk個置く) + f[i-1][j][1]+ ... + f[i-1][j][k-1] (a[-i]に1個置く)
                    f[i][j][k] += cum2
                    f[i][j][k] %= mod
                    cum2 += f[i-1][j][k]

            for k in range(K+1):
                cum3 = 0
                for j in range(k, K+1):
                    # 3. a[-i]から1をいくつか取る。
                    # 注: a[-1]に1を「置く」と「取る」を両方することは考えなくてよい。より少ない回数の操作で同じ状態が実現されるので。
                    # f[i][j][k] += f[i-1][k][k] (a[-i]からj-k個取る) + f[i-1][k+1][k] + .... + f[i-1][j-1][k] (a[-i]から1個取る)
                    if j < a[-i]:
                        f[i][j][k] += cum3
                        f[i][j][k] %= mod
                        cum3 += f[i-1][j][k]
                    else:
                        f[i][j][k] += cum3
                        f[i][j][k] %= mod
                        cum3 += f[i-1][j][k] - f[i-1][j-a[-i]][k]
    ans = 0
    for num in range(K+1):
        ans += f[len(a)][num][num]
        ans %= mod
    return ans


print(solve_naive())


Measured memory_bytes: 107316
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	int N;
	map<string, int> mm;
	cin >> N;
	REP(i, N) {
		string s;
		cin >> s;
		++mm[s];
	}
	
	int mx = 0;
	for (auto it : mm) chmax(mx, it.se);
	
	vector<string> ans;
	for (auto it : mm) if (it.se == mx) ans.push_back(it.fi);
	sort(ALL(ans));
	
	for(auto s : ans) cout << s << endl;
	
	return 0;
}


Measured memory_bytes: 28660
#include<bits/stdc++.h>
using namespace std;
signed main()
{
  string s1,s2;
  cin>>s1>>s2;
  int n=s1.length();
  int cnt=0;
  for(int i=0;i<n;i++)
  {
    //int j=i;
    if(s1[i]!=s2[i])
    {
      cnt++;
    }
  }
  cout<<cnt<<endl;
  return 0;

}

Measured memory_bytes: 3832
#include <iostream>
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <bitset>
#include <stack>
#include <queue>
#include <ctype.h>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
#define MOD 1000000007
#define more(a,b) (((a)>(b))?(a):(b))
#define less(a,b) (((a)<(b))?(a):(b))

using namespace std;

int main(void)
{
	int N, K; cin >> N >> K;
	vector<int> V(3); cin >> V[0] >> V[1] >> V[2];//R:0,S:1,P:2
	string T; cin >> T;
	vector<int> T_N(N);
	rep(i, 0, N) {
		if (T[i] == 'r')T_N[i] = 2;
		else if (T[i] == 's')T_N[i] = 0;
		else if (T[i] == 'p')T_N[i] = 1;
	}
	vector<vector<int>> d(N, vector<int>(3));
	rep(i, 0, K) {
		d[i][T_N[i]] = V[T_N[i]];
		for (int j = i + K; j < N; j += K) {
			rep(k, 0, 3) {
				if (T_N[j] == k)d[j][k] = max(d[j - K][(k + 1) % 3], d[j - K][(k + 2) % 3]) + V[k];
				else d[j][k] = max(d[j - K][(k + 1) % 3], d[j - K][(k + 2) % 3]);
			}
		}
	}
	int ans = 0;
	rep(i, 1, 1 + K)ans += max(d[N - i][0], max(d[N - i][1], d[N - i][2]));
	cout << ans << endl;

	return 0;
}


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

bool hoge(int a[], int i, int left, int right)
{
    if (i==10)
        return true;
    if (left < a[i])
        if (hoge(a, i+1, a[i], right))
            return true;
    if (right < a[i])
        if (hoge(a, i+1, left, a[i]))
            return true;
    return false;
}

int main(void) {
    int n, a[10];
    cin >> n;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < 10; ++j)
            cin >> a[j];
        cout << ((hoge(a, 0, 0, 0))? "YES" : "NO") << endl;
    }
    return 0;
}



Measured memory_bytes: 2972
s = list(input())
K = int(input())
for i in range(len(s)):
  K -= (97 - ord(s[i]))%26
  if K < 0:
    K += (97 - ord(s[i]))%26
  else:
    s[i] = 'a'
s[-1] = chr(((ord(s[-1])+K)-97)%26+97)
for i in s:
  print(i,end="")

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

int main(){
  int i,j,cnt=0;
  int n,k;
  cin>>n>>k;
  int a[n];
  for(i=0;i<n;i++)cin>>a[i];
  cout<<(n+k-3)/(k-1);
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int pos[10001];
char a[6],b[8],c[6];
int main(){
	string s;
	int len,i;
	char x;
	for(i=1;i<=5;i++){
		cin>>a[i];
	}
	cin>>x;
	for(i=1;i<=7;i++){
		cin>>b[i];
	}
	cin>>x;
	for(i=1;i<=5;i++){
		cin>>c[i];
	}
	for(i=1;i<=5;i++){
		cout<<a[i];
	}
	cout<<" ";
	for(i=1;i<=7;i++){
		cout<<b[i];
	}
	cout<<" ";
	for(i=1;i<=5;i++){
		cout<<c[i];
	}
	return 0;
}



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

int calc_div_w(const int h, const int w, const int k, const int dh, const vector<string> &S){
  int div = 0;
  for (int i=0; i<h-1; i++){
    if((dh>>i) & 1) div++;
  }

  vector<int> mem(div+1);
  int ans = div;

  for (int i=0; i<w; i++){
    int d = 0;
    vector<int> add(div+1);
    for (int j=0; j<h; j++){
      if (S[j][i] == '1'){
        mem[d]++;
        add[d]++;
      }
      if ((dh>>j) & 1) d++;
    }

    bool over = false;
    for (int j=0; j<div+1; j++){
      if (mem[j] > k){
        over = true;
        ans++;
        break;
      }
    }

    if (over){
      for (int j=0; j<div+1; j++){
        mem[j] = add[j];
        if (mem[j] > k) return -1;
      }
    }
  }

  return ans;
}


int main(){
  int h, w, k;
  cin >> h >> w >> k;
  vector<string> S(h);
  for(int i=0; i<h; i++) cin >> S[i];

  int ans = h+w;
  for (int i=0; i<(1<<(h-1)); i++){
    int a;
    a = calc_div_w(h ,w, k, i, S);
    if (a != -1) ans = min(ans, a);
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

int main()
{
	
	char S[15];
	char U[15];
	char T[15];
	int A;
	int B;
	scanf("%s %s %d %d %s",&S,&T,&A,&B,&U);
	if(strcmp(U,S)==0)
	{
		printf("%d %d",A - 1,B);
	}
	if(strcmp(U,T)==0)
	{
		printf("%d %d",A,B - 1);
	}
	
	return 0;	
}
	

Measured memory_bytes: 1708
using System;
using System.Collections.Generic;

namespace ConsoleApp3_ITP1_5_A
{
    class Program
    {
        static void Main(string[] args)
        {
            List<string[]> inputList = new List<string[]>();

            for (; ; )
            {
                string[] input = Console.ReadLine().Split(' ');
                var height = input[0];
                var width = input[1];

                if (height == "0" && width == "0")
                {
                    break;
                }
                else
                {
                    inputList.Add(input);
                }
            }
            foreach(string[] ary in inputList)
            {
                var h = Int32.Parse(ary[0]);
                var w = Int32.Parse(ary[1]);

                for (int j = 1; j <= h; j++)
                {
                    for (int i = 1; i <= w; i++)
                    {
                        Console.Write("#");
                    }
                    Console.Write("\n");
                }
                Console.Write("\n");
            }
        }
    }
}


Measured memory_bytes: 9036
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll n;
string s;
ll cnt;
ll ans;
int main(void){
    cin>>n>>s;
    for(int i=0;i<n;i++){
        if(s[i]=='W') cnt++;
    }
    for(int i=0;i<n-cnt;i++){
        if(s[i]=='W') ans++;
    }
    cout<<ans<<endl;
    
}



Measured memory_bytes: 3728
#include <cstdio>

int main()
{
	int a,b,c;
	scanf("%d %d %d", &a, &b, &c);
	if(a==5 and b==5 and c==7)
	{
		printf("YES");
	}
	else if(a==5 and b==7 and c==5)
	{
		printf("YES");
	}
	else if(a==7 and b==5 and c==5)
	{
		printf("YES");
	}
	else
	{
		printf("NO");
	}
}
	

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

int main() {
  int N,M;
  cin >> N >> M ;
  
  vector<int> L(M),R(M);
  for ( int i = 0 ; i < M ; i++ )
    cin >> L.at(i) >> R.at(i);
  
  int max_L = 0 ,min_R = pow(10,5.0);
  for ( int i = 0 ; i < M ; i++ ){
  	if ( L.at(i) > max_L )
      max_L = L.at(i);
    if ( R.at(i) < min_R )
      min_R = R.at(i);
  }
  
  if ( max_L <= min_R ){
    if ( N < max_L )
      cout << 0 << endl;
  	else if ( N >= max_L && N <= min_R )
      cout << N - max_L +1 << endl;
  	else
      cout << min_R - max_L + 1 << endl;
  	}
  else
    cout << 0 << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ri register int
namespace io {
	const int SIZE = (1 << 21) + 1;
	char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
	// getchar
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	// print the remaining part
	inline void flush () {
		fwrite (obuf, 1, oS - obuf, stdout);
		oS = obuf;
	}
	// putchar
	inline void putc (char x) {
		*oS ++ = x;
		if (oS == oT) flush ();
	}
	// input a signed integer
	template <class I>
	inline void gi (I &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = (x << 1) + (x << 3) + (c & 15); x *= f;
	}
	// print a signed integer
	template <class I>
	inline void print (I x) {
		if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10;
		while (qr) putc (qu[qr --]);
	}
	// no need to call flush at the end manually!
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
} 
using io :: gi;
using io :: putc;
using io :: print;
const int N=2e5+5,inf=2e9;
int a[N];
inline int checkmax(ri l,ri r){
	ri i,j,res=-inf;
	for(i=l,j=r;i<j;++i,--j) res=max(res,a[i]+a[j]);
	return res;
}
inline int checkmin(ri l,ri r){
	ri i,j,res=inf;
	for(i=l,j=r;i<j;++i,--j) res=min(res,a[i]+a[j]);
	return res;
}
int main(){
	ri n,m,i,size,l,r,mid;
	gi(n);gi(m);
	size=n<<1;
	for(i=1;i<=size;++i) gi(a[i]);
	sort(a+1,a+1+size);
	l=0;r=n;
	while(l<=r){
		mid=l+r>>1;
		if(checkmin(mid<<1|1,size)>=m)
			r=mid-1;
		else
			l=mid+1;
	}
	i=r+1;
	if(!i) printf("%d\n",checkmax(1,size)-m);
	else if(i==n) printf("%d\n",checkmax(1,i<<1));
	else printf("%d\n",max(checkmax(1,i<<1),checkmax(i<<1|1,size)-m));
	return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define int long long 
const long long inf=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long > > vpll;
typedef vector<pair<int, int > > vpii;
#define FORR(x,arr) for(auto& x:arr)
#define ZERO(a) memset(a,0,sizeof(a))





//3111111111111111111111111111111
	
	class unionfind {
	vector<int> par, rank;
 
	public:
	void init(int n) {
		par.resize(n);
		rank.resize(n);
 
		for (int i = 0; i < n; i++) {
			par[i] = i;
			rank[i] = 0;
		}
	}
 
	int find(int x) {
		if (par[x] == x) return x;
		else return par[x] = find(par[x]);
	}
 
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) return ;
 
		if (rank[x] < rank[y]) par[x] = y;
		else {
			par[y] = x;
			if (rank[x] == rank[y]) ++rank[x];
		}
	}
	};



	void solve(){


		ini(n);
		ini(n1);
		unionfind uf;
		uf.init(n);
		priority_queue<pair<int,pair<int,int> >> morty;
		FOR(i,0,n1){
			ini(tmp,tmp1,tmpp);
			tmpp*=-1;
			morty.push({tmpp,{tmp,tmp1}});
		}
		int rick = 0;
		while(!morty.empty()){
			auto x = morty.top();
			morty.pop();
			if(uf.find(x.second.first)!=uf.find(x.second.second)){
				uf.unite(x.second.first,x.second.second);
				rick+=x.first;
			}
		}
		out(rick*-1);
		

		


		
		
	}



	



















int32_t main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall 
	oneforall

	solve();
	


	return 0;
}



Measured memory_bytes: 6108
MOD = 10**9+7
fac = [1 for k in range(200010)]
inv = [1 for k in range(200010)]
finv = [1 for k in range(200010)]
for k in range(2,200010):
    fac[k] = (fac[k-1]*k)%MOD
    inv[k] = (MOD - inv[MOD%k] * (MOD // k))%MOD
    finv[k] = (finv[k - 1] * inv[k]) % MOD;
def nCr(n,r):
    return (fac[n]*finv[r]*finv[n-r])%MOD

H, W, A, B = map(int,input().split())
ans = 0

for k in range(W-B):
    ans += nCr(A+W-B-k-2,A-1)*nCr(B+k+1+H-A-2,H-A-1)
    ans %= MOD

print(ans)


Measured memory_bytes: 26904
import sys
input = sys.stdin.readline


def main():
    N, Q = map(int, input().split())

    total = 0
    queue = []

    for _ in range(N):
        inp = input().split()
        inp[1] = int(inp[1])
        queue.append(inp)

    # print(queue)

    while len(queue):
        process = queue.pop(0)
        if process[1] - Q > 0:
            total += Q
            process[1] -= Q
            queue.append(process)
        else:
            total += process[1]
            print("{0} {1}".format(process[0], total))


if __name__ == '__main__':
    main()



Measured memory_bytes: 16848
import sys
input = sys.stdin.readline

Days = int(input())
C = list(map(int, input().split())) # 満足度低下
Ss = [list(map(int, input().split())) for _ in range(Days)]
# Ss[d][i]: d日目にiを開催したときの満足度
T = [int(input()) for _ in range(Days)] # 開催するコンテスト

last = [0]*26

satisfied = 0
for d, t in enumerate(T):
    t -= 1; d += 1
    satisfied += Ss[d-1][t]
    last[t] = d
    for i, c in enumerate(C):
        satisfied -= c*(d-last[i])
    print(satisfied)

Measured memory_bytes: 74756
#include <bits/stdc++.h>  // clang-format off
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef _MY_DEBUG
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sun Apr  5 15:01:13 JST 2020
 **/

signed main() {
    Int K;
    std::cin >> K;
    std::priority_queue<Int, std::vector<Int>, std::greater<Int>> pq;
    REP(i, 1, 10) pq.push(i);
    REP(k, K - 1) {
        Int x = pq.top();
        pq.pop();
        REP(i, 10) {
            if (std::abs(i - x % 10) > 1) continue;
            pq.push(x * 10 + i);
        }
    }
    std::cout << pq.top() << std::endl;
}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
#define err(...) fprintf(stderr, __VA_ARGS__), fprintf(stderr, "\n"), fflush(stderr)

typedef long long ll;

using namespace std;

const ll inf = static_cast<const ll>(1e18);
const int infi = static_cast<const int>(1e9);


void solve() {
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(a, b) << ' ' << max(a + b - n, 0);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#ifdef SIR
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    solve();
}

Measured memory_bytes: 256
A,B,M = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = min(a) + min(b)

for i in range(M):
    x,y,d = map(int,input().split())
    c = min(c,a[x-1]+b[y-1]-d)

print(c)

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

#define rep(i, n) for(int i=0; i<(int)n; i++)
#define all(v) (v).begin(), (v).end()

int main(){
  int N,K;cin>>N>>K;
  vector<int> p(N);
  rep(i,N)cin>>p[i];

  sort(all(p));

  int ans = 0;
  rep(i,K){
    ans += p[i];
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define M 1000000007
int main(void)
{
	int n,m,i,cnt,sam,y;
	int t[10001];
	char s[10002][9],fb[9]="FizzBuzz",b[5]="Buzz",f[5]="Fizz";
	while(1){
		scanf("%d %d",&m,&n);
		if(m==0&&n==0) break;
		for(i=1;i<=n;i++) scanf("%s", s[i]);
		for(i=0;i<=m;i++) t[i]=i;
		cnt=0; sam=0;
		for(i=1;i<=n;i++){
			//printf("i=%d m=%d sam=%d cnt=%d\n",i,m,sam,cnt);
			char k[10]={0};
			sprintf(k,"%d",i);
			//printf("%s %s\n",s[i],k);
			if(i%3==0&&i%5==0){
				if(0!=strcmp(s[i],fb)){
					//printf("AA %d %d %s ",i,(i-sam)%m,s[i]);
					t[(i-sam)]=M;// printf("%d %d\n",i-sam,t[(i-sam)]);
					cnt++;
				}	
			}
			else if(i%5==0){
				if(0!=strcmp(s[i],b)){
					//printf("BB %d %d %s ",i,(i-sam)%m,s[i]);
					t[(i-sam)]=M;//printf("%d %d\n",i-sam,t[(i-sam)]);
					cnt++;
				}
			}
			else if(i%3==0){
				if(0!=strcmp(s[i],f)){
					//printf("CC %d %d %s ",i,(i-sam)%m,s[i]);
					t[(i-sam)]=M;//printf("%d %d\n",i-sam,t[(i-sam)]);
					cnt++;
				}
			}
			else if(0!=strcmp(s[i],k)) t[(i-sam)]=M, cnt++;
			if((i-sam)%m==0) sort(t,t+m+1),sam+=m,m-=cnt,cnt=0;
			if(m-cnt==1) break;
		}
		sort(t,t+m+1);
		m-=cnt;
		//printf("%d\n",m);
		for(i=1;i<m;i++) printf("%d ",t[i]);
		printf("%d\n",t[m]);
	}
	return 0;
}


Measured memory_bytes: 3340