akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author KharYusuf
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BEasyLinearProgramming solver = new BEasyLinearProgramming();
        solver.solve(1, in, out);
        out.close();
    }

    static class BEasyLinearProgramming {
        public void solve(int testNumber, FastReader s, PrintWriter w) {
            int a = s.nextInt(), b = s.nextInt(), c = s.nextInt(), k = s.nextInt();
            int ans = Math.min(k, a);
            k -= ans;
            k -= Math.min(k, b);
            ans -= Math.min(k, c);
            w.println(ans);
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {

            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars) {

                curChar = 0;

                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (numChars <= 0)
                    return -1;
            }

            return buf[curChar++];
        }

        public int nextInt() {

            int c = read();

            while (isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();

                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public boolean isSpaceChar(int c) {

            if (filter != null)
                return filter.isSpaceChar(c);

            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 25508
#include <stdio.h>
long long min(long long a, long long b){
    if(a<b){
        return(a);
    } else {
        return(b);
    }
}
int main(void){
    long long a,b,c,men;
    scanf ("%lld%lld%lld",&a,&b,&c);
    if (a%2==0 || b%2==0 || c%2==0){
        printf("0\n");
    } else {
        men=min(min(a*b,b*c),min(b*c,c*a));
        printf("%lld\n",men);
	    return 0 ;
    }
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
template<typename A> using V = std::vector<A>;
using vi = V<int>;
using vvi = V<vi>;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
const int INF = 1000000000;
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vi c(m);
  rep(i, m) cin >> c[i];
  vi dp(n + 1, INF);
  dp[0] = 0;
  loop(i, 1, n + 1) {
    int mini = INF;
    rep(j, m) if (i - c[j] >= 0) cmin(mini, dp[i - c[j]] + 1);
    dp[i] = mini;
  }
  cout << dp[n] << endl;
}

Measured memory_bytes: 3200
#include <iostream>
using namespace std;
int main(void){
    int x,h,m,s;
    cin >> x;
    
    h = x/3600;
    m = ((x-(h*3600))/60);
    s = (x - h*3600 - m*60);
    
    cout << h << ":" << m << ":" << s << endl;
    return 0;
    
    
}


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

using namespace std;

#define DUMP(x) std::cerr << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES puts("YES")
#define Yes puts("Yes")
#define NO puts("NO")
#define No puts("No")
#define IMP puts("IMPOSSIBLE")
#define Imp puts("Impossible")
#define imp puts("impossible")
#define M1 puts("-1")
#define pb push_back

template <typename T>
T dup(T x, T y)
{
    return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }

using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using pll = pair<ll, ll>;
using setint = set<int32_t>;
using setstr = set<string>;
using qint = queue<int32_t>;
using qpint = queue<pint>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

void Main()
{
    int m;
    cin >> m;
    ll sum = 0;
    ll di = 0;
    rep(i, m)
    {
        ll d, c;
        cin >> d >> c;
        sum += d * c;
        di += c;
    }
    ll ans = sum / 9 + (di - 1);
    if (sum % 9 == 0)
        --ans;
    cout << ans << endl;
}

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


Measured memory_bytes: 256
N, K = map(int, input().split())
# 2(a+b+c) はKの倍数
# Kが２でない時、
# Kが奇数ならa,b,cは全てKの倍数
# Kが偶数ならa,b,cは全てKの倍数か、全てK//2の倍数
# Kが２の時
if K == 2:
    print((N//2)**3 + ((N+1)//2)**3)
elif K % 2 != 0:
    a = N//K
    print(a**3)
else:
    a = N//K
    b = N//(K//2) - N//K
    print(a**3 + b**3)

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

#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;

#define boost ios::sync_with_stdio(0); cin.tie(0)

#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;

const int N = .2e6 + 5;
const int MOD = 1e9 + 7;

/***************************************************************************/

int last[N];
int C[N];
int pp[N];

ll dp[N];

int main() {

	boost;
	int n; cin>>n;
	for(int i=1; i<=n; i++) {
		cin>>C[i];
		pp[i] = last[C[i]];
		last[C[i]] = i;
	}
	dp[0] = 1;
	for(int i=1; i<=n; i++) {
		dp[i] = dp[i-1];
		if(pp[i] and pp[i] < i-1) {
			dp[i] += dp[pp[i]];
			if(dp[i] >= MOD) dp[i] -= MOD;
		}
	}
	cout<<dp[n]<<"\n";
	return 0;
}

Measured memory_bytes: 4224
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223372036854775807
#define INF 2147483647
#define MOD 1000000007
using namespace std;


int main(int argc, char* argv[])
{
    long n, k;
    scanf("%ld%ld", &n, &k);

    vector<long> a(n);
    long i;
    for(i=0; i<n; i++) {
        scanf("%ld", &a[i]);
    }
    sort( a.rbegin(), a.rend() );

    long sum = 0;
    for(i=0; i<k; i++) {
        sum += a[i];
    }
    printf("%ld\n", sum);

    return 0;
}


Measured memory_bytes: 256
#include <stdint.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

using int_type = int64_t;

#define FOR(i, n) for (int_type i = 0; i < n; ++i)

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

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

    int_type A, B;
    cin >> A >> B;

    cout << lcm(A, B);

    return 0;
}


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

using namespace std;

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

#define MOD 998244353
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()
#define ADD(a, b) a = (a + b) % MOD

ll pow(ll x, ll n)
{
  if (n == 0)
    return 1;
  ll res = pow(x * x % MOD, n / 2);
  if (n & 1)
    res = res * x % MOD;
  return res;
}

ll inv(ll n)
{
  return pow(n, MOD - 2);
}

vector<ll> fact(300030);
void calc_fact()
{
  fact[0] = 1;
  REP(i, 300030)
  fact[i + 1] = (i + 1) * fact[i] % MOD;
}

ll comb(ll n, ll r)
{
  if (n < r)
    return 0;
  if (n < 0 || r < 0)
    return 0;
  return fact[n] * inv(fact[n - r] * fact[r] % MOD) % MOD;
}

int main()
{
  ll N, A, B, K;
  cin >> N >> A >> B >> K;
  calc_fact();
  ll ans = 0;
  for (ll r = 0; r <= N; ++r)
  {
    ll tmp = K - A * r;
    if (tmp < 0 || tmp % B != 0)
      continue;
    ll b = tmp / B;
    if (N < b)
      continue;
    ADD(ans, comb(N, r) * comb(N, b) % MOD);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
const int N = 3005;
bool dp[N][N];
int dx[4], dy[4];
int main() {
	int a, b, c, d, e, f;
	cin >> a >> b >> c >> d >> e >> f;
	dx[0] = 100 * a, dx[1] = 100 * b, dy[2] = c, dy[3] = d;
	double ans = 0.0, now = 0.0, w = 100 * a, s = 0;
	dp[0][0] = 1;
	for (int i = 0; i <= f; ++i)
		for (int j = 0; j + i <= f; ++j) {
			if (dp[i][j]) {
				for (int k = 0; k < 4; ++k) {
					int tx = i + dx[k], ty = j + dy[k];
					if (tx + ty <= f && ty * 100 <= tx * e) {
						dp[tx][ty] = 1;
						if (tx + ty && (double)ty / (tx + ty) > ans) {
							ans = (double)ty / (tx + ty);
							w = tx;
							s = ty;
						}
					}
				}
			}
		}
	cout << w + s << " " << s << endl;
	return 0;
}


Measured memory_bytes: 6400
#include"bits/stdc++.h"
using namespace std;
#define rep(i, N) for(int i=0; i<N; ++i)
using ul = unsigned long;
using ll = long long;

int main() {
    int a, b;
    cin >> a >> b;
    if (a == 1 && b == 2) cout << 3 << endl;
    if (a == 2 && b == 1) cout << 3 << endl;
    if (a == 2 && b == 3) cout << 1 << endl;
    if (a == 3 && b == 2) cout << 1 << endl;
    if (a == 1 && b == 3) cout << 2 << endl;
    if (a == 3 && b == 1) cout << 2 << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#define MAX 10000
#define NIL -1

struct Node
{
  int parent, left, right;
};

Node T[MAX];
int n;

void preParse(int u)
{
  if (u == NIL)
  {
    return;
  }
  printf(" %d", u);
  preParse(T[u].left);
  preParse(T[u].right);
}

void inParse(int u)
{
  if (u == NIL)
  {
    return;
  }
  inParse(T[u].left);
  printf(" %d", u);
  inParse(T[u].right);
}

void postParse(int u)
{
  if (u == NIL)
  {
    return;
  }
  postParse(T[u].left);
  postParse(T[u].right);
  printf(" %d", u);
}

int main()
{
  int id, left, right;

  scanf("%d", &n);
  for (int i = 0; i < n; i++)
  {
    T[i].parent = NIL;
  }

  for (int i = 0; i < n; i++)
  {
    scanf("%d %d %d", &id, &left, &right);
    T[id].left = left;
    T[id].right = right;
    if (left != NIL)
    {
      T[left].parent = id;
    }
    if (right != NIL)
    {
      T[right].parent = id;
    }
  }

  int root;
  for (int i = 0; i < n; i++)
  {
    if (T[i].parent == NIL)
    {
      root = i;
    }
  }

  printf("Preorder\n");
  preParse(root);
  printf("\n");
  printf("Inorder\n");
  inParse(root);
  printf("\n");
  printf("Postorder\n");
  postParse(root);
  printf("\n");

  return 0;
}


Measured memory_bytes: 2676
import java.util.*;
import java.math.BigDecimal;
public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
      long A=sc.nextLong();
      double B=sc.nextDouble();
      BigDecimal a=BigDecimal.valueOf(A);
      BigDecimal b=BigDecimal.valueOf(B);
      BigDecimal c=a.multiply(b);
      BigDecimal x=c.setScale(0,BigDecimal.ROUND_DOWN);
      System.out.println(x);
	}
}

Measured memory_bytes: 29176
#include <iostream>

int _gcd(int a, int b)
{

    return (a % b == 0) ? b : _gcd(b, a % b);
}

int gcd(int a, int b)
{
    return (a < b) ? _gcd(b, a) : _gcd(a, b);
}

int main()
{

    int n;

    std::cin >> n;

    int sum = 0;

    for (int i = 1; i <= n; ++i)
    {
        for (int j = 1; j <= n; ++j)
        {
            int g = gcd(i, j);
            for (int k = 1; k <= n; ++k)
                sum += gcd(g, k);
        }
    }

    std::cout << sum << std::endl;

    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define M 1000033/* your task*/
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key % M; }
int h2(int key){ return 1 + key % (M-1); }
int h(int key,int i){ return (h1(key) + i * h2(key)) % M;}

int find(char str[]){
  long long key = getKey(str);
  for(int i=0;;i++){
    int idx = h(key, i);
    if(H[idx][0] == '\0') return false;
    if(strcmp(str, H[idx]) == 0) return true;
  }
}

int insert(char str[]){
  long long key = getKey(str);
  int idx = 0;
  for(int i=0; ;i++){
    idx = h(key, i);
    if(H[idx][0] == '\0') break;
  }
  strcpy (H[idx], str);
}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);
	
	if ( com[0] == 'i' ){
	    insert(str);
	} else {
	    if (find(str)){
		printf("yes\n");
	    } else {
		printf("no\n");
	    }
	}
    }

    return 0;
}



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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n){
        cin >> a.at(i);
    }
    sort(a.begin(), a.end());
    
    long long res = 0;
    long long res1 = 0, res2 = 0;
    if(n%2){
        rep(i, (n-1)/2){
            res1 += -2*a.at(i);
        }
        res1 += a.at((n-1)/2);
        res1 += a.at((n-1)/2 + 1);
        for(int i = (n-1)/2 + 2; i < n; i++){
            res1 += 2*a.at(i);
        }
        
        rep(i, (n-1)/2 - 1){
            res2 += -2*a.at(i);
        }
        res2 += a.at((n-1)/2 - 1)*-1;
        res2 += a.at((n-1)/2)*-1;
        for(int i = (n-1)/2 + 1; i < n; i++){
            res2 += 2*a.at(i);
        }
        
        res = max(res1, res2);
    } else {
        rep(i, (n-2)/2){
            res += -2*a.at(i);
        }
        res += a.at((n-2)/2)*-1;
        res += a.at((n-2)/2 + 1);
        for(int i = (n-2)/2 + 2; i < n; i++){
            res += 2*a.at(i);
        }
    }
    
    cout << res << endl;
    return 0;
}

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

int main(){
                                                                     

    string s;

    string k = "CODEFESTIVAL2016";

    int i;

    int a = 0;

    
    cin >> s;


    for( i = 0 ; i < 16 ; i = i + 1 ){

         if( s.at(i) != k.at(i) ) a += 1;

         }


    cout << a << endl;


    return 0;

    }

Measured memory_bytes: 256
A, B, C = map(int, input().split())

if A % 2 == 1 or B % 2 == 1 or C % 2 == 1:
    print(0)
    exit()
    
diff1 = abs(A-B)
diff2 = abs(B-C)

if diff1 == 0 and diff2 == 0:
    print(-1)
    exit()

ans = 0
while diff1 % 2 == 0 and diff2 % 2 == 0:
    ans += 1
    diff1 //= 2
    diff2 //= 2

print(ans)

Measured memory_bytes: 9148
#include "bits/stdc++.h"

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back

using namespace std;

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;

const int mod=1e9+7,INF=1<<30;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll lmod = 1e9+7,LINF=1LL<<60;
const int MAX_N = 51;

void solve(){
  int c[3][3]; rep(i,3) rep(j,3) cin >> c[i][j];
  bool ans = true;
  ans &= (c[1][0]-c[0][0]==c[1][1]-c[0][1])&&(c[1][0]-c[0][0]==c[1][2]-c[0][2]);
  ans &= (c[2][0]-c[1][0]==c[2][1]-c[1][1])&&(c[2][0]-c[1][0]==c[2][2]-c[1][2]);
  if(ans) cout << "Yes" << endl;
  else cout << "No" << endl;
}

int main(){
  solve();
}

Measured memory_bytes: 384
/*  -*- coding: utf-8 -*-
 *
 * a.cc: C: /\/\/\/
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_V = 100000;

/* typedef */

typedef pair<int,int> pii;

/* global variables */

pii cs[2][MAX_V];

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);
  int hn = n / 2;

  for (int v = 0; v < MAX_V; v++)
    cs[0][v].second = cs[1][v].second = v;

  for (int i = 0; i < n; i++) {
    int ai;
    scanf("%d", &ai);
    cs[i & 1][ai - 1].first++;
  }

  sort(cs[0], cs[0] + MAX_V);
  sort(cs[1], cs[1] + MAX_V);

  int k0 = MAX_V - 1, k1 = MAX_V - 1;
  //printf("%d %d\n", cs[0][k0].first, cs[1][k1].first);

  if (cs[0][k0].second == cs[1][k1].second) {
    if (cs[0][k0 - 1].first > cs[1][k1 - 1].first) k0--;
    else k1--;
  }

  printf("%d\n", n - (cs[0][k0].first + cs[1][k1].first));
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

typedef long long ll;

int n;
int num[4] = { 0 };

int main() {
	cin >> n;
	int b;
	for (int i = 0; i < n; i++) {
		cin >> b;
		if (b % 4 == 0) num[2]++;
		else if (b % 2 == 0) num[1]++;
		else num[0]++;

	}
	if (num[0] - num[2] >= 2) cout << "No" << endl;
	else if (num[0] - num[2] == 1) {
		if (num[1] == 0) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	else cout << "Yes" << endl;
	return 0;
}

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

#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define eb emplace_back
#define rep(i, a, b) for (long i = (a); i <= (b); ++i)
#define per(i, a, b) for (long i = (a); i >= (b); --i)
#define mmst(v) memset(v, 0, sizeof(v))

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

const long kMax2 = 109;
const long kMax3 = 1009;
const long kMax4 = 10009;
const long kMax5 = 100009;
const long kMax6 = 1000009;
const long kInfI = 0x3F3F3F3F;
const float kInfF = 1e15;
const long long kMod = 1000000007;

const long kMAX = 1000000000;

using namespace std;
using ll = long long;

inline int readInt() {
  char c = getchar();
  while(!isdigit(c) && c != '-') c = getchar();
  int sigma = 1;
  if (c == '-') {
    sigma = -1;
    c = getchar();
  }
  int x = 0;
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * sigma;
}

template <typename T>
struct RMQ {
  using F = function<T(T, T)>;
  T dat[kMax5][20];
  F f;

  RMQ() {}
  RMQ(F f): f(f) {}

  void init(const vector<T> & a) {
    auto n = a.size();
    rep(i, 0, n - 1) { dat[i][0] = a[i]; }
    for (auto j = 1; (1 << j) <= n; ++j) {
      for (auto i = 0; i + (1 << j) - 1 < n; ++i) {
        dat[i][j] = f(dat[i][j - 1], dat[i + (1 << (j - 1))][j - 1]);
      }
    }
  }

  T query(ll l, ll r) {
    if (l > r) {
      return 0;
    }

    auto k = 0;
    while (l + (1 << (k + 1)) - 1 <= r) { ++k; }
    return f(dat[l][k], dat[r - (1 << k) + 1][k]);
  }
};

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

  ll ans = 0;

  int m;
  vector<ll> a, b;
  string s, t;

  auto n = readInt();
  auto tmp = readInt();
  ans += tmp;
  rep(i, 1, n - 2) {
    auto b0 = readInt();
    ans += min(tmp, b0);
    tmp = b0;
  }
  ans += tmp;
  cout << ans << endl;
  return 0;

}



Measured memory_bytes: 256
#include <stdio.h>
int main(){
  long long a,sum;
  char b[2];
  scanf("%lld",&sum);
  while(1){
    scanf("%s",&b);    
    if(b[0]=='=')break;
    else scanf("%lld",&a);
    if(b[0]=='+')sum+=a;
    else if(b[0]=='-')sum-=a;
    else if(b[0]=='*')sum*=a;
    else if(b[0]=='/')sum/=a;
  }
  printf("%lld\n",sum);
  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 sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
using LP=pair<ll,ll>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;



int main() {
    int N;
    cin>>N;
    vector<int> A(N);
    rep(i,N)cin>>A.at(i);
    int count=0;
    rep(i,N){
        if(i%2==0 && A.at(i)%2==1)count++;
    }
    cout<<count<<endl;
}

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

#define nax 100009
#define FOR(i,n,m) for(int i =(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)

typedef long long ll;

int main(){
	ll n,w,weight[101],values[101];
	ll dp[nax];
	cin>>n>>w;

	REP(i,n){
		cin>>weight[i]>>values[i];
	}

	REP(i,nax) dp[i] = 100000000000000LL;
	dp[0] = 0;

	
	REP(j,n){
		for(int i = nax-1;i>=0;i--){
			if(i-values[j]>=0){
				dp[i] = min(dp[i],
					dp[i-values[j]]+weight[j]);
			}
		}
	}

	int m = 0;

	REP(i,nax){
		if(dp[i]<=w){
			m = i;
		}
	}

	cout<<m;
	
	return 0;
}

Measured memory_bytes: 1024
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
//const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
///////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    ll a,b,c,d,e,f,g; cin >> a >> b >> c >> d >> e >> f >> g;

    ll ans = b;
    if (a==0||d==0||e==0) {
        cout << a/2LL*2LL+b+d/2LL*2LL+e/2LL*2LL << endl;
        return 0;
    }
    ll A = (a-1)%2+1;
    ll B = (d-1)%2+1;
    ll C = (e-1)%2+1;
    ans += a-A+d-B+e-C;
    if (A+B+C <= 4) ans += 3LL;
    else if (A+B+C==5) ans += 4LL;
    else ans += 6LL;

    cout << ans << endl;
}

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();
        long T = sc.nextLong();
        long[] t = new long[N];
        for(int i = 0; i < N; i++){
            t[i] = sc.nextLong();
        }
        sc.close();

        long sum = T;
        long[] time = new long[N-1];
        for(int i = 0; i < N-1; i++){
            time[i] = t[i+1] - t[i];
        }
        for(int i = 0; i < N-1; i++){
            sum += Math.min(T, time[i]);
        }

        System.out.println(sum);
    }
}

Measured memory_bytes: 64280
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

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

	vector<pair<int,pair<string, int>>> rest(n);
	for (int i = 0; i < n; ++i) {
		rest[i].first = i + 1;
		cin >> rest[i].second.first >> rest[i].second.second;
	}

	sort(rest.begin(), rest.end(), [](pair<int, pair<string, int>> x, pair<int, pair<string, int>> y) {
		if (x.second.first < y.second.first) {
			return true;
		}
		else if (x.second.first == y.second.first) {
			return x.second.second > y.second.second;
		}
		return false; 
	});

	for (int i = 0; i < n; ++i) {
		cout << rest[i].first << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define vll vector<ll>
#define fast  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

int main()
{
    fast;
    string s;
    ll i,j,sum=0;
    char c;
    cin>>s;
    for(i=0;i<s.size();i++)
    {
        sum=sum+s[i]-48;
    }
    if(sum%9==0)
        cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 3748
#pragma region noncode
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll INF = 1'010'000'000'000'000'017LL;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define SORT(v) sort(all(v))
#define TROS(v) sort(all(v), std::greater<Type>());
#pragma endregion

int main() {
    // template
    int a,b;
    cin>>a>>b;
    if(a<=b) cout<<a<<endl;
    else cout<<a-1<<endl;
}


Measured memory_bytes: 3564
#include<stdio.h>
#include<cstdlib>

int main() {
  int N, A[100002], dp[100001];
  unsigned long long sum;
  scanf("%d", &N);
  A[0] = 0; A[N+1] = 0;
  for (int i=1 ; i<=N ; i++) {
    scanf("%d", &A[i]);
  }
  sum = 0;
  for (int i=0 ; i<=N ; i++) {
    dp[i] = abs(A[i+1] - A[i]);
    sum += dp[i];
  }
  for (int i=1 ; i<=N ; i++) {
    printf("%lld\n", sum - dp[i-1] - dp[i] + abs(A[i+1] - A[i-1]));
  }
}

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

int main(){
    int N, M;
    cin >> N >> M;
    vector<int> a(50);
    vector<int> b(50);
    for (int i = 0; i < M; i ++){
        cin >> a.at(i) >> b.at(i);
    }
    vector<int> c(51, 0);
    for (int i = 0; i < M; i ++){
          c.at(a.at(i)) ++;
          c.at(b.at(i)) ++;
      }
    for (int i = 1; i <= N; i ++){
        cout << c.at(i) << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#define endl '\n'
using namespace std;
typedef long long ll;
int main()
{
	ll n; cin >> n;
	ll N = n,sum=0;
	while(n!=0)
	{
		sum += (n%10);
		n/=10;
	}
	if(N%sum==0)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

num_of_swp = 0
for i in range(N):
  for j in range(N - 1, i, -1):
    if A[j] < A[j - 1]:
      A[j - 1], A[j] = A[j], A[j - 1]
      num_of_swp += 1

print(" ".join(map(str, A)))
print(num_of_swp)

Measured memory_bytes: 7660
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) ll aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) string aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007


int gcd(int x,int y){
	
	if(y>x){
		int k=y;
		y=x;
		x=k;
	}
	
	if(x%y==0){
		return y;
	}else{
		return gcd(y,x%y);
	}
	
}

int main() {
	
	int N,K;
	cin>>N>>K;
	vec(A)
	vecp(A)
	int great=A.at(0);
	fx(N-1){
		vecp(A)
		great=gcd(great,aa);
	}
	
	sorts(A)
	reverses(A)
	for(int x=0;A.at(x)>=K;x++){
		
		if((A.at(x)-K)%great==0){
			ce("POSSIBLE")
			return 0;
		}
	
	}
	ce("IMPOSSIBLE")
	
}


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

int main() {
    int N,M; cin>>N>>M;
    vector<int> wa(N,0);
    int ac=0;
    int pena=0;
    for (int i = 0; i < M; i++){
        int p;cin>>p;p--;
        string s;cin>>s;
        if(wa[p]>=0){
            if(s=="AC"){
                ac++;
                pena+=wa[p];
                wa[p]=-1;
            }else wa[p]++;
        }
    }
    cout<<ac<<" "<<pena<<endl;
}

Measured memory_bytes: 3784
n,m=map(int,input().split())
p=[(i,1)for i in range(n)]
def find(i):
  if p[i][0]==i:return i
  else:
    c=find(p[i][0])
    p[i]=(c,0)
    return c
def union(i,j):
  pi=find(i)
  pj=find(j)
  if not pi==pj:
    if p[pi][1]>p[pj][1]:
      p[pi]=(pi,p[pi][1]+p[pj][1])
      p[pj]=(pi,0)
    else:
      p[pj]=(pj,p[pi][1]+p[pj][1])
      p[pi]=(pj,0)
      

for i in range(m):
  a,b=map(int,input().split())
  union(a-1,b-1)
ans=0
for i in range(n):
  if p[i][0]==i:ans=max(ans,p[i][1])
print(ans)

Measured memory_bytes: 29624
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0);
#define END return EXIT_SUCCESS;
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR((I),0,(N))
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP((I),(N)) cin>>(V[I])
#define INS2(I,N,V1,V2) REP((I),(N)) cin>>(V1[I])>>(V2[I]);
#define INS3(I,N,V1,V2,V3) REP((I),(N)) cin>>(V1[I])>>(V2[I])>>(V3[I]);
#define OUT(P) cout<<(P)<<endl
#define OUT2(P1,P2) cout<<(P1)<<" "<<(P2)<<endl
#define OUT3(P1,P2,P3) cout<<(P1)<<" "<<(P2)<<" "<<(P3)<<endl
#define OUTS(I,N,V) REP((I),(N)) cout<<(V[i])<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}

int D,N;
inline void solve(){
  IN2(D,N);
  OUT(N<=99?N*(long)pow(100,D):101*(long)pow(100,D));
}

int main(int argc,char**argv){
  BEGIN
  solve();
  END
}


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

#define ll long long int
const ll INF = 0xFFFFFFFFFFFFFFFL;

ll dp[402][402]={-1},n,ar[402],pr[402];

ll solve(int i,int j){
    if(dp[i][j]!=-1)
        return dp[i][j];
    else if(i==j)
        return dp[i][j]=0;
    ll var = INF;
    for(int k=i;k<j;k++){
        var=min(var,solve(i,k)+solve(k+1,j)+pr[j]-pr[i-1]);
    }
    return dp[i][j]=var;
}

int main(){
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>ar[i];
    for(int i=0;i<=n;i++)
        pr[i]=pr[i-1]+ar[i];
    memset(dp,-1,sizeof(dp));
    cout<<solve(1,n)<<"\n";

    return 0;
}

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

int main() {
  int n;
  cin >> n;
  if(n % 10 == 2){ cout << "hon" << endl;}
  if(n % 10 == 4){ cout << "hon" << endl;}
  if(n % 10 == 5){ cout << "hon" << endl;}
  if(n % 10 == 7){ cout << "hon" << endl;}
  if(n % 10 == 9){ cout << "hon" << endl;}
  if(n % 10 == 0){ cout << "pon" << endl;}
  if(n % 10 == 1){ cout << "pon" << endl;}
  if(n % 10 == 6){ cout << "pon" << endl;}
  if(n % 10 == 8){ cout << "pon" << endl;}
  if(n % 10 == 3){ cout << "bon" << endl;}
  
} 


Measured memory_bytes: 3636
#include "bits/stdc++.h"
using namespace std;

#define ul unsigned long int
#define ull unsigned long long
#define li long long int

int main()
{
  string s,ns;
  ul m;
  int h;

  cin>>s;
  while (s!="-") {
    cin>>m;
    for (ul i=0;i<m;i++) {
      cin>>h;
      ns=s.substr(h,s.length()-h)+s.substr(0,h);
      //cout << ns<<endl;
      swap(ns,s);

    }
    cout <<s<<endl;

    cin>>s;
  }

  return 0;
}



Measured memory_bytes: 3200
#include"bits/stdc++.h"


#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(int x = (l);x<=(u);x++)
#define RREP(x,l,u) for(int x = (l);x>=(u);x--)
#define mst(x,a) memset(x,a,sizeof(x))
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define se second
#define fi first
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
#define sz(x) ((int)x.size())
#define cl(x) x.clear()

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;

const int maxn = 100010;
const int mod = 1e9+7;
const int MAX = 1000000010;
const double eps = 1e-6;
const double PI = acos(-1);

template<typename T> inline void read(T &x){
x=0;T f=1;char ch;do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}

template<typename A,typename B> inline void read(A&x,B&y){read(x);read(y);}
template<typename A,typename B,typename C> inline void read(A&x,B&y,C&z){read(x);read(y);read(z);}
template<typename A,typename B,typename C,typename D> inline void read(A&x,B&y,C&z,D&w){read(x);read(y);read(z);read(w);}
template<typename A,typename B> inline A fexp(A x,B p){A ans=1;for(;p;p>>=1,x=1LL*x*x%mod)if(p&1)ans=1LL*ans*x%mod;return ans;}
template<typename A,typename B> inline A fexp(A x,B p,A mo){A ans=1;for(;p;p>>=1,x=1LL*x*x%mo)if(p&1)ans=1LL*ans*x%mo;return ans;}

int n;

int A[maxn],f[maxn];

vector<int> G[maxn];

int has[maxn],cnt;

void dfs(int u){
	for(auto v:G[u])dfs(v);
	cnt=0;for(auto v:G[u])has[++cnt]=f[v];
	sort(has+1,has+cnt+1);
	REP(i,1,cnt)f[u]=max(f[u],has[i]+cnt-i+1);
}

void Work(){
	dfs(1);
	iout(f[1]);
}

void Init(){
	read(n);
	REP(i,2,n){
		int x;read(x);
		G[x].PB(i);
	}
}

int main(){
	Init();
	Work();
	return 0;
}


Measured memory_bytes: 10752
using System;
using System.Linq;
using System.Collections.Generic;
using System.Diagnostics;
using Debug = System.Diagnostics.Trace;
using SB = System.Text.StringBuilder;
//using System.Numerics;
using static System.Math;
using static System.Console;
namespace Program {
	public class Solver {
		Random rnd = new Random();
		public void Solve() {
			var n = ri;
			var m = ri;
			var max = 1;
			for (int i = 1; i * i <= m; i++) {
				if (m % i != 0) continue;
				var j = m / i;
				if (j >= n) max = Max(max, i);
				if (i >= n) max = Max(max, j);
			}
			Console.WriteLine(max);

		}
		const long INF = 1L << 60;
		static int[] dx = { -1, 0, 1, 0 };
		static int[] dy = { 0, 1, 0, -1 };
		int ri { get { return sc.Integer(); } }
		long rl { get { return sc.Long(); } }
		double rd { get { return sc.Double(); } }
		string rs { get { return sc.Scan(); } }
		public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput());

		static T[] Enumerate<T>(int n, Func<int, T> f) {
			var a = new T[n];
			for (int i = 0; i < n; ++i) a[i] = f(i);
			return a;
		}
		static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; }
	}
}

#region main
static class Ex {
	static public string AsString(this IEnumerable<char> ie) { return new string(ie.ToArray()); }
	static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") {
		return string.Join(st, ie);
	}
	static public void Main() {
		Console.SetOut(new Program.IO.Printer(Console.OpenStandardOutput()) { AutoFlush = false });
		var solver = new Program.Solver();
		solver.Solve();
		Console.Out.Flush();
	}
}
#endregion
#region Ex
namespace Program.IO {
	using System.IO;
	using System.Text;
	using System.Globalization;

	public class Printer : StreamWriter {
		public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
		public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { }
	}

	public class StreamScanner {
		public StreamScanner(Stream stream) { str = stream; }

		public readonly Stream str;
		private readonly byte[] buf = new byte[1024];
		private int len, ptr;
		public bool isEof = false;
		public bool IsEndOfStream { get { return isEof; } }

		private byte read() {
			if (isEof) return 0;
			if (ptr >= len) {
				ptr = 0;
				if ((len = str.Read(buf, 0, 1024)) <= 0) {
					isEof = true;
					return 0;
				}
			}
			return buf[ptr++];
		}

		public char Char() {
			byte b = 0;
			do b = read(); while ((b < 33 || 126 < b) && !isEof);
			return (char)b;
		}
		public string Scan() {
			var sb = new StringBuilder();
			for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b);
			return sb.ToString();
		}
		public string ScanLine() {
			var sb = new StringBuilder();
			for (var b = Char(); b != '\n' && b != 0; b = (char)read()) if (b != '\r') sb.Append(b);
			return sb.ToString();
		}
		public long Long() { return isEof ? long.MinValue : long.Parse(Scan()); }
		public int Integer() { return isEof ? int.MinValue : int.Parse(Scan()); }
		public double Double() { return isEof ? double.NaN : double.Parse(Scan(), CultureInfo.InvariantCulture); }
	}
}

#endregion


Measured memory_bytes: 13136
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define INF (2 << 28)
#define fr first
#define sc second
using namespace std;

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

int main(){
  
  int r, c;
  while(cin >> r >> c, r||c)
    cout << (r * c % 2 ? "no" : "yes") << endl;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, P> P3;
typedef pair<P, P> PP;
constexpr ll MOD = ll(1e9 + 7);
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(10000) + 5;
constexpr double EPS = 1e-9;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i > 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()



int main() {
    int n;
    double sum = 0;
    cin >> n;
    for(int i=0;i<n;i++){
        double a;
        cin >> a;
        sum += 1/a;
    }
    sum = 1/sum;
    printf("%.10lf\n", sum);
    return 0;
}


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

typedef long long ll;
const int NMAX = 3e5 + 10;
const int MOD = 1e9 + 7;

int Max[NMAX<<3];
int maxx[NMAX] , a[NMAX] ;

void push_up(int rt)
{
    Max[rt] = max(Max[rt<<1],Max[rt<<1|1]);
}

void update(int pos,int c,int l,int r,int rt)
{
    if(l == r)
    {
        Max[rt] = c;
        return;
    }

    int mid = (l + r)>>1;
    if(pos <= mid)  update(pos,c,l,mid,rt<<1);
    else update(pos,c,mid+1,r,rt<<1|1);
    push_up(rt);

}

int queryMax(int L,int R,int l,int r,int rt)
{
    if(L <= l && r <= R)
        return Max[rt];

    int mid = (l + r )>>1;
    int ans = 0;
    if(L <= mid)    ans = max(ans,queryMax(L,R,l,mid,rt<<1));
    if(R > mid)     ans = max(ans,queryMax(L,R,mid + 1,r,rt<<1|1));
    return ans;
}

int main(int argc, char const *argv[])
{
	int n , k , N = 0;
	scanf("%d%d",&n,&k);
	for(register int i = 1;i <= n;i++)	scanf("%d",a + i) , a[i]++ , N = max(N , a[i] + k);
	int ans = 0, ant;
	for(register int i = 1;i <= n;i++)
	{
		ant =  1 + queryMax(max(1 , a[i] - k),min(a[i] + k ,N) , 1 , N, 1);
		if(maxx[a[i]] < ant)
		{
			maxx[a[i]] = ant;
			update(a[i] , ant , 1 , N ,1);
		}
		ans = max(ans , ant);
	}
	printf("%d\n",ans );
	return 0;
}

Measured memory_bytes: 10740
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;
int p[10];

int calc(int n){
  int ans=0;
  REP(i,10){
    ans+=(n/p[i])%10;
  }
  return ans;
}

int main(){
  p[0]=1;
  FOR(i,1,10)p[i]=p[i-1]*10;
  int N;
  cin>>N;
  int ans=9999999;
  FOR(i,1,N/2+1){
    ans=min(ans,calc(i)+calc(N-i));
  }
  cout<<ans<<endl;
  return 0;
}


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

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

using namespace std;

const int IINF = INT_MAX;
const int h = 19;
const int w = 15;

struct Data { 
  int x,y,bitmask,cost;
  bool operator < ( const Data& data ) const { 
    if( cost != data.cost ) return cost < data.cost; 
    if( x != data.x ) return x < data.x;
    if( y != data.y ) return y < data.y;
    if( bitmask != data.bitmask ) return bitmask < data.bitmask;
  }
};

char a[20][20];
//int mindist[1<<20][9];
set<Data> mindist;
int Index[20][20];

bool isValid(int x,int y) { return 0 <= x && x < w && 0 <= y && y < h; }

void compute(){
  int black = 0;
  int sx=-1,sy=-1;
  rep(i,h) rep(j,w) {
    if( a[i][j] == 'X' ) Index[i][j] = black++;
    if( a[i][j] == 'O' ) sx = j, sy = i;
  }
  //rep(i,(1<<black)) rep(j,9) mindist[i][j] = IINF;
  mindist.clear();
  //mindist[(1<<black)-1][4] = 0;
  mindist.insert((Data){sx,sy,(1<<black)-1,0});
  deque<Data> deq;
  deq.push_back((Data){sx,sy,(1<<black)-1,0});
  while( !deq.empty() ){
    Data data = deq.front(); deq.pop_front();
    REP(dx,-1,2){
      REP(dy,-1,2){
        if( dx == 0 && dy == 0 ) continue;
        int nx = data.x + dx, ny = data.y + dy, nbitmask = data.bitmask;
        bool valid = false;
        while( isValid(nx,ny) && ( a[ny][nx] == 'X' && ( data.bitmask & (1<<Index[ny][nx]) ) ) ){
          nbitmask &= ~(1<<Index[ny][nx]);
          nx += dx, ny += dy;
          valid = true;
        }
        if( valid && ( ny >= h || ( ny == h-1 && isValid(nx,ny) ) ) ) {
          //cout << mindist[data.bitmask]+1 << endl;
          cout << data.cost+1 << endl;
          return;
        } else if( !isValid(nx,ny) ) {
          continue;
        }
        if( !valid ) continue;
        //if( mindist[nbitmask] > mindist[data.bitmask] + 1 ) {
        if( !mindist.count((Data){nx,ny,nbitmask,data.cost+1}) ) {
          //mindist[nbitmask] = mindist[data.bitmask] + 1;
          mindist.insert((Data){nx,ny,nbitmask,data.cost+1});
          deq.push_back((Data){nx,ny,nbitmask,data.cost+1});
        }
      }
    }
  }
  puts("-1");
}

int main(){
  rep(i,h) rep(j,w) scanf(" %c",&a[i][j]);
  compute();
  return 0;
}

Measured memory_bytes: 6424
#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<map>
#include<string>
#include <math.h>
#include<algorithm>
#include<functional>
#define ll long long
#define inf  999999999
#define pa pair<int,int>
#define EPS (1e-10)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

class Point{
	public:
	double x,y;
	Point(double x=0,double y=0):x(x),y(y) {}
	Point operator + (Point p) {return Point(x+p.x,y+p.y);}
	Point operator - (Point p) {return Point(x-p.x,y-p.y);}
	Point operator * (double a) {return Point(x*a,y*a);}
	Point operator / (double a) {return Point(x/a,y/a);}
	double absv() {return sqrt(norm());}
	double norm() {return x*x+y*y;}
	bool operator < (const Point &p) const{
		return x != p.x ? x<p.x: y<p.y;
	}
	bool operator == (const Point &p) const{
		return fabs(x-p.x)<EPS && fabs(y-p.y)<EPS;
	}
};
typedef Point Vector;

struct Segment{
Point p1,p2;
};


double dot(Vector a,Vector b){
	return a.x*b.x+a.y*b.y;
}
double cross(Vector a,Vector b){
	return a.x*b.y-a.y*b.x;
}

//----------------kokomade temple------------


int main(){
int n;
double a1,a2,a3,a4,a5,a6;
cin>>a1>>a2>>a3>>a4;
cin>>n;
Point p0,p1,p2;
Vector v01,v02;
p0.x=a1,p0.y=a2,p1.x=a3,p1.y=a4;
v01=p1-p0;

for(int i=0;i<n;i++){
cin>>a5>>a6;
p2.x=a5,p2.y=a6;
v02=p2-p0;

if(cross(v01,v02)>0) cout<<"COUNTER_CLOCKWISE"<<endl;
else if(cross(v01,v02)<0) cout<<"CLOCKWISE"<<endl;
else if(dot(v01,v02)<0) cout<<"ONLINE_BACK"<<endl;
else if(v01.norm() < v02.norm()) cout<<"ONLINE_FRONT"<<endl;
else cout<<"ON_SEGMENT"<<endl;



}



return 0;
}

Measured memory_bytes: 1228
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int m = scan.nextInt();
        int kk = scan.nextInt();
        int[][] a = new int[n + 1][m + 1];
        for (int i = 1; i <= kk; i++) {
            int x = scan.nextInt();
            int y = scan.nextInt();
            int val = scan.nextInt();
            a[x][y] = val;
        }
        long[][][] dp = new long[2][m + 1][4];
        int x = 1;
        for (int i = 1; i <= n; i++) {
            int pre = 1 ^ x;
            for (int j = 1; j <= m; j++) {
                dp[x][j][0] = dp[pre][j][3];
                for (int k = 1; k <= 3; k++) {
                    long tmp = dp[pre][j][3] + a[i][j];
                    tmp = Math.max(tmp, dp[x][j - 1][k]);
                    tmp = Math.max(tmp, dp[x][j - 1][k - 1] + a[i][j]);
                    dp[x][j][k] = tmp;
                }
            }
            x = pre;
        }
        System.out.println(dp[1 ^ x][m][3]);
    }
}


Measured memory_bytes: 96676
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N; cin >> N; 
	string S[60]; int T[60]; 
	int A[60] = {}; 
	for(int i = 1; i <= N; i++){
		cin >> S[i] >> T[i]; 
		A[i] = A[i-1] + T[i]; 
	}
	string X; cin >> X; 
	int idx = 0; 
	for(int i = 1; i <= N; i++){
		if(X == S[i]) idx = i; 
	}
	cout << A[N] - A[idx] << endl; 
}

Measured memory_bytes: 256
fun main(args : Array<String>) {
    val n = readLine()!!.toInt()
    val s = readLine()!!.toMutableList()
    val k = readLine()!!.toInt()

    val target = s[k-1]
    s.forEachIndexed { idx, c ->
        if (c != target) s[idx] = '*'
    }

    println(s.joinToString(""))
}

Measured memory_bytes: 33524