akhauriyash/Code-Regression huggingface dataset:
import sys
import math
from fractions import gcd
# import queue
# from collections import Counter
# from itertools import accumulate
# 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)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  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)]
"""

N, K =  map(int, sys.stdin.readline().split())
L =  list(map(int, sys.stdin.readline().split()))

if (N - K) % (K - 1) == 0:
    print((N - K) // (K - 1) + 1)
else:
    print((N - K) // (K - 1) + 2)


Measured memory_bytes: 78080
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	r, g, b := intScanner(), intScanner(), intScanner()
	if (r*100+g*10+b)%4 == 0 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


Measured memory_bytes: 1772
import java .util.Scanner;
public class Main {
public static void main(String[] args) {
	Scanner sc = new Scanner (System.in);

	int inputN = sc.nextInt();
	int inputD = sc.nextInt();
	int count = 0;

	for(int i = 0; i < inputN; i++) {
		int xi = sc.nextInt();
		int yi = sc.nextInt();

		double xixi = Math.pow(xi, 2);

		double yiyi = Math.pow(yi, 2);

		double root = xixi + yiyi;

		 double r =Math.sqrt(root);

		if(r <= inputD) {
			count++;
		}
	}
	System.out.println(count);
}
}


Measured memory_bytes: 59000
#include <bits/stdc++.h>
// #include <iostream>
// #include <vector>
// #include <map>
// #include <algorithm>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

template<typename T>
T mod(T a, T b){
    return (a + b) % b;
}

template<typename T>
T gcd(T a, T b){
    if (b == 0) return a;
    return gcd(b, a % b);
}

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

// n を素因数分解
map<ll, ll> factor(ll n){
    map<ll, ll> mp;
    for (ll i = 2; i*i <= n; i++) {
        while (n % i == 0) {
            mp[i]++;
            n /= i;
        }
    }

    if (n > 1) {
        mp[n]++;
    }

    return mp;
}

// 文字列に "hoge" が含まれているか
// string str = "hogepiyo";
// if (str.find("hoge") != string::npos) {
//     cout << "文字列が含まれています" << endl;
// }

// char to string
// char c = 'a';
// string str = {c};

void solve(){
    int r;
    cin >> r;

    cout << 3 * r * r << endl;

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


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

const int N = 100005 ;

struct Edge{
    int u , v , w , to ;
}edge[N*2];

int head[N] ;
int e ;

long long dis[N] ;

void init()
{
    e = 0 ;
    memset(head,-1,sizeof head) ;
}

void add(int u , int v , int w)
{
    edge[e].u = u ;
    edge[e].v = v ;
    edge[e].w = w ;
    edge[e].to = head[u] ;
    head[u] = e ++ ;

    edge[e].u = v ;
    edge[e].v = u ;
    edge[e].w = w ;
    edge[e].to = head[v] ;
    head[v] = e ++ ;
}

void dfs(int u , int fa)
{
    for(int i = head[u] ; i != -1 ; i = edge[i].to){
        int v = edge[i].v ;
        int w = edge[i].w ;
        if(v == fa)
            continue ;
        dis[v] = dis[u] + w ;
        dfs(v,u) ;
    }
}

int main()
{
    int n ;
    while(~scanf("%d",&n)){
        init() ;
        for(int i = 0 ; i < n - 1 ; i ++){
            int u , v , w ;
            scanf("%d %d %d",&u,&v,&w) ;
            add(u,v,w) ;
        }
        int q , k ;
        scanf("%d %d",&q,&k) ;
        dis[k] = 0 ;
        dfs(k,-1) ;
        for(int i = 0 ; i < q ; i ++){
            int u , v ;
            scanf("%d %d",&u,&v) ;
            printf("%lld\n",dis[u] + dis[v]) ;
        }
    }
    return 0 ;
}


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

using namespace std;
typedef long long ll;

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;
}

#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1LL << 60;
// ll dp[100010];

int main(){

  int n;cin>>n;
  int h[n+10];rep(i,0,n)cin>>h[i];

  vector<ll>dp(n,INF);
  dp[0]=0;
  rep(i,0,n){
    chmin(dp[i+1],dp[i]+abs(h[i+1]-h[i]));
    chmin(dp[i+2],dp[i]+abs(h[i+2]-h[i]));
  }

  out(dp[n-1]);

  return 0;
}


Measured memory_bytes: 1408
import math
n, m = map(int, input().split())
a = []
for i in range(n):
    l = list(map(int, input().split()))
    a.append(l)
a.sort(key=lambda x: x[0])
sum = 0
cnt = 0
for i in range(n):
    if cnt + a[i][1] >= m:
        sum += (m-cnt)*a[i][0]
        cnt += m-cnt
        break
    else:
        sum += a[i][0]*a[i][1]
        cnt += a[i][1]
print(sum)

Measured memory_bytes: 64600
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use proconio::{input, marker::*};
use superslice::*;
fn main() {
    input! {
        n: usize, m: usize, q: usize,
        abcd: [(Usize1, Usize1, usize, usize); q],
    }
    let mut dabc = abcd.iter().cloned().map(|(a, b, c, d)| (d, a, b, c)).collect_vec();
    dabc.sort_unstable();
    dabc.reverse();

    let mut nums = vec![0; n];
    let ans = dfs(&mut nums, 0, &dabc, 1, m);
    
    println!("{}", ans);

}

fn dfs(nums: &mut [usize], idx: usize, dabc: &[(usize, usize, usize, usize)], mini: usize, m: usize) -> usize {
    if idx == nums.len() {
        let mut sum = 0;
        for &(d, a, b, c) in dabc {
            if nums[b] - nums[a] == c {
                sum += d;
            }
        }
        return sum;
    }

    let mut res = 0;
    for num in mini..=m {
        nums[idx] = num;
        res = max(res, dfs(nums, idx+1, dabc, num, m));
    }
    res
}


Measured memory_bytes: 2168
n,m=map(int,input().split())
s=[]
for _ in range(m):
    s.append(list(map(int,input().split()))[1:])
p=list(map(int,input().split()))

import itertools

cnt=0
for i in itertools.product([0,1],repeat=n):
    tn_arr=[]
    for j in range(m):
        on_cnt=0
        for k in range(len(s[j])):
            on_cnt+=i[s[j][k]-1]
        if on_cnt%2==p[j]:
            tn_arr.append(True)
        else:
            tn_arr.append(False)
    if all(tn_arr):
        cnt+=1

print(cnt)

Measured memory_bytes: 3064
n=int(input());l=[0,1];a=0;b=c=1;p=998244353
for i in range(2,n):l+=[l[p%i]*(p-p//i)%p]
for i in range(n,n//2,-1):a+=b*c%p;b+=b%p;c=c*i*l[n+1-i]%p
print((pow(3,n,p)-2*a)%p)

Measured memory_bytes: 226484
#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;

int main() {
	/*int r;
	cin >> r;
	cout << 3 * r * r;*/


	/*int N, D;
	cin >> N >> D;
	int ans;
	ans = N / (2 * D + 1) + 1;
	if ( N % (2 * D + 1) == 0)ans = N / (2 * D + 1);
	cout << ans;*/


	int N;
	cin >> N;
	vector<pair<int, int>>a(N);
	rep(i, N) {
		cin >> a[i].first;
		a[i].second = i;
	}
	sort(all(a), greater<pair<int, int>>());
	int ans;
	rep(i, N) {
		if (i == a[0].second) {
			ans = a[1].first;
		}
		else {
			ans = a[0].first;
		}
		cout << ans << "\n";
	}


	return 0;
}

Measured memory_bytes: 3200
s = input()
n = len(s)
t = s.replace("x","")
if not t:
  print(0)
  exit()
l = len(t)
if t != t[::-1]:
  print(-1)
  exit()
plc = [-1]
for i in range(n):
  if s[i] != "x":
    plc.append(i)
plc.append(n)
l = len(plc)
if l%2 == 0:
  fm = plc[:l//2]
  lt = plc[l//2:]
else:
  fm = plc[:l//2+1]
  lt = plc[l//2:]
lt = lt[::-1]
ans = 0
for i in range(1,len(fm)):
  ans += abs((fm[i]-fm[i-1])-(lt[i-1]-lt[i]))
print(ans)
  

Measured memory_bytes: 47088
#pragma GCC optimize("O3")

# include <ext/pb_ds/assoc_container.hpp>
# include <ext/pb_ds/tree_policy.hpp>

# include <stdio.h>
# include <bits/stdc++.h>


#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

using namespace __gnu_pbds;
using namespace std;
 
typedef
tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;

inline bool isvowel (char c) {
	c = tolower(c);
    if (c == 'a' || c == 'e' || c == 'i' || c == 'y' || c == 'o' || c == 'u') return 1;
    return 0;
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 6e5 + 123;                                          
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
 
int n, m, k;
int cnt[N];
string s;
int a[N];
vector < int > g[N];
int u[N];
int ans, res;
int cur;

int main () {
	SpeedForce;
	cin >> n >> m;
	for (int i = m - n + 1; i <= m + n - 1; i ++) {
		if (abs(i) <= 100000)
			cout << i << ' ';
	} 

	return Accepted;
}

// B...a

Measured memory_bytes: 18688
#include <iostream>
#include <string>
using namespace std;
int main()
{
	string str1, str2;
	getline(cin, str1);
	getline(cin, str2);
	int len1 = str1.size(), len2 = str2.size();
	if (len1 != len2)
	{
		cout << "No" << endl;
		return 0;
	}
	string str = str2 + str2;
	int i, j = 0, count, begin;
	for (i = 0; i < 2 * len2; i++)
	{
		if (str1[j] == str[i])
		{
			begin = i;
			count = 1;
			while (str1[++j] == str[++i])
				count++;
			if (count == len1)
			{
				cout << "Yes" << endl;
				return 0;
			}
			else
			{
				j = 0;
				i = begin;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}

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

using namespace std;
using ll = long long;

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

#define ALL(o) (o).begin(), (o).end()

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T, vector<T>, greater<T> >;

const ll MOD = 1000000007;

int main() {
	int l,r;
	V<int> v;

	cin >> l >> r;
	int mi = 100000;
	FOR(i,l,r+1) {
		if(i%2019 == 0) {
			cout << 0 << endl;
			return 0;
		}
	}
	FOR(i,l,r+1) {
		FOR(j,i+1,r+1) {
			if(mi > (i%2019)*(j%2019)%2019) {
				mi = (i%2019)*(j%2019)%2019;
			}
		}
	}
	cout << mi << endl;



	/*
    int a = 2018;
    int min = 1000000000;
    REP(i,2018) {
        if(min > a*(i+1)%2019) {
            min = a*(i+1)%2019;
            cout << i+1 << ": " << a*(i+1)%2019 << endl;
        }
    }
    cout << min << endl;
    cout << 2018 * 2016 %2019 << endl;
    cout << 2018 *2 * 2017*3 %2019 << endl;
    cout << 2018 * 2018 %2019 << endl;
*/

}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

void solve()
{
	int x, y;
	while (cin >> x >> y, x || y)
	{
		if (x < y)
		{
			cout << x << " " << y << endl;
		}
		else
		{
			cout << y << " " << x << endl;
		}
	}
}

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

Measured memory_bytes: 1160
n = int(input())
input_lines = input()
alist = list(map(int, input_lines.split(' ')))
sum_list = [0 for i in range(max(alist) + 3)]

for a in alist:
	sum_list[a] += 1
	sum_list[a + 1] += 1
	sum_list[a + 2] += 1

print(max(sum_list))

Measured memory_bytes: 14552
until (n = gets.to_i).zero?
  dp = Array.new(n / 2 + 1){0}
  dp[1] = 1
  (2 .. n / 2).each do |i| dp[i] = 3 * dp[i - 1] + 1 end

  result = n
  (1 ... n / 2).each do |i|
    result += 4 * dp[i]
  end
  result += 2 * dp[n / 2] if n.odd?
  p result
end

Measured memory_bytes: 6096
#include <bits/stdc++.h>
using namespace std;
int cnt[55][200];
string s;
int n;
int main(){
   cin >> n;
   for(int i=1;i<=n;i++){
      cin >> s;
      for(int j=0;j<s.size();j++)
         cnt[i][s[j]]++;
   }
   string res;
   for(int c='a';c<='z';c++){
      int mi = 1000000;
      for(int i=1;i<=n;i++)
         mi = min(mi, cnt[i][c]);
      while(mi--)
         res.push_back((char)c);
   }
   cout << res;
}


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

struct P {string name; int time;};

const int Len = 100005;
P Q[Len];
int head,tail,n;

void enqueue(P x);
P dequeue();

int main(){
	int elaps = 0,c;
	int i,q;
	P u;
	cin>>n>>q;

	for(int i=1;i<=n;i++)
		cin>>Q[i].name>>Q[i].time;

	head = 1,tail = n+1;

	while(head!=tail){
		u = dequeue();
		c = (q>u.time)? u.time:q;
		elaps += c;
		u.time -= c;
		if(u.time>0){
			enqueue(u);
		}else{
			cout<<u.name<<" "<<elaps<<endl;
		}
	}


}

void enqueue(P x){
	Q[tail] = x;
	tail = (tail+1)%Len;
}

P dequeue(){
	P x = Q[head];
	head = (head+1)%Len;
	return x;
}

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

int main(){
	double a,b,c,d;
	cin >> a >> b >> c >> d;

	int m = ceil(c / b);	//q
	int n = ceil(a / d);  //g

	if(m > n) cout << "No" << endl;
	else cout << "Yes" << endl;
}

Measured memory_bytes: 3696
#include<stdio.h>

int main(){
	long int a, b, k;
	scanf("%ld%ld%ld", &a, &b, &k);
	if(a+b<k){
		printf("0 0");
		return 0;
	}else if(a<k){
		b=b-(k-a);
		printf("0 %ld", b);
	}else{
		a=a-k;
		printf("%ld %ld", a, b);
	}
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll maxn=1e5+1;
const ll INF=4e18;
vector<ll> adj_list[maxn];
ll parent[maxn],height[maxn];
ll dfs(ll s,ll p)	// to compute height and the parent of each node
{
	ll h=0;
	parent[s]=p;
	for(ll i=0;i<adj_list[s].size();i++)
	{
		if(adj_list[s][i]!=p)
		{
			h=max(h,1+dfs(adj_list[s][i],s));
		}
	}
	height[s]=h;
	return h;
}
void solve()
{
	ll N,A,T;
	cin>>N>>T>>A;
	for(ll i=0;i<N-1;i++)
	{
		ll u,v;
		cin>>u>>v;
		adj_list[u].push_back(v);
		adj_list[v].push_back(u);
	}
	dfs(A,-1);	// fix A as the root of the tree
	ll cur=T,ans=0,dist=0;
	while(cur!=A)	// to find the distance between T and A 
	{
		cur=parent[cur];
		dist++;
	}
	if(height[T]>0) ans=height[T]+dist-1;
	cur=parent[T];
	ll moved=0;
	while(dist>=0&&cur!=A)
	{
		dist--;	// movement of T
		if(dist==1) ans=max(ans,moved+1LL);
		else if(dist==0) ans=max(ans,moved);
		else if(dist>0) ans=max(ans,moved+dist+height[cur]-1);
		dist--;	// movement of A
		moved++;
		cur=parent[cur];
	}
	cout<<ans<<"\n";
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll T=1,p=0;
	//cin>>T;
	do
	{
		solve();
		p++;
	}while(p<T);
	return 0;
}



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

ll g(ll n){
  ll tmp = n;
  ll res = 0;
  ll digit = 1;
  while(tmp){
    if(tmp == n){
      if(tmp%4 == 2 || tmp%4 == 1){
	res += 1;
      }
      tmp /= 2;
      digit *= 2;
      continue;
    }
    int judge = tmp % 2;
    tmp /= 2;
    if(judge == 0){
      digit *= 2;
      continue;
    } 
    ll cnt = n % digit + 1;
    if(cnt % 2 == 1) res += digit;
    digit *= 2;
  }
  return res;
}

int main(){
  ll r = g(0b10);
  ll A,B;
  cin >> A >> B;
  if(A == 0){
    cout << g(B) << endl;
  }else{
    ll a = g(A-1);
    ll b = g(B);
    ll c = a^b;
    cout << c << endl;
  }
}


Measured memory_bytes: 256
/*
 * atcoder/abc147_2nd/d.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
/* Mod */
#define MOD 1000000007
struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%MOD+MOD)%MOD){}
  // mint(ll x):x(x){}
  mint& fix() { x = (x%MOD+MOD)%MOD; return *this;}
  mint operator-() const { return mint(0) - *this;}
  mint& operator+=(const mint& a){ if((x+=a.x)>=MOD) x-=MOD; return *this;}
  mint& operator-=(const mint& a){ if((x+=MOD-a.x)>=MOD) x-=MOD; return *this;}
  mint& operator*=(const mint& a){ (x*=a.x)%=MOD; return *this;}
  mint operator+(const mint& a)const{ return mint(*this) += a;}
  mint operator-(const mint& a)const{ return mint(*this) -= a;}
  mint operator*(const mint& a)const{ return mint(*this) *= a;}
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
ostream & operator << (ostream & out, mint const & v) {
  out << v.x;
  return out;
}

/*
 * 数式を組み合わせで言い換えると、Aから取り出せるすべてのペアのxorの合計を求める問題.
 * ペアはnC2通り.
 * a_iは２進数60桁
 * 単純化のために0桁目だけを考える.
 * a_iの0桁目の1の個数をaとすると、0の個数bはb=N-a
 * xorは(1, 0)の組だけが1となるので、合計はaからひとつ、bからひとつ選ぶ場合の数に等しい.
 * あとは2^0をかける.
 * それをすべての桁について計算して合計するだけ.
 */
int nth(ll a, int n) {
  return (a>>n)&1;
}
int N;
vector<ll> A;
void solve() {
  cin >> N;
  A.resize(N);
  loop(n,0,N) cin >> A[n];

  mint total = 0;
  for (int d=0; d<=60; d++) {
    mint D = 1LL<<d;
    int num1 = 0;
    for (auto&&a: A) num1 += nth(a, d);
    int num0 = N - num1;
    D *= num1;
    D *= num0;
    total += D;
  }
  cout << total << endl;
}
int main() {
  // cout.precision(15); cout << fixed;

  solve();

  return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#define MOD 1000000007
#define INT long long int
#define REP(i,n) for(int(i)=0;(i)<(n);(i)++) 
using namespace std;
const long long INF = numeric_limits<long long>::max();


int main()
{
    int N;
    cin>>N;
    string s[N];
    REP(i,N) cin>>s[i];
    int ans = 0;
    int LA = 0;
    int FB = 0;
    int LAFB = 0;
    REP(i,N){
        int L = s[i].size();
        REP(j,L-1){
            if (s[i][j] == 'A' && s[i][j+1] == 'B') ++ans;
        }
        if (s[i][L-1] == 'A' && s[i][0] == 'B'){
            ++LAFB;
        }else if(s[i][L-1] == 'A'){
            ++LA;
        }else if(s[i][0] == 'B'){
            ++FB;
        }
    }
    if (LAFB == N){
        cout << ans+N-1 << endl;
        return 0;
    }else{
        if (LA != 0 || FB != 0){
            ans += min(LA,FB) + LAFB;
        }else{
            ans += max(0,LAFB-1);
        }
        cout << ans << endl;
        return 0;
    }


    return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <string>

using namespace std;

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

  if (s[0] != 'A') {
    cout << "WA" << endl;
    return 0;
  }

  int idx = -1;
  for (int i = 2; i < s.size() - 1; i++) {
    if (s[i] == 'C') {
      if (idx < 0) {
        idx = i;
      } else {
        cout << "WA" << endl;
        return 0;
      }
    }
  }
  if (idx < 0) {
    cout << "WA" << endl;
    return 0;
  }

  for (int i = 1; i < s.size(); i++) {
    if (i == idx)
      continue;
    if (s[i] >= 'A' && s[i] <= 'Z') {
      cout << "WA" << endl;
      return 0;
    }
  }
  cout << "AC" << endl;
  return 0;
}


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

int main() {
    int n,count = 0;
    cin >> n;
    vector<int> data(n);
    pair<int,int> a;
    pair<int,int> b;
    for (int i = 0; i < n; i++){
        cin >> data.at(i);
    }
    for (int i = 0; i < n-1; i++){
        if(data.at(i) > data.at(i+1)){
            if(count == 0){
                a.first = i;
                a.second = data.at(i);
                count ++;
            }else if(count == 1){
                b.first = i+1;
                b.second = data.at(i+1);
                count ++;
            }
        }
    }
    swap(data.at(a.first),data.at(b.first));
    for (int i = 0; i < n-1; i++){
        if(data.at(i) > data.at(i+1)){
            cout << "NO" << endl;
            return 0;
        }
    }

        cout << "YES" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main(){
    int a,b;
    int i;
    int A,B;

    scanf("%d %d", &a, &b);
    A = a;
    B = b;

    for(i=1;i<b;i++){
        A += a * pow(10,i);
    }
    for(i=1;i<a;i++){
        B += b * pow(10, i);
    }
    if(a > b){
        printf("%d\n", B);
    }else{
        printf("%d\n", A);
    }

    return 0;

}

Measured memory_bytes: 256
N, T = map(int, input().split())
time_array = list(map(int, input().split()))       
sum_time = 0
for i in range(len(time_array)-1):
    if T > time_array[i+1] - time_array[i]:
        sum_time += time_array[i+1] - time_array[i]
    else:
        sum_time += T

print(sum_time + T)

Measured memory_bytes: 25200
#include <stdio.h>
#define MAX_LENGTH 101
void initial(int numV, int adj[MAX_LENGTH][MAX_LENGTH])
{
    for(int i = 0;i<MAX_LENGTH;i++)
    {
        for(int j = 0;j<MAX_LENGTH;j++)
        {
            adj[i][j]=0;
        }
    }
}
void printMatrix(int numV, int adj[MAX_LENGTH][MAX_LENGTH])
{
    for(int i = 0;i<numV;i++)
    {
        for(int j = 0;j<numV;j++)
        {
            if(j!=numV-1){
                printf("%d ", adj[i][j]);
            }
            else{printf("%d\n", adj[i][j]);}
        }
    }
}
int main() {
    int numV;
    int numA;
    int temp;
    int V[MAX_LENGTH];
    int adj[MAX_LENGTH][MAX_LENGTH];
    scanf("%d", &numV);
    initial(numV, adj);
    for(int i = 0;i<numV;i++)
    {
        scanf("%d", &V[i]);
        scanf("%d", &numA);
        for(int j = 0;j<numA;j++)
        {
            scanf("%d", &temp);
            adj[i][temp-1] = 1;
        }
    }
    printMatrix(numV, adj);
    return 0;
}



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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; }

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

const int MAX_N = 500005;
int N;
string S;

class Node {
public:
    Node(LL v = unitValue) : value(v) {

    }

    Node operator + (const Node& monoid) const {
        return Node(this->getValue() | monoid.getValue());
    }

    static Node unit() {
        return Node(unitValue);
    }

    void setValue(LL l) {
        this->value = l;
    }

    LL getValue() const {
        return this->value;
    }

private:
    LL value;
    static const LL unitValue = 0;
};

template <class T>
class SegmentTree {
public:
    SegmentTree(int size = MAX_N) {
        init(size);
    }

    void init(int size) {
        vec.clear();
        k = 1;
        while(k < size) {
            k *= 2;
        }
        for(int i = 0; i < 2*k; i++) {
            vec.push_back(T::unit());
        }
    }

    void update(int i, T x) { //iをxに変更する
        i += k-1;
        vec[i] = x;
        while(i > 0) {
            i = (i-1)/2;
            vec[i] = vec[i*2+1] + vec[i*2+2];
        }
    }

    T find(int l, int r) {
        return _find(l, r, 0, 0, k);
    }

private:
    vector<T> vec;
    int k;

    T _find(int l, int r, int k, int x, int y) {
        if (r <= x || y <= l) { //重なってない場合
            return T::unit();
        } else if (l <= x && y <= r) { //完全にかぶってる場合
            return vec[k];
        } else { //中途半端にかぶってる場合
            int mid = (x+y)/2;
            T lNode = _find(l, r, 2*k+1, x, mid);
            T rNode = _find(l, r, 2*k+2, mid, y);
            return lNode + rNode;
        }
    }
};

SegmentTree<Node> sg[30];

int Q;

signed main()
{
  cin >> N;
  cin >> S;

  REP(n,N) {
    sg[S[n] - 'a'].update(n,1);
  }

  cin >> Q;
  REP(q,Q) {
    int type;
    cin >> type;
    if(type == 1) {
      int i; char c;
      cin >> i >> c;
      i--;
      sg[S[i] - 'a'].update(i,0);
      S[i] = c;
      sg[S[i] - 'a'].update(i,1);
    } else {
      int l, r;
      cin >> l >> r;
      l--;
      int ans = 0;
      REP(i,27) {
        ans += sg[i].find(l, r).getValue();
      }
      cout << ans << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 252264
#include <bits/stdc++.h>
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
typedef long long int ll;
using namespace std;

int main(){
	int n; cin >>n;
	vector<string> s(n);
	cinf(n,s);
	ll cnt=0;
	ll cnt_A=0;
	ll cnt_B=0;
	ll cntw=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<s[i].size()-1;j++){
			if(s[i][j]=='A'&&s[i][j+1]=='B')cnt++;
		}
		if(s[i][0]=='B')cnt_B++;
		if(s[i][s[i].size()-1]=='A')cnt_A++;
		if(s[i][0]=='B' && s[i][s[i].size()-1]=='A')cntw++;
	}
	if(cntw==cnt_A &&cntw==cnt_B&&cntw!=0)cout << cnt+min(cnt_A,cnt_B)-1<<endl;
	else cout << cnt+min(cnt_A,cnt_B)<<endl;
   
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
#define  pi  pair<int,int>
#define  pb  push_back
#define  F   first
#define  S   second
const int N=2e5+2;
int a[5][5];
int t,i,j,k,x,y,z;
bool ch()
{
    int b[]={i,j,k};
    int c[]={x,y,z};
    for(int i=0;i<3;i++)
    {
        for(int j=0;j<3;j++)
        {
            if((b[i]+c[j])!=a[i][j])
            {
                return false;
            }
        }
    }
    return true;
}
int main()
{
    ft
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            cin>>a[i][j];
        }
    }
    for(i=-200;i<201;i++)
    {
        for(j=-200;j<201;j++)
        {
            for(k=-200;k<201;k++)
            {
                x=a[0][0]-i;
                y=a[1][1]-j;
                z=a[2][2]-k;
                if(ch()==true)
                {
                    cout<<"Yes\n";
                    return 0;
                }
            }
        }
    }
    cout<<"No\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
int main () {
    int n;
    cin >> n;
    int p[n + 1];
    for (int i = 1; i <= n; i++) {
        cin >> p[i];
    }
    int count = 0;
    for (int i = 2; i <= n - 1; i++) {
        if (((p[i] < p[i - 1]) && (p[i + 1] < p[i])) || ((p[i] > p[i - 1]) && (p[i + 1] > p[i]))) {
            count ++;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3620
N,A,B=map(int,input().split())

if A>B:
  C=A
  A=B
  B=C
k=B-A

if k%2==0:
  print(k//2)
else:
  a=A
  b=N+1-B
  if a<b:
    print((A+B-1)//2)
  else:
    D=A+b
    print(b+(N-D)//2)

Measured memory_bytes: 38384
import java.util.*;
import java.io.*;
import java.math.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        Integer[] h = new Integer[n];
        for(int i = 0; i < n; i++){
            h[i] = sc.nextInt();
        }
        Arrays.sort(h,Collections.reverseOrder());
        long ans = 0;
        for(int i = k; i < n; i++){
            ans += h[i];
        }
        System.out.println(ans);
    }
}
 

Measured memory_bytes: 93376
let id x = x

let repeat f = 
  let rec loop lst = function
    | 0 -> List.rev lst
    | n -> loop (f () :: lst) (n-1) in
  loop []

let n = Scanf.scanf "%d\n" id

let a = repeat (fun () -> Scanf.scanf " %d" id) n

let () = 
  let ans = List.fold_left (fun v i -> if i = (v + 1) then v + 1 else v) 0 a in
  print_int @@ if ans = 0 then -1 else n - ans

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

#define rng(i, a, b) for(int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define pb push_back
#define eb emplace_back
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed

int main() {
  int m, q, ans = 0;
  ll a, b, n, x;
  string s;
  cin >> a >> b >> n;
  //vector<int> a(q), b(q), c(q), d(q);
  x = ((b <= n)? b - 1 : n);
  cout << (a * x) / b - (x / b) * a << endl;
}

Measured memory_bytes: 3624
# -*- coding: utf-8 -*-

def main():
     x, y, a, b, c = map(int, input().split())

     # A個の赤いりんごの美味しさ
     p = list(map(int, input().split()))
     # B個の緑のりんごの美味しさ
     q = list(map(int, input().split()))
     # C個の無色のりんごの美味しさ
     r = list(map(int, input().split()))

     p = sorted(p)
     q = sorted(q)
     r = sorted(r, reverse=True)

     p_cut = p[-x:]
     q_cut = q[-y:]

     # print(p_cut)
     # print(q_cut)

     # 無色を1つも使わない場合をベースにする
     red_del = sum(p_cut)
     gre_del = sum(q_cut)
     base_ans = red_del + gre_del

     red_eat = 0
     gre_eat = 0
     cle_eat = 0
     # 交換できる無色を計算
     for i in range(c):
          if red_eat < x and gre_eat < y:
               if p_cut[red_eat] < q_cut[gre_eat]:
                    change = p_cut[red_eat]
                    if change < r[cle_eat]:
                         cle_eat += 1
                         red_eat += 1
                    else:
                         break
               else:
                    change = q_cut[gre_eat]
                    if change < r[cle_eat]:
                         cle_eat += 1
                         gre_eat += 1
                    else:
                         break
          elif red_eat >= x and gre_eat < y:
               change = q_cut[gre_eat]
               if change < r[cle_eat]:
                    cle_eat += 1
                    gre_eat += 1
               else:
                    break
          elif red_eat < x and gre_eat >= y:
               change = p_cut[red_eat]
               if change < r[cle_eat]:
                    cle_eat += 1
                    red_eat += 1
               else:
                    break
          else:
               break

     ans = sum(p_cut[red_eat:]) + sum(q_cut[gre_eat:]) + sum(r[:cle_eat])
     print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 23328
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n ; ++i)
#define REP(i,a,b) for(int i=a; i<b; ++i)
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
//プロトタイプ宣言
int gcd(int , int);
void often(void);
int get_digent(int);


int main(){
  often();
  string s;
  cin >> s;
  if(s == "SUN")cout << 7 << endl;
  if(s[0] == 'M')cout << 6 << endl;
  if(s == "TUE")cout << 5 << endl;
  if(s[0] == 'W')cout << 4 << endl;
  if(s == "THU")cout << 3 << endl;
  if(s[0] == 'F') cout << 2 << endl;
  if(s == "SAT")cout << 1 << endl;
}








































//以下、ライブラリ

int gcd(auto a, auto b) {
  return b ? gcd(b, a%b) : a;
}  //ユークリッドの互除法

void often(void){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

int get_digent(int x){
  string s;
  s = to_string(x);
  int digent = s.size();
  return digent;
} 

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
 int h,m,s;
 int sec;

 scanf("%d",&sec);

 h = sec/3600;
 m = (sec%3600)/60;
 s = (sec%3600)%60;  

 printf("%d:%d:%d\n",h,m,s);

 return 0;
}

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

#define sz 100005
#define ll long long
ll int dp[sz+5],arr[sz+5];

int frog(int pos, int n, int k){
    if(pos>n)return INT_MAX;
    if(pos==n)return 0;
    int a, b;
    if(dp[pos]!=-1)return dp[pos];
    for(ll int i=1; i<=k; i++){
    ll int a=abs(arr[pos]-arr[pos+i])+frog(pos+i,n,k);
     if(dp[pos]==-1)dp[pos]=a;
     else
     dp[pos]=min(dp[pos],a);
    }
    return dp[pos];
}

int main(){

    int n, i, j,k;
    cin>>n>>k;
    for(i=1; i<=n; i++)
    cin>>arr[i];
    memset(dp,-1,sizeof(dp));
    cout<<frog(1,n,k)<<endl;
    return 0;
}


Measured memory_bytes: 9600
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	buf := make([]byte, 1e5+1)
	sc.Buffer(buf, 1e5+1)

	sc.Scan()
	s := []byte(sc.Text())

	sc.Scan()
	t := []byte(sc.Text())

	sNum := make([][]int, 26)
	for i := 0; i < 26; i++ {
		sNum[i] = make([]int, 0)
	}

	for i, el := range s {
		sNum[el-'a'] = append(sNum[el-'a'], i)
	}

	previous := -1
	count := 0
	for _, tel := range t {
		target := sNum[tel-'a']
		if len(target) == 0 {
			fmt.Println(-1)
			return
		}

		if target[len(target)-1] <= previous {
			count++
			previous = target[0]
		} else {
			previous = bs(target, previous)
		}
	}

	fmt.Println(len(s)*count + previous + 1)
}

func bs(array []int, target int) int {
	l := 0
	r := len(array)
	for l < r {
		cur := array[(l+r)/2]
		if cur > target {
			r = (l + r) / 2
		} else {
			l = (l+r)/2 + 1
		}
	}
	return array[l]
}


Measured memory_bytes: 5888
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<math.h>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
const int N=10000;
const db pi=acos(-1.0);
#define lowbit(x) (x)&(-x)
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define fir first
#define sec second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define maxd 1000000007
#define eps 1e-8
int n,k;
ll c[2010][2010];

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

int main()
{
    n=read();k=read();
    rep(i,0,n+1)
    {
        c[i][0]=1;
        rep(j,1,i) c[i][j]=(c[i-1][j-1]+c[i-1][j])%maxd;
    }
    rep(i,1,k)
    {
        ll ans=c[k-1][i-1]*c[n+1-k][i]%maxd;
        printf("%lld\n",ans);
    }
    return 0;
}

Measured memory_bytes: 30208
#include<stdio.h>
#include <stdlib.h>
#include<string.h>
#include<math.h>
#define loop(i, l, r) for(i=l; i<r; i++)/*Instead of function, (for).*/
#define rep(i,r) for(i=0; i<r; i++)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
typedef long long int lli;
/*Return Combination ,(nCr)*/
int combi(int n, int r)
{
	if(r==0 || r==n) return 1;
	else return combi(n-1,r) + combi(n-1,r-1);
}
/*Return gcd(a, b)*/
int gcd(int a, int b){
	if(b == 0) return a;
	else return gcd(b, a % b);
}
int main(void)
{
	int n, i;
	scanf("%d", &n);
	char s[n], t[n];
	scanf("%s%s", s, t);
	rep(i,n){
		printf("%c%c", s[i], t[i]);
	}
	return 0;
}

Measured memory_bytes: 128
using System;

namespace csharp
{
    class Program
    {
        static void Main(string[] args)
        {
            var a = Console.ReadLine();
            var b = 0;
            for(var i=0; i<a.Length; i++){
                b += int.Parse(a[i].ToString());
            }
            var c = int.Parse(a);
            if(c%b == 0){
                Console.WriteLine("Yes");
            } else {
                Console.WriteLine("No");
            }
        }
    }
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <db, db> pdd;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;

#define FOR(k,a,b) for(int k=(a); k<=(b); ++k)
#define IFOR(k,a,b) for(int k=(a); k>=(b); --k)
#define REP(k,a) for(int k=0; k<(a);++k)
#define IREP(k,a) for(int k=a-1; k>=(0);--k)
#define SZ(a) int((a).size())
#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define x first
#define y second
#define INF 1000000001
#define INFLONG 1000000000000000000
#define MOD 1000000007
#define MAX 100
#define ITERS 100
#define MAXM 200000
#define MAXN 1000000
#define PI 3.1415926535897932384626
#define ERR -987654321
#define MEM(a,b) memset(a,b,sizeof(a));
#define read1(a) scanf("%d",&a)
#define read2(a,b) scanf("%d%d",&a,&b)
#define read3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define readl1(a) scanf("%lld",&a)
#define readl2(a,b) scanf("%lld%lld",&a,&b)
#define readl3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//	int rn = uniform_int_distribution<int>(0, MAXN)(rng);

//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

    int n,a,b;
    cin>>n;
    if(n == 1) {
        cout<<"Hello World";
    } else {
        cin>>a>>b;
        cout<<(a+b);
    }
	
	
	return 0;
}






Measured memory_bytes: 256
while 1:
  H, W = map(int, raw_input().split())
  if (H == 0 and W == 0):
    break
 
  print ('#' * W)
  for i in range(1,H-1):
    print ('#' + '.' * (W - 2) + '#' )
  print ('#'* W)
  print""
 

Measured memory_bytes: 6360
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define count(v, t) count(v.begin(), v.end(), t)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
const int INF = 1e9;
const ll mod = 1000000007;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a * b / gcd(a, b);}

int main() {
  cin.tie(0);ios_base::sync_with_stdio(false);
  int n,m,a,b;
  cin >> n >> m;
  vector<int> v[100010];
  priority_queue<int> q;
  for(int i=1; i<=n; ++i) {
    cin >> a >> b;
    v[a].pb(b);
  }
  int res = 0;
  for(int i=1; i<=m; ++i) {
    for(int j=0; j<v[i].size(); ++j) {
      q.push(v[i][j]);
    }
    if (q.size() > 0) {
      res += q.top(), q.pop();
    }
  }
  cout << res << "\n";
}


Measured memory_bytes: 5632
#include<bits/stdc++.h>
using namespace std;
int n,m;
char a[100][100];
queue< pair<int,int> >q;
int d[4]={0,1,-1,0},c[4]={1,0,0,-1};
int dd[100][100];
void step(){
    while(!q.empty()){
        int xx1=q.front().first;
        int xx2=q.front().second;
        q.pop();
        for(int i=0;i<=3;i++){
            int x1=xx1+d[i];
            int x2=xx2+c[i];
            if((a[x1][x2]=='.')&&(dd[x1][x2]==0)){
                dd[x1][x2]=dd[xx1][xx2]+1;
                q.push(make_pair(x1,x2));
            }
        }    
    }
}
int main(){
    cin>>n>>m;
    int count =0;
    dd[1][1]=0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin>>a[i][j];
            if(a[i][j]=='#'){
                count++;
            }
        }
    }
    q.push(make_pair(1,1));
    step();
    if(dd[n][m]==0)
	    cout<<-1;
	else
	    cout<<n*m-count-dd[n][m]-1;

}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

    string s; cin>>s;
    ll k; cin>>k;
    ll n = s.size();

    set<int> st;
    for(int i=0; i<n; i++){
        st.emplace(s[i] - 'a');
    }

    ll ans = 0;
    if(st.size() == 1){
        if(n % 2 == 0){
            ans += n * k / 2;
        }
        else{
            ans += n * ((k + 1) / 2);
            if(k % 2 == 1){
                ans -= n / 2 + 1;
            }
        }
    }
    else{
        if(s[0] != s[n-1]){
            ll cnt = 0;
            for(int i=1; i<n; i++){
                if(s[i-1] == s[i]){
                    s[i] = '@';
                    cnt++;
                }
            }
            ans += cnt * k;
        }
        else{
            ll head = 1;
            char h = s[0];
            for(int i=1; i<n; i++){
                if(h != s[i]) break;
                head++;
            }
            ll tail = 1;
            char t = s[n-1];
            for(int i=n-2; i>=0; i--){
                if(t != s[i]) break;
                tail++;
            }

            if(head % 2 == 1 && tail % 2 == 1){
                ll cnt = 0;
                for(int i=1; i<n; i++){
                    if(s[i-1] == s[i]){
                        s[i] = '@';
                        cnt++;
                    }
                }
                ans += cnt * k;
                ans += (k - 1);
            }
            else{
                ll cnt = 0;
                for(int i=1; i<n; i++){
                    if(s[i-1] == s[i]){
                        s[i] = '@';
                        cnt++;
                    }
                }
                ans += cnt * k;
            }
        }
    }

    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 L = sc.nextInt();
        int R = sc.nextInt();
        long opt=2019;
        if(L==0||R-L>=2019) opt=0;
        else{
            for(long i=L;i<R;i++){
                for(long j=i+1;j<=R;j++){
                    long num = (i*j)%2019;
                    if(opt>num) opt=num;
                }
            }
        }
        System.out.println(opt);
    }
}


Measured memory_bytes: 20564
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph=vector<vector<int>>;
#define MAX 1000000
#define MOD 1000000007
#define INF 1000000000

int main(){
  int N;
  cin>>N;
  vector<int> P(N);
  for(int i=0;i<N;i++){
    cin>>P.at(i);
  }

  vector<int> length(N+1,0);
  for(int i=0;i<N;i++){
    length.at(P.at(i))=length.at(P.at(i)-1)+1;
  }
  int ans=0;
  for(int i=0;i<N+1;i++){
    ans=max(ans,length.at(i));
  }
  cout<<N-ans<<endl;
}


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

int main() {
  int k,x;
  cin >> k >> x;
  for (int i = x-k+1; i < x+k; i++) {
    cout << i << " ";
  }
  cout << endl;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long N;
    cin >> N;
    vector<long long> A(N);
    for(int i = 0; i < N; i++) {
        cin >> A[i];
    }
    sort(A.begin(),A.end());
    bool flag = true;
    for(int i = 0; i < N-1; i++){
        if(A[i] == A[i+1]){
            flag = false;
            break;
        }
    }
    if(flag == true) cout << "YES" << endl;
    else cout << "NO" << endl;
}


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

int main() {
  
  int N,M;
  cin>>N>>M;
  
  vector<int> vec(M*2);
  vector<int> res(N);
  
  for(int i=0;i<M*2;i++)
    cin>>vec.at(i);
  
  for(int i=0;i<M*2;i++)
    res.at(vec.at(i)-1)++;
  

  for(int i=0;i<N;i++) 
    cout<<res.at(i)<<endl;
  
 
}


Measured memory_bytes: 3628
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) (x=min(x,y))
#define chmax(x,y) (x=max(x,y))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}
#define N 200010
vector<int> g[N];
ll d[N], two[N];
int n;

void dfs(int u, int dep){
	d[dep]++;
	for(auto v: g[u]) dfs(v, dep+1);
}

vector<vector<ll>> rec(int u){
	vector<vector<ll>> dp;
	int mx = 0;
	for(auto v: g[u]){
		auto dp2 = rec(v);
		if(dp.size()<dp2.size()) dp.swap(dp2);
		chmax(mx, (int)dp2.size());
		rep(i, dp2.size()){
			auto &a = dp[dp.size()-i-1], &b = dp2[dp2.size()-i-1];
			ll c[3] = {};
			for(int j = 2; j >= 0; j--) rep(k, 3) (c[min(2, j+k)]+=a[j]*b[k])%=mod;
			rep(j, 3) a[j] = c[j];
		}
	}
	for(int i = 0; i < mx; i++){
		auto &x = dp[dp.size()-i-1];
		(x[0]+=x[2])%=mod;
		x[2] = 0;
	}
	dp.emplace_back((vector<ll>){1, 1, 0});
	return dp;
}

int main(){
	cin>>n;
	rep(i, n){
		int p;
		cin>>p;
		g[p].push_back(i+1);
	}
	dfs(0, 0);
	auto dp = rec(0);
	ll res = 0;
	two[0] = 1;
	rep(i, n) (two[i+1]=two[i]*2%mod);
	rep(i, dp.size()) (res+=dp[dp.size()-i-1][1]*two[n+1-d[i]])%=mod;
	cout<<res<<endl;
	/*cerr<<"DEBUG"<<endl;
	rep(i, dp.size()) cerr<<dp[i]<<endl;
	cerr<<endl;
	rep(i, n) cerr<<d[i]<<endl;
	cerr<<endl;*/
	return 0;
}


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

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

const int INF = 1e9 + 7;
const int MAX_COMB = 2001;

using namespace std;

ll g_comb[MAX_COMB][MAX_COMB];

void comb(int n) {

	rep (i, 0, n) {
		g_comb[i][0] = 1;
		g_comb[i][i] = 1;
	}

	rep (i, 1, n)
		rep (j, 1, i)
		g_comb[i][j] = (g_comb[i - 1][j - 1] + g_comb[i - 1][j]) % INF;

}



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

	int n, k;
	cin >> n >> k;

	int red = n - k;
	comb(n + 1);

	rep (i, 1, k + 1) {
		ll blue_place = g_comb[red + 1][i];
		ll blue_position = g_comb[k - 1][i - 1];
		cout << (blue_place * blue_position) % INF << endl;
	}

	return 0;
}


Measured memory_bytes: 30080