akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		
		System.out.println((n + (2 * d + 1) - 1) / (2 * d + 1));
		

		
		

		
		
	}	

}

Measured memory_bytes: 21844
#include<iostream>

using namespace std;

int main(){
  int a,b;
  cin >> a >> b;
  if(a < b){
    for(int i = 0;i < b;i++){
      cout << a;
    }
  }else{
    for(int i = 0;i < a;i++){
      cout << b;
    }
  }cout << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap
    


@mt
def slv(N, Q, S, TD):
    def reachable(i):
        if i < 0:
            return -1
        elif i >= N:
            return 1
        for t, d in TD:
            if S[i] == t:
                if d == 'L':
                    i -= 1
                else:
                    i += 1
            if i == -1:
                return -1
            elif i == N:
                return 1
        return 0
    ans = N
    lo = 0
    hi = N
    while lo < hi:
        mid = (lo+hi)//2
        if reachable(mid) < 0: lo = mid+1
        else: hi = mid
    ans -= lo


    lo = 0
    hi = N
    while lo < hi:
        mid = (lo+hi)//2
        if 0 < reachable(mid): hi = mid
        else: lo = mid+1
    ans -= N - lo
    return ans



def main():
    N, Q = read_int_n()
    S = read_str()
    TD = [read_str_n() for _ in range(Q)]
    print(slv(N, Q, S, TD))



if __name__ == '__main__':
    main()


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

using namespace std;

#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define sz(a) static_cast<int>((a).size())
#define pb emplace_back
#define mp make_pair
#define endl '\n'
#define f first
#define s second

#ifdef SEREZHKA
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#endif

template<typename T>
void _dbg(const char* _s, T _h) { cerr << _s << " = " << _h << "\n"; }

template<typename T, typename... Ts>
void _dbg(const char*_s, T _h, Ts... _t) {
    int _b = 0;
    
    while (((_b += *_s == '(') -= *_s == ')') != 0 || *_s != ',')
        cerr << *_s++;
    
    cerr << " = " << _h << ",";
    _dbg(_s + 1, _t...);
}

using ll = long long;

const ll INF = static_cast<ll>(1e9) + 7ll;
const ll LINF = INF * INF;
const int MAXN = static_cast<int>(1e6) + 17;

int n, m, k;
pair<int, int> p[MAXN];
map<int, set<int> > M;
ll ans[10];

bool read() {
    if (!(cin >> n >> m >> k))
        return false;

    forn (i, k)
        cin >> p[i].f >> p[i].s;

    return true;
}

void solve() {
    forn (i, k)
        M[p[i].f].insert(p[i].s);

    ans[0] = (n - 2ll) * (m - 2ll);
    set< pair<int, int> > cons;

    forn (i, k)
        for (int sx = max(1, p[i].f - 2); sx <= p[i].f; ++sx)
            for (int sy = max(1, p[i].s - 2); sy <= p[i].s; ++sy)
                if (sx + 2 <= n && sy + 2 <= m && !cons.count(mp(sx, sy))) {
                    int cur = 0;
                    cons.insert(mp(sx, sy));

                    for (int x = sx; x < sx + 3; ++x)
                        for (int y = sy; y < sy + 3; ++y)
                            if (M[x].count(y)) {
                                --ans[cur++];
                                ++ans[cur];
                            }
                }

    forn (i, 10)
        cout << ans[i] << endl;
}

int main() {
    cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    
    while (read())
        solve();
    
    return 0;
}



Measured memory_bytes: 94848
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 1
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	r1 := getNextInt(scanner)
	c1 := getNextInt(scanner)
	r2 := getNextInt(scanner)
	c2 := getNextInt(scanner)

	cm := Com{}
	cm.init(int(1e6+1) * 2)
	var ans int64

	ans = cm.calc(r2+c2+2, r2+1) + cm.calc(r1+c1, r1) - cm.calc(r2+1+c1, c1) - cm.calc(r1+1+c2, r1)
	ans %= cm.mod
	if ans < 0 {
		ans += cm.mod
	}

	fmt.Fprintln(writer, ans)
}

// Com ...
type Com struct {
	facs, invs []int64
	mod        int64
}

func (cm *Com) init(n int) {
	cm.facs = make([]int64, n+1)
	cm.invs = make([]int64, n+1)

	cm.facs[0] = 1
	cm.mod = int64(1e9 + 7)
	for i := 1; i <= n; i++ {
		cm.facs[i] = (cm.facs[i-1] * int64(i)) % cm.mod
	}
	cm.invs[n] = cm.inv(cm.facs[n])
	for i := n - 1; i >= 0; i-- {
		cm.invs[i] = cm.invs[i+1] * int64(i+1) % cm.mod
	}
}

func (cm *Com) inv(n int64) int64 {
	var ii [32]int64
	ii[0] = n
	for i := 1; i < 31; i++ {
		ii[i] = (ii[i-1] * ii[i-1]) % cm.mod
	}
	var ans int64
	ans = 1
	m := cm.mod - 2
	for i := 30; i >= 0; i-- {
		for m >= 1<<uint(i) {
			ans = (ans * ii[i]) % cm.mod
			m -= 1 << uint(i)
		}
	}

	return ans
}

func (cm *Com) calc(n, k int) int64 {
	ans := cm.facs[n] * cm.invs[k]
	ans %= cm.mod
	ans = ans * cm.invs[n-k]
	ans %= cm.mod
	return ans
}


Measured memory_bytes: 32896
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i,l,r) for(i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define P pair<ll,ll>
#define F first
#define S second
signed main(){
  char N;cin>>N;
  if('A'<=N&&N<='Z')cout<<"A"<<endl;
  else cout<<"a"<<endl;
  return 0;
}

Measured memory_bytes: 3600
#include <stdio.h>
void BubbleSort(int);
void SelectionSort(int);
 int n, c1[36], c2[36];
    char s1[36], s2[36];
int main(void){
   
   int i, flag = 0;
   char c;
    scanf("%d",&n);
    for (i = 0; i < n; i++){
         scanf("%c",&c);
        scanf("%c",&s1[i]);
        scanf("%d",&c1[i]);
        s2[i] = s1[i];
        c2[i] = c1[i];
    }
   
    BubbleSort(n);
    printf("Stable\n");
    SelectionSort(n);
    for(i=0;i<n;i++){
        if(s1[i] != s2[i]){
            flag = 1;
            break;
        }
     }
     if(flag == 1){
         printf("Not stable\n");
     }
     else printf("Stable\n");
    return 0;
}

void BubbleSort (int N){
    int i, j,tmp;
    char tmpc;
    for(i = 0; i < N-1; i++){
        for(j = N-1; j >= i+1; j--){
            if(c1[j] < c1[j-1]){
                tmp = c1[j];
                c1[j] = c1[j-1];
                c1[j-1] = tmp;
                tmpc = s1[j];
                s1[j] = s1[j-1];
                s1[j-1] = tmpc;
            }
        }
    }
    for(i = 0; i < n-1; i++){
    printf("%c%d ",s1[i],c1[i]);
    }
    printf("%c%d\n",s1[i],c1[i]);
}

void SelectionSort(int N){
    int i, minj,tmp,j;
    char tmpc;
    for(i = 0; i < N; i++){
        minj = i;
        for(j = i; j < N; j++){
            if(c2[j] < c2[minj]){
                minj = j;
            }
        }
                tmp = c2[i];
                c2[i] = c2[minj];
                c2[minj] = tmp;
                tmpc = s2[i];
                s2[i] = s2[minj];
                s2[minj] = tmpc;
            
        
    }
    for(i = 0; i < n-1; i++){
    printf("%c%d ",s2[i],c2[i]);
    }
    printf("%c%d\n",s2[i],c2[i]);
}

Measured memory_bytes: 608
#include<bits/stdc++.h>
using namespace std;
  int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
 
int n;
cin>>n;
 
vector<vector<int>>v(n, vector<int>(3));
 
for(int i=0;i<n;i++){
	int a,b,c;
	cin>>a>>b>>c;
   v[i][0]=a;
   v[i][1]=b;
   v[i][2]=c;
}
 
    vector<vector<int>> dp(n, vector<int>(3));
     dp[0][0]= v[0][0];
     dp[0][1]= v[0][1];
     dp[0][2]= v[0][2];
    
    for(int i=1;i<n;i++){
      dp[i][0] = max( dp[i-1][1] , dp[i-1][2] ) + v[i][0] ;
      dp[i][1] = max( dp[i-1][0] , dp[i-1][2] ) + v[i][1] ;
      dp[i][2] = max( dp[i-1][0] , dp[i-1][1] ) + v[i][2] ;
    }
                           
   cout<< max(dp[n-1][0] , max(dp[n-1][1],dp[n-1][2]) ); 
}
  
  

Measured memory_bytes: 11264
#include <iostream>

#define NIL -1
using namespace std;

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

    int H, W;
    cin >> H >> W;

    string S[50];
    for (int i = 0; i < H; ++i) {
        cin >> S[i];
    }

    int S_int[50][50] = {0};
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            int dx[3] = {-1, 0, 1};
            int dy[3] = {-1, 0, 1};

            for (int k = 0; k < 3; ++k) {
                for (int l = 0; l < 3; ++l) {
                    int ny = i + dy[k];
                    int nx = j + dy[l];

                    if (S[i][j] == '#') {
                        if (0 <= ny && ny < H && 0 <= nx && nx < W && S[ny][nx] != '#') {
                            S_int[ny][nx]++;
                        }
                    }
                }
            }
        }
    }

    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            if(S[i][j] == '#'){
                cout << "#";
            }else{
                cout << S_int[i][j];
            }
        }
        cout << endl;
    }

}


Measured memory_bytes: 256
import math

def primeCheck(n):
	if n == 2:
		return True
	else:
		mx = math.ceil(n ** 0.5)
		for i in range(2, mx + 1):
			if n % i == 0:
				return False
				break
			elif i == mx:
				return True

x = int(input())

for i in range(x, 10**6):
	if primeCheck(i):
		print(i)
		break

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int ufr[225816],ufp[225816];
ll cnt[225816][2];

void ufinit(int n){
	int i;
	for(i=0; i<n; ++i){
		ufp[i] = i;
		ufr[i] = 1;
	}
}

int ufind(int x){
	if(x == ufp[x]){
		return ufp[x];
	}
	ufp[x] = ufind(ufp[x]);
	return ufp[x];
}

void unionf(int x, int y){
	x = ufind(x);
	y = ufind(y);
	if(x==y){
		return;
	}else if(ufr[x]<ufr[y]){
		swap(x,y);
	}
	ufp[y] = x;
	ufr[x] += ufr[y];
}

int main(void){
	int n,i,x,y,p;
	ll ans=0ll;
	ufinit(200000);
	cin >> n;
	for(i=0; i<n; ++i){
		cin >> x >> y;
		--x; --y;
		unionf(x,100000+y);
	}
	for(i=0; i<200000; ++i){
		++cnt[ufind(i)][i/100000];
	}
	ans -= n;
	for(i=0; i<200000; ++i){
		ans += cnt[i][0]*cnt[i][1];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 5376
#include<bits/stdc++.h>
using namespace std;
int main(void){
    int flg[5];
    fill(flg, flg + 5, 0);
    for(int i = 0; i < 3; i++){
        int a, b;
        cin >> a >> b;
        flg[a]++; flg[b]++;
    }
    int f = 1;
    for(int i = 1; i <= 4; i++)
        if(flg[i] < 1 || flg[i] > 2) f = 0;
    if(f) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <tuple>
#include <iomanip>
#include <queue>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> pa;
const ll MOD = 1e9 + 7;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (int i = (l); i < (r); i++)
#define reper(i, l, r) for (int i = (r)-1; i >= (l); i--)

void init() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
}
//-----------------------------------------------------------//

int main() {
    init();
    int N,H,W;
    cin>>N>>H>>W;
    int ans=0;
    rep(i,N){
    	int h,w;
    	cin>>h>>w;
    	if(h>=H&&w>=W)ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
words = ['dream', 'dreamer', 'erase', 'eraser']
for i in range(len(words)) :
    words[i] = words[i][::-1]

S = input()[::-1]

ans = True

i = 0

while True :
    flag = False
    for w in words :
        if S[i:i + len(w)] == w :
            i += len(w)
            flag = True
            break
    if flag == False:
        ans = False
        break
    if i == len(S) :
        break

if ans :
    print('YES')
else :
    print('NO')


Measured memory_bytes: 3188
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		char[][] maze = new char[H][W];
		int[] dx = {1, 0, -1, 0};
		int[] dy = {0, 1, 0, -1};
		int[][] d = new int[H][W];
		int count = 0;

		for(int i = 0; i < H; i++) {
			for(int j = 0; j < W; j++) {
				d[i][j] = -1;
			}
			maze[i] = sc.next().toCharArray();
		}

		for(int i = 0; i < H; i++) {
			for(int j = 0; j < W; j++) if(maze[i][j] == '#') count++;
		}

		d[0][0] = 1;
		Queue<pair> que = new ArrayDeque<pair>();
		que.add(new pair(0, 0));

		while(!que.isEmpty()) {
			pair p = que.poll();
			if(p.x == (H-1) && p.y == (W-1)) break;
			for(int i = 0; i < 4; i++) {
				int cx = p.x + dx[i];
				int cy = p.y + dy[i];
				if(cx >= 0 && cx <= H-1 && cy >= 0 && cy <= W-1 && maze[cx][cy] == '.'  && d[cx][cy] == -1) {
					d[cx][cy] = d[p.x][p.y] + 1;
					que.add(new pair(cx, cy));
				}
			}
		}

		if(d[H-1][W-1] != -1) {
			System.out.println(H*W - count - d[H-1][W-1]);
		}else {
			System.out.println(-1);
		}
		sc.close();
	}

	private static class pair{
		int x; int y;
		pair(int x, int y){
			this.x = x; this.y = y;
		}
	}
}

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

int main(){
    int w, h;
    while(true){
        int i, j;
        cin >> h >> w;
        if(w==0 && h == 0) break;
        for(i=0; i<h; i++){
            for(j=0; j<w; j++){
                if((i+j)%2 == 0){
                    cout << "#";
                }else cout<<".";
            }
            cout << endl;
        }
        cout << endl;
    }
    
    return 0;
    
}


Measured memory_bytes: 3088
#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <iomanip>
#include <bitset>

using namespace std;

typedef long long ll;

mt19937 rnd(228);

const int N = 300 + 1;

int dp[N][N][N];

int main()
{
#ifdef ONPC
    freopen("a.in", "r", stdin);
#endif
    string s;
    cin >> s;
    int k;
    cin >> k;
    int n = (int) s.size();
    for (int len = 1; len <= n; len++)
    {
        for (int i = 0; i + len - 1 < n; i++)
        {
            int j = i + len - 1;
            for (int cur = 0; cur <= k; cur++)
            {
                if (len == 1)
                {
                    dp[i][j][cur] = 1;
                    continue;
                }
                if (cur - 1 >= 0)
                {
                    dp[i][j][cur] = max(dp[i][j][cur], dp[i][j][cur - 1]);
                }
                if (i + 1 < n)
                {
                    dp[i][j][cur] = max(dp[i][j][cur], dp[i + 1][j][cur]);
                }
                if (j - 1 >= 0)
                {
                    dp[i][j][cur] = max(dp[i][j][cur], dp[i][j - 1][cur]);
                }
                if (s[i] == s[j])
                {
                    dp[i][j][cur] = max(dp[i][j][cur], dp[i + 1][j - 1][cur] + 2);
                }
                else if (cur - 1 >= 0 && i + 1 < n && j - 1 >= 0)
                {
                    dp[i][j][cur] = max(dp[i][j][cur], dp[i + 1][j - 1][cur - 1] + 2);
                }
            }
        }
    }
    cout << dp[0][n - 1][k] << '\n';
}


Measured memory_bytes: 106752
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn mat_chars(&mut self, row: usize) -> Vec<Vec<char>> {
        (0..row).map(|_| self.chars()).collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let S: Vec<char> = sc.chars();
    let T: Vec<char> = sc.chars();
    let N = S.len();
    for i in 0..N {
        if S[i] != T[i] {
            println!("No");
            return;
        }
    }
    println!("Yes");
}


Measured memory_bytes: 2156
w, a, b = gets.strip.split.map(&:to_i)

result = 0
if (a + w) < b
    result = b - (a + w)
elsif a <= (b + w) && b <= (a + w) 
    result = 0
else (b + w) < a
    result = a - (b + w)
end

puts result


Measured memory_bytes: 3836
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(long long i=0;i<int(N);++i)
using ll = long long;
// const int INF = 2147483647;
const ll MOD = 1e9+7;
const ll INF = 1000000000000000000LL;
 
 
 int main() {
	 ll k,n;
	 cin >> k >> n;
	 vector<ll> a(n);
	 rep(i,n) cin >> a[i];
	 ll nax = -INF;
	 rep(i,n-1){
		 ll cur = a[i+1]-a[i];
		 nax = max(nax,cur);
	 }
	 nax = max(nax, a[0]+k-a[n-1]);
	 cout << k - nax << endl;
	 return 0;
 }


Measured memory_bytes: 4840
n = gets.to_i
min = 90

1.upto(n - 1) do |i|
  tmp = 0
  i.to_s.each_char { |c| tmp += c.to_i }
  (n - i).to_s.each_char { |c| tmp += c.to_i }

  min = tmp if min > tmp
end

puts min

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

int main() {
  int n,m;cin>>n>>m;
  int L=0,R=1e9;
  rep(i,m){
    int l,r;cin>>l>>r;
    L=max(L,l);R=min(R,r);
  }
  int ans=max(R-L+1,0);
  cout<<ans<<endl;
}

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

using namespace std;

using ll = long long;

const ll MOD = 1e9 + 7;

ll dp[5005][5005];

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	string s;
	cin >> n >> s;
	
	dp[0][0] = 1;
	for (int i = 0; i < n; i++) {		
		for (int j = 0; j <= i; j++) {
			(dp[i + 1][j + 1] += dp[i][j] * 2) %= MOD;
			(dp[i + 1][max(j - 1, 0)] += dp[i][j]) %= MOD;
		}
	}

	int m = s.length();
	ll ans = dp[n][m];
	ans = ans * modpow(modpow(2, m), MOD - 2) % MOD;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 194048
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);i++)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;i--)
#define lb lower_bound
#define ub upper_bound
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
const ll LINF = (ll)(1e18 +99);
vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> void chmin(T& t, const U& u){if(t>u)t=u;}
template<typename T,typename U> void chmax(T& t, const U& u){if(t<u)t=u;}
template<typename T>T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T>T mpow(T a, T n) {
   T res = 1;
   for(;n;n>>=1) {
      if (n & 1) res = res * a;
      a = a * a;
   }
   return res;
}

//cin.tie(0);ios::sync_with_stdio(false);

template<typename T>
struct Matrix{
   int H,W;
   vector<vector<T>> A;

   Matrix() : H(0),W(0){}
   Matrix(int H_,int W_) : H(H_),W(W_),A(vector<vector<T>> (H,vector<T>(W,0))){}
   Matrix(vector<vector<T>> v) : H(v.size()),W(v[0].size()),A(v){}//

   Matrix operator+(const Matrix& r){//
      assert(H==r.H && W==r.W);
      vector<vector<T>> v(H,vector<T>(W));
      for(int i=0;i<H;i++)for(int j=0;j<W;j++)v[i][j]=A[i][j]+r.A[i][j];
      return v;
   }

   Matrix operator-(const Matrix& r){//
      assert(H==r.H && W==r.W);
      vector<vector<T>> v(H,vector<T>(W));
      for(int i=0;i<H;i++)for(int j=0;j<W;j++)v[i][j]=A[i][j]-r.A[i][j];
      return v;
   }

   Matrix operator*(const Matrix& r){//
      assert(W==r.H);
      vector<vector<T>> v(H,vector<T>(r.W,0));
      for(int i=0;i<H;i++)for(int j=0;j<W;j++)for(int k=0;k<W;k++)(v[i][j]+=A[i][k]*r.A[k][j])%=mod;
      return v;
   }

   Matrix& operator+=(const Matrix& r){return (*this)=(*this)+r;}
   Matrix& operator-=(const Matrix& r){return (*this)=(*this)-r;}
   Matrix& operator*=(const Matrix& r){return (*this)=(*this)*r;}

   T at(int i,int j){
      return A[i][j];
   }

   void set(int i,int j,T v){
      A[i][j]=v;
   }

   static Matrix E(int n){
      Matrix res(n,n);
      for(int i=0;i<n;i++){
         res.set(i,i,1);
      }
      return res;
   }
   
   Matrix pow(ll n){
      Matrix res=E(A.size()),B=A;
      while(n){
         if(n&1)res*=B;
         B*=B;
         n>>=1;
      }
      return res;
   }
};


signed main(){
   ll n,k,ans=0;cin>>n>>k;
   vector<vector<ll>> v(n,vector<ll>(n));
   rep(i,0,n)rep(j,0,n)cin>>v[i][j];
   Matrix<ll> a(v);
   a=a.pow(k);

   rep(i,0,n)rep(j,0,n)(ans+=a.at(i,j))%=mod;

   cout<<ans<<endl;

}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#include <sstream>
#include <istream>

using namespace std;

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


int main(){
	int n,m;
	cin >> n >> m;

	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			string s;
			cin >> s;
			if(s=="snuke"){
				printf("%c%d\n",('A'+j),i+1);
			}
		}
	}
	

	return 0;
}

Measured memory_bytes: 256
//
//  main.cpp
//  Atcoder1
//
//  Created by Hamske on 2020/09/17.
//  Copyright © 2020 Author. All rights reserved.
//

#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <string>

using namespace std;

//#define pb push_back
//#define mp make_pair
//
//#define F first
//#define S second

typedef long long ll;

#define rept(_i,iv,n,type) for(type _i=(type)(iv);_i<(type)(n);++_i)
//#define repi(_i,iv,n) rept(_i,iv,n,int)
//#define repl(_i,iv,n) rept(_i,iv,n,ll)

#define rept0(_i,n,type) rept(_i,0,n,type)
#define repi0(_i,n) rept(_i,0,n,int)
#define repl0(_i,n) rept(_i,0,n,ll)

//#define repst(_i,iv,n,type) for(type _i=iv;_i<=(type)(n);++_i)
//#define repsi1(_i,n) repst(_i,1,n,int)

#define REPT(_i,iv,_l,n,type) for(type _i=(type)(iv),_l=(type)(n);_i<_l;++_i)
//#define REPI(_i,iv,_l,n) REPT(_i,iv,_l,n,int)
//#define REPL(_i,iv,_l,n) REPT(_i,iv,_l,n,ll)
//
#define REPT0(_i,_l,n,type) REPT(_i,0,_l,n,type)
#define REPI0(_i,_l,n) REPT(_i,0,_l,n,int)
#define REPL0(_i,_l,n) REPT(_i,0,_l,n,ll)


//#define rrept(_i,x,e,type) for(type _i=((type)(x)-1);_i>=e;--_i)
//
//#define rrept0(_i,x,type) rrept(_i,x,0,type)
//
//#define RREPT(_i,x,_e,e,type) for(type _i=((type)(x)-1),_e=(type)(e);_i>=_e;--_i)
//
//#define RREPT0(_i,x,_e,type) RREPT(_i,x,_e,0,type)
//
//#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

//#define all(x) (x).begin(),(x).end()
#define REPV(v,_itr,_end) for(auto _itr=(v).begin(),_end=(v).end();_itr!=_end;++_itr)
#define REPVC(v,_itr,_end) for(auto _itr=(v).cbegin(),_end=(v).cend();_itr!=_end;++_itr)

#define td typedef
//#define tds(stl,type,name) typedef stl<type > name;
#define tdv(type,name) typedef vector<type > name;


//typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<vb > vvb;
typedef vector<int> vi;
typedef vector<vi > vvi;
typedef vector<ll> vll;
//typedef vector<vll > vvll;

#define mod99 998244353

int main(int argc, const char * argv[]) {
    int N;
    cin>>N;
    
    for(int i=0,len=N/7;i<=len;++i){
        if((N-i*7)%4==0){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;

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

    if(a >= 3200){
        cout << s << endl;
    }
    else{
        cout << "red" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
// ＡＢＣのＡ過去問を解くだけだよ

// フォント:Electroharmonix
// x:小文字(ｘ)    X:大文字(Ｘ)
// +:プラス(＋)    &:アンド(＆)

#include <bits/stdc++.h>

using namespace std;

void Main()
{
    int a, b;
    cin >> a >> b;

    if ((a * b) % 2 == 1)
        cout << "Yes";
    else
        cout << "No";
}

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

    //std::cout << std::fixed << std::setprecision(10);

#ifdef DEBUG_BUILD
    while (true)
    {
        Main();
        cout << std::endl;
    }
#endif

    Main();
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <bitset>

using namespace std;

bitset <5000000> f;

int i,m,n,t;

int main()
{
	scanf("%d",&n);
	f[0]=1;
	for (i=1;i<=n;i++)
	{
		scanf("%d",&t),m=m+t;
		f|=(f<<t);
	}
	for (i=m-m/2;i<=m;i++)
		if (f[i])
		{
			printf("%d\n",i);
			return 0;
		}
}

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


int main(){
  ll n;
  cin >>n;
  ll ans =0;

  if(n%2 ==1)cout<<0<<endl;


  else{
      n /= 2;
    while(n){
      ans += n/5;
      n /= 5;
    }
    cout <<ans<<endl;
  }

}


Measured memory_bytes: 256
//
// Created by yjq on 2019/11/5.
//
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
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{
        ll ans = min(a*b,min(a*c,b*c));
        printf("%lld\n",ans);
    }
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h> 
int main()
{
	int n, mini, res, r, i;
    scanf("%d%d%d", &n, &mini, &r);
	res = r - mini;
    if(r < mini) mini = r;
	for (i = 2; i < n; i++) {
        scanf("%d", &r);
        if(r - mini > res) res = r - mini;
        if(r < mini) mini = r;
	}
    printf("%d\n", res);
	return 0;
}


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

using namespace std;

long long MOD = 1000000007;

void cout_vec(vector<int> &vec){
    for(int i=0; i<vec.size(); i++){
        if (i!=0){
            cout << ' ';
        }
        cout << vec[i];
    }
    cout << endl;
}

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

    vector<int> ans(0);
    for(int i=X-K+1; i<X+K; i++){
        ans.push_back(i);
    }
    cout_vec(ans);
}

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

int main() {
  int H, N;
  cin >> H >> N;
  vector<int> A(N);
  for(int i = 0; i < N; i++)cin >> A.at(i);
  
  int sum=0;
  
  for(int i = 0; i < N; i++)sum +=A.at(i); 
  
  if(H-sum<=0){
    cout << "Yes" << endl;
  }
  else{cout << "No" << endl;}
  
  return 0;
}

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;

typedef long long LL;
typedef long double ldouble;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int n, k;
    cin >> n >> k;
    vector<double> v(n);
    for(int i = 0; i < n; ++i) {
        cin >> v[i];
        v[i] = (v[i] + 1) / 2;

    }

    double s = 0;
    for(int i = 0; i < k; ++i) {
        s += v[i];

    }

    double res = s;
    for(int i = k; i < n; ++i) {
        s -= v[i - k];
        s += v[i];
        res = max(res, s);

    }
    printf("%.10lf\n", res);

    return 0;
}



Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
LL N,K;
LL cc[100001];
LL cc2[100001];
LL dp[2][100001];
LL sum[100001];
LL dp2[2][100001];
LL sum2[100001];
LL MOD=1e9+7;
int main(){
	cin>>N>>K;
	REP(i,sqrt(N+1)){
		if(i==0)continue;
		dp[0][i]=1;//i
		LL a=max((LL)sqrt(N),N/i);
		LL b=max((LL)sqrt(N),(N/(i+1)));
		dp2[0][i]=(a-b)%MOD;//iまでok
		cc[i]=dp[0][i]%MOD;
		cc2[i]=dp2[0][i]%MOD;
	}
	dp[0][0]=0;
	dp2[0][0]=0;
	LL ans=0;
	REP(i,K-1){
		int a;
		if(i%2==0){
			a=1;
		}else{
			a=0;
		}
		LL now=0;
		LL now2=0;
		REP(j,sqrt(N+1)){
			if(j==0){
				sum[j]=dp[1-a][j];
				sum2[j]=dp2[1-a][j];
			}else{
				sum[j]=sum[j-1]+dp[1-a][j];
				sum2[j]=sum2[j-1]+dp2[1-a][j];
			}
			sum[j]%=MOD;
			sum2[j]%=MOD;
			//cout<<sum[j]<<" "<<sum2[j]<<endl;
			now=sum[j];
			now2=sum2[j];
		}
		REP(j,sqrt(N+1)){
			if(j==0)continue;
			dp[a][j]=((now+now2-sum2[j-1])%MOD+MOD)%MOD;
			if(dp2[1-a][j]!=0){
				dp2[a][j]=sum[j];
			}
			dp[a][j]%=MOD;
			dp2[a][j]%=MOD;
			dp[a][j]*=cc[j];
			dp2[a][j]*=cc2[j];
			dp[a][j]%=MOD;
			dp2[a][j]%=MOD;
		}
		dp[a][0]=0;
		dp2[a][0]=0;
		
		ans=0;
		REP(j,sqrt(N+1)){
			ans+=dp[a][j];
			ans%=MOD;
			ans+=dp2[a][j];
			ans%=MOD;
		}
		/*REP(j,10){
			cout<<"a"<<dp[a][j]<<endl;
			cout<<"b"<<dp2[a][j]<<endl;
		}
		cout<<"ans"<<ans<<endl;
		*/
	}
	cout<<ans<<endl;
}

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

using namespace std;

#define ll long long

#define DEBUG (0)

int main()
{
  ll N = 0;
  ll M = 0;
  cin >> N >> M;

  vector<ll> A(M,0);
  ll sum = 0;

  for(ll i = 0; i < M; i++){
    cin >> A[i];
    sum += A[i];
  }

  if(N < sum){
    cout << -1 << "\n";
  }else{
    cout << N - sum << "\n";
  }

#if DEBUG
  for(ll i = 0; i < M; i++){
    cout << A[i] << endl;
  }
#endif
}


Measured memory_bytes: 3676
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
//#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vl = vector<ll>;
using vi = vector<int>;
using Graph = vector<vi>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(15); //"for float-base
  // problem"
  int A, B, C;
  cin >> A >> B >> C;
  if (A % 2 == 1 || B % 2 == 1 || C % 2 == 1) {
    cout << 0 << endl;
    return 0;
  } else if (A == B && A == C) {
    cout << -1 << endl;
    return 0;
  }
  int ans = 0;
  while (A % 2 == 0 && B % 2 == 0 && C % 2 == 0) {
    ans++;
    int a = A,b = B, c = C;
    A = b / 2 + c / 2;
    B = a / 2 + c / 2;
    C = a / 2 + b / 2;
    //cout << A << " " << B << " " << C << endl;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

vector<vector<ll>> g;
priority_queue<ll, vector<ll>, greater<>> c;
vector<ll> x;
vector<bool> vi;

void dfs(int cr, int pr) {
    if (vi[cr]) return;
    vi[cr] = true;
    for (auto &&e: g[cr]) {
        dfs(e, cr);
    }
    x[cr] = c.top();
    c.pop();
    return;
}


int main(int argc, char const *argv[]) {
    int n;
    cin >> n;
    g.resize(n);
    REP(i,n-1) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    ll sum = 0ll;
    ll MAX = 0ll;

    REP(i,n) {
        ll tmp; cin >> tmp;
        sum += tmp; MAX = max(tmp, MAX);
        c.push(tmp);
    }
    x.resize(n,0);
    vi.resize(n,false);
    dfs(0,0);
    
    ll ans = sum-MAX;
    cout << ans << endl;
    
    REP(i,n) {
        cout << x[i];
        if (i!=n-1) cout << " ";
        else cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1536
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>
#include <complex>

using namespace std;

bool isPrime[1000000];
int main()
{
	fill(isPrime, isPrime+1000000, true);
	isPrime[0] = isPrime[1] = false;
	for (int i = 2; i < 1000000; ++i)
	{
		if (isPrime[i])
		{
			for (int j = 2*i; j < 1000000; j += i)
				isPrime[j] = false;
		}
	}

	int n;
	while (scanf("%d", &n), n)
	{
		int ans = 0;
		for (int i = 3; i <= n/2; ++i)
			if (isPrime[i] && isPrime[n-i])
				++ans;
		printf("%d\n", ans);
	}

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long ll;

int main(int argc, const char * argv[]) {
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string sa, sb, sc;
    cin >> sa >> sb >> sc;
    
    int la = sa.size();
    int lb = sb.size();
    int lc = sc.size();
    
    int pa = 0;
    int pb = 0;
    int pc = 0;
    int state = 0;
    
    while ( 1 ){
        if ( state == 0 ){
            if ( pa == la ){
                cout << "A" << endl;
                return 0;
            } else {
                if ( sa[pa] == 'a' ) state = 0;
                else if ( sa[pa] == 'b' ) state = 1;
                else if ( sa[pa] == 'c' ) state = 2;
                ++pa;
                continue;
            }
        } else if ( state == 1 ) {
            if ( pb == lb ){
                cout << "B" << endl;
                return 0;
            } else {
                if ( sb[pb] == 'a' ) state = 0;
                else if ( sb[pb] == 'b' ) state = 1;
                else if ( sb[pb] == 'c' ) state = 2;
                ++pb;
                continue;
            }
        } else {
            if ( pc == lc ){
                cout << "C" << endl;
                return 0;
            } else {
                if ( sc[pc] == 'a' ) state = 0;
                else if ( sc[pc] == 'b' ) state = 1;
                else if ( sc[pc] == 'c' ) state = 2;
                ++pc;
                continue;
            }
        }
    }
    
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int n, k, S[100000];

int maxload(int P){
  int r = k, load = 0, remain = P;
  while(r > 0 && S[load] > 0){
    if(S[load] <= remain){
      remain -= S[load];
      load++;
    } else {
      r--;
      remain = P;
    }
  }
  return load;
}

int main(void){
  int i;
  scanf("%d %d", &n, &k);
  for(i=0;i<n;i++)
    scanf("%d", &S[i]);
  int left = 0, right = 10000 * n, middle;
  while(left != right - 1){
    middle = (left + right - 1) / 2;
    if(maxload(middle) >= n)
      right = middle + 1;
    else
      left = middle + 1;
  }
  printf("%d\n", left);
  return 0;
}

Measured memory_bytes: 2164
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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;
}

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

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

int N;
string S;
using ull = unsigned long long;
ull csum[5010];
ull pow3[5010];

bool can(int i, int j, int x) {
  if (j + x >= S.size()) {
    return false;
  }

  if (i + x >= j) {
    return false;
  }

  ull h1 = csum[i + x + 1] - csum[i];
  ull h2 = csum[j + x + 1] - csum[j];
  return h1 * pow3[j - i] == h2;
}

bool can2(int x) {
  map<ull, vector<int>> mp;
  for (int i = 0; i < S.size() - x; ++i) {
    ull h = csum[i + x + 1] - csum[i];
    h *= pow3[S.size() - i];
    if (mp[h].size() == 0) {
      mp[h].push_back(i + x);
    } else if (mp[h].back() < i) {
      return true;
    }
  }
  return false;
}

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

  pow3[0] = 1;
  rep(i, 1, 5010) { pow3[i] = pow3[i - 1] * MOD; }

  rep(i, 0, N) { csum[i + 1] = csum[i] + S[i] * pow3[i]; }

  int ans = 0;
  int low = 0;
  int high = S.size();
  while (high - low > 1) {
    int mid = (low + high) / 2;
    if (can2(mid)) {
      low = mid;
      chmax(ans, low + 1);
    } else {
      high = mid;
    }
  }

  cout << ans;
}


Measured memory_bytes: 4252
#include <iostream>
#include <string>
#include <math.h>
using namespace std;
signed main()
{
    int i,j;
    char c[3][3];
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            cin >> c[i][j];
        }
        cout << endl;
    }
    cout << c[0][0] << c[1][1] << c[2][2] << endl;
}

Measured memory_bytes: 256
s = list(str(input()))

check = 0

n = len(s)

re_s =list(reversed(s))

if re_s == s:
    check += 1

split_s = s[:(n-1)//2]
re_ss = list(reversed(split_s))
if re_ss == split_s:
    check += 1

saigo_s = s[(n+3//2):]
re_sss = list(reversed(saigo_s))

if re_sss == saigo_s:
    check += 1

if check == 3:
    print('Yes')
else:
    print('No')

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

int main() {
	int a,b;
	cin>>a;
	cin>>b;
	int out;
	if((a==1&&b==2)||(a==2&&b==1)){
		out = 3;
	} else if((a==2&&b==3)||(a==3&&b==2)){
		out = 1;
	} else if((a==1&&b==3)||(a==3&&b==1)){
		out = 2;
	}
	cout << out <<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main ()
{
    int i,j,k,a,b;
    cin>>a>>b;
    k=max((100*a)/8,(100*b)/10);
    for(i=1;i<=1009;i++)
    {
        if((i*8)/100==a && (i/10)==b)
        {
            cout<<i;
            return 0;
        }
        else
        {
            j=1;
        }  
    }
    if(j==1)
    {
        cout<<-1;
        return 0;
    }
}

Measured memory_bytes: 3600
from collections import Counter
n, k = map(int, input().split())

c = Counter()
for _ in range(n):
    a, b = map(int, input().split())
    c[a] += b
c = sorted(c.items(), key=lambda x: x[0])

for i, v in c:
    k -= v
    if k <= 0:
        print(i)
        exit()

Measured memory_bytes: 53720
#include<stdio.h>

typedef struct{
  char num;
  char pattern;
}Card;

int isStable(Card[],Card[],int);
void selection(Card[],int);
void bubble(Card[],int);


int main(){
  Card car1[100];
  Card car2[100];
  int i,n;

  scanf("%d\n",&n);
  for(i=0;i<n;i++){
    scanf("%c%c ",&car1[i].pattern,&car1[i].num);
    car2[i]=car1[i];
  }

  bubble(car1,n);
  selection(car2,n);

  for(i=0;i<n;i++){
    if(i){
      printf(" ");
    }
    printf("%c%c",car1[i].pattern,car1[i].num);
  }
  printf("\n");
  
  printf("Stable\n");
  
  for(i=0;i<n;i++){
    if(i){
      printf(" ");
    }
    printf("%c%c",car2[i].pattern,car2[i].num);
  }
  printf("\n");

  if(isStable(car1,car2,n)){
    printf("Stable\n");
  }
  else{
    printf("Not stable\n");
  }

  return 0;
}

void bubble(Card A[], int n){
  int i, j;
  Card t;
  for (i=0;i<n;i++){
    for (j=n-1;j>=i+1;j--){
      if (A[j].num < A[j-1].num){
	t = A[j];
	A[j] = A[j-1];
	A[j-1] = t;
      }
    }
  }
}

void selection(Card A[], int n){
  int i, j, mini;
  Card t;
  for(i=0;i<n;i++){
    mini = i;
    for(j=i;j<n;j++){
      if(A[j].num<A[mini].num){
	mini = j;
      }
    }
    t = A[i];
    A[i] = A[mini];
    A[mini] = t;
  }
}

int isStable(Card A1[],Card A2[],int n){
  int i;
  for(i=0;i<n;i++){
    if(A1[i].pattern != A2[i].pattern){
      return 0;
    }
  }
  return 1;
}



Measured memory_bytes: 2108
<?php
  
$x = trim(fgets(STDIN));
 
$q = strval(floor($x/11));
$l = $x%11;
 
$qq = 0;
if ($l>=1 && $l<=6){
  $qq = 1;
} else if ($l>=7 && $l<=10){
  $qq = 2;
}
 
echo $q*2+$qq;
 
?>

Measured memory_bytes: 4856
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

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

    string s;
    cin >> s;
    if(s == "ABC")  cout << "ARC\n";
    else    cout << "ABC\n";
}

Measured memory_bytes: 3612
def exits?(h, w)
  letter_count = {}
  h.times do
    gets.chomp.split(//).each do |aa|
      letter_count[aa] ||= 0
      letter_count[aa] = (letter_count[aa] + 1) % 4
    end
  end
  letter_count.reject! { |_k, v| v.zero? }

  h, w = w, h if h.odd?

  if h.even? && w.even?
    letter_count.values.empty?
  elsif h.even? && w.odd?
    letter_count.values.all?(&:even?) && letter_count.values.inject(:+) <= h
  else
    letter_count.values.count(&:odd?) == 1 && letter_count.values.inject(:+) <= h + w - 1
  end
end

puts exits?(*gets.split.map(&:to_i)) ? 'Yes' : 'No'

Measured memory_bytes: 1788
#include<cstdio>
#include<algorithm>
using namespace std;
#define N 100000
int x[N+5],y[N+5],c[N+5];
int y1[N],n,k,Max,cnt;
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
	{
		char ch;
		scanf("%d %d %c",&x[i],&y[i],&ch);
		x[i]%=(2*k);
		y[i]%=(2*k);
		if(ch=='W')
			c[i]=1;
	}
	for(int i=0;i<=k;i++)
	{
		cnt=0;
		fill(y1,y1+2*k+1,0);
		for(int j=1;j<=n;j++)
		{
			bool p=(i<=x[j]&&x[j]<i+k);
			bool q=(0<=y[j]&&y[j]<k);
			if(p^q==c[j])
				cnt++,y1[y[j]]++;
			else
				y1[y[j]]--;
		}
		for(int j=0;j<=k;j++)
		{
			Max=max(Max,max(cnt,n-cnt));
			if(j!=k)
				cnt=cnt-y1[j]-y1[k+j];
		}
	}
	printf("%d\n",Max);
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std; 
using lint  =                           long long int;
using pint  =                           pair<int, int>;
using plint =                           pair<lint, lint>;
#define vli                             vector<lint>
#define pb                              push_back
#define ALL(x)                          begin(x),end(x)
#define inf                             (1LL<63)-1
#define MOD                             1000000007
#define SZ(x)                           ((lint)(x).size())
#define                                 FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define                                 IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define                                 REP(i, n) FOR(i,0,n)
#define                                 IREP(i, n) IFOR(i,0,n)
#define                                 f_ip   ios_base::sync_with_stdio(false); cin.tie(NULL);
#define                                 debug(x) cerr << #x << " " << (x) << endl
struct fast_ios                         { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T>                    istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T>                    bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T>                    bool mmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }


/* -------
         |
    **   |
   -------      
   |
   ---------------------------------------------------------------------------------------------------------------------------------*/

void solve(){  
	  int A,B;
	  cin >> A >> B;
	  int outlet = 1;
	  int ans = 0;
	  while(outlet < B){
	   --outlet;                          //for using this empty socket to install the power strip;
	   outlet += A;
	   ++ans;
	  } 
	  cout << ans << endl;
}

int main(){   
  
 solve();

 return 0;
}


Measured memory_bytes: 256