akhauriyash/Code-Regression huggingface dataset:
import sys

s=input()

lens=len(s)

while lens>0:
    lens0=lens
    if s[lens-7:lens]=="dreamer":
        lens=lens-7
    elif s[lens-5:lens]=="dream":
        lens=lens-5
    elif s[lens-6:lens]=="eraser":
        lens=lens-6
    elif s[lens-5:lens]=="erase":
        lens=lens-5
    if lens0==lens:
        print("NO")
        sys.exit()

print("YES")        
        

Measured memory_bytes: 3188
/* 2017/09/17
data will be seperated to 3 groups, a b c
the bigest(a) should >= sum / 3
then the second should >= (sum - a) / 3
loop to find the just data that comply with the previous conditions
*/
#include <iostream>
#include <cstdio>
using namespace std;

int main()
{
	// end link to head
	int InArray[200000] = {0};
	int N = 0;
	
	// initialize input
	int temp;
	cin >> N;
	for(int i = 0; i < N; i++){
		cin >> temp;
		InArray[i] = temp;
		InArray[i + N] = temp;
	}
	
	// Calculate sum and average
	long long sum = 0;
	for(int i = 0; i < N; i++){
		sum += InArray[i];
	}
	long long average;
	if(sum % 3 == 0){
		average = sum / 3;
	}else{
		average = sum / 3 + 1;
	}
	
	long long MaxMin = 0;
	long long tempMin;
	long long a1_sum, a2_sum;
	long long average2;
	
	for(int a1 = 0; a1 < N; a1++){
		a1_sum = 0;
		for(int a2 = a1 + 1; a2 < (a1 + N); a2++){
			a1_sum += InArray[a2 - 1];
			if(a1_sum < average) continue;
			
			if((sum - a1_sum) % 2 == 0){
				average2 = (sum - a1_sum) / 2;
			}else{
				average2 = (sum - a1_sum + 1) / 2;
			}
			
			a2_sum = 0;
			for(int a3 = a2 + 1; a3 < (a1 + N); a3++){	// left 1 for a3_sum
				a2_sum += InArray[a3 -1];
				if(a2_sum < average2) continue;
								
				if(a2_sum - InArray[a3 -1] > MaxMin){
					MaxMin = a2_sum - InArray[a3 -1];
				}
				if(sum - a1_sum - a2_sum   > MaxMin){
					MaxMin = sum - a1_sum - a2_sum;
				}
				break;
			}
			break;
		}
	}
	
	cout << MaxMin << endl;
	
	return 0;
}

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

// header area
// test
int main() {
    string S;
    cin >> S;
    deque<char> dS(S.size());
    for (int i = 0; i < S.size(); ++i) dS[i] = S[i];

    int Q; cin >> Q;
    int rev = 0;
    for (int i = 0; i < Q; ++i) {
        int type; cin >> type;
        if (type == 2) {
            int f; char c;
            cin >> f >> c; --f;
            if (rev) f = 1 - f; // 反転状態だったら、フラグを反転
            if (f == 0) dS.push_front(c);
            else dS.push_back(c);
        }
        else rev = 1 - rev;
    }
    if (rev) reverse(dS.begin(), dS.end());
    for (auto c : dS) cout << c;
    cout << endl;
}

Measured memory_bytes: 896
#include<iostream>
using namespace std;
int main() {
	int N;
	cin >> N;
	int a[105], sum = 0;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
		sum = sum + a[i];
	}
	int M;
	cin >> M;
	int P[105], X[105], count = 0;
	for (int j = 0; j < M; j++) {
		cin >> P[j] >> X[j];
		count = sum - (a[P[j] - 1] - X[j]);
		cout << count << endl;
	}
	return 0;
}

Measured memory_bytes: 256
n = gets.chomp.to_i
m = []
n.times do
  as = gets.chomp.split.map(&:to_i)
  a = as[0]
  xs = as.drop(2)
  m[a] = []
  for x in xs
    m[a][x] = 1
  end
end

for i in 1..n
  for j in 1..n
    x = if m[i][j].nil?
      print 0
    else
      print 1
    end
    print x.to_s
    print " " if j != n
  end
  print "\n"
end

Measured memory_bytes: 8844
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);	
		int N = sc.nextInt();
		int[] A;
		A = new int[N];

		for(int i = 0; i < N; i++){
		 	A[i]= sc.nextInt();
		}
		int minj;
		int count = 0;
		for(int i = 0; i < N; i++){
			minj = i;
			for(int j = i; j < N; j++){
				if(A[j] < A[minj]){
					minj = j;
				}
			}
			if(minj != i){
				int temp = A[i];
				A[i] = A[minj];
				A[minj] = temp;
				count++;
			}
		}


		for(int k = 0; k < N; k++){
			System.out.printf("%d",A[k]);
			if(k != N - 1){
				System.out.printf(" ");
			}	
		}
		System.out.printf("\n%d\n",count);

	}
}


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

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

int Y,M,D;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	scanf("%d/%d/%d",&Y,&M,&D);
	if(Y>2019) return _P("TBD\n");
	if(Y==2019 && M>4) return _P("TBD\n");
	_P("Heisei\n");
	
}


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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
vector<int> left(vector<int> a,vector<int> l);
vector<int> right(vector<int> a,vector<int> r);
int gcd(int x, int y);
int n;
 
int main(){
    cin>>n;
    vector<int> a(n);
    vector<int> l(n+1);
    vector<int> r(n+1);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int ans=0;
    l=left(a,l);
    r=right(a,r);
    for(int i=1;i<n-1;i++){
        //cout<<l[i]<<" "<<r[i+1]<<endl;
        ans=max(ans,gcd(l[i-1],r[i+1]));
    }
    ans=max(ans,r[1]);
    ans=max(ans,l[n-2]);
    cout<<ans<<endl;
    return 0;
}
vector<int> left(vector<int> a,vector<int> l){
    l[0]=a[0];
    for(int j=1;j<n;j++){
        l[j]=gcd(l[j-1],a[j]);
    }
    return l;
}
vector<int> right(vector<int> a,vector<int> r){
    r[n]=a[n-1];
    for(int j=n-1;j>=0;j--){
        r[j]=gcd(r[j+1],a[j]);
        //cout<<r[j-1]<<endl;
    }
    return r;
}
int gcd(int x, int y){
    //if(x==0) return y;
    if(y==0) return x;
    else return gcd(y,x%y);
}

Measured memory_bytes: 2176
#include<stdio.h>
#define N 100001
#define NIL -1
 
typedef struct {
  int parent, left, right;
}Node;
 
Node Tree[N]; 
void print(int);
int Depth[N];
 
 
 
int main(VOID){
  int i, j, n, cc, child[N], node;
  scanf("%d", &n);
   
  for ( i = 0; i < n; i++ ) {
    Tree[i].parent = NIL;
    Tree[i].left = NIL;
    Tree[i].right = NIL;
  }
   
   
 
  for(i=0; i < n; i++ ){
    scanf("%d %d", &node, &cc);
    for(j=0; j < cc; j++){
      scanf("%d", &child[j]);
       
      Tree[child[j]].parent = node;
      if(j == 0) Tree[node].left = child[0];
      else Tree[child[j-1]].right = child[j]; 
    }
  }
   
  for(i=0; i<n;i++) Depth[i] = getDepth(i);
  for ( i = 0; i < n; i++ ) print(i);
   
  return 0;
}
 
 
 
 
 
int getDepth(int in){
  int d=0;
   
  while(Tree[in].parent >= 0){
    in = Tree[in].parent;  
    d++;
  }
   
  return d;
}
 
 
void print(int node){
  int i, count=0;
   
  printf("node %d: parent = %d, depth = %d, ",node ,Tree[node].parent, Depth[node]);
   
  if(Tree[node].parent == NIL)
    printf("root, [");
   
  else if(Tree[node].left == NIL)
    printf("leaf, [");
   
  else
    printf("internal node, [");
   
  node = Tree[node].left;
  while(node != NIL){
    if(count==0) printf("%d", node);
    else printf(", %d", node);
     
    node = Tree[node].right;
    count++;
     
  }
   
   
  printf("]\n");
   
}

Measured memory_bytes: 2564
#include<bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  if(n>=(int)s.length()) {
  	cout<<s;
  } else {
  	for(int i=0;i<n;i++) {
    	cout<<s[i];
    }
   	cout<<"...";
  }
}

Measured memory_bytes: 3580
n, k = map(int, input().split())
x = [0] * n
for i in range(k):
    d = int(input())
    a = list(map(int, input().split()))
    for j in range(len(a)):
        x[a[j] - 1] += 1
c = 0
for i in range(n):
    if x[i] == 0:
        c += 1
print(c)

Measured memory_bytes: 9188
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm> // sort
#include <map>

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;


string day[7] = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
int main(){
    string S;
    cin >> S;
    int res;

    REP(i,7)
    {
        if(day[i] == S)
        {
            res = 7 - i;
        }
    }

    cout << res << endl;

    return 0;    
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int n;
long long a[404], d[404][404];
int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i < n; i++) {
        for (int j = 1; j + i <= n; j++) {
            d[j][j + i] = 1e18;
            for (int k = j; k < j + i; k++) {
                d[j][j + i] = min(d[j][j + i], d[j][k] + d[k + 1][j + i]);
            }
            for (int k = j; k <= j + i; k++) d[j][j + i] += a[k];
        }
    }
    cout << d[1][n] << '\n';
}


Measured memory_bytes: 1536
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>

int lcm(int a, int b)
{
    return a / std::__gcd(a, b) * b;
}

int main()
{
    int N, M;
    std::cin >> N >> M;
    
    std::vector<int> A(N);
    for (int i = 0; i < N; i++) {
        std::cin >> A[i];
    }
    
    long long res = 0;
    int max = INT_MIN, min = INT_MAX;
    for (int i = 0, j = 0; i < lcm(N, M); i++, j++) {
        max = std::max(max, A[i % N]);
        min = std::min(min, A[i % N]);
        
        if (j + 1 == M) {
            res += max - min;
            j = -1;
            max = INT_MIN;
            min = INT_MAX;
        }
    }
    std::cout << res << std::endl;    
    return 0;
}

Measured memory_bytes: 3096
n,k = map(int,input().split())
s = '0'+input()+'0'
Handstands = [(1,1)]
for i in range(1,n+2):
    if s[i-1]=='0' and s[i]=='1':
        left = i
    if s[i-1]=='1' and s[i]=='0':
        right = i
        Handstands += [(left,right)]
Handstands += [(n+1,n+1)]
if k<=len(Handstands)-1:
    ans = 0
    for i in range(len(Handstands)-k):
        ans = max(ans,Handstands[i+k][1]-Handstands[i][0])
    print(ans)
else:
    print(n)

Measured memory_bytes: 10068
#include <iostream>

using namespace std;
int main(int argc, char *argv[]) {
	string s;
	cin >> s;
	
	int ans = 0;
	int count = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T') {
			count++;
		} else {
			if (count > ans) {
				ans = count;
			}
			count = 0;
		}
	}
	if (count > ans) {
		ans = count;
	}
	count = 0;
	
	cout << ans << endl;
}

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

#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);i++)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;i>=(int)(m);i--)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
//constexpr long long MOD = (ll) 1e9 + 7;
constexpr long long MOD = 998244353LL;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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

struct Edge {
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
	to = _to; cap = _cap; rev = _rev;
	}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

ll pow2_m(ll x, ll n, ll mod) {
 ll ans = 1ll;
 while (n > 0) {
  if ((n & 1) == 1) {
   ans = ans * x % mod;
  }
  x = x * x % mod;
  n >>= 1;
 }
 return ans;
}

class Combination {
public:
 Array fact;//n！
 Array inv;//n!の逆元
 ll mod;
 Combination(ll n, ll _mod) {
  mod = _mod;
  fact.resize(n + 1);
  fact[0] = 1;
  REP(i, n) {
   fact[i + 1] = (fact[i] * (i + 1LL)) % mod;
  }
  inv.resize(n + 1);
  inv[n] = mod_inv(fact[n]);
  for(int i=n;i>0;i--) {
   inv[i - 1] = inv[i] * i % mod;
  }
 }
 //modの逆元
 ll mod_inv(ll x) {
  ll n = mod - 2;
  ll res = 1LL;
  while (n > 0) {
   if (n & 1) res = res * x % mod;
   x = x * x % mod;
   n >>= 1;
  }
  return res;
 }
 ll nCr(ll n, ll r) {
  return ((fact[n] * inv[r] % mod) * inv[n - r]) % mod;
 }
 ll nPr(ll n, ll r) {
  return (fact[n] * inv[n - r]) % mod;
 }
 ll nHr(ll n, ll r) {
  //重複組み合わせ：n種類のものからr種類選ぶ
  return nCr(r + n - 1, r);
 }
};

void solve(){
    ll n,m,k;
    cin>>n>>m>>k;

    ll ans=0;

    Combination com(n,MOD);
    REP(i,k+1){
        
        (ans+=pow2_m(m-1,n-1-i,MOD)*com.nCr(n-1,i)%MOD)%=MOD;
    }

    cout<<ans*m%MOD<<en;
}

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

    solve();
    //ll t;cin>>t;REP(i,t) solve();

    return 0;
}

Measured memory_bytes: 6368
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
//typedef __int64 LL;
typedef long long int LL;
typedef vector<int> ivec;
typedef vector<string> svec;

const int MOD=1000000007;

int main(){
	LL a,b,c,k;
	cin>>a>>b>>c>>k;
	LL x=k,y=k-a,z=k-a-b;
	x=min(a,x);
	y=max(min(b,y),(LL)0);
	z=max(min(c,z),(LL)0);
	cout<<x-z<<"\n";
	
	return 0;
}

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

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        double a = Double.parseDouble(sc.next());
        double b = Double.parseDouble(sc.next());
        int C = Integer.parseInt(sc.next());
        double radian = Math.toRadians(C);

        double h = b * Math.sin(radian);
        double S = a * h / 2;
        double a1 = b * Math.cos(radian);
        double a2 = a - a1;
        double c = Math.sqrt(a2 * a2 + h * h);
        out.printf("%.10f\n", S);
        out.printf("%.10f\n", a + b + c);
        out.printf("%.10f\n", h);
        out.flush();
    }
}


Measured memory_bytes: 26368
n = input()
A = list(map(int, input().split()))

import collections
c = collections.Counter(A)

l_ans = []
for i in c.keys():
    ans = 0
    if not c.get(i-1) == None:
        ans += c[i-1]
    if not c.get(i) == None:
        ans += c[i]
    if not c.get(i+1) == None:
        ans += c[i+1]
    l_ans.append(ans)
print(max(l_ans))

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

int main(){
    string s;
    int i=0;
    cin >> s;
    for(int k=0;k<4;k++){
        if(s[k]=='+')i+=1;
        else i-=1;
    }

    cout << i <<endl;
    return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>  // sort, 二分探索, etc
#include <iomanip>  // setprecision (浮動小数点の出力の誤差)
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cmath>

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=a,i##_len=(b);i<i##_len;++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define cauto const auto&
#define UNIQUE(v) (v).erase( unique(all(v), (v).end() );
#define SZ(x) ((ll)(x).size()) // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
#define INF 1000000000000
#define MOD 1000000007
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

using namespace std;
using ll = long long;
using ull = unsigned long long;

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

const char newl = '\n';

ll qp(ll a,ull b){ll ans=1;do{if(b&1u)ans*=a;a*=a;}while(b>>=1u);return ans;}
ll qp(ll a,ull b,ll mod){ll ans=1;do{if(b&1u)ans=ans*a%mod;a=a*a%mod;}while(b>>=1u);return ans;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll comb(int n, int r) {
    vector<vector<ll> > v(n+1, vector<ll>(r+1, 0));
    for(int i=0;i<n+1;i++) {v[i][0]=1; if(i < r+1)v[i][i]=1; }
    for(int i=1;i<n+1;i++) {for(int j=1;j<min(i,r+1);j++) {v[i][j]=v[i-1][j-1]+v[i-1][j];}}
    return v[n][r];
}

// INT_MAX   = 2.1e+09 (2147483647)
// LONG_MAX  = 9.2e+18 (9223372036854775807)
// LLONG_MAX = 9.2e+18 (9223372036854775807)


int main() {
    ll h, w, k;
    cin >> h >> w >> k;
    vector<string> vec;
    rep(i, h) {
        string x;
        cin >> x;
        vec.push_back(x);
    }

    ll ans = 0;
    rep(ii, pow(2, h)) {
        rep(jj, pow(2, w)) {
            ll total = 0;
            rep(i, h) {
                rep(j, w) {
                    if ((ii >> i) & (jj >> j) & 1u) {
                        if (vec[i][j] == '#') {
                            total += 1;
                        }
                    }
                }
            }
            if (total == k) {
                ans += 1;
            }
        }
    }

    cout << ans << newl;

    return 0;
}


Measured memory_bytes: 3328
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;

int main(){
	int n, a[200][3], p[3][101], ans[200];
	
	scanf(" %d", &n);
	memset(p, 0, sizeof(p));
	memset(ans, 0, sizeof(ans));
	
	for(int i=0; i<n; ++i){
		for(int j=0; j<3; ++j){
			scanf(" %d", &a[i][j]);
			p[j][ a[i][j] ]++;	
		}
	}
	
	for(int i=0; i<n; ++i){
		for(int j=0; j<3; ++j){
			if(p[j][a[i][j]]==1){
				ans[i]+=a[i][j];	
			}		
		}
	}
	
	for(int i=0; i<n; ++i) printf("%d\n", ans[i]);
}

Measured memory_bytes: 1192
#include <iostream>

using namespace std;

int main()
{
    int x, a, b;
    cin >> x >> a >> b;
    if (abs(x - a) < abs(x - b))
    {
        cout << "A" << endl;
    }
    else
    {
        cout << "B" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        h: usize,
        n: usize,
        v: [usize; n]
    }
    if h > v.iter().cloned().sum::<usize>() {
        println!("No");
    } else {
        println!("Yes");
    }
}


Measured memory_bytes: 4352
#include <iostream>
using namespace std;
int main(void){
   int a,b;
   cin>>a>>b;
   if ( a < b ){
   cout<<"a < b"<<endl;
   }
   else if (a > b){
   cout<<"a > b"<<endl;
   }
   else{
   cout<<"a == b"<<endl;       
   }
   return 0;
}



Measured memory_bytes: 3084
W,a,b=map(int,input().split())
if a==b:
    print(0)
elif a<b:
    if a+W>=b:
        print(0)
    else:
        print(b-(a+W))
else:
    if b+W>=a:
        print(0)
    else:
        print(a-(b+W))

Measured memory_bytes: 3060
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
int ceil(int a, int b) {
    return (a + b - 1) / b;
}
int round(int a, int b) {
    return (a + b / 2) / b;
}
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    int N, K;
    cin >> N >> K;
    int res = 1;
    REP(i, N) {
        if (res * 2 < res + K) {
            res *= 2;
        } else {
            res += K;
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
s=0
if int(N/100) == 7:
    print("Yes")
    s+=1
    

N = N % 100 
    

if s==0 and int(N / 10) == 7:
    print("Yes")
    s+=1

N = N % 10 

if s==0 and N / 1 == 7:
    print("Yes")
    s+=1
if s == 0:
    print("No")


Measured memory_bytes: 9188
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <utility>
#include <cmath>
#define REP(i, n) for(int i = 0; i < n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define RSORT(x) sort(x.begin(), x.end(), std::greater<int>())
#define swap(a, b) \
  do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0)
#define vi vector<int>
using namespace std;

const double EPS = 1e-10;
const double PI  = acos(-1.0);

int main() {
  
  int a, b, c, x;
  cin >> a >> b >> c >> x;

  int s = 0;
  REP(i_a,a+1) {
    REP(i_b, b+1) {
      REP(i_c, c+1) {
        if((500 * i_a + 100 * i_b + 50 * i_c) == x)
          ++s;
      }
    }
  }

  cout << s << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	int n; cin >> n; ll sum = 0;
	int a;
	for(int i = 0; i < n; i++){
		cin >> a;
		sum +=  a - 1;
	}
	
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main() {
	int a, b, c;
	int count = 0;
	std::cin >> a >> b >> c;

	for (int i = 0; i < (b - a + 1); i++) {
		if (c%(a + i)== 0) {
			count++;
		}
	}

	std::cout << count << std::endl;



}


Measured memory_bytes: 3112
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n, k := scanInt(), scanInt()
	a := scanInts(n)
	sort.Ints(a)
	ans := 0
	for i := 0; i < k; i++ {
		ans += a[i]
	}
	fmt.Fprintln(wr, ans)
}


Measured memory_bytes: 1784
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int K = sc.nextInt();
    String S = sc.next();
    char[] C = new char[N];
    char prev= S.charAt(0);
    int total = 0;
    int count =0;
    for (int i = 1; i < N; i++) {
      if(S.charAt(i) == prev){
        count++;
      }else{
        total += count;
        count=0;
      }
      prev = S.charAt(i);
    }

      total += count;


    System.out.println(Math.min(total+2*K, S.length()-1));

  }



}

Measured memory_bytes: 28116
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC170A
{
    class Class1
    {
        static void Main(string[] args)
        {
            {
                string[] x = Console.ReadLine().Split(' ');
                for(int i = 0; i < 5; i++)
                {
                    if (x[i].ToString() == "0")
                    {
                        Console.WriteLine(i + 1);
                    }
                }
            }
        }
    }
}


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

int main()
{
	int n;
    cin>>n;
    
    int arr[n];
    int i;
    for( i=0;i<n;i++)
    {
        cin>>arr[i];
        int flag=0;
        if(arr[i]%2==0)
        {
            if(arr[i]%3==0)
            {
                flag=1;
            }
            if(arr[i]%5==0)
            {
                flag=1;
            }
            
            if(flag==0)
            {
                break;
            }
        }
    }
    if(i==n)
    {
        cout<<"APPROVED"<<endl;
        //cout<<i<<endl;
    }
    else
    {
        cout<<"DENIED"<<endl;
        //cout<<i<<endl;
    }
    
    
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	int N, M, K, a, ans = 0;
	cin >> N >> M;
	int A[40] = {};
	for (int i = 0; i < N; i++) {
		cin >> K;
		for (int j = 0; j < K; j++) {
			cin >> a;
			A[a]++;
		}
	}
	for (int l = 1; l <= M; l++) {
		if (A[l] == N) {
			ans++;
		}
	}


	cout << ans << endl;


}

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

int main() {
    int N;
    cin >> N;
    vector<int> x(N),y(N);
    rep(i,N)cin >> x[i] >> y[i];
    vector<vector<double>> dp(N,vector<double>(N));
    rep(i,N)rep(j,N)dp[i][j]=0;
    rep(i,N){
        rep(j,N){
            if (i != j) dp[i][j] = sqrt(pow(x[i] - x[j], 2) + pow(y[i] - y[j], 2));
        }
    }
    double sum = 0;
    int count = 0;
    rep(i,N){
        rep(j,N){
            if(i!=j){
                sum += (dp[i][j])*(N-1);
                count ++;
            }
        }
    }
    printf("%.10f", sum/count);

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdlib.h>
#include <vector> //vector
#include <algorithm> //sort()
#include <numeric>

#define rep(i, n) for(int i=0; i<(int)(n);i++)
#define all(x) (x).begin(), (x).end()
#define debug(a) cout << "debug (" #a "):" << endl << (a) << endl;

typedef uint64_t ulint;
typedef int64_t lint;

using namespace std;

template<class T> inline bool chmin(T& a, T b);
template<class T> inline bool chmax(T& a, T b);
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v);

template<class T> lint sum(vector<T> a);
template<class T> double ave(vector<T> a);

//uint64_t a, b, c, d;
//uint64_t i, j;
lint n, m;

int main(){
//////////////////////////////////////////////////////

    string s;
    cin >> s;
    int flag = 0;
    rep(i,4)
    {
        if(i>0)
        {
            if(s[i]==s[i-1])
            flag=1;

        }
    }

    if(flag==1)
    cout << "Bad" << endl;
    else
    {
        cout << "Good" << endl;
    }
    
   


// Ctrl + Opt + N to make
    return 0;
}


//最小化用関数
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;
}


// vectorprint用
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	int len = v.size();
	for (int i = 0; i < len; ++i) {
		s << v[i]; if (i < len - 1) s << "\t";
	}
	return s;
}

// //合計
// template<class T> lint sum(vector<T> a)
// {
//     return std::accumulate(a.begin(), a.end(), 0);
// }


// //平均
// template<class T> double ave(vector<T> a)
// {
//     return std::accumulate(a.begin(), a.end(), 0.0) / a.size();
// }


Measured memory_bytes: 256
N,M,X,Y=map(int,input().split())
xlist=list(map(int,input().split()))
ylist=list(map(int,input().split()))

max_x=max([X]+xlist)
min_y=min([Y]+ylist)
#print(max_x,min_y)
if max_x<min_y:
  print("No War")
else:
  print("War")

Measured memory_bytes: 3060
from collections import Counter
n = int(input())
A = sorted(list(map(int, input().split())))[-1::-1]
c = Counter(A)
ans = 0
for a in A:
    b = (1<<a.bit_length()) - a
    if a == b and c[a] > 1:
        c[a] -= 2
        ans += 1
    elif a != b and c[a] > 0 and c[b] > 0:
        c[a] -= 1
        c[b] -= 1
        ans += 1
print(ans)


Measured memory_bytes: 33604
#include <bits/stdc++.h>
using namespace std;
#define dhoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);  
typedef long long ll;
#define fi first
#define se second
#define sc scanf
#define pr printf
#define pb push_back
const ll inf = 1e18;
const int nax = 2e6 + 7;
const ll mod = 1e9 + 7;
using namespace std;
ll exp(ll a , ll b){
	if(b == 0)	return 1;
	int x = b % 2 == 0 ?   ((exp(a , b/2)%mod)*(exp(a , b / 2)%mod))%mod :  (a%mod*exp(a , b - 1) % mod)%mod;
	return x;
}
int parent[10005], size[10005];
void init(){
	for(int i = 0 ; i <= 10004 ; i++)
	{	
		parent[i] = i;
		size[i] = 1;
	}
}
int whoispar(int x){
		if(parent[x] == x)
			return x;
		return parent[x] =  whoispar(parent[x]);// path compression 
}
// union by size
void uni(int x , int y){
	int parX = whoispar(x);
	int parY = whoispar(y);
	if(parX != parY){
		if(size[parX] < size[parY])
				swap(parX , parY);
		parent[parY] = parX;
		size[parX] += size[parY];
	}
}
int main(int argc,char ** argv){
	dhoom;
	int n , q; 
	cin >> n >> q;
	init();
	for(int i = 0 ; i < q ; i++){
		int c , l , r;
		cin >> c >> l >> r;
		if(c == 0)
			uni(l , r);
		else
		{
			if(whoispar(l) == whoispar(r))
				cout << 1 << endl;
			else 
				cout << 0 << endl;
		}
	}
	return 0;
	
}



Measured memory_bytes: 3316
s = input()
k = int(input())
t = sorted(list(s))
num = []
while len(num) < k:
    a = t.pop(0)
    indexes = [i for i, x in enumerate(s) if x == a]
    z = 0
    while z < len(indexes):
        i = indexes[z]
        q = 1
        while q <= 5:
            if s[i:i + q] not in num:
                num.append(s[i:i + q])
            q += 1
        z += 1

num = sorted(num)
print(num[k - 1])

Measured memory_bytes: 3188
#include <stdio.h>

int main(void){

	int a, b;

	scanf("%d %d", &a, &b);

	if(a == b){
		printf("a == b\n");
	}else if(a < b){
		printf("a < b\n");
	}else{
		printf("a > b\n");
	}

	return 0;
}

Measured memory_bytes: 580
n,m,*t=map(int,open(0).read().split())
e=[[]for _ in range(n)]
for a,b in zip(*[iter(t)]*2):
  e[a-1]+=b-1,
  e[b-1]+=a-1,
o=[]
s=[0]
f=[1]*n
for v in s:
  o+=v,
  f[v]=0
  t=[]
  for w in e[v]:
    if f[w]:
      s+=w,
      t+=w,
  e[v]=t
dp1=[0]*n
c=[[]for _ in range(n)]
for v in o[::-1]:
  c1,c2=[1],[1]
  for w in e[v]:
    c1+=c1[-1]*(dp1[w]+1)%m,
  for w in e[v][::-1]:
    c2+=c2[-1]*(dp1[w]+1)%m,
  dp1[v]=c1[-1]
  c[v]=c1,c2[-2::-1]
dp2=[0]*n
dp2[0]=1
for v in o:
  t=dp2[v]
  for w,c1,c2 in zip(e[v],*c[v]):
    dp2[w]=(t*c1*c2+1)%m
for dp1,dp2 in zip(dp1,dp2):
  print(dp1*dp2%m)

Measured memory_bytes: 57740
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

using namespace std;

int main(){
	int n=0;
	string str;
	cin >> n;
	getline(cin,str);
	for(int i=0;i<n;i++){
		getline(cin,str);
		for(int j=0;j<str.size();j++){
			if(str[j] == 'H' && str[j+1] == 'o' && str[j+2] == 's' && str[j+3] == 'h' && str[j+4] == 'i' && str[j+5] == 'n' && str[j+6] == 'o'){
				str[j+6] = 'a';
			}
		}
		cout << str << endl;
	}
	return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n;i>=0;i--)
#define MAX 10001
#define B 100
#define dmp make_pair
#define dpb push_back
#define fi first
#define se second
#define P pair<int,int>
typedef long long ll;
const int inf = 1e9;
const ll INF = 1e18;
using namespace std;
//__gcd(a,b), __builtin_popcount(a);

struct edge{int to, cost;};
vector<edge> G[3001];
priority_queue<P, vector<P>, greater<P> > q;
int v[3001];

int main(){
	int n, m, k, a, b, l;
	scanf("%d%d%d", &n, &m, &k);
	fill(v, v+3001, inf);
	rep(i,m){
		scanf("%d%d%d", &a, &b, &l);
		G[a].push_back((edge){b, l});
		G[b].push_back((edge){a, l});
	}
	rep(i,k){
		scanf("%d", &a);
		v[a] = 0;
		q.push(dmp(0, a));
	}
	
	while(!q.empty()){
		P x = q.top();q.pop();
		if(v[x.se] < x.fi)continue;
		for(int i = 0;i < G[x.se].size();i++){
			int t1 = G[x.se][i].to, t2 = G[x.se][i].cost;
			if(v[t1] > v[x.se]+t2){
				v[t1] = v[x.se]+t2;
				q.push(dmp(v[t1], t1));
			}
		}
	}
	
	int ans = 0;
	for(int i = 1;i <= n;i++){
		for(int j = 0;j < G[i].size();j++){
			int x = v[i], y = v[G[i][j].to];
			ans = max(ans, (x+y+G[i][j].cost+1)/2);
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 5940
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int lli;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}

template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

int main() {
    int N, K;
    cin >> N >> K;
    int ans = N;
    if (N == K) {
        cout << 1 << endl;
        return 0;
    }
    REP(i, 0, N) {
        int a;
        cin >> a;
        if (a == 1) {
            REP(j, max(0, i - K + 1), i + 1) {
                //                dump(j);
                int f = max(0, N - j - K);
                //                dump(f);
                //                dump(max((j + K - 2) / (K - 1), 0));
                //                dump(max((f + K - 2) / (K - 1), 0));
                ans = min(ans, max((j + K - 2) / (K - 1), 0) + max((f + K - 2) / (K - 1), 0) + 1);
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

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

int main(){
  while(true){
    int n, m;
    cin>>n>>m;
    if(n==0&&m==0)break;
    int ssum=0, tsum=0;
    vector<int> s, t;
    rep(i,n){int tmp; cin>>tmp; s.push_back(tmp); ssum+=tmp;}
    rep(i,m){int tmp; cin>>tmp; t.push_back(tmp); tsum+=tmp;}
    int ans=INF, sc, tc;
    if((ssum+tsum)%2==0)
      rep(i,n)
        rep(j,m){
        if((ssum-tsum)/2==(s[i]-t[j]) && ans>(s[i]+t[j])){ans=(s[i]+t[j]); sc=s[i]; tc=t[j];}
      }
    if(ans==INF)cout<<"-1"<<endl;
    else cout<<sc<<" "<<tc<<endl;
  }
  return 0;
}

Measured memory_bytes: 1220
#include<cstdio>
#include<algorithm>
using namespace std;
inline long long read()
{
	char ch=getchar(); long long ans=0;
	while (ch<'0'||ch>'9') ch=getchar();
	while (ch<='9'&&ch>='0') ans=ans*10+ch-48,ch=getchar();
	return ans;
}
long long gcd(long long a,long long b)
{
	if (b==0) return a;
	return gcd(b,a%b);
}
int main()
{
	int cas=read();
	while (cas--)
	{
		long long a=read(),b=read(),c=read(),d=read();
		if (a<b||d<b){puts("No"); continue;}
		if (c>=b){puts("Yes"); continue;}
		long long x=gcd((d-b)%b,b); a%=x;
		if (a-c+(b-a-1)/x*x>=1) puts("No");
		else puts("Yes");
	}
	return 0;
}



Measured memory_bytes: 128
import math
input = input().split()
r = int(input[0])
g = int(input[1])
b = int(input[2])
N = int(input[3])
 
count = 0
# print(N/r)
# print(math.ceil(N/r))
for x in range(math.ceil(N/r+0.0001)):
    for y in range(math.ceil((N-x*r)/g + 0.0001)):
        # print(str(x), str(y))
        if  (N - x*r - y*g) % b == 0:
            count +=1
 
print(count)

Measured memory_bytes: 40300
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>

using namespace std;

int main()
{
    string s; 
    cin >> s; 
  	long long sum = 0;
    int length = s.length();
    for (int i = length - 1; i >=0; --i)
    {
        char c = s[i];
        sum += c - '0'; 
    }
    if (sum % 9 == 0)cout << "Yes" << endl; 
    else cout << "No" << endl; 
    

    return 0;
}


Measured memory_bytes: 3736
import sys
sys.setrecursionlimit(10**6) #再帰関数の上限
import math
#import queue
from copy import copy, deepcopy
from operator import itemgetter

from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)
#from collections import deque 
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
#dequeを使うときはpython3を使う、pypyはダメ
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
import heapq
#q=heapq.heapify(l),heappush(q,a),heappop(q)

def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds

#mod = 10**9+7

#N = int(input())
H, W = map(int, input().split())
c=[[] for i in range(10)]
for j in range(10):
    cj=list(map(int, input().split()))
    for i in range(10):
        c[i].append(cj[i])

#L = [int(input()) for i in range(N)]
#A = list(map(int, input().split()))
#S = [inputl() for i in range(H)]


#a= [[0]*3 for i in range(5)] #2次元配列はこう準備、[[0]*3]*5だとだめ
#b=copy.deepcopy(a)  #2次元配列はこうコピーする
#w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

#素数リスト
# n = 100
# primes = set(range(2, n+1))
# for i in range(2, int(n**0.5+1)):
#     primes.difference_update(range(i*2, n+1, i))
# primes=list(primes)

#bisect.bisect_left(a, 4)#aはソート済みである必要あり。aの中から4未満の位置を返す。rightだと以下
#bisect.insort_left(a, 4)#挿入

tdis=[10**5]*10
dis=0
#tdis[0]=0

q=[(0,1)]
#print(q)
heapq.heapify(q)
while len(q):
    #print(q)
    d, v=heapq.heappop(q)
    if tdis[v] <10**5:
        continue
    tdis[v]=d
    for i in range(10):
        heapq.heappush(q,(d+c[v][i],i))

ans=0
#print(tdis)
for i in range(H):
    A=list(map(int, input().split()))
    for j in range(W):
        if A[j]==-1:
            continue
        ans+=tdis[A[j]]
print(ans)


Measured memory_bytes: 40684
//#define DEB1 //input from input.txt
//#define NDEBUG
#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <thread>
#include <mutex>
#include <iomanip>
#include <cassert>

#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define INF(a) memset(a, 0x3f, sizeof(a))
#define ALL(t) (t).begin(),(t).end()
#define FILL(a,c) fill(a, a+ sizeof(a)/sizeof(*a),c)
#define FILL2D(A,c) fill(A[0], A[0] +sizeof(A)/sizeof(**A),c)
#define FILL3D(A,c) fill(A[0][0], A[0][0] +sizeof(A)/sizeof(***A),c)
#define REP(i,m) for(int i=0;i<(m);++i)
// closed interval, inverse repeat
#define CIREP(i,start,fin) for(int i=(start);i>=(fin);i--)
#define CREP(i,start,fin) for(int i=(start);i<=(fin);i++)
#define RNG(i,start,fin) for(int i=(start);i<(fin);i++)
#define IN(a, x, b) (a<=x && x<b)
#define PB push_back
#define SZ(x) (int)(x).size()

using namespace std;

using LL = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<LL,LL>;
using VI = vector<int>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VVI = vector<VI>;
const LL LINF = 1001002003004005006ll;
/* 
template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,SZ(v))i>>v[j];return i;}

template<typename T>string join(const vector<T>&v)
{stringstream s;REP(i,SZ(v))s<<' '<<v[i];return s.str().substr(1);}

template<typename T>inline ostream& operator<<(ostream&o,const vector<T>&v)
{if(SZ(v))o<<join(v);return o;}
*/

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




/*
constant values
*/

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

//const ll INF= 1LL<<60 ;//INF = 1001001001001; //1e9


// Main program
void solve(){
    //cout << "Hello world" << endl;
    int N,K,R,S,P;
    cin >> N >> K >> R >> S >> P;
    string T;
    cin >> T;
    cerr << "T size=" << T.size();
    VI flag;

    REP(i,N) flag.PB(0);

    LL sum;
    int v;
    sum = 0;
    REP(i, N){
        if(T[i]=='r') v = P;
        if(T[i]=='s') v = R;
        if(T[i]=='p') v = S;
        if(i<K){
            sum += v;
            continue;
        }
        if(T[i-K]==T[i] && flag[i-K]==0){
            flag[i]=1;
            continue;
        }
        sum +=v;
    }
    cout << sum << endl;
    return;
}



// ----------------------------------------------
int main(){

#ifdef DEB1
    cout << "DEBUG MODE"  << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf()); //for debug
#endif

    int T=1; 

    for (int i = 0; i < T; ++i) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 1020
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define db(x) (cerr << #x << ": " << (x) << '\n')
#define cps CLOCKS_PER_SEC
#define tests(t) int t; cin >> t; while(t--)
#define iceil(n, x) (((n) + (x) - 1) / (x))
#define eb emplace_back
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define sz size()
#define all(v) (v).begin(), (v).end()
#define uni(v) sort(all(v)), (v).erase(unique(all(v)), (v).end())
#define fi first
#define se second
#define bitcount(x) __builtin_popcount(x)
#define bit(x) (1LL << x)
#define PI acos(-1.0)
#define EPS 1e-9

#define mod 1000000007
#define maxn 2005

using namespace std;

using namespace __gnu_pbds;
template<class key, class cmp = std::less<key>>
using ordered_set = tree<key, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
///All indexing is 0-based
///methods: find_by_order(k); & order_of_key(k);
///To make it an ordered_multiset, use pairs of (value, time_of_insertion)
///to distinguish values which are similar

typedef long long ll;
typedef double ld;
typedef pair<ll, ll> par;



int main()
{
    #ifdef acm
    freopen("a.in","r",stdin);
    #endif // acm
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int N,M;
    cin >> N >> M;
    if(N > M)
        swap(N,M);
    for(int i=1;i<=M;i++)
        cout << N;







}



Measured memory_bytes: 256
N, M = map(int, input().split())
L = []
H = []
for i in range(N):
  A = list(map(int, input().split()))
  L.append(A[1:])
for i in range(1, M + 1):
  count = 0
  for B in L:
    if i in B:
      count += 1
  if count == N:
    H.append(i)
print(len(H))
   
    
  

Measured memory_bytes: 3060
#include<cstdio>
#include<iostream>
#include<map>
#include<set>
#include<vector>
#include<cstring>
#include<cassert>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<limits>
#include<ctime>
#include<stack>
#include<bits/stdc++.h>
#include<string>
#include<stdlib.h>
#include<stdio.h>
#define long long

using namespace std;

int main() {
	int a[26]={0};
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++){
		a[s[i]-'a']++;
	}
	bool y=true;
	for(int i=0;i<26;i++){
		if(a[i]%2!=0){
			y=false;
		}
	}
	if(y){
		cout<<"Yes";
	}
	else{
		cout<<"No";
	}
}


Measured memory_bytes: 3548
#include <iostream>
#include <string.h>
using namespace std;
#include <iostream>
using namespace std;
bool isKaibun(char *s)
{
	char revS[10];
	int sLen=strlen(s);
	int j=0;
	int i=0;
	for (i=sLen-1;i>=0;i--){
		revS[j++]=s[i];
	}
	revS[j]='\0';
	if (!strcmp(s,revS)){
		return true;
	}
	return false;

}
int main(int argc, char* argv[])
{
	char s[10];
	int A,B;
	cin>>A>>B;
	int i;
	int aw=0;
	for (i=A;i<=B;i++){
		sprintf(s,"%d",i);
		if (isKaibun(s)){
			aw++;
		}
	}
	cout<<aw<<endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
a = [-1]+list(map(int,input().split()))
b = [0]*(N+1)
for i in range(N,0,-1):
    su = 0
    j = 2
    while i*j <= N:
        su += b[i*j]
        j+=1
    b[i] = (a[i]+su)%2

if sum(b)>0:
    print(sum(b))
else:
    print(0)
    exit()

ans =[]
for i in range(1,N+1,1):
    if b[i]==1:
        ans.append(i)
print(*ans)

Measured memory_bytes: 14124
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}

//vector<ll> a;
deque<ll> a;

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

  ll n;
  cin >> n;
  REP(i,n*3) {
    ll x; cin >> x;
    a.push_back(x);
  }
  sort(a.begin(), a.end());
  ll ans = 0LL;
  while(!a.empty()){
    a.pop_front();
    a.pop_back();
    ans += a.back();
    a.pop_back();
  }
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 2688