akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
#define low lower_bound
#define upp upper_bound
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define Rep(i, n) for (int i = (int)(n); i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define cend printf("\n");
#define prique(T) priority_queue<T, vector<T>, greater<T>>
#define prique2(T) priority_queue<T>

struct edge { int to, cost; };
using P = pair<int, int>;
using D = pair<double, double>;
const long long mod = 998244353;
//const long long mod = 1e9 + 7, inf = 3e18;
const string sp = " ";

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

int modpow(int x, int n) {
	int ans = 1;
	while (n > 0) {
		if (n & 1) {
			ans *= x;
			if (mod <= ans) ans %= mod;
		}
		x *= x;
		if (mod <= x) x %= mod;
		n >>= 1;
	}
	return ans;
}

int fact[1000000];
void f_init(int n) {
	if (1000000 <= n) return;
	fact[0] = fact[1] = 1;
	for (int i = 2; i <= n; ++i) {
		fact[i] = i * fact[i - 1];
		if (mod <= fact[i]) fact[i] %= mod;
	}
	return;
}

int comb(int n, int r) {
	if (n < r) return 0;
	if (n == r) return 1;
	int ans = fact[n] * modpow(fact[n - r], mod - 2) % mod * modpow(fact[r], mod - 2);
	if (ans < 0) return ans + mod;
	return ans;
}

int nck[1010][1010];
void comb(int n) {
	rep(i, n + 1) {
		rep(j, i + 1) {
			if (j == 0 || i == j) nck[i][j] = 1;
			else nck[i][j] = nck[i - 1][j - 1] + nck[i - 1][j];
		}
	}
}

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

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

bool pri(int p) {
	for (int i = 2; i * i <= p; ++i) if (p % i == 0) return false;
	return p > 1;
}

map<int, int> factring(int n) {
	map<int, int>ans;
	for (int i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			n /= i;
			++ans[i];
		}
	}
	if (n != 1) ++ans[n];
	return ans;
}

double dis(D a, D b) { return sqrt((a.first - b.first) * (a.first - b.first) + (a.second - b.second) * (a.second - b.second)); }

int n, ma = 0, ans = 1;
int d[100010], a[100010];
signed main() {
	cin >> n;
	rep(i, n) {
		cin >> d[i];
		a[d[i]]++;
		ma = max(ma, d[i]);
	}
	if (d[0] != 0 || a[0] != 1) {
		cout << "0\n";
		return 0;
	}
	rep(i, ma + 1) {
		if (i == 0) continue;
		if (a[i] == 0) {
			cout << "0\n"; return 0;
		}
		ans *= modpow(a[i - 1], a[i]);
		ans %= mod;
	}
	cout << ans << endl;
}

Measured memory_bytes: 1792
/*	MASTER HAS FAILED MORE TIMES
	THAN BEGINNER HAS EVER TRIED
*/

#include <bits/stdc++.h>

using namespace std;

#define endl            '\n'
#define mem(a, n)       memset(a, n, sizeof(a))
#define repeat(i, n)    for(int i=0; i<n; i++)
#define Unique(n)       (n).erase(unique(all(n)), (n).end())
#define isPowerOfTwo(n) (n && !(n & (n - 1)))
#define NumofDigits(n)  ((int)log10(n)+1)
#define all(a)          a.begin(), a.end()

typedef long long ll;
typedef long double ld;

int sieve(int n);
unsigned long long pow(long long base, long long power);
long long gcd(long long a, long long b){ return a%b ? gcd(b, a%b) : b; }
long long lcm(long long a, long long b){ return a*b/gcd(a, b); }

void quicken(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); }
void file(){
    #ifdef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif /*ONLINE_JUDGE*/
}

int main(){
    quicken();

    int n; cin >> n;
    int arr[n], ok = 1;
    repeat(i, n){
        cin >> arr[i];
        if((arr[i]%2==0)
            && (arr[i]%3!=0 && arr[i]%5!=0)) ok = 0;
    }
    cout << (ok ? "APPROVED" : "DENIED");
    return 0;
}

unsigned long long pow(long long base, long long power){ /// mod?
    if(power==0) return 1;
    if(power==1) return base;

    unsigned long long ans = pow(base, power/2); /// mod?
    ans *= ans; /// ((ans%mod)*(ans%mod))%mod;

    if(power&1) return ans*base; /// ((ans%mod)*(base%mod))%mod;
    return ans;
}

int sieve(int n){
    int c = 0;
    vector<bool> isPrime(n+1, true);
    isPrime[0] = isPrime[1] = 0;

    for(long long i=2; i*i<=n; i++)
        if(isPrime[i])
            for(long long j=i*2; j<=n; j+=i)
                isPrime[j] = 0;
    repeat(i, n+1)
        if(isPrime[i]) c++;
    return c; /// primeCount [1:n]
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

int main(void) {
	int n,k,r;
	int h[100005],dp[100005];
	scanf("%d%d",&n,&k);
	for (int i=0;i<n;i++)scanf("%d",&h[i]);
	for (int i=0;i<n;i++)dp[i] = 1000000000;
	dp[1] = abs(h[1]-h[0]);
	dp[0]=0;
	
	for (int i=2;i<n;i++){
	    r = 0;
	    if (i-k>=0)r = i-k;
	    for (int j=r;j<i;j++){
	        if (dp[i]>dp[j]+abs(h[i]-h[j])) dp[i] = dp[j]+abs(h[i]-h[j]);
	    }
	}
	printf("%d\n",dp[n-1]);
	return 0;
}



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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
#define rep(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

ll INF = 1ll << 60;

void re(ll &cnt, vector<bool> used, vvl &per, ll dps){
  ll n = used.size()-1;
  rep(i, 0, n+1){
    if(used[i] == false)
      break;
    else if(i == n){
      cnt++;
      per[cnt] = per[cnt-1];
      return;
    }
  }
  
  rep(i, 1, n+1){
    if(used[i] == false){
      vector<bool> used_new = used;
      used_new[i] = true;
      per[cnt][dps] = i;
      re(cnt, used_new, per, dps+1);
    }
  }
}

int main(){
  ll n;
  cin >> n;
  vl p(n), q(n);
  rep(i, 0, n)
    cin >> p[i];
  rep(i, 0, n)
    cin >> q[i];
  
  vvl per(50000, vl(n,0));
  vector<bool> used(n+1, false);
  used[0] = true;
  ll cnt = 0;
  
  re(cnt, used, per, 0);
  
  ll a = 0, b = 0;
  
  rep(i, 0, 50000){
    if(per[i][0] == 0)
      continue;
    if(per[i] < p)
      a++;
    if(per[i] < q)
      b++;
  }
  
  cout << abs(a-b) << endl;
  
  return 0;
  
}

Measured memory_bytes: 9872
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <queue>
#include <map>

using namespace std;


int c1,c2,c3;


int main()
{
    long long t1,t2,a1,a2,b1,b2;
    scanf("%lld%lld%lld%lld%lld%lld",&t1,&t2,&a1,&a2,&b1,&b2);
    if (a1<b1){
        long long tmp;
        tmp=a1;a1=b1;b1=tmp;
        tmp=a2;a2=b2;b2=tmp;
    }
    if (a1*t1+a2*t2==b1*t1+b2*t2){
        printf("infinity\n");return 0;
    }

    if (a1*t1+a2*t2>b1*t1+b2*t2){
        printf("0\n");return 0;
    }

    long long tmp=a1*t1-b1*t1;
    long long tmp2=b1*t1+b2*t2 - a1*t1-a2*t2;
    //printf("y %lld %lld %lld\n",tmp,tmp2,tmp%tmp2);
    if (tmp>=tmp2 && tmp%tmp2==0){
        printf("%lld\n",2*tmp/tmp2);
    }
    else
        printf("%lld\n",2*(tmp/tmp2)+1);



}



Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main() {
	int w, a, b;
	cin >> w >> a >> b;
	if (b < a) {
		swap(a, b);
	}
	cout << max(b - a - w, 0) << endl;
	return 0;
}

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

static const int MAX = 100;
static const int INFTY = (1<<21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n,M[MAX][MAX];

void dijkstra(){
    int minv;
    int d[MAX],color[MAX];
    
    for(int i=0; i<n; i++){
        d[i] = INFTY;
        color[i] = WHITE;
    }
    
    d[0] = 0;
    //color[0] = GRAY;
    while (1) {
        minv = INFTY;
        int u = -1;
        for(int i=0; i<n; i++){
            if(minv > d[i] && color[i] != BLACK){
                u = i;
                minv = d[i];
            }
        }
        if(u==-1) break;
        color[u] = BLACK;
        for(int v=0; v<n; v++){
            if(color[v]!=BLACK && M[u][v]!=INFTY){
                if(d[v] > d[u] + M[u][v]){
                    d[v] = d[u]+M[u][v];
                    color[v] = GRAY;
                }
            }
        }
    }
    for(int i=0; i<n; i++){
        cout << i << " " << (d[i]==INFTY ? -1 : d[i]) << endl;
    }
}

int main(){
    cin >> n;
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            M[i][j] = INFTY;
        }
    }
    
    int k,c,u,v;
    for(int i=0; i<n; i++){
        cin >> u >> k;
        for(int j=0; j<k; j++){
            cin >> v >> c;
            M[u][v] = c;
        }
    }
    
    dijkstra();
}

Measured memory_bytes: 3112
#include<stdio.h>

int main(void) {
int n;
int count = 1;

scanf("%d", &n);
while (count < n) {
count++;
if (count % 3 == 0 || count % 10 == 3 || (count / 10) % 10 == 3 || (count / 100) % 10 == 3 || (count / 1000) % 10 == 3) {
printf(" %d", count);
}
}
printf("\n");

return (0);
}

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

int main(){
    int s;
    cin>>s;
    if(s>=400 && s<600)
        cout<<"8";
    else if(s>=600 && s<800)
        cout<<"7";
    else if(s>=800 && s<1000)
        cout<<"6";
    else if(s>=1000 && s<1200)
        cout<<"5";
    else if(s>=1200 && s<1400)
        cout<<"4";

    else if(s>=1400 && s<1600)
        cout<<"3";
    else if(s>=1600 && s<1800)
        cout<<"2";
    else if(s>=1800 && s<2000)
        cout<<"1";
    return 0;
}

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


using namespace std;
typedef long long ll;
const int MX=1e6+7;
const long double eps=-0.00000001;

vector <char> v;
int main()
{

    string s,ans;
    cin>>s;

    int l = s.length();

    for ( int i=0 ; i<l ; i++ )
    {
        if ( s[i]=='B' )
        {
            if ( i!=0 && !v.empty() ) { v.pop_back(); }
        }
        else v.push_back( s[i] );
    }

    for ( int i=0;i<v.size() ; i++ ) { cout<<v[i]; }


    return 0;
}


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

int n;
string x, y;
bool mat[1000][1000];
int a[1000][1000];

int max(int i, int j) {
	int r = (!mat[i - 1][j] ? a[i - 1][j] : 0);
	r = ((!mat[i][j - 1] && a[i][j - 1] > r) ? a[i][j - 1] : r);
	return r > a[i - 1][j - 1] ? r : a[i - 1][j - 1];
}

int main(){
	cin >> n;
	for (int ia = 0; ia < n; ia++) {
		int ans = 0, p = 0;
		cin >> x >> y;
		for (int i = 0; i < x.length(); i++) {
			mat[i][0] = x[i] == y[0] ? true : false;
			a[i][0] = mat[i][0] ? 1 : 0;
		}
		for (int i = 1; i < y.length(); i++) {
			mat[0][i] = x[0] == y[i] ? true : false;
			a[0][i] = mat[0][i] ? 1 : 0;
		}
		for (int i = 1; i < x.length(); i++) {
			for (int j = 1; j < y.length(); j++) {
				mat[i][j] = x[i] == y[j] ? true : false;
				a[i][j] = max(i, j) + (mat[i][j] ? 1 : 0);
				if (a[i][j] > p) p = a[i][j];
			}
		}
		if (a[x.length() - 1][0] > p) p = a[x.length() - 1][0];
		if (a[0][y.length() - 1] > p) p = a[0][y.length() - 1];
		cout << p << endl;
	}


	return 0;
}

Measured memory_bytes: 7932
/**
 * Given a set of string, where each one has a cost, this algorithm find
 * o cost of the concatenation of the sames (possibly using one string more
 * than once) that is a palindrome and has cost minimum
 * 
 * The algorithm maintains as vertices the remaining of string that did not
 * match yet and the side of this remaining. And in one interaction of
 * Dijkstra is do an attempt to insert a string on the opposite side and
 * then is calculated which is the new unmatch remaining.
 * 
 * Complexity:
 *          - Time : O(n ^ 2 * L * (L + lg (N * L)) ), where L is the size
 *               of the greater string of the input
 * 
 * Problem: https://atcoder.jp/contests/abc175/tasks/abc175_f
 */

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using is = pair<int, string>;
using lis = pair<ll, is>;

#define LEFT 1

map<is, ll> cost;
vector<is> strings;

bool isPalindrome(string& s, int ini, int fim){
    return ini > fim ? true : (s[ini] == s[fim] && isPalindrome(s, ini + 1, fim - 1));
}

ll dijkstra(){
    set<lis> q;
    string sFrom, sLeft, sRight;
    q.insert({0, {LEFT, ""}});
    int i, j;

    while(!q.empty()){
        ll dist = q.begin()->first;
        sFrom = q.begin()->second.second;
        bool side = q.begin()->second.first;
        q.erase(q.begin());

        if(side == LEFT)
            sLeft = sFrom;
        else
            sRight = sFrom;

        for(is p: strings){
            if (side == LEFT)
                sRight = p.second;
            else
                sLeft = p.second;
                
            bool good = true;
            for(i = 0, j = sRight.length() - 1; i < sLeft.size() && j >= 0; i++, j--)
                good &= sRight[j] == sLeft[i];

            if(good){
                string nxt;
                if (i < sLeft.size())
                    nxt = sLeft.substr(i);
                if (j >= 0)
                    nxt = sRight.substr(0, j + 1);

                ll dist2 = dist + p.first;
                bool sideNxt = i < sLeft.size() || nxt.empty();

                is pNxt = {sideNxt, nxt};
                if (!cost.count(pNxt)){
                    cost[pNxt] = dist2;
                    q.insert({dist2, pNxt});
                }else if(dist2 < cost[pNxt]){
                    q.erase({cost[pNxt], pNxt});
                    cost[pNxt] = dist2;
                    q.insert({dist2, pNxt});
                }
            }
        }
    }

    ll ans = LONG_LONG_MAX;

    for(auto p: cost){
        string s = p.first.second;
        if (isPalindrome(s, 0, (int)s.length() - 1))
            ans = min(p.second, ans);
    }

    if(ans == LONG_LONG_MAX)
        ans = -1;
    return ans;
}

int main(){
    cin.sync_with_stdio(0);
    cin.tie(0);
    int i, j, n;
    string s;
    ll c;
    
    cin >> n;
    strings.resize(n);

    for(i = 0; i < n; i++){
        cin >> s >> c;
        strings[i] = {c, s};
    }

    cout << dijkstra() << endl;
    return 0;
}

Measured memory_bytes: 3628
import java.util.HashMap;
import java.util.Scanner;

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

		for (int i = 0; i < N; i++) {
			int b = sc.nextInt();
			int c = a.get(b) == null ? 0 : a.get(b);
			a.put(b, (c + 1));
			if (a.get(b) == 2) {
				if (y <= x && x <= b) {
					y = x;
					x = b;
					a.put(b, 0);
				} else if (y <= x && y <= b && b <= x) {
					y = b;
					a.put(b, 0);

				}
			}
		}

		ans = x * y;
		
		System.out.println(ans);

		sc.close();
	}
}

Measured memory_bytes: 61492
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define pb push_back
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef vector<vector<P>> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<ll> vec;
const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
const int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30);
const int INF = (1LL << 60);
const double EPS = (1 >> 30);
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}


signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    int h,w;
    cin>>h>>w;
    char c[h][w];
    vvec g(h,vec (w));
    rep(i,h){
        rep(j,w){
            cin>>c[i][j];
        }
    }
    
    queue<T> Q;
    rep(i,h){
        rep(j,w){
            if(c[i][j]=='#'){
                Q.push(T(i,j,0));
                g[i][j]=1;
            }
        }
    }
    ll ans=0;
    while(Q.size()){
        int x,y,z;
        tie(x,y,z)=Q.front(); Q.pop();
        rep(i,4){
            x+=dx[i]; y+=dy[i];
            if(range(x,0,h)&&range(y,0,w)){
                if(g[x][y]==0){
                    g[x][y]=1;
                    Q.push(T(x,y,z+1));
                    chmax(ans,z+1);
                }
            }
            x-=dx[i]; y-=dy[i];
        }
    }
    cout<<ans<<endl;
    
    
    
    
}

Measured memory_bytes: 33332
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
//cout << setprecision(20) << 

int main() {
    ll A, B; cin >> A >> B;
    if (B % A == 0) cout << A + B << endl;
    else cout << B - A << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i32 = int32_t;
using i64 = int64_t;
constexpr char newl = '\n';

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; }
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
//#define F first
//#define S second
#define debug(x) cout << #x << ": " << x << '\n';
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#ifdef __GNUC__
// __builtin_popcount
// __builtin_popcountl
// __builtin_popcountll
constexpr auto popcount = __builtin_popcount;
#endif

// 一番右端の立っているビット位置を求める
// https://siokoshou.hatenadiary.org/entry/20090704/p1
struct GetNumberOfTrailingZeros {
  constexpr GetNumberOfTrailingZeros() : table() {
    uint64_t hash = 0x03F566ED27179461UL;

    for (int i = 0; i < 64; i++)
    {
      table[hash >> 58] = i;
      hash <<= 1;
    }
  }
  int Calc(int64_t x)
  {
    if (x == 0) return 64;

    uint64_t y = (uint64_t)(x & -x);
    int i = (int)((y * 0x03F566ED27179461UL) >> 58);
    return table[i];
  }
  int table[64];
};

#if 1

// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  GetNumberOfTrailingZeros gntz;

  int N;
  cin >> N;

  vector<i64> dp(1 << N, INT64_MIN);
  vector<i64> scores(1 << N, -1);

  dp[0] = scores[0] = 0;
  F0R(i, N) {
    int n = 1 << i;
    dp[n] = scores[n] = 0;
    F0R(j, N) {
      cin >> scores[n | (1 << j)];
    }
  }

  F0R(i, 1 << N) {
    if (scores[i] < 0) {

      int n = 1 << gntz.Calc(i);
      int b = i & ~n;
      i64 score = scores[b];

      FOR(j, 1, 99) {
        b >>= 1;
        if (b & 1) {
          score += scores[n | (1 << j)];
        }
      }
      scores[i] = score;
    }
  }

  auto dfs = [&](auto dfs, u16 U)->i64 {
    if (dp[U] > INT64_MIN) return dp[U];

    // 部分集合 U の部分集合を全て列挙
    // https://qiita.com/drken/items/7c6ff2aa4d8fce1c9361
    // ↑の#7

    i64 result = 0;

    for (int bit = U; bit; bit = (bit - 1) & U) {

      i64 score = scores[bit] + dfs(dfs, ~bit & U);
      chmax(result, score);
    }

    return dp[U] = result;
  };
  auto result = dfs(dfs, (1 << N) - 1);
  cout << result;
}
#endif


Measured memory_bytes: 1280
N=int(input())
D,X=map(int,input().split())
A=[]
for _ in range(N):
    A.append(int(input()))

sum=0
for i in range(N):
    num=0
    for j in range(N*D*2):
        if j*A[i]+1<=D:
            num+=1
        else:
            sum+=num
            break

print(sum+X)

Measured memory_bytes: 3064
import sys
input = sys.stdin.buffer.readline

def main():
    H,W = map(int,input().split())
    a = [list(map(int,input().split())) for _ in range(H)]
    
    ans = []
    for i in range(H):
        for j in range(W-1):
            if a[i][j]%2 != 0:
                a[i][j+1] += 1
                ans.append((i+1,j+1,i+1,j+2))
                
    for i in range(H-1):
        if a[i][-1]%2 != 0:
            a[i+1][-1] += 1
            ans.append((i+1,W,i+2,W))
            
    print(len(ans))
    for x in ans:
        print(*x)

if __name__ == "__main__":
    main()


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

typedef long long ll;
typedef pair<int,int> P;

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;}

const char newl = '\n';

struct SegmentTree {
private:
    int n;
    vector<int> node;
public:
    SegmentTree(vector<int> v) {
        int sz = v.size();
        n = 1;
        while (n < sz) n *= 2;
        node.resize(2*n-1,0);
        for (int i = 0;i < sz;++i) node[i+n-1] = v[i];
        for (int i = n-2;i >= 0;--i) node[i] = max(node[2*i+1],node[2*i+2]);
    }
    void update(int x,int val) {
        x += (n-1);
        node[x] = val;
        while (x > 0) {
            x = (x-1)/2;
            node[x] = max(node[2*x+1],node[2*x+2]);
        }
    }

    int getmax(int a,int b,int k = 0,int l = 0,int r = -1) {
        if (r < 0) r = n;
        if (r <= a || b <= l) return 0;
        if (a <= l && r <= b) return node[k];
        int vl = getmax(a,b,2*k+1,l,(l+r)/2);
        int vr = getmax(a,b,2*k+2,(l+r)/2,r);
        return max(vl,vr);
    }
};
vector<int> a,b,ans;
vector<vector<int>> edges;
SegmentTree seg(vector<int>(200010,0));

void dfs(int i,int p = -1) {
    int x = seg.getmax(b[i],b[i]+1);
    seg.update(b[i],seg.getmax(0,b[i])+1);
    ans[i] = seg.getmax(0,200010);
    for (int j : edges[i]) if (j != p) {
        dfs(j,i);
    }
    seg.update(b[i],x);
}

int main() {
    int n;
    cin >> n;
    a.resize(n);
    b.resize(n);
    ans.resize(n);
    edges.resize(n);
    for (int i = 0;i < n;++i) cin >> a[i];
    map<int,int> mp;
    for (int i = 0;i < n;++i) mp[a[i]];
    {
        int i = 0;
        for (auto& p : mp) p.second = i++;
        for (int j = 0;j < n;++j) b[j] = mp[a[j]];
    }
    for (int i = 0;i < n-1;++i) {
        int u,v;
        scanf("%d%d",&u,&v);
        u--;v--;
        edges[u].push_back(v);
        edges[v].push_back(u);
    }
    dfs(0);
    for (int i = 0;i < n;++i) cout << ans[i] << newl;
}

Measured memory_bytes: 53196
#include <stdio.h>

#define MAX 101 

int T[MAX][MAX];

int main()
{
  int n,i,j,youso,kazu,v;

  scanf("%d",&n);

  for(i=1;i<=n;i++)
    {
      scanf("%d%d",&youso,&kazu);

      for(j=0;j<kazu;j++)
	{
	  scanf("%d",&v);

	  T[i][v]=1;
	}
    }

  for(i=1;i<=n;i++)
    {
      for(j=1;j<=n;j++)
	{
	  if(j!=n)printf("%d ",T[i][j]);
	  else printf("%d\n",T[i][j]);
	}
    }
  return 0;
}



Measured memory_bytes: 2052
import numpy as np


def gcd(a, b):
    while b > 0 :
        a, b = b, a%b

    return a


K = int(input())
ans = 0
for a in range(1,K+1):
    for b in range(1,K+1):
        g = gcd(a, b)
        for c in range(1,K+1):
            ans += gcd(c, g)

print(ans)

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

int main() {
  vector<int> c(11, 0);
  for (int i = 0; i < 3; i++) {
    int a;
    cin >> a;
    c[a]++;
  }
  string ans = (c[5] == 2 && c[7] == 1) ? "YES" : "NO";
  cout << ans << endl;
  return 0;
}

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

int main(void){
    int n,x;
    cin >> n >> x;
    
    int w[n],v[n];
    for(int i = 0;i < n;i++)cin >> w[i] >> v[i];
    
    ll dp[n+1][x+1];
    memset(dp,0,sizeof(dp));
    
    for(int i = 0;i < n;i++){
        for(int j = 0;j <= x;j++){
            if(j >= w[i]){
                dp[i+1][j] = max(dp[i+1][j],dp[i][j-w[i]]+v[i]);
            }
            dp[i+1][j] = max(dp[i+1][j],dp[i][j]);
        }
    }
    cout << dp[n][x] << endl;
}

Measured memory_bytes: 82408
N=int(input())
S=list(map(int,input().split()))
first=len(S)
count=0
pos=0
mokuteki=1
block=0
while count<N:
    if S[pos]!=mokuteki:
        pos+=1
        block+=1
    else:
        mokuteki+=1
        pos+=1
    count+=1

if mokuteki>1:
    print(block)
else:
    print(-1)

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

using namespace std;
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

ll f(ll k) {
    ll now = 1;
    ll n = 1;
    ll sum = 0;
    while(now <= k) {
        ll mi = now, ma = min(now * 10 - 1, k);
        ll fizz = ma / 3 - (mi - 1) / 3;
        ll buzz = ma / 5 - (mi - 1) / 5;
        ll fizzbuzz = ma / 15 - (mi - 1) / 15;

        ll num = n * (ma - mi + 1 - (fizz + buzz - fizzbuzz));
        sum += 4 * fizz + 4 * buzz + num;
        now *= 10;
        n++;
    }
    return sum;
}

string g(ll i) {
    if (i % 15 == 0) return "FizzBuzz";
    if (i % 5 == 0) return "Buzz";
    if (i % 3 == 0) return "Fizz";
    return to_string(i);
}

void solve() {
    ll N;
    cin >> N;
    
    for (int i = 0; i < 20; i++) {
        ll ng = 0, ok = 1e18 + 1;
        while(ok - ng > 1) {
            ll c = (ok + ng) / 2;
            if (f(c) >= N + i) {
                ok = c;
            } else {
                ng = c;
            }
        }
        cout << g(ok)[N + i - f(ng) - 1];
    }
    cout << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}





Measured memory_bytes: 3292
#include<bits/stdc++.h>
using namespace std;
int arr[100];
int main()
{

    int n,a,c,c1;
    c1=0;
    c=0;
    for(int i=0;i<8;i++)
    {
        arr[i]=0;
    }
    cin>>n;
    for (int i=0;i<n;i++ )
    {
        cin>>a;
        if(a<=399){arr[0]=1;}
        else if(a<=799){arr[1]=1;}
        else if(a<=1199){arr[2]=1;}
        else if(a<=1599){arr[3]=1;}
        else if(a<=1999){arr[4]=1;}
        else if(a<=2399){arr[5]=1;}
        else if(a<=2799){arr[6]=1;}
        else if(a<=3199){arr[7]=1;}
        else{c++;}
    }
    for(int i=0;i<8;i++)
    {
        if(arr[i]==1){c1++;}
    }

    if(c1==0&&c!=0){
        c+=c1;
            c1=1;

    }
else{c+=c1;}



cout<<c1<<" "<<c<<endl;


return 0;

}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,x); REP(i,sizeof(a)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}

int main(){
  int N,M; cin>>N>>M;
  int count = 0;
  int a[101];
  int x = 0;
  REP(i,N){
    cin >>a[i];
    x += a[i];
  }
  
  REP(i,N){
    if(a[i]*M*4>=x){++count;}
  }
  cout << (count>=M?Liny:Linn);
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 9999999999999999;
using ll = long long;
int main(){
  int N;
  cin>>N;
  string s;
  cin>>s;
  if(N>=3200){
    cout << s << endl;
  }
  else{
    cout << "red" << endl;
  }
  return 0;
}

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

namespace abc144_a
{
    class Program
    {
        public static string hantei(int x, int y)
        {
            string N = "";
            if(x >= 10)
            {
                N = "-1";
            }else if(y >= 10)
            {
                N = "-1";
            }
            else
            {
                int sum = x * y;
                N = sum.ToString();
            }
            return N;
        }
        static void Main(string[] args)
        {
            string[] N = Console.ReadLine().Split(' ');
            int A = int.Parse(N[0]);
            int B = int.Parse(N[1]);

            Console.WriteLine(hantei(A, B));
            Console.Read();
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
using LP=pair<ll,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;



int main() {
    int N;
    cin>>N;
    vector<int> A(N);
    rep(i,N){cin>>A.at(i);}
    sort(A.begin(),A.end());
    vector<int> plus(0),minus(0);
    rep(i,N){
        if(i==0){
            minus.pb(A.at(i));
        }
        else if(i==N-1){
            plus.pb(A.at(i));
        }
        else{
            if(A.at(i)>0)plus.pb(A.at(i));
            else minus.pb(A.at(i));
        }
    }
    ll ans=0;
    rep(i,sz(plus)){
        ans+=plus.at(i);
    }
    rep(i,sz(minus)){
        ans-=minus.at(i);
    }
    cout<<ans<<endl;
    int pp=1;
    while(pp<sz(plus)){
        cout<<minus.at(0)<<" "<<plus.at(pp)<<endl;
        minus.at(0)-=plus.at(pp);
        pp++;
    }
    rep(i,sz(minus)){
        cout<<plus.at(0)<<" "<<minus.at(i)<<endl;
        plus.at(0)-=minus.at(i);
    }
}

Measured memory_bytes: 4332
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pull = pair<ull, ll>;
using pis = pair<int, string>;
#define INF 1000000000
#define LLINF 10000000000000000ll
#define MOD 1000000007LL

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int h, w, k;
  cin >> h >> w >> k;
  vector<string> field(h);
  for (int i = 0; i < h; i++) cin >> field[i];

  int ans = 0;
  for (int i = 0; i < (1<<h); i++) {
    for (int j = 0; j < (1<<w); j++) {
      int temp = 0;
      for (int a = 0; a < h; a++) {
        for (int b = 0; b < w; b++) {
          if (((i>>a)&1) && ((j>>b)&1) && (field[a][b]=='#')) temp++;
        }
      }
      if (temp == k) ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,NAME,...) NAME
#define pr(...) GET_MACRO(__VA_ARGS__,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)
#define pr1(a) (#a)<<"="<<(a)
#define pr2(a,b) pr1(a)<<", "<<pr1(b)
#define pr3(a,b,c) pr2(a,b)<<", "<<pr1(c)
#define pr4(a,b,c,d) pr3(a,b,c)<<", "<<pr1(d)
#define pr5(a,b,c,d,e) pr4(a,b,c,d)<<", "<<pr1(e)
#define int long long
#define double long double
using namespace std;
const int N = 100010;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
typedef pair<int,int> P;
typedef long long ll;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
ostream& operator<<(ostream& o,vector<auto> &a){int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
void prArr(auto a,string s=" "){int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}

bool isPrime(ll n){
  for(ll i=2;i*i<=n;i++)if(n%i==0) return 0;
  return 1;
}

int n;
vector<int> A;

int mem[N],used[N];

bool check(int i,int j){return A[i] < A[j];}

int dfs(int idx){
  if(idx > n) return 0;
  if(idx == n) return 1;
  if(used[idx]++) return mem[idx];
  
  int num = A[idx];
  if(!isPrime(num)) return mem[idx] = 0;
  
  int res = 0;
  if(check(idx,idx+1)) res = (res + dfs(idx+1)) % mod;
  if(check(idx,idx+2)) res = (res + dfs(idx+2)) % mod;
  return mem[idx] = res;
}

signed main(){
  cin>>n;
  A.resize(n);
  cin>>A;
  
  A.push_back(1e9);
  A.push_back(1e9);

  int ans = dfs(0);
  cout<<ans<<endl;
  
  return 0;
}



Measured memory_bytes: 7276
#include<bits/stdc++.h>
using namespace std;
using lli = long long;
#define rep(i,n) for(int i=0;i<n;i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

string s;

int main(void){
    cin >> s;
    stack<char> st;
    lli ans = s.size();
    rep(i, s.size()){
        if(s[i] == 'S'){
            st.push('S');
        }else if(s[i] == 'T'){
            if(!st.empty() && st.top() == 'S'){
                ans-=2;
                st.pop();
            }else st.push('T');
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3724
# include <bits/stdc++.h>
# define speed ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
# pragma GCC target("avx2")
# pragma GCC optimize("O3")
# pragma GCC optimize("unroll-loops")
# define int long long

using namespace std;

const int N = 1e3 + 7;
const int mod = 1e9 + 7;

int dp[N][N];
string a[N];

int32_t main() {
    speed;
    int n, m;
    cin >> n >> m;
    for ( int i = 1; i <= n; i++ ) {
        cin >> a[i];
        a[i] = '#' + a[i];
    }
    dp[1][1] = 1;
    for ( int i = 1; i <= n; i++ ) {
        for ( int j = 1; j <= m; j++ ) {
            if ( i == 1 && j == 1 || a[i][j] == '#' ) {
                continue;
            }
            if ( i > 1 && a[i - 1][j] == '.' ) {
                dp[i][j] += dp[i - 1][j];
            }
            if ( j > 1 && a[i][j - 1] == '.' ) {
                dp[i][j] += dp[i][j - 1];
            }
            dp[i][j] %= mod;
        }
    }
    cout << dp[n][m];
}


Measured memory_bytes: 12472
n, m = map(int, input().split())
ab = []
for i in range(n):
    AB = list(map(int, input().split()))
    ab.append(AB)
x = 0
val = 0
ab.sort(key=lambda x:x[0])
for i in range(n):
    x += ab[i][1]
    val += ab[i][0]*ab[i][1]
    if x < m:
        continue
    else:
        val = val - ab[i][0]*(x - m)
        break
print(val)

Measured memory_bytes: 28480
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>

int main() {

    char s[100001];
    scanf("%s", s);

    int l = strlen(s);
    printf("%c%d%c",s[0],l-2,s[l-1]);
    

    return 0;

}


Measured memory_bytes: 128
#[allow(unused_imports)]
use std::cmp;
use std::io::Write;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    let s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

  ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
    let $var = read_value!($iter, $t);
    input_inner!{$iter $($r)*}
  };
}

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

  ($iter:expr, [ $t:tt ; $len:expr ]) => {
    (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  };

  ($iter:expr, chars) => {
    read_value!($iter, String).chars().collect::<Vec<char>>()
  };

  ($iter:expr, usize1) => {
    read_value!($iter, usize) - 1
  };

  ($iter:expr, $t:ty) => {
    $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}

fn main() {
  let out = std::io::stdout();
  let mut out = std::io::BufWriter::new(out.lock());
  macro_rules! puts {
    ($($format:tt)*) => (write!(out,$($format)*).unwrap());
  }
  input! {
    n: usize,
    aa: [i64; n],
  }
  let mut r0 = 0;
  for (i, &a) in aa.iter().enumerate() {
    if i % 2 == 0 {
      r0 += a;
    } else {
      r0 -= a;
    }
  }
  r0 /= 2;

  puts!("{} ", r0 * 2);
  for &a in aa.iter().take(n-1) {
    r0 = a - r0;
    puts!("{} ", r0 * 2);
  }
  puts!("\n");
}


Measured memory_bytes: 7420
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <atcoder/fenwicktree>

using std::cin;
using std::cout;
using std::endl;
using std::terminate;
using atcoder::fenwick_tree;

void solve() {
    int N, Q; cin >> N >> Q;
    fenwick_tree<long> fe(N);

    for (int i = 0; i < N; ++i) {
        long a; cin >> a;
        fe.add(i, a);
    }

    for (int i = 0; i < Q; ++i) {
        long t; cin >> t;
        if (t == 0) {
            long p, x; cin >> p >> x;
            fe.add(p, x);
        } else if (t == 1) {
            int l, r; cin >> l >> r;
            cout << fe.sum(l, r) << endl;
        }
    }
}

int main() {

#ifdef DEV
    std::ifstream in("input");
    cin.rdbuf(in.rdbuf());

    int t; cin >> t;
    for (int x = 1; x <= t; ++x) {
        solve();
    }
#else
    solve();
#endif

    return 0;
}


Measured memory_bytes: 8228
#include <iostream>
#include <vector>
#include <string.h>
#include <set>
#include <map>
#include <unordered_map>
#include <assert.h>
#include <algorithm>
#include <queue>
#include <bitset>
#include <stack>
#include <chrono>
#include <random>
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define ll long long
#define INF 1000000000000000000
#define MOD 1000000007
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define uid uniform_int_distribution <int>
using namespace std;

int sz = 1000;
using PIII = pair<pair<int, int>, int>;
const int N = 5 * 100 * 1000 + 4;
PIII p[N];
int res = 0;
vector<int> cnt(N);
bool cmp(PIII x, PIII y) {
	if (x.ff.ff / sz != y.ff.ff / sz)
		return x.ff.ff < y.ff.ff;
	else
		return x.ff.ss < y.ff.ss;
}
void add(int x) {
	if (cnt[x] == 0)
		res++;
	cnt[x]++;
}
void remove(int x) {
	if (cnt[x] == 1)
		res--;
	cnt[x]--;
}
int main() {
	int n, q;
	cin >> n >> q;
	vector<int> A(n);
	for (int i = 0; i < n; i++) {
		cin >> A[i];
	}
	for (int i = 0; i < q; i++) {
		cin >> p[i].ff.ff >> p[i].ff.ss;
		p[i].ss = i;
	}
	sort(p, p + q, cmp);
	vector<int> ans(q);
	int l = 0, r = -1;
	for (int i = 0; i < q; i++) {
		int L = p[i].ff.ff - 1;
		int R = p[i].ff.ss - 1;
		//cout << l << "  " << r << "\n";
		while (l < L) remove(A[l]), l++;
		while (l > L) l--, add(A[l]);
		while (r < R) r++, add(A[r]);
		while (r > R) remove(A[r]), r--;
		ans[p[i].ss] = res;
	}
	for (int i = 0; i < q; i++) {
		cout << ans[i] << "\n";
	}
}


Measured memory_bytes: 15500
#include<bits/stdc++.h>
using namespace std;
int res[100050],N;

int unchi(int n){
    if(n==0)return 0;
    if(res[n])return res[n];
    int ret=n; // ぜんぶ1円で払ったとき
    for(int sx=1; sx<=n; sx*=6)ret=min(ret,unchi(n-sx)+1); // 1~nの6のべき乗sx円1回引き出した＋残りの金額の回数　の最小値
    for(int nn=1; nn<=n; nn*=9)ret=min(ret,unchi(n-nn)+1); // うえと同様
    res[n]=ret;
    return ret;
}

int main(){
    cin>>N;
    for(int i=0;i<100050;i++)res[i]=0;
    cout<<unchi(N)<<endl;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
using P = pair<int,int>;
using pq = priority_queue<int>;
typedef long long ll;
string yes = "Yes";
string no = "No";

int  main()
{
	int a,b; cin >> a >> b;
	if (a*b % 2)
		cout << "Odd";
	else
		cout << "Even";
	return (0);
}

Measured memory_bytes: 256
"""
「A 以上 B 以下の整数のうち〜を満たすものの個数を求めよ」という問題では
(B 以下の整数のうちの〜を満たすものの個数) から
(A-1 以下の整数のうちの〜を満たすものの個数) を引く

- (全体)
+ (C の倍数の個数)
+ (D の倍数の個数)
- (C の倍数でも D の倍数でもあるものの個数)
"""

A,B,C,D = list(map(int, input().split()))

def gcd(a,b):
  if b==0:
    return a
  else:
    return gcd(b,a%b)
  
def u(n,C,D):
  return int(n - n//C - n//D + n//(C//gcd(C,D)*D))

print(u(B,C,D)-u(A-1,C,D))



Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>
#define maxn 100005

int main() {
	char s[maxn];
	int a, b, i, n, count = 1;
	scanf("%d", &n);
	for (b = 1; b <= n; b++) {
		scanf(" %c", &s[b]);
	}
	for (i = 1; i <= n - 1; i++) {
		if (s[i] != s[i + 1])
			count++;
	}
	printf("%d", count);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#define pb push_back
typedef long long int ll;
using namespace std;
map<char,ll> ind;
int save[100005][3];
vector<char> res;
char s[100005][2];
int main(){
  int  N;
  cin>>N>>ind['A']>>ind['B']>>ind['C'];
  for(int i=0; i<N; i++) cin>>s[i];
  save[N][0]=save[N][1]=save[N][2]=N;
  for(int i=N-1; i>=0; i--){
    if(s[i][0]=='A' || s[i][1]=='A') save[i][0]=i;
    else save[i][0]=save[i+1][0];
    if(s[i][0]=='B' || s[i][1]=='B') save[i][1]=i;
    else save[i][1]=save[i+1][1];
    if(s[i][0]=='C' || s[i][1]=='C') save[i][2]=i;
    else save[i][2]=save[i+1][2];
  }
  for(int i=0; i<N; i++){
    if(ind[s[i][0]]==ind[s[i][1]] && ind[s[i][0]]==0){
      cout<<"No"<<endl;
      return 0;
    }
    else if(ind[s[i][0]]!=0 && ind[s[i][1]]==0){
      ind[s[i][0]]--;
      ind[s[i][1]]++;
      res.pb(s[i][1]);
    }
    else if(ind[s[i][1]]!=0 && ind[s[i][0]]==0){
      ind[s[i][1]]--;
      ind[s[i][0]]++;
      res.pb(s[i][0]);
    }
    else if(ind[s[i][0]]==1 && ind[s[i][1]]>1){
      ind[s[i][0]]++;
      ind[s[i][1]]--;
      res.pb(s[i][0]);
    }
    else if(ind[s[i][1]]==1 && ind[s[i][0]]>1){
      ind[s[i][1]]++;
      ind[s[i][0]]--;
      res.pb(s[i][1]);
    }
    else if(ind[s[i][1]]==1 && ind[s[i][0]]==1){
      if(save[i+1][s[i][0]-'A']<save[i+1][s[i][1]-'A']){
        ind[s[i][1]]--;
        ind[s[i][0]]++;
        res.pb(s[i][0]);
      }
      else{
        ind[s[i][0]]--;
        ind[s[i][1]]++;
        res.pb(s[i][1]);
      }
    }
    else{
      ind[s[i][0]]--;
      ind[s[i][1]]++;
      res.pb(s[i][1]);
    }
  }
  cout<<"Yes"<<endl;
  for(int i=0; i<res.size(); i++) cout<<res[i]<<endl;
  return 0;
}


Measured memory_bytes: 5104
from math import factorial
n,k=[int(_) for _ in input().split()]
mod=10**9+7
c=0
for i in range(1,min(n-k+2,k+1)):
    print((factorial(k-1)//factorial(i-1)//factorial(k-i))*(factorial(n-k+1)//factorial(i)//factorial(n-k-i+1))%mod)
    c+=1
for i in range(k-c):print(0)

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

using namespace std;

typedef long long ll;

string s;
ll N;

int main(){
    cin >> s;
    N = s.size();
    ll count = 0;
    ll p = 0;
    ll ans = 0;
    while(p < N-2){
        if(s[p] == 'A' && s[p+1] == 'B' && s[p+2] == 'C'){
            ans += count + 1;
            s[p+2] = 'A';
            p += 2;
            continue;
        }
        if(s[p] == 'A') count++;
        else count = 0;
        p++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

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 long long INF = 1LL << 60;

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

  int ia, iz;
  bool found = false;
  rep(i, s.size()){
    if(!found && s[i] == 'A'){
      ia = i;
      found = true;
    }
    if(s[i] == 'Z') iz = i;
  }

  cout << iz - ia + 1 << endl;

  return 0;
}


Measured memory_bytes: 640
from functools import lru_cache
@lru_cache(maxsize=None)

def power(a, b):
    res = 1
    # print(a, b)
    if b > 0:
        res = power(a, b // 2)
        if b % 2 == 0:
            res = (res * res) % 1000000007
        else:
            res = (((res * res) % 1000000007) * a) % 1000000007
    
    return res
    
m, n = map(int, input().split())

print(power(m, n))


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

int main(){
    int n;
    cin >> n;
    cout << n*n*n << endl;
}

Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define all(obj) obj.begin(), obj.end()
#define db(x) cerr << #x << ":" << x << " "
#define dbl(x) cerr << #x << ":" << x << "\n"
#define dbv(vec) cerr << #vec << ":"; for (auto e : vec) cerr << e << " "; cout << "\n"
#define dbvv(vv) cerr << #vv << ":\n"; for (auto vec : vv) { for (auto e : vec) cerr << e << " "; cerr << endl; }
#define YN(f) cout << (f ? "YES" : "NO") << endl
#define Yn(f) cout << (f ? "Yes" : "No") << endl
#define yn(f) cout << (f ? "yes" : "no") << endl
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;

int main() {
	int N, L; cin >> N >> L;
	vector<string> v;
	rep(i, N) {
		string s; cin >> s;
		v.push_back(s);
	}
	sort(all(v));
	rep(i, N) {
		cout << v.at(i);
	}
	cout << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int main() {
    long long X;
    cin>>X;
    //cin>>A>>B;
    int count=0;
    long double nX=100;
    
    while((long long)nX<X){
      long double profit=nX*0.01;
      //cout<<"利子は"<<floor(profit)<<endl;
      nX+=floor(profit);
      count++;
    }
    
    cout<<count<<endl;
    
    return 0;
}

Measured memory_bytes: 3640
import java.util.Scanner;

public class Main {
    public static Scanner sc;
    public static void main(String[] args) throws Exception {
        sc = new Scanner(System.in);
        
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        int e = sc.nextInt();
        
        int p = a > b ? c > b ? b : c : c > a ? a : c;
        int j = d > e ? e : d;
        
        System.out.println(p + j - 50);
    }
}

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

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

Measured memory_bytes: 1024