akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		char[][] board = new char[n + 1][];
		for(int i = 0; i < n + 1; i++) {
			board[i] = sc.next().toCharArray();
		}
		int sum = 0; //print
		for(int i = 1; i <= n; i++) {//?????????????????£????????????
			out: for(int j = 0; j < board[i].length; j++) {//1??????????????¢?´¢
				if(board[i][j] == board[0][0]) {
					for(int k = j + 1; k < board[i].length; k++) {//2??????????????¢?´¢
						if(board[i][k] == board[0][1]) {
							int interval = k - j;//1???????????¨2??????????????????
							int cnt = 2;//?????????????????¢?´¢???????????????
							if(cnt == board[0].length) {
								sum = sum + 1;
							}
							for(int m = k + interval; m < board[i].length; m = m + interval) {//3???????????\????????¢?´¢
								if(board[i][m] == board[0][cnt]) {
									cnt = cnt + 1;
									if(cnt == board[0].length) {
										sum = sum + 1;
										break out;
									}
								} else {
									break;
								}
							}
						}
					}
				}
			}
		}
		System.out.println(sum);
	}

}

Measured memory_bytes: 27476
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
//cout << fixed << setprecision (20);   小数点以下2０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'0'+=16;        で大文字に
//'大文字'+=32;    で小文字に
//s[i]-'0'でchar文字→int数に;
//string s = to_string(int数);
//int n = stoi(string文字列)
//実行時間制約2秒では２×10^8回くらいまで計算できる



int main() {
  ll n,m;
  cin>>n>>m;
  
  set<ll> p;
  rep(i,m){
    int x;
    cin >> x;
    p.insert(x);
  }

  vector<ll> ans(n+1,0);
  ans[0]=1;
  
  repo(i,n+1){
    if(p.count(i))ans[i]=0;
    else {
      if(i>=2) ans[i]=ans[i-2];
      ans[i]=(ans[i]+ans[i-1])%mod;
    }
  }
  
  cout << ans[n] << endl;
  
}

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

int even(vector<int>& array, int);
void division(vector<int>& array, int);

int main() {
	vector<int> array;
	int i, N, tmp, count = 0;
	cin >> N;
	for (i = 0; i < N; i++) {
		cin >> tmp;
		array.push_back(tmp);
	}
	while (even(array, N) == 1) {
		count++;
		division(array, N);
	}
	cout << count << endl;
	return 0;
}

int even(vector<int>& array, int N) {
	int i;
	for (i = 0; i < N; i++) {
		if (array[i] % 2 != 0) {
			return -1;
		}
	}
	return 1;
}

void division(vector<int>& array, int N) {
	int i;
	for (i = 0; i < N; i++) {
		array[i] = array[i] / 2;
	}
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        Integer[] a = new Integer[n];
        Arrays.setAll(a, i -> Integer.parseInt(sc.next()));
        sc.close();

        // 主処理
        int[] color = new int[8];
        int over = 0;
        for (int rate : a) {
            if (rate < 400) {
                color[0] = 1;
            } else if (rate < 800) {
                color[1] = 1;
            } else if (rate < 1200) {
                color[2] = 1;
            } else if (rate < 1600) {
                color[3] = 1;
            } else if (rate < 2000) {
                color[4] = 1;
            } else if (rate < 2400) {
                color[5] = 1;
            } else if (rate < 2800) {
                color[6] = 1;
            } else if (rate < 3200) {
                color[7] = 1;
            } else {
                over++;
            }
        }
        int sum = Arrays.stream(color).sum();
        int min = Math.max(1, sum);
        int max = sum + over;
        String result = min + " " + max;

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 27728
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

struct UF{
    vector<int> par, sz;
    UF(){}
    UF(int n):par(n), sz(n, 1){
        iota(par.begin(), par.end(), 0);
    }
    int find(int x){
        if(x == par[x]) return x;
        return par[x] = find(par[x]);
    }
    void unite(int x, int y){
        x = find(x); y = find(y);
        if(x == y) return;
        if(sz[x] < sz[y]) swap(x, y);
        sz[x] += sz[y];
        par[y] = x;
    }
    bool same(int x, int y){
        return find(x) == find(y);
    }
};

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    UF uf(n);
    rep(i, 0, m){
        int x, y, z;
        cin >> x >> y >> z;
        x--; y--;
        uf.unite(x, y);
    }
    int ans = 0;
    rep(i, 0, n){
        if(uf.find(i) == i) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
typedef long long ll;
typedef double dd;
#define For(i,j,k) for (int i=(int)j;i<=(int)k;++i)
#define Forr(i,j,k) for (int i=(int)j;i>=(int)k;--i)
#define Set(a,p) memset(a,p,sizeof(a))
using namespace std;

template<typename T>bool chkmax(T &a,T b) { return a<b?a=b,1:0; }
template<typename T>bool chkmin(T &a,T b) { return a>b?a=b,1:0; }

const int maxn=4000+10;
const int N=4000;
const int modd=998244353;
int n,k;
int p[maxn],Ans[maxn],c[maxn][maxn];

inline void file() {
	freopen("ARC102E.in","r",stdin);
	freopen("ARC102E.out","w",stdout);
}

inline void init() {
	p[0]=1;
	For (i,1,N) p[i]=2ll*p[i-1]%modd;
	c[0][0]=1;
	For (i,1,N) {
		c[i][0]=1;
		For (j,1,N)
			c[i][j]=(1ll*c[i-1][j]+c[i-1][j-1])%modd;
	}
}

inline int calc(int n,int m) { return c[n+m-1][m-1]; }

inline void Add(int &a,int b) {
	a+=b;
	a=(a>=modd?a-modd:a);
	a=(a<0?a+modd:a);
}

inline int solve1(int w) {
	int ans=0,len=w/2;
	For (i,0,len) {
		Add(ans,1ll*c[len][i]*p[i]%modd*calc(n-i,k-2*len+i)%modd);
	}
	return ans;
}

inline int solve2(int w) {
	int ans=0,len=w/2;
	For (i,0,len) {
		if (i<len) Add(ans,1ll*c[len-1][i]*p[i]%modd*calc(n-i,k-2*len+i+1)%modd);
		if (i) Add(ans,1ll*c[len-1][i-1]*p[i-1]%modd*calc(n-i,k-2*len+i)%modd);
	}
	return ans;
}

int main() {
//	file();
	init();
	scanf("%d%d",&k,&n);
	For (i,2,k+1) {
		if (i&1) Ans[i]=solve1(i);
		else Ans[i]=solve2(i);
		printf("%d\n",Ans[i]);
	}
	Forr (i,k,2) printf("%d\n",Ans[i]);
	return 0;
}

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


int main(){
  int n,i;
  long long t=0;
  cin>>n;
  vector<int> a(n),b(n),c(n);
  for(i=0;i<n;i++) cin>>a[i];
  for(i=0;i<n;i++) cin>>b[i];
  for(i=0;i<n;i++) cin>>c[i];
  sort(a.begin(),a.end());
  sort(c.begin(),c.end());
  for(i=0;i<n;i++){
    long long c1=lower_bound(a.begin(),a.end(),b[i])-a.begin();
    long long c2=c.end()-upper_bound(c.begin(),c.end(),b[i]);
    t+=c1*c2;
  }
  cout<<t<<endl;
}


Measured memory_bytes: 1408
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int read() {
    int x = 0, f = 1;
    char c = getchar();
    while (c < '0' || c > '9') {
        if (c == '-') f = -1;
        c = getchar();
    }
    while (c >= '0' || c <= '9') {
        x = x * 10 + c - '0';
        c = getchar();
    }
    return x * f;
}
char s[200005];
int a[200005], cnt;
int id[200005];
int main() {
    scanf("%s", s + 1);
    int n = strlen(s + 1);
    if (s[n] != '0' || s[1] == '0') {
        puts("-1");
        return 0;
    }
    for (int i = 1; i < n; ++i) {
        if (s[i] != s[n - i]) {
            puts("-1");
            return 0;
        }
        if (s[i] == '1') a[++cnt] = i;
    }
    int sz = 0;
    for (int i = 1; i <= cnt; ++i) {
        int tlj = a[i] - a[i - 1] - 1;
        id[i] = ++sz;
        if (i != 1) printf("%d %d\n", id[i], id[i - 1]);
        for (int j = 1; j <= tlj; ++j) {
            sz++;
            printf("%d %d\n", id[i], sz);
        }
    }
    sz++;
    printf("%d %d\n", id[cnt], sz);
    return 0;
}

Measured memory_bytes: 2304
#pragma region include
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <cstdio>
#include <tuple>
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#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,n,m) for(int i = (n); i < (m); i++)
#define MOD 1000000007
#define INF 1000000000
#define LLINF 4000000000000000000
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#pragma endregion

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    int H, W; cin >> H >> W;
    vector<vector<char>> g(H, vector<char>(W));
    vector<vector<int>> R(H, vector<int>(W)), L(H, vector<int>(W)), U(H, vector<int>(W)),D(H, vector<int>(W));
    // 入力
    REP(i, H) {
        REP(j, W) {
            cin >> g[i][j];
        }
    }
    // 右方向
    REP(i, H) {
        REPR(j, W - 1) {
            if (g[i][j] == '#') {
                R[i][j] = 0;
            }
            else {
                if (j == W - 1) {
                    R[i][j] = 1;
                }
                else {
                    R[i][j] = R[i][j + 1] + 1;
                }
            }
        }
    }
    // 左方向
    REP(i, H) {
        REP(j, W) {
            if (g[i][j] == '#') {
                L[i][j] = 0;
            }
            else {
                if (j == 0) {
                    L[i][j] = 1;
                }
                else {
                    L[i][j] = L[i][j - 1] + 1;
                }
            }
        }
    }
    // 下方向
    REP(i, W) {
        REPR(j, H - 1) {
            if (g[j][i] == '#') {
                D[j][i] = 0;
            }
            else {
                if (j == H - 1) {
                    D[j][i] = 1;
                }
                else {
                    D[j][i] = D[j+1][i] + 1;
                }
            }
        }
    }
    // 上方向
    REP(i, W) {
        REP(j, H) {
            if (g[j][i] == '#') {
                U[j][i] = 0;
            }
            else {
                if (j == 0) {
                    U[j][i] = 1;
                }
                else {
                    U[j][i] = U[j-1][i] + 1;
                }
            }
        }
    }
    int ans = 0;
    REP(i, H) {
        REP(j, W) {
            ans = max(ans, R[i][j] + L[i][j] + U[i][j] + D[i][j] - 3);
        }
    }
    cout << ans << endl;
    getchar(); getchar();
}

Measured memory_bytes: 67072
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < int, int >
#define F first
#define S second
#define int  long long int
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
using namespace std;
const int N=310;
ll mod;
ll ent[N][N];
ll dp[N][N];
ll par[N][N];
int32_t main(){
    sync;
    ll n,k;
    cin >> n >> k >> mod;
    for (int i=0;i<N;i++){
        ent[0][i]=1;
      //  ent[i][i]=1;
    }
    for (int i=1;i<N;i++){
        for (int j=1;j<N;j++){
            ent[i][j]=ent[i-1][j-1]+ent[i][j-1];
            ent[i][j]%=mod;
        }
    }
    for (int i=0;i<=k;i++){
        dp[1][i]=1;
        par[1][i]=i+1;
        par[1][i]%=mod;
    }
    for (int i=2;i<N;i++){
        for (int j=0;j<=k;j++){
            /// dp[i][j]
            for (int t=1;t<i;t++){
                dp[i][j]+=(par[t][k]-par[t][j]+mod)*dp[i-t][j]%mod*ent[t-1][i-2]%mod;
                dp[i][j]%=mod;
                /*
                for (int l=j+1;l<=k;l++){
                    dp[i][j]+=dp[t][l]*dp[i-t][j]%mod*ent[t-1][i-2]%mod;
                    dp[i][j]%=mod;
                }
                */
            }

        }
        par[i][0]=dp[i][0];
        for (int j=1;j<=k;j++){
            par[i][j]=par[i][j-1]+dp[i][j];
            par[i][j]%=mod;
        }
    }
    cout << dp[n+1][0];
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
 
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); 
 
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define in insert
#define ld long double
 
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}
 
typedef long long int ll;
 
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod =1e9+7;
const ll maxn =100001;
ll power(ll x, ll n) {
    ll res = 1;
    for (; n > 0; n >>= 1) {
    if (n & 1) res = (res * x) % mod;
    x = (x * x) % mod;
    }
    return res;
}

int main()
{
   
  IOS
  char c;
  cin>>c;
  char d=c+1;
  cout<<d<<endl;
  
}

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define per(i, a, b) for(int i = (b)-1; i >= (a); --i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pii> vii;

int n;
const int N = 112345;
vvi g(N);
ll mod;
vector<ll> dp(N);
vector<ll> ans(N), pans(N), sans(N);

void dfs(int u=1, int p=1) {
  dp[u] = 1;

  for (auto v: g[u]) if (v != p) {
    dfs(v, u);
  }

  for (auto v: g[u]) if (v != p) {
    dp[u] *= dp[v]+1;
    dp[u] %= mod;
  }
}

void dfs2(int u=1, int p=1) {
  ans[u] = 1;
  if (u != p) ans[u] = (1+pans[u]*sans[u])%mod;

  ll ways = ans[u];
  for (auto v: g[u]) if (v != p) {
    pans[v] = ways;
    ways *= dp[v]+1;
    ways %= mod;
  }
  reverse(all(g[u]));

  ways = 1;
  for (auto v: g[u]) if (v != p) {
    sans[v] = ways;
    ways *= dp[v]+1;
    ways %= mod;
  }
  reverse(all(g[u]));

  ans[u] *= dp[u];
  ans[u] %= mod;

  for (auto v: g[u]) if (v != p) {
    dfs2(v, u);
  }
}

int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);

  cin >> n >> mod;

  rep(i,0,n-1) {
    int u, v;
    cin >> u >> v;
    g[u].pb(v);
    g[v].pb(u);
  }

  dfs();
  dfs2();
  for (int i = 1; i <= n; ++i) cout << ans[i]%mod << '\n';
}

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

#define pb push_back
#define ppp pop_back
#define pii pair<int,int>
#define fi first
#define se second

const int N = 3005;

pair<int, pii> dp[N][N];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif
    string s, t;
    cin >> s >> t;
    int n = s.length();
    int m = t.length();
    s = '$' + s;
    t = '$' + t;
    for (int i=1; i<=n; i++) {
        for (int j=1; j<=m; j++) {
            if (s[i] == t[j]) {
                dp[i][j].fi = dp[i-1][j-1].fi + 1;
                dp[i][j].se = {i-1, j-1};
            }
            else if (dp[i-1][j].fi >= dp[i][j-1].fi) {
                dp[i][j] = {dp[i-1][j].fi, {i-1, j}};
            }
            else {
                dp[i][j] = {dp[i][j-1].fi, {i, j-1}};
            }
        }
    }
    string ans;
    pii cell = {n, m};
    while (cell.fi != 0 && cell.se != 0) {
        pii prev_cell = dp[cell.fi][cell.se].se;
        if (cell.fi > prev_cell.fi && cell.se > prev_cell.se) ans += s[cell.fi];
        cell = prev_cell;
    }
    reverse(ans.begin(), ans.end());
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 105984
"""
https://atcoder.jp/contests/abc136/tasks/abc136_c
"""

import numpy as np


def calc(N: int, values: np.ndarray) -> bool:
    # 要素が1つなら確定でOK
    if len(values) == 1:
        return True

    # 2つ以上下がっている部分があるとNG
    gradient = np.diff(values)
    if np.min(gradient) <= -2:
        return False

    # 要素が2つでならこの時点でOK確定
    if len(values) == 2:
        return True

    # 1つ下がってから、上がる前に、1つ下がるとNG
    gradient_without_zero = gradient[gradient != 0]
    if len(gradient_without_zero) == 0:
        return True
    gradient_without_last = gradient_without_zero[:-1]
    gradient_without_first = gradient_without_zero[1:]
    if np.min(gradient_without_first + gradient_without_last) <= -2:
        return False
    return True


def load_input_as_int_array() -> np.ndarray:
    return np.array([int(v) for v in input().split(" ")])


def main() -> None:
    N, = load_input_as_int_array()
    values = load_input_as_int_array()
    result = calc(N, values)
    print("Yes" if result else "No")


main()


Measured memory_bytes: 23092
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

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

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

signed main() {
	int N, Y;
	cin >> N >> Y;

	rep(a, N + 1) rep(b, N + 1) {
		int c = N - a - b;
		if (c < 0) continue;
		int leftY = Y - 1000 * a - 5000 * b;
		if (leftY == 10000 * c) {
			cout << c << " " << b << " " << a << endl;
			return 0;
		}
	}

	cout << "-1 -1 -1" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int N,K;
set<int>st;
int main(){
    cin>>N>>K;
    for(int i=0;i<10;i++)st.insert(i);
    while(K--){
        int x;
        cin>>x;
        st.erase(x);
    }
    for(int i=N;i<1e5;i++){
        int tmp=i;
        bool b=true;
        while(tmp){
            if(st.find(tmp%10)==st.end()){
                b=false;
                break;
            }
            tmp/=10;
        }
        if(b){
            printf("%d\n",i);
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
import sys  
input = sys.stdin.readline

N = int(input())
SP = []
for i in range(N):
    s, p = list(map(str, input().split()))
    SP.append([i+1, s, int(p)])

SP = sorted(SP, reverse = True, key=lambda x:x[2])
SP = sorted(SP, key=lambda x:x[1])

for a, b, c in SP:
    print(a)




Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define MAXN 2005
#define rint register int
inline int read(){int r;int s=0,c;for(;!isdigit(c=getchar());s=c);for(r=c^48;isdigit(c=getchar());(r*=10)+=c^48);return s^45?r:-r;}
int n, K, Q, A[2005], o[2005]; int c[2005], l[2005], r[2005], Min, Max, Ans = 2e9; inline bool cmp (int i, int j){return A[i]<A[j];}
inline void Add(int i, int v){for(; i <= n; c[i] += v, i += i&-i);} inline int Sum(int i){int r=0; for(; i; r += c[i], i -= i&-i); return r;}
int Work(int k)
{
	Max = Min = k; for(rint i = 1; i <= n; l[i] = A[i-1]>=k?l[i-1]:i, i++); for(rint i = n; i; r[i] = A[i+1]>=k?r[i+1]:i, i--); memset(c+1,0,n<<2);
	for(rint i = 1, q = Q; q--;){for(; i <= n && (A[o[i]]<k||r[o[i]]-l[o[i]]+1-(Sum(r[o[i]])-Sum(l[o[i]]-1))<K); i++);
	if(i>n) return 2e9; Max = max(Max,A[o[i]]), Add(o[i],1), i++;} return Max-Min;
}
int main()
{
	n = read(), K = read(), Q = read(); generate(A+1,A+n+1,read); for(rint i = 1; i <= n; o[i] = i, i++);
	sort(o+1,o+n+1,cmp); for(rint i = 1; i <= n; Ans = min(Ans,Work(A[i])), i++); cout << Ans << endl;


	return 0;
}

Measured memory_bytes: 384
#include <iostream>

using namespace std;

int64_t Gcd(const int64_t a, const int64_t b) {
  if (b == 0) return a;

  return Gcd(b, a % b);
}

int main(void) {
  int64_t K;
  cin >> K;

  int64_t ans = 0;
  for (int64_t a = 1; a <= K; ++a) {
    for (int64_t b = 1; b <= K; ++b) {
      for (int64_t c = 1; c <= K; ++c) {
        ans += Gcd(Gcd(a, b), c);
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3136
#include <iostream>
#include <vector>
#include <cstdio>

using namespace std;

int main(){
    int N, M;
    while(cin >> N >> M){
        vector<vector<int>> g(N);
        for (int i = 0; i < M;i++){
            int s, t;
            cin >> s >> t;
            g[s-1].push_back(t-1);
        }
        double res = 1e10;
        for (int i = N - 2; i >= 0;i--){
            vector<double> dp(N, 1e10);
            dp[N - 1] = 0.0;
            for (int j = N - 2; j >= 0;j--){
                double sum = 0.0;
                double mx = 0.0;
                for (auto t : g[j]){
                    sum += dp[t];
                    mx = max(mx, dp[t]);
                }
                dp[j] = 1.0 + sum / g[j].size();
                if(i == j && g[j].size() >= 2){
                    dp[j] = min(dp[j], 1.0 + (sum - mx) / (g[j].size() - 1));
                }
            }
            res = min(res, dp[0]);
        }
        printf("%.8lf\n", res);
    }
}

Measured memory_bytes: 1408
import java.util.*;

class Main
{
    public static void main(String[] args)
    {
        Scanner input = new Scanner(System.in);
        int x = input.nextInt();
        int y = input.nextInt();
        for(int i=0; i<=x; i++){
            int j=x-i;
            if(2*i+4*j==y){
                System.out.print("Yes");
              	return;
            }
        }
        System.out.print("No");
    }
}

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

using ll = long long;
const ll MOD = 1e9 + 7;

int main() {
    string S, ans = "NO\n";
    cin >> S;
    int n = S.size();
    rep(i, 7) {
        if (S.substr(0, i + 1) + S.substr(n - 6 + i, 6 - i) == "keyence") ans = "YES\n";
    }
    cout << ans;
}

Measured memory_bytes: 256
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long int;
using ULL = unsigned long long;

int main() {
    string s;
    cin >> s;

    LL ans = 0;
    LL n = s.length();

    for (int i = 1; i < n; i++) {
        if (s[i] == s[i - 1]) {
            ans++;
            if (s[i] == '0') s[i] = '1';
            else s[i] = '0';
        }
    }

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


Measured memory_bytes: 512
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
#define INFTY 2000000001
#define MAX 1001

char str[150][2][MAX];
int n = 0;
int c[MAX][MAX];

void lcs(int i) {
  int len0 = strlen(str[i][0]);
  int len1 = strlen(str[i][1]);
  for (int j = 0; j < len0; j++) c[j][0] = 0;
  for (int j = 0; j < len1; j++) c[0][j] = 0;
  for (int m = 0; m < len0; m++) {
    for (int n = 0; n < len1; n++) {
      if (str[i][0][m] == str[i][1][n]) {
        c[m+1][n+1] = c[m][n] + 1;
      } else if (c[m+1][n] >= c[m][n+1]) {
        c[m+1][n+1] = c[m+1][n];
      } else {
        c[m+1][n+1] = c[m][n+1];
      }
    }
  }
}

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

  for (int i = 0; i < n; i++) {
    lcs(i);
    printf("%d\n", c[strlen(str[i][0])][strlen(str[i][1])]);
  }

  return 0;
}



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

using namespace std;
typedef long long ll;

int main(){
   int K, X; cin >> K >> X;
    
    for(int i = X-K+ 1; i < X+K ; i++){
        cout << i;
        if(i==K+X-1) cout << endl;
        cout << " ";
    }
}
            

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String args[]){
		  Scanner s = new Scanner(System.in);
		  int[] WHxyr = {
				  s.nextInt(),
				  s.nextInt(),
				  s.nextInt(),
				  s.nextInt(),
				  s.nextInt()};

		  if(WHxyr[2] + WHxyr[4] <= WHxyr[0] 
				  && WHxyr[3] + WHxyr[4] <= WHxyr[1] 
				  && WHxyr[2] - WHxyr[4]  >= 0 
				  && WHxyr[3] - WHxyr[4]  >= 0 )
			  System.out.println("Yes");
		  else
			  System.out.println("No");
	}
}



Measured memory_bytes: 26308
def main():
    hats = int(input())
    number = list(map(int, input().split()))
    count = {}
    for n in number:
        if n in count:
            count[n] += 1
        else:
            count[n] = 1
    answer = False
    key = list(count.keys())
    val = list(count.values())
    if len(key) == 1 and key == [0]:
        answer = True
    elif len(key) == 2 and hats % 3 == 0:
        if (key[1] == 0 and val[0] == 2 * hats // 3 and val[1] == hats // 3) or \
                (key[0] == 0 and val[1] == 2 * hats // 3 and val[0] == hats // 3):
            answer = True
    elif len(key) == 3 and hats % 3 == 0:
        if key[0] ^ key[1] ^ key[2] == 0 and val[1] == val[2] == val[0] == hats // 3:
            answer = True
    print("Yes" if answer else "No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 14120
import java.util.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String[] as = br.readLine().split(" ");
        int max = -1;
        int min = 1000000005;
        for (int i = 0; i < n; i++) {
            int a = Integer.parseInt(as[i]);
            if (max < a) max = a;
            if (min > a) min = a;
        }
        System.out.println(max-min);
    }
}


Measured memory_bytes: 21332
n,m=map(int,input().split())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

lst=make_divisors(m)

for i in lst:
    if i>=n:
        print(m//i)
        exit()

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

int main(void){
	string str;
	cin>>str;
	int n = str.length();
	int flag = 0;
	if(str[0]!='A'){
		flag = 1;
	}
	int count = 0;
	for(int i=2; i<n-1; i++){
		if(str[i]=='C'){
			count++;
		}
	}
	if(count!=1){
		flag = 1;
	}
	int count1 = 0;
	for(int i=1; i<n; i++){
		if(str[i]>='A' && str[i]<='Z'){
			count1++;
		}
	}
	if(count1>1){
		flag = 1;
	}
	if(flag==1){
		cout<<"WA";
	}else{
		cout<<"AC";
	}
}

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

using namespace std;

string keyence = "keyence";

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string S;
  cin >> S;
  int c = 0;
  for (int i = 0; i < keyence.size(); i++) {
    if (keyence[i] == S[i])
      c++;
    else
      break;
  }

  reverse(keyence.begin(), keyence.end());
  reverse(S.begin(), S.end());

  for (int i = 0; i < keyence.size(); i++) {
    if (keyence[i] == S[i])
      c++;
    else
      break;
  }

  if (c >= keyence.size())
    cout << "YES" << '\n';
  else
    cout << "NO" << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>
#include <complex>
#include <bitset>
#include <atcoder/all>

using namespace std;
using namespace atcoder;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()

template <class T> void chmin(T& a, T b) { a = min(a, b);}
template <class T> void chmax(T& a, T b) { a = max(a, b);}

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

void solve() {
    string s;
    cin >> s;
    ll n = s.size();
    vector<int> sa = suffix_array(s);
    vector<int> la = lcp_array(s, sa);
    ll ans = (n + 1) * n / 2;
    rep(i, n-1) ans -= la[i];
    cout << ans << endl;
    return;
}

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

Measured memory_bytes: 15524
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> P3;
typedef pair<P ,P> PP;
const ll MOD = ll(1e9)+7;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
const double EPS = 1e-6;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

int main() {
    int n, k, v[200], ans = 0;
    cin >> n >> k;
    REP(i,n){
        cin >> v[i];
        v[i+n] = v[i];
    }
    vector<int> ls;
    for(int l=1; l<=min(k,n); l++){
        for(int i=-l+1; i<=0; i++){
            ls.clear();
            int sum = 0;
            for(int j=0;j<l;j++){
                ls.push_back(v[i+n+j]);
                sum += v[i+n+j];
            }
            SORT(ls);
            for(int j=0;j<k-l;j++){
                if(ls[j] < 0) sum -= ls[j];
            }
            ans = max(ans, sum);
            //cout << l << " " << i << " " << sum << endl;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
#define ll long long
#define cpp boost::multiprecision::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;
const double PI = 3.1415926535897932384626433832795;
struct edge {
	int to;
	ll cost;
};
void reverse(string* s) {
	reverse((*s).begin(), (*s).end());
}
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
void COME_LET_THE_GAMES_BEGIN() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << setprecision(20);
}
int main() {
	COME_LET_THE_GAMES_BEGIN();
	int N, H;
	cin >> N >> H;
	vector<int> a(N), b(N);
	rep(i, N) {
		cin >> a[i] >> b[i];
		a[i] = -a[i];
		b[i] = -b[i];
	}
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	int ans = 0;
	rep(i, N) {
		if (b[i]<a[0]) {
			H += b[i];
			ans++;
			if (H <= 0) {
				cout << ans << endl;
				return 0;
			}
		}
		else {
			break;
		}
	}
	while (1) {
		H += a[0];
		ans++;
		if (H <= 0) {
			cout << ans << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vl;
typedef vector<int> vi;
#define pb push_back
#define en "\n"
#define forn(i,e) for(ll i=0; i<e; i++)
#define forsn(i,s,e) for(ll i=s; i<e; i++)
#define rforn(i,e) for(ll i=e; i>=0; i--)
#define rforsn(i,s,e) for(ll i=e; i>=s; i--)
#define asort(arr,n) sort(arr,arr+n)
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(),greater<int>())
#define ff first
#define ss second
#define aout(a) for (auto u:a) {cout<<u<<" ";}cout<<en;

 
#define out(x1) cout << x1 << en
#define out2(x1,x2) cout << x1 << " " << x2 << en
#define out3(x1,x2,x3) cout << x1 << " " << x2 << " " << x3 << en

 
#define in(x1) cin >> x1
#define in2(x1,x2) cin >> x1 >> x2
#define in3(x1,x2,x3) cin >> x1 >> x2 >> x3
 
#define arrin(a,n) forn(i,n) cin >> a[i];
#define arrout(a,n) forn(i,n) {cout << a[i] << " ";} cout << en;
 

int main(){
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

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


ll n,k;
in2(n,k);
ll arr[n];
arrin(arr,n);
ll dp[n];
dp[0]=0;
for (ll i = 1; i < n; i++)
{
    ll maxa=INT_MAX;
    for (ll j = 1; j <= k; j++)
    {if (i-j<0){break;
        
    }
    maxa=min(dp[i-j]+abs(arr[i]-arr[i-j]),maxa);
    }
    dp[i]=maxa;
}
out(dp[n-1]);

    return 0;
}


Measured memory_bytes: 5152
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.*;
import java.util.regex.*;
import java.util.stream.*;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;
 
public class Main
{
    public static void main(String[] args)
    {
        Scanner in=new Scanner(System.in);
        int n=in.nextInt();
        int k=in.nextInt();
        int[] P=new int[n+1];
        long[] C=new long[n+1];
        for(int i=1;i<=n;i++)
            P[i]=in.nextInt();
        for(int i=1;i<=n;i++)
            C[i]=in.nextLong();
        long max_ans=Long.MIN_VALUE;
        for(int i=1;i<=n;i++)
        {
            int j=P[i];
            long score=C[j];
            long ans=score;
            int steps=1;
            long[] prefix=new long[n+1];
            prefix[steps]=score;
            while(j!=i)
            {
                j=P[j];
                steps++;
                score+=C[j];
                prefix[steps]=Math.max(prefix[steps-1],score);
                ans=Math.max(ans,score);
            }
            if(steps<k)
            {
                if(score>0)
                {
                    int y=k/steps;
                    long tmp=score*y;
                    long tmp1=score*(y-1);
                    int mod=(k%steps);
                    ans=Math.max(tmp1+ans,tmp+prefix[mod]);
                }
            }
            else
            {
                ans=prefix[k];
            }
            max_ans=Math.max(max_ans, ans);
        }
        System.out.println(max_ans);
    }
}


Measured memory_bytes: 57312
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int lim = 1e8+8;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	string s;
	cin>>s;
	int month = stoi(s.substr(5,2));
	if(month<=4)
		cout<<"Heisei";
	else
		cout<<"TBD";
	
    return 0;
}

Measured memory_bytes: 256
num = gets.to_i
ary = gets.split.map(&:to_i)
 
(num-1).times{ |j| print "#{ary[j]} "}
print "#{ary[-1]}\n"
 
for i in 1..num-1
 
  compared = i - 1
 
  while compared >= 0 && ary[compared] > ary[i]
 
    ary[compared], ary[i] = ary[i], ary[compared]
    i -= 1
    compared -= 1
  end
 
  puts ary.join(" ")
end


Measured memory_bytes: 6896
//Sani buyuk Osman Pasa Plevneden cikmam diyor.
//FatihSultanMehmedHan
//Abdulhamid Han Elmuzaffer Daima
//Bismillahirrahmanirrahim

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long int lo;
typedef pair< int,int > PII;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(lo i=1;i<=n;i++)
#define mid (start+end)/2
#define ort (bas+son)/2

const lo MAX = -1000000000000000000; 
const lo MIN = 1000000000000000000; 
const lo inf = 1000000000; 
const lo KOK = 100000; 
const lo LOG = 30; 
const lo li = 2000005; 
const lo mod = 1000000007; 

lo n,m,cev,b,a[li],k,v[li],w[li],at,dp[105][105][305];
string s;
//~ vector<lo> v;

inline lo f(lo sira,lo kac,lo W){
	//~ cout<<at<<endl;
	lo cevv=-inf;
	if(sira>n){
		if(kac*at+W<=m) return 0;
		return -inf;
	}
	if(~dp[sira][kac][W]) return dp[sira][kac][W];
	cevv=max(cevv,f(sira+1,kac+1,W+w[sira])+v[sira]);
	cevv=max(cevv,f(sira+1,kac,W));
	return dp[sira][kac][W]=cevv;
}

inline lo solve(){
	memset(dp,-1,sizeof(dp));
	scanf("%lld %lld",&n,&m);
	FOR{
		scanf("%lld %lld",&w[i],&v[i]);
		if(i>1)
			w[i]=w[i]-w[1];
		//~ cout<<w[i]<<endl;
	}
	at=w[1];
	//~ cout<<at<<endl;
	w[1]=0;
	printf("%lld\n",f(1,0,0));
	return 0;
}

int main(void){
	solve();
	
	return 0;
}


Measured memory_bytes: 28928
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
#define PI 3.14159265358979
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repp(i, s, e) for(int i = (s); i <= (e); ++i)
#define sz(x) ((int)x.size())
#define all(x) x.begin(), x.end()
#define FAST_IO() ios::sync_with_stdio(0); cin.tie(0)
template<typename T>
ostream& operator<<(ostream &os, const vector<T> &v) { for (auto x : v) os << x << " "; return os << "\n"; }
template<class U, class V>
ostream& operator<<(ostream &os, const pair<U, V> &p) { return os << "(" << p.first << "," << p.second << ")";}

string S;

int main() {
    cin >> S;
    int ans = 1;
    char before = S[0];
    int idx = 1;
    while(idx < sz(S)) {
        if(S[idx] == before) {
            before = 0;
            if(idx < sz(S) - 1) ans++;
            idx += 2;
        } else {
            before = S[idx];
            ans++;
            idx += 1;
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 640
k, n = map(int, input().split())

a = list(map(int, input().split()))

max = 0
for i in range(n):
  if i==n-1:
    tmp = a[0] + k - a[n-1]
  else:
    tmp = a[i+1] - a[i]
  if tmp > max:
    max = tmp

print(k-max)

Measured memory_bytes: 26420
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	while (cin>>s)
	{
		bool f=1;
		for (int i=0;i<s.size()&&f;i+=2)
			if (!(s[i]=='R'||s[i]=='U'||s[i]=='D'))
				f=0;
		for (int i=1;i<s.size()&&f;i+=2)
			if (!(s[i]=='L'||s[i]=='U'||s[i]=='D'))
				f=0;
		if (f)
			cout<<"Yes"	<<endl;
		else
			cout<<"No"<<endl;
	}
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline

n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
cnt = [0] * (m + 1)
cur = [0] * n
cur_idx = [0] * n
done = [0] * (m + 1)
for i in range(n):
	cnt[a[i][0]] += 1
	cur[i] = a[i][0]
ans = max(cnt)
for _ in range(m - 1):
	col = cnt.index(max(cnt))
	done[col] = 1
	for i in range(n):
		if cur[i] == col:
			j = cur_idx[i]
			while done[a[i][j]]:
				j += 1
			t = a[i][j]
			cur[i] = t
			cur_idx[i] = j
			cnt[t] += 1
	cnt[col] = 0
	ans = min(ans, max(cnt))
print(ans)


Measured memory_bytes: 4212
#include <stdio.h>
#include <ctype.h>

int main(){
   int count[26]={0};
   char ch;
   int i, num;

   while(scanf("%c", &ch)!=EOF){
       if(islower(ch)){
           num=ch-'a';
       }else if(isupper(ch)){
           num=ch-'A';
       }else{
           continue;
       }
       count[num]++;
   }
   for(i=0;i<26;i++){
       printf("%c : %d\n", 'a'+i, count[i]);
   }

   return 0;
}


Measured memory_bytes: 2104
#include <iostream>

int main(){
    std::string s, t;
    std::cin >> s >> t;

    int tSz = t.size(), j = 0;
    
    int i = s.size() - tSz;
    for(; 0 <= i; --i){
        bool flg2 = true;
        int j = 0;
        std::string sub = s.substr(i, tSz);
        while(flg2 && j < tSz){
//    std::cout << "j: " << j << std::endl;
            flg2 = '?' == sub.at(j) || sub.at(j) == t.at(j);
            ++j;
        }
        if(flg2){
            break;
        }    
    }

//    std::cout << i << std::endl;

    std::string ans = "UNRESTORABLE";
    if(0 <= i){
        s.replace(i, tSz, t);
        for(int i = 0; i < s.size(); ++i){
            if('?' == s.at(i)){
                s.at(i) = 'a';
            }
        }
        ans = s;
    }    

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

    return 0;
}

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

using namespace std;

typedef long long ll;

vector<ll > plane;

int main() {
    ll n,x;
    cin >> n >> x;
    for(int i =0;i<n;i++){
        ll u;
        cin >> u;
        plane.push_back(u);
    }


    ll pos = 0;
    ll ans = 0;
    for(int i=0;i<n;i++){

        pos+=plane[i];
        //cout << pos << ' ' << plane[i] <<endl;
        if(pos>x) break;
        ans++;
    }

    cout << ans+1;


    return 0;
}

Measured memory_bytes: 256
# coding:UTF-8
import sys
from math import factorial

MOD = 10 ** 9 + 7
INF = 10000000000

# 素数列挙
def primeNumList(n):
    d = [d for d in range(0, n+1)]
    if n < 2:
        return [[],d]
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n ** 0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
            d[j] = i
    return [[i for i in range(n + 1) if is_prime[i]], d]

def main():
    # ------ 入力 ------#
    n = int(input())    # 数字
    aList = list(map(int, input().split()))     # スペース区切り連続数字

    # ------ 処理 ------#
    amax = max(aList)
    pl = primeNumList(amax)
    countList = [0] * (amax+1)

    if pl[0] != []:
        for a in aList:
            at = a
            sl = []
            while at != 1:
                s = pl[1][at]
                sl.append(s)
                at = int(at / s)
            sl2 = list(set(sl))
            for s in sl2:
                countList[s] += 1
        m = max(countList)
    else:
        m = 0

    # ------ 出力 ------#
    if m == len(aList):
        print("not coprime")
    elif m >= 2:
        print("setwise coprime")
    else:
        print("pairwise coprime")


if __name__ == '__main__':
    main()


Measured memory_bytes: 208156
/* {{{ Shinobu kawaii */
/*
  ______   __        _                  __                 
.' ____ \ [  |      (_)                [  |                
| (___ \_| | |--.   __   _ .--.   .--.  | |.--.   __   _   
 _.____`.  | .-. | [  | [ `.-. |/ .'`\ \| '/'`\ \[  | | |  
| \____) | | | | |  | |  | | | || \__. ||  \__/ | | \_/ |, 
 \______.'[___]|__][___][___||__]'.__.'[__;.__.'  '.__.'_/ 
                                                           
*/
/* }}} */

#include <bits/stdc++.h>
using namespace std;

// #define int long long

/* cpp template {{{ */

/* short */
#define pb push_back
#define mp make_pair
#define print(x) cout << x << '\n'
#define Fi first
#define Se second

/* REPmacro */
#define REPS(i, a, n) for (int i = (a); i < (n); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = 1; i <= (n); i++)
#define DEPS(i, a, n) for (int i = (a); i >= n; i--)
#define DEP(i, n) for (int i = (n); i >= 0; i--)

/* typedef */
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;

/* const */
const int INF = 999999999;
const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

/* func */
inline bool is_uruu(int y) {return (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0));}
inline bool inside(int y, int x, int H, int W) {return (y >= 0 && x >= 0 && y < H && x < W);}

/* }}} */

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

  for (int n; cin >> n, n;){
    vi a(n); REP(i, n) cin >> a[i];
    int ans; cin >> ans;
    int mid, l = 0, r = n - 1;
    int cnt = 0;
    do {
      cnt++;
      mid = (l + r) / 2;
      if (a[mid] == ans){
        break;
      }
      if (a[mid] <= ans){
        l = mid + 1;
      } else {
        r = mid - 1;
      }
    } while (r - l >= 0);
    print(cnt);
  }

  return (0);
}

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

int main(){
	int n, a, ans4 = 0, ans2 = 0;
	scanf("%d", &n);
	for(int i = 0;i < n;i++){
		scanf("%d", &a);
		if(a % 4 == 0)ans4++;
		else if(a % 2 == 0)ans2++;
	}
	int add = max(0, ans2-1);
	if(ans4*2+1+add >= n)printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define rep(i, a) for (int i = 0; i < (a); i++)
#define repd(i, a) for (int i = (a)-1; i >= 0; i--)
#define reps(i, a, j) for (int i = (j); i < (a); i++)
#define deb(x) cout << #x << " " << x << endl;
#define debs(x) cout << #x << " " << x << " ";
#define deba(x) for (auto _i:x) cout << _i << " "; cout << endl;
#define ms(a) memset(a,0,sizeof(a));
#define mp make_pair
#define eb emplace_back
#define FastOpen freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define pii pair < int , int >
#define all(a) a.begin(),a.end() 
//int power(int x,int p){if(p==0)return 1;if(p==1)return x;if(p%2)return x*power(x,p-1);int y=power(x,p/2);return y*y;}
/*
*/

void solve() {
    int n,m,res = 0; cin >> n >> m;
    vector < int > g[n],in_degree(n,0),dp(n,0);
    rep(i,m) {
        int x,y; cin >> x >> y;
        x--;
        y--;
        g[x].eb(y);
        in_degree[y] ++;
    }
    deque < int > q;
    rep(i,n) if (in_degree[i] == 0) q.push_back(i);
    while (!q.empty()) {
        int x = q.front();
        q.pop_front();
        for (auto v:g[x]) {
            in_degree[v]--;
            dp[v] = max(dp[v],dp[x]+1);
            if (in_degree[v] == 0) q.push_back(v);
        }
    }
    rep(i,n) res = max(res,dp[i]);
    cout << res << endl;   
}

signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//    FastOpen
    int t; t=1;
    while (t--) solve();
}





Measured memory_bytes: 10288