akhauriyash/Code-Regression huggingface dataset:
//    https://atcoder.jp/contests/abc104/tasks/abc104_c
#include <bits/stdc++.h>

using namespace std;

struct Probs {
	int p;
	int c;
	int index;
	int scoreAll;
	double effAll;
	Probs(int p, int c, int index){
		this->p = p;
		this->c = c;
		this->index = index;
		scoreAll = (1 + index) * 100 * p + c;
		effAll = (1 + index) * 100 + ((double)c) / p;
	}
};

int main(){
	int D, G;
	cin >> D >> G;

	vector<Probs> list;
	for (int i = 0; i < D; i++)
	{
		int p, c;
		cin >> p >> c;
		list.push_back(Probs(p, c, i));
	}

	int ans = INT_MAX;
	for(int i = 0; i < (1 << D); i++){
		int sum = 0;
		int count = 0;
		int restmax = 0;
		for (int k = 0; k < D; k++)
		{
			if( (i >> k) & 1 ){
				sum += list[k].scoreAll;
				count += list[k].p;
			} else {
				restmax = max(restmax, k);
			}
		}
		if(G >= sum){
			int r = (int) ceil(1.0 * (G - sum) / (list[restmax].index + 1) / 100);
			if(r < list[restmax].p){
				ans = min(ans, count + r);
			}
		} else {
			ans = min(ans, count);
		}
	}

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

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

//#pragma GCC optimize("O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
//#pragma GCC optimize ("unroll-loops")

using namespace std;
using namespace __gnu_pbds;

#define all(x) x.begin(), x.end()
#define mp make_pair
#define X first
#define Y second

template<typename T>
using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(322);

ll const mod = 1e9 + 7;

namespace {
    ll mul(ll a, ll b) {
        ll val = a * b - (ll)((ld)a * b / mod) * mod;
        if (val < 0) val += mod;
        if (val >= mod) val -= mod;
        return val;
    }
    ll poww(ll a, ll b) {
        ll val = 1;
        a %= mod;
        while (b > 0) {
            if (b % 2) val = mul(a, val);
            a = mul(a, a);
            b >>= 1;
        }
        return val % mod;
    }
    ll inv(ll a) {
        return poww(a, mod - 2);
    }
}

ll const maxn = 3e5 + 5;

signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll n; cin >> n; vector<ll> a(n);
    for(ll i =0 ;i<n;i++) cin >> a[i];
    sort(all(a));
    ll ans = 0;
    for(ll i = 0;i<n;i++){
        for(ll j = i+1;j<n;j++){
            ll sm = a[i] + a[j];
            ll pos = lower_bound(all(a), sm) - begin(a);
            ans += pos - j - 1;
        }
    }
    cout << ans;
    return 0;
}
/*

*/

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <queue>
#include <iomanip>
using namespace std;
priority_queue<pair<long long int, long long int>, vector<pair<long long int, long long int> >, greater<pair<long long int, long long int> > > que[100000];
long long int number[100000];
int main(){
	long long int n, m;
	cin >> n >> m;
	long long int p;
	long long int y;
	for(long long int i = 0;i < m;i++){
		cin >> p >> y;
		que[p - 1].push(make_pair(y, i));
	}
	long long int count;
	pair<long long int, long long int> e;
	for(long long int i = 0;i < n;i++){
		count = 1;
		while(que[i].size() > 0){
			e = que[i].top();
			que[i].pop();
			number[e.second] = (i + 1) * 1000000 + count;
			count++;
		}
	}
	for(long long int i = 0;i < m;i++){
		cout << setfill('0') << setw(12) << right << number[i] << endl;
	}
}


Measured memory_bytes: 8576
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int n;
    cin >> n;
    vec a(n);
    rep(i, n) cin >> a[i];

    vec b(n);
    
    int x = 0;

    rep(i, n) x = x ^ a[i];

    rep(i, n) {
        b[i] = x ^ a[i];
    }

    rep(i, n) {
        if (i != 0) cout << " ";
        cout << b[i];
    }
    cout << endl;
    return 0;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

ll A[10000];
int main2() {
  int N = nextInt();
  REP(i, N) A[i] = nextInt();
  sort(A, A+N);
  cout << A[N-1] - A[0] << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


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

using namespace std;

int main(){
	int n,m; cin >> n >> m;
	vector<int> kl[n+m];
	for(int i = 0; i < n; ++i){
		int kmax; cin >> kmax;
		for(int j = 0; j < kmax; ++j){
			int lg; cin >> lg;
			kl[i].push_back(n-1+lg);
			kl[n-1+lg].push_back(i);
		}
	}
	
	vector<bool> visited(n+m,false);
	queue<int> npos;
	npos.push(0);
	visited[0] = true;
	int cost = 1;
	while(!npos.empty()){
		int now = npos.front();
		npos.pop();
		for(int i = 0; i < kl[now].size(); ++i){
			int next = kl[now][i];
			if(visited[next])continue;
			visited[next] = true;
			npos.push(next);
		}
		cost ++;
	}
	bool flag = true;
	for(int i = 0; i < n; ++i){
		if(!visited[i]){
			flag = false;
			break;
		}
	}

	if(flag) cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;
}


Measured memory_bytes: 8824
def main():
    import sys
    sys.setrecursionlimit(10000000)
    #input = sys.stdin.readline

    from collections import Counter
    from collections import deque

    #dxy = [[0,1],[0,-1],[1,0],[-1,0]]
    #dxy = [[0,1],[0,-1],[1,0],[-1,0],[1,1],[1,-1],[-1,1],[-1,-1]]
    #MOD = 1000000007
    n = int(input())
    x = list(map(int, input().split()))
    ans = 1000000000000
    for i in range(min(x), max(x)+1):
        total = 0
        for j in x:
            total += (i-j)**2
        if ans>total:
            ans = total
    print(ans)



if __name__ == '__main__':
    main()

Measured memory_bytes: 3444
puts [6484,a=?+,0,1,3,?<,2,3,3]+[0,1].map{|x|[a,x,3,x]+(0..29).map{v=x+4;u=x*60+9+_1;[a,v,v,v,a,v,3,6,*[a,6,6,6]*(29-_1),?<,6,x,u,a,v,u,v]}}+(0..59).map{|t|[a,2,2,2]+(0...t).map{[a,8+t-_1,69+_1,5,?<,3,5,6,a,2,6,2]}}

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

int main()
{
    int h, w;
    cin >> h >> w;
    vector<string> c(h);

    for(int i = 0; i < h; i++){
        cin >> c[i];
        cout << c[i] << endl;
        cout << c[i] << endl;
    }
    
    return 0;

}

Measured memory_bytes: 256
import collections
n,k = map(int, raw_input().split(' '))
s = map(int,list(raw_input()))
stack = []
count,i,j = 0,0,0


while(j < len(s)):
	while(j < len(s) and s[j] == s[i]): j += 1
	stack.append((s[i], j - i))
	i = j
r = 0
cl = 0
q = collections.deque([])
for t,l in stack:
	q.append((t,l))
	cl += l
	if t == 0: k -= 1
	while(k < 0 and q):
		tu,tl = q.popleft()
		cl -= tl
		if tu == 0: k +=1

	r = max(cl, r)
print r

Measured memory_bytes: 45836
using System;

//提出 #3356307 - AtCoder Beginner Contest 112 
//https://beta.atcoder.jp/contests/abc112/submissions/3356307
class Program_ABC112_C_fgwiebfaoish
{
    static void Main()
    {
        long n = long.Parse(Console.ReadLine());
        int[][] arr = new int[n][];
        long ch = 0;
        for (long i = 0; i < n; i++)
        {
            arr[i] = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        }

        Array.Sort(arr, (a, b) => b[2] - a[2]); //高さでソート

        for (long i = 0; i <= 100; i++)
        {
            for (long j = 0; j <= 100; j++)
            {
                ch = Math.Abs(i - arr[0][0]) + Math.Abs(j - arr[0][1]) + arr[0][2];
                bool b = false;
                for (long k = 1; k < n; k++)
                {
                    var targetConst = Math.Abs(i - arr[k][0]) + Math.Abs(j - arr[k][1]);
                    if (ch != targetConst + arr[k][2])
                    {
                        if (arr[k][2] != 0 || ch > targetConst)
                        {
                            b = true;
                            break;
                        }
                    }
                }
                if (b == false)
                {
                    Console.WriteLine("{0} {1} {2}", i, j, ch);
                    Environment.Exit(0);
                }
            }
        }
    }  //Main
}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
#define max(a,b) (a<b?b:a)
#define abs(x) (x<0?(-x):x)
#define F(i,L,R) for (int i = L; i < R; i++)
#define FE(i,L,R) for (int i = L; i <= R; i++)
#define RF(i,L,R) for (int i = L; i > R; i--)
#define RFE(i,L,R) for (int i = L; i >= R; i--)
#define getI(a) scanf("%d", &a)
#define getII(a,b) scanf("%d%d", &a, &b)
#define getIII(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define VgetI(n) int (n); scanf("%d",&(n))
#define VgetII(n,m) int (n),(m); scanf("%d %d",&(n),&(m))
#define VgetIII(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k))
#define ll long long
#define INF 1000000000000000005
#define nINF -2000000000
#define MOD 1e9+7
#define PI 3.1415926535897932384626
int main(){
	int a,b,k;
	while(~getIII(a,b,k)){
		for(int i=100;i>0;i--) if(a%i==0&&b%i==0){
			k--;
			if(k==0){
				printf("%d\n",i);
				break;
			}
		}
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const long long MOD=998244353;
int main(){
    int n;scanf("%d",&n);
    int a[n];
    for(int i=0;i<n;i++)scanf("%d",&a[i]);
    int ans=0,now=101;
    for(int i=1;i<n;i++){
        if(a[i]==a[i-1]){
            ans++;
            a[i]=now;
            now++;
        }
    }
    printf("%d\n",ans);
    return 0;
}

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

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

template<class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;

#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define X                           first
#define Y                           second
#define Mp                          make_pair
#define sep                         ' '
#define endl                        '\n'
#define debug(x)                    cerr << #x << " = " << x << endl
#define SZ(x)                       ll(x.size())
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define set_random                  mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

const ll MAXN = 1e6 + 10;
const ll LOG = 22;
const ll INF = 8e18;
const ll MOD = 1e9 + 7; // 998244353; // 1e9 + 9;

ll n, m, p, A[MAXN], B[MAXN], C[MAXN], dist[MAXN], mark[MAXN];
vector<ll> adj[MAXN];

void DFS(ll v) {
    mark[v] = 1;
    for (ll u : adj[v]) {
        if (mark[u] == 0) DFS(u);
    }
}

int main() {
    fast_io;

    cin >> n >> m >> p;
    for (ll i = 1; i <= m; i++) {
        cin >> A[i] >> B[i] >> C[i];
        adj[B[i]].push_back(A[i]);
        C[i] = p - C[i];
    }

    DFS(n);
    fill(dist + 2, dist + MAXN, INF);
    for (ll i = 0; i < n + n; i++) {
        for (ll j = 1; j <= m; j++) {
            dist[B[j]] = min(dist[B[j]], dist[A[j]] + C[j]);
        }
    }
    for (ll i = 1; i <= m; i++)
        if (mark[B[i]] && dist[A[i]] < 1e18 && dist[B[i]] > dist[A[i]] + C[i])
            return cout << -1 << endl, 0;
    cout << max(0LL, -dist[n]) << endl;

    return 0;
}
/*

*/


Measured memory_bytes: 39296
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define FOR(i, a, b) for(ll i = a; i < b; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF (long long)1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main(void) {
	while(true) {
		int N;
		cin>>N;
		if(N == 0) break;
		int size = 0;
		ll res = 0;
		vector<string> s(N);
		map<char, ll> omomil;
		map<char, ll> omomir;
		vector<int> perm(10);
		vector<int> out;
		REP(i, 10) {
			perm[i] = (int)i;
		}
		REP(i, N) cin>>s[i];
		REP(i, N) {
			REP(j, s[i].size()) {
				if(omomil.count(s[i][s[i].size() - 1 - j]) == 0) {
					omomil[s[i][s[i].size() - 1 - j]] = 0;
					omomir[s[i][s[i].size() - 1 - j]] = 0;
					++size;
				}
				if(i != N - 1) omomil[s[i][s[i].size() - 1 - j]] += pow(10, j);
				else omomir[s[i][s[i].size() - 1 - j]] += pow(10, j);
			}
		}
		map<char, ll>::iterator ite3 = omomil.begin();
		int foo = 0;
		while(ite3 != omomil.end()) {
			REP(i, N) {
				if(s[i].size() > 1 && s[i][0] == (*ite3).first) {
					out.pb(foo);
					//cout<<(*ite3).first<<":"<<foo<<endl;
					break;
				}
			}
			++ite3;
			++foo;
		}

		vector<ll> sugoil(size);
		vector<ll> sugoir(size);
		ite3 = omomil.begin();
		REP(i, size) {
			sugoil[i] = (*ite3).second;
			++ite3;
		}
		ite3 = omomir.begin();
		REP(i, size) {
			sugoir[i] = (*ite3).second;
			++ite3;
		}
		do {
			ll l = 0;
			ll r = 0;
			bool cont = false;
			int roc = 0;
			REP(i, out.size()) {
				if(perm[out[i]] == 0) {
					cont = true;
					break;
				}
			}
			if(cont) continue;
			while(roc < size) {
				l += perm[roc] * sugoil[roc];
				++roc;
			}
			roc = 0;
			while(roc < size) {
				r += perm[roc] * sugoir[roc];
				++roc;
			}
			if(l == r) ++res;
		} while(next_permutation(ALL(perm)));

		ll hoge = 1;
		REP(i, 10 - size) {
			hoge *= 10 - size - i;
		}
		cout<<res / hoge<<endl;
	}
}

Measured memory_bytes: 3132
data = []
tmp = []
for x in range(0,1000000):
    a,b = map(int, input().split())
    if a==0:
        if b==0:
            break
        pass
    data.append((a,b))
for x in range(0,len(data)):
    tmp = list(data.pop(0))
    for y in range(0,tmp[0]):
        for z in range(0,tmp[1]):
            print("#",end='')
        print("")
    tmp.clear()
    print("")


Measured memory_bytes: 8988
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bits/stdc++.h>
#include<queue>
#include <numeric>
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();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define fore(i,a) for(auto &i:a)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 

LL gcd(LL a, LL b){
    if(b == 0) return a;
    return gcd(b,a%b);
}

LL lcm(LL a, LL b){
    LL g = gcd(a,b);
    return a/g *b;
}

int main(){
    int N;
    cin >> N;
    int A[N];
    for(int i=0;i<N;++i){
        cin >> A[i];
    }
    bool flag=1;
    int num=0;
    while(flag){
        flag=0;
        for(int i=N-1;i>=1;--i){
            if(A[i] < A[i-1]){
                swap(A[i],A[i-1]);
                flag=1;
                ++num;
            }
        }

    }
    for(int i=0;i<N;++i){
        if(i!=N-1){
            cout << A[i] << " ";
        }
        else{
            cout << A[N-1];
        }
    }
    cout << endl << num << endl;
}


Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define pi 3.141592653589793238

int main()
{
    int t=1;
    //cin>>t;


    while( t-- )
    {
        int k,a,b;
        cin>>k>>a>>b;

        if( a%k==0 )
            cout<<"OK"<<endl;
        else
        {
            if( a+k-(a%k)<=b )
                cout<<"OK"<<endl;
            else
                cout<<"NG"<<endl;
        }

    }
    return 0;
}


Measured memory_bytes: 3584
#include <string>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <utility>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iterator>
#include <sstream>

using namespace std;

int main()
{
	int t; cin>>t;
	while(t--){
		string s; cin>>s;
		sort(s.begin(),s.end(),greater<char>());
		int m,n;
		sscanf(s.c_str(),"%d",&m);
		sort(s.begin(),s.end(),less<char>());
		sscanf(s.c_str(),"%d",&n);
		cout << abs(m-n) << endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <iostream>

template  <typename T>
T gcd(T a, T b){
  if(a < b) std::swap(a, b);
  while(b != 0){
    a %= b; std::swap(a, b);
  }
  return a;
}

int main(void){
  int n, k; scanf("%d%d", &n, &k);
  int GCD = 0, mx = -1; 
  for(int _ = 0; _ < n; ++_){
    int a; scanf("%d", &a);
    if(mx < a) mx = a;
    GCD = gcd<int>(a, GCD);
  }
  puts(k <= mx and k % GCD == 0 ? "POSSIBLE" : "IMPOSSIBLE");
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int n,h;
    cin>>n>>h;
    vector<int>a(n),b(n);
    int mx=0;
    rep(i,n){
        cin>>a[i]>>b[i];
        mx=max(mx,a[i]);
    }
    int cnt=0;
    sort(b.rbegin(),b.rend());
    rep(i,n){
        if(mx<b[i])h-=b[i],cnt++;
        if(h<=0)break;
    }
    int ans=cnt;
    if(h>0){
        if(h%mx==0)ans+=h/mx;
        else ans+=h/mx+1;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, s, n)    for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...)  type __VA_ARGS__; read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream& operator>> (istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x): x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

i64 f(i64 n) { return n * (n + 1) / 2; }

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);

    var(int, N, M);
    print(f(N-1) + f(M-1));

    return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var s, n int
	fmt.Scan(&s)
	as := make([]int, 1000000)
	as[0] = s
	for i := 1; i < 1000000; i++ {
		//calculate n
		n = as[i-1]
		if n%2 == 0 {
			as[i] = n / 2
		} else {
			as[i] = 3*n + 1
		}
		for j := 0; j < i; j++ {
			if as[i] == as[j] {
				fmt.Println(i + 1)
				return
			}
		}
	}
}


Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define debug(x) cout << #x << " = " << (x) << endl;
#define pb push_back
#define MOD 1000000007
//#define MOD 998244353
//define MOD 1000000007000000
#define INF 1000000000000
#define EPS 0.00000000001
typedef long long ll;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    //---------------------------------------------

    char S[110];
	scanf("%s", S);
	int N = strlen(S);
	int ret = 10000;
	for (int i = 0; i < 26; ++i) {
		int reqmx = 0;
		for (int j = 0; j < N; ++j) {
			int waf = N - j;
			for (int k = j; k < N; ++k) {
				if (S[k] == i + 'a') {
					waf = min(waf, k - j);
				}
			}
			reqmx = max(reqmx, waf);
		}
		ret = min(ret, reqmx);
	}
	printf("%d\n", ret);
}


Measured memory_bytes: 256
#include<cstdio>

#define INF 0x7fffffff
int T;
int A[12];

int main()
{
	scanf("%d",&T);
	while(T--)
	{
		for(int i=1;i<=10;i++)
			scanf("%d",&A[i]);
		int x=INF,y=INF;
		bool f=1;
		for(int i=10;i>=1;i--)
		{
			if(A[i]>x&&A[i]>y)
			{
				f=0;
				break;
			}
			if(A[i]<x)
				x=A[i];
			else
				y=A[i];
		}
		if(f) printf("YES\n");
		else printf("NO\n");
	}
}

Measured memory_bytes: 2552
#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
#define ll long long
const int maxi=2000000000;
const int maxq=1000000000;
const ll mod=1000000007LL;
#define f(i,a,b) for(ll  i=(a); i<(b);++i)
/*
unsigned int countSetBits(unsigned int n)
{
    unsigned int count = 0;
    while (n) {
        count += n & 1;
        n >>= 1;
    }
    return count;
}
*/

/*
const int maxx=9000000;
void SieveOfEratosthenes(vector<int> &primes){
    bool IsPrime[maxx+1];
    memset(IsPrime, true, sizeof(IsPrime));
    for(int p=2;p*p<=maxx ;p++){
        if(IsPrime[p]){
            for(int i=p*p;i<maxx ;i+=p) IsPrime[i]=false;
        }
    }
    f(p,2,maxx +1){
        if(IsPrime[p]) primes.push_back(p);
    }
    }
*/
int aa[1000001];
ll func(ll a[], ll  n){
    ll xor_=0;
    f(i,0,n){
        xor_=xor_^a[i];
        }
        return xor_;
    }
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    /*ll n,sum=0;
    cin>>n;
    ll a[n];
    f(i,0,n){
        cin>>a[i];
        sum+=a[i];
    }
    ll x;
    cin>>x;
    while(x--){
        ll c,d;
        cin>>c>>d;
        f(i,0,n){
        if(a[i]==c){
            a[i]=d;
            sum=sum+d-c;
        }

        } cout<<sum<<endl;
    } */
    ll n;
    cin>>n;
    ll a[n];
    f(i,0,n) cin>>a[i];
    ll xor_=func(a,n);
    f(i,0,n){
        ll x=xor_^a[i] ;
        cout<<x<<' ';
    }
    return 0;
}




Measured memory_bytes: 5092
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#define int long long
using namespace std;
const int maxn = 2e5+10;

int read(){
	int x=0,f=1;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=(x<<3)+(x<<1)+c-48;c=getchar();}
	return x*f;
}

int to[maxn<<1],net[maxn<<1],h[maxn],e=1;
inline void add(int x,int y){
	to[++e]=y;net[e]=h[x];h[x]=e;
}

int f[maxn];
inline void dfs(int x,int fa){
	for(register int i=h[x];i;i=net[i]){
		int y=to[i];
		if(y==fa)continue;
		f[y]+=f[x];
		dfs(y,x);
	}
	return;
}
signed main(){
	int k,m,n;
	n=read();m=read();
	for(register int i=1;i<n;i++){
		int x=read(),y=read();
		add(x,y);
		add(y,x);
	}
	for(register int i=1;i<=m;i++){
		int x=read(),v=read();
		f[x]+=v;
	}
	dfs(1,0);
	for(register int i=1;i<=n;i++)printf("%lld ",f[i]);
	return 0;
}

Measured memory_bytes: 15616
#include <stdio.h>
#include <stdlib.h>

int compare_int(const void *a, const void *b){
  return *(int*)a - *(int*)b;
}

int main(void){

  int a[5];
  int i;
  int cnt = 0;
  for (i=0; i<3; i++) {
    scanf("%d", &a[i]);
  }
  qsort(a, 3, sizeof(int), compare_int);

  while(1) {
    qsort(a, 3, sizeof(int), compare_int);
    
    if (a[0] == a[1] && a[1] == a[2]) {
      break;
    }

    if (a[0] == a[1]) {
      a[0]++;
      a[1]++;
    }
    else {
      a[0] += 2;
    }
    cnt++;
  }

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


Measured memory_bytes: 128
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class B
{
	public static void Main()
	{
		long N = GetLong();
		long x = GetLong();
		long[] a = new long[N];
		for(int i = 0; i < N; i++)
			a[i] = GetLong();

		long ans = long.MaxValue;
		long[] f = Enumerable.Repeat(long.MaxValue, (int)N).ToArray();
		for(int k = 0; k < N; k++)
		{
			long cost = k * x;
			for(int i = 0; i < N; i++)
			{
				f[i] = Math.Min(f[i], a[(i - k + N) % N]);
				cost += f[i];
			}
			ans = Math.Min(ans, cost);		
		}

		Console.WriteLine(ans);
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}


Measured memory_bytes: 13524
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,K;
  cin>>N>>K;
  vector<int>A(N,0);
  for(int i=0;i<N;i++){
    int k;cin>>k;
    A.at(k-1)++;
  }
  sort(A.begin(),A.end());
  reverse(A.begin(),A.end());
  if(K==N){
    cout<<0<<endl;
  }
  else{
    int sum=0;
    for(int i=K;i<N;i++){
      sum=sum+A[i];
    }
    cout<<sum<<endl;
  }
}
      
    

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define fr(a,b) for(long long i=a;i<b;i++)
#define vi vector<ll>
const ll MAX=1e5+100;
const ll mod=1e9+7;
const ll INF=1e18+12;
set< pair<ll,ll> >ss;
ll dp[110][MAX];
ll sum[MAX];                                    //SAMEER KUMAR SINGH//
// ====================================================================================== ====================//


int main(){
   FASTIO;
   ll tt=1;
   //cin>>tt;

   while(tt--){
     ll n,k;cin>>n>>k;
     ll a[n];
     fr(0,n){
       cin>>a[i];
     }



     dp[0][0]=1;

     for(ll i=1;i<k+1;i++)
      dp[0][i]=0;

     for(ll i=1;i<=k+2;i++)
      sum[i]=1;
     sum[0]=0;
     ll zero=0;
     for(ll i=1;i<=n;i++){
        for(ll j=0;j<=k+1;j++){
           dp[i][j]=(sum[j+1]%mod-sum[max(j-a[i-1],zero)]%mod+mod)%mod;
        }
        ll ss=0;
        for(ll j=1;j<=k+1;j++){
           ss+=(dp[i][j-1])%mod;
           sum[j]=ss%mod;
        }
     }

     cout<<dp[n][k]<<"\n";


   }
}


Measured memory_bytes: 80128
#include<iostream>
#include<queue>
#include<vector>
#include<string>
#include<string.h>
using namespace std;

struct Edge{
  int src,dst;
  string weight;
  Edge(int src,int dst,string weight) :
    src(src), dst(dst), weight(weight) { }
};
bool operator<(const Edge &e,const Edge &f) {
  return e.weight>f.weight;
}

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

int main() {
  int n,a,s,g;
  int prev[480][40];
  string str[480][40];

  while(cin>>n>>a>>s>>g, n||a||s||g) {
    Graph graph(n);
    for(int i=0; i<a; ++i) {
      int x,y;
      string w;
      cin>>x>>y>>w;
      graph[x].push_back( Edge(x,y,w) );
    }

    //dij
    //init
    memset(prev, -1, sizeof(prev));
    for(int i=0; i<480; ++i)
      for(int j=0; j<40; ++j)
	str[i][j] = "";

    priority_queue<Edge> q;
    for(q.push( Edge(-2, s, "") );!q.empty();) {
      Edge e = q.top(); q.pop();
      int pos = e.dst, size = e.weight.size();
      if(prev[size][pos]!=-1) continue;
      prev[size][pos] = e.src;
      str[size][pos] = e.weight;
      for(int i=0; i<graph[pos].size(); ++i) {
	int npos = graph[pos][i].dst;
	if(size + graph[pos][i].weight.size() >= 12*n) continue;
	string nstr = e.weight + graph[pos][i].weight;
	if(str[nstr.size()][npos]==""||nstr<str[nstr.size()][npos]) {
	  str[nstr.size()][npos] = nstr;
	  q.push( Edge(size*n+pos, npos, nstr) );
	}
      }
    }

    //loop?
    int minpos = -1;
    string ans = "";
    for(int i=0; i<12*n; ++i) {
      if(str[i][g] == "") continue;
      if(ans == "" || ans>str[i][g]) {
	ans = str[i][g];
	minpos = i;
      }
    }
    bool flag = (minpos != -1);
    bool visit[40];
    memset(visit, false, sizeof(visit));
    int cur = minpos*n+g;
    while(flag&&cur!=-2) {
      if(visit[cur%n]) flag = false;
      visit[cur%n] = true;
      cur = prev[cur/n][cur%n];
    }
    cout<<(flag ? ans : "NO" )<<endl;
  }
}

Measured memory_bytes: 10000
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
s=0
for i in range(0,N-1):
    j=A[i]-1
    s=s+B[j]
    if(j+1!=N):
        if(A[i+1]-j==2):
            s=s+C[j]
j=A[N-1]-1
s=s+B[j]
print(s)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    string str,text="ABC";
    ll n;
    cin>>n;
    cin>>str;
    ll c=0;
    for(int i=0;i<n-2;i++)
    {
        if(str[i]=='A' && str[i+1]=='B' && str[i+2]=='C')
        {
            c++;
        }
    }
    cout<<c;
}

Measured memory_bytes: 256
package main

import "fmt"

func min(a, b int64) int64 {
	if a > b {
		return b
	}
	return a
}

func minMax(a, b, c int64) (min, max int64) {
	if a > b {
		a, b = b, a
	}
	if a > c {
		a, c = c, a
	}
	if b > c {
		b, c = c, b
	}
	min = a
	max = c
	return
}

func divideVerticalDiff(h, w, x int64) int64 {
	s1 := x * h
	w1 := (w - x) / 2
	w2 := (w - x) - w1
	s2 := w1 * h
	s3 := w2 * h
	min, max := minMax(s1, s2, s3)
	return max - min
}

func divideHorizontalDiff(h, w, x int64) int64 {
	s1 := x * h
	h1 := h / 2
	h2 := h - h1
	s2 := (w - x) * h1
	s3 := (w - x) * h2
	min, max := minMax(s1, s2, s3)
	return max - min
}

func calcMin(h, w int64) int64 {
	result := int64(10000000000)
	for x := int64(1); x < w; x++ {
		minDiff := min(divideVerticalDiff(h, w, x), divideHorizontalDiff(h, w, x))
		if minDiff < result {
			result = minDiff
		}
	}
	return result
}

func main() {
	var h, w int64
	fmt.Scan(&h, &w)

	fmt.Println(min(calcMin(h, w), calcMin(w, h)))
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    ll n, m;
    cin >> n >> m;
    vector<pair<ll, ll>> itv(m);
    for (int i = 0; i < m; i++)
    {
        ll a, b;
        cin >> a >> b;
        itv[i] = make_pair(b, a);
    }
    sort(itv.begin(), itv.end());
    ll ans = 0;
    ll t = 0;
    for (int i = 0; i < m; i++)
    {
        if (t <= itv[i].second)
        {
            ans++;
            t = itv[i].first;
        }
    }
    cout << ans << endl;
}

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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };




void solve() {
    int N; cin >> N;
    vector<vec> c(10, vec(10, 0));

    rep1(i, N){
        string s = to_string(i);
        c[s[0]-'0'][s[s.size()-1]-'0']++;
    }

    ll res=0;
    rep(i, 10){
        rep(j, 10){
            res += c[i][j]*c[j][i];
        }
    }

    cout << res << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 4352
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <utility>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <algorithm>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
#define rep(i,n)	for(int i=0;i<n;i++)
#define srep(i,a,n)	for(int i=a;i<n;i++)
#define REP(i,n)	for(int i=0;i<=n;i++)
#define SREP(i,a,n)	for(int i=a;i<=n;i++)
#define rrep(i,n)	for(int i=n-1;i>=0;i--)
#define RREP(i,n)	for(int i=n;i>=0;i--)
#define all(a)	(a).begin(),(a).end()
#define mp(a,b)	make_pair(a,b)
#define mt	make_tuple
#define fst	first
#define scn second
#define bucnt(x)	__buildin__popcount(x)
#define debug(x)	cout<<"debug: "<<x<<endl;

const ll inf = (ll)1e18;
const ll mod = (ll)1e9 + 7;
const ld eps = 1e-9;
const int dx[] = { 0,1,0,-1 };
const int dy[] = { 1,0,-1,0 };

int cnt[30];

int main() {
	string s;	cin >> s;
	rep(i, s.size())	cnt[s[i] - 'a']++;
	int ret = 10000;
	rep(i, 26) {
		if (cnt[i] == 0)	continue;
		string t = s;
		int cnt = 0;
		while (true) {
			bool flag = true;
			rep(j, t.size()) {
				if (t[j] - 'a' != i) {
					flag = false;
					break;
				}
			}
			if (flag)	break;
			string next;
			srep(j, 1, t.size()) {
				if (t[j - 1] - 'a' == i)	next += t[j - 1];
				else next += t[j];
			}
			t = next;
			cnt++;
		}
		ret = min(cnt, ret);
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using itn = int;
using ld = long double;
template<class T>
using vec = vector<T>;

#define FOR(i,a,b) for(int i=((int)(a));i<((int)(b));i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define all(x) (x).begin(),(x).end()


int main(){
  int n,m;
  cin >>n >>m;
  vec<int> l(m+1),r(m+1);
  for(int i=0;i<m;i++) cin >>l[i] >>r[i];

  vec<int> count(n+2,0);
  REP(i,m){
    ++count[l[i]];
    --count[r[i]+1];
  }
  vec<int> s(n+2,0);
  for(int i=1;i<n+2;i++){
    s[i] = s[i-1] + count[i];
  }

  int ans=0;
  REP(i,n+1){
    if(s[i] == m) ++ans;
  }

  cout <<ans <<endl;


/*
  set<int> st;
  REP(i,m){
    for(int j=1;j<l[i];j++) st.insert(j);
    for(int j=r[i]+1;j<=n;j++) st.insert(j);
  }

  int ans=0;
  for(int i=1;i<=n;i++){
    if(st.count(i) == 0) ans++;
  }

  cout <<ans <<endl;
*/
}


Measured memory_bytes: 1792
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac
import fractions
from functools import reduce
from operator import mul
import bisect
import sys
import logging
import heapq
import itertools

logging.basicConfig(level=logging.ERROR)

input = sys.stdin.readline

setrecursionlimit(1000000)


def main():
	n = int(input())
	a = list(map(int,input().split()))
	ans = list(reversed([a[i] for i in range(1 if n%2==0 else 0,n,2)])) + [a[i] for i in  range(0 if n%2==0 else 1,n,2)]
	for i in ans:
		print(i,end=' ')
	print()

main()

Measured memory_bytes: 121600
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define db long double
#define ii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define FN(i, n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i,n) for (int i = 1;i <= (int)(n); ++i)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(i,a,b) for(int i=b-1;i>=a;i--)
#define SET(A, val) memset(A, val, sizeof(A))
typedef tree<int ,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set ;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
const int N=100005;
#define iii pair<ii,int>
int a[N],b[N];
int main()
{
  std::ios::sync_with_stdio(false);
  cin.tie(NULL) ; cout.tie(NULL) ;
  set<iii> s;
  int n,h;
  cin>>n>>h;
  rep(i,1,n+1) cin>>a[i]>>b[i];
  rep(i,1,n+1)
    {
      s.insert(mp(mp(-a[i],1),i));
      s.insert(mp(mp(-b[i],2),i));
    }
  int ans=0;
  while(h>0)
    {
      auto it=*s.begin();
      int ind=it.se;
      int val=-it.fi.fi;
      if(a[ind]==val)
	{
	  cout<<ans+(h+val-1)/val<<endl;
	  return 0;
	}
      ans++;
      h-=val;
      s.erase(s.begin());
    }
  cout<<ans<<endl;
  return 0 ;
}


Measured memory_bytes: 13568
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>

using namespace std;

int main(void){
    string s;
    cin>>s;
    for(int i=0;i<s.length();i++){
        if(s[i]=='?')s[i]='D';
    }
    cout<<s<<endl;
    return 0;
}


Measured memory_bytes: 3752
import java.util.*;
public class Main {
	Scanner in = new Scanner(System.in);
	public static void main(String[] args) {
		new Main();
	}
	public Main() {
		new AOJ0201();
	}

	class AOJ0201{
		HashMap<String, ArrayList<String>> map;
		HashMap<String, Integer> price;
		
		int bfs(String target){
			int a = Integer.MAX_VALUE;
			int b = 0;
			if(price.containsKey(target))a=price.get(target);
			if(map.containsKey(target)==false)return a;
			ArrayList<String> list = map.get(target);
			for(int i=0;i<list.size();i++)if(map.containsKey(list.get(i))||price.containsKey(list.get(i))){
				b += bfs(list.get(i));
			}
			return Math.min(a, b);
		}
		
		public AOJ0201() {
			while(true){
				map = new HashMap<String, ArrayList<String>>();
				price = new HashMap<String, Integer>();
				int n = in.nextInt();
				if(n==0)break;
				for(int i=0;i<n;i++)price.put(in.next(),in.nextInt());
				int list_n = in.nextInt();
				for(int i=0;i<list_n;i++){
					String name = in.next();
					ArrayList<String> list;
					if(!map.containsKey(name))list = new ArrayList<String>();
					else list = map.get(name);
					int a = in.nextInt();
					for(int s=0;s<a;s++)list.add(in.next());
					map.put(name,list);
				}
				System.out.println(bfs(in.next()));
			}
		}
	}
}

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

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

  ll n, a, b;
  cin >> n >> a >> b;

  ll sum = a + b;
  ll c = n % sum;

  ll ans = a * (n / sum);
  if (c <= a) ans += c;
  else ans += a;

  cout << ans << '\n';

  return (0);
}


Measured memory_bytes: 3656
#include<cstdio>
#include<cstring>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
using namespace std;
int a,b;
int main(void)
{
    int n,k,a[1005];
    while(~scanf("%d%d",&n,&k))
    {
        int i,j,l=0;
        for(i=0;i<n;i++) scanf("%d",&a[i]);
        sort(a,a+n);
        for(i=n-k;i<n;i++)
            l+=a[i];
        printf("%d\n",l);
    }
    return 0;
}


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

int main() {
  int a, b;
  cin >> a >> b;
  
  if ( a%3 == 0 || b%3 == 0 || (a+b)%3 == 0 ) {
    cout << "Possible" << endl;
  }
  else { 
    cout << "Impossible" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int count, key;
    cin >> count;
    int A[count + 1];
    for (int i = 0; i < count; i++)
    {
        cin >> A[i];
    }
    for (int i = 0; i < count; i++)
    {
        key = A[i];
        int j = i - 1;
        while (j >= 0 && A[j] > key)
        {
            A[j + 1] = A[j];
            j--;
        }
        A[j + 1] = key;
        for (int i = 0; i < count; i++)
        {
            if (i < count - 1)
                cout << A[i] << " ";
            else
                cout << A[i];
        }
        cout << endl;
    }

    return 0;
}


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

using namespace std;

#pragma GCC optimize("O3")
static const auto __ = [] {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  return nullptr;
}();

bool solve() {
  int x, y;
  cin >> x >> y;
  return (y % 2 == 0) && (2 * x <= y) && (y <= 4 * x);
}

int main(int argc, char* argv[]) {
  cout << (solve() ? "Yes" : "No") << '\n';
  return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <string.h>

using namespace std;

int main() {
  int a, b, len, i;
  char s[11];
  cin >> a >> b >> s;
  len = a + b + 1;
  if (strlen(s) == len) {
    for (i = 0; i < len; i++) {
      if (i == a && s[i] == '-') continue;
      else {
        if (i != a && s[i] == '-') break;
        else if (i == a && s[i] != '-') break;
      }
    }
    if (i == len) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  else cout << "No" << endl;
  return 0;
}

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

int main()
{
    long long a,b,k;
    cin >> a >> b >> k;
    if(k-a<0) {
        cout << a-k << " " << b << endl;
    }
    else {
        k -= a;
        if(k-b<0) {
            cout << 0 << " " << b-k << endl;
        }
        else {
            cout << 0 << " " << 0 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = 0
for i in range(1,N+1):
    if i%3 == 0 and i%3 == 5:
        i = "FizzBuzz"
    elif i%3 == 0:
        i = "Fizz"
    elif i%5 == 0:
        i = "Buzz"
    else:
        A += i
print(A)
    
    


Measured memory_bytes: 9160
import java.util.Scanner;

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

        int N = sc.nextInt();
        int[] a = new int[N];
        for (int i = 0; i < a.length; ++i) {
            a[i] = sc.nextInt() - 1;
        }

        System.out.println(solve(a));

        sc.close();
    }

    static int solve(int[] a) {
        boolean[] visited = new boolean[a.length];
        visited[0] = true;
        int index = 0;
        for (int step = 1;; ++step) {
            index = a[index];
            if (index == 1) {
                return step;
            }
            if (visited[index]) {
                return -1;
            }

            visited[index] = true;
        }
    }
}

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

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

  bool flg=0;
  for(int i=0; i<n; i++){
    int s,f;
    cin >> s >> f;

    if(f<=a || b<=s){
      continue;
    }else{
      flg=1;
    }
  }

  cout << flg << endl;

  return 0;
}



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

int N , M , a[100005] ;
struct Union_Set{
	int fa[100005] ;
	void init(){
		for( int i = 1 ; i <= N ; i ++ ) fa[i] = i ;
	}
	int find( int x ){
		if( fa[x] == x ) return x ;
		return fa[x] = find( fa[x] ) ;
	}
	bool Union( int a , int b ){
		a = find( a ) , b = find( b ) ;
		if( a == b ) return false ;
		fa[a] = b ; return true ;
	}
}U ;

int bel[100005] , sta[100005] , topp , cnt[100005] , ans ;
vector<int> S[100005] , P[100005] ;
void solve(){
	for( int i = 1 ; i <= N ; i ++ ){
		bel[i] = U.find( i ) ;
		S[ bel[i] ].push_back( a[i] ) ;
		P[ bel[i] ].push_back( i ) ;
		if( S[ bel[i] ].size() == 1 ) sta[++topp] = bel[i] ;
	}
	for( int i = 1 ; i <= topp ; i ++ ){
		int u = sta[i] , siz = S[u].size() ;
		for( int j = 0 ; j < siz ; j ++ ) cnt[ S[u][j] ] ++ ;
		for( int j = 0 ; j < siz ; j ++ )
			if( cnt[ P[u][j] ] ) ans ++ ;
		for( int j = 0 ; j < siz ; j ++ ) cnt[ S[u][j] ] = 0 ;
	} printf( "%d" , ans ) ;
}

int main(){
	scanf( "%d%d" , &N , &M ) , U.init() ;
	for( int i = 1 ; i <= N ; i ++ )
		scanf( "%d" , &a[i] ) ;
	for( int i = 1 , u , v ; i <= M ; i ++ ){
		scanf( "%d%d" , &u , &v ) ;
		U.Union( u , v ) ;
	} solve() ;
}


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

struct data{
    std::string s;
    int p;
    int num;
};

int n;

data ttt;

std::vector<data> ds;

int main(){

    std::cin>>n;
    
    for(int i=0;i<n;i++){
        std::cin>>ttt.s>>ttt.p;
        ttt.num=i+1;
        ds.push_back(ttt);
    }

    std::sort(ds.begin(),ds.end(),[](const data &d1,const data &d2){
        if(d1.s==d2.s)
        return d1.p>d2.p;
        else
        return d1.s<d2.s;
        });

    for(auto&& x:ds)
    std::cout<<x.num<<std::endl;

    return 0;
}

Measured memory_bytes: 256