akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	int h,w,min=mod;
	cin>>h>>w;
	if(h%3==0||w%3==0)cout<<0<<endl;
	else{
	if(h<w)swap(h,w);
	int th=h,tw=w;
	long a1=h/3;
	if(h%3==2)a1++;
	h-=a1;
	a1*=w;
	FOR(i,0,2){
		if(i==1){
			h=tw;
			w=th;
			a1=h/3;
			if(h%3==2)a1++;
			h-=a1;
			a1*=w;
		}

	long a2,a3;
	if(w%2==0||h%2==0){
			a2=(long)h*w/2;
			a3=a2;
			//cout<<h<<w<<a1<<endl;
	}else{
	if(h<w)swap(h,w);
	//cout<<h<<w<<a1<<endl;
	a2=h/2;
	h-=a2;
	a2*=w;
	a3=(long)h*w;
	}
	if(a1<a2)swap(a1,a2);
	if(a2<a3)swap(a2,a3);
	if(a1<a2)swap(a1,a2);
	if(min>a1-a3)min=a1-a3;
}
	//cout<<a1<<a2<<a3<<endl;
	cout<<min<<endl;
}
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <map>
#define div 1000000000+7
using namespace std;
typedef long long ll;

int main(){
    string s ;
    cin >> s;
    if(s == "a" || s == "i" || s == "u" || s == "e" || s == "o"){
        cout << "vowel" << endl;
    } else {
        cout << "consonant" << endl;
    }
    return 0;
}


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

int zero(int x,int a);

int main(void){
    // Your code here!
    int X,A,B,N;
    string s;
    
    cin >> X >> A >> B >> N;
    
    for(int i=0;i<N;i++){
        cin >> s;
        if(s == "nobiro")
            X = zero(X,A);
        else if(s == "tidime")
            X = zero(X,B);
        else if(s == "karero")
            X = 0;
    }
    
    cout << X << endl;
}

int zero(int x,int a){
    if((x+a)<0)
        return 0;
    else 
        return x+a;
}


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

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

    vector<int> L(M), R(M);
    for(int i = 0; i < M; ++i){
        cin >> L[i] >> R[i];
    }

    vector<int> cnt(100010, 0);
    for(int i = 0; i < M; ++i){
        ++cnt[L[i]];
        --cnt[R[i]+1];
    }

    for(int i = 1; i < cnt.size(); ++i){
        cnt[i] += cnt[i-1];
    }

    cout << count(begin(cnt), end(cnt), M) << endl;
}

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>
#define Graph vector<vector<int>>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

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


void func(std::string S, std::string T){

}

int main(){

    std::string S;
    std::cin >> S;
    std::string T;
    std::cin >> T;

    ll count = 0;

    for(ll i = 0; i < S.size(); i++){
        if(S.at(i)!=T.at(i)){
            count++;
        }
    }

    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3864
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <cstdint>
#include <iomanip>
#include <set>
using ll = long long;
#define fast_io(); std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);

int main(){
    int n; std::cin>> n;
    std::set<int> a;
    for(int i=0; i<n; i++){
        int ai; std::cin >> ai;
        if(!a.erase(ai)) a.insert(ai);
    }

    std::cout << a.size() << "\n";
    return 0;
}


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

#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define FOR(i,n,m) for (ll i=n; i<(ll)(m); i++)
#define pb push_back
#define INF 1000000007LL
#define all(a) (a).begin(),(a).end()

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

int dy[4]={-1,1,0,0};
int dx[4]={0,0,1,-1};

ll H,W,N;

unordered_map<int, unordered_map<int, bool> > board;
unordered_map<int, unordered_map<int,bool> > checked;
ll ans[10];
int main(){
    ios::sync_with_stdio(false);
    cin >> H >> W >> N;
    vector<p> vec;
    
    REP(i,N) {
        int x,y;
        cin >> y >> x;
        vec.pb(p(x,y));
        board[x][y]=1;
    }
    
    int num = 0;
    REP(i,N) {
        int x,y;
        x = vec[i].first;
        y = vec[i].second;
        for (int tx=x-2; tx<=x; tx++) {
            for (int ty=y-2; ty<=y; ty++) {
                if(tx<1 || ty<1) continue;
                if(W<tx+2 || H<ty+2) continue;
                if(checked[tx][ty]) continue;
                int cnt=0;
                for(int ttx=tx;ttx<=tx+2;ttx++) for(int tty=ty;tty<=ty+2;tty++) {
                    if(board[ttx][tty]) cnt++;
                }
                ans[cnt]++;
                num++;
                checked[tx][ty]=true;
             }
        }
    }
    ans[0] = (W-2)*(H-2)-num;
    REP(i,10) {
        cout << ans[i] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 238824
import java.util.*;

class Main {
    public static void main (String [] args) {

        Scanner sc = new Scanner(System.in);

        int [] test = new int[5];
        for(int x = 0; x < 5; x++) {
            test[x] = sc.nextInt();
        }
        Arrays.sort(test);

        System.out.printf("%d %d %d %d %d\n", test[4], test[3], test[2], test[1], test[0]);
    }

}

Measured memory_bytes: 12000
#include <iostream>
#include <algorithm>

using namespace std;

const int N = 100;

int main(void){
    int in[N] = { 0 };
    for(int n; cin >> n; in[n - 1] ++);

    for(int *p = max_element(in, in + N), result = *p; *(p = max_element(in, in + N)) == result; cout << int(p + 1 - in) << endl) *p = -1;
    
    return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>

using namespace std;
static const int MAX = 100;

void trace(int a[], int n) {
    for (int i = 0; i < n; i++) {
        if (i > 0) cout << " ";
        cout << a[i];
    }
    cout << endl;
}

// selection sort
int main() {
    int n, counter = 0, r[MAX];
    cin >> n;
    for (int i = 0; i < n; i++) cin >> r[i];

    for (int i = 0; i < n - 1; i++) {
        int minj = i;
        for (int j = i; j < n; j++) {
            if (r[j] < r[minj]) minj = j;
        }
        swap(r[i], r[minj]);
        if (i != minj) counter++;
    }

    trace(r, n);
    cout << counter << endl;
    return 0;
}



Measured memory_bytes: 3088
// Problem : A - Takahashikun, The Strider
// Contest : AtCoder - AtCoder Grand Contest 046
// URL : https://atcoder.jp/contests/agc046/tasks/agc046_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/*⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣠⣶⡾⠏⠉⠙⠳⢦⡀⠀⠀⠀
⠀⠀⠀⣴⠿⠏⠀⠀⠀⠀⠀⠀⢳⡀⠀
⠀⠀⢠⣟⣋⡀⢀⣀⣀⡀⠀⣀⡀⣧⠀
⠀⠀⢸⣯⡭⠁⠸⣛⣟⠆⡴⣻⡲⣿⠀
⠀⠀⣟⣿⡭⠀⠀⠀⠀⠀⢱⠀⠀⣿⠀
⠀⠀⠙⢿⣯⠄⠀⠀⠀⢀⡀⠀⠀⡿⠀⠀
⠀⠀⠀⠀⠹⣶⠆⠀⠀⠀⠀⠀⡴⠃⠀⠀
⠀⠀⠀⠀⠀⢸⣷⡦⢤⡤⢤⣞⣁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⢀⣤⣴⣿⣏⠁⠀⠀⠸⣏⢯⣷⣖⣦⡀⠀⠀⠀⠀⠀⠀
⢀⣾⣽⣿⣿⣿⣿⠛⢲⣶⣾⢉⡷⣿⣿⠵⣿⠀⠀⠀⠀⠀⠀
⣼⣿⠍⠉⣿⡭⠉⠙⢺⣇⣼⡏⠀⠀⠀⣄⢸⠀⠀⠀⠀⠀⠀
⣿⣿⣧⣀⣿.........⣀⣰⣏⣘⣆⣀⠀
*/
#include <bits/stdc++.h> 
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define l00p(i, a, b) for (int i=a; i<(b); i++)
#define loop(i, a) for (int i=0; i<(a); i++)
#define rep1(i,a,b) for (int i = (b)-1; i >= a; i--)
#define rep(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
#define imax INT_MAX
#define imin INT_MIN
//#define MOD 998244353
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

 
const int MOD = 1000000007;
const char nl = '\n';
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

int main() {
	 
	int k;
	scanf("%d",&k);
	int t=1;
	while(k*t%360!=0)
	t++;
	printf("%d",t);
	return 0;
}
// read the question correctly (ll vs int)
// template by bqi343

Measured memory_bytes: 3776
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    int l=1,r=n;
    for(int i=1;i<=m;i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        l=max(l,x);
        r=min(r,y);
    }
    printf("%d\n",max(0,r-l+1));
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
int p[200002];

void init(int n){
    for (int i = 0; i < n; ++i) {
        p[i]=i;
    }
    return;
}


int find(int x){
	if(x != p[x]){
		p[x] = find(p[x]);
   	}
   	return p[x];
}
     
void union_set(int x,int y){
	x = find(x);
	y = find(y);
	if(x==y) return;
	p[x]=y;
	return ;
}
int main(){	
	int n,m;
	cin >> n >> m;
	init(n+2);
	for(int i=0;i<m;i++){
		int a,b;
		cin >> a >> b;
		union_set(a,b);
	}
	ll x=0,y=0,z=0;
	int p = find(1);
	int q = find(2);
	for(int i=1;i<=n;i++){
		int r= find(i);
		if(r==p)x++;
		else if(r==q)y++;
		else z++;
	}
	ll ans =0;
	if(x>=y){
		ans += (x+z)*(x+z-1)/2;
		ans += y*(y-1)/2;
	}else{
		ans += (y+z)*(y+z-1)/2;
		ans += x*(x-1)/2;
	}
	ans -= m;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
ll a,b,c,d,i,j,k,l,m,n,ans,tmp,hoge,fuga,piyo;

string s,str;
int main(){
  string x[200100],y[10010];
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>x[i];
  }
  sort(x,x+n);
  ans=1;
  for(int i=1;i<n;i++){
    if(x[i]!=x[i-1]){
      ans++;
    }
  }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 10200
//#include "pch.h"
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
#include <numeric>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = 3.14159265359;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };




signed main() {
	int n, m;

	cin >> n >> m;

	if (n == m) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}


	return 0;
}


Measured memory_bytes: 256
s = input()

while s != "":
    if s[-5:] == "dream" or s[-5:] == "erase":
        s = s[:-5]
    elif s[-6:] == "eraser":
        s = s[:-6]
    elif s[-7:] == "dreamer":
        s = s[:-7]
    else:
        print("NO")
        break
else:
    print("YES")

Measured memory_bytes: 3188
#include <iostream>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)

// return the minimum number of t s.t., d*(2**t)>=x
int f(int d, int x) {
  int t = 0;
  while((ll)d * (1LL << t) < (ll)x) t++;
  return t;
}

int main() {
  int n, k;
  cin >> n >> k;
  double ans = 0.0;
  rep(i, n) {
    int dice = i + 1;
    ans += (1.0) / (double)(1LL << f(dice, k));
  }
  ans *= (1.0 / (double)n);
  printf("%.20f\n", ans);
  return 0;
}

Measured memory_bytes: 256
w,h,n = gets.split.map(&:to_i)
xl = 0
xr = w
yl = 0
yh = h
n.times do
  x,y,a = gets.split.map(&:to_i)
  if a == 1
    xl = x if x >= xl
  elsif a == 2
    xr = x if x <= xr
  elsif a == 3
    yl = y if y > yl
  else
    yh = y if y < yh
  end
end

ans = (yh-yl) * (xr - xl)
if yh -yl > 0 && xr - xl > 0
  puts ans
else
  puts 0
end

Measured memory_bytes: 1788
N = int(input())

H = list(map(int,input().split()))
hn = 0
ansL = [0]*N
ansLn = 0


for p in range(N):
    if hn < H[p]:
        ansLn = p
    
    else:
        ansL[ansLn] += 1

    hn = H[p]

print(max(ansL))




Measured memory_bytes: 20536
#include <bits/stdc++.h>
using namespace std;
typedef set<int> IntSet;

int main()
{
    int n, x;
    int min, max;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    min = a[0], max = a[0];
    for (int i = 1; i < n; i++)
    {
        if (a[i] > max)
            max = a[i];
        if (a[i] < min)
            min = a[i];
    }
    int min_sum = 0;
    for (int i = 0; i < n; i++)
        min_sum += (a[i] - min) * (a[i] - min);
    for (int j = min + 1; j <= max; j++)
    {
        int tmp = 0;
        for (int i = 0; i < n; i++)
            tmp += (a[i] - j) * (a[i] - j);
        if (tmp < min_sum)
            min_sum = tmp;
    }
    cout << min_sum << endl;
}

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

using namespace std;

#define precision(n)   cout << setprecision(n) << fixed
#define sf(a)          scanf("%d",&a)
#define sf2(a,b)       scanf("%d %d",&a,&b);
#define pi             3.1415926535
#define eps            0.000001
#define gl(a)          scanf("%llu",&a)
#define mod            1000000007
#define pf             printf
#define loop(ds,itr)   for ( auto itr = ds.begin(); itr != ds.end(); itr++ )
#define bug            cout << 'x' << endl;
#define check(x)       cout << x << endl;
#define e              2.71828182845
#define mp             make_pair
#define min4(a,b,c,d)  min(a,min(b,min(c,d)));

typedef long long ll;
typedef unsigned long long ull;
typedef pair < int,char > ii;
typedef priority_queue< int,vector<int>, greater<int> > pq_increasing;

int main ( ) {
    ///freopen("input.txt","r",stdin);
    ///freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    int cnt = 0;
    int n,k;
    cin >> n >> k;
    ll n1=0,n2=0,n3=0;
    for ( int i = 1; i <= n; i++)  {
        if ( ( (i<<1) % k ) == 0 && ( i%k ) != 0 ) {
            n1++;
        }
    }
    ///cout << n1 << ' ' << n2 << endl;
    ll ans=0;
    n3 = n/k;
    ans = n3*n3*n3;
    if ( k & 1 ) { ans *= 1;}
    else {
        ans += (n1*n1*n1);
    }
    cout << ans << endl;

}


Measured memory_bytes: 764
#include <cstdio>
#include <algorithm>

using namespace std;

const int MAXN = 105;

int a[MAXN];

int main() {
    int n;
    scanf("%d", &n);// don't forget &
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);// don't forget &
    }
    int ans;
    for (int i = 1; i <= 100; i++) {
        int cur = 0;
        for (int j = 1; j <= n; j++) {
            cur += (a[j] - i) * (a[j] - i);
        }
        if (i == 1) {
            ans = cur;
        } else {
            ans = min(ans, cur);
        }
    }
    printf("%d", ans);
    return 0;
}


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

using namespace std;

#define PI 3.14159265358979323846264338327950L

int main(void){

    int X,ans;

    cin>>X;

    if(X >= 1800){
        ans=1;
    }else if(X >= 1600){
        ans=2;
    }else if(X>=1400){
        ans=3;
    }else if(X>= 1200){
        ans=4 ;
    }else if(X>=1000 ){
        ans=5 ;
    }else if(X>=800 ){
        ans=6 ;
    }else if(X>= 600){
        ans=7 ;
    }else if(X>= 400){
        ans= 8;
    }

    cout<<ans<<endl;

    return 0;
}



Measured memory_bytes: 3616
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

typedef long long ll;

// const int dx[4] = {1, 0, -1, 0};
// const int dy[4] = {0, 1, 0, -1};

// const int C = 1e6+10;
// const ll M = 1000000007;

int K;

typedef tuple<int, int> state;

int main () {
  cin >> K;
  priority_queue<state, vector<state>, greater<state> > Q;
  Q.push(state(1, 1));
  int visited[100010];
  fill(visited, visited+100010, -1);
  while (!Q.empty()) {
    int cost = get<0>(Q.top());
    int now = get<1>(Q.top());
    Q.pop();
    if (visited[now] == -1) {
      visited[now] = cost;
      if (now == 0) {
        cout << cost << endl;
        return 0;
      }
      int plusone = (now + 1)%K;
      if (visited[plusone] == -1) {
        Q.push(state(cost+1, plusone));
      }
      int timesten = (now * 10)%K;
      if (visited[timesten] == -1) {
        Q.push(state(cost, timesten));
      }
    }
  }
}


Measured memory_bytes: 1276
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define dofloat cout<<fixed<<setprecision(8)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bitcount __builtin_popcount
#define all(vec) vec.begin(),vec.end()
#define rall(vec) vec.rbegin(),vec.rend()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<long long> vl;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long> > vll;
typedef vector<pair<int,int> > vii;
typedef vector<int> vi;
typedef pair<int,int> ii;
const long long MOD=1000000007;
const long long MAX=100005;
const long double PI=3.14159265359;
const long double G=9.807;
const long long INF=1e18;
const long double EPS=1e-6;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
bool isprime(ll a){
  if(a==2)return 1;
  if(!(a&1))return 0;
  for(ll i=3;i*i<=a;i+=2)
    if(a%i==0)return 0;
  return 1;
}
ll mpow(ll base,ll exponent,ll modulus){
  if(modulus==1)return 0;
  long long result = 1;
  base=base%modulus;
  while(exponent){
    if(exponent%2 == 1)
    result=(result*base)%modulus;
    exponent=exponent>>1;
    base=(base*base)%modulus;
  }
  return result;
}
ll minv(ll a,ll mod){
  ll _gcd=gcd(a,mod);
  assert(_gcd==1);
  return mpow(a,mod-2,mod);
}


/*
ll ncr(ll N,ll K){
  if(N<K)return 0;
  if(K==0)return 1;
  if(N==0)return 0;

  ll den=1;
  for(ll i=1;i<=K;i++)den*=i;
  ll num=1;
  while(K--){
    num*=N;
    if(num%den==0){
      num/=den;
      den=1;
    }
    N--;
  }

  return num;
}
*/

const int BZ = 1000;

int n,m,a[5*MAX],ans[5*MAX],f[5*MAX];
int cur;

void take(int x){
  if(!f[a[x]])++cur;
  ++f[a[x]];
  return;
}

void drop(int x){
  --f[a[x]];
  if(!f[a[x]])--cur;
  return;
}

int omg(pair<ii,int> x,pair<ii,int> y){
  ii A = x.first;
  ii B = y.first;
  int L1 = A.first,R1 = A.second;
  int L2 = B.first,R2 = B.second;
  L1/=BZ;
  L2/=BZ;
  if(L1 != L2)
    return L1<L2;
  return R1<R2;
}

int main(){FAST;
cin>>n>>m;

for(int i=1;i<=n;++i){
  cin>>a[i];
}

vector<pair<ii,int> >qs; 

for(int i=1;i<=m;++i){
 int l,r;cin>>l>>r;
 qs.pb({{l,r},i}); 
}

sort(all(qs),omg);

int mol = 1,mor = 0;

for(int i=0;i<m;++i){
  ii p = qs[i].first;
  int idx = qs[i].second;
  int l = p.first,r = p.second;
  while(mor<r){
    take(++mor);
  }
  while(mor>r){
    drop(mor--);
  }
  while(mol<l){
    drop(mol++);
  }
  while(mol>l){
    take(--mol);
  }
  ans[idx] = cur;
}

for(int i=1;i<=m;++i){
  cout<<ans[i]<<'\n';
}
return 0;
}

/*
 WA? check edge cases, N=1,M=1 etc. Read code fully once and check all variables.
 Read the question again and see what you might have missed.
 Consider changing your solution or find more cases.
 */


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

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = Integer.parseInt(scan.next());

        AObj[] a = new AObj[n];
        for (int i = 0; i < n; i++) {
            a[i] = new AObj(i, Integer.parseInt(scan.next()));
        }
        scan.close();

        Arrays.sort(a, (x, y) -> y.value_ - x.value_);

        long[][] dp = new long[n + 1][n + 1];
        dp[0][0] = 0;

        for (int i = 0; i < n; i++) {
            for (int x = 0; x <= i; x++) {
                int y = i - x;
                dp[x + 1][y] = Math.max(dp[x + 1][y], dp[x][y] + (long)Math.abs(x - a[i].index_) * a[i].value_);
                dp[x][y + 1] = Math.max(dp[x][y + 1], dp[x][y] + (long)Math.abs(a.length - 1 - y - a[i].index_) * a[i].value_);
            }
        }

        long sum = 0;
        for (int i = 0; i < n; i++) {
            if (sum < dp[i][n - i]) {
                sum = dp[i][n - i];
            }
        }
        System.out.println(sum);
    }

}

class AObj {
    int index_;
    int value_;

    public AObj(int index, int value) {
        index_ = index;
        value_ = value;
    }
}


Measured memory_bytes: 85384
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;
typedef long long ll;
const int maxn=200050;
const int maxlen=1000050;
const int maxc=30;
vector<char> v[maxn];
int ch[maxlen][26],sum[maxlen][26];
int pos[maxn],stk[maxlen],_id[maxlen];
char s[maxlen];
bool beused[maxc];
int n,tot;

int cmp(int a,int b){
	return v[a].size()>v[b].size();
}
void solve(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%s",s);
		int len_s=strlen(s);
		reverse(s,s+len_s);
		for(int j=0;j<len_s;j++)	v[i].push_back(s[j]);
		pos[i]=i;
	}
	sort(pos+1,pos+n+1,cmp);
	ll res=0;
	for(int i=1;i<=n;i++){
		int u=0,now=0,id=0;
		for(auto x:v[pos[i]]){
			id=x-'a';
			if(!ch[u][id])	ch[u][id]=++tot;
			stk[++now]=u;_id[now]=id;
			u=ch[u][id];
		}
		res+=sum[stk[now]][id];
		memset(beused,0,sizeof(beused));
		for(int j=now;j>=1;j--){
			beused[_id[j]]=1;
			for(int k=0;k<26;k++)	sum[stk[j]][k]+=beused[k];
		}
	}
	printf("%lld\n",res);
}
int main(){
	solve();
	return 0;
}

Measured memory_bytes: 217788
#include <bits/stdc++.h>
using namespace std;
#define ll          long long int
#define pb          push_back
#define pll         pair<ll,ll>
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mode        998244353
#define mod         1000000007
#define inf         1000000000000000000LL
#define vl          vector<ll>
#define F           first
#define S           second
#define db          long double
#define sz(x)       (ll)x.size()
#define fix(n)      cout<<fixed<<setprecision(n)
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define all(x)      x.begin(),x.end()
#define mset(x)     memset(x,0,sizeof x)
#define pi          3.14159265358979323



void solve()
{
       ll n,a,b;
       cin>>n>>a>>b;
       if(abs(a-b-1)==0 || abs(a-b-1)%2==0) cout<<"Borys";
       else cout<<"Alice";
}


int main()
{
    speed_up
    ll T=1;
    //cin>>T;
    while(T--)
        solve();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define LL long long
const int mod = 998244353;
const int N = 2e7 + 11;
int fac[N], inv[N], n, m;
inline LL A(LL x, LL y){
    return x + y - (x + y >= mod ? mod : 0);
}
int C(int m, int n){
    if(m > n)return 0;
    return 1LL * fac[n] * inv[m] % mod * inv[n-m] % mod;
}
LL f(int n, int m, int k){
    LL ans = 0;
    for(int i = m % 2;i <= k; i += 2){
        ans = A(ans, 1LL * C(i, n) * C(n - 1, (m - i) / 2 + n - 1) % mod);
    }
    return ans;
}
int main(){
    cin>>n>>m;
    inv[0] = inv[1] = fac[1] = fac[0] = 1;
    for(int i = 2;i < N; i++){
        fac[i] = 1LL * fac[i-1] * i % mod;
        inv[i] = (mod - 1LL * (mod / i) * inv[mod%i] % mod) % mod;
    }
    for(int i = 2;i < N; i++){
        inv[i] = 1LL * inv[i] * inv[i-1] % mod;
    }
    LL ans = A(f(n, 3 * m, m), mod - 1LL * n * (A(f(n, m, m), mod - f(n - 1, m, m))) % mod);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 156544
N,W=map(int,input().split())
DP= [[0 for j in range(W+1)] for i in range(N+1)]
v=[0]*(N+1)
w=[0]*(N+1)
for i in range(1,N+1):
  v[i],w[i]=map(int,input().split())
for i in range(1,N+1):
  for j in range(1,W+1):
    if j-w[i]<0:
      DP[i][j]=DP[i-1][j]
    else:
      DP[i][j]=max(DP[i-1][j],DP[i-1][j-w[i]]+v[i])
print(DP[N][W])


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

public class Main{
  private static int mod = 1000000007;
  public static void main(String[] args) {
  	Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int K = sc.nextInt();
    int[] array = new int[N];
    Arrays.setAll(array, i -> sc.nextInt());
    long count1 = 0;
    long count2 = 0;
    for (int i = 0; i < N - 1; i++)
      for (int j = i + 1; j < N; j++)
        if (array[i] > array[j])
          count1++;
        else if (array[i] < array[j])
          count2++;
    long k = K % mod;
    System.out.println((k * count1 % mod + (k * (k - 1) / 2) % mod * (count1 + count2) % mod) % mod);
  }
}

Measured memory_bytes: 27576
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;


int main() {
   
    ll a,b,k;
    cin >> a >> b >> k;
    ll cnt = 0;
    ll now = 101;
    while(cnt != k){
        now--;
        if(a%now == 0 and b%now == 0) {
            cnt++;
        }

    }
    cout << now << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
int main()
{
  int n;
  double ans = 0;
  double x;
  string y;
  cin >> n;
  for(int i=0; i<n;i++){
    cin >> x >> y;
    if(y == "JPY") ans += x;
    else ans += (x * 380000.0);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import deque

def main():
    N = int(input())
    adj = [[] for _ in range(N)]
    for i in range(N-1):
        a, b = map(lambda x: int(x)-1, input().split())
        adj[a].append((b,i))
        adj[b].append((a,i))
    p = max([len(a) for a in adj])
    ans = [-1] * (N-1)
    visited = [-1] * N
    visited[0] = 0
    q = deque([0])
    
    while q:
        now = q.popleft()
        tmp = 0
        for v in adj[now]:
            if visited[v[0]] == 0:
                tmp = ans[v[1]]
                break
        
        for v in adj[now]:
            if visited[v[0]] < 0:
                q.append(v[0])
                ans[v[1]] = (tmp+1) % p
                tmp += 1
                visited[v[0]] = 0
                if ans[v[1]] == 0:
                    ans[v[1]] += p
    print(p)
    [print(a) for a in ans]

if __name__ == "__main__":
    main()


Measured memory_bytes: 40856
/*
	0280:The Outcome of Bonze
*/
#include	<iostream>
#include	<string>
#include	<algorithm>

using namespace std;

int main(void) {
	int num;
	while(1) {
		int maisu[10] = { 0 }, ba = 0, sel = 0;
		string cards;
		
		cin >> num;
		if(num == 0) { break; }
		cin >> cards;
		for(int i = 0; i < 100; i++) {
			if(cards[i] == 'M') { maisu[sel]++; }
			else if(cards[i] == 'S') { ba += maisu[sel] + 1; maisu[sel] = 0; }
			else if(cards[i] == 'L') { maisu[sel] += ba + 1; ba = 0; }
			sel = (sel+1) % num;
		}
		sort(maisu, maisu+num);
		for(int i = 0; i < num; i++) {
			cout << maisu[i] << ' ';
		}
		cout << ba << endl;
	}
	return 0;
}

Measured memory_bytes: 1224
#include <cstdio>
#include <vector>
const int MAXN = 1e5+5;
const int MOD = 1e9+7;
std::vector<int> G[MAXN];
bool seen[MAXN];
int K, N;
int ret;

void dfs(int cur, int sib) {
    seen[cur] = true;
    int sze = G[cur].size();
    // sib means cur is not root.
    int k = (sib) ? 2 : 1;
    for (auto nxt: G[cur]) {
        if (!seen[nxt]) {
            dfs(nxt, k);
            if (k < sze) ++k;
        }
    }
    ret = 1LL * ret * (K - sib) % MOD;
}

int solve() {
    ret = 1;
    for (int i = 1; i <= N; ++i) {
        if (K <= static_cast<int>(G[i].size())) {
            return 0;
        }
    }
    for (int i = 1; i <= N; ++i) if (!seen[i]) {
        dfs(i, 0);
    }
    return ret;
}

int main() {
    scanf(" %d%d", &N, &K);
    for (int i = 1; i < N; ++i) {
        int a, b;
        scanf(" %d%d", &a, &b);
        G[a].push_back(b);
        G[b].push_back(a);
    }
    printf("%d\n", solve());
    return 0;
}


Measured memory_bytes: 9344
#include<iostream>
#include<cstdlib>

int main() {
    int i ;
    std::cin >> i ;
    
    div_t d = std::div( i , 3600 ) ;
    
    int h = d.quot ;
    d = std::div( d.rem , 60 ) ;
    int m =d.quot ;
    int s =d.rem ;
    
    std::cout << h << ":" << m << ":" << s << std::endl ;
}


Measured memory_bytes: 3096
#include<iostream>
using namespace std;
int main()
{
    long long a,b,c;
    while(cin>>a>>b>>c)
    {
        for(long long i=a;i<=b;i++)
        {
            if(i<a+c||i>b-c)
                cout<<i<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 384
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
    int N;
    cin >> N;
    vector<int>a(N);
    for (int i=0; i<N; i++)cin >> a[i];

    bool is_even = true;
    for (int i=0; i<N; i++){
        if (a[i]%2 == 1)is_even = false;
    }

    if (is_even)cout << "second" << endl;
    else cout << "first" << endl;
}

Measured memory_bytes: 640
n = int(input())
sp = [input().split() for _ in range(n)]
for i in range(n):
    sp[i][1] = int(sp[i][1])
sp_sort = sorted(sp,key=lambda x: x[1],reverse=True)
sp_sort = sorted(sp_sort,key=lambda x: x[0])
for i in range(n):
    print(sp.index(sp_sort[i])+1)

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>

using namespace std;

int main(){

	int A;
	int B;
	int C;

	cin >> A >> B  >> C;

	if(A <= C && C <= B){
		cout << "Yes";
	}else{
		cout << "No";
	}




	return 0;

}


Measured memory_bytes: 256
/*
	submission # - User: herp_sy
	https://atcoder.jp/contests/
*/

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

// utility of stdin,stdout
#define _CRT_SECURE_NO_WARNINGS
#define OUT cout << 
#define BR << endl
#define RET return 0
#define TLong long long
#define TBMod 1000000007

int main(int argc, char const *argv[]){
	int k,x;
	cin >> k >> x;
	for (int i = x - k + 1; i < x + k; ++i)	OUT(i) BR;
	RET;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb emplace_back
#define vi vector<int>
#define all(x) (x).begin(), (x).end()
#define pb emplace_back
#define deb(x) cout << #x << " - " << x << endl;

using namespace std;

int main()
{
	IOS;
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif
	int x, y, z; cin >> x >> y >> z;
	cout << z << " " << x << " " << y;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
    public static void main(String[] arg) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        if(IntStream.rangeClosed(1,9)
                .parallel()
                .filter(i->
                        IntStream.rangeClosed(1, 9)
                                .parallel()
                                .filter(j->i*j==N)
                                .findAny()
                                .isPresent()
                )
                .findAny()
                .isPresent()
        ){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
        return;
    }
}

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

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; }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


string s;

int main() {
    cin >> s;

    i64 A = (s[0] - '0') * 10 + (s[1] - '0');
    i64 B = (s[2] - '0') * 10 + (s[3] - '0');
    if (1 <= A && A <= 12) {
        if (1 <= B && B <= 12) {
            cout << "AMBIGUOUS" << endl;
        } else {
            cout << "MMYY" << endl;
        }
    } else {
        if (1 <= B && B <= 12) {
            cout << "YYMM" << endl;
        } else {
            cout << "NA" << endl;
        }
    }

    return 0;
}

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

using namespace std;

const int inf = 2000000000;

int culc(int x, int y)
{
  if (x >= 0 && abs(y) < x) {
    return inf;
  }
  if (x >= 0) {
    if (y > 0) {
      return y - x;
    }
    return -y - x + 1;
  }
  if (y > 0) {
    if (x <= -y) {
      return -y - x + 1;
    }
    return y - x;
  }
  if (y < x) {
    return inf;
  }
  return y - x;
}

int main()
{
  int x, y;
  cin >> x >> y;
  int res = min(culc(x, y), culc(-x, y) + 1);
  cout << res << endl;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
A = list(map(int, input().split()))

cnt = {}

for i in range(N):
    cnt.setdefault(A[i], 0)
    cnt[A[i]] += 1

cnt_val = sorted(cnt.values())
ans = sum(cnt_val[:len(cnt_val) - K])

print(ans)


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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)

using P = std::tuple<int,int>;
using ll = long long;

const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};

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

    int N;
    cin >> N;

    std::cout << N * (N+1) / 2 << std::endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if(x < y) x = y; }

int main() {
	int N;
	while(~scanf("%d", &N)) {
		vector<int> a(N);
		for(int i = 0; i < N; ++ i)
			scanf("%d", &a[i]), -- a[i];
		int ans = 0;
		rep(i, N)
			ans += a[a[i]] == i;
		ans /= 2;
		printf("%d\n", ans);
	}
	return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++){
        int x = i;
        if (x % 3 == 0){
            cout << " " << i;
        }
        else{
            while (x){
                if (x % 10 == 3){
                    cout << " " << i;
                    break;
                }
                x /= 10;
            }
        }
    }
    cout << endl;
    return 0;
}


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

int main() {
    int n, x;
    cin >> n >> x;
    int l[n + 1];
    l[0] = 0;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        l[i + 1] = l[i] + x;
    }
    int cnt = 0;
    for (int i = 0; i <= n; i++) {
        if (l[i] <= x) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#[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,
    a: [i64; n + 1],
    b: [i64; n],
  }
  let mut a = a;
  let mut b = b;
  let mut total = 0i64;
  for i in 0 .. n {
    let l = cmp::min(a[i], b[i]);
    b[i] -= l;
    let r = cmp::min(a[i+1], b[i]);
    a[i+1] -= r;
    total += l + r;
  }

  puts!("{}\n", total);
}


Measured memory_bytes: 10232
#C
n=int(input())
a=list(map(int,input().split()))

pre=a[0]
ans=0
for i in range(1,n):
    if pre>a[i]:#前の方が大きい
        ans+=pre-a[i]
    else:#後ろの方が大きい
        pre=a[i]
print(ans)

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

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		
		int[] A = new int[N];
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
		}
		Arrays.sort(A);
		
		int[] B = new int[N];
		for (int i = 0; i < N; i++) {
			B[i] = sc.nextInt();
		}
		Arrays.sort(B);
		
		int[] C = new int[N];
		for (int i = 0; i < N; i++) {
			C[i] = sc.nextInt();
		}
		Arrays.sort(C);
		
		long ans = 0;
		for (int i = 0; i < N; i++) {
			int b = B[i];
			
			ans += binarySearch(A, b) * (C.length - binarySearch(C, b+1));
		}
		
		System.out.println(ans);
	}
	
	static long binarySearch(int[] m, int key) {
		int l = -1;
		int r = m.length;
		
		while((r-l) > 1) {
			int mid = (r + l) / 2;
			
			if (m[mid] >= key) {
				r = mid;
			} else {
				l = mid;
			}
		}
		
		return r;
	}
}


Measured memory_bytes: 91572
sa = list(input())
sb = list(input())
sc = list(input())

next_turn = 'a'
while True:
    if next_turn == 'a':
        if len(sa) == 0:
            print('A')
            break
        next_turn = sa.pop(0)
    elif next_turn == 'b':
        if len(sb) == 0:
            print('B')
            break
        next_turn = sb.pop(0)
    elif next_turn == 'c':
        if len(sc) == 0:
            print('C')
            break
        next_turn = sc.pop(0)


Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main() {
  int Tc; cin >> Tc;  
  while(Tc--) {
    int n; cin >> n;
    int a = 0, b = 0;
    int prev; cin>>prev;
    for(int i=1; i < n; i++) {
      int x; cin >> x;
      if(prev-x >= 0) {a = max(a, prev-x);}
      else {b = max(b, x-prev);}
      prev = x;
    }
    cout << b << " " << a << endl; 
  }
  return 0;
}

Measured memory_bytes: 1160
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(int)(b); i++)
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define st first
#define nd second
using namespace std;
 
const int maxN = 1 << 19;

char T[maxN];

void solve()
{
	int n;
	scanf ("%d", &n);
	scanf ("%s", T);
	
	bool res = true;
	FOR(i, 0, n/2)
		if (T[i] != T[n/2+i])
			res = false;
	if (n%2 == 1)
		res = false;
	
	printf("%s\n", res ? "Yes" : "No");
}
 
int main()
{
	int t;
	t=1;//scanf ("%d", &t);
	while (t--)
		solve();
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    int n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    a--, b--, c--, d--;
    string s;
    cin >> s;

    if(c<d){
        //追い越す必要がない
        for (int i = b; i <= d-1;i++){
            if(s[i]=='#' && s[i+1]=='#'){
                cout << "No" << endl;
                return 0;
            }
        }
        for (int i = a; i <=c-1; i++)
        {
            if(s[i]=='#' && s[i+1]=='#'){
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
    }
    else{
        for (int i = b; i <= d-1;i++){
            if(s[i]=='#' && s[i+1]=='#'){
                cout << "No" << endl;
                return 0;
            }
        }
        for (int i = a; i <=c-1; i++)
        {
            if(s[i]=='#' && s[i+1]=='#'){
                cout << "No" << endl;
                return 0;
            }
        }
        for (int i = b-1; i <=d-1; i++)
        {
            if(s[i]=='.' && s[i+1]=='.' && s[i+2]=='.' ){
                cout << "Yes" << endl;
                return 0;
            }
        }
        cout << "No" << endl;
        
        
        

    }


    return 0;
}

Measured memory_bytes: 888
import sys

x, n = map(int, input().split())
if n == 0:
    print(x)
    sys.exit()
p = list(map(int, input().split()))



for i in range(100):
    if x-i not in p:
        print(-i+x)
        sys.exit()
    if x+i not in p:
        print(x+i)
        sys.exit()

Measured memory_bytes: 9160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
	string s;cin>>s;
	int l=s.size();
	bool chk=0;
	for(int i=0;i<l/2;i++){
		if(s[i]=='d'&&s[l-i-1]=='b') chk=1;
		else if(s[i]=='b'&&s[l-i-1]=='d') chk=1;
		else if(s[i]=='q'&&s[l-i-1]=='p') chk=1;
		else if(s[i]=='p'&&s[l-i-1]=='q') chk=1;
		else {
			chk=0;
			break;
		}
	}
	if(l%2==1) chk=0;
	if(chk) cout<<"Yes"<<"\n";
	else cout<<"No"<<"\n";
} 


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

int main() {
	int k;
	cin>>k;
	if(k%2==0||k%5==0){
		cout<<-1<<endl;
		return 0;
	}
	int n=0;
	int k1=k;
	int num = 0;
	int des =1;
	while(k1){
		n++;
		num=7*des+num;
		des*=10;
		k1/=10;
	}
	//cout<<des<<endl;
	int count =0;
	while(1){
		num=num%k;
		if(num==0){
			
			//cout<<num<<endl;
			cout<<n<<endl;
			return 0;
		}
		else{
			
			n++;
		
			num=num*10+7;
		}
	}
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n = 0;
	cin >> n;
	vector<int> v(n, 0);
	for (int i = 0; i < n; i++)
	{
		cin >> v[i];
	}
	sort(v.begin(), v.end());
	int d = v.size() / 2;
	int k = v[d] - v[d - 1];
	cout << k;
}

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

int main(){
  	int A, B;
  	cin >> A >> B;
  	int ans;
  	if(A >= 13){
    	ans = B;
    }else if(A <= 12 && A >= 6){
    	ans = B/2;
    }else{
    	ans = 0;
    }
  	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256