akhauriyash/Code-Regression huggingface dataset:
fun <T> permutationIndexOf(sortedList: List<T>, predicate: (List<T>, Int) -> Boolean): Pair<List<T>, Int> {
    val queue = mutableListOf<List<T>>()
    queue += arrayListOf<T>()
    var index = 0
    while (queue.isNotEmpty()) {
        val p = queue.removeAt(0)

        if (p.size == sortedList.size) {
            index++

            if (predicate(p, index)) {
                return Pair(p, index)
            }

            continue
        }

        for (item in (sortedList - p)) {
            queue += (p + item)
        }
    }

    return Pair(emptyList(), -1)
}

fun main(args: Array<String>) {
    val n = readInteger()
    val p = readIntegerList()
    val q = readIntegerList()

//    Math.abs().let(::println)
    val (pp, pc) = permutationIndexOf((1..n).toList()) { pp, i -> p == pp }
    val (qp, qc) = permutationIndexOf((1..n).toList()) { pp, i -> q == pp }
    Math.abs(pc - qc).let(::println)
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)


Measured memory_bytes: 85700
//
// Created by Hideaki Imamura on 2020-03-27.
//
# include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair <ll, ll> l_l;
typedef pair<int, int> i_i;

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

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

# define EPS (1e-7)
# define INF (1e9)
# define PI (acos(-1))
//const ll mod = 1000000007;

int N, M, S, T;
vector<vector<int>> G;

int dijkstra(int s, int t) {
    vector<int> d(3 * N, INF);
    d[s] = 0;

    priority_queue<i_i, vector<i_i>, greater<i_i>> que;
    que.push(i_i(0, s));
    while (!que.empty()) {
        i_i p = que.top();
        que.pop();
        int v = p.second;
        if (d[v] < p.first) continue;
        for (auto e : G[v]) {
            if (d[e] > d[v] + 1) {
                d[e] = d[v] + 1;
                que.push(i_i(d[e], e));
            }
        }
    }

    return d[t] == INF ? -3 : d[t];
}

int main() {
    cin >> N >> M;
    G.assign(3 * N, vector<int>());
    for (int i = 0; i < M; ++i) {
        int u, v;
        cin >> u >> v;
        u--;
        v--;
        G[3 * u + 0].push_back(3 * v + 1);
        G[3 * u + 1].push_back(3 * v + 2);
        G[3 * u + 2].push_back(3 * v + 0);
    }
    cin >> S >> T;
    S--;
    T--;
    cout << dijkstra(3 * S, 3 * T) / 3 << endl;
    return 0;
}

Measured memory_bytes: 17792
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
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;
}
void hr() { cerr << "--------------" << endl; }
const int INF = 2e9;
const int MOD = 1e9 + 7;

int main() {
   string s;
   cin >> s;
   sort(s.begin(), s.end());
   if (s[0] != s[2])
      cout << "Yes" << endl;
   else
      cout << "No" << endl;
   return 0;
}

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

/*
 * ____         __  __ _           _                         
 * / ___| _   _ / _|/ _(_)_  __    / \   _ __ _ __ __ _ _   _ 
 * \___ \| | | | |_| |_| \ \/ /   / _ \ | '__| '__/ _` | | | |
 *  ___) | |_| |  _|  _| |>  <   / ___ \| |  | | | (_| | |_| |
 *  |____/ \__,_|_| |_| |_/_/\_\ /_/   \_\_|  |_|  \__,_|\__, |
 *                                                       |___/ 
 */
 /*
 接尾辞(Suffix)とは、文字列のある場所から末尾までの部分文字列です。文字列全体や空文字列も接尾辞となりま す。逆に、文字列の先頭からある場所までの部分文字列は接頭辞(Prefix)と呼びます。
 接尾辞配列(Suffix Array)とは、ある1つの文字列のすべての接尾辞を辞書順にソートしたものです。実際には 接尾辞は文字列としてではなく、開始位置で管理します。以下、文字列 S の場所 i からの接尾辞を S[i...]と表すこ とにします。
 */

 /*
  *Implementation of Suffix Array
  *Manber & Myers
  *基本的なアイディアは、ダブリングと呼ばれるものです。各位置からの 2 文字の部分文字列たちの順番をまず計算し、
  *それを用いて各位置から 4 文字の順番を次に計算、次に 8 文字、...としていき、n 以上になったところで接尾 辞配列が得られます。
  *S[i, 2k]、S[j, 2k] を文字列比較する代わりに、rank k (i)と rank k (i+k)のペアと、rank k (j)と rank k (j+k)のペアを比較します。
  */

#define MAX_N 5100
int n, k;
int srank[MAX_N + 1];
int tmp[MAX_N + 1];
int sa[MAX_N + 1];

// (srank[i], srank[i + k])と(srank[j], srank[j + k])を比較
bool compare_sa(int i, int j) {
	if (srank[i] != srank[j]){
		return srank[i] < srank[j];
	}else{
		int ri = i + k <=n ? srank[i + k] : -1;
		int rj = j + k <=n ? srank[j + k] : -1;
		return ri < rj;
	} 
}

// 文字列Sの接尾辞配列を構築
void construct_sa(string S) {
	n = S.length();
	// 最初は1文字、ランクは文字コードにすればよい
	for (int i = 0; i <= n; i++) {
		sa[i] = i;
		srank[i] = i < n ? S[i] : -1;
	}
	// k文字についてソートされているところから、2k文字でソートする
	for (k = 1; k <= n; k *= 2) {
		sort(sa, sa + n + 1, compare_sa);
		// いったんtmpに次のランクを計算し、それからsrankに移す
		tmp[sa[0]] = 0;
		for (int i = 1; i <= n; i++) {
			tmp[sa[i]] = tmp[sa[i - 1]] + (compare_sa(sa[i - 1], sa[i]) ? 1 : 0);
		}
		for (int i = 0; i <= n; i++) {
			srank[i] = tmp[i];
		} 
	}
}

string S;
long long K;
int main(){
	cin >> S >> K;
	construct_sa(S);

	set<string> done;

	long long i = 1;
	for(long long i = 1; i <= S.length(); i++){
		//cout << "K = " << K << " i = " << i << endl;
		//cout << "sa[i] = " << sa[i] << endl;
		//cout << S.substr(sa[i]) << endl;
		long long len = S.length() - sa[i];
		//cout << "len = " << len << endl;

		for(long long j = 1; j <= len; j++){
			string newstr = S.substr(sa[i], j);
			//cout << "K = " << K << endl;
			//cout << "newstr = " << newstr << endl;
			if(done.count(newstr) == 0){
				done.insert(newstr);
				K--;
				if(K == 0){
					cout << newstr << endl;
					return 0;
				}
			}
		}
	}
}

Measured memory_bytes: 384
a, b, n = gets.split(" ").map &:to_i
x = b - 1
if x > n
  x = n
end
ans = 0
while x <= b && x <= n
  max = ((a*x)/b).floor - a*(x/b).floor
  if ans < max
    ans = max
  end
  x += 1
end
puts ans

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

#define int long long

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

    while(cin >> n, n != 0){
        int a[70000];
        int b[70000];

        int sum = 0;
        int cnt = n;
        for(int i = 0;i < n;i++){
            cin >> a[i];
            sum += a[i];
        }

        priority_queue<int> que;

        for(int i = 0;i < n-1;i++){
            cin >> b[i];
            que.push(b[i]);
        }

        int ans = sum * cnt;

        while(!que.empty()){
            sum += que.top();
            cnt--;
            que.pop();
            ans = max(ans, sum * cnt);
        }

        cout << ans << endl;
    }

    return 0;
}




Measured memory_bytes: 4924
"use strict";
function I(s,f){this._s=s.split("\n");this._c=0;this._l=0;this._f=f||Number}I.prototype.a=function(){var l=this._s[this._l];if(!l)return;var t=l.trim().split(" ");var a=t[this._c];this._c++;if(t.length===this._c){this._c=0;this._l++}return this._f(a)};I.prototype.l=function(){var l=this._s[this._l];if(!l)return;this._c=0;this._l++;return l.split(" ").map(this._f)};

function main(input) {
  const o = new I(input);

  var arr = [];
  var mod = 10;
  for (var i = 0; i < 5 ; i++){
    var m = o.a();
    var mm = m % 10;
    if ( mm < mod  && mm > 0) {
      mod = mm;
    }
    arr.push(m);
  }

  if (mod === 10) {
    console.log(arr.reduce((acc, cur) => acc + cur));
  } else {
    var sum = 0;
    for (var i = 0; i < 5 ; i++){
      if (arr[i]%10 === 0) {
        sum += arr[i];
      } else {
        sum += arr[i] - arr[i] % 10 + 10;
      }
    }

    console.log(sum - 10 + mod);

  } 


}


main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using bint = boost::multiprecision::cpp_int;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repSE(i,s,n) for (int i = (s); i < (n); i++)
#define ssort(v) sort(v.begin(), v.end())
#define gsort(v) sort(v.rbegin(), v.rend())
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }

int main()
{
    ll X;
    cin >> X;
    int cnt = 0;
    ll mon = 100;
    while (mon < X) {
        cnt ++;
        mon += mon / 100;
    }
    cout << cnt << "\n";
    return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
	int N,roop;
	cin >> N;
	vector<int> An(N);
	for(roop=0;roop<N;roop++){
		cin >> An[roop];
	}
	int fw=0,bw=N-1;
	int etfw=-1,etbw=N;
	sort(An.begin(),An.end());
	int ans=N;
	while(bw-fw>0){
		while(An[fw]!=An[fw+1]&&bw-fw>0)
			fw++;
		while(An[bw]!=An[bw-1]&&bw-fw>0)
			bw--;
		if(bw-fw>0){
			etfw=fw;
			etbw=bw;
			fw++;
			bw--;
			ans-=2;
		}
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;
const int N = 1e5+1;

int a[N];
int main(){
    ios::sync_with_stdio(0);
    int n; cin >> n;
    if (n&1){
        cout << "0\n";
        return 0;
    }

    for (int i = 0; i < n; ++ i)
        cin >> a[i];
    sort(a, a+n);

    int ans = a[n/2]-a[n/2-1];
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 640
#ifndef LOCAL
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#else
#include <iostream>
#include <iomanip> 
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <memory>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair < b, c > d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; }
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds; 
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}
#define fix(a) fixed << setprecision(a)
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define len(V) (int)V.size()
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define endl '\n'

void solve(){
  int n;
  cin >> n;
  vector<ll>a(n+1);
  forn(i,n+1) cin >> a[i];
  vector<ll>b(n);
  forn(i,n) cin >> b[i];
  ll ans = 0;
  forn(i, n){
    ll m = min(a[i], b[i]);
    ans += m;
    b[i] -= m;
    m = min(a[i+1], b[i]);
    ans += m;
    a[i+1] -= m;
  }
  cout << ans;
}

int main() {
  ios::sync_with_stdio(false);
  // cin.tie(0); cout.tie(0);
  int t = 1;
  // cin >> t;
  forn(i, t){
    solve();
  }
}

/* 


*/

Measured memory_bytes: 4852
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define INF 1000000000
int main(){
cin.tie(0);
ios::sync_with_stdio(false);

	int N,K;
	cin>>N>>K;
	vector<int>A(N);
	REP(i,N)
		cin>>A[i];
	int b=N-1;
	int c=K-1;
	cout<<(b+c-1)/c<<endl;
	
	return 0;
}

Measured memory_bytes: 640
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    int a, b, c;
    cin >> a >> b >> c;

    cout << max(0, c - (a - b)) << "\n";
    return 0;
}

Measured memory_bytes: 888
// TLE出したのでうちもうお嫁行かれへん

#include <bits/stdc++.h>

#define REP(i,n) for(int i = 0; i < (n); ++i)
#define REP1(i,n) for(int i = 1; i <= (n); ++i)
#define RREP(i, n) for(int i = (n) - 1; i >= 0; --i)
#define ALL(a) begin(a), end(a)
#define MP(a,b) make_pair((a), (b))
#define ROUNDUP(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))
#define X first
#define Y second
#define DEBUG(a) cout << #a << ": " << a << "\n"
// #define DEBUG(a) {}

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

constexpr int MOD = 1e9 + 7;
constexpr int INF = 1e9 + 1;
constexpr ll LLINF = 4 * 1e18 + 1;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

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

template<typename T>
T debug(T x) {
	DEBUG(x);
	return x;
}

int dist(pii x, pii y){
	return abs(x.X - y.X) + abs(x.Y - y.Y);
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int h, w, d;
	cin >> h >> w >> d;
	vector<vi> a(h, vi(w));
	vector<pii> b(h * w + 1);
	REP(i, h) REP(j, w) {
		cin >> a[i][j];
		b[a[i][j]] = {i, j};
	}
	int q;
	cin >> q;
	vi l(q), r(q);
	REP(i, q) cin >> l[i] >> r[i];
	vector<vi> cost(d + 1, vi(w * h / d + 2));
	REP1(i, d){
		int j = 1;
		while(j * d + i <= w * h){
			cost[i][j] = dist(b[i + (j - 1) * d], b[i + j * d]);
			j++;
		}
		REP1(j, w * h / d + 1) cost[i][j] += cost[i][j - 1];
	}
	REP(i, q){
		int ans = cost[(r[i] % d == 0 ? d : r[i] % d)][(r[i] - 1) / d] - cost[(l[i] % d == 0 ? d : l[i] % d)][(l[i] - 1) / d];
		cout << ans << "\n";
	}
	return 0;
}


Measured memory_bytes: 7168
n=int(input())
alis=sorted(list(map(int,input().split())))
p=alis[0]
if p==0:
  print(0)
  exit()
bre=False
for i in range(1,n):
  p*=alis[i]
  
  
  if len(list(str(p)))>18:
    bre=True
    break


if bre:
  sa=list(map(int,list(str(p))))
  if sum(sa)!=1:print(-1)
  else:print(p)
else:print(p)

Measured memory_bytes: 84720
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define Rep(i,a,b) for(register int i=(a);i<=int(b);++i)
#define Dep(i,a,b) for(register int i=(a);i>=int(b);--i)
#define rep(i,a,b) for(register int i=(a);i<int(b);++i)
#define mem(x,v) memset(x,v,sizeof(x))
#define fi first
#define se second
#define gc getchar
#define pc putchar
inline ll read(){
    ll x=0,f=1;char c=gc();
    for(;!isdigit(c);c=gc())if(c=='-')f=-1;
    for(;isdigit(c);c=gc())x=(x<<1)+(x<<3)+(c^48);
    return x*f;
}
inline void write(ll x){if(x<0)x=-x,pc('-');if(x>=10)write(x/10);putchar(x%10+'0');}
inline void wri(ll x){write(x);pc(' ');}
inline void writeln(ll x){write(x);pc('\n');}
const int maxn = 605;
const int mod = 1e9+7;
int dp[maxn][maxn],g[maxn],h[maxn][maxn];
int n,m,a[maxn],b[maxn]; 
bool in(int l,int r,int x){
	return l<=x&&x<=r;
}
int get(int l,int r){
	int cnt = 0;
	Rep(i,1,m){
		bool f1 = in(l,r,a[i]),f2 = in(l,r,b[i]);
		if(f1^f2) return -1;
		if(f1)cnt++;
	}
	return cnt*2;
}
int main(){
	n = 2*read(),m = read();
	Rep(i,1,m) a[i] = read(),b[i] = read();
	g[0] = 1;for(int i=2;i<=n;i+=2) g[i] = 1ll * g[i-2] * (i-1) % mod;
	Rep(i,1,n)Rep(j,i,n)h[i][j]=get(i,j);
	int ans = 0;
	for(int l=2;l<=n;l+=2){
		for(int i=1;i+l-1<=n;i++){
			int j=i+l-1;
			int c=h[i][j];
			if(c!=-1){
				dp[i][j]=g[l-c];
				for(int k=i+1;k<j;k+=2)
					if(h[k+1][j]!=-1 && h[i][k]!=-1)
						dp[i][j] = (dp[i][j] - 1ll * dp[i][k]*g[j-k-h[k+1][j]]%mod+mod)%mod;
//				printf("{%d %d}\n",dp[i][j],g[n-l-(m*2-c)]);
				ans = (ans + 1ll * dp[i][j] * g[n-l-(m*2-c)]) % mod;
			}
		}
	}
	writeln(ans);
	return 0;
}

Measured memory_bytes: 3072
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int N = 15;
int a[N];
int ans;
int n,m,book[N][N],x;

int main(){
	scanf("%d%d%d",&n,&m,&x);
	for(int i = 1;i <= n;i++){
		for(int j = 0;j <= m;j++){
			scanf("%d",&book[i][j]);
		}
	}
	ans = inf;
	for(int i = 1;i < (1<<n);i++){
		memset(a,0,sizeof(a));
		int state = i;
		int tmp = 0;
		for(int j = 0;j < n;j++){
			if((state>>j)&1){
				for(int k = 1;k <= m;k++){
					a[k] += book[j+1][k];
				}
				tmp += book[j+1][0];
			}
		}
		bool f = 1;
		for(int j = 1;j <= m;j++){
			if(a[j] < x) {f = 0;break;}
		}
		if(f) ans = min(ans,tmp);
	}
	if(ans == inf) puts("-1");
	else printf("%d\n",ans);
	return 0;
}

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

int main() {
  for(int N; cin >> N && N;) {
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    int ans = 1<<28;
    vector<int> v(4);
    for(int a = 0; a <= A; ++a) {
      for(int b = 0; b <= B; ++b) {
        for(int c = 0; c <= C; ++c) {
          for(int d = 0; d <= D; ++d) {
            int rem = a*10 + b*50 + c*100 + d*500 - N;
            if(rem < 0) continue;
            int res = A+B+C+D - (a+b+c+d);
            res += rem / 500;
            rem %= 500;
            res += rem / 100;
            rem %= 100;
            res += rem / 50;
            rem %= 50;
            res += rem / 10;
            if(ans > res) {
              ans = res;
              v[0] = a;
              v[1] = b;
              v[2] = c;
              v[3] = d;
            }
          }
        }
      }
    }
    static int tc = 0;
    if(tc++) cout << endl;
    if(v[0]) cout << 10 << " " << v[0] << endl;
    if(v[1]) cout << 50 << " " << v[1] << endl;
    if(v[2]) cout << 100 << " " << v[2] << endl;
    if(v[3]) cout << 500 << " " << v[3] << endl;
  }
  return 0;
}

Measured memory_bytes: 1196
#include <cstdio>

int main(void) {
  char b;
  scanf("%c", &b);
  
  if( b == 'A') {
    printf("T\n");
  }
  else if( b == 'T') {
    printf("A\n");
  }
  else if(b == 'C') {
    printf("G\n");
  }
  else {
    printf("C\n");
  }
  return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
int main(){
  int n,i,count=0;
  scanf("%d",&n);
  int a[n+1];
  for(i=1;i<=n;i++){
    scanf("%d",&a[i]);
    if(i%2==1 && a[i]%2==1)
     count++;
  }
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 1728
//CODING ME ACCHHA KARNEKA HAI TERKO TO BAS PRACTICE KARTE REH
#include <bits/stdc++.h>
#define pragma
using namespace std;
#define ll unsigned long long
#define ld long double
#define pb push_back
#define pf push_front
#define aisort sort(a,a+n)
#define adsort sort(a,a+n,greater<ll>())
#define PI 2 * acos(0)

typedef pair<ll, ll> pii;
typedef pair<ll, pii> piii;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<piii> viii;
typedef set<ll> Set;

const ll maxs = 1e5+3;
const ll maxs1 = 1e3+4;
const ll mod = 1e9 + 7;

//MODULO OPEARTIONS
    inline ll add(ll a, ll b) { return (mod + a + b) % mod; }
    inline ll sub(ll a, ll b) { return (a - b + mod) % mod; }
    inline ll mul(ll a, ll b) { return (1ll * a * b) % mod; }

//POWER
    ll fastpow(ll x,ll y)
    {ll res = 1;x = x % mod;while (y > 0){ if (y & 1)res = (res * x) % mod; y = y >> 1 ; x = (x * x) % mod; } return res;}

//MODULAR INVERSE
    ll inv(ll x){ return fastpow(x , mod - 2);}
    
//PRIME
    bool isPrime(ll n) { if (n <= 1)  return false; if (n <= 3)  return true;if (n%2 == 0 || n%3 == 0) return false; for (int i=5; i*i<=n; i=i+6) if (n%i == 0 || n%(i+2) == 0) return false; return true; } 


int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
   string a,b;
   cin>>a>>b;
   ll x,y;
   cin>>x>>y;
   string c;
   cin>>c;
   if(a==c)
   {
       x--;
       cout<<x<<" "<<y;
   }
   else
   {
       y--;
       cout<<x<<" "<<y;
       }
}



Measured memory_bytes: 3632
#include <bits/stdc++.h>
 
using namespace std;
 
int gcd(int a, int b) {
 	return a == 0 ? b : gcd(b % a, a); 
}

int main()
{
  int n, x, g = 0;
  cin >> n >> x;
  for(int i=0;i<n;i++) {
    int t;
    cin >> t;
    g = gcd(g, abs(t - x));
  }
  cout << g << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
template<class T> inline bool chmax(T& a, T b) { 
if (a < b) { a = b; return true; } return false; 
}
template<class T> inline bool chmin(T& a, T b) {
 if (a > b) { a = b; return true; } return false; 
 }
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  string s;
  cin>>s;
  ll n=sz(s);
  vvll dp(100005,vll(2));
  dp[0][0]=1;
  rep(i,n){
    {//0
      if(s[i]=='0'){
        dp[i+1][0]=dp[i][0];
        dp[i+1][1]=dp[i][1];
      }
      else{
        dp[i+1][1]=(dp[i][0]+dp[i][1])%MOD;
      }
    }
    {
      if(s[i]=='0'){
        dp[i+1][1]+=(dp[i][1]*2)%MOD;
        dp[i+1][1]%=MOD;
      }
      else{
        dp[i+1][1]+=dp[i][1]*2;
        dp[i+1][1]%=MOD;
        dp[i+1][0]+=dp[i][0]*2;
        dp[i+1][0]%=MOD;
      }
    }
  }
  COUT((dp[n][0]+dp[n][1])%MOD);
}


Measured memory_bytes: 5760
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;
#define int long long int
const int INF = 1001001001001001LL;

int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

signed main(){
    
    int w, h, x, y; cin >> w >> h >> x >> y;
    int ans = 0;
    if(2 * x == w && 2 * y == h) ans = 1;
    double S = (double)(h * w) / 2.0;
    printf("%.10f %lld\n", S, ans);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,T;
  cin >> A >> T >> B;
 
  if (A * T > B ) {
    cout << B << endl;
  }
 
  if (A * T < B) {
    cout << A * T << endl;
  }
 
  if (A * T == B) {
    cout << A * T << endl;
  }
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define all(x) (x).begin(),(x).end()
typedef long long int ll;
using namespace std;
int main()
{
  int k, x;
  cin >> k >> x;
  int l = max(-1000000, x - k + 1);
  int r = min( 1000000, x + k - 1);
  for (int i = l; i <= r; i++){
    cout << i <<" ";
  }
  cout << "\n" << endl;
}


Measured memory_bytes: 256
N,a,b = map(int,input().split())
MOD = 10**9 + 7
def comb(n,k, mod):
    m = 1#分子
    l = 1#bunnbo
    for i in range(k):
        m *= n - i
        l *= (i + 1)
        m %= mod
        l %= mod
    return m * pow(l, mod-2, mod) % mod

Sum = pow(2, N, 10**9+7) -1 - comb(N, a, MOD) - comb(N, b, MOD)
Sum = Sum % (10**9+7)
print(Sum)

Measured memory_bytes: 3188
#include<stdio.h>
#include<stdlib.h>
int binarysearch(int*,int,int);
int main(){
  int i=0,q,k,cnt=0;
  int n;
  int *t,*s;
  scanf("%d",&n);
  s=(int *)malloc(n * sizeof(int));
  for(i=0;i<n;i++){
    scanf("%d",&s[i]);
  }
  scanf("%d",&q);
  t=(int *)malloc(q * sizeof(int));
   for(i=0;i<q;i++){
    scanf("%d",&t[i]);
  }
  for(i=0;i<q;i++){
    k=binarysearch(s,t[i],n);
    if(k==1)cnt++;
  }
  printf("%d\n",cnt);
  free(t);
  free(s);
  return 0;
}
int binarysearch(int s[],int key,int n){
  int left=0;
  int right=n;
  int mid;
  while(left<right){
    mid=(left+right)/2;
    if(s[mid]==key)return 1;
    else if(key<s[mid])right=mid;
    else left=mid+1;
  }
  return 0;
}



Measured memory_bytes: 2128
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int (i) = 0, i_len = n; (i) < (i_len); ++(i))
#define repp(i,n) for(int (i) = 1, i_len = n; (i) <= (i_len); ++(i))
#define per(i,n) for(int (i) = n-1; (i) >= 0; --(i))
#define perr(i,n) for(int (i) = n; (i) > 0; --(i))
#define sz(x) ((int)(x).size())
#define popcnt __builtin_popcount
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define Pi 3.1415926535
#define MOD = 1e9+7;
using namespace std;
using ll = long long;
using pint = pair<int,int>;
using itn = int;
using vint = vector<int>;
template<class T,class S> inline bool chmax(T& a, S b){if(a<b){a = b; return true;} return false;}
template<class T,class S> inline bool chmin(T& a, S b){if(a>b){a = b; return true;} return false;}
template<class T> T gcd(T a, T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a, T b){return a*b/gcd(a,b);}

int solve(){
    int n,m; cin >> n >> m;
    cout << n*(n-1)/2 + m*(m-1)/2 << endl;

    return 0;
}

int main(){
    cin.tie(0);
    cout << fixed << setprecision(10);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}


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

int main(){
	int n;
  	cin >> n;
  	double ans = 0.0, a;
  	
  	rep(i, n){
      	cin >> a;
      	ans += 1.0 / a;
    }
  	ans = 1.0 / ans;
  
  	printf("%f", ans);
}

Measured memory_bytes: 3708
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
#define pq priority_queue
#define P pair<int,int>
#define P2 pair<int,P>
#define P3 pair<int,P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const ll LINF=1e18;
const ld PI=abs(acos(-1));
string s;

int main(){
	cin >> s;
	
	//全てのアルファベットについて貪欲をためす.
	int mi=INF;
	for(int c='a';c<='z';c++){
		
		int cou=0;
		string w=s;
		while(w.size()){
			string t=""; bool f=true;
			REP(i,0,w.size()) if(w[i]!=c) f=false;
			if(f){mi=min(mi, cou); break;}
			
			REP(i,0,w.size()-1){
				if(w[i]==c) t+=w[i];
				else if(w[i+1]==c) t+=w[i+1];
				else t+=w[i];
			}
			
			w=t;
			cou++;
		}
	}
	
	cout << mi << endl;
	return 0;
}



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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

int main()
{

    lint n;
    cin >> n;

    double ans, tmp;

    ans = (double)(n / 2 +n%2) / (double) n;

    cout << ans <<"\n";

    return 0;
}

Measured memory_bytes: 256
from bisect import bisect_left, bisect_right

Q = int(input())
LR = [list(map(int, input().split())) for _ in range(Q)]

prime_flags = [1]*(10**5+1)
prime_flags[1] = 0
for i in range(2, 10**5+1):
    if prime_flags[i] == 0:
        continue
    for j in range(2*i, 10**5+1, i):
        prime_flags[j] = 0

num2017s = []
for i in range(1, 10**5+1, 2):
    if prime_flags[i] == prime_flags[(i+1)//2] == 1:
        num2017s.append(i)

for l, r in LR:
    print(bisect_right(num2017s, r) - bisect_left(num2017s, l))


Measured memory_bytes: 29056
#include<bits/stdc++.h>
using namespace std;
int main()
{
 long long int n,m,v,p,x,y,z;
 cin>>n>>m>>v>>p;
 long long int a[n];
 long long int s[n];
 int i;
 for(i=0;i<n;i++)
 {
 	cin>>a[i];
 }
 sort(a,a+n,greater<long long int> ());
 int ans=p;
 s[p-1]=0;
 for(i=p;i<n;i++)
 {
 	s[i]=s[i-1]+a[p-1]-a[i];
 	//cout<<s[i]<<endl;
 }
 for(i=p;i<n;i++)
 {
 	x=m*v-m*(p+n-i-1);
 	if(x>0)
 	{
 	 	x-=s[i-1];
 	 	if(x>0)
 	 	{
 	 	 if(x%(i-p+1)==0)
		   {
		   	y=a[p-1]+x/(i-p+1);
		   	if(y>(a[i]+m))
		   	break;
		   	else
		   	ans++;
		   }
		  else
		  {
		  	y=a[p-1]+x/(i-p+1)+1;
		   	if(y>(a[i]+m))
		   	break;
		   	else
		   	ans++;
		  }	
		}
		else
		{
			if(a[i]+m>=a[p-1])
			ans++;
			else
			break;
		}
	}
	else
	{
		if((a[i]+m)>=a[p-1])
		ans++;
		else
		break;
	}
 }
 cout<<ans<<endl;
 return 0;
}


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

#define fio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define all(a) a.begin(),a.end()
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i >= b;i--)
#define tc(t) int t; cin >> t; while (t--)
#define ll long long
#define pb push_back
#define sz(v) v.size()
#define pln(a)  cout<<a;
#define rr return 0;
#define rr1 return 1;
#define vr return;
#define int long long 

void solve()
{
  int a;
  string b, b1;
  cin>>a>>b;
  
  for0(i, b.length()) {
    if(b[i] != '.') {
      b1 += b[i];
    }
  }
  
  int c = stoi(b1);
  //cout<<c<<"\n";
  cout<<(a*c)/100;
}

signed main() {

  fio;
  
  
  //tc(t) {
    solve();
    pln("\n");
  //}
  
  rr;
}

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

int main() {
  int N;
  cin >> N;
  
  int sA=0,sB=0;
  
  vector<int> A(N);
  for (int i=0; i<N; i++) {
    cin >> A.at(i);
  }
  
  for (int j=0; j<N; j++) {
    int a=0;
    
    for (int i=0; i<N; i++) {
    	if (a < A.at(i)) {
      	a=A.at(i);
   	 	}
  	}
  
  	for (int i=0; i<N; i++) {
    	if (A.at(i) == a) {
      	A.at(i)=0;
      	break;
    	}
  	}
  
  	if (j%2==0) {
    	sA += a;
  	}
  	else {
    	sB += a;
  	}
  }
  
  cout << sA-sB << endl;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
int main(){
	int m,n;
	cin>>m>>n;
	int a[1000005],maxn=-1;
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<n-1;i++){
		maxn=max(a[i+1]-a[i],maxn);
	}
	maxn=max(m+a[0]-a[n-1],maxn);
	cout<<m-maxn;
	return 0; 
}

Measured memory_bytes: 3072
#include <iostream>

using namespace std;

bool search(int S[], int n, int key) {
    int left = 0;
    int right = n;
    int mid;
    while(left <= right) {
        mid = (left + right) / 2;
        if(S[mid] == key) return true;
        else if(S[mid] > key) right = mid - 1;
        else left = mid + 1;
    }
    return false;
}

int main() {
    int n, q;
    cin >> n;
    int S[n + 1];
    for(int i = 0; i < n; i++) cin >> S[i];
    cin >> q;

    int cnt = 0;
    for(int i = 0; i < q; i++) {
        int t;
        cin >> t;
        if(search(S, n, t)) cnt++;
    }
    cout << cnt << endl;
}


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

namespace ConsoleApplication
{
    class Program
    {
        public static void Main(string[] args)
        {
            var nums = Utils.ReadInts().OrderByDescending(i => i);
            var max = nums.First();
            var others = nums.Skip(1).Sum();
            var res = max == others ? "Yes" : "No";
            System.Console.WriteLine(res);
        }
    }

    static class Utils
    {
        public static IEnumerable<int> ReadInts()
            => ReadStrings().Select(int.Parse);

        public static int ReadInt()
            => Console.ReadLine().ToInt();
            
        public static IEnumerable<string> ReadStrings()
            => Console.ReadLine().Split(' ');

        public static int ToInt(this string str)
            => int.Parse(str);
    }
}


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


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


N, X = map(int, input().split())
x = [int(_) for _ in input().split()]
GCD = abs(X-x[0])

for i in x:
    GCD = gcd(GCD, abs(X-i))

print(GCD)

Measured memory_bytes: 14168
a=input().split()
a=[int(i) for i in a]
b=[]
cnt=0
time=0
for i in range(a[0]):
  b.append(input().split())
  cnt+=int(b[i][1])
i=0
while cnt!=time:
  if int(b[i][1])<=a[1]:
    time+=int(b[i][1])
    print(b[i][0],time)
    b.pop(0)
  else: 
    b[i][1]=int(b[i][1])-a[1]
    time+=a[1]
    b.append(b.pop(i))
    


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

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

    vector<int> a(n),b(n); 
    for(int i=0; i<n; i++){
        cin>>a[i];
        b[i]=a[i];
    }

    sort(b.begin(),b.end());
    reverse(b.begin(),b.end());

    for(int i=0; i<n; i++){
        if(a[i]==b[0]){
            cout<<b[1]<<endl;
        }else{
            cout<<b[0]<<endl;
        }
    }
}

Measured memory_bytes: 3200
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

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

    vl dp(n+1, INF);  // dp[i] : i円払うのに必要な操作回数の最小値
    dp[0] = 0;
    rep(i, n) {
        for(ll pow6 = 1; i+pow6 <= n; pow6 *= 6) {
            chmin(dp[i+pow6], dp[i] + 1);
        }
        for(ll pow9 = 1; i+pow9 <= n; pow9 *= 9) {
            chmin(dp[i+pow9], dp[i] + 1);
        }
    }

    out(dp[n]);
    re0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
 
int main() {
    ll N,K;
    cin >> N >> K;
    ll sum=0;
    
    vector<int> vec(N);
    for (int i = 0; i < N; i++) {
        cin >> vec.at(i);
    }
    
    sort(vec.begin(),vec.end());
    
    if(K>=N){
        sum=0;
    }
    else{
    for (int i = 0; i < K; i++) {
        vec.pop_back();
    }
    
    for (int i = 0; i < vec.size(); i++) {
        sum+=vec.at(i);
    }
    }
    cout << sum << endl;
    
}


Measured memory_bytes: 1024
import sys
def input(): return sys.stdin.readline().strip()


def main():
    N = int(input())
    T, A = map(int, input().split())
    H = list(map(int, input().split()))
    cand = -1
    diff = 1000000
    for i, h in enumerate(H):
        if abs(A - (T - h * 0.006)) < diff:
            cand = i + 1
            diff = abs(A - (T - h * 0.006))
    print(cand)



if __name__ == "__main__":
    main()


Measured memory_bytes: 38384
import java.util.*;
class Main
{
		public static void main(String[] args) 
		{
			Scanner sc = new Scanner(System.in);
			
			String s = sc.next();
			
			int s1 = s.charAt(0);
			int s2 = s.charAt(1);
			int s3 = s.charAt(2);
			
			int sum = 0;
			
			if(s1!='0'){
				sum++;
			}
			
			if(s2!='0'){
				++sum;
			}
			
			if(s3!='0'){
				sum++;
			}
			System.out.println(sum);
		}
}

Measured memory_bytes: 21204
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl
 
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef deque<bool> db;
template<class T> using vv=vector<vector< T > >;

int main() {
  int n;
  ll k;
  scanf("%d %lld", &n, &k);
  vll hoge(100001, 0);
  vll accum(100001, 0);
  rep (i, n) {
    int a, b;
    scanf("%d%d", &a, &b);
    hoge[a] += b;
  }
  rep (i, 100001) {
    accum[i+1] = accum[i] + hoge[i+1];
  }
  int l = 0;
  int r = 100000;
  while (r - l > 1) {
    int mid = (l + r) / 2;
    if (accum[mid] >= k) {
      r = mid;
    } else {
      l = mid;
    }
  }
  printf("%d\n", r);

  return 0;
}


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

int main() 
{
	int i, n, out, base, point;
	char str[8];

	scanf("%d", &n);

	for (i = 0; i<n; i++) 
	{
		point = base = out = 0;

		while (1) 
		{

			scanf("%s", str);

			if (strcmp(str, "OUT")==0) 
			{
				++out;
				if (out == 3)break;
			}
			else if (strcmp(str, "HIT")==0) 
			{
				if (base < 3)
				{
					++base;
				}
				else 
				{
					++point;
				}
			}
			else if (strcmp(str, "HOMERUN")==0) 
			{
				point += base + 1;
				base = 0;
			}

		}
		printf("%d\n", point);
	}
	return 0;
}


Measured memory_bytes: 596
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {

	var N int
	fmt.Scan(&N)
	if N%2 == 1 {
		fmt.Println("No")
		return
	}

	buff := make([]byte, N)
	reader := bufio.NewReader(os.Stdin)
	reader.Read(buff)

	s := string(buff)
	if s[:(N/2)] != s[(N/2):] {
		fmt.Println("No")
		return
	}
	fmt.Println("Yes")

}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<Int> a(n);
  for(Int i=0;i<n;i++) cin>>a[i];
  Int s=0;
  for(Int i=0;i<n;i++) s+=a[i];
  
  Int idx=-1,res=1e15;
  for(Int i=0;i<n;i++){
    Int tmp=abs(a[i]*n-s);
    if(tmp<res) idx=i,res=tmp;
  }
  cout<<idx<<endl;
  return 0;
}


Measured memory_bytes: 768
N = int(input())
H = list(map(int, input().split()))

DP = [0] * N
DP[0] = 0
DP[1] = abs(H[1] - H[0])
##
for i in range(2, N):
    DP[i] = min( DP[i-1] + abs(H[i]-H[i-1]), DP[i-2] + abs(H[i]-H[i-2]) )
##
print(DP[N-1])

Measured memory_bytes: 13928
#include <algorithm>
#include <array>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <stack>
#include <vector>

using namespace std;
using ll = long long;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define MOD ((ll)1000000007)


int main(int argc, char const *argv[])
{
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);

	int N, A, B;
	cin >> N >> A >> B;

	int count = 0;
	for (size_t i = 1; i <= N; i++)
	{
		int s = 0;
		for (auto &&c : to_string(i))
		{
			s += (int)(c - '0');
		}

		if (A <= s && s <= B)
		{
			count += i;
		}
	}
	cout << count << endl;
	return 0;
}


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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<double> vd;
typedef vector<vd> vdd;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define debug_print(x...) cerr << "line " << __LINE__ << " : "; debug_print_in(x);

template <typename First>
void debug_print_in(First first){
  cerr << first << endl;
  return;
}

template <typename First, typename... Rest>
void debug_print_in(First first, Rest... rest){
  cerr << first << " ";
  debug_print_in(rest...);
  return;
}

void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

template <typename First>
void OUT(First first){
  cout << first << endl;
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

template<class t, class u> void chmax(t&a,u b){if(a<b)a=b;};
template<class t, class u> void chmin(t&a,u b){if(a>b)a=b;};
int popcount(int t){return __builtin_popcount(t);} //GCC
int popcount(ll t){return __builtin_popcountll(t);} //GCC

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cerr << VEC[i] << " ";
  }
  cerr << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i,MAT.size()){
    REP(j,MAT[i].size()){
      cerr << MAT[i][j] << " ";
    }
    cerr << endl;
  }
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N;
  IN(N);
  string str;
  IN(str);

  vll R;
  vll W;
  REP(i,N){
    if(str[i]=='W'){
      W.pb(i);
    }
  }
  RREP(i,N-1){
    if(str[i]=='R'){
      R.pb(i);
    }
  }

  ll ans = 0;
  ll L = min(W.size(), R.size());
  REP(i,L){
    if(W[i]<R[i]){
      ans++;
    }
  }

  OUT(ans);

  return 0;
}


Measured memory_bytes: 5820
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#include <iomanip>
//cout << fixed << setprecision(20) << *** << endl;
#define rep(i,N) for(int i=0;i<(int)N;++i)
typedef long long ll;
using namespace std;
int main()
{
	ll N,A,B,C_A=0,C_B=0;
	string s;
	cin>>N>>A>>B>>s;
	rep(i,N){
		if(s[i]=='a'&&C_A+C_B<A+B){
			cout<<"Yes"<<endl;
			C_A++;
		}
		else if(s[i]=='b'&&C_A+C_B<A+B&&C_B<B){
			cout<<"Yes"<<endl;
			C_B++;
		}
		else{
			cout<<"No"<<endl;
		}
	}
}

Measured memory_bytes: 832
#coding: utf-8
n = int(input())
water = list(map(int,input().split()))

sum_water = sum(water)
r_1 = sum_water
for i in range(1,int((n-1)/2+1)):
    r_1 -= water[2*i-1]*2
    #print(water[2*i])

ans = [r_1]
for i in range(n-1):
    ans.append(water[i]*2-ans[-1])
    #print(ans)

print(" ".join(map(lambda x:str(int(x)),ans)))


Measured memory_bytes: 19144
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <numeric>

#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 100000000000000 //10^14
template <typename T>
bool chmax(T& a, const T& b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
template <typename T>
bool chmin(T& a, const T& b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

int op(int a, int b) {
	return max(a, b);
}

int e() {
	return -1;
}

int v;

bool f(int x) {
	return x < v;
}

int main()
{
    ll N, M;
    cin >> N >> M;
    scc_graph graph(N);
    rep(i, M) {
        ll a, b;
        cin >> a >> b;
        graph.add_edge(a, b);
    }
    vector<vector<int>> ans = graph.scc();
    cout << sz(ans) << endl;
    rep(i, sz(ans)) {
        cout << sz(ans.at(i)) << " ";
        rep(j, sz(ans.at(i)) - 1) {
            cout << ans.at(i).at(j) << " ";
        }
        cout << ans.at(i).at(sz(ans.at(i)) - 1) << endl;
    }
}

Measured memory_bytes: 40088
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define qwq(x) cerr<<" #"<<#x<<" = "<<x<<endl;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
 
template<class T> inline void read(T &x){
	int f=0;x=0;char ch=getchar();
	for(;!isdigit(ch);ch=getchar())f|=(ch=='-');
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	if(f)x=-x;
}

const int N=2000005;
ll A,B,C;

int main(){
	read(A),read(B),read(C);
	if(A%2==0||B%2==0||C%2==0){
		puts("0");
	}
	else{
		ll ans=2e18;
		ans=min(ans,A*B);
		ans=min(ans,B*C);
		ans=min(ans,C*A);
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
N, K, Q = map(int, input().split())
A = [int(input()) - 1  for i in range(Q)]

points = [K - Q for _ in range(N)]

for a in A:
    points[a] += 1

for point in points:
    if point > 0:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 11792