akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main()
{
  int H, W;

  while(true){
      cin >> H >> W;
      if(H==0&W==0) break;
      else {
        for(int i=0; i<H; i++){
          for(int j=0; j<W; j++)cout << "#";
          cout << endl;
        }
        cout << endl;
      }
  }
}



Measured memory_bytes: 3116
#include <cstdio>
#include <algorithm>
#include <cstring>

using i8 = std::int8_t;
using u8 = std::uint8_t;
using i16 = std::int16_t;
using u16 = std::uint16_t;
using i32 = std::int32_t;
using u32 = std::uint32_t;
using i64 = std::int64_t;
using u64 = std::uint64_t;
using i128 = __int128_t;
using u128 = __uint128_t;
using isize = std::ptrdiff_t;
using usize = std::size_t;

i32 dp[3001][3001];
char ans[3002];

auto main() -> i32 {
	char s[3001];
	char t[3001];
	scanf("%s%s", s, t);
	i32 slen = std::strlen(s);
	i32 tlen = std::strlen(t);
	for (i32 i = 0; i < slen; i += 1) {
		for (i32 j = 0; j < tlen; j += 1) {
			if (s[i] == t[j]) {
				dp[i + 1][j + 1] = dp[i][j] + 1;
			} else {
				dp[i + 1][j + 1] = std::max(dp[i][j + 1], dp[i + 1][j]);
			}
		}
	}

	char* p = ans + 3000;
	i32 i = slen;
	i32 j = tlen;
	while (i > 0 && j > 0) {
		if (dp[i][j] == dp[i - 1][j]) {
			--i;
		} else if (dp[i][j] == dp[i][j - 1]) {
			--j;
		} else {
			*p = s[i - 1];
			--p;
			--i, --j;
		}
	}
	puts(p + 1);
	return 0;
}


Measured memory_bytes: 36772
N = int(input())
A = [int(x) for x in input().split()]

flag = True
count = 0

while flag:
    flag = False
    for i in range(1, N)[::-1]:
        if A[i] < A[i-1]:
            A[i], A[i-1] = A[i-1], A[i]
            flag = True
            count += 1
print(' '.join(map(str, A)))
print(count)



Measured memory_bytes: 5604
#include <algorithm>
#include <bitset>
#include <cassert>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define POW(n) ((n) * (n))
#define ALL(a) (a).begin(), (a).end()
#define dump(v) (cerr << #v << ": " << v << endl)
#define cerr                                                                   \
  if (true)                                                                    \
  cerr

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<unsigned long long> vull;

// ll n = to_T<ll>("114514")
template <class T> T to_T(const string &s) {
  istringstream is(s);
  T res;
  is >> res;
  return res;
}
template <class T> string to_s(const T &a) {
  ostringstream os;
  os << a;
  return os.str();
}

void solve(long long N, vector<long long> A, vector<long long> B) {
  ll ret = 0;

  for (int i = N - 1; i >= 0; i--) {
    A[i] += ret;
    if (A[i] % B[i] == 0)
      continue;

    if (A[i] < B[i]) {
      ret += B[i] - A[i];
    } else {
      ret += B[i] * (A[i] / B[i] + 1) - A[i];
    }
  }

  cout << ret << endl;
}

int main() {
  ios::sync_with_stdio(false);
  long long N;
  cin >> N;
  vector<long long> A(N - 1 + 1);
  vector<long long> B(N - 1 + 1);
  for (int i = 0; i <= N - 1; i++) {
    cin >> A[i];
    cin >> B[i];
  }
  solve(N, A, B);
  return 0;
}


Measured memory_bytes: 3456
#include <iostream>

/// check if (x1, y1) <-> (x2, y2) and (x3, y3) <-> (x4, y4) is crossed.
bool is_cross(double x1, double y1, double x2, double y2,
              double x3, double y3, double x4, double y4)
{
  if (((x1 - x2) * (y3 - y1) + (y1 - y2) * (x1 - x3)) *
      ((x1 - x2) * (y4 - y1) + (y1 - y2) * (x1 - x4)) > 0) {
    return false;
  } else {
    return true;
  }
}

int main()
{
  double x1, y1, x2, y2, x3, y3, xp, yp, center_x, center_y;
  while (std::cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> xp >> yp) {
    center_x = (x1 + x2 + x3) / 3.0;
    center_y = (y1 + y2 + y3) / 3.0;
    if (is_cross(x1, y1, x2, y2, xp, yp, center_x, center_y) ||
        is_cross(x1, y1, x3, y3, xp, yp, center_x, center_y) ||
        is_cross(x2, y2, x3, y3, xp, yp, center_x, center_y)) {
      std::cout << "NO" << std::endl;
    } else {
      std::cout << "YES" << std::endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1224
// Aizu 1186: Integral Rectangles
// 2017.9.13 bal4u@uu

#include <stdio.h>
#include <stdlib.h>

#define MAX 11500
typedef struct { int h, w, d2; } T;
T tbl[MAX+5]; int size;

int cmp(T *a, T *b) { if (a->d2 - b->d2) return (a->d2 - b->d2); return a->h - b->h; }

int bsrch(int a)
{
	int left = 0, right = size - 1, mid;
    while (left < right) {
		mid = (left + right) >> 1;
        if (tbl[mid].d2 < a) left = mid + 1; else right = mid;
    }
    if (tbl[left].d2 < a) left++;
	return left;
}

int main()
{
	int w, h, n, d2;
	
	for (size = 0, h = 1; h <= 150; h++) for (w = h+1; w <= 150; w++)
		tbl[size].h = h, tbl[size].w = w, tbl[size].d2 = h*h+w*w, size++;
	qsort(tbl, size, sizeof(T), cmp);
	while (scanf("%d%d", &h, &w) && h) {
		d2 = h*h+w*w, n = bsrch(d2);
		while (tbl[n].d2 == d2 && tbl[n].h <= h) n++;
		printf("%d %d\n", tbl[n].h, tbl[n].w);
	}
	return 0;
}

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

int main(void) {
  int n;
  cin >> n;
  vector<int> xs(n);
  for (int &x : xs) cin >> x;

  vector<int> ys = xs;
  sort(ys.begin(), ys.end());
  int l = ys[(n - 1) / 2];
  int u = ys[(n + 1) / 2];
  
  for (const int &x : xs) {
    if (x > l) {
      cout << l << endl;
    } else {
      cout << u << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 4852
#include <iostream>
#include <algorithm>
#include <queue>
#include <cmath>
#define x first
#define h second
using namespace std;
typedef pair<long long, long long> PII;
typedef long long ll;
const int N = 2e5 + 10;
PII mons[N];
ll n, d, a;
int main(){
    cin >> n >> d >> a;
    for(int i = 0; i < n; i ++)
    {
        cin >> mons[i].x >> mons[i].h;
    }
    sort(mons, mons + n);
    queue<PII> temp;
    int damage = 0;
    ll cnt = 0;
    for(int i = 0; i < n; i ++)
    {
        while(!temp.empty() && mons[i].x > temp.front().x)
        {
            damage -= temp.front().h;
            temp.pop();
        }
        if(mons[i].h > damage)
        {
            mons[i].h -= damage;
            ll bomb = ceil(double(mons[i].h) / a);
            ll t_damage = bomb * a; 
            damage += t_damage;
            cnt += bomb;
            temp.push({mons[i].x + 2 * d, t_damage});
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x)(x).begin(), (x).end() // 昇順ソート
#define rall(v)(v).rbegin(), (v).rend() // 降順ソート
#define INF 1 LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair < ll, ll >
#define F first
#define S second
const int MOD = 1000000007;
template < class T > bool chmax(T & a,const T & b) { if (a < b) { a = b; return true; } return false; }
template < class T > bool chmin(T & a,const T & b) { if (a > b) { a = b; return true; } return false; }
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main() {
    string S;cin >> S;
    int N = S.size();
    vector<int> ans(N);
    int tmp = 1;
    char ch = 'R';
    rep(i,N){
        if(i == N-1){
            
            ans[i-tmp] += tmp/2;
            ans[i-tmp+1] += (tmp+2-1)/2;
            break;
        }
        if(S[i+1] == ch)tmp++;
        else{
            if(ch == 'R'){
                ans[i] += ((tmp+2-1)/2);
                ans[i+1] += tmp /2;
                ch = 'L';
            }
            else{
                ans[i-tmp] += tmp/2;
                ans[i-tmp+1] += (tmp+2-1)/2;
                ch = 'R';
            }
            tmp = 1;
        }
    }
    rep(i,N)cout << ans[i] <<" ";
    cout  << endl;
}

Measured memory_bytes: 1024
/**
 * There is a start and there is no end in the space. ---Infinilly.
 * It ruins and goes though there is also a start in stars. ---Finite.
 * Only the man who has wisdom can read the most foolish one from the history.
 * Fishes living in the sea doesn't know the life in the land.
 * It also ruins and goes if they have wisdom.
 * It funnier that man exceeds the speed of light than fish start living in the land.
 * It can be said that this is an final ultimatum from the god to the people who can fight.
 *
 * Steins;Gate
 */

#include <bits/stdc++.h>

typedef long long LL;
const int N = 200010, MO = 1e9 + 7;

int a[N], bin[N], f[N];

int main() {

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

    return 0;
}


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

int main(){
    int A, B;
    cin >> A >> B;
    if(A>B){
        swap(A, B);
    }
    long long ans = B;
    while(ans%A!=0){
        ans += B;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import Counter

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

cnt_dict = Counter(A)
keys_lst = list(cnt_dict.keys())
values_lst = list(cnt_dict.values())

ans = 0
for i in range(len(keys_lst)):
  if keys_lst[i] > values_lst[i]:
    ans += values_lst[i]
  elif keys_lst[i] < values_lst[i]:
    ans += values_lst[i] - keys_lst[i]
    
print(ans)

Measured memory_bytes: 18676
#include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
int main(void)
{
	int n,flg,i,a,b,c,x;
	scanf("%d",&n);
	for(i=n;i<=999;i++)	{
		x=i;
		a=x%10;
		x/=10;
		b=x%10;
		c=x/10;
		if(a==b && a==c)	break;
	}
	printf("%d\n",i);
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<iso646.h>
int N, a[200200], b=0;
int main(){
	scanf("%d", &N);
	for(int i=0; i<N; i++){
		scanf("%d", a+i);
		b xor_eq a[i];
	}
	for(int i=0; i<N; i++){
		printf("%d\n", b xor a[i]);
	}
	return 0;
}


Measured memory_bytes: 3200
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Sparsh Sanchorawala
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        APoor solver = new APoor();
        solver.solve(1, in, out);
        out.close();
    }

    static class APoor {
        public void solve(int testNumber, InputReader s, PrintWriter w) {
            int[] a = new int[3];
            for (int i = 0; i < 3; i++)
                a[i] = s.nextInt();
            for (int i = 0; i < 3; i++) {
                if (a[i] == a[(i + 1) % 3] && a[i] != a[(i + 2) % 3]) {
                    w.println("Yes");
                    return;
                }
            }
            w.println("No");
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 23252
// GRL_1_A
#include<cstdio>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<utility>
#define rep(i,a) for( int i = 0; i != (a); ++i )

typedef std::pair<int, int> P;
const int INF = 1 << 30;

std::vector<P> G[100000];
int d[100000];

int main()
{
	int v, e, r;
	scanf( "%d%d%d", &v, &e, &r );
	rep( i, e )
	{
		int s, t, d;
		scanf( "%d%d%d", &s, &t, &d );
		G[s].push_back( P( t, d ) );
	}

	std::priority_queue<P, std::vector<P>, std::greater<P> > pque;
	std::fill( d, d+v, INF );
	d[r] = 0;
	pque.push( P( 0, r ) );
	while( !pque.empty() )
	{
		P p = pque.top(); pque.pop();
		int dist = p.first, v = p.second;

		if( d[v] < dist )
			continue;

		rep( i, G[v].size() )
		{
			P &e = G[v][i];

			if( d[e.first] > d[v]+e.second )
			{
				d[e.first] = d[v]+e.second;
				pque.push( P( d[e.first], e.first ) );
			}
		}
	}

	rep( i, v )
	{
		if( d[i] == INF )
			puts("INF");
		else
			printf( "%d\n", d[i] );
	}

	return 0;
}

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

int main(){
    int n, m; cin >> n >> m;
    int diff = 0;
    if(n%2){
        loop(i, 1, m+1){
            cout << i << ' ' << n + 1 - i << endl;
        }
    } else {
        loop(i, 1, m+1){
            int j = n - i;
            if(!diff && (j - i) <= n/2) diff++;
            cout << i << ' ' << j - diff << endl;
        }
    }

    return 0;
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

const int64 mod = 1e9+7;
using PIC = pair<int32, char>;

vector<vector<PII>> G;
int main(void){
	int32 K;
	cin >> K;
	G.resize(K);
	REP(i, K){
		G[i].push_back({0, i*10%K});
		G[i].push_back({1, (i+1)%K});
	}
	vector<int32> d(K, INF);
	d[1] = 1;
	priority_queue<PII, vector<PII>, greater<PII>> pq;
	pq.push({0, 1});
	while(pq.size()){
		int32 dd, vv;
		tie(dd, vv) = pq.top(); pq.pop();
		if(dd > d[vv]) continue;
		REP(i, G[vv].size()){
			if(d[G[vv][i].sc] > d[vv]+G[vv][i].fs){
				d[G[vv][i].sc] = d[vv]+G[vv][i].fs;
				pq.push({d[G[vv][i].sc], G[vv][i].sc});
			}
		}
	}
	cout << d[0] << endl;
}

Measured memory_bytes: 9208
#include <iostream>
#include <numeric>
#include <vector>
#include <algorithm>
#include <string>
#include "math.h"

using namespace std;
int main(int argc, char const *argv[]) {
  int N;
  cin >> N;
  int a[10000000];
  for (int i = 1; i <= N; i++) {
    cin >> a[i];
  }
  int b;
  int count = 0;
  for (int i = 1; i <= N; i++) {
    b = a[i];
    if (a[b] == i) {
      count++;
    }
  }
  cout << count / 2 << endl;
  return 0;
}

Measured memory_bytes: 888
N, K = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = -float('inf')
v = []
for n in range(N):
    loop, score = 0, 0
    t = n
    for i in range(min(N,K)):
        n = P[n] - 1
        score += C[n]
        ans = max(ans,score)
        if n == t:
            loop = i + 1
            break
    v.append((loop,score))
    
    
for n in range(N):
    loop,score = v[n]
    if loop > 0 and score > 0:
        r = (K-1)//loop
        nscore = r*score
        for i in range(K - r*loop):
            n = P[n] - 1
            nscore += C[n]
            ans = max(nscore, ans)
            
print(ans)

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

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
// cout << fixed << setprecision(20);

// 最大公約数
int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

int N;
int A[110000];
signed main() {
    cin >> N;
    for (int i = 0; i < N; i++)cin >> A[i];
    if (N == 1) {
        if (A[0] % 2 == 0)cout << "First" << endl;
        else cout << "Second" << endl;
        return 0;
    }
    if (N % 2 == 0) {
        int sum = 0;
        for (int i = 0; i < N; i++)sum += A[i];
        if (sum % 2 == 0)cout << "Second" << endl;
        else cout << "First" << endl;
        return 0;
    }

    string winner = "First";
    while (true) {
        int sum = 0;
        for (int i = 0; i < N; i++)sum += A[i];
        if (sum % 2 == 0) {cout << winner << endl; return 0;}

        winner = winner == "First" ? "Second" : "First";

        for (int i = 0; i < N; i++) {
            if (A[i] == 1) {cout << winner << endl; return 0;}
        }

        int odd = 0;
        for (int i = 0; i < N; i++)odd += A[i] % 2;
        if (odd != 1) {cout << winner << endl; return 0;}
        int g = A[0] % 2 == 0 ? A[0] : A[0] - 1;
        for (int i = 0; i < N; i++) {
            if (A[i] % 2 == 1)A[i]--;
            g = gcd(g, A[i]);
        }
        for (int i = 0; i < N; i++)A[i] /= g;

    }
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,a,b) for(ll i=a;i <= b;i++)
#define fast_io ios_base::sync_with_stdio(false)
#define pb push_back
#define fir first
#define sec second
#define tr(it,x) for(it = x.begin();it != x.end();it++)
#define mp make_pair
#define sz(x) (ll)x.size()
#define rep(i,n) for(ll i=0;i<n;i++)
#define double long double
#define accuracy ll precision = numeric_limits<double>::digits10
#define pll pair<ll,ll>

ll n,ans = LLONG_MAX;

ll sum(ll x) {
	ll ret = 0;
	while(x != 0) {
		ret += (x % 10);
		x /= 10;
	}
	return ret;
}

int main() {
	// freopen("input.txt", "r", stdin); 
	// freopen("output.txt", "w", stdout);
	fast_io;	 
	accuracy;
	cin >> n;
	fr(i,1,n-1) {
		ll j = n-i;
		ans = min(ans,sum(i) + sum(j));
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
def main():
    from bisect import bisect_left as bl
    n = int(input())
    a = [int(input()) for _ in [0]*n]
    b = [int(input()) for _ in [0]*n]
    a.sort()
    b.sort()
    for i in range(n):
        if a[i] > b[i]:
            a[i], b[i] = b[i], a[i]
    # print(a)
    # print(b)
    mod = 10**9+7
    ans = 1
    for i in range(n):
        ans = ans*(i+1-bl(b, a[i])) % mod
    print(ans)


main()

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

typedef int64_t Int;
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
 
const double EPS = 1e-10;
const Int INF = 1e18;
const int inf = 1e9;
const Int mod = 1e9+7;

bool print_space_enable = false;
void print() { 
    cout << endl; 
    print_space_enable = false;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    if (print_space_enable) cout << " ";
    cout << fixed << setprecision(15) << head;
    print_space_enable = true;
    print(std::forward<Tail>(tail)...);
}

template<typename T>
void print(vector<T> v) {
    for (size_t i = 0; i < v.size(); i++) {
        if (i > 0) std::cout << " ";
        std::cout << v[i];
    }
    std::cout << std::endl;
}

int main() {
    string s;
    cin >> s;
    for (Int bit = 0; bit < (Int)(1<<3); bit++) {
        Int cnt = s[0] - '0';
        for (Int i = 0; i < (Int)3; i++) {
            if (bit & (1<<i)) {
                cnt += s[i + 1] - '0';
            } else {
                cnt -= s[i + 1] - '0';
            }
        }
        if (cnt == 7) {
            cout << s[0];
            for (Int i = 0; i < (Int)3; i++) {
                if (bit & (1<<i)) {
                    cout << "+";
                } else {
                    cout << "-";
                }
                cout << s[i + 1];
            }
            cout << "=7" << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
s = gets.chomp.split(//)

$fumi = "Yes"
catch(:break_loop) do
    s.each_with_index do |step,index|
        if (index+1).odd?
            ($fumi = "No" ; throw :break_loop) if step == "L" 
        elsif (index+1).even?
            ($fumi = "No" ; throw :break_loop) if step == "R"
        end
    end
end

puts $fumi

Measured memory_bytes: 1788
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  ll n, k;
  cin >> n >> k;
  ll m = n % k;
  cout << min(m, abs(m - k)) << endl;
  return 0;
}

Measured memory_bytes: 3616
n=int(input())
 
a=2
b=1
s=0
 
if n==1:
  s=1
  n=2
 
for i in range(n-1):
  nn = a+b
  ans=nn
  a=b
  b=nn
 
if s==1:
  ans = 1
 
print(ans)

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

int main(void)
{
	int h, w;
	int i, j;
	
	while (1){
		cin >> h >> w;
		
		if (h == 0 && w == 0){
			break;
		}
		
		for (i = 0; i < h; i++){
			for (j = 0; j < w; j++){
				cout << "#";
			}
			cout << endl;
		}
		
		cout << "\n";
	}
	
	return (0);
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b;
  cin >> a >> b;
  int big = a;
  int sml = b;
  if (big < sml) {
    big = b;
    sml = a;
  }
  for (int i = 0; i < big; i++) {
    cout << sml;
  }
  cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
const int MOD=1e9+7;
#ifndef HOME
#define cerr if(0)cerr
#endif

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,q;
    cin>>n>>q;
    string s;
    cin>>s;
    int pre[n+5]={0};
    for(int i=1;i<n;i++){
        if(s[i-1]=='A'&&s[i]=='C'){
            pre[i]=1;
        }
    }
    for(int i=1;i<n+2;i++){
        pre[i]+=pre[i-1];
    }
    while(q--){
        int l,r;
        cin>>l>>r;
        l--;
        r--;
        cout<<pre[r]-pre[l]<<endl;
    }
    
    return 0;
    
}



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

int main() {
    int N, A, B;
    cin >> N >> A >> B;
    string S;
    cin >> S;
    int sm=0, b=0;
    for(auto &p: S) {
        if(sm >= A + B || p == 'c') { cout << "No" << endl; continue; }
        if(p == 'a') {
            cout << "Yes" << endl;
            ++sm;
        } else {
            if(b < B) {
                cout << "Yes" << endl; ++sm, ++b;
            }
            else cout << "No" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 2e5 + 5;

int n;
int a[N];

int32_t main()
{
	IOS;
	char ch;
	cin>>ch;
	if(isupper(ch))
	cout<<"A";
	else
	cout<<"a";
	
	return 0;
}

Measured memory_bytes: 3636
import sys
readline = sys.stdin.readline

# 0-indexでやる

D = int(readline())

C = list(map(int,readline().split())) # 満足度の下がりやすさ

last_submit = [-26] * 26

for i in range(D):
  S = list(map(int,readline().split()))
  
  # 52回以上提出がないものを見つけたら、それを強制提出
  fin = False
  for j in range(len(last_submit)):
    if i - last_submit[j] >= 52:
      print(j + 1)
      last_submit[j] = i
      fin = True
      break
  if fin:
    continue
  for j in range(len(S)):
    S[j] = (S[j],j)
  S = sorted(S, key = lambda x:x[0], reverse = True)
  topval = S[0][0]
  for j in range(len(S)):
    val = S[j][0]
    if val < topval // 2:
      continue # 最高値の半分になるのであればやめよう
    index = S[j][1]
    if i - last_submit[index] < 26:
      continue
    print(index + 1)
    last_submit[index] = i
    break
  else:
    print(S[0][1] + 1)


Measured memory_bytes: 9260
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;

void main()
{
	while (1) {
		auto n = readln.chomp.to!int;
		if (!n) break;
		auto data = new Tuple!(double, string)[](n);
		foreach (i; 0..n) {
			auto x = readln.chomp.split.array;
			data[i][1] = x[0];
			auto p = x[1..$].map!(to!double);
			data[i][0] = ((p[6]*p[7]*p[8]) - p[0]) / (p[1]+p[2]+p[3]+(p[4]+p[5])*p[8]);
		}
		data = data.sort!((a,b) => a[0]==b[0] ? a[1] < b[1] : a[0] > b[0]).array;
		foreach (e; data) {
			e[1].writeln;
		}
		writeln("#");
	}
}

Measured memory_bytes: 2040
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const [N, K] = input[0].map(BigInt);

  return (K * (K - 1n) ** (N - 1n)).toString();
};

console.log(main(read()));


Measured memory_bytes: 29636
#include <stdio.h>
#include <math.h>


int main(void){
  int a[10005],count=0,i,j,f,n;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  for(i=0;i<n;i++){
    f=1;
    for(j=2;j<=sqrt(a[i]);j++){
      if(a[i]%j==0){
	f=0;
      }
    }
    if(a[i]==1)continue;
    if(f==1){
      count++;
    }
  }
  printf("%d\n",count);
  
  return 0;
}

Measured memory_bytes: 632
#include<bits/stdc++.h>
using namespace std;
int a,b;
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>a>>b;
	if(a>=1&&a<=9&&b>=1&&b<=9)
		cout<<a*b<<endl;
	else
		cout<<-1<<endl;
	return 0;
}


Measured memory_bytes: 256
while True:
    N = int(input())
    if N==0:
        exit()

    MAX_T = 24*3600+10
    S = [0]*MAX_T
    for _ in range(N):
        start, end = input().split()
        a, b,c = map(int, start.split(":"))
        d,e,f  = map(int, end.split(":"))
        # imos
        S[a*3600+b*60+c] += 1
        S[d*3600+e*60+f] -= 1

        # cumsum
    for i in range(MAX_T-1):
        S[i+1] += S[i]
    print(max(S))



Measured memory_bytes: 9592
N = int(input())
scg = ["3", "5", "7"]
s = []
res = []
s += scg
while len(s) > 0:
  p = s.pop()
  for i in range(3):
    q = p + scg[i]
    if int(q) <= N:
      s.append(q)
      tfs = [0, 0, 0]
      for i in range(len(q)):
        if q[i] == "3":
          tfs[0] = 1
        elif q[i] == "5":
          tfs[1] = 1
        elif q[i] == "7":
          tfs[2] = 1
      if min(tfs) != 0:
        res.append(q)
print(len(res))

Measured memory_bytes: 4928
#include <bits/stdc++.h>
using namespace std;
using P = pair<int64_t, int64_t>;
int main() {
    #ifdef DEBUG
    std::ifstream in("/home/share/inputf.in");
    std::cin.rdbuf(in.rdbuf());
    #endif
    int N, M;
    cin >> N >> M;
    vector<int64_t> A(N);
    vector<P> m(M);
    for(int i = 0; i < N; i++) {
        cin >> A[i];
        
    }
    sort(A.begin(), A.end());
    for(int i = 0; i < M; i++) {
        int64_t b, c;
        cin >> b >> c;
        m[i] = {c, b};
    }
    sort(m.rbegin(), m.rend());
    int B = 0, j = 0;
    for(int i = 0; i < N; i++) {
        if(m[j].first <= A[i]) break;
        A[i] = m[j].first;
        B++;
        if (B >= m[j].second) {
            B = 0;
            j++;
        }
    }
    int64_t ans = 0;
    for(int i = 0; i < N; i++) {
        ans += A[i];
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main()
{
    int a[100],n,i,j,temp,cou;
    scanf("%d",&n);

    for(i=0;i<n;++i)
        scanf("%d",&a[i]);
  cou=0;
    for(i=1;i<n;++i)
    {
        for(j=0;j<(n-i);++j)
            if(a[j]>a[j+1])
            {
                temp=a[j];
                a[j]=a[j+1];
                a[j+1]=temp;
                cou++;
            }
    }

    for(i=0;i<n;++i){
        printf("%d",a[i]);
        if (i<(n-1))
            printf(" ");
    }
    printf("\n");
    printf("%d\n",cou);

    return 0;
}

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


int main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int N;
	cin >> N;
	vector<int> h(N + 1);
	for (int i = 0; i < N; ++i) cin >> h[i + 1];

	vector<int> dp(N + 5, (int)1e9 + 5);
	dp[1] = 0;
	for (int i = 2; i <= N; ++i) {
		dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
	}
	cout << dp[N] << endl;

}



Measured memory_bytes: 1024
//while (clock()<=69*CLOCKS_PER_SEC)
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

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

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define shandom_ruffle random_shuffle

const int nax=100*1007;

int n;

char wcz[nax];

int wyn;

int main()
{
	scanf("%s", wcz+1);
	n=strlen(wcz+1);
	vector <int> wek, odw;
	for (int i=1; i<=n; i++)
		if (wcz[i]!='x')
			wek.push_back(wcz[i]);
	odw=wek;
	reverse(odw.begin(), odw.end());
	if (wek!=odw)
	{
		printf("-1\n");
		return 0;
	}
	wek.clear();
	wek.push_back(0);
	for (int i=1; i<=n; i++)
	{
		if (wcz[i]=='x')
			wek.back()++;
		else
			wek.push_back(0);
	}
	for (int i=0; i<=(int)wek.size()-1-i; i++)
		wyn+=abs(wek[i]-wek[(int)wek.size()-1-i]);
	printf("%d\n", wyn);
	return 0;
}


Measured memory_bytes: 1272
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <cmath>
#include <climits>
#include <bitset>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;

int main(int argc, char const* argv[])
{
  string s;
  cin >> s;
  int res = s.size();
  for(int i = 0; i + 1 < s.size(); i++){
    if(s[i] != s[i + 1])res = min(res, max(i + 1, (int)s.size() - i - 1));
  }
  cout << res << endl;
	return 0;
}


Measured memory_bytes: 512
A = list(map(int,input().split()))
A += list(map(int,input().split()))
A += list(map(int,input().split()))
ans = "No"

N = int(input())
b = []
for i in range(N):
    b.append(int(input()))

for i in range(3):
    if A[3*i] in b and A[3*i+1] in b and A[3*i+2] in b:
        ans = "Yes"
    elif A[i] in b and A[i+3] in b and A[i+6] in b:
        ans = "Yes"
if A[0] in b and A[4] in b and A[8] in b:
        ans = "Yes"
elif A[2] in b and A[4] in b and A[6] in b:
    ans = "Yes"
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<"!"<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,k;cin>>n>>k;
  map<ll,ll>MP;
  for(int i=0;i<n;i++){ll a;cin>>a;MP[a]++;}
  vi num;
  for(auto a:MP){
    num.pb(a.S);
  }
  ll ans=0;
  sort(ALL(num));
  for(int i=0;i<max(0LL,(ll)num.size()-k);i++)
    ans+=num[i];
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 14964
// 2020-09-15 00:49:11
// clang-format off
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

// clang-format on
const ll inf = 1e18;
void answer() {
  int n;
  cin >> n;
  ll maxz = -inf, minz = inf;
  ll maxw = -inf, minw = inf;
  rep(i, n) {
    ll x, y;
    cin >> x >> y;
    chmax(maxz, x + y);
    chmin(minz, x + y);
    chmax(maxw, x - y);
    chmin(minw, x - y);
  }
  ll ans = 0;
  chmax(ans, maxz - minz);
  chmax(ans, maxw - minw);
  cout << ans << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 3644
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>

#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;

const ll MOD = 1000000007;
const long double EPS = 1e-10;
const int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

string keyence = "keyence";

int main() {
    int n;
    cin >> n;
    ll takahashi[n], border[n];
    for(int i=0;i<n;++i) cin >> takahashi[i];
    for(int i=0;i<n;++i) cin >> border[i];

    vector<ll> surplus;
    ll shortage_all = 0, shortage_cnt = 0;
    for(int i=0;i<n;++i) {
        if(takahashi[i] > border[i]) {
            surplus.push_back(takahashi[i]-border[i]);
        } else if(takahashi[i] < border[i]) {
            shortage_all += border[i]-takahashi[i];
            ++shortage_cnt;
        }
    }
    sort(rall(surplus));

    ll acc = 0, cnt = 0;
    for(int i=0;i<surplus.size()&&acc<shortage_all;++i) {
        acc += surplus[i];
        ++cnt;
    }

    if(acc < shortage_all) {
        cout << -1 << endl;
    } else {
        cout << shortage_cnt+cnt << endl;
    }

    return 0;    
}

    

Measured memory_bytes: 2428
#include <bits/stdc++.h>
using namespace std;
#define ll unsigned long long int
#define mod 1000000007
bool isPrime[1000001];
ll power(ll a,ll b)
{
    ll result = 1;
    while(b>0)
    {
        if(b%2)
        {
            result = (a*result)%mod;
        }
        a = (a*a)%mod;
        b = b/2;
    }
    return result;
}
int gcd(int a,int b)
{
    if(b==0)
    {
        return a;
    }
    return gcd(b,a%b);
}
void sieve()
{
    memset(isPrime,1,sizeof(isPrime));
    isPrime[0] = isPrime[1] = 0;
    for(int i=2;i*i<=1000000;i++)
    {
        if(isPrime[i])
        {
            for(int j=i*i;j<=1000000;j+=i)
            {
                isPrime[j] = 0;
            }
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL),cout.tie(NULL);
    int t,n;
    t = 1;
    for(int i=0;i<t;i++)
    {
        int a,b,c;
        cin>>a>>b>>c;
        bool ans = 0;
        for(int i=b;i<=c;i++)
        {
            if(i%a==0)
            {
                ans = 1;
                break;
            }
        }
        if(ans)
        {
            cout<<"OK";
        }
        else
        {
            cout<<"NG";
        }
        
    }
    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
  int n,k; cin>>n>>k;
  vector<ll> a(n);
  for(int i = 0; i < n; i++)
    cin>>a[i];
  vector<ll> dp(n,1e9+7);
  dp[0] = 0;
  if(n>1)
  	dp[1] = abs(a[1]-a[0]);
  for(int i = 2; i < n; i++)
    for(int j = i-1; j>=max(0,i-k); j--)
      dp[i] = min(dp[i],dp[j] + abs(a[j]-a[i]));
  cout<<dp[n-1]<<endl;
  return 0;
}

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

int main() {
  ll A,B,C,D,count=0;

  cin >> A >> B >> C >> D;

  while(A > 0 && C > 0){
    if(count==0){
      C -= B;
      count=1;
    }else{
      A -= D;
      count=0;
    }
  }

  if(A<=0){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }

}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i,n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<"\n"
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define mp make_pair
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef tuple<ll,ll,ll> tll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using vc = vector<char>;
using vvc = vector<vc>;
template<class T> inline bool chmax(T& a, T b) { 
 if (a < b) { a = b; return true; } return false; 
}
template<class T> inline bool chmin(T& a, T b) {
 if (a > b) { a = b; return true; } return false; 
}
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
// Union Find
 
template<typename T>
struct UnionFind
{
	vector<T> par;
	vector<T> rank;
	vector<T> sizes;
	UnionFind(T n):par(n),rank(n,0),sizes(n,1){
	   for(T i=0;i<n;i++){
	     par[i]=i;
	   }
	}
	T root(T x){
	  return par[x]==x?x:par[x]=root(par[x]);
	}
 
	bool unite(T x,T y){
	  if(x==y) return false;
	  x=root(x); y=root(y);
	  if(x==y) return false;
	  if(rank[x]<rank[y]) swap(x,y);
	  if(rank[x]==rank[y]) rank[x]++;
	  par[y]=x;
	  sizes[x]=sizes[x]+sizes[y];
	  return true;
	}
	bool same(T x,T y){
	  return root(x)==root(y);
	}
	T size(T x){
	  return sizes[root(x)];
	}
};
int main(){
  ll n,m;
  cin>>n>>m;
  UnionFind<ll> uf(n);
  rep(i,m){
    ll a,b;
    cin>>a>>b;
    a--;b--;
    uf.unite(a,b);
  }
  set<ll> s;
  rep(i,n){
    ll d=uf.root(i);
    s.insert(d);
  }
  COUT(sz(s)-1);
}

Measured memory_bytes: 9104
import java.util.*;

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 < N; i++){
      a[i] += sc.nextInt();
    }
    int ans = 0;
    ending:while (true){
      for (int i = 0; i < N; i++){
        if (a[i]%2 == 1) break ending;
        a[i] /= 2;
      }
      ans++;
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 36060
#include <stdio.h>
#include <stdlib.h>
long long cmp( const void *p, const void *q ) {
  return *(long long*)p - *(long long*)q;
}

int main(void){
  long long n,m,a[100005][2],ans=0,i;
  scanf("%lld%lld",&n,&m);
  for(int i=0;i<n;i++){
    scanf("%lld%lld",&a[i][0],&a[i][1]);
  }
  qsort(a,n, sizeof(a[0]),cmp);
  i=0;
  while(1){
    if(m>a[i][1]){
      m-=a[i][1];
      ans+=a[i][0]*a[i][1];
    }else{
      ans+=m*a[i][0];
      break;                                                                                                                }
    i++;
  }
  printf("%lld",ans);

  return 0;
}

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

int main()
{
  int64_t N;
  cin >> N;
  vector<int> A;
  while (N > 0)
  {
    N--;
    A.push_back(N % 26);
    N /= 26;
  }
  reverse(A.begin(), A.end());
  for (auto a : A)
    cout << (char)(a + 'a');
  cout << endl;
}

Measured memory_bytes: 3644
def binarysearch(lis,i,j,n):
    if lis[-1]<n:
        return len(lis)
    elif j-i == 1:
        return j
    else:
        m = (i+j)//2
        if lis[m] < n:
            return binarysearch(lis,m,j,n)
        elif lis[m]>n:
            return binarysearch(lis,i,m,n)
        elif lis[m] == n:
            return m


n = int(input())
lis = [-1]
for _ in range(n):
    x = int(input())
    y = len(lis)-1
    j = binarysearch(lis,0,y,x)
    if j == len(lis):
        lis.append(x)
    else:
        if lis[j] > x:
            lis[j] = x
print(len(lis)-1)


Measured memory_bytes: 9656
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n); for(int i = 0;i < (int)(n);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
int main(){
    int n,m;
    cin >> n >> m;
    int h[n];
    rep(i,n)cin >> h[i];
    int a[m],b[m];
    rep(i,m)cin >> a[i] >> b[i];
    int ans = 0;
    vector<bool>data(n);
    rep(i,n)data[i] = true;
    rep(i,m){
        if(h[a[i]-1]>h[b[i]-1]){
            data[b[i]-1]=false;
            //cout  << "f" << b[i] << endl;
        }
        if(h[a[i]-1]<h[b[i]-1]){
            data[a[i]-1]=false;
            //cout << "f" << a[i] << endl;
        }
        if(h[a[i]-1] == h[b[i]-1]){
            data[a[i]-1]=false;
            data[b[i]-1]=false;
        }
        //cout  << "m" << endl;
        
    }
    rep(i,n)if(data[i]){
        ans++;
        //cout << i << endl;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4808
#coding=UTF-8
myon_chache={}
def turn_check(zikan,direct,around):
    nokori_naka=zikan
    for idx in range(0,N,1):
        rem_hp=kirei_HP[idx]-around*zikan
        if rem_hp > 0:
            if rem_hp in myon_chache:
                myon=myon_chache[rem_hp]
            else:
                myon= rem_hp//(direct-around) + (0 if rem_hp%(direct-around)==0 else 1)
                myon_chache[rem_hp]=myon
        
            nokori_naka=nokori_naka-myon
            if nokori_naka < 0:
                return False
        else: #以降も周辺攻撃のみで倒せる
            return True

    return True


mozir=input()
hyo=mozir.split(' ')
N=int(hyo[0])
A=int(hyo[1])
B=int(hyo[2])

HP=[]
for idx in range(0,N,1):
    HP.append(int(input()))

kirei_HP=sorted(HP,reverse=True)
dmg_mean= B
kagen=kirei_HP[0]// dmg_mean + 1
tansaku=kagen//2
ite=0
dame_jogen=0
while True:
    ite=ite+1
    if turn_check(tansaku,A,B):
        kagen=tansaku
        tansaku=(kagen+dame_jogen)//2
    else:
        if tansaku + 1 == kagen: #丁度境目を見付けたら
            break
        else:
            dame_jogen=tansaku
            tansaku=(tansaku+kagen)//2

#print(ite)
print(kagen)


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

#define INIT_CAP 10
#define INF 1000000000

#define min(a, b) (((a) < (b)) ? (a) : (b))

const int di[2][9] = {{-2, -1, -1, 0, 0, 0, 1, 1, 2}, {-2, -1, -1, 0, 0, 0, 1, 1, 2}};
const int dj[2][9] = {{1, 1, 2, 1, 2, 3, 1, 2, 1}, {-1, -2, -1, -3, -2, -1, -2, -1, -1}};

typedef struct {
	int to, w;
} Edge;

typedef struct {
	Edge *elem;
	int cap, size;
} VecEdge;

typedef struct {
	int num;
	int d;
} PairNumDis;

typedef struct {
	int d;
	int idx;
} Node;

VecEdge adj[3600];
PairNumDis heap[3600];
int hsize;
Node node[3600];

void init(int n) {
	while (n--)
		adj[n] = (VecEdge){malloc(sizeof(Edge) * INIT_CAP), INIT_CAP, 0};
}

inline void add(int from, int to, int w) {
	if (adj[from].size == adj[from].cap) {
		adj[from].cap <<= 1;
		adj[from].elem = realloc(adj[from].elem, sizeof(Edge) * adj[from].cap);
	}
	adj[from].elem[adj[from].size++] = (Edge){to, w};
}

void freeAll(int n) {
	while (n--)
		free(adj[n].elem);
}

inline int calcNextIdx(int i) {
	return i * 2 + 1 + (i * 2 + 2 < hsize && heap[i * 2 + 1].d > heap[i * 2 + 2].d);
}

inline PairNumDis delete(void) {
	int i;
	int nextIdx;
	const PairNumDis root = heap[0], last = heap[--hsize];

	for (i = 0; i * 2 + 1 < hsize && last.d > heap[nextIdx = calcNextIdx(i)].d; i = nextIdx) {
		heap[i] = heap[nextIdx];
		node[heap[i].num].idx = i;
	}
	heap[i] = last;
	node[last.num].idx = i;

	return root;
}

inline void decreaseKey(int num, int d) {
	int i;

	for (i = node[num].idx; i > 0 && d < heap[i - 1 >> 1].d; i = i - 1 >> 1) {
		heap[i] = heap[i - 1 >> 1];
		node[heap[i].num].idx = i;
	}
	heap[i] = (PairNumDis){num, d};
	node[num].idx = i;
}

void dijkstra(int n, int s) {
	int i;

	for (i = 0; i < n; i++) {
		heap[i] = (PairNumDis){i, INF};
		node[i] = (Node){INF, i};
	}
	hsize = n;

	node[s].d = 0;
	decreaseKey(s, 0);
	while (hsize > 0) {
		PairNumDis fromPair = delete();
		for (i = 0; i < adj[fromPair.num].size; i++) {
			Edge e = adj[fromPair.num].elem[i];
			if (fromPair.d + e.w < node[e.to].d) {
				node[e.to].d = fromPair.d + e.w;
				decreaseKey(e.to, node[e.to].d);
			}
		}
	}
}

char field[60][30];

int main(void) {
	int i, j, k, l;
	int w, h;
	int min;

	while (scanf("%d %d", &w, &h), w) {
		for (i = 0; i < h; i++)
			for (j = 0; j < w; j++)
				scanf(" %c", field[i] + j);

		init(h * w * 2);
		for (i = 0; i < h; i++)
			for (j = 0; j < w; j++)
				for (k = 0; k < 2; k++)
					for (l = 0; l < 9; l++) {
						const int ni = i + di[k][l], nj = j + dj[k][l];
						if (ni >= 0 && ni < h && nj >= 0 && nj < w && field[ni][nj] != 'X')
							add(i * w + j + k * h * w, ni * w + nj + (k ^ 1) * h * w, field[ni][nj] <= '9' ? field[ni][nj] - '0' : 0);
					}

		min = INF;
		for (i = 0; i < w; i++)
			if (field[h - 1][i] == 'S')
				for (j = 0; j < 2; j++) {
					dijkstra(h * w * 2, (h - 1) * w + i + j * h * w);
					for (k = 0; k < w; k++)
						if (field[0][k] == 'T') {
							min = min(min, node[k].d);
							min = min(min, node[k + h * w].d);
						}
				}

		printf("%d\n", min == INF ? -1 : min);

		freeAll(h * w * 2);
	}

	return 0;
}

Measured memory_bytes: 1052