akhauriyash/Code-Regression huggingface dataset:
/* Author : Aaryan Srivastava ^__^ */ 
#include <bits/stdc++.h>
#include <random>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second   
#define rep(i,n) for(int (i) = 0 ; i < (n) ; i++)
#define repA(i,x,y) for(int i = (x) ; i <= (y) ; i++)
#define repD(i,x,y) for(int i = (x) ; i >= (y) ; i--)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).end()
#define setval(a,val) memset(a,val,sizeof(a))
#define Randomize mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define trav(x , a) for(auto &x : a)
#define sz(a) ((int)a.size())
typedef long long ll ; 

#define int ll

using namespace std;

const int N = 3e5 +5 ;
const int mod = 1e9 + 7 ;
const ll inf = 1e18 ;
const int SZ = 101 ;
const double eps = 1e-9 ;
using namespace __gnu_pbds;
using ordered_set =  tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ;

typedef pair<int, int> pii; 
typedef pair<int , pii> ipii ;
typedef pair<pii , int> piii ; 
typedef unsigned long long ull ;
typedef long double ld;

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

void solve()
{
    int n; cin >> n;
    int id[n] = {} ;
    rep(i , n - 1){
        int x;
        cin >> x;
        x--;
        id[x]++;
    }
    rep(i , n) cout << id[i] << '\n';
}   

     
int32_t main(int32_t argc, char *argv[])
{
    ios::sync_with_stdio(0);    
    cin.tie(0); cout.tie(0);
    int TC = 1, t = 0;
    //cin >> TC ;
    while(t++ < TC)
    {
        //cout << "Case #" << t << ": " ;
        solve();
        cout << "\n" ;
    }
    return 0;
}

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

#define N 2000

int main(){
    int n,x;
    unsigned long csec[N];


    unsigned long  mins[N]; //mins[i]:色iを手に入れるため、k回変色させる間に最小の捕獲秒数で捕獲する。a_i〜a_i-kの最小値。
    unsigned long tmp_total; //k回変色させる時に、必要な合計秒数
    unsigned long tmin; //合計秒数の最小値（ループ中に随時更新）

    cin >> n >> x;

    for(int i=0;i<n;i++){
	cin >> csec[i];
    }
    
    //変色回数０回の時
    tmp_total = 0;
    for (int i = 0; i < n; i++) {
	mins[i] = csec[i];
	tmp_total += csec[i];
	    //cout << mins[i] << "\n";
    }

    //変色回数０回の秒数
    tmin = tmp_total;

    //変色回数ループ（変色回数１回〜）
    for (int i = 1; i < n; i++) {
	//cout << "k:" << i << "\n";
	//対象色ループ
	tmp_total = 0;
	for (int j = 0; j < n; j++) {
	    //cout << "i:" << j << "\n";
	    //変色回数が(i-1)回の時の最小捕獲秒数と、i回変色させた時の捕獲秒数どちらかが
	    //cout << "(j-i)%n:" << ((j+n)-i)%n << "\n";
	    //cout << "last:" << mins[j] << "\n";
	    //cout << "csec:" << csec[((j+n)-i)%n] << "\n";
	    mins[j] = min( mins[j], csec[((j+n)-i)%n] );
	    tmp_total += mins[j];
	    //cout << mins[j] << "\n";
	}
	tmin = min( tmin, tmp_total+i*x);
    }

    cout << tmin << "\n";
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int N;
  scanf("%d",&N);

  long long a,max,min;
  for(int i = 0;i < N;i++){
    scanf("%lld",&a);
    if(i == 0){
      max = a;
      min = a;
    }
    if(max < a){
      max = a;
    }
    if(min > a){
      min = a;
    }
  }

  printf("%lld\n",max-min);

  return 0;
}

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

using namespace std;

struct List {
    int value;
    List* next;
    List* prev;
    List(int value, List* next = nullptr, List* prev = nullptr) :
        value(value), next(next), prev(prev) {}
};

void deleteFromList(List* elm, List** first, List** last) {
    if (elm->prev) { elm->prev->next = elm->next; }
    if (elm->next) { elm->next->prev = elm->prev; }
    if (elm == *first) {
        *first = (*first)->next;
    } else if (elm == *last) {
        *last = (*last)->prev;
    }
    delete elm;
}

void printList(List* first) {
    auto elm = first;
    while (elm) {
        if (elm != first) { cout << " "; }
        cout << elm->value;
        elm = elm->next;
    }
    cout << endl;
}

int main() {
    ios::sync_with_stdio(false);

    int n;
    cin >> n;

    List* first = nullptr;
    List* last = nullptr;

    string cmd;
    int value;
    for (int i=0; i<n; i++) {
        cin >> cmd;
        if (cmd == "insert") {
            cin >> value;
            auto newItem = new List(value, first);
            if (first) { first->prev = newItem; }
            first = newItem;
            if (not last) { last = newItem; }
        } else if (cmd == "delete") {
            cin >> value;
            auto elm = first;
            while (elm) {
                if (value == elm->value) {
                    deleteFromList(elm, &first, &last);
                    break;
                } else {
                    elm = elm->next;
                }
            }
        } else if (cmd == "deleteFirst") {
            deleteFromList(first, &first, &last);
        } else if (cmd == "deleteLast") {
            deleteFromList(last, &first, &last);
        }
    }
    printList(first);

    return 0;
}

Measured memory_bytes: 34448
N, K = [int(n) for n in input().split()]
A = [int(n) for n in input().split()]
o = {}
for k in A:
    c = o.setdefault(k, 0)
    o[k] = c + 1
w = len(o.keys()) - K
ans = sorted(o.values())
print(sum(ans[:w]) if w > 0 else 0)


Measured memory_bytes: 32264
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll n,k;
    cin>>n>>k;
    if (n%k==n)
      	cout<<min(n,k-n)<<'\n';
    else if(n%k==0)
      	puts("0");
    else
      	cout<<min(k-n%k,n%k)<<'\n';
    
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <map>
#include <stack>
using namespace std;
typedef long long int lli;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)
int main(void)
{
    int N;
    cin >> N;
    vector<int> a;
    int tmp;
    for (int i = 0; i < N; i++)
    {
        cin >> tmp;
        a.push_back(tmp);
    }
    int cnt = 0;
    int now = a[0];
    for (int i = 0; i < N; i++)
    {
        now = min(now, a[i]);
        if (now == a[i])
        {
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 4216
n = int(input())
a = list(map(int,input().split()))
q = int(input())
b = [0]*q
c = [0]*q
for i in range(q):
	b[i],c[i] = map(int,input().split())

s = 0
L = [0]*(10**5+1)
for A in a:
	L[A] += 1
	s += A

for i in range(q):
	s += L[b[i]]*(c[i]-b[i])
	L[c[i]] += L[b[i]]
	L[b[i]] = 0
	print(s)

Measured memory_bytes: 22040
#include<bits/stdc++.h>
static const int MAX = 1000000010;
using namespace std;
int A[500010],cnt;
void Merge(int A[],int left,int mid,int right){
	int n1 = mid - left;
	int n2 = right - mid;
	int L[n1],R[n2];
	for(int i=0;i<n1;i++){
		L[i] = A[left+i];
	}
	for(int i=0;i<n2;i++){
		R[i] = A[mid+i];
	}
	L[n1]=MAX;
	R[n2]=MAX;
	int i=0,j=0;
	for(int k=left;k<right;k++){
		if(L[i]<=R[j]){
			A[k] = L[i];
			i++;
			cnt++;
		}
		else{
			A[k] = R[j];
			j++;
			cnt++;
		}
	} 
}
void Merge_Sort(int A[],int left,int right){
	if(left+1<right){
		int mid = (left+right)/2;
		Merge_Sort(A,left,mid);
		Merge_Sort(A,mid,right);
		Merge(A,left,mid,right);
	}
}
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>A[i];
	}
	Merge_Sort(A,0,n);
	for(int i=0;i<n;i++){
		if(i<n-1)
			cout<<A[i]<<" ";
		else
			cout<<A[i]<<endl;
	}
	cout<<cnt<<endl;
	return 0;
} 


Measured memory_bytes: 6948
#include <iostream>
#include <vector>
#include <set>

using namespace std;

int main()
{
  int n, d, acc;
  vector<vector<int> > x;
  set<int> sq;

  for (int i = 0; i < 200; i++) {
    sq.insert(i*i);
  }

  cin >> n >> d;
  for (int i = 0; i < n; i++) {
    vector<int> v;
    for (int j = 0; j < d; j++) {
      int v1;
      cin >> v1;
      v.push_back(v1);
    }
    x.push_back(v);
  }

  acc = 0;
  for (int i = 0; i < n-1; i++) {
    for (int j = i+1; j < n; j++) {
      int dist_sq = 0;
      for (int k = 0; k < d; k++) {
        int diff;
        diff = x[i][k] - x[j][k];
        dist_sq += diff * diff;
      }
      if (sq.find(dist_sq) != sq.end()) {
        acc++;
      }
    }
  }

  cout << acc << endl;
  return 0;
}


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

int A[200010];
int ans[200010];

int main(void)
{
  int N;

  cin >> N;

  for (int i = 2; i <= N; i++)
  {
    if (scanf("%d", &A[i]) == -1)
    {
      return 1;
    }
  }

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

  for (int i = 1; i <= N; i++)
  {
    printf("%d\n", ans[i]);
  }

  return 0;
}

Measured memory_bytes: 5252
fun main(arg: Array<String>) {
    val A = listOfLong().sorted()
    val B = A.map { it % 2 != 0L }
    println(if (B.all { it }) A[0] * A[1] else 0)
}
fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfLong() = listOfString().map { it.toLong() }

Measured memory_bytes: 37988
#include<iostream>
using namespace std;
int main() {
 int a[5]={0};
  
  int b;
  int i=1;
  while (i<7) {
    cin >> b;
    a[b]=a[b]+1;
    
    i=i+1;
  }
  
  int max=0;
  i=1;
  while (i<5) {
    if (max<a[i]) max=a[i];
    i=i+1;
  }
  
  if (max<3) cout << "YES";
  else cout << "NO";
  cout << endl;
  
  
  
}


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

using i64 = long long;

const int MAXN = 1 << 18;
const int MOD = 1e9 + 7;
std::vector<int> g[MAXN];
int sz[MAXN];

i64 p2[MAXN];

void dfs(int u, int f = -1) {
    sz[u] = 1;
    for (auto& v : g[u]) {
        if (v != f) {
            dfs(v, u);
            sz[u] += sz[v];
        }
    }
}

i64 pow(i64 a, i64 n, i64 mod) {
    i64 t = 1;
    for (; n; n >>= 1, (a *= a) %= mod)
        if (n & 1) (t *= a) %= mod;
    return t;
}

int main() {
    p2[0] = 1;
    for (int i = 1; i < MAXN; i++) {
        p2[i] = p2[i - 1] * 2 % MOD;
    }
    int n;
    scanf("%d", &n);
    for (int i = 1, u, v; i < n; i++) {
        scanf("%d%d", &u, &v);
        --u, --v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    dfs(0);
    i64 ans = 0;
    for (int i = 0; i < n; i++) {
        ans += (p2[sz[i]] - 1) * (p2[n - sz[i]] - 1) % MOD;
        ans %= MOD;
    }
    ans = (ans - n * p2[n - 1] % MOD + p2[n] - 1 + MOD) % MOD;
    ans = ans * pow(p2[n], MOD - 2, MOD) % MOD;
    printf("%lld\n", ans);
}

Measured memory_bytes: 22400
#ABC141_C
N,K,Q=map(int,input().split())
ans=[K-Q]*N
for _ in range(Q):
    idx=int(input())
    ans[idx-1]+=1
for i in range(len(ans)):
    if ans[i]>0:
        print('Yes')
    else:
        print('No')  

Measured memory_bytes: 6596
#include <iostream>

int main(int argc, char **argv) {
    int a;
    std::cin >> a;

    if((a % 2) == 0){
        std::cout << 0.5 << std::endl;
    }
    else{
        std::cout << (a+1)/(2.0*a) << std::endl;
    }

}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a, b, c;
  cin >> a >>b>>c;
  int m=max(a, b);
  m=max(m,c);
  if(m==a) cout << b+c << endl;
  else if(m==b) cout << a+c << endl;
  else cout << a+b << endl;
  return 0;
}

Measured memory_bytes: 256
#!/usr/bin/python
# -*- coding: UTF-8 -*-

import sys


def input():
    return sys.stdin.readline().strip()


def _main():
    n, k = input().split()
    x = set(input())

    n_s = set(n)

    n_i = int(n)
    while True:
        if x & n_s:
            n_i += 1
            n_s = set(str(n_i))
        else:
            print(n_i)
            break


if __name__ == "__main__":
    _main()


Measured memory_bytes: 9108
lines = STDIN.read.split("\n")
n = lines.shift.to_i
score = Array.new(2, 0)
n.times.each do |i|
  s1, s2 = lines[i].split(" ")
  if s1 > s2
    score[0] += 3
  elsif s1 < s2
    score[1] += 3
  else
    score[0] += 1
    score[1] += 1
  end
end
puts score.join(" ")

Measured memory_bytes: 8752
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    string str1,str2,str3="ooo";
    cin >> str1 >> str2;
    str3.at(0) = str2.at(2);
    str3.at(1) = str2.at(1);
    str3.at(2) = str2.at(0);
    if(str1==str3){
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
}

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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  if(A==B){
    cout << C << endl;
  }
  else if(B==C){
    cout << A << endl;
  }
  else{
    cout << B << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int>P;

int a[400000];
ll fact[400000];

ll ppow(ll a) {
	ll b = MOD - 2;
	ll res = 1;
	while (b) {
		if (b & 1)res = (res*a) % MOD;
		a = (a*a) % MOD;
		b >>= 1;
	}
	return res;
}
ll C(ll a, ll b) {
	return (fact[a] * ppow((fact[b] * fact[a - b]) % MOD)) % MOD;
}
bool used[400000];
signed main() {
	int n; scanf("%d", &n);
	int b = 0;
	rep(i, n + 1) {
		scanf("%d", &a[i]);
		if (used[a[i]])b = a[i];
		used[a[i]] = 1;
	}
	fact[0] = 1; for (int i = 1; i <= n + 1; i++)fact[i] = (fact[i - 1] * i) % MOD;
	int s = -1, g;
	rep(i, n + 1) {
		if (a[i] == b) {
			if (s == -1)s = i;
			else g = i;
		}
	}
	for (int i = 1; i <= n + 1; i++) {
		printf("%lld\n", (C(n + 1, i) + MOD - (s + n - g >= i - 1 ? C(s + n - g, i - 1) : 0)) % MOD);
	}
}

Measured memory_bytes: 4096
#include <iostream>
#include <vector>

using namespace std;

class DisjointSet
{
public:
  vector<int> rank, p;

  DisjointSet() {}
  DisjointSet(int size)
  {
    rank.resize(size, 0);
    p.resize(size, 0);
    for (int i = 0; i < size; i++)
    {
      makeSet(i);
    }
  }

  void makeSet(int x)
  {
    p[x] = x;
    rank[x] = 0;
  }
  bool same(int x, int y)
  {
    return findSet(x) == findSet(y);
  }

  void unite(int x, int y)
  {
    link(findSet(x), findSet(y));
  }

  void link(int x, int y)
  {
    if (rank[x] > rank[y])
    {
      p[y] = x;
    }
    else
    {
      p[x] = y;
      if (rank[x] == rank[y])
      {
        rank[y]++;
      }
    }
  }

  int findSet(int x)
  {
    if (x != p[x])
    {
      p[x] = findSet(p[x]);
    }
    return p[x];
  }
};

int main()
{
  int n, q;
  int com, x, y;

  cin >> n >> q;
  DisjointSet ds = DisjointSet(n);

  for (int i = 0; i < q; i++)
  {
    cin >> com >> x >> y;
    if (com == 0)
    {
      ds.unite(x, y);
    }
    else if (com == 1)
    {
      if (ds.same(x, y))
      {
        cout << 1 << endl;
      }
      else
      {
        cout << 0 << endl;
      }
    }
  }

  return 0;
}


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

template <typename T>
class SegmentTree {
	using func_t = function<T(T, T)>;
	const int n;
	const T id;
	func_t merge;
	vector<T> data;
	int size(int n) {
		int res;
		for (res = 1; res < n; res <<= 1);
		return res;
	}
	T sub(int l, int r, int node, int lb, int ub) {
		if (ub <= l || r <= lb) return id;
		if (l <= lb && ub <= r) return data[node];
		return merge(sub(l, r, node * 2, lb, (lb + ub) / 2), sub(l, r, node * 2 + 1, (lb + ub) / 2, ub));
	}
public:
	SegmentTree(int n_, T id_, func_t merge_) :
		n(size(n_)), id(id_), merge(merge_), data(size(n_) * 2, id_) {}
	void Update(int p, T val) {
		p += n;
		data[p] = val;
		while (p >>= 1) data[p] = merge(data[p * 2], data[p * 2 + 1]);
	}
	void Add(int p, T val) {
		p += n;
		data[p] += val;
		while (p >>= 1) data[p] = merge(data[p * 2], data[p * 2 + 1]);
	}
	T Find(int i) {
		return data[i + n];
	}
	T Find(int l, int r) {
		return sub(l, r + 1, 1, 0, n);
	}
};

int main()
{
	cin.sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> x(n), xs(1);
	for (int i = 0; i < n; i++) {
		cin >> x[i];
	}
	xs.reserve(n * 32);
	for (int i = 0; i < n; i++) {
		for (int j = max(1, x[i] - 32); j <= x[i] + 1; j++) {
			xs.push_back(j);
		}
	}
	sort(xs.begin(), xs.end());
	xs.erase(unique(xs.begin(), xs.end()), xs.end());
	SegmentTree<int> st((int)xs.size(), 0, [](int l, int r) { return l + r; });
	for (int i = 0; i < n; i++) {
		int id = lower_bound(xs.begin(), xs.end(), x[i]) - xs.begin();
		if (id != x[i]) {
			puts("Yes");
			st.Add(id, 1);
		}
		else if (st.Find(0) == 0 && (st.Find(id) == 0 || st.Find(1, id) < id || st.Find(id + 1, (int)xs.size() - 1) == 0)) {
			puts("Yes");
			while (st.Find(id)) {
				st.Update(id, 0);
				id--;
			}
			st.Add(id, 1);
		}
		else {
			puts("No");
		}
	}
	return 0;
}

Measured memory_bytes: 129852
import java.util.*;

public class Main{
    
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        
        String A = sc.next();
        sc.close();

        long N = A.length();
        long[] cnt = new long[26];
        long count = N*(N-1)/2;
        for(int i = 0; i < N; i++){
            cnt[(int)(A.charAt(i)-'a')]++;
        }
        for(int i = 0; i < 26; i++){
            count -= cnt[i]*(cnt[i]-1)/2;
        }
        System.out.println(count+1);
    }
}

Measured memory_bytes: 28368
#include <bits/stdc++.h>
  
using namespace std;
  
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
  
#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
  
#define ordered_set tree<int , null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> 
  
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
  
const int inf = int(1e9);
const int mod = inf + 7;
const int N = 1e6 + 555; // TL MB
const double PI = acos(-1.0);
 
void mul(ll &x, ll y){
	x *= y;
	if(x >= mod) x %= mod;
}
 
void add(ll &x, ll y){
	x += y;
	if(x >= mod) x -= mod;
	if(x < 0) x += mod;
}
ll bp(ll a, ll n){
	ll r = 1;
	while(n){
		if(n & 1) mul(r, a);
		mul(a, a);
		n >>= 1;
	}
	return r;
}

int a[N], dp[N];
int n, m;

void solve()
{
	cin >> n >> m;
	for(int i = 0; i < m; ++i){
		int x;
		cin >> x;
		a[x] = 1;
	}	
	dp[0] = 1;
	dp[1] = !a[1];
	for(int i = 2; i <= n; ++i){
		if(!a[i]){
			dp[i] = dp[i - 1] + dp[i - 2];
			dp[i] %= mod;
		}
	}
	cout << dp[n];
}


 
 
int main()
{
    Red;
  	// int T; cin >> T; while(T--)
    solve();
    return 0;
}

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

using namespace std;
using namespace std;
#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

const ll inf = 1e9+7;
const ll mod = 1e9+7;

int main(){
    ll n,c,k;
    cin>>n>>c>>k;

    vector<ll>t(n);
    rep(i,n)cin>>t[i];

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

    ll now=1,cnt=1,time=t[0];

    rep(i,n-1){
        if(t[i+1]-time>k||cnt>=c){
            now++;
            cnt=0;
            time=t[i+1];
        }
        cnt++;
    }
    cout<<now<<endl;

}


Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define FOR(i, first, last) for (int i = (first); i < (last); ++i)
#define REP(i, n) FOR(i, 0, n)
#define CLR(a) memset((a), 0, sizeof(a))
#define DUMP(x) std::cerr << #x << " = " << (x) << std::endl;
#define DUMPR(v) REP(_i,v.size()){std::cerr<< #v << "[" << _i << "] = " << (v[_i]) << std::endl;}
#define CIN_VEC(v,N) {v.clear(); v.reserve(N); REP(i,N){typename decltype(v)::value_type x; cin>>x; v.emplace_back(x);}};

inline int to_int(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string to_string(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

typedef unsigned long long ull;
typedef unsigned long ul;

static const int NMAX = 100000;
int h[NMAX];
int N;
int dp[NMAX];
const static int INF = 1e9;

int main() {
  cin>>N;
  REP(i,N) cin >> h[i];
  REP(i,N) dp[i] = INF;
  dp[0] = 0;
  dp[1] = abs(h[1]-h[0]);

  FOR(i,2,N) {
    dp[i] = min(dp[i], dp[i-1] + abs(h[i]-h[i-1]));
    dp[i] = min(dp[i], dp[i-2] + abs(h[i]-h[i-2]));
  }
  // REP(i,N) DUMP(dp[i]);
  cout<<dp[N-1]<<endl;

  return 0;
}


Measured memory_bytes: 1024
#coding: utf-8
#ALDS1_2B

def pnt(s):
 for i in xrange(len(s)):
  print s[i],
 print

n=int(raw_input())
a=map(int,raw_input().split())

cnt=0
for i in xrange(n):
 mini = i
 for j in xrange(i + 1, n):
  if a[j] < a[mini]:
   mini = j
 if i != mini:
  a[i], a[mini] = a[mini], a[i]
 if i!=mini:
  cnt+=1
pnt(a)
print cnt

Measured memory_bytes: 6440
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define Clear(a) a = decltype(a)()
#define all(a) a.begin(),a.end()
#define vec vector
typedef long long ll;
typedef pair<ll,ll> P;
//const ll big=998244353;
const ll big=1000000007LL;
const ll INF=1e18;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
if(x<y)return x;
else return y;
}
ll expm(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (expm(x,y-1)*x)%big;
    ll t=expm(x,y/2);
    return (t*t)%big;
}
ll exp(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||y==0)return x;
    if(y%2==1)return exp(x,y-1)*x;
    ll t=exp(x,y/2);
    return t*t;
}
ll inv(ll x){
    return expm(x,big-2);
}


int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    /*--------------------------------*/

    int n;cin >> n;
    vec<ll> l(n);
    rep(i,n)cin >> l[i] ;
    ll ans=0;
    rep(i,n-2)rep2(j,i+1,n-1)rep2(k,j+1,n){
        if(l[i]==l[j]||l[j]==l[k]||l[k]==l[i])continue;
        if(max({l[i],l[j],l[k]})*2<l[i]+l[j]+l[k])ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define p (int)(1e9 + 7)

int MOD(int a){
	return (a %= p) >= 0 ? a : a + p;
}

signed main(){
	int i, j, k;
	string S;
	cin >> S;
	int N = S.size();
	vector<vector<int>> dp(N + 1, vector<int>(13, 0));
	dp[0][0] = 1;
	for(i = 0; i < N; i++){
		for(j = 0; j < 13; j++){
			for(k = 0; k < 10; k++){
				if(S[i] == '?' || (int)(S[i] - '0') == k){
					dp[i + 1][(10 * j + k) % 13] = MOD(dp[i + 1][(10 * j + k) % 13] + dp[i][j]);
				}
			}
		}
	}
	printf("%lld\n", dp[N][5]);
	return 0;
}

Measured memory_bytes: 15616
#define _USE_MATH_DEFINES // for C++  
#include <cmath> 
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <array>
#include <iterator>
#include <utility>
#include <set>
#include <random>
#include <map>
#include <stack>
#include <queue>
#include <list>
#include <functional>
#define LL long long


using namespace std;

int main() {
    int a, b, c;
    vector<int> v;
    bool flag = false;
    cin >> a >> b >> c;
    for (size_t i = 1;; i++)
    {
        int num = a * i;
        int ama = num % b;
        if (find(v.begin(), v.end(), ama) == v.end())
        {
            v.emplace_back(ama);
        }
        else
        {
            break;
        }
        if (ama == c)
        {
            flag = true;
            break;
        }
    }
    if (flag)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
    return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> t(n+1, 0), x(n+1, 0), y(n+1, 0);
    for(int i=1; i<=n; i++){
        cin >> t[i] >> x[i] >> y[i];
    }
    bool success = true;
    for(int i=0; i<n; i++){
        int dist = abs(x[i+1]-x[i]) +abs(y[i+1]-y[i]);
        int time = t[i+1] -t[i];
        if(time < dist || time%2 != dist%2){
            success = false;
            break;
        }
    }
    if(success){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


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

mod = 10**9 + 7
ans = 0
A_sum = [0]

for i in range(N):
    A_sum.append(A_sum[-1] + A[i])

for i in range(N-1):
    ans += A[i] * (A_sum[N] - A_sum[i+1])
    ans %= mod

print(ans)

Measured memory_bytes: 31552
#include <iostream>
#include <vector>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<map>
#include<math.h>
#include<queue>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int MOD = 1000000007;
const int mod = 1000000007;
const int INF = 1000000000;
const long long LINF = 1e18;
const int MAX = 510000;

int main(){
	string s;
	int ci;
	bool f = 0;
	cin >> s;
	if (s[0] != 'A') {
		cout << "WA" << endl;
		return 0;
	}
	for (int i = 2; i < s.size()-1; i++) {
		if (s[i] == 'C') {
			ci = i;
			f = 1;
			break;
		}
	}
	if (f == 0) {
		cout << "WA" << endl;
		return 0;
	}
	for (int i = 1; i < s.size(); i++) {
		if (i != ci && 'z' - s[i] > 31)f = 0;
	}
	if (f == 0)cout << "WA" << endl;
	else {
		cout << "AC" << endl;
	}
	//cout <<'z'-'Z'  << endl;;

	return 0;
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())
#define rsort(v) sort(all(v)); reverse(all(v))

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template<typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template<typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template<typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template<typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template<typename T> inline T power(T x, i64 n) { T r = 1; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template<typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }

bool dp[5001];

void solve() {
  i64 N, K; cin >> N >> K;
  vi64 A(N); cin >> A;
  sort(all(A));
  int ok = N, ng = -1;
  while (ok - ng > 1) {
    int i = (ng + ok) / 2;
    if (K <= A[i]) { ok = i; continue; }
    rep(k, K) dp[k] = false;
    dp[0] = true;
    rep(j, N) {
      if (i == j) continue;
      rrep(k, K) {
        if (dp[k]) {
          if (k + A[j] < K) dp[k + A[j]] = true;
        }
      }
    }
    bool f = false;
    for (int j = K - A[i]; j < K; j++) if (dp[j]) f = true;
    if (f) ok = i; else ng = i;
  }
  cout << ok << '\n';
}


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

int main(void) {
  int N, M;
  cin >> N;
  M = N;
  int sum = 0;
  while (M) {
    sum += M % 10;
    M /= 10;
  }
  if (N % sum == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3636
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<(int)(n);i++)
#define N 200000

int main() {
	int x, y, z;
	int a, b, c;
	int s, ans;
	scanf("%d %d", &x, &y);
	ans = 0;
	for (int i = 1; i <= x; i++) {
		for (int j = 1; j <= y; j++) {
			a = j % 10;
			b = j / 10;
			if (a >= 2) {
				if (b >= 2) {
					c = a * b;
					if (c == i)ans++;
				}
			}
		}
	}
	printf("%d\n", ans);


	return 0;
}

Measured memory_bytes: 128
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use text_io::*;

fn main() {
    let a: isize = read!();
    let v: isize = read!();
    let b: isize = read!();
    let w: isize = read!();
    let t: isize = read!();

    let ans = if (a - b).abs() as isize <= (v - w) * t {
        "YES"
    } else {
        "NO"
    };

    println!("{}", ans);
}


Measured memory_bytes: 2116
# include <bits/stdc++.h>
# define maxn 200005
# define ll long long
# define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
# define rc(s) return cout << s,0
# define _ ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
# define pb push_back
# define mp make_pair
//# define int ll
using namespace std;

int32_t main(){_
	//freopen("input","r",stdin);
	int l;
	int r;
	string s;
	cin >> s;
	l = r = s.size() + 1;
	for(int i = 0;i<s.size();i++)
	{
        if(s[i] == 'A') l = min(l,i);
        if(s[i] == 'Z') r = i;
	}
	rc(r - l + 1);
}


Measured memory_bytes: 720
#include<cstdio>
#include<algorithm>
using namespace std;
char a[10100],b[10100];
int lenth;
int main(){
	scanf("%d",&lenth);
	scanf("%s",a);
	scanf("%s",b);
	for(int i=0;i<lenth;i++){
		printf("%c",a[i]);
		printf("%c",b[i]);
	}
	return 0;
}

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

int n,k,a[100100];

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

int main(){
	cin>>n>>k;
	cin>>a[1];
	int g=a[1],m=a[1];
	for (int i=2;i<=n;i++){
		cin>>a[i];
		g=gcd(max(g,a[i]),min(g,a[i]));
		m=max(m,a[i]);
	}
	if (k<=m && k%g==0) cout<<"POSSIBLE"<<endl;
	else cout<<"IMPOSSIBLE"<<endl;
	return 0;
}

Measured memory_bytes: 640
#include<stdio.h>

int main(){
  int i,n,y;;
  scanf("%d %d",&n,&y);
  int j,tmp;
  int flag=0;
  int mai1,mai2,mai3;

  for(i=0;i<n+1;i++){
    for(j=0;j<n+1-i;j++){
      tmp=10000*i+5000*j+1000*(n-i-j);
      if(tmp==y){
        flag=1;
        mai1=i;
        mai2=j;
        mai3=n-i-j;
        break;
      }
    }
  }

  if(flag==1){
    printf("%d %d %d\n",mai1,mai2,mai3);
  }else{
    printf("-1 -1 -1\n");
  }
  return 0;
}


Measured memory_bytes: 128
x = int(input())
beki_li = []
for i in range(2, 1001):
    for j in range(2, 10):
        if i ** j < 1001 and i**j <= x:
            beki_li.append(i**j)
        else:
            break
beki_li.append(1)
print(max(beki_li))


Measured memory_bytes: 38256
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
int main()
{
	ll n, a, b;
	scanf("%lld%lld%lld", &n, &a, &b);
	if (a > b)printf("0\n");
	else if (n == 1)
	{
		if (a == b)printf("1\n");
		else printf("0\n");
	}
	else
	{
		printf("%lld\n", (b - a)*(n - 2) + 1);
	}
}

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vll = vector<ll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
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; }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	for (auto &u : v) os << u << endl;
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u;
	return (is);
}

int main() {
	ll N, M; cin >> N >> M;
	vll A(N); cin >> A;
	vll imos(M + 1, 0);
	ll sum = 0;
	for (auto &v : A) v--;	
	for (int i = 0; i < N - 1; i++) {
		int c1 = A[i+1]+1;
		int c2 = (M+A[i+1]-A[i])%M;	
		if (c1 < c2) sum += c1;
		else sum += c2;
		
		if (A[i] < A[i + 1]) {
			imos[A[i] + 1]--;
			imos[A[i+1] + 1]++;
		} else {
			imos[A[i] + 1]--;
			imos[M]++;
			imos[0]--;
			imos[A[i+1] + 1]++;
		}
		imos[A[i+1]] += (M + A[i+1] - A[i]) % M;
		imos[A[i+1]+1] -= (M + A[i+1] - A[i]) % M;
	}
	ll minv = sum;
	for (int i = 0; i < M; i++) {
		if (i) imos[i] += imos[i-1];
		sum += imos[i];
		minv = min(minv, sum);
	}
	cout << minv << endl;
	return (0);
}


Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Console;

namespace AtCoder_1
{
    class Program
    {
        static void Main(string[] args)
        {
            var a = CinTAr();
            double one = a[1] * 2 + 1;
            Cout(Math.Ceiling(a[0] / one));
            Cin();
        }
        
        static readonly int MOD1E9 = (int)1e9 + 7;
        static string Cin() { return ReadLine(); }
        static string[] CinAr() { return ReadLine().Split(' '); }
        static int CinT() { return S2i(Cin()); }
        static int[] CinTAr() { return CinAr().Select((x, i) => { return S2i(x); }).ToArray(); }
        static long CinL() { return S2L(Cin()); }
        static long[] CinLAr() { return CinAr().Select((x, i) => { return S2L(x); }).ToArray(); }
        static double CinD() { return S2D(Cin()); }
        static double[] CinDAr() { return CinAr().Select((x, i) => { return S2D(x); }).ToArray(); }
        static int S2i(string s) { return int.Parse(s); }
        static long S2L(string s) { return long.Parse(s); }
        static double S2D(string s) { return double.Parse(s); }
        static void OYes() { Cout("Yes"); }
        static void ONo() { Cout("No"); }
        static void Cout(object s) { WriteLine(s); }
        /// <summary>
        /// Debug時のみの使用を推奨
        /// </summary>
        /// <typeparam name="Type"></typeparam>
        /// <param name="types"></param>
        static void CoutAr<Type>(IEnumerable<Type> types)
        {
            string text = "";
            foreach (var i in types)
            {
                text += " " + i;
            }
            WriteLine(text.Substring(1));
        }
    }
}


Measured memory_bytes: 13396
abcd = list(input())
a = int(abcd[0])
b = int(abcd[1])
c = int(abcd[2])
d = int(abcd[3])
if a+b+c+d == 7:
    print('{}+{}+{}+{}=7'.format(a,b,c,d))
elif a+b+c-d == 7:
    print('{}+{}+{}-{}=7'.format(a,b,c,d))
elif a+b-c+d == 7:
    print('{}+{}-{}+{}=7'.format(a,b,c,d))
elif a+b-c-d == 7:
    print('{}+{}-{}-{}=7'.format(a,b,c,d))
elif a-b+c+d == 7:
    print('{}-{}+{}+{}=7'.format(a,b,c,d))
elif a-b+c-d == 7:
    print('{}-{}+{}-{}=7'.format(a,b,c,d))
elif a-b-c+d == 7:
    print('{}-{}-{}+{}=7'.format(a,b,c,d))
elif a-b-c-d == 7:
    print('{}-{}-{}-{}=7'.format(a,b,c,d))

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <deque>
#include <math.h>
#include <set>
#include <iomanip>
#include <time.h>
#include <list>
#include <stdio.h>
#include <queue>
#include <map>
#include <algorithm>
#include <assert.h>
#include <memory.h>

#define mk make_pair
#define sc second
#define fr first
#define pb emplace_back
#define all(s) s.begin(), s.end()
#define sz(s) ( (int)s.size() )
#define int long long

using namespace std;

const int N = 5005;

int n, dp[N][N];

pair <int,int> ar[N];

bool cmp (pair <int ,int> a, pair <int ,int> b)
{
    return a.fr + a.sc < b.fr + b.sc;
}

main ()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
        scanf("%d%d", &ar[i].fr, &ar[i].sc);

    sort(ar + 1, ar + n + 1, cmp);

    memset(dp, 0x3f3f3f3f, sizeof(dp));

    dp[0][0] = 0;

    for (int i = 1; i <= n; i++)
    {
        dp[i][0] = 0;
        for (int j = 1; j <= n; j++)
        {
            dp[i][j] = dp[i - 1][j];

            if (dp[i - 1][j - 1] <= ar[i].fr)
                dp[i][j] = min( dp[i][j], dp[i - 1][j - 1] + ar[i].sc );
        }
    }
    int ans;

    for (int i = n; i >= 1; i--)
        if ( dp[n][i] != dp[N - 1][N - 1] )
        {
            ans = i;
            break;
        }
    cout << ans;
}


Measured memory_bytes: 195968
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
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; }
// template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

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

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s, t; cin >> s >> t;
    int ans = 0;
    rep (i, s.size()) if (s[i] != t[i]) ans++;
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3836
def is_good(mid, key):
    res = 0
    for a in A:
        res += (a + mid - 1) // mid
    return res - N <= key


def binary_search(bad, good, key):
    while good - bad > 1:
        mid = (bad + good) // 2
        if is_good(mid, key):
            good = mid
        else:
            bad = mid
    return good


N, K, *A = map(int, open(0).read().split())
print(binary_search(0, 1_000_000_000, K))


Measured memory_bytes: 31528
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();
		int k = sc.nextInt();

			if(a <b) {
				if(b<c) {
					K(c,a,b,k);
				}else {
					K(b,a,c,k);
				}
			}else {
				if(c<a) {
					K(a,b,c,k);
				}else {
					K(c,a,b,k);
				}
			}
	}
	public static void K(int x,int y,int z,int k) {
		for(int j = 0; j<k ;j++) {
			x +=x;
		}
		System.out.println(x+y+z);
	}
}


Measured memory_bytes: 20948
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;
unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

ll ll_gcd(ll a, ll b) {
    if (a < b) return ll_gcd(b, a);
    ll r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

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

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

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main() {
    ll n;
    cin >> n;
    ll k = n;
    ll b = 0;
    vector<ll>ans;
    while (k > 0) {
        b++;
        k /= 10;
    }
    for (int d = 1; d < b + 1; d++) {
        for (int i = 0; i < modpow(3, d, 1000000007); i++) {
            ll t = i;
            ll zans = 0;
            for (int j = 0; j < d; j++) {
                zans += modpow(10, j, 1000000007) * ((t % 3) * 2 + 3);
                t /= 3;
            }
            if (zans <= n)ans.push_back(zans);
        }
    }
    ll anss = 0;
    for (int i = 0; i < ans.size(); i++) {
        ll x = 0;
        ll c = 0;
        ll v = 0;
        while (ans[i] > 0) {
            if (ans[i] % 10 == 3)x++;
            if (ans[i] % 10 == 5)c++;
            if (ans[i] % 10 == 7)v++;
            ans[i] /= 10;
        }
        if (x * c * v > 0)anss++;
    }
    cout << anss << endl;
}

Measured memory_bytes: 3676
#include <iostream>
using namespace std;
int n;
string s;
int cnt=1;
int main(){
	cin>>n>>s;
	
	for(int i=1;i<n;i++)
	{
		if(s[i]==s[i-1])
			continue;
		cnt++;
	}
	
	cout<<cnt;
	return 0;
}


Measured memory_bytes: 3764
h, w, k = list(map(int, input().split()))

choco = [list(map(int, list(input()) )) for i in range(h)]

ans = h + w + 1

for h_cut in range(2**(h-1)):
    # 上位ビットが上側。1が切る、0が切らない
    num_cut_yoko = bin(h_cut).count("1") # 立っているビットの個数
    num_cut = num_cut_yoko
    w_last_cut_pos = -1
    valid = True

    count_white = [0] * (num_cut_yoko + 1)
    temp_dict = {}
    idx = 0
    temp_dict[0] = idx
    for i in range(1, h):
        # print('idx', 2 ** (-i+h-1) )
        if h_cut & (2 ** (-i+h-1) ):
            idx += 1
        # idx += h_cut & (2 ** (h-1) - i)
        temp_dict[i] = idx
    # print(temp_dict)

    iw = 0
    while iw < w:

        for ih in range(h):
            count_white[temp_dict[ih]] += choco[ih][iw]
        # print(iw, count_white)

        condition = max(count_white) > k
        if condition:
            if w_last_cut_pos < iw-1:
                # もしそこで切ってkを超えるなら、その手前で切る
                num_cut += 1
                w_last_cut_pos = iw - 1
                count_white = [0] * (num_cut_yoko + 1)
                # print('iw: ', iw, 'last: ', w_last_cut_pos)

            else:
                # 1つしか動かしてないのにk個を超えた場合は、この横方向の切り方で達成不可能なので、次のh_cutに進む
                # このとき切断回数の最小値の更新をしないように注意!
                valid = False
                break
        
        else:
            iw += 1
    
    if valid:
        ans = min(ans, num_cut)
    # print(num_cut)

print(ans)


Measured memory_bytes: 9296
H,W = map(int,input().split())
a = []
for i in range(H):
    x = list(input())
    if '#' in x:
        a.append(x)
def trans(a):
    x = [i for i in zip(*a)]
    return x
at = trans(a)
an = []
for i in at:
    if '#' in i:
        an.append(i)
ans = trans(an)
for i in ans:
    print(*i,sep = '')

Measured memory_bytes: 4724
#include<iostream>
#include<vector>
#include<map>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<set>
#include<bitset>
#include<iomanip>
#define BUG puts("no bug")
#define sci(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define ll long long
#define ull unsigned long long
#define REP(a,b,c) for(ll a=b;a<=c;a++)
#define PER(a,b,c) for(ll a=b;a>=c;a--)
#define lb(a) (a&(-a))
#define pp (p<<1)
#define ppp (p<<1|1)
#define pi pair<ll,ll>
#define pii pair<pair<ll,ll>,ll>
using namespace std;
const ll MAXN=1e6+5;
ll n,m,t;
ll v[MAXN];
char s[MAXN];
int main(){
    ll a,b;
    cin>>n>>a>>b;
    ll tmp=n/(a+b);
    n-=tmp*(a+b);
    ll ans=0;
    ans=tmp*a;
    ans+=min(n,a);
    cout<<ans;
}

Measured memory_bytes: 256
unittest
{
	assert( [ "3 1", "1 2 1" ].parse.expand.solve == 2 );
	assert( [ "6 5", "1 2 1", "2 3 2", "1 3 3", "4 5 4", "5 6 5" ].parse.expand.solve == 2 );
	assert( [ "100000 1", "1 100000 100" ].parse.expand.solve == 99999 );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nm = input.front.split.to!( long[] );
	auto xyzs = new long[ 3 ][ nm[ 1 ] ];
	foreach( ref xyz; xyzs )
	{
		input.popFront;
		xyz = input.front.split.to!( long[] );
		xyz[ 0 .. 2 ] -= 1;
	}
	return tuple( nm[ 0 ], xyzs );
}

auto solve( long n, long[ 3 ][] xyzs )
{
	auto utf = UnionFind( n );
	foreach( xyz; xyzs )
	{
		utf.unite( xyz[ 0 ], xyz[ 1 ] );
	}
	return utf.rootnum;
}

struct UnionFind
{
	private long   num;
	private long[] ps;
	
	public this( long n )
	{
		num = n;
		ps = new long[]( n );
		ps[] = -1;
	}
	
	public long root( long x )
	{
		return ( ps[ x ] < 0 ) ? x : ( ps[ x ] = root( ps[ x ] ) );
	}
	
	public bool same( long x, long y )
	{
		return root( x ) == root( y );
	}
	
	public void unite( long x, long y )
	{
		x = root( x );
		y = root( y );
		if( x == y ) return;
		if( ps[ x ] < ps[ y ] ){ ps[ x ] += ps[ y ]; ps[ y ] = x; }
		else                   { ps[ y ] += ps[ x ]; ps[ x ] = y; }
		num--;
	}
	
	public long rootnum()
	{
		return num;
	}
}


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


using namespace std;

double a, b;

int main(){
	cin >> a >> b;	
	for(double x = 1 ;x <= 1000000 ; x+=1){
		if( a == floor(x*0.08) && b == floor(x*0.1) ){
			cout << x << '\n';
			return 0;
		}
	}
	cout << -1 << '\n';
	// a = floor(x * 0.08);
	// b = floor(x * 0.1);
}


Measured memory_bytes: 256
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
d = list(map(int, input().split()))
from itertools import product
if n>=13:
    from collections import Counter
    d.append(0)
    c = Counter(d)
    for i in range(13):
        c.setdefault(0)
    if c[0]<=1 and (c[12]<=1) and all([c[v]<=2 for v in range(1,12)]):
        ans = 1
    else:
        ans = 0
else:
    ans = 0
    for ind in product(*[range(2) for _ in range(n)]):
        vals = []
        for i in range(n):
            if ind[i]:
                vals.append(d[i])
            else:
                vals.append((24-d[i])%24)
        vals.append(0)
        res = 50
        for i in range(len(vals)):
            for j in range(i+1,len(vals)):
#                 print(i,j)
                v = abs(vals[i]-vals[j])
                res = min(res, min(v, 24-v))
        ans = max(ans, res)
print(ans)

Measured memory_bytes: 74016