akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

ll solve() {
    ll N, A, B;
    cin >> N >> A >> B;
    if ( abs(A-B) % 2 == 0 ) {
        return abs(A-B)/2;
    } else {
        return min((A)/2 + (B)/2, (N-A+1)/2 + (N-B+1)/2);
    }
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
typedef long long ll;

using ipair = pair<int, int>;

ll INF = 1e16+7;

bool operator>(const ipair a,const ipair b){return a.first > b.first;}



int main(){

  int N, M;
  cin >> N >> M;
  vector<vector<int>> vect(N+1);
  rep(i, M){
    int a, b;
    cin >> a >> b;
    vect[a].push_back(b);
    vect[b].push_back(a);
  }

  vector<ll> dist(N+1, N*10);
  queue<ipair> q;
  q.push(make_pair(1, 0));
  while(!q.empty()){
    ipair p = q.front(); q.pop();
    int now = p.first;
    // cout << "now:" << now << endl;
    int now_dist = p.second;
    dist[now] = now_dist;
    for(int next: vect[now]){
      if(dist[next] == N*10){
        q.push(make_pair(next, now_dist+1));
      }
    }
  }

  // cout << "dist:" << dist[N-3] << endl;
  // cout << "dist:" << dist[N-2] << endl;
  // cout << "dist:" << dist[N-1] << endl;
  // cout << "dist:" << dist[N] << endl;

  if(dist[N] <= 2){
    cout << "POSSIBLE" << endl;
  }else{
    cout << "IMPOSSIBLE" << endl;
  }


  return 0;
}


Measured memory_bytes: 14320
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i,n) for (int i = 0; i < (n); ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main(){
    int n,m;
    cin >> n >> m;
    vector<int > s(m);
    vector<int > c(m);
    REP(i,m) cin >> s[i] >> c[i];


    // 条件埋め
    vector<int > res(3);
    REP(i,3) res[i] = -1; // -1で初期化
    int error = 0; // 条件不整合エラーフラグ

    REP(i,m){
        // 正常(-1が入っている)または(同じ条件)
        if( (res[s[i]-1] == -1) || (res[s[i]-1] == c[i]) ){
            res[s[i]-1] = c[i];
        }else{
            error = 1;
        }
    }
    // エラー処理
      // 条件不整合エラー
    if(error){
        cout << -1 << endl;
        return 0;
    }
      // 2桁以上なのに0始まりエラー
    if(n>=2 && res[0] == 0){
        cout << -1 << endl;
        return 0;
    }

    // 未確定桁の決定処理
    if(n>=2 && res[0] == -1){
        res[0] = 1;
    }else if(res[0] == -1){
        res[0] = 0;
    }
    if(res[1] == -1){
        res[1] = 0;
    }
    if(res[2] == -1){
        res[2] = 0;
    }

    // 出力
    REP(i,n){
        cout << res[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main(){
    ll N,P;string S;cin>>N>>P>>S;
    ll ans=0;
    if(P==2 or P==5){
        rep(i,N){
            if((S[i]-'0')%P==0)ans+=i+1;
        }
        cout<<ans<<endl;
        return 0;
    }
    map<ll,ll> info;
    info[0]++;
    ll now=0;
    vl modP(N);
    modP[0]=1;
    repl(i,1,N)modP[i]=modP[i-1]*10%P;
    per(i,N){
        now+=(S[i]-'0')*modP[N-1-i];
        now%=P;
        info[now]++;
    }
    for(auto p:info){
        ans+=p.se*(p.se-1)/2;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 2564
import numpy as np
S = input()

a = [0]*(len(S)+1)

for i in range(len(S)):
    if S[i] == '<':
        a[i+1] =max(a[i+1], a[i]+1)
    else:
        a[i] = max(a[i],a[i+1]+1)

for i in range(len(S)-1,-1,-1):
    if S[i] == '<':
        a[i+1] =max(a[i+1], a[i]+1)
    else:
        a[i] = max(a[i],a[i+1]+1)


print(sum(a))

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

int main() {
    int n;
    vector<int> prime;
    vector<bool> is_prime(100000, true);
    is_prime[0] = is_prime[1] = false;
    for(int i=2; i<is_prime.size(); ++i) {
        if(is_prime[i]) {
            prime.push_back(i);
            for(int j=i+i; j<is_prime.size(); j+=i) {
                is_prime[j] = false;
            }
        }
    }
    while(cin >> n) {
        auto it = lower_bound(prime.begin(), prime.end(), n);
        auto it2 = upper_bound(prime.begin(), prime.end(), n);
        cout << *(it-1) << ' ' << *it2 << endl;
    }
}


Measured memory_bytes: 3216
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int N=2e5+5;
typedef long long ll;
int a[N],n;ll sum[N],suf[N],res;
int main(){
	scanf("%d",&n);
	fp(i,1,n)scanf("%d",&a[i]),sum[i]=suf[i]=a[i];
	fp(i,1,n)sum[i]+=sum[i-1];fd(i,n,1)suf[i]+=suf[i+1];
	res=1e18;
	fp(i,1,n-1)cmin(res,abs(sum[i]-suf[i+1]));
	printf("%lld\n",res);
	return 0;
}

Measured memory_bytes: 4096
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int w,a,b;
	cin>>w>>a>>b;
	int c=max(a,b);
	int d=min(a+w,b+w);
	if(c-d<0){
		cout<<"0"<<endl;
	}
	else{
		cout<<c-d<<endl;
	}
	return 0;
}

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

int main(){
  char b;
  cin >> b;
  
  if(b == 'A'){
    cout << 'T' << endl;
  } else if(b == 'C'){
    cout << "G" << endl;
  } else if(b == 'T'){
    cout << 'A' << endl;
  } else {
    cout << 'C' << endl;
  }
}


Measured memory_bytes: 256
solve x k d
    | xdd >= k = x' - (k*d)
    | even k' = xdm
    | otherwise = abs $ xdm - d
        where
            x' = abs x
            xdd = div x' d
            xdm = mod x' d
            k' = k - xdd


main = do
    [x,k,d] <- map read . words <$> getLine :: IO [Integer]
    print $ solve x k d



Measured memory_bytes: 3972
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

ll s[200000];
int main(){
	int n;scanf("%d",&n);
	rep(i,n){
		scanf("%lld",&s[i]);
	}
	ll Max=0;
	for(int i=1;i<=n-3;i++){//A-B
		ll s1=0;
		int p=0;
		ll s2=0;
		for(int A=n-1-i;A>0&&A>i;A-=i){//A
			int B=A-i;
			if(A<=B||A<=0||B<=0)continue;
			int need=(n-1-A)/i;
			if(A%(A-B)==0&&A/(A-B)<=need)continue;
			s2+=s[A];
			while(p<need){
				p++;
				s1+=s[p*i];
			}
			Max=max(Max,s1+s2);
		}
	}
	cout<<Max<<endl;
}

Measured memory_bytes: 1024
#include <cctype>
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;

template<class T> inline void chmax(T& a, const T& b) { if(b > a) a = b; }

string s;
const int limit = (1 << 10);

int expr(int&);

inline bool out_range(int x) {
	return x < 0 || x >= limit;
}

int number(int& idx) {
	int res = 0;
	while(isdigit(s[idx])) {
		res <<= 1;
		if(s[idx] == '1')
			res += 1;

		++idx;
	}

	if(out_range(res))
		throw 0;

	return res;
}

int factor(int& idx) {
	if(isdigit(s[idx])) {
		return number(idx);
	}
	else if(s[idx] == '(') {
		int end = ++idx;
		const int res = expr(end);
		if(s[end] != ')')
			throw 0;

		bool ok = false;
		int cnt = 0;
		for(int i = idx; i < end; ++i) {
			if(s[i] == '(')
				++cnt;

			else if(s[i] == ')')
				--cnt;

			else if(cnt == 0 && (s[i] == '+' || s[i] == '-' || s[i] == '*')) {
				ok = true;
				break;
			}
		}

		if(!ok)
			throw 0;

		idx = end + 1;
		return res;
	}
	else
		throw 0;
}


int term(int& idx) {
	int res = factor(idx);
	while(s[idx] == '*') {
		++idx;
		res *= factor(idx);
		if(out_range(res))
			throw 0;
	}

	return res;
}

int expr(int& idx) {
	int res = term(idx);
	while(s[idx] == '+' || s[idx] == '-') {
		if(s[idx++] == '+') {
			res += term(idx);
			if(out_range(res))
				throw 0;
		}
		else {
			res -= term(idx);
			if(out_range(res))
				throw 0;
		}
	}

	return res;
}

vector<int> cant_read;
const string candidate = "01+-*()";

int dfs(int depth = 0) {
	if(cant_read.size() == depth) {
		try {
			int idx = 0;
			const int res = expr(idx);
			if(idx != s.size())
				throw 0;

			return res;
		} catch(...) {
			return -1;
		}
	}

	int res = -1;
	const int next_depth = depth + 1;

	for(int i = 0; i < (int)candidate.size(); ++i) {
		s[cant_read[depth]] = candidate[i];
		chmax(res, dfs(next_depth));
	}

	return res;
}

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

	cin >> s;

	for(int i = 0; i < (int)s.size(); ++i)
		if(s[i] == '.')
			cant_read.push_back(i);

	cout << dfs(0) << endl;

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1280
data = gets.split(" ").map{|nn|nn.to_i}
k = data[1]

members = gets.chomp

blocks = []

members = members.chars

lastman = members[0]
coutinuemen = 1
for i in 1..(members.size-1) do
  if lastman == members[i]
    coutinuemen += 1
  else
    blocks << coutinuemen
    coutinuemen = 1
    lastman = members[i]
  end
end
blocks << coutinuemen
enough = 100000000
if blocks[0] == "1"
  enough = (blocks.size / 2.0).floor
else
  enough = (blocks.size / 2.0).ceil
end


if enough <= k
  puts members.size.to_s
else
  getrange = k + k + 1
  maxsize = blocks.size - getrange
  tmpmax = -1

  if members[0] == "1"
    i = 0
    result = 0
    getrange.times do|offset|
      break if offset + i >= blocks.size
      result += blocks[offset + i]
    end
    i = 2
    while i <= maxsize
      result -= blocks[i-1]
      result -= blocks[i-2]
      result += blocks[i+getrange-1]
      result += blocks[i+getrange-2]
      if tmpmax < result
        tmpmax = result
      end

      i += 2
    end
    #お尻のテスト
    if members.last == "0"
      result = blocks.last(getrange-1).inject(:+)
      if tmpmax < result
        tmpmax = result
      end
    end
  else
    i = 1
    result = 0
    getrange.times do|offset|
      break if offset + i >= blocks.size
      result += blocks[offset + i]
    end
    i = 3
    tmpmax = result
    while i <= maxsize
      result -= blocks[i-1]
      result -= blocks[i-2]
      result += blocks[i+getrange-1]
      result += blocks[i+getrange-2]
      if tmpmax < result
        tmpmax = result
      end

      i += 2
    end
    if members[0] == "0"
    result = blocks.first(getrange-1).inject(:+)
    if tmpmax < result
      tmpmax = result
    end
    end
  end

  puts tmpmax.to_s
end



Measured memory_bytes: 8060
n,a,b = gets.chomp.split(" ").map(&:to_i)
h = n.times.map{gets.to_i}
min = 1
max = h.inject(0){|r,i|r+(i+a-1)/a}
while min <= max
  mid = min+(max-min)/2
  ans = 0
  for i in 0..n-1
    ans += ([0,h[i]-b*mid].max+a-b-1)/(a-b)
  end
  if ans < mid
    max = mid-1
  elsif ans > mid
    min = mid+1
  else
    break
  end
end
for i in mid-1..mid+1
  ans = 0
  for j in 0..n-1
    ans += ([0,h[j]-b*i].max+a-b-1)/(a-b)
  end
  if ans <= i
    puts i
    exit
  end
end

Measured memory_bytes: 3068
#include  <bits/stdc++.h>
// #include  <vector >
// #include  <algorithm >
using  namespace  std;
typedef  long  long ll;
#define  rep(i,n) for(int i=0;i<n;i++)
int N,M;int P[100000] ,Y[100000];
vector <int > yd [100001];
int  main(){
    scanf ("%d%d",&N,&M);
    rep(i,M)scanf ("%d%d",&P[i],&Y[i]),yd[P[i]]. push_back(Y[i]);
    rep(i,N)sort(yd[i+1]. begin(),yd[i+1]. end ());
    rep(i,M)printf ("%012lld\n",ll(P[i])*1000000+ int(lower_bound(yd[P[i]].begin(),yd[P[i]]. end(),Y[i])-yd[P[i]]. begin ())+1);
}

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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        int v;
        cin >> v;
        a[i] = (v-1+k)%k;
    }
    map<int, int> cnt;
    cnt[0] = 1;
    int s = 0;
    long long ans = 0;
    vector<int> pref = {0};
    for (int i = 0; i < n; i++) {
        int v = a[i];
        s = (s+v)%k;
        pref.push_back(s);
        int j = i + 1 - k;
        if (j >= 0) {
            cnt[pref[j]]--;
        }
        ans += cnt[s];
        cnt[s]++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 14216
#include <array>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;


typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define PB push


#define MOD 1000000007LL
#define EPS 1e-10

int main()
{
    LL n;
    cin >> n;
    LL a[n];
    REP(i, n)
    {
        cin >> a[i];
    }
    LL ans = 1e15;
    REP(i, 2)
    {
        LL sum = 0;
        LL cnt = 0;
        REP(j, n)
        {
            sum += a[j];
            LL sign = j % 2 == i ? 1 : -1;
            if (sign * sum <= 0)
            {
                cnt += abs(sum) + 1;
                sum = sign;
            }
        }
        ans = min(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<algorithm>
using namespace std;

int read(){
    int x=0;bool f=0;char c=getchar();
    while(c<'0'||c>'9') f|=c=='-',c=getchar();
    while(c>='0'&&c<='9') x=x*10+(c^48),c=getchar();
    return f?-x:x;
}

#define MAXN 20
int N,A[MAXN+5],B[MAXN+5],C[MAXN+5];

int main(){
    N=read();
    for(int i=1;i<=N;i++)
        A[i]=read();
    for(int i=1;i<=N;i++)
        B[i]=read();
    for(int i=1;i<=N-1;i++)
        C[i]=read();
    int Ans=0;
    for(int i=1;i<=N;i++){
        if(i>1&&A[i]==A[i-1]+1)
            Ans+=C[A[i-1]];
        Ans+=B[A[i]];
    }
    printf("%d",Ans);
}


Measured memory_bytes: 128
#include<iostream>
#include<set>
#include<algorithm>
#include<queue>
#include<string>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
string edge[10][2];

string substitute(string tar,string from,string to){
  string ret;
  for(int i=0;i<tar.size();i++){
    bool flag=true;
    rep(j,from.size()){
      if ( from[j]!=tar[i+j]){flag=false;break;}
    }
    if ( flag == false)ret+=tar[i];
    else {
      ret+=to;
      i+=from.size()-1;
    }
  }
  return ret;
}

int bfs(string start,string goal,int n){
  queue<pair<string,int> > Q;
  set<string>S;
  Q.push(make_pair(start,0));
  S.insert(start);
  while(!Q.empty()){
    pair<string,int> now =Q.front();
    Q.pop();
    if ( now.first == goal)return now.second;
    rep(i,n){
      string next = substitute(now.first,edge[i][0],edge[i][1]);
      if ( S.find(next) == S.end() && next.size()<= goal.size()){
	S.insert(next);
	Q.push(make_pair(next,now.second+1));
      }
    }
    
  }
  return -1;
}


main(){

  int n;
  while(cin>>n && n){
    string start,goal;
    rep(i,n)cin>>edge[i][0]>>edge[i][1];
    cin>>start>>goal;
    cout << bfs(start,goal,n) <<endl;
  }
}

Measured memory_bytes: 0
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<set>
#include<climits>
#define ll long long
using namespace std;
int main() {
	string s;
	cin >> s;
	if (s == "abc" || s == "acb" || s == "bac" || s == "bca" || s == "cab" || s == "cba") {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)n;i++)
using Graph = vector<vector<int> >;
using GraphC = vector<vector<char> >;
const int INF = 100000000;
typedef pair<int, int> P;
const int MAX_N = 1000000;



int main() {
	int64_t N;
	cin >> N;
	vector<int64_t> vec(N);
	vector<int64_t> tmp(N);
	
	rep(i, N) {
		cin>>vec.at(i);
		tmp.at(i) = vec.at(i);
	}
	
	sort(vec.begin(), vec.end());

	rep(i, N) {
		if (tmp.at(i) == vec.at(N - 1)) {
			cout << vec.at(N - 2) << endl;
		}
		else {
			cout << vec.at(N - 1) << endl;
		}
	}
}

Measured memory_bytes: 6344
#include<bits/stdc++.h>
using namespace std;
int main()
{
 
int a,b,c,i;
set<char>s;
char x;
for(i=1;i<=3;i++){cin>>x;s.insert(x);}
if(s.size()==1)cout<<"No\n";
else cout<<"Yes\n";
}

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


void FavoriteNumbers() {
	long long D, N;
	cin >> D >> N;

	if (D == 0) {
		cout << ((N == 100) ? 101 : N);
	}
	else if (D == 1) {
		cout << ((N == 100) ? 10100 : (N * 100));
	}
	else {
		cout << ((N == 100) ? 1010000 : (N * 100 * 100));
	}

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

Measured memory_bytes: 256
#include <bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int 	     	  long long   // [9,223,372,036,854,775,807 to -9.....808] 19 digits
#define pb                push_back 
#define all(x)            (x).begin(),(x).end()
#define mp                make_pair
#define vi                vector<int> 
#define vpi               vector<pair<int,int>>
#define mii               map<int,int>
#define x                 first
#define y                 second 
#define mem(a,x)          memset(a,x,sizeof(a))
#define rep(i,a,b)        for(int i=a;i<b;i++)
#define sz(x)             (int)((x).size())

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // find_by_order()  // order_of_key

//const int32_t mod=163577857; const int32_t hellhsh = 444440583533; const double pi=2*acos(0.0); const int32_t mod=998244353; 
const int32_t mod = 1e9+7;
const int32_t maxn=2e5+5;

string s="#abcdefghijklmnopqrstuvwxyz";

void solve(){
    int n;cin>>n;
    string ans;
    while(n){
        int x=n%26;
        if(!x) x=26;
        ans.pb(s[x]);
        n=(n-1)/26;
    }
    reverse(all(ans));
    cout<<ans;
}

signed main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int tc=1,k=1;                                                                                                                  
    //cin>>tc;
    while(tc--){
        //cout<<"Case #"<<k++<<": ";
        solve();
    }
    return 0;
}

Measured memory_bytes: 3612
from bisect import bisect_left

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort()
    def check(x):
        index = bisect_left(A,x)
        ans = 0
        for i in range(index,N):
            if A[i] % x == 0:
                tmp = (A[i] // x) - 1
            else:
                tmp = A[i] // x
            ans += tmp
        if ans <= K:
            return True
        else:
            return False
    ok = max(A)
    ng = 0
    while abs(ok- ng) > 1:
        mid = (ok + ng) // 2
        if check(mid):
            ok = mid
        else:
            ng = mid
    print(ok)


if __name__ == "__main__":
    main()

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

using namespace std;

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

int main(){
	
	int n;

	cin>>n;

	int sum=0;
	
	for(int i=1; i<=n; i++)
	{
		for(int j=1; j<=n; j++)
		{
			for(int p=1 ; p<=n ; p++)
			{
				int k = gcd(i,j);
				
				sum += gcd(k,p);
			}
		}
	}
	
	cout<<sum<<endl;

	return 0;
}



Measured memory_bytes: 3624
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>

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

//prototype declaration
int iin();
long long llin();
double din();
char cin();
void stin(char *s);
void iout(int i);
void llout(long long i);
void dout(double i);
void cout(char c);
void stout(char *s);
int gcd(int a, int b);
int lcm(int a, int b);
long long llgcd(long long a, long long b);
long long lllcm(long long a, long long b);
int asc(const void *a, const void *b);
int desc(const void *a, const void *b);

//main function
int main() {
    char a[100], b[100], c[100];
    stin(a);
    stin(b);
    stin(c);
    printf("%c%c%c\n", a[0], b[0], c[0]);
    return 0;
}

//body function
int iin() {
    int i;
    scanf("%d", &i);
    return i;
}

long long llin() {
    long long i;
    scanf("%lld", &i);
    return i;
}

double din() {
    double i;
    scanf("%lf", &i);
    return i;
}

char cin() {
    char c;
    scanf("%c", &c);
    return c;
}

void stin(char *s) {
    scanf("%s", s);
}

void iout(int i) {
    printf("%d\n", i);
}

void llout(long long i) {
    printf("%lld\n", i);
}

void dout(double i) {
    printf("%lf\n", i);
}

void cout(char c) {
    printf("%c\n", c);
}

void stout(char *s) {
    printf("%s\n", s);
}

/*
    int型の最大公約数
*/

int gcd(int a, int b) {
    int r;

    if (a < b) {
        r = a;
        a = b;
        b = r;
    }

    r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }

    return b;
}

/*
    int型の最小公倍数
*/

int lcm(int a, int b) {
    int r = llgcd(a, b);
    a /= r;
    return a * b;
}

/*
    long long型の最大公約数
*/

long long llgcd(long long a, long long b) {
    long long r;

    if (a < b) {
        r = a;
        a = b;
        b = r;
    }

    r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }

    return b;
}

/*
    long long型の最小公倍数
*/

long long lllcm(long long a, long long b) {
    long long r = llgcd(a, b);
    a /= r;
    return a * b;
}

/*
    int型の昇順用比較関数
*/

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

/*
    int型の降順用比較関数
*/

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


Measured memory_bytes: 128
N = int(input())
tmp = [0 for i in range(5)]
for i in range(5):
    tmp[i] = int(input())
tmp_min = min(tmp)
base = 0
if N % tmp_min == 0:
    base = N // tmp_min
else:
    base = N // tmp_min + 1

print(base + 4)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n      = s.size();
    lint ok    = n;
    lint ng    = 0;
    auto check = [&](lint mid) {
        for (int i = 0; i < 2; ++i) {
            int a = i;
            int b = mid;
            if (a % 2 != b % 2)
                b--;
            bool ok = true;
            for (int j = 0; j < n; ++j) {
                if (s[j] == '1') {
                    a++, b++;
                } else if (s[j] == '0') {
                    a--, b--;
                } else {
                    a--, b++;
                }
                if (a < 0)
                    a += 2;
                if (b > mid)
                    b -= 2;
                if (a > b) {
                    ok = false;
                    break;
                }
            }
            if (ok)
                return true;
        }
        return false;
    };
    while (abs(ok - ng) != 1) {
        lint mid               = (ok + ng) / 2;
        (check(mid) ? ok : ng) = mid;
    }
    cout << ok << "\n";
    return 0;
}

Measured memory_bytes: 4284
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**8)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    x, y = geta(int)

    m2, n2 = y - 2 * x, 4 * x - y

    if m2 & 1 == 0 and n2 & 1 == 0 and m2 >= 0 and n2 >= 0:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()

Measured memory_bytes: 64860
#include<bits/stdc++.h>
using namespace std;
const int N=105;
int n,x,a[N];
int main()
{
	scanf("%d%d",&x,&n);
	for(int i=1;i<=n;i++)
	{
		int y;
		scanf("%d",&y);
		a[y]=1;
	}
	for(int i=0;;i++)
	{
		if(!a[x-i])
		{
			printf("%d\n",x-i);
			break;
		}
		if(!a[x+i])
		{
			printf("%d\n",x+i);
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 3868
"use strict"

function main(input) {

    let num = Number(input.split('\n')[0])
    let n = input.length
    let tmp = num
    let sum = 0
    for (let i = 1; i <= n; i++) {
        sum += tmp % 10 //一の位
        tmp = Math.floor(tmp / 10) //一桁削る
            // or 
            //tmp = (tmp-(tmp % 10) / 10
    }
    if (num % sum == 0) console.log('Yes')
    else console.log('No')
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctype.h>
using namespace std;

int main ()
{
   int year,money;
   scanf("%d%d", &year, &money);
   int cost;
   if(year >= 13)
        cost = money;
    else if(year >= 6 && year <=12)
        cost = money/2;
    else if(year <=5)
        cost = 0;
    cout << cost << endl;
        return 0;
}


Measured memory_bytes: 256
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var str = ReadLine();
        var charaCounter = new Dictionary<string, int>();
        for(var i = 0; i < str.Length; i++)
        {
            if (charaCounter.ContainsKey(str.Substring(i, 1))) charaCounter[str.Substring(i, 1)]++;
            else charaCounter[str.Substring(i, 1)] = 1;
        }
        var result = charaCounter.Count ==charaCounter.Count(c=>c.Value%2==0) ? "Yes" : "No";
        WriteLine(result);
    }
}

Measured memory_bytes: 13152
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <map>

typedef long long ll;
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ALL(a) begin(a), end(a)
#define mii map<int, int>
#define msi map<string, int>
#define vi vector<int>
#define vl vector<ll>
#define MOD 1000000007
#define INF 1e9
#define showVector(v) rep(i,0,v.size()){p(v[i]);p(" ")} pl("")
#define p(s) std::cout << s ;
#define pl(s)  std::cout << s << endl;
using namespace std;

// 素数判定 O(√n)
bool is_prime(int n){
    for(int i = 2; i * i <= n; i++){
        if(n % i == 0) return false;
    }
    return true;
}

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;
}
int main() {
    int n, W;
    int v[110], w[110];
    ll dp[110][100010];
    cin >> n >> W;

    rep(i, 0, n) {
        cin >> w[i] >> v[i];
    }

    rep(i, 0, n) {
        rep(j, 0, W+1) {
            if (w[i] <= j) {
                dp[i+1][j] = max(dp[i][j-w[i]] + v[i], dp[i][j]);
            } else { // w[i]が入らない場合は前のまま
                dp[i+1][j] = dp[i][j];
            }
        }
    }
    cout << dp[n][W] << endl;
    return 0;
}


Measured memory_bytes: 80384
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const long long mod=1e9+7;
long long dp[11111],ddp[11111],n,sz;
char s[11111];
int main()
{
	scanf("%lld",&n);
	scanf("%s",s);
	sz=strlen(s);
	ddp[0]=1;
	for (int i=1;i<=n;i++)
	{
		for (int j=0;j<=sz+n;j++)
		{
			if (!j)
			{
				dp[j]=(ddp[j]+ddp[j+1]*2)%mod;
			}
			else dp[j]=(ddp[j-1]+ddp[j+1]*2)%mod;
		}
		for (int j=0;j<=sz+n;j++)
		{
			ddp[j]=dp[j];
		}
	}
	printf("%lld\n",dp[sz]);
	return 0;
}

Measured memory_bytes: 384
def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]


prime_list = primes(100000)
ruiseki = [0] * 100010
tmp = 0

for i in prime_list:
    if int((i+1)/2) in prime_list:
        for j in range(1,i - tmp + 1):
            ruiseki[tmp+j] = ruiseki[tmp]
        ruiseki[i] += 1
        tmp = i
    if i == prime_list[-1]:
        for i in range(tmp,100000):
            ruiseki[i+1] = ruiseki[i]

Q = int(input())
l,r = [],[]
for i in range(Q):
    a,b = map(int,input().split())
    l.append(a)
    r.append(b)

for i in range(Q):
    print(ruiseki[r[i]] - ruiseki[l[i]-1])


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

int main(){
    ll s;
    cin >> s;
    ll v = 1000000000;
    ll x = (v-s % v)%v;
    ll y = (s+x) / v;
    printf("0 0 1000000000 1 %lld %lld\n", x, y);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
  	ll n , a , b;
 	cin >> n >> a >> b;
  	ll dif = b - a - 1;
  	if(dif%2 == 1){
    	cout << "Alice\n"; return 0;
    }else cout << "Borys\n";
	return 0;
}

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

int main()
{
  uint64_t n;

  cin >> n;
  vector<uint64_t> b;
  b.resize(n + 1);
  for (uint64_t i = 1; i <= n; ++i) {
    cin >> b[i];
  }
  uint64_t m = 0;
  for (uint64_t i = n; i > 0; --i) {
    for (uint64_t j = 2; i * j <= n; ++j) {
      b[i] += b[i * j];
      b[i] &= 1;
    }
    m += b[i];
  }
  cout << m << endl;
  for (uint64_t i = 1; i <= n; ++i) {
    if (b[i]) {
      cout << i << endl;
    }
  }

  return 0;
}



Measured memory_bytes: 2432
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#############
# Main Code #
#############

X,t = inputIL()

print(max(0,X-t))

Measured memory_bytes: 65260
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;

long long N, M;

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

	cin >> N >> M;

	long long oneshot = 100 * (N - M) + 1900 * M;
	long long t = 1;
	for(int i=1; i<=M; i++){
		t *= 2;
	}
	long long ans = oneshot * t;
	printf("%lld\n", ans);
	return 0;
}

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

long long int lcm(long long int a, long long int b){
    long long int r, x = a * b;
    r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return x / b;
}


int main(){
    long long int A, B, C, D;
    long long int cnt = 0;
    cin >> A >> B >> C >> D;
    long long int lc = lcm(D, C);

    long long int num = (B / lc) - ((A- 1) / lc);
    long long int Cnum = (B / C) - ((A - 1) / C);
    long long int Dnum = (B / D) - ((A - 1) / D);
    cnt = (B - A + 1) - Cnum - Dnum + num;

    // cout << "[num]:" << num << " [Cnum]:" << Cnum << " [Dnum]:" << Dnum << endl; 
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
def popularity(votes, N, M):

  total_votes = sum(votes)
  limit = total_votes / (4.0 * M)
  cnt = 0
  for vote in votes:
    if vote >= limit:
      cnt += 1
    if cnt >= M:
      return "Yes"

  return "No"
  
N, M = [int (x) for x in input().split()]
votes = [int (x) for x in input().split()]
print(popularity(votes, N, M))

Measured memory_bytes: 3060
import itertools 
N,M,Q = map(int,input().split())
ans = 0
search_list = list(range(M))
value_list = [[0]*4 for _ in range(Q)]
for i in range(Q):
    value_list[i]=list(map(int,input().split()))
for i in itertools.combinations_with_replacement(search_list,N):
    value = 0
    for test in value_list:
        if(i[test[1]-1]-i[test[0]-1]==test[2]):
            value+=test[3]
    ans = max(ans,value)
print(ans)
    

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

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

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

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

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

int main() {
	char in1[3], in2[3];
	scanf("%s %s", in1, in2);

	if (in1[0] == 'D') in2[0] ^= 'H' ^ 'D';
	return !printf("%c\n", in2[0]);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F(i,a,b) for(int i=a;i<b;i++)
#define f(i,n) for(int i=0;i<n;i++)
typedef unsigned long long ull;
typedef long long ll;
#define pb(a) push_back(a);
#define bug(x) cout<<#x<<" = "<<x<<endl;

// const int MAXI=100001;
// ll **dp;
// ll ans(int a[][2],int i,int w,int n){
// 	// bug(i); bug(w);
// 	if(i>n-1 || i<0){return 0;}
// 	if(w==0){ return 0; }
// 	// if(dp[i][w]!=-1){return dp[i][w];}
// 	if(w-a[i][0]<0){ 	
// 		return ans(a,i-1,w,n); 
// 	}
// 	return max( a[i][1] + ans(a,i-1,w-a[i][0],n), ans(a,i-1,w,n));
// }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n,w;
	cin>>n>>w;
	int a[n][2];
	// cout<<"chalo"<<endl;
	f(i,n){
		cin>>a[i][0]>>a[i][1];
	}
	// cout<<"chalo"</<endl;
	// memset(dp,-1,sizeof(dp));
	// cout<<ans(a,n-1,w,n)<<endl;
	ll dp[n+1][w+1];
	// cout<<"jhelo"<<endl;
	for (int i = 0; i <= n; i++)
	{	
		// bug(i);
		for (int j = 0; j <= w; j++)
		{	
			// bug(j);
			if(j==0 || i==0){
				dp[i][j]=0;
			}
			else if(j - a[i-1][0]>=0){
				dp[i][j] = max(a[i-1][1] + dp[i-1][j-a[i-1][0]],dp[i-1][j]);
			}
			else{
				dp[i][j] = dp[i-1][j];
			}
			// cout<<dp[i][j]<<" ";
		}
		// cout<<"\n";
		// cout<<endl;
	}
	cout<<dp[n][w]<<endl;
	
	return 0;
}

Measured memory_bytes: 79232
def main():
	N = int(input())
	A = [[] for i in range(N)]
	# A[i][j] -> i-th person's testimony of person's honesty (j makes no sense)
	for i in range(N):
		a = int(input())
		for j in range(a):
			x, y = [int(b) for b in input().split(" ")]
			A[i].append([x - 1, str(y)])

	cand = []
	for i in range(2 ** N):
		honest_flag = True
		bit = list(pad_zero(format(i, 'b'), N))
		honests = [int(p) for p, q in enumerate(bit) if q == "1"]
		for honest in honests:
			w = A[honest]
			for k in range(len(w)):
				if w[k][1] != bit[w[k][0]]:
					honest_flag = False
		if honest_flag:
			cand.append(len(honests))

	print(max(cand))


def pad_zero(s, n):
	s = str(s)
	return ("0" * n + s)[-n:]

main()

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

int main(){
  string S;
  cin >> S;
  if((S.at(2)==S.at(3))&&(S.at(4)==S.at(5))){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


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

int main(){
    
    int a,b;
    char op;
    //cin >>a >> b >> op;
    
    while(1){
         cin >>a >> op >> b;
         if(op == '?') break;
         
         if(op == '+') cout << a + b << endl;
         else if(op == '-') cout << a - b << endl;
         else if(op == '*') cout << a * b << endl;
         else if(op == '/') cout << a / b << endl;
     }
    
    return 0;
    
}


Measured memory_bytes: 3104
#include <iostream>
#include <cstring>
#include <cmath> 
#include <algorithm>

using namespace std;

const int maxn=1e5+10;
int n,k;
int a[maxn],b[maxn],c[maxn];
int fa[maxn],fb[maxn],fc[maxn];

int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i]>>b[i]>>c[i];
	}
	for(int i=1;i<=n;i++)
	{
		fa[i]=a[i]+max(fb[i-1],fc[i-1]);
		fb[i]=b[i]+max(fa[i-1],fc[i-1]);
		fc[i]=c[i]+max(fb[i-1],fa[i-1]);
	}
	cout<<max(max(fa[n],fb[n]),fc[n])<<endl;
    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <math.h>
// #include <string>
// #include <vector>
// #include <set>
// #include <queue>
// #include <stack>
// #include <algorithm>

using namespace std;

int X;

int main(){
    cin >> X;
    for (int A = -121; A < 121; ++A){
        for(int B = -121; B < 121; ++B){
            if(A*A*A*A*A - B*B*B*B*B == X) {cout << A << " " << B; return 0;}
        }
    }
    return 0;
}

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

using namespace std;

long long gcd(long long a, long long b)
{
    if(a < b){
        swap(a, b);
    }

    while (b)
    {
        long long m = a % b;
        a = b;
        b = m;
    }
    return a;
}

long long lcm(long long number1, long long number2)
{
    return number1 * number2 / gcd(number1, number2);
}

int main()
{
    long long a, b, c, d, cd;
    cin >> a >> b >> c >> d;
    long long num_c, num_d, num_cd;

    num_c = b / c - (a - 1) / c;
    num_d = b / d - (a - 1) / d;
    cd = lcm(c, d);
    num_cd = b / cd - (a - 1) / cd;

    cout << (b - a + 1) - (num_c + num_d - num_cd) << endl;
}

Measured memory_bytes: 256
n,m = gets.split.map(&:to_i)
a=Array.new(n).map{Array.new()}
n.times do |i|
  a[i] = gets.split.map(&:to_i)
end
b=[]
m.times do
  b<<gets.to_i
end

n.times do |i|
  sum = 0
  m.times do |j|
    sum = sum+a[i][j]*b[j]
  end
  puts sum
end


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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

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

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define MAX_N 100
i64 N;
i64 B[MAX_N];

void solve() {
  i64 s = B[0];

  REPS(i, N - 1) {
    s += min(B[i], B[i - 1]);
  }

  cout << s << endl;
}

int main() {
  cin >> N;
  REP(i, N - 1) cin >> B[i];
  B[N - 1] = B[N - 2];

  solve();

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

struct UnionFind{
  vector<int> par;
  UnionFind(int n) : par(n, -1){}
  int root(int x){ return (par[x] < 0) ? x : par[x] = root(par[x]); }
  int size(int x){ return -par[root(x)]; }
  bool issame(int x, int y){ return root(x) == root(y); }
  void marge(int x, int y){
    x = root(x); y = root(y);
    if(x == y) return;
    if(x > y) swap(x, y);
    par[x] += par[y];
    par[y] = x;
  }
};

vector<int> to[100000], block[100000];

int main(void){
  int n, m, k;
  cin >> n >> m >> k;
  UnionFind uf(n);
  REP(i, m){
    int a, b;
    cin >> a >> b;
    a--; b--;
    to[a].emplace_back(b);
    to[b].emplace_back(a);
    uf.marge(a, b);
  }
  REP(i, k){
    int c, d;
    cin >> c >> d;
    c--; d--;
    block[c].emplace_back(d);
    block[d].emplace_back(c);
  }

  vector<int> ans(n);
  REP(i, n){
    ans[i] = uf.size(i) - 1;
    for(int v : to[i]) if(uf.issame(i, v)) ans[i]--;
    for(int v : block[i]) if(uf.issame(i, v)) ans[i]--;
  }

  REP(i, n) printf("%d ", ans[i]);
  printf("\n");
  return 0;
}

Measured memory_bytes: 12536
retsu=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(retsu[int(input())-1])

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

using namespace std;

int main(){
    string s, t;
    cin >> s >> t;
    
    s += s;
    if (s.find(t) == string::npos){
        cout << "No" << endl;
    }
    else{
        cout << "Yes" << endl;
    }
    return 0;
}

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

int main() {
  int a, b; cin >> a >> b;
  if(a == 1) a = 100;
  if(b == 1) b = 100;

  if(a > b) cout << "Alice" << endl;
  else if(a == b) cout << "Draw" << endl;
  else cout << "Bob" <<endl;
}


Measured memory_bytes: 256
K = int(input())
if  K==1:
	print("ACL")
elif K==2:
    print("ACLACL")
elif K==3:
    print("ACLACLACL")
elif K==4:
    print("ACLACLACLACL")
elif K==5:
    print("ACLACLACLACLACL")

Measured memory_bytes: 61608
n = gets.to_i
hs = gets.split(' ').map{|n| n.to_i}
moves, moves_max = 0, 0
prev = hs.shift
hs.each_with_index do |h, i|
  if h <= prev
    moves += 1
  else
    moves_max = moves if moves > moves_max
    moves = 0
  end
  prev = h
end
p [moves, moves_max].max

Measured memory_bytes: 8580
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] targets = new int[m];
        for (int i = 0; i < m; i++) {
            targets[i] = sc.nextInt();
        }
        int[] points = new int[n + 1];
        for (int i = 0; i < m; i++) {
            int bonus = 0;
            for (int j = 1; j <= n; j++) {
                int x = sc.nextInt();
                if (x == targets[i]) {
                    points[j]++;
                } else {
                    bonus++;
                }
            }
            points[targets[i]] += bonus;
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 1; i <= n; i++) {
            sb.append(points[i]).append("\n");
        }
        System.out.print(sb);
    }
}


Measured memory_bytes: 39896
#include<iostream>
#include <vector>
#include <algorithm>

using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> vec(n);
    int sum=0;
    for(int i=0;i<n;i++){
    cin >>vec.at(i);
}
    sort(vec.begin(),vec.end());
    reverse(vec.begin(),vec.end());
    for(int i=1;i<n;i++){
    sum+=vec.at(i);
    }
    sum += vec.at(0)/2;
    cout << sum <<endl;
}

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

#define LL long long

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    
    int n; n = 55555;
    vector<bool> is_prime(n+1, true);
    is_prime[0] = is_prime[1] = 0;
    for (int i = 2; i <= n; i++) {
        if (is_prime[i] && (long long)i * i <= n) {
            for (int j = i * i; j <= n; j += i)
                is_prime[j] = false;
        }
    }    

    vector<int> v;
    for(int i = 2; i <= 55555; i++) 
        if(is_prime[i] && i % 5 == 1) 
            v.push_back(i);

    cin >> n;
    for(int i = 0; i < n; i++) cout << v[i] << " ";
}

Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
//FILE *fi=freopen("1.txt","r",stdin);
struct toado{
    double x,y;
};
double kq;
double dem=0.0;
int n;
int x[9];
bool f[9];
toado a[9];
double dos(double x)
{
    return x*x;
}
double tinh(toado a,toado  b)
{
    return sqrt(dos(a.x-b.x)+dos(b.y-a.y));
}
double check()
{
    double kq=0;
    for(int i=2;i<=n;i++)
    {
        kq+=tinh(a[x[i]],a[x[i-1]]);
    }
    return kq;
}
void trys(int i)
{
    for(int j=1;j<=n;j++)
    {
        if(f[j])
            continue;
        x[i]=j;
        f[j]=true;
        if(i==n)
        {
            kq+=check();
            dem+=1.0;
        }
        else
            trys(i+1);
        f[j]=false;
    }
}
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i].x>>a[i].y;
    trys(1);
    kq/=dem;
    printf("%.8f",kq);
    return 0;
}


Measured memory_bytes: 256