akhauriyash/Code-Regression huggingface dataset:
from itertools import combinations_with_replacement
N, M, Q = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(Q)]
ans = 0

def calc(arr):
    score = 0
    for a, b, c, d in X:
        if arr[b - 1] - arr[a - 1] == c:
            score += d
    return score


def dfs(arr):
    global ans
    if len(arr) == N:
        ans = max(ans, calc(arr))

    elif len(arr) == 0:
        for nx in range(1, M + 1):
            dfs(arr + [nx])

    else:
        for nx in range(arr[-1], M + 1):
            dfs(arr + [nx])


dfs([])
print(ans)


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

#define FOR(i, a, b) for (int i = (a); i < (int)(b); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greater<int>()

using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;

const int INF = 1001001001;
const int MOD = 1000000007;
const long long INFL = (1LL << 60);
const double EPS = 1e-9;

bool meet(vi a) {
  bool ret = true;
  bool pos = (a[0] > 0);
  int sum = a[0];
  FOR(i, 1, a.size()) {
    sum += a[i];
    if ((pos && i % 2 && sum >= 0) || (pos && !(i % 2) && sum <= 0) ||
        (!pos && i % 2 && sum <= 0) || (!pos && !(i % 2) && sum >= 0)) {
      ret = false;
      break;
    }
  }
  return ret;
}

uint64_t solve(vi a, uint64_t res) {
  int sum = a[0];
  bool pos = (a[0] > 0);
  FOR(i, 1, a.size()) {
    if ((pos && i % 2 && sum + a[i] >= 0) ||
        (!pos && !(i % 2) && sum + a[i] >= 0)) {
      res += abs(sum + a[i] - (-1));
      a[i] = -1 - sum;
    } else if ((pos && !(i % 2) && sum + a[i] <= 0) ||
               (!pos && i % 2 && sum + a[i] <= 0)) {
      res += abs(sum + a[i] - 1);
      a[i] = 1 - sum;
    }
    sum += a[i];
  }
  return res;
}

int main() {
  int N;
  cin >> N;
  vi a(N);
  rep(i, N) cin >> a[i];
  bool flg = meet(a);

  bool pos = (a[0] > 0);
  bool isZero = (a[0] == 0);
  uint64_t res = 0;
  if (isZero) {
    res++;
    a[0] = 1;
  }
  uint64_t res1 = solve(a, res);

  res = 0;
  if (pos) {
    res += abs(a[0] - (-1));
    a[0] = -1;
  } else if (isZero) {
    res++;
    a[0] = -1;
  } else {
    res += abs(a[0] - 1);
    a[0] = 1;
  }
  uint64_t res2 = solve(a, res);

  res = min(res1, res2);
  if (flg) res = 0;

  cout << res << endl;
}

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

int main() {
    int n; cin >> n;
    vector<string> M(n);
    vector<vector<int>> reply(n + 1);
    rep(i, n) {
        int k; cin >> k >> M[i];
        reply[k].push_back(i);
    }
    function<void(int, int)> dump = [&](int d, int k) {
        if (k > n) return;
        for (int& i : reply[k]) {
            cout << string(d, '.') << M[i] << endl;
            dump(d + 1, i + 1);
        }
    };
    dump(0, 0);
}

Measured memory_bytes: 3388
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <algorithm>
#define rep(i, a, b) for (int i = (a), _ = (b); i <= _; ++ i)
#define per(i, a, b) for (int i = (a), _ = (b); i >= _; -- i)
#define For(i, a, b) for (int i = (a), _ = (b); i < _; ++ i)
#define ri rd<int>
using namespace std;
typedef long long LL;

template<class T> inline T rd() {
	bool f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = 0;
	T x = 0; for (; isdigit(c); c = getchar()) x = x * 10 + c - 48; return f ? x : -x;
}

inline int ask(LL x) {
	static char s[7];
	printf("? %lld\n", x); fflush(stdout);
	scanf("%s", s);
	return s[0] == 'Y';
}

inline void wow(LL x) {
	printf("! %lld\n", x); fflush(stdout);
	exit(0);
}

void solve1(LL r) {
	LL l = r / 10; --r;
	while (l < r) {
		LL mid = (l + r) >> 1;
		if (ask(mid * 10)) r = mid;
		else l = mid + 1;
	}
	wow(r);
}

void solve2() {
	for (LL t = 1, i = 0; i <= 10; ++ i, t *= 10LL)
		if (ask(t+1)) wow(t);
}

int main() {

	for (LL t = 1, i = 0; i <= 10; ++ i, t *= 10LL)
		if (!ask(t)) solve1(t);

	solve2();

	return 0;
}

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

int main(){
    ll n;
    cin >> n;
    vector<int> h(n);
    rep(i, 0, n){
        cin >> h[i];
    }
    vector<char> mark(n-1);
    int cnt = 0, c = 0;
    rep(i, 0, n-1){
        if (h[i] >= h[i+1]){
            mark[i] = '>';
            c ++;
        }
        else{
            mark[i] = '<';
            c = 0;
        }
        cnt = max(cnt, c);
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 768
# include <bits/stdc++.h>
using namespace std;
namespace Base{
	# define mr make_pair
	typedef long long ll;
	typedef double db;
	const int inf = 0x3f3f3f3f, INF = 0x7fffffff;
	const ll  infll = 0x3f3f3f3f3f3f3f3fll, INFll = 0x7fffffffffffffffll;
	template<typename T> void read(T &x){
    	x = 0; int fh = 1; double num = 1.0; char ch = getchar();
		while (!isdigit(ch)){ if (ch == '-') fh = -1; ch = getchar(); }
		while (isdigit(ch)){ x = x * 10 + ch - '0'; ch = getchar(); }
	    if (ch == '.'){
	    	ch = getchar();
	    	while (isdigit(ch)){num /= 10; x = x + num * (ch - '0'); ch = getchar();}
		}
		x = x * fh;
	}
	template<typename T> void chmax(T &x, T y){x = x < y ? y : x;}
	template<typename T> void chmin(T &x, T y){x = x > y ? y : x;}
}
using namespace Base;

const int N = 400010;
ll p[N + N];
double preb[N], s[N], bakb[N], ans;
int b[N + N], n, st[N], top;

double query(int x, int y, int i){
	int dx = i - x, dy = y - i;
	double final = 1.0 * p[x] * dy / (dx + dy) + 1.0 * p[y] * dx / (dx + dy);
	double k = ((dx - 1.0) / dx + (dy - 1.0) / dy) / 2;
	k = 1 / (1 - k);
	final = final - b[i] * k;
	double now = bakb[i + 1] - bakb[y] - (s[y - 1] - s[i]) * (n - y + 1), t = k / dy;
	final = final - now * t;
	now = preb[i - 1] - preb[x] - (s[i - 1] - s[x]) * x, t = k / dx;
	final = final - now * t;
	return final;
}
int main(){
	read(n);
	ll mx = 0;
	int mxi = 1;
	for (int i = 1; i <= n; i++){
		read(p[i]);
		if (p[i] > mx) mx = p[i], mxi = i;
	}
	for (int i = 1; i <= n; i++) read(b[i]);
	for (int i = 1; i <= n; i++) p[i + n] = p[i], b[i + n] = b[i];
	for (int i = 1; i <= n; i++){
		p[i] = p[mxi + i - 1], b[i] = b[mxi + i - 1];
		preb[i] = i * b[i] + preb[i - 1];
		s[i] = b[i] + s[i - 1];
	}
	for (int i = n; i >= 1; i--){
		bakb[i] = bakb[i + 1] + (n - i + 1) * b[i];  
	}
	p[n + 1] = p[1], b[n + 1] = b[1];
	st[top = 1] = 1;
	for (int i = 2; i <= n + 1; i++){
		while (top > 1 && query(st[top - 1], i, st[top]) > p[st[top]]) top--;
		st[++top] = i;
	}
	
	for (int i = 1; i < top; i++){
		ans = ans + p[st[i]];
		for (int j = st[i] + 1; j < st[i + 1]; j++)
			ans = ans + query(st[i], st[i + 1], j);
	}
	ans = ans / n;
	printf("%.10lf\n", ans);
	return 0;
}



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

int main() {
  int n;
  cin >> n;
  vector<int> b(n - 1);
  rep(i, n - 1) cin >> b[i];
  vector<int> a(n);
  a[0] = b[0];
  for (int i = 1; i < n - 1; i++) {
    a[i] = min(b[i - 1], b[i]);
  }
  a[n - 1] = b[n - 2];
  int ans = 0;
  rep(i, n) {
    ans += a[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3556
#include <iostream>
#include <string>
using namespace std;
int main(void){
	int k, s, ans, x, y, z, count = 0;
	cin >> k >> s;
	for (x = 0; x <= k; x++) {
		for (y = 0; y <= k; y++) {
			int  z = s - x - y;
			if (0 <= z && z <= k) {
					count++;
				
			}
		}
	}
	cout << count << endl;
	return 0;
}
	
	

Measured memory_bytes: 256
import os

def main():
    num_a,num_b = (int(x) for x in input().split())
    num_max = num_a * num_b
    
    if (num_b > num_b):
        num = num_a
        num_a = num_b
        num_b = num

    r = num_a % num_b

    while(r != 0):
        num_a = num_b
        num_b = r
        r = num_a % num_b

    print(int(num_max/num_b))

if __name__ == "__main__":
    main()



Measured memory_bytes: 3060
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

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

const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;


int main()
{
	ll h, w;
	cin >> h >> w;

	vector<string> m;
	for (ll i = 0; i < h; i++)
	{
		string s;
		cin >> s;

		bool b = false;
		for (ll j = 0; j < w; j++)
		{
			if (s[j] == '#')
			{
				b = true;
				break;
			}
		}

		if (b)
		{
			m.push_back(s);
		}
	}

	h = m.size();
	for (ll i = 0; i < w; i++)
	{

		bool b = false;
		string s;
		for (ll j = 0; j < h; j++)
		{
			if (m[j][i] == '#')
			{
				b = true;
			}
		}

		if (!b)
		{
			for (ll j = 0; j < h; j++)
			{
				m[j][i] = '-';
			}
		}
	}

	for (ll i = 0; i < h ; i++)
	{

		for (ll j = 0; j < w; j++)
		{
			if (m[i][j] != '-')
			{
				print(m[i][j]);
			}
		}

		println("");
	}

}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
	int n;
	while(cin>>n,n) 
	{
		int w,h;
		cin>>w>>h;
		int f[h][w];
		memset(f,0,sizeof(f));

		for(int i = 0; i < n; ++i)
		{
			int x,y; cin>>x>>y;
			f[y-1][x-1]=1;
		}

		int s,t; cin>>s>>t;
		int ans=0;

		for(int i = 0; i <= h-t+1; ++i)
		{
			for(int j = 0; j <= w-s+1; ++j)
			{
				int tmp=0;
				for(int k = 0; k < t; ++k)
				{
					for(int l = 0; l < s; ++l)
					{
						if(f[i+k][j+l]==1) tmp++;	
					}
				}				
				ans=max(ans,tmp);
			}			
		}
		cout<<ans<<endl;
	}
  return 0;
}

Measured memory_bytes: 1200
#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 n;
  cin >> n;

  vector<int> x(n);
  float ave=0;
  int tmp;
  for(int i=0; i<n; i++){
    cin >> tmp;
    x[i] = tmp;
    ave += tmp;  
  }
  
  //PがXiの平均値に直近の整数であるとき、最小
  ave /= (float)n;
  int p;
  if(ceil(ave)-ave > ave-floor(ave)) p=floor(ave);
  else p= ceil(ave);
  
  ll sum=0;
  for(int i=0; i<n; i++){
    sum += (x[i] - p)*(x[i] - p);
  }
  cout << sum << endl;
  
  return 0;
}

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

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

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

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

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

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

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

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

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

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

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

fn main() {
    input! {
        s: i64,
    }
    fn f(x: i64) -> i64 {
        if x % 2 == 0 {
            x / 2
        } else {
            3 * x + 1
        }
    }
    fn a(s: i64, i: i64, dp: &mut std::collections::HashMap<i64, i64>) -> i64 {
        if dp.get(&i).is_some() {
            *dp.get(&i).unwrap()
        } else {
            let tmp = if i == 1 { s } else { f(a(s, i - 1, dp)) };
            dp.insert(i, tmp);
            tmp
        }
    }
    let mut dp = std::collections::HashMap::new();
    let mut dpset = std::collections::HashSet::new();
    for i in 1.. {
        let an = a(s, i, &mut dp);
        match dpset.get(&an) {
            Some(_) => {
                println!("{}", i);
                return;
            }
            None => {
                dpset.insert(an);
            }
        }
    }
}


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

int p[8] = {1, 0, -1, 0, 1, -1, 1, -1};
int q[8] = {0, 1, 0, -1, 1, 1, -1, -1};

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

    for(int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (s[i][j] == '#') {
                cout << s[i][j];
                continue;
            }
            int count = 0;
            for (int k = 0; k < 8; k++) {
                int x = i + p[k];
                int y = j + q[k];
                if (0 <= x && x < h && 0 <= y && y < w && s[x][y] == '#')
                    count++;
            }
            cout << count;
        }
        cout << endl;
    }
    return 0;
}


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

#define all(a) a.begin(), a.end()
#define allr(a) a.rbegin(), a.rend()
#define rev(v) reverse(v.begin(), v.end());
#define io() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); srand(time(NULL));
#define check cout<<"?\n";
 
using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

signed main(){
    io();
    int n; cin >> n;
    unordered_map <string,ll> ump;
    for(int i = 0; i < n; ++i){
        string s; cin >> s;
        sort(all(s));
        ++ump[s];
    }
    ll ans = 0;
    for(const auto & x : ump){
        ll val = x.second;
        ans += (val * (val - 1) / 2);
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 10280
#include <bits/stdc++.h>
using namespace std;
string s[10];
int n;
int main(){
	cin>>n;
	cin>>s[0]>>s[1];
	for(int i=0;i<s[1].size()*2;i++){
		cout<<s[i%2][i/2];
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    string s;
    cin >> s;
    int n = s.size();
    int mul = 1, rem = 0;
    long long answer = 0;
    vector<int> cnt(2222);
    cnt[0] = 1;
    for (int i = n - 1; i >= 0; --i) {
        rem = (rem + (s[i] - '0') * mul) % 2019;
        answer += cnt[rem];
        ++cnt[rem];
        mul *= 10;
        mul %= 2019;
    }
    cout << answer;
}

Measured memory_bytes: 3724
MOD=10**9+7
cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def desc(ar) ar.sort{|x,y|y<=>x} end##
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end

def puts_yesno(can) puts(can ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def debug(k,v) puts "#{k}:#{v}" end
########### ( ˘ω˘ )ｽﾔｧ… ###########
n=gi
s=gs

# しろるいせきわ
wc=[0]
n.times do |i|
  c = wc[-1]+(1 if s[i]=='.').to_i
  wc << c
end

# くろるいせきわ
bc=[0]
bs=s.reverse
n.times do |i|
  c = bc[-1]+(1 if bs[i]=='#').to_i
  bc << c
end

right=0
(n+1).times do |i|
  sum = wc[i]+bc[(n+1)-i-1]
  right = sum if right<sum
end

puts n-right

Measured memory_bytes: 5624
// AOJ 0251: Magic Square
// 2017.12.16 bal4u@uu
// 2018.1.19

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

#define MAX 100002

/* UNION-FIND library */
int p[MAX], rank[MAX];

void link(int x, int y) {
	if (rank[x] > rank[y]) p[y] = x;
	else { p[x] = y; if (rank[x] == rank[y]) rank[y] = rank[y] + 1;	}
}
int find_set(int x) { if (x != p[x]) p[x] = find_set(p[x]);	return p[x]; }
void union_set(int x, int y) { link(find_set(x), find_set(y)); }

char f[MAX];

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int main()
{
	int n, n1, m, a, b, ans;

	while (n = in()) {
		n1 = n + 1, m = in();

		memset(rank, 0, n1 << 2);
		for (a = 1; a <= n; a++) p[a] = a;
		memset(f, 0, n1);

		ans = 1;
		while (m--) {
			a = in(), b = in();
			if (ans) {	
				if (++f[a] > 2) ans = 0;
				if (++f[b] > 2) ans = 0;
				if (find_set(a) == find_set(b)) ans = 0;
				union_set(a, b);
			}
		}
		puts(ans? "yes": "no");
	}
	return 0;
}


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

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;

#define REP(i, n, m) for(ll i=n; i<(ll)m; ++i)
#define IREP(i, n, m) for(ll i=n-1; i>=m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()

int main(){
    cout << setprecision(20);
    ll m;
    cin >> m;

    vll d(m), c(m);
    rep(i, m) cin >> d[i] >> c[i];

    vector<pair<ll, ll>> t = {{0, 0}, {10, 10}, {10, 11}, {4, 4}, {10, 13}, {10, 14}, {4, 5}, {10, 16}, {10, 17}, {2, 2}};
    ll count = 0;
    rep(i, m){
        if(d[i]==0){
            count += c[i];
            c[i] = 0;
        }
        else{
            while(c[i]>=t[d[i]].first){
                count += c[i]/t[d[i]].first*t[d[i]].second;
                c[i] = c[i]/t[d[i]].first + c[i]%t[d[i]].first;
            }
        }
    }
    vll s;
    rep(i, m){
        rep(j, c[i]) s.push_back(d[i]);
    }
    ll r = s[0];
    REP(i, 1, s.size()){
        r += s[i];
        ++count;
        if(r>=10){
            ++count;
            r = r/10 + r%10;
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 13548
# ABC 075
def getInt(): return int(input())
def getIntList(): return [int(x) for x in input().split()]
def zeros(n): return [0 for i in range(n)]
def db(x): 
    global debug
    if debug: print(x)
debug = False
H,W = getIntList()
S = zeros(H+2)
S[0] = '.'*(W+2)
for i in range(H): S[i+1] = '.' + input() + '.'
S[H+1] = '.'*(W+2)
db(S)
for i in range(1,H+1):
    for j in range(1,W+1):
        if S[i][j]=='#': continue
        c = 0
        for k in range(3):
            if S[i-1][j+k-1]=='#': c += 1
        if S[i][j-1]=='#': c += 1
        if S[i][j+1]=='#': c += 1
        for k in range(3):
            if S[i+1][j+k-1]=='#': c += 1
        S[i] = S[i][:j] + str(c) + S[i][j+1:]
    db(S[i])
db(S)
for i in range(H):
    print(S[i+1][1:W+1])



Measured memory_bytes: 3064
#include<bits/stdc++.h>
 
using namespace std;
 
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define ll long long
#define vi vector<int>
#define pi pair<int,int>
#define mp make_pair

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
 
const int mod=1e9+7;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename A,typename B> istream& operator>>(istream&,pair<A,B>&);
template<typename A> istream& operator>>(istream&,vector<A>&);
void inline add(int&,int);
int mul(int,int);
int powz(int,int);
int sub(int,int);
template<typename A> ostream& operator<<(ostream&,vector<A>&);
 
const int N=1000002;

bool cmp(pi a, pi b){
	if(a.F!=b.F)return a.F>b.F;
	return a.S>b.S;
}

void solve(){
	int n,m;
	cin>>n>>m;
	vector<pair<int,int>>v(n);
	cin>>v;
	sort(all(v));
	vector<pi>z;
	set<int>st;
	for(int i=0;i<m;i++)st.insert(i);
	for(int i=0;i<n;i++){
		//~ if(v[i].F<=m){
			z.pb({v[i].S,v[i].F});
		//~ }
	}
	n=z.size();
	sort(all(z),cmp);
	ll ans=0;	
	for(int i=0;i<n;i++){
		debug(z[i]);
		debug(st);
		auto it=st.lower_bound(z[i].S-1);
		if(it!=st.end())
		debug(*it);
		if(it!=st.end()){
			ans+=z[i].F;
			st.erase(it);
		}
		if(st.empty())break;
		
	}
	cout<<ans;
		
	
	
	
	
}

 
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int tc=1;
	//~ cin>>tc;
	for(int _=0;_<tc;_++){
		//~ cout<<"Case #"<<_+1<<": ";
		solve();
		if(_!=tc-1)
		cout<<"\n";
	}
}
 
int mul(int a,int b)
{
	return ((a)*1ll*(b))%mod;
}
 
void inline add(int &a,int b)
{
	a+=b;
	if(a>=mod)a-=mod;
}
 
int sub(int a,int b){
	a-=b;
	if(a<0){
		a+=mod;
	}
	return a;
}
 
int powz(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1)res=mul(res,a);
		b/=2;
		a=mul(a,a);
	}
	return res;
}
 
template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x) {
	input>>x.F>>x.S;
	return input;
}
 
template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
	for(auto& i:x)
		input>>i;
	return input;
}
 
template<typename A>
ostream& operator<<(ostream& output,vector<A>& x) {
	for(auto& i:x)
	    output<<i<<' ';
	return output;
}


Measured memory_bytes: 6908
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define vi vector<ll>
#define pb push_back
#define ff first
#define ss second
#define inf 2e18
#define ull unsigned long long
#define pi acos(-1.0)
#define mod 1000000007
#define lop0(n) for(ll i=0;i<n;i++)
#define lopj(n) for(ll j=0;j<n;j++)
#define lop1(n) for(ll i=1;i<=n;i++)
#define all(v) v.begin(),v.end()
ll Set(ll N,ll pos){ return N=N | (1LL<<pos); }
ll reset(ll N,ll pos){ return N= N & ~(1LL<<pos); }
bool check(ll N,ll pos){ return (bool)(N & (1LL<<pos)); }
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

main()
{
    fastio;
    ll n;
    cin>>n;
    ll ans=0;
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j*i<n;j++)
        {
           ans+=1;
        }
    }
    cout<<ans;
}



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

int main(){
	int H,W;
	while(cin>>H>>W){
		if((H==0)&(W==0)){
			return 0;}
			
		for(int i=0;i<H;i++){
		    if((i==0)||(i==H-1)){
		        for(int j=0;j<W;j++){
		            cout<<"#";
		        }
              cout<<endl;
		        continue;
		    }
			for(int j=0;j<W;j++){
			    if((i==0)||(i==H-1)){
			        
			    }
			    if(j==0){
				cout<<"#";
			    }
			    else if(j==W-1){
			        cout<<"#";
			    }
			    else{cout<<".";
			    }
			}
			cout <<endl;
		}
		cout<<endl;
	}
	return 0;
	
}





Measured memory_bytes: 3024
#include<stdio.h>
#include<math.h>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define abs(a) ((a)>0 ? (a):-(a))
#define ll long long

int main(){
	ll n,small =10000000000;
	int ans = 0ll;

	scanf("%lld",&n);

	if(n == 1 || n == 2){
		printf("1\n");
		return 0;
	}
	if(n == 3){
		printf("1\n");
		return 0;
	}
	FOR(i,1,sqrt(n)+1){
		if(n % i == 0){
			if(small > (i>n/i ? i:n/i)) small = (i>n/i ? i:n/i);
		}
	}

	//printf("%lld\n",small);


	FOR(i,1,12){
		if(small < pow(10,i)){
			ans = i;
			break;
		}
	}

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

Measured memory_bytes: 128
// coded by zeffy
#pragma GCC optimize("O3","unroll-loops","omit-frame-pointer","inline") //Optimization flags
#pragma GCC option("arch=native","tune=native","no-zeroupper") //Enable AVX
#pragma GCC target("avx","popcnt")  //Enable AVX
#include <x86intrin.h> //SSE Extensions
#include <bits/stdc++.h> 
using namespace std;
#define eb emplace_back
#define mp make_pair
#define hello cout<<"hello"<<"\n"
#define forr(i,a,b) for(int i=a;i<b;i++)
#define it(s)	for(auto itr:s)
#define dvg(s) 	for(auto itr:s)	cout<<itr<<" ";cout<<endl;
#define dbg(s)	cout<<#s<<"= "<<s<<endl;
typedef long long int lli;
typedef unsigned long long int ulli;
const lli INF=(lli)1e17+5;
const ulli MOD=1e8+7;

int main()
{
   ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    std::cout<< std::fixed;
    std::cout.precision(10);
    
    lli n,W;cin>>n>>W;
    vector<lli> dp((lli)1e5+1,INF);
    dp[0]=0;
    forr(i,0,n)
    {
       lli w,v;
       cin>>w>>v;
       
       for(lli j=100001-v;j>=0;j--)
       {
          dp[j+v]=min(dp[j+v],dp[j]+w);
       }
    }
    

    lli ans=0;
   for(lli i=0;i<(lli)1e5+1;i++) 
   {
       if(dp[i]<=W)
       {
          ans=max(ans,i);
       }
    }

    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 4004
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2 //1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) fixed<<setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) max(x,y)-min(x,y)
#define all(v) v.begin(),v.end()
#define UPDight(a,b) (a+b-1)/b //小数点切り上げ 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int, int>;
typedef vector<int> vit;

//最大公約数
lol gcd(lol x, lol y){
  if(x < y) swap(x, y);
  lol r = x % y;
  while(r != 0){
    x = y;
    y = r;
    r = x % y;
  }
  return y;
}

//最小公倍数
lol lcm(lol x, lol y){
  lol a = x * y;
  return (a / gcd(x, y));
}

signed main(void){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  lol a, b;
  cin >> a>> b;
  cout << a * b << '\n';
  return 0;
}


Measured memory_bytes: 3648
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
#define MAXN 200000
#define MOD 1000000007
int n;
int C[MAXN+5],dp[MAXN+5];
int pre[MAXN+5];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	scanf("%d",&C[i]);
	n=unique(C+1,C+n+1)-C-1;
	dp[0]=1;
	//printf("%d",n);
	for(int i=1;i<=n;i++)
	{
		dp[i]=dp[i-1];
		if(pre[C[i]]!=0)dp[i]=(dp[i]+dp[pre[C[i]]])%MOD;
		pre[C[i]]=i;
	}
	printf("%d",dp[n]);
}

Measured memory_bytes: 2560
#include "bits/stdc++.h"
using namespace std;
#define repi(i,a,b) for(int i=(a), i##_len=(b); i<i##_len; ++i)
#define rep(i,n) repi(i,0,n)
#define repi_(i,a,b) for(int i=(a), i##_len=(b); i<=i##_len; ++i)
#define rep_(i,n) repi_(i,0,n)
#define all(x) (x).begin(),(x).end()
#define vsort(v) sort((v).begin(), (v).end())
#define gsort(v) tsort(v); reverse((v).begin(), (v).end())
#define vrev(v) reverse((v).begin(), (v).end())
#define siz(v) ((int)(v).size())
#define ers(v, n) (v).erase((v).begin() + n)
#define cnt(v, n) count(all(v), n)
#define vmin(v) *min_element(v.begin(), v.end())
#define vmax(v) *max_element(v.begin(), v.end())
#define el "\n"
#define co(x) cout<<(x)<<el
#define coc(c, a, b) if(c)co((a));else co((b))
#define cosp(x) cout<<(x)<<' '
#define YES(c) coc(c,"YES", "NO")
#define Yes(c) coc(c,"Yes", "No")
#define yes(c) coc(c,"yes", "no")
#define POSSIBLE(c) coc(c, "POSSIBLE", "IMPOSSIBLE")
#define Possible(c) coc(c, "Possible", "Impossible")
#define possible(c) coc(c, "possible", "impossible")
#define inf INT_MAX
#ifdef tqktmp_2
#define gc() getchar(); getchar()
#else
#define gc() 1
#endif


typedef long long lint;
typedef vector<int> ivec; typedef vector<string> svec;

lint dx[8] = { 0,1,1,1,0,-1,-1,-1 },
dy[8] = { 1,1,0,-1,-1,-1,0,1 };

template<class T>inline bool maxi(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>inline bool mini(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }




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

	lint a, b, c, d; cin >> a >> b >> c >> d;
	a *= b; c *= d;
	co(max(a, c));
	gc();
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		Work[] works = new Work[n];
		for (int i = 0; i < n; i++) {
		    works[i] = new Work(sc.nextInt(), sc.nextInt());
		}
		Arrays.sort(works, new Comparator<Work>() {
		    public int compare(Work w1, Work w2) {
		        if (w1.day == w2.day) {
		            return w2.money - w1.money;
		        } else {
		            return w2.day - w1.day;
		        }
		    }
		});
		PriorityQueue<Work> queue = new PriorityQueue<>(new Comparator<Work>() {
		    public int compare(Work w1, Work w2) {
		        return w1.money - w2.money;
		    }
		});
		int day = 0;
		for (int i = 0; i < n; i++) {
		    if (day + works[i].day <= m) {
		        queue.add(works[i]);
		        day++;
		    } else if (day + works[i].day == m + 1) {
		        if (queue.size() > 0 && queue.peek().money < works[i].money) {
		            queue.poll();
		            queue.add(works[i]);
		        }
		    }
		}
		long ans = 0;
		while (queue.size() > 0) {
		    ans += queue.poll().money;
		}
		System.out.println(ans);
   }
   
   static class Work {
       int day;
       int money;
       
       public Work(int day, int money) {
           this.day = day;
           this.money = money;
       }
       
       public String toString() {
           return day + ":" + money;
       }
   }
}


Measured memory_bytes: 62560
/**
 *    author:  otera    
**/
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

void solve() {
	int H, W, h, w; cin >> H >> W >> h >> w;
    if(H % h == 0 && W % w == 0) {
        cout << "No" << endl;
        return;
    }
    cout << "Yes" << endl;
    rep(i, H) {
        rep(j, W) {
            if((i + 1) % h == 0 && (j + 1) % w == 0) {
                cout << -4000 * (h * w - 1) - 1 << " ";
            } else {
                cout << 4000 << " ";
            }
        }
        cout << endl;
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
struct mat{
	long long arr[50][50]={};
};
long long md = 1e9 + 7;
int n;
void print(mat a){
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			cout << a.arr[i][j]<<" ";
		}
		cout <<endl;
	}
}
mat matmulti(mat a, mat b){
	mat ret;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			for(int k = 0; k < n; k++){
				ret.arr[i][j] += (a.arr[i][k] * b.arr[k][j])%md;
				ret.arr[i][j] %= md;
			}
		}
	}
	return ret;
}
mat fast(mat base, long long k){
	if(k == 0){
		mat ret;
		for(int i = 0; i < n; i++)
			ret.arr[i][i] = 1;
		return ret;
	}
//	cout << k <<endl;
	mat temp = fast(base, k/2);
	temp = matmulti(temp, temp);
	if(k%2 == 1){
		temp = matmulti(temp, base);
	}
	return temp;
}
int main(){
	long long k;
	cin >> n >> k;
	mat base;
	for(int i = 0; i < n; i++)
		for(int j = 0; j < n; j++)
			cin >> base.arr[i][j];
	mat ret = fast(base, k);
	long long ans = 0;
	
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			ans += ret.arr[i][j];
			ans %= md;
		}
	}
	cout << ans;
}

Measured memory_bytes: 9600
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input!{
        c: [Chars;3],
    }

    let ans: String = [c[0][0],c[1][1],c[2][2]].to_vec().iter().collect();
    println!("{}", ans);

}


Measured memory_bytes: 2132
#include <iostream>
using namespace std;
const int maxn = 1000000;
int dp[maxn];
bool ar[maxn];
int main()
{
	for(int i = 2;i<=maxn;i++)
	{
		if(!ar[i])
		{
			for(int j = 2;j*i<maxn;j++)
				ar[i*j] = true;
		}
		dp[i] = dp[i-1] + !ar[i];
	}
	for(int n;cin >> n;)
		cout << dp[n] <<endl;
	return 0;
}

Measured memory_bytes: 6044
#include <bits/stdc++.h>
#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 INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
 
//const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};
 
int main()
{
	int a, b, c, d, p;
	cin >> a >> b >> c >> d >> p;

	int ans1 = 0;
	int tmp = p;
	while (tmp > 0){
		ans1 += a;
		tmp--;
	}

	int ans2 = 0;
	if (p < c) ans2 = b;
	else {
		ans2 += b;
		p -= c;
		while (p > 0){
			ans2 += d;
			p--;
		}
	}

	cout << (ans1 < ans2 ? ans1 : ans2) << endl;
}


Measured memory_bytes: 3104
#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;
typedef long long llint;
const int Maxn = 200000 + 10;

int n,A[Maxn];

llint getans(int b){
	llint ret = 0;
	for(int i=1;i<=n;i++) ret += (llint)abs(A[i]-b-i);
	return ret;
}

void solve(){
	scanf("%d",&n);
	int Mx = 0;
	for(int i=1;i<=n;i++){scanf("%d",&A[i]); Mx = max(Mx,A[i]);}
	int l = -1e9,r = 1e9; llint ans;
//	getans(-2);
	while(l + 1 < r){
		int x = (r - l + 1) / 3,mid1 = l + x,mid2 = r - x;
		llint ans1 = getans(mid1),ans2 = getans(mid2);
//		printf("%d %d %d %d %d %d\n",l,r,mid1,mid2,ans1,ans2);
		if(ans1 > ans2) l = mid1; else r = mid2;
	}
	ans = min(getans(l),getans(r));
	printf("%lld\n",ans); 
}

int main(){
	solve();
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,n,m) for(int i=n;i<=(int)(m);i++)
#define RFOR(i,n,m) for(int i=(int)(n);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(std::unique(all(x)), x.end());
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;
const double PI=acos(-1);
using namespace std;
vector<int> dx={1,0,-1,0};
vector<int> dy={0,1,0,-1};
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    int x;
    cin>>x;
    vector<bool> dp(100900,false);
    dp[0]=true;
    rep(i,x) {
        FOR(d,100,105) {
            dp[i+d]=(dp[i+d] || dp[i]);
        }
    }
    cout<<dp[x]<<endl;
}


Measured memory_bytes: 256
#include <iostream>

int main(){
	int h;
	int w;

	while(true){
		std::cin>>h;
		std::cin>>w;
		if(h==0&&w==0){
			break;
		}
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				std::cout<<((i+j)%2==0?"#":".");
			}
			std::cout<<std::endl;
		}
		std::cout<<std::endl;
	}
	return 0;
}

Measured memory_bytes: 1152
let () = Scanf.scanf "%d\n" @@ fun n ->
  let bb = Array.init (n - 1) @@ fun _ -> Scanf.scanf " %d" Fun.id in
  let ans = ref (bb.(0) + bb.(n - 2)) in
  for i = 1 to n - 2 do
    ans := !ans + min bb.(i) bb.(i - 1)
  done;
  Printf.printf "%d\n" !ans

Measured memory_bytes: 3860
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)n;i++)
int main(void){
    int n;cin>>n;
    int d[n];
    rep(i,n)cin>>d[i];
    int ans = 0;
    rep(i,n){
        for(int j=i+1;j<n;j++){
            ans+=d[i]*d[j];
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define optimizar_io ios_base::sync_with_stdio(0); cin.tie(0);
#define fore(i, a, b) for(int i = a; i < b; i++)
#define fori(i, a, b) for(lli i = a; i <= b; i++)
#define pb push_back
#define popb pop_back
#define mk make_pair
#define fi first
#define se second
#define endl '\n'
#define MAX 60
typedef long long int lli;
typedef long double ld;
const double PI = acos(-1.0);
ld eps = 1e-9;
void swap(int &n, int &n1) {
	n = n xor n1;
	n1 = n xor n1;
	n = n xor n1;
}
int main() {
	optimizar_io
	int a, b, c;
	cin >> a >> b >> c;
	swap(a, b);
	swap(a, c);
	cout << a << " " << b << " " << c << endl;
}

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

int main(){
    int W, H, N;
    int x, y, a;
    int w = 0, h = 0;
    scanf("%d %d %d", &W, &H, &N);
    for(int i = 0; i < N; i++){
        scanf("%d %d %d", &x, &y, &a);
        if(a == 1 && w < x) w = x;
        else if(a == 2 && x < W) W = x;
        else if(a == 3 && h < y) h = y;
        else if(a == 4 && y < H) H = y;
    }
    int s;
    if(W - w < 0 || H - h < 0) s = 0;
    else s = (W - w) * (H - h);
    printf("%d\n", s);
    return 0;
}


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

using LL = long long;
const int N=111111;

LL LT[N],UT[N],LA[N],UA[N];
int A[N], T[N];



const int mod = 1000000007;

int main() {
    int n;
    cin >> n;
    T[0] = 0;
    for (int i=1; i<=n; ++i)
    {
        scanf("%d",&T[i]);
        if (T[i] > T[i - 1]){
            LT[i] = UT[i] = T[i];
        } else {
            LT[i] = 1;
            UT[i] = T[i];
        }
    }
    for (int i=1; i<=n; ++i) {
        scanf("%d", &A[i]);
    }
    A[n + 1] = 0;
    for (int i=n; i>0; --i)
    {
        if (A[i] > A[i + 1])
        {
            LA[i] = UA[i] = A[i];
        }
        else
        {
            LA[i] = 1;
            UA[i] = A[i];
        }
    }
    LL ans = 1;
    for (int i=1; i<=n; ++i)
    {
        LL u = min(UT[i], UA[i]);
        LL l = max(LT[i], LA[i]);
        if (u >= l)
        {
            ans *= u-l+1;
            ans %= mod;
        } else {
            ans = 0;
            break;
        }
    }
    printf("%d\n", static_cast<int>(ans));
}

Measured memory_bytes: 4224
#include <iostream> pre processor directive
#include <string>
#include <iomanip>
#include <cctype>
using namespace std;
int main()
{
    string Arr[3]={"Sunny","Cloudy","Rainy"};
    string S;
    cin>>S;
    for (int i=0;i<3;i++){

        if (S==Arr[i]) {
                if (i==2) i=-1;
                cout<<Arr[i+1]<<endl;
                break; }
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <iomanip> 
#include <cstring>
#include <queue>
#include <stack> 
#include <vector>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
typedef struct{
	int type;
	int v;
}Apple;
struct Rule{
	bool operator()(const Apple & a1,const Apple & a2)const{
		return a1.v > a2.v;
	}
};
Apple as[300005];
int x,y,a,b,c;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> x >> y >> a >> b >> c;
	for(int i = 1;i <= a;i++){
		cin >> as[i].v;
		as[i].type = 1;
	}
	for(int i = a + 1;i <= a + b;i++){
		cin >> as[i].v;
		as[i].type = 2;
	}
	for(int i = a + b + 1;i <= a + b + c;i++){
		cin >> as[i].v;
		as[i].type = 3;
	}
	sort(as + 1,as + a + b + c + 1,Rule());
	ll res = 0,other = 0;;
	for(int i = 1;i <= a + b + c;i++){
		if(x == 0 && y == 0 || x + y - other == 0){
			break;
		}
		if(as[i].type == 1){
			if(x == 0){
				continue;
			}
			x--;
			res += as[i].v;
		}else if(as[i].type == 2){
			if(y == 0){
				continue;
			}
			y--;
			res += as[i].v;;
		}else{
			res += as[i].v;
			other++;
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 2560
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <math.h>
using namespace std;

const int MAXN = 1e6 + 10;
const int Mod = 1e9 + 7;
int N;
int fac[MAXN], inv[MAXN];
int ans;

inline int C( int n, int k ) {
    if( n < k ) return 0;
    return 1ll * fac[n] * inv[k] % Mod * inv[n - k] % Mod;
}

int main() {
    register int i;
    scanf( "%d", &N );
    for( fac[0] = i = 1; i <= N; ++i ) fac[i] = 1ll * fac[i - 1] * i % Mod;
    for( inv[0] = inv[1] = 1, i = 2; i <= N; ++i ) inv[i] = 1ll * ( Mod - Mod / i ) * inv[Mod % i] % Mod;
    for( i = 1; i <= N; ++i ) inv[i] = 1ll * inv[i] * inv[i - 1] % Mod;
    for( i = 1; i < N; ++i ) ans = ( ans + 1ll * C( i - 1, N - i - 1 ) * fac[i] % Mod * fac[N - i - 1] % Mod ) % Mod;
    printf( "%d\n", ( fac[N] - ans + Mod ) % Mod );
    return 0;
}

Measured memory_bytes: 7936
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
	string s;
	int i, j;
	long ans = 0;

	cin >> s;
	int len = s.length();

	s = s + "ZZ";
	
	long tmp = 0;
	for (i = 0; i < len; i++) {
		if (s[i] == 'A') {
			tmp++;
			if (s[i + 1] == 'B' && s[i + 2] == 'C') {
				ans += tmp;
				i += 2;
			}
		}
		else if (s[i] == 'B' && s[i+1]=='C') {
			ans += tmp;
			i += 1;
		}
		else {
			tmp = 0;
		}
//		cout << i << " : " << tmp << endl;
	}

	cout << ans << endl;

	return 0;

}

Measured memory_bytes: 772
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/

lint sgm(lint n) {
	if (n == 0) {
		return 0;
	}
	else {
		return n + sgm(n - 1);
	}
}

int main() {
	lint cnt = 0;
	lint mj = 0;
	lint MJ = 0;

	string S;
	cin >> S;
	lint Ss = S.size();
	vector<char>V(Ss + 2);
	V[0] = '>';
	V[Ss + 1] = '<';
	rep(i, Ss) {
		V[i + 1] = S[i];
	}
	rep(i, Ss + 1) {
		if (V[i] == '>' && V[i + 1] == '<') {
			cnt++;
		}
	}
	vector<lint>m(cnt);
	vector<lint>M(cnt - 1);
	rep(i, Ss + 1) {
		if (V[i] == '>' && V[i + 1] == '<') {
			m[mj] += i;
			mj++;
		}
		if (V[i] == '<' && V[i + 1] == '>') {
			M[MJ] += i;
			MJ++;
		}
	}
	lint ans = 0;
	vector<lint>X(cnt - 1);
	vector<lint>Y(cnt - 1);
	rep(i, cnt - 1) {
		X[i] = M[i] - m[i];
	}
	rep(i, cnt - 1) {
		Y[i] = m[i + 1] - M[i];
	}
	/*rep(i, cnt - 1) {
		cout << X[i] << ' ' << Y[i] << endl;
	}*/
	rep(i, cnt - 1) {
		ans += sgm(X[i]);
		ans += sgm(Y[i]);
		ans -= min(X[i], Y[i]);
	}
	lint c1 = 0;
	lint c2 = 0;
	rep(i, Ss + 2) {
		if (V[i] == '<') {
			c1 = i - 1;
			break;
		}
	}
	rep(i, Ss + 2) {
		if (V[Ss + 1 - i] == '>') {
			c2 = i - 1;
			break;
		}
	}
	ans += sgm(c1);
	ans += sgm(c2);
	//cout << c1 << ' ' << c2 << '!' << endl;
	cout << ans << endl;
}




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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int64_t a,b,x; cin>>a>>b>>x;
	cout<<((a%x)?b/x-a/x:b/x-a/x+1)<<"\n"s;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

// Left.top() == Right.top()の場合は中央値は1つ
// Left.top() < Right.top()の場合はその区間(もしくは2つのどちらか)
priority_queue<ll>Left;
priority_queue<ll, vector<ll>, greater<ll> >Right;
void push(ll x){
    Left.push(x);
    Right.push(x);
    ll l = Left.top();
    ll r = Right.top();
    if(l > r){
        Left.pop();
        Left.push(r);
        Right.pop();
        Right.push(l);
    }
}

ll A[202020];

int main(){

    ll N;
    cin >> N;

    for(ll i = 1; i <= N; i++){
        cin >> A[i];
        A[i] -= i;
        push(A[i]);
    }
    ll ans = 0;
    ll p = Left.top();
    for(ll i = 1; i <= N; i++)ans += abs(A[i] - p);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<n;i++)
ll MAX=1e9;
int main(void){
    ll n,k;cin>>n>>k;
    vector<ll>h(n);rep(i,n)cin>>h.at(i);
    vector<ll>dp(n,MAX);
    dp.at(0)=0;
    rep(i,n){
        for(int j=0;i+j<n&&j<k+1;j++){
            dp.at(i+j)=min(dp.at(i+j),dp.at(i)+abs(h.at(i+j)-h.at(i)));
            }
        }
    cout<<dp.at(n-1);
}

Measured memory_bytes: 1792
#![allow(non_snake_case, unused_imports)]

// Input
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} };}
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,HashMap,BTreeMap,VecDeque};

// Functions

// Main
fn main(){
    input!{
        N: usize,
        T: i64,
        A: [i64; N],
    }
    let mut ans = T;
    for i in 1..N{
        if A[i] > A[i-1]+T{
            ans += T;
        }else{
            ans += A[i]-A[i-1];
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 6396
/**
*    author:  y_takano
*    created: 19.06.2020 15:55:43
**/

#include <bits/stdc++.h>

using namespace std;

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

  int n, m, tmp, sum = 0;
  cin >> n >> m;

  vector<vector<int> > vec(n, vector<int>(m, 0));
  vector<int> vec2(m);

  for (size_t i = 0; i < n; i++)
  {
      for (size_t j = 0; j < m; j++)
      {
          cin >> tmp;
          vec[i][j] = tmp; 
      }
  }

  for (size_t i = 0; i < m; i++)
  {
      cin >> tmp;
      vec2[i] = tmp;
  }
  

  for (size_t i = 0; i < n; i++)
  {
      for (size_t j = 0; j < m; j++)
      {
          sum += vec[i][j] * vec2[j];
      }
      cout << sum << endl;
      sum = 0;
  }
  
  return 0;
}


Measured memory_bytes: 3216