akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <queue>
#include <algorithm>
#include <cmath>
#include <vector>
#define ll long long int

using namespace std;

int a[300001];
ll fsum[300001];
ll lsum[300001];

int main(int argc, char const* argv[])
{
	int n;
	cin >> n;
	priority_queue<int, vector<int>, greater<int> >qf;
	priority_queue<int>ql;
	for(int i = 0; i < 3 * n; i++){
			cin >> a[i];
			if(i < n){
					fsum[n-1] += a[i];
					qf.push(a[i]);
			}
			else if(i >= 2 * n){
					lsum[2*n] += a[i];
					ql.push(a[i]);
			}
	}
	for(int i = 0; i < n; i++){
			qf.push(a[i+n]);
			int t = qf.top();
			qf.pop();
			fsum[i+n] = fsum[i+n-1] + a[i+n] - t;
	}
	for(int i = 0; i < n; i++){
			ql.push(a[2 * n - i - 1]);
			int t = ql.top();
			ql.pop();
			lsum[2 * n - i - 1] = lsum[2 * n - i] + a[2 * n - i - 1] - t;
	}
	ll maxi = -1e18;
	for(int i = n - 1; i < 2 * n; i++){
			maxi = max(maxi, fsum[i] - lsum[i+1]);
	}
	cout << maxi << endl;
	return 0;
}


Measured memory_bytes: 5240
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define ll long long
int main()
{
	list<char>front,end;
    string s;
    cin>>s;
    int q;
    cin>>q;
    bool rev=false;
    while(q--)
    {
        int t,f;
        char c;
        cin>>t;
        if(t==1)
            rev=!rev;
        else
        {
            cin>>f>>c;
            if(rev)
            {
                if(f==1)
                    end.push_back(c);
                else
                    front.push_front(c);
            }
            else
            {
                if(f==1)
                    front.push_front(c);
                else
                    end.push_back(c);
            }
        }
    }
    if(rev)
        {
            reverse(end.begin(),end.end());
            reverse(s.begin(),s.end());
            reverse(front.begin(),front.end());
            for(auto all:end)
                cout<<all;
            cout<<s;
            for(auto all:front)
                cout<<all;
        cout<<endl;
        }
    else
    {
        for(auto all:front)
                cout<<all;
            cout<<s;
        for(auto all:end)
                cout<<all;
            
        cout<<endl;
    }
        
    
}

Measured memory_bytes: 6912
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // int64_t
#include <math.h>

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int get_int(void) {
  int num;
  scanf("%d", &num);
  return num;
}

int get_int2(int *a1, int *a2) {
  scanf("%d %d", a1, a2);
  return 0;
}

int get_int3(int *a1, int *a2, int *a3) {
  scanf("%d %d %d", a1, a2, a3);
  return 0;
}

int get_int4(int *a1, int *a2, int *a3, int *a4) {
  scanf("%d %d %d %d", a1, a2, a3, a4);
  return 0;
}

int get_int5(int *a1, int *a2, int *a3, int *a4, int *a5) {
  scanf("%d %d %d %d %d", a1, a2, a3, a4, a5);
  return 0;
}

// <arr[0]> <arr[1]> .. <arr[size-1]>
int fget_array(int *arr, int size) {
    int i;
    for(i = 0; i < size; i++) {
        scanf("%d", &arr[i]);
    }
    return 0;
}
#define NUM_MAX 2000
#define INF (1e+9)

int main() {
    int num, xscore, yscore;
    get_int3(&num, &xscore, &yscore);
    static int arr[NUM_MAX];
    fget_array(arr, num);

    static int dp[NUM_MAX+1][2];
    int last = arr[num-1];
    int i;
    int prev_x = INF;
    int prev_y = 0;
    for (i = num-1; i >= 0; i--) {
        int Y = (i ? arr[i-1] : yscore);
        dp[i][0] = max(abs(Y - last), prev_y);
        prev_x = min(prev_x, dp[i][0]);


        int X = (i ? arr[i-1] : xscore);
        dp[i][1] = min(abs(X - last), prev_x);
        prev_y = max(prev_y, dp[i][1]);
    }
    printf("%d\n", dp[0][0]);
}

Measured memory_bytes: 128
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;

const int MAX_N = 505;

typedef pair<int, int> pii;

int A[MAX_N * MAX_N], pos[MAX_N][MAX_N], cnt[MAX_N], N;
pii X[MAX_N];

int main() {
  scanf("%d", &N);
  for (int i = 1, temp; i <= N; ++i) {
    scanf("%d", &temp);
    X[i] = make_pair(temp, i);
    A[temp] = i;
  }
  
  sort(X + 1, X + N + 1);

  int tot = 0;
  for (int i = 1; i <= N; ++i) {
    for (int j = 1; j < X[i].second; ++j) {
      if (A[tot + 1]) {
	tot++, j--;
	continue;
      }
      A[++tot] = X[i].second;
    }
  }
  
  for (int i = 1; i <= N; ++i) {
    for (int j = 1; j <= N - X[i].second; ++j) {
      if (A[tot + 1]) {
	tot++, j--;
	continue;
      }
      A[++tot] = X[i].second;
    }
  }

  tot = N * N;
  for (int i = 1; i <= tot; ++i) 
    pos[A[i]][++cnt[A[i]]] = i;
  for (int i = 1; i <= N; ++i)
    if (pos[X[i].second][X[i].second] != X[i].first) {
      puts("No");
      return 0;
    }
  puts("Yes");
  for (int i = 1; i <= tot; ++i)
    printf("%d ", A[i]);
  puts("");
  return 0;
}


Measured memory_bytes: 3072
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
using namespace std;

  int main(){
int n,a,b;
cin>> n >>a >>b;
cout << min(a*n,b) << endl;
return 0;}

Measured memory_bytes: 256
using System;
class Program
{
  static void Main(string[] args)
  {
    int num = int.Parse(Console.ReadLine());
    int count = 0;
    for(int i = 1; i <= num; i++)
    {
      string line = i.ToString();
      if(line.Length % 2 == 1){
        count++;
      }
    }
      Console.WriteLine(count);
  }
}


Measured memory_bytes: 13140
from math import pi, cos

A, B, H, M = map(int, input().split())

theta = (H / 12 + M / 720 - M / 60) * 2 * pi
c2 = A ** 2 + B ** 2 - 2 * A * B * cos(theta)
print(c2 ** 0.5)


Measured memory_bytes: 62580
r,g,b,n=io.read("*n","*n","*n","*n")

counter=0
for i=0,n do
    for j=0,n do
        rg=r*i+g*j
        if n>=rg and (n-rg)%b==0 then
            counter=counter+1
        end
    end
end
print(counter)

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

int main(){
    // 入力
    long long n, k;
    cin >> n >> k;
    vector<long long> A(n);
    for (int i = 0; i < n; i++) cin >> A[i];
    // 最大値をx以下にできるか
    auto check = [&](long long x) -> bool {
        long long cnt = 0;
        for (int i = 0; i < n; i++) cnt += (A[i] - 1) / x;
        return cnt <= k;
    };
    // めぐる式二分探索
    long long ok = 1e9, ng = 0;
    while(ok - ng > 1){
        long long mid = (ok + ng) / 2;
        if (check(mid)) ok = mid;
        else ng = mid;
    }
    // 出力
    cout << ok << endl;
}


Measured memory_bytes: 4744
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

//#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    VL C(N); REP(i,N) cin >> C[i];
    VL dp(N,0);
    int last[212345] = {};
    REP(i,212345) last[i] = -1;
    dp[0] = 1;
    last[C[0]] = 0;
    FOR(i,1,N){
        dump(i)
        dump(C[i])
        dump(last[C[i]])
        dump(dp[last[C[i]]])

        if(last[C[i]] == -1 || last[C[i]] == i-1){
            dp[i] = dp[i-1];
            last[C[i]] = i;
        }
        else{
            dp[i] = dp[i-1] + dp[last[C[i]]];
            last[C[i]] = i;
        }
        dp[i] %= MOD;
    }
    REP(i,N){
        dump(i)
        dump(dp[i])
    }
    cout << dp[N-1] << endl;

}


Measured memory_bytes: 4224
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

vector<int> v[300010];
int main() {
    int n; cin >> n;
    rep(i,n) {
        int m; cin >> m;
        rep(j,m) {
            int num; cin >> num;
            v[i].push_back(num);
        }
    }

    priority_queue<int> q;
    ll ans = 0;

    for(int i = n-1; i >= 0; i--) {
        for(auto val : v[i]) {
            q.push(val);
        }
        ans += q.top();
        q.pop();
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 19516
from itertools import product
from bisect import bisect_right
A = []
for i in range(3,10):
    for z in product(("3","5","7"),repeat=i):
        C = {"3":0,"5":0,"7":0}
        for j in range(i):
            C[z[j]] += 1
        if C["3"]>0 and C["5"]>0 and C["7"]>0:
            x = int("".join(z))
            A.append(x)
A = sorted(A)
N = int(input())
ind = bisect_right(A,N)
print(ind)

Measured memory_bytes: 75240
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<math.h>
#include<bitset>
using namespace std;

typedef stack<int> IntStack;
typedef queue<int> IntQueue;

/*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*/



int main()
	
{	
	int x;

	for (int i = 0;i < 10000;i++)
	{
		cin >> x;

		if (x == 0) break;

		cout << "Case " << i + 1 << ": " << x << endl;
	}

	

	return 0;
}



Measured memory_bytes: 3028
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;

#define N 200000000
#define INF 200000001

int size;
int h[N];

void swap(int *a, int* b) {
  int tmp = *a;
  *a = *b;
  *b = tmp;
}

void maxHeapify(int i) {
  int l = 2*i;
  int r = 2*i+1;
  int valM;
  if ( l <= size && h[l] > h[i] ) valM = l;
  else valM = i;
  if ( r <= size && h[r] > h[valM] ) valM = r;
  if ( valM != i ) {
    swap(&h[i], &h[valM] );
    maxHeapify(valM);
  }
}

void hIncreaseKey ( int i, int key ) {
  if ( key < h[i] ) return;
  h[i] = key;
  while ( i > 1 && h[i/2] < h[i] ) {
    swap( &h[i], &h[i/2] );
    i = i/2;
  }
}

void maxHeapInsert ( int key ) {
  size++;
  h[size] = -INF;
  hIncreaseKey(size, key);
}

int heapExtractMax() {
  int valM;
  if ( size < 1 ) return 0;
  valM = h[1];
  h[1] = h[size--];
  maxHeapify(1);
  return valM;
}

int main() {
  string input;
  size = 0;
  while( cin >> input ) {
    if ( input == "end" ) break;
    if ( input == "extract" ) {
      cout << heapExtractMax() << endl;
    } else {
    int val;
    cin >> val;
    maxHeapInsert(val);
    }
  }
  return 0;
}

Measured memory_bytes: 5296
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD=1000000007;

int main(){
    string S;
    int K;
    cin>>S>>K;
    int X=S.size();
    int Y=S.at(0)-'0';
    if(K==1){
        cout<<Y+9*(X-1)<<endl;
        return 0;
    }
    if(K==2){
        ll Ans=0;
        Ans+=(X-1)*(X-2)/2*9*9;
        Ans+=(Y-1)*9*(X-1);
      	for(int i=1; i<X; i++){
            int N=S.at(i)-'0';
         
            if(N!=0){
                    Ans+=N;
                    Ans+=9*(X-i-1);
              break;
            }
        }
        cout<<Ans<<endl;
    }
    bool O=true;
    if(K==3){
        ll Ans=0;
        Ans+=(X-1)*(X-2)*(X-3)/6*9*9*9;
        Ans+=(Y-1)*(X-1)*(X-2)/2*9*9;
        for(int i=1; i<X; i++){
          	int N=S.at(i)-'0';
            if(!O){
                  if(N!=0){
                      Ans+=N;
                      Ans+=9*(X-i-1);
                break;
              }
            }
            if(O){
                if(N!=0){
                    Ans+=(N-1)*9*(X-i-1);
                  	Ans+=9*9*(X-i-1)*(X-i-2)/2;
                    O=false;
                }
            }
        }
        cout<<Ans<<endl;
    }

}

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

typedef long long LL;

const int N=18,INF=(1<<30)-1;

int n,a[N+9][2];

void into(){
  scanf("%d",&n);
  for (int i=0;i<n;++i)
	scanf("%d",&a[i][0]);
  for (int i=0;i<n;++i){
	scanf("%d",&a[i][1]);
	if (i&1) swap(a[i][0],a[i][1]);
  }
}

int tmp[2][N+9];

bool cmp0(const int &x,const int &y){return a[x][0]<a[y][0]||a[x][0]==a[y][0]&&x<y;}
bool cmp1(const int &x,const int &y){return a[x][1]<a[y][1]||a[x][1]==a[y][1]&&x<y;}

int p[N+9],td[N+9];
int c[N+9];

void Add(int p,int v){for (;p<=n;p+=p&-p) c[p]+=v;}
int Query(int p){int res=0;for (;p;p-=p&-p) res+=c[p];return res;}
int Query(int l,int r){return Query(r)-Query(l-1);}

int Get_ans(int s){
  int ct[2]={0,0};
  for (int i=0;i<n;++i) tmp[s>>i&1][ct[s>>i&1]++]=i;
  sort(tmp[0],tmp[0]+(n+1>>1),cmp0);
  sort(tmp[1],tmp[1]+(n>>1),cmp1);
  for (int i=0;i<n;++i) td[p[i]=tmp[i&1][i>>1]]=i;
  for (int i=1;i<n;++i)
	if (a[p[i-1]][i&1^1]>a[p[i]][i&1]) return INF;
  int res=0;
  for (int i=1;i<=n;++i) c[i]=0;
  for (int i=0;i<n;++i){
	res+=Query(td[i]+1,n);
	Add(td[i]+1,1);
  }
  return res;
}

int ans;

void Get_ans(){
  ans=INF;
  for (int s=0;s<1<<n;++s){
	int cnt=0;
	for (int i=0;i<n;++i) cnt+=s>>i&1;
	if (cnt^n>>1) continue;
    ans=min(ans,Get_ans(s));
  }
}

void work(){
  Get_ans();
}

void outo(){
  printf("%d\n",ans==INF?-1:ans);
}

int main(){
  into();
  work();
  outo();
  return 0;
}

Measured memory_bytes: 3832
#include <vector> 
#include <list> 
#include <map> 
#include <set> 
#include <deque> 
#include <queue> 
#include <stack> 
#include <bitset> 
#include <algorithm> 
#include <functional> 
#include <numeric> 
#include <utility> 
#include <sstream> 
#include <iostream> 
#include <iomanip> 
#include <cstdio> 
#include <cmath> 
#include <cstdlib> 
#include <cctype> 
#include <string> 
#include <cstring> 
#include <ctime> 

using namespace std;

#define _int64 long long

vector<pair<int,int> > a[110000];
int p[110000];

int main()
{
  int i,j,k,x,y,z,m,n,tmp;
  vector<int> q;
  scanf("%d%d",&n,&m);
  for (i=0;i<n;i++)
    a[i].clear();
  for (i=0;i<m;i++)
  {
    scanf("%d%d%d",&x,&y,&z);
    x--;y--;
    a[x].push_back(make_pair(y,z));
    a[y].push_back(make_pair(x,-z));
  }
  for (i=0;i<n;i++)
    p[i]=-2000000000;
  for (i=0;i<n;i++)
    if (p[i]==-2000000000)
    {
      q.clear();
      q.push_back(i);
      p[i]=0;
      for (j=0;j<q.size();j++)
      {
        x=q[j];
        z=p[x];
        //cout<<x<<" "<<z<<endl;
        for (k=0;k<a[x].size();k++)
        {
          y=a[x][k].first;
          tmp=z+a[x][k].second;
          if (p[y]==-2000000000)
          {
            p[y]=tmp;
            q.push_back(y);
          }
          else
          {
            if (p[y]!=tmp)
            {
              printf("No\n");
              return 0;
            }
          }
        }
      }
    }
  printf("Yes\n");
  return 0;
}

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

int main() {
  long long int A, B;
  cin >> A >> B;

  vector<int> a(63);
  vector<int> b(63);

  for(int i=0;i<63;i++) {
    long long int p = 0;
    long long int q = 0;
    if(i == 0) {
      p = A % 4;
      q = (B+1) % 4;
      if(p < 2) a[i] = 0;
      else a[i] = 1;
      if(q < 2) b[i] = 0;
      else b[i] = 1; 
    } else {
      p = A % (long long int)pow(2, i+1);
      q = (B+1) % (long long int)pow(2, i+1);
      if(p < pow(2, i)) a[i] = 0;
      else if(p % 2 == 0) a[i] = 0;
      else a[i] = 1;

      if(q < pow(2, i)) b[i] = 0;
      else if(q % 2 == 0) b[i] = 0;
      else b[i] = 1;
    }
  }

  long long int y = 0;
  long long int z = 0;

  for(int i=0;i<63;i++) {
    y += pow(2, i) * a[i];
    z += pow(2, i) * b[i];
  }

  cout << (y ^ z) << endl;
}

Measured memory_bytes: 512
import java.io.*;
import java.util.Scanner;

class Pair {
    final int x;
    final int y;
    Pair(int x, int y) {
        this.x = x;
        this.y = y;
    }
}

class DisjointSet {
    private static int[] parent, size;

    DisjointSet(int n) {
        parent = new int[n + 1];
        size = new int[n + 1];
        for (int i = 0; i < n + 1; i++) {
            parent[i] = i;
            size[i] = 1;
        }
    }

    private int find(int u) {
        if (u == parent[u]) return u;
        return parent[u] = find(parent[u]);
    }

    public long merge(int u, int v) {
        u = find(u); v = find(v);
        if (u == v) return -1L;
        long a = (long)size[u], b = (long)size[v];
        parent[u] = v;
        size[v] += size[u];
        size[u] = 0;
        return a * (a - 1L) / 2L + b * (b - 1L) / 2L;
    }

    public int get_size(int u) {
        u = find(u);
        return size[u];
    }
}

public class Main {

    public static void main(String[] args) throws IOException {
        Scanner s = new Scanner(System.in);

        int n = s.nextInt();
        int m = s.nextInt();

        Pair edges[] = new Pair[m];
        long ans[] = new long[m];

        for (int i = 0; i < m; i++) {
            int u = s.nextInt();
            int v = s.nextInt();
            edges[i] = new Pair(u, v);
        }

        long incon = (long)n * ((long)n - 1L) / 2L;
        DisjointSet dsu = new DisjointSet(n + 1);

        for (int i = 0; i < m; i++) {
            ans[m - i - 1] = incon;
            Pair edge = edges[m - i - 1];
            long tmp = (long)dsu.merge(edge.x, edge.y);
            if (tmp == -1L) continue;
            incon += tmp;
            long size = (long)dsu.get_size(edge.x);
            incon -= size * (size - 1L) / 2L;
        }

        for (int i = 0; i < m; i++) {
            System.out.println(ans[i]);
        }

    }
}


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

#define int long long

int N, M;
vector<vector<int> > G;
vector<bool> used;

void dfs(int v) {
  if ( used[v] ) return;
  used[v] = true;

  for ( int u : G[v] ) {
    dfs(u);
  }
}

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  cin >> N >> M;
  G = vector<vector<int> >(N);
  used = vector<bool>(N, false);

  for ( int i = 0; i < M; i++ ) {
    int x, y, z;
    cin >> x >> y >> z;
    x--; y--;
    G[x].emplace_back(y);
    G[y].emplace_back(x);
  }

  int ans = 0;
  for ( int i = 0; i < N; i++ ) {
    if ( !used[i] ) {
      dfs(i);
      ans++;
    }
  }

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


Measured memory_bytes: 8832
#include <cstdio>
#include <algorithm>
#include <vector>
typedef long long int64;
static const int MAXN = 1e5 + 4;
static const int MODULUS = 1e9 + 7;
static const int64 INF = 1LL << 61;
#define _  %  MODULUS
#define __ %= MODULUS

struct fwk {
    int f[MAXN];
    std::vector<int> updated;
    fwk() { std::fill(f, f + MAXN, 0); }
    inline void add(int pos, int inc) {
        updated.push_back(pos);
        for (++pos; pos < MAXN; pos += (pos & -pos)) (f[pos] += inc)__;
    }
    inline void clear() {
        for (int x : updated) for (++x; x < MAXN; x += (x & -x)) f[x] = 0;
        updated.clear();
    }
    inline int sum(int rg) {
        int ret = 0;
        for (++rg; rg; rg -= (rg & -rg)) (ret += f[rg])__;
        return ret;
    }
    inline int sum(int lf, int rg) { return (sum(rg) - sum(lf - 1) + MODULUS)_; }
} fx, fy;

int n;
int64 a, b, s[MAXN];

int main()
{
    scanf("%d%lld%lld", &n, &a, &b);
    for (int i = 1; i <= n; ++i) scanf("%lld", &s[i]);
    s[0] = -INF;

    fx.add(0, 1);
    for (int i = 1; i <= n; ++i) {
        int fx_p = std::upper_bound(s, s + i, s[i] - a) - &s[0] - 1,
            fy_p = std::upper_bound(s, s + i, s[i] - b) - &s[0] - 1;
        int fx_sum = fx.sum(fy_p), fy_sum = fy.sum(fx_p);
        if (s[i] - s[i - 1] < a) fx.clear();
        if (s[i] - s[i - 1] < b) fy.clear();
        fx.add(i - 1, fy_sum);
        fy.add(i - 1, fx_sum);
    }

    printf("%d\n", (fx.sum(n) + fy.sum(n))_);
    return 0;
}


Measured memory_bytes: 2812
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

int main(){

    ll N, M; cin >> N;
    M = N - 1; 
    vector<vector<pair<ll,ll>>> G(N+1);
    rep(i, 0, M){
        ll v, u, w = 1;
        cin >> v >> u;
        G[u].push_back({v, w});
        G[v].push_back({u, w});
    }

    vector<ll> sun(N+1), fen(N+1);
   
   {
    vector<ll> d(N+1, 1e18);
    ll srt = N;
    /* dijkstra's scope */{
        priority_queue<pair<ll,ll>, vector<pair<ll,ll>>, greater<pair<ll,ll>>> que;
        que.push({0, srt});
        d[srt] = 0;
        while(!que.empty()){
            auto q = que.top();
            que.pop();
            if(q.first > d[q.second]) continue;
            for(auto g : G[q.second]){
                if(d[g.first] <= q.first + g.second) continue;
                d[g.first] = q.first + g.second;
                que.push({d[g.first], g.first});
            }
        }
    }

    sun = d;
    }
   
   {
    vector<ll> d(N+1, 1e18);
    ll srt = 1;

    /* dijkstra's scope */{
        priority_queue<pair<ll,ll>, vector<pair<ll,ll>>, greater<pair<ll,ll>>> que;
        que.push({0, srt});
        d[srt] = 0;
        while(!que.empty()){
            auto q = que.top();
            que.pop();
            if(q.first > d[q.second]) continue;
            for(auto g : G[q.second]){
                if(d[g.first] <= q.first + g.second) continue;
                d[g.first] = q.first + g.second;
                que.push({d[g.first], g.first});
            }
        }
    }

    fen = d;
   }

    ll sp = 0, fp = 0;
    rep(i, 1, N+1){
        //cerr << fen[i] << " " << sun[i] << endl;
        if(sun[i] >= fen[i]) fp++;
        else sp++; 
    }
    if(fp > sp) cout << "Fennec" << endl;
    else cout << "Snuke" << endl;
    return 0;
}

Measured memory_bytes: 10544
#まずAiで、D日間のときに食べる個数をとる関数choco
def choco(a,d):
    c=0 #チョコの個数 
    while c*a+1<=d: #合宿期間に食べれるまでcを増やす
        c+=1
    return c #合宿期間を過ぎてしまったらその一つ前の値を返す
n=int(input())
d,x=map(int,input().split())
A=[]
for i in range(n):
    A.append(int(input()))
S=0
for j in range(n):
    S+=choco(A[j],d)
print(x+S)        

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")  
#pragma GCC optimize ("-fno-defer-pop")
#define all(a) a.begin(),a.end()
#define bs binary_search
#define ll long long int
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m); t=(t*t)%m; if(b&1)t=(t*a)%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ipr pair<ll,ll>
#define ps push_back
#define fs first
#define sc second
#define mkp make_pair
#define mod 1000000007
int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll a,b;
	cin>>a>>b;
	if(b%a==0){
		cout<<(a+b);
	}
	else {
		cout<<(b-a);
	}
	return 0;
}
//ctrl H replace

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <cmath>
#include <deque>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define mt make_tuple
#define pq priority_queue<ll>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vecpll vector<pll>
#define vecbl vector<bool>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
string stin(){string s;cin>>s;return s;}
ll modpow(ll a,ll b){
    if(b==0)return 1;
    else if(b%2==0){
        ll d=modpow(a,b/2);
        return d*d%2019;
    }
    else return modpow(a,b-1)*a%2019;
}
int main(){
    string s=stin();
    ll n=(int)s.size();
    vecll a(n);
    rep(i,n)a[i]=s[i]-'0';
    vecll dp(n+1);
    dp[n]=0;
    dp[n-1]=a[n-1];
    rep3(i,n-2,0)dp[i]=(dp[i+1]+a[i]*modpow(10,n-i-1))%2019;
    vec num(2019,0);
    rep(i,n+1)num[dp[i]]++;
    int ans=0;
    rep(i,2019) ans+=num[i]*(num[i]-1)/2;
    cout<<ans<<endl;
}

Measured memory_bytes: 6740
#include <iostream>

using namespace std;

int main(void)
{
    string S, T;

    cin >> S >> T;
    int m, ans = 0x7FFFFFFF;
    for (int i = 0; i < S.size(); i++) {
        m = 0;
        bool f = false;
        for (int j = 0; j < T.size(); j++) {
            if (i + j >= S.size()) {
                f = true;
                break;
            }
            if (S[i + j] != T[j]) {
                m++;
            }
        }
        if (!f) {
            ans = min(ans, m);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
#include<stdio.h>
#include<stdlib.h>
int compar(const int *val1, const int *val2);
int main(){
    	int N,A[100000],i,j,res=0,flag=1;
    	scanf("%d",&N);
    	for(i=0;i<N;i++){
    		scanf("%d",&A[i]);
    	}
    	qsort(A,N,sizeof(int),(int (*)(const void *, const void *))compar);
    	/*for(i=0;i<N;i++){
			for(j=N-1;j>i;j--){
				if(A[j]>A[j-1]){
					A[j]^=A[j-1];
					A[j-1]^=A[j];
					A[j]^=A[j-1];
				}
			}
    	}*/
    	/*for(i=0;i<N;i++){
    		printf("配列＝%d\n",A[i]);
    	}*/
    	for(i=0;i<N;i++){
    		if(A[i]==A[i+1]){
    			flag++;
    			//printf("aa=%d",flag);
    		}else{
    			//printf("flag=%d\n",flag);
    			res+=flag%2;
    			flag=1;
    		}
    	}
    	printf("%d\n",res);
    	return 0;
    }
int compar(const int *val1, const int *val2) {
    if ( *val1 < *val2 ) {
        return -1;
    } else if ( *val1 == * val2 ) {
        return 0;
    } else {
        return 1;
    }
}


Measured memory_bytes: 892
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
using namespace std;
#define ll long long int
#define abs(n) ((n>0)?(n):((n)*(-1)))

#define VREP(v) for(std::vector<ll>::iterator itr = (v).begin(); itr != (v).end();itr++)
#define VALL(v) ((v).begin(),(v).end())


std::vector<ll> setPrimes(ll max){
	std::vector<ll> primeList;
	std::vector<ll> searchList;
	std::vector<ll> nextSearchList;
	ll rt = sqrt(max);
	searchList.reserve(max-1);

	for (ll i = 2; i <= max; ++i) {
		searchList.push_back(i);
	}

	while(searchList.size()>0 && searchList[0] <= rt){
		nextSearchList.clear();
		nextSearchList.reserve(searchList.size());
		ll divisor = searchList[0];
		searchList.erase(searchList.begin());
		primeList.push_back(divisor);
		VREP(searchList){
			ll tgt = *itr;
			if(tgt%divisor != 0){
				nextSearchList.push_back(tgt);
			}
		}
		searchList = nextSearchList;
	}
	VREP(nextSearchList){
		primeList.push_back(*itr);
	}

	return primeList;
}


int num(std::vector<ll> vec, ll number){
	int ret=0;
	VREP(vec){
		if(*itr >= number) ret++;
	}
	return ret;
}

int main(int argc, const char * argv[]) {
	std::vector<ll> primeList = setPrimes(100);
	int primeSize = primeList.size();
	std::vector<ll> expList(primeSize,0);
	int N;
	cin >> N;
	for (int i = 2; i <= N; ++i) {
		int mul = i;
		for (int primeIndex = 0; primeIndex < primeSize; ++primeIndex) {
			while(mul%primeList[primeIndex]==0){
				mul /= primeList[primeIndex];
				expList[primeIndex] += 1;
			}
		}
	}

	int ret =
			num(expList,74)
			+ num(expList,24)*(num(expList,2)-1)
			+ num(expList,14) * (num(expList,4)-1)
			+ num(expList,4)*(num(expList,4)-1)*(num(expList,2)-2)/2;
	cout << ret <<endl;
}


Measured memory_bytes: 256
def solve(p, query):
    ans = 0
    for a, b in query:
        unite(a, b)

    for pi in p:
        if is_same(pi, p[pi]):
            ans += 1

    return ans


def find(x):
    if par[x] == x:
        return x
    else:
        par[x] = find(par[x])
        return par[x]


def is_same(x, y):
    return find(x) == find(y)


def unite(x, y):
    rt_x = find(x)
    rt_y = find(y)
    if rt_x == rt_y:
        return
    if rnk[rt_x] < rnk[rt_y]:
        par[rt_x] = rt_y
    else:
        par[rt_y] = rt_x
        if rnk[rt_x] == rnk[rt_y]:
            rnk[rt_x] += 1


if __name__ == '__main__':
    n, m = map(int, input().split())
    query = []
    par, rnk = [0]*n, [0]*n
    p = list(map(int, input().split()))
    p = list(map(lambda x: x-1, p))

    for _ in range(m):
        a, b = map(int, input().split())
        query.append((a-1, b-1))

    for i in range(n):
        par[i] = i

    print(solve(p, query))


Measured memory_bytes: 25768
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF 2000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int a[3], k;
int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    rep(i, 0, 3) cin >> a[i];
    cin >> k;
    sort(a, a+3);
    a[2] *= (int)pow(2, k);
    cout << accumulate(a, a+3, 0) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>

using namespace std;

 
int main(){
	int n,a,b,c,x[105]={};
	double sum=0;

	cin>>n;
	cin>>a>>b;
	cin>>c;
	for(int i=0;i<n;i++)
	{
		cin>>x[i];
	}

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

	//reverse(x,x+n);
	sum+=c;
	double R=0;R+=a;
	for(int i=0;i<n;i++){

		if((sum+x[i])/(R+b)>=sum/R){
			sum+=x[i];
			R+=b;
			//cout<<x[i]<<endl;
		}
		//if(sum/R<=65)
	//	cout<<x[i]<<endl;
	}
	cout<<(int)(sum/R)<<endl;
	return 0;
}

Measured memory_bytes: 1160
# -*- coding: utf-8 -*-
import sys
input = sys.stdin.buffer.readline


def read_int_n():
    return list(map(int, input().split()))


def slv(N, S, A):
    M = 998244353
    ans = 0

    dp = [0] * (S+1)
    for a in A:
        dp[0] += 1
        ndp = [0] * (S+1)
        for j in range(S+1):
            ndp[j] += dp[j]
            ndp[j] %= M
            if j+a <= S:
                ndp[j+a] += dp[j]
                ndp[j+a] %= M
        dp = ndp
        ans += dp[S]
        ans %= M

    return ans


def main():
    N, S = read_int_n()
    A = read_int_n()
    print(slv(N, S, A))


if __name__ == '__main__':
    main()


Measured memory_bytes: 42000
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()


int main(){
    string s,t;
    cin>>s>>t;
    sort(all(s));
    
    sort(all(t));
    reverse(all(t));

    vector<string> v;
    v.push_back(s);
    v.push_back(t);
    sort(all(v));

    //cout<<v[0]<<" "<<v[1]<<endl;

    if(s==t){
        cout<<"No"<<endl;
        return 0;
    }

    if(v[0]==s) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}




Measured memory_bytes: 3624
N, M = map(int, input().split())
AB = [[int(j) for j in input().split()] for i in range(N)]
AB_sorted = sorted(AB)
money = 0
honsuu = 0
for i, ab in enumerate(AB_sorted):
    for j in range(ab[1]):
        money += ab[0]
        honsuu += 1
        if honsuu == M:
            print(money)
            quit()


Measured memory_bytes: 22380
import java.util.*;

public class Main{            
    
     public static void main(String[] args){
      
         Scanner sc = new Scanner(System.in);
         
         int N = sc.nextInt();
         int M = sc.nextInt();                          
        
         boolean from[] = new boolean[N+1];
         boolean to[]   = new boolean[N+1];
         
         for(int i = 1;i <= M;i++){
             int a = sc.nextInt();
             int b = sc.nextInt();
             if(a == 1)
                 from[b] = true;
             
             if(b == N)
                   to[a] = true;             
         }
         
         for(int i = 2;i <= N - 1;i++){
             if(from[i] && to[i]){
                 System.out.println("POSSIBLE");
                 return;
             }
         }         
         
         System.out.println("IMPOSSIBLE");
         
   }              
}       

Measured memory_bytes: 93820
#include<cstdio>
#include<algorithm>
using namespace std;
int a,b,c,d,e,f;
int main(){
	scanf("%d %d %d %d",&a,&b,&c,&d);
	e=min(a,b);
	f=min(c,d);
	printf("%d",e+f);
	return 0;
}

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

public class Main {
    private static Scanner in;

    private static String s, t;
    private static int[][] mem;

	public static void main(String[] args) {
        in = new Scanner(System.in);
        s = in.next();
        t = in.next();

        mem = new int[s.length()][t.length()];

        for(int i=0; i<mem.length; i++) Arrays.fill(mem[i], -1);

//        int ans = solve(0, 0);

        StringBuilder sb = new StringBuilder();

        int i=0;
        int j=0;

        while(i<s.length() && j<t.length()) {
            if (s.charAt(i)==t.charAt(j)) {
                sb.append(s.charAt(i));
                i++;
                j++;
            } else if (solve(i, j)==solve(i+1, j)) {
                i++;
            } else {
                j++;
            }
        }

        System.out.println(sb);


	}

    private static int solve(int i, int j) {
        if (i>=s.length() || j>=t.length()) {
            return 0;
        }

        if (mem[i][j]!=-1) return mem[i][j];

        int ans=0;

        if (s.charAt(i)==t.charAt(j)) {
            ans = 1+solve(i+1, j+1);
        } else {
            ans = Math.max(solve(i+1, j), solve(i, j+1));
        }

        return mem[i][j]=ans;
    }


}


Measured memory_bytes: 83916
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
#include<string>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<stack>
using namespace std;
#define ll long long
#define ull unsigned long long
#define up(i,a,b) for(register int i=(a);i<=(b);i++)
#define down(i,a,b) for(register int i=(a);i>=(b);i--)
#define mem(x,y) memset(x,(y),sizeof x)
#define ff first
#define ss second
#define mp(x,y) make_pair(x,y)
#define pb(x) emplace_back(x)
#define sc(a) scanf("%d",&a)
#define scl(a) scanf("%lld",&a)
#define scs(a) scanf("%s",a)
#define pr(a,b) printf("%d%c",a,b)
#define prl(a,b) printf("%lld%c",a,b)
#define PQ priority_queue
#define ld long double
#define all(v) v.begin(),v.end()
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)

typedef pair<int,int> pii;
typedef map<int,int> mii;
typedef vector<int> V;

mii m;
int a[100010];
pii p[100010];
int main() {
	IOS;
	int n,m;
	cin>>n>>m;
	up(i,1,n)cin>>a[i];
	up(i,1,m)cin>>p[i].ss>>p[i].ff;
	sort(a+1,a+1+n);
	sort(p+1,p+1+m,greater<pii>());
	
	int cur=1;
	up(i,1,n)
	if(p[cur].ff>a[i]){
		a[i]=p[cur].ff;
		p[cur].ss--;
		if(!p[cur].ss)cur++;
	}
	ll ans=0;
	up(i,1,n)ans+=a[i];
	cout<<ans;
	
}

Measured memory_bytes: 1536
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int k = sc.nextInt();
        Set<Integer> set = new TreeSet<>();
        for (int i = a ; i < k + a ; i++) {
            if (i <= b) {
                set.add(i);
            }
        }
        for (int i = b - k + 1 ; i <= b ; i++) {
            if (i >= a) {
                set.add(i);
            }
        }
        for (Integer x : set) {
            System.out.println(x);
        }
    }

}


Measured memory_bytes: 23252
import java.util.*;
import java.io.*;

public class Main{
    static class Reader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;
 
        public Reader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }
 
        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
 
        public int nextInt() {
            return Integer.parseInt(next());
        }
 
    }

    public static void main(String[] args) throws IOException{
        Reader in = new Reader(System.in);
        String a = in.next(), b= in.next();
        for(int i =0; i<a.length()+b.length(); i++){
            System.out.print((i%2 == 0? a.charAt(i/2): b.charAt(i/2)));
        }
    }
}


Measured memory_bytes: 22484
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
//const int N = 1000000;
const ll mod = 1000000007;
//using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int dh[8] = {0, 0, 1, 1, 1, -1, -1, -1};
const int dw[8] = {1, -1, 0, 1, -1, 0, 1, -1};
  
ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * (B / gcd(A, B));
}
using Edge = pair<int,int>;
using Graph = vector<vector<Edge>>;
Graph G;
  
/*------------------------------------------------------------------*/

int main(){
    int n, x, y; cin >> n >> x >> y;
    x--, y--;

    vector<vector<int>> dp(n, vector<int>(n));
    rep(i, n)rep(j, n) dp[i][j] = abs(i - j);

    rep(i, n){
        rep(j, n){
            dp[i][j] = min(dp[i][j], dp[i][x] + dp[y][j] + 1);
            dp[i][j] = min(dp[i][j], dp[i][y] + dp[x][j] + 1);
        }
    }
    vector<int> ans(n, 0);
    rep(i, n) _rep(j, i + 1, n) ans[dp[i][j]]++;
    _rep(i, 1, n) cout << ans[i] << endl;
}

Measured memory_bytes: 16000
n = int(input())
a = list(map(int, input().split()))
a4 = []
a2 = []
a1 = []
for i in range(n):
    if a[i] % 4 == 0:
        a4.append(a[i])
    elif a[i] % 2 == 0:
        a2.append(a[i])
    else:
        a1.append(a[i])
if len(a4) >= n//2:
    print("Yes")
elif len(a4) + len(a2)//2 >= n//2:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 19928
#include<iostream>
#include<stdio.h>
#include<string>
#include<algorithm>
#include<math.h>
#include<vector>
using namespace std;
#define INF 999999999
#define lint long long
#define rep(i, n) for(int i = 1; i <= (int)(n); i++)
#define rep0(i, n) for(int i = 0; i < (int)(n); i++)
int gcd(int a,int b){return b?gcd(b,a%b):a;}


int main(){
    lint N, A[100001], ans=0;
    cin >> N;
    rep(i, N){
        cin >> A[i];
        if(i%2==0){
            ans -= A[i];
        }
        else{
            ans += A[i];
        }
    }
    cout << ans << ' ';
    lint tmp;
    for (int i=2; i<=N; ++i){
        tmp = 2 * A[i-1] - ans;
        cout << tmp << ' ';
        ans = tmp;
    }
    return 0;
}

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

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
using ll = long long;
using ull = unsigned long long;
constexpr int MOD = 1000000007;

int mod(int x){
	return x % MOD;
}

ll gcd(ll a,ll b){
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b,a%b);
    }
}

int main(void)
{
    IOS
    ll a,b,c,d; cin >>a>>b>>c>>d;
    ll ans = b-a+1;
    a--;
    ll dc = b / c - a / c;
    ll dd = b / d - a / d;
    ll lcm = c*d / gcd(c,d);
    ll dcd = b / lcm - a / lcm;

    ans -= dc + dd - dcd;

    cout << ans << endl;

    return 0;
}


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

class Program
{
    static void Main()
    {
      	int a = int.Parse(Console.ReadLine());
		string b = Console.ReadLine();
		int c = 0;
		for(int i=0; i<a-2; i++)
		{
			if(b[i] == 'A' && b[i+1] == 'B' && b[i+2] == 'C') c++;
		}
      	Console.WriteLine(c);
    }
}


Measured memory_bytes: 27284
#include <algorithm>
#include <array>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#include <cassert>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using namespace std;

int main() {
    string S;
    cin >> S;

    // skip x
    string S2;
    for(auto c: S) {
        if(c != 'x') {
            S2 += c;
        }
    }

    // check 
    rep(i, S2.size()) {
        int h = i;
        int t = S2.size() - i - 1;
        if(h >= t)
            break;

        if(S2[h] != S2[t]) {
            cout << -1 << endl;
            return 0;
        }
    } 

    int ret = 0;
    int h = 0;
    int t = S.size() - 1;
    while(h < t) {
#if 0
                cout << h << " - " << t << endl;
                cout << S[h] << " - " << S[t] << endl;
#endif
        if(S[h] != S[t]) {
            if(S[h] == 'x') {
                ret++;
                h++;
            } 
            else if(S[t] == 'x') {
                ret++;
                t--;
            } else {
                assert(0);
            }
        } else {
            h++;
            t--;
        }
    }
    cout << ret << endl;

    return 0;
}



Measured memory_bytes: 3304
import sys

sys.setrecursionlimit(10**6)

h, w, k = map(int, input().split())
l = []
for i in range(h):
    l.append(input())

c = [0]*w
r = [0]*h

def count(hc, wc):
    ans = 0
    for i in range(h):
        for j in range(w):
            if l[i][j] == "#" and not ((hc >> i)%2 == 1 or (wc >> j)%2 == 1):
                ans += 1
    return ans

ans = 0
for i in range(2**h):
    for j in range(2**w):
        if count(i, j) == k:
            ans += 1
print(ans)

Measured memory_bytes: 68524
#include <bits/stdc++.h>
#include <string> 
using namespace std;
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mod 1000000007
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define fr(i,a,n) for(i=a;i<n;i++)
#define frn(i,a,n) for(i=a;i<=n;i++)
#define vll vector<ll>
#define pll pair<ll,ll>
#define vp vector<pll>
#define ub upper_bound
#define lb lower_bound
//#define map map<ll,ll>
#define mem(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(),v.end()
#define bs binary_search
#define qll queue<ll>
#define sll set<ll>
ll power(ll x,ll n)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return power(x*x,n/2);
    else                             //n is odd
        return x*power(x*x,(n-1)/2);
}

int main()
{
    fastio;
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    if(k<=a)
    {
        cout<<k<<endl;
    }
    else
    {
        if(k<=a+b)
        {
            cout<<a<<endl;
        }
        else
        cout<<a-(k-(a+b))<<endl;
    }
}

Measured memory_bytes: 3652
#include<stdio.h>
int min2(int a, int b){return a>b?b:a;}
int max2(int a, int b){return a<b?b:a;}
int n, i;
int a, min, max;
int main(void){
  min=1000000001;
  scanf("%d", &n);
  for(i=0; i<n; i++){
    scanf("%d", &a);
    min=min2(min, a);
    max=max2(max, a);
  }
  printf("%d\n", max-min);
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<ctime>
#include<set>
#include<map>
#include<queue>
#include<stack>
#define sqr(x) ((x)*(x))
#define fz1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define fd1(i,n) for ((i)=(n);(i)>=1;(i)--)
#define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++)
#define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--)
#define fz0k(i,n) for ((i)=0;(i)<(n);(i)++)
#define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;(i)--)
#define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++)
#define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--)
#define fzin fz1(i,n)
#define fzim fz1(i,m)
#define fzjn fz1(j,n)
#define fzjm fz1(j,m)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;}
#define inc(x,y) {x+=(y);if(x>=mod)x-=mod;}
#define dec(x,y) {x-=(y);if(x<0)x+=mod;}
using namespace std;
int n,m,i,j,f[100005],c[100005];
int main()
{
	scanf("%d%d",&n,&m);
	f[1]=1;
	fz1(i,n){
		c[i]=1;
	}
	fz1(i,m){
		int x,y;
		scanf("%d%d",&x,&y);
		c[x]--;c[y]++;
		if(f[x])f[y]=1;
		if(!c[x])f[x]=0; 
	}
	int s=0;
	fz1(i,n){
		s+=f[i];
	}
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long 
#define mp make_pair
#define pb push_back
# define pi 3.14159265358979323846
#define reus ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int32_t main()
{
	reus;
	int n,k,s=0,i;
	cin>>n>>k;
	int a[n];
	for(i=0;i<n;i++)
	cin>>a[i];
	sort(a,a+n);
	for(i=0;i<k;i++)
	{
		s+=a[i];
	}
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 3608
# include <bits/stdc++.h>
using namespace std;
# define F(i, s, t) for (int i = (s), _ = (t); i <= _; i ++)
# define LL long long
const int	N = 5e5, 
			P = 998244353;
int n, A, B, fac[N], inv[N], ifa[N], ans; LL K;
int C(int n, int m) {
	return 1LL * fac[n] * ifa[m] % P * ifa[n-m] % P;
}
int main() {
	scanf("%d %d %d %lld", & n, & A, & B, & K);
	fac[0] = 1;
	F(i, 1, n)
		fac[i] = 1LL * fac[i-1] * i % P;
	inv[1] = 1;
	F(i, 2, n)
		inv[i] = 1LL * (P - P / i) * inv[P % i] % P;
	ifa[0] = 1;
	F(i, 1, n)
		ifa[i] = 1LL * ifa[i-1] * inv[i] % P;
	F(x, 0, n)
		if ((K - 1LL * x * A) % B == 0) {
			long long y = (K - 1LL * x * A) / B;
			if (0 <= y && y <= n)
				ans = (ans + 1LL * C(n, x) * C(n, y)) % P;
		}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 4608
#include <iostream>
#include <vector>
#include <array>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <limits>

using namespace std;

typedef long long ll;

struct Op {
	ll b;
	ll c;
	
	bool operator>(const Op& other) const {
		return c > other.c;
	}
};

int main (int argc, char* argv[]) {
	int n, m;
	cin >> n >> m;

	priority_queue<ll, vector<ll>, greater<ll>> q;
	for (int i = 0; i < n; i++) {
		ll n;
		cin >> n;
		q.push(n);
	}

	vector<Op> ops(m);
	for (int i = 0; i < m; i++) {
		cin >> ops[i].b >> ops[i].c;
	}
	sort(ops.begin(), ops.end(), greater<Op>());

	for (const auto& op : ops) {
		for (int i = 0; i < op.b && q.top() < op.c; i++) {
			q.pop();
			q.push(op.c);
		}
	}

	ll res = 0;
	while (!q.empty()) {
		res += q.top();
		q.pop();
	}
	cout << res << endl;
}


Measured memory_bytes: 2676