akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std; 

int main() {
  int n,t,a;
  cin>>n>>t>>a;
  vector<vector<int>> b(n+1);
  for(int i=0;i<n-1;i++){
    int c,d;
    cin>>c>>d;
    b.at(c).push_back(d);
    b.at(d).push_back(c);
  }
  
  int inf=364364;
  queue<int> q;
  vector<int> d(n+1);
  for(int i=1;i<n+1;i++){
      d.at(i)=inf;
  }
  d.at(t)=0;
  q.push(t);
  while(q.size()){
      int p=q.front();
      q.pop();
      for(int i=0;i<b.at(p).size();i++){
          if(d.at(b.at(p).at(i))==inf){
              q.push(b.at(p).at(i));
              d.at(b.at(p).at(i))=d.at(p)+1;
          }
      }
  }
  
  vector<int> e(n+1);
  for(int i=1;i<n+1;i++){
      e.at(i)=inf;
  }
  e.at(a)=0;
  q.push(a);
  while(q.size()){
      int p=q.front();
      q.pop();
      for(int i=0;i<b.at(p).size();i++){
          if(e.at(b.at(p).at(i))==inf){
              q.push(b.at(p).at(i));
              e.at(b.at(p).at(i))=e.at(p)+1;
          }
      }
  }
  
  int ans=0;
  for(int i=1;i<n+1;i++){
    if(d.at(i)<=e.at(i)){
      if(b.at(i).size()>1){
        ans=max(ans,e.at(i));
      }
      else{
        ans=max(ans,e.at(i)-1);
      }
    }
  }
  
  cout<<ans<<endl;
}

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

using namespace std;

template <typename T> T gcd(T x, T y) {
  if (y == 0)
    return x;
  return gcd(y, x % y);
}

template <typename T> T lcm(T x, T y) {
  if (x == 0 || y == 0)
    return 0;
  return x / gcd(x, y) * y;
}

int main() {
  int N;
  cin >> N;
  vector<vector<int>> A(2, vector<int>(N));
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < N; j++) {
      cin >> A[i][j];
    }
  }
  for (int i = 0; i < N - 1; i++) {
    A[0][i + 1] += A[0][i];
  }
  A[1][0] += A[0][0];
  for (int i = 1; i < N; i++) {
    A[1][i] = max(A[0][i] + A[1][i], A[1][i - 1] + A[1][i]);
  }
  cout << A[1][N - 1] << endl;
}


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

int main(){
ll N;
cin>>N;
ll ans =1e18;
for(ll i=1;i*i<=N;i++){
if(N%i!=0)continue;
ll j=N/i;
ans = min(ans,i+j-2);

}
cout<<ans<<endl;
return 0;

}

Measured memory_bytes: 3636
n = gets.to_i
arr = gets.split.map(&:to_i)

div = 0
counter = 1
(1..n).each do |i|
  c = arr[i-1] <=> arr[i]
  if div == 0
    if c == 1
      div = 1
    elsif c == -1
      div = -1
    end
  elsif (div == 1 && c == -1 || div == -1 && c == 1)
    counter += 1
    div = 0
  end
end

puts counter

Measured memory_bytes: 8452
num = int(input())
order = input().split()
order = [int(i) for i in order]
manzoku = input().split()
additional = input().split()

prev = -1
ans = 0
for i in order:
  ans += int(manzoku[i-1])
  if i == prev+1:
    ans += int(additional[i-2])
  prev = i
  
print(ans)

Measured memory_bytes: 3064
#include <iomanip>
#include <iostream>
using namespace std;
long long solve(long long l, long long r) {
	long long mul = 1; while (mul * 2 <= r) mul *= 2; r -= mul;
	if (l >= mul) return solve(l - mul, r);
	long long mul2 = 1; while (mul2 <= r) mul2 *= 2;
	if (l < mul2) return mul * 2 - l - 1;
	return (mul - l - 1) * (mul2 == mul ? 1 : 2) + mul2;
}
long long A, B;
int main() {
	cin >> A >> B;
	cout << solve(A - 1, B) << endl;
	/*
	for (int i = 0; i < 32; i++) {
		for (int j = 0; j < i; j++) {
			cout << setw(3) << solve(j, i);
		}
		cout << endl;
	}
	*/
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define long long ll
char s[30000];
int cnt;
int fun(){
    if(cnt%2!=0){
        return 0;
    }
    else{
        bool flag=1;
        for(int i=0;i<cnt/2;i++){
            if(s[i]!=s[i+cnt/2]){
                flag=0;
                break;
            }
        }
        return flag;
    }
}
int main(){
    cin>>s;
    int flag=0;
    cnt=strlen(s);
    while(!flag||!fun()){
        cnt--;
        flag=1;
        if(cnt==0) break;
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 256
#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 main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int n; cin >> n;
  vi a(n);
  for(int i=0;i<n;++i) {
    cin >> a[i];
  }

  vvll dp(n+1, vll(n+1, -LINF));
  for(int i=0;i<=n;++i) {
    dp[i][i] = 0;
  }
  for(int k=1;k<=n;++k) {
    for(int i=0;i<n;++i) {
      int j = i + k;
      if(j > n) break;
      if((k % 2) ^ (n % 2)) {
        dp[i][j] = min(dp[i+1][j] - a[i], dp[i][j-1] - a[j-1]);
      } else {
        dp[i][j] = max(dp[i+1][j] + a[i], dp[i][j-1] + a[j-1]);
      }
    }

  }

  

  cout << dp[0][n] << endl;

}


Measured memory_bytes: 70784
N, M = map(int, input().split())
L = []
R = []
for i in range(M):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)

left = -1
right = 1e9

for i in range(M):
    left = max(left, L[i])
    right = min(right, R[i])

ans = right - left + 1
ans = max(ans, 0)
print(ans)


Measured memory_bytes: 11052
#include<bits/stdc++.h>
#define F first
#define S second
#define int long long
#define double long double
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> iP;
typedef pair<P,int> Pi;
typedef pair<P,P> PP;
double eps=1e-8;
int mod=1e9+7;
int inf=1LL<<55;

priority_queue<P,vector<P>,greater<P> > pq;

template <typename T>
int Count(const vector<T> &v, T l,T r){
  //counting [l,r]
  auto L = lower_bound(v.begin(), v.end(), l );
  auto R = upper_bound(v.begin(), v.end(), r );
  // [l,r) change upper -> lower
  return R-L;
}

int ch1(int a,int b){
    if(a>b)swap(a,b);
    int s=sqrt(a*b-1);
    if(s==0)return 0;
    int mx=(a*b-1)/s;
    if(mx<s)swap(s,mx);
    int ans=2*s;
    if(mx==s)ans--;
    if(a<=s)ans--;
    return ans;
}

signed main(){
  int q,a,b;
  cin>>q;
  while(q--){
    cin>>a>>b;
    cout<<ch1(a,b)<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <map>
#include <set>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <assert.h>
#include <math.h>
#include <stack>
#include <queue>
#include <list>
using namespace std;

// #define __DEBUG__

#ifdef __DEBUG__
bool debug_disabled = false;
#else
bool debug_disabled = true;
#endif

#define dbg if (debug_disabled) {} else cerr

void solve() {
    int N;
    cin >> N;
    map<int, long long> m;
    long long res = 0;
    for (int i = 0; i < N; ++i) {
        int h;
        cin >> h;
        res += m[i + 1 - h];
        ++m[i + 1 + h];
    }
    cout << res << endl;
}

int main() {
    cout.setf(ios::fixed, ios::floatfield);
    cout.setf(ios::showpoint);
    cout.precision(12);
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);

    int T = 1;
    // cin >> T;
    for (int i = 1; i <= T; ++i) {
        solve();
    }

    return 0;
}


Measured memory_bytes: 26352
import java.util.ArrayDeque;
import java.util.Collections;
import java.util.Deque;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;

class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        long x = scan.nextLong();
        long[] a = new long[2*N];
        for(int i=0;i<N;++i)a[i] = scan.nextLong();
        for(int i=0;i<N;++i)a[N+i]=a[i];

        long ans = Long.MAX_VALUE;
        for(int i=0;i<N;++i){
            Deque<Integer> que = new ArrayDeque<>();
            long value=x*i;
            for(int j=N-i;j<N;++j){
                que.addLast(j);
                while(a[que.peekFirst()] > a[j]){
                    que.removeFirst();
                }
            }
            for(int j=N;j<2*N;++j){
                while(!que.isEmpty() && j>que.peekFirst()+i){
                    que.removeFirst();
                }
                while(!que.isEmpty() && a[que.peekLast()] > a[j]){
                    que.removeLast();
                }
                que.addLast(j);

                value += a[que.peekFirst()];
            }
        ans = Math.min(ans, value);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 62936
n = int(input())
v_cnt = 0
e_cnt = 0
def triangle(x):
  return (x*(x+1) // 2)

for l in range(1,n+1):
  v_cnt += triangle(n-l+1)

for i in range(n-1):
  u, v = map(int, input().split())
  e_cnt += min(u,v) * (n - max(u,v)+1)

print(v_cnt - e_cnt)


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

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  
  if((a == b && a != c)||(a ==c && a != b)||(b == c && b!= a)){
    cout << "Yes" << endl;
  }
  
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int n,m,i,j,k=0,max,num=0;
	int A[1000];
	int B[1000];
	int count[1000]={0};
	scanf("%d %d",&n,&m);
	for(i=0;i<n;i++){
		scanf("%d",&A[i]);
	}
	for(j=0;j<m;j++){
		scanf("%d",&B[j]);
	}
	for(j=0;j<m;j++){
		if(B[j]>=A[k]){
			B[j]=k;
			k=0;
		}else{
			k=k+1;
			j=j-1;
		}
	}
	max=count[0];
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			if(B[j]==i){
				count[i]=count[i]+1;
			}
		}
		if(count[i]>max){
				max=count[i];
				k=i+1;				
		}
	}
	printf("%d\n",k);
	return 0;
}

Measured memory_bytes: 608
from sys import stdin


def main():
    n = next_int()
    l = next_int()

    s = [input() for _ in range(n)]
    s.sort()

    print("".join(s))


def next_int():
    return int(next_str())


def next_str():
    result = ""
    while True:
        tmp = stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  int sum=0;
  rep(i,n){
    cin >> a.at(i);
    sum+=a.at(i);
  }
  ll ans=0,as=0,p=sum/n,q=(sum+n-1)/n;
  rep(i,n){
    ans+=(p-a.at(i))*(p-a.at(i));
    as+=(q-a.at(i))*(q-a.at(i));
  }
  cout << min(as,ans);

}
      
  

Measured memory_bytes: 3572
#include<iostream>
#include<string>
using namespace std;
int main() {
	int a,b,c,d,e,f,N,sum,g,i;
	string s;
	while (cin >> N) {
		if (N == 0)break;
		a = 1;
		b = 2;
		c = 3;
		d = 4;
		e = 5;
		f = 6;
		sum = 1;
		for (i = 0; i < N; i++) {
			cin >> s;
			if (s == "North") {
				g = a;
				a = b;
				b = f;
				f = e;
				e = g;
			}
			else if (s == "South") {
				g = a;
				a = e;
				e = f;
				f = b;
				b = g;
			}
			else if (s == "East") {
				g = a;
				a = d;
				d = f;
				f = c;
				c = g;
			}
			else if (s == "West") {
				g = a;
				a = c;
				c = f;
				f = d;
				d = g;
			}
			else if (s == "Left") {
				g = b;
				b = d;
				d = e;
				e = c;
				c = g;
			}
			else if (s == "Right") {
				g = b;
				b = c;
				c = e;
				e = d;
				d = g;
			}
			sum += a;
		}
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 3056
#include<iostream>
using namespace std;
int n,t,a[100010],b[100010],amax,bmax,amax2,bmax2,numa,numb;
int ans;
int main(){
	ios::sync_with_stdio(false);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>t;
		if(i%2)
			a[t]++;
		else
			b[t]++;
	}
	for(int i=1;i<=100000;i++){
		if(a[i]>amax2)
			amax2=a[i];
		if(amax2>amax){
			int t=amax;
			amax=amax2;
			amax2=t;
			numa=i;
		}
	}
	for(int i=1;i<=100000;i++){
		if(b[i]>bmax2)
			bmax2=b[i];
		if(bmax2>bmax){
			int t=bmax;
			bmax=bmax2;
			bmax2=t;
			numb=i;
		}
	}
	if(numa==numb){
		ans=n-max(amax+bmax2,bmax+amax2);
	}
	else
		ans=n-(amax+bmax);
	//cout<<amax<<' '<<bmax<<' '<<amax2<<' '<<bmax2<<' '<<numa<<' '<<numb<<endl;
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<cstring>
#include<queue>
#include<iostream>
#include<map>
using namespace std;
typedef long long ll;
typedef double lf;
typedef unsigned un;
typedef int in;
#define mian main
#define maxn 10000+10
#define maxm 10000+10
#define _(a) read(a)
#define non void
#define inf 2147483647
#define bre break
#define con continue
#define prq priority_queue
#define re register
#define bu bool
#define cz char
#define cst const
#define ope operator
#define inl inline
#define upp upper_bound
#define low lower_bound
#define next_per next_permutation
inl cz gc(){static cz buf[100000],*L=buf,*R=buf;return L==R&&(R=(L=buf)+fread(buf,1,100000,stdin),L==R)?EOF:*L++;}
template<typename T>inl T Max(T a,T b){return a>b?a:b;}
template<typename T>inl T Min(T a,T b){return a<b?a:b;}
template<typename T>inl T Abs(T a){return a<0?-a:a;}
template<typename T>inl non read(T &a){a=0;T k=1;char c=gc();while(c<'0'||c>'9')k=c=='-'?-1:k,c=gc();while(c>='0'&&c<='9')a=a*10+(c^48),c=gc();if(c!='.'){a*=k;return;}T t=0.1;while(c<'0'||c>'9')c=gc();while(c>='0'&&c<='9')a+=t*(c^48),c=gc(),t*=0.1;a*=k;}
template<typename T>non write(T a,cz t='\n'){if(a==0){putc(48,stdout),putc(t,stdout);return;}if(a<0){a=-a;putc('-',stdout);}cz c[30];in le=0;while(a){c[++le]=a%10+48;a/=10;}for(re in i=le;i>=1;--i)putc(c[i],stdout);putc(t,stdout);}
in n,l,r,sum;
in main()
{
	read(n);
	for(re in i=1;i<=n;++i)read(l),read(r),sum+=r-l+1;
	write(sum);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
}


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

#define ll long long
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define se second

ll pwr(ll a, ll b){
    if(b==0)
        return 1 ;
    ll c = pwr(a, b/2) ;
    c = c * c;
    if(b % 2)
        return c*a;
    return c ;
}
ll pwr(ll a, ll b, ll m){
    if(b==0)
        return 1;
    ll c = pwr(a, b/2, m) % m ;
    c = (c * c) % m;    
    if(b % 2)
        return (c * a%m) % m;
    return c ;
}
/*
void Dfs(int u, int p){
    visited[u] = 1;
    if(a[u]) con[u] = con[p] + 1;
    else con[u] = 0;
    if(con[u] > mx[p]) mx[u] = con[u];
    else mx[u] = mx[p];

    for(int i : adj[u]){
        if(i != p){
            Dfs(i, u);
        }
    }
}
*/
int dsum(int x){
    if(x == 0) return 0;
    return ( (x%10) + dsum(x/10));
}
int main(){
	int n, d;
	cin >> n >> d;
	int ans = n / (2 * d  + 1);
	if(n % (2*d + 1) != 0) ans++;
	cout << ans;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	int h, w; cin >> h >> w;
	int a;
	char c;
	const string str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	for (int i = 0; i < h; i++){
		for (int j = 0; j < w; j++){
			string s; cin >> s;
			if (s == "snuke") {
				a = i + 1;
				c = str[j];
			}
		}
	}
	cout << c << a << '\n';
}

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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  int N;
  cin >> N;

  int ans = ceil(N / 1.08);
  if (floor(ans * 1.08) == N) {
    cout << ans << endl;
  } else {
    cout << ":(" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#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++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
#define downque(que)  priority_queue<ll> que;
#define upque(que) priority_queue<ll, vector<int>, greater<int>> que;


int GCD(int p,int q){
    int r=p%q;

  while(r>0){
      p=q;
      q=r;
      r=p%q;
  }
  return q;
}


int main(){
   int n; cin>>n;
   //最大公約数もとめよう
   //A-B=AとBの最大公約数の倍数がくりかえされるから
   //最後は最大公約数がのこる

  int A[n];
  REP(i,n)cin>>A[i];
  
  ll gcd=GCD(A[0],A[1]);

 FOR(i,2,n){
     gcd=GCD(gcd,A[i]);
 }
   cout<<gcd<<endl;
}

Measured memory_bytes: 640
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            String s = in.next();
            out.println(s.length() >= 4 && s.substring(0, 4).equals("YAKI") ? "Yes" : "No");
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            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();
        }

    }
}



Measured memory_bytes: 23252
#![allow(unused_imports)]

use maplit::*;
use std::{i32, i64, u32, u64, f64};
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::io::{stdout, Write, BufWriter};
use std::mem::{swap};
use proconio::marker::{Isize1, Usize1, Bytes, Chars};

#[proconio::fastout]
fn main() {
    proconio::input!{
        n: usize,
        edges: [i64; n],
    }
    let mut cands = BinaryHeap::new();
    let mut ckdup = hashset!();
    for edge in edges {
        if ! ckdup.insert(edge) { cands.push(ckdup.take(&edge).unwrap()); } }
    if cands.len() >= 2 { println!("{}", cands.pop().unwrap() * cands.pop().unwrap()); }
    else { println!("0"); }
}


Measured memory_bytes: 5564
using System;
using System.Linq;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            var abc = Console.ReadLine().Split().Select(int.Parse).OrderByDescending(x => x).ToArray();
            Console.WriteLine(abc[0]*10 + abc[1] + abc[2]);
        }
    }
}


Measured memory_bytes: 13396
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;

void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    double w,h,x,y;
    cin >> w >> h >> x >> y;
    double ans = w * h /2;
    if(w == x * 2 && h == y * 2){
        cout << setprecision(10) <<  ans << " " << 1;
    }
    else{
        cout << setprecision(10) <<  ans << " " << 0;
    }

    return 0;
}

Measured memory_bytes: 3812
#include "bits/stdc++.h"
using namespace std;
#define Rep(i, n) for (int i = 0; i < (int)(n); i++)
#define BitRep(i, n) for (int i = 0; i < (int)(1 << n); i++)
#define Sum(vec) accumulate(vec.begin(), vec.end(), 0)
#define Sort(vec) sort(vec.begin(), vec.end())
#define Reverse(vec) reverse(vec.begin(), vec.end())
#define Next_permutation(vec) next_permutation(vec.begin(), vec.end())

struct Card { char sign, value; };

void bubble(struct Card A[], int N) {
    for (int i = 0; i < N - 1; ++i) {
        for (int j = N - 1; j >= i + 1; --j) {
            if (A[j].value < A[j - 1].value) {
                swap(A[j], A[j - 1]);
            }
        }
    }
}

void selection(struct Card A[], int N) {
    for (int i = 0; i < N - 1; ++i) {
        int minj = i;
        for (int j = i + 1; j < N; ++j) {
            if (A[j].value < A[minj].value) {
                minj = j;
            }
        }
        swap(A[i], A[minj]);
    }
}

void print(struct Card A[], int N) {
    Rep(i, N) {
        if (i) {
            cout << " ";
        }
        cout << A[i].sign << A[i].value;
    }
    cout << endl;
}

bool isstable(struct Card A[], struct Card B[], int N) {
    Rep(i, N) {
        if (A[i].sign != B[i].sign) {
            return false;
        }
    }
    return true;
}

int main() {
    int N;
    cin >> N;
    Card A[100], B[100];
    Rep(i, N) {
        cin >> A[i].sign >> A[i].value;
        B[i].sign = A[i].sign;
        B[i].value = A[i].value;
    }
    bubble(A, N);
    selection(B, N);
    print(A, N);
    cout << "Stable" << endl;
    print(B, N);
    cout << (isstable(A, B, N) ? "Stable" : "Not stable") << endl;
    return 0;
}


Measured memory_bytes: 3108
# Big Array
n,k =  list(map(int, input().split()))

A = []
for i in range(n):
    a,b = list(map(int, input().split())) 
    A.append([a,b])
    
A.sort(key=lambda x:x[0])

cnt = 0
for i in range(n):
    cnt += A[i][1]
    if ( cnt >= k ):
        print(A[i][0])
        break

Measured memory_bytes: 21720
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        int age = scan.nextInt();
        if(age==7||age==5||age==3){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
    }
}


Measured memory_bytes: 22356
# coding:utf-8

import sys

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


A = LI()
A.sort()
print('Yes' if sum(A[:-1]) - A[-1] == 0 else 'No')


Measured memory_bytes: 2940
/*
██████╗  ███████╗  
██╔══██╗ ██╔════╝ 
██████╔╝ ███████╗ 
██╔══██╗ ╚════██║  
██║  ██║ ███████║      
╚═╝  ╚═╝ ╚══════╝                                                                                                             
*/

#include<bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define haha(j,a,n) for(int j=a;j<n;j++)
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define endl "\n"
#define bc(v) v.begin(),v.end()
#define vl vector<ll>
#define vi vector<int>
#define why 1000000007
#define NUM 100005
#define F first
#define S second
#define bhar(a) rep(i,a.size()) cin>>a[i];
#define show(a) rep(i,a.size()) cout<<a[i]<<" ";
#define sott(a) sort(bc(a))
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define mapp map<ll,ll>
#define dkac cout<<fixed<<setprecision(15);
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define yeah(n) while(n--)
ll gcd(int a, int b){if(b==0) return a; else return gcd(b,a%b);}
ll bitfun(ll x){
  return (x&(-x));
}
void solve(){
  ll n,k; cin>>n>>k;
  vl h(n); bhar(h);
  vl dp(n,1e18);
  dp[0]=0;
  dp[1]=abs(h[1]-h[0]);
  for(int i=2;i<k;i++){
      for(ll j=0;j<i;j++){
        dp[i] = min(dp[i],dp[j]+abs(h[j]-h[i]));
      }
  }
  for(int i=k;i<n;i++){
    for(int j=i-k;j<i;j++){
      dp[i] = min(dp[i],dp[j] + abs(h[j]-h[i]));
    }
  }
  //show(dp);
  cout<<dp[n-1];
}
int main(){
    ios
    int t=1; 
    //cin>>t;
    yeah(t){
      solve();
    }
}

Measured memory_bytes: 1792
a,b=map(int,input().split())
print(100,100)
b_r=b-1
q=b_r//50
r=b_r%50
for i in range(q):
    print('.'*100)
    print('.#'*50)
print('.'*100)
print('.#'*r+'..'*(50-r))
for i in range(50-2*(q+1)):
    print('.'*100)
a_r=a-1
q=a_r//50
r=a_r%50
for i in range(q):
    print('#'*100)
    print('#.'*50)
print('#'*100)
print('#.'*r+'##'*(50-r))
for i in range(50-2*(q+1)):
    print('#'*100)


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

int L = 0, R, n, len;
string cur, nxt;
int main() {
    cin >> n;
    cout << 0 << '\n';
    cout.flush();
    cin >> cur;
    if(cur == "Vacant") return 0;
    for(int i = 19; i >= 0; i--) {
        int pos = L + (1<<i);
        if(pos >= n) continue;
        cout << pos << '\n';
        cout.flush();
        cin >> nxt;
        if(nxt == "Vacant") return 0;
        if(cur == nxt) L += (1<<i), cur = nxt;
    }
    cout << L+1 << '\n';
    cout.flush();
}


Measured memory_bytes: 852
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair

using namespace std;

const int N=2e5+5;
const int mod=1000000007;
int n,a[N],b[N],pw[N],zero1,zero2;
map<pii,int>cnt;

main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>n;
    pw[0]=1;
    set<pii>val;
    int both=0;
    for(int i=1;i<=n;i++)
    {
        pw[i]=pw[i-1]*2%mod;
        cin>>a[i]>>b[i];
        if(a[i]==0&&b[i]==0) both++;
        else if(a[i]==0) zero1++;
        else if(b[i]==0) zero2++;
        else
        {int g=__gcd(abs(a[i]),abs(b[i]));
        a[i]/=g;
        b[i]/=g;
        if(b[i]<0)
        {
            a[i]*=-1;
            b[i]*=-1;
        }
        pii now=mp(a[i],b[i]);
        pii need=mp(-b[i],a[i]);
        if(need.se<0)
        {
            need.se*=-1;
            need.fi*=-1;
        }
        if(!val.count(need)) val.insert(now);
        cnt[now]++;
        }
    }
    int res=(pw[zero1]+pw[zero2]-1)%mod;
    for(auto&x:val)
    {
        pii cur=x;
        pii ncur=mp(-x.se,x.fi);
        //cout<<cur.fi<<' '<<cur.se<<' '<<ncur.fi<<' '<<
        if(ncur.se<0)
        {
            ncur.se*=-1;
            ncur.fi*=-1;
        }
        res=res*(pw[cnt[cur]]+pw[cnt[ncur]]-1+mod)%mod;
    }
    cout<<(res-1+mod+both)%mod;
}



Measured memory_bytes: 45644
import sys
input = sys.stdin.readline
S = list(input())[: -1]
rtable = [1]
ltable = [0]
N = len(S)
for i in range(1, N):
  if S[i - 1] == "L" and (S[i] == "R"):
    rtable.append(1)
    ltable.append(0)
  elif S[i] == "R": rtable[-1] += 1
  else:
    ltable[-1] += 1

lrtable = []

for i in range(N - 1):
  if S[i] == "R" and (S[i + 1] == "L"): lrtable.append(i)

#print(lrtable)
#print(ltable, rtable)
res = [0] * N
for i in range(len(lrtable)):
  x = lrtable[i]
  y = -(-ltable[i] // 2)
  z = -(-rtable[i] // 2)

  l = z + (ltable[i] - y)
  r = y + (rtable[i] - z)
  res[x] = l
  res[x + 1] = r
print(*res)

Measured memory_bytes: 53096
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>
#include <functional>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)
#define llrep(i, n) for(ll i = 0; i < n; ++i)
#define llREP(i, m, n) for(ll i = m; i < n; ++i)
#define llrrep(i,n) for(ll i = n; i >= 0; --i)
#define llRREP(i, m, n) for(ll i = n; i >= m; --i)

using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;
using plpii = std::pair<long long, std::pair<int, int>>;

using namespace std;

const long long _MOD = 1000000007;
const long long MOD = 998244353;

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

	string s, t;
	cin >> s >> t;

	if (t.length() == s.length() + 1) {
		if (s == t.substr(0, s.length())) {
			cout << "Yes" << "\n";
			return 0;
		}
	}

	cout << "No" << "\n";

	return 0;
}



Measured memory_bytes: 3656
let modulo = 1000003
let (+^) a b = (a + b) mod modulo
let ( *^) a b = (a * b) mod modulo
let rec ( ** ) a n =
  if n = 0 then 1
  else if n mod 2 = 1 then a *^ a ** (n-1)
  else let h = a ** (n/2) in h *^ h
let inv x = x ** (modulo-2)
let (/^) a b = a *^ inv b

let fact, facti =
  let fact = Array.make 1000003 1 in
  let facti = Array.make 1000003 1 in
  for i = 1 to 1000002 do
    fact.(i) <- i *^ fact.(i-1);
    facti.(i) <- inv fact.(i)
  done;
  fact, facti

let solve x d n =
  if d = 0 then x**n else 
  let y0 = x /^ d in
  if y0+n-1 >= modulo then 0
  else d**n *^ fact.(y0+n-1) *^ facti.(y0-1)

let () =
  Scanf.scanf "%d" @@ fun q ->
  for i = 1 to q do Scanf.scanf " %d %d %d" solve |> Printf.printf "%d\n" done


Measured memory_bytes: 22908
#include <bits/stdc++.h>
#define ri register
#define int long long
#define E (n+1)
using namespace std; const int N=200010;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
signed main()
{
    int x,y,z;;
    x=read(), y=read(), z=read();
    printf("%lld\n",(x-y)%z);
    return 0;
}

Measured memory_bytes: 3652
using System;
using System.Collections.Generic;
using System.Linq;

class D
{
	static void Main()
	{
		Func<long[]> read = () => Console.ReadLine().Split().Select(long.Parse).ToArray();
		var h = read();
		var v = new int[3].Select(_ => read().OrderBy(x => -x).ToArray()).ToArray();
		Console.WriteLine(string.Join("\n", comb(comb(v[0], v[1], (int)h[3]), v[2], (int)h[3])));
	}

	static long[] comb(long[] p, long[] q, int count)
	{
		var r = new List<long>();
		for (int i = 0; i < p.Length; i++)
			for (int j = 0; j < q.Length && (i + 1) * (j + 1) <= count; j++)
				r.Add(p[i] + q[j]);
		r.Sort((x, y) => y.CompareTo(x));
		return r.Take(count).ToArray();
	}
}


Measured memory_bytes: 15712
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import itertools

INF=10**10

N,M = map(int,readline().split())
A = [0,0]+list(map(int,readline().split()))
B = [[INF]*M]+[list(map(int,line.split())) for line in readlines()]

for i in range(1,N+1):
    A[i] += A[i-1]

answer = 0
INF = 10**12
diff = [INF]+[0]*N
left = [list(range(-1,N)) for m in range(M)]
arr = [INF,2,1,2]
for i in range(1,N+1):
    for m in range(M):
        p=i; prev_val=0
        q=left[m][p]
        x = B[i][m]
        while prev_val<=x:
            diff[p] += x-prev_val
            diff[q] -= x-prev_val
            p=q; q=left[m][p]
            prev_val=B[p][m]
        left[m][i]=p
    # 出発地点ごとの収入
    ticket_sum = list(itertools.accumulate(diff[::-1]))[::-1]
    for start in range(1,i+1):
        happy = ticket_sum[start] + A[start]-A[i]
        if answer < happy:
            answer = happy

print(answer)

Measured memory_bytes: 102112
#include<bits/stdc++.h>
using namespace std;
vector<int>g[100001];
int n,m;
int dp[100001];
int dfs(int now,int d){
  if(dp[now]>=0)return dp[now];
  if(g[now].size()==0)return dp[now]=0;
  int ret=0;
  for(int i=0;i<g[now].size();i++){
    ret=max(ret,dfs(g[now][i],d+1)+1);
  }
  return dp[now]=ret;
}
int main(){
  cin>>n>>m;
  fill(dp,dp+n,-1);
  int x[m],y[m];
  vector<int>sta;
  bool bo[n];
  fill(bo,bo+n,false);
  for(int i=0;i<m;i++){
    cin>>x[i]>>y[i];
    x[i]--;y[i]--;
    g[x[i]].push_back(y[i]);
    bo[y[i]]=true;
  }
  for(int i=0;i<n;i++){
    if(bo[i]==false)sta.push_back(i);
  }
  int ans=0;
  for(int i=0;i<sta.size();i++){
    ans=max(ans,dfs(sta[i],0));
  }
  cout<<ans<<endl;
  //for(int i=0;i<n;i++)cout<<dp[i]<<endl;
  
}
                        
  

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

#define trace(...) __f( #__VA_ARGS__ , __VA_ARGS__ )
template <typename Arg1>
void __f( const char* name , Arg1&& arg1 ) {
        cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f( const char* na , Arg1&& arg1 , Args&&... args ) {
        const char* c = strchr( na + 1 , ',' );
        cerr.write( na , c - na ) << " : " << arg1 << " , ";
        __f( c + 1 , args... );
}
#define endl "\n"
#define all(V) V.begin(),V.end()
#define Unique(V) sort(all(V)),V.erase(unique(all(V)),V.end())
#define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long int LL;
typedef pair <int,int> pii;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const double EPS = 1e-9;
const double PI = acos(-1.0);
const long long INF = 1e18;
const int N = 1e5 + 5;

int main( ) {
        IO;
        #ifdef LOCAL
            freopen( "input.txt" , "r" , stdin );
        #endif // LOCAL
        int n;
        cin >> n;
        cout << 180*(n-2) << endl;
        return 0;
}










Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less

using namespace std;
#define md 1000000007
#define itn int
#define pb push_back
#define mp make_pair
#define ull unsigned long long int
#define ll long long int
#define ppi pair<int, int>
#define ppl pair<ll, ll>
#define vi vector<int>
#define all(x) x.begin(), x.end()
#define ff first
#define lb lower_bound
#define ub upper_bound
#define ss second
#define inf 1e9
#define enld '\n'
#define cuot cout
#define trace1(x) cerr << #x << ": " << x << endl
#define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define trace3(x, y, z)                                                        \
  cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": "    \
       << z << endl
#define trace4(a, b, c, d)                                                     \
  cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \
       << c << " | " << #d << ": " << d << endl
#define trace5(a, b, c, d, e)                                                  \
  cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \
       << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl
#define trace6(a, b, c, d, e, f)                                               \
  cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \
       << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | "   \
       << #f << ": " << f << endl
#define trace(v)                                                               \
  for (auto it = v.begin(); it != v.end(); it++)                               \
    cerr << *it << " ";                                                        \
  cerr << endl;
#define linf 1e18
#define reset(x) memset(x, 0, sizeof(x))
#define rep(i, a, b) for (int i = a; i < b; i++)

using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    oset;

void fastio() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

void solve() {
    int n,k;cin>>n>>k;
    string s;cin>>s;
    s[k-1]= (char)(s[k-1]+32);
    cout<<s<<endl;
}
int main() {
  fastio();
  int t;
  t = 1;
  //   cin>>t;
  for (int i = 1; i <= t; i++) {
    solve();
  }
  return 0;
}

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

int A[5][5];

int main()
{
    for(int i = 0; i < 3; i++)for(int j = 0; j < 3; j++)scanf("%d",&A[i][j]);

    if(A[0][0] + A[1][1] + A[2][2] == A[0][2] + A[1][0] + A[2][1] && A[0][0] + A[1][1] + A[2][2] == A[0][1] + A[1][2] + A[2][0])printf("Yes\n");
    else printf("No\n");
    return 0;
}


Measured memory_bytes: 256
H,W = map(int, input().split())

A = [[0 for i in range(W)] for j in range(H)]

for i in range(H):
    A[i] = list(map(int, input().split()))

# 最小のコスト
Res = [[[float('Inf') for i in range(W * H)] for j in range(H)] for k in range(W)]
Res[0][0][0] = 0


for l in range(1, W*H):
    for x in range(W):
        # 探索する意味がない範囲
        if x > l:
            break
        for y in range(H):
            # 探索する意味がない範囲
            if x + y > l:
                break
            
            # 左
            if x != 0: 
                if Res[x-1][y][l] > Res[x][y][l-1] + ((l - 1) * 2 + 1) * A[y][x-1]:
                    Res[x-1][y][l] = Res[x][y][l-1] + ((l - 1) * 2 + 1) * A[y][x-1]
                
            # 右
            if x != (W-1):
                # print(x, y, l)
                if Res[x+1][y][l] > Res[x][y][l-1] + ((l - 1) * 2 + 1) * A[y][x+1]:
                    Res[x+1][y][l] = Res[x][y][l-1] + ((l - 1) * 2 + 1) * A[y][x+1]
                    
            # 上
            if y != 0:
                if Res[x][y-1][l] > Res[x][y][l-1] + ((l - 1) * 2 + 1) * A[y-1][x]:
                    Res[x][y-1][l] = Res[x][y][l-1] + ((l - 1) * 2 + 1) * A[y-1][x]
                        
            # 下
            if y != (H-1):
                if Res[x][y+1][l] > Res[x][y][l-1] + ((l - 1) * 2 + 1) * A[y+1][x]:
                    Res[x][y+1][l] = Res[x][y][l-1] + ((l - 1) * 2 + 1) * A[y+1][x]

print(min(Res[W-1][H-1]))


Measured memory_bytes: 44360
// https://atcoder.jp/contests/abc075/tasks/abc075_c

#include <iostream>
#include <vector>
#include <functional>

using namespace std;
using ll = long long;

struct C {
    vector<ll> src_{};
    vector<ll> tgt_{};
    ll N_{};
    vector<vector<ll>> e_{};

    explicit C(vector<ll> src, vector<ll> tgt, ll N) : src_(move(src)), tgt_(move(tgt)), N_(N){
        e_.resize(N_+1);
        for(int i=0; i < src_.size(); ++i) {
            e_[src_[i]].emplace_back(tgt_[i]);
            e_[tgt_[i]].emplace_back(src_[i]);
        }
    }
    void dfs(vector<bool>& visited, ll prev, ll cur, std::function<bool(ll, ll)> l) {
        visited[prev] = true;
        for(auto t : e_[cur]) {
            if (visited[t] || !l(cur, t)) {
                continue;
            }
            dfs(visited, cur, t, l);
        }
        visited[prev] = false;
    }
    bool check(ll src, ll tgt) {
        bool unreached = true;
        vector<bool> visited;
        visited.resize(N_+1, false);
        dfs(visited, 0, src, [&src, &tgt, &unreached](auto a, auto b) {
            if (a == src && b == tgt) {
                return false;
            }
            if (b == tgt) {
                unreached = false;
                return false;
            }
            return true;
        });
        return unreached;
    }
    ll resolve() {
        ll count = 0;
        for(int i=0; i < src_.size(); ++i) {
            if(check(src_[i], tgt_[i])) {
                ++count;
            }
        }
        return count;
    }
};

int main() {
    ll N, M;
    cin >> N >> M;
    vector<ll> src{};
    vector<ll> tgt{};
    for (int i=0; i < M; ++i) {
        ll x;
        ll y;
        cin >> x >> y;
        src.emplace_back(x);
        tgt.emplace_back(y);
    }
    C c{move(src), move(tgt), N};
    cout << c.resolve() << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;
int main()
{
    int n,r,p,ans;
    cin>>n>>r;

    if(n<10)
    {
        p=100*(10-n);

        ans=r+p;

        cout<<ans<<endl;

    }
    else
    {
        cout<<r<<endl;
    }


    return 0;
}


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

using namespace std;

#define rep(i,n) for (decay_t <decltype (n)> i = 0, i ## __len = (n); i < i ## __len; ++ i)

static auto generate_id ()
{
  static int res = 0;
  return res ++;
}

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

  size_t n, m;
  cin >> n >> m;

  vector <int> connected_graph_ids (n + 1, -1);
  vector <vector <size_t>> goable (n + 1);

  rep (i, m)
  {
    size_t x, y;
    int z;
    cin >> x >> y >> z;

    goable [x].emplace_back (y);
    goable [y].emplace_back (x);
  }

  queue <size_t> q;

  for (size_t i = 1; i <= n; ++ i)
  {
    if (connected_graph_ids [i] == -1)
    {
      connected_graph_ids [i] = generate_id ();
      q.push (i);
      while (! q.empty ())
      {
        auto node = q.front ();
        q.pop ();
        for (auto && to : goable [node])
        {
          if (connected_graph_ids [to] == -1)
          {
            connected_graph_ids [to] = connected_graph_ids [node];
            q.push (to);
          }
        }
      }
    }
  }

#ifdef DEBUG
  cerr << "debug: ";
  copy (connected_graph_ids.begin (), connected_graph_ids.end (), ostream_iterator <decay_t <decltype (connected_graph_ids.front ())>> (cerr, " "));
  cout << endl;
#endif

  cout << generate_id () << endl;
}


Measured memory_bytes: 7796
#include <cassert>
#include <iostream>
#include <functional>
#include <iomanip>
#include <set>
#include <unordered_map>
#include <queue>
#include <vector>
#include <deque>
#include <algorithm>
#include  <cstring>
#include <string>
#include <cmath> 
using namespace std;
typedef long long LL;
const int MAX = 210000;
const LL base = 1e9 + 7;


struct Node {
	int x, y, w;
};

LL md[11000][100];

void solve() {

	LL result = 0;
	int d;

	string k;
	cin >> k;
	cin >>d;
	md[0][0] = 1;
	for (int i = 0; i < k.size(); ++i) {
		for (int j = 0; j < d; ++j) {
			for (int t = 0; t < 10; ++t) {
				auto & x = md[i + 1][(j + t) % d];
				x += md[i][j];
				x %= base;
			}
		}
	}
	int lm = 0;
	for (int i = 0; i < k.size(); ++i) {
		for (int j = 0; '0' + j < k[i]; ++j) {
			int x = lm + j;
			x = d - x;
			x %= d;
			if (x < 0) x += d;
			result += md[k.size() - 1 - i][x];
			result %= base;
		}
		lm += k[i] - '0';
		lm %= d;
	}
	if (lm%d == 0) result++;
	result-- ;
	if (result < 0) result += base;
	cout << result << endl;

}

int main() {
	const int inId = 0;
	const int outId = 0;
	if (inId>0) {
		cerr << "redirect stdin to input " << inId << endl;
		string s = "input";
		s += to_string(inId);
		s += ".txt";
		auto r = freopen(s.c_str(), "r", stdin);	
		if (r == nullptr) {
			cerr<< "invalid input file "<< s;
		}
	}
	if (outId>0) {
		cerr << "redirect stdout to stdout " << outId << endl;
		string s = "stdout";
		s += to_string(outId);
		s += ".txt";
		auto r = freopen(s.c_str(), "w", stdout);
		if (r == nullptr) {
			cerr<< "invalid output file "<< s;
		}		
	}
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // close sync between cout and printf
	cout.precision(10);
	solve();
}
 

Measured memory_bytes: 8448
n,m,x=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(n)]
ans=float("inf")
for i in range(2**n):
    ll=[0 for _ in range(m+1)]
    now=0
    for j in range(n):
        if (i>>j)&1:
            now+=l[j][0]
            for k in range(m):
                ll[k+1]+=l[j][1+k]
    if all(ll[s]>=x for s in range(1,m+1)):
        ans=min(ans,now)
print(ans if ans!=float("inf") else -1)


Measured memory_bytes: 69004
inp=int(input())
if 400<=inp<=599:
    print(8)
if 600<=inp<=799:
    print(7)
if 800<=inp<=999:
    print(6)
if 1000<=inp<=1199:
    print(5)
if 1200<=inp<=1399:
    print(4)
if 1400<=inp<=1599:
    print(3)
if 1600<=inp<=1799:
    print(2)
if 1800<=inp<=1999:
    print(1)

Measured memory_bytes: 9188
x = int(input())
a = list(map(int,input().split()))
#for i in range(x):
 #   a = int(input())
#    a = list(map(int,input().split()))
#a = [input().split() for l in range(x)]
#for i in range(x):
 #   a , b , c = list(map(int,input().split()))
  #  lst = [32, 14, 2, 17, 48, 50, 15, 24, 46, 8]
   # a = min(lst)
    #b = max(lst)
    #c = sum(lst)
#print(a)

x = min(a)
y = max(a)
z = sum(a)
print(x,end=' ')
print(y,end=' ')
print(z)
#    print(min(a))
#    print(max(a))
#    print(sum(a))


Measured memory_bytes: 6584
import numpy as np
import sys

mod = 10 ** 9 + 7

if sys.argv[-1] == 'ONLINE_JUDGE':
	from numba.pycc import CC
	cc = CC('unko')
	@cc.export('main', '(i8, i8, i8[:])')
	def main(n, k, a):
		fac = np.full(n + 3, 1, dtype = np.int64)
		for i in range(1, n + 1):
			fac[i] = fac[i - 1] * i % mod
		
		def inv(x):
			res = 1
			e = mod - 2
			while e > 0:
				if e & 1:
					res = res * x % mod
				x = x * x % mod
				e >>= 1
			return res
		def c(n, k):
			return fac[n] * inv(fac[n - k] * fac[k] % mod) % mod

		ans = 0
		for i in range(n - k + 1):
			ans += (a[n - 1 - i] - a[i]) * c(n - 1 - i, k - 1)
			ans %= mod
		print(ans)
	cc.compile()
	exit()


if __name__ == '__main__':
	from unko import main
	stdin = np.fromstring(sys.stdin.read(), dtype=np.int64, sep=' ')
	n, k = stdin[:2]
	a = np.sort(stdin[2:])
	main(n, k, a)


Measured memory_bytes: 29128
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

a = rr()
b = 0
for i in a:
  b += int(i)
  b = b%9
if b == 0:
  print('Yes')
else:
  print('No')

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

using namespace std;

int main()
{
  int a[3]; cin >> a[0] >> a[1] >> a[2];
  if (a[0] == a[1]) cout << a[2];
  else if(a[1] == a[2]) cout << a[0];
  else cout << a[1];
}

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

public class Main{
	public static void main(String[] args){
		try{
			new Main();
		}catch(IOException err){
			err.printStackTrace();
		}
	}
	
	public double[] c500 = {
			35.5, 37.5, 40.0, 43.0, 50.0, 55.0, 70.0
	};
	
	public double[] c1000 = {
			71.0, 77.0, 83.0, 89.0, 105.0, 116.0, 148.0
	};
	
	public String[] cname = {
			"AAA", "AA", "A", "B", "C", "D", "E", "NA"
	};
	
	public Main() throws IOException{
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		List<Integer> Ans = new ArrayList<Integer>();
		String line;
		
		while((line = in.readLine()) != null){
			String[] dst = line.split(" ");
			double t500 = Double.parseDouble(dst[0]);
			double t1000 = Double.parseDouble(dst[1]);
			
			int cls = 7;
			for(int i=0; i<7; i++){
				if(t500 < c500[i] && t1000 < c1000[i]){
					cls = i;
					break;
				}
			}
			Ans.add(cls);
		}
		
		for(int n=0; n<Ans.size(); n++){
			System.out.println(cname[Ans.get(n)]);
		}
	}
}

Measured memory_bytes: 10000
import java.io.File;
import java.io.IOException;
import java.util.Scanner;

public class Main {
	static int time = 0;

	public static void main(String[] args) throws IOException {

		Scanner scan = new Scanner(System.in);
		// Scanner scan = new Scanner(new
		// File("D:\\UserArea\\J0124567\\Downloads\\ALDS1_6_A-in9.txt"));

		int n = scan.nextInt();

		int[][] v = new int[n + 1][n];
		int[] d = new int[n + 1];
		int[] f = new int[n + 1];

		for (int i = 0; i < n; i++) {
			int u = scan.nextInt();
			int k = scan.nextInt();
			for (int j = 0; j < k; j++)
				v[u][j] = scan.nextInt();
		}

		for (int i = 1; i <= n; i++) {
			if (d[i] == 0)
				Dsearch(v, d, f, i);
		}

		for (int i = 1; i <= n; i++) {
			System.out.println(i + " " + d[i] + " " + f[i]);
		}

		scan.close();
		System.exit(0);
	}

	private static void Dsearch(int[][] v, int[] d, int[] f, int u) {
		d[u] = ++time;
		for (int i = 0; i < v[u].length && v[u][i] > 0; i++)
			if (d[v[u][i]] == 0)
				Dsearch(v, d, f, v[u][i]);
		f[u] = ++time;
	}
}

Measured memory_bytes: 28128