akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int MOD = 1000000007;
//const int MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const double pi = acos(-1.0);
const double EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

template<typename T>
struct Min_Cost_Flow{
    struct edge{
        int to; T cap, cost; int rev;
        edge(int to, T cap, T cost, int rev) : to(to), cap(cap), cost(cost), rev(rev) {} 
    };

    vector<vector<edge>> es;
    vector<T> d;
    vector<int> pre_v, pre_e;
    const T INF_T;
    const int n;

    Min_Cost_Flow(int n) : INF_T(numeric_limits<T>::max()), n(n){
        es.resize(n), d.resize(n), pre_v.resize(n), pre_e.resize(n);
    }

    void add_edge(int from, int to, T cap, T cost){
        es[from].eb(to, cap, cost, sz(es[to]));
        es[to].eb(from, 0, -cost, sz(es[from])-1);
    }

    void bellman_ford(int s){
        fill(all(d), INF_T);
        d[s] = 0;
        while(true){
            bool update = false;
            rep(i, n){
                if(d[i] == INF_T) continue;
                rep(j, sz(es[i])){
                    edge &e = es[i][j];
                    if(e.cap > 0 && chmin(d[e.to], d[i]+e.cost)){
                        pre_v[e.to] = i, pre_e[e.to] = j;
                        update = true;
                    }
                }
            }
            if(!update) break;
        }
    }

    T min_cost_flow(int s, int t, T flow){
        T ret = 0;
        while(flow > 0){
            bellman_ford(s);
            if(d[t] == INF_T) return -1;
            T f = flow;
            for(int now = t; now != s; now = pre_v[now]){
                chmin(f, es[pre_v[now]][pre_e[now]].cap);
            }
            ret += f*d[t], flow -= f;
            for(int now = t; now != s; now = pre_v[now]){
                edge &e = es[pre_v[now]][pre_e[now]];
                e.cap -= f, es[now][e.rev].cap += f;
            }
        }
        return ret;
    }
};

int main(){
    int N, K;
    cin >> N >> K;
    Min_Cost_Flow<ll> G(2*N+2);
    int s = 2*N, t = 2*N+1;
    rep(i, N){
        G.add_edge(s, i, K, 0), G.add_edge(N+i, t, K, 0);
        rep(j, N){
            ll A; cin >> A;
            G.add_edge(i, N+j, 1, -A);
        }
    }
    G.add_edge(s, t, K*N, 0);
    cout << -G.min_cost_flow(s, t, K*N) << endl;
    char ans[N][N];
    rep(i, N){
        for(auto &e: G.es[i]){
            if(e.to == s) continue;
            ans[i][e.to-N] = (e.cap == 0? 'X' : '.');
        }
    }
    rep(i, N){
        rep(j, N) cout << ans[i][j];
        cout << endl;
    }
}

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

int main() {
	int n;
	cin >> n;
	vector<pair<ll, int> > a(n);
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i].first;
		if (i % 2 == 0)
		{
			a[i].second = 0;
		} else {
			a[i].second = 1;
		}
	}
	sort(a.begin(), a.end());

	int ans = 0;
	for (int i = 0; i < n; ++i)
	{
		if (i % 2 != a[i].second)
		{
			ans++;
		}
	}
	cout << ans / 2 << endl;


	return 0;
}

Measured memory_bytes: 1792
'''
Created on 2020/08/31

@author: harurun
'''
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write

  N=int(pin())
  ans=""
  while N:
    N-=1
    ans+=chr(97+N%26)
    N=N//26
  print(ans[::-1])
  return
main()
#解説AC

Measured memory_bytes: 9060
//おまじない
//#include <bits/stdc++.h>
#include <iostream>
#include<iomanip>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<int,int>
#define space ' '
#define pll pair<ll,ll>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

const int maxn = 100000;

//UnionFind
class UnionFind {
public:
  //親の番号を格納する。親だった場合は-(その集合のサイズ)
  vector<int> Parent;

  UnionFind(int N) {
    Parent = vector<int>(N, -1);
  }

  //Aがどのグループに属しているか調べる
  int root(int A) {
    if (Parent[A] < 0) return A;
    return Parent[A] = root(Parent[A]);
  }

  //自分のいるグループの頂点数を調べる
  int size(int A) {
    return -Parent[root(A)];
  }

  //AとBをくっ付ける
  bool connect(int A, int B) {
    
    A = root(A);
    B = root(B);
    if (A == B) {
      
      return false;
    }
    if (size(A) < size(B)) swap(A, B);
    
    Parent[A] += Parent[B];
    Parent[B] = A;

    return true;
  }
};

int main(){
    
    int n,m;
    int x[maxn],y[maxn],z[maxn];
    bool used[maxn+1]={0};
    int ans = 0;
    int cnt = 0;
    
    cin >> n>>m;
    rep(i,m){
        scanf("%d%d%d",&x[i],&y[i],&z[i]);
    }
    
    UnionFind Uni(n+2);
    
    rep(i,m){
        Uni.connect(x[i],y[i]);
    }
    
    rep(i,n){
        if(Uni.size(i+1)==1)ans++;
        else{
            if(used[Uni.root(i+1)]==false){
                ans++;
                used[Uni.root(i+1)]=true;
            }
        }
    }
    
    cout << ans<<endl;
    
    return 0;
}


Measured memory_bytes: 1920
function tobu(arr){
   var max=0;
   for(var i=0;i<arr.length-1;i++){
      if(i>max)break;
      var d = Math.floor(arr[i]/10);
      max=Math.max(max,i+d);
   }
   return (max>=arr.length-1);
}
 
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr= input.trim().split("\n").map(Number);
var n=arr.shift();
if(tobu(arr) && tobu(arr.reverse()))console.log("yes");
else console.log("no");


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

int main()
{
	int n, k;
	cin >> n >> k;
	vector<int> p(n);
	vector<double> e(n);
	for (int i = 0; i < n; i++) {
		cin >> p[i];
		e[i] = (p[i] + 1.0) / 2;
	}
	vector<double> s(n - k + 1);
	for (int i = 0; i < k; i++) {
		s[0] += e[i];
	}
	double max = s[0];
	for (int i = 1; i <= n - k; i++) {
		s[i] = s[i - 1] - e[i - 1] + e[i + k - 1];
		if (max < s[i])
			max = s[i];
	}
	printf("%.9lf\n", max);
	return 0;
}

Measured memory_bytes: 4096
#include<iostream>

using namespace std;

int main(void)
{
	int w,h,n;
	cin >> w >> h >> n;
	int xmn=0,xmx=w,ymn=0,ymx=h;
	
	for(int i=1;i<=n;i++)
	{
		int x,y,a;
		cin >> x >> y >> a;
		if(a==1)	xmn=max(xmn,x);
		else if(a==2)	xmx=min(xmx,x);
		else if(a==3)	ymn=max(ymn,y);	
		else		ymx=min(ymx,y);
	}

	cout << max(0,(xmx-xmn))*max(0,(ymx-ymn)) << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

const u_int64_t R = 1'000'000'007;

u_int64_t simple[8 + 1];
u_int64_t amida[100 + 1][8];

u_int64_t withBar(int bar, int width)
{
    if (bar < 0 || bar >= width - 1)
    {
        return 0;
    }
    u_int64_t lSide = simple[bar];
    u_int64_t rSide = simple[width - (bar + 2)];
    return lSide * rSide % R;
}

int main()
{
    int H, W, K;
    cin >> H >> W >> K;
    K--;

    for (int i = 0; i <= W; i++)
    {
        if (i < 2)
        {
            simple[i] = 1;
            continue;
        }
        simple[i] = (simple[i - 1] + simple[i - 2]) % R;
    }

    for (int i = 0; i <= H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            if (i == 0)
            {
                amida[i][j] = j == 0 ? 1 : 0;
                continue;
            }

            u_int64_t leftP = withBar(j - 1, W);
            u_int64_t rightP = withBar(j, W);
            u_int64_t centerP = ((simple[W] + R - leftP) % R + R - rightP) % R;
            u_int64_t fromLeft = (j - 1 < 0) ? 0 : (leftP * amida[i - 1][j - 1]) % R;
            u_int64_t fromRight = (j + 1 >= W) ? 0 : (rightP * amida[i - 1][j + 1]) % R;
            u_int64_t fromCenter = centerP * amida[i - 1][j] % R;
            amida[i][j] = ((fromLeft + fromRight) % R + fromCenter) % R;
        }
    }

    cout << amida[H][K] << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <tuple>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<ll, ll>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << endl; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

#include <set>

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int h, w;
    cin, h, w;
    set<P> s1, s2;
    REP(i, 0, w) {
        s1.emplace(i, 0);
        s2.emplace(0, i);
    }
    const int inf = 1 << 29;
    vector<int> m(w, 0);
    REP(i, 0, h) {
        int a, b;
        cin, a, b;
        a--;
        b--;
        auto it1 = s1.lower_bound(P(a, -1));
        auto it2 = s1.lower_bound(P(b, inf));
        P maxP(-1, -1);
        while (it1 != it2) {
            chmax(maxP, *it1);
            auto [s, t] = *it1;
            it1 = s1.erase(it1);
            s2.erase(P(t, s));
            m[s] = inf;
        }
        if (maxP.first != -1 && b + 1 < w) {
            auto [s, t] = maxP;
            int cost = t + b + 1 - s;
            if (m[b + 1] > cost) {
                s1.emplace(b + 1, cost);
                s2.emplace(cost, b + 1);
                m[b + 1] = cost;
            }
        }

        if (s2.size() == 0) {
            print(-1);
        } else {
            auto [s, t] = *s2.begin();
            print(s + i + 1);
        }
    }

    return 0;
}


Measured memory_bytes: 29016
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

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

    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        long[] A = new long[N];
        for (int i = 0; i < N; i++) {
            A[i] = scan.nextLong();
        }
        if (A[N-1] != 2) {
            System.out.println(-1);
            return;
        }
        long min = 2;
        long max = 3;
        for (int i = N - 2; 0 <= i; i--) {
            if (max < A[i]) {
                System.out.println(-1);
                return;
            }
            long from = min / A[i];
            if (min % A[i] != 0) {
                from += 1;
            }
            long to = max / A[i];
            long next_min = from * A[i];
            long next_max = to * A[i] + A[i] - 1;
            if (max < next_min) {
                System.out.println(-1);
                return;
            }
            min = next_min;
            max = next_max;
        }
        System.out.printf("%d %d\n", min, max);
    }
}


Measured memory_bytes: 60912
# coding: utf-8

# https://atcoder.jp/contests/abc113
# 12:01-12:49 give up -> kaisetsu
# 11:57-12:25 try again

# from pprint import pprint as ppr


# def main():
#     H, W, K = map(int, input().split())

#     v = "v"
#     h = "h"
#     dp = [[{"v": 0, "h": 0} for _ in range(W)] for _ in range(H)]
#     dp[0][0][v] = 1

#     for i in range(H):

#         for j in range(W):
#             # horizontal computation
#             if j == 0:
#                 dp[i][j+1][h] += dp[i][j][v]
#             elif j == W-1:
#                 dp[i][j-1][h] += dp[i][j][v]
#             else:
#                 dp[i][j+1][h] += dp[i][j][v]
#                 dp[i][j-1][h] += dp[i][j][v]

#         if i < H-1:
#             for j in range(W):
#                 # vertical computation
#                 dp[i+1][j][v] += dp[i][j][v] + dp[i][j][h]
    
#     ppr(dp)

#     return dp[H-1][K-1][v] + dp[H-1][K-1][h]


def main():
    H, W, K = map(int, input().split())

    if W == 1:
        return 1

    dp = [[0]*W for _ in range(H)]
    dp[0][0] = 1

    bridges_list = []

    def preset(i, bridges, n_cand):
        if i == n_cand:
            bridges_list.append(bridges)
            return None

        if i-1 in bridges:
            preset(i+1, bridges, n_cand)
        else:
            bridges_1 = bridges[:]
            bridges_2 = bridges[:]
            bridges_1.append(i)

            preset(i+1, bridges_1, n_cand)
            preset(i+1, bridges_2, n_cand)

    preset(0, [], W-1)

    n_bridges = [0] * (W-1)
    for bridges in bridges_list:
        for x in bridges:
            n_bridges[x] += 1

    n_all_cands = len(bridges_list)

    # ppr(bridges_list)
    # ppr(n_bridges)

    dp[0][0] = (n_all_cands-n_bridges[0])
    dp[0][1] = n_bridges[0]

    for i in range(H-1):
        for j in range(W):
            if j == 0:
                dp[i+1][j] += dp[i][j] * (n_all_cands-n_bridges[j])
                dp[i+1][j+1] += dp[i][j] * n_bridges[j]
            elif j == W-1:
                dp[i+1][j] += dp[i][j] * (n_all_cands-n_bridges[j-1])
                dp[i+1][j-1] += dp[i][j] * n_bridges[j-1]
            else:
                dp[i+1][j] += dp[i][j] * (n_all_cands-n_bridges[j-1]-n_bridges[j])
                dp[i+1][j-1] += dp[i][j] * n_bridges[j-1]
                dp[i+1][j+1] += dp[i][j] * n_bridges[j]
    # ppr(dp)

    return dp[-1][K-1] % (10**9 + 7)


print(main())


Measured memory_bytes: 3188
#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 ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;

int n=10;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int H,W;
  int c[10][10];
  cin >> H >> W;
  REP(i,n)REP(j,n) cin >> c[i][j];
  REP(k, n) REP(i, n) REP(j, n) c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
  
  ll ans = 0;
  REP(i,H) REP(j,W){
    int a;
    cin >> a;
    if(a>-1){
      ans += (ll)c[a][1];
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int N, K, R, S, P;

int get_pnt(char c){
    if(c=='r') return P;
    if(c=='s') return R;
    if(c=='p') return S;
}

int main(void){
    char T[100000];
    int i,j;
    int flg=1;

    long long pnt=0;

    scanf("%d %d", &N, &K);
    scanf("%d %d %d", &R, &S, &P);
    scanf("%s", T);

    for(i=0;i<K;i++){
        if((i+1)>(N%K) || i==K-1){
            flg=1;
            for(j=0;j<N/K;j++){
                if(j==0){
                    pnt+=get_pnt(T[i]);
                    continue;
                }
                if(T[i+j*K]==T[i+(j-1)*K]){
                    if(flg==0){
                        pnt+=get_pnt(T[i+j*K]);
                        flg=1;
                    }else{
                        flg=0;
                    }
                }else{
                    pnt+=get_pnt(T[i+j*K]);
                    flg=1;
                }
            }
        }else if((i+1)<=(N%K)&&i!=K-1){
            flg=1;
            for(j=0;j<N/K+1;j++){
                if(j==0){
                    pnt+=get_pnt(T[i]);
                    continue;
                }
                if(T[i+j*K]==T[i+(j-1)*K]){
                    if(flg==0){
                        pnt+=get_pnt(T[i+j*K]);
                        flg=1;
                    }else{
                        flg=0;
                    }
                }else{
                    pnt+=get_pnt(T[i+j*K]);
                    flg=1;
                }
            }
        }
    }

    printf("%lld", pnt);
    return 0;

}


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

using namespace std;


class UnionFind{
    int N;
    vector<int> par;
    vector<int> rank;
    public:
    UnionFind(int N):N(N),par(N),rank(N,0){iota(par.begin(),par.end(),0);}
    int find(int x);
    void unite(int x,int y);
    bool same(int x,int y){return find(x)==find(y);}
};

int UnionFind::find(int x){
    if(par[x]==x) return x;
    return par[x]=find(par[x]);
}
void UnionFind::unite(int x,int y){
    x=find(x),y=find(y);
    if(x==y) return;
    if(rank[x]>=rank[y]){
        if(rank[x]==rank[y]) rank[x]++;
        par[y]=x;
    }else{
        par[x]=y;
    }
}

using Weight=long long;
struct Edge{
    int from,to;
    Weight weight;
};
bool operator<(const Edge& lhs,const Edge& rhs){
    return lhs.weight<rhs.weight;
}

using Edges=vector<Edge>;
using Graph=vector<Edges>;


Edges MinimumSpanningTree(int n,Edges edges){
    sort(edges.begin(),edges.end());
    Edges res;
    UnionFind u(n);
    for(int i=0;i<edges.size();i++){
        if(!u.same(edges[i].from,edges[i].to)){
            res.push_back(edges[i]);
            u.unite(edges[i].from,edges[i].to);
        }
    }
    return res;
}

Edges MinimumSpanningTree(const Graph& g){
    Edges edges;
    for(int i=0;i<g.size();i++){
        copy(g[i].begin(),g[i].end(),back_inserter(edges));
    }
    auto res=MinimumSpanningTree(g.size(),edges);
    return res;
}

int main(){
    int n;
    cin>>n;
    Graph g(n);
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            Weight c;
            cin>>c;
            if(c==-1) continue;
            g[i].push_back({i,j,c});
        }
    }
    auto mst=MinimumSpanningTree(g);
    cout<<accumulate(mst.begin(),mst.end(),Weight(0),[](const Weight& lhs,const Edge& rhs){return lhs+rhs.weight;})<<endl;
    return 0;
}

Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <algorithm>
#include <cmath>
#include <climits>
#define REP(i, n) for(int i=0; i<(n); i++)
#define FOR(i, a, n) for(int i=(a); i<(n); i++)
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> x(n);
    vector<int> y(n);
    REP(i, n){
        cin >> x[i] >> y[i]; 
    }

    int ans = INT_MAX;
    if(n==1){
        ans = 1;
    }else{
        REP(i, n){
            FOR(j, i+1, n){
                int p = x[i] - x[j];
                int q = y[i] - y[j];
                int cost = n;
                REP(k, n){
                    FOR(l, k+1, n){
                        if(x[k]+p == x[l] && y[k]+q == y[l]) cost--;
                        else if(x[k]-p == x[l] && y[k]-q == y[l]) cost--;
                    }
                }
                ans = ans < cost ? ans : cost;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define int long long int
#define ff first
#define ss second
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define pb push_back
#define MOD 1000000007
#define MAX 200005
#define sz size()
ll power(ll n,ll x)
{
    if(x==0)   return 1;
    if(x%2==0) return power(n*n,x/2);
    else       return n*power(n*n,x/2);
}
bool prime(ll n)
{
    if(n==1) return false;
    for(ll i=2;i*i<=n;i++)
        if(n%i==0) return false;
    return true;
}
ll powermode(ll n,ll x)
{
    if(x==0) return 1;
    ll y=((n%MOD)*(n%MOD))%MOD;
    if(x%2==0)  return powermode(y,x/2)%MOD;
    else    return ((n%MOD)*(powermode(y,x/2)%MOD))%MOD;
}
ll inv(ll a){ return powermode(a,MOD-(ll)2);}
ll mul(ll x,ll y) { return ((x%MOD)*(y%MOD))%MOD; }
ll sum(ll x,ll y) { return ( x%MOD+ y%MOD) %MOD;}
ll sub(ll x,ll y) {  return ((x%MOD)-(y%MOD)+MOD)%MOD;}
ll divide(ll x,ll y) { return mul(x,inv(y));}
ll ans=0;
void d(ll n)
{
	if(n>0)
	{
	ll temp=n;
	ll cnt=0;
	while(temp)
	{
		cnt+=temp%2;
		temp/=2;
	}
	ans++;
	d(n%cnt);
	}
	
}
ll i;
   void solve()
   {
        ll n;
        cin>>n;
        string s;
        cin>>s;
        ll a[n]={0};
        ll b[n]={0};
        ll cnt=0;
        for(i=0;i<n;i++)
        {
        	  if(s[i]=='1')
        	  cnt++;
        }
        ll temp1=1;
        ll temp2=1;
        for(i=0;i<n;i++)
        {
        	 a[i]=temp1%(cnt+1);
         if(cnt-1)	 b[i]=temp2%(cnt-1);
        	 temp1=(temp1*2)%(cnt+1);
         if(cnt-1)	 temp2=(temp2*2)%(cnt-1);
        	 
        }
        ll aa=0,bb=0;
        for(i=0;i<n;i++)
        {
           if(s[i]=='1')
           {
           	   aa=(aa+a[n-i-1])%(cnt+1);
           	   if( cnt>1)
                 bb=(bb+b[n-i-1])%(cnt-1);
           }
        }
       
        for(i=0;i<n;i++)
        {
        	if(s[i]=='1')
        	{
        		ll t=bb;
        		 if(cnt>1)
                   bb=(bb-b[n-i-1]+cnt-1)%(cnt-1);
              else{
                   cout<<0<<endl;
                   continue;
              }
        		ans=1;
        		d(bb);
        		cout<<ans<<endl;
        		bb=t;
        	}else
        	{
        		ll t=aa;
        	    aa=(aa+a[n-i-1])%(cnt+1);
        		ans=1;
        		d(aa);
        		cout<<ans<<endl;
        		aa=t;
        	}
        }
        

   }
            signed main()
            {
               FAST;
               ll q=1;
             //  cin>>q;
	            while(q--)
                {
                   solve();
                }
            }



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

int n, fr[200001], a[200001];

int main(){
    cin >> n;
    for (int i = 2; i <= n; ++i) {
        cin >> a[i];
        fr[a[i]]++;
    }
    for (int i = 1; i <= n; ++i) {
        cout << fr[i] << "\n";
    }
    return 0;
}

Measured memory_bytes: 5156
from sys import stdin, stdout

rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())

INF, NINF = float('inf'), float('-inf')

def submasks(m):
	s = m
	while s > 0:
		s = (s-1)&m
		yield s

def main():
	n, m, x = rli()
	A = []
	for _ in range(n):
		A.append(list(rli()))
	mask = 0
	for i in range(n):
		mask |= (1 << i)

	opt = INF

	def process(s):
		nonlocal opt
		i = 0
		cost = 0
		algs = [0 for _ in range(m)]
		while s:
			s, bit = divmod(s, 2)
			if bit:
				cost += A[i][0]
				for j in range(1, m+1):
					algs[j-1] += A[i][j]
			i += 1
		if all(skill >= x for skill in algs):
			opt = min(opt, cost)

	process(mask)
	for s in submasks(mask):
		process(s)

	print(opt if opt < INF else -1)
	stdout.close()

if __name__ == "__main__":
	main()

Measured memory_bytes: 85488
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }


string str;


int main() {
  while (cin >> str) {
	int res = str.size();
	for (int i = 1; i < str.size(); ++i) {
	  if (str[i] == str[i-1]) continue;
	  chmin(res, max(i, (int)str.size()-i));
	}
	cout << res << endl;
  }
}
















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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

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

    int N, M;
    cin >> N >> M;

    if (M == 0) {
        if (N == 1) {
            cout << 0 << endl;
        }
        else {
            string ans;
            ans += '1';
            for (int i = 0; i < N - 1; i++) {
                ans += '0';
            }
            cout << ans << endl;
        }
        return 0;
    }


    Vi s(M), c(M);
    for (int i = 0; i < M; i++) {
        cin >> s[i] >> c[i];
    }


    Vi vec(N, -1);
    bool dup = false;
    for (int i = 0; i < M; i++) {
        if (vec[s[i] - 1] == -1) {
            vec[s[i] - 1] = c[i];
        }
        else {
            if (vec[s[i] - 1] != c[i]) {
                dup = true;
                break;
            }
        }
    }
    if (dup) {
        cout << -1 << endl;
        return 0;
    }


    if (vec[0] == 0) {
        if (N == 1) {
            cout << 0 << endl;
            return 0;
        }
        else {
            cout << -1 << endl;
            return 0;
        }
    }


    string ans;
    for (int i = 0; i < N; i++) {
        if (i == 0 && vec[i] == -1) {
            ans += '1';
        }
        else {
            if (vec[i] == -1) {
                ans += '0';
            }
            else {
                ans += vec[i] + '0';
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())

l = list()

for a in range(0, N):
    L = list(map(int, input().split()))
    L.pop(0)
    l.append(L)

count = [0]*(M)

for a in l:
    for b in a:
        count[b-1] += 1

print(len(list(filter(lambda x: x == N, count))))


Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;
bool isp(int x){
    for(int i=2;i*i<=x;i++){
	if(x%i==0)return 0;
    }
    return 1;
}
int main(){
    int n;cin>>n;
    int x=11;
    for(int i=0;i<n;i++){
	while(true){
	    if(isp(x)==true){
		if(i)cout<<" ";
		cout<<x;
		x+=10;
		break;
	    }
	    x+=10;
	}
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
import sys
from fractions import gcd
from functools import reduce
def input(): return sys.stdin.readline().rstrip()

sys.setrecursionlimit(10 ** 9)
def main():
    _, X = input().split()
    x = sorted(map(int, input().split() + [X]))
    min_x = x[0]
    x = map(lambda a: a - min_x, x[1:])
    print(reduce(gcd, x))

if __name__ == '__main__':
    main()


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

int main()
{
    int N, M;
    cin >> N >> M;
    vector<vector<int>> s(M);

    rep(i, M) {
        int k;
        cin >> k;
        rep(j, k) {
            int a;
            cin >> a;
            a--;
            s[i].push_back(a);
        }
    }

    vector<int> p(M);
    rep(i, M) {
        cin >> p[i];
    }

    ll res = 0;
    for (int bit = 0; bit < (1 << N); bit++) {
        bool ok = true;
        for (int i = 0; i < M; i++) {
            int con = 0;
            for (auto v : s[i]) {
                if (bit & (1 << v)) ++con;
            }
            if (con % 2 != p[i]) ok = false;
        }
        if (ok) res++;
    }

    cout << res << endl;

    return 0;
}

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

int main()
{
  int N;
  cin >> N;
  vector<tuple<string, int, int>> t;
  rep(i, N)
  {
    string s;
    int p;
    cin >> s >> p;
    t.push_back(make_tuple(s, p * -1, i + 1));
  }
  sort(ALL(t));
  rep(i, N) cout << get<2>(t[i]) << endl;
}

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

typedef long long ll;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod 1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}


int main() {
  int n, m, from, to;
  vector<int> box(100001), boc(100001, 1);
  box[1] = 1;
  cin >> n >> m;

  rep(i, 0, m) {
    cin >> from >> to;
    if(box[from]) box[to] = 1;
    boc[from]--;
    if(boc[from] == 0) box[from] = 0;
    boc[to]++;
  }

  int ans = 0;
  rep(i, 1, n + 1) if(box[i]) ans++;

  cout << ans << endl;
}


Measured memory_bytes: 1024
#include <stdio.h>
#define INF (1<<21)

int main(void)
{
 int i,j,n,m,ans=0,min,a[101][101],b[101],c[101];

 scanf("%d",&n);

 for(i=0;i<n;i++){
  for(j=0;j<n;j++){

   scanf("%d",&a[i][j]);
   if(a[i][j]==-1) a[i][j]=INF;

  }
 }

 for(i=0;i<101;i++){
    b[i]=0;
    c[i]=INF;
 }

 c[0]=0;

 while(1){

  min=INF;
  m=-1;

  for(i=0;i<n;i++){
     if(b[i]) continue;
     if(c[i]<min){
       min=c[i];
       m=i;
     }
  }

  if(m==-1) break;

  b[m]=1;
  ans+=c[m];

  for(i=0;i<n;i++){
   if(b[i]) continue;
   if(a[m][i]<c[i]){
      c[i]=a[m][i];
   }
  }
 }

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

 return 0;
}

Measured memory_bytes: 1760
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#define REP(i,n,N) for(int i=(n);i<(int)N;i++)
#define p(s) cout<<(s)<<endl
#define ck(n,a,b) ((a)<=(n)&&(n)<(b))
#define F first
#define S second
typedef long long ll;
using namespace std;
const int inf=1e9;
int card[100010];
int usa_row[510], usa_col[510], usa_d, usa_u, usa_line;
int neko_row[510], neko_col[510], neko_d, neko_u, neko_line;
int main() {
    int n, u, v, m;

    map<int, pair<int, int> > usa_map, neko_map;
    set<int> usa_s, neko_s;

    cin>>n>>u>>v>>m;
    REP(i, 0, n){
        REP(j, 0, n){
            int usa;
            cin>>usa;
            usa_s.insert(usa);
            usa_map[usa]=(make_pair(i, j));
        }
    }
    REP(i, 0, n){
        REP(j, 0, n){
            int neko;
            cin>>neko;
            neko_s.insert(neko);
            neko_map[neko]=(make_pair(i, j));
        }
    }
    REP(i, 0, m){
        cin>>card[i];
    }

    if(n==1){
      REP(i,0,m){
        if((usa_s.find(card[i]) != usa_s.end() && u <= 1)
            && (neko_s.find(card[i]) != neko_s.end() && v <= 1)){
              cout<<"DRAW"<<endl;
              return 0;
        }else if(usa_s.find(card[i]) != usa_s.end() && u <= 1){
          cout<<"USAGI"<<endl;
          return 0;
        }else if(neko_s.find(card[i]) != neko_s.end() && v <= 1){
          cout<<"NEKO"<<endl;
          return 0;
        }
      }
      cout<<"DRAW"<<endl;
      return 0;
    }

    REP(k, 0, m){
        int num=card[k];
        // usa
        if(usa_s.find(num)!=usa_s.end()) {
            int i=usa_map[num].first;
            int j=usa_map[num].second;

            usa_row[i]++;
            usa_col[j]++;
            if(i==j) usa_d++;
            if(i+j==n-1) usa_u++;

            if(usa_row[i]==n) usa_line++;
            if(usa_col[j]==n) usa_line++;
            if(usa_d==n) {
                usa_line++;
                usa_d=0;
            }
            if(usa_u==n) {
                usa_line++;
                usa_u=0;
            }
        }

        //neko
        if(neko_s.find(num)!=neko_s.end()){
            int i=neko_map[num].first;
            int j=neko_map[num].second;
            neko_row[i]++;
            neko_col[j]++;
            if(i==j) neko_d++;
            if(i+j==n-1) neko_u++;

            if(neko_row[i]==n) neko_line++;
            if(neko_col[j]==n) neko_line++;
            if(neko_d==n) {
                neko_line++;
                neko_d=0;
            }
            if(neko_u==n){
                neko_line++;
                neko_u=0;
            }
        }
        if(usa_line>=u && neko_line>=v){
            cout<<"DRAW"<<endl;
            return 0;
        }
        else if(usa_line>=u){
            cout<<"USAGI"<<endl;
            return 0;
        }
        else if(neko_line>=v){
            cout<<"NEKO"<<endl;
            return 0;
        }
    }
    cout<<"DRAW"<<endl;


    return 0;
}

Measured memory_bytes: 34600
#include <bits/stdc++.h>
using namespace std;
#define EPS (1e-4)
typedef complex<double> P;

int main() {
  int n;
  while (cin >> n, n) {
    vector<P> a(n);
    for (auto &e : a) {
      double x, y;
      cin >> x >> y;
      e.real(x);
      e.imag(y);
    }
    int m = 1;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (i != j && abs(a[j] - a[i]) < 2.0 + EPS) {
          P u = (a[j] - a[i]) / 2.0;
          P v = P(-u.imag(), u.real()) / abs(u) * sqrt(1.0 - pow(abs(u), 2));
          vector<P> o = {a[i] + u + v, a[i] + u - v};
          for (auto e : o) {
            int t = 2;
            for (int k = 0; k < n; k++) {
              if (k != i && k != j) {
                t += abs(a[k] - e) < 1.0 + EPS;
              }
            }
            m = max(m, t);
          }
        }
      }
    }
    cout << m << endl;
  }
}



Measured memory_bytes: 3188
//***Bismillahir Rahmanir Rahim***//

//*********************************//
//******Ashraful Haque Toni********//
//********Dept. of CSE,JnU*********//
//email:ashrafulhaquetoni@gmail.com//
//*******contact:01640690531*******//
//*********************************//


#include<bits/stdc++.h>

using namespace std;

#define         ash ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define         pb push_back
#define         sc(n) scanf("%d",&n);
#define         scl(n) scanf("%I64d",&n);
#define         sc2(m,n) scanf("%d%d",&m,&n);
#define         sc2l(m,n) scanf("%I64d%I64d",&m,&n);
#define         pf printf
#define         Big(x,y) max(x,y);
#define         Small(x,y) min(x,y);
#define         input(array,size) for(int i=0;i<size;i++)cin>>array[i];
#define         newline pf("\n");
#define         f(s,l,in) for(ll i=s;i<l;i+=in)
#define         Max INT_MAX
#define         Min INT_MIN
#define         pi acos(-1.0)
#define         Memset(a,val) memset(a,val,sizeof(a));
#define         mp make_pair

typedef long long ll;

pair<pair<string,int>,int>p[105];

int main()
{
    ash;
    int t;
    cin>>t;
    for(int i=0; i<t; i++)
    {
        string s;
        int val;
        cin>>s>>val;
        p[i]=mp(mp(s,-val),i+1);
    }
    sort(p,p+t);

    for(int i=0; i<t; i++)
        cout<<p[i].second<<"\n";




    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define maxn 200101
using namespace std;
int n,t[maxn],p[maxn],f[maxn];
long long ans;
int main(){
	ios::sync_with_stdio(false);
	cin>>n;
	for (int i=1;i<=n;i++)
	cin>>p[i],t[p[i]]=i;
	int ans=-1;
	for (int i=1;i<=n;i++)
	if (t[i-1]<t[i]) f[i]=f[i-1]+1,ans=max(ans,f[i]);
	else f[i]=1;
	cout<<n-ans<<endl;
	return 0;
}

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

int main()
{
    string s;
    cin >> s;
    int n = s.size();
    int b = 0;
    for(int i = 0; i < n; i++){
        if(s[i] == 'x') b++;
    }
    if(b >= 8) cout << "NO" << endl;
    else cout << "YES" << endl;
}

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

int main() {
 int a;
 cin >> a ;
  if(a % 2 ==0){
  cout << (a/2)*(a/2) << endl;
  }
  else if(a % 2 ==1){
  cout << ((a+1)/2)*((a-1)/2) << endl;
  }
  
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#include <cstdio>


using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){
    if(b==0)return a;
    return gcd(b,a%b);
}



int main(){
    ll a,b,c,d,e,k,l,m,o=0,p,q,r,x,y,z,max1=0,ans=0;
    
    cin>>a>>b;
    c=gcd(a,b);
    ll c1=c;
    for(ll i=2;i*i<=c1;i++){
        
        if(c%i==0){
            o++;  
            while(c%i==0){
               
            c/=i;
         
            }
        }
        
    }
    if(c!=1)o++;
    cout<<o+1<<endl;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
bitset<2000010> f;
int n,sum;
int a[2005];
int main()
{
    scanf("%d",&n);
    for(int i = 1;i <= n;i++){
        scanf("%d",&a[i]);
        sum += a[i];
    }
    f[0] = 1;
    for(int i = n;i >= 1;i--) f |= f << a[i];
    for(int i = (sum+1) >> 1;i <= sum;i++){
        if(f[i]){
            printf("%d\n",i);
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>

using namespace std;
int main() {
    int n;
    cin >> n;
    int res = 0;
    if(n >= 100000) {
        res = 90909;
    } else if(n >= 10000 && n < 100000) {
        res = 909 + n - 10000 + 1;
    } else if(n >= 1000) {
        res = 909;
    } else if(n >= 100 && n < 1000) {
        res = 9 + n - 100 + 1;
    } else if(n >= 1 && n < 10) {
        res = n;
    } else if(n >= 10) {
        res = 9;
    }

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

Measured memory_bytes: 256
#pragma region Header
#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#define IFD(...)
#ifndef NDEBUG
#define NDEBUG
#endif
#endif
#include <utility>
#include <cstdint>
#include <cmath>
#include <cassert>
#include <vector>
#include <array>
#include <deque>
#include <queue>
#include <stack>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <string>
#include <functional>
#include <algorithm>
#include <numeric>
#include <stdexcept>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <boost/hana/functional/fix.hpp>
using boost::hana::fix;
using namespace std;
using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repd(i, n) for (int i = (n)-1; i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define FORD(i, b, a) for (int i = (b); i >= (a); --i)
template <typename T>
int SZ(T const &x)
{
    return static_cast<int>(x.size());
}
template <class T>
bool chmax(T &a, T const &b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, T const &b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}
#pragma endregion

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);

    i64 n;
    cin >> n;
    i64 x, m;
    cin >> x >> m;

    int cyc = 0;
    i64 sum0 = 0;
    i64 sum1 = 0;
    int ini = -1;
    int y1;
    {
        vector<i64> sums(m, -1);
        vector<int> occ(m, -1);
        i64 y = x;
        i64 sum = 0;
        for (int i = 0;; ++i)
        {
            sum += y;

            if (occ[y] >= 0)
            {
                ini = occ[y];
                cyc = i - occ[y];
                sum0 = sums[y];
                sum1 = sum - sums[y];
                y1 = y * y % m;

                break;
            }

            sums[y] = sum;
            occ[y] = i;
            y = y * y % m;
        }
    }
    debug(cyc, sum0, sum1, ini, y1);

    i64 ans = 0;
    if (ini >= n)
    {
        // nが小さいので直接
        i64 y = x;
        rep(i, n)
        {
            ans += y;
            y = y * y % m;
        }
    }
    else
    {
        i64 n2 = n - ini - 1;
        ans += sum0;
        ans += n2 / cyc * sum1;
        n2 %= cyc;

        // y1からn2項
        i64 y = y1;
        rep(i, n2)
        {
            ans += y;
            y = y * y % m;
        }
    }

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 4496
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
#define MOD 1000000007LL
#define endl "\n"

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N;
  cin >> N;
  priority_queue<Pll, vector<Pll>, greater<Pll>> que;
  for(int i = 0; i < N; i++){
    ll X, L;
    cin >> X >> L;
    que.push(Pll(X+L, X-L));
  }
  ll t = -1 * INF;
  ll ans = 0;
  while(!que.empty()){
    ll goal = que.top().first;
    ll start = que.top().second;
    que.pop();
    if(start < t) continue;
    ans++;
    t = goal;
  }
  cout << ans << endl;
}


Measured memory_bytes: 2420
"use strict";
const Main = (input) =>{
   let xs = input.trim().split(' ').map(v=>parseInt(v,10));
   let X = xs[0] * 500;
   if(X >= xs[1]){
     console.log('Yes');
   }else{
     console.log('No');
   }

}
Main(require('fs').readFileSync('/dev/stdin','utf8'));

Measured memory_bytes: 7372
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

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

i = 1
ans = 0
while i * i <= M:
    if M % i == 0 and M // i >= N:
        ans = max(ans, i)
    if M % i == 0 and M // (M // i) >= N:
        ans = max(ans, M // i)

    i += 1

print(ans)


Measured memory_bytes: 3572
A,B,C,D = map(int,input().split())
 
Takahashi = A
Aoki = C
 
while Takahashi >= 0 or Aoki >=0:
  Aoki -= B
  if Aoki <= 0:
    print('Yes')
    break
  Takahashi -= D
  if Takahashi <= 0:
    print('No')
    break

Measured memory_bytes: 9116
X,Y,Z, K  = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

apb =  []

for a in A:
    for b in B:
        apb.append(a+b)
apb.sort(reverse=True)

apb = apb[:K]
ans = []

for k in apb:
    for c in (C):
        ans.append(k+c)
ans.sort(reverse=True)

for k in range(K):
    print(ans[k])

    


Measured memory_bytes: 145776
#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;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define f0(i,a,b) for(int i=a;i<b;i++)
#define f1(i,a,b) for(int i=a;i<=b;i++)
#define f2(i,a,b) for(int i=a;i>b;i--)
#define f3(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define int long long
#define fi first
#define se second
#define ncr(n,r) fact[n]*modInv(fact[r])*modInv(fact[n-r])
#define modInv(a) binExp(a,mod-2)
#define mod 1000000007
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
//#define os_find(k) find_by_order(k)
//#define os_order(k) order_of_key(k)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define make_graph(k) int x,y; f0(i,0,k){cin>>x>>y; adj[x].pb(y); adj[y].pb(x);}
#define test int t;cin>>t;while(t--)

signed main()
{
    fast

    int n,k;
    cin>>n>>k;

    int h[n];
    f0(i,0,n) cin>>h[i];

    int dp[n];
    f0(i,1,n) dp[i] = LLONG_MAX;
    dp[0] = 0;
    f0(i,1,n)
    {
        f3(j,i-1,max(0ll,i-k))
        {
            dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]));
        }
    }
    cout<<dp[n-1];
}

Measured memory_bytes: 5216
#include "bits/stdc++.h"
using namespace std;
using ll = long long; using ull = unsigned long long;
//#define int ll
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<V<T>>;
#define fi first
#define se second
#define maxs(x,y) (x=max(x,y))
#define mins(x,y) (x=min(x,y))
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(ll i = (ll)(b)-1;i >= a;--i)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1), EPS = 1e-10;
const ll MOD = 1e9+7;
void cioacc(){//accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}
int gcd(int a,int b){//ユークリッドの互除法
  if(a==0||b==0){
    return max(a,b);
  }
  while(b){
    a %= b;
    swap(a,b);
  }
  return a;
}
struct segment_tree{
  //dataはこの二分木の本体で、各ノードの値を持っている
  //data[i]に対し、data[(i-1)/2]は親であり、
  //逆にdata[2*i+1],data[2+i+2]は子である。
  vl data;
  //funcはこの木で用いられるモノイドである。
  //モノイドとは単位元を持つ2項演算のこと。
  function<ll(ll,ll)> func;
  //nはdataのサイズ決定に関わる変数
  //nはdataの葉ノードのサイズ
  //但し、二分木の葉の性質から、nは2の冪乗でなければならない。
  //data全体のサイズは2*n+1
  ll n,
  //identitiyはfuncに対する単位元
  identity;
  //下はこのstructのコンストラクタ
  //sizeは計算区間の最大の幅(元の問題の区間)
  //このsizeによりも、この木の葉ノードの数は多い必要がある。
  //idは単位元,fはモノイドである
  segment_tree(ll size,ll id,function<ll(ll,ll)> f):func(f),identity(id){
    //2^n>=sizeとなる最初の2の冪乗nを探す
    //これが葉ノードのサイズである
    n = 1;
    while(n<size) n*=2;
    data.assign(2*n+1,id);
  }
  //update(i,x)でi番目の値をxに更新し、
  //その後、木の根の方まで更新する。
  void update(ll i,ll x){
    data[i+=n-1]=x;//data[i+n-1]がi番目の葉ノード
    while(i>0){
      i = (i-1)/2;//親ノードに移動
      data[i]=func(data[2*i+1],data[2*i+2]);//各子ノードの2項演算でそのノードを更新
    }
  }
  void update2(ll i,ll x){
    i += n-1;
    data[i]=func(data[i],x);//data[i+n-1]がi番目の葉ノード
    while(i>0){
      i = (i-1)/2;//親ノードに移動
      data[i]=func(data[2*i+1],data[2*i+2]);//各子ノードの2項演算でそのノードを更新
    }
  }
  //find(a,b)で区間[a,b)における二項演算の結果を返す
  //根から葉に向かって実行する
  ll find(ll a,ll b,ll k=0,ll l=0,ll r=-1){
    //区間[l,r)は現在見ている値が受け持つ探索範囲
    //data[k]は現在見ている値
    //イメージは[a,b)に完全に収まる、ないし完全に外に出るまで探索区間を分割していく感じ
    if(r<0) r = n;//最初は左端から右端まで
    if(r<=a||b<=l) return identity;//探索範囲[l,r)が区間[a,b)外の時、単位元を返す。
    if(a<=l&&r<=b) return data[k];//探索範囲[l,r)が区間[a,b)内の時、今の値を返す。
    //どちらでもない時、子同士をfuncで演算した結果を返す。
    ll vl = find(a,b,2*k+1,l,(l+r)/2);//左の子ノードに移動
    ll vr = find(a,b,2*k+2,(l+r)/2,r);//右の子ノードに移動
    return func(vl,vr);
  }
};
struct gcd_tree{
  segment_tree gd;
  gcd_tree(ll size):gd(size,0,[](ll a,ll b)->ll{return gcd(a,b);}){}
  void update(ll i,ll x){
    gd.update(i,x);
  }
  ll find(ll a,ll b){
    return gd.find(a,b);
  }
};
signed main(){
  int n;
  cin >> n;
  vi a(n);
  REP(i,n) cin >> a[i];
  gcd_tree gd(n);
  REP(i,n){
    gd.update(i,a[i]);
  }
  int ans = 0;
  REP(i,n){
    ans = max(ans,gcd(gd.find(0,i),gd.find(i+1,n)));
  }
  cout << ans << endl;
}


Measured memory_bytes: 2688
t = list(input())    
for i in range(len(t)):

  if t[i] == '?':
    if len(t) == 1:
      if t[i] == '?':
        t[i] = 'D'
      break
    if i == 0:
      if t[1] == 'P':
        t[i] = 'D'
      else:
        t[i] = 'P'
    if i == len(t)-1:
        t[i] = 'D'
    else:
      if t[i-1] == 'P':
        t[i] = 'D'
      else:
        if t[i+1] == 'P':
          t[i] = 'D'
        else:
          t[i] = 'P'
a = ''
for i in range(len(t)):
  a += t[i]
        
print(a)

Measured memory_bytes: 10936