akhauriyash/Code-Regression huggingface dataset:
#pragma warning(disable:4996)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <float.h>

#pragma region 定義
typedef long long  ll;
typedef unsigned long long  ull;


#define _itoa(A,N) sprintf(A, "%d", N);

int i_dsort(const void* a, const void* b);
int i_asort(const void* a, const void* b);

int  _gcd(int a, int b);
int  _swp(int* a, int* b);
int _cknum(char* a, int n);
int _atoi(char* s, int len);

int s_asort(const void* a, const void* b);
int s_dsort(const void* a, const void* b);

//昇順
int s_asort(const void* a, const void* b) {
	return(strcmp((char*)a, (char*)b));
}
int s_dsort(const void* a, const void* b) {
	return(strcmp((char*)b, (char*)a));
}

int i_dsort(const void* a, const void* b) {
	return(*(int*)b - *(int*)a);
}
int i_asort(const void* a, const void* b) {
	return(*(int*)a - *(int*)b);
}

int _gcd(int a, int b) {
	int r, tmp;
	if (a < b) { tmp = a; a = b; b = tmp; }
	r = a % b;
	while (r) {
		if (!r) break;
		a = b; b = r;
		r = a % b;
	}
	return(b);
}
// puts("Yes\n") puts("No\n")
// scanf("%d.%d") 浮動小数点入力を整数２つで得る


//#define pai  3.1415926535 
//#define  _USE_MATH_DEFINES でM_PIが使える

#define deg_rad(X)  (X*(M_PI/180))


int _swp(int* a, int* b)
{
	int tmp;
	tmp = *b; *b = *a; *a = tmp;
	return 0;
}
#define _abs(x) ((x)>0?(x):-(x))
#define _min(x,y) ((x)<(y)?(x):(y))
#define _max(x,y) ((x)<(y)?(y):(x))

int _cknum(char* a, int n) {
	int i;
	char t = '0';

	for (i = 0; i < n; i++) {
		if (a[i] < '0' || a[i]>'9') return 1;
	}
	return 0;
}


int _atoi(char* s, int len) {
	char tmp[20];
	memcpy(tmp, s, len);
	tmp[len] = 0x00;
	return (atoi(tmp));
}

//素因数分解　pf素数が入る　pc 素数の数
ll _pfact(ll a);
static ll pf[100000000];
static ll pc;

ll _pfact(ll a) {
	long i, r;
	if (a % 2 == 0) {
		pf[pc] = 2; pc++;
		return(_pfact(a / 2));
	}
	r = sqrt(a);
	for (i = 3; i <= r; i += 2) {
		if (a % i == 0) {
			pf[pc] = i; pc++;
			return(_pfact(a / i));
		}
	}
	if (a != 1) {
		pf[pc] = a; pc++;
	}
	return 0;

}


#pragma endregion


// 123 C-Five Transportations
int main(void) {
	int n, w, h;
	int x, y, a;
	int x0 = 0, y0 = 0;

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

	for (int i = 0; i < n; i++) {
		scanf("%d %d %d", &x, &y, &a);
		switch (a) {
		case 1:x0 =(x0<x)?x:x0; break;
		case 2:w  =(w>x) ?x:w; break;
		case 3:y0 =(y0<y)?y:y0; break;
		case 4:h  =(h>y) ?y:h; break;
		}
		//printf("\n%d %d %d %d\n", w, h, x0, y0);

	}

	w = (w < x0) ? 0 : w - x0;
	h = (h < y0) ? 0 : h - y0;
	printf("%d\n", w * h);

	return 0;
}

Measured memory_bytes: 2148
#include<cstdio>
#include<algorithm>
#define maxn 100005
#include<map>
using namespace std;
typedef long long ll;
bool cmp(pair<int,int>a,pair<int,int>b){
    return a.first < b.first;
}
int main(){
	int n;
	pair <int,int> a[maxn];
	scanf("%d",&n);
	for(int i = 1;i<=n;i++){
		scanf("%d",&a[i].first);
		a[i].second = i;
	}
	sort(a+1,a+n+1,cmp);
	for(int i = 1;i<=n;i++){
		printf("%d ",a[i].second);
	}
	return 0;
} 

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

int main() {
  int n,k,l;
  cin >> n;
  if (n%1000!=0) {
  k = n/1000;
  l = (k+1)*1000 - n;
  } else {
    l = 0;
  }
  cout << l << endl;
}

Measured memory_bytes: 3620
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = 1LL << 60;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(16);

	//cout << setprecision(10) << scientific << ans << endl;
}

//最大公約数
ll gcd(ll m, ll n)
{
	if (m < n) {
		swap(m, n);
	}

	if (n == 0) {
		return m;
	}

	return gcd(n, m % n);
}

signed main() {
	ll n, x;

	cin >> n >> x;

	vector<ll> v(n + 1, x);

	REP(i, n) {
		cin >> v[i + 1];
	}

	vector<ll> dif;

	FOR(i, 1, n + 1) {
		dif.push_back(abs(v[i] - v[i - 1]));
	}

	ll ans = dif[0];

	FOR(i, 1, dif.size()) {
		ans = gcd(ans, dif[i]);
	}

	cout << ans << endl;
}

Measured memory_bytes: 2168
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int ll;

ll Grundy(ll n,ll k){
	if(n%k==0)return n/k;
	if(n==k+1)return 0;
	return Grundy(n-(n/k+1)*max(1LL,(n%k)/(n/k+1)),k);
}

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	int g=0;
	for(int i=0;i<n;i++){
		ll a,k; cin >> a >> k;
		g^=Grundy(a,k);
	}
	if(g==0){
		cout << "Aoki" << endl;
	}else{
		cout << "Takahashi" << endl;
	}
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
	
	char num[1001];
	int i;
	while(1){

		if(num[0] == '0'){
			break;	
		}
		int sum = 0;
			gets(num);
	
		
		for(i=0;i < 1001;i++){
			if(num[i] == '\0'){

				break;
			}
			sum += num[i] - '0';

			

		}
		if(sum != 0){
			printf("%d\n",sum);
		}
	
	}


return 0;

}

Measured memory_bytes: 524
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
using namespace std; using ll = long long; using ld = long double;  using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
using vs = vector<string>; using tll = tuple<ll, ll, ll>; using vtll = vector<tll>;
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define co(i) cout << i << endl;
#define co2(i,j) cout << i << " " << j << endl;
#define co3(i) cout << i << " ";
#define po(i) cout << i.first << " " << i.second << endl;
void in() {}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop, bitSearch, bitList, nod, digitDP, treeDP//
//gcdlcm, isPrime, eratos, primeFactorize, Npow, combination, divisor, modinv, doubling//
//dfs, bfs, dijkstra, WarshallFloyd, BellmanFord, UnionFind, Kruskal, RMQ, LCA//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R, Q;
ll MOD = 1000000007, INF = 1LL << 60, ans = 0, z = 0, o = 1;
vpll flag, D; vll path;
//***********//
ll modinv(ll a, ll m) {
	ll b = m, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int main() {
	cin >> N;
	vl X(N);
	for (i = 0; i < N; i++) cin >> X[i];
	ll base = 1;
	for (i = 1; i < N; i++) {
		(base *= i) %= MOD;
	}
	vl J(N);
	for (i = 1; i < N; i++) {
		(J[i] = J[i - 1] + (base * modinv(i, MOD))%MOD) %= MOD;
	}
	//debug(J);
	for (i = 1; i <= N-1; i++) {
		ll pre = (X[i] - X[i - 1]);
		(pre *= J[i]) %= MOD;
		//debug(pre);
		(ans += pre)%=MOD;
	}
	cout << ans;
}

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

teleport = [-1] * (N+1)
teleport[0] = 1
visited = [(False, -1)] * (N+1)
visited[1] = (True, 0)

for i in range(1, N+1):
    next_town = A[teleport[i-1]-1]
    if visited[next_town][0]:
        before = visited[next_town][1]
        now = i
        break
    teleport[i] = next_town
    visited[next_town] = (True, i)

if K < before:
    print(teleport[K])
else:
    K -= before
    period = now - before
    K %= period
    print(teleport[before + K])



Measured memory_bytes: 38744
line = input()
data = line.split()
 
height = int(data[0])
wei = int(data[1])

if height !=1 and wei !=1: 
  if height %2 ==0:
    if wei %2 ==0:
      print(int(wei/2)*height)
    else:
      print(int(wei/2)*height+int(height/2))
  else:
    if wei %2 ==0:
      print(int(height/2)* wei + int(wei/2))
    else:
      print(wei* int(height/2) + int(wei/2)+1)
else:
  print(1)

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

vector<long long int> combination_list(int n){
  vector<long long int> ret(n+1,1);
  long long int t = 1LL;
  for(int i = 0; i < n; ++i){
    for(int j = 1; j <= i; ++j){
      long long int t_ = ret[j];
      ret[j] += t;
      t = t_;
    }
  }
  return ret;
}

int main(){
  int N, A, B;
  cin >> N >> A >> B;
  vector<long long int> V(N);
  for(int i = 0; i < N; ++i) cin >> V[i];
  sort(V.begin(),V.end());
  double mean = 0;
  for(int i = 0; i < A; ++i){
    mean += (double)V[N-1-i]/A;
  }
  printf("%.12f\n",mean);
  int n = upper_bound(V.begin(),V.end(),V[N-A]) - lower_bound(V.begin(),V.end(),V[N-A]), k = upper_bound(V.begin(),V.end(),V[N-A]) - V.begin() - N + A;
  //n = min(n, k-A+B+1);
  vector<long long int> nC = combination_list(n);
  //cout << n << " " << k << endl;
  long long int ans = nC[k];
  if(V[N-A] == V[N-1]){
    for(int i = k+1; i <= min(n,B); ++i){
      ans += nC[i];
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
    int N,M; cin>>N>>M;
    vector<vector<int>> s(M);
    for(int i=0;i<M;i++){
        int k; cin>>k;
        for(int j=0;j<k;j++){
            int tmp; cin>>tmp;
            s[i].emplace_back(tmp);
        }
    }
    vector<int> p(M);
    for(int i=0;i<M;i++) cin>>p[i];

    int cnt=0;
    for(int i=0;i<(1<<N);i++){
        vector<int> flag(N,0);
        for(int j=0;j<N;j++) flag[j] = (i>>j&1);
        // 判定
        bool f=true;
        for(int m=0;m<M;m++){
            int tmp=0;
            for(int n=0;n<s[m].size();n++)
                tmp += flag[s[m][n]-1];
            if(tmp%2!=p[m]) f=false;
        }
        if(f==true) cnt++;
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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++)
using namespace std;
const int INF=1e9+5;
typedef long long ll;

int main() {
  ll N;
  cin>>N;
  ll a[N],b[N];
  bool judge[N];
  for(ll i=0;i<N;i++){
    cin>>a[i];
    if(i==0){
      b[i]=a[i];
    }
    else{
      b[i]=min(b[i-1],a[i]);
    }
  }
  for(ll i=0;i<N;i++){
    if(a[i]==b[i]){
      judge[i]=true;
    }
    else{
      judge[i]=false;
    }
  }
  ll ans=0;
  for(int i=0;i<N;i++){
    if(judge[i]){
      ans++;
    }
  }
  cout<<ans<<endl;
  
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repa(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#define _GLIBCXX_DEBUG

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

  bool f = false;
  if(s[0] == 'A' && s[1] >= 97 && s[(int)s.size()-1] >= 97){
    repa(i, 2, (int)s.size()-1){
      if(s[i] == 'C'){
        if(f){
          f = false;
          break;
        }
        else{
          f = true;
        }
      }
      else if(s[i] <= 90){
        f = false;
        break;
      }
    }
  }

  if(f) cout << "AC" << endl;
  else cout << "WA" << endl;

}

Measured memory_bytes: 256
#pragma GCC optimize("O3")

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <string>
#include <assert.h>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <random>
#include <cmath>
#include <chrono>
#include <bitset>

#define ld long double
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

#define int long long
using namespace std;

const int INF = 2e18;
const int MOD = 1e9 + 7;
const int MB = 20;

void solve() {
	int n;
	cin >> n;
	vector<int> b(n - 1);
	for (int i = 0; i < n - 1; i++) cin >> b[i];
	vector<int> a(n, INF);
	for (int i = 0; i < n - 1; i++){
		a[i] = min(a[i], b[i]);
		a[i + 1] = min(a[i + 1], b[i]);
	}
	int ans = 0;
	for (int i = 0; i < n; i++) ans += a[i];
	cout << ans;
}
signed main() {
	/*
	freopen("search.in", "r", stdin);
	freopen("search.out", "w", stdout);
	*/
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout.precision(12);
	solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define pi 3.14
using namespace std;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef pair<long long,int> pli;
typedef pair<int,long long> pil;
const int INF=1000000007;
const int MOD=1000000007;
const int nmax=101234;



int main()
{
    ll n,k;
    scanf("%lld%lld",&n,&k);
    n%=k;
    if(k-n<n)n=k-n;
    printf("%lld\n",n);
    return 0;
}


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

typedef pair<int,int> PII;
bool isprime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    for (int i = 3; i*i <= num; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

int main(){
  int N; cin >> N;
  
  vector<PII> v(N);
  int ymax = 0;
  
  for(int i = 0; i < N; i++){
    cin >> v.at(i).first >> v.at(i).second ;
    if(ymax < v.at(i).second){
      ymax = v.at(i).second;
    }
  }
  vector<int> y(ymax+2);
  for(int i = 0; i < ymax+2; i++){
    if(i%2 == 0){
      y.at(i) = 0;
    } else if(isprime(i) && isprime((i+1)/2)){
      y.at(i) = 1;
    }
  }

  vector<int> cumsum(ymax+2, 0);
  for(int i = 0; i < ymax+1; i++){
    cumsum[i+1] = cumsum[i] + y[i];
  }
  
  for(int i = 0; i < N; i++){
    cout << cumsum[v.at(i).second+1] - cumsum[v.at(i).first] << endl;
  }

    

  
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main(){
  string ans;
  ll n,m;
  cin >> n;
  ans="No";
  for(int i=0;i<3;i++){
    m=n%10;
    if(m==7){
      ans="Yes";
    }
    n=n/10;
  }
  cout << ans;
}

Measured memory_bytes: 3596
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
#include<iterator>
#include<sstream>
#include<iomanip>
#include<map>
#include<queue>
#include<deque>
#include<fstream>

#define rep(i, n) for (ll i = 0; i < n; i++) 
#define rrep(i, n) for(ll i = n-1; i>=0; i--)
#define range(i, n, m) for (ll i = n; i < m; i++) 
#define rrange(i, n, m) for (ll i = n - 1; i => m; i--) 
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vp vector<pair<ll, ll> >
#define vvp vector<vector<pair<ll, ll> > >
#define First first
#define Second second.first
#define Third second.second
//#define MOD 998244353

typedef long long int ll;
typedef unsigned long long int ull;

using namespace std;

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; }

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

	//std::ifstream in("../../test.txt");
	//std::cin.rdbuf(in.rdbuf());

	ll H, W;
	cin >> H >> W;

	vector<string> S(H);
	vvl XX(H, vector<ll>(W));
	vvl YY(H, vector<ll>(W));
	rep(i, H) {
		cin >> S[i];
	}

	vector < pair<ll, pair<ll, ll> > > X, Y;

	ll count = 0;
	ll l, r;

	rep(y, H) {
		rep(x, W) {
			if (S[y][x] == '#') continue;
			if (x == 0) {
				XX[y][x] = 1;
			}
			else {
				XX[y][x] = XX[y][x - 1] + 1;
			}
		}

		rrep(x, W) {
			if (S[y][x] == '#') continue;
			if (x == W - 1) continue;
			else {
				chmax(XX[y][x], XX[y][x + 1]);
			}
		}

	}

	rep(x, W) {
		rep(y, H) {
			if (S[y][x] == '#') continue;
			if (y == 0) {
				YY[y][x] = 1;
			}
			else {
				YY[y][x] = YY[y-1][x] + 1;
			}
		}

		rrep(y, H) {
			if (S[y][x] == '#') continue;
			if (y == H - 1) continue;
			else {
				chmax(YY[y][x], YY[y+1][x]);
			}
		}

	}


	ll ret = 0;
	rep(y, H) {
		rep(x, W) {
			chmax(ret, XX[y][x] + YY[y][x] - 1);
		}
	}

	cout << ret << endl;


	return 0;
}



Measured memory_bytes: 69120
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<cmath>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define FOR(i, j, limit) for(int i=j; i< limit; ++i)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ECHO(x) cout<<x<<endl;
#define LL long long
int INF = 2147483647;
LL LINF = 9223372036854775807;
LL MOD = 1000000007;
typedef pair<int, int>P;
typedef pair<LL, LL>PL;
typedef vector<int> vi;
typedef vector<LL> vl;


int main(){
  int n;
  cin>>n;
  int lcount=0, rcount=0, count=0;

  string s;
  cin>>s;
  REP(i, n){
    if(s[i]=='(') ++count;
    else{
      if(count==0) ++lcount;
      else --count;
    }
  }
  count=0;
  for(int i=n-1; i>-1; --i){
    if(s[i]==')') ++count;
    else{
      if(count==0) ++rcount;
      else --count;
    }
  }
  string left="", right = "";
  REP(i, lcount) left += "(";
  REP(i, rcount) right += ")";

  s = left + s + right;

  cout<<s<<endl;


  return 0;
}


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

using namespace std;

#define frei(i,a,b) for (int i = (a), _b = (b); i <= _b; i++)
#define fred(i,a,b) for (int i = (a), _b = (b); i >= _b; i--)
#define fri(i,n) for (int i = 0, _n = (n); i < _n; i++)
#define frd(i,n) for (int i = (n) - 1; i >= 0; i--)
#define foreach(it, ar) for ( typeof(ar.begin()) it = ar.begin(); it != ar.end(); it++ )

#define uint64 unsigned long long
#define int64 long long
#define all(ar) ar.begin(), ar.end()
#define pb push_back
#define pf push_front
#define mp make_pair
#define ff first
#define ss second
#define pr pair

#define BIT(n) (1<<(n))
#define AND(a,b) ((a) & (b))
#define OR(a,b) ((a) | (b))
#define XOR(a,b) ((a) ^ (b))
#define sqr(x) ((x) * (x))

typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<pii> vii;
typedef vector<int> vi;

#define PI 3.1415926535897932385
#define INF 1000111222
#define eps 1e-7
#define maxN 5005

void add_slef(int &a, int b, int mod = 0) {
    a += b;
    if(mod > 0 && a >= mod) a -= mod;
}

void sub_slef(int &a, int b, int mod = 0) {
    a -= b;
    if(mod > 0 && a < 0) a += mod;
}

vector<string> split(string s, string del) {
        vector<string> ans;
        if(s.size() == 0) {
            return ans;
        }
        size_t pos = 0;
        while((pos = s.find(del)) != string::npos) {
            string str = s.substr(0, pos);
            ans.push_back(str);
            s.erase(0, pos + del.size());
        }
        return ans;
}

const int nax = 1e5+10;

int main(int argc, char const *argv[])
{
    /* code */
    int n;
    cin >> n;
    int base = 1;
    while(base <= n) {
        base *= 2;
    }
    vector<int64> tree(2*base);
    vector<int> h(n), a(n);
    for(int i = 0; i < n; i++) cin >> h[i];
    for(int i = 0; i < n; i++) cin >> a[i];
    vector<int64> dp(n+1); // so far height is i waht is max beauty it stores and h <= n so size is n
    for(int i = 0; i < n; i++) {
        // here we can use segment tree and compl is nlogn
        /* for(int j = 0; j < h[i]; j++) {
            dp[h[i]] = max(dp[h[i]], dp[j] + a[i]);
        }*/
        // using segment tree i need max of 0 to h[i]
        int64 best = 0;
        int x = h[i] + base;
        while(x > 1) {
            if(x%2 == 1) {
                best = max(best, tree[x-1]);
            }
            x /= 2;
        }
        dp[h[i]] = best + a[i];
        for(int x = base + h[i]; x >= 1; x /= 2) {
            tree[x] = max(tree[x], dp[h[i]]);
        }
    }
    int64 ans = 0;
    for(int i = 0; i <= n; i++) {
        ans = max(ans, dp[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 7424
#include <bits/stdc++.h>
using namespace std;
// rep macro
#define rep(i, n)        for (int i = 0; i < (int)(n); i++)
#define rev(i, n)        for (int i = (int)(n - 1); i >= 0; i--)
#define rep2(i, s, n)    for (int i = (s); i < (int)(n); i++)
#define rev2(i, s, n)    for (int i = (int)(n) - 1; i >= (int)(s); i--)
#define bitrep(i, n)     for (int i = 0; i < (1 << (int)(n)); i++)
#define bitrep2(i, s, n) for (int i = (s); i < (1 << (int)(n)); i++)
const int di[8] = {-1, 0, 1, 0, -1, -1, 1, 1};
const int dj[8] = {0, 1, 0, -1, -1, 1, 1, -1};
// type macro
using ll = int64_t;
// vector macro
#define all(v) v.begin(), v.end()
using  vi = vector<int>;
using vvi = vector<vector<int>>;
using  vu = vector<size_t>;
using vvu = vector<vector<size_t>>;
using  vl = vector<ll>;
using vvl = vector<vector<ll>>;
using  vd = vector<double>;
using vvd = vector<vector<double>>;
using  vb = vector<bool>;
using vvb = vector<vector<bool>>;
using  vc = vector<char>;
using vvc = vector<vector<char>>;
using  vs = vector<string>;
using vvs = vector<vector<string>>;
// pair macro
#define fi first
#define sj second
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
// math macro
#define lcm(a, b) a / __gcd(a, b) * b
#define dist(a, b) sqrt(pow(a.fi - b.fi, 2) + pow(a.sj - b.sj, 2))
// print macro
#define println(x) cout << x << endl
#define Yes println("Yes")
#define No println("No")
#define YES println("YES")
#define NO println("NO")
// memo
// desc sort: sort(vec.begin(), vec.end(), greater<int>());#include "header.h"

int main()
{
    int n; cin >> n;
    vi a(n), b(n), c(n); rep(i, n) cin >> a[i];rep(i, n) cin >> b[i];rep(i, n) cin >> c[i];
    sort(all(a));sort(all(b));sort(all(c));
    ll sum = 0;
    auto itr_ub = b.begin();
    // O(nlogn)
    while (itr_ub != b.end())
    {
        auto ua = lower_bound(all(a), *itr_ub);
        auto uc = upper_bound(all(c), *itr_ub);
        sum += (ua - a.begin()) * (c.end() - uc);
        itr_ub++;
    }
    cout << sum << endl;
}

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

int main() {
  string str;
  vector<string> strs;
  int n;
  cin >> str >> n;

  for (int i=0;i<n;i++) {
    string op;
    int a, b;
    cin >> op >> a >> b;
    if (op == "replace") {
      string tmp;
      cin >> tmp;
      // str.replace(a, b, tmp);
      tmp = str.substr(0, a) + tmp + str.substr(b+1);
      str = tmp;
    } else if (op == "reverse") {
      reverse(str.begin()+a, str.begin()+b+1);
    } else {
      strs.push_back(str.substr(a, b-a+1));
    }
  }

  for (int i=0;i<strs.size();i++)
    cout << strs[i] << endl;
}



Measured memory_bytes: 3224
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size())  
#define rep(i, n) for(int i=0;i<n;i++)  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef unsigned int uint;
typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 19;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

const int MX = 5005;
const int MM = 998244353;

ll dp[MX][MX];

int main()
{
	int N;
	scanf("%d", &N);
	vector<pii> L;
	for(int i = 1; i <= N; i++){
		int a, b;
		scanf("%d%d", &a, &b);
		L.emplace_back(a, b);
	}
	sort(L.begin(), L.end(), [](pii l, pii r){
		return l.first+l.second < r.first+r.second;
	});

	for(int i = 0; i < MX; i++) for(int j = 0; j < MX; j++) dp[i][j] = 1e18;
	dp[0][0] = 0;
	for(int i = 1; i <= N; i++){
		dp[i][0] = 0;
		for(int j = 1; j <= i; j++){
			dp[i][j] = dp[i-1][j];
			if(dp[i-1][j-1] <= L[i-1].first) dp[i][j] = min(dp[i][j], dp[i-1][j-1] + L[i-1].second);
		}
	}
	for(int i = N; i >= 0; i--) if(dp[N][i] != 1e18) return !printf("%d\n", i);
}


Measured memory_bytes: 196096
#include <stdio.h>
int main(void){
	int n,x,i,cnt=0;
	int l[105];
	int d[105]={0};
	scanf("%d %d",&n,&x);
	for(i=1;i<=n;i++){
		scanf("%d",&l[i]);
	}
	for(i=2;i<=n+1;i++){
		d[i] = d[i-1] + l[i-1];
		if(d[i] <= x) cnt = cnt+1;
	}
	printf("%d\n",cnt+1);
	return 0;
}
	

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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> Vec;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define rep(i, n) REP(i, 0, n)
const int INF=1e9;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define ALL(v) v.begin(), v.end()
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define pb(x) push_back(x)
#define sum(v) accumulate(ALL(v),0)

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

vector<int> divisor(int n) {
    vector<int> ret;
    for(int i=1; i*i<=n; i++) {
        if(n%i==0) {
            ret.pb(i);
            if(i*i!=n) {
                ret.pb(n/i);
            }
        }
    }
    sort(ALL(ret));
    return ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    Vec a(n+1);
    Vec b(n+1);

    rep(i, n) {
        cin>>a[i];
    }

    ll cnt=0;
    Vec box(0);
    rep(i, n) {
        //m→1
        ll m=n-i;
        Vec div=divisor(m);

//        dbg(m);
//        dbg(b[m]);
//        dbg(a[m-1]);
        if(b[m]%2!=a[m-1]){
            rep(j, div.size()) {
                b[div[j]]+=1;
            }
            cnt++;
            box.pb(m);
        }
    }

//    dbg(b);
//    dbg(cnt);
//    dbg(box);

    cout<<cnt<<endl;
    rep(i,box.size()){
        cout<<box[i]<<" ";
    }
    return 0;
}


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

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}

signed main() {
	int n, a, b;
	cin >> n >> a >> b;
	if (a>b||n==0){
		cout << 0 << endl;
	}
	else if (n == 1 && a != b) {
		cout << 0 << endl;
	}
	else {
		cout << b * (n - 2) - a * (n - 2) + 1 << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;

const int MAXN = 262150;
const ll INF = 100000000ll;

ll DP[MAXN][55], n, in[18][2];
bool vis[MAXN][55];

ll dp(int st, int val) {
	if (st == ((1 << n) - 1)) return 0;
	if (vis[st][val]) return DP[st][val];

	vis[st][val] = true;
	DP[st][val] = INF;

	vector<pii> G;
	int tmp = 0;

	for (int i = n-1; i >= 0; --i) {
		if (st & (1 << i)) tmp ^= 1;
		else G.push_back(make_pair(i, tmp));
	}

	reverse(G.begin(), G.end());

	int len = G.size(), id;
	for (int i = 0; i < len; ++i) {
		tmp = (i + G[i].second) & 1;
		id = G[i].first;
		if (in[id][tmp] >= val) {
			DP[st][val] = min(dp(st + (1 << id),in[id][tmp]) + i, DP[st][val]);
		}
	}
	return DP[st][val];
}

int main(){
	ios::sync_with_stdio(0),cin.tie(0);
	while (cin >> n) {
		for (int i = 0; i < 2; ++i) {
			for (int j = 0; j < n; ++j) {
				cin >> in[j][i];
			}
		}
		memset(vis, 0, sizeof(vis));

		if (dp(0,0) >= INF) cout << "-1\n";
		else cout << dp(0,0) << '\n';

	}
	return 0;
}


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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    string s;
    t = 1;
    while(t--) {
     cin >> s;
     s[3] = s[3] + 1;
      cout << s << endl;
    }
    return 0;
}


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

#define int int
#define ff first
#define ss second
#define pb push_back

int bexp(int a, int b, int mod)
{
    int res = 1;
    if (mod <= 0)
        return 0;

    while (b)
    {
        if (b & 1) res = (res * a) % mod;

        a = (a * a) % mod; 
        b >>= 1;
    }
    return res;
}

#define N 500010
#define MOD 1000000007

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

vector<int> seg[4 * N];
int a[N], b[N];
int n, q;

void build(int node, int l, int r)
{
    if (l == r)
    {
        seg[node] = vector<int>(1, a[l]);
    }
    else
    {
        int mid = l + r >> 1;
        build(2 * node, l, mid);
        build(2 * node + 1, mid + 1, r);

        merge(seg[2 * node].begin(), seg[2 * node].end(), 
              seg[2 * node + 1].begin(), seg[2 * node + 1].end(),
              back_inserter(seg[node]));

    }
}

int R;

int query(int node, int l, int r, int x, int y)
{
    if (x > y)
        return 0;

    if (l == x && r == y)
    {
        int k = abs(distance(seg[node].end(), upper_bound(seg[node].begin(), seg[node].end(), R)));
        return k; 
    }

    int mid = l + r >> 1;
    return query(2 * node, l, mid, x, min(mid, y)) + query(2 * node + 1, mid + 1, r, max(mid + 1, x), y);
}

int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(10);

    cin >> n >> q;

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

    map<int, int> mi;

    for (int i = n; i > 0; --i)
    {
        a[i] = (mi[b[i]] == 0 ? INT_MAX : mi[b[i]]);
        mi[b[i]] = i;
    }

    // for (int i = 1; i <= n; ++i)
    // {
    //     cout << a[i] << " ";
    // }
    build(1, 1, n);

    int l, r;
    for (int i = 0; i < q; ++i)
    {
        cin >> l >> r;
        R = r;
        cout << query(1, 1, n, l, r) << "\n";
    }
    return 0;
}


Measured memory_bytes: 142912
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fio ios_base::sync_with_stdio(false)
#define pdl cout << "*" << endl
#define MOD 1000000007
#define INF 1000000000
#define INFLL 1000000000000000000ll
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define long int64_t
using namespace std;
using namespace __gnu_pbds;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
typedef priority_queue<pii, vector<pii>, greater<pii>> min_pq;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> OST;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char* name, Arg1&& arg1){ cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args)
{ const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma+1, args...); }

const int N = 3001;
const int i2 = MOD + 1 >> 1;

int a[N], dp[N][N], t[N][N];

int main()
{
	fio;
	int n, q;
	cin >> n >> q;
	for(int i=1; i<=n; i++)
		cin >> a[i];
	for(int i=1; i<=n; i++)
		for(int j=1; j<=n; j++)
			dp[i][j] = int(a[i] > a[j]);
	int f = 1;
	while(q--)
	{
		f <<= 1;
		f %= MOD;
		int x, y;
		cin >> x >> y;
		for(int j=1; j<=n; j++)
		{
			int i = j;
			if(i == x or i == y)
				i ^= x ^ y;
			t[x][j] = (dp[x][j] * 1ll * i2 + dp[y][i] * 1ll * i2) % MOD;
			t[y][j] = (dp[y][j] * 1ll * i2 + dp[x][i] * 1ll * i2) % MOD;
			t[j][x] = (dp[j][x] * 1ll * i2 + dp[i][y] * 1ll * i2) % MOD;
			t[j][y] = (dp[j][y] * 1ll * i2 + dp[i][x] * 1ll * i2) % MOD;
		}
		for(int i=1; i<=n; i++)
		{
			dp[x][i] = t[x][i];
			dp[y][i] = t[y][i];
			dp[i][x] = t[i][x];
			dp[i][y] = t[i][y];
		}
	}
	int ans = 0;
	for(int i=1; i<=n; i++)
		for(int j=i+1; j<=n; j++)
			ans = (ans + dp[i][j]) % MOD;
	ans = (ans * 1ll * f) % MOD;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 70656
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
using namespace std;

using LL = long long;

const LL MOD = 1000000007;

LL n, m;
struct query
{
	LL l, x;
};
vector<query>q[333];

LL dpn[333][333][3], dpo[333][333][3];
int main(void)
{
	cin >> n >> m;
	for (LL j = 0; j < m; ++j)
	{
		LL ll, rr, xx; cin >> ll >> rr >> xx;
		q[rr].push_back({ ll, xx });
	}
	memset(dpo, 0, sizeof(dpo));
	/*
	for (LL id = 0; id < 3; ++id)
	{
		dpo[0][0][id] = 1;
	}
	//*/
	dpo[0][0][0] = 1;
	for (LL i = 0; i <= n; ++i)
	{
		//dpnを0初期化
		memset(dpn, 0, sizeof(dpn));
		for (LL j = 0; j <= i; ++j)for (LL k = 0; k <= i; ++k)for (LL id = 0; id < 3; ++id)
		{
			LL prim = max(j, k);
			LL seco = min(j, k);
			bool ok = true;
			for (query& dat : q[i])
			{
				LL ins = dat.l;
				if (ins > prim)
				{
					if (dat.x != 1)
					{
						ok = false; break;
					}
				}
				else if (ins > seco)
				{
					if (dat.x != 2)
					{
						ok = false; break;
					}
				}
				else
				{
					if (dat.x != 3)
					{
						ok = false; break;
					}
				}
			}
			if (!ok)
			{
				dpo[j][k][id] = 0;
				continue;
			}
			if (i == n)
			{
				//配るDPはiがnの時しなくてよい
				break;
			}
			//配るdp
			//col0を配置
			dpn[j][k][id] += dpo[j][k][id];
			//col1を配置
			{
				LL nid = id + 1; nid %= 3;
				dpn[k][i][nid] += dpo[j][k][id];
			}
			//col2を配置
			{
				LL nid = id + 2; nid %= 3;
				dpn[i][j][nid] += dpo[j][k][id];
			}
		}
		if (i == n)break;
		//dpoにdpnの内容を入れる
		for (LL j = 0; j <= n; ++j)for (LL k = 0; k <= n; ++k)for (LL id = 0; id < 3; ++id)
			dpo[j][k][id] = dpn[j][k][id] % MOD;
	}
	LL ans = 0;
	for (LL j = 0; j <= n; ++j)for (LL k = 0; k <= n; ++k)for (LL id = 0; id < 3; ++id)
	{
		ans += dpo[j][k][id];
		ans %= MOD;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 5632
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 998244353
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int main(){
  ll H,W;cin>>H>>W;
  ll i,j,k;
  string s[H];
  rep(i,H) cin>>s[i];
  ll yoko[H][W],tate[H][W];
  rep(i,H){
    ll tmp=0;
    rep(j,W){
      if(s[i][j]=='.'){
        tmp++;yoko[i][j]=tmp;
      }
      else{
        yoko[i][j]=0;
        tmp=0;
      }
    }
  }
  rep(i,H){
    ll tmp1=0;
    for(j=W-1;j>=0;j--){
      if(yoko[i][j]>0 and tmp1>0){
        yoko[i][j]=tmp1;
      }
      else if(yoko[i][j]>0 and tmp1==0){
        tmp1=yoko[i][j];
      }
      else{
        tmp1=0;
      }
    }
  }

  rep(j,W){
    ll tmp=0;
    rep(i,H){
      if(s[i][j]=='.'){
        tmp++;tate[i][j]=tmp;
      }
      else{
        tate[i][j]=0;
        tmp=0;
      }
    }
  }
  rep(j,W){
    ll tmp1=0;
    for(i=H-1;i>=0;i--){
      if(tate[i][j]>0 and tmp1>0){
        tate[i][j]=tmp1;
      }
      else if(tate[i][j]>0 and tmp1==0){
        tmp1=tate[i][j];
      }
      else{
        tmp1=0;
      }
    }
  }

  ll sum[H][W];
  rep(i,H){
    rep(j,W){
      sum[i][j]=tate[i][j]+yoko[i][j];
    }
  }

  ll ans;
  rep(i,H){
    rep(j,W){
      ans=max(ans,sum[i][j]);
      //cout<<ans;
    }
    //cout<<endl;
  }
  cout<<ans-1<<endl;
}


Measured memory_bytes: 98048
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
  int N,K;
  cin >> N >> K;
  vector<int> p(N);
  int i;
  for(i=0;i<N;i++)cin >> p[i];
  sort(p.begin(),p.end());
  int ans = 0;
  for(i=0;i<K;i++)ans += p[i];
  cout << ans << endl;
}

Measured memory_bytes: 3628
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

def ceil(x,y):
  return (x-1)//y+1
n = int(input())
A=[];B=[]
for i in range(n):
  a,b = map(int,input().split())
  A.append(a);B.append(b)
for i in range(n-1,-1,-1):
  count += B[i] * ceil(A[i]+count,B[i]) - (A[i]+count)
print(count)


Measured memory_bytes: 51420
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

void solve() {
    int M, K;
    cin >> M >> K;
    if (M == 1) {
        if (K == 0) {
            cout << "0 0 1 1" << endl;
        } else {
            cout << -1 << endl;
        }
        return;
    }

    if (K >= (1 << M)) {
        cout << -1 << endl;
        return;
    }

    vi ans;
    rep(i, 1 << M) {
        if (i != K)ans.push_back(i);
    }
    ans.push_back(K);
    for (int i = (1 << M) - 1; i >= 0; --i) {
        if (i != K)ans.push_back(i);
    }
    ans.push_back(K);
    each(x, ans)cout << x << ' ';
    cout << endl;
}

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

Measured memory_bytes: 2932
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#define PI 3.141592653589793
#define MOD 1000000007

//qsort用、昇順
int compare_int(const void *a, const void *b)
{
	return *(int*)a-*(int*)b;
}
//qsort(data, 10, sizeof(int), compare_int)


int main(){
	int n, m;
	scanf("%d%d", &n, &m);
	int array[m], sum=0;
	for(int i=0; i<m; i++){
		scanf("%d", &array[i]);
		sum += array[i];
	}

	if(sum > n) printf("-1\n");
	else printf("%d\n", n-sum);
	
	
	return 0;
}

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

int main() {
  int n, k, S = 0;
  cin >> n >> k;
  for(int i = 0;i < n;i++) {
    int h;
    cin >> h;
    if(h >= k) S++;
  }
  cout << S << endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
 
#define REP(i,s,N) for (int i=s;i<(N); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;


ll ans=0;

int main(){
	ll N,K;
	cin >> N >> K;
	ll h[N];
	REP(i,0,N){
		cin >> h[i];
		if(h[i]>=K) ans++;
	}
	
	cout << setprecision(10) << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
S = input()
for i in range(len(S)-1):
    if S[i] == S[i+1]:
        print(i+1, i+2)
        exit()


for i in range(len(S)-2):
    if S[i] == S[i+2]:
        print(i+1, i+3)
        exit()


print(-1, -1)


Measured memory_bytes: 39408
from collections import defaultdict
H, W, K = map(int, input().split())
cake = []
sbdict = defaultdict(list)
sbrows = set()

for i in range(H):
    line = input()
    assert len(line) == W
    cake.append(line)
    for j in range(W):
        if line[j] == '#':
            sbrows.add(i)
            sbdict[i].append(j)
sbrows = sorted(sbrows)

def divide():
    dcake = [[None]*W for _ in range(H)]
    color = 1
    for r in sbrows:
        cs = list(sorted(sbdict[r]))
        cs.append(W)  # sentinel
        prev = 0
        for i in range(len(cs)-1):
            for j in range(prev, cs[i+1]):
                dcake[r][j] = color
            color += 1
            prev = cs[i+1]
    # Fill blank lines.
    prev = 0
    for i in range(len(sbrows)):
        for r in range(prev, sbrows[i]):
            dcake[r] = list(dcake[sbrows[i]])
        prev = sbrows[i] + 1
    lastr = sbrows[-1]
    for r in range(lastr+1, H):
        dcake[r] = list(dcake[lastr])
    return dcake

dcake = divide()
for r in range(H):
    print(' '.join('{:4}'.format(x) for x in dcake[r]))


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

const int k_mod = ( int )1e9 + 7;
int main( void ){
	string array[] = { "MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"};
	string hoge = "SUN";
	if (!scanf( "%s", &hoge[ 0 ] ))
		return -1;
	rep(i,0,7){
		if (hoge == array[i]){
			i++;
			i%=7;
			printf( "%d\n", 7-i);
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define dofloat cout<<fixed<<setprecision(8)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bitcount __builtin_popcount
#define all(vec) vec.begin(),vec.end()
#define rall(vec) vec.rbegin(),vec.rend()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<long long> vl;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long> > vll;
typedef vector<pair<int,int> > vii;
typedef vector<int> vi;
typedef pair<int,int> ii;
const long long MOD=1000000007;
const long long MAX=100005;
const long double PI=3.14159265359;
const long double G=9.807;
const long long INF=1e18;
const long double EPS=1e-6;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
bool isprime(ll a){
  if(a==2)return 1;
  if(!(a&1))return 0;
  for(ll i=3;i*i<=a;i+=2)
    if(a%i==0)return 0;
  return 1;
}
ll mpow(ll base,ll exponent,ll modulus){
  if(modulus==1)return 0;
  long long result = 1;
  base=base%modulus;
  while(exponent){
    if(exponent%2 == 1)
    result=(result*base)%modulus;
    exponent=exponent>>1;
    base=(base*base)%modulus;
  }
  return result;
}
ll minv(ll a,ll mod){
  ll _gcd=gcd(a,mod);
  assert(_gcd==1);
  return mpow(a,mod-2,mod);
}


/*
ll ncr(ll N,ll K){
  if(N<K)return 0;
  if(K==0)return 1;
  if(N==0)return 0;

  ll den=1;
  for(ll i=1;i<=K;i++)den*=i;
  ll num=1;
  while(K--){
    num*=N;
    if(num%den==0){
      num/=den;
      den=1;
    }
    N--;
  }

  return num;
}
*/
ll k,x;
int main(){FAST;
cin>>k>>x;
if(k*500>=x){
  cout<<"Yes\n";
}
else{
  cout<<"No\n";
}
return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    for(int i=0 ; i<=1000 ; i++){
      int a1 = (int)(i*0.08);
      int b1 = (int)(i*0.1);
      if(a1==a && b1==b){
        System.out.println(i);
        break;
      }else if(a1>a || b1>b){
        System.out.println(-1);
        break;
      }
    }
  }
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

const ll MAX = 510010;
const ll MOD = 1000000007;
vector<ll> fac(MAX), finv(MAX), inv(MAX);
bool init_called = false;
//=============modinv============================
void COMinit() {
  fac.at(0) = 1;
  fac.at(1) = 1;
  finv.at(0) = 1;
  finv.at(1) = 1;
  inv.at(1) = 1;
  for (ll i = 2; i < MAX; i++){
    fac.at(i) = fac.at(i - 1) * i % MOD;
    inv.at(i) = MOD - inv.at(MOD % i) * (MOD / i) % MOD;
    finv.at(i) = finv.at(i - 1) * inv.at(i) % MOD;
  }
}

ll COM(ll n, ll k){
  if (!init_called) {
    COMinit();
    init_called = true;
  }
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac.at(n) * (finv.at(k) * finv.at(n - k) % MOD) % MOD;
}
//=================================================


ll N, K;

int main()
{
  cin >> N >> K;
  ll M = COM(N + N - 1, N - 1);
  if (K >= N - 1) {
    cout << M << endl;
    return 0;
  }
  ll ans = 1;
  for (ll i = 1; i <= K; ++i) {
    ans = (ans + COM(N, i) * COM(N - 1, i) % MOD) % MOD;
  }
  cout << ans << "\n";
}


Measured memory_bytes: 12160
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner stdIn=new Scanner(System.in);
		int N=stdIn.nextInt();
		int K=stdIn.nextInt();
		String S=stdIn.next();
		String a="";
		char b=' ';
		b=S.charAt(K-1);
		if(b=='A')
			b='a';
		if(b=='B')
			b='b';
		if(b=='C')
			b='c';
		a=S.substring(0,K-1)+b+S.substring(K,N);
		System.out.println(a);
	}
}

Measured memory_bytes: 21844
mod = 10**9 + 7
def gcd(a, b):
    return a if b == 0 else gcd(b, a % b)
def solve():
    n = int(input())
    a = list(map(int, input().split()))
    primes = []
    isprime = [True for i in range(1001)]
    for i in range(2, 1001):
        if isprime[i]:
            primes.append(i)
            for j in range(i * i, 1001, i):
                isprime[j] = False
    x = a[0]
    f = True

    cnt = [0 for i in range(1000001)]
    for val in a:
        x = gcd(x, val)
        i = 0
        while i < len(primes) and primes[i] ** 2 <= val:
            if val % primes[i] == 0:
                cnt[primes[i]] += 1
                while val % primes[i] == 0:
                    val //= primes[i]
            i += 1
        if val > 1:
            cnt[val] += 1
    for i in range(2, 1000001):
        if cnt[i] > 1:
            f = False
            break
    if f:
        print('pairwise coprime')
    elif x == 1:
        print('setwise coprime')
    else:
        print('not coprime')



t = 1
while t > 0:
    solve()
    t -= 1

Measured memory_bytes: 208848
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {

            string[] str = Console.ReadLine().Split(' ');
            int nn = int.Parse(str[0]);
            int a = int.Parse(str[1]);
            int b = int.Parse(str[2]);

            int ans = 0;

            for(int i =1; i< nn + 1; i++)
            {
                int sum = 0;
                foreach(char c in i.ToString())
                {
                    sum += (int)(c-'0');
                }
                
                if(a<=sum && sum<= b)
                {
                    ans += i;
                }
            }

            Console.WriteLine(ans);

        }
    }
 }


Measured memory_bytes: 11092