akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
#define INF 1LL<<60

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int N;
    string S;
    cin >> N >> S;

    // unique[i]: i以降でuniqueな数字の個数
    vector<int> unique(N);
    vector<vector<int>> table(10, vector<int>(10)); 
    set<int> s;
    s.insert(int(S[N-1] - '0'));
    unique[N-1] = 1;

    for(int i=N-2; i>=0; i--) {
        int n = int(S[i] - '0');
        if(s.find(n) == s.end()) {
            s.insert(n);
            unique[i] = unique[i+1] + 1;
        } else {
            unique[i] = unique[i+1];
        }
    }

    for(int i=0; i<N-2; i++)
        for(int j=i+1; j<N-1; j++) {
            int n = int(S[i] - '0'), m = int(S[j] - '0');
            if(table[n][m] == 0)
                table[n][m] = unique[j+1];
        }

    int ans = 0;
    for(int i=0; i<10; i++)
        for(int j=0; j<10; j++) {
            ans += table[i][j];
        }
    cout << ans << endl;

    return 0;
}

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

//繰り返し二乗法
ll ex(ll x,ll n){
    if(n==0)return 1;
    else if(n%2==1)return ex(x,n-1)*x;
    else return ex(x*x,n/2);
};

int main(){
    int x;
    cin >> x;
    pair<ll,ll> ans;
    for(int i = 0; i < 5000; i++){
        for(int j = 0; j < 5000; j++){
            ll a = ex(i,5), b = ex(j,5);
            if(a+b == x) ans = {i,-j};
            else if(a-b == x) ans = {i,j};
        }
    }    
    cout << ans .first << " " << ans.second << endl;
}

Measured memory_bytes: 3640
S = list(input())
T = list(input())
ls = len(S)
lt = len(T)
ans = lt
for offset in range(ls - lt + 1):
	cnt = 0
	for i in range(lt):
		if S[offset + i] != T[i]:
			cnt += 1
	ans = min(ans, cnt)
print(ans)

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

typedef long long ll;
const int maxn = 4015, mod = 1e9 + 7;

inline int gi()
{
	char c = getchar();
	while (c < '0' || c > '9') c = getchar();
	int sum = 0;
	while ('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar();
	return sum;
}

inline int add(int x, int y) {return x + y >= mod ? x + y - mod : x + y;}
inline int sub(int x, int y) {return x >= y ? x - y : x - y + mod;}

int n, fac[maxn << 1], ifac[maxn << 1];
int **f, **val, *_f[maxn], *_val[maxn], __f[maxn][maxn], __val[maxn][maxn];

int C(int n, int m)
{
	return (ll)fac[n] * ifac[m] % mod * ifac[n - m] % mod;
}

int main()
{
	n = gi();
	for (int i = 1; i <= 4010; ++i) _f[i] = __f[i] + 2005, _val[i] = __val[i] + 2005;
	f = _f + 2005; val = _val + 2005;

	fac[0] = ifac[0] = ifac[1] = 1;
	for (int i = 1; i <= 8000; ++i) fac[i] = (ll)fac[i - 1] * i % mod;
	for (int i = 2; i <= 8000; ++i) ifac[i] = (ll)(mod - mod / i) * ifac[mod % i] % mod;
	for (int i = 1; i <= 8000; ++i) ifac[i] = (ll)ifac[i - 1] * ifac[i] % mod;
	
	int ans = 0;
	for (int A, B, i = 1; i <= n; ++i) {
		A = gi(); B = gi();
		++val[A][B]; ++val[-A][-B];
		++f[A][B];
		ans = sub(ans, C((A << 1) + (B << 1), (A << 1)));
	}

	for (int i = 2000; i >= -2000; --i)
		for (int j = 2000; j >= -2000; --j) {
			if (!f[i][j]) continue;
			if (i > -2000) f[i - 1][j] = add(f[i - 1][j], f[i][j]);
			if (j > -2000) f[i][j - 1] = add(f[i][j - 1], f[i][j]);
		}

	for (int i = -1; i >= -2000; --i)
		for (int j = -1; j >= -2000; --j)
			if (val[i][j]) ans = add(ans, (ll)val[i][j] * f[i][j] % mod);
	printf("%lld\n", (ll)ans * (mod + 1) / 2 % mod);
	
	return 0;
}



Measured memory_bytes: 125568
#include "bits/stdc++.h"
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/dynamic_bitset.hpp>
namespace adaptor = boost::adaptors;
using index_t = std::size_t;

namespace lib
{
	using graph_t = std::vector<std::set<index_t>>;
	template<class T>using weighted_graph_t = std::vector<std::map<index_t, T>>;

	struct max_t
	{
		template<class T>constexpr T operator()(T const& lhs, T const& rhs)const
		{
			return std::max(lhs, rhs);
		}
	};
	struct min_t
	{
		template<class T>constexpr T operator()(T const& lhs, T const& rhs)const
		{
			return std::min(lhs, rhs);
		}
	};

	constexpr max_t max;
	constexpr min_t min;

	template<class T>auto order_by(T func)
	{
		return [=](auto&& lhs, auto&& rhs)
		{
			return func(lhs) < func(rhs);
		};
	}

	template<class T>constexpr auto max_v = std::numeric_limits<T>::max();
	template<class T>constexpr auto min_v = std::numeric_limits<T>::min();

	template<class T>using p_queue = std::priority_queue<T, std::vector<T>, std::greater<>>;
}

void Main()
{
	int X;
	std::cin >> X;
	std::cout << (30 <= X ? "Yes" : "No") << std::endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

Measured memory_bytes: 3644
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;


template<class T> class BIT   // 1-indexed (0 is not used)
{
private:
    int num;
    vector<T> bit;
public:
    BIT(int n):bit(vector<T>(n+1, 0)), num(n) {}

    T sum(int i) {   // sum of 1..i
        if (!i) return 0;
        return bit[i] + sum(i-(i&-i));
    }

    void add(int i, T x) {
        if (i > num) return;
        bit[i] += x;
        add(i+(i&-i), x);
    }

    int lower_bound(T x) {
        T res=0;
        int N=1;
        while(N<num) N*=2;
        int i;
        for(i=N/2; i>0; i/=2) {
            if(res+i<num && bit[res+i]<x) {
                x = x - bit[res +i];
                res = res + i;
            }
        }
        return res + 1;
    }
};

int main(int argc, char* argv[])
{
    int n;
    scanf("%d", &n);
    vector<int> a(n);
    set<int> z;
    int i;
    for(i=0; i<n; i++) {
        scanf("%d", &a[i]);
        z.insert(a[i]);
    }
    vector<int> b;
    copy(z.begin(), z.end(), back_inserter(b));
    int siz=(int)b.size();

    int l=-1,r=siz;
    while(r-l>1) {
        int m=(l+r)/2;
        vector<int> aa(n),saa(n+1);
        for(i=0; i<n; i++) {
            if(a[i]<b[m]) aa[i]=1;
            else aa[i]=-1;
            saa[i+1]=saa[i]+aa[i];
        }

        ll sum=0;
        int num=n+10;
        BIT<int> bit(num*2);
        for(i=0; i<n+1; i++) {
            sum+=bit.sum(saa[i]+num-1);
            bit.add(saa[i]+num, 1);
        }
        if(sum>(ll)n*(n+1)/4) {
            r=m;
        }
        else {
            l=m;
        }
    }
    printf("%d\n", b[l]);

    return 0;
}



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

const int max_n = 50;
const int max_s = (max_n - 1) * 50;

struct train
{
    int v, a, b;
    train(int v, int a, int b) : v(v), a(a), b(b) {}
};

struct change
{
    int c, d;
};

struct data
{
    int i, s;
    long long t;
    data(int i, int s, long long t) : i(i), s(s), t(t) {}

    bool operator<(const data &d) const
    {
        return t > d.t;
    }
};

int main()
{
    int n, m, s;
    std::cin >> n >> m >> s;
    std::vector<train> t[max_n];
    for (int i = 0; i < m; ++i)
    {
        int u, v, a, b;
        std::cin >> u >> v >> a >> b;
        --u;
        --v;
        t[u].emplace_back(v, a, b);
        t[v].emplace_back(u, a, b);
    }

    change c[max_n];
    for (int i = 0; i < n; ++i)
    {
        std::cin >> c[i].c >> c[i].d;
    }

    long long time[max_n][max_s + 1];
    for (int i = 0; i < max_n; ++i)
    {
        std::fill(time[i], time[i] + max_s + 1, LONG_LONG_MAX);
    }

    std::priority_queue<data> q;
    auto push = [&](int i, int s, long long t) {
        int mins = std::min(s, max_s);
        if (mins < 0)
        {
            return;
        }
        if (time[i][mins] <= t)
        {
            return;
        }
        time[i][mins] = t;
        q.emplace(i, mins, t);
    };
    push(0, s, 0);

    while (!q.empty())
    {
        data d = q.top();
        q.pop();
        if (d.t > time[d.i][d.s])
        {
            continue;
        }

        for (int j = 0; j < t[d.i].size(); ++j)
        {
            push(t[d.i][j].v, d.s - t[d.i][j].a, d.t + t[d.i][j].b);
        }
        push(d.i, d.s + c[d.i].c, d.t + c[d.i].d);
    }

    for (int i = 1; i < n; ++i)
    {
        long long min = LONG_LONG_MAX;
        for (int j = 0; j <= max_s; ++j)
        {
            min = std::min(time[i][j], min);
        }
        std::cout << min << std::endl;
    }

    return 0;
}

Measured memory_bytes: 6144
a,b,c,d=map(int,input().split())

hp_t=a
hp_a=c

while hp_a>0 and hp_t>0:
    hp_a=hp_a - b
    if hp_a<=0:
        print("Yes")
        break
    hp_t=hp_t - d
    if hp_t<=0:
        print("No")
        break

Measured memory_bytes: 61596
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <algorithm>
#include <set>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#define REP(i, n) for(int i=0; i<n; i++)
#define REPR(i, n) for(int i=n; i>0; i--)
#define FOR(i, m, n) for(int i=m; i<n; i++)
#define FORR(i, m, n) for(int i=m; i>=n; i--)
#define INF 1999999999
#define VSORT(v) sort(v.begin(), v.end())
#define pb(a) push_back(a)
using namespace std;
typedef long long ll;

#ifdef INPUT
stringstream input(R"(
100 100 100
)");
#define cin input
#endif

int main()
{
    int n, a, b, max, min;
    cin >> n >> a >> b;
    max = min = 0;

    if (a>=b)
        max = b;
    else
        max = a;

    if (a+b > n)
        min = a+b-n; 

    cout << max << " " << min << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
public class Main {
    static class Scan {
        private byte[] buf=new byte[1024];
        private int index;
        private InputStream in;
        private int total;
        public Scan()
        {
            in=System.in;
        }
        public int scan()throws IOException
        {
            if(total<0)
            throw new InputMismatchException();
            if(index>=total)
            {
                index=0;
                total=in.read(buf);
                if(total<=0)
                return -1;
            }
            return buf[index++];
        }
        public int scanInt()throws IOException
        {
            int integer=0;
            int n=scan();
            while(isWhiteSpace(n))
            n=scan();
            int neg=1;
            if(n=='-')
            {
                neg=-1;
                n=scan();
            }
            while(!isWhiteSpace(n))
            {
                if(n>='0'&&n<='9')
                {
                    integer*=10;
                    integer+=n-'0';
                    n=scan();
                }
                else throw new InputMismatchException();
            }
            return neg*integer;
        }
        public double scanDouble()throws IOException
        {
            double doub=0;
            int n=scan();
            while(isWhiteSpace(n))
            n=scan();
            int neg=1;
            if(n=='-')
            {
                neg=-1;
                n=scan();
            }
            while(!isWhiteSpace(n)&&n!='.')
            {
                if(n>='0'&&n<='9')
                {
                    doub*=10;
                    doub+=n-'0';
                    n=scan();
                }
                else throw new InputMismatchException();
            }
            if(n=='.')
            {
                n=scan();
                double temp=1;
                while(!isWhiteSpace(n))
                {
                    if(n>='0'&&n<='9')
                    {
                        temp/=10;
                        doub+=(n-'0')*temp;
                        n=scan();
                    }
                    else throw new InputMismatchException();
                }
            }
            return doub*neg;
        }
        public String scanString()throws IOException
        {
            StringBuilder sb=new StringBuilder();
            int n=scan();
            while(isWhiteSpace(n))
            n=scan();
            while(!isWhiteSpace(n))
            {
                sb.append((char)n);
                n=scan();
            }
            return sb.toString();
        }
        private boolean isWhiteSpace(int n)
        {
            if(n==' '||n=='\n'||n=='\r'||n=='\t'||n==-1)
            return true;
            return false;
        }
    }
    public static void main(String args[]) throws IOException {
        Scan input=new Scan();
        int a=input.scanInt();
        int b=input.scanInt();
        System.out.println(a*b);
    }
}


Measured memory_bytes: 32352
def main():
    import sys
    input = sys.stdin.readline

    N = int(input())
    A = list(map(int, input().split()))

    cnt = [0] * 61
    for a in A:
        for j in range(61):
            if a >> j & 1:
                cnt[j] += 1
    ans = 0
    for j in range(61):
        if cnt[j] & 1:
           ans += 1<<j
    mask = ((1<<61) - 1) ^ ans
    for i in range(N):
        A[i] &= mask

    rnk = 0
    for j in range(60, -1, -1):
        for i in range(rnk, N):
            if A[i] >> j & 1:
                A[rnk], A[i] = A[i], A[rnk]
                a = A[rnk]
                for ii in range(N):
                    if ii == rnk:
                        continue
                    if A[ii] >> j & 1:
                        A[ii] ^= a
                rnk += 1
                break
    ans2 = 0
    for i in range(rnk):
        ans2 ^= A[i]
    print(ans + ans2 * 2)


if __name__ == '__main__':
    main()


Measured memory_bytes: 69408
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <map>
#include <vector>

using namespace std;

int main(){
	
	string str[10];
	int num1[10], num2[10];
	
	for(int i = 0; i < 9; i++){
		cin >> str[i] >> num1[i] >> num2[i];
	}
	
	
	for(int i = 0; i < 9; i++){
		cout << str[i] << " " << num1[i] + num2[i] << " " << num1[i] * 200 + num2[i] * 300 << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<ii> vii;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define fr(be, en) for(int i = be; i <= en; i++) 
ll mod = LLONG_MAX;
ll power(ll a, ll b)
{
	if(b == 0) return 1;
	ll ans = power(a, b/2);
	ans = (ans*ans)%mod;
	if(b%2) ans*=a;
	return ans%mod;
}
ll mul(ll a,ll n, ll mod)
{
	ll ret;
	if(n==0) return 0;
	ret = mul(a,n/2, mod);
	ret = (ret+ret)%mod;
	if(n%2)	ret=(ret+a)%mod;
	return ret;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cout.tie(NULL);
	cin.tie(NULL);
	int x;
	cin >> x;
	cout << 1 - x;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long 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; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=998244353;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};


int M_N = 200000;

vector<LL> fact;
vector<LL> inver(M_N+1);
 
LL combi(int n,int r){
    if(n<r||n<0||r<0) return 0;
    return fact[n]%mod*inver[n-r]%mod*inver[r]%mod;
}
 
 
LL fpow(LL a, LL n){
    LL x = 1;
    while(n > 0){
        if(n&1){
            x=x*a%mod;
        }
        a=a*a%mod;
        n >>= 1;
    }
    return x;
}
 
void set_combi(){
    LL s=1;
    fact.push_back(1);
    for(int i=1;i<=M_N;i++){
        s*=i;
        s%=mod;
        fact.push_back(s);
    }
    inver[M_N]=fpow(fact[M_N],mod-2);
    for(int i=M_N-1;i>=0;i--){
        inver[i]=inver[i+1]*(i+1)%mod;
    }
}
 
LL hcombi(int n,int r){
    return combi(n+r-1,r); 
}

int main(){
    set_combi();
    int n,x;cin >> n >> x;
    vector<vector<LL>> dp(n + 1, vector<LL> (512, 0));
    dp[0][0] = 1;
    for (int k = 0; k <= x; k++) {
        for (int i = n - 1; i >= 0; i--) {
            for (int j = 0; j < 512; j++) {
                dp[i+1][j^k] = (dp[i+1][j^k] + dp[i][j])%mod;
            }
        }
    }
    LL ans = 0;
    for (int i = 0; i <= n; i++) {
        if((n - i) % 2) continue;
        ans = (ans + dp[i][x] * hcombi(x + 1, (n - i) / 2))%mod;
    }
    cout << ans << endl;
    return 0;
}






Measured memory_bytes: 8096
use proconio::{fastout, input};
use rand::prelude::*;
use std::cmp::Ordering;

pub fn quicksort<T, R>(a: &mut [T], rng: &mut R)
where
    T: Ord,
    R: Rng + ?Sized,
{
    quicksort_impl(a, rng);
}

fn get_pivot<T>(a: &[T], i: usize, j: usize, k: usize) -> usize
where
    T: Ord,
{
    if a[i] < a[j] {
        if a[j] < a[k] {
            j
        } else if a[k] < a[i] {
            i
        } else {
            k
        }
    } else {
        if a[k] < a[j] {
            j
        } else if a[i] < a[k] {
            i
        } else {
            k
        }
    }
}

fn quicksort_impl<T, R>(a: &mut [T], rng: &mut R)
where
    T: Ord,
    R: Rng + ?Sized,
{
    let n = a.len();
    if n <= 1 {
        return;
    }
    let mut r = get_pivot(a, 0, (n - 1) / 2, n - 1);
    let mut p = 0;
    let mut j = 0;
    let mut q = n;
    while j < q {
        match a[j].cmp(&a[r]) {
            Ordering::Less => {
                a.swap(j, p);
                if r == p {
                    r = j;
                } else if r == j {
                    r = p;
                }
                p += 1;
                j += 1;
            }
            Ordering::Equal => {
                j += 1;
            }
            Ordering::Greater => {
                q -= 1;
                a.swap(j, q);
                if r == q {
                    r = j;
                } else if r == j {
                    r = q;
                }
            }
        }
    }
    quicksort_impl(&mut a[..p], rng);
    quicksort_impl(&mut a[q..], rng);
}

#[fastout]
fn main() {
    input! {
        n: usize,
        mut a: [i64; n],
    }
    a.sort();
    if a[0] == 0 {
        println!("0");
        return;
    }
    let mut prod = 1;
    for x in a {
        if prod > 1_000_000_000_000_000_000 / x {
            println!("-1");
            return;
        }
        prod *= x;
    }
    println!("{}", prod);
}


Measured memory_bytes: 5120
#!/usr/bin/env python3
import sys

MOD = 998244353  # type: int

def solve(N: int, S: str):
    # N = 2 * (10 ** 5)
    # S = 'R' * N + 'G' * N + 'B' * N
    c2n = {'R': 0, 'G': 1, 'B': 2}
    rgb = [[] for i in range(3)]

    for i, c in enumerate(S):
        c = c2n[c]
        rgb[c].append(i)
    
    S = [0] * N
    M = [0] * N
    L = [0] * N

    for i, t in enumerate(zip(*rgb)):
        S[i], M[i], L[i] = sorted(t)

    # print(S)
    # print(M)
    # print(L)
    # print("done")

    ri = [0] * 3 * N # ri[i]: iより大きいLの要素の数
    le = [0] * 3 * N

    j = N-1
    lj = L[j]
    count = 0
    for i in range(3*N-1, -1, -1):
        if i >= lj:
            ri[i] = count
            continue
        j -= 1
        lj = L[j] if j >= 0 else 0
        count += 1
        ri[i] = count

    j = 0
    sj = S[j]
    count = 0
    for i in range(3*N):
        if i <= sj:
            le[i] = count
            continue
        j += 1
        sj = S[j] if j <= N-1 else 3*N
        count += 1
        le[i] = count
    
    # print(ri)
    # print(le)

    res = 1
    for i, m in enumerate(M):
        cl = i
        cr = N-1-i
        res *= (le[m] - cl)
        res %= MOD
        res *= (ri[m] - cr)
        res %= MOD
    
    for i in range(1, N+1):
        res *= i
        res %= MOD
    
    print(res)
        
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 57396
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define PRINT(x) cout<<(x)<<endl
#define INF 1000000000000 // 10^12
#define MOD 1000000007 // 10^9+7
#define PB push_back
#define MP make_pair

const int MAX_N = 100, MAX_P = 100;

int X, N, p[MAX_N];

bool flag[MAX_P + 2];

int main() {
    REP(i, MAX_P + 2) flag[i] = false;

    cin >> X >> N;
    REP(i, N) {
        cin >> p[i];
        flag[p[i]] = true;
    }

    int ans;
    REP(d, X+1) {
        if (flag[X - d] == false) {
            ans = X - d;
            break;
        }
        if (flag[X + d] == false) {
            ans = X + d;
            break;
        }
    }
    PRINT(ans);
    return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define FSP(x) fixed << setprecision(x)
using namespace std;
using ll = long long;
constexpr ll INF = LLONG_MAX;
constexpr long double PI = acosl(-1);
void Yes() {cout << "Yes\n";}
void No() {cout << "No\n";}
void YES() {cout << "YES\n";}
void NO() {cout << "NO\n";}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	//constexpr ll P = 1e9 + 7;
	//constexpr ll P = 998244353;

	ll d, t, s;
	cin >> d >> t >> s;
	if (s * t >= d) Yes();
	else No();
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
#include <boost/range/adaptors.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;
using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long int;

int main() {
    ll N;
    cin >> N;
    vector<vector<pair<ll, ll>>> nodes(N, vector<pair<ll, ll>>{});
    for (auto &&i: boost::irange(0LL, N-1)){
        ll a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        nodes.at(a).emplace_back(make_pair(c, b));
        swap(a, b);
        nodes.at(a).emplace_back(make_pair(c, b));
    }
    vector<ll> costs(N, numeric_limits<ll>::max());
    ll Q, K;
    cin >> Q >> K;
    K--;
    costs.at(K) = 0LL;
    vector<ll> stack{};
    stack.emplace_back(K);
    while(!stack.empty()){
        ll now = stack.back();
        stack.pop_back();
        for (auto &&p: nodes.at(now)){
            ll cost, next;
            tie(cost, next) = p;
            if (costs.at(next)==numeric_limits<ll>::max()){
                costs.at(next) = costs.at(now)+cost;
                stack.emplace_back(next);
            }
        }
    }
//    for (auto &&i: boost::irange(0LL, N)){
//        cout << costs.at(i) << " ";
//    }
//    cout << endl;
    for (auto &&i: boost::irange(0LL, Q)){
        ll x, y;
        cin >> x >> y;
        x--;
        y--;
        cout << costs.at(x)+costs.at(y) << endl;
    }
    return 0;
}

Measured memory_bytes: 10992
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	string s; cin>>s;
	int n=s.size();
	cout<<string(n,'x')<<endl;
	return 0;
}


Measured memory_bytes: 3592
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<map>
#include<queue>
#include<set>
#include<bitset>
#include<stdio.h>
#include<deque>
#include<iomanip>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long int ll;
typedef pair<int, int> P;
const ll mod = 1e9+7;
int main()
{
    int n,m;
    cin >> n >> m;
    vector<int> f(n+1, true);
    rep(i, m){
        int a;
        cin >> a;
        f[a] = false;
    }
    vector<ll> dp(n+1);
    dp[0] = 1;
    for(int i = 0; i < n; i++){
        for(int j = i+1; j <= min(n, i+2); j++){
            if(f[j]){
                dp[j]+=dp[i];
                dp[j] %= mod;
            }
        }
    }
    cout << dp[n] << endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

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

	ll n;
	cin >> n;
	vll x(n), y(n), h(n);
	ll hmax = 0;
	REP(i, n){
		cin >> x[i] >> y[i] >> h[i];
		hmax = max(hmax, h[i]);
	}

	REP(sx, 101){
		REP(sy, 101){
			FOR(H, hmax, hmax + 200){
				ll flg = 1;
				REP(i, n){
					if(max(H - abs(sx - x[i]) - abs(sy - y[i]), (ll)0) != h[i]) flg = 0;
				}
				if(flg)	cout << sx << " " << sy << " " << H << endl;
			}
		}
	}
    return 0;
}

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

bool f(const long kind, const size_t n, const vector<long>& a){
    map<long,long> c;
    long len = a[0];
    for(size_t i=1; i<n; i++){
        const long n_len = a[i];
        if(len>=n_len){
            c.erase(c.lower_bound(n_len), c.end());
            long j=n_len-1;
            for(;;){
                auto it = c.find(j);
                if(it == c.end()){
                    it = c.insert(c.end(), make_pair(j, 1));
                }else{
                    it->second++;
                }
                if(it->second<kind){
                    c.erase(c.upper_bound(j), c.end());
                    break;
                }else if(j<=0){
                    return false;
                }else{
                    j--;
                }
            }
        }
        len = n_len;
    }
    return true;
}

bool strict_increasing(const vector<long>& a){
    size_t n = a.size();
    for(size_t i=1; i<n; i++){
        if(a[i-1]>=a[i]){
            return false;
        }
    }
    return true;
}

int main(void){
    long n;
    cin >> n;
    vector<long> a(n);
    for(long i=0; i<n; i++){
        cin >> a[i];
    }
    if(strict_increasing(a)){
        cout << 1 << endl;
        return 0;
    }
    long left=1, right=n;
    for(;;){
        const long mid = (left+right)/2;
        if(right-left<=1){
            if(f(right, n, a)){
                cout << right << endl;
            }else{
                cout << left << endl;
            }
            return 0;
        }
        const bool b = f(mid, n, a);
        //printf("[%ld, %ld] %ld %s\n", left, right, mid, b ? "true" : "false");
        if(b){
            right=mid;
        }else{
            left=mid;
        }
    }
}


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

int comb2(int n){
  int c = n * (n-1);
  if(c>1){
    return c/2;
  }
  else return 0;
}

int main(){
  int m, n, sum=0;
  cin >> n >> m;
  sum += (comb2(n) + comb2(m));
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
int main (void) {
    int N;
    int K;
    int ans = 0;

    cin >> N >> K;
    for (int i = 0; i < N; i++) {
        int x;
        cin >> x;
        ans += 2 * min(x, K - x);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <math.h>
#include <limits.h>
#define swap(type,a,b) do{type t=a;a=b;b=t;}while(0);
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ll long long
#define INF 100000000
#define MOD 1000000007
#define SIZE 100005
#define FOR(i,a,n) for(i=(a);i<(n);i++)
int comp(const void* a,const void* b){
	return *(int*)a-*(int*)b;
}
int a[2000];
int main(void)
{
	int z,w,n,max,min,i;
	scanf("%d%d%d",&n,&z,&w);
	FOR(i,0,n) scanf("%d",a+i);
	if(n==1) printf("%d\n",abs(a[0]-w));
	else if(abs(a[n-2]-a[n-1])>abs(a[n-1]-w)) printf("%d\n",abs(a[n-2]-a[n-1]));
	else printf("%d\n",abs(a[n-1]-w));
	return 0;
}


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

// boost
#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::cpp_int;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using vld = vector<ld>;
using vvld = vector<vld>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
// #define mod (998244353ll)

const long long INF = 1LL << 60;

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

  string s, t;
  cin >> s >> t;

  vll x(s.size() + 1);
  vll y(t.size() + 1);
  rep(i, s.size()) {
    ll add = (s[i] == 'A') ? 2 : 1;
    x[i + 1] = x[i] + add;
  }

  rep(i, t.size()) {
    ll add = (t[i] == 'A') ? 2 : 1;
    y[i + 1] = y[i] + add;
  }

  ll q;
  cin >> q;
  rep(i, q) {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    if ((x[b] - x[a - 1]) % 3 == (y[d] - y[c - 1]) % 3) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }

  return 0;
}


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

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

int main(){
	int X;
	cin >> X;
	if(X==7 || X==5 || X==3){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
fun main(args:Array<String>){

    var (n) = readLine()!!.split(" ").map { it.toInt() }
    var (h) = readLine()!!.split(" ").map { it.toInt() }
    var (w) = readLine()!!.split(" ").map { it.toInt() }

    var ans = 0;

    for(i in 0..n-1){
        for(j in 0..n-1){
            if(i+h<=n && j+w <=n)ans++
        }
    }

    println(ans)

}

Measured memory_bytes: 38032
#include <iostream>
#include <vector>

using namespace std;
using sz = size_t;

int main() {
  // input
  sz N, M;
  cin >> N >> M;

  int rest = N;
  for (sz i = 0; i < M; ++i) {
    int tmp;
    cin >> tmp;
    rest -= tmp;
  }

  cout << (rest < 0 ? -1 : rest) << endl;

  return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

// xのn乗%modを計算
ll mod_pow(ll x,ll n,ll mod){
    ll res = 1;
    while(n > 0){
        if(n & 1) res = res*x%mod;
        x = x*x%mod;
        n >>= 1;
    }
    return res;
}

int main(void) {

    int n;
    cin>>n;
    vi v(n);
    rep(i,n)cin>>v[i];
    int t=1;
    rep(i,n){
        if(v[i]%2==0)t*=2;
    }
    cout<<mod_pow(3,n,MOD)-t<<endl;

}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
//        long startTime = System.currentTimeMillis();
        Scanner scanner = new Scanner(System.in);
        String S = scanner.next();
        scanner.close();

        char[] chars = S.toCharArray();

        // YYMMチェック
        boolean yymm = checkMM(chars[2], chars[3]);

        // MMYYチェック
        boolean mmyy = checkMM(chars[0], chars[1]);

        if (yymm && mmyy) {
            System.out.println("AMBIGUOUS");
        } else if (yymm) {
            System.out.println("YYMM");
        } else if (mmyy) {
            System.out.println("MMYY");
        } else {
            System.out.println("NA");
        }


//        System.out.println(System.currentTimeMillis() - startTime);
    }

    private static boolean checkMM(char seq1, char seq2) {
        int num = Character.getNumericValue(seq1)*10 + Character.getNumericValue(seq2);

        return (num > 0 && num <= 12);
    }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define int long long
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define all(x) x.begin(),x.end()
using namespace std;
string s, t;
map<char, vector<int>>m;
int ans = 0, p = -1;
signed main() {
	cin >> s >> t;
	for0(i, s.size())m[s[i]].push_back(i);
	for (char ch = 'a'; ch <= 'z'; ch++)if (m[ch].size())m[ch].push_back(m[ch][0] + s.size());
	for (char ch : t) {
		if (m[ch].size() == 0) {
			cout << "-1" << endl; return 0;
		}
		p = *upper_bound(all(m[ch]), p);
		if (p >= s.size()) {
			p -= s.size(); ans += s.size();
		}
	}
	cout << ans + p + 1 << endl;
}

Measured memory_bytes: 1728
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
#define MOD 1000000007LL
#define PI 3.141592653589793
#define endl "\n"

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N, u, v;
  cin >> N >> u >> v;
  u--; v--;
  vvll G(N, vll(0));
  for(int i = 0; i < N-1; i++){
    ll A, B;
    cin >> A >> B;
    A--; B--;
    G.at(A).push_back(B);
    G.at(B).push_back(A);
  }
  vll uu(N, INF), vv(N, INF);
  queue<ll> que;
  que.push(u);
  uu.at(u) = 0;
  while(!que.empty()){
    ll x = que.front();
    que.pop();
    for(int i = 0; i < G.at(x).size(); i++){
      ll next = G.at(x).at(i);
      if(uu.at(next) != INF) continue;
      uu.at(next) = uu.at(x)+1;
      que.push(next);
    }
  }

  que.push(v);
  vv.at(v) = 0;
  while(!que.empty()){
    ll x = que.front();
    que.pop();
    for(int i = 0; i < G.at(x).size(); i++){
      ll next = G.at(x).at(i);
      if(vv.at(next) != INF) continue;
      vv.at(next) = vv.at(x)+1;
      que.push(next);
    }
  }

  ll ans = 0;
  for(int i = 0; i < N; i++){
    if(uu.at(i) >= vv.at(i)) continue;
    chmax(ans, vv.at(i)-1LL);
  }
  cout << ans << endl;
}

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

int main() {
  int N;
 
  cin >> N;
   
  if(N%1111 == 0){
    cout << "Yes"<< endl;
  }
  else if((N+1000)%1111 == 0){
    cout << "Yes"<<endl;
  } 
  else if((N+2000)%1111 == 0){
    cout << "Yes"<<endl;
  }
  else if((N+3000)%1111 == 0){
    cout << "Yes"<<endl;
  }
  else if((N+4000)%1111 == 0){
    cout << "Yes"<<endl;
  }
  else if((N+5000)%1111 == 0){
    cout << "Yes"<<endl;
  }
  else if((N+6000)%1111 == 0){
    cout << "Yes"<<endl;
  }
  else if((N+7000)%1111 == 0){
    cout << "Yes"<<endl;
  }
  else if((N+8000)%1111 == 0){
    cout << "Yes"<<endl;
  }
  else if((N-1000)%1111 == 0){
    cout << "Yes"<<endl;
  }
  else if((N-2000)%1111 == 0){
    cout << "Yes"<<endl;
  }
  else if((N-3000)%1111 == 0){
    cout << "Yes"<<endl;
  }
  else if((N-4000)%1111 == 0){
    cout << "Yes"<<endl;
  }
  else if((N-5000)%1111 == 0){
    cout << "Yes"<<endl;
  }
  else if((N-6000)%1111 == 0){
    cout << "Yes"<<endl;
  }
  else if((N-7000)%1111 == 0){
    cout << "Yes"<<endl;
  }
  else if((N-8000)%1111 == 0){
    cout << "Yes"<<endl;
  }        
  else if((N+1)%1111 == 0){
    cout << "Yes"<<endl;
  } 
  else if((N+2)%1111 == 0){
    cout << "Yes"<<endl;
  }
  else if((N+3)%1111 == 0){
    cout << "Yes"<<endl;
  } 
  else if((N+4)%1111 == 0){
    cout << "Yes"<<endl;
  }
  else if((N+5)%1111 == 0){
    cout << "Yes"<<endl;
  } 
  else if((N+6)%1111 == 0){
    cout << "Yes"<<endl;
  }
  else if((N+7)%1111 == 0){
    cout << "Yes"<<endl;
  } 
  else if((N+8)%1111 == 0){
    cout << "Yes"<<endl;
  }
  else if((N+9)%1111 == 0){
    cout << "Yes"<<endl;
  }
  else if((N-1)%1111 == 0){
    cout << "Yes"<<endl;
  } 
  else if((N-2)%1111 == 0){
    cout << "Yes"<<endl;
  }
  else if((N-3)%1111 == 0){
    cout << "Yes"<<endl;
  } 
  else if((N-4)%1111 == 0){
    cout << "Yes"<<endl;
  }
  else if((N-5)%1111 == 0){
    cout << "Yes"<<endl;
  } 
  else if((N-6)%1111 == 0){
    cout << "Yes"<<endl;
  }
  else if((N-7)%1111 == 0){
    cout << "Yes"<<endl;
  } 
  else if((N-8)%1111 == 0){
    cout << "Yes"<<endl;
  }
  else if((N-9)%1111 == 0){
    cout << "Yes"<<endl;
  }
  else{
    cout << "No"<< endl;
  }
  
 
}

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

int main(void){
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    for(int i=0; i<n; i++){
        cin >> h[i];
    }
    
    sort(h.begin(), h.end());
    int min = INT_MAX;
    for(int i=0; i < n - k + 1; i++){
        if(h[i + k - 1] - h[i] < min) min = h[i + k - 1] - h[i];
    }
    
    cout << min << endl;
    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main(void) {
  long long int a, b, v, w, t;
  scanf("%lld %lld %lld %lld %lld", &a, &v, &b, &w, &t);
  long long int diff_dis = b - a, diff_speed = v - w;
  if (diff_dis < 0) diff_dis *= -1;
  if (diff_speed <= 0) {
    printf("NO\n");
  } else {
    double time_d = (double) diff_dis / (double) diff_speed;
    long long int time = (long long int) time_d;
    if (time_d == time && time <= t) {
      printf("YES\n");
    } else {
      if (time + 1 <= t) printf("YES\n");
      else printf("NO\n");
    }
  }

  return 0;
}


Measured memory_bytes: 1660
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from heapq import heappush, heappop

def find_rc(h, w, a, b):
    row = -1
    col = -1

    for r in range(h+1):
        for c in range(w+1):
            if (2*a - w) * r - a * h == (2*b - h) * c - b * w:
                return r, c

    return row, col

def construct(h, w, a, b, r, c):
    grid = [[""]*w for _ in range(h)]

    heap = []
    for col in range(w):
        if col < c:
            heappush(heap, (-b, col))
        else:
            heappush(heap, (-(h-b), col))

    for row in range(h):
        if row < r:
            for _ in range(a):
                rest, col = heappop(heap)
                grid[row][col] = "0"
                heappush(heap, (rest + 1, col))
        else:
            for _ in range(w - a):
                rest, col = heappop(heap)
                grid[row][col] = "0"
                heappush(heap, (rest + 1, col))

    for rr in range(h):
        for cc in range(w):
            if grid[rr][cc] == "":
                grid[rr][cc] = "1"

    for row in grid:
        print("".join(row))

h, w, a, b = li()

# 存在判定
r, c = find_rc(h, w, a, b)
if r == -1:
    print("No")
else:
    construct(h, w, a, b, r, c)

Measured memory_bytes: 70236
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
#include<cassert>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
#define ceil(a, b) a / b + !!(a % b)

int main() {
    int n; cin >> n;
    int f[n][10]; rep(i, n) rep(j, 10) cin >> f[i][j];
    int p[n][11]; rep(i, n) rep(j, 11) cin >> p[i][j];
    int ans = -inf;
    rrep(i, 1, (1 << 10)) {
        int table[n]; rep(j, n) table[j] = 0;
        rep(j, 10) {
            if (i & (1 << j)) {
                rep(k, n) {
                    if (f[k][j] == 1) table[k]++;
                }
            }
        }
        //rep(j, n) cout << table[j] << " "; cout << endl;
        int tmp = 0;
        rep(j, n) tmp += p[j][table[j]];
        ans = max(ans, tmp);
    }
    cout << ans << endl;
}


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

char s[300][300];
ll ans;
int main(){
	int n;
	scanf("%d",&n);
	rep(i,0,n)scanf("%s",s[i]);
	rep(a,0,n){
		int flag=1;
		rep(i,0,n)rep(j,0,n)if(s[(a+i)%n][+j]!=s[(a+j)%n][i])flag=0;
		if(flag)ans+=n;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<string.h>
int main()
{
	int i,j = 0,k = 0;
	char a[52],b[52];
	scanf("%s",a);
	scanf("%s",b);
	for(i = 0;i < strlen(a) + strlen(b);i++)
	{
		if(i % 2 == 0)
		{
			printf("%c",a[j]);
			j++;
		}
		else
		{
			printf("%c",b[k]);
			k++;
		}
	}
	printf("\n");
	return 0;
}


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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ASC(x) sort(ALL((x)))
#define DESC(x) sort(ALL((x)),greater<ll>())
#define REV(x) reverse(ALL((x)))
#define pb push_back

int main()
{
    ll N, Q;
    cin >> N >> Q;
    vector<pair<ll,pair<ll,ll>>> P;
    set<pair<ll,ll>> D;
    REP(i,0,N) {
        ll s, t, x;
        cin >> s >> t >> x;
        P.pb({x, {s-x, t-x-1}});
    }
    REP(i,0,Q) {
        ll d;
        cin >> d;
        D.insert({d, i});
    }

    ASC(P);

    vec X(Q, -1);
    REP(i,0,N) {
        auto begin = D.lower_bound({P[i].second.first, 0});
        auto end = D.upper_bound({P[i].second.second, Q});
        for(auto it = begin; it != end; ++it)
            X[it->second] = P[i].first;
        D.erase(begin, end);
    }

    REP(i,0,Q) PR(X[i]);
    
    return 0;
}

/*



*/

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

const int N = 2e5 + 10, mod = 1e9 + 7;



int main() {
    // ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int tc = 1; 
    //scanf("%d", &tc);
    while(tc--) {
        long long n, k; cin >> n >> k;
        long long ans = 0;
        for(long long i = k; i <= n + 1; i++) {
            long long mn = i * (i - 1) / 2;
            long long mx = i * (2 * n - i + 1) / 2;
            ans += mx - mn + 1; 
        }
        printf("%lld\n", ans % mod);
    }    
    return 0;
}

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

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, m, n) for (ll i = (m); i < (n); i++)
#define FORR(i, m, n) for (ll i = (m); i >= (n); i--)
#define INF 1e9
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((ll)(x).size())
#define SORT(x) sort((x).begin(), (x).end())
#define dump(x) cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl

int main(int argc, char const *argv[])
{
    ll x, a, b;
    cin >> x;
    cin >> a;
    cin >> b;
    x -= a;
    cout << x % b << endl;
    return 0;
}


Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as BC
import Data.Maybe (fromJust)
import Data.List

main = do
  getLine
  print =<< sum . map (\x -> if length x `mod` 2 == 0 then 0 else 1) . group . sort <$> getIntListBC

bsToInt :: BC.ByteString -> Int
bsToInt = fst . fromJust . BC.readInt

getIntListBC :: IO [Int]
getIntListBC = map bsToInt . BC.lines <$> BC.getContents


Measured memory_bytes: 15612
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <string>
#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;


int main(){
    string s;
    cin >> s;
    map<int,int> mp;

    rep(i,4){
        mp[s[i]-'A']++;
    }

    for(auto e : mp) {
        if(e.second != 2){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 3576
//https://atcoder.jp/contests/abc124/tasks/abc124_b
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
    int N;
    cin >> N;
    vector<int> H(N);
    for(auto &x : H){
        cin >> x;
    }
    vector<int> view(N);
    int tmp = H[0];
    for(int i = 0; i < (int)H.size(); i++){
        if(tmp <= H[i]){
            tmp = H[i];
            view[i] = 1;
        }
    }
    cout << count(ALL(view), 1) << endl;
    return 0;
}

Measured memory_bytes: 256