akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        char[] s = sc.next().toCharArray();
        int len = s.length;
        if(len == 2){
            if(s[0] == s[1]){
                System.out.println("1 2");
            }else{
                System.out.println("-1 -1");
            }
            return;
        }
        for(int i = 0; i < len-2; i++){
            if(s[i] == s[i+1] || s[i+1] == s[i+2] || s[i] == s[i+2]){
                System.out.println((i+1) + " " + (i+3));
                return;
            }
        }
        System.out.println("-1 -1");
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}


Measured memory_bytes: 23124
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////


int main(){
    string s;
    cin >> s;
    if(s[0] == s[2])Yes;
    else No;
    
	return  0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <iomanip>


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(9);
    cout << std::fixed;

    string s;
    ll a,b,k;
    cin >> a >> b >> k;
    FOR(i,a,a+k){
      if(i <= b)
      cout << i << endl;
    }

    FOR(i,b-k+1,b+1){
      if(i >= a+k)
      cout << i << endl;
    }
    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


Measured memory_bytes: 256
class uf_tree:
    def __init__(self, n):
        self.sizes = [0] * n
        self.par = range(n)

    def find(self, x):
        if x == self.par[x]:
            return x
        self.par[x] = self.find(self.par[x])
        return self.par[x]

    def unite(self, x, y):
        x, y = self.find(x), self.find(y)
        if x == y:
            return
        if self.sizes[x] < self.sizes[y]:
            x, y = y, x
        self.par[y] = x
        self.sizes[x] += self.sizes[y]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return self.sizes[find(x)]


N, K, L = map(int, raw_input().split())

uf_1 = uf_tree(N+1)
uf_2 = uf_tree(N+1)

for i in range(K):
    p, q = map(int, raw_input().split())
    uf_1.unite(p, q)

for i in range(L):
    r, s = map(int, raw_input().split())
    uf_2.unite(r, s);

dic = {}

for i in range(1, N+1):
    key = (uf_1.find(i), uf_2.find(i))
    dic[key] = dic.get(key, 0) + 1

for i in range(1, N+1):
    print dic[(uf_1.find(i), uf_2.find(i))],


Measured memory_bytes: 55340
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <bitset>
#include <cstdio>
#include <set>
#include <stack>
#include <queue>
#include <cassert>
//#include <bits/stdc++.h>
#define rep(i,n) Rep(i,0,n)
#define Rep(i,k,n) for(int i=k ; i<n ; i++)
#define rep1(i,n) for(int i=1 ; i<=n ; i++)
#define vi vector<int>
#define vii vector<vector<int>>
#define mii map<int,int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())
#define ALL(a)  (a).begin(),(a).end()
#define pb push_back
//#define int ll
typedef long long ll;

//const int MOD = 1000000007;
const int INF = 1<<30;
using namespace std;

string yn(bool x){
    return x ? "Yes" : "No";
}

int main(){
    int n , T; cin >> n >> T;
    int c[n] , t[n];
    
    rep(i,n) cin >> c[i] >> t[i];
    
    int ans = INF;
    
    rep(i,n){
        if(t[i] <= T and c[i] <= ans) ans = c[i];
    }
    
    if(ans == INF){
        cout << "TLE" << endl;
    }else{
        cout << ans << endl;
    }
    
}











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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int pre = -999;
    rep(i, n) {
        if(pre <= a[i] - 1) {
            pre = a[i] - 1;
        } else if(pre <= a[i]) {
            pre = a[i];
        } else {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 640
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let input: Vec<f64> = read_vec();

    let a = input[0];
    let b = input[1];
    let c = input[2];
    let d = input[3];

    if (a / d).ceil() >= (c / b).ceil() {
        println!("Yes");
    } else {
        println!("No");
    }
}

Measured memory_bytes: 2604
#include <bits/stdc++.h>
using namespace std;
#define rep(i,end) for(ll i = 0; i < end ; i++ )
#define print(ans) cout << fixed << setprecision(15) << ans << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int N;
string S;

int main() {
  cin >> N;
  double ans;
  ans = 1-((N/2)/double(N));
  print(ans);
}



Measured memory_bytes: 3736
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    int n; cin >> n;
    vector<P> data(n);
    rep(i,n) {
        int x, l; cin >> x >> l;
        data[i] = P(x-l,x+l);
    }
    sort(all(data),[](P &a, P &b){return a.second < b.second;});
    int l = -inf;   
    int ans = 0;
    rep(i,n) {
        if (l <= data[i].first) {
            ans++;
            l = data[i].second;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3980
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ls( s) (s&(-s))
#define ll long long
#define inf 0x3f3f3f3f
#define fast    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int N = 2e5+5;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod =    2019;
ll n;ll lo=1;ll hi=2e5;
ll arr[N];
bool fn(ll x)
{
	ll t;
	map<ll,ll> mp;
	if(x==1)
	{
		for(int i=2;i<=n;i++)
		if(arr[i]<=arr[i-1]) return 0;
		return 1;
	}
	for(int i=2;i<=n;i++)
	if(arr[i]<=arr[i-1])
	{
		t=arr[i];
		mp.erase(mp.upper_bound(t),mp.end());

  while(t>0&&mp[t]==x-1)
		{
			mp.erase(t);
			t--;
		}
		if(!t)
		return 0;
		else
		mp[t]++;
	}
	return 1;
}
int main()
{  fast
cin>>n;
int ans=1;
for(int i=1;i<=n;i++)cin>>arr[i];
while(lo<=hi)
{
	ll mid=(lo+hi)/2;
//	cout<<mid<<endl;
	if(fn(mid))
	ans=mid,hi=mid-1;
	else
	lo=mid+1;
}
cout<<ans<<endl;
}


Measured memory_bytes: 1920
from functools import reduce
from collections import deque


def operate(dq, op):
    if op[0] == 'i':
        dq.appendleft(int(op[7:]))
    else:
        k = op[6]
        if k == 'F':
            dq.popleft()
        elif k == 'L':
            dq.pop()
        else:
            try:
                dq.remove(int(op[7:]))
            except ValueError:
                pass
    return dq


n = int(input())
print(*reduce(operate, [input() for _ in range(n)], deque()))

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

void dfs(vector<vector<int>> &tree, vector<int> &node_score, int node_name, int parent=-1){
  for(int u : tree.at(node_name)){
    if(u == parent) continue; //もし親の番号と一致するなら次のループへ
    node_score.at(u) += node_score.at(node_name);
    dfs(tree, node_score, u, node_name);    
  }
}

int main(){
  int N, Q;
  cin >> N >> Q;
  vector<vector<int>> tree(N, vector<int>());
  vector<int> node_score(N, 0);
  int a, b;
  for(int i=0; i<N-1; i++){
    cin >> a >> b;
    a--; b--;
    tree.at(a).push_back(b);
    tree.at(b).push_back(a);
  }
  /*for(int i=0; i<tree.size(); i++){
   cout << i << ": ";
   for(int j=0; j<tree.at(i).size(); j++){
     cout << tree.at(i).at(j) << " ";
   }
    cout << endl;
  }*/
  
  int p, x;
  for(int i=0; i<Q; i++){
    cin >> p >> x;
    p--;
    node_score.at(p) += x;    
  }
  dfs(tree, node_score, 0, -1);
  
  for(int i=0; i<node_score.size(); i++){
    cout << node_score.at(i) << " ";
  }
  cout << endl;
}




Measured memory_bytes: 32896
#include<iostream>
using namespace std;
int primes[9591];
int primes2017[673];
bool isPrime(int n){
	if(n==2)return 1;
	if(n==1||n%2==0)return 0;
	for(int i=3;i*i<=n;i+=2){
		if(n%i==0)return 0;
	}
	return 1;
}
int main(){
    int n;
    cin>>n;
    int t=0;
    for(int i=3;i<99998;i+=2){
    	if(isPrime(i)){
    		primes[t++]=i;
		}
	}
	t=0;
	for(int i=0;i<9592;i++){
    	if(isPrime(primes[i]/2+1)){
    		primes2017[t++]=primes[i];
		}
	}
    int l,r;
    for(int i=0;i<n;i++){
    	t=0;
    	cin>>l>>r;
    	for(int j=0;j<673;j++){
    		if(primes2017[j]>r)break;
    		if(primes2017[j]>=l)t++;
		}
		cout<<t<<endl;
	}
}

Measured memory_bytes: 640
solve :: Int -> Int -> Int -> Int
solve n m i
  | i * i > m = 0
  | m `mod` i /= 0 = solve n m (i + 1)
  | otherwise = max (if n * i <= m then i else 0) $ max (if n <= i then m `div` i else 0) $ solve n m (i + 1)

main :: IO ()
main = do
  [n, m] <- (map (\s -> read s :: Int)) . words <$> getLine
  print $ solve n m 1


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

int N,M;
string S;
string ks[13];

int sc[(1<<12)];
bool dp[(1<<12)];

bool solve(int id){
  memset(dp,0,sizeof(dp));
  dp[0] = 1;
  int n = S.size();
  if( n-id < sc[(1<<N)-1] ) return false;
  for(int i=0;i<(1<<N);i++){
    if( !dp[i] ) continue;
    for(int j=0;j<N;j++){
      if( i & (1<<j) ) continue;
      if( S.compare(id+sc[i],ks[j].size(),ks[j]) == 0 ){
	//	cout << S.substr(id+sc[i]) << " "<< ks[j] << " " << S.compare(id+sc[i],ks[j].size(),ks[j]) << endl;
	dp[i|(1<<j)] = 1;	 	
      }
    }
  }
  return dp[(1<<N)-1];
}

int main(){
  while( cin >> N >> M && (N||M) ){

    memset(sc,0,sizeof(sc));

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

    for(int i=0;i<(1<<N);i++){
      for(int j=0;j<N;j++){
	if( i & (1<<j) ) sc[i] += (int)ks[j].size();
      }
    }
    
    S.clear();
    for(int j=0;j<M;j++){
      string s;
      cin >> s;
      S+=s;
    }
    int res = 0;
    for(int i=0;i<(int)S.size();i++){
      if( solve(i) ) res++;
    }
    cout << res << endl;
  }
}

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

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; }
 
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 10000000000
#define MOD 1000000007
using ll = long long;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
using Graph = vector<vector<int>>;

int main(){
    int x; cin>>x;
    if(x)cout<<0<<endl;
    else cout<<1<<endl;
}


Measured memory_bytes: 3628
import java.util.*;
import java.util.stream.Stream;

public class Main {
    static class Product implements Comparable<Product> {
        String label;
        double incomeRate;

        Product(String l, int p, int a, int b, int c, int d, int e, int f, int s, int m) {
            this.label = l;
            this.incomeRate = (double)(f * s * m - p) / (a + b + c + (d + e) * m);
        }

        public String getLabel() {
            return this.label;
        }

        @Override
        public int compareTo(Product o) {
            if (this.incomeRate > o.incomeRate)
                return 1;
            else if (this.incomeRate < o.incomeRate)
                return -1;
            return o.label.compareTo(this.label);
        }
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n;
        String[] input;
        int[] params;
        String label;
        List<Product> products;
        while (true) {
            n = Integer.parseInt(sc.nextLine().trim());
            if (n == 0) break;
            products = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                input = sc.nextLine().trim().split(" ");
//                System.out.println(Arrays.toString(input));
                label = input[0];
                params = Stream.of(Arrays.copyOfRange(input, 1, input.length)).mapToInt(Integer::parseInt).toArray();
//                System.out.println(Arrays.toString(params));

                products.add(new Product(label, params[0], params[1], params[2], params[3], params[4], params[5], params[6], params[7], params[8]));
            }
//            System.out.println(products.size());

            Collections.sort(products);
            for (int i = 0; i < n; i++) {
                System.out.println(products.get(n-i-1).getLabel());
            }
            System.out.println("#");
        }
    }
}

Measured memory_bytes: 39104
R,C,K=map(int,input().split())
l=[[0] * C for i in range(R)]
for i in range(K):
  a,b,c=map(int,input().split())
  a-=1
  b-=1
  l[a][b]=c
dp=[0]*C
for i in range(R):
  ndp=[0]*C
  kdp=[0]*4
  for j in range(0,C):
    kdp[0]=max(kdp[0],dp[j])
    for k in range(2,-1,-1):
      kdp[k+1]=max(kdp[k+1],kdp[k]+l[i][j])
    ndp[j]=max(kdp)
  dp=ndp
print(dp[C-1])

Measured memory_bytes: 156244
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;
using namespace std;

//---

template <typename T>
inline void print(const T& rhs){ std::cout<<" = "<<rhs<<std::endl; }
template <typename T>
inline void print(const std::vector<T>& rhs){
    std::cout<<" = [ ";
    for(uint i=0; i<rhs.size(); ++i){ std::cout<<rhs[i]<<' '; }
    std::cout<<"]"<<std::endl;
}
template <typename T>
inline void print(const std::vector<std::vector<T>>& rhs){
    std::cout<<" = "<<std::endl;
    std::cout<<"[[ ";
    for(uint p=0; p<rhs.size(); ++p){
        if(p!=0){ std::cout<<" [ "; }
        for(uint q=0; q<rhs[p].size(); ++q){
            std::cout<<rhs[p][q]<<' ';
        }
        if(p!=rhs.size()-1){ std::cout<<"]"<<std::endl; }
    }
    std::cout<<"]]"<<std::endl;
}
template <typename TL, typename TR>
inline void print(const std::vector<std::pair<TR,TL>>& rhs){
    std::cout<<" = [";
    uint i=0;
    for(; i<rhs.size()-1; ++i){ std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"], "; }
    std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"]]" << endl;
}
#define printn(var) {printf("%s", #var);print(var);}
#define printn_all(var) {printf("%s(%d): ", __func__, __LINE__);printf("%s", #var);print(var);}

//---

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

    const uint N = 5;
    vector<int> vT(N);
    for(uint i=0; i<N; ++i){ cin >> vT[i]; }
    
    int sum=0;
    int min_mod=INT_MAX;
    for(uint i=0; i<N; ++i){
        int div = vT[i] / 10;
        int mod = vT[i] - 10*div;
        if(mod!=0){ min_mod = min(min_mod, mod); }
        
        sum += 10*div + (mod!=0 ? 10 : 0);
    }
    if(min_mod!=INT_MAX){ sum -= 10 - min_mod; }
    
    cout << sum << endl;
    
    return 0;
}

Measured memory_bytes: 256
from collections import deque
d = deque([1,2,3,4,5,6,7,8,9])

k = int(input())

cnt = 0
while k > cnt:
  x = d.popleft()
  cnt += 1  
  if x%10 != 0:
  	d.append(x*10+x%10-1)
  d.append(x*10+x%10)
  if x%10 != 9:
    d.append(x*10+x%10+1)
print(x)  

Measured memory_bytes: 11872
#include <iostream>
#include <algorithm>
using namespace std;
const int MAX_N = 300;

int n,cnt;
int in[MAX_N][MAX_N];
int s[MAX_N][MAX_N];

void cp_in(){
    for(int i = 0 ; i < n ; i++){
        for(int j = 0 ; j < n ; j++){
            s[i][j] = in[i][j];
        }
    }
}

void dfs(int y,int x,bool bit){
    if(bit){
        if(n <= x || n <= y) return;
        cnt++;
        int nx = x + 1;
        int ny = y + 1;
    
        if(0 <= nx && nx < n && 0 <= ny && ny < n && s[ny][nx] == 1){
            dfs(ny,nx,bit);
        }
    }
    else{
        if(x < 0 || n <= y) return;
        cnt++;
        int nx = x - 1;
        int ny = y + 1;
        
        if(0 <= nx && nx < n && 0 <= ny && ny < n && s[ny][nx] == 1){
            dfs(ny,nx,bit);
        }
    }
}

int main(){
    char ch;
    while(cin >> n ,n){
        int a = 0,b = 0,c = 0,d = 0;
        for(int i = 0 ; i < n ; i++){
            for(int j = 0 ; j < n ; j++){
                cin >> ch;
                in[i][j] = ch - '0';
            }
        }
        
        for(int i = 0 ; i < n ; i++){
            cnt = 0;
            for(int j = 0 ; j < n ; j++){
                if(in[i][j] == 1){
                    cnt++;
                    a = max(a,cnt);
                }
                else cnt = 0;
            }
        }
        
        for(int i = 0 ; i < n ; i++){
            cnt = 0;
            for(int j = 0 ; j < n ; j++){
                if(in[j][i] == 1){
                    cnt++;
                    b = max(b,cnt);
                }
                else cnt = 0;
            }
        }

        cp_in();
        for(int i = 0 ; i < n ; i++){
            for(int j = 0 ; j < n ; j++){
                cnt = 0;
                if(s[i][j] == 1) dfs(i,j,1);
                c = max(c,cnt);
            }
        }
        
        cp_in();
        for(int i = 0 ; i < n ; i++){
            for(int j = 0 ; j < n ; j++){
                cnt = 0;
                if(s[i][j] == 1) dfs(i,j,0);
                d = max(d,cnt);
            }
        }
        
        cout << max(max(a,b),max(c,d)) << endl;
    }
    
    return 0;
}

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

int main(){
  int N,K,ans=0;
  cin >> N >> K;
  int a[N];
  for(int i=0;i<N;i++){
    cin >> a[i];
  }
  sort(a,a+N,greater<int>());
  for(int j=0;j<K;j++){
    ans += a[j];
  }
  cout << ans << endl;
}

Measured memory_bytes: 764
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
template<typename V> constexpr typename V::value_type sum(const V &v) { return accumulate(all(v), 0); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  double x, h;
  while (cin >> x >> h, x) {
    cout << prec(8) << x * x + x * hypot(h, x / 2) * 2 << endl;
  }
}

Measured memory_bytes: 3100
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

ostream& operator <<(ostream& out, const pair<int, int>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const set<T>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

int main() {
  int a, b;
  cin >> a >> b;
  cout << (a + b - 1) / b << endl;
  return 0;
}


Measured memory_bytes: 256
// Problem : B - Judge Status Summary
// Contest : AtCoder - AtCoder Beginner Contest 173
// URL : https://atcoder.jp/contests/abc173/tasks/abc173_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	int ac = 0;
	int tle = 0;
	int wa = 0;
	int re = 0;
	for(int j = 0 ;  j <n; j++)
	{
		string s;
		cin>>s;
		if(s == "WA")
		{
			wa += 1;
		}
		else if(s == "RE")
		{
			re += 1;
		}
		else if(s == "AC")
		{
			ac += 1;
		}
		else
		{
			tle += 1;
		}
	}
	cout<<"AC x "<<ac<<"\n";
	cout<<"WA x "<<wa<<"\n";
	cout<<"TLE x "<<tle<<"\n";
	cout<<"RE x "<<re<<"\n";
	return 0;
}

Measured memory_bytes: 3624
import java.util.*;


public class Main {
    public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.nextLine();
		for (int i = 0; i < S.length(); i++) {
		    if (Character.isUpperCase(S.charAt(i))) {
		        System.out.print(Character.toLowerCase(S.charAt(i)));
		    } else {
		        System.out.print(Character.toUpperCase(S.charAt(i)));
		    }
		}
		System.out.println("");
    }
}


Measured memory_bytes: 26648
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main()
    {
        long n = long.Parse(Console.ReadLine());
        long t = 0, a = 0;
        long x = 1, y = 1;
        long s = 0;
        for (long i = 0; i < n; i++)
        {
            string[] cin = Console.ReadLine().Split();
            t = long.Parse(cin[0]);
            a = long.Parse(cin[1]);
            //while (s * t < x || s * a < y)
            //{
            //    s++;
            //}
            s = Math.Max(x / t, y / a);
            if (s * t < x || s * a < y) s++;
            x = s * t;
            y = s * a;
            s = 0;
        }
        Console.WriteLine(x + y);
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
using ll = long long;
using P = pair<int, int>;
/* ------------------------------------------------ */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ------------------------------------------------ */
int main() {
    int n;
    cin >> n;
    map<string, int> mp;
    rep(i, n) {
        string s;
        cin >> s;
        mp[s]++;
    }
    
        cout << "AC x " << mp["AC"] << endl;
        cout << "WA x " << mp["WA"] << endl;
        cout << "TLE x " << mp["TLE"] << endl;
        cout << "RE x " << mp["RE"] << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define ll long long
using namespace std;
vector<ll> a;
ll n;
int dp[100005];
int main(){
cin>>n;
a={100,101,102,103,104,105};
dp[0]=1;
for(int k=100;k<=n;k++){
    for(int i=0;i<a.size();i++){
        if(k-a[i]<0)
            continue;
        dp[k]=max(dp[k],dp[k-a[i]]);
    }
}
cout<<dp[n];
return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
 
using lli = long long int;
using ll = long long ;
using ld=long double;
using d= double;


int main(){
    int t=1;
    //cin>>t;
    while(t--){
        int n,m;
        cin>>n>>m;
        vector<int> a(n);
        ll sum=0;
        for(int i=0;i<n;i++){
            cin>>a[i];
            sum+=a[i];
        }
        
        sort(a.begin(),a.end());
        reverse(a.begin(),a.end());
        
        double c=sum/(double)(4*m);
        int flag=1;
        //cout<<c<<" ";
;        for(int i=0;i<m;i++){
            if(double(a[i])<c){
                flag=0;
                break;
            }
        }
        if(flag)
            cout<<"Yes";
        else
            cout<<"No";
    }
    return 0;
}
    

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

int main()
{
	int n,i,s=0;
	cin>>n;
	int d[n+1];
	for(i=1;i<=n;i++) cin>>d[i];
	sort(d+1,d+n+1);
	for(i=1;i<=n;i++)
	if(d[i]!=d[i-1]) s++;
	cout<<s;
	return 0; 
}

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



int main(){
  
  ll n,k;
  cin >> n >> k;
  k--;
  vector<ll>x(n);
  for(int i=0; i<n; i++) cin >> x[i];
  
  ll ans = 10e9;
  
  for(int i=0; i<n-k; i++){
    if(x[i]>=0 && x[i+k]>=0){
      ans = min(ans,x[i+k]);
    }
    else if(x[i]<=0; x[i+k]<=0){
      ans = min(ans,x[i]*(-1));
    }
    else{
      ans = min(ans,x[i+k]*2-x[i]);
      ans = min(ans,x[i+k]-x[i]*2);
    }
  }
  
  cout << ans << endl;
  
}
       
        
      
  
    

Measured memory_bytes: 4040
#include<stdio.h>
#include<string.h>
int main()
{
  int q,a,b,i,j,k,n=0,m,cent,basyo;
  char str[1001],mei[10],p[1001];
  scanf("%s",str);
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%s %d %d",mei,&a,&b);
    if(strcmp(mei,"replace")==0){
      scanf("%s",p);
      for(j=a;j<=b;j++){
    str[j]=p[n];
    ++n;
      }
    }
    n=0;
    if(strcmp(mei,"reverse")==0){
      cent=(b-a)/2;
      for(basyo=0;basyo<=cent;basyo++){
    m=str[a+basyo];
    str[a+basyo]=str[b-basyo];
    str[b-basyo]=m;
      }
    }
    if(strcmp(mei,"print")==0){
      for(j=a;j<=b;j++){
    printf("%c",str[j]);
    if(j==b)printf("\n");
      }
    }
  }
  return 0;
}



Measured memory_bytes: 2112
import java.util.Arrays;
import java.util.Scanner;

public class Main {

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

	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		if (n % f(n) == 0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}

	int f(int n) {
		int ret = 0;
		while (n > 0) {
			ret += n % 10;
			n /= 10;
		}
		return ret;
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}


Measured memory_bytes: 22996
import System.IO
import Control.Applicative

main = do
  -- "L M N" ---> [L,M,N]
  n <- fmap (read :: String -> Int) . words <$> getLine
  -- ns <- fmap (fmap (read :: String -> Int) . words) . lines <$> getContents
  print $ digit $ foldl (+) 0 n
  eof <- isEOF
  if eof
    then return ()
    else do main

digit :: Int -> Int
digit = length . show

Measured memory_bytes: 3996
import java.io.*;
import java.util.*;
import static java.lang.System.out;

public class Main {
    static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

    public static void main(String[] args) throws IOException {
        int N = Integer.parseInt(in.readLine());
        char[] c = new char[11 * N];
        int M = in.read(c, 0, c.length);
        int[] a = new int[N];
        int max = 0;
        for (int i = 0, j = 0; i < N; i++) {
            int x = 0;
            while (true) {
                int k = c[j++] - '0';
                if (0 <= k && k <= 9) {
                    x = 10 * x + k;
                } else {
                    break;
                }
            }
            max = Math.max(max, (a[i] = x));
        }

        int half = max / 2;
        int ans = 0;
        for (int i = 0; i < N; i++) {
            int now = Math.min(a[i], max - a[i]);
            int temp = Math.min(ans, max - ans);
            if (temp < now && now <= half) {
                ans = a[i];
            }
        }

        out.println(max + " " + ans);
    }
}


Measured memory_bytes: 39552
#include <iostream>
using namespace std;
const int MOD = 1e9 + 7;
int fpw(int x , int t){
	if(!t) return 1;
	int c = fpw(x , t >> 1);
	c = 1ll * c * c % MOD;
	if(t & 1) c = 1ll * c * x % MOD;
	return c;
}
int inv(int x){
	return fpw(x , MOD - 2);
}
int g[35];
int cal(int x){
	if(x & 1)
		return (x + 1) * (x + 1) / 4;
	return x * (x + 2) / 4;
}

void init(){
	for(int a = 1 ; a <= 31 ; ++ a)
		for(int b = 1 ; a + b <= 31 ; ++ b)
			for(int c = 1 ; a + b + c <= 31 ; ++ c)
				for(int d = 1 ; a + b + c + d <= 31 ; ++ d)
					for(int e = 1 ; a + b + c + d + e <= 31 ; ++ e){
						int v = 1ll * cal(a) * cal(b) * cal(c) * cal(d) * cal(e) % MOD; 
						(g[a + b + c + d + e] += v) %= MOD;
					}
	for(int i = 2 ; i <= 31 ; ++ i)
		(g[i] += g[i - 2]) %= MOD;
}

int main(){
	init();
	int T;
	scanf("%d" , &T);
	while(T --){
		int N;
		scanf("%d" , &N);
		int E = ((N & 1) ? N - 1 : N) , O = ((N & 1) ? N : N - 1);
		int ans = 0;
		for(int i = 1 ; i <= 31 ; i += 2){
			int t = g[i];
			for(int j = 1 ; j <= 31 ; j += 2)
				if(i != j)
					t = 1ll * t * (O + MOD - j) % MOD * inv((i + MOD - j) % MOD) % MOD;
			ans = (ans + t) % MOD;
		}
		for(int i = 0 ; i <= 30 ; i += 2){
			int t = g[i];
			for(int j = 0 ; j <= 30 ; j += 2)
				if(i != j)
					t = 1ll * t * (E + MOD - j) % MOD * inv((i + MOD - j) % MOD) % MOD;
			ans = (ans + t) % MOD;
		}
		printf("%d\n" , ans);
	}
	return 0;
}

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

class Proc{
public:
 string nam;
 int time;
 Proc() { nam == ""; time = 0; }
};

Proc Q[100001];

class Queue{
private:
 int fp;
 int rp;
public:
 Queue() { fp = 0; rp = 0; }
 int next(int p) const { return (p+1)%100001; }
 bool isFull() const { return (next(rp)==fp); }
 bool isEmpty() const { return (rp==fp); }
 void push(Proc d){
  if(isFull()) return;
  Q[rp] = d;
  rp = next(rp);
 }
 Proc front(){
  if(isEmpty()){
   Proc er;
   er.time = -1;
   return er;
  }
  return Q[fp];
 }
 void pop(){
  if(isEmpty()) return;
  fp = next(fp);
 }
};

int main(){
 Queue que;

 int n, q;
 cin >> n >> q;

 for(int i=0; i<n; i++){
  Proc p;
  cin >> p.nam >>p.time;
  que.push(p);
 }

 int total_time = 0;

 while(!que.isEmpty()){
  Proc p = que.front();
  que.pop();
  if(p.time<=q){
   total_time += p.time;
   cout << p.nam << ' ' << total_time << endl;
  }else{
   total_time += q;
   p.time -= q;
   que.push(p);
  }
 }

 return 0;
}

Measured memory_bytes: 7008
OFFSET = 97
def main():
    n = int(input())

    ans = []
    while True:
        n -= 1
        n,mod = divmod(n,26)
        ans.append(chr(mod+OFFSET))
        if n==0:
            break
    print(''.join(ans)[::-1])
    return

if __name__ == '__main__':
    main()

Measured memory_bytes: 61808
#define _CRT_SECURE_NO_WARNINGS

/* include ***********************/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

/* define *************************/
//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)
#define FOR(i,s,n) for(int i=(int)(s),i##_len=(int)(n);i<i##_len;i++)
#define RFOR(i,s,n) for(int i=(int)(n)-1,i##_len=(int)(s);i>=i##_len;i--)

//printf
#define PRINTD(d) printf("%d\n",(d))
#define PRINTL(d) printf("%lld\n",(d))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

#define INF 1e9
#define MOD 1000000007

typedef long long ll;
typedef unsigned long long ull;

int diff[4][2] = {
	{ 0, -1 },
	{ -1, 0 },
	{ 1, 0 },
	{ 0, 1 },
};
//今回の変数

int Min(int a, int b) {
	return (a)<(b) ? (a) : (b);
}
int Max(int  a, int  b) {
	return (a) > (b) ? (a) : (b);
}
ll Minl(ll a, ll b) {
	return (a)<(b) ? (a) : (b);
}
ll Maxl(ll a, ll b) {
	return (a)>(b) ? (a) : (b);
}
void hSwap(int x[], int i, int j)
{
	int temp;

	temp = x[i];
	x[i] = x[j];
	x[j] = temp;
}
void ShowData(int x[], int left, int right)
{
	int i;
	for (i = left; i <= right; i++)printf("%d  ", x[i]);
	printf("\n");
}
void QSort(int x[], int left, int right, int n) {
	int i, j;	//左端,右端
	int pivot;	//軸

	i = left;
	j = right;
	pivot = x[(left + right) / 2];

	while (1) {
		if (n > 0) {				//n>0なら昇順、n<=0なら降順
			while ((x[i] < pivot) && (i <= right))i++;	//軸値より大きい要素
			while ((pivot < x[j]) && (i <= right))j--;	//軸値より小さい要素
		}
		else {
			while ((x[i] > pivot) && (i <= right))i++;	//軸値より小さい要素
			while ((pivot > x[j]) && (i <= right))j--;	//軸値より大きい要素
		}
		if (i >= j)	break;
		hSwap(x, i, j);
		i++; j--;
	}
	//ShowData(x, left, right);

	if (left < i - 1)QSort(x, left, i - 1, n);
	if (j + 1 <  right)QSort(x, j + 1, right, n);
}

int main() {
	int ans = -1 * 1e9;

	int n, k;
	scanf("%d%d", &n, &k);

	int v[50];
	REP(i, n)scanf("%d", &v[i]);

	REP(i, n + 1) {
		if (i > k)break;
		REP(j, n + 1 - i) {
			if (i + j > k)break;
			int left = i;
			int right = j;
			int back = k - left - right;
			int min[50];
			int num = 0;
			int cnt = 0;
			REP(m, 50)min[m] = 1e9;
			REP(m, left) {
				num += v[m];
				if (v[m] < 0) {
					min[cnt++] = v[m];
				}
			}
			REP(m, right) {
				num += v[n-1-m];
				if (v[n - 1 - m] < 0) {
					min[cnt++] = v[n - 1 - m];
				}
			}
			if (cnt > back) {
				QSort(min, 0, cnt - 1, 1);
			}
			REP(m, Min(cnt,back)) {
				num -= min[m];
			}
			//printf("left:%d,right:%d,back:%d,:cnt:%d\n", left, right, back, cnt);
			ans = Max(ans, num);
			//PRINTD(ans);
			//puts("");
		}
	}
	PRINTD(ans);
}


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

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

int main(){

  int n, k; cin>> n>> k;
  vector<int> a(n);
  rep(i, n) cin>> a[i];

  int pos1=-1;
  rep(i, n)if(a[i]==1) pos1=i;
  int mn=1e9;
  for(int i=0; i+k-1<n; i++){
    int j=i+k-1;
    if(i<=pos1 and pos1<=j){
      int ret=1;
      if(k-1>1){
        if(i>0) ret+=(i-1)/(k-1)+1;
        if(j+1<n) ret+=(n-j-1-1)/(k-1)+1;
      }else{
        ret+=i;
        ret+=(n-j-1);
      }
      mn=min(mn, ret);
    }
  }

  cout<< mn<< endl;

  return 0;
}

Measured memory_bytes: 640
#include <cstdio>
#include <map>
using namespace std;

int main(){
  int N;
  scanf("%d",&N);
  int a[N];
  int i;
  map<int,int> b;
  for(i=0;i<N;i++){
    scanf("%d",&a[i]);
    b[a[i]]=0;
  }
  for(i=0;i<N;i++){
    b[a[i]]+=1;
  }
  int n,m;
  n=0;
  map<int,int>::iterator ite;
  for(ite=b.begin();ite!=b.end();++ite){
    m=ite->first-ite->second;
    if(m<0) n-=m;
    else{
      if(m!=0) n+=ite->second;
    }
  }
  printf("%d",n);
  return 0;
}

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair

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

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define INF 100000
#define N_ALPH 26

int main() {
    i64 N; cin >> N;
    vector<i64> A(N_ALPH, INF);
    REP(n, N) {
        string S; cin >> S;
        vector<i64> dist(N_ALPH, 0);
        REP(i, S.length()) dist[S[i] - 'a']++;
        REP(i, N_ALPH) chmin(A[i], dist[i]);
    }

    string ans = "";
    REP(i, N_ALPH) {
        if (A[i] == INF) continue;
        REP(j, A[i]) ans += ('a' + i);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

s = input()
s_list = list(s)
s_len = len(s_list)

hag = 0

for i in range(s_len//2):
  if s_list[i] != s_list[(s_len-1)-i]:
    s_list[(s_len-1)-i] = s_list[i]
    hag += 1
  
print(hag)


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

int main(){
  ll n, q;
  cin >> n >> q;
  vector<ll> ans;
  while(q--) {
    ll v, w;
    cin >> v >> w;
    v--; w--;
    if(n == 1) {
      ans.push_back(min(v,w));
      continue;
    }
    while(v != w) {
      if(v > w) swap(w,v);
      w = (w-1)/n; 
    }
    ans.push_back(w);
  }
  for(ll x : ans) cout << x+1 << endl;
  return 0;
}


Measured memory_bytes: 4264
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll A, B;
  char op;
  cin >> A >> op >> B;

  if(op == '+'){
    cout << A + B << endl;
  } else{
    cout << A - B << endl;
  }
  
  return 0;
}

Measured memory_bytes: 764
#include <cstdio>

#define N 1000

typedef long long int lli;

lli a[N*N];
lli b[N*N];
lli c[N*N];

int n,m,l;

void mult() {
    for(int i=0; i<n; i++)
        for(int j=0; j<l; j++)
            for(int k=0; k<m; k++)
                c[i*N + j] += a[i*N + k] * b[k*N + j];
}

int main(void) {
    scanf("%d%d%d",&n,&m,&l);

    for(int i=0; i<n; i++)
        for(int j=0; j<m; j++)
            scanf("%lld", &a[i*N + j]);
    for(int i=0; i<m; i++)
        for(int j=0; j<l; j++)
            scanf("%lld", &b[i*N + j]);
    for(int i=0; i<n; i++)
        for(int j=0; j<l; j++)
            c[i*N + j] = 0;

    mult();

    for(int i=0; i<n; i++)
    {
        for(int j=0; j<l-1; j++)
            printf("%lld ", c[i*N + j]);
        printf("%lld", c[i*N + l-1]);
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 9700
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<bitset>
#include<string>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cstdlib>
#include<cstring>
#include<sstream>
#include<iostream>
#include<algorithm>

#define For(i,x,y) for (int i=x;i<y;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second

#define dprintf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;

typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> Vi;

ll IN(){
	int c,f;ll x;
	while (!isdigit(c=getchar())&&c!='-');c=='-'?(f=1,x=0):(f=0,x=c-'0');
	while (isdigit(c=getchar())) x=(x<<1)+(x<<3)+c-'0';return !f?x:-x;
}

const int p=1e9+7;
const int N=300000+19;

struct QType{
	ll x,y;
	int id;
};vector<QType> Q[100];
ll F[100];
ll x,y;
vector<ll> V1,V2,V3,V4;
int ans1[N],ans2[N];
int n,q,res,mx;

int cal(ll a,ll b){
	if (a<b) swap(a,b);
	int res=0;
	for (;b;res++){
		ll tmp=a;a=b;b=tmp%b;
	}
	return res;
}

int main(){
	F[0]=1,F[1]=1;
	For(i,2,100) F[i]=F[i-1]+F[i-2];
	q=IN();
	For(i,1,q+1){
		x=IN(),y=IN();
		if (x>y) swap(x,y);
		if (x==1){
			ans1[i]=1;
			ans2[i]=y%p;
			continue;
		}
		if (y==2){
			ans1[i]=1;
			ans2[i]=4;
			continue;
		}
		for (n=0;F[n+1]<=x&&F[n+2]<=y;n++);
		ans1[i]=n;
		Q[n].pb((QType){x,y,i});
		mx=max(mx,n);
	}
	V1={1};
	V2={2};
	For(n,2,mx+1){
		V2.pb(F[n+1]);
		V3.clear();
		for (ll a:V1) for (ll b:V2) V3.pb(a+b);
		sort(V3.begin(),V3.end());
		V3.resize(unique(V3.begin(),V3.end())-V3.begin());
		V4.clear();
		for (ll b:V3)
			for (ll a:V2){
				if (a<b&&b<2*a&&cal(a,b)==n){
					V4.pb(b);
					break;
				}
			}
		V1=V2;V2=V4;
		for (ll a:V1){
			for (ll b:V2)
				if (a<b&&b<2*a&&cal(a,b)==n){
					for (QType A:Q[n]){
						if (a<=A.x&&b<=A.y){
							ans2[A.id]=(ans2[A.id]+(A.y-b)/a+1)%p;
						}
						if (a<=A.y&&b<=A.x){
							ans2[A.id]=(ans2[A.id]+(A.x-b)/a+1)%p;
						}
					}
				}
		}
	}
	For(i,1,q+1){
		printf("%d %d\n",ans1[i],ans2[i]);
	}
}


Measured memory_bytes: 16640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int M = 2e6 + 10;
const int N = 2e6;
ll fac[M], inv[M], f[M];
ll quick_mod(ll k, ll b)
{
    ll ans = 1;
    while(b)
    {
        if(b & 1) ans = ans * k % mod;
        k = k * k % mod;
        b >>= 1;
    }
    return ans;
}
void init() {
	fac[0] = 1;
	for (int i = 1; i <= N; i++) fac[i] = fac[i - 1] * i % mod;
	inv[N] = quick_mod(fac[N], mod - 2);
	for (int i = N - 1; i >= 0; i--) inv[i] = inv[i + 1] * (i + 1) % mod;
}
ll C(int n, int m)
{
    return (fac[n] * inv[n - m] % mod) * inv[m] % mod;
}
int main()
{
    int x, y;
    init();
    scanf("%d%d", &x, &y);
    x++, y++;
    if((x + y - 2) % 3 != 0)
    {
        printf("0\n");
        return 0;
    }
    int m = (x + y - 2) / 3;
    int n = m + 1;
    m = y - m;
    //printf("n = %d m = %d\n", n, m);
    if(m < 0 || m > n)
    {
        printf("0\n");
        return 0;
    }
    ll ans = C(n - 1, m - 1);
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 32768