akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

int p[100001],r[100001];
void init(){rep(i,100001)p[i]=i,r[i]=0;}
int find(int x){return (p[x]==x)?x:(p[x]=find(p[x]));}
void unite(int x,int y) {
  x=find(x),y=find(y);
  if(x==y)return;
  if(r[x]<r[y])p[x]=y;
  else{p[y]=x;if(r[x]==r[y])r[x]++;}
}
bool same(int x,int y){return find(x)==find(y);}

void Main() {
  int n,m;
  cin >> n >> m;
  int a[n];
  rep(i,n) R a[i];
  P b[m];
  rep(i,m) cin >> b[i].F >> b[i].S;
  init();
  rep(i,m) unite(b[i].F-1,b[i].S-1);
  set<int> s[n];
  rep(i,n) s[find(i)].in(i);
  int ans=0;
  rep(i,n) {
    if(s[find(i)].count(a[i]-1)) ans++;
  }
  pr(ans);
}

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


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

typedef long long ll;
const int N = 4054, mod = 924844033;

int n, K, L = 0;
int sp[N], fact[N];
int f[N][N], g[N][N];

inline void add(int &x, const int y) {x += y - mod, x += x >> 31 & mod;}

int main() {
	int i, j, c; ll ans = 0;
	scanf("%d%d", &n, &K);
	for (*fact = i = 1; i <= n; ++i) fact[i] = (ll)fact[i - 1] * i % mod;
	for (i = 0; i < K; ++i)
		sp[++L] = 1, L += (n - i - 1) / K,
		sp[++L] = 1, L += (n - i - 1) / K;
	assert(L == 2 * n);
	for (**f = i = 1; i <= L; ++i)
		for (*f[i] = j = 1; j <= (i + 1) / 2; ++j)
			add(f[i][j] = f[i - 1][j], g[i - 1][j]),
			g[i][j] = (sp[i] ? 0 : f[i - 1][j - 1]);
	for (i = 0; i <= n; ++i)
		c = ll(f[L][i] + g[L][i]) * fact[n - i] % mod,
		i & 1 ? ans -= c : ans += c;
	ans %= mod, printf("%d\n", int(ans + (ans >> 63 & mod)));
	return 0;
}

Measured memory_bytes: 126208
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
#define REP(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for(ll (i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for(ll (i) = (m); (i) < (n); (i)++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
#define _GLIBCXX_DEBUG

template <uint MD> struct ModInt {
    using M = ModInt;
    const static M G;
    uint v;
    ModInt(ll _v = 0) { set_v(uint(_v % MD + MD)); }
    M& set_v(uint _v) {
        v = (_v < MD) ? _v : _v - MD;
        return *this;
    }
    explicit operator bool() const { return v != 0; }
    M operator-() const { return M() - *this; }
    M operator+(const M& r) const { return M().set_v(v + r.v); }
    M operator-(const M& r) const { return M().set_v(v + MD - r.v); }
    M operator*(const M& r) const { return M().set_v(uint(ull(v) * r.v % MD)); }
    M operator/(const M& r) const { return *this * r.inv(); }
    M& operator+=(const M& r) { return *this = *this + r; }
    M& operator-=(const M& r) { return *this = *this - r; }
    M& operator*=(const M& r) { return *this = *this * r; }
    M& operator/=(const M& r) { return *this = *this / r; }
    bool operator==(const M& r) const { return v == r.v; }
    M pow(ll n) const {
        M x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    M inv() const { return pow(MD - 2); }
    friend ostream& operator<<(ostream& os, const M& r) { return os << r.v; }
};
using Mint = ModInt<1000000007>;

const double PI = 3.14159265358979323846;

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

int main()
{	
    ll n;
    cin >> n;
    vector<string> v(n);
    REP(i, n) cin >> v[i];

    ll cnt_AC = 0;
    ll cnt_WA = 0;
    ll cnt_TLE = 0;
    ll cnt_RE = 0;

    REP(i, n){
        if(v[i] =="AC") cnt_AC++;
        if(v[i] =="WA") cnt_WA++;
        if(v[i] =="TLE") cnt_TLE++;
        if(v[i] =="RE") cnt_RE++;
    }

    cout << "AC x " << cnt_AC << endl;
    cout << "WA x " << cnt_WA << endl;
    cout << "TLE x " << cnt_TLE << endl;
    cout << "RE x " << cnt_RE << endl;
}


Measured memory_bytes: 6420
import java.util.Scanner;

/**
 * TITLE : Rally URL
 * https://atcoder.jp/contests/abc156/tasks/abc156_c
 */
public class Main {

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] X = new int[N];
        int min = 100;
        int max = 0;
        int sum = 0;
        for (int i = 0; i < N; i++) {
            X[i] = sc.nextInt();
            sum += X[i];
            min = min > X[i] ? X[i] : min;
            max = max < X[i] ? X[i] : max;
        }

        long P = Math.round((double) sum / X.length);
        int answer = 0;
        for (int i = 0; i < X.length; i++) {
            answer += (X[i] - P) * (X[i] - P);
        }
        System.out.println(answer);
        sc.close();
    }
}

Measured memory_bytes: 21844
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    int i,ac=0,wa=0,tle=0,re=0,n;
    cin>>n;
    char st[20];
    for(i=1;i<=n;i++)
    {
        cin>>st;
        if(st[0]=='A')
            ac++;
        else if(st[0]=='W')
            wa++;
        else if(st[0]=='T')
           tle++;
        else if(st[0]=='R')
            re++;
    }
    cout<<"AC x "<<ac<<endl;
    cout<<"WA x "<<wa<<endl;
    cout<<"TLE x "<<tle<<endl;
    cout<<"RE x "<<re<<endl;
    return 0;
}


Measured memory_bytes: 3600
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <climits>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <set>
#include <complex>
#include <functional>
#include <utility>
#include <iterator>

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (m); i < (int)(n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define INF 2000000000

#ifdef LOCAL
  #define dprintf(...) fprintf(stdout, __VA_ARGS__)
#else
  #define dprintf(...) 0
#endif

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int uint;

//const double PI = 3.1415926535897932384626433832795;

int main() {
  ULL n;
  cin >> n;
  ULL tmp = n;

  map<ULL, ULL> primes;
  for(ULL i = 2; i * i <= n; i++) {
    while(tmp % i == 0) {
      tmp /= i;
      primes[i] += 1;
    }
  }
  if(tmp != 1) {
    primes[tmp] = 1;
  }

  int ans = 0;
  for(auto itr = primes.begin(); itr != primes.end(); itr++) {
    int p = itr->second;
    //printf("%d: %d\n", itr->first, itr->second);
    for(int i = 1; i <= p; i++) {
      if(p >= i) {
        p -= i;
        ans++;
      }
    }
  }

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


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

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

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep2(i, begin_i, end_i) for (int i = (int)begin_i; i < (int)end_i; i++)

long long INF = 1LL<<60;
long long dp[100010];
int h[100010];
int n;
ll fact(int x){
    ll ret=1;
    while(x){
        ret*=x;
        x--;
    }
    return ret;
}
ll choose(int n,int r){
    ll ret=0;
    ret = fact(n)/(fact(n-r)*fact(r));
    return ret;
}
int main(){
    int n;
    cin>>n;
    string s[n+5];
    rep(i,n){cin>>s[i];sort(s[i].begin(),s[i].end());}
    unordered_map<string,ll> count;
    for(int i=0;i<n;i++){
            count[s[i]]++;
    }
    ll ans=0;
    for(auto iter=count.begin();iter!=count.end();iter++){
        pair<string,ll> elem=*iter;
        ans+= elem.second*(elem.second-1)/2;
    }
    cout<<ans<<endl;
    return 0;
}




Measured memory_bytes: 17700
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define N 1000100
inline int read(){
    int x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9'){
        if(c=='-')f=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9'){
        x=(x<<3)+(x<<1)+c-'0';
        c=getchar();
    }
    return x*f;
}
int n,a[N],b[N],c[N],tmp[N];
char s[N];
inline int C(int n,int m){
	if(n==m||!m)return 1;
	if(n<m)return 0;
	return C(n&1,m&1)*C(n>>1,m>>1);
}
int Solve(int *p){
	int ans=0;
	for(int i=1;i<=n;++i){
		if(tmp[i]){
			ans^=p[i];
		}
	}
	return ans;
}
int main(){
	n=read();
	scanf("%s",s+1);
	bool ok=0;
	for(int i=1;i<=n;++i){
		a[i]=s[i]-'0'-1;
		if(a[i]==1)ok=1;
		b[i]=(a[i]&1);
		c[i]=(a[i]>>1);
	}
	for(int i=0;i<n;++i){
		tmp[i+1]=C(n-1,i);
	}
	if(!ok){
		printf("%d\n",Solve(c)<<1);
	}
	else{
		printf("%d\n",Solve(b));
	}
	return 0;
}


Measured memory_bytes: 16896
import os, sys, math
if os.environ.get("DEBUG") is not None:
    sys.stdin = open("in.txt", "r")
rl = sys.stdin.readline

n = int(rl())
a = list(map(int, rl().split()))

ans = math.inf
for it in a:
    cnt = 0
    while it > 0 and it % 2 == 0:
        it /= 2
        cnt += 1
    ans = min(ans, cnt)
print(ans)


Measured memory_bytes: 9256
#include <iostream>
#include <algorithm>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define DEBUG(x) cerr << #x << " = " << x << endl
int A[100];
int main() {
  while(true) {
    int N; cin >> N;
    if(N == 0) break;
    REP(i,N) cin >> A[i];
    int t; cin >> t;
    int lb = 0, ub = N - 1;
    int c = 0;
    while(ub >= lb) {
      int mid = (lb + ub) / 2;
      //DEBUG(lb);
      //DEBUG(ub);
      //DEBUG(mid);
      ++c;
      if(A[mid] == t) {
        break;
      }
      if(t < A[mid]) {
        ub = mid - 1;
      }
      else {
        lb = mid + 1;
      }
    }
    cout << c << endl;
  }
}

Measured memory_bytes: 1160
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
//CONST
//------------------------------------------
#define INF 1010000000000000017LL
#define MOD 1000000007LL
#define EPS 1e-12
#define PI 3.14159265358979323846
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
//-----------------------------------------
#define dcml(n) fixed<<setprecision(n)
using namespace std;
int main(void){
    ll N,M;cin>>N>>M;
    ll cnt=0;
    if(N%2==1){
        if((N/2)%2==0){
            ll l=0,r=(N/2-1);
            REP(i,N/2){
                cout<<l+1<<" "<<r+1<<"\n";cnt++;if(cnt==M)exit(0);
                if(l+1==r)break;
                l++;r--;
            }
            l=N/2,r=N-1;
            REP(i,N/2){
                cout<<l+1<<" "<<r+1<<"\n";cnt++;if(cnt==M)exit(0);
                if(l+2==r)break;
                l++;r--;
            }
        }else{
            ll l=0,r=(N/2);
            REP(i,N/2){
                cout<<l+1<<" "<<r+1<<"\n";cnt++;if(cnt==M)exit(0);
                if(l+1==r)break;
                l++;r--;
            }
            l=N/2+1,r=N-1;
            REP(i,N/2-1){
                cout<<l+1<<" "<<r+1<<"\n";cnt++;if(cnt==M)exit(0);
                if(l+2==r)break;
                l++;r--;
            }
        }
    }else{
        ll n=(N-1)/2;
        if((N/2)%2==0){
            ll l=0,r=(N/2-1);
            REP(i,n/2+1){
                cout<<l+1<<" "<<r+1<<"\n";cnt++;if(cnt==M)exit(0);
                if(l+1==r)break;
                l++;r--;
            }
            l=N/2,r=N-1-1;
            REP(i,n/2){
                cout<<l+1<<" "<<r+1<<"\n";cnt++;if(cnt==M)exit(0);
                if(l+2==r)break;
                l++;r--;
            }
        }else{
            ll l=0,r=(N/2-1);
            REP(i,n/2){
                cout<<l+1<<" "<<r+1<<"\n";cnt++;if(cnt==M)exit(0);
                if(l+1==r)break;
                l++;r--;
            }
            l=N/2,r=N-1-1;
            REP(i,n/2){
                cout<<l+1<<" "<<r+1<<"\n";cnt++;if(cnt==M)exit(0);
                if(l+2==r)break;
                l++;r--;
            }
        }
    }
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
using namespace std;
template <typename T> ostream & operator << (ostream & out, const vector<T> & xs) { REP (i, xs.size()) { if (i) { out << ' '; } out << xs[i]; } return out; }

vector<int64_t> solve(int n, int k, int64_t s) {
    constexpr int A_MAX = 1000000000;
    vector<int64_t> a;
    REP (i, k) {
        a.push_back(s);
    }
    REP (i, n - k) {
        a.push_back(s == A_MAX ? 1 : A_MAX);
    }
    return a;
}

int main() {
    int n, k; int64_t s; cin >> n >> k >> s;
    cout << solve(n, k, s) << endl;
    return 0;
}


Measured memory_bytes: 2292
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


struct Info{
	Info(int arg_a,int arg_b,bool arg_is_reverse){
		a = arg_a;
		b = arg_b;
		is_reverse = arg_is_reverse;
	}
	bool operator<(const struct Info &arg) const{
		if(a != arg.a){
			return a < arg.a;
		}else{
			return b > arg.b;
		}
	}
	int a,b;
	bool is_reverse;
};

int dp[200001];

int main(){

	int N;
	scanf("%d",&N);

	int a,b;
	vector<Info> V;

	for(int i = 0; i < N; i++){
		scanf("%d %d",&a,&b);
		V.push_back(Info(a,b,false));
		V.push_back(Info(b,a,true));
	}

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

	for(int i = 0; i < 2*N; i++)dp[i] = BIG_NUM;
	int left,right,m,loc;

	for(int i = 0; i < 2*N; i++){
		left = 0,right = i,m = (left+right)/2;
		loc = BIG_NUM;
		while(left <= right){
			if(dp[m] >= V[i].b){
				loc = m;
				right = m-1;
			}else{
				left = m+1;
			}
			m = (left+right)/2;
		}
		if(loc == BIG_NUM)continue;
		if(V[i].is_reverse == true && loc%2 == 0){
			dp[loc] = V[i].b;
		}else if(V[i].is_reverse == false && loc%2 == 1){
			dp[loc] = V[i].b;
		}
	}

	int ans = 0;
	left = 0,right = 2*N-1,m = (left+right)/2;

	while(left <= right){
		if(dp[m] == BIG_NUM){
			ans = m;
			right = m-1;
		}else{
			left = m+1;
		}
		m = (left+right)/2;
	}

	printf("%d\n",ans);

	return 0;
}



Measured memory_bytes: 6200
// #pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
#define fou(i,a,n) for(int i=a;i<n;i++)
#define fod(i,a,n) for(int i=n-1;i>=a;i--)
#define rep(n) fou(_,0,n)
#define tra(a,x) for(auto& a : x)
#define elif(c) else if(c)

#define emb emplace_back
#define pub push_back
#define pob pop_back
#define me min_element
#define Me max_element
#define mp make_pair
#define fi first
#define se second
#define siz(xs) ((int)(xs).size())
#define all(xs) xs.begin(),xs.end()
#define lla(xs) xs.rbegin(),xs.rend()
#define sortup(xs) sort(all(xs))
#define sortdown(xs) sort(lla(xs))
template<class C>void mini(C &a,C b){a=min(a,b);}
template<class C>void maxi(C &a,C b){a=max(a,b);}
#define in(T,...) T __VA_ARGS__;_cin(__VA_ARGS__)
#define out(...) _cout(__VA_ARGS__)
void _cin(){}template<class Head,class...Tail>void _cin(Head&&head,Tail&&...tail){cin>>head;_cin(forward<Tail>(tail)...);}
void _cout(){}template<class Head,class...Tail>void _cout(Head&&head,Tail&&...tail){cout<<head<<endl;_cout(forward<Tail>(tail)...);}
template<class Type>void _cinvec(Type t,int n){}template<class Type,class Head,class...Tail>void _cinvec(Type t,int n,Head&&head,Tail&&...tail){rep(n){cin>>t;head.eb(t);}_cinvec(t,n,forward<Tail>(tail)...);}

#define VI vector<int>
#define VD vector<double>
#define VS vector<string>
#define VVI vector<VI>
#define VVD vector<VD>
#define VVS vector<VS>

// #define int int64_t
// #define double long double

// map,文字列処理


signed main(){
  in(char,b);
  if(b=='A') out('T');
  elif(b=='T') out('A');
  elif(b=='C') out('G');
  elif(b=='G') out('C');
}

Measured memory_bytes: 256
h, n = map(int, input().split())
a = [0] * n
b = [0] * n
for i in range(n):
    a[i], b[i] = map(int, input().split())

a_max = max(a)
# dp[i] : モンスターのHPをi減らすのに必要な魔力の最小値
dp = [0] * (h + a_max + 1)
dp[0] = 0

for i in range(1, h + a_max + 1):
    m = 10 ** 9
    for j in range(n):
        tmp = dp[i - a[j]] + b[j]
        if (m > tmp):
            m = tmp

    dp[i] = m

print(min(dp[h:]))


Measured memory_bytes: 41580
#include<stdio.h>
#include<math.h>

int main(){
	double a,b,c,d,e,f,x,y;
	while(scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f)!=EOF){
		x=(b*f-c*e)/(b*d-a*e);
		y=-1.0*(x*a-c)/b;
		printf("%.3lf %.3lf\n",x==0.0 ? fabs(x) : x, y==0.0 ? fabs(y) : y);
	}

    return 0;
}

Measured memory_bytes: 652
#include <bits/stdc++.h>
using namespace std;
int m,n;
int main(){
	cin>>m>>n;
	if(n==1)
		cout<<0;
	else if((n-1)%(m-1)==0)
		cout<<(n-1)/(m-1);
	else
	 cout<<(n-1)/(m-1)+1;
	return 0;
}
/*
模拟只会猜题意
贪心只能过样例
数学上来先打表
DP一般看规律
组合数学靠运气
计算几何瞎暴力
图论强行套模板
数论只会GCD
递归递推伤不起
搜索茫然TLE
分治做得像枚举
暴力枚举数第一
数据结构干瞪眼
怒刷水题找信心
涨姿势也不容易
考试一来全懵逼
*/

 

Measured memory_bytes: 256
(n,k),p,c=[[*map(int,t.split())]for t in open(0)]
a=-9e9
for i in range(n):
 s=t=f=m=0;x,*l=i,
 while~f:x=p[x]-1;l+=c[x],;s+=c[x];m+=1;f-=x==i
 for j in range(min(m,k)):t+=l[j];a=max(a,t+(~j+k)//m*s*(s>0))
print(a)

Measured memory_bytes: 117196
def resolve():
	n, k = map(int, input().split())
	p = [0]*n
	for _ in range(k):
		input()
		t = list(map(int, input().split()))
		for i in t:
			p[i-1] += 1
	ans = 0
	for i in p:
		if i == 0:
			ans += 1
	print(ans)
resolve()

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

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i,n) for(auto i=0;i<(n);i++)
#define rep1(i,n) for(auto i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()

using namespace std;


struct init{ init(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20); }; }aaaaaaa;



ll gcd(ll m, ll n){
  if(m == 0) return 0;
  if(n == 0) return 0;
	
	while(m != n){
		if(m > n) m = m - n;
		else    n = n - m;
	}
	return m;
}

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


  ll g = gcd(c, d);
  ll r = g * c/g * d/g;
  ll sum = 0;
  sum += b/c - (a-1)/c;
  sum += b/d - (a-1)/d;
  sum -= b/r - (a-1)/r;


  cout << b-a+1-sum << endl;


  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	public static void main(String args[]) {
	Scanner scan=new Scanner(System.in);
	int N=scan.nextInt();
	int K=scan.nextInt();
	int A[]=new int[N];
	for(int i=0;i<N;i++) {
		A[i]=0;
	}
	for(int i=0;i<K;i++) {
	int d=scan.nextInt();
		for(int j=0;j<d;j++) {
			int m=scan.nextInt();
			A[m-1]=1;
		}
	}
	int num=0;
	for(int i =0;i<N;i++) {
		if(A[i]==0) {
		num++;
		}
		else {}
	}
	System.out.println(num);
	}
}


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

int main(){
    string s; cin >> s;
    string t=s;
    reverse(t.begin(), t.end());
    int n=s.size();
    string a, b, c, d;
    a=s.substr(0, (n-1)/2);
    b=a;
    reverse(b.begin(), b.end());
    c=s.substr((n+1)/2, (n-1)/2);
    d=c;
    reverse(d.begin(), d.end());
    //cout << a << " " << b << " " << c << " " << d << endl;
    if (s==t && a==b && c==d){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PREP(i, s, x) for(ll i = (s); i < (x); i++)
#define MREP(i, s, x) for(ll i = (s); i >= (x); i--)
#define REP(i, x) PREP(i, 0, x)
using namespace std;
using ll = long long;
typedef long long ll;
typedef pair<ll, ll> P;
template<typename T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template<typename T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}

// ////////////////////////////////////////////

constexpr ll INF = (1ll << 60);
constexpr ll MOD = 998244353ll;

// べき乗を計算　指数を計算
ll llpow(ll a, ll n){
    ll res = 1;
    while(n > 0){
        if(n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

ll kumi(ll n, ll m){
    return (m * llpow(m-1, n-1)) % MOD;
}


const ll MAX = 404040;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    COMinit();

    ll n, m, k;
    cin >> n >> m >> k;

    ll ans = 0;
    REP(i, k+1){
        ans += kumi(n-i, m) * COM(n-1, i) % MOD;
        ans %= MOD;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 13072
import java.util.*;
import java.io.*;
public class Main{

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		ArrayList<Integer> vector  = new ArrayList<>();

		int loop = in.nextInt();
		for(int i = 0; i < loop; i++) {
			int odr = Integer.parseInt(in.next());
			switch(odr) {
				case 0:
					vector.add(Integer.parseInt(in.next()));
					break;

				case 1:
					out.println(vector.get(Integer.parseInt(in.next())));
					break;

				case 2:
					vector.remove(vector.size()-1);
					break;
			}
		}
		out.flush();
		in.close();
	}

}



Measured memory_bytes: 105768
import java.util.Scanner;

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

        for (int i = 0; i < q; i++) {
            int answer = std.nextInt() - 1;
            points[answer] += 1;
        }

        for (int i = 0; i < n; i++) {
            int minusPoint = q - points[i];
            if(k - minusPoint > 0) {
                System.out.println("Yes");
            } else {
                System.out.println("No");
            }
        }
    }
}

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

using namespace std;

int main(){
	int n,k;
	cin>>n>>k;
	int dp[n];
	for(int i=0; i<n; i++){
		dp[i]=INT_MAX;
	}
	cout<<endl;
	int h[n];
	for(int i=0; i<n; i++){
		cin>>h[i];
	}
	dp[0]=0;
	dp[1]=abs(h[1]-h[0]);
	for(int i=2; i<n; i++){
		for(int j=1; j<=k; j++){
			if(i>=j){
				//cout<<dp[i]<<" "<<dp[i-j]<<" "<<h[i]<<" "<<h[i-j]<<endl;
				dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
				//cout<<dp[i]<<endl;
			}
		}
	}
	//for(int i=0; i<n; i++)
	//cout<<dp[i]<<" ";
	cout<<dp[n-1];
}

Measured memory_bytes: 4364
//$g++ -std=c++11 Template.cpp 

//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>
#include<string.h>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

priority_queue<int> q_descending;
priority_queue<int, vector<int>, greater<int> > q_ascending;

int
main(void){  
  ios_base::sync_with_stdio(false);
  string s, l="", r="keyence";
  int itr = 0;
  cin >> s;

  while(true){
    l += r[0];
    REP(j, r.size()-1) r[j] = r[j+1];
    r.pop_back();
    //cout << l << " " << r << endl;
    if(s.find(l) == string::npos || s.find(r) == string::npos) {
      itr++;
      if(itr >= 7) {cout << "NO" << endl; return 0;}
    }
    else{
      
      //cout << s.find(l) << " " << s.rfind(r) << endl;
      if((s.find(l) == 0 &&  s.rfind(r) + r.size() == s.size()) || (s.rfind(r) == s.find(l) + l.size() && (s.find(l) == 0 || s.rfind(r) + r.size() == s.size()) ) ){
	cout << "YES" << endl; return 0;
      }
      else{
	itr++;
	if(itr >= 7) {cout << "NO" << endl; return 0;}	
      }
    }
  }

 
  
  return 0;
}


Measured memory_bytes: 256
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao Twitter/QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 10e16
#define MOD 1000000007
#define mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}

//---------------------------------------------------------------------------
long long modpow(long long a, long long n) {//a^n(MOD)を求める
    long long res = 1;
    while (n > 0) {
         if (n & 1) res = res * a % MOD;
         a= a * a % MOD;//次の準備
         n >>= 1;
      }
 return res;
}

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????        memset()!!!!!!!!!!!!       ペナを減らせ!!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    string L;cin>>L;
    ll one=0;
    for(ll i=L.length()-1;i>=0;i--){
        if(L[i]=='1')one++;
    }
    ll c0=0;ll c1=one;    ll ans=0;
    for(ll i=L.length()-1;i>=0;i--){
        if(L[i]=='0'){
            c0++;
        }
        else{
            ans+=modpow(3,c0)*modpow(2,--c1);
            ans%=MOD;
            c0++;
        }
    }
    ans+=modpow(2,one);
    ans%=MOD;
    cout<<ans<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------









Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	static BufferedReader reader;
	//static field here
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		reader = new BufferedReader(new InputStreamReader(System.in));
		//code here
		String[] strings = readLine();
		int N = Integer.parseInt(strings[0]);
		int[] A = new int[N];
		strings = readLine();
		for(int i=0;i<N;i++) {
			A[i]= Integer.parseInt(strings[i]);
		}
		int[] x = new int[N];
		x[0]=A[0];
		for(int i=1;i<N-1;i+=2) {
			x[0]+=(-A[i]+A[i+1]);
		}
		x[0]/=2;
		for(int i=1;i<N;i++) {
			x[i]=A[i-1]-x[i-1];
		}
		StringBuilder sBuilder = new StringBuilder();
		for(int i=0;i<N-1;i++) {
			sBuilder.append(x[i]*2).append(" ");
		}
		sBuilder.append(x[N-1]*2);
		print(sBuilder.toString());
		
		//String[] s = readLine();
		//print(num);
	}
	
	//functions here
	//note that all methods should be STATIC

	private static String[] readLine(){
		try{
			return reader.readLine().split(" ");
		}catch(Exception e){
			e.printStackTrace();
			return new String[]{e.getMessage()};
		}
	}
	private static void print(Object o){
		System.out.println(o);
	}
	private static void print(){
		System.out.println();
	}
}


Measured memory_bytes: 44332
import java.io.*;
import java.util.StringTokenizer;

class Main {
	public static void main(String args[]) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String buf;

		try {
			while ((buf = br.readLine())!=null) {
				int d[] = new int[100];

				for (int i=0;i<buf.length();i++) {
					switch (buf.charAt(i)) {
						case 'I': d[i] = 1; break;
						case 'V': d[i] = 5; break;
						case 'X': d[i] = 10; break;
						case 'L': d[i] = 50; break;
						case 'C': d[i] = 100; break;
						case 'D': d[i] = 500; break;
						case 'M': d[i] = 1000; break;
					}
				}

				int ans = 0;
				int l = buf.length();
				for (int i=0;i<l;i++) {
					if (d[i]<d[i+1]&&i<l-1) ans -= (d[i]<<1);
					ans += d[i];
				}
				System.out.println(ans);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 17084
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		String[] ary = new String[H * W];
		for (int i = 0; i < H; i++) {
			String str = sc.next();
			for (int j = 0; j < str.length(); j++) {
				ary[i * W + j] = String.valueOf(str.charAt(j));
			}
		}
		int index = 0;

		for (int i = 0; i < H + 2; i++) {
			for (int j = 0; j < W + 2; j++) {
				if (i == 0 || i == H + 1) {
					System.out.print("#");
				} else if (j == 0 || j == W + 1) {
					System.out.print("#");
				} else {
					System.out.print(ary[index]);
					index++;
				}
			}
			System.out.println("");
		}
	}

}

Measured memory_bytes: 26452
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define mod 1000000007
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { cerr << (itr) << " "; }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

template <class T>
T inf = numeric_limits<T>::max();

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

  int N;
  cin >> N;
  vector<int> A(N);
  repr(i, N, 0) cin >> A[i];

  int ans = 0;
  for (int i = 0; i < N; ++i) {
    int num = i + 1;
    if (num % 2 == 1) {
      if (A[i] % 2 == 1) {
        ans += 1;
      }
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 3640
import java.io.File;
import java.io.IOException;
import java.util.*;
 
public class Main {
 
	public static void main(String[] args) throws IOException {
		//File file = new File("input.txt");
		//Scanner sc = new Scanner(file);
		
		Scanner sc = new Scanner(System.in);
		
		int H = sc.nextInt();
		int W = sc.nextInt();
		char[][] board = new char[H][W];
		for(int i = 0; i < H; i++){
			board[i] = sc.next().toCharArray();
		}
		
		
		
		for(int i = 0; i < H; i++){
			for(int j = 0; j < W; j++){
				if(board[i][j] == '#') System.out.print("#");
				else{
					int sum = 0;
					int[] dir = {-1, -1, -1, 0, 1, 1, 1, 0, -1, -1};
					for(int k = 0; k < 8; k++){
						if(i + dir[k] < 0 || i + dir[k] >= H) continue;
						if(j + dir[k + 2] < 0 || j + dir[k + 2] >= W) continue;
						if(board[i + dir[k]][j + dir[k + 2]] == '#') sum++;
					}
					System.out.print(sum);
				}
			}
			System.out.println();
		}
			 
	}
}

Measured memory_bytes: 22100
#include <stdio.h>
#include <stdlib.h>
typedef struct {
    unsigned long long a;
    int b;
} drink;
int cmp(const void *p, const void *q) {
    return ((drink *)p)->a - ((drink *)q)->a;
}
int main(void){
    int n, m, i;
    unsigned long long cost=0;
    scanf("%d %d", &n, &m);
    drink monster[n];
    for(i=0; i<n; i++)
        scanf("%lld %lld", &monster[i].a, &monster[i].b);
    qsort(monster, n, sizeof(drink), cmp);
    for(i=0; m>0; i++){
        if(monster[i].b < m){
            cost += monster[i].a * monster[i].b;
            m -= monster[i].b;
        }else{
            cost += monster[i].a * m;
            break;
        }
    }
    printf("%lld\n", cost);
    return 0;
}

Measured memory_bytes: 3324
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using ll = long long int;

int main(){
    ll H, W, N; cin >> H >> W >> N;
    ll r,c; cin >> r >> c;
    string S, T; cin >> S >> T;
    bool t = true;
    ll p, q; p = r; q = c;
    for(int i=0; i<N; i++){
        if(S[i] == 'L'){
            c--;
        }else if(S[i] == 'U'){
            r--;
        }
        if(c<1||r<1){
            t = false;
            cout << "NO";
            break;
        }
        if(T[i] == 'R'&&W-c>1){
            c++;
        }else if(T[i] == 'D'&&r<H){
            r++;
        }
    }
    if(t){
        r = p; c = q;
    for(int i=0; i<N; i++){
        if(S[i] == 'L'){
            c--;
        }else if(S[i] == 'D'){
            r++;
        }
        if(c<1||r>H){
            t = false;
            cout << "NO";
            break;
        }
        if(T[i] == 'R'&&W-c>1){
            c++;
        }else if(T[i] == 'U'&&r>1){
            r--;
        }
    }
    }
    if(t){
        r = p; c = q;
    for(int i=0; i<N; i++){
        if(S[i] == 'R'){
            c++;
        }else if(S[i] == 'D'){
            r++;
        }
        if(c>W||r>H){
            t = false;
            cout << "NO";
            break;
        }
        if(T[i] == 'L'&&c>1){
            c--;
        }else if(T[i] == 'U'&&r>1){
            r--;
        }
    }
    }
    if(t){
        r = p; c = q;
    for(int i=0; i<N; i++){
        if(S[i] == 'R'){
            c++;
        }else if(S[i] == 'U'){
            r--;
        }
        if(c>W||r<1){
            t = false;
            cout << "NO";
            break;
        }
        if(T[i] == 'L'&&c>1){
            c--;
        }else if(T[i] == 'D'&&r<H){
            r++;
        }
    }
    }
    if(t){
        cout << "YES";
    }
}

Measured memory_bytes: 776
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>

using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

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

const ll INF = 1ll<<29;
const ll MOD = 1000000007;

int main()
{
	int n;
	while (cin >> n, n) {
		vector<char> rank(n);

		for (int i = 0; i < n; i++) {
			int pm, pe, pj;

			cin >> pm >> pe >> pj;

			double pm_pe_avg = (pm + pe) / 2.0;
			double all_avg = (pm + pe + pj) / 3.0;
			if (pm == 100 || pe == 100 || pj == 100) {
				rank[i] = 'A';
			}
			else if (pm_pe_avg >= 90 || all_avg >= 80)
				rank[i] = 'A';
			else if (all_avg >= 70 || (all_avg >= 50 && (pm >= 80 || pe >= 80))) {
				rank[i] = 'B';
			}
			else
				rank[i] = 'C';
		}
		for (int j = 0; j < n; j++)
			cout << rank[j] << endl;
	}
	return 0;
}

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

typedef pair<int, int> pii;
const int MX = 1e5 + 5;
pii A[MX];

int main() {
	int n, m;
	scanf("%d", &n);
	for(int i = 0; i < n; i++) {
		scanf("%d", &m);
		A[i] = pii(m, i + 1);
	}
	sort(A, A + n);
	for(int i = 0; i < n; i++) {
		if(i) printf(" ");
		printf("%d", A[i].second);
	}
	printf("\n");
	
	return 0;
}

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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

// n回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii;  // 2次元配列
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> PII;

template<typename T>
using vec = vector<T>;
template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

const ld Pi = std::acos(-1.0L);
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;

/*GRAPH_TEMPLATE=============================================*/
template<typename T>
class Edge {
public:
    int src;  // source 状態記録「null = -1」
    int to;  // 辺の行き先
    T cost;  // 辺の重み
    Edge(int t, T w) : src(-1), to(t), cost(w) {}
    Edge(int t, T w, int src) : src(src), to(t), cost(w) {}
};
template<typename T>
using W_Graph = std::vector<std::vector<Edge<T>>>;   //重み付きグラフ
using Graph = std::vector<std::vector<int>>;         //通常グラフ
template<typename T>
using Matrix = std::vector<std::vector<T>>;          //隣接行列(使わなさそう...)


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int _StartTime_ = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    // cout << fixed << setprecision(15);

    int V,E,r; cin >> V >> E >> r;
    W_Graph<int> g(V);
    rep(i,E) {
        int s, t, d; cin >> s >> t >> d;
        g[s].push_back(Edge<int>(t, d));
    }

    minheap<PII> que;
    vi dist(V, inf);
    que.push(make_pair(0, r));
    dist[r] = 0;

    while(que.size()) {
        int cost, u;
        tie(cost, u) = que.top(); que.pop();

        for(auto e : g[u]) {
            if(!chmin(dist[e.to], cost + e.cost)) continue;
            que.emplace(cost + e.cost, e.to);
        }
    }

    rep(i,V) {
        if(dist[i] == inf) cout << "INF" << '\n';
        else cout << dist[i] << '\n';
    }

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-_StartTime_)/CLOCKS_PER_SEC));
}


Measured memory_bytes: 15300
e=enumerate
n,s,q,*k=open(0).read().split()
n=int(n)
m,c,x=eval('[0]*-~n,'*3)
for i,t in e(s,1):
  m[i]=m[i-1]+(t=='M')
  f=t=='C'
  c[i]=c[i-1]+f
  x[i]=x[i-1]+f*m[i]
for k in map(int,k):
  a=0
  for i,t in e(s):
    j=min(n,i+k)
    if t=='D':
      a+=x[j]-x[i]-(c[j]-c[i])*m[i]
  print(a)

Measured memory_bytes: 86044
#include<bits/stdc++.h>          
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define int long long
#define mk_p(a,b)	make_pair((a),(b))
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr long long MOD = 1000000007;

int gcd(int a,int b){return b ? gcd(b,a%b) : a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	double t,x;
	cin >> t >> x;
	cout << fixed << t / x << '\n';	
	return 0;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func nextInt() int {
	v, _ := strconv.Atoi(read())
	return v
}

func main() {
	sc.Split(bufio.ScanWords)

	b := read()

	if b == "A" {
		fmt.Println("T")
	} else if b == "T" {
		fmt.Println("A")
	} else if b == "C" {
		fmt.Println("G")
	} else if b == "G" {
		fmt.Println("C")
	}

}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
int main() {
  int n,x,ans=0,a[100];
  cin >> n >> x;
  for(int i=0; i<n; i++) {
    cin >> a[i];
  }
  sort(a,a+n);
  for(int i=0; i<n&&x>0; i++) {
    x-=a[i];
    ans++;
  }
  if(x!=0) {
    ans--;
  }
  cout << ans << endl;
}

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

int main(){
 
  int H,N;
  
  cin  >> H >> N;
  
  vector <int> A(N);
  
  for(int i=0; i<N; i++){
  cin >> A.at(i);
  }

  int sum=0;
  
   
  for(int j=0; j<N; j++){
    sum += A.at(j);
  }
  
  if(H-sum >0){
   cout << "No" << endl; 
  }
  
  else{
   cout << "Yes" << endl; 
  }
  
}

Measured memory_bytes: 640
program answer
implicit none

integer :: X, Y, sum

read(*,*) X, Y

if(X==1.and.Y==1) then
    write(*,*) '1000000'
     stop
end if

sum = 0
if(X==1.or.Y==1) then
   sum = sum + 300000
end if

if(X==2) then
 sum = sum + 200000
end if

if(Y==2) then
 sum = sum + 200000
end if

if(X==3) then
 sum = sum + 100000
end if

if(Y==3) then
sum = sum + 100000
end if

write(*,*)  sum

stop
end program answer

Measured memory_bytes: 2828
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)

/*
またぐときにコストが発生すると考える。
dp(i,j) = i個保留、コストがjとなる場合の数
*/

template<int MOD>
struct ModInt {
	static const int Mod = MOD;
	unsigned x;
	ModInt() : x(0) { }
	ModInt(signed sig) { int sigt = sig % MOD; if (sigt < 0) sigt += MOD; x = sigt; }
	ModInt(signed long long sig) { int sigt = sig % MOD; if (sigt < 0) sigt += MOD; x = sigt; }
	int get() const { return (int)x; }

	ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
	ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
	ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
	ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }

	ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
	ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
	ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
	ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }

	ModInt inverse() const {
		signed a = x, b = MOD, u = 1, v = 0;
		while (b) {
			signed t = a / b;
			a -= t * b; std::swap(a, b);
			u -= t * v; std::swap(u, v);
		}
		if (u < 0) u += Mod;
		ModInt res; res.x = (unsigned)u;
		return res;
	}
};
typedef ModInt<1000000007> mint;

ll n,m;
mint dp[51][5001],dp2[51][5001];

void init(){
	cin>>n>>m;
	dp[0][0]=1;
}

int main(void){
	init();
	rep(i,n){
		rep(j,n){
			rep(k,n*n+1){
				dp2[j][k+j*2]+=dp[j][k]*2*j;  // どのjとくっつくかで 2j 通り
				if(j-1>=0)dp2[j-1][k+j*2]+=dp[j][k]*j*j;  // 左右それぞれどのjを受け取るかで j^2 通り
				dp2[j][k+j*2]+=dp[j][k];  // ----
				dp2[j+1][k+j*2]+=dp[j][k];  // 出す
			}
		}
		// cerr<<i<<endl;
		rep(j,n){
			rep(k,n*n+1){
				dp[j][k]=dp2[j][k];
				dp2[j][k]=0;
				// cerr<<dp[j][k].get()<<" ";
			}
			// cerr<<endl;
		}
	}
	cout<<dp[0][m].get()<<endl;
	return 0;
}

Measured memory_bytes: 2176
#include <cstdlib>
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string str_s;
    cin >> str_s;
    int n;
    n = str_s.size();
    vector<char> s(n), zero(n), one(n);
    for (int i = 0; i < n; i++)
    {
        s.at(i) = str_s[i];
    }

    for (int i = 0; i < n; i++)
    {
        if (i % 2 == 0)
        {
            zero.at(i) = '0';
            one.at(i) = '1';
        }
        else
        {
            zero.at(i) = '1';
            one.at(i) = '0';
        }
    }

    int count_zero = 0, count_one = 0;

    for (int i = 0; i < n; i++)
    {

        if (s.at(i) == zero.at(i))
        {
            count_zero++;
        }
        if (s.at(i) == one.at(i))
        {
            count_one++;
        }
    }

    if (count_zero > count_one)
    {
        cout << count_one << endl;
    }
    else
    {
        cout << count_zero << endl;
    }

    return 0;
}

Measured memory_bytes: 640
l,r=map(int,input().split())
mod=2019
ans=((10**9)*2)**2
for i in range(l,r):
    for j in range(i+1,r+1):
        x=i*j

        if x%mod==0:
            print(0)
            exit()
        else:
            ans=min(ans,x%mod)
print(ans)

Measured memory_bytes: 39024
#include<iostream>
using namespace std;
int main()
{
    int a,b,max,result;
    cin >> a >> b;
    if(a>=3 && b<=20)
    {
        if(a!=b)
            {
                if(a>b) max=a;
                else max=b;
                result=(max*2)-1;
                cout << result << endl;
            }
        else
            cout << a*2 << endl;
    }
    return 0;
}


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

int main(){
  string S ; 
  cin >> S ; 
  int N ; 
  N = S.size() ;
  int cnt = 0  ; 
  
  for(int i = 1 ; i < N ; i++){
    if((N-i)%2 == 0){
      
      for(int j = 0 ; j < (N-i)/2 ; j++){
        if(S.at(j) != S.at((N-i)/2 + j)){
          cnt++ ; 
          
        }
      }
     // cout << N-i <<" "<< cnt << endl ; 
      if(cnt == 0)  {
        cout << N - i << endl ; 
        return 0 ; 
      }
      cnt = 0;

    }
  }
}

Measured memory_bytes: 3552
from fractions import gcd
from itertools import accumulate


def solve(n, x, d):
    if d == 0:
        return 1 if x == 0 else n + 1
    elif d < 0:
        x, d = -x, -d

    g = gcd(x, d)
    x //= g
    d //= g

    lowers = [0] + list(accumulate(range(n)))
    uppers = [0] + list(accumulate(range(n - 1, -1, -1)))
    ans = 0
    for k_mod in range(min(n + 1, d)):
        k = k_mod
        offset = 0
        endpoints = []
        while k <= n:
            endpoints.append((lowers[k] + offset, 0))
            endpoints.append((uppers[k] + offset, 1))
            k += d
            offset += x
        endpoints.sort()
        opening = 0
        current_left = 0
        for s, t in endpoints:
            if t == 0:
                if opening == 0:
                    current_left = s
                opening += 1
            else:
                opening -= 1
                if opening == 0:
                    ans += s - current_left + 1

    return ans


n, x, d = map(int, input().split())
print(solve(n, x, d))


Measured memory_bytes: 69148
#!/usr/bin/env python3
import sys
from math import ceil
input = lambda: sys.stdin.readline()[:-1]
sys.setrecursionlimit(10**8)
inf = float('inf')
mod = 10**9+7

n,a,b=map(int,input().split())
h=[]
for i in range(n):
    h.append(int(input()))
ok=inf
left=1
right=10**9+10
while left<right:
    mid=(left+right)//2
    tmp=0
    for hi in h:
        tmp+=max(0,ceil((hi-mid*b)/(a-b)))
    if tmp>mid:
        left = mid+1
    else:
        right=mid
        ok=min(ok,mid)
print(ok)




Measured memory_bytes: 45276