akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int num[158];
int main(){
    string a;
    cin>>a;
    sort(a.begin(),a.end());
    if(a[0]==a[1]&&a[2]==a[3]&&a[0]!=a[2])
        return cout<<"Yes\n",0;

    return cout<<"No\n",0;


}


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

const int INF = 2147483647;
int N, Q;

struct LazySegmentTree {
private:
    int n;
    vector <int> node, lazy;
    vector <bool> lazyFlag;

public:
    LazySegmentTree(vector <int> v) {
        int sz = v.size();
        n = 1;
        while (n < sz) n *= 2;
        node.resize(2*n-1);
        lazy.resize(2*n-1, 0);
        lazyFlag.resize(2*n-1, false);
        for (int i = 0; i < sz; i++) node[i+n-1] = v[i];
        for (int i = n-2; i >= 0; i--) node[i] = min(node[2*i+1], node[2*i+2]);
    }

    void lazyEvaluate(int k, int l, int r) {
        if (lazyFlag[k]) {
            node[k] = lazy[k];
            if (r - l > 1) {
                lazy[k*2+1] = lazy[2*k+2] = lazy[k];
                lazyFlag[k*2+1] = lazyFlag[k*2+2] = true;
            }
            lazyFlag[k] = false;
        }
    }

    void update(int a, int b, int val, int k=0, int l=0, int r=-1) {
        if (r < 0) r = n;
        lazyEvaluate(k, l, r);
        if (b <= l || r <= a) return;
        if (a <= l && r <= b) {
            lazy[k] = val;
            lazyFlag[k] = true;
            lazyEvaluate(k, l, r);
        } else {
            update(a, b, val, 2*k+1, l, (l+r)/2);
            update(a, b, val, 2*k+2, (l+r)/2, r);
            node[k] = min(node[2*k+1], node[2*k+2]);
        }
    }

    int find(int a, int b, int k=0, int l=0, int r=-1) {
        if (r < 0) r = n;
        lazyEvaluate(k, l, r);
        if (r <= a || b <= l) return INF;
        if (a <= l && r <= b) return node[k];
        int vl = find(a, b, 2*k+1, l, (l+r)/2);
        int vr = find(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
    }
};

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

    cin >> N >> Q;
    LazySegmentTree seg(vector<int>(N, INF));
    for (int i = 0; i < Q; i++) {
        int c;
        cin >> c;
        if (c == 0) {
            int s, t, x;
            cin >> s >> t >> x;
            seg.update(s, t+1, x);
        } else {
            int s, t;
            cin >> s >> t;
            cout << seg.find(s, t+1) << "\n";
        }
    }

    return 0;
}


Measured memory_bytes: 5084
#include <bits/stdc++.h>
#include <cmath>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;

int main(void)
{
    ll a, b, c;
    cin >> a >> b >> c;

    ll d = c - a - b;
    if (d > 0 && d * d > 4 * (a * b))
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return (0);
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>
#include <climits>
#include <cmath>
#include <unordered_map>

using namespace std;

typedef long long ll;

int main(void) {
  int a, p; cin >> a >> p;
  cout << (((a * 3) + p) / 2) << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;


public class Main {

	public static void main(String [] args) {
		
		Scanner sc = new Scanner(System.in);
		
		while(true) {
			
			int H = sc.nextInt();
			int W = sc.nextInt();
			
			if(H == 0 && W == 0)break;
			
			for(int i = 1;i <= W;i++) {
				System.out.print("#");
				
			}
			
			System.out.println("");
			
			for(int j = 1;j <= H - 2;j++) {
				System.out.print("#");
					for(int k = 1;k <= W - 2;k++) {
						System.out.print(".");
						
					}
				System.out.println("#");
				
			}
			
			for(int i = 1;i <= W;i++) {
				System.out.print("#");
				
			}

			System.out.println("");
			
			System.out.println("");
			
		}
				
	}
}


Measured memory_bytes: 34404
from collections import defaultdict
import itertools

n = int(input())
r = defaultdict(int)
for i in range(n):
    r[input()[0]] += 1

ans = 0
for c in itertools.combinations(list('MARCH'), 3):
    a = 1
    for cc in c:
        a *= r[cc]
    ans += a
print(ans)


Measured memory_bytes: 9452
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Long A=sc.nextLong();
		Long B=sc.nextLong();
		Long C=sc.nextLong();
		Long K=sc.nextLong();
		sc.close();
		long point=0l;
		
		if((A>=K)&&K!=0l) {
			point=K;
			K=0l;
		}else {
			point+=A;
			K-=A;
		}
		if((B>=K)) {
			K=0l;
		}else if((B<K)&&K!=0l) {
			K-=B;
		}
		if(K!=0l)
			point-=K;
		System.out.println(point);
	}
}


Measured memory_bytes: 35744
#include <iostream>
typedef long long in;
using namespace std;

in h[100010];

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    in a,b,diff,mid,l,r,temp,t=0;
    int n;
    cin>>n>>a>>b;
    diff=a-b;
    l=1; r=1e9+10;
    in res=r;
    for (int i=0;i<n;i++) cin>>h[i];
    while (l<=r){
        mid = (l+r)/2;
        t=0;
        for (int i=0;i<n;i++)
            {
                temp = h[i]-b*mid;
                if (temp>=0) {t+=temp/diff;
                        if (temp%diff!=0) t++;
                }
            }
        if (t>mid) l=mid+1;
        else r=mid-1,res=mid;
    }
    cout<<res;
    return 0;
}


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

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int N, M;

bool path[50][50];
bool visit[50];

void init()
{
  REP(i, 50)
  visit[i] = false;
}

void dfs(int point)
{
  visit[point] = true;
  REP(i, N)
  {
    if (path[point][i] && !visit[i])
      dfs(i);
  }
}

int main()
{
  cin >> N >> M;
  vector<int> a(M), b(M);
  REP(i, M)
  {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
  }
  REP(i, 50)
  REP(j, 50)
  path[i][j] = false;
  REP(i, M)
  {
    path[a[i]][b[i]] = true;
    path[b[i]][a[i]] = true;
  }
  int ans = 0;
  REP(i, M)
  {
    init();
    path[a[i]][b[i]] = false;
    path[b[i]][a[i]] = false;
    bool all_visit = true;
    dfs(0);
    REP(i, N)
    {
      if (!visit[i])
        all_visit = false;
    }
    if (!all_visit)
      ans++;
    path[a[i]][b[i]] = true;
    path[b[i]][a[i]] = true;
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

int main(){
  int N, K, S;
  cin >> N >> K >> S;
  if(S == 1e9){
    for(int i = 0; i < K; i++){
      cout << S << ' ';
    }
    for(int i = K; i < N; i++){
      cout << 1 << ' ';
    }
    cout << endl;
  }else{
    for(int i = 0; i < K; i++){
      cout << S << ' ';
    }
    for(int i = K; i < N; i++){
      cout << S + 1 << ' ';
    }
    cout << endl;
  }
  
  return 0;
}

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

def main():
    n = int(input())
    t = 0
    x = 0
    y = 0

    l = [tuple(map(int, input().split())) for _ in range(n)]

    for t1, x1, y1 in l:
        if (abs(x1 - x) + abs(y1 - y))/(t1 - t) > 1:
            print("No")
            exit()
        if (abs(x1 - x) + abs(y1 - y))%2 != (t1 - t)%2:
            print("No")
            exit()
        x = x1
        y = y1
        t = t1

    print("Yes")
main()

Measured memory_bytes: 17324
#include <bits/stdc++.h>
using namespace std;
int n,K,Q,a[2005],L,R,M;
int main(){
	scanf("%d%d%d",&n,&K,&Q);
	for (int i=1;i<=n;++i) scanf("%d",&a[i]);
	L=0; R=1000000000;
	while (L<R){
		M=(L+R)/2;
		int fl=0;
		for (int i=1;i<=n;++i){
			int p=a[i];
			int k=0,tmp=0,s=0;
			for (int j=1;j<=n+1;++j)
			if (a[j]<p||j==n+1){
				tmp+=j-k-1<K?0:min(j-k-1-K+1,j-k-1-s); k=j; s=0;
			}else
			if (a[j]>p+M) ++s;
			if (tmp>=Q) {fl=1; break;}
		}
		if (fl) R=M; else L=M+1;
	}
	printf("%d\n",L);
}

Measured memory_bytes: 256
X,Y,A,B,C = map(int,input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
pi = 0
qi = 0
ri = 0
pl = len(p)
ql = len(q)
rl = len(r)
R = 1
scr = 0
for j in range(X+Y):
  mx = max(p[pi],q[qi],r[ri])
  scr += mx
  if mx == p[pi]:
    X -= 1
    if pi+1 >= pl or X <= 0:
      p.append(0)
      pi = -1
      X = 0
    else:
      pi += 1
  elif mx == q[qi]:
    Y -= 1
    if qi+1 >= ql or Y <= 0:
      q.append(0)
      qi = -1
      Y = 0
    else:
      qi += 1
  else:
    if ri+1 >= rl or R <= 0:
      r.append(0)
      ri = -1
      R = 0
    else:
      ri += 1
      
print(scr)

Measured memory_bytes: 22720
n,m = map(int,input().split())
if m % n == 0:
    print(m//n)
    exit()
ans = 1
for i in range(2,int(m**(0.5))+1):
    if m % i == 0:
        if i <= m/n:
            ans = max(ans,i)
        if m//i <= m/n:
            ans = max(ans,m//i)
print(ans)

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main(){
	int N, n, t, ans;
	while (cin >> N, N){
		n = N / 2;
		ans = 0;
		for (int i = 1; i < n + 1; ++i){
			t = i;
			for (int j = 1; j < n + 1; ++j){
				t += i + j;
				if (t == N) ans++;
				else if (t > N) break;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3096
use std::io::prelude::*;

fn input<T: std::str::FromStr>() -> T {
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let n: usize = input();
    let mut ab: Vec<(i32, i32)> = (0..n).map(|_| (input(), input())).collect();
    ab.sort_by_key(|&(_, b)| b);

    let mut ok = true;
    let mut t = 0;
    for (a, b) in ab {
        if t + a > b {
            ok = false;
            break;
        }
        t += a;
    }

    println!("{}", if ok { "Yes" } else { "No" });
}


Measured memory_bytes: 6396
N=int(input())
A=list(map(int,input().split()))

def GCD(x,y):
    x,y=min(x,y),max(x,y)
    if y%x==0: return x
    return GCD(y%x,x)
ans=A[0]
for a in A[1:]:
    ans = GCD(ans,a)
print(ans)

Measured memory_bytes: 14252
/**************************
*                         *
*  Nothing Is Impossible  *
*                         *
**************************/
#include <algorithm>
#include <iostream>
#include <fstream>
#include <ctype.h>
#include <string>
#include <vector>
#include <thread>
#include <math.h>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <set>
#include <map>
#define GetRand(Min, Max) ((rand()%(int)(((Max) + 1)-(Min))) + (Min))
#define Rep(i, min, max) for(int i = min; i < max; ++i)
#define PB push_back
#define MP make_pair
typedef long long ll;
typedef long double ld;
using namespace std;

void Solve(){
	int a,b,c;	cin >> a >> b >> c;
	if((b*c) >= a){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}

int main(){
	ios::sync_with_stdio(NULL);
	cin.tie(NULL); cout.tie(NULL);
	int t = 1;
	//int t;	cin >> t;
	while(t--) Solve();
	return 0;
}



Measured memory_bytes: 3536
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
using namespace std;
int main() {
    int H, N;
    cin >> H >> N;
    int sum = 0;
    for (int i=0; i < N; i++) {
        int m;
        cin >> m;
        sum += m;
    }

    if (H > sum) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
}

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

int main(){
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    bool j = s[0] == s[1] && s[1] != s[2] && s[2]==s[3];
    cout << (j ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
 int n,k,i,o,h,x;
 int ans;
 
 scanf("%d %d", &n, &k);
 
 int s[n];
 for(i = 0; i < n; i++)
   s[i] = 0;
 
 for(i = 0; i < k; i++) {
   scanf("%d", &o);
   for (h = 0; h < o; h++) {
     scanf("%d", &x);
     s[x - 1]++;
   }
 }

 ans = 0;
 for(i = 0; i < n; i++) {
   if(s[i] == 0)
     ans++;
 }
 
 printf("%d", ans);
 return(0);
}

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

int main() {
	int N;
	cin >> N;
	vector<int> List(N);
	for (int i = 0; i < N; i++) cin >> List[i];
	sort(List.begin(), List.end());
	int MAX = List.back();
	cout << MAX << " ";
	const auto itr = lower_bound(List.begin(), List.end() - 1, MAX / 2);
	if (MAX / 2 - *(itr - 1) < *itr - MAX / 2 || itr == List.end() - 1) cout << *(itr - 1) << endl;
	else cout << *itr << endl;
}

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

bool isPrime(const ll &n){
    if(n == 2) return true;
    if(n < 2 || n%2 == 0) return false;
    const ll m = n-1, d = m / (m & -m);
    auto modpow = [&](ll a, ll b){
        ll res = 1;
        while(b){
            if(b&1) res = res*a%n;
            a = a*a%n;
            b >>= 1;
        }
        return res;
    };
    auto suspect = [&](ll a, int t){
        a = modpow(a,t);
        while(t != -1+n && a != 1 && a != -1+n){
            a = a*a%n;
            t *= 2;
        }
        return a == n-1 || t%2 == 1;
    };
    const int witness[] = {2,7,61,0}; // 要検証
    for(const int *w = witness; *w < n && *w; w++){
        if(!suspect(*w,d)) return false;
    }
    return true;
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    int ans = 0;
    rep(i,n){
        ll x;
        cin >> x;
        ans += isPrime(x);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6;
const ll LINF = 1e18;
using namespace std;

#define rep(i, n) for (int(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (int i = (a); i < (b); i++)
#define rrrep(i, a, b) for (int i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl

ll n, cnt, ans, a, b, c, d, tmp, tmpp, m, h, w, x, y, sum, pos, k;
ld doua;
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
bool fl;
struct edge
{
    int to, cost;
};
pair<ll, ll> p[ohara];

//-------------------------↓↓↓↓↓↓------------------------

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

    cin >> n >> k;
    rep(i, n)
    {
        cin >> a >> b;
        p[i] = make_pair(a, b);
    }
    sort(p, p + n);
    ll now = 0;
    rep(i, n)
    {
        now += p[i].second;
        if (now >= k)
        {
            Cout(p[i].first);
            return 0;
        }
    }
    return 0;
}


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

using namespace std;

typedef long long ll;

#define FOR(i,a,b) for(ll i=a;i<=b;i++)
#define FORd(i,a,b) for(int i=a;i>=b;i--)
#define fi first
#define se second
#define II pair<ll,ll>

const int N=8e3+10;
const int maxN=1e5;

int main(){
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif // ONLINE_JUDGE
    int a,b,c,k;
    cin >> a >> b >> c >> k;
    int ans=0;
        if (a>0) {
            ans+=min(a,k);
            int b=a,k1=k;
            k-=min(a,k);
            a-=min(b,k1);
        }
        if (b>0) {k-=min(k,b);b-=min(k,b);}
        if (c>0) {
            ans-=min(k,c);
            int b=c,k1=k;
            k-=min(k,c);
            c-=min(k1,b);
        }
    cout << ans;
}


Measured memory_bytes: 3588
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/rope>
using namespace std;
using namespace chrono;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
mt19937 rng(high_resolution_clock::now().time_since_epoch().count());
mt19937_64 rngll(high_resolution_clock::now().time_since_epoch().count());
template<typename T> T ctmax(T &x, const T &y){ return x = max(x, y); }
template<typename T> T ctmin(T &x, const T &y){ return x = min(x, y); }
template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;



int main(){
	cin.tie(0)->sync_with_stdio(0);
	cout << fixed << setprecision(15);
	int n;
	cin >> n;
	vector<int> cnt(4);
	for(auto i = 0; i < n; ++ i){
		int x;
		cin >> x;
		++ cnt[x];
	}
	vector<vector<vector<double>>> dp(n + 1, vector<vector<double>>(n + 1, vector<double>(n + 1))), p(dp);
	p[cnt[1]][cnt[2]][cnt[3]] = 1;
	for(auto tot = cnt[1] + cnt[2] + cnt[3]; tot >= 0; -- tot){
		for(auto k = min(tot, cnt[3]); k >= 0; -- k){
			for(auto j = min(tot - k, cnt[2] + cnt[3] - k); j >= 0; -- j){
				int i = tot - j - k;
				double q = 1.0 * (n - i - j - k) / n;
				if(i){
					dp[i - 1][j][k] += dp[i][j][k] * i / (i + j + k) + p[i][j][k] * i / n / (1 - q) / (1 - q);
					p[i - 1][j][k] += p[i][j][k] * i / (i + j + k);
				}
				if(j){
					dp[i + 1][j - 1][k] += dp[i][j][k] * j / (i + j + k) + p[i][j][k] * j / n / (1 - q) / (1 - q);
					p[i + 1][j - 1][k] += p[i][j][k] * j / (i + j + k);
				}
				if(k){
					dp[i][j + 1][k - 1] += dp[i][j][k] * k / (i + j + k) + p[i][j][k] * k / n / (1 - q) / (1 - q);
					p[i][j + 1][k - 1] += p[i][j][k] * k / (i + j + k);
				}
			}
		}
	}
	cout << dp[0][0][0];
	return 0;
}

/*

*/

////////////////////////////////////////////////////////////////////////////////////////
//                                                                                    //
//                                   Coded by Aeren                                   //
//                                                                                    //
////////////////////////////////////////////////////////////////////////////////////////

Measured memory_bytes: 432000
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = br.readLine();

		int henkan = Integer.parseInt(line);
		int ans = henkan * henkan * henkan;
        System.out.println(ans);
	}
}

Measured memory_bytes: 24208
n = gets.to_i
a = gets.split.map(&:to_i).sort
b = gets.split.map(&:to_i).sort
c = gets.split.map(&:to_i).sort

count = Array.new(n+1,0)

i = n-1
(n-1).downto(0) do |j|
    i -= 1 while i >= 0 && b[j] < c[i]
    count[j] = n - i - 1 + count[j+1]
end
#p count

ans = 0
i = 0
n.times do |j|
    i += 1 while i < n && a[j] >= b[i]
    ans += count[i]
end

puts ans

Measured memory_bytes: 24688
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 87;
char s[N];
deque<int> p[26];
int f[N];
void add(int i,int v)
{
    for (; i < N; i += i & -i)
        f[i] += v;
}
int qry(int i)
{
    int r = 0;
    for (; i; i ^= i & - i)
        r += f[i];
    return r;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> (s+1);
    int n = strlen(s+1);
    for (int i = 1; i <= n; ++i) {
        p[s[i]-'a'].push_back(i);
        add(i,1);
    }
    int mi = -1;
    for (int i = 0; i < 26; ++i)
        if (p[i].size() & 1) {
            if (mi != -1 || n % 2 == 0) {
                cout << "-1\n";
                return 0;
            }
            mi = i;
        }
    int l=1;
    long long ans = 0;
    for (int i = 0; i < n/2; ++i) {
        while (p[s[l]-'a'].size() <= 1 || l != p[s[l]-'a'].front() )
            ++l;
        auto & q = p[s[l]-'a'];
        ans += qry(l-1) + n - 2 * i - qry(q.back());
        add(l,-1);
        add(q.back(),-1);
        q.pop_front();
        q.pop_back();
    }
    cout << ans << '\n';
}


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

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

    int n;
    cin >> n;
    map<string, long long> mp;
    for(int i = 0; i < n; i++){
        string s;
        cin >> s;
        sort(s.begin(), s.end());
        mp[s]++;
    }

    long long ans = 0;
    for(auto x: mp){
        long long a = x.second;
        ans += (a - 1) * a / 2;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 11264
H = int(input())

memo = {}
memo['0'] = 0
memo['1'] = 1

def dp(arg):
    key = str(arg)
    if memo.setdefault(key, None) != None: return memo[key]
    ret = 1 + 2 * dp(arg // 2)
    memo[key] = ret
    return ret

print(dp(H))

Measured memory_bytes: 3060
#include <stdio.h>
 
class Dice2{
public:
    Dice2(){
        number = new int[6];
        relative = new int[55];
        relative[31] = relative[43] = relative[24] = relative[12] = 0;
        relative[3] = relative[20] = relative[52] = relative[35] = 1;
        relative[1] = relative[40] = relative[54] = relative[15] = 2;
        relative[4] = relative[10] = relative[51] = relative[45] = 3;
        relative[2] = relative[30] = relative[53] = relative[25] = 4;
        relative[21] = relative[42] = relative[34] = relative[13] = 5;
    };
    ~Dice2(){
        delete[] number;
        delete[] relative;
    };
 
    void setNumber(int index,int num){
        number[index] = num;
    };
 
    int returnRight(int top,int front){
        int top_index,front_index;
        for(int i = 0; i < 6; i++){
            if(number[i] == top)
                top_index = i;
            if(number[i] == front)
                front_index = i;
        }
        return number[relative[10*top_index+front_index]];
    }
private:
    int* number;
    int* relative;
};
 
int main(){
    Dice2 dice2;
    int x,q,top,front;
    for(int i = 0; i < 6; i++){
        scanf("%d",&x);
        dice2.setNumber(i,x);
    }
    scanf("%d",&q);
    for(int i = 0; i < q; i++){
        scanf("%d %d",&top,&front);
        printf("%d\n",dice2.returnRight(top,front));
    }
}


Measured memory_bytes: 2640
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
#include <tuple>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rep(i,N) for (ll i=0;i<N;i++)
#define loop(i,N,M) for(ll i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())
#define SORTMF(v,func) sort(v.begin(),v.end(),func)

template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}

typedef struct {
	ll t;
	bool in;
	ll pos;
}event;

void solve() {
	ll N, Q;
	cin >> N >> Q;
	//vector<event> ev(2*N);
	vector<tuple<ll, ll, ll>> ev;
	rep(i, N) {
		ll st, en, pos;
		cin >> st >> en >> pos;
		//ev[2*i].t = st - pos;
		//ev[2 * i].in = true;
		//ev[2 * i].pos = pos;
		//ev[2 * i+1].t = en - pos;
		//ev[2 * i + 1].in = false;
		//ev[2 * i + 1].pos = pos;
		ev.emplace_back(make_tuple(st - pos, 1, pos));
		ev.emplace_back(make_tuple(en - pos, -1, pos));
	}

	vector<ll> human(Q);
	rep(i, Q) cin >> human[i];

	/*sort(ev.begin(), ev.end(), [](const event& x, const event& y) {
		return x.t < y.t;
	});*/

	sort(ev.begin(), ev.end());

	set<ll> stopping;
	ll ev_cnt = 0;
	ll hu_cnt = 0;
	vector<ll> ans(Q, -1);
	while (ev_cnt < ev.size() && hu_cnt < Q) {

		while (ev_cnt < ev.size() && /*ev[ev_cnt].t*/get<0>(ev[ev_cnt]) <= human[hu_cnt]) {

			if (/*ev[ev_cnt].in*/get<1>(ev[ev_cnt]) == 1/*true*/) {
				stopping.insert(/*ev[ev_cnt].pos*/get<2>(ev[ev_cnt]));
			}
			else {
				stopping.erase(/*ev[ev_cnt].pos*/get<2>(ev[ev_cnt]));
			}

			ev_cnt++;
		}

		if (!stopping.empty()) ans[hu_cnt] = *stopping.begin();

		hu_cnt++;
	}

	for (ll i = 0; i < Q; i++) {
		cout << ans[i] << endl;
	}

}

int main() {
	solve();
	cout << endl;
	return 0;
}


Measured memory_bytes: 23272
#include<iostream>
#include <iomanip>
#include <ios>
#include <vector>
#include <string>
#include <algorithm>
#include <string>
#include<limits>
#include<cstdlib>
#include<functional>
#include<cassert>
#include <cstdio>
#include <stack>
#include <queue>
#include <map>
#define fi(p) for(int i=0;i<(p);i++)
#define ce(d) cout<<d<<endl;
#define ll long long
#define sorts(c) sort((c).begin(),(c).end());
 
using namespace std;
 
void solve() {
	ll a, b, r, x, tmp;
 
	cin >> a >> b;
 
	x = a * b;
 
	/* 自然数 a > b を確認・入替 */
	if (a < b) {
		tmp = a;
		a = b;
		b = tmp;
	}
 
	/* ユークリッドの互除法 */
	r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
 
 
	ce(x/b)
}
 
int main()
{
	solve();
 
	int a;//止める用
	cin >> a;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int N;
vector< pair<int, int> > V;
 
int main() 
{
	scanf("%d", &N);
	for (int i = 0; i < N; i++) 
{
		for (int j = i + 1; j < N; j++) 
{
			printf("? ");
			for (int k = 0; k < N; k++)
 {
				if (i == k || j == k) printf("1");
				else printf("0");
			}
			printf("\n");
			fflush(stdout);
			int x;
			scanf("%d", &x);
			if (x == 1) V.push_back(make_pair(i, j));
		}
	}
	printf("! ");
	for (int i = 0; i < V.size(); i++) printf("(%d,%d) ", V[i].first, V[i].second);
	printf("\n");
}

Measured memory_bytes: 852
#include<bits/stdc++.h>
#define cy cout<< "Yes"<<endl;
#define cn cout<< "No"<<endl;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main()
{
    fast;
    int a,b,c,d,e,i,j;
    char ch;
    cin >> ch;
    if(ch>='a' && ch<='z')
    {
       cout << "a" << endl;
    }
    else{
            cout << "A" << endl;

    }






}






Measured memory_bytes: 3604
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){
	int h,w;
    while(1){
		cin>>h>>w;
		if (h==0 && w==0) break;
    for(int i=0;i<w;i++)cout<<"#";
    cout<<endl;
    for (int i=0; i<h-2; i++)
    {
		for (int j=0; j<w; j++)
		{
		    if (j==0 ||	j==w-1) cout<<"#";
		    else cout<<".";
		}
		cout<<endl;
	}
    for(int i=0;i<w;i++)cout<<"#";
    cout<<endl;
cout<<endl;
}
}




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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod =(1e9)+7;
using P = pair<ll,ll>;

int main(){
    ll n;cin >>n;
    vector<ll>a(n);
    for (int i = 0; i < n; ++i) {
        cin >>a[i];
    }
    vector<ll>memo(60,0);
    for (int i = 0; i < 60; ++i) {
        for (int j = 0; j < n; ++j) {
            if(a[j]>>i&1)memo[i]++;
        }
    }
//    for (int i = 0; i < 5; ++i) {
//        cout <<i<<" "<<memo[i]<<" "<<(1LL<<i)<<endl;
//   }
    ll ans=0;
    for (int i = 0; i < 60; ++i) {
        ll x=memo[i]*(n-memo[i])%mod;
        for (int j = 0; j < i; ++j) {
            x=x*2%mod;
        }
        ans+=x;
        ans%=mod;
//        cout <<i<<" "<<ans<<endl;
    }
    ans%=mod;
    cout <<ans<<endl;
    return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
long long qw[100000],dp[100000],a,b;
long long dfs(long long  now);
int main(){
  cin >> a >> b;
  for(int i=0;i<a;i++){
    cin >> qw[i];
  }
  for(int i=0;i<a;i++){
    dfs(i);
  }
  cout << *max_element(dp,dp+a) << endl;
}
long long dfs(long long  now){
  if(dp[now]>0)return dp[now];
  if((now==0 && qw[now]>qw[now+1]) || (now==a-1 && qw[now]>qw[now-1]) || (qw[now]>qw[now-1] && qw[now]>qw[now+1])){
    return dp[now]=b-qw[now];
  }
  if(now==0)return dp[now]=dfs(1)+b-qw[now];
  if(now==a-1)return dp[now]=dfs(a-2)+b-qw[now];
  if(qw[now]<qw[now-1])dp[now]=max(dp[now],dfs(now-1)+b-qw[now]);
  if(qw[now]<qw[now+1])dp[now]=max(dp[now],dfs(now+1)+b-qw[now]);
}

Measured memory_bytes: 2716
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
const long long MOD = 1000000007;
using namespace std;
typedef long long ll;
map<ll, int> mp;
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int a, b, c;
	cin >> a >> b >> c;
	int tmp = 0;
	if (a > b) {
		tmp = a;
		a = b;
		b = tmp;
	}
	if (b > c) {
		tmp = b;
		b = c;
		c = tmp;
	}
	if (a > b) {
		tmp = a;
		a = b;
		b = tmp;
	}
	cout << a << " " << b << " " << c << endl;
	return 0;
}


Measured memory_bytes: 3164
h = int(input())
w = int(input())
n = int(input())

if h > w:
  if n%h == 0:
    print(n//h)
  else:
    print(n//h+1)
else:
  if n%w == 0:
    print(n//w)
  else:
    print(n//w+1)  

Measured memory_bytes: 3060
#include <algorithm>
#include <math.h>
#include <iostream>
#include <vector>
using ll=long long;
#define rep(i,a,b) for(ll i=a;i<ll(b);i++)
#define repr(i,a,b) for(ll i=a;i>=ll(b);i--)
#define endl "\n"
#define ALL(x) x.begin(),x.end()
#define ALLR(x) x.rbegin(),x.rend()
using namespace std;

const ll MAX = 1e18;
int n;
int main() {
	cin >> n;
	vector<ll> a(n); rep(i, 0, n) cin >> a[i];


	double alog = 0;
	rep(i, 0, n){
		// 0が含まれているか
		if(a[i] == 0){
			cout << "0" << endl;
			return 0;
		}

		// 配列全部の積の桁数を求める
		alog += log10(a[i]);
	}

	// 1e18 を大きく超えているか
	if(alog > 18){
		cout << "-1" << endl;
		return 0;
	}

	// 積を求める
	ll ans = 1;
	rep(i, 0, n){
		ans *= a[i];
		if(ans > MAX){
			cout << "-1" << endl;
			return 0;
		}
	}

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


Measured memory_bytes: 3588
#include <stdio.h>
int main()
{
	int W, H, x, y, r;

		scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

	if (x-r>=0&& x+r<=W&&y-r>=0&&
		y + r <= H){
		printf("Yes\n");
	}
	else{ printf("No\n");
	}
	return 0;
}


Measured memory_bytes: 2628
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define REP(i,n) for(int i=0,_n=(n);(i)<(int)_n;++i)
#define RANGE(i,a,b) for(int i=(int)a,_b=(int)(b);(i)<_b;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define PRINT1(table, D0) REP(d0, D0) cout<<table[d0]<<" "; cout<<"\n";
#define PRINT2(table, D0, D1) REP(d0, D0) { REP(d1, D1) cout<<table[d0][d1]<<" "; cout<<"\n"; }
#define PRINT3(table, D0, D1, D2) REP(d0, D0) { REP(d1, D1) { REP(d2, D2) cout<<table[d0][d1][d2]<<" "; cout<<"\n"; } cout<<"\n"; }
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }

#define MOD 1000000007LL
#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	while(cin>>s) {
		cout<<(s.find("AC")!=string::npos ? "Yes":"No")<<endl;
	}
	
	return 0;
}


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

int main(){
    int N, M;
    cin >> N >> M;
    int sum = 0;
    int a;
    for (int i = 0; i < M; i++){
        cin >> a;
        sum += a;
    }
    if (N >= sum)
        cout << N - sum << endl;
    else 
        cout << -1 << endl;

    }

Measured memory_bytes: 3644
import java.io.*
import java.util.*
import java.lang.*
import java.lang.Math.*


fun factorize(N: Long): LongArray {
    val factors = ArrayList<Long>()
    (1L..N).takeWhile { it*it <= N }.filter { N%it==0L }
            .map {
                if (it == N/it) factors.add(it)
                else {
                    factors.add(it)
                    factors.add(N/it)
                }
            }
    return factors.sorted().toLongArray()
}


fun solve() {
    val N = rd.readLong()

    val st = mutableSetOf<Long>()
    st.add(2L)
    st.addAll(factorize(N-1).filter { it > 2 })
    st.add(N)

    val fcs = factorize(N).filter { it > 2 }
    fun rec(n: Long, k: Long) {
        if (n < k) {
            if (n == 1L) {
                st.add(k)
            }
            return
        }

        if (n%k == 0L) rec(n/k, k)
        //else rec(n-k, k)
        else rec(n%k, k)
    }

    for (k in fcs) {
        rec(N, k)
    }
    //errPrintln(st.joinToString(" "))

    val ans = st.size
    println(ans)
}


//val rd = debug.Reader("abc", "161", "f", "sample-2")
val rd = Reader()


fun main(args: Array<String>) {
    try {
        var exception: Throwable? = null
        val sth = Thread(null, SolveThread(), "solveThread", 128 * 1024 * 1024)
        sth.setUncaughtExceptionHandler { _, e -> exception = e }
        sth.start(); sth.join()
        if (exception != null) throw exception!!
    } catch (e: Exception) { throw e }
}
const val MOD = 1_000_000_007L; const val INF = Int.MAX_VALUE/2; const val LINF = Long.MAX_VALUE/2
const val EPS = 1e-9; fun DBLEQ(a: Double, b: Double): Boolean {return abs(a - b) < EPS}
data class IntPair(val first: Int, val second: Int)
data class To(val idx: Int, val cost: Long, val col: Int)
fun <T>edge(V: Int): Array<ArrayList<T>> { return Array(V){ArrayList<T>()} }
val errPrintln: (Any) -> Unit = { msg -> System.err.println(msg) }
fun rAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("EAssert Error: $msg"); throw Error(msg) }
}
fun tAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("TAssert Error: $msg"); Thread.sleep(3000) }
}
class SolveThread : Runnable {
    override fun run() { solve() }
}
class Reader {
    private val br = BufferedReader(InputStreamReader(System.`in`))
    val readString: () -> String = { br.readLine() }
    val readInt: () -> Int = { br.readLine().toInt() }
    val readLong: () -> Long = { br.readLine().toLong() }
    val readIntArray: () -> IntArray = { br.readLine().split(' ').map { it.toInt() }.toIntArray() }
    val readLongArray: () -> LongArray = { br.readLine().split(' ').map { it.toLong() }.toLongArray() }
    val readListInt: () -> List<Int> = { br.readLine().split(' ').map { it.toInt() } }
    val readListLong: () -> List<Long> = { br.readLine().split(' ').map { it.toLong() } }
}


Measured memory_bytes: 104124
#include <cstdio>
long long dp[99][21];
int numbers[100];
int main() {
	int N;
	scanf("%d",&N);
	for(int i=0;i<N;i++) {
		scanf("%d",&numbers[i]);
	}
	dp[0][numbers[0]]++;
	for(int i=1;i<(N-1);i++) {
		for(int j=0;j<=20;j++) {
			if((j-numbers[i])>=0) dp[i][j-numbers[i]]+=dp[i-1][j];
			if((j+numbers[i])<=20) dp[i][j+numbers[i]]+=dp[i-1][j];
		}
	}
	printf("%lld\n",dp[N-2][numbers[N-1]]);
}

Measured memory_bytes: 1044
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MOD 1000000007

void solve()
{
	ll n;
	cin>>n;
	map<ll,ll> mp;
	ll ans=0;
	for(ll i=0;i<n;i++)
	{
		ll x;
		cin>>x;
		mp[x]++;
	}
	// cout<<mp[16];
	for(auto c:mp)
	{
		ans+=(c.second%2);
	}
	cout<<ans;
	return;
}
int main()
{
	fast;
	int q;
	q=1;
	// cin>>q;
	while(q--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 9720
//INCLUDE
//------------------------------------------
#include <iostream>
#include <functional>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <string>
#include <cstring>
#include <vector>
//DEFINE
//------------------------------------------
#define ll long long
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
//CONST
//------------------------------------------
#define INF 1010000000000000017LL
#define MOD 1000000007LL
#define EPS 1e-12
#define PI 3.14159265358979323846
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
using namespace std;
//-------------------------------------------

int main(void){
  ll N;cin>>N;ll c=0;
  REPS(i,N){
    if(i%2==0)continue;
    ll count=0;REPS(j,i){
      if(i%j==0)count++;
    }if(count==8)c++;
    count=0;
  }
  cout<<c;
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,a,b) for(int i =(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define REPS(i,n) for(int i=1;i<=(n);i++)
#define RREPS(i,n) for(int i=(n);i>0;i--)
#define mp make_pair
#define pb(a) push_back(a)
typedef long long ll;

int main(){
  int N;
  cin >> N;
  vector<int> X(N);
  vector<int> Y(N);
  REP(i,N){
    cin >> X[i];
    Y[i] = X[i];
  }
  sort(Y.begin(),Y.end());
  if(N == 2){
    cout << X[1] << endl;
    cout << X[0] << endl;
    return 0;
  }
  int a,b,c,d;
  a = Y[N/2-1];
  b = Y[N/2];
  REP(i,N){
    if(X[i] <= a) cout << b << endl;
    else cout << a << endl;
  }
  return 0;
}


Measured memory_bytes: 3712
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long int llint;
int main() {
	int n;
	cin >> n;
	vector<llint>a(n);
	for (int i = 0;i < n;i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	llint b[2] = {};
	int cnt = 0;
	for (int i = 0;i < n - 1;i++) {
		if (a[n - 1 - i] == a[n - 2 - i]) {
			b[cnt] = a[n - 1 - i];
			cnt++;
			i++;
			if (cnt == 2) {
				break;
			}
		}
	}
	if (b[1] == 0) {
		cout << 0 << endl;
	}
	else {
		cout << b[0] * b[1] << endl;
	}
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>

long long fgcm(long long a,long long b){
	long long ab;
	
	while(b!=0){
		a=a%b;
		ab=a; a=b; b=ab;
	}
	
	return a;
}

int main(void){
	long long na,nb,ans,gcm,lcm;
	
	long long a,b;
	
	long long c,d;
	
	scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
	
	if(c>=d){
		gcm=fgcm(c,d);
	}else{
		gcm=fgcm(d,c);
	}
	
	a--;
	
	lcm=c*d/gcm;
	
	nb=b-(b/c)-(b/d)+(b/lcm);
	na=a-(a/c)-(a/d)+(a/lcm);
	
	printf("%lld\n",nb-na);
	
	return 0;
}

Measured memory_bytes: 128
local mfl, mce, mmi = math.floor, math.ceil, math.min
local mma = math.max
local SegTree = {}
SegTree.updateAll = function(self)
  for i = self.stagenum - 1, 1, -1 do
    for j = 1, self.cnt[i] do
      self.stage[i][j] = self.stage[i + 1][j * 2 - 1] + self.stage[i + 1][j * 2]
    end
  end
end
SegTree.clear = function(self)
  for i = self.stagenum, 1, -1 do
    for j = 1, self.cnt[i] do
      self.stage[i][j] = 0
    end
  end
end
SegTree.create = function(self, n)
  local stagenum, mul = 1, 1
  self.cnt, self.stage, self.size = {1}, {{}}, {}
  while mul < n do
    mul, stagenum = mul * 2, stagenum + 1
    self.cnt[stagenum], self.stage[stagenum] = mul, {}
  end
  for i = 1, stagenum do self.size[i] = self.cnt[stagenum + 1 - i] end
  self.stagenum = stagenum
  self:clear()
  self:updateAll()
end
SegTree.getRange = function(self, right)
  local stage = 1
  while right < self.size[stage] do
    stage = stage + 1
  end
  local ret = 0
  local l, r = 1, right
  while true do
    local sz = self.size[stage]
    ret = ret + self.stage[stage][mce(l / sz)]
    l = l + sz
    if l <= r then
      local nsize = r + 1 - l
      while nsize < self.size[stage] do
        stage = stage + 1
      end
    else
      break
    end
  end
  return ret
end
SegTree.inc = function(self, idx)
  self.stage[self.stagenum][idx] = self.stage[self.stagenum][idx] + 1
end
SegTree.dec = function(self, idx)
  self.stage[self.stagenum][idx] = self.stage[self.stagenum][idx] - 1
  for i = self.stagenum - 1, 1, -1 do
    local dst = mce(idx / 2)
    local rem = dst * 4 - 1 - idx
    self.stage[i][dst] = self.stage[i + 1][idx] + self.stage[i + 1][rem]
    idx = dst
  end
end
SegTree.new = function(n)
  local obj = {}
  setmetatable(obj, {__index = SegTree})
  obj:create(n)
  return obj
end

local n = io.read("*n")
local a = {}
local t = {}
for i = 1, n do
  a[i] = io.read("*n")
  t[i] = a[i]
end
table.sort(t)
local totcnt = mfl(n * (n + 1) / 2)
local st = SegTree.new(n * 2 + 1)
local z = {}
local function solve(v)
  st:clear()
  local ofst = n + 1
  z[1] = v <= a[1] and 1 or -1
  for i = 2, n do
    z[i] = v <= a[i] and z[i - 1] + 1 or z[i - 1] - 1
  end
  for i = 1, n do
    st:inc(z[i] + ofst)
  end
  st:updateAll()
  local cnt = 0
  local n2_1 = 2 * n + 1
  for i = 1, n do
    local left = i == 1 and ofst or z[i - 1] + ofst
    if left <= 1 then
      cnt = cnt + n + 1 - i
    else
      cnt = cnt + n + 1 - i - st:getRange(left - 1)
    end
    st:dec(z[i] + ofst)
  end
  return totcnt <= cnt * 2
end
local function solveAll()
  if solve(t[n]) then
    return t[n]
  end
  local min, max = 1, n
  while 1 < max - min do
    local mid = mfl((min + max) / 2)
    if solve(t[mid]) then
      min = mid
    else
      max = mid
    end
  end
  return t[min]
end
print(solveAll())


Measured memory_bytes: 7676
#include <bits/stdc++.h>
using namespace std;
#define st first
#define nd second

int main() {
	int a, b, t;
	scanf(" %d%d%d", &a, &b, &t);
	if( t < b ) return 0*puts("0");
	t = t/a;
	printf("%d\n", b*t);
	return 0;
}


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

int main() {
  int a,b,c,d; cin >> a >> b >> c >> d;
  bool f = false;
  if( abs(a-c) <= d ) f = true;
  if ( abs(a-b) <= d && abs(b-c) <=d ) f = true;
  if(f)cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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

int main(){
  constexpr int Amax= 1e6;
  constexpr int Nbit= Amax+ 1;
  int N;
  cin >> N;

  unordered_map<int, int> data;
  int buf;
  for(int i=0; i<N; i++){
    cin >> buf;
    if(data.count(buf)){ data.at(buf)++; }
    else               { data[buf]= 1; }
  }
  
  bitset<Nbit> divisible;
  for(auto [num, freq]:data){
    for(int i=2*num; i<Nbit; i+=num){
      divisible.set(i);
    }
  }

  int ans= 0;
  for(auto [num, freq]:data){
    if(!divisible.test(num) && freq==1){ ans++; }
  }

  cout << ans << endl;
}

Measured memory_bytes: 11676
import java.util.*;

public class Main {

	public static void main(String[] args) {
		String taro, hanako;
		int taroP = 0, hanakoP = 0;
		int length;
		boolean flag = false;
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for (int i = 0; i < n; i++) {
			taro = sc.next();
			hanako = sc.next();
			if (taro.length() < hanako.length())
				length = taro.length();
			else
				length = hanako.length();
			for (int j = 0; j < length; j++) {
				if (taro.charAt(j) > hanako.charAt(j)) {
					taroP += 3;
					flag = true;
					break;
				} else if (taro.charAt(j) < hanako.charAt(j)) {
					hanakoP += 3;
					flag = true;
					break;
				}
			}
			if (flag == false) {
				if (taro.equals(hanako)) {
					taroP += 1;
					hanakoP += 1;
				} else if (taro.length() > hanako.length())
					taroP += 3;
				else
					hanakoP += 3;
			}
			flag = false;
		}

		System.out.println(taroP + " " + hanakoP);
	}
}

Measured memory_bytes: 20800
import java.util.Scanner;
class Main
{
    public static void main(String args[])
    {
	int a,b;
	String op;
	Scanner scan=new Scanner(System.in);
	while(true)
	    {
	a=scan.nextInt();
	op=scan.next();
	b=scan.nextInt();
	if(op.equals("?"))break;
	else if(op.equals("+"))
	    System.out.println(a+b);
	else if(op.equals("-"))
	    System.out.println(a-b);
	else if(op.equals("*"))
	    System.out.println(a*b);
	else if(op.equals("/"))
	    System.out.println(a/b);
	    }
    }
}

Measured memory_bytes: 18000
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let s = sc.chars();
    let mut ans = 1;
    for i in 1..n {
        if s[i - 1] != s[i] {
            ans += 1;
        }
    }
    println!("{}", ans);
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


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

map<string, int> m;

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  m[s] = true;

  for (int i = 2; i <= n; i++) {
    string t;
    cin >> t;
    if (m[t]) {
      cout << "No" << endl;
      return 0;
    }
    m[t] = true;
    if (t.front() != s.back()) {
      cout << "No" << endl;
      return 0;
    }
    s = t;
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define int long long
#define INF 1000000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);



signed main(){

    int N; cin >> N;
    vec x(N), y(N);
    REP(i, N) cin >> x[i] >> y[i];
    int m = INF, M = 0;
    REP(i, N){
        m = min(m, min(x[i], y[i]));
        M = max(M, max(x[i], y[i]));
    }

    int m2 = m, M2 = M;
    REP(i, N){
        m2 = max(m2, min(x[i], y[i]));
        M2 = min(M2, max(x[i], y[i]));
    }
    int ans1 = (M - M2) * (m2 - m);

    vector<Pii> p(N);
    REP(i, N) p[i] = Pii(min(x[i], y[i]), max(x[i], y[i]));
    SORT(p);
    int l = p[N - 1].first - p[0].first;
    int mm = INF, MM = p[N - 1].first;
    REP(i, N){
        mm = min(mm, p[i].second);
        MM = max(MM, p[i].second);
        int mm2 = mm;
        if(i < N - 1) mm2 = min(mm, p[i + 1].first);
        l = min(l, MM - mm2);
    }
    int ans2 = (M - m) * l;

    cout << min(ans1, ans2);
    
    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

Measured memory_bytes: 6528