akhauriyash/Code-Regression huggingface dataset:
#include <iostream>                                                     
#include <vector>                                                       
using namespace std;                                                    
                                                                        
int main(void) {                                                        
  int x;                                                                
  vector<int> Case;                                                     
  while (true) {                                                        
    cin >> x;                                                           
    if (x==0) {                                                         
      break;                                                            
    }                                                                   
    Case.push_back(x);                                                  
  }                                                                     
  for (int i=0; i<Case.size(); i++) {                                   
    cout << "Case" << " " << i+1 << ": " << Case[i] << endl;            
  }                                                                     
  return 0;                                                             
}                                                                       
                                                                        
                                    

Measured memory_bytes: 3180
import java.util.*;

public class Main{
    
    public static void main(String[] args){
        
        int n,k;
        
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        k = n%10;
        
        if(k == 2 || k == 4 || k == 5 || k == 7 || k == 9){
            System.out.println("hon");
        }
        else if(k == 3){
            System.out.println("bon");
        }
        else{
            System.out.println("pon");
        }
        
    }
    
}

Measured memory_bytes: 35780
import java.math.*

fun main(args: Array<String>) {
    val (n, k) = readInputLine().split(" ").map{it.toInt()}
    
    val sushi = mutableListOf<Pair<Long, Long>>()
    
    for (i in 1..n) {
        val (t, d) = readInputLine().split(" ").map{it.toLong()}
        sushi.add(Pair(t, d))
    }
    
    sushi.sortByDescending{it.second}
    
    val f = LongArray(n + 1, {Long.MIN_VALUE})
    
    var score = 0L
    val kinds = mutableSetOf<Long>()
    val removable = mutableListOf<Long>()
    
    for (i in 1..k) {
        val (t, d) = sushi.first()
        sushi.removeAt(0)
        score += d
        if (kinds.contains(t)) {
            removable.add(0, d)
        } else {
            kinds.add(t)
        }
    }

    f[kinds.size] = score
    
    while (removable.isNotEmpty() && sushi.size != 0) {
        val (t, d) = sushi.first()
        sushi.removeAt(0)
        if (kinds.contains(t)) {
            continue
        }
        kinds.add(t)
        f[kinds.size] = f[kinds.size - 1] - removable.first() + d
        removable.removeAt(0)
    }

    println(f.foldIndexed(Long.MIN_VALUE, {index, acc, elem -> Math.max(acc, elem + index.toLong() * index.toLong())}))
}

fun readInputLine(): String {
    return readLine()!!
}



Measured memory_bytes: 89336
#!/usr/bin/env python3
import sys


def solve(N: int, D: int, X: int, A: "List[int]"):
    ans = X + N
    for i in A:
        ans += ((D-1) // i)
    print(ans)


    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    X = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, D, X, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 61500
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n-1; i >= 0; i--)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
const int mod = 1e9+7;
const int INF = 1e9;
const int MAX = 1e6;

bool solve(string s, string t) {
    rep(i, s.size()) {
        rep(j, t.size()) {
            if (s[i] < t[j]) return true;
        }
    }
    if (s.size() < t.size()) {
        sort(ALL(s));
        sort(ALL(t));
        rep(i, s.size()) {
            rep(j, t.size()) {
                if (s[i] != t[j]) return false;
            }
        }
        return true;
    }
    return false;
}

int main() {
    string s, t;
    cin >> s >> t;
    if (solve(s, t)) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3604
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxPosNum = 1e5 + 5, maxRegionNum = 2e5 + 5;
int nodeNum, nbNumber, nbRegion, lef[maxRegionNum], rig[maxRegionNum], pos[maxPosNum], totChos;
bool lim[maxPosNum], vis[maxPosNum], chos[maxRegionNum], can = 1;
struct DOT{
	int pos, state;
	bool operator < (const DOT &d) const {
		return pos < d.pos;
	}
} dot[maxPosNum];
template<const int maxNodeNum, const int maxEdgeNum> struct Graph {
	int tot, head[maxNodeNum], to[maxEdgeNum << 1], next[maxEdgeNum << 1], reg[maxEdgeNum << 1];
	Graph() { memset(head, -1, sizeof(head)); }
	void AddEdge(int u, int v, int regId) {
		to[++tot] = v;
		next[tot] = head[u];
		reg[tot] = regId;
		head[u] = tot;
	}
};
//n+1个点，m条边的图 
Graph<maxPosNum, maxRegionNum> G;
void dfs(int now, int fa, int EId) {
	vis[now] = 1;
	for (int pt = G.head[now]; ~pt; pt = G.next[pt]) {
		int to = G.to[pt];
		if (!vis[to])
			dfs(to, now, pt);
	}
	if (~EId) {
		if (lim[now]) {
			lim[now] ^= 1;
			lim[fa] ^= 1;
			chos[G.reg[EId]] = 1;
			++totChos;
		}
	} else {
		if (lim[now]) {
			can = 0;
		}
	}
}
int main() {
	scanf("%d%d", &nbNumber, &nbRegion);
	for (int i = 1; i <= nbNumber; ++i) {
		scanf("%d%d", &dot[i].pos, &dot[i].state);
		pos[i] = dot[i].pos;
	}
	sort(dot + 1, dot + nbNumber + 1);
	for (int i = 1; i <= nbNumber + 1; ++i)
		lim[i] = dot[i - 1].state ^ dot[i].state;
	for (int i = 1; i <= nbRegion; ++i)
		scanf("%d%d", &lef[i], &rig[i]);
	sort(pos + 1, pos + nbNumber + 1);
	for (int i = 1; i <= nbRegion; ++i) {
		lef[i] = lower_bound(pos + 1, pos + nbNumber + 1, lef[i]) - pos;
		rig[i] = upper_bound(pos + 1, pos + nbNumber + 1, rig[i]) - pos - 1;
		if (lef[i] > rig[i])
			continue ;
		G.AddEdge(lef[i], rig[i] + 1, i);
		G.AddEdge(rig[i] + 1, lef[i], i);
	}
	dfs(nbNumber + 1, 0, -1);
	for (int i = 1; i <= nbNumber; ++i) {
		if (!vis[i]) {
			dfs(i, 0, -1);
			if (!can) {
				printf("-1\n");
				return 0;
			}
		}
	}
	printf("%d\n", totChos);
	for (int i = 1; i <= nbRegion; ++i)
		if (chos[i])
			printf("%d ", i);
	printf("\n");
	return 0;
}


Measured memory_bytes: 11520
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k;
	cin>>n>>k;
	int h[n+1];
	h[0]=0;
	for(int i=1;i<=n;i++)
	cin>>h[i];
	int ans[n+1];
	for(int i=1;i<=n;i++)
	ans[i]=1e9+5;
	ans[0]=ans[1]=0;
	for(int i=2;i<=n;i++)
	{
		for(int j=1;j<=k;j++)
		{
			if((i-j)<1)
			break;
	        ans[i]=min(ans[i-j]+abs(h[i]-h[i-j]),ans[i]);
		}
    }
	cout<<ans[n];
	return 0;
}

Measured memory_bytes: 1024
N = int(input())
a = input().split()
a = list(map(int,a))
a.sort()
A = 0
B = 0
for i in range(1,N+1):
  if i%2 == 0:
    B = B + a[N-i]
  else:
    A = A + a[N-i]
print(A-B)

Measured memory_bytes: 3064
#coding:utf-8
import itertools
n = int(input())
ls_all = []
A = ['3','5','7']
for j in range(3,10):
    ls = list(itertools.product(A, repeat=j))
    ls = [int(''.join(i)) for i in ls if ('3' in i and '5' in i and '7' in i)]
    ls_all.extend(ls)
ans = [n >= i for i in ls_all]
print (sum(ans))

Measured memory_bytes: 7156
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  int ans = 0, a = 0, b = 0, ba = 0;
  rep(i, n) {
    cin >> s[i];
    rep(j, s[i].size()-1) {
      if (s[i][j] == 'A' && s[i][j+1] == 'B')
        ans++;
    }
    if (s[i][0] == 'B' && s[i].back() == 'A')
      ba++;
    else if (s[i][0] == 'B')
      b++;
    else if (s[i].back() == 'A')
      a++;
  }
  if (ba) {
    if (a+b)
      ans += ba+min(a, b);
    else
      ans += ba-1;
  } else
    ans += min(a, b);
  cout << ans << endl;
  return 0;
}

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

int main(){
	string s;
	cin >> s;
	long ans = 0;
	for(long i=0; i < (1 << (s.size()-1)); i++) {
		long pre = 0;
		string post = "";
		post += s.at(0);
		for(int j=1; j < s.size(); j++) {
			if(i & (1 << (j-1))) {
				pre += stoll(post);
				post = "";
				post += s.at(j);
			}else{
				post += s.at(j);
			}
		}
		ans += pre + stoll(post);
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
 
int main(void){
 
int s=0;
 
int x=0;
int y=0;
  
scanf("%d",&s);
  
x=s/100;
y=s%100;
  
if(x>=1 && x<=12){
	if(y>=1 && y<=12){
    printf("AMBIGUOUS");
    }else {printf("MMYY");}
}else if(y>=1 && y<=12){
printf("YYMM");
}else{
printf("NA");
}
return 0; 
}

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

namespace ConsoleApp11
{
    class Class35
    {
        static void Main()
        {
            string S = Console.ReadLine();
            var T = new Dictionary<int, int>
            {
                [0] = 0,
                [1] = 0
            };
            for (int i = 0; i < S.Length; i++)
            {
                if (S[i] == '0')
                    T[0] += 1;
                else
                    T[1] += 1;

            }
            int ans = Math.Min(T[0], T[1]);
            Console.WriteLine(ans*2);
        }
    }
}


Measured memory_bytes: 13536
#include<iostream>
#include<vector>
#include<string>
#define F for(int j=0;j<date;j++)
using namespace std;
int main(void){
	int t;
	string s;
	while(1){
		cin>>t>>s;
		if(t==0)break;
		int date=s.size();
		vector<int> a(date,0);
		for(int i=0;i<date;i++){
			a[i]=s[i]-'0';
		}
		int sum=0;
		vector<int> c(date,-1);
		vector<bool> ans(date,false);
		int n=1;
		for(int i=0;i<date;i++){
			n*=2;
		}
		int time=0,kazu=0;
		for(int i=0;i<n;i++){
			int x=i;

			int k=0;
			vector<int> d(date,-1);
			vector<bool> b(date,false);
			F{
				if(x%2==1){
					b[j]=true;
				}
			//	x-=x%2;
				x/=2;
			}
			int num=0,sum1=0;
		//	if(b[date-1])cout<<"ok"<<endl;
			F{
				if(b[j]){
					k*=10;
					k+=a[j];
				}else{
					sum1+=k;
				if(j!=0){
						d[num]=k;
						num++;
				}						
					k=a[j];
					
				}
				
			}
			sum1+=k;
			d[num]=k;
			if(sum1==sum){
				time++;
				//	cout<<sum<<' '<<sum1<<endl;;
	//	F{
	//					if(c[j]!=-1)cout<<c[j];
	//			if(j!=date-1)cout<<' ';
	
		
	//	}
	//	cout<<endl;
			}
			if(sum1<=t&&sum1>sum){
				sum=sum1;
				kazu=0;
				F{
					if(d[j]!=-1)kazu++;
					ans[j]=b[j];
					c[j]=d[j];
				}
				time=1;


			}
		}
		if(sum==0){
			cout<<"error"<<endl;
			continue;
		}
		if(time>2){
			cout<<"rejected"<<endl;
			continue;
		}
		cout<<sum<<' ';
		F{
			//if(!ans[j]){
			//	cout<<a[j];
			//}else{
			//	cout<<a[j];
				if(c[j]!=-1){
					cout<<c[j];
				if(j<kazu-1)cout<<' ';
				}
		
		}
		cout<<endl;
	}

	return 0;	
}

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

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

    priority_queue<
         double
        ,vector<double>
        ,greater<double>
    > q;
    int v;
    for (int i = 0; i < N; i++) {
        cin >> v;
        q.push(v);
    }

    double top1, top2;
    for (int i = 0; i < N - 1; i++) {
        top1 = q.top(); q.pop();
        top2 = q.top(); q.pop();
        q.push((top1 + top2) / 2.0);
    }
    cout << q.top() << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,c=0,h=0;
	cin >> n;
	int a[n+1];
	for (int i=1;i<=n;++i)
	cin >> a[i];
	for (int i=1;i<=n;++i)
	{
		if (a[i]%2==0)
		{
			if (a[i]%3==0 || a[i]%5==0)
			h++;
			
		}
	   else
	   h++;
	}
if(h!=n)
cout <<  "DENIED";
else
cout << "APPROVED";
return 0;
}

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

int main() {
  int a,b,c,d,k;
  cin>>a>>b>>c>>d>>k;
  cout<<(c-a)*60+d-b-k<<endl;
  
  
}


Measured memory_bytes: 3636
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

const int INF = 1e9;
const long long LINF = 1e18;

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

    string S;
    cin >> S;

    S[K - 1] = tolower(S[K - 1]);
    cout << S << endl;

    return 0;
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Kein Yukiyoshi
 */

#include "bits/stdc++.h"
#define int long long
#define rep(i, n)           for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b)        for (int i = (int)(a); i < (int)(b); i++)
#define FOR(i, a)           for (auto &i : a)
#define ALL(obj)            begin(obj), end(obj)
#define MAX(x)              *max_element(ALL(x))
#define MIN(x)              *min_element(ALL(x))
#define SUM(x)              accumulate(ALL(x), 0LL)
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))

using namespace std;
const int MOD    = (int)(1e9 + 7);
const int INF    = (int)(1e13 + 7);
const double EPS = 1e-14;
const double PI  = acos(-1);

int CEIL(int a, int b) { return (a >= 0 ? (a + (b - 1)) / b : (a - (b - 1)) / b); } //ceil() for int
int mod(int a, int b) { return a >= 0 ? a % b : a - (b * CEIL(a, b)); }             //always return positive num
int bpm(int a, int b) {                                                             //return x^y in order(log(y))
  int res = 1;
  for (a %= MOD; b; a = a * a % MOD, b >>= 1)
    if (b & 1) res = res * a % MOD;
  return res;
}

class ATwoRectangles {
public:
  static void solve(istream &cin, ostream &cout) {
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    cout << max(A * B, C * D) << endl;
  }
};


signed main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
  ATwoRectangles solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}


Measured memory_bytes: 3640
#include<stdio.h>
#include<stdlib.h>
#define mymalloc(p,n) {p = malloc((n)*sizeof(*p));if ((p)==NULL) {printf("not enough memory?\n"); exit(1);};}


int *readArray(int *num){
	int i,j;
	int *A;
	scanf("%d", num);
	mymalloc(A,*num);
	for(i=0;i<*num;i++){
		scanf("%d",&j);
		A[i]=j;
	}
	return A;
}

void swapIJ(int *a, int *b){
	int temp;
	temp=*a;
	*a=*b;
	*b=temp;
}

void printArray(int *A, int num){
	int k;
	for(k=0;k<num;k++){
		printf("%d",A[k]);
		if(k<num-1){
			printf(" ");
		}
		else{printf("\n");}
	}
}

main(){
	int i,j,num,mini,count;
	int *A;
	A=readArray(&num);
	count=0;
	for(i=0;i<num;i++){
		mini=i;
		for(j=i+1;j<num;j++){
			if(A[j]<A[mini]){mini=j;}
		}
		if(i!=mini){
			count++;
			swapIJ(&A[i],&A[mini]);
		}
	}
	printArray(A,num);
	printf("%d\n",count);
	return 0;
}

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

ll dp[101][100001];
ll dfs(vector<pair<ll,ll>>& arr,ll index,ll w)
{
  if(w==0)
    return 0;
  if(index>=(ll)arr.size())
    return 0;
  if(dp[index][w]!=-1)
    return dp[index][w];
  
  if(arr[index].first<=w)
    return dp[index][w] = max(arr[index].second+dfs(arr,index+1,w-arr[index].first),dfs(arr,index+1,w));
  else
    return dp[index][w] = dfs(arr,index+1,w);
    
  
}

int main() 
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll n,w;
  cin>>n>>w;
  vector<pair<ll,ll>> arr;
  for(ll i=0;i<n;i++)
  {
    int a,b;
    cin>>a>>b;
    arr.push_back({a,b});
  }
  memset(dp,-1,sizeof(dp));
  ll ans = dfs(arr,0,w);
  cout<<ans<<endl;
    
}


Measured memory_bytes: 82576
import java.util.Arrays;
import java.util.Scanner;
public class Main{
 
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String input = scan.nextLine();
        String[] in = input.split(" ");
        int num1 = Integer.parseInt(in[0]);
        int num2 = Integer.parseInt(in[1]);
        int num3 = Integer.parseInt(in[2]);
        if (num1 >= 1 && num1 <= 10000 && num2 >= 1 && num2 <= 10000 && num3 >= 1 && num3 <= 10000) {
            int[] sortNum = new int[3];
            sortNum[0] = num1;
            sortNum[1] = num2;
            sortNum[2] = num3;
            Arrays.sort(sortNum);
            System.out.print(sortNum[0] + " ");
            System.out.print(sortNum[1] + " ");
            System.out.println(sortNum[2]);
        }
    }
}

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

int main(){
    string s;
    cin >> s;
    int a = 0,b = 0,c = 0;

    for(int i = 0;i < 3;i++){
        switch(s.at(i)){
            case 'a':
            a++;
            break;
            case 'b':
            b++;
            break;
            case 'c':
            c++;
            break;
        }
    }

    if((a == 1)&&(b == 1)&&(c == 1)){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <climits>
#include <cmath>
#include <algorithm>
#include <cassert>

#define TEST_ASSERT(msg, cond) do { if (cond) { cout << msg << " => pass" << endl;} else { cout << msg << " => failed" << endl;} } while(0)

using namespace std;

int main() {

  int N, K;
  cin >> N >> K;

  unordered_map<int, int> table;
  for (int i = 0; i < N; i++) {
    int ai = 0;
    cin >> ai;
    if (table.count(ai) > 0) {
      table[ai] += 1;
    }
    else {
      table[ai] = 1;
    }
  }
  vector<int> vec;
  vec.reserve(table.size());
  for (const pair<int, int>& p : table) {
    vec.push_back(p.second);
  }

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

/*
  for (int i = 0; i < vec.size(); i++) {
    cout << vec[i] << " ";
  }
  cout << endl;
*/

  int sum = 0;
  for (int i = 0; i < static_cast<int>(vec.size()) - K; i++) {
    //cout << "i = " << i << endl;
    sum += vec[i];
  }
  cout << sum << endl;

  return 0;
}


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

#define EPS (1e-10)
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)
#define all(a) a.begin(), a.end()

using namespace std;
using ll = long long;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvb = vector<vb>;

constexpr int MOD = 1000000007;

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

    int n;
    cin >> n;

    vi a(n);
    rep(i, 0, n) { cin >> a[i]; }

    vi b = a;
    sort(all(b));

    rep(i, 0, n) {
        if (a[i] == b[n - 1]) {
            cout << b[n - 2] << endl;
        } else {
            cout << b[n - 1] << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 3200
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

def main():
    N = int(input())
    num = [0] * 100005
    A = list(map(int,input().split()))
    S = sum(A)
    for a in A:
        num[a] += 1
    
    Q = int(input())
    for _ in range(Q):
        c,d = map(int,input().split())
        x = num[c]
        num[c] = 0
        S -= x * c
        num[d] += x
        S += x * d
        #print(num[:10])
        print(S)
if __name__ == '__main__':
    main()

Measured memory_bytes: 86344
#include <bits/stdc++.h>
using namespace std;
int main(){
int A, B;
char op;
cin >> A >> op >> B;

if (op == '+') cout << A + B << endl;
else if (op == '-') cout << A - B << endl;
else if (op == '*') cout << A * B << endl;
else if (op == '/' && B == 0) cout << A / B << endl;
else cout << "error" << endl;

}

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

using namespace std;

long long MOD = 1000000007;

int main(){
    int N;
    cin >> N;
    vector<int> B(N,0);
    for(auto &b:B){
        cin >> b;
        b--;
    }

    deque<int> ans;
    int cnt=0;
    for(int j=0; j<N; j++){
        int tmp =cnt;    
        for(int i=N-1; i>=0; i--){
            if(B[i]==-1){
                tmp--;
                continue;
            }
            if(B[i]==i-tmp){
                ans.push_front(B[i]);
                B[i]=-1;
                cnt++;
                break;
            }
        }
    }
    if(cnt!=N){
        //cout << cnt << endl;
        cout << -1 << endl;
        return 0;
    }

    while((int)ans.size()>0){
        cout << ans.front()+1 << endl;
        ans.pop_front();
    }
}

Measured memory_bytes: 256
(let ((s (read-line))
    (ans "Yes"))
    (loop for i below (length s) do
        (if (zerop (rem i 2))
            (if (string= (char s i) "L")
                (progn
                    (setq ans "No")
                    (return)
                )
            )
            (if (string= (char s i) "R")
                (progn
                    (setq ans "No")
                    (return)
                )
            )
        )
    )
    (princ ans)
)

Measured memory_bytes: 23684
#include <iostream>
#include <vector>
#include <tuple>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <string>
#include <climits>
#include <map>
#include <set>
#include <queue>
#include <bitset>
using namespace std;
#define Rep(i, n) for (int i = 0; i < (n); ++i)
#define InitRep(i, begin, n) for (int i = (begin); i < (n); ++i)
#define RepItr(it, begin, end) for (auto it = (begin); it != (end); ++it)
using int64 = long long;
using vint = vector<int>;
using vint64 = vector<int64>;
const static double PI = ::acos(-1);

constexpr int64 MOD = 1000000007;

int main()
{
    int n;
    cin >> n;
    vector<vint> stateHonest(n), stateUnkind(n);
    Rep(i, n)
    {
        int ai;
        cin >> ai;
        Rep(j, ai)
        {
            int x, y;
            cin >> x >> y;
            --x;
            if (y == 1)
            {
                stateHonest[i].push_back(x);
            }
            else
            {
                stateUnkind[i].push_back(x);
            }
        }
    }

    auto meets = [&](int bit, set<int>& honests, set<int>& unkinds)
    {
        Rep(i, n)
        {
            if (bit & (1 << i))
            {
                if (unkinds.find(i) != unkinds.end()) return false;
            }
            else
            {
                if (honests.find(i) != honests.end()) return false;
            }
        }
        return true;
    };

    int maxHonestsCount = 0;
    int maxBit = (1 << n);
    Rep(i, maxBit)
    {
        set<int> honests, unkinds;
        int honestsCount = 0;
        Rep(j, n)
        {
            if (i & (1 << j))
            {
                ++honestsCount;
                for (const int honest : stateHonest[j])
                {
                    honests.insert(honest);
                }
                for (const int unkind : stateUnkind[j])
                {
                    unkinds.insert(unkind);
                }
            }
        }
        if (meets(i, honests, unkinds))
        {
            //cout << bitset<16>(i) << endl;
            maxHonestsCount = max(honestsCount, maxHonestsCount);
        }
    }
    cout << maxHonestsCount << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long 
#define vi vector<int>
#define vl vector<ll>
#define vll vector<pair<ll,ll> >
#define pb push_back
#define f(i,a,b) for(i=a;i<b;i++)
using namespace std;

int main()
{
	int n,i,j,mx=1;
	
	cin>>n;
	int a[n],b[n+1],c[n+1];

	f(i,0,n)cin>>a[i];
	
	b[0]=a[0],c[0]=a[n-1];
	
	f(i,0,n)
	{
		b[i+1]=__gcd(a[i],b[i]);
	}
	f(i,0,n)c[i+1]=__gcd(c[i],a[n-1-i]);
	
	mx=max(b[n-1],c[n-1]);
	
	for(i=1;i<n-1;i++)
	{
		mx=max(mx,__gcd(b[i],c[n-i-1]));
	}
	cout<<mx;
}

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

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

Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <numeric>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
#define int long long
#define vint vector<int>
#define pint pair<int,int>
#define pb(a) push_back(a)
#define all(v) v.begin(),v.end()
#define dbg(x) cerr << #x << " = " << (x) << endl
#define yn(b) cout << ((b) ? "Yes" : "No") << endl
#define YN(b) cout << ((b) ? "YES" : "NO") << endl

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

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

	int A[30][30] = {0};

	int N, M, C;
	cin >> N >> M >> C;
	vint B(M);

	int ans = 0;

	for (int i = 0; i < M; i++) {
		cin >> B[i];
	}

	for(int i = 0; i < N; i++)
	{
		for (int j = 0; j < M; j++) {
			cin >> A[i][j];
		}
	}
	

	for (int i = 0; i < N; i++) {
		int res = 0;
		for (int j = 0; j < M; j++) {
			res += (A[i][j] * B[j]);
			//cout << A[i][j] << " " << B[j] << ",";
		}
		if(res>-C){
			ans++;
		}
		//cout << endl;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
main()
{
	int n,k;cin>>n>>k;
	long a[15];for(int i=0;i<n;i++)cin>>a[i];
	long ans=1LL<<60;
	for(long i=1;i<1<<n;i++)
	{
		int pcount=0;
		for(int j=0;j<n;j++)if(i&(1<<j))pcount++;
		if(pcount!=k)continue;
		long maxa=-(1e10);
		long b[15],nans=0;
		for(int j=0;j<n;j++)b[j]=a[j];
		for(int j=0;j<n;j++)
		{
			if(i&(1<<j))
			{
				if(b[j]<=maxa)
				{
					nans+=maxa-b[j]+1;
					b[j]=maxa+1;
				}
			}
			maxa=max(maxa,b[j]);
		}
		ans=min(ans,nans);
	}
	cout<<ans<<endl;
}

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

int main(){
  int n, buf, d=0, dt=0;
  vector<int> t, x, y;
  t.push_back(0), x.push_back(0), y.push_back(0);
  bool travel=true;

  cin >> n;
  for(int i=0; i<n; i++){
    scanf(" %d", &buf);
    t.push_back(buf);
    scanf(" %d", &buf);
    x.push_back(buf);
    scanf(" %d", &buf);
    y.push_back(buf);
  }

  for(int i=0; i<n; i++){
    d = abs(x[i+1]-x[i]) + abs(y[i+1]-y[i]);
    dt = t[i+1]-t[i];
    if((dt-d)%2!=0 || d>dt){
      travel=false;
      break;
    }
  }

  if(travel) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 1644
n,m = map(int,input().split())
x = [0]*n
y = [0]*n
z = [0]*n
for i in range(n):
  x[i],y[i],z[i] = map(int,input().split())
ans = 0
for i in range(2**3):
  s = [0]*n
  a = [1]*3
  j = 0
  while i > 0:
    if i&1:
      a[j] = -1
    i = i >> 1
    j += 1
  for i in range(n):
    s[i] = x[i]*a[0] + y[i]*a[1] + z[i]*a[2]
  s.sort(reverse = True)
  ans = max(ans, sum(s[:m]))
print(ans)


Measured memory_bytes: 3188
n,x=map(int,input().split())
l=list(map(int,input().split()))
d=[0]
for i in range(n):
  d.append(d[-1]+l[i])
  if d[-1]>x:
    print(len(d)-1)
    break
  if i==n-1:
    print(n+1)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned int;
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define all(c) c.begin(),c.end()
#define si(x) int(x.size())
#define pb emplace_back
#define fs first
#define sc second
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
template<class T,class U> void chmax(T& x, U y){if(x<y) x=y;}
template<class T,class U> void chmin(T& x, U y){if(y<x) x=y;}
template<class T> void mkuni(V<T>& v){sort(all(v));v.erase(unique(all(v)),v.end());}
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
void dmpr(ostream& os){os<<endl;}
template<class T,class... Args>
void dmpr(ostream&os,const T&t,const Args&... args){
	os<<t<<" ~ ";
	dmpr(os,args...);
}
#define shows(...) cerr << "LINE" << __LINE__ << " : ";dmpr(cerr,##__VA_ARGS__)
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) void(0)
#define dump(x) void(0)
#define shows(...) void(0)
#endif
struct UnionFind{
	vector<int> par;
	UnionFind(int N){
		par.assign(N,0);
		rep(i,N) par[i]=i;
	}
	int find(int x){
		if(par[x]==x) return x;
		return par[x]=find(par[x]);
	}
	bool same(int x,int y){
		return find(x)==find(y);
	}
	void unite(int x,int y){
		x=find(x),y=find(y);
		if(x==y) return;
		par[y]=x;
	}
};
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);

	int N; cin >> N;
	V<int> x(N),y(N);
	rep(i,N) cin >> x[i] >> y[i];
	VV<ll> es;
	rep(_,2){
		V<int> idx(N); iota(all(idx),0);
		sort(all(idx),[&](int l,int r){return x[l]<x[r];});
		rep(i,N-1){
			int a = idx[i], b = idx[i+1];
			es.push_back({x[b]-x[a],a,b});
		}
		rep(i,N) swap(x[i],y[i]);
	}
	sort(all(es));
	UnionFind UF(N);
	ll ans=0;
	for(auto e: es){
		if(!UF.same(e[1],e[2])){
			UF.unite(e[1],e[2]);
			ans += e[0];
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 15140
#include <stdio.h> 
int main(void)
{
	int a,b;
	
	scanf("%d %d",&a,&b);
	if(a>b)
		printf("a > b\n");
	else if(a<b)
		printf("a < b\n");
	else
		printf("a == b\n");
		
	return 0;
}

Measured memory_bytes: 580
#include <bits/stdc++.h>
#define f(i,n) for(int i=0;i<n;i++)
#define P pair<int,int>
#define F first
#define S second
#define int long long
#define mod 1000000007
#define mmod 998244353
#define all(v) v.begin(), v.end()
#define INF LLONG_MAX/3
using namespace std;
int mypow(int a, int b, int c) {
	if (b == 0)return 1;
	if (b % 2)return mypow(a, b - 1, c)*a%c;
	int z = mypow(a, b / 2, c);
	return z * z%c;
}
int x[100000];
signed main() {
	int a, b;
	cin >> a >> b;
	cout << min(a%b, b - a % b) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int Max = 1000000;

int main(){
  	int N;
  	cin >> N;
  	ll A, B;
  	P task[N];
  	for(int i=0;i<N;i++){
  		cin >> A >> B;
  		task[i] = make_pair(B, A);
  	}
  	sort(task, task+N);

  	ll time = 0;
  	int i=0;
  	while(i<N){
  		if(task[i].first-time < task[i].second){
  			cout << "No" <<endl;
  			return 0;
  		}else{
  			time += task[i].second;
  		}
  		i++;
  	}
  	cout << "Yes" <<endl;
    
  	return 0;
}


Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

string norm(string s){
    map<char,char> mp;
    string ret = "";
    char ch = 'a';
    rep(i,s.size()){
        if(mp.count(s[i])==0){
            ret+=ch;
            mp[s[i]] = ch;
            ch++;
        }else{
            ret+=mp[s[i]];
        }
    }
    return ret;
}

int main(){
    string s,t;
    cin>>s>>t;
    if(norm(s)==norm(t))cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 1552
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf
#define lcm hddalkwjeidjjhasda
#define random_shuffle asdasdd

int n, need;
vector <int> l, r;
int ans = 1e9;

int main() { 

  scanf("%d %d", &n, &need);
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    if (x < 0) {
      l.push_back(-x);
    } else {
      r.push_back(x);
    }
  }

  sort(all(l));
  sort(all(r));

  if (sz(r) >= need) {
    ans = r[need - 1];
  }

  for (int i = 0; i < min(need, sz(l)); i++) {
    int rem = need - (i + 1);
    if (rem > sz(r)) {
      continue;
    }
    int curAns = l[i];
    if (rem) {
      curAns += l[i] + r[rem - 1];
    }
    if (rem) {
      curAns = min(curAns, 2 * r[rem - 1] + l[i]);  
    }
    ans = min(ans, curAns);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1020
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main() {
    string n;
    cin >> n;
    int ans = 0;
    rep(i, n.length()) {
        if ( n[i] == '2' ) ++ans;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=2e5;
int a[N],mx[N],cnt,ans;
int main(){
	int n,t;
	scanf("%d%d",&n,&t);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	for (int i=n;(i);i--) mx[i]=max(mx[i+1],a[i]);
	for (int i=1;i<n;i++)
	{
		int o=mx[i]-a[i];
		if (o==ans) cnt++;
		if (o>ans)
		{
			ans=o;
			cnt=1;
		}
	}
	printf("%d",cnt);
}

Measured memory_bytes: 4536
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {

	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = null;

		try {
			while ((line = br.readLine()) != null) {
				line = line.trim();
				
				line = line.replaceAll("apple", "ELPPAHCAEP");
				line = line.replaceAll("peach", "apple");
				line = line.replaceAll("ELPPAHCAEP", "peach");
				
				System.out.println(line);
			}
			br.close();
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

}

Measured memory_bytes: 17068
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repp(i,a,b) for(ll i=a; i<b; i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
typedef long long ll;
struct edge { ll s, t, x; };
typedef pair<ll, ll> P;
typedef pair<double, P> event;
const ll MAX = 510000;
const ll MOD = 1000000007;
#define INF (ll)10000000000000000

int main() {
  ll A,B,C;
  ll K;
  cin>>A>>B>>C>>K;
  int flag=0;
  rep(i,K){
    if(A>=B){B*=2ll;continue;}
    if(B>=C){C*=2ll;continue;}
  }
  if(A<B&&B<C){cout<<"Yes"<<endl;}
  else{cout<<"No"<<endl;}
}


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

int main() {
  int N;
  cin >> N;
  
  vector<int> cards(N);
  
  for (int i = 0; i < N; i++) cin >> cards.at(i);
  
  sort(cards.begin(),cards.end(),greater<int>());
  
  int Alice = 0;
  int Bob = 0;
  
  for (int i = 0; i < N; i += 2) Alice += cards.at(i);
  for (int i = 1; i < N; i += 2) Bob += cards.at(i);
  
  cout << Alice - Bob << endl;
}

Measured memory_bytes: 3612
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def ok(last, first, S):
    N = len(S)
    ans = [None] * N
    ans[-1], ans[0] = last, first

    for i in range(N):

        if ans[i] == 0:
            if S[i] == "o":
                nex = ans[i - 1]
            else:
                nex = 1 - ans[i - 1]
        else:
            if S[i] == "o":
                nex = 1 - ans[i - 1]
            else:
                nex = ans[i - 1]

        if ans[(i + 1) % N] is None:
            ans[(i + 1) % N] = nex
        else:
            if ans[(i + 1) % N] != nex:
                return None
    return ans


def main():
    N = int(input())
    S = input()

    for l, f in [(0, 0), (0, 1), (1, 0), (1, 1)]:
        ans = ok(l, f, S)
        if ans is not None:
            print(*["S" if v == 0 else "W" for v in ans], sep="")
            return
    print(-1)


if __name__ == '__main__':
    main()


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

int main() {
    long n;
    cin>>n;
    if(n==1){
        cout<<0<<endl;
    }else{
        cout<<n*(n-1)/2<<endl;
    }
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#include <math.h>
#include <cmath>
#include <limits>
#include <iostream>
#include <assert.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;
typedef pair<ll,Pi> P1i;
const ll INF=10000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};
struct pos{
	int x,y,sx,sy,total;
};
char c[2001][2001];
int U[2001][2001]={},D[2001][2001]={};
int R[2001][2001]={},L[2001][2001]={};
int main(){

	int h,w;
	cin>>h>>w;
	for(int i=1; i<h+1; i++){
		for(int j=1; j<w+1; j++){
			cin>>c[j][i];
			if(c[j][i]=='.'){
				L[j][i]=L[j-1][i]+1;
				U[j][i]=U[j][i-1]+1;
			}
		}
	}
	int total=0;
	for(int i=h; i>0; i--){
		for(int j=w; j>0; j--){
			if(c[j][i]=='.'){
				R[j][i]=R[j+1][i]+1;
				D[j][i]=D[j][i+1]+1;
				total=max(total,R[j][i]+D[j][i]+U[j][i]+L[j][i]-3);
			}
		}
	}
	cout<<total<<endl;
	return 0;

}




Measured memory_bytes: 66688
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

template<class T> ll llpow(T x,T n){ll ans=1;while(n--){ans*=x;}return ans;}
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}

#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep2(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)

long long INF = 1LL<<60;
int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    rep(i,n)cin>>a[i];
    sort(a.begin(),a.end());
    int sum=0;
    double temp=0;
    rep(i,n)temp+=a[i];
    sum=temp/n+0.5;
    ll ans=INF;
    ll y=0;
    rep(i,n)y+=llpow(a[i]-sum,2);
    chmin(ans,y);
    sum=temp/n;
    y=0;
    rep(i,n)y+=llpow(a[i]-sum,2);
    chmin(ans,y);
    cout<<ans<<endl;
    return 0;
}




Measured memory_bytes: 256
s = gets.chomp
k = gets.to_i

s.chars.uniq.sort.each do |c|
  pos = 0
  idxs = []
  while pos = s.index(c,pos)
    idxs << pos
    pos += 1
  end
  ss = idxs.map { |i|
    s[i..-1]
  }.sort

  ss_ = []

  (0..ss.length-2).each do |i|
    if ss[i+1].start_with? ss[i]
      # nop
    else
      ss_ << ss[i]
    end
  end

  ss_ << ss[-1]

  ss_.each do |t|
    if k <= t.length
      puts t[0..k-1]
      exit 0
    end
    k -= t.length
  end
end

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

int main(){
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;

    int ans = X*A + Y*B;
    for(int i = 1; i <= 100000; i++)
        ans = min(ans, 2*C*i + max(X-i, 0)*A + max(Y-i, 0)*B);
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

const int maxn = 10;
int h, w;
int mp[10][10];

void floyd()
{
    for (int k = 0; k < maxn; k++)
        for (int i = 0; i < maxn; i++)
            for (int j = 0; j < maxn; j++)
                mp[i][j] = min(mp[i][j], mp[i][k] + mp[k][j]);
}

int main(void)
{
    while (scanf("%d %d", &h, &w) != EOF)
    {
        for (int i = 0; i < maxn; i++)
            for (int j = 0; j < maxn; j++)
                scanf("%d", &mp[i][j]);
        floyd();
        int ans = 0;
        for (int i = 0; i < h; i++)
        {
            for (int j = 0; j < w; j++)
            {
                int a;
                scanf("%d", &a);
                if (a == -1 || a == 1) continue;
                ans += mp[a][1];
            }
        }
        printf("%d\n", ans);
    }

    return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;
import static java.lang.System.out;
public class Main{
   public static void main(String []args){
      Scanner sc = new Scanner(System.in);
      int N = sc.nextInt();
      boolean result = false;
      int ns = N%10;//1
      int nt = (N-ns)/10;
      if(ns == 9){
         result = true;
      }else{
         if(nt==9){
            result = true;
         }
      }
      if(result == true){
         out.println("Yes");
      }else{
         out.println("No");
      }
   }
}

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

using namespace std;

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


int main() {

    int N;
    cin >> N;

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

    int sum = accumulate(a.begin(), a.end(), 0);

    int index = 0;
    for (int i = 0; i < N; i++) if (abs(N * a[index] - sum) > abs(N * a[i] - sum)) index = i;
    cout << index << endl;

    return 0;
}











































































Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main()
{
	char a[4010];
	int n,i,j;
	long long int num = 0, r = 0, b = 0, g = 0;
	scanf("%d", &n);
	getchar();
	gets(a);
	for (i = 0; i < n; i++)
	{
		if (a[i] == 'R')
		{
			r++;
		}
		else if (a[i] == 'G')
		{
			g++;
		}
		else
		{
			b++;
		}
	}
	num = r * g * b;
	for (i = 0; i < n; i++)
	{
		for (j = 1; j <= (n - 1) / 2; j++)
		{
			if (i + 2 * j < n)
			{
				if (a[i] != a[i + j] && a[i] != a[i + j+j] && a[i + j] != a[i + j+j])
				{
					num--;
				}
			}
		}
	}
	printf("%lld", num);
	return 0;
}


Measured memory_bytes: 1732
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>

using namespace std;
using lint = int64_t;
using P = pair<lint, lint>;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (lint i = 1; i < (n); ++i)
#define repn(i, a, b) for(int i = (a); i < (b); ++i)
#define Rep(i, n) for (lint i = (n); i >= 0; --i)
#define All(vec) vec.begin(), vec.end()
#define cend printf("\n")

//constexpr lint mod = 998'244'353LL;
constexpr lint mod = 1000'000'007LL;
constexpr lint inf = 3LL * mod * mod;
constexpr double Pi = 3.141592653589793;

template<class T> using prique = priority_queue<T>;
template<class T> using prique_inv = priority_queue<T, vector<T>, greater<T>>;
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& rhs) { return is >> rhs.first >> rhs.second; }
template<class T, class U>inline ostream& operator<<(ostream& os, const pair<T, U>& rhs) { return os << rhs.first << " " << rhs.second << "\n"; }
template<class InputIterator> void arrin(InputIterator first, InputIterator last) { for (; first != last; ++first) cin >> (*first); }
template<class InputIterator> void arrout(InputIterator first, InputIterator last) {
	for (; first != last; ++first) {
		cout << (*first) << ((first + 1) != last ? " " : "\n");
	}
}

constexpr bool pri(lint x) { for (lint i = 2; i * i <= x; ++i) if (x % i == 0) return false; return 1 < x; }

lint fact[3000000];
void fact_init(lint n, lint m = mod) {
	if (3000000 <= n) return;
	fact[0] = fact[1] = 1;
	for (lint i = 2; i <= n; ++i) {
		fact[i] = i * fact[i - 1] % m;
	}
}

lint modpow(lint x, lint n, lint m = mod) {
	lint res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % m;
		x = x * x % m;
		n >>= 1;
	}
	return res;
}

lint intpow(lint x, lint n) {
	lint res = 1;
	while (n > 0) {
		if (n & 1) res *= x;
		x *= x;
		n >>= 1;
	}
	return res;
}

lint comb(lint n, lint r, lint m = mod) {
	if (r == 0 || r == n) return 1;
	lint res = fact[n] * modpow(fact[n - r], m - 2, m) % m * modpow(fact[r], m - 2, m) % m;
	return res < 0 ? res + m : res;
}

map<lint, lint> factring(lint n) {
	map<lint, lint> res;
	for (lint i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			n /= i;
			++res[i];
		}
	}
	if (n != 1) ++res[n];
	return res;
}

int n, k;
int a[2 * 100010];
int main() {
	cin >> n >> k;
	rep(i, n) {
		cin >> a[i];
	}
	rep(i, n - k) {
		if (a[i] < a[i + k]) cout << "Yes\n";
		else cout << "No\n";
	}
}

Measured memory_bytes: 4372
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
ga, sa, ba = li()
gb, sb, bb = li()

vg1, vg2 = gb - ga, ga - gb
vs1, vs2 = sb - sa, sa - sb
vb1, vb2 = bb - ba, ba - bb

dp1 = [0]*(n+1)

for i in range(1,n+1):
    dp1[i] = max(dp1[i-1]+1,
                  dp1[i-ga] + gb if i-ga >= 0 else 0,
                  dp1[i-sa] + sb if i-sa >= 0 else 0,
                  dp1[i-ba] + bb if i-ba >= 0 else 0)

m = max(n, dp1[n])
dp2 = [0] * (m+1)

for i in range(1, m+1):
    dp2[i] = max(dp2[i-1]+1,
                 dp2[i-gb] + ga if i-gb >= 0 else 0,
                 dp2[i-sb] + sa if i-sb >= 0 else 0,
                 dp2[i-bb] + ba if i-bb >= 0 else 0)

print(max(m, dp2[m]))

Measured memory_bytes: 230296
#include<bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define mp make_pair
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define MOD 1000000007
typedef long long ll;
using namespace std;
int main(){
     ll x; cin>>x;
     if(x==0) cout<<1;
     else
     cout<<0;
    
    return 0;
    
}

Measured memory_bytes: 3620