akhauriyash/Code-Regression huggingface dataset:
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647
// MAX O(n) 10^18

int main() {
    int N, X;
    cin >> N >> X;
    vector<int> L(N);
    rep(i, N) cin >> L.at(i);

    vector<int> D(N + 1);
    D.at(0) = 0;
    int ans = 0;
    for (int i = 1; i <= N; i++) {
        D.at(i) = D.at(i - 1) + L.at(i - 1);
        if (D.at(i) <= X) {
            ans = i + 1;
        }
    }

    cout << ans << endl;

    return 0;
}


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

int read(){
	int a = 0; char c = getchar(); bool f = 0;
	while(!isdigit(c)){f = c == '-'; c = getchar();}
	while(isdigit(c)){
		a = a * 10 + c - 48; c = getchar();
	}
	return f ? -a : a;
}

#define int long long
const int _ = 1e5 + 7;
struct peo{int A , B , C;}now[_]; int X , Y , Z , N , ans[_];

signed main(){
	X = read(); Y = read(); Z = read(); N = X + Y + Z;
	int sum = 0 , cur = 0;
	for(int i = 1 ; i <= N ; ++i){
		now[i].A = read(); now[i].B = read(); now[i].C = read();
		now[i].A -= now[i].C; now[i].B -= now[i].C; sum += now[i].C;
	}
	sort(now + 1 , now + N + 1 , [&](peo a , peo b){return a.A - a.B > b.A - b.B;});
	multiset < int > val;
	for(int i = 1 ; i <= N ; ++i){
		val.insert(now[i].A); cur += now[i].A;
		if(val.size() > X){cur -= *val.begin(); val.erase(val.begin());}
		ans[i] = cur;
	}
	val.clear(); cur = 0;
	for(int i = N ; i ; --i){
		val.insert(now[i].B); cur += now[i].B;
		if(val.size() > Y){cur -= *val.begin(); val.erase(val.begin());}
		ans[i - 1] += cur;
	}
	int mx = -1e18;
	for(int i = X ; i + Y <= N ; ++i) mx = max(mx , ans[i]);
	cout << sum + mx;
	return 0;
}


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

#define gc() getchar()

#define ll long long
#define ri register int 

using std::max;

inline int read()
{
	int ret=0;char ch=gc();
	while(!isdigit(ch))ch=gc();
	while(isdigit(ch))
	{
		ret=ret*10+ch-'0';
		ch=gc();
	}
	return ret;
}

const int MAXN=2e3+10;
const int MOD=1e9+7;

int n,S;
int f[MAXN/3][MAXN];
int sum[MAXN/3][MAXN];
int ans;

int main()
{
//	freopen("in.in","r",stdin);
	
	S=read();n=S/3;
	
	f[0][0]=sum[0][0]=1;
	for(ri j=1;j<=S;++j)sum[0][j]=sum[0][j-1]+f[0][j];
	
	for(ri i=1;i<=n;++i)
	{
		for(ri j=3;j<=S;++j)
		{
			f[i][j]=sum[i-1][j-3];
			sum[i][j]=(sum[i][j-1]+f[i][j])%MOD;
//			printf("f[%d][%d]=%d\n",i,j,f[i][j]);
		}
		ans=(ans+f[i][S])%MOD;
	}
	printf("%d\n",ans);
	
	return 0;
}

Measured memory_bytes: 14164
#ifdef Prateek
  #include "Prateek.h"
#else
  #include <bits/stdc++.h>
  using namespace std;
  #define debug(...) 42
#endif
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
const int MOD = 1e9+7, N = 1e5 + 10; 

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   int a[6];
   f(i,1,6) cin >> a[i];
   f(i,1,6) if(!a[i]) cout << i;
   return 0;
} 

Measured memory_bytes: 3612
/*
Cerberus97
Hanit Banga
*/

#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

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

const int N = 1e5 + 10;

ll a[N], suff[N];

int main() {
	int n; cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
	}
	for (int i = n; i >= 1; --i) {
		suff[i] = abs(a[i] - a[i + 1]) + suff[i + 1];
	}
	ll cost = 0;
	for (int i = 1; i <= n; ++i) {
		cout << cost + abs(a[i - 1] - a[i + 1]) + suff[i + 1] << '\n';
		cost += abs(a[i - 1] - a[i]);
	}
}

Measured memory_bytes: 2816
import math

def gcd(a,b,c):
    d = math.gcd(a, b)

    return math.gcd(c,d)

k = int(input())
sum = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        for c in range(1, k+1):
            sum += gcd(a,b,c)

print(sum)

Measured memory_bytes: 68068
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res
def gcd(x, y):
    if x < y: x, y = y, x
    div = x % y
    while div != 0:
        x, y = y, div
        div = x % y
    return y

N=II()
cnt = 0
for i in range(1,10):
    for i_keta in range(6):
        for j in range(1,10):
            for j_keta in range(6):
                A = i if i_keta == 0 else int(str(i) + ("0"*(i_keta-1)) + str(j))
                B = j if j_keta == 0 else int(str(j) + ("0"*(j_keta-1)) + str(i))
                if A <= N and B <=N:
                    if i_keta == 0 or j_keta == 0:

                        patA = 0
                        if i_keta:
                            if (i+1)*(10**i_keta) <= N:
                                patA = 10**(i_keta-1)
                            else:
                                for k in range(10000):
                                    if A+k*10 <= N:
                                        patA += 1
                                    else:
                                        break
                        else:
                            patA=1

                        patB = 0
                        if j_keta:
                            if (j+1)*(10**j_keta) <= N:
                                patB = 10**(j_keta-1)
                            else:
                                for k in range(10000):
                                    if B+k*10 <= N:
                                        patB += 1
                                    else:
                                        break
                        else:
                            patB = 1


                        if i == j:
                            # print(A,B,patA*patB)
                            cnt += patA*patB
                    else:
                        patA = 0
                        if (i+1)*(10**i_keta) <= N:
                            patA = 10**(i_keta-1)
                        else:
                            for k in range(10000):
                                if A+k*10 <= N:
                                    patA += 1
                                else:
                                    break

                        patB = 0
                        if (j+1)*(10**j_keta) <= N:
                            patB = 10**(j_keta-1)
                        else:
                            for k in range(10000):
                                if B+k*10 <= N:
                                    patB += 1
                                else:
                                    break
                        cnt += patA*patB
                        # print(A,B,patA*patB)

print(cnt)


Measured memory_bytes: 43356
#include <bits/stdc++.h>
using namespace std;
int main() {
	long long int a, b, ans = 1;
	cin >> a >> b;
	if(a > 1 && b > 1)  ans = ((a * b) / 2) + ((a * b) % 2 ? 1 : 0);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

i64 n, d;
int main() {
  cin >> n >> d;
  i64 e = 2 * d + 1;
  cout << (n + e - 1) / e << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
        int a,b,c;
        scanf("%d %d %d",&a,&b,&c);
        if(a<b){
                if(b<c){
                    printf("%d %d %d\n",a,b,c);
                }else if(a<c){
                    printf("%d %d %d\n",a,c,b);
                }else{
                    printf("%d %d %d\n",c,a,b);
                }
        }else{
                if(a<c){
                    printf("%d %d %d\n",b,a,c);
                }else if(b<c){
                    printf("%d %d %d\n",b,c,a);
                }else{
                    printf("%d %d %d\n",c,b,a);
                }
        }
        return 0;
}

Measured memory_bytes: 1172
/* AtCoder コピペ */
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repEq(i, n) for (int i = 0; i <= (int)(n); i++)
#define repVector(i, v) for (auto i = v.begin(); i != v.end(); ++i)

#define ifBetween(n, a, b) if (n > a && n < b)
#define ifBetweenEq(n, a, b) if (n >= a && n <= b)

int main() {
	string s;
  	string result = "Yes";
  	cin >> s;
  
  	int n = s.length();
    char charArray[n + 1];
  	strcpy(charArray, s.c_str());
    
    map<char, int> counter;

  	rep(i, n) {
      counter[charArray[i]]++;
    }

    for (auto pair : counter) {
        if (pair.second % 2 != 0) {
          result = "No";
          break;
        }
    }
  
  	cout << result << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pb push_back
#define f first
#define s second
#define MOD 1000000007
 
using namespace std;

int A[100001];
int B[100001];

void solve(){
	int n; cin>>n;
	for(int i=0; i<n; i++){
		cin>>A[i];
	}
	for(int i=0; i<n; i++){
		B[A[i]] = i+1;
	}
	for(int i=1; i<=n; i++){
		cout<<B[i]<<" ";
	}

}


int main()
{ 
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout<<fixed<<setprecision(12);
	int t =1; //cin>>t;
	for(int i=1; i<=t; i++){
		solve();
		cout<<"\n";
	}
	return 0;

}

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

int main() {
  int K,A,B;
  cin >> K >> A >> B;
int D;
 D=0;
  for (int i = A; i <= B; i++) {
 int C = i % K;
if (C == 0)
 D++;
}
  if(D > 0)
  cout << "OK" << endl; 

  else
  cout << "NG" << endl;
 }


Measured memory_bytes: 3636
import java.util.Scanner;

/**
 * Created by Harry on 3/31/20.
 */
public class Main {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int res = 0;
        int a=0, b=0, c=0;
        for(int i=0; i<n ;i++){
            int curA = scanner.nextInt() + Math.max(b,c);
            int curB = scanner.nextInt() + Math.max(a,c);
            int curC = scanner.nextInt() + Math.max(a,b);
            a = curA;
            b = curB;
            c = curC;
        }
        System.out.print(Math.max(a, Math.max(b,c)));
    }
}


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

int main()
{
	long long a, b, k;
	bool flag = true;
	scanf("%lld  %lld %lld", &a, &b, &k);
	while (k--)
	{
		if (flag)//a
		{
			flag = false;
			if (a & 1)//odd
			{
				a--;
				int t = a / 2;
				a -= t;
				b += t;
			}
			else
			{
				int t = a / 2;
				a -= t;
				b += t;
			}

		}

		else//b
		{
			flag = true;
			if (b & 1)//odd
			{
				b--;
				int t = b / 2;
				b -= t;
				a += t;
			}
			else
			{
				int t = b / 2;
				b -= t;
				a += t;
			}

		}

	}

	printf("%lld %lld\n", a, b);

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int N,K,d,a,ans=0;
int main(){
    cin>>N>>K;
    bool v[N];
    memset(v,false,sizeof v);
    for(int i=0;i<K;i++){
        cin>>d;
        for(int j=0;j<d;j++){
            cin>>a;
            v[a-1]=true;
        }
    }
    //for(int i=0;i<N;i++)cout<<(v[i]?1:0)<<endl;
    for(int i=0;i<N;i++)if(v[i]==false)ans++;
    cout<<ans<<endl;
    return 0;
}

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

int main(){
  ll n,x;
  cin>>n>>x;
  ll ans=n;
  ll a=n-x;
  ll px=x;
  while(x%a) ans+=2*(a*(x/a)),px=x,x=a,a=px-(a*(px/a));
  ans+=2*(a*(x/a))-a;
  cout <<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())

V = 0
for i in range(1,N+1):
    V += i*(N+1-i)

E = 0
for i in range(N-1):
    u,v = map(int,input().split())
    a = min(u,v)
    b = max(u,v)
    E += a*(N+1-b)

print(V-E)

Measured memory_bytes: 73948
import sys
input = sys.stdin.readline
import math

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

N, K = MI()
mylist = LI()
length = len(mylist)

high = max(mylist)+1
low = 0
mid = (high + low) / 2

while high - low >= 0.001:
    temp = 0
    for i in mylist:
        if i % mid == 0:
            temp += (i // mid) - 1
        else:
            temp += i // mid
    if temp > K:
        low = mid
    else:
        high = mid
    mid = (high + low) / 2

result = math.ceil(low)


num2 = result+10**(-8)
temp= 0
for i in mylist:
    if i % num2 == 0:
        temp += (i // num2) - 1
    else:
        temp += i // num2
if temp > K:
    print(result+1)
else:
    print(result)

Measured memory_bytes: 92696
/*
たてH cm よこ W cm の長方形を描くプログラムを作成して下さい。
1 cm × 1cm の長方形を '#'で表します。
 */

// Time Limit Exceeded

#include <stdio.h>

int main(void)
{
    int height, width;
    int i, j;

    for (;;)
    {
        scanf("%d %d", &height, &width);
        if (height == 0 && width == 0)
            break;

        for (i = 0; i < height; i++)
        {
            for (j = 0; j < width; j++)
            {
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
    }
    return (0);
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef tuple<int, int> duo;
const int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
const int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
const int Mod = 1000000000 + 0;
//{{{ templates
#define TT_ template<typename T>inline
#define TTF_ template<typename T,typename F>inline
TT_ T sq(T x){return x*x;}
TT_ T In(){T x;cin>>x;return x;}
TT_ void Out(T&x){cout<<x;}
TT_ void sort(T&v){sort(begin(v),end(v));}
TT_ void revs(T&v){reverse(begin(v),end(v));}
TT_ void uniq(T&v){sort(v);v.erase(unique(begin(v),end(v)),end(v));}
TT_ int ubnd(T&v,typename T::value_type&x){return upper_bound(begin(v),end(v),x)-begin(v);}
TT_ int lbnd(T&v,typename T::value_type&x){return lower_bound(begin(v),end(v),x)-begin(v);}
TTF_ void inpt(T&v,int n,F f){for(v.reserve(n);n--;v.emplace_back(f()));}
TTF_ void show(T&v,F f,string d=" ",string e="\n"){int i=0;for(auto&x:v)i++&&(cout<<d),f(x);cout<<e;}
TT_ typename T::iterator minel(T&v){return min_element(begin(v),end(v));}
TT_ typename T::iterator maxel(T&v){return max_element(begin(v),end(v));}

inline void fast_io(){ios::sync_with_stdio(0);cin.tie(0);}
inline int in(){int x;scanf("%d",&x);return x;}
inline ll pow_mod(ll a,ll k,ll m){ll r=1;for(;k>0;a=a*a%m,k>>=1)if(k&1)r=r*a%m;return r;}
inline ll mod_inv(ll a,ll p){return pow_mod(a,p-2,p);}
//}}} priority_queue queue deque front stringstream max_element min_element insert count make_tuple

int main()
{
  cout << __gcd(in(), in()) << endl;
  return 0;
}

Measured memory_bytes: 1200
#include <iostream>
#include <vector>
#include <string>
#include <boost/algorithm/string.hpp>
#include <boost/foreach.hpp>
#include <boost/range/algorithm/count.hpp>
using namespace std;



int main() {
    int n, m;
    cin >> n >> m;
    vector<int> kinds(m);
    for (int i = 0; i < n; i++) {
        int num;
        cin >> num;
        for (int j = 0; j < num; j++) {
            int k;
            cin >> k;
            kinds.at(k-1)++;
        }
    }


    cout << boost::count(kinds, n) << endl;
    return 0;
}


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

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

#define REPR(i,n) for(int i =n; i >=0; --i)

#define _REP(i,m,n) for(int i =m; i <n; ++i)

#define INF 2e9

using namespace std;

int main(){
   int n; cin >> n;
   vector<int> a(n+1);

   REP(i,n){
       int b;
       cin >>b ; 
       a[b] = i+1;
   }

    _REP(i,1,n+1)cout << a[i] << " " ;
    cout << endl;
    return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#include <string>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
#define mod 1000000007

ll di(ll s,ll b){
    if(s==-1) return 0;
    else return s/b+1;
}

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

    cout << di(b,x)-di(a-1,x) << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();

        Set<String> s = new HashSet<>();
        for (int i = 0; i < n; i++) {
            s.add(in.next());
        }

        System.out.println(s.size());
    }
}



Measured memory_bytes: 76924
#include <iostream>
    #include <vector>
    #include <set>
    #include <algorithm>
    #include <string>
    #include <cmath>
    #include <iomanip>
    #include <map>
    #include <set>
    using namespace std;
    #define loop(i,N) for(ll (i)=0; (i)<(N);++(i))
    struct _OMAZINAI_ { _OMAZINAI_() { std::ios::sync_with_stdio(false); std::cin.tie(0); } } __omazinai_instance__;
    #define INF ((1LL<<61) + (1<<29))
    #define YesNo(x) {std::cout << ((x)?"Yes":"No") << std::endl;}
    #define YESNO(x) {std::cout << ((x)?"YES":"NO") << std::endl;}
    #define OddEven(x) {std::cout << ((x)%2?"Odd":"Even") << std::endl;}
    #define ODDEVEN(x) {std::cout << ((x)%2?"ODD":"EVEN") << std::endl;}
    typedef long long int ll;
    ll my_gcd(ll a, ll b) { return b ? my_gcd(b, a%b) : a; };
    void _INPUT_IMPL_() {};
    template <class T, class... Args> void _INPUT_IMPL_(T& dest, Args&... args) { cin >> dest; _INPUT_IMPL_(args...); }
    void _OUTPUT_IMPL_() {};
    template <class T, class... Args> void _OUTPUT_IMPL_(T dest, Args... args) { cout << dest << (sizeof...(Args) ? " " : ""); _OUTPUT_IMPL_(args...); }
    #define in(type, ...) type __VA_ARGS__; _INPUT_IMPL_(__VA_ARGS__)
    #define in_v(type, name, cnt) vector<type> name(cnt); loop(i, cnt) cin >> name[i];
    #define sort_v(v) std::sort(v.begin(), v.end())
    #define out(...) (_OUTPUT_IMPL_(__VA_ARGS__), std::cout<<std::endl)
    #define set_fix(x) ((std::cerr<<std::fixed<<std::setprecision(x)),(std::cout<<std::fixed<<std::setprecision(x)))
    //小さい方に寄る
    #define space_op(x, y, a, b, c) ([](auto x_, auto y_, auto a_, auto b_, auto c_){if(x_<y_)return a_;if(x_>y_)return c_;return b_;}(x,y,a,b,c))
    #define space_out(x, y, a, b, c) out(space_op(x, y, a, b, c))
     
    // ^^^ Template ^^^ //
     
  int main(){
    in(ll, N, M);
    for(ll t = M/N; t; --t)
      if(M % t == 0){
        out(t);
        return 0;
      }
  }

Measured memory_bytes: 256
a=[0 for code in range(26)]
b= 'abcdefghijklmnopqrstuvwxyz'
while True:
    try:
        c=input()
        for i in range(len(c)):
            if c[i] in b or c[i].lower() in b:
                a[b.index(c[i].lower())]+=1
    except:
        break
for j in range(26) :
    print(f'{b[j]} : {a[j]}')


Measured memory_bytes: 5584
#include <stdio.h>

int main(void) {
    int n, i, j, maxi, cnt, maxj;
    scanf("%d", &n);
    int a[n];
    maxi = 0; cnt = 0; maxj = 0;
    for (i = 0; i < n; i++) {
        scanf("%d", &a[i]);
        if (a[i] > maxi) maxi = a[i];
    }

    for (i = 0; i < n; i++) {
        if (maxi == a[i]) cnt++;
    }

    for (i = 0; i < n; i++) {
        if (cnt > 1 || maxi > a[i]) printf("%d\n", maxi);
        else {
            maxj = 0;
            for (j = 0; j < n; j++) {
                if (i == j) continue;
                if (a[j] > maxj) maxj = a[j];
            }
            printf("%d\n", maxj);
        }
    }
    return 0;
}

Measured memory_bytes: 2304
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <queue>
# define MOD 1000000000+7
# define INF 1000000000
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
using namespace std;

int main() {
	ll n = 0, a,b,m = 0,counter = 0;
	string in,in2;
	vector<ll>vec;
	cin >> n >> in;
	if (n >=  3200)cout << in << endl;
	else { cout << "red" << endl; }
	
}




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

int N, W; long long D[100100];

int main()
{
	scanf("%d %d", &N, &W);

	for (int i=1;i<=N;i++){
		int w,v; scanf ("%d %d",&w,&v);
		for (int j=W-w;j>=0;j--) if (D[j+w] < D[j] + v) D[j+w] = D[j] + v;
	}
	printf ("%lld\n",D[W]);

	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define mk make_pair
using namespace std;
typedef long long ll;
const int N = 3e3 + 5;
const int mod = 1e9 + 7;
int n, k, a[N];
ll dp[N][N];
bool bo[N][N];
void cal(int l, int r, int f) {
	if (bo[l][r]) return;
	if (l > r) return;
	cal(l + 1, r, 1 - f);
	cal(l, r - 1, 1 - f);
	if (f) {
		dp[l][r] = max(dp[l + 1][r] + a[l], dp[l][r - 1] + a[r]);	
	} else {
		dp[l][r] = min(dp[l + 1][r] - a[l], dp[l][r - 1] - a[r]);
	}
	bo[l][r] = 1;
}
int main() {
	cin >> n;
	for (int i = 1; i <= n; ++i) cin >> a[i];
	cal(1, n, 1);
	cout << dp[1][n];
}


Measured memory_bytes: 78464
using System;

class Program
{
	static void Main()
	{
		var output = new System.Text.StringBuilder();
		for (string input; (input = Console.ReadLine()) != "0 0";)
		{
			var i = input.Split();
			if (int.Parse(i[0]) > int.Parse(i[1]))
				output.AppendLine(i[1] + " " + i[0]);
			else
				output.AppendLine(i[0] + " " + i[1]);
		}
		Console.Write(output.ToString());
	}
}

Measured memory_bytes: 9056
#include<iostream>
#include<string>

using namespace std;

int main(){

  int n;
  char c;
  string s="";

  cin>>n;
  for(int i=0;i<n;i++){
    cin>>c;
    s+=c;
  }

  for(int i=0;;i++){
    string x=to_string(i);
    if(s.find(x)==string::npos){
      cout<<i<<endl;
      return 0;
    }
  }
  
  return 0;
}



Measured memory_bytes: 3296
// D - Not Divisible
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int)(n);++i)

int main(){
	int N; cin>>N;
	vi A(N);
	int mx = 0;
	rep(i, N){
		cin>>A[i];
		mx = max(mx, A[i]);
	}

	vi c(mx+1, 0);
	vi l(mx+1, 0);
	for(int a:A){
		c[a]++;
		for(int i=a*2; i<=mx; i+=a) l[i] = 1;
	}

	int ans = 0;
	for(int a:A) if(!l[a] && c[a] <= 1) ans++;
	cout<< ans <<endl;
}


Measured memory_bytes: 11976
n,a=[int(_) for _ in input().split()]
x=[int(_) for _ in input().split()]
dp=[[[0 for k in range(2551)] for j in range(51)] for i in range(n)]
dp[0][1][x[0]]=1;dp[0][0][0]=1
for i in range(n-1):
    for j in range(50):
        for k in range(2501):
            dp[i+1][j+1][k+x[i+1]] += dp[i][j][k]
            dp[i+1][j][k] += dp[i][j][k]
ans=0
for j in range(1,n+1):ans += dp[-1][j][j*a]
print(ans)

Measured memory_bytes: 94556
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long a,b,c,x,i,j,k,count=0;
	cin>>a>>b>>c>>x;
	for(i=0;i<=a;i++)
	{
		for(j=0;j<=b;j++)
		{
			for(k=0;k<=c;k++)
			{
				if((500*i+100*j+50*k)==x)
				count++;
			}
		}
	}
	cout<<count<<endl;
	return 0;
}

Measured memory_bytes: 256
//#pragma GCC optimize ("-O3","unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<'\n';
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
//#define int unsigned long long
#define all(x) (x).begin(), (x).end()
//#define double long double

using namespace std;

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;
}

const int MOD = 1e9 + 7;
const ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;
const int MAX = 200020;

int N, M;
vector<P>u, v;
int ans[100];
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> N >> M;
	//u.resize(N); v.resize(M);

	REP(i, N) {
		int a, b; cin >> a >> b;
		u.push_back({ a,b });
	}
	REP(i, M) {
		int c, d; cin >> c >> d;
		v.push_back({ c,d });
	}
	REP(i, N) {
		int idx = 0;
		int mn = INF;
		REP(j, M) {
			int res = abs(u[i].first - v[j].first) + abs(u[i].second - v[j].second);
			if (res < mn) {
				mn = res;
				idx = j;
			}
		}
		ans[i] = idx + 1;
	}
	REP(i, N) {
		print(ans[i]);
	}
}


Measured memory_bytes: 256
using static System.Math;using static System.Console;using System.Collections.Generic;using System.Linq;using System;using System.Collections;
using System.Runtime.Serialization;
using System.Collections.Specialized;
using System.Security.Cryptography;
using System.Globalization;

class Program
{
    #region Reader
    static string ReadStr => Console.ReadLine();
    static string[] ReadStrs => Console.ReadLine().Split(' ');
    static int ReadInt => Convert.ToInt32(Console.ReadLine());
    static int[] ReadInts => Console.ReadLine().Split(' ').Select(s => Convert.ToInt32(s)).ToArray();
    static long ReadLong => Convert.ToInt64(Console.ReadLine());
    static long[] ReadLongs => Console.ReadLine().Split(' ').Select(s => Convert.ToInt64(s)).ToArray();
    #endregion
    #region Method
    const int mod = 1000000007;
    public static int Mod(int a,int mod) { return a % mod >= 0 ? a % mod : a % mod + mod; }
    public static long Mod(long a, int mod = mod) { return a % mod >= 0 ? a % mod : a % mod + mod; }
    #endregion


    #region Mod
    public static long GetInv(long a, long mod = 1000000007)
    {
        return PowerMod(a, mod - 2, mod);
    }
    public static long Combination(long a, long b, long mod = 1000000007)
    {
        if (b < 0 || b > a) return 0;
        if (b > a / 2) b = a - b;
        long numerator = Factorial(a, mod);
        long denominator = (Factorial(b, mod) * Factorial(a - b, mod)) % mod;

        return (numerator * GetInv(denominator, mod)) % mod;
    }
    public static long Factorial(long n, long mod = 1000000007)
    {
        if (n == 0) return 1;
        if (n == 1) return 1;
        long ans = n;
        for (int i = 2; i < n; i++)
        {
            ans = (ans * i) % mod;
        }

        return ans;
    }
    private static long PowerMod(long a, long n, long mod = 1000000007)
    {
        if (n == 0) return 1;
        if (n == 1) return a;

        long p = PowerMod(a, n / 2, mod);
        if (n % 2 == 1) return ((p * p) % mod * a) % mod;
        else return (p * p) % mod;
    }
    #endregion


    static void Main()
    {
        long[] ABK = ReadLongs;
        long A = ABK[0];
        long B = ABK[1];
        long K = ABK[2];

        if (A >= K)
        {
            WriteLine((A - K) + " " + B);
        }
        else
        {
            WriteLine(0 + " " + Max(0, (B - (K - A))));
        }

    }

}


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

int main(){

  int s=0;

  cin>>s;
  
  int ans=0;
  
  ans+=(s%10);
  ans+=(s%100)/10;
  ans+=(s/100);
  
  cout<<ans;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
a.sort()
num = 1
now = a[0]
ans = [0,0]
for i in a[1:]:
  if i == now:
    num += 1
  else:
    if num >= 4:
      ans.append(now)
      ans.append(now)
    elif num >= 2:
      ans.append(now)
    now = i
    num = 1
if num >= 4:
  ans.append(now)
  ans.append(now)
elif num >= 2:
  ans.append(now)
print(ans[-1]*ans[-2])

Measured memory_bytes: 14252
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder.ABC099.A
{
    class Program
    {
        static void Main ()
        {
            var sc = new Scanner ();
            var n = sc.Nextint ();
            Console.WriteLine (n <= 999 ? "ABC" : "ABD");
        }
    }
    class Scanner
    {
        string[] s;
        long i;

        char[] cs = new char[] { ' ' };

        public Scanner ()
        {
            s = new string[0];
            i = 0;
        }

        public string Next ()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine ();
            while (st == "") st = Console.ReadLine ();
            s = st.Split (cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return Next ();
            i = 0;
            return s[i++];
        }

        public int Nextint ()
        {
            return int.Parse (Next ());
        }
        public int[] Arrayint (int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = Nextint () + add;
            }
            return Array;
        }

        public long NextLong ()
        {
            return long.Parse (Next ());
        }

        public long[] ArrayLong (int N, long add = 0)
        {
            long[] Array = new long[N];
            for (long i = 0; i < N; i++)
            {
                Array[i] = NextLong () + add;
            }
            return Array;
        }

        public double NextDouble ()
        {
            return double.Parse (Next ());
        }

        public double[] ArrayDouble (long N, double add = 0)
        {
            double[] Array = new double[N];
            for (long i = 0; i < N; i++)
            {
                Array[i] = NextDouble () + add;
            }
            return Array;
        }

        public decimal NextDecimal ()
        {
            return decimal.Parse (Next ());
        }

        public decimal[] ArrayDecimal (long N, decimal add = 0)
        {
            decimal[] Array = new decimal[N];
            for (long i = 0; i < N; i++)
            {
                Array[i] = NextDecimal ();
            }
            return Array;
        }
    }
}

Measured memory_bytes: 13140
#include<iostream>

using namespace std;

int main(){
  
  int r,g,b;
  int rgb;
  
  cin >> r >> g >> b;

  rgb = r*100 + g*10 + b;

  if(rgb%4 == 0){
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;    
  }
  
  return 0;
}



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

int main() {
    int N; 
    long long K; cin >> N >> K;
    vector<pair<int, int>> num(N);
    for (int i = 0; i < N; i++) {
        int x, y; cin >> x >> y;
        num.at(i) = make_pair(x, y);
    }
    sort(num.begin(), num.end());
    for (int j = 0; j < N; j++) {
        K -= num.at(j).second;
        if (K <= 0) {
            cout << num.at(j).first << endl;
            break;
        }
    }
}

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

using namespace std;

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

	vector<int> height;

	for(int i = 0 ; i < stairs; i++)
	{
		int val;
		cin>>val;
		height.push_back(val);
	}

	height[0]--;
	int i;
	for( i = 1 ; i < stairs ; i++)
	{
		if(height[i] < height[i-1])
		{
			cout<<"No";break;
		}
		if(height[i] > height[i-1])
		{
			height[i]--;
		}
	}

	if(i == stairs)
	cout<<"Yes";
	
	return 0;
}

Measured memory_bytes: 892
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

class Data
{
public:
    int w, s;
    string name;
    bool operator<(const Data& d) const{
        return s < d.s;
    }
};

int n;
vector<Data> d;
vector<bool> used;
vector<int> bestIndex;
int bestG;

void solve(int k, vector<int>& index, int g, int sumW)
{
    if(k == n){
        if(g < bestG){
            bestG = g;
            bestIndex = index;
        }
        return;
    }

    for(int i=0; i<n; ++i){
        if(used[i])
            continue;
        if(d[i].s >= sumW){
            used[i] = true;
            index[k] = i;
            solve(k+1, index, g+(n-k)*d[i].w, sumW+d[i].w);
            used[i] = false;
        }else{
            return;
        }
    }
}

int main()
{
    for(;;){
        cin >> n;
        if(n == 0)
            return 0;

        d.resize(n);
        for(int i=0; i<n; ++i)
            cin >> d[i].name >> d[i].w >> d[i].s;
        sort(d.begin(), d.end());

        bestG = INT_MAX;
        used.assign(n, false);
        vector<int> index(n);
        solve(0, index, 0, 0);
        for(int i=n-1; i>=0; --i)
            cout << d[bestIndex[i]].name << endl;
    }
}

Measured memory_bytes: 924
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <deque>
#include <string>
#include <stack>
#include <unordered_set>
#include <cmath>
#define endl '\n'
#define ll unsigned long long
//#define mod 1000000007

using namespace std;

int main(void)
{
	cin.tie(NULL); ios_base::sync_with_stdio(false);
	ll N, M;
	ll mod = 1000000007;
	cin >> N >> M;
	if (N < M) swap(N, M);
	// N >= M
	if (N - M > 1)
	{
		cout << 0;
		return 0;
	}
	ll ret = 1;
	for (int i = 2; i <= M; i++)
	{
		ret *= i;
		ret %= mod;
		ret *= i;
		ret %= mod;
	}

	if (N == M + 1)
		ret *= N;
	else
		ret *= 2;
	cout << ret % mod;
	return 0;
}

Measured memory_bytes: 256
n=gets.to_i
p=gets.split.map(&:to_i)
q=gets.split.map(&:to_i)
l = (1..n).to_a
a=0
b=0
i=0
l.permutation(n) do |s|
  if s==p
    a=i
  end
  if s==q
    b=i
  end
  i+=1
end
puts (a-b).abs


Measured memory_bytes: 2172
#![allow(unused_imports)]
#![allow(dead_code)]

use proconio::input;
use proconio::marker::{Bytes, Chars};
use std::collections::*;

fn main() {
    input! {
        s:Chars,
        t:Chars,
    }
    let ans = s.iter().enumerate().filter(|&(i, &c)| c != t[i]).count();
    println!("{}", ans);
}

Measured memory_bytes: 3992
#include<stdio.h>
int main()
{
 int n;               
 float ans;                
 int r2;
 int i;                    
 float temp;
 scanf("%d",&n);
 scanf("%f",&ans);
 for(i=1;i<n;i++)
 {
     scanf("%d",&r2);
     temp=(1/ans)+((1/(float)r2));       
     ans=(1/temp);
 }
 printf("%f",ans);
 return 0;
}

Measured memory_bytes: 128
#include <stdlib.h>
#include <stdio.h>
#include <time.h>

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

int main() {
	srand(time(0));
	int a, b;
	int k = rand() % 2;
	scanf("%d %d", &a, &b);
	if (k) printf("%d\n", gcd(a, b));
	else printf("0");
	return 0;
}

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

int main() {
	int sx,sy,tx,ty;
	int x,y,xy,memo;
	cin >> sx >> sy >> tx >> ty;

	if(tx-sx<0) {
		x=-(tx-sx);
	} else {
		x=(tx-sx);
	}
	if(ty-sy<0) {
		y=-(ty-sy);
	} else {
		y=(ty-sy);
	}
	xy=x+y;
	memo=(xy*2+1)*2+(xy*2);

	for(int i=x;i>0;--i) {
		cout << "R";
	}
	for(int j=y;j>0;--j) {
		cout << "U";
	}
	for(int k=x;k>0;--k) {
		cout << "L";
	}
	for(int l=y;l>0;--l) {
		cout << "D";
	}

	cout << "D";
	cout << "R";
	for(int i=x;i>0;--i) {
		cout << "R";
	}
	for(int j=y;j>0;--j) {
		cout << "U";
	}
	cout << "U";
	cout << "L";

	cout << "U";
	cout << "L";
	for(int k=x;k>0;--k) {
		cout << "L";
	}
	for(int l=y;l>0;--l) {
		cout << "D";
	}
	cout << "D";
	cout << "R";


	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a, b;
	int d,r;
	double f;

	scanf("%d %d",&a, &b);

	d = a / b;
	r = a%b;
	f = (double)a / (double)b;

	printf("%d %d %f\n", d, r, f);


	return 0;
}

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

void solve() {
    int A, B, C; cin >> A >> B >> C;
    int residual = A - B;
    int ans = C - residual;

    if(ans < 0){
        cout << 0 << "\n";
    }else{
        cout << ans << "\n";
    }

}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	long long a, b, c, k;
	cin>>a>>b>>c>>k;
	long long A=min(a, k);
	long long B=min(b, k-A);
	long long C=min(c, k-A-B);
	cout<<A-C;
}

Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <sstream>
#include <iomanip>
 
#define INPUT_FROM_FILE (0)
#if INPUT_FROM_FILE
#include <fstream>
#endif

void str_to_vec(std::string str, std::vector<char> &v){
	v.clear();
	for(int i = str.size() - 1; i >= 0; i--){
		v.push_back(str[i] - 48);
	}
	return;
}

std::vector<char> sum(std::vector<char> &v0, std::vector<char> &v1){
	std::vector<char> ret;
	char carry = 0;

	if(v0.size() < v1.size()){
		std::swap(v0, v1);
	}
	for(unsigned int i = 0; i < v1.size() - v0.size(); i++){
		v1.push_back(0);
	}

	ret.resize(v1.size(), 0);

	for(unsigned int i = 0; i < ret.size(); i++){
		char tmp = v0[i] + v1[i] + carry;
		if(tmp >= 10){
			carry = 1;
			tmp -= 10;
		}
		else{
			carry = 0;
		}
		ret[i] = tmp;
	}
	if(carry == 1){
		ret.push_back(1);
	}

	return ret;
}

int main(int argc, char **argv){
	int n = 0;
	std::string buf;

#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
#endif



#if INPUT_FROM_FILE
	std::getline(ifs, buf);
#else
	std::getline(std::cin, buf);
#endif
	n = std::stoi(buf);

	for(int i = 0; i < n; i++){
		std::vector<char> num0;
		std::vector<char> num1;
#if INPUT_FROM_FILE
		std::getline(ifs, buf);
#else
		std::getline(std::cin, buf);
#endif
		str_to_vec(buf, num0);
#if INPUT_FROM_FILE
		std::getline(ifs, buf);
#else
		std::getline(std::cin, buf);
#endif
		str_to_vec(buf, num1);

		if(num0.size() > 80 || num1.size() > 80){
			std::cout << "overflow" << std::endl;
		}
		else{
			std::vector<char> s = sum(num0, num1);

			if(s.size() > 80){
				std::cout << "overflow" << std::endl;
			}
			else{
				for(int i = s.size() - 1; i >= 0; i--){
					std::cout << (int)s[i];
				}
				std::cout << std::endl;
			}
		}
	}
	return 0;
}


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

int main(){
  int n;
  cin >> n;
  int multiple_2=0,multiple_4=0,other=0;

  for(int i=0;i<n;i++){
    int x;
    cin >> x;
    if(x%4 == 0) multiple_4++;
    else if(x%2 == 0) multiple_2++;
    else other++;
  }
  if(multiple_2 != 0){
    if(other <= multiple_4) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  else{
    if(other-1 <= multiple_4) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import sys
import itertools

def sieve(n):
    is_prime = [True] * (n + 1)
    prime_list = []
    
    is_prime[0] = is_prime[1] = False
    prime_list.append(2)
    
    for i in range(3, n + 1, 2):
        if is_prime[i]: prime_list.append(i)
        for j in range(i * i, n + 1, i):
            is_prime[j] = False
    return prime_list
    
primes = sieve(40000)

def factoriaztion(n):
    ret = []
    for prime in primes:
        while n % prime == 0:
            ret.append(prime)
            n /= prime
        if n == 1: break
    if n > 1: ret.append(n)
    return ret
    
    
if __name__ == '__main__':
    n = sys.stdin.readline()
    n = int(n)
    factors = factoriaztion(n)
    factors = itertools.groupby(factors)
    
    ans = 1
    
    for k, v in factors:
        l = len(list(v))
        ans = ans * (k ** l - k ** (l - 1))
    
    sys.stdout.write(str(ans) + '\n')
    
        

Measured memory_bytes: 5572
import java.util.Scanner;

public class Main {
public static void main(String args[])
{
	Scanner scan=new Scanner(System.in);
	int n=scan.nextInt();
	int m=scan.nextInt();
	int ar[]=new int[m];
	int dp[]=new int[n+1];
	for(int i=0;i<m;i++)
	{
		dp[scan.nextInt()]=-1;
	}
	dp[0]=(dp[0]==0)?1:-1;
	dp[1]=(dp[1]==0)?1:-1;
	for(int i=2;i<=n;i++)
	{
		if(dp[i]==-1)continue;
		int x=(dp[i-1]==-1)?0:dp[i-1];
		int y=(dp[i-2]==-1)?0:dp[i-2];
		dp[i]=(x+y)%1000000007;
	}
	System.out.println(dp[n]);
}
}


Measured memory_bytes: 55556
#include<stdio.h>

long long int lcd(long long int a, long long int b)
{
  long long int temp;

  if (a < b) {
    temp = a;
    a = b;
    b = temp;
  }
  
  if (a % b == 0) {
    return b;
  } else {
    return lcd(b, a % b);
  }
}

long long int lcm(long long int a, long long int b)
{
  return a / lcd(a, b) * b;
}

int main()
{
  long long int a,b,c,d;
  long long int divable = 0;

  scanf("%lld %lld %lld %lld", &a, &b, &c, &d);

  divable = (b / c - (a - 1) / c) -
    (b / lcm(c, d) - (a - 1) / lcm(c, d)) + (b / d - (a - 1) / d) ;

  printf("%lld\n", b - a + 1 - divable);
  
  return 0;
}


Measured memory_bytes: 128
def answer(aaa,max):
    half = max / 2
    bbb = []
    for i in range(len(aaa)):
        bbb.append(abs(half - aaa[i]))
    return aaa[bbb.index(min(bbb))]


n = int(input())
a = list(map(int,input().split(" ")))
b = max(a)
a.remove(b)
print(b,answer(a,b))


Measured memory_bytes: 14060
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<string> S(N);
  for(int i = 0; i < N; i++){
    cin >> S[i];
  }
  sort(S.begin(), S.end()); 
  int count = 0;
  for(int i = 0; i < N; i++){
    if(S[i] == S[i+1]){
      count ++;
      if (i == N-1){
        break;
      }
    }
  }
  cout << N - count << endl;
}

Measured memory_bytes: 9604
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import itertools

def main():
    N = int(input())
    F_all = [[int(i) for i in input().split()] for _ in range(N)]
    P_all = [[int(i) for i in input().split()] for _ in range(N)]
    ans = float('-inf')
    for i in range(1, 11):
        # combinationsは第一引数の中から第二引数の文字数を使った組み合わせを返す．
        for iOPs in itertools.combinations(range(10), i):
            gain = 0
            for f, p in zip(F_all, P_all):
                c = sum(f[k] for k in iOPs)
                gain += p[c]
            ans = max(ans, gain)
    return ans


if __name__ == '__main__':
    print(main())

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define inf (int)1e9+7
#define eb emplace_back

int a[2010][2010];
int b[2010][2010];
int h, w;
void out(char ch) {
    cout << endl;
    for (int i = 0; i <= h; ++i) {
        for (int j = 0; j <= w; ++j) {
            if (ch == 'a') cout << a[i][j] << " ";
            else cout << b[i][j] << " ";
        }
        cout << endl;
    }
}

int main() {
    //clock_t start = clock();
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> h >> w;
    char c[h][w];
    rep(i, h) rep(j, w) cin >> c[i][j];
    rrep(i, 1, h + 1) rrep(j, 1, w + 1) {
        if (c[i - 1][j - 1] == '#') continue;
        a[i][j] = a[i][j - 1] + 1;
    }
    int tmp;
    rrep(i, 1, h + 1) {
        for (int j = w; j >= 1; j--) {
            tmp = a[i][j];
            if (a[i][j] == 0) continue;
            for (int k = j - 1; k >= 1; k--) { //0まで流す
                if (a[i][k]) {a[i][k] = tmp; if (k == 1) {j = k;} continue;}
                j = k; //next j--
                break;
            }
        }
    }
    //out('a');
    rrep(i, 1, h + 1) rrep(j, 1, w + 1) {
        if (c[i - 1][j - 1] == '#') continue;
        b[i][j] = b[i - 1][j] + 1;
    }
    //out('b');
    rrep(j, 1, w + 1) {
        for (int i = h; i >= 1; i--) {
            tmp = b[i][j];
            //cout << tmp << endl;
            if (tmp == 0) continue;
            for (int k = i - 1; k >= 1; k--) {
                if (b[k][j]) {b[k][j] = tmp; if (k == 1) {i = k;} continue;}
                i = k;
                break;
            }
        }
    }
    //out('b');
    int ans = -1;
    rrep(i, 1, h + 1) rrep(j, 1, w + 1) {
        if (c[i - 1][j - 1] == '#') continue;
        chmax(ans, a[i][j] + b[i][j] - 1);
    }
    cout << ans << endl;
    //clock_t end = clock();
    //cout << (double)(end - start) / CLOCKS_PER_SEC << endl;
    return 0;
}




Measured memory_bytes: 35712
#include<iostream>
#include<vector>
#include<utility>
#include<queue>
using namespace std;
enum COLOR {BLACK, WHITE};
int main(){
    int V, E;
    cin >> V >> E;
    vector<vector<pair<int, int> > > G(V);
    for (int i = 0; i < E; i++) {
        int s, t, w;
        cin >> s >> t >> w;
        G[s].push_back(make_pair(t, w));
        G[t].push_back(make_pair(s, w));
    }
    vector<COLOR> color(V, WHITE);
    priority_queue<pair<int, int> > Q;
    color[0] = BLACK;
    int u = 0;
    int sum = 0;
    while(1) {
        for (int i = 0; i < G[u].size(); i++) {
            int v = G[u][i].first;
            if (color[v] == BLACK) continue;
            int w = G[u][i].second;
            Q.push(make_pair(w * (-1), v));
        }
        while (!Q.empty() && color[Q.top().second] == BLACK) Q.pop();
        if (Q.empty()) break;
        u = Q.top().second;
        color[u] = BLACK;
        sum += Q.top().first * (-1);
        Q.pop();
    }
    cout << sum << endl;
    return 0;
}



Measured memory_bytes: 6820
//#include <ext/pb_ds/assoc_container.hpp>
#include <bits/stdc++.h>
using namespace std;

  #define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); 

  #define ff first
  #define ss second
  #define pb push_back
  #define pf push_front
  #define mp make_pair
  #define in insert
  #define ld long double


  #define TRACE
  #ifdef TRACE
  #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
  template <typename Arg1>
  void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
  }
  template <typename Arg1, typename... Args>
  void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
  }
  #else
  #define trace(...) 1
  #endif
  template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
  template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}

  typedef long long int ll;

  typedef vector<int> vi;
  typedef vector<ll> vl;
  typedef vector<vi> vvi;
  typedef vector<vl> vvl;
  typedef pair<int,int> pii;
  typedef pair<ll,ll> pll;
  typedef vector<pii> vpii;
  typedef vector<pll> vpll;
  const ll mod =1e9+7;
  const ll MAX_NODES =200001;
  const ll MAX_LOG =50;
  const ll maxn = 200000+10;
  #define endl '\n'
  ll power(ll x, ll n) {
      ll res = 1;
      for (; n > 0; n >>= 1) {
      if (n & 1) res = (res * x) % mod;
      x = (x * x) % mod;
      }
      return res;
  }


  int main()
  {

  IOS
  ll n,k;
  cin>>n>>k;
  ll c=0;
  while(n>=k)
  {
    n/=k;
    c++;
  }
  cout<<c+1<<endl;

  

  
  

}


Measured memory_bytes: 256