akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>

int top = 0, S[100];

void push(int x)
{
	++top;
	S[top] = x;
}

int pop()
{
	--top;
	return S[top + 1];
}

int main(void)
{
	char s[1000];
	int a, b;
	while (scanf("%s", s) != EOF) {
		if (s[0] == '+') {
			a = pop();
			b = pop();
			push(a + b);
		}
		else if (s[0] == '-') {
			b = pop();
			a = pop();
			push(a - b);
		}
		else if (s[0] == '*') {
			a = pop();
			b = pop();
			push(a * b);
		}
		else push(atoi(s));
	}
	printf("%d\n", pop());
	return 0;
}


Measured memory_bytes: 2104
import Control.Monad
import Control.Applicative hiding ((<|>))
import Text.Parsec
import Text.Parsec.Char

expression = maxmin 
  <$> oneOf "^_" <* char '('
  <*> expression <* char ',' <*> expression <* char ')'
  <|> number
number = makeNumber <$> (sourceColumn <$> getPosition) <*> many1 digit

maxmin c g h a b
  | a' >= b' = (i,x)
  | otherwise = (j,z)
  where 
    (i,x) = g a b
    (j,y) = h a' b'
    (a',b',z) = case c of
      '^' -> (max a x, b, max x y)
      '_' -> (a, min b x, min x y)

makeNumber i s@(c:_) a b
  | x == 0 || x*10+9 <= a || x >= b = (i, read s)
  | otherwise = (i+1, read s)
  where x = read [c]

main = do
  q <- readLn
  replicateM_ q $ do
    s <- getLine
    let (Right f) = parse expression "" s
        (i,x) = f 0 99
    putStrLn $ show x ++ " " ++ show i


Measured memory_bytes: 2428
#include <iostream>
#include <vector>

using namespace std;

int main()
{
  int N;
  cin >> N;
  long long a = 1, t = 1;
  for (int i = 0; i < N; i++) {
    int A, T;
    cin >> A >> T;
    long long k = max((a + A - 1)/A, (t + T - 1)/T);
    a = k*A;
    t = k*T;
  }
  cout << (a + t) << endl;

  return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	a := scanInt()
	b := scanInt()
	c := scanInt()
	k := scanInt()

	ans := 0
	if a <= k {
		ans += a
	} else {
		ans += k
	}
	k -= a
	k -= b
	k = max(0, k)
	if c <= k {
		ans -= c
	} else {
		ans -= k
	}
	fmt.Fprintln(wr, ans)

}


Measured memory_bytes: 1764
module Main where

import Control.Applicative
import Numeric

main :: IO ()
main = loop

loop :: IO ()
loop = do
  { [m, f, r] <- getInts
  ; if m == -1 && f == -1 && r == -1 then done
    else printGrade m f r
  }

done :: IO ()
done = return ()

printGrade :: Int -> Int -> Int -> IO ()
printGrade m f r = putStrLn (grade m f r) >> loop

grade :: Int -> Int -> Int -> String
grade m f r = if m == -1 || f == -1 then "F"
              else if mpf >= 80 then "A"
              else if mpf >= 65 then "B"
              else if mpf >= 50 then "C"
              else if mpf >= 30 then (if r >= 50 then "C" else "D")
              else "F"
  where
    mpf = m + f
  
--

getInts :: IO [Int]
getInts = map read . words <$> getLine

putInts :: [Int] -> IO ()
putInts = putStrLn . unwords . map show

getDoubles :: IO [Double]
getDoubles = map read . words <$> getLine

putDoubles :: [Double] -> IO ()
putDoubles = putStrLn . unwords . map showDouble

showDouble :: Double -> String
showDouble d = showFFloat Nothing d ""



Measured memory_bytes: 4200
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
int main(){
    int64_t a,b,c,k;
    cin >> a>>b>>c>>k;
    if(abs(a-b)>pow(10,18)){
        cout<<"Unfair"<<endl;
    }
    else{
        if(k%2==0){
            cout<<a-b<<endl;
        }
        else{
            cout<<b-a<<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;
typedef long long ll;
typedef double db;
typedef vector <ll> vll;
typedef pair <ll, ll> pll;
#define pb push_back
#define mp make_pair
#define MAX 1000000
#define mod 1000000007
#define all(_) _.begin(), _.end()
#define F first
#define S second
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
bool c(pair <string, ll> a, pair <string, ll> b)
{
    if(a.F == b.F)
        return a.S > b.S;
    return a.F < b.F;
}
int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    ll n, i;
    cin >> n;
    vector <pair <string, ll> > a(n);
    map <ll, ll> m;
    for(i = 0; i < n; i++)
    {
        cin >> a[i].F >> a[i].S;
        m[a[i].S] = i + 1;
    }
    sort(all(a), c);
    for(i = 0; i < n; i++)
        cout << m[a[i].S] << endl;
    return 0;
}

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

int main() {
	int a,b,c;
  	cin >> a >> b >> c;
  	if(a == b){
      cout << c << endl;
    }else if(b == c){
      cout << a << endl;
    }else if(a == c){
      cout << b << endl;
    }
}


Measured memory_bytes: 256
# coding: utf-8
#Problem Name: Sum of 4 Integers
#ID: tabris
#Mail: t123037@kaiyodai.ac.jp

pairs = {i:0 for i in range(51)}
for i in range(10):
    for j in range(10):
        for k in range(10):
            for l in range(10):
                pairs[i+j+k+l] += 1
         
while True:
    try:
        n = int(raw_input())
        print pairs[n]
    except:
        break

Measured memory_bytes: 4204
#include <iostream>
#include <algorithm>
#include <cmath>
#include <list>
#include <queue>
#include <set>
#include <vector>

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define FOR(i,a,b) for (int i=(int)(a);i<(int)(b);++i)
#define FORE(i,a,b) for (int i=(int)(a);i<=(int)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define REPE(i,n) FOR(i,0,n)

typedef long long ll;

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

  if (a < 3200) {
    cout << "red" << endl;
  } else {
    for (auto x: s) cout << x;
    cout << endl;
  }
}

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

#define int long long int
int32_t main()
{
    
    string s;
    cin>>s;
    if(s[2]==s[3]&&s[4]==s[5])
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;

}

Measured memory_bytes: 256
use std::cmp::min;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|i| i.parse().ok().unwrap())
        .collect()
}

fn shortest(i: i32, j: i32, x: i32, y: i32) -> usize {
    let short = min(j-i, (x-i).abs() + 1 + (j-y).abs());
    (short as usize)
}

fn main() {
    let input = read_vec::<i32>();
    let n = input[0];
    let x = input[1] - 1;
    let y = input[2] - 1;

    let mut len = vec![0; (n - 1) as usize];

    for i in 0..n {
        for j in i+1..n {
            let index = shortest(i,j,x,y) - 1;
            len[index] += 1;
        }
    }


    for i in len.iter() {
        println!("{}", i);
    }
}

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

const int mxN=2e5;
int n, r[2], d[2][mxN], p[mxN], ans;
vector<int> adj[2][mxN];

void dfs(int u, int k, int pu=-1) {
	if(k)
		p[u]=pu;
	if(!k&&d[0][u]>=d[1][u])
		return;
	for(int v : adj[k][u]) {
		if(v^pu) {
			d[k][v]=d[k][u]+1;
			dfs(v, k, u);
		}
	}
}

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

	cin >> n >> r[0] >> r[1], --r[0], --r[1];
	for(int k : {0, 1}) {
		for(int i=1, a, b; i<n; ++i) {
			cin >> a >> b, --a, --b;
			adj[k][a].push_back(b);
			adj[k][b].push_back(a);
		}
	}
	memset(d, 0x3f, 4*n);
	d[0][r[0]]=0;
	for(int k : {1, 0})
		dfs(r[k], k);
	for(int i=0; i<n; ++i) {
		if(d[0][i]<=d[1][i])
			ans=max(2*d[1][i], ans);
		if(d[0][i]>=d[1][i])
			continue;
		for(int j : adj[0][i]) {
			if(p[i]^j&&p[j]^i&&p[i]^p[j]&&(p[i]<0||p[p[i]]^j)&&(p[j]<0||p[p[j]]^i)) {
				cout << -1;
				return 0;
			}
		}
	}
	cout << ans;
}

Measured memory_bytes: 38780
#include <bits/stdc++.h>
#define N 1000005
#define ll long long int 	
#define MP make_pair
#define pb push_back
#define ppb pop_back
#define sp " "
#define endl "\n"
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define fast2 freopen ("badhair.gir","r",stdin);freopen ("badhair.cik","w",stdout);
#define mod 1000000007
#define fs(x,y) for(ll i=1;i<=y;i++) cin>>x[i]
#define fo(i,x,y) for(ll i=x;i<=y;i++)
#define INF 1000000000005
using namespace std;

ll n,m,ar[N],sum,t;

char s[N];

int main()
{
	fast;
	cin>>s+1;
	n=strlen(s+1);
	fo(i,1,n/2)
		if(s[i]!=s[n-i+1])
			sum++;
		cout<<sum;

}



/*     cd onedrive\desktop\kod
cls

Sinav:21-22 aralik
Aciklama: Muhtemelen 25 aralik
*/

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

using namespace std;

#define ll long long 
const ll mod=1e9+7;
const ll maxx=1e9+7;


long long power(long long x, long long y, long long m) 
{
    if (y == 0) 
        return 1; 
    long long p = power(x, y/2, m) % m; 
    p = (p * p) % m; 
  
    return (y%2 == 0)? p : (x * p) % m; 
} 



long long ncr(ll n,ll r){
	long long ans=1;
	for(long long i=0;i<r;i++){
		long long m1=power(i+1,maxx-2,maxx);
	    ans=((ans*(((n-i)%maxx))%maxx)*((m1%maxx)%maxx))%maxx;
	
	    
	    
	}
	return ans;
}




ll cal_pow(ll x){
	ll res;
	if (x == 0)	res=1;
	else if (x == 1)	res=2;
	else {
		res = cal_pow(x/2);
		if (x % 2 == 0)	
			res = (res * res) % mod;
		else
			res = (((res*res) % mod) * 2) % mod;
	}
	return res;
}



int main(){
    
        ll n,a,b;
        cin>>n>>a>>b;
        
        ll a1=ncr(n,a);
        ll a2=ncr(n,b);
        
        
        ll a3=cal_pow(n);
        a3=((a3%maxx)-(1%maxx)+maxx)%maxx;
        a3=((a3%maxx)-(a1%maxx)+maxx)%maxx;
        a3=((a3%maxx)-(a2%maxx)+maxx)%maxx;
        
        
        cout<<a3<<"\n";
    
//       cout<<ans;
       
}
    


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <set>

using namespace std;

int main() {
	int n; cin >> n;
	string s; cin >> s;
	set<int> st[26];
	for (int i = 0; i < 26; ++i) st[i].insert(n);
	for (int i = 0; i < n; ++i) st[s[i] - 'a'].insert(i);
	int q; cin >> q;
	while (q--) {
		int f; cin >> f;
		if (f == 1) {
			int i; cin >> i;
			--i;
			char c; cin >> c;
			st[s[i] - 'a'].erase(i);
			st[c - 'a'].insert(i);
			s[i] = c;
		} else {
			int l, r; cin >> l >> r;
			--l, --r;
			int ans = 0;
			for (int i = 0; i < 26; ++i)
				if (*st[i].lower_bound(l) <= r) ++ans;
			cout << ans << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 24196
# -*- coding: utf-8 -*-
from sys import stdin

in_strings = lambda: stdin.readline()[:-1] # s = in_strings()
in_int = lambda: int(stdin.readline()) # N = in_int()
in_intlist = lambda: list(map(int, stdin.readline().split())) # List = in_intlist()

N, X = in_intlist()
a_list = in_intlist()

a_list.sort()

flag = 1
dist = 0
count = 0
for i in range(N):
    dist += a_list[i]
    if dist <= X:
        count += 1
    else:
        flag = 0
        break
if flag and (dist < X):
    count -= 1

print(count)



Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)




bool bfs(vector<vector<pair<int,int> > > &g,vector<ll>&dst,vector<bool> &flag,int i){
	flag[i] = 1;
	for(auto x:g[i]){
		int y = x.first;
		int d = x.second;
		if(flag[y]){
			if(dst[y]!= dst[i]+d){
				return 0;	
			}
		}else{
			dst[y] = dst[i]+d;
			if(!bfs(g,dst,flag,y)){
				return 0;
			}
		}
	}
	return 1;
}


int main(){
	int n,m;
	cin >> n >> m;
	vector<vector<pair<int,int > > > g(n);
	for(int i=0;i<m;i++){
		int l,r,d;
		cin >> l >> r >> d;
		l--;
		r--;
		g[l].PB(MP(r,d));
		g[r].PB(MP(l,-d));
	}
	vector<ll> dst(n);
	vector<bool> flag(n);
	for(int i=0;i<n;i++){
		if(flag[i]==0){
			if(!bfs(g,dst,flag,i)){
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 14208
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
mx = a[-1]
table = [[] for _ in range(M)]
ctable = [0] * (mx + 1)
for x in a: ctable[x] += 1
for x in a:
  if ctable[x] % 2:
    ctable[x] -= 1
    table[x % M].append(x)
for i in range(mx + 1):
  table[i % M] += [i] * ctable[i]

for i in range(M): table[i].reverse()
#print(table)

res = 0
for x in range(M):
  y = (M - x) % M
  if x != y:
    while len(table[x]) > 0 and (len(table[y]) > 0):
      res += 1
      table[x].pop()
      table[y].pop()
  else:
    while len(table[x]) // 2 > 0:
      res += 1
      table[x].pop()
      table[x].pop()

ctable = [0] * (mx + 1)
for i in range(M):
  for x in table[i]:
    ctable[x] += 1
for i in range(mx + 1): res += ctable[i] // 2
print(res)

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

using namespace std;

const int N = 2e5+7;

int n;
int a[N], f[N];
long long k;

int main()
{
    cin >> n >> k;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    for (int i = 1; i <= n; ++i) {
        cin >> f[i];
    }
    sort(a+1, a+n+1);
    sort(f+1, f+n+1);
    reverse(a+1, a+n+1);
    long long l = 0, r = 1e12, mid, need;
    while (l < r) {
        mid = (l+r)>>1;
        need = 0;
        
        for (int i = 1; i <= n; ++i) {
            if (1ll*a[i]*f[i] <= mid) continue;
            need += a[i]-mid/f[i];
        }
        if (need <= k) r = mid;
        else l = mid+1;
    }
    cout << l << endl;
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<string>
#include<sstream>
using namespace std;
int inf = 1000000000;

int main(){

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

  if( a <= b ) cout << a << endl;
  else cout << a-1 << endl;

  return 0;
}





//


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true)
        {
            int n = sc.nextInt();
            int sum = 0;
            double a2 = 0;
            double a = 0;
            if(n == 0)
                break;
            int num[] = new int[n];
            for(int  i = 0 ; i < n ; i++)
            {
                num[i] = sc.nextInt();
                sum += num[i];
            }
            double ave = (double)sum / n;
            for(int i = 0 ; i < n ; i++)
                a2 += Math.pow(num[i] - ave,2);
            a2 /= (double)n;
            a = Math.pow(a2,0.5);
            System.out.println(a);
        }
    }
}


Measured memory_bytes: 31392
(H, W), (Ch, Cw), (Dh, Dw) = 3.times.map{gets.split.map(&:to_i)}
Ss = [['#']*(W + 3)] + readlines.map{['#'] + _1.chomp.chars + ['#','#']} + [['#']*(W + 3)]*2
INF = 1 << 20

mv = [[1, 0], [-1, 0], [0, 1], [0, -1]]
wp = [*-2 .. 2].repeated_permutation(2).to_a - [[0, 0]] - mv
d = Array.new(H + 3){Array.new(W + 3, INF)}
d[Ch][Cw] = 0
q1 = [[Ch, Cw]]
(0 ..).each do |k|
  break if q1.empty? || d[Dh][Dw] < INF
  q2 = []
  while !q1.empty?
    h, w = q1.pop
    next if d[h][w] < k
    mv.each do |a, b|
      x = h + a
      y = w + b
      next if Ss[x][y] == '#' || d[x][y] <= k
      d[x][y] = k
      q1 << [x, y]
    end
    wp.each do |a, b|
      x = h + a
      y = w + b
      next if Ss[x][y] == '#' || d[x][y] <= k + 1
      d[x][y] = k + 1
      q2 << [x, y]
    end
  end
  q1 = q2
end
puts d[Dh][Dw] == INF ? -1 : d[Dh][Dw]

Measured memory_bytes: 105444
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(ll, N);
  VEC(ll, A, N);
  VEC(ll, B, N);
  VEC(ll, C, N);

  sort(all(A));
  sort(all(C));

  ll ans = 0;
  rep(i, 0, N) {
    ans += (lower_bound(all(A), B[i]) - A.begin()) * (C.end() - upper_bound(all(C), B[i]));
  }

  print(ans);
}


Measured memory_bytes: 2560
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

int main(void) {
  long N;
  cin >> N;
  unordered_map<long, long> mp;
  for (long i = 1; i <= N; i++) {
    long tmp = i;
    while (tmp % 2 == 0) {
      mp[2] ++;
      tmp /= 2;
    }
    for (long j = 3; j * j <= tmp; j+= 2) {
      while (tmp % j == 0) {
        mp[j] ++;
        tmp /= j;
      }
    }
    if (tmp != 1) mp[tmp] ++;
  }
  long result = 1;
  for (auto it: mp) {
    result = (result * (it.second + 1)) % MOD;
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい

#define ALL(x) x.begin(),x.end()
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<int, vector<int>, greater<int> > gpq; //逆順priority_queue
typedef priority_queue<int> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const long double PI=3.14159265358979323846264338327950288;

int main(){
    ll N;
    cin>>N;
    int ans=0;
    for(ll i=2;i<=1000000;i++){
        int nn=0;
        while(N%i==0){
            N/=i;
            nn++;
        }
        int sub=1;
        while(nn-sub>=0){
            nn-=sub;
            sub++;
            ans++;
        }
    }
    if(N>1)ans++;
    cout<<ans<<endl;
}


Measured memory_bytes: 3596
N = int(input())
S = input()
def f(m):
    res = False
    hs = []
    for i in range(0,N-m+1):
        hs.append(hash(S[i:i+m]))
    for i in range(0,N-m+1):
        if hash(S[i:i+m]) in hs[i+m:]:
            res = True
            break
    return res

l = 0
r = N//2+1
while (r-l)>1:
    mid = (r+l)//2
    if f(mid):
        l = mid
    else:
        r = mid
print(l)

Measured memory_bytes: 43612
#include <algorithm>
#include <vector>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <fstream>
#include <math.h>

using namespace std;

int main(void)
{
	int n;
	int y;
	cin >> n >> y;
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n; j++) {
			int k = n-i-j;
			if (k < 0)
				break;
			if (10000*i+5000*j+1000*k == y) {
				cout << i << " " << j << " " << k << endl;
				return 0;
			}
		}
	}
	cout << "-1 -1 -1" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

int main (int argc, char *argv[]) {
    int H, W;
    cin >> H >> W;
    cin.ignore();
    char grid[H][W];
    int ans[H][W];
    for (int y = 0; y < H; ++y) {
        string str;
        getline(cin, str);
        for (int x = 0; x < W; ++x) {
            grid[y][x] = str[x];
            ans[y][x] = -1;
        }
    }

    for (int t = 0; t < W; ++t) {
        // move
        for (int y = 0; y < H; ++y) {
            for (int x = W - 2; x >= 0; --x) {
                if (t > 0) {
                    grid[y][x+1] = grid[y][x];
                    grid[y][x] = '.';
                }
            }
        }
        // check
        for (int y = 0; y < H; ++y) {
            for (int x = 0; x < W; ++x) {
                if (grid[y][x] == 'c' && ans[y][x] == -1) {
                    ans[y][x] = t;
                }
            }
        }
    }

    for (int y = 0; y < H; ++y) {
        bool first = true;
        for (int x = 0; x < W; ++x) {
            if (first) {
                cout << ans[y][x];
                first = false;
            }
            else cout << " " << ans[y][x];
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3168
#include <iostream>
using namespace std;
int n, d[100], res = 0;
int main(void){
    // Your code here!
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> d[i];
    
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            if (d[i] == d[j]) d[j] = 0;
        }
    }
    for (int i = 0; i < n; i++) {
        if (d[i] != 0) res++;
    }
    cout << res << endl;
}


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

int main(void){
    using namespace  std;

    long N;
    cin >> N;

    long root = (long)floor(sqrt(N));
    long ret = N - 1;
    for (long i = 2; i <= root; i++) {
        if(N%i==0){
            long candidate = i + N / i - 2;
            if(candidate < ret)
                ret = candidate;
        }
    }

    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    
    int a,b;
    cin >>a>>b;
    
    if(a<b){
        cout <<"a < b"<<endl;
    }else if(a>b){
        cout <<"a > b"<<endl;
    }else if(a==b){
        cout <<"a == b"<<endl;
        
    }
    
    
}



Measured memory_bytes: 3064
/* {{{ */
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
/* }}} */

fn main() {
    input! {
        a: i64,
        b: i64,
        c: i64,
        k: i64,
    }
    use std::cmp::min;
    let mut k = k;
    let a = min(a,k);
    k -= a;
    let b = min(b,k);
    k -= b;
    let c = min(c,k);
    println!("{}", a-c);
}
/* vim:set foldmethod=marker: */


Measured memory_bytes: 2112
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		
		Scanner scan = new Scanner(System.in);
		
		while(true){
			String str[] = scan.nextLine().split(" ");
			int h = Integer.parseInt(str[0]);
			int w = Integer.parseInt(str[1]);
			if(h==0 && w==0) break;
			for(int i=0; i<h; i++){
				for(int j=0; j<w; j++){
					System.out.print("#");
				}
				System.out.println();
			}
			System.out.println();
		}
	}
} 

Measured memory_bytes: 26716
#include<stdio.h>
long long dp[51][5001];
main(){
    int N,P;
    int A[50];
    scanf("%d%d",&N,&P);
    for(int i = 0;i < N;i++){
        scanf("%d",&A[i]);
    }
    dp[0][0] = 1;
    for(int i = 1;i <= N;i++){
        for(int j = 0;j < 5001;j++){
            dp[i][j] = dp[i-1][j];
            if(j >= A[i-1]){
                dp[i][j] += dp[i-1][j-A[i-1]];
            }
        }
    }
    long long count = 0;
    for(int i = P;i < 5001;i+=2){
        count += dp[N][i];
    }
    printf("%lld\n",count);
}

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

#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];

int getChar(char ch){
  if(ch=='A') return 1;
  else if(ch=='C') return 2;
  else if(ch=='G') return 3;
  else if(ch=='T') return 4;
  else return 0;
}

long long getkey(char str[]){
  long long sum=0,p=1,i;
  for(i=0;i<strlen(str);i++){
    sum+=p*(getChar(str[i]));
    p*=5;
  }
  return sum;
}

int h1(int key){return key % M;}
int h2(int key){return 1+(key%(M-1));}

int find(char str[]){
  long long key,i,h;
  key=getkey(str);
  for(i=0;;i++){
    h=(h1(key)+i*h2(key)) %M;
    if(strcmp(H[h],str)==0) return 1;
    else if (strlen(H[h])==0) return 0;
  }
  return 0;
}

int insert(char str[])
{
  long long key,i,h;
  key=getkey(str);
  for(i=0;;i++){
    h=(h1(key)+i*h2(key)) %M;
    if(strcmp(H[h],str)==0) return 1;
    else if (strlen(H[h])==0){
      strcpy(H[h],str);
      return 0;
    }
  }
  return 0;
}


int main(){
  int i,n,h;
  char str[L],com[9];
  for(i=0;i<M;i++) H[i][0]='\0'
;  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s %s",com,str);
    if(com[0]=='i'){
      insert(str);
    }else{
      if(find(str)){
	printf("yes\n");
      }else{
	printf("no\n");
      }
    }
  }
  return 0;
}




Measured memory_bytes: 16036
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import *
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    m, d = LI()
    ans = 0
    for i in range(1, m + 1):
        for j in range(10, d + 1):
            if int(str(j)[0]) < 2 or int(str(j)[1]) < 2:
                continue
            if i == int(str(j)[0]) * int(str(j)[1]):
                ans += 1
    print(ans)
    return

#B
def B():
    n, l = LI()
    a = LI()
    d0 = defaultdict(int)
    d1 = defaultdict(int)
    for i in a:
        d0[i] += 1
    for i in range(n):
        b = 0
        for k in range(i+1, n):
            if a[i] > a[k]:
                b += 1
        d1[i] = b
    ans = 0
    d2 = list(d0.items())
    d2.sort()
    d3 = defaultdict(int)
    d = 0
    for key, value in d2:
        d3[key] = d
        d += value
    for i in range(n):
        ans += d3[a[i]] * l * (l-1) // 2 + d1[i] * l
        ans %= mod
    print(ans % mod)
    return

#C
def C():
    n = II()
    s = S()
    lis = [0]
    for i in range(2 * n - 1):
        lis.append(lis[-1] ^ (s[i] == s[i+1]))
    l = [0] * (2 * n)
    for i in range(2 * n):
        l[i] += l[i - 1] + (lis[i] == 0)
    ans = 1
    if l[-1] != n or s[0] == "W":
        print(0)
        return
    k = 1
    for i in range(2 * n):
        if lis[i]:
            ans *= l[i] - (k - 1)
            ans %= mod
            k += 1
    print(ans * math.factorial(n) % mod)
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    C()


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

int main(void) {
	int N, K;
	char S[64];
	if (scanf("%d%d", &N, &K) != 2) return 1;
	if (scanf("%63s", S) != 1) return 1;
	S[K - 1] = tolower((unsigned char)S[K - 1]);
	puts(S);
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define int long long 
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define all(a) a.begin(),a.end()
#define ld long double
#define ub upper_bound
#define lb lower_bound
#define pii pair<int,int>
using namespace std;
int mod = 1e9+7;
int mul(int a,int b){
    return ((a%mod)*(b%mod))%mod;
}
int power(int a,int b){
    int res = 1;
    while(b!=0){
        if(b&1)
            res = mul(res,a);
        b = b/2;
        a = mul(a,a);
    }
    return  res;
}
signed main(){
    fast;
    int n;
    cin>>n;
    int ans = 0;
    map<int,int> mp;
    for(int i=1;i<=n;i++){
        int x;
        cin>>x;
        mp[x]++;
    }
    if(n%2 == 0){
        if(mp.find(0)!=mp.end()){
            cout<<0;
        }
        else{
            for(auto it:mp){
                if(it.second!=2){
                    cout<<0;
                    return 0;
                }
            }
            cout<<power(2,n/2);
        }
    }
    else{
        if(mp[0]!=1){
            cout<<0;
        }
        else{
            for(auto it:mp){
                if(it.first == 0)
                    continue;
                if(it.second!=2){
                    cout<<0;
                    return 0;
                }
            }
            cout<<power(2,n/2);
        }
    }
}
   
    

Measured memory_bytes: 4224
import sys

input = sys.stdin.readline

N = int(input())
a = list(map(int, input().split()))
if 0 in a:
    print(0)
    exit()
c = 1
l = 10 ** 18
for i in a:
    c *= i
    if c > l:
        print(-1)
        exit()

print(c)

Measured memory_bytes: 21608
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

#define lpsbd(i, s, b, d) for(size_t i = (s); i < (b); i+=(d))
#define lpsb(i, s, b) for(size_t i = (s); i < (b); i++)
#define lpn(i, n) for(size_t i = 0; i < (n); i++)
#define fa(i, x) for(auto &i: x)
#define vcd(t, n, d) vector<t>(n, d)
#define vc(t, n) vector<t>(n)

using namespace std;
using ull = unsigned long long;

const ull MOD = 1000000007;

int main(void)
{
    int r, D, x;
    cin >> r >> D >> x;
    lpn(i, 10) cout << (x = r * x - D) << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
S = input()

flag = 1
if N%2 == 0:
    n = N//2
    for i in range(n):
        if S[i] != S[i+n]:
            flag = 0
    if flag:
        print('Yes')
    else:
        print('No')
else:
    print('No')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);

int main(){
  int x, y;
  cin >> x >> y;

  bool flg = false;
  for (int a = 0; a <= 100; a++) {
    for (int b = 0; b <= 100; b++) {
      if (a + b == x && (2 * a) +(4 * b) == y) {
        cout << "Yes" << endl;
        flg = true;
      }
    }
  }
  if (!flg) {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3640
#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

long long  x, y, a, b, c;
vector<long long > red, green, cless;
vector<long long > pred, pgreen, pcless;

long long  f(long long  i, long long  j) {
	if (i<0 or i > a or j<0 or j > b or x - i + y - j < 0 or x - i + y - j > c) return 0;
	return pred[i] + pgreen[j] + pcless[x - i + y - j];
}

int main() {

	cin >> x >> y >> a >> b >> c;
	red.resize(a + 1, 0), green.resize(b + 1, 0), cless.resize(c + 1, 0);

	for (long long  i = 1; i <= a; i++) cin >> red[i];
	for (long long  i = 1; i <= b; i++) cin >> green[i];
	for (long long  i = 1; i <= c; i++) cin >> cless[i];

	sort(red.begin() + 1, red.end(), greater<long long >());
	sort(green.begin() + 1, green.end(), greater<long long >());
	sort(cless.begin() + 1, cless.end(), greater<long long >());

	pred.resize(a + 1, 0), pgreen.resize(b + 1, 0), pcless.resize(c + 1, 0);

	for (int i = 1; i <= a; i++) pred[i] = pred[i - 1] + red[i];
	for (int i = 1; i <= b; i++) pgreen[i] = pgreen[i - 1] + green[i];
	for (int i = 1; i <= c; i++) pcless[i] = pcless[i - 1] + cless[i];

	long long ans = 0;

	for (int i = 0; i <= x; i++) {
		long long  lo = max(0ll, x + y - c - i), hi = min(y, x + y - i);
		while (hi - lo >= 3) {
			long long  m1 = lo + (hi - lo) / 3;
			long long  m2 = hi - (hi - lo) / 3;

			if (f(i, m1) <= f(i, m2)) lo = m1;
			else hi = m2;
		}
		for (int j = lo; j <= hi; j++) ans = max(ans, f(i, j));
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 7900
package main
import "fmt"
func main() {
  var n,m int
  var s string
  fmt.Scan(&n,&m)
  a := make([]int64,n)
  b := make([]int64,m)
  for i:=0;i<n;i++ {
    fmt.Scan(&s)
    for j:=0;j<n;j++ {
      if s[j:j+1] == "#" { a[i] |= 1<<uint(j) }
    }
  }
  for i:=0;i<m;i++ {
    fmt.Scan(&s)
    for j:=0;j<m;j++ {
      if s[j:j+1] == "#" { b[i] |= 1<<uint(j) }
    }
  }
  for i:=0;i<n-m+1;i++ {
    Mid:
    for j:=0;j<n-m+1;j++ {
      for k:=0;k<m;k++ {
        if ((a[i+k]>>uint(j))&b[k]) != b[k] { continue Mid }
      }
      fmt.Println("Yes")
      return
    }
  }
  fmt.Println("No")
}

Measured memory_bytes: 512
while True:
    a,b,c=map(int,input().split())
    sum=0
    count=0
    if a==-1 and b==-1 and c==-1 :
        break
    elif a==-1 or b==-1:
        sum+=0
    else:
        sum+=a+b
    if 0<=sum<=29:
        print("F")
    elif 30<=sum<=49:
        if c>=50:
            print("C")
            count+=1
        else:
            print("D")
            
    elif 50<=sum<=64 and count==0:
        print("C")
    elif 65<=sum<=79:
        print("B")
    else:
        print("A")


Measured memory_bytes: 5592
result1 = 0
S = input()
l = len(S)
for i in range(l):
  if i % 2 == 0:
    if S[i] == "0":
      result1 += 1
  else:
    if S[i] == "1":
      result1 += 1
print(min(result1,l - result1))

Measured memory_bytes: 9156
#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <ctime>
#include <cstdlib>
#include <queue>
#include <cstring>
#include <cassert>
#include <bitset>

using namespace std;

#define mp make_pair
#define f first
#define s second
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define sqr(x) ((x)*1ll*(x))

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;

#define ROOT 1,0,n
#define LS v+v,l,mid
#define RS v+v+1,mid+1,r

int n, k;
int a[200200];
ll s[200200];
pll b[200200];

int t[4 * 200200];

void add(int v, int l, int r, int pos) {
    if(l == r) {
        t[v]++;
        return;
    }
    int mid = (l + r) >> 1;
    if(pos <= mid) add(LS, pos);
    else add(RS, pos);
    t[v] = t[v+v] + t[v+v+1];
}

int get(int v, int l, int r, int L, int R) {
    if(r < L || R < l) return 0;
    if(L <= l && r <= R) return t[v];
    int mid = (l + r) >> 1;
    return get(LS, L, R) + get(RS, L, R);
}

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

    cin >> n >> k;
    for(int i = 1; i <= n; ++i) {
        cin >> a[i];
        a[i] -= k;
        s[i] = s[i-1] + a[i];
        b[i] = mp(s[i], i);    
    }
    b[0] = mp(0, 0);
    sort(b, b + n + 1);
    for(int i = 0, j = 0; i <= n; ++i) 
        s[b[i].s] = j++;
    ll ans = 0;
    for(int i = 0; i <= n; ++i) {
        ans += get(ROOT, 0, s[i]);
        add(ROOT, s[i]);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 8832
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define INF (ll)(1e18)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }




vector<int> v() {
    const int maxn = 200000;
    vector<int> table(maxn);
    table[0] = 1;
    table[1] = 1;
    for (int i = 2; i * i <= maxn; ++i) {
        int j = 2;
        while (i * j <= maxn) {
            table[i * j] = 1;
            j++;
        }
    }
    vector<int> ans;
    rep(i, maxn) if (table[i] == 0) ans.eb(i);
    // rep(i, 100) cout << ans[i] << " "; cout << endl;
    return ans;
}

void solve() {
    /*
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    */
    
    int x;
    cin >> x;
    auto V = v();
    int it = lower_bound(all(V), x) - V.begin();
    cout << V[it] << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    int T;
    // cin >> T;
    T = 1;
    while (T--) {
        solve();
        // cout << (solve() ? "YES" : "NO") << endl;
    }
}


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

int main() {
  int N;
  int num;
  int counter,res,max_num = 0;
  
  cin >> N;

  for(int i = 1;i <= N;i++){
    num = i;
    while(num % 2 == 0){
      num /= 2;
      res++;
    }
    if(counter <= res){
      max_num = i;
      counter = res;
    }
    res = 0;
  }

  cout << max_num << endl;
}

Measured memory_bytes: 256
import java.util.*;
class Main{
	static Scanner s = new Scanner(System.in);
	public static void main(String[] args){
		int m,f,r;
		while (s.hasNext()) {
			m = Integer.parseInt(s.next());
			f = Integer.parseInt(s.next());
			r = Integer.parseInt(s.next());

			if(m==-1||f==-1) {
				if(m==f&&f==r)
					return;
				else
					System.out.println("F");
				continue;
			}

			if(m+f>=80)
				System.out.println("A");
			else if(m+f>=65)
				System.out.println("B");
			else if(m+f>=50)
				System.out.println("C");
			else if(m+f>=30) {
				if(r>=50)
					System.out.println("C");
				else
					System.out.println("D");
			}else
				System.out.println("F");
		}
	}
}

Measured memory_bytes: 26064
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let a: String = read();
    let b: String = read();

    if a.len() > b.len() {
        println!("GREATER");
    } else if a.len() < b.len() {
        println!("LESS");
    } else {
        let mut ab = a
            .chars()
            .zip(b.chars())
            .skip_while(|&(a_c, b_c)| a_c == b_c);
        match ab.next() {
            None => println!("EQUAL"),
            Some((a_c, b_c)) => if a_c > b_c {
                println!("GREATER");
            } else {
                println!("LESS");
            },
        }
    }
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
const int N=200005;
int n,k,a[N];
char s[N];
int main(){
	cin >> n >> k >> s+1;
	for (int i=1;i<=n;i++)
		a[i]=s[i]-'A';
	int t=0,h=1;
	while (k--){
		if (!(a[h]^t)){
			a[h]^=1;
			continue;
		}
		if (!((a[h+1]^t)&1))
			a[h]^=1;
		t^=1,h++;
		if (h==n)
			break;
	}
	if (k>0&&(n&1))
		a[h]^=k&1;
	else if (k>0)
		h++;
	for (int i=h;i<=n;i++)
		putchar('A'+(a[i]^t));
	for (int i=n-h+2;i<=n;i++)
		putchar('A'+((n-i)&1));
	return 0;
}

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

#define PI 3.14159265359
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descSort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;
ll gcd(ll x,ll y){
    if(x%y==0)return y;
    return gcd(y,x%y);
}
ll LCM(int a, int b){
    return a*b/gcd(a,b);
}

int main(void)
{
    int n;
    cin>>n;
    vector<int> c(n-1),s(n-1),f(n-1);
    rep(i,0,n-1){
        cin>>c[i]>>s[i]>>f[i];
    }

    rep(i,0,n){
        if(i==n-1){ cout<<0<<endl;break;}
        ll arrival=0;
        rep(j,i,n-1){
            if(arrival<s[j]) arrival=s[j];
            else{
                if(arrival%f[j]){
                    ll div=(arrival-s[j])/f[j];
                    arrival=s[j]+div*f[j]+f[j];
                }
            }
            arrival+=c[j];
        }
        cout<<arrival<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))
dp = [[0]*3 for _ in [0]*N]
dp[0] = [1, 1, 1]
ans = 0

for i, (n1, n2) in enumerate(zip(a, a[1:]), start=1):
    if n1 != n2:
        for j in range(3):
            dp[i][j] = dp[i-1][j]+1
    else:
        dp[i][0] = 1
        if dp[i-1][2] > ans:
            ans = dp[i-1][2]
        for j in range(2, 0, -1):
            dp[i][j] = dp[i-1][j-1]+1

print(max(max(dp[-1]), ans))


Measured memory_bytes: 25868
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;


int main() {
	int D, N;
	cin >> D >> N;
	int cnt = 0;
	for (int i = 1; i < mod; i++) {
		int c = 0;
		int tmp = i;
		while (tmp % 100 == 0) {
			tmp /= 100;
			c++;
		}
		if (c == D) cnt++;
		if (cnt == N) {
			cout << i << endl;
			return 0;
		}
	}
}


Measured memory_bytes: 3608
MOD = 10**9 + 7
I = lambda:list(map(int,input().split()))

n , k =I()
a = I()
m = 10**10
for i in range(n - k + 1):
	m = min(m , a[i+k-1] - a[i] + min(abs(a[i]) , abs(a[i+k-1])))
print(m)

Measured memory_bytes: 14480
h,w=map(int,input().split())
s=[]
for _ in range(h):
    a=list(input())
    s.append(a)
grid=[[0 for _ in range(w)] for _ in range(h)]
dx=[-1,0,1,-1,1,-1,0,1]
dy=[1,1,1,0,0,-1,-1,-1]
for i in range(h):
    for j in range(w):
        if s[i][j]=="#":
            grid[i][j]="#"
            for t in range(8):
                ny=i+dy[t]
                nx=j+dx[t]
                if 0 <= ny <= h-1 and 0<= nx <= w-1 and grid[ny][nx] != "#":
                    grid[ny][nx]+=1
for row in grid:
    print(*row,sep="")





Measured memory_bytes: 3572
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

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

const int infI=1e9+5;
const long long infL=1e16;
const int MOD=1e9+7;
const int MAX=2e5+5;

#define mp make_pair
#define in &
#define pb push_back
#define ii pair<int,int>
#define iii pair<ii,int>
#define ll long long
#define pll pair<ll,ll>
#define vvl vector<vector<ll> >
#define vi vector<int>
#define vvi vector<vector<int> >
#define vl vector<ll>
#define eb emplace_back
#define forn(i,a,b) for(ll i=a;i<b;i++)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define endl '\n'
#define popb pop_back()
#define se second
#define fi first
#define test(t) int t;cin>>t;while(t--)
#define debug(x) cerr<<"=>"<<#x<<" = "<<x<<endl

ll power(ll a,ll b){
    if(b==0){
        return 1;
    }
    if(b==1){
        return a;
    }
    ll temp=power(a,b/2);
    temp=(temp*temp)%MOD;
    if(b%2){
        temp=(temp*a)%MOD;
    }
    return temp;
}

//only use if mod is prime
ll mod_inv(ll a,ll mod){
    a%=mod;
    return power(a,mod-2);
}

void extended_gcd(ll a,ll b,ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return;
    }
    ll x1,y1;
    extended_gcd(b,a%b,x1,y1);
    x=y1;
    y=x1-((a/b)*y1);
    return;
}

//TLE can also occur if vectors are not passed by reference
//priority_queue implements max heap by default

int main(){
    fastio;
    // think about edge cases like n=1,n=MAX etc.
    int a;
    cin>>a;
    int b = a+pow(a,2)+pow(a,3);
    cout<<b;
    return 0;
}

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

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
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; }
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

#define MAX_V 1000000
vector<int> divisor(int n) {
	vector<int> res;
	for(int i = 1; i * i <= n; i++) {
		if(n % i == 0) {
			res.push_back(i);
			if(i != n / i) res.push_back(n / i);
		}
	}
	return res;
}

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

  int n;
  cin >> n;
  int rsl = 0;
  rep(i, 1, n + 1) {
    if(i % 2 == 0) continue;
    vector<int> tmp = divisor(i);
    if(tmp.size() == 8) rsl++;
  }
  cout << rsl << endl;

}



Measured memory_bytes: 256
// *e**** ********e* *e****e* ****e**


#include <iostream>
#include <vector>
#include <math.h>
#include <string>

using namespace std;

int main()
{
    int N,K;
    string S;
    cin >> N >> S >> K;

    char r = S[K-1];
    for (int i = 0; i < N; i++) {
        if (r != S[i]) {
            S[i] = '*';
        }
    }

    cout << S << endl;

    return 0;
}


Measured memory_bytes: 256