akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
	ost<<"{"<<p.first<<","<<p.second<<"}";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
	ost<<"{";
	for(int i=0;i<v.size();i++){
		if(i)ost<<",";
		ost<<v[i];
	}
	ost<<"}";
	return ost;
}

template<uint32_t mod>
struct ModInt{
	uint32_t a;
	ModInt& s(uint32_t vv){
		a=vv<mod?vv:vv-mod;
		return *this;
	}

	ModInt(int64_t x=0){s(x%mod+mod);}

	ModInt& operator+=(const ModInt &x){return s(a+x.a);}
	ModInt& operator-=(const ModInt &x){return s(a+mod-x.a);}
	ModInt& operator*=(const ModInt &x){
		a=uint64_t(a)*x.a%mod;
		return *this;
	}
	ModInt& operator/=(const ModInt &x){
		*this*=x.inv();
		return *this;
	}

	ModInt operator+(const ModInt &x)const{return ModInt(*this)+=x;}
	ModInt operator-(const ModInt &x)const{return ModInt(*this)-=x;}
	ModInt operator*(const ModInt &x)const{return ModInt(*this)*=x;}
	ModInt operator/(const ModInt &x)const{return ModInt(*this)/=x;}
	bool operator==(const ModInt &x)const{return a==x.a;}
	bool operator!=(const ModInt &x)const{return a!=x.a;}
	bool operator<(const ModInt &x)const{return a<x.a;}

	ModInt operator-()const{return ModInt()-*this;}
	ModInt pow(int64_t n)const{
		ModInt res(1),x(*this);
		while(n){
			if(n&1)res*=x;
			x*=x;
			n>>=1;
		}
		return res;
	}

	ModInt inv()const{return pow(mod-2);}
};

template<uint32_t mod>
istream& operator>>(istream& in,ModInt<mod>& a){
	return (in>>a.a);
}
template<uint32_t mod>
ostream& operator<<(ostream& out,const ModInt<mod>& a){
	return (out<<a.a);
}
using mint=ModInt<1000000007>;

int N,K;
mint dp[111][40000];
signed main(){
	cin>>N>>K;
	int B=1;
	while((B+1)*(B+1)<=N)B++;
	dp[0][1]=1;
	K++;
	rep(i,K){
		mint sum=0;
		for(int j=1;j<=B;j++)sum+=dp[i][j];
		for(int j=1;j<=B;j++)dp[i+1][j]+=sum;

		sum=0;
		for(int j=B;j>=1;j--){
			int tmp=max(0ll,N/j-B);
			sum+=dp[i][j]*tmp;
			dp[i+2][j]+=sum;
		}
		sum=0;
		for(int j=1;j<=B;j++){
			int tmp=max(0ll,N/j-B);
			dp[i+2][j]+=sum*tmp;
			sum+=dp[i][j];
		}
	}


	cout<<dp[K][1]<<endl;
	return 0;
}

Measured memory_bytes: 17536
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        // 整数の入力
        int H = sc.nextInt();
        int W = sc.nextInt();
        int A = sc.nextInt();
        int B = sc.nextInt();
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++) {
                if ((i < B && j < A) || (i >= B && j >= A)){
                    System.out.print("1");
                } else {
                    System.out.print("0");
                }
            }
            System.out.println("");
        }
//        System.out.println((a + b + c) + " " + s);
    }

}

Measured memory_bytes: 45200
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#pragma comment(linker, "/STACK:16000000")
using namespace std;

const int Maxn = 100005;

int n;
vector <int> neigh[Maxn];

int Get(int v, int p)
{
	int res = 0;
	for (int i = 0; i < neigh[v].size(); i++) {
		int u = neigh[v][i];
		if (u == p) continue;
		res ^= (Get(u, v) + 1);
	}
	return res;
}

int main()
{
	scanf("%d", &n);
	for (int i = 0; i < n - 1; i++) {
		int a, b; scanf("%d %d", &a, &b);
		neigh[a].push_back(b);
		neigh[b].push_back(a);
	}
	int res = Get(1, 0);
	printf("%s\n", res? "Alice": "Bob");
	return 0;
}

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

static const int MAX = 1e+5;
const ll INF = 1e+15;
int a[3 * MAX];
ll lsum[MAX+1], rsum[MAX+1];

int main(){
    int n;
    scanf("%d", &n);
    ll l = 0, r = 0;
    priority_queue<int> lpq, rpq;
    for(int i = 0; i < 3 * n; i++){
        scanf("%d", &a[i]);
        if(i < n){
            lpq.push(-a[i]);
            l += a[i];
        }
        if(i >= 2 * n){
            rpq.push(a[i]);
            r += a[i];
        }
    }
    ll ans = -INF;
    lsum[0] = l, rsum[n] = r;
    for(int k = n; k < 2 * n; k++){
        lpq.push(-a[k]);
        l += a[k] + lpq.top();
        lpq.pop();
        lsum[k - n + 1] = l;
    }
    for(int k = 2 * n - 1; k >= n; k--){
        rpq.push(a[k]);
        r += a[k] - rpq.top();
        rpq.pop();
        rsum[k - n] = r;
    }
    for(int k = 0; k <= n; k++){
        ans = max(ans, lsum[k] - rsum[k]);
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 3832
# Square869120Contest #4 B - Buildings are Colorful!　
# 全探探索　ver

import sys

N, K = map(int, sys.stdin.readline().strip().split())
a = list(map(int, sys.stdin.readline().strip().split()))

ans = float('inf')
for i in range(2 ** (N - 1)):
    bit = [(i >> j) & 1 for j in range(N - 1)]  # 左から2番目以降で見えるようにするビルを選択

    can_see = 0
    cost = 0
    height = a[0]
    for j, b in enumerate(bit):
        if (b == 1) & (height >= a[j + 1]):
            cost += height - a[j + 1] + 1
            height = height + 1
            can_see += 1
        elif (b == 1):
            height = a[j + 1]
            can_see += 1
        elif height < a[j + 1]:
            can_see += 1
        height = max(a[j + 1], height)

    if can_see >= K - 1:
        ans = min(ans, cost)

print(ans)







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

# 各時点での最小値を求める
m = [0]*(N)
m[0] = p[0]
for i in range(N-1):
  m[i+1] = min(m[i], p[i+1])

ans = 1
for i in range(1, N):
  if m[i-1] > p[i]: ans += 1
    
print(ans)

Measured memory_bytes: 32204
module subprogram
	implicit none
	contains
subroutine heapsort2(n,array,turn)
		implicit none
		integer(8),intent(in)::n
		integer(8),intent(out)::turn(1:n)
		integer(8),intent(inout)::array(1:n)
  
		integer(8)::i,k,j,l,m
		integer(8)::t
		do i=1,N
			turn(i)=i
		enddo  
		
		if(n.le.0)then
			write(6,*)"Error, at heapsort"; stop
		endif
		if(n.eq.1)return
 

 
		l=n/2+1
		k=n
		do while(k.ne.1)
			if(l.gt.1)then
				l=l-1
				t=array(l)
				m=turn(l)
			else
				t=array(k)
				m=turn(k)
				array(k)=array(1)
				turn(k)=turn(1)
				k=k-1
				if(k.eq.1) then
					array(1)=t
					turn(1)=m
					exit
				endif
			endif
			i=l
			j=l+l
			do while(j.le.k)
				if(j.lt.k)then
					if(array(j).lt.array(j+1))j=j+1
				endif
				if (t.lt.array(j))then
					array(i)=array(j)
					turn(i)=turn(j)
					i=j
					j=j+j
				else
					j=k+1
				endif
			enddo
			array(i)=t
			turn(i)=m
		enddo
 
		return
	end subroutine heapsort2
end module subprogram	

program main
	use subprogram
	implicit none
	integer(8) :: N, M, i, j
	integer(8), allocatable :: A(:)
	integer(8), allocatable :: B(:), turn(:)
	integer(8) :: ans
	read(*, *) N, M
	allocate(A(1:N), B(1:N), turn(1:N))
	do i = 1, N
		read(*, *) A(i), B(i)
	end do
	call heapsort2(N,A,turn)
	ans = 0
	do i = 1, N
		if(M - B(turn(i)) >= 0) then
			ans = ans + B(turn(i))*A(i)
			M   = M - B(turn(i))
		else
			ans = ans + A(i)*M
			exit
		end if
	end do
	write(*, *) ans
end program main

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define all(a) a.begin(), a.end()
#define mkp make_pair
#define F first
#define S second
#define pb push_back
#define ll long long
#define vi vector<long long>
#define sz(x) (int)x.size()
#define pi pair<long long, long long>
#define endl '\n'
#define _ << ' '
#define FAST_LOG2(x) (sizeof(unsigned long)*8 - 1 - __builtin_clzl((unsigned long)(x)))
#define clog2(x) (((x) - (1 << FAST_LOG2(x))) ? FAST_LOG2(x) + 1 : FAST_LOG2(x))
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> idxset;
//find_by_order(i) : iterator to the value at index i, order_of_key(x) : the index of value x
const ll mod = 998244353;
const ll INF = (ll)1e9+1;
const ll N = 1e5;

ll t, q, n, a[100001];

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    #ifndef ONLINE_JUDGE
    //freopen("B.txt", "r", stdin);
    #endif
    cin >> n;
    for(int i=1; i<n; i++){
        cin >> a[i];
    }
    a[0] = INF;
    ll ans = a[n-1];
    for(int i=n-1; i>0; i--){
        ans += min(a[i], a[i-1]);
    }
    cout << ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

class tsort {
public:
	int V;
	vector<vector<int> > G;
	vector<int> deg,res;
	tsort(int node_size) : V(node_size), G(V), deg(V, 0){}
	void add_edge(int from,int to){
		G[from].push_back(to);
		deg[to]++;
	}
	bool solve() {
		queue<int> que;
		for(int i = 0; i < V; i++){
			if(deg[i] == 0){
				que.push(i);
			}
		}
		while(!que.empty()){
			int p = que.front();
			que.pop();
			res.push_back(p);
			for(int v : G[p]){
				if(--deg[v] == 0){
					que.push(v);
				}
			}
		}
		return (*max_element(deg.begin(),deg.end()) != 0);
	}
};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    string s;
    cin >> s;
    tsort ts(2*n);
    rep(i,m){
        int a,b;
        cin >> a >> b;
        --a, --b;
        if(s[a] == s[b]){
            ts.add_edge(2*a, 2*b+1), ts.add_edge(2*b, 2*a+1);
        }else{
            ts.add_edge(2*a+1, 2*b), ts.add_edge(2*b+1, 2*a);
        }
    }
    if(ts.solve()){
        cout << "Yes\n";
    }else{
        cout << "No\n";
    }
    return 0;
}

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

int main(){
  int n,x,t;
  cin >> n >> x >> t;
  int m = n/x;
  if(n%x != 0) x = 1;
  else x = 0;
  
  n = m + x;
  
  cout << n*t << endl;
  
  return 0;
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
typedef pair<P, P> PP;

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

    int h, w;
    cin >> h >> w;
    int a[510][510] = {};
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            cin >> a[i][j];
        }
    }
    vector<PP> ans;
    for (int i = 0; i < h; i++)
    {
        if (i % 2 == 0)
        {
            for (int j = 0; j < w; j++)
            {
                if (a[i][j] % 2 == 1)
                {
                    if (j == w - 1)
                    {
                        if (i == h - 1)
                            continue;
                        ans.push_back(PP{{i + 1, j + 1}, {i + 2, j + 1}});
                        a[i + 1][j]++;
                    }
                    else
                    {
                        ans.push_back(PP{{i + 1, j + 1}, {i + 1, j + 2}});
                        a[i][j + 1]++;
                    }
                }
            }
        }
        else
        {
            for (int j = w - 1; j >= 0; j--)
            {
                if (a[i][j] % 2 == 1)
                {
                    if (j == 0)
                    {
                        if (i == h - 1)
                            continue;
                        ans.push_back(PP{{i + 1, j + 1}, {i + 2, j + 1}});
                        a[i + 1][j]++;
                    }
                    else
                    {
                        ans.push_back(PP{{i + 1, j + 1}, {i + 1, j}});
                        a[i][j - 1]++;
                    }
                }
            }
        }
    }
    cout << ans.size() << endl;
    for (int i = 0; i < ans.size(); i++)
    {
        P a = ans[i].first, b = ans[i].second;
        cout << a.first << " " << a.second << " " << b.first << " " << b.second << endl;
    }
}

Measured memory_bytes: 5232
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define reps(i,a,b) for(int i=a;i<b;++i)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
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(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    vector<int> a(3);
    rep(i, 3) cin >> a[i];
    sort(all(a));
    rep(i, 3) cout << a[i] << (i == 2 ? '\n' : ' ');
}



Measured memory_bytes: 3164
using System;
using System.Collections.Generic;
using System.Linq;

public class Hello
{
    private const int MOD_N = 1000000000 + 7;

    public static void Main()
    {
        var list = Console.ReadLine().Split(' ');
        var m = int.Parse(list[0]);
        var k = int.Parse(list[1]);

        var max = (int)Math.Pow(2, m);

        if (k >= max)
        {
            Console.WriteLine(-1);
            return;
        }

        if (m == 0)
        {
            Console.WriteLine("0 0");
            return;
        }
        if (m == 1)
        {
            if (k == 0)
                Console.WriteLine("0 0 1 1");
            else
                Console.WriteLine("-1");
            return;
        }

        Console.WriteLine(string.Join(" ", Ans(k, max)));
    }

    private static IEnumerable<int> Ans(int k, int max)
    {
        for (int i = 0; i < max; ++i)
        {
            if (i != k)
                yield return i;
        }
        yield return k;
        while (max > 0)
        {
            --max;
            if (max != k)
                yield return max;
        }
        yield return k;
    }
}


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

struct segment_tree {
  vector<map<char, int>> node;
  int n;

  segment_tree(int n) {
    int msb = 1LL << ((n==0) ? 0 : 64 - __builtin_clzll(n)-1);
    this->n = (n==msb) ? n : msb << 1;
    node.resize(2 * this->n - 1);
  }

  inline int r_child(int v) { return v*2+2; }
  inline int l_child(int v) { return v*2+1; }
  inline int parent(int v) { return (v + (v%2)) / 2 - 1; }

  void query(set<char> &out, int ql, int qr, int v=0, int l=0, int r=-1) {
    r = (r==-1) ? n-1 : r;
    if(ql<=l && r<=qr) {
      for(auto e : node[v]) if(e.second) out.insert(e.first);
      return;
    }
    int mid=(l+r)/2;
    if(ql <= mid)   query(out, ql, qr, l_child(v), l,     mid);
    if(qr >= mid+1) query(out, ql, qr, r_child(v), mid+1, r  );
  }

  void set_value(int index, char val) {
    int v = node.size()/2 + index;
    char orig = 0;
    for(auto x : node[v]) if(x.second) orig = x.first;

    if(orig) node[v][orig]--;
    node[v][val]++;

    while(parent(v) != -1) {
      v=parent(v);
      if(orig) node[v][orig]--;
      node[v][val]++;
    }
  }
};

int N, Q;
string S;

signed main() {
  cin >> N;
  cin >> S;

  segment_tree st(N);
  for(int i=0; i<N; i++) {
    st.set_value(i, S[i]);
  }

  cin >> Q;
  for(int q=0; q<Q; q++) {
    int t;
    cin >> t;
    if(t==1) {
      int i; char c; cin >> i >> c;
      st.set_value(i-1, c);
    }
    else {
      int l,r; cin >> l >> r;
      l--; r--;
      set<char> out;
      st.query(out, l,r);
      //for(auto o : out) cerr << o; cerr<<endl;
      cout << out.size() << endl;
    }
  }
}

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

#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)

int a[100000];
int n,k;

int main(){
    while(cin>>n>>k, n|k){
        rep(i,n) cin>>a[i];
        int ans=0;
        rep(i,k) ans+=a[i];
        int t=ans;
        rep(i,n-k){
            t-=a[i]; t+=a[i+k];
            ans=max(t,ans);
        }
        cout<<ans<<endl;
    }
}

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

#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define eb emplace_back

typedef long long ll;
typedef pair<int,int> ii;
typedef vector< pair<int,int> > vii;
const int INF = 0x3f3f3f3f;

const int T = 2e5 + 2;
ll v[T];
bool vis[T];
vector<int> g[T];
int n,q;

void dfs(int at) {
    vis[at] = 1;
    for(int nxt : g[at]) {
        if(!vis[nxt]) {
            v[nxt] += v[at];
            dfs(nxt);
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin >> n >> q;
    ll a,b;

    for(int i = 0; i < n-1; i++) {
        cin >> a >> b;
        g[a].pb(b);
        g[b].pb(a);
    }

    while(q--) {
        cin >> a >> b;
        v[a] += b;
    }
    
    for(int i = 1; i <= n; i++) {
        if(!vis[i]) dfs(i);
        cout << v[i] << " ";
    }
    cout << endl;
    

    return 0;
}


Measured memory_bytes: 21376
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()
// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class X> void DEBUG(X d, T e){if(DEBUG_OUT == false)return;std::cout <<d<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//CODE
int gcd(int a, int b) {
  while(1) {
    if(a < b) swap(a, b);
    if(!b) break;
    a %= b;
  }
  return a;
}

void solve(void)
{
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  cout<<(B) + (B)/(C*D/gcd(C,D)) - (B)/C - (B)/D -1*((A-1) + (A-1)/(C*D/gcd(C,D)) - (A-1)/C - (A-1)/D)<<endl;
  // DEBUG((B) + (B)/(C*D/gcd(C,D)) - (B)/C - (B)/D);
  return;
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();
  

 
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll ,ll> pll;
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(X) (X).begin(), (X).end()
#define REP(i,x,y) for(ll i = x;i <= y;++i)
vector<string> vec_splitter(string s) {
    for(char& c: s) c = c == ','?  ' ': c;
    stringstream ss; ss << s;
    vector<string> res;
    for(string z; ss >> z; res.push_back(z))
        ;
    return res;
}
void debug_out(vector<string> args, int idx) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, Head H, Tail... T) {
    if(idx > 0) cerr << ", ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, T...);
}
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __VA_ARGS__)
void localTest() {
    #ifndef ONLINE_JUDGE
        freopen("inp", "r", stdin);
        freopen("out", "w", stdout);
    #endif      
}
const ll N = 2e5 + 5, inf = 1e15, M = 1e6 + 5, MX = 1e6;
ll dp[N], n, b, A[N];
struct line {
	ll m, c;
};
vector<line> T(4 * M, (line){0LL, inf});
ll getY(line l, ll x) {
	return l.m * x + l.c;
}
void addLine(ll node, ll lo, ll hi, line l) {
	if(lo > hi) return;
	ll mid = (lo + hi) >> 1LL;
	bool leftVal = getY(l, lo) < getY(T[node], lo);
	bool rightVal = getY(l, mid + 1) < getY(T[node], mid + 1);
	if(rightVal) swap(T[node], l);
	if(lo == hi) return;
	if(leftVal != rightVal) addLine(node << 1, lo, mid, l);
	else addLine(node << 1 | 1, mid + 1, hi, l);
	return;
}
ll query(ll node, ll lo, ll hi, ll x) {
	ll ans = getY(T[node], x);
	if(lo >= hi) return ans;
	ll mid = (lo + hi) >> 1LL;
	if(x <= mid) return min(ans, query(node << 1, lo, mid, x));
	else return min(ans, query(node << 1 | 1, mid + 1, hi, x));
}
int main() {

    //localTest();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n >> b;
 	for(ll i = 1;i <= n;++i) {
 		cin >> A[i];
 		if(i > 1) dp[i] = b + A[i] * A[i] + query(1, 1, MX, A[i]);
 		addLine(1, 1, MX, (line){-2 * A[i], dp[i] + A[i] * A[i]});
 	}
 	cout << dp[n] << "\n";
    
    return 0;
}

Measured memory_bytes: 65920
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

int n;
vector<int> a;

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

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    vector<int> b(n);
    b[0] = a[0];
    Rep(i, 1, n) b[i] = b[i - 1] + a[i];
    int res1 = 0, tmp = 0;
    rep(i, n)
    {
        int c = b[i] + tmp;
        if (i % 2 == 0)
        {
            if (c > 0)
                continue;
            res1 += 1 - c;
            tmp += 1 - c;
        }
        else
        {
            if (c < 0)
                continue;
            res1 += c + 1;
            tmp -= c + 1;
        }
    }
    int res2 = 0;
    tmp = 0;
    rep(i, n)
    {
        int c = b[i] + tmp;
        if (i % 2 == 0)
        {
            if (c < 0)
                continue;
            res2 += c + 1;
            tmp -= c + 1;
        }
        else
        {
            if (c > 0)
                continue;
            res2 += 1 - c;
            tmp += 1 - c;
        }
    }
    cout << min(res1, res2) << endl;
}

Measured memory_bytes: 1792
from itertools import accumulate
n, k, *a = map(int, open(0).read().split())
acc = [0] + list(accumulate(a))
ps = [acc[j] - acc[i] for i in range(n) for j in range(i + 1, n + 1)]
ans = 0
for i in range(max(ps).bit_length(), -1, -1):
	x = ans + (1 << i)
	c = 0
	for y in ps:
		if y & x == x:
			c += 1
			if c >= k:
				ans = x
				break
print(ans)


Measured memory_bytes: 66044
import java.util.*;
import java.math.*;
public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int m = in.nextInt();
		for(int i = 0; i < m; i++) n -= in.nextInt();
		System.out.println((n >= 0) ? n : -1);
	}
} 


Measured memory_bytes: 46060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <numeric>

template <class T>
auto Input()
{
	T t;
	std::cin >> t;
	return t;
}

template <class T>
auto Input(int n)
{
	T v(n);
	for (auto &e : v) std::cin >> e;
	return v;
}


int main()
{
	auto s = Input<std::string>();
	
	int max = 0;
	int cnt = 0;
	for (char c : s) {
		if (c == 'A' || c == 'C' || c == 'G' || c == 'T') {
			cnt++;
		}
		else {
			max = std::max(cnt, max);
			cnt = 0;
		}
	}
	
	std::cout << std::max(cnt, max) << std::endl;
	
	return 0;
}


Measured memory_bytes: 3152
#include <bits/stdc++.h>
using namespace std;
#define inf 999999999
#define lin long long
#define lfl long double
#define loop(i, a, b) for (lin i = (a), i##len = (b); i < i##len; ++i)
#define rep(i, n) loop(i, 0, n)

lin x[3], a[3][1000], k;

int main(void)
{
    rep(i,3)
    {
        cin >> x[i];
    }
    cin >> k;
    rep(i,3)
    {
        rep(j,x[i])
        {
            cin >> a[i][j];
        }
    }

    vector<lin> ab;
    rep(i, x[0])
    {
        rep(j, x[1])
        {
            ab.push_back(a[0][i] + a[1][j]);
        }
    }

    sort(ab.begin(), ab.end(), greater<lin>());

    vector<lin> abc;
    lin abSize = ab.size();
    lin kk = min(abSize, k);
    rep(i, kk)
    {
        rep(j, x[2])
        {
            abc.push_back(ab[i] + a[2][j]);
        }
    }
    sort(abc.begin(), abc.end(), greater<lin>());

    rep(i,k)
    {
        cout << abc[i] << endl;
    }

    return 0;
}


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

#define REP(i ,n) for(int i=0 ;i < n; i++)
#define REPB(i ,n) for(int i=n; i >= 0; i--)
#define FOR(i ,m ,n) for(int i=m; i < n; i++)
#define FORB(i, m, n) for(int i=m; i>= n; i--)
#define ll long long
#define pb push_back
#define popb pop_back
#define debug(i) cout << i << endl
using namespace std;
int main(){
  int a, b, c;
  cin >> a >> b >> c;
  string ans = "NO";

  if(a == 1){
      cout << "YES" << endl;
      return 0;
    }
  int p = a;
  for(int i = 0 ; i <= b; i++ ){
      if((p % b) == c){
         ans = "YES";
         break;
      }
      p += a;
    }
    cout << ans << endl;
}

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

int atob(int a,int b){
  if(a<b){
    int tmp=a;
    a=b;
    b=tmp;
  }
  
  int r=a%b;
  while(r!=0){
    a=b;
    b=r;
    r=a%b;
  }
  return b;
}

int main()
{
  int k;
  cin >> k;
  long long int sum = 0;
  for(int i=1;i<=k;i++){
    for(int j=1;j<=k;j++){
      for(int l=1;l<=k;l++){
        int a = atob(i,j);
        int b = atob(a,l);
        sum += b;
      }
    }
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 3620
#include "bits/stdc++.h"

typedef long long ll;
using namespace std;

int main() {
    int a, b, k;
    cin >> a >> b >> k;

    int cnt = 0;
    for (int i = min(a, b); 0 < i; --i) {
        if (a % i == 0 && b % i == 0) cnt++;
        if (cnt == k) {
            cout << i << endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val a_b_c = sc.nextLine()
            .split(" ")
            .map { Integer.parseInt(it) }
    val d = a_b_c[0] - a_b_c[1]
    val e = a_b_c[2] - d
    if (e < 0) {
        println(0)
    } else {
      println(e)
    }
}

Measured memory_bytes: 36080
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> ipair;
typedef pair<ll, ll> lpair;
typedef tuple<int, int, int> ituple;

// const int INF = INT_MAX;
// const ll INF = LLONG_MAX;
// const int MOD = ((int)1e9 + 7);
// const ld EPS = (1e-10);
#define PI acosl(-1)
#define MAX_N (100000 + 2)

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

  if (c - (a + b) < 0) {
    cout << "No" << endl;
    return;
  }
  ll left = 4 * a * b;
  ll d = a + b;
  ll right = c * c - 2 * c * d + d * d;

  cout << (left < right ? "Yes" : "No") << endl;


}

void solve(){
  int t = 1;
  // scanf("%d", &t);
  for (int i = 0; i < t; i++){
    exec();
  }
}

int main(){
  solve();
  return 0;
}


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

using namespace std;

static const int INF = 1e9 + 7;

template<typename T>
using Vec = vector<T>;

template<typename T, typename T2>
using P = pair<T, T2>;

template<typename... Args>
using Tup = tuple<Args...>;

template<typename T>
using qp = priority_queue<T, Vec<T>, greater<T> >;

template<typename T>
using pq = priority_queue<T>;

using llong = long long;
using ullong = unsigned long long;
using uint = unsigned int;

template<typename T>
T gcd(T x, T y)
{
	return y ? gcd(y, x % y) : x;
}

void hawawa()
{
	int k, s;
	cin >> k >> s;
	int ans = 0;
	for (int i = 0; i <= k; i++) {
		for (int j = 0; j <= k; j++) {
			if (i + j > s) continue;
			if (s - i - j <= k) ans++;
		}
	}
	cout << ans << "\n";
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ff(i,s,n) for(int i=s;i<n;i++)
#define fr(i,s,n) for(int i=n-1;i>=s;i--)
#define llu long long int
const int mod=1000000007;

int val=0;
void dfs(set<int> adj[], bool visited[], int source){
	val++;
	visited[source]=true;
	set<int>::iterator i;
	for (i = adj[source].begin(); i != adj[source].end(); ++i) 
        if (!visited[*i]) 
            dfs(adj, visited, *i); 
	
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,e;
	cin>>n>>e;
	set<int> adj[n];
	for(int i=0;i<e;i++){
		int a,b;
		cin>>a>>b;
		a--;b--;
		//if(find(adj[a].begin(),adj[a].end(),b)==adj[a].end())
			adj[a].insert(b);
		//if(find(adj[b].begin(),adj[b].end(),a)==adj[b].end())
			adj[b].insert(a);
	}
	
	bool visited[n];
	memset(visited,false,sizeof(visited));
	
	int ans=0;
	for(int i=0;i<n;i++){
		val=0;
		//TODO: for every node do DFS 
		if(!visited[i]){
			dfs(adj,visited,i);
      ans++;
		}
	}
	cout<<ans-1;
	return 0;
}


//1
//7 2
//3 5 4 5 1 1 1


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

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define sz(v) (int)v.size()

#define MOO(i, a, b) for(int i=a; i<b; i++)
#define M00(i, a) for(int i=0; i<a; i++)
#define MOOd(i,a,b) for(int i = (b)-1; i >= a; i--)
#define M00d(i,a) for(int i = (a)-1; i>=0; i--)

#define FAST ios::sync_with_stdio(0); cin.tie(0);
#define finish(x) return cout << x << '\n', 0;
#define dbg(x) cerr << ">>> " << #x << " = " << x << "\n";
#define _ << " _ " <<

template<class T> bool ckmin(T& a, const T& b) {return b < a ? a = b, 1 : 0;}
template<class T> bool ckmax(T& a, const T& b) {return a < b ? a = b, 1 : 0;}

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef pair<ld,ld> pd;
typedef complex<ld> cd;

template<int sz> struct BIT {
    int b[sz+1];
    BIT() {
        M00(i, sz+1) b[i] = 0;
    }
    void add(int k, int val) {
        k++;
        for(; k <= sz; k+=(k&-k)) b[k] += val;
    }
    int psum(int ind) {
        int ans = 0;
        ind++;
        for(; ind>0; ind-=(ind&-ind)) ans+=b[ind];
        return ans;
    }
    int sum(int l, int r) {
        return psum(r) - psum(l-1);
    }
};

const int MAX_N = 500050;
int n, q;
int arr[MAX_N];
pi ori[MAX_N];
pi queries[MAX_N];
int idx[MAX_N];
BIT<MAX_N> b;
map<pi, int> ans;

bool sortSecond(pi p1, pi p2) {
    return p1.s < p2.s;
}

int main() { FAST
    cin >> n >> q;
    M00(i, n) {
        cin >> arr[i];
        arr[i]--;
    }
    M00(i, q) {
        cin >> queries[i].f >> queries[i].s;
        queries[i].f--;
        queries[i].s--;
        ori[i] = queries[i];
    }
    sort(queries, queries+q, sortSecond);
    int cur = 0;
    M00(i, n) idx[i] = -1;
    M00(i, q) {
        for(; cur <= queries[i].s; cur++) {
            if(idx[arr[cur]] != -1) {
                b.add(idx[arr[cur]], -1);
            }
            idx[arr[cur]] = cur;
            b.add(cur, 1);
        }
        cur--;
        ans[queries[i]] = b.sum(queries[i].f, queries[i].s);
    }
    M00(i, q) cout << ans[ori[i]] << "\n";
}



Measured memory_bytes: 48692
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
const int mod = 1e9 + 7;
int main()
{
	SPEED
	int n, m;
	cin >> n >> m;
	int WA_count[n] = {0};
	int AC_count[n] = {0};
	int count_AC = 0;
	int count_pen = 0;

	int p;
	string s;
	for (int i = 0; i < m; ++i)
	{
		cin >> p >> s;
		p--;
		if (s == "AC")
		{
			if (AC_count[p] == 0)
			{
				AC_count[p] = 1;
				count_AC++;
				if (WA_count[p] != 0)
				{
					count_pen += WA_count[p];
					WA_count[p] = 0;
				}
			}
		}
		else
		{
			if (AC_count[p] != 1)
			{
				WA_count[p]++;
			}
		}
	}

	cout << count_AC << " " << count_pen;
	return 0;
}

Measured memory_bytes: 1024
#include <atcoder/all>
#include <cstdio>

using namespace std;
using namespace atcoder;
using ll = long long;

int main() {
    int n;
    scanf("%d", &n);
    if(n==1)printf("ACL");
    if(n==2)printf("ACLACL");
    if(n==3)printf("ACLACLACL");
    if(n==4)printf("ACLACLACLACL");
    if(n==5)printf("ACLACLACLACLACL");
    return 0;
}


Measured memory_bytes: 3808
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <numeric>

/* debug macros */
#ifdef WAFDAYO
#define DBG_LINE() {std::cerr<<"\e[2m[L"<<__LINE__<<"]\e[m ";}
#define DBG_PRINT(s,t,u) {std::cerr<<(s)<<" \e[2m=\e[m \e[1m"<<(t)<<"\e[m"<<(u);}
#define SELECT_7TH(x1,x2,x3,x4,x5,x6,x7,...) x7
#define dbg1(x1) DBG_PRINT(#x1,x1,std::endl)
#define dbg2(x1,x2) DBG_PRINT(#x1,x1,", ")dbg1(x2)
#define dbg3(x1,x2,x3) DBG_PRINT(#x1,x1,", ")dbg2(x2,x3)
#define dbg4(x1,x2,x3,x4) DBG_PRINT(#x1,x1,", ")dbg3(x2,x3,x4)
#define dbg5(x1,x2,x3,x4,x5) DBG_PRINT(#x1,x1,", ")dbg4(x2,x3,x4,x5)
#define dbg6(x1,x2,x3,x4,x5,x6) DBG_PRINT(#x1,x1,", ")dbg5(x2,x3,x4,x5,x6)
#define dbg(...) DBG_LINE()\
SELECT_7TH(__VA_ARGS__,dbg6,dbg5,dbg4,dbg3,dbg2,dbg1)(__VA_ARGS__)
#else
#define dbg(...) {}
#endif

/* utility functions */
struct read_item{read_item(){};
template<class T>operator T(){T t;std::cin>>t;return t;}};
char splf(int i,int n){return(i+1<n)?' ':'\n';};
template<bool up>
struct _RI{int i;_RI(int a):i(a){}
int operator*(){return i;}void operator++(){i+=(up?1:-1);}
bool operator!=(const _RI& r){return up?i<r.i:i>=r.i;}};
template<bool up>
struct _RX{_RI<up> x,y;_RI<up> begin(){return x;}_RI<up> end(){return y;}
_RX(int a,int b):x(up?a:(a-1)),y(b){}_RX(int a):_RX(up?0:a,up?a:0){}};
typedef _RX<true> range;
typedef _RX<false> revrange;

/* types and constants */
typedef int64_t i64;
typedef uint64_t u64;
// const i64 inf = (i64)1.05e18;
// const int inf = (int)1.05e9;

using namespace std;

int main() {

	const int N = read_item();
	i64 ans = 0;

	for(auto a : range(1, N)) {
		i64 w = (N - 1) / a;
		ans += w;
	}

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

	return 0;
}

/* wafdayo~~~ */


Measured memory_bytes: 3700
import java.util.Scanner;

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

       		String inputString = scanner.nextLine();

		String[] strStdIn = inputString.split(" ", 0);

		String name = null;

		if (strStdIn[1].length() == 1)  {
			name = strStdIn[1];
		} else {
			name = strStdIn[1].substring(0, 1);
		}

		System.out.println("A" + name + "C");
	}
}

Measured memory_bytes: 8916
#include <iostream>
#include <algorithm>
#include <string>
#include <list>
#include<vector>
#include <sstream>
#include <stdio.h>
#include <valarray>
#include <iomanip>
#include <unordered_set>
using namespace std;

int main(void)
{
	int A, B, C, D = 0;

	cin >> A >> B >> C >> D;

	int AtkCountA, AtkCountB = 0;

	AtkCountA = C / B;
	if (C%B!=0)
	{
		AtkCountA++;
	}

	AtkCountB = A / D;
	if (A%D != 0)
	{
		AtkCountB++;
	}


	if (AtkCountA<=AtkCountB)
	{
		cout << "Yes" << endl;

		return 0;
	}

	cout << "No" << endl;

	return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  cout << max(a+b, max(a-b, a*b)) << endl;
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define endl '\n'
#define w(t) int t;cin>>t;while(t--)
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);
#define rep(i,a,b) for(int i=a; i<b; ++i)
#define repl(i,a,b) for(ll i=a; i<b; ++i)


int main(){
	IOS

	int n;
  	cin>>n;
  	int rem = n%10;
  	if(rem == 3)
      cout<<"bon"<<endl;
  	else if(rem == 0 || rem ==1 || rem ==6 || rem ==8)
      cout<<"pon"<<endl;
  	else
      cout<<"hon"<<endl;
    
}

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

using namespace std;

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_1_D&lang=jp

int LIS(int n,vector<int> a) {
  vector<int> dp(n+1,INT_MAX);
  for(int i=0;i<n;++i) {
    *lower_bound(dp.begin(),dp.end(),a[i]) = a[i];
  }
  return lower_bound(dp.begin(),dp.end(),INT_MAX) - dp.begin();
}

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0;i<n;++i) cin >> a[i];
  cout << LIS(n,a) << endl;
  return 0;
}

Measured memory_bytes: 2060
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

// int main() {
//     ios::sync_with_stdio(false);
//     cin.tie(0);
    
//     ll n, k;
//     cin >> n >> k;
//     vi a(n);
//     rep(i, n) cin >> a[i];
//     set<int> st;
//     vi ans;
//     int now = 1;
//     while (1) {
//         now = a[now-1];
//         if (st.count(now)) {
//             ans.pb(now);
//             break;
//         } else {
//             st.insert(now);
//             ans.pb(now);
//         }
//     }
//     int s = 0;
//     rep(i, n) {
//         if (ans[i] == ans.back()) {
//             s = i;
//             break;
//         }
//     }
//     vi repeat;
//     for (int i = s; i < sz(ans) - 1; ++i) {
//         repeat.pb(ans[i]);
//     }
//     int len = sz(ans) - s - 1;
//     if (k <= s) {
//         cout << ans[k-1] << endl;
//     } else {
//         k -= s;
//         k %= len;
//         if (k == 0) cout << repeat.back() << endl;
//         else cout << repeat[k-1] << endl;
//     }
// }

// int main() {
//     int n; ll k;
//     cin >> n >> k;
//     vi a(n);
//     rep(i, n) cin >> a[i];

//     vi s;
//     vi ord(n+1, -1);
//     int c = 0, l = 0;
//     {
//         int v = 1;
//         while (ord[v] == -1) {
//             ord[v] = sz(s);
//             s.pb(v);
//             v = a[v-1];
//         }
//         c = sz(s) - ord[v];
//         l = ord[v];
//     }
//     if (k < l) {
//         cout << s[k] << endl;
//     } else {
//         k -= l;
//         k %= c;
//         cout << s[l+k] << endl;
//     }
// }

const int D = 60;
const int MAX_N = 200005;
int to[D][MAX_N];

int main() {
    int n; ll k;
    cin >> n >> k;
    rep(i, n) {
        cin >> to[0][i];
        to[0][i]--;
    }
    rep(i, D-1) rep(j, n) to[i+1][j] = to[i][to[i][j]];
    int v = 0;
    for (int i = D-1; i >= 0; --i) {
        ll l = 1LL<<i;
        if (l <= k) {
            v = to[i][v];
            k -= l;
        }
    }
    cout << v+1 << endl;
}

Measured memory_bytes: 50456
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc139_a
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            string T = Console.ReadLine();

            int OK = 0;

            if (S[0]==T[0])
            {
                OK += 1;
            }
            else
            {
                OK += 0;
            }
            if(S[1]==T[1])
            {
                OK += 1;
            }
            else
            {
                OK += 0;
            }
            if(S[2]==T[2])
            {
                OK += 1;
            }
            else
            {
                OK += 0;
            }
            Console.Write(OK);
            Console.Read();
        }
    }
}


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

using namespace std;

int main(){
    int n,l,i,j;
    cin>>n>>l;
    vector<string> s;
    string t,temp;
    for(i=0;i<n;i++){
        cin>>t;
        s.push_back(t);
    }
    sort(s.begin(),s.end());
    for(i=0;i<n;i++)
        cout<<s[i];
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	double n, w, h, x, y; cin >> w >> h >> x >> y;
	if (x * 2 == w && y * 2 == h) {
		cout << w * h / 2 << ' ' << 1 << endl;
	}
	else {
		cout << w * h / 2 << ' ' << 0 << endl;
	}
	cin >> n;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
long long a, b, c;
int main() {
	std::cin >> a >> b >> c;
	if (c - a - b <= 0) puts("No");
	else {
		if ((c - a - b) * (c - a - b) > 4 * a * b) puts("Yes");
		else puts("No");
	}
}

Measured memory_bytes: 256
/*" بِسْمِ اللهِ الرَّحْمٰنِ الرَّحِيْمِ -In the name of Allah."
   Never stop chasing!-MD.SOURAV.

   ░░░░░░░░( •̪●)░░░░░░░░░░░░░░░░░░░░░░░░
   ░░░░░░███████ ]▄▄▄▄▄▄▄▄▃░░░▃░░░░ ▃░
   ▂▄▅█████████▅▄▃▂░░░░░░░░░░░░░░░░░
   [███████████████████].░░░░░░░░░░░░░░
   ◥⊙▲⊙▲⊙▲⊙▲⊙▲⊙▲⊙◤...░░░░░░░░░░░░
*/

#include <bits/stdc++.h>

#define endl "\n"
#define MAX 32000
#define F first
#define S second
#define sz(x) x.size()
#define li long int
#define gcd(a, b) __gcd(a, b)
#define pb push_back
#define mp make_pair
#define asrt(a, n) sort(a, a + n)
#define MOD 1000000007
#define ll long long int
#define lcd(a, b) (a * b) / gcd(a, b)
#define mp(x, y) make_pair(x, y)
#define no cout << "NO" << endl
#define yes cout << "YES" << endl
#define f(i, a, n) for (int i = a; i < n; i++)
#define test  int t;cin >> t;while (t--)
#define srt(v) sort(v.begin(), v.end())
#define basrt(a, n) sort(a, a + n, greater<int>())
#define debug(x) cout << #x << ": " << x << endl;
#define sumof(x) accumulate(x.begin(), x.end(), 0);
#define rsrt(v) sort(v.begin(), v.end(), greater<int>())
#define enter(v, n) for (ll i = 0; i < n; i++) { ll x;cin >> x;v.pb(x);}
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end())
#define start  ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0)
#define ignore cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
#define deb(args...){string _s = #args;replace(_s.begin(), _s.end(), ',', ' ');stringstream _ss(_s);istream_iterator<string> _it(_ss);err(_it, args);}

using namespace std;

double pi = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664;
typedef vector<ll> vll;
typedef vector<int> vii;
typedef map<ll, ll> mllll;
typedef map<char, ll> mchll;
typedef map<string, ll> msll;
typedef vector<pair<ll, ll>> vpllll;
typedef vector<pair<int, int>> vpiiii;

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '{';
    for (const auto &x : v)
        os << " " << x;
    return os << '}';
}

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


void solve()
{

    int n;
    cin>>n;
    for(int i=0;i<n;i++)
	{
		cout << "ACL";
	}

}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll test_case;
    test_case = 1;
    //cin>>test_case;
    while (test_case--)
    {
        solve();

    }

    return 0;
}

Measured memory_bytes: 3568
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <map>
#include <cmath>
using namespace std;

typedef long long ll;

#define rep(i, n) for(ll i=0; i<n; ++i)

//--------------------

bool func(int p[], int n) {

  for(int i=0; i<n-1; ++i) {
    for(int j=n-1; j>i; j--) {
      if(p[j-1]>p[j]) return false;
    }
  }

  return true;
}


int main() {

  int n;
  cin >> n;
  int p[n];
  rep(i, n) cin >> p[i];

  if(func(p, n)) {
    cout << "YES" << endl;
    return 0;
  }

  for(int i=0; i<n; ++i) {
    for(int j=i+1; j<n; ++j) {
      if(p[i]>p[j]) {
        swap(p[i], p[j]);
        if(func(p, n)) {
          cout << "YES" << endl;
          return 0;
        }
        swap(p[i], p[j]);
      }
    }
  }

  cout << "NO" << endl;

  return 0;
}


Measured memory_bytes: 256
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;

long long a,v,b,w,t;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    cin >> a >> v >> b >> w >> t;
    if (v <= w) {
        cout << "NO" << endl;
        return 0;
    }

    long long vel = v - w;
    long long dist = abs(a - b);
    long long nt = (dist + vel - 1) / vel;

    cout << (nt <= t ? "YES" : "NO") << endl;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define MAXN 200005 
using namespace std;

string s;
const int C = 8005;
int tx,ty;

bool dp[2][MAXN], temp[2][MAXN];

void work(int x, bool f){
	memset(temp, 0, sizeof(temp));
	for(int j=0;j<=2*C;j++){
		if(j-x>=0) temp[0][j] = dp[f][j-x];
		if(j+x<=2*C) temp[1][j] = dp[f][j+x];
	}
	
	for(int j=0;j<=2*C;j++){
		dp[f][j] = (temp[0][j] | temp[1][j]);
	}
}

int main(){
	
	cin>>s;
	cin>>tx>>ty;
	
	bool f = 0, f0 = 1;
	int cnt = 0;
	dp[1][C] = 1;
	for(int i=0;i<s.length();i++){
		if(s[i]=='F'){
			++cnt;
			if(i < s.length()-1) continue;
		}
		 
		if(f0){
			dp[f][cnt+C] = 1;
			f ^= 1;
			cnt = 0;
			f0 = 0;
		}
		else{
			work(cnt, f);
			f ^= 1;
			cnt = 0;
		}
	}
	
	if(dp[0][tx+C] && dp[1][ty+C]) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 640
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = 1; i < (int)(n); i++) 
#define dunk(n) cout << n << endl
#define all(a) (a).begin(),(a).end()
typedef pair<int,int> P;
typedef long long ll;

int main() {
    int n,m;
    cin >> n >> m;
    vector<int> day(m);
    rep(i,m) cin >> day[i];
    int ans = n;
    rep(i,m){
        ans -= day[i];
    }
    if(ans >= 0) dunk(ans);
    else dunk(-1);
    return 0;
}

Measured memory_bytes: 3636