akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll w, h, n;
    cin >> w >> h >> n;

    ll hidari = 0;
    ll migi = w;
    ll shita = 0;
    ll ue = h;
    rep(i, n) {
        ll x, y, a;
        cin >> x >> y >> a;
        if(a == 1) {
            chmax(hidari, x);
        }
        else if(a == 2) {
            chmin(migi, x);
        }
        else if(a == 3) {
            chmax(shita, y);
        }
        else if(a == 4) {
            chmin(ue, y);
        }
    }

    if(hidari >= migi || shita >= ue) {
        out(0);
    }
    else {
        out((migi - hidari)*(ue - shita));
    }
    
    re0;
}

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

using namespace std;

int main()
{
    int n, m, c;
    scanf("%d %d %d", &n, &m, &c);
    vector<int> b(m);
    for (int i = 0; i < m; i++)
    {
        scanf("%d", &b[i]);
    }

    int cnt = 0;
    for (int i = 0; i < n; i++)
    {
        int k = c;
        for (int j = 0; j < m; j++)
        {
            int a;
            scanf("%d", &a);
            k += a * b[j];
        }
        if (k > 0)
            cnt++;
    }

    printf("%d\n", cnt);

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
#include <cstring>

using namespace std;

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

int main(){
	long long int n, power = 1; cin >> n;

	for(int i=1; i<=n; ++i){
		power *= i;
		power %= ((int)pow(10, 9) + 7);
		//cout << "[" << i << "] : " << power << endl;
	}
   
	cout << power << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  
  int	a[3];	
  
  for(int i = 0;i < 3;i++){
  	cin >> a[i];
  }
  
  cout << a[2] << " " << a[0]  << " " << a[1];
}

Measured memory_bytes: 256
import numpy as np

A, B, H, M = map(int, input().split())

h_degree = 0.5*(H*60+M)
m_degree = 6*M

diff_degree = abs(m_degree-h_degree)
if diff_degree > 180:
  diff_degree = 360 - diff_degree
  
if diff_degree == 180:
    print(A+B)
elif diff_degree == 0:
    print(abs(A-B))
else:
    tmp = np.cos(np.deg2rad(diff_degree))
    print(np.sqrt(A**2+B**2-2*A*B*tmp))


Measured memory_bytes: 27180
#include <inttypes.h>
#include <math.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
    intmax_t N, X, T;
    intmax_t ans = 0;

    scanf("%jd%jd%jd", &N, &X, &T);

    ans = (N + (X - 1)) / X * T;

    printf("%jd\n", ans);

    return 0;
}


Measured memory_bytes: 2140
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#define N 1234
#define int long long
template<typename T> inline void read(T &x) {
	x = 0; char c = getchar(); bool flag = false;
	while (!isdigit(c)) { if (c == '-') flag = true; c = getchar(); }
	while (isdigit(c)) { x = (x << 1) + (x << 3) + (c ^ 48); c = getchar(); }
	if (flag)	x = -x;
}
using namespace std;
inline int F(int x) {
	return x < 0 ? -x : x;
}
int n;
int X[N], Y[N];
int d[43], dtot;
inline void work(int x, int y) {
	int nx = 0, ny = 0;
	for (int i = 1; i <= dtot; ++i) {
		int t = d[i];
		if (F(x - nx) > F(y - ny)) {
			if (x < nx)	putchar('L'), nx -= t;
			else	putchar('R'), nx += t;
		} else {
			if (y < ny)	putchar('D'), ny -= t;
			else putchar('U'), ny += t;
		}
	}
	putchar('\n');
}
signed main() {
	read(n);
	int type = -1;
	for (int i = 1; i <= n; ++i) {
		read(X[i]), read(Y[i]);
		int t = (X[i] + Y[i]) % 2;
		if (t < 0)	t += 2;
		if (type == -1)	type = t;
		else if (type != t) { puts("-1"); exit(0); }
	}
	if (type)	puts("31");
	else	puts("32");
	for (int i = 30; ~i; --i)	printf("%d ", 1 << i);
	if (type == 0)	puts("1");
	else	puts("");
	int nw = 30;
	if (type == 0) {
		for (int i = 0; i <= 30; ++i)	d[++dtot] = 1 << nw, --nw;
		d[++dtot] = 1;
	} else {
		for (int i = 0; i <= 30; ++i)	d[++dtot] = 1 << nw, --nw;
	}
	for (int i = 1; i <= n; ++i)	work(X[i], Y[i]);
	return 0;
}


Measured memory_bytes: 3196
#include <stdio.h>
int main(void){
    int n,A[100],flag=1,i,j,temp,c=0,bar=0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&A[i]);
    }
    while(flag){
        for(j=n-1;j>0;j--){
            if(A[j]<A[j-1]){
                temp=A[j];
                A[j]=A[j-1];
                A[j-1]=temp;
                c++;
            }
        }
            bar++;
            if(bar==n+1){
                break;
            }
    }
    for(i=0;i<n-1;i++){
    printf("%d ",A[i]);
    }
    printf("%d\n%d\n",A[i],c);
    return 0;
}


Measured memory_bytes: 2144
from collections import deque

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

graph = [[] for i in range(N)]
to_this = [0] * N
for i in range(M):
  x, y = map(int, input().split())
  graph[x-1].append(y-1)
  to_this[y-1] += 1


depth = [0] * N
d = deque([i for i in range(N) if not to_this[i]])
while d:
  l = len(d)
  for i in range(l):
    node = d.popleft()
    children = graph[node]
    for child in children:
      to_this[child] -= 1
      if not to_this[child]:
        d.append(child)
        depth[child] = depth[node] + 1

print(max(depth))  

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

int main(){
    using namespace std;
    string s;
    cin >> s;
    size_t ans{0}, cur{0};
    for(const auto c : s)if(!cur)cur = c == 'A';
    else ans = max(ans, ++cur * (c == 'Z'));
    cout << ans << endl;
}

Measured memory_bytes: 640
////////////////////////////////////////////////////////////////////
// This source code is for Visual Studio
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <stack>
#include <functional>
#include <iomanip>
#include <string>
#include <cstring>
#include <deque>
#include <math.h>
#include <assert.h>

#define	numberof(a)	(sizeof(a) / sizeof(a[0]))
#define	INF32		INT32_MAX
#define	INF64		INT64_MAX
#define Rep(i,n) for(int i = 0; i < (n); ++i )

using namespace std;

typedef vector< vector<int> > MAT;
typedef pair<int, int> PINT;
typedef long long ll;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int32_t s32;
typedef int64_t s64;

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

static char get_neighbor(char before, char curr, char marubatu)
{
	char after = 0;
	if (before == 'W' && curr == 'W') {
		after = (marubatu == 'o') ? 'S' : 'W';
	}
	else if (before == 'S' && curr == 'W') {
		after = (marubatu == 'o') ? 'W' : 'S';
	}
	else if (before == 'W' && curr == 'S') {
		after = (marubatu == 'o') ? 'W' : 'S';
	}
	else if (before == 'S' && curr == 'S') {
		after = (marubatu == 'o') ? 'S' : 'W';
	}
	else {
		assert(0);
	}
	return after;
}

// main function
int main()
{
	ll N = 0;
	string s = "";
	string ans = "";

	cin >> N;
	cin >> s;

	string init_str[] = {"SS", "SW", "WS", "WW"};
	string tmp(N, '.');
	Rep(i, numberof(init_str)) {
		tmp[0] = init_str[i][0];
		tmp[1] = init_str[i][1];
		char tail = get_neighbor(init_str[i][1], init_str[i][0], s[0]);

		for (ll j = 1; j < N; ++j) {
			char next = get_neighbor(tmp[j - 1], tmp[j], s[j]);

			if (j == N - 1) {
				if (next == tmp[0] && tail == tmp[N - 1]) ans = tmp;
			}
			else {
				tmp[j + 1] = next;
			}
		}
	}

	if (ans == "") {
		cout << -1 << endl;
	}
	else {
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main(){
	int i,j,n,ans = 0;
	vector<int> vec;
	cin >> n;
	for(i = 0;i < n;i++){
		cin >> j;
		ans += j;
		vec.push_back(j);
	}
	j = 0;
	sort(vec.begin(),vec.end());
	if(ans % 10 == 0){
		for(i = 0;i < vec.size();i++){
			if(vec[i] % 10 != 0){
				ans -= vec[i];
				break;
			}else if(vec[i] % 10 == 0)j++;
		}
	}
	if(j == vec.size()){
		cout << '0' << endl;
		return 0;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

S = sys.stdin.readline().rstrip()
K = int(sys.stdin.readline())


def solve(S, K):
    if len(set(list(S))) == 1:
        return K * len(S) // 2

    if K == 1:
        counts = [1] * len(S)
        cnt = 1
        for i, (c, d) in enumerate(zip(S, S[1:])):
            if c == d:
                cnt += 1
                counts[i] = 0
            else:
                counts[i] = cnt
                cnt = 1
        counts[-1] = cnt
        counts = np.array(counts, dtype=int)
        return (counts // 2).sum()

    S3 = S * 3
    counts = [1] * len(S3)
    cnt = 1
    for i, (c, d) in enumerate(zip(S3, S3[1:])):
        if c == d:
            cnt += 1
            counts[i] = 0
        else:
            counts[i] = cnt
            cnt = 1
    counts[-1] = cnt

    counts = np.array(counts, dtype=int)
    ans = (counts[:len(S)] // 2).sum()
    ans += (counts[len(S):len(S)*2] // 2).sum() * (K - 2)
    ans += (counts[len(S)*2:] // 2).sum()
    return ans


print(solve(S, K))


Measured memory_bytes: 21400
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;


int main()
{
    int N = 0;
    int cnt = 0;
    //問題の読込
    cin >> N;
    vector<string> S(N);
    rep(i, N)  cin >> S.at(i);
    sort(S.begin(), S.end());

    //探索
    rep(i, N) {
        if (i == 0) {
            cnt = cnt + 1;
            continue;
        }
        if (S.at(i - 1) != S.at(i)) 
            cnt = cnt + 1;
    }
    cout << cnt;
}


Measured memory_bytes: 7644
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
using namespace std;

int main(){
    int x;
    cin >> x;
    
    if(x == 7 || x == 5 || x == 3){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}


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

using namespace std;
#define INF 1000007
#define MOD 1000000007
#define int long long
#define maxn 1e5+4
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)

typedef std::pair<int, int> P;

vector<bool> prime(maxn + 1, true); //素数テーブル
void prime_table(void) {
    prime[0] = false;
    prime[1] = false;
    for (int i = 2; i * i <= maxn; i++) {
        if (!prime[i]) {
            continue;
        }
        for (int j = i + i; j <= maxn; j += j + i) {
            prime[j] = false;
        }
    }
}

int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

int lcm(int a, int b) { return a / gcd(a, b) * b; }

bool IsPrime(int num) //素数判定
{
    if (num < 2)
        return false;
    else if (num == 2)
        return true;
    else if (num % 2 == 0)
        return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2) {
        if (num % i == 0) {
            return false;
        }
    }

    return true;
}

vector<int> divisor(int n) //約数列挙
{
    vector<int> ret;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i - 1);
            if (i * i != n) {
                ret.push_back((n / i) - 1);
            }
        }
    }
    sort(ret.begin(), ret.end());
    return (ret);
}

int a, b;

void f(int x) {
    while (x) {
        a++;
        b = x;
        x /= 10;
    }
}

int N, M, K;
vector<int> A(maxn), B(maxn), C(maxn), D(maxn), lavel(maxn);
vector<vector<int>> fr(maxn);
vector<vector<int>> bl(maxn);
vector<int> ans(maxn);
int dfs(int now, int l) {
    lavel[now] = l;

    int ret = 0;
    for (int c:fr[now]) {
        if (lavel[c] != 0)continue;
        ret += dfs(c, l) + 1;
    }

    return ret;
}

signed main() {
    cin >> N >> M >> K;
    rep(i, M) {
        cin >> A[i] >> B[i];
        A[i]--, B[i]--;
        fr[A[i]].push_back(B[i]);
        fr[B[i]].push_back(A[i]);
    }
    rep(i, K) {
        cin >> C[i] >> D[i];
        C[i]--, D[i]--;
        bl[C[i]].push_back(D[i]);
        bl[D[i]].push_back(C[i]);
    }
    for (int i = 0, l = 1; i < N; i++, l++) {
        if (lavel[i] != 0) continue;
        ans[l] = dfs(i, l) + 1;
    }
    rep(i, N) {
        int A = ans[lavel[i]] -1 -fr[i].size();
        for (int b:bl[i]) {
            if (lavel[b] == lavel[i]){
             A--;
            }
        }
        cout << A << " ";
    }
    cout << endl;
}


Measured memory_bytes: 18304
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>

using namespace std;


int main() 
{
	int n;
	while(cin >> n && n>0)
	{
		int ans = 2000000;
		for(int i = 0;i<101;i++)
		{
			for(int j=0;j<1001;j++)
			{
				if((n-i*i*i-j*j)>-1)
				{
					if(ans>(i+j+n-i*i*i-j*j))
					{
						ans = i+j+n-i*i*i-j*j;
					}
				}
			}
		}
		cout << ans << endl;
	}
	return 0 ;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIII pair< int, pair<int,int> >
const int MXN = 105;
const int MXN2 = 1e5;
int weight[MXN], profit[MXN];
ll dp[MXN][MXN2+5];
int N,W;

ll rec(int pos, int rem){

    if(rem<0) return INT_MIN;
    if(pos>N) return 0;
    ll &ret = dp[pos][rem];
    if(ret!=-1) return ret;
    return ret = max( rec(pos+1,rem-weight[pos]) + profit[pos] , rec(pos+1,rem)  );
}

void read(){
    cin>>N>>W;
    for(int i=1; i<=N; i++)
        cin>>weight[i]>>profit[i];
}

void solve(){

    memset(dp,-1,sizeof(dp));
    read();
    cout<< rec(1,W) << "\n";
}

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
}


Measured memory_bytes: 82304
#include<iostream>
#include<cstdlib>
#include<stack>
#include<queue>
using namespace std;

int max(int x, int y);
int min(int x, int y);
int gcd(int x, int y);	/*最大公約数*/
int lcm(int x, int y);	/*最小公倍数*/

typedef stack<int> IntStack;
typedef queue<int> IntQueue;

/*ここまでテンプレ*/



/*ここからmain関数*/

int main()
{
	int N, Q;
	char S[100000];
	cin >> N >> Q >> S;

	int l[100000], r[100000];
	for (int i = 0;i < Q;i++)
	{
		cin >> l[i] >> r[i];
	}

	int c[100000];
	c[0] = 0;

	for (int i = 1;i <= N;i++)
	{
		if (S[i-1] == 'A'&&S[i] == 'C')
			c[i] = c[i - 1] + 1;
		else
			c[i] = c[i - 1];
	}

	for (int i = 0;i < Q;i++)
	{
		cout << c[r[i]-1]-c[l[i]-1] << "\n";
	}

	return 0;
}

/*2数の大きい方を返す*/
int max(int x, int y)
{
	int max;

	if (x < y)
		max = y;
	else
		max = x;

	return max;
}

/*2数の小さい方を返す*/
int min(int x, int y)
{
	int min;

	if (x < y)
		min = x;
	else
		min = y;

	return min;
}

/*2数の最大公約数を返す*/
int gcd(int x, int y)
{
	int m;
	int gcd = 1;

	m = min(x, y);

	for (int i = 1;i <= m; i++)
	{
		if (x%i == 0 && y%i == 0)
			gcd = i;
	}

	return gcd;
}

/*2数の最小公倍数を返す*/
int lcm(int x, int y)
{
	int m;

	for (int i = 1;i <= y;i++)
	{
		if ((x*i) % y == 0) {
			m = x * i;
			break;
		}
	}

	return m;
}

Measured memory_bytes: 2048
import sys
import collections
sys.setrecursionlimit(10**6)


def main(input, print):
    n = int(input())
    a = list(map(int, input().split()))
    counter = collections.Counter(a)
    q = int(input())
    sum = 0
    for key in counter:
        sum += key * counter[key]
    for i in range(q):
        b, c = map(int, input().split())
        cnt = counter[b]
        del counter[b]
        counter[c] += cnt
        sum += (c-b)*cnt

        print(sum)


if __name__ == '__main__':
    main(sys.stdin.readline, print)


Measured memory_bytes: 95444
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a;
    cin>>a;
    int b[a];
    int c=1;
    int kaito72=0;
    for(int i=1;i<=a;i++){
		cin>>b[i];
	}
	while(c!=2){
		c=b[c];
		if(c==2){
			cout<<kaito72+1<<endl;
			return 0;
		}
		if(kaito72>a){
			break;
			//これでTLEしないぞ//
		}
		kaito72++;
	}
	cout<<-1<<endl;
}


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

int main() {
  using tsii = tuple<string, int, int>;
  using vt = vector<tsii>;

  int n;
  cin >> n;
  auto v = vt(n);
  
  for (int i = 0; i < n; i++) {
    cin >> get<0>(v[i]) >> get<1>(v[i]);
    get<2>(v[i]) = i + 1; 
  }

  sort(v.begin(), v.end());

  int left = 0;
  for (int i = 0; i < n - 1; i++) {
    string s, sn;
    tie(s, ignore, ignore) = v[i];
    tie(sn, ignore, ignore) = v[i + 1];

    if (s != sn) {
      reverse(v.begin() + left, v.begin() + i + 1);
      left = i + 1;
    } else if (i == n - 2) {
      reverse(v.begin() + left, v.end());
    }
  }

  for (auto t: v)
    cout << get<2>(t) << endl;
}


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

#define NREP() for(ll i = 0; i < n; i++)
#define MREP() for(ll j = 0; j < m; j++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define IPT(t, x) t ipt; cin >> ipt; x.push_back(ipt);
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;

const static ll MOD = 1e9 + 7;
ll n, cnt, ans, tmp, sum, a, b, c, d, k, m, h, w, q, x, y;
string s, t;

int main() {
    cin >> s;
    sum = 0;
    REP(i, s.size()) {
        sum += s.at(i) - '0';
    }
    Yn(atoi(s.c_str()) % sum == 0)
}


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

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

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


int main() {
  //入力
  int K, N;
  cin >> K >> N;
  vector<int> A(N);
  REP(i, N) cin >> A.at(i);
  
  int t = N, tmax = K + A.at(0) - A.at(N-1);

  REP(i, N-1){
    int d = A.at(i+1) - A.at(i);
    if(chmax(tmax, d)) t = i;
  }

  int ans = 0;
  
  REP(i, N-1){
    if(t != i) ans += A.at(i+1) - A.at(i);
  }
  
  if(t != N) ans += K + A.at(0) - A.at(N-1);
  
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3976
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(void){
    string s; cin>>s;
    int ans=1000000000;
    for(int i=0;i<s.size()-2;i++){
        int a=s[i]-48,b=s[i+1]-48,c=s[i+2]-48;
        //cout<<a<<" "<<b<<" "<<c<<endl;
        ans=min(ans,abs(100*a+10*b+c-753));
    }
    cout<<ans<<endl;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  int P = 1000000007; 
  int n,k;
  cin >> n >> k;
  
  vector<int> a(n);
  vector<pair<int,int>> b(n);
  rep(i,0,n) cin >> a[i];
  
  int f,s;
  rep(i,0,n) {
    f = 0;
    s = 0;
    rep(j,1,n-i){
      if(a[i]>a[i+j]) f++;
    }
    rep(j,0,n){
      if(a[i]>a[j]) s++;
    }
    
    b[i] = make_pair(f,s);
  }
  
  int ans = 0;
  rep(i,0,n){
    ans += (b[i].first * k) % P;
    ans += ( (((k*(k-1))/2)%P) * b[i].second) % P;
  }
  cout << ans % P << endl;
}


Measured memory_bytes: 256
using System;
using static System.Console;

class Program
{
    static void Main()
    {
        var input = ReadLine().Split();
        var n = int.Parse(input[0]);
        var x = int.Parse(input[1]);

        var pos = ReadLine().Split();
        var distance = new int[n];
        for (int i = 0; i < n; i++)
        { distance[i] = Math.Abs(int.Parse(pos[i]) - x); }        

        var ans = distance[0];
        for (int i = 1; i < n; i++)
        {
            ans = gcd(ans, distance[i]);
        }

        WriteLine(ans);
    }

    static int gcd(int a,int b)
    {
        var max = Math.Max(a, b);
        var min = Math.Min(a, b);

        while (min != 0)
        {
            var temp = max % min;
            max = min;
            min = temp;
        }
        return max;
    }
    
}


Measured memory_bytes: 18400
S=input()
N=len(S)
dp=[[0 for i in range(13)] for j in range(N+1)]
q=[(i*10)%13 for i in range(13)]
r=[q.index(i) for i in range(13)]
MOD=10**9+7
if S[0]=="?":
  dp[1]=[1,1,1,1,1,1,1,1,1,1,0,0,0]
else:
  dp[1][int(S[0])]=1
for i in range(2,N+1):
  if S[i-1]=="?":
    for j in range(13):
      for x in range(10):
        dp[i][(x+q[j])%13]+=dp[i-1][j]
    dp[i]=[dp[i][j]%MOD for j in range(13)]
  else:
    for j in range(13):
      x=int(S[i-1])
      dp[i][(x+q[j])%13]=dp[i-1][j]
print(dp[N][5])

Measured memory_bytes: 84316
n, d = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
count = 0

for i in range(n):
    for j in range(i+1, n):
        num = 0
        for k in range(d):
            num += (x[i][k] - x[j][k]) ** 2
        check = pow(num, 0.5)
        if check.is_integer():
            count += 1

print(count)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, begin, end) for (ll i = (begin); i < (end); i++)
#define REP(i, n) FOR(i, 0, n)
#define IFOR(i, begin, end) for (ll i = (begin)-1; i >= (end); i--)
#define IREP(i, n) IFOR(i, n, 0)
#define SORT(a) sort(a.begin(), a.end())
#define ISORT(a) sort(a.begin(), a.end(), greater<ll>())
#define REVERSE(a) reverse(a.begin(), a.end())
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v)                                                              \
  cout << #v << "=(" << v[0];                                                  \
  FOR(i_debug, 1, v.size()) { cout << "," << v[i_debug]; }                     \
  cout << ")" << endl;
#define mdebug(m)                                                              \
  cout << #m << "=" << endl;                                                   \
  REP(i_debug, m.size()) {                                                     \
    REP(j_debug, m[i_debug].size()) { cout << m[i_debug][j_debug] << ","; }    \
    cout << endl;                                                              \
  }
#define Lower_bound(v, x)                                                      \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x)                                                      \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)

#define ll long long
// #define f first
// #define s second
#define mp make_pair
#define pb push_back
#define INF 1000000000000000000

using vec = vector<ll>;
using mat = vector<vec>;
using Pii = pair<ll, ll>;
using PiP = pair<ll, Pii>;
using PPi = pair<Pii, ll>;
using bvec = vector<bool>;
using Pvec = vector<Pii>;

template <typename T> void readv(vector<T> &a) { REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a) {
  REP(i, a.size()) {
    cin >> a[i];
    a[i]--;
  }
}

ll mod = 1000000007;

// https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a#4-%E7%B4%AF%E4%B9%97-an
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

int main() {
  ll N, K;
  cin >> N >> K;

  vec ans(K + 1, 0);

  IFOR(i, K + 1, 1) {
    ans[i] = modpow(int(K / i), N, mod);
    // debug(i);
    for (ll j = 2; j * i <= K; j++) {
      ans[i] -= ans[j * i];
      // debug(j * i);
    }
  }
  // vdebug(ans);

  ll fnans = 0;
  FOR(i, 1, K + 1) { fnans = (fnans + ans[i] * i) % mod; }
  fnans %= mod;

  cout << fnans << endl;

  return 0;
}

Measured memory_bytes: 4052
import java.util.Scanner;
 
public class Main {
 
	public Main() {
		// TODO 自動生成されたコンストラクター・スタブ
	}
 
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n,m,answer,index;
		float ans;
		String s,t;
		
			// 整数の入力
		
		s = sc.next();
		sc.close();
		
		
		if(s.equals("SUN")){
			System.out.print("7");
		}
		else if(s.equals("MON")){
			System.out.print("6");
		}
		else if(s.equals("TUE")){
			System.out.print("5");
		}
		else if(s.equals("WED")){
			System.out.print("4");
		}
		else if(s.equals("THU")){
			System.out.print("3");
		}
		else if(s.equals("FRI")){
			System.out.print("2");
		}
		else if(s.equals("SAT")){
			System.out.print("1");
		}

			// 出力
 
	}
}	

Measured memory_bytes: 21716
import sys
input = sys.stdin.readline

n = int(input())

f = [0 for i in range(n)]
for x in range(1,100):
    for y in range(1,100):
        for z in range(1,100):
            tmp = x*x+y*y+z*z+x*y+y*z+z*x
            if tmp <= n:
                f[tmp-1] += 1

print("\n".join(map(str,f[:n])))

Measured memory_bytes: 68044
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
typedef long long ll;
ll n, m;

int main() {
	ll h, w;
	cin >> h >> w;
	ll a[h][w]; 
	for(ll i = 0; i < h; i++){
		for(ll j = 0; j < w; j++){
			cin >> a[i][j];
		}
	}
	vector<vector<ll>> operation;
	for(ll i = 0; i < h; i++){
		if(i%2 == 0){
			for(ll j = 0; j < w; j++){
				if(a[i][j]%2 != 0){
					if(j != w-1){
						operation.push_back({i, j, i, j+1});
						a[i][j+1]++;
					}
					else{
						if(i != h-1){
							operation.push_back({i, j, i+1, j});
							a[i+1][j]++;
						}
					}
				}
			}
		}
		else{
			for(ll j = w-1; j >= 0; j--){
				if(a[i][j]%2 != 0){
					if(j != 0){
						operation.push_back({i, j, i, j-1});
						a[i][j-1]++;
					}
					else{
						if(i != h-1){
							operation.push_back({i, j, i+1, j});
							a[i+1][j]++;
						}
					}
				}
			}
		}
	}
	ll n = operation.size();
	cout << n << endl;
	for(ll i = 0; i < n; i++){
		vector<ll> buf = operation[i];
		cout << buf[0]+1 << " " << buf[1]+1 << " " << buf[2]+1 << " " << buf[3]+1 <<endl;
	}
	
	return 0;
}

Measured memory_bytes: 12848
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define era(t) t.erase(unique(be(t)),t.end())
typedef long long ll;
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    vector<string> t;
    int n=s.length();
    int k;
    cin>>k;
    for(int i=0;i<n;i++){
        int maki=min(k,n-i);
        for(int j=0;j<maki;j++){
            t.pb(s.substr(i,j+1));
        }
    }
    sort(be(t));
    era(t);
    cout <<t[k-1]<<endl;
    return 0;
}




Measured memory_bytes: 1660
def exp(n)
  return 0 if n == 0
  sum = 0
  sum = (n * (n + 1)) / 2
  sum.to_f / n
end

n, k = gets.split.map(&:to_i)
p = gets.split.map{ |x| exp(x.to_i) }
s= []
s[0] = p[0]
for i in 1..n-1
  s[i] = s[i-1] + p[i]
end
max = s[k-1]
for j in k..n-1
  max = s[j] - s[j-k] if max < s[j] - s[j-k]
end
puts max


Measured memory_bytes: 16596
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.io.IOException;
import java.io.FileReader;
import java.io.FileWriter;

import java.util.*;
import java.util.stream.LongStream;

public class Main {
    // 標準入力
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    // 標準入力数値配列用 int
    static int[] inputval() throws Exception {
        String[] strarray = br.readLine().trim().split(" ");
        int[] intarray = new int[strarray.length];
        for (int i = 0; i < intarray.length; i++) {
            intarray[i] = Integer.parseInt(strarray[i]);
        }
        return intarray;
    }

    /* 標準入力数値配列用 long */
    static long[] inputLongArr() throws Exception {
        String[] strarray = br.readLine().trim().split(" ");
        long[] longarray = new long[strarray.length];
        for (int i = 0; i < longarray.length; i++) {
            longarray[i] = Long.parseLong(strarray[i]);
        }
        return longarray;
    }

    // 標準入力数値リスト用 int
    static List<Integer> inputIntList() throws Exception {
        List<String> strList = Arrays.asList(br.readLine().trim().split(" "));
        List<Integer> intList = new ArrayList<Integer>();
        for (String elem : strList){
            intList.add(Integer.parseInt(elem));
        }
        return intList;
    }

    // 標準入力数値配列用 integer 降順ソート用
    static Integer[] inputvalInteger() throws Exception {
        String[] strarray = br.readLine().trim().split(" ");
        Integer[] intarray = new Integer[strarray.length];
        for (int i = 0; i < intarray.length; i++) {
            intarray[i] = Integer.parseInt(strarray[i]);
        }
        return intarray;
    }

    /*標準入力long*/
    static long inputLong() throws Exception {
        return Long.parseLong(br.readLine());
    }

    /*標準入力long*/
    static int inputInt() throws Exception {
        return Integer.parseInt(br.readLine());
    }




    public static void main(String[] args) throws Exception {
        // write your code here
        int n = inputInt();
        long [] al = inputLongArr();
        int kCnt = 0;
        for (long a : al){
            if (a % 2 == 1){
                kCnt++;
            }
        }
        if (kCnt %2 == 0){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }

    }

}



Measured memory_bytes: 46584
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;



const int MAX_SIZE = 10000;
const int MAX_PRIME = 100001;


int prime[MAX_PRIME+1];
bool isPrime[MAX_PRIME+1];
int p;

void erats(){
	// primeツδ環スツトツづーツ渉可甘コツ可サ
	fill(isPrime,isPrime+MAX_PRIME,true);
	p = 0;
	isPrime[0] = isPrime[1] = false;

	for(int i = 2; i <= MAX_PRIME; i++){
		if(isPrime[i]){
			prime[p++] = i;
		}
		else
			continue;

		// ツづ督づゥツつ「ツづ可つゥツつッツづゥ
		for(int j = 2*i; j <= MAX_PRIME; j+=i){
			isPrime[j] = false;
		}
	}
}

int main(){

    int m,a,b;
    erats();
    while(cin>>m>>a>>b&&!(m==0&&a==0&&b==0)){
        int maxNum=0;
        int p,q;
        for(int i = 1; i*i<= m; i++){
            if(!isPrime[i])continue;
            for(int j = i; j*i<=m&&j*a<=i*b; j++){
                if(!isPrime[j])continue;
                if(j*i>maxNum){
                    p=i;q=j;
                    maxNum=j*i;
                }
            }
        }
        cout<<p<<" "<<q<<endl;
    }

    return 0;
}

Measured memory_bytes: 1004
#include<bits/stdc++.h>
#define lg long long int
#define loop(i,s,e) for(lg i=s;i<=e;i++)
#define iloop(i,s,e) for(lg i=e;i>=s;i--)
#define pb push_back
#define mp make_pair
#define mod 1000000007


using namespace std;

lg min(lg a,lg b)
{return a<b?a:b;}
lg max(lg a,lg b)
{return a>b?a:b;}
lg lcm(lg a ,lg b)
{
    return (a*b)/__gcd(a,b);
}

int main()
{

    lg n;
    cin>>n;

    cout<<n+(n*n)+(n*n*n)<<endl;

}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)   for(signed i=0; i<n; i++)
#define yn(b)   cout << ((b)?"Yes":"No") << endl
#define YN(b)   cout << ((b)?"YES":"No") << endl
#define pr(r)   cout << r << endl
int main(void){
    string s, t;
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    reverse(t.begin(), t.end());
    int r = (s.length()<=t.length())? s.length():t.length();
    int i;
    rep(i, r){
        if((int)s.at(i) < (int)t.at(i)){
            yn(1);
            break;
        }else if((int)s.at(i) > (int)t.at(i)){
            yn(0);
            break;
        }
        if(i == r-1 && s.length()<t.length()) yn(1);
        else if(i == r-1 && s.length()>=t.length()) yn(0);
    }
}

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

const int INFTY = 2e9;

int A[500001], L[250001], R[250001], cnt = 0;

void merge(int left, int mid, int right){
    int n1 = mid - left;
    int n2 = right - mid;
    for(int i = 0; i < n1; i++) L[i] = A[left+i];
    for(int i = 0; i < n2; i++) R[i] = A[mid+i];
    L[n1] = INFTY;
    R[n2] = INFTY;
    int i = 0, j = 0;
    for(int k = left; k < right; k++){
        if(L[i] <= R[j]){
            A[k] = L[i];
            i++;
            cnt++;
        }
        else{
            A[k] = R[j];
            j++;
            cnt++;
        }
    }
}

void mergeSort(int left, int right){
    if(left+1 < right){
        int mid = (left + right) / 2;
        mergeSort(left, mid);
        mergeSort(mid, right);
        merge(left, mid, right);
    }
}

int main(){
    int n;
    cin >> n;
    for(int i = 0; i < n; i++) cin >> A[i];
    mergeSort(0, n);
    for(int i = 0; i < n; i++) cout << A[i] << (i == n-1 ? '\n' : ' ');
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 6992
#include<bits/stdc++.h>
using namespace std;
//freopen("input.txt" , "r" , stdin);
//freopen("output.txt" , "w" , stdout);
#define ll long long
#define endl  '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i,n)  for(ll i=0;i<n;i++)
#define REP1(i1,n)  for(ll i=1;i<n;i++)
#define pb push_back
#define mk make_pair
int main()
{
   IOS
   char c;
   cin>>c;
   if(c>='A'&& c<='Z')cout<<"A"<<endl;
   else cout<<"a"<<endl;

}
    //for(ll i=0;i<len;i++)cout<<v[i]<<" ";



/*

Alhamdulilla...

*/


Measured memory_bytes: 3636
A, B, C, K = [int(x) for x in input().split()]

count, score = 0, 0

c = min(A, (K - count))
score += 1 * c
count += c
if count < K:
    c = min(B, (K - count))
    score += 0 * c
    count += c

    if count < K:
        c = min(C, (K - count))
        score += -1 * c
        count += c

print(score)


Measured memory_bytes: 9100
#include <iostream>
#include<vector>
using namespace std;
int main() {
	int n;
	cin >> n;
	vector<int> vec(n - 1);
	for (int i = 0; i < n - 1; i++) {
		cin >> vec.at(i);
	}
	vector<int> ans(n, 0);
	for (int i = 0; i < n - 1; i++) {
		ans.at(vec.at(i) - 1)++;
	}
	for (int i = 0; i < n-1; i++) {
		cout << ans.at(i) << endl;
	}
	cout << ans.at(n - 1);
}

Measured memory_bytes: 4816
#include <iostream>
#include <vector>
#include <string.h>
#include <set>
#include <map>
#include <unordered_map>
#include <assert.h>
#include <algorithm>
#include <queue>
#include <bitset>
#include <stack>
#include <chrono>
#include <random>
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define ll long long
#define MOD 1000000007 
#define INF 1000000000000000000
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define uid uniform_int_distribution <int>
using namespace std;
// Read the question carefully and see all the given sample tests
// Think about the correctness before implementing

const int N = 200 * 1000 + 5;
vector <int> tree(N);
int getsum(int id) {
	int res = 0;
	while(id > 0) {
		res += tree[id];
		id -= (id & -id);
	}
	return res;
}
void update(int id, int val) {
	while(id < N) {
		tree[id] += val;
		id += (id & -id);
	}
}
int main() {
	int n;
	cin >> n;
	vector <int> A(n);
	map <int, int> m, rm;
	for (int i = 0; i < n; i++) {
		cin >> A[i];
		m[A[i]];
	}
	int x = 0;
	for (auto g : m) {
		m[g.ff] = ++x;
		rm[x] = g.ff;
	}
	for (int i = 0; i < n; i++) {
		A[i] = m[A[i]];
	}
	auto check = [&](int mid) {
		vector <int> pre(n);
		ll ans = 0;
		for (int i = 0; i < n; i++) {
			pre[i] = (A[i] <= mid ? -1 : 1);
			if(i > 0)
				pre[i] += pre[i - 1];
			if(pre[i] < 0)
				ans++;
		}
		for (int i = 0; i < n; i++) {
			pre[i] += (n + 1);
		}
		for (int i = 0; i < n; i++) {
			ans += (i - getsum(pre[i]));
			update(pre[i], 1);
		}
		tree.assign(N - 1, 0);
		return ans;
	};
	int lo = 1, hi = n, ans = -1;
	ll total = 1LL * n * (n + 1) / 2;
	while(lo <= hi) {
		int mid = (lo + hi) / 2;
		if(check(mid) >= total / 2 + 1) {
			ans = mid;
			hi = mid - 1;
		}
		else {
			lo = mid + 1;
		}
	}
	cout << rm[ans];
}


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

typedef long long int ll;

const int MAX = 2e5 + 10;

int main()
{
	int k,s; cin>>k>>s;

	int ans = 0;

	for(int i=0;i<=k;i++){
		int res = s - i;
		if(res < 0) break;
		for(int j=0;j<=k;j++){
			int res1 = res - j;
			if(res1 < 0) break;

			if(res1 <= k) ans++;
		}
	}

	cout<<ans;
}

// abcab

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

signed main() {
    string s;
    int ans = 0, sum;
    cin >> s;
    
    sum = 0;
    for ( int i = 0; i < s.size(); i++ ) {
        if ( s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T' ) {
            sum ++;
        } else {
            ans = max(sum, ans);
            sum = 0;
        }
    }
    
    cout << max(sum, ans) << endl;
    return (0);
}

Measured memory_bytes: 3628
import kotlin.math.*
import java.util.*

const val MOD = 1_000_000_007L

fun readI() = readLine()!!.toInt()
fun readL() = readLine()!!.toLong()
fun readD() = readLine()!!.toDouble()
fun readIs() = readLine()!!.split(' ').map(String::toInt)
fun readLs() = readLine()!!.split(' ').map(String::toLong)
fun readDs() = readLine()!!.split(' ').map(String::toDouble)

fun main() {
    val (n, x, t) = readIs()
    if (n % x == 0) {
        println(n / x * t)
    } else {
        println(n / x * t + t)
    }
}





Measured memory_bytes: 36500
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
//using System.Text;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;
//using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;
    void chmax<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? b : a; }
    void chmin<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? a : b; }

    void solve()
    {
        int X = cin.nextint;
        int ans = 1;
        for (int i = 2; i < X; i++)
        {
            int j = i * i;
            while (j <= X)
            {
                chmax(ref ans, j);
                j *= i;
            }

        }
        WriteLine(ans);
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

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

#define ll long long
#define ld long double
#define ull unsigned ll
#define ioi exit(0);

#define f first
#define s second

#define inf (int)1e9 + 7

#define NFS ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);

#define mp(x,y) make_pair(x,y)

#define lb(x) lower_bound(x)
#define ub(x) upper_bound(x)

#define pb push_back
#define ppb pop_back

#define bitcoin __builtin_popcount
 
#define endl "\n"
 
#define in(x) insert(x)
 
#define sz(x) (int)x.size()
 
#define all(x) x.begin(),x.end()
 
#define pw2(x) (1ll<<x) //2^x
 
#define forit(it,v) for (typeof(v.begin()) it = v.begin(); it != v.end(); ++it)
 
#define sqr(x) ((x) * 1ll * (x))
 
#define UpdateRandom srand (time(NULL));
 
using namespace std;
 
const int N = (int)5e5 + 7, MOD = (int)1e9 + 7;

int main(){
		
	NFS

	int a,b;
	
	cin >> a >> b;	
	
	cout << a*b << endl;
	
	ioi
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;

int main(){
  int N,M; cin>>N>>M;
  vector<pair<int,int>> V(N);
  rep(i,N){
    cin>>V[i].first>>V[i].second;
  }
  sort(V.begin(),V.end());
  ll ans=0;
  for(auto p:V){
    ans+=1LL*p.first*min(p.second,M);
    M-=min(p.second,M);
    if(M==0) break;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repo(i,N) for(int i = 1; i < (N); i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//#define int long long
//cout << fixed << setprecision (10);   小数点以下１０桁まで

int main() {
  string s;
  cin >>s;

    cout <<(s<="2019/04/30"?"Heisei":"TBD")<< endl;
    
}


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

int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    for(int i=0; i<N; i++) cin >> a[i];

    int mx = *max_element(a.begin(), a.end());
    if(mx <= 0){
        cout << mx << endl;
        int id = max_element(a.begin(), a.end()) - a.begin() + 1;
        cout << N - 1 << endl;
        for(int i=N; i>id; i--)
            cout << i << endl;
        for(int i=1; i<id; i++)
            cout << 1 << endl;
        return 0;
    }

    long long w = 0, b = 0;
    for(int i=0; i<N; i+=2)
        if(a[i] > 0)
            w += a[i];
    for(int i=1; i<N; i+=2)
        if(a[i] > 0)
            b += a[i];

    long long ans = max(w, b);
    cout << ans << endl;

    vector<int> dl;
    if(ans == w){
        for(int i=0; i<N; i+=2)
            if(a[i] < 0)
                dl.push_back(i);
    }else{
        for(int i=1; i<N; i+=2)
            if(a[i] < 0)
                dl.push_back(i);
    }
    int M = N - 2*dl.size();
    bool flg = false;
    if(!dl.empty() && dl[0] == 0){
        M++;
        flg = true;
    }
    if(!dl.empty() && dl.back() == N-1) M++;

    vector<int> dl2;
    if( (!flg && ans == w) || (flg && ans == b)){
        for(int i=1; i<M; i+=2)
            dl2.push_back(i);
    }else{
        for(int i=0; i<M; i+=2)
            dl2.push_back(i);
    }

    cout << dl.size() + dl2.size() << endl;
    reverse(dl.begin(), dl.end());
    reverse(dl2.begin(), dl2.end());
    for(int x : dl)
        cout << x+1 << endl;
    for(int x : dl2)
        cout << x+1 << endl;

    return 0;
}

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

int main(){
    string S;
    cin >> S;
    int s = (int)S.size();

    int t = 0, ans = 0;
    for (int i = 0; i < s;i+= 2){
        if(S[i] != '1')
            t++;
        if(i + 1 < s && S[i+1] != '0')
            t++;
    }
    for (int i = 0; i < s; i += 2)
    {
        if (S[i] != '0')
            ans++;
        if (i + 1 < s && S[i + 1] != '1')
            ans++;
    }
    cout << min(ans, t) << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
string s;
int main() {
  cin >> s;
  int cnt[50];
  for (int i = 0; i < 50; i++) cnt[i] = 0;
  for (int i = 0; i < s.length(); i++) cnt[s[i]-'a']++;
  bool flag = true;
  for (int i = 0; i < 30; i++) if (cnt[i] % 2) flag = false;
  if (flag) puts("Yes");
  else puts("No");
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
#define Mod 1000000007
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;

bool ok(char c){
    if(c=='A'||c=='C'||c=='G'||c=='T') return 1;
    else return 0;
}

int main(){
    ll i,j;
    string s;
    cin>>s;
    ll l=s.size();
    ll an=0;
    for(i=0;i<l;i++){
        if(ok(s[i])) an++;
    }
    if(an==0) {
        cout<<0<<endl;
        return 0;
    }
    ll p=0,q=l-1;
    vector<ll> v(l);
    ll t=0;
    ll ans=0;
    for(i=0;i<l;i++){
        if(ok(s[i])) t++;
        else {
            ans=max(ans,t);
            t=0;
        }
    }
    cout<<max(ans,t)<<endl;
    
    return 0;
}

Measured memory_bytes: 256
import numpy as np
n = int(input())
h = list(map(int, input().split()))
h_diff = np.diff(h)
li = [[]]
for i in range(n-1):
  if(h_diff[i] > 0):
    li.append([])
  else:
    li[-1].append("s")
tmp = 0
for arr in li:
  if(tmp <= len(arr)):
    tmp = len(arr)
print(tmp)
  

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

using namespace std;

string s;
bool exist(char c, int l, int r) {
	for (int i = l; i <= r; i++) {
		if (c == s[i]) {
			return true;
		}
	}
	return false;
}

int main() {
    int n;
    cin >> n >> s;
    int res = 0;
    for (int i = 0; i < n; i++) {
		int sum = 0;
		for (char c = 'a'; c <= 'z'; c++) {
			sum += exist(c, 0, i) & exist(c, i + 1, n - 1);
		}
		res = max(res, sum);
	}
	cout << res;
    return 0;
}


Measured memory_bytes: 3608