akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public final class Main {

    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        final String[] line = in.nextLine().split(" ");
        long x = Long.parseLong(line[0]);
        long k = Long.parseLong(line[1]);
        long d = Long.parseLong(line[2]);
        x = Math.abs(x);
        if ((x / d) >= k) {
            System.out.println(x - d * k);
        } else {
            k -= x / d;
            long r = x % d;
            if (k % 2 == 0) {
                System.out.println(r);
            } else {
                System.out.println(d - r);
            }
        }
    }
}


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

int main() {
int64_t n,k,ans;
  ans=0;
  cin>>n>>k;
 vector<int64_t> vec(n);
  for(int64_t i=0;i<n;i++){cin>>vec.at(i);}
  int64_t l=0;
  int64_t u=1000000000;
    while(u-l>1){
     int64_t mid=(l+u)/2;
      for(int64_t j=0;j<n;j++){ans+=((vec.at(j)+mid-1)/mid)-1;}
      if(ans<k||ans==k){u=mid;}
      else{l=mid;}
      ans=0;
    }
  cout<<u<<endl;
}

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

def SumOfDigits(n):
    s = 0
    while n != 0:
        s += n % 10
        n = n // 10
    return(s)

ans = 0

for i in range(1, N):
    j = SumOfDigits(i) + SumOfDigits(N-i)
    if ans > j:
        ans = j
    elif ans == 0:
        ans = j
    else:
        pass

print(ans)

Measured memory_bytes: 3064
//値Aiを1減らしたとき, 全体のxorは「下位log2(Ai & (-Ai))ビット」反転する。
//各xについて, log2(Ai & (-Ai)) = xを満たすiの個数をcnt[x]に入れておく。
//すると以下の問題になる。
//・yの初期値が与えられる。
//・yの下位xビットを反転する操作を高々cnt[x]回できる
//・y=0にできるか？できるなら操作回数を最小化せよ。
//これはxが大きい順に処理すれば解ける。O(N)
//ちなみに, 同じ操作を2回するのは無駄なので, cnt[x]をcnt[x] % 2に置き換えても問題ない。

#include <iostream>
using namespace std;

int n;
int a[100000];
int cnt[100000];

int log2(int x) {
	int i;
	for (i = 0; (1 << i) < x; i++);
	return i;
}

int main() {
	int i;
	
	cin >> n;
	for (i = 0; i < n; i++) cin >> a[i];
	for (i = 0; i < n; i++) cnt[log2(a[i] & -a[i])]++;
	
	int x = 0;
	for (i = 0; i < n; i++) x ^= a[i];
	
	int ans = 0;
	for (i = 29; i >= 0; i--) {
		if ((x >> i) % 2 == 0) continue;
		if (cnt[i] == 0) { cout << -1 << endl; return 0; }
		ans++;
		
		//xの下位iビットを全て反転
		x = x ^ ((1 << i) - 1);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include<cstdio>
#include<cstdlib>
#include<hash_map>
#include<algorithm>
using namespace std;
using namespace __gnu_cxx;
int main()
{
    int n;
    cin>>n;
    hash_map<int,int>mp;
    int cnt=0;
    for(int i=0;i<n;++i)
    {
        int x;
        cin>>x;
        hash_map<int,int>::iterator it;
        it=mp.find(x);
        if(it!=mp.end())
        {
            mp[x]++;
        }
        else
        {
            mp[x]=1;
        }
    }
    hash_map<int,int>::iterator it;
    it=mp.begin();
    while(it!=mp.end())
    {
        if((it->second)%2!=0)
            ++cnt;
        ++it;
    }
    cout<<cnt;
    return 0;
}


Measured memory_bytes: 5560
#include <algorithm>
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <vector>
#include <queue>
#include <math.h>
#include <string> 
#include <bits/stdc++.h>
using namespace std;

int main(){
    string s;
    long long k;
    cin >> k >> s;
    if(s.length()<=k){
        cout << s << endl;
    }else{
        string ans; 
        ans=s.substr(0,k);
        cout << ans << "..." << endl;
    }
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

int n,m,q;
int a[51],b[51],c[51],d[51];
int ans = 0;
// int n_use = 0, m_use = 0;

void dfs(vector<int> A){

  if(A.size() == n + 1){
    int now = 0;
    for(int i = 0; i < q; i++){
      if(A[b[i]] - A[a[i]] == c[i]) now += d[i];
    }

    ans = max(ans, now);

    return;
  }

  A.push_back(A.back());
  while(A.back() <= m){
    dfs(A);
    A.back()++;
  }

  return;

}


int main(){
  cin >> n >> m >> q;
  for(int i = 0; i < q; i++) cin >> a[i] >> b[i] >> c[i] >> d[i];

  dfs(vector<int>(1,1));
  cout << ans << endl;


  return 0;
}

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

using namespace std;

typedef unsigned long long ull;

const int MAXN=101;

ull h,tot=0,ans=1;

int main() {
	cin>>h;
	for(ull tmp=1; tmp<=h; tmp<<=1) ++tot;
	for(; tot; ans<<=1,--tot);
	cout<<ans-1<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>

int main(){
    int A,B,C;
    scanf("%d %d %d",&A,&B,&C);
    int a[]= {A,B,C};
    int count5 = 0;
    int count7 = 0;
    for(int i = 0; i < 3; i++){
        if(a[i] == 5){
            count5++;
        }
        if(a[i] == 7){
            count7++;
        }
    }

    if(count5 == 2 && count7 == 1){
        printf("YES");
    }
    else{
        printf("NO");
    }
    printf("\n");

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
// make_tuple emplace_back next_permutation push_back make_pair second first
// setprecision

#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif

using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;

namespace Problem {
using namespace std;

class Solver {
   public:
    int n;
    vector<int> p;
    Solver(LL n) : n(n), p(n){};

    void solve() {
        for (int i = 0; i < n; ++i) {
            int tmp;
            cin >> tmp;
            p[tmp - 1] = i;
        }
        int ans = 0, cnt = 0;
        for (int i = 1; i < n; ++i) {
            if (p[i] > p[i - 1]) {
                cnt++;
            } else {
                ans = max(ans, cnt);
                cnt = 0;
            }
        }
        ans = max(ans, cnt);
        cout << n - 1 - ans << "\n";
    }
};
}  // namespace Problem

int main() {
    std::cin.tie(0);
    std::ios_base::sync_with_stdio(false);
    long long n = 0;
    std::cin >> n;
    Problem::Solver sol(n);
    sol.solve();
    return 0;
}


Measured memory_bytes: 1024
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace D
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var n = int.Parse(Console.ReadLine());
            var ai = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var answer = 0L;
            var sum = 0L;
            var xor = 0L;
            var l = 0;
            var r = 0;
            while (r < ai.Length)
            {
                sum += ai[r];
                xor ^= ai[r];
                if (sum == xor)
                {
                    answer += r - l + 1;
                }
                else
                {
                    while (sum != xor)
                    {
                        sum -= ai[l];
                        xor ^= ai[l];
                        l++;
                    }
                    answer += r - l + 1;
                }
                r++;
            }

            Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 32476
n,m=map(int,input().split())
ab=[]
cd=[]
for i in range(n):
    ab.append(list(map(int,input().split())))
for j in range(m):
    cd.append(list(map(int,input().split())))

for k in range(n):
    s=[abs(ab[k][0]-cd[l][0])+abs(ab[k][1]-cd[l][1]) for l in range(m)]
    print(s.index(min(s))+1)

Measured memory_bytes: 3064
#include<stdio.h>
 
int main(void)
{
char a[27];
int i, j,flag=0;
scanf("%s",a);

for(i=0;a[i]!='\0'; i++){
for(j=i+1; a[j]!='\0'; j++){
if(a[i]==a[j])flag=1;
}
}
if(flag==0) printf("yes\n");
else printf("no\n");
 
 
return 0;
}

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

int main() {
    int x,y;
    cin >> x >> y;

    for(int i=0; i<=x; ++i){
        if(y==i*2+(x-i)*4){
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 3620
// abc062_d
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    ll N;
    cin >> N;
    vector<ll> A(3 * N);
    REP(i, 3 * N) cin >> A[i];

    priority_queue<ll, vector<ll>, greater<ll>> pq_l;
    priority_queue<ll, vector<ll>, less<ll>> pq_r;

    ll sum_l = 0, sum_r = 0;
    REP(i, N){
        pq_l.push(A[i]);
        sum_l += A[i];

        pq_r.push(A[3*N-i-1]);
        sum_r += A[3*N-i-1];
    }

    vector<ll> p(N+1), q(N+1);

    p[0] = sum_l;
    q[N] = sum_r;
    REP(i, N) {
        pq_l.push(A[N + i]);
        sum_l += A[N + i];
        ll x = pq_l.top(); pq_l.pop();
        sum_l -= x;
        p[i+1] = sum_l;

        pq_r.push(A[2*N-i-1]);
        sum_r += A[2*N-i-1];
        ll y = pq_r.top(); pq_r.pop();
        sum_r -= y;
        q[N-i-1] = sum_r;
    }
//    print(p);
//    print(q);

    ll ans = -1e15;
    REP(i, N+1){
        ans = max(ans, p[i] - q[i]);
    }
    print(ans);

    return 0;
}


Measured memory_bytes: 5996
#include <math.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;

int main() {
  std::string S;

  int match = 0;
  cin >> S;

  for (size_t i = 0; i < 3; i++) {
    char tmp;
    cin >> tmp;
    if (tmp == S[i]) match++;
  }

  cout << match << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int d;
  scanf("%d",&d);
  switch(d){
    case 22:
      printf("Christmas Eve Eve Eve\n");
      break;
    case 23:
      printf("Christmas Eve Eve\n");
      break;
    case 24:
      printf("Christmas Eve\n");
      break;
    case 25:
      printf("Christmas\n");
      break;
  }
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 1LL << 60;

int main(){
    int N;
    cin >> N;
    int t, ft = 0;
    int x, y, fx = 0, fy = 0;
    bool flag = true;
    rep(i, N){
        cin >> t >> x >> y;
        int dist = abs(x - fx) + abs(y - fy);
        dist = dist - (t - ft);
        if(dist > 0){
            flag = false;
        }
        dist *= -1;
        if(dist %2 == 1){
            flag = false;
        }
        ft = t;
        fx = x;
        fy = y;
    }
    if(flag == true) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3588
//#pragma comment(linker,"/STACK:102400000,102400000")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 0x3f3f3f3f;
#define _for(i, a, b) for (int i = (a); i < (b); ++i)
#define _rep(i, a, b) for (int i = (a); i <= b; ++i)
const int max_number = 1000000;

int main() //Print a Chessboard
{
    int h, w;
    while (true) {

        scanf("%d%d", &h, &w);

        if (h == 0 && w == 0)
            return 0;
for (int i = 1; i <= h; i++) {
            for (int j = 1; j <= w; j++) {
                if ((i + j) % 2 == 0) {
                    printf("#");
}else {
                    printf(".");
                }
            }
            printf("\n");
        }

        printf("\n");
    }
    return 0;
}
















Measured memory_bytes: 3144
#include <map>
#include <iostream>
using namespace std;
int main(){
  string w;
  cin >> w;
  map<char,int> m;
  for(int i = 0; i < w.length(); ++i){
    ++m[w[i]];
  }
  for(auto itr = m.begin(); itr != m.end(); ++itr){
    if(itr->second%2){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


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

using namespace std;

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

	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	int s = 0;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		s += a[i];
	}
	vector<int> div;
	for (int i = 1; i * i <= s; ++i) {
		if (s % i) {
			continue;
		}
		div.push_back(i);
		div.push_back(s / i);
	}
	int ans = 1;
	for (int d : div) {
		vector<int> b(n);
		for (int i = 0; i < n; ++i) {
			b[i] = a[i] % d;
		}
		sort(b.begin(), b.end());
		int cnt = 0, l = 0, r = n - 1;
		while (l < r) {
			if (b[l] == 0) {
				++l;
			}
			else if (b[r] == d) {
				--r;
			}
			else {
				int q = min(b[l], d - b[r]);
				b[l] -= q;
				b[r] += q;
				cnt += q;
			}
		}
		if (cnt <= k) {
			ans = max(ans, d);
		}
	}
	cout << ans;

	return 0;
}


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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll N;
string S;

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

  cin>>S;
  reverse(all(S));
  N=S.size();

  ll lev=0;
  bool f=true;
  ll res=0;
  rep(i,N){
    if(S[i]=='A'){
      if(!f){
        f=true;lev=0;
      }
      res+=lev;
    }else if(S[i]=='B'){
      if(!f){
        f=true;
        lev++;
      }else{
        f=true; lev=0;
      }
    }else{
      if(!f)lev=0;
      f=false;
    }
  }

  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const long long mod = 1000000007LL;

struct Unionfind {
  vector<ll> d;

  Unionfind(ll n) : d(n,-1) {}

  ll root(ll x) {
    if(d[x] < 0) return x;
    return d[x] = root(d[x]);
  }

  bool unite(ll x, ll y) {
    ll rx = root(x);
    ll ry = root(y);
    if(rx==ry) return false;
    if(d[rx] < d[ry]) swap(rx,ry);
    d[rx] += d[ry];
    d[ry] = rx;
    return true;
  }

  bool same(ll x, ll y) {
    return root(x) == root(y);
  }

  ll size(ll x) {
    return -d[root(x)];
  }
};

int main() {
  ll n, m;
  cin >> n >> m;
  Unionfind tree(n);
  rep(i,m) {
    ll a, b;
    cin >> a >> b;
    a--; b--;
    tree.unite(a,b);
  }
  ll ans = 0LL;
  rep(i,n) ans = max(ans,tree.size(i));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 10964
#include<string>
#include<list>
#include<iostream>
using namespace std;
int main(){

  string str;
  list<int> data;
  list<int>::iterator it,l;
  int n,x;
  cin >> n;
  while(n--){
    cin >> str;
    if(str == "insert"){
      cin >> x;
      data.push_front(x);
    }else if(str == "delete"){
      cin >> x;
      for(it=data.begin(),l=data.end();it!=l;++it){
	if(*it == x){
	  data.erase(it);
	  break;
	}
      }
    }else if(str == "deleteFirst") data.pop_front();
    else data.pop_back();
  }
  for(it=data.begin(),l=--data.end();it!=l;++it) cout << *it << " ";
  cout << *it << endl;
}



Measured memory_bytes: 34420
#include <iostream>

using namespace std;

int counter(int n){

  int count = 0;
  bool flag = true;
  while(flag){
    if(n % 2 == 1){
      flag = false;
    }
    else{
      count++;
      n = n / 2;
    }
  }
  return count;
}

int main(){
  int N;
  cin >> N;
  int ans_count = 0;
  int ans = 1;
  for(int i = 1; i <= N; i++){
    if(ans_count < counter(i)){
      ans_count = counter(i);
      ans = i;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
using vs = vector<string>;
using vb = vector<bool>;
#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 REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
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> inline void prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n;
    cin >> n;
    vvi g(n, vi());
    int a, b;
    REP(i, n - 1) {
        cin >> a >> b;
        a--; b--;
        g[a].emplace_back(b);
        g[b].emplace_back(a);
    }

    vvl dp(n, vl(2, 1LL));

    function<void(int, int)> dfs = [&](int c, int p) {
        if (p != -1 and sz(g[c]) == 1) return;
        for (auto e : g[c]) {
            if (e == p) continue;
            dfs(e, c);
            dp[c][0] *= (dp[e][0] + dp[e][1]) % MOD;
            dp[c][0] %= MOD;
            dp[c][1] *= dp[e][0];
            dp[c][1] %= MOD;
        }
    };

    dfs(0, -1);
    cout << ((dp[0][0] + dp[0][1]) % MOD) << endl;
}


Measured memory_bytes: 22344
import sys
a = "abcdefghijklmnopqrstuvwxyz"
x = str.maketrans(a, a[1:] + a[:1])
for s in sys.stdin:
    while True:
        s = s.translate(x)
        if "the" in s or "that" in s or "this " in s:
            print(s, end = "")
            break


Measured memory_bytes: 5564
x,y,a,b,c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p.sort(reverse=True)
q.sort(reverse=True)

apples=[]
apples.extend(p[:x])
apples.extend(q[:y])
apples.extend(r)

apples.sort(reverse=True)

print(sum(apples[:x+y]))

Measured memory_bytes: 110444
using System;
using System.Collections.Generic;
using System.Linq;
using static Atcoder;
using System.Threading.Tasks;
using System.ComponentModel;

public class Hello
{
    private const long INF = 1000000007;
    public static void Main()
    {
        int N = IntRead();
        bool[] table = Enumerable.Repeat(false, 10010).ToArray();
        table[0] = true;
        for (int i = 0; i < N; i++)
        {
            int a = IntRead();
            for (int j = 10000; j != -1; j--)
            {
                if (table[j]) table[j + a] = true;
            }
        }
        int max = 0;
        for (int i = 10000; i != -1; i--)
        {
            if (i % 10 == 0) continue;
            else if (table[i]) max = Math.Max(max, i);
        }
        Console.WriteLine(max);
    }
}

public class Atcoder
{
    public static void Swap<T>(ref T a, ref T b)
    {
        var t = a;
        a = b;
        b = t;
    }
    public static long LCM(long a, long b)
    {
        long c = a * b;
        if (a < b) Swap(ref a, ref b);
        long d = a % b;
        while (d != 0)
        {
            a = b;
            b = d;
            d = a % b;
        }
        return c / b;
    }
    public static string StrReverce(string s)
    {
        return new string(s.Reverse().ToArray());
    }
    public static bool IsPrime(int n)
    {
        if (n < 2) return false;
        if (n == 2) return true;
        if (n % 2 == 0) return false;

        //double sqrtNum = Math.Sqrt(n);
        for (int i = 3; i < n; i += 2)
        {
            if (n % i == 0) return false;
        }
        return true;
    }
    public static string[] SpRead(char c)
    {
        return Console.ReadLine().Split(c);
    }
    public static string ToConvertBit(int N, int e)
    {
        string ret = "";
        int r = 0;
        while (N != 0)
        {
            r = N % e;
            ret += r.ToString();
            N -= r;
            N /= e;
        }
        ret = StrReverce(ret);
        return ret;
    }
    public static int IntRead()
    {
        return int.Parse(Console.ReadLine());
    }
    public static long LongRead()
    {
        return long.Parse(Console.ReadLine());
    }
    public static long[] LongLine()
    {
        return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
    }
    public static int[] IntLine()
    {
        return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
    }
}


Measured memory_bytes: 13216
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            int X = sc.nextInt();
            int Y = sc.nextInt();

            for (int i = 0; i <= X; i++) {
                int j = X - i;
                if (i * 2 + j * 4 == Y) {
                    System.out.println("Yes");
                    return;
                }
            }
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 27088
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <string>
#include <algorithm>
#include <time.h> 
#include <stdio.h>      
#include <stdlib.h>
#include<cstdlib>
#include <map>
#include <utility>
#include <functional>
using namespace std;

typedef long long ll;
typedef long double ld;

#define all(v) v.begin(),v.end()

const long double pi = 3.1415926535;

bool check(char c) {
	return (c <= 'z' && c >= 'a') || (c <= 'Z' && c >= 'A');
}


ll gcd(ll a, ll b) {
	if (b == 0) return a;
	else return gcd(b, a%b);
}


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





int main() {

	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	vector<string> v;

	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		sort(s.begin(), s.end());
		v.push_back(s);
	}

	sort(v.begin(), v.end());
	ll k = 1, ans = 0;
	for (int i = 1; i < n; i++) {
		if (v[i] == v[i - 1]) {
			k++;
		}
		else {
			ans += (k - 1)*k / 2;
			k = 1;
		}
	}
	ans += (k - 1)*k / 2;
	cout << ans;
}

Measured memory_bytes: 5748
#include <algorithm>
#include <cstring>
#include <cstdio>
typedef long long ll;
ll arr[300005], sum[300005], dp_l[300005], dp_r[300005], dp[300005], tmp[300005], ans[300005]; 
int que[300005]; 
inline void rev(int n)
{
	std::reverse(arr + 1, arr + n + 1); 
	for (int i = 1; i <= n; i++)
		sum[i] = sum[i - 1] - arr[i]; 
}
inline ll calc(ll *val, int x, int y)
{
	ll a = val[x] + (ll)x * (x - 1) / 2 - sum[x], b = val[y] + (ll)y * (y - 1) / 2 - sum[y]; 
	return std::max((ll)y + 1, (b - a - 1) / (y - x) + 1); 
}
inline void init(ll *res, int n)
{
	int he = 0, ta = 0; 
	for (int i = 1; i <= n; i++)
	{
		while (he < ta && calc(res, que[ta - 1], que[ta]) <= i)
			ta--; 
		int pos = que[ta]; 
		// printf("%d %d\n", i, pos);
		res[i] = std::max(res[i - 1], res[pos] + (ll)(i - pos) * (i - pos + 1) / 2 + sum[i] - sum[pos]);
		while (he < ta && calc(res, que[ta - 1], que[ta]) <= calc(res, que[ta], i))
			ta--; 
		que[++ta] = i; 
	}
}
void work(int l, int r, int coef)
{
	if (l == r)
	{
		dp[l] = std::max(dp[l], -arr[l] + 1 + dp_l[l - 1] + dp_r[r + 1]); 
		return; 
	}
	int m = l + r + coef >> 1, he = 0, ta = -1; 
	for (int i = l - 1; i < m; i++)
	{
		while (he < ta && calc(dp_l, que[ta - 1], que[ta]) <= calc(dp_l, que[ta], i))
			ta--; 
		que[++ta] = i; 
	}
	for (int i = m + 1; i <= r; i++)
	{
		while (he < ta && calc(dp_l, que[ta - 1], que[ta]) <= i)
			ta--; 
		int pos = que[ta];
		tmp[i] = dp_l[pos] + (ll)(i - pos) * (i - pos + 1) / 2 + sum[i] - sum[pos] + dp_r[i + 1];
	}
	for (int i = r - 1; i > m; i--)
		tmp[i] = std::max(tmp[i], tmp[i + 1]); 
	for (int i = r; i > m; i--)
		dp[i] = std::max(dp[i], tmp[i]);
	work(l, m, coef); 
	work(m + 1, r, coef); 
}
int main()
{
	// freopen("ARC066-F.in", "r", stdin); 
	int n; 
	scanf("%d", &n); 
	for (int i = 1; i <= n; i++)
	{
		scanf("%lld", arr + i); 
		sum[i] = sum[i - 1] - arr[i]; 
	}

	init(dp_l, n); 

	rev(n); 
	init(dp_r, n); 
	std::reverse(dp_r + 1, dp_r + n + 1); 

	rev(n);
	memset(dp, -0x3f, sizeof(dp));
	work(1, n, 0); 
	memcpy(ans, dp, sizeof(dp)); 

	rev(n);
	memset(dp, -0x3f, sizeof(dp)); 
	for (int i = 1; i <= n; i++)
		std::swap(dp_l[i], dp_r[n - i + 1]); 
	work(1, n, -1);
	for (int i = 1; i <= n; i++)
		ans[i] = std::max(ans[i], dp[n - i + 1]); 

	rev(n); 
	for (int i = 1; i <= n; i++)
		std::swap(dp_l[i], dp_r[n - i + 1]); 

	int q; 
	scanf("%d", &q); 
	while (q--)
	{
		int x, y; 
		scanf("%d%d", &x, &y); 
		// printf("%lld %lld\n", dp_l[x - 1], dp_r[x + 1]);
		printf("%lld\n", std::max(ans[x] + arr[x] - y, dp_l[x - 1] + dp_r[x + 1]));
	}
	return 0; 
}


Measured memory_bytes: 18944
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF (1<<30)-1
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
#define vii vector<int>
#define vll vector<long long>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
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; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int n;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> n;
    vll x(n), y(n);
    rep(i, 0, n) {
        cin >> x[i];
        y[i] = x[i];
    }
    sort(all(y));
    rep(i, 0, n) {
        ll t = y[n/2-1];
        if (x[i] <= t) 
            t = y[n/2];
        cout << t << endl;
    }
    return 0;
}


Measured memory_bytes: 5376
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
    int n; ll x, d;
    cin>>n>>x>>d;
    ll m[55];
    vector<int> g[55];
    for(int i=0; i<n; i++){
        cin>>m[i];
        if(i==0) continue;
        int p;
        cin>>p; p--;
        g[p].push_back(i);
        g[i].push_back(p);
    }
    int cnt[55]={};
    auto dfs=[&](auto dfs, int x, int p)->void{
        cnt[x]=1;
        for(auto y:g[x]){
            if(y==p) continue;
            dfs(dfs, y, x);
            cnt[x]+=cnt[y];
          m[x]+=m[y];
        }
    };
    dfs(dfs, 0, -1);
    ll dp[125050];
    const ll INF=1e18;
    fill(dp, dp+n*n*n, INF);
  ll mx[55];
  mx[0]=cnt[0]-1;
  for(int i=1; i<n; i++){
    mx[i]=min(d, (ll)cnt[i]-1);
  }
  dp[0]=0;
  for(int i=0; i<n; i++){
    ll tmp[125050];
    deque<int> deq[50];
    for(int j=0; j<n*n*n; j++){
      int r=j%cnt[i];
      while(!deq[r].empty()){
        int k=deq[r].back();
        if(dp[k]-k*m[i]/cnt[i]<dp[j]-j*m[i]/cnt[i]) break;
        deq[r].pop_back();
      }
      deq[r].push_back(j);
      if(deq[r].front()==j-cnt[i]*(mx[i]+1)){
        deq[r].pop_front();
      }
      int k=deq[r].front();
      tmp[j]=dp[k]+(j-k)/cnt[i]*m[i];
    }
    for(int j=0; j<n*n*n; j++) dp[j]=tmp[j];
  }
  vector<int> ind(n);
  iota(ind.begin(), ind.end(), 0);
  sort(ind.begin(), ind.end(), [&](int i, int j){ return cnt[i]*m[j]>cnt[j]*m[i];});
  ll ans=0;
  for(int i=0; i<n*n*n; i++){
    //cout<<i<<" "<<dp[i]<<endl;
    if(dp[i]>x) continue;
    ll x1=x-dp[i], s=i;
    for(auto j:ind){
      ll c=x1/m[j];
      if(j) c=min(d-mx[j], c);
      s+=cnt[j]*c;
      x1-=c*m[j];
    }
    ans=max(ans, s);
  }
  cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
struct edge
{
	int v,nxt;
} vs[300000];
int sign[100010][15],q;
int n,m,st[100010],ee,col[100010];
inline void addedge(int u,int v)
{
	vs[++ee].v=v ;
	vs[ee].nxt=st[u];
	st[u]=ee;
}
void calc(int u,int d,int c)
{
	if(sign[u][d]) return ;
	sign[u][d]=1;
	if(d==0)
	{
		col[u]=c;
		return;
	}
	calc(u,d-1,c);
	for(int i=st[u]; i; i=vs[i].nxt)
		calc(vs[i].v,d-1,c);
}
void work(int cnt)
{
	if(cnt==0) return ;
	int u,d,c;
	scanf("%d%d%d",&u,&d,&c);
	work(cnt-1);
	calc(u,d,c);
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1; i<=m; i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		addedge(u,v);
		addedge(v,u);
	}
	scanf("%d",&q);
	work(q);
	for(int i=1; i<=n; i++) printf("%d\n",col[i]);
	return 0 ;
}


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

using namespace std;

int main()
{
    string s;
    int k;
    cin >> s >> k;

    vector<string> vs;
    for (int i = 0; i < s.size(); ++i) {
        for (int j = 1; i + j <= s.size() && j <= k; ++j) {
            vs.push_back(s.substr(i, j));
        }
    }

    sort(vs.begin(), vs.end());
    vs.erase(unique(begin(vs), end(vs)), end(vs));
    cout << vs[k-1] << endl;
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
ll fun(ll p)
{
    ll ans = 1;
    for (int i = 0; i < 5; i++)
        ans *= p;
    return ans;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n, a, b;
    cin >> a >> b;
    cin >> n;
    if (n < b - 1)
    {
        cout << (a * n) / b - a * (n / b) << "\n";
        return 0;
    }
    else
    {
        ll p = b - 1;
        cout << (a * p) / b - a * (p / b) << "\n";
    }

    return 0;
}

Measured memory_bytes: 3644
/*
 Remember not to use arithmetic operation in double while comparision 

 priority of uses
 array > maps > unordered_maps
*/

#include<bits/stdc++.h>
#define lli long long int
#define vl vector<lli>
#define vi vector<int>
#define pb push_back
#define pii pair<int,int>
#define pll pair<lli,lli>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int n;
	cin>>n;
	vector<vector<lli>> A(n,vector<lli>(3));
	for(int i=0;i<n;i++)
		cin>>A[i][0]>>A[i][1]>>A[i][2];
	// cout<<"breaks";
	if(n==1)
	{
		cout<<max(A[0][0],max(A[0][1],A[0][2]));
		return 0;
	}
	lli DP[3][n];
	for(int i=0;i<3;i++)
		DP[i][0]=A[0][i];
	for(int i=1;i<n;i++)
	{
		for(int j=0;j<3;j++)
		{
			DP[j][i]=A[i][j]+max(DP[(j+1)%3][i-1],DP[(j+2)%3][i-1])	;
		}
	}
	cout<<max(DP[0][n-1],max(DP[1][n-1],DP[2][n-1]));
	return 0;
}


Measured memory_bytes: 8064
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

int ma[11];
int a[11];int b[11];

bool ch;

int dx[]={1,0,0,-1};
int dy[]={0,-1,1,0};

void dfs(int deep,int aa,int bb)
{
    if(ch)return ;
    if(deep==10)
    {
        ch=true;
        return ;
    }


    if(ma[deep]>a[aa-1])
    {
        a[aa]=ma[deep];
        dfs(deep+1,aa+1,bb);
    }

    if(ch==false&&ma[deep]>b[bb-1])
    {
        b[bb]=ma[deep];
        dfs(deep+1,aa,bb+1);
    }

}


int main()
{
    int f;
    scanf("%d",&f);
    while(f--)
    {
        ch=false;
        memset(a,0,sizeof(a));
        memset(b,0,sizeof(b));
        for(int i=0;i<10;i++)
            scanf("%d",&ma[i]);
        dfs(0,1,1);
        if(ch)
            printf("YES\n");
        else
            printf("NO\n");
    }


}

Measured memory_bytes: 3116
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <numeric>
#include <string>
#include <bitset>
#include <functional>

using ld = long double;
using vld = std::vector<ld>;
using vvld = std::vector<vld>;
using vvvld = std::vector<vvld>;
using ll = long long;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vvvll = std::vector<vvll>;
using pll = std::pair<ll, ll>;
using vpll = std::vector<pll>;
using str = std::string;
using vstr = std::vector<str>;

template<typename T> bool chmin(T a, T &b) {
    return a < b ? b = a, true : false;
}
template<typename T> bool chmax(T a, T &b) {
    return a > b ? b = a, true : false;
}

constexpr ld PI = 3.141592653589793L;
constexpr ld EPS = std::numeric_limits<ld>::epsilon();

ll gcd(ll n, ll m) { return m ? gcd(m, n % m) : n; }
ll lcm(ll n, ll m) { return n / gcd(n, m) * m; }
bool isprime(ll n) {
    if (n < 2) return false;
    for (ll i = 2; i * i <= n; i++)
        if (n % i == 0) return false;
    return true;
}
vll sieve(ll n) {
    str flg(n + 1, '1');
    for (ll i = 2; i * i <= n; i++) {
        if (flg[i] == '0') continue;
        for (ll j = i * i; j <= n; j += i)
            flg[j] = '0';
    }
    vll res;
    for (ll i = 2; i <= n; i++)
        if (flg[i] == '1') res.push_back(i);
    return res;
}
ll rpow(ll x, ll n) {
    if (n == 0) return 1;
    ll k = 1;
    for (; n > 1; n /= 2) {
        if (n & 1) k *= x;
        x *= x;
    }
    return k * x;
}
ll modpow(ll x, ll n, ll mod) {
    if (n == 0) return 1;
    ll k = 1;
    for (; n > 1; n /= 2) {
        if (n & 1) (k *= x) %= mod;
        (x *= x) %= mod;
    }
    return k * x % mod;
}
ll modcomb(ll n, ll r, ll mod) {
    if (r < 0 || n < r) return 0;
    chmin(n - r, r);
    ll mul = 1, div = 1;
    for (ll i = 0; i < r; i++) {
        (mul *= n - i) %= mod;
        (div *= i + 1) %= mod;
    }
    return mul * modpow(div, mod - 2, mod) % mod;
}

/*----------------------------------------------------------------*/

void solve();

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

    solve();
}
void solve() {
    ll n, y;
    std::cin >> n >> y;

    y /= 1000;

    for (ll i = 0; i <= n; i++) for (ll j = 0; i + j <= n; j++) {
        ll k = n - (i + j);
        if (10 * i + 5 * j + k == y) {
            std::cout << i << ' ' << j << ' ' << k << '\n';
            return;
        }
    }

    std::cout << "-1 -1 -1" << '\n';
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std; 
string s;
int main()
{
	cin>>s;
	int l=s.size();
	vector<int> child(l,1);
	for(int j=l-1;j>0;j--)
		if(s[j]=='L' && s[j-1]=='L')
		{
			child[j-2] += child[j];
			child[j]=0;
		}
	for(int j=0;j<l-1;j++)
		if(s[j]=='R' && s[j+1]=='R')
		{
			child[j+2] += child[j];
			child[j]=0;
		}
	for(int i=0;i<l;i++)
		cout<<child[i]<<' ';
	cout<<endl;
	return 0;	
}

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

struct Card{ char suit;int value; };

void bubbleSort(struct Card A[], int N){
	for(int i=0;i<N;i++){
		for(int j=N-1;j>i;j--){
			if(A[j].value < A[j-1].value){
				struct Card t = A[j];
				A[j] = A[j-1];
				A[j-1] = t;
			}
		}
	}
}

void selectionSort(struct Card A[], int N){
	for(int i=0;i<N;i++){
		int minj=i;
		for(int j=i;j<N;j++){
			if(A[minj].value > A[j].value) minj = j;
		}
		if(minj != i){
			struct Card t = A[minj];
			A[minj] = A[i];
			A[i] = t;
		}
	}
}

bool isStable(struct Card A1[],struct Card A2[],int N){
	for(int i=0;i<N;i++){
		if(A1[i].suit != A2[i].suit) return false;
	}
	return true;
}

void print(struct Card A[],int N){
	for(int i=0;i<N;i++){
		if(i) cout<<" ";
		cout<<A[i].suit<<A[i].value;
	}
	cout<<endl;

}

int main(){
	int N;
	cin>>N;
	struct Card C1[36],C2[36];
	for(int i=0;i<N;i++){
		cin>>C1[i].suit>>C1[i].value;
	}
	
	for(int i=0;i<N;i++){
		C2[i] = C1[i];
	}
	
	bubbleSort(C1,N);
	print(C1,N);
	cout<<"Stable"<<endl;
	selectionSort(C2,N);
	print(C2,N);
	if(isStable(C1,C2,N)){
		cout<<"Stable"<<endl;
	}else{
		cout<<"Not stable"<<endl;
	}
	
	return 0;
}

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

using ll = long long;

const int mod = 1000000007;

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

int main() {
    ll n;
    cin >> n;
    vector<ll> v(n);
    rep(i,n) cin >> v[i];
    mint ans=0;
    mint tot=0;
    rep(i,n) tot+=v[i];
    rep(i,n-1){
        ll x=v[i];
        tot-=x;
        ans+=(x*tot.x);
    }
    cout << ans.x << endl;
}


Measured memory_bytes: 4740
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        if (a + b == c || b + c == a || c + a == b) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }

}

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

int f(int n){
    if(n%2 == 0)
        return n/2;
    else
        return 3*n + 1;
}

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

    int m=0; 
    int x=s;
    set<int> a;
    while(a.count(x) == 0){
        a.insert(x);
        x = f(x); m++;
    }
    cout << (a.size()+1) << endl;
    return 0;
}

Measured memory_bytes: 3620
n, k = gets.split(" ").map(&:to_i)

l0 = []
m0 = []

gets.split(" ").each do |x|
  x = x.to_i
  if x < 0
    l0.unshift(-x)
  else
    m0 << x
  end
end

ans = 4 * 10**8 + 1
ans = [ans, m0[k - 1]].min if m0.length >= k
ans = [ans, l0[k - 1]].min if l0.length >= k

1.upto(k - 1) do |i|
  a = []
  
  if l0.length >= i && m0.length >= (k - i)
    a << l0[i - 1]*2 + m0[k - i - 1]
  end
 
  if m0.length >= i && l0.length >= (k - i)
    a << m0[i - 1]*2 + l0[k - i - 1]
  end
  
  ans = [a.min, ans].min if a.size > 0
end

puts ans


Measured memory_bytes: 11220
#include <bits/stdc++.h>
#define debug(x) cout << #x << " = " << x << endl
#define REP(i,n) for(Long i = 0; i < (Long)n; i++)
#define pb push_back
using namespace std;
typedef long long ll;

const int N = 2e5 + 5;
ll ac[N];
string s;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> s;
	int n = s.size();
	ac[n] = 0;
	for (int i = n - 1; i >= 0; i--) {
		ac[i] = ac[i + 1] + (s[i] == 'W'? 1 : 0);
	}
	ll sum = 0;
	for (int i = 0; i < n; ++i) {
		if (s[i] == 'B') {
			sum += ac[i];
		}
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 2196
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;cin>>s;
	int l=s.length();
	int markc=1e9;
	int markf=-1e9;
	for(int i=0;i<=l;i++)
	if(s[i]=='C')
	{
		markc=i;
		break;
	}
	for(int i=l;i>=0;i--)
	if(s[i]=='F')
	{
		markf=i;
		break;
	}
	if(markc<markf)
	cout<<"Yes";
	else cout<<"No";
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main 
{
	public static void main(String[] args) 
	{
		Scanner stdIn = new Scanner(System.in);
		while(stdIn.hasNext())
		{
			int n = stdIn.nextInt();
			int ans = 0;
			for(int i = 0; i < 10; ++i)
			{
				for(int j = 0; j < 10; ++j)
				{
					for(int k = 0; k < 10; ++k)
					{
						for(int l = 0; l < 10; ++l)
						{
							if(i + j + k + l == n)
							{
								++ans;
							}
						}
					}
				}
			}
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 12000
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.ascii;
void times(alias fun)(int n) {
    foreach(i; 0..n) fun();
}
auto rep(alias fun, T = typeof(fun()))(int n) {
    T[] res = new T[n];
    foreach(ref e; res) e = fun();
    return res;
}
// fold was added in D 2.071.0.
template fold(fun...) if (fun.length >= 1) {
    auto fold(R, S...)(R r, S seed) {
        static if (S.length < 2) {
            return reduce!fun(seed, r);
        } else {
            return reduce!fun(tuple(seed), r);
        }
    }
}

void main() {
    readln.chomp.uniq.array.length.pipe!"a-1".writeln;
}


Measured memory_bytes: 792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
	ll n, a, b; cin >> n >> a >> b;
	ll old , now; cin >> old;
	ll ans = 0;
	for(int i = 1; i < n; ++i){
		cin >> now;
		ans += min<ll>(a * (now - old), b);
		old = now;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef int long long ll;




int main(){
    ll n,h;
    ll mi=10000000000;
    cin>>n>>h;
    vector<ll> a(n);
    vector<ll> b(n);
    for(int i=0;i<n;i++){
        ll x,y;
        cin>>x>>y;
        a.push_back(x);
        b.push_back(y);
    }
    vector<ll> bb(n);
    sort(a.rbegin(),a.rend());
        sort(b.rbegin(),b.rend());
    ll ans=0;
    ll nokori=h;
    for(int i=0;i<n;i++){
        if(b[i]>a[0]){
            ans++;
            nokori-=b[i];
            if(nokori<=0){
                cout<<ans<<endl;
                return 0;
            }
        }
    }
    
    ans+=nokori/a[0];
    if(nokori%a[0]!=0)ans++;
    cout<<ans<<endl;

return 0;
}


Measured memory_bytes: 4192
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    double R;
    cin >> R;

    double ans = 2 * R * 3.1415926535;
    printf("%f\n", ans);
    return 0;
}

Measured memory_bytes: 3808
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define rando mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define fi first
#define se second
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define debugii(x) cerr << " - " << #x << ": " << x.fi<<","<<x.se << endl;
#define sep() cerr << "--------------------" << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ld long double
#define ll long long
#define int ll
#define ii pair<int,int>
#define v vector<int>
#define vii vector<ii>
#define vv vector<vector<int> >
#define mp make_pair
#define INF 1000000000
#define pb push_back
#define EPS 1e-9
const int MOD = 1000000007; // 998244353
int32_t main(){
	boost;
	//freopen(".in","r",stdin);
	int n;
	cin>>n;
	set<int> d1,d2;
	for (int i = 1; i*i<= n; ++i)
	{
		if(!(n%i)){
			d1.insert(i);
			if((n/i)!=i)d1.insert(n/i);
		}
	}
	for (int i = 1; i*i<= (n-1); ++i)
	{
		if(!((n-1)%i)){
			d2.insert(i);
			if(((n-1)/i)!=i)d2.insert((n-1)/i);
		}
	}
	int ans=0;
	d1.erase(1),d2.erase(1);
	for(auto it:d1){
		int h=n;
		while(!(h%it))
			h/=it;
		if(h==1){
			ans++;
			continue;
		}
		if(!((h-1)%it)){
			ans++;
		}
	}
	for(auto it:d2){
		if(d1.find(it)!=d1.end())continue;
		if(!((n-1)%it)){
			ans++;
		}
	}
	cout<<ans;
	return 0;
}
//long long
//array bounds
//special cases
//binary search

Measured memory_bytes: 512
#include <algorithm>
#include <iostream>

using namespace std;

int main(){
	
	int x,y,s;
	while(cin >> x >> y >> s){
		if(x == 0 && y == 0 && s == 0)break;
		int ans = 0;
		for(int a = 1;a <= s;a++){
			for(int b = 1;b <= s;b++){
				if(a*(100 + x)/100 + b*(100 + x)/100 == s){
					ans = max(a*(100 + y)/100 + b*(100 + y)/100, ans);
				}				
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 2000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
#define seg_size 524288
int dp[67108864] = {};
int main() {
	for (int i = 1;i < 67108864;++i) {
		dp[i] = 300000;
	}
	string s;
	cin >> s;
	long long hashing = 0;
	int ans = 300000;
	for (int i = 0;i < s.length();++i) {
		hashing ^= (1 << (s[i] - 'a'));
		for (int q = 0;q < 27;++q) {
			long long mew = (1 << (q-1));
			if (q == 0) {
				mew = 0;
			}
			if (i == s.length() - 1) {
				ans = min(ans, dp[mew^hashing] + 1);
			}
			dp[hashing] = min(dp[(mew ^ hashing)]+1, dp[hashing]);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 262976