akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
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)
#define DEBUG
#define int long long
#define INF 1e18
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; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

ll MOD=1e9+7;
ll add(ll x, ll y)
{
    x += y;
    if (x >= MOD)
        return x - MOD;
    return x;
}
ll sub(ll x, ll y)
{
    x -= y;
    if (x < 0)
        return x + MOD;
    return x;
}
ll mult(ll x, ll y)
{
    return (x * y) % MOD;
}
ll bin_pow(ll x, ll p)
{
    if (p == 0)
        return 1;
    if (p & 1)
        return mult(x, bin_pow(x, p - 1));
    return bin_pow(mult(x, x), p / 2);
}

signed main()
{
    int n;
    cin>>n;
    vector<int>c(n);
    REP(i,n) cin>>c[i];
    sort(ALL(c));
    int ans=0;
    for (int i = 0; i < n; i++)
    {
        int x =mult(bin_pow(2,2*n-2),i+2);
        //cerr<<x<<endl;
        ans = add(ans,mult(x,c[n-1-i]));
        //cerr << mult(x, c[n - 1 - i]) << endl;
    }
    cout<<ans<<endl;
    
    return 0;
}

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

int main(){
  int n;
  int a[100000];
  int ans[100000];

  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> a[i];
    ans[a[i]-1]=i;
  }
  
  for(int i=0; i<n; i++){
        cout << ans[i]+1 << " ";
  }
    

  return 0;
}

Measured memory_bytes: 1536
#include "bits/stdc++.h"
#define FI first.first
#define SE first.second
#define TH second
#define fi first
#define se second
#define th second

using namespace std;

template<typename T>
string to_string(const vector<T>& vc, int w) {
	if(vc.empty()) return "";
	if(w + 1 == vc.size()) return to_string(vc[w]);
	return to_string(vc[w]) + "," + to_string(vc, w + 1);
}

template<typename T>
string to_string(const vector<T>& vc) {
	return "{" + to_string(vc, 0) + "}";
}

void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

class DebugStream {}LOG;
template <typename T>DebugStream &operator<<(DebugStream &s, const T&) { return s; }
#ifdef DEBUG
#define LOG clog
#endif

typedef long long ll;
typedef pair<ll, ll> ii;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 335, lg = 20, bs = 29;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifdef DEBUG
	freopen("input.txt", "r", stdin);
	#endif

	int n;
	cin >> n;
	vector<ll> one(n), two(n);
	for(int i = 0; i < n; i++) cin >> one[i] >> two[i];
	sort(one.begin(), one.end());
	sort(two.begin(), two.end());
	if(n & 1) cout << two[n / 2] - one[n / 2] + 1 << '\n';
	else cout << two[n / 2 - 1] + two[n / 2] - one[n / 2 - 1] - one[n / 2] + 1 << '\n';
}



Measured memory_bytes: 6356
//************************
//*  Date: 2018.9.15     *
//*  Problem:            *
//*  Author: xuziyuan    * 
//************************

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++)
#define LL long long
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

int n,x;
int a[110];

int main()
{
	cin>>n>>x;
	rep(i,n) cin>>a[i];
	sort(a,a+n);
	int i=0;
	rep(i,n)
	{
		if(i==n-1&&x-a[i]!=0)
		{
			cout<<n-1<<endl;
			rt0;
		}
		if(x-a[i]>=0)
		{
			x-=a[i];
			continue;
		}
		cout<<i<<endl;
		rt0;
	}
	cout<<n<<endl;
	rt0;
}

Measured memory_bytes: 256
n,m,c = map(int,input().split())
b = list(map(int,input().split()))
ans = 0
for i in range(n):
    a = list(map(int,input().split()))
    num = 0
    for j in range(m):
        num += a[j]*b[j]
    num += c
    if num > 0:
        ans += 1
print(ans)

Measured memory_bytes: 3060
#include "bits/stdc++.h"
#ifndef err
#define err(...)(void)0
#endif
using namespace std;
using ll = long long;
using ull = decltype(1ull);
template<class T>int size(T&&a) { return a.size(); }
#define REP(t,a)for(typename make_signed<decltype(a.second)>::type t=a.first,_l##t=a.second;t<_l##t;t++)
#define RREP(t,a)for(typename make_signed<decltype(a.second)>::type t=a.second-1,_l##t=a.first;t>=_l##t;t--)
template<class B>pair<int, B>make_pair(B b) { return{ 0,b }; }
#define rep(t,...)REP(t,make_pair(__VA_ARGS__))
#define rrep(t,...)RREP(t,make_pair(__VA_ARGS__))
#define all(a)begin(a),end(a)
#define rall(a)a.rbegin(),a.rend()

void Calc();
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr); cin.exceptions(istream::failbit | istream::badbit);
  cout << fixed << setprecision(15); Calc(); cout.flush(); return 0;
}
template<class A>void amax(A&a, A b) { a = max(a, b); }
template<class A>void amin(A&a, A b) { a = min(a, b); }
struct Scanner {
  template<class A = string>A Next() { A a; cin >> a; return a; }
  template<class A = int>vector<A>Array(int n) { vector<A>a(n); for (A&i : a) cin >> i; return a; }
  string Line() const { string s; getline(cin, s); return s; }
  template<class A>Scanner&operator,(A&a) { a = Next<A>(); return *this; }
  template<class A>operator A() { return Next<A>(); }
}in;

/*---------------------------------------------------------------------*/



void Calc() {

  int h, w;
  in, h, w;

  auto v = in.Array<string>(h);

  int x = 0, y = 0;
  v[0][0] = '0';
  for (; x < w, y < h;) {
    if (x + 1 < w && v[y][x + 1] == '#') {
      rep(i, h)if (v[i][x] == '#') {
        cout << ("Impossible") << endl;
        return;
      }
      v[y][x + 1] = '0';
      x++;
    } else if (y + 1 < h&& v[y + 1][x] == '#') {
      rep(i, w)if (v[y][i] == '#') {
        cout << ("Impossible") << endl;
        return;
      }
      v[y + 1][x] = '0';
      y++;
    } else {
      break;
    }
  }
  rep(i, h)rep(j, w) if (v[i][j] == '#') {
    cout << ("Impossible") << endl;
    return;
  }
  cout << ("Possible") << endl;

}


Measured memory_bytes: 256
x = input().split()
a = int(x[0])
b = int(x[1])
c = int(x[2])
 
if a <= b <= c:
    print(a, b, c)
elif a <= c <= b:
    print(a, c, b)
elif b <= a <= c:
    print(b, a, c)
elif b <= c <= a:
    print(b, c, a)
elif c <= a <= b:
    print(c, a, b)
else:
    print(c, b, a)

Measured memory_bytes: 6724
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

int main() {
    ll L, R;
    ll a, b, f;
    ll ans = 2045;
    cin >> L >> R;
    
    if (R-L>=2019) {
        f = 2019;
    } else {
        f = R-L;
    } 

    for (ll i = L; i <= L+f; i++) {
        for (ll j = i+1; j<=L+f; j++) {
            ans = min(ans, (j*i)%2019);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long H = sc.nextLong();
        long W = sc.nextLong();
        long sum = H*W;
        long ans = 0;
        
        if(H==1 || W == 1){
            ans = 1;
        }else if(sum%2 == 0){
            ans = (long)sum/2;
        }else{
            ans = (long)sum/2+1;
        }
        
        System.out.println(ans);
   }
}


Measured memory_bytes: 35624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main() {
    ll n,k;
    cin >> n >> k;
    vector<ll>a(n);
    for(ll i=0;i<n;i++){
        cin >> a[i];
    }
    ll inv=0;
    for(ll i=0;i<n;i++){
        for(ll j=0;j<i;j++){
            if(a[j]>a[i]) inv++;
        }
    }
    ll mi=0;
    for(ll i=0;i<n;i++){
        for(ll j=0;j<n;j++){
            if(i==j) continue;
            if(a[i]<a[j]) mi++;
        }
    }
    ll ans=(k*(k-1)/2)%MOD;
    ans=(ans*mi)%MOD;
    ans+=(inv*k)%MOD;
    ans%=MOD;
    cout << ans << endl;
}


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

typedef signed long long ll;
typedef long double ld;

#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(x) x.begin(),x.end()

#define DEBUG

int main()
{
	int n, k;
	string s;
	cin >> n >> k;
	cin >> s;

	int d = 'A'-'a';
	s[k-1] = s[k-1]-d;
	cout << s << endl;
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

#define faster ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define read freopen("in.txt","r",stdin)
#define write freopen("out.txt","w",stdout)
#define mem(x,n) memset(x,n,sizeof(x))
#define all(x) x.begin(), x.end()
#define endl "\n"

int main()
{
	faster;
	
	ll a,b,c,d;
	cin >> a >> b >> c >> d;
	ll one = a * c, two = b * d, three = a * d, four = c * b;
	ll mxn = max(one,max(two,max(three,four)));
	if(mxn < 0 && ((a <= 0 && b >= 0) || (c <= 0 &&  d>= 0))){
		mxn = 0;
	}
	cout << mxn << endl;
	
	return 0;
}

Measured memory_bytes: 3648
n = int(input())
max1 = 0
max2 = 0
max_index = 0
for i in range(n):
    a = int(input())
    if a >= max1:
        max2 = max1
        max1 = a
        max_index = i
    elif a > max2:
        max2 = a

for i in range(n):
    if i == max_index:
        print(max2)
    else:
        print(max1)


Measured memory_bytes: 4668
#include <iostream>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <stack>
#define Endl endl
#define mp make_pair
#define ll long long 
#define pii pair<int,int>
#define pll pair<ll,ll>
#define over(A) {cout<<A<<endl;exit(0);}
#define all(A) A.begin(),A.end()
#define ceil(a,b) ((a-1)/b+1)
#define srand() mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rand(l,r) uniform_int_distribution<int>(l,r)(rng)
typedef unsigned long long ull;
const int inf=1039074182;
using namespace std;
int n;
vector <int> vec[200005];
ll tag[200005];
int q;
ll a[200005];

void dfs(int x,int p,ll value=0)
{
	a[x]=value+tag[x];
	for(auto u:vec[x])
	{
		if(u==p) continue;
		dfs(u,x,value+tag[x]);
	}
}

int main()
{
//	freopen("input.txt","r",stdin);
	cin>>n>>q;
	int x,y;
	for(int i=0;i<n-1;i++)
	{
		scanf("%d%d",&x,&y);
		x--;
		y--;
		vec[x].push_back(y);
		vec[y].push_back(x);
	}
	int p;
	while(q--)
	{
		scanf("%d%d",&p,&x);
		p--;
		tag[p]+=x;
	}
	dfs(0,-1);
	for(int i=0;i<n;i++)
	{
		printf("%lld ",a[i]);
	}
	return 0;
}

Measured memory_bytes: 28672
N = int(input())
hantei = False

for i in range(int(N/7) + 1):
    for j in range(int(N/4) + 1):
        if i == 0 and j == 0:
            continue
        if N % (7*i + 4*j) == 0:
            hantei = True
            break

if hantei:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
#define rep(i,a,b) for(int i=a;i<b;++i)
#define repr(i,a,b) for(int i=a,i > b;--i)
#define mm(lamb, tttt) memset(lamb, tttt, sizeof lamb)

#define null NULL
#define eps 0.000000001
#define modi 1000000007
#define PI 3.14159265358979323846
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define ALL(V) V.begin(), V.end()
#define sz(V) (ll)V.size()
#define _ <<" "<<

#include <iostream>
#include <fstream>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <iterator>
#include <bitset>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <limits.h>
#include <iomanip>
#include <cctype>
#include <numeric>
#include <complex>

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef pair <double, double> ii;
typedef pair<int, pair<int,int> > iii;
typedef vector<int> vii;

int n;
vector<ll> a,prefix;
ll sum(int l,int r){
	if(l==0) return prefix[r];
	else return prefix[r]-prefix[l-1];
}

ll maximum(ll ax,ll b,ll c,ll d){
	return max(ax,max(b,max(c,d)));
}

ll minimum(ll ax,ll b,ll c,ll d){
	return min(ax,min(b,min(c,d)));
}

int decide(int i1,int i2,int i3,int l,int r){ // [l,i1],[i1+1,i2][i2+1,r]
	//cout<<l<<" "<<r<<" "<<i1<<" "<<i2<<" "<<i3<<endl;
	ll a1=1e15,a2=1e15,a3=1e15;
	if(i1 >= l && i1 < r) {
		a1 = abs(sum(l,i1)-sum(i1+1,r));
	}
	if(i2 >= l && i1 < r) {
		a2 = abs(sum(l,i2)-sum(i2+1,r));
	}
	if(i3 >= l && i1 < r) {
		a3 = abs(sum(l,i3)-sum(i3+1,r));
	}
	ll mini = minimum(a1,a2,a3,1e16);
	if(a1 == mini) return i1;
	if(a2 == mini) return i2;
	else return i3;	
}

int main(){
	cin>>n;
	a.resize(n),prefix.resize(n);
	cin>>a[0];prefix[0]=a[0];
	rep(i,1,n) {
		cin>>a[i];
		prefix[i]=prefix[i-1]+a[i];
	}
	ll ans =1e15;
	for(int i=1;i<n-1;i++){
		ll sum1 = sum(0,i);
		ll sum2 = sum(i+1,n-1);
		auto itr1 = lower_bound(prefix.begin(),prefix.end(),sum1/2);
		int idx1 = itr1-prefix.begin();
		int idx1_f = decide(idx1-1,idx1,idx1+1,0,i);
		auto itr2 = lower_bound(prefix.begin(),prefix.end(),sum1+sum2/2);
		int idx2 = itr2-prefix.begin();
		int idx2_f = decide(idx2-1,idx2,idx2+1,i+1,n-1);
		//cout<<"Trying at i = "<<i<<" "<<sum1<<" "<<sum2<<" "<<idx1<<" "<<idx2<<" "<<idx1_f<<" "<<idx2_f<<" "<<maximum(sum(0,idx1_f),sum(idx1_f+1,i),sum(i+1,idx2_f),sum(idx2_f+1,n-1))-minimum(sum(0,idx1_f),sum(idx1_f+1,i),sum(i+1,idx2_f),sum(idx2_f+1,n-1))<<endl;
		ans = min(ans,maximum(sum(0,idx1_f),sum(idx1_f+1,i),sum(i+1,idx2_f),sum(idx2_f+1,n-1))-minimum(sum(0,idx1_f),sum(idx1_f+1,i),sum(i+1,idx2_f),sum(idx2_f+1,n-1))); 
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3328
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int l = Integer.parseInt(br.readLine());
		int[] a = new int[l];
		for (int i = 0; i < l; i++) {
			a[i] = Integer.parseInt(br.readLine());
		}
		br.close();
		long[] b = new long[l + 1];
		for (int i = 0; i < l; i++) {
			b[i + 1] = b[i] + a[i];
		}

		long ans = b[l];
		long[] dplr = new long[l + 1];
		long[] dpll = new long[l + 1];
		long[] dprr = new long[l + 1];
		for (int i = 0; i < l; i++) {
			dplr[i + 1] = Math.min(Math.min(dplr[i], dprr[i]), b[i]) + (a[i] % 2 ^ 1);
			dpll[i + 1] = Math.min(Math.min(Math.min(dplr[i], dpll[i]), dprr[i]), b[i]) + a[i] % 2;
			dprr[i + 1] = Math.min(dprr[i], b[i]) + a[i] % 2;
			if (a[i] == 0) {
				dpll[i + 1] += 2;
				dprr[i + 1] += 2;
			}
			long val = Math.min(Math.min(dplr[i + 1], dpll[i + 1]), dprr[i + 1]) + b[l] - b[i + 1];
			ans = Math.min(ans, val);
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 44832
#include <iostream>
#include <limits.h>

using namespace std;

int main(){
  int n, max=0, min=INT_MAX;
  cin >> n;
  for(int i=0;i<n;i++){
    int a;
    cin >> a;
    if(a>max)max=a;
    if(a<min)min=a;
  }
  cout << max - min << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#define X first
#define Y second
#define clr(u,v); memset(u,v,sizeof(u));
#define in() freopen("data","r",stdin);
#define out() freopen("ans","w",stdout);
#define Clear(Q); while (!Q.empty()) Q.pop();
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int maxn = 1e5 + 10;
const ll INF = 1e18;
ll N[maxn];
ll c[maxn];
int main()
{
    ll n;
    cin >> n;
    ll all = (1 + n) * n / 2,sum = 0;
    for (int i = 0; i < n; i++)
        {
            cin >> N[i];
            sum += N[i];
        }
    if (sum%all)
    {
        puts("NO");
        return 0;
    }
    ll k = sum / all;
    N[n] = N[0];
    for (int i = 1; i <= n; i++)
    {
        c[i] = N[i] - N[i-1];
    }
    ll ans = 0;
    for (int i = 1; i <= n; i++)
    {
        c[i] -= k;
        if (c[i] % n == 0)
            ans += abs(c[i] / n);
        else
        {
            puts("NO");
            return 0;
        }
    }
    if (ans == k)
        puts("YES");
    else puts("NO");
    return 0;
}


Measured memory_bytes: 1920
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
using namespace std;

int main(){
    int y,m,d;
    scanf("%d/%d/%d", &y, &m, &d);
    string ans;
    if(y<=2018)ans = "Heisei";
    else if(y==2019){
        if(m<=4) ans = "Heisei";
        else ans = "TBD";
    }
    else ans = "TBD";
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <assert.h>
#include <vector>
#include <unordered_map>
#include <queue>
#include <climits>
#include <cmath>
#include <algorithm>
using namespace std;

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

  int32_t N;
  cin >> N;
  vector<int64_t> A(N);
  for (auto& a : A) {
    cin >> a;
  }
  sort(A.begin(), A.end(), greater<int64_t>());
  int64_t res = A[0];
  for (int i = 1; i <= (N-1) / 2; i++) {
    res += 2 * A[i];
  }
  if (N % 2 != 0) {
    res -= A[(N-1)/2];
  }
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 4784
abcd = input()

l = ["+", "-"]
for i in l:
  for j in l:
    for k in l:
      ans = eval(abcd[0]+i+abcd[1]+j+abcd[2]+k+abcd[3])
      if ans == 7:
        print(abcd[0]+i+abcd[1]+j+abcd[2]+k+abcd[3]+"=7")
        exit()

Measured memory_bytes: 9040
#include <iostream>
using namespace std;
char a[11], b[11];
int main() {
	cin >> a;
	cin >> b;
	for(int i = 0; i < 3; i++)
		if(a[i] != b[2-i]) {
			printf("NO\n");
			return 0;
		}
	printf("YES\n");
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, f, n) for (int i = (f); i < (n); i++)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
ll const INF = 1LL << 60;

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

    vector<int> A(M);
    rep(i, M) cin >> A[i];

    vector<bool> Amap(N + 1);
    rep(i, N + 1) {
        rep(j, M) {
            if (A[j] == i) {
                Amap[i] = true;
                break;
            }
        }
    }

    int a1 = 0;
    int a2 = 0;
    rep(i, X) {
        if (Amap[i]) a1++;
    }

    reps(i, X, N + 1) {
        if (Amap[i]) a2++;
    }

    // rep(i, N + 1) { cout << Amap[i]; }
    // cout << endl;
    cout << min(a1, a2) << endl;

    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

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

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

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

    int N;
    cin >> N;

    vector<char> s(N);
    REP(i,N) cin >> s[i];
    int ans = 0;
    char befor = ' ';
    REP(i,N) {
        if (s[i] != befor) {
            ans++;
            befor = s[i];
        }
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
use std::io;
use std::str::FromStr;

fn input<T:FromStr>() -> T {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.trim().parse().ok().unwrap()
}

fn input_i32_vec() -> Vec<i32> {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.split_whitespace().map(|s| s.parse().unwrap()).collect()
}

fn main() {
    let _: i32 = input();
    let a_vec = input_i32_vec();
    let mut ave = 0f64;
    for a in &a_vec {
        ave += *a as f64;
    }
    ave /= a_vec.len() as f64;
    ave = ave.round();

    let mut ans = 0i32;

    for a in &a_vec {
        ans += (ave as i32 - *a) * (ave as i32 - *a);
    }
    println!("{}", ans);


}


Measured memory_bytes: 4352
/*
	Name:
	Author: xiaruize
	Date:
*/

#include<bits/stdc++.h>
using namespace std;
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define LL long long

int main()
{
 	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	LL n;
	cin>>n;
	if(n%2==1)
	{
		cout<<"0"<<endl;
		return 0;
	}
	LL ans=0;
	for(LL i=5;i<=n;i*=5)
	{
		ans+=n/i;
		if((n/i)%2==1)
		{
			if(n%2==0)
			{
				ans--;
			}
			else
			{
				ans++;
			}
		}
	}
	cout<<ans/2<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int MOD = 1e9 + 7;
const int INF = 2e18;

signed main() {
    string S;
    cin >> S;
    int ans = 0;
    {
        // left;
        int count = 1;
        string check = S.substr(0, 1);
        int before = 1;
        for (int i = 1; i < S.length(); i++) {
            string now = S.substr(before, i - before + 1);
            if (now != check) {
                count++;
                before = i + 1;
                check = now;
            }
        }
        ans = max(ans, count);
    }
    {
        // right
        int count = 1;
        string check = S.substr(S.length() - 1, 1);
        int before = S.length() - 2;
        for (int i = S.length() - 2; i >= 0; i--) {
            string now = S.substr(before, i - before + 1);
            if (now != check) {
                count++;
                before = i - 1;
                check = now;
            }
        }
        ans = max(ans, count);
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <queue>
#include <deque>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <bitset>

#define REP(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define FILL(x, y) memset(x, y, sizeof(x))
#define pb push_back
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

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 (a > b) {
      a = b;
      return 1;
   }
   return 0;
}

using namespace std;
using ll = long long;

const int kInf = 2e9;
const ll kLInf = 2e18;

int gcd (int a, int b) {
   return b ? gcd(b, a % b) : a;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int N, R;
int main()
{
   cout << fixed << setprecision(10);
   cin >> N >> R;
   int ans;
   if (N >= 10) {
      ans = R;
   } else {
      ans = R + 100 * (10 - N);
   } 
   cout << ans << endl;
   return 0;
}



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


class MainClass
{
	static Scanner sc;
	static int D, N, M;
	static int[] d;
	public static void Main(string[] args)
	{
		sc = new Scanner();
		while (true)
		{
			D = sc.nextInt();
			if (D == 0) break;
			N = sc.nextInt();
			M = sc.nextInt();
			d = new int[N];
			d[0] = 0;
			for (int i = 1; i < N; i++)
			{
				d[i] = sc.nextInt();
			}
			Array.Sort(d);
			long ans = 0;
			for (int i = 0; i < M; i++)
			{
				int k = sc.nextInt();
				ans += func(k);
			}
			Console.WriteLine(ans);
		}
	}
	static int func(int n)
	{
		long l = N - 1;
		long r = 0;
		while (l - r > 1)
		{
			long mid = (l + r) / 2;
			if (d[mid] >= n)
			{
				l = mid;
			}
			else
			{
				r = mid;
			}
			//Console.WriteLine(l + " " + r);
		}
		int[] buf = new int[3];
		for (int i = 0; i < 3; i++)
		{
			long id = l + i - 1;
			if (id >= N)
			{
				buf[i] = Math.Abs(D - n);
			}
			else if (id < 0)
			{
				buf[i] = n;
			}
			else 
			{
				buf[i] = Math.Abs(d[id] - n);
			}
		}
		Array.Sort(buf);
		return buf[0];
	}
}

public class Scanner
{
	public Scanner() { }
	public int nextInt()
	{
		return int.Parse(Console.ReadLine());
	}
	public double nextDouble()
	{
		return double.Parse(Console.ReadLine());
	}
	public long nextLong()
	{
		return long.Parse(Console.ReadLine());
	}
	public string next()
	{
		return Console.ReadLine();
	}
	public int[] nextIntArray()
	{
		return Array.ConvertAll(Console.ReadLine().Split(' '), (input) => int.Parse(input));
	}
	public long[] nextLongArray()
	{
		return Array.ConvertAll(Console.ReadLine().Split(' '), (input) => long.Parse(input));
	}
	public double[] nextDoubleArray()
	{
		return Array.ConvertAll(Console.ReadLine().Split(' '), (input) => double.Parse(input));
	}
	public string[] nextArray()
	{
		return Console.ReadLine().Split(' ');
	}
}

Measured memory_bytes: 10012
#include <iostream>
#include <algorithm>
#include <functional>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>

using namespace std;

int t,n=10,a[10002],b[10002],c[10002];
bool flag;

void dfs(int dep,int db,int dc)
{
	if(!flag)return;
	if(dep==n)
	{
		flag=0;
		for(int i=1;i<db;++i)
			if(b[i]<b[i-1])
				flag=1;
		for(int i=1;i<dc;++i)
			if(c[i]<c[i-1])
				flag=1;
		return;
	}
	b[db]=a[dep];
	dfs(dep+1,db+1,dc);
	c[dc]=a[dep];
	dfs(dep+1,db,dc+1);
}
int main()
{
	scanf("%d",&t);
	while(t--)
	{
		flag=1;
		for(int i=0;i<n;++i)
			scanf("%d",&a[i]);
		dfs(0,0,0);
		if(flag)
			printf("NO\n");
		else
			printf("YES\n");
	}
	return 0;
}

Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

int main() {
    int n, k;
    cin >> n >> k;
    map<int, int> m;
    rep(i, n) {
        int a;
        cin >> a;
        m[a]++;
    }

    vi v;
    for(auto p : m) {
        v.push_back(p.second);
    }
    sort(all(v));

    int cnt = max(0, (int)m.size() - k);
    cout << accumulate(v.begin(), v.begin()+cnt, 0) << endl;

    return 0;
}


Measured memory_bytes: 10748
#include <bits/stdc++.h>
using namespace std;
int r[55];
int main(){
    int n, m,a,b;
    memset(r,0,sizeof(r));
    cin >> n>> m;
    for(int i = 1; i<=m; i++)
    {
        scanf("%d%d", &a,&b);
        r[a]++;
        r[b]++;
    }
    for(int i = 1; i<=n; i++)
        printf("%d\n", r[i]);
    return 0;
}

Measured memory_bytes: 256
#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; }

bool solve(lli h, lli w, vector<lli> cnt) {
    lli r1 = (h%2)*(w%2);
    lli r2 = (h%2)*(w/2)+(w%2)*(h/2);
    assert  ((h * w - 2 * r2 - r1) % 4 == 0);
    lli r4 = (h*w-2*r2-r1) / 4;
    rep(i, 26){
        if(cnt[i] < 4) continue;
        while(r4 > 0 && cnt[i] >= 4) cnt[i]-=4, r4--;
    }
    if(r4 > 0) return false;
    rep(i, 26){
        if(cnt[i] < 2) continue;
        while(r2 > 0 && cnt[i] >= 2) cnt[i]-=2, r2--;
    }
    if(r2 > 0) return false;
    return true;
}

int main() {
    lli h, w;
    cin >> h >> w;
    vector<lli> cnt(26);
    rep(i, h) rep(j, w){
        char c;
        cin >> c;
        cnt[c - 'a']++;
    }
    // solve
    bool result = solve(h, w, cnt);
    // output
    printf("%s\n", result ? "Yes" : "No");
    return 0;
}


Measured memory_bytes: 3588
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<bitset>
#define endl "\n"
using namespace std;

int main() 
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  
  int s, tmp, ans;
  int counter=2;
  vector<int> lst;
  cin >> s;
  lst.push_back(s);
  while (1)
  {
    if (lst.back()%2==0)
    {
       tmp = lst.back()/2;
       if (find(lst.begin(), lst.end(), tmp) != lst.end())
       {
          ans = counter;
          break;
       }
       else
       {
           lst.push_back(tmp);
       }
    }
    else
    {
        tmp = lst.back()*3 + 1;
        if (find(lst.begin(), lst.end(), tmp) != lst.end())
        {
            ans = counter;
            break;
        }
        else
        {
            lst.push_back(tmp);
        }
    }
    counter += 1;
  }
  cout << ans << endl;
  return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>  // std::setprecision()
#include <set>

using namespace std;
using ll = long long;
#define rep(i,a,b) for(ll i=(a); i<(b); i++)
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define pai 3.14159265358979323846
ll gcd(ll a, ll b){if (a%b == 0)  return(b);else  return(gcd(b, a%b));}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}
/* map<string,int> */
/* 大文字を小文字に変換 tolower*/
/* 小文字を大文字に変換 toupper*/
/* 辞書順 next_permutation(a.begin(),a.end()) */
void printVec(std::vector<char> &vec) {
  std::cout << "";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    std::cout << *it << " ";
  }
  std::cout << std::endl;
}
 
int main() {
    int n,m,x;
    cin >> n >> m >>x;
    int t = x;
    vector <int> a(m);
    rep(i,0,m) {
        cin >> a[i];
    }
    int sum = 0;
    int mi = 0;
    while (x != n) {
        bool flag = false;
        x++;
        rep (i,0,m) {
            if (a[i] == x) {
                flag = true;
            }
        }
        if (flag) sum++;
    }
    mi = sum;
    sum = 0;
    x = t;
    while (x != 0) {
        bool flag = false;
        x--;
        rep (i,0,m) {
            if (a[i] == x) {
                flag = true;
            }
        }
        if (flag) sum++;
    }
    mi = min(mi,sum);
    cout << mi << endl;
}

Measured memory_bytes: 3180
def solve():
    N, P = map(int, input().split())
    S = input()

    if P == 2 or P == 5:
        res = 0

        for i in range(N):
            if int(S[i]) % P == 0:
                res += i + 1
        
        print(res)

    else:
        res = 0
        count = [0] * P
        r = 0

        for i in range(N-1, -1, -1):
            r = (int(S[i]) * pow(10, N-1 - i, P) + r) % P
            if r == 0: res += 1
            res += count[r]
            count[r] += 1
        
        print(res)

if __name__ == '__main__':
    solve()


Measured memory_bytes: 3500
#include<cstdio>
#include<cstring>
using namespace std;
int N,K;
char sz[5000];
bool ok(int n,char a[],int lo){
	if(lo==0)	return true;
	for(int i=n;i<n+lo;i++){
		if(sz[i]!=a[i-n])	return false;
	}
	return true;
}
void sou(char a[]){
	if(K==0)	return;
	char b[5000]={0};
	bool o[26]={false};
	int ng=strlen(a);
	for(int i=0;i<ng;i++)	b[i]=a[i];
	for(int i=ng;i<N;i++){
		if(ok(i-ng,a,ng))	o[sz[i]-'a']=true;
	}
	for(int i=0;i<26;i++){
		if(o[i]){
			b[ng]=i+'a';
			--K;
			if(K==0){
				printf("%s",b);
				return;
			}
			sou(b);
		}
		if(K==0)	return;
	}
}
int main(){
	scanf("%s %d",sz,&K);
	while(sz[N]!='\0')	++N;
	char a[5000]={'\0'};
	sou(a);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
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; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define FOR(i,a,b) for(long long i=a; i<b; i++)
#define ll long long
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define PB(x) push_back(x)
#define MP make_pair
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstr vector<string>
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) max_element(x.begin(),x.end())
#define MIN(x) min_element(x.begin(),x.end())
#define couty cout<<'Y'<<'e'<<'s'<<endl
#define coutn cout<<'N'<<'o'<<endl
#define coutY cout<<'Y'<<'E'<<'S'<<endl
#define coutN cout<<'N'<<'O'<<endl
//fixed<<setprecision(15);
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
const long long dx[4]={1,0,-1,0};
const long long dy[4]={0,1,0,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;
signed main(){
    int k,s; cin >> k >> s;
    vint a(k+1); rep(i,k+1) a[i]=i;
    int res=0;
    rep(i,k+1){
        rep(j,k+1){
            int z=s-a[i]-a[j];
            if(z>=0 && z<=k) res++;
        }
    }
    cout<<res<<endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

template <typename TYPE>
void print_vec(const vector<TYPE>& v){
	for(int i=0; i<v.size(); i++){
		cout << v[i] << " ";
	}
	cout << endl;
}

template <typename TYPE>
void print_vec2(const vector<vector<TYPE>>& v){
  cout << endl; cout << "       ";
  for(int i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(int j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}



int main(){
	ll N;
	cin >> N;

	string c;
	cin >> c;

	// vector<int> Rs, Ws;
	deque<int> Rs, Ws;
	for(int i=0; i<N; i++){
		if(c[i] == 'R') Rs.push_back(i);
		else Ws.push_back(i);
	}

	ll ans = 0;
	if((int)Ws.size() == 0){
		cout << ans << endl;
		return 0;
	}
	if((int)Rs.size() == 0){
		cout << ans << endl;
		return 0;
	}
	while(Rs.back() >= Ws[0]){
		int tmp = Rs[Rs.size()-1];
		Rs.pop_back();
		Ws.push_back(tmp);

		int tmp2 = Ws[0];
		Ws.pop_front();
		Rs.push_front(tmp2);
		ans++;
		//std::swap(Rs.back(), Ws[0]);
		// int tmp = Rs[Rs.size()-1];
		// Rs[Rs.size()-1] = Ws[0];
		// Ws[0] = tmp;
		// sort(Rs.begin(), Rs.end());
		// sort(Ws.begin(), Ws.end());
		// ans++;
	}
	cout << ans << endl;


	// ll ans1 = 0;
	// bool is_white = false;
	// for(int i=0; i<N; i++){
	// 	if(is_white){
	// 		if(c[i] == 'R') ans1++;
	// 	}
	// 	if(c[i] == 'W') is_white = true;
	// }

	// ll ans2 = 1;
	// is_white = false;
	// for(int i=N-1; i>=0; i--){
	// 	if(is_white){
	// 		if(c[i] == 'R') ans2++;
	// 	}
	// 	if(c[i] == 'W') is_white = true;
	// }
	// ll ans = min(ans2, ans1);
	// cout << ans << endl;




	return 0;
}



Measured memory_bytes: 4436
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define pye cout << "yes" << endl;
#define pno cout << "no" << endl;
#define pYe cout << "Yes" << endl;
#define pNo cout << "No" << endl;
#define pYE cout << "YES" << endl;
#define pNO cout << "NO" << endl;
#define prin(num) cout << num << endl;
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 100000000000
#define MOD 1000000007LL
#define MAX 100050
#define NIL -1
#define WHITE 0
#define BLACK 1
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;

ll H, W;

int main(void) {
    ll i, j;
    cin >> H >> W;
    ll a[H+1][W+1];
    for(i=1; i<=H; i++) {
        for(j=1; j<=W; j++) {
            cin >> a[i][j];
        }
    }
    ll k=1, l=1;
    ll dire=0;
    ll ans=0;
    vector<pair<P, P>> m;
    for(i=0; i<H*W-1; i++) {
        if(a[k][l]%2==1) {
            ans++;
            if(l<W && dire==0) {
                a[k][l]--; a[k][l+1]++;
                m.push_back(make_pair(P(k, l), P(k, l+1)));
                l++;
            }else if(l==W && dire==0) {
                a[k][l]--; a[k+1][l]++;
                m.push_back(make_pair(P(k, l), P(k+1, l)));
                k++;
                dire=1;
            }else if(l>1 && dire==1) {
                a[k][l]--; a[k][l-1]++;
                m.push_back(make_pair(P(k, l), P(k, l-1)));
                l--;
            }else if(l==1 && dire==1) {
                a[k][l]--; a[k+1][l]++;
                m.push_back(make_pair(P(k, l), P(k+1, l)));
                k++;
                dire=0;
            }
        } else {
            if(l<W && dire==0) {
                l++;
            }else if(l==W && dire==0) {
                k++;
                dire=1;
            }else if(l>1 && dire==1) {
                l--;
            }else if(l==1 && dire==1) {
                k++;
                dire=0;
            }
        }
    }
    
    prin(ans)
    for(i=0; i<m.size(); i++) {
        printf("%lld %lld %lld %lld\n", m[i].first.first, m[i].first.second, m[i].second.first, m[i].second.second);
    }
    
    
}



Measured memory_bytes: 8432
//{{{
#include<algorithm>
#include<cmath>
#include<deque>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(printde) FUNC(printdbe) FUNC(printdwe) FUNC(printdu);
#endif
template <template <class T, class = std::allocator<T>> class V, class E>
istream& operator >> (istream& in, V<E>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    int k, x;
    cin >> k >> x;
    for(int i = x - k + 1; i <= x + k - 1; i++){
        cout << i << ' ';
    }
}


Measured memory_bytes: 888
import sys

X,N=(int(x) for x in input().split())
if N==0:
  print(X)
  sys.exit()

P=input().split()
P_int = [int(s) for s in P]
#print(P_int)
#print(X,Y)
#print(4 in P_int)
if not X in P_int:
  print(X)
  sys.exit()

for i in range(1,100):
  if not (X-i) in P_int:
    print(X-i)
    sys.exit()
  
  if not (X+i) in P_int:
    print(X+i)
    sys.exit()
  
  



Measured memory_bytes: 9200
(h, w, k) = list(map(int, input().split()))
n = [0, 1] + [0 for _ in range(w - 1)]
c = {0: 1, 1: 1, 2: 2, 3: 3, 4: 5, 5: 8, 6: 13, 7: 21}
for i in range(h):
    nn = [0 for _ in range(w + 1)]
    for j in range(1, w + 1):
        nn[j] += c[max(0, j - 1)] * n[j]     * c[max(0, w - j)]
    for j in range(2, w + 1):
        nn[j] += c[max(0, j - 2)] * n[j - 1] * c[max(0, w - j)]
    for j in range(1, w):
        nn[j] += c[max(0, j - 1)] * n[j + 1] * c[max(0, w - j - 1)]
    n = nn

print(n[k] % 1000000007)

Measured memory_bytes: 3064
/*

　　　　　　　　　　　　　　　　　　　　　　　　　　　 　 　 　 　 　 　 　 ／ 
　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　 { 
　　　　　＿＿＿＿＿＿＿＿＿　　　　　　　　　　　　,.-‐┬‐┬ｧ　l 
　　　　　　　￣｀ー､＿　　 l::::::::}ヽ　　　　　　　l　l　-ﾆ､＿_l_;:='／　 ', 
　　　　　　　　　　　　　｀ｰ┴‐'"´　　　　　　　 l　l　＼　ー─‐　　　　i 
　　　　　　　　　　　　　　　　　　　　　　　　　　 l　l　　＼　 　 　 　 　 l 
　　　　　　　　　　　　　　　　　　　　　　　　　　　l　l　　　＼　　　　 　 } 
　　　　　　　　　　　　　　　　　　　　　　　　　　　 l　l　　　　　　　　 　 l 
　　　　　　　　　　　　　　　　　　　　　　　　　　　　l　l　　　　　　　　　,' 
　　　　　　　　　　　　　　　　　　 ／　　　　　　　　 ヽ ヽ　　　　　　　,' 
　　　　　　　　　　　　　　　　 .／{　　　　　　　　　 　 }　} 　 　 　 　 ,' 
　　　　　　　　　　　　　　　　　　 ヽ、　＿＿　　　　ノ ノ　　　　　　/ 
　　　　　　　　　　　　　　　　　　　　　　¨¨¨｀　ーテ ´　　　　　　 / 
　　　　　　　　　　　　　　　　　　　　　　　　/　　 l　　　　　　　　/ 
　　　　　　　　　　　　　　　　　　　　　　　　ゝ、　j　 　 　 　 　 / 
　　　　　　　　　　　　　　　　　　 　 ,. -‐'"　　￣　｀ヽ　 　 　 /＿＿＿＿ 
　　　　　　　　　　 　 　 　 ＿,.-‐'" -‐┬‐┬‐┬ｭ､＿,,　 　 /　　　　　　　｀ ー─-､ 
　　　　　　　　 　 　 　 　 　 　 ￣ ｀ー┴‐┴‐‐'"ﾞ￣　　　 /　　　　　　　　　　　　　 ￣｀ー-､ 
　　　　　　　　　　　　　　　　　　　　　　　　　 　 ＿ ノ　　/　　　　　　　　　　　　　　　　　　　｀ー-､




*/
#include<stdio.h>
int N;
int F[100][14];
int P[100][15];
int main(){
	scanf("%d",&N);
	for(int i=0;i<N;i++) {
		for(int j=0;j<10;j++)
			scanf("%d",&F[i][j]);
	}
	for(int i=0;i<N;i++)
		for(int j=0;j<11;j++)
			scanf("%d",&P[i][j]);
	int res = -(1<<30);
	for(int b=1;b<(1<<10);b++){
		int cc=0;
		for(int i=0;i<N;i++){
			int c=0;
			for(int j=0;j<10;j++)
				if((b>>j&1)&&F[i][j])
					c++; 
				cc+=P[i][c];
		}
		if(res<cc)
			res=cc;
	}
	printf("%d\n",res);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
int main(){
    int n,m;
    cin >> n >> m;
    vector<pair<int,int>> p(m,pair<int,int>());
    for(int i = 0;i < m;i++)cin >> p[i].first >> p[i].second;
    sort(p.begin(),p.end());
    int ans = 1;
    int l = p[0].first;
    int r = p[0].second;
    for(int i = 1;i < m;i++){
        if(p[i].second <= r){
            r = p[i].second;
        }
        if(p[i].first >= r){
            ans++;
            l = p[i].first;
            r = p[i].second;
        }
    }
    cout << ans << endl;
    //cin >> n;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

int main(void){
	int n[2],i,k;
	ll s[2]={0ll,0ll},x[100100],t;
	cin >> n[0] >> n[1];
	for(k=0; k<2; ++k){
		for(i=0; i<n[k]; ++i){
			cin >> x[i];
		}
		for(i=1; i<n[k]; ++i){
			t = (x[i]-x[i-1]);
			mul_mod(t,i);
			mul_mod(t,n[k]-i);
			add_mod(s[k],t);
		}
	}
	cout << ((s[0]*s[1])%MOD) << endl;
	return 0;
}


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

typedef long long ll;

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

    ll n,m,a;
    cin >> n >> m;
    vector<bool> broken(100100,false);
    for(ll i=0;i<m;i++){
        cin >> a;
        broken[a] = true;
    }
    ll dp[100100];
    dp[0] = 1LL;
    for(ll i=1;i<=n;i++) dp[i] = 0LL;
    const ll MOD = 1e9+7;
    for(ll i=1;i<=n;i++){
        if(broken[i]) continue;
        if(i==1) dp[i] = dp[i-1]%MOD;
        else dp[i] = dp[i-1]%MOD + dp[i-2]%MOD;
        dp[i] %= MOD;
    }
    cout << dp[n]%MOD << endl;
    return 0;
}

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

#define   ipr         	pair<int, int>
#define   pb            push_back
#define   ff            first
#define   ss            second
#define   fr(i, j, k)   for (int i = j; i < k; i++)
#define   rf(i, j, k)   for (int i = j; i >= k;i--)
#define   int           long long
#define   ll 			unsigned long long
#define   ld            long double
#define   all(x)        x.begin(), x.end()
#define   rall(x)       x.rbegin(),x.rend()
#define   mp            make_pair
#define   inf           INT_MAX
#define   read_file();	freopen("input.txt", "r", stdin);	freopen("output.txt", "w", stdout);
#define   IOS           std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

const int Maxn  =  2019;
const ld  pi   =  acos(-1);
const int mod =  1000000007;

template<class T> ostream& operator <<(ostream &out,vector<T> &A){for(auto x:A) out<<x<<" ";return out;}
template<class T> ostream& operator <<(ostream &out,set<T> &A){for(auto x:A) out<<x<<" ";return out;}
template <class T1,class T2>T1 powr(T1 a,T2 b){T1 res = 1;fr(i,1,b+1)res = res*a;return res;}


int32_t main(){ IOS
    int n,k,sum=0;    cin>>k>>n;
    fr(i,0,n){
        int x;  cin>>x;
        sum += x;
    }
    puts((sum>=k) ? "Yes" : "No");
    return 0;
}

Measured memory_bytes: 256
#二部グラフで連結判定
N,M = map(int,input().split())
KL = [list(map(int,input().split())) for _ in [0]*N]

c = [False]*(N+M) #d[0] - d[N-1]:人, d[N] - D[N+M-1]:言語
E = [[] for _ in [0]*(N+M)]
for i,kl in enumerate(KL):
    for l in kl[1:]:
        E[i].append(N+l-1)
        E[N+l-1].append(i)

start = 0
q = [start]
c[start] = True
while q:
    i = q.pop()
    for j in E[i]:
        if c[j]:continue
        c[j] = True
        q.append(j)

ans = True
for b in c[:N]:
    ans = ans and b
print("YES" if ans else "NO")

Measured memory_bytes: 48692
#include<stdio.h>

int main(){
	int n,i,flag;
	char hina[300];
	scanf("%d",&n);
	for(i=0;i<2*n+1;i++){
	scanf("%c",&hina[i]);
}

	flag=0;

	for(i=0;i<n+1;i++){
		if(hina[i]=='Y'){
			flag=1;
		}
	}

	if(flag==1){
		printf("Four\n");
	}else{
		printf("Three\n");
	}
	return 0;
}


Measured memory_bytes: 128
def main():
    s = input()
    n = len(s)
    k = int(input())
    # dp[使った回数][左端からの距離][左端]
    dp = [[[1]*(n-i) for i in range(n)] for _ in range(k+1)]

    for i in range(n-1):
        if s[i] == s[i+1]:
            dp[0][1][i] = 2
    if k > 0:
        for cnt in range(1, k+1):
            for i in range(n-1):
                dp[cnt][1][i] = 2

    for cnt in range(k):
        for d in range(2, n):
            for left in range(n-d):
                right = left+d
                plus = (s[left] == s[right])*2
                dp[cnt][d][left] = max(
                    dp[cnt][d][left], dp[cnt][d-1][left],
                    dp[cnt][d-1][left+1], dp[cnt][d-2][left+1]+plus)
                dp[cnt+1][d][left] = max(
                    dp[cnt+1][d][left], dp[cnt][d][left], dp[cnt][d-2][left+1]+2)
    for d in range(2, n):
        for left in range(n-d):
            right = left+d
            plus = (s[left] == s[right])*2
            dp[k][d][left] = max(
                dp[k][d][left], dp[k][d-1][left], dp[k][d-1][left+1], dp[k][d-2][left+1]+plus)
    print(dp[-1][-1][0])


main()

Measured memory_bytes: 154076
n = gets.strip.split(' ').map(&:to_i)[0]
h = gets.strip.split(' ').map(&:to_i)

ans = "Yes"
max_prev = 0
(1..n).each do |num|
    if h[num-1] < max_prev-1 then
        ans = "No"
        break
    end
    if h[num-1] > max_prev then
        max_prev = h[num-1]
    end
end
puts(ans)

Measured memory_bytes: 9604