akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.lang.IllegalArgumentException
import java.lang.StringBuilder
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextInt()
    val k = sc.nextInt()
    val a = Array(n) { sc.nextInt() }
    a.sort()
    println(a.take(k).sum())
}

fun main(args: Array<String>) {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}

Measured memory_bytes: 39160
str1 = str(input())
s1 = str1.split(' ')
n = int(s1[0])
m = int(s1[1])
str2 = str(input())
s2 = str2.split(' ')
l2 = [int(x) for x in s2]
if n<sum(l2):
    print('-1')
else:
    print(n-sum(l2))

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

int main() {
  int n;
  cin >> n;
  
  int s = 0;
  int nn = n;
  while(nn > 0){
    s = s+nn%10;
    nn = nn/10;
  }
  
  if (n%s == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#define rep(i,n) for (int i=0; i<n;++i)
#define rep_down(i,n) for (int i=n-1; i>=0;--i)
#define ALL(a)  (a).begin(),(a).end()
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;
const int INF = 1000000007;
int N, K;
string S;

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

  cin >> N >> K;
  cin >> S;

  vector<int> M;
  bool isInitialHandStand = S[0]=='1';
  bool isLastHandStand = S[N-1]=='1';
  bool isHandStand = isInitialHandStand;
  int cnt = 0;

  // 最初直立→最初0人が番兵していると考える
  // 最後直立→最後0人が番兵していると考える
  if (!isInitialHandStand) {
    M.push_back(cnt);
  }
  rep(i, N){
    char c = S[i];
    if ((c == '0' && isHandStand) || (c == '1' && !isHandStand)){
      M.push_back(cnt);
      isHandStand = !isHandStand;
      cnt = 1;
    } else cnt++;
  }
  M.push_back(cnt);
  if (!isLastHandStand) {
    M.push_back(0);
  }

  int sz = (int)M.size();
  if (sz <= 2*K+1){
    cout << N << "\n";
    return 0;
  }

  vector<int> Sm(sz+1, 0); //計算のため, Sm[0] = 0とする
  Sm[0] = 0;
  rep(i, M.size()) Sm[i+1] = Sm[i] + M[i];
  
  int ans = 0;
  for (int idx=0; idx<sz-2*K; idx+=2) {
    ans = max(ans, Sm[idx+2*K+1]-Sm[idx]);
  }

  cout << ans  << "\n";
  return 0;
}

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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, m, t;
  cin >> n >> m >> t;
  vector<int> can(t, 1);
  while (n--) {
    int a;
    cin >> a;
    for (int i = a - m; i < min(a + m, t); ++i) {
      can[i] = 0;
    }
  }
  int res = accumulate(begin(can), end(can), 0);
  cout << res << '\n';
}



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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

bool is_prime(int n){
  for(int i=2; i*i<=n; i++){
    if(n%i==0)return false;
  }
  return true;
}

int main(){
  ll n; cin>>n;
  vector<ll>p(n);
  rep(i, n)cin>>p[i];

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

  map<ll, ll> m;
  for(auto t: p) m[t]++;

  ll result=0;

  rep(i, n){
    ll c = p[i];
    ll count = m[c];

    if(count==0)continue;
    if(count==1)result++;

    m[c]=0;

    ll num=c;
    while(num<=1000000){
      num+=c;
      m[num]=0;
    }
  }

  cout<<result<<endl;

  return 0;
}

Measured memory_bytes: 71152
///
// File:  0013.cpp
// Author: ymiyamoto
//
// Created on Mon Nov 20 21:20:22 2017
//

#include <cstdint>
#include <iostream>
#include <stack>

using namespace std;

int32_t main()
{
  stack<uint32_t> s;
  while (true) {
    uint32_t n;
    cin >> n;
    if (cin.eof()) break;

    if (n == 0) {
      cout << s.top() << endl;
      s.pop();
    } else {
      s.push(n);
    }
  }
  return 0;
}

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

deque<int> dq;
string s;

int main()
{
    cin >> s;
    dq.clear();
    for (int i = 0; i < s.size(); ++ i) {
        if (s[i] == '0') dq.push_back(0);
        if (s[i] == '1') dq.push_back(1);
        if (s[i] == 'B') if(!dq.empty()) dq.pop_back();
    }
    while(!dq.empty()) {
        cout << dq.front();
        dq.pop_front();
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
//#include"pch.h"
//#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<cmath>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;
typedef long long ll;

	ll A[1100], B[1100], C[1100];
	ll AB[1000100];
	ll ABC[3000000];


int main() {

	ll X, Y, Z, K;
	ll cnt = 0;

	scanf("%lld %lld %lld %lld", &X, &Y, &Z, &K);

	for (int i = 0; i < X; i++) {
		scanf("%lld", &A[i]);
	}
	for (int i = 0; i < Y; i++) {
		scanf("%lld", &B[i]);
	}
	for (int i = 0; i < Z; i++) {
		scanf("%lld", &C[i]);
	}
	for (int i = 0; i < X; i++) {
		for (int j = 0; j < Y; j++) {
			AB[cnt] = A[i] + B[j];
			cnt++;
		}
	}
	cnt = 0;
	sort(AB, AB + X * Y,greater<ll>());
	for (int i = 0; i < K; i++) {
		for (int j = 0; j < Z; j++) {
			ABC[cnt] = AB[i] + C[j];
			cnt++;
		}
	}
	sort(ABC, ABC + K * Z, greater<ll>());
	for (int i = 0; i < K; i++) {
		printf("%lld\n", ABC[i]);
	}
	return(0);
}

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

// 定義
typedef long long         ll;
typedef pair<ll, ll>      P;
#define ALL(x)            (x).begin(),(x).end()
#define REP(i, n)         for(ll i = 0 ; i < (ll)n ; ++i)
#define REPN(i, m, n)     for(ll i = m ; i < (ll)n ; ++i)
#define VL                vector<ll>
#define VVL               vector<vector<ll>>
#define VVVL              vector<vector<vector<ll>>>
#define VC                vector<char>
#define VVC               vector<vector<char>>
#define INF               (ll)2e9
#define INF_LL            1LL<<60
//#define MOD             998244353
#define MOD               1000000007

ll Ceil(ll val, ll div)   { return (val + div - 1) / div; }
ll CeilN(ll val, ll div)  { return Ceil(val, div) * div; }
ll FloorN(ll x, ll n)     { return (x - x % n); }
bool IsOdd(ll x)          { return ((x & 1) == 1); }
bool IsEven(ll x)         { return ((x & 1) == 0); }
template<class T> bool chmax(T& a, T b) { if (a <= b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, T b) { if (a >= b) { a = b; return 1; } return 0; }


// 一次元累積和
template<class T>
class Ruiseki
{
private:
	int num;

public:
	vector<T> sumVal;
	Ruiseki(const vector<T> &srcVal)
	{
		num = srcVal.size();
		sumVal.resize(num + 1, 0);
		for (int i = 0; i < num; i++) {
			sumVal[i + 1] = sumVal[i] + srcVal[i];
		}
	}

	T GetSumAll()
	{
		return sumVal[num];
	}

	// [start, endIdx) ※endIdxは含まない
	T GetSumRange(int startIdx, int endIdx)
	{
		return sumVal[endIdx] - sumVal[startIdx];
	}

	// [0, endIdx) ※endIdxは含まない
	T GetSumFromTop(int endIdx)
	{
		return sumVal[endIdx] - sumVal[0];
	}

	// [startIdx, N] ※startIdxは含む
	T GetSumFromEnd(int startIdx)
	{
		return sumVal[num] - sumVal[startIdx];
	}
};

void Solve()
{
	ll N, M;
	cin >> N >> M;
	VL SA(N);
	REP(i, N) cin >> SA[i];
	sort(ALL(SA), greater<ll>());
	VL GA = SA;
	reverse(ALL(SA));

	// a   = aa,                                = 2
	// ab  = aa, ab,     ba, bb,                = 4
	// abc = aa, ab, ac, ba, bb, bc, ca, cb, cc = 6

	auto compExec = [&](ll mid, ll &res) {
		ll cnt = 0;
		for (auto &g : GA) {
			ll nokori = mid - g;
			ll numOne = SA.end() - lower_bound(ALL(SA), nokori);
			if (numOne == 0) break;
			cnt += numOne;
		}
		res = cnt;
		return (M <= cnt);
	};

	ll lb = 0;//SA[0] * 2;
	ll lu = GA[0] * 2 + 1;
	ll mid = 0;
	ll res;
	while ((lb + 1) != lu) {
		mid = (lb + lu) / 2;
		if (compExec(mid, res)) {
			lb = mid;
		} else {
			lu = mid;
		}
	}

	ll ans = 0;
	ll cnt = 0;
	Ruiseki<ll> rui(SA);
	for (auto &g : GA) {
		ll nokori = lu - g;
		auto it = lower_bound(ALL(SA), nokori);
		if (it == SA.end()) continue;
		ll pos = it - SA.begin();
		ll ansOne = rui.GetSumFromEnd(pos);
		ans += (ansOne + g * (N - pos));
		cnt += (N - pos);
	}

	ll nokori = M - cnt;
	ans += nokori * lb;

	cout << ans << endl;
}

// メイン
int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Solve();
	return 0;
}


Measured memory_bytes: 5576
#include<iostream>
#include<cstdio>
#include<map>
#define ll long long
using namespace std;
int T,d;
int w[5],dv[5]={2,3,5};
ll n;
const ll inf=4e18;
map<ll,ll>f;
ll dfs(ll x){
	if(!x)return 0;
	if(f[x])return f[x];
	ll res=x>inf/d?inf:x*d;
	for(register int i=0;i<3;i++){
		ll y=x/dv[i];
		res=min(res,dfs(y)+w[i]+(x-y*dv[i])*d);
		y=(x+dv[i]-1)/dv[i];
		res=min(res,dfs(y)+w[i]+(y*dv[i]-x)*d);
	}
	return f[x]=res;
}
int main(){
	scanf("%d",&T);
	while(T--){
		scanf("%lld%d%d%d%d",&n,&w[0],&w[1],&w[2],&d);
		f.clear();
		f[1]=d;
		printf("%lld\n",dfs(n));
	}
	return 0;
}

Measured memory_bytes: 4652
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include<ctime>
#include<random>
#include<cstring>
#include<cstdlib>
#include<cstdint>
#include<fstream>
#include<strstream>
#include<vector>
#include<string>

//#include "D:\Code\C++\Headers\zle_CSV.h"

#define ll long long
#define US unsigned
#define UINT unsigned int

using namespace std;



int main() {
	int X, N;
	int ans;
	vector<int> A;
	cin >> X >> N;
	A.resize(N);
	for (int c = 0; c < N; c++) {
		cin >> A[c];
	}


	ans = X;
	int pans = X;
	int nans = X;


		for (int c = 0; c < N; c++) {
			if (A[c] == pans) {
				pans++;
				c = -1;
			}			
		}

		for (int c = 0; c < N; c++) {
			if (A[c] == nans) {
				nans--;
				c = -1;
			}
		}
	
		if ((pans - ans) > (ans - nans)) {
			cout << nans << endl;
		}
		else if ((pans - ans) < (ans - nans)) {
			cout << pans << endl;
		}
		else {
			cout << nans << endl;
		}


	return 0;
}

Measured memory_bytes: 3628
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

/*
	?????°???????????¨
	???????????° 2n (m<=n=2^e)
	?????¨??? ??????????????????
		?????????
		?????¨????????????
		??¨??????????????????
*/
struct Monoid {
	using T = int;
	T operator()(const T &a, const T& b) { return min(a, b); }
	static const T I = INT_MAX;
};
struct SegmentTree {
	using T = Monoid::T;
	Monoid op;
	int n;
	vector<T> d;
	SegmentTree(int m) {
		for (n = 1; n < m; n *= 2);
		d.assign(2 * n - 1, op.I);
	}
	void update(int k, T x) {
		k += n - 1;
		d[k] = x;
		while (k > 0) {
			k = (k - 1) / 2;
			d[k] = op(d[2 * k + 1], d[2 * k + 2]);
		}
	}
	T query(int a, int b, int k, int l, int r) {
		if (r <= a || b <= l)return op.I;
		if (a <= l&&r <= b)return d[k];
		int xl = query(a, b, 2 * k + 1, l, (l + r) / 2);
		int xr = query(a, b, 2 * k + 2, (l + r) / 2, r);
		return op(xl, xr);
	}
	T query(int a, int b) {
		return query(a, b, 0, 0, n);
	}
};

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, q; cin >> n >> q;
	SegmentTree st(n);
	rep(i, 0, q) {
		int com, x, y; cin >> com >> x >> y;
		dump(com, x, y);
		if (com == 0) {
			st.update(x, y);
		}
		else {
			cout << st.query(x, y + 1) << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3908
#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 <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;

int main() {
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  regex t("^A?KIHA?BA?RA?$");
  cout << (regex_match(s, t) ? "YES" : "NO") << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

Int N;
Int A[100000+10];
Int X[100000+10];

void solve(void) {
    Int sum = 0;
    for(int i = 1;i <= N;i++) {
        sum += A[i];
    }
    sum = sum / 2;

    for(int i = 2;i <= N;i+=2) {
        sum -= A[i];
    }

    X[1] = sum;
    X[2] = A[1]-X[1];
    for(int i = 3;i <= N;i++) {
        X[i] = A[i-1]-X[i-1];
    }

    for(int i = 1;i <= N;i++) {
        cout<<X[i]*2;
        if(i != N)
            cout<<" ";
    }
    cout<<endl;

    return;
}

int main(void) {
    cin>>N;

    for(int i = 1;i <= N;i++) {
        cin>>A[i];
    }

    solve();

    return 0;
}



Measured memory_bytes: 2816
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>

using namespace std;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	       	
	int x, y;
	cin >> x >> y;

	int count = 0;

	if(x == 1) {
		count += 300000;
	} else if(x == 2) {
		count += 200000;
	} else if(x == 3) {
		count += 100000;
	}	
        if(y == 1) {
                count += 300000;
        } else if(y == 2) {
                count += 200000;
        } else if(y == 3) {
                count += 100000;
        }
	
	if(x == 1 && y == 1) {
		count += 400000;
	}

	cout << count << endl;
}


Measured memory_bytes: 256
/**
  @date Time-stamp: <2019-05-19 22:14:44 tagashira>
  @file c.cpp
  @title C - Dice and Coin
  @brief https://atcoder.jp/contests/abc126/tasks/abc126_c
**/

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(int argc, char* argv[]) {
  uint N, K;
  cin >> N >> K;

  long double p = 0.0;

  // cout << "K/N:  " << (double)K / (double)N << endl;
  // cout << "log2: " << log2((double)K / (double)N) << endl;
  // cout << "ceil: " << ceil(log2((double)K / (double)N)) << endl;

  uint i;
  for (i = 1; i <= N; i++) {
    if (i <= K - 1) {
      p += (long double)(1 / (long double)N) * powl(0.5l, ceil(log2((long double)K / (long double)i)));
    } else
      p += (long double)(1 / (long double)N);
  }
  cout << std::setprecision(16) << p << endl;

  return 0;
}


Measured memory_bytes: 256
# cook your dish here
n,k = map(int,input().split())
c = 0
j = []
for i in range(n):
    a,b = map(int,input().split())
    j.append([a,b])
j.sort()
for i in range(n):
    d = c
    c += j[i][1]
    if d +1 <= k and k <= c:
        print(j[i][0])
        

Measured memory_bytes: 20104
import qualified Data.ByteString.Char8 as B
import Data.List
import qualified Data.Vector.Unboxed as V
import Data.Monoid((<>))
import Data.Function hiding ((&))
import Debug.Trace

(&) :: a -> (a -> b) -> b
(&) a b = b a

infixl 1 &

data P = P { p_fst :: {-# UNPACK #-} !Int, 
             p_snd :: (String -> String) }

{-
instance Eq P where
    (==) = (==) `on` p_fst
instance Ord P where
    compare = compare `on` p_fst
instance Monoid P where
    mappend (P a b) (P c d) = P (a + c) (b . d)
    mempty = P 0 id 
    -}

main :: IO ()
main = do
    s <- B.getLine
    t <- B.getLine
    let len_s = B.length s
        len_t = B.length t
        v_end = scanl' step s0 (B.unpack t) 
                    & reverse 
                    & dig (len_t, len_s) ""
        step :: V.Vector (Int,Int) -> Char -> V.Vector (Int,Int)
        step tbl ch = tbl'
            where
            tbl' = V.constructN (len_s + 1) gen 
            gen vec | i == 0 = (0, -1)
                    | ch == ch' = (a1,0) `max` (a2,1) `max` (a3,2)
                    | otherwise = (a1,0) `max` (a2,1)
                where
                    i = V.length vec
                    ch' = B.index s (i - 1)
                    a1 = fst $ V.last vec
                    a2 = fst $ tbl V.! i
                    a3 = fst (tbl V.! (i - 1)) + 1
        dig :: (Int, Int) -> String -> [V.Vector (Int, Int)] -> String
        dig (i,j) acc (tbl:tbls) 
            | dir == 0 = dig (i,j-1) acc (tbl:tbls)
            | dir == 1 = dig (i-1,j) acc tbls
            | dir == 2 = dig (i-1,j-1) (B.index t (i-1) :acc) tbls
            | otherwise = acc
            where
                (_, dir) = tbl V.! j
        s0 = V.replicate (len_s + 1) (0,-1)
    putStrLn v_end 
    


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

int main() {
    int n;
    int sum = 0;
    cin >> n;
    vector<int> w(n);
    for(int i = 0; i < n; i++){
        cin >> w.at(i);
        sum += w.at(i);
    }
    int min_num = sum;
    int sum_buf = 0;
    for(int i = 0; i < n; i++){
        sum_buf += w.at(i);
        min_num = min(min_num, abs(sum - 2 * sum_buf));
    }
    cout << min_num << endl;
}

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

int main(){
    int n ;
    cin >> n ;
    rep(i,100){
        rep(j,100){
            if(i*4 + j*7 == n ){
                cout << "Yes" << endl;
                return 0 ;
            }
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3600
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <deque>
#include <string.h>
#include <set>
using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

const int MAX_N = 100000;
ll n;
string s;

int main(){
  cin >> n >> s;
  int re[n], lw[n];
  int tre = 0, tlw = 0;
  lw[0] = 0;
  re[n - 1] = 0;
  REP(i, n - 1){
    if(s[i] == 'W') tlw++;
    lw[i + 1] = tlw;
    if(s[n - 1 - i] == 'E') tre++;
    re[n - 2 - i] = tre;
  }
  int ans = INFi;
  REP(i, n) {
    ans = min(ans, lw[i] + re[i]);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 2948
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include <cstdint>
using namespace std;
#define rep(N) for(int i=0;i<N;i++)
#define rep2(N1,N2) for(int i=0;i<N1;i++)for(int j=0;j<N2;j++)
#define rep3(N1,N2,N3)for(int i=0;i<N1;i++)for(int j=0;j<N2;j++)for(int k=0;k<N3;k++)
#define For(i,N) for(int i=0;i<N;i++)
#define ll long long int
void yn(bool b) {
	if (b)printf("yes\n");
	else printf("no\n");
}

void Yn(bool b) {
	if (b)printf("Yes\n");
	else printf("No\n");
}

void YN(bool b) {
	if (b)printf("YES\n");
	else printf("NO\n");
}

int ctoi(char c) {
	return c - '0';
}

ll kai(ll x) {
	ll a = 1;
	if (x <= 0)
		return 1;
	else {
		for(ll i=0;i<x;i++)
			a = a * (i + 1);
		return a;
	}
}

ll rui(ll x, ll y) {
	ll a = 1;
	for (ll i = 0; i < y; i++)
		a = a * x;
	return a;
}
const int nmax = 150;
int cccc[nmax][nmax];
ll comb(ll n, ll k) {
	if (n < k) {
		cout << "error n<k"<<endl;
		return -1;
	}
	if (cccc[n][k] > 0)return cccc[n][k];
	if (k == 0 || n == k)return 1;
	return cccc[n][k] = comb(n - 1, k - 1) + comb(n - 1, k);
}

int main() {
//	cout.precision(16);
	ll N, K;
	cin >> N >> K;
	vector<ll>A(N+1);
	vector<ll>sht(N + 1, 0);
	for(int i=1;i<=N;i++)
		cin >> A[i];
	ll cnt = 0;
	map<ll, ll>pas;
	pas[1]++;
	ll now=1;
	ll next;
	int flag = 1;
	while (flag==1) {
		next = A[now];
		if (pas[next] != 1) {
			pas[next]++;
			now = next;
			cnt++;
			sht[next] = cnt;
		}
		else {
			cnt++;
			flag = 0;
		}
	}

	ll ans = 0;
	if (K >= sht[next]) {
		ans = K - sht[next];
		ans = ans % (cnt - sht[next]);
		now = next;
		for (int i = 0; i < ans; i++) {
			next = A[now];
			now = next;
		}
		cout << next;
	}
	else
		for (int i = 1; i <= N; i++) {
			if (sht[i] == K) {
				cout << i;
			}
		}
}

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

using i64 = int_fast64_t;
using f64 = double;

constexpr i64 INF = INT_FAST64_MAX / 2;
constexpr f64 EPS = DBL_EPSILON;

void solve() {
    string s;
    cin >> s;
    cout << (s.substr(0, 4) == "YAKI" ? "Yes" : "No") << endl;
}

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


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
	long long int count[100001]={0};
	long long int N,A,Q,B,C;
	long long int ans=0;
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>A;
		count[A]++;
	}
	for(int i=1;i<=100000;i++){
		ans+=i*count[i];
	}
	cin>>Q;
	for(int i=0;i<Q;i++){
		cin>>B>>C;
		count[C]+=count[B];
		ans+=count[B]*C;
		ans-=count[B]*B;
		count[B]=0;
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 4412
a = list()
for i in range(3):
    a.append([int(x) for x in input().split()])
n = int(input())
b = list()
for i in range(n):
    b.append(int(input()))
appear = [[0,0,0],[0,0,0],[0,0,0]]
for i in range(3):
    for j in range(3):
        for k in b:
            if (a[i][j] == k):
                appear[i][j] = 1

def x ():
    for i in range(3):
        if (appear[i][0] and appear[i][1] and appear[i][2] ):
            return "Yes"
    for i in range(3):
        if (appear[0][i] and appear[1][i] and appear[2][i]):
            return "Yes"
    if (appear[0][0] and appear[1][1] and appear[2][2]):
        return "Yes"
    if (appear[0][2] and appear[1][1] and appear[2][0]):
        return "Yes"
    return "No"
print(x())

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void){
  int n;
  cin >> n;

  double ans = ceil(n / 2.0) / double(n);
  cout << fixed << setprecision(10) << ans << endl;
}


Measured memory_bytes: 3784
#include<math.h>
#include<stdio.h>
 
int main(void)
{
  int x,y;
  
  scanf("%d",&x);
  
  y=x % 111;
  if(y!=0)
  {
  x=x+(111-y);
  }
  
  printf("%d",x);
  
  return 0;
  
}

Measured memory_bytes: 128
<?php
list($n, $t) = ints();
for($i = 0; $i < $n; $i++){
  list($a[], $b[]) = ints();
}
array_multisort($a, $b);
//o($a);
//o($b);
for($j = 0; $j <= $t; $j++){
  $dp[0][$j] = 0;
}
$max = 0;
for($i = 0, $I = $n-2; $i <= $I; $i++){
  for($j = 0, $J = $t-1; $j <= $J; $j++){
    if($j - $a[$i] >= 0){
      $dp[$i+1][$j] = max($dp[$i][$j - $a[$i]] + $b[$i], $dp[$i][$j]);
    }else{
      $dp[$i+1][$j] = $dp[$i][$j];
    }
  }
  $max = max($max, $dp[$i+1][$t-1] + $b[$i+1]);
}
//o($dp);
//o($dp[$n][$t]);
echo $max;
function str(){
  return trim(fgets(STDIN));
}
function ints(){
  return array_map("intval", explode(" ", trim(fgets(STDIN))));
}
function int(){
  return intval(trim(fgets(STDIN)));
}
function o(...$val){
    if(count($val)==1)$val = array_shift($val);
    $trace = debug_backtrace();
    echo $trace[0]['line'].")";
    if(is_array($val)){
        if(count($val) == 0){
            echo "empty array";
        }elseif(!is_array(current($val))){
            echo "array:";
            echo implode(" ", $val)."\n";
        }else{
            echo "array:array\n";
            foreach($val as $row){
                echo implode(" ", $row)."\n";
            }
        }
    }else{
        echo $val."\n";
    }
}

Measured memory_bytes: 414200
#include <iostream>

using namespace std;
long dp[10000]={0};


long fibo(int a){
  if (a==0 or a==1) return 1L;

  if(dp[a] !=0) return dp[a];
  dp[a] = fibo(a-1)+fibo(a-2);

  return dp[a];

}

int main(){
  long n,req;

  cin >> req;
  n = fibo(req);

  cout <<n<<endl;



  
  return 0;
}





Measured memory_bytes: 3096
N,M = map(int , input().split())
data = sorted(list(map(int , input().split())))
A=[list(map(int , input().split())) for _ in range(M)]
change_list = sorted(A, key=lambda x:x[1])
cnt_total = 0

for i,x in reversed(change_list):
	for j in range(i):
		if data[cnt_total] <=x:
			data[cnt_total] =x
		else:
			print(sum(data))
			exit()

		cnt_total += 1
		if cnt_total == N:
			print(sum(data))
			exit()
			
print(sum(data))

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

int a[505][505];

int main()
{
    int h, w;
    cin >> h >> w;
    
    int odd = 0;
    rep(i,h)rep(j,w) {
        cin >> a[i][j];
    }

    vector<vector<int>> V;

    int step = 0;
    int y = 0;
    int x = 0;
    while (true) {
        step++;
        if (step == w*h) break;

        int next_x, next_y;
        if (y % 2 == 0) { // 偶数行
            next_x = x==w-1? x : x+1;
            next_y = x==w-1? y+1 :y;
        } else {          // 奇数行
            next_x = x==0? 0 : x-1;
            next_y = x==0? y+1 : y;
        }

        if (a[y][x] % 2 == 1) {
            a[y][x]--;
            a[next_y][next_x]++;
            vector<int> v = {y, x, next_y, next_x};
            V.push_back(v);
        }
        
        x = next_x;
        y = next_y;
    }

    cout << V.size() << endl;
    rep(i,V.size()) {
        auto v = V[i];
        cout << v[0]+1 << " " << v[1]+1 << " " << v[2]+1 << " " << v[3]+1 << endl;
    }

    return 0;
}

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

using namespace std;
using ll = long long;

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> to[n];
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }

  vector<int> g(n, -1);
  int cur = 0;
  rep(i, n) {
    if (g[i] != -1) continue;
    queue<int> q;
    q.push(i);
    g[i] = ++cur;
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      for (auto v : to[u]) {
        if (g[v] != -1) continue;
        g[v] = g[u];
        q.push(v);
      }
    }
    ++cur;
  }

  map<int, int> mp;
  rep(i, n) ++mp[g[i]];
  int ans = 0;
  for (auto p : mp) ans = max(ans, p.second);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 17880
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdio>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;
#define MOD 1000000007
#define rep(i,n) for(int i = 0; i < (n); ++i)
typedef long long ll;


int main(void) {
  int a, b;
  cin >> a >> b;
  int ans = -1;
  if(a < 10 && b < 10) {
    ans = a * b;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2013

#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<numeric>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

using namespace std;

int main()
{
	int N;
	while(cin >> N && N)
	{
		vector< pair<int,int> > train( N, {0,0} );
	
		int hh,mm,ss;
		rep(nth,N)
		{
			scanf("%d:%d:%d",&hh,&mm,&ss);
			train[nth].first = (hh*10000) + (mm*100) + (ss);

			scanf("%d:%d:%d",&hh,&mm,&ss);
			train[nth].second = (hh*10000) + (mm*100) + (ss);
		}

		vector<int> route(240000,0);
		rep(i,train.size()){
			REP(j,train[i].first, train[i].second){
				route[j] += 1;
			}
		}

		cout << *max_element(ALL(route)) << endl;

}
	return 0;
}

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

using namespace std;
#define ull unsigned long long
#define ll long long
/*-----------------------------------------------------MATH------------------------------------------------*/
inline ll gcd(ll a, ll b) { while (b) { a %= b; swap(a, b); } return a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
inline int pwm(ll xx, ll pow, int MD) { if (pow < 0) { pow = pow % (MD - 1) + MD - 1; } ll mlt = 1; while (pow) { if (pow & 1) { mlt *= xx; mlt %= MD; } xx *= xx; pow >>= 1; xx %= MD; } return (int)mlt; }
inline ll gcdex(ll a, ll b, ll &x, ll &y) { if (b == 0) { x = 1; y = 0; return a; }ll xx, yy; ll gc = gcdex(b, a % b, yy, xx); x = xx; y = yy - (a / b) * xx; return gc; }
inline int inv(ll r, int _mod) { return pwm(r % _mod, _mod - 2, _mod); }
/*-----------------------------------------------------MATH------------------------------------------------*/

const int inf = 1e6;
const int MAXN = 2e5 + 10;
ll mod =998244353;
void solve() {
    int a,b;
    cin>>a>>b;
    cout<<6-a-b;


}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n=1;
    for (int i = 0; i < n; i++) solve();
    return 0;
}

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

struct Edge{
    int from,to,cost;
};

bool operator<(Edge lhs,Edge rhs){
    return lhs.cost<rhs.cost;
}
const int INF=1e8;

class UnionFind{
    vector<int> par;
    vector<int> rank;
    public:
    UnionFind(int n):rank(n,0),par(n){
        iota(par.begin(),par.end(),0);
    }
    int find(int x){
        if(par[x]==x) return x;
        else return par[x]=find(par[x]);
    }
    int unite(int x,int y){
        x=find(x),y=find(y);
        if(rank[x]<rank[y]) par[x]=y;
        else{
            if(rank[x]==rank[y]) rank[x]++;
            par[y]=x;
        }
    }
    int same(int x,int y){
        return find(x)==find(y);
    }
};
int solve(int n,int m){
    vector<Edge> edges(m);
    for(int i=0;i<m;i++){
        int a,b,w;
        cin>>a>>b>>w;
        a--,b--;
        edges[i]=Edge{a,b,w};
    }
    sort(edges.begin(),edges.end());
    int res=INF;
    for(int i=0;i<m;i++){
        UnionFind u(n);
        int cnt=0;
        for(int j=i;j<m;j++){
            int a=edges[j].from,b=edges[j].to;
            if(!u.same(a,b)){
                cnt++;
                u.unite(a,b);
            }
            if(cnt==n-1){
                res=min(res,edges[j].cost-edges[i].cost);
                break;
            }
        }
    }
    return res==INF ? -1 : res;
}

int main(){
    int n,m;
    while(cin>>n>>m,n){
        cout<<solve(n,m)<<endl;
    }
    return 0;
}


Measured memory_bytes: 3068
require 'pp'

s = gets.chomp!

if s == s.reverse
    x = s[0, (s.length-1)/2]
    if x == x.reverse
        y = s[(s.length-1+3)/2, s.length - 1]
        if y == y.reverse
            puts "Yes"
            exit 0
        end
    end
end

puts "No"


Measured memory_bytes: 2044
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N,A,B,C,D,E;
    cin>>N>>A>>B>>C>>D>>E;
    ll res=min(A,min(B,min(C,min(D,E))));
    cout <<5LL+(N-1)/res<<"\n";
}

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

int main(){
    
    char a[15], b[15], c[15];
    scanf("%s", a);
	scanf("%s", b);
	scanf("%s", c);
	
	int lena = strlen(a);
	int lenb = strlen(b);
	int lenc = strlen(c);
	
	if(a[lena-1] == b[0] && b[lenb-1] == c[0]){
		printf("YES\n");
	}
	else{
		printf("NO\n");
	}
	
	return 0;
}

Measured memory_bytes: 1640
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N,x=MI()
    a=LI()
    ans=0
    if a[0]>x:
        ans+=a[0]-x
        a[0]=x
    
    for i in range(N-1):
        b=a[i]+a[i+1]
        if b>x:
            ans+=b-x
            a[i+1]-=b-x
            
    print(ans)
    

main()


Measured memory_bytes: 59632
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for(int i=m; i<n; i++)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
template <typename T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0; }
template <typename T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1;} return 0; }


int main() {
    string n; cin>>n;
    if(n=="ABC") cout<<"ARC"<<endl;
    else cout<<"ABC"<<endl;




}

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <map>
#include <tuple>
#include <string>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;

int main() {
	string s;
	char c;
	cin >> s;
	int ans = 1;
	rep(i, s.length()) {
		c = s[i];
		if (i%2 == 0) {
			if (c == 'R' or c == 'U' or c == 'D') {
				//			
			} else {
				ans = 0;
			}
		} else {
			if (c == 'L' or c == 'U' or c == 'D') {
				//
			} else {
				ans = 0;
			}
		}
		
	}
	if (ans == 1) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	} 
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void){
int A,B,C,D,E,N,M,x,y,cou=0,cou2,v[1000000],w[1000000],min_i,en=0;
    char S[20],W[10],s[10],X,Y;
   scanf("%s",&S);
   for(int i=0;i<5;i++){
       printf("%c",S[i]);
   }
   printf(" ");
   for(int i=6;i<13;i++){
       printf("%c",S[i]);
   }
   printf(" ");
   for(int i=14;i<19;i++){
       printf("%c",S[i]);
   }
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using ll = long long;

using namespace std;

int main() {
    bool calcable[101];
    fill(calcable, calcable+101, false);
    for (int i=1; i<10; i++) {
        for (int j=i; j<10; j++) {
            calcable[i * j] = true;
        }
    }
    int n;
    cin >> n;
    cout << (calcable[n] ? "Yes" : "No") << '\n';
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  int ans = 100000;
  int term = 0;
  int s6,s9;
  for (int i=0; i<=N; i++) {
    s6 = i;
    s9 = N-i;
    term = 0;
    for (int j=0; j<8; j++) {
      term += s6%6 + s9%9;
      s6 /= 6;
      s9 /= 9;
    }
    ans = min(ans,term);
  }
  cout << ans << endl;
}

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

int main() {
  int n,a,b;
  cin >>n>>a>>b;
  int p,j,k,l;
  j=0;
  k=0;
  l=0;
  
  for(int i=0;i<n;i++){
    cin>>p;
    if(p<=a){
      j++;
    }
    else if(p<=b){
      k++;
    }
    else{
      l++;
    }
  }
  
  cout<<min(min(j,k),l)<<endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
        String s = sc.next();
        int ans = 0; int run = 0;
        for (int i = 0; i < 3; i++) {
            if (s.charAt(i) == 'R') {
                run++;
            } else {
                ans = Math.max(ans, run);
              	run = 0;
            }
        }
        ans = Math.max(ans, run);
        out.println(ans);
        out.close();
    }


    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }


    }

}

Measured memory_bytes: 32880
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const ll inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

template <typename T>
void print(vector<T> vec)
{
    int n = vec.size();
    for (int i = 0; i < n; i++)
    {
        cout << vec[i] << (i == n - 1 ? "\n" : " ");
    }
}

int n, m = 0, ans;

int main()
{
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
        if (m <= v[i])
            ans++;
        m = max(m, v[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
open System
let R T = stdin.ReadLine()|> T
let RS T = stdin.ReadLine().Split()|>Array.map T
let R2 T U = RS string|>fun c-> (c.[0]|>T),(c.[1]|>U)
let R3 T U V = RS string|>fun c-> (c.[0]|>T),(c.[1]|>U),(c.[2]|>V)
let R4 T U V W = RS string|>fun c-> (c.[0]|>T),(c.[1]|>U),(c.[2]|>V),(c.[3]|>W)
let R5 T U V W X = RS string|>fun c-> (c.[0]|>T),(c.[1]|>U),(c.[2]|>V),(c.[3]|>W),(c.[4]|>X)
let outl s = stdout.WriteLine(s|>string)
let outsep ls = stdout.WriteLine(String.concat " " (ls|>Array.map string))
let outsepl ls = stdout.WriteLine(String.concat "\n" (ls|>Array.map string))
let Mod = (1e9|>int64)+7L
[<EntryPoint>]
let main argv =
    let N,R=R2 int int
    let f k r = r+100*(max 0 (10-k))
    outl (f N R)
    0
    

Measured memory_bytes: 11348
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;
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; }

vector<vll> G;
ll N;
vll a;
vll dp;
vll ans;

void dfs(ll u, ll p){   
    ll i = lower_bound(dp.begin(), dp.end(), a[u])  - dp.begin() ;
    ll old = dp[i];
    dp[i] = a[u];
    ans[u] = i;
    if(p != -1) chmax(ans[u], ans[p]);
    for(ll v: G[u]){
        if(v == p) continue;
        dfs(v, u);
    }
    dp[i] = old;
}

int main(){
    cin >> N;
    a.resize(N);
    G.resize(N);
    dp.resize(N+1, INF);
    ans.resize(N, 0); ans[0] = 1;
    dp[0] = -INF;
    REP(i, N) cin >> a[i];
    REP(i, N-1) {
        ll u, v; cin >> u >> v; u--; v--;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    dfs(0, -1);
    REP(i, N) cout<<ans[i] << endl;
    return 0;
}


Measured memory_bytes: 29920
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(a==b){
		if(c==a){
			cout<<"No"<<endl;
		}else{
			cout<<"Yes"<<endl;
		}
	}else if(c==a){
		cout<<"Yes"<<endl;
	}else if(c==b){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;const int mod=1000000007;typedef pair<long long,long long> pii;int h[105];
inline int qpow(int a,int b) {int rtv=1;for (;b;b>>=1,a=1LL*a*a%mod) if (b&1) rtv=1LL*rtv*a%mod;return rtv;}
inline pii dac(int l,int r,int bnd) {long long mn=1e18,cnt=0,rem=r-l+1,ans0=1,ans1=1;pii _;
	for (int i=l;i<=r;++i) if (h[i]<mn) mn=h[i],cnt=1;else if (h[i]==mn) ++cnt;
	if (cnt==r-l+1) return make_pair((qpow(2,r-l+1)+mod-2)%mod,qpow(2,mn-bnd-1));
	for (int i=l,j=0;i<=r+1;++i) if (!j&&h[i]>mn) j=i;
		else if (j&&(h[i]==mn||i>r)) {rem-=i-j,_=dac(j,i-1,mn),j=0;
			ans0=1LL*ans0*(_.first+(4LL*_.second%mod)%mod)%mod,ans1=1LL*ans1*(_.second<<1)%mod;
		}ans0=(ans0-ans1+mod)%mod;
	return make_pair((1LL*ans0*qpow(2,rem)%mod+1LL*ans1*(qpow(2,rem)+mod-2)%mod)%mod,1LL*ans1*qpow(2,mn-bnd-1)%mod);
}int main() {int n,prod=1;pii _;scanf("%d",&n);for (int i=1;i<=n;++i) scanf("%d",h+i);
	if (n<2) return 0*printf("%d",qpow(2,h[1]));
	for (int i=1;i<=n;++i) if (h[i]>h[i-1]&&h[i]>h[i+1])
		prod=1LL*prod*qpow(2,h[i]-max(h[i-1],h[i+1]))%mod,h[i]=max(h[i-1],h[i+1]);
	_=dac(1,n,0);printf("%lld",1LL*prod*((_.first+_.second+_.second)%mod)%mod);return 0;
}

Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;

int main()
{
	ll x;
	cin >> x;
	ll ans = x/11*2;
	if(x%11>6)ans+=2;
	else if(x%11==0)ans+=0;
	else if(x%11<=6)ans=ans+1;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(void){
  int n,q,i,ac[100010]={},l,r,res;
  string s;
  cin >> n >> q >> s;
  for (i=2;i<=n;i++) if (s[i-2]=='A' && s[i-1]=='C') ac[i]=1;
  for (i=2;i<=n;i++) ac[i]+=ac[i-1];
  for (i=0;i<q;i++){
    cin >> l >> r;
    res=ac[r]-ac[l-1];
    if (l>=2 && s[l-2]=='A' && s[l-1]=='C') res--;
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 1408
import sys
input = sys.stdin.readline
import itertools

# 解けなかった
# N, M, X = map(int, input().split())
# values_list = []
# for i in range(N):
#     values = list(map(int, input().split()))
#     values_list.append(values)

# ans = 0
# for i in range(1, N+1):
#     for pair in itertools.combinations(values_list, i):
#         this_m_dict = {}
#         this_cost = 0
#         for item in pair:
#             for j in range(1, M+1):
#                 this_m_dict[j] = this_m_dict.get(j, 0) + item[j]
#             this_cost += item[0]
#         for myvalue in this_m_dict.values():
#             if myvalue < X:
#                 break
#         ans = min(this_cost, ans)

N, M, X = map(int, input().split())
A = []
C = []

for i in range(N):
    values = list(map(int, input().split()))
    C.append(values[0])
    A.append(values[1:])

INF = float('INF')
min_cost = INF

def dfs(i, cost, learn):
    if i == N:
        if min(learn) >= X: 
            return cost
        else:
            return INF

    else:
        new_learn = [(x+y) for (x, y) in zip(A[i], learn)]
        cost = min(dfs(i+1, cost, learn), dfs(i+1, cost + C[i], new_learn))
        return cost

min_cost = dfs(0, 0, [0] * M)

if min_cost == INF:
    print(-1)
else:
    print(min_cost)

Measured memory_bytes: 9160
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Map = map<string,ll>;



int main(){
	ll N;
	cin >> N;
	ll M;
	cin >> M;
	vector<ll> A(N,0);
	vector<ll> B(N,0);
	for(ll i=0;i<N;i++){
		cin>>A[i]>>B[i]
	;}
	vector<vector<ll>> days(100009, vector<ll>(0));
	for(ll i=0;i<N;i++){
		days[A[i]].emplace_back(B[i]);
	;}
	priority_queue<ll> tank;
	ll ans=0;
	for(ll i=1;i<=M;i++){
		ll j=0;
		while(j<days[i].size()){
			tank.emplace(days[i][j]);
			j++;
		}
		if(tank.size()){
		ans+=tank.top();
		tank.pop();}
	}
	

	cout<<ans<<endl;


return 0;
}  



Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);

const int N = 2e5+5, M = 1e6+6, OO = 0x3f3f3f3f;
int tc;

int main()
{
    FIO
    ll n, x, m;
    cin>>n>>x>>m;
    map<ll, int> mp;
    vector<ll> vec;
    ll prev = x;
    ll sum = 0;
    int i = 0;
    for(i = 0 ; i < n ; i++)
    {
        
        if(prev == 0)
            break;
        if(mp.count(prev))
            break;
        mp[prev]++;
        vec.push_back(prev);
        prev = (prev * prev) % m;
        // cout<<"num "<<prev<<endl;
    }
    for(auto x : vec)
        sum += x;
    if(i == n || prev == 0)
    {   
        cout<<sum;
        return 0;
    }
    int idx = find(vec.begin(), vec.end(), prev) - vec.begin();
    // cout<<"idx: "<<idx<<endl;
    ll rem = n - (int) vec.size();
    // cout<<"rem: "<<rem<<endl;
    ll csum = 0;
    for(int j = idx; j < (int) vec.size() ; j++)
        csum += vec[j];
    // cout<<vec.size()<<endl;
    int cyclesize = (int) vec.size() - idx;
    // cout<<"cycleSzie: "<<cyclesize<<endl;
    // cout<<"Csum: "<<csum<<endl;
    sum += csum *(rem / cyclesize);
    for(int j = idx; j < idx + (rem%cyclesize) ; j++)
        sum += vec[j];
    cout<<sum<<endl; 

    return 0;
}

Measured memory_bytes: 6760
#include <bits/stdc++.h>
#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 pb push_back
#define pcnt __builtin_popcount
#define show(x) cout<<#x<<" = "<<x<<endl;
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define fi first
#define se second
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define sz(x) (int)(x).size()
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v)
{stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
ll gcd(ll a,ll b){if(a>b)swap(a,b);for(;a>0;b%=a,swap(a,b));return b;}
int modpow(ll a,ll n,int m){if(a==0)return a;ll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(int)p;}
void dout(double d){printf("%.12f\n",d);}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;
string s;
char c;

main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> s;
  int l = sz(s);
  c = s[l/2];
  int ans = l%2 + l/2;
  FOR(i, 0, l/2){
    if(s[l/2-1-i] != c || s[l/2+l%2+i] != c) break;
    ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 512