akhauriyash/Code-Regression huggingface dataset:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from operator import itemgetter
from collections import defaultdict,deque

n,k = map(int,readline().split())
chk = []
for i in range(n):
  t,d = map(int,readline().split())
  chk.append((t,d))
chk = sorted(chk,key=itemgetter(1),reverse=True)

T = defaultdict(int)
d = deque()
s = set()
ans = []
aa = 0
for i in range(k):
  p,q = chk[i]
  T[p] += 1
  if T[p] > 1:
    d.append(q)
  s.add(p)
  aa += q
  
l = len(s)
aa += l**2
if k == n or l == k:
  print(aa)
  exit()
  
ans = aa
cnt = k-l
for p,q in chk[k:]:
  if T[p] == 0:
    T[p] += 1
    P = d.pop()
    aa -= P
    aa += q+2*l+1
    l += 1
    cnt -= 1
    ans = max(ans,aa)
  if cnt == 0:
    break
    
print(ans)

Measured memory_bytes: 101984
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    x = S()
    s = 0
    ans = len(x)
    for i in x:
        if i == "S":
            s += 1
        else:
            if s > 0:
                s -= 1
                ans -= 2
    print(ans)
    return

#B
def B():
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    A()


Measured memory_bytes: 63728
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

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

fn main() {
    input! {
        h: usize,
        w: usize,
        k: usize,
        board: [chars;h],
    }

    let mut ans: usize = usize::max_value();

    for bit in 0..(1 << (h - 1)) {
        let mut splited_board = std::vec::Vec::with_capacity(h);
        let mut latest_i = 0;
        for i in 0..h {
            if bit & 1 << i != 0 || i == h - 1 {
                let tmp = (0..w)
                    .map(|j| {
                        (&board[latest_i..(i + 1)])
                            .iter()
                            .map(|c| if c[j] == '1' { 1 } else { 0 })
                            .sum::<usize>()
                    })
                    .collect::<std::vec::Vec<_>>();
                splited_board.push(tmp);
                latest_i = i + 1;
            }
        }
        let mut split_count = splited_board.len() - 1;

        let mut sums = vec![0; splited_board.len()];
        'inner: for x in 0..(w - 1) {
            let mut over = false;
            for i in 0..splited_board.len() {
                if splited_board[i][x] > k {
                    split_count = usize::max_value();
                    break 'inner;
                }

                sums[i] += splited_board[i][x];
                if sums[i] + splited_board[i][x + 1] > k {
                    over = true;
                }
            }

            if over {
                split_count += 1;
                sums = vec![0; splited_board.len()];
            }

            if split_count > ans {
                split_count = usize::max_value();
                break;
            }
        }
        // println!("count = {}", split_count);

        ans = std::cmp::min(split_count, ans);
    }
    println!("{:?}", ans);
}

Measured memory_bytes: 4352
N,M,a,*A=`dd`.split.map &:to_i
s=[x=0]*9**6
A.map{|b|c=b;a>b&&b+=M;x+=b-a
[0,M].map{|m|s[m-~a]+=1;s[m+b]+=a-b;s[m-~b]+=b+~a}
a=c}
2.times{c=0;s=s.map{|s|c+=s}}
p x-s.max

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

using namespace std;
using ll = long long;

int main(int argc, const char * argv[]) {
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;
    cin >> N;
    
    ll maxMSum = 0;
    for (int i = 0; i < N; ++i)
    {
        maxMSum += i;
    }
    
    cout << maxMSum << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
int N,M;
int x[100100];
int y[100100];
int solve(){
    scanf("%d %d",&N,&M);
    if(N==0&&M==0)return 1;
    for(int i=1;i<=N;i++)scanf("%d",&x[i]);
    for(int i=1;i<=M;i++)scanf("%d",&y[i]);
    for(int i=1;i<=N;i++)x[i]+=x[i-1];
    for(int i=1;i<=M;i++)y[i]+=y[i-1];
    vector<int> vx,vy;
    for(int i=0;i<N;i++){
        for(int j=i+1;j<=N;j++){
            vx.pb(x[j]-x[i]);
        }
    }
    for(int i=0;i<M;i++){
        for(int j=i+1;j<=M;j++){
            vy.pb(y[j]-y[i]);
        }
    }
    sort(all(vx));
    int ans = 0;
    for(int i=0;i<vy.size();i++){
        ans += upper_bound(all(vx),vy[i])-lower_bound(all(vx),vy[i]);
    }
    printf("%d\n",ans);
    return 0;
}
int main(){
    while(1){
        if(solve())return 0;
    }
    return 0;
}

Measured memory_bytes: 19860
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int main()
{
	SPEED
	int a, b, c;
	cin >> a >> b >> c;
	int result = c - (a-b);
	if (result < 0)
	{
		cout << 0;
	}
	else
	{
		cout << result;
	}
	return 0;
}

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

class Program
{
    static void Main(string[] args)
    {

            var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var n = input[0];
            var m = input[1];

            var s = Console.ReadLine();
            var t = Console.ReadLine();

            var gcd = GCD(n, m);
            var ss = n / gcd;
            var tt = m / gcd;
            for (int i = 0; i < gcd; i++)
            {
                if(s[ss * i] != t[tt * i])
                {
                    Console.WriteLine("-1");
                    return;
                }
            }
            Console.WriteLine((long)ss * tt * gcd);
    }


        static int GCD(int x, int y)
        {
            if (x < y) return GCD(y, x);
            var r = x % y;
            if (r == 0) return y;
            return GCD(y, r);
        }

}



Measured memory_bytes: 13664
import java.util.*;

public class Main{
    int n,m;
    int[] d,p;

    public static void main(String[] args){
	new Main().solve();
    }

    void solve(){
	Scanner sc = new Scanner(System.in);
	n = sc.nextInt();
	while(n!=0){
	    m = sc.nextInt();
	    d = new int[n];
	    p = new int[n];
	    for(int i=0 ;i<n; i++){
		d[i] = sc.nextInt();
		p[i] = sc.nextInt();
	    }

	    //ツ甘コツ妥陳値ツつェツ妥・ツつォツつ「ツ渉?づ可陛?づ堕妥鳴つヲ
	    for(int i=0; i<n; i++){
		int max = p[i];
		int maxIndex = i;
		for(int j=i; j<n; j++){
		    if(max<p[j]){
			max = p[j];
			maxIndex = j;
		    }
		}
		int tmp = p[maxIndex];
		p[maxIndex] = p[i];
		p[i] = tmp;
		tmp = d[maxIndex];
		d[maxIndex] = d[i];
		d[i] = tmp;
	    }

	    int i=0;
	    while(d[i]>0 && m>0){
		d[i]--;
		m--;
		if(d[i]==0 && i+1<n)i++;
	    }
	    
	    long ans = 0;
	    for(i=0; i<n; i++){
		if(d[i]>0){
		    ans += d[i]*p[i];
		}
	    }

	    System.out.println(ans);

	    n = sc.nextInt();
	}
    }
}

Measured memory_bytes: 13000
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>
#include <cmath>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;


int32_t N;
std::string S[2000000];

std::multimap<int32_t, int32_t> plus;
std::multimap<int32_t, int32_t> minus;


int main()
{
    using std::endl;
    in.sync_with_stdio(false);
    out.sync_with_stdio(false);
    in.tie(nullptr);
    out.tie(nullptr);

    in >> N;
    for (size_t i = 0; i < N; i++)
    {
        in >> S[i];
    }

    for (size_t i = 0; i < N; i++)
    {
        int now = 0;
        int min = 0;
        for (auto& c : S[i]) {
            if (c == '(') {
                ++now;
            }
            else {
                min = std::min(min, --now);
            }
        }

        if (now >= 0) {
            plus.insert({ -min, now });
        }
        else {

            now = 0;
            min = 0;
            for (int j = S[i].size() - 1; j >= 0; j--)
            {
                auto& c = S[i][j];
                if (c == ')') {
                    ++now;
                }
                else {
                    min = std::min(min, --now);
                }

            }
            minus.insert({ -min, now });
        }
    }

    int now1 = 0;
    for (auto& p : plus)
    {
        if (p.first <= now1) {
            now1 += p.second;
        }
        else {
            out << "No\n";
            return 0;
        }
    }
    int now2 = 0;
    for (auto& p : minus)
    {
        if (p.first <= now2) {
            now2 += p.second;
        }
        else {
            out << "No\n";
            return 0;
        }
    }


    if (now1 != now2) {
        out << "No\n";
        return 0;
    }
    out << "Yes\n";
    return 0;
}
#endif


Measured memory_bytes: 96728
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int taro=0;
		int hanako=0;
		String first = "";
		String second = "";
		for(int i=0;i<n;i++){
			first = scan.next();
			second = scan.next();
			if((first.compareTo(second))>0)
				taro+=3;
			else if((first.compareTo(second))<0)
				hanako+=3;
			else{
				taro++;
				hanako++;
			}
		}
		System.out.println(taro+" "+hanako);
	}
}

Measured memory_bytes: 20820
//** aman**/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define dl          double
#define hell        1000000007
#define endl        '\n'
#define rep(i,a,b) for(int i=a;i<b;i++)
#define lb lower_bound
#define ub upper_bound
#define bs          binary_search
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
const ll N=100005;
const ll P=67,g=53;
const ll m=1e9+7;
ll pp[N],h[N]={0},n,gg[N],b[N]={0};
string s;
void lli(){
	pp[0]=1;
	for(ll i=1;i<N;i++){
		pp[i]=(pp[i-1]*P)%m;
	}
	gg[0]=1;
	for(ll i=1;i<N;i++){
		gg[i]=(gg[i-1]*g)%m;
	}	
	for(ll i=1;i<=n;i++){
		h[i]=(h[i-1]+(s[i-1]-'a'+1)*pp[i]);
		b[i]=(b[i-1]+(s[i-1]-'a'+1)*gg[i]);
	}
}
ll chk(ll mid){
	map<pair<ll,ll>,ll> mm;
	for(ll i=0;i<n-mid+1;i++){
		ll cur1=(h[i+mid]-h[i]+m)%m;
		ll cur2=(b[i+mid]-b[i]+m)%m;
		cur1=cur1*pp[n-i]%m;
		cur2=cur2*gg[n-i]%m;
		pair<ll,ll> cur={cur1,cur2};
		//cout<<cur<<" ";
		if(mm[cur]!=0){
			if(mm[cur]<i+2)return 1;
		}
		else{
			mm[cur]=i+mid+1;
		}
	}
	return 0;
}
int main(){
	cin>>n>>s;
	lli();
	ll s=0,e=n/2+1,mid,x;
	//chk(2);
	while(s<=e){
		mid=(s+e)/2;
		if(chk(mid)){
			x=mid;
			s=mid+1;
		}
		else{
			e=mid-1;
		}
	}
	cout<<x<<endl;
}

Measured memory_bytes: 2176
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int n, m;
    int k;
    cin >> n >> m;
    vector<int> a(m*n);

    for(size_t i = 0; i < n; i++)
    {
        cin >> k;
        for(size_t j = 0; j < k; j++)
        {
           cin >> a[i*m+j];
        }        
    }
    int ans = 0;
    int counter = 0;
    for(size_t i = 0; i < a.size(); i++)
    {
        for(size_t j = 0; j < a.size(); j++)
        {
            if(a[i] == a[j] && a[i] != 0) counter ++ ;
        }
        if(counter != n) counter = 0;
        else{
            ans ++;
            counter = 0;
        }
        
    }
    cout << ans/n << endl;
    
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
	static Scanner sc = new Scanner(System.in);
	
	public static void main(String[] args) {
		Stack<Integer> stk = new Stack<Integer>();
		String s;
		while(sc.hasNext()){
			s = sc.next();
			if(s.equals("+")){
				int n1 = stk.pop();
				int n2 = stk.pop();
				stk.push(n1+n2);
			}
			else if(s.equals("-")){
				int n1 = stk.pop();
				int n2 = stk.pop();
				stk.push(n2-n1);
			}
			else if(s.equals("*")){
				int n1 = stk.pop();
				int n2 = stk.pop();
				stk.push(n1 * n2);
			}
			else{
				stk.push(Integer.valueOf(s));
			}
		}
		cout(stk.pop());
	}
	
	
	
	public static boolean isPrime(int n){
		for(int i=2;i<=n*n;i++){
			if(n%i==0) return true;
		}
		return false;
	}
	public static int gcd(int a,int b){
		if(a%b==0) return b;
		else return gcd(b,a%b);
	}
	public static void showary(int[] ary){
		for(int i=0;i<ary.length-1;i++){
			System.out.print(ary[i]+" ");
		}
		cout(ary[ary.length-1]);
	}
	public static void cout(String n){
		System.out.println(n);
	}
	
	public static void cout(int n){
		System.out.println(n);
	}
	public static void cout(boolean n){
		if(n==true){
			cout("true");
		}else{
			cout("false");
		}
	}
}

Measured memory_bytes: 26408
#include<iostream>
using namespace std;
int main() {
	int n,j;
	long long k = 100000;
	cin >> n;
	for (int i = 0; i < n; i++) {
		k += k / 20;
		j = k % 1000;
		if (j != 0) {
			k += 1000 - j;
		}
	}
	cout << k << endl;
	return 0;
}

Measured memory_bytes: 1156
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<string.h>
#include<complex>
#include<math.h>
using namespace std;
typedef long long int llint;
#define rep(i,n) for(int i=0;i<n;i++)

bool check(char a, char b) {
	return a > b;
}

int kuraiwa(int n) {
	int ans = 0;
	while (n > 0) {
		ans += n % 10;
		n /= 10;
	}
	return ans;
}

int main() {
	int a, b;
	char s[20];
	cin >> a >> b;
	cin >> s;
	rep(i, a) {
		if (48 > s[i] || s[i] > 57) {
			cout << "No" << endl;
			return 0;
		}
	}
	if (s[a] != '-') {
		cout << "No" << endl;
		return 0;
	}
	for (int i = a + 1;i < a + b + 1;i++) {
		if (48 > s[i] || s[i] > 57) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
a=Counter(v[0::2]).most_common()
b=Counter(v[1::2]).most_common()
a.append([0,0])
b.append([0,0])
if a[0][0]!=b[0][0]:
    print(n-(a[0][1]+b[0][1]))
else:
    print(min(n-(a[1][1]+b[0][1]),n-(a[0][1]+b[1][1])))

Measured memory_bytes: 20572
'use strict'

const main = (input) => {
    const S = input.split('\n')[0].split('').reverse()
    for(let i = 0; i <= 200; i++ ){
        S.shift()
        if(S.length % 2 !== 0) continue
        let first = S.slice(0, S.length / 2)
        let last = S.slice(S.length / 2)
        if(first.join('') === last.join('')){
            console.log(S.length)
            return
        }
    }
}

main(require('fs').readFileSync('/dev/stdin', 'utf-8'))

Measured memory_bytes: 7372
N = int(input())
W = list(input() for i in range(N))
ans = 'Yes'
for i in range(N-1):
    if W[i][-1] != W[i+1][0]:
        ans = 'No'
W.sort()
for i in range(N-1):
    if W[i] == W[i+1]:
        ans = 'No'
print(ans)


Measured memory_bytes: 3060
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(0,-1),(1,0),(0,1),(-1,0)]
ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

def main():
    n = I()
    a = LI()

    return max(a) - min(a)



print(main())


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

int main() {
	int a = 0;
	int b = 0;
	cin >> a >> b;
	int q = a + b;
	int w = a - b;
	int e = a * b;

	int Max = max(q, w);
	int ans = max(Max,e);

	cout <<ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <string>
#include <queue>
#include <numeric>
#include <ctype.h>
#include <limits>
#include <iomanip>

#define rep(i,n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
using namespace std;

typedef long long ll;

int main()
{
	/*string s, t, u;
	int a, b;
	cin >> s >> t >> a >> b >> u;
	if (s == u)a--;
	else b--;
	cout << a << " " << b;*/


	/*string s;
	cin >> s;
	rep(i, s.size()) {
		cout << "x";
	}*/


	int n;
	cin >> n;
	vector<int>a(n);
	rep(i, n)cin >> a[i];
	sort(all(a));
	rep(i, n - 1) {
		if (a[i] == a[i + 1]) {
			puts("NO");
			return 0;
		}
	}
	puts("YES");



	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    vector<vector<char> >v(n,vector<char>(m));
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++){
            cin>>v[i][j];
        }
    }
    for(int i=0;i<n+2;i++)
    {
        for(int j=0;j<m+2;j++){
            if(i==0){
                cout<<"#";
                continue;
            }
            if(i==n+1){
                cout<<"#";
                continue;
            }
            if(j==0){
                cout<<"#";
                continue;
            }
            if(j==m+1){
                cout<<"#";
                continue;
            }
            cout<<v[i-1][j-1];
        }
        cout<<endl;
    }
}

Measured memory_bytes: 3556
#include <stdio.h>
#include <stdlib.h>
 
int main (void) {
  int a = 0;
  int b = 0;
  int sum = 1;
  int resoult = 0;
  
  scanf("%d %d", &a, &b);
  
  while (sum < b) {
    sum += a-1;
    resoult++;
  }
  
  printf("%d", resoult);
  
  return 0;
}

Measured memory_bytes: 128
//03
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int n;
string d[4][6];

void rot(int x,string *d){
  int r[][4]={{0,1,5,4},{0,2,5,3},{1,3,4,2}};
  string t=d[r[x][0]];
  d[r[x][0]]=d[r[x][1]];
  d[r[x][1]]=d[r[x][2]];
  d[r[x][2]]=d[r[x][3]];
  d[r[x][3]]=t;
}

int dfs(int r){
  if(r==n){
    int s=0;
    for(int i=0;i<6;i++){
      int m=1;
      for(int j=0;j<n;j++){
	int c=0;
	for(int k=0;k<n;k++){
	  c+=d[j][i]==d[k][i];
	}
	m=max(c,m);
      }
      s+=n-m;
    }
    return s;
  }else{
    int m=99;
    for(int i=0;i<6;i++){
      rot(i&1,d[r]);
      for(int j=0;j<4;j++){
	rot(2,d[r]);
	m=min(m,dfs(r+1));
      }
    }
    return m;
  }
}

int main(){
  while(cin>>n,n){
    for(int i=0;i<n;i++){
      for(int j=0;j<6;j++){
	cin>>d[i][j];
      }
    }
    cout<<dfs(0)<<endl;
  }
  return 0;
}

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

int main(){
int N;
  cin>>N;
  vector<int>a(N);
  for(int i=0; i<N; i++){
  cin>>a[i];
  }
  
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  
  int alice=0;
  int bob=0;
  for(int i=0; i<N; i+=2){
   alice+=a[i];
  }
  for(int i=1; i<N; i+=2){
   bob+=a[i];
  }  
  cout<<alice-bob<<endl;
  
}

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

using namespace std;
typedef long long ll;

#define INF (long long)(1e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

int main(void)
{
  ll x,y; cin >> x >> y;
  ll cnt = 0;
  while(x <= y) {
    x *= 2;
    cnt ++;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pii pair<int,int>
#define fi first 
#define se second 
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define pb push_back
#define faster ios_base::sync_with_stdio(0);cin.tie(0);
#define mem(a,v) memset(a,v,sizeof(a))
const ll INF=1e18;
const int mod=998244353;
const int iinf=1e9+10;
const int xd[4]={1,0,-1,0},yd[4]={0,1,0,-1};
const int mxN=2e5;
ll dp[mxN+1],c[10],dp1[mxN+1];
pii a[mxN+1];
ll g(int l,int r){
    //cout<<"r="<<r<<" "<<dp1[r]<<"\n";
    //cout<<"l-1="<<l-1<<" "<<dp1[l-1]<<"\n";
    if(l<=0)l=0;
    return ((dp1[r]-dp1[l-1])%mod+mod)%mod;
}
int main()
{
    faster
    int n,k;
    cin>>n>>k;
    for(int i=0;i<k;i++)
        cin>>a[i].fi>>a[i].se;
    dp[0]=1;
    dp1[0]=1;
    for(int i=1;i<=n-1;i++){
        for(int j=0;j<k;j++){
            dp[i]=(dp[i]+g(i-a[j].se,i-a[j].fi))%mod;
        }
        dp1[i]=(dp1[i-1]+dp[i])%mod;
    }
    cout<<dp[n-1];
}

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

using namespace std;

bool equal(string const &s, int m)
{
    for (int i = 0; i < m / 2; ++i)
        if (s[i] != s[i + m / 2])
            return false;
    return true;
}

int solve(string const &s)
{
    int n = s.size();
    for (int i = n - 2; i > 0; i -= 2)
    {
        if (equal(s, i))
            return i;
    }
    return 0;
}

int main(void)
{
    string s;

    cin >> s;

    cout << solve(s) << endl;
    return 0;
}


Measured memory_bytes: 3612
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
#define low lower_bound
#define upp upper_bound
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define Rep(i,n) for (int i = (int)(n); i >= 0; i--)
#define all(vec) vec.begin(),vec.end()
#define rever(vec) reverse(all(vec));
#define cend cout << endl;
#define prique(T) priority_queue<T,vector<T>,greater<T>>
struct edge { int to, cost; };
typedef pair<int, int> P;
const int mod = 1e9 + 7, inf = 1e16;

int modpow(int x, int n) {
	if (n == 0) return 1;
	if (n % 2) return (x * modpow(x * x % mod, n / 2) % mod + mod) % mod;
	return (modpow(x * x % mod, n / 2) + mod) % mod;
}

int fact(int n) {
	int ans = 1;
	rep(i, n) {
		ans *= (i + 1);
		ans %= mod;
	}
	return ans;
}

int comb(int n, int r) {
	if (n < r) swap(n, r);
	if (n - r < r) r = n - r;
	return fact(n) * modpow(fact(n - r), mod - 2) % mod * modpow(fact(r), mod - 2) % mod;
}

int gcd(int a, int b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

template <typename T>
void greater_sort(vector<T>& vec) {
	sort(all(vec), greater<T>());
	return;
}

int h, w;
string k = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
signed main() {
	cin >> h >> w;
	rep(i, h) {
		rep(j, w) {
			string s;
			cin >> s;
			if (s == "snuke") {
				cout << k[j] << i + 1 << endl;
				break;
			}
		}
	}
}

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

int main(){
    long long k,n;
    vector<long long> p;
    cin >>n >>k;
    rep(i,n){
        long long t;
        cin >> t;
        p.push_back(t);
    }
    sort(p.begin(),p.end());
    long long ans = 0;
    rep(i,k){
        ans += p.at(i);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main()
{
    int n, h, w;
    cin >> n >> h >> w;
    int ans = 0;
    rep(i, 0, n) {
        int a, b;
        cin >> a >> b;
        if (h <= a && w <= b) ans ++;
    }
    cout << ans << endl;
}


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

int main()
{
    int a,b,c,d,e;
    cin >> a >> b >> c >> d >> e; 
    if(a==0)
        cout << 1;
    else if(b==0)
        cout << 2;
    else if (c == 0)
        cout << 3;
    else if (d == 0)
        cout << 4;
    else
        cout << 5;
    
    return 0;
}


Measured memory_bytes: 3556
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <climits>
#include <tuple>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#define rep(i, n) for(Int (i) = 0; (i) < (n); (i)++)
using namespace std;
using Int = int32_t;
using Uint = uint32_t;
constexpr long long int mod = 1e9 + 7;


int main() {

	Int K, X; cin >> K >> X;

	cout << ((K * 500 >= X) ? "Yes" : "No") << endl;

}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define int long long
#define endl '\n'
using namespace std;
 
typedef long long ll;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cout << *it << " = " << a << endl;
	err(++it, args...);
}
 
#define read(a) int a; cin >> a;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define readarr(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}
 
#define print(a) cout << a << endl;
#define printarr(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;} cout << endl;
#define all(v) v.begin(), v.end()
#define sz(v) (int)(v.size())
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define vvi vector <vi>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll N = 2e3 + 1;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);	
	
	readb(k, n);
	readarr(a, n);
	int d = 0;
	FOR (i, 1, n-1) d = max(d, a[i+1] - a[i]);
	d = max(d, k - a[n] + a[1]);
	cout << k - d;
}















Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
const lli INF = 1e9 + 100;
const lli INF64 = (1LL << 61) + 100;
const lli MOD = 1e9 + 7;
const lli MH1 = 1599614977, MH2 = 2034417103, MH3 = 1090250123, MH4 = 2024491871; 
lli bpow(lli baseee, lli exponenttt) {
	if(exponenttt < 0) return 0;
	lli res = 1;
	baseee %= MOD;
	while (exponenttt > 0) {
		if ((exponenttt & 1) == 1) res = (res*baseee) % MOD;
		baseee = (baseee*baseee) % MOD;
		exponenttt >>= 1;
	}
	return res;
}
lli multInverse(lli a) {//if_mod_is_prime
	return bpow(a, MOD - 2);
}
lli divm(lli a, lli b) {//if_mod_is_prime
	return (a * multInverse(b)) % MOD;
}
lli multm(lli a, lli b) {
	return (a * b) % MOD;
}
lli subm(lli a, lli b) {
	a += MOD;
	lli r = a - b;
	if(r >= MOD) return r - MOD;
	return r;
}
lli addm(lli a, lli b) {
	lli r = a + b;
	if(r >= MOD) return r - MOD;
	return r;
}
set<lli> anss;
void check(lli nn, lli i) {
	while(nn % i == 0) nn /= i;
	if((nn - 1) % i == 0) anss.insert(i);
}
signed main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//	freopen("input.txt", "r", stdin);
	//	freopen("output.txt", "w", stdout);
	lli n;
	cin >> n;
	if(n == 2) {
		cout << "1\n";
		return 0;
	}
	anss.insert(n);
	for(lli i = 2; i*i <= n; i++) {
		if(n % i != 0) continue; 
		check(n, i);
		check(n, n/i);
	}
	lli mn = n - 1;
	anss.insert(mn);
	for(lli i = 2; i*i <= mn; i++) {
		if(mn % i == 0) {
			anss.insert(i);
			anss.insert(mn / i);
		}
	}
	cout << anss.size() << "\n";
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int X = sc.nextInt();
      
 	if(X == 7){
	System.out.println("YES");
    }else if(X == 5){
	System.out.println("YES");
    }else if(X == 3){
	System.out.println("YES");
    }else {
	System.out.println("NO");      
    }
  }
}

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

aves = [(i + 1) / 2 for i in P]
max_ave = sum(aves[0:K])
temp = max_ave
for i in range(N - K):
    temp -= aves[i]
    temp += aves[i + K]
    if temp > max_ave:
        max_ave = temp
print(max_ave)


Measured memory_bytes: 25172
#include<bits/stdc++.h>
using namespace std;
#define ll long long int;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main()
{
	fastio;
	char s[1000];
	cin>>s;
	if(s[strlen(s)-1]=='s'){
	
		cout<<s<<"es";
	}
	else cout<<s<<"s";
}

Measured memory_bytes: 3580
#include<iostream>
#include<algorithm>

using namespace std;

int n, x, y, b, p;

int main(){
	while(cin >> n, n){
		int res = 0;
		bool ok = false;
    	for(int i = 0;i < n;i++){
			cin >> x;
			if(x > 0)res++;
			if(x > 1)ok=true;
		}
		if(ok)cout << res + 1 << endl;
		else cout << "NA" << endl;
	}	
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){
	
	int n, a, b;
	cin >> n >> a >> b;
	
	int ans = 0;
	for(int i = 1; i <= n; i++){
		string s = to_string(i);
		int dsum = 0;
		
		for(int j = 0; j < s.length(); j++){
			dsum = dsum + s[j] - '0';
		
		}
		
		if(a <= dsum && dsum <= b) ans = ans + i;
	
	}
	
	
	cout << ans << endl;
	
	return 0;
}
/*
+++++ +++++ +++++ +++++
+++++ +++++ ++
>,[[-<->]]

*/


Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[][] A = new int[N][2];
		for(int i = 0; i < N; i++) {
			A[i][0] = sc.nextInt();
			A[i][1] = i+1;
		}
		Arrays.sort(A, (x,y) -> x[0]-y[0]);
		for(int i = 0; i < N; i++)
			System.out.print(A[i][1]+" ");
		System.out.println();

	}

}

Measured memory_bytes: 65480
#include <stdio.h>
#include <set>
using namespace std;
int main(){
    int n,temp;
    set<int> s;
    scanf("%d",&n);
    while(n--){
        scanf("%d",&temp);
        s.insert(temp);
    }
    scanf("%d",&n);
    while(n--){
        scanf("%d",&temp);
        if(s.find(temp)==s.end())printf("0\n");
        else printf("1\n");
    }
}


Measured memory_bytes: 7444
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int result = scanner.nextInt();;
		while (true) {
			String op = scanner.next();
			if (op.equals("=")) {
				System.out.println(result);
				break;
			}
			else if (op.equals("+")) {
				result += scanner.nextInt();
			}
			else if (op.equals("-")) {
				result -= scanner.nextInt();
			}
			else if (op.equals("*")) {
				result *= scanner.nextInt();
			}
			else if (op.equals("/")) {
				result /= scanner.nextInt();
			}
		}
		scanner.close();
	}

}



Measured memory_bytes: 26340
#include <vector>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

inline int read()
{
  int f = 1;
  int x = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    f = (ch == '-') ? -1 : 1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return f * x;
}

long long N;

int main()
{
  N = read();
  long long h;
  long long w;
  long long n;
  for (h = 1; h <= 3500; ++h) {
    for (w = 1; w <= 3500; ++w) {
      long long k = 4 * h * w - N * h - w * N;
      if (k > 0 && w * N * h % k == 0) {
        printf("%lld %lld %lld\n", h, w * N * h / k, w);
        return 0;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
int main(){
  int n,i,a;
  long long d[21]={0};
  long long e[21]={0};
  scanf("%d %d",&n,&a);
  d[a]=1;
  n--;
  while(--n){
    scanf("%d",&a);
    for(i=0;i<21;i++){
      if(d[i]==0)continue;
      if(i+a<21)e[i+a]+=d[i];
      if(-1<i-a)e[i-a]+=d[i];
    }
    for(i=0;i<21;i++){
      d[i]=e[i];
      e[i]=0;
    }
  }
  scanf("%d",&a);
  printf("%lld\n",d[a]);
  return 0;
}
    

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

ll digit(ll N){
  ll cnt = 0;
  while (N > 0) {
    N /= 10; cnt++;
  }
  return cnt;
}

void Main()
{
  ll N; cin >> N;
  ll sqrtN = sqrt(N);
  ll minDigit = 100;
  for (ll i = sqrtN; i > 0; i--) {
    if (N%i == 0) {
      ll bigger = max(digit(i), digit(N/i));
      minDigit = min(minDigit, bigger);
    }
  }
  cout << minDigit << endl;
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  Main();
  return 0;
}


Measured memory_bytes: 3672
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();

		int cnt = 0;
		for (int i = 0; i <= N; i++) {
			int num = i;
			int sum = 0;
			while(num > 0) {
				sum += num % 10;
				num /= 10;
			}
			if(A <= sum && sum <= B) cnt += i;
		}
		System.out.print(cnt);
	}
}

Measured memory_bytes: 21716
#define _LIBCPP_DEBUG 0
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9 + 7;


int main(void) {

    ll A,B; cin>>A>>B;
    ll GCD = __gcd(A,B);
    ll ans = 1;


    for (ll i = 2; i*i <= GCD; ++i) {

        if(GCD%i==0) {
            ans++;
            while (GCD % i == 0) {
                GCD /= i;
            }
        }
    }
    if(GCD!=1){
        ans++;
    }
    cout<<ans<<endl;
    return 0;

}

Measured memory_bytes: 256
def main():
    n,k = map(int,input().split(' '))
    n = n % k
    key = 0
    data = []
    while(key == 0):
        check = abs(n - k)
        for per in data:
            if(check == per):
                key = 1
        if(key == 0):
            data.append(check)
            n = check
        else:
            key = 1
    print(min(data))

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<algorithm>

int main(){

	int n;
	std::cin >> n;

	for (int i = 0; i < n; i++){
		std::string str, str2, res;
		std::cin >> str >> str2;

		std::reverse(str.begin(), str.end());
		std::reverse(str2.begin(), str2.end());

		bool up = 0;
		for (int i = 0; up || i < std::max(str.size(), str2.size()); i++){

			int a = 0, b = 0;

			if (str.size() > i)a = str[i] - '0';
			if (str2.size() > i)b = str2[i] - '0';

			if (up + a + b >= 10){
				res += (up + a + b - 10 + '0');
				up = 1;
			}
			else{
				res += (up + a + b + '0');
				up = 0;
			}
		}

		std::reverse(res.begin(), res.end());

		if (res.size() > 80)std::cout << "overflow" << std::endl;
		else std::cout << res << std::endl;
	}

	return 0;
}

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

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back

typedef long long ll;

const ll MOD = 1e9+7;
const ll INF = 1e9+5;

int n, m, k, a, b, c;
string s, t, r;
char c1, c2, c3;

int A[200005];
int B[200005];
int C[200005];

int main() {
	cin >> n;
	for (int i=0 ; i<n ; i++) {
		cin >>A[i];
	}
	int sol = INF;
	for (int i=1 ; i<=100 ; i++) {
		int cnt = 0;
		for (int j=0 ; j<n ; j++) {
			cnt += (i-A[j])*(i-A[j]);
		}
		sol = min(sol, cnt);
	}
	cout <<sol<<endl;
	return 0;
}

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

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

  int sum = 0;
  for (int i = 0; i < n; i++) sum += x[i];
  float ave = (float)sum / n;
  int int_ave = round(ave);

  long long min_sum = 0;
  for (int i = 0; i < n; i++) min_sum += (x[i] - int_ave) * (x[i] - int_ave);

  cout << min_sum << endl;
  return 0;
}


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

const int N=100005,P=1000000007;
int n,x[N];

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i)scanf("%d",x+i);
	int ans=1;
	for(int i=0,j=0;i<n;++i){
		while(j<n&&x[j+1]>=2*(j-i)+1)++j;
		ans=1LL*ans*(j+(j<n&&x[j+1]>=2*(j-i))-i)%P;
	}
	printf("%d\n",ans);
}


Measured memory_bytes: 640
#include <iostream>
#include <cmath>

using namespace std;

int main(){
    int a, b, c, k, maior;
    cin >> a >> b >> c >> k;

    if(a>b){
        if(a>c){
            maior=a;
            a=0;
        } else {
            maior=c;
            c=0;
        }
    } else {
        if(b>c){
            maior=b;
            b=0;
        } else {
            maior=c;
            c=0;
        }
    }

    for(int i=1;i<=k;i++){
        maior*=2;
    }

    cout << maior+a+b+c << endl;

    return 0;
}


Measured memory_bytes: 256
/*
 * main.cpp
 *
 *  Created on: 2020/04/08
 *      Author: SkAaO
 */

#include <iostream>
#include <vector>

using namespace std;

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

	vector<char> odd_string;

	for(int i = 0; i < (int)s.size(); i++){
		if((i + 1) % 2 == 1){
			odd_string.push_back(s.at(i));
		}
	}

	for(int i = 0; i < (int)odd_string.size(); i++){
		cout << odd_string[i];
	}
	cout << endl;

	return 0;
}



Measured memory_bytes: 640
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define ull unsigned long long
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
using namespace std;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int A, B;
	cin >> A >> B;
	cout << ceil(1.*B/A) << endl;
}



Measured memory_bytes: 3272
//ABC121-C
//with priority queue

#include<iostream>
#include <queue>
using namespace std;
typedef long long ll;

#include<vector>
#define pb push_back

#define rep(i, a, b) for(int i=(a); i<(b); i++)

int main(){
  ll N,M;
  ll Drinks, Pay=0;
  priority_queue<pair<ll,ll> , vector<pair<ll,ll> > , greater<pair<ll,ll> > > C;
  cin >> N >> M;
  
  rep(i, 0, N){
    ll a_temp,b_temp;
    cin >> a_temp >> b_temp;
    C.push(make_pair(a_temp,b_temp));
  }

  rep(i, 0, N){
    pair<ll,ll> temp = C.top();
    C.pop();
    if(M>temp.second){
      //cout<<temp.first<<" "<<temp.second<<endl;
      Pay+=temp.first*temp.second;
      M-=temp.second;
 
    }else{
      //cout<<temp.first<<" "<<temp.second<<" M"<<M<<endl;
      Pay+=temp.first*M;
      break;
    }
  }
  cout<<Pay<<endl;
  
  return 0;
}


Measured memory_bytes: 2420
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	ary := strings.Split(strings.TrimSpace(sc.Text()), " ")
	x, _ := strconv.Atoi(ary[0])
	y, _ := strconv.Atoi(ary[1])
	for 0 < y {
		if x < y {
			x, y = y, x
		}
		r := x % y
		if r == 0 {
			break
		}
		x = y
		y = r
	}
	fmt.Println(y)
}



Measured memory_bytes: 1124
#include <bits/stdc++.h>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)

using namespace std;
int N;
string S[100];
bool V;

bool repeat(int x){
	for(int i = 0; i < x; i++)
		if(S[i] == S[x]) return true;
	return false;
}

int main(void){
	//IO("test.in", "test.out");
	V = true;
	cin >> N >> S[0];
	for(int i = 1; i < N; i++){
		cin >> S[i];
		if(S[i][0] != S[i - 1][S[i - 1].length() - 1] || repeat(i)){
			V = false;
			break;
		}
	}
	if(V) printf("Yes\n");
	else printf("No\n");
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)

//ll X[100];
//ll Y[100];
pair<ll, ll> XY[100];
int main(){
    int N, K;
    cin >> N >> K;

    //map<ll, int> x2i;
    REP(i,N){
        ll x, y;
        cin >> x >> y;
        //X[i] = x;
        //Y[i] = y;
        //x2i[x] = i;
        XY[i] = make_pair(x, y);
    }

    sort(XY, XY+N);
    ll ans = LLONG_MAX;
    for(int li = 0; li < N; li++){
        pair<ll, ll> lxy = XY[li];
        ll lx = lxy.first;
        ll ly = lxy.second;
        vector<ll> vy;
        vy.push_back(ly);
        for(int ri = li+1; ri < N; ri++){
            pair<ll, ll> rxy = XY[ri];
            ll rx = rxy.first;
            ll ry = rxy.second;
            vy.push_back(ry);
            if(vy.size() < K) continue;
            ll width = rx - lx;
            ll height = LLONG_MAX;
            sort(vy.begin(), vy.end());
            for(int i = 0; i < vy.size()-K+1; i++){
                height = min(height, vy[i+K-1] - vy[i]);
            }
            ans = min(ans, height*width);
        }
    }

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


Measured memory_bytes: 256
n,k=map(int,input().split())
point=list(map(int,input().split()))
s=input()
t=[]
d={'r':0,'s':1,'p':2}
for x in s:
    t.append(d[x])
d=[]
for i in range(k):
    d.append(point[ (t[i]+2)%3 ])
    
for i in range(k,n):
    if t[i]==t[i-k] and d[i-k]!=0:
        d.append(0)
    else:
        d.append(point[ (t[i]+2)%3 ])
print(sum(d))

Measured memory_bytes: 47412
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
const int maxN = (int)1e5 + 100;
vector < int > g[maxN];
int n;
bool dfs(int v, int p) {
    bool has = true;
    for (int to : g[v]) {
        if (to == p) continue;
        if (dfs(to, v)) {
            if (!has) {
                cout << "First";
                exit(0);
            }
            has = false;
        }
    }
    return has;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    //freopen("input.txt", "r", stdin);
    cin >> n;
    for (int i = 1; i < n; i++) {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    if (!dfs(1, -1)) {
        cout << "Second";
    }
    else {
        cout << "First";
    }
    return 0;
}

Measured memory_bytes: 5888
import java.util.*;

class Main{
	public static void main(String[] $){
    Scanner in = new Scanner(System.in);
    double n = in.nextInt();
    double nam = 0;
    
    for(int i = 1; i <= n ; i++){
        if(i%2!=0){
            nam++;
        }
    }
	System.out.print(nam/n);
}
}


Measured memory_bytes: 21844
import java.util.ArrayList;
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args){
 
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		ArrayList<String> ansList = new ArrayList<>();
		
		String s = sc.next();
		String[] sArray = s.split("");
		
		ansList.add(sArray[0]);
		for(int i = 0; i < N-1; i++) {
			if(!sArray[i].equals(sArray[i+1])) {
				ansList.add(sArray[i+1]);
			}
		}

		System.out.println(ansList.size());
		sc.close();
	}
 
}

Measured memory_bytes: 31336
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 99999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(150) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 5100000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
  lli A,B,C,D,E,F,N,M,K,L,R,X,Y,H,W,sum=0,num=0,flag=0;string S,T;
  cin >> N;
  Vec(P,lli,N,0);
  rep(i,0,N){cin >> P[i];sum+=P[i];}
  A=sum/N;
  B=A+1;
  sum=0;
  rep(i,0,N){sum+=(P[i]-A)*(P[i]-A);num+=(P[i]-B)*(P[i]-B);}
  Out(min(sum,num));
}

Measured memory_bytes: 256