akhauriyash/Code-Regression huggingface dataset:
///   BISMILLAHIR RAHMANIR RAHEEM
///   ALLAH IS WATCHING ME
///   ALLAH save us from COVID-19.Amin.

///   █▀█─█──█──█▀█─█─█
///   █▄█─█──█──█▄█─█▄█
///   █─█─█▄─█▄─█─█─█─█

///   كُلُّ نَفْسٍ ذَآئِقَةُ الْمَوْت
///   Every soul shall taste death.



#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

///  order_of_key return number of elements less than x.
///  find_by_order return index.

using namespace std;
using namespace __gnu_pbds;


#define MOHAMMAD  ios::sync_with_stdio(0);cin.tie(0);
#define all(x)    (x).begin(), (x).end()
#define AE        cout << fixed << setprecision(10);

int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1}; // 8-direction.......
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[]= {1,-1,0,0}; // 4-direction...........
int dy4[]= {0,0,1,-1};

typedef tree< int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;

//***********************************************  The END **********************************************************************************************************************************




int main()
{

    // MOHAMMAD
  int n , k , sum = 0;
  cin >> n >> k;
  int arr[n];
  for( int i = 0 ; i<n ; ++i ) cin >> arr[i];
  sort(arr,arr+n);

  for ( int i = 0 ; i<k ; ++i ){
                sum+=arr[i];
  }
  cout << sum << "\n";
}

/*





  Alhamdulillah
*/



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

int main() {
  int N, K, x[100];
  cin >> N >> K;
  for (int i = 0; i < N; i++) cin >> x[i];
  int ans = 0;
  for (int i = 0; i < N; i++) ans += min((x[i] - 0) * 2, (K - x[i]) * 2);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
const int MaxN = 50;
typedef long long LL;
using namespace std;
LL K ;
int main()
{
	while(~scanf("%lld" , &K)){
		if(K < 50){
			LL last = 49 + K * 50;
			printf("50\n");
			for(int i = 1;i <= 50;i++){
				if(i != 50) printf("0 ");
				else printf("%lld\n" , last);
			}
		}
		else {
			LL n = K % 50;
			LL t = K / 50;
			LL pre = 49 + t;
			printf("50\n");
			for(int i = 1;i <= 50;i++){
				if(i <= n) printf("%lld " , pre + 50 - n);
				else printf("%lld\n" , pre - n);
			}
		}
	}
}

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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

	int N; cin >> N;

	int A;
	int ans = INT_MAX;

	for (int i = 0;i < N;i++){
		cin >> A;
		int cnt = 0;
		while(A%2 == 0){
			cnt++; A /= 2;
		}
		ans = min(cnt,ans);
	}

	cout << ans << endl;

	return 0;

}


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

#define hell                         1000000007
#define lcm(a,b)                     (a*b)/__gcd(a,b)
#define ll                           long long
#define vll                          vector<ll>
#define vi                           vector<int>
#define pll                          vector< pair<ll,ll> >
#define pb                           push_back
#define mp                           make_pair
#define all(v)                       v.begin(),v.end()
#define lbnd                         lower_bound
#define ubnd                         upper_bound
#define bs                           binary_search
#define F                            first
#define S                            second
#define rep(i,a,b)                   for(ll i=a;i<b;i++)
#define parr(a,n)                    for(ll it=0;it<n;it++) cout<<a[it]<<" ";cout<<endl;
#define pcont(a)                     for(auto it:a) cout<<it<<" ";cout<<endl;
#define ret(x)                       return cout<<x,0;
#define endl                           '\n'

#define MAX 100005
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);

    ll n;
    cin >> n;
    string s;
    cin>>s;
    ll p[n];
    ll c=0;
    rep(i,0,n) if(s[i]=='.') c++;
    if(s[0]=='#') p[0]=1;
    else p[0]=0;
    rep(i,1,n) {
        p[i]=p[i-1];
        if(s[i]=='#') p[i]++;
    }
    ll sf[n+1];
    sf[n]=0;
    if(s[n-1]=='.') sf[n-1]=1;
    else sf[n-1]=0;
    for(ll i=n-2;i>=0;i--) {
        sf[i]=sf[i+1];
        if(s[i]=='.') sf[i]++;
    }

    //rep(i,0,n) cout << p[i] << " ";cout << endl;
    //rep(i,0,n) cout << sf[i] << " ";cout << endl;

    ll ans=hell;
    ans=min(ans,c);
    rep(i,0,n) {
        ll whiteright=sf[i+1];
        ll blackleft=p[i];
        ans=min(ans,blackleft+whiteright);
    }
    ret(ans);
}  

Measured memory_bytes: 3732
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

vector<int> solve(const vec<int, 2>& G) {
  int N = G.size();
  vector<int> indeg(N, 0);
  for (int v = 0; v < N; v++) {
    for (int u : G[v]) ++indeg[u];
  }
  queue<int> que;
  for (int i = 0; i < N; i++)
    if (indeg[i] == 0) que.push(i);
  vector<int> dp(N, 0);
  while (!que.empty()) {
    int v = que.front();
    que.pop();
    for (int u : G[v]) {
      dp[u] = max(dp[u], dp[v] + 1);
      --indeg[u];
      if (indeg[u] == 0) {
        que.push(u);
      }
    }
  }
  return dp;
}

int main() {
  int N, M;
  while (cin >> N >> M) {
    vec<int, 2> G(N), rG(N);
    for (int i = 0; i < N - 1 + M; i++) {
      int a, b;
      cin >> a >> b;
      --a;
      --b;
      G[a].push_back(b);
      rG[b].push_back(a);
    }
    vector<int> depth = solve(G);
    for (int v = 0; v < N; v++) {
      if (depth[v] == 0) {
        cout << 0 << endl;
        continue;
      }
      int p;
      for (int u : rG[v]) {
        if (depth[u] + 1 == depth[v]) {
          p = u;
        }
      }
      cout << p + 1 << endl;
    }
  }
  return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll N;
vector<P> ps;

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

  cin>>N;
  ll rmin=INF,lmax=-INF;
  ll res=0;
  rep(i,N){
    ll a,b;
    cin>>a>>b;
    minch(rmin,b);
    maxch(lmax,a);
    ps.push_back(P(a,b));
  }
  sort(all(ps));
  rep(i,N){
    maxch(res,max(0LL,rmin-lmax+1)+ps[i].se-ps[i].fi+1);
  }

  ll Y=INF;
  for(ll i=N-1;i>=0;i--){
    ll X=ps[i].fi;
    if(i<N-1)maxch(res,max(0LL,rmin-X+1)+max(0LL,Y-lmax+1));
    minch(Y,ps[i].se);
  }

  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 3444
/*

宣告——
汝身听吾号令，托付吾之命运于汝之剑，
应圣杯之召，若汝遵从此意志此理，回应吧。
在此起誓，吾愿成就世间一切之善行，吾愿诛尽世间一切之恶行。
汝为身缠三大言灵之七天，从抑止之轮显现吧，天秤之守护者！

*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cassert>
#include<cmath>
#include<vector>
#include<queue>
#define ll long long
using namespace std;
inline int read(){
	int re=0,flag=1;char ch=getchar();
	while(!isdigit(ch)){
		if(ch=='-') flag=-1;
		ch=getchar();
	}
	while(isdigit(ch)) re=(re<<1)+(re<<3)+ch-'0',ch=getchar();
	return re*flag;
}
ll n,a[110],lim;
int main(){
	n=read();lim=read();int i;ll sum=0;
	for(i=1;i<=n;i++) a[i]=read();
	sort(a+1,a+n+1);
	for(i=1;i<=n;i++){
		sum+=a[i];
		if(lim<sum){
			cout<<i-1<<'\n';
			return 0;
		}
	}
	if(lim==sum) cout<<n<<'\n';
	else cout<<n-1<<'\n';
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayDeque;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		String str;
		double t;
		ArrayDeque<Double> ad = new ArrayDeque<Double>();
		while ((str = bf.readLine()) != null) {
			String p[] = str.split(" ");
			ad.clear();
			for (int i = 0; i < p.length; i++) {
				if (p[i].length() == 1) {
					switch (p[i].charAt(0)) {
					case '+':
						t = ad.pollLast();
						ad.addLast(ad.pollLast() + t);
						break;
					case '-':
						t = ad.pollLast();
						ad.addLast(ad.pollLast() - t);
						break;
					case '*':
						t = ad.pollLast();
						ad.addLast(ad.pollLast() * t);
						break;
					case '/':
						t = ad.pollLast();
						ad.addLast(ad.pollLast() / t);
						break;
					default:
						ad.addLast(Double.valueOf(p[i]));
					}
				} else {
					ad.addLast(Double.valueOf(p[i]));
				}
			}
			System.out.println(ad.pollLast());
		}
	}
}

Measured memory_bytes: 9768
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<functional>
#include<string.h>
#include<vector>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<list>
#include<queue>
#include<deque>
#include<string>
#include<stack>
#include<limits.h>
#define int long long
#define P pair<int,int>
using namespace  std;

P a[50];
signed main() {
	int n, k; cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> a[i].first >> a[i].second;
	}
	sort(a, a + n);
	int ans = LLONG_MAX;
	for (int i = 0; i < n; i++) {
		for (int j = i; j < n; j++) {
			vector<int>V;
			for (int k = i; k <= j; k++) {
				V.push_back(a[k].second);
			}
			sort(V.begin(), V.end());
			if (V.size() < k)continue;
			for (int t = 0; t <= V.size() - k; t++) {
				ans = min(ans, (a[j].first - a[i].first)*(V[t + k - 1] - V[t]));
			}
		}
	}
	cout << ans << endl;
}

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

int main(){
    int N, i, j, s;
    string S;
    cin>>N;
    set<string> st;
    s=N;
    for(i=0; i < N; i++){
        cin>>S;
        st.insert(S);
    }

    // if(s>0)
    cout<<st.size()<<endl;
    return 0;
}

Measured memory_bytes: 19252
#define LOCAL
#include "bits/stdc++.h"
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define LLINF ((long long) 1e18)//1234567890987654321
#define INF 1234567890ll
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second	
#define db 0
#define EPS (1e-7)    //0.0000001 the value
#define PI (acos((ld)-1.0))
#define MAXN (1002)
#define ll long long int 
#define ld long double
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
#define FOR(ii, ss, ee) for(ll ii = ss; ii < (ll)ee; ++ii)
#define space " "
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ((ll)x.size())
#define ph push
#define btinpct(x) __builtin_popcountll((x))
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
typedef pair <ll, ll> pi;
typedef pair <ll, pi> spi;
typedef pair <pi, pi> dpi;
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss
string to_string(char c) {string s(1,c);return s;}string to_string(bool b){return (b ? "true" : "false");}template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}template <typename A>string to_string(A v) {bool first = true;string res = "{";for (const auto &x : v) {if (!first) {res += ", ";}first = false;res += to_string(x);}res += "}";return res;}void degug_out() { cerr << endl; }template <typename Head, typename... Tail>void degug_out(Head H, Tail... T) {cerr << " " << to_string(H);degug_out(T...);}inline ll gcd(ll a,ll b){if(a>b)swap(a,b);if(a==0)return b;return gcd(b%a,a);}
#ifdef LOCAL
#define degug(...) cerr << "[" << #__VA_ARGS__ << "]:", degug_out(__VA_ARGS__)
#else
#define degug(...) 42
#define cerr if(0)cout
#endif
ll n,A[MAXN],dp[MAXN][5002],pdp[MAXN][5002];
vector<int>v[MAXN];
void no(){ cout<<"IMPOSSIBLE"<<'\n'; exit(0); }
void dfs(ll x,ll p){
	fill(dp[x],dp[x]+5002,LLINF);
	bool f=0;ll sum=0;
	for(auto i:v[x])if(i!=p){
		dfs(i,x);
		ll a=A[i],b=dp[i][A[i]];sum+=a+b;
		if(min(a,b)>A[x])no();
		if(f==0){
			if(a<=A[x])dp[x][a]=b;if(b<=A[x])dp[x][b]=a;
		}else{
			for(ll i=A[x];i>=0;--i){
				if(i-a>=0)dp[x][i]=min(dp[x][i],pdp[x][i-a]+b);
				if(i-b>=0)dp[x][i]=min(dp[x][i],pdp[x][i-b]+a);
			}
		}f=1;
		FOR(i,0,A[x]+1){
			pdp[x][i]=dp[x][i];
		}
		fill(dp[x],dp[x]+5002,LLINF);
	}
	FOR(i,0,A[x]+1){
		dp[x][i]=pdp[x][i];
	}
	FOR(i,1,A[x]+1){
		dp[x][i]=min(dp[x][i],dp[x][i-1]);
	}
	if(dp[x][A[x]]>=LLINF)no();
}
int main()
{
	FAST
	cin>>n;
	FOR(i,2,n+1){
		ll a;cin>>a;v[i].pb(a);v[a].pb(i);
	}
	FOR(i,1,n+1)cin>>A[i];
	dfs(1,1);
	cout<<"POSSIBLE\n";
}


Measured memory_bytes: 77056
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using f80 = __float80;
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
static const int dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define repi(i,start,end) for(i64 i=(start);i<(end);++i)
#define _rep(i,n) repi(i,0,n)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,start,end) for(i64 i=(start);i>end;--i)
#define pb push_back
#define rng(a) a.begin(),a.end()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define sz(x) (i64)(x).size()
#define bit(n) (1LL<<(n))
#define fi first
#define se second
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef v(i64) vi;
typedef v(vi) vvi;
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;}

void Main()
{
  i64 N;
  cin >> N;
  char c;
  vi a(N);
  rep(i,N){
    cin >> c;
    a[i] = c-'0';
  }
  vi b(N-1);
  bool flag_one = false;
  rep(i,N-1){
    b[i] = abs(a[i]-a[i+1]);
    if(b[i] == 1) flag_one = true;
  }

  if(flag_one){
    rep(i,N-1) if(b[i]==2) b[i]=0;
  }else{
    rep(i,N-1) if(b[i]==2) b[i]=1;
  }

  i64 con = 0;
  rep(i,N-2){
    if(con>0) b[i] = 0;
    i64 x = N-2-i;
    while(x%2==0){
      con++;
      x /= 2;
    }
    x = i+1;
    while(x%2==0){
      con--;
      x /= 2;
    }
  }
  i64 ans = accumulate(rng(b),0);
  ans %= 2;
  if(!flag_one) ans *= 2;
  cout << ans << endl;


}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}



Measured memory_bytes: 15872
import sys


def _s(): return sys.stdin.readline().strip()


def _ia(): return map(int, sys.stdin.readline().strip().split())


n, p = _ia()
u = [1 if i == 0 else 0 for i in range(p)]
s = _s()
cnt = 0
if p == 2 or p == 5:
    for i, c in enumerate(s):
        if int(c) % p == 0:
            cnt += i + 1
else:
    b = 1
    m10 = 10 % p
    prev = 0
    for c in s[::-1]:
        ui = prev = (prev + int(c) * b) % p
        b = (b*m10) % p
        cnt += u[ui]
        u[ui] += 1
print(cnt)


Measured memory_bytes: 42188
#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<math.h>

#define REPS(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

const int mod = 1e9 + 7;
const long double pi = 3.141592653589793238462643383279502884197;
const long double eps = 1e-7;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main() {
	int N;
	cin >> N;
	ll ans = 0;
	REP(i, N) {
		int num = 0;
		cin >> num;
		ans += (num - 1);
	}
	cout << ans;

	system("pause");
	return 0;
}

Measured memory_bytes: 504
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9+7;

int main(){
	
	int n,m; cin>>n>>m;
	priority_queue<pair<ll,ll>> q;
	for(int i=0; i<n; i++){
		ll a,b;cin>>a>>b;
		q.push({-a,b});
	}
	ll sum{},now{};
	while(1){
		auto p = q.top();
		q.pop();
		if(p.second>=m-now){
			sum += -p.first*(m-now);
			break;
		}
		else{
			now += p.second;
			sum += -p.first*p.second;
		}
	}
	
	cout << sum<<endl;
	
}

Measured memory_bytes: 2420
print([1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, 514229, 832040, 1346269, 2178309, 3524578, 5702887, 9227465, 14930352, 24157817, 39088169, 63245986, 102334155, 165580141, 267914296, 433494437, 701408733, 1134903170][int(input())])

Measured memory_bytes: 7660
import string

a, b = map(int, input().split())
s = list(input())
flag = True
hyphen_count = s.count("-")

if "-" in s and hyphen_count == 1:
  hyphen_position = s.index("-")
  
  for i in range(len(s)):
    if not s[i] in string.digits and i != hyphen_position:
      flag = False
    elif a != len(s[0:hyphen_position]):
      flag = False
    elif b != len(s[hyphen_position + 1:len(s)]):
      flag = False
    
else:
  flag = False

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

Measured memory_bytes: 9868
#include<bits/stdc++.h>
using namespace std ;
#define ll long long int 
#define pb push_back 
#define mp make_pair 
int main(){
	ios_base::sync_with_stdio(false) ;
	cin.tie(NULL) ;
	string s ;
	cin >> s ;
	int a = s[0] - '0' ;
	int b = s[1] - '0' ;
	int c = s[2] - '0' ;
	int d = s[3] - '0' ;
	int x = 10*a + b ;
	int y = 10*c + d ;
	if(x >= 1 && x <= 12){
		if(y >= 1 && y <= 12){
			cout << "AMBIGUOUS" ;
		}
		else if(y == 0){
			cout << "MMYY" ;
		}
		else{
			cout << "MMYY" ;
		}
		return 0 ;
	}
	if(x > 12){
		if(y >= 1 && y <= 12){
			cout << "YYMM" ;
		}
		else if(y == 0){
			cout << "NA" ;
		}
		else
			cout << "NA" ;
		return 0 ;
	}
	if(x == 0){
		if(y == 0){
			cout << "NA" ;
		}
		else if(y >= 1 && y <= 12){
			cout << "YYMM" ;
		}
		else
			cout << "NA" ;
	}
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define max_size (int)(1e5 + 1)

int main(){
	int N, i;
	char *S = (char *)malloc(sizeof(char) * max_size);
	scanf("%s", S);
	for(i = 0; S[i] != '\0'; i++){}
	N = i;
	for(i = N - 1; i >= 0; ){
		if(i >= 6){
			if(strncmp(&S[i - 4], "dream", 5) == 0){
				i -= 5;
			}
			else if(strncmp(&S[i - 6], "dreamer", 7) == 0){
				i -= 7;
			}
			else if(strncmp(&S[i - 4], "erase", 5) == 0){
				i -= 5;
			}
			else if(strncmp(&S[i - 5], "eraser", 6) == 0){
				i -= 6;
			}
			else{
				printf("NO\n");
				return 0;
			}
		}
		else if(i == 5){
			if(strncmp(&S[i - 5], "eraser", 6) == 0){
				i -= 6;
			}
			else{
				printf("NO\n");
				return 0;
			}
		}
		else if(i == 4){
			if(strncmp(&S[i - 4], "dream", 5) == 0){
				i -= 5;
			}
			else if(strncmp(&S[i - 4], "erase", 5) == 0){
				i -= 5;
			}
			else{
				printf("NO\n");
				return 0;
			}
		}
		else{
			printf("NO\n");
			return 0;
		}
	}
	printf("YES\n");
	return 0;
}

Measured memory_bytes: 256
X,  N= map(int, input().split())
if N != 0 :
    P = list(map(int, input().split()))
else:
    P = []

P.sort()

L = []
for p in P:
    L.append(p - X)

Ls = sorted(L, key=abs)

for m in range(100):
    if m*(-1) not in Ls:
        print(X - m)
        break
    elif m not in Ls:
        print(X + m)
        break

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) max((a),-(a))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  while(1){
    int n;
    cin >> n;
    if(n==0) return 0;
    string s;
    int ans=0;
    bool yuka=true,l=false,r=false;
    for(int i=0;i<n;i++){
      cin >> s;
      if(s=="lu"){
        l=true;
        if(yuka&l&r){
          yuka=false;
          ans++;
        }
      }else if(s=="ru"){
        r=true;
        if(yuka&l&r){
          yuka=false;
          ans++;
        }
      }else if(s=="ld"){
        l=false;
        if(!yuka&!l&!r){
          yuka=true;
          ans++;
        }
      }else{
        r=false;
        if(!yuka&!l&!r){
          yuka=true;
          ans++;
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}



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

int main() {
    vector<int> a(3),b(3);
    for (int i=0;i<3;i++){
        cin >> a.at(i);
    }
    sort(a.begin(),a.end());
    cout << a.at(2) - a.at(0) << endl;
}

Measured memory_bytes: 256
dic = {i+1:0 for i in range(4)}

for i in range(3):
    a,b = map(int, input().split())
    dic[a] += 1
    dic[b] += 1

flag = True
for v in dic.values():
    if v == 3: flag = False

if flag: print('YES')
else: print('NO')

Measured memory_bytes: 3060
H, W = map(int, input().split())
c = [[int(i) for i in input().split()] for j in range(10)]

for i in range(10):#中間点
    for j in range(10):#起点
        if i == j:
            continue
        for k in range(10):#終点
            if i == k or j == k:
                continue
            tmp = c[j][i] + c[i][k]
            if c[j][k] > tmp:
                # print(j,i,k)
                c[j][k] = tmp

res = 0
for _ in range(H):
    for i in input().split():
        i = int(i)
        if i == -1:
            continue
        res += c[i][1]
print(res)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define dg(x) cerr << #x << " = " << x << endl;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define fore(i, a, b) for (int i = (int)a; i <= (int)b; ++i)
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
int main()
{
#ifdef LOCAL
    //freopen("h.txt", "r", stdin);
    // freopen("main.out", "w", stdout);
#else
    ios::sync_with_stdio(0), cin.tie(0);
#define endl '\n'
#endif
    ll n,a,b,c,d,e;
    cin>>n>>a>>b>>c>>d>>e;
    cout<<(n-1)/min(a,min(b,min(c,min(d,e))))+5<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <algorithm>
#include <iomanip>
#include <random>
#include <ctime>
#include <bitset>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <climits>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define ld long double
#define ull unsigned long long
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fast_io cout.tie(0), cin.tie(0), ios_base::sync_with_stdio(0)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ld eps = (ld)1 / 1e6;
ll inf = LLONG_MAX, mod1 = 1e9 + 7, mod2 = 998244353;
ll sqr(ll a) { return a * a; }
ll qb(ll a) { return a * a * a; }
ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); }
ll binpow(ll a, ll b, ll mod) { return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod : sqr(binpow(a, b / 2, mod)) % mod) : 1; }
ll binmult(ll a, ll b, ll mod) { return b ? (b % 2 ? (2 * binmult(a, b / 2, mod) + a) % mod : (2 * binmult(a, b / 2, mod)) % mod) : 0; }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main()
{
    fast_io;
    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    while (k > 0 && a >= b) b *= 2, k--;
    while (k > 0 && b >= c) c *= 2, k--;
    cout << (a < b && b < c ? "Yes" : "No");
    return 0;
}

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

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	int cnt = 0;
	int tt = 0;
	while (cnt < c) {
		cnt += a;
		tt++;
		if (tt % 7 == 0) cnt += b;
	}
	cout << tt << endl;
}


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

typedef long long ll;
const ll MOD=1e9+7,MAX=2001;
ll S,memo[2010],prefix[2010];

ll sub(ll a, ll b){
	return (a+MOD-b)%MOD;
}

void dp(){
	memo[0]=1; memo[1]=0; memo[2]=0; 
	prefix[0]=0; prefix[1]=1; prefix[2]=1; prefix[3]=1;
	for(int i=3; i<=MAX; i++){
		memo[i]=prefix[i-2];
		prefix[i+1]=(prefix[i]+memo[i])%MOD;
	}
}

void Input(){
	cin>>S;
}

void Solve(){
	dp();
	cout<<memo[S]<<'\n';
}

int main(){
	Input();
	Solve();
}

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

typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<LD, LD> PDD;

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define dbl(k, x) fixed << setprecision(k) << (x)

template <typename _T>
inline void _DBG(const char *s, _T x) {
  cerr << s << " = " << x << "\n";
}
template <typename _T, typename... args>
void _DBG(const char *s, _T x, args... a) {
  while (*s != ',') cerr << *s++;
  cerr << " = " << x << ',';
  _DBG(s + 1, a...);
}

#define _upgrade                \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define DBG(...) _DBG(#__VA_ARGS__, __VA_ARGS__)

// ********************** CODE ********************** //

int main() {
  _upgrade;
  long double R;
  cin >> R;
  long double p = 2 * M_PI * R;
  cout << dbl(10, p) << endl;
  return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e19;
//const int INF=(1<<30);

int main(){
  string s;
  cin >> s;
  cout << 2 * count(ALL(s), '+') - 4 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MAX=2e5+6;
long long sl[MAX],sz[MAX];
int main(){
  int n;
  cin>>n;
  for (int i=1;i<=n;i++) {
    cin>>sl[i];
    sz[i]=(sz[i-1]+sl[i]); 
  }
  long long ans=0;
  for (int j=1;j<=n;j++) {
    ans+=(sl[j]%1000000007)*((sz[n]-sz[j])%1000000007);
    ans%=1000000007;
  }
  cout<<ans<<endl;
  return 0;
} 

Measured memory_bytes: 6760
A,B,K = map(int,input().split())

if A+K-1 >= B-K+1:
    ans = list(range(A,B+1))
    for i in ans:
        print(i)
else:
    for i in list(range(A,A+K)):
        print(i)
    for i in list(range(B-K+1,B+1)):
        print(i)

Measured memory_bytes: 3060
n = int(input())
h = list(map(int, input().split()))
h.append(10 ** 9 + 1)
ans = []
tmp = 0
for h1, h2 in zip(h, h[1:]):
    if h1 >= h2:
        tmp += 1
    else:
        ans.append(tmp)
        tmp = 0
print(max(ans))


Measured memory_bytes: 14252
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll> > vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
const long long INF = numeric_limits<ll>::max();
const long long MOD = 1000000007;
const long double PI = 3.1415926;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
//char c;
 
#define Endl endl
 
/*--------------------template--------------------*/

int main() {
    ll N;
    cin>>N;
    vi C(N),S(N),F(N);
    REP(i,N)cin>>C[i]>>S[i]>>F[i];
    REP(i,N-1){
    //REP(i,1){
        ans=0;
        FOR(j,i,N-1){
            if(ans<S[j])ans=S[j];
            ans+=(F[j]-(ans-S[j])%F[j])%F[j];
            ans+=C[j];
            //cout<<ans<<endl;
        }
        cout<<ans<<endl;
    }
    cout<<0<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin>>n;
    bool f=0;
    for(int i=0;i<n;i++) {
        int x;
        cin>>x;
        if(x%2==0) {
            if(x%3!=0 && x%5!=0) f=1; 
        }
        if(f) break;
    }
    if(f) cout<<"DENIED"<<endl;
    else cout<<"APPROVED"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ar array
#define nl '\n'
#define AC ios_base::sync_with_stdio(0); cin.tie(NULL);
using namespace std;
const int MOD = 998244353;
const int N = 2*1e5;
ll height[N+5]; 

int main(){
    AC
    int n;
    map<ll, ll> M;
    cin>>n;
    for(int i=1; i<=n; i++){
        cin>>height[i];
        M[(ll)i-height[i]]++;
    }
    ll ans = 0;
    for(int i=1; i<=n; i++){
        ans+=M[(ll)i+height[i]];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 27924
import sys,collections as cl,bisect as bs,math
sys.setrecursionlimit(100000)
Max = sys.maxsize
def l(): #intのlist
	return list(map(int,input().split()))
def m(): #複数文字
	return map(int,input().split())
def onem(): #Nとかの取得
	return int(input())
def s(x): #圧縮
	a = []
	aa = x[0]
	su = 1
	for i in range(len(x)-1):
		if aa == x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
def jo(x): #listをスペースごとに分ける
	return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
	return max(map(max,x))

n = onem()

print(3 * n* n)

Measured memory_bytes: 3316
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(",");
    System.out.println(str[0] + " " + str[1] + " " + str[2]);
  }
}

Measured memory_bytes: 38032
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define pb push_back
#define pp pair<int,int>
#define rep(i,l,r) for(int i=l;i<r;i++)
#define inf 10000000000000000
#define int long long
 main()
{
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt.txt","r",stdin);
	// freopen("output.txt.txt","w",stdout);
	// #endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,k;
	cin>>n>>k;
	vi a(n);
	rep(i,0,n) cin>>a[i];
	vi dp(n,inf);
	dp[0] = 0;
	rep(i,1,n)
	{
		rep(j,1,min(k+1,i+1))
		dp[i] = min(dp[i-j]+abs(a[i]-a[i-j]),dp[i]);
	//	if(i>1) dp[i] = min(dp[i-2]+abs(a[i]-a[i-2]),dp[i]);
	}
	cout<<dp[n-1]<<endl;

}

Measured memory_bytes: 1792
def is_prime(n):
    if n < 2:
        return False
    if n == 2:
        return True
    if n % 2 == 0:
        return False
    x = 3
    while x * x <= n:
        if n % x == 0:
            return False
        x += 2
    return True


N = int(input())
ans = 0
for _ in range(N):
    n = int(input())
    ans += is_prime(n)
print(ans)



Measured memory_bytes: 5612
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <map>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

struct P {
  int x1,y1,x2,y2;
  string s;
  P(int x1,int y1,int x2,int y2, string s) : x1(x1),y1(y1),x2(x2),y2(y2),s(s) {}
};

int main() {
  int n;
  while(cin>>n,n) {
    int w,h;
    cin >> w>>h;
    string title[n];
    vector<P> button[n];;
    map<string, int> rid;
    REP(i,n) {
      cin >> title[i];
      rid[title[i]] = i;
      int m;
      cin >> m;
      REP(j,m) {
        int ax,ay,bx,by;
        cin>>ax>>ay>>bx>>by;
        string s;
        cin >> s;
        button[i].push_back(P(ax,ay,bx,by,s));
      }
    }
    int m;
    cin >> m;
    int now = 0;
    int page[100000] = {};
    int maxpage = 0;
    while(m--) {
      string s;
      cin >> s;
      if (s == "click") {
        int x, y;
        cin >> x >> y;
        FOR(it, button[page[now]]) {
          if (it->x1<=x && x<=it->x2 && it->y1<=y && y<=it->y2) {
            page[++now] = rid[it->s];
            maxpage = now;
            break;
          }
        }
      } else if (s == "show"){
        cout << title[page[now]] << endl;
      } else if (s == "back") {
        if (now>0)
          now--;
      } else if (s == "forward") {
        if (now<maxpage)
          now++;
      }
    }
  }
}

Measured memory_bytes: 0
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
#define double long double
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
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 fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
#define eps 1e-12 
//priority_queue<int,vector<int>, greater<int> > q2;

ll comb(ll N_, ll C_) {
	const int NUM_ = 3000001;
	static ll fact[3000002], factr[3000002], inv[3000002];
	if (fact[0] == 0) {
		inv[1] = fact[0] = factr[0] = 1;
		for (int i = 2; i <= NUM_; ++i) inv[i] = inv[mod % i] * (mod - mod / i) % mod;
		for (int i = 1; i <= NUM_; ++i) fact[i] = fact[i - 1] * i%mod, factr[i] = factr[i - 1] * inv[i] % mod;
	}
	if (C_<0 || C_>N_) return 0;
	return factr[C_] * fact[N_] % mod*factr[N_ - C_] % mod;
}
ll modpow(ll a, ll n = mod - 2) {
	ll r = 1;
	while (n) r = r * ((n % 2) ? a : 1) % mod, a = a * a%mod, n >>= 1;
	return r;
}

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

	int N; cin >> N;
	if (N < 2) {
		cout << 0 << endl;
		return 0;
	}
	int ans = modpow(10, N);
	ans -= (modpow(9, N) * 2 % mod);
	ans += mod;

	ans += (modpow(8, N) % mod);
	ans += mod;


	

	cout << ans % mod << endl;

	return 0;
}



Measured memory_bytes: 3652
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	n = readline() |> parseInt
	a = readline() |> split |> parseMap
	b = readline() |> split |> parseMap
	c = readline() |> split |> parseMap
	k = b[a[1]]
	for i in 2:n
		k += b[a[i]]
		if a[i-1]+1==a[i]
			k += c[a[i-1]]
		end
	end
	println(k)
end

main()

Measured memory_bytes: 164840
from math import factorial as fact

N = int(input())
A = [int(_) for _ in input().split()]
Csum = [0]
tmp = 0

for i in A:
    tmp += i
    Csum.append(tmp)

Csum = sorted(Csum)

num = 10**10
cnt = 0
ans = 0
for i in Csum:
    if i == num:
        cnt += 1
    else:
        if cnt > 1:
            ans += fact(cnt)//(fact(2)*fact(cnt-2))
        cnt = 1
        num = i
if cnt > 1:
    ans += fact(cnt)//(fact(2)*fact(cnt-2))

print(ans)

Measured memory_bytes: 27268
#include <bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fod(i,a,b) for(int i=a;i>=b;i--)
#define me0(a) memset(a,0,sizeof(a))
#define me1(a) memset(a,-1,sizeof(a))
#define op freopen("in.txt", "r", stdin)
#define op1 freopen("C:\\acm\\Cproj\\in.txt","r",stdin);
#define pr freopen("C:\\acm\\Cproj\\out.txt","w",stdout)
#define pr2 freopen("C:\\acm\\Cproj\\std.txt","w",stdout)
#define pii pair<int,int>
using namespace std;
const int INF = 0x3f3f3f3f;
typedef long long LL;
template <class T>
void read(T &val) { T x = 0; T bz = 1; char c; for (c = getchar(); (c<'0' || c>'9') && c != '-'; c = getchar()); if (c == '-') { bz = -1; c = getchar(); }for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - 48; val = x * bz; }
const int maxn = 1e6 + 11;
const int mod=1e9+7;
int n,m,x,y,t;
char g[1100][1100];
int to(int x,int y){
    return (x-1)*m+y;
}
bool check(int x,int y){
    if(x<1||x>n||y<1||y>m||g[x][y]=='#') return false;
    return true;
}

bool vis[maxn];
LL dis[maxn];
int tot,head[maxn];
struct Edge{
    int to,nxt,w;
}e[maxn*100];
void add(int u,int v,int w){
//    cout<<"add "<<u<<" "<<v<<" "<<w<<endl;
    e[++tot]={v,head[u],w};head[u]=tot;
}
struct HeapNode{
    LL dis,u;
    bool operator<(const HeapNode b)const{
        return dis>b.dis;
    }
};
void dijkstra(int s){
    me0(vis);
    memset(dis,0x3f,sizeof(dis));
    dis[s]=0;
    priority_queue<HeapNode>q;
    q.push({0,s});
    while(!q.empty()){
        HeapNode tp = q.top();q.pop();
        int u = tp.u;
        if(vis[u]) continue;
        vis[u]=1;
        for(int i =head[u];i;i=e[i].nxt){
            int to=e[i].to;
            if(dis[to]>dis[u]+e[i].w){
                dis[to]=dis[u]+e[i].w;
                q.push({dis[to],to});
            }
        }
    }
}

int main(){
//    op;
    read(n);read(m);
    int cx,cy,dx,dy;
    read(cx);read(cy);read(dx);read(dy);
    fo(i,1,n) scanf("%s",g[i]+1);
    fo(i,1,n){
        fo(j,1,m){
            int nx = i+1,ny = j;
            if(check(nx,ny)) add(to(i,j),to(nx,ny),0);
            nx = i-1,ny = j;
            if(check(nx,ny)) add(to(i,j),to(nx,ny),0);
            nx = i,ny = j+1;
            if(check(nx,ny)) add(to(i,j),to(nx,ny),0);
            nx = i,ny = j-1;
            if(check(nx,ny)) add(to(i,j),to(nx,ny),0);
            fo(a,-2,2){
                fo(b,-2,2){
                    if(a==0&&b==0) continue;
                    nx = i+a,ny = j+b;
                    if(check(nx,ny)) add(to(i,j),to(nx,ny),1);
                }
            }
        }
    }

    dijkstra(to(cx,cy));

    if(dis[to(dx,dy)]>=INF) puts("-1");
    else printf("%d\n",dis[to(dx,dy)]);

    return 0;
}

Measured memory_bytes: 181196
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <functional>
#include <string>
#include <stack>
#include <set>
#include <sstream>
#include <iomanip>
#include <limits>
#include <cstring>

using namespace std;
using ll = long long;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<string, string> sP;
typedef pair<ll, pair<ll, ll>> PP;

const ll mod = 1e4;
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1 << 30;
const ll INF2 = 9e18;
const double INF3 = 9e14;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
const int tx[8] = { -1,0,1,-1,1,-1,0,1 }, ty[8] = { -1,-1,-1,0,0,1,1,1 };
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define pb push_back
#define eb emplace_back
#define fr first
#define sc second

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

int n, ma, mb, a, b, c, dp[41][410][410];

int main() {
	ll ans = INF;
	cin >> n >> ma >> mb;
	for (int i = 0;i <= n;i++) {
		for (int j = 0;j <= 400;j++) {
			for (int k = 0;k <= 400;k++) {
				dp[i][j][k] = INF;
			}
		}
	}
	dp[0][0][0] = 0;
	for (int i = 1;i <= n;i++) {
		cin >> a >> b >> c;
		for (int j = 0;j <= 400;j++) {
			for (int k = 0;k <= 400;k++) {
				if (dp[i - 1][j][k]!=INF)dp[i][j+a][k+b] = min(dp[i][j+a][k+b], dp[i - 1][j ][k] + c);
				if (dp[i - 1][j][k]!=INF)dp[i][j][k] = min(dp[i][j][k],dp[i - 1][j][k]);
			}
		}
	}
	for (int i = 1;i <= 400;i++) {
		for (int j = 1;j <= 400;j++) {
			if (i / gcd(i, j) == ma && j / gcd(i, j) == mb) {
				if (dp[n][i][j]!=INF)ans = min(ans, (ll)dp[n][i][j]);
			}
		}
	}
	if (ans == INF)cout << -1 << endl;
	else cout << ans << endl;
	return 0;
}

Measured memory_bytes: 27264
# frozen_string_literal: true

_ = gets
a = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)
count = 0

b.each_with_index do |i, idx|
  if i > a[idx]
    rest = i - a[idx]

    if rest > a[idx + 1]
      count += a[idx] + a[idx + 1]
      a[idx + 1] = 0
    else
      a[idx + 1] -= rest
      count += i
    end
  else
    count += i
  end
end

puts count

Measured memory_bytes: 15372
#include<bits/stdc++.h>
using namespace std;
#define ve vector
#define pb push_back


int main()
{
    int n;
    cin>>n;
    int a[n],b[n],c[n];
    for(int i=0;i<n;i++)
        cin>>a[i]>>b[i]>>c[i];
    ve<ve<int>> dp(n+1,ve<int>(3));
    for(int i=0;i<n;i++)
    {
        dp[i+1][0]=max(dp[i][1],dp[i][2])+a[i];
        dp[i+1][1]=max(dp[i][0],dp[i][2])+b[i];
        dp[i+1][2]=max(dp[i][0],dp[i][1])+c[i];
    }
    cout<<max(dp[n][0],max(dp[n][1],dp[n][2]));
    return 0;
}


Measured memory_bytes: 6912
def resolve():
  N, A, B = [int(i) for i in input().split()]
  S = input()
  
  passed_a = 0
  passed_b = 0
  result = [False]*N
  
  for i in range(N):
    if S[i] == "a":
      if passed_a + passed_b < A + B:
        passed_a += 1
        result[i] = True
    
    elif S[i] == "b":
      if passed_a + passed_b < A + B and passed_b < B:
        passed_b += 1
        result[i] = True

  ans = ["Yes" if i else "No" for i in result]
  print("\n".join(ans))

resolve()

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

int main(){

    int n,m,x,i,sum=0;
   cin>>n>>m;
   for(i=1;i<=m;i++){
    cin>>x;
    sum=sum+x;
   }
   if(sum>n) cout<<-1<<endl;
   else cout<<n-sum<<endl;
}



Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1e9+7;
 
int main(){
  string s;
  cin >>s;

  for(int i=0; i<s.size()-1; i++){
    if(s[i]==s[i+1]){
      cout << "Bad" << endl;
      return 0;
    }
  }
  cout << "Good" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
using namespace std;
typedef long long int LL;
typedef unsigned long long int ULL;

int main() {
    int t, x;

    cin >> t >> x;

    printf("%.8f\n", t /(double) x );
    return 0;
}


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

signed main()
{
  int n;
  int score[2] = {0};
  string str[2];

  cin >> n;

  while (n > 0){
    cin >> str[0] >> str[1];

    if (str[0] > str[1]){
      score[0] += 3;
    }
    else if (str[0] < str[1]){
      score[1] += 3;
    }
    else {
      score[0]++;
      score[1]++;
    }
    n--;
  }

  cout << score[0] << " " << score[1] << endl;

  return (0);
}

Measured memory_bytes: 3124
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int dp[11111][111][2];
vector<int> fact;
vector<int> ifact;
vector<int> inv;
vector<int> pow2;
const int MOD = (1e9 + 7);
int add(int a, int b)
{
	a+=b;
	while(a>=MOD) a-=MOD;
	return a;
}
int mult(int a, int b)
{
	return (a*1LL*b)%MOD;
}
int modpow(int a, int b)
{
	int r=1;
	while(b)
	{
		if(b&1) r=mult(r,a);
		a=mult(a,a);
		b>>=1;
	}
	return r;
}
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	string s; cin>>s; s="0"+s; int d; cin>>d;
	int n=s.length();
	dp[0][0][0]=1;
	for(int i=0;i+1<n;i++)
	{
		for(int j=0;j<d;j++)
		{
			for(int k=0;k<2;k++)
			{
				int v=dp[i][j][k];
				if(v==0) continue;
				for(int dig=0;dig<10;dig++)
				{
					if(!k&&(dig>s[i+1]-'0')) continue;
					int newk=k;
					if(!k&&(dig<s[i+1]-'0')) newk=1;
					dp[i+1][(j+dig)%d][newk]=add(dp[i+1][(j+dig)%d][newk],v);
				}
			}
		}
	}
	int ans = MOD-1;
	for(int k=0;k<2;k++)
	{
		ans=add(ans,dp[n-1][0][k]);
	}
	cout<<ans<<'\n';
}


Measured memory_bytes: 8960
#include <stdio.h>
int main(void)
{
	int r,g,b;
	scanf("%d%d%d",&r,&g,&b);
	if((r*100+g*10+b)%4==0){
		printf("YES\n");
	}else{
		printf("NO\n");
	}
	return 0;
}

Measured memory_bytes: 128
import time
import random

d = int(input())
dd = d * (d + 1) // 2
*C, = map(int, input().split())
S = [list(map(int, input().split())) for i in range(d)]
T = []
L = [-1 for j in range(26)]
for i in range(d):
    max_diff = -10**7
    arg_max = 0
    for j in range(26):
        memo = L[j]
        L[j] = i
        diff = S[i][j] - sum([C[k] * (i - L[k]) for k in range(26)])
        if diff > max_diff:
            max_diff = diff
            arg_max = j
        L[j] = memo
    T.append(arg_max)
    L[arg_max] = i


def calc_score(T):
    L = [-1 for j in range(26)]
    X = [0 for j in range(26)]
    score = 0
    for i in range(d):
        score += S[i][T[i]]
        X[T[i]] += (d - i) * (i - L[T[i]])
        L[T[i]] = i
    for j in range(26):
        score -= C[j] * (dd - X[j])
    return score


score = calc_score(T)
start = time.time()
cnt = 0
while True:
    now = time.time()
    if now - start > 1.8:
        break
    p = (cnt // 26) % d
    q = cnt % 26
    memo = T[p]
    T[p] = q
    new_score = calc_score(T)
    temp = 20000 * (1 - (now - start) / 2)
    prob = 2**((new_score - score) / temp)
    if random.random() < prob:
        score = new_score
    else:
        T[p] = memo
    cnt = (cnt + 1) % (10**9 + 7)

for t in T:
    print(t + 1)


Measured memory_bytes: 85148
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<cmath>
#include<iomanip>
#include<functional>
using namespace std;

int INF = 1e9 + 7;

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

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

	vector<ll> lsum(n + 1, 0), rsum(n + 1, 0);
	lsum[1] = a[1], rsum[1] = a[n];
	for (int i = 1; i < n; i++) {
		lsum[i + 1] = lsum[i] + a[i + 1];
		rsum[i + 1] = rsum[i] + a[n - i];
	}
	ll ans = 1e18;
	for (int i = 1; i < n; i++) {
		ans = min(ans, abs(lsum[i] - rsum[n - i]));
	}
	cout << ans << endl;
}

Measured memory_bytes: 4096