akhauriyash/Code-Regression huggingface dataset:
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define pb            push_back
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>

const int INF = 1e9;

// code
// ------------------------------------------------
int main() {

  int n,m;
  cin >> n >> m;
  cout << (n - 1) * (m - 1);
  return 0;
}

// funcの実体
// ------------------------------------------------
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 256
#include <iostream>

#define max(X,Y) ((X > Y)?X:Y)

int main(void)
{
	while(true)
	{
		int n;
		int m=0,prev=0;
		std::cin >> n;
		if(!n)
			break;

		m = prev = -1000001;
		for(int i=0; i<n; i++)
		{
			int a;
			std::cin >> a;
			prev = max( a, prev + a );
			m = max( m, prev );
		}
		std::cout << m << std::endl;
	}
	return 0;
}

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

#define ll             long long
#define LL             long long
#define pii            pair<int, int>
#define pll            pair<ll, ll>
#define pil            pair<int, ll>
#define pli            pair<ll, int>
#define vi             vector<int>
#define vl             vector<ll>
#define vii            vector<pii>
#define vll            vector<pll>
#define vil            vector<pil>
#define vli            vector<pli>
#define pb             push_back
#define ppb            pop_back
#define mp             make_pair
#define ff             first
#define ss             second
#define sz(x)          (int)x.size()
#define TN             typename
#define all(v)         v.begin(), v.end()
#define fill(a, b)     memset(a, b, sizeof(a))
#define endl           '\n'

template <TN T> T gcd(T a, T b) {return !b ? a : gcd(b, a % b);}
template <TN T> T lcm(T a, T b) {return a * (b / gcd(a, b));}
template <TN T> T sqr(T a) {return a * a;}
template <TN T> T cube(T a) {return a * a * a;}
template <TN T> inline void smin(T &a, T b) {a = a < b ? a : b;}
template <TN T> inline void smax(T &a, T b) {a = a > b ? a : b;}

template <TN T> inline void Int(T &n) {
	n = 0; int f = 1; register int ch = getchar();
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
	for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';
	n = n * f;
}

#define error(args...) {vector <string> _v = split(#args, ','); err(_v.begin(), args); cout << endl;}
vector <string> split(const string &s, char c) {
	vector <string> v;
	stringstream ss(s); string x;
	while (getline(ss, x, c)) v.emplace_back(x);
	return move(v);
}
void err(vector <string> :: iterator it) {}
template <typename T, typename... Args>
void err(vector <string> :: iterator it, T a, Args... args) {
	cout << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << ", ";
	err(++it, args...);
}

inline int in() {int n; scanf("%d", &n); return n;}
inline ll Lin() {ll n; scanf("%lld", &n); return n;}
inline double Din() {double n; scanf("%lf", &n); return n;}

inline int add(int a, int b, int mod) {a += b; return a >= mod ? a - mod : a;}
inline int sub(int a, int b, int mod) {a -= b; return a < 0 ? a + mod : a;}
inline int mul(int a, int b, int mod) {return (ll)a * b % mod;}

const int N          = 3e3 + 5;
const ll  Mod        = (ll)1e9 + 7;
const int inf        = (int)2e9;
const ll  Inf        = (ll)1e18;
const int mod        = (int)1e9 + 7;

ll dp[N][N];

int solve() {
	int n = in();
	vl a(n + 1);
	for (int i = 1; i <= n; i++) {
		a[i] = Lin();
	}
	for (int l = n; l >= 1; l--) {
		for (int r = l; r <= n; r++) {
			if (l == r) dp[l][r] = a[l];
			else dp[l][r] = max(a[l] - dp[l + 1][r], a[r] - dp[l][r - 1]);
		}
	}
	printf("%lld\n", dp[1][n]);
	return 0;
}

int main() {
	int test = 1, tc = 0;
	//scanf("%d", &test);
	while (test--) {
		//printf("Case %d: ", ++tc);
		solve();
	}
	return 0;
}





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

int main()
{
    int n;
    cin >> n;
    int sum = 0;
    for (int i = 0; i < n; i++) {
        int l, r;
        cin >> l >> r;
        sum += r - l + 1;
    }
    cout << sum << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }


//FUNCTION
int fn(int X)
{
  string str = to_string(X);
  int res = 0;
  for (int i = 0; i < str.size(); i++)
  {
    res += str[i] - '0';
  }
  res += X;
  return res;
}
void solve(void)
{
  int A,B;
  cin>>A>>B;
  A--;
  int ANS = 0;
  for (int i = 0; i < 40;i++) 
  {
    int k = 1LL<<(i+1);
    int nA = (A/k)*(k/2) + max(A%k - (k/2-1),0LL);
    int nB = (B/k)*(k/2) + max(B%k - (k/2-1),0LL);
    int c = nB - nA;
    if(c%2 == 1)
    {
      ANS |= (1LL<<i);
    }
    // DEBUG(A,B,nA,nB,c,"\n");
  }
  cout<<ANS<<endl;
    
  return;
}

int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(15);
  solve();

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long ans;
int main() {
    int N, K; cin >> N >> K;
    for(int i = 0; i < N; i++) {
        int h; cin >> h;
        if(h >= K) ans++;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (true) {
            int n = scanner.nextInt();
            if (n == 0) {
                break;
            }
            int max = 0;
            int[] x = { -1, 0, 1, -1 };
            int[] y = { -1, -1, -1, 0 };
            int[][][] map = new int[n + 1][n + 2][4];
            for (int i = 1; i <= n; i++) {
                char[] line = scanner.next().toCharArray();
                for (int j = 1; j <= n; j++) {
                    if (line[j - 1] == '1') {
                        for (int k = 0; k < 4; k++) {
                            max = Math.max(max, map[i][j][k] = map[i + y[k]][j + x[k]][k] + 1);
                        }
                    }
                }
            }
            System.out.println(max);
        }
    }
}


Measured memory_bytes: 47912
#include<stdio.h>

int S[1000000], N, k = 0;

int binarySearch(int X){
  int left = 0;
  int right = N;
  int middle;
  
  while(left < right){
    middle = (left + right) / 2;
    if(X == S[middle]){
      return 1;
    }
    else if(X > S[middle]){
      left = middle + 1;
    }
    else {
      right = middle;
    }
  }
  return 0;
}

int main() {
  int M, i, x,count = 0 ;
  
  scanf("%d", &N);
  for(i = 0; i < N; i++){
    scanf("%d", &S[i]);
  }
  
  scanf("%d", &M);
  for(i = 0; i < M; i++){
      scanf("%d", &x);
      if(binarySearch(x) == 1){
        count += 1;
      }
  }
  
  printf("%d\n",count);
  
  return 0;
}

Measured memory_bytes: 2076
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
#define CONTAINS_SET(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }


int tower[1001];


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

	for (int i = 1; i < 1000; i++)
	{
		for (int j = 1; j <= i; j++)
		{
			tower[i] += j;
		}
	}

	for (int i = 1; i < 1000 - 1; i++)
	{
		int yuki = tower[i] - a;
		if (yuki > 0)
		{
			int x = tower[i] - yuki;
			int y = tower[i + 1] - yuki;

			if (x == a && y == b)
			{
				cout << yuki << endl;
			}
		}
	}
}



Measured memory_bytes: 3176
def study_time(h1, m1, h2, m2, k):
    result = (h2 - h1) * 60 + m2 - m1 - k
    return result

h1, m1, h2, m2, k = tuple(map(int, input().split()))

if __name__ == '__main__':
    print(study_time(h1, m1, h2, m2, k))

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

int main() {
    int N, M; cin >> N >> M;
    vector<int> g1[N], g2[N];
    for (int i=0; i<M; i++){
        int s, t; cin >> s >> t;
        g1[s-1].push_back(t-1);
        g2[t-1].push_back(s-1);
    }
    queue<int> q;
    for (int i=0; i<N; i++){
        if (g2[i].size() == 0){
            q.push(i);
        }
    }
    vector<int> D(N);
    for (int i=0; i<N; i++){
        D[i] = 0;
    }
    int checked[N];
    for (int i=0; i<N; i++){
        checked[i] = 0;
    }
    int p;
    while (q.size()){
        p = q.front(); q.pop();
        for (int np : g1[p]){
            D[np] = max(D[np], D[p]+1);
            checked[np] += 1;
            if (checked[np] == g2[np].size()){
                q.push(np);
            }
        }
    }
    cout << *max_element(D.begin(), D.end()) << endl;
}

Measured memory_bytes: 11904
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define max0(a,b,c) max(max(a,b),c)
#define min0(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
using Graph = vector<vector<int>>;
typedef long long lint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldouble;
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<ull> ulvec;
typedef vector<double> dvec;
typedef vector<pair<int,int>> pvec;
typedef vector<pair<ll,ll>> plvec;
typedef vector<tuple<ll,ll,ll>> tvec;
typedef vector<string> svec;

int main(){
    ull n,m,ans=0;
    cin>>n;
    m=n;
    if(n%2!=0) cout<<0<<endl;
    else{
        rep(i,27){
            ull s=1;
            for(int j=0;j<=i;j++) s*=5;
            if(n/s!=0){
                ull k=n/s;
                k/=2;
                ans+=k;
            }
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int A,B,C,coin,day;;
    coin=0;
    day=0;
    cin>>A>>B>>C;
    while(1){
       if(coin>=C){
           break;
       } 
       coin=A+coin;
       day=day+1;
       if(day%7==0){
           coin=coin+B;
       }
    }
    cout<<day<<endl;
}



Measured memory_bytes: 3116
#include <iostream>

using namespace std;

int main(){
  int n;
  cin >> n;
  int a[n];
  int count[n] = {0};
  int button;
  int ans = 0;
  
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  
  button = a[0];
  count[0]++;
  ans++;
  while(1){
    if(button == 2){
      cout << ans << endl;
      return 0;
    }
    
    count[button - 1]++;
    if(count[button - 1] > 1){
      cout << -1 << endl;
      return 0;
    }
    
    button = a[button - 1];
    ans++;
  }
}

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

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

int main() {
    int K;
    cin >> K;
    int A,B,C,Z,ans=0;
    for (int i=1 ; i<K+1 ; i++){
        for (int j=1 ; j<K+1 ; j++){
            for (int k=1 ; k<K+1 ; k++){
                A=i,B=j,C=k;
                Z=X(A , B);
                ans+=X(Z , C);
            }
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 3624
def main():
    from sys import stdin, setrecursionlimit
    setrecursionlimit(10**6)
    r = stdin.readline()[:-1]
    #n = int(stdin.readline()[:-1])   
    #r = [stdin.readline() for i in range(n)]
    #t = [int(stdin.readline()) for i in range(n)]

    res = 0
    a, b = map(int, r.split())
    print(max(a+b,a-b,a*b))

if __name__ == '__main__':
    main()



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

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


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
cnt = 0
for a in range(1,N+1):
    cnt += N // a
    if N % a == 0:
        cnt -= 1
print(cnt)    

Measured memory_bytes: 63228
import numpy as np


if __name__ == "__main__":
    n = int(input())
    a = np.array(list(map(int, input().split())))
    mod = 10**9+7

    memo = np.zeros(n+10, dtype=int)
    memo[0] = 3
    ans = 1
    for i in a:
        mae = memo[i]
        now = memo[i+1]
        ans *= mae-now
        ans %= mod

        memo[i+1] += 1

    print(ans)


Measured memory_bytes: 23348
#include<iostream>
using namespace std;
int main(){
  long long  sum,temp,min;
  cin>>sum>>min;
  for(int i=0;i<4;i++){
    cin>>temp;
    if (temp<min) min=temp;
  }
  cout<<4+(sum+min-1)/min<<endl;
  return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<vector<int>> A(N, vector<int>(N));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) cin >> A[i][j];
    }
    
    ll mod = 1e9+7;
    vector<vector<ll>> dp(N+1, vector<ll>((1<<N), 0));
    dp[0][0] = 1;
    for (int i = 1; i <= N; i++) {
        for (int j = 0; j < (1<<N); j++) {
            if (__builtin_popcount(j) != i) continue;
            for (int k = 0; k < N; k++) {
                if (((j>>k)&1) == 0) continue;
                if (A[i-1][k] == 0) continue;
                dp[i][j] += dp[i-1][j-(1<<k)];
                dp[i][j] %= mod;
            }
        }
    }
    cout << dp[N][(1<<N)-1] << endl;
    return 0;
}

Measured memory_bytes: 380260
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

int main(void){
    vector<string> dir;
    {
        string str; cin >> str;
        str.push_back('.');
        int p = 1;
        int np;
        while((np = str.find('.', p)) != string::npos){
            dir.push_back(str.substr(p, np - p));
            p = np + 1;
        }
    }
    int len = dir.size();

    cin.ignore();

    int depth = 0;
    string in;
    int correct = -1;
    int pbcnt = 0;
    vi brs = {0};
    while(getline(cin, in)){
        int bcnt = 0;
        while(in[bcnt] == ' ') bcnt++;
        if(bcnt > brs.back()) depth++, brs.push_back(bcnt);
        while(bcnt < brs.back()){
            brs.pop_back();
            depth--;
        }

        if(correct >= depth) correct = depth - 1;

        stringstream ss(in);
        string obj; ss >> obj;

        obj.pop_back();
        if(correct == depth - 1 and dir[depth] == obj){
            correct = depth;
            if(correct == len - 1){
                int si = in.find(':') + 2;
                if(si >= in.size()){
                    cout << "object" << endl;
                }
                else {
                    string name = in.substr(in.find(':') + 2);
                    cout << "string \"" << name << "\"" << endl;
                }
                return 0;
            }
        }
    }

    cout << "no such property" << endl;

    return 0;
}

Measured memory_bytes: 3272
/*
    Mbak Sana Dong
    Mbak Chaeyoung Dong
*/
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    int n,i,j,k,x,y,ans,curr,temp,m;
    int tc;
    int d;
    cin >> n;
    ans = 0;
    for(i=1;i<=n;i++) {
        cin >> curr;
        if(i%2==1 && curr%2==1) ans++;
    }
    cout <<ans << endl;
    return 0;
}


Measured memory_bytes: 3592
#include<stdio.h>
int n,i,u,v,ea[2<<17],eb[2<<17],next[2<<17],first[1<<17];
long M,dp1[1<<17],dp2[1<<17],L[2<<17]={1},R[2<<17]={1};
int dfs1(int u,int p)
{
	dp1[u]=1;
	int id=first[u];
	while(id)
	{
		if(eb[id]!=p)
		{
			dfs1(eb[id],u);
			dp1[u]=dp1[u]*(dp1[eb[id]]+1)%M;
		}
		id=next[id];
	}
}
int make(int,int,long,long);
int dfs2(int u,int p,long x)
{
	x%=M;
	dp2[u]=dp1[u]*x%M;
	make(first[u],p,x%M,0L);
	int id=first[u];
	L[id]=x;
	while(id)
	{
		if(eb[id]!=p)
		{
			dfs2(eb[id],u,(L[id]%M*R[next[id]]%M+1)%M);
		}
		id=next[id];
	}
}
int make(int id,int p,long x,long t)
{
	if(id>0)
	{
		L[id]=x%=M;
		t=eb[id]!=p?(dp1[eb[id]]+1)%M:1;
		make(next[id],p,t*x%M,0L);
		R[id]=R[next[id]]*t%M;
	}
}
main()
{
	scanf("%d%ld",&n,&M);
	for(i=0;~scanf("%d%d",&u,&v);)
	{
		i++;
		ea[i]=u;
		eb[i]=v;
		i++;
		ea[i]=v;
		eb[i]=u;
	}
	for(i=1;i<2*n;i++)
	{
		next[i]=first[ea[i]];
		first[ea[i]]=i;
	}
	dfs1(1,-1);
	dfs2(1,-1,1L);
	for(i=1;i<=n;i++)printf("%ld\n",dp2[i]%M);
}

Measured memory_bytes: 12288
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;

namespace AtCoderContest
{
    class Program
    {
        static void Main()
        {
            var nums = Console.ReadLine()
                              .Split(" ")
                              .Select(long.Parse)
                              .ToList();
            var (x, k, d) = (nums[0], nums[1], nums[2]);

            var absX = Math.Abs(x);
            if (new BigInteger(k) * new BigInteger(d) <= absX)
            {
                Console.WriteLine(absX - k * d);
            }
            else
            {
                if ((k - absX / d) % 2 == 0)
                {
                    Console.WriteLine(absX % d);
                }
                else
                {
                    Console.WriteLine(Math.Abs(absX % d - d));
                }
            }
        }
    }
}


Measured memory_bytes: 28500
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pl = pair<ll,ll>;
using pi = pair<int,int>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
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; }
//(a+b-1)/b
//priority_queue<ll, vector<ll>, greater<ll>> q;

signed main(){
	//cout << fixed << setprecision(10);
    int n,k; cin >> n >> k;
	string s; cin >> s;
    vector<pi> vec(0);
    int f = (s[0] == '0' ? 1 : 0);
    int cnt = 0;
    rep(i,0,n){
        int g = (s[i] == '0' ? 1 : 0);
        if(f != g){
            vec.push_back(make_pair(cnt , f));
            f = g;
            cnt = 0;
        }
        cnt++;
    }
    if(cnt != 0)vec.push_back(make_pair(cnt , f));
    int ans = 0;
    int memo = 0;
    int ind = 0;
    cnt = 0;
    if(vec.size() == 1){
        cout << n << endl;
        return 0;
    }
    rep(i,0,vec.size()){
        cnt += vec[i].second;
        while(cnt > k){
            cnt -= vec[ind].second;
            memo -= vec[ind].first;
            ind++;
        }
        memo += vec[i].first;
        chmax(ans , memo);
    }
    chmax(ans , memo);
    cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4476
package main

import (
	"fmt"
)

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func main() {
	var A, B int
	fmt.Scan(&A, &B)
	if A%2 != B%2 {
		fmt.Println("IMPOSSIBLE")
		return
	}
	K := (A + B) / 2
	if abs(A-K) != abs(B-K) {
		fmt.Println("IMPOSSIBLE")
		return
	}
	fmt.Println(K)
}


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

int main()
{
  int W, H, x, y, r;

  cin >> W >> H >> x >> y >> r;

  if(0 <= x-r && x+r <= W && 0 <= y-r && y+r <= H)
    {
      cout << "Yes" << endl;
    }else
    {
      cout << "No" << endl;
    }
  return 0;
}

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

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	int L, N;
	cin >> N >> L;
	string s[110];
	for (int i = 0; i < N; i++)
		cin >> s[i];
	sort(s, s + N);
	for (int i = 0; i < N; i++)
		cout << s[i];

}

Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
    	int w = sc.nextInt();
      	int a = sc.nextInt();
      	int b = sc.nextInt();
      	if(Math.abs(a-b) <= w) System.out.println(0);
      	else System.out.println(Math.abs(a-b)-w);
	}
}

Measured memory_bytes: 35760
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int n,m;
int xx[1001];int yy[1001];
int main()
{
	cin>>n>>m>>xx[1]>>yy[1];
	int x=xx[1];
	int y=yy[1];
	for(int i=2;i<=n+1;i++)
	{
		cin>>xx[i];
	}
	for(int i=2;i<=m+1;i++)
	{
		cin>>yy[i];
	}
	sort(xx+1,xx+2+n);
	sort(yy+1,yy+2+m);
		if(xx[n+1]<yy[1]&&x<y)
		{
			cout<<"No War";
			return 0;
		}
	cout<<"War";
	return 0;
}

Measured memory_bytes: 256
/*
	2440:Kagisys
*/
#include	<iostream>
#include	<string>

using namespace std;

int main(void) {
	int N, M;
	string IDs[256];
	bool oc = false;
	
	cin >> N;
	for(int i = 0; i < N; i++) {
		string buff;
		
		cin >> buff;
		IDs[i] = buff;
	}
	cin >> M;
	for(int i = 0; i < M; i++) {
		string buff;
		bool isHit = false;
		
		cin >> buff;
		for(int j = 0; j < N; j++) {
			if(IDs[j] == buff) {
				isHit = true;
				break;
			}
		}
		if(isHit == true) {
			if(oc == false) {
				cout << "Opened by " << buff << endl;
				oc = true;
			} else {
				cout << "Closed by " << buff << endl;
				oc = false;
			}
		} else {
			cout << "Unknown " << buff << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1220
# -*- coding: utf-8 -*-
import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect


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


def z():
    return int(sys.stdin.readline())


def S():
    return sys.stdin.readline()


def C(line):
    return [sys.stdin.readline() for _ in range(line)]


D = z()
C = zz()
S = defaultdict(list)
for i in range(D):
    S[i + 1] = zz()
# やらなくていいコンテストはやらないC=0
never_held = []

arr = list(range(26))
C, arr = zip(*sorted(zip(C, arr), reverse=True))
for i in range(D):
    print(arr[i % 26]+1)


Measured memory_bytes: 27472
import sys
sys.setrecursionlimit(2147483647)
INF = float("inf")
MOD = 10**9 + 7 # 998244353
input = lambda:sys.stdin.readline().rstrip()
from functools import lru_cache
def resolve():
    n = int(input())
    A = list(map(int, input().split()))

    dp = [[None] * (n + 1) for _ in range(n + 1)]
    for i in range(n + 1):
        dp[i][i] = 0

    for width in range(1, n + 1):
        for l in range(n):
            r = l + width
            if r > n:
                break
            turn = (n - (r - l)) & 1
            if turn & 1 == 0:
                dp[l][r] = max(A[l] + dp[l + 1][r], A[r - 1] + dp[l][r - 1])
            else:
                dp[l][r] = min(-A[l] + dp[l + 1][r], -A[r - 1] + dp[l][r - 1])


    print(dp[0][n])
resolve()

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

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

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

	int ans = 0;
	for (int i = 0; i <= n - 1; ) {

		int cnt = 0;
		int j;
		for ( j = i; ; j++) {
					
			if (n <= j + 1) break;

			if (h[j] >= h[j + 1]) {	
				cnt++;
			}
			else {
				break;
			}		
		}
		
		i = j + 1;
		ans = max(ans, cnt);

	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main(void){
	int x,y;
	while(1){
	scanf("%d %d",&x,&y);
		if(x==0 && y==0){
			break; 
		}else
	 if(x<y){
		printf("%d %d\n",x,y);
	}else if(x>y){
		printf("%d %d\n",y,x);
	}else{
		printf("%d %d\n",x,y);
	}
	}
	return 0;
}

Measured memory_bytes: 596
import heapq
from collections import defaultdict
x, y, z, K = map(int, input().split())
a = sorted(list(map(int, input().split())))[::-1]
b = sorted(list(map(int, input().split())))[::-1]
c = sorted(list(map(int, input().split())))[::-1]

used = defaultdict(bool)
pq = [(-(a[0] + b[0] + c[0]), 0, 0, 0)]
used[(0, 0, 0)] = True
heapq.heapify(pq)

for _ in range(K):
    d, i, j, k = heapq.heappop(pq)
    print(-d)
    if i + 1 < x and not used[(i + 1, j, k)]:
        heapq.heappush(pq, (-(a[i + 1] + b[j] + c[k]), i + 1, j, k))
        used[(i + 1, j, k)] = True
    if j + 1 < y and not used[(i, j + 1, k)]:
        heapq.heappush(pq, (-(a[i] + b[j + 1] + c[k]), i, j + 1, k))
        used[(i, j + 1, k)] = True
    if k + 1 < z and not used[(i, j, k + 1)]:
        heapq.heappush(pq, (-(a[i] + b[j] + c[k + 1]), i, j, k + 1))
        used[(i, j, k + 1)] = True


Measured memory_bytes: 10720
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<cstring>

using namespace std;
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define P pair<int, int>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x) << endl

/*-- template --*/
int N;
vector<vector<int>>G;
vector<int> bfs(int root) {
    vector<int> dist(N, INF);
    dist[root] = 0;
    queue<int>Q;
    Q.push(root);
    while(!Q.empty()) {
        int q = Q.front();Q.pop();
        for(int i : G[q]) {
            if(dist[i] == INF) {
                dist[i] = dist[q] + 1;
                Q.push(i);
            }
        }
    }
    return dist;
}

int main() {
    cin >> N;
    G.resize(N);
    rep(i, N - 1) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        G[a].pb(b), G[b].pb(a);
    }
    vector<int>dist1 = bfs(0);
    vector<int>distN = bfs(N - 1);
    int scoreFenec = 0, scoreSnuke = 0;
    rep(i, N) {
        ++((dist1[i] <= distN[i]) ? scoreFenec : scoreSnuke);
    }
    cout << ((scoreFenec > scoreSnuke) ? "Fennec" : "Snuke") << endl;
}


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

using namespace std;
#define ll long long


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

    int q;
    string s;

    cin >> s >> q;

    bool qt = 0;
    vector<char> add[2];    
    while(q--) {
        int t;
        cin >> t;

        if(t == 1) {
            qt = !qt;
        } else {
            int f;
            char c;
            cin >> f >> c; 
            f--;
            add[f^qt].push_back(c);
        }
    }
    string t;
    for(int i = (int)add[0].size()-1; i >= 0 ; i--) {
        t += add[0][i];
    }
    t += s;

    for(char c : add[1])
        t += c;
    if(qt)
        reverse(t.begin(), t.end());
    cout << t << endl;


    return 0;
}

Measured memory_bytes: 1448
// #pragma GCC target("avx")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
// #define BEGIN_STACK_EXTEND(size) void * stack_extend_memory_ = malloc(size);void * stack_extend_origin_memory_;char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);*stack_extend_dummy_memory_ = 0;asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
// #define END_STACK_EXTEND asm volatile("mov %%rax, %%rsp"::"a"(stack_extend_origin_memory_));free(stack_extend_memory_);

#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<unordered_map>
#include<complex>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-11;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 11100000;
const int UF_SIZE = 3100000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	inline long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
	int UF[UF_SIZE];
	void init_UF(int n){
		for(int i=0;i<n;i++)UF[i]=-1;
	}
	int FIND(int a){
		if(UF[a]<0)return a;
		return UF[a]=FIND(UF[a]);
	}
	void UNION(int a,int b){
		a=FIND(a);b=FIND(b);if(a==b)return;
		if(UF[a]>UF[b])swap(a,b);
		UF[a]+=UF[b];UF[b]=a;
	}
}
// ここから編集しろ

int main(){
	int a;scanf("%d",&a);
	if(a>=30)printf("Yes\n");else printf("No\n");
}

Measured memory_bytes: 1620
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

typedef long double ld;
typedef long long ll;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const ld eps = 1e-9;
const ld pi = acos((ld) -1.0);

const int mod = (int) 1e9 + 7;

void add(int &x, int y) {
  if ((x += y) >= mod) {
    x -= mod;
  }
}

int mult(int x, int y) {
  return (long long) x * y % mod;
}

int power(int x, int pw) {
  int res = 1;
  for (; pw; pw >>= 1) {
    if (pw & 1) {
      res = mult(res, x);
    }
    x = mult(x, x);
  }
  return res;
}

void precalc() {
}


int n, k;

int read() {
  if (scanf("%d%d", &n, &k) < 2) {
    return 0;
  }
  return 1;
}

const int maxn = (int) 2e3 + 10;
const int maxv = maxn * maxn;
int inv[maxv];
int cs[maxv];

int dp[maxn][maxn];

void solve() {
  if (k == 1) {
    printf("1\n");
    return;
  }
  inv[1] = 1;
  for (int i = 2; i <= n * k; ++i) {
    inv[i] = mult(mod - mod / i, inv[mod % i]);
  }

  for (int i = 0; i < k - 2; ++i) {
    cs[i] = 0;
  }
  cs[k - 2] = 1;
  for (int i = k - 1; i <= n * k; ++i) {
    cs[i] = mult(mult(cs[i - 1], i), inv[i - k + 2]);
  }

  for (int left = 0; left <= n; ++left) {
    for (int t = 0; t + left <= n; ++t) {
      int &cur = dp[left][t];
      cur = 0;
      if (!left && !t) {
        cur = 1;
        continue;
      }

      if (t) {
        add(cur, mult(dp[left][t - 1], cs[(left + t) * k - t - 1]));
      }

      if (left) {
        add(cur, dp[left - 1][t + 1]);
      }
      //eprintf("dp[left=%d][t=%d] = %d\n", left, t, cur);
    }
  }
  int res = dp[n][0];
  for (int i = 1; i <= n; ++i) {
    res = mult(res, i);
  }
  printf("%d\n", res);
}

int main() {
  precalc();
#ifdef LOCAL
  freopen(TASK ".out", "w", stdout);
  assert(freopen(TASK ".in", "r", stdin));
#endif

  while (1) {
    if (!read()) {
      break;
    }
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 47488
#define ll long long
#define ffor(i,a,b) for (int i=(a);i<(b);i++)
#define rfor(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define rep(i,n) for (int i=0;i<(n);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#define SIZE 100001
#define MOD 1000000007
#define INF 100000000
using namespace std;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,l;
	cin >> n >> l;
	string data[100];
	rep(i,n){
		cin >> data[i];
	}
	sort(data,data+n);

	rep(i,n){
		cout << data[i];
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(100000)

def gcd(a, b):
    r = a % b
    if r == 0:
        return b
    else:
        return gcd(b, r)

T = int(input())
for i in range(T):
    a, b, c, d = list(map(int, input().split()))

    if a < b:
        print("No")
        continue

    if b > d:
        print("No")
        continue

    if c >= b: # d >= b
        print("Yes")
        continue

    diff = d % b
    if diff == 0:
        if a % b <= c:
            print("Yes")
            continue
        else:
            print("No")
            continue

    g = gcd(b, diff)

    init_mod = c % b

    base_mod = init_mod % g
    if b + base_mod - g > c:
        print("No")
    else:
        print("Yes")


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;

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

int main(){
    int R;
    cin >> R;
    if (R < 1200) {
        cout << "ABC";
    } else if (R <2800) {
        cout << "ARC";
    } else {
        cout << "AGC";
    }
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		String s=sc.nextLine();
      	int count=0;int tmp=0;
      	String ATCG[]={"A","C","G","T"};
      	for( String atcg:ATCG){
          s=s.replace(atcg,"0");
        }
      	for(int i=0;i<s.length();i++){
         if(s.charAt(i)=='0'){
           tmp+=1;
         }else{
           count=Math.max(tmp,count);
           tmp=0;
         }
        }
        count=Math.max(tmp,count);
		System.out.println(count);
		
		
	}
}


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

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

int main() {
	ll A,B,Q,x;
	cin >> A >> B >> Q;
	vector<ll> s(A+2),t(B+2);

	s.at(0)=-INF, s.at(A+1)=INF;
	rep(i,A)
		cin >> s.at(i+1);
	sort(s.begin(), s.end());

	t.at(0)=-INF, t.at(B+1)=INF;
	rep(i,B)
		cin >> t.at(i+1);
	sort(t.begin(), t.end());

	rep(i,Q) {
		ll ws,es,wt,et,l,r,m,d=INF;
		cin >> x;

		l=0,r=A;
		while(l <= r) {
			m = (l+r)/2;
			if(x > s.at(m))
				l = m+1;
			else if(x < s.at(m))
				r = m-1;
			else {
				l=m,r=m;
				break;
			}
		}
		r = max(min(A+1,r), 0ll);
		l = max(min(A+1,l), 0ll);
		ws=s.at(r), es=s.at(l);

		l=0,r=B;
		while(l <= r) {
			m = (l+r)/2;
			if(x > t.at(m))
				l = m+1;
			else if(x < t.at(m))
				r = m-1;
			else {
				l=m,r=m;
				break;
			}
		}
		r = max(min(B+1,r), 0ll);
		l = max(min(B+1,l), 0ll);
		wt=t.at(r), et=t.at(l);

		if(ws < wt)
			d = min(d,x-ws);
		else
			d = min(d,x-wt);
		if(es < et)
			d = min(d,et-x);
		else
			d = min(d,es-x);
		d = min(d,(x-ws)*2+et-x);
		d = min(d,(x-wt)*2+es-x);
		d = min(d,(es-x)*2+x-wt);
		d = min(d,(et-x)*2+x-ws);

		cout << d << endl;
	}
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

using i64=int64_t;

void solve(){
    i64 N,A,B;
    cin >> N >> A >> B;
    vector<i64> h(N);
    rep(i,0,N) cin >> h[i];

    auto ok=[&](i64 x){
        auto h_=h;
        rep(i,0,N) h_[i]-=x*B;
        i64 cnt=0;
        rep(i,0,N) if(h_[i]>0) cnt+=(h_[i]+(A-B)-1)/(A-B);
        return cnt<=x;
    };

    i64 lb=0,ub=inf+1;
    while(ub-lb>1){
        i64 mid=(lb+ub)/2;
        if(ok(mid)) ub=mid;
        else lb=mid;
    }
    cout << ub << endl;
}

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


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> q(N);
  for(int i = 0; i < N; i++) {
    cin >> q.at(i);
  }
  int s = 0;
  for(int i = 0; i < N; i++){
    for(int j = 0; j < N; j++){
      if(!(i == j)) {
        s += q.at(i) * q.at(j);
      }
    }
  }
  cout << s / 2 << endl;
}

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

int main() {
    vector<int> v(1e6 + 1);
    for (int i = 0; i <= 1e6; ++i) {
        v[i] = i;
    }
    for (int i = 3; i <= 1e6; i += 3) {
        v[i] = 0;
    }
    for (int i = 5; i <= 1e6; i += 5) {
        v[i] = 0;
    }
    long long sum = 0;
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        sum += v[i];
    }
    cout << sum << endl;
    return 0;
}

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

const ll MAX = 1000000;
const ll MOD = 1000000007;

ll fac[MAX];

// テーブルを作る前処理
/*
void COMinit() {
    fac[0] = fac[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
    }
}
*/

ll pow_kai(ll a,ll n){//aのn乗を計算します。
  ll x = 1;
  while(n > 0){//全てのbitが捨てられるまで。
    if(n&1){//1番右のbitが1のとき。
      x = x*a%MOD;
    }
    a = a*a%MOD;
    n >>= 1;//bit全体を右に1つシフトして一番右を捨てる。
  }
  return x;
}

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    ll tmp=1;
    for(ll i=n;i>=n-k+1;i--) tmp = (tmp*i)%MOD;

    return (tmp * pow_kai(fac[k],MOD-2)) % MOD;
}



int main()
{
    ll N,K;
    cin >> N >> K;

    ll bit[N],d,A;

    rep(i,N) bit[i]=1;

    rep(i,K){
        cin >> d;
        rep(j,d){
            cin >> A;
            bit[A-1] =0;
        }
    }

    ll ans=0;

    rep(i,N) ans+=bit[i];

        cout << ans << endl;

 
    return 0;

}

Measured memory_bytes: 3640
#pragma region
#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
typedef long long ll;
#define tr t[root]
#define lson t[root << 1]
#define rson t[root << 1 | 1]
#define rep(i, a, n) for (long long i = a; i <= n; ++i)
#define per(i, a, n) for (long long i = n; i >= a; --i)
#define IO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
template <typename T>
void read(T &x) {
    x = 0;
    char ch = getchar();
    ll f = 1;
    while (!isdigit(ch)) {
        if (ch == '-') f *= -1;
        ch = getchar();
    }
    while (isdigit(ch)) {
        x = x * 10 + ch - 48;
        ch = getchar();
    }
    x *= f;
}
using namespace std;
/*
 *                                                     __----~~~~~~~~~~~------___
 *                                    .  .   ~~//====......          __--~ ~~
 *                    -.            \_|//     |||\\  ~~~~~~::::... /~
 *                 ___-==_       _-~o~  \/    |||  \\            _/~~-
 *         __---~~~.==~||\=_    -_--~/_-~|-   |\\   \\        _/~
 *     _-~~     .=~    |  \\-_    '-~7  /-   /  ||    \      /
 *   .~       .~       |   \\ -_    /  /-   /   ||      \   /
 *  /  ____  /         |     \\ ~-_/  /|- _/   .||       \ /
 *  |~~    ~~|--~~~~--_ \     ~==-/   | \~--===~~        .\
 *           '         ~-|      /|    |-~\~~       __--~~
 *                       |-~~-_/ |    |   ~\_   _-~            /\
 *                            /  \     \__   \/~                \__
 *                        _--~ _/ | .-~~____--~-/                  ~~==.
 *                       ((->/~   '.|||' -_|    ~~-/ ,              . _||
 *                                  -_     ~\      ~~---l__i__i__i--~~_/
 *                                  _-~-__   ~)  \--______________--~~
 *                                //.-~~~-~_--~- |-------~~~~~~~~
 *                                       //.-~~~--\
 *                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 */

#pragma endregion
const int maxn = 1e5 + 5;
ll n, W, w[maxn], val[maxn], dp[maxn];
int main() {
    IO;
    cin >> n >> W;
    rep(i, 1, n) cin >> w[i] >> val[i];
    rep(i, 1, n) for (int t = W; t >= w[i]; --t) dp[t] = max(dp[t], dp[t - w[i]] + val[i]);
    cout << dp[W] << endl;
}

Measured memory_bytes: 3964
Bingo = [list(map(int, input().split())) for _ in range(3)]
for i in range(int(input())):
    b = int(input())

    for j in range(3):
        for k in range(3):
            if Bingo[j][k] == b:
                Bingo[j][k] = 0

ans = 'No'

for i in range(3):
    if Bingo[i][0] == Bingo[i][1] == Bingo[i][2]:
        ans = 'Yes'
    if Bingo[0][i] == Bingo[1][i] == Bingo[2][i]:
        ans = 'Yes'

if Bingo[0][0] == Bingo[1][1] == Bingo[2][2]:
    ans = 'Yes'
if Bingo[2][0] == Bingo[1][1] == Bingo[0][2]:
    ans = 'Yes'

print(ans)
    

Measured memory_bytes: 9228
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
#define ll long long
#define MAX 500500
#define lson (now<<1)
#define rson (now<<1|1)
inline int read()
{
    int x=0;bool t=false;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
    if(ch=='-')t=true,ch=getchar();
    while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
    return t?-x:x;
}
int n,K;
struct Line{int v,next;}e[MAX<<1];
int h[MAX],cnt=1,dg[MAX];
inline void Add(int u,int v){e[cnt]=(Line){v,h[u]};h[u]=cnt++;dg[v]++;}
int a[MAX],P[MAX],ans[MAX],tot;
int t[MAX<<2];
priority_queue<int,vector<int>,greater<int> >Q;
void Modify(int now,int l,int r,int p,int w)
{
    if(l==r){t[now]=w;return;}
    int mid=(l+r)>>1;
    if(p<=mid)Modify(lson,l,mid,p,w);
    else Modify(rson,mid+1,r,p,w);
    t[now]=min(t[lson],t[rson]);
}
int Query(int now,int l,int r,int L,int R)
{
    if(L>R)return t[0];
    if(l==L&&r==R)return t[now];
    int mid=(l+r)>>1;
    if(R<=mid)return Query(lson,l,mid,L,R);
    if(L>mid)return Query(rson,mid+1,r,L,R);
    return min(Query(lson,l,mid,L,mid),Query(rson,mid+1,r,mid+1,R));
}
void Topsort()
{
    for(int i=1;i<=n;++i)if(!dg[i])Q.push(i);
    while(!Q.empty())
    {
        int u=Q.top();Q.pop();ans[u]=++tot;
        for(int i=h[u];i;i=e[i].next)
            if(!--dg[e[i].v])Q.push(e[i].v);
    }
}
int main()
{
    n=read();K=read();
    for(int i=1;i<=n;++i)a[P[i]=read()]=i;
    memset(t,63,sizeof(t));
    for(int i=n;i;--i)
    {
        int x=Query(1,1,n,a[i]+1,min(a[i]+K-1,n));
        if(x<1e9)Add(a[i],a[x]);
        x=Query(1,1,n,max(1,a[i]-K+1),a[i]-1);
        if(x<1e9)Add(a[i],a[x]);
        Modify(1,1,n,a[i],i);
    }
    Topsort();
    for(int i=1;i<=n;++i)printf("%d\n",ans[i]);
    return 0;
}

Measured memory_bytes: 28928