akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector> 
#include <algorithm>
#include <typeinfo>
#include <cmath>
#include <numeric>
#include <queue>
#include <set>
using namespace std;

long long getGCD(long a, long b){
    if(b == 0) return a;
    return getGCD(b, a%b);
}

long getStart(long A, long C){
    if(A%C == 0){
        return A/C; 
    }else{
        return A/C + 1;
    }
}

int main(){
    long long A, B, C, D;
    std::cin >> A >> B >> C >> D;
    long long num_C, num_D, num_CD;
    num_C = B/C - getStart(A ,C) + 1;
    num_D = B/D - getStart(A ,D) + 1;
    long long CD;
    CD = C * D / getGCD(C, D);
    num_CD = B/CD - getStart(A ,CD) + 1;
    long long ans;
    ans = B - A + 1 - num_C - num_D + num_CD;
    std::cout << ans << "\n";
    
}

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

using namespace std;

int main() {
  int n; // number of entries
  cin >> n;

  vector<int> sort_vec;

  for (int i = 0; i < n; i++) {
    int entry;
    cin >> entry;
    sort_vec.push_back(entry);
  }
  
  //bubble sort
  int n_swaps = 0; //number of swaps
  for (int i = 0; i < n; i++) {
    int min_index = i; // assume min is first element
    for (int j = i+1; j < n; j++) {
      // test for minimum 
      if (sort_vec[j] < sort_vec[min_index]) min_index = j;
    }
    if (i != min_index) {
      swap(sort_vec[i], sort_vec[min_index]); //swap 
      n_swaps++;
    }
  } 
  
  //print vector
  for (int i = 0; i < n; i++) {
    cout << sort_vec[i];
    if (i < n - 1) cout << " ";
  }
  cout << endl;

  cout << n_swaps << endl;
}
	

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

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

    int ans = 0;
    int i = 1;

    while (int a = n % 10) {
        ans += (a == 1 ? 9 : 1) * i;

        i *= 10;
        n /= 10;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
# include <cstdio>
# include <iostream>

using namespace std;

int h,w,f=1,j,x,lasx,lasy;
int g[502][502];
int H,a[250005],b[250005],c[250005],d[250005];

int main()
{
	scanf("%d%d",&h,&w);
	for (int i=1;i<=h;++i)
		for (int j=1;j<=w;++j)
			scanf("%d",&g[i][j]),g[i][j]%=2;
	for (int i=1;i<=h;++i)
	{
		for (int j=1;j<=w;++j)
		{
			if(x)
			{
				a[++H]=lasx,b[H]=lasy,c[H]=i,d[H]=j;
				g[i][j]++;
				if(g[i][j]==2) x=0,g[i][j]=0;
			}else if(g[i][j]) x=1;
			lasx=i;
			lasy=j;
		}
		if(x) g[i][w]=1;
		x=0;
	}
	for (int i=1;i<=h;++i)
	{
		if(x)
		{
			a[++H]=i-1,b[H]=w,c[H]=i,d[H]=w;
			if(g[i][w]) x=0;
		}else if(g[i][w]) x=1;
	}
	printf("%d\n",H);
	for (int i=1;i<=H;++i)
		printf("%d %d %d %d\n",a[i],b[i],c[i],d[i]);
	return 0;
}

Measured memory_bytes: 6016
a,b,k = map(int, input().split())

if 2*k < b-a:
    for i in range(a, a+k):
        print(i)
    for i in range(b-k+1, b+1):
        print(i)
else:
    for i in range(a, b+1):
        if (a <= i and i < a+k) or (b-k < i and i <= b):
            print(i)


Measured memory_bytes: 3060
package main

import (
	"fmt"
	"sort"
)

func scanint() int{
	var v int;
	fmt.Scan(&v)
	return v
}
func main() {
	N := scanint()
	p := make([]int,N)
	ans := 0
	for i:=0; i< N ; i++ {
		fmt.Scan(&p[i])
		ans += p[i]
	}

	sort.Ints(p)
	ans -= p[N-1]/2
	fmt.Println(ans)

}


Measured memory_bytes: 512
n,k=map(int,input().split())
a=list(map(int,input().split()))
m=10**9+7
s=sum
print(s((((s(a[i]>j for j in a[i:])*(k*(k+1)//2)%m)+(s(a[i]>j for j in a[:i+1])*(k*(k-1)//2)%m))%m) for i in range(n))%m)

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

#define int long long

int n;
int a[2020];

int dp[2020][2020];

int dfs(int l, int r)
{
  l = (l + n) % n;
  r = (r + n) % n;

  int &ret = dp[l][r];
  if (ret != -1) return ret;
  if (l == r) return 0;
  if (a[l] > a[r]) {
    l--;
  } else if (a[r] > a[l]) {
    r++;
  }

  l = (l + n) % n;
  r = (r + n) % n;

  if (l == r) return a[l];

  ret = max(dfs(l - 1, r) + a[l], dfs(l, r + 1) + a[r]);

  return ret;
}

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

  int maxv = 0;
  memset(dp, -1, sizeof(dp));
  for (int i = 0; i < n; i += 2){
    maxv = max(maxv, dfs(i - 1, i + 1) + a[i]);
  }
  memset(dp, -1, sizeof(dp));
  for (int i = 1; i < n; i += 2){
    maxv = max(maxv, dfs(i - 1, i + 1) + a[i]);
  }
  cout << maxv << endl;
}

Measured memory_bytes: 35016
#include<bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    long long i,j,k;
    long long n;
    long long ga,gb,sa,sb,ba,bb;
    std::cin >> n;
    std::cin >> ga>>sa>>ba;
    std::cin >> gb>>sb>>bb;
    long long ans=0;
    long long m;
    if(ga<=gb&&sa<=sb&&ba<=bb){
        for (i=0;i<=n/ga;i++){
            for (j=0;j<=(n-i*ga)/sa;j++){
                    m=i*(gb-ga)+j*(sb-sa)+((n-i*ga-j*sa)/ba)*(bb-ba);
                    if (m>ans) ans=m;
            }
        }
        ans+=n;
    }
    else if(ga>=gb&&sa>=sb&&ba>=bb){
        long long g=ga,s=sa,b=ba;
        ga=gb;sa=sb;ba=bb;gb=g;sb=s;bb=b;
        for (i=0;i<=n/ga;i++){
            for (j=0;j<=(n-i*ga)/sa;j++){
                    m=i*(gb-ga)+j*(sb-sa)+((n-i*ga-j*sa)/ba)*(bb-ba);
                    if (m>ans) ans=m;
            }
        }
        ans+=n;
    }
    else if(ga>=gb&&sa>=sb&&ba<=bb){
        n+=(bb-ba)*(n/ba);
        for (i=0;i<=n/gb;i++){
                m=i*(ga-gb)+((n-i*gb)/sb)*(sa-sb);
                if (m>ans) ans=m;
         }
        ans+=n;
    }
    else if(ga>=gb&&sa<=sb&&ba>=bb){
        n+=(sb-sa)*(n/sa);
        for (i=0;i<=n/gb;i++){
                m=i*(ga-gb)+((n-i*gb)/bb)*(ba-bb);
                if (m>ans) ans=m;
         }
        ans+=n;
    }
    else if(ga<=gb&&sa>=sb&&ba>=bb){
        n+=(gb-ga)*(n/ga);
        for (i=0;i<=n/sb;i++){
                m=i*(sa-sb)+((n-i*sb)/bb)*(ba-bb);
                if (m>ans) ans=m;
         }
        ans+=n;
    }
    else if(ga>=gb&&sa<=sb&&ba<=bb){
        for (i=0;i<=n/sa;i++){
                m=i*(sb-sa)+((n-i*sa)/ba)*(bb-ba);
                if (m>ans) ans=m;
         }
        n+=ans;
        n+=(ga-gb)*(n/gb);
        ans=n;
    }
    else if(ga<=gb&&sa>=sb&&ba<=bb){
        for (i=0;i<=n/ga;i++){
                m=i*(gb-ga)+((n-i*ga)/ba)*(bb-ba);
                if (m>ans) ans=m;
         }
        n+=ans;
        n+=(sa-sb)*(n/sb);
        ans=n;
    }
    else if(ga<=gb&&sa<=sb&&ba>=bb){
        for (i=0;i<=n/ga;i++){
                m=i*(gb-ga)+((n-i*ga)/sa)*(sb-sa);
                if (m>ans) ans=m;
         }
        n+=ans;
        n+=(ba-bb)*(n/bb);
        ans=n;
    }
    std::cout << ans << std::endl;
   
}


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

template<typename T>
T knapsack(int N, int W, vector<T> v, vector<int> w) {
    vector<vector<T>> dp(N + 1, vector<T>(W + 1, 0));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j <= W; j++) {
            if (j < w[i]) {
                dp[i + 1][j] = dp[i][j];
            } else {
                dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
            }
        }
    }
    return dp[N][W];
}

int main() {
    int N, W; cin >> N >> W;
    vector<int> w(N);
    vector<long long> v(N);
    for (int i = 0; i < N; i++) {
        cin >> w[i] >> v[i];
    }
    cout << knapsack(N, W, v, w) << endl;
    return 0;
}

Measured memory_bytes: 80256
/************************Code by Hardik Aggarwal!!!!***********************************/

#include<bits/stdc++.h>
using namespace std;

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); 

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define endl '\n'
#define debug cout << "Hold right there sparky.....\n";
#define forn(low,high,i) for(i=low;i<high;i++)
#define forrev(high,low,i) for(i = high; i>= low;i--)
#define trace(x) cerr << #x << ": " << x << " " << endl;

typedef long long int ll;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod =1e9+7;

int main()
{
    
 
    IOS
    ll a;
    string s;
    cin>>a>>s;
    if(a>=3200)
        cout<<s;
    else
        cout<<"red";
    

}
    
 
    
    



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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using Pi = pair<int, int>;
using Ti = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int n, h;
  cin >> n >> h;
  vint a(n), b(n);
  rep(i, n) cin >> a[i] >> b[i];
  sort(all(a));
  reverse(all(a));
  sort(all(b));
  reverse(all(b));
  b.push_back(0);
  int ans = inf;
  int sum = 0;
  rep(i, n+1) {
    chmin(ans, i+max(0ll, (h-sum+a[0]-1)/a[0]));
    sum += b[i];
    //cout<<ans<<endl;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 2560
#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>;

int main() {
  string s;
  cin >> s;
  if (s.find("7") != string::npos) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

typedef long long ll;
const int maxn = 1e5+10;
int a[maxn],b[maxn];

int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    ll res=0;
    for(int i=0;i<n;i++){
        scanf("%d%d",&a[i],&b[i]);
        if((a[i]&k)==a[i])  res+=(ll)b[i];
    }
    for(int i=30;i>=0;i--){
        int tmp=1<<i;
        if(k&tmp){
            int f=(k^tmp)|(tmp-1);
            ll ans=0;
            for(int j=0;j<n;j++){
                if((a[j]&f)==a[j])    ans+=(ll)b[j];
            }
            res=max(res,ans);
        }
    }
    printf("%lld\n",res);
    return 0;
}


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

#define REP(i, x) for (int i = 0, i##_len = (int)(x); i < i##_len; i++)
#define REP1(i, x) for (int i = 1, i##_len = (int)(x); i <= i##_len; i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREP1(i, x) for (int i = ((int)(x)); i > 0; i--)
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
const int MOD = (int)1e9 + 7;
const int INF = 1145141919;
using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using l_l = pair<ll, ll>;
using d_d = pair<double, double>;
using vint = vector<int>;
using vll = vector<ll>;
using vbool = vector<bool>;

struct edge {
    int to, cost;
    edge(int to, int cost) : to(to), cost(cost) {}
};

int N;
vector<vector<edge>> vertex;
vbool isblack;
vbool yet;

void dfs(int i, bool isb) {
    if (yet[i])
        return;
    yet[i] = true;

    isblack[i] = isb;

    // cout << "isb " << isb << endl;
    for (auto e : vertex[i]) {
        // cout << "e.cost" << e.cost << endl;
        dfs(e.to, e.cost % 2 == 0 ? isb : !isb);
    }
}

int main() {
    cin >> N;
    vertex = vector<vector<edge>>(N, vector<edge>());
    isblack = vbool(N);
    yet = vbool(N);

    int u, v, w;
    REP(_, N - 1) {
        cin >> u >> v >> w;
        u -= 1;
        v -= 1;
        vertex[u].push_back(edge(v, w));
        vertex[v].push_back(edge(u, w));
    }

    dfs(0, true);

    REP(i, N) {
        cout << isblack[i] << endl;
    }
}

Measured memory_bytes: 7808
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var xn = Console.ReadLine().Split(' ').Select(num => int.Parse(num)).ToArray();
            var x = xn[0];
            if (xn[1] == 0)
            {
                Console.WriteLine(x);
                return;
            }

            var xs = Console.ReadLine().Split(' ').Select(num => int.Parse(num)).ToHashSet();
            if (!xs.Contains(x))
            {
                Console.WriteLine(x);
                return;
            }
            for (var i = 1; i < xs.Count + 2; i++)
            {
                if (Judge(x - i)) return;

                if (Judge(x + i)) return;

                bool Judge(int num)
                {
                    if (!xs.Contains(num))
                    {
                        Console.WriteLine(num);
                        return true;
                    }
                    return false;
                }
            }
        }
    }
}

Measured memory_bytes: 28288
#include <bits/stdc++.h>
using namespace std;
int V, m;
int cost[200][200];
int mincost[200];
bool used[200];

int prim(){
  for(int i=0; i < V; ++i){
    mincost[i] = INT_MAX/2;
    used[i] = false;
  }
  mincost[0] = 0;
  int res = 0;

  while(true){
    int v = -1;
    for(int u=0; u < V; u++){
      if(!used[u] && (v == -1 || mincost[u] < mincost[v])) v = u;
    }

    if(v == -1) break;
    used[v] = true;
    res += mincost[v];

    for(int u=0; u < V; u++){
      mincost[u] = min(mincost[u], cost[v][u]);
    }
  }
  return res;
}

int main(void){
  while(cin >> V >> m, V | m){
    for(int i=0; i < V; i++)
      for(int j=0; j < m; j++)
        cost[i][j] = INT_MAX/2;
    for(int i=0; i < m; i++){
      int a, b, c; cin >> a >> b >> c;
      cost[a][b] = c;
      cost[b][a] = c;
    }
    cout << prim() << endl;
  }
  return 0;
}

Measured memory_bytes: 1240
#include <iostream>

using namespace std;

#define INF 2000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> P;




int main()
{
	int n;
	string s, t;
	cin >> n >> s >> t;

	int idxs = n-1;
	int idxt = n-1;

	while (idxt > -1) {
		if (s[idxs] == t[idxt]) {
			int tmps = idxs;
			int tmpt = idxt;
			while (tmps > 0 && tmpt > 0) {
				tmps--;
				tmpt--;
				if (s[tmps] != t[tmpt]) {
					break;
				}
			}
			if (tmpt == 0) {
				break;
			}
		}
		idxt--;
	}

//	cout << idxt << "\n";
	if (idxt == -1) {
		cout << s.size() + t.size() << endl;
		return 0;
	}


	cout << n*2-((idxt+1)) << endl;
	// cout << s;
	// for (int i = idxt+1; i < n; i++) {
	// 	cout << t[i];
	// }
	// cout  << "\n";
}


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

int main()
{
    string s;
    cin >> s;
    int cnt = 0;
    for(char c: s)
    {
        if(c == '1')
        {
            ++cnt;
        }
    }
    cout << cnt << endl;
    return 0;
}

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

int main() {

	ll n; cin >> n;
	vector<ll> a(n + 1);
	for (ll i = 1; i <= n; i++) {
		cin >> a[i];
	}
	ll x = 0;
	for (ll i = 1; i <= n; i++) {
		if (i % 2 == 1) x += a[i];
		else x -= a[i];
	}
	cout << x << " ";
	ll prev = x;
	for (ll i = 2; i <= n; i++) {
		ll ans = 2 * a[i - 1] - prev;
		cout << ans << " ";
		prev = ans;
	}
	return 0;
}

Measured memory_bytes: 4028
while 1:
  s,t= map(int,input().split())
  if s+t == 0:break
  c=0
  for i in range(1,s+1):
    for j in range(i+1,s+1):
      for k in range(j+1,s+1):
        if i+j+k ==t:c+=1
  print(c)


Measured memory_bytes: 5596
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner scan = new java.util.Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        if(a != 1 && b != 1){
            System.out.println("1");
        }else if(a != 2 && b != 2){
            System.out.println("2");
        }else{
            System.out.println("3");
        }
    }
}

Measured memory_bytes: 22868
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;

int H[220000];
map<int, int> mp;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int N; cin >> N;
	for (int i = 0; i < N; i++) cin >> H[i];

	ll ans = 0;
	for (int i = N - 1; i >= 0; i--) {
		ans += mp[H[i] + i];
		mp[i - H[i]]++;
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 21328
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;

void solve() {
    fori (i, 0, 5) {
        int x;
        cin >> x;
        if (x == 0) {
            cout << i + 1 << endl;
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    solve();
    return 0;
}



Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main () {
  int N, K;
  cin >> N >> K;
  vector<int>A(N);
  for (int i = 0; i < N; i ++) cin >> A[i];
  bool dp[100009];//dp[i] = 先手勝ちならtrue、負けならfalse
  for (int i = 0; i < A[0]; i ++) dp[i] = false;
  for (int i = A[0]; i < 100009; i ++) {
    bool win = false;
    for (int j = 0; j < N; j ++) {
      if (i >= A[j] && !dp[i - A[j]]) win = true;
    }
    dp[i] = win;
  }
  cout << (dp[K] ? "First" : "Second") << endl;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  int n = s.size();
  vector<pair<int, int>> range;
  range.reserve(n);
  for (int i = 0, cur = 0; i < n; i++) {
    if (s[i] == '1') {
      range.push_back({cur, i});
      if (i + 1 < n && s[i + 1] == '1') {
        range.push_back({cur + 1, i + 1});
      }
      i++;
      cur += 2;
    }
  }
  long long ans = 0;
  for (int i = 0; i < (int) range.size(); i++) {
    if (range[i].first & 1) {
      if (range[i].second & 1) range[i].second--;
      int tim = (range[i].second - range[i].first + 1) / 2;
      tim = max(tim, 0);
      ans += tim;
    } else {
      int tim = n - range[i].first;
      tim -= (range[i].second - range[i].first + 1) / 2;
      ans += tim;
    }
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 5052
from itertools import combinations

h,w,k = map(int,input().split())
c = [list(input()) for _ in range(h)]

ans = 0
for i in range(h+1):
  for j in range(w+1):
    for ci in combinations(list(range(h)),i):
      for cj in combinations(list(range(w)),j):
        cnt = 0
        for l in ci:
          for m in cj:
            if c[l][m] == "#":
              cnt += 1
        if cnt == k:
          ans += 1
print(ans)

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

int main()
{
    int ans = 0, n, m, c;
    cin >> n >> m >> c;
    int b[20], a[20][20];
    for(int i = 0; i < m; i++) cin >> b[i];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++) cin >> a[i][j];
    }
    
    for(int i = 0; i < n; i++){
        int sum = c;
        for(int j = 0; j < m; j++){
            sum += a[i][j]*b[j];
        }
        if(sum > 0) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	char a,b;
	scanf("%c %c",&a,&b);
	if(a == 'H' && b == 'H') printf("H");
	else if(a == 'H' && b == 'D') printf("D");
	else if(a == 'D' && b == 'H') printf("D");
	else if(a == 'D' && b == 'D') printf("H");
	return 0;
}


Measured memory_bytes: 128
// https://atcoder.jp/contests/abc107/tasks/arc101_a

#include <bits/stdc++.h>
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for (int(i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for (int(i) = (m); (i) < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

ll N, K, x[100000], r;

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

  REP(i, N)
  {
    cin >> x[i];
  }

  r = INF;
  REP(i, N - K + 1)
  {
    r = min(r, min(abs(x[i + K - 1]), abs(x[i])) + x[i + K - 1] - x[i]);
  }

  cout << r << '\n';

  return 0;
}


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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
const ll mod = ll(1e9) + 7;
const int INF = int(1e9);

int idxa = 0, idxb = 0;

int calc(string &A, string &B)
{
    string tmpa, tmpb;
    idxa++;
    idxb++;
    while (A[idxa] != ']')
    {
        tmpa.push_back(A[idxa++]);
    }
    while (B[idxb] != ']')
    {
        tmpb.push_back(B[idxb++]);
    }
    //cout << tmpa << " " << tmpb << endl;
    return stoi(tmpa) + stoi(tmpb);
}
int proceed(int idx, string &C)
{
    int cnt = 1;
    while (1)
    {
        idx++;
        if (C[idx] == ')')
            cnt--;
        if (C[idx] == '(')
            cnt++;
        if (cnt < 0)
            break;
    }
    return idx;
}

int main()
{
    string A, B;
    cin >> A >> B;
    string ans;
    while (idxa < A.size())
    {
        if (A[idxa] == B[idxb])
        {
            if (A[idxa] == '[')
            {
                ans.push_back('[');
                int tmp = calc(A, B);
                ans += to_string(tmp);
                ans.push_back(']');
            }
            else
                ans.push_back(A[idxa]);
        }
        else
        {
            if (A[idxa] == '(')
                idxa = proceed(idxa, A);
            else
            {
                idxb = proceed(idxb, B);
            }
            ans.push_back(A[idxa]);
        }
        idxa++;
        idxb++;
        //cout << ans << endl;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3272
#include<iostream>
#include<string>
using namespace std;
int main(){
  string s;
  int n, x;
  int *l;
  l = new int[n];
  
  cin >> n >> x;
  for(int i=0; i<n; i++){
	  cin >> l[i];
  }

  int *d;
  d = new int[n];
  int temp = 0;
  for(int i=0; i<n; i++){
    temp += l[i];
    d[i] = temp;
  }  
  
  int ct=0;
  for(int i=0; i<n; i++){
    if(d[i]<=x) ct++;
  }  
  cout << ct+1 << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  double a,v,b,w,t;
  cin>>a>>v>>b>>w>>t;
  double c;
  if(w>v)
    cout<<"NO";
  else if(w<v)
  {
    c=(b-a)/(v-w);
    if(abs(c)<=t)
      cout<<"YES";
    else
      cout<<"NO";
  }
  else
  {
    if(a==b)
      cout<<"YES";
    else
      cout<<"NO";
  }
}


Measured memory_bytes: 3724
import java.util.Scanner;

public class Main {

	static char[][] table = new char[6][7];
	static{
		int cnt=0;
		for(int i = 1;i<7;i++){
			for(int j =1;j<6;j++){
				table[j][i]=(char)('a'+cnt++);
			}
		}
		table[2][6]='.';
		table[3][6]='?';
		table[4][6]='!';
		table[5][6]=' ';
	}
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		label:while(cin.hasNext()){
			String str = cin.next();
			if(str.length()%2!=0){
				System.out.println("NA");
				continue;
			}
			String ans = "";
			for(int i = 0;i<str.length();i+=2){
				int a = str.charAt(i)-'0';
				int b = str.charAt(i+1)-'0';
				//System.out.println(a + ""+ b);
				if(b < 1 || b > 5 || a < 1 || a > 6){
					System.out.println("NA");
					continue label;
				}
				else{
					ans += table[b][a];
				}
			}
			System.out.println(ans);
		}
	}

}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
using P=pair<int,int>;
ll __lcm(ll a,ll b){
    ll ab=a*b;
    ll g=__gcd(a,b);
    return ab/g;
}
int two(ll x){
    int cnt=0;
    while(x%2==0){
        x/=2;
        cnt++;
    }
    return cnt;
}
int main() {
    ll n,m;cin>>n>>m;
    vector<ll> a(n);
    for(ll i=0;i<n;i++){
        cin>>a[i];
    }
    int flag=1;
    for(int i=0;i<n-1;i++){
        if(two(a[i])!=two(a[i+1])) flag=0;
    }
    if(flag==0){
        cout<<0<<endl;
    }else{
        ll l=1;
        for(ll i=0;i<n;i++){
            l=__lcm(l,a[i]);
            if(l/2>m){
                cout<<0<<endl;
                return 0;
            }
        }
        ll ans;
        
        ans=(m-(l/2))/l+1;
        cout<<ans<<endl;
        }

}

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

int main(void){
   
    string S,T,U;
    int A,B;
    cin >> S >> T >> A >> B >> U;
    if(U == S){
        A--;
    }
    else{
        B--;
    }
    
    cout << A << " " << B <<endl;
}

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

string divide[4] = {"dream", "dreamer", "erase", "eraser"};

int main() {
    string S;
    cin >> S;

    // 後ろから解くかわりにすべての文字列を「左右反転」する
    reverse(S.begin(), S.end());
    for (int i = 0; i < 4; ++i) reverse(divide[i].begin(), divide[i].end());

    // 端から切っていく
    bool can = true;
    for (int i = 0; i < S.size();) {
        bool can2 = false; // 4 個の文字列たちどれかで divide できるか
        for (int j = 0; j < 4; ++j) {
            string d = divide[j];
            if (S.substr(i, d.size()) == d) { // d で divide できるか
                can2 = true;
                i += d.size(); // divide できたら i を進める
            }
        }
        if (!can2) { // divide できなかったら
            can = false;
            break;
        }
    }

    if (can) cout << "YES" << endl;
    else cout << "NO" << endl;
}


Measured memory_bytes: 512
#include <stdio.h>

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const ll maxn = 2e5 + 111;
const ll mod = 1e9 + 7;
int f[maxn];
int sizze[maxn];
int F(int x) { return f[x] == x ? x : f[x] = F(f[x]); }
void merge(int x, int y) {
    if(F(x)==F(y)) return;
    sizze[F(y)] += sizze[F(x)];
    f[F(x)] = F(y);
}
int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; ++i) {
        f[i] = i;
        sizze[i] = 1;
    }
    for (int i = 1; i <= m; ++i) {
        int u, v;
        scanf("%d%d", &u, &v);
        merge(u, v);
    }
    int maxx = 0;
    for (int i = 1; i <= n; ++i) {
        maxx = max(maxx, sizze[F(i)]);
    }
    printf("%d\n", maxx);
    return 0;
}

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

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

    cout << max({a + b, a - b, a * b}) << '\n';
    return (0);
}


Measured memory_bytes: 3552
m=10**9+7
n=int(input())
s=0
d=[]
for i in range(n):
 s+=pow(i+1,m-2,m)
 d.append(s)
i=r=0
f=1
for a in input().split():
 r+=int(a)*(d[i]+d[~i]-1)
 i+=1
 f=f*i%m
print(r*f%m)

Measured memory_bytes: 16128
/*
P135
POJ 2718 Smallest Difference
*/


#include <iostream>
#include <map>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <functional>
#include <string.h>
using namespace std;

int a[10];
void read()
{
    for(int i=0; i<10; ++i)
        scanf("%d", a+i);
}

void solve()
{
    int x1=0, x2=0;
    bool ans = true;
    for(int i=0; i<10; ++i)
    {
        if(x1 < x2) swap(x1, x2);
        if(x1 < a[i]) x1 = a[i];
        else if(x2 < a[i]) x2 = a[i];
        else {ans = false; break;}
    }
    if(ans) printf("YES\n");
    else printf("NO\n");
}



vector<int> L_bucket;
vector<int> R_bucket;

bool dfs2(int d){
    if(d == 10) return true;
    bool flag = false;
    if(L_bucket.size() == 0 || L_bucket.back() < a[d]){
        L_bucket.push_back(a[d]);
        flag = dfs2(d+1);
        L_bucket.pop_back();
    }
    if(flag) return true;
    if(R_bucket.size() == 0 || R_bucket.back() < a[d]){
        R_bucket.push_back((a[d]));
        flag = dfs2(d+1);
        R_bucket.pop_back();
    }
    if(flag) return true;
    return false;
}

void solve2()
{
    if(dfs2(0)) printf("YES\n");
    else printf("NO\n");
}

int main()
{
    int T;
    scanf("%d", &T);
    while(T--){
        read();
        solve2();
    }
}

Measured memory_bytes: 1188
N, K = map(int, raw_input().split())
S = list(raw_input())

if S[K-1] == 'A':
    S[K-1] = 'a'
elif S[K-1] == 'B':
    S[K-1] = 'b'
else:
    S[K-1] = 'c'

print "".join(S)

Measured memory_bytes: 2568
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    // length N+1
    val monstersPerCity = readLine()!!.split(" ").map { it.toInt() }.toMutableList()

    // length N
    val heroPowers = readLine()!!.split(" ").map { it.toInt() }.toMutableList()

    var monsterKillCount = 0.toLong()

    for (i in 0 until N) {
        val left = Math.min(heroPowers[i], monstersPerCity[i])
        heroPowers[i] -= left
        monstersPerCity[i] -= left
        monsterKillCount += left

        val right = Math.min(heroPowers[i], monstersPerCity[i + 1])
        heroPowers[i] -= right
        monstersPerCity[i + 1] -= right
        monsterKillCount += right
    }

    println(monsterKillCount)
}



Measured memory_bytes: 85044
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;


template<unsigned P> struct ModInt {
  using M = ModInt;
  unsigned v;
  ModInt() : v(0) {}
  template<class Int> ModInt(Int x) : v(x >= 0 ? x % P : -x % P ? P - -x % P : 0) {}
  constexpr ModInt(unsigned v, int) : v(v) {}
  static constexpr unsigned p() { return P; }
  M operator+() const { return *this; }
  M operator-() const { return {v ? P - v : 0, 0}; }
  explicit operator bool() const noexcept { return v; }
  bool operator!() const noexcept { return !(bool) *this; }
  M operator*(M rhs) const { return M(*this) *= rhs; }
  M operator/(M rhs) const { return M(*this) /= rhs; }
  M operator+(M rhs) const { return M(*this) += rhs; }
  M operator-(M rhs) const { return M(*this) -= rhs; }
  bool operator==(M rhs) const { return v == rhs.v; }
  bool operator!=(M rhs) const { return !(*this == rhs); }
  M& operator*=(M rhs) { v = (unsigned long long) v * rhs.v % P; return *this; }
  M& operator/=(M rhs) { return *this *= rhs.inv(); }
  M& operator+=(M rhs) { v = rhs.v < P - v ? v + rhs.v : v - (P - rhs.v); return *this; }
  M& operator-=(M rhs) { v = rhs.v <= v ? v - rhs.v : v + (P - rhs.v); return *this; }
  M inv() const {
    int a = v, b = P, x = 1, u = 0;
    while (b) {
      int q = a / b;
      swap(a -= q * b, b);
      swap(x -= q * u, u);
    }
    assert(a == 1);
    return x;
  }
  template<class Int> M pow(Int n) const {
    n = n >= 0 ? n % (P - 1) : P - 1 - -n % (P - 1);
    M res = 1;
    for (M a = *this; n; a *= a, n >>= 1) if (n & 1) res *= a;
    return res;
  }
  template<class Int> friend M operator*(Int lhs, M rhs) { return M(lhs) *= rhs; }
  template<class Int> friend M operator/(Int lhs, M rhs) { return M(lhs) /= rhs; }
  template<class Int> friend M operator+(Int lhs, M rhs) { return M(lhs) += rhs; }
  template<class Int> friend M operator-(Int lhs, M rhs) { return M(lhs) -= rhs; }
  friend ostream& operator<<(ostream& os, M rhs) { return os << rhs.v; }
  friend istream& operator>>(istream& is, M& rhs) { lint x; is >> x; rhs = x; return is; }
  template<class Int> friend bool operator==(Int lhs, M rhs) { return M(lhs) == rhs; }
  template<class Int> friend bool operator!=(Int lhs, M rhs) { return !(lhs == rhs); }
};
using Mint = ModInt<998244353>;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  V< bitset<300> > a(n);
  for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) {
    int x; cin >> x;
    a[i][j] = x;
  }
  int r = 0;
  for (int j = 0; j < m; ++j) {
    for (int i = r + 1; i < n; ++i) if (a[i][j]) {
      swap(a[r], a[i]);
      break;
    }
    if (!a[r][j]) continue;
    for (int i = 0; i < n; ++i) if (i != r and a[i][j]) {
      a[i] ^= a[r];
    }
    if (++r == n) break;
  }
  Mint res = Mint(2).pow(n + m - 1) * (1 - Mint(2).pow(-r));
  cout << res << '\n';
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int main() {

  int n, a, b;
  scanf("%d%d%d", &n, &a, &b);
  static int c[3];
  while (n--) {
    int v;
    scanf("%d", &v);
    if (v <= a)
      ++c[0];
    else if (v <= b)
      ++c[1];
    else
      ++c[2];
  }
  printf("%d\n", *min_element(c, c + 3));

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define ALL(x) (x).begin(),(x).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
using namespace std;
typedef long long ll;

class UnionFind {
  std::vector<int> p;

public:
  UnionFind(int n) : p(n, -1) {}

  // find: x を含む集合の代表元を返す
  int root(int x) { return (p[x] < 0) ? x : (p[x] = root(p[x])); }

  bool same(int x, int y) { return root(x) == root(y); }

  // union:
  // 既に x を含む集合と y を含む集合が同じ集合である場合は false を返し，
  // そうでない場合は true を返す．
  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (p[y] < p[x]) std::swap(x, y);
    p[x] += p[y];
    p[y] = x;
    return true;
  }

  int size(int x) { return -p[root(x)]; }
};

int N,M;
vector<int> A,B;
vector<ll> ans;

int main()
{
  cin >> N >> M;
  A.resize(M);
  B.resize(M);
  ans.resize(M);

  REP(i,0,M) {
    cin >> A[i] >> B[i];
    A[i]--; B[i]--;
    // int A,B;
    // cin >> A >> B;
  }

  ans[M-1] = (ll)N * (N-1) / 2;  // どの橋も行き来できない

  // 橋が0個の状態から増えていく
  UnionFind uf(N);
  for(int i = M-2; i >= 0; --i) {
    if (uf.same(A[i+1], B[i+1])) {
      ans[i] = ans[i+1];
    } else {
      ans[i] = ans[i+1] - uf.size(A[i+1]) * uf.size(B[i+1]);
      uf.unite(A[i+1], B[i+1]);
    }
  }

  REP(i,0,M) cout << ans[i] << endl;

  return 0;
}


Measured memory_bytes: 3328
n = int(input())
Z = [0 for i in range(n)]
W = [0 for i in range(n)]
for i in range(n):
    xi, yi = map(int, input().split())
    Z[i] = xi + yi
    W[i] = xi - yi

ans = max(max(Z)-min(Z), max(W)-min(W))
print(ans)

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

int main(){
  int n;
  cin >> n;
  vector<int> a(n),b(n+1);
  rep(i,n) cin >> a[i];
  
  ll sum=0;
  rep(i,n){
    sum+=b[a[i]];
    b[a[i]]++;
  }
  rep(i,n) cout << sum-b[a[i]]+1 << "\n";  
  
  return 0;
}

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

#define fi first
#define se second
#define pb push_back
#define dbg(x) cout << #x << " = " << x << endl
#define all(x) x.begin(), x.end()

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;

int n;
const ll INF = 1e18;
vi valor(105), costo(105);
vector<vector<ll>> dp(105, vector<ll>(1e5 + 5, -1));

ll sol(int i, int j){
    if(j < 0) return -INF;
    if(j == 0 || i == n) return 0;
    if(dp[i][j] != -1) return dp[i][j];
    return dp[i][j] = max(sol(i + 1, j - costo[i]) + valor[i], sol(i + 1, j));
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
    #else
        #define endl '\n'
    #endif

    int w;
    cin >> n >> w;
    for(int i = 0; i < n; ++i){
        cin >> costo[i] >> valor[i];
    }
    cout << sol(0, w) << endl;
    return 0;
}





Measured memory_bytes: 86196
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <utility>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
typedef long long int ll;

int main() {
  int N;
  cin>>N;
  
  for(int i=1;i<=N;++i){
    int price=i*1.08;
    if(price==N){
      cout<<i<<endl;
      return 0;
    }
  }
  
  cout<<":("<<endl;
  return 0;
    
  
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
typedef unsigned long long ull;

int main()
{
    ull ans=0,n;
    scanf("%llu", &n);
    // for (i = 1; i < n;i++)
    // {
    //     ans += i;
    // }
    ans = (n * (n - 1)) / 2;
    printf("%llu", ans);
    return 0;
}

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

int main(){
    int n;
    cin>>n;
    int count=0;
    // This is brute force.
    // for(int i=1;i<n;i++){
    //     for(int j=1;j<n;j++){
    //         for(int k=1;k<n;k++){
    //             if(i*j+k==n)
    //             count++;
    //         }
    //     }
    // }

    // for(int i=1;i<n;i++){
    //     count+=(n-1)/i;
    // }

    for(int i=1;i<n;i++){
        for(int j=1;j*i<n;j++)
        count++;
    }
    cout<<count<<"\n";
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std; inline void fileio(const char* in, const char* out) { freopen(in, "r", stdin); freopen(out, "w", stdout); } 
#define TD typedef
#define forx(i,n) for(int i = 0; i < (n); ++i)
#define forxr(i,n) for(int i = (n)-1; i >= 0; --i)
TD long long ll; TD long double ld; TD pair<int,int> pii; TD pair<ll,ll> pll; TD vector<int> VI; TD vector<bool> VB; TD vector<ll> VL;
const char nl = '\n'; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fll; const ld EPS = 1e-9, PI = acos(-1);
#define ff first
#define ss second
#define all(c) c.begin(),c.end()

const int N = 1 << 19;
struct seg {
  bitset<2*N> t;
  void update(int l, int i=1, int s=0, int e=N) {
    const int r = l+1;
    if (r <= s || e <= l) return;
    if (s+1 == e) {
      assert(s == l);
      t.flip(i);
      return;
    }
    int mid = (s+e)/2;
    update(l,i*2,s,mid);
    update(l,i*2+1,mid,e);
    t[i] = t[i*2] | t[i*2+1];
  }
  bool query(int l, int r, int i=1, int s=0, int e=N) {
    if (r <= s || e <= l) return false;
    if (l <= s && e <= r) return t[i];
    int mid = (s+e)/2;
    return query(l,r,i*2,s,mid) || query(l,r,i*2+1,mid,e);
  }
} segs[26];

int main() {
  atexit([](){ cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << nl; });
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cout << fixed << setprecision(12);
  // Emily <3
  int n, q;
  cin >> n;
  string s; cin >> s;
  for (int i = 0; i < n; ++i) {
    segs[s[i]-'a'].update(i);
  }
  cin >> q;
  while (q--) {
    int t;
    cin >>t;
    if (t == 1) {
      int i; char c;
      cin >> i >> c;
      i--;
      if (s[i] != c) {
        segs[s[i]-'a'].update(i);
        s[i] = c;
        segs[s[i]-'a'].update(i);
      }
    } else {
      int l, r;
      cin >> l >> r;
      int ans = 0;
      for (int c = 0; c < 26; ++c) {
        ans += segs[c].query(l-1, r);
      }
      cout << ans << nl;
    }
  }
  return 0;
}



Measured memory_bytes: 4252
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <climits>

using namespace std;

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

typedef long long LL;
typedef vector<int> VI;

int main() {
  int H, N;
  cin >> H >> N;
  vector<int> A(N);
  vector<int> B(N);
  for (int i = 0; i < N; i++) cin >> A[i] >> B[i];
  vector<int> dp(10000 + 1, 0);
  for (int h = 1; h <= H; h++) {
    int minv = INT_MAX;
    for (int i = 0; i < N; i++) {
      int v;
      if (h < A[i]) {
        v = B[i];
      } else {
        v = dp[h-A[i]] + B[i];
      }
      minv = min({v, minv});
    }
    dp[h] = minv;
  }
  cout << dp[H] << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
     
     
//#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define sd(x) scanf("%d",&x)
#define sld(x) scanf("%lld",&x)
#define pld(x) printf("%lld\n",x)
#define pd(x) printf("%d\n",x)
     
     
int main(){
            
	string s;

	cin >> s;

	int ocount = 0, xcount = 0;

	for(int i = 0; i < s.size() ; i++){
		if(s[i] == 'o')ocount++;
		else xcount++;

	}          

	if(ocount >= 8 || ocount + 15 - s.size() >= 8)printf("YES\n");
	else printf("NO\n");
     
     
        
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <bitset>
#include <tuple>
#include <cmath>
#include <complex>
#include <algorithm>
#include <utility>
#include <regex>
#include <cstdint>
#include <numeric>
#include <functional>
#include <cassert>

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

constexpr ll INF = 1'000'000'000'000'000'000;
namespace utils{
#define ALL(x) begin(x), end(x)
#define rALL(x) rbegin(x), rend(x)
    template<class T, class Compare> using p_queue = priority_queue<T, vector<T>, Compare>;
    template<class T> using min_queue = p_queue<T, greater<T>>;
    template<class T> using max_queue = p_queue<T, less<T>>;

    template<class T> bool min_update(T& X, const T& A){ if(X > A) {X = A; return true;} return false; }
    template<class T> bool max_update(T& X, const T& A){ if(X < A) {X = A; return true;} return false; }
    using V_Set = unordered_set<int>;
    using E_Set = unordered_map<int, V_Set>;

    ll operator"" _64(unsigned long long x){ return ll(x); }
    ull operator"" _64u(unsigned long long x){ return ull(x); }

    template<class T>
    vector<T> make_vector(int n, T t){
        return vector<T>(n, t);
    }
    template<class ...Ts>
    auto make_vector(int n, Ts ... ts){
        return vector<decltype(make_vector(ts...))>(n, make_vector(ts...));
    }

    template<class T>
    ostream& operator<<(ostream& os, const vector<T>& v){
        for (auto &&x : v) { os << x << ' '; } cout << endl; return os ;
    }
}
using namespace utils;

class solver{
    istream& is;
    ostream& os;

public:
    solver(istream& I, ostream& O) :is(I), os(O) {}
    void run(){
        ll N;
        is >> N;
        if(!is) return;
        string S;
        is >> S;
        int count = 0;
        char p = 0;
        for (auto &&c : S) {
            if(p != c){
                count++;
            }
            p = c;
        } // end c
        os << count << endl;

    }
};

int main(int argc, char *argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(16) << scientific;
#ifdef DEBUG
    string test_cases = "test_C.txt";
    cerr << test_cases << " -->" << endl;
    auto fs = fstream(test_cases, fstream::in);
    int loop = 0;
    while(fs) {
        loop++;
        cout << '#' << loop << "#------\n";
        solver(fs, cout).run();
    }
    if(loop <= 1) {
        cout << "===" << endl;
        while(cin) solver(cin, cout).run();
    }
#else
    solver(cin, cout).run();
#endif
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)

const ll mod = 1e9+7;
const ll INF = -1*((1LL<<63)+1);
const int inf = -1*((1<<31)+1);

using namespace std;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(20);
    int K,X;
    cin >> K >> X;
    if(K*500 >= X){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
from scipy.sparse import*;f=lambda*z:map(int,raw_input().split());n,=f();a,b=zip(*map(f,[0]*~-n));g,h=csgraph.dijkstra(csr_matrix(([1]*~-n,(a,b)),[n+1]*2),0,[1,n]);print'FSennunkeec'[sum(g[i]>h[i]for i in range(n+1))*2>=n::2]

Measured memory_bytes: 37724
USE_STDIO = False

if not USE_STDIO:
    try: import mypc
    except: pass

def main():
    n, x = map(int, input().split(' '))
    A = list(map(int, input().split(' ')))
    A.sort()
    ans = 0
    for i, a in enumerate(A):
        if a > x: break
        x -= a
        if x == 0 or i != len(A) - 1:
            ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
n,m,x = [int(i)  for i in input().split()]
a=[list(map(int,input().split())) for i in range(n)]

l=[]
suml=[]
for  i in range(2**n):
  bag=[0]*n
  #print("pattern {}: ".format(i), end="")
  for j in range(n):
    if((i >> j) & 1):
      bag[j]=1
      
  l.append(bag)
  
for bag in l:
  ll=[0]*m
  s=0
  for b in range(len(bag)):
    if bag[b] == 0:
      continue
    #print("bag: ", bag, b)
    #print("sum:", s)
    s+=a[b][0]
    for im in range(1, m+1):
      #print("im", im)
      ll[im-1] += a[b][im]
      #print(ll)
    if len([i for i in ll if i >= x]) == m:
      suml.append(s)
      #print("money: ", s)

if suml == []:
  print(-1)
else:
  print(min(suml))


Measured memory_bytes: 10508
#include<stdio.h>
#include<string.h>
int map[19][19],dp[19][19];
int main(){
	int i,j,x,y;
	long long int ans;
	
	while(1){
		scanf("%d%d",&x,&y);
		if(x+y==0)break;
		memset(dp,0,sizeof(dp));
		memset(map,0,sizeof(map));
		ans=0;
		for(i=1;i<=y;i++){
			for(j=1;j<=x;j++){
				scanf("%d",&map[i][j]);
				if(i==1 && map[1][j]==0)dp[1][j]=1;
			}
		}
		for(i=1;i<=y;i++){
			for(j=1;j<=x;j++){
				if(map[i][j]==0){
					if(map[i+1][j]!=1)dp[i+1][j]+=dp[i][j];
					if(i<y){
						if(map[i+1][j-1]==0)dp[i+1][j-1]+=dp[i][j];
						if(map[i+1][j+1]==0)dp[i+1][j+1]+=dp[i][j];
					}
				}
				else if(map[i][j]==2){
					dp[i+2][j]+=dp[i][j];
				}
				//printf("%2d ",dp[i][j]);
			}
			//printf("\n");
		}
		for(j=1;j<=x;j++){
			//ans+=dp[y+1][j]+dp[y+2][j];
			if(map[y+1][j]!=1)ans+=dp[y+1][j];
			if(map[y+2][j]!=1)ans+=dp[y+2][j];
			//printf("%2d ",dp[y+1][j]);
		}
		//printf("\n");
		//for(j=1;j<=x;j++)printf("%2d ",dp[y+2][j]);
		//printf("\n");
		printf("%lld\n",ans);
	}
	
	return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include<algorithm>
using namespace std;
int N_MAX = 10001;
int main()
{
  int n,t,i,j,k;
  int c[N_MAX];
  cin >> n;
  fill(c,c+n+1,0);
  for(i=1;i<=100;i++)
    for(j=1;j<=100;j++)
      for(k=1;k<=100;k++){
        t=i*i+j*j+k*k+i*j+j*k+k*i;
        if(t<=n)
          c[t]++;
      }
  for(i=1;i<=n;i++)
    cout << c[i] << endl;
  return 0;
}

Measured memory_bytes: 3532
N,A,B=map(int,input().split())
ans=0
def FindSumOfDigits(x):
  count=0
  while x>0:
    count+=x%10
    x=x//10
  return count

for n in range(1,N+1):
  count=FindSumOfDigits(n)
  if A<=count<=B:
    ans+=n
print(ans)

Measured memory_bytes: 3060