akhauriyash/Code-Regression huggingface dataset:
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;

enum dx = [0, 0, 1, -1];
enum dy = [1, -1, 0, 0];
enum inf = int.max;

void main() {
  auto zz = readln.split.map!(a => a.to!int).array;
  immutable h = zz[0], w = zz[1];
  auto d = new int[][h];
  foreach (i; 0 .. h) {
    d[i] = readln.take (w).map! ( (a) => (a == '#') ? 0 : inf).array;
  }
  int[] q;
  foreach (i; 0 .. h) foreach (j; 0 .. w) {
    if (d[i][j] == 0) q ~= i * w + j;
  }
  int l = 0;
  while (l < q.length) {
    int z = q[l++];
    int i = z / w, j = z % w;
    int nd = d[i][j] + 1;
    foreach (k; 0 .. 4) {
      int x = i + dx[k];
      if (x < 0 || x >= h) continue;
      int y = j + dy[k];
      if (y < 0 || y >= w) continue;
      if (d[x][y] > nd) {
        d[x][y] = nd;
        q ~= x * w + y;
      }
    }
  }
  int res = int.min;
  foreach (i; 0 .. h) {
    res = max (res, d[i].reduce!"max(a,b)");
  }
  writeln (res);
}



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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

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

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

vector<int64> G[112345];
vector<int64> cnt;

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

	int64 N, M;
	cin >> N >> M;
	cnt.resize(N, 0);
    REP(i, M) {
        int64 a, b;
        cin >> a >> b; a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    vector<int64> d(N, INF);
    if (M % 2 == 1) {
        cout << -1 << endl;
        return 0;
    }
    d[0] = 0;
	priority_queue<PLL, vector<PLL>, greater<>> pq;
	pq.emplace(0, 0);
	while (pq.size()) {
	    int64 vv, dd;
	    tie(dd, vv) = pq.top(); pq.pop();
	    if (d[vv] < dd) continue;
	    for (auto &u : G[vv]) {
	        if (d[u] > dd + 1) {
	            d[u] = dd + 1;
	            pq.emplace(d[u], u);
	        }
	    }
	}

	vector<int64> ord(N); iota(all(ord), 0);
	vector<int64> rord(N);
	sort(all(ord), [&](int64 a, int64 b) {
	    return d[b] < d[a];
	});
	REP(i, N) rord[ord[i]] = i;

	REP(i, N) {
//	    cout << i << endl;
	    int v = ord[i];
	    vector<PLL> es;
	    for (auto &u : G[v]) {
	        if (rord[u] > i) {
                es.emplace_back(rord[u], u);
//                cout << v << " " << u << " " << rord[u] << endl;
            }
	    }
	    sort(all(es));
	    int64 esn = es.size()+cnt[v];
//	    cout << v << " " << esn << ": ";
//	    REP(j, es.size()) {
//	        cout << "(" << es[j].fs << " " << es[j].sc << ") ";
//	    }
//	    cout << endl;
	    REP(j, es.size()-(esn)%2) {
            cout << v+1 << " " << es[j].sc+1 << endl;
            cnt[v]++;
        }
        if (esn%2) {
            cout << es.back().sc+1 << " " << v+1 << endl;
            cnt[es.back().sc]++;
        }
	}
}


Measured memory_bytes: 10880
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
typedef vector<int> vi;
typedef long long ll;


int main(){
    char s[11],ans[11];
    int in=0;
    rep(i,0,10){
        cin>>s[i];
        
        if(s[i]=='0'){
            ans[in]='0';
            in++;
        }
        else if(s[i]=='1'){
            ans[in]='1';
            in++;
        }
        else if(s[i]=='B'&&in!=0){
            in--;
        }
        
    }
    rep(i,0,in)cout<<ans[i];
    cout<<endl;
}






Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int a,d,b,c,e,i;
	b=0;
	e=20;
	scanf("%d",&a);
	for(i=0;i<a;i++){
		scanf("%d %d",&c,&d);
		if(b<d){
			b=d;
			e=c;
		}
		if(b==d&&e>=c){
			e=c;
		}
	}
	printf("%d %d\n",e,b);
	return 0;
}

Measured memory_bytes: 600
use std::io;
use std::collections::HashMap;

fn procon_read<T: std::str::FromStr>() ->  Vec<T> {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).expect("");
    let iter = buf.split_whitespace();
    let mut v: Vec<T> = Vec::new();
    for i in iter {
        v.push(i.parse().ok().unwrap());
    }
    v
}

fn score(c: &mut Vec<i64>, s: &mut Vec<Vec<i64>>, last: &mut HashMap<i64, i64>, t: &mut Vec<i64>, d:&u32){
    let mut score:i64 = 0;
    for i in 0..*d {
        let mut minusSatisfy:i64 = 0;
        last.insert(t[i as usize], (i + 1) as i64);
        for j in 1..(26+1) {
            minusSatisfy += c[(j-1) as usize]*((i+1) as i64 - *(last.get(&(j as i64)).unwrap()) );
            //println!("{}回目: minusSatisfy = {}", j, minusSatisfy);
        }
        score += s[i as usize][(t[i as usize] - 1) as usize] - minusSatisfy;
        println!("{}", score);
    }
}

fn main() {
    let mut d:u32 = procon_read()[0];
    /* c_i */
    let mut c:Vec<i64> = procon_read();
    
    /*s_{d, i}*/
    let mut s:Vec<Vec<i64>> = Vec::new();
    for i in 0..d {
        s.push(procon_read());
    }
    
    /* test schaduled*/
    let mut t:Vec<i64> = Vec::new();
    for i in 0..d {
        t.push(procon_read()[0]);
    }
    
    /*last(d, i)*/
    let mut last:HashMap<i64, i64> = HashMap::new();
    for i in 1..(26+1) {
        last.insert(i as i64, 0);
    }
    
    score(&mut c, &mut s, &mut last, &mut t, &mut d);
    
}

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

const int dx[] = {0, -1, 1, 0};
const int dy[] = {-1, 0, 0, 1};

LL fac[SIZE], finv[SIZE], inv[SIZE];
void combInit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for( int i = 2; i < SIZE; ++i ) {
        fac[i] = (fac[i - 1] * i) % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = (finv[i - 1] * inv[i]) % MOD;

    }
}

LL comb(int n, int k) {
    if( n < k ) return 0;
    if( n < 0 || k < 0 ) return 0;
    return (fac[n] * (finv[k] * finv[n - k] % MOD)) % MOD;

}

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

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

    int n, t;
    cin >> n >> t;
    vector< int > v(n);
    for( int i = 0; i < n; ++i ) {
        cin >> v[i];

    }

    if( n == 1 ) {
        cout << 0 << endl;
        return 0;

    }

    int mn = v[0];
    int dif = 0;
    int l, r;
    for( int i = 1; i < n; ++i ) {
        if( v[i] <= mn ) {
            mn = v[i];
            continue;

        }
        if( dif < v[i] - mn ) {
            dif = v[i] - mn;

        }

    }

    mn = v[0];
    int res = 0;
    for( int i = 1; i < n; ++i ) {
        if( v[i] < mn ) {
            mn = v[i];
            continue;

        }
        if( v[i] - mn == dif ) ++res;

    }

    int mx = v[n - 1];
    int tmp = 0;
    for( int i = n - 2; i >= 0; --i ) {
        if( v[i] > mx ) {
            mx = v[i];
            continue;

        }
        if( mx - v[i] == dif ) ++tmp;
    }
    cout << min(res, tmp) << endl;
    return 0;
}



Measured memory_bytes: 640
n, m = map(int, (input().split()))
a = {int(input()) for i in range(m)}

dp = [1] + [0] * (n + 1)

for i in range(n):
    if i in a:
        continue
    dp[i + 1] += dp[i]
    dp[i + 2] += dp[i]

print(dp[n] % 1000000007)


Measured memory_bytes: 462692
#include <iostream>
#include <algorithm>
#define MAX_M 20
#define MAX_N 50000
#define INF 1000000000
using namespace std;

int c[MAX_M + 1];
int dp[MAX_N + 1];

void solve(int n, int m) {
  dp[0] = 0;
  for (int i = 1; i <= m; i++) {
    for (int j = c[i]; j <= n; j++) {
      dp[j] = min(dp[j], dp[j - c[i]] + 1);
    }
  }
  cout << dp[n] << endl;
}

void init() {
  for (int i = 0; i < MAX_N + 1; i++) {
    dp[i] = INF;
  }
}

int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> c[i];
  }

  init();

  solve(n, m);
  
  return 0;
}

Measured memory_bytes: 3284
N = [int(n) for n in input()]

dp = [[0] * 2 for _ in range(len(N) + 1)]
dp[0][1] = 1

for i, n in enumerate(N):
    dp[i + 1][0] = min(dp[i][0] + n, dp[i][1] + (10 - n))
    dp[i + 1][1] = min(dp[i][0] + (n + 1), dp[i][1] + (10 - (n + 1)))
    
print(dp[-1][0])


Measured memory_bytes: 150452
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define INFF 9223372036854775807
#define ll long long
#define REP(i,n) for(long long i=0;i<n;i++)
#define REPP(i,m,n) for(long long i=m;i<n;i++)
#define ALL(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
#define pq priority_queue
#define Dcout(N) cout << setprecision(20) << N << 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; }

int main() {
    cin.tie(0);    
	ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll a[N];
    ll sum = 0,cnt = 0;
    ll minv = INFF;
    REP(i,N) cin >> a[i];
    REP(j,2){
        cnt = 0;
      	sum = 0;
    REP(i,N){
        if(j == 0 && i == 0){
            if(a[i] <= 0){
                sum = 1;
                cnt += abs(a[i])+1;
            }
          	else sum += a[i];
            continue;
        }
        else if(j == 1 && i == 0){
            if(a[i] >= 0){
                sum = -1;
                cnt += a[i]+1;
            }
          	else sum += a[i];
            continue;
        }

        if(sum > 0 && sum + a[i] > 0){
          	if(a[i] < 0) cnt += sum + a[i] + 1;
            else cnt += abs(sum + a[i]) + 1;
            sum = -1;
        }
        else if(sum < 0 && sum + a[i] < 0){
          	if(a[i] > 0) cnt += abs(sum) - a[i] + 1;
            else cnt += abs(sum + a[i]) + 1;
            sum = 1;
        }
        else if(sum + a[i] == 0){
            if(sum <= 0){
                sum = 1;
                cnt++;
            }
            else{
                sum = -1;
                cnt++;
            }
        }
        else sum += a[i];
      //if(j == 1) cout << cnt << endl;
      //cout << cnt << endl;
    }
    minv = min(minv,cnt);
    }
    cout << minv << endl;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

	Scanner sca = new Scanner(System.in);
	// 入力
	String s = sca.next();
	String t = sca.next();

	// 処理
	String ans = t + s;


	// 出力
	System.out.println(ans);

	// 後始末
	sca.close();
	}
}

Measured memory_bytes: 23252
#include<bits/stdc++.h>
//#define int long long
#define ll long long
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define mat vector<vi>
using namespace std;
const int mod = 1e9+7,N=2e5+5;
mat a;
ll k;

mat mul(mat A,mat B) {
    int n = A.size();
    mat C = mat(n,vi(n));
    for (int i = 0;i < n; i++)
        for (int j = 0; j < n; j++)
        for (int k = 0;k < n; k++)
        (C[i][j] += (ll)A[i][k]*B[k][j]%mod)%=mod;
    return C;
}
mat pw(mat A,ll k) {
    if (k == 1LL) return A;
    mat B = pw(A,k/2);
    if (k%2 == 0) return mul(B,B);
    return mul(mul(B,B),A);
}
main() {
    ios::sync_with_stdio(0);
    int n;
    cin >> n >> k;
    a = vector<vi> (n,vi(n));
    for (int i = 0; i < n; i++)
        for (int j = 0;j < n; j++)
        cin >> a[i][j];
    a = pw(a,k);
    int ans = 0;
    for (int i  = 0; i < n; i++)
        for (int j  =0 ;j < n; j++)
        (ans+= a[i][j])%=mod;
    cout << ans;

}


Measured memory_bytes: 4100
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let s = read::<String>().chars().collect::<Vec<_>>();
    let big_int = 1000_000_000 + 7;
    let mut dp = vec![vec![0i64; 2]; s.len() + 1];
    dp[0][0] = 1;
    for i in 0..s.len() {
        // if a + b = 0
        {
            if s[i] == '0' {
                dp[i + 1][0] = dp[i][0];
                dp[i + 1][1] = dp[i][1];
            } else {
                dp[i + 1][1] = dp[i][0] + dp[i][1];
                dp[i + 1][1] %= big_int;
            }
        }
        // if a + b = 1
        {
            if s[i] == '0' {
                dp[i + 1][1] += (dp[i][1] * 2) % big_int;
                dp[i + 1][1] %= big_int;
            } else {
                dp[i + 1][0] += dp[i][0] * 2;
                dp[i + 1][0] %= big_int;
                dp[i + 1][1] += dp[i][1] * 2;
                dp[i + 1][1] %= big_int;
            }
        }
    }
    println!("{:?}", (dp[s.len()][0] + dp[s.len()][1]) % big_int);
}

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

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 1005

int a , b , c , n , k;
string s;

int main()
{
    _FastIO;

    cin >> s;
    for(int i = 0; i < 3; i++){
        if(s[i] == 'R')
            a++;
    }
    if(s[1] == 'S'){
        cout << min(1 , a) << endl;
    }else{
        cout << a << endl;
    }
    return 0;
}


Measured memory_bytes: 3636
n = int(input())
height = list(map(int, input().split()))
max_count = 0
count = 0
for i in range(n - 1):
    if height[i] < height[i + 1]:
        max_count = max(count, max_count)
        count = 0
        continue
    count += 1
max_count = max(count, max_count)
print(max_count)


Measured memory_bytes: 14224
n = int(input())
bs = list(map(int, input().split()))
out = []
i = 0
while len(bs) > 0:
    change_i = 0
    ok = True
    for i, b in enumerate(bs):
        if b > i + 1:
            ok = False
            break
        elif b == i + 1:
            change_i = i
    if not ok:
        break
    out.append(bs[change_i])
    del bs[change_i]

if ok:
    for o in reversed(out):
        print(o)
else:
    print(-1)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define itn int

int main(void){
    int n,m,q;
    cin >> n >> m >> q;
    int A[q],B[q],C[q],D[q];
    
    for(int i = 0;i < q;i++)cin >> A[i] >> B[i] >> C[i] >> D[i];
    
    long long ans = 0;
    int num[11] = {};
    for(int a = 1;a <= m;a++){
        num[1] = a; 
        for(int b = a;b <= m;b++){
            num[2] = b;
            for(int c = b;c <= m;c++){
                num[3] = c;
                for(int d = c;d <= m;d++){
                    num[4] = d;
                    for(int e = d;e <= m;e++){
                        num[5] = e;
                        for(int f = e;f <= m;f++){
                            num[6] = f; 
                            for(int g = f;g <= m;g++){
                                num[7] = g;
                                for(int h = g;h <= m;h++){
                                    num[8] = h;
                                    for(int i = h;i <= m;i++){
                                        num[9] = i;
                                        for(int j = i;j <= m;j++){
                                            num[10] = j;
                                            
                                            long long sum = 0;
                                            for(int k = 0;k < q;k++){
                                                if(num[B[k]]-num[A[k]] == C[k])sum += D[k];
                                            }
                                            ans = max(sum,ans);
                                            
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    
    cout << ans << endl;
    
}

Measured memory_bytes: 3660
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main() {
    int h,w; cin>>h>>w;
    string ans="Yes";
    vector<vector<int>> m(h+2,vector<int>(w+2,1));
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            char ch; cin>>ch;
            m[i][j]=(ch=='#' ? 0 : 1);
        }
    }
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            if(m[i][j]==0 && m[i-1][j]*m[i+1][j]*m[i][j-1]*m[i][j+1]==1)
            ans="No";
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func main() {
	x := 0
	y := 0
	fmt.Scan(&x, &y)
	fmt.Println(gcd(x, y))
}



Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k,a,ak,h;
    cin>>n>>k>>a;
    h=a;
    for(int i=2;i<=n;i++){
        cin>>ak;
        a=__gcd(a,ak);
        h=max(ak,h);
    }
    if(k%a==0&&k<=h){
        cout<<"POSSIBLE"<<endl;
    }
    else{
        cout<<"IMPOSSIBLE"<<endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  int x,y;
  cin>>x>>y;
  int a[]={0,1,3,1,2,1,2,1,1,2,1,2,1};
  if(a[x]==a[y])
    {
      cout<<"Yes"<<endl;
    }else{
    cout<<"No"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int inf=(1<<30);
int main(){
	int n,m,p;
	cin>>n>>m>>p;
	int d[m]={};
	for(int i=0; i<m; i++){
		int a;
		cin>>a;
		if(a-p>0){
			d[i]=a-p;
		}else{
			d[i]=n-(p-a);
		}
	}
	sort(d,d+m);
	//for(int i=0; i<m; i++){
	//	cout<<d[i]<<" ";
	//}cout<<endl;
	//
	
	int ans=inf;
	
	//cout<<n-d[0]<<" "<<d[m-1]<<endl;
	ans=min(n-d[0],d[m-1]);
	for(int i=0; i<m-1; i++){
		
		ans=min(ans,d[i]+n-(d[i+1]-d[i]));
		//cout<<d[i]+n-(d[i+1]-d[i])<<endl;
		
		
	}
	
	//cout<<endl;
	for(int i=1; i<m; i++){
		
		ans=min(ans,n-d[i]+n-(d[i]-d[i-1]));
		//cout<<n-d[i]+n-(d[i]-d[i-1])<<endl;
		
	}
	cout<<ans*100<<endl;
}
	
	


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

int main()
{
    int n;
    cin >> n;
    
    vector<int> vec(n+1, 0);
    
    for (int i = 1; i <= 100; ++i) {
        for (int j = 1; j <= 100; ++j) {
            for (int k = 1; k <= 100; ++k) {
                int tmp = pow(i, 2) + pow(j, 2) + pow(k, 2) + i*j + j*k + k*i;
                if (tmp<= 10000) ++vec[tmp];
            }
        }
    }
    
    for (int i = 0; i < n; ++i) cout << vec[i+1] << "\n";
    
    return 0;
    
}


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

using P = pair<int, int>;
int n, m, cnt, ans;
P p[100010];
prique2(int)que;
signed main() {
	cin >> n >> m;
	rep(i, n) {
		scanf("%lld %lld", &p[i].first, &p[i].second);
	}
	sort(p, p + n);
	for (int i = 1; i <= m; ++i) {
		for(; cnt < n&& p[cnt].first <= i; cnt++) {
			que.push(p[cnt].second);
		}
		if (que.empty()) continue;
		ans += que.top();
		que.pop();
	}
	printf("%lld\n", ans);
}


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

struct mint {
  ll x;
  mint(ll x=0):x(x%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(ll 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;
  }
};
 

mint f(int n){
  if (n==0) return 1 ;
  mint x = f(n/2);
  x *= x;
  if(n%2==1){
    x *=2;
  }
  return x;
  
}

mint choose(int n,int a){
  mint x=1,y=1;

  for(int i=0;i<a;i++){
    x *= (n-i);
    y *= i+1;
  }
  return x / y;
}

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

    mint ans;
    ans  = f(n);
    ans -= 1;
    ans -= choose(n,a);
    ans -= choose(n,b);

    cout << ans.x;
    return 0;
}

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

#include <math.h>
#include <stdlib.h>


#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true; } return false; }
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true; } return false; }

//INT_MAX	2,147,483,647 = 2*1.0e9

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int N, A, B;
    cin >> N >> A >> B;
    cout << min(N*A, B) << endl;

    return 0;
}


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

using namespace std;
#define LL long long 

LL H[10001]={0};

int main()
{
	char A[1000];
	cin>>A;
	int L=strlen(A);
	for(int i=0;i<L;i++)
	{
		H[A[i]]++;
	}
	
	for(int i=1;i<=1000;i++)
	{
		if(H[i]&1)
		{
			cout<<"No\n";
			return 0;
		}
		
	}
	cout<<"Yes\n";
	return 0;
} 

Measured memory_bytes: 256
package main

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

func reverseStr(s string) string {

	runes := []rune(s)

	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}

	return string(runes)
}

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

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	// Code for D - String Formation
	var S string
	fmt.Scan(&S)

	var Q int
	fmt.Scan(&Q)

	var ans [1000000]string
	ans[500000] = S

	sc.Split(bufio.ScanWords)

	var T int
	var F int
	var C string
	var flag int
	var l, m int
	l++
	m++
	for i := 0; i < Q; i++ {
		T = nextInt()
		if T == 1 {
			if flag == 0 {
				flag++
			} else {
				flag--
			}
		} else {
			F, C = nextInt(), nextStr()
			if (F == 1 && flag == 0) || (F == 2 && flag == 1) {
				ans[500000-l] = C
				l++
			} else {
				ans[500000+m] = C
				m++
			}
		}
	}

	temp := make([]string, 0)
	for _, v := range ans {
		if v != "" {
			temp = append(temp, v)
		}
	}

	S = strings.Join(temp, "")

	if flag == 1 {
		S = reverseStr(S)
	}

	fmt.Println(S)
}


Measured memory_bytes: 40296
n = int(input())
txy = [[0, 0, 0]] + [list(map(int, input().split())) for _ in range(n)]

flag = True
for i in range(1, n + 1):
    t = txy[i][0] - txy[i - 1][0]
    x = abs(txy[i][1] - txy[i - 1][1])
    y = abs(txy[i][2] - txy[i - 1][2])

    if not t >= x + y or not t % 2 == (x + y) % 2:
        flag = False
        break

print('Yes') if flag else print('No')


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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

ll d[200004], n, k;
ll par[200004], init, cycle, start;

void fastio() {
    ios::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
}

void dfs(int num, int cnt) {
    if (par[num]) {
        start = num;
        init = par[num];
        cycle = cnt - par[num];
        return;
    }
    par[num] = cnt;
    dfs(d[num], cnt + 1);
}

int main() {
    fastio();
    cin >> n >> k;
    for (ll i=1; i<=n; i++) cin >> d[i];
    par[1] = 1, dfs(d[1], 2);
    // cout << init << " " << cycle;
    vector<int> iinit, ccycle;
    int res;
    if (k < init) {
        res = 1;
        while (k--) res = d[res];
    }
    else {
        k -= init;
        k = k % cycle;
        k += 1;
        res = start;
        while (k--) res = d[res];
    }
    cout << res;
    return 0;
}

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

int main()
{
  int N, K;
  cin >> N >> K;
  int num = 1;
  for(int i = 0; i < N; i++){
    if(num * 2 <= num + K){
      num = num * 2;
    }
    else num = num + K;
  }
  cout << num << endl;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long int;
 
const ll mod = 1e9 + 7;
 
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
 
  string s;
  cin >> s;
  int s_len = s.size();
 
  vector<ll> prev(13, 0);
  vector<ll> next(13, 0);
  prev[0] = 1;
 
  for (int i = 0; i < s_len; i++) {
    for (int r = 0; r < 13; r++) {
      if (s[i] == '?') {
        for (int c = 0; c <= 9; c++) {
          next[(r * 10 + c) % 13] += prev[r];
          next[(r * 10 + c) % 13] %= mod;
        }
      } else {
        int c = s[i] - '0';
        next[(r * 10 + c) % 13] += prev[r];
        next[(r * 10 + c) % 13] %= mod;
      }
    }
    copy(next.begin(), next.end(), prev.begin());
    fill(next.begin(), next.end(), 0);
  }
 
  cout << prev[5] << endl;
 
  return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<functional>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<deque>
#include<sstream>
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<bitset>
#include<time.h>
#include<cstdlib>
using namespace std;
#define ll long long
#define inf (999999999)
#define fi first
#define se second
#define MOD 1e9+7
#define PI acos(-1.0)
//--------------------------------------------------------------------------------------------------//
int n;
int df[100001];
int ds[100001];
bool pastf[100001];
bool pasts[100001];
vector<int> v[100001];
inline void bfs(int s,int dare) {
	fill(pastf, pastf + n, 0);
	fill(pasts, pasts + n, 0);
	pastf[0] = 1;pasts[n - 1] = 1;
	queue<pair<int,int>> q;
	q.push(make_pair(s, 0));
	while (!q.empty()) {
		int now = q.front().first;
		int cost = q.front().second;
		q.pop();
		if (dare == 1) df[now] = cost;
		else ds[now] = cost;
		int nowsize = (int)v[now].size();
		for (int i = 0; i <nowsize; i++) {
			int next = v[now][i];
			if (dare == 1 && !pastf[next]) {
				pastf[next] = 1;
				q.push(make_pair(next, cost + 1));
			}
			else if (dare != 1 && !pasts[next]) {
				pasts[next] = 1;
				q.push(make_pair(next, cost + 1));
			}
		}
	}
}
int main() {
	cin >> n;
	for (int i = 0; i < n-1; i++) {
		int to, from; cin >> to >> from;
		to--; from--;
		v[to].push_back(from);
		v[from].push_back(to);
	}
	bfs(0, 1);
	bfs(n - 1, -1);
	int contf = 0;
	int conts = 0;
	for (int i = 0; i < n; i++) {
		if (df[i] > ds[i]) conts++;
		else contf++;
	}
	if (contf > conts) cout << "Fennec" << endl;
	else cout << "Snuke" << endl;
}

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

#define NMAX 1000001
int nm[NMAX],nm2[NMAX];

int main()
{
	int N;
	for(int i=0; i<NMAX; i++)
	{
		nm[i] = nm2[i] = (1<<25);
	}
	nm[0]=nm2[0]=0;
	
	for(int n=1; true; n++)
	{
		int V=n*(n+1)*(n+2)/6;
		if(V>=NMAX) break;		
	
		for(int i=V; i<NMAX; i++)
		{
			nm[i]=min(nm[i],nm[i-V]+1);
		}	
	}
	
	for(int n=1; true; n++)
	{
		int V=n*(n+1)*(n+2)/6;
		if(V>=NMAX) break;
		
		if(V%2==0) continue;		
	
		for(int i=V; i<NMAX; i++)
		{
			nm2[i]=min(nm2[i],nm2[i-V]+1);
		}	
	}	
	
	while(cin >> N, N)
	{		
		cout << nm[N] << " " << nm2[N] << endl;
	}
}

Measured memory_bytes: 8612
#include<bits/stdc++.h>
using namespace std;
#define MAX_VAL 200
#define INF 12345678

int V, d[MAX_VAL][MAX_VAL], z[MAX_VAL][MAX_VAL];

void warshall_floyd(int x[MAX_VAL][MAX_VAL]){
	for(int k = 1; k <= V; k++)
		for(int i = 1; i <= V; i++)
			for(int j = 1; j <= V; j++)
				x[i][j] = min(x[i][j],x[i][k]+x[k][j]);
}

int main(){
	int n, k;
	while(true){
		cin>>n>>V;
		
		if(!n&&!V) break;
		
		for(int i = 0; i <= V; i++)
			for(int j = 0; j <= V; j++)d[i][j]=z[i][j] = i == j ? 0 : INF;
		
		for(int i = 1,a,b,cost,time; i <= n; i++){
			cin>>a>>b>>cost>>time;
			d[a][b] = d[b][a] = cost;
			z[a][b] = z[b][a] = time;
		}
		
		warshall_floyd(d);
		warshall_floyd(z);
		
		cin>>k;
		
		for(int i = 1,p,q,r; i <= k; i++){
			cin>>p>>q>>r;
			if(r)cout<<z[p][q]<<endl;
			else cout<<d[p][q]<<endl;
		}
	}
	
	return 0;
}


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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#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 repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

const string YES = "Yes";
const string NO = "No";

int main(){
    int x, y;
    cin >> x >> y;
    if (y >= x*2 && y <= x*4 && y%2==0) cout << YES << endl;
    else cout << NO << endl;
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define rrep(i,m,n) for(int i = m; i >= n; i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define printa2(x,m,n) for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ cout << x[i][j] << " ";} cout << endl;}
#define printp(x,n) for(int i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
typedef struct{
    ll to;
    ll cost;
} edge;
typedef pair<ll, ll> lpair;
ll dp[110][100010] = {};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,K;
    cin >> N >> K;
    ll a[110];
    rep(i,0,N){
        cin >> a[i];
    }
    dp[0][0] = 1;
    rep(i,0,N){
        ll sum[100010] = {};
        rep(j,0,100010){
            sum[j+1] = (sum[j]+dp[i][j]) % MOD;
            sum[j+1] %= MOD;
        }
        rep(j,0,K+1){
            ll min_val = max(0LL,j-a[i]);
            dp[i+1][j] += (sum[j+1] - sum[min_val] + MOD) % MOD;
            dp[i+1][j] %= MOD;
            // rep(k,0,a[i]+1){
            //     if(j-k>= 0){
            //         dp[i+1][j] += dp[i][j-k];

            //     }
                
            // }
        }
    }
    print(dp[N][K]);


}


Measured memory_bytes: 80128
from itertools import accumulate
from math import floor, sqrt
N, K = map(int,input().split())
A = list(map(int,input().split()))
sm = sum(A)
divs = set()
for i in range(1, floor(sqrt(sm))+1):
    if sm % i == 0:
        divs.add(i)
        divs.add(sm // i)
ans = 1
for d in divs:
    ls = sorted(map(lambda x: x%d, A))
    acc = [0]+list(accumulate(ls, lambda x,y:x+y))
    for i in range(1, N):
        minus = acc[i]-acc[0]
        plus = d*(N-i) - (acc[-1]-acc[i])
        if plus == minus and plus <= K:
            ans = max(ans, d)
print(ans)

Measured memory_bytes: 9304
N = int(input())
numbers = [int(input()) for i in range(N)]
ans = []

def check_prime(n):
    for i in range(2, int(n**0.5)+1):
        if n % i == 0:
            return 0
    else:
        return 1
    
for n in numbers:
    ans.append(check_prime(n))

print(sum(ans))

Measured memory_bytes: 8472
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

struct UnionFind {
  vector< int > data;
 
  UnionFind(int sz) {
    data.assign(sz, -1);
  }
  int root(int x) {
        if (data[x] < 0) return x;
        else return data[x] = root(data[x]);
  }
  bool same(int x, int y) {
    return root(x) == root(y);
  }
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
 
  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }
 
  int size(int k) {
    return (-data[find(k)]);
  }
};

int main() {
  int n,m;
  cin >> n >> m;
  UnionFind tree(n+m);
  rep(i,n){
    int k;
    cin >> k;
    rep(j,k){
      int l;
      cin >> l;
      l--;
      tree.unite(i,n+l);
    }
  }
  bool ok = true;
  rep(i,n){
    ok&=tree.same(0,i);
  }
  if(ok)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <complex>
#include <cstdio>
#include <utility>
#include <vector>
#include <iostream>
#define X real()
#define Y imag()
#define EPS 1e-10
using namespace std;
typedef complex<double> P;
typedef pair<P,P> L;
typedef pair<P,double> C;

double dot(P a, P b){
  return a.X*b.X + a.Y*b.Y;
}

double cross(P a, P b){
  return a.X*b.Y - a.Y*b.X;
}

P projection(P a, P b){
  return dot(a,b)/abs(b)/abs(b)*b;
}

double p_to_l_dist(P p, L l){
  return abs(cross(l.second-l.first,p-l.first))/abs(l.first-l.second);
}

vector<P> sort_comp(vector<P> a){
  int l = a.size();
  vector< pair<double, double> > t(l);
  for(int i = 0; i < l; ++i){
    t[i].first = a[i].X;
    t[i].second = a[i].Y;
  }
  sort(t.begin(),t.end());
  for(int i = 0; i < l; ++i){
    a[i] = P(t[i].first,t[i].second);
  }
  return a;
}

vector<P> cpcl(C c, L l){
  double d = p_to_l_dist(c.first,l), r = c.second;
  P m = l.first + projection(c.first-l.first,l.second-l.first);
  P x = sqrt(r*r-d*d)/abs(l.second-l.first)*(l.second-l.first);
  vector<P> cp(2,m);
  cp[0] -= x;
  cp[1] += x;
  return cp;
}

int main(){
  double x1, y1, x2, y2, r;
  cin >> x1 >> y1 >> r;
  C c = C(P(x1,y1),r);
  int q;
  cin >> q;
  for(int i = 0; i < q; ++i){
    cin >> x1 >> y1 >> x2 >> y2;
    L l;
    l.first = P(x1,y1);
    l.second = P(x2,y2);
    vector<P> cp = sort_comp(cpcl(c,l));
    printf("%.10lf %.10lf %.10lf %.10lf\n", cp[0].X, cp[0].Y, cp[1].X, cp[1].Y);
  }
  return 0;
}

Measured memory_bytes: 3256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i=0; i<int(n); i++)
#define RNG(i, f, t) for(int i=int(f); i<=int(t); i++)
bool RELAXED = false;
template<int,typename T> struct MINMAX{ T val; MINMAX(T val) : val(val) {} };
template<typename T> MINMAX<1,T> MAX(T val) { return MINMAX<1,T>(val); };
template<typename T> MINMAX<2,T> MIN(T val) { return MINMAX<2,T>(val); };
template<typename T, typename U> inline T& operator|=(T &lhs, MINMAX<1,U> rhs) { return lhs = (rhs.val > lhs ? (RELAXED=true,rhs.val) : (RELAXED=false,lhs)); }
template<typename T, typename U> inline T& operator|=(T &lhs, MINMAX<2,U> rhs) { return lhs = (rhs.val < lhs ? (RELAXED=true,rhs.val) : (RELAXED=false,lhs)); }
template<typename T> inline vector<T> readVector(int n) { vector<T> vec(n); FOR(i,n) cin>>vec[i]; return vec; }
template<typename T> void EXIT(T answer) { cout<<answer<<endl; exit(0); }
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef signed long long int ll;

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

    int L; cin>>L;
    double a = L/3.0;
    double ans = a*a*a;
    cout<<setprecision(12)<<ans<<endl;


}



Measured memory_bytes: 256
fun main(arg: Array<String>) {
    val input = listOfInt()
    val (A, B, C, D) = input
    val (E, F) = input.subList(4, 6)
    var z = 0.0
    var x = A * 100
    var y = 0
    for (a in 0 .. F step 100 * A) {
        for (b in 0 .. F step 100 * B) {
            val w = a + b
            if (w == 0) continue
            for (c in 0 .. F step C) {
                for (d in 0 .. F step D) {
                    val s = c + d
                    val t = w + s
                    if (F < t || E < s * 100.0 / w) break
                    val conc = s * 100.0 / t
                    if (z < conc) {
                        z = conc; x = t; y = s
                    }
                }
            }
        }
    }
    println("$x $y")
}

fun next() = readLine()!!
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta
fun listOfString() = next().split(" ")
fun listOfInt(D: Int = 0) = listOfString().map { Integer.parseInt(it) + D }
fun listOfLong() = listOfString().map(String::toLong)
fun listOfDouble() = listOfString().map { it.toDouble() }


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  REP(i, N) cin >> A[i];
  vector<int> M(200100, 0);
  for(int i = 0; i < N; i++) {
    M[A[i]]++;
  }
  sort(M.rbegin(), M.rend());
  int ans = 0;
  for(int i = K; i < 200100; i++) {
    if(M[i] == 0) break;
    ans += M[i];
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
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;}

vector<vector<int>> E;
vector<int> c;
vector<int> ans;
vector<bool> visited;

void dfs(int i, int value){
	visited[i] = true;
	ans[i] = value+c[i];
	
	for(int child: E[i]){
		if(visited[child]) continue;
		dfs(child, ans[i]);
	}
}

int main(){
	int n,q;
	cin >> n >> q;
	E.resize(n);
	int a,b;
	REP(i,n-1){
		cin >> a >> b;
		E[a-1].push_back(b-1);
		E[b-1].push_back(a-1);
	}
	vector<int> p(n,0);
	REP(i,q){
		cin >> a >> b;
		p[a-1] += b;
	}
	c = p;

	ans.resize(n);
	visited.resize(n);
	fill(visited.begin(),visited.end(),false);
	dfs(0,0);
	
	REP(i,n){
		if(i!=0) cout << " ";
		cout << ans[i];
	}
	cout << endl;
	
	return 0;
}

Measured memory_bytes: 25964
import math
#import numpy


def readints():
    return list(map(int, input().split()))


n = int(input())
p = readints()
#print(p)
sum = 0
for i in range(n-2):
    #print(p[i], end="")
    #print(p[i+1], end="")
    #print(p[i+2], end="")
    if p[i] < p[i+1] < p[i+2] or p[i] > p[i+1] > p[i+2]:
        sum += 1
print(sum)


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

int main(){
  int n,m,q,i,j,k,M,P;
  cin >> n >> m >> q;
  vector<int> a(q),b(q),c(q),d(q);
  for(i=0;i<q;i++){
    cin >> a.at(i) >> b.at(i) >> c.at(i) >> d.at(i);
  }
  
  vector<int> A(n,1);
  A.at(n-1)=0;
  
  long long S=1;
  for(i=m;i<=m+n-1;i++){
    S=S*i;
  }
  for(i=1;i<=n;i++){
    S=S/i;
  }
  
  M=0;
  for(i=1;i<=S;i++){
    j=n-1;
    while(A.at(j)==m){
      j--;
    }
    A.at(j)++;
    for(k=j+1;k<n;k++){
      A.at(k)=A.at(j);
    }
    P=0;
    for(k=0;k<q;k++){
      if(A.at(b.at(k)-1)-A.at(a.at(k)-1)==c.at(k)){
        P=P+d.at(k);
      }
    }
    M=max(M,P);
  }
  
  cout << M << endl;
}

Measured memory_bytes: 3632
//shan61916
#include <bits/stdc++.h>
    using namespace std;
#define IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n" 
typedef long long ll;
typedef unsigned long long ull ;
typedef double dll ;
 
int main(){
 IOS
#ifdef SHAN
    freopen("input.txt" , "r" , stdin);  
#endif
  ll l, r;
  cin >> l >> r;
   ll mn = (ll)1e19;
    for(ll i = l ; i < r; i++) {
      for(ll j = i+1; j <= r; j++) {
        if(((i%2019 * j%2019)%2019)  <= mn) mn = ((i%2019 * j%2019)%2019) ;
        if(mn == 0) {
          cout << 0;
          return 0;
        }
      }
   }
    cout << mn%2019;
} //good night.

Measured memory_bytes: 256
n = int(input())
A = list(map(int,input().split()))
ave1 = sum(A)//len(A)
ave2 = ave1+1
Ans1 = 0
Ans2 = 0
for i in range(n):
  Ans1 += (A[i] - ave1)**2
  Ans2 += (A[i] - ave2)**2
Answer = min(Ans1,Ans2)
print(Answer)

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <string>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <iterator>
#include <limits>
#include <numeric>
#include <utility>
#include <cmath>
#include <cassert>
#include <cstdio>

using namespace std; using namespace placeholders;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector< int > VI;
typedef vector< vector< int > > VVI;
typedef vector< string > VS;
typedef stringstream SS;
typedef pair< int, int > PII;
typedef vector< pair< int, int > > VPII;
#define VT( T ) vector< T >
#define VVT( T ) vector< vector< T > >
#define LIM( T ) numeric_limits< T >

template < typename T > inline istream& operator>>( istream &s, vector< T > &v ){ for ( T &t : v ) { s >> t; } return s; }
template < typename T > inline ostream& operator<<( ostream &s, const vector< T > &v ){ for ( int i = 0; i < int( v.size() ); ++i ){ s << ( " " + !i ) << v[i]; } return s; }
template < typename T > inline T fromString( const string &s ) { T res; istringstream iss( s ); iss >> res; return res; };
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };

#define REP2( i, n ) REP3( i, 0, n )
#define REP3( i, m, n ) for ( int i = ( int )( m ); i < ( int )( n ); ++i )
#define GET_REP( a, b, c, F, ... ) F
#define REP( ... ) GET_REP( __VA_ARGS__, REP3, REP2 )( __VA_ARGS__ )
#define FOR( e, c ) for ( auto &e : c )
#define ALL( c ) ( c ).begin(), ( c ).end()
#define AALL( a, t ) ( t* )a, ( t* )a + sizeof( a ) / sizeof( t )
#define DRANGE( c, p ) ( c ).begin(), ( c ).begin() + p, ( c ).end()

#define SZ( v ) ( (int)( v ).size() )
#define PB push_back
#define EM emplace
#define EB emplace_back
#define BI back_inserter

#define EXIST( c, e ) ( ( c ).find( e ) != ( c ).end() )

#define MP make_pair
#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

int dp[ 131072 ][ 16 ];

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

	for ( string S; cin >> S && S != "0" ; )
	{
		const int L = SZ( S );

		fill( AALL( dp, int ), 0 );

		REP( i, L )
		{
			const int D = S[i] - '0';

			REP( j, 11 )
			{
				const int nj = ( j * 10 + D ) % 11;
				dp[ i + 1 ][ nj ] += dp[i][j];
			}
			if ( D )
			{
				++dp[ i + 1 ][D];
			}
		}

		int res = 0;
		REP( i, L + 1 )
		{
			res += dp[i][0];
		}
		cout << res  << endl;
	}




	return 0;
}

Measured memory_bytes: 9504
N = gets.to_i
A = gets.split.map(&:to_i)
D = [-1] + (0...N-1).to_a.select{ |i| A[i] != A[i+1] } + [N-1]
p (0...D.size-1).reduce(0) { |a,i| a + (D[i+1] - D[i])/2 }


Measured memory_bytes: 1788