akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) (v).begin(),(v).end()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    ll n,m,x; cin>>n>>m>>x;
    vector<ll> c(n);
    vector<vector<ll>> a(n,vector<ll>(m));
    rep(i,n){
        cin>>c[i];
        rep(j,m) cin>>a[i][j];
    }
    ll ans=INF;
    rep(bit,(1<<n)){
        ll tmp=0;
        vector<ll> u(m);
        rep(i,n){
            if(bit & (1<<i)){
                tmp+=c[i];
                rep(j,m) u[j]+=a[i][j];
            }
        }
        bool can=true;
        rep(i,m) if(u[i] < x) can=false;
        if(can) ans=min(ans,tmp);
    }
    if(ans==INF) cout<<-1<<endl;
    else cout<<ans<<endl;
    return 0;
}

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

int main(){
	int A[5][4][11] , n;
	for (int i = 1; i <= 4 ; i++ )
		for ( int j = 1; j <= 3; j++ )
			for ( int k = 1; k <= 10; k++ ) A[i][j][k] = 0;

	cin >> n;
	for (int i = 0; i < n; i++ ){
		int b, f, r, v;
		cin >> b >> f >> r >> v;
		A[b][f][r] += v;
	}

	for ( int f = 1; f <= 4; f++ ){
		if ( f > 1 ) cout << "####################\n";
		for ( int b = 1; b <= 3; b++ ){
			for ( int r = 1; r <= 10; r++ ) {
				cout << " " << A[f][b][r];
		    }
		    cout << endl;
		} 
	}

	return 0;
}

Measured memory_bytes: 3100
from sys import stdin, setrecursionlimit
from collections import deque

setrecursionlimit(10 ** 9)


def input():
    return stdin.readline().strip()


H, W = map(int, input().split())
s = [input() for _ in range(H)]

gx, gy = H - 1, W - 1
q = deque([(0, 0)])
dist = [[-1] * W for _ in range(H)]
dist[0][0] = 1

while q:
    x, y = q.popleft()
    if x == gx and y == gy:
        break

    for dx, dy in ((-1, 0), (1, 0), (0, -1), (0, 1)):
        nx, ny = x + dx, y + dy
        if 0 <= nx < H and 0 <= ny < W and dist[nx][ny] == -1 and s[nx][ny] == '.':
            q.append((nx, ny))
            dist[nx][ny] = dist[x][y] + 1

if dist[gx][gy] == -1:
    print(-1)
else:
    ans = sum(row.count('.') for row in s) - dist[gx][gy]
    print(ans)


Measured memory_bytes: 3316
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include <deque>
#include <stack>
#include <queue>
#include <array>
#include <random>
#include <chrono>

using namespace std;
#define rep(i, a, n) for (int i = a; i < n; ++i)
#define per(i, a, n) for (int i = n - 1; i >= a; --i)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef int64_t i64;
typedef uint64_t ui64;
typedef pair<int, int> pi;

struct custom_hash {
    static ui64 splitmix64(ui64 x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(ui64 x) const {
        static const ui64 FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

template <class T, class U>
inline ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << p.first << ' ' << p.second;
    return os;
}
template <class T, class U>
inline istream& operator>>(istream& os, pair<T, U>& p) {
    os >> p.first >> p.second;
    return os;
}
template <class T>
inline ostream& operator<<(ostream& os, const vector<T>& v) {
    if (v.empty())
        return os;
    if (v.begin() != v.end())
        os << v.front();
    for (auto it = ++v.begin(); it != v.end(); ++it)
        os << ' ' << *it;
    return os;
}
template <class T>
inline istream& operator>>(istream& is, vector<T>& v) {
    for (auto& i : v)
        is >> i;
    return is;
}

void Solve(istream& is, ostream& os) {
    string s;
    is >> s;

    int count = 0;
    rep(i, 1, sz(s)) {
        count += s[i] != s[i - 1];
    }
    os << count;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout << setprecision(20) << fixed;
    Solve(cin, cout);
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define FOR(i, m, n) for (ll i = m; i < (n); i++)
#define RFOR(i, m, n) for (ll i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
//#define print(ele) cout << (ele) << "\n"
#define print10(ele) cout << fixed << setprecision(10) << (ele) << "\n"

using namespace std;
typedef long long ll;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

const int mod = 1e9 + 7;
const int INF = 1001001001;

void print() { cout << endl; }

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) != 0) cout << " ";
  print(forward<Tail>(tail)...);
}

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  ivec c(n);

  vector<ivec> a(n, ivec(m));
  REP(i, n) {
    cin >> c[i];
    REP(j, m) { cin >> a[i][j]; }
  }
  int ans = INF;
  REP(s, 1 << n) {
    int cost = 0;
    ivec d(m);
    REP(i, n) {
      if (s >> i & 1) {
        cost += c[i];
        REP(j, m) d[j] += a[i][j];
      }
    }
    bool ok = true;
    REP(j, m) if (d[j] < x) ok = false;
    if (ok) ans = min(ans, cost);
  }
  if (ans == INF)
    print(-1);
  else
    print(ans);
  return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>  // min, max
#include <fstream>  // ifstream
#include <iomanip>  // setprecision
using namespace std;
typedef long long ll;

bool string_order(std::pair<ll, ll> first_entry,
                  std::pair<ll, ll> second_entry)
{
    return (first_entry.second > second_entry.second);
}

int main(void)
{
    ifstream inputFile("data/input.txt");
    if (getenv("SSH_CONNECTION") != nullptr) {
        cin.rdbuf(inputFile.rdbuf());
    }

    ll N, M;
    cin >> N >> M;
    vector<ll> A(N);
    for (ll i = 0; (i < N); ++i) {
        cin >> A[i];
    }
    vector<pair<ll, ll>> data(M);
    for (ll i = 0; (i < M); ++i) {
        cin >> data[i].first >> data[i].second;
    }
    sort(A.begin(), A.end());
    std::sort(data.begin(), data.end(), string_order);
    ll index = 0;
    for (ll i = 0; (i < M); ++i) {
        for (ll j = 0; (j < data[i].first); ++j) {
            if (A[index] < data[i].second) {
                A[index] = data[i].second;
                ++index;
            } else {
                goto ABORT;
            }
        }
    }
ABORT:
    ll res = 0;
    for (ll i = 0; (i < N); ++i) {
        res += A[i];
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 2560
#include <stdio.h>

int Fibonacci(int);
int F[45];

int main(){
  int n,f;
  scanf("%d",&n);
  f = Fibonacci(n);
  printf("%d\n",f);

  return 0;
}

int Fibonacci(int n){
  int i;
  F[0] = 1;
  F[1] = 1;
  for(i=2; i<=n; i++){
    F[i] = F[i-1] + F[i-2];
  }
  return F[n];
}


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

int n;
vector<int> a;

int gcd(int a, int b) {
    if (a < b) swap(a, b);
    if (b == 0) return a;
    return gcd(b, a % b);
}

int l(int i) { // a[1]...a[i-1]のgcd
    if (i == 1) return  a[i];
    return gcd(l(i-1), a[i-1]);
}

int r(int i) { // a[i+1]...a[n]のgcd
    if (i == n-1) return  a[i+1];
    return gcd(a[i+1], r(i+1));
}

int m(int i) {
    if (i == 1) return r(i);
    if (i == n) return l(i);
    return gcd(l(i), r(i));
}

int main() {
    cin >> n;
    a.resize(n+1);
    rep(i, n+1) {
        if (i == 0) continue;
        cin >> a[i];
    }
    int max_v = 0;

    vector<int> l(n+1), r(n+1), m(n+1);
    for (int i = 2; i <= n; i++) {
        // if (i == 2) l[i] = a[i-1];
        // else l[i] = gcd(l[i-1], a[i-1]);
        l[i] = gcd(l[i-1], a[i-1]);
    }
    for (int i = n-1; i >= 1; i--) {
        // if (i == n-1) r[i] = a[i+1];
        // else r[i] = gcd(a[i+1], r[i+1]);
        r[i] = gcd(a[i+1], r[i+1]);
    }
    for (int i = 1; i <= n; i++) {
        if (i == 1) m[i] = r[i];
        else if (i == n) m[i] = l[i];
        else m[i] = gcd(l[i], r[i]);
    }
    for (int i = 1; i <= n; i++) {
        // max_v = max(m(i+1), max_v);
        max_v = max(m[i], max_v);
    }
    printf("%d\n", max_v);
}

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

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

    int s = 0;
    for (int i = 0; i < m; i++) {
        int a;
        cin >> a;
        s += a;
    }

    cout << max(n - s, -1) << "\n";
}

Measured memory_bytes: 3620
#include <stdio.h>

int min(int a, int b){
return a <= b ? a : b;
}

int main(){
int a, b, c, d;
scanf("%d%d%d%d", &a, &b, &c, &d);
printf("%d\n", min(a, b) + min(c, d));
return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		int n=sc.I;
		var a=sc.Ia;
		var ans="Yes";
		if(n%3!=0){ans="No";}
		Array.Sort(a);
		var hs=new Dictionary<int,int>();
		for(int i = 0;i<n;i++) {
			if(hs.ContainsKey(a[i])){hs[a[i]]++;}
			else{hs.Add(a[i],1);}
		}
		if(hs.Count>3){ans="No";}
		foreach(var e in hs){
			if(e.Value%(n/3)!=0){
				ans="No";break;
			}
		}
		if((a[0]^a[n/3])!=a[n/3*2]){ans="No";}
		if(hs.Count==1&&a[0]==0){ans="Yes";}
		Console.WriteLine("{0}",ans);
	}
}

public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}


Measured memory_bytes: 20192
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
import functools 
import sys
import bisect
import string
import math
import time
import random
def Golf():*a,=map(int,open(0))
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[];g=[[] for i in range(n)]
    for i in range(E):
        inp=LI();org_inp.append(inp)
        if index==0:inp[0]-=1;inp[1]-=1
        if len(inp)==2:
            a,b=inp;g[a].append(b)
            if not Directed:g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp;aa=(inp[0],inp[2]);bb=(inp[1],inp[2]);g[a].append(bb)
            if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'#':1,'.':0}):
#h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0}) # sample usage
    mp=[1]*(w+2);found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[1]+[mp_def[j] for j in s]+[1]
    mp+=[1]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def bit_combination(k,n=2):
    rt=[]
    for tb in range(n**k):
        s=[tb//(n**bt)%n for bt in range(k)]
        rt+=[s]
    return rt
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)

YN=['YES','NO'];Yn=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
#sys.setrecursionlimit(10**7)
input=lambda: sys.stdin.readline().rstrip()
 
def ran_input():
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

show_flg=False
show_flg=True

N=10**6+2
m=[0]*(N)

n=I()
a=[]
for i in range(n):
    a+=[input()]
t=input()  
L,F=0,0
for i in a:
    f=''
    l=''
    for j in i:
        if j=='?':
            f+='a'
            l+='z'
        else:
            f+=j
            l+=j
    #show(f,l,t,sorted([f,l,t]))
    if f<=t:
        F+=1
    if l<t:
        L+=1
        
print(*list(range(L+1,F+1+1)))


Measured memory_bytes: 52440
#include "iostream"
#include "algorithm"
#include "string"
#include "set"
#include "vector"

using namespace std;

long long int N, M, K, L, R, H, W;

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

	cin >> N >> K >> M;
	vector<int>v(N + 1);
	for (int i = 0; i < K; i++) {
		cin >> L;
		v[L]++;
	}
	for (int i = 1; i < M; i++) {
		H += v[i];
	}
	for (int i = M + 1; i < N; i++) {
		W += v[i];
	}
	cout << min(H, W) << endl;
	return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<int64_t> H(N);
    for(int i = 0;i < N;i++) {
        cin >> H.at(i);
    }
    int max = 0;
    int i = 0;
    while(max <= N - i + 1) {
        int count = 0;
        int j = i;
        while(j < N - 1 && H.at(j) >= H.at(j + 1)) {
            count++;
            j++;
        }
        if(max < count) {
            max = count;
        }
        i++;
    }
    cout << max << endl;
}


Measured memory_bytes: 1024
#include <iostream>

typedef long long ll;

#define FOR(i,a,b) for(ll i = (a);i < (b);++i)
#define REP(i,n) FOR(i,0,n)

#define debug(x) cout << #x << "=" << x << endl;

using namespace std;

int main(void){
    
    int N;
    cin >> N;
    
    int a[100000];

    REP(i,N){
        cin >> a[i];
    }
    
    ll oddOnlyPosAns = 0;
    ll oddOnlyNegAns = 0;

    ll sum = 0;
    REP(i,N){
        sum += a[i];
        if(i % 2 == 1 && sum <= 0){
            oddOnlyPosAns += abs(sum)+1;
            sum = 1;
        }else if(i % 2 == 0 && sum >= 0){
            oddOnlyPosAns += sum+1;
            sum = -1;
        }
    }

    sum = 0;
    
    REP(i,N){
        sum += a[i];
        if(i % 2 == 1 && sum >= 0){
            oddOnlyNegAns += sum+1;
            sum = -1;
        }else if(i % 2 == 0 && sum <= 0){
            oddOnlyNegAns += abs(sum)+1;
            sum = 1;
        }
    }

    ll ans = min(oddOnlyPosAns,oddOnlyNegAns);

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


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main() {
	int n, d, x, a[1000],count=0;
	cin >> n >> d >> x;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		for (int j = 1; j<=d; j=j+a[i]) {
			if (j == 1) {
				count++;
				goto loop1;
			}
			count++;
		loop1:;
		}
	}
	cout << count+x << endl;
	int y;
	cin >> y;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>




int main (void) {
long long int N;
long long int i=1;
scanf("%lld",&N);
int res=0;
while (i<=sqrt(N)){
    if (N%i==0) res=i;
    i++;

}
printf("%lld",N/res-1 + res-1);
  return EXIT_SUCCESS;
}

Measured memory_bytes: 128
import sys
sys.setrecursionlimit(10*5)

n = int(input())
s = int(input())

def f(b, n):
  if n < b:
    return n
  return n % b + f(b, n//b)

is_b = False
if n < s:
  print(-1)
elif n == s:
  print(n + 1)
else:
  b = 2
  is_b = False
  while b * b <= n:
    if s == f(b, n):
      is_b = True
      break
    b += 1
  if is_b:
    print(b)
  else:
    p = 1
    ans = -1
    while p * p <= n:
      if (n - s) % p != 0:
        p += 1
        continue
      else:
        b = (n-s) // p + 1
        if s == f(b, n):
          ans = min(b, ans) if ans != -1 else b
      p += 1
    print(ans)

Measured memory_bytes: 3188
#pragma region header
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr ll inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
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;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */
#pragma endregion
signed main() {
    int n,k;cin >> n>> k;
    int r,s,p;cin >> r >> s >> p;
    string t;cin >> t;
    int ans = 0;
    rep(i, n) {
        if(i>=k)if((t[i]==t[i-k])){
            t[i]='z';
            continue;
        }
        if(t[i]=='r') ans+=p;
        else if(t[i]=='s') ans+=r;
        else ans+=s;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3772
from collections import deque
N, M, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
da = deque()
i = 0
tmpK = 0
while tmpK <= K and i < N:
    tmpK += A[i]
    da.append(A[i])
    i += 1
# 一冊多い場合がある
if (tmpK > K):
    i -= 1
    tmpK -= da.pop()

# Bを増やしていく
db = deque()
j = 0
while tmpK <= K and j < M:
    tmpK += B[j]
    db.append(B[j])
    j += 1
# 一冊多い場合がある
if (tmpK > K):
    j -= 1
    tmpK -= db.pop()
tmptot = i+j
while len(da) > 0:
    tmpK -= da.pop()
    i -= 1
    while tmpK <= K and j < M:
        tmpK += B[j]
        db.append(B[j])
        j += 1
    # 一冊多い場合がある
    if (tmpK > K):
        j -= 1
        tmpK -= db.pop()
    if tmptot < i+j:
        tmptot = i+j
print(tmptot)

Measured memory_bytes: 121576
#include<stdio.h>
int main()
{
	int n,a,p,z,i;
	
	scanf("%d",&n);
	a=500000000;
	z=0;
	for(i=0;i<n;i++){
		scanf("%d",&p);
		if(a>p){
			a=p;
		}
		if(z<p){
			z=p;
		}
	}
	printf("%d",z-a);
	
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;

typedef long long ll;

int N,M; vector<pair<ll,int>> P;
void input()
{
    cin >> N >> M;
    for(int i=0;i<N;++i){
        ll a; int b; cin >> a >> b;
        P.emplace_back(make_pair(a,b));
    }
}

void solve()
{
    sort(P.begin(),P.end());
    ll ans=0; int i=0;
    while(M > 0 && i < N){
        if(P[i].second > M){
            ans += P[i].first * M;
            break;
        }
        else {
            ans += P[i].first * P[i].second;
            M -= P[i].second;
        }
        ++i;
    }
    cout << ans << endl;
}

int main()
{
    cin.tie();
    ios::sync_with_stdio(false);
    input();
    solve();
    return 0;
}

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

typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> pll;
#define endl "\n";
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

ll const inf = 1e18;
ll const maxn = 1e6+5;
ll const mod = 998244353;

// code begins here

int main(){
    fast;
    
    ll n, sum=0;
    cin>>n;
    
    vector<ll> arr(n);
    for(auto &u: arr)
        cin>>u;
    
    map<ll,ll> mp;
    for(auto u: arr){
        mp[u]++;
        sum += u;
    }
    
    ll q;
    cin>>q;
    
    while(q--){
        ll b,c;
        cin>>b>>c;
        
        sum += mp[b]*(c-b);
        mp[c] += mp[b];
        mp[b] = 0;
        
        cout<<sum<<endl;
    }
    
    return 0;
}

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

#define ld long double
#define ll long long
#define ull unsigned long long
#define F first
#define S second
#define nl '\n'
#define pii pair <ll, ll>
#define pb push_back
#define mp make_pair
#define pi 3.14159265358979323846264
#define y1 abacaba
#define fn "abc"
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define pcnt(i) __builtin_popcount(i)
#define lcm(a,b) (a * b) / __gcd(a, b)
#define chill_wave ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pressF freopen("lepus.in", "r", stdin); freopen("lepus.out", "w", stdout);

using namespace std;

const long long MXN = 1e6 + 3;
const long long MAXN = 2e3 + 7;
const long long MOD = 1e9;
const long long INF = 1e18;
const long long MAXLOG = 20;

inline void f_math(bool ok = 0) { chill_wave if(ok) { pressF; } }

//int dx[]= {1,0,-1,0}; int dy[]= {0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1}; int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2}; int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[]={-1,-1,+0,+1,+1,+0}; int dy[]={-1,+1,+2,+1,-1,-2}; //Hexagonal Direction

ll n, k, a[MXN], dp[MXN];

int main() {

    f_math();

    cin >> n >> k;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
        dp[i] = INF;
    }
    dp[1] = 0;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= k; j++) {
            if(i + j <= n) {
                dp[i + j] = min(dp[i + j], dp[i] + abs(a[i] - a[j + i]));
            } else {
                break;
            }
        }
    }
    cout << dp[n];
    return 0;
}


Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
#pragma region atcoder
/*#include <atcoder/dsu>
using namespace atcoder;*/
#pragma endregion
#pragma region macros
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vl = vector<ll>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvc = vector<vector<char>>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n - 1; i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#pragma endregion
#pragma region debug for var, v, vv
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){cout << endl;int cnt = 0;for(const auto& v : vv){cout << cnt << "th : "; view(v); cnt++;} cout << endl;}
#pragma endregion
const ll mod = 1000000007;
const int inf = 1001001001;
const ll INF = 1001001001001001001;
const int MAX = 2000005;
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; }
ll modpow(ll a, ll p){ll ret = 1; while(p){if(p & 1){ret = ret * a % mod;} a = a * a % mod; p >>= 1;} return ret;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

/*-----------------------------------------------------------------------------------------------------*/
ll dp[103][103][303];
int main(){
    ll N, W; cin >> N >> W;
    vl v(N), w(N);
    rep(i,N){
        cin >> w[i] >> v[i];
        if(i > 0) w[i] -= w[0];
    }
    ll base = w[0];
    w[0] = 0;
    rep(i, N){
        rep(j, i + 1){
            rep(k, 301){
                chmax(dp[i + 1][j][k],dp[i][j][k]);
                if(k - w[i] >= 0) chmax(dp[i + 1][j + 1][k], dp[i][j][k - w[i]] + v[i]);
            }
        }
    }
    ll ans = 0;
    for(int i = 0; i <= N; i++){
        for(int j = 0; j < 301; j++){
            if(base * i + j <= W) chmax(ans, dp[N][i][j]);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 15980
n=int(input())
a=list(map(int,input().split()))
d={}
for i in range(n):
  if a[i] in d:
    d[a[i]]+=1
  else:
    d[a[i]]=1
d=list(d.items())
cnt=0
for i in range(len(d)):
  if d[i][0]>d[i][1]:
    cnt+=d[i][1]
  elif d[i][0]<d[i][1]:
    cnt+=(d[i][1]-d[i][0])
print(cnt)

Measured memory_bytes: 20976
#! usr/bin/env python
# -*- coding: utf-8 -*-


def main():
    a = int(input())
    s = set()

    s.add(a)
    for i in range(1, 1000001):
        if a % 2:
            a = 3 * a + 1
        else:
            a = a // 2
        if a in s:
            print(i+1)
            break
        s.add(a)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxx = 2e5 + 7;
const int Inf = 1 << 30;
const LL INF = 1LL << 60;
int s, w;

int main() {
	cin >> s >> w;
	if(s <= w) puts("unsafe");
	else puts("safe");
	return 0;
}

Measured memory_bytes: 3624
#include<iostream>

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

int main(){


	int c[4];
	int p[4];
	int r[4];
	int minc[4];
	int d[4] = {10,50,100,500};
	int m;
	int sum;
	int min;
	int flag = 0;
	while(std::cin >> m, (m)){

		if(flag == 1)std::cout << std::endl;
		flag = 1;

		rep(i,4){
			std::cin >> c[i];
			minc[i] = 0;
		}
		min = 20*20*20*20;

		for(p[0]=0; p[0]<=c[0];p[0]++){
			for(p[1]=0; p[1]<=c[1];p[1]++){
				for(p[2]=0; p[2]<=c[2];p[2]++){
					for(p[3]=0; p[3]<=c[3];p[3]++){
						sum = 0;
						rep(i,4){
							sum += d[i] * p[i];
							r[i] = 0;
						}
						if(sum < m)continue;
						sum -= m;
						rep(i,4){
							while(sum >= d[3-i]){
								sum -= d[3-i];
								r[i]++;
							}
						}
						int remain = 0;
						rep(i,4){
							remain += c[i] - p[i] + r[i];
						}
						if(remain < min){
							min = remain;
							rep(i,4){
								minc[i] = p[i];
							}
						}
					}
				}
			}
		}
		rep(i,4){
			if(minc[i] > 0){
				std::cout << d[i] << ' ' << minc[i] << std::endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 864
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i, n) for(int i=0; i<(int)(n); ++i)
const int M=998244353;
vector<int> to[200005];

ll dfs(int x) {
  ll res = 1;
  for (int t : to[x]) {
    res = res * dfs(t) % M;
  }
  return res+1;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  vector<P> r(n);
  rep(i, n) {
    cin >> r[i].first >> r[i].second;
  }
  sort(r.rbegin(), r.rend());
  set<P> s;
  rep(i, n) {
    int x = r[i].first, d = r[i].second;
    while (!s.empty() && s.begin()->first < x+d) {
      to[i].push_back(s.begin()->second);
      s.erase(s.begin());
    }
    s.emplace(x, i);
  }
  ll ans = 1;
  for (auto x : s) {
    int v = x.second;
    ans = ans * dfs(v) % M;
  }
  cout << ans << endl;
}

Measured memory_bytes: 22272
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if ( (a+b)%2 == 1) System.out.println((a+b)/2+1);
		else System.out.println( (a+b)/2);
	}
}


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

#define sz(x) (int)x.size() 
#define pb push_back 
#define mp make_pair 
#define fi(a, b) for(int i=a; i<=b; i++) 
#define fj(a, b) for(int j=a; j<=b; j++) 
#define fo(a, b) for(int o=a; o<=b; o++) 
#define fdi(a, b) for(int i=a; i>=b; i--) 
#define fdj(a, b) for(int j=a; j>=b; j--) 
#define fdo(a, b) for(int o=a; o>=b; o--) 

#ifdef LOCAL
#define err(...) fprintf(stderr, __VA_ARGS__)
#else
#define err(...) while(false) {}
#endif

typedef long long ll; 
typedef pair<int, int> pii; 
typedef pair<ll, ll> pll; 
typedef vector<int> vi; 
typedef vector<ll> vll;
typedef vector<pii> vpii; 
typedef vector<pll> vpll; 
typedef long double ld;
typedef unsigned long long ull;

/////////////////////////////////

int const MAX = 1e5 + 41;
char s[MAX];

int n;

void bad() {
	printf("-1\n");
	exit(0);
}

void solve() {
	if (s[1] == '0' || s[n] == '1' || s[n - 1] == '0') {
		bad();
	}
	fi(1, n - 1) {
		if (s[i] != s[n - i]) bad();
	}

	vpii edges;
	int root = 1;
	int x = 2;
	int p = 1;
	while (p < n) {
		if (s[p] == '1') {
			edges.pb(mp(root, x));
			root = x;
			x++;
			p++;
			continue;
		}
		int p1 = p + 1;
		while (p1 < n && s[p1] == '0') {
			p1++;
		}
		fi(1, p1 - p) {
			edges.pb(mp(root, x));
			x++;
		}
		edges.pb(mp(root, x));
		root = x;
		x++;
		p = p1 + 1;
	}

	for (auto x : edges) {
		printf("%d %d\n", x.first, x.second);
	}
}

int main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

  scanf(" %s", s + 1);
  n = strlen(s + 1);
	solve();		

	
#ifdef LOCAL
	err("ELAPSED TIME: %.3Lf\n", (ld) clock() / CLOCKS_PER_SEC);
#endif	
	
	return 0;
}

Measured memory_bytes: 2420
public class Main {
	/**
	 * ?????????????????????
	 *
	 * @param args
	 *            ?????¨?????????
	 */
	public static void main(String[] args) {
		for (int first = 1; first < 10; first++) {
			for (int second = 1; second < 10; second++) {
				System.out.println(first + "x" + second + "=" + (first * second));
			}
		}

	}
}

Measured memory_bytes: 24260
#include<bits/stdc++.h>
using namespace std;   
int main(){
    int c[5][5],n;
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            cin>>c[i][j];
        }
    }
    cin>>n;
    int b;
    bool a[5][5]={};
    for(int i=0;i<n;i++){
        cin>>b;
        for(int j=0;j<3;j++){
            for(int k=0;k<3;k++){
                if(c[j][k]==b){
                    a[j][k]=true;
                }
            }
        }
    }
    if(a[0][0]&&a[0][1]&&a[0][2]||a[1][0]&&a[1][1]&&a[1][2]||a[2][0]&&a[2][1]&&a[2][2]||a[0][0]&&a[1][0]&&a[2][0]||a[0][1]&&a[1][1]&&a[2][1]||a[0][2]&&a[1][2]&&a[2][2]||a[0][0]&&a[1][1]&&a[2][2]||a[2][0]&&a[1][1]&&a[0][2]){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    return 0;
}

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

int main(void){
    int w, a, b;
    cin >> w >> a >> b;
    
    if(a + w < b){
        cout << b - (a + w) << endl; 
    }else if(b + w < a){
        cout << a - (b + w) << endl;
    }else{
        cout << 0 << endl;
    }
    
    return 0;
}


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

#define int ll

#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(), (v).end() 
#define sz(v) (int)((v).size())
#define fs first
#define sd second

typedef long long ll;

typedef pair < int, int > pi;
typedef pair < pi, int > ppi;

typedef vector < int > vi;
typedef vector < vector < int > > vvi;
typedef vector < pi > vpi;
typedef vector < vpi > vvpi;
typedef vector < ppi > vppi;

void fast() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}

void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}

#ifdef LOCAL
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

double get_time() {
	return 1.0 * clock() / CLOCKS_PER_SEC;
}

int32_t main() {
	int a, v, b, w, t;
	cin >> a >> v >> b >> w >> t;
	int dist = abs(a - b), speed = v - w;
	if(speed <= 0)
		cout << "NO" << '\n';
	else {
		if(speed * t >= dist)
			cout << "YES" << '\n';
		else
			cout << "NO" << '\n';
	}
}


Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {

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

        if (b-a <= 0) {
            System.out.println("delicious");
        } else if (b-a <= x) {
            System.out.println("safe");
        } else {
            System.out.println("dangerous");
        }
    }

}

Measured memory_bytes: 21076
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
#define N_MAX 100000
using namespace std;

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

class Factorial {
    private:
        vector<long long int> fac;
    public:
        Factorial(long long int n_max);
        long long int getFactorial(long long int n);
};

Factorial::Factorial(long long int n_max) {
    fac.push_back(1);
    fac.push_back(1);
    for (long long int i = 2; i <= n_max; i++) {
        fac.push_back(fac[i-1] * i % MOD);
    }
}

long long int Factorial::getFactorial(long long int n) {
    return fac[n];
}

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}

void factorization(vector<LLP>& llp, long long n) {
    if (n <= 1) return;
    long long n2 = n;
    for (long long i = 2; i * i <= n ; i++) {
        int count = 0;
        while (n2 % i == 0) {
            n2 = n2 / i;
            count ++;
        }
        if (count > 0) {
            LLP temp;
            temp.first = i;
            temp.second = count;
            llp.push_back(temp);
        }
    }
    if (n2 > 1) {
        LLP temp;
        temp.first = n2;
        temp.second = 1;
        llp.push_back(temp);
    }
}

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

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

    vector<LLP> pfactors;
    factorization(pfactors, M);

    // if (pfactors.size() == 1) {
    //     cout << N << endl;
    //     return 0;
    // }

    Factorial fact(N_MAX * 2);

    long long int res = 1;

    for (int i = 0; i < pfactors.size(); i++) {
        res = res * fact.getFactorial(N - 1 + pfactors[i].second) % MOD * modinv(fact.getFactorial(N - 1), MOD) % MOD * modinv(fact.getFactorial(pfactors[i].second), MOD) % MOD;
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 2420
/*
If you want to shine like a sun, first burn like a sun.
*/

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long int
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define v2i vector<vector<int>>
#define v2l vector<vector<ll>>
#define ppi pair<int,int>
#define ppl pair<ll,ll>
#define vpi vector<ppi>
#define vpl vector<ppl>
#define all(x) x.begin(),x.end()
#define ii int,int 
#define ff first    
#define ss second
#define forn(i,a,b) for(int i=a;i<b;i++)
#define forr(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,m) for(auto i : m)
#define imx INT_MAX
#define imn INT_MIN
#define inf 9000000000000000000
#define minf -inf
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse 
#define itr iterator 
#define pre cout<<fixed<<setprecision(10);
#define umap unordered_map
#define uset unordered_set
#define pi 3.141592653589793
#define MAXN 100005
#define test1(x) cout << #x " = " << x << endl;
#define test2(x,y) cout << #x " = " << x << " " << #y " = " << y << endl;
const ll infinity = 9e18;

/*
#define oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define MODM(a,b,md) ((a%md)*(b%md))%md
#define MODA(a,b,md) ((a%md)+(b%md))%md
#define ull unsigned long long int
*/

/*
bool compare(int a,int b) {return a > b;}
bool compare1(ppi a,ppi b) {return a.ff > b.ff;}
bool compare2(ppi a,ppi b) {return a.ss < b.ss;}
ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md) {ll product = 1; while(b){if(b&1){product = MODM(product,a,md);}a = MODM(a,a,md);b = b>>1;} return product%md;}
bool isprime(ll n){if(n < 2) return 0; ll i = 2; while(i*i <= n){if(n%i == 0) return 0; i++;} return 1;}
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }
*/


int main()
{
    fast

/*
    #ifndef ONLINE_JUDGE
        freopen("input.txt",  "r",  stdin);
        freopen("output.txt", "w", stdout);
    #endif
//*/

        
	int n,m;
	cin>>n>>m;


	if(n == m)
	{
		cout<<"Yes";
	}
	else
	{
		cout<<"No";
	}
        
        












    return 0;
}

Measured memory_bytes: 256
program main
	implicit none
    character(2*10**5)::s
    integer(8)::i,ans,t,u
    t=1
    u=0
    i=1
    ans=0
    read(*,*) s
    
    do while(s(i:i)=='W' .or. s(i:i)=='B')
    	if (s(i:i)=='W')then
        	ans=ans+i-t
            t=t+1
            
        end if
        i=i+1
    end do
    
    write(*,*) ans
    
    stop
end program main

Measured memory_bytes: 1084
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;

long long spart[200005];

int n,k,x,i;
long double rez;

int main()
{
    ios_base::sync_with_stdio(false);
    cin>>n>>k;
    cout<<fixed<<setprecision(10);
    for(i=1;i<=n;i++){
        cin>>x;
        x++;
        spart[i]=spart[i-1]+x;
    }
    for(i=k;i<=n;i++){
        rez=max(rez,(long double)(spart[i]-spart[i-k])/2);
    }
    cout<<rez<<'\n';
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

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

    vector<int> a(N);
    for(int i=0; i<N; ++i){
        cin >> a[i];
    }

    // int trial_num;

    for(int n=0; n< K; ++n){
        vector<int> delta(N, 0);
    //     for(int i=0; i<N; ++i){
    //         int power = a[i];

    //         int MIN = max(0, i - power);
    //         int MAX = min( N-1, i + power);

    //         if(power > 0){
    //             for(int j=MIN; j<i; ++j){
    //                 delta[j]++;
    //             }

    //             for(int j=i+1; j<=MAX; ++j){
    //                 delta[j]++;
    //             }
    //         }
    //     }
    //     for(int i=0; i<N; ++i){
    //         delta[i]++;
    //     }
    //     swap(a, delta);

    // 　累積和
    for(int i=0; i<N; ++i){
        int power = a[i];
        int l  = max(0, i- power);
        int r = min(N-1, i+power);

        delta[l]++;
        if(r+1 < N) delta[r+1]--;
    }

    for(int i=1; i<N; i++){
        delta[i] += delta[i-1];
    }

    if( a == delta) break;
    else swap(a, delta);
    }

    for(int i=0; i<N; ++i){
        cout << a[i] << " ";
    }


    return 0;
}

Measured memory_bytes: 5104
s = input()
s12 = s[0] + s[1] 
s34 = s[2] + s[3]

if int(s12) >= 13 or s12 == "00": ## s12はMMでない YY
  if int(s34) >= 13 or s34 == "00": ## s34はMMでない YY
    print("NA")
  else: ## s34はMM
    print("YYMM")
else:
  if 1 <= int(s12) <= 12:
    if 1 <= int(s34) <= 12:
      print("AMBIGUOUS")
    else:
      print("MMYY")
    

Measured memory_bytes: 3060
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <cctype>
#include <complex>
#include <vector>
#include <algorithm>
#include <cassert>

using namespace std;


bool solve(){
	double in;
	while(cin>>in){
		int y = 4.9 * (in/9.8) * (in/9.8);
		int ans = 0;
		for(int i=1;i<10000;i++){
			int h = 5 * (i - 1);
			if(h > y){
				ans = i;
				break;
			}
		}
		cout<< ans<< endl;
	}
	return true;
}

int main(){
	cout.setf(ios::fixed);
	cout.precision(10);
	solve();

	return 0;
}

 

Measured memory_bytes: 1224
def main():
    n = int(input())
    a = list(map(int, input().split()))

    su = [0 for _ in range(n + 1)]    
    for i in range(n):
        su[i + 1] = su[i] + a[i]

    INF = 1e18
    dp = [[-INF for _ in range(n + 1)] for _ in range(n + 1)]

    for i in range(n + 1):
        dp[i][i] = 0

    for length in range(1, n + 1):
        i = 0
        while i + length <= n:
            j = i + length
            dp[i][j] = max(a[i] + (su[j] - su[i + 1]) - dp[i + 1][j], a[j - 1] + (su[j - 1] - su[i]) - dp[i][j - 1])
            i += 1
    
    print(dp[0][n] - (su[n] - dp[0][n]))

if __name__ == '__main__':
    main()

Measured memory_bytes: 399272
#include <bits/stdc++.h>
using namespace std;
int D; 
string S;

int N;
int solve(string s1, string s2){
    vector<vector<int> > dp(s1.size() + 1, vector<int>(s2.size() + 1, 0)); 
    for (int i = 1; i <= s1.size(); ++i){
        for (int j = 1; j <= s2.size(); ++j){
            if (s1[i - 1] == s2[j - 1]) {
                dp[i][j] = dp[i - 1][j - 1] + 1;
            }else{
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            }
        }
    }
    return dp[s1.size()][s2.size()];
}
int main(){
    cin >> N;
    string temp1, temp2;
    for (int i = 0; i < N; ++i){
        cin >> temp1 >> temp2;
        cout << solve(temp1, temp2) << endl;
    }
}



Measured memory_bytes: 6840
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod=1e9+7;

int main(){
  int N;
  string s;
  cin>>N>>s;
  ll cnt(1);
  for (int i(0);i<2*N;i++){
    if (i%2==0) {
      if (s[i]=='W') s[i]='B';
      else if (s[i]=='B') s[i]='W';
    }
  }
  ll cw(0);
  for (int i(0);i<N*2;i++){
    if (s[i]=='W'){
      cw+=1;
    } else {
      cnt*=cw;
      cw--;
      cnt%=mod;
    }
  }
  if (cw!=0) {
    cout << 0 << endl;
    return 0;
  }
  //cout << cnt << endl;
  ll p(1);
  for (int i(1);i<=N;i++){
    p*=i;
    p%=mod;
  }
  cout << (cnt*p)%mod << endl;
  return 0;
}



Measured memory_bytes: 640
program name
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int64):: n,i,j,ans,msum,psum
    integer(int64), allocatable:: a(:),b(:),d(:)
    
    read*, n
    allocate(a(n),b(n),d(n))
    read*, a(:)
    read*, b(:)
    d(:) = a(:) - b(:)

    if (sum(d) < 0) then
        print'(i0)', -1
        stop
    end if

    ans=0
    msum=0
    do i=1,n
        if (d(i) < 0) then
            ans=ans+1
            msum=msum-d(i)
        end if
    end do
    if (msum == 0) then
        print'(i0)', 0
        stop
    end if

    call merge_sort(d,1_8,n)

    psum=0
    do i=1,n
        psum=psum+d(i)
        if (psum >= msum) then
            print'(i0)', i+ans
            stop
        end if
    end do



contains
    recursive subroutine merge_sort(ar, fst, lst)
        integer(int64),intent(inout):: ar(:)
        integer(int64),intent(in):: fst,lst
        integer(int64):: mdl

        if (lst-fst < 2) then
            if (ar(fst) < ar(lst)) call swap(ar(fst),ar(lst))
            return
        end if

        mdl = (fst+lst)/2
        call merge_sort(ar, fst, mdl)
        call merge_sort(ar, mdl+1, lst)
        call merge_(ar, fst, mdl, lst)
    end subroutine

    subroutine merge_(ar, fst, mdl, lst)
        integer(int64),intent(inout):: ar(:)
        integer(int64),intent(in):: fst, mdl, lst
        integer(int64),allocatable:: tmp(:)
        integer(int64):: li, ri, ti

        allocate(tmp(lst-fst+1))

        li=fst
        ri=mdl+1   
        ti=1

        do while (li <= mdl .and. ri <= lst)
            if (ar(li) >= ar(ri)) then
                tmp(ti) = ar(li)
                li=li+1
            else
                tmp(ti) = ar(ri)
                ri=ri+1
            end if
            ti=ti+1
        end do

        if (li <= mdl) then
            tmp(ti:) = ar(li:mdl)
        else
            tmp(ti:) = ar(ri:lst)
        end if

        ar(fst:lst) = tmp(:)
        deallocate(tmp)
    end subroutine

    subroutine swap(x,y)
        integer(int64),intent(inout):: x,y
        integer(int64):: tmp
        tmp = x
        x = y
        y = tmp
    end subroutine
end program name

Measured memory_bytes: 4328
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
L = lr()
L.sort()
answer = 0
for i in range(N-1, -1, -1):
    # iが一番大きい辺
    x = L[i]
    left = 0
    right = i - 1
    while left < right:
        if L[left] + L[right] <= x:
            left += 1
            continue
        answer += (right - left)
        right -= 1

print(answer)


Measured memory_bytes: 3188
#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;  cin >> n;
  vector<ll> a(n);  rep(i,n) cin >> a[i];
  sort(a.begin(),a.end());
  cout << a[n-1]-a[0];
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cassert>
#include <vector>


using namespace std;


int main(void) {

	vector<int> v = { 0 };

	int N, M, a, b;
	unsigned int i = 0;

	cin >> N >> M;

	v.resize(N);
	
	while (M > 0) {
		cin >> a;
		cin >> b;

		v[a - 1] += 1;
		v[b - 1] += 1;
		M--;
	}

	while (v.size() > i) {
		cout << v[i] << endl;
		i++;
	}

}

Measured memory_bytes: 256