akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main {
	//0140 start
	//0200 end
	//0430 restart
	//0442 sample match WA
	//0509 WA * 2
	//0920 WA * 2
	//0921 AC
	
	class C{
		int count, rest;
		ArrayList<Integer> list;
		public C(int count, int rest) {
			this.count = count;
			this.rest = rest;
			this.list = new ArrayList<Integer>();
		}
		
		private void sort(){
			Collections.sort(this.list);
		}
		
	}

	private void doit(){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		while(n-- > 0){
			ArrayList<Integer> input = new ArrayList<Integer>();
			int inputnum = sc.nextInt();
			while(inputnum != 0){
				input.add(inputnum);
				inputnum = sc.nextInt();
			}
			
			ArrayList<C> rooms = new ArrayList<C>();
			int first = input.get(0);
			int nowroom = 0;
			rooms.add(new C(0, first));
			for(int i = 1; i < input.size(); i++){
				int nownum = input.get(i);
				if(nownum < 0){
					//nownumのcount を探す
					int find = rooms.get(nowroom).count + nownum;
					for(int j = nowroom - 1; j >= 0; j--){
						if(rooms.get(j).count == find){
							//つなげる
							rooms.get(nowroom).rest--;
							rooms.get(nowroom).list.add(j + 1);
							
							//反対側
							rooms.get(j).rest--;
							rooms.get(j).list.add(nowroom + 1);
							break;
						}
					}
				}
				else{
					int nextcount = rooms.get(nowroom).count + 1;
					rooms.add(new C(nextcount, nownum));
					int nextroomid = rooms.size() - 1;
					
					//つなげる
					rooms.get(nowroom).rest--;
					rooms.get(nowroom).list.add(nextroomid + 1);
					
					//反対側
					rooms.get(nextroomid).rest--;
					rooms.get(nextroomid).list.add(nowroom + 1);
				}
				//次のnowroomを探す
				for(int j = rooms.size() - 1; j >= 0; j--){
					if(rooms.get(j).rest > 0){
						nowroom = j;
						break;
					}
				}
			}
			
			for(int i = 0; i < rooms.size(); i++){
				rooms.get(i).sort();
			}
			
			//print
			for(int i = 0; i < rooms.size(); i++){
				System.out.print((i + 1));
				for(int j = 0; j < rooms.get(i).list.size(); j++){
					System.out.print(" " + rooms.get(i).list.get(j));
				}
				System.out.println();
			}
		}
	}
	public static void main(String [] args){
		new Main().doit();
	}
}

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

using ll = long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define ALL(c) (c).begin(), (c).end()

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }

template <class T, class U>
void chmin(T& t, const U& u) {
    if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
    if (t < u) t = u;
}

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "{";
    rep(i, v.size()) {
        if (i) os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

#ifdef LOCAL
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << H;
    debug_out(T...);
}
#define debug(...) \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

int main() {
    ll a, b, c;
    cin >> a >> b >> c;
    ll r = c - a - b;
    ll l = 4 * a * b;
    if (r >= 0 && l < r * r) {
        puts("Yes");
    } else {
        puts("No");
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
// Hey! 僕の提出を見てくれてありがとう.
// ロボ子さん可愛いぞ！！！！！君もV沼にはまろう↓
// https://www.youtube.com/channel/UCDqI2jOz0weumE8s7paEk6g
using namespace std;
namespace mp = boost::multiprecision;
// 任意長整数型
using bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using real1024 = mp::number<mp::cpp_dec_float<1024>>;
// ついでに有理数型
using rat = boost::rational<bint>;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示
//sortを降順にする時は greater<型>()

void solve(long long X, long long N, std::vector<long long> p){
  ll now = X;
  ll i = 1;
  sort(all(p));
  while(1){
    if(find(all(p),now) == p.end()){
      break;
    }
    now += i*(i%2 == 0?1:-1);
    i++;
  }
  cout << now << endl;
}

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


Measured memory_bytes: 3696
#include<bits/stdc++.h>+
using namespace std;
int main()
{
    int a[205]={0},i,t,n,x,k,cnt=0,s=0;
    cin>>n>>x;
    //n--;
    //x--;
    for(i=1;i<n;i++)
    {
        cnt=cnt+i;
    }
    for(i=1;i<x;i++)
    {
        s=s+i;
    }
    s=s+cnt;
    cout<<s;

    return 0;
}



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

int main(){
    int x;
    cin >> x;
    int a;
    a = x/500;
    int b =x-500*a;
    int c = b/5;
    cout << (1000*a + 5*c) <<endl;
}

Measured memory_bytes: 256
import bisect
import itertools
import sys


def most_simRL(ds, x):
    index = bisect.bisect_left(ds, x)
    if index == 0:
        return [ds[0]]
    elif index == len(ds):
        return [ds[-1]]
    return ds[index-1:index+1]

if __name__ == '__main__':
    A, B, Q = map(int, input().split())


    s_list = [-sys.maxsize] + [int(input()) for i in range(A)] + [sys.maxsize]
    t_list = [-sys.maxsize] + [int(input()) for i in range(B)] + [sys.maxsize]
    x_list = [int(input()) for i in range(Q)]


    for xi in x_list:
        s_RL = most_simRL(s_list, xi)
        t_RL = most_simRL(t_list, xi)

        answer = sys.maxsize

        for a, b in itertools.product(s_RL, t_RL):
            answer = min(answer, min(abs(xi-a), abs(xi-b)) + abs(a-b))

        print(answer)

Measured memory_bytes: 16144
#include <bits/stdc++.h>
#define int long long
#define uint unsigned int
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(a) (a).begin(), (a).end()
#define ALLR(a) (a).rbegin(), (a).rend()
#define SZ(a) ((int)(a).size())
#define PB(a) push_back(a)
#define EMP emplace
#define EMPB(...) emplace_back(__VA_ARGS__)
#define MP(a, b) make_pair(a, b)
#define MT(...) make_tuple(__VA_ARGS__)
#define Bit(n) (1LL << (n))
using namespace std;
using pii = pair<int, int>;
template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
const int MOD = 1000000007;
const int INF = 1LL << 30;
const double EPS = 1e-10;

int N;
int A[100010], B[100010];
int v[100010];

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N;
  int sum = 0;
  REP(i, N) {
    cin >> A[i] >> B[i];
    sum += A[i];
    v[i] = A[i]+B[i];
  }
  sort(v, v+N, greater<int>());
  int ans = sum;
  REP(i, N) {
    if (i & 1) ans -= v[i];
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 2560
using System;
using System.Collections.Generic;
using System.Linq;

namespace Test01
{
    class Program
    {
        const int INF = 1000000009;
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());

            int[] dp = (new int[N + 1]).Select(x => INF).ToArray();
            dp[0] = 0;
            int[] six = new int[8];
            int[] nine = new int[8];
            six[0] = 1;
            for (int i = 1; i <= 7; i++) six[i] = six[i - 1] * 6;
            nine[0] = 1;
            for (int i = 1; i <= 7; i++) nine[i] = nine[i - 1] * 9;

            for(int i = 0; i < N; i++)
            {
                dp[i + 1] = Math.Min(dp[i + 1], dp[i] + 1);
                for (int j = 1; j <= 7; j++) if (i + six[j] <= N) dp[i + six[j]] = Math.Min(dp[i + six[j]], dp[i] + 1);
                for (int j = 1; j <= 7; j++) if (i + nine[j] <= N) dp[i + nine[j]] = Math.Min(dp[i + nine[j]], dp[i] + 1);
            }

            Console.WriteLine(dp[N]);
        }
    }
}


Measured memory_bytes: 12896
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#define int long long
#define REP(i,n) for(int i=0; i<n; i++)
#define pb push_back
#define MOD 1000000007
#define IDE 0

using namespace std;

const int MAX_N = 1 << 17;
int n, dat[2 * MAX_N - 1];

void init(int n_) {
    n = 1;
    while (n < n_) n *= 2;
    REP(i,2 * n - 1) dat[i] = IDE;
}

int segfunc(int n, int m) {
    if (n == 0 && m == 0) return 0;
    //cout << "gcd: " << n << " " << m  << " ";
    if (n > m) {int t = m; m = n; n = t;}
    //cout << n << " " << m;
    while (1) {
        n = n % m;
        int t = m; m = n; n = t;
        if (m == 0) break;
    }
    //cout << " " << m << "\n"; 
    //cout << n << "\n";
    return n;
}

//k番目の値(0-indexed)をaに変更
void update(int k, int a) {
    k += n - 1;
    dat[k] = a;
    while (k > 0) {
        k = (k - 1) / 2;
        dat[k] = segfunc(dat[k * 2 + 1], dat[k * 2 + 2]);
    }
}

int query(int a, int b, int k, int l, int r) {
    //cout << "query: " << a << b << k << l << r << "\n";
    if (r <= a || b <= l) return IDE;
    if (a <= l && r <= b) return dat[k];
    else {
        int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
        int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
        return segfunc(vl, vr);
    }
}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);    
    int q;
    cin >> n;
    int len = n;
    init(n);
    REP(i, len) {
        int a;
        cin >> a;
        update(i,a);
    }
    int ans = 0;
    REP(i, len) {
        int ans_t = segfunc(query(0,i,0,0,n),query(i+1,len,0,0,n));
        //cout << "ans_t: " << i << " " << ans_t << "\n";
        if (ans_t > ans) ans = ans_t;
    }
    cout << ans << "\n";
    return 0;
}

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

int main() {
	string s;
	cin>>s;
	int num=0;
	for(int i=0;i<s.size();i++){
	    if(s[i]=='+'){
	        num++;
	    }
	    else num--;
	}
	cout<<num<<endl;
	return 0;
}


Measured memory_bytes: 3560
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <array>
#include <list>
#include <stack>
#include <valarray>

using namespace std;

typedef unsigned uint;
typedef long long Int;
typedef unsigned long long UInt;

const int INF = 1001001001;
const Int INFLL = 1001001001001001001LL;

template<typename T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<typename T> void chmin(T& a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T& a, T b) { if (a < b) a = b; }
int in() { int x; scanf("%d", &x); return x; }
double fin() { double x; scanf("%lf", &x); return x; }
Int lin() { Int x; scanf("%lld", &x); return x; }

int pos[100050];
vector<pair<int, Int>> gs[100050];
pair<int, Int> si[100050];
Int X[100050], W[100050];

struct edge {
  int src, dst;
  Int len;
  edge(int s, int d, Int l) : src(s), dst(d), len(l) { }
};

int main() {
  int N = in();
  int M = in();
  for (int i = 0; i < N; ++i) {
    X[i] = lin();
  }

  vector<edge> E;
  for (int i = 0; i < M; ++i) {
    int a = in() - 1;
    int b = in() - 1;
    int y = in();
    E.emplace_back(a, b, y);
  }
  sort(E.begin(), E.end(), [] (const edge& a, const edge& b) {
    return a.len < b.len;
  });

  for (int i = 0; i < N; ++i) {
    si[i] = make_pair(1, X[i]);
    gs[i].emplace_back(i, X[i]);
    pos[i] = i;
    W[i] = X[i];
  }

  for (const edge& e : E) {
    if (pos[e.src] == pos[e.dst]) {
      continue;
    }
    int ui = pos[e.src], vi = pos[e.dst];
    if (gs[ui].size() < gs[vi].size()) {
      swap(ui, vi);
    }

    for (int k = 0; k < (int)gs[vi].size(); ++k) {
      pos[gs[vi][k].first] = ui;
      gs[ui].emplace_back(gs[vi][k].first, k < si[vi].first ? si[vi].second : gs[vi][k].second);
    }
    W[ui] += W[vi];
    gs[vi].clear();

    if (W[ui] >= e.len) {
      si[ui] = make_pair(gs[ui].size(), W[ui]);
    }
  }

  for (int i = 0; i < N; ++i) {
    for (int k = 0; k < (int)gs[i].size(); ++k) {
      X[gs[i][k].first] = k < si[i].first ? si[i].second : gs[i][k].second;
    }
  }

  int res = 0;
  for (int i = 0; i < M; ++i) {
    if (E[i].len <= min(X[E[i].src], X[E[i].dst])) {
      ++res;
    }
  }

  printf("%d\n", M - res);

  return 0;
}


Measured memory_bytes: 24176
#include <iostream>

using namespace std;


int main() {

  int s1,s2;

  int max,max_id;


  while(cin >> s1 >> s2) {

    if(s1==0 && s2==0) break;

    max=s1+s2;
    
    max_id=0;

    for(int i=1;i<5;i++) {

      cin >> s1 >> s2;

      if(max<s1+s2) {

	max=s1+s2;

	max_id=i;

      }

    }

    cout << (char)('A'+max_id) << " " << max << endl;

  }

  return 0;

}

Measured memory_bytes: 0
def I(): return int(input())
def MI(): return map(int, input().split())
def LMI(): return list(map(int, input().split()))


# 桁DPによる数え上げ
# dp[i][smaller][j] = 上からi桁目までで0でない桁がj個ある数字の数
N = input()
K = I()
l = len(N)
dp = [[[0] * (K + 1) for _ in range(2)] for _ in range(l + 1)]
dp[0][False][0] = 1
for i in range(1, l + 1):
    N_i = int(N[i - 1])
    for smaller in [True, False]:  # smaller := Nより小さいことが確定している
        for j in range(K + 1):
            for d in range((9 if smaller else N_i) + 1):
                if j + (0 if d == 0 else 1) <= K:
                    dp[i][smaller or d < N_i][j + (0 if d == 0 else 1)] += dp[i - 1][smaller][j]

print(dp[l][True][K] + dp[l][False][K])


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

using namespace std;

#define intt long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int main() {

	FAST;

	char x;
	cin >> x;
	if (isupper(x)) cout << "A\n";
	else cout << "a\n";
	return 0;
}

Measured memory_bytes: 3612
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>


typedef long double ld;
typedef long long ll;

using namespace std;

#define MAXN (1 << 20)

int a[MAXN];

int main() {
	int n;
	int s = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		s ^= a[i];
	}
	for (int i = 0; i < n; i++) {
		cout << (a[i] ^ s) << " ";
	}
	cout << endl;
	return 0;
}


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

int main(){
    int i;
    char a[5],b[5],c[5];
    
    scanf("%s",a);
    scanf("%s",b);
    scanf("%s",c);
    
    printf("%c%c%c\n",a[0],b[1],c[2]);
    
    return 0;
}

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

using namespace std;
using ll = long long;
using pii = pair<int, int>;

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz size()

const int N = 1e5 + 5;
const int MOD = 1e9 + 7;

ll bigMod(ll a, ll p){
  ll ret = 1LL;
  while(p){
    if(p & 1)ret = (ret * a) % MOD;
    a = (a * a) % MOD;
    p >>= 1LL;
  }
  return ret;
}

ll G[N];

int main(){

  int n, k;
  cin >> n >> k;

  for(ll i = 1; i <= k; i++){
    G[i] = bigMod( k / i, n);
    G[i] %= MOD;
  }

  for(int i = k; i >= 1; i--){
    for(int j = 2 * i; j <= k; j += i)G[i] -= G[j];
  }
    
  ll ans = 0LL;
  for(ll i = 1; i <= k; i++)ans = (ans + G[i] * i) % MOD;

  if(ans < 0)ans += MOD;

  cout << ans << '\n';

  return 0;
}

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

int main(){
  int n;
  while(1){
    cin>>n;
    if(!n)break;
    int pm,pe,pj;
    rep(i,n){
      cin>>pm>>pe>>pj;
      int average=(pm+pe+pj)/3;
      if(pm==100 || pe==100 || pj==100)cout<<"A"<<endl;
      else if((pm+pe)/2>=90)cout<<"A"<<endl;
      else if(average>=80)cout<<"A"<<endl;
      else if(average>=70)cout<<"B"<<endl;
      else if(average>=50 &&(pm>=80 || pe>=80))cout<<"B"<<endl;
      else cout<<"C"<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1156
N = int(input())

task = [[0,0] for _ in range(N)]
for i in range(N):
    task[i][0],task[i][1] = map(int,input().split())

t = 0
t_limit = 0
task_s = sorted(task, key=lambda x: x[1])
ans = 1

for i in range(N):
    t += task_s[i][0]
    t_limit = task_s[i][1]

    if(t > t_limit):
        ans = 0
        break

if(ans):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 78964
def main():
    import sys
    my_input = sys.stdin.readline
    H, W, K = map(int, my_input().split())
    V = [[0] * W for _ in range(H)]
    for i in range(K):
        h, w, v = map(int, my_input().split())
        h, w = h - 1, w - 1
        V[h][w] = v

    # dp1 ~ 4[h][w][x] := h行w列にいて、h行からn個アイテムを拾っている時の価値の総和の最大値
    dp1 = [[0] * (W + 1) for _ in range(H + 1)]
    dp2 = [[0] * (W + 1) for _ in range(H + 1)]
    dp3 = [[0] * (W + 1) for _ in range(H + 1)]

    for h in range(1, H + 1):
        for w in range(1, W + 1):
            dp1[h][w] = max(
                dp1[h][w],
                dp3[h - 1][w] + V[h - 1][w - 1],
                dp1[h][w - 1]
            )

            dp2[h][w] = max(
                dp2[h][w],
                dp3[h - 1][w] + V[h - 1][w - 1],
                dp2[h][w - 1],
                dp1[h][w - 1] + V[h - 1][w - 1]
            )

            dp3[h][w] = max(
                dp3[h][w],
                dp3[h - 1][w] + V[h - 1][w - 1],
                dp3[h][w - 1],
                dp2[h][w - 1] + V[h - 1][w - 1]
            )

    print(dp3[-1][-1])


if __name__ == "__main__":
    main()


Measured memory_bytes: 357588
# AtCoder Beginner Contest 042
# B - 文字列大好きいろはちゃんイージー / Iroha Loves Strings (ABC Edition)
N, L = map(int, input().split())
S = ['' for i in range(N)]
for i in range(N):
    S[i] = input()
S.sort()
for i in range(N):
    print(S[i], end='')
print('')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_n=200005;
const ll inf=0x3f3f3f3f3f3f3f3f;
struct Seg//min 
{
    #define lson l,mid,rt<<1
    #define rson mid+1,r,rt<<1|1
    ll d[1<<20],lazy[1<<20];
    void pushup(int rt)
    {
        d[rt]=min(d[rt<<1],d[rt<<1|1]);
    }
    void pushdown(int rt,int ln=1,int rn=1)
    {
        if(lazy[rt])
        {
            d[rt<<1]+=lazy[rt]*ln;
            d[rt<<1|1]+=lazy[rt]*rn;
            lazy[rt<<1]+=lazy[rt];
            lazy[rt<<1|1]+=lazy[rt];
            lazy[rt]=0;
        }
    }
    void init(int l,int r,int rt)
    {
        d[rt]=inf,lazy[rt]=0;
        if(l==r)return;
        int mid=l+r>>1;
        init(lson),init(rson);
    }
    void ins(int x,ll c,int l,int r,int rt)
    {
        if(l==r)
        {
            d[rt]=min(d[rt],c);
            return;
        }
        int mid=l+r>>1;
        pushdown(rt);
        if(x<=mid)ins(x,c,lson);
        else ins(x,c,rson);
        pushup(rt);
    }
    void update(int L,int R,int C,int l,int r,int rt)
    {
        if(L>R)return;
        if(l>=L&&r<=R)
        {
            d[rt]+=C;
            lazy[rt]+=C;
            return;
        }
        int mid=l+r>>1;
        pushdown(rt);
        if(mid>=L)update(L,R,C,lson);
        if(mid<R)update(L,R,C,rson);
        pushup(rt);
    }
    ll query(int L,int R,int l,int r,int rt)
    {
        if(L>R||L>r||R<l)return inf;
        if(l>=L&&r<=R)return d[rt];
        int mid=l+r>>1;
        pushdown(rt);
        return min(query(L,R,lson),query(L,R,rson));
    }
}Tree1,Tree2,Tree3;
int n,q,a,b;
int x[max_n];
int main(){
    scanf("%d%d%d%d",&n,&q,&a,&b);
    Tree1.init(1,n,1),Tree2.init(1,n,1),Tree3.init(1,n,1);
    for(int i=1;i<=q;i++)scanf("%d",x+i);
    for(int i=1;i<=q;i++){
        if(i==1){
            Tree1.ins(b,abs(a-x[1])+b,1,n,1);
            Tree2.ins(b,abs(a-x[1])-b,1,n,1);
            Tree3.ins(b,abs(a-x[1]),1,n,1);
            Tree1.ins(a,abs(b-x[1])+a,1,n,1);
            Tree2.ins(a,abs(b-x[1])-a,1,n,1);
            Tree3.ins(a,abs(b-x[1]),1,n,1);
        }
        else{
            ll val=Tree1.query(x[i],n,1,n,1)-x[i];
            val=min(val,Tree2.query(1,x[i]-1,1,n,1)+x[i]);
            Tree1.update(1,n,abs(x[i]-x[i-1]),1,n,1);
            Tree2.update(1,n,abs(x[i]-x[i-1]),1,n,1);
            Tree3.update(1,n,abs(x[i]-x[i-1]),1,n,1);
            Tree1.ins(x[i-1],val+x[i-1],1,n,1);
            Tree2.ins(x[i-1],val-x[i-1],1,n,1);
            Tree3.ins(x[i-1],val,1,n,1);
        }
    }
    printf("%lld\n",Tree3.query(1,n,1,n,1));
    return 0;
}

Measured memory_bytes: 37120
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long int64;


int main()
{
  int N, C;
  int64 now[100000] = {};

  scanf("%d %d", &N, &C);
  tree< pair< int64, int >, null_type, less< pair< int64, int > >, rb_tree_tag, tree_order_statistics_node_update > beet;
  for(int i = 0; i < N; i++) beet.insert({0LL, i});
  while(C--) {
    int T;
    scanf("%d", &T);
    if(T == 0) {
      int a, b;
      scanf("%d %d", &a, &b);
      --a;
      beet.erase({now[a], a});
      now[a] -= b;
      beet.insert({now[a], a});
    } else {
      int m;
      scanf("%d", &m);
      auto p = beet.find_by_order(m - 1);
      printf("%d %lld\n", p->second + 1, -p->first);
    }
  }
}

Measured memory_bytes: 10268
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1{
    class Program{
        static void Main(string[] args){
            for (int i = 1; i < 10; i++){
                for (int j = 1; j < 10; j++){
                    Console.WriteLine(i+"x"+j+"="+i*j);
                }
            }
        }
    }
}

Measured memory_bytes: 5532
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

int main(void) {
	int n;
	cin >> n;
	
	vector<ll> a(n), b(n);
	ll add_a = 0LL, add_b = 0LL;
	for(int i = 0; i < n; ++i) {
		cin >> a[i];
		add_a += a[i];
	}
	
	for(int i = 0; i < n; ++i) {
		cin >> b[i];
		add_b += b[i];
	}
	
	ll limit = add_b - add_a;
	
	ll one = 0LL, two = 0LL;
	for(int i = 0; i < n; ++i) {
		if( a[i] < b[i] ) {
			two += (b[i] - a[i] + 1LL) / 2LL;
		} else if( a[i] > b[i] ) {
			one += a[i] - b[i];
		}
	}
	
	if( limit >= one && limit >= two ) cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return 0;
}


Measured memory_bytes: 3768
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;

int n,m,k,b,ans,a[101];

int main(void)
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)
    {
        scanf("%d",&b);
        for(int j=1;j<=b;j++)
        {
            scanf("%d",&k);
            a[k]++;
        }
    }
    
    for(int i=1;i<=n;i++)
    {
        if(!a[i]) ans++;
    }
    
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 3828
#include<bits/stdc++.h>
#define MAXN 45
#define MAXW 205
#define MAXA 405
#define INF 1000000000
using namespace std;
int N,ma,mb,a[MAXN],b[MAXN],c[MAXN];
int dp[MAXN][MAXA][MAXA];
int main()
{
	scanf("%d%d%d",&N,&ma,&mb);
	for(int i=1;i<=N;i++) scanf("%d%d%d",&a[i],&b[i],&c[i]);
	for(int i=0;i<=N;i++)
        for(int j=0;j<=400;j++)
            for(int k=0;k<=400;k++)
                dp[i][j][k]=INF;
	dp[0][0][0]=0;
	for(int i=1;i<=N;i++)
        for(int A=0;A<=40*i;A++)
            for(int B=0;B<=40*i;B++)
            {
                dp[i][A][B]=dp[i-1][A][B];
                if(A>=a[i]&&B>=b[i]) dp[i][A][B]=min(dp[i][A][B],dp[i-1][A-a[i]][B-b[i]]+c[i]);
            }
    int ans=INF;
    for(int i=1;i<=400;i++)
        for(int j=1;j<=400;j++)
            if(i*mb==j*ma) ans=min(ans,dp[N][i][j]);
    if(ans==INF) printf("-1"); else printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 28928
//おまじないc++
#include <iostream>
#include<cmath>
#include<vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;

int main() {

	string  s;

	cin >> s;

	int size = s.size();
	int c = 0;

	for (int i = 0; i < size / 2; i++) {
		if (s.at(i) != s.at(size - i-1)) {
			c++;
		}
	}

	cout << c;
}

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

int main()
{
  string a,b,c;
  cin >> a >> b;
  c = b[b.length()-1];
  a = a + c;
  if( a==b )
    cout <<"Yes";
  else
    cout <<"No";
  return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define showmap(is, js, x) {rep(i, is){rep(j, js){cout << x[i][j] << " ";}cout << endl;}}
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> llP;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}


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

    ll p = 1;
    ll m = -1;

    vector<ll> th;

    ll bai = 1;
    vector<ll> m2;

    const int max_bit = 35;
    rep(i, max_bit){
        m2.push_back(bai);
        if (i%2 == 0){
            th.push_back(p);
            p += bai;
        } else {
            th.push_back(m);
            m += bai;
        }
        bai *= -2;
    }

  //  show(th);

    ll nn = n;
    vector<int> bit(max_bit, 0);
    for (int i = max_bit - 1; i >= 0; i--)
    {
        if (i%2 == 0){
            if (th[i] <= nn) {nn -= m2[i]; bit[i] = 1;}
        } else {
            if (th[i] >= nn) {nn -= m2[i]; bit[i] = 1;}
        }
    }
    
    //show(bit);

    bool iswrite = false;
    for (int i = max_bit - 1; i >= 0; i--)
    {
        if (bit[i] == 1){
            iswrite = true;
        }
        if (iswrite) cout << bit[i];
    }
    
    if (!iswrite) {cout << 0 << endl; return 0;}
    cout << endl;
    
}



Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int a, b, c, k[5];
	for (int i = 0; i < 3; ++i) {
		cin >> k[i];
	}
	sort(k, k + 3);
	a = k[0];
	b = k[1];
	c = k[2];
	int ans = 0;
	if (3 * c % 2 == (a + b + c) % 2) {
		while (b != c) {
			a++;
			b++;
			ans++;
		}
		while (a != b) {
			a += 2;
			ans++;
		}
	}
	else {
		ans++;
		c++;
		b++;
		while (b != c) {
			a++;
			b++;
			ans++;
		}
		while (a != b) {
			a += 2;
			ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp;

fn run() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let a: usize = sc.read();
    let b: String = sc.read::<String>();
    // b.retain(|x| x != '.');
    let b = b.split(".").collect::<Vec<&str>>();

    let ans = a * b[0].parse::<usize>().unwrap() + a * b[1].parse::<usize>().unwrap() / 100;
    println!("{}", ans);
}

fn main() {
    std::thread::Builder::new()
        .name("run".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(run)
        .unwrap()
        .join()
        .unwrap();
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn read_pairs<T: std::str::FromStr>(&mut self, n: usize) -> Vec<(T, T)> {
        (0..n).map(|_| (self.read(), self.read())).collect()
    }
    pub fn read_pairs_1_indexed(&mut self, n: usize) -> Vec<(usize, usize)> {
        (0..n)
            .map(|_| (self.read::<usize>() - 1, self.read::<usize>() - 1))
            .collect()
    }
    pub fn read_chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
    pub fn read_char_grid(&mut self, n: usize) -> Vec<Vec<char>> {
        (0..n).map(|_| self.read_chars()).collect()
    }
    pub fn read_matrix<T: std::str::FromStr>(&mut self, n: usize, m: usize) -> Vec<Vec<T>> {
        (0..n)
            .map(|_| (0..m).map(|_| self.read()).collect())
            .collect()
    }
}


Measured memory_bytes: 2280
N, K = map(int, input().split())
S = list(input())
    
K -= 1 
if S[K] == "A": 
    S[K] = "a" 
elif S[K] == "B": 
    S[K] = "b" 
elif S[K] == "C": 
    S[K] = "c" 
 
print("".join(S)) 


Measured memory_bytes: 2940
#include<cstdio>
#include<algorithm>
using namespace std;
int n, w[301000], BIT[301000][2];
void Add(int a) {
	int ck = a % 2;
	while (a <= n) {
		BIT[a][ck]++;
		a += (a&-a);
	}
}
int Sum(int a, int ck) {
	int r = 0;
	while (a) {
		r += BIT[a][ck];
		a -= (a&-a);
	}
	return r;
}
int main() {
	int i;
	scanf("%d", &n);
	long long s = 0, s2 = 0;
	for (i = 1; i <= n; i++) {
		scanf("%d", &w[i]);
		Add(w[i]);
		int c1 = Sum(n, 0) - Sum(w[i], 0);
		int c2 = Sum(n, 1) - Sum(w[i], 1);
		s += c1 + c2;
		if (w[i] % 2 != i % 2) {
			puts("No");
			return 0;
		}
		if (i % 2)s2 += c2;
		else s2 += c1;
	}
	if (s % 3 || s/3 < s2) {
		puts("No");
		return 0;
	}
	puts("Yes");
}

Measured memory_bytes: 3712
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define ll long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const ll MAX = 1000000000000000;
static const int NIL = -1;
using namespace std;
const long double EPS = 0.0000000001;
const long double PI = (acos(-1));
const int MOD = 1000000007;

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


Measured memory_bytes: 3564
#include<bits/stdc++.h>
using namespace std;
int main(){
    int r,g,b,K;
    int R,G,B;
    cin >> r >> g >> b;
    cin >> K;

    for(int i = 0; i < K; i++){
      if (g > r && b > g){
        cout << "Yes" << endl;
        return 0;
      } else if (b <= g){
        b *= 2;
      } else {
        g *= 2;
      }
    }
    

    if(g > r && b > g){
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }

}

Measured memory_bytes: 3620
//38
#include<iostream>
#include<vector>
#include<queue>
#include<set>
#include<algorithm>

using namespace std;

struct S{
  int t;
  vector<vector<int> > v;
};

int main(){
  int t;
  cin>>t;
  while(t--){
    vector<vector<int> >v(4,vector<int>(8));
    for(int i=0;i<4;i++){
      v[i][0]=(i+1)*10+1;
      for(int j=1;j<=7;j++){
	cin>>v[i][j];
	if(v[i][j]%10==1){
	  v[i][j]=0;
	}
      }
    }
    S is={0,v};
    queue<S> que;
    que.push(is);
    set<vector<vector<int> > > s;
    while(!que.empty()){
      S c=que.front();
      for(int i=0;i<4;i++){
	for(int j=0;j<7;j++){
	  if(c.v[i][j]!=(i+1)*10+j+1)goto next;
	}
	if(c.v[i].back())goto next;
      }
      break;
    next:
      que.pop();
      if(!s.insert(c.v).second)continue;
      for(int i=0;i<4;i++){
	for(int j=0;j<8;j++){
	  if(c.v[i][j]||c.v[i][j-1]%10==7)continue;
	  S ns={c.t+1,c.v};
	  for(int k=0;k<4;k++){
	    for(int l=0;l<8;l++){
	      if(ns.v[k][l]==ns.v[i][j-1]+1){
		/*
		for(int i=0;i<4;i++){
		  for(int j=0;j<8;j++){
		    cout<<ns.v[i][j]<<' ';
		  }
		  cout<<endl;
		}
		*/
		swap(ns.v[k][l],ns.v[i][j]);
		que.push(ns);
		goto nb;
	      }
	    }
	  }
	nb:
	  ;
	}
      }
    }
    cout<<(que.empty()?-1:que.front().t)<<endl;
  }
  return 0;
}

Measured memory_bytes: 24928
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    B=LI()
    A=LI()
    ans = 0
    for i in range(N):
        ans += max(0,min(A[i],B[i]))
        A[i] -= max(0,B[i])
        ans += max(0,min(A[i],B[i+1]))
        B[i+1]-=max(0,A[i])
    #ans += max(0,min(B[-1],A[-1]))
    print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 73572
#include "bits/stdc++.h"
using namespace std;
int main()
{
	int a, b, c;
	scanf("%d%d%d", &a, &b, &c);
	if(c > a + b)
	{
		printf("%d\n", a + b + 1 + b);
	}
	else
	{
		printf("%d\n", c + b);
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#define REP(i,n) for(int i = 0; n > i; i++)
#define MOD 1000000007
using namespace std;
typedef vector<int> Ivec;
typedef pair<int, int> pii;
typedef long long int ll;

class RMQ {
private:
	static const int MAX_N = 1 << 17;
	int n, dat[2 * MAX_N - 1];
	//[a,b)の最小値を返す
	//kは節点の番号l,rはその節点が[l,r)を保持している
	int rec(int a, int b, int k, int l, int r) {
		if (b <= l || r <= a) {
			return INT_MAX;
		}

		if (a <= l && r <= b) {
			return dat[k];
		}
		else {
			int rl = rec(a, b, 2 * k + 1, l, (l + r) / 2);
			int rr = rec(a, b, 2 * k + 2, (l + r) / 2, r);
			return min(rl, rr);
		}
	}

public:
	void init(int n_) {
		n = 1;
		while (n < n_) n *= 2;

		for (int i = 0; i<2 * n - 1; i++) {
			dat[i] = INT_MAX;
		}
	}

	//kをaに変更
	void update(int k, int a) {
		int reaf = k + n - 1;
		dat[reaf] = a;
		while (reaf>0) {
			reaf = (reaf - 1) / 2;
			dat[reaf] = min(dat[reaf * 2 + 1], dat[2 * reaf + 2]);
		}
	}

	//query[a,b]の範囲内の最小値を返す
	int query(int a, int b) {
		return rec(a, b + 1, 0, 0, n);
	}
};

int main() {
	int n, x;
	RMQ r;
	scanf("%d %d", &n, &x);
	vector<int> a(n);
	r.init(n);
	REP(i, n) {
		scanf("%d", &a[i]);
		r.update(i, a[i]);
	}
	ll ans = LLONG_MAX;

	for (int ccou = 0; n > ccou; ccou++) {
		ll bufans = 0;
		REP(i, n) {
			int num = i - ccou;
			if(num < 0)
				bufans += min(r.query(0, i),r.query(n+num, n-1));
			else bufans += r.query(num,i);
		}
		bufans += (ll)x*ccou;
		ans = min(ans, bufans);
	}
		printf("%lld\n",ans);
	return 0;
}

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

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecbool vector<bool>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)


int main()
{
  ll n, t, count=0, tmp, time=0;
  cin >> n >> t;
  cin >> tmp;  // drop 0
  forll(i, 1, n){
	cin >> tmp;
	count += min(tmp-time, t);
	time = tmp;
  }
  cout << count + t << endl;
}


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

set<int> make_divisors(int a) {
    set<int> ret;
    for (int d = 1; d*d <= a; d++) {
        if (a % d == 0) {
            ret.insert(d);
            ret.insert(a / d);
        }
    }
    return ret;
} 

int main() {
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 1; i <= n; i += 2) {
        if (make_divisors(i).size() == 8) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int H, W;
vector<string> grid;

int main(void){
	
	scanf("%d %d", &H, &W);
	for(int i = 0; i < H; ++i){
	    string s; cin >> s;
	    int num = 0;
	    for(auto j : s) if(j == '.') ++num;
	    if(num != W) grid.push_back(s); 
	}
    
    for(int j = 0; j < W; ++j){
        int num = 0;
        for(int i = 0; i < grid.size(); ++i) if(grid[i][j] == '.') ++num;
        if(num == grid.size()){
            for(int i = 0; i < grid.size(); ++i){
                grid[i].erase(grid[i].begin() + j);
            }
            --j;
        }
    }
    
    for(int i = 0; i < grid.size(); ++i){
        for(int j = 0; j < grid[i].size(); ++j) cout << grid[i][j];
        cout << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <climits>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <tuple>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <vector>
#include <iterator>
#include <regex>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define FOR(x,xs) for(auto &x: xs)

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef vector<int> VI;
typedef vector<ll> VL;

template <class T, template <class, class> class C, class charT = char>
void vdump(const C<T, allocator<T>> &v, const charT* delimiter = ", ",
           ostream &stream = cout) {
  copy(v.begin(), v.end(), ostream_iterator<T>(stream, delimiter));
  stream << endl;
}

int main() {
  ios::sync_with_stdio(false);
  string target = "keyence";
  string s;
  cin >> s;
  int n = s.size();
  REP(i,0,8) {
    if (s.substr(0, i) + s.substr(n - 7 + i) == target) {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;

  return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	keta := keta(n)

	ans := 0
	st := 1
	fin := 10
	for i := 1; i <= keta; i += 2 {
		if fin <= n {
			ans += (fin - st)
		} else {
			ans += (n - st + 1)
		}
		st *= 100
		fin *= 100
	}
	fmt.Println(ans)
}
func keta(num int) int {
	res := 0
	for num/10 != 0 {
		num /= 10
		res++
	}
	return res + 1
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
//自作関数
template<class T> ll llpow(T x,T n){ll ans=1;while(n--){ans*=x;}return ans;}

#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep2(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)

long long INF = 1LL<<60;
int n;
int main(){
    int W;
    cin>>n>>W;
    int w[n],v[n];
    rep(i,n)cin>>w[i]>>v[i];

    vector<vector<ll>> dp(2,vector<ll> (W+1,0));
    for(int i=0;i<n;i++){
        for(int j=0;j<=W;j++){
        chmax(dp[(i+1)%2][j],dp[i%2][j]);
        if(j-w[i]>=0)chmax(dp[(i+1)%2][j],dp[i%2][j-w[i]]+v[i]);
        }
        dp[i%2].assign(W+1,0);
    }
    cout<<dp[n%2][W]<<endl;
    return 0;
}




Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll mod = 1e09;

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

  int k, s;
  cin >> k >> s;

  ll cnt = 0;

  REP(i, k + 1){
    REP(j, k + 1){
      if(i + j <= s && s - (i + j) <= k) cnt++;
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define pvec(v) rep(i,v.size()){cout << v[i] << " ";};cout<<endl;
#define pb push_back
#define pf push_front
#define mod 1e9+7
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;

const double pi = acos(-1.0);
 
ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
    return true;
}

int main()
{
	ll a[7],ans=0,tmp=0;
    rep(i,7) cin >> a[i];
    tmp=a[1]+(a[0]/2)*2+(a[3]/2)*2+(a[4]/2)*2;
    if(a[0]>0 && a[3]>0 && a[4]>0) ans=a[1]+((a[0]-1)/2)*2+((a[3]-1)/2)*2+((a[4]-1)/2)*2+3;
    cout << max(tmp,ans) << endl;
	return 0;
}

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

#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
 
Int INF = 1e18;
int inf = 1e9;
Int mod = 1e9+7;

int main() {
    string s;
    cin >> s;
    Int n = s.size();
    string t = s.substr(0, n / 2);
    string u = s.substr((n + 3) / 2 - 1);
    dump(t == u ? "Yes" : "No");
    return 0;
}

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

int main(void){
    int n, s;
    scanf("%d",&n);
    s = n % 10;

    if(s==2 || s==4 || s==5 || s ==7 || s==9){
        printf("hon");
    }else if(s==0 || s==1 || s==6 || s==8){
        printf("pon");
    }else{
        printf("bon");
    }
    
    return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
#include <string>
#include <cmath>
#include <sstream>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORD(i, a, b) for(int i = (a-1); i >= (b); i--)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
typedef long long int ll;
using namespace std;
//ll mod=1000000007;
//ll mod=67280421310721;
ll mod=998244353;
ll INF=1e18;
ll po(ll a,ll b)
{
	ll re=1;
	while(b)
	{
		if(b%2==1)
		{
			re=(re*a);
			re%=mod;
		}
		a=(a*a);
		a%=mod;
		b>>=1;
	}
	return re;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int test=1;
//	cin>>test;
	while(test--)
	{
		string s;
		int re[2019]={0},dp[2019]={0};
		cin>>s;
		ll ans=0;
//		dp[0]=1;
		FOR(i,0,s.size())
		{
			int g=s[i]-'0';
			ans+=dp[2019-g];
			FOR(i,0,2019)
			{
//				cout<<((i*10)+g)%2019<<' ';
				re[((i+g)*10)%2019]+=dp[i];
			}
			re[(10*g)%2019]++;
			FOR(i,0,2019)
			{
				dp[i]=re[i];
//				if(dp[i]!=0)
//				{
//					cout<<i<<':'<<dp[i]<<" ; ";
//				}
				re[i]=0;
			}
//			cout<<'\n';
		}
		cout<<ans;
	}
	return 0;
}

Measured memory_bytes: 3724
// clang-format off
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i,n) for(ll i=n-1; i>=0; --i)
#define rrep1(i,n) for(ll i=n; i>0; --i)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define SORT_DESC(x) sort(all(x), greater<>())
#define pb push_back
#define mp make_pair
#define coutl cout<<fixed<<setprecision(10)
#define ANS(ans) cout<<ans<<endl;
template<class T>bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if (b<a){a=b;return 1;}return 0;}
const int INF = 1e9;
const ll LINF = 1e18;
// clang-format on

void solve(long long N, long long K, long long R, long long S, long long P, std::string T) {
  ll ans = 0;
  auto win = [=](char c) {
    switch (c) {
    case 'r':
      return P;
    case 's':
      return R;
    case 'p':
      return S;
    }
  };
  vector<string> t(K);
  rep(i, N) t[i % K].pb(T[i]);
  rep(i, K) {
    bool skipped = false;
    rep(j, t[i].size()) {
      if (j > 0 && t[i][j - 1] == t[i][j] && !skipped) {
        skipped = true;
      } else {
        skipped = false;
        ans += win(t[i][j]);
      }
    }
  }

  ANS(ans);
}

int main() {
  long long N;
  scanf("%lld", &N);
  long long K;
  scanf("%lld", &K);
  long long R;
  scanf("%lld", &R);
  long long S;
  scanf("%lld", &S);
  long long P;
  scanf("%lld", &P);
  std::string T;
  std::cin >> T;
  solve(N, K, R, S, P, T);
  return 0;
}


Measured memory_bytes: 5248
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) {
		Scanner stdin = new Scanner( System.in);
		int  a,b,c;
		int i=0,j=0;
		c =stdin.nextInt();
		b =stdin.nextInt();
		a =stdin.nextInt();
		if(b+c+1>a) {
		System.out.print(b+a);
	}else {
		System.out.print(b*2+c+1);
		}
	}
}


Measured memory_bytes: 23764