akhauriyash/Code-Regression huggingface dataset:
def gcd(xxx,yyy):
    if xxx<yyy:
        xxx,yyy=yyy,xxx
    if yyy==0:
        return xxx
    else:
        return gcd(yyy,xxx%yyy)

def seg_tree_update(n,x):
    ind=2**m-1+n
    tree[ind]=x
    ind=(ind-1)//2
    while ind>=0:
        tree[ind]=gcd(tree[2*ind+1],tree[2*ind+2])
        ind=(ind-1)//2

def seg_tree_find_gcd(L,R):
    qqq=A[L]
    L,R=2**m-1+L,2**m-1+R
    while L<R:
        if L%2==0:
            qqq=gcd(qqq,tree[L])
        if R%2==1:
            qqq=gcd(qqq,tree[R])
        L//=2
        R=R//2-1
        
    if L==R:
        qqq=gcd(qqq,tree[L])
    return qqq

N=int(input())
A=list(map(int,input().split()))
inf=float("inf")
m=0
while pow(2,m)<N:
    m+=1
tree=[0]*(pow(2,m+1)-1)

for i in range(N):
    seg_tree_update(i,A[i])
    
ans=max(seg_tree_find_gcd(1,N-1),seg_tree_find_gcd(0,N-2))
for i in range(1,N-1):
    ddd=gcd(seg_tree_find_gcd(0,i-1),seg_tree_find_gcd(i+1,N-1))
    ans=max(ans,ddd)
print(ans)

Measured memory_bytes: 126344
#include<iostream>
#include<string>
#include<cstdio>
#include<set>
#include<algorithm>
#include<vector>
#include<string.h>
#include<map>
using namespace std;
int cnt[51];

int main(){
   int n, m;
   while(cin >> n >>m){
        memset(cnt, 0, sizeof(cnt));
        for(int i = 0; i <m; ++i){
                int p, q;
                cin >> p >> q;
                cnt[p]++;
                cnt[q]++;
        }
        for(int i = 1; i <= n; ++i){
            cout << cnt[i]<<endl;
        }
   }

    return 0;
}


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

using namespace __gnu_pbds;
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

#define mp make_pair
#define pb push_back
#define pf push_front
#define ss second
#define ff first
#define sz(x) (int)x.size()
#define newl "\n"
#define vi vector<int>
#define pii pair<int, int>
#define vii vector<pii>
#define vl vector<ll>
#define pll pair<ll, ll>
#define vll vector<pll>
#define coutp cout << fixed << setprecision(12)
#define mem(x, val) memset(x, val, sizeof(x))
#define fastio                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define all(v) (v).begin(), (v).end()

const ld pi = 3.14159265359;
ll INF = 1e18 + 10;
ll MOD = 998244353;
ll mod = 1e9 + 9;

inline ll add(ll a, ll b, ll m)
{
    if ((a + b) >= m)
        return (a + b) % m;
    return a + b;
}

inline ll mul(ll a, ll b, ll m)
{
    if ((a * b) < m)
        return a * b;
    return (a * b) % m;
}

ll power(ll x, ll y, ll m)
{
    ll res = 1;
    x = x % m;
    if (x == 0)
        return 0;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % m;
        y = y >> 1;
        x = (x * x) % m;
    }
    return res;
}

void solve() 
{
    ld a,b,c;
    cin>>a>>b>>c;
    ld val = a/c;
    if(val<=b) cout<<"Yes";
    else cout<<"No";
        
}

int main()
{
    fastio;
    int t;

    t = 1;
    //cin >> t;
    //int test=t;
    while (t-- > 0)
    {
        //cout<<"Case #"<<(test-t)<<": ";
        solve();
        cout << newl;
    }

    return 0;
}

Measured memory_bytes: 3740
#include <bits/stdc++.h>
#define ctz __builtin_ctz
#define EB emplace_back

typedef std::pair <int, int> pr;
typedef std::vector <pr> vector;
const int N = 24, N2 = 524354, mod = 1000000007;

int L, n, q, ALL;
int mask0[N], mask1[N], f[N2];
vector mdf[N];

inline void add(int &x, const int y) {x += y - mod, x += x >> 31 & mod;}

int main() {
	int i, j, c, S;
	scanf("%d%d%d", &L, &n, &q), ALL = ~(-1 << --L);
	for (; q; --q) scanf("%d%d%d", &i, &j, &c), (c ? mask1 : mask0)[--i] |= 1 << (L - j);
	for (i = 0; i <= ALL; ++i)
		for (c = 0, S = i & ((ALL & ~i) >> 1); S; S &= S - 1, ++c)
			 mdf[c].EB(i, i ^ ((S & -S) * 3));
	for (*f = 1, i = 0; i < n; ++i) {
		for (j = 0; j < ALL; ++j) add(f[j | (j + 1)], f[j]);
		for (c = 0; c < L; ++c) for (const pr e : mdf[c]) add(f[e.second], f[e.first]);
		for (j = 0; j <= ALL; ++j) if ((j & mask0[i]) | (~j & mask1[i])) f[j] = 0;
	}
	printf("%d\n", int(std::accumulate(f, f + (ALL + 1), 0ll) % mod));
	return 0;
}

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

struct RSQ {
	using type = ll;
	static type id1() { return 0; }
	static type id2() { return 0; }
	static type op1(const type& l, const type & r) { return l + r; }
	static type op2(const type& l, const type & r) { return l + r; }
};

template <typename M>
class LazySegmentTree {
	using T = typename M::type;
	const int n;
	vector<T> data, lazy;
	int size(int n) {
		int res = 1;
		while (res < n) res <<= 1;
		return res;
	}
	T get(int node, int lb, int ub) {
		return M::op2(data[node], lazy[node] * (ub - lb));
	}
	void push(int node, int lb, int ub) {
		if (lazy[node] == M::id2()) return;
		if (node < n) {
			lazy[node * 2] = M::op2(lazy[node * 2], lazy[node]);
			lazy[node * 2 + 1] = M::op2(lazy[node * 2 + 1], lazy[node]);
		}
		data[node] = get(node, lb, ub);
		lazy[node] = M::id2();
	}
	void suc(int l, int r, int node, int lb, int ub, T val) {
		if (ub <= l || r <= lb) return;
		push(node, lb, ub);
		if (l <= lb && ub <= r) {
			lazy[node] = val;
			return;
		}
		int c = (lb + ub) / 2;
		suc(l, r, node * 2, lb, c, val);
		suc(l, r, node * 2 + 1, c, ub, val);
		data[node] = M::op1(get(node * 2, lb, c), get(node * 2 + 1, c, ub));
	}
	T sub(int l, int r, int node, int lb, int ub) {
		if (ub <= l || r <= lb) return M::id1();
		push(node, lb, ub);
		if (l <= lb && ub <= r) return data[node];
		int c = (lb + ub) / 2;
		return M::op1(sub(l, r, node * 2, lb, c), sub(l, r, node * 2 + 1, c, ub));
	}
public:
	LazySegmentTree(int n_) : n(size(n_)), data(n * 2, M::id1()), lazy(n * 2, M::id2()) {}
	void update(int l, int r, T val) {
		suc(l, r + 1, 1, 0, n, val);
	}
	T find(int l, int r) {
		return sub(l, r + 1, 1, 0, n);
	}
};

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int n, q;
	cin >> n >> q;
	LazySegmentTree<RSQ> lst(n);
	for (int i = 0, type, s, t, x; i < q; i++) {
		cin >> type >> s >> t; s--; t--;
		if (type) {
			printf("%lld\n", lst.find(s, t));
		}
		else {
			cin >> x;
			lst.update(s, t, x);
		}
	}
	return 0;
}

Measured memory_bytes: 7080
#include <stdio.h>

int main(void) {
	int i,ii,a,b,c,sum,yen,w;
	while(scanf("%d",&ii) , ii != 0){
		yen = 0;
		for(i = 1;i <= ii;i++){
			scanf("%d%d%d%d",&a,&b,&c,&w);
			sum = a + b + c;
			if (sum <= 60 && w <= 2){
				yen = yen + 600;
			}
			else if (sum <= 80 && w <= 5){
				yen = yen + 800;
			}
			else if (sum <= 100 && w <= 10){
				yen = yen + 1000;
			}
			else if (sum <= 120 && w <= 15){
				yen = yen + 1200;
			}
			else if (sum <= 140 && w <= 20){
				yen = yen + 1400;
			}
			else if (sum <= 160 && w <= 25){
				yen = yen + 1600;
			}
		}
		printf ("%d\n",yen);
	}
	return 0;
}
//aoj 0160

Measured memory_bytes: 600
<?php
fscanf(STDIN, '%d %d %d', $n, $a, $b);
 
$sum = $a + $b;
$fraction = $n % $sum;
$count = (int)floor($n / $sum);
$result = $count * $a;
 
 
if ($a >= $fraction) {
  $result += $fraction;
} else {
  $result += $a;
}
 
echo $result;

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

using namespace std;
#define ll long long


int main() {
    int n;
    cin >> n;
    pair<int, int> p[n];
    for (int i = 0; i < n; i++) {
        cin >> p[i].first >> p[i].second;
    }
    sort(p,p+n);
    for (int i = 0; i < n; i++) {
        cout << p[i].first << " " << p[i].second << endl;
    }

    return 0;
}


Measured memory_bytes: 3884
N=int(input())
A=[input() for _ in range(N)]
M=int(input())
b=list(set(A))
z=0
k=0
B=[input() for _ in range(M)]
c=list(set(B))
for j in range(len(b)):
    k=A.count(b[j])-B.count(b[j])
    z=max(0,z,k)
print(z)

Measured memory_bytes: 3064
X,Y=map(int,input().split())
d=Y-X
k= Y // X
if k <= 1:
  print(1)
  exit(0)
count=1
while(1):
  if k < 2**count:
    break
  elif k ==2**count:
    count+=1
    break
  else:
    count+=1
print(count)


Measured memory_bytes: 2940
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
//#include <regex>

/* g++ -g -std=c++0x */
/* g++ -g -std=c++11 */

using namespace std;

// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

int main()
{
/* #ifndef ONLINE_JUDGE */
/*     freopen("foo", "rt", stdin); */
/* #endif */
    std::ios::sync_with_stdio(false);

    int h, w;
    while (cin >> h >> w) {
        string a[h];
        FOR(i,0,h) {
            cin >> a[i];
            cout << a[i] << endl << a[i] << endl;
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
const int INF=1001001001;
int main(){
  int n,m;
  cin>>n>>m;
  vector<pair<int,int>>key;
  rep(i,m){
    int a,b;
    cin>>a>>b;
    int s=0;
    rep(j,b){
      int c;
      cin>>c;
      --c;
      s|=1<<c;
    }
    key.emplace_back(s,a);
  }
  
  vector<int> dp(1<<n,INF);
  dp[0]=0;
  rep(s,1<<n){
    rep(i,m){
      int t=s | key[i].first;
      int cost = dp[s]+key[i].second;
      dp[t]=min(dp[t],cost);
    }
  }
  int ans=dp.back();
  if (ans==INF) ans=-1;  
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long       ll;
#define MOD ((int)1e9+7)
#define N ((int)1e5+123)
void reads(string& x){ char kk[N]; scanf("%s",kk); x = kk;}

ll x,y,a,b,c,A[N],B[N],C[N], ans;
priority_queue<ll> pa,pb;
void solve(){
    scanf("%lld%lld%lld%lld%lld", &x,&y,&a,&b,&c);
    for(int i=0;i<a;i++){
        scanf("%lld",&A[i]);
    }
    for(int i=0;i<b;i++){
        scanf("%lld",&B[i]);
    }
    for(int i=0;i<c;i++){
        scanf("%lld",&C[i]);
    }
    sort(A,A+a,greater<ll>());
    sort(B,B+b,greater<ll>());
    sort(C,C+c,greater<ll>());

    for(int i=0;i<x;i++){
        pa.emplace(-A[i]);
    }
    for(int i=0;i<y;i++){
        pb.emplace(-B[i]);
    }
    for(int i=0;i<c;i++){
        if(-pa.top()<-pb.top()){
            if(C[i]>-pa.top()){
                pa.pop();
                pa.emplace(-C[i]);
            }
            else break;
        }
        else{
            if(C[i]>-pb.top()){
                pb.pop();
                pb.emplace(-C[i]);
            }
            else break;
        }
    }
    while(!pa.empty()){
        ans-=pa.top();
        pa.pop();
    }
    while(!pb.empty()){
        ans-=pb.top();
        pb.pop();
    }
    printf("%lld\n",ans);
}

int main(){
    ios_base::sync_with_stdio(0);
    int t = 1; //scanf("%d",&t);
    for(int caso=1;caso<=t;caso++){
        solve();
    }
}

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

int main() {
  string S; 
  cin>>S;
  int lgt;
  
  while(lgt==0){
    S.pop_back();
    S.pop_back();//末尾2文字を消す
    rep(i,S.size()/2){
      if(S[i]!=S[i+S.size()/2])break;
      else if(i==S.size()/2-1) lgt=S.size();
    }
  }
  cout<<lgt<<endl;
  return 0;
}

Measured memory_bytes: 256
n = int(input())
s = input()
nb = s.count('#')
nw = s.count('.')
if nw == n or nb == n:
    print(0)
    exit()
lb = 0
rw = nw

b = False
ans = float('inf')
for i in range(n):
    if b == False and s[i] == '#':
        ans = min(ans, lb + rw)
        b = True
        lb += 1
    elif s[i] == '#':
        lb += 1
    elif s[i] == '.':
        rw -= 1
        b = False
ans = min(ans, nb)
print(ans)

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

using namespace std;
using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define rep(i, N) for (ll i = 0; i < (N); i++)
#define FOR(i, a, b) for (ll i = (a), i < (N): i++)
#define all(A) (A).begin(), (A).end()

int main(){
    int N;
    cin >> N;
    int V[N];
    rep(i, N) cin >> V[i];
    vector<pii> A(1e5 + 10), B(1e5+10);
    rep(i, 1e5+10) {
        A[i].first = 0;
        B[i].first = 0;
        A[i].second = i;
        B[i].second = i;
    }
    rep(i, N) {
        if (i % 2 == 0) {
            A[V[i]].first++;
        }
        else B[V[i]].first++;
    }

    sort(all(A), [](pii a, pii b) {return a.first > b.first;});
    sort(all(B), [](pii a, pii b) {return a.first > b.first;});

    int ans = 0;
    if (A[0].second == B[0].second) {
        ans = N - max(A[0].first + B[1].first, A[1].first + B[0].first);
    }
    else ans = N - A[0].first - B[0].first;

    cout << ans << endl;

    return 0;
}


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

#define ll long long
int main() {
	
	string s,t;
	cin>>s>>t;
	int n = t.size();
	char ch = t[n-1];
	if((s+ch)!=t) cout<<"No\n";
	else cout<<"Yes\n";
	
	return 0;
}

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

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

    int n;
    cin >> n;
    vector<vector<int>> cnt(10, vector<int>(10));
    for (int a = 1; a <= n; a++) {
        string s = to_string(a);
        int x = s[0] - '0';
        int y = s[s.size() - 1] - '0';
        cnt[x][y]++;
    }

    long long res = 0;
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            res += (long long)cnt[i][j] * (long long)cnt[j][i];
        }
    }

    cout << res << "\n";

    return 0;
}


Measured memory_bytes: 256
//template code, C343, 2019
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Iterator;

class Graph {
	private int totalVertex;
	private LinkedList<LinkedList<Integer>> adjList;
	//adjacency list of edges
	public Graph() { totalVertex = 0; }
	public void loadAdjList() {
		Scanner in = new Scanner(System.in);
		totalVertex = in.nextInt();
		adjList = new LinkedList<LinkedList<Integer>>();
		for(int i = 0; i < totalVertex; i ++) {
			LinkedList<Integer> tmp = new LinkedList<Integer>();
			int idx1 = in.nextInt() - 1;
			int degree = in.nextInt();
			//System.out.println("mark idx1 = " + idx1 + " degree = " + degree);
			for(int j = 0; j < degree; j ++) {
				int idx2 = in.nextInt() - 1;
				tmp.add(idx2);
			}	
			adjList.add(tmp);
		}
		in.close();
	}
	public void printAdjMatrix() {
		Integer[][] adjMatrix = new Integer[totalVertex][totalVertex];
		//complete the following
		for(int i = 0; i < totalVertex; i++) {
			for(int j = 0; j < totalVertex; j++) {
				adjMatrix[i][j] = 0;
			}
		}
		for(int i = 0; i < totalVertex; i++) {
			for(int j = 0; j < adjList.get(i).size(); j++) {
					adjMatrix[i][adjList.get(i).get(j)] = 1;
			}
		}
		for(int i = 0; i < totalVertex; i++) {
			for(int j = 0; j < totalVertex - 1; j++) {
				System.out.print(adjMatrix[i][j] + " ");
			}
			System.out.println(adjMatrix[i][totalVertex - 1]);
		}
	}
}

//change class name GraphRepresentation to Main() for submission to AIZU
public class Main {
	public static void main(String argv[]) {
		Graph g = new Graph();
		g.loadAdjList();
		g.printAdjMatrix();
	}
}



Measured memory_bytes: 32420
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>

using namespace std;

typedef long long tnum;

#define min(a,b) (a <= n ? a : n)
#define max(a,b) (a <= n ? a : n)

char* result;
int p = 0;
tnum k;
bool ex = 0;
int targetdigit = 0;

void re(char cur, int digit) {
	result[digit] = cur + '0';
	if (digit == targetdigit) {
		p++;
		if (p == k) {
			ex = 1;
		}
		return;
	}

	if (cur > 0) {
		re(cur - 1, digit + 1);
	}
	if (ex) return;
	re(cur, digit + 1);
	if (ex) return;
	if (cur < 9) {
		re(cur + 1, digit + 1);
	}
	if (ex) return;
}



int main() {
	
	tnum* a;
	scanf("%lld", &k);

	for (targetdigit = 0; targetdigit < 20; targetdigit++) {
		result = (char*)calloc(22, 1);
		for (int i = 1; i <= 9; i++) {
			ex = 0;
			re(i, 0);
			if (ex) {
				printf("%s", result);
				return 0;
			}
		}
	}
	

	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int ordena(const void*a,const void*b){
    int x = *((int *)a); int y = *((int *)b);
    if(x<y)
        return -1;
    if(x>y)
        return 1;
    return 0;
}
int main(){
    int n,total=0;
    scanf("%d",&n);
    int a[n];
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        total+= a[i];
    }
    qsort(a,n,sizeof(a[0]),ordena);
    int val = a[n/2]-a[n/2 - 1];
    printf("%d\n",val);

    return 0;
}


Measured memory_bytes: 892
//g++ -std=c++14 test.cpp -o test.out
//入出力：http://kaitei.net/cpp/iostream/
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
using namespace std;

int A;
int B;
int ans;

void solve(){
	if(A==1){
		if(B==2) ans = 3;
		if(B==3) ans = 2;
	}
	if(A==2){
		if(B==1) ans = 3;
		if(B==3) ans = 1;
	}
	if(A==3){
		if(B==1) ans = 2;
		if(B==2) ans = 1;
	}
}

int main(){
	cin >> A >>B;

	solve();

	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <stack>
#include <set>
#include <map>
#include <math.h>
#include <queue>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define rev(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = INT_MAX;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ O(logN)
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//



int main() {

    ll n;
    cin >> n;
    vector <ll> l(n);
    rep(i,n) cin >> l[i];
    Sort(l);

    ll ans = 0;
    for (int i = 0; i < n - 1; ++i) {
        for (int j = i + 1; j < n; ++j) {
            int two = l[i] + l[j];
            auto itr = lower_bound(l.begin(), l.end(), two);
            int dis = distance(l.begin(), itr);
            ans += dis - j - 1;
        }
    }

    out(ans);


    return 0;
}








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

using namespace std;

constexpr int MAX = (1 << 23);

class RMQ2D {
  public:
    int H, W;
    int dat[MAX];    

    int c(int i, int j)
    {
        return i * (2 * W - 1) + j;
    }
    
    void init(int h, int w, vector<int>& grid)
    {        
        H = 1;
        while (H < h) H *= 2;
        W = 1;
        while (W < w) W *= 2;
        
        for (int i = 0; i < 2 * H - 1; i++) {        
            for (int j = 0; j < 2 * W - 1; j++) {
                dat[c(i, j)] = INT_MAX;
            }
        }

        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                dat[c(i + H - 1, j + W - 1)] = grid[i * w + j];
            }
        }
        
        for (int i = 2 * H - 2; i >= 0; i--) {
            for (int j = W - 2; j >= 0; j--) {
                dat[c(i, j)] = min(dat[c(i, j * 2 + 1)],
                                   dat[c(i, j * 2 + 2)]);
            }
        }

        for (int i = 2 * W - 2; i >= 0; i--) {
            for (int j = H - 2; j >= 0; j--) {
                dat[c(j, i)] = min(dat[c(j * 2 + 1, i)],
                                   dat[c(j * 2 + 2, i)]);
            }
        }
    }

    int query_h(int h1, int w1, int h2, int w2, int k, int l, int r)
    {
        if (r <= h1 || h2 <= l) return INT_MAX;
        if (h1 <= l && r <= h2) return query_w(w1, w2, k, 0, 0, W);
        int vl = query_h(h1, w1, h2, w2, k * 2 + 1, l, (l + r) / 2);
        int vr = query_h(h1, w1, h2, w2, k * 2 + 2, (l + r) / 2, r);
        return min(vl, vr);
    }

    int query_w(int w1, int w2, int j, int k, int l, int r)
    {
        if (r <= w1 || w2 <= l) return INT_MAX;
        if (w1 <= l && r <= w2) return dat[c(j, k)];
        int vl = query_w(w1, w2, j, k * 2 + 1, l, (l + r) / 2);
        int vr = query_w(w1, w2, j, k * 2 + 2, (l + r) / 2, r);
        return min(vl, vr);
    }

    int query(int h1, int w1, int h2, int w2)
    {
        return query_h(h1, w1, h2 + 1, w2 + 1, 0, 0, H);
    }
};

RMQ2D r;

int main()
{
    int H, W, Q;
    while (std::cin >> H >> W >> Q, H) {
        vector<int> grid(H * W);
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                cin >> grid[i * W + j];
            }
        }
        r.init(H, W, grid);
        for (int i = 0; i < Q; i++) {
            int y1, x1, y2, x2;
            cin >> y1 >> x1 >> y2 >> x2;
            cout << r.query(y1, x1, y2, x2) << endl;
        }
    }       
    return 0;
}

Measured memory_bytes: 39168
#include <bits/stdc++.h>
using namespace std;
const unsigned int M = 1000000007;
#define ll long long
int main() {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int k, n;
    while(cin>>n>>k){
        n*500>=k?cout<<"Yes"<<endl:cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
// #include <algorithm>
// #include <map>
// #include <set>
// #include <cmath>

using namespace std;
typedef unsigned long long ull;


int main(int argc, char const *argv[]) {
    ull x;
    cin >> x;
    ull ans = (x / 11) * 2;
    ull res = x % 11;
    if (res > 0 && res <= 6) {
        ans += 1;
    } else if (res > 0) {
        ans += 2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=int64_t;
using vi=vector<int>;
using vll=vector<ll>;
int main() {
  ll n,q,a,b,c,i,k,s=0;
  cin>>n;
  map<ll,ll> m;
  for(i=0;i<n;i++){
    cin>>a;
    if(m.count(a)) m.at(a)++;
    else m[a]=1;
    s+=a;
  }
  cin>>q;
  for(i=0;i<q;i++){
    cin>>b>>c;
    if(m.count(b)){
      k=m.at(b);
      m.erase(b);
      s+=(c-b)*k;
      if(m.count(c)) m.at(c)+=k;
      else m[c]=k;
    }
    cout<<s<<endl;
  }
}

Measured memory_bytes: 7544
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define RFOR(i,a,b) for(int i = (int)(b-1);i>=(int)(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

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

  string x;
  cin >> x;

  int pointer = 0;
  int ans = 0;
  REP(i, x.length()){
    if(x[i] == 'S'){
      pointer++;
    }
    else if(x[i] == 'T'){
      if(pointer != 0) {
        pointer--;
        ans++;
      }
    }
  }

  cout << x.length() - ans * 2 << endl;

  return 0;
}

Measured memory_bytes: 720
import std.stdio, std.string, std.conv;
import std.typecons;
import std.algorithm, std.array, std.range, std.container;
import std.math;

void main() {
	auto data = readln.split.to!(int[]);
	auto A = data[0], B = data[1], C = data[2];
	if (A+B >= C-1) writeln(B+C);
	else writeln( B + A+B+1 );
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>

int main() {
    int n;
    int from_num, num; 
    std::cin >> n;
    std::vector<std::vector<int>> vec(n, std::vector<int>(n, 0));
    for (int i = 0; i < n; i++) {
        std::cin >> from_num;
        std::cin >> num;
        int node_num;
        for (int p = 0; p < num; p++) {
            std::cin >> node_num;
            vec[from_num-1][node_num-1] = 1;
        }
    }
    for (int i = 0; i < n; i++) {
        for (int p = 0; p < n; p++) {
            std::cout << vec[i][p];
            if (p == n - 1) {
                std::cout << std::endl;
            }
            else {
                std::cout << " ";
            }
        }
    }
}



Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll n;
	cin>>n;
	ll N=sqrt(n),ans[100010]={};
	for(int x=1;x<=N;x++){
		for(int y=1;y<=N;y++){
			for(int z=1;z<=N;z++){
				ans[x*x+y*y+z*z+x*y+x*z+y*z]++;
			}
		}
	}
	for(int i=1;i<=n;i++)cout<<ans[i]<<endl;
	return 0;
}


Measured memory_bytes: 4320
s = [i for i in range(1, 14)]
h = [i for i in range(1, 14)]
c = [i for i in range(1, 14)]
d = [i for i in range(1, 14)]

n = int(input())
for i in range(n):
    line = input().split()
    if line[0] == "S":
        s.remove(int(line[1]))
    elif line[0] == "H":
        h.remove(int(line[1]))
    elif line[0] == "C":
        c.remove(int(line[1]))
    elif line[0] == "D":
        d.remove(int(line[1]))
for i in s:
    print("S"+" "+str(i))
for i in h:
    print("H"+" "+str(i))
for i in c:
    print("C"+" "+str(i))
for i in d:
    print("D"+" "+str(i))
    


Measured memory_bytes: 5612
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
			int n = sc.nextInt();
			if(n == 0) break;
			int[] c = new int[n];
			for(int i = 0; i < n; i++) {
				c[i] = sc.nextInt();
			}
			ArrayDeque<Data> stack = new ArrayDeque<Data>();
			stack.push(new Data(c[0],1));
			for(int i = 1; i < n; i++) {
				if((i+1) % 2 == 0) {
					if(stack.peek().color == c[i]) {
						Data tmp = stack.pop();
						tmp.count++;
						stack.push(tmp);
					}
					else {
						Data tmp = stack.pop();
						tmp.color = c[i];
						tmp.count++;
						if(!stack.isEmpty())
						tmp.count += stack.pop().count;
						stack.push(tmp);
					}
				}
				else {
					if(stack.peek().color == c[i]) {
						Data tmp = stack.pop();
						tmp.count++;
						stack.push(tmp);
					}
					else {
						stack.push(new Data(c[i],1));
					}
				}
			}
			int sum = 0;
			while(!stack.isEmpty()) {
				if(stack.peek().color == 0) sum += stack.pop().count;
				else stack.pop();
			}
			System.out.println(sum);
		}
		
	}
	static class Data {
		int color;
		int count;
		Data(int a, int b) {
			color = a;
			count = b;
		}
	}

	
}

Measured memory_bytes: 64196
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Range(container) container.begin(), container.end()
#define Cin(T, x) T x; cin >> x;
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i];
#define Cout(val) cout << (val) << "\n";
using namespace std;
using ll = long long;

int main(void){
    Cin(int, a);
    Cin(int, b);
    Cin(int, c);
    Cin(int, d);
    Cout((a-1)*(b-1));
}

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

const int MAX_N = 100;
const int WHITE = -1;
const int GRAY = -2;
const int BLACK = -3;

int n;
int color[MAX_N];
bool adj[MAX_N][MAX_N];
int d[MAX_N], f[MAX_N];

int t;

void dfs(int u) {
    color[u] = GRAY;
    d[u] = ++t;
    for (int v = 0; v < n; v++) {
        if (adj[u][v] && color[v] == WHITE) {
            dfs(v);
        }
    }
    color[u] = BLACK;
    f[u] = ++t;
}

void dfs_init(void) {
    t = 0;
    for (int i = 0; i < n; i++) {
        color[i] = WHITE;
    }
    for (int i = 0; i < n; i++) {
        if (color[i] == WHITE) {
            dfs(i);
        }
    }
}

int main(void) {
    cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            adj[i][j] = false;
        }
    }
    for (int i = 0; i < n; i++) {
        int u, k; cin >> u >> k;
        for (int j = 0; j < k; j++) {
            int v; cin >> v;
            adj[u-1][v-1] = true;
        }
    }

    dfs_init();

    for (int i = 0; i < n; i++) {
        cout << i+1 << " " << d[i] << " " << f[i] << endl;
    }

    return 0;
}

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

using namespace std;

typedef long long ll;

const int INF = 1000000000;
const ll MOD = 1000000007;

int main()
{
  int N; scanf("%d", &N);
  string s, t;
  cin >> s >> t;
  ll ans = (s[0] == t[0]) ? 3 : 6;
  // 0: vertical
  // 1: horizontal
  int prev = (s[0] == t[0]) ? 0 : 1;
  for (int i = prev + 1; i < N; ) {
    if (s[i] == t[i]) {
      // => vertical
      if (prev == 0) {
        // vertical => vertical
        ans *= 2;
      }
      else {
        // horizontal => vertical
        prev = 0;
      }
      ++i;
    }
    else {
      // => horizontal
      if (prev == 0) {
        // vertical => horizontal
        ans *= 2;
        prev = 1;
      }
      else {
        // horizontal => horizontal
        ans *= 3;
      }
      i += 2;
    }
    ans %= MOD;
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 256
A,B,C,X,Y=[int(i) for i in input().split()]
if X>=Y:
    result=min(X,Y)*min(A+B,C*2)+(max(X,Y)-min(X,Y))*min(A,C*2)
else:
    result=min(X,Y)*min(A+B,C*2)+(max(X,Y)-min(X,Y))*min(B,C*2)
print(result)

Measured memory_bytes: 3064
from collections import defaultdict
n = int(input())
li = []
for i in range(n):
    x, y = map(int, input().split())
    li.append((x, y))
dd = defaultdict(lambda:0)
for i in range(n):
    for j in range(n):
        if i != j:
            dd[(li[i][0]-li[j][0], li[i][1]-li[j][1])] += 1
m = 0
for k in dd:
    m = max(dd[k],m)
print(n-m)

Measured memory_bytes: 9836
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
using namespace std;

int main(void)
{
	long long N, C;
	cin >> N >> C;

	vector<long long> x(N+2, 0), v(N+2, 0);
	for(int i=0; i<N; i++)
		cin >> x[i+1] >> v[i+1];
	x[N+1] = C;

	long long sum = 0;
	vector<long long> _x(N+2, 0), _x2(N+2, 0);
	for(int i=1; i<N+2; i++){
		sum += v[i];
		_x[i] = max(_x[i-1], sum - x[i]);
		_x2[i] = max(_x2[i-1], sum - 2*x[i]);
	}

	long long ret = 0;
	sum = 0;
	for(int i=N+1; i>0; i--){
		long long d = C - x[i];
		sum += v[i];
		ret = max(ret, _x[i-1] + sum - 2*d);
		ret = max(ret, _x2[i-1] + sum - d);
	}

	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define ll long long
using namespace std;
map<char,vector<int>> mp;
string s;
int main(){
    int n;
    cin>>n;
    cin>>s;
    for(int k=0;k<s.size();k++)
        mp[s[k]].push_back(k);
        int ans=0;
for(int k=0;k<1000;k++){
    int p=k;
    string a=to_string(p);
    while(a.size()!=3){
        a='0'+a;
    }
    if(mp[a[0]].size()==0 || mp[a[1]].size()==0 || mp[a[2]].size()==0)
        continue;
int x=0;
vector<int>::iterator it=lower_bound(mp[a[0]].begin(),mp[a[0]].end(),x);
x=*it;
x++;
if(x>mp[a[1]][mp[a[1]].size()-1])
    continue;
it=lower_bound(mp[a[1]].begin(),mp[a[1]].end(),x);
x=*it;
x++;
if(x>mp[a[2]][mp[a[2]].size()-1])
    continue;
    ans++;
}
cout<<ans;
return 0;
}


Measured memory_bytes: 512
#include<iostream> 
#include<vector> 
#include<algorithm> 
using namespace std; 
#define lld long long int
#define X 1000000007
#define fast();  ios_base::sync_with_stdio(false); cin.tie(0);
# define rec(i,n) for(int i=0;i<n;i++) 
#define w(t) int t; cin>>t; while(t--)
int main()
{
    fast(); 
    lld n,x;  
    cin>>n; 
    lld a[n]; 
     rec(i,n)
       a[i]=0; 
    rec(i,n-1)
    {  cin>>x; 
       a[-1+x]++; 
    }
     for(int i=0;i<n;i++) 
      cout<<a[i]<<endl; 
	return 0;
}

Measured memory_bytes: 5180
#include <bits/stdc++.h>
using namespace std;
const int N=1e6;
char s[N];
int a[N],f[N],n;
void rebuild(int l,int r){
    for (int i=r; i>=l; --i)
	f[i]=f[i+1]+a[i];
    return;
}
void mul(int s){
    for (int i=1; i<=n; ++i)
	a[i]=a[i]*s;
    for (int i=1; i<=n; ++i)
	a[i+1]+=a[i]/10,a[i]%=10;
    while(a[n+1])
	++n,a[n+1]+=a[n]/10,a[n]%=10;
    return rebuild(1,n);
}
void add(int s){
    a[1]+=s;
    for (int i=1; i<=n; ++i)
	if (a[i]<10){
	    rebuild(1,i);
	    break;
	}
	else a[i+1]+=a[i]/10,a[i]%=10;
    if (a[n+1])
	++n,a[n+1]+=a[n]/10,a[n]%=10,rebuild(1,n);
    return;
}
int main(){
    scanf("%s",s),n=strlen(s);
    for (int i=n; i; --i) a[i]=s[n-i]-'0';
    mul(9);
    for (int i=1; i<=10*n; ++i){
	add(1);
	if (f[1]<=i)
	    return cout<<(i-1)/9+1,0;
    }
    return 0;
}


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

#define int long long
#define abs(n) ((n) < 0 ? -(n) : (n))

const int LLINF = 1LL << 60;

signed main()
{
  int n;
  int sum = 0;
  int ss = 0;
  int ans = LLINF;
  int a[200005];

  cin >> n;

  for(int i = 0; i < n; i++) {
    cin >> a[i]; sum += a[i];
  }
  
  for(int i = 0; i < n - 1; i++) {
    ss += a[i];
    ans = min(ans, abs((sum - ss) - ss));
  }

  cout << ans << endl;

  return (0);
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, m; cin >> n >> m;
    vector<pair<long long,int>> A(n);
    for(int i = 0; i < n; ++i) {
        cin >> A[i].first >> A[i].second;
    }
    sort(A.begin(),A.end());
    long long ans = 0;
    int i = 0;
    while(m > 0) {
        int diff = min(m, A[i].second);
        ans += diff*A[i].first;
        m -= diff;
        ++i;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
/*
    Washief Hossain Mugdho
    17 September 2020
    Educational DP Frog1
*/

#ifndef DEBUG
#pragma GCC optimize("O3")
#endif

#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define fastio ios_base::sync_with_stdio(0)
#define untie cin.tie(0)
#define ms(a, b) memset(a, b, sizeof a)
using namespace std;

int main()
{
#ifdef LOCAL_OUTPUT
    freopen(LOCAL_OUTPUT, "w", stdout);
#endif
#ifdef LOCAL_INPUT
    freopen(LOCAL_INPUT, "r", stdin);
#endif

    int n, k;
    cin >> n >> k;
    int a[n];
    vector<int> dp(n, INT32_MAX);
    dp[0] = 0;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int i = 0; i < n - 1; i++)
    {
        for (int j = 1; j <= k; j++)
            if (i + j < n)
                dp[i + j] = min(dp[i + j], dp[i] + abs(a[i + j] - a[i]));
    }
    cout << dp[n - 1] << endl;
}


Measured memory_bytes: 4016
#include <bits/stdc++.h>
using namespace std;
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;
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

using P = pair<ll, ll>;

ll dist(P a, P b) {
    return llabs(a.first - b.first) + llabs(a.second - b.second);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<P> p(n), chp(m);
    for(int i = 0; i < n; i++) {
        cin >> p[i].first >> p[i].second;
    }
    for(int i = 0; i < m; i++) {
        cin >> chp[i].first >> chp[i].second;
    }
    for(int i = 0; i < n; i++) {
        ll mn = LLINF;
        int id = -1;
        for(int j = 0; j < m; j++) {
            if(chmin(mn, dist(p[i], chp[j]))) {
                id = j;
            }
        }
        cout << id + 1 << endl;
    }
}

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

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

int main(){
    string S;
    cin >> S;
    int N = (int)S.size();

    //右側からチェックしていく
    for(int i = N-1; i >= 0; i--){
        string t;

        //dreamer check
        if(i-7+1 >= 0){
            t = S.substr(i-7+1 ,7);
            if(t == "dreamer"){
                i -= 6;
                continue;
            }
        }

        //eraser check
        if(i-6+1 >= 0){
            t = S.substr(i - 6 + 1, 6);
            if (t == "eraser"){
                i -= 5;
                continue;
            }
        }

        //dream and erase check
        if(i-5+1 >= 0){
            t = S.substr(i - 5 + 1, 5);
            if (t == "dream" || t == "erase"){
                i -= 4;
                continue;
            }
        }

        cout << "NO" << endl;
        return 0;
    }
    cout << "YES" << endl;
    return 0;
}

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

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

using namespace std;

int main() {
  string s;
  std::cin >> s;
  int maxv = 0;
  for (int i = 0; i < s.length(); ++i) {
    int count = 0;
    while (s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T') {
      count++;
      i++;
    }
    maxv = max(maxv, count);
  }
  std::cout << maxv << std::endl;
  return 0;
}


Measured memory_bytes: 3620
/*ex3_4
ryo_1129*/
#include <stdio.h>

int main(void){
	int N; //変数宣言
	scanf("%d",&N); //入力
	int divisor = 1; //割る数、
	//割る数が1以上９以下の間
	while(divisor <= 9){
		//余りが０かつ商が１以上９以下の場合、Yesと表示する 
		if(N / divisor !=0 && N % divisor == 0 && N / divisor <= 9){
			printf("Yes\n");
			break;
		}
		divisor++; //割る数を１増やす
	}
	// Yesが表示されなかった場合、Noを表示する。
	if(divisor == 10){
		printf("No\n");
	}
	return 0;
}

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

#define FOR(i, a, b) for (int i = a; i < (int) b; i++) 
#define F0R(i, a) FOR (i, 0, a)
#define GO(to, a) for (auto to : a)

#define f first
#define s second
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vpii> vvpii;

const int dr[] = {+1, -1, +0, +0, +1, -1, +1, -1};
const int dc[] = {+0, +0, +1, -1, +1, -1, -1, +1};

const int m[] = {+31, +29, +31, +30, +31, +30, +31, +31, +30, +31, +30, +31};

const int N = 2e4 + 5;
int dp[N + 10000];

int main () {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int h, n;
	cin >> h >> n;
	F0R (i, N) dp[i] = 1e9;
	dp[0] = 0;
	F0R (i, n) {
		int vida, custo;
		cin >> vida >> custo;
		FOR (j, vida, h + N) {
			assert (j - vida >= 0);
			 dp[j] = min (dp[j], dp[j - vida] + custo);
		}
	}
	int mn = 1e9;
	FOR (i, h, N) mn = min (mn, dp[i]);
	cout << mn  << '\n';
	return 0;
}

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

int main(){
  int y,m,d;
  char s1,s2;
  cin >> y >>s1>> m >>s2>> d;
  if(m>4){
    cout<<"TBD"<<endl;
  }
  else
    cout<<"Heisei"<<endl;
}
  

Measured memory_bytes: 256
import collections
N = int(input())
S = input()
_ = input()

c = collections.Counter(S)
instant = []
i = 0
while i < N:
    if c[S[i]] == 2:
        instant.append(2)
        i += 2
    else:
        instant.append(1)
        i += 1


if instant[0] == 2:
    ans = 6
else:
    ans = 3

for i in range(1, len(instant)):
    if instant[i-1] == 1:
        ans *= 2
    elif instant[i] == 2:
        ans *= 3

print(ans % (10 ** 9 + 7))

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,ll> P;
const int MAX_N = 100005;
const ll INF = 1e10;
bool used[MAX_N];
ll lo[MAX_N];
vector<P> G[MAX_N];

void init()
{
	rep(i,MAX_N)
	{
		lo[i] = INF;
	}
}

void dfs(int x, ll c)
{
	if (used[x]) return;
	lo[x] = c;
	used[x] = true;
	rep(i,G[x].size())
	{
		dfs(G[x][i].first, lo[x] + G[x][i].second);
	}
	return;
}

int main()
{
	//init();
	int N,M;
	cin >> N >> M;
	rep(i,M)
	{
		int l,r;
		ll d;
		cin >> l >> r >> d;
		l--; r--;
		G[l].push_back(P(r,d));
		G[r].push_back(P(l,-d));
	}
	rep(i,N)
	{
		dfs(i,ll(0));
	}
	rep(i,N)
	{
		rep(j,G[i].size())
		{
			if (lo[G[i][j].first] - lo[i] != G[i][j].second)
			{
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 16512
#include <bits/stdc++.h>
#define il inline
#define RG register
#define ll long long
#define N (100005)

using namespace std;

deque<int> Q;
int dis[N],n;

il void bfs(){
  for (RG int i=0;i<n;++i) dis[i]=1<<30;
  dis[1]=1,Q.push_back(1);
  while (!Q.empty()){
    RG int x=Q.front(),v; Q.pop_front();
    if (dis[v=x*10%n]>dis[x]) dis[v]=dis[x],Q.push_front(v);
    if (dis[v=(x+1)%n]>dis[x]+1) dis[v]=dis[x]+1,Q.push_back(v);
  }
  return;
}

int main(){
  cin>>n,bfs(),cout<<dis[0]; return 0;
}


Measured memory_bytes: 896
s = gets.strip

words = ['dream', 'dreamer', 'erase', 'eraser']

until s.empty? do
    reduced = false
    words.map do |w|
        if s[-w.size, w.size] == w
            s = s[0..-w.size - 1]
            reduced = true
            break
        end
    end

    unless reduced
        puts 'NO'
        exit 0
    end
end

puts 'YES'

Measured memory_bytes: 56296
import java.util.*;

public class Main{
	
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	int n=sc.nextInt(),max=0;
    int[] a=new int[n],b=new int[100000];
    for(int i=0;i<n;i++){
      a[i]=sc.nextInt();
      b[a[i]]++;
    }
    Arrays.sort(a);
    for(int i=a[0];i<=a[n-1];i++){
      if(i!=0&&i!=99999){
        int f=b[i-1]+b[i]+b[i+1];
        max=(int)Math.max(f,max);
      }else if(i==0){
        int f=b[i]+b[i+1];
        max=(int)Math.max(f,max);
      }else{
        int f=b[i-1]+b[i];
        max=(int)Math.max(f,max);
      }
    }
    System.out.println(max);
          
  }
}


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

#define mp make_pair
#define pb push_back
#define f first
#define s second 
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()
#define int long long
#define forn(i, x, y) for(int i = x; i <= y; i++)
#define forev(i, y, x) for(int i = y; i >= x; i--)

using namespace std;

const int maxn = (int)3e5 + 100;
const int mod = (int)1e9 + 7;
const int P = (int)1e6 + 7;
const int inf = (int)1e9 + 7;

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef long double ld;

using namespace std;

int n, x;	
main () {
	cin >> n;
	multiset<double>s;
	forn(i, 1, n){
		cin >> x;
		s.insert(x+0.0);
	}	
	while(sz(s)>1){
		auto x=*s.begin();
		s.erase(s.begin());
		auto y=*s.begin();
		s.erase(s.begin());
		s.insert((x+y)/2.0);
	}
	cout<<fixed<<setprecision(5)<<*s.begin();
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <queue>
#include <map>
#include <algorithm>
using namespace std;
typedef pair<int, int> P;
typedef pair<P, pair<int,string> > PP;
string a, b, c;
int k;
int br[1000];
int main() {
    cin>>a>>b;
    scanf("%d",&k);
    c="";
    int n=a.length();
    for (int i=0; i<n; i++) c+='0';
    while (b.length()<n) b="0"+b;
    reverse(a.begin(), a.end()); reverse(b.begin(), b.end());
    queue<PP> que;
    que.push(make_pair(P(0,k),make_pair(0,"")));
    while (!que.empty()) {
        PP p=que.front(); que.pop();
        int i=p.first.first;
        int x=p.first.second;
        int br=p.second.first;
        string s=p.second.second;
        if (s.length()==n) {
            if (c<s) c=s;
            continue;
        }
        if (a[i]-br>=b[i]) {
            string temp="";
            temp+=a[i]-br-b[i]+'0';
            que.push(make_pair(P(i+1,x),make_pair(0,(temp+s))));
        } else {
            string temp="";
            temp+=a[i]-br+10-b[i]+'0';
            if (x>0) que.push(make_pair(P(i+1,x-1),make_pair(0,(temp+s))));
            que.push(make_pair(P(i+1,x),make_pair(1,(temp+s))));
        }
    }
    bool flag=false;
    for (int i=0; i<c.length(); i++) {
        if (c[i]!='0') {
            flag=true;
            putchar(c[i]);
        } else if (flag) {
            putchar(c[i]);
        }
    }
    puts("");
}

Measured memory_bytes: 0
#include<map>
#include<set>
#include<cmath>
#include<regex>
#include<queue>
#include<stack>
#include<bitset>
#include<vector>
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<unordered_map>

#pragma warning(disable:4996)
using namespace std;

map<char, char>myMap;
string str;

bool Check() {
	int i = 0;
	int j = str.size() - 1;
	if (str.size() % 2) {
		return false;
	}
	while (i < j) {
		if (myMap[str[i]] != str[j]) {
			return false;
		}
		++i; --j;
	}
	return true;
}

int main() {	
	myMap['b'] = 'd';
	myMap['d'] = 'b';
	myMap['p'] = 'q';
	myMap['q'] = 'p';
	cin >> str;
	if (Check()) {
		puts("Yes");
	}
	else {
		puts("No");
	}
	return 0;
}

Measured memory_bytes: 512
import java.util.HashSet;
import java.util.Scanner;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author rn-sshawish
 */
public class Main{

    public static void main(String[] args) {
        HashSet<Integer> values = new HashSet<>();
        Scanner input = new Scanner(System.in);
        int a = input.nextInt();
        int b = input.nextInt();
        int k = input.nextInt();
        int acopy = a;
        StringBuilder out = new StringBuilder();

        for (int i = 0; i < k && acopy <= b; i++) {
            out.append(acopy).append("\n");
            values.add(acopy);
            acopy++;
        }
        int secandCopy = Math.max(a, b - k) + 1;
        for (int i = 0; i < k && secandCopy <= b; i++) {
            if (!values.contains(secandCopy)) {
                out.append(secandCopy).append("\n");
                values.add(secandCopy);
            }
            secandCopy++;
        }
        System.out.print(out);
    }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d,e,f[409],dp[401][401],jm[401];
int main(){
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>a;
	for(b=1; b<=a; b++) cin>>f[b];
	for(b=1; b<=a; b++){
		for(c=b; c<=a; c++){
			dp[b][c]=999999999999999999LL;
		}
	}
	for(b=1; b<=a; b++) jm[b]=jm[b-1]+f[b];
	for(b=1; b<=a; b++) dp[b][b]=0;
	for(b=2; b<=a; b++){
		for(c=1; c<=a; c++){
			if(c+b-1>a) break;
			for(d=c; d<c+b-1; d++){
				if(dp[c][c+b-1]>dp[c][d]+dp[d+1][c+b-1]+jm[c+b-1]-jm[c-1]){
					dp[c][c+b-1]=dp[c][d]+dp[d+1][c+b-1]+jm[c+b-1]-jm[c-1];
				}
			}
		}
	}
	cout<<dp[1][a];
	return 0;
}

Measured memory_bytes: 1536