akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define pii pair<int, int>
#define endl '\n'
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define vpii vector<pii>
typedef long long ll;
typedef long double ld;
using namespace std;
template<class T> using minheap = priority_queue<T, vector<T>, greater<T>>;



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

  int n;
  cin >> n;
  vpii p(n);
  for (auto& pp: p) {
    cin >> pp.f >> pp.s;
  }
  sort(p.begin(), p.end());
  
  ld sum = 0;
  do {
    for (int i = 1; i < n; i++) {
      sum += sqrt(pow(p[i].f - p[i - 1].f, 2) + pow(p[i].s - p[i - 1].s, 2));
    }
  } while (next_permutation(p.begin(), p.end()));

  int fac = 1;
  for (int i = 1; i <= n; i++) fac *= i;

  ld ans = sum / ld(fac);

  printf("%.12LF\n", ans);
  return 0;
}

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

int main(){
  vector<string> cards(3);
  for(int i=0;i<3;++i) cin >> cards[i];

  int turn = 0;
  while(true){
	if(cards[turn].empty()){
	  cout << (char)('A' + turn) << endl;
	  break;
	}
	int next = cards[turn][0] - 'a';
	cards[turn].erase(0, 1);
	turn = next;
  }

  return 0;
}


Measured memory_bytes: 764
#include <stdio.h>
#include <iostream>
using namespace std;

int main(){
	long long int A[10000];
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>A[i];
	
	for(int i=n-1;i>0;i--)
		cout<<A[i]<<" ";
	printf("%d\n",A[0]);
	
}


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

int main() {
    while (true) {
        int n, x;
        cin >> n >> x;
        if (n == 0 && x == 0) break;

        int count = 0;
        for (int a = 1; a <= n - 2; a++) {
            for (int b = a + 1; b <= n - 1; b++) {
                for (int c = b + 1; c <= n; c++) {
                    if ((a + b + c) == x) count++;
                }
            }
        }
        cout << count << endl;
    }

    return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>

int main()

{
 int a,b,c,i,sum=0;

 scanf("%d %d",&a,&b);

 for(i=1;i<=b;i++){

  scanf("%d",&c);

  sum+=c;
 }

 if(a>=sum){
  printf("%d\n",a-sum);
 }

 else{
  printf("-1\n");
 }

 return 0;
}


Measured memory_bytes: 2140
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
using namespace std;

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


Measured memory_bytes: 888
H, W, A, B = map(int, input().split())
mod = 10**9+7

count = 0

factoriallist = [1]*(H+W)
for i in range(1,H+W):
    factoriallist[i] = factoriallist[i-1]*i % mod
#print("fact",factoriallist)

inverse_factoriallist = [0]*(H+W)
inverse_factoriallist[H+W-1] = pow(factoriallist[H+W-1],mod-2,mod)
#print("inverse",inverse_factoriallist)
for i in range(H+W-2,-1,-1):
    
    inverse_factoriallist[i] = inverse_factoriallist[i+1] * (i+1) % mod
    #print("inverse",inverse_factoriallist)


for i in range(B, W):
    count += ((factoriallist[H-A+i-1] * inverse_factoriallist[H-A-1] * inverse_factoriallist[i] )%mod) * ((factoriallist[A+(W-i) -2] * inverse_factoriallist[A-1] * inverse_factoriallist[W-i-1])%mod)

print(int(count% mod))

Measured memory_bytes: 18804
for e in iter(input,'0'):
 a=list(tuple(map(int,input().split())) for _ in range(int(e)))
 s,t=a[0]
 b=[tuple(map(int,input().split())) for _ in range(int(input()))]
 for x,y in b:
  flag = True
  for u,v in a[1:]:
   if(x+u-s,y+v-t)not in b:
    flag = False
    break
  if flag == True:
   print(x - s, y - t)
   break


Measured memory_bytes: 5896
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
int A;
  int B;
  int K;
  cin >>A>>B>>K;
  
  if(B-A+1>2*K) {
  rep(i,K) {
    cout<<A+i<< endl;
  }
  rep(i,K) {
cout<<B-K+i+1<<endl;
  }
  }
  
  else {
    int x=B-A+1;
    rep(i,x) {
      cout<<A+i<<endl;
    }
  }
  
  
  
}
  
  
 

Measured memory_bytes: 256
/*------------------------Original Copyright belongs to-------------------------/
!      																			!
!      ##  ##                                                		##  ##	    !
!      #   #             											#   #		!		                
!      				 ###  ####  ###   ###     ##         #                      !
!					#     #  #  #  #  #  #   #  #       ##                      !
!					#	  #  #  ###   ###    ####        #                      !
!					#     #  #  #  #  #  #   #  #        #                      !
!					 ###  ####  ###   #   #  #  #  ###  ### 			        !
!                                                                               !
/------------------------------------------------------------------------------*/
#include<bits/stdc++.h>
using namespace std;
//------------Template begins--------------------//
#define ss string
#define last(s) s.length()-1
#define lli long long int
#define v(type) vector<type>
#define pr(type1,type2) pair<type1,type2>
#define ma(type1,type2) map<type1,type2>
#define f first
#define s second
#define all(v) v.begin(),v.end()
#define pb push_back
#define pf push_front
#define mp make_pair
#define L(i,start,end) for(lli i=start;i<=end;i++)
#define R(i,start,end) for(lli i=start;i>=end;i--)
#define inp(var,start,end,array) for(var=start;var<=end;var++) cin>>array[var];
#define whatIs(x) cout<<#x<<" is "<<x<<endl
#define dbg1D(i,start,end,arr) for(lli i=start;i<=end;i++) cout<<i<<"th : "<<arr[i]<<endl;
#define dbg2D(i,j,s1,e1,s2,e2,arr) for (lli i=s1;i<=e1;i++) {cout<<i<<"th :"; for(lli j=s2;j<=e2;j++)cout<<arr[i][j]<<" ";cout<<endl;}

lli dx[4]={-1, 0, 0, +1};
lli dy[4]={0, -1, +1, 0};
const lli LINF = 1e18;
const lli INF = 1e9;
const lli mod = 1e9+7;
lli power(lli a,lli b,lli m){ if(b==0) return 1; if(b==1) return a%m;
 		lli t=power(a,b/2,m); t=(t*t)%m; if(b&1) t=(t*a)%m; return t;}
lli modInverse(lli a, lli m) { return power(a, m-2, m); }
//---------------Template ends------------------//
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	#ifndef ONLINE_JUDGE
	//freopen("ip.txt","r",stdin);
	//freopen("op.txt","w",stdout);
	#endif
//#################### CATCH HERE ##########################
   	/* Uncomment if t test cases
	lli t;
	cin>>t;
	while(t--)
	{
		lli n,ans,i,j;

		cout<<ans<<endl;
	}
	*/
	lli n;
	cin>>n;
	cout<<((n-2)*180)<<endl;
	//cout<<ans<<endl;
//##########################################################
	return 0;
} 

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
from heapq import heappush, heappop, heapify

N=input()

hq1=[]  #中央値より小さい値を入れるヒープキュー
hq2=[]  #中央値より大きい値を入れるヒープキュー
fx=0     #f(x)の最小値
for _ in range(N):
    q=map(int, sys.stdin.readline().split()) 

    if q[0]==1:
        q_type=q[0]
        a=q[1]
        b=q[2]
        heappush(hq1,a*-1)
        heappush(hq2,a)
        if hq2[0]<hq1[0]*-1:
            hq1_max=heappop(hq1)*-1
            hq2_min=heappop(hq2)
            heappush(hq1,hq2_min*-1)
            heappush(hq2,hq1_max)
            fx+=abs(hq1_max-hq2_min)
        fx+=b
    elif q[0]==2:
        print hq1[0]*-1,fx


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

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

#define LEN 4

using namespace std;

// data
int8_t P[LEN][LEN];

void solve();
int main(){
    rep(i, LEN){
        rep(j, LEN){
            int p; cin >> p;
            P[i][j] = p;
        }
    }

    solve();
}

int manhattan(int8_t (*P)[LEN])
{
    int dst = 0;
    rep(i, LEN){
        rep(j, LEN){
            if(P[i][j] == 0) continue;

            int ti = (P[i][j] - 1) / LEN,
                tj = (P[i][j] - 1) % LEN; // target location
            dst += abs(ti - i) + abs(tj - j);
        }
    }

    return dst;
}

typedef pair<int, int> Pi;

struct State{
    State(int8_t (*P0)[LEN], int move0, Pi blankBef, Pi blankNow)
    {
        rep(i, LEN)
            rep(j, LEN)
                P[i][j] = P0[i][j];
        move = move0;
        dst = manhattan(P) + move;
        blank = blankNow;
        _blank = blankBef;
    }
    friend bool operator>(State s0, State s1){
        return s0.dst > s1.dst;
    }
    int dst;
    int move;
    int8_t P[LEN][LEN];
    pair<int, int> blank, _blank;
};

const int di[4] = {-1, 1, 0 ,0},
    dj[4] = {0,0,-1, 1};
void solve(){
    // find blank
    int bi, bj;
    rep(i, LEN)
        rep(j, LEN) if (P[i][j] == 0) bi = i,
                                    bj = j;

    State s0(P, 0, Pi(bi, bj), Pi(bi, bj));
    priority_queue<State, vector<State>, greater<State> > pq;
    pq.push(s0);

    while(!pq.empty()){
        State s = pq.top(); pq.pop();

        // check final
        if(manhattan(s.P) == 0){
            cout << s.move << endl;
            break;
        }
        
        rep(i, 4){
            int ii, jj;
            ii = s.blank.first + di[i];
            jj = s.blank.second + dj[i];

            if(ii>=0&&ii<LEN && jj>=0&&jj<LEN && Pi(ii, jj)!= s._blank){
                swap(s.P[s.blank.first][s.blank.second], 
                    s.P[ii][jj]);

                pq.push(State(s.P, s.move+1, s.blank, Pi(ii, jj)));

                swap(s.P[s.blank.first][s.blank.second],
                     s.P[ii][jj]);
            }
        }
    }
}


Measured memory_bytes: 166684
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from fractions import gcd

A,B,C,D = map(int,read().split())

def F(N):
    # N以下でどちらでも割れない
    x = N//C
    x += N//D
    lcm = C*D//gcd(C,D)
    x -= N//lcm
    return N-x

answer = F(B) - F(A-1)
print(answer)

Measured memory_bytes: 5048
using System;
using System.Collections;
using System.Linq;


public class Test
{
    public static long n = 0;
    public static long ans = 0;
    public static string str = "";

	public static void Main()
	{
       str = Console.ReadLine();
       
       string s = "";
       bit(s);
       Console.WriteLine(ans);
    }

    public static void bit(string s)
    {
        if(s.Length == str.Length-1)
        {
            calc(s);
        }
        else
        {
            bit(s+"0");
            bit(s+"1");
        }
    }

    public static void calc(string s)
    {
        string ss = "";
        char[] nums = str.ToCharArray();
        char[] c = s.ToCharArray();
        
        ss += nums[0].ToString();
        
        for(int i = 0 ; i < c.Length ; i++)
        {
            if(c[i] == '1')
            {
                ans += long.Parse(ss);
                ss = "";
            }
            ss += nums[i+1].ToString();
        }
        ans += long.Parse(ss);
    }
}

Measured memory_bytes: 13140
//Coded by Abhijay Mitra
#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <numeric>
#include <vector>
#include <iterator> 
#include <map>
#include <set>
#include <climits>
#include <queue>
#include <cmath>
#include <stack>
#include <cctype>
#include <bitset>
// #include <bits/stdc++.h>
#define double long double
#define int long long int
#define ll int
#define ibs ios_base::sync_with_stdio(false)
#define cti cin.tie(0)
#define bp __builtin_popcount
#define pb emplace_back
#define koto_memory(a) cout<<(sizeof(a)/1048576.0)<<" MB";
#define res(v) sort(all(v)),v.erase(unique(all(v)), v.end());
#define timer cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
#define deb(x) cout<<"\n["<<#x<<" = "<<x<<"]\n";
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using pii = std::pair<int,int>;
using vpii = std::vector<pii>;
using vvpii = std::vector<vpii>;
#define mp         make_pair
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define per(i,b,a) for (int i = b; i >= a; i--)
#define all(x)     x.begin(), x.end()
using namespace std;
const int N=2e6+10;
const int inf = /*0x3f3f3f3f*/1e18+10;
// const ll M = 998244353 ; // Mulo
// const int M = 1e9+7 ; // Mulo
const double Pi = 3.14159265;
#define F first
#define S second
int parent[N],ind[N],ans;
int find_set(int v) {
    if (v == parent[v])
        return v;
    return parent[v] = find_set(parent[v]);
}
void make_set(int v) {
    parent[v] = v;
    ind[v] = rand();
}
void union_sets(int a, int b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b) {
        if (ind[a] < ind[b])
            swap(a, b);
        parent[b] = a;
    }
}
set<int>s[N];
void solve(){
  int n,m,x,y;cin>>n>>m;
  rep(i,1,n){
    make_set(i);
  }
  rep(i,1,m){
    cin>>x>>y;
    union_sets(x,y);
  }
  rep(i,1,n){
    s[find_set(i)].insert(i);
  }
  rep(i,1,n){
    ans=max((int)s[i].size(),ans);
  }
  cout<<ans;
}
int32_t main()
{
  ibs;cti;
  solve();return 0;
  /*,cout<<"\n"*/;
  // cout<<"\n";
  int xx=0;
  int t;cin>>t;while(t--){/*xx++;cout<<"Case "<<xx<<":\n"*/;solve();cout<<"\n";}
  return 0;
}

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

ll gcd(ll a, ll b)
{
  if (a < b)
    swap(a, b);
  while (b)
  {
    ll m = a % b;
    a = b;
    b = m;
  }
  return a;
}

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

int main()
{
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  ll sub_ans = 0;
  ll l, Ql, Qc, Qd;
  l = lcm(c, d);
  Ql = b / l;
  Qc = b / c;
  Qd = b / d;
  sub_ans = Qc + Qd - Ql;
  Ql = (a - 1) / l;
  Qc = (a - 1) / c;
  Qd = (a - 1) / d;
  sub_ans = sub_ans - (Qc + Qd - Ql);

  cout << (b - a + 1) - sub_ans << endl;
  return 0;
}

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

int main(){
	int n;
	cin >> n;
	int a[210];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int count = 100;
	for (int i = 0; i < n; i++) {
		int x = a[i];
		int temp = 0;
		while (x % 2 == 0) {
			temp++;
			x /= 2;
		}
		if (count > temp) count = temp;
	}
	cout << count << endl;
}

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

int main(){
  int n,w;
  bool table[100100];
  vector<int> f;

  cin >> n >> w;
  int cnt = w;
  cout << cnt << (w==n?"\n":" ");
  for(int i=1;i<=w;i++)table[i] = true;
  for(int i=w+1;i<=n;i++)table[i] = false;

  for(int z=w+1;z<=n;z++){
    int prv = z-w;
    f.clear();
    for(int i=1;i*i<=prv;i++){
      if(prv%i==0){
	f.push_back(i);
	if(i*i!=prv)f.push_back(prv/i);
      }
    }

    for(int i=0;i<f.size();i++){
      if(!table[f[i]])continue;
      int pre = (prv+1)/f[i];
      if((prv+1)%f[i]!=0)pre++;
      int suf = (z-1)/f[i];
      if(suf-pre<=0){
	table[f[i]] = false;
	cnt--;
      }
    }
    
    f.clear();
    for(int i=1;i*i<=z;i++){
      if(z%i==0){
	f.push_back(i);
	if(i*i!=z)f.push_back(z/i);
      }
    }
    
    for(int i=0;i<f.size();i++){
      if(table[f[i]])continue;
      int pre = (prv+1)/f[i];
      if((prv+1)%f[i]!=0)pre++;
      int suf = (z-1)/f[i];
      if(suf-pre>=0){
	table[f[i]] = true;
	cnt++;
      }
    }
    table[z] = true; cnt++;

    cout << cnt << (z==n?"\n":" ");
  }
}
    

Measured memory_bytes: 1320
#include <bits/stdc++.h>
#include <stdarg.h>
#include <assert.h>
#include <ctype.h>
#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/join.hpp>

using namespace std;
using boost::algorithm::split;
using boost::algorithm::join;
using boost::algorithm::replace_all;

typedef long long int lli;
typedef vector<int> iv;
typedef vector<bool> bv;
typedef vector<string> sv;
typedef vector<long long int> llv;
typedef vector<double> dv;

#define sor_(vec) sort(vec.begin(),vec.end())
#define rev_(vec) reverse(vec.begin(),vec.end())
#define rep(i,n) for(int i=0;i<static_cast<int>(n);i++)
#define reps(i,n,s) for(int i=static_cast<int>(s);i<static_cast<int>(n);i++)
#define isposi(num) if(num>0)
const long long mod = 1000000007;
#define PI 3.141592653589793

template<typename TypeInt>
std::string Itoa(const TypeInt v, int base)
{
    static const char table[] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    string ret;
    static numeric_limits<TypeInt> t;
    TypeInt n = v;
    if (t.is_signed) {
        if (v < 0) n *= -1;
    }

    while (n >= base) {
        ret += table[n%base];
        n /= base;
    }
    ret += table[n];
    if (t.is_signed) {
        if (v < 0 && base == 10) ret += '-';
    }
    std::reverse(ret.begin(), ret.end());

    return ret;
}

void printm(char const *format,...){
    va_list arguments;
    va_start(arguments,format);
    unsigned index=0;
    while (format[index]!='\0') {
        if(format[index]=='%'){
            index++;
            if(format[index]=='d')printf("%d",va_arg(arguments, int));
            else if(format[index]=='c')printf("%c",va_arg(arguments, int));
            else if(format[index]=='x')printf("%x",va_arg(arguments,int));
            else if(format[index]=='o')printf("%o",va_arg(arguments,int));
            else if(format[index]=='f')printf("%f",va_arg(arguments, double));
            else if(format[index]=='s')printf("%s",va_arg(arguments, char const *));
            else if(format[index]=='p')printf("%p",va_arg(arguments,void*));
            else if(format[index]=='y')printf("Yes");
            else if(format[index]=='n')printf("No");
            else if(format[index]=='%')printf("%%");
            else assert(!"Unknown format with %.");
        }
        else printf("%c",format[index]);
        index++;
    }
    va_end(arguments);
    return;
}

struct Chara{
    int hp;
    int sp;
};
bool pairCompare(const pair<int,int>& firstElof, const pair<int,int>& secondElof)
{
    return firstElof.second > secondElof.second;
}

int main(void){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << std::setprecision(15);
    //
    long double a,b;
    cin>>a>>b;
    cout<<(unsigned long long)(a*b);
    //
    return 0;
}


Measured memory_bytes: 3752
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000; //1e18
const double EPS = 1e-10;            //

int main(void)
{
    int A, B, C, D;
    cin >> A >> B >> C >> D;

    cout << max(A * B, C * D) << endl;
    return (0);
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>

using namespace std;

#define C_MAX(a, b) ((a)>(b)?(a):(b))
#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v) {std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

string comp(const string s1, const string s2) {
    if (s1.size() > s2.size()) return s1;
    if (s1.size() < s2.size()) return s2;
    if (s1.size() == s2.size()) {
        for (int i = 0; i < s1.size(); i++) {
            if (s1[i] > s2[i]) return s1;
            if (s1[i] < s2[i])return s2;
        }
    }
    return s1;
}

int main() {

    while (true) {

        int W, H;
        cin >> W >> H;

        if (W == 0 && H == 0) break;

        vector<string> C(H);
        for (int i = 0; i < H; i++)cin >> C[i];

        vector<vector<string>> dp(H + 1, vector<string>(W + 1, ""));
        for (int i = 1; i <= H; i++) {
            for (int j = 1; j <= W; j++) {
                if (!isdigit(C[i - 1][j - 1])) continue;
                string s1 = dp[i - 1][j] + C[i - 1][j - 1];
                string s2 = dp[i][j - 1] + C[i - 1][j - 1];
                if (s1[0] == '0') s1 = s1.substr(1);
                if (s2[0] == '0') s2 = s2.substr(1);
                dp[i][j] = comp(s1, s2);
            }
        }

        string ans = "0";
        for (int i = 1; i <= H; i++) for (int j = 1; j <= W; j++) if (dp[i][j].size() > 0) ans = comp(ans, dp[i][j]);
        cout << ans << endl;

    }

    return 0;
}





























Measured memory_bytes: 3188
N,M = map(int,input().split())
D = [list(map(int,input().split())) for i in range(M)]
C = [list(map(int,input().split())) for i in range(N)]

dic0 = {}
dic1 = {}
dic2 = {}

for i in range(N) :
    for j in range(N) :
        key = C[i][j]-1
        if (i+j) % 3 == 0 :
            if key not in dic0 :
                dic0[key] = 1
            else :
                dic0[key] += 1
        elif (i+j) % 3 == 1 :
            if key not in dic1 :
                dic1[key] = 1
            else :
                dic1[key] += 1
        else :
            if key not in dic2 :
                dic2[key] = 1
            else :
                dic2[key] += 1

ans = float("inf")

for i in range(M) :
    for j in range(M) :
        if i == j :
            continue
        for k in range(M) :
            if (i == k) or (j == k) :
                continue
            
            calc = 0
            for a,b in dic0.items() :
                calc += D[a][i]*b
            for a,b in dic1.items() :
                calc += D[a][j]*b
            for a,b in dic2.items() :
                calc += D[a][k]*b
            ans = min(ans,calc)
print(ans)
            
      

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


int main(int argc, char *argv[]) {
  // C-style stdio functions should not be used.
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  int H, W, K; cin >> H >> W >> K;
  int k = 0;
  bool apY = false;
  int pending = 0;
  vector<int> row(W);

  auto putrow = [&]() -> void {
    for (int i = 0; i < W; i++) {
      if (i > 0) cout << " ";
      cout << row.at(i);
    }
    cout << "\n";
  };

  for (int h = 0; h < H; h++) {
    string s; cin >> s;
    if (s.find('#') == string::npos) {
      if (!apY) pending ++;
      else putrow();
    }else {
      k++;
      bool apX = false;
      for (int i = 0; i < W; i++) {
	if (s.at(i) == '#') {
	  if (!apX) {
	    apX = true;
	  }else {
	    k++;
	  }
	  row.at(i) = k;
	}else {
	  row.at(i) = k;
	}
      }
      apY = true;
      if (pending > 0) {
	for (int j = 0; j < pending; j++) putrow();
	pending = 0;
      }
      putrow();
    }
  }

  return 0;
}



Measured memory_bytes: 768
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	w,h,n = readline() |> split |> parseMap
	k = [0,w,0,h]
	for i in 1:n
		x, y, a = readline() |> split |> parseMap
		if a == 1
			k[1] = max(x,k[1])
		elseif a == 2
			k[2] = min(x,k[2])
		elseif a == 3
			k[3] = max(y,k[3])
		elseif a == 4
			k[4] = min(y,k[4])
		end
	end
	print((max(k[2]-k[1],0))*(max(k[4]-k[3],0)))
end

main()

Measured memory_bytes: 111200
x, y, a, b, c = map(int, input().split())
ps = sorted(list(map(int, input().split())), reverse=True)
qs = sorted(list(map(int, input().split())), reverse=True)
rs = sorted(list(map(int, input().split())), reverse=True)

tr = ps[:x]
tg = qs[:y]
added = 0
for e in rs:
  if len(tg) != 0 and len(tr) != 0:
    if tr[-1] >= tg[-1] and e > tg[-1]:
      tg.pop()
      added += e
    elif tg[-1] > tr[-1] and e > tr[-1]:
      tr.pop()
      added += e
    else:
      break
  elif len(tg) != 0:
    if e > tg[-1]:
      tg.pop()
      added += e
    else:
      break
  elif len(tr) != 0:
    if e > tr[-1]:
      tr.pop()
      added += e
    else:
      break
  else:
    break
print(sum(tg)+sum(tr)+added)


Measured memory_bytes: 23200
#include "bits/stdc++.h"

using namespace std;

using ll = long long;

template<typename T> using V = std::vector<T>;
using Vi = V<int>;
using VVi = V<V<int>>;
using Vl = V<ll>;
using VVl = V<V<ll>>;
using Vs = V<string>;

template<typename T1, typename T2> using P = std::pair<T1, T2>;
using Pii = P<int, int>;
using Pll = P<ll, ll>;
using Pdd = P<double, double>;

template<typename T1, typename T2> using M = std::map<T1, T2>;
using Mii = M<int, int>;
using Msi = M<string, int>;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define RREP(i,s,e) for(int i=(int)(s);i>=(int)(e);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()

const double PI = acos(-1);
const ll MOD = 1e9+7;

int n;
Vi primes;

std::map<int, int> prime_fact(long long n) {
    std::map<int, int> cnt;

    long long m = n;
    for (int i: primes) {
        if (m % i == 0) {
            cnt[i] = 1;
            m /= i;
        }
        while (m % i == 0) {
            cnt[i]++;
            m /= i;
        }
    }
    if (m != 1) {
        cnt[m] = 1;
    }

    return cnt;
}

int main() {
    cin >> n;

    primes = Vi();
    V<bool> isPrime(n+1, true);
    for (int i = 2; i <= n; i++) {
        if (!isPrime[i]) continue;
        primes.push_back(i);
        long long buf = i * 2;
        while (buf <= n) {
            isPrime[buf] = false;
            buf += i;
        }
    }

    Mii m;
    REP2(i, 2, n+1) {
        Mii m2 = prime_fact(i);
        for (auto x: m2) {
            if (m.count(x.first) == 0) {
                m[x.first] = x.second;
            } else {
                m[x.first] += x.second;
            }
        }
    }

    int c75 = 0, c25 = 0, c15 = 0, c5 = 0, c3 = 0;
    for (auto x: m) {
        if (x.second >= 74) c75++;
        else if (x.second >= 24) c25++;
        else if (x.second >= 14) c15++;
        else if (x.second >= 4) c5++;
        else if (x.second >= 2) c3++;
    }

    int res = c75;
    c25 += c75;
    res += c25 * (c25 - 1) + c25 * (c3 + c5 + c15);
    c15 += c25;
    res += c15 * (c15 - 1) + c15 * c5;
    c5 += c15;
    res += c5 * (c5-1) * (c5-2) / 2 + c5 * (c5-1) / 2 * c3;
    cout << res << '\n';

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN=2e5+5;
int a[MAXN];
int n,A,B,C,D;
bool fl;
int main(){
	scanf("%d",&n);
	scanf("%d%d%d%d",&A,&B,&C,&D);
	for (int i=1;i<=n;i++){
		char c=getchar(); while (c!='.'&&c!='#') c=getchar();
		a[i]=(c=='#');
	}
	for (int i=A;i<C;i++){
		if (a[i]&&a[i+1]) fl=1;
	}
	for (int i=B;i<D;i++){
		if (a[i]&&a[i+1]) fl=1;
	}
	if (fl||C==D) return printf("No\n"),0;
	if (C<D) return printf("Yes\n"),0;
	fl=1;
	for (int i=B;i<=D;i++){
		if (!a[i-1]&&!a[i]&&!a[i+1]) fl=0;
	}
	if (fl) printf("No\n");
	else printf("Yes\n");
	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

int n, A[50];

// 入力値のMから選んだ要素を引いていく再帰関数
int solve(int i, int m) {
    if(m==0) return 1;
    if(i>=n) return 0;
    int res = solve(i+1,m) || solve(i+1,m-A[i]);
    return res;
}

int main(void) {
    int q, M, i;

    scanf("%d", &n);
    for(i=0;i<n;i++) scanf("%d",&A[i]);
    scanf("%d",&q);
    for(i=0;i<q;i++) {
        scanf("%d", &M);
        if(solve(0,M)) printf("yes\n");
        else printf("no\n");
    }
    return 0;
}


Measured memory_bytes: 2080
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>

using namespace std;

int main(){
    int needR, needG, numR, numG, numN;
    cin >> needR >> needG >> numR >> numG >> numN;
    vector<long long> vR, vG, vN;

    for(int i=0;i<numR;++i)
    {
        long long temp;
        cin >> temp;
        vR.push_back(temp);
    }

    for(int i=0;i<numG;++i)
    {
        long long temp;
        cin >> temp;
        vG.push_back(temp);
    }

    for(int i=0;i<numN;++i)
    {
        long long temp;
        cin >> temp;
        vN.push_back(temp);
    }

    sort(vR.begin(), vR.end(), greater<long long>());
    sort(vG.begin(), vG.end(), greater<long long>());
    sort(vN.begin(), vN.end(), greater<long long>());

    for(int i=0;i<needR;++i)
    {
        vN.push_back(vR[i]);
    }

    for(int i=0;i<needG;++i)
    {
        vN.push_back(vG[i]);
    }

    sort(vN.begin(), vN.end(), greater<long long>());

    cout <<  accumulate(vN.begin(), vN.begin()+needR+needG, 0LL) << endl;

    return 0;

}



Measured memory_bytes: 7664
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a; i< (int)(b); ++i)
using ll=long long;
using namespace std;
const auto mod=1e9+7;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  
  int n; cin >> n;
  vector<ll> a(n),b(n),c(n);
  rep(i,0,n) cin >> a[i];
  rep(i,0,n) cin >> b[i];
  rep(i,0,n) cin >> c[i];
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  sort(c.begin(),c.end());
  ll ans=0;
  rep(i,0,n){
  	ll  A = lower_bound(a.begin(),a.end(),b[i])-a.begin();
  	ll B = n-(upper_bound(c.begin(),c.end(),b[i])-c.begin());
  	ans+=A*B;
  }


  cout << ans << endl;
}






Measured memory_bytes: 2560
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#include <numeric>
 
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef pair<int, int> pi;

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

ll calcLCM(ll a, ll b){
  return a * b / gcd(a, b);
}

int main() {
  int n, m;
  cin >> n >> m;
  vector<ll> p(n);
  rep(i, n) cin >> p[i];
  rep(i, n) p[i] /= 2;

  ll lcm = p[0];
  for(int i=1;i<n;i++){
    lcm = calcLCM(lcm, p[i]);
  }
  if (lcm > m){
    cout << 0 << endl;
    return 0;
  }
  rep(i, n){
    if ((lcm / p[i]) % 2 == 0){
      cout << 0 << endl;
      return 0;
    }
  }

  ll ans = m / lcm;
  ans = (ans + 1) / 2;
  cout << ans << endl;
  return 0;
}

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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1)
    printEoln();
  if (suc == 2)
    printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U> void chmax(T &a, U b) {
  if (a < b)
    a = b;
}

template <class T, class U> void chmin(T &a, U b) {
  if (b < a)
    a = b;
}

template <class T> T Sq(const T &t) { return t * t; }

const int mod = 1e9 + 7;

signed main() {
  int a, b;
  std::cin >> a >> b;
  print(ceil((a + b) / 2.0));
}


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

lli n, c, k;

int main(void){
	cin >> n >> c >> k;
	vector<lli> t(n);
	rep(i, n) cin >> t[i];
	sort(t.begin(), t.end());
	lli ans = 0;
	lli i = 0;
	while(i < n){
		lli l = t[i];
		lli p = 0;
		while(i < n && p < c && t[i] <= l+k){
			p++;
			i++;
		}
		ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4028
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn=100010;
int a[maxn];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",a+i);
	sort(a+1,a+1+n);
	int ans,min_diff=0x3f3f3f3f;
	for(int i=1;i<=n;i++){
		if(abs((a[n]+1)/2-a[i])<min_diff){
			min_diff=abs((a[n]+1)/2-a[i]);
			ans=a[i];
		}
	}
	printf("%d %d\n",a[n],ans);
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define MP make_pair
using namespace std;
#define int long long
signed main(){
    int n,m,H,k,s,t,p;
    while(cin >> n >> m >> H >> k&&n!=0){
        vector<vector<pair<pair<int,int>,pair<int,int>> > > g(n);
        rep(i,m){
            int a,b,c,h,r;
            cin >> a >> b >> c >> h >> r;
            a--;b--;
            r--;
            g[a].push_back(MP(MP(b,h),MP(c,r)));
            g[b].push_back(MP(MP(a,h),MP(c,r)));
        }
        cin >> s >> t;
        s--;t--;
        cin >> p;
        int cost[1<<8];
        rep(i,(1<<8)){
            cost[i] = (1LL<<40);
        }
        cost[0] = 0;
        rep(i,p){
            int mm,ccc;
            cin >> mm >> ccc;
            int bits  = 0;
            rep(j,mm){
                int tt;
                cin >> tt;
                tt--;
                bits |= (1<<tt);
            }
            rep(sub,(1<<8)){
                if((sub&bits)==sub){
                    cost[sub] = min(cost[sub],ccc);
                }
            }
        }
        for(int bits=1;bits<(1<<8);bits++){
            for(int cc=1;cc<bits;cc++){
                cost[bits] = min(cost[bits],cost[cc]+cost[cc^bits]);
            }
        }
        int dp[25][101][1<<8];
        rep(i,25)rep(j,101)rep(kk,(1<<8))dp[i][j][kk] = (1LL<<40);
        
        priority_queue<pair<pair<int,int>,int >,vector<pair<pair<int,int>,int> >, greater<pair<pair<int,int>,int> > >  pq;
        rep(bits,1<<8){
            dp[0][s][bits] = cost[bits];
            pq.push(MP(MP(0,cost[bits]),s));
            while(!pq.empty()){
                auto x = pq.top();
                pq.pop();
                int id = x.second;
                int ti = x.first.first;
                int price = x.first.second;
                // if(bits==0)cerr << id << " " << ti << " " << price << " " << dp[ti][id][bits] << endl;
                if(dp[ti][id][bits]<price)continue;
                for(auto y:g[id]){
                    int nxt = y.first.first;
                    int dist = y.first.second;
                    int ccc = y.second.first;
                    int kind = y.second.second;
                    // if(bits==0)cerr << id << " " << nxt << " " << dist << " " << ccc << " " << kind << endl;
                    if(bits&(1<<kind))ccc = 0;
                    if(ti+dist <= H){
                        if(dp[ti+dist][nxt][bits]>price+ccc){
                            dp[ti+dist][nxt][bits] = price+ccc;
                            pq.push(MP(MP(ti+dist,price+ccc),nxt));
                        }
                    }
                }
            }
        }
        int mi = (1LL<<40);
        rep(bits,1<<8){
            for(int i=0;i<=H;i++){
                if(mi > dp[i][t][bits]){
                    mi = dp[i][t][bits]; 
                }
            }
        }
        if(mi!=(1LL<<40)){
            cout << mi << "\n";
        }else{
            cout << -1 << "\n";
        }
    }
    return 0;
}


Measured memory_bytes: 8256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e16+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int n;
    cin >> n;
    vector<int>a(n);
    int mx = 0;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        mx = max(mx,a[i]);
    }
    if(n == 2) {
        if(a[0] == 100 && a[1] == 0) {
            cout << "100 0" << endl;
            return 0;
        }
    }
    sort(a.begin(),a.end());
    int ABS = INF;
    int ans = 0;
    for(int i = n-1; i >= 0; i--) {
        if(abs(mx/2-a[i]) < ABS) {
            ABS = abs(mx/2-a[i]);
            ans = i;
        }
    }
    cout << mx << " " << a[ans] << endl;
}


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

int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if (a+b>c+d){
    cout << "Left" << endl;
    }
  else if (a+b==c+d){
    cout << "Balanced" << endl;
    }
  else{
    cout << "Right" << endl;
    }
  }

Measured memory_bytes: 256
N,H = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]
A = [AB[i][0] for i in range(N)]
B = [AB[i][1] for i in range(N)]
A.sort(reverse=True)
B.sort(reverse=True)

amax = A[0]
res = 0
damage = 0
for b in B:
    if b <= amax:
        break
    res += 1
    damage += b
    if damage >= H:
        break
if damage < H:
    res += ((H-damage-1)//amax + 1)
print(res)

Measured memory_bytes: 69592
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define REV(i,n) for(int i=n-1;i>0;i--)
#define req(i,n,m) for(int i=n;i<m;i++)
#define REQ(i,n,m,l) for(int i=n;i<m;i+=l) 
#define _GLIBCXX_DEBUG
int INF = 1e9 + 7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
    unsigned day;
    if (dow < dow1) dow += 7;
    day = dow - dow1;
    day += 7 * n - 6;
    return day;
}
signed gcd(int x, int y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
signed lcm(int x, int y) {
    return x / gcd(x, y) * y;
}
unsigned DayToWeekNumber(unsigned day)
{
    return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
    return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main() {
    int a, b; cin >> a >> b;
    cout << (1 + b - a) * (b - a) / 2 - b << endl;
}

Measured memory_bytes: 3608
fun main(args: Array<String>) {
    edpf()
}

private enum class From { LEFT, LEFT_ABOVE, ABOVE, UNDEFINED }

fun edpf() {
    val s = readLine()!!
    val t = readLine()!!

    // sをiまで、tをjまで選んだときのLCSテーブル
    val dp = Array(s.length + 1) { IntArray(t.length + 1) { 0 } }
    // dpテーブルでどの方向から遷移してきたか (縦軸s、横軸tとする)
    val from = Array(s.length + 1) {
        Array(t.length + 1) {
            From.UNDEFINED
        }
    }

    // LCSの遷移を記録
    for (i in 1..s.length) {
        for (j in 1..t.length) {
            dp[i][j] = if (s[i - 1] == t[j - 1]) {
                from[i][j] = From.LEFT_ABOVE
                dp[i - 1][j - 1] + 1
            } else {
                if (dp[i - 1][j] > dp[i][j - 1]) {
                    from[i][j] = From.ABOVE
                    dp[i - 1][j]
                } else {
                    from[i][j] = From.LEFT
                    dp[i][j - 1]
                }
            }
        }
    }

    val answer = StringBuffer()

    // LCSの復元
    var si = s.length
    var ti = t.length
    while (si > 0 && ti > 0) {
        when (from[si][ti]) {
            From.LEFT_ABOVE -> {
                answer.append(s[si - 1])
                si--
                ti--
            }
            From.ABOVE -> si--
            From.LEFT -> ti--
            else -> Unit
        }
    }

    println(answer.reverse())
}


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

using namespace std;
typedef pair<int, int> P;

void solve()
{
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; ++i)
	{
		cin >> A[i];
	}
	int oddCount = 0;
	for (int i = 0; i < N; ++i)
	{
		if (A[i] % 2 == 1)
		{
			++oddCount;
		}
	}
	if (oddCount % 2 == 0)
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}
}

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

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

#define ll long long

int main()
{
	int n, m;
	cin >> n >> m;

	vector<pair<ll,ll>> arr(n);

	for (int i = 0; i < n; i++)
	{
		int a, b;
		cin >> a >> b;

		arr[i] = make_pair(a, b);
	}

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

	ll ans = 0;
	priority_queue<int> pq;
	int now = 0;

	for (int i = 1; i <= m ; i++)
	{	
		for (; now < n; now++)
		{
			if (arr[now].first <= i)
			{
				pq.push(arr[now].second);
			}
			else
			{
				break;
			}
		}

		if (pq.size())
		{
			ans += pq.top();
			pq.pop();
		}
	}

	cout << ans << endl;

}


Measured memory_bytes: 2428
// </> : towhid1zaman

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;typedef vector<ll> vll;
#define fill(a,b) memset(a, b, sizeof (a))
#define all(v) (v).begin(),(v).end()
#define sp(k) cout<<setprecision(k)<<fixed;
#define rep(i,a) for(int i=0; i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define unq(v) sort(all(v)),(v).erase(unique(all(v)),(v).end())
#define _ios ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define sqr(a) ((a)*(a))
#define sz(a) int(a.size())
#define ff first
#define ss second
#define pb push_back

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int maxn = 2000100;

int main(){
        _ios;
    int a,b,c,d;
	cin>>a>>b>>c>>d;
	while(1){
		c=c-b;
		if(c<=0){
			cout<<"Yes";
			break;
		}
		a=a-d;
		if(a<=0){
			cout<<"No";
			break;
		}
	}


return 0;
}



Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
string s;
int ans=1e9; 
int main(void){
    cin>>s;
    for(int i=1;i<s.size();++i)
        if(s[i]!=s[i-1]) ans=min(ans,max(i,int(s.length())-i)); 
    cout<<min(ans,int(s.size()))<<"\r\n";
}

Measured memory_bytes: 512
N = int(input())
S = [input() for _ in range(N)]
L = ['M', 'A', 'R', 'C', 'H']
dict_S = {}

for i in range(N):
    moji = S[i][0]
    if moji in L:
        if moji not in dict_S:
            dict_S[moji] = 1
        else:
            dict_S[moji] += 1

keys = len(dict_S.keys())
values = list(dict_S.values())

if keys < 3 or keys == None:
    print(0)
else:
    x = 0
    for i in range(keys):
        for j in range(i+1, keys):
            for k in range(j+1, keys):
                x += values[i] * values[j] * values[k]
    print(x)

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

typedef long long int ll; 


int main()
{
	std::ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
		
	ll n;
	cin>>n;
	
	map < string , ll > mp;
	
	for(ll i=0;i<n;i++)
	{
		string s;
		cin>>s;
		sort(s.begin(),s.end());
		mp[s]++;
	} 
	ll ans = 0;
	for(auto it=mp.begin();it!=mp.end();it++)
	{
		ll x = it->second;
		
		ans += (x*(x-	1))/2;
	}
	cout<<ans<<endl;
	
}



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

int j,y;

void solve(int a,int b,string s) {
    if(a>j||b>y) return;
	if(a==j&&b==y) cout << s << endl;
	if((a==5&&b<=3)||(b==5&&a<=3)||(a==b&&a==5)||(a==6||b==6)) return;
	solve(a+1,b,s+'A');
	solve(a,b+1,s+'B');
}

int main() {
	cin >> j >> y;
	solve(0,0,"");
	
	return 0;
}



Measured memory_bytes: 3172
import sys
from itertools import accumulate

def solve():
    n = int(input())
    s = [int(input()) for i in range(n)]

    lim = n * 100
    dp = [False] * (lim + 1)
    dp[0] = True

    for i in range(n):
        for j in range(lim, s[i] - 1, -1):
            dp[j] |= dp[j - s[i]]

    for i in range(lim, 0, -1):
        if i % 10 == 0:
            continue
        if dp[i]:
            print(i)
            return

    print(0)

if __name__ == '__main__':
    solve()

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll factorial(ll n, ll m=2) {
    // calculate n!
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    string a, b, c;
    cin >> a >> b >> c;
    cout << a[0] << b[0] << c[0] << endl;
    return 0;
}

Measured memory_bytes: 256
import math
import sys
import queue
from collections import Counter
from itertools import accumulate
from fractions import gcd
from functools import reduce


def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

sys.setrecursionlimit(10000)

mod = 1000000007

"""
# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]

# 標準入力取得
## 文字列
    = sys.stdin.readline().rstrip()
    = list(sys.stdin.readline().rstrip())

## 数値
    = int(sys.stdin.readline())
    = map(int, sys.stdin.readline().split())
    = list(map(int, sys.stdin.readline().split()))
    = [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

# Kの倍数を全網羅する方針？
# 最大長は3N
# 2, 4, 6, 8
if __name__ == "__main__":
    N, K = map(int, sys.stdin.readline().split())
    if K % 2 == 0:
        a = N // K
        b = (N + (K // 2)) // K
        print(a ** 3 + b ** 3)
    else:
        a = N // K
        print(a ** 3)



Measured memory_bytes: 5456
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<queue>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
typedef long long LL;
typedef pair<int,int> PII;
#define X first
#define Y second
inline int read()
{
	int x=0,f=1;char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=x*10+c-'0';c=getchar();}
	return x*f;
}

int main()
{
	int x;
	x=read();
	if(x<600 && x>=400)puts("8");
	else if(x<800 && x>=600)puts("7");
	else if(x<1000 && x>=800)puts("6");
	else if(x<1200 && x>=1000)puts("5");
	else if(x<1400 && x>=1200)puts("4");
	else if(x<1600 && x>=1400)puts("3");
	else if(x<1800 && x>=1600)puts("2");
	else if(x<2000 && x>=1800)puts("1");
	return 0;
}
/*

*/


Measured memory_bytes: 3064