akhauriyash/Code-Regression huggingface dataset:
MOD = 1000000007

def prime_fact(n)
  #素因数分解
  i = 2
  while i ** 2 <= n do
    cnt = 0
    while n % i == 0
      cnt += 1
      n /= i
    end

    @map[i] = cnt if cnt > 0 && (@map[i] == nil || @map[i] < cnt)
    i += 1
  end

  @map[n] = 1 if n != 1 && @map[n] == nil
end

def power(n, a, m)
  res = 1

  if a > 0
    res = power(n, a / 2, m)
    if a % 2 == 0
      res = (res * res)
    else
      res = ((res * res) * n)
    end
  end
  
  return res
end

def main
  n = gets.chomp.to_i
  a = gets.chomp.split.map(&:to_i)

  @map = {}

  a.each do |v|
    prime_fact(v)
  end

  gcd = 1
  @map.map { |v, k|
    gcd *= power(v, k, MOD)
  }

  ans = 0
  a.each do |v|
    ans += (gcd / v)
  end

  puts ans % MOD
end

main

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

int main(){
    int n;
    cin >> n;
    while(n != 0){
        vector < int > s(n);
        int min = 1001;
        int max = -1;
        int total = 0;
        for(int i = 0 ; i < n ; i++){
            cin >> s[i];
            if(s[i] < min){
                min = s[i];
            }
            if(s[i] > max){
                max = s[i];
            }
            total += s[i];
       }

       cout << (total-min-max)/(n-2) << endl;
       cin >> n;
    }
}


Measured memory_bytes: 3008
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
#include <cstring>

#define roop(i, n) for(int i=0;i<n;i++)

using namespace std;
using ll = long long int;
using ull = unsigned long long;

constexpr ull mod = 1e9+7;
constexpr int N = 13;
ull dp[100010][N];

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

int main() {
	int x,i;
	cin >> x;
	//=======================================
	// 解法1　品物の個数を決め打ち
	// 入力値(合計金額)：x円
	// 品物の個数は
	// 入力値を100で割ったときの整数部分個だけである。
	// (例)　615円　→　6個のもので構成されているはず。
	// なぜなら、100円～105円のもので購入していくので
	// 615円のものを作るにはどれかを6個買わないと作れない.
	// この品物の個数をC個とする。
	// すると、C = (x / 100)と表すことができる
	// このCを100倍した値～105倍した値の中に
	// 入力値x円があれば1を
	// なければ0を出力すれば今回の答えとなる。
	// 例：x = 615円
	// C=>6個
	// C*100 => 600
	// C*105 => 630
	// 600 <= x(=615) <= 630なので、1
	// 例：x = 217円
	// c=>2個
	// c*100 => 200
	// c*105 => 210
	// 200 <= 210 <= x(=217)なので、0
	//=======================================
	int itemCount = x / 100;
	if (itemCount*100 <= x && x <= itemCount*105) {
		cout << "1" << endl;
	} else {
		cout << "0" << endl;
	}
	return 0;
}

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

#define INF 1000000007
#define LINF 1000000000000000007

using namespace std;

typedef long long Int;
typedef pair<Int, Int> P;

Int gcd(Int x, Int y){
	if(y == 0)
		return x;
	return gcd(y, x % y);
}

Int lcm(Int x, Int y){
	return x * y / gcd(x, y);
}

bool sosuu(int x){
	bool b = 1;
	if(x == 1) b = 0;
	for(int i = 2; i * i <= x; i++){
		if(x % i == 0) {
			b = 0;
			break;
		}
	}
	return b;
}

int n, a[100];

int main(){
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	
	sort(a, a+n);
	int c[2] = {0};
	for(int i = 0; i < n; i++){
		c[i%2] += a[n-i-1];
	}
	cout << c[0] - c[1] << endl;
	
	return 0;
}

Measured memory_bytes: 256
// Input macro
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// Test Code
macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
    "2\n2" => "6",
    "5\n15" => "1",
}

fn main() {
    println!("{}", solve(&stdin!()));
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        k: isize,
        s: isize,
    }

    let mut ans = 0;

    for x in 0..k + 1 {
        for y in 0..k + 1 {
            let z = s - x - y;

            if 0 <= z && z <= k {
                ans += 1;
            }
        }
    }

    ans.to_string()
}

Measured memory_bytes: 4352
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long

int gcd(int a, int b) {
    if (a < b) return gcd(b, a);
    if (b == 0) return a;
    return gcd(b, a % b);
}
map<int, char> mp;
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    string S, T;
    cin >> S >> T;
    if (N < M) {
        swap(N, M);
        swap(S, T);
    }
    int L = N * M / gcd(N, M);
    rep(i, N) mp[L/N * i] = S[i];
    rep(i, M) {
        if (mp.find(L/M * i) == mp.end()) continue;
        if (mp[L/M * i] != T[i]) {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << L << endl;

    return 0;
}
// L = 6
// N = 6
// 1, 2, 3, 4, 5, 6
// M = 3
// 1, 3, 5


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

using namespace std;

long long K;
long long A[101010];

int main() {
  cin >> K;
  for (int i = 0; i < K; i++) cin >> A[i];

  reverse(A, A + K);

  if (A[0] != 2) {
    cout << -1 << endl;
    return 0;
  }

  long long mx = 2, mn = 2;
  for (int i = 0; i < K; i++) {
    mx = mx - (mx % A[i]) + A[i] - 1;
    mn = A[i] * ((mn + A[i] - 1) / A[i]);
  }

  reverse(A, A + K);

  long long tmx = mx, tmn = mn;
  for (int i = 0; i < K; i++) {
    tmx = A[i] * (tmx / A[i]);
    tmn = A[i] * (tmn / A[i]);
  }

  if (tmx != 2 && tmn != 2) {
    cout << -1 << endl;
  } else {
    cout << mn << " " << mx << endl;
  }

  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define endl '\n'
#define int long long
int32_t  main()
{
    IOS;  
    int X;
    cin>>X;  
    int ans=0;
    int curr=100;
    while(curr<X)
    {
        ans++;
        curr+=curr/100;
    }
    cout<<ans;  
}

Measured memory_bytes: 3636
#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
    int N;
    int i;
    do
    {
        cin >> N;
    } while (N < 1 && N > 100);
    int A[N];
    for (i = 0; i < N; i++)
    {
        do
        {
            cin >> A[i];
        } while (A[i] < 1 && A[i] > 1000);
    }
    for (i = 0; i < N; i++)
    {
        if (A[i] % 2 == 0)
        {
            if (A[i] % 3 != 0 && A[i] % 5 != 0)
            {
                break;
            }
        }
    }
    if (i == N)
    {
        cout << "APPROVED" << endl;
    }
    else
    {
        cout << "DENIED" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#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>

using namespace std;

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

template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main() {
  int n;

  while(1) {
    cin >> n;
    if(!n) break;

    REP(i, n) {
      int pm, pe, pj;
      cin >> pm >> pe >> pj;
      if(pm == 100 || pe == 100 || pj == 100) cout << 'A' << endl;
      else if((pm+pe)/2 >=90) cout << 'A' << endl;
      else if((pm+pe+pj)/3 >= 80) cout << 'A' << endl;
      else if((pm+pe+pj)/3 >= 70) cout << 'B' << endl;
      else if(((pm+pe+pj)/3 >= 50) && (pm >= 80 || pe >= 80)) cout << 'B' << endl;
      else cout << 'C' << endl; 
    }
  }
}

Measured memory_bytes: 1156
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int m = scan.nextInt();
        scan.close();

        if(n == m) System.out.println("Yes");
        else System.out.println("No");
    } 
}

Measured memory_bytes: 21588
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE

void test(){
  for(Int i=1;i<=64;i++){
    if(i % 2) continue;
    for(Int k=2;k<=64;k*=2) {
      if(i <= k-i) cout<<i<<" "<<abs(k-i)<<endl;
    }
  }
  
}

signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);
  
  Int n;
  cin>>n;
  vector<Int> A(n);
  cin>>A;
  map<Int,Int> num;
  for(Int a:A) num[a]++;
  
  sort(A.begin(), A.end(), greater<Int>());
  A.erase(unique(A.begin(), A.end()), A.end());
  
  Int ans = 0;
  for(int a:A){
    int flag = 0;
    for(int i=0;i<32;i++){
      Int target = 1LL<<i;
      Int b = target - a;
      if(b > a || b <= 0) continue;
      if(num[a] == 0 || num[b] == 0) continue;
      if(b == a) {flag++, ans += num[a]/2, num[a] %= 2; continue;}
      else{
	int score = min(num[a], num[b]);
	flag++;
	ans += score;
	num[b] -= score;
	num[a] -= score;
      }
    }
  }

  cout<<ans<<endl;
  

  
  return 0;
}


Measured memory_bytes: 26880
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = 1e9 + 7;
signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    while(cin >> n, n)
    {
        char table[n + 1][n + 1];
        int dp[n + 1][n + 1] = {};
        for(int i = 1; i <= n; i++)
        {
            for(int j = 1; j <= n; j++)
            {
                cin >> table[i][j];
                dp[i][j] = (table[i][j] == '.' ? 1 : 0);
            }
        }
        int ans = 0;
        for(int i = 1; i <= n; i++)
        {
            for(int j = 1; j <= n; j++)
            {
                if(table[i][j] == '*') continue;
                dp[i][j] = min({dp[i - 1][j - 1], dp[i - 1][j], dp[i][j - 1]}) + 1;
                ans = max(ans, dp[i][j]);
            }
        }
        cout << ans << endl;
    }
    return 0;
}




Measured memory_bytes: 7928
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


int main(){
    ll X;
    cin >> X;

    ll t = 0;
    ll p = 0;
    while(p < X){
        t++;
        p += t;
    }

    cout << t << endl;

    return 0;
}

Measured memory_bytes: 3588
n, m = [int(item) for item in input().split()]
x = [int(item) for item in input().split()]

x = sorted(x)
for i in range(1, m):
  x[i-1] = x[i] - x[i-1]
x[-1] = 10**6

x = sorted(x)
ans = 0
for i in range(m-n):
  ans += x[i]
  
print(ans)

Measured memory_bytes: 13840
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <climits>

long table[2000+1][2000+1]={};
long MOD=1000000000+7;
void init(long S)
{
  for(long i=3; i<=S; i++){
    table[1][i]=1;
  }
}

void solve(long S)
{
  for(long i=2; i<=S; i++){
    for(long j=3;j<=S; j++){
      table[i][j] = table[i][j-1]+table[i-1][j-3];
      table[i][j]%=MOD;
    }
  }
}

int main(){
  long S;
  std::cin >> S;
  init(S);
  solve(S);
  long sum=0;
  for(long i=1; i<=S; i++){
    sum+=table[i][S];
    sum%=MOD;
  }
  
  std::cout << sum << std::endl;
  return 0;
}

Measured memory_bytes: 34464
#include <stdio.h>

int main(){
  int c=0,d=0;
  char S[10];
  scanf("%s",S);
  for(int i=0;i<3;i++){
    if(S[i]=='R'){
      c++;
      if(d<c) d=c;
    }else{
      c=0;
    }
  }
  printf("%d\n",d);
  return 0;
}


Measured memory_bytes: 1728
/*..............................................*\
Author:Kishor Kumar Paroi
Dept:CSE-1703053
email.kishor.josephite@gmail.com
RUET,BANGLADESH
\*---------------------------*/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
#include <sstream>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include<bits/stdc++.h>
#include<iostream>
#include<iterator>

#define max(a,b) ((a>b)?a:b)                        //finding max
#define min(a,b) ((a<b)?a:b)                        //finding min
#define Max(a,b,c) max(a,max(b,c))                  //finding max between 3 numbers
#define Min(a,b,c) min(a,min(b,c))                  //finding min between 3 numbers
#define Pi acos(-1.0)                               //defining Pi for mathematical uses
#define Clear(a) memset(a,0,sizeof(a))              //clearing memory of an array
#define setfalse(a) memset(a,false,sizeof(a))       //setting the array into false
#define settrue(a) memset(a,true,sizeof(a))         //setting the array into true
#define clrstr(a) memset(a,'\0',sizeof(a))          //setting string array to null
#define open freopen("input.txt","r",stdin)         //opening input file
#define close freopen ("output.txt","w",stdout)     //opening output file
#define Case(a) printf("Case %d: ",a)               //printing case number
#define caseh(a) printf("Case #%d: ",a)             //printing case number having '#'
#define getcase(a) scanf("%d",&a)                   //scanning case number
#define caseloop(a,b) for(a=1;a<=b;a++)             //making case loop
#define EPS 1e-9                                    //small value for avoiding preccesion error
#define LL long long                                //long long short form
#define fori(i,n) for(int i=1;i<=n;++i)
#define forn(i,n) for(int i=0;i<n;++i)
#define sz(x) int(x.size())
#define error(x) cout<<#x<<" "<<x<<endl
#define IOS  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)

//const int N=100*1000;
//const int mod=1e9+7;

//# define int min3(int a,int b,int c){return min(a,min(b,c));}
//#define int max3(int a,int b,int c){return max(a,max(b,c));}
//#define int min4(int a,int b,int c,int d){return min(min(a,b),min(c,d));}
//#define int max4(int a,int b,int c,int d){return max(max(a,b),max(c,d));}

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

     string s;
     cin>>s;
     int i,cnt=0,temp=0;
     for(i=0;i<s.size();i++)
     {
         if(s[i]=='A'||s[i]=='T'||s[i]=='C'||s[i]=='G')
            temp++;
         else
            temp=0;
            cnt=max(cnt,temp);
     }
     cout<< cnt <<endl;

    return 0;
}



Measured memory_bytes: 256
/*
problem's name:
statue:
writer:Chris
*/
#include <iostream>
#include <map>
#include <vector>
#include <cstring>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <string>
#include <stack>
#include <set>
#include <deque>
#include <cctype>
#include <sstream>
#include <math.h>
#include <stdio.h>
#include <time.h>
#define mp make_pair
typedef long long ll;
using namespace std;
const int INF=1e9;
/*------------main part------------*/
inline ll read()
{
    ll 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<<3)+(x<<1)+ch-'0';ch=getchar();}
    return x*f;
}
int a[100005];
vector<int> v;
int main()
{
	int n,k;
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	int sum=INF;
	for(int i=1;i+k-1<=n;i++)
	{
		int j=i+k-1;
		int cnt=INF;
		cnt=min(cnt,(abs(0-a[j])+abs(a[i]-a[j])));
		cnt=min(cnt,(abs(0-a[i])+abs(a[i]-a[j])));
		sum=min(sum,cnt);
	}	
	cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 640
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
cnt=1
lst=[]
for i in range(1,n):
    if a[i]==a[i-1]:
        cnt+=1
    else:
        lst.append(cnt)
        cnt=1
lst.append(cnt)
lst.sort()
if k>=len(lst):
    print(0)
else:
    count=0
    for i in range(len(lst)-k):
        count+=lst[i]
    print(count)

Measured memory_bytes: 85328
/* 
	Author: ankrypt
*/


#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

ll N, M;
ll temp;
ll arr[35][35];
ll hashCnt[35];
std::vector<ll> temps[35];
ll sz;

int main() {
	scanf("%lld %lld", &N, &M);
	for(int i = 0; i < N; i++) {
		scanf("%lld", &sz);
		for(int j = 0; j < sz; j++) {
			scanf("%lld", &temp);
			temps[i].push_back(temp);
			// cout << temps[i][j] << " ";
		}
	}
	// cout << "\n";
	for(int i = 0; i < N; i++) {
		// cout << temps[i].size() << "this\n";
		for(int j = 0; j < temps[i].size(); j++) {
			hashCnt[temps[i][j]]++;
			// cout << temps[i][j] << " ";
		}
	}
	// cout << "\n";
	ll cnt = 0;
	for(int i = 1; i <= M; i++) {
		// cout << hashCnt[i] << " ";
		if(hashCnt[i] == N) {
			cnt++;
		}
	}

	printf("%lld\n", cnt);
	return 0;
}
/*
	Powered by Buggy Plugin
*/ 


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            var sts = new string[] { "1100000011", "1000000010000000100000001", "1111", "1000000110000001", "11000000011", "100000001100000001", "110000011" };
            do
            {
                string s = "";
                for (int i = 0; i < 8; i++)
                {
                    s += Console.ReadLine().Replace(Environment.NewLine, "");
                }
                for(int i = 0; i < sts.Length; i++)
                {
                    string st = sts[i];
                    if (s.Contains(st)) Console.WriteLine((char)('A' + i));
                }
            }
            while (Console.ReadLine() != null);
        }
    }
}

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

int main() {
	int n;
	cin >> n;
	if (n%2) cout << 2*n << endl;
	else cout << n << endl;
	return 0;
}


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

#define infile "../test/sample-1.in"
#define int long long
// #define INF 2147483647
#define INF 1000000000000000000LL
#define MOD 1000000007LL

// {{{ define basic macro
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)

#define foreach(x,a) for(auto& (x) : (a) )
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)

#define all(x) (x).begin(),(x).end()
#define sum(v) accumulate(all(v), 0)
#define sz(x) ((int)(x).size())
template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }
// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
#define fill(x,y) memset(x,y,sizeof(x))
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ten(n) ((int)1e##n)

template <class T = int>
T in() {T x; cin>>x; return (x);}

struct Fast {
  Fast(){
    std::cin.tie(0);
    ios::sync_with_stdio(false);
  }
} fast;
// }}}
//{{{ dump macro
#ifdef PCM
  #include "dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}
//{{{ others
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;
template<typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;

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

int n,M;
int x[100000]={};

int dfs(int i, int pos, const auto& G){
  if (x[i]==INF){  // not reached
    x[i] = pos;
    foreach(p, G[i]){
      dfs(p.first, pos + p.second, G);
    }
  }
  return 0;
}

int solve(){
  cin>>n>>M;
  if (M==0){ cout << "Yes" << endl; return 0; }
  int l[M],r[M],d[M];
  rep(i, n){ x[i]=INF; }
  vector<vector<pii>> G(n);
  rep(i, M){
    cin>>l[i]>>r[i]>>d[i];
    l[i]--;r[i]--;
    G[l[i]].pb(mp(r[i], d[i]));
    G[r[i]].pb(mp(l[i], -d[i]));
  }

  rep(i, n){
    dfs(i, 0, G);
  }
  dump_1d(x, n);

  rep(m, M){
    if (x[r[m]] - x[l[m]] != d[m]){
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
  return 0;
}

int test(){ //{{{
  return 0;
}
//}}}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
#ifdef PCM
  test();
#endif
  solve();
  return 0;
} //}}}


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

int main(){
  int n; cin >>n;
  vector<int> a(n);
  rep(i,n) cin >>a[i];
  sort(a.begin(), a.end());
  int cnt = 0;
  rep(i,n){
    rep(j,i){
      rep(k,j){
        if(a[k]!=a[j]&&a[j]!=a[i]&&a[k]+a[j]>a[i]) cnt++;
      }
    }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 3644
#include<iostream>
#include<cmath>
typedef long long ll;
#define f first
#define s second
#define pb push_back

using namespace std;

int main(void){

    int a, b;
    cin>>a>>b;
    int ans = 0, boards = 1;

    while(boards < b){
         --boards;
        boards += a;
        ans++;
    }

    cout << ans << "\n";
    
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    bool flag = false;
    rep(i, n) {
        cin >> a[i];
        if (a[i] > i || (i > 0 && a[i - 1] + 1 < a[i])) {
            flag = true;
        }
    }
    if (flag) {
        puts("-1");
        return 0;
    }
    ll todo = 0, ans = 0;
    for (int i = n - 1; i >= 0; i--) {
        if (todo < a[i]) {
            todo = a[i];
            ans += a[i];
        }
        if (todo > 0) todo--;
    }
    cout << ans << endl;
}


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

using namespace std;

typedef long long  ll;
typedef vector<ll> VL;
typedef pair<ll,ll> PLL;
#define fr(i,x,y) for(ll i=x;i<y;i++)
#define inf 1000*1000*1000+5
const ll mod=998244353;

vector<VL> adj;
VL ans;
map<PLL,ll> mp;
void bfs(int i,int p,int ct,VL visit)
{
	if(p<i)
	{
		if(!mp.count({p,i}))
		{
			mp[{p,i}]=ct;
		}
		else
		{
			ll x=mp[{p,i}];
			mp[{p,i}]=min(x,(ll)ct);
		}
		//ans[ct]++;
	}
	visit[i]=1;
	for(auto j: adj[i])
	{
		if(visit[j]==0)
		{
			bfs(j,p,ct+1,visit);
		}
	}
}
void solve()
{
	ll n,x,y;
	cin>>n>>x>>y;
	x--,y--;

	ans.assign(n,0);
	fr(i,0,n)
	{
		VL temp(n,0);
		ll ct=0;
		fr(j,i,n)
		{
			temp[j]=ct++;
		}
		// ct=0;
		// for(int j=i;j>=0;j--)
		// {
		// 	temp[j]=ct++;
		// }
		if(i<y)
		{
			ll dist=abs(x-i);
			dist++;
			ll pav=dist;
			fr(j,y,n)
			{
				temp[j]=min(temp[j],dist);
				dist++;
			}
			
			dist=pav+1;
			for(int j=y-1;j>=x;j--)
			{
				temp[j]=min(dist,temp[j]);
				dist++;
			}
			
		}	
		// cout<<i<<endl;
		// fr(i,0,n)
		// 	cout<<temp[i]<<" ";
		// cout<<"\n";
		fr(i,0,n)
		{
			ans[temp[i]]++;
		}
	}
	fr(i,1,n)
	{
		cout<<ans[i]<<endl;
	}
	return;
}
int main()
{
	solve();
	return 0;
}

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

int main() {
  int l, r;
  cin >> l >> r;

  int middle = l / 2019 + 1;
  int value = 2019 * middle;
  if ((l <= value && value <= r) || r - l >= 2019) {
    cout << 0 << endl;
    return 0;
  } else if (r - l >= 674) {
    cout << 0 << endl;
    return 0;
  }

  long long min = 2000000000000000;
  for (long long i = l; i < r; i++) {
    for (long long j = l + 1; j <= r; j++) {
      long long value = ((i % 2019) * (j % 2019)) % 2019;
      if (value == 0) {
        cout << 0 << endl;
        return 0;
      }
      if (value < min)
        min = value;
    }
  }
  cout << min << endl;
}


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

long long N, A[200009], B[200009], minx = (1LL << 60);

long long ranged(long long L, long long R) {
	return B[R] - B[L - 1];
}

int main() {
	cin >> N;
	for (int i = 1; i <= N; i++) { cin >> A[i]; B[i] = B[i - 1] + A[i]; }

	for (int i = 2; i <= N - 2; i++) {
		long long mid1 = B[i] / 2, mid2 = B[i] + (B[N] - B[i]) / 2;

		int pos1 = lower_bound(B, B + N, mid1) - B;
		int pos2 = lower_bound(B, B + N, mid2) - B;

		vector<pair<long long, long long>>vec1;
		if (pos1 - 1 > 0 && pos1 - 1 < i) { vec1.push_back(make_pair(ranged(1, pos1 - 1), ranged(pos1 + 0, i))); }
		if (pos1 + 0 > 0 && pos1 + 0 < i) { vec1.push_back(make_pair(ranged(1, pos1 + 0), ranged(pos1 + 1, i))); }
		if (pos1 + 1 > 0 && pos1 + 1 < i) { vec1.push_back(make_pair(ranged(1, pos1 + 1), ranged(pos1 + 2, i))); }

		vector<pair<long long, long long>>vec2;
		if (pos2 - 1 > i && pos2 - 1 < N) { vec2.push_back(make_pair(ranged(i + 1, pos2 - 1), ranged(pos2 + 0, N))); }
		if (pos2 + 0 > i && pos2 + 0 < N) { vec2.push_back(make_pair(ranged(i + 1, pos2 + 0), ranged(pos2 + 1, N))); }
		if (pos2 + 1 > i && pos2 + 1 < N) { vec2.push_back(make_pair(ranged(i + 1, pos2 + 1), ranged(pos2 + 2, N))); }

		for (int j = 0; j < vec1.size(); j++) {
			for (int k = 0; k < vec2.size(); k++) {
				long long V[4] = { vec1[j].first, vec1[j].second, vec2[k].first, vec2[k].second };
				sort(V, V + 4);
				minx = min(minx, V[3] - V[0]);
			}
		}
	}
	cout << minx << endl;
	return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <queue>
#include <sstream>
#include <unordered_map>
#include <cstring>
#include <iomanip>

using namespace std;

typedef long long ll;

const ll INF=1e9+7;

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

#define rep(i,n) for(int i=0;i<(n);i++)

int main(){
    int A,B;
    cin>>A>>B;
    if(A<2*B){
        cout<<0<<endl;
    }else{
        cout<<A-(2*B)<<endl;
    }
    return 0;
}

//a=97,z=122

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<algorithm>
using namespace std;

int main(){
    int A, B;
    cin >> A >> B;
    if (A == B)
        cout << 2*A << endl;
    else if(A>B)
        cout << 2*A - 1  << endl;
    else
        cout << 2*B  - 1<< endl;
    return 0;
}

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

#define int long long

#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define low(a,b) lower_bound(all(a),(b))
#define upp(a,b) upper_bound(all(a),(b))
#define fill(i,n) memset(i,n,sizeof i)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint,int> P1;
typedef pair<int,pint> P2;
typedef pair<pint,pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD=1000000007;
const ll INF=1e18;

int N;
string s;
int a[100010];
double sum=0;

signed main() {
    IOS();
    cin>>N;
    rep(i,0,N){
        cin>>a[i];
        sum+=a[i];
    }
    int ans=0;
    sum=(double)sum/N;
    double ave=100001;
    rep(i,0,N){
        if(ave>abs(sum-a[i])){
            ave=abs(sum-a[i]);
            ans=i;
        }
    }
    
    cout<<ans<<endl;
    
    
    
    
    
    
    
    
    
    
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std; 
int N; 
vector<int> E[100010]; 
long long int dp[100010][2]; 
long long int P = 1e9 + 7; 
void dfs(int now, int parent){
	dp[now][0] = 1; dp[now][1] = 1; 
	for(auto i : E[now]){
		if(i == parent) continue; 
		dfs(i, now); 
		dp[now][0] *= (dp[i][0] + dp[i][1]); 
		dp[now][0] %= P; 
		dp[now][1] *= dp[i][0]; 
		dp[now][1] %= P; 
	}
}
int main(){
	cin >> N; 
	for(int i = 1; i < N; i++){
		int a, b; cin >> a >> b; 
		a--; b--; 
		E[a].push_back(b); 
		E[b].push_back(a); 
	}
	dfs(0, -1); 
	cout << (dp[0][0] + dp[0][1]) % P << endl; 
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define debug(x) cerr << "[debug] " << #x << ": " << x << endl;
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << endl;
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

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

signed main() {
  init();
  ll N;
  cin >> N;
  vll A(N);
  ll max = 0;
  rep(i, N) {
    cin >> A[i];
    if (max < A[i]) max = A[i];
  }

  ll index = 0;
  while (max > 0) {
    ll count = 0;
    rep(i, N) {
      ll a = (A[i] >> index) % 2;
      count += a;
    }
    if (count % 2 == 1) {
      rep(i, N) {
        A[i] ^= (1 << index);
      }
    }
    max /= 2;
    index++;
  }

  rep(i, N) {
    if (i == 0)
      cout << A[i];
    else
      cout << " " << A[i];
  }
  ENDL;

  return 0;
}

Measured memory_bytes: 4784
#pragma GCC optimize("O2")
#include<bits/stdc++.h>
#define ll long long
using namespace std;
typedef pair<int,int> pii;
const int N = 100;
int A[N],B[N],n,ans;

int main(){
    cin >> n;
    for(int i=1;i<=n-1;++i)   cin >> B[i];
    B[0] = 1<<30;   B[n] = 1<<30;
    // A[n] = B[n-1];  ans = A[n];
    for(int i=n;i>=1;--i) A[i] = min(B[i],B[i-1]),ans+=A[i];
    // for(int i=1;i<=n;++i)   cout <<A[i] << ' ';
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

s = list(input())
n = len(s)-1

res = 0

d = dict()
mod = 2019
d[0] = 1

tmp = 0
for i in range(n-1,-1,-1):
    tmp = (tmp + int(s[i])*pow(10,n-1-i,mod))%mod
    if tmp in d:
        res += d[tmp]
        d[tmp] += 1
    else:
        d[tmp] = 1

print(res)

Measured memory_bytes: 77656
#include <iostream>
#include <vector>
#include <cstring>
#include <cmath>

using namespace std;
typedef long long ll;

int K,S;

int main(){
  cin >> K >> S;
  int ans = 0;
  for (int i=0;i<K+1;i++){
    for(int j=0;j<min(S+1-i,K+1);j++){
      if(S-i-j<=K){
	//cout << i << " " << j << " " << S-i-j << endl;
	ans++;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    Init();
    ll n; cin >> n;
    map<ll, ll> cnt;
    rep(i, n){
        ll in; cin >> in;
        cnt[in]++;
    }
    vector<pair<ll, ll>> cntr;
    for(auto p: cnt) cntr.push_back(make_pair(p.second, p.first));
    sort(all(cntr), greater<pair<ll, ll>>());

    vi ans;
    for(auto p: cntr){
        if(p.first >= 2){
            for(ll j=0; j<p.first/2; j++) ans.push_back(p.second);
        }
    }
    ans.push_back(0); ans.push_back(0);
    sort(all(ans), greater<ll>());
    cout << ans[0] * ans[1] << endl;
}

Measured memory_bytes: 8696
#ABC097-C
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
import collections
S=input()
k=I()
ans=[]
for i in range(len(S)):
    for j in range(1,k+1):
        ans.append(S[i:i+j])
ans=list(set(ans))
ans.sort()
print(ans[k-1])

Measured memory_bytes: 40560
n = int(input())
ls_a = [int(input()) for _ in range(n)]

ls_next = [ls_a[0]]

for i in range(n):
    Num = ls_a[ls_next[i] - 1]
    ls_next.append(Num)
    if ls_a[0] == 2:
        print(1)
        break
    elif Num == 2:
        print(len(ls_next))
        break
    elif i == n - 1:
        print(-1)

Measured memory_bytes: 8112
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, a, b;
    cin >> n >> a >> b;
    vector< int > h(n);
    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }
    sort(h.begin(), h.end());
    reverse(h.begin(), h.end());
    int NMax = (h[0] + b - 1) / b;
    int L = 1, R = NMax;
    while (R - L > 1) {
        int t = L + (R - L) / 2;
        int sum = 0;
        bool ok = true;
        for (int i = 0; i < n; i++) {
            if (h[i] < b * t) {
                break;
            }
            sum += max(0, (h[i] - b * t + a - b - 1) / (a - b));
            if (sum > t) {
                ok = false;
            }
        }
        if (ok) {
            R = t;
        } else {
            L = t;
        }
    }
    cout << R << endl;

    return 0;
}

Measured memory_bytes: 640
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	x, _, y, _ := iScan(), iScan(), iScan(), iScan()
	if x != y {
		fmt.Println(1)
	} else {
		fmt.Println(0)
	}
}


Measured memory_bytes: 1772
#include<bits/stdc++.h>
 
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define mp  make_pair
#define all(v) (v).begin(), (v).end()
#define mod 1000000007
#define inf 1e18
 
 
using namespace std;

signed main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
    #endif
    
    IOS;
    int a;
    cin>>a;
    string b;
    cin>>b;
    int x=(b[0]-48);
    int y=(b[2]-48)*10+b[3]-48;
    cout<<a*x+a*y/100;
}

Measured memory_bytes: 3664
n, m = map(int, input().split())
s = [0] * m
c = [0] * m
for i in range(m):
    s[i], c[i] = map(int, input().split())

for i in range(0, 1000):
    x = str(i)
    if len(x) != n:
        continue
    for j in range(m):
        if s[j] > len(x) or int(x[s[j] - 1]) != c[j]:
            break
    else:
        print(x)
        exit()
print(-1)


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

// 22
public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int umaibo = sc.nextInt();
        int[] a = new int[n];
        for(int i = 0; i < n; i++)
            a[i] = sc.nextInt();

        Arrays.sort(a);
        int i = 0;
        for( ; i < n; i++) {
            umaibo -= a[i];
            if(umaibo < 0) break;
        }
        if(umaibo > 0) --i;

        System.out.println(i);
    }

}


Measured memory_bytes: 35816
n=int(input())
s=str(input())

if n%2==1:
	print("No")
	
else:
	s1=s[0:int(n/2)]
	s2=s[int(n/2):n]
	#print(s1)
	#print(s2)
	if s1==s2:
		print("Yes")
	else:
		print("No")

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

#define FOR(i, a, b) for(long long int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;


int main(void) {
	
	int n;
	string s;
	int maxi = -1;

	cin >> n;
	cin >> s;

	FOR(i, 0, s.size() - 1) {
		bool count[27] = {};
		bool point[27] = {};
		int res = 0;
		FOR(j, 0, i) {
			count[s[j] - 'a' + 1] = true;
		}
		FOR(j, i + 1, s.size() - 1) {
			point[s[j] - 'a' + 1] = true;
		}
		FOR(j, 1, 26) {
			if (count[j] == true && point[j] == true) {
				res++;
			}
		}
		if (res > maxi) {
			maxi = res;
		}
	}
	cout << maxi << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;
 
int tx[] = {1,0};
int ty[] = {0,1};
 
static const double EPS = 1e-8;

class State{
public:
  int mX;
  int mY;
  int mCost;
  State(int x,int y,int cost) : mX(x), mY(y), mCost(cost){}

  bool operator <(const State& s) const{
    return mCost < s.mCost;
  }

  bool operator >(const State& s) const{
    return mCost > s.mCost;
  }
};

int main(){
  int H,W;
  while(~scanf("%d %d",&H,&W)){
    char stage[50][50];
    for(int y=0;y<H;y++){
      char buf[51];
      scanf("%s",buf);
      for(int x=0;x<W;x++){
	stage[y][x] = buf[x];
      }
    }

    int cost_table[50][50];
    memset(cost_table,0x3f,sizeof(cost_table));
    priority_queue<State,vector<State>,greater<State> > que;
    cost_table[0][0] = stage[0][0]-'0';

    que.push(State(0,0,stage[0][0]-'0'));
    while(!que.empty()){
      State s = que.top();
      que.pop();
      for(int i=0;i<2;i++){
	int dx = s.mX + tx[i];
	int dy = s.mY + ty[i];
	if(dx < 0 || dx >= W 
	   || dy < 0 || dy >= H) continue;
	   
	   if(cost_table[dy][dx] <= s.mCost + stage[dy][dx]-'0') continue;
	   cost_table[dy][dx] = s.mCost + stage[dy][dx]-'0';
	   que.push(State(dx,dy,s.mCost + stage[dy][dx]-'0'));
	   }
      }

      printf("%d\n",cost_table[H-1][W-1]);
  }
}

Measured memory_bytes: 1212
n = int(input())
ans = [0]*(6*10**4)
for x in range(1, 10**2+1):
    for y in range(x, 10**2+1):
        for z in range(y, 10**2+1):
            cal = x*x + y*y + z*z + x*y + y*z + z*x
            if x == y and y == z:
                ans[cal-1] += 1
            elif x == y or y == z:
                ans[cal-1] += 3
            else:
                ans[cal-1] += 6
for i in range(n):
    print(ans[i])


Measured memory_bytes: 69700
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

long S(long a){
    long sum=0;
    while(a>0){
        sum += a%10;
        a /= 10;
    }
    return sum;
}

double g(long a){
    return (double)(a)/S(a);
}
int compare(long *a,long *b){
    if(*a<*b) return -1;
    else if(*a>*b) return 1;
    else return 0;
}
int main(){
    int k;
    scanf("%d",&k);
    int n=0;
    long cand[2500];
    for(int i=0; i<15; i++){
        for(int j=1; j<150; j++){
            cand[n]=pow(10,i)*(j+1)-1;
            n++;
        }
    }
    qsort(cand,n,sizeof(long),compare);
    long cand_[2500];
    int m=0;
    cand[n]=0;
    for(int l=0; l<n; l++){
        while(cand[l]==cand[l+1]) l++;
        cand_[m]=cand[l];
        m++;
    }
    int tri=1;
    int count = 0;
    for(int ii=0; ii<m; ii++){
        if(count>=k) break;
        tri=1;
        for(int jj=ii+1; jj<m; jj++){
            if(g(cand_[ii])>g(cand_[jj])){
                tri=0;
                break;
            }
        }
        if(tri){
            printf("%ld\n",cand_[ii]);
            count++;
        }
    }
    return 0;
}

Measured memory_bytes: 256
import math

N = int(input())

As = list(map(int, input().split()))
Bs = list(map(int, input().split()))

if sum(As) > sum(Bs):
  print('No')
  exit()
  
dif = sum(Bs) - sum(As)
A = 0
for i in range(N):
  if Bs[i] > As[i]:
    A += math.ceil((Bs[i]-As[i])/2)
    
if A > dif:
  print('No')
else:
  print('Yes')

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

string s;
int a[26];
char c[26];

int main() {
    while (getline (cin, s)) {
    for (int i=0; i<s.length(); i++) {
        if (s[i]>='a' && s[i]<='z') a[s[i]-97]++;
        if (s[i]>='A' && s[i]<='Z') a[s[i]-65]++;
    }}
    for (int i=0; i<26; i++) {
        c[i] = 97+i;
        cout << c[i] << " " << ":" << " " << a[i] << endl;
    }
}


Measured memory_bytes: 3152
#include <stdio.h>
i,a,t[27];
int main(void){
    char c[1201]={};
    for(i=0,scanf("%[^\r]",c);c[i]!='\0';i++){
        a=64<c[i]&&c[i]<91?c[i]-'A'
         :96<c[i]&&c[i]<123?c[i]-'a'
         :26;
        t[a]++;
    }
    for(i=0;i<26;i++){
    printf("%c : %d\n",i+97,t[i]);
    }
}

Measured memory_bytes: 1752