akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

struct ST {
  int i;
  int l, r;
  int orig_l, orig_r;
};

vector<ST> G[100005];
bool visited[100005];
bool use[200005];

int dfs(int v, const string& T){
  visited[v] = true;

  int cnt = (int)(T[v]-'0');
  rep(i,G[v].size()){
    if(visited[G[v][i].r]) continue;
    int res = dfs(G[v][i].r, T);
    if(res == 1) use[G[v][i].i] = true;
    cnt += res;
  }

  return cnt%2;
}

void solve(const vector<pair<int,int>>& v, const vector<ST>& w){
  string S = "0";
  rep(i,v.size()){
    if(v[i].second == 1) S += "1";
    else S += "0";
  }
  S += "0";

  string T = "";
  rep(i,S.size()-1){
    if(S[i] == S[i+1]) T += "0";
    else T += "1";
  }

  rep(i,w.size()){
    ST st = w[i];
    st.r++;
    G[st.l].push_back(st);
    swap(st.l, st.r);
    G[st.l].push_back(st);
  }

  rep(i,T.size()){
    if(visited[i]) continue;
    if(dfs(i, T) != 0){
      cout << -1 << endl;
      return;
    }
  }

  vector<int> ret;
  rep(i,200005){
    if(use[i]) ret.push_back(i);
  }

  cout << ret.size() << endl;
  rep(i,ret.size()){
    if(i>0) cout << " ";
    cout << ret[i];
  }
  cout << endl;
}

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

  vector<pair<int,int>> v;
  rep(i,N){
    int a, b;
    cin >> a >> b;
    v.emplace_back(a,b);
  }
  sort(ALLOF(v));


  vector<ST> w;
  rep(i,M){
    int l, r;
    cin >> l >> r;

    int lidx = -1, ridx = v.size();
    {
      int lb=-1,ub=v.size()+1;
      while(ub-lb>1){
        int mid = (lb+ub)/2;
        if(mid<0) lb = mid;
        else if(mid>=v.size()) ub = mid;
        else{
          if(v[mid].first < l) lb = mid;
          else ub = mid;
        }
      }
      lidx = ub;
    }
    {
      int lb=-1,ub=v.size()+1;
      while(ub-lb>1){
        int mid = (lb+ub)/2;
        if(mid<0) lb = mid;
        else if(mid>=v.size()) ub = mid;
        else{
          if(v[mid].first <= r) lb = mid;
          else ub = mid;
        }
      }
      ridx = lb;
    }

    if(lidx > ridx) continue;
    w.push_back((ST){i+1,lidx,ridx,l,r});
  }
  
  solve(v, w);

  return 0;
}



Measured memory_bytes: 27368
#include<bits/stdc++.h>
	using namespace std;
	
	int main(){
      int Num, X, Dt, i, S;
      cin >> Num >> X;
      for (i = 0 ; i < Num ; i++){
        cin >> Dt ;
        if (Dt <=  X - Dt ){
        S += Dt * 2;
       }
        else {
        S += (X - Dt) * 2;
       }
      }
       cout << S << endl;
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MX 20000
using namespace std;
typedef long long lnt;
template <class T> inline void read(T &x) {
	x = 0; int c = getchar(), f = 1;
	for (; !isdigit(c); c = getchar()) if (c == 45) f = -1;
	for (; isdigit(c); c = getchar()) (x *= 10) += f*(c-'0');
}
int n; lnt f[MX+5], mx;
struct node {int w, s, v;} a[1005];
bool cmp(const node &x, const node &y) {return x.w+x.s < y.w+y.s;}
int main() {
	read(n);
	for (int i = 1; i <= n; i++)
		read(a[i].w), read(a[i].s), read(a[i].v);
	sort(a+1, a+n+1, cmp);
	for (int i = 1; i <= n; i++)
		for (int j = min(a[i].s+a[i].w, MX); j >= a[i].w; j--)
			f[j] = max(f[j], f[j-a[i].w]+a[i].v), mx = max(mx, f[j]);
	return printf("%lld\n", mx), 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner((System.in));
		int N = sc.nextInt();
		int[] a = new int[N];
		long x = 0, y = 0, min = 0;

		for (int i = 0; i < N; i++) {
			a[i] = sc.nextInt();
			y += a[i];
		}
		
		x += a[0];
		y -= a[0];
		min = Math.abs(x - y);
		
		for (int i = 1; i < N - 1; i++) {
			x += a[i];
			y -= a[i];
			if (Math.abs(x - y) < min) {
				min = Math.abs(x - y);
			}
		}

		System.out.println(min);

		sc.close();
	}
}


Measured memory_bytes: 83788
///   ***   ---   |||         In the name of ALLAH        |||   ---   ***   ///



#include<bits/stdc++.h>
using namespace std;


typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef double dl;

#define endl '\n'
#define PB push_back
#define F first
#define S second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define sz(x) (int)x.size()

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007

#define mem(a,b) memset(a, b, sizeof(a) )
#define sqr(a) ((a) * (a))

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu () {            cerr << endl;}
template < typename T, typename ... hello>void faltu( T arg, const hello &... rest) {cerr << arg << ' ';faltu(rest...);}


int main()
{
    optimize();

    int n;
    cin >> n;
    string s, t, ans;
    cin >> s >> t;

    for ( int i = 0; i < sz ( s ); i++ ) {
        ans += s[i];
        ans += t[i];
    }

    cout << ans << endl;


    return 0;
}


















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

int N , ptr , res ;
int A [100000];
int main ()
{
  cin >> N;//数字を言う回数
  for ( int i = 0; i < N ; i ++) cin >> A[i];
  sort (A , A + N );
  while ( ptr < N ){
    //入力した数字をソートして左から順にみて、奇数回登場する数が何種類あるかを数える
    int cc = A [ ptr ] , f = 0;//ptr=参照する数字の序数詞,f=その数字が出現する回数
    while ( ptr < N && A [ ptr ] == cc ) {
      f ++ , ptr ++;
    }
    res = res + f % 2;//res=ゲーム終了時に書かれている数字の個数
  }
  cout << res << endl;
}


Measured memory_bytes: 640
import java.util.Arrays;
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		String[] value = scan.nextLine().split(" ");
		int n   = Integer.parseInt(value[0]);
		int k 	 = Integer.parseInt(value[1]);
		long count = 0;
		double temp  = 0;
		double ans = 0;
		double x = 0;

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

			temp = i;
			count = n;

			while(temp < k) {
				temp  *= 2;
				count *= 2;
			}

			ans += 1 / (double)count;

		}

		System.out.println(ans);

	}

}


Measured memory_bytes: 23252
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
ll i, temp,t, n,ans,d, x[200600], y[200600];
map<pair<ll, ll>, bool>P;
int main()
{
    //I am Monim, a tiny creature of Allah
    cin >> n >> d;
    for(i=0;i<n;i++)
        cin >> x[i] >> y[i];
    for(i=0;i<n;i++)
    {
        temp = x[i]*x[i] + y[i]*y[i];
        if(x[i]*x[i]+y[i]*y[i]<=d*d)
            ans++;
    }
    cout << ans <<endl;
    return 0;
}



Measured memory_bytes: 6720
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll N, R;
    cin >> N >> R;
    if(N >= 10) cout << R << endl;
    else cout << R + 100 * (10 - N) << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    long[] t = new long[N];
    long[] a = new long[N];
    for(int i = 0; i < N; i++) {
      t[i] = sc.nextLong();
      a[i] = sc.nextLong();
    }
    // (i+1)回目の最小票数を(t[i]*dp[i],a[i]*dp[i])とする
    long[] dp = new long[N];
    dp[0] = 1;
    for(int i = 1; i < N; i++) {
      long takahashi = (t[i - 1] * dp[i - 1] + t[i] - 1) / t[i];
      long aoki = (a[i - 1] * dp[i - 1] + a[i] - 1) / a[i];
      dp[i] = Math.max(takahashi, aoki); 
    }
    System.out.println((t[N - 1] + a[N - 1]) * dp[N - 1]);
  }
}

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

#define rep(i, n) for(int i=0; i<n; ++i)
#define repit(it, li) for(auto it=li.begin(); it!=li.end(); it++)
#define ll long long int

int main(){
    int ans;
    rep(i, 5){
        int x;
        cin>>x;
        if(x==0){
            ans=i;
        }
    }

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


Measured memory_bytes: 3520
#include <vector>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
using namespace std;

int main(){
    string a;
    cin >>a;
    vector<int>x;
    vector<int>y;
    for(int i=0;i<a.length();i++){
        if(a[i]=='A'){
            x.push_back(i);
        }
        if(a[i]=='Z'){
            y.push_back(i);
        }
    }
    cout << y[y.size()-1]-x[0]+1;
}

Measured memory_bytes: 1364
#include <stdio.h>

int main(void)
{
	int n1,h,m,s;
	
	scanf("%d",&n1);
	h=n1/3600;
	m=n1%3600/60;
	s=n1%3600%60;
	
	printf("%d:%d:%d\n",h,m,s);
	
	return 0;
}

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

int main() {
  int A, B, C; cin >> A >> B >> C;
  if (A == B && A != C) cout << "Yes" << endl;
  else if (A == C && A != B) cout << "Yes" << endl;
  else if (B == C && A != B) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include<iostream>
 
using namespace std;
 
int main(){
	long  n;
	string s;
	cin >> n;
	cin >> s;
	
	int tmp_min,min = 0;
	int x, y = 0;
	for(long  i=1;i<n;i++){
		if(s[i]!='W')y++;
	}
  	tmp_min = y;
  	min = y;
//	cout << "first: " << tmp_min << endl;
	char pre_L = s[0];
	char L;
	for(long i=1;i<n;i++){
		L = s[i];
		if(pre_L=='W')tmp_min++;
		if(L=='E')tmp_min--;
		pre_L=L;
//		cout << "tmp: " << tmp_min  <<"  "<<min<< endl;
		if(min>tmp_min)min=tmp_min;
    }
	
	cout << min;
	return 0;
}

Measured memory_bytes: 900
class List
  def initialize
    @head = Node.new
    @tail = Node.new(@head)
    @head.nxt = @tail
  end

  def insert(val)
    nxt_old = @head.nxt
    node = Node.new(@head, nxt_old, val)
    @head.nxt = node
    nxt_old.prv = node
  end

  def delete(val)
    node = @head.nxt
    while node.val
      if node.val == val
        node.prv.nxt = node.nxt
        node.nxt.prv = node.prv
        return
      end
      node = node.nxt
    end
  end

  def delete_first
    raise 'List is mpety.' if @head.nxt == @tail
    @head.nxt = @head.nxt.nxt
    @head.nxt.prv = @head
  end

  def delete_last
    raise 'List is mpety.' if @head.nxt == @tail
    @tail.prv = @tail.prv.prv
    @tail.prv.nxt = @tail
  end

  def to_s
    vals = []
    node = @head.nxt
    while node.val
      vals << node.val
      node = node.nxt
    end
    vals.join(' ')
  end

  class Node
    attr_accessor :prv, :nxt, :val
    def initialize(prv = nil, nxt = nil, val = nil)
      @prv = prv
      @nxt = nxt
      @val = val
    end
  end
end

list = List.new

STDIN.read.split(/\n/)[1..-1].each do |line|
  ary = line.split(/\s/)
  command = ary[0]
  #start = Time.now
  case command
  when 'insert' then
    list.insert ary[1].to_i
  when 'delete' then
    list.delete ary[1].to_i
  when 'deleteFirst' then
    list.delete_first
  when 'deleteLast' then
    list.delete_last
  end
end
puts list.to_s

Measured memory_bytes: 409836
#include<bits/stdc++.h>
using namespace std;
long long s[1000005],s1[1000005];
long long sum=0;
int main(){
	int i,j,l;
	int a,b,n;
	scanf("%d",&n);
	for(i=0;i<n+1;i++){
		scanf("%lld",&s[i]);
	}
	for(i=0;i<n;i++){
		scanf("%lld",&s1[i]);
	}
	for(i=0;i<n;i++){
		
		
		if(s1[i]>s[i]){
			
			if(s[i+1]>(s1[i]-s[i])){
				sum=sum+s1[i];
				s[i+1]=s[i+1]-s1[i]+s[i];
			}
			else{
				sum=sum+s[i+1]+s[i];
				s[i+1]=0;
			} 
			
		}
		else sum=sum+s1[i];
	}
	printf("%lld",sum);
	return 0;
}

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

using ll = long long;
using ull = unsigned long long;
const int INF = 1e9;
const ll MOD = 1e9+7;

ll k,a,b;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> k >> a >> b;

  if (a >= b) {
    cout << k+1 << endl;
    return 0;
  }

  ll cnt = max(0LL, (k+1-a)/2);
  cout << max(k-2*cnt+1 - a*cnt + b*cnt, k+1) << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll read(){
	ll a=0,b=getchar(),c=1;
	while(!isdigit(b))c=b=='-'?-1:1,b=getchar();
	while(isdigit(b))a=a*10+b-'0',b=getchar();
	return a*c;
}
int n,m,q,a[55],b[55],c[55],d[55],e[55];
int gg(){
	int ans=0;
	for(int i=0;i<q;i++){
		if(e[b[i]-1]-e[a[i]-1]==c[i])
			ans+=d[i];
	}
	return ans;
}
int dfs(int i,int y){
	if(y==n)return gg();
	if(i==m)return 0;
	int ans=dfs(i+1,y);
	e[y]=i+1;
	ans=max(ans,dfs(i,y+1));
	return ans;
}
int main(){
	cin >> n >> m >> q;
	for(int i=0;i<q;i++)
		cin >> a[i] >> b[i] >> c[i] >> d[i];
	cout << dfs(0,0);
	return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>

using namespace std;
typedef long long ll;

ll a = 0, b = 0, c = 0;

int main() {
	cin >> a >> b >> c;
	if (a < b && b < c) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 3088
# """
# コンプリートするものと、せざるものに分ける
# コンプリートしないものに関しては、得点の高い方から一個だけ潰す
# """

D, G = map(int, input().split())
ps_ini,cs = [], []
for i in range(D):
    p,c = map(int,input().split())
    ps_ini.append(p)
    cs.append(c)

q_min = 1000000
for i in range(2**D):
    Gtmp = G
    ps = [p for p in ps_ini]
    s = "{:010b}".format(i)[::-1]
    q_all = 0
    for j,(p,c) in enumerate(zip(ps,cs)):
        # ボーナスの考慮
        Gtmp -= (p*(j+1)*100+c)*int(s[j]) 
        q_all += p*int(s[j])
        ps[j] -= p*int(s[j])
    # print(s,ps)
    if Gtmp <= 0:
        q_min = min(q_min, q_all)
    else:
        # コンプしていない問題で一番大きいやつ
        ind = 0
        for i,p in enumerate(ps):
            if p != 0:
                ind = i
        # print(Gtmp,ind,Gtmp//((ind+1)*100))
        # 比較
        if Gtmp//((ind+1)*100) > ps[ind]:
            continue
        if Gtmp%((ind+1)*100) == 0:           #割り切れない
            q_all += (Gtmp//((ind+1)*100))
        else:                           #割り切れる
            q_all += (Gtmp//((ind+1)*100) + 1) #最大値をコンプする以外ありえん
        q_min = min(q_min, q_all)
print(q_min)

Measured memory_bytes: 3188
#include <cstring>
#include <iostream>
#include <limits>

struct edge {
  int from, to;
  long long cost;
};

edge e[1000 * 999];

long long d[1001];


long long finf;

int main(int argc, char const* argv[]) {
  using namespace std;

  int n, m;

  cin >> n;
  cin >> m;

  finf = std::numeric_limits<long long>::min();

  for (int i = 0; i < m; i++) {
    cin >> e[i].from;
    cin >> e[i].to;
    cin >> e[i].cost;
  }

  for (int i = 0; i < n + 1; i++) {
    d[i] = finf;
  }
  d[1] = 0;

  for (int i = 0; i < n + 1; i++) {
    for (int j = 0; j < m; j++) {
      if (d[e[j].from] != finf && d[e[j].to] < d[e[j].from] + e[j].cost) {
        d[e[j].to] = d[e[j].from] + e[j].cost;
      }
    }
  }

  long long ans = d[n];

  for (int i = 0; i < n + 1; i++) {
    for (int j = 0; j < m; j++) {
      if (d[e[j].from] != finf && d[e[j].to] < d[e[j].from] + e[j].cost) {
        d[e[j].to] = d[e[j].from] + e[j].cost;
      }
    }
  }

  if (ans == d[n])
    cout << ans << endl;
  else
    cout << "inf" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>

 

using namespace std;

 

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if (a < b && b < c)
      cout << "Yes" << endl;
    else if (a > b && b > c)
      cout << "Yes" << endl;
      else
      cout << "No" << endl;    
}
 


Measured memory_bytes: 3116
/*  -*- coding: utf-8 -*-
 *
 * c.cc: C - Sum of gcd of Tuples (Easy)
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

template <typename T>
T gcd(T m, T n) {  // m > 0, n > 0
  if (m < n) swap(m, n);
  while (n > 0) {
    T r = m % n;
    m = n;
    n = r;
  }
  return m;
}

/* main */

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

  int sum = 0;
  for (int a = 1; a <= k; a++)
    for (int b = 1; b <= k; b++) {
      int gab = gcd<int>(a, b);
      for (int c = 1; c <= k; c++) {
	int g = gcd<int>(gab, c);
	sum += g;
      }
    }

  printf("%d\n", sum);
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<long long> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }

  sort(v.begin(), v.end());
  long long ans = v[0];
  long long ansid = 0;
  while (true) {
    long long cnt = 0;
    for (int i = 0; i < n; i++) {
      if (v[i] > 0) {
        cnt++;
      }
      if (cnt == 1) {
        ans = v[i];
        ansid = i;
      }
    }
    if (cnt == 1) {
      break;
    }

    for (int i = 0; i < n; i++) {
      if (v[i] > 0 && ansid != i) {
        long long x = v[i]/ans;
        v[i] -= x*ans;
      }
    }

    sort(v.begin(), v.end());
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
n,k=map(int,input().split())
A=list(map(int,input().split()))
d={}
for a in A:
    if a in d:
        d[a]+=1
    else:
        d[a]=1
D=sorted(d.items(), key=lambda x:x[1], reverse=True)
if len(set(A))>k:
    for i in range(k):
        n-=D[i][1]
    print(n)
else:
    print(0)

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

int main()
{
  int n; cin >> n;
  vector<ll> a(n); rep(i,n) cin >> a[i];
  bool flg = true;
  //e+e=e o+o=e
  rep(i,n){
    if(a[i]%2==1) flg = !flg;
  }
  if(flg) cout << "YES" << endl;
  else cout << "NO" << endl;  
  return 0;
}



Measured memory_bytes: 3988
#include <bits/stdc++.h>
#define FAST_INPUT ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long

using namespace std;

void solve() {
	int N, W; cin >> N >> W;
	vector<ll> w(N), v(N);
	for (int i = 0; i < N; i++) {
		cin >> w[i] >> v[i];
	}
	vector<vector<ll>> dp(N + 1, vector<ll>(W + 1, 0));

	for (int i = 1; i <= N; i++) {
		for (int j = 0; j <= W; j++) {
			if (!i || !j) {
				dp[i][j] = 0;
			} else if (j - w[i - 1] >= 0) {
				dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i - 1]] + v[i - 1]);
			} else {
				dp[i][j] = dp[i - 1][j];
			}
		}
	}

	ll res = 0;
	for (int i = 0; i <= W; i++) {
		res = max(res, dp[N][i]);
	}

	cout << res << endl;
}

int main() {
    FAST_INPUT;

    solve();

    return 0;
}


Measured memory_bytes: 80256
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
 
int main(){
  ll int a, b;
  ll int c, d;
  cin >> a >> b >> c >> d;
  ll int cd = lcm(c, d);
  ll int cc = (b / c) - ((a-1)/c);
  ll int dd = (b / d) - ((a-1)/d);
  ll int ccdd = (b / cd) - ((a-1)/cd);
  cout << (b-a+1)-(cc+dd-ccdd) << endl;

}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
#define INF 100000000
#define fi first
#define se second
const int LEN = 2e5+5;
typedef long long ll;
int n, dp[LEN]; int k;
int main() {

   // freopen ("myfile.txt","r",stdin);
   // freopen ("myfile.txt","w",stdout);

   // ios_base::sync_with_stdio(0); cin.tie(NULL);
   scanf("%d%d",&n,&k);
   int ar[LEN];
   for(int i =0;i<n;i++) {
   		scanf("%d",&ar[i]);
   }

   dp[0] = 0;
   dp[1] = abs(ar[1]-ar[0]);
   for(int i =2;i<n;i++) {
   		dp[i] = INT_MAX;
   		for(int j = 1;j<=k;j++) {
   			if(i - j < 0) break;
   			dp[i] = min(dp[i],dp[i-j] + abs(ar[i]-ar[i-j]));
   		}
   }
   cout<<dp[n-1]<<endl;
}   

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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

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

    int n;
    cin >> n;
    vector<int> a(n), b(n);
    vector<P> v;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i] >> b[i];
        v.emplace_back(b[i], i);
    }
    sort(v.begin(), v.end());
    bool f = true;
    ll pass = 0;
    for (int i = 0; i < n; i++)
    {
        int dl = v[i].first, index = v[i].second;
        if (pass + a[index] > dl)
        {
            f = false;
            break;
        }
        pass += a[index];
    }
    cout << (f ? "Yes" : "No") << endl;
}


Measured memory_bytes: 3956
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

int L;
int calc(vector<char> a, vector<char> b) {
  int aa = 0, bb = 0;
  for(int i = L - 1; i >= 0; i--) {
    aa += a[i] * pow(10, L - 1 - i);
    bb += b[i] * pow(10, L - 1 - i);
  }
  return aa - bb;
}

vector<char> i2vc(int x) {
  vector<char> ret(L, '0');
  for(int i = L - 1; i >= 0; i--) {
    ret[i] = to_string(x % 10)[0];
    x /= 10;
  }
  return ret;
}

int main()
{
  int aa;
  while(cin >> aa >> L, aa || L) {
    map<int, int> MAP;
    MAP[aa] = 0;
    string a = to_string(aa);
    vector<char> A(L, '0');
    FOR(i,0,a.length()) A[i] = a[i];
    FOR(i,1,21) {
      vector<char> mx = A, mn = A;
      sort(mx.rbegin(), mx.rend());
      sort(mn.begin(), mn.end());
      int sa = calc(mx, mn);
      A = i2vc(sa);
      if(MAP.count(sa)) {
        cout << MAP[sa] << " " << sa << " " << i - MAP[sa] << endl;
        break;
      } else MAP[sa] = i;

    }
  }
  return 0;
}

Measured memory_bytes: 3416
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    int X,T;
    R(X,T);
    W(X*1./T);
    return 0;
}


Measured memory_bytes: 256
N = int(input())
# = map(int, input().split())
a = list(map(int, input().split()))
# = [int(input()) for i in range(N)]
# = [list(map(int, input().split())) for i in range(N)]
counter = a[0]^a[1]
answer = []

for i in range(2, N):
    counter = counter^a[i]

for i in range(N):
    answer.append(counter^a[i])

test = map(str, answer)

result = ' '.join(test)
print(result)


Measured memory_bytes: 41780
//Himanshu Shukla
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
//#define multitest
#define ll long long
#define v32 vector<int>
#define v64 vector<ll>
#define s32 set<int>
#define s64 set<ll>
#define p32 pair<int, int>
#define p64 pair<ll, ll>
#define sz(v) (ll)(v).size()
#define fi first
#define se second
#define ln '\n'
#define debug(x) cerr << (#x) << ": " << (x) << ln
inline ll add(ll a, ll b, ll m)
{
	return (((a % m + b % m) % m + m) % m);
}
inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }
const ll MOD = 1e9 + 7;
template <typename T, typename U>
ostream &operator<<(ostream &out, const pair<T, U> &p)
{
	out << '[' << p.fi << ", " << p.se << ']';
	return out;
}
template <template <typename, typename...> class ContainerType, typename ValueType, typename... Args>
void print_container(const ContainerType<ValueType, Args...> &c)
{
	cout << "{ ";
	for (const auto &v : c)
		cout << v << ' ';
	cout << '}' << ln;
}

const int N = 2e5 + 5;
ll sz[N], dp[N], fact[N], ifact[N], inv[N], res[N];

void pre()
{
	inv[1] = fact[0] = fact[1] = ifact[0] = ifact[1] = 1;
	for (int i = 2; i < N; i++)
	{
		inv[i] = mul(MOD - MOD / i, inv[MOD % i], MOD);
		fact[i] = mul(fact[i - 1], i, MOD);
		ifact[i] = mul(inv[i], ifact[i - 1], MOD);
	}
}

ll fp(ll x, ll y)
{
	if (y == 0)
		return 1;
	ll t = fp(x, y / 2);
	t = mul(t, t, MOD);
	if (y & 1)
		return mul(t, x, MOD);
	else
		return t;
}

void dfs1(int src, int par, vector<v32> &g)
{
	sz[src] = 1;
	for (auto jj : g[src])
	{
		if (jj != par)
		{
			dfs1(jj, src, g);
			sz[src] += sz[jj];
		}
	}
	return;
}

ll dfs2(int u, int par, vector<v32> &g)
{
	dp[u] = 1;
	for (auto v : g[u])
		if (v != par)
		{
			dp[u] = mul(dp[u], dfs2(v, u, g), MOD);
			dp[u] = mul(dp[u], ifact[sz[v]], MOD);
		}
	dp[u] = mul(dp[u], fact[sz[u] - 1], MOD);
	return dp[u];
}

void dfs3(int u, int p, vector<v32> &g, int n)
{
	ll ans = 1;
	if (p != -1)
	{
		ll temp = 1;
		temp = mul(temp, res[p], MOD);
		temp = mul(temp, fact[sz[u]], MOD);
		temp = mul(temp, fact[n - sz[u] - 1], MOD);
		temp = mul(temp, ifact[n - 1], MOD);
		temp = mul(temp, fp(dp[u], MOD - 2), MOD);
		for (auto v : g[u])
		{
			if (v != p)
			{
				temp = mul(temp, dp[v], MOD);
				temp = mul(temp, ifact[sz[v]], MOD);
			}
		}
		temp = mul(temp, fact[n - 1], MOD);
		temp = mul(temp, ifact[n - sz[u]], MOD);
		res[u] = temp;
	}
	for (auto v : g[u])
	{
		if (v != p)
			dfs3(v, u, g, n);
	}
}

void solve()
{
	int n;
	cin >> n;
	vector<v32> g(n + 1, v32());
	pre();
	int u, v;
	for (int i = 0; i < n - 1; i++)
	{
		cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dfs1(1, -1, g);
	dfs2(1, -1, g);
	res[1] = dp[1];
	dfs3(1, -1, g, n);
	for (int i = 1; i < n + 1; i++)
		cout << res[i] << ln;
	return;
}

int main()
{
	FASTIO;
	int t = 1;
#ifdef multitest
	cin >> t;
#endif
	for (int tc = 1; tc < t + 1; tc++)
		solve();
	return 0;
}


Measured memory_bytes: 23284
import sys
input = sys.stdin.readline
h, w, d = map(int, input().split())
a = {}
l = list(range(1, h * w + 1))
for i in range(h):
  for j, x in enumerate(input().split()):
    a[int(x)] = (i, j)
memo = {}
def calc(s):
  tmp = 0
  memo[a[s+1]] = 0
  for Xc, Xn in zip(l[s::d], l[s+d::d]):
    xc, yc = a[Xc]
    xn, yn = a[Xn]
    tmp += abs(xc - xn) + abs(yc - yn)
    memo[a[Xn]] = tmp
for i in range(d):
  calc(i)
for _ in range(int(input())):
  l, r = map(int, input().split())
  print(memo[a[r]] - memo[a[l]])


Measured memory_bytes: 38200
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int n, a[4][13], p[10], z; char c; pair<int, int> s[5]; string s1 = "A23456789TJQK", s2 = "SCHD";
int judge() {
	vector<int> v; int w = 1;
	for (int i = 1; i < 5; i++) {
		if (s[i].first != s[i - 1].first) v.push_back(w), w = 0;
		w++;
	}
	v.push_back(w);
	sort(v.begin(), v.end());
	if (v.back() == 4) return 7;
	if (v.back() == 3 && v.size() == 2) return 6;
	int f = 1, g = 1, h = 1;
	for (int i = 1; i < 5; i++) {
		if (s[i].second != s[i - 1].second) f = 0;
	}
	for (int i = 1; i < 5; i++) {
		if (s[i - 1].first + 1 != s[i].first) g = 0;
	}
	for (int i = 0; i < 5; i++) {
		if (s[i].first != (i ? (i + 8) % 13 : 0)) h = 0;
	}
	if (f) {
		if (h) return 9;
		if (g) return 8;
		return 5;
	}
	if (g | h) return 4;
	if (v.back() == 3) return 3;
	if (v.back() == 2 && v[v.size() - 2] == 2) return 2;
	if (v.back() == 2) return 1;
	return 0;
}
int main() {
	while (cin >> n) {
		if (z++) cout << endl;
		for (int i = 0; i < 4; i++) {
			for (int j = 0; j < 13; j++) cin >> a[i][j];
		}
		for (int i = 1; i < 10; i++) cin >> p[i];
		for (int i = 0; i < n; i++) {
			int cnt = 0;
			for (int j = 0; j < 5; j++) {
				cin >> c; s[j].first = s1.find(c);
				cin >> c; s[j].second = s2.find(c);
				cnt += a[s[j].second][s[j].first];
			}
			sort(s, s + 5);
			cout << cnt * p[judge()] << endl;
		}
	}
}

Measured memory_bytes: 3016
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <climits>
#include <cmath>
#include <cfloat>

using namespace std;

stack<int> st;
queue<int> qu;
int a;

int main()
{
	while(cin >> a, !cin.eof())
	{
		
		if( a == 0 )
		{
			qu.push(st.top());
			st.pop();
		}
		else
			st.push(a);
	}
	
	while(!qu.empty())
	{
		cout << qu.front() << endl;
		qu.pop();
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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 (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}

int main() {
  int N,A,B;
  cin>>N>>A>>B;
  cout<<min(A,B)<<" "<<max(0,(A+B)-N)<<endl;
  return 0;
}

Measured memory_bytes: 3552
#include<bits/stdc++.h>
using namespace std;
long long a[100010];
long long n,x;
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin>>n>>x;
	for(long long i=0;i<n;i++)cin>>a[i];
	long long ans=0;
	for(long long i=0;i<n-1;i++){
		if((a[i]+a[i+1])>x){
			ans+=(a[i+1]+a[i])-x;
			if((a[i+1]+a[i])-x<=a[i+1])a[i+1]=a[i+1]-((a[i]+a[i+1])-x);
			else{
				a[i+1]=0;
				a[i]=a[i]-((a[i-1]+a[i])-x); 
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define Abs(x)((x) < 0 ? (x) * -1 : (x))

#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y) - 1; 0 <= (x); (x)--)
#define nepi(x, y, z) for ((x) = (y) - 1; (z) <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repis(x, y, z, s) for ((x) = (z); (x) < (y); (x) += (s))
#define repiins(x, y, z, s) for ((x) = (z); (x) <= (y); (x) += (s))
#define repit(x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define nepit(x) for (__typeof((x).rbegin()) it = (x).rbegin(); it != (x).rend(); it++)

#define All(x) (x).begin(),(x).end()

#define Mem0(x) memset(x, 0, sizeof(x))
#define Mem1(x) memset(x, -1, sizeof(x))

#define Unique(v) v.resize(unique(All(v)) - v.begin())

#define peq(p0, p1)(p0.first == p1.first && p0.second == p1.second)

#define End '\n'
#define Out(x) cout<<(x)<<End
#define OutP(p, sep, end) cout<<p.first<<sep<<p.second<<end

template<typename T> inline bool Max(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool Min(T &x, const T &y) { return x > y ? x = y, 1 : 0; }
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T> >;

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define lb std::lower_bound
#define ub std::upper_bound

#define lbi(v, x) lb(All(v), (x))-v.begin()
#define ubi(v, x) ub(All(v), (x))-v.begin()

static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;

#define LOCAL 0

int main()
{
#if LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif

    cin.tie(0);
    ios::sync_with_stdio(false);
	//std::cout.precision(18);

    int n, a, b;

	cin >> n >> a >> b;

	cout << min(a, b) << " " << max(0, min(a, b) - (n - max(a, b))) << End;
	
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  char a,b;
  scanf("%c %c",&a,&b);
  if(a=='H'&& b=='H') puts("H");
  if(a=='H' && b=='D') puts("D");
  if(a=='D' && b=='H') puts("D");
  if(a=='D' && b=='D') puts("H");
  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#define DATA_SIZE 100
int main(void)
{
  int a, b;
  char op;

  while (1) {
	scanf("%d %c %d", &a, &op, &b);

	if(op == '?') { break;}
	switch (op) {
	case '+':
	  printf("%d\n", a + b);
	  break;
	case '-':
	  printf("%d\n", a - b);
	  break;
	case '*':
	  printf("%d\n", a * b);
	  break;
	case '/':
	  printf("%d\n", a / b);
	  break;
	}
  }

  return 0;
}

Measured memory_bytes: 600
S = input()

ans = 0
numOperations = 0
# 先頭を1にする場合
for i in range(len(S)):
    if i%2 == 0 and S[i] == '0': numOperations += 1
    if i%2 == 1 and S[i] == '1': numOperations += 1
ans = numOperations    

numOperations = 0
# 先頭を0にする場合
for i in range(len(S)):
    if i%2 == 0 and S[i] == '1': numOperations += 1
    if i%2 == 1 and S[i] == '0': numOperations += 1
 
print( min(ans, numOperations) )

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N;
    cin >> N;
    int i = 0;
    long long S = 1;
    while(i < N){
        if(S * (N-i) >1000000007) S = S * (N-i) % 1000000007;
        else S *= (N-i);
        i++;
    }
    cout << S << endl;
}


Measured memory_bytes: 256
// Author : Chi
// created : 2020-05-24 Sunday

//header files
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

//macros
#define ll 		    long long
#define ss          second
#define ff          first
#define vi          vector<int>
#define vll         vector<long long>
#define pb          push_back
#define TEST  	    int TesT;cin>>TesT;while(TesT--)solve();
#define TEST1       solve();
#define mod         1000000007
#define r0n(i,n)    for(ll i = 0; i < n; ++i)
#define r1n(i,n)    for(ll i = 1; i <= n; ++i)
#define CHI         ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
//namespaces
using    namespace __gnu_pbds;
using    namespace std;

typedef tree <int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update > ordered_set;
void solve(){
    int n,m;
    cin>>n>>m;
    string s[n];
    for(int i=0;i<n;i++)    cin>>s[i];
    int ans[n][m];
    memset(ans,0,sizeof ans);
    ans[0][0]=1;
    r0n(i,n){
        r0n(j,m){
            if(s[i][j]=='.'){
                if(i-1 >= 0 && s[i-1][j] == '.')
                    ans[i][j]+=ans[i-1][j];
                if(j-1 >= 0 && s[i][j-1] == '.')
                    ans[i][j]+=ans[i][j-1];
                ans[i][j]%=mod;
            }
//         cout<<ans[i][j];
        }
//        cout<<"\n";
        }
    cout<<ans[n-1][m-1];
}
// Driver Code
int main(){
    TEST1
    return 0;
}
/*
adsfasdfas
adfasdfsadgnf
afdsafda
*/


Measured memory_bytes: 5248
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
  
int main() {
  int n;
  cin >> n;
  bool have = false;
  rep(i,9){
    rep(j,9){
      if((i + 1) * (j + 1) == n){
        have = true;
      }
    }
  }
  if(have){
    cout << "Yes";
  }
  else{
    cout << "No";
  }
  return 0;
}

Measured memory_bytes: 256
using ll=long long;using ull=unsigned long long;
#include<limits>
namespace pcl{template<typename T>constexpr T TNF=std::numeric_limits<T>::max()/2;constexpr int INF=TNF<int>;constexpr ll LNF=TNF<ll>;constexpr double DNF=TNF<double>;constexpr double EPS=1e-8;constexpr int P7=1'000'000'007;constexpr int DX[]={1,0,-1,0,1,1,-1,-1};constexpr int DY[]={0,1,0,-1,-1,1,1,-1};}
#include<algorithm>
#include<cmath>
#include<iostream>
namespace pcl{template<typename T>void updmax(T&a,T const&b){a=std::max(a,b);}template<typename T>void updmin(T&a,T const&b){a=std::min(a,b);}template<typename T,typename U,typename V>bool in_range(T const&begin,U const&mid,V const&end){return begin<=mid&&mid<end;}template<typename T,typename U,typename V>bool in_range(T const&begin,std::initializer_list<U>list,V const&end){auto p=std::minmax_element(list.begin(),list.end());return begin<=*p.first&&*p.second<end;}template<typename T,typename U,typename V>bool in_range_strict(T const&begin,std::initializer_list<U>list,V const&end){if(!std::is_sorted(list.begin(),list.end()))return false;return in_range(begin,list,end);}template<typename T>inline T cget(){T x;std::cin>>x;return x;}}
#include<iostream>
#include<vector>
namespace pcl{template<typename T>std::ostream&operator<<(std::ostream&os,std::vector<T>const&v){os<<'[';for(size_t i=0;i<v.size();i++){if(i!=0)os<<",";os<<v[i];}os<<']';return os;}template<typename T>std::istream&operator>>(std::istream&is,std::vector<T>&v){for(size_t i=0;i<v.size();i++)is>>v[i];return is;}}
#include<bits/stdc++.h>
using namespace std;using namespace pcl;int main(){int N,M;cin>>N>>M;priority_queue<ll,vector<ll>,greater<ll>>cards;for(int i=0;i<N;i++){ll a;cin>>a;cards.push(a);}vector<pair<ll,int>>BC(M);for(auto&bc:BC)cin>>bc.second>>bc.first;sort(BC.begin(),BC.end());int rest=N;priority_queue<ll,vector<ll>,greater<ll>>changes;while(rest>0&&!BC.empty()){auto bc=BC.back();BC.pop_back();for(int i=0;i<bc.second&&rest>0;i++,rest--){changes.push(bc.first);}}while(!changes.empty()){ll c=changes.top();changes.pop();ll a=cards.top();if(c>a){cards.pop();cards.push(c);}assert((int)cards.size()==N);}ll res=0;while(!cards.empty()){res+=cards.top();cards.pop();}cout<<res<<endl;}


Measured memory_bytes: 4212
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define FOR(i, m, n) for(ll i = m; i < (n); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vii = vector<vi>;
using pii = pair<int, int>; 
using vl = vector<ll>;
using vll = vector<vl>;
using pll = pair<ll, ll>;

int main() {
    ll x;
    cin >> x;
    ll ans = 0;
    ll y = 100;
    while(true){
        ans++;
        y += y*0.01;
        if(y >= x){
            cout << ans;
            return 0;
        }
    }
}

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

#define fi first
#define se second
#define long long long
typedef pair<long,long> ii;

int n;
long d, pw;
ii A[200003];

int main()
{
	// freopen("input.in", "r", stdin);

	scanf("%d %lld %lld", &n, &d, &pw);
	for(int i = 0; i < n; i++)
		scanf("%lld %lld", &A[i].fi, &A[i].se);	

	sort(A, A+n);

	queue<ii> atk;
	long tot_pow = 0;
	long mov = 0;

	for(int i = 0; i < n; i++)
	{
		long x = A[i].fi, h = A[i].se;

		while(atk.size() && atk.front().fi < x)
		{
			tot_pow -= atk.front().se;
			atk.pop();
		}
		// printf("%lld %lld %d\n", h, tot_pow, pw);
		if(h > tot_pow)
		{
			h -= tot_pow;
			mov += (h+pw-1)/pw;
			tot_pow += 1LL*(h+pw-1)/pw*pw;

			// printf("	%lld %lld\n", x + 2*d, 1LL*(h-pw+1)/pw*pw);
			atk.push({x + 2*d, 1LL*(h+pw-1)/pw*pw});
		}
	}
	printf("%lld\n", mov);
}

Measured memory_bytes: 4992
iW=$stdin.gets.chomp
  arr=[]
  until ( iT=$stdin.gets.chomp ) == "END_OF_TEXT" do
    #iT=iT.gsub(/\.$/,"").split
    arr<<iT.split
  end
  arr.flatten!.map!{|s|s.gsub(/\.$/,"").downcase}
  puts arr.select{|s|s==iW}.size


Measured memory_bytes: 6864
/**
*
* Author: Mouhanad
* Lang: GNU C++14
*
**/
#include<bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define ii pair < int , int >
#define LS pair < ll , string >
typedef long long ll;
const int inf = 1<<30;
const int N =100100;
int n , a[N] , q ;

int main ( ){
  scanf("%d",&n);
  for  (int i = 1; i <= n ;i++ ) scanf("%d",a+i);
  bool sol = 1 ;
  int cur = 0 ;
  for ( int i = 2 ; i <= n ;i++ ){
       cur += a[i]-a[i-1];
       if ( cur < -1 ) {
        sol =0 ;
       }
       if ( cur > 0 ) cur = 0 ;
  }
  if ( sol) printf("Yes\n");
  else printf("No\n");
 return 0 ;
}


Measured memory_bytes: 640
#include <stdio.h>

int main(){
	
	
	int A,B;
	char S[15], T[15], U[15];
	
	scanf("%s %s", S, T);
	scanf("%d %d", &A, &B);
	getchar();
	scanf("%s", U);
	if (S[0] == U[0]){
		printf("%d %d", A-1, B);
	}else if (T[0]==U[0]) {
		printf("%d %d", A, B-1);
	}
	


	
	return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <map>
#include <string>

using namespace std;

void solve()
{
	int a;
	char c[3];
	map<string, int> Map;
	while(~scanf("%d,%2s", &a, c))
	{
		Map[string(c)]++;
	}
	cout << Map["A"] << endl;
	cout << Map["B"] << endl;
	cout << Map["AB"] << endl;
	cout << Map["O"] << endl;
}

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

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
const int mod = 1000000007;
#define ll long long

int main()
{
	int a[3];
	for (int i = 0; i < 3; i++)  cin >> a[i];
	sort(a, a + 3);
	int an = 0;
	for (int i = 0; i < 2; i++) {
		an += a[i + 1] - a[i];
	}
	cout << an << endl;
}

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

#define vt          vector
#define sz(x)       int((x).size())
#define all(x)      (x).begin(), (x).end()
#define rall(x)     (x).rbegin(), (x).rend()
#define fi          first
#define se          second

using ll = long long;
using pii = pair<int, int>;

void solve() {
    int n;
    cin >> n;
    vt<pii> pos(n);
    for (pii &i : pos) cin >> i.fi >> i.se;

    vt<int> per(n);
    iota(all(per), 0);
    double ans = 0;
    int cnt = 0;
    do {
        for (int i = 1; i < n; i++) {
            ans += hypot(pos[per[i]].fi - pos[per[i - 1]].fi,
                    pos[per[i]].se - pos[per[i - 1]].se);
        }
        cnt++;
    } while (next_permutation(all(per)));

    cout << setprecision(7) << fixed << ans / cnt;
}

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

    int tcs = 1;
    for (int tc = 1; tc <= tcs; tc++) {
        // cout << "Case " << tc << ": ";
        solve();
    }
}


Measured memory_bytes: 3828
#include <iostream>
using namespace std;
int main()
{
    int a,b,c,temp;
    cin>>a>>b>>c;
    temp = a;
    a = b;
    b = temp;
    temp = c;
    c = a;
    a = temp;
    cout<<a<<' '<<b<<' '<<c;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
typedef long long ll;
typedef long double ld;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int main(){
  ll n,m,k,i,j,result=0,x,t;
  int a[200010];
  string s;
  cin >> n >> x >> t;
  result = (n+x-1)/x;
  result *= t;
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <set>

using namespace std;
set<int> s;
int x[30][30];
int main(){
	int i,j,k,n,d;
	cin >> n >> d;
	for(i=0;i<n;i++){
		for(j=0;j<d;j++){
			cin >> x[i][j];
		}
	}
	for(i=0;i<=300;i++){
		s.insert(i*i);
	}
	int ans = 0;
	for(i=0;i<n;i++){
		for(j=i + 1;j<n;j++){
			int y = 0;
			for(k=0;k<d;k++){
				y += (x[i][k] - x[j][k])*(x[i][k] - x[j][k]);
			}
			if(s.count(y)){
				ans++;
			}
		}
	}
	cout << ans << endl;
}

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

#define ff first
#define ss second
#define PI acos(-1)
#define pb push_back
#define int long long
#define ld long double
#define sp fixed<<setprecision
#define bp __builtin_popcountll
#define all(x) x.begin(),x.end()
#define pii pair<long long,long long>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int MOD = (1e9)+7;
const int N = 1e6+5;

signed main()
{
    FAST
    int tc=1;
    //cin>>tc;
    for(int ti=1;ti<=tc;ti++)
    {
        int n,cnt[3];
        cin>>n>>cnt[0]>>cnt[1]>>cnt[2];
        string s[n];
        int x,y;
        int ok = 1;
        char ans[n];
        for(int i=0;i<n;i++)cin>>s[i];
        for(int i=0;i<n;i++)
        {
            x=s[i][0],y=s[i][1];
            x-='A',y-='A';
            int z = 3^(x^y);
            if(!(cnt[x]-1) && !(cnt[y]-1)&& !cnt[z])
            {
                int j = i+1,c=1;
                while(j<n && s[j]==s[i])j++,c++;
                if(c%2)
                {
                    if(j<n)
                    {
                        int id,sid;
                        if(s[j][0] == s[i][0] || s[j][1] == s[i][0])id=0;
                        else id=1;
                        sid = id;
                        for(int k=i;k<j;k++,id++)ans[k]=s[i][id%2];
                        cnt[s[i][sid]-'A'] = 2;
                        cnt[s[i][1-sid]-'A'] = 0;
                    }
                    else for(int k=i;k<j;k++)ans[k]=s[i][k%2];
                }
                else for(int k=i;k<j;k++)ans[k]=s[i][k%2];
                i= j-1;
                continue;
            }
            if(cnt[x]<=cnt[y])cnt[x]++,cnt[y]--,ans[i]=char(x+'A');
            else cnt[x]--,cnt[y]++,ans[i]=char(y+'A');
            if(cnt[x]<0 || cnt[y]<0)ok=0;
        }
        if(ok)
        {
            cout<<"Yes\n";
            for(int i=0;i<n;i++)cout<<ans[i]<<endl;
        }
        else cout<<"No\n";
    }
    return 0;
}


Measured memory_bytes: 6884
import Data.List (scanl')

computeMax :: String -> Int
computeMax = maximum . scanl' f 0
    where
        f x 'I' = x + 1
        f x 'D' = x - 1
        f x _ = x

main :: IO ()
main = do
    _ <- getLine
    s <- getLine
    print $ computeMax s


Measured memory_bytes: 508
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef pair<ll, ll> P;
 
int main(){
    ll n, k;
        cin >> n >>k;
 
        ll ans = n-n/k*k;
        ll tmp = ans - k;

        
        cout << min(ans, abs(tmp)) << endl;
}


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

int main() {
	int N;
	cin >> N;
	int M = 1;
	for (;M <= N;M += M);
	cout << M / 2;
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり

今、2^M<=Nを満たす最大のMが与えられたとする
この時、1<=x<2^Mを満たす全ての整数xは素因数分解しても2をM個含まないのでM回割ることはできないし、
2^M<x<=Nを満たす全ての整数xも素因数分解しても2をM個含まない
(2^M*1の次は2^M*3だが、その前に2^M*2==2^(M+1)を含み、これはMの条件に反する)
よって、答えは必ず2の累乗になる
後は下から順にNを超えない2の累乗を探していけば、O(logN)で求まるね
*/

Measured memory_bytes: 256