akhauriyash/Code-Regression huggingface dataset:
/*Program from Luvwgyx*/
#include<queue>
#include<vector>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define int long long
#define fir first
#define sec second
#define pi pair<int ,int >
#define mp(x,y) make_pair(x,y)
using namespace std;
const int inf=1e18;
const int maxn=3e2+10;
int n,m,ans,pos[maxn],cnt[maxn],vis[maxn],a[maxn][maxn];
int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
void print(int x){
    if(x<0)putchar('-'),x=-x;
    if(x>9)print(x/10);
    putchar(x%10+'0');
}
void write(int x){print(x);puts("");}
signed main(){
    n=read();m=read();ans=inf;
    for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)a[i][j]=read();
    for(int i=1;i<=n;i++)pos[i]=1;
    while(1){
        int mx=0,now=0;
        for(int i=1;i<=n;i++){
            cnt[a[i][pos[i]]]++;
            if(cnt[a[i][pos[i]]]>mx)mx=cnt[a[i][pos[i]]],now=a[i][pos[i]];
        }ans=min(ans,mx);vis[now]=1;bool flag=0;//write(mx);
        for(int i=1;i<=n;i++)while(vis[a[i][pos[i]]])pos[i]++;
        for(int i=1;i<=n;i++)if(pos[i]<=m){flag=1;break;}
        if(!flag)break;memset(cnt,0,sizeof(cnt));
    }write(ans);
    return 0;
}


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

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

    int n, m;
    cin >> n >> m;

    char C[n][m];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            cin >> C[i][j];
        }
    }

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

    bool f = true;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            if(C[i][j] == '.') continue;
            bool ff = false;
            for(int k = 0; k < 4; k++){
                int nx = dx[k] + i;
                int ny = dy[k] + j;
                if(nx < 0 or ny < 0 or nx >= n or ny >= m) continue;
                if(C[nx][ny] == '#'){
                    ff = true;
                    break;
                }
            }
            if(!ff){
                f = false;
                break;
            }
        }
    }

    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
 int t,zero = 0,flag = 0;
 scanf("%d",&t);
 long long int n,max = 1e18,sum = 1;
 	for(int i=0;i<t;i++){
 		scanf("%lld",&n);
 		n>max ? flag = 1 : flag;
		 sum *= n;
		 n==0 ? zero = 1 : max /= n; 
	 }
	 if(zero ==1){
	 	puts("0");
	 }
	 else{
	 	flag==1 ? puts("-1") : printf("%lld\n",sum);
	 }

  return 0;
}

Measured memory_bytes: 3232
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define fi first
#define se second
#define INF 1000000009
#define LLINF 1000000000000000009LL
using ll = long long;

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

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
}comb(100009);

int main(){
  int n,k;
  cin>>n>>k;
  rep(i,k){
    cout<<(comb(k-1,i)*comb(n-k+1,i+1)).x<<endl;
  }
  return(0);
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

const long MOD = 1000000007;
typedef pair<int, int> P;
typedef long long ll;

vector<int> v[100];
int N, M;

long dfs(int now, int state){
    if(state == pow(2, N)-1) return 1;

    long ans = 0;
    for(int next : v[now]){
        if((state>>next)&1 == 1) continue;
        int next_state = (state | (1<<next));
        ans += dfs(next, next_state);
    }
    return ans;
}

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

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

    cout << dfs(0, 1) << endl;

    return 0;
}


Measured memory_bytes: 256
import os
import sys
from atexit import register
from io import BytesIO
sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))
input = lambda: sys.stdin.readline().rstrip('\r\n')
raw_input = lambda: sys.stdin.readline().rstrip('\r\n')

n = int(input())
seq = input()
r = seq.count('R')
ans = 0
if r != n and r != 0:
    cnt = 0
    for i in xrange(n):
        if seq[i] == 'R':
            cnt += 1
        else:
            ans += 1
            cnt += 1
        if cnt == r:
            break
print(ans)

Measured memory_bytes: 85456
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <set>
#include <queue>
#include <map>
#include <numeric>
#include <functional>
#include <math.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)


int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<ll> A(N+1);
    vector<ll> B(N+1, INF);
    for (int n = 0; n <= N; ++n) {
        cin >> A[n];
    }
    
    if (N == 0) {
        if (A[0] == 1) cout << 1 << endl;
        else cout << -1 << endl;
        return 0;
    }
    
    if (A[0] != 0) {
        cout << -1 << endl;
        return 0;
    }
    
    vector<ll> Sum(N+1);
    Sum[N] = 0;
    for (int n = N-1; n >= 0; --n) {
        Sum[n] = Sum[n+1] + A[n+1];
    }
    
    B[0] = 1;
    bool bImp = false;
    for (int n = 0; n < N; ++n) {
        B[n+1] = Sum[n+1];
        if (B[n+1] > 2*B[n]-A[n+1]) {
            B[n+1] = 2*B[n]-A[n+1];
        }
        if (B[n+1] < B[n]-A[n+1] || B[n+1] < 0) {
            bImp = true;
            break;
        }
    }
    
    if (bImp) {
        cout << -1 << endl;
        return 0;
    }
    
    ll Res = 0;
    for (int n = 0; n <= N; ++n) {
        Res += A[n] + B[n];
    }
    cout << Res << endl;

    return 0;
}


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

#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ALL(a) begin(a), end(a)
#define SZ(a) ((int)(a).size())

#define REP(a, b) for (int a = 0; a < (b); a++)
#define FOR(a, b, c) for (int a = (b); a <= (c); a++)
#define REPD(a, b) for (int a = (b) - 1; a >= 0; a--)
#define FORD(a, b, c) for (int a = (b); a >= (c); a--)

#define MIN(a, b) (a) = min((a), (b))
#define MAX(a, b) (a) = max((a), (b))

#ifdef __DEBUG
#define debug if (true)
#else
#define debug if (false)
#endif

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

template <typename T> using V = vector<T>;
template <typename T> using VV = vector<V<T>>;
template <typename T> using VVV = vector<VV<T>>;

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2> &p) {
  return is >> p.fi >> p.se;
}

const int MX = 303;

double dp[MX][MX][MX];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vi a(3);
  REP(i, n) {
    int x;
    cin >> x;
    a[x - 1]++;
  }
  FOR(k, 0, n) FOR(j, 0, n) FOR(i, 0, n) {
    int l = n - i - j - k;
    if (i == 0 && j == 0 && k == 0) continue;
    double &ref = dp[i][j][k];
    if (i > 0) ref += 1.0 * i * dp[i - 1][j][k];
    if (j > 0) ref += 1.0 * j * dp[i + 1][j - 1][k];
    if (k > 0) ref += 1.0 * k * dp[i][j + 1][k - 1];
    ref += n;
    ref /= n - l;
  }
  cout << fixed << setprecision(12) << dp[a[0]][a[1]][a[2]] << endl;
}


Measured memory_bytes: 217344
#include <stdio.h>

int main(void){
  long A,B;
  int ans = 0;
  scanf("%ld%ld",&A,&B);

  for(int i = A;i <= B;i++){
    if(i%10 == i/10000){
      if((i/1000)%10 == (i/10)%10){
        ans++;
      }
    }
  }

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

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

int n, A[15], ans;

void dfs(int x,int s){
  if(x==n){
    if(s%2==0) ans++;
    return;
  }

  for(int i=-1;i<=1;i++) dfs(x+1, s*(A[x]+i));
}

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

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


Measured memory_bytes: 256
N, M = map(int, input().split())
S = input().split()
X = [int(s) for s in S]
X.sort()
# print(X)
res = []
for i in range(0, M):
    try:
        res.append(X[i+1]-X[i])
    except:
        break
# print(res)
res.sort(reverse=True)
print(sum(res[N-1:]))

Measured memory_bytes: 14728
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)

#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define pi pair<ll,ll>
#define md (ll)(1e9+7)
#define all(X) X.begin(),X.end()

// for pair comparison function(ascending order) use return (i1.ff < i2.ff);

/* string operations :
   str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
   str.substr (x) : returns a substring str[x],... end of string
   str.find(qtr) : returns the first occurenece of qtr in str */

const int M=1e6+6;

ll pwr(ll a,ll n,ll m)
{
	ll p=1;
	while(n>0)
	{
		if(n%2==1)
			p=(p*a)%m;
		a=(a*a)%m;
		n=n/2;
	}
	return p;
}

ll dp[M],h[M];

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

	ll n,k,i,j;

	cin >> n;

	k = 2;

	for(i=1;i<=n;++i)
		cin >> h[i];

	for(i=2;i<=n;++i)
	{
		dp[i] = 1e16;
		for(j=max(i-k,1ll);j<i;++j)
			dp[i] = min(dp[i],dp[j]+abs(h[i]-h[j]));
	}

	cout << dp[n] << endl;
	return 0;
}

	


Measured memory_bytes: 5120
#include <stdio.h>
#include <ctype.h>
int main(void){
  int i,c;
  int count[26]={0};
  while((c=getchar())!=EOF){
      if(isalpha(c)){
        if(isupper(c)){
            c=tolower(c);
        }
      ++count[c-'a'];
      }
  }
  for(i=0;i<26;i++){
      printf("%c : %d\n",'a'+i,count[i]);
  }
  return 0;  
}



Measured memory_bytes: 2128
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

int h,w,k,si,sj;
string g[1000];

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    cin>>h>>w>>k;
    rep(i,h) cin>>g[i];
    rep(i,h)rep(j,w)if(g[i][j]=='S') si=i,sj=j;

    int dis[h][w];
    rep(i,h)rep(j,w)dis[i][j]=INF;
    dis[si][sj]=0;

    priority_queue<pair<int,pair<int,int>>,vector<pair<int,pair<int,int>>>,
            greater<pair<int,pair<int,int>>>> que;
    que.push(make_pair(0,make_pair(si,sj)));
    while(!que.empty()){
        auto P=que.top();que.pop();
        int d=P.first,pi=P.second.first,pj=P.second.second;
        rep(i,4){
            int ni=pi+dx[i],nj=pj+dy[i];
            if(0<=ni and ni<h and 0<=nj and nj<w and g[ni][nj]=='.'){
                if(chmin(dis[ni][nj],d+1)){
                    que.push(make_pair(dis[ni][nj],make_pair(ni,nj)));
                }
            }
        }
    }

    // rep(i,h){
    //     rep(j,w){
    //         if(dis[i][j]>=INF) cout<<"I ";
    //         else cout<<dis[i][j]<<" ";
    //     }cout<<endl;
    // }

    rep(i,h){
        rep(j,w){
            if(i==0 or j==0 or i==h-1 or j==w-1){
                if(dis[i][j]<=k){
                    cout<<1<<endl;
                    return 0;
                }
            }
        }
    }

    rep(i,h){
        rep(j,w){
            if(dis[i][j]<=k){
                que.push(make_pair(0,make_pair(i,j)));
                dis[i][j]=0;
            }else{
                dis[i][j]=INF;
            }
        }
    }

    while(!que.empty()){
        auto P=que.top();que.pop();
        int d=P.first,pi=P.second.first,pj=P.second.second;
        rep(i,4){
            int ni=pi+dx[i],nj=pj+dy[i];
            if(0<=ni and ni<h and 0<=nj and nj<w){
                if(chmin(dis[ni][nj],d+1)){
                    que.push(make_pair(dis[ni][nj],make_pair(ni,nj)));
                }
            }
        }
    }


    // rep(i,h){
    //     rep(j,w){
    //         if(dis[i][j]>=INF) cout<<"I ";
    //         else cout<<dis[i][j]<<" ";
    //     }cout<<endl;
    // }

    int ans=INF;
    rep(i,h){
        rep(j,w){
            if(i==0 or j==0 or i==h-1 or j==w-1) chmin(ans,1+(dis[i][j]+k-1)/k);
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4352
# Problem https://atcoder.jp/contests/abc085/tasks/abc085_a
# Python 1st Try


def solver(errorDay):
    result = "2018/01/"
    day = errorDay[8:]
    #   print(day)
    result = result+day
    return result


if __name__ == "__main__":
    result = ""
    result = solver(input())
    print(result)


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

using namespace std;

int gcm(int m, int n) {
    if (m < n) {
        int w = m;
        m = n;
        n = w;
    }

    while (n != 0) {
        int w = m % n;
        m = n;
        n = w;
    }

    return m;
}

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

    int d = 0;
    for (int i = 0; i < n; i++) {
        int xi;
        cin >> xi;

        if (i == 0) {
            d = abs(x - xi);
        } else {
            d = gcm(d, abs(x - xi));
        }
    }

    cout << d << endl;
}


Measured memory_bytes: 256
def abc157_c():
  n, m = map(int, input().split())
  query = [tuple(map(int, input().split())) for _ in range(m)]

  # 推定される桁ごと、-1は未定
  digit = [-1] * n
  for s, c in query:
    # まだ決まっていなければ、当てはめる
    if digit[s-1] == -1:
      digit[s-1] = c
    # 決定済みの桁で、競合したらNG
    elif digit[s-1] != c:
      return -1

  # 1桁の場合、先頭ゼロでよい
  if n == 1:
    if digit[0] == -1: return 0
    return digit[0]
  # ここからは2桁以上の場合
  # 先頭が0は不正
  if digit[0] == 0: return -1
  # 最小値で埋める(先頭桁なので0はダメで1)
  elif digit[0] == -1: digit[0] = 1
  # 最小値で埋める
  if digit[1] == -1: digit[1] = 0
  if n == 3 and digit[2] == -1: digit[2] = 0
  # 数字に復元
  ans = 0
  for i in range(n):
    ans += (10**i) * digit[-(i+1)]
  return ans

ans = abc157_c()
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

struct UnionFind {
    int n;
    vector<int> rank;
    vector<int> parent;

    UnionFind(int n = 0) : n(n) {
        rank = vector<int>(n);
        parent = vector<int>(n);
        iota(parent.begin(), parent.end(), 0);
    }

    int find(int x) {
        return (parent[x] == x ? x : parent[x] = find(parent[x]));
    }

    void unite(int x, int y) {
        x = find(x); y = find(y);
        if(x == y)  return;

        if(rank[x] < rank[y])  swap(x, y);
        parent[y] = x;
        rank[x] += (rank[x] == rank[y]);
    }

    int count() {
        set<int> s;
        for(int i = 0; i < n; i++)  s.insert(find(i));
        return s.size();
    }
};

int main() {
    lint n;
    cin >> n;
    
    vector<lint> x(n), y(n);
    for(lint i=0; i<n; i++)  cin >> x[i] >> y[i];
    for(lint i=0; i<n; i++)  y[i] += 2e5;

    UnionFind vertex(4e5); // 0 <= x < 2e5, 2e5 <= y < 4e5
    for(lint i=0; i<n; i++)  vertex.unite(x[i], y[i]);

    map<lint, lint> vx, vy;
    for(lint i=0; i<4e5; i++) {
        lint root = vertex.find(i);
        (i < 2e5 ? vx[root] : vy[root])++;
    }

    set<lint> roots;
    for(auto e : x)  roots.insert(vertex.find(e));

    lint ans = 0;
    for(auto root : roots) {
        ans += vx[root] * vy[root];
    }

    cout << ans - n << endl;
}

Measured memory_bytes: 29952
H, W = map(int, input().split())
grid = []
d = [(1, 0), (0, 1)]
for _ in range(H):
    grid.append(input())
dp = [[0 for _ in range(W)] for _ in range(H)]
mod = 1e9 + 7
dp[0][0] = 1
for h in range(H):
    for w in range(W):
        if h > 0 and grid[h - 1][w] == '.':
            dp[h][w] = (dp[h][w] + dp[h - 1][w]) % mod
        if w > 0 and grid[h][w - 1] == '.':
            dp[h][w] = (dp[h][w] + dp[h][w - 1]) % mod
print(int(dp[H - 1][W - 1]))


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

using namespace std;

typedef long long ll;

const int N = 200100;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    vector<int> b = a;
    sort(b.begin(), b.end());
    int l = b[n / 2 - 1];
    int r = b[n / 2];
    for (int i = 0; i < n; ++i) {
        if (a[i] <= l) {
            cout << r << '\n';
        } else {
            cout << l << '\n';
        }
    }
    return 0;
}

Measured memory_bytes: 3840
#include <iostream>
#include <cstdlib>
#include <algorithm>
using namespace std;

int main() {
	int n;
	cin>>n;
	long long arr1[n];
	long long arr2[n];
	for(int i=0;i<n;i++){
	    int t1,t2;
	    cin>>t1>>t2;
	    arr1[i] = t1+t2;
	    arr2[i] = t1-t2;
	}
	sort(arr1,arr1+n);
	sort(arr2,arr2+n);
	int op1 = arr1[n-1]-arr1[0];
	int op2 = arr2[n-1]-arr2[0];
	cout<<max(op1,op2)<<endl;
	return 0;
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  string s, ans;
  cin >> s;
  if (s <= "2019/04/30") {
    ans = "Heisei";
  } else {
    ans = "TBD";
  }

  // string st = s.substr(0, 4) + s.substr(5, 2) + s.substr(8, 2);
  // int sti = atoi(st.c_str());
  // string ans;
  // if (sti <= 20190430) {
  //   ans = "Heisei";
  // } else {
  //   ans = "TBD";
  // }

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int X;
    cin>>X;
    cout<<1-X<<endl;
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int mod = 1e9 + 7;
const int MAX = 510000;

int main() {
    ll k; cin >> k;
    ll q = k / 50;
    ll r = k % 50;
    vl a(50);
    rep(i,r) a[i] = 50;
    REP(i,r,50) a[i] = 49-r;
    rep(i,50) a[i] += q;
    puts("50");
    rep(i,50) cout << a[i] << " ";
}

Measured memory_bytes: 256
#pragma warning( disable : 6031)

#include <stdio.h>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <math.h>
int minimum(int a, int b) { return a < b ? a : b; }
int maximum(int a, int b) { return a > b ? a : b; }
//const long long mod = 1000000007;
const long long mod = 998244353;
const double PI = 3.14159265358979323846;
using std::vector;
using std::pair;
using std::string;
using std::map;
using std::abs;
using std::priority_queue;

int main() {
	int N, M;
	scanf("%d %d", &N, &M);
	auto v = new vector<int>[N];
	for (int i = 0; i < M; i++) {
		int a, b;
		scanf("%d %d", &a, &b);
		a--;
		b--;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	vector<int> q;
	q.push_back(0);
	auto c = new int[N];
	for (int i = 0; i < N; i++)c[i] = -1;
	for (int i = 0; i < q.size(); i++) {
		int p = q[i];
		for (int j = 0; j < v[p].size(); j++) {
			int r = v[p][j];
			if (c[r] == -1) {
				c[r] = p;
				q.push_back(r);
			}
		}
	}
	printf("Yes\n");
	for (int i = 1; i < N; i++) {
		printf("%d\n", c[i] + 1);
	}
	return 0;
}

Measured memory_bytes: 10176
package main

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

var h int
var heap = make([]int, 2000000)

func main() {
	defer writer.Flush()
	for {
		cmd := ReadString()
		if cmd == "end" {
			return
		}
		switch cmd {
		case "end":
			return
		case "insert":
			insert(ReadInt())
		case "extract":
			Println(heapExtractMax())
		}
	}
}

const Inf = 1 << 62

func insert(key int) {
	h++
	heap[h] = -Inf
	heapIncreaseKey(h, key)
}

func heapIncreaseKey(i, key int) {
	if key < heap[i] {
		return
	}
	heap[i] = key
	for i > 1 && heap[i] > heap[i/2] {
		heap[i], heap[i/2] = heap[i/2], heap[i]
		i /= 2
	}
}

func heapExtractMax() int {
	if h < 1 {
		return -Inf
	}
	max := heap[1]
	heap[1] = heap[h]
	h--
	maxHeapify(1)
	return max
}

func maxHeapify(i int) {
	largest := i
	left := i * 2
	right := i*2 + 1
	if left <= h && heap[left] > heap[largest] {
		largest = left
	}
	if right <= h && heap[right] > heap[largest] {
		largest = right
	}
	if largest != i {
		heap[largest], heap[i] = heap[i], heap[largest]
		maxHeapify(largest)
	}
}

var writer = bufio.NewWriter(os.Stdout)

func Println(a ...interface{}) { fmt.Fprintln(writer, a...) }

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Buffer(make([]byte, 256), 1e9)
	sc.Split(bufio.ScanWords)
}

func ReadString() string { sc.Scan(); return sc.Text() }
func ReadInt() int {
	a, err := strconv.Atoi(ReadString())
	if err != nil {
		panic(err)
	}
	return a
}



Measured memory_bytes: 25832
n = int(input())
a = list(map(int,input().split()))
imos = [0]
for i in range(n):
    imos.append(imos[i]+a[i])
ans = 10**18
for i in range(n):
    ans = min(ans,abs(imos[i]-(imos[n]-imos[i])))
print(ans)

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

using namespace std;

using ll = long long;
const ll MOD = 1000000007;

vector<ll> fac(1000001); //n!(mod M)
vector<ll> ifac(1000001); //k!^{M-2} (mod M)


ll modpow(ll x, ll n) {
  x = x%MOD;
  if(n==0) return 1;  //再帰の終了条件

  else if(n%2==1) {
    return (x*modpow(x, n-1))%MOD;  //nが奇数ならnを1ずらす
  }
  else return modpow((x*x)%MOD, n/2)%MOD;  //nが偶数ならnが半分になる
}

ll comb(ll a, ll b){ //aCbをmod計算
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % MOD;
    return tmp * fac[a] % MOD;
}



int main(){
    ll N;
    cin >> N;
    cin.ignore();

    fac[0] = 1;
    ifac[0] = 1;

    for(ll i = 0; i<1000000; i++){
        fac[i+1] = fac[i]*(i+1) % MOD; // n!(mod M)
        ifac[i+1] = ifac[i]*modpow(i+1, MOD-2) % MOD; // k!^{M-2} (mod M) ←累乗にmpowを採用
    }

    ll sum = 0;
    for(ll p = 2; p <= N; p++){
        ll p2 = modpow(2, p);
        if(p2 < 2) p2 = p2 + MOD - 2;
        else p2 -= 2;

        ll right = (comb(N, p) * modpow(8, N - p)) % MOD;

        sum += (p2 * right) % MOD;
        sum %= MOD;
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 18688
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = 0
for i in range(n):
    ans += min(b[i], a[i]+a[i+1])
    a[i+1] = max(0, a[i+1]-max(0, b[i]-a[i]))
print(ans)

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

int
main(){
        int a,b,c;
        cin>>a>>b;
        for(int x=0;x<2;x++){
        	if(a>=b){
        		c=c+a;
        		a--;
        	}else{
        		c=c+b;
        		b--;
        	}
        }
        cout<<c<<endl;
        return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[][][] room = new int[4][3][10];
        int b,f,r,v;

        for (int i = 0; i < room.length; i++) {
            for (int j = 0; j < room[0].length; j++) {
                for (int k = 0; k < room[0][0].length; k++) {
                    room[i][j][k] = 0;
                }
            }
        }

        for (int i = 0; i < n; i++) {
            b = scan.nextInt();
            f = scan.nextInt();
            r = scan.nextInt();
            v = scan.nextInt();

            room[b -1][f -1][r -1] += v;
        }

        for (int i = 0; i < room.length; i++) {
            for (int j = 0; j < room[0].length; j++) {
                for (int k = 0; k < room[0][0].length; k++) {
                    System.out.print(" " + room[i][j][k]);
                }
                System.out.println();
            }
            if (i < room.length -1) {
                for (int a = 0; a < 20; a ++) {
                    System.out.print("#");
                }
                System.out.println();
            }
        }

    }
}

Measured memory_bytes: 29860
import java.util.Scanner;

public class Main {

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

		if (s.length() == 2) {
			System.out.println(0);
		} else {
			for (int i = s.length() - 2; i >= 2; i -= 2) {
				if (s.substring(0, i / 2).equals(s.substring(i / 2, i))) {
					System.out.println(s.substring(0, i).length());
					break;
				}
			}
		}
	}

}


Measured memory_bytes: 21844
s = list(input().split('/'))
s = [int(ss) for ss in s]

if s[0] < 2019:
  print("Heisei")
elif s[0] == 2019:
  if s[1] < 4 or (s[1] == 4 and s[2] <= 30):
    print("Heisei")
  else:
    print("TBD")
else:
  print("TBD")


Measured memory_bytes: 9156
N,D = map(int,input().split())

row = list()
count = 0
for i in range(N):
  x = [int(_) for _ in input().split()]
  if i == 0:
    row.append(x)
  else:
    for j in range(len(row)):
      dist = 0
      for k in range(D):
        dist += (row[j][k]-x[k])**2
      if (dist**0.5)-int(dist**0.5)==0:
      	count += 1
    row.append(x)
      
print(count)

Measured memory_bytes: 3188
#include <cstdio>
#include <utility>
#include <queue>
#include <map>
using namespace std;

#define F(X,Y) ((X)>>((Y-1)*2)&3)

typedef pair<int,int> P;

int main() {
	char st[10];
	while(scanf("%s",st),st[0]!='0') {
		queue<P> que;
		map<int,bool> mp;
		int x=0,d;
		for(d=0;st[d]!='\0';d++) {
			x<<=2;
			x|=st[d]=='r'?0:st[d]=='b'?1:2;
		}
		mp[x]=true;
		que.push(P(x,0));
		int ans=-1;
		while(!que.empty()) {
			P p=que.front();
			que.pop();
			x=p.first;
			bool b=true;
			for(int i=d;i>1;i--) {
				int t1=F(x,i),t2=F(x,i-1),t3=3-(t1+t2);
				if(t1==t2) continue;
				else b=false;
				int y=0;
				for(int j=d;j>0;j--) {
					y<<=2;
					y|=(j==i||j==(i-1))?t3:F(x,j);
				}
				if(!mp[y]) {
					mp[y]=true;
					que.push(P(y,p.second+1));
				}
			}
			if(b) {ans=p.second; break;}
		}
		printf(ans==-1?"NA\n":"%d\n",ans);
	}
}

Measured memory_bytes: 1696
N,X,D=map(int,input().split())
f,c,r={},[0]*10**8,0
for x,y,z in sorted((((N-k)*j+~-k)*k//2+k*X//D,j,k*X%D) if D else(0,j,k*(X!=0))for k in range(N+1)for j in[0,2]):
 if c[z]+y<1:
  f[z]=x
 r+=(x-f[z]+1)*(c[z]<y)
 c[z]-=y-1
print(r)

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) {
    cin >> a[i];
    --a[i];
  }
  int pos = 0;
  int cnt = 0;
  rep(i, n) {
    if (pos == 1) break;
    pos = a[pos];
    ++cnt;
  }
  if (pos == 1) cout << cnt << endl;
  else cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 3636
def main():
    a, b = tuple(map(int,input().split()))
    if a < b:
        (a, b) = (b, a)
        # a > b となるように並べ替え
    print(gcd(a, b))

def gcd(x, y):    
    
    if y == 0:
        return x
    else:
        return gcd(y, x%y)

if __name__ == '__main__':
    main()



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

ll N, K, t, d, sum, ans;
vector<ll> F, S;
vector<pair<ll, ll>> v;
map<ll, ll> mp;

main()
{
    cin >> N >> K;
    for (ll i = 0; i < N; i++)
    {
        cin >> t >> d;
        v.push_back(make_pair(t, d));
    }
    sort(v.rbegin(), v.rend());
    for (ll i = 0; i < v.size(); i++)
    {
        pair<ll, ll> p = v[i];
        if (mp[p.first] == 0)
            F.push_back(p.second);
        else
            S.push_back(p.second);
        mp[p.first]++;
    }
    sort(F.rbegin(), F.rend());
    sort(S.rbegin(), S.rend());
    ll L = F.size(), M = S.size();
    for (ll i = 0; i < min(K, L); i++)
        sum += F[i];
    if (K > L)
    {
        ll check = 0;
        for (ll i = 0; i < K - L; i++)
            sum += S[i], check = i;
        check++, ans = sum + L * L;
        for (ll j = L - 1; j > 0 && check < M; j--)
        {
            sum = sum - F[j] + S[check];
            check++;
            ans = max(ans, sum + j * j);
        }
        cout << ans << endl;
    }
    else
    {
        ans = sum + K * K;
        for (ll i = 0; i < K - 1 && i < M; i++)
        {
            sum -= F[K - 1 - i];
            sum += S[i];
            ans = max(ans, sum + (K - i - 1) * (K - i - 1));
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 8816
lst = [int(input()) for i in range(5)]
tmp = 99
idx = 0
ans = 0

for i in range(5):
    if lst[i] % 10 != 0 and tmp > lst[i] % 10:
        tmp = lst[i] % 10
        idx = i

for i in range(5):
    if i != idx:
        if lst[i] % 10 != 0:
            lst[i] += (10 - lst[i] % 10)
        ans += lst[i]


ans += lst[idx]
print(ans)


Measured memory_bytes: 38256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<deque>
#include<bitset>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
typedef long long ll;
typedef pair<ll,ll> P;
template<class T> inline bool chmax(T&a , T b){ if(a<b){ a=b; return true; } else{ return false; } }
template<class T> inline bool chmin(T&a , T b){ if(a>b){ a=b; return true; } else{ return false; } } 

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main(){
    string s;
    cin >> s;
    if(s=="ABC"){
        cout << "ARC" << endl;
    }else{
        cout << "ABC" << endl;
    }
}

Measured memory_bytes: 3592
M = int(input())
dc = [list(map(int,input().split())) for _ in range(M)]
ans = 0
s = 0
for i in dc:
  d = i[0]
  c = i[1]
  ans += c
  s+=d*c

ans -= 1
ans += (s-1)//9
print(ans)

Measured memory_bytes: 45356
/*There's a possibility*/
/*but stop sucking first*/
#define dbg(...) ; 
#define db(...) ; 
#include "bits/stdc++.h"
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define f(i,a,b) for(i=a;i<b;i++)
#define fr(i,a,b) for(i=a;i>=b;i--)
#define endl '\n'
#define tst cout<<'*';
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define pf push_front
using namespace std;

int main()
{
    fast;
    int n,i,j;
    cin>>n;
    int pts[3][n],dp[3][n];
    f(i,0,n)
        f(j,0,3)
            cin>>pts[j][i];

    f(i,0,1)
        f(j,0,3)
            dp[j][i]=pts[j][i];

    f(i,1,n)
        f(j,0,3)
            dp[j][i]=pts[j][i]+max(dp[(j+1)%3][i-1], dp[(j+2)%3][i-1]);


    cout<<max({dp[0][n-1],dp[1][n-1],dp[2][n-1]});
}

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

vector<int> height(999, 0);
void set(){
    for(int i = 0; i < 999; i++){
        for(int j = 1; j <= i + 1; j++){
            height[i] += j;
        }
    }
}

int main(){
    set();

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

    int ans = 1;
    while(true){
        a++;
        b++;
        //cout << "a:" << a << endl;
        for(int i = 0; i < 998; i++){
            if(a == height[i] && b == height[i + 1]){
                cout << ans << endl;
                return 0;
            }
        }
        ans++;
    }

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
  int H ,W;
  int i, j;
  while(1){
      scanf("%d %d" ,&H ,&W);
      if(H == 0 && W == 0) break;
      for ( i = 0; i < H; i++ ){
          for ( j = 0; j < W; j++ ){
              if(j==0||j==W-1||i==0||i==H-1){
                  printf("#");

              }else{
                  printf(".");
                  }
              }
          printf("\n");
     }
      puts("");
     }
  return 0;
  }


Measured memory_bytes: 2040
#include <iostream>

int main()
{
    int input;
    std::cin >> input;
    
    int h, m, s;
    h = m = s = 0;
    while (input >= 3600)
    {
        ++h;
        input -= 3600;
    }
    while (input >= 60)
    {
        ++m;
        input -= 60;
    }
    s = input;
    
    std::cout << h << ":" << m << ":" << s << std::endl;
    
    return 0;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
long long A,B,C,K;
int main(){
	cin>>A>>B>>C>>K;
	if(K<A){
		cout<<K<<'\n';
	}else if(K<A+B){
		cout<<A<<'\n';
	}else{
		cout<<A-(K-A-B)<<'\n';
	}
}

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

int main(){
    ll l,r;
    cin>>l>>r;
    ll ans=2020;
    if(r-l>=2019){
        cout<<0<<endl;
        return 0;
    }
    else {
         for(ll i=l;i<=r;i++){
        for(ll j=i+1;j<=r;j++){
            ll ung;
            ung=i*j%2019;
            ans=min(ans,ung);
        }
    }
    cout<<ans<<endl;
    
}
}

Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n = int(input())
    ab = [list(map(int, input().split())) for _ in range(n-1)]

    adj = [[] for _ in range(n)]
    order = []
    for a,b in ab:
        adj[a-1].append(b-1)
        order.append(b-1)

    

    c = [0]*n
    d = deque([0])
    while d:
        v = d.popleft()
        cnt = 1
        for nv in adj[v]:
            if c[v] == cnt:
                cnt += 1
            c[nv] = cnt
            cnt += 1
            d.append(nv)

    print(max(c))

    for i in order:
        print(c[i])

if __name__ == '__main__':
    main()

Measured memory_bytes: 43960
N,M = map(int,input().split())
AC = 0
penalty = 0
AC_list = [0]*N
WA_list = [0]*N

for i in range(M):
  p,s = map(str,input().split())
  p = int(p)-1
  if s == "AC" and AC_list[p] == 0:
    AC += 1
    AC_list[p] = 1
    penalty += WA_list[p]
  elif s == "WA":
    WA_list[p] += 1
  if AC == N:
    break
print(AC,penalty)

Measured memory_bytes: 4596
#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;
using ll = long long;

constexpr int s = 1 << 18;
int n, k, a[210000];
int main() {
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n; i++)
		scanf("%d", a + i);

	for (int i = 0; i < k; i++) {
		vector<int> imos(n+1, 0);
		for (int i = 0; i < n; i++)
			imos[max(0, i - a[i])]++, imos[min(n, i + a[i] + 1)]--;
		for (int i = 1; i < n; i++)
			imos[i] += imos[i - 1];
		bool c = false;
		for (int i = 0; i < n; i++)
			if (a[i] != imos[i])
				c = true, a[i] = imos[i];
		if (!c)
			break;
	}
	printf("%d",a[0]);
	for (int i = 1; i < n; i++)
		printf(" %d", a[i]);
	printf("\n");
}

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

int main(){
        ll n, tmp;
        scanf("%lld", &n);
        vector<ll> a(n);
        for(ll i=0; i<n; i++) scanf("%lld", &tmp), a[i]=tmp-i-1;
        sort(a.begin(), a.end());
        ll b = a[n/2], ans = 0;
        for(ll i: a) ans += abs(i-b);
        printf("%lld\n", ans);
        return 0;
}

Measured memory_bytes: 1792
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever for (;;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
template<typename A> using V = std::vector<A>;
template<typename A> using F = std::function<A>;
template<typename A, typename B> using P = std::pair<A, B>;
using pii = P<int, int>;
using vi = V<int>;
using vd = V<double>;
using vs = V<std::string>;
using vpii = V<pii>;
using vvi = V<vi>;
using vvpii = V<vpii>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> std::istream &operator>>(std::istream &is, std::pair<A, B> &p) { is >> p.first; is >> p.second; return is; }
using namespace std;
// clang-format on

template<typename Group> class FenwickTree {
  using T = typename Group::value_type;

  Group g;
  std::vector<T> tree; // 1-indexed
  int size;

public:
  FenwickTree(const int &n = 0) : size(n), g() { tree.assign(size + 1, g.id()); }

  T fold(int i) { // [0, i)
    T acc = g.id();
    for (; i; i -= i & -i) acc = g(acc, tree[i]);
    return acc;
  }

  T fold(const int &l, const int &r) { return g(fold(r), g.inv(fold(l))); } // [l, r)

  void add(int i, const T &x) {
    for (i++; i <= size; i += i & -i) tree[i] = g(tree[i], x);
  }

  void update(int i, const T &a) { add(i + 1, a - fold(i + 1, i + 2)); }
};

template<typename T> struct sumGroup {
  using value_type = T;
  constexpr T id() const { return 0; }
  T operator()(const T &a, const T &b) const { return a + b; }
  T inv(const T &x) const { return -x; }
};

main {
  int n, q;
  cin >> n >> q;
  FenwickTree<sumGroup<int>> t(n);
  while (q--) {
    int com, x, y;
    cin >> com >> x >> y;
    x--;
    if (com) {
      cout << t.fold(x, y) << endl;
    } else {
      t.add(x, y);
    }
  }
}

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

int main(){
	int A, B, C, D, E;
	cin >> A >> B >> C >> D >> E;
	int ans = (A + 9) / 10 * 10 + (B + 9) / 10 * 10 + (C + 9) / 10 * 10 + (D + 9) / 10 * 10 + (E + 9) / 10 * 10;
	ans -= max({ (A + 9) / 10 * 10 - A,(B + 9) / 10 * 10 - B ,(C + 9) / 10 * 10 - C ,(D + 9) / 10 * 10 - D ,(E + 9) / 10 * 10 - E });
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>

using namespace std;

#define C_MAX(a, b) ((a)>(b)?(a):(b))
#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

bool isOK(long long N, long long A, long long B, long long mid, vector<long long> h) {
    for (int i = 0; i < N; i++) h[i] -= (B * mid);
    long long count = 0;
    long long diff = A - B;
    for (int i = 0; i < N; i++) {
        if (h[i] > 0) {
            count += h[i] / diff;
            if (h[i] % diff) count++;
        }
    }
    return count <= mid;
}

int main() {

    long long N, A, B;
    cin >> N >> A >> B;

    vector<long long> h(N);
    for (int i = 0; i < N; i++) cin >> h[i];

    long long ng = -1LL;
    long long ok = 1000000001LL;

    while (abs(ok - ng) > 1) {
        long long mid = (ng + ok) / 2LL;
        if (isOK(N, A, B, mid, h)) ok = mid;
        else ng = mid;
    }

    cout << ok << endl;

    return 0;
}




















































































Measured memory_bytes: 1792
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
  //    String[] nyu=sc.nextLine().split(" ");

     String nyu=sc.nextLine();
//int[] num=new int[6];
//int A=Integer.parseInt(nyu[0]);
//int B=Integer.parseInt(nyu[1]);
//int C=Integer.parseInt(nyu);
//double A=Double.parseDouble(nyu[0]);
//double B=Double.parseDouble(nyu[1]);
/*
switch(C){
case 7:
case 5:
case 3:
System.out.println("YES") ;
break;
default:
System.out.println("NO") ;

break;
}
*/

nyu=nyu.replaceAll("1","e");
nyu=nyu.replaceAll("9","g");
nyu=nyu.replaceAll("e","9");
nyu=nyu.replaceAll("g","1");


System.out.println(nyu) ;

	}
}

Measured memory_bytes: 25172
N = int(input())
S = [list(input()) for _ in range(N)]
#N = 300
#S = [["a"]*N for _ in range(N)]
ans = 0

for A in range(N):
    if all([S[(i+A)%N][j] == S[(j+A)%N][i] for i in range(N) for j in range(i+1, N)]):
        ans += N
print(ans)

Measured memory_bytes: 120376
import java.util.*; 
class Main{
public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        long d=sc.nextLong();
  		int ans=0;

		for(int c=0;c<n;c++){
		long x=sc.nextLong();
        long y=sc.nextLong();
          if((x*x+y*y)<=(d*d)){
           ans++;
          }
    	}
    
 	

    	System.out.println(ans);
    }
}


Measured memory_bytes: 59204
#include <iostream>
#include <algorithm>
using namespace std;
long long n;
void solve()
{
    long long i,j,k,a[n],ans=0;
    for (i=0;i<n;i++)
        cin>>a[i];
    if (n<3) cout<<0;
    else
    {
        sort(a,a+n);
        for (i=0;i<n-2;i++)
            for (j=i+1;j<n-1;j++)
                for (k=j+1;k<n;k++)
                    if (!(a[i]==a[j]||a[j]==a[k]||a[i]==a[k]))
                    {
                        if (a[i]+a[j]>a[k]) ans++;
                    }
        cout<<ans;
    }
    cout<<endl;
}
int main()
{
    while(cin>>n)
        solve();
}

Measured memory_bytes: 3152
import sys


def get_ints(): return list(map(int, sys.stdin.readline().strip().split()))


def get_array(): return list(map(int, sys.stdin.readline().strip().split()))


def frog_1(arr, n, k):

    dp = [0] * (n + 1)
    dp[1] = 0

    for i in range(2, n+1):
        dp[i] = float("inf")
        for j in range(1, k+1):
            if i - j >= 1:
                dp[i] = min(dp[i], dp[i - j] + abs(arr[i - 1] - arr[i - j - 1]))

    return dp[n]


def vacation(mat, n):

    for i in range(1, n):
        for j in range(3):
            x = mat[i][j]
            for t in range(3):
                if t != j:
                    mat[i][j] = max(mat[i][j], mat[i - 1][t] + x)


    return max(mat[n - 1])



# n, k = get_ints()
# arr = get_array()

# sys.stdout.write(str(frog_1(arr, n, k)))

n = int(sys.stdin.readline())
mat = []

for i in range(n):
    mat.append(list(map(int, sys.stdin.readline().strip().split())))

sys.stdout.write(str(vacation(mat, n)))



Measured memory_bytes: 30596
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <unordered_map> 
#include <unordered_set>
#include <functional>
#include <bitset>

using namespace std;

typedef pair<long long int, long long int> P;
typedef tuple<int, int, int> T;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

#define MAX_V 200000

struct edge{
	int to;
	long long int cost;
    edge(int to_, long long int cost_){
        to = to_;
        cost = cost_;
    }
};

vector<edge> G[MAX_V];
long long int d1[MAX_V], d2[MAX_V];

// O(ElogV)

void shortest_path(int s, int V, long long int d[]){
	
	priority_queue<P, vector<P>, greater<P> > que;
	
	for(int i = 0; i < V; i++){
		d[i] = INF;
	}
	d[s] = 0;
	
	que.push(P(0, s));
	
	while(!que.empty()){
		
		P p = que.top();
		que.pop();
		
		int v = p.second;
		
		if(d[v] < p.first){
			continue;
		}
		
		for(int i = 0; i < G[v].size(); i++){
			edge e = G[v][i];
			if(d[e.to] > e.cost + d[v]){
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}

int main(){
	int N, u, v;
	cin >> N >> u >> v;
	for(int i = 0; i < N - 1; i++){
		int a, b;
		cin >> a >> b;
		G[a].emplace_back(b, 1);
		G[b].emplace_back(a, 1);
	}
	shortest_path(u, N + 1, d1);
	shortest_path(v, N + 1, d2);
	long long int ans = 0;
	for(int i = 1; i <= N; i++){
		if(d2[i] - d1[i] > 0){
			if(d1[i] % 2 == d2[i] % 2){
				ans = max(ans, d2[i] - 1);
			}else{
				ans = max(ans, d2[i] - 1);
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
  	long long int A,B,N;
  	cin>> A >> B >> N;
  	long long int ans=0;
  
  	if(B<=N){
     	ans= A-A/B-1; 
    }
  	else{
     	ans=A*N/B; 
    }
  	if(B==1) ans=0;
  	
  	cout<<ans<<endl;
}

Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define int long long
#define lint long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
typedef pair<int,int> P;
const lint inf=1e18+7;
const int MOD=1000000007;
int n,m,v,p;
bool judge(vector<int> const& a,int key){
    bool res=true;
    if(key<p){
        return true;
    }
    if(a[key]+m<a[p-1]){
        return false;
    }
    int rem=m*v;
    rem-=(n-key)*m;
    if(rem<=0){
        return true;
    }
    int sum=a[key]+m;
    for(int i=0;i<key;++i){
        if(i<p-1){
            rem-=m;
            continue;
        }
        rem-=sum-a[i];
    }
    return rem<=0;
}
signed main(){
    cin>>n>>m>>v>>p;
    vector<int> a(n);
    rep(i,n){
        cin>>a[i];
    }
    sort(a.begin(),a.end());
    reverse(ALL(a));
    rep(i,n){
        //cout<<a[i]<<" ";
    }
    //cout<<endl;
    int d=0;int u=n;
    while(u-d>1){
        int mid=(u+d)/2;
        if(judge(a,mid)){
            d=mid;
        }
        else{
            u=mid;
        }
    }
    cout<<u<<endl;
    return 0;
}

Measured memory_bytes: 1024