akhauriyash/Code-Regression huggingface dataset:
INF = 10**10
H, W = [int(i) for i in input().split(" ")]
Ch, Cw = [int(i) + 1 for i in input().split(" ")]
Dh, Dw = [int(i) + 1 for i in input().split(" ")]
S = [[False for i in range(W + 4)], [False for i in range(W + 4)]]
for i in range(H):
    S.append([False, False] + [j == '.' for j in input()] + [False, False])
S += [[False for i in range(W + 4)], [False for i in range(W + 4)]]


def check(h, w, island_num):
    assert S[h][w]
    block[h][w] = island_num
    if S[h - 1][w] and block[h - 1][w] == -1:
        check(h - 1, w, island_num)
    if S[h + 1][w] and block[h + 1][w] == -1:
        check(h + 1, w, island_num)
    if S[h][w - 1] and block[h][w - 1] == -1:
        check(h, w - 1, island_num)
    if S[h][w + 1] and block[h][w + 1] == -1:
        check(h, w + 1, island_num)


block = []
for i in range(H + 4):
    block.append([-1 for j in range(W + 4)])

island_num = 0

for h in range(H + 4):
    for w in range(W + 4):
        if S[h][w] and block[h][w] == -1:
            check(h, w, island_num)
            island_num += 1


neighbor = {}
for island in range(island_num):
    neighbor[island] = set()


for h in range(2, H + 2):
    for w in range(2, W + 2):
        if block[h][w] != -1:
            for y in range(h - 2, h + 3):
                for x in range(w - 2, w + 3):
                    if block[y][x] != -1 and block[h][w] != block[y][x]:
                        neighbor[block[h][w]].add(block[y][x])


start = block[Ch][Cw]
goal = block[Dh][Dw]
assert start != -1
assert goal != -1


dist = [INF for i in range(island_num)]
dist[start] = 0

nexts = [start]
while True:
    _nexts = []
    for n in nexts:
        for neigh in neighbor[n]:
            assert neigh != -1
            if dist[neigh] > dist[n] + 1:
                _nexts.append(neigh)
                dist[neigh] = dist[n] + 1
    nexts = list(set(_nexts))
    if len(nexts) == 0:
        break

if dist[goal] == INF:
    print(-1)
else:
    print(dist[goal])


Measured memory_bytes: 148532
using System;
using System.Collections.Generic;
using System.Linq;

namespace debug
{
    public static partial class Program
    {
        public static void Main()
        {
            n = Console.ReadLine().ToLong();
            var pis = Console.ReadLine().ArrayLongs();

            long cnt = 0;
            for (int i1 = 1; i1 < n - 1; i1++)
            {
                var list = new List<long>();
                list.Add(pis[i1 - 1]);
                list.Add(pis[i1]);
                list.Add(pis[i1 + 1]);
                list.Sort();
                if (list[1] == pis[i1])
                {
                    cnt++;
                }
            }

            Console.WriteLine(cnt);
        }
    }

    public static partial class Program
    {
        //テンプレここから
        public static long a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z;
        public static long GCD(long aaa, long bbb) => bbb == 0 ? aaa : GCD(bbb, aaa % bbb);
        public static long LCM(long aaa, long bbb) => aaa * bbb / GCD(aaa, bbb);
        public static long ToLong(this double ddd) => (long) ddd;
        public static long ToLong(this string str) => long.Parse(str);
        public static long[] ToLong(this IEnumerable<string> strs) => strs.Select(x => x.ToLong()).ToArray();
        public static long[] ArrayLongs(this string str, char opr = ' ') => str.Split(opr).ToLong();
        public static long Diff(long aaa, long bbb) => Math.Abs(Math.Max(aaa, bbb) - Math.Min(aaa, bbb));
        public static long Sign(this long iii) => Math.Sign(iii);
        public static bool IsEven(this long iii) => iii % 2 == 0;
        public static readonly int[] Dx = {0, -1, 0, 1};
        public static readonly int[] Dy = {-1, 0, 1, 0};
        public const int MOD = 1000000007;
        public const string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        public const string ALPHABET = "abcdefghijklmnopqrstuvwxyz";
        public static long ToLong(this char ccc) => ccc.ToString().ToLong();
        public static string Join(this IEnumerable<string> array, string sep = "") => string.Join(sep, array);
        public static string Join(this IEnumerable<char> array, string sep = "") => string.Join(sep, array);
        public static string JoinToStr(this IEnumerable<long> array, string sep = "")
            => array.Select(xxx => xxx.ToString()).Join(sep);
        //テンプレここまで
    }
}

Measured memory_bytes: 13524
x, y = gets.split

case x
when 'A' then
  case y
  when 'A' then
    puts '='
  when 'B' then
    puts '<'
  when 'C' then
    puts '<'
  when 'D' then
    puts '<'
  when 'E' then
    puts '<'
  when 'F' then
    puts '<'
  end
when 'B' then
  case y
  when 'A' then
    puts '>'
  when 'B' then
    puts '='
  when 'C' then
    puts '<'
  when 'D' then
    puts '<'
  when 'E' then
    puts '<'
  when 'F' then
    puts '<'
  end
when 'C' then
  case y
  when 'A' then
    puts '>'
  when 'B' then
    puts '>'
  when 'C' then
    puts '='
  when 'D' then
    puts '<'
  when 'E' then
    puts '<'
  when 'F' then
    puts '<'
  end
when 'D' then
  case y
  when 'A' then
    puts '>'
  when 'B' then
    puts '>'
  when 'C' then
    puts '>'
  when 'D' then
    puts '='
  when 'E' then
    puts '<'
  when 'F' then
    puts '<'
  end
when 'E' then
  case y
  when 'A' then
    puts '>'
  when 'B' then
    puts '>'
  when 'C' then
    puts '>'
  when 'D' then
    puts '>'
  when 'E' then
    puts '='
  when 'F' then
    puts '<'
  end
when 'F' then
  case y
  when 'A' then
    puts '>'
  when 'B' then
    puts '>'
  when 'C' then
    puts '>'
  when 'D' then
    puts '>'
  when 'E' then
    puts '>'
  when 'F' then
    puts '='
  end
end


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

ll n;
vector<ll>a;
map<ll,ll>mp;
ll solve(){
   ll ans=0;
   rep(i,n){
       ll id=i+1;
       ll h=a[i];
       ans+=mp[id-h];
       mp[id+h]++;
   }

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

    cin>>n;
    a.resize(n);
    rep(i,n)cin>>a[i];
    cout<<solve()<<endl;
    return 0;
}

Measured memory_bytes: 27332
#include <bits/stdc++.h>
// #pragma GCC optimize("Ofast")
using namespace std;
#define INF 100001

int main()
{
  int N,d;
  cin >> N;
  set<int> d_set{};
  for (int i = 0; i < N; ++i)
  {
    cin >> d;
    d_set.insert(d);
  }
  cout << d_set.size() << endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys
import os
import math

directions = [(1, 0), (-1, 0), (0, 1), (0, -1)]

for s in sys.stdin:
    H, W = map(int, s.split())
    if H == W == 0:
        break

    # map
    M = []
    for i in range(H):
        s = input().strip()
        M.append(s)

    # W x H white map
    A = [[None for i in range(W)] for j in range(H)]

    def drawable(x, y):
        if 0 <= x < W and 0 <= y < H and A[y][x] == None:
            return True
        else:
            return False

    color_num = 0

    def fill(x, y):
        global color_num

        Q = [(x, y)]
        while Q:
            p = Q.pop(0)
            _x = p[0]
            _y = p[1]
            A[_y][_x] = color_num
            for direction in directions:
                new_x = _x + direction[0]
                new_y = _y + direction[1]
                if drawable(new_x, new_y) and M[_y][_x] == M[new_y][new_x]:
                    A[new_y][new_x] = color_num
                    Q.append((new_x, new_y))

    for y in range(H):
        for x in range(W):
            if drawable(x, y):
                color_num += 1
                fill(x, y)

    print(color_num)

Measured memory_bytes: 7968
#include<stdio.h>
  
#define MAX 10000
  
typedef struct{
  
  int parent;
    
  int left;

  int right;

}Node;
  
Node T[MAX];

int D[MAX], H[MAX], n;
  
void setDepth(int,int);

int setHeight(int);

int getSibling(int);

void output(int);
  
int main(){

  int i, v, l, r, root;

  root = 0;
  
  scanf("%d",&n);
   
  for(i = 0; i < n; i++){

    T[i].parent = -1;
  }

  for(i = 0 ;i < n; i++){

    scanf("%d %d %d",&v,&l,&r);

    T[v].left = l;

    T[v].right = r;

    if(l != -1)T[l].parent = v;

    if(r != -1)T[r].parent = v;
  }
  
  for(i = 0 ; i < n; i++){

    if(T[i].parent == -1)
      root = i;

  }
   
  setDepth(root,0);

  setHeight(root);
  
  for(i = 0; i < n; i++){

    output(i);

  }
  return 0;
}
  
void setDepth(int u, int d){
  
  if(u == -1)
    return;

  D[u] = d;

  setDepth(T[u].left, d+1);

  setDepth(T[u].right,d+1);

}
  
int setHeight(int u){
  
  int h1,h2;
  
  h1 = h2 = 0;

  if(T[u].left != -1)h1 = setHeight(T[u].left) + 1;

  if(T[u].right != -1)h2 = setHeight(T[u].right) + 1;

  return H[u] = (h1 > h2 ? h1 : h2); 
}
  
int getSibling(int u){
  
  if(T[u].parent == -1)return -1;

  if(T[T[u].parent].left != u && T[T[u].parent].left != -1)
    return T[T[u].parent].left;

  if(T[T[u].parent].right != u && T[T[u].parent].right != -1)
    return T[T[u].parent].right;

  return -1;
}
  
void output(int u){

  int count;
  
  printf("node %d: parent = %d, sibling = %d, ",u,T[u].parent,getSibling(u));
  
  count = 0;
  
  if(T[u].left != -1)
    count++;
  if(T[u].right != -1)
    count++;
  
  printf("degree = %d, depth = %d, height = %d, ",count,D[u],H[u]);
  
  if(T[u].parent == -1)
    printf("root\n");

  else if(T[u].left == -1 && T[u].right == -1)
    printf("leaf\n");

  else 
    printf("internal node\n");

}

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


int main() {
  string s;
  cin >> s;
  int N =s.size();
  bool a=true;
  rep(i,N/2){
    if(s.at(i)==s.at(N-1-i)) continue;
    a=false;
    break;
  }
  rep(i,(N-1)/2){
    if(s.at(i)==s.at((N-1)/2-1-i)) continue;
    a=false;
    break;
  }
  for(int i=0;i<(N-(N+3)/2)/2;i++){
    if(s.at((N+3)/2-1+i)==s.at(N-1-i))continue;
    a=false;
    break;
  }
    if(a) cout << "Yes" <<endl;
    else cout << "No" <<endl;
}





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

using namespace std;

int main(){

	int wi=0;
	string s;

	cin>> s;

	for(int i=0;i<s.size();i++) if(s[i]=='o') wi++;

	if(8<=15-s.size()+wi) cout<< "YES" << endl;
	else cout<< "NO" << endl;


}

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

int main(){
    int n;
    cin>>n;
    cout<<(n+1)/2<<endl;
}

Measured memory_bytes: 256
#include <cstdio>

/* -----------------------------------------------------------------------------
	型とクラス定義
----------------------------------------------------------------------------- */

/* -----------------------------------------------------------------------------
	大域データ
----------------------------------------------------------------------------- */
int r;	// 円の半径


int main () {

	// 個数と長さの読込み
	scanf("%d", &r);

	printf("%d\n", r*r);

	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
LL N,X,tmp;
int main(){
	cin>>N>>X;
	tmp=X;
	for(int i=0;i<4;i++){
		cin>>X;
		tmp=min(tmp,X);
	}
	cout<<(N-1)/tmp+5<<endl;
	return 0; 
}

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

//pragmas
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
*/

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

const long double pi = acos(-1.0);

#define FOR(a,b,c) for(ll (a)=(b);(a)<(c);++(a))
#define FORE(a,b,c) for(ll (a)=(b);(a)<=(c);++(a))
#define FORN(a,b,c) for(ll (a)=(b);(a)>(c);--(a))
#define FORNE(a,b,c) for(ll (a)=(b);(a)>=(c);--(a))
#define COUT(n) printf("%d\n", (n))
#define COUTLL(n) printf("%lld\n", (n))
#define CIN(n) scanf("%d", &(n))
#define CINLL(n) scanf("%lld", &(n))
#define MEM(a,b) memset((a), (b), sizeof((a)))
#define MAX(a,b) (a) = max((a), (b))
#define MIN(a,b) (a) = min((a), (b))
#define nl '\n'
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back

void init(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
}

void infile(){
	freopen("input.in", "r", stdin);
}

void outfile(){
	freopen("output.out", "w", stdout);
}

ll modex(ll a, ll b, ll mod){
	if(b == 0)
		return 1;
	if(b == 1)
		return a;
	ll tmp = modex(a, b/2, mod);
	tmp = (tmp * tmp) % mod;
	if(b & 1)
		tmp = (tmp * a) % mod;
	return tmp;
}

//End of template

int n;
ld arr[3000];
ld memo[3005][3005];

ld dp(int id, int tails){
	//cout << id << ' ' << tails << nl;
	if(id == n && tails <= n/2){
		return 1;
	}
	if(id == n && tails > n/2){
		return 0;
	}
	if(memo[id][tails] >= 0){
		return memo[id][tails];
	}	
	ld one, two;
	one = (1.00-arr[id])*dp(id+1, tails);
	//cout <<" DP" << dp(id+1, tails) << nl;
	two = arr[id]*dp(id+1, tails-1);
	//cout << "DP2 " <<  << nl;
	return memo[id][tails] = one + two;
}

int main(){
	init();

	cin >> n;
	FOR(i, 0, n){
		cin >> arr[i];
	}
	MEM(memo, -1);
	ld ans = dp(0, n);
	cout << fixed << setprecision(12) << ans << nl;
	return 0;	
}

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

int ans[114][2][12];//二つ目の次元の0の0に数列の長さ、0の1に操作回数、1に答えの数列

int counter=0,flag=0;

void solve(){
	int n;
	cin >> n;
	if(n==0){flag=1;return;}
	ans[counter][0][0]=n;
	
	int S[12];//数列
	for(int i=0;i<n;i++){
		cin >> S[i];
	}
	
	bool check=false;//操作の有無のフラグ
	int time=0;//操作回数
	do{
		map<int,int> marker;
		for(int i=0;i<n;i++){
			marker[S[i]];
			marker[S[i]]++;
		}
		check=false;
		for(int i=0;i<n;i++){
			if(S[i]!=marker[S[i]]){
				check=true;
				S[i]=marker[S[i]];
			}
		}
		if(check) time++;
	}while(check);
	
	ans[counter][0][1]=time;
	for(int i=0;i<n;i++){
		ans[counter][1][i]=S[i];
	}
	counter++;
}

int main(){
	while(flag==0)solve();
	for(int i=0;i<counter;i++){
		cout << ans[i][0][1] << endl;
		for(int j=0;j<ans[i][0][0]-1;j++){
			cout << ans[i][1][j]<<" ";
		}
		cout << ans[i][1][ans[i][0][0]-1] << endl;
	}
}
			
	
	

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

using namespace std;

const int MAXN = 2010;
const int MAXL = 1010;
int N;
vector<int> V;

int find_me(int left, int right, int sum) {

    int ans = left - 1;
    while (left <= right) {
        int mid = (right + left) / 2;
        if ( V[mid] < sum ) {
            left = mid + 1;
            ans = mid;
        } else {
            right = mid - 1;
        }
    }
    return ans;
}

int main(){
    cin >> N;
    for(int i = 1, x; i <= N; i++) {
        cin >> x;
        V.push_back(x);
    }
    sort(V.begin(), V.end());
    //for (auto it: V) cout << it << " ";
    //cout << endl;
    int cnt = 0;
    for (int i = 0; i < V.size(); i++) {
        int a = V[i];
        for (int j = i + 1; j < V.size(); j++) {
            int b = V[j];
            int sum = a + b;
            /*
            for (int k = j + 1; k < V.size(); k++) {
              if (V[k] < sum) cnt++;
            }
            */

            int rs = find_me(j, V.size() - 1, sum);

            //cout << a << " " << b << " " << rs << endl;
            //if (V[left] < sum) left = j;
            cnt += rs - j;

        }
    }
    cout << cnt;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iterator>
#include <vector>
#include <functional>
#include <string>
#include <sstream>
#include <algorithm>

using namespace std;
typedef unsigned long long ull;

vector<ull> split(string& str){
	std::istringstream iss(str);
	std::string buf;
	vector<ull> res;
	while(std::getline(iss,buf,' ')){
		res.push_back(stoi(buf));
	}
	return res;
}

int main(){
	int n,m;
	cin>>n>>m;
	cin.ignore();
	vector<ull> vec(n-1);
	generate(vec.begin(),vec.end(),[]{return 0;});
	//?§??????????
	string line;
	getline(cin,line);
	vector<ull> t(split(line));
	for(int c = 0,e = t.size()-1;c < e;c++){
		int mx = max(t[c],t[c+1]),mn = min(t[c],t[c+1]);
		for(int mm = mn;mm < mx;mm++){
			vec[mm-1]++;
		}
	}
	vector<ull> av(n-1);
	vector<ull> bv(n-1);
	vector<ull> cv(n-1);

	for(int i = 0;i < n-1;i++){
		cin>>av[i]>>bv[i]>>cv[i];
	}
	ull res = 0;
	for(int i = 0;i < n-1;i++){
		if((av[i] - bv[i])*vec[i] < cv[i]){
			res += av[i]*vec[i];
		}else{
			res += bv[i]*vec[i]+cv[i];
		}
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 7784
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=5e5+10;
int n,q,x[N],d[N],Min[N];
int main()
{
	scanf("%d%d",&n,&x[0]);
	for (int i=1;i<=n;i++) scanf("%d",&d[i]),x[i]=min(x[i-1],abs(x[i-1]-d[i]));
	Min[n+1]=1;
	for (int i=n;i;i--) Min[i]=(d[i]>=2*Min[i+1]?Min[i+1]:Min[i+1]+d[i]);
	scanf("%d",&q);
	for (int i=1;i<=q;i++){
		int p;
		scanf("%d",&p);
		puts(x[p-1]>=Min[p+1]?"YES":"NO");
	}
	return 0;
}

Measured memory_bytes: 7680
from collections import defaultdict
INF = 10 ** 10


def main():
    N, W = map(int, input().split())
    items = []
    for _ in range(N):
        v, w = map(int, input().split())
        items.append((v, w))

    dp = [[INF] * (N * 100 + 1) for _ in range(N + 1)]
    dp[0][0] = 0
    for i in range(N):
        v, w = items[i]
        for j in range(len(dp[0])):
            if dp[i][j] != INF:
                dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])
                dp[i + 1][j + v] = min(dp[i + 1][j + v], dp[i][j] + w)
    ans = 0
    for i in range(len(dp)):
        for j in range(len(dp[0])):
            if dp[i][j] <= W:
                ans = max(ans, j)
    print(ans)

if __name__ == '__main__':
    main()

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

int main()
{
  int n,a,b;
  scanf("%d%d%d",&n,&a,&b);
  if(a*n>b) {printf("%d",b);}
  else {n=n*a; printf("%d",n);}
  return 0;
}

Measured memory_bytes: 256
import math
import collections


def C(n, r):
    if n < 2:
        return 0
    else:
        return n*(n-1)//r


N = int(input())
A = list(map(int, input().split()))
c = collections.Counter(A)
dic = {}
total = 0
for key, value in c.items():
    C_val = C(value, 2)
    dic[key] = C_val
    total += C_val
for i in range(N):
    print(total - dic.get(A[i]) + C(c[A[i]]-1, 2))


Measured memory_bytes: 32020
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vec> mat;
int n,B[200001];
void inout(int x){
    string s;
    cout<<x<<"\n";
    cin>>s;
    if(s=="Vacant") B[x]=-1;
    if(s=="Male") B[x]=1;
    if(s=="Female") B[x]=2;
}
int solve(int x,int y){
    int mid;
    if(x<y) mid=(x+y)/2;
    else mid=(x+y+n)/2;
    inout(mid);
    if(B[mid]==-1) return 0;
    if((y-x+1+n*(x>y))%4==1){
        if(B[x]==B[mid]) solve(mid,y);
        else solve(x,mid);
    }
    else{
        if(B[x]==B[mid]) solve(x,(mid-1+n)%n);
        else solve(mid,(y+1)%n);
    }
}
int main(){
    cin>>n;
    inout(0);
    if(B[0]==-1) return 0;
    solve(0,n-1);
}

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

#define MEM(a, b) memset(a, b, sizeof a);
#define REP(i, k) for(int i = (0); i < int(k); i++ )
#define FOR(i, a, b) for(int i = (a); i <= int(b); i++)

#define ALL(cont) cont.begin(), cont.end()
#define RALL(cont) cont.begin(), cont.end()
#define FOREACH(it, l) for(auto it=l.begin(); it != l.end(); it++)
#define mp make_pair
#define pb push_back
#define INF (int)INT_MAX
#define EPS (int)1e-9
#define PI acos(-1)
#define MOD 1000000007

#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

typedef long L;
typedef unsigned long UL;
typedef long long LL;
typedef unsigned long long ULL;

string to_string(string s) {
    return '"' + s + '"';
}

string to_string(const char* s) {
    return to_string((string) s);
}

string to_string(bool b) {
    return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

void solve(__attribute__((unused)) int tc = 0) {
    int n;
    LL h, x, y;
    vector<LL> a, b;
    cin >> n >> h;

    REP(_, n) { cin >> x >> y; a.pb(x); b.pb(y); }
    
    sort(ALL(a), greater<LL>());
    sort(ALL(b), greater<LL>());

    LL p = a[0];
    LL t = 0;
    REP(i, b.size()) {
        if (b[i] > p && h > 0) {
            h -= b[i];
            t++;
        }
    }
    LL m = 0;
    if (h > 0) m = ceil((double)h/ p);
    cout << (t + m) << endl;


    return;
}

int main() {
#ifdef FILE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    cin.tie(0);
    ios_base::sync_with_stdio(false);

    /*int TC;
      cin >> TC;
      REP(tc, TC) {
      solve(tc);
      }*/
    solve();
#ifdef TIME
    cout << "Execution time(second) : " << int(clock() * 1000.0 / CLOCKS_PER_SEC) << " ms" << endl;
#endif
}


Measured memory_bytes: 2036
import sys
import string
import io

readline = sys.stdin.buffer.readline
n, m = map(int, readline().split())
es = []
for _ in range(m):
    a, b = map(int, readline().split())
    es.append((a, b))
def find(x):
    if par[x] == x:
        return x
    else:
        par[x] = find(par[x])
        return par[x]
def same(x, y):
    return find(x) == find(y)
def unite(x, y):
    x = find(x)
    y = find(y)
    if x == y:
        return 0
    par[x] = y
ans = 0
for i in range(m):
    par = [_ for _ in range(n + 1)]
    for j, k in enumerate(es):
        if i == j:
            continue
        a, b = k
        unite(a, b)
    a, b = es[i]
    if not same(a, b):
        ans += 1
print(ans)


Measured memory_bytes: 3892
#include <bits/stdc++.h>
using namespace std;
//debug
#ifdef grief
#define debug(...) do{\
	fprintf(stderr , "%s - %d : (%s) = " , __PRETTY_FUNCTION__ , __LINE__ , #__VA_ARGS__ );\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){
	cerr<<x<<endl;
}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){
	cerr<<x<<" , ";
	_DO(tail...);
}
#else
#define debug(...)
#endif
//type
typedef long long ll;
typedef pair<int,int> pii;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef priority_queue<pll,vector<pll>,greater<pll> > heap;
//macro
#define SZ(x) ((ll)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define F first
#define S second
#define REP(i,n) for(ll i=0;i<(n);i++)
#define REP1(i,a,b) for(ll i=(a);i<=(b);i++)
#define mkp make_pair
#define pb push_back
const ll INF=1e18;
const ll MA=1e5+5;
const ll MOD=1e9+7;
//}}}
ll n,A,B;
ll a[MA];
ll ca[MA];
ll cb[MA];
int d1=0,d2=0;
ll fca(int k){
	if(k<d1)	return 0;
	return ca[k];
}
ll fcb(int k){
	if(k<d2)	return 0;
	return cb[k];
}
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin>>n>>A>>B;
	ca[0]=cb[0]=1;
	ll ma,x;
	cin>>ma;
	a[0]=-INF; a[1]=ma;
	for(int i=2;i<=n;i++){
		cin>>x;
		a[i]=x;
		int s1=upper_bound(a,a+i-1,x-B)-a; //plus in B
		s1--;
		cb[i-1]=fca(s1);
		cb[i-1]%=MOD;
		int s2=upper_bound(a,a+i-1,x-A)-a; //plus in A
		s2--;
		ca[i-1]=fcb(s2);
		ca[i-1]%=MOD;
		if(x<ma+A){
			d1=i-1;
		}
		else{
			ca[i-1]+=ca[i-2];
			ca[i-1]%=MOD;
		}
		if(x<ma+B){
			d2=i-1;
		}
		else{
			cb[i-1]+=cb[i-2];
			cb[i-1]%=MOD;
		}
		debug(ca[i-1],cb[i-1]);
		ma=x;
	}
	debug(ca[n-1],cb[n-1]);
	ll ans=ca[n-1]+cb[n-1];
	ans%=MOD;
	cout<<ans<< '\n';
	return 0;
}


Measured memory_bytes: 2688
#include <iostream>
#include <stack>
#include <vector>
#include <map>

using namespace std;


int main(){
    for(;;){
    int n;
    cin >> n;
    if(n==0) break;
    int ans=0;
    int bef=0;
    int r=0,l=0;
    for (int i=0; i<n; i++) {
        string S;
        cin >> S;
        if (S=="lu") {
            l++;
        }
        if (S=="ru") {
            r++;
        }
        if (S=="ld") {
            l--;
        }
        if (S=="rd") {
            r--;
        }
        if (r==l and r != bef) {
            ans++;
            bef=r;
        }
    }
    cout << ans<<endl;
    }
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
using namespace std;
const int M=2e3+5;
int que[M],order[M],tmp[M],now[M],tot,top,n,k,q;
void in()
{
    scanf("%d%d%d",&n,&k,&q);
    for(int i=1;i<=n;++i)scanf("%d",&que[i]),order[i]=que[i];
}
void add(int le,int ri)
{
    tot=0;
    if(le>ri||ri-le+1<k)return;
    for(int i=le;i<=ri;++i)tmp[++tot]=que[i];
    sort(tmp+1,tmp+1+tot);
    for(int i=ri-le+2-k;i>=1;--i)now[++top]=tmp[i];
}
int test(int mn)
{
    int p=1;top=0;
    for(int i=1;i<=n;++i)if(que[i]<mn)add(p,i-1),p=i+1;
    if(top<q)return INT_MAX; 
    sort(now+1,now+1+top);
    return now[q]-mn;
}
void ac()
{
    int ans=INT_MAX;
    sort(order+1,order+1+n);que[++n]=-INT_MAX;
    for(int i=1;i<n;++i)ans=min(test(order[i]),ans);
    printf("%d",ans);
}
int main()
{
    in();ac();
    return 0;
}

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

const int N = 500050;

int bit[N][26], n, q, type, l, r;
char c;

void upd(int ind1, int ind2, int chng) {
	++ind1;
  	while (ind1 < N) {
     	bit[ind1][ind2] += chng;
    	ind1 += ind1&-ind1;
    }
}

int qry(int ind1, int ind2) {
	int ans = 0;
  	while (ind1) {
    	ans += bit[ind1][ind2];
      	ind1 -= ind1&-ind1;
    }
  	return ans;
}

int qry(int a, int b, int c) {
	return qry(b,c) - qry(a-1,c);
}

int main() {
	cin >> n;
  	char s[n];
  	cin >> s >> q;
  	for (int i = 0; i < n; i++) {
     	 upd(i, s[i] - 'a', 1);
    }
  	while (q--) {
     	cin >> type;
      	if (type == 1) {
          	cin >> l >> c;
          	upd(l-1,s[l-1]-'a',-1);
          	s[l-1] = c;
        	upd(l-1,s[l-1]-'a',1);
        }
      	else {
        	cin >> l >> r;
          	int ans = 0;
          	for (int i = 0; i < 26; i++) {
             	ans += qry(l, r, i) ? 1 : 0; 
            }
          	cout << ans << endl;
        }
    }
}


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

int main(){
  string s;
  cin>>s;
  for(int i=0;i<s.size();i++){
    if(s.at(i)=='1') s.at(i)='9';
    else if(s.at(i)=='9') s.at(i)='1';
  }
  cout<<s<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include <vector>
#include<algorithm>
#include<iostream>
using namespace std;
int main(){
    int M,D;
    cin >> M >> D;

    int ans = 0;

    for(int i=1;i<=M;i++){
        for(int j=10;j<=D;j++){
            if(i == ((j%10)*(j/10)) && (j%10) >= 2 && (j/10) >=2){
                //cout << "month " << i << "day " << j << endl;;
                ans++;
                }
            }
        }

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







Measured memory_bytes: 256
#include<iostream>
#define for1(i, n) for(int i = 1; i <= (n);i++)
using namespace std;
int h, w;
char map[510][510];
int main() {
	cin >> h >> w;
	for1(i, h)for1(j, w)cin >> map[i][j];
	for1(i, h) { for1(j, w) { if (i == 1)cout << '#'; else if (i == h)cout << '.'; else if (j % 2 == 0 || map[i][j] == '#')cout << '#'; else cout << '.'; } cout << endl; }cout << endl;
	for1(i, h) { for1(j, w) { if (i == 1)cout << '.'; else if (i == h)cout << '#'; else if (j % 2 == 1 || map[i][j] == '#')cout << '#'; else cout << '.'; } cout << endl; }
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Int32;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        label:
        int n = Parse(ReadLine());
        var a = new int[n + 2];
        var sp = ReadLine().Split();
        int sum = 0;
        for (int i = 0; i < sp.Length; ++i)
        {
            a[i + 1] = Parse(sp[i]);
            sum += Abs(a[i + 1] - a[i]);
        }
        sum += Abs(a[a.Length - 2]);
        for (int i = 1; i < a.Length - 1; ++i)
        {
            int diff = Abs(a[i] - a[i - 1]) + Abs(a[i + 1] - a[i]) - Abs(a[i + 1] - a[i - 1]);
            WriteLine(sum - diff);
        }
    }
}


Measured memory_bytes: 25948
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    N = int(input())
    S = input().rstrip('\n')
    ans = N
    w = 0
    e = S.count("E")
    for s in S:
        if s == "E":
            e -= 1
        ans = min(ans, w+e)
        if s == "W":
            w += 1
    print(ans)


if __name__ == '__main__':
    main()


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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  
  int ans;
  if ((A + B) < C) {
    ans = B + (A + B) + 1;
  } else {
    ans = B + C;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n,m,cnt;
	cin>>n>>m;
	vector<string>a(n),b(m);
	for(int i=0;i<n;i++){
		cin>>a.at(i);
	}
	for(int i=0;i<m;i++){
		cin>>b.at(i);
	}
	for(int i=0;i<n-m+1;i++){
		for(int j=0;j<n-m+1;j++){
			cnt=0;
			for(int k=0;k<m;k++){
				for(int l=0;l<m;l++){
					if(a[i+k][j+l]==b[k][l]){
						cnt++;
					}
					else{break;}
				}
			}
			if(cnt==m*m){
				cout<<"Yes"<<endl;
				return 0;
			}
		}
	}
	cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
    int date[10000],i=0,c=1;
    while(1){
        if(i>10000)break;
        scanf("%d",&date[i]);
        if(date[i]==0)break;
        i++;
    }
    i=0;
    while(1){
        if(date[i]==0)break;
        if(date[i]!=0){
            printf("Case %d: %d\n",c,date[i]);
            c++;
            i++;
        }
    }
    return 0;
}


Measured memory_bytes: 1908
use std::io::*;
use std::str::FromStr;
use std::collections::VecDeque;

struct Task {
    name: String,
    time: i32,
}

fn main() {
    let nq = read_vec::<i32>();
    let n = nq[0];
    let q = nq[1];

    let mut queue: VecDeque<Task> = VecDeque::new();
    let mut total_time = 0;

    for _ in 0..n {
        let name: String = read();
        let time: i32 = read();
        queue.push_back(Task{name, time});
    }

    while queue.len() > 0 {
        let this: Task = queue.pop_front().expect("Error parsing");
        if this.time > q {
            total_time += q;
            queue.push_back(Task{
                name: this.name,
                time: this.time - q,
            });
        } else {
            total_time += this.time;
            println!("{} {}", this.name, total_time);
        }
    }

}

/// 標準入力から一行を読み取り、指定の型に変換する関数
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line)
        .ok()
        .expect("Faild to read Vec");
    line.trim().split_whitespace()
        .map(|i| i.parse().ok().unwrap()).collect()
}


Measured memory_bytes: 7064
M, D = map(int, input().split())
cnt = 0
for m in range(1, M + 1):
  for d in range(1, D + 1):
    if d // 10 >= 2 and d % 10 >= 2 and (d // 10) * (d % 10) == m:
      cnt += 1
print(cnt)

Measured memory_bytes: 2940
using System;

namespace A___Dodecagon
{
    class Program
    {
        static void Main(string[] args)
        {
            int r;
            r = Convert.ToInt32(Console.ReadLine());
            
            
                int sum = 3 * (r * r);
                Console.WriteLine(sum);
            

            Console.ReadLine();
        }
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <stdio.h>
using namespace std;

int main(void){
    int n,m,l;
    int i,j,k;
    cin>>n;
    cin>>m;
    cin>>l;
    
    int A[n][m];
    int B[m][l];
    long C[n][l];
    
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            scanf("%d",&A[i][j]);
        }
    }
    
    for(int i=0;i<m;i++){
        for(int j=0;j<l;j++){
            scanf("%d",&B[i][j]);
        }
    }
    
    for(int i=0;i<n;i++){
        for(int j=0;j<l;j++){
            C[i][j]=0;
        }
    }
    
    for(i=0;i<n;i++){
        for(j=0;j<l;j++){
            for(k=0;k<m;k++){
                C[i][j]+=(A[i][k])*(B[k][j]);
            }
            cout<<C[i][j];
            if(j!=l-1)cout<<" ";
        }
        cout<<endl;
    }
    
}



Measured memory_bytes: 3252
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		String A =scan.next();
		String B =scan.next();
		String C = scan.next();
		A = A.toUpperCase();
		B = B.toUpperCase();
		C = C.toUpperCase();
        char [] an = new char[3];
        an[0] = A.charAt(0);
        an[1] = B.charAt(0);
        an[2] = C.charAt(0);
		
        for(char h: an){
        	System.out.print(h);
        }
	}}


Measured memory_bytes: 21844
N,M = map(int, input().split())
 
pref = [[0] for i in range(N+1)]
q=[]

for i in range(M):
    p,y = map(int, input().split())
    pref[p].append(y)
    q.append([p,y])
for p in pref:
    p.sort()
 
import bisect
for p,y in q:
    print("%06d%06d" %(p, bisect.bisect_left(pref[p], y)))

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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

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

  int N = S.length();
  for (int i = 0; i < N; i++){
    string now = "";
    for (int j = i; j < N; j++) now += T[j];
    for (int j = 0; j < i; j++) now += T[j];
    if (S == now){
      Yes(); return 0;
    }
  }
  No();

  return 0;
}


Measured memory_bytes: 3548
let () = Scanf.scanf "%d %d\n" @@ fun n m ->
  let ds = Array.make n None in
  try
    for i = 0 to m - 1 do
      Scanf.scanf "%d %d\n" @@ fun s c ->
        match ds.(s - 1) with
        | None ->
            if n <> 1 && s = 1 && c = 0 then raise Not_found;
            ds.(s - 1) <- Some c
        | Some c' -> if c <> c' then raise Not_found
    done;
    Array.iteri (fun i -> function
      | None -> print_string @@ if i = 0 && n <> 1 then "1" else "0"
      | Some d -> print_int d) ds;
    print_newline ()
  with Not_found -> print_endline "-1"

Measured memory_bytes: 2432
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <tuple>
#include <list>
#include <deque>
#include <stack>
#include <complex>
#include <functional>
#include <regex>
#include <map>
#include <numeric>

using namespace std;

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

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

using ll = long long;
using ld = long double;
using ull = unsigned long long;

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

int main(void) {
  ll A, B; cin >> A >> B;
  ll _gcd = gcd(A, B);
  ll tmp = _gcd, result = 1;

  for (ll i = 2; i * i <= _gcd; i++) {
    bool found = false;
    while (tmp % i == 0) {
      if (!found) result++;
      found = true;
      tmp /= i;
    }
  }
  if (tmp != 1) result++;
  cout << result << endl;
  return 0;
}


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

struct P{double x,y;};

void koch(int n,P a,P b){
    if(n==0)return;
    P s,t,u;
    double angle=M_PI*60.0/180.0;
    s.x=(2.0*a.x+1.0*b.x)/3.0;
    s.y=(2.0*a.y+1.0*b.y)/3.0;
    t.x=(1.0*a.x+2.0*b.x)/3.0;
    t.y=(1.0*a.y+2.0*b.y)/3.0;
    u.x=(t.x-s.x)*cos(angle)-(t.y-s.y)*sin(angle)+s.x;
    u.y=(t.x-s.x)*sin(angle)+(t.y-s.y)*cos(angle)+s.y;
    
    koch(n-1,a,s);
    printf("%.8f %.8f\n",s.x,s.y);
    koch(n-1,s,u);
    printf("%.8f %.8f\n",u.x,u.y);
    koch(n-1,u,t);
    printf("%.8f %.8f\n",t.x,t.y);
    koch(n-1,t,b);
}
int main(){
    P a,b;
    int n;
    
    scanf("%d",&n);
    
    a.x=0;
    a.y=0;
    b.x=100;
    b.y=0;
    printf("%.8f %.8f\n",a.x,a.y);
    koch(n,a,b);
    printf("%.8f %.8f\n",b.x,b.y);
    
    return 0;
}


Measured memory_bytes: 3236
#include <iostream>
using namespace std;
static const int INFTY = (1 << 21);

int n,M[100][100];

void dikstra(){
  int u,minu,d[100],p[100],color[100];
  for (int i = 0; i < n; i++) {
    color[i] = 0;
    d[i] = INFTY;
  }
  d[0] = 0;
  color[0] = 1;

  while (1) {
    minu = INFTY;
    u = -1;
    for (int i = 0; i < n; i++) {
      if (color[i] != 2 && d[i] < minu) {
        minu = d[i];
        u = i;
      }
    }
    if (u == -1)break;
    color[u] = 2;

    for (int v = 0; v < n; v++) {
      if (color[v] != 2 && M[u][v] != INFTY) {
        if (d[u] + M[u][v] < d[v]) {
          d[v] = d[u] + M[u][v];
          color[v] = 1;
        }
      }
    }
  }
  for (int i = 0; i < n; i++) {
    cout << i << " " <<(d[i] == INFTY ? -1 : d[i])<< endl;
  }

}
int main() {
  int u,v,k,c;
  cin >> n/* variable */;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      M[i][j] = INFTY;
    }
  }
  for (int i = 0; i < n; i++) {
    cin >> u >> k;
    for (int j = 0; j < k; j++) {
      cin >> v >> c;
      M[u][v] = c;
    }
  }

  dikstra();

  return 0;
}



Measured memory_bytes: 3136
//author:Deshansh Garg
#include<bits/stdc++.h>
typedef long long int lli;
using namespace std;

int main()
{
 lli r,c;
 cin>>r>>c;
 char a[r][c];
 for(lli i=0;i<r;i++)
 {
 	for(lli j=0;j<c;j++)
 	{
     cin>>a[i][j];
 	}
 }
 lli grid[r+1][c+1];
 grid[1][1]=1;
 for(lli i=0;i<=r;i++)
 {
 	for(lli j=0;j<=c;j++)
 	{   lli x1=0,x2=0;
 		if(i==0 || j==0) grid[i][j]=0;
 		else if(i==1 && j==1) grid[i][j]=1;
 		else if(a[i-1][j-1]=='#') grid[i][j]=0;
 	//	else if(a[i-2][j-1]=='#'&& a[i-1][j-2]=='#') grid[i][j]=0;
 		else
 		{
 			if(a[i-2][j-1]!='#')
 				x1=grid[i-1][j];
 			if(a[i-1][j-2]!='#')
 				x2=grid[i][j-1];
 			grid[i][j]=(x1+x2)%1000000007;
 		}
 	}
 }
 cout<<grid[r][c];
 return 0;
}

Measured memory_bytes: 9088
# Try AtCoder
# author: Leonardone @ NEETSDKASU
############################################################
def gs() gets.strip end
def gi() gets.to_i end
def gf() gets.to_f end
def gss() gs.split end
def gis() gss.map(&:to_i) end
def nmapf(n,f) n.times.map{ __send__ f } end
def ngs(n) nmapf n,:gs end
def ngi(n) nmapf n,:gi end
def ngss(n) nmapf n,:gss end
def ngis(n) nmapf n,:gis end
def arr2d(h,w,v=0) h.times.map{[v] * w} end
def for2p(hr,wr,&pr) hr.each{|i|wr.each{|j| yield(i,j)}} end
def nsum(n) n * (n + 1) / 2 end
def vcount(d,r=Hash.new(0)) d.inject(r){|m,e| m[e]+=1;m} end
MV4 = [[0, 1], [1, 0], [0, -1], [-1, 0]]
MV8 = MV4 + [[1, 1], [1, -1], [-1, -1], [-1, 1]]
DV7 = 7 + 10 ** 9
############################################################
 
S = gs

i = 0
h = Hash.new 0
h[S[0]] += 1
(1 ... S.size).each do |j|
    ch = S[j]
    h[ch] += 1
    mx = h.values.max
    l = j - i + 1
    if l < mx * 2
        puts "%d %d" % [i + 1, j + 1]
        exit
    end
    while j - i + 1 > mx * 2
        h[S[i]] -= 1
        i += 1
        mx = h.values.max
    end
end

puts "-1 -1"



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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  LL D;
  while(cin >> D,D){
	LL N, M;
	cin >> N >> M;
	VL xs(N*3);
	xs[0] = 0;
	xs[1] = D;
	xs[2] = -D;
	REP(i,N-1){
	  cin >> xs[3*(i+1)];
	}
	REP(i,N){
	  xs[3*i+1] = xs[3*i] + D;
	  xs[3*i+2] = xs[3*i] - D;
	}
	SORT(xs);
	LL ans = 0;
	REP(i,M){
	  LL x;
	  cin >> x;
	  auto it = upper_bound(ALL(xs), x);
	  ans += min(abs(*it - x), abs(x - *(it-1)));
	}
	cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 4972
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using st = string;
#define mrep(i, m, n) for(int i = m; i < n; i++)
#define rep(i, n) mrep(i, 0, n)
#define chmax(x, y) { x = max(x, y); }
#define chmin(x, y) { x = min(x, y); }
#define mp(x, y) make_pair(x, y)
#define mt(x, y, z) make_tuple(x, y, z)
#define tp(x, y) tie(x, y)
#define tt(x, y, z) tie(x, y, z)

int main() {
    int n;
    cin >> n;
    vector<tuple<string, int, int>> sp(n);
    rep(i, n){
        string s;
        int p;
        cin >> s >> p;
        int x = i + 1;
        sp.at(i) = mt(s, p, x);
    }
    sort(sp.begin(), sp.end());
    rep(i, n - 1){
        mrep(j, i + 1, n){
            string s1 = get<0>(sp.at(i));
            string s2 = get<0>(sp.at(j));
            if(s1 == s2){
                int i1 = get<1>(sp.at(i));
                int i2 = get<1>(sp.at(j));
                if(i1 < i2){
                    tuple<string, int, int> t = sp.at(i);
                    sp.at(i) = sp.at(j);
                    sp.at(j) = t;
                }
            }
        }
    }
    rep(i, n){
        string s;
        int p;
        int x;
        tt(s, p, x) = sp.at(i);
        cout << x << endl;
    }
    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 2020000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
ll pcount(ll x) {return __builtin_popcount(x);};
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
    int n; cin >> n;
    vector<int> x(n),y(n),p(n);
    rep(i,n) cin >> x[i] >> y[i] >> p[i];
    vl ans(n+1,linf);
    vvl tate(1<<n,vl(n,linf)), yoko(1<<n,vl(n,linf));
    rep(bit,1<<n){
        rep(i,n){
            chmin(tate[bit][i], abs(x[i]));
            chmin(yoko[bit][i], abs(y[i]));
            rep(j,n){
                if(bit>>j & 1){
                    chmin(tate[bit][i], abs(x[i] - x[j]));
                    chmin(yoko[bit][i], abs(y[i] - y[j]));
                }
            }
        }
    }
    rep(bit,1<<n){
        int pcnt = pcount(bit);
        int stop = 1;
        for(int sub=bit; stop>0; sub=(sub-1)&bit){
            stop = sub;
            ll sum = 0;
            rep(i,n){
                sum += min(tate[sub][i], yoko[bit-sub][i]) * p[i];
            }
            chmin(ans[pcnt], sum);
        }
    }
    rep(i,n+1) cout << ans[i] << "\n";
}


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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

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

template <typename T1, typename T2> 
inline bool chmax(T1 &a, T2 b) {
  return a < b && (a = b, true);
}

template <typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {
  return a > b && (a = b, true);
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s,t;
  cin >> s >> t;

  if(s == t.substr(0,s.size()) && s.size()+1 == t.size()){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 3564
N = gets.to_i

if N == 1
  p 0
  exit
end

C, S, F = (N-1).times.map { gets.split.map(&:to_i) }.transpose

N.times do |n|
  t = 0
  (n...(N-1)).each do |i|
    case
    when t < S[i]
      t = S[i]
    when (t % F[i]) == 0
      t = t
    else
      t += F[i] - (t % F[i])
    end
    t += C[i]
  end
  p t
end


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

using vi = vector<int>;
using vvi = vector<vi>;

constexpr int INF = 1e9;

int main() {
    using state = tuple<int, int, int, int, int>;

    int W, H;
    while(cin >> W >> H, W) {
        int tx, ty, kx, ky;
        cin >> tx >> ty >> kx >> ky;
        tx--; ty--; kx--; ky--;
        vector<vector<int>> v(H, vector<int>(W));
        for(int i=0; i<H; ++i) {
            for(int j=0; j<W; ++j) {
                cin >> v[i][j];
            }
        }
        vector<vector<vvi>> d(H, vector<vvi>(W, vvi(H, vi(W, INF))));
        d[ty][tx][ky][kx] = 0;
        queue<state> que;
        que.push(make_tuple(0, ty, tx, ky, kx));
        int dx[4] = {0, -1, 0, 1},
            dy[4] = {1, 0, -1, 0};
        auto check = [&v, W, H](int y, int x) {
            return 0 <= y && y < H && 0 <= x && x < W && v[y][x] == 0;
        };
        int res = INF;
        while(!que.empty()) {
            int cd, y1, x1, y2, x2;
            tie(cd, y1, x1, y2, x2) = que.front();
            if(y1 == y2 && x1 == x2) {
                res = cd;
                break;
            }
            que.pop();
            for(int i=0; i<4; ++i) {
                int ny1 = y1+dy[i], nx1 = x1+dx[i];
                if(!check(ny1, nx1)) {
                    ny1 = y1;
                    nx1 = x1;
                }
                int ny2 = y2-dy[i], nx2 = x2-dx[i];
                if(!check(ny2, nx2)) {
                    ny2 = y2;
                    nx2 = x2;
                }
                if(d[ny1][nx1][ny2][nx2] > cd + 1 && cd + 1 < 100) {
                    d[ny1][nx1][ny2][nx2] = cd + 1;
                    que.push(make_tuple(cd+1, ny1, nx1, ny2, nx2));
                }
            }
        }
        if(res == INF) {
            cout << "NA" << endl;
        } else {
            cout << res << endl;
        }
    }
}


Measured memory_bytes: 31880