akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import static java.lang.System.*;
import java.io.*;
import java.math.*;

public class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
        	a[i] = sc.nextInt();
        }
        int cnt = 0;
        int search = 1;
        for(int i = 0; i < n; i++) {
        	if (a[i] == search) {
        		cnt++;
        		search++;
        	}
        }
        int ans = n - cnt; 
        if (ans == n) ans = -1;
        out.println(ans);
              
    }
static class FastScanner {
    private final 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;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; 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() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}
}


Measured memory_bytes: 22356
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;

const int MAX_N = 100005;

int N, M, A[MAX_N], B[MAX_N], odd;

int main() {
  scanf("%d%d", &N, &M);
  for (int i = 1; i <= M; ++i) {
    scanf("%d", &A[i]);
    if (A[i] & 1) odd++;
  }

  if (M == 1) {
    if (N == 1) printf("1\n1\n1\n");
    else printf("%d\n2\n%d %d\n", N, N - 1, 1);
  } else if (odd <= 2) {
    for (int i = 1, num = 0; i <= M; ++i)
      if ((A[i] & 1) && num == 0) swap(A[1], A[i]), num++;
      else if ((A[i] & 1) && num == 1) swap(A[i], A[M]), num++;

    int tot = 0, sum = 0;
    for (int i = 1; i <= M; ++i) {
      sum += A[i];
      if (i != M && sum != 1) {
	B[++tot] = sum - 1;
      } else if (i == M) {
	B[++tot] = N;
      }
    }

    for (int i = 1; i <= M; ++i)
      printf("%d ", A[i]);
    puts("");

    printf("%d\n", tot);

    for (int i = 1; i <= tot; ++i)
      printf("%d ", B[i] - B[i - 1]);
    puts("");

  } else {
    puts("Impossible");
  }
  
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>

int main() {

	std::string s;
	std::cin >> s;

	int N = s.size();
	int st = 0;
	int ed = 0;

	for (int i = 0; i < N; i++) {
		if (s[i] == 'A') {
			st = i;
			break;
		}
	}

	std::reverse(s.begin(), s.end());

	for (int i = 0; i < N; i++) {

		if (s[i] == 'Z') {
			ed = i;
			break;
		}
	}

	ed = N - ed - 1;

	int ans = ed - st + 1;

	std::cout << ans << std::endl;

}

Measured memory_bytes: 640
class UnionFind
    def initialize(n); @data = Array.new(n, -1); end
    def find(a); @data[a] < 0 ? a : @data[a] = find(@data[a]); end
    def same?(a, b); find(a) == find(b); end
    def size(a); -@data[find(a)]; end
    def unite(a, b)
        a = find(a) 
        b = find(b)
        return if a == b
        a, b = b, a if @data[a] > @data[b]
        @data[a] += @data[b]
        @data[b] = a
    end
end

n, m, k = gets.chomp.split(" ").map(&:to_i)
UF = UnionFind.new(n)
FR = Array.new(n){[]}
BL = Array.new(n){[]}

m.times do 
    a, b = gets.chomp.split(" ").map(&:to_i)
    a -= 1
    b -= 1
    UF.unite(a, b)
    FR[a] << b
    FR[b] << a
end

k.times do 
    a, b = gets.chomp.split(" ").map(&:to_i)
    a -= 1
    b -= 1
    BL[a] << b
    BL[b] << a
end

ans = n.times.map do |i|
    count = UF.size(i)
    FR[i].each do |j|
        count -= 1 if UF.same?(i, j)
    end
    BL[i].each do |l|
        count -= 1 if UF.same?(i, l)
    end
    count -= 1
end

puts ans.join(" ")

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

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define st first
#define nd second
#define endl '\n'
#define what_is(x) cerr << #x << " is " << x << endl;
#define what_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << e << ' '; cerr << '\n'; //vector, set
#define what_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << x[i] << ' '; cerr <<  '\n'; //n first element of array
#define cerr_pair(x) '{' << x.st << ", " << x.nd << '}'
#define pwhat_is(x) cerr << #x << " is " << cerr_pair(x) << endl;
#define pwhat_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << cerr_pair(e) << ' '; cerr << '\n'; //vector, set
#define pwhat_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << cerr_pair(x[i]) << ' '; cerr <<  '\n'; //n first element of array
// #define int long long
// #define pow mypow

typedef pair<int,int> pii;
const int N = 1e5+5;
const int INF = 1e9+5;
const int MOD = 1e9+7;
const double pi = 3.14159265358979;

double a, b, h, m;
int32_t main()
{
	IOS
	// freopen("input.txt", "r", stdin);
	cin >> a >> b >> h >> m;
	double angle = abs((h+m/60)/12  - (m/60)) * 2*pi;
	angle = min(angle, 2*pi-angle);
	double ans = a*a + b*b - 2*a*b*cos(angle);
	ans = sqrt(ans);
	cout << fixed;
	cout << setprecision(10);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4156
# coding:utf-8
import math
def isprime(x):
    if x == 2:
        return True
    if x < 2 or x % 2 == 0:
        return False
    i = 3
    while i <= math.sqrt(x):
        if x % i == 0:
            return False
        i = i + 2
    return True
n = input()
array = []
cnt = 0
for i in range(n):
    array.append(input())
for i in range(n):
    if isprime(array[i]):
        cnt += 1
print cnt

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

int main() {
    int N;
    cin >> N;
    vector<int> H(N);
    for (int i = 0; i < N; i++)
        cin >> H[i];

    int res = 0, now = 0;
    for (int i = 0; i < N; i++) {
        if (H[i] >= now) {
            res += H[i] - now;
        }
        now = H[i];
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <list>
#include <iomanip>
#include <vector>
#include <functional>
#include <algorithm>
#include <cstdio>
#include <random>
#include <ctime>
#include <cstdlib>
#include <unordered_map>
#include <string.h>
#include <iostream>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    string S, T;
    cin >> S >> T;
    rep(0, i, S.size())
    {
        if (S.at(i) != T.at(i))
        {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 3632
# -*- coding: utf-8 -*-
import bisect
n = int(input())
l = list(map(int, input().split()))
l.sort()
result = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        tmp = l[i] + l[j]
        ind = bisect.bisect_left(l, tmp)
        result += (ind-j-1)
print(result)



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

typedef long long LL;
typedef pair<int, int> II;

const int MAXN = (int) 1e5 + 10;
const int MOD  = (int) 1e9 + 7;
int n, a[MAXN];
int pos[MAXN];
int fac[MAXN];
int inv[MAXN];

int Power(int a, int k) {
	int ans = 1;
	while (k > 0) {
		if (k & 1) ans = (LL) ans * a % MOD;
		a = (LL) a * a % MOD;
		k >>= 1;
	}
	return ans;
}

int C(int n, int k) {
	if (n < k) return 0;
	return (LL) fac[n] * inv[k] % MOD * inv[n - k] % MOD;
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n + 1; ++i) scanf("%d", &a[i]);

	int x = -1, y = -1;
	for (int i = 1; i <= n; ++i) pos[i] = -1;
	for (int i = 1; i <= n + 1; ++i) {
		if (pos[a[i]] != -1) {
			x = pos[a[i]];
			y = i;
		}
		pos[a[i]] = i;
	}

	fac[0] = inv[0] = 1;
	for (int i = 1; i <= n + 1; ++i) {
		fac[i] = (LL) fac[i - 1] * i % MOD;
		inv[i] = Power(fac[i], MOD - 2);
	}

	for (int k = 1; k <= n + 1; ++k) {
		int tot = C(n + 1, k);
		int sub = C(x + n - y, k - 1);
		printf("%d\n", (tot + MOD - sub) % MOD);
	}
	return 0;
}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
typedef pair<int,int> P;
vector<P> construct(vector<int> as){
	int N = as.size();
	if(N==4){
		vector<P> res;
		res.pb(P(1,0));
		res.pb(P(1,1));
		res.pb(P(0,1));
		res.pb(P(0,0));
		return res;
	}
	int s = -1;
	rep(i,N){
		if(as[i]==90 && as[(i+1)%N]==270) s=i;
	}
	vector<int> nas;
	for(int i=s-1;i<s-1+N;i++) if(i!=s&&i!=s+1) nas.pb(as[(i+N)%N]);
	vector<P> base = construct(nas);
	vector<P> res(N);

	rep(i,N-2){
		P p = base[i];
		if(i==0 || base[0].fs<p.fs) p.fs++;
		if(base[0].sc<p.sc) p.sc++;
		int id = (i==0?0:i+2);
		res[id] = p;
	}
	res[1] = P(res[0].fs,res[0].sc+1);
	res[2] = P(res[1].fs-1,res[1].sc);
	assert(res[2].fs==res[3].fs);
	// puts("--------");
	// show(res);
	// puts("--------");
	rotate(res.begin(),res.begin()+(N-s+1)%N,res.end());
	if(res[0].fs!=res[1].fs){
		rep(i,N) swap(res[i].fs,res[i].sc),res[i].fs*=-1;
	}
	assert(res[0].fs==res[1].fs);
	if(res[0].sc>res[1].sc){
		rep(i,N) res[i].fs*=-1, res[i].sc*=-1;
	}
	// show(as);
	// printf("erase %d,%d\n",s,(s+1)%N);
	// show(res);
	return res;
}
int main(){
	int N;
	vector<int> xs;
	cin>>N;
	int sum = 0;
	rep(i,N){
		int x;
		cin>>x;
		xs.pb(x);
		if(x==90) sum++;
		else sum--;
	}
	if(sum!=4){
		puts("-1");
		return 0;
	}
	vector<P> ans = construct(xs);
	rep(i,N) ans[i].fs += 5e8, ans[i].sc += 5e8;
	rep(i,N){
		cout<<ans[i].fs<<" "<<ans[i].sc<<endl;
	}
}


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

using namespace std;
int dp[1 << 12]; // minimum value

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    vector<pair<int, int> > V(M);
    for (int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b;
        V[i] = {a, 0};
        for (int j = 0; j < b; ++j) {
            int c;
            cin >> c;
            V[i].second += 1 << (c - 1);
        }
    }
    sort(V.begin(), V.end());
    for (int i = 1; i < (1 << N); ++i) {
        dp[i] = 1e7;
        for (int j = 1; 2 * j < i; ++j) { // combination
            if ((i & j) == j) {
                dp[i] = min(dp[i], dp[j] + dp[i - j]);
            }
        }
        for (int j = 0; j < M; ++j) {
            if (V[j].first >= dp[i]) break;
            if ((i & V[j].second) == i) {
                dp[i] = V[j].first;
                break;
            }
        }
    }
    int ans = dp[(1 << N)-1];
    if (ans >= 1e7) {
        ans = -1;
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){

  int a,b;

  scanf("%d %d", &a,&b);

  if (a < b)
    puts("a < b");
  else if (a > b)
    puts("a > b");
  else if (a == b)
    puts("a == b");

  return 0;
}
    

Measured memory_bytes: 580
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
int main(){
    int a,b;
    std::cin >> a >> b;
    int c = a - (2 * b);
    if(c < 0){
        c = 0;
    }
    std::cout << c << std::endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <set>
#include <vector>
using namespace std;

constexpr int N = 2e5 + 5;

int i, n, m1, m2, x, y, where1[N], where2[N], rs[N];
bool viz[N];
vector<int> lda1[N], lda2[N];
vector<set<int>> comp1, comp2;

void dfs1(int x) {
  viz[x] = 1;
  comp1.back().insert(x);
  where1[x] = comp1.size() - 1;
  for (int to : lda1[x]) if (!viz[to]) dfs1(to);
}

void dfs2(int x) {
  viz[x] = 1;
  comp2.back().insert(x);
  where2[x] = comp2.size() - 1;
  for (int to : lda2[x]) if (!viz[to]) dfs2(to);
}

set<int> getIntersection(int x, int y) {
  if (!comp1[x].size() || !comp2[y].size()) return {};
  auto it1 = comp1[x].begin();
  auto it2 = comp2[y].begin();
  set<int> ans;
  while(it1 != comp1[x].end() && it2 != comp2[y].end()) {
    if (*it1 == *it2) ans.insert(*it1), ++it1, ++it2;
    else {
      if (*it1 < *it2) ++it1;
      else ++it2;
    }
  }
  for (auto it : ans) comp1[x].erase(it), comp2[y].erase(it);
  return ans;
}

int main() {
  scanf("%d %d %d", &n, &m1, &m2);
  while (m1--) {
    scanf("%d %d", &x, &y);
    lda1[x].push_back(y);
    lda1[y].push_back(x);
  }
  while (m2--) {
    scanf("%d %d", &x, &y);
    lda2[x].push_back(y);
    lda2[y].push_back(x);
  }

  for (i = 1; i <= n; ++i) if (!viz[i]) comp1.push_back(set<int>()), dfs1(i);
  memset(viz, 0, sizeof(viz));
  for (i = 1; i <= n; ++i) if (!viz[i]) comp2.push_back(set<int>()), dfs2(i);

  memset(viz, 0, sizeof(viz));
  for (i = 1; i <= n; ++i) {
    if (viz[i]) continue;
    auto S = getIntersection(where1[i], where2[i]);
    for (auto it : S) viz[it] = 1, rs[it] = S.size();
  }
  for(i=1;i<=n;++i)rs[i]=max(rs[i], 1);
  for(i = 1; i <= n; ++i) printf("%d%c", rs[i], " \n"[i == n]);

  return 0;
}


Measured memory_bytes: 44080
#include <bits/stdc++.h>
#define ll long long int  

using namespace std;

#define max 4000000000

void bkt(ll x, set<ll> &visited){

	if(visited.find(x) != visited.end() || x > max){
		return;
	}
	if(x!=0)
	visited.insert(x);
	
	if(x == 0){
		for(ll i=1;i<=9;i++){
			bkt(i, visited);
		}
	} else {

		ll lastDigit = x%10;
		if(lastDigit > 0){
			bkt(10*x + lastDigit-1, visited);
		}
		bkt(10*x + lastDigit,visited);
		if(lastDigit < 9){
			bkt(10*x + lastDigit+1,visited);
		}
	}

}

void solve(){

	ll k;
	cin>>k;

	set<ll> visited;
	bkt(0, visited);

	ll ans = -1;
	ll i=1;
	// visited.erase(visited.begin());
	for(ll el : visited){
		if(i == k){
			ans = el;
			break;
		}
		i++;
	}
	cout<<ans<<endl;

}

int main(){

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	ll t;
	// cin>>t;
	t=1;
	while(t--){
		solve();
	}

}

Measured memory_bytes: 5504
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;

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 (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()

int main() {
    int h, w;
    cin >> h >> w;
    int n;
    cin >> n;
    vector<int> a(n);
    rep (i, n) {
        cin >> a[i];
    }
    vector<vector<int>> c(h, vector<int>(w));
    int hash = 0;
    rep (i, n) {
        rep (j, a[i]) {
            int y = hash / w;
            int x = hash % w;
            c[y][x] = i + 1;
            hash++;
        }
    }
    rep (i, h) {
        if(i % 2 == 0) {
            reverse(all(c[i]));
        }
    }
    rep (i, h) {
        rep (j, w) {
            if (j > 0) {
                cout << " ";
            }
            cout << c[i][j];
        }
        cout << endl;
    }
}


Measured memory_bytes: 384
#include <bits/stdc++.h>;
#define FIO ios_base::sync_with_stdio(0); cin.tie(0);
#define T() int tt; cin>>tt; while(tt--)
#define mp make_pair
#define pb push_back
#define lchild (2*node+1)
#define rchild (2*node+2)
#define f first
#define s second
#define br cout<<endl

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;

ll gcd(ll a, ll b){
    if(b==0)return a;
    else gcd(b, a%b);
}
ll pwr(ll base, ll p, ll mod){
    ll ans=1; while(p){if(p&1)ans=(ans*base)%mod; base=(base*base)%mod; p/=2;} return ans;
}


int main(){
    FIO
    ll x, a, b;
    cin >> x >> a >> b;

    if(b-a<=0){
        cout << "delicious" << endl;
    }
    else {
        if(b-a<=x){
            cout << "safe" << endl;
        }
        else cout << "dangerous" << endl;
    }



return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
namespace mp = boost::multiprecision;
#define ll long long
#define cpp mp::cpp_int
#define dequeue deque
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = 1; i <= n; i++)
#define drep(i, n) for(int i = n-1; i >= 0; i--)
#define srep(i, s, t) for (int i = s; i < t; i++)
#define vi vector<int>
#define P pair<ll, ll>
int mod = 1'000'000'000 + 7;
struct edge {
	int to;
	ll cost;
};

void COME_LET_THE_GAMES_BEGIN() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << setprecision(20);
}
void reverse(string* s) {
	reverse((*s).begin(), (*s).end());
}
int main() {
	COME_LET_THE_GAMES_BEGIN();
	int N, M;
	cin >> N >> M;
	vector<int> A(N);
	rep(i, N)cin >> A[i];
	vector<pair<int,int>> v;
	rep(i, M) {
		int b, c;
		cin >> b >> c;
		v.push_back(P(b, c));
	}
	sort(v.begin(), v.end(), [](auto p, auto q) {
		return p.second > q.second;
		});
	sort(A.begin(), A.end());
	int a = 0;
	for (auto x : v) {
		rep(i, x.first) {
			if (a < N && A[a] < x.second) {
				A[a] = x.second;
				a++;
			}
			else {
				break;
			}
		}
	}
	ll ans = 0;
	rep(i, N) {
		ans += A[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 1784
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <time.h>
#define int long long
#define endl '\n'
#define INF 1000000000000000000
#define EPS 1e-10
#define PI 3.141592653589793238
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define double long double
#define square1001 E869120
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;
typedef complex<double> com;
template<class T, class S> bool chmax(T &a, const S &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class S> bool chmin(T &a, const S &b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }

int h, w, k;
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };

struct T {
	int x, y, dis;
};

int dist(int x, int y) {
	return min({ x, h - 1 - x, y, w - 1 - y });
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	//modcalc();

	cin >> h >> w >> k;
	vector<vector<char>> a(h, vector<char>(w));
	queue<T> que;
	vector<vector<bool>> vis(h, vector<bool>(w));
	int ans;
	rep(i, h) {
		rep(j, w) {
			cin >> a[i][j];
			if (a[i][j] == 'S') {
				que.push({ i,j,0 });
				ans = dist(i, j);
				vis[i][j] = true;
			}
		}
	}
	while (!que.empty()) {
		T p = que.front(); que.pop();
		if (p.dis >= k) continue;
		rep(i, 4) {
			int nx = p.x + dx[i];
			int ny = p.y + dy[i];
			if (nx < 0 || h <= nx || ny < 0 || w <= ny || a[nx][ny] == '#' || vis[nx][ny]) continue;
			chmin(ans, dist(nx, ny));
			vis[nx][ny] = true;
			que.push({ nx,ny,p.dis + 1 });
		}
	}
	cout << (ans + k - 1) / k + 1 << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

signed main() {
    int H, W, m;
    cin >> H >> W >> m;
    int cnty[H] = {}, cntx[W] = {};
    int h[m], w[m];
    rep(i, m) {
        cin >> h[i] >> w[i];
        h[i]--;
        w[i]--;
        cnty[h[i]]++;
        cntx[w[i]]++;
    }
    vector<int> y, x;
    rep(i, H) {
        y.emplace_back(cnty[i]);
    }
    rep(i, W) {
        x.emplace_back(cntx[i]);
    }
    sort(ALL(y));
    reverse(ALL(y));
    sort(ALL(x));
    reverse(ALL(x));
    int yy = 0, xx = 0;
    rep(i, H) {
        if (y[i] != y[0]) break;
        yy++;
    }
    rep(i, W) {
        if (x[i] != x[0]) break;
        xx++;
    }
    int ans = y[0] + x[0];
    ll sum = (ll)yy * xx;
    rep(i, m) {
        if (cnty[h[i]] == y[0] && cntx[w[i]] == x[0]){
            sum--;
        }
    }
    if (sum == 0) ans--;
    cout << ans << endl;
    return 0;
}

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

int main(int argc, char **argv)
{
  int N;
  long long W;
  cin >> N >> W;
  vector<int> value[4];
  long long w0;
  for (int i = 0; i < N; ++i) {
    int w, v;
    cin >> w >> v;
    if (i == 0) w0 = w;
    value[w - w0].push_back(v);
  }

  // for (int i = 0; i < 4; ++i)
  //   cout << value[i].size() << endl;

  vector<int> ruisekiwa[4];
  for (int i = 0; i < 4; ++i) {
    sort(value[i].begin(), value[i].end(), greater<int>());
  }
  for (int i = 0; i < 4; ++i) {
    ruisekiwa[i].push_back(0);
    for (int j = 0; j < value[i].size(); ++j) {
      ruisekiwa[i].push_back(ruisekiwa[i].back() + value[i][j]);
    }
  }

  // for (int i = 0; i < 4; ++i)
  //   cout << value[i].size() << endl;

  int maxValue = 0;
  for (int n1 = 0; n1 <= value[0].size(); ++n1) {
    for (int n2 = 0; n2 <= value[1].size(); ++n2) {
      for (int n3 = 0; n3 <= value[2].size(); ++n3) {
        for (int n4 = 0; n4 <= value[3].size(); ++n4) {
          if (w0*n1 + (w0+1)*n2 + (w0+2)*n3 + (w0+3)*n4 > W) continue;
          int sum = 0;

          sum += ruisekiwa[0][n1];
          sum += ruisekiwa[1][n2];
          sum += ruisekiwa[2][n3];
          sum += ruisekiwa[3][n4];

          // cout << sum << endl;
          maxValue = (sum > maxValue) ? sum : maxValue;
        }
      }
    }
  }
  cout << maxValue << endl;

  return 0;
}


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

int main(void){
  int i,N; cin >> N;
  vector<char> c(N);
  vector<int> r(N,0),w(N,0);
  for(i=0; i<N; ++i){
    cin >> c[i];
    if(c[i]=='R') ++r[i]; else ++w[i];
    if(i<N-1) {r[i+1] = r[i]; w[i+1] = w[i];}
  }
  int dis=r[N-1]-1;
  cout << w[dis] << endl;
  return 0;
}


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

using Graph = vector<vector<pair<int, int>>>;
Graph G;
vector<int> color;

void dfs(int v, int cur = 0) {
    color[v] = cur;
    for (auto e : G[v]) {
        if (color[e.first] != -1) continue;
        if (e.second % 2 == 0) {
            dfs(e.first, cur);
        }
        else dfs(e.first, 1-cur);
    }
    return;
}

int main() {
    int N;
    cin >> N;
    G.assign(N, vector<pair<int, int>>());
    color.assign(N, -1);

    for (int i = 0; i < N-1; i++) {
        int a, b, c; cin >> a >> b >> c; a--; b--;
        G[a].push_back(pair<int, int>(b, c));
        G[b].push_back(pair<int, int>(a, c));
    }

    dfs(0);

    for (int i = 0; i < N; i++) {
        cout << color[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define mp make_pair
#define All(v) v.begin(),v.end()
#define mod 1000000007
#define pi 3.14159265358979323
using namespace std;
int a[200005];
int main()
{
    int n;
    cin >> n;
    ll sum = 0;
    ll res = 1e17;
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        sum += a[i];
    }
    ll x = 0;
    for(int i=0;i<n-1;i++)
    {
        x+=a[i];
        sum -= a[i];

        res = min(res,abs(x-sum));
    }
    cout << res << endl;


}


Measured memory_bytes: 1024
// Shuffling
// * frank_c1
// * 2017 / 09 / 30

#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;

const int maxn = 3005;
const int mo = (int)(1e9) + 7;
char s[maxn];
pii b[maxn];
int a[maxn], f[maxn], g[maxn];
int n, m, tot, cnt;

inline void addX(int p) {
	if (s[p] == '1') {
		for (int j = n; j; --j) f[j] = f[j - 1]; f[0] = 0; ++cnt;
	} ++tot;
}

inline void add(int& x, int v) {
	x += v; if (x >= mo) x -= mo;
}

int main() {
	scanf("%d%d", &n, &m);
	scanf("%s", s + 1);
	for (int i = 1; i <= m; ++i) scanf("%d%d", &b[i].first, &b[i].second);
	int ps = 1, mx = 1; f[0] = 1;
	for (int i = 1; i <= n; ++i) {
		while (mx <= i) addX(mx++);
		for (; ps <= n && b[ps].first == i; ++ps) {
			while (mx <= b[ps].second) addX(mx++);
		}
		memset(g, 0, sizeof(g));
		for (int j = 0; j <= cnt; ++j) {
			if (j) add(g[j - 1], f[j]); 
			if (j < tot) add(g[j], f[j]);
		}
		memcpy(f, g, sizeof(g)); --tot;
	} printf("%d\n", f[0]);
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

int main(){

int w,h,x,y,r;
cin>>w>>h>>x>>y>>r;
bool flag = true;
if(w < 0){
  w = -w;
  x = -x;
}
if(h < 0){
  h = -h;
  y = -y;
}
if( x - r < 0 || y - r < 0 || x + r > w || y + r > h) flag = false;
if(flag)cout<<"Yes"<<endl;
else cout<<"No"<<endl;

  return 0;
}

Measured memory_bytes: 1160
use std::io::Read;

fn main() {
    let buf = input();
    println!("{}", solve(buf));
}

fn input() -> String {
    let mut buf = String::from("");
    std::io::stdin().read_to_string(&mut buf).unwrap();
    buf
}

fn solve(input: String) -> String {
    let yes = String::from("Yes");
    let no = String::from("No");

    let input = input.chars().collect::<Vec<char>>();

    if input[2] == input[3] && input[4] == input[5] {
        return yes;
    }
    no
}

Measured memory_bytes: 4352
class UnionFind:
    # 初期化
    def __init__(self, n):
        # 根
        self.par = [i for i in range(n)]
        # 木の高さ
        self.rank = [0] * n
        # 自分が根の時の集合のサイズ（根じゃないときは狂う）
        self.size = [1] * n

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        # 異なる集合に属する場合のみ併合
        if x != y:
            if self.rank[x] < self.rank[y]:
                self.par[x] = y
                self.size[y] += self.size[x]
            else:
                self.par[y] = x
                self.size[x] += self.size[y]
                if self.rank[x] == self.rank[y]:
                    self.rank[x] += 1

    # 同集合判定
    def same(self, x, y):
        return self.find(x) == self.find(y)

    # 集合の大きさ
    def sizeof(self, x):
        return self.size[self.find(x)]


n,m = map(int, input().split())

ab = []
for i in range(m):
    a,b = map(int, input().split())
    a-=1
    b-=1
    ab.append([a,b])

u = UnionFind(n)

f = sum(i for i in range(n))
ans = [f]

for i in range(m):
    a = ab[-1-i][0]
    b = ab[-1-i][1]
    if not u.same(a,b):
        ans.append(ans[-1]-u.sizeof(a)*u.sizeof(b))
        u.unite(a, b)
    else:
        ans.append(ans[-1])

for i in range(m):
    print(ans[-2-i])




Measured memory_bytes: 115672
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;
// ceil() 切り上げ, floor() 切り捨て
// next_permutation(all(x))

int		main(void)
{
	int a, b, c;
	cin >> a >> b >> c;
	cout << a * b / 2 << endl;
}



Measured memory_bytes: 256
#!/usr/bin/env python3


def valid(honest, a):
    n = len(honest)
    for i in range(n):
        if honest[i]:
            for idx, is_honest in a[i]:
                if honest[idx] != is_honest:
                    return False
    return True

def count_bit(n):
    ret = 0
    while n > 0:
        if n % 2:
            ret += 1
        n //= 2
    return ret

def solve(n, a):
    ret = 0
    for status in range(1 << n):
        honest = [0] * n
        for j in range(n):
            if (1 << j) & status:
                honest[j] = 1
        if valid(honest, a):
            ret = max(ret, count_bit(status))
    print(ret)
    return ret

def main():
    N = int(input())
    a = [[] for _ in range(N)]
    for i in range(N):
        A = int(input())
        for _ in range(A):
            x, y = map(int, input().split())
            a[i].append((x - 1, y))
    solve(N, a)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <bitset>
#include <tuple>
#include <cmath>
#include <complex>
#include <algorithm>
#include <utility>
#include <regex>
#include <cstdint>
#include <numeric>
#include <functional>
#include <cassert>

using namespace std;
using ll = int64_t;
using ull = uint64_t;

constexpr ll INF = 1e+15;


void solve(istream &cin) {
    ll A, B, Q;
    cin >> A >> B >> Q;
    if(!cin) return;
    vector<ll> X[2];
    for (int i = 0; i < A; ++i) {
        ll t; cin >> t; X[0].push_back(t);
    } // end i
    for (int i = 0; i < B; ++i) {
        ll t; cin >> t; X[1].push_back(t);
    } // end i

    auto nearest = [](const vector<ll>& X, ll val){
        auto it = upper_bound(X.begin(), X.end(), val);
        ll R = it != X.end() ? *it - val : INF;
        auto lit = it - 1;
        ll L = it != X.begin() ? val - *lit : INF;

        if(R < L) return *it;
        else return *lit;
    };

    auto al = [](const vector<ll>& X, ll L, ll R){
        auto ll = lower_bound(X.begin(), X.end(), L);
        auto rr = upper_bound(X.begin(), X.end(), R);
        return ll != rr;
    };

    for (int i = 0; i < Q; ++i) {
        ll x;
        cin >> x;
        ll lst = nearest(X[0], x);
        ll ltp = nearest(X[1], lst);
        ll cd = INF;
        cd = min(cd, abs(lst - x) + abs(ltp - lst));
        cd = min(cd, abs(ltp - x) + abs(lst - ltp));
        if(al(X[1], lst, x)){
            cd = min(cd, abs(lst - x));
        }

        ltp = nearest(X[1], x);
        lst = nearest(X[0], ltp);
        cd = min(cd, abs(lst - x) + abs(ltp - lst));
        cd = min(cd, abs(ltp - x) + abs(ltp - lst));
        if(al(X[0], ltp, x)){
            cd = min(cd, abs(ltp - x));
        }

        cout << cd << endl;

    } // end i

}

int main(int argc, char *argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(16) << scientific;
#ifdef DEBUG
    cerr << "DEBUG MODE" << endl;
    string test_cases = "test.txt";
    auto fs = fstream(test_cases, fstream::in);
    while(fs) {
        solve(fs);
    }
#else
    solve(cin);
#endif
    return 0;
}


Measured memory_bytes: 3060
using System;

namespace ALDS1_1_D {
    class Program {
        static void Main(string[] args) {
            int n = int.Parse(Console.ReadLine());
            int minprice = int.Parse(Console.ReadLine());
            int maxValue = int.MinValue;
            for(int i = 1; i < n; i++) {
                int input = int.Parse(Console.ReadLine());
                maxValue = Math.Max(maxValue, input - minprice);
                minprice = Math.Min(minprice, input);
            }
            Console.WriteLine(maxValue);
        }
    }
}

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

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

int main() {
    int h, w;
    cin >> h >> w;
    string s[50];
    rep(i, h) cin >> s[i];
    
    rep(i, h) {
        rep(ii, w) {
            if (s[i][ii] == '.') {
                int cnt = 0;
                
                rep(iii, 8) {
                    int x = ii + dx[iii];
                    int y = i + dy[iii];
                    
                    if (
                        (x >= 0) && (x < w) &&
                        (y >= 0) && (y < h) &&
                        (s[y][x] == '#')
                    ) {
                        cnt++;
                    }
                }
                
                cout << cnt;
            }
            else {
                cout << s[i][ii];
            }
        }
        
        cout << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const ll INF = 1e16;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

int main() {
    init();
    vl A = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    ll K;
    cin >> K;
    cout << A[K - 1] << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
        int A,B,C;
        cin>>A>>B>>C;
        cout<<A<<' '<<B<<' '<<C*3-A-B<<endl<<4*C-2*A-B<<' '<<C<<' '<<2*A+B-2*C<<endl<<A+B-C<<' '<<C*2-B<<' '<<C*2-A;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<ll, ll>;

vector<P> prime_factor(ll n){
    vector<P> res;
    for(ll i = 2; i * i <= n; ++i){
        if(n % i != 0) continue;
        ll cnt = 0;
        while(n % i == 0){
            n /= i;
            cnt++;
        }
        res.push_back(P(i, cnt));
    }
    if(n != 1) res.push_back(P(n, 1));//nが素数の時
    return res;
}

int main(){
    ll n; cin >> n;
    vector<P> vec = prime_factor(n);
    ll ans = 0;
    for(auto p : vec){
        ll num = p.second;
        for(ll k = 1; ; k++){
            if(num >= k){
                ans++;
                num -= k;
            }else{
                break;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define rep(i,a,b) for (int i=(a); i<=(b); i++)
#define per(i,a,b) for (int i=(a); i>=(b); i--)
using namespace std;
typedef long long LL;

inline int read() {
    int x=0,f=1; char ch=getchar();
    while (!(ch>='0'&&ch<='9')) {if (ch=='-')f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9') {x=x*10+(ch-'0'); ch=getchar();}
    return x*f;
}

const int N = 100005;

int n,k,m1,m2;
int t[N],d[N],a[N],b[N],c[N];
bool used[N];
LL sumb[N],sumc[N],ans = 0;

inline bool cmp(int x,int y) {if (d[x]==d[y]) return t[x]>t[y]; return d[x]>d[y];}

int main() {

	n=read(),k=read(); rep(i,1,n) t[i]=read(),d[i]=read(),a[i]=i;
	sort(a+1,a+n+1,cmp);
	rep(i,1,n) {
		if (used[t[a[i]]]) {
			b[++m1] = a[i];
		} else {
			used[t[a[i]]]=1;
			c[++m2] = a[i];
		}
	}
	rep(i,1,m1) sumb[i]=sumb[i-1]+d[b[i]];
	rep(i,1,m2) sumc[i]=sumc[i-1]+d[c[i]];
	rep(i,1,min(k,m2)) ans=max(ans,sumc[i]+sumb[k-i]+(LL)i*i);
	printf("%lld\n",ans);	

	return 0;
	
}


Measured memory_bytes: 2688
import java.util.*;
class Main{
  public static void main(String args[])
  {
     Scanner in=new Scanner(System.in);
    int k=in.nextInt();
    int flag=0;
    int a=in.nextInt();
    int b=in.nextInt();
    for(int i=a;i<=b;i++)
    {
      if(i%k==0)
      {
          flag=1;
          break;
      }
    }
    if(flag==1)
      System.out.print("OK");
    else
      System.out.print("NG");
    
    
    
    
    
  }
}

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

string fill(string s) {
  while (s.size() < 6) s = "0" + s;
  return s;
}

string create_id(int p, int o) {
  return fill(to_string(p)) + fill(to_string(o));
}

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

  int n, m; cin >> n >> m;
  vector<vector<int>> db(m, vector<int>(3));
  for (int i = 0; i < m; i++) {
    cin >> db[i][0] >> db[i][1];
    db[i][2] = i;
  }
  sort(db.begin(), db.end());
  vector<string> res(m);
  int prev = 0, j;
  for (auto &t : db) {
    (t[0] == prev) ? j++ : j = 1;
    res[t[2]] = create_id(t[0], j); 
    prev = t[0];
  }
  for (string &id : res) {
    cout << id << '\n';
  }
  return 0;
}

Measured memory_bytes: 12544
n, k, q = gets.chomp.split.map(&:to_i)
hs = Hash.new(0)
q.times do |_|
  hs[gets.to_i] += 1
end

(1..n).each do |i|
  puts (k + hs[i] - q > 0)? "Yes" : "No"
end


Measured memory_bytes: 6524
/* Akshat Sharma @akshat98 */
#include <iostream>
#include <bits/stdc++.h>
#define IOS  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define mp   make_pair
#define pb   push_back
#define F    first
#define S    second
#define ll   long long
#define MOD  1000000007
#define MAX  1000000001
#define vi 	 vector<int>
#define vl   vector<ll>
#define vpi  vector<pair<int,int> >
#define vpl  vector<pair<ll,ll> >
#define rep(i,a,b) for(i=a;i<b;i++)
#define reqp(i,a,b) for(i=a;i<=b;i++)
#define ren for(i=0;i<n;i++)
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
typedef pair<int,int>pii;
typedef pair<ll,ll>pll;


int main()
{
	#ifndef ONLINE_JUDGE
	//freopen("input_file.txt", "r", stdin);
	//freopen("output_file.txt", "w", stdout);
	#endif
	int i,j,k,l,n,test_case,m,r;
	test_case=1;
	//cin>>test_case;
	while(test_case--){
		string str;
		cin>>n>>k;
		cin>>str;
		str[k-1]='a'+str[k-1]-'A';
		cout<<str;


	}
	
	return 0;
}

Measured memory_bytes: 256
/// kazuki08
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define ar array
//#define inf 1000000000
#define mod 1000000007
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
    return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
    o<<"{";
    for(const T& v:vc) o<<v<<",";
    o<<"}";
    return o;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());



signed main(){
IOS;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
  
  int n,m;
  cin >> n >> m;
  int ans = 1;
  for(int i=1;i*i<=m;i++){
    if(m%i==0){
      int lef = m/i;
      if(lef>=n){
        ans = max(ans,i);
      }
      if(i>=n){
        ans = max(ans,lef);
      }
    }
  }
  cout << ans << endl;


return 0;
}
///....


Measured memory_bytes: 256
#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;
    ll n,W,V=0;
    cin>>n>>W;
    ll wt[n+5]={0};
    ll val[n+5]={0};
    rep1(i,1,n)
    cin>>wt[i]>>val[i],V+=val[i];
    ll dp[n+5][V+5];
    rep1(i,0,n+1)
      rep1(j,0,V+1)
        dp[i][j]=1e18+5;
    //rep1(i,1,n)
    dp[1][0]=0;
    dp[1][val[1]]=wt[1];
    rep1(i,2,n)
    {
      rep1(v,0,V)
      {
        if(val[i]<=v)
         dp[i][v]=min(wt[i]+dp[i-1][v-val[i]],dp[i-1][v]);
        else
         dp[i][v]=dp[i-1][v];
      }
    }
    ll max_=-inf;
    rep1(i,1,V)
    {
      if(dp[n][i]<=W)
      max_=i;
    }
    cout<<max_;
return 0;
}


Measured memory_bytes: 81280
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int n;
int a[200001];
vector<int> g[200001];
int dp[200001],ans[200001];
const int INF=1000100010;
void dfs(int p,int v){
    ans[v]=lower_bound(dp,dp+n,INF)-dp;
    for(auto it:g[v])if(it!=p){
        int pos=lower_bound(dp,dp+n,a[it])-dp;
        int pre=dp[pos];
        dp[pos]=a[it];
        dfs(v,it);
        dp[pos]=pre;
    }
}
int main(){
    cin>>n;
    rep(i,n) cin>>a[i],dp[i]=INF;
    int ui,vi;
    rep(i,n-1){
        cin>>ui>>vi;
        --ui,--vi;
        g[ui].pb(vi);
        g[vi].pb(ui);
    }
    dp[0]=a[0];
    dfs(-1,0);
    FOR(i,0,n) cout<<ans[i]<<endl;
    return 0;
}

Measured memory_bytes: 31236
from typing import List


class UnionFind:
    """Union Find (Disjoint Set): O(α(N))
    References:
        https://github.com/atcoder/ac-library/blob/master/atcoder/dsu.hpp
        https://tumoiyorozu.github.io/single-file-ac-library/document_en/dsu.html
    """

    __slots__ = ["_data_size", "_roots"]

    def __init__(self, data_size: int) -> None:
        self._data_size = data_size
        self._roots = [-1] * data_size

    def __getitem__(self, x: int) -> int:
        """Find the group (root) of vertex x in O(α(n)) amortized."""
        while self._roots[x] >= 0:
            x = self._roots[x]
        return x

    def __len__(self) -> int:
        """Count the number of groups (roots)."""
        return len(self.groups)

    @property
    def groups(self) -> List[int]:
        """Return the set of groups (roots) in O(n)."""
        return [i for i, r in enumerate(self._roots) if r < 0]

    def is_connected(self, x: int, y: int) -> bool:
        """Return whether two vertices x and y are connected in O(α(n)) amortized."""
        return self[x] == self[y]

    def unite(self, x: int, y: int) -> None:
        """Unite two groups of vertices x and y in O(α(n)) amortized."""
        x, y = self[x], self[y]
        if x == y:
            return
        if self._roots[x] > self._roots[y]:
            x, y = y, x
        self._roots[x] += self._roots[y]
        self._roots[y] = x

    def get_size(self, x: int) -> int:
        """Return the size of the group where vertex x belongs in O(α(n)) amortized."""
        return -self._roots[self[x]]


def unionfind():
    # https://judge.yosupo.jp/problem/unionfind
    # https://atcoder.jp/contests/practice2/tasks/practice2_a
    import sys

    read = sys.stdin.buffer.read

    N, Q, *TUV = map(int, read().split())
    tree = UnionFind(N)
    res = []
    for t, u, v in zip(*[iter(TUV)] * 3):
        if t:
            res.append(int(tree.is_connected(u, v)))
        else:
            tree.unite(u, v)
    print("\n".join(map(str, res)))


def arc032_b():
    # https://atcoder.jp/contests/arc032/tasks/arc032_2
    N, M, *AB = map(int, open(0).read().split())
    tree = UnionFind(N + 1)
    for a, b in zip(*[iter(AB)] * 2):
        tree.unite(a, b)
    print(len(tree) - 2)


if __name__ == "__main__":
    unionfind()
    # arc032_b()


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

int main(){
  int side1, side2, diagonal, rectangle = 0, rhombus = 0;

  while(1){
    if(scanf("%d,%d,%d", &side1, &side2, &diagonal) != EOF){
      if(side1 * side1 + side2 * side2 == diagonal * diagonal){
	rectangle++;
      }
      if(side1 == side2){
	rhombus++;
      }
    }else{
      printf("%d\n%d\n", rectangle, rhombus);
      break;
    }
  }

  return 0;
}

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

int main(){
    int n; cin >> n;
    int count=0;
    rep(i,n){
        int l,r;
        cin >> l >> r;
        count =count+r-l+1;
    }
    cout << count << endl;
}

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

using namespace std;

int main(){
    cin.sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int X, A;
    cin >> X >> A;
    if(X < A){
        cout << 0 << endl;
    }
    else{
        cout << 10<< endl;
    }
}


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

int main(){
  int pos=0;
  int n,m;
  int cnt=0;
  int array[n];
  while(cin>>n>>m){
    if(n==0)break;
    cnt=0;
    pos=0;
    for(int i=0;i<n;i++){
      cin>>array[i];
    }
    for(int i=0;i<m;i++){
      int tmp;
      cin>>tmp;
      if(pos<n){
	pos+=tmp;
	pos+=array[pos];
	cnt++;
      }
    }
    cout<<cnt<<endl;
  }
  return 0;
}

Measured memory_bytes: 1168
#include <iostream> 
using namespace std; 
   
int ans, s, n; 
   
void dfs(int i, int sum, int n){ 
    if((sum == s) && (n == 0)){ 
        ans++; 
        return; 
    } 
    if((i == 10) || (n == 0)) return; 
    dfs(i+1, sum, n); 
    dfs(i+1, sum+i, n-1); 
} 
   
int main(){ 
    while(cin >> n >> s){ 
        ans = 0; 
        if(n == 0 && s == 0) break; 
        dfs(0, 0, n); 
        cout << ans << endl; 
    } 
    return 0; 
}

Measured memory_bytes: 1156