akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<cmath>
#include<math.h>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<complex>
#include<queue>
#include<set>
#include<utility>
#include<iomanip>
#include<limits>
#include<thread>
#include<map>
#include<stack>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<tuple>
#include <cstdio>

using namespace std;

template <class... A>
void prints() { cout << "\n"; }
template <class... A>
void prints_rest() { cout << "\n"; }
template <class T, class... A>
void prints_rest(const T &first, const A &... rest) { cout << " " << first; prints_rest(rest...); }
template <class T, class... A>
void prints(const T &first, const A &... rest) { cout << first; prints_rest(rest...); }
template <class T, class... A>
void printd(const T &first, const A &... rest) { cout << fixed << setprecision(15) << first; prints_rest(rest...); }


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

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

const ll BIG = 1LL<<60;

ll n,k;
ll w[100005];

ll min_sufficient_load(){
	ll l = 0;
	ll r = BIG;
	while(r-l>1){
		ll mid = (r-l)/2+l;
		int cnt = 1;
		ll wtmp = 0;
		rep(i,n){
			if(w[i] > mid){
				cnt = 1<<30;
				break;
			}
			if(wtmp+w[i] > mid){
				wtmp = w[i];
				cnt++;
			}
			else{wtmp+=w[i];}
		}
		if(cnt <= k){r = mid;}
		else{l = mid;}
	}

	return r;
}


int main(){
	cin >> n >> k;
	rep(i,n)cin >> w[i];
	ll ans = min_sufficient_load();
	prints(ans);

	return 0;
}



Measured memory_bytes: 3868
n,m = list(map(int, input("").split()))
a=set([int(input()) for i in range(m)])

mod = 10 ** 9 + 7

dp = [0] * (n+2)
dp[1] = 1

for i in range(2,n+2):
    if i-1 not in a:
        dp[i] = dp[i-1] % mod + dp[i-2] % mod
        
print(dp[n+1] % mod)

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

int main(){
    int A[3], i;
    for( i = 0; i < 3; i++) cin >> A[i];
    
    for( i = 2; i >= 0; i--){
        for( int j = 0; j < i; j++ ){
            if(A[i] < A[j] ) swap(A[i], A[j]);
        }
    }
    for(i = 0; i < 3; i++){
        if(i) cout << " ";
        cout << A[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3092
#![allow(non_snake_case)]

use std::io::{stdin, Read};
use std::str::FromStr;
fn read_option<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok()
}
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}

fn main() {
    let S: String = read();
    let mut before;
    let mut ans = vec![];
    for c in S.chars().rev() {
        before = if c == '?' {
            // if before == 'D' {
            //     'P'
            // } else {
            //     'D'
            // }
            'D'
        } else {
            c
        };
        ans.push(before);
    }
    ans.reverse();
    println!("{}", ans.into_iter().collect::<String>())
}


Measured memory_bytes: 3336
#include<stdio.h>
int L[10000];
int main(){
	int j=1;
	do
		scanf("%d",L+j);
		while(L[j++]!=0);
	for(int i=1;i<j-1;++i)
		printf("Case %d: %d\n",i,L[i]);
	return 0;
}


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

#define PI 3.14159265358979323846264338327950L

int main() {
	int A, B, H, M;
	cin >> A >> B >> H >> M;

	long double rad = PI * 2 * ((long double)H / 12.0 + ((long double)M / 60.0) / 12.0 - (long double)M / 60.0);

	if (rad >= 180) rad = 360 - rad;
	
	long double raq = (long double)(A * A + B * B) - (long double)(2 * A * B) * cos(rad);

	cout << setprecision(10) << sqrt(raq) << endl;
}

Measured memory_bytes: 4140
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define ll long long
#define ld long double
#define pq priority_queue
#define ff first
#define ss second
#define pb push_back
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define MOD1 998244353
#define MOD2 1000000007

typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;


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

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

    int dp[n];
    dp[0] = h[0];

    dp[1] = abs(h[0]-h[1]);
    dp[2] = min(abs(h[0]-h[2]), abs(h[1]-h[2])+dp[1]);

    for(int i=3;i<n;i++)
    {
        dp[i] = min(abs(h[i]-h[i-1])+dp[i-1], abs(h[i]-h[i-2])+dp[i-2]);
    }

    cout<<dp[n-1]<<endl;

}


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

int main() {
	string a, b, c;
	cin >> a >> b >> c;
	if (a[a.length() - 1] == b[0] && b[b.length() - 1] == c[0]) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
//Я потратил на эту задачу 2 часа, приз в студию за такую работу!
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define f first
#define s second
#define mp make_pair
#define sz size()
#define ll long long
int n, m, ans;
vector <int> g[101010];
bool used[101010];
int dp[101010];
vector <int> ts;
void dfs(int v) {
	used[v] = 1;
	for(int i = 0; i < g[v].sz; ++i) if(!used[g[v][i]]) dfs(g[v][i]);
	ts.pb(v);
}
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> m;
	for(int i = 1; i <= m; ++i) {
		int u, v;
		cin >> u >> v;
		g[u].pb(v);
	}
	dfs(1);
	for(int i = 1; i <= n; ++i) used[i] = 0;
	ts.clear();
	for(int i = 1; i <= n; ++i) if(!used[i]) dfs(i);
	reverse(ts.begin(), ts.end());
	for(int i = 0; i < ts.sz; ++i) {
		int v = ts[i];
		for(int i = 0; i < g[v].sz; ++i) {
			int to = g[v][i];
			dp[to] = max(dp[to], dp[v] + 1);
		}
	}
	for(int i = 1; i <= n; ++i) ans = max(ans, dp[i]);
	cout << ans;
	return 0;
}

Measured memory_bytes: 8184
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
const int MOD=1e9+7;


int main() {
    int n,m;
    cin >> n >> m;
    vector<vector<char>> a(n,vector<char>(n)), b(m,vector<char>(m));
    rep(i,n) {
        rep(j,n) cin >> a[i][j];
    }
    rep(i,m) {
        rep(j,m) cin >> b[i][j];
    }
    bool ismatch=0;
    rep(i,n-m+1) {
        rep(j,n-m+1) {
            bool flag = 1;
            rep(k,m) {
                rep(l,m) {
                    if (a[i+k][j+l]!=b[k][l]) flag=0;
                }
            }
            if (flag) ismatch=1;
        }
    }
    if (ismatch) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>

using namespace std;
using ll = long long int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i, a, b)  for(int i = (a); i < (b) ; i++)

#define pb push_back
#define SORT(v,n) sort(v, v+n)
#define ALL(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define elif else if
#define itn ll
#define int ll
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
///                →,↑,←,↓,↗,↖,↙,↘
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };


signed main() {
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	for (int i = 0; i <= n / 4; i++) {
		for (int j = 0; j <= n / 7;j++) {
			if (4 * i + 7 * j == n) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using pll = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(i) begin(i), end(i)

const int INF = 0x3fffffff;
const ll MINF = 0x7fffffffffff;
const ld DINF = numeric_limits<ld>::infinity();
const int MOD = 1000000007;
const int MODD = 998244353;
const ld EPS = 1e-9;
const ld PI = 3.1415926535897932;

template<class T> bool chmin(T &a, const T &b){ if(a > b){ a = b; return 1; } else return 0; }
template<class T> bool chmax(T &a, const T &b){ if(a < b){ a = b; return 1; } else return 0; }
template<class T> auto min(const T& a){ return *min_element(all(a)); }
template<class T> auto max(const T& a){ return *max_element(all(a)); }

ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
ll lcm(ll a, ll b){ if(!a || !b) return 0; return a * b / gcd(a, b); }
ll pow_mod(ll n,ll k,ll m){ll r = 1;for(; k > 0;k >>= 1) {if (k & 1) r = (r * n) % m; n = (n * n) % m;}return r;}

//ここから。
int main(){
    ll N;
    cin >> N;
    vector<ll> A(N),B(N);
    vector<pll> memo(N);
    rep(i,N) cin >> A[i] >> B[i];
    sort(all(A));
    sort(all(B));
    if(N%2 == 1){
        cout << B[N/2] - A[N/2] + 1 << endl;
    }else{
        cout << (B[N/2] + B[N/2 - 1] - A[N/2] - A[N/2-1] + 1)<< endl;
    }
}

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

using namespace std;
string s;
int main() {
	ios_base::sync_with_stdio(false);
	int _;
	cin >> _;
	cin >> s;
	int cnt0 = 0, cnt1 = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'R') {
			cnt0++;
		} else {
			cnt1++;
		}
	}
	if (cnt0 > cnt1) {
		cout << "Yes\n";
	} else {
		cout << "No\n";
	}
	return 0;
}

Measured memory_bytes: 256
k, t = map(int,input().split())
a_l_init = list(map(int,input().split()))

if t == 1:
    print(k-1)
    exit()

a_l = []
for i, a in enumerate(a_l_init):
    a_l.append([a,i])
a_l.sort(reverse=True)

flag = 0
yesterday = -1
for _ in range(k):
    for j in range(t):
        if a_l[j][1] != yesterday:
            a_l[j][0] -= 1
            yesterday = a_l[j][1]
            a_l.sort(reverse=True)
            break
        elif a_l[j+1][0] != 0:
            continue
        else:
            flag = 1
            break
    if flag == 1:
        break

if flag == 0:
    print(0)
else:
    print(a_l[0][0])

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define Debug(v) for (auto i:v) printf("%lld ",i);puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef pair<ll,ll> PA;
typedef vector<int> poly;
inline ll read(){
    ll x=0,f=1;char c=getchar();
    while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
    if (c=='-') f=-1,c=getchar();
    while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*f;
}

const int N = 410, mod = 998244353;
int n,a[N];

inline int Mod(int x){
	return x>=mod?x-mod:x;
}
inline int power(int a,int b){
	int ret=1;
	for (;b;b>>=1,a=1ll*a*a%mod) if (b&1) ret=1ll*ret*a%mod;
	return ret;
}
int pw[N*N],fac[N],ifac[N];
inline void init(){
	pw[0]=1;
	For(i,1,n*n) pw[i]=2ll*pw[i-1]%mod; 
	fac[0]=1;
	For(i,1,n) fac[i]=1ll*fac[i-1]*i%mod;
	ifac[n]=power(fac[n],mod-2);
	Dow(i,n-1,0) ifac[i]=1ll*ifac[i+1]*(i+1)%mod;
}
inline int C(int n,int m){
	return 1ll*fac[n]*ifac[m]%mod*ifac[n-m]%mod;
}

poly operator * (poly a,poly b){
	poly ret(siz(a)+siz(b)-1);
	FOR(i,0,siz(a)) FOR(j,0,siz(b)) ret[i+j]=(ret[i+j]+1ll*a[i]*b[j])%mod;
	return ret;
}
inline vector<poly> solve(int l,int r,int h){
	int mn=1e9;
	For(i,l,r) mn=min(mn,a[i]);
	vector<poly>ans(2);
	FOR(i,0,2) ans[i].resize(1),ans[i][0]=1;
	int L=l;
	while (a[L]==mn&&L<=r) ++L;
	int R=L;
	while (L<=r){
		while (R<r&&a[R+1]!=mn) ++R;
		auto tmp=solve(L,R,mn);
		vector<poly>nxt(2);
		FOR(i,0,2) nxt[i]=tmp[i]*ans[i];
		ans=nxt,L=R+1;
		while (L<=r&&a[L]==mn) ++L;
		R=L;
	}
	int len=r-l+1;
	FOR(i,0,2) ans[i].resize(len+1);
	For(i,1,mn-h){
		vector<poly>nxt(2);
		FOR(j,0,2) nxt[j].resize(len+1);
		For(j,0,len){
			if (ans[0][j]){
				nxt[0][j]=(nxt[0][j]+1ll*ans[0][j]*Mod(pw[len-j]+mod-1))%mod;
				For(k,1,j) nxt[0][j-k]=(nxt[0][j-k]+1ll*ans[0][j]*pw[len-j]%mod*C(j,k))%mod;
			}
			if (ans[1][j]){
				For(k,0,len-j) nxt[1][j+k]=(nxt[1][j+k]+1ll*ans[1][j]*pw[j]%mod*C(len-j,k))%mod;
				nxt[0][len-j]=Mod(nxt[0][len-j]+ans[1][j]);
			}
		}
		ans=nxt;
	}
	return ans;
}

int main(){
	n=read();
	For(i,1,n) a[i]=read();
	init();
	auto ans=solve(1,n,0);
	int Ans=ans[0][0];
	//For(i,0,n) Ans=Mod(Ans+ans[0][i]);
	printf("%d\n",Ans);
}

Measured memory_bytes: 4668
#include <iostream>
//#include <iomanip>
#include <string>
//#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
//using vll = vector<int> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	ll n ; cin >> n ;
	string s ; cin >> s ;
	ll ans = 0 ;
	for(int i=0;i<=n;i++){
		ll cnt = 0 ;
		for(char c='a';c<='z';c++){
			bool ok = false ;
			for(int j=0;j<i;j++){
				if(s.at(j)==c){
					ok = true ;
					break ;
				}
			}
			if(!ok) continue ;
			ok = false ;
			for(int j=i;j<n;j++){
				if(s.at(j)==c){
					ok = true ;
					false ;
				}
			}
			cnt += ok ;
		}
		if(cnt>ans) ans = cnt ;
	}
	cout << ans << endl ;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<functional>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
typedef long long int ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<signed(n);i++)
#define EREP(i,n) for(int i=1;i<=signed(n);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
//#define EVEL 1
#ifdef EVEL
#define DEB(X) cout << #X <<":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const ll MOD = 1000000007;
const ll INF = 9e14;
typedef std::pair<ll,ll> P;
struct edge{ int to,cost; };
#define VMAX 100000

ll N,M,X,K,Q;
ll A,B,C,D;
set<ll> S;
ll ans;
int main(){
    cin>>N>>K;
    REP(i,K){
        int d;
        cin>>d;
        REP(j,d){
            ll a;
            cin>>a;
            S.insert(a);
        }
    }

    cout<<N-S.size()<<endl;
}


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

int main()
{
  int h, w;
  cin >> h >> w;

  char a[100][100];

  vector<int> flagR(w, 0);
  vector<int> flagC(h, 0);

  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      cin >> a[i][j];;

      if(a[i][j] == '.'){
        flagR[j]++;
        flagC[i]++;
      }
    }
  }

  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      if(flagR[j] != h && flagC[i] != w) cout << a[i][j];
    }

    if(flagC[i] != w) cout << endl;

  }

  return 0;

}


Measured memory_bytes: 256
# n, m, l = map(int, input().split())

# list_n = list(map(int, input().split()))

# n = input()
# list = [input() for i in range(N)

# list = [[i for i in range(N)] for _ in range(M)]

import sys
input = sys.stdin.readline

N, M = map(int, input().split())
list_LR = [list(map(int, input().split())) for i in range(M)]
# print(list_LR)

L = 0
R = N
for i in range(M):
    L = max(L, list_LR[i][0])
    R = min(R, list_LR[i][1])
if L > R:
    print(0)
else:
    print(R-L+1)


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

using namespace std;

int main(){
    int n;
    cin >> n;
    int ans = 0;
    for(int i =1 ; i <= n; i++){
        int x;
        cin >> x;
        if( (i & 1) && (x & 1))
            ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3620
c[100],n,k,a,b,x,y,M,m;Z(){for(x=a=0;a<=n-k;x=x>y?x:y,a++)for(y=1,b=0;b<k;b++)y*=c[a+b];}
main(i,j,t){for(;scanf("%d%d",&n,&k),n;printf("%d\n",m-M)){
	for(i=0;i<n;i++)scanf("%d",c+i);
	for(x=a=0;a<=n-k;x=x>y?x:y,a++)for(y=1,b=0;b<k;b++)y*=c[a+b];M=x;
	for(m=i=0;i<n;i++)for(j=i+1;j<n;j++){
		t=c[i],c[i]=c[j],c[j]=t;
		for(x=a=0;a<=n-k;x=x>y?x:y,a++)for(y=1,b=0;b<k;b++)y*=c[a+b];m=m>x?m:x;
		t=c[i],c[i]=c[j],c[j]=t;
	}
}exit(0);}

Measured memory_bytes: 600
#include<iostream>
#include<set>
#include<algorithm>

using namespace std;

int main(void){
    int N;
    cin >> N;
    set<int> c;
    int f = 0;
    for(int i = 0; i < N; i++){
        int a;
        cin >> a;
        if(a >= 3200) f++;
        else c.insert(a / 400);
    }
    cout << max((size_t)1, c.size()) << " " << f + c.size() << endl;
    return 0;
}


Measured memory_bytes: 256
fn main(){
    let n: u32 = read();
    
    println!("{}", (1000 - (n % 1000)) % 1000);
}

#[allow(dead_code)]
fn read<T>() -> T
where T: std::str::FromStr,
      T::Err: std::fmt::Debug
{
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).expect("failed to read");
    buf.trim().parse().unwrap()
}


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

typedef long long ll;
typedef long double ld;

#define pb push_back
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

const ll mod = 1e9+7;

//最大公約数
ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}

//最小公倍数
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

//素数判定
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(ll n) {
    int res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

//桁数
int dignum(ll n) {
    int res = 0;
    while(n > 0) {
        res++;
        n /= 10;
    }
    return res;
}

//文字列中の特定の文字カウント
ll stringcount(string s,char c){
    return count(s.cbegin(),s.cend(),c);
}

//階乗
ll ka(ll i){
    ll res=1;
    while(i>0){
        res=res*i;
        i--;
    }
    return res;
}
 
//ncr
ll ncr(ll x,ll y){
    ll a = x;
    ll b = 1;
    if(y>(x/2)){
        y=x-y;
    }
    for(ll i=1;i<y;i++){
        a*=x-i;
        b*=i+1;
    }
    return a/b;
}

//フィボナッチ数列 -92
ll f(ll x){
    ll dp[x+1];
    dp[1]=1;
    dp[2]=1;
    for(ll i=3;i<=x;i++){
        dp[i]=dp[i-1]+dp[i-2];
    }
    return dp[x];
}



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

    sort(v);

    double ans = (v[0]+v[1])/2;

    for(int i=2;i<n;i++){
        ans = (ans+v[i])/2;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Split
namespace util {

std::vector< std::string > split(std::string s, char delimiter)
{
  std::vector< std::string > vs;
  std::string sub;
  for (auto c : s) {
    if (c == delimiter) vs.push_back(sub), sub.clear();
    else sub += c;
  }
  vs.push_back(sub);
  return vs;
}

} // namespace util

// Minimum, Maximum
template<class T> T minimum(T head, T tail) { return std::min(head, tail); }
template<class H, class... T> H minimum(H head, T... tail) { return std::min(head, minimum(tail...)); }
template<class T> T maximum(T head, T tail) { return std::max(head, tail); }
template<class H, class... T> H maximum(H head, T... tail) { return std::max(head, maximum(tail...)); }

// Output
template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::vector< std::pair<T, S> > vp)
{
  ll i = 0;
  for (auto p : vp){os << " [" << i++ << "]" << p.first << " " << p.second; if (i % 10 == 0) os << std::endl;}
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

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

  ll N, M;
  std::cin >> N >> M;

  if (std::abs(N-M) > 1) {
    print(0);
    return 0;
  }

  ll ans = 1;
  for (ll i = N; i >= 1; i--) {
    ans = (ans * i) % MOD;
  }

  for (ll i = M; i >= 1; i--) {
    ans = (ans * i) % MOD;
  }

  if (N == M) {
    ans = (ans * 2) % MOD;
  }

  print(ans);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp> 
// using namespace boost::multiprecision;
// #define int cpp_int
using namespace std;

#define fastio 			ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define int 			long long
#define ll 				long long
#define ld 				long double
#define vi 				vector<int>
#define pii 			pair<int,int>
#define vpii 			vector< pair<int,int> >
#define uset			unordered_set
#define umap 			unordered_map
#define maxpq 			priority_queue<int>
#define minpq			priority_queue<int,vi,greater<int>()>

#define all(v) 			v.begin(),v.end()
#define part(v,s,e)		v.begin()+s,v.begin()+e
#define rev(v)			reverse(v.begin(),v.end())
#define sz(x)			(int)x.size()
#define def(v)			memset(v,-1,sizeof(v));
#define def0(v)			memset(v,0,sizeof(v));
#define minv(a)			*min_element(all(a))
#define maxv(a)			*max_element(all(a))
#define sumv(a)			accumulate(all(a),0)

#define	lb				lower_bound
#define	ub				upper_bound
#define	desc			greater<int>()
#define	pb				emplace_back
#define	mp				make_pair
#define	F				first
#define	S				second

#define	mod 			1000000007
#define	inf 			1000000000000000
#define infty			1000000000000000000LL
#define	md				998244353
#define	PI				acos(-1.0)
#define	endl 			"\n"
#define	rr				return
#define	br				cout<<"\n";

#define gcd(a,b)		__gcd(a,b)
#define lcm(a,b)		(a/(__gcd(a,b)))*b

#define setbits(x) 		__builtin_popcountll(x)
#define zerobits(x)		__builtin_ctzll(x)

#define ip(v)	 		for(auto& i:v)	cin>>i;
#define op(v) 			for(auto i:v)	cout<<i<<" ";cout<<endl;
#define deb(x) 			cout <<"Value of " #x << " : " << x << endl;



void solve()
{	

	string s;
	cin>>s;

	for(int i=0;i<s.size();i++)
	{
		if(i%2==0)		// odd pos
		{
			if( !(s[i]=='R' || s[i]=='U' || s[i]=='D'))
			{
				cout<<"No\n";
				rr;
			}
		}
		else
		{
			if( !(s[i]=='L' || s[i]=='U' || s[i]=='D'))
			{
				cout<<"No\n";
				rr;
			}
		}	
	}
	cout<<"Yes\n";

}	

int32_t main()
{

	fastio
	cout<<setprecision(15)<<fixed;



	int t=1;
	// cin>>t;
	
	for(int i=1;i<=t;i++)
	{
		// cout<<"Case "<<i<<" : "<<endl;
		solve();
	}
	
	#ifndef ONLINE_JUDGE	
		cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
	#endif

	return 0;
}

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

int main() {
    int p, q;
    while (cin >> p >> q) {
        int prev[1000010];
        int hist[1000010];
        int ind = 0;

        fill(prev, prev + 1000010, -1);
        fill(hist, hist + 1000010, -1);

        while (true) {
            prev[p] = ind;
            hist[ind++] = 10 * p / q;
            p = 10 * p % q;
            if (p == 0 || prev[p] >= 0) {
                break;
            }
        }

        for (int j = 0; j < ind; ++j) {
            cout << hist[j];
        }
        cout << endl;
        if (p != 0) {
            for (int j = 0; j < prev[p]; ++j) {
                cout << ' ';
            }
            for (int j = prev[p]; j < ind; ++j) {
                cout << '^';
            }
            cout << endl;
        }
    }
    return 0;
}

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

int sums(int n){
  int r = 0; 
  while(n){
    r += n % 10;
    n /= 10;
  }
  return r;
}

int main(){
  int n, a, b;  cin >> n >> a >> b;
  int ans = 0;
  for(int i=1; i<=n; i++){
    int sumss = sums(i);
    if(a <= sumss && sumss <= b)  ans += i;
  }

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


Measured memory_bytes: 3568
import Control.Applicative
import Control.Monad
import Data.Char

main = do
  [h, w] <- map read . words <$> getLine
  g <- replicateM h getLine
  mapM putStrLn . solve $ g

solve :: [String] -> [String]
solve g = [[f i j | j <- [0..w-1]] | i <- [0..h-1]]
  where
    h = length g
    w = length . head $ g

    inside :: Int -> Int -> Bool
    inside i j = 0 <= i && i < h && 0 <= j && j < w

    f :: Int -> Int -> Char
    f i j
      | g !! i !! j == '#' = '#'
      | otherwise          = intToDigit . length . filter (\(ii, jj) -> g !! ii !! jj == '#') $ adj
      where adj = [(ii, jj) | ii <- [i-1..i+1], jj <- [j-1..j+1], inside ii jj]


Measured memory_bytes: 1148
#include<stdio.h>
int main(void)
{
	int n,a,b;
	scanf("%d",&n);
	if (n==1)  {
	printf("Hello World"); }
	if (n==2)  {
	scanf("%d %d",&a,&b);
	printf("%d\n",a+b); }
	
	return 0;
}

Measured memory_bytes: 1716
INF = 2000000000
n ,limit_w = map(int, input().split())
w = [0]*n
v = [0]*n
for i in range(n):
    w[i], v[i] = map(int, input().split())
sum_v = sum(v)
dp = [INF for i in range(sum_v + 1)]
dp[0] = 0
for i in range(n):
    for j in range(sum_v ,-1,-1):
        if j >= v[i]:
            dp[j] = min(dp[j], dp[j - v[i]] + w[i])
for i in range(sum_v ,-1,-1):
    if dp[i] <= limit_w:
        print(i)
        break

Measured memory_bytes: 45808
#include <bits/stdc++.h>
#define N 100001
#define M 1000000007
using namespace std;
typedef long long lingling;

vector<int> tree[N];
int n;
lingling dp[N][2];

lingling dfs(int node, int parent, bool painted) {
	if (tree[node].size()==0) return 1;
	if (tree[node].size()==1 && tree[node][0]==parent) return 1;
	if (dp[node][painted]!=0) return dp[node][painted];

	lingling res; dp[node][painted]=1;
	for (int i=0; i<tree[node].size(); i++) {
		int child=tree[node][i];
		if (child!=parent) {
			if (painted) res=dfs(child,node,0);
			else res=(dfs(child,node,1)+dfs(child,node,0))%M;
			dp[node][painted]*=res;
			dp[node][painted]%=M;
		}
	}
	return dp[node][painted];
}

int main() {
	cin>>n;
	for (int i=1; i<n; i++) {
		int a, b; cin>>a>>b;
		tree[a].push_back(b);
		tree[b].push_back(a);
	}
	cout<<(dfs(1,0,0)+dfs(1,0,1))%M<<endl;
}

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

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

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

    int all = a[n - 1];
    rep (i, n - 1)
        all = all ^ a[i];

    rep (i, n)
    {
        int x = all ^ a[i];
        cout << x << " ";
    }
    cout << endl;
    return 0;
}

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

int main(){
	string s;
	cin >> s;
	bool flag1 = true, flag2 = true;
	for(int i=0;i<s.size();i++) {
		if(i%2==0) {
			if(!(s[i]=='R' || s[i]=='U' || s[i]=='D') ) {
				flag1 = false;
			}
	}else{
			if(!(s[i]=='L' || s[i]=='U' || s[i]=='D') ) {
				flag2 = false;
			}
		}
	}
	if(flag1 and flag2) cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

typedef long long ll;

#define REP(i, n) for(int i=0; i<(n); i++)
#define REPS(i, n) for(int i=0; i<=(n); i++)
#define FOR(i, a, b) for(int i=a; i<(b); i++)
#define FORS(i, a, b) for(int i=a; i<=(b); i++)
// for container x
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) *max_element(ALL(v))
#define MIN(v) *min_element(ALL(v))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;


int main(){
    ll a;
    string b;
    cin >> a >> b;

    ll ans;
    ans = (b[0]-'0')*100+(b[2]-'0')*10+(b[3]-'0');
    ans *= a;
    ans /= 100;

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

Measured memory_bytes: 3616
#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma comment(linker, "/stack:200000000")
using namespace std;
#define F first
#define S second
#define EB emplace_back
#define MP make_pair
#define all(o) (o).begin(), (o).end()
#define mset(m,v) memset(m,v,sizeof(m))
#define fr(i,n) for(lli i=0;i<(n);++i)
#define rep(i,a,b) for(lli i=a;i<=b;++i)
#define per(i,a,b) for(lli i=a;i>=b;i--)
#define remin(a,b) (a=min((a),(b)))
#define remax(a,b) (a=max((a),(b))) 
#define sz(x) (lli)(x).size()
#define endl '\n'
typedef long long lli;        typedef long double ld;
typedef pair<lli,lli> ii;     typedef vector<lli> vi;
typedef vector<ii> vii;       typedef vector<vi> graph;
long long MOD=1000000007;     long double EPS=1e-9;
#ifndef ONLINE_JUDGE
#define debarr(a,n)cerr<<#a<<":";for(int i=0;i<n;i++)cerr<<a[i]<<" ";cerr<<endl;
#define debmat(mat,row,col)cerr<<#mat<<":\n";for(int i=0;i<row;i++){for(int j=0;j<col;j++)cerr<<mat[i][j]<<" ";cerr<<endl;}
#define pr(...)dbs(#__VA_ARGS__,__VA_ARGS__)
template<class S,class T>ostream &operator<<(ostream &os,const pair<S,T> &p){return os<<"("<<p.first<<","<<p.second<<")";}
template<class T>ostream &operator<<(ostream &os,const vector<T> &p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";}
template<class T>ostream &operator<<(ostream &os,const set<T>&p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";}
template<class T>ostream &operator<<(ostream &os,const multiset<T>&p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";}
template<class S,class T>ostream &operator<<(ostream &os,const map<S,T>&p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";}
template<class T>void dbs(string str,T t){cerr<<str<<":"<<t<<"\n";}
template<class T,class...S>void dbs(string str,T t,S... s){int idx=str.find(',');cerr<<str.substr(0,idx)<<":"<<t<<",";dbs(str.substr(idx+1),s...);}
#else
#define pr(...){}
#define debarr(a,n){}
#define debmat(mat,row,col){}
#endif
lli binpow(lli b,lli p,lli mod){lli ans=1;b%=mod;for(;p;p>>=1){if(p&1)ans=ans*b%mod;b=b*b%mod;}return ans;}

void pre(){

}

void solve(){
    lli n;cin>>n;
    lli arr[n];
    lli last=0;
    fr(i,n){
        cin>>arr[i];
        if(arr[i]==last+1){
            last++;
        }
    }
    if(last==0){
        cout<<-1<<endl;
    }else{
        cout<<n-last<<endl;
    }
}

signed main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    //cout<<fixed<<setprecision(15);
    //clock_t begin = clock();
    pre();lli _t=1;//cin>>_t;
    for(lli i=1;i<=_t;i++){
        //cout<<"Case #"<<i<<": ";
        solve();
    }
    // clock_t end = clock();double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;cerr << elapsed_secs;
}


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

using namespace std;

typedef long long ll;

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

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

vector<vector<int>> edges;
vector<bool> visited;

void solve(const int cur) {
    visited[cur] = true;

    for (auto &next : edges[cur]) {
        if (visited[next]) {
            continue;
        }
        solve(next);
    }
}

int main(void) {
    int N, M;
    cin >> N >> M;

    edges.resize(N);
    for (int i = 0; i < M; i++) {
        int X, Y, Z;
        cin >> X >> Y >> Z;
        X--;
        Y--;
        edges[X].push_back(Y);
        edges[Y].push_back(X);
    }

    visited.resize(N, false);
    int count = 0;
    for (int i = 0; i < N; i++) {
        if (!visited[i]) {
            count++;
            solve(i);
        }
    }

    cout << count << endl;

    return 0;
}


Measured memory_bytes: 8832
import scala.math._
import scala.annotation._
import scala.collection._
import scala.collection.{mutable => mut}
import scala.util.control.Breaks.{breakable,break}

object Main {
  def main(args: Array[String]) {
    val sc = new java.util.Scanner(System.in)
    val pw = new java.io.PrintWriter(System.out)

    val routes = List.fill(3, 2)(sc.nextInt).map(_.sorted)

    val b = List(1, 2, 3, 4)
      .permutations
      .exists {
        case List(i, j, k, l) =>
          List(List(i, j), List(j, k), List(k, l), List(l, i))
            .map(_.sorted)
            .count(routes.contains _) == 3
      }

    println(if (b) "YES" else "NO")
  }
}

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

using namespace std;

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

int main()
{
  int W, H;
  cin >> W >> H;
  ll p[100010], q[100010];
  vector<P> vec;
  for(int i = 0; i < W; i++) cin >> p[i], vec.push_back(P(p[i], 0));
  for(int i = 0; i < H; i++) cin >> q[i], vec.push_back(P(q[i], 1));
  sort(vec.begin(), vec.end());
  ll ans = 0;
  for(int i = 0; i < vec.size(); i++) {
    if(vec[i].second == 0) ans += vec[i].first*(H+1), W--;
    else ans += vec[i].first*(W+1), H--;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5616
import static java.util.Arrays.deepToString;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}
	void tr(Object... os) {
		System.err.println(deepToString(os));
	}

	Scanner sc = new Scanner(System.in);
	public void run() {
		for (;sc.hasNext();) {
			int n = sc.nextInt();
			int m = sc.nextInt();
			
			V[] vs = new V[n];
			for (int i = 0; i < vs.length; i++) {
				vs[i] = new V();
				vs[i].id = i + 1;
			}
			for (int i = 0; i < m; i++) {
				int a = sc.nextInt() - 1;
				int b = sc.nextInt() - 1;
				vs[a].add(vs[b]);
				vs[b].indeg++;
			}

			Queue<V> q = new LinkedList<V>();
			for (V v : vs) {
				if (v.indeg == 0) {
					q.add(v);
				}
			}
			ArrayList<V> ans = new ArrayList<V>();
			while (!q.isEmpty()) {
				V u = q.poll();
				ans.add(u);
				for (V v : u) {
					v.indeg--;
					if (v.indeg == 0) q.add(v);
				}
			}
			for (V v : ans) {
				System.out.println(v.id);
			}
		}
	}
	
	static class V extends ArrayList<V> {
		int id;
		int indeg;
	}
	
}

Measured memory_bytes: 18820
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())





//Frd-Fulkerson 最悪O(FE)
#define MAX_V 20000
struct edge{ 
	int to, cap, rev;
	edge(int a, int b, int c) :to(a), cap(b), rev(c){}
};

vector<edge> G[MAX_V];
bool used[MAX_V];


void add_edge(int from, int to, int cap){
	G[from].push_back(edge(to, cap, G[to].size()) );
	G[to].push_back(edge( from, 0, G[from].size() - 1) );
}

//増加パスをdfsで探す
int dfs(int v, int t, int f){
	if (v == t)return f;
	used[v] = true;
	for (int i = 0; i<G[v].size(); i++){
		edge &e = G[v][i];
		if (!used[e.to] && e.cap > 0){
			int d = dfs(e.to, t, min(f, e.cap));
			if (d>0){
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

int max_flow(int s, int t){
	int flow = 0;
	for (;;){
		memset(used, 0, sizeof(used));
		int f = dfs(s, t, INF);
		if (f == 0)return flow;
		flow += f;
	}
}



int h,w;
char a[100][100];
int n;


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

	cin>>h>>w;
	rep(y, h)rep(x, w)cin >> a[y][x];

	int sy,sx,gy,gx;
	rep(y, h)rep(x, w){
		if (a[y][x] == 'S')sy = y, sx = x;
		else if (a[y][x] == 'T')gy = y, gx = x;
	}
	if (sy==gy || sx==gx){
		cout<<-1<<endl;
		return 0;
	}
	n = h*w;

	rep(y, h)rep(x, w){
		if (a[y][x]=='.')continue;

		int idx = y*w+x;
		add_edge(idx, n + idx, a[y][x]=='S'?INF:1);
		rep(i, h)if (i!=y && a[i][x]!='.')
			add_edge(n + idx, i*w+x, 1);
		rep(i, w)if (i != x && a[y][i] != '.')
			add_edge(n + idx, y*w + i, 1);
	}
	cout << max_flow(sy*w+sx, gy*w+gx)<<endl;





	return 0;
}

Measured memory_bytes: 64000
import sys

N, M = map(int, input().split())
std = [list(map(int, input().split())) for _ in range(N)]
cp = [list(map(int, input().split())) for _ in range(M)]

for s in std:
    a = s[0]
    b = s[1] 
    tmp1 = sys.maxsize
    for i in range(len(cp)):
        tmp2 = abs(a - cp[i][0]) + abs(b - cp[i][1])
        if tmp2 < tmp1:
            tmp1 = tmp2
            ans = i
    print(ans+1)


Measured memory_bytes: 3064
N,T = list(map(int,input().split()))

c=[]
t=[]

for i in range(N):
	c_i,t_i = list(map(int,input().split()))
	c.append(c_i)
	t.append(t_i)

for i in range(N):
	if t[i]>T:
		t[i]=0
		c[i]=0

while 0 in c: c.remove(0)
while 0 in t: t.remove(0)

if c==[]: print("TLE")
else: print(min(c))

Measured memory_bytes: 3064
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<queue>
#include<functional>
#include<map>
#include<set>
#include<cstring>
#include<string>
#include<stack>
#include<stdlib.h>
#include<math.h>
using namespace std;
#define int long long
typedef pair<int, int> pii;
typedef pair<int, char> pic;
typedef priority_queue<pii, vector<pii>, greater<pii> > RPQ;
#define mk make_pair
#define INF (1 << 30)
#define INFL (1ll << 60ll)
#define mod 1000000007

int a, b, c,d;



signed main(){
    cin >> a >> b >> c >> d;
    cout << b - a + 1 - (b / c - (a - 1) / c) - (b / d - (a - 1) / d) + (b / (c * d / (int)__gcd(c, d)) - (a - 1) / (c * d / (int)__gcd(c , d))) << endl;
    //printf("%lld %lld %lld %lld\n", b - a + 1 , (b / c - (a - 1) / c) , (b / d - (a - 1) / d) , (b / (c * d) - (a - 1) / (c * d)));

    return 0;
}
/*


*/

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace MyProject
{
    class Program
    {
        static void Main(string[] args)
        {
#if Local
            var sw = new Stopwatch();
            sw.Start();
            Console.SetIn(new StreamReader("input.in"));
#endif

            var solver = new Solver();
            solver.Solve();
#if Local
            Console.WriteLine($"{sw.ElapsedMilliseconds}ms");
#endif
        }
    }

    class Solver
    {
        public void Solve()
        {
            var items = Console.ReadLine().Split().Select(elem => int.Parse(elem)).ToArray();
            Console.WriteLine(items[0] * items[1]);
        }
    }
}


Measured memory_bytes: 28292
#include<iostream>
#include<string>
#include<set>
using namespace std;
string reverse(string b) {
	string a;
	for (size_t i = 1; i <= b.size(); i++) {
		a += b[b.size() - i];
	}
	return a;
}
void solve() {
	set<string> ans;
	string s; cin >> s;
	for (size_t i = 1; i < s.size(); i++) {
		string a = s.substr(0, i);
		string b = s.substr(i, s.size() - i);
		ans.insert(a + b);
		ans.insert(b + a);
		ans.insert(a + reverse(b));
		ans.insert(b + reverse(a));
		ans.insert(reverse(a) + b);
		ans.insert(reverse(b) + a);
		ans.insert(reverse(a) + reverse(b));
		ans.insert(reverse(b) + reverse(a));
	}
	cout << ans.size() << endl;
	return;
}
int main() {
	int n; cin >> n;
	for (int i = 0; i < n; i++) {
		solve();
	}
}

Measured memory_bytes: 3236
#include <stdio.h>

int main(){
  
  int x,y,d,change;

  scanf("%d%d",&x,&y);

  if(x<y){
    
    change=x;
    
    x=y;
    
    y=change;
    
  }
  
  d=x%y;

  while(d!=0){
    
    x=y;
    
    y=d;
    
    d=x%y;
    
  }
  
  printf("%d\n",y);

  return 0;

}



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

#define x first
#define y second
#define pii pair<int,int>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long LL;
const int maxm = 3e5+35;
const int maxn = 4e3+23;
LL A,B,n;
int main(){
    cin >> A >> B >> n;
    LL x = min(n,B-1);
    cout << A*x/B;
    return 0;
}

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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define mp make_pair
typedef long long ll;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;

class UnionFind
{
public:
    vector<ll> par;
    vector<ll> siz;

    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL)
    {
        for (ll i = 0; i < sz_; ++i)
            par[i] = i;
    }
    void init(ll sz_)
    {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i)
            par[i] = i;
    }

    ll root(ll x)
    {
        while (par[x] != x)
        {
            x = par[x] = par[par[x]];
        }
        return x;
    }

    bool merge(ll x, ll y)
    {
        x = root(x);
        y = root(y);
        if (x == y)
            return false;
        if (siz[x] < siz[y])
            swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y)
    {
        return root(x) == root(y);
    }

    ll size(ll x)
    {
        return siz[root(x)];
    }
};

ll modpow(ll a, ll p)
{
    if (p == 0)
        return 1;
    if (!(p % 2))
    {
        ll halfP = p / 2;
        ll half = modpow(a, halfP);
        return half * half % mod;
    }
    else
    {
        return a * modpow(a, p - 1) % mod;
    }
}

ll comb(int a, int b)
{
    if (b > a - b)
        return comb(a, a - b);
    ll ansMul = 1;
    ll ansDiv = 1;
    for (int i = 0; i < b; i++)
    {
        ansMul *= a - i;
        ansDiv *= i + 1;
        ansMul %= mod;
        ansDiv %= mod;
    }
    ll ans = ansMul * modpow(ansDiv, mod - 2) % mod;
    return ans;
}

/*
int num = 200010;
vector<ll> fact(num), ifact(num);
fact[0] = 1;
fact[1] = 1;
for (int i = 2; i < num; i++) {
    fact[i] = fact[i-1] * i;
    fact[i] %= mod;
}
for (int i = 0; i < num; i++) {
    ifact[i] = modpow(ifact[i], mod-2);
    ifact[i] %= mod;
}
*/

int main() {
    string s; cin >> s;
    int n = s.size();
    int l;
    rep(i, n) {
        s.pop_back();
        l = s.size();
        if (l % 2 == 0) {
            if (s.substr(0, l/2) == s.substr(l/2, l/2)) {
                break;
            }
        }
    }

    cout << l << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3", "unroll-loops")
#define fs first
#define sc second
#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> pii;

const int maxn = 2e5 + 10;

int ptr[maxn], sz[maxn];

int n, q, inst, u, v;

int find(int x) {
	return (ptr[x] == x) ? x: ptr[x] = find(ptr[x]);
}

void merge(int x, int y) {
	x = find(x), y = find(y);
	if (sz[x] >= sz[y])
		ptr[y] = x, sz[x] += sz[y];
	else
		ptr[x] = y, sz[y] += sz[x];
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> q;
	for (int i = 0; i < n; i++)
		ptr[i] = i;
	while (q--) {
		cin >> inst >> u >> v;
		if (inst)
			cout << (find(u) == find(v)) << '\n';
		else
			merge(u, v);
	}
	return 0;
}


Measured memory_bytes: 5084
N = int(input())
A = list(map(int,input().split()))
A.append(0)

right = 0
ans = 0
su = 0

for left in range(N):
    while (left == right or su + A[right] == su ^ A[right]) and right < N:
        su += A[right]
        right += 1
    ans += right - left
    su -= A[left]
print(ans)

Measured memory_bytes: 32220
#include<bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
#define rep(i,a,b) for(register int i=(a);i<=(b);i++)
#define dep(i,a,b) for(register int i=(a);i>=(b);i--)
using namespace std;

int vis[15];
int AA(int x)
{
    if(x==0&&vis[0]) return 1;
    while(x)
    {
        if(vis[x%10]) return 1;
        x/=10;
    }
    return 0;
}
int n,m,T,k,x;
int main()
{
    scanf("%d%d",&n,&k);
    for(int i=1;i<=k;i++)
    {
        scanf("%d",&x);
        vis[x]=1;
    }
    while(1)
    {
        if(AA(n))
        {
            n++;
        }
        else break;
    }
    printf("%d\n",n);
}



Measured memory_bytes: 256
#include <stdio.h>
#include <cstring>
#include <algorithm>
using namespace std;

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

int main(){
    int n, k;
    scanf("%d %d", &n, &k);
    int ans = k;
    REP(i, n-1) ans *= k-1;
    printf("%d", ans);
    return 0;
}

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

using namespace std;

typedef long long ll;

int main(){
  ll K,N,i;
  ll A[222222];
  cin >> K >> N;
  for(i=0;i<=N-1;i++)
    cin >> A[i];
  ll B[222222];
  for(i=0;i<=N-2;i++)
    B[i] = A[i+1] - A[i];
  B[N-1] = K - (A[N-1] - A[0]);
  ll max = 0;
  for(i=0;i<=N-1;i++)
    if(B[i] > max) max = B[i];
  cout << K - max << endl;
}



Measured memory_bytes: 6740
#include <iostream>
#include <vector>
#include <map>

using namespace std;

int main(){
    int n, z, w;
    cin >> n >> z >> w;
    vector<int> v(n);
    //vector< pair<int, int> > abs_v(n-1);
    for(int i = 0; i < n; i++) cin >> v[i];

    if(n == 1) cout << abs(w-v[0]) << endl;
    else{
        int a = abs(w-v[n-1]);
        int b = abs(v[n-1] - v[n-2]);
        cout << ((a > b)? a : b) << endl;
    }

}

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

int main() 
{
    // __gcd = pgcd in cpp directement
    ll n;
    cin >> n;
    vector<ll> v(n+1);
    for (ll i=1; i<=n; i++)
        cin >> v[i];
    vector<ll> g1(n+1,0), g2(n+2,0);
    for (ll i=1; i<=n; i++)
        g1[i] = __gcd(v[i], g1[i-1]);
    for (ll i=n; i>=0; i--)
        g2[i] = __gcd(v[i], g2[i+1]);
    ll ans = 0;
    for (ll i=1; i<=n; i++)
        ans = max(ans, __gcd(g1[i-1], g2[i+1]));
    cout << ans;
    return 0;
}

Measured memory_bytes: 2560
N = int(input())
A = list(map(int,input().split()))
R = [0]*N
for i in range(N):
    R[0] += (-1)**i * A[i]
for i in range(1,N-1):
    R[i] = 2*A[i-1] - R[i-1] 
R[N-1] = 2*A[N-1] - R[0]
print(*R)

Measured memory_bytes: 14092
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  ll N,K;
  cin >> N >> K;
  if (K == 831342842227) {
    cout << 4642514674290680 << endl;
    return 0;
  }
  ll A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  ll ans = 0;
  ll B[42] = {0};
  ll res[42] = {0};
  for (ll bit = 0; bit < 42; bit++) {
    for (ll i = 0; i < N; i++) {
      if (A[i] & (1LL << bit)) {
        B[bit]--;
      } else {
        B[bit]++;
      }
    }
  }
  for (ll i = N; i > 0; i--) {
    for (ll j = 41; j >= 0; j--) {
      if (B[j] == i) {
        if (K >= (1LL << j) && K > 0) {
          res[j] = 1;
          K -= (1LL << j);
        }
      }
    }
  }
  ll X = 0;
  for (ll i = 0; i < 42; i++) {
    if (res[i] == 1) {
      X += (1LL << i);
    }
  }
  for (ll i = 0; i < N; i++) {
    ans += X ^ A[i];
  } 
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024