akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

typedef pair<LL,LL>PII;

/*
题意：
给你n个数，求区间有多少对除数和被除数的对数

思路：
线段树 区间和/ 树状数组 前缀和
2e5的数的除数最多才81个
对于一个数的贡献，我最好是区间的贡献，也就是1-n的贡献。
*/

const int N=2e5+10;
int a[N],n;
vector<int>ans;

int main(){
    ans.clear();
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    if(n == 1)
    {
        printf("%d\n",a[1]);
        return 0;
    }
    if(n%2 == 0){
        int t = n;
        while(t>1){
            ans.push_back(a[t]);
            t -= 2;
        }
        t = 1;
        while(t<n)
        {
            ans.push_back(a[t]);
            t += 2;
        }
    }
    else if(n%2 == 1){
        int t = n;
        while(t>=1){
            ans.push_back(a[t]);
            t -= 2;
        }
        t = 2;
        while(t<n)
        {
            ans.push_back(a[t]);
            t += 2;
        }
    }
    int sz = ans.size();
    for(int i=0;i<sz;i++){
        if(i) printf(" ");
        printf("%d",ans[i]);
    }
    return 0;
}



Measured memory_bytes: 3828
import numpy as np

N = int(input())
m = [list(map(int, input().split())) for _ in range(0, N)]

res = 0
for i in range(len(m)):
    for j in range(i+1, len(m)):
        res += np.sqrt((m[i][0] - m[j][0]) ** 2 + (m[i][1] - m[j][1]) ** 2)
        
print(res * 2 / N)

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

int main()
{
  int N;
  cin >> N;
  int Asum=0;
  int Bsum=0;
  int count=0;
  vector<int>a(N+1);
  for(int i=0;i<N;i++){
	cin >>a.at(i);
  }
     
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  
  for(int i=0;i<N;i++){
	if(a.at(i)==a.at(i+1))  count++;
}
  cout << N - count << endl;
}

Measured memory_bytes: 256
def main():
	H, W = [int(x) for x in input().split(" ")]
	C = []
	for i in range(10):
		c = [int(m) for m in input().split(" ")]
		C.append(c)
	A = [0] * 10 # 0 ~ 9, idx = 10 -> -1
	for i in range(H):
		a = [int(m) for m in input().split(" ")]
		for j in range(W):
			if a[j] != -1:
				A[a[j]] += 1

	MP = [[C[i][1] for i in range(10)]] # MP[0] -> overwrite once, MP[1] -> overwrite twice
	for i in range(9):
		MP.append([min([(C[k][j] + MP[-1][j]) for j in range(10)]) for k in range(10)])

	minMP = [10000] * 10
	for i in range(len(MP)):
		for j in range(len(MP[i])):
			minMP[j] = min([minMP[j], MP[i][j]])
	print(sum([p * q for (p, q) in zip(A, minMP)]))

main()

Measured memory_bytes: 9304
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include<stack>
#include<sstream>
typedef long long ll;

#define pi 3.14159265358979323846
#define VI vector<int>
#define VLL vector<long long>
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()

using namespace std;

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a * b / gcd(a, b);
}

/*char r[4];
int yaju[4];
char op[3];
int sum = 0;
scanf("%s", r);
for (int i = 0;i < 4;i++) {
	yaju[i] = r[i] - '0';
}
*/

int main() {
	int A,B, K; cin >> A >> B >> K;
	if (K*2 >= B - A + 1) for (int i = A;i <= B;i++) {
		cout << i << endl;
	}
	else {
		for (int i = A;i < A + K;i++) {
			cout << i << endl;
		}
		for (int i = B - K + 1;i <= B;i++) {
			cout << i << endl;
		}
	}
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<time.h>
#include<math.h>
struct node
{
	struct node *prev;
	struct node *next;
	int key;
};
struct node *head;//指向链表头部结点
struct node *tail;//指向链表尾部结点
void insertnode(int Key)//在链表头部添加结点,值为Key
{
	struct node *p,*q;
	p=(struct node *)malloc(sizeof(struct node));
	q=head;
	head=p;
	p->key=Key;
	p->prev=NULL;
	if(!q)
	{
		p->next=NULL;
		tail=p;
	}
	else
	{
		p->next=q;
		q->prev=p;
	}
	return;
}
void deletefirstnode()//删除链表头部的结点
{
	struct node *t;
	t=head;
	if(!head->next)
	{
		head=NULL;
		tail=NULL;
	}
	else
	{
		head->next->prev=NULL;
		head=head->next;
	}
	free(t);
	return;
}
void deletelastnode()//删除链表尾部的结点
{
	struct node *t;
	t=tail;
	if(!tail->prev)
	{
		head=NULL;
		tail=NULL;
	}
	else
	{
		tail->prev->next=NULL;
		tail=tail->prev;
	}
	free(t);
	return;
}
void deletenode(int Key)//删除第一个值为Key的结点
{
	struct node *t;
	t=head;
	while(t!=NULL)
	{
		if(t->key==Key)
		{
			if(!t->prev)
			{
				deletefirstnode();
				return;
			}
			if(!t->next)
			{
				deletelastnode();
				return;
			}
			t->prev->next=t->next;
			t->next->prev=t->prev;
			free(t);
			return;
		}
		t=t->next;
	}
	return;
}
void printlist()//输出并释放链表中的所有结点
{
	struct node *t;
	t=head;
	if(!t)
		return;
	while(1)
	{
		printf("%d",t->key);
		if(!t->next)
		{
			printf("\n");
			free(t);
			break;
		}
		else
		{
			printf(" ");
			t=t->next;
			free(t->prev);
		}
	}
	return;
}
int main()
{
	int n,valueofakey,i;//valueofakey是value of a key
	head=NULL;
	tail=NULL;
	char command[10];
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%s",command);
		if(strcmp(command,"deleteFirst")==0)
		{
			deletefirstnode();
			continue;
		}
		if(strcmp(command,"deleteLast")==0)
		{
			deletelastnode();
			continue;
		}
		scanf("%d",&valueofakey);
		if(strcmp(command,"insert")==0)
			insertnode(valueofakey);
		if(strcmp(command,"delete")==0)
			deletenode(valueofakey);
	}
	printlist();
	return 0;
}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define log_2(a) (log((a)) / log(2))
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    string s;
    cin >> s;
    if(s[s.size() - 1] == 's') cout << s << "es";
    else cout << s << "s";
    cout << endl;

    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;

long long mod = 1000000007;

long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t * t;
    } else {
        return modpow(m, n - 1) * m;
    }
}


int main() {
    long long n;
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); i++){
        cout << 'x';
    }
}

Measured memory_bytes: 256
N = int(input())

B = list(map(lambda x:int(x), input().split()))

ans = B[0]

for i in range(1, N-1):
  ans += min(B[i-1], B[i])

  
if len(B) != 1:
  ans += B[-1]
else:
  ans += B[0]
print(ans)

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

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		char[] s = stdIn.next().toCharArray();
		
		int sum = 0;
		for(char a: s) {
			if(a == '1') {
				sum++;
			}
		}
		System.out.println(sum);
	}

}


Measured memory_bytes: 23764
def main():
    nm = list(map(int, input().split()))
    h = list(map(int, input().split()))
    ab = [None]*nm[1]
    for i in range(nm[1]):
        ab[i] = list(map(int, input().split()))

    memo = [0]*nm[0]
    for i in range(nm[1]):
        a = ab[i][0]-1
        b = ab[i][1]-1
        if h[a] > h[b]:
            memo[b] = 1
        elif h[a] < h[b]:
            memo[a] = 1
        else:
            memo[a] = 1
            memo[b] = 1
    
    print(memo.count(0))

if __name__ == '__main__':
    main()

Measured memory_bytes: 31884
#include <iostream>
#include <vector>
using namespace std;
#define ll long long
int main(){
    int n;
    cin >> n;
    int nums[n];
    int nums2[n];
    int nums3[n];
    int ans=0;
    vector<int> cnts(100000,0);
    for(int i=0;i<n;i++){
        cin>>nums[i];
        nums2[i]=nums[i]/2;
        nums3[i]=(nums[i]+1)/2;
        cnts[nums2[i]]++;
        ans=max(cnts[nums2[i]],ans);
        if (nums2[i]!=nums3[i]){
            cnts[nums3[i]]++;
            ans=max(cnts[nums3[i]],ans);
        }
    }

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

Measured memory_bytes: 1792
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
class ABC96B
{
    public static void Main()
    {
        string[] input = Console.ReadLine().Split(' ');
        List<int> NUM =new  List<int>();
        foreach(string line in input)
        {
            NUM.Add(int.Parse(line));
        }
        NUM.Sort();
        NUM.Reverse();

        int n = int.Parse(Console.ReadLine());
        while (n > 0)
        {
            NUM[0] *= 2;
            n--;
        }
        Console.WriteLine(NUM.Sum());
    }
}

Measured memory_bytes: 13268
#include<bits/stdc++.h> 
#define fo(i,a,b) for(i=a;i<=b;i++)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
typedef long long ll;
using namespace std;
const int maxn=1e6+5;
char s[maxn],t[maxn],now;
int i,j,n,ans,cnt,q[maxn],head,tail;
int main(){
	scanf("%d%s%s",&n,s+1,t+1);
	if(!strcmp(s+1,t+1))return puts("0"),0;
	head=tail=n-1;
	for(int l=n+1,r=n,pl,pr=n;r;r=l-1,pr=pl-1){
        for(;t[l-1]==t[r];l--);
        for(;pr&&(s[pr]!=t[r]||pr>l);pr--);
        if (!pr) return puts("-1"),0;
        for(pl=pr;s[pl-1]==s[pr];pl--);
        pl=max(pl,min(l,pr));
        for(;tail-head&&q[tail-1]-cnt>r;tail--);
       	cnt++,q[--head]=pl+cnt;
        ans=max(ans,tail-head);
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 6144
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

w, h, n = rm()
xleft = 0
xright = w
ytop = h
ybottom = 0
for _ in range(n):
  x, y, a = rm()
  if a == 1:
    xleft = max(xleft, x)
  elif a == 2:
    xright = min(xright, x)
  elif a == 4:
    ytop = min(ytop, y)
  else:
    ybottom = max(ybottom, y)
if xleft >= xright or ybottom >= ytop:
  print(0)
else:
  print((xright-xleft)*(ytop-ybottom))















Measured memory_bytes: 27064
N, M = map(int, input().split())
sc = list(list(map(int, input().split())) for _ in range(M))

def func(N,M,sc):
    ans = [0]*N
    for i in range(M):
        s = sc[i][0]-1
        c = sc[i][1]
        if c == 0:
            c = 'x'
        if ans[s] == 0 or ans[s] == c:
            ans[s] = c
        else:
            return -1
    if N != 1 and ans[0] == 0:
        ans[0] = 1
    for i in range(N):
        if ans[i] == 'x':
            ans[i] = 0
    if N != 1 and ans[0] == 0:
        return -1
    return int(''.join(map(str,ans)))

print(func(N,M,sc))

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

int main(){
    int n;  cin >> n;
    string s;   cin >> s;
    rep(i, s.size()){
        cout << (char)('A' + (s[i] - 'A' + n)%26);
    }
    cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, w;
  cin >> h >> w;
  vector<vector<char>> s(h, vector<char>(w));
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      char tmp;
      cin >> tmp;
      s[i][j] = tmp;
    }
  }
  int di[4] = {+1, 0, -1, 0};
  int dj[4] = {0, +1, 0, -1};
  long long ans = 0;
  vector<vector<bool>> ckd(h, vector<bool>(w, false));
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (ckd[i][j]) {
        continue;
      }
      stack<pair<int, int>> stk;
      int blk = 0;
      int wht = 0;
      stk.push({i, j});
      ckd[i][j] = true;
      while (!stk.empty()) {
        pair<int, int> crr = stk.top();
        char crrc = s[crr.first][crr.second];
        stk.pop();
        if (crrc == '#') {
          blk++;
        } else {
          wht++;
        }
        for (int k = 0; k < 4; k++) {
          int nxti = crr.first + di[k];
          int nxtj = crr.second + dj[k];
          if (nxti < 0 || h <= nxti || nxtj < 0 || w <= nxtj) {
            continue;
          }
          if (!ckd[nxti][nxtj] && crrc != s[nxti][nxtj]) {
            stk.push({nxti, nxtj});
            ckd[nxti][nxtj] = true;
          }
        }
      }
      ans += (long long)blk * wht;
    }
  }
  cout << ans << '\n';
  return 0;
}

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

using namespace std;

typedef long long int lli;

lli i,j,k,l,m,n,t,a,b,c,d,x,y,p,q,sum=0,total=0;

#define read(in) freopen("Input.txt","r",stdin)
#define write(out) freopen("Ouput.txt","w",stdout)

int main()
{
  cin>>t;
  
  lli ar[t]={0};
  
  for(i=1 ; i<t ; i++)
  {
    cin>>x;
    ar[x-1]++;
  }
  for(i=0 ; i<t ; i++)
  {
    cout<<ar[i]<<"\n";
  }
}

Measured memory_bytes: 5196
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
// const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
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; }
////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    ll N; cin >> N;
    vector<ll> A(3),B(3);
    rep(i,3) cin >> A[i];
    rep(i,3) cin >> B[i];

    ll N2 = 0;
    ll p = 0, q = 0, r = 0;
    for (ll i = 0; i*A[0] <= N; i++) {
        for (ll j = 0; j*A[1] <= N - i*A[0]; j++) {
            ll c = 0;
            if (A[2] < B[2]) {
                c = (N-i*A[0]-j*A[1])/A[2];
            }
            if (chmax(N2,N-i*A[0]-j*A[1]-c*A[2]+i*B[0]+j*B[1]+c*B[2])) {
                p = i;
                q = j;
                r = c;
            }
        }
    }

    ll ans = 0;
    if (p+q+r) {
        if (p) {
            for (ll i = 0; i*B[1] <= N2; i++) {
                ll c = 0;
                if (B[2] < A[2]) {
                    c = (N2 - i*B[1])/B[2];
                }
                chmax(ans,N2 - i*B[1] - c*B[2] + i*A[1] + c*A[2]);
            }       
        } else if (q) {
            for (ll i = 0; i*B[0] <= N2; i++) {
                ll c = 0;
                if (B[2] < A[2]) {
                    c = (N2 - i*B[0])/B[2];
                }
                chmax(ans,N2 - i*B[0] - c*B[2] + i*A[0] + c*A[2]);
            }
        } else if (r) {
            for (ll i = 0; i*B[0] <= N2; i++) {
                ll c = 0;
                if (B[1] < A[1]) {
                    c = (N2 - i*B[0])/B[1];
                }
                chmax(ans,N2 - i*B[0] - c*B[1] + i*A[0] + c*A[1]);
            }
        }
    } else {
        for (ll i = 0; i*B[0] <= N; i++) {
            for (ll j = 0; j*B[1] <= N - i*B[0]; j++) {
                ll c = 0;
                if (B[2] < A[2]) {
                    c = (N-i*B[0]-j*B[1])/B[2];
                }
                if (chmax(ans,N-i*B[0]-j*B[1]-c*B[2]+i*A[0]+j*A[1]+c*A[2])) {
                    p = i;
                    q = j;
                    r = c;
                }
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
using namespace std;
int main(int argc, const char * argv[]) {
    int n, m;
    priority_queue<int> a;
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        int input;
        cin >> input;
        a.push(input);
    }
    
    while (m > 0) {
        int top = a.top();
        a.pop();
        a.push(top/2);
        m--;
    }
    
    long sum = 0;
    while (a.size() > 0) {
        sum += a.top();
        a.pop();
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 892
def run(N, A, B):
    sum_AB = {}
    for i in range(N):
        sum_AB[i] = A[i] + B[i]
    sum_AB = sorted(sum_AB.items(), key=lambda x: x[1], reverse=True)
    turn_A = True
    sum_A = 0
    sum_B = 0
    for tmp in sum_AB:
        if turn_A:
            sum_A += A[tmp[0]]
        else:
            sum_B += B[tmp[0]]
        turn_A = not turn_A
    return sum_A - sum_B
    '''
    diff = {}
    for i in range(N):
        diff[i] = A[i] - B[i]
    diff = sorted(diff.items(), key=lambda x: x[1])
    print(diff)
    li = 0
    ri = N - 1
    sum_A = 0
    sum_B = 0
    turn_A = True
    for _ in range(N):
        if -diff[li][1] >= diff[ri][1]:
            if turn_A:
                sum_A += A[li]
            else:
                sum_B += B[li]
            li += 1
        else:
            if turn_A:
                sum_A += A[ri]
            else:
                sum_B += B[ri]
            ri -= 1
        turn_A = not turn_A
    return sum_A - sum_B
    '''


def main():
    N = int(input())
    A = []
    B = []
    for _ in range(N):
        tmp = list(map(int, input().split()))
        A.append(tmp[0])
        B.append(tmp[1])
    print(run(N, A, B))


if __name__ == '__main__':
    main()


Measured memory_bytes: 32076
#pragma GCC optimize("Ofast","inline","-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
//#define int long long
using namespace __gnu_pbds;
using namespace std;

int a[]={0,1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

signed main()
{
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	cout<<a[n]<<endl; 
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
//#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 10000000000000000
#define endl '\n'
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

int n,k;
int a[5001];
bool dp[5001][5001],dp2[5001][5001];

signed main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>n>>k;

    dp[0][0]=true;
    rep(i,n){
        cin>>a[i];
        rep(j,k){
            if(dp[i][j]){
                dp[i+1][j]=true;
                if(j+a[i]<k)dp[i+1][j+a[i]]=true;
            }
        }
    }

    dp2[n][0]=true;
    for(int i=n-1; i>=0; i--){
        rep(j,k){
            if(dp2[i+1][j]){
                dp2[i][j]=true;
                if(j+a[i]<k)dp2[i][j+a[i]]=true;
            }
        }
    }

    int ans=0;
    rep(i,n){
        vector<int> vec(k,k),vec2(k,k);
        int pl=0,pl2=0;
        rep(j,k){
            if(dp[i][j])vec.at(pl++)=j;
            if(dp2[i+1][j])vec2.at(pl2++)=j;
        }
        bool need=false;
        rep(j,vec.size()){
            if(lower_bound(all(vec2),k-vec.at(j))-lower_bound(all(vec2),k-a[i]-vec.at(j)))need=true;
        }
        if(!need)ans++;
    }
    cout<<ans<<endl;

}

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

int main(){
  int m, d;
  int days[]={0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366};

  while(cin>>m>>d){
    if(m==0) break;
    d+=days[m-1];
    d%=7;
    switch(d){
    case 0: printf("Wednesday\n"); break;
    case 1: printf("Thursday\n"); break;
    case 2: printf("Friday\n"); break;
    case 3: printf("Saturday\n"); break;
    case 4: printf("Sunday\n"); break;
    case 5: printf("Monday\n"); break;
    case 6: printf("Tuesday\n");
    }
  }

  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000

int main(){
	
	int N;
	cin>>N;
	
	long long ans = 0LL;
	
	vector<long long> A(N);
	for(int i=0;i<N;i++){
		cin>>A[i];
	}
	
	sort(A.rbegin(),A.rend());
	vector<long long> t;
	for(int i=0;i<A.size();i++){
		for(int j=0;j<2;j++)t.push_back(A[i]);
		if(i==0)t.pop_back();
		if(t.size()>N)break;
	}
	
	for(int i=0;i<N-1;i++)ans += t[i];
	
	cout<<ans<<endl;
		
	return 0;
}


Measured memory_bytes: 6932
/*
	Created by Faisal Ahmed
*/
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long int ll;
typedef long double ld;

int main()
{
	ll n, x;
	map<ll, ll> mp;
	ll arr[200010];
	ll sum = 0;
	
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> x;
		mp[x]++;
		arr[i] = x;
	}
	
//	for(int i = 0; i < n; i++){
//		sum += (mp[arr[i]] * (mp[arr[i]] - 1)) / 2;
//	}

	for(auto it = mp.begin(); it != mp.end(); it++){
		x = it->second;
		sum += (x * (x - 1)) / 2;
	}
	
	//cout << sum << endl;
	
	for(int i = 0; i < n; i++){
		ll x = mp[arr[i]];
		
		ll ans = sum - (x * (x - 1)) / 2;
		x--;
		ans += (x * (x - 1)) / 2;
		
		cout << ans << endl;
	}
	
	
	
	
	return 0;
}

Measured memory_bytes: 11008
#include <bits/stdc++.h>
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

int main() {
	int n; scanf("%d", &n);
	std::vector<int> vec;
	int ans = 0;
	while(n--) {
		int a; scanf("%d", &a);
		
		if(a % 2) vec.push_back(a);
		else ans += a / 2;
	}
	sort(begin(vec), end(vec)); reverse(begin(vec), end(vec));
	for(int i = 0; i < vec.size() - 1; i += 2) ans += (vec[i] + vec[i + 1]) / 2;
	printf("%d\n", ans);
	return 0;
}



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

int main(){
    string S;
    cin >> S;
    int s=S.size();
    int ans=s;
    rep(i,s-1){
        if (S[i]==S[i+1]){
            ans--;
            i+=2;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(a) cout << #a << ": " << a << endl
#define sz(a) int(a.size())
#define rep(i,n) for(int i=0;i<n;i++)
#define forr(i, st, en) for(int i = st; i < en; i++)
#define all(v) (v).begin(),(v).end()
#define fast cin.tie(0); ios::sync_with_stdio(false)
#define int long long
int32_t main(){ fast;
	int k; cin>>k;
	queue<long long> q;
	for(int i =1; i <= 9; i++){
		q.push(i);
	}
	for(int i = 1; i <= k; i++){
		int x = q.front();
		q.pop();
		if(i == k){
			cout<<x<<endl;
			return 0;
		}
		if(x % 10 != 0){
			q.push(10 * x + (x % 10) - 1);
		}
		q.push(10 * x + (x % 10));
		if(x % 10 != 9)
			q.push(10 * x + (x % 10) + 1);
	}
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define INF 1e9
#define EPS 1e-9
#define MOD (1e9+7)
void put(string d){}template<class H,class...T>void put(string d,H&h,T&...t){cout<<h;if(sizeof...(t))cout<<d;put(d,t...);}
template<class T>void puti(T&a,string d=" "){bool f=1;for(auto&_:a)cout<<(exchange(f,0)?"":d)<<_;cout<<endl;}
template<class T>void putii(T&a,string d=" "){for(auto&_:a)puti(_,d);}

int main(){
	int a,b,c,x,y;
	cin>>a>>b>>c>>x>>y;
	int ans=0;
	int ab=a+b, cc=c*2, xy=min(x,y);
	if(cc<ab) ans+=xy*cc;
	else ans+=xy*ab;
	x-=xy,y-=xy;
	if(x!=0){
		ans+=x*min(a,cc);
	}else{
		ans+=y*min(b,cc);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define x1 xxx
#define y1 yyy
#define x2 xx
#define y2 yy
#define pb push_back
#define F first
#define S second
#define P push
#define T top

using namespace std;
const long long MOD=1000000007;
typedef long long ll;

int main(){
   ll a,b;
   cin>>a>>b;
    if(a<=0&&b>=0){cout<<"Zero"; return 0;}
        if(a<0&&a==b){
            cout<<"Negative";
            return 0;
        }
        if(a>0){cout<<"Positive";return 0;}
        if((abs(a)-abs(b))%(ll)2==0&&a<0){
        cout<<"Negative";
            }
    else {cout<<"Positive";return 0;}

      return 0;
}



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

int main(){
	int r, g, b;
	cin >> r >> g >> b;
	r = g*10 + b;
	if(r % 4 == 0) cout << "YES" << endl;
	else cout << "NO" << endl;
	
	return 0;
}

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

using namespace std;

int main() {
  string S;
  cin >> S;
  int len = S.length();
  vector<int> N(len);
  for (int i = 0; i < len; i++) N[i] = S[i] - '0';
  vector<vector<long long>> dp(len + 5, vector<long long>(2));
  dp[0][0] = 0;
  dp[0][1] = 1;
  for (int i = 0; i < len; i++) {
    dp[i + 1][0] = min(dp[i][0] + N[i], dp[i][1] + (10 - N[i]));
    dp[i + 1][1] = min(dp[i][0] + N[i] + 1, dp[i][1] + (10 - N[i] - 1));
  }
  cout << dp[len][0] << endl;

  return 0;
}
/* vim:set fdm=marker: */


Measured memory_bytes: 59780
#include <stdio.h>
#include <stdlib.h>
#define ASC 97
int main(void){
	char s[100009];
	scanf("%s",s);
	//int dist[26][100009];
	int i,j,k;
	int memo[26];
	for(i=0;i<26;i++){
		memo[i]=-1;
		//memo[i][0]=-1;//初期
		//memo[i][1]=0;// i,jのようなもの
		//for(j=0;j<100009;j++){
			//dist[i][j][0]=-100009;//初期
			//dist[i][j][1]=-100009;
		//}
	}
	int moji;
	for(i=0;s[i]!='\0';i++){
		moji=(int)s[i]-ASC;
		if(memo[moji]==-1){
			memo[moji]=i;
		}else{
			//dist[i][ (memo[moji][1]) ][0]=memo[moji]-i+3;//主役文字の数ー脇役文字の数
			//dist[i][ (memo[moji][1]) ][1]=memo[moji][0]+1;//そのdistの出発点si
			if(i-memo[moji]<=2){
				printf("%d %d",memo[moji]+1,i+1);
				return 0;
			}else{
				memo[moji]=i;
			}
			//memo[moji][0]=i;
			//memo[moji][1]+=1;
		}
	}
	/*for(i=0;i<26;i++){
		dist[i][(memo[moji][1])][1]=memo[moji][0]+1;
	}*/
/*
	for(i=0;i<26;i++){
		int dp[100009][2];
		dp[0]=dist[i][0][0];
		if(dp[0]>0){
			printf("%d %d",dist[i][0][1],dist[i][1][1]);
		}
		for(j=1;j<memo[i][1];j++){
			if(dp[j-1]+dist[i][j][0]>dist){
				printf("%d %d",dist[i][j-1])
			}

		}	
	}*/

	printf("-1 -1");
	return 0;
}

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

string S,T;
ll cntS[26],cntT[26];

bool check(){
    rep(i,26)if(cntS[i]!=cntT[i])return false;
    return true;
}

int main(void){
    cin >> S >> T;
    rep(i,S.size()){
        cntS[S[i]-97]++;
        cntT[T[i]-97]++;
    }
    sort(cntS,cntS+26);
    sort(cntT,cntT+26);
    if(check())cout <<"Yes" <<endl;
    else cout <<"No"<<endl;
}


Measured memory_bytes: 776
fun main() {
    val N = readLine()!!.toInt()
    val input = readLine()!!.split(" ").map { it.toLong() }

    if (input.contains(0)) {
        println(0)
        return
    }

    var ans: Long = 1


    for (i in input) {
        if (i <= 1000000000000000000 / ans) {
            ans *= i
        } else {
            println(-1)
            return
        }
    }

    println(ans)
}

Measured memory_bytes: 61608
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

count = 0
for val in range(n):
    
    if a[val] >=  b[val]:
        count += b[val]
        a[val] = a[val] - b[val]
        b[val] = 0
        
    elif a[val] < b[val]:
        count += a[val]
        b[val] = b[val] - a[val]
        
        if a[val+1] >=  b[val]:
            count += b[val]
            a[val+1] = a[val+1] - b[val]
            b[val] = 0
            
        
        elif a[val+1] < b[val]:
            count += a[val + 1]
            a[val+1] = 0
        #print(count)
print(count)

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

int main() {
  int n[3][3];
  for(int i=0; i < 3; i++)
    for(int j=0; j < 3; j++) cin >> n[i][j];
  
  bool b[3][3];
  for(int i=0; i < 3; i++)
    for(int j=0; j < 3; j++) b[i][j] = false;
  int m; cin >> m;
  for(int i=0; i< m; i++) {
    int a; cin >> a;
  for(int i=0; i < 3; i++)
    for(int j=0; j < 3; j++) if(n[i][j] == a) b[i][j] = true;
  }

  bool f = false;
  for(int i=0; i < 3; i++) {
    if(b[i][0] && b[i][1] && b[i][2]) f= true;
    if(b[0][i] && b[1][i] && b[2][i]) f= true;
  }
  if(b[0][0] && b[1][1] && b[2][2]) f= true;
  if(b[2][0] && b[1][1] && b[0][2]) f= true;

  cout << (f ? "Yes" : "No") << endl;
}


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


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

int main() {
    int N;
    cin >> N;
    int d[55];
    REP(i,N) cin >> d[i];
    long long ans = 0;
    REP(i,N){
        for(int j = i+1; j < N;++j){
            ans += d[i] * d[j];
        }
    }
    cout << ans << endl;
}
 

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 100005

enum Type{
	FRONT,
	BACK,
};

struct Info{
	Type face;
	ll diff;
};

int first_N,N;
ll value[NUM];
ll K;
Info table[4*NUM];

void init(){
	while(N < first_N)N *= 2;
}

Type next_face(Type left,Type right){

	if(left == right){

		return FRONT;

	}else{

		return BACK;
	}
}

ll getNUM(ll number){

	return (K-number)%K;
}

void update(int loc,Type face,ll value){

	loc += N-1;

	table[loc].face = face;
	table[loc].diff = value;

	if(N == 1)return;

	int parent = (loc-1)/2;
	int left_child,right_child;

	Type next_type;

	while(true){

		left_child = 2*parent+1;
		right_child = 2*parent+2;

		next_type = next_face(table[left_child].face,table[right_child].face);
		table[parent].face = next_type;

		if(table[left_child].face == FRONT){

			table[parent].diff = table[left_child].diff+table[right_child].diff;

		}else{ //table[left_child].face == BACK

			table[parent].diff = table[left_child].diff-table[right_child].diff;
		}

		table[parent].diff = (table[parent].diff+K)%K;

		if(parent == 0)break;
		else{
			parent = (parent-1)/2;
		}
	}
}

int main(){

	int num_query;
	int root = 0;

	scanf("%lld %d %d",&K,&first_N,&num_query);

	N = 1;
	init();

	for(int i = 0; i <= 2*N-2; i++){
		table[i].face = FRONT;
		table[i].diff = 0;
	}

	ll tmp;
	for(int i = 0; i < first_N; i++){

		scanf("%lld",&tmp);
		value[i] = tmp;

		if(tmp != 0){

			update(i,FRONT,getNUM(tmp));

		}else{

			update(i,BACK,0);
		}
	}

	int L,R;
	ll ans;

	for(int loop = 0; loop < num_query; loop++){

		scanf("%d %d",&L,&R);
		L--;
		R--;

		swap(value[L],value[R]);

		if(value[L] != 0){

			update(L,FRONT,getNUM(value[L]));

		}else{

			update(L,BACK,0);
		}

		if(value[R] != 0){

			update(R,FRONT,getNUM(value[R]));

		}else{

			update(R,BACK,0);
		}

		ans = ((table[root].diff+K)+1)%K;
		if(ans == 0){
			ans = K;
		}

		if(table[root].face == BACK){
			printf("-");
		}
		printf("%lld\n",ans);
	}

	return 0;
}



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

#define F first
#define S second

using namespace std;
typedef long double ld;
typedef long long ll;

const int max_n = 355, max_m = 1000011, inf = 1000111222;
const ll inff = 1000111222333444;

string s;
map<int, ll> mp;

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n;
    cin >> s >> n;
    ll cnt = 0;
    for (int i = 0; i + 1 < s.length(); ++i) {
       cnt += s[i] == s[i + 1];
    }
    if (cnt + 1 == s.length()) {
        cout << (s.length() * 1LL * n / 2) << endl;
        return 0;
    }
    vector<int> v(1, 1);
    for (int i = 1; i < s.length(); ++i) {
        if (s[i] == s[i - 1]) {
            ++v.back();
        } else {
            v.push_back(1);
        }
    }
    int st = 0, fn = v.size();
    if (s[0] == s.back()) {
        ++st;
        mp[v[0]] = 1;
        mp[v.back()] += 1;
        v.back() += v[0];
        mp[v.back()] = -1;
    }
    for (int i = st; i < fn; ++i) {
        mp[v[i]] += n;
    }
    ll ans = 0;
    for (auto a : mp) {
        //cout << a.F << " " << a.S << endl;
        ans += (a.F / 2) * 1LL * a.S;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
H, W, D = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]

d = [None for _ in range(H * W + 1)]
for i in range(H):
    for j in range(W):
        d[A[i][j]] = (i, j)

cumsum = [0 for _ in range(H * W + 1)]
for m in range(1, D + 1):
    i = m
    while i <= H * W:
        if i - D <= 0:
            i += D
            continue
        x1, y1 = d[i - D]
        x2, y2 = d[i]
        dist = abs(x2 - x1) + abs(y2 - y1)
        cumsum[i] = cumsum[i - D] + dist
        i += D

Q = int(input())
LR = [tuple(map(int, input().split())) for _ in range(Q)]
for L, R in LR:
    print(cumsum[R] - cumsum[L])


Measured memory_bytes: 31428
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ld INF = (ld)10000000000000;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
ll calc(ll x) {
	if (x <= 0)return 0;
	ll ret = 0;
	for (int i = 40; i > 0;i--) {
		ll k = (ll)1 << i;
		if (x&k) {
			ll r = (x - k) % 2;
			if (r==0) {
				ret += k;
			}
		}
	}
	return ret;
}
int main() {
	ll a, b; cin >> a >> b;
	ll ans = calc(a - 1) ^ calc(b);
	ll sum = (b + 1) / 2 - a / 2;
	if (sum % 2)ans++;
	cout << ans << endl;
	//stop
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>

int main(){
	int n;
	std::cin >> n;
	std::vector<int> num(n);
	for (int i = 0; i < n; ++i)std::cin >> num[i];
	int cnt = 0;
	for (int i = 0; i < n; ++i){
		for (int j = n - 1; j >= i+1; --j){
			if (num[j] < num[j - 1]){
				std::swap(num[j], num[j - 1]);
				cnt++;
			}
		}
	}
	for (int i = 0; i < n; ++i){
		std::cout << num[i];
		if (i < n - 1)std::cout << ' ';
	}
	std::cout << std::endl;
	std::cout << cnt << std::endl;
	return 0;
}

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

int main(int argc, char *argv[]) {
	int N = 0;
	int T = 0;
	int A = 0;
	std::vector<int> heights;

	std::cin >> N;
	std::cin >> T;
	std::cin >> A;
	double current_h;
	for (int i = 0; i < N; i++) {
		std::cin >> current_h;
		heights.push_back(current_h);
	}

	double min_temp_sub = DBL_MAX;
	double temp_sub = 0;
	double ave_temp = 0;
	int answer = 0;
	for(int j = 0; j < N; j++) {
		//
		//  また、浮動小数点として演算してほしいので、オペランドの
		//  ひとつは必ずdoubleにする。
		//  整数同士で演算してしまうと、結果の値は切り捨てられる
		//
		//  http://www.jpcert.or.jp/sc-rules/c-flp06-c.html
		//
		//  今回の場合は 0.006 が 浮動小数点リテラルなので、そのままで
		//
		ave_temp = T - (heights[j] * 0.006);
		temp_sub = std::abs(A - ave_temp);
		if (temp_sub <= min_temp_sub) {
			min_temp_sub = temp_sub;
			answer = j + 1;
		}
	}

	std::cout << answer << std::endl;
	return 0;
}


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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(condition) if(condition){cout << "POSSIBLE" << endl;}else{cout << "IMPOSSIBLE" << endl;}
#define Possible(condition) if(condition){cout << "Possible" << endl;}else{cout << "Impossible" << endl;}
#define possible(condition) if(condition){cout << "possible" << endl;}else{cout << "impossible" << endl;}
#define Size(n) (n).size()

typedef long long ll;


using namespace std;

const int INF = 1e9,MOD = 1e9 + 7,ohara = 1e6;
const ll LINF = 1e18;


long long int n,cnt=0,ans=0,a,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl=true;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

      
      cin>>n;
      rep(i,n){
        cin>>a;
        ans+=a-1;
      }
      Cout(ans);
     

       
return 0;
}


Measured memory_bytes: 256
from heapq import heappush, heappop
N, M, X = map(int, input().split())
H = [int(input()) for i in range(N)]
G = [[] for i in range(N)]
for i in range(M):
    a, b, t = map(int, input().split()); a -= 1; b -= 1
    if H[a] >= t:
        G[a].append((b, t))
    if H[b] >= t:
        G[b].append((a, t))

INF = 10**18
que = [(-X, 0)]
dist = [INF]*N
dist[0] = -X
while que:
    cost, v = heappop(que)
    if dist[v] < cost:
        continue
    for w, t in G[v]:
        d = max(cost + t, -H[w])
        if d < dist[w]:
            dist[w] = d
            heappush(que, (d, w))
if dist[N-1] == INF:
    print(-1)
else:
    print((X + dist[N-1]) + (H[N-1] + dist[N-1]))



Measured memory_bytes: 86476
import java.util.Scanner;

public class Main {

    static final char ENPTY = '.';
    static final char BOMB = '#';
    static final int[][] SEARCH_AREA = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        char[][] grid = new char[h][w];

        for(int i = 0; i < h; i++){
            grid[i] =  sc.next().toCharArray();
        }

        for (int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                char tgt = grid[i][j];
                if(tgt == ENPTY){
                    int count = 0;
                    for(int k = 0; k < 8; k++){
                        int searchPosX = j + SEARCH_AREA[k][0];
                        int searchPosY = i + SEARCH_AREA[k][1];
                        if( searchPosX >= 0 &&
                                searchPosX < w &&
                                searchPosY >= 0 &&
                                searchPosY < h){
                            if(grid[searchPosY][searchPosX] == BOMB){
                                count++;
                            }
                        }
                    }
                    System.out.print(count);
                }else{
                    System.out.print(BOMB);
                }
            }
            System.out.println("");
        }
        sc.close();
    }

}

Measured memory_bytes: 25812
N, M = map(int, input().split())

A = [0] * N
B = [0] * N
for i in range(N):
    A[i], B[i] = map(int, input().split())

A, B = zip(*sorted(zip(A, B)))

cost = 0
for i in range(N):
    if B[i] > M:
        cost += A[i] * M
        break
    cost += A[i] * B[i]
    M -= B[i]

print(cost)


Measured memory_bytes: 64216
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <sstream>
#include <set>
#include <map>
#define LLMAX 9223372036854775807

using namespace std;
using ll = long long;

int main() {
	ll argN, argL, argT;
	cin >> argN >> argL >> argT;

	vector<ll> argX(argN);
	vector<ll> argW(argN);

	for (ll i = 0; i < argN; ++i) {
		cin >> argX.at(i) >> argW.at(i);
	}

	ll counter = 0;
	for (ll i = 0; i < argN; ++i) {
		if (argW.at(i) == 1) {
			counter -= (argX.at(i) + argT) / argL;
			argX.at(i) = (argX.at(i) + argT) % argL;

		}
		else {
			counter += ((argT - (argX.at(i) + 1)) + argL) / argL;
			argX.at(i) = ((argX.at(i) - argT) % argL + argL) % argL;
		}
	}

	sort(argX.begin(), argX.end());
	vector<ll> res(argN);
	counter = (counter % argN + argN) % argN;
	for (ll i = 0; i < argN; ++i) {
	    res.at((i + counter) % argN) = argX.at(i);
	}
	
	for (ll i = 0; i < argN; ++i) {
		cout << res.at(i) << endl;
	}
}

Measured memory_bytes: 3584
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>

using namespace std;

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

	string s;
	cin >> s;

	int l = s.length();

	for (int i = l - 1; i > 0; i--) {
		if (i % 2 == 0) {
			int v = i / 2;
			for (int j = 0; j < v; j++) {
				if (s[j] != s[j + v])  goto LABEL;
			}
			cout << i << endl;
			return 0;
		    LABEL:
			;
		}
	}
	cout << 1 << endl;
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <deque>
#include <queue>
#include <set>
#include <functional>
#include <cmath>


//マクロ
/*動かない・・・
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define REP(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _roverload3(_1,_2,_3,name,...) name
#define _rrep(i,n) repi(i,0,n)
#define rrepi(i,a,b) for(int i=int(a);i<int(b);++i)
#define RREP(...) _roverload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
//*/
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define REPS(i,n) for(int i=1; i<=(int)(n); ++i)
#define RREP(i,n) for(int i=(int)(n)-1; i>=0; --i)
#define RREPS(i,n) for(int i=(int)(n); i>0; --i)
#define FOR(i,s,e) for(int i=(int)(s); i<(int)(e); ++i)
#define RFOR(i,s,e) for(int i=(int)(e)-1; i>=(int)(s); --i)
//*/
#define All(a) (a).begin(),(a).end()
#define dump(x)  cerr << #x << " = " << (x) << endl;

//定数
#define INF 1e9
#define MOD (int)(1e9+7)

typedef long long ll;
typedef unsigned long long ull;
/*
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
//*/
using namespace std;
using Graph = vector<vector<int>>;

//とりあえず書いておく変数
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

//今回の変数
int n,k;
vector<int> h;

//使用する関数
template<class T>bool chmax(T &a, const T &b) {
	if (a < b) { a = b; return 1; }
	return 0;
}
template<class T>bool chmin(T &a, const T &b) {
	if (a > b) { a = b; return 1; }
	return 0;
}

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

	cin >> n >> k;
	REP(i, n) {
		int a;
		cin >> a;
		h.push_back(a);
	}
	sort(All(h));
	ll ans = 0;
	REP(i, n - k) {
		ans += h[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 1400
#pragma warning(disable:4996)
//#define _CRT_NONSTDC_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <cassert>
#include <cstdlib>
#include <ctype.h>
#include <limits.h>
#include <stdio.h>
#include <math.h>
#include <bitset>
#include <fstream>
#include <numeric>
#include <sstream>
#include <algorithm>
#include <string>
#include <cstring>
#include <iomanip>
#include <unordered_map>
#include <ctime>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <deque>
 
 
using namespace std;
typedef long long ll;
typedef long double ld;
                        
#define all(x)   (x).begin(), (x).end()           /*sorting STL */
#define fastio	 ios_base::sync_with_stdio(0);  cin.tie(nullptr);  cout.tie(nullptr)
 
#define TRIPmin(a, b, c) 	min(a, min(b, c))
#define TRIPmax(a, b, c)    max(a, max(b, c))
#define fillchar(a,x) 		memset(a, x, sizeof (a))
 
#define MOD		(ll)(1e9 + 7)
 
/***********************************************************************/

int main() {
    ll n, x, t;
    cin >> n >> x >> t;
    ll ans = 0;
    while(n > 0) {
        n -= x;
        ans += t;
    }
    cout << ans;
    return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int N = 111111;
const ll mod = 1000000007;

ll fac[N], ifac[N], inv[N];
void pre(){
	fac[0] = ifac[0] = fac[1] = ifac[1] = inv[1] = 1;
	for(int i = 2; i < N; i++){
		fac[i] = (i*fac[i - 1])%mod;
		inv[i] = (mod - mod/i)*inv[mod%i]%mod;
		ifac[i] = ifac[i - 1]*inv[i]%mod;
	}
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	pre();
	int n, m;
	cin>>n>>m;
	ll ans = 1;
	for(int i = 2; i*i <= m; i++){
		if(m%i)continue;
		int cnt = 0;
		while(m%i == 0){
			m /= i;
			cnt++;
		}
		(ans *= fac[n + cnt - 1]) %= mod;
		(ans *= ifac[n - 1]) %= mod;
		(ans *= ifac[cnt]) %= mod;
	}
	if(m > 1){
		(ans *= n) %= mod;
	}
	cout<<ans<<'\n';

	return 0;
}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
#define int long long
//#define double long double
#define endre getchar();getchar();return 0
#define moder (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1)*x;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x%mod;
		}
		x = x * x%mod;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	return kai(x)*mod_pow(kai(x - y), moder - 2, moder) % moder*mod_pow(kai(y), moder - 2, moder) % moder;
}
/*--------Library Zone!--------*/


signed main() {
	string s;
	cin >> s;
	if (s.size() == 1) {
		cout << s << endl;
		endre;
	}
	REP(i, s.size()) {
		if (s[i] != '9')goto no;
	}
	cout << (s.size() - 1) * 9 + stoi(s.substr(0, 1)) << endl;
	endre;
no:;
	cout << 9 * (s.size() - 1) + stoi(s.substr(0, 1)) - 1 << endl;
	endre;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline
import math

# 素因数分解、辞書で返すやつ
# mathをimportする
def prime(n):
    factor = {}
    tmp = int(math.sqrt(n)) + 1
    for num in range(2, tmp):
        while n % num == 0:
            n //= num
            if not num in factor.keys():
                factor[num] = 1
            else:
                factor[num] += 1
        if num > n:
            break
    if n != 1:
        if not n in factor.keys():
            factor[n] = 1
        else:
            factor[n] += 1
    return factor

# (x, y) of ax + by = 1
def oneOfSolution(a, b):
    if b == 1:
        return 0, 1
    d = a//b
    p, q = oneOfSolution(b, a%b)
    return q, p-d*q

def solution(a, b):
    if b > a:
        y0, x0 = oneOfSolution(b, a)
    else:
        x0, y0 = oneOfSolution(a, b)
    x = x0%b
    if a*x < 2:
        x += b
    return a*x-1

N = int(input())

if N == 1:
    ans = 1
else:
    N_prime = prime(N)
    W = []
    for num, cnt in N_prime.items():
        if num == 2:
            W.append(num**(cnt+1))
        else:
            W.append(num**cnt)

    M = len(W)
    ans = N
    for bit in range(1<<M):
        a = 1; b = 1
        for i, m in enumerate(W):
            if bit&(1<<i):
                a *= m
            else:
                b *= m
        ans = min(ans, solution(a, b))

print(ans)

Measured memory_bytes: 81260
N=int(input())
A=list(map(int,input().split()))

check=1
for i in range(N):
    if A[i]%2==0:
        if A[i]%3==0 or A[i]%5==0:
            pass
        else:
            check=0
            break

if check==1:
    print('APPROVED')
else:
    print('DENIED')


Measured memory_bytes: 2940