akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <deque>
using namespace std;
using ll = long long; using P = pair<int,int>;
using vl = vector<ll>; using vvl = vector<vl>;
#define mp make_pair
#define pb push_back
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,n) for (int i=(n-1);i >= 0;i--)
#define all(v) v.begin(),v.end()
#define sz(v) (int)((v).size())
#define MAX(v) *max_element(all(v))
#define MIN(v) *min_element(all(v))
#define Sort(v) sort(all(v))
#define Rev(v) reverse(all(v))
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);in(name)
#define vv(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define VV(type,name,h,w) vector<vector<type>>name(h,vector<type>(w));in(name)
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cout << H << " ";
    debug_out(T...);
}
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
    for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
    return os;
}
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
template<class T>bool chmax(T &a, const T &b) {if(a<b){a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if(b<a){a=b; return 1;} return 0;}
// const ll INF = 1LL << 60;
// const ll mod = 1000000007;
const int dx[8] = {1,0,-1,0,1,1,-1,-1}; const int dy[8] = {0,1,0,-1,1,1,-1,-1};

int h, w, ch, cw, dh, dw;

bool canMove(int y, int x) {
    if(y < 0 || y > h-1 || x < 0 || x > w-1) return false;
    return true;
}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    IN(h,w,ch,cw,dh,dw);
    ch--; cw--; dh--; dw--;
    vector<vector<char>> maze(h, vector<char>(w));
    rep(i,h) rep(j,w) cin >> maze[i][j];
    
    vector<vector<bool>> visited(h,vector<bool>(w, false));
    visited[ch][cw] = true;
    deque<pair<P, int>> dq;
    dq.push_front({{ch,cw}, 0});
    while(!dq.empty()) {
        int y, x, cost;
        tie(y, x) = dq.front().first;
        cost = dq.front().second;
        visited[y][x] = true;
        dq.pop_front();
        if(y == dh && x == dw) {
            cout << cost << endl;
            return 0;
        }
        rep(i, 4) {
            int ny = y + dy[i], nx = x + dx[i];
            if(!canMove(ny, nx) || visited[ny][nx] || maze[ny][nx] == '#') continue;
            dq.push_front({{ny, nx}, cost});
        }
        for(int i = -2;i <= 2;i++) for(int j = -2;j <= 2;j++) {
            int ny = y + i, nx = x + j;
            if(!canMove(ny, nx) || visited[ny][nx] || maze[ny][nx] == '#') continue;
            dq.push_back({{ny, nx}, cost + 1});
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 11280
// #pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vll = vector<ll>;
using vii = vector<int>;
using pii = pair<int, int>;

const ll INF = numeric_limits<ll>::max(),
         MOD = 1e9 + 7;

const int INF_i = numeric_limits<int>::max(),
          MAX = 1e6;

int main() {
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
    // freopen("in.in", "r", stdin);

    int n;
    cin >> n;
    vector<double> dp(n + 1, 0);
    dp[0] = 1;
    for (int i = 0; i < n; i++) {
        double p;
        cin >> p;
        for (int j = n; j >= 1; j--) {
            dp[j] = dp[j] * (1 - p) + dp[j - 1] * p;
        }
        dp[0] *= 1 - p;
    }
    cout << fixed << setprecision(10)
        << accumulate(dp.begin() + (n + 1) / 2, dp.end(), 0.0) << '\n';
}

Measured memory_bytes: 256
// #[warn(dead_code)]
// const TOP: u64 = 1000000007;

pub struct Poper<'a> {
	iter: std::str::SplitWhitespace<'a>,
}

impl<'a> Poper<'a> {
	pub fn new(iter: std::str::SplitWhitespace<'a>) -> Poper {
		Poper { iter: iter }
	}
	pub fn read<T: std::str::FromStr>(&mut self) -> T
	where
		<T as std::str::FromStr>::Err: std::fmt::Debug,
	{
		self.iter.next().unwrap().parse().unwrap()
	}
}

use std::collections::BTreeMap;
use std::collections::VecDeque;

fn main() {
	let input = {
		use std::io::Read;
		let mut s = String::new();
		std::io::stdin().read_to_string(&mut s).unwrap();
		s
	};
	let mut iter = Poper::new(input.split_whitespace());

	let n: u64 = iter.read();
	let k: u64 = iter.read();

	let mut d_v: VecDeque<i64> = VecDeque::new();
	for _ in 0..n {
		d_v.push_back(iter.read());
	}

	println!("{}", check(k, d_v, BTreeMap::new(), 0, 0));
}

fn check(k: u64, d_v: VecDeque<i64>, having: BTreeMap<i64, usize>, max: i64, pop: usize) -> i64 {
	if k < 1 {
		return max;
	}
	let mut ret = max;
	if 2 != pop && 0 < d_v.len() {
		if 0 == pop {
			let mut d_v2 = d_v.clone();
			if let Some(i) = d_v2.pop_front() {
				let mut having2 = having.clone();
				{
					let v = having2.entry(i).or_insert(0);
					*v += 1;
				}
				let tmp = check(k - 1, d_v2, having2, max + i, 0);
				if tmp > ret {
					ret = tmp;
				}
			}
		}
		let mut d_v2 = d_v.clone();
		if let Some(i) = d_v2.pop_back() {
			let mut having2 = having.clone();
			{
				let v = having2.entry(i).or_insert(0);
				*v += 1;
			}
			let tmp = check(k - 1, d_v2, having2, max + i, 1);
			if tmp > ret {
				ret = tmp;
			}
		}
	}
	if 0 < having.len() {
		let mut having2 = having.clone();
		let (&i, &c) = having2.iter().next().unwrap();
		if i > 0 {
			return ret;
		}
		if c < 2 {
			having2.remove(&i);
		} else {
			having2.insert(i, c - 1);
		}
		// let mut d_v2 = d_v.clone();
		// d_v2.push_front(i);
		// let tmp = check(k - 1, d_v2, having2.clone(), max - i, false);
		// if tmp > ret {
		// 	ret = tmp;
		// }
		let mut d_v2 = d_v.clone();
		d_v2.push_back(i);
		let tmp = check(k - 1, d_v2, having2, max - i, 2);
		if tmp > ret {
			ret = tmp;
		}
	}
	ret
}


Measured memory_bytes: 4352
def resolve():
	N = int(input())
	A = list(map(int, input().split()))
	a_max = max(A)+1
	B = {}
	for i in range(N):
		a = A[i]
		if a not in B.keys():
			for j in range(a, a_max, a):
				B[j] = False
			B[a] = True
		else:
			B[a] = False
	Y = list(B.values()).count(True)
	print(Y)
resolve()

Measured memory_bytes: 99944
#include <stdio.h>
#define LL long long
int main(){
	int n,i,cnt;
	LL d,x,y;
	scanf("%d",&n);
	scanf("%lld",&d);
	cnt=0;
	for(i=1;i<=n;i++){
		scanf("%lld%lld",&x,&y);
		if(x*x+y*y<=d*d)cnt++;
	}
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 1716
#include<iostream>
using namespace std;
#define MAX 100005
#define NIL -1

struct Node { int p, l, r; };

Node T[MAX];
int n, D[MAX];

void print(int u) {
  int i, c;
  cout << "node " << u << ": ";
  cout << "parent = " << T[u].p << ", ";
  cout << "depth = " << D[u] << ", ";

  if ( T[u].p == NIL ) cout << "root, ";
  else if ( T[u].l == NIL ) cout << "leaf, ";
  else cout << "internal node, ";

  cout << "[";

  for ( i = 0, c = T[u].l; c != NIL; i++, c = T[c].r ) {
    if ( i ) cout << ", ";
    cout << c;
  }

  cout << "]" << endl;
}

int rec (int u, int p) {
  D[u] = p;
  if (T[u].r != NIL) rec(T[u].r, p);
  if (T[u].l != NIL) rec(T[u].l, p + 1);
}

int main() {
  int n;
  cin >> n;
  for ( int i = 0; i < n; i++ ) T[i].p = T[i].l = T[i].r = NIL;

  int v, d, l, c;
  for ( int i = 0; i < n; i++ ) {
    cin >> v >> d;
    for ( int j = 0; j < d; j++ ) {
      cin >> c;
      if ( j == 0 ) T[v].l = c;
      else T[l].r = c;
      l = c;
      T[c].p = v;
    }
  } 

  int r;
  for ( int i = 0; i < n; i++ ) {
    if ( T[i].p == NIL ) r = i;
  }

  rec(r, 0);

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

  return 0;
}



Measured memory_bytes: 7772
import sys

n, g, *pc = map(int, sys.stdin.read().split())
p, c = pc[::2], pc[1::2]
s = [100 * (i + 1) for i in range(n)]

def main():
    res = float('inf')
    for i in range(1 << n):
        tot = 0
        cnt = 0
        for j in range(n):
            if i >> j & 1:
                cnt += p[j]
                tot += s[j] * p[j] + c[j]
            else:
                k = j
        if tot >= g: res = min(res, cnt); continue
        d = (g - tot + s[k] - 1) // s[k]
        if d < p[k]: res = min(res, cnt + d)
    print(res)

if __name__ ==  '__main__':
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>

using namespace std;
typedef long long ll;

int main() {
  int N, T, A;
  cin >> N >> T >> A;
  vector<int> vec(N + 1);
  
  double minv = 1e9;
  int k = -1;
  for (int i = 1; i <= N; i++) {
    cin >> vec[i];
    double v = T - vec[i] * 0.006;
    if(minv > abs(A - v)) {
      minv = abs(A - v);
      k = i;
    }
  }
  cout << k << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <iomanip>

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

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

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

    int ans = 0;
    rep(i, n){
        int a;
        cin >> a;
        if(a % 2 == 1){
            ans++;
        }
    }

    if(ans % 2 == 0){
        cout << "YES" << endl;
        return 0;
    }
    cout << "NO" << endl;

    return 0;
}


Measured memory_bytes: 256
// Mon Aug 24 16:24:09 IST 2020        
#include <bits/stdc++.h>        
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define forn(ii,a,b)       for(int ii = (int)a ; ii < (int)b  ; ii++ )
#define scan(any)          for(auto &i:any) cin>>i;
#define debug(x)           cerr << #x << " " << x << " -- \n"
#define I__O               ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define int64              long long   
#define all(x)             (x).begin(),(x).end() 
#define ff                 first
#define ss                 second
#define pppp               pair <int,int> 
#define flushOff           fflush(stdout) 
#define precise(x)         cout << fixed << setprecision(12) << x << '\n'; 
using namespace std ;    
// policy based   
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set ; 
 
const int MOD1 = 1e9+7;
const int MOD2 = 1e9+9;
const double pi = 3.141592653589793238;
const int INF = 2e9+7; 
// const int N = 2e5+7;
struct compare{
    bool operator()(pair <int,int> A, pair <int,int> B){
        if(A.first == B.first)
            return A.second > B.second;
        return A.first > B.first;
    }
}; 
void print(vector <int>v){
    for(int t : v){
        cout << t << ' ';
    }
    cout << '\n';
} 
int tests(){  
    int n;
    cin >> n;
    vector <int> h(n);
    for(auto &x : h){
        cin >> x;
    }    
    map <int,int> m;
    m[h[0]]++;
    int64 ans  = 0LL;
    forn(i,1,n){ 
        ans += (int64)m[i-h[i]];
        m[i+h[i]]++;
    }
    cout << ans << '\n';
    return 0;
}    
int main(){
    I__O ;      
    int cases = 1 ;  
    // cin >> cases ;
    while(cases--)
        tests(); 
    return 0 ; 
}
 


Measured memory_bytes: 21028
n=int(input())
a=0
for i in range(1,n+1):
    x=int(i)
    if  x%3==0:
        a=1

    else:
        while x >= 0 and i >=10:
            if x%10==3:
                a=1
                break
            elif x>10:
                x=x//10
            else:
                break
    if a:
        print(f" {i}",end="")
        a=0
print()   


Measured memory_bytes: 5880
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author hakamada
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TPBC_1 solver = new TPBC_1();
        solver.solve(1, in, out);
        out.close();
    }

    static class TPBC_1 {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String S = in.next();

            if (S.length() == 2) {
                out.println(S);
            } else {
                String outst[] = S.split("");
                out.println(outst[2] + outst[1] + outst[0]);
            }
        }

    }
}



Measured memory_bytes: 21972
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <iomanip>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
const int inf = 1e9;
const ll linf = 1LL << 50;

typedef struct stick_ {
		int l, r, lt, rt;
		stick_(int l, int r, int lt, int rt): l(l), r(r), lt(lt), rt(rt){};
} stick;

int gcd(int x, int y){
		if(y == 0)return x;
		else return gcd(y, x % y);
}

vector<stick> vec;
bool fi[101];

ll gg(ll x, ll y){
		return x / gcd(x, y) * y;
}

ll calc(int x){
		stick s = vec[x];
		int lw, rw;
		if(s.lt != 0)lw = calc(s.lt -1);
		else lw = 1;
		if(s.rt != 0)rw = calc(s.rt - 1);
		else rw = 1;
		ll tmp = gg(lw*s.l, rw*s.r);
		return tmp / s.l + tmp / s.r;
}

int main(int argc, char const* argv[])
{
	int n;
	while(true){
			vec.erase(vec.begin(), vec.end());
			cin >> n;
			fill(fi, fi + n, false);
			if(n == 0)break;
			for(int i = 0; i < n; i++){
					int p, q, r, s;
					cin >> p >> q >> r >> s;
					vec.pb(stick(p, q, r, s));
					if(r != 0)fi[r-1] = true;
					if(s != 0)fi[s-1] = true;
			}
			int start = -1;
			for(int i = 0; i < n; i++){
					if(!fi[i]){
							start = i;
							break;
					}
			}
			cout << calc(start) << endl;
	}
	return 0;
}



Measured memory_bytes: 3092
//Bismillahir Rahmanir Rahim
#include <bits/stdc++.h>
using namespace std;

typedef long long              ll;
typedef long double            ld;
typedef pair<int, int>         pi;
typedef vector<int>            vi;
typedef vector<pair<int, int>> vpi;

#define pb       push_back
#define all(x)   begin(x), end(x)
#define sz(x)    (int)(x).size()
#define ff       first
#define ss       second
#define mp       make_pair
#define lb       lower_bound
#define ub       upper_bound
#define tcase()  int t; cin >> t; while(t--)

const int MOD = 1e9 + 7; // 998244353;
const int MX  = 2e5 + 5;
const ll  INF = 1e18;
const ld  PI  = acos((ld) -1);

void setIO(string name = "") {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    if(sz(name)){
        freopen((name+".in").c_str(), "r", stdin);
        freopen((name+".out").c_str(), "w", stdout);
    }
}

int main(){

    setIO();

    int n, l, r;
    cin >> n >> l >> r;

    int dif = r - l - 1;

    int arr[n + 1] = {0};

    for(int i = 1; i <= n; i++){
        for(int j = i + 1; j <= n; j++){
            arr[min({j - i, abs(l - i) + 1 + abs(j - r), abs(r - i) + 1 + abs(j - l)})]++;
        }
    }

    for(int i = 1; i < n; i++) cout << arr[i] << "\n";
}


Measured memory_bytes: 3664
#include <cstdio>
#include <algorithm>

const int P = (int)1e9 + 7;

int s[205];
int num[(int)1e5 + 5];
int64_t factorial[205];
int64_t comb[205][205];
int64_t f[(int)1e5 + 5];

void init(int n, int x) {
  std::sort(s, s + n);
  
  factorial[0] = 1;
  for (int i = 1; i <= n; ++i)
    factorial[i] = factorial[i - 1] * i % P;

  for (int i = 0; i <= n; ++i) {
    comb[i][0] = comb[i][i] = 1;
    for (int j = 1; j < i; ++j)
      comb[i][j] = (comb[i - 1][j] + comb[i - 1][j - 1]) % P;
  }

  for (int i = 0; i < n; ++i) {
    num[s[i]] = 1;
  }
  for (int i = 1; i <= x; ++i)
    num[i] += num[i - 1];
}

int solve(int n, int x) {
  init(n, x);
  for (int i = 0; i <= x; ++i) {
    if (i < s[0]) {
      f[i] = i;
      continue;
    }
    for (int j = 0; j < n; ++j) {
      if (s[j] > i)
        break;
      int tmp = num[i] - num[i % s[j]] - 1;
      f[i] += f[i % s[j]] * comb[num[i] - 1][tmp] % P * 
              factorial[tmp] % P;
      if (f[i] >= P)
        f[i] -= P;
    }
  }

//  for (int i = 0; i < n; ++i) 
//    printf("i = %d, f = %d\n", s[i], (int)f[s[i]]);
//  printf("x = %d f[x] = %d\n", x, (int)f[x]);

  int64_t res = f[x] * comb[n][n - num[x]] % P * factorial[n - num[x]] % P;
  return res;
}

int main() {
  int n, x;
  scanf("%d %d", &n, &x);
  for (int i = 0; i < n; ++i)
    scanf("%d", s + i);
  printf("%d\n", solve(n, x));
  return 0;
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(void) {
    int n;
    cin>>n;
    unordered_map<string,int> mp;
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        sort(s.begin(),s.end());
        mp[s]++;
    }
    ll ans=0;
    for(auto& p : mp){
        int s=p.second;
        ans+=(ll)s*(s-1)/2;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 10660
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    char a;
    cin >> a;
    if (a>='a')
    {
    	cout << 'a';
    }
    else
    {
    	cout << 'A';
    }
    return 0;
}

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

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

  ll H,W; cin >> H >> W;

  if(H == 1 || W  == 1) {
    cout << 1 << endl;
    return 0;
  }

  if(H % 2 == 0 || W % 2 == 0) {
    cout << H * W / 2 << endl;
    return 0;
  }

  if(H % 2 == 1) {
    ll ans = (H - 1ll) * W / 2;
    ans += (ll)ceil((ld)W / 2);
    cout << ans << endl;
  } else {
    ll ans = (W - 1ll) * H / 2;
    ans += (ll)ceil((ld)W / 2);
    cout << ans << endl;
  }
}


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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const double EPS = 1e-10;

const int mod = 1000000007;
struct mint {
    long long x;
    mint(long long x = 0) : x((x % mod + mod) % mod) {}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return (*this) *= a.inv(); }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

int main() {
    lint N;
    cin >> N;
    vector<mint> A(N);
    rep(i, N) {
        lint a;
        cin >> a;
        A[i] = a;
    };

    vector<mint> L(N + 1, 0);
    rep(i, N) L[i + 1] = L[i] + A[i];

    mint ans = 0;
    for (int i = 0; i < N - 1; i++) {
        ans += A[i] * (L[N] - L[i + 1]);
    }
    cout << ans.x << endl;
    return 0;
}

Measured memory_bytes: 6372
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define DEBUG(x) cerr << #x << " = " << x << endl
#define int long long
const int INF = (int)1e9;
int N, M, STEP[3];
vector<vector<int>> G;
bool canMove[50][50][101];
int winning[50];
signed main() {
  ios::sync_with_stdio(false);
  cin >> N >> M >> STEP[0] >> STEP[1] >> STEP[2];
  G.resize(N);
  REP(i,M) {
    int u, v; cin >> u >> v;
    u--; v--;
    G[u].push_back(v);
  }
  memset(canMove, 0, sizeof(canMove));
  REP(i,N) canMove[i][i][0] = true;
  REP(d,100) {
    REP(i,N) REP(j,N) {
      if(canMove[i][j][d]) {
        for(int k : G[j]) canMove[i][k][d + 1] = true;
      }
    }
  }
  REP(i,N) winning[i] = INF;
  winning[N - 1] = 0;
  while(true) {
    bool update = false;
    REP(v,N) {
      int mx = 0;
      REP(k,3) {
        int mn = INF;
        REP(u,N) {
          if(canMove[v][u][STEP[k]]) {
            mn = min(mn, winning[u] + 1);
          }
        }
        mx = max(mx, mn);
      }
      if(winning[v] > mx) {
        winning[v] = mx;
        update = true;
      }
    }
    if(!update) break;
  }
  if(winning[0] == INF) {
    cout << "IMPOSSIBLE" << endl;
  }
  else {
    cout << winning[0] << endl;
  }
}

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

using namespace std;
typedef long long LL;
const double pi = acos(-1.0);
const double eps = 1e-7;
const LL N = 100010;

LL T,n,m,i,j,k,t,a[N],ans=0,cnt=1,aa,bb;

int main()
{
    scanf("%lld",&n);
    for(i=0;i<n;i++){
        scanf("%lld",&a[i]);
    }
    sort(a,a+n);
    for(i=n-1;i>0;i--){
        if(a[i]==a[i-1])cnt++;
        else{
            if(cnt>=4){
                if(!aa){bb=aa=a[i];}
                else bb=a[i];
                printf("%lld",aa*bb);
                //system("pause");
                exit(0);
            }else if(cnt>=2){
                if(!aa){aa=a[i];}
                else{
                    bb=a[i];
                    printf("%lld",aa*bb);
                    //system("pause");
                    exit(0);
                }
            }
            cnt=1;
        }
    }

    if(cnt>=4){
        if(!aa){bb=aa=a[1];}
        else bb=a[1];
        printf("%lld",aa*bb);
        //system("pause");
        exit(0);
    }else if(cnt>=2){
        if(!aa){aa=a[1];}
        else{
            bb=a[1];
            printf("%lld",aa*bb);
            //system("pause");
            exit(0);
        }
    }


    printf("0");
    //system("pause");
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
using namespace std;
int main(void)
{
  int n;
  cin >> n;
  LL minm=0,answer=0;
  while(n--){
    LL a;
    cin >> a;
    if(a>minm+1){
      --a;
      answer+=a/(minm+1);
    }else if(a==minm+1) ++minm;
    if(minm==0) minm=1;
  }
  cout << answer << endl;
}

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

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;
//const int MOD = 998244353;

// Lib
//
void add(ll &a, ll b){
    a += b;
    if (a >= MOD) a -= MOD;
}

int main(){
#ifdef MYLOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    int N; cin >> N;
    vector<int> c(N);
    for (int i = 0; i < N; ++i) cin >> c[i];

    vector<int> places[210000];
    ll dp[210000];

    // places[i] := (c[j] = i となるような j の集まり)
    for (int i = 0; i < N; ++i) places[c[i]].push_back(i);

    // DP
    dp[0] = 1;
    for (int i = 1; i <= N; ++i) {
        // 特に操作しない場合
        add(dp[i], dp[i-1]);

        // 操作する場合
        int color = c[i-1];
        // c[i] が color 色の何番目の要素か
        int it = lower_bound(places[color].begin(), places[color].end(), i-1) - places[color].begin();
        if (it > 0) {
            int j = places[color][it - 1]; // c[j] = c[i] となる j
            if ((i-1) - j > 1){
                add(dp[i], dp[j+1]);
            }
        }
    }
    cout << dp[N] << endl;
}


Measured memory_bytes: 13824
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
char ope[4];
int num[4];
int flag=0;
void dfs(int now,int sum)
{
	if(flag)
		return ;
	if(now==3)
	{
		if(sum==7)
			flag=1;
		return ;
	}
	ope[now]='+';
	dfs(now+1,sum+num[now+1]);
	if(flag)
		return ;
	ope[now]='-';
	dfs(now+1,sum-num[now+1]);
	if(flag)
		return ;
}
int main()
{
	
	for(int i=0;i<4;i++)
		scanf("%1d",&num[i]);
	dfs(0,num[0]);
	for(int i=0;i<4;i++)
	{
		printf("%d",num[i]);
		if(i!=3)
			printf("%c",ope[i]);
	}
	printf("=7");
	return 0;
 } 

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

using namespace std;

int main(){
    int n;
    vector<long> monster;
    vector<long> hero_ab;

    cin>>n;

    for(int i=0;i<n+1;i++){
        long mon;
        cin>>mon;
        monster.push_back(mon);
    }

    for(int i=0;i<n;i++){
        long kill;
        cin>>kill;
        hero_ab.push_back(kill);
    }
    hero_ab.push_back(0);
    long count=0;
    long prev=0;

    for(int i=0;i<n+1;i++){
        if(monster.at(i)<=hero_ab.at(i)+prev){
            count+=monster.at(i);
            if(monster.at(i)<=prev){
                prev=hero_ab.at(i);
            }else{
                if((monster.at(i)-prev)<hero_ab.at(i)){
                    prev=hero_ab.at(i)-(monster.at(i)-prev);
                }else{
                    prev=0;
                }
            }
        }else{
            count+=hero_ab.at(i)+prev;
            prev=0;
        }
    }
    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 2548
#include <bits/stdc++.h>
#define endl '\n'
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define F first
#define S second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double db;

const db inf = 1e18;
const db pi = acos(-1);
const db eps = 1e-9;
const int mod = 998244353;

int main () {
	#ifdef ernestico
		freopen ("a.in", "r", stdin );
//		freopen ("a.out", "w", stdout );
	#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int n; cin >> n;
	vector<ll> a(n);
	db lg = 0;
	for ( auto &i : a ) {
		cin >> i;
		if ( i == 0 ) {
			cout << 0 << endl;
			return 0;
		}

		lg += log ( i );
	}

	if ( lg > log(1e18) ) {
		cout << -1 << endl;
	} else {
		ll ret = 1;
		for ( auto i : a )
			ret = ret * i;
		cout << ret << endl;
	}



	return 0;
}


Measured memory_bytes: 3996
def f(flg, an):
    accum = 0
    ret = 0
    for ai in an:
        accum += ai
        if flg:
            flg = False
            if accum <= 0:
                ret += -accum + 1
                accum = 1
        else:
            flg = True
            if 0 <= accum:
                ret += accum + 1
                accum = -1
    return ret


def main():
    an = list(map(int, open(0).read().split()[1:]))
    print(min(f(False, an), f(True, an)))
    return


main()


Measured memory_bytes: 14084
import sys

def Main():
    a = int(input())
    b = int(input())
    c = int(input())
    d = int(input())
    e = int(input())
    k = int(input())
    
    ans = 'Yay!'
    
    ed = e-d
    ec = e-c
    eb = e-b
    ea = e-a
    dc = d-c
    db = d-b
    da = d-a
    cb = c-b
    ca = c-a
    ba = b-a
    
    if ed > k:
    	ans = ':('
    
    if ec > k:
    	ans = ':('

    if eb > k:
    	ans = ':('
    
    if ea > k:
    	ans = ':('
        
    if dc > k:
    	ans = ':('
        
    if db > k:
    	ans = ':('
    
    if da > k:
    	ans = ':('
    
    if cb > k:	
    	ans = ':('
        
    if ca > k:
    	ans = ':('
        
    if ba > k:
    	ans = ':('
       
    
    print(ans)

Main()

Measured memory_bytes: 3064
n = int(input())
lst = list(map(int, input().split()))
lst.append(0)
goal = [0] * (n + 1)
watercnt = 0
if lst[0] == 0:
  phase = '-'
else:
  phase = '+'
while lst != goal:
  for i in range(n + 1):
    if phase == '+':
      if lst[i] > 0:
        lst[i] -= 1
      else:
        phase = '-'
        watercnt += 1
    else:
      if lst[i] > 0:
        lst[i] -= 1
        phase = '+'
print(watercnt)
    

Measured memory_bytes: 9120
#include <iostream>
#include <algorithm>
#include <array>
using namespace std;

int main(int argc, char const *argv[]) {
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  sort(a,a+n);
  int mid=n/2;
  if(a[mid]!=a[mid-1]){
    cout<<a[mid]-a[mid-1]<<endl;
  }else{
    cout<<0<<endl;
  }

  return 0;
}


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

int nth_bit(int64_t num, int n){
    return (num >> n) & 1;
}

int main(){
    int N, M, X;
    cin >> N >> M >> X;
    vector<int> C(N);
    vector<vector<int>> A(N, vector<int>(M));
    for(int i=0; i<N; i++){
        cin >> C[i];
        for(int j=0; j<M; j++) cin >> A[i][j];
    }

    int ans = 1e9;
    for(int b=0; b<(1<<N); b++){
        vector<int> sum(M);
        int cost = 0;
        for(int i=0; i<N; i++) if(nth_bit(b, i)){
            cost += C[i];
            for(int j=0; j<M; j++) sum[j] += A[i][j];
        }
        if(*min_element(sum.begin(), sum.end()) >= X) ans = min(ans, cost);
    }
    if(ans == 1e9) ans = -1;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3632
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

// Acknowledgement: Special thanks to kyomukyomupurin, who developed this
// template.
template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  int n = 0;
  for (auto e : vec) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& st) {
  int n = 0;
  for (auto e : st) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) {
  int n = 0;
  for (auto e : mp) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
  for (T& e : vec) is >> e;
  return is;
}

#ifdef LOCAL
#define debug(...) \
  std::cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}
using namespace std;
using int64 = long long;

int main() {
  int64 a, b, x;
  cin >> a >> b >> x;
  int64 tmp1;
  if (a == 0) {
    tmp1 = 0;
  } else {
    tmp1 = (a - 1) / x + 1;
  }
  debug(tmp1);
  int64 tmp2 = b / x + 1;
  int64 ans = tmp2 - tmp1;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3608
import           Control.Applicative
import           Control.DeepSeq
import           Control.Monad
import           Control.Monad.ST
import qualified Data.Array                    as A
import qualified Data.Array.IArray             as IA
import qualified Data.Array.IO                 as AI
import qualified Data.Array.MArray             as MA
import qualified Data.Array.ST                 as STA
import qualified Data.Array.Unboxed            as AU
import           Data.Bits
import qualified Data.ByteString.Char8         as BS
import           Data.Char
import qualified Data.Graph                    as G
import           Data.Int
import qualified Data.IntMap                   as IM
import qualified Data.IntSet                   as IS
import           Data.List
import qualified Data.Map.Strict               as M
import           Data.Maybe
import           Data.Ord
import qualified Data.Sequence                 as SQ
import qualified Data.Set                      as S
import           Data.Time
import qualified Data.Tree                     as T
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as VM
import qualified Data.Vector.Unboxed           as VU
import qualified Data.Vector.Unboxed.Mutable   as VUM

readInt :: IO Int
readInt = fst . fromJust . BS.readInt <$> BS.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

readIntLists :: Int -> IO [[Int]]
readIntLists n = replicateM n readInts

readInteger :: IO Integer
readInteger = fst . fromJust . BS.readInteger <$> BS.getLine

readIntegers :: IO [Integer]
readIntegers = map (fst . fromJust . BS.readInteger) . BS.words <$> BS.getLine

readIntegerLists :: Int -> IO [[Integer]]
readIntegerLists n = replicateM n readIntegers

readStrings :: IO [String]
readStrings = map BS.unpack . BS.words <$> BS.getLine

readStringLists :: Int -> IO [[String]]
readStringLists n = replicateM n <$> readStrings

toPair :: [a] -> (a, a)
toPair [x, y] = (x, y)

count :: Eq a => a -> [a] -> Int
count a as = length $ filter (== a) as

put :: Show a => a -> IO ()
put = putStr . show

putList :: Show a => [a] -> IO ()
putList [n     ] = print n
putList (n : ns) = do
  put n
  putStr " "
  putList ns

putStrList :: [String] -> IO ()
putStrList [n     ] = putStrLn n
putStrList (n : ns) = do
  putStr n
  putStr " "
  putStrList ns

yesNoUpper b | b         = putStrLn "YES"
             | otherwise = putStrLn "NO"

yesNo b | b         = putStrLn "Yes"
        | otherwise = putStrLn "No"

divCeiling x n | b == 0    = a
               | otherwise = a + 1
  where (a, b) = x `divMod` n

main = do
  n <- readInt
  yesNo $ n `mod` (sum $ map (\x -> read (x : "")) $ show n) == 0


Measured memory_bytes: 508
#include "bits/stdc++.h"
using namespace std;
#define int long long

signed main() {
	int a,p;
	cin >> a >> p;

	//vector<int> v(n);
	//for (size_t i = 0; i < n; i++)
	//{
	//	cin >> v[i];
	//}

	p += a * 3;
	p /= 2;

	cout << p << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
#include <bits/stdc++.h>

using namespace std;

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

using pqg = priority_queue<ll,vector<ll>, greater<ll> >; // 1,3,5..
using pql = priority_queue<ll,vector<ll> >; //5, 3, 1...

using pqg_p = priority_queue<P,vector<P>, greater<P> >; // 1,3,5..
using pql_p = priority_queue<P,vector<P> >; //5, 3, 1...

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define REPS(i,s,n) for(auto i=s, i##_len=(n); i<i##_len; ++i)

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define ALL(a)  (a).begin(),(a).end()

int H,W;


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

  int c[100][100];
  cin >> H  >> W;

  //0 dame
  //1 koori

  int white = 0;

  REP(i,H) {
    c[i+1][0] = 0;
    c[i+1][W+1] = 0;
    REP(j,W) {
      char _c;
      cin >> _c;
      if (_c == '#') c[i+1][j+1] = -1;
      else {
        c[i+1][j+1] = -2;
        white++;
      }
    }
  }
  REP(i,W+2) {
    c[0][i] = -1;
    c[H+1][i] = -1;
  }


  queue<P> q;
  q.push(MP(1,1));
 
  c[1][1] = 0;
 
  int cy[4] = {0,1,0,-1};
  int cx[4] = {1,0,-1,0};
  for(;;) {
    if (q.empty()) break;
    auto d = q.front();
    q.pop();
    if (d.S == W && d.F == H) break;
 
    REP(i,4) {
      int ny = d.F + cy[i];
      int nx = d.S + cx[i];
      if (c[ny][nx] == -2 ) {
        c[ny][nx] = c[d.F][d.S] + 1;
        q.push(MP(ny,nx));
      }
    }
  }

  //REP(ii,N+2) { REP(jj,M+2) { cout << tmp[ii][jj] << " " ; } cout << endl;}
  

  cout << (c[H][W] == -2?-1: white - c[H][W] -1) << endl;



  return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;
using Graph = vector<vector<ll>>;
const ll INF = 1LL << 60;
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
#define tl 1'000'000'007
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REREP(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, a, n) for (ll i = a; i < n; i++)
#define REFOR(i, n, a) for (ll i = n; i >= a; i--)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ) //被り削除
#define debug cout << "line : " << __LINE__ << " debug" << endl
int gcd(long long a, long long b) { return b != 0 ? gcd(b, a % b) : a; }

ll factorial(ll n){
   ll ans = 1;
   for(int i = n;i>=1;i--){
     ans *= i;
     ans %= tl;
   }
   return ans;
}
int main(){
    init();
    ll n,q;
    cin >> n >> q;
    Graph T(n+1); //隣接行列
    REP(i,n-1){
        ll a,b;
        cin >> a >> b;
        T[a].push_back(b);
        T[b].push_back(a);
    }
    vl cnt(n+1,0);
    REP(i,q){
        ll p,x;
        cin >> p >> x;
        cnt[p]+= x;
    }
    //幅優先？ 
    queue<ll> que;
    que.emplace(1); //1から見る
    vc<bool> used(n+1);
    while(!que.empty()){
        ll v = que.front();
        que.pop();
        used[v] = true; //visited 
        for(auto to:T[v]){
            if (used[to]) continue;
            cnt[to] += cnt[v];
            que.emplace(to);
        }
    }
    FOR(i,1,n+1) cout << cnt[i] << " ";
    cout << endl;
}


Measured memory_bytes: 18408
import collections
n=int(input())
S=[list(input()) for _ in range(n)]
tables=[]
tables2=[]
l=[]
l2=[]
l3=[]
for i in range(n):
    c = collections.Counter(S[i])
    tables2.append(c)
    values = list(c.values())  # aのCollectionのvalue値のリスト(n_1こ、n_2こ…)
    key = list(c.keys())  # 先のvalue値に相当する要素のリスト(要素1,要素2,…)
    for j in range(len(key)):
        l.append([key[j], values[j]])  # lは[要素i,n_i]の情報を詰めたmatrix
    tables.append(l)
    l=[]
l=[]
#print(tables)
for i in range(97,123):
    #print(chr(i))
    for j in range(len(tables2)):
        #print(tables2[j][chr(i)])
        l.append(tables2[j][chr(i)])
    if min(l)>0:
        l2.append([chr(i),min(l)])
    l=[]
l2.sort(key=lambda x:x[0])
for i in range(len(l2)):
    l3.extend([l2[i][0]]*l2[i][1])
print(*l3,sep="")

Measured memory_bytes: 42096
#include <bits/stdc++.h>
#define endl '\n'
#define debug(X) cout << #X << " = " << X << endl

using namespace std;

const int MD = 1e9 + 7;

int bit(long long mask, int b) { return (mask >> b) & 1; }

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	#ifdef UTP
	freopen("input.txt", "r", stdin);
	#endif
	int n; cin >> n;
	vector<long long> a(n);
	for (int i = 0; i < n; i++)
		cin >> a[i];
	long long ans = 0;
	for (int b = 60; b >= 0; b--) {
		long long p2 = (1LL << b) % MD;
		for (int i = n - 1, cnt0 = 0, cnt1 = 0; i >= 0; i--) {
			if (bit(a[i], b)) {
				ans = (ans + p2 * cnt0) % MD;
				cnt1++;
			} else {
				ans = (ans + p2 * cnt1) % MD;
				cnt0++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 2560
/*************************************************************************

       Author:            palayutm
       Created Time :     Sat 18 Feb 2017 08:04:02 PM CST

       File Name:         c.cc
       Description:       new style, new life

 ************************************************************************/
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main(int argc, const char *argv[])
{
  ll n, m;
  cin >> n >> m;
  ll ans = min(m/2, n);
  m -= ans*2;
  ans += m/4;
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
// ConsoleApplication69.cpp : アプリケーションのエントリ ポイントを定義します
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<utility>
#include<queue>
#include<cmath>
using namespace std;
#define REP(i, a,b) for(i=a;i<b;i++) 
#define REP1(i,b,a) for(i=b-1;i>=a;i--)
#define output(x) cout<<x<<endl;
#define pb(x) push_back(x);
typedef long long int ll;
const int MAX = 510000;
const int MOD = 1000000007;


int main()
{
	ll i, j, k, l, m, flag, N, M,K;

	flag = 0;
	cin >> N;
	if (N == 3 || N == 5 || N == 7) {
		output("YES");
	}
	else
	{
		output("NO");
	}
	
	return 0;
}



Measured memory_bytes: 256
import heapq

n,m=map(int,input().split())
jobs=[[] for _ in range(m)]
for i in range(n):
    d,r=map(int,input().split())
    if d-1<m:
        jobs[d-1].append(-r)
rewards=0
heap=[]
for i in range(m):
    for reward in jobs[i]:
        heapq.heappush(heap,reward)
    if len(heap)>0:
        rewards+=-heapq.heappop(heap)

print(rewards)

Measured memory_bytes: 17732
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll,ll> pll;
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
#define MOD 1000000007
#define ARRAY_MAX 200005

const int INF = 1e9+7;


int main(){

    ll n;
    cin >> n;
    vector<ll> a(ARRAY_MAX,0);
    for(int i = 0;i < n;i++){
        cin >> a[i+1];
    }
    for(int i = 0;i < n;i++){//累積和
        a[i+1] += a[i];
    }

    map<ll,ll> mp;
    for(int i = 0;i <= n;i++){
        mp[a[i]]++;
    }
    ll ans = 0;

    for(auto itr:mp){
        ans += (itr.second)*(itr.second-1)/2;
    }
    cout << ans << endl;





    return 0;
}


Measured memory_bytes: 14336
S = input()
if int(S[:2]) > 0 and int(S[:2]) < 13:
    if int(S[2:]) > 0 and int(S[2:]) < 13:
        print('AMBIGUOUS')

    else:
        print('MMYY')

else:
    if int(S[2:]) > 0 and int(S[2:]) < 13:
        print('YYMM')

    else:
        print('NA')


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <vector>

using namespace std;

void c()
{
	int n;
	cin >> n;
	vector<int> h(n);
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}

	int res = true;
	int min = h[n - 1];
	for (int i = n - 2; i >= 0; i--) {
		if (h[i] - min >= 2) {
			res = false;
			break;
		}
		if (h[i] < min) {
			min = h[i];
		}
	}

	cout << (res ? "Yes" : "No") << endl;
}

int main()
{
	c();

	return 0;
}


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

class Program
{
    static void Main(string[] args)
    {
        var input =int.Parse(Console.ReadLine());
        var dict = new Dictionary<int, Dictionary<int, int>>();

        for (var i = 0; i <= 9; i++)
        {
            dict.Add(i, new Dictionary<int, int>());
            for(var j = 0; j <= 9; j++)
            {
                dict[i].Add(j, 0);
            }
        }

        for (var i = 1; i <= input; i++)
        {
            var str = i.ToString().ToCharArray();
            dict[int.Parse(str[0].ToString())][int.Parse(str[str.Length - 1].ToString())] += 1;
        }

        var ans = 0;

        for (var i = 1; i <= 9; i++)
        {
            for (var j = 0; j <= 9; j++)
            {
                ans += dict[i][j] * dict[j][i];
            }
        }


        Console.WriteLine(ans);

        Console.ReadLine();
    }


}



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

const long long mod = 1000000007;

long long mpow(long long x,long long y){
  if(y==0) return 1;
  long long ret = mpow(x,y/2);
  ret %= mod;
  ret *= ret;
  ret %= mod;
  if(y%2==1) ret *= x;
  ret %= mod;
  return ret;
}

int main(){
  long long n,a,b;
  cin >> n >> a >> b;
  vector<long long> V(b+1,1);
  for(int i=1;i<=b;i++){
    V[i] = V[i-1]*i;
    V[i] %= mod;
  }
  
  long long ans = mpow(2,n)-1, nCa = 1, nCb = 1;
  for(int i=0;i<a;i++){
    nCa *= n-i;
    nCa %= mod;
  }
  nCa *= mpow(V[a],mod-2);
  nCa %= mod;
  for(int i=0;i<b;i++){
    nCb *= n-i;
    nCb %= mod;
  }
  nCb *= mpow(V[b],mod-2);
  nCb %= mod;
  ans += mod*2;
  ans -= nCa + nCb;
  ans %= mod;
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#include<bitset>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
ll wa(ll a,ll b){
	if(a<0){
		if(b>0) return a/b-((-a)%(-b)!=0);
		else return (-a)/(-b)+((-a)%(-b)!=0);
	}
	else return a/b;
}
int main(){
	int N;
	ll K;
	vll A,B;
	scan(N>>K);
	rep(i,N){
		int a;
		scan(a);
		A.push_back(a);
	}
	sort(ALL(A));
	brep(i,N) B.push_back(-A[i]);
	ll amin=-INFl,amax=INFl;
	while(amax-amin>=2){
		ll amid=(amax+amin)/2;
		ll kosu=0;
		rep(i,N) if(A[i]*A[i]<=amid) kosu--;
		rep(i,N){
			if(A[i]==0){
				if(amid>=0) kosu+=N;
			}
			else if(A[i]<0){
				kosu+=N-(lower_bound(A.begin(),A.end(),wa(amid,A[i]))-A.begin());
			}
			else{
				kosu+=N-(lower_bound(B.begin(),B.end(),-wa(amid,A[i]))-B.begin());
			}
		}
		kosu/=2;
		//printf("amid:%lld kosu:%lld\n",amid,kosu);
		if(kosu<K) amin=amid;
		else amax=amid;
	}
	prin(amax);
	return 0;
}


Measured memory_bytes: 4976
#include <stdio.h>

int main(void)
{
  unsigned long n, b, r, div, mod;
  div = 0;
  mod = 0;
  scanf("%lu %lu %lu", &n, &b, &r);
  if (n < 1 || (b == 0 && r == 0) || b < 0 || r < 0)
  {
    return 0;
  }
  div = n / (b + r);
  mod = n % (b + r);
  if (mod == 0)
  {
    printf("%lu", b * div);
  }
  else if (mod < b)
  {
    printf("%lu", b * div + mod);
  }
  else if (mod >= b)
  {
    printf("%lu", b * div + b);
  }
  return 0;
}


Measured memory_bytes: 128