akhauriyash/Code-Regression huggingface dataset:
import numpy as np

N = int(input())
A = np.fromstring(input(), sep=" ", dtype=np.int64)
Q = int(input())
B = np.zeros(Q)
C = np.zeros(Q)
D = np.fromstring(" ".join([input() for q in range(Q)]), sep=" ", dtype=np.int64).reshape((Q, 2))
B = D[:, 0]
C = D[:, 1]

d = dict(np.c_[np.unique(A, return_counts=True)])
s = np.sum(A)
for q in range(Q):
    if(B[q] in d):
        n = d.pop(B[q])
        s += n * (C[q] - B[q])
        if(C[q] in d):
            d[C[q]] += n
        else:
            d[C[q]] = n
    print(s)


Measured memory_bytes: 38580
if __FILE__ == $0
  while line = STDIN.gets
    tokens = line.chomp!.split.map!(&:to_i)
    w, h, x, y, r = *tokens
    if (x - r) >= 0 && (x + r) <= w && (y - r) >= 0 && (y + r) <= h
      puts "Yes"
    else
      puts "No"
    end
  end
end

Measured memory_bytes: 8652
s = input()
A = int(s[0])
B = int(s[1])
C = int(s[2])
D = int(s[3])

if A+B+C+D == 7:
	print("{0}+{1}+{2}+{3}=7".format(A,B,C,D))
elif A+B+C-D == 7:
	print("{0}+{1}+{2}-{3}=7".format(A,B,C,D))
elif A+B-C-D == 7:
	print("{0}+{1}-{2}-{3}=7".format(A,B,C,D))
elif A+B-C+D == 7:
	print("{0}+{1}-{2}+{3}=7".format(A,B,C,D))
elif A-B+C+D == 7:
	print("{0}-{1}+{2}+{3}=7".format(A,B,C,D))
elif A-B+C-D == 7:
	print("{0}-{1}+{2}-{3}=7".format(A,B,C,D))
elif A-B-C-D == 7:
	print("{0}-{1}-{2}-{3}=7".format(A,B,C,D))
elif A-B-C+D == 7:
	print("{0}-{1}-{2}+{3}=7".format(A,B,C,D))

Measured memory_bytes: 3064
w, h, n = map(int, input().split())

dist = []
for _ in range(n):
    x, y = map(int, input().split())
    dist.append([x, y])

start = dist.pop(0)
x1, y1 = start

cnt = 0
for d in dist:
    x2, y2 = d
    while 1:
        if x1 == x2 and y1 == y2:
            break

        cnt += 1
        if x1 < x2 and y1 < y2:
            x1 += 1
            y1 += 1
        elif x1 == x2 and y1 < y2:
            y1 += 1
        elif x1 > x2 and y1 < y2:
            if y1 != h:
                y1 += 1
            else:
                x1 -= 1
        elif x1 < x2 and y1 == y2:
            x1 += 1
        elif x1 > x2 and y1 == y2:
            x1 -= 1
        elif x1 < x2 and y1 > y2:
            if y1 != 0:
                y1 -= 1
            else:
                x1 += 1
        elif x1 == x2 and y1 > y2:
            y1 -= 1
        elif x1 > x2 and y1 > y2:
            x1 -= 1
            y1 -= 1

print(cnt)



Measured memory_bytes: 5660
import java.io.PrintWriter

object Main extends App {

  val out = new PrintWriter(System.out)
  val month = Array(0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30)
  val week = Array("Wednesday", "Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday")

  Iterator.continually(io.StdIn.readLine)
    .takeWhile(_ != "0 0")
    .map(s => s.split(" ").map(_.toInt))
    .map(a => month.take(a(0)).sum + a(1))
    .map(d => week(d%7))
    .foreach(out.println)

  out.flush()
}



Measured memory_bytes: 43748
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int inf = 1e9;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, b, a) for (int i = a - 1; i >= b; i--)
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

int main() {
    int n, k;
    cin >> n >> k;
    int p[n];
    rep (i, 0, n) cin >> p[i];
    sort (p, p + n);
    int ans = 0;
    rep (i, 0, k) ans += p[i];
    cout << ans << "\n";
}

Measured memory_bytes: 3616
// A - Range Flip Find Route
#include <bits/stdc++.h>

using namespace std;

int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false); cin.tie(0);
	int h, w;
	cin >> h >> w;
	vector<string> g(h);
	for (int i = 0; i < h; i++) cin >> g[i];
	vector<vector<int> > dp(h, vector<int>(w, 1e9));
	dp[0][0] = g[0][0] == '#' ? 1 : 0;
	for (int i = 0; i < h; i++)
		for (int j = 0; j < w; j++) {
			if (i == 0 && j == 0) continue;
			if (i > 0) {
				if (g[i - 1][j] == g[i][j] || g[i][j] == '.') dp[i][j] = min(dp[i][j], dp[i - 1][j]);
				else dp[i][j] = min(dp[i][j], dp[i - 1][j] + 1);
			}
			if (j > 0) {
				if (g[i][j - 1] == g[i][j] || g[i][j] == '.') dp[i][j] = min(dp[i][j], dp[i][j - 1]);
				else dp[i][j] = min(dp[i][j], dp[i][j - 1] + 1);
			}
		}

	cout << dp[h - 1][w - 1] << endl;

	return 0;
}


Measured memory_bytes: 384
using System;
using System.Collections.Generic;

    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            double a = double.Parse(input[0]);
            double b = double.Parse(input[1]);
            double h = double.Parse(input[2]);
            double m = double.Parse(input[3]);

            double x0, y0, x1, y1;
            x0 = Math.Cos((h / 12.0+m/60.0/12.0) * 2.0 * Math.PI)*a;
            y0 = Math.Sin((h / 12.0+m/60.0/12.0) * 2.0 * Math.PI)*a;
            x1 = Math.Cos(m / 60.0 * 2.0 * Math.PI)*b;
            y1 = Math.Sin(m / 60.0 * 2.0 * Math.PI)*b;

            double output= Math.Sqrt(
                Math.Pow(x0 - x1, 2.0) +
                Math.Pow(y0 - y1, 2.0));

            Console.WriteLine(output);
        }
    }


Measured memory_bytes: 28008
n = gets.to_i
ws = gets.split(" ").map(&:to_i)
full = ws.inject(:+)
half = full / 2
s1 = 0
ws.each do |w|
    s1 += w
    if s1 >= half
        s1 -= w if (s1 - half).abs > (s1 - w - half).abs
        break
    end
end
print (2 * s1 - full).abs

Measured memory_bytes: 1788
#include<iostream>
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

int main(){
    int N;cin>>N;
    if(N%2==0){
        cout<<N/2-1<<endl;
        return 0;
    }
    else{
        cout<<N/2<<endl;
        return 0;
    }
}

Measured memory_bytes: 384
n = input()
An = [int(x) for x in input().split()]
mod0 = 0
mod1 = 0
mod2 = 0
for x in An:
    if x % 3 == 0:
        mod0 += 1
    if x % 3 == 1:
        mod1 += 1
    if x % 3 == 2:
        mod2 += 1
if mod1 == 0 and mod2 == 0:
    print("1")
elif abs(mod1 - mod2) <= 3:
    print((mod0+mod1+mod2))
else:
    if mod1>mod2:
        print((mod0+mod2+mod2+3))
    if mod1<mod2:
        print((mod0+mod1+mod1+3))



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

using namespace std;

#define inf 1<<30
#define pqueue priority_queue
#define mp make_pair
#define pb push_back
#define fn fill_n
typedef long long llong;
typedef unsigned long long ullong;
typedef pair<int, int> P;

vector<P> v;

llong memo[51][10001];
llong npr[51][51] = {};

llong NPR(int n, int r){
	if(npr[n][r] != 0)
		return npr[n][r];

	llong ret = 1;
	for(int i = 1; i <= r; i++)
		ret = ret * (n - (i - 1)) / i;

	return npr[n][r] = ret;
}

llong solve(int now, int ave){
	if(memo[now][ave+5000] > -1)
		return memo[now][ave+5000];
	if(ave > 0) return 0;
	if(now == v.size()){
		if(ave == 0) return 1;
		else return 0;
	}

	llong ret = 0;
	for(int i = 0; i <= v[now].second; i++){
		ret += NPR(v[now].second, i) * solve(now+1, ave + v[now].first*i);
	}

	return memo[now][ave+5000] = ret;
}

int main(){
	fn(*memo, 51*10001, -1);
	int N, A;
	map<int,int> m;
	cin >> N >> A;
	int in;
	for(int i = 0; i < N; i++){
		cin >> in;
		m[in-A]++;
	}
	for(auto it = m.begin(); it != m.end(); it++){
		v.pb(*it);
	}

	cout << solve(0,0) - 1 << endl;

	return 0;
}


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

#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define ll long long int
 
using namespace std;


int main(){ 

        int n;
        int m;
        int x;
        cin >> n >> m >> x;
        
        vector<int> a(n);
        for(int i = 0; i <n; i++){
           cin >> a[i];
        }
        
        vector<int> b(m);
        for(int i =0; i <m; i++){
           cin >> b[i];
        }
        ll sum=0,count=0,temp=0,i=0,j=0;        
        while(i<n && sum+a[i]<=x){   
            sum+=a[i];
            i++;
        }
        count=i;        
       
        while(j<m && i>=0){           
            sum+=b[j];             
            j++;
            while(sum>x && i>0){
                i--;
                sum-=a[i];
            }
            if(sum<=x && i+j>count)
                count=i+j;
        }
        cout<<count;
 
    return 0;
}

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

int main() {
  int n, k;
  cin >> n >> k;
  
  vector<int> v(n);
  rep(i,k) {
    int d;
    cin >> d;
    vector<int> a(d);
    rep(j,d) {
      cin >> a.at(j);
      a.at(j)--;
      if (v.at(a.at(j))==0) v.at(a.at(j))++;
    }
  }
  
  int ans = 0;
  rep(i,n) if (v.at(i)==0) ans++;
  
  cout << ans << endl;
}

Measured memory_bytes: 3632
import Data.List
import qualified Data.Vector.Unboxed as V
main=do
    n<-readLn::IO Int
    as<-V.fromList.map read.words<$>getLine::IO(V.Vector Int)
    print $ (`div` 2) $ length $ filter (\i->as V.! ((as V.! i)-1) == (i+1)) [0..n-1]


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

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

  vector<int> A(N);
  int tot = 0;
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    tot += A.at(i);
  }

  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());

  for (int i = 0; i < M; i++) {
    if (A.at(i) * 4 * M < tot) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
}

Measured memory_bytes: 256
import java.util.stream.*;
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        int h = scanner.nextInt();
        int w = scanner.nextInt();
        int n = scanner.nextInt();
        List<Integer> a = new ArrayList<>();
        for (int i = 1; i <= n; i++) {
            a.addAll(Collections.nCopies(scanner.nextInt(), i));
        }

        for (int i = 0; i < h; i++) {
            List<Integer> list = a.subList(i * w, i * w + w);
            if (i % 2 == 1) {
                Collections.reverse(list);
            }
            System.out.println(list.stream().map(String::valueOf).collect(Collectors.joining(" ")));
        }
    }
}

Measured memory_bytes: 33968
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<map>
#include <algorithm>
#include<cstdlib>
#include<cmath>
#include<deque>
#include <numeric>
typedef unsigned long long ull;
typedef  long long ll;

int main() {
	ll a, b;
	std::cin >> a >> b;

	if ((b % a) == 0) {
		std::cout << a+ b << std::endl;
	}
	else
	{
		std::cout << b - a << std::endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
typedef long long ll;
const int maxn = 1e6;
ll ans[maxn];

void init() {
    memset(ans, 0, sizeof(ans));
    for (int i=1; i <= 1000000; i++) {
       ans[i]+=ans[i-1];
       if (i%3==0 || i%5==0) {
         continue;
       } else {
         ans[i]+=i;
       }
    }
}

int main () {
    init();
    int n;
    cin>>n;
    cout<<ans[n]<<endl;
    return 0;
}


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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

LL N;

int main(){
	cin >> N;
	int ans = 0 , z = 0;
	LL k = N;
	for( ; k > 9 ; k /= 10){
		ans += k%10;
		++z;
	}
	ans += k;
	ans = max((LL)ans , 9*z+k-1);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/abc067/tasks/arc078_a

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DUMP(a, n) REP(_i, n) printf("%d%c", a[_i], _i + 1 == n ? '\n' : ' ')
#define DUMP2D(a, n, m) REP(_i, n) REP(_j, m) printf("%d%c", a[_i][_j], _j + 1 == m ? '\n' : ' '); puts("")

const int N_MAX = 2*1e5;
const int A_I_MAX = 1e9;
const ll INF = 1e18;

int N;
int a[N_MAX];

ll acc[N_MAX + 1];

void solve() {
  REP(i, N) acc[i + 1] = acc[i] + a[i];
  ll ans = INF;
  FOR(i, 1, N - 1) {
    ll x = acc[i];
    ll y = acc[N] - acc[i];
    ans = min(ans, abs(x - y));
  }
  printf("%lld\n", ans);
}

void input() {
  scanf("%d", &N);
  REP(i, N) scanf("%d", a + i);
}

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


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

using namespace std;

#define ll long long

int main(){
	int n, m;
	cin >> n >> m;
	vector<int> adj(n+1, 0);
	for(int i = 0; i < m; ++i){
		int a, b;
		cin >> a >> b;
		++adj[a];
		++adj[b];
	}
	for(int i = 1; i <= n; ++i){
		cout << adj[i] << "\n";
	}

	return 0;
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long int
#define ld long double
using namespace std;
const int N = 1e6 + 5;
const int MOD = 1e9 + 7;


int main(){
	fast;
	string s, ss;
	cin >> s >> ss;
	int n = ss.size(), mx = 0, ct = 0, k = 0;
	for(int i = 0; i <= s.size() - n; ++i){
		if(s[i] == ss[k]) ++ct;
		++k;
		for(int j = i + 1; j < i + n; ++j){
			if(s[j] == ss[k]) 
				++ct;
			++k;
		}
		// cout << ct << " ";
		mx = max(mx, ct);
		ct = 0, k = 0;
	}
	cout << n - mx;
	return 0;
}
// 								This code will self destruct in 5 seconds..		

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

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;
    }
};

int main() {
    int n;
    cin >> n;
    vll t(n), a(n);
    rep(i, n) cin >> t[i];
    rep(i, n) cin >> a[i];
    mint ans = 1;
    if (t[n-1] != a[0]) ans = 0;    
    srep(i, n-1, 1) {
        if (t[i] == t[i-1] && a[i] == a[i+1]) ans *= min(t[i], a[i]); 
        else if (t[i] > t[i-1] && t[i] > a[i]) ans = 0;
        else if (a[i] > a[i+1] && a[i] > t[i]) ans = 0;
    }

    cout << ans.x << endl;
    return 0;
}

Measured memory_bytes: 1792
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>

namespace adaptor = boost::adaptors;

void Solve()
{
    int64_t D, G;
	std::cin >> D;
	std::cin >> G;
	std::vector<int64_t> p(D);
	std::vector<int64_t> c(D);
	for (int64_t i = 0; i < D; i++) {
		std::cin >> p[i];
		std::cin >> c[i];
	}

	int64_t ans = 1e9;
	for (int64_t bit = 0; bit < (1 << D); bit++) {
		int64_t tmp_sum = 0;
		int64_t num = 0;
		int64_t rest_max = -1;
		for (int64_t i = 0; i < D; i++) {
			if (bit & (1 << i)) {
				tmp_sum += 100 * (i + 1) * p[i] + c[i];
				num += p[i];
			} else {
				rest_max = i;
			}
		}
		if (tmp_sum < G) {
			int64_t provisional_sum = 100 * (rest_max + 1);
			int64_t need = (G - tmp_sum + provisional_sum - 1) / provisional_sum;
			if (need >= p[rest_max]) {
				continue;
			}
			num += need;
		}
		ans = std::min(ans, num);
	}

	std::cout << ans << std::endl;

}

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


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"reflect"
	"strconv"
	"sort"
)

var sc = bufio.NewScanner(os.Stdin)

// スライス内に指定した要素があるか判定
// 第1引数 : 要素, 第2要素 : スライス
// return : result, err
func contains(target interface{}, list interface{}) (bool, error) {
	switch list.(type) {
		case []int:
			revert := list.([]int)
			for _, r := range revert {
				if target == r {
					return true, nil
				}
			}
			return false, nil
			
		case []uint64:
			revert := list.([]uint64)
			for _, r := range revert {
				if target == r {
					return true, nil
				}
			}
			return false, nil
			
		case []string:
			revert := list.([]string)
			for _, r := range revert {
				if target == r {
					return true, nil
				}
			}
			return false, nil
		default:
			return false, fmt.Errorf("%v is an unsupported type", reflect.TypeOf(list))
	}

	return false, fmt.Errorf("processing failed")
}

// 1行読み込み
func nextLine() string {
	sc.Scan()
	return sc.Text()
}

// 読み込みをint型へキャスト
func nextInt() int {
	sc.Scan()
	num, err := strconv.Atoi(sc.Text())
	if(err != nil) {
		panic(err)
	}
	return num
}

// 読み込みをfloat型へキャスト
func nextFloat() float64 {
	sc.Scan()
	num, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}
	return num
}

func main() {
	// scannerの挙動を改行区切り → 空白区切りに変更
	sc.Split(bufio.ScanWords)
	n := nextInt()
	k := nextInt()
	price := make([]int, 0, n)
	for i := 0; i < n; i++ {
		price = append(price, nextInt())
	}
	// sort.Sort(price)
	sort.Slice(price, func(i, j int) bool { return price[i] < price[j] })
	
	sum := 0
	for m := 0; m < k; m++ {
		sum += price[m]
	}
	fmt.Println(sum)
}

Measured memory_bytes: 1780
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using Pair = pair<int64_t, int64_t>;
constexpr int64_t kInf = INT64_MAX / 2L;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int64_t N, x;
  cin >> N >> x;
  // const int64_t L = static_cast<int64_t>(T.length());
  int64_t result = 0;
  vector<int64_t> A(N);
  for (int64_t i = 0; i < N; ++i) {
    cin >> A[i];
    if (A[i] > x) {
      result += A[i] - x;
      A[i] = x;
    }
    if (i >= 1 && A[i - 1] + A[i] > x) {
      const int64_t d = A[i - 1] + A[i] - x;
      A[i] -= d;
      result += d;
    }
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 3948
function Main (input) {
  input = input.split("\n")[0].split(" ").map(Number);
  var h1 = input[0];
  var s1 = input[1];
  var h2 = input[2];
  var s2 = input[3];
  var tr = 0;
  while (true) {
    if (h1 <= 0) {
      console.log("No");
      break;
    }
    else if (h2 <= 0) {
      console.log("Yes");
      break;
    }
    else {
      if (tr) {
        h1 -= s2;
      }
      else {
        h2 -= s1;
      }
      tr == 0 ? tr = 1 : tr = 0
    }
  }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29644
#include<bits/stdc++.h>
using namespace std;
int main(){
	int N,M;cin>>N>>M;
	vector<pair<long,long>> A(N);
	for(int i=0;i<N;i++){
		cin>>A[i].first>>A[i].second;
	}sort(A.begin(),A.end());
	long sum=0,num=0;int a=0,b=0;
	while(num<M){
		num++;
		sum+=A[a].first;
		b++;
		if(b==A[a].second){
			a++;
			b=0;
		}
	}cout<<sum<<endl;
}

Measured memory_bytes: 1792
def main():
    from collections import Counter

    N = int(input())
    S = [input() for _ in range(N)]

    c = Counter(S)
    _max = max(c.values())

    keys = [k for k, v in c.items() if v == _max]
    print('\n'.join(sorted(keys)))

if __name__ == '__main__':
    main()


Measured memory_bytes: 35940
/*
        _            _                  _            _       _     _         _   _          _          _             _        
       / /\         / /\               / /\         / /\    / /\  /\ \      /\_\/\_\ _     /\ \       /\ \     _    /\ \      
      / /  \       / /  \             / /  \       / / /   / / /  \ \ \    / / / / //\_\   \ \ \     /  \ \   /\_\ /  \ \     
     / / /\ \__   / / /\ \           / / /\ \__   / /_/   / / /   /\ \_\  /\ \/ \ \/ / /   /\ \_\   / /\ \ \_/ / // /\ \_\    
    / / /\ \___\ / / /\ \ \         / / /\ \___\ / /\ \__/ / /   / /\/_/ /  \____\__/ /   / /\/_/  / / /\ \___/ // / /\/_/    
    \ \ \ \/___// / /  \ \ \        \ \ \ \/___// /\ \___\/ /   / / /   / /\/________/   / / /    / / /  \/____// / / ______  
     \ \ \     / / /___/ /\ \        \ \ \     / / /\/___/ /   / / /   / / /\/_// / /   / / /    / / /    / / // / / /\_____\ 
 _    \ \ \   / / /_____/ /\ \   _    \ \ \   / / /   / / /   / / /   / / /    / / /   / / /    / / /    / / // / /  \/____ / 
/_/\__/ / /  / /_________/\ \ \ /_/\__/ / /  / / /   / / /___/ / /__ / / /    / / /___/ / /__  / / /    / / // / /_____/ / /  
\ \/___/ /  / / /_       __\ \_\\ \/___/ /  / / /   / / //\__\/_/___\\/_/    / / //\__\/_/___\/ / /    / / // / /______\/ /   
 \_____\/   \_\___\     /____/_/ \_____\/   \/_/    \/_/ \/_________/        \/_/ \/_________/\/_/     \/_/ \/___________/    
                                                                                                                              
*/
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for(int i = 0;i < (n);++i)

#define endl '\n'
#define pb emplace_back
#define mkp make_pair
#define p_q priority_queue
#define INF 2000000000
#define PI 3.1415926
#define coutdb cout << fixed << setprecision(10)

const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};
const int dx_8[]={1,1,0,-1,-1,-1,0,1}, dy_8[]={0,-1,-1,-1,0,1,1,1};
const long long MOD = 1e9+7;

typedef long long ll;
// #define int long long

template <typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}

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

  int n, k; string s; cin >> n >> s >> k; k--;
  REP(i, n){
    if(s[i] != s[k]) s[i] = '*';
  }
  cout << s << endl;

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define NM 10000
#define QM 500
#define NOT_FOUND -1

int linearSearch(int *A,int key,int length){
  int i=0;
  A[length] = key;
  while (A[i] != key) i++;
  if(i == length) return NOT_FOUND;
  return i;
}

int main(){

  int i,j,count=0,x,y,A[NM],B[QM],k;

  scanf("%d",&x);

  for(i=0;i<x;i++) scanf("%d",&A[i]);

  scanf("%d",&y);

  for(i=0;i<y;i++) scanf("%d",&B[i]);

  for(i=0;i<y;i++) {
    k =  linearSearch(A, B[i], x+1);
    if( k >= 0 ) count++;
  }

  printf("%d\n",count);

  return 0;
}
  



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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repp(i, n, m) for(int (i) = (n); (i) < (m); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define ldou long double
#define fi first
#define se second
#define setpre(x) std::cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ std::cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , "; logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 300005;

/* ...o(^-^)o... */

int main(){
    lint a,b,c; cin>>a>>b>>c;
    lint res = b+min(c,a+b+1);
    out(res);
    /*
    b枚は確実に食べられる
    毒入りのクッキーは, a+b+1枚まで食べられる
    */
}

Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
struct food{
	int t;
	int d;
	bool operator<(const food b)const{
		return d>b.d;
	}
}a[100000+5];
int n,k;
stack<int > q;
set<int > s;
long long sum=0,sum1;
int main(int argc, char *argv[])
{
	cin>>n>>k;
	for(int i=0;i<n;i++)
		scanf("%d %d",&a[i].t,&a[i].d);
	sort(a,a+n);
	for(int i=0;i<k;i++){
			sum+=a[i].d;
			if(s.count(a[i].t))
				q.push(a[i].d);
			s.insert(a[i].t);	
	}	
	sum+=s.size()*s.size();
	sum1=sum;
	int i=k;	
	while(i<n&&!q.empty()){
		if(!s.count(a[i].t)){
			sum1=sum1-q.top()+a[i].d-s.size()*s.size()+(s.size()+1)*(s.size()+1);
			q.pop();
			s.insert(a[i].t);
			sum=max(sum1,sum);
			//sum1=sum;
		}
		i++;	
	}	
	cout<<sum<<'\n';
	
	
	return 0;
}

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

typedef long long ll;

int main() {
    int N, M, p, co = 0, pe = 0;
    string S;
    cin >> N >> M;
    vector<int> WA(N, 0), AC(N, 0);
    rep(i, M) {
        cin >> p >> S;
        if (S == "AC" && AC[p - 1] == 0) {
            co++;
            pe += WA[p - 1];
            AC[p - 1]++;
        } else {
            WA[p - 1]++;
        }
    }
    cout << co << " " << pe << endl;
}

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

using namespace std;
typedef long long ll;
#define pi pair<double,double>
const int N = 110;
ll read() {
    ll x = 0,f = 1; char c = getchar();
    while(c < '0' || c > '9') {if(c == '-') f = -1;c = getchar();}
    while(c >= '0' && c <= '9') {x = x * 10 + c - '0',c = getchar();}
    return x * f;
}
pi a[N];
bool cmp(const pi &A,const pi &B) {
    return atan2(A.second , A.first) < atan2(B.second , B.first);
}
int main() {
    int n = read();
    for(int i = 0;i < n;++i) a[i].first = read(),a[i].second = read();
    sort(a,a + n,cmp);
    double ans = 0;
    for(int i = 0;i < n;++i) {
        double X = a[i].first,Y = a[i].second;
        ans = max(ans,X * X + Y * Y);
        for(int j = (i + 1) % n;j != i;j = (j + 1) % n) {
            X += a[j].first,Y += a[j].second;
            ans = max(ans,X * X + Y * Y);
        }
    }
    printf("%.10lf",sqrt(ans));
    return 0;
}

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

#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ALL(a) begin(a), end(a)
#define SZ(a) ((int)(a).size())

#define REP(a, b) for (int a = 0; a < (b); a++)
#define FOR(a, b, c) for (int a = (b); a <= (c); a++)
#define REPD(a, b) for (int a = (b) - 1; a >= 0; a--)
#define FORD(a, b, c) for (int a = (b); a >= (c); a--)

#define MIN(a, b) (a) = min((a), (b))
#define MAX(a, b) (a) = max((a), (b))

#ifdef __DEBUG
#define debug if (true)
#else
#define debug if (false)
#endif

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

template <typename T> using V = vector<T>;
template <typename T> using VV = vector<V<T>>;
template <typename T> using VVV = vector<VV<T>>;

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2> &p) {
  return is >> p.fi >> p.se;
}

const int MOD = 1e9 + 7;

int add(int a, int b) { if ((a += b) >= MOD) a -= MOD; return a; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  vector<string> grid(n);
  REP(i, n) cin >> grid[i];
  VV<int> dp(n, vi(m, 0));
  dp[0][0] = 1;
  REP(i, n) REP(j, m) if (grid[i][j] != '#') {
    if (i + 1 < n && grid[i + 1][j] != '#') {
      dp[i + 1][j] = add(dp[i + 1][j], dp[i][j]);
    }
    if (j + 1 < m && grid[i][j + 1] != '#') {
      dp[i][j + 1] = add(dp[i][j + 1], dp[i][j]);
    }
  }
  cout << dp[n - 1][m - 1] << endl;
}


Measured memory_bytes: 5248
#pragma region Macros

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
#define int ll
using vi = vector<int>;
using vvi = vector<vi>;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

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;
}
template <class T>
ostream &operator<<(ostream &out, vector<T> const &v) {
    for (auto &&a : v) out << a << " ";
    out << endl;
    return out;
}

// debug methods
// usage: debug(x,y);
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define debug_1(x1) cout << #x1 << ": " << x1 << endl
#define debug_2(x1, x2) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define debug_3(x1, x2, x3) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << endl
#define debug_4(x1, x2, x3, x4) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << endl
#define debug_5(x1, x2, x3, x4, x5) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#ifdef _DEBUG
#define debug(...)                                                        \
    CHOOSE((__VA_ARGS__, debug_5, debug_4, debug_3, debug_2, debug_1, ~)) \
    (__VA_ARGS__)
#else
#define debug(...)
#endif

#pragma endregion

void Main() {
    int A, B, C, K;
    cin >> A >> B >> C >> K;

    if (K <= A) {
        cout << K;
        return;
    }
    if (K <= A + B) {
        cout << A;
        return;
    }
    cout << A + (K - (A + B)) * -1;
}

#pragma region main
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    Main();
    cout << flush;
}
#pragma endregion


Measured memory_bytes: 3588
# import math
S = str(input())
ans = 0

before = S[0]
for i in range(1, len(S)):
    # print(before)
    # print('')
    # print(S[i])
    # print(before==S[i])
    if before == S[i]:
        ans += 1
    if before == '0':
        before = '1'
    else:
        before = '0'

print(ans)

# zero = 0
# one = 0
# for i in range(len(S)):
#     if S[i] == '0':
#         zero += 1
#     else:
#         one += 1
#
# hoge = abs(zero - one) /2
#
# ans = int(hoge)
#
# print(ans)


Measured memory_bytes: 3188
/*Coded by::
    **Avinash Tiwary**
    **BE/10298/2015**
    **Production Engineer**
    **Producing <code>**
*/
#include<bits/stdc++.h>
#define buf ios_base::sync_with_stdio (0), cin.tie (0)
typedef long long ll;
typedef double dob;
#define MAX 50010
#define M5 200009
#define M6 2000009
#define M 1000000007
#define INF 1e18
using namespace std;
typedef vector<ll> V;
typedef queue<ll > Q;
typedef stack<ll> S;
typedef pair<ll,ll> P;
#define f first
#define s second
#define mp make_pair
#define mt make_tuple
#define pb push_back
ll fac[M6],not_prime[M6],ar[M5],dis[2009][2009];
ll power(ll x,ll n)
{   if(n==0||x==0) return 1;
    else if(n%2 == 0) return power((x*x),n/2);
    else return (x*power((x*x),(n-1)/2));
}
void fact(){
    fac[0]=1;
    for(ll i=1;i<M6;i++) fac[i]=(i*fac[i-1])%M;
}
void sieve(){
    not_prime[1]=1; not_prime[0]=1;
    for(ll p=2;p*p<M6;p++){
        if(!not_prime[p]){
            for(ll i=p*2;i<=MAX;i+=p) not_prime[i]=1;
        }
    }
}
ll modi(ll a, ll m){
    ll m0 = m, t, q; ll x0 = 0, x1 = 1;
    if (m == 1) return 0;
    while (a > 1){  q = a / m; t = m; m = a % m, a = t;t = x0;x0 = x1 - q * x0; x1 = t;}
    if (x1 < 0) x1 += m0;return x1;
}
int main(){
    //buf; 
    //sieve(); 
    //fact();
    ll i,j,k,n,a,b,l,m,r,ans,test,sum;
    test=1;
    while(test--){
        cin>>n>>m>>r;
        for(i=1;i<=r;i++) cin>>ar[i];
        for(i=1;i<=200;i++) for(j=1;j<=200;j++) dis[i][j]=INT_MAX;
        for(i=1;i<=m;i++){
            cin>>a>>b>>l;
            dis[a][b]=min(dis[a][b],l); dis[b][a]=min(dis[b][a],l);
        }
        
        for(i=1;i<=n;i++) dis[i][i]=0;
        for(i=1;i<=n;i++){
            for(j=1;j<=n;j++){
                for(k=1;k<=n;k++){
                    dis[j][k]=min(dis[j][k],dis[j][i]+dis[i][k]);
                }
            }
        }
        sort(ar+1,ar+r+1);
        ans=INT_MAX;// ll l=0;
        do{
            ll mans=0;
            for(i=2;i<=r;i++){
                mans+=dis[ar[i-1]][ar[i]];
            }
            //l++;
            ans=min(ans,mans);
        }
        while(next_permutation(ar+1,ar+r+1));
        cout<<ans;//<<" "<<l;
    }
    return 0;
}

Measured memory_bytes: 5120
# E - Balanced Path

H, W = map(int, input().split())
A = [list(map(int, input().split())) for i in range(H)]
B = [list(map(int, input().split())) for i in range(H)]

assert all(len(row) == W for row in A)
assert all(len(row) == W for row in B)

# そのマスを通過したときの赤・青の差 (の絶対値)
table = [[set() for j in range(W)] for i in range(H)]

table[0][0].add(abs(A[0][0] - B[0][0]))

for i in range(H):
    if i >= 2:
        table[i - 2] = None
    for j in range(W):
        prev  = table[i - 1][j] if i > 0 else set()
        prev |= table[i][j - 1] if j > 0 else set()
        for pdiff in prev:
            diff = A[i][j] - B[i][j]
            table[i][j].add(abs(pdiff + diff))
            table[i][j].add(abs(pdiff - diff))

m = min(diff for diff in table[H - 1][W - 1])
print(m)


Measured memory_bytes: 153992
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

int main(){
    Init();
    ll h, w, ans = INFLL; cin >> h >> w;

    // 割れる位置はh-1, w-1箇所
    // 極力(h*w)/3に近い値となるのが望ましい
    // すなわち、hまたはwが3の倍数なら答えは単純
    if(h%3==0 || w%3 == 0) ans = 0;

    // 初手を縦に割るケースと横に割るケースで分けて考える
    // 極力(h*w)/3に近い値となるように割る
    double  optValue = (h*w)/3.0;
    vi ve(1, 0), ho(1, 0);

    // 縦に割る位置を決める
    for(ll i=1; i<=w-1; i++){
        if(h*i >= optValue){
            ve[0] = i;
            if(i >=2) ve.push_back(i-1);
            break;
        }
    }

    // 横に割る位置を決める
    for(ll i=1; i<=h-1; i++){
        if(w*i >= optValue){
            ho[0] = i;
            if(i >=2) ho.push_back(i-1);
            break;
        }
    }

    // 最小値候補を計算
    for(auto p: ve){
        vi s(3);
        s[0] = h*p;
        ll tw = w-p;
        if(h%2 == 0 || tw%2 == 0) s[1] = s[2] = (h*tw)/2;
        else{
            ll tmp_s = h*tw;
            s[1] = max(h, tw)/2*min(h, tw);
            s[2] = tmp_s - s[1];
        }
        sort(all(s));
        chmin(ans, s[2]-s[0]);
    }

    for(auto p: ho){
        vi s(3);
        s[0] = w*p;
        ll th = h-p;
        if(th%2 == 0 || w%2 == 0) s[1] = s[2] = (th*w)/2;
        else{
            ll tmp_s = th*w;
            s[1] = max(th, w)/2*min(th, w);
            s[2] = tmp_s - s[1];
        }
        sort(all(s));
        chmin(ans, s[2]-s[0]);
    }
    cout << ans << endl;
}

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

int main() {
  int N,D;
  cin >> N >> D;
  if (N%(2*D+1) == 0) {
    cout << N/(2*D+1) << endl;
  }
  else
    cout << N/(2*D+1) +1 << endl;
 
  
  
}


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

int main() {
  int N;
  cin >> N;
  
  map<string, int> A;
  for(int i=0; i<N; i++){
    string tmp;
    cin >> tmp;
    A[tmp] = 1;
  }
  
  cout << A.size() << endl;
  
    
  
}

//cout << fixed << setprecision(10) << (long double)2*sum/(long double)N << endl;


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

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

  for(int i=1; i<=n; i++)
  {
    int c=0, tmp=i;
    for(int j=0; j<5; j++)
    {
      c += tmp % 10;
      tmp /= 10;
    }
    if( a <= c && c <= b )
      sum += i;
  }

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 256
w=list(input())
n=len(w)
t=-1
def Z(s):
    m=len(s);z=[0]*m;c=0;f=[1]*m;
    for i in range(1,m):
        if i+z[i-c]<c+z[c]:z[i]=z[i-c]
        else:
            j=max(0,c+z[c]-i)
            while i+j<n and s[j]==s[i+j]:j=j+1
            z[i]=j;c=i
    for p in range(1,m):
        for k in range(2,z[p]//p+2):f[k*p-1]=0
    return f
for j in range(1,n//2+1):
    if n%j==0 and w[:n-j]==w[j:]:t=j;break;
if t==-1:print ('1\n1')
elif t==1:print (n);print (1)
else:
    zl=Z(w)
    w.reverse()
    zr=Z(w)
    cnt=0
    for i in range(0,n-1):
        if zl[i] and zr[n-2-i]:cnt=cnt+1
    print(2);print(cnt);


Measured memory_bytes: 26500
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

int main() {
    int n, c, k;
    cin >> n >> c >> k;
    vint t(n);
    rep(i, n) cin >> t[i];
    sort(all(t));

    int ans = 0;
    int rm = 0, tm = 0;
    rep(i, n) {
        if (rm == 0 || t[i] > tm) {
            ans++;
            rm = c-1;
            tm = t[i]+k;
        }
        else rm--;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
// AtCoder ABC131: D - Megalomania
// 2019.9.4 bal4u

#include <stdio.h>
#include <stdlib.h>

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif

int in() {   // 非負整数の入力
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

typedef struct { int a, b; } T;
T t[200005]; int N;

int cmp(const void *u, const void *v) { return ((T *)u)->b - ((T *)v)->b; }

int main()
{
	int i, s;
	
	N = in(); for (i = 0; i < N; i++) {
		t[i].a = in(), t[i].b = in();
		if (t[i].a > t[i].b) goto No;
	}
	qsort(t, N, sizeof(T), cmp);
	s = 0; for (i = 0; i < N; i++) {
		s += t[i].a;
		if (s > t[i].b) goto No;
	}
	puts("Yes"); return 0;
No: puts("No");  return 0;
}



Measured memory_bytes: 3324
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int m = sc.nextInt();
		int l = sc.nextInt();
		
		long[][] A = new long[n][m];
		long[][] B = new long[m][l];
		long[][] C = new long[n][l];
		
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < m; j++) {
				A[i][j] = sc.nextInt();
			}
		}
		
		for(int i = 0; i < m; i++) {
			for(int j = 0; j < l; j++) {
				B[i][j] = sc.nextInt();
			}
		}
		
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < l; j++) {
				for(int k = 0; k < m; k++) {
					C[i][j] += A[i][k] * B[k][j];
				}
			}
		}
		
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < l-1; j++) {
				System.out.print(C[i][j] + " ");
			}
			System.out.println(C[i][l-1]);
		}
	}
}



Measured memory_bytes: 54204
import sys
input=sys.stdin.readline

n=int(input())
J=[]
for i in range(n):
    a,b=map(int,input().split())
    J.append([b,a])
J=list(sorted(J))
now=0

for i in range(n):
    now+=J[i][1]
    if now>J[i][0]:
        print("No")
        sys.exit()
print("Yes")

Measured memory_bytes: 73564
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<iomanip>
#include<limits>
#include<deque>
#include<map>
#include<list>
#include<set>
#include <unordered_set>
#include<vector>
#include<cmath>
#include<cstdio>
#include<memory>
#include<bitset>
#include<stack>
#include <functional>
#include <queue>
#include <regex>

using namespace std;

constexpr int MOD = 1000000007;
constexpr int INF = 1050000000;

#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl

#define Tof(x) (x) ? Yes : No
#define TOF(x) (x) ? YES : NO
#define tof(x) (x) ? yes : no

using ll = long long;


/*vectorの要素を全部確認するやつだよ。


for (vector<int>::iterator itr = ans.begin(); itr != ans.end(); ++itr) {
	cout << *itr << " ";
}


*/


/*for文でx,yを上下左右確認するやつだよ。

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


for (int i = 0; i < 4; i++) {
	int ny = y + dy[i];
	int nx = x + dx[i];
}
*/

/*繰り返し二乗法だよ。modもとってくれるよ。n^kをmodで割った余りでやってくれるよ。

ll POW_MOD(ll n, ll k, ll mod) {
	ll r = 1;

	for (; k > 0; k >>= 1) {
		if (k & 1) {
			r = (r * n) % mod;
		}
		n = (n * n) % mod;
	}
	return r;
}


*/

/*2重for文書くのめんどくなった時用だよ。

for (int i = 0; i < h; i++) {
	for (int j = 0; j < w; j++) {

	}
}

*/


int main(void) {
	int n, m; cin >> n >> m;

	int l, r;

	int an[100005];
	memset(an, 0, sizeof(an));

	for (int i = 0; i < m; i++) {
		cin >> l >> r;
		an[l]+=1;
		an[r+1]-=1;
	}

	for (int i = 1; i <= n; i++) {
		an[i] += an[i - 1];
	}

	int ans = 0;
	for (int i = 0; i <= n; i++) {
		if (an[i] == m) { ans++; }
	}

	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 768
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

int main() {
    ll H, W;
    cin >> H >> W;

    vector<vector<ll>> a(H, vector<ll>(W));
    for (ll i = 0; i < H; i++) {
        for (ll j = 0; j < W; j++) {
            cin >> a[i][j];
        }
    }

    vector<ll> y, x, yy, xx;
    for (ll i = 0; i < H; i++) {
        for (ll j = 0; j < W - 1; j++) {
            if (a[i][j] % 2 == 1) {
                //右へ
                y.push_back(i + 1);
                x.push_back(j + 1);
                yy.push_back(i + 1);
                xx.push_back(j + 2);
                a[i][j]--;
                a[i][j + 1]++;
            }
        }
    }
    for (ll i = 0; i < H - 1; i++) {
        if (a[i][W - 1] % 2 == 1) {
            //下へ
            y.push_back(i + 1);
            x.push_back(W);
            yy.push_back(i + 2);
            xx.push_back(W);
            a[i][W - 1]--;
            a[i + 1][W - 1]++;
        }
    }

    cout << y.size() << endl;
    for (ll i = 0; i < y.size(); i++) {
        cout << y[i] << " " << x[i] << " " << yy[i] << " " << xx[i] << endl;
    }
}

Measured memory_bytes: 8152
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

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

bool check(int n) {
    vector<P> v;
    rep(i, n) {
        int a, b;
        cin >> a >> b;
        v.emplace_back(P(b, a));
    }
    sort(all(v));
    int sm = 0;
    for (auto p : v) {
        int a, b;
        tie(b, a) = p;
        sm += a;
        if (sm > b) {
            return false;
        }
    }
    return true;
}

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

    int n;
    while (cin >> n, n) {
        cout << (check(n) ? "Yes" : "No") << endl;
    }

}

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

template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
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 MOD = 998244353;
const ll inf = 1e18;

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

    ll n, s;
    cin >> n >> s;
    vll a(n);
    REP(i, n) {
        cin >> a[i];
    }
    ll res = 0;
    // dp[i][j][k] := i 文字目まで見て和が j になる場合の数
    // k == 0 -> L も R も決めていない
    // k == 1 -> L を決めたが R を決めていない
    // k == 2 -> L も R も決めた

    // L 確定時, 区間の先頭は (i + 1) 通りから選べる
    // R 確定時, 区間の終端は (n - i) 通りから選べる

    vvvll dp(n + 1, vvll(3030, vll(3)));
    dp[0][0][0] = 1;
    REP(i, n) {
        REP(j, s + 1) {
            // 前の文字までの和からスタート
            REP(k, 3) {
                dp[i + 1][j][k] += dp[i][j][k];
                dp[i + 1][j][k] %= MOD;
            }
            if (j + a[i] > s) continue;
            dp[i + 1][j + a[i]][1] += dp[i][j][0] * (i + 1); // L 確定
            dp[i + 1][j + a[i]][1] += dp[i][j][1]; // L 確定済, R 未定
            dp[i + 1][j + a[i]][2] += dp[i][j][0] * (i + 1) * (n - i) + dp[i][j][1] * (n - i); // R 確定
            REP(k, 3) dp[i + 1][j + a[i]][k] %= MOD;
        }
    }
    cout << dp[n][s][2] << endl;
    return 0;
}

Measured memory_bytes: 497792