akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <queue>

using namespace std;

int main(void)
{
    int lunlun_order;

    cin >> lunlun_order;

    if(lunlun_order <= 10){
        cout << lunlun_order << endl;
        return 0;
    }

    queue<long long> lunlun_numbers;
    int lunlun_count = 0;
    int que_pos = 0;

    for(int i = 1; i <= 9; i++){
        lunlun_numbers.push(i);
    }
    lunlun_count = 9;

    while(lunlun_count < lunlun_order){
        long long seeing = lunlun_numbers.front();
        lunlun_numbers.pop();
        que_pos += 1;

        if(seeing % 10 > 0){
            lunlun_numbers.push(seeing * 10 + (seeing % 10 - 1));
            lunlun_count += 1;
        }

        lunlun_numbers.push(seeing * 10 + seeing % 10);
        lunlun_count += 1;

        if(seeing % 10 < 9){
            lunlun_numbers.push(seeing * 10 + (seeing % 10 + 1));
            lunlun_count += 1;
        }
    }

    for(int i = 0; i < lunlun_order - que_pos - 1; i++){
        lunlun_numbers.pop();
    }

    cout << lunlun_numbers.front() << endl;

    return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b; if (a >= mod) a -= mod; }


void solve();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(10);
  int T;
  T = 1;
  while (T--) solve();
}

void solve() {
  int n;
  ll k;
  cin >> n >> k;
  vector<int> a(n);
  cin >> a;
  rep(i, n) a[i]--;
  vector<vector<int> > G(n);
  rep(i, n) {
    G[i].eb(a[i]);
  }

  if (k <= 10000000) { // ループ前に終わる
    int now = 0;
    rep(i, k) now = a[now];
    cout << now + 1 << endl;
    return;
  }

  vector<int> seen(n);
  int pos = -1; // cycle 中に含まれる頂点 pos
  stack<int> hist; // 訪問履歴
  auto dfs = [&](auto&& dfs, int v, int p) -> void {
    seen[v] = 1;
    hist.push(v);
    for (auto nv : G[v]) {
      // if (nv == p) continue; directed ならいらない, undirected なら 2 頂点ループは見つけられない
      if (seen[nv] == 2) continue;
      if (seen[nv] == 1) { // cycle を検出
        pos = nv;
        return;
      }
      dfs(dfs, nv, v);
      if (pos != -1) return;
    }
    hist.pop();
    seen[v] = 2;
  };
  dfs(dfs, 0, -1);
  if (pos != -1) { // cycle
    // 経路復元, cycle に限らず
    vector<int> cycle;
    while (!hist.empty()) {
      int t = hist.top();
      cycle.eb(t);
      hist.pop();
      if (t == pos) break;
    }
    reverse(all(cycle));
    // cout << cycle << endl;

    int now = 0, cnt = 0;
    rep3(i, 1, n) {
      now = a[now];
      if (now == cycle[0]) {
        cnt = i;
        break;
      }
    }
    // cout << "cnt " << cnt << endl;

    (k = k - cnt + sz(cycle)) %= sz(cycle);
    cout << cycle[k] + 1 << endl;
  }
}


Measured memory_bytes: 26500
#include <iostream>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <stack>
#include <cstdio>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>
#include <algorithm>
#include <iterator>
#include <sstream>
#define popcount(x) __builtin_popcount(x)
#define oddparity(x) __builtin_parity(x)
#define clz(x) __builtin_clz(x)
#define ctz(x) __builtin_ctz(x)
#define sf scanf
#define pf printf
#define ll long long int
using namespace std;

int i, n, m, x, y;
vector<int>edge[51];

int main()
{
    sf("%d%d", &n, &m);
    while (m--) {
        sf("%d%d", &x, &y);
        edge[x].push_back(y);
        edge[y].push_back(x);
    }
    for (i = 1; i <= n; i++) pf("%d\n", edge[i].size());
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
/*cout <<setprecision(11)<<ret<<endl;で、数字部分を計11桁表示*/
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
//Shift+Command+bでデバッグ
//その後ターミナルで./a.outを実行
//入力を貼り付ける

//////////////////
//  A
int main(void){
    vector<int> a(3);
    cin>>a[0]>>a[1]>>a[2];

    sort(a.begin(),a.end());

    cout<<a[0]+a[1]<<endl;
    return 0;
}
//////////////////
//  B
/*int main(void){

    return 0;
}*/
//////////////////
//  C
/*int main(void){

    return 0;
}*/
//////////////////
//  D
/*int main(void){

    return 0;
}*/
//////////////////
//  E
/*int main(void){

    return 0;
}*/
//////////////////
//  F
/*int main(void){

    return 0;
}*/


Measured memory_bytes: 3600
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <cmath>
#include <stack>

using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}


void solve(long long N, long long M, std::vector<long long> L, std::vector<long long> R){
  vector<ll> v(N+2, 0);
  ll ans = 0;
  for(ll i=0; i<M; i++) {
    v[L[i]]++;
    v[R[i]+1]--;
  }
  
  for(ll i=1; i<N+2; i++) {
    v[i] += v[i-1];
    if(v[i]==M) ans++;
  }
  std::cout << ans << std::endl;
}

int main(){
  long long N;
  scanf("%lld",&N);
  long long M;
  scanf("%lld",&M);
  std::vector<long long> L(M);
  std::vector<long long> R(M);
  for(int i = 0 ; i < M ; i++){
    scanf("%lld",&L[i]);
    scanf("%lld",&R[i]);
  }
  solve(N, M, std::move(L), std::move(R));
  return 0;
}



Measured memory_bytes: 2560
N = int(input())
A = list(map(int, input().split()))

if A.count(0) > 0:
    print(0)
else:
    ans = A[0]
    for i in range(1, N):
        ans = ans * A[i]
        if ans > 10**18:
            ans = -1
            break

    print(ans)


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

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef long double ld;

const ll mod = (ll)1e9 + 7;
const ll mxN = 200200;




int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(20);
	cout << fixed;

	ll a,b,c;
	cin>>a>>b>>c;
	if(a&1 || b&1 || c&1) {cout<<0<<"\n";return 0;}
	if(a==b && c==a) {cout<<-1<<"\n";return 0;}
	ll co=0;
	while(1){
		if(a&1 || b&1 || c&1)
			break;
		ll x = (c+b)/2,y=(a+c)/2,z=(a+b)/2;
		a=x,b=y,c=z;
		co++;
	}
	cout<<co;

}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define forn(i, n)             for(int i = 0; i < n; i ++)
#define forn1(i, n)            for(int i = 1; i <= n; i ++)
#define pb push_back
#define ll long long int
#define fi first
#define se second
#define ii  pair<long long int, long long int>
#define vi  vector <long long int>
#define vii vector <pair <long long int, long long int > >
#define all(cont)  cont.begin(), cont.end()
#define EPS 1e-9
#define MOD 1000000007
#define range 
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#pragma GCC optimize ("Ofast")
int main(){

   // freopen("input.txt","r",stdin);
    IOS;
    clock_t clk = clock();
    int n;
    cin>>n;
    int a[n], b[n], c[n];
    forn(i,n)    cin>>a[i];
    forn(i,n)    cin>>b[i];
    forn(i, n-1) cin>>c[i];
    ll ans = 0;
    
    forn(i,n)ans += b[i];
    forn1(i, n-1){
    		if(a[i] - a[i-1] == 1){
    			ans += c[a[i]-2];
    		}
    }

    cout<<ans;

    cerr << endl << setprecision(10) << fixed << (double)(clock() - clk) / CLOCKS_PER_SEC;
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import static java.lang.Integer.parseInt;

/**
 * Refreshment Area
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		words = br.readLine().split(" ");

		int N, M, D;
		N = parseInt(words[0]);
		M = parseInt(words[1]);
		D = parseInt(words[2]);

		int[][] map = new int[N][M];
		int[][] mapH = new int[N][M];
		int[][] mapV = new int[N][M];

		for (int i = 0; i < N; i++) {
			line = br.readLine();
			for (int j = 0; j < M; j++) {
				if (line.charAt(j) == '.') {
					mapH[i][j] = mapV[i][j] = map[i][j] = 1;
				}
			}
		}

		//sum
		for (int i = 0; i < N; i++) {
			for (int j = 1; j < M; j++) {
				if (map[i][j] != 0) mapH[i][j] += mapH[i][j - 1];
			}
		}

		for (int i = 1; i < N; i++) {
			for (int j = 0; j < M; j++) {
				if (map[i][j] != 0) mapV[i][j] += mapV[i - 1][j];
			}
		}

		//solve
		int count = 0;

		for (int i = 0; i < N; i++) {
			for (int j = 0, _j = j + D - 1; _j < M; j++, _j++) {
				if (map[i][j] != 0 && mapH[i][_j] - mapH[i][j] == D - 1) count++;
			}
		}

		for (int i = 0, _i = i + D - 1; _i < N; i++, _i++) {
			for (int j = 0; j < M; j++) {
				if (map[i][j] != 0 && mapV[_i][j] - mapV[i][j] == D - 1) count++;
			}
		}

		System.out.println(count);

	}
}

Measured memory_bytes: 24772
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef double db;
typedef vector <ll> vll;
typedef pair <ll, ll> pll;
#define pb push_back
#define mp make_pair
#define MAX 1000000
#define mod 1000000007
#define all(_) _.begin(), _.end()
#define F first
#define S second
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    ll n, m, i, sum = 0;
    cin >> n >> m;
    vll a(n);
    for(i = 0; i < n; i++)
        cin >> a[i], sum += a[i];
    ll x = 0;
    for(auto y : a)
        x += ((4 * m * y >= sum) ? 1 : 0);
    cout << (x >= m ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>


int main (int argc, char const *argv[])
{
    int64_t N, V[20], C[20];
    int64_t ans = 0;

    scanf("%"PRId64, &N);
    for (int i = 0; i < N; i++) {
        scanf("%"PRId64, &V[i]);
    }
    for (int i = 0; i < N; i++) {
        scanf("%"PRId64, &C[i]);
    }

    for (int i = 0; i < N; i++) {
        if (V[i] > C[i]) ans += V[i] - C[i];
    }
    
    printf("%"PRId64"\n", ans);
}


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

int main() {
	std::string s;
	std::cin >> s;
	int i = std::stoi(s);

	if (i % 2 == 0) {
		std::cout << i << std::endl;
	}
	else {
		std::cout << i * 2 << std::endl;
	}
}

Measured memory_bytes: 256
num = input()
list = input().split()

ans = 0

for i in range(int(num) - 1):
    n1 = int(list[i])
    n2 = int(list[i+1])

    if  n1 > n2 :
        ans += (n1 - n2)
        list[i+1] = list[i]
    else:
        ans += 0

print(ans)

Measured memory_bytes: 24992
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define all(t) t.begin(), t.end()
#define inrange(i, a, b) (((i)>= min((a), (b))) && ((i) <= max((a), (b))))
typedef vector<ll> vi;
typedef pair<ll, ll> pii;
#define fi first
#define se second
#define show(x) cout << #x << " is " << x << "\n";
const ll inf = 2e18;
const ll mod = 1e9 + 7;
const ld pi = 3.141592653589793238462643383279502884;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void print(ll a[], ll n){for(ll i=0;i<n;i++){cout<<a[i]<<" ";}cout<<"\n";}
ll power(ll x, ll y, ll M = inf){
	if(y<=0) return 1;
    ll ans = 1;
    x %= M;
    while(y){
        if(y&1)
            ans = (x * ans) % M;

        x = (x * x) % M;
        y >>= 1;
    }
    return ans;
}
ll modInverse(ll n) {return power(n, mod-2, mod);}
inline ll mul(ll a, ll b){ return (a * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c >= mod) c -= mod; return c; }
inline ll divi(ll a, ll b){ return mul(a, modInverse(b)); }

//------------------------------------------------------------------------------------------

//const ll N = 1e5 + 1;
//vector<ll> adj[N];
//bool visited[N];

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

	string s, t;
	cin>>s>>t;
	ll c=0;
	for(int i=0;i<s.size();i++){
		if(s[i]!=t[i]) c++;
	}
	cout<<c;


    return 0;
}


Measured memory_bytes: 3816
#!/usr/bin/ruby

require 'pp'

N = gets.chomp.to_i


map = {}

1.upto(N){|i|
  s = gets.chomp
  if map[s] == nil
    map[s] = 1
  else
    map[s]+=1
  end
}


result = map.sort_by{|k,v| [-v, k]}

c = result[0][1]
result.each{|e|
  if c == e[1]
    puts e[0]
  else
    break
  end
}



Measured memory_bytes: 47812
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
ans = sum(b)
for i in range(len(a)-1):
  if(a[i]+1==a[i+1]):
    ans+=c[a[i]-1]
print(ans)

Measured memory_bytes: 3064
inputstr1 = [int(input()) for _ in range(6)]

s = []
for i in range(1, 6):
    s.append(inputstr1[i])
ss = sorted(s)

if ss[0] == 1:
    maxtime = inputstr1[0] // ss[0] - 1
elif inputstr1[0] > ss[0]:
    maxtime = inputstr1[0] // ss[0]
else:
    maxtime = 0
print(maxtime + 5)


Measured memory_bytes: 3060
f :: Int->Bool
f 0 = True
f n | n < 0 = False
f n = f (n - 4) || f (n - 7)
main :: IO ()
main = do
    [a] <- words <$> getLine
    let n = read a :: Int
        r = case n `mod` 28 of
            0 -> True
            4 -> True
            8 -> True
            12 -> True
            16 -> True
            20 -> True
            24 -> True
            7 -> True
            14 -> True
            21 -> True
            11 -> True
            15 -> True
            19 -> True
            23 -> True
            27 -> True
            18 -> True
            22 -> True
            25 -> True
            26 -> True
            _ -> False

    putStrLn $ (if r then "Yes" else "No") where


Measured memory_bytes: 508
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 X = sc.nextInt();
		int Y = sc.nextInt();
		int[] x = new int[n];
		int[] y = new int[m];
		for(int i = 0; i < n; i++) x[i] = sc.nextInt();
		for(int i = 0; i < m; i++) y[i] = sc.nextInt();
		int maxx = -101;
		int miny = 101;
		for(int i = 0; i < n; i++) maxx = Math.max(maxx, x[i]);
		for(int i = 0; i < m; i++) miny = Math.min(miny, y[i]);
//		System.out.println(maxx);
//		System.out.println(miny);
		for(int i = -100; i <= 100; i++) {
			if(maxx < i && i <= miny && X < i && i <= Y) {
				System.out.println("No War");
				return;
			}
		}
		System.out.println("War");
	}
}


Measured memory_bytes: 23636
#include<iostream>

using namespace std;

int main()
{
    int W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;
    if(r + x <= W && x - r >= 0 && r + y <= H && y - r >= 0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

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

#define pb push_back
#define fi first
#define se second
#define ll long long
#define pq priority_queue
#define mp make_pair
#define pii pair<int,int>
#define mod 998244353

int lowbit(int x) {return x&(-x);}

int n;
struct node{
	int s,w,v;
}a[1010];

ll f[30010];

bool com(node a,node b) {
	return -a.w+b.w>-b.s+a.s;
} 

int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d%d%d",&a[i].w,&a[i].s,&a[i].v);
	sort(a+1,a+n+1,com);
	ll ans=0ll;
	for (int i=1;i<=n;i++)
		for (int j=a[i].s;j>=0;j--) {
			f[j+a[i].w]=max(f[j+a[i].w],f[j]+(ll)a[i].v);
			ans=max(ans,f[j+a[i].w]);
		}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
const ll INF = 1e18;
#define print(x) cout << (x) << endl;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll r, D, x;
    cin >> r >> D >> x;
    for (int i = 0; i < 10; i++) {
        x = r * x - D;
        print(x);
    }
}

Measured memory_bytes: 384
import java.util.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;
	
	void run() {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
			String str = sc.next();
			int[] num = new int[9];
			for(int i=0;i<13;i++) num[str.charAt(i)-'0'-1]++;
			LinkedList<Integer> list = new LinkedList<Integer>();
			for(int i=0;i<9;i++) {
				int[] tmp = num.clone();
				if(tmp[i] == 4) continue;
				tmp[i]++;
				if(solve(tmp, 0, false)) list.add(i);
			}
			if(list.isEmpty()) System.out.println(0);
			else {
				System.out.print((list.get(0)+1));
				for(int i=1;i<list.size();i++) {
					System.out.print(" " + (list.get(i)+1));
				}
				System.out.println();
			}
			
		}
	}
	
	boolean solve(int[] num, int i, boolean flg) {
		if( i== 9 ) return true;
		if( num[i] == 0 ) return solve(num, i+1, flg);
		if( num[i] >= 3 ) {
			num[i] -= 3;
			if(solve(num, i, flg)) return true;
			num[i] += 3;
		}
		if(!flg && num[i] >= 2) {
			num[i] -= 2;
			if(solve(num, i, true)) return true;
			num[i] += 2;
		}
		if( i < 7 && num[i] >= 1 && num[i+1] >= 1 && num[i+2] >= 1) {
			num[i]--; num[i+1]--; num[i+2]--;
			if(solve(num, i, flg)) return true;
			num[i]++; num[i+1]++; num[i+2]++;
		}
		return false;
	}
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 0
chop($s=<>=~y/?/./r);chop($t=<>);$a=UNRESTORABLE;$p=substr($s,$_,$m=length$t),$t=~/^$p$/?$a=substr($s,0,$_).$t.substr($s,$_+$m):0for 0..length$s;print$a=~y/./a/r

Measured memory_bytes: 512
// package app;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {

    public static void main(final String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);

        long H = sc.nextLong();
        long N = sc.nextLong();

        boolean exceedHP = false;
        long score = 0;
        for (int i = 0; i < N; i++) {
            score += sc.nextLong();
            if (H <= score) {
                exceedHP = true;
                break;
            }
        }

        System.out.println(exceedHP ? "Yes" : "No");



    }
}

Measured memory_bytes: 48296
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
  int n,l;
  cin >> n >> l;
  vector<string> s(n);
  for(int i=0;i<n;i++){
    cin >> s.at(i);
  }
  sort(s.begin(),s.end());
  string t;
  for(int i=0;i<n;i++){
    t += s.at(i);
  }
  cout << t << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>  // include all standard C++ libraries

using namespace std;

// Loops
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define _rrep(i,n) rrepi(i,n,0)
#define rrepi(i,a,b) for(int i=int(a)-1;i>=int(b);--i)

#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(xi, x) for (auto&& xi : x)
// Note: we can use rep(i,N) or rep(i,from,to)


// typedef
using ll = long long;
template <class T> using vec = vector<T>;
using vi   = vector<int>;
using vvi  = vector<vi>;
using vvvi = vector<vvi>;
using pii  = pair<int, int>;


// Constants
#define INF 1e9

// Algorithms
#define all(x) (x).begin(), (x).end()
#define uniq(v) v.erase( unique(all(v)), v.end() )
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<class T> inline bool chmax(T &maxval, const T &newval) { if (maxval<newval) { maxval=newval; return 1; } return 0; }
template<class T> inline bool chmin(T &minval, const T &newval) { if (minval<newval) { minval=newval; return 1; } return 0; }

// Utilities
// Moving in a grid world (NESW)
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};

inline int in() {int x; cin >> x; return x;} // read int from cin
inline  ll IN() {ll x; cin >> x; return x;}  // read ll from cin


// Shorter repr for frequently used terms
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second

// Debug
#ifdef LOCAL
  #include "dump.hpp"
  #define debug(x) cerr << #x << ": " << x << '\n'
#else
  #define dump(...)
  #define debug(x)
#endif

// Paste snippets here!!

// 

int main(){
  cin.tie(0); ios::sync_with_stdio(false);    // Magic for faster cin

  int N=in(); int M=in();
  vec<pair<ll,ll>> AB(N);
  rep(i,N){
    cin >> AB[i].Fi >> AB[i].Se;
  }
  
  sort(all(AB));

  ll money = 0;
  ll drinks = 0;
  rep(i,N){
    if(drinks+AB[i].Se>=M){
      money += AB[i].Fi * (M-drinks);
      drinks = M;
      break;
    } else {
      money += AB[i].Fi * AB[i].Se;
      drinks += AB[i].Se;
    }
  }
  cout << money << endl;

  return 0;
}


Measured memory_bytes: 1792
#define _USE_MATH_DEFINES
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<stdbool.h>
#include<math.h>
#include<sstream>
#include<math.h>
#include<vector>
#include<functional>
#include<queue>
#include<utility>
#include<bitset>
typedef long long ll;
#define N (1000000000+7)
#define INF 1e10
using namespace std;
typedef pair<ll, ll> P;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

ll sum[200010];
ll x[200010];
int main(void){
	ll n,ans = 0;
	cin >> n;
	sum[0] = 0;
	for (ll i = 1;i <= n;i++) {
		cin >> x[i];
		sum[i] = sum[i - 1] + x[i];
	}
	ll right = 1, xor_sum = x[1];
	for (ll left = 1; left <= n; left++) {
		while (right <= n && (xor_sum==sum[right]-sum[left-1])) {
			right++;
			xor_sum ^= x[right];
		}
		ans += right - left;
		xor_sum ^= x[left];
		if (left == right) {   // leftがrightに追いついたら
			right++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3328
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		String str="";
		int sets=0;
		int[] rui=new int[3];
		rui[0]=0;
		rui[1]=0;
		rui[2]=0;
		sets=sc.nextInt();
		String[] stat=new String[5000];
		int outs=0;int counts=0;
		while(outs<3*sets) {
			stat[counts]=sc.next();
			if(stat[counts].equals("OUT")) {
				outs++;
				if(outs==sets*3) {break;}
			}
			counts++;
		}
		int ten=0;
		int ot=0;
		for(int i=0; i<=counts; i++) {
			if(stat[i].equals("HIT")) {
				if(rui[2]==1) {
					ten++;
				}
				rui[2]=rui[1];
				rui[1]=rui[0];
				rui[0]=1;
			}
			else if(stat[i].equals("HOMERUN")) {
				ten++;
				ten+=rui[0];
				ten+=rui[1];
				ten+=rui[2];
				rui[0]=0;
				rui[1]=0;
				rui[2]=0;
			}
			else if(stat[i].equals("OUT")) {
				ot++;
				if(ot==3) {
					System.out.println(ten);
					ot=0;
					ten=0;
					rui[0]=0;
					rui[1]=0;
					rui[2]=0;
				}
			}
			sc.close();
		}
	}
}


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

int main() {

    int n, k, d, a;
    cin >> n >> k;

    bool snack[n] = {false};

    for (int i = 0; i < k; i++) {
        cin >> d;
        for (int j = 0; j < d; j++) {
            cin >> a;
            snack[a - 1] = true;
        }
    }

    int c = 0;
    for (int i = 0; i < n; i++) {
        if (!snack[i])
            c++;
    }

    cout << c;

    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
const ll E=1e18+7;
const ll MOD=1000000007;

void insert(vector<ll> &A,ll g,ll &count){
    for(ll i=g;i<A.size();i++){
        ll v=A[i];
        ll j=i-g;
        while(j>=0 && A[j]>v){
            A[j+g]=A[j];
            j-=g;
            count++;
        }
        A[j+g]=v;
    }
}

vector<ll> G;

ll shell(vector<ll> &A){
    ll count=0;
    for(ll i=0;i<G.size();i++){
        insert(A,G[i],count);
    }
    return count;
}


int main(){
    ll n;
    cin>>n;
    vector<ll> a(n);
    for(int i=0;i<n;i++){cin>>a[i];}
    G={1};
    for(int i=0;G[i]*2+1<n;i++){
        G.push_back(G[i]*2+1);
    }
    reverse(G.begin(),G.end());
    ll count=shell(a);
    cout<<G.size()<<endl;
    for(int i=0;i<G.size();i++){
        cout<<G[i];
        if(i+1!=G.size()){cout<<" ";}
    }
    cout<<endl<<count<<endl;;
    for(int i=0;i<n;i++){
        cout<<a[i]<<endl;
    }
    
    
    return 0;
}


Measured memory_bytes: 10668
//{{{
#include <bits/stdc++.h>
using namespace std;
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop,~))(__VA_ARGS__)
#define loop(n) rep2(_loop_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define repN(a) repX a
#define repX(a0,a1,a2,x,...) x
#define foreach(x,a) for(auto &x:a)
typedef long long ll;
const int MOD = 1e9+7;
//}}}

int main(){
  int N, M, X;
  cin >> N >> M >> X;
  set<int> st;
  rep(i, M){
    int A;
    cin >> A;
    st.insert(A);
  }
  int a = 0;
  int b = 0;
  rep(i, 1, X + 1) if(st.count(i)) a++;
  rep(i, X, N) if(st.count(i)) b++;
  cout << (min(a, b)) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

#define VECTOR_LIMIT (55)

int main() {
	char s1[VECTOR_LIMIT] = { 0 }, s2[VECTOR_LIMIT] = { 0 };
	int n, i;
	long long res=1;
	bool bVecNow, bVecLeft;

	cin >> n;

	for (i = 0; i < n; i++) { cin >> s1[i]; }
	for (i = 0; i < n; i++) { cin >> s2[i]; }


	for (i = 0; i < n; i++) {
		bVecNow = (s1[i] == s2[i]);
		if (i == 0) {
			if (bVecNow) {res *= 3;}
			else {res *= 6;i++;}
			continue;
		}

		bVecLeft = (s1[i - 1] == s2[i - 1]);
		if (bVecNow) {//当前是竖块
			if (bVecLeft) {
				res *= 2;
			} else {
				res *= 1;
			}
			res %= 1000000007;
		} else {//当前是横块
			if (bVecLeft) {
				res *= 2;
			} else {
				res *= 3;
			}
			i++;
			res %= 1000000007;
		}
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
while True:
	n, x = map(int, input().split())
	if n == x == 0: break

	ans = 0
	for a in range(1, n+1):
		for b in range(a+1, n+1):
			for c in range(b+1, n+1):
				if a + b + c == x:
					ans += 1
	print(ans)

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  __MAKE_TIME__  Problem: __PROBLEM__ / Link: __CONTEST_URL__  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */


int read() { int in; scanf("%d", &in); return in; }
int main() {
	int N = read();
	VI a(N);
	FOR(i, 0, N) {
		a[i] = read();
	}
	int sum = accumulate(ALL(a), 0);
	const int sz = 2000 * 2000 + 1;
	bitset<sz>bit;
	bit[0] = 1;
	FOR(i, 0, N) {
		bit |= bit << a[i];
	}
	int mid = (sum + 1) / 2;
	FOR(i, mid, sz) {
		if (bit[i]) {
			cout << i << endl;
			return 0;
		}
	}

	return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define pii pair<int,int>
#define F first
#define S second
#define mp make_pair
using namespace std;
const int N=1e5+5;
long long ans=0;
int n,ji;
pii p[N];
bool who=true;
inline bool cmp(pii a,pii b)
{
	if(a.F+a.S!=b.F+b.S)return a.F+a.S>b.F+b.S;
	if(a.F!=b.F)return a.F>b.F;
	return a.S>b.S;
}
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>p[i].F>>p[i].S;
	sort(p,p+n,cmp);
	ji=0;
	for(int i=0;i<n;i++)
	{
		if(who)
			ans+=p[ji].F,ji++;
		else
			ans-=p[ji].S,ji++;
		who=!who;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
using namespace std;
 
#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define RSORT(x) sort((x).rbegin(),(x).rend())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
#define chmax(x,y) x = max(x,y)

 
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int> > VVI;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<bool> VB;
typedef vector<LL> VL;
typedef vector<vector<long long>> VVLL;
typedef vector<set<int>> VSI;
const int MOD = 1e9+7;
const int INF = 1e9;
const LL LINF = 1e18;
int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

int lcm(int a, int b)
{
   return a * b / gcd(a, b);
}
struct UnionFind {
    VI d;
    UnionFind(int n = 0): d(n,-1) {}
    int find(int x) {
        if(d[x] < 0) return x;
        return d[x] = find(d[x]);
    }
    bool unite(int x,int y) {
        x = find(x); y = find(y);
        if(x == y) return false;
        if(d[x] > d[y]) swap(x,y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x,int y) { return find(x) == find(y); }
    int size(int x) { return -d[find(x)]; }
};
int deg[100005];
VI to[100005];

struct mint {
  LL x; // typedef long long ll;
  mint(LL x=0):x((x%MOD+MOD)%MOD){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD-a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(LL t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(MOD-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

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

mint choose(int n,int a) {
    mint x = 1, y = 1;
    rep(i,a) {
        x *= n-i;
        y *= i+1;
    }
    return x/y;
}

int main() {
    int n,k;
    cin >> n >> k;
    VI a(n);
    rep(i,k) {
      int d;
      cin >> d;
      int tmp;
      rep(j,d) {
        cin >> tmp;
        a[tmp-1]++;
      }
    }
    int ans = 0;
    rep(i,n) {
      if(a[i] == 0) ans++; 
    }
    cout << ans << endl;
}


Measured memory_bytes: 5948
#include<bits/stdc++.h>
using namespace std;
int main()
{
        ios::sync_with_stdio(0);
        cin.tie(0);
        int n{0},m{0};
        cin>>n>>m;
        vector<int> arr(n);
        vector<bool> ans(n);
        for(int i = 0;i<m;i++)
        {
                int t;
                string s;
                cin>>t>>s;
                t--;
                if(ans[t] == true && s == "WA")
                        continue;
                else if(ans[t] == false && s == "WA")
                        arr[t]++;
                else if(ans[t] == true && s == "AC")
                        continue;
                else
                {
                        ans[t] = true;
                }
        }
        int s{0};
        for(auto it : ans)
                if(it)
                        s++;
        cout<<s<<' ';
        s = 0;
        for(int i = 0;i<n;i++)
        {
                if(ans[i] == true)
                s+= arr[i];
        }
        cout<<s;


return 0;
}



Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long a,b,c,d=0,e,f,g,h;
//vector<long long>mp;

cin>>a>>b;
for(long long i=1;i<=b;i++)
{
    cin>>c;
    d=d+c;
}
if(d>a)
    cout<<"-1";
else cout<<a-d;




}


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

vector<int> color;

struct edge {
    int to;
    int id;
};

vector<vector<edge>> tree;

void dfs(int now,int par,int ban) {
    int nc = 0;
    for(auto e : tree[now]) {
        if(e.to == par) continue;
        if(nc == ban) nc++;
        color[e.id] = nc;
        nc++;
        dfs(e.to,now,color[e.id]);
    }
}

int main() {
    int n;
    cin >> n;
    tree.resize(n);
    color.resize(n-1);
    rep(i,n-1) color[i] = inf;
    rep(i,n-1) {
        int a,b;
        cin >> a >> b;
        a--; b--;
        tree[a].push_back(edge{b,i});
        tree[b].push_back(edge{a,i});
    }
    int sum = 0;
    rep(i,n) {
        if(sum < tree[i].size()) sum = tree[i].size();
    }
    dfs(0,-1,-1);
    cout << sum << endl;
    rep(i,n-1) cout << color[i]+1 << endl;
}

Measured memory_bytes: 8320
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
const int maxn = 1e3+7;
int A[maxn],B[maxn];
long long dp[10007];
int h,n;
const int inf = 1e9;
int main()
{
    cin>>h>>n;
    for(int i=1;i<=n;++i)cin>>A[i]>>B[i];
    for(int i=1;i<=h;++i)dp[i] = inf;
    for(int i=1;i<=h;++i)
    {
        for(int j=1;j<=n;++j)
        {
            int x = i - A[j];
            if( x < 0 ) x = 0;
            dp[i] = min(dp[i],dp[x]+B[j]);
        }
    }
    cout<<dp[h]<<endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <math.h>
#include <vector>
#include <iomanip>
#include <limits>
#include <map>
using namespace std;

int main()
{
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        if (i % 3 == 0 || i % 10 == 3)
        {
            cout << " " << i;
            continue;
        }
        int s = i;
        while (s > 10)
        {
            s = s / 10;
            if (s % 10 == 3)
            {
                cout << " " << i;
                break;
            }
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f(i,n) for(ll i=0;i<n;i++)
#define pb push_back
int mod=1e9+7;
int gcd (int a, int b) {
   while (b) {
        a %= b;
        swap(a, b);
    }
    return a;
}
ll fast(ll a,ll n){
	a%=mod;
	ll res=1;
	while(n>0){
		if(n&1)res=res*a%mod;
		a=a*a%mod;
		n>>=1;
	}
	return res;
}
int digit_sum(int a){
	int sum=0;
	while(a){
		sum+=a%10;
		a/=10;
	}
	return sum;
}
	// vector<int> v;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,k;
	cin>>n;
	// vector<vector<int> >a(n,vector<int>(3,0));
	int a[n][3];
	for(int i=0;i<n;i++)cin>>a[i][0]>>a[i][1]>>a[i][2];
	// vector<vector<int>> dp(n,vector<int>(2,INT_MAX));
	// func(a,dp,i,j);
	for(int i=n-2;i>=0;i--){
		for(int j=0;j<3;j++){
			a[i][j]=a[i][j]+max(a[i+1][(j+1)%3],a[i+1][(j+2)%3]);
		}
	}
	cout<<max(a[0][0],max(a[0][1],a[0][2]))<<endl;
	return 0;
}



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

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const int INF = 1 << 30;
const ll INFL = 1LL << 60;


class Solver {
  public:
    bool solve() {
        int H, W, N; cin >> H >> W >> N;
        int Sr, Sc; cin >> Sr >> Sc;
        Sr--; Sc--;
        string S, T; cin >> S >> T;

        string SD = "LRUD";
        string TD = "RLDU";
        bool exitable = false;

        rep(c, 4) {
            const char sd = SD[c], td = TD[c];

            vector<int> max_movable(N + 1);
            int movable = 0;
            for(int i = N - 1; i >=0 ;i--) {
                movable += S[i] == td;
                max_movable[i] = max(max_movable[i + 1], movable);
                movable -= T[i] == sd;
            }

            int need;
            if(c == 0) {
                need = Sc + 1;
            } else if (c == 1) {
                need = W - Sc;
            } else if (c == 2) {
                need = Sr + 1;
            } else if (c == 3) {
                need = H - Sr;
            } else assert(0);
            int sup = c < 2 ? W : H;
            rep(i, N) {
                if(S[i] == sd) need--;
                exitable |= need == 0;
                if(T[i] == td and need + max_movable[i] < sup) need++;
            }
        }
        cout << (not exitable ? "YES" : "NO") << endl;

        return 0;
    }
};

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


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

int     main() {
        long N;
        cin >>N;
        if (N<10) {
                cout <<N <<endl;
                return 0;
        } else if (N<100) {
                cout <<9 <<endl;
                return 0;
        } else if (N<1000) {
                cout << (N-90) <<endl;
                return 0;
        } else if (N<10000) {
                cout << 909 <<endl;
                return 0;
        } else if (N<100000) {
                cout << (N-9999+909) << endl;
                return 0;
        }
        cout << 90909 << endl;
        return 0;
};

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<long long,long long>;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);++i)
#define FORE(x,c) for(auto &x:c)
#define FOR(i,a,n) for(int i=a,i##_len=(int)n;i<i##_len;++i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i=((int)(n)-1);i>=0;--i)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define SZ(c) ((int)c.size())
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0}, DY[9]={-1,0,1,0,-1,1,1,-1,0};
const int INF=1e9*2; const long long INFLL=1e18*2;
template<class T> ostream& operator << (ostream &os, const vector<T> &v) {
    ITR(i,v) os << *i << (i==end(v)-1 ? "" : " "); return os; }
template<class T> istream& operator >> (istream &is, vector<T> &v) {
    ITR(i,v) is >> * i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
        is >> p.second >> p.first; return is; }
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;}
//------------------------------------------------------------------------------

// 10分
signed main() {
    int N,x;
    cin>>N>>x;
    vi a(N);
    cin>>a;
    int ans=0;
    REP(i,N-1) {
        int sum=a[i]+a[i+1];
        int t=sum-x;
        if(t<=0) continue;
        if(a[i+1]<t) a[i+1]=0;
        else a[i+1]-=t;
        ans+=t;
    }
    cout<<ans<<endl;
    return 0;
}


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

int main()
{
int x;
cin>>x;
int sum=0;
vector<int> a(x);
for(int i=0;i<x;i++)
{
    cin>>a[i];
}
sort(a.begin(),a.end());
for(int k=0;k<x-1;k++)
{
    sum=sum+a[k];
}
if(sum>a[x-1]) cout<<"Yes"<<endl;
else cout<<"No"<<endl;



  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    while(1){
        int x,y;
        cin>>x>>y;
        if((x==0)&&(y==0))break;
        if(x<y){
            cout<<x<<" "<<y<<endl;
        }else{
            cout<<y<<" "<<x<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 2976
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1000000007;
#define rep1(i, n) for (ll i=0; i<(n); i++) 
#define rep2(i, k, n) for (ll i=k; i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() {
    ll n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    ll c = 0;
    ll ans = 1;
    bool pat = true;
    while (c<n){
        if (c==0){
            if (s[c]==t[c]){
                ans *= 3;
                pat = false;
                c++;
            }
            else{
                ans *= 6;
                pat = true;
                c += 2;
            }
        }
        else if (pat){
            if (s[c]==t[c]){
                ans *= 1;
                pat = false;
                c++;
            }
            else{
                ans *= 3;
                pat = true;
                c += 2;
            }
        }
        else{
            if (s[c]==t[c]){
                ans *= 2;
                pat = false;
                c++;
            }
            else{
                ans *= 2;
                pat = true;
                c += 2;
            }
        }
        ans %= MOD;
    }
    cout << ans << endl;
    //printf("%.12f", ans);
}

Measured memory_bytes: 3592
import java.util.*;
public class Main{
  public static void main(String[] args){
   	Scanner sc = new Scanner(System.in);
	String S = sc.next();
    int N = S.length();
    int min = 753;
   	for(int i = 0;i<N-2;i++)
   {
	    if(Math.abs(753-Integer.valueOf(S.substring(i,i+3)))<min) min = Math.abs(753-Integer.valueOf(S.substring(i,i+3)));
   }
   	System.out.println(min);
 }
}

Measured memory_bytes: 23764
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,a,b,c=map(int,input().split())
    L=[int(input()) for _ in range(n)]

    def dfs(v,Idx)->int:
        # terminate condition
        if(v==n):
            score=0
            Idx=tuple(Idx)
            A,B,C=[],[],[]
            for i,k in enumerate(Idx):
                if(k==0): A.append(L[i])
                elif(k==1): B.append(L[i])
                elif(k==2): C.append(L[i])
            if((not A) or (not B) or (not C)): return INF # 1つも竹が無いのはダメ
            score+=(len(A)+len(B)+len(C)-3)*10

            SA=sum(A)
            SB=sum(B)
            SC=sum(C)
            score+=abs(SA-a)
            score+=abs(SB-b)
            score+=abs(SC-c)

            return score

        res=INF
        for i in range(4):
            res=min(res,dfs(v+1,Idx+[i]))
        return res

    print(dfs(0,[]))
resolve()

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

using namespace std;
using ll = long long;

int main() {
    int N = 0;
    cin >> N;
    int K; 
    cin >> K;
    vector<int> A(N + 1,0);
    for(int i = 0; i < N; i++) {
        cin >> A.at(i + 1);
    }
    for(int i = 1; i < N; i++) {
        A.at(i + 1) += A.at(i);
    }
    int ans = 0;
    for(int i = 0; i < N - K + 1; i++) {
        ans = max(ans, A.at(i + K) - A.at(i));
    }
    cout << fixed << setprecision(15) << (double)(ans + K)/2 << endl;
    


    return 0;
}

Measured memory_bytes: 4032
#include <bits/stdc++.h>
using namespace std;
int n,c,len[110],p[110];
typedef long long ll;
ll f[61*6][1<<5],ans;

inline void solve()
{
	for(int i=0;i<=n*c;i++)
		for(int j=0;j<1<<(n-1);j++)
			f[i][j] = 0;
	f[n*len[n-1]][0] = 1;
	for(int i=1;i<n*c;i++)
		for(int j=i;j<=n*c;j++)
			for(int k=0;k<1<<(n-1);k++)if(i%n && !((k>>p[i%n-1])&1)){
				f[min(n*c, max(j, i + n * len[p[i%n-1]]))][k | (1<<p[i%n-1])] += f[j][k];
			}
	ans += f[n*c][(1<<(n-1))-1];
}

int main()
{
	cin >> n >> c;
	for(int i=0;i<n;i++)scanf("%d",&len[i]);
	sort(len, len+n);
	ll cnt = 0;
	for(int i=0;i<n-1;i++)p[i]=i;
	do{
		solve();
		cnt ++;
	}while(next_permutation(p,p+n-1));
	for(int i=0;i<n-1;i++)cnt*=c;
	printf("%.16Lf\n",(long double)ans / (long double)cnt);
}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

long long inv(long long n) {
    long long res = 1;
    while (n > 1) {
        res *= (MOD - MOD/n);
        res %= MOD;
        n = MOD % n;
    }
    return res;
}

long long comb_mod(long long n, long long r) {
    long long nume = 1;
    long long deno = 1;
    long long r_new = (r <= n/2) ? r : n-r;
    if (r_new < 0) {
        return 0;
    } else if (r_new == 0) {
        return 1;
    }

    for (long long i=1; i<=r_new; i++) {
        deno *= i % MOD;
        deno %= MOD;
    }
    for (long long i=n-r_new+1; i<=n; i++) {
        nume *= i % MOD;
        nume %= MOD;
    }
    deno = inv(deno);
    return (deno * nume) % MOD;
}

ll sum(int i, int j) {
    ll res = comb_mod(i+j+2, i+1) - 1;
    res %= MOD;
    if (res < 0) res += MOD;
    return res;
}

void solve() {
    ll r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;

    ll res = sum(r2, c2) - sum(r2, c1-1) - sum(r1-1, c2) + sum(r1-1, c1-1);
    res %= MOD;
    if (res < 0) res += MOD;
    cout << res << '\n';
}

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

    solve();

    return 0;
}


Measured memory_bytes: 256