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

double pro[SIZE];
double dp[SIZE][SIZE];
int n;

    void input(){
        cin >> n;
        for(int i = 1; i <= n; i++)
            cin >> pro[i];
    }

int main(){

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    input();

    dp[0][0] = 1.0;
    double licz = 0.0;

    for(int i = 1; i <= n; i++){
        licz = 0.0;
        for(int j = 1; j <= i; j++){
            dp[i][j] = double(pro[i] * dp[i - 1][j - 1] + (1 - pro[i]) * dp[i - 1][j]);
            licz += dp[i][j];
        }
        dp[i][0] = 1 - licz;
    }

    double wynik = 0.0;
    
    for(int i = n/2 + 1; i <= n; i++)
        wynik += dp[n][i];

    cout << setprecision(10) << fixed << wynik;
    return 0;
}

Measured memory_bytes: 70272
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define dunk(a) cout << (a) << "\n"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int h, n;
	cin >> h >> n;
	vector<int> a(n), b(n);
	vector<int> dp(11111, inf);

	rep(i, n) {
		cin >> a[i] >> b[i];
		dp[a[i]] = min(dp[a[i]], b[i]);
	}
	rep(i, h) {
		if (dp[i] == inf) continue;
		rep(j, n) {
			dp[i + a[j]] = min(dp[i + a[j]], dp[i] + b[j]);
		}
	}
	int ans = inf;
	for (int i = h; i < 11111; ++i) {
		ans = min(ans, dp[i]);
	}
	dunk(ans);
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		System.out.print(a*b + " ");
		System.out.println(a*2 + b*2);
	}
}

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

int serch(char *data);
void count(char *data);

int main(void)
{
    char data[100];
    while (feof(stdin) != EOF){
        if (fgets(data, sizeof(data), stdin) == NULL){
            break;
        }
        while (serch(data) == 0){
            count(data);
        }
        printf("%s", data);
    }
    return (0);
}
int serch(char* data){
    if (strstr(data, "the")){
        return 1;
    }
    if (strstr(data, "this")){
        return 1;
    }
    if (strstr(data, "that")){
        return 1;
    }
    return (0);
}
void count(char* data){
    int i;
    for (i = 0; data[i] != 0; i++){
        if (data[i] >= 'a' && data[i] <= 'z'){
            if (data[i] == 'z'){
                data[i] = 'a';
            }else{
                data[i]++;
            }
        }
    }
}


Measured memory_bytes: 2032
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define pye cout << "yes" << endl;
#define pno cout << "no" << endl;
#define pYe cout << "Yes" << endl;
#define pNo cout << "No" << endl;
#define pYE cout << "YES" << endl;
#define pNO cout << "NO" << endl;;
#define prin(num) cout << num << endl;
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define mp make_pair
#define INF 100000000000
#define MOD 1000000007LL
#define MAX 200005
#define NIL -1
#define WHITE 0
#define BLACK 1
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;

ll fact[MAX];
ll rfact[MAX];

ll comb(ll n, ll k) {
    return fact[n]*rfact[k]%MOD*rfact[n-k]%MOD;
}

ll modPow(ll x, ll n) {
    ll res=1;
    while(n>0) {
        if(n&1) res=res*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return res;
}


int main(void) {
    ll H, W, A, B;
    cin >> H >> W >> A >> B;
    ll i, j;
    fact[0]=rfact[0]=1;
    for(i=1; i<MAX; i++) {
        fact[i]=i*fact[i-1]%MOD;
        rfact[i]=modPow(fact[i], MOD-2);
    }
    
    ll ans=0;
    for(j=B; j<W; j++) {
        ll h=H-A-1, w=j;
        ll t=comb(h+w, h);
        h=A-1; w=W-1-j;
        t*=comb(h+w, h)%MOD;
        ans+=t;
        ans%=MOD;
    }
    prin(ans);
}

Measured memory_bytes: 3328
// https://atcoder.jp/contests/abc086/tasks/abc086_a
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define CEIL(a, b) ((a - 1) / b + 1)

void solve() {
    int a, b;
    cin >> a >> b;
    if (a * b % 2 == 0) {
        cout << "Even\n";
    } else {
        cout << "Odd\n";
    }
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    solve();
}


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

int main() {
    int n;
    cin >> n;
    int R[n];
    for (int i=0; i<n; i++) {
        cin >> R[i];
    }
    int maxv=R[1]-R[0];
    int minv=R[0];
    for (int t=1; t<n; t++) {
        maxv=max(maxv,R[t]-minv);
        minv=min(minv,R[t]);
    }
    printf("%d\n",maxv);
    return 0;
}

Measured memory_bytes: 3912
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define Rep(i,a,n)for(int i=(int)(a);i<(int)(n);i++)
#define rep(i,n)Rep(i,0,n)
typedef long long ll;
typedef long double ld;
#define Ma(x,y) ((x)>(y)?(x):(y))
#define mi(x,y) ((x)<(y)?(x):(y))

int main(){
    int n, m, x, c[12] = { 0 }, a[12][12] = { 0 }, y, z[12] = { 0 }, b, d = 1e9, all[12], flag = 0;
    scanf("%d%d%d",&n,&m,&x);
    rep(i,n){
    scanf("%d",&c[i]);
        rep(j,m){
            scanf("%d",&a[i][j]);
        }
    }

    rep(i, 4096) {
        y = 0;
        all[0] = i / 2048;
        Rep(j, 1, 12)all[j] = (i % (int)pow(2,12-j)) / pow(2,11-j);
        rep(j, 12)y += c[j] * all[j];
        for (b = 0; b < m; b++) {
            rep(j, 12)z[b] += all[j]*a[j][b];
            if (z[b] < x)flag++;
            z[b] = 0;
        }
        if (flag==0)d = mi(d, y);
        flag = 0;
    }  
    if (d == (int)1e9)puts("-1");
    else printf("%d", d);
    return 0;
}

Measured memory_bytes: 2556
#include <stdio.h>
int main(void){
    int array[5];
    int i;
    
    for(i = 0; i < 5; i++){
        scanf("%d", &array[i]);
    }
    for(i = 0; i < 5; i++){
        if(array[i] == 0){
            break;
        }
    }
    printf("%d\n", i+1);
    return 0;
    
}


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

int main(){
  int A,B;
  cin >> A >> B;
  if(A<=5){
    cout << 0 << endl;
  }else if(A<=12){
    cout << B/2 << endl;
  }else{
    cout << B << endl;
  }
}

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

int main(){
    int a,l,x;
    while(cin >> a >> l >> x){
        double h = sqrt(l*l -a*a/4.0);
        double y = sqrt((l+x)*(l+x) -l*l) /2.0;
        cout << fixed << setprecision(10);
        cout << a*h/2 +l*y << endl;
    }
    return 0;
}


Measured memory_bytes: 3160
// https://atcoder.jp/contests/abc126/tasks/abc126_c

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF (1e9)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
// int gcd(long a, long b) { return b ? gcd(b, a % b) : a; }
// int lcm(long a, long b) { return a * b / gcd(a, b); }

struct UnionFind {
    vector<int> data;
    UnionFind(int size) : data(size, -1) {}
    bool unionSet(int x, int y) {
        x = root(x);
        y = root(y);
        if (x != y) {
            if (data[y] < data[x])
                swap(x, y);
            data[x] += data[y];
            data[y] = x;
        }
        return x != y;
    }
    inline bool findSet(int x, int y) { return root(x) == root(y); }
    inline int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
    inline int size(int x) { return -data[root(x)]; }
};

// X, Yのグループが何個あるか調べればいい
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;

    UnionFind tree(n);
    set<int> st;
    int k = n;

    for (int i = 0; i < m; i++) {
        int x, y, z;
        cin >> x >> y >> z;
        k -= tree.unionSet(--x, --y);
    }
    cout << k << endl;

    return 0;
}

Measured memory_bytes: 640
from collections import Counter

N = int(input())
s = input()
cnt = Counter(s)
R = cnt.get('R', 0)
G = cnt.get('G', 0)
B = cnt.get('B', 0)
ans = R * G * B
for i in range(N-1):
  for j in range(i+1, N):
    if s[i] != s[j] and 2*j-i < N and s[i] != s[2*j-i] and s[j] != s[2*j-i]:
      ans -= 1
print(ans)

Measured memory_bytes: 68924
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b;
    cin>>a>>b;
    if(a==1) a=14;
    if(b==1) b=14;
    if(a>b) cout<<"Alice"<<endl;
    else if(b>a) cout<<"Bob"<<endl;
    else cout<<"Draw"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
#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 int long long
void test_case() {
	string s; cin>>s;
	int t = 0;
	for(char ch : s){
		t += ch - '0';
	}
	if(t % 9 == 0){
		cout<<"Yes"<<endl;
	}
	else {
		cout<<"No"<<endl;
	}
}

signed main() {
	IOS
	int i=1, T=1;
	//cin>>T;
	while(T--){
		//cout<<"Case #"<<i<<": ";
		test_case();
		i++;
	}
}


Measured memory_bytes: 3776
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

int getDigitSum(int x)
{
    int sum = 0;
    while(x > 0){
        sum += x % 10;
        x /= 10;
    }
    return sum;
}

int main()
{
    int n, a, b;
    cin >> n >> a >> b;

    int ans = 0;
    for(int x=1; x<=n; ++x){
        int sum = getDigitSum(x);
        if(a <= sum && sum <= b)
            ans += x;
    }
    cout << ans << endl;

    return 0;
}


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

void print() { std::cout << std::endl; }
template <class Head, class... Tail> void print(Head &&head, Tail &&... tail) {
    std::cout << head;
    if(sizeof...(tail) != 0)
        std::cout << " ";
    print(std::forward<Tail>(tail)...);
}
template <class T> void print(std::vector<T> &vec) {
    for(auto &a : vec) {
        std::cout << a;
        if(&a != &vec.back())
            std::cout << " ";
    }
    std::cout << std::endl;
}
template <class T> void print(std::vector<std::vector<T>> &df) {
    for(auto &vec : df) {
        print(vec);
    }
}

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

    int a = (N % 2 == 1) ? (N + 1) / 2 : N / 2;
    cout << fixed;
    cout << (double)a / (double)N << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;

int main(void)
{
    IOS
    int n; cin >> n;
    vector<vector<int>> v;

    REP(i,n) {
        vector<int> v2(n-1);
        REP(j,n-1) {
            cin >> v2[j];
            v2[j]--;
        }
        v.emplace_back(v2);
    }

    int ans = 0;
    vector<int> cnt(n,0);
    vector<pair<int,int>> q;
    
    auto next = [&](int i) {
        if (cnt[i] == n-1) return;
        int j = v[i][cnt[i]];
        //cerr << i << " " << j << endl;
        if (cnt[j] == n-1) return;
        if (v[j][cnt[j]] == i) {
            if (i > j) swap(i,j);
            pair<int,int> p(i,j);
            auto it = find(ALL(q),p);
            if (it == q.end()) q.emplace_back(p);
        }
    };

    REP(i,n) {
        next(i);
    }

    while (!q.empty())
    {
        ans++;
        vector<pair<int,int>> q2(q);
        q.clear();
        for(auto x : q2) {
            cnt[x.first]++;
            cnt[x.second]++;
        }
        for(auto x : q2) {
            next(x.first);
            next(x.second);
        }

    }
    
    REP(i,n) if (cnt[i] != n-1) ans = -1;
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n, m, x,tmp,cost1=0,cost2=0;
	cin >> n >> m >> x;
	vector<int> v(n+1, 0);
	for (int i = 0; i < m; i++) {
		cin >> tmp;
		v[tmp] = 1;
	}
	for (int i = x; i <= n; i++) {
		cost1 += v[i];
	}
	for (int i = x; i >= 0; i--) {
		cost2 += v[i];
	}
	cout << min(cost1, cost2) << endl;
}

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

int main()
{
  int N;
  string color;
  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> color;
	if(color != "Y" && i == N - 1){
     cout << "Three" << endl;      
    }else if(color !="Y"){
    continue;
    }else{
    cout << "Four" << endl;
      break;
    }
  }
}

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

int main()
{
    string s;
    cin >> s;
        for (int i=0; i<s.length(); i++){
        if (isupper(s[i])){
		  cout << "A"<<endl;
        }
        else cout<<"a"<<endl;
    }
    return 0;
}



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

using namespace std;

const int MAXN = 2e5 + 10;
const int MOD = 1e9 + 7;

long long aib[MAXN];

void update(int poz, long long val) {
	for(; poz < MAXN; poz += poz&-poz) aib[poz] = max(aib[poz], val);
}
long long query(int poz) {
	long long ret = 0;
	for(; poz; poz -= poz&-poz) ret = max(ret, aib[poz]);
	return ret;
}
int main() {
    #ifdef BLAT
        freopen("input", "r", stdin);
    #endif

    int n;
    cin >> n;
    vector< int > h(n);
    for(int i = 1; i <= n; ++i) {
    	cin >> h[i];
    }
    for(int i = 1; i <= n; ++i) {
    	int a;
    	cin >> a;
    	update(h[i], a + query(h[i]));
    }

    cout << query(n) << '\n';
}   	

Measured memory_bytes: 2560
import sys

def solve():
    input = sys.stdin.readline
    N, K = map(int, input().split())
    A = [int(a) for a in input().split()]
    M, P = [], [0]
    Z = 0
    for a in A:
        if a < 0: M.append(a)
        elif a == 0: Z += 1
        else: P.append(a)
    M.sort(reverse = True)
    mL, pL = len(M), len(P)

    minusT = mL * pL
    zeroT = Z * (mL + pL)

    if K <= minusT: #K番目の数が負の値
        P.sort(reverse = True)
        low, high = - 10 ** 18 - 1, 0
        while high - low > 1:
            mid = (low + high) // 2
            pi = 0
            count = 0
            for i in range(mL):
                while M[i] * P[pi] <= mid: pi += 1
                count += pi
            #print(mid, count)
            if count >= K: high = mid
            else: low = mid
        print(high)

    elif K <= minusT + zeroT: #K番目の数が0
        print(0)

    else: #正の数の内、K番目の数は何か
        M.append(0)
        P.sort()
        T = N * (N - 1) // 2
        low, high = 0, 10 ** 18 + 1
        while high - low > 1:
            mid = (high + low) // 2
            count = 0
            pi = pL - 1
            for i in range(pL):
                while P[i] * P[pi] >= mid:
                    pi -= 1
                count += pL - 1 - max(i, pi)
               
            mi = mL - 1
            for i in range(mL):
                while M[i] * M[mi] >= mid:
                    mi -= 1
                count += mL - 1 - max(i, mi)

            #midよりも大きい数字がcount個ある
  
            if T - count >= K: high = mid
            else: low = mid
        print(low)
   
    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 89428
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;

namespace Atcoder_0404
{
    class Program
    {

        static long mod = 1000000000 + 7;
        static void Main(string[] args)
        {
            var abcd = GetInput_int();
            var a_hp = abcd[0];
            var a_attack = abcd[1];
            var b_hp = abcd[2];
            var b_attack = abcd[3];

            while (a_hp > 0 && b_hp > 0)
            {
                a_hp -= b_attack;
                b_hp -= a_attack;
            }

            if (b_hp <= 0)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
        #region input
        

        static string[] GetInput_string()
        {
            var input = Console.ReadLine().Split(' ');
            return input;
        }

        static int[] GetInput_int()
        {
            var input = GetInput_string();
            var result = new int[input.Length];
            for (int i = 0; i < result.Length; i++)
            {
                result[i] = int.Parse(input[i]);
            }
            return result;
        }
        static long[] GetInput_long()
        {
            var input = GetInput_string();
            var result = new long[input.Length];
            for (int i = 0; i < result.Length; i++)
            {
                result[i] = long.Parse(input[i]);
            }
            return result;
        }
        #endregion
        #region sonota
        static void Swap_array<T>(T[] target, int a, int b)
        {
            T temp = target[a];
            target[a] = target[b];
            target[b] = temp;
        }
        static void Swap_list<T>(List<T> target, int a, int b)
        {
            T temp = target[a];
            target[a] = target[b];
            target[b] = temp;
        }
        /// <summary>
        /// 最大公約数
        /// </summary>
        public static int GCD(int a, int b)
        {

            /* 自然数 a > b を確認・入替 */
            if (a < b)
            {
                int tmp = a;
                a = b;
                b = tmp;
            }

            /* ユークリッドの互除法 */
            int r = a % b;
            while (r != 0)
            {
                a = b;
                b = r;
                r = a % b;
            }
            return b;
        }

        /// <summary>
        /// 最小公倍数
        /// </summary>
        public static int LCM(int a, int b)
        {
            int x = a * b;
            b = GCD(a, b);
            return x / b;

        }
        #endregion
    }
}

Measured memory_bytes: 27388
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	@SuppressWarnings("unchecked")
	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int n = scanner.nextInt();
			int m = scanner.nextInt();
			if ((n | m) == 0)
				break;
			List<Point>[] lists = new ArrayList[n + 1];
			for (int i = 0; i <= n; i++)
				lists[i] = new ArrayList<Point>();
			for (int i = 1; i <= n; i++) {
				int k = scanner.nextInt();
				for (int j = 0; j < k; j++) {
					int x = scanner.nextInt();
					int cost = scanner.nextInt();
					lists[i - 1].add(new Point(1, x, cost));
					if (i != 1)
						lists[i - 2].add(new Point(2, x, cost));
					if (i == n - 1)
						lists[i].add(new Point(2, x, 0));
					if (i == n)
						lists[i].add(new Point(1, x, 0));

				}
			}
			PriorityQueue<Point> pq = new PriorityQueue<Main.Point>();
			pq.offer(new Point(0, 0, 0, 0, m));
			int[][][] dp = new int[m + 1][n + 2][1001];
			for (int[][] d : dp)
				for (int[] dd : d)
					Arrays.fill(dd, 1 << 26);
			dp[m][0][0] = 0;
			while (!pq.isEmpty()) {
				Point point = pq.poll();
				int y = point.y;
				int x = point.x;
				int cost = point.cost;
				int total = point.total;
				int mm = point.m;
				if (y >= n) {
					System.out.println(total);
					break;
				}
				for (Point p : lists[y]) {
					int nc = (cost + p.cost) * Math.abs(x - p.x);
					if (p.y == 2) {
						if (mm >= 1) {
							if (dp[mm - 1][p.y + y][p.x] > nc) {
								dp[mm - 1][p.y + y][p.x] = nc;
								pq.offer(new Point(y + p.y, p.x, p.cost,
										y == 0 ? 0 : nc + total, mm - 1));
							}
						}
					} else {
						if (dp[mm][p.y + y][p.x] > nc) {
							dp[mm][p.y + y][p.x] = nc;
							pq.offer(new Point(y + p.y, p.x, p.cost, y == 0 ? 0
									: nc + total, mm));
						}
					}
				}
			}

		}
	}

	class Point implements Comparable<Point> {
		int y, x, cost, total, m;

		public Point(int y, int x, int cost, int total, int m) {
			super();
			this.y = y;
			this.x = x;
			this.cost = cost;
			this.total = total;
			this.m = m;
		}

		public Point(int y, int x, int cost) {
			super();
			this.y = y;
			this.x = x;
			this.cost = cost;

		}

		@Override
		public String toString() {
			return "Point [y=" + y + ", x=" + x + ", cost=" + cost + ", total="
					+ total + ", m=" + m + "]";
		}

		@Override
		public int compareTo(Point o) {
			return this.total - o.total;
		}
	}
}

Measured memory_bytes: 192764
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(final String[] args) {
        final FastScanner scanner = new FastScanner(System.in);
        final int n = scanner.nextInt();
        final int x = scanner.nextInt();

        int prev = 0;
        long sum = 0;
        for (int i = 0; i < n; i++) {
            final int a = scanner.nextInt();
            if (prev + a <= x) {
                prev = a;
                continue;
            }

            prev = x - prev;
            sum += a - prev;
        }

        System.out.println(sum);
    }

    private static class FastScanner {
        private final BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(final InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (final IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (final IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }
    }
}


Measured memory_bytes: 41812
from fractions import gcd


def lcm(x,y):
    return (x*y)//gcd(x,y)


n,m=map(int,input().split())
s,t=input(),input()
lcm=lcm(n,m)

if s[::int(lcm/m)]!=t[::int(lcm/n)]:
    print(-1);exit()

print(lcm)

Measured memory_bytes: 5344
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int YYQ=1e9+7;
int n,dp[100005][2];
vector<int> g[100005];
void dfs(int cur,int fa){
	bool leaf=1;
	for(int i=0;i<g[cur].size();i++){
		if(g[cur][i]==fa)	continue;
		leaf=0;
		dfs(g[cur][i],cur);
	}
	if(leaf){
		dp[cur][0]=dp[cur][1]=1;
	}
	else{
		dp[cur][0]=1;
		dp[cur][1]=1;
		for(int i=0;i<g[cur].size();i++){
			int to=g[cur][i];
			if(to==fa)	continue;
			dp[cur][0]=(dp[cur][0]*dp[to][1])%YYQ;
			dp[cur][1]=(dp[cur][1]*(dp[to][0]+dp[to][1]))%YYQ;
		}
	}
}
signed main(){
	cin>>n;
	for(int i=1;i<n;i++){
		int a,b;
		cin>>a>>b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	dfs(1,0);
	cout<<(dp[1][0]+dp[1][1])%YYQ<<endl;
}

Measured memory_bytes: 12800
#include<stdio.h>
#include<string.h>
int main(void)
{
   int sum;
   char str[1100];
   int i;
   for(i=0;i<1100;i++){
      str[i]=0;
   }
   while(1){
      scanf("%s",str);
      if(strcmp(str,"0")==0){
         break;
      }
      sum=0;
      for(i=0;str[i]!='\0';i++){
         sum+=str[i]-'0';
      }
      printf("%d\n",sum);
   }
   return 0;
}

Measured memory_bytes: 2644
#include <iostream>
#include <algorithm>
using namespace std;
static const int MAX = 200000;

int main(void){
    int R[MAX], n;
    
    cin >> n;
    for ( int i = 0; i < n; i++ ) cin >> R[i];
    
    int maxv = -2000000000;
    int minv = R[0];
    
    for ( int i = 1; i < n; i++ ) {
        maxv = max(maxv, R[i] - minv);
        minv = min(minv, R[i]); 
    }
    
    cout << maxv << endl;
    
    return 0;
}



Measured memory_bytes: 3900
/*---> 26 January 2020 <--- > 17:29:34 <---*/
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("unroll-loops")
// #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
//#pragma GCC target ("sse4")
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
//template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
#define int long long
#define F first
#define S second
#define mod 1000000007
#define inf (int)1e18+5
#define sz(x) (int)x.size()
#define PI 3.141592653589793238510
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define __ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define vi vector<int>
#define vpii vector<pair<int,int> > 
#define vvi vector<vector<int> >
#define PRINT_TIME cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s." <<endl;
#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__) << "] "
typedef long double ld;
typedef pair<int,int> pii;
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
const int N=1e5+5;

int32_t main(){__
	int n,a;
	cin>>n>>a;
	cout<<(n+a-1)/a<<"\n";
return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int n;
string s;
pair<ll, ll> hsh[5005], c_hs[5005][5005];
ll inv1[5005];
ll inv2[5005];
ll p = 31, p1 = 179;
ll m = 1e9 + 9, m1 = 1e9 + 7;

pair<ll, ll> compute_hash(string s1){
	long long hash_value = 0, hash_value1 = 0;
	long long p_pow = 1, p_pow1 = 1;
	for(char c : s1){
		hash_value = (hash_value + (c - 'a' + 1) * p_pow) % m;
		p_pow = (p_pow * p) % m;
		hash_value1 = (hash_value1 + (c - 'a' + 1) * p_pow1) % m1;
		p_pow1 = (p_pow1 * p1) % m1;
	}
	return mp(hash_value, hash_value1);
}

void computeHashes(){
	repn(i, 1, n + 1){
		string s1 = s.substr(0, i);
		hsh[i - 1] = compute_hash(s1);
	}
}

ll mypow(ll a, ll p, ll MOD){
	if(p == 0) return 1;
	if(p == 1) return (a % MOD);
	if(p & 1) return ((a % MOD) * (mypow(a, p - 1, MOD) % MOD)) % MOD;
	ll x = mypow(a, p / 2, MOD) % MOD;
	return (x * x) % MOD;
}

void computeInvs(){
	ll mult1 = 1LL, mult2 = 1LL;
	rep(i, 5005){
		inv1[i] = mypow(mult1, m - 2, m);
		(mult1 *= p) %= m;
	}
	rep(i, 5005){
		inv2[i] = mypow(mult2, m1 - 2, m1);
		(mult2 *= p1) %= m1;
	}
}

void comp_hs(int i, int j){
	ll hs1 = ((hsh[j].fi - (i ? hsh[i - 1].fi : 0)) + m) % m;
	ll hs2 = ((hsh[j].se - (i ? hsh[i - 1].se : 0)) + m1) % m1;
	(hs1 *= inv1[i]) %= m;
	(hs2 *= inv2[i]) %= m1;
	c_hs[i][j] = mp(hs1, hs2);
}

bool eq(pair<ll, ll> a, pair<ll, ll> b){
	return (a.fi == b.fi && a.se == b.se);
}

bool check(int len){
	rep(i, n - (2 * len) + 1) repn(j, i + len, n - len + 1){
		if(eq(c_hs[i][i + len - 1], c_hs[j][j + len - 1])) return 1;
	}
	return 0;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	cin >> n;
	cin >> s;
	vi cnt(30, 0);
	int f = 1;
	rep(i, n){
		if(cnt[s[i] - 'a']){
			f = 0;
			break;
		}
		cnt[s[i] - 'a']++;
	}
	if(f){
		cout << 0 << endl;
		return 0;
	}
	computeHashes();
	computeInvs();
	rep(i, n) repn(j, i, n) comp_hs(i, j);
	int l = 1, r = n / 2;
	while(l < r){
		int mid = (l + r + 1) / 2;
		if(check(mid)) l = mid;
		else r = mid - 1;
	}
	cout << l << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


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

int main(){
    double d,e;
    while(cin>>d>>e){
        if(d==0 && e==0){
            return 0;
        }
        double ans=1e9;

        for(int i=0;i<d;i++){
            ans=min(ans,abs(sqrt(i*i+(d-i)*(d-i))-e));
        }
        printf("%.8f\n",ans);
    }
}



Measured memory_bytes: 3124
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


# inputna
n = int(input())
a = list(map(int, input().split()))
ans = 1/sum((1/num) for num in a)
print(ans)

Measured memory_bytes: 61916
#include<cstdio>
#include<algorithm>
using namespace std;
typedef __int128 LL;
char buf[1<<21],*p1=buf,*p2=buf;
#define getchar() (p1==p2 && (p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
LL read()
{
	LL x=0,f=1;
	char c=getchar();
	while(c<'0' || c>'9')
	{
		if(c=='-')	f=-1;
		c=getchar();
	}
	while(c>='0' && c<='9')	x=(x<<1)+(x<<3)+(c^'0'),c=getchar();
	return x*f;
}
void write(LL x)
{
	if(x<0)	putchar('-'),x=-x;
	if(x>9)	write(x/10);
	putchar(x%10+'0');
}
const LL MOD=998244353;
LL QuickPow(LL x,LL p)
{
	LL base=x,ans=1;
	while(p)
	{
		if(p&1)	ans*=base,ans%=MOD;
		p>>=1;
		base*=base;
		base%=MOD;
	}
	return ans;
}
LL n,m,fac[1000005],inv[1000005];
LL C(LL n,LL m){return fac[n]*inv[m]%MOD*inv[n-m]%MOD;}
int main(){
	n=read(),m=read();
	fac[0]=fac[1]=1;
	for(LL i=2;i<=1000000;++i)	fac[i]=fac[i-1]*i%MOD;
	inv[1000000]=QuickPow(fac[1000000],MOD-2);
	for(LL i=1000000-1;~i;--i)	inv[i]=inv[i+1]*(i+1)%MOD;
	LL ans=0;
	for(LL i=1;i<=min(n,m);++i)
	{
		ans+=C(2*i,i)*C(n-i+m-i,n-i)%MOD;
		ans%=MOD;
	}
	ans*=inv[2];
	/*
	C(2n,n)
	*/
	ans*=inv[n+m];
	ans%=MOD;
	ans*=fac[n];
	ans%=MOD;
	ans*=fac[m];
	ans%=MOD;
	ans+=max(n,m);
	ans%=MOD;
	write(ans);
	puts("");
	return 0;
}

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

using namespace std;

int n;

int dfs(long x=0, int a=0, int b=0, int c=0)
{
  if (x > n) return 0;
  int res = a*b*c;
  x *= 10;
  res += dfs(x+3, 1, b, c);
  res += dfs(x+5, a, 1, c);
  res += dfs(x+7, a, b, 1);
  return res;
}

int main()
{
  cin >> n;
  cout << dfs() << endl;
}

Measured memory_bytes: 256
;; E - Red and Green Apples

(defun eat (p q r acc)
  "pとqの要素を食べるが, rの要素の方が大きければそちらに替える"
  (let ((ph (car p))
        (qh (car q))
        (rh (car r)))
    (cond ((and ph rh (< ph rh) (or (not qh) (>= qh ph)))
           (eat (cdr p) q (cdr r) (+ acc rh)))
          ((and qh rh (< qh rh) (or (not ph) (>= ph qh)))
           (eat p (cdr q) (cdr r) (+ acc rh)))
          (t (+ (reduce #'+ p) (reduce #'+ q) acc)))))

(defun solve (x y a b c p q r)
  "赤りんごx個, 緑りんごy個食べるときの美味しさの総和の最大"
  (setf p (drop (- a x) (sort p #'<))) ; 大きいものx個, 昇順
  (setf q (drop (- b y) (sort q #'<))) ; 大きいものy個, 昇順
  (setf r (sort r #'>)) ; 降順
  (eat p q r 0))

(defun drop (n lst)
  "先頭n個を削除"
  (if (plusp n) (drop (1- n) (cdr lst)) lst))

(defun main ()
  (let* ((x (read))
         (y (read))
         (a (read))
         (b (read))
         (c (read))
         (p (loop repeat a collect (read)))
         (q (loop repeat b collect (read)))
         (r (loop repeat c collect (read))))
    (print (solve x y a b c p q r))))

(main)


Measured memory_bytes: 63908
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
ll n,q,h,s,D;
ll a,b,c,d;
int main()
{
	while(cin>>q>>h>>s>>D)
	{
		cin>>n;
		a=q;//25
		b=min(q*2ll,h);//50
		c=min(min(a*4ll,a*2ll+b),min(b*2,s));//100
		d=min(min(a*8ll,b*4ll),min(c*2ll,min(c+2*b,min(c+b+2*a,min(c+4*a,D)))));//20
		ll t,ans=0;
		t=n/2;
		n-=2*t,ans+=t*d;
		
		t=n/1;
		n-=1*t,ans+=t*c;
		
		t=n/0.5;
		n-=0.5*t,ans+=t*b;
		
		t=n/0.25;
		n-=0.25*t,ans-=t*a;
		
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int N, d[111111], dp = -1, c = 0;

  std::cin >> N;

  for (int i = 0; i < N; i ++) {
    std::cin >> d[i];

    if (d[i] > dp)
      dp = d[i];
  }

  std::sort(d, d + N);
  
  for (int i = 0; i <= dp; i ++) {
    int x = std::upper_bound(d, d + N, i) - d;

    if (x + x == N)
      c ++;
  }

  std::cout << c << std::endl;

  return 0;
}


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

using namespace std;

int main()
{
  string s;
  cin >> s;
  if (s == "AAA" || s == "BBB")
  {
    cout << "No" << endl;
  }
  else
  {
    cout << "Yes" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,tune=native")
 
using namespace __gnu_pbds;
using namespace std;
     
#define mp make_pair
#define sz(x) (int)((x).size())
#define all(x) (x).begin(),(x).end()
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define eb emplace_back
 
typedef pair< int, int > pii;
typedef pair< long long, long long > pll;
typedef long long ll;
typedef unsigned long long ull;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< ll > vll;
typedef vector< vll > vvll;
typedef vector< pii > vpii;
typedef vector< vpii > vvpii;
typedef vector< pll > vpll;
typedef long double ld;
typedef vector< ld > vld;
 
const ll MOD2 = 1e9 + 7;
const int MOD = 1e9 + 7;
 
const ull infull = numeric_limits<unsigned long long>::max();
 
void fix(int &x, ll MOD) {
    x = (x % MOD);
    if(x < 0) x += MOD;
    return;
}
 
ll lgput(ll a, ll b, ll MOD) {
    ll ret = 1;
    a %= MOD;
    while(b) {
        if(b&1) ret = ret*a % MOD;
        a = a*a % MOD;
        b >>= 1;
    }
 
    return ret;
}
 
ll inv(ll a, ll MOD) {
    return lgput(a, MOD-2, MOD);
}
 
struct f {
    int a, b;
    f(int _a = 0, int _b = 0) : a(_a) ,b(_b) {}
    ll eval(int x) {
        return 1ll*x*a + b;
    }
};
 
int binarySearch(int x, vi &v) {
    int pos = 0;
    int l = 1, r = sz(v);
    while(l <= r) {
        int m = l + r >> 1;
        if(v[m] <= x) {
            pos = m;
            l = m + 1;
        } else {
            r = m - 1;
        }
    }
 
    return pos;
}
 
int main() { 
    #ifdef BLAT
        freopen("stdin", "r", stdin);
        freopen("stderr", "w", stderr);
    #endif
 
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(12);
    srand(time(NULL));
        
    int n, m;
    cin >> n >> m;

    vector< vector< int > > mat(n + 1, vector< int >(m + 1));
    vector< vector< int > > dp(n + 1, vector< int >(m + 1, 1e9));

    for(int i = 1; i <= n; ++i) {
        for(int j = 1; j <= m; ++j) {
            char c;
            cin >> c;
            mat[i][j] = (c == '#');
        }
    } 

    dp[1][1] = mat[1][1];
    for(int i = 1; i <= n; ++i) {
        for(int j = 1; j <= m; ++j) {
            if(i == 1 && j == 1) continue;
            dp[i][j] = min(dp[i-1][j] + (mat[i-1][j]!=mat[i][j] && mat[i][j] == 1), dp[i][j-1] + (mat[i][j-1]!=mat[i][j] && mat[i][j] == 1));
            // cout << dp[i][j] << ' ';
        }
        // cout << '\n';
    }

    cout << dp[n][m] << '\n';
    return 0;  
}

Measured memory_bytes: 384
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
import           Data.Foldable (toList)
import           Data.List     (group)
import           Data.Sequence ((|>))
import qualified Data.Sequence as Seq

data Direction = V | H deriving (Show, Eq)

main :: IO ()
main = do
  n <- readLn
  s1 <- getLine
  s2 <- getLine
  print $ solve n s1 s2

solve :: Int -> String -> String -> Int
solve n s1 _ = foldr1 mulMod cs where
  cs = f (head bs) : map g (windows 2 bs)
  bs = map h $ group s1
  f V = 3
  f H = 6
  g [V, V] = 2
  g [V, H] = 2
  g [H, V] = 1
  g [H, H] = 3
  h xs = if length xs == 1 then V else H

mulMod :: Int -> Int -> Int
mulMod a b = (a * b) `mod` m

m :: Int
m = 10^9 + 7

-- https://stackoverflow.com/questions/27726739/implementing-an-efficient-sliding-window-algorithm-in-haskell
windows :: Int -> [a] -> [[a]]
windows n0 = go 0 Seq.empty where
  go n s (a:as)
    | n' <  n0  =              go n' s'  as
    | n' == n0  = toList s'  : go n' s'  as
    | otherwise = toList s'' : go n  s'' as where
        n'  = n + 1
        s'  = s |> a
        s'' = Seq.drop 1 s'
  go _ _ [] = []


Measured memory_bytes: 508
from collections import deque
N,M = map(int,input().split())
p = [0] + list(map(int,input().split()))
l = [[] for _ in range(N+1)]
for i in range(M):
  x,y = map(int,input().split())
  l[x].append(y)
  l[y].append(x)

#unionfind
lp = [i for i in range(N+1)] #親のリスト
#木の根を求める
def root(x):
  if lp[x] == x:
    return x
  else:
    lp[x] = root(lp[x])
    return lp[x]
#xとyが同じ集合に属するか否か
def det(x,y):
  return root(x) == root(y)
#xとYが属する集合の併合 Yが親になる
def unite(x,y):
  x = root(x)
  y = root(y)
  if x != y:
    lp[x] = y 

seen = [False]*(N+1)
for i in range(1,N+1):
  if seen[i] == False:
    seen[i] = True
    d = deque([i])
    while len(d)>0:
      v = d.popleft()
      for j in l[v]:
        if seen[j] == False:
          seen[j] = True
          unite(j,i)
          d.append(j)
###
cnt = 0
for i in range(1,N+1):
  cnt += int(det(p[i],i))
print(cnt)  

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

typedef long long ll;
const ll MOD = 1000000007;
ll mod;

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m;
    cin >> n >> m;
    vector<vector<int> > v(m + 1);
    priority_queue<int, vector<int> > pq;
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        if (a <= m)
            v[a].push_back(b);
    }
    int ans = 0;
    for (int i = 1; i <= m; i++) {
        // insert all b's having a = i into pq
        for (int b : v[i]) pq.push(b);
        if (!pq.empty()) {
            ans += pq.top();
            pq.pop();
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 5632
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <limits.h>
#include <cstring>
#include <tuple>
#include <cassert>
#include <numeric>
using namespace std;
// type alias
typedef long long LL;
typedef vector < int > VI;
typedef unordered_map < int, int > MAPII;
typedef unordered_set < int > SETI;
typedef pair< int , int > II;
typedef tuple< int, int, int > III;
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// minmax
#define SMAX(a,b) a = max(a,b)
#define SMIN(a,b) a = min(a,b)
// debug cerr
#define TRACE true
#define dump(x) if(TRACE) { cerr << #x << " = " << (x) << endl; }
#define dump2(x,y) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << endl; }
#define dump3(x,y,z) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << endl; }
#define dump4(x,y,z,a) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << ", " << #a << " = " << (a) << endl; }
#define dumpAR(ar) if(TRACE) { FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }

/*
 
 8/11/2018
 
 15:15-16:00 time is up
 17:30-17:50 read editorials
 
 23:00- read editorials
 
 Editorials:
  - https://cf16-final.contest.atcoder.jp//data/other/cf16-exhibition-final/editorial.pdf
  - http://wk1080id.hatenablog.com/entry/2018/02/05/123131
  - http://ferin-tech.hatenablog.com/entry/2017/12/18/211329
  - https://kimiyuki.net/writeup/algo/atcoder/codefestival-2016-grand-final-a/
 
 */

// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG x.cpp && ./a.out
const int MAX_N=1e5+1;
int N;
const LL MOD=1e9+7;
LL A[MAX_N],B[MAX_N];
void solve() {
  vector<pair<LL,int>> imos;
  REP(i,N) imos.emplace_back(A[i],-1),imos.emplace_back(B[i],1);
  sort(imos.begin(),imos.end());
  LL res=1;
  int bal=0;
  REP(i,2*N) {
    LL x; int b; tie(x,b)=imos[i];
    int dt=b;
    if(bal!=0&&(bal>0!=dt>0)) {
      res=res*abs(bal)%MOD;
    }
    bal+=dt;
  }
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  
  cin>>N;
  REP(i,N) cin>>A[i];
  REP(i,N) cin>>B[i];
  solve();
  return 0;
}


Measured memory_bytes: 7792
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;

public static class P
{
    public static void Main()
    {
        var nmk = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var a = nmk[0];
        var b = nmk[1];
        var c = nmk[2];
        var k = nmk[3];
        var res = 0;
        var take = Min(a, k);
        k -= take;
        res += take;
        take = Min(b, k);
        k -= take;
        take = Min(c, k);
        res -= take;
        Console.WriteLine(res);
    }
}


Measured memory_bytes: 28140
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}
string YN(bool v) { return v ? "Yes":"No"; }

#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,M,W,H;
	string s;
	while(cin>>H>>W) {
		vector<string> m(H);
		REP(i, H) cin>>m[i];
		ll dx[]={0,0,1,-1};
		ll dy[]={1,-1,0,0};
		ll ok=1;
		REP(y, H) REP(x, W) if(m[y][x]=='#') {
			ll c=0;
			REP(d, 4) {
				ll nx=x+dx[d];
				ll ny=y+dy[d];
				if(IN(nx, 0, W)&&IN(ny, 0, H) && m[ny][nx]=='#') c++;
			}
			if(c==0) ok=0;
		}
		
		cout<<YN(ok)<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 256