akhauriyash/Code-Regression huggingface dataset:
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#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 <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define FILL(ptr, value) FILL_((ptr), sizeof(ptr)/sizeof(value), (value))
template <typename T>
void FILL_(void * ptr, size_t size, T value){
  std::fill((T*)ptr, (T*)ptr+size, value);
}
//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};
int w,h;
char board[25][25];
int sx,sy;
int nx,ny;
int ans;
void dfs(int x,int y){
  board[y][x] ='#';
  for(int j = 0;j <4;j++){
    nx =x +dx[j];
    ny =y +dy[j];
    if(nx <1 ||nx >w||ny <1 ||ny >h)
      continue;
    if(board[ny][nx] =='.'){
      ans++;
      dfs(nx,ny);
    }
  }
}

int main()
{
  while(cin>>w>>h,w||h){
    ans = 1;
    for(int i = 1;i <=h;i++){
      for(int j = 1;j <=w;j++){
	cin>>board[i][j];
      }
    }
    for(int i = 1;i <=h;i++){
      for(int j = 1;j <=w;j++){
	if(board[i][j] =='@'){
	  sx = j;
	  sy = i;
	  dfs(j,i);
	}
      }
    }
    cout <<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1168
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(n);++i)
#define _repe3(i,a,b) for(ll i=(a);i<=(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
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<class T>
using pq=priority_queue<T,vector<T>,greater<T>>;

void solve(ll K);

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    ll K;
    cin >> K;
    solve(K);
}

ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
void solve(ll K){
    ll sum=0;
    repe(i,1,K)repe(j,1,K)repe(k,1,K){
        ll tmp=gcd(gcd(i,j),k);
        sum+=tmp;
    }
    cout<<sum<<endl;
}



Measured memory_bytes: 3636
n = int(input())

fibs = [0 for _ in range(n+1)]
# checks = [False for _ in range(n+1)]

def fib(k):
    for i in range(k+1):
        if i == 0:
            fibs[i] = 1
        elif i == 1:
            fibs[i] = 1
        else:
            fibs[i] = fibs[i-1] + fibs[i-2]
    return fibs[k]

print(fib(n))


Measured memory_bytes: 5604
#pragma GCC optimize("Ofast,inline,unroll-loops,fast-math")
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define mod 1000000007
#define mod1 998244353
#define INF LLONG_MAX
#define NINF LLONG_MIN
#define inf 1e18
#define all(v) v.begin(),v.end()
#define T ll test;cin>>test; while(test--)
#define rep(i,a,n) for(ll i=a;i<(long long)n;++i)
#define rep1(i,a,n) for(ll i=a;i<=(long long)n;++i)
#define rep2(i,n,a) for(ll i=n;i>(long long)a;--i)
#define rep3(i,n,a) for(ll i=n;i>=(long long)a;--i)
#define repi(i,a,n) for(int i=a;i<=(int)n;++i)
#define repl(i,a,n) for(int i=a;i<(int)n;++i)
#define PI 3.141592653589793238510
#define en '\n'
#define MAX 100005
#define less_time ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define debug cout<<"HERE"<<en;
#define setbits(x)  __builtin_popcountll(x)
#define zrobits(x)  __builtin_ctzll(x)
#define ps(x,y) fixed<<setprecision(y)<<x
#define mk(arr,n,type) type *arr=new type[n];
#define F first
#define S second
#define LB lower_bound
#define UB upper_bound
#define vc vector
#define vi vc<int>
#define mii unordered_map<int,int>
#define pql priority_queue<int>
#define pqs priority_queue<int,vi,greater<int>>
#define vll vector<long long>
#define pll pair<long long,long long>
#define pl pair<int,int>
#define eb emplace_back
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
using namespace std;
using namespace std::chrono;
int main(){
    less_time;
    int n,k;
    cin>>n>>k;
    int h[MAX]={0};
    repi(i,1,n)cin>>h[i];
    int dp[MAX];
    repl(i,0,MAX)dp[i]=INT_MAX;
    dp[1]=0;
    dp[2]=abs(h[2]-h[1]);
    repi(i,3,n)
    {
      repi(j,1,k)
      {
        if(i-j>=1)
        dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
      }
    }
    cout<<dp[n];
return 0;
}


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

set<string>st;

void f(string s)
{
   // cout<<s<<endl;
    if(s.size()>=11)return ;
   if(s[0]=='0')return;
    int flag=0;

    for(int i=0;i<s.size();i++)
    {
       // if(i+1<s.size()&&s[i]==s[i+1])flag++;
         if(i+1<s.size()&&abs(s[i]-s[i+1])>1)flag++;
    }

    if(flag>0)return ;
//cout<<s<<endl;
    st.insert(s);

        for(char i='0';i<='9';i++)
        {
            f(s+i);
        }
}


int main()
{
    string s="";
    f(s);
    vector<long long>v;
    for(auto it=st.begin();it!=st.end();it++)
    {
       long long num=0;
       string r=*it;
       reverse(r.begin(),r.end());
       long long p=1;
       for(int i=0;i<r.size();i++)
       {
           num+=p*(char(r[i]-'0'));
           p*=10;
       }
       v.push_back(num);
    }
  sort(v.begin(),v.end());
int n;
cin>>n;
cout<<v[n]<<endl;

}


Measured memory_bytes: 21108
package main

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

func main() {
	parseProblem(os.Stdin)
}

func parseProblem(r io.Reader) {
	const (
		initialBufSize = 100000
		maxBufSize     = 1000000
	)
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	a, b := scanString(sc), scanString(sc)
	i, _ := strconv.Atoi(a + b)
	p := int(math.Sqrt(float64(i)))
	if p*p == i || (p+1)*(p+1) == i {
		fmt.Println("Yes")
		return
	}
	fmt.Println("No")
	return
}

func resolve(n int) int {
	return n
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
typedef pair<ll,ll> pll;
void read(int& x){ scanf("%d",&x); }
void read(ll& x){ scanf("%lld",&x); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define x first
#define y second

int n;
int x[300010];

void in(){
	read(n);
	for(int i=1; i<=3*n; ++i) read(x[i]);
}

pp xs[300010]; int xn;
void comp(){
	for(int i=1; i<=3*n; ++i){
		xs[xn++] = pp{x[i], i};
	}
	sort(xs, xs+xn);
}

struct TREE {
	static const int M=524288;

	ll tree[M<<1];
	int tcnt[M<<1];

	void tadd(int i, int c){
		int p = lower_bound(xs, xs+xn, pp{x[i], i}) - xs;
		p += M;
		while(p){
			tree[p] += x[i]*c;
			tcnt[p] += c;
			p>>=1;
		}
	}
	
	ll lowk(int k){
		if(k == 0) return 0;
		int p=1;
		ll ret=0;
		while(p<M){
			p *= 2;
			if(tcnt[p] <= k){
				k -= tcnt[p];
				ret += tree[p++];
			}
		}
		return ret;
	}
} lt, rt;

ll ans;

void proc(){
	for(int i=1; i<=n; ++i) lt.tadd(i, 1);
	for(int i=n+1; i<=3*n; ++i) rt.tadd(i, 1);
	ans = lt.tree[1] - rt.lowk(n);
	for(int i=n; i<=2*n; ++i){
		if(i > n){
			lt.tadd(i, 1);
			rt.tadd(i, -1);
		}
		/*for(int j=1; j<=i; ++j) printf("%d ", x[j]); printf("/ ");
		for(int j=i+1; j<=3*n; ++j) printf("%d ", x[j]); 
		printf(": left sum %lld, min(%d): %lld, right min %d: %lld\n", lt.tree[1],
				i-n, lt.lowk(i-n), n, rt.lowk(n));*/
		ans = max(ans, lt.tree[1] - lt.lowk(i-n) - rt.lowk(n));
	}
	printf("%lld\n", ans);
}

int main()
{
	in(); comp(); proc();
    return 0;
}


Measured memory_bytes: 27520
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
typedef long long ll;
int main(){
    ll n,m,sum,temp,count;
    cin >> n >> m;
    vector<ll> v;
    bool judge = false;
    sum = 0;
    count = 0;
    for(ll i = 0; i < n; i++){
        cin >> temp;
        sum += temp;
        v.push_back(temp);
    }
    sort(v.begin(),v.end(),std::greater<int>());
    for(int i = 0; i < v.size(); i++){
        if(v[i] >= sum / (4.0 * m)){
            count++;
        }
        if(count == m){
            judge = true;
            break;
        }
    }
    if(judge) cout << "Yes" << endl;
    else cout << "No" << endl;

}

Measured memory_bytes: 256
n=int(input())
s=input()

ans=0
for i in range(n):
    sl=set()
    sr=set()
    for j in range(n):
        if j<=i:
            sl.add(s[j])
        else:
            sr.add(s[j])
    ans=max(ans,len(sl & sr))
print(ans)



Measured memory_bytes: 2940
import java.util.*;

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

        int a = sc.nextInt();
        int b = sc.nextInt();

        System.out.print(task(a,b));
    }

    public static int task(int a,int b){
        int x = Math.max(a+(a-1),b+(b-1));
        int y = Math.max(a + b,x);
        return y;
    }
}

Measured memory_bytes: 21716
#include<iostream>
#include<algorithm>
#include <cassert>
#include<string>
#include<vector>
#include <utility>
#include <math.h>
#include<cmath>
# include <set>
# include <iomanip>
# include <functional>
# include <queue>
#define INF 1000000009;
using namespace std;
int gcd(int a, int b) {
	while (a % b != 0) {
		int c = 0;
		c = a % b;
		a = b;
		b = c;
	}
	return  b;
}


int main() {
	int N = 0, A[200005] = { 0 }, copy[200005] = { 0 };
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		copy[i] = A[i];
		//cout << copy[i] << endl;
	}
	sort(A, A + N,greater<int>());
	for (int i = 0; i < N; i++) {
		if (copy[i] == A[0]) {
			cout << A[1] << endl;
			
		}
		else {
			cout << A[0] << endl;
			
		}
	}
	return 0;
}

Measured memory_bytes: 3200
#[allow(unused_imports)]
use std::cmp;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::vec::Vec;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        a: [usize; n],
    }
    let avg = Iterator::sum::<usize>(a.iter()) as f64 / a.len() as f64;
    // eprintln!("{}", avg);
    let min = a
        .iter()
        .map(|&x| (x as f64 - avg).abs())
        .fold(0.0 / 0.0, |m, v| v.min(m));
    let result = a
        .iter()
        .enumerate()
        .filter(|&(_, &x)| (x as f64 - avg).abs() == min)
        .next()
        .unwrap()
        .0;
    println!("{}", result);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

Graph G;
vector<int>ans;
int main() {
	init();

	int N, M; cin >> N >> M;
	G.resize(N);
	rep(i, 0, M) {
		int a, b;
		cin >> a >> b;
		--a;--b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	if (G[0].size() == 0)cout << "No" << "\n";
	else {
		ans.resize(N,-1);
		ans[0] = 0;
		//bfs
		queue<int>que;
		que.push(0);
		while (!que.empty()) {
			int now = que.front();
			que.pop();
			for (auto v : G[now]) {
				if (ans[v] != -1)continue;
				ans[v] = now;
				que.push(v);
			}
		}

		bool ok = true;
		rep(i, 1, N) {
			if (ans[i] == -1)ok = false;
		}
		if (ok) {
			cout << "Yes" << "\n";
			rep(i, 1, N) {
				cout << ans[i] + 1 << "\n";
			}
		}
		else cout << "No" << "\n";
	}



	return 0;
}

Measured memory_bytes: 10328
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define N 100000
typedef long long ll;
#define all(v) (v).begin(),(v).end()
int main(){
	int n,m;
	cin>>n>>m;
	vector<int> xm(m);
	rep(i,m){
		cin>>xm.at(i);
	}
	vector<int> dx(m-1);
	ll ans=0;
	if(m>n){
		sort(all(xm));
		rep(k,m-1){
			dx.at(k)=xm.at(k+1)-xm.at(k);
		}
		sort(all(dx));
		rep(l,m-n){
			ans+=dx.at(l);
		}
	}else{
		ans=0;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
def f(i,s,t):
    if i==3:
        if t==7:
            print(s + '=7')
            exit()
    
    else:
        f(i+1,s+'-'+a[i+1],t-int(a[i+1]))
        f(i+1,s+'+'+a[i+1],t+int(a[i+1]))

a=input()
f(0,a[0],int(a[0]))

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

typedef long long ll;
const int maxn=1e6+7;
const int inf=INT_MAX;
const ll inff=1e18;
const ll mod=1e9+7;
#define pii pair<int,int>
#define mkp make_pair
#define F first
#define S second
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//#define int ll
//#define endl '\n'

int n,m,x,y;
set<pii> u,v;
vector<int> G[maxn];
int cnt[maxn],used[maxn];

void dfs(int now)
{
    used[now]=1;
    for (int i:G[now])
    {
        if (!used[i])
        {
            dfs(i);
            u.insert(mkp(min(now,i),max(now,i)));
        }
    }
}

void dfs2(int now,int p)
{
    used[now]=1;
    for (int i:G[now])
    {
        if (!used[i])
        {
            dfs2(i,now);
            //u.insert(mkp(min(now,i),max(now,i)));
        }
    }
    if (p!=-1)
    {
        if (cnt[now]&1) cout<<now<<' '<<p<<'\n',cnt[now]++;
        else cout<<p<<' '<<now<<'\n',cnt[p]++;
    }
}

int32_t main()
{
    IOS
    cin>>n>>m;
    for (int i=1;i<=m;i++)
    {
        cin>>x>>y;
        G[x].pb(y);
        G[y].pb(x);
        v.insert(mkp(min(x,y),max(x,y)));
    }
    if (m%2==1) return cout<<"-1\n",0;
    dfs(1);
    for (pii i:v)
    {
        if (u.find(i)==u.end())
        {
            cout<<i.F<<' '<<i.S<<'\n';
            cnt[i.F]++;
        }
    }
    memset(used,0,sizeof(used));
    dfs2(1,-1);
}



Measured memory_bytes: 51456
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <functional>
#include <bitset>
#include <limits>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <random>

#ifdef DEBUG
#include "library/Utility/debug.cpp"
#else
#define debug(...)
#endif

#define rep(i,n) for(int i=0;i<(n);++i)
#define EL '\n'
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using lnt = long long;
struct FIO{FIO(){std::cin.tie(0);std::ios_base::sync_with_stdio(0);std::cout<<std::setprecision(15);}}fIO;
template<typename T> using V = std::vector<T>;
template<typename T> void fill(V<T>&v) { for(T&e:v) std::cin >> e; }
/*-*/

int main() {
	lnt d,t,s;
	std::cin >> d >> t >> s;
	if(d>t*s) print("No");
	else print("Yes");
}


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

using namespace std;

typedef vector<int> vec;

struct node
{
	int fa,dep;
	vec son;
	node()
	{
		fa=-1;
		dep=0;
		son.clear();
	}
}T[100100];

int main()
{ 
	//freopen("out.txt","w",stdout);
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		int id,ns;
		scanf("%d%d",&id,&ns);
		for(int j=0;j<ns;j++)
		{
			int t;
			scanf("%d",&t);
			T[id].son.push_back(t);
			T[t].fa=id;
		}
	}
	queue<int> que;
	for(int i=0;i<n;i++)
		if(T[i].fa==-1)
		{
			for(int j=0;j<T[i].son.size();j++)
				que.push(T[i].son[j]);
			break; 
		}
	while(!que.empty())
	{
		int t=que.front();que.pop();
		T[t].dep=T[T[t].fa].dep+1;
		for(int i=0;i<T[t].son.size();i++)
			que.push(T[t].son[i]);
	}
	for(int i=0;i<n;i++)
	{
		printf("node %d: parent = %d, depth = %d, ",i,T[i].fa,T[i].dep);
		if(T[i].fa==-1)
			printf("root, ");
		else if(T[i].son.size()==0)
			printf("leaf, ");
		else printf("internal node, ");
		for(int j=0;j<T[i].son.size();j++)
			printf("%c%d%c",j==0?'[':' ',T[i].son[j],j+1==T[i].son.size()?']':',');
		if(T[i].son.size()==0) printf("[]");
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 7272
#include <iostream>
#include <vector>
#include <algorithm>

int main()
{
    int n{};
    std::cin >> n;

    std::vector<int> x(n);
    for (int i = 0; i < n; i++) {
        std::cin >> x[i];
    }

    size_t result = 0;

    auto first = x.begin();
    bool sunuke = false;
    for (int i = 0; i < n; i++) {
        const auto found = std::find(first, x.end(), i + 1);
        result += &(*found) - &(*first);
        if (found == x.end()) {
            break;
        }
        sunuke = true;
        first = found + 1;;
    }
    if (sunuke) {
        std::cout << result << std::endl;
    } else {
        std::cout << -1 << std::endl;
    }
    return 0;
}


Measured memory_bytes: 1024
def spliter():
    a, b, c = map(int, input().split())
    return a, b, c

def count(a, b, c):
    count = 0
    for i in range(a, b + 1):
        if c % i == 0:count +=1
    return count

def main():
    a, b, c = spliter()
    print(count(a, b, c))

if __name__ == '__main__':
    main()

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

int main(){
    string s; int k;
    cin>>s>>k;
    int cnt=0;
    set<string>se;
    vector<string>ans;
    int f=s.size();
    int x=min(k,f);
    for(int i=0; i<=x; ++i){
        for(int j=0; j<=s.size()-i; ++j){
            string ss=s.substr(j,i);
            if(se.find(ss)==se.end()){
                se.insert(ss);
                ans.push_back(ss);
            }        
        }
    }
    sort(ans.begin(),ans.end());
    cout<<ans[k]<<endl;
    return 0;
}

Measured memory_bytes: 1792
from collections import deque

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

es_lang = [[] for _ in range(M+1)] # 各言語の番号がidxで、それを話せる人が中身
es_p = [[] for _ in range(N+1)] # 各人の番号がidxで、その人の話せる言語が中身
for i in range(N):
    KL = list(map(int, input().split()))
    es_p[i+1].extend(KL[1:])
    for j in KL[1:]:
        es_lang[j].append(i+1)

checked_lang = [False] * (M+1)
checked_p = [False] * (N+1)

#人１からスタートする
stack_p = [1]
checked_p[1] = True
while len(stack_p) > 0:
    new_stack_p = [] # この次のループで調べる人の集合
    for p in stack_p:
        checked_p[p] = True
        stack_lang = []
        for lang in es_p[p]: #人ｐが話せる言語について調べる
            if checked_lang[lang] == False: # まだその言語を調査してないとき
                stack_lang.append(lang)
                checked_lang[lang] = True

        # 人pの持つ言語をだれが話せるか調べる
        for lang in stack_lang:
            for pp in es_lang[lang]: # 人ｐの話せる言語を話せる人について調べる
                if checked_p[pp] == False: # まだその人を調べてないなら次のループで調べる人に入れる
                    new_stack_p.append(pp)
                    checked_p[pp] = True

    if all(checked_p[1:]):
        print("YES")
        exit()
    if len(new_stack_p) > 0:
        stack_p = new_stack_p
    else:
        break



print("NO")


Measured memory_bytes: 38832
import java.awt.Frame;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

import javax.xml.parsers.DocumentBuilder;

import java.math.BigInteger;
import java.time.chrono.MinguoChronology;

public class Main {
  static InputReader in;
  static PrintWriter out;
  
  static class Solution {
    void solve() throws IOException {                
        int a = in.nextInt();
        int b = in.nextInt();
        
        int d = a / b;
        int r = a % b;
        double f = (double)a / (double)b;
        
        out.print(d+" "+r);
        out.printf(" %.5f\n", f);
    }
  }

  public static void main(String[] args) throws IOException {
    in = new InputReader(System.in);
    out = new PrintWriter(System.out);
    Solution solver = new Solution();
    solver.solve();
    out.close();
}

  static class InputReader {
    public BufferedReader br;
    public StringTokenizer st;
    
    public InputReader(InputStream stream) {
      br = new BufferedReader(new InputStreamReader(stream));
    }
   
    public int nextInt() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Integer.parseInt(st.nextToken());
    }
    
    public long nextLong() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Long.parseLong(st.nextToken()); 
    }
    
    public String next() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return st.nextToken();
    }
    
    public double nextDouble() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Double.parseDouble(st.nextToken());
    }
    
  }
  
}

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

#define INF INT_MAX/3
#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define SET(a,c) memset(a,c,sizeof a)
#define CLR(a) memset(a,0,sizeof a)
#define PII pair<int,int>
#define PCC pair<char,char>
#define PIC pair<int,char>
#define Pci pair<char,int>
#define VS vector<string>
#define VI vector<int>
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define PI 2*acos(0.0)
#define INFILE() freopen("in0.txt","r",stdin)
#define OUTFILE() freopen("out0.txt","w",stdout)
#define IN scanf
#define OUT(x) cout<<x<<endl
#define LL long long
#define ll long long
#define ULL unsigned long long
#define EPS 1e-14
#define FST first
#define SEC second

#include<iostream>

using namespace std;
int main()
{
  string r = "No";
  // 入力
  string a;
  cin >> a;

  bool n = true, w = true, s = true, e = true;
  if (a.find("N") == string::npos) n = false;
  if (a.find("W") == string::npos) w = false;
  if (a.find("S") == string::npos) s = false;
  if (a.find("E") == string::npos) e = false;

  if (n && w && s && e) r = "Yes";
  if (n && !w && s && !e) r = "Yes";
  if (!n && w && !s && e) r = "Yes";

  OUT(r);
  
  return 0;
}


Measured memory_bytes: 256
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;
#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)
typedef long long ll;

char buf[20];

int main(void) {
  cin >> buf;
  int n = strlen(buf);
  int cnt = 0;
  REP(i, n) {
    if(buf[i] == 'o') {
      ++cnt;
    }
  }
  puts(cnt + (15-n) >= 8 ? "YES" : "NO");
  return 0;
}


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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define revrepeat(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
typedef complex<ld> Point;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const int MAX_V = 1e5 + 5;
const int MAX_N = 1e5 + 5;
const double PI = acos(-1);

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream> 
#include <stdio.h>
#define MAX 20000005
typedef long long ll; 
using namespace std; 
int main () 
{
    int x; 
    cin >> x; 
    if (x >= 400 && x <=599) 
    {
        cout << "8" << endl; 
    }
    if (x >= 600 && x<=799) 
    {
        cout << "7" << endl; 
    }
    if (x >= 800 && x <= 999) 
    {
        cout << "6" << endl; 
    }
    if (x >= 1000 && x <= 1199) 
    {
        cout << "5" << endl; 
    }
    if (x >= 1200 && x <= 1399) 
    {
        cout << "4" << endl; 
    }
    if ( x >= 1400 && x <= 1599) 
    {
        cout << "3" << endl ; 
    }
    if (x >= 1600 && x <= 1799) 
    {
        cout << "2" << endl; 
    }
    if ( x>= 1800 && x <= 1999) 
    {
        cout << "1" << endl; 
    }
    return 0; 
}


Measured memory_bytes: 3600
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void rd(char &c){
  int i;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c = i;
}
inline int rd(char c[]){
  int i;
  int sz = 0;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int N;
int M;
int P;
char S[4];
int res1;
int res2;
int ok[100000];
int ng[100000];
int main(){
  int Lj4PdHRW, i;
  rd(N);
  rd(M);
  for(Lj4PdHRW=(0);Lj4PdHRW<(M);Lj4PdHRW++){
    rd(P);P += (-1);
    rd(S);
    if(ok[P]){
      continue;
    }
    if(S[0]=='A'){
      ok[P]++;
    }
    else{
      ng[P]++;
    }
  }
  for(i=(0);i<(N);i++){
    if(ok[i]){
      res1++;
      res2 += ng[i];
    }
  }
  wt_L(res1);
  wt_L(' ');
  wt_L(res2);
  wt_L('\n');
  return 0;
}
// cLay varsion 20200119-1

// --- original code ---
// int N, M, P; char S[4];
// int res1, res2, ok[1d5], ng[1d5];
// {
//   rd(N,M);
//   rep(M){
//     rd(P--,S);
//     if(ok[P]) continue;
//     if[S[0]=='A', ok[P], ng[P]]++;
//   }
//   rep(i,N) if(ok[i]) res1++, res2 += ng[i];
//   wt(res1,res2);
// }


Measured memory_bytes: 1024
// Problem : D - Multiple of 2019
// Contest : AtCoder - AtCoder Beginner Contest 164
// URL : https://atcoder.jp/contests/abc164/tasks/abc164_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

// #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>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
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;
typedef vector<cd> vcd;
 
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
#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,b,a) 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 ins insert
#define cs(ans) setprecision(10)<<fixed<<ans
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const ld pii=3.14159265359;
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
 
int main() 
{
	#define int ll
	ios_base::sync_with_stdio(0); cin.tie(0);    
	string str;
	cin>>str;
	int N=sz(str);
	vl m(2019);
	m[str[0]-'0']++;
	ll ans=0;
	FOR(x,1,N)
	{
		int nb=str[x]-'0';
		// dp[nb]++;
		vl v(2019);
//		v[0]=1;
		v[nb]++;
		F0R(y,2019)
		{
			if(m[y]!=0)
			{
				int rem=(y*10+nb)%2019;
				// cout<<nb<<endl;
				// cout<<x<<' '<<y<<' '<<rem<<endl;;
				if(rem==0)ans+=m[y];
				v[rem]+=m[y];
//				if(y==0)
			}
		}
//		ans+=v[0];
		F0R(x,2019)
			m[x]=v[x];
	}
	cout<<ans<<endl;
	return 0;
	//CHECK CORNER CASES
}
// read the question correctly (ll vs int)
// template by bqi343




Measured memory_bytes: 3740
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
const int inf=1e9+7;
const ll mod=1e9+7;

int DP[256][20005];

int main() {
    int N, M;
    vector<int> ansarr;
    while(true){
        cin>>N>>M;
        if((N==0) & (M==0)) break;
        for(int i=0;i<256;++i){
            for(int j=0;j<20005;++j){
                DP[i][j] = inf;
            }
        }
        vector<int> C(M);
        for(int i=0;i<M;++i){
            cin>>C[i];
        }
        vector<int> x(N);
        for(int i=0;i<N;++i){
            cin>>x[i];
        }
        for(int i=0;i<M;++i){
            if(128 + C[i] <= 0){
                DP[0][0] = x[0] * x[0];
            }
            else if(128 + C[i] >= 255){
                DP[255][0] = (255 - x[0]) * (255 - x[0]);
            }
            else {
                DP[128+C[i]][0] = (128+C[i]-x[0])*(128+C[i]-x[0]);
            }
        }
        for(int i=0;i<N-1;++i){
            for(int j=0;j<256;++j){
                for(int k=0;k<M;++k){
                    if(j+C[k]<=0) {
                        DP[0][i+1] = min(DP[0][i+1], DP[j][i] + x[i+1] * x[i+1]);
                    }
                    else if(j+C[k]>=255) {
                        DP[255][i+1] = min(DP[255][i+1], DP[j][i] + (255 - x[i+1]) * (255 - x[i+1]));
                    }
                    else {
                        DP[j+C[k]][i+1] = min(DP[j+C[k]][i+1], DP[j][i] + (j + C[k] - x[i+1]) * (j + C[k] - x[i+1]));
                    }
                }
            }
        }
        /**
        for(int i=0;i<256;++i){
            for(int j=0;j<N;++j){
                cout<<DP[i][j]<<" ";
            }
            cout<<endl;
        }
        cout<<endl;
        **/
        int ans = inf;
        for(int i=0;i<256;++i){
            ans = min(ans, DP[i][N-1]);
        }
        ansarr.push_back(ans);
    }
    for(int i=0;i<ansarr.size();++i){
        cout<<ansarr[i]<<endl;
    }
}




Measured memory_bytes: 23248
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

const int INF = 1e9+5;

int main(){
 int N;
     cin>>N;
     vector<pair<int,int>> A,B;
     rep(i,N){
         int x,y;cin>>x>>y;
         A.push_back({y,x});
     }
     rep(i,N){
         int x,y;cin>>x>>y;
         B.push_back({x,y});
     }
     sort(all(A), greater<pair<int, int>>());
     sort(all(B));
     vector<bool> f(N, false);
     //cの小さい順
     rep(i,N){
         int c = B[i].first;
         int d = B[i].second;
         //bの大きい順
         rep(j,N){
             int a = A[j].second;
             int b = A[j].first;
             if(f[j])continue;
             if(a < c && b < d){
                 f[j] = true;
                 break;
             }
         }
     }
     int cnt =0;
     rep(i,N){
         if(f[i])cnt++;
     }
     cout<<cnt<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 5LL << 60;
const ll mod = 1e9 + 7;

int main() {
	int R, G, B, N;
	cin >> R >> G >> B >> N;

	int red = N / R, ans = 0;
	for(; red >= 0; red--) {
		int green = (N - red * R) / G;
		for(; green >= 0; green--) {
			if((N - red * R - green * G) % B == 0) ans++;
		}
	}
	cout << ans << "\n";
	return 0;
}


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

int main(){
  int n,m,x;
  cin >>n >>m >>x;
  vector<int> a(m);
  rep(i,m) cin >>a[i];
  int sum = 0;
  for(int i = 0;;i++){
    if(a[i]<x) sum++;
    if(a[i]>x) break;
  }
  cout << min(sum,m-sum) << endl;
  return 0;
}


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

int main() {
	int l,r,d; cin >> l >> r >> d;
	
	int l1,r1;
	l1 = l/d - (l%d==0);
	r1 = r/d - (d%d==0);
	
	cout << r1 - l1 + 1 << endl;
}

Measured memory_bytes: 3644
#include <stdio.h>
int main()
{
    int a,b,c=0,d=0;
    scanf("%02d%02d",&a,&b);
    if(a>0 && a<13) c++;
    if(b>0 && b<13) d++;
    if(c==0 && d==0) printf("NA");
    else if(c==1 && d==1) printf("AMBIGUOUS");
    else if(c==1 && d==0) printf("MMYY");
    else printf("YYMM");
}


Measured memory_bytes: 128
#include <stdio.h>
#include <math.h>

int main(){
  int D,G;
  int p[10],c[10],s[10],N;
  int max,sum,n,min;
  scanf("%d %d",&D,&G);

  for(int i=0;i<D;i++){
    scanf("%d %d",&p[i],&c[i]);
    s[i]=100*(i+1)*p[i]+c[i];
    N+=p[i];
  }

  for(int i=0;i<(1<<D);i++){
    sum=n=0;
    for(int j=0;j<D;j++)
      if(i&(1<<j)){
	sum+=s[j];
	n+=p[j];
      }
      else
	max=j;
    //    printf("%d sum %d n %d\n",i,sum,n);
    min=N;
    if(G-sum<=0 && n<N)
         N=n;
	//	printf(" !min\n");}
    if(G-sum>0)
      for(int j=0;j<D;j++)
	if(!(i&(1<<j))){
	  int k=ceil((G-sum)/100./(j+1));
	  if(k<min&&k<p[j]){
	    min=k;
	    //	    printf("min %d %d\n",j,k);
	  }
	}
    if(min<N&&n+min<N){
      N=n+min;
      //      printf(" !+min\n");
    }
    
  }

  printf("%d\n",N);
  return 0;
}


Measured memory_bytes: 128
use std::io;
use std::str;
use std::usize;
use std::cmp;

fn mod_pow(x: i64, mut exp: i64, modulo: i64) -> i64 {
    let mut result = 1;
    let mut cur = x;
    while exp > 0 {
        if exp & 1 == 1 {
            result = (result * cur) % modulo;
        }
        cur = (cur * cur) % modulo;
        exp >>= 1;
    }
    result
}

fn main() {
    let modulo = 998244353;
    let n = read_values::<usize>()[0];
    let (x, y) = {
        let mut x = vec![0; n];
        let mut y = vec![0; n];
        for i in 0..n {
            let v = read_values::<i64>();
            x[i] = v[0];
            y[i] = v[1];
        }
        (x, y)
    };

    let mut ans = mod_pow(2, n as i64, modulo);
    ans -= 1;
    ans -= n as i64;
    ans = (ans + modulo) % modulo;

    // 両端がそれぞれ i, j となるような線分に乗っている点の数を数える
    for i in 0..n {
        for j in (i + 1)..n {
            let dx = x[i] - x[j];
            let dy = y[i] - y[j];

            let mut count = 0;
            let mut left = i;
            let mut right = j;
            for k in 0..n {
                let kx = x[i] - x[k];
                let ky = y[i] - y[k];
                if dx * ky - kx * dy == 0 {
                    left = cmp::min(left, k);
                    right = cmp::max(right, k);
                    count += 1;
                }
            }

            // 両端が i, j でない時はスルー
            if left != i || right != j {
                continue;
            }

            // 凸包の面積が 0 であるような部分集合のサイズ
            let subset = mod_pow(2, count, modulo) - count - 1;
            ans = (ans + modulo - subset) % modulo;
        }
    }

    println!("{}", ans);
}

fn read_line() -> String {
    let stdin = io::stdin();
    let mut buf = String::new();
    stdin.read_line(&mut buf).unwrap();
    buf
}

fn read_values<T>() -> Vec<T>
    where T: std::str::FromStr,
          T::Err: std::fmt::Debug
{
    read_line()
        .split(' ')
        .map(|a| a.trim().parse().unwrap())
        .collect()
}

Measured memory_bytes: 4352
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

int main()
{
    int n, m;
    cin >> n >> m;
    priority_queue<int, vector<int>, less<int>> q;
    rep(i, n)
    {
        int a;
        cin >> a;
        q.push(a);
    }

    rep(i, m)
    {
        int a = q.top();
        q.pop();
        q.push(a / 2);
    }

    int64_t result = 0;
    while (!q.empty()) {
        result += q.top();
        q.pop();
    }
    cout << result << endl;

    return 0;
}

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


def solve(N: int, P: int, S: str):

    if P == 2 or P == 5:
        tot = 0
        for i, c in enumerate(S):
            c = int(c)
            if c % P == 0:
                tot += i+1
        print(tot)
        return

    U = [0]*(N+1)
    a = 0
    beki = 1
    for i in range(N-1, -1, -1):
        a += beki*int(S[i])
        a %= P
        U[i] = a
        beki = (beki * 10) % P
    table = [0]*P
    tot = 0
    for i in range(N-1, -1, -1):
        tot += table[U[i]]
        table[U[i]] += 1
    tot += table[0]
    print(tot)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    P = int(next(tokens))  # type: int
    S = str(next(tokens))  # type: int
    solve(N, P, S)


if __name__ == '__main__':
    main()


Measured memory_bytes: 43500
import java.io.IOException;
import java.util.Arrays;
import java.util.NoSuchElementException;

 
public class Main{
	
	public static void main(String args[])throws Exception{
		FastScanner sc = new FastScanner();
		
		int W = sc.nextInt();
		int H = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		int r = sc.nextInt();
		if(0<=x-r&&x+r<=W&&0<=y-r&&y+r<=H){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}









class FastScanner {
    private final java.io.InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
    public boolean hasNext() { skipUnprintable(); return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return (minus ? -n : n);
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return (int) (minus ? -n : n);
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
}





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

#define MOD 53
int cn[MOD];

int main(){
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
  	int a;
    scanf("%d",&a);
    cn[(a&-a)%MOD]++;
  }
  int ans=0;
  for(int i=0;i<30;i++){
  	ans+=cn[(1<<i)%MOD]*i;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
//khodaya khodet komak kon
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#pragma GCC optimise ("ofast")
#pragma GCC optimise("unroll-loops")

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int N = 100000 + 10;
const ll MOD = 1000000000 + 7;
const ll INF = 1000000000000000000;
const ll LOG = 25;


bool M[N], mark[N];
int n, m, inv[N], par[N], p[N], IN[N], ans[N];
vector<int> G[N], ft, g[N];

int getpar(int v){
	return (par[v] == v ? v : par[v] = getpar(par[v]));
}

void merge(int v, int u){
	v = getpar(v), u = getpar(u);
	if (v == u) return;
	par[v] = u;
}

void DFS(int v, int p = 0){
	M[v] = 1;
	for (auto u:G[v]){
		if (!M[u]) DFS(u, v);
	}
	ft.pb(v);
}

bool cmp(int x, int y){
	return (inv[x] < inv[y]);
}


int32_t main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> m;
	for (int i = 1; i <= n; i++) par[i] = i;
	for (int i = 1; i <= n + m - 1; i++){
		int v, u;
		cin >> v >> u;
		G[v].pb(u);
		IN[u] ++;
	}
	int root;
	for (int i = 1; i <= n; i++){
		if (IN[i] == 0){
			root = i; 
		}
	}
	DFS(root);
	reverse(all(ft));
	//for (auto u:ft) cout << u << ' ';
	//cout << '\n';
	for (int i = 0; i < ft.size(); i++){
		inv[ft[i]] = i;
	}
	for (int i = 0; i < ft.size(); i++){
		sort(all(G[ft[i]]), cmp);
	}
	for (int i = ft.size() - 1; i >= 0; i--){
		for (auto u:G[ft[i]]){
		//	cout << i << ' ' << u << ' ' << getpar(u) << '\n';
			if (!mark[getpar(u)]){
				//cout << ft[i] << ' ' << u << '\n';
				mark[getpar(u)] = 1;
				ans[u] = ft[i];
			}
		}
		for (auto u:G[ft[i]]){
			mark[getpar(u)] = 0;
			merge(ft[i], u);
		}
	}
	for (int i = 1; i <= n; i++) cout << ans[i] << '\n';




	return 0;
}


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


signed main(){
    int H, W, k, ans = 0, cnt;
    char mat[10][10];

    cin>>H>>W>>k;

    for(int i=0; i<H; i++)
        for(int j=0; j<W; j++)
            cin>>mat[i][j];

    for(int maskh=0; maskh < (1<<H); maskh++)
        for(int maskw=0; maskw < (1<<W); maskw++){
            cnt = 0;

            for(int i=0; i<H; i++)
                for(int j=0; j<W; j++)
                    if( ((maskh>>i)&1) == 0 && ((maskw>>j)&1) == 0 && mat[i][j] == '#')
                        cnt++;

            if(cnt == k) ans++;
        }

    cout<<ans<<endl;
}

Measured memory_bytes: 3592
#include <iostream>
#include <vector>
using namespace std;
typedef long long int LLI;

int main()
{
	string s;
	cin >> s;
	int sum = 0;
	for(int i = 0; i < s.size(); i++)
		if( s[i] == '1' )
			sum++;
	cout << sum;
}

Measured memory_bytes: 3608