akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<cstring>
#include<bitset>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<numeric>
#include<set>
#include<math.h>
using namespace std;

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

#define rep(i,x) for(int i=0;i<x;i++)
#define re(i,x,y) for(int i=x;i<y;i++)

long long INF=1e9;
const int mod=10007;
#define ll long long

int main(){
    int n;
    cin>>n;
    vector<int>a(n);
    int two=0,four=0,none=0;
    rep(i,n){
        cin>>a[i];
        if(a[i]%4==0){
            four++;
        }else if(a[i]%2==0){
            two++;
        }else{
            none++;
        }
    }
    if(four==0){
        if(none==0&&two>=2){
            cout<<"Yes"<<endl;
        }else{
            cout<<"No"<<endl;
        }
    }else{
        if(two==0){
            if(four+1>=none){
                cout<<"Yes"<<endl;
            }
            else{
                cout<<"No"<<endl;
            }
        }else{
            if(four>=none){
                cout<<"Yes"<<endl;
            }else{
                cout<<"No"<<endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double PI = 4*atan(1);
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-6;
const string YES = "Possible";
const string NO = "Impossible";
#define pb push_back
#define mp make_pair

const int MAX_N = 105;
int A[MAX_N];
int N;

int cal(int n)
{
	int res = 0;
	for(int i=0;i<N;++i) res += (n-A[i])*(n-A[i]);
	return res;
}

void solve()
{
    int ans = 1e9;
	sort(A, A+N);
	int l = A[0], u = A[N-1];
	for(int i=l;i<=u;++i){
		ans = min(ans, cal(i));
	}
	cout << ans << endl;
}

int main()
{
	cin >> N;
	for(int i=0;i<N;++i) cin >> A[i];
	solve();
	return 0;
}

Measured memory_bytes: 256
n,m = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(m)]

ans = -1

if n == 1:
    for i in range(10):
        x = str(i)
        tf = 1
        for j in range(m):
            if x[sc[j][0] - 1] != str(sc[j][1]):
                tf = 0
        if tf == 1:
            ans = i
            break

elif n == 2:
    for i in range(10, 100):
        x = str(i)
        tf = 1
        for j in range(m):
            if x[sc[j][0] - 1] != str(sc[j][1]):
                tf = 0
        if tf == 1:
            ans = i
            break

else:
    for i in range(100, 1000):
        x = str(i)
        tf = 1
        for j in range(m):
            if x[sc[j][0] - 1] != str(sc[j][1]):
                tf = 0
        if tf == 1:
            ans = i
            break

print(ans)

Measured memory_bytes: 40688
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii=pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(c) begin(c),end(c)
#define rall(c) rbegin(c),rend(c)
#define fore(x,c) for(auto &&x:c)
#define rep(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define rrep(i, a, n) for(int i=(int)(n-1);i>=a;--i)
#define sz(c) ((int)c.size())
#define contains(c,x) (c.find(x)!=end(c))
#define inseg(l,x,r) ((l)<=(x)&&(x)<(r))
#define dump(...)
#define pb push_back
#define _ 0
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(nullptr); ios::sync_with_stdio(0);
        cout << setprecision(15) << fixed;
        // #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int N;
    cin >> N;
    string s;
    cin >> s;
    if (N % 2) {
        cout << "No" << endl;
    } else {
        string t = s.substr(0, N / 2);
        if (s == t + t) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
    return (0^_^0);
}



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

int main()
{
	int N, M, Q;
	int L[200010] = {};
	int R[200010] = {};
	int p[100010] = {};
	int q[100010] = {};

	cin >> N >> M >> Q;
	for(int i = 0; i < M; i++)
		cin >> L[i] >> R[i];
	for(int i = 0; i < Q; i++)
		cin >> p[i] >> q[i];

	int cnt[510][510] = {};
	for(int i = 0; i < M; i++)
		cnt[L[i]][R[i]]++;
	
	int csum[510][510] = {};
	for(int l = 0; l <= N; l++)
		for(int r = 0; r <= N; r++)
			csum[l][r] = cnt[l][r];
	for(int l = 0; l <= N; l++)
		for(int r = 0; r <= N; r++)
			csum[l+1][r] += csum[l][r];
	for(int l = 0; l <= N; l++)
		for(int r = 0; r <= N; r++)
			csum[l][r+1] += csum[l][r];
	
	for(int i = 0; i < Q; i++)
	{
		int cp = p[i];
		int cq = q[i];
		int ans = csum[cq][cq] - csum[cp-1][cq] - csum[cq][cp-1] + csum[cp-1][cp-1];
		cout << ans << endl;
	}

	return 0;
}



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

int main() {
  int N, x;
  cin >> N;
  
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    
    x = x+b-a+1;
  }
  cout << x << endl;
}

Measured memory_bytes: 256
/*
     Author: Wasi Ur Rahman
     RMSTU,Rangamati,Chittagong,Bangladesh
*/
#include <bits/stdc++.h>
using namespace std;
#define  gcd(a,b) __gcd(a,b)
#define  lcm(a,b) (a*b)/gcd(a,b)
#define  PI acos(-1.0)
#define  sqr(x) ((x)*(x))
#define  min3(a,b,c) min(a,min(b,c))
#define  min4(a,b,c,d) min(d,min(a,min(b,c)))
#define  max4(a,b,c,d) max(d,max(a,max(b,c)))
typedef   pair<int, int> ii;
typedef   std::vector<ii> vii;
#define   vi   std::vector<int>
#define   vll  std::vector<ll>
#define   all(n) n.begin(),n.end()
#define  mpsi std::map<string, int>
#define  pb             push_back
#define  ll             long long int
#define  ln             printf("\n");
#define  fast           ios::sync_with_stdio(false);cin.tie(0)
#define  max3(a,b,c)    max(a,max(b,c))
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)     __builtin_ctzll(x)
#define dec(x,y)        fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
#define  mod           1e9 + 7;
bool prm[1000001];
void sieve()
{
    prm[0] = prm[1] = 1;
    for(ll i = 4 ; i <= 1000000 ; i += 2)
        prm[i] = 1 ;
    for(ll i = 3 ; i * i <= 1000000 ; i += 2)
    {
        if(!prm[i])
        {
            for(ll j = i * i ; j <= 1000000 ; j+= i + i)
                prm[j] = 1 ;
        }
    }
}
const string str[32]={"1", "1", "1", "2", "1", "2", "1", "5", "2", "2", "1", "5", "1", "2", "1", "14", "1", "5", "1", "5", "2", "2", "1", "15", "2", "2",
     "5", "4", "1", "4", "1", "51"};
int main()
{
    fast;
    ll n;
    cin >> n;
    cout << str[n-1] << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
import math
import numpy as np
# from functools import lru_cache

args = sys.argv
if len(args) == 2:
  from IPython import embed
  em = True
else:
  em = False

#### input
N = int(input())
# a, b, c, d = map(int, input().split())
Bs = list(map(int, input().split()))
# a = list(map(lambda x: int(x)*(-1), a))  # 各要素を-1倍


# n = int(input())
# t = [int(input()) for i in range(n)]
if em: sys.stdin = open('/dev/tty')

#### functions
# @lru_cache(maxsize=10000)

#### process
# if em: embed()

As = [Bs[0]]

for i in range(0, len(Bs) - 1):
  As.append(min(Bs[i], Bs[i + 1]))

As.append(Bs[-1])
print(sum(As))
## heapsort, O(logN)
# import heapq
# heapq.heapify(A)
# min = heapq.heappop(A)
# heapq.heappush(A, new_element)


Measured memory_bytes: 12504
xs,ys,xt,yt=map(int,input().split())
N=int(input())
import numpy as np
XYR=np.empty((N+2,3),dtype=np.float64)
XYR[1:-1,:]=np.array([input().split() for i in range(N)])
XYR[0,:]=xs,ys,0
XYR[-1,:]=xt,yt,0
X,Y,R=XYR.T
c=np.maximum(0,np.sqrt(np.square(X[None,:]-X[:,None])+np.square(Y[None,:]-Y[:,None]))-R[None,:]-R[:,None])
c[range(N+2),range(N+2)]=-1
from scipy.sparse import*
g=csgraph.csgraph_from_dense(c,null_value=-1)
print(csgraph.dijkstra(g,indices=0)[-1])

Measured memory_bytes: 53776
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner a = new Scanner(System.in);
        int i = a.nextInt();
        if(i==3 || i==5 || i==7){
        System.out.println("YES");
    }else{
        System.out.println("NO");
        }
    a.close();
    }
}

Measured memory_bytes: 22740
#include<bits/stdc++.h>
using namespace std;
#define ll long long
// driver program for 0/1 knapsack
ll int knapsack(ll int wt[], ll int val[], ll int W, ll int n){
    ll int dp[n+1][W+1];
    for(int i=0;i<=n;i++){
        for(int j=0;j<=W;j++){
            if(i==0 || j==0){
                dp[i][j] = 0;
            }
            else{
                if(wt[i-1] > j){
                    dp[i][j] = dp[i-1][j];
                }
                else{
                    dp[i][j] = max(val[i-1] + dp[i-1][j-wt[i-1]], dp[i-1][j]);
                }
            }
        }
    }
    /*
    for(int i=0;i<=n;i++){
        for(int j=0;j<=W;j++){
            cout<<dp[i][j]<<"\t";
        }cout<<endl;
    }
    */
    return dp[n][W];
}

int main()
{
    ll int W, n;
    cin>>n>>W;
    ll int wt[W], val[n];
    for(int i=0;i<n;i++){
        cin>>wt[i]>>val[i];
    }
    //
    cout<<knapsack(wt, val, W, n)<<endl;
    return 0;
}


Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define de(c) cout << #c << " = " << c << endl
#define dd(c) cout << #c << " = " << c << " "
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

const int maxn = 3e5 + 100;
int h,w,m;
int T;
map<int,int> sx,sy;
pair<int,int> s[maxn];

int main(int argc, char const *argv[])
{
#ifdef indiewar
    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    T =1;
    while(T--) {
        int x,y;
        int mx = 0, my = 0;
        cin >> h >> w >> m;
        rep(i,0,m) {
            cin >> x >> y;
            sx[x]++;
            sy[y]++;
            s[i].fi = x , s[i].se = y;
            mx = max(mx,sx[x]);
            my = max(my,sy[y]);
        }
        ll nx = 0,ny = 0,num = 0;
        rep(i,1,h+1) {
            if(sx[i] == mx) {
                nx++;
            }
        }
        rep(i,1,w+1) {
            if(sy[i] == my) {
                ny++;
            }
        }
        rep(i,0,m) {
            if (sx[s[i].fi] == mx && sy[s[i].se] == my) {
                num++;
            }
        }
        if(nx*ny <= num) {
            cout << mx+my-1 << endl;
        }
        else{
            cout << mx+my << endl;
        }
    }
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> w(n+1);
    w[0] = 0;
    for(int i=1; i<n+1; i++){
        cin >> w[i];
        w[i] += w[i-1];
    }
    int han = w[n]/2;
    int pre = han;
    for(int i=1; i<n+1; i++){
        int tmp = abs(han-w[i]);
        if(pre > tmp){
            pre = tmp;
        }else{
            cout << abs(w[i-1] - (w[n] - w[i-1])) << endl;
            return 0;
        }
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define rp(a) while(a--)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	int n;
	ll out=1;
	cin>>n;
	rep(i,n)out*=i+1;
	cout<<out<<endl;
}

Measured memory_bytes: 1156
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 6)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
AL = al.upper()

n = k()
s = v()
e = list(itertools.accumulate([1 if i=="E" else 0 for i in s]))
w = list(itertools.accumulate([1 if i=="W" else 0 for i in s]))

for i in range(n):
    cnt = e[-1]-e[i]+w[i]
    if mod > cnt:
        mod,ans = cnt,i
if ans == 0:
    mod -= 1

print(mod)







Measured memory_bytes: 37928
#include "bits/stdc++.h"
using namespace std;
int main(){
    int a, b, c;
    cin >> a >> b >> c;
    bool d = false;
    for(int i = 1; i <= b; i++){
        if(a * i % b == c){
            d = true;
            break;
        }
    }
    if(d == true)
    cout << "YES" << endl;
    else 
    cout << "NO" << endl;
    return 0; 
}

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

#define fir first
#define sec second

typedef long long LL;
typedef pair<int,int> PP;

const int Maxn=2E5+5;

int N,M;
char s[Maxn];
int nxt[Maxn];

LL L,R;
LL len[1005];
LL cnt[1005][30];
LL Ans[30];

void Get_Nxt(){
	int X=1,Y=0;
	while(X<=N){
		if(Y==0 || s[Y]==s[X])
			nxt[++X]=++Y;
		else
			Y=nxt[Y];
	}
}

void Work_1(){
	for(int i=1;i<=M;++i)
		Ans[s[i]-'a']+=R/M;
	for(int i=1;i<=R%M;++i)
		++Ans[s[i]-'a'];
	for(int i=1;i<=M;++i)
		Ans[s[i]-'a']-=(L-1)/M;
	for(int i=1;i<=(L-1)%M;++i)
		--Ans[s[i]-'a'];
}

void Calc(LL X,int flag){
	if(X<=N){
		for(int i=1;i<=X;++i)
			Ans[s[i]-'a']+=flag;
		return ;
	}
	int i=1;
	while(len[i+1]<=X) ++i;
	for(int j=0;j<26;++j)
		Ans[j]+=cnt[i][j]*flag;
	Calc(X-len[i],flag);
}

void Work_2(){
	for(int i=1;i<=M;++i)
		++cnt[0][s[i]-'a'];
	for(int i=1;i<=N;++i)
		++cnt[1][s[i]-'a'];
	len[0]=M,len[1]=N;
	for(int i=2;;++i){
		len[i]=len[i-1]+len[i-2];
		if(len[i]>R) break ;
		for(int j=0;j<26;++j)
			cnt[i][j]=cnt[i-1][j]+cnt[i-2][j];
	}
	Calc(R,1),Calc(L-1,-1);
}

int main(){
	scanf("%s",s+1),N=strlen(s+1);
	scanf("%lld %lld",&L,&R); Get_Nxt();
	N>>=1; M=nxt[N+1]-1; M=N-M;
	if(N%M==0) Work_1();
	else Work_2();
	for(int i=0;i<26;++i)
		printf("%lld ",Ans[i]);
	return 0;
}


Measured memory_bytes: 1280
import numpy as np

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

B = sorted(A)

cnt = 0
amount = 0
for i in range(N):
  if cnt+B[i][1] < M:
    cnt += B[i][1]
    amount += B[i][0]*B[i][1]
  elif cnt+B[i][1] >= M:
    #cnt = M
    amount += B[i][0]*(M-cnt)
    break

print(amount)




Measured memory_bytes: 37644
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        boolean started = false;
        int len = 0;
        int index1 = 0, index2;
        for (int i=0; i<a.length(); i++) {
            if (!started && a.charAt(i) == 'A') {
                started = true;
                index1 = i;
            }
            if (started && a.charAt(i) == 'Z') {
                started = true;
                index2 = i;
                len = index2 - index1 + 1;
            }
        }
        System.out.println(len);
    }
}


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

using namespace std;

#define MOD 1000000007
#define ll long long int
#define ld long double
#define pb push_back
#define mkp make_pair
#define pii pair<int, int> 
#define pll pair<long long int, long long int>
#define sci(x) scanf("%d", &x)
#define scl(x) scanf("%lld", &x)
#define fi first
#define sc second
#define eps 1e-9

ll A[200005];

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

	ll n, i, j, k, x, y, z;
	ll ans = 0;
	cin >> n;
	for (i = 1; i <= n; ++i) {
		cin >> A[i];
	}
	x = 0;
	j = 1;
	for (i = 1; i <= n; ++i) {
		while (j <= n && ((x&A[j]) == 0)) {
			x |= A[j++];
		}
		ans += (j-i);
		for (k = 0; k <= 20; ++k) {
			if ((A[i]>>k)&1) x ^= (1ll<<k);
		}
	}
	cout << ans << endl;

	return 0;
}

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

int main() {
	// your code goes here
	int n;
	cin >> n;
	int arr[n];
	int flag=0,count=0;
	for(int i=0;i<n;i++)
	{
		cin >> arr[i];
		if(arr[i]%2==0)
		{
			flag=flag+1;
			if(arr[i]%3==0 || arr[i]%5==0)
			{
				count=count+1;
			}
		
		}
		
	}
		if(flag==count)
		cout << "APPROVED";
		else
		cout << "DENIED";
	
	return 0;
}

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

typedef long long ll;

bool isPrime(ll x){
  if(x == 0 || x == 1) return false;
  for(ll i = 2; i * i <= x; i++){
    if(x % i == 0) return false;
  }
  return true;
}

// Spaghetti Source
// ガウス素数判定 : http://www.prefield.com/algorithm/math/isgprime.html
bool isGaussianPrime(ll a, ll b) {
  if(a < 0) a = -a;
  if(b < 0) b = -b;
  if(a == 0) return b % 4 == 3 && isPrime(b);
  if(b == 0) return a % 4 == 3 && isPrime(a);
  return isPrime(a * a + b * b);
}

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

  while(T--){
    ll a, b;
    cin >> a >> b;
    cout << (isGaussianPrime(a, b) ? "P" : "C") << endl;
  }
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define int long long

int K, X;
signed main(){
    cin >> K >> X;
    cout << (500*K >= X ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int LL;
int val[45];
LL use[45];
vector<int> s[45];
int ans=1<<30;
int n,m;
int cnt(LL mask){
    int tmp=0;
    for(int i=0;i<n;i++){
        if(mask & (1LL<<i)) tmp+=val[i];
    }
    return tmp;
}
LL is = 0;
void dfs(int u,int fa,LL mask){
    if(is & (use[u]^(1LL<<fa)^(1LL<<u))) return;
    if(u==n-1){
        ans=min(ans,cnt(mask));
        return;
    }
    for(int i=0;i<s[u].size();i++){
        int v=s[u][i];
        if(is & (1LL << v)) continue;
        is ^= (1LL << v);
        dfs(v,u,mask | use[v]);
        is ^= (1LL << v);
    }
}
int main(){
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++){
        scanf("%d",&val[i]);
        use[i] = (1LL << i);
    }
    for(int i=0;i<m;i++){
        int x,y;
        scanf("%d%d",&x,&y);
        x--, y--;
        s[x].push_back(y);
        s[y].push_back(x);
        use[x] |= (1LL << y);
        use[y] |= (1LL << x);
    }
    is=1;
    dfs(0,n,use[0]);
    printf("%d\n",ans);
}

Measured memory_bytes: 3232
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
typedef long long ll;
#define vint vector<int>
#define vstring vector<string>
#define vll vector<ll>
#define vbool vector<bool>
#define INF 100000000

ll gcm(ll a,ll b);
ll lcm(ll a,ll b);

int main(){
  int n;
  cin >> n;
  int odd = 0;
  int even = 0;
  int weven = 0;
  rep(i,n){
    int a;
    cin >> a;
    if(a%4 == 0) weven++;
    else if(a%2 == 0) even++;
    else odd++;
  }
  n -= 1;
  n -= 2*weven;
  if(n > 0 && even > 1){
    n -= even-1; 
  }
  if(n > 0){
    cout << "No" << endl;
  }
  else{
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 256
N=gets.to_i
h=gets.split(" ").map(&:to_i)
tmp1,tmp2=0,(h[1]-h[0]).abs
for i in 2..N-1
	tmp1,tmp2=tmp2,[tmp1+(h[i-2]-h[i]).abs,tmp2+(h[i-1]-h[i]).abs].min
end
puts tmp2

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

using namespace std;
#define _rep(n, a, b) for (ll n = (a); n <= (b); ++n)
#define _rev(n, a, b) for (ll n = (a); n >= (b); --n)
#define _for(n, a, b) for (ll n = (a); n < (b); ++n)
#define _rof(n, a, b) for (ll n = (a); n > (b); --n)
#define oo 0x3f3f3f3f3f3f
#define ll long long
#define db double
#define eps 1e-6
#define bin(x) cout << bitset<10>(x) << endl;
#define what_is(x) cerr << #x << " is " << x << endl
#define met(a, b) memset(a, b, sizeof(a))
#define mp(a, b) make_pair(a, b)
#define all(x) x.begin(), x.end()
#define pii pair<ll, ll>
#define pdd pair<db, db>
#define pi acos(-1.0)
const ll maxn = 3e5 + 10;
const ll mod = 1e9 + 7;
inline ll qpow(ll a, ll b, ll mod = mod) {
	ll ret = 1;
	for (; b; b >>= 1, a = a * a % mod) {
		if (b & 1) {
			ret = ret * a % mod;
		}
	}
	return ret %mod;
}
ll n, m;
inline ll C(int m, int n, ll mod = mod) {//c(m,n)
	if (m == n)return 1;
	if (m < n)return 0;
	ll ans1 = 1, ans2 = 1;
	for(ll i = 1;i <= n; i++) {
		ans1 = ans1 * (m - i + 1) % mod;
		ans2 = ans2 * i % mod;
	}
	return ans1 * qpow(ans2, mod - 2, mod) % mod;
}
inline ll lucas(ll m, ll n,ll mod = mod) {
	return n == 0 ? 1 : C(m % mod, n % mod, mod) * lucas(m / mod, n / mod, mod) % mod;
}
signed main(){
    ll n, a, b;
    cin >> n >> a >> b;
    ll res = ((qpow(2, n) - lucas(n, a) - lucas(n, b) -1)%mod + mod)%mod;
    // ll f1 = qpow(2, n);
    // ll f2 = lucas(n, a);
    // ll f3 = lucas(n, b);
    cout << res << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);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 mp make_pair
#define fi first
#define sc second

int main(){
	string s1,s2;

	while(true) {
		cin >> s1;
		if(s1 == ".")
			break;
		cin >> s2;
		if(s1 == s2) {
			cout << "IDENTICAL" << endl;
			continue;
		}

		string t1,t2;

		t1 = t2 = "";
		ll cou1 = 0,cou2 = 0;
		vector<string> u1,u2;

		REP(i,s1.size()) {
			if(s1[i] == '\"') {
				i++;
				string u = "";
				while(s1[i] != '\"'){
					u.push_back(s1[i]);
					i++;
				}
				u1.pb(u);
				cou1++;
			}
			if(i < s1.size()) 
				t1.push_back(s1[i]);
		}
		REP(i,s2.size()) {
			if(s2[i] == '\"') {
				i++;
				string u = "";
				while(s2[i] != '\"'){
					u.push_back(s2[i]);
					i++;
				}
				u2.pb(u);
				cou2++;
			}
			if(i < s2.size()) 
				t2.push_back(s2[i]);
		}
		if(t1 != t2 || cou1 != cou2) {
			cout << "DIFFERENT" << endl;
			continue;
		}
		ll cou = 0;

		REP(i,u1.size()) {
			if(u1[i] != u2[i]) 
				cou++;
		}

		if(cou > 1) {
			cout << "DIFFERENT" << endl;
		}else {
			cout << "CLOSE" << endl;
		}

	}
	return 0;
}



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

#define rep(i,s,e) for(int i = (s);i <= (e);i++)

typedef long long i64;

int n;
i64 k;
vector<i64> a;

i64 gcd(i64 t,i64 s)
{
    if(t % s == 0)
    {
        return s;
    }
    return gcd(s,t % s);

}

int main()
{
    cin >> n >> k;
    a.resize(n,0);
    rep(i,0,n - 1) cin >> a[i];
    sort(a.begin(),a.end());
    i64 g = a[0];
    rep(i,1,n - 1) g = gcd(g,a[i]);
    if(k <= a.back() && k % g == 0)
    {
        cout << "POSSIBLE" << endl;
    }
    else
    {
        cout << "IMPOSSIBLE" << endl;
    }
    return 0;

}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main() {
    long long int i,n,max,min,sum,input,swap;

    cin >> n;
    cin >> max;
    sum=min=max;
    for(i=2;i<=n;i++)
    {
        cin >> input;
        if(input>=max)
        max=input;
        if(input<=min)
        min=input;
        sum=sum+input;
        
        
    }
    
    cout<< min << " " << max << " " << sum << endl;
    
    
}


Measured memory_bytes: 3116
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string alpha = "abcdefghijklmnopqrstuvwxyz";
            int[] ans = new int[26];
            while (true) 
            {
                string input = Console.ReadLine();
                if (input == null || input.Length == 0)
                    break;
                else 
                {
                    input = input.ToLower();
                    for (int i = 0; i < input.Length; i++)
                    {
                        for (int j = 0; j < alpha.Length; j++) 
                        {
                            if('a' <= input[i] && input[i] <= 'z')
                            if (input[i] == alpha[j])
                                ++ans[j];
                        }
                    }
                }
            }
            for (int i = 0; i < alpha.Length; i++)
            {
                Console.WriteLine(alpha[i] + " : " + ans[i]);
            }
        }
    }
}

Measured memory_bytes: 9068
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef pair<int,int>P;

int n,nex,cost;
int dis[100009],ans[100009];
vector<P>v[100009];

void SET(int x,int i){
  nex=v[x][i].first;
  cost=v[x][i].second;
}

void dfs1(int x,int pre){
  r(i,v[x].size()){
    SET(x,i);
    if(nex==pre)continue;
    dfs1(nex,x);
    SET(x,i);
    dis[x]=max(dis[x],dis[nex]+cost);
  }
}

void dfs2(int x,int d_pre,int pre){
  vector<P>child;
  child.push_back(P(0,-1));
  r(i,v[x].size()){
    SET(x,i);
    if(nex==pre)child.push_back(P(d_pre+cost,nex));
    else child.push_back(P(dis[nex]+cost,nex));
  }
  sort(child.begin(),child.end(),greater<P>());
  ans[x]=max(child[0].first,child[1].first);
  r(i,v[x].size()){
    SET(x,i);
    if(nex==pre)continue;
    dfs2(nex,child[nex==child[0].second].first,x);
  }
}

int main(){
  cin>>n;
  r(i,n-1){
    int s,t,w;
    scanf("%d%d%d",&s,&t,&w);
    v[s].push_back(P(t,w));
    v[t].push_back(P(s,w));
  }
  dfs1(0,-1);
  dfs2(0,0,-1);
  r(i,n)cout<<ans[i]<<endl;
}


Measured memory_bytes: 7764
d=1..gets.to_i
r=d.map{[]}<<[]
gets.to_i.times{x,y=gets.split.map &:to_i;r[x]<<y}
a=[0]*21
b=[*d]
d.map{|c|b=b.flat_map{|i|a[i]=c;r[i]}}
puts d.sort_by{|i|a[i]}

Measured memory_bytes: 6152
import java.util.*;
import java.util.Map.Entry;
 
 
 
public class Main{
	
	
	
	public static Set<Long> set=new HashSet<Long>();
	public static long T;
	public static long ans;
	

 
	
	//最大公約数・最小公倍数（セットで使う）
	public static long gcm(long a, long b) {
		long result = a;
		long k = 0;
		long n = b;
		do {
			k = result % n;
			result = n;
			n = k;
		} while(k != 0);
		return result;
	}
	
	public static long lcm(long a, long b) {
		long g;
		g = gcm(a, b);
		return a/g*b;
	}
	
	static long gcd(long a, long b) {
		if (b == 0) {
			return a;			
		}
		return gcd(b, a % b);
	}
	
	//等差数列
	static long tousasum(int n) {
		return (long)n*((long)n+1)/2;
	}
 
 
 
	//素数判定
	static boolean isPrime (int n) {
		if (n==2) return true;
		if (n<2 || n%2==0) return false;
		double d = Math.sqrt(n);
		for (int i=3; i<=d; i+=2) if(n%i==0){return false;}
		return true;
	}
 
 
	//倍数判定（10進数以外のときに有用）
	static boolean isMultiple (String s, int base, int m) {
		int temp = 0;
		for (int i=0; i<s.length(); i++) {
			temp = (temp*base+Character.getNumericValue(s.charAt(i)))%m;
		}
		if (temp==0) {return true;}
		return false;
	}
 
 
	//階乗
	static long factorial (int i) {
		if (i==1) {return 1;}
		else {return i*factorial(i-1);}
	}
 
 
	//進数変換
	static String toNbase (String sm, int m, int n) {
		return Long.toString(Long.parseLong(sm,m),n);
	}
	
	public static final long gcd_n(long[] param) {
	    final int len = param.length;
	    long g = gcd(param[0], param[1]);    //gcd(a, b) は以前作ったもの
	    for (int i = 1; i < len - 1; i++) {
	        g = gcd(g, param[i + 1]);       //gcd(a, b) は以前作ったもの
	    }
	    return g;
	}
	
	public static long lcm_n(long[] numbers) {
		long l;
		l = numbers[0];
		for (int i = 1; i < numbers.length; i++) {
			l = lcm(l, numbers[i]);
		}
		return l;
	}
	
    public static boolean tree(long N,long r) {
    	ans = r;
    	if(N==T) {
    		return true;
    	}else if(2*N==T||2*N+1==T) {
    		ans = r+1;
    		return true;
    	}else if(2*N>T) {
    		return false;
    	}
    	return tree(2*N,r+1)||tree(2*N+1,r+1);
    	
    	
    }
	
	
 public static void main(String[] args) {
	 Scanner sc=new Scanner(System.in);
	 int N=sc.nextInt();
	 String S=sc.next(),T=sc.next();
	 
	 int length = 0;
	 boolean flag = false;
	 for(int i=0;i<N;i++) {
		 if(T.contains(S.substring(i))) {
			 flag = true;
			 length = i;
			 break;
		 }
	 }
	 if(!flag) {
		 System.out.println(2*N);
	 }else {
		 System.out.println((S.substring(0,length)+T).length());
	 }
	 
	 
	 
	
	 
    
}
}


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

using namespace std;

int main()
{
  bool isPrime[100001];
  for(int i = 0; i <= 100000; i++) isPrime[i] = true;
  isPrime[0] = isPrime[1] = false;
  for(int i = 2; i <= 100000; i++){
    if(isPrime[i]){
      for(int j = i+i; j <= 100000; j+=i) isPrime[j] = false;
    }
  }
  int m, a, b;
  while(cin >> m >> a >> b, m || a || b){
    int P = 0, Q = 0;
    for(int p = 0; p <= m/2; p++){
      if(!isPrime[p]) continue;
      for(int q = 0; q <= m/p; q++){
	if(!isPrime[q]) continue;
	if(p*q > m) continue;
	if(p > q) continue;
	if(a*q > p*b) continue;
	if(p*q > P*Q) P = p, Q = q;
      }
    }
    cout << P << " " << Q << endl;
  }
  return 0;
}

Measured memory_bytes: 1256
li = [[1,3,5,7,8,10,12],[4,6,9,11],[2]]
x,y = map(int,input().split())
for i in range(3):
    if x in li[i]:
        a = i
for i in range(3):
    if y in li[i]:
        b = i
if a == b:
    print("Yes")
else:
    print("No")


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

using namespace std;

typedef long long ll;

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

        int a,b,c;
        cin>>a>>b>>c;
        cout<<max(0,c-a+b)<<"\n";

        return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define uLL unsigned long long
#define db double

using namespace std;
const int N=17,_=121,M=(1<<16)+10,mod=1e9+7;
int rd()
{
	int x=0,w=1;char ch=0;
	while(ch<'0'||ch>'9'){if(ch=='-') w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
	return x*w;
}
int n,m,ans,l2[M],f[M],g[M],cc[M],nm[M],pw[_];
bool mp[N][N];

int main()
{
	n=rd(),m=rd();
	for(int i=1;i<=m;++i)
	{
		int x=rd(),y=rd();
		mp[x][y]=mp[y][x]=1;
		cc[1<<(x-1)]|=1<<(y-1),cc[1<<(y-1)]|=1<<(x-1);
	}
	pw[0]=1;
	for(int i=1;i<=m;++i) pw[i]=2ll*pw[i-1]%mod;
	int nn=1<<n;
	for(int i=1;i<=nn;++i) l2[i]=l2[i>>1]+1;
	for(int i=0;i<nn;++i)
	{
		int x=i&(-i),ls=i^x;
		cc[i]=cc[x]|cc[ls];
		nm[i]=nm[ls];
		for(int j=1;j<=n;++j)
			if((ls>>(j-1)&1)&&mp[j][l2[x]]) ++nm[i];
	}
	for(int i=1;i<nn;++i)
	{
		if(i>>0&1)
		{
			f[i]=pw[nm[i]];
			for(int j=(i-1)&i;j;j=(j-1)&i)
				f[i]=(f[i]-1ll*f[j]*pw[nm[i^j]]%mod+mod)%mod;
		}
		if(i>>1&1)
		{
			g[i]=pw[nm[i]];
			for(int j=(i-1)&i;j;j=(j-1)&i)
				g[i]=(g[i]-1ll*g[j]*pw[nm[i^j]]%mod+mod)%mod;
		}
	}
	int ans=pw[m];
	for(int i=1;i<nn;++i)
		if(i>>0&1)
		{
			int u=(nn-1)^i;
			for(int j=u;j;j=(j-1)&u)
				if((j>>1&1)&&!(cc[i]&j))
					ans=(ans-1ll*f[i]*g[j]%mod*pw[nm[(nn-1)^i^j]]%mod+mod)%mod;
		}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vb = vector<bool>;
using vll = vector<long long>;
using vpii = vector<pair<int,int>>;
using vivi = vector<vector<int>>;
using vbvb = vector<vector<bool>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int mod = 1000000007;
const int inf = 1001001001;

int main(void) {
  ll n;
  cin >> n;
  vll a(5,0);
  rep(i,n) {
    string s;
    cin >> s;
    if(s[0]=='M') a[0]++;
    if(s[0]=='A') a[1]++;
    if(s[0]=='R') a[2]++;
    if(s[0]=='C') a[3]++;
    if(s[0]=='H') a[4]++;
  }
  ll ans = 0;
  rep(i,5)rep2(j,i+1,5)rep2(k,j+1,5){
    if(i==j || j==k || k==i)continue;
    ans += a[i]*a[j]*a[k];
  }
  cout << ans << endl;
      
  
}




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

int main() {
  int X,Y,Z;
  cin>>X>>Y>>Z;
  swap(X,Y);
  swap(X,Z);
  cout<<X<<" "<<Y<<" "<<Z<<endl;
}

Measured memory_bytes: 256
n = int(input())
ListB = [int(val) for val in input().split()]
sumA = ListB[0]
count = 1
while(count < n - 1):
	if (ListB[count - 1] < ListB[count]):
		sumA += ListB[count - 1]
	else:
		sumA += ListB[count]
	count += 1
sumA += ListB[n - 2]
print(sumA)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
        using namespace std;
        #define ll long double
        #define pb push_back
        #define pf push_front
        #define f first
        #define s second
        #define mk make_pair
        #define MOD 1000000007
        int main()
        {
          ios_base::sync_with_stdio(false);
          cin.tie(NULL);
        	ll a,b,c;
        	cin>>a>>b>>c;
          long double eps= 1.0E-14;
        	if(sqrt(a)+sqrt(b)+eps<sqrt(c))
        	cout<<"Yes";
        	else
        	cout<<"No";
          return 0;
        }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define N 3050
typedef long long ll;
ll a[N],ps[N],memo[N][N];
int n;

void preCompute() {
    for (int i = 1 ; i <= n ; i++)
        ps[i] = ps[i - 1] + a[i];
}

ll sum(int l , int r) {
    return ps[r] - ps[l - 1];
}

ll dp(int l , int r) {
    if (l == r) return a[l];
    ll &sol = memo[l][r];
    if (sol != -1) return sol;
    return sol = max(
        a[l] + (sum(l + 1 , r) - dp(l + 1 , r)) ,
        a[r] + (sum(l , r - 1) - dp(l , r - 1))
    );
}

int main() {
    scanf("%d" , &n);
    ll sum = 0;
    for (int i = 1 ; i <= n ; i++) {
        scanf("%lld" , &a[i]);
        sum += a[i];
    }
    preCompute();
    memset (memo , -1 , sizeof memo);
    ll x = dp(1 , n);
    ll y = sum - x;
    printf("%lld\n" , x - y);
}


Measured memory_bytes: 73216
#include <bits/stdc++.h>
#define lli long long int
using namespace std;
#define MOD 1000000007
#define mod 1000000037
#define mod1 998244353
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
#define INF 2*1e9

int main()
{
    fastio;
    int n;
    cin >> n;
    vector<int>a(n),b(n),c(n);
    for(int i=0;i<n;i++)
        cin >> a[i] >> b[i] >> c[i];
    int dp[n][3];
    dp[0][0]=a[0];dp[0][1]=b[0];dp[0][2]=c[0];
    for(int i=1;i<n;i++)
    {
        dp[i][0]=a[i]+max(dp[i-1][1],dp[i-1][2]);
        dp[i][1]=b[i]+max(dp[i-1][0],dp[i-1][2]);
        dp[i][2]=c[i]+max(dp[i-1][0],dp[i-1][1]);
    }
    cout << max({dp[n-1][0],dp[n-1][1],dp[n-1][2]}) << endl;
}

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

int main(){
  double a, ans;
  while(cin >> a){
    ans = a;
    for(int i = 2; i <= 10; i++){
      if(i % 2 == 0) a *= 2;
      else a /= 3; 
      ans += a; 
    }
    cout << fixed << setprecision(8) << ans << endl; 
  }
}

Measured memory_bytes: 1280
#pragma region header
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr int inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */
#pragma endregion
int main() {
    int n;cin >> n;
    vector<string> v(n);
    set<string> st;
    rep(i, n) {
        string s;cin >> s;
        v[i]=s;
        st.insert(s);
        if(i>0) {
            if(v[i-1][v[i-1].size()-1]!=s[0]){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    if(n!=st.size()) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3584
#include<stdio.h>

long long gcd(long long x,long long y){
    long long r;
    while((r = x%y) != 0){/*ユークリッドの互除法*/
    x=y;
    y=r;
    }
    return y;
}

long long LCM(long long x, long long y){
return (x*y)/gcd(x,y);
}
int main(){
  long long A,B,C,D,i,j,k,ans=0;
  
  scanf("%lld %lld %lld %lld",&A,&B,&C,&D);
  A--;
  ans = (B-B/C - B/D + B/LCM(C,D)) - (A-A/C - A/D + A/LCM(C,D));
  printf("%lld\n",ans);
  return 0;
}

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

int main() {
  
  int N;
  
  cin >> N;
  
  vector<int> vec(N);
  for(int i =0 ;i < N;i++){
    cin >> vec.at(i); 
  }
  
  int count = 0;
  int num = 1;
  int res;
  
  for(int i = 0;i<N;i++){
    if(vec.at(i) == num){
      num++;
//      cout << "num=" << num << endl;
    }
    else{
      count++; 
 //           cout << vec.at(i) << ":count++" << endl;
    }
  }
  if(num == 1){
//    cout << "num ==1:" << num << endl;
    res = -1; 
  }
  else{
    res = count; 
  }
  
  
  cout << res << endl;
}





Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 2510;
const int MAXM = 200010;
const int MAXK = 110;
const int MAXQ = 200010;

int n, m, p, f[MAXN], F[MAXN];
ll d[MAXN], D[MAXN], d2[MAXN], D2[MAXN];
vector<II> a[MAXN], b[MAXN];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n >> m >> p;
    FOR(i,1,m) {
        int u, v, c;
        cin >> u >> v >> c;
        c -= p;
        c = -c;
        a[u].emplace_back(II(v, c));
        b[v].emplace_back(II(u, c));
    }

    d[1] = 0;
    f[1] = 1;
    FOR(i,2,n) d[i] = 1e18;
    FOR(i,1,n-1) {
        FOR(u,1,n) {
            FOR(j,0,SZ(a[u])-1) {
                II r = a[u][j];
                d[r.FI] = min(d[r.FI], d[u] + r.SE);
                f[r.FI] |= f[u];
            }
        }
    }

    FOR(i,1,n) D[i] = d[i];
    FOR(i,1,n-1) {
        FOR(u,1,n) {
            FOR(j,0,SZ(a[u])-1) {
                II r = a[u][j];
                D[r.FI] = min(D[r.FI], D[u] + r.SE);
            }
        }
    }
    FOR(i,1,n)
        if (D[i] != d[i] && f[i]) d[i] = -1000000000LL;

    // FOR(i,1,n) cout << d[i] << endl;

    
    d2[n] = 0;
    F[n] = 1;
    FOR(i,1,n-1) d2[i] = 1e18;
    FOR(i,1,n-1) {
        FORE(u,n,1) {
            FOR(j,0,SZ(b[u])-1) {
                II r = b[u][j];
                d2[r.FI] = min(d2[r.FI], d2[u] + r.SE);
                F[r.FI] |= F[u];
            }
        }
    }

    FOR(i,1,n) D2[i] = d2[i];
    FOR(i,1,n-1) {
        FORE(u,n,1) {
            FOR(j,0,SZ(b[u])-1) {
                II r = b[u][j];
                D2[r.FI] = min(D2[r.FI], D2[u] + r.SE);
            }
        }
    }
    FOR(i,1,n)
        if (D2[i] != d2[i] && F[i]) d2[i] = -1000000000LL;
    
    FOR(i,1,n)
        if (d[i] == d2[i] && d2[i] == -1000000000LL) {
            cout << -1;
            return 0;
        }

    cout << max(0LL, -d[n]);
    return 0;
}


Measured memory_bytes: 640
import itertools


n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))

junretsu = itertools.permutations(range(1, n + 1))
junretsu = sorted(junretsu)
a = junretsu.index(p)
b = junretsu.index(q)

print(abs(a - b))


Measured memory_bytes: 8052
#include <stdio.h>
#include <stdlib.h>

int compare_int(const void *a, const void *b){
   if(*(long long int*)b > *(long long int*)a){
     return 1;
   }else{
     return -1;
   }
}

int main(){
  int n,m = 0;
  scanf("%d %d",&n,&m);
  long long int x[n];
  long long int y[n];
  long long int z[n];
  int i = 0;
  for(i=0;i<n;i++){
    scanf("%lld %lld %lld",&x[i],&y[i],&z[i]);
  }
  long long int sum[n];
  long long int ret = 0;
  int s[3];
  s[0]=s[1]=s[2]=1;
  long long int max = 0;
  long long int min = 0;
  int si = 0;
  for(si=0;si<4;si++){
    switch (si) {
      case 0: s[0]=1;s[1]=1;s[2]=1;break;
      case 1: s[0]=-1;s[1]=1;s[2]=1;break;
      case 2: s[0]=-1;s[1]=-1;s[2]=1;break;
      case 3: s[0]= 1;s[1]=-1;s[2]=1;break;
      default: return 1;
    }
    for(i = 0;i < n; i++){
      sum[i] = s[0]*x[i]+s[1]*y[i]+s[2]*z[i];
    }
    qsort(sum,n,sizeof(long long int),compare_int);
    max = 0; min = 0;
    for(i=0;i < m; i++){
      max = max + sum[i];
      min = min + sum[n-1-i];
    }
    if(max > ret){
      ret = max;
    }
    if(min * -1 > ret){
      ret = min * -1;
    }
  }
  printf("%lld\n",ret);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
#define all(obj) (obj).begin(), (obj).end()
static const int dx[4] = {0, 1, 0, -1};
static const int dy[4] = {1, 0, -1, 0};
static const char dir[4] = {'u', 'r', 'd', 'l'};
static const ll INF = 1 << 21;
static const ll MOD = 1e9 + 7;

signed main() {
  string s;
  cin >> s;
  int K;
  cin >> K;

  int cur = 0;
  while (cur != (int)s.size()) {
    if (s[cur] != 'a' && 'z' - s[cur] + 1 <= K) {
      K -= 'z' - s[cur] + 1;
      s[cur] = 'a';
    }
    ++cur;
  }
  K %= 26;
  while (K && 0 < cur && cur <= (int)s.size()) {
    while (s[cur - 1] != 'z' && K) {
      s[cur - 1]++;
      K--;
    }
    cur--;
  }
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 512
#include<cstdio>
#include<cctype>
#include<vector>
using namespace std;
const int N=2000,inf=0x3f3f3f3f;
int n,val[N+1];
vector<int>e[N+1];
int siz[N+1],dis[N+1],f[N+1];
int res=inf;
void dfs(int u,int fa)
{
    siz[u]=val[u],dis[u]=0;
    int maxn=0;
    for(int v:e[u]) {
        if(v==fa) {
            continue;
        }
        dfs(v,u);
        siz[u]+=siz[v],dis[u]+=dis[v];
        if(dis[v]>=dis[maxn]) {
            maxn=v;
        }
    }
    if(maxn) {
        if(dis[u]>=dis[maxn]*2) {
            f[u]=dis[u]/2;
        } else {
            f[u]=dis[u]-dis[maxn]+min(f[maxn],(dis[maxn]*2-dis[u])/2);
        }
    } else {
        f[u]=0;
    }
    if(fa) {
        dis[u]+=siz[u];
    }
    return;
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;++i) {
        char c=getchar();
        while(!isdigit(c)) {
            c=getchar();
        }
        val[i]=c-'0';
    }
    for(int i=1,u,v;i<n;++i) {
        scanf("%d%d",&u,&v);
        e[u].push_back(v),e[v].push_back(u);
    }
    for(int i=1;i<=n;++i) {
        dfs(i,0);
        if(!(dis[i]&1)&&(f[i]>=dis[i]/2)) {
            res=min(res,dis[i]/2);
        }
    }
    printf("%d\n",res==inf?-1:res);
    return 0;
}


Measured memory_bytes: 3524
#include <stdio.h>

long calc(long max, long count) {
  return (max - count + 1) * count + 1;
}

int main(void) {
  int n, k;
  
  scanf("%d %d", &n, &k);
  long ret = 0;
  for(int i = k;i <= n + 1;i++) {
    ret += calc(n, i);
  }
  ret %= 1000000007;
  printf("%ld\n", ret);
  return 0;
}


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

int main(){
  string A,B;
  cin >> A >> B;
  if(A.length()>B.length()){cout << "GREATER" << endl;}
  else if(A.length()<B.length()){cout << "LESS" << endl;}
  else if(A>B){cout << "GREATER" << endl;}
  else if(A<B){cout << "LESS" << endl;}
  else{cout << "EQUAL" << endl;}
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(){
    int n, j, count_;
    cin >> n;
    vector<int> arr;
    arr.resize(n);
    for(vector<int>::iterator itr = arr.begin(); itr < arr.end(); itr++){
        cin >> *itr;
    }
    count_ = 0;
    for(int i = 0; i < n; i++){
        j = i;
        while(arr[j] == j + 1 && j < n) j++;
        if(j == i){
            continue;
        }
        else if((j - i) % 2 == 0){
            count_ += (j - i) / 2;
        }else{
            count_ += (j - i) / 2 + 1;
        }
        i = j;
    }
    cout << count_ << endl;
    return 0;
}


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

using namespace std;

const int MOD = (int)1e9 + 7;

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

  vector<bool> primes(n + 1, true);
  primes[0] = primes[1] = false;
  for (int i = 2; i * i <= n; i++) {
    if (primes[i]) {
      for (int j = i * i; j <= n; j += i) {
        primes[j] = false;
      }
    }
  }

  long long ans = 1;
  for (int i = 0; i <= n; i++) {
    if (!primes[i]) continue;

    long long cnt = 0;
    for (int j = i; j <= n; j++) {
      int tmp = j;
      while (tmp != 0 && tmp % i == 0) {
        tmp /= i;
        cnt++;
      }
    }
    ans *= cnt + 1;
    ans %= MOD;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
long long x, y, ans, n, m;
 
int main(){
	scanf("%lld%lld", &n, &m);
	if (n != 1 && m != 1){
		ans = m * n - (2 * m + 2 * n - 4);
	} else {
		if (n == 1 && m == 1) ans = 1;
		else ans = m * n - 2;
	}
	printf("%lld", ans);
	
	return 0;
} 

Measured memory_bytes: 128