akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include<math.h>
using namespace std;

int main() {
	int N, A, B;
	cin >> N >> A >> B;
	int sum=0,re=0;
	for (int i = 1; i <= N;i++) {
		int x = i;
		sum = 0;
		while (true) {
			sum += x % 10;
			x /= 10;
			if (x == 0) break;
		}
		if (sum >= A && sum <= B)re += i;
	}
	cout << re << endl;
}

Measured memory_bytes: 256
NK = input().split()
N = int(NK[0])
K = int(NK[1])

sum = 0

H = []
tmp = input().split()
for i in range(N):
	H.append(int(tmp[i]))

  
H.sort() 
for i in range(K):
  try:
    H.pop()
  except IndexError:  
    pass

sum = 0  
  
for i in H:
  sum += i

print(sum)


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

int main() {
  long long K,A,B;
  cin >> K >> A >> B;
  if (A + 1 >= B || A > K) {
    cout << K + 1 << endl;
  }
  else {
    K -= (A - 1);
    cout << A + K / 2 * (B - A) + K % 2 << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
#ifdef DEBUG
#define debug(...) pr(any{__VA_ARGS__})
#define debugv(x) pr((x))
#else
#define debug(...)
#define debugv(x)
#endif

vector<vector<int>> graph;

int dfs(int u, vector<int> &path, vector<bool> &visit){
	visit[u] = true;
	for(int v: graph[u]){
		path[u] = v;
		if(path[v]>=0) return v;
		if(visit[v]) continue;
		int c = dfs(v, path, visit);
		if(c >= 0) return c;
	}
	path[u] = -1;
	return -1;
}

int main(){
	int N, M; cin >> N >> M;
	graph.assign(N, {});
	for(int i=0; i<M; i++){
		int a, b; cin >> a >> b;
		a--; b--;
		graph[a].push_back(b);
	}

	vector<int> path;
	int first = -1;
	for(int i=0; i<N; i++){
		vector<bool> visit(N);
		path.assign(N, -1);
		first = dfs(i, path, visit);
		if(first >= 0) break;
	}
	if(first<0) {
		cout << -1 << endl;
		return 0;
	}

	vector<bool> loop(N);
	int next = first;
	while(!loop[next]){
		debug("a", next, path[next]);
		loop[next] = true;
		next = path[next];
	}
	while(true){
		bool update = false;
		int u = first;
		int t = -1;
		//debug("pohe");
		while(true){
			debug("b", u, path[u], first);
			for(int v: graph[u]){
				if(!loop[v]) continue;
				if(v == path[u]) continue;
				t = v;
				break;
			}
			if(t >= 0){
				debug(u, t, path[u]);
				path[u] = t;
				update = true;
				break;
			}
			u = path[u];
			if(u==first) break;
		}
		if(update){
			loop.assign(N, false);
			int v = u;
			first = u;
			while(true){
				//debug(v, path[v]);
				loop[v] = true;
				v = path[v];
				if(v == u) break;
			}
		} else {
			break;
		}
	}

	vector<int> ans;
	for(int i=0; i<N; i++){
		if(loop[i]) ans.push_back(i);
	}
	cout << ans.size() << endl;
	for(int a: ans){
		cout << a+1 << endl;
	}

	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>


int main() {
    int a, b; std::cin >> a >> b;
    for (int i = 0; i <= 10000; i++) {
        if (i * 8 / 100 == a && i * 10 / 100 == b) {
            std::cout << i << std::endl;
            return 0;
        }
    }
    std::cout << -1 << std::endl;
    return 0;
}


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

using namespace std;

int main() {
  int n;
  vector<int> v;
  
  cin >> n;
  
  int tmp;
  for (int i = 0; i < n; i++) {
  	cin >> tmp;
    v.push_back(tmp);
  }
  sort(v.begin(), v.end(), greater<int>());
  int mx = v[0];
  int other = accumulate(++v.begin(), v.end(), 0);
  
  if (mx >= other) {
  	cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
/*

*/

#include <stdio.h>
#include <ctype.h>
#include <string.h>

int main()
{
	int n;
	int T=0,H=0;
	int i;
	char Tcard[101],Hcard[101];
	scanf("%d", &n);
	for(i=0; i<n; i++){
		scanf("%s %s", Tcard, Hcard);
		if(strcmp(Tcard, Hcard)<0){
			H+=3;
		}
		else if(strcmp(Tcard, Hcard)>0){
			T+=3;
		}
		else{
			T++;
			H++;
		}
	}
	printf("%d %d\n", T, H);
	return 0;
}

Measured memory_bytes: 604
#include<bits/stdc++.h>
using namespace std;
const long long mod=1e9+7;
long long n,h[200005],b[200005],tree[800005];
int mid(int l,int r)
{
    return (l+r)/2;
}
void up(int nod,int l,int r,int x,long long val)
{
    if(x<l||r<x)return;
    if(l==r)
    {
        tree[nod]=val;
        return;
    }
    up(nod*2,l,mid(l,r),x,val);
    up(nod*2+1,mid(l,r)+1,r,x,val);
    tree[nod]=max(tree[nod*2],tree[nod*2+1]);
}
int ck(int x,int y,int l,int r)
{
    if(x<=l&&r<=y)return 1;
    else if(y<l||r<x)return 3;
    else return 2;
}
long long q(int nod,int l,int r,int x,int y)
{
    int c=ck(x,y,l,r);
    if(c==1)return tree[nod];
    else if(c==3)return 0;
    else
    {
        long long s=q(nod*2,l,mid(l,r),x,y);
        long long ss=q(nod*2+1,mid(l,r)+1,r,x,y);
        return max(s,ss);
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n;
    for(int i=0;i<n;i++)cin>>h[i];
    for(int i=0;i<n;i++)cin>>b[i];
    long long ans=0;
    for(int i=0;i<n;i++)
    {
        long long mx=q(1,1,n,1,h[i]-1);
        ans=max(ans,mx+b[i]);
        up(1,1,n,h[i],mx+b[i]);
    }
    cout<<ans;
}


Measured memory_bytes: 9600
import bisect

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))    

A = sorted(A)
B = sorted(B)
C = sorted(C)

ans = 0
for b in B:
    a = bisect.bisect_left(A, b)
    c = len(C) - bisect.bisect_right(C, b)
    ans += (a*c)

print(ans)

Measured memory_bytes: 22720
#include <bits/stdc++.h>
#define cout16 cout << setprecision(16) 
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using P = std::pair<int,int>;
using vp = std::vector<P>;
using namespace std;
#define INF 1001001001
#define LL_INF 1001001001001001001
#define fi first
#define se second

int main(void) {
	string s,t; cin >> s >> t;
	int n = s.size();
	vi sm(26,-1),tm(26,-1);
	vi sv(n),tv(n);
	int cnt = 0;
	rep(i,n){
		int x = s[i]-'a';
		if(sm[x]==-1){ sm[x]=cnt; cnt++; }
		sv[i] = sm[x];
	}
	cnt = 0;
	rep(i,n){
		int x = t[i]-'a';
		if(tm[x]==-1){ tm[x]=cnt; cnt++; }
		tv[i] = tm[x];
	}
	if(sv==tv) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 2312
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner sc = new Scanner(System.in);
        int age = sc.nextInt();
        int price = sc.nextInt();
        if (age >= 13) {
            System.out.println(price);
        } else if (age <= 12 && age >= 6) {
            System.out.println(price / 2);
        } else {
            System.out.println(0);
        }
    }
}


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

int main(){
    string s;
    cin >> s;
    s[3] = '8';
    cout << s << endl;
    
    return 0;
}


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

#define forw(m,i,n) for(i=m; i<n; i++)
#define done return 0
#define in(x) cin >> x
#define out(x) cout << x << endl
#define pb(x) push_back(x)
#define w(x) while(x--)
#define maxx 1000000000

using namespace std;

typedef long long ll;

 map<int,int>dig;

int main() {
    //freopen("output.txt","w",stdout);
    //freopen("input.txt","r",stdin);
    int f=0,s=0;
    for(int i=0; i<3; i++) {
        int x;
        in(x);
        if(x==5) f++;
        else s++;
    }
    if(f==2 && s==1) cout << "YES\n";
    else cout << "NO\n";
    done;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define N 105
#define INF 1e8
using namespace std;
int main(){
	int n,x,i,pos,a,b,ans=INF;
	vector<int> w,qdh;
	qdh.push_back(0);
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>x;
		w.push_back(x);
	}
	for(i=0;i<n;i++)
	{
		qdh.push_back(qdh[qdh.size()-1]+w[i]);
	}
	for(i=1;i<=n;i++)
	{
		a=qdh[i];
		b=qdh[n]-qdh[i];
		ans=min(ans,abs(a-b));
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<int> h(n);
    rep(i,n){
        cin>>h[i];
    }
    int pre=h[0]-1;
    FOR(i,1,n){
        if(pre>h[i]){
            cout<<"No"<<endl;
            return 0;
        }
        if(pre+1<=h[i]) h[i]--;
        pre=h[i];
    }
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 640
#include <stdio.h>

int main(void)
{
    int a, b, c;
    int i;
    int n;
    
    scanf("%d%d%d", &a, &b, &c);
    
    n = 0;
    for (i = a; i <= b; i++){
        if (c % i == 0){
            n++;
        }
    }
    
    printf("%d\n", n);

    return (0);
}



Measured memory_bytes: 2104
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define MP make_pair
#define ls (o << 1)
#define rs (o << 1 | 1)
#define mid ((L + R) >> 1)
#define eps (1e-5)
using namespace std;
typedef long long LL;
const LL mod = 1e9 + 7;
int n, m;
typedef pair<int, int> PII;
LL c[3050][3050];
int l[3050], r[3050], pre[3050];
char s[3050];
LL dp[3050][3050];
int have(int l, int r) { return pre[r] - pre[l - 1]; }
int have(int mark) { return pre[r[mark]] - pre[l[mark] - 1]; }
void add(LL &o, LL p) { o = (o + p) % mod; }
int main() {
    scanf("%d%d", &n, &m);
    for (int i = 0; i <= n; ++i) {
        c[i][0] = 1;
        for (int j = 1; j <= i; ++j) {
            c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % mod;
        }
    }
    scanf("%s", s + 1);
    for (int i = 1; s[i]; ++i) {
        pre[i] = pre[i - 1] + s[i] - '0';
    }
    for (int i = 0; i < m; ++i) {
        scanf("%d%d", &l[i], &r[i]);
        if (i && r[i] <= r[i - 1]) {
            m--;
            i--;
        }
    }
    l[m] = n + 1;
    pre[n + 1] = pre[n];
    r[m] = n + 1;
    dp[0][have(0)] = 1;
    for (int i = 0; i < m; ++i) {
        //        for(int j = 0;j <= n; ++j){
        //            if(dp[i][j])printf("%d %d %lld\n",i,j,dp[i][j]);
        //        }
        if (r[i] < l[i + 1]) {
            // cout <<have(i + 1) <<endl;
            for (int j = 0; j <= n; ++j) {
                add(dp[i + 1][have(i + 1)],
                    dp[i][j] * c[r[i] - l[i] + 1][j] % mod);
            }
            continue;
        }
        int L = r[i] - l[i + 1] + 1;
        for (int j = 0; j <= n; ++j) {
            for (int k = 0; k <= L; ++k) {
                if (j < k)
                    break;
                int qian = l[i + 1] - l[i];
                if (qian < j - k)
                    continue;
                add(dp[i + 1][have(r[i] + 1, r[i + 1]) + k],
                    dp[i][j] * c[qian][j - k] % mod);
            }
        }
    }
    printf("%lld\n", dp[m][0]);
    return 0;
}

Measured memory_bytes: 52224
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REPR(i,n) for (int i=(int)(n)-1;i>=0;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
#define tpl(...) make_tuple(__VA_ARGS__)
const int INF = 0x3f3f3f3f;
const double EPS = 1e-8;
const double PI = acos(-1);
const int dy[] = {-1,0,1,0};
const int dx[] = {0,1,0,-1};
typedef long long ll;
typedef pair<int,int> pii;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename Ch,typename Tr,typename C,typename=decltype(begin(C()))>basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>&os,
const C& c){os<<'[';for(auto i=begin(c);i!=end(c);++i)os<<(i==begin(c)?"":" ")<<*i;return os<<']';}
template<class S,class T>ostream&operator<<(ostream &o,const pair<S,T>&t){return o<<'('<<t.first<<','<<t.second<<')';}
template<int N,class Tp>void output(ostream&,const Tp&){}
template<int N,class Tp,class,class ...Ts>void output(ostream &o,const Tp&t){if(N)o<<',';o<<get<N>(t);output<N+1,Tp,Ts...>(o,t);}
template<class ...Ts>ostream&operator<<(ostream&o,const tuple<Ts...>&t){o<<'(';output<0,tuple<Ts...>,Ts...>(o,t);return o<<')';}
template<class T>void output(T t,char z=10){if(t<0)t=-t,putchar(45);int c[20];
int k=0;while(t)c[k++]=t%10,t/=10;for(k||(c[k++]=0);k;)putchar(c[--k]^48);putchar(z);}
template<class T>void outputs(T t){output(t);}
template<class S,class ...T>void outputs(S a,T...t){output(a,32);outputs(t...);}
template<class T>void output(T *a,int n){REP(i,n)cout<<a[i]<<(i!=n-1?',':'\n');}
template<class T>void output(T *a,int n,int m){REP(i,n)output(a[i],m);}
template<class T>bool input(T &t){int n=1,c;for(t=0;!isdigit(c=getchar())&&~c&&c-45;);
if(!~c)return 0;for(c-45&&(n=0,t=c^48);isdigit(c=getchar());)t=10*t+c-48;t=n?-t:t;return 1;}
template<class S,class ...T>bool input(S&a,T&...t){input(a);return input(t...);}
template<class T>bool inputs(T *a, int n) { REP(i,n) if(!input(a[i])) return 0; return 1;}

ll dp[10][1001][101];

int main() {
  memset(dp,0,sizeof(dp));
  REP(i,101)
    dp[0][0][i] = 1;
  dp[1][0][0] = 1;
//  REP(i,101) dp[1][0][0] = 1;
  REP(i,9) {
    REP(j,1001) {
      for (int k=1; k<=100; ++k) {
        if (j>=k)
          dp[i+1][j][k] += dp[i][j-k][k-1];
        dp[i+1][j][k] += dp[i+1][j][k-1];
      }
    }
  }
  int n, s;
  while(input(n,s), n||s) {
    cout << dp[n][s][100] << endl;
  }
}

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

int main()
{
	char a;
	int ans = 0;
	while(scanf("%c",&a))
	{
		if(a < '0'||a > '9')
		{
			break;
		}
		else
		{
			ans += a-'0';
		}
	}
	if(ans % 9 == 0)
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}
	return 0;
}

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

#define INF 1000000000

int c[10][10];
int s[10]={INF,INF,INF,INF,INF,INF,INF,INF,INF,INF};

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

    int h,w;cin>>w>>h;

    for(int i=0;i<10;i++)for(int j=0;j<10;j++)cin>>c[i][j];

    vector<int> v={0,1,2,3,4,5,6,7,8,9};

    do
    {
        int sum=0;
        for(int i=0;i<10;i++)
        {
            if(v[i]==1)break;
            sum+=c[v[i]][v[i+1]];
        }
        s[v[0]]=min(s[v[0]],sum);
    } while (next_permutation(v.begin(),v.end()));

    int ans=0;

    for(int i=0;i<w*h;i++)
    {
        int ia;cin>>ia;
        if(ia==-1)continue;
        ans+=s[ia];
    }

    cout<<ans<<"\n";

    return 0;
}


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


int main() {
    cin.tie(0);
    iostream::sync_with_stdio(false);
    int N, Q;
    cin >> N >> Q;
    string S;
    cin >> S;
    assert(S.size() == N);
    vector<int> prefix_count = vector<int>(N, 0);
    for (int i = 1; i < N; i++) {
        prefix_count.at(i) = prefix_count.at(i - 1);
        prefix_count.at(i) += (S.at(i) == 'C' && S.at(i - 1) == 'A') ? 1 : 0;
    }
    for (int i = 0; i < Q; i++) {
        int l, r;
        cin >> l >> r;
        cout << prefix_count.at(r - 1) - prefix_count.at(l - 1) << "\n";
    }
}


Measured memory_bytes: 1488
def LCS(str1,str2):
    A = [0 for _ in range(len(str2)+1)]
    for i in range(len(str1)):
        A_copy = A[:]
        for j in range(len(str2)):
            if(str1[i]==str2[j]):
                A[j+1] = A_copy[j]+1
            elif(A[j] > A[j+1]):
                A[j+1] = A[j]
    return A[-1]


m = int(input())
for i in range(m):
    str1 = input()
    str2 = input()
    print(LCS(str1,str2))


Measured memory_bytes: 5632
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

total = 0
min_mod = 10
for t in (a,b,c,d,e):
  total += (t + 9) // 10
  if t%10 != 0:
    min_mod = min(t%10, min_mod)

ans = (total - 1) * 10 + min_mod
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
struct UF {						 // Union_Find木
	vector<int> par;			 // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
	vector<int> sz;				 // size[i]:iを根とする木のサイズ
	UF(int N) : par(N), sz(N) {	 //最初は全てが根であるとして初期化
		for(int i = 0; i < N; i++) {
			par[i] = i;
			sz[i] = 1;
		}
	}

	int root(int x) {  // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if(par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	// 2つのデータx, yが属する木が同じならtrueを返す
	bool same(int x, int y) { return root(x) == root(y); }

	void unite(int x, int y) {	// xとyの木を併合
		int rx = root(x);		// xの根をrx
		int ry = root(y);		// yの根をry
		if(rx == ry) return;	// xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry;			// xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
		sz[ry] += sz[rx];
		sz[rx] = 0;	 //サイズの処理 根じゃなくなったらサイズは0になる
	}

	// xが属する木のサイズ sz[x]は根でないとき0になるので注意
	int size(int x) { return sz[root(x)]; }
};

int main() {
	// https://onlinejudge.u-aizu.ac.jp/courses/library/3/DSL/all/DSL_1_A
	int n, q;
	cin >> n >> q;
	UF uf(n);
	for(int i = 0; i < q; i++) {
		int com, x, y;
		cin >> com >> x >> y;
		if(com) {
			cout << uf.same(x, y) << "\n";
		} else {
			uf.unite(x, y);
		}
	}
}



Measured memory_bytes: 3240
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <x86intrin.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define chmin(x,y) x = min(x, y)
#define chmax(x,y) x = max(x, y)
#define V vector
vector<int> dx = {-1, 1,  0, 0, -1, -1,  1, 1};
vector<int> dy = { 0, 0, -1, 1, -1,  1, -1, 1};

int main () {
    int n; double k; cin >> n >> k;
    V<double> a(n);
    double sum = 0;
    rep(i, n) {
        cin >> a[i];
        sum += a[i];
    }
    //sort(allr(a));
    /*
    if (k == 0) {
        cout << a[0] << endl;
        return 0;
    }
    */
    
    int ok = 1001001001;
    int ng = 0;
    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;
        ll cnt = 0;
        rep(i, n) {
            cnt += (int(a[i]) + mid - 1)/mid - 1;
        }
        if (cnt <= k) ok = mid;
        else ng = mid;
    }
    cout << ok << endl;
    /*
    int r = sum/k + 5;
    int l = sum/(k+n) - 1;
    //printf("l = %d\nr = %d\n", l, r);
    ll ans = 1001001001;
    for (int x = l; x <= r; x++) {
        if (x <= 0) {
            x = 0;
            continue;
        }
        ll cnt = -n;
        rep(i, n) {
            cnt += (int(a[i]) + (int)x - 1)/(int)x;
        }
        if (cnt <= k) {
            ans = x;
            break;
        }
        //printf("max = %d\ncnt = %d\n", x, cnt);
    }
    cout << ans << endl;
    */
    return 0;
}

Measured memory_bytes: 4888
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, n1, n2, n3, n4;
  cin >> N;
  n1 = N / 1000;
  n2 = (N - n1 * 1000) / 100;
  n3 = (N - n1 * 1000 - n2 * 100) / 10;
  n4 = (N - n1 * 1000 - n2 * 100 - n3 * 10);
  if (n2 == n3) {
    if (n1 == n2 || n4 == n2) {
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
#define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};

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

struct Timer{
    chrono::system_clock::time_point start, end;
    Timer(){ start = chrono::system_clock::now(); }
    ~Timer(){
        end = chrono::system_clock::now();
        auto msec = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cerr<<"time : "<<msec<<" ms"<<endl;
    }
};




signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    // Timer TM;

    ll k,x;
    cin>>k>>x;
    if(500*k>=x) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
unittest
{
	assert( [ "2", "1", "2" ].parse.expand.solve == "first" );
	assert( [ "3", "100000", "30000", "20000" ].parse.expand.solve == "second" );
}



import std.algorithm;
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 n = input.front.to!( long );
	auto as = new long[ n ];
	foreach( ref a; as )
	{
		input.popFront;
		a = input.front.to!( long );
	}
	return tuple( as );
}

auto solve( long[] as )
{
	return as.count!( ( a ) => a % 2 == 1 ) ? "first" : "second";
}


Measured memory_bytes: 3836
N=int(input())
X=[]

for i in range(0,N):
    S,P=input().split()
    P=int(P)
    X.append([S,P,i+1])

X.sort()

for i in range(0,N-1):
    for j in range(i+1,N):
        if X[i][0]==X[j][0]:
            if X[i][1]<X[j][1]:
                tmp=X[i]
                X[i]=X[j]
                X[j]=tmp

for i in range(0,N):
    print(X[i][2])


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

int main(){
	string A, B, C;
	cin >> A >> B >> C;
	if (A[A.size() - 1] == B[0] && B[B.size() - 1] == C[0]){
		cout << "YES" << endl;
			}
	else{
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,m;
  cin >> n >> m;
    
  int a[n+1] = {0};
  int total = 0;
  for(int i=1; i<n+1; i++){
    cin >> a[i];
    total += a[i];
  }
  
  int count = 0;
  for(int i=1; i<n+1; i++){
    if(a[i]*4*m>=total) count++;
  }
  
  string ans = "No";
  if(count>=m) ans = "Yes";
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}

const int node_max = 200050;
vector<int> graph[node_max];
int dist[node_max];
int ans[node_max];
bool visited[node_max];

void bfs(int v){

    queue<int> q;
    q.push(v);
    dist[v] = 0;

    while(!q.empty()){
        int now = q.front(); q.pop();
        for(auto next: graph[now]){
            if (visited[next]) continue;
            dist[next] = dist[now] + 1;
            q.push(next);
        }
        visited[now] = true;
    }
}

queue<int> num[3];
bool setdata(int i, int box){
    int res = 0;
    if (!num[box].empty()) {
        ans[i] = num[box].front(); 
        num[box].pop();
        return true;
    } else {
        return false;
    }
}

int main()
{
    int n;
    cin >> n;
    vector<P> a(n-1);
    rep(i, n-1){
        int tmp1, tmp2;
        cin >> tmp1 >> tmp2;
        tmp1--; tmp2--;
        graph[tmp1].push_back(tmp2);
        graph[tmp2].push_back(tmp1);
    }

    bfs(0);

    //rep(i, n) cout << dist[i] << endl;

    int gu = 0;
    int ki = 0;
    rep(i, n) {
        if(dist[i]%2==0) gu++;
        else ki++;
    }

    rep(i, n){
        int id = i+1;
        num[id%3].push(id);
    }

    // 11122200
    if (gu <= n/3){
        rep(i, n){
            if (dist[i]%2==0){
                setdata(i, 0);
            }else{
                setdata(i, 1) || setdata(i, 2) || setdata(i, 0);
            }
        }
    } else if (ki <= n/3){
        rep(i, n){
            if (dist[i]%2!=0){
                setdata(i, 0);
            }else{
                setdata(i, 1) || setdata(i, 2) || setdata(i, 0);
            }
        }
    } else {
        rep(i, n){
            if (dist[i]%2==0){
                setdata(i, 1) || setdata(i, 0);
            }else{
                setdata(i, 2) || setdata(i, 0);
            }
        }
    }

    rep(i, n){
        cout << ans[i]  << " ";
    }
}



Measured memory_bytes: 17264
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>

using namespace std;
static const int MAX_V = 101;
static const int INF = 1e9;

struct edge
{
	int to;
	int cap;
	int revNum;
	edge();
	edge(int to, int cap, int revNum) : to(to), cap(cap), revNum(revNum){};
};

vector<edge> G[MAX_V];
bool used[MAX_V];

int dfs(int v, int t, int f)
{
	if (v == t)
	{
		return(f);
	}
	used[v] = true;
	for (int i = 0; i < G[v].size(); ++i)
	{
		edge& e = G[v][i];
		if (!used[e.to] && e.cap > 0)
		{
			int d = dfs(e.to, t, min(f, e.cap));
			if (d > 0)
			{
				e.cap -= d;
				G[e.to][e.revNum].cap += d;
				return(d);
			}
		}
	}
	return(0);
}

int maxFlow(int s, int t)
{
	int flow = 0;
	while (true)
	{
		memset(used, 0, sizeof(used));
		int f = dfs(s, t, INF);
		if (f == 0)
		{
			return(flow);
		}
		flow += f;
	}
}

void solve()
{
	int V, E;
	cin >> V >> E;
	for (int i = 0; i < E; ++i)
	{
		int from, to, cap;
		cin >> from >> to >> cap;
		G[from].push_back(edge(to, cap, G[to].size()));
		G[to].push_back(edge(from, 0, G[from].size() - 1));
	}
	cout << maxFlow(0, V - 1) << endl;
}

int main()
{
	solve();
	return(0);
}

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

int main() {
vector<int>a;
a={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int k;
cin >>k;
cout << a.at(k-1);
}


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

#define endl '\n'
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define F(i,j,k) fill(i[0],i[0]+j*j,k)
#define P(p) cout<<(p)<<endl;
#define SORT(v) sort(all(v))
#define SORTD(v) sort(all(v), greater<int>())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define INF 1<<30
#define v(T) vector<T>
#define vv(T) v(v(T))
#define print(x) cout<<x<<endl
#define printv(v) for(auto i : v){cout<<i<<" ";}cout<<endl
#define printu(v) for(auto i : v){print(i);}
#define readarray(v, n) for (int i=0;i<n;i++)cin >> v[i]
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef long long ll;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int i, j, k;
vi v;
int main()
{
	int n;
	cin >> n;
	rep(i, n) {
		int j;
		cin >> j;
		v.push_back(j);
	}
	int index = 0;
	int ans = 0;
	rep(i, v.size()) {
		int t = v[index];
		if (t == -1) {
			print(-1);
			break;
		} else if (t == 2) {
			ans++;
			print(ans);
			break;
		}
		ans++;
		v[index] = -1;
		index = t - 1;
	}
	return 0;
}


Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
signed main()
{
	 ios_base::sync_with_stdio(false);
	 cin.tie(NULL);
	 cout.tie(NULL);
	 int n,k;
	 cin>>n>>k;
	 vector<int>h(n);
	 for(int i=0;i<n;i++)
	 	cin>>h[i];
	 vector<int>dp(n,1e18);
	 dp[0]=0;
	 dp[1]=abs(h[1]-h[0]);
	 for(int i=2;i<n;i++)
	 {
	 	   for(int j=1;j<=k;j++)
	 	   	if(i>=j)
	 	   dp[i]=min(dp[i-j]+abs(h[i]-h[i-j]),dp[i]);
	 }
	 cout<<dp[n-1]<<endl;
	 return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//#include <stdbool.h>
#include <limits.h>
//#include <math.h>

#define Max(a, b) (a > b ? a : b)

int main() {
  int n;
  scanf("%d", &n);
  int f[n][10], p[n][11];
  for (int i=0; i<n; i++)
    for (int j=0; j<10; j++)
      scanf("%d", f[i]+j);
  for (int i=0; i<n; i++)
    for (int j=0; j<11; j++)
      scanf("%d", p[i]+j);
  int ans = INT_MIN, profit, cnt;
  for (int i=1; i<(1<<10); i++) {
    profit = 0;
    for (int j=0; j<n; j++) {
      cnt = 0;
      for (int k=0; k<10; k++)
        if ((i & (1<<k)) != 0 && f[j][k] == 1)
          cnt++;
      profit += p[j][cnt];
    }
    ans = Max(ans, profit);
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repr(i,a,n) for(int i=a;i>=n;i--)
#define INF 999999999
#define INF_M 2147483647
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
 
int main() {
	int n; cin >> n;
	rep(i,0,n) {
		int a[8];
		rep(j,0,8) scanf("%1d",&a[j]);

		int big = 0; int small = 0;
		sort(a, a+8);
		rep(j,0,8) {
			small += a[j] * pow(10,7-j);
			big += a[7-j] * pow(10,7-j);
		}

		cout << big - small << endl;
	}
    return 0;
}

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

int main() {
    int N, M; cin >> N >> M;
    int left = 1, right = N;
    for (int i = 0; i < M; i++) {
        int a, b; cin >> a >> b;
        left = max(left, a);
        right = min(right, b);
    }
    cout << max(right - left + 1, 0) << endl;
}

Measured memory_bytes: 3592
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
from heapq import *

n,m=nii()
a=lnii()
a=[-i for i in a]
a.sort(reverse=True)

heapify(a)

for i in range(m):
  x=heappop(a)
  x*=-1
  x//=2
  heappush(a,-x)

print(-sum(a))

Measured memory_bytes: 20284
#include <stdio.h>

int main(){
    
    char now;
    int res=0,culc=0;
    scanf("%d",&res);
    while(true){
        
        scanf("%c",&now);
        if(now=='='){
            break;
        }
        if(now=='+'){
            scanf("%d",&culc);
            res+=culc;
        }
        if(now=='-'){
            scanf("%d",&culc);
            res-=culc;
        }
        if(now=='*'){
            scanf("%d",&culc);
            res*=culc;
        }
        if(now=='/'){
            scanf("%d",&culc);
            res/=culc;
        }
    }
    
    printf("%d\n",res);
    return 0;
}


Measured memory_bytes: 2720
N, M = map(int, input().split())
lis = [list(input().split()) for _ in range(M)]
AC = [[0] * 2 for i in range(N)]
for i in range(M):
    if lis[i][1] == "AC":
        AC[int(lis[i][0])-1][1] = 1
    elif AC[int(lis[i][0])-1][1] == 0:
        AC[int(lis[i][0])-1][0] += 1
a = 0
w = 0
for i in range(N):
    if AC[i][1] == 1:
        a += 1
        w += AC[i][0]
print(a, w)


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

int main() {
    int n;
    long long k;
    cin >> n >> k;
    vector<int> a(n), b(n);
    map<int, long long> m;
    rep(i, n) {
        cin >> a[i] >> b[i];
        m[a[i]] += b[i];
    }
    long long cnt = 0;
    for (auto x : m) {
        cnt += x.second;
        if (cnt >= k) {
            cout << x.first << endl;
            break;
        }
    }
}


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

using namespace std;

int main(){
	int a,b,c;
	cin>>a>>b>>c;
	int i,j,k;
	i=a+b;
	j=b+c;
	k=a+c;
	cout<<min(k,min(i,j))<<endl;
	
	return 0;
}

Measured memory_bytes: 256
import math
import numpy as np


#a, b, c, x = map(int, [input() for i in range(4)])
#z = list(map(int, input().split()))
#n, a, b = map(int, input().split())

#print(len(z))
#for i in z:
#    print(i)

n, a, b = map(int,input().split())

ans = 0
for i in range(n+1):
    sum = 0
    k = i
    while k > 0:
        sum += k % 10
        k = k // 10
    if a <= sum <= b:
        ans += i
print(ans)


Measured memory_bytes: 12392
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;


int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if (abs(c-a)<=d) cout << "Yes" << endl;
  else if (abs(b-a)<=d && abs(b-c)<=d) cout << "Yes" << endl;
  else cout << "No" << endl;
}


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

//xまでの素数を列挙O(n^1.5)
vector<int> get_prime_numbers(int x) {
	vector<int> v;
	int sn = sqrt(x);

	for (int number = 2; number <= x; number++) {
		int i = 0;
		bool pn = false;
		while (true) {
			if (i >= v.size() || v[i] > sn) { //平方根までの全素数で割れればOK
				v.push_back(number);
				break;
			}
			if (number % v[i] == 0) break;
			i++;
		}
	}
	return v;
}

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

	if (N < 10) {
		cout << 0 << endl;
		return 0;
	}

	vector<int> pnumbers = get_prime_numbers(N/2);



	vector<int> counter2, counter4, counter14, counter24, counter74;
	for (int i = 0; i < pnumbers.size(); i++) {

		int counter = 0;
		for (int k = 1; k <= N; k++) {
			int num = k;
			while (num > 1) {
				if (num%pnumbers[i] == 0)
				{
					counter++;
					num = num / pnumbers[i];
				}
				else
				{
					break;
				}
			}
		}

		if (counter >= 2) counter2.push_back(pnumbers[i]);
		if (counter >= 4) counter4.push_back(pnumbers[i]);
		if (counter >= 14) counter14.push_back(pnumbers[i]);
		if (counter >= 24) counter24.push_back(pnumbers[i]);
		if (counter >= 74) counter74.push_back(pnumbers[i]);


	}

	//3*5*5, 3*25, 5*15, 75
	int total = counter4.size() * (counter4.size() - 1) / 2 * (counter2.size() - 2);
	total += counter24.size()*(counter2.size()-1);
	total += counter14.size()*(counter4.size()-1);
	total += counter74.size();
	cout << total << endl;
	return 0;
}

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
const int inf = 1000000001;
const ll INF = 1e18 * 4;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<<fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };

int main() {
	string s;
	cin >> s;
	int k, i, j;
	cin >> k;
	i = 0;
	while (k > 0 && i<s.size()) {
		if ('z' - s[i] + 1 <= k && s[i] != 'a') {
			k -= ('z' - s[i] + 1);
			s[i] = 'a';
		}
		i++;
	}
	while (k >= 26) {
		k -= 26;
	}
	i = s.size() - 1;
	while (k > 0) {
		if ('z' - s[i] <= k) {
			k -= ('z' - s[i]);
			s[i] = 'z';
		}
		else {
			s[i] += k;
			k = 0;
		}
		if (i > 0) {
			i--;
		}
	}
	cout << s << endl;
}

Measured memory_bytes: 512
//libraries
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//namespace
using namespace std;
using namespace __gnu_pbds;

//typedef
typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long,long> pll;

//define
#define inp(X) cin>>X;
#define inp_long(X) long long X; cin>>X;
#define inp_arr(A,N) long long A[N]; for(long long int i=0;i<N;i++) {cin>>A[i];}
#define sz(A) A.size()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define endl '\n'
#define vect(A) vector<long long> A;
#define inp_vect(A,N); vect(A);for(long long i=0;i<N;i++){long long q; cin>>q; A.push_back(q);}
#define forin(i,a,b) for(long long i=a;i<=b;i++)
#define forde(i,a,b) for(long long i=a;i>=b;i--)
#define fio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);

ll power(ll x,ll y)
{
    if (y == 0)
        return 1;
    ll p = power(x, y/2) % MOD;
    p = (p * p) % MOD;

    return (y%2 == 0)? p : (x * p) % MOD;
}
ll modInverse(ll a)
{
   return power(a,MOD-2);
}
ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
ll p=1e5;

int main()
{
    /*#ifndef ONLINE_JUDGE
       freopen ("input.txt" , "r" , stdin);
		// freopen ("OUTPUT.txt" , "w" , stdout);
	#endif
    */
	fio;
    ll n;
    cin>>n;
    ll a[n];
    double sum=0;
    forin(i,0,n-1)
    {
        cin>>a[i];
        sum+=a[i];
    }
    ll cost=1e18;
    ll sum1=0;
    ll e=0;
    forin(i,0,n-1)
    {
        sum1+=a[i];
        cost=min(cost,(ll)abs(2*sum1-sum));
    }
    cout<<cost<<endl;
}



Measured memory_bytes: 1792
N = int(input())
X = [int(i) for i in input().split()]
X_sorted = sorted(X)
a = [X_sorted[N//2-1], X_sorted[N//2]]
for i in range(N):
    if X[i] >= a[1]:
        print(a[0])
    else:
        print(a[1])


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


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

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

    vector<int> p_sort = p;
    sort(p.begin(),p.end());

    int count = 0;
    rep(i,n){
        if(p[i] != p_sort[i]) count++;
    }
    if(count < 3)print("YES");
    else print("NO");

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100000000000
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<int, int>
#define PP pair<P,P>
#define T tuple<int,int,int> 
using namespace std;
 
int main(){
   int k; cin >> k;
   vector<ll> a(k);
   rep(i,k) cin >> a[i];
   ll mn=2; ll ma=3;
   if(a[k-1]>2){
       cout << -1 << endl;
       return 0;
   }
   for(int i=k-2; i>=0; i--){
       mn=a[i]*((mn-1)/a[i]+1);
       ma=((ma/a[i])+1)*a[i]-1;
       //mn=((mn-1)/a[i]+1)*a[i];
       //ma=(ma/a[i])*a[i]+a[i]-1;
       //cout << ma << endl;
       //cout << mn << ' ' << ma << endl;
       if(mn>ma){
           cout << -1 << endl;
           return 0;
       }
   }
 
   cout << mn << ' ' << ma << endl;
return 0;
}

Measured memory_bytes: 3992
from heapq import heapify, heappop, heappush


def main():
    heap = []
    while True:
        operation = input()
        if operation[0] == "i":
            heappush(heap, -int(operation.split()[1]))
        elif operation[1] == "x":
            print(-heappop(heap))
        else:
            break


if __name__ == "__main__":
    main()



Measured memory_bytes: 45308
package main

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

func out(x ...interface{}) {
	//fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func main() {
	sc.Split(bufio.ScanWords)
	N, W := getInt(), getInt()
	w := make([]int, N)
	v := make([]int, N)
	for i := 0; i < N; i++ {
		w[i], v[i] = getInt(), getInt()
	}
	out(N, W, w, v)
	w0 := w[0]
	var dp [101][101][330]int
	WW := 301

	dp[0][0][0] = 0

	for i := 1; i <= N; i++ {
		for j := 1; j <= N; j++ {
			for k := 0; k <= WW; k++ {
				dw := w[i-1] - w0
				if k-dw < 0 {
					dp[i][j][k] = dp[i-1][j][k]
				} else {
					if dp[i-1][j][k] >= dp[i-1][j-1][k-dw]+v[i-1] {
						dp[i][j][k] = dp[i-1][j][k]
					} else {
						dp[i][j][k] = dp[i-1][j-1][k-dw] + v[i-1]
					}
				}
			}
		}
	}

	res := 0
	for i := 0; i <= N; i++ {
		out("--------")
		for j := 0; j <= WW; j++ {
			out("w = ", i, "v = ", dp[N][i][j], w0*i+j)
			if w0*i+j <= W && res < dp[N][i][j] {
				res = dp[N][i][j]
			}
		}
	}
	fmt.Println(res)

}


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

int main(void){
    int N;
    string S;
    cin >> N >> S;
    
    int cnt = 0;
    for(int i = 0 ; i < N-2 ; i++){
        if(S.substr(i,3) == "ABC"){
            cnt++;
        }
    }
    
    cout << cnt << endl;
}

Measured memory_bytes: 3640
while True:
    n = int(input())
    if n == 0:
        break
    else:
        data_set = [int(i) for i in input().split()]
        m = sum(data_set) / n
        v = 0
        for i in data_set:
            diff = i - m
            v += diff ** 2
        v /= n
        print(v ** 0.5)

Measured memory_bytes: 7700
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <limits.h>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <string>
using namespace std;
#define ll long long
const int maxx =105;
int vis[maxx];
int sign[maxx][maxx];
int flag[maxx];
int n;
struct node{
    int x,y;
};
node a[maxx],b[maxx];
bool solve(int x)
{
    for(int i=1;i<=n;i++){
        if(vis[i]==0 && sign[i][x]){
            vis[i] = 1;
            if(flag[i] == -1 || solve(flag[i])){
                flag[i] = x;
                return true;
            }
        }
    }
	return false;
}
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++){
        flag[i] = -1;
        scanf("%d%d",&a[i].x,&a[i].y);
    }
    for(int i=1;i<=n;i++){
        scanf("%d%d",&b[i].x,&b[i].y);
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            if(a[i].x< b[j].x && a[i].y < b[j].y ){
                sign[i][j] = 1;
            }
        }
    }
    int ans = 0;
    for(int i=1;i<=n;i++){
        memset(vis,0,sizeof(vis));
        if(solve(i)){
            ans++;
        }
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
n,d = list(map(int,input().split()))
x = [input().split() for i in range(n)]
D = d**2
ans = 0
for i in range(n):
  kyori = int(x[i][0])**2 + int(x[i][1])**2
  if kyori <= D:
    ans = ans + 1
print(ans)

Measured memory_bytes: 67520
import java.util.*;
import java.io.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		HashMap hs = new HashMap();
		PrintWriter ou = new PrintWriter(System.out);
		int n = Integer.parseInt(sc.next());
		int[] a = new int[n + 1];
		int[] b = new int[n];
		for(int i = 0 ; i <= n ; i++){
			a[i] = Integer.parseInt(sc.next());
		}
		for(int i = 0 ; i < n ; i++){
			b[i] = Integer.parseInt(sc.next());
		}
		sc.close();
		long yono = 0;
		for(int i = 0 ; i < n ; i++){
			if(a[i] >= b[i]){
				a[i] -= b[i];
				yono += b[i];
			}else{
				b[i] -= a[i];
				yono += a[i];
				yono += Math.min(b[i] , a[i + 1]);
				a[i + 1] -= Math.min(a[i + 1] , b[i]);
			}
		}
		ou.print(yono + "\n");
		ou.flush();
	}
}

Measured memory_bytes: 60652
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long d = sc.nextLong();
        int kaunto = 0;
        long[] a = new long[n];
        long[] b = new long[n];
        for(int i = 0; i < n; i++){
            a[i] = sc.nextLong();
            b[i] = sc.nextLong();
            if(a[i]*a[i] + b[i]*b[i] <= d*d) kaunto++;
        }
        System.out.println(kaunto);
        sc.close();
    }
}

Measured memory_bytes: 64572
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
using namespace std;
using ll=long long;
#define mod  1000000007

int main(int argc, char const *argv[]) {
  int n,a;
  std::cin >> n >> a;
  std::cout << n*n-a << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n;cin >> n;
  	int ans = 0;
  	if (n==10||n==100||n==1000||n==10000||n==100000) ans = 10;
  	else while(n) {
    	ans += n%10;
      	n/=10;
    }
  	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int a, b, c;
    cin >> a >> b >> c;

    cout << (c - a - b >= 0 && 4ll * a * b < 1ll * (c - a - b) * (c - a - b) ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int A[2000010];
int C[100010];

int main (){
	int n;
	cin>>n;
	for(int i=0;i<100000;i++) C[i]=0;
	for(int i=0;i<n;i++) {
		cin>>A[i];
		C[A[i]]++;
	}
	int flag=0;
	for(int i=0;i<100000;i++){
		for(int j=C[i];j>0;j--) if(flag) {
			cout<<" "<<i;
			flag++;
		}
		else {cout<<i;flag++;}
	}
	cout<<endl;
	return 0;
}


Measured memory_bytes: 11264
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tl3;



const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;



int main() {
	int a, b;
	cin >> a >> b;
	cout << max(a + b, 2 * max(a, b) - 1) << endl;

}


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



int main(void) {

	int N, M, A, B, C;
	priority_queue<pair<int, int>> Q;
	cin >> N >> M;

	for (int i = 0; i < N; i++)
	{
		cin >> A;
		Q.push(make_pair(A, 1));
	}

	for (int i = 0; i < M; i++)
	{
		cin >> B >> C;
		Q.push(make_pair(C, B));
	}

	long long ans = 0;
	int count = 0;
	while (1)
	{
		for (int i = 0; i < Q.top().second; i++)
		{
			ans += Q.top().first;
			count++;
			if (count == N) break;
		}
		Q.pop();
		if (count == N) break;
	}

	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 2420