akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
using namespace std;
typedef long long int ll;
int main(void){
int n;
cin>>n;
queue<ll> a;
ll b;
for(int i=0;i<n;i++){
	cin>>b;
	a.push(b-1);
}
ll m=1,ans=0;
ans+=a.front();
a.pop();
for(int i=0;i<n-1;i++){
int t=a.front();
a.pop();
if(m==t){
	m++;
}else if(m<t){
ans+=t/(m+1);
}
}
cout<<ans<<endl;
	return 0;
}

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

using namespace std;

#define int long long
#define pii pair<int,int>
#define fi first
#define se second

const int N = 1e5 + 7;

int n, ans[N];
pii a[N];

bool cmp(pii x, pii y){
	return (x.fi > y.fi || (x.fi == y.fi && x.se < y.se));
}

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	cin >> n;
	for(int i = 1; i <= n; ++i) cin >> a[i].fi, a[i].se = i;
	sort(a + 1, a + n + 1, cmp);
	
	
	for(int i = 1, pick = i, cur = a[pick].fi; i <= n; ){
		if(i <= n && a[i].fi == a[i + 1].fi) ++i;
		int ptr = i + 1;
		ans[a[pick].se] += (ptr - 1) * (cur - a[ptr].fi);
		cur = a[ptr].fi;
		pick = (a[pick].se > a[ptr].se ? ptr : pick);
		i = ptr;
	}
	
	for(int i = 1; i <= n; ++i) cout << ans[i] << "\n";
}


Measured memory_bytes: 5924
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;

const pii Dir[8] = { //?????????
	{ 0,1 },{ 0,-1 },{ 1,0 },{ -1,0 },
	{ 1,1 },{ 1,-1 },{ -1,-1 },{ -1,1 }
};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*) array, (T*) (array + N), val);
}

signed main() {
	int w, h, k;
	scanf("%d %d %d", &w, &h, &k);
	vector<vector<pii>> sww(w+1), swh(h+1), graph(k+2);
	int spos = k,gpos = k+1;
	bool als = 0, alg = 0;
	REP(i, k) {
		int a, b;
		scanf("%d %d", &a, &b);
		sww[a].push_back({ b,i });
		swh[b].push_back({ a,i });
		if (a == 1 && b == 1) {
			als = 1;
			spos = i;
		}
		if (a == w && b == h) {
			alg = 1;
			gpos = i;
		}
	}
	if (!als) {
		sww[1].push_back({ 1,k });
		swh[1].push_back({ 1,k });
	}
	if (!alg) {
		sww[w].push_back({ h,k + 1 });
		swh[h].push_back({ w,k + 1 });
	}
	REP(i, w+1)
		sort(ALL(sww[i]));
	REP(i, h+1)
		sort(ALL(swh[i]));

	REP(i, w+1) {
		for (int j = 0; j < (int)sww[i].size() - 1; j++) {
			int dis = abs(sww[i][j].first - sww[i][j + 1].first);
			graph[sww[i][j].second].push_back({ sww[i][j + 1].second, dis });
			graph[sww[i][j + 1].second].push_back({ sww[i][j].second, dis });
		}
	}
	REP(i, h+1) {
		for (int j = 0; (int) swh[i].size() - 1 > j; j++) {
			if (i == 1 && sww[i][j].first == 1 && !als)
				continue;
			int dis = abs(swh[i][j].first - swh[i][j + 1].first);
			graph[swh[i][j].second].push_back({ swh[i][j + 1].second, -dis });
			graph[swh[i][j + 1].second].push_back({ swh[i][j].second, -dis });
		}
	}


	priority_queue<pair<ll, pii>, vector<pair<ll, pii>>, greater<pair<ll, pii>>> que;
	que.push({ 0, {spos, 0} });

	map<int, ll> al;

	while (que.size()) {
		auto top = que.top();
		ll cos = top.first;
		int pos = top.second.first, dir = top.second.second;
		que.pop();
		if (al.count(pos)) {
			continue;
		}
		al[pos] = cos;

		REP(i, (int) graph[pos].size()) {
			bool howcon = graph[pos][i].second < 0;//????????????????????????
			que.push({ cos + abs(graph[pos][i].second) + (howcon!=dir), {graph[pos][i].first, howcon} });
		}

	}
	if (!al.count(gpos))
		al[gpos] = -1;
	printf("%lld\n", al[gpos]);
	return 0;
}

Measured memory_bytes: 42368
from collections import deque

N,M = list(map(int,input().split()))

edges = []
connections = {}
for i in range(M):
    edges.append(list(map(int,input().split())))
    a,b = edges[-1][0],edges[-1][1]
    
    if a in connections:
        connections[a].append(b)
    else:
        connections[a] = [b]
    
    if b in connections:
        connections[b].append(a)
    else:
        connections[b] = [a]

ans = 0
for i in range(M):
    queue = deque([1])
    checked = [0]*(N+1)
    checked[1] = 1
    NG = {edges[i][0],edges[i][1]}
    
    while queue:
        currentpoint = queue.popleft()
        for nextpoint in connections[currentpoint]:
            if not (currentpoint in NG and nextpoint in NG) and checked[nextpoint] == 0:
                queue.append(nextpoint)
                checked[nextpoint] = 1
            
    if sum(checked) != N:
        ans += 1
        
print(ans)

Measured memory_bytes: 3316
n,s = map(int,input().split())
a = [0]+list(map(int,input().split()))
mod = 998244353
dp = [[0]*(s+1) for j in range(n+1)]
ans = 0
for i in range(1,n+1):
  if a[i] <= s:
    dp[i][a[i]] = i
  for j in range(1,s+1):
    dp[i][j] += dp[i-1][j]
    if a[i] <= j:
      dp[i][j] += dp[i-1][j-a[i]]
    dp[i][j] %= mod
  ans =  (ans + (dp[i][s]-dp[i-1][s])*(n-i+1))%mod
print(ans%mod)

Measured memory_bytes: 113116
#include <iostream>

using namespace std;

const int max_v = 100;

int origami[max_v][max_v];
int tmp[max_v][max_v];

void copy() {
    for (int i = 0; i < max_v; i++) {
        for (int j = 0; j < max_v; j++) { tmp[i][j] = origami[i][j]; }
    }
}

void show() {
    for (int i = 0; i < max_v; i++) {
        for (int j = 0; j < max_v; j++) {
            cout << origami[i][j] << " ";
        } 
        cout << endl;
    }
    cout << "-------------------" << endl;
}

void fold_a(int c) {
    int t = c;
    for (int i = 0; i < c; i++) {
        for (int j = 0; j < max_v; j++) {
            origami[j][t+i] += origami[j][t-i-1];
            origami[j][t-i-1] = 0;
        }
    }

    copy();

    for (int i = 0; i < max_v; i++) {
        for (int j = 0; j < max_v; j++) {
            if (j-c < 0 || max_v-1 < j-c) { continue; }
            origami[i][j-c] = tmp[i][j];
        }
    }
}


void fold_b(int c) {
    int t = max_v-c-1;
    for (int i = 0; i < max_v; i++) {
        for (int j = 0; j < c; j++) {
            origami[t-j][i] += origami[t+j+1][i];
            origami[t+j+1][i] = 0;
        }
    }

    copy();

    for (int i = 0; i < max_v; i++) {
        for (int j = 0; j < max_v; j++) {
            if (i+c < 0 || max_v-1 < i+c) { continue; }
            origami[i+c][j] = tmp[i][j];
        }
    }
}

int main() {
    int n, m, t, p;
    int d, c, x, y;

    while (cin >> n >> m >> t >> p) {
        if (!n && !m && !t && !p) { break; }

        for (int i = 0; i < max_v; i++) {
            for (int j = 0; j < max_v; j++) {
                origami[i][j] = 0;
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                origami[max_v-j-1][i] = 1;
            }
        }

        for (int i = 0; i < t; i++) {
            cin >> d >> c;
            if (d == 1) { fold_a(c); }
            if (d == 2) { fold_b(c); }
        }
 
        for (int i = 0; i < p; i++) {
            cin >> x >> y;
            cout << origami[max_v-y-1][x] << endl;
        }
    }
    return 0;
}


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

int main() {
    double sm=0,a;
    int n;
    cin>>n;
    while (n--) {
        cin>>a;
        sm+=1/a;
    }
    cout<<fixed<<1/sm<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <iostream>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=1<<29;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main() {

	int a,b;
	cin>>a>>b;
	cout<<max(a-b*2,0)<<endl;


	return 0;
}


Measured memory_bytes: 256
program rotated_palindromes
  implicit none
  integer(8), parameter :: md = 1000000007_8
  integer :: n, i, j, d(1500) = 0, m = 0
  integer(8) :: k, num(1500) = 0_8, ans = 0_8
  read(*,*) n, k
  i = 1
  do while (i*i <= n)
    if (mod(n,i) == 0) then
      m = m+1
      d(m) = i
      if (i*i == n) exit
      m = m+1
      d(m) = n/i
    end if
    i = i+1
  end do
  call quick_sort(d(1:m))
  do i = 1, m
    num(i) = pow(k,(d(i)+1)/2)
    do j = 1, i-1
      if (mod(d(i),d(j)) == 0) num(i) = modulo(num(i)-num(j),md)
    end do
  end do
  do i = 1, m
    ans = mod(ans+num(i)*int(d(i)/(2-mod(d(i),2)),8),md)
  end do
  write(*,'(i0)') ans
contains
  function pow(a,b) result(r)
    integer(8), intent(in) :: a
    integer, intent(in) :: b
    integer :: k
    integer(8) :: r, p
    r = 1_8
    p = a
    k = b
    do while (k > 0)
      if (btest(k,0)) r = mod(r*p,md)
      p = mod(p*p,md)
      k = rshift(k,1)
    end do
  end
  recursive subroutine quick_sort(a)
    integer, intent(inout) :: a(:)
    integer :: n, l, r, m
    integer :: p
    n = size(a)
    l = 1
    r = n
    m = (n+1)/2
    p = a(l)+a(m)+a(r)-max(a(l),a(m),a(r))-min(a(l),a(m),a(r))
    do
      do while (a(l) < p)
        l = l+1
      end do
      do while (a(r) > p)
        r = r-1
      end do
      if (l >= r) exit
      a(l) = xor(a(l),a(r))
      a(r) = xor(a(l),a(r))
      a(l) = xor(a(l),a(r))
      l = l+1
      r = r-1
    end do
    if (l-1 > 1) call quick_sort(a(1:l-1))
    if (n > r+1) call quick_sort(a(r+1:n))
  end
end program rotated_palindromes

Measured memory_bytes: 256
/*
    問題をよく読もう！
    論理的に考えよう！
    サンプルを確認しよう!
    絶対に諦めるな！
    工夫をしろ！

    Twitterは終わるまでログアウト！
    （間違えて解法をツイートしてはいけないから）

*/
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cctype>
using namespace std;
#define rep(i, n) for(int i=0; i<n; ++i)
typedef long long ll;
//必要な宣言

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

  cout << (n-1)*(m-1) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (n); i++)
#define all(v) v.begin(), v.end()
#define out(s) cout << (s) << endl
#define ll long long

string join(vector<int> v, string sep){
  std::stringstream ss;
  for(size_t i = 0; i < v.size(); ++i){
    if(i != 0)
    ss << sep;
    ss << v[i];
  }
  return ss.str();
}

void solve(){
  int n;
  cin>>n;
  vector<int> A(n);
  rep(i,0,n) {cin>>A[i];}

  out(join(A, " "));

  rep(i,1,n){
    int v = A[i];
    int j=i-1;
    while(j>=0&&A[j]>v){
        A[j+1]=A[j];
        j--;
    }
    A[j+1]=v;
    out(join(A, " "));
  }
}

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



Measured memory_bytes: 3216
from collections import Counter

N = int(input())
text = input().split()

count = Counter()
for i in range(0, N):
    count[int(text[i])] += 1
remove = 0
for key, item in count.items():
    if key > item:
        remove = remove + item
    elif key < item:
        remove = remove + (item - key)
print(remove)


Measured memory_bytes: 23668
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <cassert>
#include <string.h>

using namespace std;

int main()
{
	
	int n;
	cin >> n;
	
	string in;
	cin >> in;
	string s1, s2;
	int len = in.size();
	
	
	if (n%2 != 0){
		cout << "No" <<endl;
		return 0;
	}
	
	else {
		
		
		for (int i = 0 ; i<= n/2-1; i++)
		{
			s1.push_back(in[i]);
		}
		
		for (int j = n/2; j<n; j++ ) 
		{
			s2.push_back(in[j]);
		}
		
		
	}
	
	if (s1 == s2) cout <<"Yes"<<endl;
	else cout << "No" <<endl;
	
	
	
	
	
	
	
	return 0;
}



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

using namespace std;
using ll = long long;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    ll ans = 1;
    for (int c = n - 2; c > 0; c--)
    {
        int val = n - c;
        for (int i = 1; i <= sqrt(val); i++)
        {
            if (val % i == 0)
            {
                int k = val / i;
                if (k == i)
                {
                    ans++;
                }
                else
                {
                    ans += 2;
                }
            }
        }
    }
    cout << ans << '\n';

    return 0;
}


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define ll long long

template<class T>
void changeMax(T&a, const T b){if(a < b) a = b;}
template<class T>
void changeMin(T&a, const T b){if(a > b) a = b;}


template<class T>
void changeIdxMax(T&a, const T b, int&i, int j){
  if(a < b){
    a = b;
    i = j;
  }
}
template<class T>
void changeIdxMin(T&a, const T b, int&i, int j){
  if(a > b){
    a = b;
    i = j;
  }
}
#define mod 2019

int main(){
  ll l,r;cin >> l >>r;
  if(r - l >= mod - 1){
    cout << 0 << endl;
    return 0;
  }
  ll minv = 3000;
  for(ll i = l; i <= r; ++i){
    for(ll j = i + 1; j <= r; ++j){
      changeMin(minv,((i%mod)*(j%mod))%mod);
    }
  }
  cout << minv << endl;
  return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF ((1<<30)-1)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()




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

	string s;
	cin >> s;

	for (char c: s) {
		if (c == '?')cout << 'D';
		else cout << c;
	}
	cout << endl;


	return 0;
}


Measured memory_bytes: 3744
#include "bits/stdc++.h"
using namespace std;

int main(){
    int n; cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i ++) cin >> a.at(i);
    if(n % 2){
        for(int i = 0; i < (n+1)/2; i++){
            if(i) cout << " ";
            cout << a.at(n-1-2*i);
        }
        for(int i = 0; i < n/2; i++){
            cout << " " << a.at(1+2*i);
        }
        cout << endl;
    }else{
        for(int i = 0; i < n/2; i++){
            if(i) cout << " ";
            cout << a.at(n-1-2*i);
        }
        for(int i = 0; i < n/2; i++){
            cout << " " << a.at(2*i);
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 2944
#include<stdio.h>
int main()
{
	int a[6],i;
	for(i=1;i<6;i++)
	scanf("%d",&a[i]);
	for(i=1;i<6;i++)
	if(a[i]!=i)
	{
		printf("%d",i);
		break;
	}
}

Measured memory_bytes: 2156
INF = 1e10

H, W = list(map(int, input().split()))
c = []
cnt = 0
for y in range(H):
    c.append(input())
    for s in c[-1]:
        if s=='.':
            cnt+=1
    
def search(syx, gyx):
    sy,sx = syx
    gy,gx = gyx
    visited = [[INF]*W for _ in range(H)]
    q = [[sy,sx]]
    visited[sy][sx]=0
    while len(q)>0:
        tmp_q = []
        for one in q:
            cy,cx = one
            for dy, dx in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                ny, nx = cy+dy, cx+dx
                if 0 <= nx < W and 0 <= ny < H and c[ny][nx] == '.' and visited[ny][nx]> visited[cy][cx]+1:
                    visited[ny][nx] = visited[cy][cx]+1
                    tmp_q.append([ny,nx])
        q = tmp_q
        if visited[gy][gx]!=INF:
            break
    return visited[gy][gx]

ans = search([0,0],[H-1,W-1])
if ans==INF:
    print(-1)
else:
    print(cnt-ans-1)

Measured memory_bytes: 3064
#include <stdio.h>

int main(){
    int N, M;
    int dat;
    int A[100];
    int sum = 0;
    int ninki = 0;

    scanf("%d %d", &N, &M);
   for(int i = 0; i < N; i++){
       scanf("%d", &dat);
       A[i] = dat;
       sum += dat;
   }

   for(int i = 0; i < N; i++){
       if(A[i] * 4 * M >= sum){
           ninki += 1;
       }
   }

   if(ninki >= M) printf("Yes");
   else printf("No");
    }

Measured memory_bytes: 128
# Dは距離　Tは制限時間　速度はS
Information_Lists = input().split()
#.split("文字列")で、文字列ごとに分けることができる。"文字列"を入れないとスペースで分けられる。
D = int(Information_Lists[0])
T = int(Information_Lists[1])
S = int(Information_Lists[2])
if D > T * S:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 9148
-- ABC111 C - /\/\/\/
import Control.Monad
import Data.List
import qualified Data.IntSet as IntSet
import qualified Data.IntMap.Strict as IntMap
import Debug.Trace

main :: IO ()
main = do
  n <- readLn :: IO Int
  ss <- fmap (map read . words) getLine :: IO [Int]
  -- print $ solve ss
  print $ solve' ss

solve' :: [Int] -> Int
solve' ss
  | IntSet.size uniques == 1 = n
  | otherwise = go ss (IntMap.empty, IntMap.empty)
  where
    uniques = IntSet.fromList ss
    n = (length ss) `div` 2
    go :: [Int] -> (IntMap.IntMap Int, IntMap.IntMap Int) -> Int
    go [] (odds, evens) = if okey == ekey
                          then 2 * n - max (oval + e2) (eval + o2)
                          else 2 * n - oval - eval
      where
        (okey, oval) = lookupMax odds
        (ekey, eval) = lookupMax evens
        o2 = if (IntMap.size odds) > 1
             then (sort . IntMap.elems $ odds) !! (length odds - 2)
             else minBound
        e2 = if (IntMap.size evens) > 1
             then (sort . IntMap.elems $ evens) !! (length evens - 2)
             else minBound
    go (a:b:as) (odds, evens) = go as
      (IntMap.insertWith (+) a 1 odds, IntMap.insertWith (+) b 1 evens)

-- IntMap.lookupMaxがAtCoderになかったので自分で実装
lookupMax :: IntMap.IntMap Int -> (Int, Int)
lookupMax = last . sortOn snd . IntMap.toList

-- 全探索　遅い
solve :: [Int] -> Int
solve ss
  | IntSet.size uniques == 1 = length ss `div` 2
  | otherwise = minimum $ map (countNotEqual ss) $ candidates uniques
  where
    uniques = IntSet.fromList ss

candidates :: IntSet.IntSet -> [[Int]]
candidates us = map toInf pairs
  where
    pairs = filter (\(a:b:_) -> not (a == b)) $ replicateM 2 $ IntSet.toList us
    toInf :: [Int] -> [Int]
    toInf pair = pair ++ (toInf pair)

countNotEqual :: [Int] -> [Int] -> Int
countNotEqual _ [] = 0
countNotEqual [] _ = 0
countNotEqual (a:as) (b:bs) = (if a == b then 0 else 1) + (countNotEqual as bs)


Measured memory_bytes: 48508
#include <stdio.h>

int main(void){
  int A,B,C;
  scanf("%d%d%d",&A,&B,&C);

  int max = A;
  if(max < B){
    max = B;
  }
  if(max < C){
    max = C;
  }

  printf("%d\n",A+B+C-max+max*10);

  return 0;
}

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

int main(){
    ll a,b,k;
    cin >> a >> b >> k;
    ll ans_a = max((ll)0,a-k);
    k = max((ll)0,k-a);
    ll ans_b = max((ll)0,b-k);
    cout << ans_a << " " << ans_b << endl;
}

Measured memory_bytes: 3600
#include <stdio.h>
#include <algorithm>
#include <functional>

using namespace std;

int N, H, ans;
int A[100000], B[100000];

int main()
{
	scanf("%d %d", &N, &H);

	for (int i = 0; i < N; i++) scanf("%d %d", &A[i], &B[i]);
	sort(B, B + N, greater<int>());
	sort(A, A + N, greater<int>());

	int sum = 0;
	for (int i = 0; i < N; i++)
	{
		if (B[i] > A[0])
		{
			sum += B[i];
			ans++;
			if (sum >= H)
			{
				printf("%d\n", ans);
				return 0;
			}
		}
		else break;
	}
	if ((H - sum) % A[0] == 0) printf("%d\n", ans + (H - sum) / A[0]);
	else printf("%d\n", ans + (H - sum) / A[0] + 1);
	return 0;
}

Measured memory_bytes: 896
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	c := nextByte()
	fmt.Println(string(nextChar(c[0])))
}

func nextChar(ch byte) byte {
	if ch++; ch > 'z' {
		return 'a'
	}
	return ch
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextByte() []byte {
	sc.Scan()
	return sc.Bytes()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}


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

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

int main(){
    double n;
    while(cin >> n){
        double t = n;
        n *= 2; t += n;
        n /= 3; t += n;
        n *= 2; t += n;
        n /= 3; t += n;
        n *= 2; t += n;
        n /= 3; t += n;
        n *= 2; t += n;
        n /= 3; t += n;
        n *= 2; t += n;
        printf("%.9f\n", t);
    }
    return 0;
}

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


int main() {
	int n;
	cin >> n;
	int a = n / 100;
	int b = (n - a * 100) / 10;
	int c = n - (a * 100 + b * 10);
	if (a == 9)a = 1;
	else a = 9;
	if (b == 9)b = 1;
	else b = 9;
	if (c == 9)c = 1;
	else c = 9;
	cout << a << b << c << endl;
}


Measured memory_bytes: 256
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() (int, []int) {
	n := readInt()
	return n, readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int

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

func main() {
	defer stdout.Flush()
	s := []byte(readString())
	println(min(calc(s[:], 0), calc(s[:], 1)))
}

func calc(s []byte, x int) int {
	count := 0
	for i := range s {
		v := int(s[i] - '0')
		if v != x {
			count++
		}
		x = 1 - x
	}
	return count
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

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


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

#define fi first
#define se second

typedef pair<int, int> P;

int n;
int x[100000], y[100000];
P p[100000], q[100000];
bool s[100000][2], t[100000][2];

void asn(const P p[], int m, bool s[][2])
{
	for (int i = 0; i < n; i++){
		s[p[i].se][0] = s[p[i].se][1] = false;
		if (p[i].fi <= p[0].fi + m) s[p[i].se][1] = true;
		if (p[i].fi >= p[n - 1].fi - m) s[p[i].se][0] = true;
	}
}

bool cond(int m)
{
	asn(p, m, s); asn(q, m, t);
	bool f = true, g = true;
	for (int i = 0; i < n; i++){
		if ((!s[i][0] || !t[i][0]) && (!s[i][1] || !t[i][1])) f = false;
		if ((!s[i][0] || !t[i][1]) && (!s[i][1] || !t[i][0])) g = false;
	}
	return f | g;
}

int main()
{
	scanf("%d", &n);
	for (int i = 0; i < n; i++){
		scanf("%d %d", x + i, y + i);
		p[i] = P(x[i] + y[i], i);
		q[i] = P(x[i] - y[i], i);
	}

	sort(p, p + n);
	sort(q, q + n);

	int lb = 0, ub = 1e6;
	while (ub - lb > 1){
		int md = (lb + ub) / 2;
		(cond(md) ? ub : lb) = md;
	}

	printf("%d\n", ub);
}

Measured memory_bytes: 5896
#include <iostream>
#include <algorithm>
#include <vector>
#include<deque>
 
int main()
{
    using Int=long long;
    int n;
    std::vector<Int> a={};
    std::cin>>n;
    Int t;
    for(;std::cin>>t;){
        a.push_back(t);
    }
    
    std::deque<Int> deq={};
    
    for(auto x: a){
        auto it = std::lower_bound(deq.begin(),deq.end(),x);
        if(it == deq.begin()){
            deq.push_front(x);
        }else{
            *(it-1)=x;
        }
    }
   
    std::cout<<deq.size();
}

Measured memory_bytes: 1908
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {
	final int _intMax = Integer.MAX_VALUE; // =2147483647>10^9
	final int _intMin = Integer.MIN_VALUE;
	final long _longMax = Long.MAX_VALUE; // =9223372036854775807L>10^18
	final long _longMin = Long.MIN_VALUE;
	static boolean bElapsed = false;

	void solve() {
		int a = readNum();
		int b = readNum();
		int c = readNum();
		int x = readNum();
		int ans = 0;
		for (int aa = 0; aa <= a; aa++) {
			for (int bb = 0; bb <= b; bb++) {
				for (int cc = 0; cc <= c; cc++) {
					int sum = 500 * aa + 100 * bb + 50 * cc;
					if (sum == x)
						ans++;
				}
			}
		}
		pln(ans);
	}

	int pint(String s) {
		return Integer.parseInt(s);
	}

	long plong(String s) {
		return Long.parseLong(s);
	}

	String readLine() {
		try {
			return _in.readLine();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

	int readNum() {
		String line = readLine();
		return pint(line);
	}

	String[] readFlds() {
		String line = readLine();
		return line.split(" ");
	}

	int[] readNums() {
		String[] flds = readFlds();
		int[] nums = new int[flds.length];
		for (int i = 0; i < flds.length; i++) {
			nums[i] = pint(flds[i]);
		}
		return nums;
	}

	void p(char c) {
		_out.print(c);
	}

	void pln(char c) {
		_out.println(c);
	}

	void p(double d) {
		_out.print(d);
	}

	void pln(double d) {
		_out.println(d);
	}

	void p(long l) {
		_out.print(l);
	}

	void pln(long l) {
		_out.println(l);
	}

	void p(String s) {
		_out.print(s);
	}

	void pln(String s) {
		_out.println(s);
	}

	static BufferedReader _in;
	static PrintWriter _out;

	public static void main(String[] args) {
		long start = System.currentTimeMillis();
		_in = new BufferedReader(new InputStreamReader(System.in));
		_out = new PrintWriter(System.out);
		new Main().solve();
		_out.flush();
		long end = System.currentTimeMillis();
		if (bElapsed) {
			System.err.println((end - start) + "ms");
		}
	}
}


Measured memory_bytes: 22612
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>

using namespace std;

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

typedef vector<int> vec;
typedef vector<vec> mat;

const ll mod = 1000000007;

int main(){
    int n;
    cin >> n;
    string s, ans;
    cin >> s;
    string a = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    a += a;
    rep(i, s.size()){
        rep(j, 26){
            if(s[i] == a[j]){
                ans += a[j+n];
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3676
n=int(input())
l=[(input().split()) for i in range(n)]
s=input()
ts,ls=[a for a in zip(*l)]
f=0
for i,d in enumerate(ts):
  if d==s:f=i;break
if f==n-1:print(0);exit()
print(sum(list(map(int,list(ls)[f+1:]))))

Measured memory_bytes: 3060
n, k, s = map(int, input().split())
p = 10**9
ans = []
if s != p:
  for i in range(n):
    if i < k:
      ans.append(s)
    else:
      ans.append(p)
else:
  for i in range(n):
    if i < k:
      ans.append(s)
    else:
      ans.append(1)

print(" ".join(map(str,ans)))

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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
  int n, m;
  cin >> n >> m;

  vector<vector<int>> inputs(m, vector<int>(2));
  map<int, vector<int>> edge;

  for (int i = 0; i < m; ++i) {
    cin >> inputs[i][0] >> inputs[i][1];
    edge[inputs[i][0]].push_back(inputs[i][1]);
    edge[inputs[i][1]].push_back(inputs[i][0]);
  }

  int cnt = m;
  for (int i = 0; i < m; ++i) {
    int start = inputs[i][0];
    int goal = inputs[i][1];
    
    queue<int> que;
    que.push(start);
    unordered_set<int> visited;
    visited.insert(start);
    
    while (!que.empty()) {
      int curr = que.front();
      que.pop();
      if (curr == goal) {
        --cnt;
        break;
      }
      for (int next : edge[curr]) {
        if (curr == start and next == goal) continue;
        if (visited.find(next) != visited.end()) continue;
        que.push(next);
        visited.insert(next);
      }
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <cmath>
#include <complex>
#include <map>
using namespace std;

#define rep(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<long long,int> P;
static const int INF=1<<24;

int n;
int a[10100],b[10100];

int main(){
	while(cin>>n,n){
		rep(i,n){
			cin>>a[i]>>b[i];
		}
		ll ans1=0,ans2=0;
		rep(i,n){
			if(a[i]<b[i]){
				ans2+=a[i]+b[i];
			}
			else if(a[i]==b[i]){
				ans1+=a[i];
				ans2+=b[i];
			}
			else{
				ans1+=a[i]+b[i];
			}
		}
		cout<<ans1<<" "<<ans2<<endl;
	}
	return 0;
}

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

int n;
lli arr[200001];
lli _abs(lli a){return a<0 ? -a : a;}
int main() {
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%lld",arr+i),arr[i]+=arr[i-1];
    lli mx=1e18;
    for(int i=1;i<n;i++) {
        mx = min(mx, _abs(2*arr[i]-arr[n]));
    }
    printf("%lld\n",mx);
    
    return 0;
}


Measured memory_bytes: 1792
/*
本宝的程序外人别想看！！

name: [夏宝宝]
run time：[] ms
compilation time: [] ms
output memory: [] MiB
where: []
state: []
*/
#include<bits/stdc++.h>
using namespace std;

int main()
{
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	
	cout.sync_with_stdio(false);
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	long long int n, a, b, sum=0;
	
	cin>>n>>a>>b;
	
	long long int h=a+b;
	
	sum+=n/h*a;
	
	if(n%h==a)
	{
		sum+=a;
	}
	else if(n%h<=a)
	{
		sum+=n%h;
	}
	else
	{
		sum+=a;
	}
	
	cout<<sum<<endl;
	
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static readonly long Mod = 1000000000 + 7;

        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var N = Sarray()[0];
            var S = ReadLine();
            var max = 0L;
            for (var i = 1; i < N - 1; ++i)
            {
                var X = S.Substring(0, i).Distinct();
                var Y = S.Substring(i, S.Length - i).Distinct();
                var cnt = 0L;
                foreach (var x in X)
                    if (Y.Contains(x)) ++cnt;
                max = Max(max, cnt);
            }
            WriteLine(max);
            //Out.Flush();
        }
    }
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
const int N=5e5;

#define C getchar()-48
int read()
{
  int s=0,t=1,k=C;
  for (;k<0||9<k;k=C) if (k==-3) t=-1;
  for (;0<=k&&k<=9;k=C) s=(s<<1)+(s<<3)+k;
  return s*t;
}

  int t;
  int h[N];
  struct hh
    {
      int n,r;
    }e[N];
void ins(int x,int y)
{
  e[++t]=(hh){h[x],y};h[x]=t;
}

  int n;
void in()
{
  cin>>n;
  for (int i=1;++i<=n;)
    ins(read(),i);
}

  int z;
  int d[N],v[N];
int cmp(int x,int y)
{
  return d[x]<d[y];
}
 
#define P(i) e[i].r
void dfs(int k)
{
  int l=++z;
  v[z]=k;
  for (int i=h[k];i;i=e[i].n)
    dfs(P(i));
  sort(v+l+1,v+z+1,cmp);
  for (int i=l;++i<=z;)
    d[k]=max(d[k],d[v[i]]+z-i+1);
  z=l;
}

void wor()
{
  dfs(1);
}

void out()
{
  cout<<d[1];
}

int main()
{
  in();
  wor();
  out();
  exit(0);
}


Measured memory_bytes: 13184
class DisjointSets:#Union-Find
    def __init__(self, n):
        self.nodes = [-1] * n #根にサイズを負の値で格納する。
    def find(self, i):
        if self.nodes[i] < 0: #値が負の場合は根
            return i
        else:
            self.nodes[i] = self.find(self.nodes[i]) #縮約
            return self.nodes[i]
    def unite(self, i, j):
        i = self.find(i)
        j = self.find(j)
        if i == j:
            return
        if self.nodes[i] > self.nodes[j]: #サイズ比較してiの方がサイズが大きいようにする
            i, j = j, i
        self.nodes[i] += self.nodes[j] #大きい方に小さい方を統合しサイズを登録する。
        self.nodes[j] = i # jの親はi
    
    def size(self, i): # 所属する集合の大きさを返す
        i = self.find(i)
        return -self.nodes[i]

n, m = map(int, input().split())
ds = DisjointSets(n)
for _ in range(m):
    a, b = map(lambda x: int(x) - 1, input().split())
    ds.unite(a, b)

ans = 0
for i in range(n):
    ans = max(ans, ds.size(i))
print(ans)

Measured memory_bytes: 80952
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <cmath>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int n;
  cin >> n;
  n %= 10;
  if(n == 3) cout << "bon" << endl;
  else if(n == 0 || n == 1 || n == 6 || n == 8) {
    cout << "pon" << endl;
  }
  else {
    cout << "hon" << endl;
  }
}

Measured memory_bytes: 3636
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*
cout<<setprecision(20);
cin.tie(0);
ios::sync_with_stdio(false);
*/
const llint mod=1000000007;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	llint n,Q,r=0;cin>>n>>Q;
	while(Q--){
		llint a,b;cin>>a>>b;
		if(a==0){cout<<(r+b-1)%n +1<<endl;}
		else{r+=b;}
	}
	return 0;
}


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

using namespace std;
using ll = long long;

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

int main() {
  int x, y, z, k;
  cin >> x >> y >> z >> k;
  vector<ll> a(x), b(y), c(z);
  rep(i, x) cin >> a[i];
  rep(i, y) cin >> b[i];
  rep(i, z) cin >> c[i];

  vector<ll> e;
  rep(i, x) rep(j, y) e.push_back(a[i] + b[j]);
  sort(e.rbegin(), e.rend());

  vector<ll> f;
  rep(i, min(x * y, k)) rep(j, z) f.push_back(e[i] + c[j]);
  sort(f.rbegin(), f.rend());

  rep(i, k) cout << f[i] << endl;

  return 0;
}


Measured memory_bytes: 44036
n=int(input())
a=list(map(int,input().split()))
flg=0
for i in range(n):
  if a[i]%2==0:
    if a[i]%3!=0 and a[i]%5!=0:
      flg=1

if flg==0:
  print("APPROVED")
else:
  print("DENIED")

Measured memory_bytes: 3064
import java.util.Scanner;

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

		for(char x: S.toCharArray()){
			int count = 0;
			for(char s: S.toCharArray()){
				if(x == s){
					count++;
				}
			}
			if (count%2==1){
				System.out.println("No");
				return;
			}
		}
		System.out.println("Yes");
		return;
	}
}

Measured memory_bytes: 20948
#include <bits/stdc++.h>
using namespace std;
 
using ll=long long;
 
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
const ll MOD = 1e9 + 7;

int main() {
    int h, w;
    cin >> h >> w;
    vector<vector<char>> mp(h, vector<char>(w));
    int bc = 0;
    rep(i, h) {
        rep(j, w) {
            cin >> mp[i][j];
            if (mp[i][j] == '#') ++bc;
        }
    }
    vector<vector<int>> dp(h, vector<int>(w, -1));
    queue<pair<int, int>> q;
    int dx[4] = {-1, 0, 0, 1};
    int dy[4] = {0, -1, 1, 0};
    q.push({0,0});
    dp[0][0] = 0;
    while (!q.empty()) {
        auto p = q.front(); q.pop();
        int x = p.first; int y = p.second;
        rep(i, 4) {
            int nx = x + dx[i]; int ny = y + dy[i];
            if (0 <= nx && nx < h && 0 <= ny && ny < w && mp[nx][ny] == '.' && dp[nx][ny] == -1) {
                dp[nx][ny] = dp[x][y] + 1;
                q.push({nx,ny});
            }
        }
    }
    int rt = dp[h-1][w-1];
    int ret = (rt == -1) ? -1 : h*w - rt - bc -1;
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VL = vector<LL>;
using PII = pair<int, int>;
using PLL = pair<LL, LL>;

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define FILL(a, b) memset(a, b, sizeof(a))

void dout() { cerr << endl; }

template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << H << ' ';
    dout(T...);
}

const LL INF = 1e14 + 47;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    VL a(n + 1);
    FOR(i, 0, n + 1) cin >> a[i];
    VL suf(n + 2);
    suf[n] = a[n];
    RFOR(i, n, 0)
        suf[i] = suf[i + 1] + a[i];
    bool ok = a[0] <= 1;
    LL in = 1 - a[0];
    LL ans = a[0];
    FOR(i, 1, n + 1)
    {
        ans += in;
        if (a[i] > in * 2)
            ok = false;
        else
        {
            ans += a[i];
            in = min(2 * in - a[i], suf[i + 1]);
        }
    }
    if (!ok)
        ans = -1;
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 4784
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
using namespace std;
int inf = 1000000000;

class Graph{
public:
  int v;
  int cost = inf;
  int ftime = -1;
  int ltime = -1;
  vector<int> e;
};
vector<Graph> g;
int cnt = 0;
void dfs(int pos){
  if( g[pos].ftime != -1 ) return;
  cnt++;
  g[pos].ftime = cnt;
  for(int i=0; i<g[pos].e.size(); i++){
    dfs(g[pos].e[i]);
  }
  cnt++;
  g[pos].ltime = cnt;
}
void bfs(int pos){
  queue<int> q;
  q.push(pos);
  while(!q.empty()){
    int p = q.front();
    q.pop();
    for(int i=0; i<g[p].e.size(); i++){
      if( g[ g[p].e[i] ].cost != inf ) continue;
      g[ g[p].e[i] ].cost = min(g[ g[p].e[i] ].cost, g[p].cost + 1);
      q.push(g[p].e[i]);
    }
  }
}

int main(void) {

  int n;
  cin >> n;
  g.resize(n);
  int u, k;
  for(int i=0; i<n; i++){
    cin >> u >> k;
    u--;
    g[u].v = u;
    g[u].e.resize(k);
    for(int j=0; j<k; j++){
      cin >> g[u].e[j];
      g[u].e[j]--;
    }
    sort(g[u].e.begin(), g[u].e.end());
  }

  g[0].cost = 0;
  bfs(0);
  for(int i=0; i<n; i++) cout << g[i].v + 1 << " " << (g[i].cost == inf ? -1 : g[i].cost) << endl;

  // for(int i=0; i<n; i++) dfs(i);
  // for(int i=0; i<n; i++){
  //   cout << g[i].v + 1 << " " << g[i].ftime << " " << g[i].ltime << endl;
  // }



  return 0;
}

// EOF

Measured memory_bytes: 3100
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;

int dp[20010][256];
int solve_testcase() {
    int N, M; scanf("%d%d", &N, &M);
    if(N == 0 and M == 0) return 1;

    vector<int> C(M), X(N);
    for(int i=0; i<M; i++) scanf("%d", &C[i]);
    for(int i=0; i<N; i++) scanf("%d", &X[i]);

    fill(dp[0], dp[N+1], INF);
    dp[0][128] = 0;
    for(int i=0; i<N; i++) {
        for(int j=0; j<256; j++) {
            for(int k=0; k<M; k++) {
                int nj = j + C[k];
                if(nj < 0) nj = 0;
                if(nj > 255) nj = 255;
                int diff = (X[i] - nj);
                chmin(dp[i+1][nj], dp[i][j] + diff*diff);
            }
        }
    }

    int ans = INF;
    for(int i=0; i<256; i++) chmin(ans, dp[N][i]);
    printf("%d\n", ans);
    return 0;
}

int main() {
    while(!solve_testcase());
    return 0;
}



Measured memory_bytes: 23288
#include <bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i = m; i < (int)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<int> v(n);
    rep(i, n) v[i] = i + 1;
    set<int> E[10];

    rep(i, m) {
        int a, b;
        cin >> a >> b;
        E[a].insert(b);
        E[b].insert(a);
    }
    int cnt = 0;
    while (1) {
        bool can = true;
        rep(i, n - 1) {
            if (!E[v[i]].count(v[i + 1])) can = false;
        }
        if (can) cnt++;
        NP(v);
        if (v[0] != 1) break;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
int main( void ){
	int n;
	if (!scanf( "%d", &n ))
		return -1;
	int sum = 0;
	int max = 0;
	for(int i = 0; i < n; i++){
		int num;
		if (!scanf( "%d", &num ))
			return -1;
		if (num > max)
			max = num;
		sum += num;
	}
	if(max * 2 < sum)
		printf( "Yes\n" );
	else
		printf( "No\n" );
	return 0;
}


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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { std::cout << #a << " = " << a << "\n"; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; }
template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; }
template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; }

typedef long long ll;
int const inf = INT_MAX / 2;

int dfs(ll curr, bool three, bool five, bool seven, ll N) {
  if (curr > N) return 0;
  int ret = 0;
  if (curr + 3 <= N) {
    ret += dfs(curr * 10 + 3, 1, five, seven, N);
  }
  if (curr + 5 <= N) {
    ret += dfs(curr * 10 + 5, three, 1, seven, N);
  }
  if (curr + 7 <= N) {
    ret += dfs(curr * 10 + 7, three, five, 1, N);
  }
  return ret + (three && five && seven);
}

int main() {
  int N; cin >> N;
  cout << dfs(0, 0, 0, 0, N) << endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N = int(input())
ABC = [list(map(int,input().split())) for i in range(N)]

dp = [[0]*3 for i in range(N+1)]

for i in range(1,N+1):
    dp[i] = [max([dp[i-1][k]+ABC[i-1][j] for k in range(3) if j != k]) for j in range(3)]

print(max(dp[N]))

Measured memory_bytes: 80732
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <cstring>
#include <map> 
#include<set>
#include<queue>
#include <iomanip>

typedef long long ll;

#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;

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

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h,n, w,m,t; string s;
ll R, C;
ll sy, sx, gy, gx;
char maze[110][110];
ll dis[20][20];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);
}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%ma;
		}
	}
}

ll GetDigit(ll num) {
	return log10(num) + 1;
}
ll Combination(int n, int r)
{
	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> numerator(r);
	vector<ll> denominator(r);

	for (int k = 0; k < r; k++)
	{
		numerator[k] = n - r + k + 1;
		denominator[k] = k + 1;
	}

	for (int p = 2; p <= r; p++)
	{
		int pivot = denominator[p - 1];
		if (pivot > 1)
		{
			int offset = (n - r) % p;
			for (int k = p - 1; k < r; k += p)
			{
				numerator[k - offset] /= pivot;
				denominator[k] /= pivot;
			}
		}
	}

	ll result = 1;
	for (int k = 0; k < r; k++)
	{
		if (numerator[k] > 1) result *= numerator[k];
		result %= ma;
	}

	return result;
}

ll bfs() {
	queue<P> que;
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) dis[i][j] = INF;
	}
	que.push(P(sy - 1, sx - 1));
	dis[sy - 1][sx - 1] = 0;

	while (que.size() > 0) {
		P p = que.front();
		que.pop();
		if (p.first == gy - 1 && p.second == gx - 1) break;
		for (ll i = 0; i < 4; i++) {
			ll ny = p.first + dy[i];
			ll nx = p.second + dx[i];
			if (0 <= ny && ny < R && 0 <= nx && nx < C && maze[ny][nx] == '.' && dis[ny][nx] == INF) {
				que.push(P(ny, nx));
				dis[ny][nx] = dis[p.first][p.second] + 1;
			}
		}
	}
	return dis[gy - 1][gx - 1];
}


int main() {
	ll k, a, b;
	cin >> k >> a >> b;
	ll ck = 1;
	if (b - a <= 2) {
		cout << 1 + k << endl;
	}
	else {
		ck = a; k -= (a - 1);
		if (k % 2 == 0) {
			ck += (k / 2 * (b - a));
		}
		else {
			ck += (k / 2 * (b - a)) + 1;
		}
		cout << ck << endl;
	}
}

Measured memory_bytes: 256