akhauriyash/Code-Regression huggingface dataset:
S = list(input())
l = len(S)
if S == list('zyxwvutsrqponmlkjihgfedcba'):
    print(-1)
else:
    if l != 26:
        for i in range(26):
            if not chr(i+97) in S:
                S.append(chr(i+97))
                break
        print(''.join(S))
    else:
        li = []
        for i in range(26):
            c = S.pop()
            li.append(c)
            for x in li:
                if x>c:
                    S.append(x)
                    print(''.join(S))
                    break
            else:
                continue
            break    

Measured memory_bytes: 38256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long ll ;
#define rep(i, a, b) for (int i = a; i <= b; ++ i) 
const int N = 3e5 + 5, inf = 1e9 + 7 ;
using namespace std ;

int W, H, n, d[N] ;
struct poi {
	int x, y ;
} a[N], stl[N], str[N] ;
struct node {
	int tag, mx ;
} tr[N << 2] ;
bool cmp(poi a, poi b) {
	return a.x < b.x ;
}
int find(int ave) {
	int l = 1, r = d[0] ;
	for ( ; l <= r ; ) {
		int mid = (l + r) / 2 ;
		if (d[mid] == ave) return mid ;
		if (ave < d[mid]) r = mid - 1 ; else l = mid + 1 ;
	}
	return 0 ;
}
void pre() {
	d[0] = 0 ;
	rep(i, 1, n) d[++ d[0]] = a[i].x ;
	d[++ d[0]] = 0 ;
	sort(d + 1, d + d[0] + 1) ;
	d[0] = unique(d + 1, d + d[0] + 1) - (d + 1) ;
	rep(i, 1, n) a[i].x = find(a[i].x) ;
}
void psd(int p) {
	int l = p << 1, r = l | 1 ;
	if (tr[p].tag) {
		tr[l].tag += tr[p].tag, tr[l].mx += tr[p].tag ;
		tr[r].tag += tr[p].tag, tr[r].mx += tr[p].tag ;
		tr[p].tag = 0 ;
	}
}
void upd(int p) {
	int l = p << 1, r = l | 1 ;
	tr[p].mx = max(tr[l].mx, tr[r].mx) ;
}
void build(int p, int l, int r) {
	tr[p].tag = 0 ; 
	if (l == r) {
		tr[p].mx = - d[l] + H ;
		return ;
	}
	int mid = (l + r) / 2 ;
	build(p << 1, l, mid), build(p << 1 | 1, mid + 1, r) ;
	upd(p) ;
}
int query(int p, int l, int r, int lx, int rx) {
	if (lx > rx) return - inf ;
	if (l == lx && r == rx) return tr[p].mx ;
	int mid = (l + r) / 2 ; psd(p) ;
	if (rx <= mid) return query(p << 1, l, mid, lx, rx) ;
	if (lx > mid) return query(p << 1 | 1, mid + 1, r, lx, rx) ;
	return max(query(p << 1, l, mid, lx, mid), query(p << 1 | 1, mid + 1, r, mid + 1, rx)) ;
}
void modify(int p, int l, int r, int lx, int rx, int ave) {
	if (lx > rx) return ;
	if (l == lx && r == rx) {
		tr[p].tag += ave, tr[p].mx += ave ;
		return ;
	}
	int mid = (l + r) / 2 ; psd(p) ;
	if (rx <= mid) modify(p << 1, l, mid, lx, rx, ave) ; else
	  if (lx > mid) modify(p << 1 | 1, mid + 1, r, lx, rx, ave) ; else
		modify(p << 1, l, mid, lx, mid, ave) , modify(p << 1 | 1, mid + 1, r, mid + 1, rx, ave) ; 
	upd(p) ;
}
int solve() {
	int res = 0 ;
	sort(a + 1, a + n + 1, cmp) ;
	pre() ;
	build(1, 1, d[0]) ;
	int topl = 0, topr = 0, mid = H / 2 ; 
	poi o ; o.x = 1, o.y = 0 ;
	stl[0] = o, o.y = H, str[0] = o ; 
	rep(i, 1, n) {
		if (a[i].x) res = max(res, d[a[i].x] + query(1, 1, d[0], 1, a[i].x - 1)) ;
		if (a[i].y <= mid) {
			modify(1, 1, d[0], stl[topl].x, a[i].x - 1, - a[i].y) ;
			for ( ; topl && a[i].y >= stl[topl].y ; -- topl) modify(1, 1, d[0], stl[topl - 1].x, stl[topl].x - 1, stl[topl].y - a[i].y) ;
			stl[++ topl] = a[i] ;
		} else {
			modify(1, 1, d[0], str[topr].x, a[i].x - 1, a[i].y - H) ;
			for ( ; topr && a[i].y <= str[topr].y ; -- topr) modify(1, 1, d[0], str[topr - 1].x, str[topr].x - 1, a[i].y - str[topr].y) ;
			str[++ topr] = a[i] ;
		}
	}
	res = max(res, W + query(1, 1, d[0], 1, d[0])) ;
	rep(i, 1, n) a[i].x = d[a[i].x] ;
	return res * 2 ;
}
int main() {
	scanf("%d%d%d", &W, &H, &n) ;
	rep(i, 1, n) scanf("%d%d", &a[i].x, &a[i].y) ;
	int ans = solve() ;
	swap(W, H) ;
	rep(i, 1, n) swap(a[i].x, a[i].y) ;
	ans = max(ans, solve()) ;
	printf("%d\n", ans) ;
	return 0 ; 
}

Measured memory_bytes: 17792
#include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i = 0; i < N; i++)
#define all(x) x.begin(), x.end()
#define sort(x) sort(all(x))
#define cou(x) cout << x << endl
using vi = vector<int>;
using lint = long long;
int main() {
	string s;
	cin >> s;
	deque<char> str;
	rep(i, s.size()) {
		str.push_back(s.at(i));
	}
	int Q, query;
	cin >> Q;
	int flag = 0;
	rep(i, Q) {
		cin >> query;
		if (query == 1) {
			flag++;
		}
		else {
			int f;
			char c;
			cin >> f >> c;
			if (f == 1) {
				if (flag % 2 == 0) {
					str.push_front(c);
				}
				else {
					str.push_back(c);
				}
			}
			else {
				if (flag % 2 == 0) {
					str.push_back(c);
				}
				else {
					str.push_front(c);
				}
			}
		}
	}
	if (flag % 2 == 0) {
		rep(i, str.size()) {
			if (i < s.size()) {
				s.at(i) = str.at(i);
			}
			else {
				s.push_back(str.at(i));
			}
		}
	}
	else {
		rep(i, str.size()) {
			if (i < s.size()) {
				s.at(i) = str.at(str.size() - i - 1);
			}
			else {
				s.push_back(str.at(str.size() - i - 1));
			}
		}
	}
	cou(s);
}

Measured memory_bytes: 1280
import math
import copy
from copy import deepcopy
import sys
import fractions
# import numpy as np
from functools import reduce
# import statistics
import decimal
import heapq
import collections
import itertools
from operator import mul

sys.setrecursionlimit(100001)


# input = sys.stdin.readline
# sys.setrecursionlimit(10**6)

# ===FUNCTION===

def getInputInt():
    inputNum = int(input())
    return inputNum


def getInputListInt():
    outputData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===

s = input()
s = s+" "

ref = ["A", "C", "G", "T"]

tmp = 0
ans = 0
for i in range(len(s)):
    if s[i] in ref:
        tmp += 1
    else:
        ans = max(tmp, ans)
        tmp = 0

print(ans)


Measured memory_bytes: 5164
import java.util.Scanner;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int d = sc.nextInt();
        int n = sc.nextInt();
        
        if(d==0){
            if(n==100){
                System.out.println(n+1);
            }else{
                System.out.println(n);
            }
        }
        if(d==1){
            if(n==100){
                System.out.println(n*100+100);
            }else{
                System.out.println(n*100);
            }
        }
        if(d==2){
            if(n==100){
                System.out.println(n*10000+10000);
            }else{
                System.out.println(n*10000);
            }
        }
        
    }
}

Measured memory_bytes: 22996
import math

def insert_sort(A, n, g):
    cnt = 0
    for i in range(g, n):
        j = i - g
        v = A[i]
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j -= g
            cnt += 1
        A[j+g] = v
    return cnt

def shell_sort(A, n):
    cnt = 0
    
    G = []
    h = 1
    while h <= n:
        G.append(h)
        h = h*3+1
    
    G.reverse()
    
    print(len(G))
    print(*G)
        
    for g in G:
        cnt += insert_sort(A, n, g)
    return cnt

N = int(input())
A = [int(input()) for _ in range(N)]

cnt = shell_sort(A, N)

print(cnt)

for a in A:
    print(a)



Measured memory_bytes: 45580
'use strict'

const main = (input) => {
    input = input.split('\n')
    const A = parseInt(input[0].split(' ')[0])
    const B = parseInt(input[0].split(' ')[1])
    const S = input[1]
    
    let flag = true
    S.split('').forEach((v, i) => {
        if(i === A){
            if(v !== '-'){
                flag = false
            }
        }else{
            if(v === '-'){
                flag = false
            }
        }
    })
    if(flag){
        console.log('Yes')
    }else{
        console.log('No')
    }
}

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

Measured memory_bytes: 21064
# coding: utf-8
# hello worldと表示する
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
lis=[I() for i in range(n)]
lis.sort()
if sum(lis)%10!=0:
    print(sum(lis))
    sys.exit()
ans=sum(lis)
for j in lis:
    if j%10!=0:
        ans-=j
        break
if ans==sum(lis):
    ans=0
print(ans)

Measured memory_bytes: 3316
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque> 
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype> 
using namespace std;

int main(){
    int N, M;
    cin >> N >> M;
    vector<int> a(M), b(M);
    vector<int> c(N,0);
    for (int i=0; i<M; i++) {
        cin >> a.at(i) >> b.at(i);
        c.at(a.at(i)-1)++;
        c.at(b.at(i)-1)++;
    }   
    for (int i=0; i<N; i++) {
        cout << c.at(i) << endl;
    } 
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
 
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n)  for(int i=0;i<(n);++i)
#define REPr(i, n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m, n) for(int i = (n);i >=(m);--i)
#define PB push_back
#define MP make_pair
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x, y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
/* (๑╹◡╹) */
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll MOD = 1000000007;
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;
}
/* (๑╹◡╹)(๑╹◡╹)(๑╹◡╹)(๑╹◡╹)(๑╹◡╹)(๑╹◡╹) */
///////////////////////////////////////////////
const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 



int main() {
	int ans = 0;
	int A,B; cin >> A >> B;
	string s = "Yay!";
	if(A>8 or B>8){s = ":(";}



	cout << s << endl;
	}


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

int main(){
  vector<long int> v;

  int n;
  cin >> n;

  for(int i = 0;i < n;++i){
    int a;
    cin >> a;
    v.push_back(a);
  }
  int i = v.size() - 1;
  for(; i >= 0;i -= 2){
    cout << v[i] << " ";
  }

  for(int j = i == -1 ? i + 1:i + 3;j < v.size();j+=2){
    cout << v[j] << " ";
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 3824
#include<stdio.h>
int main()
{
    int sx,sy,tx,ty;
    while(~scanf("%d%d%d%d",&sx,&sy,&tx,&ty))
    {
        for(int i=1;i<=ty-sy;i++)
            printf("U");
        for(int i=1;i<=tx-sx;i++)
            printf("R");
        for(int i=1;i<=ty-sy;i++)
            printf("D");
        for(int i=1;i<=tx-sx;i++)
            printf("L");
        printf("L");
        for(int i=1;i<=ty-sy+1;i++)
            printf("U");
        for(int i=1;i<=tx-sx+1;i++)
            printf("R");
        printf("D");
        printf("R");
        for(int i=1;i<=ty-sy+1;i++)
            printf("D");
        for(int i=1;i<=tx-sx+1;i++)
            printf("L");
        printf("U\n");
    }
}

Measured memory_bytes: 128
N = int(input())
h = [int(i) for i in input().split()]
dp = [float("inf")]*N

dp[0] = 0

for i in range(N-1):
    dp[i+1] = min(dp[i+1], dp[i] + abs(h[i] - h[i+1]))
    if i < N-2: dp[i+2] = min(dp[i+2], dp[i] + abs(h[i] - h[i+2]))

print(dp[-1])

Measured memory_bytes: 13980
package main

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

func main() {
	H := nextInt()
	answer := solve(H)
	fmt.Println(answer)
}

func solve(h int) int {
	if h == 0 {
		return 0
	}
	if h == 1 {
		return 1
	}
	return 1 + 2*solve(h/2)
}

var scanner *bufio.Scanner

func init() {
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
}
func nextInt() int {
	if !scanner.Scan() {
		panic("No more token.")
	}
	num, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic("nextInt(): cannot convert to int: " + scanner.Text())
	}
	return num
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const int INF = 100000000;
using namespace std;

void warshallFloyd(int m[50][50], map<int, int> t){
    for(auto K = t.begin(); K != t.end(); K++){
        int k = K->first;
        for(auto I = t.begin(); I != t.end(); I++){
            int i = I->first;
            for(auto J = t.begin(); J != t.end(); J++){
                int j = J->first;
                m[i][j] = min(m[i][j], m[i][k] + m[k][j]);
            }
        }
    }
}

int main(){
    int n;
    while(cin >> n, n){
        map<int, int> t;
        int m[50][50];
        int ans[2];
        ans[1] = INF;

        rep(i,50) rep(j,50) m[i][j] = INF;
        rep(i,50) m[i][i] = 0;
        rep(i,n){
            int a, b , c;
            cin >> a >> b >> c;
            m[a][b] = m[b][a] = c;
            t[a] = 1;
            t[b] = 1;
        }

        warshallFloyd(m, t);

        for(auto i = t.begin(); i != t.end(); i++){
            int sum = 0;
            for(auto j = t.begin(); j != t.end(); j++){
                sum+=m[i->first][j->first];
                //show(sum)
            }
            if(sum < ans[1] || (sum == ans[1] && ans[0] > i->first)){
                ans[0] = i->first;
                ans[1] = sum;
            }
        }
        cout << ans[0] << ' ' << ans[1] << endl;
    }
}

Measured memory_bytes: 2980
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<set>
#include<map>
#include<random>
#include<functional>

#define rep(i,n) for(int i=0; i<n; i++)
#define pb push_back
#define pint pair<int, int>
#define mp make_pair

using namespace std;

typedef long long ll;


const int INF = 1e7;

struct xyd
{
	int x, y, d;
	xyd(int x, int y, int d):x(x), y(y), d(d){}
};

int N, K;
vector<int> x, y, d;
vector<xyd> xyd1, xyd2;
int imos[105][105][105] = {};

int main() {
	cin >> N >> K;
	rep(i, N) {
		int x1, y1, d1, x2, y2, d2;
		cin >> x1 >> y1 >> d1 >> x2 >> y2 >> d2;

		xyd1.push_back(xyd(x1, y1, d1));
		xyd2.push_back(xyd(x2, y2, d2));

		x.push_back(x1); x.push_back(x2);
		y.push_back(y1); y.push_back(y2);
		d.push_back(d1); d.push_back(d2);
	}

	sort(x.begin(), x.end()); sort(y.begin(), y.end()); sort(d.begin(), d.end());
	x.erase(unique(x.begin(), x.end()), x.end());
	y.erase(unique(y.begin(), y.end()), y.end());
	d.erase(unique(d.begin(), d.end()), d.end());

	int xn = x.size(), yn = y.size(), dn = d.size();

	for (int i = 0; i < N; i++) {
		int x1 = lower_bound(x.begin(), x.end(), xyd1[i].x) - x.begin();
		int y1 = lower_bound(y.begin(), y.end(), xyd1[i].y) - y.begin();
		int d1 = lower_bound(d.begin(), d.end(), xyd1[i].d) - d.begin();
		int x2 = lower_bound(x.begin(), x.end(), xyd2[i].x) - x.begin();
		int y2 = lower_bound(y.begin(), y.end(), xyd2[i].y) - y.begin();
		int d2 = lower_bound(d.begin(), d.end(), xyd2[i].d) - d.begin();

		imos[x1][y1][d1]++;

		imos[x2][y1][d1]--;
		imos[x1][y2][d1]--;
		imos[x1][y1][d2]--;

		imos[x1][y2][d2]++;
		imos[x2][y1][d2]++;
		imos[x2][y2][d1]++;

		imos[x2][y2][d2]--;
	}
	
	for (int i = 0; i < xn; i++) {
		for (int j = 0; j < yn; j++) {
			for (int k = 1; k < dn; k++) {
				imos[i][j][k] += imos[i][j][k-1];
			}
		}
	}
	for (int i = 0; i < xn; i++) {
		for (int j = 1; j < yn; j++) {
			for (int k = 0; k < dn; k++) {
				imos[i][j][k] += imos[i][j-1][k];
			}
		}
	}
	for (int i = 1; i < xn; i++) {
		for (int j = 0; j < yn; j++) {
			for (int k = 0; k < dn; k++) {
				imos[i][j][k] += imos[i-1][j][k];
			}
		}
	}
	
	
	ll ans = 0;
	for (int i = 0; i < xn-1; i++) {
		for (int j = 0; j < yn-1; j++) {
			for (int k = 0; k < dn-1; k++) {
				if (imos[i][j][k] >= K) {
					ans += (ll)(x[i + 1] - x[i])*(y[j + 1] - y[j])*(d[k + 1] - d[k]);
				}
			}
		}
	}

	cout << ans << endl;


	return 0;
}



Measured memory_bytes: 7428
n = int(input())
A = list(map(int, input().split()))
cnt = 0
minus = 0

for a in A:
    if a < 0:
        cnt += 1

if cnt%2 == 0:
    print(sum( [ abs(a) for a in A ] ))
else:
    print(sum( [ abs(a) for a in A ] ) - min([ abs(a) for a in A ] )*2)

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

using namespace std;

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

    string prediction;
    switch (weatherOfToday[0]){
        case 'S':
            prediction = "Cloudy";
            break;
        case 'C':
            prediction = "Rainy";
            break;
        case 'R':
            prediction = "Sunny";
            break;
    }
    cout << prediction << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl
using namespace std;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
#define pb push_back
template<class T> void print(const T& x){cout << x << endl;}
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
typedef long long ll;
const int inf = 1000000001;
const ll INF = 1e18 * 4;

int main(){
    int N; cin >> N;
    int ans = inf;
    vi W(N, 0);
    rep(i, 0, N) cin >> W[i];
    rep(j, 0, N){
        int s1 = 0;
        int s2 = 0;
        rep(i, 0, j){
            s1 += W[i];
        }
        rep(i, j, N){
            s2 += W[i];
        }
        ans = min(ans, abs(s2-s1));
    }
    cout << ans << endl;

    return 0;
}




Measured memory_bytes: 3604
N = int(input())
li = list(map(int, input().split()))
if 1 not in li:
	print(-1)
else:
	num = 1
	b = 0
	for i in range(len(li)):
		if li[i] == num:
			num += 1
		else:
			b += 1
	print(b)

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

int main() {
	int n,i,j;
	cin >>n;
	int a[n+1],dp[n+1];
	for(i=1;i<=n;i++)
	cin >>a[i];
	dp[1]=0;
	dp[2]=abs(a[2]-a[1]);
	for(i=3;i<=n;i++)
	{
        dp[i]=min(abs(a[i-1]-a[i])+dp[i-1],abs(a[i-2]-a[i])+dp[i-2]);
	}
	cout<<dp[n];
	
	return 0;
}

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


def next_line():
    return input()


def next_int():
    return int(input())


def next_int_array_one_line():
    return list(map(int, input().split()))


def next_int_array_multi_lines(size):
    return [int(input()) for _ in range(size)]


def next_str_array(size):
    return [input() for _ in range(size)]


def main():
    n = next_int()
    ar = list(reversed(sorted(next_int_array_one_line())))
    # print(ar)
    res = ar[0]
    n -= 2
    use = 1
    while n > 0:
        if n >= 2:
            res += ar[use] * 2
            n -= 2
            use += 1
        else:
            res += ar[use]
            n -= 1
    print(res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 103932
using System;
using System.Linq;

namespace procon
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var inputs = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var x = inputs[0];
            var y = inputs[1];
            
            var min = Math.Min(x, y);
            var max = Math.Max(x,y);
            var mod = max%min;
            while(mod != 0)
            {
                max = Math.Max(min, mod);
                min = Math.Min(min, mod);
                mod = max % min;
            }

            Console.WriteLine(min);
        }
    }
}

Measured memory_bytes: 9556
n,m=map(int,input().split())

lamp=[]
switches=[]
temp=[]

for i in range(m):
    temp=list(map(int,input().split()))
    lamp.append(temp.pop(0))
    switches.append(temp)
    temp=[]

modul=list(map(int,input().split()))

bit_list=[]

for i in range(2**(n)):
    bit_list.append(bin(i)[2:].zfill(n))

ans = 0

for b in bit_list:
    flag = 0
    for s,p in zip(switches,modul):
        sum = 0
        for k in range(len(s)):
            sum=sum+int(b[s[k]-1])
        if sum%2 != p:
            flag = 1
            break
    if flag == 0:
        ans=ans+1

print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main(){
    int a, b, c;
    cin >> a >> b >> c;
    int ans = c - (a-b);
    if(ans <0) cout << 0 << endl;
    else cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
/* clang-format on */

int main() {
  int N, D;
  while (cin >> N >> D) {
    vector<int> d(N);
    for (int i = 0; i < N; i++) cin >> d[i];
    vector<int> A(N + 1);
    A[0] = D;
    for (int i = 0; i < N; i++) {
      if (d[i] < 2 * A[i]) {
        A[i + 1] = abs(A[i] - d[i]);
      } else {
        A[i + 1] = A[i];
      }
    }
    vector<int> B(N + 1);
    B[N] = 1;
    for (int i = N - 1; i >= 0; i--) {
      if (d[i] >= 2 * B[i + 1]) {
        B[i] = B[i + 1];
      } else {
        B[i] = B[i + 1] + d[i];
      }
    }
    int Q;
    cin >> Q;
    for (int i = 0; i < Q; i++) {
      int q;
      cin >> q;
      --q;
      bool res = A[q] >= B[q + 1];
      cout << (res ? "YES" : "NO") << '\n';
    }
    cout << endl;
  }
  return 0;
}


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


int main() {
    int N;
    cin >> N;

    vector<int> a(3 * N);
    rep (i, 3 * N) {
        cin >> a.at(i);
    }

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

    ll res = 0;

    for (int i = N; i < 3 * N ; i += 2) {
        res += a.at(i);
    }
    cout << res << endl;


}


Measured memory_bytes: 4584
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
struct state { int cnt; long long sum; };
int N, K; long long L, R, a[50];
int main() {
	cin >> N >> K >> L >> R;
	for (int i = 0; i < N; i++) cin >> a[i];
	int sep1 = N / 2, sep2 = N - sep1;
	vector<state> sl(1 << sep1), sr(1 << sep2);
	for (int i = 0; i < sep1; i++) {
		int bl = (1 << i), br = (bl << 1);
		for (int j = bl; j < br; j++) {
			state v = sl[j - bl];
			sl[j] = state{ v.cnt + 1, v.sum + a[i] };
		}
	}
	for (int i = 0; i < sep2; i++) {
		int bl = (1 << i), br = (bl << 1);
		for (int j = bl; j < br; j++) {
			state v = sr[j - bl];
			sr[j] = state{ v.cnt + 1, v.sum + a[i + sep1] };
		}
	}
	vector<vector<long long> > tl(sep1 + 1), tr(sep2 + 1);
	for (int i = 0; i < 1 << sep1; i++) tl[sl[i].cnt].push_back(sl[i].sum);
	for (int i = 0; i < 1 << sep2; i++) tr[sr[i].cnt].push_back(sr[i].sum);
	for (int i = 0; i <= sep1; i++) sort(tl[i].begin(), tl[i].end());
	for (int i = 0; i <= sep2; i++) sort(tr[i].begin(), tr[i].end());
	long long ret = 0;
	for (int i = 0; i <= sep1; i++) {
		for (int j = 0; j <= sep2; j++) {
			if (i + j != K) continue;
			for (long long x : tl[i]) {
				int pl = lower_bound(tr[j].begin(), tr[j].end(), L - x) - tr[j].begin();
				int pr = lower_bound(tr[j].begin(), tr[j].end(), R - x + 1) - tr[j].begin();
				ret += pr - pl;
			}
		}
	}
	cout << ret << endl;
	return 0;
}

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

int main() {
    long double a, b, c; cin >> a >> b >> c;
    if(1+sqrt(b/a)<sqrt(c/a)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl "\n"
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define B begin()
#define E end()
using namespace std;
typedef long long ll;
typedef double D;
typedef vector<ll> VL;
typedef set<ll> SL;
ll M= 1e9+7;	

void solve()
{
	ll n;
	cin>>n;
	vector<ll> dp(n+1, 1);
	for(int i=2;i<=n;i++)
	{
		ll o=i;
		while(o<=n)
		{
			dp[o]++;
			o+=i;
		}
	}
	ll ans=0;
	for(int i=1;i<=n;i++) ans+=i*dp[i];
	cout<<ans;
}

int main()
{
    IOS
    int t=1;
    //cin>>t;
    while(t--)
    {
	    solve();
    }
    
    return 0;
}




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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const ll MOD = 1000000007;
int n, m;
ll h[100005];
vector<vector<int>> g;

ll GCD(ll x, ll y){
	return y ? GCD(y, x%y) : x;	
}

int main() {
	int n, m; cin >> n >> m;
	for(int i=1;i<=n;i++){
		cin >> h[i];
	}
	int a[100005], b[100005];
	g.clear();
	g.resize(n+1);
	for(int i=1;i<=m;i++){
		cin >> a[i] >> b[i];
		g[a[i]].push_back(b[i]);
		g[b[i]].push_back(a[i]);
	}
	int ans = n;
	for(int i=1;i<=n;i++){
		for(auto c: g[i]){
			if(h[i]<=h[c]){
				ans--;
				break;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 9800
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
const ll mod=1e9+7;

ll power(ll x,ll n){
  if(n==0) return 1;
  ll res=power(x*x%mod,n/2);
  if(n&1) res=res*x%mod;
  return res;
}

int main(){
  int n;
  cin>>n;
  ll a=power(10,n);
  ll b=power(9,n);
  ll c=power(8,n);
  ll d=a-b-b+c;
  while(d<0) d+=mod;
  cout<<d<<endl;
}

Measured memory_bytes: 3616
#include<iostream>
using namespace std;
int main(){
    long long A,B,K;
    cin>>A>>B>>K;
    
    if(A+B<=K){
       A=0;
       B=0;
    }
    else{
        if(A>=K){
            A=A-K;
        }
        else{
            B=B-(K-A);
            A=0;
        }
    }
    
    cout<<A<<" "<<B<<endl;

}

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

using namespace std;

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

const ll INF=1e9+7;
int n,m,q[100001],dag[100001],maxf=-1;
vector<int> v[100001];
int tail,head;
int dp[100001];
int main(){
	/*freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);*/
	cin>>n>>m;
	rep(i,m){
		int x,y;
		cin>>x>>y;
		v[x].push_back(y);
		dag[y]++;
	}
	rep(i,n){
		if(!dag[i]){
			q[++tail]=i;
		}
	}
	while(head<tail){
//		cout<<head<<' '<<tail<<endl;
		int x=q[++head];
		maxf=max(maxf,dp[x]);
		rep0(i,v[x].size()){
			dp[v[x][i]]=max(dp[v[x][i]],dp[x]+1);
			dag[v[x][i]]--;
			if(!dag[v[x][i]]){
				q[++tail]=v[x][i];
			}
		}
	}
	cout<<maxf;
	return 0;
}

Measured memory_bytes: 6912
#include<stdio.h>
#include<math.h>
int main(void){
  long long n;
  scanf("%lld",&n);
  //if(sqrt(n)*sqrt(n)==n)printf("%.0lf",2*sqrt(n)-2);
  
    
    for(long i=sqrt(n);i>=1;i--){
      if(n%i==0)		//約数あり
      {printf("%ld",i+n/i-2);
       return 0;}
      
                }
    
  }

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
typedef long long ll;
using namespace std;

void HalfAndHalf() {
	int A, B, C, X, Y;
	cin >> A >> B >> C >> X >> Y;
	int AB = C * 2;
	ll res = 0;
	if (AB < A + B ) {
		res += min(X, Y) * AB;
		if (X < Y) {
			int rem = Y - X;
			cout << (res + min(rem * B, AB * rem)) << endl;
		}
		else {
			int rem = X - Y;
			cout << (res + min(rem * A, AB * rem)) << endl;
		}
	}
	else {
		cout << (X * A + Y * B) << endl;
	}

}

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

Measured memory_bytes: 256
import math

a,b,x = map(int,input().split())
S = a * b / 2

if S >= x/a:
  change_length = 2*x/(a*b)
  rad = math.atan2(b, change_length)
else:
  change_length = (2*b - 2*x/(a**2))
  rad = math.atan2(change_length, a)
Theta = math.degrees(rad)
print('{:.10f}'.format(Theta))

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

int main(){
	int a,b;
  	cin>>a>>b;
  	int cnt = 0;
  	int now = 1;
  	while(1){
    	if(now>=b) break;
      	now += a -1;
      	cnt++;

    }
  	cout<<cnt<<endl;
}

Measured memory_bytes: 256
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;

#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let a: i32 = read_as_vec()[0];
    let s = read_as_string();

    if a >= 3200{
        println!("{}", s);
    }else{
        println!("red");
    }
}


Measured memory_bytes: 4352
n,*z=`dd`.split.map &:to_i;t=*0...n;*e=t;a=z.shift n+1;n.downto(1){|i|a[i]-=a[i-1]};k,*z=z;z.map{|x|t[x-2,2]=t[x-1],t[x-2]};60.times{|i|k[i]>0&&e.map!{|q|t[q]};t=t.map{|q|t[q]}};k,*a=a;e.map{|q|p k;k+=a[q]}

Measured memory_bytes: 57440
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
money = 0
AB = sorted(AB, key=lambda x: x[0])
if M <= AB[0][1]:
  money += AB[0][0] * M
else:
  i = 0
  while M > 0:
    money += AB[i][0] * AB[i][1]
    M -= AB[i][1]
    if M <= 0:
      money += AB[i][0] * M
      break
    i += 1
print(money)


Measured memory_bytes: 65368
def resolve():
    l, r = map(int, input().split())
    result = 2018
    for i in range(l, r):
        for j in range(i+1, r+1):
            result = min(result, (i * j) % 2019)
            if result == 0:
                print(0)
                return
    print(result)
    
resolve()

Measured memory_bytes: 38896
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <queue>
#include <map>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
#define INF 1e10
typedef long long ll;
typedef long double ld;
int main(){
    ll x;
    cin>>x;
    vector<ll> v;
    FOR(i,1,x+1)FOR(j,2,x+2){
        ll num=pow(i,j);
        if(num<=x)v.push_back(num);
    }
    cout<<MAX(v)<<endl;
    return 0;
}


Measured memory_bytes: 12144
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ll long long
#define MOD 1000000007
#define MAX 1000010
using namespace std;


int main(){
  int a,b;
  cin >> a>>b;
  
  if(a==b) cout << "Yes";
  else cout << "No";
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <stack>

#define pb push_back
#define ins insert
#define pob pop_back
#define er erase
#define emp empty
#define f first
#define s second
#define ff f.f
#define fs f.s
#define sf s.f
#define ss s.s
#define var auto

using namespace std;
template<typename  T>
using s = set<T>;
template<typename T>
using  v = vector<T>;
template<typename T1, typename  T2>
using p = pair < T1, T2>;
typedef long long ll;
typedef p<int, int> pii;
typedef v<int> vi;
typedef v<pii> vpii;
typedef s<int> si;
typedef s<pii> spii;


const int Max = 4e3 + 100;
const int MOD = 1e9 + 7;
ll dp[Max][Max];
int main()
{
	int n, m
		; cin >> n >> m;

	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
		{
			char c; cin >> c;
			if (c == '#')
				dp[i][j] = -1;
		}
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			if (dp[i][j] == -1)
				dp[i][j] = 0;
			else
			{
				if (i > 0 && j > 0)
					dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % MOD;
				else if (i > 0)
					dp[i][j] = (dp[i - 1][j]) % MOD;
				else if (j > 0)
					dp[i][j] = (dp[i][j - 1]) % MOD;
				else
					dp[i][j] = 1;
			}
		}
	}
	cout << dp[n - 1][m - 1];
}

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

using namespace std;


int main()
{
	int n, m;
	cin >> n >> m;
	int kijun = 0;
	vector<int> hyou(n);
	for (int i = 0; i < n; i++) {
		cin >> hyou[i];
		kijun += hyou[i];
	}

	sort(hyou.begin(), hyou.end(), greater<int>());

	kijun = (kijun - 1) / (4 * m) + 1;

	if (hyou[m - 1] < kijun) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main { 
  public static void main(String[] args){
    Scanner scanner = new Scanner(System.in);
    int a = scanner.nextInt();
    int b = scanner.nextInt();
    int ans1 = a * b;
    int ans2 = 2 * (a + b);
    System.out.println(ans1 + " " + ans2);
  }
}


Measured memory_bytes: 26036
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)
#define REV(X, Y, Z) for (ll(X) = (Y); (X) > (Z); (X)--)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMod = 1e9 + 7;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

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

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  ll H, W;
  cin >> H >> W;
  vector<string> A(H);
  REP(i, 0, H) {
    string s;
    cin >> s;
    A[i] = s;
  }

  REP(i, 0, W+2) {
    cout << "#";
  }
  cout << endl;

  REP(i, 0, H) {
    cout << "#" << A[i] << "#" << endl;
  }

  REP(i, 0, W+2) {
    cout << "#";
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define MAX_N 100100
const int INF = 1e9;
int n, k;
int h[MAX_N];
int dp[MAX_N];

int main() {
    cin >> n >> k; 
    for (int i = 0; i < n; i++) cin >> h[i];
    fill(dp, dp + MAX_N, INF);
    dp[0] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 1; j <= k; j++) {
            if (i + j < n) { 
                dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
            }
        }
    }
    cout << dp[n-1] << endl;
}

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

using ll = long long;
int INF = numeric_limits<int>::max() / 2;
ll LINF = numeric_limits<ll>::max() / 2;
int MOD = 1e9 + 7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    vector<bool> a(s.size(), false);
    for(int i = 0; i < s.size(); i++){
        if(a[s[i] - 'a']){
            cout << "no" << endl;
            return 0;
        }else{
            a[s[i] - 'a'] = true;
        }
    }
    cout << "yes" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
template<class Type_a,class Type_b> bool chmax(Type_a &a,const Type_b &b){if(a<b){a=b;return true;}return false;}
template<class Type_a,class Type_b> bool chmin(Type_a &a,const Type_b &b){if(a>b){a=b;return true;}return false;}
template<class Type> Type igcd(Type x,Type y){return (y==0)?x:igcd(y,x%y);}
template<class Type> Type ilcm(Type x,Type y){return x/igcd(x,y)*y;}
template<class Type> void line(const Type &a){int cnt=0;for(const auto &elem:a){if(cnt++)cout<<' ';cout<<elem;}cout<<endl;}

//参加者解答参考.
int main(){
	int w,h;
	cin>>w>>h;
	
	priority_queue<pii,vector<pii >,greater<pii > > que;//pii(cost,jud)
	REP(i,w){
		int p;
		cin>>p;
		que.push(pii(p,0));
	}
	REP(i,h){
		int q;
		cin>>q;
		que.push(pii(q,1));
	}
	
	llong ans=0;
	int nw=w+1,nh=h+1;
	while(!que.empty()){
		int cost;
		int jud;
		tie(cost,jud)=que.top();
		que.pop();
		
		if(jud==0){
			ans+=(llong)cost*nh;
			nw--;
		}else{
			ans+=(llong)cost*nw;
			nh--;
		}
	}
	
	cout<<ans<<endl;
}

Measured memory_bytes: 3444
import java .util.Scanner;
 
public class Main{
    public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = Integer.parseInt(sc.next());//高橋体力
    	int b = Integer.parseInt(sc.next());//高橋攻撃
		int c = Integer.parseInt(sc.next());//青木体力
    	int d = Integer.parseInt(sc.next());//青木攻撃

 		while(true){
			c -= b;
			if(c <= 0){
				System.out.println("Yes");
				break;
			}

			a -= d;
			if(a <= 0){
				System.out.println("No");
				break;
			}
		}
	}
}

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

int main() {
    int N, K;
    cin >> N >> K;
    vector <int> l(N);
    for (int i=0; i<N; i++) cin >> l.at(i);
    sort(l.begin(), l.end());
    reverse(l.begin(), l.end());
    int res=0;
    for (int i=0; i<K; i++) res+=l.at(i);
    cout << res << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const string EMP = " ";
const ll INF = 1LL<<60;
const ll MOD = 1000000007;

int main(){
  int n,m; cin >> n >> m;
  vector<int> a(m);
  rep(i,m) cin >> a[i];
  if(n >= m){
    cout << 0 << endl;
    return 0;
  }
  sort(a.begin(), a.end());
  vector<int> dist;
  for(int i = 1; i < m; i++){
    dist.push_back(a[i]-a[i-1]);
  }
  sort(dist.begin(), dist.end());
  int ans = 0;
  for(int i = 0; i < m-n; i++){
    ans += dist[i];
  }
  cout << ans << endl;
  return 0;
}


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

int main(void){
    int n; cin >> n;
    ll f[n][10], p[n][11];
    for(int i=0;i<n;i++) for(int j=0;j<10;j++) cin >> f[i][j];
    for(int i=0;i<n;i++) for(int j=0;j<11;j++) cin >> p[i][j];
    ll ans=-1*pow(10,10);
    for(int i=1;i<(1<<10);i++){
        ll tmp=0;
        for(int j=0;j<n;j++){
            ll cnt=0;
            for(int k=0;k<10;k++) if((i>>k&1)==1 && f[j][k]==1) cnt++;
            tmp += p[j][cnt];
        }
        if(ans<tmp) ans = tmp;
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
    ll N,M;
    cin >>N >>M;
    vector<vector<P>> pref(N);
    for(int i=0;i<M;i++){
        ll p,y;
        cin >>p >>y;
        --p;
        pref[p].push_back(P(y,i));
    }

    vector<P> ans(M);
    for(int i=0;i<N;i++){
        sort(pref[i].begin(),pref[i].end());
        for(int j=0;j<pref[i].size();j++){
            ans[pref[i][j].second] = P(i+1,j+1);
        }
    }

    for(int i=0;i<M;i++){
        printf("%06lld",ans[i].first);
        printf("%06lld",ans[i].second);
        cout << "\n";
    }



    return 0;
}

Measured memory_bytes: 10136
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

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


int main() {
    
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    REP(i, N) cin >> A[i];

    ll ans = 0;
    const ll MOD = 1e9 + 7;
    ll tmp1, tmp2;
    ll K1 = K * (K + 1) / 2;
    K1 %= MOD;
    ll K2 = K * (K - 1) / 2;
    K2 %= MOD;
    REP(i, N){
        tmp1 = 0;
        tmp2 = 0;
        REP(j, N){
            if (i == j) continue;
            if (A[i] > A[j]){
                if (i < j) tmp1++;
                else tmp2++;
            }
        }
        
        tmp1 = (tmp1 * K1 )% MOD;
        tmp2 = (tmp2 * K2) % MOD;
        ans = (ans + tmp1) % MOD;
        ans = (ans + tmp2) % MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys

lines = sys.stdin.readlines()

N = int(lines[0])
K = int(lines[1])
X = lines[2].split(' ')
x =[]

y = 0
for i in range(N):
  x.append(int(X[i]))
  if 2*x[i] >= K:
      dist = 2*(K-x[i])
  else:
      dist = 2*x[i]
  y = y + dist

print(y)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()
{
	int n;
	cin >> n;
	
	int sum[50][22] = {};
	vector<pair<int, int>> a(n);
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;

		bool f = true;
		int p = 0;
		long long num = 0;
		for (int j = 0; j < s.length(); j++) {
			if (s[j] == '.') {
				f = false;
				p = j;
			} else {
				num = num * 10 + (s[j] - '0');
			}
		}

		if (f) {
			num *= 1000000000;
		} else {
			for (int j = 0; j < (10 - (s.length() - p)); j++) {
				num *= 10;
			}
		}

		int n2 = 0, n5 = 0;
		while (num % 2 == 0) {
			n2++;
			num /= 2;
		}
		while (num % 5 == 0) {
			n5++;
			num /= 5;
		}

		sum[n2][n5]++;
		a[i] = make_pair(n2, n5);
	}

	for (int i = 0; i < 50; i++) {
		for (int j = 1; j < 22; j++) {
			sum[i][j] += sum[i][j - 1];
		}
	}
	for (int i = 1; i < 50; i++) {
		for (int j = 0; j < 22; j++) {
			sum[i][j] += sum[i - 1][j];
		}
	}

	long long ans = 0;
	for (int i = 0; i < n; i++) {
		if (a[i].first >= 18) {
			if (a[i].second >= 18) {
				ans += n - 1;
			} else if (a[i].second >= 9) {
				ans += sum[49][21] - sum[49][17 - a[i].second] - 1;
			} else {
				ans += sum[49][21] - sum[49][17 - a[i].second];
			}
		} else if (a[i].first >= 9) {
			if (a[i].second >= 18) {
				ans += sum[49][21] - sum[17 - a[i].first][21] - 1;
			} else if (a[i].second >= 9) {
				ans += sum[49][21] - sum[17 - a[i].first][21] - sum[49][17 - a[i].second] + sum[17 - a[i].first][17 - a[i].second] - 1;
			} else {
				ans += sum[49][21] - sum[17 - a[i].first][21] - sum[49][17 - a[i].second] + sum[17 - a[i].first][17 - a[i].second];
			}
		} else {
			if (a[i].second >= 18) {
				ans += sum[49][21] - sum[17 - a[i].first][21];
			} else if (a[i].second >= 9) {
				ans += sum[49][21] - sum[17 - a[i].first][21] - sum[49][17 - a[i].second] + sum[17 - a[i].first][17 - a[i].second];
			} else {
				ans += sum[49][21] - sum[17 - a[i].first][21] - sum[49][17 - a[i].second] + sum[17 - a[i].first][17 - a[i].second];
			}
		}
	}
	cout << ans / 2 << endl;

    return 0;
}

Measured memory_bytes: 4696
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  int n, k;
  cin >> n >> k;
  vi a(n);
  rep(i, n) cin >> a[i];
  rep(_, k) {
    vi s(n + 2, 0);
    rep(j, n) {
      ll l = max(0, j - a[j]);
      ll r = min(n, j + a[j] + 1);
      s[l + 1]++;
      s[r + 1]--;
    }
    bool ok = true;
    rep(j, n) {
      s[j + 1] += s[j];
      if(s[j + 1] < n) ok = false;
      a[j] = s[j + 1];
    }
    if(ok) break;
  }
  rep(i, n) cout << a[i] << (i == n - 1 ? '\n' : ' ');
}

Measured memory_bytes: 4780
N = int(input())
A = [0] * N
B = [0] * N
for i in range(N):
  a, b = list(map(int, input().split()))
  A[i] = a
  B[i] = b
  
A = sorted(A)
B = sorted(B)

if N % 2 == 1:
  x = int((N + 1)// 2)
  ans = abs(B[x - 1] - A[x - 1]) + 1
else:
  x = int(N // 2)
  a = A[x] + A[x - 1]
  b = B[x] + B[x - 1]
  #print(a, b)
  ans = abs(b - a) + 1
  
print(ans)
  
  

Measured memory_bytes: 27000
#include<stdio.h>

int main(){
  int count=0;
  double data, max, min, ans;

  while(scanf("%lf", &data) != EOF){
    if(data > max || count == 0)
      max = data;
    if(data < min || count == 0)
      min = data;
    count++;
  }

  ans = max - min;
  printf("%0.1f\n", ans);
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
typedef long long ll;

int main(void){
    ll x, y, z, k, a[1010], b[1010], c[1010];
    cin >> x >> y >> z >> k;
    
    for (int i = 0; i < x; i++) cin >> a[i];
    for (int i = 0; i < y; i++) cin >> b[i];
    for (int i = 0; i < z; i++) cin >> c[i];
    
    vector<ll> list, list2;
    for (int i = 0; i < x; i++) {
        for (int j = 0; j < y; j++) {
            list.push_back(a[i] + b[j]);
        }
    }
    
    sort(list.begin(), list.end(), greater<ll>());
    
    for (int i = 0; i < min(3000ll, x*y); i++) {
        for (int j = 0; j < z; j++) {
            list2.push_back(list[i] + c[j]);
        }
    }
    
    sort(list2.begin(), list2.end(), greater<ll>());
    
    for (int i = 0; i < k; i++) cout << list2[i] << endl;
}


Measured memory_bytes: 43236