akhauriyash/Code-Regression huggingface dataset:
/*
ID: computerbox --> Huseyn Hajiyev
LANG: C++
TASK: target_mode_on
*/
#include <bits/stdc++.h>
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#define _CRT_SECURE_NO_WARNINGS
//#include <boost/multiprecision/cpp_int.hpp>
//using boost::multiprecision::cpp_int;
#define FAST_READ ios_base::sync_with_stdio(0);
#define in freopen("input.txt", "r", stdin);
#define out freopen("output.txt", "w", stdout);
#define ll long long
#define debt(x,y)cout<<"#x = "<<(x)<<" and "<<"#y = "<<(y)<<endl;
#define deb(x)cout<<"#x = "<<(x)<<endl;
#define COUT(n, a) cout<< fixed << setprecision(a) << n<<endl
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define arr(a,n) for(ll i=1;i<=n;i++) cout<<a[i]<<" "; cout << "\n";
#define vecc(a,n) for(ll i=0;i<n;i++) cout<<a[i]<<" "; cout << "\n";
#define CURTIME() cerr << clock() * 1.0 / CLOCKS_PER_SEC << endl
#define DTIME(ccc) __begin = clock(); ccc; cerr<<"Time of work = "<<(clock()-__begin)/CLOCKS_PER_SEC<<endl;
#define MAXN 2000
//cin.ignore (7777, '\n');

using namespace std;

#define debug(args...)(Debugger()) , args
class Debugger
{
  public:
  Debugger(const std::string& _separator=", ") :
  first(true),separator(_separator){}
  template<typename ObjectType>
  Debugger& operator,(const ObjectType& v)
  {
        if(!first)cerr<<separator;
        cerr<<v;
        first=false;
        return *this;
  }
  ~Debugger() {cerr<<endl;}      
  private:
    bool first;
    string separator;
};
 
template <typename T1, typename T2>
inline ostream& operator<<(std::ostream& os, const std::pair<T1, T2>& p)
{
   return os<<"("<<p.first<<", "<<p.second<<")";
}
template<typename T>
inline ostream &operator<<(ostream & os,const vector<T>& v)
{
    bool first=true;
    os<<"[";
    for(unsigned ll i=0;i<v.size();i++)
    {
        if(!first)os<<", ";
        os<<v[i];
        first=false;
    }
        return os<<"]";
}
template<typename T>
inline ostream &operator<<(ostream & os,const set<T>&v)
{
    bool first=true;
    os<<"[";
    for(typename set<T>::const_iterator ii=v.begin();ii!=v.end();++ii)
    {
        if(!first)os<<", ";
        os<<*ii;
        first=false;
    }
    return os<<"]";
}
template<typename T1, typename T2>
inline ostream &operator<<(ostream & os,const map<T1, T2>&v)
{
        bool first=true;
        os<<"[";
        for(typename map<T1,T2>::const_iterator ii=v.begin(); ii!=v.end();++ii)
        {
            if(!first)os<<", ";
            os<<*ii;
            first=false;
        }
        return os<<"]";
}

ll a,b;
int main(){
FAST_READ;
//cin.tie(0);
cin>>a>>b;
if(a*b%2!=0)cout<<"Yes"<<endl;
else if(a*b*2%2!=0)cout<<"Yes"<<endl;
else if(a*b*3%2!=0)cout<<"Yes"<<endl;
else cout<<"No"<<endl;








return 0;
} 


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--)
#define ITER(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;

const int MOD = 1000 * 1000 * 1000 + 7;
const double EPS = 1e-7;


const int MAX = 1000 + 7;

char S[MAX][MAX];

int main()
{
    int n, m, a, b;
    scanf("%d%d%d%d", &n, &m, &a, &b);
    
    FOR(i, 0, n)
        FOR(j, 0, m)
            S[i][j] = '.';
    
    if (m & 1)
    {
        FOR(i, 0, n - 1)
        {
            if (i & 1)continue;
            if (!b)break;
            S[i][0] = '^';
            S[i+1][0] = 'v';
            --b;
        }
    }
    
    
    if ((b & 1) && (n & 1))
    {
        if (n >= 2 && m >= 3)
        {
            S[n-2][2] = '^';
            S[n-1][2] = 'v';
            --b;
        }
    }
    
    FOR(i, 0, n-1)
        RFOR(j, m, 0)
        {
            if (!b)break;
            if (S[i][j] == '.' && S[i+1][j] == '.')
            {
                S[i][j] = '^';
                S[i+1][j] = 'v';
                --b;
            }
        }
    
    FOR(i, 0, n)
        RFOR(j, m-1, 0)
        {
            if (!a)continue;
            if (S[i][j] == '.' && S[i][j+1] == '.')
            {
                S[i][j] = '<';
                S[i][j+1] = '>';
                --a;
            }
        }
    

    if (a || b)
    {
        printf("NO\n");
        return 0;
    }
    
    printf("YES\n");
    FOR(i, 0, n)
    {
        FOR(j, 0, m)printf("%c", S[i][j]);
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2176
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        int H = sc.nextInt();
        int W = sc.nextInt();
        int A = sc.nextInt();
        int B = sc.nextInt();

        if (W < 2 * A || H < 2 * B) {
            System.out.println(-1);
            return;
        }

        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                if ((i < B && j < A) || (i >= B) && (j >= A)) bw.write("0");
                else bw.write("1");
            }
            bw.newLine();
        }

        bw.flush();
    }
}

Measured memory_bytes: 24152
#include <iostream>
#include <cstdio>
using namespace std;
typedef long long ll;

int calcFloat(double fl, ll n) {
    int sum = 0;
    for(int r = 1; r <= n; r++) {
        sum += (int)(fl*10);
        fl *= 10;
        //整数部分を取り除く
        int temp = fl;
        fl -= temp;
    }
    return(sum);
}

int main(void) {
    int a, b, n;
    while(cin >> a >> b >> n) {
        /*
        double div = a / (double)b;
        int temp = div;
        div -= temp;
        cout << calcFloat(div, n) << endl;
         */
        a %= b;
        int ans = 0;
        for(int r = 1; r <= n; r++) {
            a *= 10;
            ans += a / b;
            a %= b;
        }
        cout << ans << endl;
    }
    return(0);
}

Measured memory_bytes: 1160
# -*- coding: utf-8 -*-
# 整数の入力
n = int(input()) # Skip first line
b = list(map(int,input().split()))
s = b[0]
for i in range(1,n-1):
    s = s + min(b[i-1],b[i])
s = s + b[n-2]
print(s)

exit(0)

Measured memory_bytes: 3060
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll a, b, d, r;
    double f;
    cin >> a >> b;
    d = a / b;
    r = a % b;
    f = (double)a / (double)b;
    printf("%d %d %.5f\n", d, r, f);
}


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


int main() {
  int n;
  ll d;
  cin >> n >> d;
  int ans = 0;
  for(int i = 0; i < n; i++){
    ll a,b;
    cin >> a >> b;
    if((a*a)  + (b*b) <= d*d){
      ans++;
    }
  }
  cout << ans << endl;

}



Measured memory_bytes: 3576
import numpy as np
import sys
import math

pi = 3.1415926535897923

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

sh1 = 360 * ( (H*60 + M) % 720 ) / 720
sh2 = 360 * ( M % 60 ) / 60
sh = min(abs(sh1-sh2) , 360 - abs(sh1-sh2))

print(math.sqrt( A ** 2 + B ** 2 - 2 * A * B * math.cos( ( sh * pi) / 180 )  ) )

Measured memory_bytes: 27220
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
#include <sstream>
using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;

template <class T>
void initvv(vector<vector<T> > &v,int a,int b, const T  &t = T()){
	v.assign(a,vector<T>(b,t));
}

//v.erase(unique(v.begin(),v.end()),v.end());

int main(){
	string s;
	while(cin>>s){
		int ans=0;
		if(s.size()<=2){
			cout<<0<<endl<<0<<endl;
			continue;
		}
		rep(i,s.size()-2){
			if("JOI"==s.substr(i,3)){
				ans++;
			}
		}
		cout<<ans<<endl;
		ans=0;
		rep(i,s.size()-2){
			if("IOI"==s.substr(i,3)){
				ans++;
			}
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
#define int long long
#define ll long long 
#define rep(i,a,b) for(signed i=a;i<(b);++i)
#define erep(i,a,b) for(signed i=a;i<=(b);++i)
#define per(i,a,b) for(signed i=(a);i>(b);--i)
#define eper(i,a,b) for(signed i=(a);i>=b;--i)
#define fore(i, x, a) for(auto &&x:a) 
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define pb emplace_back
#define mp make_pair
#define ALL(x) begin(x),end(x)
#define F first
#define S second
#define debug(x)  cout << #x << ": " << (x) << '\n';
const long long INF=1001001001001001001;
const int MOD=(int)1e9 + 7;
const double EPS=1e-9;
using namespace std;
using Pii = pair<int,int>;
using vii = vector<int>;
template<class T>using  PS_queue = priority_queue<T, vector<T>, greater<T> >;
template<class T>using vv = vector<T>;
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 (b<a) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill( (T*)array, (T*)(array+N), val );}
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> ostream& operator<<(ostream &os,const vector<vector<T> > &v) {
    ITR(u,begin(v),end(v))ITR(w,begin(*u),end(*u))os<<*w<<(w==end(*u)-1?"\n":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct edge { int from, to, cost; };
int dy[]={0, 1, -1, 0}; int dx[]={1, 0, 0, -1};
// cout << fixed << setprecision(10) << val;

string s;
// i番目で13で割ったあまりがjになる場合の数をMODで割ったあまり
int dp[100005][13];
signed main() {
 cin.tie(0);
 ios::sync_with_stdio(false);
  cin >> s;
  int n = (int)s.size();

  dp[0][0] = 1;
  rep(i, 0, n) {
    int d = (s[i] == '?' ? -1 : s[i] - '0');
    rep(j, 0, 10) {
      if (d != -1 && j != d) continue;
      rep(k, 0, 13) {
        dp[i+1][(k*10+j)%13] += dp[i][k];
        dp[i+1][(k*10+j)%13] %= MOD;
      }
    }
  }
  cout << dp[n][5] << endl;
  return 0;
}




Measured memory_bytes: 10704
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long LL;
template <typename F, typename S> std::ostream& operator<<(ostream& os, const pair<F,S>& p) {
    os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for(const T& a: v){ os << a << ", "; } os << "]"; return os; }
template <typename K, typename V> ostream& operator<<(ostream& os, const map<K,V>& m) {
    os << "{"; for(const auto& p: m){ os << p.first <<":"<< p.second << ", "; } os << "}"; return os; }


int main(){
    LL n, m;
    cin >> n >> m;
    vector<vector<LL>> path(n);
    for(LL i = 0; i < m; ++i){
        LL s, t;
        cin >> s >> t;
        --s; --t;
        path[s].push_back(t);
    }
    vector<double> pass_prob(n);
    vector<double> exp_cost(n);
    pass_prob[0] = 1.;
    for(LL i = 0; i < n; ++i){
        for(LL t: path[i]){
            pass_prob[t] += pass_prob[i] / path[i].size();
        }
    }
    for(LL i = n-2; i >= 0; --i){
        for(LL t: path[i]){
            exp_cost[i] += (exp_cost[t] + 1.) / path[i].size();
        }
    }

    double ans = exp_cost[0];
    for(LL i = 0; i < n; ++i){
        for(LL t: path[i]){
            if(path[i].size() <= 1) continue;
            double gain = exp_cost[i] - (exp_cost[i]*path[i].size() - (exp_cost[t] + 1.)) / (path[i].size()-1);
            ans = min(ans, exp_cost[0] - gain * pass_prob[i]);
        }
    }
    cout << setprecision(13) << ans << endl;
    return 0;
}



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

int main(){
    ll h; cin >> h;
    ll n = 1;
    ll ans = 0;
    while(h > 1){
        h /= 2;
        ans += n;
        n *= 2;
    }
    ans += n;
    cout << ans << endl;
}

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

int main()
{
	string s;
	cin >> s;
	int cnt = 0;
	for (int i = 0; i < 3; i++)
	{
		if (i == 0)
		{
			if (s[i] == 'R')
				cnt++;
		}
		else
		{
			if (s[i - 1] == 'R' and s[i] == 'R')
				cnt++;
			else if (s[i] == 'R')
				cnt = 1;
		}
	}
	cout << cnt << endl;
}


Measured memory_bytes: 3596
#!/usr/bin/perl
use Data::Dumper;

my ($X,$Y,$A,$B,$C) = map { $_ - 0 } split(/\s+/,<STDIN>);
my @p = map { $_ - 0 } split(/\s+/,<STDIN>);
my @q = map { $_ - 0 } split(/\s+/,<STDIN>);
my @r = map { $_ - 0 } split(/\s+/,<STDIN>);

my @p2 = map { +[ $_ , 'r' ] } @p;
my @q2 = map { +[ $_ , 'g' ] } @q;
my @r2 = map { +[ $_ , 'w' ] } @r;

my @all = sort { $b->[0] <=> $a->[0] } ( @p2 ,@q2, @r2 );

my %c = ('r'=>0, 'g'=>0, 'w'=>0);
my $tot = 0;
for(my $i=0;$i<=$#all;$i++){
  $tot += $all[$i]->[0];
  $c{$all[$i]->[1]} ++;
  next if $i < $X + $Y - 1;
  my $cc_r = $c{'r'};
  my $cc_g = $c{'g'};
  my $cc_w = $c{'w'};
  my $cx_r = 0;
  my $cx_g = 0;
  if( $cc_r < $X ){
    $cx_r = $X - $cc_r;
    $cc_w -= $cx_r;
  }
  next if $cc_w < 0;
  if( $cc_g < $Y ){
    $cx_g = $Y - $cc_g;
    $cc_w -= $cx_g;
  }
  next if $cc_w < 0;
  my $cx_rg = $cx_r + $cx_g;
  my $res = 0;
  $cc_r = $X if( $cc_r > $X );
  $cc_g = $Y if( $cc_g > $Y );
  for(my $j=0;$j<=$i;$j++){
    if( $all[$j]->[1] eq 'r' and $cc_r > 0 ){
      $res += $all[$j]->[0];
      $cc_r --;
    }
    if( $all[$j]->[1] eq 'g' and $cc_g > 0 ){
      $res += $all[$j]->[0];
      $cc_g --;
    }
    if( $all[$j]->[1] eq 'w' and $cx_rg > 0 ){
      $res += $all[$j]->[0];
      $cx_rg --;
    }
  }
  print "$res\n";
  exit(0);
}



Measured memory_bytes: 98072
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
int main() {
    int h, w;
    cin >> h >> w;
    vector<vector<int>> c(10, vector<int>(10, 0));
    for(int i = 0; i < 10; i++) {
        for(int j = 0; j < 10; j++) {
            cin >> c[i][j];
        }
    }
    for(int i = 0; i < 10; i++) {         // 経由する頂点
        for(int j = 0; j < 10; j++) {     // 開始頂点
            for(int k = 0; k < 10; k++) { // 終端
                c[j][k] = min(c[j][k], c[j][i] + c[i][k]);
            }
        }
    }
    ll ans = 0;
    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            int a;
            cin >> a;
            if(a != -1) {
                ans += c[a][1];
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);
		char[] o = sc.next().toCharArray();
		int l = o.length;
		long ans = 0L;
		for(int i = 0; i < 1<<(l-1); i++) {
			String p = Integer.toBinaryString(i);
			while(p.length() < l-1) {
				p = "0"+p;
			}
			char[] pp = p.toCharArray();
			char[] chars = new char[l*2-1];
			for(int j = 0; j < chars.length; j++) {
				if(j%2==0) chars[j]=o[j/2];
				else  {
					chars[j]=pp[(j-1)/2];
					if(chars[j]=='1') {
						chars[j]='p';
					}
				}
			}
			String[] nums = new String(chars).replaceAll("0", "").split("p");
			ans += Arrays.stream(nums).mapToLong(Long::parseLong).sum();
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 28244
#include<iostream>
#include<string>
#include<iomanip>

using namespace std;

int main(){
  int N; cin >> N;  double sum = 0;
  for(int i = 0; i < N; i++){
    double a; cin >> a; string s; cin >> s;
    if( s == "JPY"){ sum += a;}
    else{ sum += a * 380000.0;}}
  
  cout << setprecision(6) << sum << endl;
  
  return 0;
}

Measured memory_bytes: 256
K, A, B = map(int, input().split())

if (B - A) < 3:
	print(K + 1)
	exit()

if K - 1 < A:
	print(K + 1)
	exit()

swap = K - (A - 1)
print(A + (B - A) * (swap // 2) + swap % 2)


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

using namespace std;

typedef long long ll;
typedef vector<int> pi;
typedef pair<int,int> vi;

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(vi c, vi d){
	return c.S < d.S;
}

int main() {
	string s;
	map<char, int> m;
	cin >> s;
	for(char x: s){
		if(m.find(x) != m.end() ) ++m[x];
		else m[x] = 1;
	}
	for (auto const& x: m){
		if(x.second % 2 == 1){
			cout << "No";
			exit(0);
		}
	}
	cout << "Yes";
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main () {
  string A, B;
  cin >> A >> B;
  int a, b;
  cin >> a >> b;
  string d;
  cin >> d;
  if (d == A) a --;
  else b --;
  cout << a << ' ' << b << endl;
}


Measured memory_bytes: 256
//************************
//*  Date: 2018.11.25    *
//*  Problem:            *
//*  Author: xuziyuan    * 
//************************

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++)
#define LL long long
#define pii pair <int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

int n,a[110],sum=0,ans;

inline pii yuefen(pii a)
{
	int p=__gcd(a.fi,a.se);
	return {a.fi/p,a.se/p};
}

inline pii minu(pii a,pii b)
{
	int aa=a.se,bb=b.se;
	a.fi*=bb;
	b.fi*=aa;
	a.se*=bb;
	b.se*=aa;
	return yuefen({abs(max(a.fi,b.fi)-min(a.fi,b.fi)),a.se});
}

inline bool sm(pii sma,pii bi)
{
	return (sma.fi*bi.se)<(bi.fi*sma.se);
}

int main()
{
	cin>>n;
	rep(i,n) cin>>a[i],sum+=a[i];
	pii av=yuefen({sum,n});
	pii mn={1e7,1};
	//cout<<av.fi<<'/'<<av.se<<endl<<endl;
	rep(i,n)
	{
		pii res=minu(av,{a[i],1});
		//cout<<res.fi<<'/'<<res.se<<endl;
		if(sm(res,mn))
		{
			//cout<<'p';
			mn=res;
			ans=i;
		}
	}
	cout<<ans<<endl;
	rt0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int arr[n];
    long long int mn[n];
    for(int i=0;i<n;i++){
        cin>>arr[i];
        mn[i]=100000;
    }
    if(n==1)
        return 0;
    mn[n-1]=0;
    for(int i=n-1;i>=0;i--)
    {
        int first=i+1;
        int second = i+2;
        if(first<n)
        {
            int diff = arr[i]-arr[first];
            if(diff<0)
                diff*=-1;
            mn[i]=diff+mn[first];
        }
        if(second<n)
        {
            int diff = arr[i]-arr[second];
            if(diff<0)
                diff*=-1;
            mn[i]=min(mn[i],diff+mn[second]);
        }
    }
    cout<<mn[0]<<endl;
}


Measured memory_bytes: 1408
n = int(input())
s = input()
cnt = 0
for i in range(10):
    a = s.find(str(i))
    if a == -1:
        continue
    for j in range(10):
        b = s.find(str(j),a+1)
        if b == -1:
            continue        
        for k in range(10):
            if str(k) in s[b+1::]:
                cnt += 1
print(cnt)

Measured memory_bytes: 3060
lines = []
while line = gets
    lines << line.chomp.split(' ').map(&:to_i)
end

N = lines[0][0]

access = []
for i in 1..N do
  access[i-1] = []
end
for i in 1..N-1 do
  from = lines[i][0]
  to = lines[i][1]
  access[from-1].push(to)
  access[to-1].push(from)
end

c = lines[N].sort.reverse

visited = []
for i in 1..N do
  visited[i-1] = false
end

target = [1]
ans = []
num = 0
while target != [] do
  i = target.shift
  visited[i-1] = true
  ans[i-1] = c[num]
  num += 1
  access[i-1].each do |j|
    if visited[j-1] == false then
      target.push(j)
    end
  end
end
  
num_ans = 0
for i in 1..N-1 do
  num_ans += c[i]
end
  
puts num_ans
for i in 1..N do
  print ans[i-1]
  if i != N then
    print " "
  end
end


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

namespace AOJ
{
  class Board
  {
    public int Edge1 { get; private set; }
    public int Edge2 { get; private set; }
    public int Diagonal { get; private set; }
    public Board(int edge1, int edge2, int diagonal)
    {
      Edge1 = edge1;
      Edge2 = edge2;
      Diagonal = diagonal;
    }
  }

  class Problem0032
  {
    static void Main()
    {
      var boards = new List<Board>();
      string line;
      while (!string.IsNullOrEmpty(line = Console.ReadLine()))
      {
        var sp = line.Split(',');
        if (sp.Any(s => string.IsNullOrEmpty(s)))
          return;
        var parsed = sp.Select(s => int.Parse(s)).ToArray();
        boards.Add(new Board(parsed[0], parsed[1], parsed[2]));
      }
      Console.WriteLine(boards.Where(b => IsRectangle(b)).Count());
      Console.WriteLine(boards.Where(b => IsRhombus(b)).Count());
    }

    static bool IsRectangle(Board board)
    {
      return Math.Pow(board.Edge1, 2.0) + Math.Pow(board.Edge2, 2.0) == Math.Pow(board.Diagonal, 2.0);
    }

    static bool IsRhombus(Board board)
    {
      return board.Edge1 == board.Edge2;
    }
  }
}

Measured memory_bytes: 6032
<?php
const INPUT_DELIMITER = " ";
$input = fgets(STDIN);
list($N, $D) = array_map('intval', explode(INPUT_DELIMITER, $input));

$points = [];
for ($i = 0; $i < $N; $i++) {
    $input = fgets(STDIN);
    $points[] = array_map('intval', explode(INPUT_DELIMITER, $input));
}

// 愚直に計算してみる
$count = 0;
foreach ($points as $index => $point) {
    if ($index+1 == count($points)) {
        break;
    }
    for ($i = $index+1; $i < count($points); $i++) {
        $powSum = 0;
        for ($j = 0; $j < $D; $j++) {
            $powSum += pow($point[$j] - $points[$i][$j], 2);
        }
        $diff = sqrt($powSum) - floor(sqrt($powSum));
        if ($diff == 0) {
            $count++;
        }
    }
}
echo $count;

Measured memory_bytes: 3828
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <set>
#include <cmath>
#include <map>


int main(int,char**){
	typedef std::map<short,unsigned long long> Data;
	
	int n;
	while(std::cin>>n){
		if(!n) break;
		bool ex(0);
		Data tbl;
		std::vector<int> seq;
		while(n--){
			int Cnum,at,num;
			std::cin >>Cnum>>at>>num;
			if(tbl[Cnum]==0) seq.push_back(Cnum);
			tbl[Cnum]+=at*num;
		}
		for(std::vector<int>::const_iterator it=seq.begin();it!=seq.end();++it){
			if(tbl[*it]>=1000000){ std::cout<< *it << std::endl; ex=1;}
		}
		if(!ex) std::cout << "NA"<<std::endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
ll gcl(ll a,ll b){
  if(a%b==0){
    return b;
  }
  else{
    return gcl(b,a%b);
  }
}

int main() {
  
  ll a;
  cin>>a;
  vector<ll>vec(a);
  for(ll i=0;i<a;i++){
    cin>>vec.at(i);
  }
  sort(vec.begin(),vec.end());
  ll b=vec.at(0);
  for(ll i=0;i<a;i++){
    b=gcl(vec.at(i),b);
    if(b==1){
      cout<<b<<endl;
      return 0;
    }
  }
  cout<<b<<endl;
  return 0;
}
                             
    


Measured memory_bytes: 4024
h,w,q=map(int,input().split())
c2=[input() for _ in range(h) ]
ans=0
for i in range(1<<w):#縦
  for j in range(1<<h):#横
    b=0
    for x in range(w):#ビット
      for y in range(h):
        if (i>>x &1)==0 and (j>>y &1)==0 and c2[y-1][x-1]=="#":
          b+=1   
    if b==q:
      ans+=1
print(ans)

Measured memory_bytes: 9144
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int MAX = 1e6+2;

int main(){
	int n;
	cin >> n;
	
	vector<int> nf(MAX, 0);
	for(int i=0; i<n; i++){
		int a,b;
		cin >> a >> b;
		nf[a]++;
		nf[b+1]--;
	}
	
	int ans=0;
	for(int i=2; i<MAX; i++){
		nf[i] += nf[i-1];
		if(nf[i]+1>=i) ans=i-1;
	}
	cout << ans << endl;
	return 0;
}

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

struct Ps{
  int r,c;
  Ps():r(0),c(0){}
  Ps(int r,int c):r(r),c(c){}
  Ps operator+(const Ps&p)const
  { return Ps(r+p.r,c+p.c);  }
  friend istream& operator>>(istream&is,Ps&p)
  {is >> p.r >> p.c; return is;  }
};

int main(){
  int h,w; cin >> h >> w;
  Ps s,g; cin >> s >> g;
  s = s+Ps(-1,-1);
  g = g+Ps(-1,-1);
  bitset<1000> mz[1000];
  for(int i = 0; i < h; ++i)for(int j = 0; j < w; ++j)
      mz[i][j] = []{char c; cin >> c; return c;}() == '.';
  optional<int> distance[1000][1000];
  deque<pair<Ps,int>> dq;
  dq.emplace_front(s,0);
  while(!dq.empty()){
    auto [ps,di] = dq.front();
    dq.pop_front();
    if(distance[ps.r][ps.c])continue;
    distance[ps.r][ps.c] = di;
    if(ps.r==g.r && ps.c==g.c)break;
    static int mr[] = {0,0,1,-1};
    static int mc[] = {1,-1,0,0};
    for(int i = 0; i < 4; ++i){
      Ps nps = ps + Ps(mr[i],mc[i]);
      if(nps.r < 0 || nps.c < 0 || nps.r >= h || nps.c >= w)continue;
      if(!mz[nps.r][nps.c])continue;
      if(distance[nps.r][nps.c])continue;
      dq.emplace_front(nps,di);      
    }
    for(int i = -2; i <= 2; ++i){
      for(int j = -2; j <= 2; ++j){
	Ps nps = ps + Ps(i,j);

	if(nps.r < 0 || nps.c < 0 || nps.r >= h || nps.c >= w)continue;
	if(!mz[nps.r][nps.c])continue;
	if(distance[nps.r][nps.c])continue;
	dq.emplace_back(nps,di+1);
      }
    }
  }
  cout << (distance[g.r][g.c] ? distance[g.r][g.c].value() : -1) << endl;
}


Measured memory_bytes: 12360
import java.io.*;
import java.math.*;
import java.util.*;
public class Main {

	public static void main(String[] args) { 
		Scanner input = new Scanner(System.in);
		int N = input.nextInt();
		int M = input.nextInt();
		boolean[] diff = new boolean[N]; //N not possible as max gap = N-1; N/2 is bad for even
		boolean[] used = new boolean[N+1];
		int bad = -1;
		if (N%2==0) bad=N/2;
		System.out.println(1+" "+N);
		diff[1]=true;
		diff[N-1]=true;
		used[1]=true;
		used[N]=true;
		M--;
		int START = 2;
		while (M>0) {
			for (int d = N-1; d>=1; d--) {
				int diff1 = d;
				int diff2 = N-d;
				int END = START+diff1;
				if (!diff[diff1]&&!diff[diff2]&&!used[END]&&diff1!=bad) {
					System.out.println(START+" "+END);
					diff[diff1]=true;
					diff[diff2]=true;
					used[END]=true;
					START++;
					M--;
					if (M==0) break;
				}
			}
		}
	}	
}

Measured memory_bytes: 44812
#include<bits/stdc++.h>
using namespace std;
int a[100000],n,m,sum;;
int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    sort(a+1,a+n+1);
    for(int i=n;i>=n-m+1;i--)
        sum+=a[i];
    cout<<sum;
    return 0;
}

Measured memory_bytes: 256
a=int(input())
b=list(map(int,input().split()))
sum=0
break_loop=False
while True:
    for i in range(a):
        if b[i]%2!=0:
            break_loop=True
            break
        else:
            continue
    if break_loop==True:
        break
    b=list(map(lambda x:x/2,b))
    #print(b)
    sum+=1
print(sum)

Measured memory_bytes: 9252
N,Q=map(int,input().split())
S=input()
table=[]
for i in range(Q):
    t,d=input().split()
    table.append((t,d))
def f(x):
    u=x
    for t,d in table:
        if S[u]==t:
            if d=='L':
                u-=1
            else:
                u+=1
        if u==-1:
            return 0
        if u==N:
            return 1
    return 2
mi=0
ma=N-1
while ma-mi>1:
    mid=(ma+mi)//2
    if f(mid)==0:
        mi=mid
    else:
        ma=mid
left=mi
mi=0
ma=N-1
while ma-mi>1:
    mid=(ma+mi)//2
    if f(mid)==1:
        ma=mid
    else:
        mi=mid
right=ma
#print(left,right)
ans=(left+1)+(N-right)
num=N-ans
if left==0:
    if f(0)==2:
        num+=1
if right==N-1:
    if f(N-1)==2:
        num+=1
print(num)

Measured memory_bytes: 92608
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

func main() {
	fmt.Printf("%d\n", resolve(parseProblem(os.Stdin)))
}

func parseProblem(r io.Reader) int {
	const (
		initialBufSize = 100000
		maxBufSize     = 1000000
	)
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines

	return scanInt(sc)
}

func resolve(n int) int {
	// index == value
	states := make([]int, n+1)
	for i := 1; i < n+1; i++ {
		states[i] = inf
	}
	// 驟阪ｋDP
	for i := 0; i < n; i++ {
		if i+1 <= n {
			changeToMin(&(states[i+1]), states[i]+1)
		}
		for idx := 6; i+idx <= n; idx *= 6 {
			changeToMin(&(states[i+idx]), states[i]+1)
		}
		for idx := 9; i+idx <= n; idx *= 9 {
			changeToMin(&(states[i+idx]), states[i]+1)
		}
	}
	return states[n]
}

const (
	inf  = math.MaxInt32
	ninf = math.MinInt32
)

func changeToMin(v *int, cand int) (updated bool) {
	if *v > cand {
		*v = cand
		updated = true
	}
	return updated
}

func changeToMax(v *int, cand int) (updated bool) {
	if *v < cand {
		*v = cand
		updated = true
	}
	return updated
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1408
'use strict'

function main(input) {

    input = input.split('\n')
    let ary = input[1].split('')
    let a, b = [];
    let max = 0 //answer
    let matched = {};

    // for (let i = ary.length; i >= 0; i--) {
    for (let i = 0; i < ary.length; i++) {
        //i の位置で配列を分割
        a = ary.slice(0, i)
        b = ary.slice(i, ary.length)

        if (i >= max) { // max が 配列数より大きかったらスキップ

            matched = {}

            for (let j = 0; j < i; j++) {
                b.find(element => {

                    if (element == a[j]) {
                        matched[a[j]] = true
                    }
                })
            }

            max = (max > Object.keys(matched).length) ? max : Object.keys(matched).length
        }

    }
    console.log(max)
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7868
#include <stdio.h>
int n;
int main(){
    int i,j,k,m;
    int A[2500][2500];
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        scanf("%d %d",&A[i][0],&k);
        A[0][i]=A[i][0];
        for(j=0;j<k;j++){
            scanf("%d",&m);
            A[i][m]=1;
        }
    }
    for(i=1;i<=n;i++){
        for(j=1;j<=n;j++){
            printf("%d",A[i][j]);
            if(j!=n){
                printf(" ");
            }
        }
        printf("\n");
    }
return 0;
}


Measured memory_bytes: 2128
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template < typename T > string tost( const T& n ) { ostringstream stm; stm << n; return stm.str();}
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;}
int const INF = 1001001001;


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

int N;
cin >> N;
vi a(N);
rep(i,N) cin >> a[i];

auto prime_factor_count = [&](int c,int p) {
    int res = 0;
    while(c % p == 0 && c > 0) {
        c /= p;
        res++;
    }
    return res;
};

int ans = 0;
rep(i,N) {
    ans += prime_factor_count(a[i], 2);
}
cout << ans << endl;
return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<vector<ll> > mat;

int n,m,k;
string s[105];

int main()
{ios_base::sync_with_stdio(false);
cin.tie(0);
cin>>n>>m>>k;
rep(i,0,n-1)cin>>s[i];
int ans=0;
rep(m1,0,(1<<n)-1)
{
	rep(m2,0,(1<<m)-1)
	{
		int cnt=0;
		rep(i,0,n-1)
		{
			if(m1&(1<<i))continue;
			rep(j,0,m-1)
			{
				if(m2&(1<<j))continue;
				cnt+=(s[i][j]=='#');
			}
		}
		if(cnt==k)ans++;
	}
}
ol(ans);
return 0;
}



Measured memory_bytes: 3648
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int x, y;
	cin >> x >> y;
	bool yes = false;
	if(x == 2 && y == 2) yes = true;
	if((x==4||x==6||x==9||x==11)&&(y==4||y==6||y==9||y==11)) yes = true;
	if((x==1||x==3||x==5||x==7||x==8||x==10||x==12)&&(y==1||y==3||y==5||y==7||y==8||y==10||y==12)) yes = true;
	if(yes) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.HashSet;
import java.util.StringTokenizer;

class Main{

static final PrintWriter out=new PrintWriter(System.out);

static class Dictionary{

HashSet<String> set=new HashSet<String>();

void insert(String str){
set.add(str);
}

boolean find(String str){
return set.contains(str);
}
}

public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String line="";
while((line=br.readLine())!=null&&!line.isEmpty()){
int n=Integer.parseInt(line);
Dictionary d=new Dictionary();
for(int i=0;i<n;i++){
StringTokenizer st=new StringTokenizer(br.readLine());
String command=st.nextToken();
String str=st.nextToken();
if("insert".equals(command)){
d.insert(str);
}
else{
if(d.find(str)) out.println("yes");
else out.println("no");
}
}
}
out.flush();
}
}

Measured memory_bytes: 132984
import collections

n = int(input())
s = [input() for i in range(n)]
c = collections.Counter(s)
m = c.most_common()

maxn = m[0][1]
ans = []

for i in range(len(m)):
    if m[i][1] == maxn:
        ans.append(m[i][0])
    else:
        break
for i in sorted(ans):
    print(i)


Measured memory_bytes: 49172
#include<iostream>
#include<queue>
#include<cstdio>
using namespace std;
int main(){
	int n=0;
	int i=0;
	priority_queue<int,vector<int>,greater<int> > q1;
	int a=0;
	int b=0;
	int j=0;
	int s=0;
	int m=-1;
	for(i=0;i<2;i++){
		cin>>n;
		for(j=0;j<n;j++){
			cin>>a>>b;
			a=a*60+b;
			q1.push(a);
		}
	}
	while(!q1.empty()){
		a=q1.top();
		q1.pop();
		if(a==m)continue;
		m=a;
		b=a%60;
		a/=60;
		if(s==1)cout<<" ";
		s=1;
		printf("%d:%02d",a,b);
	}
	cout<<endl;
}

Measured memory_bytes: 1252
#define _GLIBCXX_DEBUG//TLEの原因になるので注意！！！！！！！！！！！
#include<cmath>
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.sise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
//#define int long long

//cerrはコメントアウトしなくても通る//ただしTLEを引き起こすことがある

//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
//const ll INF = 1LL << 60;
//typedef pair<ll,ll> P;
typedef pair<int, int> P;
bool chmx(int &a, int b) {
	if (b > a) {
		a = b;
		return true;
	}
	return false;
}

bool chmn(int &a, int b) {
	if (b < a) {
		a = b;
		return true;
	}
	return false;
}

int main(){
    int n,m;
    cin >> n>> m;
    int al=0;
    rep(i,m){
        int a;
        cin >> a;
        al+=a;
    }
    if(n-al>=0){
        cout<<n-al<<endl;
    }else{
        cout<<-1<<endl;
    }
    return 0;
}



Measured memory_bytes: 3600
#![allow(unused_imports)]
#![allow(non_snake_case)]

use procon::*;
use std::cmp::{max, min};
use std::collections::*;
use std::ops::*;
use std::*;

pub fn main() {
    let N = read_line().parse::<usize>().unwrap();
    let A = (0..N)
        .map(|_| read_line().parse::<i64>().unwrap())
        .collect::<Vec<_>>();

    if (0..N).any(|i| A[i] > i as i64 || (i > 0 && A[i] - A[i - 1] > 1)) {
        println!("-1");
        return;
    }

    let mut count = 0_i64;
    let mut end = 0_i64;

    for i in 0..N {
        if A[i] != end + 1 {
            count += end;
        }
        end = A[i];
    }
    count += end;

    println!("{}", count);
    return;
}

pub mod procon {
    use std;
    use std::collections::*;
    use std::io;
    use std::mem;
    use std::str::FromStr;

    pub fn read_line() -> String {
        let mut buf = String::new();
        io::stdin().read_line(&mut buf).unwrap();
        buf.trim_right().to_owned()
    }

    pub fn read_words<T>() -> Vec<T>
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        let mut buf = String::new();
        io::stdin().read_line(&mut buf).unwrap();
        buf.split_whitespace()
            .map(|word| T::from_str(word).unwrap())
            .collect()
    }

    pub fn read_vec(len: usize) -> Vec<String> {
        let mut vec = Vec::new();
        while vec.len() < len {
            let line = read_line();
            for word in line.split_whitespace() {
                vec.push(word.to_owned());
            }
        }
        assert!(vec.len() == len);
        vec
    }
}


Measured memory_bytes: 6524
#include <iostream>
#include <sstream>
#include <vector>
#include <cassert>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <tuple>

using namespace std;
using ull = unsigned long long;

struct Store{
	ull price;
	ull amount;
};

int main() {
	int N, M;

	cin >> N >> M;

	vector<Store> vec_store;

	for (size_t i = 0; i < N; i++) {
		ull A, B;
		cin >> A >> B;
		vec_store.emplace_back(Store{A, B});
	}

	sort(begin(vec_store), end(vec_store), [](const Store& s1, const Store& s2) {
		return s1.price < s2.price;
	});

	// M個になるまで買っていく！
	ull ans = 0;
	ull buy_count = 0;
	for (const Store& s: vec_store) {
		if (buy_count == M) {
			break;
		}

		if (s.amount + buy_count <= M) {
			// 全部買えばよい
			ans += s.amount * s.price;
			buy_count += s.amount;
		} else {
			// ぴったりまで買う
			const ull need_to_buy = M - buy_count;
			ans += need_to_buy * s.price;
			buy_count += need_to_buy;
		}
	}

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


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

using namespace std;

#define ll long long

void solve() {
	string s, s1;
	cin >> s >> s1;
	reverse(s1.begin(), s1.end());
	if (s == s1) {
		cout << "YES\n";
	} else {
		cout << "NO\n";
	}
}

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

	int t = 1, i = 1;
	//cin >> t;
	while(t--) {
		//cout << "Case #" << i << ": ";
		solve();
		//i++;
	}
	return 0;
}



Measured memory_bytes: 3636
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, bytes) => {
        read_value!($iter, String).into_bytes()
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
r#"3
2 3 1"# => r#"3 1 2"#,
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        n: usize,
        a: [usize; n],
    }

    let mut an = vec![0; n];
    for i in 0..n {
        an[a[i] - 1] = i + 1;
    }

    let mut ans = "".to_string();
    for i in 0..n {
        ans.push_str(&(an[i]).to_string());
        if i != n - 1 {
            ans.push_str(&" ".to_string());
        }
    }

    ans.to_string()
}

Measured memory_bytes: 8444
#include<bits/stdc++.h>
#define endl '\n'
#include <math.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int A,B,C,D;
    cin>>A>>B>>C>>D;
    int t = 0;
    while(A>0 && C>0){
        if(t%2 == 0) {
            C -= B;
        }
        else{
            A -= D;
        }
        t++;
    }
    if(A <= 0) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
    return 0;
}




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

#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)
#define ll long long
#define INF 1000000007
#define ull unsigned long long

int main()
{
    IOS;
    int W, n;
    cin >> n >> W;
    pair <int, int> w[n];
    for (int i = 0; i < n; i++)
    {
        cin >> w[i].first >> w[i].second;
    }
    vector< vector< ll> > dp(n + 1,vector< ll>(W + 1));
    sort(w, w + n);
    
    for (int i = 0; i <= n; i++)
    {
        dp[i][0] = 0;
    }
    for (int i = 0; i <= W; i++)
    {
        dp[0][i] = 0;
    }

    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= W; j++)
        {
            dp[i][j] = dp[i - 1][j];
            if (w[i - 1].first <= j)
            {
                dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i - 1].first] + w[i - 1].second);
            }
            else
            {
                dp[i][j] = dp[i - 1][j];
            }
        }
    }

    cout << dp[n][W];
    return 0;
}


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

int main(){
    int n,k,c;
    cin >> n >> k >> c;
    string s;
    cin >> s;
    vector<int> use(n,-1);
    int cnt = -1;
    int all =0;
    rep(i,n){
        if(cnt < 0 && s[i] == 'o') all++,use[i] = all,cnt =c;
        cnt --;
        if(all >= k) break;
    }
    vector<int> user(n);
    cnt = -1;
    for(int i=n-1;i>=0;i--){
        if(cnt < 0 && all >= use[i] && use[i] != -1) user[i] = 1,cnt = c,all--;
        else if(cnt < 0 && s[i] =='o') all--,cnt =c;
        cnt--;
        if(all <= 0) break;
    }
    //rep(k,n) cout << use[k] << " ";
    //rep(k,n) cout << user[k] << " " ;
    rep(i,n){
        if(user[i] ==1) cout << i+1 << endl;
    }

    return 0;
}

Measured memory_bytes: 3332
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"time"
)

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	return n
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Scan()
	s := sc.Text()
	layout := "2006/01/02"
	t, _ := time.Parse(layout, s)
	a, _ := time.Parse(layout, "2019/04/30")
	if !t.After(a) {
		fmt.Println("Heisei")
	} else {
		fmt.Println("TBD")
	}

}

Measured memory_bytes: 640
#include <cmath>
#include <iostream>
using namespace std;
int main() {
  int n, p[8], q[8], f[8] = {}, fq[8] = {}, a = 0, b = 0;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    cin >> p[i];
    int cnt = 0;
    p[i]--;
    for (int j = 0; j < p[i]; j++) {
      if (f[j] == 0) {
        cnt++;
      }
    }
    a += cnt;
    a *= (n - 1 - i);
    f[p[i]] = 1;
  }
  cin >> p[n - 1];
  for (int i = 0; i < n - 1; i++) {
    cin >> q[i];
    q[i]--;
    int cnt = 0;
    for (int j = 0; j < q[i]; j++) {
      if (fq[j] == 0) {
        cnt++;
      }
    }
    b += cnt;
    b *= (n - 1 - i);
    fq[q[i]] = 1;
  }
  cin >> q[n - 1];
  cout << abs(a - b) << endl;
}

Measured memory_bytes: 764