akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG true
// sort(a.begin(), a.end(), std::greater<int>());

/*
std::vector<std::string> split(const std::string &input, char delimiter)
{
    std::istringstream stream(input);

    std::string field;
    std::vector<std::string> result;
    while (std::getline(stream, field, delimiter))
    {
        result.push_back(field);
    }
    return result;
}
*/

int main()
{
    int n, m;

    while (cin >> n >> m)
    {
        int mp[101] = {0};
        if (n == 0 && m == 0)
            break;
        int a, b;
        rep(i, n)
        {
            cin >> a >> b;
            mp[a] = max(mp[a], b);
        }
        int ans = 0;
        rep(i, 101)
        {
            if (mp[i] != 0)
                ans += mp[i];
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 2956
function Main(s) {
  s = +s;
  var ans = 1;
  for(var i = 2; i < s; i++)
  for(var j = 2; j < s; j++){
    if(Math.pow(i, j) <= s)ans = Math.max(ans, Math.pow(i, j));
    else break;
  }
  console.log(ans);
}

Main(require("fs").readFileSync("/dev/stdin","utf8"));

Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{

    long n;
    cin >> n;
    vector<long> vec(n + 1, 1);
    for (long i = 2; i <= n; i++)
    {
        for (long j = i; j <= n; j += i)
        {
            vec.at(j)++;
        }
    }
    long s = 1;
    for (long i = 2; i <= n; i++)
    {
        s += (i * vec.at(i));
    }
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 81396
<?php
fscanf(STDIN, "%d", $n);
$q = ['M'=>0,'A'=>0,'R'=>0,'C'=>0,'H'=>0];
while ($n--) {
	fscanf(STDIN, "%s", $s);
	if (isset($q[$s[0]])) $q[$s[0]]++;
}
$r = [];
foreach ($q as $k => $v) {
	if ($v > 0) $r[] = $v;
}
$m = count($r);
if ($m < 3) exit('0');
$x = 0;
for ($i = 0; $i < $m - 2; $i++) {
	for ($j = $i + 1; $j < $m - 1; $j++) {
		for ($k = $j + 1; $k < $m; $k++) {
			$x += $r[$i] * $r[$j] * $r[$k];
		}
	}
}
echo $x;

Measured memory_bytes: 4728
# -*- coding: utf-8 -*-
"""
Created on Sat Sep 19 20:18:10 2020

@author: liang
"""
#D
N, K = map(int, input().split())
areas = list()
for i in range(K):
    l, r = map(int,input().split())
    areas.append((l,r))
#areas_sum = [0] * N 
tmp = 0
d = [0] * N
#check = [0] * N
#check[0] = 1
d[0] = 1
for i in range(N):
    for j in range(K):
        l, r = areas[j]
        if i-l >= 0:
            #areas_sum[j] += d[i-l]
            tmp += d[i-l]
        if i-r-1 >= 0:
            #areas_sum[j] -= d[i-r-1]
            tmp -= d[i-r-1]
    d[i] += tmp
    #check[i] += tmp
    d[i] %= 998244353 
    tmp  %= 998244353 
    #t.append(tmp)

#print(d)
#print(check)
ans = d[N-1]
print(ans)
#print(tmp)

Measured memory_bytes: 75332
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string> //文字列
#include <iomanip> //doubleの桁数指定 setprecision()
#include <list> //前後に数値を入れれる配列
#include <map> //map
#include <vector> //vecror

#define REP(i,m,n) for(ll i = (ll) (m);i < (ll) (n);i++) //forの短縮
#define rep(i,n) REP(i,0,n) //REPが0の時
#define ll long long int

using namespace std;

double PI = acos(-1); //円周率
ll mod = 1e9 + 7;


//提出コード↓

string s;



int main() {
	cin >> s;
	if (s == "ABC") cout << "ARC" << endl;
	else cout << "ABC" << endl;


	return 0;
}



Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

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

    int n = (int)s.size();
    int a = 0;

    map<int, int> mp;
    mp[0] = 0;

    for (int i = 0; i < n; i++) {
        a ^= 1 << (s[i] - 'a');
        int m = n;
        for (int k = 1 << ('z' - 'a');; k >>= 1) {
            auto it = mp.find(a ^ k);
            if (it != mp.end()) {
                int t = it->second + 1;
                if (t < m) m = t;
            }
            if (k == 0) break;
        }

        if (i == n - 1) {
            cout << m << endl;
            quick_exit(0);
        }
        auto it = mp.find(a);
        if (it == mp.end()) mp.insert(make_pair(a, m)); else it->second = min(it->second, m);
    }

    return 0;
}

Measured memory_bytes: 9860
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long int ll;
typedef pair<int, int> Pii;
typedef pair<ll, int> Pli;
typedef pair<int, ll> Pil;
typedef pair<ll, Pii> PPii;
struct Edge{int to; int cost; ll dist;};
using Graph = vector<vector<Edge>>;

const ll INF = 1LL<<60;

int main()
{
  int n, m, s;
  cin >> n >> m >> s;
  s = min(s, 2500);
  
  Graph G(n);
  
  rep(i,m)
  {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    a--; b--;
    G[a].emplace_back(Edge{b, c, d});
    G[b].emplace_back(Edge{a, c, d});
  }
  //rep(i,n) { for(auto e : G[i]) cout << e.to << " "; cout << endl; } cout << endl;
  
  vector<Pil> exc(n);
  rep(i,n)
  {
    int a, b;
    cin >> a >> b;
    exc[i] = Pil(a, b); //cost, dist
  }
  
  vector<vector<ll>> dist(n, vector<ll>(2600, INF));
  
  priority_queue<PPii, vector<PPii>, greater<PPii>> pq; //dist, (vertex, resource)
  pq.push(PPii(0, Pii(0, s)));
  dist[0][s] = 0;
  
  while(!pq.empty())
  {
    auto p = pq.top();
    pq.pop();
    int v = p.second.first;
    ll d = p.first, r = p.second.second;
    
    if(d < dist[v][r])
    {
      continue;
    }
    
    for(auto e : G[v])
    {
      int nr = r - e.cost;
      if(nr < 0) continue;
      if(dist[v][r] + e.dist < dist[e.to][nr])
      {
        dist[e.to][nr] = dist[v][r] + e.dist;
        pq.push(PPii(dist[e.to][nr], Pii(e.to, nr)));
      }
    }
    int nr = r + exc[v].first;
    nr = min(nr, 2500);
    if(dist[v][r] + exc[v].second < dist[v][nr])
    {
      dist[v][nr] = dist[v][r] + exc[v].second;
      pq.push(PPii(dist[v][nr], Pii(v, nr)));
    }
  }
  
  for(int i = 1; i < n; i++)
  {
    ll res = 1LL<<60;
    rep(j,2600)
    {
      if(dist[i][j] == INF) continue;
      res = min(res, dist[i][j]);
    }
    cout << res << endl;
  }
  
  return 0;
}

Measured memory_bytes: 6316
//  cout << char(i+48) << endl;//なぜかaは47と得る時がある。+48で出力もaにできる。
//  cout << char(97) << endl;//アスキーコードでaを出力
// sort(b.begin(), b.end());//bという配列を小さい方からソート
// reverse(b.begin(), b.end());//bという配列をリターン
// 10桁でdouble出力するパターン１ 
// printf("%.10f\n", ma);
// 10桁でdouble出力するパターン２
//cout << fixed << setprecision(10);
//  cout << ma << endl;

/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*///vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  ll n,k;
  cin >> n >> k;
  if(n==1)cout<<k<<endl;
  else {
    ll count = 1;
    for(int i=1;i<n;i++){
      count *= (k-1);
    }
    cout << k * count <<endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;
int ABS(int a){return max(a,-a);}
char in[11];
int m[120][120];
vector<pair<int,int> >at[11000];
int dp[120][120];
int main(){
	int a,b;
	while(scanf("%d%d",&b,&a),a){
		for(int i=0;i<11000;i++)at[i].clear();
		int n=0;
		
		for(int i=0;i<a;i++)for(int j=0;j<b;j++)dp[i][j]=999999999;
		for(int i=0;i<a;i++)for(int j=0;j<b;j++){
			scanf("%s",in);
			if(in[0]=='.')m[i][j]=-1;
			else if(in[0]=='S'){
				m[i][j]=0;
				at[0].push_back(make_pair(i,j));
				dp[i][j]=0;
			}else if(in[0]=='G'){
				m[i][j]=-2;
			}else{
				int v=0;
				for(int k=0;in[k];k++){
					v*=10;v+=in[k]-'0';
				}
				m[i][j]=v;
				n=max(n,v);
				at[v].push_back(make_pair(i,j));
			}
		}
		for(int i=0;i<a;i++)for(int j=0;j<b;j++)if(m[i][j]==-2){
			at[n+1].push_back(make_pair(i,j));
		}
		for(int i=0;i<=n;i++){
			for(int j=0;j<at[i].size();j++){
				for(int k=0;k<at[i+1].size();k++){
					dp[at[i+1][k].first][at[i+1][k].second]=min(dp[at[i+1][k].first][at[i+1][k].second],
					dp[at[i][j].first][at[i][j].second]+ABS(at[i][j].first-at[i+1][k].first)+ABS(at[i][j].second-at[i+1][k].second));
				}
			}
		}
		printf("%d\n",dp[at[n+1][0].first][at[n+1][0].second]);
	}
}

Measured memory_bytes: 1536
#include <iostream>
#include <list>
#include <string>
using namespace std;
int main(){

  int n,x,i;
  list <int> a;
  list<int>::iterator it;
  string com;

  cin>>n;
  for(i=0;i<n;i++){
    cin>>com;
    if(com=="deleteFirst") a.pop_front();
    else if(com=="deleteLast") a.pop_back();
    else{
      cin>>x;
      if(com=="insert") a.push_front(x);
      else for(it=a.begin();it!=a.end();it++) if(*it==x){
            a.erase(it);
            break;
          }
    }
  }
  i=0;
  for(it=a.begin();it!=a.end();it++){
    if(i++) cout<<" ";
    cout<<*it;
  }
  cout<<endl;

  return 0;

}


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



int main() {
int n;
cin >> n;
vector<int> p(n);
rep(i,n) cin >> p[i];
int ans = 0;
int curMin = 1e9;
rep(i,n){
	curMin = min(curMin , p[i]);
	if(curMin == p[i]) ans++;
}
cout << ans++ << endl;

	return 0;
}

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

#include <fstream>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  /*
  ifstream in("input.txt");
  cin.rdbuf(in.rdbuf());
  //*/
  string S;
  cin >> S;
  int K;
  cin >> K;
  for(int i = 0; i < S.size(); i++){
    if(S[i] != '1'){
      cout << S[i] <<endl;
      return 0;
    }
    if(i == K-1){
      cout << '1' <<endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>

using namespace std;

    int main() {
       int A,B,C;
       cin>>A>>B>>C;
       if(A+B>=C) {
           cout << "Yes";
           return 0;
       }cout<<"No";
        return 0;

    }

Measured memory_bytes: 256
# coding: cp932
N = gets.to_i
P = gets.split.map {|e| e.to_i}

# １つめの要素から検索していって、最大値を記録
# 最大値より小さい場合は○、
# 最大値より大きい場合は最大値を更新

_max = 0
_min = 0
ans = 0

P.each_with_index do |p, i|
  # p "p=#{p} ans=#{ans} max:#{_max} min=#{_min}"
  if i == 0
    ans += 1
    _max = p
    next
  end

  if i == 1
    if _max < p
      _min = _max
      _max = p
    else
      _min = p
      ans += 1
    end
    next
  end

  if p <= _min and p <= _max
    ans += 1
  else
    _max = p if p > _max
  end
  _min = p if p < _min
  
end

puts ans


Measured memory_bytes: 15236
import java.util.*;

public class Main{ 

	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		//int numNode = scan.nextInt();
		Tree tree = new Tree(scan.nextInt());
		scan.nextLine();
		tree.connectNode(scan);
		//.out.println("scan end");
		tree.treeView();
	}

}
class Tree{
	int numNode;
	HashMap<Integer, Node> nodes = new HashMap<Integer, Node>();
	public Tree(int n){
		this.numNode = n;
		for(int i=0; i<numNode; i++)
			nodes.put(i, new Node(i));	
	}
	public void connectNode(Scanner scan){
		for(int i=0; i<numNode; i++){
			int id = scan.nextInt();//Integer.parseInt(splitLine[0]);
			int numChild = scan.nextInt();//IInteger.parseInt(splitLine[1]);
			if(numChild == 0)
				continue;
			for(int j=0; j<numChild; j++){
				int childId = scan.nextInt();
				nodes.get(id).setChild(nodes.get(childId));
				nodes.get(childId).setParent(nodes.get(id));
			}
		}
	}
	public void treeView(){
		for(int i=0; i<numNode; i++)
			System.out.println(nodes.get(i));
	}

}

class Node{
	int id;
	Node parent;
	ArrayList<Node> children = new ArrayList<Node>();
	public Node(int id){
		this.id=id;
	}
	public void setParent(Node p){
		this.parent = p;
	}
	public Node getParent(){
		return this.parent;
	}
	public int getParentID(){
		return (parent==null)? -1 : parent.id;
	}
	public void setChild(Node c){
		children.add(c);
	}
	public Iterator<Node> getChildren(){
		return children.iterator();
	}
	int getDepth(Node n){
		if(n.parent==null)
			return 0;
		else
			return getDepth(n.parent)+1;
	}
	String getType(){
		if(parent==null)
			return "root";
		else if(children.size()==0)
			return "leaf";
		else
			return "internal node";
	}
	String childrenID(){
		StringBuilder temp = new StringBuilder();
		temp.append("[");
		if(children.size()>0)
		for(int i=0; ; i++){
			temp.append(children.get(i).id);
			if( i == children.size() - 1 )
				break;
			temp.append(", ");
		}
		temp.append("]");
		return new String(temp);
	}
	@Override
	public String toString(){
		StringBuilder temp = new StringBuilder();
		temp.append("node " + this.id);
		temp.append(": parent = " + getParentID());
		temp.append(", depth = " + getDepth(this));//+ this.id;
		temp.append(", "  + getType());
		temp.append(", "   + childrenID());
		//node 1: parent = 0, depth = 1, internal node, [2, 3]
		return new String(temp);
	}
}

Measured memory_bytes: 213548
import java.util.Scanner;
public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int i = 0;
        int count = 0;
        String strMoney;
        StringBuilder result = new StringBuilder();
        while (true) {
            String line = sc.nextLine();
            if(line.equals("0")) {
                break;
            } else if(i > 0 && i % 2 == 0) {
                result.append("\n");
            }

            if(i % 2 ==0) {
                count = Integer.valueOf(line);
            } else {
                strMoney = line;
                result.append(calculate(count, strMoney));
            }
            i++;
        }

        System.out.println(result.toString());

    }

    public static int calculate(int count, String strMoney) {
        String[] arrMoney = strMoney.split(" ");
        int total = 0;
        for (String money : arrMoney) {
            total += Integer.valueOf(money);
        }

        int result = 0;
        for (String money : arrMoney) {
            if(Integer.valueOf(money) * count <= total) {
                result++;
            }
        }
        return result;
    }
}


Measured memory_bytes: 63292
#include <assert.h>
#include <limits>
#include <iostream>
#include <random>
#include <bitset>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <unordered_map>
#include <iterator>
#include <thread>
#include <stack>
#include <numeric>
#include <queue>
#include <unordered_set>
#include <set>
#include <sstream>
#include <iomanip>
#include <chrono>
#include <ctime>

using namespace std;

#define pv(x) printVector(x)
#define pvv(x) printVectorsOfVector(x)
#define f0(n) for(int i = 0; i < n; ++i)
#define f0e(n) for(int i = 0; i <= n; ++i)
#define f1(n) for(int i = 1; i < n; ++i)
#define f1e(n) for(int i = 1; i <= n; ++i)
#define eol cout<<endl

typedef vector<int> vi;
typedef vector<vector<int>> vvi;

template <class T>
void printVector(const vector<T>& v)
{
	for (T& i : v)
	{
		cout << i << " ";
	}
	cout << endl;
}

template <class T>
void printVectorsOfVector(const vector<vector<T>>& v)
{
	cout << " [ " << endl;
	for (size_t i = 0; i < v.size(); i++)
	{
		cout << "  ";
		cout << " [ ";
		for (size_t j = 0; j < v[i].size(); j++)
		{
			cout << v[i][j];
			if (j != v[i].size() - 1)
				cout << " , ";
		}
		cout << " ] ";
		cout << endl;
	}
	cout << " [ ";
	cout << endl;
}

////////////////////////////////////////////////////////////////////
// Write your code here onwards...
////////////////////////////////////////////////////////////////////

static int __ = []() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
  return 0;
}();

int main() {
  int N = 0;
  cin >> N;
	if (N % 1000 == 0)
		cout << 0;
	else
		cout << (N / 1000 + 1) * 1000 - N;
	return 0;
}

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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = 1LL << 60;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	ll n;
	vector<ll> c, s, f;

	cin >> n;

	REP(i, n - 1) {
		ll x, y, z;
		cin >> x >> y >> z;
		c.push_back(x);
		s.push_back(y);
		f.push_back(z);
	}

	REP(i, n) {
		if (i == n - 1) {
			cout << 0 << endl;
		}
		else {
			ll now = i;
			ll ans = 0;
			while (now < n - 1) {
				if (ans <= s[now]) {
					ans = s[now] + c[now];
				}
				else {
					if ((ans - s[now]) % f[now] == 0) {
						ans += c[now];
					}
					else {
						ans = s[now] + ((ans - s[now]) / f[now] + 1) * f[now] + c[now];
					}
				}
				now++;
			}
			cout << ans << endl;
		}
	}
}

Measured memory_bytes: 256
N=int(input())

so=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97]
log=[1]*len(so)

for num in range(1,(N)+1):
    for index,item in enumerate(so):    
        while num%item==0:
            num/=item
            log[index]+=1
        if num==1:
            break
            

ans=0
#print(sum([x>=75 for x in log]))
ans+=sum([x>=75 for x in log])
#print(ans)
ans+=sum([x>=25 for x in log])*(sum([x>=3 for x in log])-1)
ans+=sum([x>=15 for x in log])*(sum([x>=5 for x in log])-1)
ans+=sum([x>=5 for x in log])*(sum([x>=5 for x in log])-1)*(sum([x>=3 for x in log])-2)//2

#print(log)
print(ans)

Measured memory_bytes: 3188
#!/usr/bin/env pypy
from __future__ import division, print_function

import os
import sys
from __builtin__ import xrange as range
from cStringIO import StringIO
from future_builtins import ascii, filter, hex, map, oct, zip
from io import IOBase

import __pypy__


def main():
    a, b = map(int, input().split())
    print(max(a + b, a - b, a * b))


# region fastio

BUFSIZE = 8192


class FastI(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = StringIO()
        self.newlines = 0

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count("\n") + (not b)
            ptr = self._buffer.tell()
            self._buffer.seek(0, 2), self._buffer.write(b), self._buffer.seek(ptr)
        self.newlines -= 1
        return self._buffer.readline()


class FastO(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = __pypy__.builders.StringBuilder()
        self.write = lambda s: self._buffer.append(s)

    def flush(self):
        os.write(self._fd, self._buffer.build())
        self._buffer = __pypy__.builders.StringBuilder()


def print(*args, **kwargs):
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


sys.stdin, sys.stdout = FastI(sys.stdin), FastO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()


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

#define _ ios_base::sync_with_stdio(0);cin.tie(0);

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

int main(int argc, char *argv[]) { _
    ll k;
    string s;

    cin >> s >> k;

    for (auto &i : s) {
        if (i != 'a' && 'z' + 1 - i <= k) {
            k = k - ('z' + 1 - i);
            i = 'a';
        }
    }
    s[s.size() - 1] += (k % 26);
    if (s[s.size() - 1] > 'z') {
        // cout << "Char: " << s[s.size() - 1] << endl;
        s[s.size() - 1] = 'a' + s[s.size() - 1] - 'z' - 1;
    }

    cout << s;
    cout << endl;
    return 0;
}


Measured memory_bytes: 592
#include <iostream>
#include <cstdio>
#define REP(i,n) for (int i=0;i<(n);i++)
using namespace std;
int main(void){
    int x,y;
    cin >> x >> y ;
    if(((x==4||x==6||x==9)&&(y==6||y==9||y==11)) || ((x==1||x==3||x==5||x==7||x==8||x==10)&&(y==3||y==5||y==7||y==8||y==10||y==12))){
        cout << "Yes";
    }else{
        cout << "No";
    }
    
    return 0;
}


Measured memory_bytes: 764
n = int(input())
a = [[0, 0, 0]] + [[int(i) for i in input().split()] for i in range(n)]
for i in range(n):
    d = a[i + 1][0] - a[i][0]
    x = abs(a[i + 1][1] - a[i][1])
    y = abs(a[i + 1][2] - a[i][2])
    if x + y > d:
        print("No")
        break
    elif (d - (x + y)) % 2 == 1:
        print("No")
        break
else:
    print("Yes")

Measured memory_bytes: 21924
#include<bits/stdc++.h>
using namespace std;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>;
#define ll long long
#define ff first
#define ss second

int main()
{
    ll a, b, g;
    cin >> a >> b;
    g = __gcd(a, b);

    ll i, ans = 1;

    for(i = 2; i <= sqrt(g); i++)
    {
        if((g%i) == 0)
        {
            while(g%i == 0)
                g /= i;
            ans++;
        }
    }

    if(g > 1)
        ans++;
    cout << ans;
}


Measured memory_bytes: 384
fun main(args: Array<String>){
    val input = readLine()!!.split(' ')
                            .map  { it.toInt() }
    val fiveCount = input.count{it == 5}
    if (fiveCount != 2) return noGood()

    val sum = input.sum()
    if (sum != 17) return noGood()

    println("YES")
}
fun noGood(){
    println("NO")
}

Measured memory_bytes: 38308
#include<bits/stdc++.h>
# define    all(a)              a.begin(), a.end()
#define forn(i, a, b) for (int i=a; i<b; i++)
#define pb push_back
#define mp make_pair
#define MOD int(1e9+7)
using namespace std;

typedef long long int ll;

bool cmp(int a, int b) {
    return a < b;
}

void printV(vector<int> nums) {
    for (int i: nums) {
        printf("%d ", i);// << " ";
    }
    printf("\n");
}

// void printV(vector<ll> nums) {
//     for (ll i: nums) {
//         printf("%lld ", i);// << " ";
//     }
//     printf("\n");
// }



int dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};

bool valid(int i, int j, int n, int m) {
    if (i >= 0 && i < n && j >=0 && j < m)
        return true;
    else 
        return false;
}


int main() {
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
    // ios_base::sync_with_stdio(false);
    // cin.tie(0);cout.tie(0);
    // time_t start, end;
    // time(&start);
    int n;
    cin >> n;
    vector<int> nums(n);
    for (int i=0; i<n; i++) cin >> nums[i];
    vector<int> cnt(100012);
    for (int i: nums)
        cnt[i]++;
    for (int i=n-1; i>=0; i-=2) {
        if (i == 0 && cnt[i] == 1) {
            continue;
        }
        if (cnt[i] != 2) {
            cout << 0 << endl;
            return 0;
        }
    }
    long long int ans = 1;
    for (int i=0; i<n/2; i++) {
        ans = (ans*2)%MOD;
    }
    cout << ans << endl;
    // time(&end); 
    // double time_taken = double(end - start);
    // cout << "Time Taken: " << fixed << time_taken << setprecision(5);
    // cout << " sec" << endl;
    return 0;
}  

Measured memory_bytes: 3984
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;



namespace Test1 {

    

    class ClassMain {



        public static void Main(String[] args) {
            string line;
            while ((line = Console.ReadLine()) != null) {
                int n = int.Parse(line);
                if (n == 0) { break; }
                //Store
                List<int> intList = new List<int>();
                for (int i = 0; i < n; i++) {
                    intList.Add(int.Parse(Console.ReadLine()));
                }
                int srch = int.Parse(Console.ReadLine());

                int cnt = 0;
                while (true) {
                    cnt++;
                    int half = (intList.Count-1) / 2;
                    if (intList.ElementAt(half) == srch) { break; }
                    if (intList.Count == 1) { break; }
                    if (intList.Count == 2 && (intList.ElementAt(half) > srch)) { break; }
                    if (intList.ElementAt(half) < srch) {//serach right.
                        intList = intList.GetRange(half + 1, intList.Count - half-1);
                    }
                    else {
                        intList = intList.GetRange(0, half);
                    }
                }
                Console.WriteLine(cnt);
            }
        }


       

    }

    
}

Measured memory_bytes: 5820
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long 
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
int const M=1e6+10,inf=1e9+10;
int a[M];
main()
{
	int n;
	cin>>n;
	int sum=0;
	for(int i=1;i<=n;i++)cin>>a[i],sum+=a[i];
	if(sum%2==0)cout<<"YES";
	else cout<<"NO";
}

Measured memory_bytes: 1024
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  dp=[0]*100010

  dp[1]=0
  dp[2]=abs(l[0]-l[1])
  for i in range(2,n):
    dp[i+1]=min(dp[i]+abs(l[i]-l[i-1]),dp[i-1]+abs(l[i]-l[i-2]))

  return dp[n]

print(main())


Measured memory_bytes: 16708
use proconio::{input,fastout};

#[fastout]
fn main() {
    input! {
        n: i32,
    }

    let mut acs = 0;
    let mut was = 0;
    let mut tles = 0;
    let mut res = 0;

    for _m in 0..n {
        input! {
            s: String,
        }
        if s == "AC" {
            acs += 1;
        }
        if s == "WA" {
            was += 1;
        }
        if s == "TLE" {
            tles += 1;
        }
        if s == "RE" {
            res += 1;
        }
    }
    println!("AC x {}",acs);
    println!("WA x {}",was);
    println!("TLE x {}",tles);
    println!("RE x {}",res);
}


Measured memory_bytes: 2516
#include <iostream>
/*図のようなリング状の文字列 s の任意の位置から、時計回りに連続した文字をいくつか選んで、文字列 p が作れるかを判定するプログラムを作成してください。*/
using namespace std;
bool rotateSearch(string s, string word){
	for(int i = 0; i < s.size(); i++){
		string left = s.substr(0, s.size() - 1 - i);
		string right = s.substr(s.size() - 1 - i);
		if ((right + left).find(word) != string :: npos) return true;
	}
	return false;
}
int main(){
	string s, word;
	cin >> s >> word;
	cout << (rotateSearch(s, word) ? "Yes" : "No") << endl;
}



Measured memory_bytes: 3192
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 998244353;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef vector<vector<ll>> mat;
typedef vector<int> vec;

void solve() {
	int a, b; cin >> a >> b;
	int x = 1;
	int ans = 0;
	while (x < b) {
		ans++;
		x += a-1;
	}
	cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(5);
	//init();
	solve();
	stop
		return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
#define pvec(vec) {for (auto v: vec) cout << v << ' '; cout << endl;}
#define pivec(vec) {rep(i, 0, vec.size()) cout << i << ':' << vec[i] << ' '; cout << endl;}

using namespace std;
using ll = long long;

// Binary Indexed Tree (Fenwick Tree)
template<typename T>
struct BIT {
  int n;
  vector<T> d;
  BIT(int n=0):n(n),d(n+1) {}
  void add(int i, T x=1) {
    for (i++; i <= n; i += i&-i) {
      d[i] += x;
    }
  }
  T sum(int i) {
    T x = 0;
    for (i++; i; i -= i&-i) {
      x += d[i];
    }
    return x;
  }
  T sum(int l, int r) {
    return sum(r-1) - sum(l-1);
  }
};

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

    // read input as range 
    vector<pair<int, int>> clr_rng;
    {
        unordered_map<int, int> prepos;
        rep(i, 1, N+1)
        {
            int c;
            cin >> c;
            clr_rng.emplace_back(prepos[c], i);
            prepos[c] = i;
        }
    }
    vector<tuple<int, int, int>> qry;
    rep(i, 0, Q)
    {
        int l, r;
        cin >> l >> r;
        qry.emplace_back(l, r, i);
    }


    // sort by start pos 
    sort(clr_rng.rbegin(), clr_rng.rend());
    sort(qry.rbegin(), qry.rend());

    // countint with bit
    BIT<ll> bit(N+1);
    vector<int> ans(Q);
    int pos_c = 0;
    int pos_q = 0;
    rrep(pos, N+1, 1)
    {
        // add range
        while (pos_c < (int) clr_rng.size())
        {
            int frm, to;
            tie(frm, to) = clr_rng[pos_c];
            if (frm < pos) break;

            // printf("from: %d, to: %d\n", frm, to);

            bit.add(to, 1);
            ++pos_c;
        }

        // process query
        while (pos_q < (int) qry.size())
        {
            int frm, to, i;
            tie(frm, to, i) = qry[pos_q];
            if (frm < pos) break;

            int num = to - frm + 1;
            num -= bit.sum(to);

            // printf("from: %d, to: %d, i: %d, bit: %lld\n", frm, to, i, bit.sum(to));

            ans[i] = num;
            ++pos_q;
        }

    }

    // output answer
    rep(i, 0, Q) printf("%d\n", ans[i]);

    return 0;
}


Measured memory_bytes: 26848
n = int(input())
x = [list(map(str, input().split())) for _ in range(n)]
jp = 0
bt = 0

for i in range(n):
    if x[i][1] == 'JPY':
        jp += int(x[i][0])
    elif x[i][1] == 'BTC':
        bt += float(x[i][0])

print(jp + 380000*bt)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll a,b;cin>>a>>b;
  print(max(0ll,a-2*b));
  return 0;
}


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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

int main() {
  in(string, s, t);
  out(t+s);
}


Measured memory_bytes: 256
A,B,K = map(int,input().split())
A_box = []
B_box = []
for i in range (1,101):
    if (A/i) == int(A/i):
        A_box.append(i)
    if (B/i) == int(B/i):
        B_box.append(i)
result=list(set(A_box) & set(B_box))
result.sort()

print(result[-K])

Measured memory_bytes: 3064
N, Q = map(int, input().split())
S = input()

cnt = [0] * N
for i in range(1, N):
    if S[i-1:i+1] == "AC":
        cnt[i] = cnt[i-1] + 1
    else:
        cnt[i] = cnt[i-1]

for _ in range(Q):
    L, R = map(int, input().split())
    ans = cnt[R-1] - (cnt[L-2] if L >= 2 else 0)
    if L >= 2 and cnt[L-1] != cnt[L-2]:
        ans -= 1
    print(ans)

Measured memory_bytes: 6140
a,b,c,d,e,f=map(int, input().split())

indxmax=0.0
wmax=0
emax=0
elimit=(100*e)/(100+e)
c31=int(f/c)+1
for ai in range(0,f+1,a):
    for bi in range(0,f-ai+1,b):
        w=100*ai+100*bi
#        print("a,b:",ai,bi,w)
        if w<=f and w>0:
#            c31=int(w/100*e/c)+1
#            c31=min(int(w/100*e/c)+1,31)
#            d31=int(w/100*e/d)+1
            c31=(w*e)//100+c
            for ci in range(0,c31,c):
#                for di in range(d31):
                for di in range(0,c31-ci,d):
                    indx=(ci+di)*100/w
                    if indxmax<indx and e-indx>=0.0 and w+ci+di<=f:
                        wmax=w+ci+di
                        indxmax=indx 
                        emax=ci+di
#                    print("c,d",ci,di,emax,wmax,diii)
if wmax>0:
    print(wmax,emax)
else:
    print(100*a,emax)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define int long long
int mod = 1e9 + 7;
int INF = 2e18;
 
signed main() {
    int N;
    cin >> N;
    vector<int> H(N);
    for (int i = 0; i < N; i++) cin >> H[i];
    int ans = 0, count = 0;
    for (int i = 0; i < N - 1; i++) {
        if (H[i] >= H[i + 1]) {
            ++count;
            ans = max(ans, count);
        } else {
            count = 0;
        }
    }
    

    cout << ans << endl;
}


Measured memory_bytes: 1024
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import Data.List (sortBy)

main :: IO ()
main = do
  (x : y : a : b : c : _) <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  ps <- sortBy (flip compare) . map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  qs <- sortBy (flip compare) . map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  rs <- sortBy (flip compare) . map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  let
    ss = rs >< take x ps >< take y qs :: [Int]
  print . sum . take (x + y) $ ss

(><) :: [Int] -> [Int] -> [Int]
[] >< ys = ys
xs >< [] = xs
xs@(x : xs') >< ys@(y : ys') | x < y     = y : (xs >< ys')
                             | otherwise = x : (xs' >< ys)
infixr 5 >< 

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n


Measured memory_bytes: 46460
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#define V(x, y, z) ((x) * 1000000 + (y) * 1000 + (z))
#define inf 1000000000

using namespace std;

int W, H;
char map[55][55];
int P;
string S[15];
int sx, sy, gx, gy;

vector<string> vec;
int Next[105][4];
bool ng[105][4];
const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
const char c[] = {'R', 'U', 'L', 'D'};

int dist[55][55][105];

int bfs()
{
	for(int x = 1; x <= W; x++){
		for(int y = 1; y <= H; y++){
			for(int k = 0; k < vec.size(); k++){
				dist[x][y][k] = inf;
			}
		}
	}
	dist[sx][sy][0] = 0;
	
	queue<int> Q;
	Q.push(V(sx, sy, 0));
	int x, y, state;
	while(Q.size()){
		state = Q.front() % 1000, Q.front() /= 1000;
		y = Q.front() % 1000, Q.front() /= 1000;
		x = Q.front();
		Q.pop();
		for(int i = 0; i < 4; i++){
			int nx = x + dx[i], ny = y + dy[i], nstate = Next[state][i];
			if(ng[state][i]) continue;
			if(nx <= 0 || nx > W || ny <= 0 || ny > H) continue;
			if(map[nx][ny] == '#') continue;
			if(dist[nx][ny][nstate] < inf) continue;
			dist[nx][ny][nstate] = dist[x][y][state] + 1;
			Q.push(V(nx, ny, nstate));
		}
	}
	
	int ret = inf;
	for(int i = 0; i < vec.size(); i++) ret = min(ret, dist[gx][gy][i]);
	if(ret == inf) return -1;
	return ret;
}

int main(void)
{
	while(1){
		cin >> H >> W;
		if(H == 0 && W == 0) break;
		
		for(int y = 1; y <= H; y++){
			for(int x = 1; x <= W; x++){
				cin >> map[x][y];
				if(map[x][y] == 'S') sx = x, sy = y;
				if(map[x][y] == 'G') gx = x, gy = y;
			}
		}
		cin >> P;
		for(int i = 0; i < P; i++) cin >> S[i];
		
		vec.clear();
		vec.push_back("");
		for(int i = 0; i < P; i++){
			for(int j = 0; j < S[i].size(); j++){
				vec.push_back(S[i].substr(0, j));
			}
		}
		sort(vec.begin(), vec.end());
		vec.erase(unique(vec.begin(), vec.end()), vec.end());
		
		for(int i = 0; i < vec.size(); i++){
			for(int j = 0; j < 4; j++){
				ng[i][j] = false;
			}
		}
		
		for(int i = 0; i < vec.size(); i++){
			for(int j = 0; j < 4; j++){
				
				string s = vec[i] + c[j];
				for(int k = 0; k < P; k++){
					string t = s;
					while(t.size()){
						if(t == S[k]){
							ng[i][j] = true;
							goto end;
						}
						t = t.substr(1);
					}
				}
				end:;
				
				while(1){
					auto p = lower_bound(vec.begin(), vec.end(), s);
					if(p != vec.end() && *p == s){
						Next[i][j] = p - vec.begin();
						break;
					}
					s = s.substr(1);
				}
				
			}
		}
		
		cout << bfs() << endl;
	}
	
	return 0;
}


Measured memory_bytes: 4220
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn main() {
    let n: u32 = read();
    println!("{}", n / 2 + n % 2);
}


Measured memory_bytes: 4352
S = input()

a = len(S)
cnt = 0
for i in range(a):
#奇数の場合
  if i % 2==0:
#L以外が含まれる（Lではない）
    if S[i] != "L":
      cnt +=1
    elif S[i] == "L":
      cnt -= 101
#偶数の場合
  elif i %2 ==1:
#R以外が含まれる（Rではない）
    if S[i] != "R":
      cnt +=1
    elif S[i]=="R":
      cnt -= 101

if cnt>0:
  print("Yes")
else:
  print("No")


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

public class Main {

  public static void main(String[] args) {

    new Main().run();
  }
  public void run() {

    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {
      String[] lines = in.readLine().split(" ");
      int n = Integer.parseInt(lines[0]);
      int k = Integer.parseInt(lines[1]);

      double dn = n;
      double ans = 0.0;
      if(k == 1) ans = 1;
      else {
        for (int i = 1; i <= n; i++) {
          int cnt = 0;
          for (int j = i; j < k; j*=2) {
            cnt++;
          }
          
          ans += 1 / dn * Math.pow(0.5, cnt);
        }
      }

      System.out.println(ans);
    }
    catch(IOException e) {

      System.err.println(e);
    }
  }
}

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

using namespace std;
int n,d,dat[100005],mx,res,cnt;
int main()
{
	scanf("%d%d",&n,&d);
	for(int i=1;i<=n;i++) scanf("%d",&dat[i]);
	mx=dat[n];
	for(int i=n-1;i>=1;i--)
	{
		if(mx>dat[i])
		{
			if(mx-dat[i]>res) res=mx-dat[i],cnt=1;
			else if(mx-dat[i]==res) cnt++;
		}
		mx=max(mx,dat[i]);
	}
	printf("%d",cnt);
	return 0;
}

Measured memory_bytes: 640
n, k = gets.chomp.split(' ').map(&:to_i)
arr = gets.chomp.split(' ').map(&:to_i)
cost = Float::MAX
(0...(1 << n)).each do |i|
  next if sprintf("%0#{n}d", i.to_s(2)).count('1') != k
  height = 0
  current_cost = 0
  (0...n).each do |j|
    if arr[j] <= height && (i >> j) & 1 == 1
      height += 1
      current_cost += height - arr[j]
    end
    height = [height, arr[j]].max
  end
  cost = [cost, current_cost].min
end
puts cost

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

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

    if ((int)s.size() <= k)
        cout << s << endl;
    else
    {
        for (int i = 0; i < k; i++)
        {
            cout << s[i];
        }
        cout << "..." << endl;
    }
}

Measured memory_bytes: 3628
#include <algorithm>
#include <iostream>
#include <cstring>
#include <climits>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>

#define R register
#define LL long long
#define U unsigned
#define FOR(i,a,b) for(R int i = a;i <= b;++i)
#define ROF(i,a,b) for(R int i = a;i >= b;--i)
#define CLR(i,a) memset(i,a,sizeof(i))
#define BR printf("--------------------\n")
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl
#define int long long
const int MAXN = 100000 + 5;

struct Node{
    int a,b,c;

    bool operator < (const Node &other) const {
        return a-b < other.a-other.b;
    }
}p[MAXN];

int N,x,y,z;
int sum=0,tot;
int l[MAXN];
std::priority_queue<int,std::vector<int>,std::greater<int> > q;

signed main(){
    scanf("%lld%lld%lld",&x,&y,&z);
    N = x+y+z;
    FOR(i,1,N) scanf("%lld%lld%lld",&p[i].a,&p[i].b,&p[i].c),tot += p[i].c;
    std::sort(p+1,p+N+1);
    LL ans = 0,sum = 0;
    FOR(i,1,y){
        sum += p[i].b-p[i].c;
        q.push(p[i].b-p[i].c);
    }
    FOR(i,y+1,N-x+1){
        l[i] = sum;
        sum += p[i].b-p[i].c;
        q.push(p[i].b-p[i].c);
        sum -= q.top();q.pop();
    }
    while(!q.empty()) q.pop();
    sum = 0;
    ROF(i,N,N-x+1){
        sum += p[i].a-p[i].c;
        q.push(p[i].a-p[i].c);
    }
    ROF(i,N-x,y){
        ans = std::max(ans,tot+l[i+1]+sum);
        sum += p[i].a-p[i].c;
        q.push(p[i].a-p[i].c);
        sum -= q.top();
        q.pop();
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 3832
#include <stdio.h>
#include <string>
#include <algorithm>
#include <map>
#include <iostream>
#include<math.h>
using namespace std;
string a[4] = { "dream","dreamer","erase","eraser" };

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

	reverse(s.begin(), s.end());

	for (int i = 0; i < 4; ++i) reverse(a[i].begin(), a[i].end());
	bool can = true;
	for (int i = 0; i < s.size();) {
		bool can2 = false;
		for (int j = 0; j < 4; j++) {
			string d = a[j];
			if (s.substr(i, d.size()) == d) {
				can2 = true;
				i += d.size();
			}
		}
		if (!can2) {
			can = false;
			break;
		}
	}
	if (can)cout << "YES" << endl;
	else cout << "NO" << endl;

}



Measured memory_bytes: 512
#include <bits/stdc++.h>
#define S second
#define F first
#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using LL = long long;
using LD = long double;
const int mod = 1e9 + 7;
const LL N = 1e5 + 5;

using namespace std ;

LL ans[1007][1007];
//LL arr[N];
int main (){
    int n;
    cin >> n;
    LL hap[n][3];
    for(int i = 0; i < n; ++i)
        cin >> hap[i][0] >> hap[i][1] >> hap[i][2];

    LL ans[n][3];
    ans[0][0] = hap[0][0], ans[0][1] = hap[0][1], ans[0][2] = hap[0][2];
    for (int i = 1; i < n; ++i){
            ans[i][0] = max(ans[i - 1][1], ans[i - 1][2]) + hap[i][0];
            ans[i][1] = max(ans[i - 1][0], ans[i - 1][2]) + hap[i][1];
            ans[i][2] = max(ans[i - 1][1], ans[i - 1][0]) + hap[i][2];
    }
    cout << max (ans[n - 1][0], max(ans[n - 1][1], ans[n - 1][2])) << endl;
}


Measured memory_bytes: 4992
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

//引用元
//http://drken1215.hatenablog.com/entry/2019/03/03/224600
struct UnionFind {
    vector<long> parent;
    
    UnionFind(long n) : parent(n, -1) { }
    void init(long n) { parent.assign(n, -1); }
    
    //xの属している木の根っこを返す
    long root(long x) {
        if (parent[x] < 0) return x;
        else return parent[x] = root(parent[x]);//経路圧縮
    }
    
    long size(long x) {return -parent[root(x)];}
    bool is_same_tree(long x,long y) {return root(x)==root(y);}
    
    bool merge(long x,long y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (parent[x] > parent[y]) swap(x, y);//xの親の方がyの親より小さくなるようにする
        parent[x] += parent[y];
        parent[y] = x;//yの親をxとする
        return true;
    }
};

int N,M;
vector<int> war;//iと交戦状態の島のうち、最も番号が小さいものをwar[i]とする
 
int ans = 0;

void solve(){
	UnionFind uf(N);
	int partition_point = INF_INT;//どこで橋を切断する予定か
	for(int i=0;i<N;i++){
		if(partition_point==i){
			ans++;
			partition_point = INF_INT;
		}
		if(war[i]==INF_INT) continue;
		partition_point = min(partition_point,war[i]);
	}
}
 
int main(){
    cin >> N >> M;
    war = vector<int>(N,INF_INT);
    for(int i=0;i<M;i++){
    	int a,b;cin >> a >> b;
    	war[a-1] = min(war[a-1],b-1);
    }
 
    solve();
 
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1536
#include <stdio.h>

int main(void)
{
	int a, b, c, d;
	int ans;
	int n;
	
	while (scanf("%d", &n) == 1){
		ans = 0;
		for (a = 0; a < 10; a++){
			for (b = 0; b < 10; b++){
				for (c = 0; c < 10; c++){
					for (d = 0; d < 10; d++){
						if ( a + b + c + d == n){
							ans++;
						}
					}
				}
			}
		}
		printf("%d\n", ans);
	}
	
	return (0);
}
				
	

Measured memory_bytes: 592
//
//  main.cpp
//  atcoder001
//
//  Created by 芦原智隆 on 2018/02/01.
//  Copyright © 2018年 芦原智隆. All rights reserved.
//

#include <iostream>
#include <math.h>
using namespace std;

int main (){
    
    //合計値を算出するあれ。
    int total = 0;
    int total_value = 0;

    //配列の列の長さをインプット
    int side;
    cin >>  side;
    //配列１行目の入力を定義する
    int array1[side];
    for (int i = 1; i <= side; i++){
        cin >> array1[i];
    }
    //配列２行目の入力を定義する
    int array2[side];
    for (int j = 1; j <= side; j++){
        cin >> array2[j];
    }
    
    for(int k = 1; k <= side ; k++){
        for(int m = 1; m <= side; m++){
            if(m <= k){
                total =  total + array1[m];
            }
            if(m >= k){
                total =  total + array2[m];
            }
        }
        if(total_value  < total){
            total_value = total;
        }
        total = 0;
    }
    cout << total_value << "\n";
    return 0;
    
}


Measured memory_bytes: 256