akhauriyash/Code-Regression huggingface dataset:
# coding: utf-8

s = list(map(int, input().split(" ")))

snk = s[0]
oks = s[1]

v = []
for i in range(oks) :
    num = int(input())
    x = list(map(int, input().split(" ")))
    for j in range(num) :
        v.append(x[j])

ans = snk - len(set(v))

print(ans)

Measured memory_bytes: 9192
N = int(input())
H = list(map(int, input().split()))
count = 0
while sum(H) != 0:
    for i in range(N):
        if i == N - 1:
            if H[i] != 0:
                count += 1
        else:
            if H[i] != 0 and H[i+1] == 0:
                count += 1
        if H[i] > 0:
            H[i] -= 1
print(count)

Measured memory_bytes: 39152
'use strict'

function gcd(a,b){
    //console.log('gcd:',a,b);
    if(b===0){
        return a;
    }
    return gcd(b,a%b)
}

function Main(input) {
    let temp = input.trim().split('\n');
    let n = parseInt(temp[0]);
    let a = temp[1].split(' ').map((v)=>(parseInt(v)));

    a.sort((a,b)=>a-b);
    let x = gcd(a[1],a[0]);
    let ans = new Set([a[0],a[1]]);

    for(let i=2;i<n;i++){
        //console.log('start------',ans);
        let s = new Set();
        if(1<x){
            s.add(x);
            x = gcd(x,a[i]);
        }
        
        for(let j of ans){
            let y = gcd(j,a[i]);
            if(1<y) s.add(y);
        }
        ans = s;
        //console.log(ans);
    }
    let max = 1;
    for(let j of ans) if(max < j) max = j;
    console.log(max);

}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 31812
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
#define FOR(i, a, b) for(ll i=(a); i < (ll)(b); ++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;}

int main(){
	int n;
	cin >> n;
	vector<pair<int,int>> d(n);
	REP(i,n) cin >> d[i].first >> d[i].second;
	
	REP(i, n-2){
		if(d[i].first==d[i].second
		 && d[i+1].first==d[i+1].second
		 && d[i+2].first==d[i+2].second){
			 cout << "Yes\n";
			 return 0;
			 
		 }
	}
	
	cout << "No\n";
	return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

string S; int K;

int main() {
	cin >> K >> S;
	if (S.size() <= K) cout << S << endl;
	else cout << S.substr(0, K) << "..." << endl;
	return 0;
}

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

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
const long long INF =  999999999;
const long long M=1000000007;
ll N,a[300030],ans=0,bit[70];

int main(){

  cin>>N;
  ll c=0;
  REP(i,N){
    cin>>a[i];
    c=max(c,a[i]);
  }

  REP(i,60){
    ll n1=0;
    REP(j,N){
      //ビットが立っていた
      if(a[j]>>i &1){
        n1++;
      }
    }
    ll now=n1*(N-n1)%M;
    REP(j,i)now=now*2%M;
    ans+=now;
    ans%=M;
  }
  cout<<ans<<endl;
}


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

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int digit(int x) {
	int cnt = 0;
	while (x > 0) {
		cnt += x % 10;
		x /= 10;
	}
	return cnt;
}

signed main() {
	int n;
	cin >> n;
	set<int>se;
	rep(i, n) {
		int a;
		cin >> a;
		se.insert(a);
	}
	cout << se.size() << endl;

	return 0;
}



Measured memory_bytes: 7764
import java.util.Scanner;
public class Main {
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int l = scan.nextInt();
    int bited = 300;
    int sum = 0;
    for(int i = l; i < l + n; i++){
      sum += i;
      if(Math.abs(i) < Math.abs(bited)){
        bited = i;
      }
    }
    System.out.println(sum - bited);
  }
}

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


def solve(S: int):
    s_array = list(str(S))
    N = len(s_array) - 1

    sum = 0
    for bit in range(2 ** N):
        num_string = s_array[0]
        for i in range(N):
            if not (bit & 1 << i):
                sum += int(num_string)
                num_string = ""
            num_string += s_array[i + 1]
        sum += int(num_string)
    print(sum)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = int(next(tokens))  # type: int
    solve(S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 39536
#include <bits/stdc++.h>
using namespace std;
const int MOD =(int)(1e9)+7;
int main()
{
    int N,K;
    cin >> N >> K;
    vector<int>h(N);
    for(int i=0;i<N;i++){
        cin >> h[i];
    }
    sort(h.begin(),h.end());
    int ans=(int)(1e9)+10;
    for(int i=0;i<N-K+1;i++){
        ans=min(ans,abs(h[i]-h[i+K-1]));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(intl i=0;i<(intl)(n);i++)
#define Rep1(i,n) for(intl i=1;i<(intl)(n)+1;i++)
#define vec vector
#define fi first
#define se second
#define pushb push_back
#define popb pop_back
#define SortA(v) sort(v.begin(), v.end())
#define SortD(v) sort(v.rbegin(), v.rend())
using intl = int64_t;
using vi = vec<intl>;
using vvi = vec<vi>;
vec<intl> dx = {0, 1, 0, -1, 1, 1, -1, -1};
vec<intl> dy = {1, 0, -1, 0, 1, -1, 1, -1};

intl pow(intl a,intl n){
  intl ans=1;
  Rep(i,n) ans *=a;
  return ans;
}

int main(){
  deque<intl> lun;
  int k;
  cin >> k;
  int cnt = 0;
  Rep1(i,9){
    lun.push_back(i);
    cnt++;
    if (cnt == k) {cout << lun.back();return 0;}
  }
  
  while(cnt < k){
    intl num = lun.front();
    intl numfirstd = num % 10;
    
    for (int i=-1 ; i <=1 ; i++){
      if (numfirstd+i >= 0 && numfirstd +i <=9){
        lun.push_back(num*10 + numfirstd+i);
        cnt ++;
        if (cnt == k) {cout <<lun.back();return 0;}
      }
    }
    
    lun.pop_front();
  }
  
}
  

Measured memory_bytes: 4148
def main():
    s = input()
    ans = ''
    for ch in s:
        if ch == 'B' and len(ans) != 0:
            ans = ans[:-1]
        elif ch == 'B' and len(ans) == 0:
            ans = ''
        else:
            ans += ch

    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let s = read::<String>();
    let mut ans = vec![];
    for ch in s.chars() {
        if ch == 'B' {
            ans.pop();
        } else {
            ans.push(ch);
        }
    }
    println!("{}", ans.into_iter().collect::<String>());
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

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


Measured memory_bytes: 4352
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<functional>
#include <random>
#include<iostream>
#include<iomanip>
using namespace std;

int main() {
	int H, W, K;
	char S[10][1001];
	cin >> H >> W >> K;
	for (int i = 0; i < H; i++) {
		cin >> S[i];
	}

	int ans = H + W;

	for (int i = 0; i < (1 << (H - 1)); i++) {
//		cout << i << "\n";
		int block[20];

		int p = 1;
		block[0] = 0;
		for (int j = 0; j < H - 1; j++) {
			if ((i >> j) % 2 == 1) {
				block[p] = j + 1;
				p++;
			}
		}
		block[p] = H;

//		for (int j = 0; j < p; j++) {
//			cout << block[j] << " ";
//		}
//		cout << "p:" << p << "\n";
		/*この時点で、p-1回切って、ブロックはp個のはず*/
		
		int white[20];
		for (int j = 0; j < p; j++) {
			white[j] = 0;
		}
		int tate = 0;
		bool a_ok = true;
		for (int j = 0; j < W; j++) {
//			cout << "white:";
//			for (int k = 0; k < p; k++) {
//				cout << white[k] << " ";
//			}


//			cout << "white_now:";
			int q = 0;
			int white_now[20];

			for (int k = 0; k < p; k++) {
				white_now[k] = 0;
				for (int l = block[k]; l < block[k + 1]; l++) {
					if (S[l][j] == '1') { white_now[k]++; }
				}
				for (int k = 0; k < p; k++) {
					if (white_now[k] > K) {
						a_ok = false;
					}
				}
//				cout << white_now[k] << " ";
			}

			bool ok = true;
			for (int k = 0; k < p; k++) {
				if (white[k] + white_now[k] > K) {
					ok = false;
					break;
				}
			}
			if (!ok) {
//				cout << "kitta!";
				tate += 1;
				for (int k = 0; k < p; k++) {
					white[k] = 0;
				}
			}
			for (int k = 0; k < p; k++) {
				white[k] += white_now[k];
			}
//			cout << "\n";
		}
		if (a_ok) {
			int ansnow = p - 1 + tate;
//			cout << "ans:" << ansnow << "\n";
			if (ans > ansnow) { ans = ansnow; }
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#define rep(i,n) for (int i=0; i<n;++i)
#define rep_down(i,n) for (int i=n-1; i>=0;--i)
#define ALL(a)  (a).begin(),(a).end()
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;
const int INF = 1000000007;
int N;
int B[101];
int A[101];

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

  cin >> N;
  rep(i, N-1) cin >> B[i];
  A[0] = B[0];
  A[N-1] = B[N-2];
  rep(i, N-2){
    A[i+1] = min(B[i], B[i+1]);
  }
  int sm = 0;
  rep(i, N) sm += A[i];
  
  cout << sm << "\n";
  return 0;
}

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

int gcd(int x, int y) {
    if (y == 0) return x;
    return gcd(y, x%y);
}

int main() {
    int n, x; cin >> n >> x;
    vector<int> y(n+1);
    y[0] = x;
    for (int i = 1; i <= n; i++) {
        cin >> y[i];
    }
    
    sort(y.begin(), y.end());
    vector<int> dif(n);
    for (int i = 0; i < n; i++) {
        dif[i] = y[i+1] - y[i];
    }
    
    int ans = dif[0];
    for (int i = 1; i < n; i++) {
        ans = gcd(ans, dif[i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
import java.io.*;
import java.util.*;
import java.math.*;
     
public class Main{
	public static void main(String[] args) throws Exception {
	IO io = new IO();
	PrintWriter out = new PrintWriter(System.out);
	Solver sr = new Solver();
	sr.solve(io,out);
	out.flush();
	out.close();
    	}

	static class Solver
	{
	    void solve(IO io, PrintWriter out)
	    {
          String s = io.nextLine();
          if(s.contains("A") && s.contains("B"))
          	out.print("Yes");
          else
            out.print("No");
	    }
    	
	}
	//Special thanks to Petr (on codeforces) who inspired me to implement IO class!
	static class IO
	{
    	BufferedReader reader;
        StringTokenizer tokenizer;
    	public IO() {
                reader = new BufferedReader(new InputStreamReader(System.in));
                tokenizer = null;
            }
     
        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        public String nextLine() {
            String s="";
            try {
                    s=reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            return s;
        }
        public int nextInt() {
            return Integer.parseInt(next());
        }
    
        public long nextLong() {
            return Long.parseLong(next());
        }
    	double nextDouble()
    	{
    		return Double.parseDouble(next());
    	}
	}
}

Measured memory_bytes: 21332
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef long double ld;
const double pi=acos(-1.0);
const ll mod=pow(10,9)+7;
const ll INF=pow(2,31)-1;
using str=string;
typedef pair<int,int> P;
typedef vector<int> vi;

ll gcd(ll a,ll b){
    ll v0=a,v1=b,v2=a%b;
    while(v2!=0){
        v0=v1;
        v1=v2;
        v2=v0%v1;
    }
    return v1;
}

ll lcm(ll a,ll b){
    return (a*b/gcd(a,b));
}

int main(){
    ios::sync_with_stdio(false);
    int a[3][3],b[10],n;
    rep(i,3){
        rep(j,3){
            cin >> a[i][j];
        }
    }
    cin >> n;
    rep(i,n){
        cin >> b[i];
    }
    bool c[3][3];
    rep(i,3){
        rep(j,3){
            c[i][j]=false;
            rep(k,n){
                if(a[i][j]==b[k]) c[i][j]=true;
            }
        }
    }
    str ans="No";
    rep(i,3){
        if(c[i][0]&&c[i][1]&&c[i][2]) ans="Yes";
    }
    rep(i,3){
        if(c[0][i]&&c[1][i]&&c[2][i]) ans="Yes";
    }
    if(c[0][0]&&c[1][1]&&c[2][2]) ans="Yes";
    if(c[0][2]&&c[1][1]&&c[2][0]) ans="Yes";
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string.h>
#include <stack>
#include <queue>
#include <algorithm>
#include <climits>
#include <cmath>
#include <map>
#include <set>
#include <assert.h>
#define REP(i,n) for(ll i=0;i<(n);i++)
#define MOD 1000000007
#define int long long
#ifdef int
const long long INF = LLONG_MAX / 10;
#else
const int INF = 1010101010;
#endif
using namespace std;
typedef long long ll;
typedef vector<vector<ll>> mat;
typedef pair<int, int> P;
//typedef pair<double, double> P;

//約数の列挙O(√n)
vector<int> divisor(int n)
{
    vector<int> res;
    for (int i=1; i*i<=n; i++) {
        if (n % i == 0) {
            res.push_back(i);
            if (i != n / i) res.push_back(n / i);
        }
    }
    return res;
}

int n, s;

int f(int b, int n)
{
    if (n < b) return n;
    else return f(b, n / b) + n % b;
}

signed main()
{
    cin >> n >> s;

    if (s == n) {
        cout << n + 1 << endl;
        return 0;
    }

    for (int b=2; b*b<=n; b++) {
        if (f(b, n) == s) {
            cout << b << endl;
            return 0;
        }
    }

    vector<int> divs = divisor(n - s);
    set<int> ans;
    for (int div : divs) {
        int b = div + 1;
        if (f(b, n) == s) ans.insert(b);
    }

    if (ans.size() == 0) {
        cout << -1 << endl;
    } else {
        cout << *ans.begin() << endl;
    }
}


Measured memory_bytes: 256
from collections import Counter
N=int(input())
A=[int(i) for i in input().split(" ")]

A2=[i-A[i] for i in range(N)]
A3=[i+A[i] for i in range(N)]

c2=Counter(A2)
c3=Counter(A3)

retval=0
for key in c2+c3:
    retval+=c2[key]*c3[key]

print(retval)


Measured memory_bytes: 94232
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string>
typedef long long LL;
using namespace std;
typedef pair<int, int> Pii;
typedef pair<LL, LL> PLL;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int x = 0, y = 0, z = 0;
	int n, money;
	cin >> n >> money;
	int tmpn = n;
	y = money / 5000;
	for(int i = 0; i <= 20000; i++){
		for(int j = 0; j <= 4000; j++){
			LL l = money - ( 1000 * i + j * 5000);
			if(l < 0) break;
			if(!(l % 10000) && l/10000 + i + j == n){
				cout << l/10000  << ' ' << j  << ' ' << i << endl;
				return 0;
			}
		}
	}
	if(y == n){
		cout << x << ' ' << y << ' ' << z << endl;
		return 0;
	}
	cout << "-1" << ' ' << "-1" << ' ' << "-1" << endl;
	return 0;
}

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

public class Main {
  private static boolean debug = false;
  private static boolean elapsed = false;

  private static PrintWriter _err = new PrintWriter(System.err);

  private void solve(Scanner sc, PrintWriter out) {
    int a = sc.nextInt();
    int b = sc.nextInt();
    int h = sc.nextInt();
    out.println(((a + b) * h / 2));
  }
  private long C(long n, long r) {
    long res = 1;
    for (long i = n; i > n - r; --i) {
      res *= i;
    }
    for (long i = r; i > 1; --i) {
      res /= i;
    }
    return res;
  }
  private long P(long n, long r) {
    long res = 1;
    for (long i = n; i > n - r; --i) {
      res *= i;
    }
    return res;
  }
  /*
   * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
   * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
   */
  public static void main(String[] args) {
    long S = System.currentTimeMillis();

    Scanner sc = new Scanner(System.in);
    PrintWriter out = new PrintWriter(System.out);
    new Main().solve(sc, out);
    out.flush();

    long G = System.currentTimeMillis();
    if (elapsed) {
      _err.println((G - S) + "ms");
    }
    _err.flush();
  }
}

Measured memory_bytes: 9800
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=a;i>=(ll)b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

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

double distance(ddatas& x,ddatas& y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}
void judgement(int a){
  if(a){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  if(a){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}
int main(){
  ll i,j=0,N,M,ans=0;
  cin>>N>>M;
  vec v(N);
  pvec sv(N+1,datas(0,0));
  rep(i,N){
    cin>>v[i];
    sv[i+1]=datas(((sv[i].first+v[i]-1)%M+M)%M,i+1);
  }
  vsort(sv);
  rep1(i,N+1){
    if(sv[i].first==sv[j].first){
      while(sv[i].second-sv[j].second>=M)j++;
      ans+=i-j;
    }else{
      j=i;
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 4992
#include<iostream>
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
int n, q, v[300009], w[300009], h[300009], mxarr[2009];
vector<pair<int,int> > dp[300009];
int main()
{
    IO
    cin>>n;
    dp[0].push_back({0,0});
    for(int i=1; i<=n; i++)
        h[i]=h[i/2]+1;
    for(int i=1; i<=n; i++)
    {
        cin>>v[i]>>w[i];
        if(h[i]<=11)
        {
            dp[i]=dp[i/2];
            for(auto j : dp[i/2])
            {
                pair<int,int> p= {j.first+w[i],j.second+v[i]};
                if(p.first<=1e5)
                    dp[i].push_back(p);
            }
            sort(dp[i].begin(),dp[i].end());
        }
    }
    cin>>q;
    while(q--)
    {
        int node, L, ans=0;
        cin>>node>>L;
        if(h[node]<=11)
        {
            for(auto i : dp[node])
                if(i.first<=L)
                    ans=max(ans,i.second);
            cout<<ans<<"\n";
            continue;
        }
        vector<pair<int,int> > v1;
        v1.push_back({0,0});
        while(h[node]>11)
        {
            int sz=v1.size();
            for(int i=0; i<sz; i++)
            {
                pair<int,int> p= {v1[i].first+w[node],v1[i].second+v[node]};
                if(p.first<=L)
                    v1.push_back(p);
            }
            node=node/2;
        }
        sort(v1.begin(),v1.end());
        int curmx=0, id=0;
        while(!v1.empty())
        {
            int rem=L-v1.back().first;
            while(id+1<dp[node].size() && dp[node][id+1].first<=rem)
                id++, curmx=max(curmx,dp[node][id].second);
            ans=max(ans,v1.back().second+curmx);
            v1.pop_back();
        }
        cout<<ans<<"\n";
    }
}


Measured memory_bytes: 35392
#include<string>
#include<iostream>
  
using namespace std;
  
int main(){
    string s;
    getline(cin,s);
  
    for(int i=0;i<s.length();i++){
        if     (s.substr(i,5)=="apple")   s.replace(i,5,"peach");
        else if(s.substr(i,5)=="peach")   s.replace(i,5,"apple");
    }
  
    cout << s << endl;
}

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

const int MAX_N = 2e5;

int dp[MAX_N+1];

int main()
{
    int n,m;
    cin>>n>>m;
    
    vector<vector<int>> adj_list(MAX_N+1);
    vector<int> degree(MAX_N+1);
    
    for(int i=0;i<m;i++)
    {
        int x,y;
        cin>>x>>y;
        
        adj_list[y].push_back(x);
        degree[x]++;
    }
    
    vector<int> BFS;
    
    for(int i=1; i<=n; i++)
    {
        if(degree[i]==-0) BFS.push_back(i);
    }
    
    while(!BFS.empty())
    {
        vector<int> new_BFS;
        
        for(auto u:BFS)
        {
             for(auto v:adj_list[u])
             {
                 dp[v]=max(dp[v],1+dp[u]);
                 //cout << v << " " << dp[v] << endl;
                 
                 degree[v]--;
                 if(degree[v]==0)
                 {
                     new_BFS.push_back(v);
                 }
             }
        }
        
        BFS=new_BFS;
    }
    
    int max_path=0;
    
    for(int i=1; i<=n; i++)
    {
        max_path=max(max_path,dp[i]);
    }
    cout << max_path << endl;
}

Measured memory_bytes: 9216
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;

namespace atcorder2
{
    class Program
    {
        public static long Read()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {

            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }

        public static void swap(ref long x,ref long y)
        {
            var tmp = x;
            x = y;
            y = tmp;
        }
        

        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            var n = Read();
            var p = Reads();
            long ans = 0;

            if (p[0] == 1) { swap(ref p[0], ref p[1]);  ans++; }  
            for (int i = 1; i < n-1; i++)
            {
                if (p[i] == i + 1)
                {
                    if (p[i - 1] == i) swap(ref p[i], ref p[i - 1]);
                    else if (p[i + 1] == i + 2) swap(ref p[i], ref p[i + 1]);
                    else swap(ref p[i], ref p[i - 1]);
                    ans++;
                }
            }
            if (p[n - 1] == n) { swap(ref p[n - 2], ref p[n - 1]); ans++; }

            Console.WriteLine(ans);





            Console.Out.Flush();
        }
    }
}

Measured memory_bytes: 21216
#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp make_pair
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

vector<int> diameter(int n, vector<pair<int,int>> *vec){
  if(n==1) return {0};
  vector<long> dist(n);
  vector<int> pre(n);
  auto bfs = [&](int ini){
    queue<pair<int,int>> q;
    q.push({ini,-1});
    dist[ini] = 0;
    int farthest = ini;
    while(q.size()){
      auto p = q.front(); q.pop();
      int v = p.first;
      int from = p.second;
      if(dist[farthest] < dist[v]){
        farthest = v;
      }
      for(auto pp : vec[v]) if(pp.first!=from){
        int to = pp.first;
        q.push({to, v});
        dist[to] = dist[v] + pp.second;
        pre[to] = v;
      }
    }
    return farthest;
  };
  int p = bfs(0);
  int q = bfs(p);
  int cur = q;
  vector<int> res;
  res.push_back(cur);
  while(cur != p){
    cur = pre[cur];
    res.push_back(cur);
  }
  assert(res[0]==q && res.back()==p);
  return res;
}

const int N = 100005;
vector<pair<int,int>> tree[N];

int main(){
  int n;
  cin>>n;
  rep(i,n-1){
    int a,b,c;
    cin>>a>>b>>c;
    tree[a].pb({b,c});
    tree[b].pb({a,c});
  }

  auto dia = diameter(n, tree);
  int m = dia.size();
  long ans = 0;
  //dbg(dia);
  rep(i,m-1){
    for(auto to : tree[dia[i]]) if(to.first == dia[i+1]) ans += to.second;
  }

  cout << ans << endl;

  return 0;
}



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

int main() {
  int N;
  cin>>N;
  
  vector<int> a(N),b(N);
  for(int i=0; i<N; i++){
    cin>>a.at(i);
    b.at(i) = a.at(i);
  }
  sort(a.begin(), a.end());
  int x, y;
  x = a.at(N-1);
  y = a.at(N-2);
  
  for(int i=0; i<N; i++){
    if(b.at(i) == x) cout<<y<<endl;
    else cout<<x<<endl;
  }
}

Measured memory_bytes: 4852
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main(){
  char s[101];
  cin>>s;
  bool easy=true;
  //left
  for(int i=1;i<strlen(s);i+=2){
    if(s[i]=='R'){
      easy=false;
      break;
    }
  }
  //right
  for(int i=0;i<strlen(s);i+=2){
    if(s[i]=='L'){
      easy=false;
      break;
    }
  }
  if(easy)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	char s[25];
	scanf("%s",s);
	int ytf=0,i;
	for(i=0;s[i]!=0;i++){
		if(s[i]!='/'){
			ytf=ytf*10+s[i]-'0';
		}
	}
	if(ytf<=20190430)puts("Heisei");
	else puts("TBD");
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
#define forn(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define fore(i,b,a)for(int i=(b),_a=(a);i>=_a;i--)
#define rep(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pii>
#define m_p make_pair
#define re return
#define pb push_back
#define si set<int>
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define mod 1000000007
#define INF 1000000007
#define x1 XZVJDFADSPFOE
#define y1 GASDIJSLDAEJF
#define x2 DFDAJKVOHKWIW
#define y2 PSFSAODSXVNMQ
#define LLINF 0x3f3f3f3f3f3f3f3fLL
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
ll quickpower(ll n,ll k){
	ll ans=1;
	while(k){
		if(k%2){
			ans*=n;
			ans%=mod;
		}
		n*=n;
		n%=mod;
		k/=2;
	}
	return ans;
}
string int_to_string(int n)
{
	string s="";
	while(n)
	{
		int now=n%10;
		s+=now+'0';
		n/=10;
	}
	reverse(s.begin(),s.end());
	return s;
}
int string_to_int(string s)
{
	int n=0;
	rep(i,s.size())
	{
		n*=10;
		n+=s[i]-'0';
	}
	return n;
}
bool use[111];
int main()
{
	ios::sync_with_stdio(0);
	//think twice,code once
	int n,m;
	cin>>n>>m;
	rep(i,m)
	{
		int k;
		cin>>k;
		rep(j,k)
		{
			int kk;
			cin>>kk;
			if(use[kk]==0)
			{
				use[kk]=1;
				n--;
			}
			}	
	 } 
	 cout<<n<<endl;
	return 0;
}



Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits.h>
#include <climits>
#include <map>
#include <unordered_map>
#define _USE_MATH_DEFINES
#include <cmath>
#include <set>
#include <unordered_set>
#include <iterator>
#include <deque>
#include <assert.h>
#include <cstdlib>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
ull min(ull x, ull y){ if (x<y) return x; return y;}
ull max(ull x, ull y){ if (x<y) return y; return x;}
ll min(ll x, ll y){ if (x<y) return x; return y;}
ll max(ll x, ll y){ if (x<y) return y; return x;}
double min(double x, double y){ if (x<y) return x; return y;}
double max(double x, double y){ if (x<y) return y; return x;}
ull gcd(ull x, ull y){
    if (!x) return y;
    if (!y) return x;
    if (x>y) swap(x,y);
    return gcd(x, y%x);
}
ull inv(ull a, ull c){ // a,c are coprime and a<c
    if (a==1){
        return 1;
    }
    return ((c-(c/a))*inv(c%a,c))%c;
}

ll n;

int sol(){
    ll i = 2;
    int ans = 0;
    while (i<=sqrt(n)){
        if (n%i==0){
            int cnt = 0;
            while (n%i==0){
                cnt++;
                n/=i;
            }
            int sum = 0;
            for (int j = 1; j <= cnt; ++j){
                if (sum+j>cnt) break;
                ans++;
                sum += j;
            }
        }
        else{
            i++;
        }
    }
    if (n>=2) ans++;
    return ans;
}

int main(){
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    
    cin>>n;
    cout<<sol()<<"\n";


    return 0;
}


Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define all(x) (x).begin(),(x).end()
#define S(x) (int)(x).size()
#define L(x) (int)(x).length()
#define debug(x) cerr << #x << " " << x << endl;
#define debug_p(x) cerr << #x << " [" << x.fi << " " << x.se << "]"<<endl;
#define debug_v(x) {cerr << #x << " "; for (auto ioi : x) cerr << ioi << " "; cerr << endl;}
#define debug_vp(x) {cerr << #x << " "; for (auto ioi : x) cerr << '[' << ioi.fi << " " << ioi.se << ']'; cerr << endl;}
#define debug_v_v(x) {cerr << #x << "/*\n"; for (auto ioi : x) { for (auto ioi2 : ioi) cerr << ioi2 << " "; cerr << '\n';} cerr << "*/" << #x << endl;}
#define gen_clock(x) ll x = clock(); cerr << "Clock " << #x << " created" << endl;
#define check_clock(x) cerr << "Time spent in " << #x << ": " << (double)(clock() - x)/CLOCKS_PER_SEC << endl; x = clock();
#define reset_clock(x) x = clock()
 
const int mod = 1e9+7;
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;
 
void solve()
{
	ll n,k;
	cin>>n>>k;
	ll a[n];
	for(ll i=0;i<n;i++)
	cin>>a[i];
	sort(a,a+n);
	ll ct=0;
	for(ll i=0;i<k;i++)
	ct+=a[i];
	cout<<ct;
}

 
int main()
{
	IOS
	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
}


Measured memory_bytes: 3612
open Batteries

let read_two () = Scanf.sscanf (read_line ()) "%d %d" (fun a b -> (a, b))

let read_three () =
  Scanf.sscanf (read_line ()) "%d %d %d" (fun a b c -> (a, b, c))

let read_four () =
  Scanf.sscanf (read_line ()) "%d %d %d" (fun a b c d -> (a, b, c, d))

(* a**x *)
let pow a x =
  let rec aux acc = function 0 -> acc | n -> aux (acc * a) (n - 1) in
  aux 1 x

let () =
  let a, b = read_two () in
  let pow_b = string_of_int b |> String.length in
  let n = b + (a * pow 10 pow_b) in
  let max_i = float_of_int n |> sqrt |> int_of_float in
  let ans = ref false in
  for i = 1 to max_i + 1 do
    if i * i = n then ans := true else ()
  done;
  if !ans then print_string "Yes\n" else print_string "No\n"


Measured memory_bytes: 1024
#!/usr/bin/perl

$all = "abcdefghijklmnopqrstuvwxyz";

$line = 0;
while (<>) {
    chomp;
    if($line == 0) {
        @s = split //, $_
    } else {
    }
    $line++;
}

@all = split //, $all;

foreach (@s) {
    $e{$_}++;
}

foreach (@all) {
    if(!defined $e{$_}) {
        print "$_\n";
        exit;
    }
}
print "None\n";


Measured memory_bytes: 13952
def P(n):#素数判定のアルゴリズム(O(√n))
    if type(n)!=int:raise TypeError#自然数以外はエラーを返す
    if n<1:raise ValueError#1未満は定義域を外れています
    if n==1:return -1#1は素数でも合成数でもないので負数を返す
    if n%2==0and n!=2:return 2#高速化用に2を別で判定
    a=3
    while a*a<n:#nの平方根以下のすべての奇数で割れるか判定
        if n%a==0:return a#割り切れたら最小の素因数を返す
        a+=2#奇数のみの判定なので偶数を飛ばせる
    return 0#割れなかったら(素数なら)0を返す
import math
a=int(input())
while P(a):a+=1
print(a)

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

int main(){
  long long int H, N;
  cin >> H >> N;
  vector<long long int> A(N);
  long long int attack = 0;
  for(long long int i = 0; i < N; i++) cin >> A[i];
  for(long long int i = 0; i < N; i++) attack += A[i];
  if(H <= attack) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 4008
from collections import deque
    
def bfs(graph,start): #def bfs(graph,start,limit): 
    dist = [-1] * (N)
    ans = [-1] *(N)
    dist[start]= 0
    q = deque([start])
    cnt = 0
    while q:
        x = q.popleft()
        for i in graph[x]:
            #if dist[x] >= limit:
            #    break
            if dist[i] == -1:
                dist[i] = dist[x] + 1
                ans[i] = x+1
                q.append(i)
    return dist, ans

N,M  = map(int,input().split())# 頂点数
X = [[] for i in range(N)] #辺リスト

for i in range(M):
    x, y = map(int, input().split())
    X[x-1].append(y-1)
    X[y-1].append(x-1)

dist,ans = bfs(X,0)
#print(dist,ans)
if -1 in dist:
    print("No")
else:
    print("Yes")
    for i in range(1,N):
        print(ans[i])

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

class imos2
{
public:
	void addInc( long long int x, long long int y ) {
		inc.emplace_back( make_pair( x, y ) );
		incsortflag = false;
	}

	void addDec( long long int x, long long int y ) {
		dec.emplace_back( make_pair( x, y ) );
		decsortflag = false;
	}

	pair<long long int, long long int> ans( long long int R ) {
		pair<long long int, long long int>ret = make_pair( 0, 0 );
		if( !incsortflag ) {
			for( auto now : inc ) {
				incymax = max( incymax, now.second );
				incymin = min( incymin, now.second );
			}
			sort( inc.begin(), inc.end() );
			incsortflag = true;
		}
		if( !decsortflag ) {
			for( auto now : dec ) {
				decymax = max( decymax, now.second );
				decymin = min( decymin, now.second );
			}
			sort( dec.begin(), dec.end() );
			decsortflag = true;
		}
		long long int ymin = min( incymin, decymin ), ymax = max( incymax, decymax );
		vector<long long int>tmp1( ymax - ymin + 1 );
		vector<long long int>tmp2( ymax - ymin + 1 );
		long long int incidx = 0, decidx = 0;
		for( long long int i = inc[0].first; i <= dec[dec.size() - 1].first; i++ ) {
			while( incidx < inc.size() && inc[incidx].first == i&&inc[incidx].second <= ymax ) {
				tmp2[inc[incidx].second - ymin]++;
				incidx++;
			}
			while( decidx < dec.size() && dec[decidx].first == i&&dec[decidx].second <= ymax ) {
				tmp2[dec[decidx].second - ymin]--;
				decidx++;
			}
			for( long long int j = 0; j < ymax - ymin; j++ ) {
				tmp2[j + 1] += tmp2[j];
			}
			for( long long int j = 0; j < ymax - ymin + 1; j++ ) {
				tmp2[j] += tmp1[j];
				//cout << setw( 2 ) << tmp2[j];
				if( tmp2[j] ) {
					ret.first++;
				}
				if( R == 2 ) {
					if( (!tmp2[j]) != (!tmp1[j]) ) {
						ret.second++;
					}
					if( j > 0 && (!tmp2[j]) != (!tmp2[j - 1]) ) {
						ret.second++;
					}
				}
			}
			if( tmp2[0] ) {
				ret.second++;
			}
			tmp1 = tmp2;
			tmp2 = vector<long long int>( ymax - ymin + 1 );
		}
		return ret;
	}


	vector<pair<long long int, long long int>>inc;
	vector<pair<long long int, long long int>>dec;

	bool incsortflag;
	bool decsortflag;

	long long int incymax = LLONG_MIN, decymax = LLONG_MIN;
	long long int incymin = LLONG_MAX, decymin = LLONG_MAX;
};

int main() {
	long long int N, R;
	while( cin >> N >> R, N || R ) {
		imos2 imos;
		for( size_t i = 0; i < N; i++ ) {
			long long int x1, y1, x2, y2;
			cin >> x1 >> y1 >> x2 >> y2;
			imos.addInc( x1, y1 );
			imos.addInc( x2, y2 );
			imos.addDec( x1, y2 );
			imos.addDec( x2, y1 );
		}
		auto memo = imos.ans( R );
		if( R == 1 ) {
			cout << memo.first << endl;
		} else {
			cout << memo.first << endl << memo.second << endl;
		}

	}
	return 0;
}

Measured memory_bytes: 3924
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>
#include <stack>
using namespace std;
 
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define ktya(x) sort(all(x))
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 1e18
#define INFLL 1000000000000000007LL
#define SIZE 200105
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define PI (acos(-1))
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
ll MOD = 1000000007;
// ll MOD=998244353;
typedef ll Weight;
struct Edge {
	int src, dst;
	ll weight;
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
	e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
ll powMod(ll x, ll k, ll m) {//x^k (mod n)
	if (k == 0)     return 1;
	if (k % 2 == 0) return powMod(x*x % m, k/2, m);
	else            return x*powMod(x, k-1, m) % m;
}
int N,M;
int lefmos[27][114514];
int main(){
	string s,t;
	cin>>s>>t;
	int sz=s.size();
	rep(i,sz+1)rep(j,26)lefmos[j][i]=-1;
	for(int i=sz-1;i>=0;i--){
		int x=s[i]-'a';
		rep(j,26){
			if(j!=x){
				if(lefmos[j][i+1]!=-1){
					lefmos[j][i]=lefmos[j][i+1]+1;
				}
			}else{
				lefmos[x][i]=0;
				//cout<<x<<endl;
			}
		}
	}
	bool flag=true;
	ll ansx=1;
	ll ansy=-1;
	rep(j,t.size()){
		int x=t[j]-'a';
		if(lefmos[x][0]==-1)flag=false;
		else{
			
			int LEF=lefmos[x][int((ansy+1)%sz)];
			if(LEF==-1){
				ansx+=1;
				ansy=lefmos[x][0];
			}else{
				if(ansy+1==sz){
					ansx+=1;
					ansy=LEF;
				}else{
					ansy=ansy+1+LEF;
				}
			}
			//cout<<ansx<<" "<<ansy<<" "<<(ansx-1)*sz+ansy+1<<endl;

		}
	}
	if(flag){
		cout<<(ansx-1)*(ll)sz+ansy+1<<endl;
	}else{
		cout<<-1<<endl;
	}

}



Measured memory_bytes: 11776
def base_10_to_n(X,n):
    X_dumy=X
    out= ''
    while X_dumy>0:
        out=str(X_dumy%n)+out
        X_dumy=int(X_dumy/n)
    return out

N,K=map(int,input().split())

X =len(base_10_to_n(N,K))
print(X)


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

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

	int n, k;
	cin >> n >> k;
	vector<pair<int, int>> ed;
	for (int i = 1; i < n; i++) {
		ed.push_back({0, i});
	}
	int cans = (n - 1) * (n - 2) / 2;
	if (cans < k) {
		cout << -1 << endl;
		exit(0);
	}
	for (int i = 1; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			if (cans > k) {
				ed.push_back({i, j});
				cans--;
			}
		}
	}
	if (cans == k) {
		cout << ed.size() << endl;
		for (auto t : ed) {
			cout << t.first + 1 << ' ' << t.second + 1 << endl;
		}
	} else {
		cout << -1 << endl;
	}
}


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

template <typename A, typename B>
string to_string(pair<A, B> p);
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
 
string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char& ch) {
	string s = "";
	s += ch;
	return "'" + s + "', ";
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
 
void debug_out() { cout << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef LOCAL_DEFINE
#define debug(...) cout << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
   
#define int long long
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
typedef pair<int, int> pii;
const int mod = (int) 1000000007; // 998244353;
const int inf = (int) 2e18;



int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(9);
	#ifdef LOCAL_DEFINE
		freopen("in.txt", "rt", stdin);
	#endif
	
	
	int n;
	cin >> n;
	int x = 0;
	vector<int> a(n);
	for(int& tmp : a)
	{
		cin >> tmp;
		x ^= tmp;
	}
	
	for(int i = 0; i < n; ++ i)
	{
		// debug(x, a[i]);
		int is = x ^ a[i];
		// debug(is);
		cout << is << " ";
		// cout << x ^ a[i] << " ";
	}
	cout << '\n';
	
	return 0;
}






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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int f(int n) {
  if(n % 2) return 3 * n + 1;
  else return n / 2;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int s; cin >> s;
  vector<bool> sel(1000100);
  sel[s] = true;
  int cnt = 1;

  while(1) {
    s = f(s);
    cnt++;
    if(sel[s]) break;
    sel[s] = true;
  }
  cout << cnt << endl;

}


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

const int Maxn = 100005;

int n;
int a[Maxn];

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        scanf("%d", &a[i]);
    vector <int> seq;
    for (int i = n - 1; i >= 0; i--) {
        int ind = upper_bound(seq.begin(), seq.end(), a[i]) - seq.begin();
        if (ind < seq.size()) seq[ind] = a[i];
        else seq.push_back(a[i]);
    }
    printf("%d\n", int(seq.size()));
    return 0;
}


Measured memory_bytes: 1276