akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <unordered_set>
#include <bitset>
#include <limits>
#include <algorithm>

#define MOD_BIG 1000000007
#define MOD_BIG2 998244353
using std::string;
using std::cin;
using std::cout;
using std::cerr;
using std::endl;
using ll = long long;
using std::vector;

template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) {
    vec.resize(len);
    for (auto &v : vec) ndarray(v, args...);
}

//////////////////////////////////////

enum Status {
    Not = 0,
    Now,
    End,
};

template<typename T>
struct Edge {
    int to;
    int from;
    T weight;
    Edge(int from, int to, T weight) : from(from), to(to), weight(weight) {}
};

template<typename T, typename D>
struct Graph {
    int n;
    vector<vector<Edge<T>>> g;
    vector<D> data;
    vector<Status> s;
    
    Graph(int N) : n(N), g(N+1), data(N+1), s(N+1) {}
    
    void add_edge(int from, Edge<T> e) {
        g[from].push_back(e);
    }
    void set_data(int node, D value) {
        data[node] = value;
    }
    
    //出力
    void print() {
        for (auto v: g) {
            for (auto e: v) {
                std::cout << e.from << "-(" << e.weight << ")->" << e.to << ", ";
            }
            std::cout << std::endl;
        }
    }
    
    int bfs(int start);
};

template<typename T, typename D>
int Graph<T, D>::bfs(int start) {
    vector<T> d(n+1, -1);
    vector<vector<Edge<T>>> route(n+1);
    std::queue<int> q;
    d[start] = 1;
    int res = 0;
    q.push(start);
    while(!q.empty()) {
        int v = q.front();
        q.pop();
        
        for (auto e: g[v]) {
            if (d[e.to] != -1) {
                //到達済み
                if (d[e.to] % 2 != (d[e.from] + 1) % 2) {
                    return -1;
                }
                continue;
            }
            d[e.to] = d[e.from] + 1;
            res = std::max(res, d[e.to]);
            auto tmp = route[e.from];
            tmp.push_back(e);
            route[e.to] = tmp;
            q.push(e.to);
        }
    }
    return res;
}



//////////////////////////////////////

int main() {
    
    int N;
    cin >> N;
    Graph<int, int> g(N);
    
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            char c;
            cin >> c;
            if (c == '1') {
                g.add_edge(i+1, Edge<int>(i+1, j+1, 1));
                g.add_edge(j+1, Edge<int>(j+1, i+1, 1));
            }
        }
    }
    
    int ans = 0;
    for (int i = 0; i < N; i++) {
        auto res = g.bfs(i+1);
        if (res == -1) {
            cout << -1 << endl;
            return 0;
        }
        ans = std::max(ans, res);
    }
    cout << ans << endl;
    
    return 0;
}


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

#define INF (1 << 29)
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define out(x) cout << x << endl;
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;

int N, M, R;
int r[100];
int A[100000], B[100000], C[100000];
int d[300][300];
bool used[100];
int ans;
void dfs(int count, int src, int ret){
    if(count == R){
        if(ans > ret){
            ans = ret;
            return;
        }
    }
    for(int i = 1; i <= R; i++){
        if(used[i] != true){
            used[i] = true;
            if(src == -1){
                dfs(count+1, i, 0);
            }else{
                dfs(count+1, i, ret + d[r[src]][r[i]]);
            }
            used[i] = false;
        }
    }
}
int main(){
    cin >> N >> M >> R;
    FOR(i, 1, R+1){
        cin >> r[i];
    }
    rep(i, N+1){
        A[i] = B[i] = C[i] = 0;
    }
    rep(i, M){
        cin >> A[i] >> B[i] >> C[i];
    }
    // warshall-floyd >>> 
    // can be used if N <= 200
    FOR(i, 1, N+1){
        FOR(j, 1, N+1){
            if(i == j){
                d[i][j] = 0;
            }else{
                d[i][j] = INF;
            }
        }
    }
    // warshall-floyd input >>>
    rep(i, M){
        if(d[A[i]][B[i]] > C[i]){
        d[A[i]][B[i]] = C[i];
        d[B[i]][A[i]] = C[i];
        }
    }
    // warshall-floyd input <<<
    for(int k = 1; k <= N; k++){
        for(int i = 1; i <= N; i++){
            for(int j = 1; j <= N; j++){
                if(d[i][j] > d[i][k] + d[k][j]){
                    d[i][j] = d[i][k] + d[k][j];
                }
            }
        }
    }

    ans = INF;
    rep(i, 9){
        used[i] = false;
    }
    dfs(0, -1, 0);
    out(ans);
    return 0;
}

Measured memory_bytes: 768
n,m=map(int,input().split())
x=sorted(list(map(int,input().split())))
a=[0]*(m-1)

dis=x[-1]-x[0]
for i in range(m-1):
    a[i]=x[i+1]-x[i]
a=sorted(a,reverse=True)
ans=dis-sum(a[:n-1])
print(ans)

Measured memory_bytes: 13960
#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define pii pair<int,int>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
ll MOD=1e9+7;
#define INF 2*1e9
#define N 600010
using namespace std;
//区間加算
static const int MAX_SIZE = 1 << 19; //segment tree のサイズ。 2^19 ≒ 5.2 * 10^5
ll all[2 * MAX_SIZE - 1], part[2 * MAX_SIZE - 1]; // segment tree
//区間[a, b)に値xを加算する.
void ADD(int a, int b, int x, int k = 0, int l = 0, int r = MAX_SIZE)
{
    if (a <= l && r <= b){ //[l, r)が[a, b)に完全に内包されていれば
        all[k] = (all[k]+x)%MOD; //[l, r)の全ての区間が持つ値としてxを足す.
    }
    else if (l < b && a < r){ //[l, r)と[a, b)が交差していれば
        part[k] =(part[k]+ (min(b, r) - max(a, l)) * x)%MOD;  //交差している分の値を, 部分的な和を持つノードに加算する.
        ADD(a, b, x, k * 2 + 1, l, (l + r) / 2); //子でも同じ処理を行う.
        ADD(a, b, x, k * 2 + 2, (l + r) / 2, r); //〃.
    }
}
void add(int a,int b,int x){
    ADD(a,b,x,0,0,MAX_SIZE);
}
ll SUM(int a, int b, int k = 0, int l = 0, int r = MAX_SIZE)
{
    if (b <= l || r <= a){ //[a, b)と[l, r)が全く交差しない場合
        return (0);
    }
    else if (a <= l && r <= b){ //完全に内包されていれば
        return (all[k] * (r - l) + part[k])%MOD;
    }
    else { //[l, r)と[a, b)が交差していれば
        ll res;
        res = (min(b, r) - max(a, l)) * all[k]; //そのノードの全ての要素が持つ値のうち, [a, b)に属すものの分だけを加算する.
        res += SUM(a, b, k * 2 + 1, l, (l + r) / 2); //子ノードで和を求める.
        res += SUM(a, b, k * 2 + 2, (l + r) / 2, r); //〃
        return (res)%MOD;
    }
}
//[a,b)の和を求める
ll sum(int a,int b){
    return SUM(a,b,0,0,MAX_SIZE);
}
main(){
    int n;cin>>n;
    ll a,b;cin>>a>>b;
    ll s[N];
    rep2(i,1,n)cin>>s[i];
    s[0]=-1e18;
    vector<int> v;
    if(a>b) swap(a,b);
    rep(i,n-1){
        if(s[i+2]-s[i]<a){cout<<0;return 0;}
    }
    rep(i,n){
        if(s[i+1]-s[i]<a)v.pb(i);
    }
    v.pb(n+1);
    add(0,1,1);
    int pos=0,now=0;
    while(pos<n+1){
        while(pos<v[now]){
            int l=lower_bound(s,s+(n+1),s[pos]+b)-s;
            if(l<v[now]+2){
            add(l,v[now]+2,sum(pos,pos+1));
            }
            pos++;        
        }
        now++;
    }
    cout<<sum(n+1,n+2);
}

Measured memory_bytes: 11900
#include <math.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define PI acos(-1)
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;

int main(void) {
  /* 標準入力フラグ */
  int   scan;

  /* 数入力 */
  ll    answer;
  ll    n;
  answer = 0;
  scan = scanf("%lld", &n);

  /* プログラムを書く */
  answer = n*n + n*n*n + n;







  /* 数回答 */
  printf("%lld", answer);


  return (0);
}



Measured memory_bytes: 1732
#include <iostream>
#include <vector>

using namespace std;

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

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

    long long res = 0;
    for (int l = 0, r = 0, s = a[0]; l < n; l++) {
        while (r + 1 < n && (s & a[r + 1]) == 0) {
            s += a[r + 1];
            r++;
        }
        s -= a[l];
        res += r - l + 1;
    }

    cout << res << endl;
}


Measured memory_bytes: 1152
from collections import *
n=int(input())
l=list(map(int,input().split()))
d=defaultdict(int)
for i in l:
    d[i]+=1
x=[]
for i in d:
    if(d[i]>=4):
        x.append(i)
        x.append(i)
    elif(d[i]>=2):
        x.append(i)
x.sort(reverse=True)
if(len(x)<2):
    print(0)
else:
    print(x[0]*x[1])

Measured memory_bytes: 101004
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{ 
    ll N;
    cin>>N;
    vector<ll> T(N);
    for(ll i=0;i<N;i++)
    {
        cin>>T[i];
    }
    sort(T.begin(),T.end());
    for(ll i=0;i<N-1;i++)
    {
        ll a,b;
        if(T[i]<T[i+1])
        {
            a=T[i+1];
            b=T[i];
        }
        else
        {
            a=T[i];
            b=T[i+1];
        }
        ll k=a%b;
        while(k!=0)
        {
            a=b;
            b=k;
            k=a%b;
        }
        T[i+1]=T[i]/b*T[i+1];
    }
    cout<<T[N-1]<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#define maxn 100010
using namespace std;
int N,a[maxn],b[maxn],c[maxn],f1[maxn],f2[maxn],f3[maxn];
int main() {
	scanf("%d",&N);
	for(int i=0; i<N; i++) {
		scanf("%d",&a[i]);
		scanf("%d",&b[i]);
		scanf("%d",&c[i]);
	}
	f1[0]=a[0];
	f2[0]=b[0];
	f3[0]=c[0];
	for(int i=1; i<N; i++) {
		f1[i]=max(f2[i-1],f3[i-1])+a[i];
		f2[i]=max(f1[i-1],f3[i-1])+b[i];
		f3[i]=max(f1[i-1],f2[i-1])+c[i];
	}
	printf("%d\n",max(f1[N-1],max(f2[N-1],f3[N-1])));
	return 0;
}


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

int main(){
  int H, W;
  cin >> H >> W;
  char S[H][W];
  
  bool can = true;

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

  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
    cin >> S[i][j];
    }}

  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      if (S[i][j]=='#'){
        	bool can_1 = true ;
        		for(int d=0; d<4; d++){
         		 const int ni = i + dy[d]; //列
         		 const int nj = j + dx[d]; //行
        		  if(ni < 0 || ni >= H) continue;
        		  if(nj < 0 || nj >= W) continue;
        		  if(S[ni][nj]=='#'){can_1 = false;}
      			  }
        if(can_1){can = false;}
       }
  }}
  if(can) cout << "Yes" << endl;
  else 	  cout << "No" << endl;
 return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
    int p = 0;
    int pmin[1000] = { 0 };
    int n = 1;
    int k = 1;
    int i = 0;
    int j = 0;
    int sum = 0;
    int swap = 0;

    scanf("%d %d", &n, &k);
    for (i = 0; i < n; i++) {
        scanf("%d", &p);
        if (i < k) {
            pmin[i] = p;
            continue;
        }
        for (j = 0; j < k; j++) {
            if (pmin[j] > p) {
                swap = pmin[j];
                pmin[j] = p;
                p = swap;
            }
        }
    }

    for (j = 0; j < k; j++) {
        sum += pmin[j];
    }

    printf("%d\n", sum);
    return 0;
}

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

signed main() {
	int n;
	cin >> n;
	int ans = 0;
	for(int i = 1; i <= n; i++){
		int cou = 1;
		bool t = true;
                int x = i;
		while(t){
			if(x/10 >= 1){
				cou++;
				x /= 10;
			}
			else t = false;
		}
		if(cou%2 == 1) ans++;
	}
	
	cout << ans << endl;
	
	return 0;			
}

Measured memory_bytes: 3608
import std.algorithm, std.conv, std.range, std.stdio, std.string;

void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}}
void readA(T)(size_t n,ref T t){t=new T(n);auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(ElementType!T);r.popFront;}}
void readM(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=readln.splitter;foreach(ref v;t){v[i]=r.front.to!(ElementType!(typeof(v)));r.popFront;}}}
void readS(T)(size_t n,ref T t){t=new T(n);foreach(ref v;t){auto r=readln.splitter;foreach(ref j;v.tupleof){j=r.front.to!(typeof(j));r.popFront;}}}

void main()
{
  int n; readV(n);
  int[] c, s, f; readM(n-1, c, s, f);

  foreach (i; 0..n-1) {
    auto t = 0;
    foreach (ci, si, fi; lockstep(c[i..$], s[i..$], f[i..$])) {
      if (t < si) t = si;
      else        t = (t+fi-1)/fi*fi;
      t += ci;
    }

    writeln(t);
  }

  writeln(0);
}


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

int p,q;
vector<vector<char>> vec;
int ans=0;

void bfs(int h,int w){
  vector<vector<int>> dist(p,vector<int>(q,-1));
  dist.at(h).at(w)=0;
  vector<int> mx(4),my(4);
  mx={-1,0,1,0};
  my={0,1,0,-1};
  queue<pair<int,int>> Q;
  Q.push({h,w});
  while(Q.size()){
    int h=Q.front().first;
    int w=Q.front().second;
    Q.pop();
    for(int i=0;i<4;i++){
      int nh=h+mx.at(i);
      int nw=w+my.at(i);
      if(nh<0||nh>=p||nw<0||nw>=q) continue;
      if(vec.at(nh).at(nw)=='#') continue;
      if(dist.at(nh).at(nw)==-1){
        dist.at(nh).at(nw)=dist.at(h).at(w) + 1;
        Q.push({nh, nw});
        ans=max(ans,dist.at(nh).at(nw));
      }
    }
  }
}

int main(){
  cin>>p>>q;
  vec.resize(p,vector<char>(q));
  for(int i=0;i<p;i++){
    for(int j=0;j<q;j++){
      cin>>vec.at(i).at(j);
    }
  }
  for(int i=0;i<p;i++){
    for(int j=0;j<q;j++){
      if(vec.at(i).at(j)=='.'){
        bfs(i,j);
      }
    }
  }
  cout<<ans<<endl;
}

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

#define FOR(i,a) for(int i=0;i<a;i++)
#define int long long int
signed main(){
	int n,m,p;
	cin>>n>>m>>p;
	int score=0;
	int path[5000][3];
	FOR(i,m){
		FOR(j,3){cin>>path[i][j];}
	}
	int cost[2500];
	FOR(i,n){cost[i]=-1612695271;}
	cost[0]=0;
	int newcount =0;
	bool update=true;
	int old[2500];
	int reach[2500];
	FOR(i,2500){reach[i]=0;}
	reach[n-1]=1;
	FOR(j,m){
		FOR(i,m){if(reach[path[i][1]-1]==1){reach[path[i][0]-1]=1;}}
	}
	while(update==true){
		update=false;
		if(newcount==m){FOR(i,2500){old[i]=cost[i];}}
		if(newcount>m){
			FOR(i,2500){
				if(reach[i]==1 and old[i]!=cost[i]){
					cout<<-1<<endl;return 0;
				}
			}
		}
		FOR(i,m){
			if(cost[path[i][0]-1]!=-1612695271 and cost[path[i][1]-1]<cost[path[i][0]-1]+path[i][2]-p){
				update=true;
				cost[path[i][1]-1]=cost[path[i][0]-1]+path[i][2]-p;
			}
		}
		if(newcount>m){break;}
		newcount++;
	}
	cout<<max(cost[n-1],0ll)<<endl;
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define SZ(x) ((int)(x).size())
#define rep(i,n) for(int i=0;i<(n);++i)
#define fore(i,a) for(auto &i:a)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define ALL(x) (x).begin(),(x).end()
signed _main(); signed main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> using v = vector<T>;
template<class T> using vv = vector<v<T>>;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
using P=pair<int,int>;

signed _main(){
  /*
  string S; cin >> S;
  if(S=="ABC") cout << "ARC" << endl;
  else cout << "ABC" << endl;
  */
  int N,K; cin >> N >> K;
  v<int> A(N+1,0);
  rep(i,K){
    int d; cin >> d;
    rep(j,d){
      int a; cin >> a;
      A[a]++;
    }
  }
  int ans=0;
  for(int i=1;i<=N;i++){
    if(A[i]==0) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3644
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int min = scan.nextInt();
		int r = scan.nextInt();
		int maxLong = r - min;
		if (min > r){
			min = r;
		}
		for (int i = 0; i < N - 2; i++) {
			r = scan.nextInt();
			if (maxLong < r - min) {
				maxLong = r - min;
			}
			if (r < min) {
				min = r;
			}
		}
		System.out.println(maxLong);
	}
}

Measured memory_bytes: 94352
#include <bits/stdc++.h>
#define REP(i,n) for (long long i=0;i<(n);i++)
#define FOR(i,a,b) for (long long i=(a);i<(b);i++)
#define RREP(i,n) for(long long i=n;i>=0;i--)
#define RFOR(i,a,b) for(long long i=(a);i>(b);i--)
#define dump1d_arr(array) REP(i,array.size()) cerr << #array << "[" << (i) << "] ==> " << (array[i]) << endl
#define dump2d_arr(array) REP(i,array.size()) REP(j,array[i].size()) cerr << #array << "[" << (i) << "]" << "[" << (j) << "] ==> " << (array[i][j]) << endl
#define dump(x)  cerr << #x << " => " << (x) << endl
#define dumpP(p) cerr << "( " << p.first << " , " << p.second << " )" << ends
#define SORT(c) sort((c).begin(),(c).end())
#define MIN(vec) *min_element(vec.begin(), vec.end())
#define MAX(vec) *max_element(vec.begin(), vec.end())
#define UNIQ(vec) vec.erase(unique(vec.begin(), vec.end()),vec.end()) //ソートの必要あり
#define IN(n,m)  (!(m.find(n) == m.end()))
#define ENUM(m) for (auto itr = m.begin(); itr != m.end(); ++itr)
#define dump_MAP(m) for(auto itr = m.begin(); itr != m.end(); ++itr) { cerr << itr->first << " --> "  << itr->second << endl; }
#define FINDL(vec,x) (lower_bound(vec.begin(),vec.end(),x) - vec.begin())
#define FINDU(vec,x) (upper_bound(vec.begin(),vec.end(),x) - vec.begin())
#define ROUND(N) setprecision(N)
#define ROUND_PRINT(N,val) cout << fixed;cout << setprecision(N) << val << endl
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define INARR(h,w,x,y) (0 <= y && y < h && 0 <= x && x < w)
#define EQ(a,b) (abs(a - b) < 1e-10)
#define ZETA(n,m) REP(i,n) REP(b,1<<m) if (!(b & (1 << i))) 
using namespace std;
constexpr int dx[4] = {0,1,0,-1};
constexpr int dy[4] = {1,0,-1,0};
constexpr long double pi = M_PI;
constexpr double eps = 1e-10;
constexpr long mod = 1000000007;
constexpr short shINF = 32767;
constexpr long loINF = 2147483647;
constexpr long long llINF = 9223372036854775807;
typedef long long LL;
typedef vector<long> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<LL,LL> pr;
typedef vector<bool> VB;
typedef vector<pr> VP;
struct Order {
	bool operator() (pr const& a,pr const& b) const {
		return a.first > b.first || ((a.first == b.first) && (a.second > b.second));
	}
};

VI merge(VI &A,VI &B) {
	VI cp(A.begin(),A.end());
	REP(i,B.size()) cp.push_back(B[i]);
	sort((cp).begin(),(cp).end(),greater<long>());
	return vector<long>(cp.begin(),cp.begin()+min(2,(int)cp.size()));
}

int main(void) {
	int N;
	cin >> N;
	VI A(1<<N);
	REP(i,1<<N) cin >> A[i];
	VVI dp(1<<N,VI(2,0));
	REP(i,1<<N) dp[i] = {A[i]};
		
	RREP(b,N-1) {	
		RREP(k,(1<<N)-1) {
			if (!(k & (1 << b))) dp[k|(1<<b)] = merge(dp[k|(1<<b)],dp[k]);
		}
	}
	
	long ans = 0;
	FOR(i,1,1<<N) {
		ans = max(ans,dp[i][0]+dp[i][1]);
		cout << ans << endl;
	}
	//dump2d_arr(dp);
}



Measured memory_bytes: 19456
S = input().strip()
cur = 0
flag = 0
while cur<len(S):
    if S[cur:cur+11]=="dreameraser":
        cur += 11
    elif S[cur:cur+10]=="dreamerase":
        cur += 10
    elif S[cur:cur+7]=="dreamer":
        cur += 7
    elif S[cur:cur+6]=="eraser":
        cur += 6
    elif S[cur:cur+5]=="dream" or S[cur:cur+5]=="erase":
        cur += 5
    else:
        flag = 1
        break
if flag==0:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 40176
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
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; }
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

#define MAX_V 1000000

#define MAX_N 11
#define MAX_M 11
#define MAX_K 11
int n, m, k;
int p[MAX_M];
vector<int> s[MAX_M];

void input() {
  cin >> n >> m;
  rep(i, 0, m) {
    cin >> k;
    rep(j, 0, k) {
      int _s;
      cin >> _s;
      s[i].push_back(_s);
    }
    vsort(s[i]);
  }
  rep(i, 0, m) cin >> p[i];
}

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

  input();

  int rsl = 0;
  for(int bit = 0; bit < (1 << n); ++bit) {
    map<int, int> cnt;
    for(int mask = 0; mask < n; ++mask) {
      if(bit & (1 << mask)) {
        rep(i, 0, m) {
          if(binary_search(s[i].begin(), s[i].end(), mask + 1)) {
            ++cnt[i];
          }
        }
      }
    }
    bool flag = true;
    rep(i, 0, m) {
      if(!(cnt[i] % 2 == p[i])) flag = false;
    }
    if(flag) ++rsl;
  }
  cout << rsl << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>

using namespace std;

double abso( double n )
{
	if ( n < 0 )
	{
		return -n;
	}
	else
	{
		return n;
	}
}

int main()
{
	vector<double> height;

	double input;

	while ( cin >> input )
	{
		height.push_back( input );
	}

	sort( height.begin(), height.end() );

	cout << abso( *height.begin() - *height.rbegin() ) << endl;

	return 0;
}

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

using namespace std;

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


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

    int k = 1;
    for (int i = 0; i < n; ++i) {
        if (a[i] == k) ++k;
    }

    if (k != 1) {
        cout << n - (k - 1);
    } else {
        cout << -1;
    }

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <iomanip>
#include <complex>
#include <random>
#include <bitset>
#include <list>
#include <assert.h>
// #include <prettyprint.hpp>
using namespace std;
#define repi(i,n) for(int i=0;i<n;++i)
#define rep(i,n) for(ll i=0;i<n;++i)
#define repinvi(i,n) for(int i=n-1;i>=0;--i)
#define sll(n) scanf("%lld", &n);
#define sii(n) scanf("%d", &n);
#define slf(n) scanf("%lf", &n);
#define pll pair<ll,ll>
#define pii pair<int,int>
#define psi pair<si,si>
typedef long long ll;
typedef double lf;
typedef short int si;


void Main(){
    ll N, X, T;
    cin >> N >> X >> T;
    cout << (N + (X-1)) / X * T << endl;

}

int main(){
    Main();
}

Measured memory_bytes: 3108
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
    tmp = input.split("\n");
    N = tmp[0];
    tmp2 = String(tmp[1]).split(" ");
    T = tmp2[0];
    A = tmp2[1];
    H = String(tmp[2]).split(" ");
    //console.log(H);
    check = 9999;
    for(i = 0; i < N; i++){
        aveTemp = T - 0.006*H[i]
        //console.log(Math.abs(aveTemp - A));
        if(Math.abs(aveTemp - A) < check){
            check = Math.abs(aveTemp - A)
            answer = i + 1;
        }

    }
    console.log(answer);
    
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

template<class T>
inline vector<pair<T, T> > primeFactorize(T n) {
	vector<pair<T, T> > res;
	for (T a = 2; a * a <= n; a++) {
		if (n % a != 0) continue ;
		T ex = 0;
		while (n % a == 0) {
			++ex;
			n /= a;
		}
		res.push_back({a, ex});
	}
	if (n != 1) res.push_back({n, 1});
	return res;
}

int main() {
	cin.tie(0)->sync_with_stdio(false);

	ll A, B; cin >> A >> B;
	set<ll> a, b;

    const auto &resA = primeFactorize(A);
    for (auto p : resA)
		a.insert(p.first);

    const auto &resB = primeFactorize(B);
    for (auto p : resB)
		b.insert(p.first);

	set<ll> res;
	set_intersection(a.begin(), a.end(),
			b.begin(), b.end(),
			inserter(res, res.end()));

	cout << res.size() + 1 << '\n';
	return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
const int MN = 105;
const ll INFL = 1LL<<60;
int s,t;
ll mf,f;
ll res[MN][MN];
int p[MN];
vvi g;
void aug(int u, ll fl) {
	if(u == s) {f = fl;return;}
	aug(p[u],min(res[p[u]][u],fl));
	res[p[u]][u] -= f;res[u][p[u]] += f;
}
int main() {
	int n;
	memset(res,0,sizeof(res));
	scanf("%d ",&n);
	s = 0;t = n+1;
	g.assign(n+2,vi());
	ll mv = 0;
	for(int i=0;i<n;i++) {
		ll fl;
		scanf("%lld ",&fl);
		if(fl > 0) {
			mv += fl;
			res[s][i+1] = fl;
			g[s].push_back(i+1);
			g[i+1].push_back(s);
		} else {
			res[i+1][t] = -fl;
			g[t].push_back(i+1);
			g[i+1].push_back(t);
		}
	}
	for(int i=1;i<=n;i++) {
		for(int j=1;j<i;j++) {
			if(!(i%j)) {
				res[i][j] = INFL;
				g[i].push_back(j);
				g[j].push_back(i);
			}
		}
	}
	mf = 0;
	while(1) {
		f = 0;
		queue<int> q;
		bitset<MN> bs;
		q.push(s);
		bs.set(s);
		while(!q.empty() && !bs[t]) {
			int u = q.front();q.pop();
			for(int i=0;i<g[u].size();i++) {
				int v = g[u][i];
				if(bs[v]) continue;
				if(res[u][v] == 0) continue;
				p[v] = u;
				bs.set(v);
				q.push(v);
			}
		}
		if(bs[t]) {
			aug(t,INFL);
		}
		mf += f;
		if(f == 0) break;
	}
	printf("%lld\n",mv-mf);
	
}

Measured memory_bytes: 512
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
import math
from copy import deepcopy
import queue
import numpy as np
# sympy as syp(素因数分解とか)
Mod = 1000000007
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1] 
for i in range(2, 10**5 + 1):
    fact.append((fact[-1] * i) % Mod)
    inv.append((-inv[Mod % i] * (Mod // i)) % Mod)
    factinv.append((factinv[-1] * inv[-1]) % Mod)
    
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n - r] % p
    
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[y] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)

def main():  #startline-------------------------------------------
    x, n = map(int, input().split())
    numlist = [i for i in range(102)]
    p = list(map(int, input().split()))
    for i in range(101):
        if numlist[i] in p:
            numlist[i] = -1
    ans = float("inf")
    memo = 101
    for i in range(102):
        if numlist[i] == -1: continue
        if ans > abs(numlist[i] - x):
            ans = abs(numlist[i] - x)
            memo = i
    print(memo)
if __name__ == "__main__":
    main() #endline===============================================

Measured memory_bytes: 38944
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
using namespace std;
#define pi pair<int32,int32>
#define pl pair<int64,int64>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
// cout << fixed << setprecision(10);
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}

int main(){
    long long x,y; cin >> x >> y;
    int ans = 0;
    while (x <= y){
        x *= 2;
        ans++;
    }
    cout << ans << endl;
} 

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

int main() {
  int n;
  	cin>>n;
  int sum=0;
  int now=1;
  vector<int>vec(n);
  for(int i=0;i<n;i++){
    cin>>vec.at(i);
  }
   //配列をここまでで完成させてしまう
   //ここから下でループさせる
  for(int j=0;j<n;j++){
    if(now==2){
  cout<<sum<<endl;
      break;
    }
    else{
      now=vec.at(now-1);
      sum+=1;
    }
  }
  if(sum==n)
    cout<<-1<<endl;
  
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using VI = vector<int>;
#define rep(i, n) for (int i = 0; i < (n); i++)

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

  int n, q; cin >> n >> q;
  VI c(n); rep(i, n) cin >> c[i];
  vector<pair<int, int>> lr(q); rep(i, q) cin >> lr[i].first >> lr[i].second;
  rep(i, q) lr[i].first--;

  const int sq = 700;
  vector<tuple<int, int, int>> lri(q);
  rep(i, q) lri[i] = make_tuple(lr[i].first / sq, lr[i].second, i);
  sort(lri.begin(), lri.end());

  VI ans(q);

  VI cnt(n+1);
  int prev = -1;
  int lx, rx; lx = rx = get<0>(lri[0]);
  int sum = 0;
  VI changed;
  for (auto [ls, r, i] : lri) {



    // ここのコメントを外すとhandmade03-05, random06がWAになる

    if (ls != prev) {
      for (auto cx : changed) cnt[cx] = 0;
      changed.clear();
      lx = rx = r;
      prev = ls;
      sum = 0;
    }



    int l = lr[i].first;
    assert(r == lr[i].second); assert(rx <= r);
    int cx;
    while (rx < r) {
      assert(cnt[c[rx]] >= 0);
      if (cnt[cx=c[rx++]]++ == 0) sum += 1, changed.push_back(cx);
    }
    while (lx > l) {
      assert(cnt[c[lx-1]] >= 0);
      if (cnt[cx=c[--lx]]++ == 0) sum += 1, changed.push_back(cx);
    }
    while (lx < l) {
      assert(cnt[c[lx]] >= 1);
      if (--cnt[c[lx++]] == 0) sum -= 1;
    }
    ans[i] = sum;
  }
  rep(i, q) cout << ans[i] << "\n";
}


Measured memory_bytes: 22972
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	//	n = 17971
	t := fmt.Sprintf("%d", n)
	rev := ""
	for i := len(t); i > 0; i-- {
		rev += string(t[i-1])
	}
	if rev == t {
		fmt.Println("Yes")
		return
	}
	fmt.Println("No")
}


Measured memory_bytes: 512
s = input()
if s[len(s)-1] == "2" or s[len(s)-1] ==  "4" or s[len(s)-1] ==  "5" or s[len(s)-1] ==  "7"  or s[len(s)-1] == "9":
    print("hon")
elif s[len(s)-1] == "3":
    print("bon")
else:
    print("pon")


Measured memory_bytes: 9076
#include <bits/stdc++.h>
      
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); i++)
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())

#define pb emplace_back
#define fi first
#define se second

using namespace std;

using ld = long double;
using ll = long long int;

const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ll MOD = 998244353;
     
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); }
template<class T> void UNIQUE(vector<T> &a){ a.erase(unique(a.begin(), a.end()), a.end()); }

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

ll in(){long long int x; assert(scanf("%lld", &x) == 1); return x;}
ld fin(){double x; assert(scanf("%lf", &x) == 1); return x;}
char yuyushiki[1000010]; string stin(){assert(scanf("%s", yuyushiki) == 1); return yuyushiki;}

// head

int main(){

  ll a = in();
  ll cur = 0;
  FOR(i, 1, INFLL){
    cur += i;
    if(cur >= a){
      cout << i << endl;
      break;
    }
  }
  
  
  
  return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector<int> x(n);
    for (int i = 0; i < n; i++) cin >> x[i];
    int ans = 1e9;
    for (int p = 0; ; p++) {
        int sum = 0;
        for (int i = 0; i < n; i++) {
            sum += (x[i] - p) * (x[i] - p);
        }
        if (ans < sum) break;
        ans = sum;
    }
    cout << ans << endl;
    return 0;
}


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


int main(){
    int A[100],top=0,i;
    char s[100];
    while(scanf("%s",s) != EOF ){
        if( s[0] == '+' ){
            top--;
            A[top] = A[top] + A[top+1];
        }else if ( s[0] == '-' ){
            top--;
            A[top] = A[top] - A[top+1];
        }else if ( s[0] == '*' ){
            top--;
            A[top] = A[top] * A[top+1];
        }else {
            top++;
            A[top] = atoi(s);
            
}
    }
      printf("%d\n",A[1]);
    return 0;
}



Measured memory_bytes: 2108
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String input = sc.nextLine();
        String input2 = sc.nextLine();
        // System.out.println(input);
        String[] inputs = input.split(" ", 0);
        String[] inputs2 = input2.split(" ", 0);
        int hp = Integer.parseInt(inputs[0]);
        int iter = Integer.parseInt(inputs[1]);
        boolean hantei = false;
        for(int i = 0; i < iter; i++){
            int attack = Integer.parseInt(inputs2[i]);
            hp -= attack;
            if(hp <= 0){
                break;
            }
        }
        if(hp > 0){
            hantei = true;
        }
        if(hantei){
            System.out.println("No");
        }else{
            System.out.println("Yes");
        }
    }
}

Measured memory_bytes: 47444
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define reep(i,n) for(ll i = n; i >-1; i--)
#define deb(variable) cout<<#variable<<"="<<variable<<endl;
#define pb push_back
const ll INF=99999999999999999;
const ll MAX_N=100010;
ll a,b,c,d,e,k,x,y,m,n,l,q,ans=0;
vl v,v1,v2;
int main(){
    cin>>n>>a>>b>>c>>d>>e;
    v.push_back(a);
    v.push_back(b);
    v.push_back(c);
    v.push_back(d);
    v.push_back(e);
    sort(v.begin(),v.end());
    cout<<(n-1)/v[0]+5;
}

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

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

  int64_t ans = 0;
  for(int b=1; b<=N; b++){
    int p = N/b, r = N%b;
    ans += p * max(0, b-K) + max(0, r-K+1);
    if(K == 0) ans--;
  }

  cout << ans << endl;
}
  
  

Measured memory_bytes: 256
import sys

lines = [list(map(int,line.split())) for line in sys.stdin]
n,m,l = lines[0]

A = lines[1:n+1]
B = [i for i in zip(*lines[n+1:])]

for a in A:
    row = []
    for b in B:
        row.append(sum([i*j for i,j in zip(a,b)]))
    print (" ".join(map(str,row)))

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

void insertionSort(int* A, int N) {
  int v, j;
  for (int i = 1; i < N; i ++) {
    v = A[i];
    j = i - 1;
    while (j >= 0 && A[j] > v) {
      A[j+1] = A[j];
      j --;
      A[j+1] = v;
    }
    for (int index = 0; index < N-1; index ++) {
      cout << A[index] << " ";
    }
    cout << A[N-1] << endl;
  }
}

int main() {
  int N;
  cin >> N;
  int A[N], l;
  for (int i = 0; i < N; i ++) {cin >> l; A[i] = l;}
  for (int i = 0; i < N-1; i ++) cout << A[i] << " ";
  cout << A[N-1] << endl;
  insertionSort(A, N);
}



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

int main() {
	ll a,b;
	cin>>a>>b;
	if(a>=b)
	{
		for(ll i=0;i<a;i++)
		{
			cout<<b;
		}
	}
	else
	{
		for(ll i=0;i<b;i++)
		{
			cout<<a;
		}
	}
	return 0;
}


Measured memory_bytes: 256
// dp[W]
#include <iostream>
using namespace std;
int n, W, v, w;
int main() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	
	cin >> n >> W;
	int dp[W+1] = {0};
	for (int i = 1; i <= n; ++i) {
		cin >> v >> w;
		for (int j = W; j >= w; --j) 
			dp[j] = max(dp[j], dp[j-w]+v);
	}
	cout << dp[W] << "\n";
}

Measured memory_bytes: 3192
#include<bits/stdc++.h>
#define MOD 1000000007
#define MOD2 1000000006
#define TEMPMOD1 998244353
#define TEMPMOD2 998244352
#define INF 1000000000000000007
#define NEGINF -1000000000000000007
#define vll vector<ll> 
#define vvll vector<vector<ll>>
#define pll pair<ll,ll>
#define plll pair<pll,ll>
#define vpll vector<pll>
using namespace std;
typedef long long int ll;

map<pll,ll> edgeval;
ll vertice;
ll weight[100001];
vector<ll> graph[100001];


void DFS(ll start,ll parent)
{
    ll size=graph[start].size();
    ll store;
    for(ll i=0;i<size;i++)
    {
        store=graph[start][i];
        if(store==parent)
        {
            continue;
        }
        weight[store]=weight[start]+edgeval[make_pair(start,store)];
        DFS(store,start);
    }
}


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

    memset(weight,0,sizeof(weight));
    cin>>vertice;
    ll vert1,vert2,weigh;
    for(ll i=1;i<vertice;i++)
    {
        cin>>vert1>>vert2>>weigh;
        graph[vert1].push_back(vert2);
        graph[vert2].push_back(vert1);
        edgeval[make_pair(vert1,vert2)]=weigh;
        edgeval[make_pair(vert2,vert1)]=weigh;
    }
    DFS(1,0);
    for(ll i=1;i<=vertice;i++)
    {
        weight[i]=weight[i]%2;
        cout<<weight[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 24320
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
Apparently, the tree supports the same operations as the set 
(at least I haven't any problems with them before), but also there are two new features — 
find_by_order() — The first returns an iterator to the k-th largest element (counting from zero)
order_of_key() — the number of items in a set that are strictly smaller than our item. 
https://codeforces.com/blog/entry/11080
using namespace __gnu_pbds; */
using namespace std;
#define test() int t;cin>>t;for(int test=1;test<=t;test++)
#define int long long
#define MOD 1000000007
#define pb push_back 
#define ins insert
#define fast(); ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ld long double
#define endl '\n'
int m(int a) {
    return ((a%MOD)+MOD)%MOD;
}
int p(int a, int b) {
    int res = 1;
    while(b > 0){
        if(b&1) res = m(m(res)*m(a));
        a = m(m(a)*m(a));
        b >>= 1;
    }
    return res;
}
// vector<int> fac; //precompute fac array
// fac.resize(n+1);
// fac[0] = 1; 
// for (int i=1; i<=n; i++)   fac[i] = m(m(fac[i-1])*m(i));
// int modInverse(int n){ 
// return p(n, MOD-2); 
// }  
// int nCrModPFermat(int n, int r){   
//     if(r == 0)  return 1; 
//     return m(m(m(fac[n])*m(modInverse(fac[r])))*m(modInverse(fac[n-r]))); 
// } 
signed main(){
    fast();
    int x, n;
    cin >> x >> n;
    vector<int> a(n);
    for(int i=0; i<n; i++)  cin >> a[i];
    sort(a.begin(), a.end());
    if(!binary_search(a.begin(), a.end(), x)){
        cout << x << endl;
        return 0;
    }
    int ind = -1;
    for(int i=0; i<n; i++){
        if(a[i] == x){
            ind = i;
            break;
        }
    }
    // for(auto i: a)  cerr << i << " ";
    // cerr << endl;
    int p1 = ind-1, p2 = ind+1;
    int temp = x-1;
    while(p1 >= 0){
        // cerr << temp << " " << p1 << endl;
        if(a[p1] != temp){
            break;
        }
        else{
            temp--;
            p1--;
        }
    }
    // cerr << temp << endl;
    int temp2 = x+1;
    // cerr << "temp2: " << endl;
    while(p2 < n){
        // cerr << temp2 << " " << p2 << endl;
        if(a[p2] != temp2){
            break;
        }
        else{
            p2++;
            temp2++;
        }
    }
    if(abs(temp-x) <= abs(temp2-x)){
        cout << temp << endl;
    }
    else    cout << temp2 << endl;
    cerr << "\nTime elapsed : " << 1000 * clock() / CLOCKS_PER_SEC << " ms\n";
}

Measured memory_bytes: 3656
N, Y = map(int,input().split())

a1 = -1
b1 = -1
c1 = -1
for i in range(N+1):
    for j in range(N+1-i):
        total = 10000*i+5000*j+1000*(N-i-j)
        if total == Y:
            a1 = i
            b1 = j
            c1 = N-i-j

print(str(a1)+" "+str(b1)+" "+str(c1))
        


Measured memory_bytes: 9136
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define endl '\n'
#define maxl __LONG_LONG_MAX__
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define rep(i, n) for(int i = 0; i < n; i++)
#define rev(i, n) for(int i = n-1; i >= 0; i--)
#define rep1(i, n) for(int i=1; i < n; i++)
#define rev1(i, n) for(int i=n ; i > 0; i--)
#define FOR(i, a, b) for(int i=a ; i < b; i++)
#define trace(x)                 cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define n_ones(x) __builtin_popcountll(x)
#define n_trailzero(x) __builtin_ctzll(x)
#define n_leadingzero(x) __builtin_clz(x)
#define sz(a) (ll)(a.size())
#define all(v) v.begin(),v.end()

typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<pair<ll, ll>> vpll;
typedef vector<vector<ll>> vvll;
typedef stack<ll> stk;
typedef queue<ll> que;

typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_setll;
typedef tree<char,null_type,less<char>,rb_tree_tag,
tree_order_statistics_node_update> indexed_setc;

ll max(int a,ll b){ return max((ll)a,b);}
ll min(int a,ll b){ return min((ll)a,b);} 
ll min(ll a,int b){ return min(a,(ll)b);}
ll max(ll a,int b){ return max(a,(ll)b);}

ll mod = 1e9 + 7;

void solve()
{	
	ll n;
	cin>>n;
	ll a[n-1];
	rep(i, n-1)
		cin>>a[i];
	ll cnt[n+1] = {0};
	rep(i, n-1)
	{
		cnt[a[i]]++;
	}
	rep1(i, n+1)
	{
		cout<<cnt[i]<<endl;
	}
	return;
}

int main()
{
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    cout.tie(NULL);
	ll t = 1;
	//cin>>t;
	rep(i, t)
		solve();
	return 0;
	
}

Measured memory_bytes: 6740
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9;
using namespace std;
using ll = long long;
int main() {
    int a , b , c;
    cin >> a >> b >> c;
    int d = max(a , b);
    if(c % d == 0){
        cout << c / d << endl;
    }
    else{
        cout << c / d + 1 << endl;
    }
}

Measured memory_bytes: 3556
n,k=map(int,input().split())
h=[int(x) for x in input().split()]
inf=1e9
dp=[inf]*(n)
dp[0]=0
for i in range(n):
    for j in range(1,k+1):
        if i>=j:
            dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]))
print(dp[-1])

Measured memory_bytes: 55392
import java.math.BigInteger;
import java.util.Collections;
import java.util.Iterator;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner std = new Scanner(System.in);
        int n = std.nextInt();
        int m = std.nextInt();
        PriorityQueue<Integer> queue = new PriorityQueue<>(n, Collections.reverseOrder());

        for (int i = 0; i < n; i++) {
            queue.add(std.nextInt());
        }
        int restCount = m;

        while (restCount != 0) {
            Integer price = queue.poll();
            Integer newPrice = (int) (price * 0.5);
            queue.add(newPrice);
            restCount--;
        }

        Iterator<Integer> it = queue.iterator();
        BigInteger ans = BigInteger.ZERO;

        while (it.hasNext()) {
            int price = it.next();
            ans = ans.add(BigInteger.valueOf(price));
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 64888
fn solve(s: &str, t: &str) -> String {
    let sn = s.len();
    let tn = t.len();
    let s = s.chars().collect::<Vec<_>>();
    let t = t.chars().collect::<Vec<_>>();

    #[derive(Clone)]
    enum Src {
        INV,
        UL,
        L,
        U,
    }

    let mut dp = vec![vec![(0, Src::INV); tn + 1]; sn + 1];

    for i in 0..sn {
        let sc = s[i];
        for j in 0..tn {
            let tc = t[j];
            if sc == tc {
                dp[i + 1][j + 1] = (dp[i][j].0 + 1, Src::UL);
            } else {
                if dp[i][j + 1].0 > dp[i + 1][j].0 {
                    dp[i + 1][j + 1] = (dp[i][j + 1].0, Src::U);
                } else {
                    dp[i + 1][j + 1] = (dp[i + 1][j].0, Src::L);
                }
            }
        }
    }

    let mut i = sn;
    let mut j = tn;
    let mut ans = "".to_owned();

    while i > 0 && j > 0 {
        match dp[i][j].1 {
            Src::UL => {
                ans.push(s[i - 1]);
                i -= 1;
                j -= 1;
            }
            Src::L => {
                j -= 1;
            }
            Src::U => {
                i -= 1;
            }
            Src::INV => unreachable!(),
        }
    }

    ans.chars().rev().collect()
}

#[test]
fn solve_test() {
    assert_eq!(solve("axyb", "abyxb"), "ayb".to_owned());
    assert_eq!(solve("aa", "xayaz"), "aa".to_owned());
}

#[allow(unused_macros)]
macro_rules! parse_line {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            iter.next().unwrap().parse::<$t>().unwrap()
        }
    );

    ( $( $t:ty), +) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ( $(iter.next().unwrap().parse::<$t>().unwrap()),* )
        }
    );
}

#[allow(unused_macros)]
macro_rules! read_line {
    () => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        line.pop();
        line
    }};
}

#[allow(unused_macros)]
macro_rules! parse_vec {
    ( $t:ty ) => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        let iter = line.split_whitespace();
        iter.map(|v| v.parse::<$t>().unwrap()).collect::<Vec<_>>()
    }};
}

fn main() {
    let s = read_line!();
    let t = read_line!();

    println!("{}", solve(&s, &t));
}


Measured memory_bytes: 90364
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,0,n)
#define SORT(V) sort((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
using namespace std;

int main(){
  ll N,mn=INF,mx=0;
  cin>>N;
  ll A[N];
  REP(i,N){
    cin>>A[i];
    mn=min(mn,A[i]);
    mx=max(mx,A[i]);
  }
  cout<<mx-mn<<endl;
}

Measured memory_bytes: 256