akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
 
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> P;
 
constexpr int INF = 1e9;
constexpr int MOD = 1e9+7;
 
int main() {
    ll n,k;
    cin >> n >> k;
    vector<ll> p(n+10,0),c(n+10,0);
    for(int i = 1; i <= n; i++) cin >> p[i];
    for(int i = 1; i <= n; i++) cin >> c[i];
 
    ll ans = -1e10;
    for(int i = 1; i <= n; i++){
        ll sum = 0,ti = p[i],j = 1;
        while(i != ti) { ti = p[ti]; j++; }
        if(k < j){
            for(int l = 1; l <= k; l++){
                sum += c[p[ti]];
                ans = max(ans,sum);
                ti = p[ti];
            }
        }else{
            for(int l = 1; l <= j; l++){
                sum += c[p[ti]];
                ans = max(ans,sum);
                ti = p[ti];
            }
            if(sum >= 0){
                sum = (k/j-1)*sum;
                for(int l = 1; l <= j+k%j; l++){
                    sum += c[p[ti]];
                    ans = max(ans,sum);
                    ti = p[ti];
                }
            }
        }
        ans = max(ans,sum);
    }
    cout << ans << endl;
 
	return 0;
}

Measured memory_bytes: 3704
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
 
const double TL = 1.5 * CLOCKS_PER_SEC;
mt19937 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count());
#define clr(x, y) memset(x, y, sizeof(x))
#define forn(i, n) for (int i = 0; i < n; i++)
#define LL long long
const double pi = acos(-1.0);

int h, w, n;

int main() {
#ifdef LOCAL
  auto start_clock = clock();
  freopen("in", "r", stdin);
#endif

  scanf("%d%d%d", &h, &w, &n);
  vector<pair<int, int>> r(h);
  vector<pair<int, int>> c(w);
  set<pair<int, int>> st;

  for (int i = 0; i < h; i++) r[i].second = i;
  for (int i = 0; i < w; i++) c[i].second = i;

  for (int i = 0; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    x -= 1;
    y -= 1;
    st.insert({x, y});
    r[x].first += 1;
    c[y].first += 1;
  }
  sort(r.begin(), r.end());
  reverse(r.begin(), r.end());

  sort(c.begin(), c.end());
  reverse(c.begin(), c.end());

  int ans = c[0].first + r[0].first - 1;
  bool flag = false;
  for (int i = 0; i < h && r[i].first == r[0].first; i++) {
    for (int j = 0; j < w && c[j].first == c[0].first; j++) {
      if (st.find({r[i].second, c[j].second}) == st.end()) {
        flag = true;
        break;
      }
    }
    if (flag) {
      break;
    }
  }
  if (flag) ans += 1;
  printf("%d\n", ans);


#ifdef LOCAL
 auto end_clock = clock();
 cout << "Time:" << (end_clock - start_clock) * 1.0 / CLOCKS_PER_SEC << endl;
#endif
  return 0;
}

Measured memory_bytes: 22008
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class BPopularVote {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      int n, m; cin >> n >> m;
      vector<int> a(n);
      int sum = 0;
      rep(i, n) {
        cin >> a[i];
        sum += a[i];
      }
      sort(a.rbegin(), a.rend());
      if (a[m-1]*4*m >= sum) {
        cout << "Yes" << endl;
      } else {
        cout << "No" << endl;
      }
    }
};

signed main() {
  BPopularVote solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

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

int main() {
  char a;
  cin >> a;
  if (a < 91){
    cout << 'A' << endl;
  }
  else{
    cout << 'a' << endl;
  }

  /*int N = 3;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }*/

  /*for (int i = 0; i < vec.size(); i ++){
    cout << vec.at(i) << endl;
  }

  for (int i = 0; i < vec.size()-1; i ++){
    cout << vec.at(i) << " ";
  }
  cout << vec.at(vec.size() - 1) << endl;*/
}


Measured memory_bytes: 3644
#include <cstdio>
#include <algorithm>
using namespace std;
const int N = 105;
int a[N],b[N],n,m;
int main(){
    scanf("%d",&n);
    for(int i=1;i<n;++i) scanf("%d",&b[i]);
    a[1]=b[1]; a[n]=b[n-1];
    for(int i=2;i<n;++i)
        a[i]=min(b[i-1],b[i]);
    for(int i=1;i<=n;++i) m+=a[i];
    printf("%d\n",m);
}

Measured memory_bytes: 128
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////

int a,b,c,d[100005] = {},n,m;
string s,t;

int main(){

    cin >> a >> s;

    if( a >= 3200)P(s);
    else P("red");
    
    return  0;
}


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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 1e5 + 5;

int x[MAXN];

void solve(){
	int n;
	scanf("%d", &n);
	REPN(i, 1, n){
		scanf("%d", &x[i]);
	}
	ll ans = 1ll;
	int cnt = 0;
	REPN(i, 1, n){
		if ((i - cnt - 1) * 2 == x[i]){
			ans = (ans * (i - cnt)) % MOD;
			cnt++;
		}
	}
	for(; cnt < n; cnt++){
		ans = (ans * (n - cnt)) % MOD;
	}
	printf("%lld\n", ans);
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


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

a = [0 for _ in range(m)]
for _ in range(n):
    k = list(map(int, input().split()))
    for i in range(k[0]):
        a[k[i+1] - 1] += 1

ans = 0
for i in range(m):
    if a[i] == n:
        ans += 1

print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
using lli = long long;
using pii = pair<int, int>;

#define rep(i,k,n) for(int i=(k); i != int(n); ++i)
#define sz(x) x.size()
#define all(x) x.begin(), x.end()

#define dbg(x) cout << #x << '=' << x << '\n'
#define dbg2(x, y) cout << #x << '=' << x << ' ' << #y << '=' << y << '\n' 

#define input() (*istream_iterator<int>(cin))
#define strin() (*istream_iterator<string>(cin))
#define output(x) cout << x << '\n' 

int main(){
    ios::sync_with_stdio(false);
    int n = input(), m = input();
    (m >= n)? puts("unsafe"): puts("safe");
}

Measured memory_bytes: 3612
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;

int main()
{
	double r;cin >> r;
	cout << 2 * r * 3.1415926;
    return 0;
}


Measured memory_bytes: 3228
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <map>
#include <iomanip>
#include <limits>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

int asc(const void* a, const void* b) {
	return *(int*)a- *(int*)b;
}

int main()
{
	int n;
	double ans = 0.0, a;
	cin >> n;
	rep(i, n) {
		cin >> a;
		ans += 1.0 / a;
	}
	ans = 1.0 / ans;
	cout << setprecision(16) << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

int chmin(int a, int b)
{
	if (a > b)
		return b;
	return a;
}

int n;
int k;
int h[100010];
int dp[100010];

int main(int argc, char const *argv[])
{
	scanf("%d%d", &n, &k);
	for (int i = 0; i < n;i++)
	{
		scanf("%d", h+i);
		dp[i] = INT_MAX;
	}
	dp[0] = 0;
	dp[1] = llabs(h[1] - h[0]);

	for (int i = 2; i < n; i++)
	{
		for (int j = 1; j <= k && i - j >= 0; j++)
		{
			dp[i] = chmin(dp[i], dp[i - j] + llabs(h[i] - h[i - j]));
		}
	}

	printf("%d", dp[n - 1]);
	return 0;
}


Measured memory_bytes: 896
S = input()
l_1 = [0]
l_2 = [0]
for i in range(len(S)):
  if S[i] == '<':
    l_1.append(l_1[i] + 1)
  else:
    l_1.append(0)
for i in range(len(S)):
  if  S[len(S)-i-1] == '>':
    l_2.append(l_2[i] + 1)
  else:
    l_2.append(0)
l_2.reverse()
l_3 = []
for i in range(len(S)+1):
  l_3.append(max(l_1[i], l_2[i]))
print(sum(l_3))

Measured memory_bytes: 31908
#include<bits/stdc++.h>
using namespace std;
int sa(int a, int b) {
  return max(a - b, b - a);
}
int main () {
  int N, K;
  cin >> N >> K;
  vector<int>he(N);
  for (int i = 0; i < N; i ++) cin >> he[i];
  if (N - 1 <= K) {
    cout << sa(he[0], he[N - 1]) << endl;
    return 0;
  }
  vector<int>dp(N);
  for (int i = 0; i <= K; i ++) {
    dp[i] = sa(he[0], he[i]);
  }
  for (int i = K + 1; i < N; i ++) {
    dp[i] = sa(he[i], he[i - 1]) + dp[i - 1];
    for (int j = 2; j <= K; j ++) {
      int kuma = sa(he[i], he[i - j]) + dp[i - j];
      if (dp[i] > kuma) dp[i] = kuma;
    }
  }
  cout << dp[N - 1] << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
	int n, t;
	cin >> n >> t;

	std::vector<int> vc, vt;
	for (int i = 0; i < n; ++i)
	{
		int ci, ti;
		cin >> ci >> ti;
		vc.push_back(ci);
		vt.push_back(ti);
	}

	int mincost = 10000;
	for (int i = 0; i < vc.size(); ++i)
	{
		if (vt[i] <= t && vc[i] < mincost)
		{
			mincost = vc[i];
		}
	}

	if (mincost == 10000)
	{
		printf("TLE\n");
	}
	else
	{
		printf("%d\n", mincost);
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
const double pi = 3.141592653589793238462643383279;
using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
 
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
 
//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
 
 
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
 
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
 
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)

const long double EPS = 1e-6, PI = acos((long double)-1);

//ここから編集


int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(4);

  ll a, b, c, d; cin >> a >> b >> c >> d;

  cout << max({b*d, a*c, a*d, b*c}) << endl;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define FIXED_FLOAT(x)  std::fixed <<std::setprecision(7)<<(x)
#define all(v) (v).begin(), (v).end()
using namespace  std;
#define loop(i,a,b) for (int i=a; i<b; ++i)
using ll = long long;
const int mod = 1e9 + 7;
typedef pair<int , int> pairs;
typedef complex<ll> G;
 
const int N = 1e3 + 10;
 
int power(int a,int b){
    if(!b)
        return 1;
    int c=power(a,b/2);
    c=(1LL*c*c)%mod;
    if(b%2)
        c=(1LL*c*a)%mod;
    return c;
}
 
vector<int>dis(N);
vector<bool>vis(N);
vector<int>c[N];
int far;
int ans;
int now;
void aff(int s, int e, int d) {
    if(vis[s])return;
    vis[s] = true;
    dis[s] = d;
    ans = max(ans, dis[s]);
    for(auto u : c[s]) {
        if(u == e)continue;
        aff(u, s, d + 1);
    }
}
void dfs(int s, int e, int d) {
 
    if(vis[s])return;
 
    dis[s] = d;
    if(now < d) {
        far = s;
        now = d;
    }
    vis[s] = true;
    for(auto u : c[s]) {
        if(u == e)continue;
        dfs(u, s, d + 1);
    }
}
void done() {
    int n;
    cin >> n;
    for(int i = 1;i < n;++i) {
        int a,b;
        cin >> a >> b;
        c[a].push_back(b);
        c[b].push_back(a);
    }
    if(n == 1) {
        cout << 0 << '\n';
        return;
    }
    far = 0;
    now = 0;
    ans = 0;
    dfs(1, 0, 0);
 
    fill(vis.begin(), vis.end(), 0);
    fill(dis.begin(), dis.end(), 0);
    aff(far, 0, 0);
    cout << ans * 3 << '\n';
 
}
/*string solve_palindrome(const string& s)
{
    string a = s;
    reverse(a.begin(), a.end());
    //a = s + "#" + a;
    int c = 0;
    for (int i = 1; i < (int)a.size(); i++)
    {
        while (c != 0 && a[c] != a[i])
            c = pref[c - 1];
        if (a[c] == a[i])
            c++;
        pref[i] = c;
    }
    return s.substr(0, c);
}
*/
 
/*3
3 7 7 9 11
4 6 6 7*/
void solve()
{
    int s;
    cin >> s;
    vector<ll>dp(s + 1, 0);
    if(s < 3) {
        cout << 0 << '\n';
        return;
    }
    dp[3] = 1;
    for(int i = 4;i <= s;++i)
        dp[i] = (dp[i-1] + dp[i-3]) % mod;
    cout << dp[s] << '\n';
 
 
}
int cal(int  n) {
    string s = to_string(n);
    int ans = 0;
    for(int i = 0;i < s.size();++i) {
        ans += s[i] - '0';
    }
    return ans;
}
int sum(long long n) {
	int res = 0;
	while (n > 0) {
		res += n % 10;
		n /= 10;
	}
	return res;
}
long long  a[N];
long long  find(int x,int y)
{
    if(x>y) return 1;
    long long ans = 1ll * pow(a[x],find(x+1,y));
    return ans;
}
void another() {
    int n;
    cin >> n;
    vector<int>dp(N + 10, (int)1073709056), a(n + 10);
    for(int i = 0;i < n;++i) {
        cin >> a[i];
    }
    for(int i = n;i < n + 5;++i) {
        a[i] = 0;
    }
    dp[0] = 0;
    for(int i = 0;i < n;++i) {
        dp[i + 2] = min(dp[i + 2], dp[i] + a[i]);
        dp[i + 3] = min(dp[i + 4], dp[i] + a[i]);
        dp[i + 4] = min(dp[i + 4], dp[i] + a[i] + a[i + 1]);
    }
    cout << dp[n] << '\n';
 
 
 
}
 
 
void test_case() {
    int t;
    cin >> t;
    while(t--)another();
}
int main() {
 
    ios::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
 
    solve();
}

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

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

    static class CYutori {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int k = in.nextInt();
            int c = in.nextInt();
            char[] sin = in.next().toCharArray();
            boolean[] s = new boolean[n];
            for (int i = 0; i < n; i++) {
                s[i] = sin[i] == 'x';
            }

            // let's say he works on the earliest possible days
            BitSet first = new BitSet(n);
            outer:
            for (int d = 0; d < n; d += c + 1) {
                while (s[d]) {
                    d++;
                    if (d >= n)
                        break outer;
                }
                first.set(d);
            }
            BitSet last = new BitSet(n);
            outer:
            for (int d = n - 1; d >= 0; d -= c + 1) {
                while (s[d]) {
                    d--;
                    if (d < 0)
                        break outer;
                }
                last.set(d);
            }

            if (first.cardinality() > k) {
                return;
            }

            first.and(last);
            for (int i = first.nextSetBit(0); i != -1; i = first.nextSetBit(i + 1)) {
                out.println(i + 1);
            }
        }

    }

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

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 41216
#include <iostream>
#include <algorithm>
using namespace std;
int tbl[30][13][160];
int solve(int n,int k,int s){
  if(k==0 && s==0) return 1;
  if(k<0 || s<0) return 0;
  if(tbl[n][k][s]) return tbl[n][k][s];
  int ret = 0;
  for(int i=n;i>=1;--i){
    ret+=solve(i-1,k-1,s-i);
  }
  return tbl[n][k][s]=ret;
}
int main(){
  int n,k,s;

  while(cin>>n>>k>>s,n||k||s){
    cout << solve(n,k,s) << endl;
  }
  return 0;
}

Measured memory_bytes: 1328
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'

using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;

long long maximum_rectangle(const std::vector<int> &h) {
    int n = h.size();
    std::stack<int> s;
    std::vector<int> L(n), R(n);
    for (int i = 0; i < n; i++) {
        while (s.size() && h[s.top()] >= h[i]) s.pop();
        L[i] = s.size() ? (s.top() + 1) : 0;
        s.push(i);
    }
    while (s.size()) s.pop();
    for (int i = n - 1; i >= 0; i--) {
        while (s.size() > 0 && h[s.top()] >= h[i]) s.pop();
        R[i] = s.size() ? s.top() : n;
        s.push(i);
    }
    long long res = 0;
    for (int i = 0; i < n; i++) {
        res = std::max(res, (long long)h[i] * (R[i] - L[i]+1));
    }
    return res;
}

int main() {
  ll H,W;
  cin >> H >> W;
  vector<string> S(H);
  repeat(i,H){
    cin >> S[i];
  }
  vector<vint> fld(H,vint(W-1,1));
  for(int i=1;i<H;i++){
    for(int j=0;j<W-1;j++){
      fld[i][j] -= INF*((S[i-1][j]=='#')^(S[i-1][j+1]=='#')^(S[i][j]=='#')^(S[i][j+1]=='#'));
    }
  }
  repeat(j,W-1){
    repeat(i,H-1){
      fld[i+1][j] += fld[i][j];
      if(fld[i+1][j] < 0) fld[i+1][j]=1;
    }
  }
  debugArray(fld[2],W-1);
  ll ans = 0;
  repeat(i,H){
    ans = max(ans,maximum_rectangle(fld[i]));
  }
  ans = max(ans,max(H,W));
  cout << ans << endl;
  return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> TUP;
#define a first
#define b second
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll MOD=1000000007;

ll maxx(ll x,ll y,ll z){
	return max(max(x,y),z);
}
ll minn(ll x,ll y,ll z){
	return min(min(x,y),z);
}
ll gcd(ll x,ll y){
	if(x%y==0) return y;
    else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
	return x*(y/gcd(x,y));
}

//a,b x
int main(){
	ll m; cin>>m;
	string s; cin>>s;
	ll ans=0;
	rep(N,s.sz-1){
		vector<ll> sit(26,0);
		rep(i,N+1){
          	char tp=s[i]-'a';
			if(sit[tp]==0) sit[tp]=1;
		}
		for(int i=N+1;i<=s.sz-1;i++){
          char tp=s[i]-'a';
			if(sit[tp]==1) sit[tp]=2;
		}
		ll cnt=0;
		rep(i,26){
			if(sit[i]==2) cnt++;
		}
		if(ans<cnt) ans=cnt;
	}
	cout<<ans;
}


Measured memory_bytes: 256
mod reader {
    use std;

    macro_rules! read_line((  ) => {
                           {
                           let mut input = String :: new (  ) ; std :: io ::
                           stdin (  ) . read_line ( & mut input ) . unwrap (
                           ) ; input } } ;);

    pub fn read_to_vec<T: std::str::FromStr>() -> Vec<T> {
        read_line!().split_whitespace().map(|e|
                                                e.parse().ok().unwrap()).collect()
    }

    pub fn read_str() -> String { read_line!().trim().to_owned() }
}
use reader::*;

#[macro_use]
mod misc {
    #[macro_export]
    macro_rules! bind_from_vec((
                               $ ( $ variable : ident ) , + = $ vector : expr
                               ) => {
                               let mut v = $ vector . clone (  ) . into_iter (
                                ) ; $ (
                               let $ variable = v . next (  ) . unwrap (  ) ;
                               ) + } ;);
}

use std::collections::HashMap;

fn main() {
    bind_from_vec!(n , q = read_to_vec :: < usize > (  ));
    let text = read_str();
    let mut searched: Vec<usize> = Vec::new();
    let mut ans_mem = HashMap::new();
    let mut ans = Vec::new();

    let mut flag = false;
    for (i, c) in text.chars().enumerate() {
        if flag { flag = false; if c == 'C' { searched.push(i); } }
        if c == 'A' { flag = true; }
    }

    for _ in 0..q {
        bind_from_vec!(l , r = read_to_vec :: < usize > (  ));

        let left =
            match *ans_mem.entry(l).or_insert(searched.binary_search(&l)) {
                Ok(x) => x,
                Err(x) => x,
            };
        let right =
            match *ans_mem.entry(r).or_insert(searched.binary_search(&r)) {
                Ok(x) => x,
                Err(x) => x,
            };

        ans.push(right.checked_sub(left).unwrap_or(0));
    }

    for x in ans.iter() { println!("{}" , x); }
}


Measured memory_bytes: 12540
n,q=map(int,input().split())
s=input()
lr=[list(map(int,input().split())) for i in range(q)]

rui=[0]*(n+1)
tmp=0
for i in range(len(s)):
  if s[i-1] == 'A' and s[i] == 'C':
    tmp += 1
  rui[i] = tmp

for i in range(q):
  print(rui[lr[i][1]-1] - rui[lr[i][0]-1])


Measured memory_bytes: 29636
import collections 
List=collections.deque()
n=int(input())
for i in range(n):
	command=input().split()
	if command[0] == 'insert':
		List.appendleft(command[1])		
	elif command[0] == 'delete':
		try:List.remove(command[1])
		except:pass
	elif command[0] == 'deleteFirst':
		List.popleft()	
	elif command[0] == 'deleteLast':
		List.pop()
		
print(*List)



Measured memory_bytes: 69740
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i];}cout<<endl;
#define pprint(A,m,n) rep(j,0,m){print(A[j],n);}
const long mod=1e9+7;
const int size=1e5;
const long inf=1e9;
int main(){
	int N;string s;cin>>N>>s;
	int cnt=0;
	rep(i,0,1000){
		string t=to_string(1000+i);
		int k=1;
		rep(j,0,N){
			if(s[j]==t[k]) k++;
			if(k==4){ cnt++; break; }
		}
	}cout<<cnt<<endl;
}

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


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

  int n,a,b;
  cin >> n >> a >> b;

  cout << min(a,b) << " " << max(a+b-n, 0) << endl;


  
  return 0;
    

}


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

using namespace std;

int main()
{
    long long x, k, d;
    cin >> x >> k >> d;
    if (x < 0)
        x = -x;
    long long a = x/d;
    if (k < a) {
        cout << x  - k*d << '\n';
    }
    else {
        long long r = k - a;
        long long m = x%d;
        if (r%2 == 0)
            cout << x - a*d << '\n';
        else
            cout << abs(x - a*d - d) << '\n';
    }
    return 0;
}

Measured memory_bytes: 3604
import queue
import math
import copy
"""
N = int(input())
#S = input()
# (N,M) = (int(i) for i in input().split(" "))
# A = [int(i) for i in input().split()]
A = []
for i in range(N):
	A.append(int(input()))

print(A)

"""

N = int(input())
A = [int(i) for i in input().split()]
mn = 10000000
ans = 0
for a in A:
	if a <= mn:
		ans += 1
	mn = min(mn,a)
print(ans)

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

int main(void) {
    int N, D;
    cin >> N >> D;

    int ans;
    ans = N / (2*D+1);
    if(N%(2*D+1)!=0) ans++;

    cout << ans << endl;

    return (0);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s;
int main()
{
    int n;cin>>n;
    cin>>s;
    int ans=0;
    for(int i=0;i+2<s.size();i++)
        if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C') ans++;
        cout<<ans;
}


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

public class Main {
    public static void main(String[] args) throws IOException {
        FastScanner in = new FastScanner();
        int n = in.nextInt();
        int m = in.nextInt();
        //0 to n-1
        ArrayList<ArrayList<Integer>> graph = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            graph.add(new ArrayList<>());
        }
        
        for (int i = 0; i < m; i++) {
            int a = in.nextInt() - 1;
            int b = in.nextInt() - 1;
            graph.get(a).add(b);
            graph.get(b).add(a);
        }
        
        for (int i = 0; i < graph.get(0).size(); i++) {
            for (int j = 0; j < graph.get(graph.get(0).get(i)).size(); j++) {
                if (graph.get(graph.get(0).get(i)).get(j) == n-1) {
                    System.out.println("POSSIBLE");
                    return;
                }
            }
        }
        System.out.println("IMPOSSIBLE");
    }

    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        public FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String nextToken() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        String nextLine() {
            st = null;
            try {
                return br.readLine();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return null;
        }

        int nextInt() {
            return Integer.parseInt(nextToken());
        }

        long nextLong() {
            return Long.parseLong(nextToken());
        }

        double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }
}


Measured memory_bytes: 87268
from itertools import combinations

a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

for p, q in combinations([a, b, c, d, e], 2):
    if q - p > k:
        print(":(")
        break
else:
    print("Yay!")


Measured memory_bytes: 3060
import math

def KochCurve(p1,p2,n):
    if n==0:
        return
    s = [(2*p1[0]+p2[0])/3,(2*p1[1]+p2[1])/3]
    t = [(p1[0]+2*p2[0])/3,(p1[1]+2*p2[1])/3]
    u = [(p1[0]+p2[0])/2+((-1)*math.sqrt(3))*(p2[1]-p1[1])/6,(p1[1]+p2[1])/2+(math.sqrt(3))*(p2[0]-p1[0])/6]
    KochCurve(p1,s,n-1)
    print(f"{'{:.9f}'.format(s[0])} {'{:.9f}'.format(s[1])}")
    KochCurve(s,u,n-1)
    print(f"{'{:.9f}'.format(u[0])} {'{:.9f}'.format(u[1])}")
    KochCurve(u,t,n-1)
    print(f"{'{:.9f}'.format(t[0])} {'{:.9f}'.format(t[1])}")
    KochCurve(t,p2,n-1)

p1 = [0,0]
p2 = [100,0]
n = int(input())
print(f"{'{:.9f}'.format(p1[0])} {'{:.9f}'.format(p1[1])}")
KochCurve(p1,p2,n)
print(f"{'{:.9f}'.format(p2[0])} {'{:.9f}'.format(p2[1])}")


Measured memory_bytes: 5752
#include <bits/stdc++.h>
#define int long long 
#define uint unsigned long long 
#define double long double 
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define sett(c) (c).resize(unique(all(c))-(c).begin())
#define sz(a) (int)(a).size()
#define hell 1000000007
#define pi pair<int,int>
#define vi vector<int> 
#define vb vector<bool> 
#define vpi vector<pair<int,int>> 
#define x first 
#define y second 
#define endl '\n'
#define forn(i,n) for(int i = 0 ; i < n ; i++ )
#define for1(i,n) for(int i = 1 ; i < n ; i++ )
#define fore(i,a,b) for(int i = a ; (a>b)?(i>=b):(i<=b) ; (a>b)?(i--):(i++) ) 
 
using namespace std;
const int MAX = 1e6;

long long binpow(long long a, long long b) {

    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a ;
        a = a * a ;
        res %= hell;
        a %= hell;
        b >>= 1;
    }
    return res;
}

bool comp(const pi& a , const pi& b ){
        return a.y < b.y;
}

int ncr(int n , int r ){
	r = min(r,n-r);
	int res = 1 ;
	for(int i = 1 ; i <= r ; i++ ){
		( res *= n-i+1 )%= hell;
		res /= i ;
	}
	return res ;
}

void solve(){
		int n ; cin >> n ;
		int k = n/100 ;
		int  d = n%100 ;
		k -= (d/5);
		d -= (d/5)*5 ;
		int arr[] = {5,4,3,2,1};
		forn(i,5){
			k -= (d/arr[i]);
			d -= (d/arr[i])*arr[i] ;
		}
		if(k < 0 or n == 0){
			cout << 0 << endl ;
		}else{
			cout << 1 << endl ;
		}
}
 
int32_t main(){
        
        ios_base::sync_with_stdio(false);
        cin.tie(nullptr);
        cout.tie(nullptr);
        cout << fixed;
        cout.precision(10);
 
#ifdef LOCAL_DEFINE
        //freopen("input.txt","rt",stdin);
        //freopen("output.txt","w",stdout);
#endif
 
        int t = 1;
        //cin >> t ;
        while(t--){
                solve();
        }
#ifdef LOCAL_DEFINE
        cout << "Time elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms.\n";
#endif
 
        return 0;
}


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

#define ll long long int
#define pf push_front
#define mod  1000000007
#define inf  1000000000000000000
#define pi  acos(-1.0)
#define maxn  1000009
#define endl '\n'
#define sorted(s)  sort(s.begin(),s.end())
#define reversed(s) reverse(s.begin(),s.end())
#define sortarr(a) sort(a,a+n)
#define slc(n) scanf("%I64d", &n)
#define sl(n)  scanf("%lld", &n)
#define sf(n)  scanf("%lf", &n)
#define si(n)  scanf("%d", &n)
#define sch(n)  scanf(" %c", &n)
#define ss(n)  scanf("%s", n)
#define prf printf
#define pb  push_back
#define fr first
#define sc second
#define all(a)  a.begin(),a.end()
#define forl(n) for(i=0;i<n;i++)
#define ison(n,j) (n&(1LL<<j))
#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;

int main()
{
    _fastio
     ll n,i,j,s=0,x;
     cin>>n;
     for(i=0;i<n;i++)
     {
         cin>>x;
         s+=x;
     }
     cout<<s-n<<endl;
    return 0;
}





Measured memory_bytes: 3668
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
const long long INF = 1LL << 60;

int n;

int main()
{
  cin >> n;
  bool check = false;
  if(n/100 == 7 || (n/10)%10 == 7 || n%10 == 7) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main(){
long long n, l, r,ans=0;
cin >> n;
ans = (n*(n+1)*(2*n+1) + 3*(n+1)*n)/12;
for(int i=0;i<n-1;i++){
  cin >> l >> r;
  if(l > r)swap(l,r);
  ans-= l * (n-r+1);
}
  cout << ans;
}
  

Measured memory_bytes: 3640
x,y = map(int,input().split())
if x == 0 and y > 0:
    print(y-x)
elif x == 0 and y < 0:
    print(1+abs(x+y))
elif y == 0 and x > 0:
    print(1+abs(x+y))
elif y == 0 and x < 0:
    print(y-x)
elif x < 0 and y < x:
    print(2+abs(x-y))
elif 0 < x and x < y:
    print(y-x)
elif 0 < y and x > y:
    print(2+abs(x-y))
elif 0 > y and x > y:
    print(abs(y+x)+1)
elif x < 0 and y > 0:
    print(abs(y+x)+1)
elif y < 0 and x < y:
    print(y-x)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; 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 rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  int M,D;
  cin >> M >> D;
  int ans = 0;
  srep(m,1,M+1) {
    srep(d,1,D+1) {
      if((d/10) * (d % 10) == m && (d/10) >= 2 && (d%10) >= 2) {
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int m=0,n,b,v,c,k,j,i,a,q=0,w=0,e=0,r=0,t=0,y=0,u=0;
	scanf("%d%d%d%d",&a,&b,&c,&n);
	for(i=0;i<=a;i++)
	{
		for(j=0;j<=b;j++)
		{
			for(k=0;k<=c;k++)
			{
				if(i*500+j*100+k*50==n)
				{
					m++;
				}
			}
		}
	 } 
	 printf("%d",m);
	return 0;
} 

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

using namespace std;
using i64 = std::int_fast64_t;
using u64 = std::uint_fast64_t;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string S, T;
  cin >> S >> T;
  vector<vector<int>> pos(30);
  for (int i = 0; i < (int)S.size(); i++) {
    pos[S[i] - 'a'].emplace_back(i);
  }

  for (int i = 0; i < 30; i++) {
    if (pos[i].empty()) continue;
    pos[i].emplace_back(1 << 28);
    sort(pos[i].begin(), pos[i].end());
  }

  int p = -1, res = 0;
  for (int i = 0; i < (int)T.size(); i++) {
    if (pos[T[i] - 'a'].empty()) {
      cout << -1 << '\n';
      return 0;
    }

    int t = upper_bound(pos[T[i] - 'a'].begin(), pos[T[i] - 'a'].end(), p) -
            pos[T[i] - 'a'].begin();

    if (t == (int)pos[T[i] - 'a'].size() - 1) {
      res++;
      p = pos[T[i] - 'a'][0];
    } else {
      p = pos[T[i] - 'a'][t];
    }
  }

  cout << 1LL * res * S.size() + 1LL * p + 1 << '\n';
  return 0;
}


Measured memory_bytes: 1228
a = Array.new(3){ gets.to_s.split.map{|i|i.to_i} }
n = gets.to_s.to_i
b = Array.new(n){ gets.to_s.to_i }

c = Array.new(3){ Array.new(3){ false } }
b.each do |k|
  3.times do |i|
    3.times do |j|
      c[i][j] = true if a[i][j] == k
    end
  end
end

f = false
3.times{ |i| f = true if c[i][0] && c[i][1] && c[i][2] }
3.times{ |j| f = true if c[0][j] && c[1][j] && c[2][j] }
f = true if c[0][0] && c[1][1] && c[2][2]
f = true if c[0][2] && c[1][1] && c[2][0]

puts f ? "Yes" : "No"

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

typedef pair<int,int>P;

int main(){
    string s;cin>>s;
    vector<int>a(s.size());

    for(int i=0;i<s.size();i++){
        if(s[i]=='J')a[i]=0;
        else if(s[i]=='O')a[i]=1;
        else a[i]=2;
    }

    int cur=0;
    vector<P>v;
    while(cur<a.size()){
        int next=cur;
        while(next<a.size()&&a[next]==a[cur])next++;
        v.push_back(P(a[cur],next-cur));
        cur=next;
    }


    int ma=0;
    for(int i=0;i+2<v.size();i++){
        if(v[i].first==0&&v[i+1].first==1&&v[i+2].first==2){
            int mi=min(min(v[i].second,v[i+1].second),v[i+2].second);
            if(v[i+1].second==mi)ma=max(ma,mi);
        }
    }

    cout<<ma<<endl;
    return 0;
}

Measured memory_bytes: 16548
n = int(input())
s = input()
ls = list(s)
alphabet = list('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
for i in range(len(s)):
    index = alphabet.index(ls[i])
    if index + n < 26:
        ls[i] = alphabet[index + n]
    else:
        ls[i] = alphabet[index + n - 26]
print(''.join(ls))

Measured memory_bytes: 9224
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
const int MOD = 1000000007;
const int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;



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

  string S;
  cin >> S;
  bool ok = false;
  int N = S.size();
  for(int i=0;i<=N-3;i++){
    if(S[i] != S[i+2])ok = true;
  }
  if(ok){
    if(N % 2 == 0 && S[0] == S[N-1]){
      cout << "First" << endl;
    }
    else if(N % 2 == 1 && S[0] != S[N-1]){
      cout << "First" << endl;
    }
    else{
      cout << "Second" << endl;
    }
  }
  else{
    cout << "Second" << endl;
  }

}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n); for(int i = 0;i < (int)(n);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
int main(){
    int n;
    cin >> n;
    vector<int>a(n);
    rep(i,n)cin >> a[i];
    sort(all(a));
    int b = a[n-1];
    vector<pair<int,int>>data(n-1);
    rep(i,n-1){
        data[i].second = a[i];
        data[i].first = a[i];
        if(a[i]>b/2)data[i].first = b-a[i];
    }
    sort(all(data));
    reverse(all(data));
    cout << b << " " << data[0].second << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>

using namespace std;
const long long MOD = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ll> pdl;
typedef pair<ld, ld> pdd;
//typedef boost::multiprecision::cpp_int bigint;

string S;
int main() {
	cin >> S;
	cout << S.substr(0, 1) << S.size() - 2 << S.substr(S.size() - 1, 1) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

int main() {
	int n, k, r = 0;
	
	int max = 0;
	for(int i = 0; i < 3; i++) {
		scanf("%d", &n);
		if(n > max) max = n;
		r += n;
	}getchar();
	
	r -= max;
	
	scanf("%d", &k);
	for(int i = 0; i < k; i++) {
		max *= 2;
	}
	
	printf("%d\n", r + max);
	return 0;
}

Measured memory_bytes: 128
from heapq import heapify, heappop, heappush
import sys
input = sys.stdin.readline

DEBUG = False
INF = float('inf')
MAX_N = 50
MAX_A = 50

N, M, S = map(int, input().split())
U = []
V = []
A = []
B = []
C = []
D = []

connect = [[] for _ in range(N)]
for _ in range(M):
    u, v, a, b = map(int, input().split())
    U.append(u)
    V.append(v)
    A.append(a)
    B.append(b)
    connect[u-1].append([v-1, a, b])
    connect[v-1].append([u-1, a, b])
for _ in range(N):
    c, d = map(int, input().split())
    C.append(c)
    D.append(d)

if DEBUG:
    print("U: {}".format(U))
    print("V: {}".format(V))
    print("A: {}".format(A))
    print("B: {}".format(B))
    print("C: {}".format(C))
    print("D: {}".format(D))
    print("connect: {}".format(connect))

MAX_N = N
MAX_A = max(A)
MAX_MONEY = MAX_N * MAX_A
S = min(S, MAX_MONEY-1)

node = [INF for _ in range(MAX_MONEY * N)]
hq = []
heappush(hq, (0, S))
while hq:
    time, current_node = heappop(hq)
    if DEBUG:
        print("time: {}, current_node: {}, len(hq): {}".format(time, current_node, len(hq)))
    if time < node[current_node]:
        node[current_node] = time
    else:
        continue
    index_city = current_node // MAX_MONEY
    money = current_node % MAX_MONEY
    if DEBUG:
        print("money: {}".format(money))

    for index_next_city, a, b in connect[index_city]:
        if money >= a and time+b < node[index_next_city*MAX_MONEY + money-a]:
            heappush(hq, (time+b, index_next_city*MAX_MONEY + money-a))
    if money < MAX_MONEY-1:
        heappush(hq, (time+D[index_city], min(money+C[index_city], MAX_MONEY-1)+MAX_MONEY*index_city))

for i in range(1,N):
    if DEBUG:
        print("node{}: {}".format(i, node[MAX_MONEY*i:MAX_MONEY*(i+1)]))
    print(min(node[MAX_MONEY*i:MAX_MONEY*(i+1)]))


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

int pl,cn,wi,cs,r,c,p;
char f[102][52];

void init()
{
	r=0; c=0; p=0;
	memset(f,'.',sizeof(f));
}

void output()
{
	for(int i=0; i<pl; i++)
	{
		for(int j=0; j<(cn*wi+cs*(cn-1)); j++)
			cout << f[j][i];
		cout << endl;
	}
	
	cout << "#" << endl;
}

int main()
{
	while(cin >> pl, pl)
	{
	 	cin >> cn >> wi >> cs;
		
		init();
		string s;
		cin.ignore();
		while(getline(cin, s), s!="?")
		{
			p=0;
			for(int i=0; i<s.size(); i++)
			{
				if(p==wi)
				{
					r++;
					p=0;
				}
				if(r==pl)
				{
					r=0;
					c++;
				}
				if(c==cn)
				{
					output();
					init();
				}
				f[p+c*wi+cs*c][r]=s[i];
				
				p++;
			}
			
			r++;
			if(r==pl)
			{
				r=0;
				c++;
			}
			if(c==cn)
			{
				output();
				init();
			}
		}
		
		if(c!=0||r!=0||p!=0) output();
		
		cout << "?" << endl;
	}
}

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

int main() {
	int N,smallest,largest;
	cin >> N;
	int input[N];
	for(int i = 0;i<N;i++)
		cin >> input[i];
	if(input[0]>input[1]){
		largest=input[0];
		smallest=input[1];
	}
	else{
		largest=input[1];
		smallest=input[0];
	}
	for(int i = 0;i<N;i++){
		if(input[i]>largest)
			largest=input[i];
		if(input[i]<smallest)
			smallest=input[i];
	}
	cout << largest-smallest << endl;
	return 0;
}

Measured memory_bytes: 256