akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
string a;
int x=0,y=0,p=0,k=0;
int main(){
	cin>>a;
  for(int i=0;i<a.size();i++){
  	if(a[i]=='N')x++;
  	if(a[i]=='S')p++;
    if(a[i]=='W')y++;
    if(a[i]=='E')k++;
  }
  if(((x!=0&&p!=0)||(x==0&&p==0))&&((y!=0&&k!=0)||(y==0&&k==0))){
  	cout<<"Yes"<<endl;
  }
  else cout<<"No"<<endl;
}

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

//DFSによって全域正規木を作り、そこから関節点を知る
const int MAX=100100;
int V,E,s,t,np;
vector<int> A[MAX];
set<int> ans;
int d[MAX],prenum[MAX],lowest[MAX],parent[MAX];

int min(int a,int b){
    if(a<b) return a;
    else return b;
}

void dfs(int s,int depth){
    d[s]=1;
    lowest[s]=prenum[s]=depth;
    for(int i=0;i<A[s].size();++i){
        if(d[A[s][i]]!=1){
            parent[A[s][i]]=s;
            dfs(A[s][i],depth+1);
            lowest[s]=min(lowest[s],lowest[A[s][i]]);
        }
        else if(A[s][i]!=parent[s]){
            lowest[s]=min(lowest[s],prenum[A[s][i]]);
        }
    }
}


int main(){
    cin>>V>>E;
    for(int i=0;i<E;++i){
        cin>>s>>t;
        A[s].push_back(t);
        A[t].push_back(s);
    }

    dfs(0,0);

    for(int i=1;i<V;++i){
        int p=parent[i];
        if(p==0) ++np;
        else if(prenum[p]<=lowest[i]) ans.insert(p);
    }

    if(np>1) ans.insert(0);
    for(auto i=ans.begin();i!=ans.end();++i){
        cout<<*i<<endl;
    }


}


Measured memory_bytes: 6988
import numpy as np

a, b, h, m = [int(i) for i in input().split()]

minute = h*60 + m
a_ang = (minute%720 * np.pi) / 360
b_ang = (minute%60 * np.pi) / 30

theta = min(abs(a_ang-b_ang), abs(b_ang-a_ang))

c = np.sqrt(a**2 + b**2 - 2*a*b*np.cos(theta))
print("{:.12f}".format(c))

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

#define rep(i, n) for (ll 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; }
#define ALL(x) (x).begin(),(x).end()
#define Sort(a) sort(ALL(a))
#define Rev(a) reverse(ALL(a))


using namespace std;
//using ll=long long;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pi;
const long double PI=3.14159265358979323846;


template<class T> bool contain(const std::string& s, const T& v) {
   return s.find(v) != std::string::npos;
}


int main(){

  ll n;
  cin>>n;

  vector<ll> h(n+1);
  rep(i,n){
    cin>>h[i];
  }
  h[n]=100000000000;
  ll ans = 0;

  ll i = 0;
  ll j = 0;
  while(h[j]==0) j++;
  i=j;
  
  while(j<n){
    //cout<<j<<h[i]<<endl;
    if(i>n-1 || h[i]==0) {
      //cout<<"#"<<ans<<" "<<i<<" "<<j<<endl;
      while(h[j]==0) j++;
      i=j;
      ans++;
    }
    if(h[i]>0) {
      h[i]--;
      //cout<<i<<endl;
      i++;
    }
  }
  
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdint>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <valarray>
#include <vector>

#if __has_include(<string_view>)
#include <string_view>
#endif
#if __has_include(<optional>)
#include <optional>

template <class T>
constexpr const T& max(const T& a, const std::optional<T>& b)
{
    return b ? max(a, *b) : a;
}

template <class T>
constexpr const T& max(const std::optional<T>& a, const T& b)
{
    return a ? max(*a, b) : b;
}

template <class T>
constexpr const std::optional<T>& max(const std::optional<T>& a, const std::optional<T>& b)
{
    if (a && b)
        return *a > *b ? a : b;
    else if (a)
        return a;
    else
        return b;
}

template <class T>
constexpr const T& min(const T& a, const std::optional<T>& b)
{
    return b ? min(a, *b) : a;
}

template <class T>
constexpr const T& min(const std::optional<T>& a, const T& b)
{
    return a ? min(*a, b) : b;
}

template <class T>
constexpr const std::optional<T>& min(const std::optional<T>& a, const std::optional<T>& b)
{
    if (a && b)
        return *a < *b ? a : b;
    else if (a)
        return a;
    else
        return b;
}

#endif
#if __has_include(<any>)
#include <any>
#endif

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

using namespace std;

template <class T, class U>
istream& operator>>(istream& is, pair<T, U>& pair)
{
    is >> pair.first >> pair.second;
    return is;
}

template <class T>
istream& operator>>(istream& is, vector<T>& collection)
{
    for (auto& item : collection)
        is >> item;
    return is;
}

template <class T>
istream& operator>>(istream& is, valarray<T>& collection)
{
    for (auto& item : collection)
        is >> item;
    return is;
}

template <class T>
T peak_and_pop(std::queue<T>& q)
{
    assert(!q.empty());
    T t = move(q.front());
    q.pop();
    return t;
}

template <class T>
T peak_and_pop(std::priority_queue<T>& q)
{
    assert(!q.empty());
    T t = move(q.top());
    q.pop();
    return t;
}

template <class T>
T peak_and_pop(std::stack<T>& q)
{
    assert(!q.empty());
    T t = move(q.top());
    q.pop();
    return t;
}

const double PI=3.14159265358979323846;

void solution()
{
    double a,b,h,m;
    cin >> a >> b >> h >> m;
    const double ha = (h * 60 + m) / (60*6) * PI;
    const double ma = m / 30 * PI;
    const double dx = a * cos(ha) - b * cos(ma);
    const double dy = a * sin(ha) - b * sin(ma);
    cout << hypot(dx,dy) << '\n';
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    solution();
    return 0;
}


Measured memory_bytes: 4184
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<cstring>
using namespace std;

const int N_MAX = 200005;
typedef pair<int, int> P;
vector<P> ROB;
const int MOD = 998244353;
const int INF = 1000000005;
const int mINF = -1000000005;

template< typename Monoid >
struct SegmentTree {
  using F = function< Monoid(Monoid, Monoid) >;

  int sz;
  vector< Monoid > seg;

  const F f;
  const Monoid M1;

  SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) {
    sz = 1;
    while(sz < n) sz <<= 1;
    seg.assign(2 * sz, M1);
  }

  void set(int k, const Monoid &x) {
    seg[k + sz] = x;
  }

  void build() {
    for(int k = sz - 1; k > 0; k--) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  void update(int k, const Monoid &x) {
    k += sz;
    seg[k] = x;
    while(k >>= 1) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  Monoid query(int a, int b) {
    Monoid L = M1, R = M1;
    for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if(a & 1) L = f(L, seg[a++]);
      if(b & 1) R = f(seg[--b], R);
    }
    return f(L, R);
  }

  Monoid operator[](const int &k) const {
    return seg[k + sz];
  }

  template< typename C >
  int find_subtree(int a, const C &check, Monoid &M, bool type) {
    while(a < sz) {
      Monoid nxt = type ? f(seg[2 * a + type], M) : f(M, seg[2 * a + type]);
      if(check(nxt)) a = 2 * a + type;
      else M = nxt, a = 2 * a + 1 - type;
    }
    return a - sz;
  }


  template< typename C >
  int find_first(int a, const C &check) {
    Monoid L = M1;
    if(a <= 0) {
      if(check(f(L, seg[1]))) return find_subtree(1, check, L, false);
      return -1;
    }
    int b = sz;
    for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if(a & 1) {
        Monoid nxt = f(L, seg[a]);
        if(check(nxt)) return find_subtree(a, check, L, false);
        L = nxt;
        ++a;
      }
    }
    return -1;
  }

  template< typename C >
  int find_last(int b, const C &check) {
    Monoid R = M1;
    if(b >= sz) {
      if(check(f(seg[1], R))) return find_subtree(1, check, R, true);
      return -1;
    }
    int a = sz;
    for(b += sz; a < b; a >>= 1, b >>= 1) {
      if(b & 1) {
        Monoid nxt = f(seg[--b], R);
        if(check(nxt)) return find_subtree(b, check, R, true);
        R = nxt;
      }
    }
    return -1;
  }
};

int dp[N_MAX];

int main(){
    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        int x, d;
        cin >> x >> d;
        ROB.push_back(make_pair(x, d));
    }
    sort(ROB.begin(), ROB.end());
    long long int ans = 1;
    SegmentTree<int> seg(n+5, [](int a, int b){return max(a, b);}, mINF);
    for(int i = n-1; i >= 0; i--){
        int x = ROB[i].first;
        int d = ROB[i].second;
        int last = lower_bound(ROB.begin(), ROB.end(), make_pair(x+d, 0)) - ROB.begin();
        seg.update(i, last-1);
        int tlast = seg.query(i, last);
        seg.update(i, tlast);
    }
    dp[n] = 1;
    for(int i = n-1; i >= 0; i--){
        dp[i] = dp[i+1] + dp[seg[i]+1];
        dp[i] %= MOD;
    }
    cout << dp[0] << endl;
    return 0;
}

Measured memory_bytes: 4720
#include<iostream>

const long long MOD = 1000000007;

int main(){
    int N;
    std::cin >> N;
    long long power = 1;
    for(int i = 1; i <= N; i++){
        power = (power * i) % MOD;
    }
    std::cout << power << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<ctime>
#include<vector>
#include<iomanip>

using namespace std;

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

	vector<int> A(n);
	unsigned long long maxTall = 0, total = 0;

	for (int i = 0; i < n; i++)
	{
		cin >> A[i];
		
		if (maxTall > A[i])
		{
			unsigned long long distance = maxTall - A[i];
			total += distance;
		}
		else if (maxTall < A[i])
		{
			maxTall = A[i];
		}
	}

	cout << total << endl;

	return 0;
}

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

#define ll long long
#define ld long double
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define ppb pop_back
#define vll vector<ll>
#define vi vector<int>
#define endl "\n"

const ll INF = 1000000007;

/*
const int max_size = 100001;
int parent[max_size];
int Size[max_size];

int root(int x){
	while(x!=parent[x]){
		parent[x] = parent[parent[x]];
		x = parent[x];
	}
	return x;
}

void sunion(int x,int y){
	int rx = root(x);
	int ry = root(y);
	if(rx != ry){
		if(Size[rx] > Size[ry]){
			parent[ry] = parent[rx];
			Size[rx] += Size[ry];
		}
		else{
			parent[rx] = parent[ry];
			Size[ry] += Size[rx];
		}
	}
}
*/

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t=1;
	//cin >> t;
	while(t--){
		int n;
		cin >> n;
		string s;
		cin >> s;
		int r[n+1],g[n+1],b[n+1];
		r[0] = g[0] = b[0] = 0;
		for(int i=0;i<n;i++){
			r[i+1] = r[i];
			g[i+1] = g[i];
			b[i+1] = b[i];
			if(s[i] == 'R') r[i+1]++;
			else if(s[i] == 'G') g[i+1]++;
			else b[i+1]++;
		}
		ll sum=0;
		for(int i=0;i<n;i++){
			for(int j=i+1;j<n;j++){
				if(s[i] != s[j]){
					int k=2*j-i;
					if(s[i]!='R' && s[j]!='R'){
						sum += (r[n]-r[j+1]);
						if(k<n && s[k]=='R') sum--;
					}
					if(s[i]!='G' && s[j]!='G'){
						sum += (g[n]-g[j+1]);
						if(k<n && s[k]=='G') sum--;
					}
					if(s[i]!='B' && s[j]!='B'){
						sum += (b[n]-b[j+1]);
						if(k<n && s[k]=='B') sum--;
					}
				}
			}
		}
		cout << sum << endl;
	}
	return 0;
}


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

int main() {
  int n;
  cin >> n;
  
  vector<int> p(n);
  for (int i = 0; i < n; i++) {
    cin >> p.at(i);
  }
  
  int num = 1;
  int min = p.at(0);
  for (int i = 1; i < n; i++) {
    if (p.at(i) < min) {
      min = p.at(i);
      num++;
    }
  }
  cout << num << endl;
}

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

const int nm = 1e6;
int n, l, r, cnt, ls, rs;
;
vector<pair<int, int>> b, c;

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		cnt = 0, l = 0, r = 0;
		for (int i = 0; i < (int) s.size(); i++) {
			if (s[i] == '(')
				cnt--;
			else
				cnt++;
			l = max(cnt, l);
		}
		cnt = 0;
		for (int i = s.size() - 1; i >= 0; i--) {
			if (s[i] == ')')
				cnt--;
			else
				cnt++;
			r = max(cnt, r);
		}
		if (l == 0) {
			ls += r;
		} else if (r == 0)
			rs += l;
		else if (r - l >= 0)
			b.emplace_back(l, r);
		else
			c.emplace_back(r, l);
	}
	sort(b.begin(), b.end());
	sort(c.begin(), c.end());
	for (auto &x : b) {
		if (x.first <= ls)
			ls += x.second - x.first;
		else {
			cout << "No" << endl;
			return 0;
		}
	}
	for (auto &x : c) {
		if (x.first <= rs)
			rs += x.second - x.first;
		else {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << (ls == rs ? "Yes" : "No") << endl;
}


Measured memory_bytes: 5272
#include <iostream>
#include <stdio.h>

using namespace std;

int N, v[110];

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

    for(int i = 1; i < N; i++) {
        for(int j = 0; j < N; j++) {
            if(j == N - 1) {
                cout << v[j] << endl;
            } else {
                cout << v[j] << " ";
            }
        }
        int key = v[i];
        int id = i - 1;
        while(id >= 0 && v[id] > key) {
            v[id + 1] = v[id];
            id--;
        }
        v[id + 1] = key;
    }
    for(int j = 0; j < N; j++) {
        if(j == N - 1) {
            cout << v[j] << endl;
        } else {
            cout << v[j] << " ";
        }
    }
    return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define inf INT_MAX
#define sc(a) scanf("%d",&a)
#define scc(a,b) scanf("%d %d",&a,&b)
#define sccc(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pf(a) printf("%d",a)
#define pff(a,b) printf("%d %d",a,b)
#define pfff(a,b,c) printf("%d %d %d",a,b,c)
#define pb(a) push_back(a)
#define em empty()
#define fr front()
#define cl clear()
#define sz size()
#define mp(a,b) make_pair(a,b)
#define fri(b) freopen(b,"r",stdin)
#define fro(b) freopen(b,"w",stdout)
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
/*
ID: uslusam1
TASK: test
LANG: C++
*/
using namespace std;

long long n,w,sum;
long long arr[113][3];
long long dp[113][100013];

long long solve(long long x,long long y,long long ans){
	if(y<0){
		return (long long)1e17;
	}
	if(dp[x][y]!=-1){
		return ans+dp[x][y];
	}
	if(y==0){
		dp[x][y]=0;
		return ans;
	}
	if(x>n){
		dp[x][y]=(long long)1e17;
		return (long long)1e17;		
	}	
	long long don=min(solve(x+1,y,ans),solve(x+1,y-arr[x][2],ans+arr[x][1]));
	dp[x][y]=don-ans;
	return don;
}
 
int main(){
	//fri("a.txt");
	//fro("b.txt");
	memset(dp,-1,sizeof dp);
	scanf("%lld %lld",&n,&w);
	for(int i=1;i<=n;i++){
		scanf("%lld %lld",&arr[i][1],&arr[i][2]);
		sum+=arr[i][2];
	}
	for(long long i=sum;i>0;i--){
		if(solve(1,i,0)<=w){
			cout<<i<<endl;
			break;
		}
	}
	
	return 0;
}


Measured memory_bytes: 88576
# 初期入力
import sys
input = sys.stdin.readline  #文字列では使わない
H,W = map(int, input().split())
a = [list(map(int, input().split())) for i in range(H)]

#左上から右下に向かって探索
ans =[]
for h in range(H):
    for w in range(W-1):
        if a[h][w] %2 ==1:
            a[h][w] -=1
            a[h][w+1] +=1
            ans.append((h+1,w+1,h+1,w+2))
for i in range(H):
    if a[i][W-1] %2 ==1:
        if i !=H-1:        
            a[i][W-1] -=1
            a[i+1][W-1] +=1
            ans.append((i+1,W,i+2,W))


print(len(ans))
for i in range(len(ans)):
    print(*ans[i])

Measured memory_bytes: 30412
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<cstdio>
#include<string>
#include<vector>
#include<math.h>
#include<time.h>
#include<utility>
#include<cstdlib>
#include<sstream>
#include<cstring>
#include<stdio.h>
#include<iomanip>
#include<iostream>
#include<algorithm>
//#include<conio.h>
//ios::sync_with_stdio(false);
using namespace std;
long long n;
int main(){
	cin>>n;
	for(long long i=1;i<3500;i++){
		for(long long j=i;j<3500;j++){
			long long deno=i+j;
			long long nume=i*j;
			long long diff=4*nume-deno*n;
			long long nnume=nume*n;
			long long g=__gcd(diff,nnume);
			diff/=g;nnume/=g;
			if(diff==1&&nnume>0){
				cout<<i<<" "<<j<<" "<<nnume<<endl;
				return 0;
			}
			if(diff/nnume<4/n) break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define forn(i, n) for (ll i = 0; i < (n); i++)
#define fori(i, b, e) for (ll i = (b); i < (e); i++)
#define forr(i, b, e) for (ll i = (b); i >= (e); i--)
#define allele(v) v.begin(), v.end()
#define fi first
#define se second

ll mod;

class Matrix
{
public:
    vector<vector<ll>> M;

    Matrix(int h, int w)
    {
        M = vector<vector<ll>>(h, vector<ll>(w));
    }

    vector<ll> &operator[](int i)
    {
        return M[i];
    }
};

Matrix operator*(Matrix x, Matrix y)
{
    int xh = x.M.size(), xw = x[0].size();
    int yh = y.M.size(), yw = y[0].size();
    if (xw != yh)
        throw invalid_argument("Sizes do not match.");
    Matrix res(xh, yw);
    forn(i, xh) forn(j, yw)
    {
        res[i][j] = 0;
        forn(k, xw) res[i][j] += ((x[i][k] % mod) * (y[k][j] % mod)) % mod, res[i][j] %= mod;
    }
    return res;
}

template <typename T>
T quickpow(T b, ll e)
{
    T cur = b;
    T ans = b;
    e--;
    while (e)
    {
        if (e & 1)
            ans = ans * cur;
        cur = cur * cur;
        e >>= 1;
    }
    return ans;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll l, a, b;
    cin >> l >> a >> b >> mod;

    ll pow10[20];
    ll cur = 1;
    forn(i, 19) pow10[i] = cur, cur *= 10;

    Matrix ans(3, 1);
    ans.M = {{0}, {a}, {b}};
    forn(x, 19)
    {
        if (pow10[x + 1] <= a)
            continue;
        ll L = (pow10[x + 1] - a + b - 1) / b - (max(pow10[x], a) - a + b - 1) / b;
        L = min(L, l), l -= L;
        Matrix M(3, 3);
        M.M = {{pow10[x + 1] % mod, 1, 0}, {0, 1, 1}, {0, 0, 1}};
        if (L > 0)
            ans = quickpow(M, L) * ans;
    }
    cout << ans[0][0] << endl;
    return 0;
}

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

using namespace std;

struct Point{ double x, y;};

void solve(int i, Point a, Point b){
    if(i == 0) return;
    Point s, u, t;
    s.x = a.x + (b.x - a.x) / 3;
    s.y = a.y + (b.y - a.y) / 3;
    t.x = a.x + (b.x - a.x) / 3 * 2;
    t.y = a.y + (b.y - a.y) / 3 * 2;
    double rad = 60.0 / 180 * M_PI;
    u.x = (t.x - s.x) * cos(rad) - (t.y - s.y) * sin(rad) + s.x;
    u.y = (t.x - s.x) * sin(rad) + (t.y - s.y) * cos(rad) + s.y;
    solve(i - 1, a, s);
    cout << fixed;
    cout << setprecision(8) << s.x << " " << s.y << endl;
    solve(i - 1, s, u);
    cout << setprecision(8) << u.x << " " << u.y << endl;
    solve(i - 1, u, t);
    cout << setprecision(8) << t.x << " " << t.y << endl;
    solve(i - 1, t, b);
}

int main(void){
    int i; cin >> i;
    Point a, b;
    a.x = 0.0;
    a.y = 0.0;
    b.x = 100.0;
    b.y = 0.0;
    cout << fixed; 
    cout << setprecision(8) << a.x << " " << a.y << endl;
    solve(i, a, b);
    cout << setprecision(8) << b.x << " " << b.y ;
    return 0;
}


Measured memory_bytes: 3300
#include <iostream>

using namespace std;

int main() {
  int a = 0, b = 0, c = 0;
  cin >> a >> b >> c;
  if (a > c) cout << "NO" << endl;
  else if (a + b >= c) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from pprint import pprint as pp
from pprint import pformat as pf


class Data:

    def __init__(self, frm, to, diff, score):
        self.frm = frm - 1
        self.to = to - 1
        self.diff = diff
        self.score = score

    def __repr__(self):
        return "{} {} {} {}".format(
                self.frm,
                self.to,
                self.diff,
                self.score,
                )

    def calc_score(self, l):
        if l[self.to] - l[self.frm] == self.diff:
            return self.score
        else:
            return 0

def flat(l, key, value):
    for i in range(key, len(l)):
        l[i] = value

def shift(l, m, key):
    if key < 0:
        return False
    if l[key] < m:
        flat(l, key, l[key] + 1)
        return True
    else:
        return shift(l, m, key - 1)

def count(n, m):
    l = [1] * n
    key = 0
    flg = True
    while flg:
        yield l
        flg = shift(l, m, len(l) - 1)

def get_scorebook(q):
    book = [None] * q
    for i in range(q):
        a, b, c, d = list(map(int, input().split()))
        book[i] = Data(a, b, c, d)
    return book

def calc_score(l, book):
    score = 0
    for data in book:
        score += data.calc_score(l)
    return score

if __name__ == '__main__':
    n, m, q = map(int, input().split())
    scorebook = get_scorebook(q)
    score = 0
    for l in count(n, m):
        score = max(score, calc_score(l, scorebook))
    print(score)


Measured memory_bytes: 75496
#include<stdio.h>

int main(void) {
  char b;
  scanf("%c", &b);
  switch(b) {
    case 'A': printf("T");break;
    case 'T': printf("A");break;
    case 'C': printf("G");break;
    case 'G': printf("C");break;
  }
  printf("\n");

  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<time.h>
#include<vector>
#define ll long long
using namespace std;

int main()
{
    //ios::sync_with_stdio(false);
    //cin.tie(0);
    //cout.tie(0);
    int n,ans = 0;
    cin>>n;
    int t = n/1000;
    int r = n % 1000;
    if(r>0){
        t+=1;
        ans = t*1000 - n;
    }
    else if(r==0){
        ans = 0;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3616
package main

import (
	"fmt"
	"sort"
)

func IntArrayEquals(a []int, b []int) bool {
	if len(a) != len(b) {
		return false
	}
	for i, v := range a {
		if v != b[i] {
			return false
		}
	}
	return true
}

func main() {
	a := make([]int, 4)

	for i := 0; i < 4; i++ {
		fmt.Scanf("%d", &a[i])
	}

	sort.Ints(a)

	if IntArrayEquals(a, []int{1, 4, 7, 9}) {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

Measured memory_bytes: 512
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int n, t;
        cin >> n >> t;
        if(n == 0)
            return 0;

        string s;
        cin >> s;

        vector<double> dp(n, 0.0);
        dp[0] = 1.0;
        for(int i=0; i<t; ++i){
            vector<double> next(n, 0.0);
            for(int j=0; j<n; ++j){
                for(int k=0; k<6; ++k){
                    next[(j+k)%n] += dp[j] / 6.0;
                }
            }
            dp.swap(next);
        }

        double ret = 0.0;
        for(int i=0; i<n; ++i){
            double p = 0.0;
            for(int j=0; j<n; ++j){
                if(s[j] == 'R')
                    p += dp[(j+i)%n];
            }
            ret = max(ret, p);
        }
        printf("%.10f\n", ret);
    }
}

Measured memory_bytes: 1280
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <string>

using namespace std;

#define LL long long

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

int main() {
	LL n, a, b;
	cin >> n >> a >> b;
	if (a > b) {
		swap(a, b);
	}
	LL res;
	if ((b - a) % (LL)(2) == 0) {
		res = (b - a) / (LL)(2);
	}
	else if (b - a == (LL)(1)) {
		res = min(b - (LL)(1), n - a);
	}
	else {
		LL resa = a + (b - a - (LL)(1)) / (LL)(2);
		LL resb = (n - b + (LL)(1)) + (b - a - (LL)(1)) / 2;
		res = min(resa, resb);
	}
	cout << res << endl;
	return 0;
}

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

public class Main {
    public static void main(String[] args) throws Exception {
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            
            String[] tmp = br.readLine().split(" ");
            int a = Integer.parseInt(tmp[0]);
            int b = Integer.parseInt(tmp[1]);
            int c = Integer.parseInt(tmp[2]);
            int k = Integer.parseInt(tmp[3]);
            
            br.close();
            
            PrintWriter pw = new PrintWriter(System.out);
            
            if (k <= a) {
                System.out.println(k);
            } else if (k <= a + b) {
                System.out.println(a);
            } else {
                System.out.println(a - (k - a - b));
            }
            
            pw.flush();
            
        }
    }
}

Measured memory_bytes: 32620
#include <iostream>
#include <vector>   
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

int main() {
  int p[5];
  int ans = 0;
  rep(i, 5)    cin >> p[i];
  rep(i, 5) if (p[i]== 0) {
    ans = i + 1;
  }
  cout << ans << endl;
  return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;

#define ff first
#define PI acos(-1.0)
#define ss second
#define pb push_back
#define mp make_pair
#define sz size()
#define MOD 1000000007
#define MOD1 998244353
#define ep 0.000000001
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, 1};
int dy4[] = {1, -1, 1, -1};
//#define fio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

int main()
{
    #ifndef ONLINE_JUDGE
    freopen ("in.txt", "r", stdin);
    freopen ("out.txt", "w", stdout);
    #endif
    int n, s, x; ll ans=0;
    cin>>n; s=sqrt(n);
    for(int i=1;i<=s;i++){
        x=n/i; x=x-i; if(n%i!=0)x++; 
        if(x>0)ans+=(x*2),ans--;
    }
    cout<<ans<<endl;
    return 0;
}
//https://thebestoffersintheweb.com/redirect/57a764d042bf8/

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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    string S;
    cin >> S;

    rep (i, S.size()) {
        for (int j = i; j < S.size(); j++) {
            string tmp = S.substr(0, i) + S.substr(j, S.size()-j);
            if (tmp == "keyence") {
                YES;
                return 0;
            }
        }
    }

    NO;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        new Solver().run();
    }
}

class Solver {

    public void run() {
        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();
        }

        Set<Integer> set = new HashSet<>();
        for (int v : A) {
            if (set.contains(v)) {
                set.remove(v);
            } else {
                set.add(v);
            }
        }

        System.out.println(set.size());

        return;
    }

}

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

int main() {
  int N, A, B;
  cin >> N >> A;
  B = N - N/500 * 500;
  if ( A>= B ) {
    cout << "Yes" << endl;
  }
  else{
  cout << "No" << endl;
  }  
}

Measured memory_bytes: 256
N = int(input())
p_list = list(map(int, input().split(" ")))

p_list_true = sorted(p_list)

flag = True
diff_indexs = []
for i in range(N):
    if p_list[i] != p_list_true[i]:
        diff_indexs.append(i)
if len(diff_indexs) == 0:
    print("YES")
elif len(diff_indexs) == 2:
    i, j = diff_indexs
    if p_list[i] == p_list_true[j] and p_list[j] == p_list_true[i]:
        print("YES")
    else:
        print("NO")
else:
    print("NO")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define int long long
#define L 999999
using namespace std;
int n,k,a[L];
bool f(int x) {
	int ret=0;
	for(int i=1; i<=n; i++) {
		ret+=((a[i]/x)-1+(a[i]%x>0));
	}
	return ret<=k;
}
signed main() {
	cin>>n>>k;
	int l=1,r=0;
	for(int i=1; i<=n; i++){
		cin>>a[i];
		r=max(r,a[i]);
	}
	r++;
	int mid;
	while(l+1<r) {
		mid=(l+r)/2;
		if(f(mid))r=mid;
		else l=mid;
	}
	if(f(l))cout<<l<<endl;else cout<<r<<endl;
	return 0;
}

Measured memory_bytes: 5092
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

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

int main() {

  string S, T;

  cin >> S;
  cin >> T;

  int l = S.size();

  string a;
  bool ans = false;
  for (int i = 0; i < l; i++){
    a = S[l - 1];
    S.pop_back();
    S = a + S;
    //cout << S << endl;
    if (S == T) {
      ans = true;
      break;
    }
  }

  if (ans){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


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

for i in range(K):
  R = [ {} for j in range(N)]

  for j in range(N):
    s = A[j]
    # j - s ~ j + s
    if min(j+s, N-1) in R[max(0, j-s)]:
      R[max(0, j-s)][min(j+s, N-1)] += 1
    else:
      R[max(0, j-s)][min(j+s, N-1)] = 1
        
  # Make Next List
  #print(R)
  L = [0 for j in range(N)]
  t = 0
  for j in range(N):
    r = R[j]
    for k, v in r.items():
      t += v
      L[k] += v
    A[j] = t
    t -= L[j]
    
  if A[0] == N and A[-1] == N:
    for j in range(N):
      if A[j] < N:
        break
    else:
      break
print(*A)

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

int main(){
int H, W, i, j, k, u, v, ans=0; cin >> H >> W; string S[H]; 
for(i=0; i<H; i++){ cin >> S[i]; }

for(i=0; i<H; i++){ for(j=0; j<W; j++){ if(S[i][j]=='.'){
vector< vector<int> > A={{i, j}}; int C[H][W]={}; bool D[H][W]={};
D[i][j]=true;
for(k=0; k<A.size(); k++){
int a=A[k][0], b=A[k][1], c=C[a][b];  
if(a>0&&S[a-1][b]=='.'&&!D[a-1][b]){ D[a-1][b]=true; C[a-1][b]=c+1; A.push_back({a-1, b}); }
if(b>0&&S[a][b-1]=='.'&&!D[a][b-1]){ D[a][b-1]=true; C[a][b-1]=c+1; A.push_back({a, b-1}); }
if(a+1<H&&S[a+1][b]=='.'&&!D[a+1][b]){ D[a+1][b]=true; C[a+1][b]=c+1; A.push_back({a+1, b}); }
if(b+1<W&&S[a][b+1]=='.'&&!D[a][b+1]){ D[a][b+1]=true; C[a][b+1]=c+1; A.push_back({a, b+1}); }
}
for(u=0; u<H; u++){ for(v=0; v<W; v++){ ans=max(ans, C[u][v]); } }
} } }
cout << ans << "\n";
}

Measured memory_bytes: 256
N = int(input())
C = [0 for i in range(N)]

for i in range(N):
    C[i] = int(input())

sosu = 10 ** 9 + 7

dp = [1 for i in range(N)]
alpha = {}
alpha[C[0]] = [0]
mae = C[0]
for i in range(1,N):
    dp[i] = dp[i-1]
    if C[i] != mae:
        if C[i] in alpha.keys():
            length = len(alpha[C[i]])
            lastnum = alpha[C[i]][length - 1]
            dp[i] += dp[lastnum]
            alpha[C[i]].append(i)
        else:
            alpha[C[i]] = [i]
    mae = C[i]
    dp[i] = dp[i] % sosu
print(dp[N-1])


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

public class HelloWorld
{
    static bool res = false;
    static long[] avail;
    static long[] memo;
    static public void Main()
    {

        var N = long.Parse(Console.ReadLine());
        //var NM = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
        var S = Console.ReadLine();
        long ans = 0;
        for (int i = 0; i < 10; i++)
        {
            for (int j = 0; j < 10; j++)
            {
                for (int k = 0; k < 10; k++)
                {
                    var pass = new long[3];
                    pass[0] = i;
                    pass[1] = j;
                    pass[2] = k;
                    var count = 0;
                    for (int l = 0; l < S.Length; l++)
                    {
                        if(pass[count] == S[l] - '0')
                        {
                            count++;
                        }
                        if(count == 3)
                        {
                            ans++;
                            break;
                        }
                    }
                }
            }
        }

        Console.WriteLine(ans);
    }

    public static long Pow(long a, int n)
    {
        switch (n)
        {
            case 0:
                return 1;
            case 1:
                return a;
            default:
                var p = Pow(a, n / 2);
                return p * p * Pow(a, n % 2);
        }
    }

    public static long PrimeFactorization(long n)
    {
        var res = 1L;

        for (long i = 2; i * i <= n; i++)
        {
            if (n % i != 0) continue;
            long exponents = 0;

            // 割り続ける
            while (n % i == 0)
            {
                exponents++;
                n /= i;
            }

            res *= exponents+1;
        }

        // 素数が残っている場合
        if (n != 1) res *= 2;
        return res;
    }
}



Measured memory_bytes: 27680
#include<iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <bitset>
#include <stack>
#include <queue>
#include <fstream>

using namespace std;
using ll=long long;

#define PRI(n) cout << n <<endl;
#define PRI2(n, m) cout << n << " " << m << endl;
#define PRI3(n, m, o) cout << n << " " << m<< " " << o << endl;

#define REP(i, n)  for(int i = 0; i < (int)n; ++i)
#define REPInv(i, n)  for(int i = n-1; i >= 0; --i)

#define FOR(i, t, n)  for(int i = t; i <= (int)n; ++i)
#define FORInv(i, t, n)  for(int i = t; i >= (int)n; --i)

const char alphabet[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
                           's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
const ll MOD = 1e9 + 7;

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

ll LCM(ll a, ll b) {
    ll gcd = GCD(a, b);
    return a / gcd * b;
}

ll nCr(int n, int r) {
    vector<ll> C(r + 1);
    C[0] = 1;
    FOR(i, 1, n) FORInv (j, min(i, r), 1)C[j] = (C[j] + C[j - 1]) % MOD;
    return C[r];
}

int N;
int A[110];

int main() {
    cin >> N;
    REP(i,N)cin >>A[i];
    ll ans = 1e18;
    FOR(i,-100,100){
        ll sum = 0;
        REP(j,N){
           sum += (i - A[j])*(i - A[j]);
        }
        if(ans>sum)ans = sum;
    }
    PRI(ans)
    return 0;
}

Measured memory_bytes: 256
//By Bibi
///                 .-~~~~~~~~~-._       _.-~~~~~~~~~-.
///             __.'              ~.   .~              `.__
///           .'//                  \./                  \\`.
///        .'//                     |                     \\`.
///       .'// .-~"""""""~~~~-._     |     _,-~~~~"""""""~-. \\`.
///     .'//.-"                 `-.  |  .-'                 "-.\\`.
///   .'//______.============-..   \ | /   ..-============.______\\`.
/// .'______________________________\|/______________________________`.
#include<bits/stdc++.h> 
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define dep(i,a,b) for(int i=a;i>=b;--i)
#define ll long long
using namespace std;
ll read()
{
	ll sum=0,flag=1;
	char c;
	for(;c<'0'||c>'9';c=getchar())if(c=='-') flag=-1;
	for(;c>='0'&&c<='9';c=getchar())sum=(sum<<1)+(sum<<3)+c-'0';
	return sum*flag;
}
ll n,m;
ll ans;
void work()
{
	if(n==1&&m==1) {ans=1;return;}
	if(n==1) {ans=m-2;return;}
	if(m==1) {ans=n-2;return;}
	if(n==2||m==2) {ans=0;return;}
	ans=n*m-m-m-n-n+4;
}
int main()
{
	n=read();m=read();
	work();
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); --i)
#define all(c) c.begin(),c.end()
#define sz(x) ((int)x.size())
using pii = pair<int, int>;
using vvi = vector<vector<int>>;
using vi  = vector<int>;
constexpr int INF = 1001001001001001001LL;

struct RSQ {
    const int ident = 0;
    vi data;
    int size;
    RSQ(int n) {
        size = 1;
        while (size < n) size *= 2;
        data.assign(size * 2, ident);
    }
    void update(int idx, int value) {
        idx += size - 1;
        data[idx] = value;
        while (idx) {
            idx = (idx - 1) / 2;
            data[idx] = data[idx * 2 + 1] + data[idx * 2 + 2];
        }
    }
    // [ql, qr)
    int query(int ql, int qr) {
        return query(ql, qr, 0, 0, size);
    }
    int query(int ql, int qr, int node, int nl, int nr) {
        if (qr <= nl || nr <= ql) return ident;
        if (ql <= nl && nr <= qr) return data[node];
        int nm = (nl + nr) / 2;
        return query(ql, qr, node * 2 + 1, nl, nm) +
               query(ql, qr, node * 2 + 2, nm, nr);
    }
};

signed main() {
    int N, Q;
    cin >> N >> Q;
    RSQ seg(N);
    rep(i, 0, Q) {
        int com;
        cin >> com;
        if (com == 0) {
            // add
            int X, Y;
            cin >> X >> Y;
            X--;
            int old = seg.data[X + seg.size - 1];
            seg.update(X, old + Y);
        } else {
            // getSum
            int X, Y;
            cin >> X >> Y;
            X--, Y--;
            cout << seg.query(X, Y + 1) << endl;
        }
    }
}



Measured memory_bytes: 4940
#include<stdio.h>
#include<stdlib.h>
 
int main(){
  int i = 0; // スタックの一番上の位置を表す整数。一番下は0
  int S[100]; // スタック
  char str[10]; // 入力用文字列配列
 
  // EOFまで読み込む
  while(scanf("%s", str) != EOF){

    // 加算
    if (str[0] == '+'){
      // スタックの上から二番目と一番上の値の和を出し、上から二番目の値があった位置に値を入れる
      S[i-2] = S[i-2] + S[i-1];
      i--;
    }
    // 減算
    else if(str[0] == '-'){
      S[i-2] = S[i-2] - S[i-1];
      i--;
    }
    // 乗算
    else if(str[0] == '*'){
      S[i-2] = S[i-2] * S[i-1];
      i--;
    }
    // オペランドをスタックに値を積む
    else{
      S[i] = atoi(str);
      i++;
    }
  }
  // スタックの一番下(計算結果)を出力する
  printf("%d\n", S[0]);

  return 0;
}

Measured memory_bytes: 548
#include<cstring>
#include<string>
#include<vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<complex>
#include<sstream>
#include<climits>
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define pb push_back
#define mk make_pair
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_N = 200000;
int N;
int a[MAX_N], b[MAX_N];
vector<int> modb[30];

int main() {
  cin >> N;
  rep(i,N) cin >> a[i];
  rep(i,N) cin >> b[i];

  for (int k = 1; k < 30; ++k) {
    for (int i = 0; i < N; ++i) {
      modb[k].pb(b[i]%(1<<k));
    }
    sort(all(modb[k]));
  }

  int ans = 0;
  for (int k = 0; k < 29; ++k) {
    int t = 1 << k;
    for (int i = 0; i < N; ++i) {
      int moda = a[i]%(1<<(k+1)), n = 0;
      n += lower_bound(all(modb[k+1]), 2*t-moda) - lower_bound(all(modb[k+1]), t-moda);
      n += lower_bound(all(modb[k+1]), 4*t-moda) - lower_bound(all(modb[k+1]), 3*t-moda);
      ans ^= (n%2) << k;
    }
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 29180
#include<stdio.h>

int main (void){
	
	int n;//??????????????°
	scanf("%d",&n);
	
	int score[n];
	for (int i=0;i<n;i++){
		score[i]=0;
	}
	
	int m;//??????????????°
	scanf("%d",&m);
	int a[m];//???????????????
	for(int i=0;i<m;i++){
		scanf("%d",&a[i]);
	}
	
	int b[m][n];
	for(int i=0;i<m;i++){
		for (int j=0;j<n;j++){
			scanf("%d",&b[i][j]);
		}
	}
	
	int x;
	
	for(int i=0;i<m;i++){
		x=0;
		for(int j=0;j<n;j++){
			if(b[i][j]==a[i]){
				score[j]++;
			}else{
				x++;
			}
		}
		score[a[i]-1]+=x;
	}
	
	for(int i=0;i<n;i++){
		printf("%d\n",score[i]);
	}
	return 0;
}

Measured memory_bytes: 1064
N,D,A=map(int,input().split())
XH=[]
for _ in range(N):
  x,h=map(int,input().split())
  XH.append([x,h])
XH=sorted(XH, key=lambda x:x[0])
X=[XH[i][0] for i in range(N)]
H=[XH[i][1] for i in range(N)]
from math import ceil
from bisect import bisect_right
imos=[0]*(N+1)
hit=0
ans=0
for i in range(N):
  hit+=imos[i]
  restH=H[i]-hit*A
  if restH>0:
    ans+=ceil(restH/A)
    hit+=ceil(restH/A)
    ind=bisect_right(X,X[i]+2*D)
    imos[ind]-=ceil(restH/A)
print(ans)

Measured memory_bytes: 47296
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  auto n = readln.chomp.to!int;
  auto ds = readln.chomp.split.to!(int[]);
  auto m = readln.chomp.to!int;
  auto ts = readln.chomp.split.to!(int[]);

  int[int] cnt;
  foreach (d; ds) {
    cnt[d]++;
  }

  bool f = false;
  foreach (t; ts) {
    if (cnt.get(t, 0)) {
      cnt[t]--;
    } else {
      f = true;
      break;
    }
  }
  if (f) writeln("NO");
  else writeln("YES");
}


Measured memory_bytes: 28004
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------


int T;
ll N,M,A,B;

ll floor_sum(ll N,ll M,ll A,ll B) {
	// sum(i=0...N-1) floor((A*i+B)/M)
	
	ll ret=0;
	if(B>=M) ret+=N*(B/M), B%=M;
	if(A>=M) ret+=N*(N-1)/2*(A/M), A%=M;
	
	ll Y=(A*N+B)/M;
	if(Y==0) return ret;
	ll X=Y*M-B;
	// 90度回転、Y=Nのラインは無視する
	ret+=(N-(X+A-1)/A)*Y;
	ret+=floor_sum(Y,A,M,(A-X%A)%A);
	return ret;
	
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>T;
	FOR(i,T) {
		cin>>N>>M>>A>>B;
		cout<<floor_sum(N,M,A,B)<<endl;
	}
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using Int = unsigned long long;
typedef pair<int,int> P;
typedef priority_queue<int> Pr;
int const MOD = 1000000007;
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; }

struct UnionFind {
  vector< int > data;
 
  UnionFind(int sz) {
    data.assign(sz, -1);
  }
 
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
 
  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }
 
  int size(int k) {
    return (-data[find(k)]);
  }
};

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

    int n,q; cin>>n>>q;
    UnionFind u(n+1);
    for (int i = 0; i < q; i++){
        int p,a,b; cin>>p>>a>>b;
        if(p)cout<<(u.find(a)==u.find(b))<<'\n';
        else u.unite(a,b);
    }
}


Measured memory_bytes: 3244
x=int(input())
y=list(map(int, input().split()))
y.sort()
chk=y[len(y)-1]
ans=0
dis=10**10
for i in range(x):
	if abs(y[i]-(chk/2))<dis:
		ans=y[i]
		dis=abs(y[i]-(chk/2))
print(chk,ans)

Measured memory_bytes: 14428
A, B, C, X, Y = map(int,input().split())

if X>Y:
  print(min(A*X+B*Y, A*(X-Y)+C*Y*2, C*X*2))
if Y>=X:
  print(min(A*X+B*Y, B*(Y-X)+C*X*2, C*Y*2))

Measured memory_bytes: 3060
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n,m=map(int,input().split())
    E=[[] for _ in range(n)]
    for _ in range(m):
        x,y,z=map(int,input().split())
        x-=1; y-=1
        E[x].append(y)
        E[y].append(x)

    cnt=0
    col=[None]*n
    def dfs(v)->bool:
        if(col[v] is not None): return False
        Q=[v]
        col[v]=cnt
        while(Q):
            v=Q.pop()
            for nv in E[v]:
                if(col[nv] is not None): continue
                col[nv]=cnt
                Q.append(nv)
        return True

    for v in range(n):
        cnt+=dfs(v)

    print(cnt)
resolve()

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

#define mp make_pair
using ll  = long long;
using pii = pair<ll,ll>;
using vl  = vector<ll>;
using vvl = vector<vl>;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define per(i,n) for(int i = (n)-1; i >= 0; --i)
#define rng(i,a,b) for(int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()


int main() {
    int N, M;
    cin >> N >> M;
    vvl edges(N);
    vl ans(N,-1);
    rep(i,M) {
        int A, B;
        scanf("%d %d", &A, &B); A--; B--;
        edges[A].push_back(B);
        edges[B].push_back(A);
    }
    priority_queue<pair<int, pii>> que;
    for (auto to : edges[0]) {
        que.push(mp(-0, pii(0, to)));
    }
    while (!que.empty()) {
        int d = -que.top().first;
        int pre = que.top().second.first;
        int now = que.top().second.second;
        que.pop();
        if (ans[now] != -1) continue;
        // cerr << now+1 << endl;
        ans[now] = pre;
        for (auto to : edges[now]) {
            if (to == pre) continue;
            que.push(mp(-d-1, pii(now, to)));
        }
    }
    cout << "Yes" << endl;
    rep(i,N-1) {
        cout << ans[i+1]+1 << endl;
    }
    return 0;
}


Measured memory_bytes: 21132
from itertools import permutations

n = int(input())
p = tuple(map(int, input().split(" ")))
q = tuple(map(int, input().split(" ")))

array = [int(i) for i in range(1, n+1)]
c = 1
n_p = 0
n_q = 0

for perm in permutations(array):
    if perm == p:
        n_p = c
        
    if perm == q:
        n_q = c
        
    c += 1
    
print(abs(n_p - n_q))

Measured memory_bytes: 3188
#include <cstdio>
#include <vector>

using namespace std;

const int MAXN = 1e3 + 5;

int n, m;
vector <int> graph[MAXN];

void read_input()
{
    scanf("%d %d", &n, &m);

    int v, w;
    for(int i = 0; i < m; i++)
    {
        scanf("%d %d", &v, &w);
        graph[v].push_back(w);
    }
}

int parent[MAXN];
int mark[MAXN];
vector <int> cycle;
bool ve[MAXN];

bool check()
{
    int z = cycle.size();
    for(int i = 0; i < z; i++)
    {
        ve[cycle[i]] = true;
    }
    for(int i = 0; i < z; i++)
    {
        int cnt = 0;
        for(auto x : graph[cycle[i]])
        {
            if(ve[x])
            {
                cnt++;
                if(cnt == 2)
                {
                    for(int i = 0; i < z; i++)
                    {
                        ve[cycle[i]] = false;
                    }
                    return false;
                }
            }
        }
    }
    for(int i = 0; i < z; i++)
    {
        ve[cycle[i]] = false;
    }
}

bool dfs(int v, int p)
{
    //printf("%d %d\n", v, p);
    if(mark[v] == 1)
    {
        int temp = p;
        cycle.clear();
        cycle.push_back(temp);
        //printf("%d\n", temp);
        while(temp != v)
        {
            //printf("~%d\n", temp);
            //printf("DAS");
            //printf("%d\n", temp);
            temp = parent[temp];
            cycle.push_back(temp);
            //printf("%d\n", temp);
        }
        if(check())
        {
            return true;
        }
        return false;
    }
    parent[v] = p;
    mark[v] = 1;

    for(auto x : graph[v])
    {
        if(mark[x] == 2) continue;
        if(dfs(x, v))
        {
            return true;
        }
    }

    mark[v] = 2;
    return false;
}

void solve()
{
    for(int i = 1; i <= n; i++)
    {
        if(mark[i] == 0)
        {
            if(dfs(i, i))
            {
                int z = cycle.size();

                printf("%d\n", z);
                for(int j = 0; j < z; j++)
                {
                    printf("%d\n", cycle[j]);
                }
                return;
            }
        }
    }
    printf("-1\n");
}

int main()
{
    read_input();
    solve();

    return 0;
}


Measured memory_bytes: 384