akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007

int n, m;

int main(){
ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
        cin >>n >>m;
        if ((n-2)*(n-1)/2 < m) {
                cout << "-1";
        } else {
                vector<pair<int, int> > v;
                v.push_back({1, 2});
                for (int i = 3; i <= n; i++) {
                        v.push_back({2, i});
                }
                int l = (n - 2) * (n - 1) / 2 - m;
                for (int i = 1; i < n; i++) {
                        if (i == 2) continue;
                        int j = i;
                        if (i == 1) j += 2;
                        else j += 1;
                        for (; j <= n; j++) {
                                if (!l) break;
                                v.push_back({i, j});
                                l--;
                        }
                        if (!l) break;
                }
                cout << v.size()<< "\n";
                for (int i = 0; i < v.size(); i++) {
                        cout << v[i].first << " " << v[i].second<< "\n";
                }
        }
return 0;
}


Measured memory_bytes: 384
import math
from decimal import Decimal
hour_len, minute_len, hour, minute = list(map(int, input().split()))

rad_h = math.radians( Decimal( (hour * 60 + minute) / 720 * 360 ) )
rad_m = math.radians( Decimal(minute / 60 * 360) )
cos_hm = math.cos( abs( Decimal(rad_h - rad_m) ) )

a_double = hour_len ** 2 + minute_len ** 2 - (2 * hour_len * minute_len * cos_hm)
ans = math.sqrt(a_double)
print( f"{ans:.20f}" )

Measured memory_bytes: 10140
var obj = init();
Main();
function nextInt(){return myconv(next(),1);}
function nextStrArray(){return myconv(next(),2);}//半角スペース分割
function nextIntArray(){return myconv(next(),4);}//半角スペース + 数値化
function nextCharArray(){return myconv(next(),6);}//1文字分割
function next(){return obj.next();}
function hasNext(){return obj.hasNext();}
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");}
function init(){
  var inputFile = myin();
  var returnObj = {
    "list" : inputFile, "index" : 0, "max" : inputFile.length,
    "hasNext" : function(){return (this.index < this.max);},
    "next" : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(t){console.log(t);}//標準出力
function myerr(t){console.error(t);}//標準エラー出力
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す　1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
  var output = 0;
  var one = nextIntArray();
  var N = one[0];
  var M = one[1];
  if(N >= M / 2){
    output = Math.floor(M / 2);
  }else{
    output = Math.floor(N + ((M - (N * 2)) / 4));
  }
  myout(output);
}

Measured memory_bytes: 7372
#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,k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  sort(a.begin(),a.end());
  int sum=0;
  rep(i,k) sum+=a[i];
  cout << sum << "\n";
  return 0;
}

Measured memory_bytes: 3596
from itertools import accumulate
n = int(input())
alst = list(map(int, input().split()))
acc = [0] + list(accumulate(alst))
dp = [[None] * (n + 1) for _ in range(n + 1)]
for i in range(n):
  dp[i][i] = 0

for length in range(2, n + 1):
  for left in range(n - length + 1):
    right = left + length - 1
    dp[left][right] = min([dp[left][k] + dp[k + 1][right] for k in range(left, right)]) + acc[right + 1] - acc[left]
print(dp[0][n - 1])

Measured memory_bytes: 45584
def resolve():
    n = int(input())
    a = list(map(int, input().split()))
    a1 = []
    for i in range(len(a)):
        a1.append(a[i]-i-1)
    a2 = sorted(a1)
    if len(a2)%2 == 0:
        mda = a2[len(a2)//2]
    else:
        mda = a2[(len(a2)-1)//2]
    ans = 0
    for i in range(len(a2)):
        ans += abs(mda-a2[i])
    print(ans)
resolve()

Measured memory_bytes: 101204
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
//#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 3000050;
const int K = 25;
vector <int> g[N];
int a[N];
void dfs(int v, int p = -1){
    int b = 0;
    for (auto u: g[v]){
        if (u == p) continue;
        dfs(u, v);
        for (int i = b; i < K; i++){
            if ((a[v] & a[u]) & (1 << i)){
                b = i + 1;
            }
        }
        a[v] |= a[u];
        while (a[v] & (1 << b)) b++;
    }
    for (int i = 0; i < b; i++) if (a[v] & (1 << i)) a[v] ^= (1 << i);
    a[v] |= (1 << b);
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
   // freopen("input.txt", "r", stdin);
    int n;
    cin >> n;
    for (int i = 1; i < n; i++){
        int u, v;
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    dfs(1);
    int ans = 0;
    for (int i = 0; i < K; i++) if (a[1] & (1 << i)) ans = i;
    cout << ans;
}


Measured memory_bytes: 81152
#include <bits/stdc++.h>
using namespace std;
const int maxn = 10000, mod = 1'000'000'007;
int mul(long long a, long long b){
	return a * b % mod;
}
int pwr(long long a, long long b){
	int r = 1;
	for(; b; b >>= 1, a = mul(a, a)) if(b&1) r = mul(r, a);
	return r;
}
int fact[maxn], ifact[maxn];
void init(){
	fact[0] = 1;
	for(int i = 1; i < maxn; i++) fact[i] = mul(fact[i - 1], i);
	ifact[maxn - 1] = pwr(fact[maxn - 1], mod - 2);
	for(int i = maxn - 2; i >= 0; i--) ifact[i] = mul(ifact[i + 1], i + 1);
	for(int i = 0; i < maxn; i++) assert(mul(fact[i], ifact[i]) == 1);
}
int ncr(int n, int r){
	if(n < r) return 0;
	return mul(fact[n], mul(ifact[r], ifact[n - r]));
}
int main(){
	int n, a, b, c;
	cin >> n >> a >> b >> c;
	/**
	1 = (1, 2)
	22 = (1, 3) (2, 4)
	2 (3)* 2
	31 = (1, 4) (2, 3)
	333 = (1, 4) (2, 5) (3, 6)
	  **/
	if(b % 2){
		cout << 0 << endl;
		return 0;
	}
	init();
	int ans = 0;
	for(int i31 = 0; i31 <= a; i31++){
		for(int i333 = 0; i31 + 3 * i333 <= c; i333++){
			int i1 = a - i31;
			int miss_3 = c - i31 - 3 * i333;
			int blocks = i1 + i31 + i333 + b / 2;
			int comb = fact[blocks];
			comb = mul(comb, ifact[i1]);
			comb = mul(comb, ifact[i31]);
			comb = mul(comb, ifact[i333]);
			comb = mul(comb, ifact[b / 2]);
			if(miss_3)
				comb = mul(comb, ncr(b / 2 - 1 + miss_3, miss_3));
			ans += comb;
			if(ans >= mod) ans -= mod;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 384
N=gets.to_i
s1=gets.chomp
s2=gets.chomp
MOD=10**9+7

i = 0
ret = 1
prev = nil
while i < N
    if s1[i] == s2[i]
        case prev
        when 1 then ret *= 2
        when 2 then ret *= 1
        else ret *= 3
        end
        prev = 1
        i += 1
    else
        case prev
        when 1 then ret *= 2
        when 2 then ret *= 3
        else ret *= 6
        end
        prev = 2
        i += 2
    end
end

p ret%MOD

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

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


    while (1) {
        c = c - b;
        if (c <= 0) {
            cout << "Yes" << '\n';
            break;
        }
        a = a - d;
        if (a <= 0) {
            cout << "No" << '\n';
            break;
        }
    }


    return 0;
}

Measured memory_bytes: 3636
def get_divisor(n):
    a,b = [],[]
    for i in range(1,int(n**0.5)+1):
        if n%i==0:
            a.append(i)
            b.append(n//i)
    if a[-1]==b[-1]:b.pop()
    a.extend(b[::-1])
    return a

N = int(input())
*A, = map(int,input().split())
D = [0]*(N+1)
ans = []
for i in range(N,0,-1):
    if D[i]%2 != A[i-1]:
        ans.append(i)
        for j in get_divisor(i):
            D[j]+=1
print(len(ans))
print(*ans)

Measured memory_bytes: 74204
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
using namespace std;

int H, W, K;
int room[800][800];

int GetCnt(int x, int y)
{
	int d1 = (x - 1) / K;
	int d2 = (y - 1) / K;
	int d3 = ((W - 1) - (x + 1)) / K;
	int d4 = ((H - 1) - (y + 1)) / K;
	return MIN(d1, MIN(d2, MIN(d3, d4))) + 1;
}

signed main()
{
	int sx, sy;

	cin >> H >> W >> K;
	for (int y = 0; y < H; y++)
	{
		string str;
		cin >> str;
		for (int x = 0; x < W; x++)
		{
			room[x][y] = (str.at(x) == '#') ? 1: 0;
			if (str.at(x) == 'S')
			{
				sx = x;
				sy = y;
			}
		}
	}

	if (sx == 0 || sy == 0 || sx == W - 1 || sy == H - 1)
	{
		cout << 0 << endl;
		return 0;
	}


	int ans = GetCnt(sx, sy);
	int dx[4] = {1, 0, -1, 0};
	int dy[4] = {0, 1, 0, -1};
	bool flg[800][800] = { 0 };
	queue<int> q;
	q.push(sx);
	q.push(sy);
	flg[sx][sy] = true;
	for (int i = 0; i < K; i++)
	{
		int size = q.size();
		if (size == 0) break;
		for (int j = 0; j < size / 2; j++)
		{
			int qx = q.front();
			q.pop();
			int qy = q.front();
			q.pop();
			for (int d = 0; d < 4; d++)
			{
				int x = qx + dx[d];
				int y = qy + dy[d];
				if (flg[x][y]) continue;
				flg[x][y] = true;
				if (room[x][y] == 1)
				{
					continue;
				}
				if (x == 0 || y == 0 || x == W - 1 || y == H - 1)
				{
					cout << 1 << endl;
					return 0;
				}
				ans = MIN(ans, GetCnt(x, y));
				q.push(x);
				q.push(y);
			}
		}
	}
	cout << (ans + 1) << endl;
}

Measured memory_bytes: 5888
#include<bits/stdc++.h>
using namespace std;
const int N=1e4+10;
typedef long long ll;
ll a[N],b[N];
ll dp[10003];

int main()
{
    ll h,n;
    cin>>h>>n;
    for(int i=1;i<=n;++i){
        cin>>a[i]>>b[i];
    }
    memset(dp,0x3f,sizeof(dp));
    dp[0]=0;
    for(int i=1;i<=n;++i){
        for(int j=a[i];j<=10000;++j)
            dp[j]=min(dp[j],dp[j-a[i]]+b[i]);
    }
    ll ans=1e18;
    for(int i=h;i<=10000;++i)
        ans=min(ans,dp[i]);
    cout<<ans;
    return 0;
}
/*

*/

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define INF 999999999
#define rep(i,n) for(int i=0;i<n;i++)
const int MOD = 1000000007;
ll cnt =0,ans=0;

int main(){
    int n;  cin >> n;
    vector<int>a(n+1);
    for(int i=1;i<=n;i++){
        cin >> a.at(i);
    }
    sort(a.begin(),a.end());

    for(int i=1;i<n;i++){
        ans+=a.at(n-i/2);
    }

    cout << ans << endl;


}

Measured memory_bytes: 4056
# -*- coding: utf-8 -*-
from itertools import product, accumulate
from math import gcd
from bisect import bisect
import sys
from sys import setrecursionlimit
setrecursionlimit(10**9)
input = sys.stdin.readline
def inpl(): return list(map(int, input().split()))

def primes(N):
    sieve = [1]*(N+1)
    sieve[:2] = [0, 0]
    P = []
    for i in range(2, N+1):
        if sieve[i]:
            P.append(i)
            for j in range(2*i, N+1, i):
                sieve[j] = 0
    return P

C = [1]*(10**5+1)
C[0] = 0
C[1] = 0
P = primes(10**5)

for p in P:
    C[p] = 0

for p in P:
    if p**3 > 100000:
        break
    C[p**3] = 0

for i in range(len(P)):
    for j in range(i, bisect(P, 10**5//P[i])):
        C[P[i] * P[j]] = 0

S = list(accumulate(C))
for _ in range(int(input())):
    print(S[int(input())])


Measured memory_bytes: 12068
from math import sqrt


def f(a, b):
    return max(len(str(a)), len(str(b)))


def main():
    n = int(input())
    min_f = 10
    for a in range(int(sqrt(n))+1, 0, -1):
        if n % a == 0:
            b = n // a
            min_f = min(min_f, f(a, b))
    print(min_f)


if __name__ == "__main__":
    main()



Measured memory_bytes: 39024
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}


int main() {
    int N;
    cin >> N;
    vector<bool> v(N+1,true);
    REP(i,N) {
        int id = 1+i;
        int a;
        cin >> a;
        v[i] = id != a;
    }

    int cnt = 0;
    REP(i,N) {
        if (!v[i]) v[i] = true,v[i+1]= true,cnt+=1;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
a,b,c,x,y = (int(_) for _ in input().split())

cost = min(x,y) * min(a+b, 2*c)
if x>y:
    cost += (x-y)*min(a, 2*c)
else:
    cost += (y-x)*min(b, 2*c)

print(cost)


Measured memory_bytes: 3060
package main

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

func main() {
	scanner := makeWordScanner()
	a := eGetInt(scanner)
	b := eGetInt(scanner)
	c := eGetInt(scanner)
	if a == b && b == c {
		fmt.Println("No")
	} else if a == b || b == c || c == a {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

////////////////////////////////////////////////////////////////////////////////
// ライブラリ
////////////////////////////////////////////////////////////////////////////////
func makeScanner(maxByte int) *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]uint8, 0, 8192), maxByte)
	return scanner
}
func makeCharScanner() *bufio.Scanner {
	scanner := makeScanner(8192)
	scanner.Split(bufio.ScanRunes)
	return scanner
}
func makeWordScanner() *bufio.Scanner {
	scanner := makeScanner(8192)
	scanner.Split(bufio.ScanWords)
	return scanner
}
func eGetLine(r *bufio.Scanner) string {
	if r.Scan() {
		return r.Text()
	}
	err := r.Err()
	if err != nil {
		log.Fatal(err)
	}
	// EOF
	return ""
}
func eGetInt(r *bufio.Scanner) int {
	line := eGetLine(r)
	return eAtoi(line)
}
func eGetInt64(r *bufio.Scanner) int64 {
	line := eGetLine(r)
	return eAtoInt64(line)
}
func eGetFields(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Fields(line)
}
func eGetInts(r *bufio.Scanner) []int {
	fields := eGetFields(r)
	ints := make([]int, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoi(fields[i])
	}
	return ints
}
func eGetInt64s(r *bufio.Scanner) []int64 {
	fields := eGetFields(r)
	ints := make([]int64, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoInt64(fields[i])
	}
	return ints
}
func eGetChars(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Split(line, "")
}
func eAtoi(s string) int {
	n, err := strconv.Atoi(s)
	if err != nil {
		log.Fatal(err)
	}
	return n
}
func eAtoInt64(s string) int64 {
	n, err := strconv.ParseInt(s, 10, 64)
	if err != nil {
		log.Fatal(err)
	}
	return n
}
func pow(a, n int) int {
	return int(math.Pow(float64(a), float64(n)))
}
func countBitOfOn(i, numbits int) int {
	count := 0
	var bit uint64
	for bit = 0; bit < uint64(numbits); bit++ {
		t := 1 << bit
		if i&t > 0 {
			count++
		}
	}
	return count
}


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

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

using namespace std;

template<class T> struct interval{
	T l,r;
	interval():l(T{}),r(T{}){}
	interval(const T& l,const T& r):l(l),r(r){}
};

template<class T>
int interval_scheduling(vector<interval<T>> I){
	sort(I.begin(),I.end(),[](const interval<T>& a,const interval<T>& b){
		return make_pair(a.r,a.l)<make_pair(b.r,b.l);
	});

	int res=0;
	T now=I[0].l;
	for(auto J:I) if(now<=J.l) now=J.r, res++;
	return res;
}

int main(){
	int n; scanf("%d",&n);
	vector<interval<int>> I(n);
	rep(i,n){
		int x,l; scanf("%d%d",&x,&l);
		I[i]={x-l,x+l};
	}

	printf("%d\n",interval_scheduling(I));

	return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<functional>
#include<string>
#include<cstring>
#include<time.h>
#include<array>
#include<iomanip>
#include<list>
#include<set>
#include<map>
#include<random>
#include<unordered_map>
#include<unordered_set>
#include<bitset>
#include <queue>
#include<boost/multiprecision/cpp_int.hpp>


using namespace std;
using namespace boost::multiprecision;

using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldb = long double;


//BDD,ZDD,kdtree, bdtree,bicalc, bolonoy, doloney, tree, chinesemod,segmenttree,daikusutora, saidairyuu, 2bugurahu, heirokenshutu, topologicalsort, kyourenketuseibun

#define REP(i,a,b) for(ll i = a; i < b; ++i)
#define PRI(s) cout << s << endl
#define PRIF(v, n) printf("%."#n"f\n", v)
#define PRIY PRI("Yes")
#define PRIN PRI("No")
template<typename A, typename B>
void mins(A & a, const B & b) { a = min(a, (A)b); };
template<typename A, typename B>
void maxs(A & a, const B & b) { a = max(a, (A)b); };

int ctoi(char c) {
	return c - '0';
}
ll modpow(ll r, ll n, ll mod) {
	ll ans = 1;
	ll tmp = r;
	while (n > 0) {
		if ((n & 1) > 0)ans = ans * tmp % mod;
		tmp = tmp * tmp % mod;
		n >>= 1;
	}
	return ans;
}
int main() {
	string s;
	cin >> s;
	ll mod = 1e9 + 7;
	vector<vector<ll>> dp(s.size() + 1);
	for(auto & v : dp)v.resize(13, 0);
	if (s.back() == '?')REP(k, 0, 10)dp[1][k] = 1;
	else dp[1][ctoi(s.back())] = 1;
	REP(i, 2, s.size()+1) {
		char c = s[s.size() - i];
		REP(j, 0, 13) {
			if (c == '?') {
				REP(k, 0, 10) dp[i][j] += dp[i - 1][((j - k * modpow(10, i - 1, 13)) % 13 + 13) % 13];
			}
			else dp[i][j] += dp[i - 1][((j - ctoi(c) * modpow(10, i - 1, 13)) % 13 + 13) % 13];
			dp[i][j] %= mod;
		}
	}
	PRI(dp[s.size()][5]);
	return 0;
}

Measured memory_bytes: 16704
#include <iostream>
using namespace std;
int main()
{
	int A,B;
	cin >> A >> B;
	if (A >= 13)
	{
		cout << B << endl;
	}
	else if (A >= 6)
	{
		cout << B/2 << endl;
	}
	else
	{
		cout << "0" << endl;
	}
	return 0;
}

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

int main(void){
  int N,cnt=0;
  cin >> N;
  for(int i = 1;i <= N;i++){
    if(i>=0 && i <=9){
      cnt++;
    }
    if(i>=100 && i <=999){
      cnt++;
    }
    if(i>=10000 && i <=99999){
      cnt++;
    }
  }

  cout << cnt << endl;
  return 0;
}



Measured memory_bytes: 256
#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()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
	string s;
	cin >> s;
	string is;
	rep(i,26) {
		is += 'z'- i;
	}
	if (is == s) {
		cout << -1 << endl;
		return;
	}
	vector<int> cnt(26);
	rep(i,26) {
		cnt[s[i] - 'a']++;
	}
	if (s.size() != 26) {
		char c;
		rep(i,26) {
			if (cnt[i] == 0) {
				c = 'a' + i;
				break;
			}
		}
		cout << s + c << endl;
	} else {
		string f;
		string t;
		for(int i = s.size() - 1; i >= 1; i--) {
			if (s[i-1] > s[i]) continue;
			f = s.substr(0, i);
			t = s.substr(i);
			break;
		}
		vector<int> cnt2(26);
		rep(i,t.size()) {
			cnt2[t[i] - 'a']++;
		}
		int p = f[f.size()-1] - 'a';
		char c;
		for (int i = p; i < 26; i++) {
			if (cnt2[i]) {
				c = 'a' + i;
				break;
			}
		}
		string ans = "";
		rep(i,f.size()) {
			if (i == f.size() - 1) ans = ans + c;
			else ans = ans + f[i];
		}
		cout << ans << endl;
	}

}

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

Measured memory_bytes: 3640
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define NUM 410


struct Edge{
	Edge(int arg_to,int arg_capacity,int arg_cost,int arg_rev_index){
		to = arg_to;
		capacity = arg_capacity;
		cost = arg_cost;
		rev_index = arg_rev_index;
	}

	int to,capacity,cost,rev_index;
};

int V;
vector<Edge> G[NUM];
int dist[NUM];
int pre_node[NUM],pre_edge[NUM];


void add_edge(int from,int to,int capacity,int cost){
	G[from].push_back(Edge(to,capacity,cost,G[to].size()));
	G[to].push_back(Edge(from,0,-cost,G[from].size()-1));
}

int min_cost_flow(int source,int sink,int flow){
	int ret = 0;
	while(flow > 0){

		for(int i = 0; i < V; i++)dist[i] = BIG_NUM;
		dist[source] = 0;
		bool update = true;
		while(update){
			update = false;
			for(int node_id = 0; node_id < V; node_id++){
				if(dist[node_id] == BIG_NUM)continue;
				for(int i = 0; i < G[node_id].size(); i++){
					Edge &e = G[node_id][i];
					if(e.capacity > 0 && dist[e.to] > dist[node_id]+e.cost){
						dist[e.to] = dist[node_id]+e.cost;
						pre_node[e.to] = node_id;
						pre_edge[e.to] = i;
						update = true;
					}
				}
			}
		}

		if(dist[sink] == BIG_NUM){
			return -1;
		}

		int tmp_flow = flow;
		for(int node_id = sink; node_id != source; node_id = pre_node[node_id]){
			tmp_flow = min(tmp_flow,G[pre_node[node_id]][pre_edge[node_id]].capacity);
		}
		flow -= tmp_flow;
		ret += tmp_flow*dist[sink];
		for(int node_id = sink; node_id != source; node_id = pre_node[node_id]){
			Edge &e = G[pre_node[node_id]][pre_edge[node_id]];
			e.capacity -= tmp_flow;
			G[node_id][e.rev_index].capacity += tmp_flow;
		}
	}
	return ret;
}

int main(){

	int A,B,K;
	scanf("%d %d %d",&A,&B,&K);

	char table_1[A][B+1],table_2[B][A+1];
	int cost[A][B];

	for(int i = 0; i < A; i++){
		scanf("%s",table_1[i]);
	}

	for(int i = 0; i < B; i++){
		scanf("%s",table_2[i]);
	}

	for(int i = 0; i < A; i++){
		for(int k = 0; k < B; k++){
			cost[i][k] = (table_1[i][k]-'0')+(table_2[k][i]-'0');
		}
	}

	int source = 0,sink = 1,index = 2;
	int index_A[A],index_B[B];

	for(int i = 0; i < A; i++){
		index_A[i] = index++;
		add_edge(source,index_A[i],1,0);
	}

	for(int i = 0; i < B; i++){
		index_B[i] = index++;
		add_edge(index_B[i],sink,1,0);
	}

	for(int i = 0; i < A; i++){
		for(int k = 0; k < B; k++){
			add_edge(index_A[i],index_B[k],1,cost[i][k]);
		}
	}

	int ans = 0,add_cost;
	int sum_cost = 0;

	V = index;

	while(sum_cost <= K){
		add_cost = min_cost_flow(source,sink,1);

		if(add_cost < 0)break;

		if(sum_cost+add_cost <= K){
			sum_cost += add_cost;
			ans++;
			if(ans == min(A,B))break;
		}else{
			break;
		}
	}

	printf("%d\n",ans);

	return 0;
}




Measured memory_bytes: 4932
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n = int(input())
    A = list(map(int,input().split()))
    A.sort()
    max_A = max(A)
    dp = [True] * (max_A+1) # iより小さいiの約数がAに存在しない
    multi = [0] * (max_A+1) #重複個数
    for a in A:
        multi[a] += 1
        if multi[a] > 1: continue
        x = a
        while x + a <= max_A:
            x += a
            dp[x] = False
    ans = 0
    for a in A:
        if dp[a] and multi[a]==1:
            ans += 1
    print(ans)

if __name__=='__main__':
    main()

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

int main(){

    int N;
    cin >> N;
    map<string,int> mp;
    string S;
    long long ans = 0;
    for(int i = 0; i < N;i++){
        cin >> S;
        sort(S.begin(),S.end());
        mp[S]++;
        if(mp[S]>0)ans += mp[S] - 1;
    }
    

    cout << ans << endl;
    
    
}


Measured memory_bytes: 11136
#include <iostream>
#include <array>
#include <vector>
#include <iomanip>
#include <string>
#include <cmath>
#include <array>
#include <algorithm>
#include <queue>
#include <map>
using namespace std;

typedef  pair<int,int> P;
typedef long long LL;

const LL  INF=1<<31;



int main(){
     int n,k;
     cin>>n>>k;
     int h[100000];
     for(int i=0;i<n;++i){
          cin>>h[i];
     }
     LL dp[100001];

      for(int i=0;i<n;++i){
           dp[i]=INF;
      }
            dp[0]=0;
            dp[1]=abs(h[0]-h[1]);



     for(int i=2;i<n;++i){
          dp[i]=dp[i-1]+abs(h[i-1]-h[i]);
          for(int j=2;j<=k;++j){

               if(j<=i)dp[i]=min(dp[i],dp[i-j]+abs(h[i-j]-h[i]));
          }
     }     

     cout<<dp[n-1]<<endl;


}

Measured memory_bytes: 1408
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

typedef long long ll;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define INF 999999999

int main() {
	int n;
	cin >> n;
	vector<int>a(n);
	vector<int>b(n);
	vector<int>c(n,0);
	REP(i, n) {
		cin >> a[i];
		if (i) {
			if (a[i - 1] < a[i])c[i] = -1;
			else c[i] = a[i];
		}
		else c[i] = -1;
	}
	REP(i, n)cin >> b[i];
	reverse(b.begin(), b.end());
	REP(i, n) {
		cin >> b[i];
		if (c[n-1-i]==-1 && a[n-1-i] > b[i]) {
			cout << "0" << endl;
			return 0;
		}
		if (c[n-1-i] == -1)continue;
		if (i) {
			if (b[i - 1] < b[i]) {
				c[n-1-i] = -1;
			}
			c[n-1-i] = min(c[n-1-i], b[i]);
		}
		else {
			c[n-1-i] = -1;
			if (a[n-1-i] < b[i]) {
				cout << "0" << endl;
				return 0;
			}
		}
	}
	ll ans = 1;
	REP(i, n) {
		if (c[i] == -1)continue;
		ans *= c[i];
		ans %= 1000000007;
	}
	cout << ans << endl;
}




Measured memory_bytes: 1408
/*
Author: Racer5x
 ***************************************   UNAUTHORISED COPYING OF CODE PROHIBITED   **********************************
*/
 
// #pragma GCC optimize("O3")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#include<bits/stdc++.h>
#define int         long long
#define double      long double
#define pb          emplace_back
#define pf          emplace_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define x           first
#define y           second
#define endl        '\n'
#define hell        998244353 
#define PI          3.141592653589
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MAX         2000000000000000000
#define M           1000000007
using namespace std;
 
signed main()
{
    tezz
    
    string s;
    cin>>s;

    int curr = 0;
    int n = s.length();
    for(int i=0;i<n/2;i++){
    	if(s[i] != s[n-i-1]) curr++;
    }

    cout<<curr;
} 

Measured memory_bytes: 256
import java.util.Scanner;

class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int N = sc.nextInt(),i, a[] = new int[N],b[]=new int[N],c[]=new int[N];
		for(i=0;i<N;i++) {
			a[i]=sc.nextInt();
			b[i]=sc.nextInt();
			c[i]=sc.nextInt();
		}
		int dp[][]=new int[N+1][3];//dp[日にち][活動]0:a, 1:b, 2:c
		for(i=0;i<3;i++) dp[0][i]=0;
		for (int date = 0; date < N; date++) {
			dp[date + 1][2] = Math.max(dp[date][0] + a[date], dp[date][1] + b[date]);
			dp[date + 1][1] = Math.max(dp[date][0] + a[date], dp[date][2] + c[date]);
			dp[date + 1][0] = Math.max(dp[date][2] + c[date], dp[date][1] + b[date]);
		}
		System.out.println(Math.max(Math.max(dp[N][0], dp[N][1]),dp[N][2]));
	}
}

Measured memory_bytes: 61044
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
typedef vector< ii > vii;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef	vector<pair<int,pair<int,int > > > viii;
typedef long long int lli;

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(i,a,b) for(int i=b-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define sz(a) (int)(a.size())

#define si(n) scanf("%d",&n)
#define dout(n) printf("%d\n",n)
#define slli(n) scanf("%llid",&n)
#define lldout(n) printf("%llid\n",n)
const int N = (int)1e5 + 10;
map<int,int> ph;
int main(){
 	int n;
 	int x;
 	cin>>n>>x;
 	int f;
 	vector<int> v1;
 	v1.pb(x);
 	rep(i,0,n){cin>>f;v1.pb(f);}
 	sort(v1.begin(),v1.end());
 	int ans=v1[1]-v1[0];
 	rep(i,2,sz(v1)){
 		ans=__gcd(ans,v1[i]-v1[i-1]);
 		//cout<<ans<<endl;
 	}
 	cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 892
package main

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

type node struct {
	prev *node
	next *node
	value int
}

type doublyLinkedList struct {
	first *node
	last *node
	size int
}

func (l doublyLinkedList) String() string {
	elems := make([]string, l.size)
	node := l.first
	for i := 0; i < l.size; i++ {
		elems[i] = strconv.Itoa(node.value)
		node = node.next
	}
	return strings.Join(elems, " ")
}

func newDoublyLinkedList() *doublyLinkedList {
	return &doublyLinkedList{
		first: nil,
		last: nil,
		size: 0,
	}
}

func (l *doublyLinkedList) insert(value int) {
	node := &node{prev: nil, next: nil, value: value}
	if l.first == nil {
		l.first = node
		l.last = node // last should be nil if first is nil
	} else {
		node.next = l.first
		l.first.prev = node
		l.first = node
	}
	l.size++
}

func (l *doublyLinkedList) delete(value int) {
	if l.first == nil || l.last == nil {
		return
	}
	if l.first.value == value {
		l.deleteFirst()
	} else {
		node := l.first
		for node != nil && node.value != value {
			node = node.next
		}
		if node != nil {
			if node == l.last {
				l.deleteLast()
			} else {
				node.prev.next = node.next
				node.next.prev = node.prev
				l.size--
			}
		}
	}
}

func (l *doublyLinkedList) deleteFirst() {
	if l.first != nil {
		if l.last == l.first {
			l.first = nil
			l.last = nil
		} else {
			l.first = l.first.next
			l.first.prev = nil
		}
		l.size--
	}
}

func (l *doublyLinkedList) deleteLast() {
	if l.last != nil {
		if l.first == l.last {
			l.first = nil
			l.last = nil
		} else {
			l.last = l.last.prev
			l.last.next = nil
		}
		l.size--
	}
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}

	l := newDoublyLinkedList()

	for i := 0; i < n; i++ {
		command := nextText(sc)
		switch command {
		case "insert":
			v, err := nextInt(sc)
			if err != nil {
				panic(err)
			}
			l.insert(v)
		case "delete":
			v, err := nextInt(sc)
			if err != nil {
				panic(err)
			}
			l.delete(v)
		case "deleteFirst":
			l.deleteFirst()
		case "deleteLast":
			l.deleteLast()
		default:
			panic(fmt.Errorf("invalid command: %s\n", command))
		}
	}

	fmt.Println(l)
}

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

func nextInt(sc *bufio.Scanner) (int, error) {
	return strconv.Atoi(nextText(sc))
}


Measured memory_bytes: 47580
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#define ll long long
#define rep(i, a, b) for(int i = a; i < b; i++)
using namespace std;

int main() {
  int n;
  cin >> n;
  cout << n / 3 << "\n";
}


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

using namespace std;

int main() {
    long long a, b, n;
    float sq;
    cin >> n;
    a = sqrt(n);
    for (; a > 0; --a) {
        b = n / a;
        if (n == a * b) {
            break;
        }
    }
    cout << a + b - 2<< endl;
    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    int n;
    while(cin>>n,n){
        int hoge; cin>>hoge;
        int ujimatu=0;
        rep(i,hoge){
            int a,b; cin>>a>>b;
            ujimatu+=abs(a-b);
        }
        if(n<=ujimatu)  cout<<"OK"<<endl;
        else cout<<(n-ujimatu)<<endl;
    }
}

Measured memory_bytes: 3088
N,M=map(int,input().split())
st=[list(map(int,input().split())) for i in range(N)]
ch=[list(map(int,input().split())) for i in range(M)]
for s in st:
    Min=1000000000
    Mindex=-1
    for i in range(M):
        if abs(ch[i][0]-s[0])+abs(ch[i][1]-s[1])<Min:
            Min=abs(ch[i][0]-s[0])+abs(ch[i][1]-s[1])
            Mindex=i+1
    print(Mindex)


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

int gcd(int x, int y) {
    if(y == 0) return x;
    else return gcd(y, x % y);
}

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

    vector<int> l(N), r(N);
    l[0] = A[0];
    for(int i=1; i<N; ++i) l[i] = gcd(l[i - 1], A[i]);
    r[N - 1] = A[N  - 1];
    for(int i=N-2; i>=0; --i) r[i] = gcd(r[i + 1], A[i]);

    int res = max(l[N - 2], r[1]);
    for(int i=1; i<N-1; ++i) res = max(res, gcd(l[i - 1], r[i + 1]));
    cout << res << endl;
}

Measured memory_bytes: 1408
#include<iostream>
#include<stdio.h>

using namespace std;
struct node{
    int parent=-1;
    int lchild=-1;
    int rchild=-1;
    int d=0;
    int sibling=-1;
};

int getDep(node A[],int node){
    int ans=0;
    while(A[node].parent!=-1){
        ans++;
        node=A[node].parent;
    }
    return ans;
}
int getHeight(node A[],int n){
    if(n==-1) return 0;
    if(A[n].lchild==-1 && A[n].rchild==-1){
        return 0;
    }
    return 1+max(getHeight(A,A[n].lchild),getHeight(A,A[n].rchild));
}

void show(node A[],int n){
    int i;
    for(i=0;i<n;i++){
        printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",
               i,A[i].parent,A[i].sibling,A[i].d,getDep(A,i),getHeight(A,i));
        if(A[i].parent==-1){
            cout<<"root"<<endl;
        }else if(A[i].d==0){
            cout<<"leaf"<<endl;
        }else{
            cout<<"internal node"<<endl;
        }
    }
}

int main(){
    int n,k;
    node A[26];
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>k;
        cin>>A[k].lchild>>A[k].rchild;
        A[A[k].lchild].parent=k;  A[A[k].lchild].sibling=A[k].rchild;
        A[A[k].rchild].parent=k;  A[A[k].rchild].sibling=A[k].lchild;
        A[k].d=(A[k].lchild!=-1)+(A[k].rchild!=-1);
    }

    show(A,n);
    return 0;
}



Measured memory_bytes: 3248
import sys
input = sys.stdin.readline


def main():
    N = int(input())
    d = list(map(int, input().split()))
    D = []

    for (k, v) in enumerate(d):
        D.append((v, k))

    D = sorted(D)
    a = D[len(D)//2-1]
    b = D[len(D)//2]
    diff = b[0] - a[0]
    # print(a, b)
    print(diff)


if __name__ == '__main__':
    main()


Measured memory_bytes: 59100
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <cassert>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define LLINF 1000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
int N;
ll w[4005];
ll dp[4005][4005];
ll minarg[4005][4005];
int main(){
	scanf("%d",&N);
	for(int i=1;i<=N;i++)scanf("%lld",&w[i]);
	for(int i=1;i<N;i++)w[i+1]+=w[i];
	for(int i=1;i<=N;i++){
		minarg[i][i]=i;
		for(int j=i+1;j<=N;j++){
			dp[i][j]=LLINF;
		}
	}
	for(int i=1;i<N;i++){
		for(int l=1,r=i+1;r<=N;l++,r++){
			for(int j=minarg[l][r-1];j<=minarg[l+1][r];j++){
				ll res = dp[l][j]+dp[j+1][r]+w[r]-w[l-1];
				if(dp[l][r]>res){
					minarg[l][r]=j;
					dp[l][r]=res;
				}
			}
		}
	}
	printf("%lld\n",dp[1][N]);
	return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,K;
int R,S,P;
string T;
string ST[101010];
int dp[101010][3];
ll hoge(string T) {
	int N=T.size();
	int i,x,y;
	FOR(i,3) FOR(x,N+1) dp[x][i]=0;
	FOR(i,N) {
		FOR(x,3) FOR(y,3) if(x!=y) {
			int cur=dp[i][x];
			if(y==0 && T[i]=='r') cur+=P;
			if(y==1 && T[i]=='p') cur+=S;
			if(y==2 && T[i]=='s') cur+=R;
			dp[i+1][y]=max(dp[i+1][y],cur);
		}
	}
	return max({dp[N][0],dp[N][1],dp[N][2]});
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>K;
	cin>>R>>S>>P;
	cin>>T;
	FOR(i,N) ST[i%K]+=T[i];
	ll ret=0;
	FOR(i,K) ret+=hoge(ST[i]);
	cout<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 5328
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;

int main(){
    ll N, K;
    cin >> N >> K;
    vector<ll> V(200000);

    for(int i=0; i<N; i++) {
        ll a, b;
        cin >> a >> b;
        V[a] += b;
    }

    ll total = 0;
    for(int i=0; i<V.size(); i++) {
        total += V[i];
        if(total >= K) {
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 4800
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <utility>
#include <algorithm>
#include <set>
#include <string>
#include <queue>
#include <functional>
using namespace std;
signed main(void)
{
	int x;
	cin >> x;
	int ans = 0; int sum = 0;
	while (sum < x) {
		sum += ans; ans += 1;
	}
	cout << ans-1;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	ll n, k;
	cin >> n >> k;
	vector<pair<ll, ll>> vp;
	for( int i = 0; i < n; ++i ){
		ll x, y;
		cin >> x >> y;
		vp.emplace_back( x, y );
	}
	sort( vp.begin(), vp.end() );
	ll sum = 0;
	for( int i = 0; i < n; ++i ){
		sum += vp[i].second;
		if( sum >= k ){
			cout << vp[i].first << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 2420
#include <iostream>
#include <vector>
#include <unordered_map>
#include <deque>
#include <list>
#include <set>
#include <random>
#include <deque>

using namespace std;
using ll = long long;
const int BIG = 100000007;

int search(vector<vector<char>> grid,ll nx,ll ny,ll w,ll h,ll k){
    int cnt = 0;
    if(nx == w && ny == h){
        int bcnt = 0;
        string s = "\n";
        for(ll y = 0;y < h;++y){
            for(ll x = 0;x < w;++x){
                if(grid[x][y] == '#')++bcnt;
                s += grid[x][y];
            }
            s += '\n';
        }
        //cout << s << endl;
        if(bcnt == k){
            return 1;
        }
    }
    else if(nx < w && ny < h){
        vector<vector<char>> ngrid1 = grid;
        for(ll y = 0;y < h;++y){
            ngrid1[nx][y] = '!';
        }

        vector<vector<char>> ngrid2 = grid;
        for(ll x = 0;x < w;++x){
            ngrid2[x][ny] = '!';
        }

        vector<vector<char>> ngrid3 = ngrid1;
        for(ll x = 0;x < w;++x){
            ngrid3[x][ny] = '!';
        }


        cnt += search(grid,nx + 1,ny + 1,w,h,k);
        cnt += search(ngrid1,nx + 1,ny + 1,w,h,k);
        cnt += search(ngrid2,nx + 1,ny + 1,w,h,k);
        cnt += search(ngrid3,nx + 1,ny + 1,w,h,k);
    }
    else if(nx < w){
        vector<vector<char>> ngrid1 = grid;
        for(ll y = 0;y < h;++y){
            ngrid1[nx][y] = '!';
        }
        cnt += search(grid,nx + 1,ny,w,h,k);
        cnt += search(ngrid1,nx + 1,ny,w,h,k);
    }
    else{
        vector<vector<char>> ngrid2 = grid;
        for(ll x = 0;x < w;++x){
            ngrid2[x][ny] = '!';
        }

        cnt += search(grid,nx,ny + 1,w,h,k);
        cnt += search(ngrid2,nx,ny + 1,w,h,k);
    }
    return cnt;
}


int main() {
    ll h,w;
    cin >> h >> w;
    ll k;
    cin >> k;
    vector<vector<char>> grid(w,vector<char>(h,'.'));
    for(ll y = 0;y < h;++y){
        string s;
        cin >> s;
        for(ll x = 0;x < w;++x){
            grid[x][y] = s[x];
        }
    }
    cout << search(grid,0,0,w,h,k) << endl;
}




Measured memory_bytes: 3184
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define P pair<int,int>
#define PI 3.141592653589793
const int INF = 1001001001;
const ll MX = 1e18;
const int mod = 1000000007;
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

int main() {
	string s;
	cin >> s;
	if (s[s.size() - 1] == 's') {
		cout << s + "es" << endl;
	}
	else {
		cout << s + 's' << endl;
	}
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long int llint;
typedef unsigned long long int ullint;
std::string YesNo[] = {"No","Yes"};
#define loop(i,N) for(int i=0; i<(N); i++)
template<typename T>
auto sort_all(T& v) { return std::sort(v.begin(),v.end()); }
template<typename T>
auto sum_all(const T& v) { auto z = v[0]; z = 0;
    return std::accumulate(v.begin(),v.end(),z); }
template<typename T>
auto input(int N) {
    std::vector<T> v(N);
    loop(i,N) std::cin >> v[i];
    return std::move(v);
}

typedef llint Int;

Int gcd(Int a, Int b)
{
    while (b > 0) {
        Int tmp = b;
        b = a % b;
        a = tmp;
    }
    return a;
}

int main(void)
{
    Int N, M;
    cin >> N >> M;
    auto a = input<Int>(N);
    Int L = 1;
    loop(i, N) {
        Int c = a[i]/2;
        Int g = gcd(L,c);
        L *= (c/g);
    }
    loop(i, N) {
        Int c = a[i]/2;
        if ((L/c) % 2 == 0) {
            cout << 0 << endl;
            return 0;
        }
    }
    Int z = M / L;
    cout << (z+1)/2 << endl;

    return 0;
}

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

int main() {
  int n, mod;
  string S;
  string ABC = "ABC";
  mod = 1e9+7;
  
  cin >> S;
  n = S.size();
  
  long long DP[n+1][4] = {};
  
  for(int i=n; i>=0; i--){
    for(int k=3; k>=0; k--) {
      
      if(i==n){
        if(k==3) {
          DP[i][k] = 1;
        } else {
          DP[i][k] = 0;
        }
        break;
      }
      
      if(k==3) {
        if(S[i] == '?') {
          DP[i][k] = 3*DP[i+1][k];
        } else {
          DP[i][k] = DP[i+1][k];
        }
      } else {
        if(S[i] == '?') {
          DP[i][k] = 3*DP[i+1][k] + DP[i+1][k+1];
        } else if(S[i] == ABC[k]) {
          DP[i][k] = DP[i+1][k] + DP[i+1][k+1];
        } else if(S[i] != ABC[k]) {
          DP[i][k] = DP[i+1][k];
        }
      }
      DP[i][k] %= mod;
    }
  }
  cout << DP[0][0] << endl;
  return 0;
}

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

using namespace std;

int n;

string a, b;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> a >> b;
    for(int i = 0; i < n; i++)
        cout << a[i] << b[i];
    cout << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <string.h>
#define rep(i,a,n) for(int i=a;i<n;i++)

int main(){
	int n;
	double x[101]={0},y[101]={0},p[10]={0};
	scanf("%d",&n);
	rep(i,0,n) scanf("%lf",&x[i]);
	rep(i,0,n) scanf("%lf",&y[i]);
	rep(i,0,n){
		p[1]+=fabs(x[i]-y[i]);
		p[2]+=pow(fabs(x[i]-y[i]),2.0);
		p[3]+=pow(fabs(x[i]-y[i]),3.0);
		if(p[4]<fabs(x[i]-y[i])) p[4]=fabs(x[i]-y[i]);
	}
	p[2]=pow(p[2],0.5);
	p[3]=pow(p[3],1.0/3.0);
	rep(i,1,5) printf("%.10lf\n",p[i]);
	return 0;
}

Measured memory_bytes: 1148
L, R = map(int, input().split())

if R - L >= 2019:
    print(0)
else:
    ans = 10**10
    for i in range(L, R + 1):
        for j in range(i + 1, R + 1):
            ans = min(ans, (i * j) % 2019)
    
    print(ans)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};

ll x=1000000000001;
int main() {

	ll n;
	cin>>n;

	for(int i=1; i<10000001; i++){
		if(n%i==0)x=min(x,n/i+i-2);
	}
	cout<<x<<endl;

	return 0;

}


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<utility>
#include<queue>
#include<cmath>
#include<cstdio>
using namespace std;
#define REP(i, a,b) for(i=a;i<b;i++) 
#define REP1(i,b,a) for(i=b-1;i>=a;i--)
#define output(x) cout<<x<<endl;
#define pb(x) push_back(x);
typedef long long int ll;
typedef pair<ll, ll > P;
const int MOD = 1000000007;


int main() {
	ll i, j, k, l, m, n, sum, flag, cc, M, X, H, W, N;
	cc = 0;
	flag = 0;
	ll A[5] = {};
	cin >> N;
	REP(i, 0, 5) {
		cin >> A[i];
	}
	sort(A, A + 5);
	if (A[0] != 1) {
		output(5 + (N / A[0]));
	}
	else {
		output(5 + N - 1);
	}
	return 0;
}





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

int main(){
	int n;
	double x,sum;
	char u[3];

	scanf("%d",&n);
	sum=0.0;
	for(int i=1;i<=n;i++){
		scanf("%lf %s",&x,u);
		if(strcmp(u,"JPY")==0) sum=sum+x;
		if(strcmp(u,"BTC")==0) sum=sum+x*380000.0;
	}
	printf("%lf",sum);
	return 0;
}


Measured memory_bytes: 128