akhauriyash/Code-Regression huggingface dataset:
fun main(args: Array<String>) {
    val (n, x) = readLine()!!.split(' ').map(String::toLong)
    val aList = readLine()!!.split(' ').map(String::toLong)
    var before = aList.first()
    var answer = 0L
    if (before > x) {
        answer += before - x
        before = x
    }

    for (i in 1 until n.toInt()) {
        if (before + aList[i] > x) {
            val sub = before + aList[i] - x
            answer += sub
            before = aList[i] - sub
        }else{
            before = aList[i]
        }
    }
    println(answer)
}

Measured memory_bytes: 73836
#include <bits/stdc++.h>
using namespace std;
#define boost ios::sync_with_stdio(false);cin.tie(nullptr)
#define int long long
#include "string"

vector<int>preffix(string s) {
    int n=s.size();
    vector<int>pi(n,0);
    for(int i=1;i<n;i++) {
        int j=pi[i-1];
        while(j>0 and s[i]!=s[j])
            j=pi[j-1];
        if(s[i]==s[j])
            pi[i]=j+1;
    }
    return pi;
}

int kmp(string t,string p) {
    vector<int>ans;
    int n=t.size();
    int m=p.size();
    vector<int>pi=preffix(p);
    int j=0;
    for(int i=0;i<n;i++) {
        while(j>0 and t[i]!=p[j])
            j=pi[j-1];
        if(t[i]==p[j]) {
            j++;
            if(j==m){
                ans.push_back(i-j+1);
                j = pi[j-1];
            }
        }
    }
    return ans.size();
}

int solve(string s,string t){
	int l=1,r = s.size()/t.size() + 1,ans = -1;

	while(l<=r){
		int m = (l + r)/2;
		string tt = "";
		for(int i=0;i<m;i++)
			tt += t;
		if(kmp(s,tt) > 0){
			ans = m;
			l = m + 1;
		}
		else
			r = m - 1;
	}
	return ans;
}

int32_t main(){
	boost;
	string S,T;
	cin>>S>>T;
	string s = S;
	while(s.size() <= S.size()  + T.size())
		s += S;
	s += S;
	int ans1 = solve(s,T);
	if(ans1 == -1){
		cout<<0<<endl;
		return 0;
	}

	s += s;
	
	int ans2 = solve(s,T);

	if(ans1 != ans2)
		cout<<-1<<endl;
	else
		cout<<ans2<<endl;
}




Measured memory_bytes: 71876
import java.util.*;
import java.util.stream.*;
class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        String W = input.next();
        int ans = 0;
        while (true){
            String T = input.next();
            if (T.equals("END_OF_TEXT")){
                break;
            }
            T = T.toLowerCase();
            if (T.equals(W)){
                ans += 1;
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 26164
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;
typedef long long ll;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

long long kk;

int read() {
  if (scanf("%lld", &kk) < 1) {
    return false;
  }
  return true;
}

const string f = "FESTIVAL";
const int p = 200;
string s;

void solve(int pos, long long k) {
  k--;
  while (k % p) {
    s += f[pos];
    k--;
  }
  if (!k) {
    return;
  }
  solve(pos - 1, k / p);
  for (int i = 0; i < p; i++) {
    s += f[pos];
  }
}

void solve() {
  s = f;
  solve(7, kk);
  printf("%s\n", s.c_str());
}

int main() {
  precalc();
#ifdef LOCAL
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (true) {
    if (!read()) {
      break;
    }
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


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

int main()
{
	int n, x;
	cin >> n >> x;
	int y;
	cin >> y;
	int ans = abs(x - y);
	auto gcd = [](int a, int b) -> int {
		int t;
		while((t = a % b) != 0){
			a = b;
			b = t;
		}
		return b;
	};
	for(auto i = 1; i < n; ++i){
		cin >> y;
		ans = gcd(ans, abs(y - x));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main implements Runnable {

    private void solve() throws IOException {

        int N = nextInt();
        int[] arr = new int[N];
        for(int i = 0; i < N; ++i) arr[i] = nextInt();

        for(int i = N - 1; i >= 0; i -= 2) {
            writer.print(arr[i] + " ");
        }
        int start = 0;
        if(N%2 != 0) ++start;
        for(int i = start; i < N; i += 2) {
            writer.print(arr[i] + " ");
        }
        writer.println();
    }




    public static void main(String[] args) {
        new Main().run();
    }

    BufferedReader reader;
    //    BufferedReader reader2;
    StringTokenizer tokenizer;
    PrintWriter writer;
    //    BufferedWriter writer;

    public void run() {
        try {
            reader = new BufferedReader(new InputStreamReader(System.in));
//            reader = new BufferedReader(new FileReader("input.txt"));
            //            reader2 = new BufferedReader(new FileReader("1.in"));
            tokenizer = null;
            writer = new PrintWriter(System.out);
//            writer = new     PrintWriter("output.txt");
//                                                    writer = new BufferedWriter(System.out);
            //                        writer = new BufferedWriter(new OutputStreamWriter(System.out));
            solve();
            reader.close();
            //            reader2.close();
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    short nextShort() throws IOException {
        return Short.parseShort(nextToken());
    }

    String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }

        return tokenizer.nextToken();
    }

}

Measured memory_bytes: 56088
#include <stdio.h>
int main()
{
    int H, W, a=0, b=0;
    while(1){
        scanf("%d %d", &H, &W);
        if(H==0 && W==0){
            break;
        }
        for(a=0; a<H; a++){
            if(a==0 || a==H-1){
                for(b=0; b<W; b++){
                    printf("#");
                }
                printf("\n");
            } else {
                for(b=0; b<W; b++){
                    if(b==0 ||  b==W-1){
                        printf("#");
                    } else {
                        printf(".");
                    }
                }
                printf("\n");
            }
        }
        printf("\n");
    }
    return 0;
}

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

int main()
{
  int A, B;
  bool flag = false;

  cin >> A >> B;

  if ( (A + B) % 3 == 0
   ||  A % 3 == 0
   ||  B % 3 == 0      )
  {
    flag = true;
  }

  if (flag) {
    cout << "Possible" << endl;
  } else {
    cout << "Impossible" << endl;
  }
}


Measured memory_bytes: 256
S = input()
n = len(S)
ans = 1e100
for i in range(26):
    t = chr(ord('a') + i)
    if t not in S:continue
    tmp = 0
    cnt = 0
    for s in S + t:
        if s == t:
            tmp = max(tmp, cnt)
            cnt = 0
        else:
            cnt += 1
    ans = min(ans, tmp)
print(ans)


Measured memory_bytes: 3064
package main

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

type point struct {
	x, y int
}

func main() {
	n := getInt()
	m := getInt()

	students := make([]point, n)
	for i := range students {
		students[i].x = getInt()
		students[i].y = getInt()
	}

	checkPoints := make([]point, m)
	for i := range checkPoints {
		checkPoints[i].x = getInt()
		checkPoints[i].y = getInt()
	}

	for _, s := range students {
		ans := -1
		comparer := 9999999999
		for i, c := range checkPoints {
			tmp := abs(s.x-c.x) + abs(s.y-c.y)
			if tmp < comparer {
				ans = i
				comparer = tmp
			}
		}
		fmt.Println(ans + 1)
	}
}

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

// -----------------------------------------

var scanner = wordScanner()

func wordScanner() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}

func getInt() int {
	scanner.Scan()
	i, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getString() string {
	scanner.Scan()
	s := scanner.Text()
	return s
}


Measured memory_bytes: 640
#include<stdio.h>

int main(void){
    int N = 0, X = 0;
    int L[255];
    int D = 0;
    int i = 0;

    scanf("%d %d", &N, &X);

    for(i = 0; i < N; i++){
        scanf("%d", &L[i]);
    }

    for(i = 1; i <= N; i++){
        D = D + L[i-1];
        if(D > X){
            break;
        }
    }

    printf("%d", i);

    return 0;
}

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

using namespace std;

int main(){
	string pal;
	int count = 0;
	
	while(cin >> pal){
		bool ispalin = true;
		int l = pal.size();		
		for(int i=0;i*2 < l-1;i++) if(pal[i] != pal[l-1-i]) {ispalin = false;break;}
		if(ispalin) count++;
	}
	
	cout << count << endl;
	
	return 0;
}

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};

int main()
{
    ll n;
    cin>>n;
    vector<ll> a(n),s(n+1);
    s[0]=0;
    for (int i = 0; i < n; i++)
    {
        cin>>a[i];
        s[i+1]=s[i]+a[i];
    }
    ll sm=s[n];
    ll ans=__LONG_LONG_MAX__;
    for (int i = 0; i < n; i++)
    {
        ans=min(ans,abs(2*s[i]-sm));
    }
    cout<<ans<<endl;
    
    return 0;
}

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

#include <iostream>
#include <fstream>

#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>
using namespace std;
using ll = long long;
constexpr ll INF = 1010000000000000017LL;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()

class DBannedK {
public:
	void solve(std::istream& in, std::ostream& out) {
        ll n;
        in>>n;
        map<ll,ll> mp;
        vector<ll> a(n);
        rep(i,n) in>>a[i];
        rep(i,n){
            mp[a[i]]++;
        }

        ll res=0;
        for(const auto &i: mp) res+=i.second*(i.second-1)/2;

        rep(i,n){
            ll x= mp.at(a.at(i));
            ll before = x*(x-1)/2;
            ll after = (x-1)*(x-2)/2;
            out<<res-before+after<<endl;
        }

	}
};


int main() {
	DBannedK solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 11136
(defun _int-cards (n m lst m-lst)
  (let* ((n-lst (mapcar #'(lambda (x) `(1 . ,x)) lst)) 
         (nm-lst (append n-lst m-lst))
         (sorted-lst (sort nm-lst #'(lambda (a b) 
                                      (let ((a0 (cdr a))
                                            (b0 (cdr b)))
                                        (> a0 b0))))))
    (labels ((all-m-lst (_m-lst rest-n rv)
                        ;(print rv)
                        (if (or (null _m-lst) (<= rest-n 0)) rv
                          (let* ((elm (car _m-lst))
                                 (b (car elm))
                                 (c (cdr elm)))
                            (all-m-lst (cdr _m-lst) (- rest-n b) 
                                       (+ rv (* c (min b rest-n))))))))
      ;(print sorted-lst)
      (all-m-lst sorted-lst n 0))))


(defun int-cards (n m lst m-lst)
  (print (_int-cards n m lst m-lst)))


#|
(int-cards 3 2 '(5 1 4) '((2 . 3) (1 . 5)))
(int-cards 10 2 '(1 8 5 7 100 4 52 33 13 5) '((3 . 10) (4 . 30) (1 . 4)))
(int-cards 3 2 '(100 100 100) '((3 . 99) (3 . 99) ))
(int-cards 11 4 '(1 1 1 1 1 1 1 1 1 1 1) '((3 . 10000000000) (4 . 10000000000) (3 . 10000000000 )))
|#

(let* ((n (read))
       (m (read))
       (lst (labels ((read-n (my-n rv)
                             (if (= my-n 0) (nreverse rv)
                               (let ((a (read)))
                                 (read-n (- my-n 1) (cons a rv))))))
              (read-n n nil)))
       (m-lst (labels ((read-m (my-m rv)
                               (if (= my-m 0) (nreverse rv)
                                 (let ((b (read))
                                       (c (read)))
                                   (read-m (- my-m 1) (cons (cons b c) rv))))))
                (read-m m nil))))
  (int-cards n m lst m-lst))


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

n,a,b= map(int, input().split())
h= [int(input()) for i in range(n)]


# めぐる式二部探索、mid=攻撃回数
l=-1
r=pow(10,10)
while r-l>1:
    # rは常にOK、lは常にNG。
    mid=l+(r-l)//2
    # 残りの攻撃回数を記録
    x=mid
    # なんらかの判定
    for i in range(n):
        # 爆風で倒せる敵はスルー
        if mid*b>=h[i]:
            continue
        else:
            # 爆風で削りきれないモンスターを爆弾で削る
            y=-(-(h[i]-(mid*b))//(a-b))
            x-=y
            if x<0:
                break
    if x>=0:
        r = mid  # 判定がOKのとき→範囲を左に狭める
    else:
        l=mid # 判定がNGのとき→範囲を右に狭める

print(r)


Measured memory_bytes: 44124
def main():
    N = int(input())
    csfs = [[int(i) for i in input().split()] for j in range(N-1)] + [[-1,0,0]]

    for i in range(N):
        state = i
        time = csfs[state][1]
        while state < N-1:
            if time % csfs[state][2] == 0 and csfs[state][1] <= time:
                time += csfs[state][0]
                state += 1
            else:
                time += (csfs[state][2] - time%csfs[state][2])
                if csfs[state][1] > time:
                    time = csfs[state][1]
        print(time)
if __name__ == '__main__':
    main()

Measured memory_bytes: 41836
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;

//
#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0, sizeof(x))
#define mm(x) memset((x), -1, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define bit(n) (1LL << (n))
#define bitset(a, b) (a) |= (1 << (b))
#define bitunset(a, b) (a) |= ~(1 << (b))
#define bitcheck(a, b) ((((a) >> (b)) & 1) == 1)
#define bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
const int INF = (int)1e18;
const int MOD = (int)1e9 + 7;
const double PI = (double)acos(-1);
const double EPS = (double)1e-10;
const int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
const int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
template <typename T>
void chmax(T &a, T b) { a = max(a, b); }
template <typename T>
void chmin(T &a, T b) { a = min(a, b); }
//
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
};

signed main() {
  int N;
  cin >> N;
  vec b;
  for (int i = 0; i < N; i++) {
    int tmp;
    cin >> tmp;
    b.pb(tmp);
  }

  vec ans;
  for (int i = 0; i < N; i++) {
    for (int j = N - 1 - i; j >= 0; j--) {
      if (b[j] == j + 1) {
        ans.pb(j + 1);
        b.erase(b.begin() + j);
        break;
      }
      if (j == 0) {
        cout << -1 << endl;
        return 0;
      }
    }
  }

  reverse(ALL(ans));
  for (auto x : ans) {
    cout << x << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define foi(i,k,n) for(int i = (int)k; i < (int)n; ++i)
using namespace std;
using ll = long long;
using ii = pair<int,int>;
constexpr int MAXN = 5 + 100000;

vector<ii> intervals;
int n, memo[MAXN];

int dp(int i) {
  if (i >= n) {
    return 0;
  }
  int& ans = memo[i];
  if (~ans) return ans;

  return ans = max(dp(1 + i), 1 + dp(lower_bound(intervals.begin(), intervals.end(), ii(intervals[i].second, -2e9)) - intervals.begin()));
}

int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
  cin >> n;
  foi (i,0,n) {
    int x,l; cin >> x >> l;
    intervals.push_back({x - l, x + l});
  }
  sort(intervals.begin(), intervals.end());
  memset(memo, -1, sizeof memo);
  cout << dp(0) << '\n';
  return 0;
}


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

using ll = long long;
using P = pair<ll, ll>;

const ll MOD = 1e9+7;
// const ll MOD = 998244353;
const ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define DEBUG(x) ;

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


int main(int argc, char **argv)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll H, W, M; cin >>H >> W >> M;
	vector<ll> h(M), w(M);
	REP(i, M) cin >> h[i] >> w[i];

	set<P> is;
	REP(i, M)
		is.insert(P{h[i], w[i]});

	map<ll, ll> tate;
	map<ll, ll> yoko;
	REP(i, M)
		tate[h[i]]++;
	REP(i, M)
		yoko[w[i]]++;

	vector<P> tatev;
	vector<P> yokov;
	for (auto &p : tate)
		tatev.push_back(P{p.second, p.first});
	for (auto &p : yoko)
		yokov.push_back(P{p.second, p.first});

	sort(ALL(tatev), greater<P>());
	sort(ALL(yokov), greater<P>());

	ll res{0};

	ll ma = yokov.front().first;
	ll yokoi = yokov.front().second;
	REP(i, (ll)tatev.size())
	{
		auto p = tatev[i];
		ll tatei = p.second;
		ll tmp = p.first + ma;
		if (is.count(P{tatei, yokoi}))
			tmp = max(0ll, tmp-1);
		res = max(res, tmp);
	}

	ma = tatev.front().first;
	ll tatei = tatev.front().second;
	REP(i, (ll)yokov.size())
	{
		auto p = yokov[i];
		ll yokoi = p.second;
		ll tmp = p.first + ma;
		if (is.count(P{tatei, yokoi}))
			tmp = max(0ll, tmp-1);
		res = max(res, tmp);
	}
	
	std::cout << res << std::endl;
	return 0;
}









Measured memory_bytes: 81076
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int n;
  cin >> n;
  int use = (n + 1000 - 1) / 1000;
  cout << 1000 * use - n << endl;
  return 0;
}

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

using namespace std;

#define ll long long
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl '\n'
#define Endl '\n'
#define cont continue
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a*b/__gcd(a,b)
#define pb push_back
#define mp make_pair
#define mem(x) memset(x, 0, sizeof(x))

const ll inf=1e18;
const int mod=1e9+7;
inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}
const int mxn = 2e5+10;

int main(){
    fast;

    int tt = 1;
    //cin>>tt;
    for(int tc = 1; tc <= tt; tc++) {
        int n;
        cin>>n;
        for(int i = 1; i < 10; i++) {
			if((n % i==0) && (n/i) < 10) {
				cout<<"Yes\n";
				return 0;
			}
		}
		cout<<"No\n";
        
        
    }



return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,a,sum=0;
    cin>>n;
    std::deque<int> deq;
    for (int i=0;i<n;i++) {
        cin>>a;
        deq.emplace_back(a);
        sum+=a;
    }
    int another=0,min_abs=100000;
    for (int j=0;j<n-1;j++) {
        another+=deq[j];
        sum-=deq[j];
        if (abs(another-sum)<min_abs) {
            min_abs=abs(another-sum);
        }
    }
    cout<<min_abs<<endl;
}


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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

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

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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(void){
    int A,B,C; cin >> A >> B >> C;
    cout << min(B/A,C) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int data[102][102];

void DFS(int x,int y,int gx,int gy,bool &Flag,int color){
  if((data[y][x]!=color)||(Flag==true))
    return;
  if((x==gx)&&(y==gy)){
    Flag=true;
    return;
  }
  data[y][x]=0;
  DFS(x,y+1,gx,gy,Flag,color);
  DFS(x,y-1,gx,gy,Flag,color);
  DFS(x+1,y,gx,gy,Flag,color);
  DFS(x-1,y,gx,gy,Flag,color);
}


int main(){
  int w,h;
  int sx,sy;
  int gx,gy;
  while(1){
    cin>>w>>h;
    if(!w&&!h)
      break;
    for(int i=0;i<102;i++){
      for(int j=0;j<102;j++){
        data[i][j]=0;
      }
    }
    cin>>sx>>sy;
    cin>>gx>>gy;
    int n;
    cin>>n;
    int c,d,x,y;
    for(int i=0;i<n;i++){
      cin>>c>>d>>x>>y;
      if(d){
        for(int j=0;j<4;j++){
          for(int z=0;z<2;z++){
            data[j+y][z+x]=c;
          }
        }
      }else if(!d){
        for(int j=0;j<2;j++){
          for(int z=0;z<4;z++){
            data[j+y][z+x]=c;
          }
        }
      }
      /*
      for(int j=0;j<h+1;j++){
        for(int z=0;z<w+1;z++){
          cout<<data[j][z];
        }
        cout<<endl;
      }*/
    }
    bool Flag=false;
    int color=data[sy][sx];
    if(color!=0)
      DFS(sx,sy,gx,gy,Flag,color);
    if (Flag){
      cout<<"OK"<<endl;
    }else if(!Flag){
      cout<<"NG"<<endl;
    }
  }
  return 0;

}



Measured memory_bytes: 3108
n = int(input())
p = list(map(int, input().split(' ')))
#print(n)
#print(p)

count = 0
A = [0 for i in range(3)]
for i in range(1, n - 1):
    A[0], A[1], A[2] = p[i - 1], p[i], p[i + 1]
    A.sort()
    if A[1] == p[i]:
        count += 1
print(count)

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

using LL = long long;

struct Person {LL A=0, B=0, C=0;};

int main() {
  int X, Y, Z;
  cin >> X >> Y >> Z;
  vector<Person> P(X+Y+Z);
  for(auto& i: P) cin >> i.A >> i.B >> i.C;

  sort(begin(P), end(P), [](auto l, auto r) {return l.A-l.B < r.A-r.B;});

  auto lc = [](auto l, auto r) {
    auto ld = l.B - l.C;
    auto rd = r.B - r.C;
    if(ld != rd) return ld > rd;
    return l.C < r.C;
  };
  auto rc = [](auto l, auto r) {
    auto ld = l.A - l.C;
    auto rd = r.A - r.C;
    if(ld != rd) return ld > rd;
    return l.C < r.C;
  };
  priority_queue<Person, vector<Person>, function<bool(Person, Person)>> lq(lc), rq(rc);

  vector<Person> left(X+Y+Z);
  for(auto i = 0; i < Y; ++i) left[Y-1].B += P[i].B;
  for(auto i = 0; i < Y; ++i) lq.emplace(P[i]);
  for(auto K = Y; K < Y+Z; ++K) {
    left[K].B = left[K-1].B + P[K].B;
    left[K].C = left[K-1].C;
    lq.emplace(P[K]);
    left[K].B -= lq.top().B;
    left[K].C += lq.top().C;
    lq.pop();
  }

  vector<Person> right(X+Y+Z+1);
  for(auto i = Y+Z; i < X+Y+Z; ++i) right[Y+Z].A += P[i].A;
  for(auto i = Y+Z; i < X+Y+Z; ++i) rq.emplace(P[i]);
  for(auto K = Y+Z-1; Y <= K; --K) {
    right[K].A = right[K+1].A + P[K].A;
    right[K].C = right[K+1].C;
    rq.emplace(P[K]);
    right[K].A -= rq.top().A;
    right[K].C += rq.top().C;
    rq.pop();
  }

  LL res = 0;
  for(auto K = Y-1; K < Y+Z; ++K) res = max(res, left[K].B+left[K].C + right[K+1].A+right[K+1].C);
  cout << res << endl;
}


Measured memory_bytes: 10868
#include <stdio.h>

int main(){
  int N, i, j, a[100]={0};
  int suma=0, sumb=0;
  int d;
  scanf("%d", &N);
  for(i=0; i < N; i++){
    scanf("%d",&a[i]);
  }
  
  for(j = N-1; j>0; j--){
  	for(i=0; i < j; i++){
		if(a[i] < a[i+1]){
      	d = a[i];
      	a[i] = a[i+1];
      	a[i+1] = d;
        }
    }
  }
  
  for(i=0; i<=(N/2); i++){
    suma = suma + a[2*i];
    sumb = sumb + a[2*i+1];
  }
  
  printf("%d", suma-sumb);
return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<string>
#include<cstring>
#include<time.h>
#include<array>
#include<iomanip>
#include<list>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<bitset>
#include <queue>
#include <map>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;


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


#define PRI(s) cout << s << endl
#define PRIY PRI("Yes")
#define PRIN PRI("No")

int ctoi(char c) {
	switch (c)
	{
	case '0': return 0;
	case '1': return 1;
	case '2': return 2;
	case '3': return 3;
	case '4': return 4;
	case '5': return 5;
	case '6': return 6;
	case '7': return 7;
	case '8': return 8;
	case '9': return 9;
	default:
		cout << "ERR_ctoi" << endl;
		return -1;
	}
}
int main() {
	string s;
	cin >> s;
	if (s[5] == '1')PRI("TBD");
	else if (ctoi(s[6]) >= 5) PRI("TBD");
	else PRI("Heisei");
	return 0;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    int N, K;
    cin >> N >> K;
    string S;
    cin >> S;

    int cnt = 0;
    rep2(i, 1, N) {
        if (S[i] == S[i - 1]) cnt++;
    }

    cout << min(N - 1, 2 * K + cnt) << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 512
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <regex>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
using ll = long long;
using VL=vector<ll>;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
const long long INF =  999999999;

int H,W,a[85][85],b[85][85];
bool dp[82][82][30000];

int main(){
  cin>>H>>W;
  FOR(i,1,H+1){
    FOR(j,1,W+1){
      cin>>a[i][j];
    }
  }
  FOR(i,1,H+1){
    FOR(j,1,W+1){
      cin>>b[i][j];
    }
  }

    dp[1][0][0]=true;
    dp[0][1][0]=true;


  FOR(i,1,H+1){
    FOR(j,1,W+1){
      REP(k,13000){
        dp[i][j][k]=false;
      }
    }
  }
  FOR(i,1,H+1){
    FOR(j,1,W+1){
      REP(k,13000){
        if(dp[i-1][j][k]){
          dp[i][j][k+abs(a[i][j]-b[i][j])]=true;
          dp[i][j][abs(k-abs(a[i][j]-b[i][j]))]=true;
        }
        if(dp[i][j-1][k]){
            dp[i][j][k+abs(a[i][j]-b[i][j])]=true;
            dp[i][j][abs(k-abs(a[i][j]-b[i][j]))]=true;
        }
      }
    }
  }
  int ans=0;
  REP(i,13000){
    if(dp[H][W][i]){
      ans=i;
      break;
    }
  }
  cout<<ans<<endl;
}


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

#define rep(i,n) for(int i = 0;i < n;++i)
#define rep2(i,n,m) for(int i = n;i < m;++i)
#define all(v) v.begin(),v.end()
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; }

const int INF = 1001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll n,w;
    cin >> n >> w;
    vector<vector<ll>> dp(n+1,vector<ll> (w+1));
    vector<ll> value(n);
    vector<ll> weight(n);

    rep(i,n){
        cin >> weight.at(i) >> value.at(i);
    }
    rep(i,n){
        for(int j = 0;j <= w;++j){
            if(j - weight.at(i) >= 0){
                chmax(dp[i+1][j],dp[i][j-weight[i]]+value[i]);
            }
            chmax(dp[i+1][j],dp[i][j]);
        }
    }
    cout << dp[n][w] << endl;

    cout << endl;
    return 0;
}

Measured memory_bytes: 80256
def era(num):
    input_list = [False if i % 2 == 0 or i % 3 == 0 or i % 5 == 0 else True for i in range(num)]
    input_list[0] = input_list[1] = False
    input_list[2] = input_list[3] = input_list[5] = True
    sqrt = num**0.5

    for serial in range(3, num, 2):

        if serial >= sqrt:
            return input_list

        for s in range(serial ** 2, num, serial): 
            input_list[s] = False

N=int(input())
if N<25:
    Prime=[2,3,5]
else:
    input_list=era(int(N**0.5)+1)
    Prime=[i for i, b in enumerate(input_list) if b == True]

Fac={}
for p in Prime:
    while N%p==0:
        N//=p
        if p in Fac:
            Fac[p]+=1
        else:
            Fac[p]=1
    if N==1:
        break
if N!=1:
    Fac[N]=1
ans=0

for k in Fac:
    nec=1
    while True:
        if Fac[k]>=nec:
            ans+=1
            Fac[k]-=nec
            nec+=1
        else:
            break

print(ans)

Measured memory_bytes: 20280
#include <bits/stdc++.h>
using namespace std;
typedef  long long int ll;
typedef pair<ll, ll> pll;
#define pb push_back
typedef long double ld;
#define fi first
#define se second
#define mp make_pair
ll inf=1e18;
ll p= 998244353;
ll phi(ll n) {
    ll result = n;
    for (ll i = 2; i * i <= n; i++) {
        if(n % i == 0) {
            while(n % i == 0)
                n /= i;
            result -= result / i;
        }
    }
    if(n > 1)
        result -= result / n;
    return result;
}
ll power(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
   while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
ll modInverse(ll n, ll p)
{
    return power(n, p-2, p);
}
int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll i,j,y,k,z,w,g,m,t,n,a,b;
	ll t2,t3,t4,t1;
	    string s;
	    cin>>n>>k;
	    ll arr[n];
	    for(i=0;i<n;i++)
	    cin>>arr[i];
	    sort(arr,arr+n);
	    ll ans=0;
	    for(i=0;i<k;i++)
	    ans+=arr[i];
	    cout<<ans;
	     
	 return 0;
	 
           
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e5 + 100;
const int MOD = 1000000007;

void doc() {
    freopen("OB.inp","r",stdin);
    freopen("OB.out","w",stdout);
    ///cerr << "OK" << '\n';
}

int res = 0;

void Merge(vector<int> &A, int l, int m, int r){
    //cout << l << " " << r << '\n';
    int n1 = m - l + 1;
    int n2 = r - m;
    int x[n1], y[n2];
    for(int i = 0; i < n1; i++) x[i] = A[i + l];
    for(int i = 0; i < n2; i++) y[i] = A[i + m + 1];
    int i = 0, j = 0, k = l;
    while (i < n1 && j < n2){
        if (x[i] <= y[j]){
            A[k++] = x[i++];
            res++;
        }
        else{
            res++;
            A[k++] = y[j++];
        }
    }
    while (i < n1) {
        A[k++] = x[i++];
        res++;
    }
    while (j < n2) {
        A[k++] = y[j++];
        res++;
    }

}

void mergeSort(vector<int> &A, int l, int r){
    if (l >= r) return;
    int m = (l + r) >> 1;
    //cout << l << " " << r << '\n';
    mergeSort(A, l, m);
    mergeSort(A, m + 1, r);
    //cerr << l << " " << r << endl;
    Merge(A, l, m, r);
}

void solve() {
    int n;
    cin >> n;
    //int a[n];
    vector<int> a;
    for(int i = 0; i < n; i++)
        //cin >> a[i];
    {
        int x;
        cin >> x;
        a.push_back(x);
    }
    mergeSort(a, 0, n - 1);
    for(int i = 0; i < n-1; i++) printf("%d ",a[i]);
	printf("%d\n",a[n-1]);
	printf("%d\n",res);
}
int main(){
    //ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr);
    //doc();
    solve();
}




Measured memory_bytes: 6804
#include <stdio.h>
#include <stdlib.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define INF ((1LL<<62)-(1LL<<31))



//辺の情報を個別に持つタイプ
typedef struct edge{ll s,g,c;}E;
typedef struct graph{
	int vcnt,ecnt;
	E  e[500010];//適宜変える
	int id[100010];//適宜変える
}G;

int esort(const void*a,const void*b){
	E*p=(E*)a,*q=(E*)b;
	if((*p).s<(*q).s)return -1;
	if((*p).s>(*q).s)return  1;
	if((*p).g<(*q).g)return -1;
	return 1;
}
int csort(const void*a,const void*b){
	ll p=(*(E*)a).c,q=(*(E*)b).c;
	return p<q?-1:p>q?1:0;
}

G g;
void readgraph(){
	//適宜変える
	ll n;
	ll m=0;
	scanf("%lld",&n);
	rep(i,0,n){
		int s,k;
		scanf("%d%d",&s,&k);
		while(k--){
			int t,c;
			scanf("%d%d",&t,&c);
			g.e[m].s=s;
			g.e[m].g=t;
			g.e[m].c=c;
			m++;
		}
	}
	g.vcnt=n;
	g.ecnt=m;
	qsort(g.e,g.ecnt,sizeof(E),esort);
//	qsort(g.e,g.ecnt,sizeof(E),csort);

	int p=0;
	rep(i,0,g.vcnt){
		while(p<g.ecnt&&g.e[p].s<i)p++;
		g.id[i]=p;
	}
	g.id[g.vcnt]=g.ecnt;//番兵
}


//プラキュー（二分ヒープ）（優先度変更ありバージョン）
ll heapN,heap[1<<20],heapinv[1<<20];
int PQhikaku(int i,int j);//jの方が優先度が高いならtrueを返す
void PQchange(int n);
void heap_utod(int n){
	if(2*n>heapN)return;
	int rflag=(2*n+1<=heapN)&&(PQhikaku(2*n,2*n+1));
	if(PQhikaku(n,2*n+rflag)){
		ll temp=heap[2*n+rflag];
		heap[2*n+rflag]=heap[n];
		heap[n]=temp;
		heapinv[heap[n]]=n;
		heapinv[heap[2*n+rflag]]=2*n+rflag;	
		heap_utod(2*n+rflag);
	}
}
void heap_dtou(int n){
	if(n==1||PQhikaku(n,n/2))return;
	ll temp=heap[n];
	heap[n]=heap[n/2];
	heap[n/2]=temp;
	heapinv[heap[n]]=n;
	heapinv[heap[n/2]]=n/2;
	heap_dtou(n/2);
}
ll PQpop(){
	ll rr=heap[1];
	heapinv[heap[1]]=0;
	heap[1]=heap[heapN--];
	heapinv[heap[1]]=1;
	heap_utod(1);
	return rr;
}
void PQpush(ll n){
	heap[++heapN]=n;
	heapinv[heap[heapN]]=heapN;
	heap_dtou(heapN);
}


//早い方のダイクストラ
//グラフと始点を引いて各点への最短距離・最短経路を返す
//プラキューが必要
//O((E+V)logV)
ll daikusutorappp[1<<21];
void daikusutora2(ll s){
	rep(i,0,g.vcnt)daikusutorappp[i]=i==s?0:INF;
	rep(i,0,g.vcnt)PQpush(i);
	while(heapN){
		ll mv=PQpop();
		for(ll t=g.id[mv];g.e[t].s==mv;t++){
			if(daikusutorappp[g.e[t].g]>daikusutorappp[mv]+g.e[t].c){
				daikusutorappp[g.e[t].g]=daikusutorappp[mv]+g.e[t].c;
				//daikusutorappp[n+g.e[t].g]=mv;//最短経路がいる場合はこれ
				PQchange(g.e[t].g);
			}
		}
	}
}
int PQhikaku(int i,int j){return daikusutorappp[heap[i]]>daikusutorappp[heap[j]];}
void PQchange(int n){if(heapinv[n])heap_dtou(heapinv[n]);}



int main(){
	readgraph();
	daikusutora2(0);
	rep(i,0,g.vcnt)printf("%d %d\n",i,daikusutorappp[i]);
}


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

int main(){
  int r,d,x;cin>>r>>d>>x;
  for(int i=0;i<10;i++){
    cout << r * x - d << endl;
    x = r * x - d;
  }
  return 0;
}


Measured memory_bytes: 256
n=int(input())
d=list(map(int,input().split()))
m=int(input())
t=list(map(int,input().split()))
import collections
d=collections.Counter(d)
t=collections.Counter(t)
for i in t.items():
  if i[0] not in d:
    print("NO")
    break
  elif i[0] in d and i[1]>d[i[0]]:
    print("NO")
    break
else:
  print("YES")


Measured memory_bytes: 55392
#import<bits/stdc++.h>
#define elif else if
#define sorted(vector) sort(vector.begin(),vector.end())
using namespace std;


int a,b,c;
string s,t,r;

int main(void){
    cin>>a>>b>>c;
    vector<int> d;
    d={a,b,c};
    sorted(d);
    cout<<d[0]+d[1];
}


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

int main() {
  int N;
  cin >> N;//7777
  int a,b,c,d,x,y,z;  
  a = N / 1000;//7
  x = a * 1000;//7000
    b = (N - x)/*777*/ / 100;//7
  y = b * 100;//700
    c = (N - x  - y)/*77*//10;//7
  z = c * 10;//70
    d = (N - x - y - z);//7
    if(a == b && b == c || b == c && c == d) {
      cout << "Yes" << endl;
    }
  else {
  cout << "No" << endl;
  }
}

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

int gcd(int a, int b){
  return (b>0)? gcd(b,a%b) : a ;
}
int lcm(int a, int b){
  return (a/gcd(a, b)*b);
}

int main(){
  int a, b;
	
  while(cin>>a>>b){
    cout<<gcd(a,b)<<" "<<lcm(a,b)<<endl;
  }
}

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

ll power(ll x,ll y)
{
    ll ml=1;
    while(y>0)
    {
        if(y&1)
        {
            ml=(ml*x)%mod;
        }
        x=(x*x)%mod;
        y/=2;
    }
    return ml;
}
int main() 
{
    ll n;
    cin>>n;
    if(n==1)
    {
        cout<<0;
    }
    else if(n==2)
    {
        cout<<2;
    }
    else
    {
        cout<<(power(10,n)+mod-power(9,n)+mod-power(9,n)+mod+power(8,n))%mod;
    }
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define MOD 1e9+7

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

    long long h,w,mn,smx,smn;

    cin >> h >> w;

    if(h%3==0 or w%3==0){ cout << "0"; return 0; }

    mn = min(h,w);

    for(int i = 1;i < h;i++)
    {
        smx = INT_MIN; smn = INT_MAX;
        long long ar = w/2*(h-i);
        smx = max(ar,max((h-i)*w-ar,i*w));
        smn = min(ar,min((h-i)*w-ar,i*w));
        mn = min(mn,smx-smn);
    }

    for(int i = 1;i < w;i++)
    {
        smx = INT_MIN; smn = INT_MAX;
        long long ar = h/2*(w-i);
        smx = max(ar,max((w-i)*h-ar,i*h));
        smn = min(ar,min((w-i)*h-ar,i*h));
        mn = min(mn,smx-smn);
    }

    cout << mn;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pq priority_queue
using namespace std;
const ll INF=(ll)1e9;
const ll MOD=(ll)1e9+7;
const ll MAX=510000;
vector<int> dx={1,0,-1,0},dy={0,1,0,-1};
template<class T> inline bool chmax(T& a, T b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a>b) { a=b; return 1; } return 0; }

int main(){
    string S;
    ll K;
    cin>>S>>K;
    for(ll i=0;i<S.size();i++){
        int cnt=(26-S[i]+'a')%26;
        if(K>=cnt){
            S[i]='a';
            K-=cnt;
        }
    }
    K%=26;
    if(K>0){
        int cnt=S[S.size()-1]-'a';
        S[S.size()-1]='a'+(cnt+K)%26;
    }
    cout<<S<<endl;
}

Measured memory_bytes: 512
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::iter::FromIterator;
// input macro
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
 
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
 
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
 
    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        _n: usize,
        k: usize,
        mut s: chars,
    }
    s[k-1] = s[k-1].clone().to_lowercase().collect::<Vec<_>>()[0];
    println!("{}", s.into_iter().collect::<String>());
}


Measured memory_bytes: 4352
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef complex<double> P;
static const double EPS = 1e-8;

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

bool brank[4][4];
int solve(int n,vector<PII>& p){
  if(n==8) return 1;
  int res = 0;
  REP(y,4)REP(x,4){
    bool findempty = false;
    if(!brank[y][x]){
      findempty = true;
      brank[y][x] = true;
      REP(i,4){
        int nx = x + p[i].first;
        int ny = y + p[i].second;
        if(0<=nx&&nx<4&&0<=ny&&ny<4&&!brank[ny][nx]){
          brank[ny][nx] = true;
          res += solve(n+1,p);
          brank[ny][nx] = false;
        }
      }
      brank[y][x] = false;
    }
    if(findempty) goto END;
  }
END:
  return res;
}
int main(void){
  int x,y;
  while(cin>>x>>y){
    if(x>4) break;
    vector<PII> data;
    data.push_back(PII(x,y));
    REP(i,3){
      cin>>x>>y;
      data.push_back(PII(x,y));
    }
    memset(brank,0,sizeof(brank));
    cout<<solve(0,data)<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define res register int
#define ll long long
#define N 100000
#define inf 0x3f3f3f3f
using namespace std;
ll a,b,c;
int main()
{
	scanf("%lld%lld%lld",&a,&b,&c);
	if(a%2==0||b%2==0||c%2==0)
	printf("0\n");
	else 
	printf("%lld\n",min(a*b,min(b*c,a*c)));
}


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

int n;

int main() {
  cin >> n;
  int ans = 1000 - n % 1000;
  if (ans == 1000) ans = 0;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3632
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

template <typename Monoid>
struct RMQ {
  RMQ(int sz, const Monoid UNITY) : UNITY(UNITY) {
    init(sz);
    dat.assign((n << 1) - 1, UNITY);
  }

  RMQ(const vector<Monoid> &a, const Monoid UNITY) : UNITY(UNITY) {
    int a_sz = a.size();
    init(a_sz);
    dat.resize((n << 1) - 1);
    REP(i, a_sz) dat[n - 1 + i] = a[i];
    for (int i = n - 2; i >= 0; --i) dat[i] = max(dat[(i << 1) + 1], dat[(i << 1) + 2]);
  }

  void update(int node, Monoid val) {
    node += n - 1;
    dat[node] = val;
    while (node > 0) {
      node = (node - 1) >> 1;
      dat[node] = max(dat[(node << 1) + 1], dat[(node << 1) + 2]);
    }
  }

  Monoid query(int a, int b) const { return query(a, b, 0, 0, n); }

  int find(int a, int b, Monoid val) const { return find(a, b, val, 0, 0, n); }

  Monoid operator[](const int idx) const { return dat[idx + n - 1]; }

private:
  int n = 1;
  const Monoid UNITY;
  vector<Monoid> dat;

  void init(int sz) { while (n < sz) n <<= 1; }

  Monoid query(int a, int b, int node, int left, int right) const {
    if (right <= a || b <= left) return UNITY;
    if (a <= left && right <= b) return dat[node];
    return max(query(a, b, (node << 1) + 1, left, (left + right) >> 1), query(a, b, (node << 1) + 2, (left + right) >> 1, right));
  }

  int find(int a, int b, Monoid val, int node, int left, int right) const {
    if (dat[node] < val || right <= a || b <= left) return -1;
    if (right - left == 1) return node - (n - 1);
    int res_l = find(a, b, val, (node << 1) + 1, left, (left + right) >> 1);
    return res_l == -1 ? find(a, b, val, (node << 1) + 2, (left + right) >> 1, right) : res_l;
    // int res_r = find(a, b, val, (node << 1) + 2, (left + right) >> 1, right);
    // return res_r == -1 ? find(a, b, val, (node << 1) + 1, left, (left + right) >> 1) : res_r;
  }
};

int main() {
  int h, w, m; cin >> h >> w >> m;
  vector<vector<int>> y(w);
  RMQ<int> rmq(h, 0);
  while (m--) {
    int hi, wi; cin >> hi >> wi; --hi; --wi;
    y[wi].emplace_back(hi);
    rmq.update(hi, rmq[hi] + 1);
  }
  // REP(i, h) cout << rmq[i] << " \n"[i + 1 == h];
  int ans = 0;
  REP(j, w) {
    for (int e : y[j]) rmq.update(e, rmq[e] - 1);
    chmax(ans, rmq.query(0, h) + y[j].size());
    for (int e : y[j]) rmq.update(e, rmq[e] + 1);
  }
  cout << ans << '\n';
  return 0;
}


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

int main(){ 
    int a,b;
    cin>>a>>b;
    int c=0;
    for(int i=a;i<b+1;i++){
        if((i%10==i/10000)&&((i/1000)%10==(i%100)/10)){
        c++;
        }
    }
    cout<<c;
    return 0;
}


Measured memory_bytes: 256