akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010

/* Aho Corasick */

struct ACNode{
  int val;
  ACNode *next[26], *failure;
  
  ACNode():val(0) { memset(next,0,sizeof(next)); }
  
  void insert(char *s){
    if(!*s){ val++; return; }
    int al = *s-'a';
    if(next[al]==NULL) next[al] = new ACNode;
    next[al]->insert(s+1);
  }

  ACNode *nextNode(char c){
    int al = c - 'a';
    if (next[al]) return next[al];
    return failure == this ? this : failure->nextNode(c);
  }
};

struct AhoCorasick{
  ACNode *node;

  AhoCorasick(){node = new ACNode;}
  
  void insert(char *s) {
    node->insert(s);
  }
  
  void build() {
    queue<ACNode*> que;
    que.push(node);
    node->failure = node;
    
    while(que.size()){
      ACNode *p = que.front();
      que.pop();
      
      for(int i=0;i<26;i++){
        if(p->next[i]){
          ACNode *failure = p->failure;
          while(!failure->next[i] && failure != node){
            failure = failure->failure;
          }
          if (failure->next[i] && failure != p){
            p->next[i]->failure = failure->next[i];
            p->next[i]->val += failure->next[i]->val;
          }else{
            p->next[i]->failure = node;
          }
          que.push(p->next[i]);
        }
      }
    }
  }
};



int main(){
  char s[SIZE], p[SIZE];
  int n;
  AhoCorasick ac;
  
  scanf("%s%d", s, &n);
  
  for(int i=0;i<n;i++){
    scanf("%s", p);
    ac.insert(p);
  }

  ac.build();

  ACNode *now = ac.node;
  int ans = 0;
  for(int i=0;s[i] != '\0';i++){
    now = now->nextNode(s[i]);
    if(now->val){
      ans++;
      now = ac.node;
    }
  }

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




Measured memory_bytes: 22892
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>
typedef long long ll;


#define REP(i, N) for (int i = 0; i < (N); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((int)(x).size())
//vvintを作る　マクロで　 #define vvint(N,M) vector<vector<int>>

using namespace std;


int main(){
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    string RandB;
    cin >> RandB;
    int countR = 0;
    for(int i = 0; i < N;i++){
        if(RandB[i] == 'R') countR++;
    }
    if(countR > N-countR) cout << "Yes" << endl;
    else cout << "No" << endl;
    

    return 0;
}

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

int main()
{
  int a,b,c,d,e,f;
 cin >>a;
  cin >>b;
  cin >>c;
  cin >>d;
  e=(a+b);
  f=(c+d);
  
  if (e>f)
  {
    cout << "Left"<< endl;
  }
  if (f>e)
  {
    cout << "Right"<< endl;
  }
  if (e==f)
  {
    cout << "Balanced"<< endl;
  }
  return 0;
}

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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

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

    Int(n);
    set<string> yui;
    rep(i, n) {
        string st;
        cin >> st;
        yui.insert(st);
    }

    cout << yui.size() << endl;
        

    return 0;
}


Measured memory_bytes: 19280
/**
 * @brief  : c++ code for AtCoder
 * @author : rk222
 * @created: 2019.05.25 20:43:55
 */

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<int, P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i, x) for (int i = 0; i < x; i++)
#define rep1(i, x) for (int i = 1; i <= x; i++)
#define rrep(i, x) for (int i = x - 1; i >= 0; i--)
#define rrep1(i, x) for (int i = x; i > 0; i--)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define uniq(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define mp1(a, b, c) P1(a, P(b, c))

#define disp(x) cout << #x << ": " << x << endl
#define disp_vec(v)                                                                           \
    cout << #v << ":";                                                                        \
    rep(i, v.size()) cout << " " << v[i];                                                     \
    cout << endl

const int INF = 100000000;
const int M = 100000000;
const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int dir_8[8][2] = {{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};

/* ------------------------------------- */

int main() {
    ll r, d, x;
    scanf("%lld%lld%lld", &r, &d, &x);
    rep(i, 10) {
        x = r * x - d;
        printf("%lld\n", x);
    }

    /* --------------------------------- */
    return 0;
}

Measured memory_bytes: 256
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() //sortなどの引数を省略したい
#define SIZE(x) ll(x.size()) //sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define Umap unordered_map
#define Uset unordered_set

signed main(){
    //入力の高速化用のコード
    //ios::sync_with_stdio(false);
    //cin.tie(nullptr);
  	int a;
  cin >> a;
  cout << (a)+pow(a,2)+pow(a,3);
}

Measured memory_bytes: 4184
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> PII;

// chmax, chmin
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;
}

template <typename T>
function<T(T, T)> op_max = [](T a, T b) -> T { return max(a, b); };
template <typename T>
function<T(T, T)> op_min = [](T a, T b) -> T { return min(a, b); };

template <typename T>
function<T(T, T)> op_sum = [](T a, T b) -> T { return a + b; };

namespace detail {
template <typename T, std::size_t NDIMS>
struct vector_builder {
  using type = std::vector<typename vector_builder<T, NDIMS - 1>::type>;

  static type make(std::vector<std::size_t> dims, const T& v = {}) {
    const auto vec = std::vector<T>(dims.empty() ? 0 : dims.back(), v);
    if (!dims.empty()) dims.pop_back();
    return vector_builder<std::vector<T>, NDIMS - 1>::make(dims, vec);
  }
};

template <typename T>
struct vector_builder<T, 1> {
  using type = std::vector<T>;

  static type make(std::vector<std::size_t> dims, const T& v = {}) {
    return type(dims.empty() ? 0 : dims.back(), v);
  }
};
}  // namespace detail

template <typename T, typename... SIZE_T>
auto exvector(const T& v, SIZE_T... dims) {
  static_assert(sizeof...(dims) != 0, "invalid dimension");
  std::vector<std::size_t> vec_dims{dims...};
  return detail::vector_builder<T, sizeof...(dims)>::make(vec_dims, v);
}

using namespace std;
//********************  dumps ************************//

template <typename T>
void dump(const T& data, vector<int>& iter) {
  cout << data << " ";
}
template <typename T>
void dump(const vector<T>& data, vector<int>& iter) {
  for (auto elem : data) dump(elem, iter);
  cout << endl;
}

template <typename T>
void dump(const vector<vector<T>>& data, vector<int>& iter) {
  for (auto elem : iter) {
    cout << "[" << elem << "]";
  }
  cout << endl;
  for (int i = 0; i < data.size(); i++) {
    iter.push_back(i);
    dump(data[i], iter);
    iter.pop_back();
  }
  cout << endl;
}

template <typename T>
void dump(const vector<T>& data, int dummy) {
  for (int i = 0; i < data.size(); i++) {
    cout << "[" << i << "] " << data[i] << endl;
  }
}
template <typename T>
void dump(const T& data) {  // T : data, U = base type val.
  vector<int> iter;
  dump(data, iter);
}
///////////////////////////////////////////////

void solve(string S) {
  int N = S.size();
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    if (S[i] == '0' + i % 2) cnt++;
  }
  cout << min(cnt, N - cnt) << endl;
}

int main() {
  cout << setprecision(10);
  string S;
  cin >> S;
  solve(S);
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <cstring>
#include<vector>
#include <algorithm>
#include<cstdlib>
#include<math.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<n;i++)

int main()
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    ll p, q;
    p = 1;
    rep(i, n) p *= a[i];

    ll count = 0;
    rep(i, n)
    {
        if (a[i] == 0) count++;
    }
    if (count != 0)
    {
        cout << '0' << "\n";
    }
    else
    {
        q = p;
        rep(i, n) q /= a[i];
        if (q == 1 && p <= 1000000000000000000)
        {
            cout << p << "\n";
        }
        else cout << "-1" << "\n";
    }

    return 0;
}

Measured memory_bytes: 4060
inf = 10 ** 15
mod = 10 ** 9 + 7

n,m,q = map(int, input().split())

maps = [[0 for j in range(n)]for i in range(n)]
for i in range(m):
    l,r = map(int, input().split())
    l-=1
    r-=1
    maps[l][r]+=1
c = []
for i in range(n):
    a = [0]
    for j in maps[i]: a.append(a[-1]+j)
    c.append(a)
for i in range(q):
    l,r  = map(int, input().split())
    ans = 0
    for i in range(l-1,r):
        ans += (c[i][r]-c[i][l-1])
    print(ans)

Measured memory_bytes: 56008
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
  cin>>N;
  vector<int> p(N);
  
  int sum=0;
  int max=0;
  
  for(int i=0;i<N;i++){
    cin>>p.at(i);
    sum+=p.at(i);
      
      if(max<=p.at(i)){
        max=p.at(i);
    
  }
}

cout<<sum-max/2<<endl;
}

  
  

Measured memory_bytes: 256
#include<iostream>

using namespace std;

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

    int max1=-1;
    int max2=-4;
    int max_loc;

    int A[N];
    for(int i=0; i<N; i++){
        cin >> A[i];
        if(A[i] > max2){
            if(A[i] > max1){
                max2 = max1;
                max1 = A[i];
                max_loc=i;
            }
            else{
                max2 = A[i];
            }
        }
    }

    for(int i=0 ; i<N; i++){
        if(i == max_loc) cout << max2 << endl;
        else cout << max1 << endl;
    }
    return 0;
}

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

using namespace std;

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;

const ll OO = (ll) 1e18;

ll mult(ll a, ll b) {
  if (a == 0 || b == 0) {
    return 0;
  }
  if (a == OO || b == OO) {
    return OO;
  }
  ll p = a * b;
  if (p % a == 0 && p / a == b && p <= OO) {
    return p;
  } else {
    return OO;
  }
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  ll x, i = 0;
  cin >> x;
  vector<ll> a;
  while (1) {
    ll p = 1;
    for (int j = 1; j <= 5; j++) {
      p = mult(p, i);
    }
    if (p == OO) {
      break;
    }
    a.push_back(p);
    i++;
  }
  int k = (int) a.size() - 1;
  for (int i = 0; i <= k; i++) {
    for (int j = 0; j <= k; j++) {
      if (a[i] - a[j] == x) {
        cout << i << " " << j << "\n";
        return 0;
      }
      if (a[i] + a[j] == x) {
        cout << i << " -" << j << "\n";
        return 0;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 3720
import sys
sys.setrecursionlimit(10**7)
n,m=map(int,input().split())
g=[[] for i in range(1+n)]
dist=[-1]*(1+n)
for i in range(m):
    a,b=map(int,input().split())
    g[a].append(b)
    
def dfs(cur):
    if dist[cur]!=-1:
        return dist[cur]
        
    if not g[cur]:
        dist[cur]=0
    else:
        dist[cur]=1+max([dfs(nb) for nb in g[cur]])
    return dist[cur]

ans=0
for i in range(1,n+1):
    ans=max(ans,dfs(i))

print(ans)

Measured memory_bytes: 177568
package main

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

var sc = bufio.NewScanner(os.Stdin)

// Binary indexed tree

type BITree struct {
	bit []int
	M int
}

func newBITree(m int) *BITree {
	b := new(BITree)
	b.M = m
	b.bit = make([]int, m + 1)
	return b
}

func (b BITree) sum(i int) int {
	if (i <= 0) {
		return 0
	}
	return b.bit[i] + b.sum(i - (-i & i))
}

func (b BITree) add(i int, x int) {
	if (i > b.M) {
		return
	}
	b.bit[i] += x
	b.add(i + (-i & i), x)
}

type Section struct {
	start int
	end int
}

func main() {
	N, M, l, r := scan()

	// 区間[l,r]を長さによって分類する
	sectionsGroup := make([][]Section, M + 1)
	for i := 0; i <= M; i++ {
		sectionsGroup[i] = make([]Section, 0)
	}
	for n := 0; n < N; n++ {
		length := r[n] - l[n] + 1
		section := Section{
			start: l[n],
			end: r[n],
		}
		sectionsGroup[length] = append(sectionsGroup[length], section)
	}

	// 必ず通る区間たち
	base := N
	// Binary indexed tree
	bit := newBITree(M+2)

	answers := make([]int, M + 1)

	// BIT使って頑張る
	for d := 1; d <= M; d++ {
		sections := sectionsGroup[d - 1]
		for _, section := range sections {
			start := section.start
			end := section.end
			bit.add(start, 1)
			bit.add(end + 1, -1)
		}
		base -= len(sections)
		answers[d] = base
		for pos := 0; pos <= M; pos += d {
			answers[d] += bit.sum(pos)
		}
	}

	for d := 1; d <= M; d++ {
		fmt.Println(answers[d])
	}
}


func scan() (int, int, []int, []int) {
	var N, M int
	sc.Scan()
	nm := strings.Split(sc.Text(), " ")
	N, _ = strconv.Atoi(nm[0])
	M, _ = strconv.Atoi(nm[1])
	l := make([]int, N)
	r := make([]int, N)
	for i := 0; i < N; i++ {
		sc.Scan()
		lr := strings.Split(sc.Text(), " ")
		l[i], _ = strconv.Atoi(lr[0])
		r[i], _ = strconv.Atoi(lr[1])
	}
	return N, M, l, r
}


Measured memory_bytes: 22400
# coding: utf-8
# Your code here!

import sys
readline = sys.stdin.readline
read = sys.stdin.read

#n,*a = [int(i) for i in read().split()]
#a = [int(i) for i in readline().split()]
#n = int(input())

def solve():
    from bisect import bisect_right, bisect_left
    
    n,k,*a = map(int,read().split())
    a.sort()
    
    #v = [a[i]*a[j] for i in range(n) for j in range(i+1,n)]
    #v.sort()
    #print(v)
    #print(v[k-1])
    
    l = bisect_left(a,0)
    r = bisect_right(a,0,lo = l)
    
    a_neg = [-i for i in a[:l][::-1]]
    a_pos = a[r:]
    
    if k <= l*(n-r): # negative
        def check(x): #x 以上は k 個以上あるか？
            res = (n-r)*l
            L = n-r
            v = 0
            for i in a_neg[::-1]:
                V = (x+i-1)//i
                while v < L and a_pos[v] < V:
                    v += 1
                res -= v
            return res >= k
    
        ok = 0
        ng = 10**18
        while ng-ok > 1:
            mid = (ok+ng)//2
            if check(mid): ok = mid
            else: ng = mid
    
        print(-ok)
    
    elif k <= n*(n-1)//2 - l*(l-1)//2 - (n-r)*(n-r-1)//2:
        print(0)
    
    else:
        k -= n*(n-1)//2 - l*(l-1)//2 - (n-r)*(n-r-1)//2
    
        def check(x): #x 以下は k 個以上あるか？
            res = 0
            vn = l-1
            for i,ai in enumerate(a_neg):
                X = x//ai
                while vn and a_neg[vn] > X:
                    vn -= 1            
                #vn = bisect_right(a_neg,x//ai,hi=vn)
                if vn+1 > i+1: res += vn+1-i-1

            vp = n-r-1
            for i,ai in enumerate(a_pos):
                X = x//ai
                while vp and a_pos[vp] > X:
                    vp -= 1            
                #vp = bisect_right(a_pos,x//ai,hi=vp)
                if vp+1 > i+1: res += vp+1-i-1
            return res >= k
        
        ng = 0
        ok = 10**18
        while ok-ng > 1:
            mid = (ok+ng)//2
            if check(mid): ok = mid
            else: ng = mid
    
        print(ok)


solve()





Measured memory_bytes: 103712
#include <bits/stdc++.h>
#define Mashu cout << "UUZ ate it." << endl
#define RE register int
#define ll long long
using namespace std;

inline int read(){
	char ch=getchar();
	int x=0,cf=1;
	while(ch<'0'||ch>'9') {
		if(ch=='-') cf=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9') {
		x=(x<<3)+(x<<1)+(ch^48);
		ch=getchar();
	}
	if (cf < 0) return -x;
	else return x;
}

int G[55];
template<class T> inline void write(T x){
	int g=0;
	do{G[++g]=x%10;x/=10;}while(x);
	for(int i=g;i>=1;--i)putchar('0'+G[i]);putchar('\n');
}

struct edge{
	int to;
	int nxt;
	int w;
}e[400010];

int f[200010], cnt = 0;

void add(int u, int v, int w){
	e[++cnt].to = v;
	e[cnt].w = w;
	e[cnt].nxt = f[u];
	f[u] = cnt;
}

int main(){
	int n;
	cin >> n;
	int qwq = n - 1;
	long long ans = 0;
	for (int i = 1; i <= n; i++){
		ans += qwq / i;
	}
	cout << ans << endl;
	return 0;
	Mashu;
}

Measured memory_bytes: 3632
#include"bits/stdc++.h"

using namespace std;


#define MAX 195

int h;
int w;
char buf[MAX];
vector<string> v;

#define MAX2 21

int dpx[MAX][MAX][MAX];
int dpy[MAX][MAX][MAX];

int wx[MAX][MAX];
int wy[MAX][MAX];

int tmpx[MAX][MAX][MAX];
int tmpy[MAX][MAX][MAX];


int main() {
	cin >> h >> w;
	for (int i = 0; i < h; i++) {
		scanf("%s", buf);
		v.push_back(buf);
	}
	int len = max(h, w);
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			for (int k = j; k < w; k++) {
				if (v[i][k] == v[i][j]) {
					wx[i][j]++;
				}
				else {
					break;
				}
			}
		}
	}
	for (int j = 0; j < w; j++) {
		for (int i = 0; i < h; i++) {
			for (int k = i; k < h; k++) {
				if (v[k][j] == v[i][j]) {
					wy[i][j]++;
				}
				else {
					break;
				}
			}
		}
	}
	memset(dpx, -1, sizeof(dpx));
	memset(dpy, -1, sizeof(dpy));
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			int cm = wx[i][j];
			for (int k = i; k < h; k++) {
				if (v[k][j] != v[i][j])break;
				cm = min(cm, wx[k][j]);
				dpx[i][j][cm] = k;
			}
			for (int k = w; k >= 0; k--) {
				dpx[i][j][k] = max(dpx[i][j][k], dpx[i][j][k + 1]);
			}
		}
	}
	for (int j = 0; j < w; j++) {
		for (int i = 0; i < h; i++) {
			int cm = wy[i][j];
			for (int k = j; k < w; k++) {
				if (v[i][k] != v[i][j])break;
				cm = min(cm, wy[i][k]);
				dpy[i][j][cm] = k;
			}
			for (int k = h; k >= 0; k--) {
				dpy[i][j][k] = max(dpy[i][j][k], dpy[i][j][k + 1]);
			}
		}
	}
	for (int calc = 1; calc < 100; calc++) {
		if (dpx[0][0][w] == h-1) {
			cout << calc-1 << endl;
			return 0;
		}
		memset(tmpx, -1, sizeof(tmpx));
		memset(tmpy, -1, sizeof(tmpy));
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				for (int fix = 1; fix <= w; fix++) {
					if (dpx[i][j][fix] != -1) {
						tmpx[i][j][fix] = dpx[dpx[i][j][fix]+1][j][fix];
					}
				}
				for (int fix = 1; fix <= h; fix++) {
					if (dpy[i][j][fix] != -1) {
						tmpy[i][j][fix] = dpy[i][dpy[i][j][fix]+1][fix];
					}
				}
			}
		}
		for (int loop = 0; loop < 2; loop++) {
			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					for (int k = max(h,w); k >=1; k--) {
						dpx[i][j][k] = max(dpx[i][j][k], tmpx[i][j][k]);
						dpy[i][j][k] = max(dpy[i][j][k], tmpy[i][j][k]);
						dpx[i][j][k] = max(dpx[i][j][k], dpx[i][j][k + 1]);
						dpy[i][j][k] = max(dpy[i][j][k], dpy[i][j][k + 1]);
						if (dpx[i][j][k] != -1) {
							dpy[i][j][dpx[i][j][k] - i + 1] = max(dpy[i][j][dpx[i][j][k] - i + 1], j + k - 1);
						}
						if (dpy[i][j][k] != -1) {
							dpx[i][j][dpy[i][j][k] - j + 1] = max(dpx[i][j][dpy[i][j][k] - j + 1], i + k - 1);
						}
					}
				}
			}
		}
	}
	return 0;
}

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

ll const INF = 40000000000;
ll dp[60][2][2][10];

int main(){
	ll k;
	cin >> k;
	
	ll r = INF;
	ll l = 0;
	
	while(r - l > 1){
		ll m = (r+l)/2;
		//m以下のルンルン数の数をカウントする。
		string s = to_string(m);
		int n = s.size();
		
		//dp初期条件
		for (int x = 0; x <= s[0] - '0'; ++x) {
			if(x == 0){
				dp[0][1][0][0] = 1;
			} else if (x == s[0] - '0'){
				dp[0][0][1][x] = 1;
			}else{
				dp[0][1][1][x] = 1;
			}
		}
		
		for (int i = 1; i <= n-1; ++i) {
			for (int smaller = 0; smaller < 2; ++smaller) {
				for (int zero = 0; zero < 2; ++zero) {
					for (int x = 0; x <= 9 ; ++x) {
						for (int nx = 0; nx <= 9; ++nx) {
							int d = s[i] - '0';
							int nsmaller = smaller;
							if(smaller == 0){
								if(nx > d) continue;
								if(nx == d) nsmaller = 0;
								if(nx < d) nsmaller = 1;
							}
							int nzero = 1;
							if(zero == 0){
								if(nx == 0) nzero = 0;
								dp[i][nsmaller][nzero][nx] += dp[i-1][smaller][zero][x];
							}else{
								if(abs(nx-x) > 1) continue;
								dp[i][nsmaller][nzero][nx] += dp[i-1][smaller][zero][x];
							}
						}
					}
				}
			}
		}
		
		ll count = -1;
		rep(smaller,2){
			rep(zero,2){
				rep(x,10){
					count += dp[n-1][smaller][zero][x];
				}
			}
		}
		
		if(count >= k){
			r = m;
		}else{
			l = m;
		}
		
		rep(i,60) {
			rep(smaller, 2) {
				rep(zero, 2) {
					rep(x, 10) {
						dp[i][smaller][zero][x] = 0;
					}
				}
			}
		}
	}
	
	cout << r << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const ll mod = 1e9+7;
#define rep(i,n) for(int i = 0;i<n;i++)

int main(){
	int a,b;
	cin >> a>>b;
	cout << a*b << endl;

	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n;
    cin >> n;
    map<string, int> mp;
    rep(i, 0, n) {
        string s;
        cin >> s;
        mp[s]++;
    }
    int mx = 0;
    for (auto i : mp) {
        mx = max(mx, i.second);
    }
    for (auto i : mp) {
        if (i.second == mx) {
            cout << i.first << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 25216
#include<stdio.h>

int main(void){
  int n;
  long k;
  scanf("%d%ld", &n, &k);

  int a[n+1];
  int done[n+1];
  a[0] = 0;
  done[0] = -1;
  for(int i = 1; i <= n; i++){
    scanf("%d", &a[i]);
    done[i] = 0;
  }

  long outCycle = 0;
  long cycle = 0;
  long startCycle = 0;

  int now = 1;
  int next = 0;
  done[now] = 0;

  // printf("%d(%d)", now, done[now]);
  for(long i = 1; i <= k; i++){
    next = a[now];
    if(done[next]){
      outCycle = done[next];
      cycle = i - done[next];
      startCycle = next;
      // printf("-> %d(%d)", next, done[next]);
      break;
    }
    now = next;
    done[now] = i;
    // printf("->%d(%d)", now, done[now]);
  }
  // printf("\n");
  // printf("out:%d, cycle:%d, star:%d\n", outCycle, cycle, startCycle);
  if(cycle){
    long kc = k - outCycle;
    long end = kc % cycle;
    if(end == 0)
      end = cycle;
    now = startCycle;
    for(long i = 0; i < end; i++){
      now = a[now];
    }
  }
  // printf("\n");
  printf("%d\n", now);
}


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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;

#define int long long

struct union_find {
    vector<int> par;
    vector<int> rank;
    vector<int> siz;

    union_find(int n) : par(n), rank(n), siz(n) {
        for (int i = 0; i < n; ++i) {
            par[i] = i;
            rank[i] = 0;
            siz[i] = 1;
        }
    }

    void init(int n) {
        for (int i = 0; i < n; ++i) {
            par[i] = i;
            rank[i] = 0;
            siz[i] = 1;
        }
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        } else {
            return par[x] = root(par[x]);
        }
    }

    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return;

        if (rank[x] < rank[y]) {
            par[x] = y;
            siz[y] += siz[x];
        } else {
            par[y] = x;
            siz[x] += siz[y];
            if (rank[x] == rank[y]) rank[x]++;
        }
    }

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

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

signed main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> bridge(m, vector<int>(2));
    for (int i = 0; i < m; ++i) {
        cin >> bridge[i][0] >> bridge[i][1];
        bridge[i][0]--;
        bridge[i][1]--;
    }
    reverse(bridge.begin(), bridge.end());
    union_find u(n);
    vector<int> res(m + 1, 0);;
    for (int i = 1; i <= m; ++i) {
        int a = bridge[i - 1][0];
        int b = bridge[i - 1][1];
        int sa = u.size(a);
        int sb = u.size(b);
        if (u.same(a, b)) {
            res[i] = res[i - 1];
            continue;
        }
        res[i] = res[i - 1] + sa * sb;
        u.unite(a, b);
    }
    reverse(res.begin(), res.end());
    for (int i = 1; i <= m; ++i) {
        cout << n * (n-1) / 2 - res[i] << endl;
    }
}

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

using namespace std;
int main(){
	while(true){
		int n,m;
		cin>>n>>m;
		if(n==0&&m==0)break;
		string text="";
		vector<string> key(n);
		for(auto &s:key)cin>>s;
		text.reserve(5000);
		for(int i=0;i<m;i++){
			string s;cin>>s;
			text+=s;
		}
		m=text.size();

		vector<list<int>> mv(m);
		for(int i=0;i<n;i++)
			for(int j=0,sz=key[i].size();j<m+1-sz;j++){
				bool f=true;
				for(int k=0;k<sz;k++)f&=(key[i][k]==text[j+k]);
				if(f)mv[j].push_back(i);
			}

		int res=0;
		vector<vector<bool>> dp(m+1,vector<bool>(1<<n,false));
		for(int i=0;i<=m;i++)dp[i][0]=true;
		for(int i=0,sz=1<<n;i<m;i++){
			for(int b=0;b<sz;b++)
				if(dp[i][b])
					for(auto &it:mv[i])
						if(((1<<it)&b)==0)
							dp[i+key[it].size()][b|(1<<it)]=true;
			if(dp[i+1][sz-1])res++;
		}
		cout<<res<<endl;
	}
	return 0;
}

Measured memory_bytes: 7628
A,B,Q = map(int, input().split())
S = [int(input()) for _ in range(A)]
T = [int(input()) for _ in range(B)]
import bisect
for _ in range(Q):
    x = int(input())
    s_idx = bisect.bisect_left(S, x)
    t_idx = bisect.bisect_left(T, x)
    if s_idx == A and t_idx == B:
        ans = x-min(S[-1], T[-1])
    elif s_idx == A and t_idx == 0:
        ans = min(x-S[-1]*2+T[0], T[0]*2-x-S[-1])
    elif t_idx == B and s_idx == 0:
        ans = min(x-T[-1]*2+S[0], S[0]*2-x-T[-1])
    elif s_idx == A:
        ans = min(x-min(S[-1], T[t_idx-1]), x-S[-1]*2+T[t_idx], T[t_idx]*2-x-S[-1])
    elif t_idx == B:
        ans = min(x-min(T[-1], S[s_idx-1]), x-T[-1]*2+S[s_idx], S[s_idx]*2-x-T[-1])
    elif s_idx == 0 and t_idx == 0:
        ans = max(S[0], T[0])-x
    elif s_idx == 0:
        ans = min(max(S[0], T[t_idx])-x, S[0]*2-x-T[t_idx-1], x-T[t_idx-1]*2+S[0])
    elif t_idx == 0:
        ans = min(max(T[0], S[s_idx])-x, T[0]*2-x-S[s_idx-1], x-S[s_idx-1]*2+T[0])
    else:
        ans = min(max(S[s_idx], T[t_idx])-x, x-min(S[s_idx-1], T[t_idx-1]), S[s_idx]*2-x-T[t_idx-1], T[t_idx]*2-x-S[s_idx-1])
        ans = min(ans, x-T[t_idx-1]*2+S[s_idx], x-S[s_idx-1]*2+T[t_idx])
    print(ans)

Measured memory_bytes: 12128
"use strict";
    
const main = arg => {
    const a = arg.split("\n")[0].split(" ")[0];
    const b = arg.split("\n")[0].split(" ")[1];
    
    if(a=="D") {
        console.log(b == "H" ? "D" : "H");   
    } else {
        console.log(b);
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;

int main(){

	double a, b, c, C, PI=3.1415926535;;
	double S, L, h;

	cin >> a >> b >> C;

	/* 面積の計算（三角比の高さを求める式）*/
	S = a * b * sin(C*PI/180) / 2;

	/* 周の長さ（余弦定理で未知の辺の長さを求める）*/
	c = sqrt(pow(a,2)+pow(b,2) - 2*a*b*cos(PI*C/180));
	L = a + b + c;

	/* 辺aが底辺のときの長さ（三角比の高さを求める式） */
	h = b * sin(PI*C/180);

	printf("%.8f\n", S);
	printf("%.8f\n", L);
	printf("%.8f\n", h);


	return 0;
}

/************************************************************/
//
// cos(double x)とsin(double x)を使うときの注意点
// （ カッコ内の変数 ）はラジアンを代入すること
//  1° = π/180
//  例：90°のときは　⇒　90°= 90 × π/180
//                    ⇒  90°= π/2
//                    ⇒  答え: π/2
//
/***********************************************************/


Measured memory_bytes: 3452
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
typedef long long ll;
long long mod = 1e9 + 7;
const int iINF = 0x3f3f3f3f;
const long long INF = 1LL << 60;
using namespace std;
using pint = pair<int, int>;

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

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

int main()
{
  int n;
  cin >> n;
  vector<int> a;

  rep(i, n)
  {
    int x;
    cin >> x;
    a.push_back(x);
  }

  sort(a.rbegin(), a.rend());

  ll ans = a[0];
  repi(i, 1, n - 1)
  {
    if (i % 2 == 1)
      ans += a[(i + 1) / 2];
    else
      ans += a[i / 2];
  }

  cout << ans << endl;
  return 0;
}


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


int main() {
    int n[3];
    cin >> n[0] >> n[1] >> n[2];

    sort(n, n+3);
    cout << n[2] * 10 + n[1] + n[0] << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int sx,sy,tx,ty;
    cin>>sx>>sy>>tx>>ty;
    if(sx==tx){
        for(int i=0;i<ty-sy;i++)  cout<<'U';
        for(int i=0;i<ty-sy;i++)  cout<<'D';
        cout<<'L';
        for(int i=0;i<ty-sy;i++)  cout<<'U';
        cout<<"RR";
        for(int i=0;i<ty-sy;i++)  cout<<'D';
        cout<<'L'<<endl;
    }
    else if(sy==ty){
        for(int i=0;i<tx-sx;i++)  cout<<'R';
        for(int i=0;i<tx-sx;i++)  cout<<'L';
        cout<<'U';
        for(int i=0;i<tx-sx;i++)  cout<<'R';
        cout << "DD";
        for(int i=0;i<tx-sx;i++)  cout<<'L';
        cout<<'U'<< endl;
    }
    else{
        for(int i=0;i<ty-sy;i++)  cout<<'U';
        for(int i=0;i<tx-sx;i++)  cout<<'R';
        for(int i=0;i<ty-sy;i++)  cout<<'D';
        for(int i=0;i<tx-sx;i++)  cout<<'L';
        cout<<'L';
        for(int i=0;i<ty-sy;i++)  cout<<'U';
        cout<<'U';
        for(int i=0;i<tx-sx;i++)  cout<<'R';
        cout<<"RDR";
        for(int i=0;i<ty-sy;i++)  cout<<'D';
        cout<<'D';
        for(int i=0;i<tx-sx;i++)  cout<<'L';
        cout<<"LU"<<endl;
    }
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define sz(x) (int)(x).size()
using namespace std;
typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s = "AKIHABARA";
    string t;
    cin >> t;
    function<bool(string)> rec = [&](string pattern) {
        if(s == pattern)
            return true;
        if(sz(pattern) >= sz(s))
            return false;
        for(int i = 0; i <= sz(pattern); i++) {
            if(rec(pattern.substr(0, i) + "A" + pattern.substr(i)))
                return true;
        }
        return false;
    };
    cout << (rec(t) ? "YES":"NO") << '\n';

    return 0;
}












Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int X;
int ANSWER;
bool exists[1<<13];
bool ignores[1<<13];
int estimate[1<<13];
int cur[13], maxi;

bool init() {
	scanf("%d", &X);
	return X > 0;
}


bool dfs(int depth) {
	if (depth + estimate[maxi] > ANSWER) {
		return false;
	}
	if (exists[X]) {
		return true;
	}

	int nums[13*13];
	int n = 0;
	for (int i = 0; i <= depth; ++i) {
		for (int j = 0; j <= depth; ++j) {
			const int add = cur[i] + cur[j];
			const int sub = cur[i] - cur[j];
			if (i <= j && !exists[add] && !ignores[add]) {
				nums[n++] = add;
			}
			if (sub > 0 && !exists[sub] && !ignores[sub]) {
				nums[n++] = sub;
			}
		}
	}

	sort(nums, nums + n);
	for (int i = 0; i < n; ++i) {
		int tmp = maxi;
		exists[nums[i]] = true;
		maxi = max(maxi, nums[i]);
		cur[depth + 1] = nums[i];
		if (dfs(depth + 1)) {
			return true;
		}
		maxi = tmp;
		exists[nums[i]] = false;
		ignores[nums[i]] = true;
	}
	for (int i = 0; i < n; ++i) {
		ignores[nums[i]] = false;
	}

	return false;
}

int solve() {
	memset(exists, false, sizeof(exists));
	memset(estimate, 0, sizeof(estimate));
	memset(ignores, false, sizeof(ignores));
	for (int i = 1; i < 1<<13; ++i) {
		int t = i;
		for (;t < X; t <<= 1, ++estimate[i]);
	}
	exists[1] = true;
	cur[0] = 1;
	maxi = 1;
	for (ANSWER = 0; ANSWER <= 12; ++ANSWER) {
		if (dfs(0)) {
			return ANSWER;
		}
	}
	return ANSWER;
}

int main() {
	for (;scanf("%d", &X), X; printf("%d\n", solve()));
	return 0;
}

Measured memory_bytes: 1104
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;

immutable long MOD = 10L^^9 + 7;

void main() {
    auto s = readln.split.map!(to!long);
    auto N = s[0].to!int;
    auto X = s[1];
    auto Y = s[2];
    auto A = new long[][](N);
    foreach (i; 0..N) {
        s = readln.split.map!(to!long);
        A[s[0].to!int-1] ~= s[1];
    }

    A = A.filter!(a => !a.empty).array;
    int M = A.length.to!int;
    
    foreach (i; 0..M) {
        A[i].sort!"a < b";
    }
    A.sort!"a[0] < b[0]";

    
    int[] B;
    
    foreach (i; 0..M) {
        if (i >= 1 && A[i][0] + A[0][0] > Y) {
            break;
        }
        
        int cnt = 1;
        long second = A.length > 1 ? A[1][0] : 1L<<59;
        
        foreach (j; 1..A[i].length) {
            if (i == 0) {
                if (A[i][0] + A[i][j] <= X || second + A[i][j] <= Y) {
                    ++cnt;
                }
            } else {
                if (A[i][0] + A[i][j] <= X || A[0][0] + A[i][j] <= Y) {
                    ++cnt;
                }
            }
        }
        B ~= cnt;
    }


    auto F = new long[](N+1);
    F[0] = 1;
    foreach (i; 0..N) {
        F[i+1] = F[i] * (i + 1) % MOD;
    }

    long ans = F[B.sum];
    foreach (b; B) {
        ans = ans * powmod(F[b], MOD-2, MOD) % MOD;
    }
    
    ans.writeln;;
}

long powmod(long a, long x, long m) {
    long ret = 1;
    while (x) {
        if (x % 2) ret = ret * a % m;
        a = a * a % m;
        x /= 2;
    }
    return ret;
}


Measured memory_bytes: 29308
fun main(args: Array<String>) {
    var (n, m) = readLine()!!.split(" ").map { it.toLong() }
    val abs = (1..n).map {
        val x = readLine()!!.split(" ").map { it.toLong() }
        Pair(x[0], x[1])
    }.sortedBy { it.first }
    
    var ans = 0L
    for ((a, b) in abs) {
        if (b >= m) {
            ans += m * a
            break
        } else {
            m -= b
            ans += b * a
        }
    }
    println(ans)
}

Measured memory_bytes: 85412
#include<bits/stdc++.h>
#include<numeric>
using namespace std;
int gcd(int x,int y){
  if(y>x){
    swap(x,y);
  }
  int r=x%y;
  while(r!=0){
    x=y;
    y=r;
    r=x%y;
  }
  return y;
}
int main(){
  int n,x;cin>>n>>x;
  int r[n],y[n];
  for(int i=0;i<n;i++){
    cin>>r[i];
    y[i]=abs(r[i]-x);
  }
  if(n==1)
    cout<<y[0]<<endl;
  else{
    int s=gcd(y[0],y[1]);
  for(int i=2;i<n;i++){
    if(s==1){
      break;
    }
    s=gcd(s,y[i]);
  }
  cout<<s<<endl;
  }
}
  

Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <tuple>
#include <stack>
#include <bitset>

#define MAX_K 100001
#define INF   1000000000
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
vector<ll> v;
#define LIM 10

int dfs(ll n, ll keta) {

  v.push_back(n);
  
  if(keta == LIM) return true;
  
  ll a = n % 10;
  for (ll i = 0; i <= 9; i++) {
    if(i + 1 == a || i == a || i - 1 == a){
      ll m = n*10 + i;
      dfs(m, keta + 1);
    }
  }

  return true;
}


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

    ll K;
    cin >> K;

    for (ll i = 1; i <= 9; i++) dfs(i, 1);

    sort(v.begin(), v.end());
    cout << v[K-1] << endl;
    return 0;
}


Measured memory_bytes: 4884
# include <bits/stdc++.h>
// # define INF 1e9
using namespace std;


int main(){

  int N;
  cin >> N;
  int v[N];
  for(int i=0; i<N; i++){
    cin >> v[i];
  }
  sort(v, v+N);
  double ans = v[0];
  for(int i=1; i<N; i++){
    ans = (ans + v[i]) / 2;
  }

  cout << setprecision(20) << ans << endl;


}


Measured memory_bytes: 256
#include <iostream>

using std::cin;
using std::cout;
using std::endl;

static long long
variation_count(int N, int a, int b)
{
  if (N < a)
  {
    return 0;
  }
  int count = 0;
  if (a == b)
  {
    count++;
  }
  for (int mul = 10;; mul *= 10)
  {
    int limit = (a + 1) * mul;
    for (int val = a * mul + b; val < limit; val+= 10)
    {
      if (N < val)
      {
        return count;
      }
      count++;
    }
  }
}

static long long
solve(int N)
{
  long long ret = 0;
  for (int a = 1; a < 10; a++)
  {
    for (int b = a; b < 10; b++)
    {
      long long a_count = variation_count(N, a, b);
      if (a == b)
      {
        ret += a_count * a_count;
      }
      else
      {
        long long b_count = variation_count(N, b, a);
        ret += a_count * b_count * 2;
      }
    }
  }
  return ret;
}

int
main()
{
  int N;
  cin >> N;
  cout << solve(N) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <set>
#include <math.h>
#include <algorithm>
using namespace std;

typedef long long ll;
const int maxn = 200200;
int dp[maxn];
void solve()
{
    int h,n;
    cin >> h >> n;
    memset(dp,200200,maxn);
    dp[0] = 0;
    for (int i = 0; i < n; i++){
        int x,y;
        cin >> x >> y;
        for (int j = 0; j < h; j++){
            dp[min(j + x,h)] = min(dp[min(j + x,h)], dp[j] + y);
        }
    }
    cout << dp[h] << endl;
}

// 7 3 3 1 1

int main()
{
    int t;
    solve();
    return (0);
}





Measured memory_bytes: 384
#include <stdio.h>

int main(void)
{int i,x,y;
	for(i=0;;i++){
	scanf("%d %d",&x,&y);
	if(x==0&&y==0){
	break;}
	else if(x<=y){
	printf("%d %d\n",x,y);}
	else{
	printf("%d %d\n",y,x);}
	}
	return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
int main() {
  int n, m;
  cin >> n >> m;
  int a[n + 1] = { };
  int b;
  rep(i, m)
  {
    cin >> b;
    a[b]++;
    cin >> b;
    a[b]++;
  }
  for (int i = 1; i <= n; ++i){
    cout << a[i]<<endl;
  }
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"

#define REP(i,x,y) for(int i=(x);i<(y);i++)
#define RREP(i,x,y) for(int i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
//#define int long long

using namespace std;

// conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

#define dump(x)  cout << #x << " = " << (x) << endl
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

typedef long long ll;

const ll MOD = 1e9 + 7;

class FXORMatching {
public:
    void solve(std::istream& in, std::ostream& out) {
        int M, K;
        in >> M >> K;
        if (K != 0 && M <= 1) {
            out << -1 << "\n";
            return;
        }
        if (M == 0) {
            out << "0 0" << "\n";
            return;
        } else if (M == 1) {
            out << "0 0 1 1" << "\n";
            return;
        }
        if ((1 << M) <= K) {
            out << -1 << "\n";
            return;
        }
        REP(i,0,1 << M) {
            if (i == K) continue;
            out << i << " ";
        }
        out << K << " ";
        RREP(i,0,1 << M) {
            if (i == K) continue;
            out << i << " ";
        }
        out << K << "\n";
    }
};


int main() {
	FXORMatching solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 1792
/*
 * Ankit Raj, NIT Agartala
 */
#include<bits/stdc++.h>
using namespace std;
#define lld long long int
#define MAX_RANGE 10000007
#define BOOST ios_base::sync_with_stdio(0) 
#define NITRO cin.tie(NULL)
#define pb push_back
#define mp make_pair
#define F first
#define S second
int main()
{
	BOOST;
	NITRO;
	clock_t t1,t2;
	t1 = clock();
	/*
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	*/ 
	//Main Code
	int a,b,c;
	cin>>a>>b>>c;
	int rem = b/a;
	if(rem>c)
	{
		rem = c;
	}
	cout<<rem<<"\n";

	t2 = clock();
	float diff = (float)t2 - (float)t1;
	float execution_time = diff/CLOCKS_PER_SEC;
	//cout<<"\n"<<execution_time;
	//system("pause");
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        // 整数の入力
        int n = sc.nextInt();
        String slimes = sc.next();
        StringBuilder ans = new StringBuilder();
        String[] slimesarr = new String[n+1];

        for (int i = 0; i < n; i++) {
            slimesarr[i] = String.valueOf(slimes.charAt(i));
        }
        for (int i = 0; i < n; i++) {
            if(slimesarr[i].equals(slimesarr[i+1])){

            }else{
                ans.append(slimesarr[i]);
            }
        }

        System.out.println(ans.toString().length());
    }
}


Measured memory_bytes: 32776
n, k = map(int, input().split())
a = list(map(int, input().split()))

l = 50

dp = [[-1] * 2 for _ in range(l + 1)]
dp[0][0] = 0

for i in range(l):
    mask = 1 << (l - i - 1)
    ones = 0
    for e in a:
        if e & mask:
            ones += 1

    cost0 = mask * ones
    cost1 = mask * (n - ones)

    if dp[i][1] != -1:
        dp[i+1][1] = max(dp[i+1][1], dp[i][1] + max(cost0, cost1))

    if dp[i][0] != -1:
        if k & mask:
            dp[i+1][1] = max(dp[i+1][1], dp[i][0] + cost0)

    if dp[i][0] != -1:
        if k & mask:
            dp[i+1][0] = max(dp[i+1][0], dp[i][0] + cost1)
        else:
            dp[i+1][0] = max(dp[i+1][0], dp[i][0] + cost0)

ans = max(dp[l][0], dp[l][1])
print(ans)


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

int main(){
  int N, K;
  cin >> N >> K;
  int count = 0;
  for(int i = 0; i < N; i++){
    int h;
    cin >> h;
    if(h >= K)
      count++;
  }
  cout << count << endl;
}

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

int main()
{
	long n = 0, g = 0, v = 0, cnt = 0, m = 0;

	cin >> n;

	vector <long> a(n);

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

	cnt = 0;
	if (n < 3)
		m = 1;
	else
		m = (int)log2(n);

	vector <long> G(m);		

	for (long k = 0; k < m; k++) {
		G[k] = ((long)pow(2, m - k) - 1);
		g = G[k];

		for (long i = g; i < n; i++) {

			long j = 0;

			v = a[i];
			j = i - g;

			while (j >= 0 && a[j] > v) {
				a[j + g] = a[j];
				j = j - g;
				cnt++;
			}

			a[j + g] = v;
		}
	}

	cout << m << endl;

	for (long i = 0; i < m - 1; i++)
		cout << G[i] << " ";
	cout << G[m - 1] << endl;

	cout << cnt << endl;

	for (long i = 0; i < n; i++)
		cout << a[i] << endl;	

	return 0;
}

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

typedef long long 			ll;
typedef unsigned long long 	ull;

const int N = 100 + 20;
const int MAXN = 100 * 1000 + 20;

ll dp[MAXN][5];

int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
	ll n, k, s, r, p;
	string t;
	cin >> n >> k >> r >> s >> p;
	cin >> t;
	for (int i = 0; i < t.size(); i++) {
		if (t[i] == 'r')
			dp[i][1] = p;
		else if (t[i] == 'p')
			dp[i][2] = s;
		else
			dp[i][0] = r;
		if (i >= k) {
			dp[i][0] += max(dp[i - k][1], dp[i - k][2]);
			dp[i][1] += max(dp[i - k][0], dp[i - k][2]);
			dp[i][2] += max(dp[i - k][0], dp[i - k][1]);
		}
	}
	ll ans = 0;
	for (int i = n; i >= n - k; i--)
		ans += max(dp[i][0], max(dp[i][1], dp[i][2]));
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4432
# フィボナッチ数列 Fibonacci number

DP = [-1 for i in range(45)]
DP[0] = 1
DP[1] = 1

def fib(i):
    if DP[i] != -1:
        return DP[i]
    else:
        DP[i] = fib(i-1) + fib(i-2)
        return DP[i]

n = int(input())
print(fib(n))


Measured memory_bytes: 5604
#include<iostream>
int main()
{
    long long int n;
    scanf("%lld",&n);
    int a[n+1];
    long long int count =0;
    for(long long int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        if(i%2&&a[i]%2)count++;
    }
    printf("%lld",count);
    return 0;
}

Measured memory_bytes: 3820