akhauriyash/Code-Regression huggingface dataset:
import sys
sys.setrecursionlimit(10**6)
INF = 10**7
n = int(input())
edge = [[] for _ in range(n)]
for i in range(n - 1):
    u, v = [int(item) - 1 for item in input().split()]
    edge[u].append(v)
    edge[v].append(u)
k = int(input())
number = [-INF] * n
for i in range(k):
    v, c = [int(item) for item in input().split()]
    number[v - 1] = c

min_c = [-INF] * n
max_c = [INF] * n
odd = [-1] * n

def dfs(v, prev):
    if len(edge[v]) == 1 and prev is not -1:
        if number[v] != -INF:
            min_c[v] = number[v]
            max_c[v] = number[v]
            odd[v] = number[v] % 2
        return
    l = -INF; r = INF
    for item in edge[v]:
        if item == prev:
            continue
        dfs(item, v)
        if odd[v] == -1 and odd[item] != -1:
            odd[v] = (odd[item] + 1) % 2
        l = max(l, min_c[item] - 1)
        r = min(r, max_c[item] + 1)
        if odd[item] is not -1 and odd[v] == odd[item]:
            print("No")
            exit()
    min_c[v] = l
    max_c[v] = r
    if l > r:
        print("No")
        exit()
    if r == l and r % 2 != odd[v]:
        print("No")
        exit()
    if number[v] != -INF:
        if not l <= number[v] <= r:
            print("No")
            exit()
        min_c[v] = number[v]
        max_c[v] = number[v]
        odd[v] = number[v] % 2
    return

ans = [-INF] * n
def build(v, prev):
    if prev == -1:
        for item in range(min_c[v], max_c[v]+1):
            if item % 2 == odd[v] or odd[v] == -1:
                ans[v] = item
                break
    else:
        if min_c[v] <= ans[prev] + 1 <= max_c[v]:
            ans[v] = ans[prev] + 1
        else:
            ans[v] = ans[prev] - 1
    for item in edge[v]:
        if item == prev:
            continue
        build(item, v)
    return
        
dfs(0, -1)
print("Yes")        
build(0, -1)
for item in ans:
    print(item)

Measured memory_bytes: 123532
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;

double p[200010];
double psum[200010];

void solve(){

    int n,k;
    cin >> n >> k;
    rep(i,n){
        cin >> p[i];
        p[i] = (p[i]+1)/2;
    }
    //期待値は出る目の最大値をcとして、(1+2+...+c)/c=(c+1)/2

    //psum[i]:p[i]からp[i+k-1]までの合計
    psum[0]=0;
    rep(i,k){
        psum[0] += p[i];
    }
    for(int i=1; i<n-k+1; i++){
        psum[i]=psum[i-1]-p[i-1]+p[i+k-1];
    }

    double ans = 0;
    rep(i,n-k+1){
        ans = max(ans, psum[i]);
        //cout << psum[i] << " ";
    }
    //cout << endl;

    cout << std::setprecision(12) << ans << endl;

}

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


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

#define FASTIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using ll = long long;

const int MOD = 1e9+7;

ll modpower(ll x, ll y) {
    ll res = 1;
    x %= MOD;
    if(!x) return 0;
    while(y) {
        if(y&1) res = (res*x)%MOD;
        x = (x*x)%MOD;
        y >>= 1;
    }
    return res;
}

int main() {
    FASTIO

    ll n;
    cin >> n;
    ll ans = modpower(10,n) - 2*modpower(9,n) + modpower(8,n);
    if(ans < 0) ans += 2*MOD;
    ans %= MOD;
    cout << ans << "\n";
    
    return 0;
}

Measured memory_bytes: 3640
import java.util.*;

public class Main {
	
	public static final int[] PRIME = new int[]{3 * 5 * 7, 3 * 5 * 11, 3 * 5 * 13, 3 * 3 * 3 * 5, 3 * 3 * 3 * 7};
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int count = 0;
		for (int i = 0; i < PRIME.length; i++) {
			if (PRIME[i] <= n) {
				count++;
			}
		}
		
		System.out.println(count);
	}
}

Measured memory_bytes: 21844
import java.util.Scanner;

public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long power = 1;
        for (int i = 0; i < n; i++) {
            power *= (i + 1);
            power %= (1000000000 + 7);
        }
        

        System.out.println(power);
    }

}

Measured memory_bytes: 21588
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define vpll vector < pair<long long,long long> >
#define fill(a,val)  memset(a,val, sizeof (a))
#define sort_unique(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define all(cont) cont.begin(), cont.end()
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define max4(a,b,c,d) max(max(a,d),max(b,c))
#define MAX   1e9
#define MIN  -1e9
#define PI 3.14159265358979
#define eps 1e-9
typedef map<int,int> mpi;
typedef set<int> seti;
typedef multiset<int> mseti;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define rep(i, n)    for(long long int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(long long int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(long long int i = a; i >= (n); --i)
#define repn(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define trav(a, x) for(auto& a : x)
#define dbg(x) cout << #x << " = " << x << '\n'
#define dbg2(x,y) cout<<#x<<" = "<<x<<" & "<<#y<<" = "<<y<<endl
#define inp(a,start,len) for(long long int i = start;i < len;i++) cin>>a[i]
struct Interval{ll start,end;};
bool compare(Interval i1, Interval i2) {return (i1.start < i2.start);}

ll dp[100005];
int main(){
	fio;
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	ll T = 1;
	// cin>>T;
	while(T--){
		string s;
		cin>>s;
		ll len = s.length();
		if(s[len-1] == 's')
			cout<<s+"es";
		else
			cout<<s+"s";
	}
	return 0;
}


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

typedef std::pair<int, int> ipair;
#define pb push_back
#define ff first
#define ss second
#define fr(i, j, k) for (int i = j; i < k; i++)
#define rf(i, j, k) for (int i = j; i >= k;i--)
#define int long long
#define ld long double
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(),x.rend()
#define mp make_pair

const int mod = 1000000007;
const ld pi = acos(-1);
const int maxn = 200006;

template<class T> ostream& operator <<(ostream &out,vector<T> &A){for(auto x:A) out<<x<<" ";return out;}
template <class T1,class T2>T1 powr(T1 a,T2 b){T1 res = 1;fr(i,1,b+1)res = res*a;return res;}
#define IOS  std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int32_t main(){
  int n,m;  cin>>n>>m;
  m = 2*m+1;
  cout<<ceil(n/(double)m);
}


Measured memory_bytes: 256
#include <vector>
#include <sstream>
#include <algorithm>
#include <fstream>
#include <list>
#include <map>
#include <istream>
#include <bitset>
#include <sstream>
#include <unordered_map>
#include <stack>
#include <set>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <queue>
#include <string>

// #define int long long
#define ull unsigned long long
#define endl "\n"
#define all(x) x.begin(),x.end()
#define rr return 0
#define xx first
#define yy second
#define pii pair<int,int>

using namespace std;

typedef long long ll;
typedef long double ld;

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int a, p;
    cin >> a >> p;
    cout << (3 * a + p) / 2;
    rr;
}


Measured memory_bytes: 256
N = int(input())
e = [[int(i) for i in input().split()] for i in range(N)]

from operator import itemgetter
              
se = sorted(e, key=itemgetter(1))
#print(se)
flg = 0
sm = 0
for i in range(N):
	sm += se[i][0]
	if sm > se[i][1]:
		print('No')
		break
#print(i)
if i == N-1 and sm <= se[N-1][1]:
	print('Yes')

Measured memory_bytes: 42840
#include <bits/stdc++.h>
#include <cstdlib>  // abs() for integer 絶対値求めやつ
#include <cmath>    // abs() for float, and fabs()
#include <algorithm>
#define _GLIBCXX_DEBUG//.at(i)を[i]と書いても許される
#include <vector>
#include <string>
#define rep(i,n) for(int i = 0; i < (n);i++)
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
using namespace std;
#define INF 2000000000
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 che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
int n;
int main(){
	cin >> n;
	int min = 111000;
	int max = 0;
	rep(i,n){
		int a;
		cin >> a;
		chmax(max,a);
		chmin(min,a);
	}
	cout<<max-min<<endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
const int g = 998244353;

int main() {
    int n, x[200], y[200], p[201];
    cin >> n;
    p[0] = 1;
    for(int i = 0; i < n; i++) {
        cin >> x[i] >> y[i];
        p[i+1] = p[i] * 2 % g;
    }
    int a = p[n];
    for(int i = 0; i < n; i++) {
        for(int j = i + 1; j < n; j++) {
            int d = 0;
            for(int k = j + 1; k - n; k++) {
                d += (x[j] - x[i]) * (y[k] - y[i]) == (x[k] - x[i]) * (y[j] - y[i]);
            }
            a = (a + g - p[d]) % g;
        }
    }
    cout << (a + g - 1 - n) % g << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
p = list(map(int,input().split()))
cnt = 0
for i in range(1,n - 1):
    if p[i - 1] < p[i] < p[i + 1] or p[i - 1] > p[i] > p[i + 1]:
        cnt += 1
print(cnt)

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

#define pii pair<int, int>
#define endl "\n"
// #define int long long
#define F first
#define S second
#define B begin
#define E end
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
const int INF = 1e9 + 1;
const double EPS = 1e-10;
const ll P = 1e9 + 7;
const ll Q = 31;
 
using namespace std;
 
void hello()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}
 
void show(vector<int>& arr)
{
    for (auto i : arr)
        cout << i << " ";
    cout << endl;
}
void show(vector<vector<int>>& arr)
{
    for (auto i : arr)
        show(i);
    cout << endl;
}

 
signed main()
{
    hello();

    int n;
    cin >> n;
    vector <vector <pii>> graph(n);

    for (int i = 0; i < n; ++i)
    {
        int sz;
        cin >> sz;
        graph[i].resize(sz);
        for (int j = 0; j < sz; ++j)
        {
            int x, y;
            cin >> x >> y;
            --x;
            graph[i][j] = {x, y};
        }
    }

    int res = 0;
    for (int mask = 1; mask < (1 << n); ++mask)
    {
        bool flag = 0;
        for (int i = 0; i < n; ++i)
        {
            if (!(mask & (1 << i)))
                continue;
            for (auto j : graph[i])
            {
                if ((bool)(mask & (1 << j.F)) != j.S)
                    flag = 1;
            }
        }
        if (flag == 1)
            continue;
        res = max(res, __builtin_popcount(mask));
    }

    cout << res << endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

const int mod = 1e9+7;

ll dp[100005][5];

void add(ll &a, ll b){
    a += b;
    if(a >= mod) a -= mod;
}

int main(){
    string s; 
    cin >> s;
    memset(dp, 0, sizeof(dp));
    dp[0][0] = 1;
    for(int i = 0; i < s.size(); i++){
        /*
        for(int j = 0; j < 5; j++){
            //ABCの場所を選ばない場合
            if(s[i] != '?') add(dp[i+1][j], dp[i][j]);
            else add(dp[i+1][j], dp[i][j] * 3 % mod);
        }
        */
        //ABCの場所を選ぶ場合
        if(s[i] == 'A' || s[i] == '?') add(dp[i+1][1], dp[i][0]);
        if(s[i] == 'B' || s[i] == '?') add(dp[i+1][2], dp[i][1]);
        if(s[i] == 'C' || s[i] == '?') add(dp[i+1][3], dp[i][2]);
        
        for(int j = 0; j < 5; j++){
            //ABCの場所を選ばない場合
            if(s[i] != '?') add(dp[i+1][j], dp[i][j]);
            else add(dp[i+1][j], dp[i][j] * 3 % mod);
        }
        
    }
    cout << dp[s.size()][3] << endl;
}

Measured memory_bytes: 7636
#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


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);  
    int H, W;
    cin >> H >> W;
    rep(i, H) {
        rep(j, W) {
            string S; cin >> S;
            if (S == "snuke") {
                cout << (char)(j + 'A') << i + 1 << endl;
                return 0;
            }
        }
    }


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int MOD = 1000000007;
const int INF = 1e12;
using Graph = vector<vector<int>>;

vector<int> Zalgo( const string &S ){
  int c = 0;
  int N = (int)S.size();
  vector<int> Z(N+10, 0);
  for( int i = 1; i < N; i++ ){
    int l = i-c;
    if( i+Z[l] < c+Z[c] ) Z[i] = Z[l];
    else{
      int j = max(0LL, c+Z[c]-i);
      while( i+j < N && S[j] == S[i+j] ) j++;
      Z[i] = j;
      c = i;
    }
  }
  Z[0] = N;
  return Z;
}

signed main(){
  int N;
  cin >> N;
  string S;
  cin >> S;
  int ans = 0;
  for( int i = 0; i < N; i++ ){
    string T = S.substr(i);
    vector<int> Z = Zalgo(T);
    for( int j = 0; j <= T.size(); j++ ){
      if( Z[j] <= j ) ans = max(ans, Z[j]);
    }
  }
  cout << ans << endl;

}


Measured memory_bytes: 3692
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e7+7;
ll a,b,c,p=0,k=0;
int d[maxn];

void is_prime(ll n){
	int cnt=0;
	for(ll i=2;i*i<n;i++){
		if(n%i==0) d[k++]=i;
		while(n%i==0){
			n/=i;
		}
	}
	if(n>1){
		d[k++]=n;
	}
}
int main()
{
	
	cin>>a>>b;
	c=__gcd(a,b);
	is_prime(c);
	cout<<++k;
	
		
	return 0;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
 
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    int a[n],i,s=0;
    for(i=0;i<n;i++){
        cin>>a[i];
        s+=a[i];
    }
    int k=0;
    for(i=0;i<n;i++)
        if(a[i]>=((.25*s)/m)) k++;
        
    if(k>=m) cout<<"Yes";
    else cout<<"No";
}

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

int main() {
	int n,p;
	while (cin >> n>>p) {
		if (!n)break;
		int ans = -1, i = 0;
		vector<int> v(n,0);
		int c = p;
		
		while (ans<0) {
			for (i=0; i < n; ++i) {
				if (!c) {
					c = v[i];
					v[i] = 0;
				}else{
					v[i]++;
					c--;
				}
				if (p == v[i]) {
					ans = i;
					break;
				}
				
			}
		}
		cout << ans << endl;
		
	}
	return 0;
}


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

#define int long long
#define rep(i, n) for (int i = 0; i < (int) (n); i++)
#define reps(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define bit(n) (1LL << (n))
#define cdiv(a, b) (((a) - 1) / (b) + 1)
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double PI = 3.1415926535897932384626433832795028;
constexpr int DY[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
constexpr int DX[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
int sgn(int x) { return (x > 0) - (x < 0); }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

long long mod_pow(long long a, long long n, int m) {
    a %= m;
    long long ret = 1;
    while (n) {
        if (n & 1) { (ret *= a) %= m; }
        (a *= a) %= m;
        n >>= 1;
    }
    return ret;
}

int N;
string X;
signed main() {
    cin >> N >> X;
    int p = 0;
    rep(i, N) { p += X[i] - '0'; }
    dump(p);
    auto f = [](int n) {
        dump(n);
        int ret = 0;
        while (n) {
            n %= __builtin_popcountll(n);
            ret++;
        }
        return ret;
    };
    map<int, int> mp;
    for (int i = -1; i <= 1; i++) {
        if (p + i < 1) { continue; }
        rep(j, N) {
            (mp[i] += (X[j] - '0') * mod_pow(2, N - j - 1, p + i)) %= (p + i);
        }
    }
    rep(j, N) {
        if (p == 1 && X[j] == '1') {
            cout << 0 << endl;
            continue;
        }
        int i = X[j] == '0' ? 1 : -1;
        cout << f((mp[i] + p + i + mod_pow(2, N - j - 1, p + i) * i) % (p + i)) + 1 << endl;
    }

}

Measured memory_bytes: 3756
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)

void chmax(ll& a, ll b) { a = max(a, b); }
void chmin(ll& a, ll b) { a = min(a, b); }

using P = pair<ll, ll>;
const ll INF = 1e18;

ll dp[2005][2005];


int main() {
    int n; cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];

    rep(i, 2005) rep(j, 2005) dp[i][j] = -INF;
    dp[0][0] = 0;

    vector<P> p;
    rep(i, n) p.emplace_back(a[i], i);
    sort(p.rbegin(), p.rend());
    rep(i, n) {
        int pi = p[i].second;
        rep(l, i+1) {
            int r = i-l;
            chmax(dp[i+1][l+1], dp[i][l] + ll(pi-l)*a[pi]);
            chmax(dp[i+1][l], dp[i][l] + ll((n-r-1)-pi) * a[pi]);
        }
    }

    ll ans = 0;
    rep(i, n+1) chmax(ans, dp[n][i]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 35052
a = input()
n = len(a)-1
fg = ['+']*n
su = 0
s = ''
for i in range(2**n):
    s = ''
    fg = ['+']*n
    for j in range(n):
        if (i >> j) & 1:
            fg[j] = ""
        s = s+a[j]+fg[j]
    s = s+a[n]
    su = su+eval(s)
    
print(su)

Measured memory_bytes: 3064
#include <algorithm>
#include <cstdio>
#include <iostream>

using namespace std;

int main() {

	int n, m;
	scanf("%d %d", &n, &m);

	int INF = 50000;
	int L[n + 1];
	for (int i = 1; i <= n; ++i) {
		L[i] = INF;
	}
	L[0] = 0;

	int M[m];
	for (int i = 0; i < m; ++i) {
		scanf("%d", &M[i]);
	}

	for (int i = 0; i < m; ++i) {
		for (int j = M[i]; j <= n; ++j) {
			L[j] = min(L[j], L[j - M[i]] + 1);
		}
	}

	cout << L[n] << endl;

	return 0;
}

Measured memory_bytes: 3420
#include<bits/stdc++.h>
using namespace std;
#define vite ios_base::sync_with_stdio(false); cin.tie(NULL);
#define tst lli T; cin>>T; while(T--)
#define mod 1000000007
#define MAX 1e9
#define MIN -1e9
#define lli long long int
#define vt vector
#define pb push_back
int main()
{
    vite;
    lli n, t = 0;
    cin >> n;
    lli a[n];
    for (lli i = 0; i < n;i++)
        cin >> a[i];
    sort(a, a + n);
    t = a[n - 1];
    lli j = 2, i = n - 2;
    while(1)
    {
        if(j==n)
            break;
        if(j==n-1)
        {
            t += a[i];
            break;
        }    
        else 
        {
            t += 2 * a[i];
            i--;
            j += 2;
        }
    }

    cout << t;

    return 0;
}

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

#define ll          long long
#define ld          long double
#define pb          push_back
#define pf          push_front
#define mp          make_pair
#define pll         pair<ll,ll>
#define vl          vector<ll>
#define sl          set<ll> 
#define vll         vector<pll>
#define ml          map<ll,ll>
#define mll         map<pll,ll>
#define all(a)      a.begin(),a.end()
#define x           first
#define y           second
#define sz(x)       (ll)x.size()
#define dl          '\n'
//#define mod         (ll)1000000007
#define mod         (ll)998244353
#define lp(i,a,b)   for(ll i=a;i<b;++i)
#define lpr(i,a,b)  for(ll i=a;i>=b;i--)
#define lpd(i,x)    for(auto i:x)
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
ll inf = 1e18;
ld pi = 3.141592653589;

ll bpow(ll x, ll v) {   
    if (v == 0)
        return 1 % mod;
    if (v % 2 == 1)
        return (x * bpow(x, v - 1)) % mod;
    ll r = bpow(x, v / 2);
    return (r * r) % mod;   
}

ll solve(){ 
    ll k,n; cin>>k>>n;
    vl a(n); lp(i,0,n) cin>>a[i];
    ll diff = -1,in;
    lp(i,0,n-1){
        if(a[i+1]-a[i] > diff){
            diff = a[i+1]-a[i];
            in = i;
        }
    }
    if((k - a[n-1] + a[0]) > diff){
        in = n-1;
    }
    ll ans=0;
    lpr(i,in,1){
        ans+=a[i] - a[i-1];
    }
    if(in < n-1)
    ans+=a[0] + k - a[n-1];
    lpr(i,n-1,in+2){
        ans+=a[i]-a[i-1];
    }
    cout<<ans;
}
int main(){
    ios
    ll t=1; 
    //cin>>t;
    while(t--){
        solve();
    }
}

Measured memory_bytes: 1792
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;//for StringBuilder
class c
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var p = string.Join("", Array.ConvertAll(Console.ReadLine().Split(), int.Parse));
        var q = string.Join("", Array.ConvertAll(Console.ReadLine().Split(), int.Parse));
        var src = new List<int>();
        for (int i = 1; i <= n; i++) src.Add(i);
        var x = Permutations(src, n);
        var list = new List<string>();
        foreach (var item in x) list.Add(string.Join("", item));
        Console.WriteLine(Math.Abs(list.IndexOf(p) - list.IndexOf(q)));
    }
    static List<List<T>> Permutations<T>(List<T> src, int n)
    {
        // nは1以上かつsrcの長さよりも短い必要がある。
        int len = src.Count;
        if (!(0 < n && n <= len))
        {
            throw new ArgumentOutOfRangeException();
        }

        var permutations = new List<List<T>>();
        var queue = new Queue<List<int>>(Enumerable.Range(0, len).Select(i => new List<int>() { i }));
        while (queue.Any())
        {
            var indexes = queue.Dequeue();

            if (indexes.Count == n)
            {
                permutations.Add(indexes.Select(index => src[index]).ToList());
                continue;
            }

            for (int index = 0; index < len; index++)
            {
                if (indexes.Contains(index))
                {
                    continue;
                }

                var newIndexes = new List<int>(indexes);
                newIndexes.Add(index);
                queue.Enqueue(newIndexes);
            }
        }

        return permutations;
    }
}

Measured memory_bytes: 62708
import java.util.Scanner;



public class Main{
    public static final int MP = 200010; //MaxPassengers
    public static final int MSN = 100010; //MaxStationNumber
    public static class p{
        int bp; //boarding point
        int dp; //deplaning
    }
    public static void main(String[] args){
        int P1 = 0, P2 = 0;
        p[] pas = new p[MP]; //passenger
        int[] igo = new int[MSN]; //is getting on
        int[] agon = new int[MSN]; //already getting on
        int[] agoff= new int[MSN]; //already getting off 
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        for(int i = 0; i < n; i++){
            pas[i] = new p(); 
            pas[i].bp = Integer.parseInt(sc.next());
            pas[i].dp = Integer.parseInt(sc.next());
            igo[pas[i].bp]++;
            igo[pas[i].dp]--;
            agon[pas[i].bp]++;
            agoff[pas[i].dp]++;
        }
        for(int j = 1; j < MSN; j++){ //make Accumulation
            igo[j] += igo[j-1];
            agon[j] += agon[j-1];
            agoff[j] += agoff[j-1];
            if(P2 < igo[j]){ //Policy 2
                P2 = igo[j];
            }
        }
        for(int k = 0; k < n; k++){
            //i番目の人が降りる一つ前までの駅までに乗ってきた人数-i番目の人が乗る駅で降りている人数
            if(P1 < (agon[pas[k].dp - 1] - agoff[pas[k].bp])){ 
                P1 = agon[pas[k].dp - 1] - agoff[pas[k].bp];
            }
        }
        System.out.println(P1 + " " + P2);
        sc.close();   
    }
}


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

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using vld = vector<ld>;
using vvld = vector<vld>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()

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

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
const long long INF = 1LL << 60;

// prime factorization (素因数分解)
// key: value of prime factor
// value: number of prime factor
std::map<ll, ll> prime_factorization(ll n) {
  std::map<ll, ll> prime_factors;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      prime_factors[i]++;
      n /= i;
    }
  }
  if (n != 1)
    prime_factors[n] = 1;
  return prime_factors;
}

// 約数リスト
vector<ll> get_divisors(const ll n) {
  vector<ll> divs;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      divs.push_back(i);
      if (i != n / i) {
        divs.push_back(n / i);
      }
    }
  }

  // 必要に応じてソート
  sort(divs.begin(), divs.end());

  return divs;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  ll n;
  cin >> n;

  auto primes = prime_factorization(n);

  ll ans = 0;
#if 1
  for (auto it : primes) {
    ll v = it.second;
    ll tmp = 1;
    while (v >= tmp) {
      v -= tmp;
      ans++;
      tmp++;
    }
  }
#else
  auto divs = get_divisors(n);
  for (auto it : divs) {
    if (it == 1) {
      continue;
    }
    if (n % it == 0) {
      ans++;
      n /= it;
    }
  }
#endif
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3660
import java.io.*;
import java.util.*;

public class Main {

	static long pmod = 1000000007L;

	public static void main(String[] args) throws IOException {

//		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//		PrintWriter op = new PrintWriter(System.out);
//		StringTokenizer ste = new StringTokenizer(br.readLine());
//
//		StringBuilder ash = new StringBuilder();
//		for (int tcs = Integer.parseInt(ste.nextToken()) - 1; tcs >= 0; --tcs) {
//
//			ste = new StringTokenizer(br.readLine());
//			String s1 = ste.nextToken();
//
//		}
//		op.print(ash);
//		op.flush();
		Scanner scn = new Scanner(System.in);
		int k = scn.nextInt();
		String s = scn.next();
		if (s.length() <= k)
			System.out.println(s);
		else {
			System.out.println(s.substring(0,k) + "...");
		}

	}
}

Measured memory_bytes: 38668
i = 0
tyo = ei = don = 0
loop do
  nums = gets.split.map(&:to_i)
  a, b, c = nums.sort
  break if c >= a + b
  i += 1
  case a**2 + b**2 <=> c**2
  when -1
    don +=1
  when 0
    tyo += 1
  when 1
    ei += 1
  end
end
puts "#{i} #{tyo} #{ei} #{don}"



Measured memory_bytes: 6872
/* Dsingh_24 */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define ios	    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

#define N  100005

int main()
{
	ios
	ll n,m,i,j,x;
	cin>>n>>m>>x;
	ll c[n+1],a[n+1][m+1];
	for(i=0;i<n;i++){
		cin>>c[i];
		for(j=0;j<m;j++)
			cin>>a[i][j];
	}
	ll ans=hell;
	for(ll mask=1;mask<(1<<n);mask++){
		ll un[m+1]={0},cost=0;
		for(i=0;i<n;i++){
			if(mask&(1<<i)){
				cost+=c[i];
				for(j=0;j<m;j++)
					un[j]+=a[i][j];
			}
		}
		ll f=0;
		for(j=0;j<m;j++)
			if(un[j]<x)f=1;
		if(!f)ans=min(ans,cost);
	}
	if(ans==hell)cout<<"-1";else
	cout<<ans;
	return 0;
}

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

int main() {
  int H,W,i;
  cin>>H>>W;
  for(i=0;i<W+2;i++)cout<<"#";
  cout<<endl;
  for(i=0;i<H;i++){
    string S;
    cin>>S;
    S="#"+S+"#";
    cout<<S<<endl;
  }
   for(i=0;i<W+2;i++)cout<<"#";
  cout<<endl;
}


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

int main() {
    string S , T ;
    cin >> S ;
    cin >> T ;
    int s = S.length() ; 
    int change = 0 ;
    for (int i = 0 ; i < s ; i ++){
        if (S[i] != T[i]) change++ ; 
    }
    cout << change ;
	return 0;
}

Measured memory_bytes: 3856
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <utility>
#include <map>
#include <set>
#include <algorithm>
#include<cmath>

#define rep(i, a, b) for (int i=a; i <b; i++)
#define F first
#define S second

using namespace std;

typedef long long ll;
typedef vector< int > vi;


int main() {
    string s;
    unsigned long long k;
    cin >> s;
    cin >> k;
    for (int i=0; i < s.length(); i++) {
        if (s.compare(i, 1, to_string(1)) != 0) {
            cout << s[i] << endl;
            break;
        } else {
            if (i + 1== k) {
                cout << 1 << endl;
                break;
            }
        }
    }
    return 0;
}

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

int main() {
  int N, A, B, V;
  cin >> N;
   A = 0;
  for (int i = 0; i < N; i++){
    int l, r, s;
    cin >> l >> r;
    s = r - l + 1;
    A = A + s;}
  cout << A << endl;
}


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

#define faster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int MOD = 1e9 + 7;
const int INF = 1e9 + 5;
const int MAXN = 1e5+13;
const ll LINF = LLONG_MAX;
ll powmod (ll a,ll b) {ll res=1;a%=MOD; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}

int main() {
	faster;

	double n;

	cin >> n;
	cout << 2*3.141592653*n;

	return 0;
}

// READ
// THINK
// CODE
// DEBUG
// AC


Measured memory_bytes: 3796
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int k;
    cin >> k;
    string s;
    cin >> s;
    int n = s.size();
    if (n <= k) {
        cout << s << '\n';
    } else {
        cout << s.substr(0, k) << "...";
    }
    return 0;
}

Measured memory_bytes: 3596
import java.util.*;
 
public class Main{
	public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
      	int a = scan.nextInt();
      	int b = scan.nextInt();
      	int w = Math.max(a-b, a+b);
      	System.out.print(Math.max(w, a*b));
    }
}

Measured memory_bytes: 21844
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

const int N=100+50;
int n,m,visR[N],visC[N];
char a[N][N];

inline int read(){
	int x=0,f=1;char ch;
	for(ch=getchar();!isdigit(ch);ch=getchar())if(ch=='-')f=-1;
	for(;isdigit(ch);ch=getchar())x=(x<<3)+(x<<1)+ch-'0';
	return x*f;
}

int main(){
	n=read(),m=read();
	for(int i=1;i<=n;++i)scanf("%s",a[i]+1);
	for(int i=1;i<=n;++i){
		visR[i]=1;
		for(int j=1;j<=m;++j)if(a[i][j]=='#'){
			visR[i]=0;break;
		}
	}
	for(int i=1;i<=m;++i){
		visC[i]=1;
		for(int j=1;j<=n;++j)if(a[j][i]=='#'){
			visC[i]=0;break;
		}
	}
	for(int i=1;i<=n;++i)if(!visR[i]){
		for(int j=1;j<=m;++j)if(!visC[j])putchar(a[i][j]);
		puts("");
	}
	return 0;
}

Measured memory_bytes: 256
package main

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

const mod = 1000000007

// 1MB
const ioBufferSize = 1 * 1024 * 1024

var sc = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	sc.Split(bufio.ScanWords)
	return sc
}()

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

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

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	n, a, b := nextInt(), nextInt(), nextInt()

	res := n
	if (b-a)%2 == 0 {
		res = (b - a) / 2
	} else {
		res = min(a-1, n-b) + 1 + (b-a-1)/2
	}
	fmt.Println(res)
}


Measured memory_bytes: 640
n = int(input())
list_word = [input()]
for i in range(1, n):
  new_word = input()
  if list_word[-1][-1] != new_word[0] or new_word in list_word:
    print("No")
    exit()
  else:
    list_word.append(new_word)
print("Yes")

Measured memory_bytes: 2940
import sys
sys.setrecursionlimit(1000000)

def dfs(a):
    if len(a)==n:
        tmp=a[:]
        a_lis.append(tmp)
        return
    
    for i in range(m):
        if len(a)>0 and i<a[-1]:
            continue
        a.append(i)
        dfs(a)
        a.pop()

cnt=0        
n,m,q=map(int,input().split())
lis=[[int(i) for i in input().split()]for i in range(q)]
a_lis=[]

dfs([])
ans=0
for i in a_lis:
    score=0
    for a,b,c,d in lis:
        if i[b-1]-i[a-1]==c:
            score+=d
    ans=max(ans,score)
print(ans)

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

int main() {
  in(int, n, m);
  vector<int> inc(n), dec(n);
  rep(i, m) {
    in(int, l, r);
    ++inc[l - 1];
    ++dec[r - 1];
  }
  int ans = 0;
  int curr = 0;
  rep(i, n) {
    curr += inc[i];
    if (curr == m) ++ans;
    curr -= dec[i];
  }
  out(ans);
}


Measured memory_bytes: 4000
import java.math.BigInteger;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		BigInteger A = new BigInteger(sc.next()), B = new BigInteger(sc.next());
		sc.close();
		System.out.println(A.add(B));
	}
}


Measured memory_bytes: 76192
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cstdlib>
#include <math.h>
#include<map>
using namespace std;

int main(int argc,char** argv)
{

	int n;
	cin >> n;
	int a[n];
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	int nowpoint = 0;
	int cnt = 0;
	for(int i = 0; i < n; i++){
		if(nowpoint == 1){
			cout << cnt <<endl;
			return 0;
		}
		nowpoint = a[nowpoint]-1;
		cnt ++;
	}
	cout << -1 <<endl;

	return 0;

}

Measured memory_bytes: 640
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *L = map(int, read().split())

    s = sum(L)
    ok = True
    for l in L:
        if l >= s - l:
            ok = False
            break

    if ok:
        print('Yes')
    else:
        print('No')

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9124
import java.util.*;
import java.math.*;
public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = Integer.parseInt(in.next());
		String s = in.next();
		int[][] left = new int[n][3];
		int[][] right = new int[n][3];
		for(int i = 0; i < n - 1; i++) {
			left[i + 1][0] = left[i][0];
			left[i + 1][1] = left[i][1];
			left[i + 1][2] = left[i][2];
			if(s.charAt(i) == 'R') {
				left[i + 1][0] += 1;
			}else if(s.charAt(i) == 'B') {
				left[i + 1][1] += 1;
			}else {
				left[i + 1][2] += 1;
			}
		}
		for(int i = n - 1; i > 0; i--) {
			right[i - 1][0] = right[i][0];
			right[i - 1][1] = right[i][1];
			right[i - 1][2] = right[i][2];
			if(s.charAt(i) == 'R') {
				right[i - 1][0] += 1;
			}else if(s.charAt(i) == 'B') {
				right[i - 1][1] += 1;
			}else {
				right[i - 1][2] += 1;
			}
		}
		long ans = 0L;
		for(int i = 0; i < n; i++) {
			if(s.charAt(i) == 'R') {
				ans += left[i][1] * right[i][2];
				ans += left[i][2] * right[i][1];
			}else if(s.charAt(i) == 'B') {
				ans += left[i][0] * right[i][2];
				ans += left[i][2] * right[i][0];
			}else {
				ans += left[i][0] * right[i][1];
				ans += left[i][1] * right[i][0];
			}
		}
		for(int i = 0; i < n; i++) {
			for(int j = i + 2; j < n; j += 2) {
				int mid = (j - i) / 2;
				if(s.charAt(i) != s.charAt(j)) {
					if(s.charAt(i + mid) != s.charAt(i)) {
						if(s.charAt(i + mid) != s.charAt(j)) {
							ans -= 1;
						}
					}
				}
			}
		}
		System.out.println(ans);
	}
} 


Measured memory_bytes: 38212
import sys
def input():
    return sys.stdin.readline()[:-1]
N,M = map(int,input().split(' '))
l = list(map(int, input().split()))

cnt = 0
S = sum(l)
for i in range(N):
    if l[i]>=(S/(4*M)):
        cnt += 1

if cnt>=M:
    print('Yes')
else:
    print('No')

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define rep(i, n) REP(i, 0, n)
const int INF=1e9;
const int MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define ALL(v) v.begin(), v.end()
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbgmap(mp) for (auto i = mp.begin(); i != mp.end(); ++i) { cout << i->first <<":"<<i->second << endl;}
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b,c,d;

    cin>>a>>b>>c>>d;
    ll gcd = __gcd(c,d);
    ll lcd = c*d/gcd;
    a -=1;
    ll a1 = a/c;
    ll a2 = a/d;
    ll a3 = a/lcd;
    ll aa = a+a3-a1-a2;

    ll b1 = b/c;
    ll b2 = b/d;
    ll b3 = b/lcd;
    ll bb = b+b3-b1-b2;
    ll ans=0;
//    dbg(aa);
//    dbg(bb);
    ans = bb-aa;
    cout<<ans<<endl;
    return  0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int A, B;
    cin >> A >> B;
    vector<int> cnt(10000, 0);

    repd(i, 1, 10000) {
        if ((int)(i * 0.08) == A) {
            cnt[i]++;
        }
    }

    repd(i, 1, 10000) {
        if ((int)(i * 0.1) == B) {
            cnt[i]++;
        }
    }

    int ans = -1;
    rep(i, cnt.size()) {
        if (cnt[i] >= 2) {
            ans = i;
            break;
        }
    }

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

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <utility>

using namespace std;
typedef long long ll;
const int LEN = 100000;

struct fastio{
  int it,len;
  char s[LEN + 5];
  fastio(){
    it = len = 0;
  }
  char get(){
    if(it < len) return s[it++];
    it = 0, len = fread(s,1,LEN,stdin);
    return len ? s[it++] : EOF;
  }
  bool notend(){
    char c;
    for(c = get();c == ' ' || c == '\n';c = get());
    if(it) it--;
    return c != EOF;
  }
  void put(char c){
    if(it == LEN) fwrite(s,1,LEN,stdout), it = 0;
    s[it++] = c;
  }
  void flush(){
    fwrite(s,1,it,stdout);
  }
}buff,bufo;
inline int getint(){
  char c; int res = 0, sig = 1;
  for(c = buff.get();c < '0' || c > '9';c = buff.get()) if(c == '-') sig = -1;
  for(;c >= '0' && c <= '9';c = buff.get()) res = res * 10 + (c - '0');
  return sig * res;
}
inline ll getll(){
  char c; ll res = 0, sig = 1;
  for(c = buff.get();c < '0' || c > '9';c = buff.get()) if(c == '-') sig = -1;
  for(;c >= '0' && c <= '9';c = buff.get()) res = res * 10 + (c - '0');
  return sig * res;
}
inline void putint(int x,char suf){
  if(!x) bufo.put('0');
  else{
    if(x < 0) bufo.put('-'), x = -x;
    int k = 0; char s[15];
    while(x){
      s[++k] = x % 10 + '0';
      x /= 10;
    }
    for(;k;k--) bufo.put(s[k]);
  }
  bufo.put(suf);
}
inline void putll(ll x,char suf){
  if(!x) bufo.put('0');
  else{
    if(x < 0) bufo.put('-'), x = -x;
    int k = 0; char s[25];
    while(x){
      s[++k] = x % 10 + '0';
      x /= 10;
    }
    for(;k;k--) bufo.put(s[k]);
  }
  bufo.put(suf);
}
inline char get_char(){
  char c;
  for(c = buff.get();c == ' ' || c == '\n';c = buff.get());
  return c;
}
ll calc(ll x){
  if(x == 0) return 0;
  if(x == 1) return 1;
  return 2 * calc(x / 2) + 1;
}
int main(){
  ll x = getll();
  putll(calc(x),'\n');
  bufo.flush();
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int bubble_sort(int n, int A[])
{
    int i, j, v;
    int frag = 1;
    int count = 0;

    for (i=0; frag; i++)
    {
        frag = 0;

        for (j=n-1; j>=i+1; j--){
            if (A[j] < A[j-1]){
                // A[j]とA[j-1]をswap
                v = A[j];
                A[j] = A[j-1];
                A[j-1] = v;

                frag = 1;
                count++;
            }
        }
    }
    return count;
}

int main(void)
{
    int i;

    //データの読み取り
    int N;
    scanf("%d", &N);

    int A[N];
    for (i=0; i<N; i++)
        scanf("%d", &A[i]);

    //バブルソートの実行
    int count = bubble_sort(N, A);

    //出力
    for (i=0; i<N-1; i++)
        printf("%d ", A[i]);
    printf("%d\n", A[N-1]);
    printf("%d\n", count);

    return 0;
}


Measured memory_bytes: 2760
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include<iomanip>

#define MX 10000000000
#define mod 1000000007
#define ll long long int
#define pb(x) push_back(x)
#define MP(x,y) make_pair(x,y)

using namespace std;

ll power(ll a, ll b, ll m)
{
	if (b == 0)
		return(1);
	ll sol = power(a, b / 2, m);
	sol = (sol * sol) % m;
	if (b % 2 == 1)
		sol = (sol * a) % m;
	return(sol);
}

ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	else
	{
		return gcd(b, a % b);
	}
}
void solve()
{
	 int x;
	 cin >> x;
	 for (int i = 1; i <= 1000; i++)
	 {
		  if (x >= i * 100 && x <= 105 * i)
		  {
				cout << "1";
				return;
		  }
	 }
	 cout << "0";
}
int main()
{
	int t = 1;
	//cin >> t;
	while (t--)
	{
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
H = list(map(int, input().split()))
lst = [1] * n
for i in range(m):
    a, b = map(int, input().split())
    if H[a-1] > H[b-1]:
        lst[b-1] = 0
    elif H[a-1] < H[b-1]:
        lst[a-1] = 0
    elif H[a-1] == H[b-1]:
        lst[a-1] = 0
        lst[b-1] = 0

print(sum(lst))

Measured memory_bytes: 20072
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(n); ++i)
typedef long long ll;
ll gcd(ll x, ll y){
  if(y==0) return x;
  return gcd(y, x%y);
}
ll lcm(ll x, ll y){ return (x/gcd(x, y))*y;}
int main(){
  ll n, t, ans;
  ans = 1;
  cin >> n;
  rep(i,n){
    cin >> t;
    ans = lcm(ans, t);
  }
  cout << ans;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <vector>
#include <stack>
#include <map>
#include <bitset>
#define ri register
#define inf 0x7fffffff
#define E (1)
#define mk make_pair
#define int long long
#define double long double
using namespace std; const int N=200010;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch-'0'), ch=getchar();
    return s*w;
}
void print(int x) { if(x<0) x=-x, putchar('-'); if(x>9) print(x/10); putchar(x%10+'0'); }
int n,a[N],book[19][19],res; double t[N];
struct Node{int p,q; }e[N];
signed main()
{
    n=read();
    for(ri int i=1;i<=n;i++)
    {
        scanf("%Lf",&t[i]);
        t[i]*=1e9;
        a[i]=floor(t[i]+0.4);
    }
    for(ri int i=1;i<=n;i++)
    {
        int x=a[i];
        while(x%2==0) e[i].p++, x/=2;
        x=a[i];
        while(x%5==0) e[i].q++, x/=5;
        e[i].p=min(e[i].p,18ll);
        e[i].q=min(e[i].q,18ll);
    }
    for(ri int i=1;i<=n;i++) book[e[i].p][e[i].q]++;
    //for(ri int i=1;i<=n;i++) printf("%lld %lld\n",e[i].p,e[i].q);
    for(ri int i=0;i<=18;i++)
    {
        for(ri int j=0;j<=18;j++)
        {
            for(ri int x=0;x<=18;x++)
            {
                for(ri int y=0;y<=18;y++)
                {
                    if(i+x>=18&&j+y>=18)
                    {
                        if(i==x&&y==j)
                        {
                            res+=(book[i][j]-1)*book[x][y];
                        }
                        else res+=book[i][j]*book[x][y];
                    }
                }
            }
        }
    }
    printf("%lld\n",res/2);
    return 0;
}

Measured memory_bytes: 11596