akhauriyash/Code-Regression huggingface dataset:
n=int(input())
L=0
R=0

p1=[]
p2=[]
p3=[]

for _ in range(n):

    s=input()

    #パターン１：))((
    #パターン２：))　右に置きたいタイプ
    #パターン３：（（左に置きたいタイプ

    flag=0
    ll=0
    rr=0
    temp=0

    for ss in s:
        if ss==")":
            if  rr>0:
                rr-=1
            else:
                ll+=1
        elif ss=="(":
            rr+=1
 #   print(s,rr,ll)
    if rr>0 and ll>0:
        p1.append((ll-rr,ll,rr))
    elif rr>0:
        p3.append(rr)
    else:
        p2.append(ll)

cnt=0
for item in p3:
    cnt+=item

#print(p1,p2,p3)

p1.sort()
for item in p1:
    lll=item[1]
    rrr=item[2]

    cnt-=lll
    if cnt<0:
        print("No")
        exit()
    cnt+=rrr

    if cnt<0:
        print("No")
        exit()

for item in p2:
    cnt-=item
    if cnt<0:
        print("No")
        exit()
if cnt==0:
    print("Yes")
else:
    print("No")








    



            


Measured memory_bytes: 145724
#include <bits/stdc++.h>
#include <iomanip>
#define ll long long
using namespace std;

int main() {
  ll N, M, min, minj;
  cin >> N >> M;
  vector<ll> a(N), b(N), c(M), d(M);
  for(ll i = 0; i < N; i++) cin >> a.at(i) >> b.at(i);
  for(ll j = 0; j < M; j++) cin >> c.at(j) >> d.at(j);
  for(ll i = 0; i < N; i++) {
    min = 200000001;
    for(ll j = 0; j < M; j++) {
      if(min > abs(a.at(i) - c.at(j)) + abs(b.at(i) - d.at(j))) {
        min = abs(a.at(i) - c.at(j)) + abs(b.at(i) - d.at(j));
        minj = j + 1;
      }
    }
    cout << minj << endl;
  }
}


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

typedef long long ll;

int main()
{
    ll l,r;
    cin >> l >> r;

    ll ans = 2020;
    for(int i = l; i <= r; i++){
        for(int j = i+1; j <= r; j++){
            if (((ll)i*j)%2019 < ans){
                ans = ((ll)i*j)%2019;
            }
            if(ans == 0) break;
        }
        if(ans == 0) break;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
h, w = map(int,(input().split()))
s= [[0]*(w+2)]*(h+2)
ans= 'Yes'
for i in range(1,h+1):
        s[i] = [0] + list(input()) + [0]

for i in range(1,h+1):
    for j in range(1,w+1):
        if s[i][j] == '#':
            if s[i+1][j]=='#' or s[i-1][j]=='#' or s[i][j+1]=='#' or s[i][j-1]=='#':
                pass
            else:
                ans='No'
                break

print(ans)

Measured memory_bytes: 3064
import collections


class Solution:
    def solve(self, W: int, H: int, x: int, y: int) -> int:

        area = 0.5 * W * H

        if x * 2 == W and y * 2 == H:
            return area, 1
        else:
            return area, 0


if __name__ == '__main__':

    # standard input
    W, H, x, y = map(int, input().split())

    # solve
    solution = Solution()
    answer = solution.solve(W, H, x, y)
    print(answer[0], answer[1])


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

int main(){
    int D;
    std::cin >> D;
    std::vector< int > C(26);
    for(int i=0; i<26; i++){
        std::cin >> C[i];
    }
    std::vector< std::vector< int > > S(D, std::vector< int >(26));
    for(int i=0; i<D; i++){
        for(int j=0; j<26; j++){
            std::cin >> S[i][j];
        }
    }
    std::vector< int > T(D);
    for(int i=0; i<D; i++){
        std::cin >> T[i];
    }
    
    int M;
    std::cin >> M;
    std::vector< int > D_query(M);
    std::vector< int > Q_query(M);
    for(int i=0; i<M; i++){
        std::cin >> D_query[i] >> Q_query[i];
    }
    

    std::vector< int > V(M);
    for(int q=0; q<M; q++){
        T[D_query[q]-1] = Q_query[q];
        long long ans = 0;
        std::vector< int > last(26, 0);
        for(int i=0; i<D; i++){
            ans += S[i][T[i] - 1];
            last[T[i] - 1] = i + 1;
            for(int j=0; j<26; j++){
                ans -= (i + 1 - last[j]) * C[j];
            }
        }
        V[q] = ans;
    }
    
    for(int i=0; i<M; i++){
        std::cout << V[i] << std::endl;
    }
    
    return 0;
}



Measured memory_bytes: 4492
#include<iostream>
#include<vector>
#include<bits/stdc++.h>
#define lli long long int
#define mod 1000000007
#define pb push_back
#define mk make_pair
#define MAX 1000003 
#define fastio ios_base::sync_with_stdio(false); cout.tie(NULL);
using namespace std;

lli prime[MAX]; 
unordered_map<lli, lli> max_map; 

lli power(lli a, lli n) 
{ 
	if (n == 0) 
		return 1; 
	lli p = power(a, n / 2) % mod; 
	p = (p * p) % mod; 
	if (n & 1) 
		p = (p * a) % mod; 
	return p; 
} 

void sieve() 
{ 
	prime[0] = prime[1] = 1; 
	for (lli i = 2; i < MAX; i++) { 
		if (prime[i] == 0) { 
			for (lli j = i * 2; j < MAX; j += i) { 
				if (prime[j] == 0) { 
					prime[j] = i; 
				} 
			} 
			prime[i] = i; 
		} 
	} 
} 
 
lli lcmModuloM(const lli* ar, lli n) 
{ 

	for (lli i = 0; i < n; i++) { 
		lli num = ar[i]; 
		unordered_map<lli, lli> temp; 
		while (num > 1) {  
			lli factor = prime[num]; 
			temp[factor]++;  
			num /= factor; 
		} 

		for (auto it : temp) { 
			max_map[it.first] = max(max_map[it.first], it.second); 
		} 
	} 

	lli ans = 1; 

	for (auto it : max_map) { 
		ans = (ans * power(it.first, it.second)) % mod; 
	} 

	return ans; 
}

int main()
{
	fastio;
	sieve();
	lli n,i;
	cin>>n;
	lli a[n],gcd=1,lcm=1,mul=1,pairwise=1;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		mul=(mul*a[i])%mod;
	}
	gcd=a[0];
	for(i=1;i<n;i++)
		gcd=__gcd(gcd,a[i]);
	if(lcmModuloM(a,n)==mul)
		cout<<"pairwise coprime";
	else if(gcd==1)
		cout<<"setwise coprime";
	else
		cout<<"not coprime";
	return 0;
}


Measured memory_bytes: 22228
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd_(ll a,ll b){if(a%b==0)return b;return gcd_(b,a%b);}
ll lcm_(ll a,ll b){ll c=gcd_(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop_(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}
ll ketawa(ll a){ll r=0;while(a){r+=a%10;a/=10;}return r;}

 
int main(){
  string s;
  cin >> s;
  FOR(i,0,3){
    if(s[i]=='7'){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}


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

int main() {
	int N,T,ans=1005;
	cin>>N>>T;
	for(int i=0;i<N;++i){
		int c,t;cin>>c>>t;
		if(T<t)continue;
		ans=min(c,ans);
	}
	if(ans==1005)cout<<"TLE"<<endl;
	else 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 ll long long
#define P pair<int,int>
#define PI 3.141592653589793
const int INF = 1001001001;
const ll MX = 1e18;

int main() {
	int n,k;
	cin >> n >> k;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	sort(a.begin(), a.end());
	int ans = 0;
	rep(i, k) {
		ans += a[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 3624
#define _USE_MATH_DEFINES
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <math.h>
#include <cmath>
#include <set>   

using namespace std;


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

	size_t n = S.length();

	for (int i = 0; i<n; i += 2) {
		S.pop_back(); S.pop_back();
		if (S.substr(0, S.length() / 2) == S.substr(S.length() / 2, S.length() / 2)) {
			cout << S.length() << endl;
			break;
		}
	}

	
}

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

#define rep(i, a, b) for(ll i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) ((ll)(x).size())
#define pb push_back
#define fst first
#define snd second
#define PI (acos(-1))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))

#define MAXN 1123456
#define MOD 1000000007

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

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

  ll x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  ll i = 0, j= 0, k = 0;

  vi p(a), q(b), r(c);
  rep(i,0,a) cin>> p[i];
  rep(i,0,b) cin>> q[i];
  rep(i,0,c) cin>> r[i];

  priority_queue<pii> pq;
  rep(i,0,a) pq.push(make_pair(p[i], 0));
  rep(i,0,b) pq.push(make_pair(q[i], 1));
  rep(i,0,c) pq.push(make_pair(r[i], 2));

  ll ans = 0;
  ll red = 0, green = 0, u = 0;

  while (red+green+u<x+y) {
    ll val, type;
    tie(val, type) = pq.top(); pq.pop();

    if (type==0 and red<x) {
      ++red;
      ans += val;
    } else if (type==1 and green<y) {
      ++green;
      ans += val;
    } else if (type==2) {
      ++u;
      ans += val;
    }
  }

  cout << ans << endl;

}

Measured memory_bytes: 12908
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define popcnt(x) __builtin_popcount(x)
#define inf 0x3f3f3f3f
#define watch(x) cout << (#x) << " is " << (x) << endl
#define rand() (rand() << 15 | rand())
using namespace std;
using namespace __gnu_pbds;

template<typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long  ll;
#define EPS 1e-9
#define PI acos(-1.0)

int main() {
   ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
   int n , k;
   cin >> n >> k;
   vector<double> a(n);
   for(int i = 0 ; i < n ; ++i){
      int x;
      cin >> x;
      a[i] = (x + 1.0) / 2.0;
   }

   partial_sum(a.begin() , a.end() , a.begin());
   double ans = a[k - 1];
   for(int i = 1 ; i + k - 1 < n ; ++i){
      ans = max(ans , a[i + k - 1] - a[i - 1]);
   }
   cout << fixed << setprecision(10) << ans << "\n";
}

Measured memory_bytes: 1792
#include <iostream>
#include <utility>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <climits>
using namespace std;
signed main()
{
	ios::sync_with_stdio(false);
	int a, b;
	cin >> a >> b;
	if (a <= 8 && b <= 8)cout << "Yay!";
	else cout << ":(";
}

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

N, M = [int(item) for item in input().split()]
from collections import defaultdict
bs = defaultdict(lambda: [])

import heapq

for n in range(N):
    A, B = [int(item) for item in input().split()]
    bs[A].append(B)

heap = []

total = 0

for d in range(1, M + 1):
    [heapq.heappush(heap, -item) for item in bs[d]]
    if len(heap) > 0:
        total += -heapq.heappop(heap)

print(total)


Measured memory_bytes: 27856
/*
AtCoder Library Practice Contest - F - Convolution
https://atcoder.jp/contests/practice2/tasks/practice2_f
*/

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<vl> vvl;

double EPS=1e-9;
int INF=1000000005;
long long INFF=1000000000000000005ll;
double PI=acos(-1);
int dirx[8]={ -1, 0, 0, 1, -1, -1, 1, 1 };
int diry[8]={ 0, 1, -1, 0, -1, 1, -1, 1 };
const ll MOD = 1000000007;

#define DEBUG fprintf(stderr, "====TESTING====\n")
#define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
#define OUT(x) cout << x << endl
#define OUTH(x) cout << x << " "
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define READ(x) for(auto &(z):x) cin >> z;
#define FOR(a, b, c) for (int(a)=(b); (a) < (c); ++(a))
#define FORN(a, b, c) for (int(a)=(b); (a) <= (c); ++(a))
#define FORD(a, b, c) for (int(a)=(b); (a) >= (c); --(a))
#define FORSQ(a, b, c) for (int(a)=(b); (a) * (a) <= (c); ++(a))
#define FORC(a, b, c) for (char(a)=(b); (a) <= (c); ++(a))
#define EACH(a, b) for (auto&(a) : (b))
#define REP(i, n) FOR(i, 0, n)
#define REPN(i, n) FORN(i, 1, n)
#define MAX(a, b) a=max(a, b)
#define MIN(a, b) a=min(a, b)
#define SQR(x) ((ll)(x) * (x))
#define RESET(a, b) memset(a, b, sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz))
#define PERMUTE next_permutation
#define TC(t) while (t--)
#define FAST_INP  ios_base::sync_with_stdio(false);cin.tie(NULL)


void solve() {

}

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

//    int tc; cin >> tc;
//    TC(tc) solve();
	int n, m;
	cin >> n >> m;
	vl a(n), b(m);
	READ(a);
	READ(b);
	vl conv = convolution(a,b);
	EACH(c,conv) OUTH(c);
    return 0;
}


Measured memory_bytes: 27288
fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let n: u64 = sc.read();
    let s: u64 = sc.read();

    for b in 2.. {
        if b * b > n {
            break;
        }
        if f(b, n) == s {
            println!("{}", b);
            return;
        }
    }

    // b*b > n
    // a*b + c = n
    // a + c = s
    // a*(b-1) = n - s
    if n >= s {
        let mut c = vec![];
        let m = n - s;
        for d in 1.. {
            if d * d > m {
                break;
            }
            if m % d == 0 {
                c.push(m / d);
                c.push(d);
            }
        }

        c.sort();
        for c in c.into_iter() {
            let b = c + 1;
            if f(b, n) == s {
                println!("{}", b);
                return;
            }
        }
    }

    if n == s {
        println!("{}", n + 1);
    } else {
        println!("-1");
    }
}

fn f(b: u64, mut n: u64) -> u64 {
    let mut result = 0;
    while n > 0 {
        result += n % b;
        n /= b;
    }
    result
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N;
    cin >> N;
    int sen, hyaku, zyu, iti;
    // 千の位
    sen = N / 1000;
    N -= 1000*sen;
    // 百の位
    hyaku = N / 100;
    N -= 100*hyaku;
    // 十の位
    zyu = N / 10;
    N -= 10*zyu;
    // 一の位
    iti = N;
    bool isGood = false;
    if((sen == hyaku) && (hyaku == zyu) && (zyu == iti)){
        isGood = true;
    }else if((sen == hyaku) && (hyaku == zyu)){
        isGood = true;
    }else if((hyaku == zyu) && (zyu == iti)){
        isGood = true;
    }
    if(isGood) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MAX = 2e5+9 ;
#define fastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define what_is(x) cerr << #x << " = " << x << endl;
typedef long long ll;
int numdiv (int n)
{
    if (n==1)
        return 1;
    int ret=2;
    for (int i=2; i*i<=n; ++i)
    {
        if (n%i==0)
        {
            ++ret;
            if (n%(n/i)==0 && n/i!=i)
                ++ret;
        }
    }
    return ret;
}
ll pr[10000009];
int main()
{
    fastIO

    for (int i=1; i<=10000009; ++i)
    {
        for (int j=i; j<=10000009; j+=i)
        {
            ++pr[j];
        }
    }

    int n;
    cin>>n;

    ll ans=0;

    for (ll i=1; i<=n; ++i)
    {
        ans+=pr[i]*i;
    }
    cout<<ans;








}


Measured memory_bytes: 81688
#include <stdio.h>

int main(void)
{
	int no;
	int i;
	unsigned long r_money;
	
	r_money = 100000;
	
	scanf("%d", &no);
	
	for (i = 0; i < no; i++){
		r_money *= 1.05;
		if (r_money % 1000 > 0){
			r_money = ((r_money / 1000) + 1) * 1000;
		}
	}
	
	printf("%d\n", r_money);
	
	return (0);
}

Measured memory_bytes: 0
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
ans = 0
for i in range(K):
    ans += P if T[i] == "r" else R if T[i] == "s" else S
    prev = T[i]
    for t in T[i::K][1:]:
        if t != prev:
            ans += P if t == "r" else R if t == "s" else S
            prev = t
        else:
            prev = "*"
print(ans)

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

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

	int number = b - a;
	int sum = 0;
	for (int i=1;i<=number;i++)
		sum += i;
	cout << sum - b << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <chrono>
#include <ext/random>
#include <random>
using namespace std;
using ull = unsigned long long;

class RollingHash {
 public:
  RollingHash(const std::string& s) : s_(s) { Initialize(); }
  std::pair<ull, ull> GetHash(const int& left, const int& right);

 private:
  const std::string s_;
  static ull base0_;
  static ull base1_;
  static constexpr ull mod0_ = 2020202077;
  static constexpr ull mod1_ = 2020202111;
  std::vector<ull> hash0_;
  std::vector<ull> hash1_;
  static std::vector<ull> power0_;
  static std::vector<ull> power1_;
  static __gnu_cxx::sfmt19937_64 sfmt_;
  void Initialize();
};

inline void RollingHash::Initialize() {
  size_t n = s_.size();
  hash0_.assign(n + 1, 0);
  hash1_.assign(n + 1, 0);
  for (size_t i = 0; i < n; ++i) {
    hash0_[i + 1] = (hash0_[i] * base0_ + s_[i]) % mod0_;
    hash1_[i + 1] = (hash1_[i] * base1_ + s_[i]) % mod1_;
  }
  while (power0_.size() <= n) {
    power0_.emplace_back(power0_.back() * base0_ % mod0_);
    power1_.emplace_back(power1_.back() * base1_ % mod1_);
  }
}

inline std::pair<ull, ull> RollingHash::GetHash(const int& left, const int& right) {
  ull ret0 = (hash0_[right] - hash0_[left] * power0_[right - left] % mod0_ + mod0_) % mod0_;
  ull ret1 = (hash1_[right] - hash1_[left] * power1_[right - left] % mod1_ + mod1_) % mod1_;
  return {move(ret0), move(ret1)};
}

__gnu_cxx::sfmt19937_64 RollingHash::sfmt_(
    std::chrono::steady_clock::now().time_since_epoch().count());
ull RollingHash::base0_ = std::uniform_int_distribution<ull>(
    2, RollingHash::mod0_)(RollingHash::sfmt_);
ull RollingHash::base1_ = std::uniform_int_distribution<ull>(
    2, RollingHash::mod1_)(RollingHash::sfmt_);
std::vector<ull> RollingHash::power0_{1};
std::vector<ull> RollingHash::power1_{1};

void ABC141_E() {
  int n; cin >> n;
  string s; cin >> s;
  RollingHash rh(s);

  auto ok = [&](int x) -> bool{
    for (int i = 0; i + 2 * x <= n; ++i) {
      for (int j = i + x; j + x <= n; ++j) {
        if (rh.GetHash(i, i + x) == rh.GetHash(j, j + x)) {
          return true;
        }
      }
    }
    return false;
  };

  int low = 0, high = n / 2 + 1;

  while (high - low > 1) {
    int mid = (low + high) >> 1;
    if (ok(mid)) {
      low = mid;
    } else {
      high = mid;
    }
  }

  cout << low << '\n';
}

int main(){
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);

  ABC141_E();

  return 0;
}

Measured memory_bytes: 516
#include<bits/stdc++.h>
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define forN(i, n) for(int i = 0; i <n ; ++i)
#define endl "\n"
#define noob (main)
typedef long long ll;
using namespace  std;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const int N = 2e5 +5 ;
ll n,m;

int noob(){
    cin>>n>>m;
    cout<<(ll)lcm(n,m);
}



Measured memory_bytes: 3604
#include<vector>
#include<algorithm>
#include<cstdint>
//RMQ
class SegmentTree{
private:
    using Int = int_fast64_t;
    std::vector<Int> arr;
    size_t size;
    const Int INF = (1ll << 31) - 1ll;
public:
    SegmentTree(size_t range){
        size = 1;
        while(size < range) size <<= 1;
        arr.assign(2*size-1, INF);
    }
    SegmentTree(const std::vector<Int>& vec){
        size = 1;
        while(size < vec.size()) size <<= 1;
        arr.assign(2*size-1, INF);
        for(size_t i = 0; i < vec.size(); ++i) arr[i+size-1] = vec[i];
        for(Int i = size-2; i >= 0; --i) arr[i] = std::min(arr[2*i+1], arr[2*i+2]);
    }
    
    void update(size_t idx, Int value){
        idx += (size - 1);
        arr[idx] = value;
        while(idx > 0){
            idx = (idx-1) / 2;
            arr[idx] = std::min(arr[2*idx+1], arr[2*idx+2]);
        }
    }

    Int minQuery(size_t L, size_t R, size_t idx=0, size_t l=0, size_t r=1e9+7){
        if(r > 1e9) r = size;

        if(r <= L || R <= l) return INF;
        if(L <= l && r <= R) return arr[idx];

        Int MIN = INF;
        MIN = std::min(minQuery(L, R, 2*idx+1, l, (l+r)/2), MIN);
        MIN = std::min(minQuery(L, R, 2*idx+2, (l+r)/2,r), MIN);
        return MIN;
    }
};

#include<iostream>
using namespace std;
using i64 = int_fast64_t;
int main(){
    int N,L;
    cin >> N >> L;
    vector<i64> v(N);
    for(int i=0;i<N;i++) cin >> v[i];

    SegmentTree Seg(v);
    for(int i=0;i<=N-L;i++){
        cout << Seg.minQuery(i, i+L);
        if(i != N-L) cout << " ";
    }
    cout << endl;
}



Measured memory_bytes: 27132
#include <bits/stdc++.h>
 
using namespace std;
 
#define MAX_N 1010
#define MAX_M 1010
#define INF 1e9
 
int main(){
    int N,M,D[MAX_N],C[MAX_M];
    cin >> N >> M;
    for(int i = 0 ; i < N ; i++){
	cin >> D[i];
    }
    for(int i = 0 ; i < M ; i++){
	cin >> C[i];
    }
    int dp[MAX_N][MAX_M];
    fill(dp[0],dp[0]+MAX_N*MAX_M,INF);
    dp[0][0] = 0;
    for(int i = 0 ; i < N ; i++){
	for(int j = 0 ; j < M ; j++){
	    dp[i][j+1] = min(dp[i][j+1],dp[i][j]);
	    dp[i+1][j+1] = min(dp[i+1][j+1],dp[i][j]+D[i]*C[j]);
	}
    }
    cout << *min_element(dp[N],dp[N]+M+1) << endl;
    return 0;
}

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

using namespace std;
int main()
{
    int n,w,x;
    cin>>n;
    cin>>w;
    vector<int> v,a;
    v.push_back(0);
    a.push_back(0);
    for(int i=0;i<n;i++)
    {
        cin>>x;
        a.push_back(x);
        cin>>x;
        v.push_back(x);
    }
    vector<vector<long long> >dp(n+1,vector<long long>(w+1,0));
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=w;j++)
        {
            dp[i][j]=dp[i-1][j];
            if(a[i]<=j)
            {
                dp[i][j]=max(dp[i][j],dp[i-1][j-a[i]]+v[i]);
            }
        }
    }
    cout<<dp[n][w];
   
}

Measured memory_bytes: 83004
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
	ll n,w;
	cin>>n>>w;
	vector<vector<ll> > dp(n+1,vector<ll>((1000*100)+1,1000000001));
	dp[0][0] = 0;
	for(int i=1;i<=n;i++)
	{
		dp[i][0] = 0;
		ll weight,value;
		cin>>weight>>value;
		for(int j=1;j<=100000;j++)
		{
			dp[i][j] = min(dp[i-1][j],(j-value>=0)?dp[i-1][j-value]+weight:1000000001);
		}
	}
	int ans=0;
	for(int i=100000;i>=0;i--)
	{
		if(dp[n][i]<=w)
		{
			ans = i;
			break;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 80256
/* 
Rohit645
Rohit Kumar 
*/

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

using ll = long long;
using db = double;
using pll = pair < ll, ll >;

#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
	cerr << name << " : " << arg1 << std :: endl;
}
template < typename Arg1, typename... Args >
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << " | ";
	__f(comma + 1, args...);
}
#else
#define trace(...)
#endif

#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end() 
#define fastIo() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)

const int MOD = 1e9 + 7, INF = INT_MAX, N = 1e5 + 10;

ll n;
vector <ll> h(N), dp(N, -1);

ll solve(ll );
int main() {
	cin >> n;
	// vector<ll> h(n + 5), dp(n+5, -1);
	for(ll i = 0; i < n; i++) cin >> h[i];
	cout << solve(0) << endl;
	return 0;
}
ll solve(ll i) {
	ll &ans = dp[i];
	if (ans != -1)
	return ans;
	
	if(i == n-2) {
		ans = abs(h[n-2]-h[n-1]);
	}
	else if (i == n-1) {
		ans = 0;
	}
	else if(i + 2 < n){
		ans = min(abs(h[i]-h[i+1])+solve(i+1), abs(h[i]-h[i+2])+solve(i+2));
	}
	return ans;
}


Measured memory_bytes: 4096
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <stack>

using namespace std;

int main()
{
    int n, a[100000];
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    int p=1;
    for(int i=n-1;i>0;i--)
    {
        if(a[i-1]>a[i])
        {
            a[i-1]--;
            if(a[i-1]>a[i])
            {
                p=0;
                break;
            }
        }
    }
    if(p==0)
        printf("No\n");
    else
        printf("Yes\n");
    return 0;
}


Measured memory_bytes: 640
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        
        String[] input1 = br.readLine().split(" ");
        int n = Integer.parseInt(input1[0]);
        int m = Integer.parseInt(input1[1]);
        
        String[] input2 = br.readLine().split(" ");
        int[] cost = new int[m];
        int totalCost = 0;
        
        for(int i = 0; i < m; i++){
            cost[i] = Integer.parseInt(input2[i]);
            totalCost += cost[i];
        }
        
        out.println(n >= totalCost ? n - totalCost : -1);
        out.close();
        
    }
}

Measured memory_bytes: 34720
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char a = sc.next().toCharArray()[0];
		char b= sc.next().toCharArray()[0];


		if (a < b) {
			System.out.println("<");
		} else if (b < a) {
			System.out.println(">");
		} else {
			System.out.println("=");
		}

		sc.close();

	}

}


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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    char ch;
    while(cin.get(ch)) {
        if(islower(ch)) ch=toupper(ch);
        cout.put(ch);
    }
    return 0;
}

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
    vector<int> dp;
    dp.push_back(1),dp.push_back(1);
    for(int i=0;i<44;i++)dp.push_back(dp[i]+dp[i+1]);
    int N;scanf("%d",&N);
    printf("%d\n",dp[N]);
    return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

template<::std::uint_fast64_t mod>
class ModInt{
private:
	using value_type = ::std::uint_fast64_t;
	value_type n;
public:
	ModInt() : n(0) {}
	ModInt(value_type n_) : n(n_ % mod) {}
	ModInt(const ModInt& m) : n(m.n) {}

	template<typename T>
	explicit operator T() const { return static_cast<T>(n); }
	value_type get() const { return n; }

	friend ::std::ostream& operator<<(::std::ostream &os, const ModInt<mod> &a) {
		return os << a.n;
	}

	friend ::std::istream& operator>>(::std::istream &is, ModInt<mod> &a) {
		value_type x;
		is >> x;
		a = ModInt<mod>(x);
		return is;
	}

	bool operator==(const ModInt& m) const { return n == m.n; }
	bool operator!=(const ModInt& m) const { return n != m.n; }
	ModInt& operator*=(const ModInt& m){ n = n * m.n % mod; return *this; }

	ModInt pow(value_type b) const{
		ModInt ans = 1, m = ModInt(*this);
		while(b){
			if(b & 1) ans *= m;
			m *= m;
			b >>= 1;
		}
		return ans;
	}

	ModInt inv() const { return (*this).pow(mod-2); }
	ModInt& operator+=(const ModInt& m){ n += m.n; n = (n < mod ? n : n - mod); return *this; }
	ModInt& operator-=(const ModInt& m){ n += mod - m.n; n = (n < mod ? n : n - mod); return *this; }
	ModInt& operator/=(const ModInt& m){ *this *= m.inv(); return *this; }
	ModInt operator+(const ModInt& m) const { return ModInt(*this) += m; }
	ModInt operator-(const ModInt& m) const { return ModInt(*this) -= m; }
	ModInt operator*(const ModInt& m) const { return ModInt(*this) *= m; }
	ModInt operator/(const ModInt& m) const { return ModInt(*this) /= m; }
	ModInt& operator++(){ n += 1; return *this; }
	ModInt& operator--(){ n -= 1; return *this; }
	ModInt operator++(int){
		ModInt old(n);
		n += 1;
		return old;
	}
	ModInt operator--(int){
		ModInt old(n);
		n -= 1;
		return old;
	}
	ModInt operator-() const { return ModInt(mod-n); }
};


const ll MOD = 1e9+7;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, k; cin>>n>>k;
	vll a(n);
	rep(i, n) cin>>a[i];

	ModInt<MOD> ans(0);

	rep(i, n){
		for(int j=i+1; j<n; j++){
			if (a[i]>a[j]) ans++;
		}
	}
	ans *= k;
	sort(all(a));
	rep(i, n){
		ModInt<MOD> temp;
		temp = (k-1)*k/2;
		ans += temp*(lower_bound(a.begin(), a.end(), a[i])-a.begin());
	}

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 256
unittest
{
	assert( [ "6", "0 1 2 3 4 5" ].parse.expand.solve == 3 );
	assert( [ "3", "0 0 0" ].parse.expand.solve == 6 );
	assert( [ "54", "0 0 1 0 1 2 1 2 3 2 3 3 4 4 5 4 6 5 7 8 5 6 6 7 7 8 8 9 9 10 10 11 9 12 10 13 14 11 11 12 12 13 13 14 14 15 15 15 16 16 16 17 17 17" ].parse.expand.solve == 115295190 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	input.popFront;
	auto as = input.front.split.to!( long[] );
	return tuple( as );
}

auto solve( long[] as )
{
	auto ans = 1L;
	auto cs = new long[ 3 ];
	foreach( a; as )
	{
		ans = ans.mulMod( cs.count( a ) );
		foreach( ref c; cs )
		{
			if( c == a )
			{
				c++;
				break;
			}
		}
	}
	return ans;
}

// 掛け算
auto mulMod( long MOD = 10L ^^ 9 + 7 )( long x, long y )
{
	return x * y % MOD;
}


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

int main ( void)
{
    int n , *a,i,ans;

    scanf("%d" , &n);

    a = (int*)malloc(sizeof(int)*n);

    for(i=0;i<n;i++)
        scanf("%d" , &a[i]);

    ans=0;
    for(i=0;i<n;i++){
        ans+=a[i]-1;
    }

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

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<map>
#include<string>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
    int n,m,l;
    cin>>n>>m>>l;
    int a[n][m],b[m][l];
    rep(i,n)rep(k,m){
        cin>>a[i][k];
    }
    rep(k,m)rep(j,l){
        cin>>b[k][j];
    }
    long long c[n][l];
    rep(i,n)rep(j,l){
        c[i][j]=0;
        rep(k,m) c[i][j]+=a[i][k]*b[k][j];
    }

    rep(i,n)rep(j,l){
        cout<<c[i][j]<<((j==l-1)?'\n':' ');
    }
}


Measured memory_bytes: 3232
#include<bits/stdc++.h> 
#define fo(i,a,b) for(i=a;i<=b;i++)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
typedef long long ll;
using namespace std;
const int mo=1e9+7,maxn=3005;
int i,j,n,m,ans,b,f[maxn][maxn][2];
int main(){
	scanf("%d%d",&n,&m);
	f[0][0][1]=1;
	fo(i,1,n) f[0][i][0]=1;
	fo(i,0,m-1){
		fo(j,0,n)
		fo(b,0,1)if (f[i][j][b]){
			int s=f[i][j][b];
			if (j) {
				bool x=b|(j==1);
				(f[i+1][j-1][x]+=s)%=mo;
				(f[i+1][j][x]+=s)%=mo;
			}
			if (j!=n){
				(f[i+1][j+1][b]+=s)%=mo;
				(f[i+1][j][b]+=s)%=mo;
			}
		}
	}
	fo(i,0,n) (ans+=f[m][i][1])%=mo; 
	printf("%d\n",ans);
}

Measured memory_bytes: 70656
#include <iostream>
#include <string>
#include <algorithm>
#include <list>
using namespace std;

int main()
{
    string s;
    cin >> s;
    bool has[26];
    for (int i = 0; i < 26; i++)
        has[i] = false;
    for (int i = 0; i < s.length(); i++)
    {
        int idx = int(s[i] - 'a');
        if (has[idx])
        {
            cout << "no" << endl;
            return 0;
        }
        else
            has[idx] = true;
    }
    cout << "yes" << endl;
    return 0;
}


Measured memory_bytes: 3632
#pragma warning(disable:4996)

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

typedef long long ll;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define pb push_back
#define mp make_pair
#define fill(x,y) memset(x,y,sizeof(x))
#define even(x) x % 2 == 0
#define odd(x) x % 2 != 0

const ll INF = (1ll << 60);
const int INF_CONST = (int)1e9;
const ll MOD_CONST = (ll)(1e9 + 7);

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

	int N; cin >> N;
	vector<pair<int, int>> as(N); 
	REP(i, N) {
		cin >> as[i].first;
		as[i].second = i;
	}
	sort(as.begin(), as.end());

	ll ans = 0;
	REP(i, N) {
		ll d = abs(i - as[i].second);
		if (odd(d)) ans++;
	}
	cout << ans / 2 << endl;

	return 0;
}


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

int main() {
  int n;
  cin >> n;
  
  vector<int> a(n),b(n),c(n-1);
  for(int i=0; i<n; i++){
    cin >> a[i];
  }
  for(int i=0; i<n; i++){
    cin >> b[i];
  }
  for(int i=0; i<n-1; i++){
    cin >> c[i];
  }
  
  int ans = 0;
  for(int i=0; i<n; i++){
    ans += b[a[i]-1];
    if(a[i-1]==a[i]-1){
      ans += c[a[i-1]-1];
    }
  }
  
  cout << ans << endl;
}

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

int main() {
  vector<long long> arr(5);
  long long N;
  cin >> N;
  for(long long &n : arr) cin >> n;
  for(int i = 1; i < 5; i++)
    if(arr[i] > arr[i-1]) arr[i] = arr[i-1];
  cout << (N + arr[4] - 1) / arr[4] + 4;
}

Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.ascii;
import std.bigint;
import std.complex;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

void readlnTo(T...)(ref T t) {
    auto s = readln().split();
    assert(s.length == t.length);
    foreach(ref ti; t) {
        ti = s[0].to!(typeof(ti));
        s = s[1..$];
    }
}

const real eps = 1e-10;

const long p = 1_000_000_000 + 7;

void main(){
    auto N = readLong();
    auto a = readLongs().map!"a % 4".array();
    auto c = iota(4).map!(x => a.count!(b => b == x)).array();
    if(c[1] + c[3] > c[0] + 1) {
        writeln("No");
        return;
    }
    if(c[1] + c[3] == c[0] + 1 && c[2] > 0) {
        writeln("No");
        return;
    }
    writeln("Yes");
}



Measured memory_bytes: 6452
using System.Collections.Generic;
    using System.Collections;
    using System.IO;
    using System.Linq;
    using System.Text;
    using System;

    namespace cysharp_test
    {
        class Program
        {
            static void Main (string[] args)
            {
                new Program ().solve ();
            }

            void solve ()
            {
            int[] sw = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            Console.WriteLine(sw[0] <= sw[1] ? "unsafe" : "safe");

            Console.ReadKey ();

            }

        }

        struct Vector2
        {
            public Vector2 (long x, long y)
            {
                this.x = x;
                this.y = y;
            }

            public long x, y;

            public string ToString ()
            {
                return "(" + this.x + "," + this.y + ")";
            }

            public static Vector2 operator + (Vector2 a, Vector2 b)
            {
                return new Vector2 (a.x + b.x, a.y + b.y);
            }

            public static Vector2 operator - (Vector2 a, Vector2 b)
            {
                return new Vector2 (a.x - b.x, a.y - b.y);
            }

            public static Vector2 operator * (Vector2 a, long scala)
            {
                return new Vector2 (a.x * scala, a.y + scala);
            }

            public static bool operator == (Vector2 a, Vector2 b)
            {
                return a.x == b.x && a.y == b.y;
            }

            public static bool operator != (Vector2 a, Vector2 b)
            {
                return !(a.x == b.x && a.y == b.y);
            }
        }
    }

Measured memory_bytes: 19088
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main(void){
int n;scanf("%d",&n);
int k;
printf("%d:",n);
for(;;){
    for(k=2;;k++){
    
    if(n%k==0){printf(" %d",k);n=n/k;break;}
    if(k>=sqrt(n)+1){printf(" %d\n",n);return 0;}
    }
    k=2;
    if(n==1){break;}
}
printf("\n");
return 0;
}



Measured memory_bytes: 2120
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
	double a,b;
	cin>>a>>b;
	double x=(a+b)/2;
	int e=x;
	if(x-e>0.4)
	{
		e++;
	}
	cout<<e;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

struct Data {
  int num, idx;
  Data() : num(0x7FFFFFFF), idx(-1) {}
  Data(int n, int i) : num(n), idx(i) {}
};

inline Data Merge(Data left, Data right) {
  return left.num < right.num ? left : right;
}

struct SegmentTree {
  int n; vector<Data> data;
  SegmentTree(int N) : n(1 << N), data(n * 2) {}
  void update (int pos, Data value) {
    data[pos] = value;
    while (pos < 2*n-1) {
      int l = pos, r = pos^1;
      if (l > r) swap(l, r);
      pos = pos / 2 + n;
      data[pos] = Merge(data[l], data[r]);
    }
  }
  Data sub(int fr, int to, int node, int la, int ra) {
    if (ra<=fr || to<=la) return Data();
    if (fr<=la && ra<=to) return data[node];
    Data vl = sub(fr, to, (node-n)*2+0, la, (la+ra)/2);
    Data vr = sub(fr, to, (node-n)*2+1, (la+ra)/2, ra);
    return Merge(vl, vr);
  }
  Data query(int fr, int to) { return sub(fr, to, 2*n-2, 0, n); }
};

struct Tree {
  tuple<int,int> val;
  vector<shared_ptr<Tree>> children;
};

shared_ptr<Tree> solve(int fr, int to, SegmentTree& even, SegmentTree& odd) {
  if (fr == to) {
    return nullptr;
  }
  auto t1 = even.query(fr, to);
  auto t2 = odd.query(t1.idx+1, to);
  auto c1 = solve(fr, t1.idx, even, odd);
  auto c2 = solve(t1.idx+1, t2.idx, odd, even);
  auto c3 = solve(t2.idx+1, to, even, odd);
  auto res = make_shared<Tree>();
  res->val = make_tuple(t1.num, t2.num);
  if (c1) res->children.push_back(c1);
  if (c2) res->children.push_back(c2);
  if (c3) res->children.push_back(c3);
  return res;
}

bool operator>(const shared_ptr<Tree>& lhs, const shared_ptr<Tree>& rhs) {
  return lhs->val > rhs->val;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin>>n;
  SegmentTree even(18), odd(18);
  REP(i,n) {
    int p;
    cin>>p;
    if (i%2 == 0) {
      even.update(i, Data(p, i));
    } else {
      odd.update(i, Data(p, i));
    }
  }
  auto res = solve(0, n, even, odd);
  using T = shared_ptr<Tree>;
  priority_queue<T, vector<T>, greater<T>> q;
  q.push(res);
  vecint ans;
  while (!q.empty()) {
    auto p = q.top();
    q.pop();
    int x,y;
    tie(x,y) = p->val;
    ans.push_back(x);
    ans.push_back(y);
    for (auto&& child : p->children) {
      q.push(child);
    }
  }
  REP(i,n) {
    if (i) cout<<" ";
    cout<<ans[i];
  }
  cout<<"\n";
  return 0;
}


Measured memory_bytes: 148084
s = input()
n = len(s)
while 0 < n:
    if s[n-5:n] == 'dream' or s[n-5:n] == 'erase':
        n -= 5
        continue
    elif s[n-6:n] == 'eraser':
        n -= 6
        continue
    elif s[n-7:n] == 'dreamer':
        n -= 7
        continue
    print('NO')
    exit()
print('YES')

Measured memory_bytes: 9164
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <iomanip>
#include <queue>
#include <stack>
#include <functional>
#define rep(i,n) for(int i=0;i<n;i++)
using ll = long long;
using namespace std;
int main() {
	ll n, m, ans = 0, A[10101];
	string s;
	cin >> s >> n;
	for (int i = 0; i < s.size(); i += n)
		cout << s[i];
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int mod = 1e9+7;
int count[1001];
void function(int i){
	//iまでを素因数分解していく
	int j = 2;
	while(i!=1){
		if(i%j==0){
			::count[j]++;
			i /=j;
			continue;
		}
		j++;
	}
}
int main(void){
	int N;
	cin >> N;
	long long ans = 1;
	for(int i = 1;i<=N;i++)::function(i);
	for(int i =1;i<=N;i++){
		ans *= (long long)::count[i]+1;
		ans %= (long long)mod;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque, defaultdict
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations,product#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
from functools import reduce,lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printe(*x):print("## ",*x,file=sys.stderr)
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def binr(x): return bin(x)[2:]
def bitcount(x): #xは64bit整数
    x= x - ((x >> 1) & 0x5555555555555555)
    x= (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x= (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f 
    x+= (x >> 8); x+= (x >> 16); x+= (x >> 32) 
    return x & 0x7f

def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reverse=True)  #二個目の要素で降順並び替え

    N = int(input())
    #N, K = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    cnt=0
    for i in range(1,N+1):
        if len(str(i))%2==1:
            cnt+=1
    print(cnt)




if __name__ == "__main__":
    main()

Measured memory_bytes: 77524
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pii pair<int, int>
#define p3i pair<pii, int>
#define pll pair<ll, ll>
#define p3l pair<pll, ll>
#define lseg L, (L+R)/2, N*2+1
#define rseg (L+R)/2+1, R, N*2+2
#define ub upper_bound
#define lb lower_bound
#define pq priority_queue
#define MN 1000000007
#define fox(k, x) for (int k=0; k<x; ++k)
#define fox1(k, x) for (int k=1; k<=x; ++k)
#define foxr(k, x) for (int k=x-1; k>=0; --k)
#define fox1r(k, x) for (int k=x; k>0; --k)
#define ms multiset
#define flood(x) memset(x, 0x3f3f3f3f, sizeof x)
#define drain(x) memset(x, 0, sizeof x)
#define rng() (rand() >> 3)*rand()
#define scan(X) do{while((X=getchar())<'0'); for(X-='0'; '0'<=(_=getchar()); X=(X<<3)+(X<<1)+_-'0');}while(0)
char _;
#define pi 3.14159265358979323846

int a, b, D, n, m, d[100005];
bool u[100005];
vector<pii> v[100005];
bool dfs(int N, int D){
    if (u[N]) return D!=d[N];
    u[N]=1;d[N]=D;
    fox(l, v[N].size()){
        if (dfs(v[N][l].x, D+v[N][l].y)) return 1;
    }
    return 0;
}
int main(){
    cin >> n >> m;
    fox(l, m){
        cin >> a >> b >> D;
        v[a].pb(mp(b, D));
        v[b].pb(mp(a, -D));
    }
    fox1(l, n){
        if (!u[l]){
            if (dfs(l, 0)){
                cout << "No";
                return 0;
            }
        }
    }
    cout << "Yes";
    return 0;
}


Measured memory_bytes: 12032
n = int(input())

spade = [1,2,3,4,5,6,7,8,9,10,11,12,13]
heart = [1,2,3,4,5,6,7,8,9,10,11,12,13]
club = [1,2,3,4,5,6,7,8,9,10,11,12,13]
diamond = [1,2,3,4,5,6,7,8,9,10,11,12,13]

for i in range(n):
    suit,number = input().split()

    if suit == 'S':
        spade.remove(int(number))
    if suit == 'H':
        heart.remove(int(number))
    if suit == 'C':
        club.remove(int(number))
    if suit == 'D':
        diamond.remove(int(number))

for i in range(len(spade)):
    print(end = 'S ')
    print(*spade[i:i+1])
for i in range(len(heart)):
    print(end = 'H ')
    print(*heart[i:i+1])
for i in range(len(club)):
    print(end = 'C ')
    print(*club[i:i+1])
for i in range(len(diamond)):
    print(end = 'D ')
    print(*diamond[i:i+1])

Measured memory_bytes: 5612