akhauriyash/Code-Regression huggingface dataset:
var stdin = require("fs").readFileSync("/dev/stdin", "utf8");

//console.log(stdin)
var a =  stdin.split(" ")

 var dis=Number(a[0])
 var time=Number(a[1])
 var speed=Number(a[2])

//cal by min
const cal=(dis,speed)=>{
  var result = dis/speed
  return result
}

if (cal(dis,speed)>time){

  console.log('No');
}
else{
  console.log('Yes');

}


Measured memory_bytes: 30240
#include <stdio.h>
int main()
{
  int n;
  scanf("%d",&n);
  int i = 0;
  char s[n][2];
  char buf[256] = {0};
  while (i < n)
  {
    scanf("%s",&s[i]);
    //printf("%s",s[i]);
    //printf("%c",s[i][0]);
    buf[s[i][0]]++;
    i++;
  }
  i = 0;
  int cnt = 0;
  //printf("%d\n",i);
  i = 0;
  while (i < 256)
  {
    if (buf[i] > 0)
    {
      cnt++;
      //printf("%c",s[buf[i]][0]);
      //printf("%d",i);
    }
    i++;
  }
  if (cnt == 3)
    printf("Three");
  else
    printf("Four");
  //printf("%d",cnt);
}

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

#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif
#if __cplusplus <= 201402L
template <typename T>
T gcd(T a, T b) { return ((a % b == 0) ? b : gcd(b, a % b)); }
template <typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }
#endif
using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;

namespace Problem {
using namespace std;
#define int LL
class Solver2 {
 public:
  LL n, k;
  vector<LL> a;
  vector<vector<int>> A;
  vector<vector<LL>> tr;
  Solver2(LL n, LL k) : n(n), k(k), a(n), A(200001), tr(42, vector<LL>(n, -1)){};

  void nextRow(int i) {
    if (tr[0][i] >= 0) return;
    int now = a[i];
    auto nxtp = upper_bound(A[now].begin(), A[now].end(), i);
    if (nxtp < A[now].end()) {
      tr[0][i] = *nxtp - i + 1;
    } else {
      tr[0][i] = A[now][0] + n - i + 1;
    }
  }

  void solve() {
    for (int i = 0; i < n; ++i) {
      cin >> a[i];
      A[a[i]].push_back(i);
    }
    for (int i = 0; i < n; ++i) {
      nextRow(i);
    }
    DBG(a)
    for (int i = 1; i < tr.size(); ++i) {
      for (int j = 0; j < n; ++j) {
        int nxt = (tr[i - 1][j] + j) % n;
        tr[i][j] = tr[i - 1][j] + tr[i - 1][nxt];
      }
      DBG(i, tr[i])
    }
    DBG(a)
    LL sum = 0;
    LL now = 0;
    while (sum < n * k) {
      int P = 0;
      for (int i = tr.size() - 1; i >= 0; --i) {
        if (sum + tr[i][now] <= n * k) {
          P = i;
          break;
        }
        if (i == 0) P = -1;
      }
      if (P == -1) break;
      sum += tr[P][now];
      DBG(P, sum)
      now = sum % n;
    }
    DBG(a)
    DBG(now)
    if (sum == n * k) {
      cout << endl;
      return;
    }
    vector<int> ans = calc(now);
    DBG(ans)
    for (int i = 0; i < ans.size(); ++i) {
      cout << ans[i];
      if (i < ans.size() - 1) cout << ' ';
    }
    cout << endl;
  }
  vector<int> calc(int p) {
    vector<vector<int>> memo(200001);
    set<int> st;
    int size = 0;
    for (int i = p; i < n; ++i) {
      int now = a[i];
      if (memo[now].size() == 0) {
        memo[now].push_back(size);
        size++;
        st.insert(now);
      } else {
        size = memo[now][0];
        set<int> er;
        for (auto x : st) {
          DBG(x, memo[x], size)
          while (memo[x].size() > 0 && memo[x].back() >= size) memo[x].pop_back();
          if (memo[x].size() == 0) er.insert(x);
        }
        for (auto x : er) st.erase(x);
      }
    }
    vector<int> ret(size);
    for (int i = 1; i <= 200000; ++i) {
      for (auto j : memo[i]) {
        ret[j] = i;
      }
    }
    return ret;
  }
};
}  // namespace Problem

signed main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(12);
  long long n = 0, k;
  std::cin >> n >> k;

  Problem::Solver2 sol(n, k);
  sol.solve();
  return 0;
}


Measured memory_bytes: 100324
#include <bits/stdc++.h>
#define REP(i,n) for (long i=0;i<(n);i++)
#define FOR(i,a,b) for (long i=(a);i<(b);i++)
#define RREP(i,n) for(long i=n;i>=0;i--)
#define RFOR(i,a,b) for(long i=(a);i>(b);i--)
#define dump1d_arr(array) REP(i,array.size()) cerr << #array << "[" << (i) << "] ==> " << (array[i]) << endl;
#define dump2d_arr(array) REP(i,array.size()) REP(j,array[i].size()) cerr << #array << "[" << (i) << "]" << "[" << (j) << "] ==> " << (array[i][j]) << endl;
#define dump(x)  cerr << #x << " => " << (x) << endl;
#define CLR(vec) { REP(i,vec.size()) vec[i] = 0; } 
#define llINF (long long) 9223372036854775807
#define loINF (long) 2147483647
#define shINF (short) 32767
#define SORT(c) sort((c).begin(),(c).end())

using namespace std;
typedef vector<long> VI;
typedef vector<VI> VVI;


long N,A,B;

bool check(long mid,VI h){
	long cnt = 0;
	REP(i,N) h[i] -= ((B)*mid);
	REP(i,N){
		if (h[i] <= 0) continue;
		cnt += h[i] / (A-B);
		if (h[i] % (A-B)) cnt++;
	}

	if (cnt <= mid) return true;
	else return false; 
}


int main (void){
	cin >> N >> A >>  B;
	VI h(N,0);
	REP(i,N) cin >> h[i];
	long h_max = *max_element(h.begin(), h.end());
	long l = 0;
	long r = loINF;
	long minv = loINF;

	while (l <= r){
		long middle = (l + r) / 2;
		//dump(middle);

		if ((h_max / B) + 1 < middle){
			r = middle - 1;
			minv = min(middle,minv);
			continue;
		}

		if (check(middle,h)){
			r = middle - 1;
			minv = min(middle,minv);
		}
		else {
			l = middle + 1;
		}
	}

	cout << minv << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
#define D10 fixed<<setprecision(10)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<ll, ll> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/


const ll mod[] = { 999999937, 1000000007 }, base = 9973;

struct RollingHash
{
	int n;
	vector<ll> hs[2], pw[2];
	RollingHash() {};
	RollingHash(const string& s)
	{
		n = s.size();
		REP(i, 2)
		{
			hs[i].assign(n + 1, 0);
			pw[i].assign(n + 1, 0);
			hs[i][0] = 0;
			pw[i][0] = 1;
			REP(j, n)
			{
				pw[i][j + 1] = pw[i][j] * base%mod[i];
				hs[i][j + 1] = (hs[i][j] * base + s[j]) % mod[i];
			}
		}
	}

	ll hash(int l, int r, int i)
	{
		return ((hs[i][r] - hs[i][l] * pw[i][r - l]) % mod[i] + mod[i]) % mod[i];
	}

	bool match(int l1, int r1, int l2, int r2)
	{
		return (hash(l1, r1, 0) == hash(l2, r2, 0)) && (hash(l1, r1, 1) == hash(l2, r2, 1));
	}
};


int main()
{
	int n, m;
	cin >> n >> m;
	string s; cin >> s;
	RollingHash rh(s);
	set<pii> st;
	int l = 0, r = 1;
	REP(i, m)
	{
		string q; cin >> q;
		if (q == "L++") l++;
		else if (q == "L--") l--;
		else if (q == "R++") r++;
		else if (q == "R--") r--;
		st.insert(pii(rh.hash(l, r, 0), rh.hash(l, r, 1)));
	}
	cout << st.size() << endl;
	return 0;
}

Measured memory_bytes: 31376
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, a, b) for (int i = a; i >= b; i--)
using namespace std;

typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef long long ll;

template <typename _T>
inline void read(_T &f) {
    f = 0; _T fu = 1; char c = getchar();
    while (c < '0' || c > '9') { if (c == '-') { fu = -1; } c = getchar(); }
    while (c >= '0' && c <= '9') { f = (f << 3) + (f << 1) + (c & 15); c = getchar(); }
    f *= fu;
}

template <typename T>
void print(T x) {
    if (x < 0) putchar('-'), x = -x;
    if (x < 10) putchar(x + 48);
    else print(x / 10), putchar(x % 10 + 48);
}

template <typename T>
void print(T x, char t) {
    print(x); putchar(t);
}

const int N = 2e5 + 5;

int a[N], b[N], ida[N], idb[N], vis[N], ans[N];
int n, cnt;

bool cmpa(int x, int y) { return a[x] < a[y]; }
bool cmpb(int x, int y) { return b[x] < b[y]; }

int main() {
    read(n);
    for (int i = 1; i <= n; i++) read(a[i]), read(b[i]), ida[i] = idb[i] = i;
    sort(ida + 1, ida + n + 1, cmpa); sort(idb + 1, idb + n + 1, cmpb);
    int las = 0;
    for (int i = 1; i <= n; i++) {
        if (!vis[ida[i]]) vis[ida[i]] = 1, ++cnt;
        if (!vis[idb[n - i + 1]]) vis[idb[n - i + 1]] = 1, ++cnt;
        if (cnt == i) {
            for (int j = las + 1; j <= i; j++) ans[ida[j]] = i - las;
            las = i;
        }
    }
    for (int i = 1; i <= n; i++) print(ans[i], '\n');
    return 0;
}

Measured memory_bytes: 8288
int main(void)
{
	int n,x;
	
	int i,j,k;
	int c = 0;
	
	while(1){
		c = 0;
		scanf("%d %d",&n,&x);
		if(n == 0&&x == 0)break;
		
		for(i = 1;i <= n-2;i++){
			for(j = i+1;j <= n-1;j++){
				for(k = j+1;k <= n;k++){
					if(i + j + k == x)c++;
				}
			}
		}
		printf("%d\n",c);
	}
	return 0;
}

Measured memory_bytes: 600
num = int(input())
lastNumber = int(repr(num)[-1])
if lastNumber == 2 or lastNumber == 4 or lastNumber == 5 or lastNumber == 7 or lastNumber == 9:
    print("hon")
elif lastNumber == 0 or lastNumber == 1 or lastNumber == 6 or lastNumber == 8:
    print("pon")
else:
    print("bon")



Measured memory_bytes: 9176
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;


void main() {
    int n;
    scan(n);
    auto s = readln.chomp.to!string;

    auto pf = new int[](n + 1);
    foreach (i ; 1 .. n + 1) {
        pf[i] = pf[i-1] | (1 << (s[i-1] - 'a'));
    }

    auto sf = new int[](n + 1);
    foreach_reverse (i ; 0 .. n) {
        sf[i] = sf[i+1] | (1 << (s[i] - 'a'));
    }

    int ans;

    foreach (i ; 0 .. n) {
        ans = max(ans, popcnt(pf[i] & sf[i]));
    }

    writeln(ans);
}





































void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
   ll cnt1=0,cnt2=0;
   ll n,k;cin >>n>>k;
    for (int i = 1; i <= n; ++i) {
        if(k%2==0){
            if(i%k==k/2)cnt1++;
        }
        if(i%k==0)cnt2++;
    }
    ll ans=0;
   ll now=1;
//   cout <<cnt1<<" "<<cnt2<<endl;
    for (int j = 0; j < 3; ++j) {
        now*=cnt1;
    }
    ans+=now;
    now=1;
    for (int l = 0; l < 3; ++l) {
        now*=cnt2;
    }
    ans+=now;
    cout <<ans <<endl;
   return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int x;
    outer:
    for(int i = 1;i <= n;i++){
      if(i % 3 == 0){
        //iが３の倍数
        System.out.print(" " + i);
        continue;
      }
      x = i;
      do{
        if(x % 10 == 3){
          //下一桁が３ならその桁以降を表示
          System.out.print(" " + i);
          continue outer;
        }
      }while((x /= 10) != 0);
    }
    System.out.println("");
    sc.close();
  }
}



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

int main()
{

  int N;
  cin >> N;

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

  vector<long long> B(N);
  for (long long i = 0; i < N; i++)
  {
      B[i] = A[i] - i;
  }

  sort(B.begin(), B.end());
  long long ans=0,b = B[N / 2];

  for (int i = 0; i < N; i++)
  {
    ans+=abs(b-B[i]);
  }

  cout << ans << endl;

}


Measured memory_bytes: 3328
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            Solve();

            Console.ReadKey();
        }

        static void Solve()
        {
            var str = IO.GetIntList();
            var ans = Math.Ceiling(str[0] * 1.0 / (str[1] * 2 + 1));

            Console.WriteLine(ans);
        }
    }


    static class IO
    {
        static public string GetString() { return Console.ReadLine(); }
        static public int GetInt() { return int.Parse(Console.ReadLine()); }
        static public long GetLong() { return long.Parse(Console.ReadLine()); }
        static public List<string> GetStringList() { return Console.ReadLine().Split(' ').ToList(); }
        static public List<int> GetIntList() { return Console.ReadLine().Split(' ').Select(int.Parse).ToList(); }
        static public List<long> GetLongList() { return Console.ReadLine().Split(' ').Select(long.Parse).ToList(); }
        static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); }
        static public void WriteStrings<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } }
    }
}

Measured memory_bytes: 11604
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int i;
  int N, count=0;
  cin >> N;
  vector<int> mochi(N);
  
  for(i=0; i<N; i++){
  	cin >> mochi.at(i);
  }
  
  sort(mochi.rbegin(), mochi.rend());
  
  for(i=0; i<N; i++){
  	if(i==0)count++;
    else{
    	if(mochi.at(i) < mochi.at(i-1))count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long int
#define mod(x) ((x % MOD) + MOD) % MOD
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define RFORE(i,a,b) for(int i=(b);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(c) (int)((c).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define LB(c,x) (int)(lower_bound(ALL(c),x)-(c).begin())
#define UB(c,x) (int)(upper_bound(ALL(c),x)-(c).begin())
#define COUNT(c,x) (UB(c,x)-LB(c,x))
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define COPY(c1,c2) copy(ALL(c1),(c2).begin())
#define EXIST(s,e) (bool)((s).find(e)!=(s).end())
#define PB push_back
#define MP make_pair
#define DEL(v) decltype(v)().swap(v)
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
using namespace std;
template<typename T1, typename T2> using P = pair<T1,T2>;
template<typename T> using V = vector<T>;
struct edge { int from, to; int cost; };
bool operator< (const edge &edge1, const edge &edge2) { return edge1.cost < edge2.cost; };
const int INF = 1e18;
const int MOD = 1e9+7;

template<typename T> ostream& operator << (ostream& s, const V<T>& v) {
   s << "[";
   for (int i = 0; i < v.size(); i++) { s << v[i]; if (i < v.size() - 1) s << " "; }
   s << "]";
   return s;
}

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

   const int N = 50;
   cout << N << endl;
   int q = K % N;
   int p = K / N;
   // K = pN + q

   REP(i, q) {
      cout << 2*N + p - q << " ";
   }
   REP(i, N-q) {
      cout << N - 1 + p - q << " ";
   }
   cout << endl;

   return 0;
}


Measured memory_bytes: 256
num = list(range(1, 14))

spairs = 13 * ['S'] + num
hpairs = 13 * ['H'] + num
cpairs = 13 * ['C'] + num
dpairs = 13 * ['D'] + num

n = int(input())
s, h, c, d = 4*[0]
for i in range(n):
    a, b = input().split()
    if a == 'S':
        spairs.remove(a)
        spairs.remove(int(b))
        s += 1
    if a == 'H':
        hpairs.remove(a)
        hpairs.remove(int(b))
        h += 1
    if a == 'C':
        cpairs.remove(a)
        cpairs.remove(int(b))
        c += 1
    if a == 'D':
        dpairs.remove(a)
        dpairs.remove(int(b))
        d += 1

for i in range(13 - s):
    print(*[spairs[i], spairs[i + 13 - s]])
for i in range(13 - h):
    print(*[hpairs[i], hpairs[i + 13 - h]])
for i in range(13 - c):
    print(*[cpairs[i], cpairs[i + 13 - c]])
for i in range(13 - d):
    print(*[dpairs[i], dpairs[i + 13 - d]])


Measured memory_bytes: 5616
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
#define all(ppp) ppp.begin(),ppp.end()
#define out(ppp) cout<<(ppp)<<endl
#define out1(ppp) cout<<(ppp) 
#define MAX_CHAR 256

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define pb push_back

typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<vpi> vvpi;

typedef set<pi> spi;

const int INF=INT_MAX;


int main(){
    int N,a,b;
    cin>>N>>a>>b;
    out(min(N*a,b));

    return 0;
}


Measured memory_bytes: 256
fn main() {
    let v = read_vec::<usize>();
    let a = v[0];
    let b = v[1];
    let s = read::<String>();
    if s.chars().take(a).all(|c|c.is_digit(10))
    && s.chars().skip(a).take(1).all(|c|c=='-')
    && s.chars().skip(a+1).all(|c|c.is_digit(10)) {
        println!("Yes");
    } else {
        println!("No");
    }
}

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

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


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
typedef long long int ll;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T>
bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false;}
template<typename T>
bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false;}
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    if (s[0] == 'S') {
        cout << "Cloudy" << endl;
    }else if (s[0] == 'C')  {
        cout << "Rainy" << endl;
    } else {
        cout << "Sunny" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=1e18;
using P=pair<int,int>;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  ll n,a[100005]={},x,ans=0;
  cin >> n >> x;
  for(int i=0; i<n; i++) {
    cin >> a[i];
  }
  if(a[0]>x) {
    ans+=a[0]-x;
    a[0]=x;
  }
  for(int i=0; i<n-1; i++) {
    if(a[i]+a[i+1]>x) {
      ans+=a[i]+a[i+1]-x;
      a[i+1]-=a[i]+a[i+1]-x;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;

typedef long long Int;
typedef pair<Int,Int> P;
#define print(x) cout<<(x)<<endl

#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007


int main() {
	string s; cin >> s;
	int aplace = -1;
	int zplace = -1;
	for (int i = 0; i < s.length(); i++) {
		if (aplace == -1 && s[i] == 'A')aplace = i;
		if (s[i] == 'Z')zplace = i;
	}
	cout << zplace - aplace + 1 << endl;







	return 0;
}

Measured memory_bytes: 640
n = int(input())
x = [int(x) for x in input().split()]
x2 = sorted(x)
ans1, ans2 = x2[n//2-1], x2[n//2]
for i in range(n):
    if x[i] <= ans1:
        print(ans2)
    else:
        print(ans1)

Measured memory_bytes: 25220
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
using namespace std;
#define fr first
#define sc second
#define rep(i,n) for(int i = 0 ; i < n ; i++ )
typedef pair< int , int > Pt;
typedef long long ll;
const int dx[] = { 0, 1, -1, 0}, dy[] = { 1, 0, 0, -1};
struct P{
  Pt nkmr;
  vector< Pt > pnl,cnt;
  bool operator<(const P& right)const{
    return nkmr < right.nkmr;
  }
};
typedef pair< int , P > IP;
Pt Goal;
int h, w;
char mas[10][10];
int search_cnt(int y,int x,P& n){
  rep(i,n.cnt.size()) if(n.cnt[i] == Pt(y,x)) return i;
  return -1;
}
int search_panel(int y,int x,P& n){
  rep(i,n.pnl.size()) if(n.pnl[i] == Pt(y,x)) return i;
  return -1;
}
bool isused(set<ll>& used,P& p){
  ll ret = (p.nkmr.fr << 4) + p.nkmr.sc;
  sort(p.pnl.begin(),p.pnl.end()),sort(p.cnt.begin(),p.cnt.end());
  for(int i = 0 ; i < p.pnl.size() ; i++ ){
    ret <<= 4;
    ret += p.pnl[i].fr;
    ret <<= 4;
    ret += p.pnl[i].sc;
  }
  for(int i = 0 ; i < p.cnt.size() ; i++ ){
    ret <<= 4;
    ret += p.cnt[i].fr;
    ret <<= 4;
    ret += p.cnt[i].sc;
  }
  if(used.find(ret) != used.end()) return true;
  used.insert(ret);
  return false;
}
int Dijkstra(P& St){
  int dbk;
  priority_queue<pair<int,P>,vector<pair<int,P> >,greater<pair< int,P> > > que;
  set < ll >  used;
  que.push(IP(0,St));
  while(!que.empty()){
    int _cost = que.top().fr;
    P p = que.top().sc;
    que.pop();
    if(p.nkmr == Goal) return _cost;
    if(isused(used,p)) continue;
    rep(i,4){
      P next = p;
      int ny = p.nkmr.fr + dy[i], nx = p.nkmr.sc + dx[i],contena,panel;
      if(mas[ny][nx] == '#' || search_panel(ny,nx,next) != -1) continue;
      if((contena = search_cnt(ny,nx,next)) != -1){ //コンテナあった
        int ty = ny + dy[i], tx = nx + dx[i];
        if(mas[ty][tx] != '.' || search_cnt(ty,tx,next) != -1) continue;
        while(mas[ty][tx] == '.' &&
              search_cnt(ty,tx,next) == -1 && search_panel(ty,tx,next) == -1){
          ty += dy[i], tx += dx[i];
        }
        if((panel = search_panel(ty,tx,next)) != -1){
          next.cnt[contena] = Pt(-1,-1);
          next.pnl[panel] = Pt(-1,-1);
        }else next.cnt[contena] = Pt(ty - dy[i],tx - dx[i]);
        que.push(IP(_cost,next));
      }else{
        que.push(IP(_cost+1,(P){Pt(ny,nx),p.pnl,p.cnt}));
      }
    }
  }
  return -1;
}
int main(){
  while(cin >> h >> w , h ){
    P p = (P){Pt(),vector<Pt>(),vector<Pt>()};
    int cpa = 0,ccn = 0;
    rep(i,h) rep(j,w){
      cin >> mas[i][j];
      if(mas[i][j] == '@') p.nkmr = Pt(i,j), mas[i][j] = '.';
      else if(mas[i][j] == 'w'){
        p.pnl.push_back(Pt(i,j)), mas[i][j] = '.';
      }else if(mas[i][j] == 'c'){
        p.cnt.push_back(Pt(i,j)), mas[i][j] = '.';
      }else if(mas[i][j] == 'E') Goal = Pt(i,j), mas[i][j] = '.';
    }
    cout << Dijkstra(p) << endl;
  }
}

Measured memory_bytes: 4000
#include<iostream>

using namespace std;

int main()
{
	int age = 0;
	int A = 0,B = 0;

	cin >> age;

	if(age == 1)
	{
		cout << "Hello World" << endl;
		return 0;
	}

	if(age == 2)
	{
		cin >> A >> B;
		cout << A + B << endl;
		return 0;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;


template<int mod> struct ModInt{
    long long x=0; 
    constexpr ModInt(long long x=0):x((x%mod+mod)%mod){}
    constexpr ModInt operator+(const ModInt& r)const{return ModInt(*this)+=r;}
    constexpr ModInt operator-(const ModInt& r)const{return ModInt(*this)-=r;}
    constexpr ModInt operator*(const ModInt& r)const{return ModInt(*this)*=r;}
    constexpr ModInt operator/(const ModInt& r)const{return ModInt(*this)/=r;}
    constexpr ModInt& operator+=(const ModInt& r){ if((x+=r.x)>=mod) x-=mod; return *this;}
    constexpr ModInt& operator-=(const ModInt& r){ if((x-=r.x)<0) x+=mod; return *this;}
    constexpr ModInt& operator*=(const ModInt& r){ if((x*=r.x)>=mod) x%=mod; return *this;}
    constexpr ModInt& operator/=(const ModInt& r){ return *this*=r.inv();}
    ModInt inv() const {
        long long s=x,sx=1,sy=0,t=mod,tx=0,ty=1;
        while(s%t!=0){
            long long temp=s/t,u=s-t*temp,ux=sx-temp*tx,uy=sy-temp*ty;
            s=t;sx=tx;sy=ty;
            t=u;tx=ux;ty=uy;
        }
        return ModInt(tx);
    }
    ModInt pow(long long n) const {
        ModInt a=1;
        while(n>0){
            if(n&1) a*=*this;
            *this*=*this;
            n>>=1;
        }
        return a;
    }
    friend constexpr ostream& operator<<(ostream& os,const ModInt<mod>& a) {return os << a.x;}
    friend constexpr istream& operator>>(istream& is,ModInt<mod>& a) {return is >> a.x;}
};
using mint = ModInt<MOD>;

struct combination{
    int N;
    vector<mint> fac,finv,inverse;
    combination(int N):N(N){
        fac.resize(N+1);finv.resize(N+1);
        fac[0]=1;
        for(int i=1;i<=N;++i){fac[i]=fac[i-1]*i;}
        finv[N]=fac[N].inv();
        for(int i=N-1;i>=0;--i){finv[i]=finv[i+1]*(i+1);}
    }
    void inverse_build(){
        inverse.resize(N+1);
        inverse[1]=1;
        for(int i=2;i<=N;++i){inverse[i]=finv[i]*fac[i-1];}
    }
    mint c(int n,int k){
        if(n<k||n<0||k<0) return 0;
        return fac[n]*finv[n-k]*finv[k];
    }
    mint p(int n,int k){
        if(n<k||n<0||k<0) return 0;
        return fac[n]*finv[n-k];
    }
};

int main(){
    int h,w,a,b;
    cin >> h >> w >> a >> b;
    combination com(200005);
    vector<mint> v(w-b,0);
    for(int i=b;i<w;++i){
        v[i-b] = com.c(h-a-1+i,i);
    }
    mint ans = 0;
    for(int i=b;i<w;i++){
        v[i-b] *= com.c(w-i+a-2,a-1);
        ans += v[i-b];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 7136
def intMap(): return map(int,input().split())
def intList(): return list(map(int, input().split())) #横並びの場合
def intListVertical(): [int(input()) for _ in range(N)] #縦並びの場合

#s = input()
#n = int(input())
#s,t = input().split()
a,b = intMap()
#a = intList()
#w = intListVertical()

print(a*b)

Measured memory_bytes: 9152
#include <iostream>
#include <cstdio>
using namespace std;
int n;
int ans[11];
bool vis[30];
void dfs(int x) {
    if (x == n) {
        for (int i = 1; i <= n; i++) {
            cout << (char)(ans[i] + 'a');
        }
        puts("");
        return;
    }
    for (int i = 0; i <= 26; i++) {
        if (vis[i]) {
            ans[x + 1] = i;
            dfs(x + 1);
        } else {
            vis[i] = 1;
            ans[x + 1] = i;
            dfs(x + 1);
            vis[i] = 0;
            break;
        }
        
    }
}
int main() {
    cin >> n;
    dfs(0);
    return 0;
}



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

#define vi vector<int>
#define vl vector<long long>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPD(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define FORD(i, a, b) for (int i = (int)(a); i >= (int)(b); i--)
#define INF 1e18
#define MOD 1e9+7;

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

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



int main() {
    int N, M, Q;
    cin >> N >> M >> Q;
    vi a(Q);
    vi b(Q);
    vi c(Q);
    vi d(Q);
    REP(i, Q) {
        int _a, _b, _c, _d;
        cin >> _a >> _b >> _c >> _d;
        a[i] = _a;
        b[i] = _b;
        c[i] = _c;
        d[i] = _d;
    }
    int ans = 0;
    int cnt = 0;
    REP(S, 1<<(N+M-1)) {
        if (__builtin_popcount(S) != M-1) continue;
        cnt += 1;
        int num = 1;
        int res = 0;
        int pos = 0;
        vi A(N);
        REP(i, N+M-1) {
            if (S & (1<<i)) num++;
            else {
                A[pos] = num;
                pos++;
            }
        }
        REP(i, Q) {
            if (A[b[i]-1] - A[a[i]-1] == c[i]) res += d[i];
        }
        if (ans < res) ans = res;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int n,x;
struct task
{
	int b,l,r;
	long long sum;
	bool operator<(const task &q)const{return sum>q.sum;}
}a[110001];
int main()
{
	cin>>n>>x;
	long long o=0;
	for(int i=1;i<=n;i++)cin>>a[i].b>>a[i].l>>a[i].r,a[i].sum=1ll*a[i].b*a[i].l+1ll*(x-a[i].b)*a[i].r,o+=1ll*a[i].b*a[i].l;
	sort(a+1,a+1+n);
	long long l=0,r=1ll*x*n,ans=r;
	while(l<=r)
	{
		long long m=(l+r)/2,p=m/x,q=m%x,s=0,buf=0;
		for(int i=1;i<=p;i++)s+=a[i].sum;
		buf=s;
		if(q)
		{
			for(int i=1;i<=n;i++)
				if(i<=p)buf=max(buf,s+(q>a[i].b?a[i].b*a[i].l+(q-a[i].b)*a[i].r:q*a[i].l)+a[p+1].sum-a[i].sum);
				else buf=max(buf,s+(q>a[i].b?a[i].b*a[i].l+(q-a[i].b)*a[i].r:q*a[i].l));
		}
		if(buf>=o)r=m-1,ans=m;
		else l=m+1;
	}
	cout<<ans<<'\n';
}


Measured memory_bytes: 2560
cnt = [0 for i in range(26)]
letters = "abcdefghijklmnopqrstuvwxyz"
str = open(0).read()

for c in str:
  for j in range(len(letters)):
    if c == letters[j] or c == letters[j].upper():
      cnt[j] += 1
      break
for i in range(26):
    
  print(letters[i], ":", cnt[i])


Measured memory_bytes: 5576
H, W, M = map(int, input().split())

hc = [0] * H
wc = [0] * W
d = {}
for _ in range(M):
    h, w = map(lambda x: int(x) - 1,input().split())
    hc[h] += 1
    wc[w] += 1
    d[(h, w)] = 1

maxh = max(hc)
maxw = max(wc)

result = max(maxh + maxw - 1, 0)
wi = [i for i in range(W) if wc[i] == maxw]
for h in [i for i in range(H) if hc[i] == maxh]:
    for w in wi:
        if (h, w) not in d:
            result = maxh + maxw
            break
print(result)


Measured memory_bytes: 85472
#include <iostream>
#include <algorithm>
using namespace std;
#define mod 1000000007
long long dp[205][100005],fact[205],inv[205],sum[100005];
int arr[100005];
long long pow_log(long long x,int y)
{
	if (!y)
	return 1;
	long long ret=pow_log(x,y/2);
	ret=(ret*ret)%mod;
	if (y%2)
	ret=(ret*x)%mod;
	return ret;
}
int main()
{
	int n,x;
	scanf("%d%d",&n,&x);
	for (int i=1;i<=n;i++)
	scanf("%d",&arr[i]);
	sort(arr+1,arr+n+1);
	reverse(arr+1,arr+n+1);
	fact[0]=1;
	for (int i=1;i<=n;i++)
	fact[i]=(fact[i-1]*i)%mod;
	inv[n]=pow_log(fact[n],mod-2);
	for (int i=n-1;i>=0;i--)
	inv[i]=(inv[i+1]*(i+1))%mod;
	sum[x]=fact[n-1];
	for (int i=1;i<=n;i++)
	{
		for (int j=0;j<=x;j++)
		dp[i][j%arr[i]]=(dp[i][j%arr[i]]+sum[j])%mod;
		for (int j=0;j<=x;j++)
		{
			dp[i][j]=(dp[i][j]*inv[n-i])%mod;
			if (i!=n)
			sum[j]=(sum[j]+dp[i][j]*fact[n-i-1])%mod;
		}
	}
	long long ans=0;
	for (int j=0;j<=x;j++)
	ans=(ans+dp[n][j]*j)%mod;
	printf("%lld",ans);
}

Measured memory_bytes: 158720
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<iomanip>
#include <string>
#include <math.h>
using namespace std;

int main(){
    long long int n,ans=1;
    string s,t;
    cin>>n>>s>>t;
    if(s[0]==t[0]){
        ans*=3;
        if(n>=2){
            ans*=2;
        }
    }
    else{
        ans*=6;
    }
    for(int i=1;i<n-1;i++){
        if(s[i]==t[i]){
            if(s[i+1]==t[i+1]){
                ans*=2;
                ans%=1000000007;
            }
            else{
                ans*=2;
                ans%=1000000007;
            }
        }
        else if(s[i-1]==s[i]&&t[i-1]==t[i]){
            if(s[i+1]==t[i+1]){
                ans*=1;
                ans%=1000000007;
            }
            else{
                ans*=3;
                ans%=1000000007;
            }
        }
    }
    cout<<ans%1000000007<<endl;

    
    return 0;
}


Measured memory_bytes: 3600
#include<iostream>
#include<cstring>
using namespace std;
#define MAX 200200
char ch[MAX];
int ans,tot;
int main()
{
    cin>>(ch+1);
    for(int i=1,l=strlen(ch+1);i<=l;++i)
        if(ch[i]=='S')++tot;
        else tot?--tot:++ans;
    cout<<ans+tot<<endl;
        return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdio.h>

using namespace std;

//typedefリスト
typedef vector<long long int> vint;
typedef vector<vector<long long int>> vvint;
typedef vector<string> vstr;
typedef long long int llint;

llint gcd(llint x, llint y){
	while (y != 0){
		if (x > y){
			llint r = x%y;
			x = y;
			y = r;
		}
		else {
			llint r = y%x;
			y = r;
		}
	}
	return x;
}

int main(void) {
	double N,K,ans=0;
	cin >> N >> K;
	vector<double> two(18);
	two[0] = 1;
	for (int i = 1; i < 18; i++)two[i] = two[i - 1] * 2;

	
	for (double i = 1; i <= N; i++){
		for (int j = 0; j < 18; j++){
			if ((K / i) <= two[j]){
				ans += 1 / two[j];
				break;
			}
		}
	}
	cout  << setprecision(20) << ans*(1 / N) << endl;
}


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

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)


void func(long long A, long long B){
    cout << 6 - (A+B) << endl;
}

int main(){
    // cout << fixed << setprecision(5);

    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    func(A, B);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int main(){
	int n,x,y,z;
	cin>>n;
	int a[n+5]={0};
	int b[n+5]={0};
	int c[n+5]={0};
	
	for(int i=1;i<n+1;i++){
		cin>>x>>y>>z;
		a[i]=max(b[i-1]+y,c[i-1]+z);
		b[i]=max(a[i-1]+x,c[i-1]+z);
		c[i]=max(b[i-1]+y,a[i-1]+x);
	}
	
	cout<<max({a[n],b[n],c[n]});
	return 0;
}

Measured memory_bytes: 1408
// G++ MACRO.CPP -STD=C++14
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9+2;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;

#define dump(x)  cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl

#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j])

#define SCOUT(x) cout<<(x)<<" "
#define ENDL cout<<endl

#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECIN2(x,y) REP(i,x.size())cin>>x[i]>>y[i]
#define VECCOUT(x) for(auto tt=x.begin();tt!=x.end();tt++){if(tt!=x.begin())cout<<" ";cout<<(*tt);}cout<<endl

#define ALL(obj) (obj).begin(),(obj).end()

#define EXIST(n,x) (find(ALL(n),x)!=n.end())
#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end())
#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

template <class T = ll>
T IN(){T x;cin>>x;return (x);}

template <class Head>
void VT(Head head){}
template <class Head,class Seco,class... Tail>
void VT(Head&& head,Seco&& seco,Tail&&... tail){
    seco.resize(head);
    VT(head,move(tail)...);
}
void VT2(){}
template <class Head,class... Tail>
void VT2(Head&& head,Tail&&... tail){
  VECCIN(head);
  VT2(move(tail)...);
}

template <class Head>
void VT3(Head&& head){}
template <class Head,class Seco,class... Tail>
void VT3(Head&& head,Seco&& seco,Tail&&... tail){
  seco[head]=IN();
  VT3(head,move(tail)...);
}

#define VC1(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);VT2(__VA_ARGS__); //aaabbbccc
#define VC2(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);REP(i,n)VT3(i,__VA_ARGS__); //abcabcabc

// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision; // cpp_int

#define P pair<int,int>
#define V vector<int>
#define M map<int,int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int,V,greater<int>>

#define str string

#define pb(a) push_back(a)
#define mp make_pair

int main(){
  CIN(n);vector<V> a(n,V(n,0));
  REP(i,n)VECCIN(a[i]);
  vector<V> ac=a;WFA(a,n);
  REP(i,n)REP(j,n)
    if(a[i][j] < ac[i][j]){COUT(-1);return 0;}

  ll sum=0;
  REP(i,n)FOR(j,i+1,n){
    int range = a[i][j];
    bool flag=true;
    REP(k,n){
      if(k==i||k==j)continue;
      if(a[i][k] + a[j][k] == range){flag=false;;break;}
    }
    if(flag)sum += range;
  }
  COUT(sum);

  return 0;
}


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

int main() {
    string s, t, u;
    int a, b;
    map<string, int> m;
    cin >> s >> t >> a >> b;
    m[s] = a;
    m[t] = b;
    cin >> u;
    m[u] -= 1;
    cout << m[s] << " " << m[t] << endl;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define stl_repr(itr, x) for (auto itr = x.rbegin(); itr != x.rend(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

using llong = long long int;

const static int MOD = 1000000007;
const static int inf = INT_MAX;
const static llong INF = LLONG_MAX;
const static int dx[4] = {1, 0, -1, 0};
const static int dy[4] = {0, 1, 0, -1};

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<int> B(n - 1);
    rep(i, n - 1) cin >> B[i];

    int ans = 0;
    ans += B[0] + B[n - 2];
    if (n == 1) {
        cout << ans << endl;
    } else {
        for (int i = 1; i < n - 1; ++i) {
            ans += min(B[i - 1], B[i]);
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
# Vicfred
# https://atcoder.jp/contests/abc126/tasks/abc126_b
# implementation
s = int(input())

yy = s // 100
mm = s % 100

if 1 <= yy <= 12:
    if 1 <= mm <= 12:
        print("AMBIGUOUS")
    else:
        print("MMYY")
else:
    if 1 <= mm <= 12:
        print("YYMM")
    else:
        print("NA")



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

using namespace std;

void solve(int a,int b,int A,int B,string s){
  if(a == A && b == B){
    cout << s << endl;
    return;
  }
  int c = min(a,b), d = max(a,b);
  if(c <= 3 && d >= 5) return;
  if(c == 4 && d == 6) return;
  if(a == 5 && b == 5) return;
  solve(a+1,b,A,B,s+'A');
  solve(a,b+1,A,B,s+'B');
}

int main(){
  int A,B;
  cin >> A >> B;
  solve(0,0,A,B,"");
  return 0;
}

Measured memory_bytes: 1208
#include <stdio.h>

#define STACK 1000
#define Q     200000

void push(int, int);
int top(int);
void pop(int);

int S[STACK][Q];
int sp[STACK];

int main(void) {
  int n, q, op, t, x;

  scanf("%d %d", &n, &q);

  while(q--) {
    scanf("%d %d", &op, &t);

    switch(op) {
      case 0: scanf("%d", &x);
              push(t, x);
              break;
      case 1: top(t);
              break;
      case 2: pop(t);
              break;
    }
  }

  return 0;
}

void push(int t, int x) {
  ++sp[t];
  S[t][sp[t]] = x;
}

int top(int t) {
  if(sp[t] != 0)
    printf("%d\n", S[t][sp[t]]);
}

void pop(int t) {
  if(sp[t] != 0) {
    S[t][sp[t]] = 0;
    --sp[t];
  }
}



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

#define pb push_back
#define ff first
#define ss second
#define inf 1000000000
#define ninf -1000000000

using namespace std;

typedef long long ll;   
typedef double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef vector<ii> vii;
typedef vector<ll> vll;
typedef vector<int> vi;

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

    int ans = (b/k) - (a/k);
    if(a%k == 0) ans = 1;
    if(b%k == 0) ans = 1;
    if(ans == 0) cout<<"NG"<<endl;
    else cout<<"OK"<<endl;
    cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}


Measured memory_bytes: 3788
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;
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(){
	string s,t;cin>>s>>t;
	int res = t.size();
	for(int i = 0; i < s.size(); i++) {
		int index = i;
		int ans = 0;
		for(int j = 0; j < t.size(); j++) {
			if (index >= s.size()){
				ans = INF;
			}
			else if (s[index] != t[j]){
				ans++;
			}
			index ++;
		}
		res = min(res,ans);
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 3596
from itertools import accumulate

N, X = map(int, input().split())
BLUs = [tuple(map(int, input().split())) for _ in range(N)]

vs = [(L*B + U*(X-B), i) for i, (B, L, U) in enumerate(BLUs)]
vs.sort(reverse=True)

accV = 0
accVs = [0]
for v, i in vs:
    accV += v
    accVs.append(accV)
D0 = -sum([L*B for B, L, U in BLUs])

def isOK(k):
    q = k // X
    r = k % X
    for odr, (v, i) in enumerate(vs):
        B, L, U = BLUs[i]
        d = D0
        if odr < q:
            d += accVs[q+1] - v
        else:
            d += accVs[q]
        if r <= B:
            d += L*r
        else:
            d += L*B + U*(r-B)
        if d >= 0:
            return True
    return False

ng, ok = -1, N*X
while abs(ok-ng) > 1:
    mid = (ng+ok) // 2
    if isOK(mid):
        ok = mid
    else:
        ng = mid

print(ok)


Measured memory_bytes: 75224
NONE_RES,A_RES,B_RES = 0,1,2
buf = [[NONE_RES,B_RES,A_RES],[A_RES,NONE_RES,B_RES],[B_RES,A_RES,NONE_RES]]

S = input()
s = [1 if c == 'A' else 0 for c in S]
T = input()
t = [1 if c == 'A' else 0 for c in T]
n = int(input())

sum_s = [0]
for s_ in s:
    sum_s.append(sum_s[-1]+s_)

sum_t = [0]
for t_ in t:
    sum_t.append(sum_t[-1]+t_)

for _ in range(n):
    a,b,c,d = map(int,input().split(' '))
    A1 = sum_s[b] - sum_s[a-1]
    B1 = (b-(a-1))-A1
    A2 = sum_t[d] - sum_t[c-1]
    B2 = (d-(c-1))-A2
    type1 = buf[A1%3][B1%3]
    type2 = buf[A2%3][B2%3]
    if type1==type2:
        print('YES')
    else:
        print('NO')

Measured memory_bytes: 13324
package main

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

// 大小関係
func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	ary := strings.Split(strings.TrimSpace(sc.Text()), " ")
	x, _ := strconv.Atoi(ary[0])
	y, _ := strconv.Atoi(ary[1])
	if x < y {
		fmt.Println("a < b")
	} else if x == y {
		fmt.Println("a == b")
	} else {
		fmt.Println("a > b")
	}
}



Measured memory_bytes: 1100
/*
 ID: swagchicken1
 PROG:
 LANG: C++11
 */

#include <iostream>
#include <tuple>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <algorithm>
#include <vector>
#include <fstream>
#include <iomanip>
#include <ctime>
#include <cctype>
#include <climits>
#include <chrono>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector< vector <int> > vvi;
typedef pair<int, int> pii;
typedef pair < pair < int, int >, int > piii;
typedef pair < pair <int, int > , pair <int, int> > piiii;

#define FOR(i,a,b) for(int i = a; i < b; i ++)
#define RFOR(i,a,b) for(int i = a-1; i >= b; i --)

//#define endl '\n';

#define mp make_pair
#define pb push_back
#define f first
#define s second

const int MOD = 1000000007;

long double PI = 4*atan(1);
long double eps = 1e-12;


ll dp[2010][2010] = {};
int main() {
    //auto start = chrono::high_resolution_clock::now();
    ios_base::sync_with_stdio(0);cin.tie(0);
    //ofstream cout("output.txt");
    //ifstream cin("input.txt");
    int N; cin >> N;
    set<string> myset;
    FOR(i,0,N) {
        string str; cin >> str;
        myset.insert(str);
    }
    cout << myset.size() << endl;
    //auto stop = chrono::high_resolution_clock::now();
    //auto duration = chrono::duration_cast<chrono::microseconds>(stop - start);
    //cout << duration.count() << endl;
    //cin.close();
    //cout.close();
}


Measured memory_bytes: 19140
let substr (s: string) =
    if s.Substring(s.Length - 5) = "dream" then Some(s.Substring(0, s.Length - 5))
    elif s.Substring(s.Length - 5) = "erase" then Some(s.Substring(0, s.Length - 5))
    elif s.Substring(s.Length - 6) = "eraser" then Some(s.Substring(0, s.Length - 6))
    elif s.Substring(s.Length - 7) = "dreamer" then Some(s.Substring(0, s.Length - 7))
    elif s = "" then Some("")
    else None

let rec fc s =
    match substr s with
    | Some x ->
        match x with
        | "" -> "YES"
        | _ -> fc x
    | _ -> "NO"



let main () = stdin.ReadLine() |> fc |> printfn "%s"

main()

Measured memory_bytes: 30304
#include <stdio.h>
#include <string.h>

int main(void) {
	int i,j,q,a,b;
	char str[1000],v[1000],p[1000],c[100];
	scanf("%s %d",str,&q);
	for(i=0;i<q;i++){
		scanf("%s %d %d",c,&a,&b);
		if(strcmp(c,"print")==0){
			for(j=a;j<=b;j++){
				printf("%c",str[j]);
			}
			printf("\n");
		}
		else if(strcmp(c,"reverse")==0){
			strcpy(v,str);
			for(j=a;j<=b;j++){
				str[j]=v[b-(j-a)];
			}
		}
		else{
			scanf("%s",p);
			for(j=a;j<=b;j++){
				str[j]=p[j-a];
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1816
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;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(){
    string s; cin >> s;
    vector<string> lst = {"maerd", "remaerd", "esare", "resare"};

    reverse(all(s));
    string ss;
    rep(i, s.size()){
        ss += s[i];
        if(count(all(lst), ss)> 0)ss = "";
    }

    if(ss == "") cout << "YES" << ln;
    else cout << "NO" << ln;
}


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

int main() {
    int N , x;
    cin >> N >> x;
    vector <int> a(N);
    for(int i = 0; i < N; i++){
        cin >> a[i];
    }
    sort(a.begin() , a.end());
    int t = 0;
    for(int i = 0; i < N; i++){
        x-=a[i];
        if(x >= 0){
            t++;
        }
        else{
            break;
        }
    }
    if(t == N && x > 0){
        t--;
    }
    cout << t << endl;
}

Measured memory_bytes: 256