akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<unordered_map>
using namespace std;
int main(){
    int N;
    cin >> N;
    int K;cin >> K;
    string S;
    cin >> S;
    int ans = 0;
    bool R = false;
    bool L = false;
    bool serch = false;
    for(int i = 0;i < N-1;i++){
        if(S[i] == 'R' && S[i+1] == 'R')ans++;
        if(S[i] == 'L' && S[i+1] == 'L')ans++;
    }
    for(int i = 0;i < N;i++){
        if(serch == false && S[i] == 'R'){R = true;serch = true;}
        else if(serch == false && S[i] == 'L'){L = true;serch = true;}
        else if(R == true && S[i] == 'R' && S[i-1] == 'L'){ans+=2;R = false;L = true;K--;}
        else if(L == true && S[i] == 'L' && S[i-1] == 'R'){ans+=2;L = false;R = true;K--;}
        
        if(K == 0)break;
    }
        if (S[0] != S[N-1] && K > 0){ans++;}
    if (ans >= N)ans = N-1;
    cout << ans;
}


Measured memory_bytes: 512
while True:
    n,x=map(int,input().split())
    if n==0 and x==0:
        break
    else:
        count=0
        for i in range(1,n-1):
            for j in range(i+1,n):
                for k in range(j+1,n+1):
                    if i+j+k==x:
                        count +=1
    print(count)


Measured memory_bytes: 5592
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007;
using ll = long long;
using namespace std;

int dp[10050];
const int gs[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};

int main(){
	int n, m; cin >> n >> m;
	vector<int> match(m);
	for( auto &k : match ) cin >> k;
	fill_n( dp, 10000, -1 );
	dp[0] = 0;
	for( int i = 0; i <= n; ++i ){
		for( auto k : match ){
			dp[i+gs[k]] = max(dp[i]+1, dp[i+gs[k]]);
		}
	}
	/*
	cout << "!" << endl;
	for( int i = 0; i <= n; ++i ){
		cout << "dp[" << i << "]: " << dp[i] << endl;
	}
	*/
	vector<int> ans;
	while( n > 0 ){
		int d = -1;
		for( auto k : match ){
			if( n-gs[k] >= 0 && dp[n]-dp[n-gs[k]] == 1 ){
				d = max(d, k);
			}
		}
		ans.push_back(d);
		n -= gs[d];
	}
	sort( ans.begin(), ans.end(), greater<int>() );
	for( auto k : ans ) cout << k;
	cout << endl;
}

Measured memory_bytes: 384
import math
import collections
def f(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
c = collections.Counter(f(math.factorial((int(input())))))
d = [i[1]+1 for i in c.items()]
ans = 1
for i in range(len(d)):
    ans = (ans * d[i]) % 1000000007
print(ans)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ll;
const int INF = 1<<30;

int calc(int num, vector<int> &vec){
  int sum = 0;
  for(int i=0;i<(int)vec.size();i++){
  	sum += vec[i];
  }
  return max(0, (int)vec.size()-1)*10+abs(num-sum);
}

int main(){
  int n, a, b, c;cin>>n>>a>>b>>c;
  vector<int> bamboo(n);
  for(auto &e: bamboo)cin>>e;
  int min_cost = INF;
  for(int t=0;t<(1<<(n*2));t++){
    int cost = 0;
    vector<int> sa, sb, sc;
  	for(int i=0;i<n;i++){
      int ind = t & (3<<(i*2));
      ind = ind>>(i*2);
      if(ind==1)sa.push_back(bamboo[i]);
      else if(ind==2)sb.push_back(bamboo[i]);
      else if(ind==3)sc.push_back(bamboo[i]);
    }
    if(sa.size()*sb.size()*sc.size()==0)continue;
    cost += calc(a, sa);
    cost += calc(b, sb);
    cost += calc(c, sc);
    min_cost = min(min_cost, cost);
  }
  cout<<min_cost<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

const int maxn = 2000005 ;

int pre[maxn];
int dis[maxn];

int Find(int x)
{
     if(pre[x]==x)
        return x;

    int r=Find(pre[x]);
    dis[x]=dis[pre[x]]+dis[x];

    return pre[x]=r;
}

int Union(int x, int y, int z)
{
    int fx = Find(x);
    int fy = Find(y);

    if (fx == fy)
        return (z == dis[y] - dis[x]);

    pre[fy] = fx;

    dis[fy] = dis[x] + z - dis[y];

    return 1;
}

int x[maxn];
int y[maxn];
int z[maxn];

int main()
{
    int n, m;
    int flag = 1;

    cin >> n >> m;

    for (int i = 1; i <= n; i++)
        pre[i]=i;

    for (int i = 1; i <= m; i++)
    {
        cin >> x[i] >> y[i] >> z[i];
    }

    for(int i =1;i<=m;i++)
    {
        flag = Union(x[i], y[i], z[i]);
        if(flag == 0)
            goto end;
    }

end:
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 13312
#include <bits/stdc++.h>
using namespace std;
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; }
const long long INF = 1LL<<60;

int main() {
    // 入力
    int z = 3;
    int N;
    long long W, weight[110], value[110]; // 品物の個数は 100 個なので少し余裕持たせてサイズ 110 に

    // DPテーブル
    long long dp[110][100100] = {0};
    cin >> N >> W;
    for (int i = 0; i < N; ++i) cin >> weight[i] >> value[i];

    // DPループ
    for (int i = 0; i < N; ++i) {
        for (int sum_w = 0; sum_w <= W; ++sum_w) {

            // i 番目の品物を選ぶ場合
            if (sum_w - weight[i] >= 0) {
                chmax(dp[i+1][sum_w], dp[i][sum_w - weight[i]] + value[i]);
            }

            // i 番目の品物を選ばない場合
            chmax(dp[i+1][sum_w], dp[i][sum_w]);
        }
    }

    // 最適値の出力
    cout << dp[N][W] << endl;
}

Measured memory_bytes: 86272
#include <iostream>
#include <vector>
#define rep(i, n) for(i = 0; i < n; i++)

using namespace std;

const int N = 1e5 + 10;

struct UF {
	int par[N];
	int sz[N];
	UF() { 
	   int i; 
	   rep(i, N) {
	       par[i] = i; sz[i] = 1; 
	   } 
	}
	int root(int x) {
	  if (par[x] == x) return x; 
	  return par[x] = root(par[x]); 
	}
	void unit(int a, int b) {
		a = root(a);
		b = root(b);
		if (a == b) return;
		par[a] = b;
		sz[b] += sz[a];
	}
	int getSz(int x) {
	    return sz[root(x)]; 
	}
	bool same(int a, int b) {
	    return root(a) == root(b); 
	}
};

int n, m, k;
vector<int> fri[N];
vector<int> blo[N];
UF uf;

int main() {
	int i, j;
	
	cin >> n >> m >> k;
	rep(i, m) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		fri[a].push_back(b);
		fri[b].push_back(a);
		uf.unit(a, b);
	}
	rep(i, k) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		blo[a].push_back(b);
		blo[b].push_back(a);
	}
	
	vector<int> ans;
	rep(i, n) {
		int res = uf.getSz(i) - (int)fri[i].size() - 1;
		rep(j, blo[i].size()) {
			int x = blo[i][j];
			if (uf.same(i, x)) res--;
		}
		ans.push_back(res);
	}
	
	rep(i, ans.size()) {
		cout << ans[i];
		if (i + 1 < ans.size()) cout << " ";
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 13432
#include <iostream>
#include <string>
#include <vector>

int max(int x, int y)
{
	return x>y ? x : y;
}

std::string sadd(std::string str_a, std::string str_b)
{
	// padding
	while (str_a.size() > str_b.size()) str_b.insert(0, "0");
	while (str_b.size() > str_a.size()) str_a.insert(0, "0");
	
	std::string res(str_a);
	int carry = 0;
	for (int i=res.size()-1; i>=0; i--) {
		res[i] += str_b[i] - 48 + carry;
		if (res[i] > '9') {
			res[i] -= 10;
			carry = 1;
		}
		else carry = 0;
	}
	if (carry==1) res.insert(0, "1");
	
	// std::cout << str_a << "," << str_b << "," << res << std::endl;
	
	return res;
}

int main ()
{
	std::string eq;
	while (getline(std::cin, eq)) {
		int pos_plus  = eq.find('+');
		int pos_equal = eq.find('=');
		
		std::vector<int> Xpos;
		for (int pos=0; pos < eq.size(); pos++) {
			if ( eq[pos] == 'X' ) Xpos.push_back(pos);
		}
		
		int ans = -1;
		for (int x=0; x<10; x++) {
			std::string eq_cpy(eq);
			for (std::vector<int>::iterator it = Xpos.begin(); it != Xpos.end(); ++it) {
				// size_type pos, size_type n1, size_type n2, charT c
				eq_cpy.replace((*it), 1, 1, (char)(x+48));
			}
			std::string str_a = eq_cpy.substr(0, pos_plus);
			std::string str_b = eq_cpy.substr(pos_plus + 1, pos_equal - pos_plus - 1);
			std::string str_c = eq_cpy.substr(pos_equal + 1);
			
			if (str_a.size() > 1 && str_a[0] == '0' || str_b.size() > 1 && str_b[0] == '0' || str_c.size() > 1 && str_c[0] == '0') continue;

			// std::cout << x << " : " << a << "," << b << "," << c << std::endl;
			
			if ( sadd(str_a, str_b) == str_c ) {
				ans = x; break;
			}
		}
		
		if (ans >= 0) std::cout << ans << std::endl;
		else std::cout << "NA" << std::endl;
	}
	
	return 0;
}




Measured memory_bytes: 3148
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np
# from numpy import cumsum  # accumulate

def solve():
    a = input()
    if a.islower():
        print('a')
    else:
        print('A')

if __name__ == '__main__':
    solve()


Measured memory_bytes: 9152
a,b,c = map(int,input().split())

count=0
while a%2==0 and b%2==0 and c%2==0:
    if (b/2+c/2)==(a/2+c/2)==(a/2+b/2):
        count=-1
        break
    a,b,c = b/2+c/2,a/2+c/2,a/2+b/2
    count+=1
print(count)


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

#define F first
#define S second
#define prev azaza
#define MP make_pair
#define PB push_back

using namespace std;
typedef long long ll;
typedef long double ld;

const int max_n = 211, inf = 1000111222;

vector<int>v[max_n];

int col[max_n];

int n;
void dfs(int cur) {
    for (int to : v[cur]) {
        if (col[to] != -1) {
            if (col[to] == col[cur]) {
                cout << -1 << endl;
                exit(0);
            }
            continue;
        }
        col[to] = (col[cur] == 1 ? 0 : 1);
        dfs(to);
    }
}
int d[max_n];
int bfs(int from) {
    for (int i = 0; i < max_n; ++i) {
        d[i] = inf;
    }
    d[from] = 0;
    queue<int> q;
    q.push(from);
    while (!q.empty()) {
        int cur = q.front();
        q.pop();
        for (int to : v[cur]) {
            if (d[to] == inf) {
                d[to] = d[cur] + 1;
                q.push(to);
            }
        }
    }
    int mx = 0;
    for (int i = 0; i < n; ++i) {
        mx  = max(mx, d[i]);
    }
    return mx + 1;
}

int main()
{
    //freopen("input.txt", "r", stdin);
    cin >> n;
    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        for (int j = 0; j < n; ++j) {
            if (s[j] == '1') {
                v[i].PB(j);
            }
        }
    }
    for (int i = 0; i < n; ++i) {
        col[i] = -1;
    }
    col[0] = 0;
    dfs(0);
    int ans = -1;
    for (int i = 0; i < n; ++i) {
        ans = max(ans, bfs(i));
    }
    cout << ans << endl;
    return 0;
}




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

#define MAX 100010

using namespace std;

struct node{
  int index;
  int way = 0;
  vector <int> room;
};

void printans(vector <node>& cavemap, int& cnt, int& N)
{
  if (cnt < N - 1)
    cout << "No" << '\n';
  else{
    cout << "Yes" << '\n';
    for (int i = 2; i <= N; i++)
      cout << cavemap[i].way << '\n';
  }
}

void findans(vector <node>& cavemap, int& cnt, int& N,
	     queue <int>& temp, int index)
{
  if (temp.size() != 0)
    temp.pop();
  if (cnt > N - 1)
    return;
  int length = cavemap[index].room.size();
  for (int i = 0; i < length; i++)
    if (cavemap[cavemap[index].room[i]].way == 0){
      cavemap[cavemap[index].room[i]].way = index;
      temp.push(cavemap[index].room[i]);
      cnt++;
    }
  if (temp.size() == 0)
    return;
  findans(cavemap, cnt, N, temp, temp.front());
}

int main(void)
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M, cnt = 0, a, b;;
  cin >> N >> M;
  vector <node> cavemap(MAX);
  for (int i = 0; i < M; i++){
    cin >> a >> b;
    cavemap[a].index = a;
    cavemap[b].index = b;
    cavemap[a].room.push_back(b);
    cavemap[b].room.push_back(a);
  }
  queue <int> temp;
  findans(cavemap, cnt, N, temp, 1);
  printans(cavemap, cnt, N);
  return 0;
}


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

using namespace std;

using ll = long long;
using db = double;
using vi = vector<int>;

ll n; 
ll a[1000000]; 
ll l[1000000]; 
ll r[1000000]; 
multiset<ll> S; 

int main() {
	cin>>n; 
	for (int i = 1; i <= 3*n; ++i) scanf("%lld", &a[i]); 
	ll sum = 0; 
	for (int i = 1; i <= n; ++i) {
		S.insert(a[i]); 
		sum += a[i];
	} 
	for (int i = n; i <= 2*n; ++i) {
		l[i] = sum; 
		//cout<<i<<' '<<l[i]<<endl; 
		sum += a[i+1]; 
		S.insert(a[i+1]); 
		sum -= *S.begin(); 
		S.erase(S.begin()); 
	}
	//cout<<endl; 
	reverse(a+1,a+n*3+1); 
	S.clear(); 
	sum = 0; 
	for (int i = 1; i <= n; ++i) {
		S.insert(a[i]); 
		sum += a[i];
	} 
	for (int i = n; i <= 2*n; ++i) {
		r[i] = sum; 
		//cout<<i<<' '<<r[i]<<endl; 
		sum += a[i+1]; 
		S.insert(a[i+1]); 
		sum -= *S.rbegin(); 
		S.erase(prev(S.end())); 
	}
	//cout<<endl; 
	ll ans = -0x3f3f3f3f3f3f3f3fll; 
	for (int i = n; i <= 2*n; ++i) ans = max(ans, l[i]-r[3*n-i]); 
	cout<<ans<<endl; 
}


Measured memory_bytes: 11904
#include <bits/stdc++.h>
#define int long long
using namespace std;
#define mod 1000000007
#define FAST                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);
bool vis[200005];
vector<int> vec[2000005], v1;
int child[2000005];
int parent[2000005];
int div1[100005];
int min_indx[200005];
int count1 = 0;
int height = 0;
int max_indx[200005];
void dfs(int node)
{

    vis[node] = 1;

    min_indx[count1] = node;
    max_indx[node] = min(max_indx[node], count1);
    count1++;

    //  count1++;
    child[node] = height++;
    for (int i = 0; i < vec[node].size(); i++)
    {
        if (!vis[vec[node][i]])
        {
            dfs(vec[node][i]);
            min_indx[count1] = node;
            max_indx[node] = min(max_indx[node], count1);
            count1++;
        }
    }
    height--;
}
int MAXN = 200005;
int LOGMAXN = (int)log2(200005) + 1;
int M[200005][60];
int ans[200005];
void fun(int a, int b, int c)
{
    //ll val = 1;

    while (a <= b)
    {
        ans[a] += c;
        int p = -a;
        a += (a & p);
    }
}
int find1(int a)
{
    int sum = 0;
    while (a != 0)
    {
        sum += ans[a];
        int p = -a;
        a -= (a & p);
    }
    return sum;
}
void process2(int A[], int N)
{
    int i, j;

    for (i = 0; i < N; i++)
        M[i][0] = i;
    for (j = 1; 1 << j <= N; j++)
        for (i = 0; i + (1 << j) - 1 < N; i++)
            if (find1(M[i][j - 1]) < find1(M[i + (1 << (j - 1))][j - 1]))
                M[i][j] = M[i][j - 1];
            else
                M[i][j] = M[i + (1 << (j - 1))][j - 1];
}
int arr1[1000005], arr2[1000005];
int32_t main()
{
    FAST;
    string str;
    cin >> str;
    int one = 0;
    for (int i = 0; i < str.length(); i++)
    {
        if (str[i] == '1')
            one++;
    }
    cout << one << "\n";
    return 0;
}

Measured memory_bytes: 50500
#include <algorithm>
#include <functional>
#include <iostream>
//#include <bits/stdc++.h>
using namespace std;

int main() {

	int N,K;
	int L[60];
	cin >> N >> K;
	int ans = 0;

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

	}

	sort(L,L+N,greater<int>());

	for (int i = 0; i < K; i++)
	{
		ans += 	L[i];
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
 
using namespace std;
//using namespace __gnu_pbds;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int long long 
#define rep(i,n) for(int i=0;i<n;i++)
#define repa(i,arr,n) for(int i=arr;i<=n;i++)
#define repd(i,arr,n) for(int i=arr;i>=n;i--)
#define trav(arr,x) for(auto& arr:x)
#define all(c) c.begin(), c.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(arr) arr.size()
#define pi 3.14159265358979323846
#define MAX 500003
#define vi vector<int>
#define pii pair<int,int>
#define pqueue priority_queue<int>
#define pdqueue priority_queue<int,vi,greater<int> >
//#define endl "\n"
 
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
 
const int mod=998244353;
int power(int a,int b)
{
    int ans=1;
    while(b)
    {
        if(b&1)
        {
            ans=(ans*a)%mod;
        }
        a=(a*a)%mod;
        b>>=1;
    }
    return ans;
}

int32_t main()
{
    fast;
    int n,m,c,val;
    cin>>n>>m>>c;

    vi a,b;
    int sum=0;
    rep(i,n)
    {
        cin>>val;
        sum+=val;
        a.pb(sum);
    }
    sum=0;
    rep(i,m)
    {
        cin>>val;
        sum+=val;
        b.pb(sum);
    }

    int ans=upper_bound(all(a),c)-a.begin();
    //cout<<ans<<endl;
    rep(i,m)
    {
        int cc=c-b[i];
        if(cc<0) break;
        //cout<<c<<endl;
        val=upper_bound(all(a),cc)-a.begin();
        ans=max(ans,val+i+1);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 7944
#include <stdlib.h>
#include <stdio.h>

int fib(int n){
int i;
int a[44];
a[0]=a[1]=1;
for(i=2;i<=n;i++){
a[i]=a[i-1]+a[i-2];
   }
return a[n];
}

int main(){

int x,n;
scanf("%d",&n);
x=fib(n);
printf("%d\n",x);

return 0;
}

Measured memory_bytes: 2752
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

const int MXN=300;
long double dp[MXN+1][MXN+1][MXN+1];
bool vis[MXN+1][MXN+1][MXN+1];
int n;
long double solve(int a,int b,int c){
	if( a==0 && b==0 && c==0)return 0;
	if( vis[a][b][c] ){
		return dp[a][b][c];
	}
	vis[a][b][c]=1;
	dp[a][b][c]=0;
	long double tot = a + b + c ;
	dp[a][b][c]+=((long double)n/(long double)tot);
	if(a)dp[a][b][c]+=((long double)a/(long double)tot)*solve(a-1,b,c);
	if(b)dp[a][b][c]+=((long double)b/(long double)tot)*solve(a+1,b-1,c);
	if(c)dp[a][b][c]+=((long double)c/(long double)tot)*solve(a,b+1,c-1);
	return dp[a][b][c];
}
	
int32_t main()
{
   IOS
   cin>>n;
   vector<int>v(4);
   for(int i=0;i<n;i++)
   {
	   int x;cin>>x;
	   v[x]++;
   }
   memset(vis,false,sizeof(vis));
   for(int i=0;i<=MXN;i++)
   for(int j=0;j<=MXN;j++)
   for(int k=0;k<=MXN;k++)
   dp[i][j][k]=0;
   cout << fixed << setprecision(10)  << solve(v[1],v[2],v[3]) << endl;
   
   
	  
}


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

using namespace std;

typedef long long LL;

const int N = 110;

int res;
int n;

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

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
typedef long long int ll;
#define int ll
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}

int a[2*maxn];
int b[2*maxn];


int32_t main(){
	fastio();
	int n , m , k;

	cin >> n >> m >> k;

	for(int i = 0;i < n;i++){
		cin>>a[i];
		if(i) a[i]+=a[i-1];
	}
	for(int i = 0; i < m;i++){
		cin >> b[i];
		if(i) b[i] += b[i-1];
	}
	int ans1 = 0;
	for(int i = 0; i < n; i++){
		if(a[i]<=k){
			int left = k - a[i];
			int t = lower_bound(b,b+m , left) - b;
			if(t==0){
				if(b[t]==left) t = 1;
				ans1 = max(ans1,i+1 + t);
			}else{
				if(b[t]==left) t+=1;
				ans1 = max(ans1,i + 1 + t);
			}
		}
	}

	int t = lower_bound(b,b+m,k) - b;
	if(b[t]==k) t+=1;
	ans1 = max(ans1,t);
	cout << ans1;
}

Measured memory_bytes: 6728
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N; cin >> N;
    int cnt = 0, ans =1;
    for (int i=1; i<= N; ++i){
        if (pow(2, (int)log2(i))==i) ans = i;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4020
# import sys;input = lambda : sys.stdin.readline()
import collections
d=collections.defaultdict(lambda:0)
for _ in range(int(input())):
    s=input()
    d[s]+=1
print("AC x",d['AC'])
print("WA x",d['WA'])
print("TLE x",d["TLE"])
print("RE x",d['RE'])


Measured memory_bytes: 9476
def resolve():
    import numpy as np
    n=int(input())
    x_base=list(map(int,input().split()))
    x_base.sort()
    x=np.array(x_base)
    ans=10**10
    for i in range(x[0],x[-1]+1):
        if sum((x-i)**2) <=ans:
            ans=sum((x-i)**2)
    print(ans)
resolve()


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

using namespace std;

int nice_shopping(vector<int>& a, vector<int>& b, vector<int>& x, vector<int>& y, vector<int>& c) {
	int cost = *min_element(a.begin(), a.end()) + *min_element(b.begin(), b.end());
	for (int i = 0; i < c.size(); i++)
		cost = min(a[x[i] - 1] + b[y[i] - 1] - c[i], cost);
	return cost;
}

int main() {
	int A, B, M;
	cin >> A >> B >> M;
	vector<int> a(A), b(B), x(M), y(M), c(M);
	for (int i = 0; i < A; i++)
		cin >> a[i];
	for (int i = 0; i < B; i++)
		cin >> b[i];
	for (int i = 0; i < M; i++)
		cin >> x[i] >> y[i] >> c[i];
	cout << nice_shopping(a, b, x, y, c);
	return 0;
}

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

int main(){
  int N;
  cin >> N;

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

  for(int i = max(N, static_cast<int>(max(s.length(), t.length()))); i <= s.length() + t.length(); i++){
    bool ok = true;
    for(int j = 0; j < i; j++){
      if(j < s.length() && j >= i - t.length() && s[j] != t[j - (i - t.length())]){
        ok = false;
      }
    }
    if(ok){
      cout << i << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
from sys import stdin
import numpy as np



############################################

# read data for n sequences.
temp = stdin.readline().split()
N, M = np.asarray(temp).astype(int)
temp = stdin.readline().split()
a = np.asarray(temp).astype(int)

sumvotes = np.sum(a)

c = 0; OUT = False
for data in a:
    if data >= sumvotes/(4*M):
        c += 1
    if c >= M:
        OUT = True
        #break

if OUT:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 18484
x=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
y=int(input())
print(x[y-1])

Measured memory_bytes: 3316
// LL(3)

#include <cctype>
#include <cstdio>
#include <cassert>
#include <cstring>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

typedef long long ll;

const int M=1000000007;

int len;
char s[2000010];

int idx;

int expr();

int number(){
	int a=0;
	assert(isdigit(s[idx]));
	while(isdigit(s[idx])) a=10*a+(s[idx++]-'0');
	return a;
}

int term(){
	if(isdigit(s[idx])){
		return number();
	}
	else{
		assert(s[idx++]=='S');
		assert(s[idx++]=='<');
		int a=expr();
		assert(s[idx++]=='>');
		return ((ll)a*a)%M;
	}
}

int expr(){
	int a=term();
	while(s[idx]=='>'
		&& idx+1<len && s[idx+1]=='>'
		&& idx+2<len && (s[idx+2]=='S' || isdigit(s[idx+2]))
	){
		idx+=2;
		int b=term();
		if(b<32) a>>=b;
		else     a=0;
	}
	return a;
}

int main(){
	for(;fgets(s,2000010,stdin),s[0]!='#';){
		len=strlen(s)-1;
		s[len]='\0';

		// trim spaces
		int k=0;
		rep(i,len) if(s[i]!=' ') s[k++]=s[i];
		len=k;
		s[len]='\0';

		idx=0;
		printf("%d\n",expr());
	}

	return 0;
}

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

int main(void) {
  long long n, k;
  cin >> n >> k;
  vector<long long> a(n), b(n);
  vector<pair<int,int>> p;
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
    p.emplace_back(a[i], b[i]);
  }

  sort(p.begin(), p.end());

  long long c = 0;
  for (int i = 0; i < n; i++) {
    long long aa = p[i].first;
    long long bb = p[i].second;
    if (k <= c + bb) {
      cout << aa << endl;
      return 0;
    }
    c += bb;
  }

  return 0;
}

Measured memory_bytes: 2936
#include <stdio.h>
int main(void)
{
	int i, no;
	int submited[31];

	for(i=0; i<=30; i++)
		submited[i] = 0;
	
	for(i=0; i<28; i++)
	{
		scanf("%d", &no);
		submited[no]=1;
	}

	for(i=1; i<=30; i++)
		if( !submited[i] )
			printf("%d\n", i);

	return 0;
}

Measured memory_bytes: 596
n,k = map(int,input().split())
td = [list(map(int,input().split())) for i in range(n)]
td.sort(key=lambda x:x[1],reverse=True)
a = 0
ans = []
kind = [-1]*n
c = 0
min_p = []
for i in range(n):
    eat = False
    if i<k:
        a += td[i][1]
        eat = True
    else:
        if min_p:
            if kind[td[i][0]-1]<0:
                a -= (min_p.pop()-td[i][1])
                a += (c+1)**2-c**2
                ans.append(a)
                eat = True
    if eat:
        if kind[td[i][0]-1]<0:
            kind[td[i][0]-1]=1
            c+=1
        else:min_p.append(td[i][1])
    if i==k-1:
        a += c**2
        ans.append(a)
print(max(ans))

Measured memory_bytes: 29056
#include<bits/stdc++.h>
using namespace std;
#define INF 1e9 + 5

int main(){
	int n;
	cin >> n;
	vector<int> h(n);
	for(int i = 0; i < n; i++){
		cin >> h[i];
	}
	vector<int> dp(n, INF);
	dp[0] = 0;
	for(int i = 0; i < n; i++){
		for(int j = 1; j < 3; j++){
			if(i - j >= 0){
				dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
			}
		}
	}
	cout << dp[n-1] << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 200010;

// aのn乗を求める。計算量はO(logn)
ll modpow(ll a, ll n) {
    if(n == 0) {
        return 1;
    }
    if(n%2 == 1) {
        return (a * modpow(a, n-1))%mod;
    }
    return (modpow(a, n/2) * modpow(a, n/2))%mod;
}

ll inverse(ll a) {
    return modpow(a, mod-2);
}

ll inv[MAX_N];
ll fact[MAX_N];  // fact[i] : iの階乗のmod
ll invfact[MAX_N];

// main関数でinit()を呼び出してからComb()を使用する
void init() {
    inv[0] = fact[0] = invfact[0] = 1;
    inv[1] = 1;
    for(ll i = 1; i < MAX_N; i++) {
        if(i >= 2) {
            inv[i] = mod - inv[mod%i]*(mod/i)%mod;
        }
        fact[i] = (i * fact[i-1])%mod;
        invfact[i] = inverse(fact[i]);
    }
}

//--- main関数でinit()を呼び出すのを忘れるな ---//
int main() {
    ll n;
    cin >> n;

    vl x(n);
    rep(i, n) {
        cin >> x[i];
    }

    init();

    ll u = 0;
    ll ans = 0;
    rep(i, n-1) {
        u += inv[i+1];
        u %= mod;
        ans += (x[i+1] - x[i])*u%mod;
        ans %= mod;
    }
    ans *= fact[n-1];
    ans %= mod;

    out(ans);
    re0;
}

Measured memory_bytes: 5760
n,k = map(int, input().split())
p = list(map(int, input().split()))
c = list(map(int, input().split()))
l = []
check = [True]*n
for i in range(1,n+1):
    if (check[i-1]==True):
        s = i
        sl = []
        tnp = i
        for j in range(n):
            tnp = p[tnp-1]
            check[tnp-1] = False
            sl.append(c[tnp-1])
            if (tnp==s):
                break
        l.append(sl)
#print(l)
ans = -float("inf")
for i in range(len(l)):
    if (len(l[i])<=k):
        if (sum(l[i])>0):
            x = k%len(l[i])
            if (x==0):
                tnp = 0
            else:
                tnp = -float("inf")
            for p in range(1,x+1):
                wa = sum(l[i][:p])
                tnp = max(tnp,wa)
                for j in range(len(l[i])):
                    wa -= l[i][j]
                    wa += l[i][(j+p)%len(l[i])]
                    tnp = max(tnp,wa)
            ans = max(ans, tnp + sum(l[i])*(k//len(l[i])) )
    tnp = -float("inf")
    for p in range(1,min(k,len(l[i]))+1):
        wa = sum(l[i][:p])
        tnp = max(tnp,wa)
        for j in range(len(l[i])):
            wa -= l[i][j]
            wa += l[i][(j+p)%len(l[i])]
            tnp = max(tnp,wa)
    ans = max(ans, tnp)
    if (len(l[i])<=k and sum(l[i])>0):
        ans = max(ans, tnp+sum(l[i])*(k//len(l[i])-1))
print(ans)
            

Measured memory_bytes: 69988
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;}

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

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

int main(){
  long long int N,A,B;
  cin >> N >> A >> B;
  
  if(A == 0 || N == 0){cout << 0 << endl; return 0;}
  if(B == 0){cout << N << endl; return 0;}
  if(A == 0 && B == 0){cout << 0 << endl; return 0;}
  if(N <= A + B){
    if(N < A){
      cout << N << endl; return 0; 
    }
    else{
      cout << A << endl; return 0;
    }
  }

  long long int ans = 0,tmp = N / (A+B),r = N-(tmp * (A+B));
  if((tmp * (A+B)) < N){
    if(r > A)
      ans = tmp * A + A;
    else
      ans = tmp * A + r;
  }else{
    if(r > A)
      ans = tmp * A;
    else
      ans = tmp * A + r;
  }


  cout << ans << endl;

}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
typedef long long ll;

int n;
int x[10],y[10];

double dist(int i,int j) {
    double dx = x[i] - x[j];
    double dy = y[i] - y[j];
    return pow(dx * dx + dy * dy, 0.5);
}

int main() {
    cin >> n;
    rep1(i,n+1) cin >> x[i] >> y[i];
    double sum = 0.0;
    vector<int> v(n);
    rep(i,n) v[i] = i+1;
    do{
        for(int i = 0; i < n-1; i++){
            sum += dist(v[i],v[i+1]);
        }
    }while(next_permutation(v.begin(),v.end()));
    int num = 1;
    for(int i = 1; i <= n; i++) num *= i;
    
    cout << fixed << setprecision(10) << sum / num << endl;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define ft first
#define sd second
#define ue printf("what?\n");
#define pb push_back
#define oo 0x3F3F3F3F	
#define OO 3000000000000000000LL
#define EPS 0
#define maxn 200000
#define pi acos(-1)
#define mod 1000000007
#define mdc __gcd
#define N 100010
#define M 33
using namespace std;
typedef long long ll;
typedef vector<vector<ll> > mat;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;

vi g[N];

main()
{
	int n, m, i, a, b, ans, mn, j;
	scanf("%d%d", &n, &m);
	for(i=0; i<m; i++)
		scanf("%d%d", &a, &b), g[a].pb(b);
	ans = 0, mn = oo;
	for(i=1; i<=n; i++)
	{
		if(mn == i) ans++, mn = oo;
		for(j=0; j<g[i].size(); j++)
			mn = min(mn, g[i][j]);
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 5760
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;

#define rep(i,N) for(int i=0;i<(int)N;++i)

ll GCD(ll x, ll y) {
    if (y == 0) return x;
    else return GCD(y, x % y);
}


#include <iostream>

int main()
{
    int a, b, c, d;
    cin >> a >> b >> c>> d;

    if (abs(a - c) <= d) { cout << "Yes" << endl; }
    else {
        if (abs(a - b) <= d && abs(b - c) <= d) { cout << "Yes" << endl; }
        else { cout << "No" << endl; }
    }
}


Measured memory_bytes: 256
int main(){
  char s[3],t[3];
  for(int i = 0;i<3;i++){
    scanf("%c",&s[i]);
  }
  scanf("\n");
  for(int i = 0;i<3;i++){
    scanf("%c",&t[i]);
  }
  int a = 0;
  for(int i = 0;i<3;i++){
    if (s[i]==t[i]){
      a++;
    }
  }
  printf("%d\n",a);
    return 0;
}

Measured memory_bytes: 128
//g++  5.4.0

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


int main()
{
  
    long int n,k,i,hi;
    cin>>n>>k;
    
    long int c=0;
    for(i=0;i<n;i++){cin>>hi;
                     if(hi>=k)c++;
                    }
    cout<<c;
   
}

Measured memory_bytes: 256
/*{{{*/
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB emplace_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int N,M,Q;
int a[52],b[52],c[52],d[52],A[52];
int an;
void dfs(int id,int v){
    if(id>N){
        int now=0;
        REP(i,Q){
            if(A[b[i]]-A[a[i]]==c[i])now+=d[i];
        }
        an=max(an,now);
        return;
    }
    FOR(i,v,M){
        A[id]=i;
        dfs(id+1,i);
    }
}
int main(){
    R(N,M,Q);
    REP(i,Q){
        R(a[i],b[i],c[i],d[i]);
    }
    dfs(1,1);
    W(an);
    return 0;
}


Measured memory_bytes: 3824
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>
#define pb push_back

#define mp make_pair
#define all(a) (a).begin(),(a).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; }

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

const int MAX = 1e6+1;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(ll n, ll k){
  if(n >= MAX){
    ll tmp = 1;
    rep(i,k){
      tmp *= (n-i);
      tmp %= MOD;
    }
    return tmp*finv[k]%MOD;
  }

  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll POW(ll x, ll n){
  ll ret = 1;

  if(n < 0){// n < 0 にも対応
    n *= -1;
    x = inv[x];
  }

  while(0 < n){
    if(n%2 == 0){
      x = x*x%MOD;
      n /= 2;
    }
    else{
      ret = ret*x%MOD;
      n--;
    }
  }

  return ret;
}

vi MP(string s){
  vi A(s.size()+1);
  A[0] = -1;
  int j = -1;
  rep(i,s.size()) {
    while(j >= 0 && s[i] != s[j]) j = A[j];
    j++;
    A[i+1] = j;
  }
  return A;
}

vi Manacher(string s){
  vi R(s.size());
  int i = 0, j = 0;
  while(i < s.size()){
    while(i-j >= 0 && i+j < s.size() && s[i-j] == s[i+j]) ++j;
    R[i] = j;
    int k = 1;
    while(i-k >= 0 && i+k < s.size() && k+R[i-k] < j) R[i+k] = R[i-k], k++;
    i += k; j -= k;
  }
  return R;
}

vi Z_algorithm(string &s){
  vi Z(s.size());
  Z[0] = s.size();
  int i = 1, j = 0;
  while(i < s.size()){
    while(i+j < s.size() && s[j] == s[i+j]) j++;
    Z[i] = j;
    if(j == 0){++i; continue;}
    int k = 1;
    while(i+k < s.size() && k+Z[k] < j) Z[i+k] = Z[k], ++k;
    i += k; j -= k;
  }
  return Z;
}

int main(){
  int n; string s;
  cin >> n >> s;
  int ans = 0;
  rep(i,n) {
    string t = s.substr(i);
    vi z = Z_algorithm(t);
    rep(j,t.size()) {
      int l = min(z[j],j);
      chmax(ans, l);
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 384
using System;

class Small_Large_Equal{
    static void Main(){
        string[] str = Console.ReadLine().Split(' ');
        
        var a = int.Parse(str[0]);
        var b = int.Parse(str[1]);
        
        if(a > b)
        {
            Console.WriteLine("a > b");
        }
        else if(a < b)
        {
            Console.WriteLine("a < b");
        }
        else {
            Console.WriteLine("a == b");
        }
    }
}

Measured memory_bytes: 8800
class UnionFind:
    def __init__(self, n):
        self.table = [-1] * n

    def _root(self, x):
        stack = []
        tbl = self.table
        while tbl[x] >= 0:
            stack.append(x)
            x = tbl[x]
        for y in stack:
            tbl[y] = x
        return x

    def find(self, x, y):
        return self._root(x) == self._root(y)

    def unite(self, x, y):
        r1 = self._root(x)
        r2 = self._root(y)
        if r1 == r2:
            return
        d1 = self.table[r1]
        d2 = self.table[r2]
        if d1 <= d2:
            self.table[r2] = r1
            self.table[r1] += d2
        else:
            self.table[r1] = r2
            self.table[r2] += d1

    def get_size(self, x):
        return -self.table[self._root(x)]


n, m = map(int, input().split())
uft = UnionFind(n + m)
for i in range(n):
    k, *lll = map(int, input().split())
    for l in lll:
        uft.unite(i, l + n - 1)

for j in range(1, n):
    if not uft.find(0, j):
        print('NO')
        break
else:
    print('YES')


Measured memory_bytes: 15588
N, M = map(int, input().split())
An = list(map(int, input().split()))

An = sorted(An, reverse=True)

goukei = sum(An)
keisan = goukei * (1 / (4 * M))

flag = True

for i in range(M):
  if An[i] < keisan:
    flag = False
    print('No')
    break
  
if flag is True:
  print('Yes')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
using namespace std;

typedef long long ll;
typedef double db;
typedef long double ldb;

template<class T> inline void checkmin(T &a,const T &b){if(b<a) a=b;}
template<class T> inline void checkmax(T &a,const T &b){if(b>a) a=b;}

const int inf=1e9+10;

int a,b,c,d;

int main(){
	scanf("%d%d%d%d",&a,&b,&c,&d);
	for(int i=0;;i++){
		if(i%2==1){
			a-=d;
			if(a<=0){
				printf("No\n");
				return 0;
			}
		}
		else{
			c-=b;
			if(c<=0){
				printf("Yes\n");
				return 0;
			}
		}
	//	cout<<a<<" "<<c<<endl;
	}
	return 0;
}


Measured memory_bytes: 3732
#include <stdio.h>


int main()
{
	int ret;

	int A, B;
	ret = scanf("%d %d", &A, &B);

	int diff = A - B;
	if (diff % 2 == 0) {
		int K = (A + B) / 2;
		printf("%d", K);
	}
	else {
		printf("IMPOSSIBLE");

	}

	return 0;
}


Measured memory_bytes: 128
A = []
A = map(int, raw_input().split(' '))
pow = [1, 2, 4, 8]

N = int(raw_input())
N *= 4

for i in range(len(A) - 1):
	A[i + 1] = min(A[i] * 2, A[i + 1])

res = 0
for i in range(len(A) - 1, -1, -1):
	floor = N / pow[i]
	res += floor * A[i]
	N %= pow[i]

print res

Measured memory_bytes: 2692
#include <iostream>
#include <cstdlib>
#include <string>
#include <cstdio>
using namespace std;

int main() {
    string s;
    int y, m, d;
    cin >> s;
    sscanf(s.substr(0,4).c_str(), "%d", &y);
    sscanf(s.substr(5,2).c_str(), "%d", &m);
    sscanf(s.substr(8,2).c_str(), "%d", &d);
    if (y > 2020) cout << "TBD" << endl;
    else if (y == 2019 && m >= 5) cout << "TBD" << endl;
    else cout << "Heisei" << endl;
    return 0;
}

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

using namespace std;

int main()
{
    int n,d;
    while(scanf("%d%d",&n,&d)!=EOF)
    {
        int a=2*d+1;
        int ans=n/a;
        if(n%a!=0)
            ans++;
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using itn = int;
using namespace std;
int GCD(int a, int b){
    return b ? GCD(b, a%b) : a;
}
int main(){
    string s;
    cin >> s;
    bool ok = true;
    for(int i=0; i<s.size();){
        if(s.substr(i,11)=="dreameraser"){
            i+=11;
            continue;
        }else if(s.substr(i,10)=="dreamerase"){
            i+=10;
            continue;
        }else if(s.substr(i,7)=="dreamer"){
            i+=7;
            continue;
        }else if(s.substr(i,5)=="dream"){
            i+=5;
            continue;
        }else if(s.substr(i,6)=="eraser"){
            i+=6; 
            continue;
        }else if(s.substr(i,5)=="erase"){
            i+=5;
            continue;
        }else{
            ok = false;
            break;
        }
    }
    if(ok) puts("YES");
    else puts("NO");
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
string s;
void die()
{
	puts("No");
	exit(0);
}
int main()
{
	cin>>s;
	for(int i=0;i<s.size();i++)
	{
		if(i%2&&s[i]=='R')
			die();
		if(i%2==0&&s[i]=='L')
			die();
	}
	puts("Yes");
	return 0;
}

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


int main() {
    int N,M;

    cin >> N >> M;
    vector<int> vec(N);
    for(int i=0;i<M;++i){
      int a,b; cin >> a >> b;
      vec.at(a-1)++;
      vec.at(b-1)++;
    }
    for(int i=0;i<N;++i){
      cout << vec.at(i) << endl;
    }
    return 0;
}


Measured memory_bytes: 3616
#include "bits/stdc++.h"

using namespace std;

struct Card
{
    string suit_value;
    char suit;
    int value;
    int original_position;
    
};

bool IsStable(Card cards[], int n) {
    bool is_stable = true;
    for (int i = 0; i < n - 1; i++) {
    
        for (int j = i + 1; j < n; j++) {
            if (cards[j].value != cards[i].value) break;
            if (cards[j].value == cards[i].value && cards[j].original_position < cards[i].original_position) is_stable = false;
            if (!is_stable) break;
        }
        if (!is_stable) break;
    }
    return is_stable;
}
    
bool BubbleSort(Card cards[], int n) {
    bool is_stable = true;
    for (int i = 0; i < n; i++) {
        for (int j = n - 1; j > i; j--) {
            if (cards[j].value < cards[j - 1].value) swap(cards[j], cards[j - 1]);
        }
    }
    is_stable = IsStable(cards, n);
    return is_stable;
}

bool SelectionSort(Card cards[], int n) {
    bool is_stable = true;
    for (int i = 0; i < n; i++) {
        int minj = i;
        for (int j = i + 1; j < n; j++) {
            if (cards[j].value < cards[minj].value) minj = j;
        }
        if (minj != i) swap(cards[i], cards[minj]);
    }
    is_stable = IsStable(cards, n);
    return is_stable;
}

int main() {
    int n;
    cin >> n;
    
    Card cards[n];
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        cards[i].suit_value = s;
        cards[i].suit = s[0];
        cards[i].value = s[1] - '0';
        cards[i].original_position = i;
    }

    Card bubble_sort_cards[n];
    copy(cards, cards + n, bubble_sort_cards);
    bool is_stable_bubble_sort = BubbleSort(bubble_sort_cards, n);
    for (int i = 0; i < n; i++) {
        if (i != 0) cout << " ";
        cout << bubble_sort_cards[i].suit_value;
    }
    cout << endl << (is_stable_bubble_sort ? "Stable" : "Not stable") << endl;

    Card selection_sort_cards[n];
    copy(cards, cards + n, selection_sort_cards);
    bool is_stable_selection_sort = SelectionSort(selection_sort_cards, n);
    for (int i = 0; i < n; i++) {
        if (i != 0) cout << " ";
        cout << selection_sort_cards[i].suit_value;
    }
    cout << endl << (is_stable_selection_sort ? "Stable" : "Not stable") << endl;
    

    return 0;
}


Measured memory_bytes: 3168
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <map>
using namespace std;
typedef long long int lli;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)
typedef vector<int> vi;
typedef vector<vector<int>> vi2;
int main(void)
{
    int N, K;
    cin >> N >> K;
    vi x;
    int tmp;
    for (int i = 0; i < N; i++)
    {
        cin >> tmp;
        x.push_back(tmp);
    }
    lli calca = 0;
    lli calcb = 0;
    lli ans = 0;
    for (int i = 0; i < N; i++)
    {
        calca = 2 * x[i];
        calcb = 2 * abs(x[i] - K);
        ans += min(calca, calcb);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256