akhauriyash/Code-Regression huggingface dataset:
using System;

namespace Getting_Started
{
    class Prime_Numbers
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var c = n;
            for (int i = 0; i < n; i++)
            {
                var a = int.Parse(Console.ReadLine());
                if (a == 2) continue;
                if (a == 1 || a % 2 == 0)
                {
                    c--; continue;
                }
                for (int j = 3; j <= Math.Sqrt(a); j+=2)
                {
                    if (a % j == 0)
                    {
                        c--; break;
                    }
                }
            }
            Console.WriteLine(c);
        }
    }
}

Measured memory_bytes: 9188
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import qualified Data.Vector.Unboxed as VU

main :: IO ()
main = do
  n <- unsafeTextToInt <$> T.getLine :: IO Int
  as <- VU.map pred . VU.fromList . map unsafeTextToInt . T.words <$> T.getLine :: IO (VU.Vector Int)
  let
    ls = VU.unsafeAccumulate_ (+) (VU.replicate n 0) as (VU.replicate n 1) :: VU.Vector Int
    m = VU.sum . VU.map comb $ ls :: Int
  VU.mapM_ print . VU.map ((m -) . pred . (ls VU.!)) $ as

comb :: Int -> Int
comb l = (l * pred l) `div` 2

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n


Measured memory_bytes: 16252
inf = 10**12


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

    D = int(input())
    C = list(map(int, input().split()))
    S = []
    for _ in range(D):
        S.append(list(map(int, input().split())))
    ans = 0
    last = [-1] * 26
    days = [[-1] for _ in range(26)]
    T = []
    # greedy
    for d in range(D):
        plus = -inf
        t = -1
        for tt in range(26):
            plus_new = S[d][tt] + C[tt] * (d - last[tt])
            if plus_new > plus:
                t = tt
                plus = plus_new
        T.append(t)
        ans += S[d][t]
        last[t] = d
        days[t].append(d)
        for i in range(26):
            ans -= C[i] * (d - last[i])
    for t in range(26):
        days[t].append(D)
    for t in T:
        print(t+1)
    exit()







    M = int(input())
    for _ in range(M):
        d, q = map(int, input().split())
        d -= 1
        q -= 1
        t = T[d]
        ans += S[d][q]
        ans -= S[d][t]
        i = bisect_left(days[q], d)
        ans += C[q] * (d - days[q][i-1]) * (days[q][i] - d)
        j = bisect_left(days[t], d)
        ans -= C[t] * (d - days[t][j-1]) * (days[t][j+1] - d)
        #print(days[q], days[t])
        T[d] = q
        days[q].append(d)
        days[q].sort()
        days[t].remove(d)
        print(ans)


if __name__ == '__main__':
    main()


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

int main() {
  int n, k, l;
  int ans = 0;
  vector<int> a;
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    cin >> l;
    a.push_back(l);
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  //for (int i = 0; i < n; ++i) {
    //cout << a[i] << endl;
  //}
  for (int i = 0; i < k; ++i) {
    ans+= a[i];
  }
  cout << ans << endl;


}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define N 200010
int n,cnt;
char s[N];
set<int>a,b;
bool ok()
{
	if(a.empty())return true;
	if(b.empty())return true;
	return *a.rbegin()<*b.begin();
}
int main()
{
	scanf("%d",&n);
	scanf("%s",s+1);
	for(int i=1;i<=n;i++)
	  if(s[i]=='R')a.insert(i);
	  else b.insert(i);
	while(!ok())
	  {
	  int x=*a.rbegin(),y=*b.begin();
	  a.erase(x),b.erase(y);
	  a.insert(y),b.insert(x);
	  cnt++;
	  }
	printf("%d\n",cnt);
}

Measured memory_bytes: 13404
def test
	n, m = gets.split(" ").map(&:to_i)
	arr = Array.new(m, 0)
	n.times do
		as = gets.split(" ").map(&:to_i)
		as.shift
		as.each do |a|
			arr[a-1] += 1
		end
	end
	arr.select{|i| i == n}.length
end

puts test


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

#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define FOR(i,m,n) for(int i=(m) ; i<(n) ; i++)
#define FORR(i,m,n) for(int i=(m) ; i>=(n) ; i--)

typedef long long ll;
typedef unsigned long long ull;

const int INF = 1000000000;

int main(){
   int H,W,h,w;cin >>H >> W>>h>>w;
   cout << (H-h)*(W-w);
   return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define dl double long
#define rep(i, m, n) for(ll i = (ll)(m); i < (ll)(n); ++i)
#define rrep(i, m, n) for(ll i = (ll)(m); i < (ll)(n); --i)
const ll MOD = 1000000007;
const double pi = 3.14159265358979323846;

const int INF = 2000000000;

void marge(int a[], int left, int mid, int right, int *count){
    int n1 = mid - left;
    int n2 = right - mid;
    vector<int> l,r;
    rep(i, 0, n1) l.push_back(a[left+i]);
    rep(i, 0, n2) r.push_back(a[mid+i]);
    l.push_back(INF);
    r.push_back(INF);
    int i = 0, j = 0;
    rep(k, left, right){
        (*count)++;
        if(l[i] <= r[j]) a[k] = l[i++];
        else a[k] = r[j++];
    }
    return;
}

void margesort(int a[], int left, int right, int *count){
    if(left + 1 < right){
        int mid = (left + right) / 2;
        margesort(a, left, mid, count);
        margesort(a, mid, right, count);
        marge(a, left, mid, right, count);
    }
    return;
}

int main(void){
    int n, s[500000], count = 0;
    cin >> n;
    rep(i, 0, n) cin >> s[i];
    margesort(s, 0, n, &count);
    rep(i, 0, n) {
        if(i) cout << ' ';
        cout << s[i];
    }
    cout << endl << count << endl;
    return 0;
}


Measured memory_bytes: 7472
#include<stdio.h>
int main(){
	int a,b,d,r;
	double f;
	scanf("%d %d",&a,&b);
	d=a/b;
	r=a%b;
	f=(double)a/b;
	printf("%d %d %lf\n",d,r,f);
	return 0;
}

Measured memory_bytes: 2720
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define int ll
#define double long double
#define nn '\n'
#define YES {cout<<"YES"<<'\n';}
#define NO {cout<<"NO"<<'\n';}
#define Yes {cout<<"Yes"<<'\n';}
#define No {cout<<"No"<<'\n';}
#define yes {cout<<"yes"<<'\n';}
#define no {cout<<"no"<<'\n';}
void YN(bool flg){cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg){cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define out(n) {cout << n << '\n';}
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 10e10;
const double PI = acos(-1.0);
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n /= 2; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------ライブラリとか----------------

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(15);

    int n,k; cin >> n >> k;
    double ans = 0;
    FOR(i,1,n+1){
        int c = 0 , tmp = i;
        while(tmp<k){tmp*=2; c++;}
        ans += (1/(double)n) * pow(0.5,c);
    }
    out(ans);

    return 0;
}

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

template<int MAX>
struct Combination {
    vector<long long> _inv, _fac, _ifac;
    const long long MOD;
    Combination(long long mod) : _inv(MAX+1), _fac(MAX+1), _ifac(MAX+1), MOD(mod) { init(); }
    void init() { init_inv(), init_fac(); }

    void init_inv() {
        _inv[0] = 0;
        for (int i = 1; i <= MAX; i++) {
            if (i == 1) _inv[i] = 1;
            else {
                _inv[i] = (MOD - (MOD / i) * _inv[MOD % i]) % MOD;
                if (_inv[i] < 0) _inv[i] += MOD;
            }
        }
    }
    void init_fac() {
        _fac[0] = _ifac[0] = 1;
        for (int i = 1; i <= MAX; i++) {
            _fac[i] = _fac[i-1] * i % MOD;
            _ifac[i] = _ifac[i-1] * _inv[i] % MOD;
        }
    }

    long long modpow(long long n, long long r) {
        n %= MOD, r %= (MOD-1);
        if (!n) return 0;
        long long ret = 1; long long tmp = n;
        while (r != 0) {
            if (r % 2) ret *= tmp;
            tmp *= tmp; tmp %= MOD; ret %= MOD;
            r /= 2;
        }
        return ret;
    }
    long long invb(int i) const { return (i <= MAX) ? _inv[i] : this->modpow(i, MOD-2); }
    long long inv(int i) const { return _inv[i]; }
    long long fac(int i) const { return _fac[i]; }
    long long ifac(int i) const { return _ifac[i]; }

    long long operator()(int n, int r) const {
        if (n < r) return 0;
        return fac(n) * ifac(r) % MOD * ifac(n-r) % MOD;
    }
};

constexpr int mod = 1000000007;
constexpr int MAX = 2000010;
Combination<MAX> C(mod);

int main() {
    int K; string S; 
    cin >> K >> S;
    const int N = S.size();
    long long All = C.modpow(26, N+K);
    long long Sub = 0;
    for (int m = 0; m < N; m++) {
        Sub += C(N+K, m) * C.modpow(25, N+K-m) % mod;
    }
    cout << (All - Sub % mod + mod) % mod << "\n";
    return 0;
}

Measured memory_bytes: 52168
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, char> P;
const int mod = 1000000007;
const int INF = 1e12;

int n;
vector<P> a;

int partition(int p, int r){
    int x = a[r].first;
    int i = p - 1;
    rep(j, p, r){
        if(a[j].first <= x){
            i = i + 1;
            swap(a[i], a[j]);
        }
    }
    swap(a[i + 1], a[r]);
    return i + 1;
}

void quicksoert(int p, int r){
    if(p < r){
        int q = partition(p, r);
        quicksoert(p, q - 1);
        quicksoert(q + 1, r);
    }
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    a.resize(n);
    map<int, vector<char> > mp;
    map<int, int> id;    
    rep(i, 0, n){
        cin >> a[i].second >> a[i].first;
        mp[a[i].first].push_back(a[i].second);
    }
    quicksoert(0, n - 1);
    bool f = true;
    rep(i, 0, n){
        if(a[i].second != mp[a[i].first][id[a[i].first]]) f = false;
        else id[a[i].first]++;
    }
    if(f) cout << "Stable" << endl;
    else cout << "Not stable" << endl;
    rep(i, 0, n){
        cout << a[i].second << " " << a[i].first << endl;
    }
}

Measured memory_bytes: 8640
#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+1); ++i)
using namespace std;
using ll = long long;
const int INF = -100100100;
typedef pair<int,int> P;

int main(){
    int n,m;
    cin >> n >> m;
    cout << n * (n-1) /2 + m * (m-1)/2 << endl;
    return 0;
}

Measured memory_bytes: 256
class Node

  attr_accessor :to, :cost
  def initialize(to, cost)
    @to = to
    @cost = cost
  end
end

INF = 10 ** 7
# INF = Float::INFINITY

def dijkstra(g, s)

  # inf = 10 ** 12
  inf = INF
  dist = Array.new(g.size, inf)
  dist[s] = 0

  que = []
  que.push( [0, s] )

  while que.any?

    d, v = que.shift
    next if dist[v] < d
    g[v].each do |e|
      next if dist[e.to] != inf || dist[v] == inf
      dist[e.to] = dist[v] + 1
      que.push( [dist[e.to], e.to ] )
    end
  end
  
  # dist.map!{|d| d == inf ? "INF" : d }
  dist
end

n, m = gets.to_s.split.map{|t|t.to_i}

g = Array.new(n*3){ [] }

m.times do
  u, v = gets.to_s.split.map{|t|t.to_i-1}
  g[3*u+0] << Node.new(3*v+1, 1)
  g[3*u+1] << Node.new(3*v+2, 1)
  g[3*u+2] << Node.new(3*v+0, 1)
end

s, t = gets.to_s.split.map{|i|i.to_i-1}

dist = dijkstra(g, s*3+0)

puts dist[t*3+0] == INF ? -1 : dist[t*3+0]/3

Measured memory_bytes: 47740
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int arr[5];
    cin>>arr[0]>>arr[1]>>arr[2];
    sort(arr,arr+3);
    if((arr[1]-arr[0])%2==0)
    {
        int dif=(arr[1]-arr[0])/2;
        dif+=arr[2]-arr[1];
        cout<<dif<<endl;
    }
    else if((arr[2]-arr[0])%2==0)
    {
        int dif=(arr[2]-arr[0])/2;
        while(arr[1]<arr[2])
            arr[1]+=2,dif++;
        cout<<dif+1<<endl;
    }
    else
    {
        int dif=(arr[2]-arr[1])/2;
         while(arr[0]<arr[2])
            arr[0]+=2,dif++;
        cout<<dif+1<<endl;

    }


    return 0;
}


Measured memory_bytes: 3628
N = int(input())
A = [int(input()) for i in range(N)]
min = A[0]
max = A[1]-A[0]
for i in range(1,N):
    if max < A[i]-min:
        max = A[i]-min
    if min > A[i]:
        min = A[i]

print(max)


Measured memory_bytes: 13592
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
a = []
for _ in range(n):
    a.append(list(map(int, input().split())))

ans = 0
for aa in a:
    tmp = c
    for i, j in zip(aa, b):
        tmp += i*j
    if tmp>0:
        ans += 1
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
 
int main() 
{
	int n;
	scanf("%d",&n);
	if ( n == 111 )
	{
		printf("999");
	}
	else if ( n == 119 )
	{
		printf("991");
	}
	 else if ( n == 191 )
	{
		printf("919");
	}
	 else if ( n == 911 )
	{
		printf("199");
	}
	 else if ( n == 199 )
	{
		printf("911");
	}
	 else if ( n == 919 )
	{
		printf("191");
	}
	 else if ( n == 991 )
	{
		printf("119");
	}
	 else if ( n == 999 )
	{
		printf("111");
	}
	return 0;
	 
}

Measured memory_bytes: 128
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd # 最大公約数
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) # 最小公倍数
# list(map(int, input().split()))

n = int(input())
ac = 0
wa = 0
tle = 0
re = 0
for _ in range(n):
    s = input()
    if s == 'AC':
        ac += 1
    elif s == 'WA':
        wa += 1
    elif s == 'TLE':
        tle += 1
    elif s == 'RE':
        re += 1
print('AC x', ac)
print('WA x', wa)
print('TLE x', tle)
print('RE x', re)

Measured memory_bytes: 10440
#include <iostream>
#include <stdlib.h>

using namespace std;

#define MAX_STACK_SIZE 100
#define MAX_NUM_AND_OP 200

struct Stack {
    int values[MAX_STACK_SIZE];
    int top;
};

void push(struct Stack *stack, int x) {
    stack->values[stack->top] = x;
    stack->top++;
}

int pop(struct Stack *stack) {
    stack->top--;
    return stack->values[stack->top];
}

bool is_empty(struct Stack *stack) {
    return stack->top == 0;
}

bool is_full(struct Stack *stack) {
    return stack->top == MAX_STACK_SIZE;
}

void init_stack(struct Stack *stack) {
    for (int i = 0; i < MAX_STACK_SIZE; i++) {
        stack->values[i] = 0;
    }
    stack->top = 0;
}

int main() {
    struct Stack stack;
    init_stack(&stack);

    int l, r;
    char str[MAX_NUM_AND_OP];
    while(cin >> str) {
        if (str[0] == '+') {
            r = pop(&stack);
            l = pop(&stack);
            push(&stack, l + r);
        } else if (str[0] == '-') {
            r = pop(&stack);
            l = pop(&stack);
            push(&stack, l - r);
        } else if (str[0] == '*') {
            r = pop(&stack);
            l = pop(&stack);
            push(&stack, l * r);
        } else {
            push(&stack, atoi(str));
        }
    }

    cout << pop(&stack) << endl;

    return 0;
}


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

public class Main {

    public static void main(String[] args) {
      Scanner scan = new Scanner(System.in);
      int n = scan.nextInt();
      int k[] = new int[n];

      for(int i=0;i<n;i++)
      k[i] = scan.nextInt();

      Arrays.sort(k);

      int count = 1;
      for(int i=0;i<n-1;i++){
        if(k[i]<k[i+1])
        count++;
      }
      System.out.println(count);
    }
  }


Measured memory_bytes: 21844
#include <stdio.h>
#include <string.h>

void fgets2(char *s, int size, int *len){
  int l=size;
  for(l=0;l<size;l++) {
    int c = fgetc(stdin);
    s[l]=(char)c;
    if(c=='\n') break;
  }
  if (l==size) {
    if(s[l] == '\n') {
      s[l] = 0;
      *len = l-1;
    }
    else {
      int c;
      *len = l;
      while ((c = fgetc(stdin))!=EOF) {
	if((char)c=='\n') break;
      }
    }
  }
  else {
    s[l] = 0;
    *len = l;
  }
}

int main(){
  int N,n;
  scanf("%d\n",&N);
  for(n=0;n<N;n++){
    char a[81],b[81],c[82];
    int al=0,bl=0,cl=80;
    fgets2(a,81,&al);
    fgets2(b,81,&bl);
    if((al>80)||(bl>80)) puts("overflow");
    else {
      memset(c,0,82);
      while(al||bl){
	int an,bn;
	if(al>0) an=a[--al]-'0';else an=0;
	if(bl>0) bn=b[--bl]-'0';else bn=0;
	c[cl]+=an+bn;
	if(c[cl]>9){
	  c[cl-1]=1;
	  c[cl]=c[cl]%10+'0';
	}
	else{
	  c[cl-1]=0;
	  c[cl]=c[cl]+'0';
	}
	cl--;
      }
      if (c[0]) puts("overflow");
      else {
	if (!c[cl]) cl++;
	if (c[cl]==1) c[cl]='1';
	puts(&c[cl]);
      }
    }
  }
  return 0;
}

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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const double PI=acos(-1);
const double EPS=1e-6;

int N;
double x[333],y[333];

signed main(){
    while(cin>>N,N){
        rep(i,N)cin>>x[i]>>y[i];

        int ma=1;
        rep(i,N)rep(j,N){
            if(i==j)continue;
            double dx=x[i]-x[j],dy=y[i]-y[j];
            double d=sqrt(dx*dx+dy*dy);
            if(d>2+EPS)continue;
            double r=sqrt(1.0-d*d/4);
            double vx=-dy/d*r;
            double vy=dx/d*r;

            double xx=(x[i]+x[j])/2+vx;
            double yy=(y[i]+y[j])/2+vy;
            int cnt=0;
            rep(k,N){
                if((x[k]-xx)*(x[k]-xx)+(y[k]-yy)*(y[k]-yy)<1.0+EPS)cnt++;
            }
            chmax(ma,cnt);
        }
        printf("%lld\n",ma);
    }
}

Measured memory_bytes: 3092
fn main() {
    let (a, b) = {
        let v = read_vec::<i32>();
        (v[0], v[1])
    };

    println!("{}", vec![a+b, a-b, a*b].iter().max().unwrap());
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T  {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().parse::<T>().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
    .map(|e| e.parse().ok().unwrap())
    .collect()
}

Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <climits>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
using namespace std;

ll maxSubarrayXOR(ll set[], ll n){
  ll index = 0;
  for (int i = 63; i >= 0; i--){
    ll maxInd = index;
    ll maxEle = LLONG_MIN;
    for (int j=index;j<n;j++) if(((set[j]&(1<<i))!=0) && set[j]>maxEle) maxEle=set[j],maxInd = j;
    if (maxEle==LLONG_MIN) continue;
    swap(set[index], set[maxInd]);
    maxInd = index;
    for (int j=0; j<n; j++) if (j!=maxInd&&((set[j]&(1<<i))!=0))set[j]^=set[maxInd];
    index++;
  }
  ll res = 0;
  for (int i = 0; i < n; i++) res ^= set[i];
  return res;
}
int main(int argc, char const *argv[]) {
  ll N;
  std::cin >> N;
  ll A[N];
  ll d = 0, b = 0;
  for(int i=0;i<N;i++){
    std::cin >> A[i];
    d ^= A[i];
  }
  for(int i=0;i<N;i++) A[i] &= ~d;

  b = maxSubarrayXOR(A, N);
  ull rank = 0;
  ll i = 0, j = 0;
	for (i = 59; i >= 0; i--) {
		for (j = rank; j < N; j++) {
			if (A[j] & (1LL << i)) break;
		}
		if (j == N) {
			continue;
		}

		if (j > rank) A[rank] ^= A[j];
		for (j = rank + 1; j < N; j++) {
			A[j] = min(A[j], A[j] ^ A[rank]);
		}

		rank++;
	}
	ull x = 0;
	for (i = 0; i < N; i++) {
		x = max(x, x ^ A[i]);
	}
  //std::cout << d << " " << b << " " << x<< '\n';
  std::cout << d + (x * 2)  << '\n';
  return 0;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h> 
#define ll long long 
#define pb push_back 
#define vec vector<int> 
#define fo(i,n) for (ll i = 0; i < n; i++)
#define so(v) sort(v.begin(), v.end())
#define fi first
#define se second 
using namespace std;  
int main()
{
 int n;
 cin>>n;
 int a;
 a=n%1000;
 if(a==0)
 {
    cout<<0;
    
 }
 else if(a<1000)
 {
     a=1000-a;
     cout<<a;
 }
 
}

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

int main() 
{ 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a, b, n;
    cin >> a >> b >> n;
    ll x = min(n, b-1);
    cout << floor(((long double)a*x)/b) - a*floor((long double)x/b) << "\n";
    return 0; 
}

Measured memory_bytes: 3820
n, x = map(int, input().split(" "))
children = list(map(int, input().split(" ")))

children.sort()

for i in range(n):
  x -= children[i]
  if x < 0:
    print(i)
    exit()
    
if x > 0:
  print(n - 1)
elif x == 0:
  print(n)

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

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

using namespace std;

int main(){
  int a,b;cin>>a>>b;
  if(a*b==15)cout<<'*';
  else if(a+b==15)cout<<'+';
  else cout<<'x';
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll d,t,s;
    cin>>d>>t>>s;
    double tim = (d+0.0)/(s+0.0);
    if(tim <= t)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}



Measured memory_bytes: 3596
// 2013/07/12 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int t;
		cin >> t;

		if(t==0)
			break;

		int n;
		cin >> n;

		int sum = 0;

		for(int i=0; i<n; i++){
			int s, f;
			cin >> s >> f;

			sum += (f-s);
		}

		if(sum>=t){
			cout << "OK" << endl;
		}
		else{
			cout << t-sum << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1160
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;

typedef long long ll;
#define Dct(x) (lower_bound(&Num[1],&Num[num+1],x)-Num)
#define ls (x<<1)
#define rs (ls|1)
const int maxN=101000*5;

int n,K;
ll Sm[maxN],num,Num[maxN],F[maxN],Lft[maxN],Rht[maxN];
int C[maxN<<2];

void Cover(int x,int c);
void PushDown(int x);
void Modify(int x,int l,int r,int ql,int qr,int c);
int Query(int x,int l,int r,int p);
ll Calc(ll pos);
int main(){
    //freopen("in","r",stdin);
    ll sum=0;
    scanf("%d%d",&n,&K);
    for (int i=1;i<=n;i++){
        int key,opt;scanf("%d%d",&key,&opt);
        if (opt==1&&key*2>K){printf("-1\n");exit(0);}
        Sm[i]=(Sm[i-1]+key)%K;sum+=key;
        if (opt==2) Lft[i]=0,Rht[i]=K-1;
        else Lft[i]=(K-Sm[i-1]*2%K)%K,Rht[i]=(K-Sm[i]*2%K)%K;
        Num[++num]=Lft[i];Num[++num]=Rht[i];
    }
    Num[++num]=0;Num[++num]=K-1;sort(&Num[1],&Num[num+1]);num=unique(&Num[1],&Num[num+1])-Num-1;
    //for (int i=1;i<=num;i++) cout<<Num[i]<<" ";cout<<endl;
    for (int i=n;i>=1;i--){
        int l=Dct(Lft[i]),r=Dct(Rht[i]);
        F[i]=Calc(Lft[i]);
        //cout<<"("<<l<<" "<<r<<")"<<endl;
        if (l<=r){
            if (l>1) Modify(1,1,num,1,l-1,i);
            if (r<num) Modify(1,1,num,r+1,num,i);
        }
        else if (r+1<=l-1) Modify(1,1,num,r+1,l-1,i);
        //cout<<F[i]<<" "<<Lft[i]<<endl;for (int j=1;j<=num;j++) cout<<Query(1,1,num,j)<<" ";cout<<endl;
    }
    ll Ans=F[1];
    for (int i=1;i<=num;i++) Ans=min(Ans,Calc(Num[i]));
    printf("%lld\n",Ans+sum*2);return 0;
}
void PushDown(int x){
    if (C[x]){
        C[ls]=C[x];C[rs]=C[x];
        C[x]=0;
    }
    return;
}
void Modify(int x,int l,int r,int ql,int qr,int c){
    if (l==ql&&r==qr){
        C[x]=c;return;
    }
    int mid=(l+r)>>1;PushDown(x);
    if (qr<=mid) Modify(ls,l,mid,ql,qr,c);
    else if (ql>=mid+1) Modify(rs,mid+1,r,ql,qr,c);
    else Modify(ls,l,mid,ql,mid,c),Modify(rs,mid+1,r,mid+1,qr,c);
    return;
}
int Query(int x,int l,int r,int p){
    if (l==r) return C[x];
    int mid=(l+r)>>1;PushDown(x);
    if (p<=mid) return Query(ls,l,mid,p);
    else return Query(rs,mid+1,r,p);
}
ll Calc(ll pos){
    int p=Dct(pos),id=Query(1,1,num,p);
    if (id==0) return 0;
    return F[id]+(Lft[id]-pos+K)%K;
}

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

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second

#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 ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cout << #a << " = " << a << endl;

const double PI = acos(-1.0);
const LL INF = 1e9;
const LL LINF = INF * INF;

string s, t;
const int MAX = 3000 + 47;
int dp[MAX][MAX];

int get(int x, int y)
{
	if (x < 0 || y < 0)
		return 0;
	
	if (dp[x][y] != -1)
		return dp[x][y];
	
	int res = max(get(x - 1, y), get(x, y - 1));
	if (s[x] == t[y])
		res = max(res, get(x - 1, y - 1) + 1);
		
	return dp[x][y] = res;
}

string ans;

void go(int x, int y)
{
	if (x < 0 || y < 0)
		return;
	
	int a = get(x - 1, y - 1);
	if (s[x] == t[y])
		++a;
	int b = get(x - 1, y);
	int c = get(x, y - 1);
	
	int m = max(a, max(b, c));
	if (a == m && s[x] == t[y])
	{
		ans += s[x];
		go(x - 1, y - 1);
		return;
	}
	
	if (b == m)
		go(x - 1, y);
	else
		go(x, y - 1);
}

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("In.txt", "r", stdin);
	//freopen("In.txt", "w", stdout);

	cin >> s >> t;
	int n = SZ(s);
	int m = SZ(t);
	
	FILL(dp, -1);
	go(n - 1, m - 1);	
	reverse(ALL(ans));
	cout << ans << endl;
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
	return 0;
}


Measured memory_bytes: 36992
#!/usr/bin/env python3


def main():
    n, k = list(map(int, input().split()))
    s = input()
    result = ''
    for i, st in enumerate(s):
        if i == k-1:
            result += st.lower()
        else:
            result += st
    print(result)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <cmath>
#define ll long long
#define LINF 0x3f3f3f3f3f3f3f3f
#define INF 0x3f3f3f3f
#define PI 3.14159265
using namespace std;
const int MAX = 1e5 + 10; //N
const ll MOD = 1e9 + 7;
int N, M, K, Q;

int main()
{
	int i, j, k;
	string s;
	stack<int> st;
	cin >> s;
	for (i = 0; i < s.size(); ++i) {
		if (st.empty()) st.push(s[i] - '0');
		else if (s[i] - '0' == 0 && st.top() == 1) st.pop();
		else if (s[i] - '0' == 1 && st.top() == 0) st.pop();
		else st.push(s[i] - '0');
	}
	printf("%d", s.size() - st.size());

}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define int long long

map<int , int> m;

int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int N;
	cin >> N;
	int nb = 0;
	for (int i = 0 ; i < N ; i++)
	{
		int h;
		cin >> h;
		nb += m[i - h];
		m[i + h]++;
	}
	cout<<nb<<endl;
}

Measured memory_bytes: 26332
#include <cstdio>
#include <algorithm>

using namespace std;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DUMP(a, n) REP(i, n) printf("%d%c", a[i], i + 1 == n ? '\n' : ' ')

const int N_MAX = 100000;
const int K_MAX = 100;
const int INF = 1e9+10;

int N, K;
int h[N_MAX];
int dp[N_MAX];

void solve() {
  fill(dp, dp + N, INF);
  dp[0] = 0;
  FOR(i, 1, N - 1) {
    FOR(j, 1, K) {
      if (i >= j) dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
    }
  }
  // DUMP(dp, N);
  printf("%d\n", dp[N - 1]);
}

void input() {
  scanf("%d%d", &N, &K);
  REP(i, N) scanf("%d", h + i);
}

int main() {
  input();
  solve();
  return 0;
}


Measured memory_bytes: 896
n=gets.to_i
a=gets.split(" ").map(&:to_i)
b=false

(0..n-1).each do |x|
    if a[x]%2==0
        if a[x]%3==0 || a[x]%5==0
            b=true
        else
            puts "DENIED"
            exit
        end
    end
end
puts "APPROVED"

Measured memory_bytes: 1788
package main

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

// const abcd = "abcdefghijklnmopqrstuvwxyz"
// const ABCD = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

// var dy = [...]int{1, 1, 0, -1, -1, -1, 0, 1}
// var dx = [...]int{0, 1, 1, 1, 0, -1, -1, -1}

// var dx = [...]int{0, 1, 0, -1}
// var dy = [...]int{1, 0, -1, 0}
var inf int = 1e9

// ---------------------------------------------------------
func main() {
	log.SetFlags(log.Lshortfile)
	next := newScanner()
	n := next.Int()
	l := make([]int, n)
	r := make([]int, n)
	for i := 0; i < n; i++ {
		l[i] = next.Int()
		r[i] = next.Int()
	}
	ans := 0
	for i := 0; i < n; i++ {
		ans += r[i] - l[i] + 1
	}

	fmt.Println(ans)
}

// ---------------------------------------------------------

// Pair is liked C++ pair
type Pair struct {
	a, b int
}

// Pairs is sorted by []Pair struct
type Pairs []Pair

func (p Pairs) Len() int {
	return len(p)
}
func (p Pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Pairs) Less(i, j int) bool {
	if p[i].a < p[j].a {
		return true
	} else if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return false
}

// -------------------------------
func in(c, a, z int) bool {
	return c >= a && c < z
}

func btoi(b bool) int {
	if b {
		return 1
	}
	return 0
}

func itob(a int) bool {
	if a == 0 {
		return false
	}
	return true
}

func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}

func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}

func minmax(a, b int) (int, int) {
	if a > b {
		return b, a
	}
	return a, b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// ---------- buffered scanner -----------------------------------------
type scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func newScanner() *scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 10000)
	return &scanner{r: rdr}
}
func (s *scanner) next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *scanner) Line() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *scanner) Int() int {
	v, _ := strconv.Atoi(s.next())
	return v
}
func (s *scanner) Int64() int64 {
	v, _ := strconv.ParseInt(s.next(), 10, 64)
	return v
}
func (s *scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


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

int main(){
    long n,a,b;
    cin>>n>>a>>b;

    long q=n/(a+b);
    long r=n%(a+b);

    if(r<=a){
        cout<<q*a+r<<endl;
    }else{
        cout<<(q+1)*a<<endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<set>
#include<map>
#include<utility>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

#define MOD 1000000007;

int main(){
	int n;
	cin >> n;
	double sum=0;
	for(int i=0; i<n; i++){
		double x;
		string u;
		cin >> x >> u;
		if(u=="BTC")
			x*=380000;
		sum+=x;
	}
	cout << fixed << setprecision(5) << sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>

const int N = 203, M = 10001003;
bool ispri[M], vs[N];
int a[N], tot;
int n, Ans;

void input() {
	int x, y;
	scanf("%d%d", &n, &x);
	a[tot = 1] = x;
	for(int i=2;i<=n;++i) {
		scanf("%d", &y);
		if(x+1 != y) a[++tot] = x+1, a[++tot] = y;
		x = y;
	}
	a[++tot] = ++x;
	
	for(int i=2;i<=x;++i) ispri[i] = true;
	for(int i=2;i<=x;++i) if(ispri[i])
		for(int j=i+i;j<=x;j+=i) ispri[j] = false;
	ispri[2] = false;
}

namespace Part1 {
	struct Edge {int v, w, nxt;} e[N*N];
	int head[N], cur[N];
	int q[N], he, ta, dis[N];
	int s, t, _;
	
	inline void add(int x, int y) {
		e[++_].v = y, e[_].w = 1, e[_].nxt = head[x], head[x] = _;
		e[++_].v = x, e[_].w = 0, e[_].nxt = head[y], head[y] = _;
	}
	
	void init() {
		s = tot + 1, t = s + 1, _ = 1;
		for(int i=1;i<=t;++i) head[i] = 0;
	}
	
	bool bfs() {
		for(int i=1;i<=t;++i) dis[i] = -1;
		dis[q[he = ta = 1] = s] = 0;
		while(he <= ta) {
			int x = q[he++];
			for(int i=head[x];i;i=e[i].nxt)
				if(e[i].w and -1 == dis[e[i].v]) {
					dis[q[++ta] = e[i].v] = dis[x] + 1;
					if(e[i].v == t) return true;
				}
		}
		return false;
	}
	
	int dfs(int x, int flw) {
		if(x == t or !flw) return flw;
		int res = 0, tmp;
		for(int&i=cur[x];i;i=e[i].nxt)
			if(e[i].w and dis[e[i].v] == dis[x] + 1)
			if(tmp = dfs(e[i].v, e[i].w)) {
				e[i].w -= tmp, e[i^1].w += tmp, res += tmp;
				if(res == flw) return res;
			}
		if(!res) dis[x] = -1;
		return res;
	}
	
	int Dinic() {
		const int oo = 1e9;
		int res = 0;
		while(bfs()) {
			for(int i=1;i<=t;++i) cur[i] = head[i];
			res += dfs(s, +oo);
		}
		return res;
	}

	inline int abs(const int x) {return x < 0 ? -x : x;}	
	
	void work() {
		init();
		for(int i=1;i<=tot;++i)
			if(a[i]&1) add(s, i);
		
		for(int i=1;i<=tot;++i) if(a[i]&1)
		for(int j=1;j<=tot;++j) if(~a[j]&1)
			if(ispri[abs(a[i] - a[j])]) add(i, j);
		
		for(int i=1;i<=tot;++i)
			if(~a[i]&1) add(i, t);
	
		Ans += Dinic();
		for(int i=head[s];i;i=e[i].nxt)
			if(!e[i].w) vs[e[i].v] = true;
		for(int i=head[t];i;i=e[i].nxt)
			if(e[i].w) vs[e[i].v] = true;
	}
}

void Part23() {
	int ct[2] = {0, 0};
	for(int i=1;i<=tot;++i)
		if(!vs[i]) ++ct[a[i]&1];
	Ans += ct[0] ^ (ct[0] & 1);
	Ans += ct[1] ^ (ct[1] & 1);
	Ans += (ct[0] & ct[1] & 1) * 3;
}

int main() {
	input();
	
	Part1::work();
	Part23();
	
	printf("%d\n", Ans);
	return 0;
}

Measured memory_bytes: 9984
import qualified Control.Monad as C
import qualified Data.List     as L
import Control.Applicative ((<$>))

solve :: Int -> IO ()
solve n = do
    rideAndLeftTimes <- C.forM [1..n] $ \_ -> do
        [ride, left] <- map read . words . filter (/= ':') <$> getLine :: IO [Int]
        return (ride, left)
    let rides = map (\x -> (x,  1)) $ map fst rideAndLeftTimes
    let lefts = map (\x -> (x, -1)) $ map snd rideAndLeftTimes
    print . maximum . scanl (+) 0 . map snd . L.sort $ rides ++ lefts
    main

main :: IO ()
main = do
    n <- read <$> getLine :: IO Int
    C.when (n /= 0) $ solve n




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

ans = []

for i in range(n):
    j = n-i
    count = 0
    itr = 2
    while(1) :
        s =j * itr
        if s > n :
            break
        count += ans[n-1-(s-1)]
        itr +=1
    j = n -i
    if (count%2 == a[j-1]):
        ans.append(0)
    else:
        ans.append(1)

ans.reverse()
print(sum(ans))
for i,j in enumerate(ans):
    if j == 1:
        print(i+1, end=" ")
        


Measured memory_bytes: 71392
import java.util.*;
public class Main {
	static Scanner sc = new Scanner(System.in);
	static int n, m;
	static int[] t;
	public static void main(String[] args) {
		while(read()){
			solve();
		}

	}
	static boolean read(){
		n = sc.nextInt(); m = sc.nextInt();
		if( n == 0 && m == 0 )return false;
		t = new int[n+m];
		for(int i = 0; i < t.length; i++){
			t[i] = sc.nextInt();
		}
		return true;
	}
	static void solve(){
		Arrays.sort(t);
		int max = t[0];
		int diff = 0;
		
		for(int i = 0; i < t.length -1; i++){
			diff = t[i+1] - t[i];
			if( diff > max)max = diff;
		}
		System.out.println(max);
	}

}

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

long long int a[100001];

long long int minCost(long long int arr[], long long int& n, long long int i, long long int sum){
    if(i==n-1){
        return sum;
    }
    if(a[i+1]!=-1) return a[i+1];
    
        long long int x, y = INT_MAX, temp = sum;
    
    sum = abs(arr[i]-arr[i+1]);
    x = minCost(arr, n, i+1, sum);
    if(i!=n-2)x += sum;
    // sum -= abs(arr[i]-arr[i+1]);
    
    if(i+2<n){
        sum = abs(arr[i]-arr[i+2]);
        y = minCost(arr, n, i+2, sum);
        if(i!=n-2 && i!= n-3)y += sum;
        // sum -= abs(arr[i]-arr[i+2]);
    }
    
    a[i+1] = min(x, y);
    return a[i+1];
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    long long int n;
    cin >> n;
    memset(a, -1, sizeof(a));
    long long int m = 0;
    long long int arr[n];
    
    for(long long int i = 0; i < n; i++){
        cin >> arr[i];
    }
    
    m = minCost(arr, n, 0, m);
    
    cout << m;
    
    return 0;
}

Measured memory_bytes: 9600
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#define ll long long
//vector<int> g1;
//g1.push_back(i);

using namespace std;

int main()
{
	int n;
	cin >> n;
	int frbc[10][10];
	for (int i=1;i<10;i++)
	{
		for (int j=1;j<10;j++)
		{
			frbc[i][j] = 0; 
		}
	}
	for (int i=1;i<=n;i++)
	{
		if (i%10!=0)
		{
			int a = i;
			while (a>=10)
			{
				a = a/10;	
			}	
			int b = i%10;
			frbc[a][b]++;
		}
	}
	int otpt = 0;
	for (int i=1;i<10;i++)
	{
		for (int j=1;j<10;j++)
		{
			otpt += frbc[i][j]*frbc[j][i];
		}
	}
	cout << otpt;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define mod 1000000007LL
#define nax 200009LL
#define FOR(i,n,m) for(int i = (n); i < (m); i++)
#define REP(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define all(v) v.begin(),v.end()
#define sz(v) int(v.size())

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

const ll N=1e6;

int main(){
	fastio;

	ll a, b; cin>>a>>b;

    ll x=a, y=b;
    
    set<ll> s;
    
    for(ll i=2; i<=N; i++){
        if(a%i==0) s.insert(i);
        while(a%i==0){
            a/=i;
        }
    }
    if(a>1) s.insert(a);

    for(ll i=2; i<=N; i++){
        if(b%i==0) s.insert(i);
        while(b%i==0){
            b/=i;
        }
    }
    if(b>1) s.insert(b);
    ll ans=0;
    for(ll j : s){
        if(x%j==0 && y%j==0) ans++;
    }

    cout<<ans+1;


	return 0;
}


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

int main()
{
	int q;

	cin >> q;

	for (int i = 0; i < q; i++) {
		long long s;
		long double t;

		cin >> hex >> s;

		if (s > 0x80000000 - 1)
			cout << "-";

		s %= 0x80000000;
		t = s;
		t /= 128;

		if (s % 128 != 0)
			cout << setprecision(20) << t << endl;
		else
			cout << t << ".0" << endl;			
	}

	return 0;
}



Measured memory_bytes: 3252
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
typedef long long ll;


int main(void){
    int n;
    vector<int> G[100010];
    cin >> n;
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--;  b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    
    int x[100010];
    queue<int> que;
    que.push(0);  x[0] = 1;
    que.push(n - 1);  x[n - 1] = -1;
    
    while (que.size() != 0) {
        int k = que.front();
        for (int i = 0; i < G[k].size(); i++) {
            if (x[G[k][i]] == 0) {
                x[G[k][i]] = x[k];
                que.push(G[k][i]);
                //cout << k << " " << G[k][i] << endl;
            }
        }
        que.pop();
    }
    
    int f = 0, s = 0;
    for (int i = 0; i < n; i++) {
        //cout << x[i] << endl;
        if (x[i] == 1) f++;
        else s++;
    }
    
    if (f > s) cout << "Fennec" << endl;
    else cout << "Snuke" << endl;
    
}


Measured memory_bytes: 6272
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
typedef long long ll;
ll fac[200005], inv[200005], invfac[200005];
int p[200005];
int n;
ll SZ[200005], ANS[200005], ans[200005],total[200005];
vector<int> adjlist[200005];
ll exp(int a, int x){
    if (x == 0) return 1;
    ll p = exp(a,x/2);
    p *= p;
    p %= mod;
    if (x & 1){
        p *= a;
        p %= mod;
    }
    return p;
}
void dp(int u){
    int sz = 1;
    ll ans = 1;
    for (auto v: adjlist[u]){
        if (v==p[u])continue;
        p[v] = u;
        dp(v);
        sz += SZ[v];
        ans *= invfac[SZ[v]]; ans %= mod;
        ans *= ANS[v]; ans %= mod;
    }
    ans *= fac[sz-1]; ans %= mod;
    SZ[u] = sz;
    ANS[u] = ans;
}
void dp2(int u){
    ll finalans = fac[n-1];
    for (auto v : adjlist[u]){
        if (v == p[u]){
            ll newans = ans[v];
            newans *= invfac[n-1]; newans %= mod;
            newans *= fac[SZ[u]]; newans %= mod;
            newans *= exp(ANS[u],mod-2); newans %= mod;
            int newsz = n-SZ[u];
            newans *= fac[newsz-1]; newans %= mod;
            finalans *= newans; finalans %= mod;
            finalans *= invfac[newsz]; finalans %= mod;
        }
        else{
            finalans *= ANS[v]; finalans %= mod;
            finalans *= invfac[SZ[v]]; finalans %= mod;
        }
    }
    ans[u] = finalans;
    for (auto v : adjlist[u]){
        if (v == p[u]) continue;
        dp2(v);
    }
}
int main(){
    scanf("%d",&n);
    fac[0] = inv[0] = invfac[0] =1;
    for (int i = 1; i <= n; i++){
        fac[i] = (fac[i-1]*i)%mod;
        inv[i] = exp(i,mod-2);
        invfac[i] = (invfac[i-1]*inv[i])%mod;
    }
    for (int i = 1; i < n; i++){
        int a,b;
        scanf("%d%d",&a,&b);
        adjlist[a].push_back(b);
        adjlist[b].push_back(a);
    }
    p[1] = 0;
    dp(1); dp2(1);
    for (int i = 1; i <= n; i++){
        printf("%lld\n",ans[i]);
    }

}


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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define big ((ll)(1e9)+7)

int main(){
    ll n,k;
    cin >> n >> k;
    vector<ll> h;
    for (ll i = 0;i < n;i++)
    {
      ll H;
      cin >> H;
      h.push_back(H);
    }
    sort(h.rbegin(),h.rend());
    if(n > k)
    {
      for(ll i = 0;i < k;i++)
      {
        h[i] = 0;
      }
    }
    else
    {
      cout << 0 << endl;
      return 0;
    }
    ll sum = 0;
    for(ll i = 0;i < n;i++)
    {
      sum += h[i];
    }
    cout << sum << endl;
}


Measured memory_bytes: 2420
#include <map>
#include <string>
#include <iostream>
#include <cstdlib>
using namespace std;

int main() {
  //N, M
  int Length, RuleCount;
  cin >> Length >> RuleCount;

  if (Length == 1 && RuleCount == 0) {
    cout << "0" << endl;
    return 0;
  }

  map<int, int> Rules;

  for (int i = 0; i < RuleCount; i++) {
    int Pos, Number;
    cin >> Pos >> Number;

    //Rules.contains(Pos)
    if (Rules.find(Pos) != Rules.end()) {
      //すでに前に定義された値を出して比較して、同じじゃなければ
      //(同じ桁に複数の条件が出されていたら）弾く

      int AlreadyRegisteredPos = Rules.at(Pos);
      if (Number != AlreadyRegisteredPos) {
        cout << "-1" << endl;
        return 0;
      } else {
        continue;
      }
    }
    
    Rules.insert(make_pair(Pos, Number));
  }

  string answer = "";
  for (int i = 0; i < Length; i++) {
    if (Rules.find(i+1) != Rules.end()) {
      int RegisteredNumber = Rules.at(i+1);
      answer += to_string(RegisteredNumber);
    } else {
      answer += to_string(i == 0 ? 1 : 0);
    }
  }

  //頭が0とかで長さが変わる場合を考える
  int answeri = stoi(answer);
  if (to_string(answeri).length() != Length) {
    cout << "-1" << endl;
    return 0;
  }

  cout << answer << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ii pair<int, int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define uni(v) v.erase(unique(v.begin(), v.end()), v.end())
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (ll) a / __gcd(a, b) * b
#define what_is(x) cerr << #x << " is " << x << endl;

using namespace std;

void write();
template <typename T, typename... Args>
void write(T x, Args... args);
template <typename T>
void print_all(vector<T>& a);

void solve() {
    ll n, a, b;
    cin >> n >> a >> b;
    cout << n / (a + b) * a + min(a, n % (a + b)) << '\n';
}

int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    // freopen("in", "r", stdin);

    int t = 1;
    // cin >> t;
    while (t--) solve();

    return 0;
}

void write() { cout << "\n"; }
template <typename T, typename... Args>
void write(T x, Args... args) {
    cout << x << ' ';
    write(args...);
}
template <typename T>
void print_all(vector<T>& a) {
    for (int i = 0; i < a.size(); ++i) cout << a[i] << " \n"[i == a.size() - 1];
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n,m=mii()
arr=llint(n)

arr.sort()
ncnt=0
mcnt=0

for i in range(n):
    if ncnt ==m:
        continue
    elif ncnt + arr[i][1]<m:
        ncnt+=arr[i][1]
        mcnt+=arr[i][0]*arr[i][1]

    elif ncnt + arr[i][1]>=m:
        mcnt+=(m-ncnt)*arr[i][0]
        ncnt=m
print(mcnt)

Measured memory_bytes: 81496