akhauriyash/Code-Regression huggingface dataset:
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

//debug
//--------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//IO accelerate
//--------------------------------------------
struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

//template
//--------------------------------------------
template<typename T>
istream& operator >>(istream& is, vector<T>& vec) {
  for(T& x: vec) is >> x;
  return is;
}
template<typename T>
ostream& operator <<(ostream& os, const vector<T>& vec) {
  for(int i=0; i<vec.size(); i++){
    os << vec[i] << ( i+1 == vec.size() ? "" : "\t" );
  }
  return os;
}
template<typename T>
ostream& operator <<(ostream& s, const vector<vector<T>>& vv) {
	for (int i = 0; i < vv.size(); ++i) {
		s << vv[i] << endl;
	}
	return s;
}

// 多重vector
// auto dp=make_v<int>(4,h,w) みたいに使える
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

// 多重vectorのためのfill
// fill_v(dp,0) みたいに使える
template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

//main code

int main(int argc, char *argv[])
{
	LL n,a,b;
	cin >> n >> a >> b;
	if (abs(a-b)%2) {
		LL bb = min(b,a);
		LL aa = max(b,a);
		cout << min(bb + max(0LL, (aa-bb-1)/2),n-aa+1 + max(0LL, (aa-bb-1)/2)) << endl;
	} else {
		cout << abs(a-b)/2 << endl;
	}
	return 0;
}


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

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

  bool ans=false;
  for(int i=1; i<10; ++i){
    if(n%i==0 && 1<=n/i && n/i<=9)ans=true;
  }

  if(ans)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  
}


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

int main() {
    ll n,w;
    cin>>n>>w;
    vector<vector<ll>>vect(n,vector<ll>(2));
    for(int i=0 ; i<n ; i++){
        cin>>vect[i][0]>>vect[i][1];
    }
    vector<vector<ll>> dp(n,vector<ll>(100005,INT_MAX));
    dp[0][vect[0][1]]=vect[0][0];
    for(int i=1 ; i<n ; i++){
        dp[i-1][0]=0;
        for(int j=0 ; j<100001 ; j++){
            
            if(dp[i-1][j]!=INT_MAX && j+vect[i][1]<=100000){
                dp[i][j]=min(dp[i][j],dp[i-1][j]);
                dp[i][j+vect[i][1]]=min(dp[i][j+vect[i][1]],dp[i-1][j]+vect[i][0]);
            }
        }
    }
    int ans=0;
    for(int i=0 ; i<100001 ; i++){
        if(dp[n-1][i]<=w)
        ans=i;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 79488
#include<bits/stdc++.h>
using namespace std;
main()
{
    long long i,j,k,l;
    while(cin>>i){
        j=0; k=1;
        while(i>=1){
          j+=k;
          k*=2;
          i/=2;

        }
        cout<<j<<endl;
    } return 0;

}


Measured memory_bytes: 256
n,m,l = map(int,input().split())
road = [[10**18 for _ in range(n)] for _ in range(n)]
for _ in range(m):
  a,b,c = map(int,input().split())
  a -= 1
  b -= 1
  road[a][b] = c
  road[b][a] = c
#print(road)
for k in range(n):
  for i in range(n):
    for j in range(n):
      road[i][j] = min(road[i][j],road[i][k]+road[k][j])
#print(road)
cango = [[1000 for _ in range(n)] for _ in range(n)]
for i in range(n):
  for j in range(n):
    if road[i][j] == 0:
      cango[i][j] = 0
    elif road[i][j] <= l:
      cango[i][j] = 1
#print(cango)
for k in range(n):
  for i in range(n):
    for j in range(n):
      cango[i][j] = min(cango[i][j],cango[i][k]+cango[k][j])
#print(cango)
q = int(input())
for _ in range(q):
  s,t = map(int,input().split())
  ans = cango[s-1][t-1]-1
  if ans > 500:
    print(-1)
  else:
    print(ans)

Measured memory_bytes: 60504
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var N = sc.ReadInt();
        if (N == 1)
        {
            Console.WriteLine("Hello World");
        }
        else
        {
            var A = sc.ReadInt();
            var B = sc.ReadInt();
            Console.WriteLine(A + B);
        }
    }
    static Scanner sc = new Scanner();
}

class Scanner
{
    string[] S = new string[0];
    int Index = 0;
    char[] Separators = new char[] { ' ' };

    public string Next()
    {
        if (this.Index < this.S.Length) return this.S[this.Index++];
        var line = "";
        while (line == "") line = Console.ReadLine();
        this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
        if (this.S.Length == 0) return this.Next();
        this.Index = 0;
        return this.S[this.Index++];
    }
    public string ReadStr()
    {
        return this.Next();
    }
    public char ReadChar()
    {
        return this.Next()[0];
    }
    public int ReadInt()
    {
        return int.Parse(this.Next());
    }
    public uint ReadUInt()
    {
        return uint.Parse(this.Next());
    }
    public long ReadLong()
    {
        return long.Parse(this.Next());
    }
    public double ReadDouble()
    {
        return double.Parse(this.Next());
    }
    public int[] ReadIntArray(int n)
    {
        var array = new int[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadInt();
        }
        return array;
    }
    public long[] ReadLongArray(int n)
    {
        var array = new long[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadLong();
        }
        return array;
    }
    public double[] ReadDoubleArray(int n)
    {
        var array = new double[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadDouble();
        }
        return array;
    }
    public char[] ReadCharArray(int n)
    {
        var array = new char[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadChar();
        }
        return array;
    }
    public string[] ReadStrArray(int n)
    {
        var array = new string[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadStr();
        }
        return array;
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int n = (int)s.size();
	string s1;
	int ans = 0;
	for(int i = 0; i < n; i++)
	{
		if(s[i] != s[n-i-1]) ans++;
	}
	cout<<ans/2;
}


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

using namespace std;

double d[3000][3000];

int main(){
	int n; cin >> n;
	double p[n];
	for (int i = 0; i < n; ++i)
	{
		cin >> p[i];
	}
	d[0][0] = 1-p[0]; d[0][1] = p[0];
	for (int i = 1; i < n; ++i)
	{
		d[i][0] = d[i-1][0]*(1-p[i]);
		for (int j = 1; j <= i+1; ++j)
		{
			d[i][j] = p[i]*d[i-1][j-1] + (1-p[i])*d[i-1][j];
		}
	}
	double ans = 0;
	for(int i = n/2 + 1; i <= n; ++i){
		ans += d[n-1][i];
	}
	cout << setprecision(10) << ans;
}

Measured memory_bytes: 49912
#include<bits/stdc++.h>
#define rep(i,n,k) for(long long int i=k; i<n; ++i)
#define drep(i,n,k) for(long long int i=n-1; i>=k; --i)
using namespace std;

int main(){
  long long int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  
  vector<long long int> vec;
  long long int sum = 1;
  rep(i,n-1,0){
    if(s[i] == s[i+1]) sum++;
    else{
      vec.push_back(sum);
      sum = 1;
    }
  }
  vec.push_back(sum);
  
  rep(i,k,0){
    long long int v = vec.size();
    if(v >= 3){
      vec[v-2] += vec[v-1];
      vec.pop_back();
      vec[v-3] += vec[v-2];
      vec.pop_back();
    }
    else if(v == 2){
      vec[0] += vec[1];
      vec.pop_back();
    }
    else break;
  }
  
  long long int ans = 0;
  rep(i,vec.size(),0) ans += vec[i]-1;
  cout << ans << endl;
}

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

using namespace std;

int main(){
  string s, t;
  map<char,vector<long long>> mp;
  cin >> s >> t;
  for(long long i=0;i<s.length();i++)mp[s[i]].push_back(i);
  for(int i=0;i<t.length();i++){
    if(mp[t[i]].size()==0){
      cout << -1 << endl;
      return 0;
    }
  }
  long long ans=0;
  long long cur=-1;
  map<char, long long> idx;
  for(int i=0;i<t.length();i++){
    char c = t[i];
    long long v_size=mp[c].size();
    while(idx[c]<v_size && mp[c][idx[c]]<=cur){
      idx[c]++;
    }
    if(idx[c]==mp[c].size()){
      for(auto& p: idx){
        idx[p.first]=0;
      }
      cur=mp[c][0];
      ans+=s.length();
    }
    else{
      cur=mp[c][idx[c]];
    }
  }
  char last = t[t.length()-1];
  ans += mp[last][idx[last]]+1;
  cout << ans << endl;
}



Measured memory_bytes: 1728
#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()
typedef long long ll;
using namespace std;
int main(){
	int e,y;cin>>e>>y;
	if(e==0){
		if(y<=1911){
			cout<<"M"<<y-1868+1<<endl;
		}else if(y<=1925){
			cout<<"T"<<y-1912+1<<endl;
		}else if(y<=1988){
			cout<<"S"<<y-1926+1<<endl;
		}else{
			cout<<"H"<<y-1989+1<<endl;
		}
	}else if(e==1){
		cout<<1868+y-1<<endl;
	}else if(e==2){
		cout<<1912+y-1<<endl;
	}else if(e==3){
		cout<<1926+y-1<<endl;
	}else{
		cout<<1989+y-1<<endl;
	} 
}



Measured memory_bytes: 3136
n,m = map(int,input().split())
import copy
def bfs(graph,s,g):
    que = [s]
    visited = []
    while len(que)>0:
        label = que.pop(0)
        for nv in graph[label]:
            if nv == g:
                return 1
            if nv not in visited:
                visited.append(nv)
                que.append(nv)
    return 0

def main():
    graph = {}
    for i in range(n):
        graph[i] = []
    for _ in range(m):
        s,g = map(int,input().split())
        graph[s-1] += [g-1]
        graph[g-1] += [s-1]

    ans = 0
    for i in range(n):
        for k in graph[i]:
            g = copy.copy(graph)
            if k>i:
                g[i] = list(set(g[i])-set([k]))
                if bfs(g,i,k)==0:
                    ans += 1
    print(ans)
if __name__ == "__main__":
    main()

Measured memory_bytes: 3572
#include <iostream>

using namespace std;

int reverse ( int x ) {
  int ans = 0, rank = 1;
  int rerank = 1;

  while( rank < x ) rank *= 10; rank /= 10;

  while ( x > 0 ) {
    int tmp = x/rank;
    x = x % rank;
    ans += tmp*rerank;
    rank /= 10;
    rerank *= 10;
  }

  return ans;
}

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

  if ( reverse(n) == n ) cout << "Yes\n";
  else cout << "No\n";
}


Measured memory_bytes: 888
def main():
    N, M = map(int, input().split())
    A = []
    for _ in range(N):
        a,b = map(int, input().split())
        A.append([a,b])

    sort_A = sorted(A)
    cnt = 0
    money = 0
    for i in range(N):
        if cnt + sort_A[i][1] >= M:
            money += (M - cnt) * sort_A[i][0]
            break
        money += sort_A[i][0] * sort_A[i][1]
        cnt += sort_A[i][1]

    print(money)

main()

Measured memory_bytes: 60504
from collections import defaultdict
from collections import deque
import sys
sys.setrecursionlimit(10**6)

N, K = map(int, input().split())
ab = defaultdict(list)
for i in range(N-1):
    a, b = map(int, input().split())
    ab[a-1].append(b-1)
    ab[b-1].append(a-1)

MOD = 10**9+7


def dfs(v, pv, n):
    k = K-1 if pv == -1 else K-2
    a = 1
    for u in ab[v]:
        if u != pv:
            a *= dfs(u, v, k)
            a %= MOD
            k -= 1
    return a*n % MOD


print(dfs(0, -1, K))


Measured memory_bytes: 96180
/* ex 9_1
   yy8332 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//スタックに格納するデータの最大数
#define SIZE 100

//スタックの定義
typedef struct stack{
  int size;
    int count;
    char data[SIZE];
    char *top;
  } stack;

//スタックの初期化
void initialize_stack(stack *stk){
  stk->count = 0;
  stk->size = SIZE;
  stk->top = &(stk->data[SIZE]);
}

//データの追加
void push(stack *stk, char elem){
  if(stk->count >= stk->size){
    fprintf(stderr, "Error: stack overflow. (x=%c)\n", elem);
    exit(1);
  }
  else{
    stk->top--;
    *(stk->top) = elem;
    stk->count++;
  }
}

//データの取り出し
char pop(stack *stk){
  char latest;
  if(stk->count <= 0){
    fprintf(stdout, "Error: stack underflow.\n");
    exit(1);
  }
  else{
    latest = *(stk->top);
    stk->top++;
    stk->count--;
    return latest;
  }
}

int main(void){
  stack stk;
  char input[11], str1[11], str2[11];
  int len1, len2, i;
  //スタックを初期化（ポインタ渡しで関数にわたすこと）
  initialize_stack(&stk);

  //入力読み取り
  scanf("%s", input);

  //入力文字列の長さ取得
  len1 = strlen(input);

  //入力で場合分けしてstackを操作
  for(i = 0; i < len1; i++){
    if(input[i] == 'B' && stk.count != 0){
      pop(&stk);
    }
    else if(input[i] == '0' || input[i] == '1'){
      push(&stk, input[i]);
    }
  }

  //出力文字列の長さ取得
  len2 = stk.count;

  //出力
  for(i = 0; i < len2; i++){
    str1[i] = pop(&stk);
  }
  for(i = 0; i < len2; i++){
    str2[i] = str1[(len2 - 1) - i];
  }
  str2[len2] = '\0';

  printf("%s\n", str2);

  return 0;
}


Measured memory_bytes: 1604
import java.util.*;

public class Main {
 
  public static void main(String[] args) {
  	Scanner sc = new Scanner(System.in);
    String S = sc.nextLine();
    String T = sc.nextLine();
    
    int ans = 0;
    for (int i = 0; i < S.length(); i++) {
      if (S.charAt(i) != T.charAt(i)) {
        ans++;
      }
    }
    
    System.out.println(ans);
  }
}


Measured memory_bytes: 42428
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()
arr=deque(limii())
b=deque([])
for i in range(n):
    if i%2==1:
        x=arr.popleft()
        b.appendleft(str(x))

    else:
        x=arr.popleft()
        b.append(str(x))
if n%2==0:
    print(" ".join(list(b)))
else:
    print(" ".join(list(reversed(list(b)))))


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

namespace AtCoder
{
	public class ABC
	{
		static void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });


			string s = Console.ReadLine();
			long k = int.Parse(Console.ReadLine());

			string s2;
			long ans = 0;
			if (k < 4) {
				s2 = s;
				for (int i = 1; i < k; i++) {
					s2 += s;
				}
				char c = s2[0];
				for (int i = 1; i < s2.Length; i++) {
					if (c == s2[i]) {
						ans++;
						c = ' ';
					} else {
						c = s2[i];
					}
				}
			} else {
				int[] cnt = new int[5];
				if (k % 2 == 0) {
					s2 = s + s + s + s;
				} else {
					s2 = s + s + s + s + s;
				}
				char c = s2[0];
				for (int i = 1; i < s2.Length; i++) {
					if (c == s2[i]) {
						cnt[i / s.Length]++;
						c = ' ';
					} else {
						c = s2[i];
					}
				}
				long even = k / 2 - (k % 2 == 0 ? 1 : 0);
				long odd = k / 2 + k % 2 - 1 - (k % 2 == 0 ? 0 : 1);
				long last = k % 2 == 0 ? 3 : 4;
				// System.Diagnostics.Debug.WriteLine($"cnt[0]{cnt[0]} + cnt[1]{cnt[1]} * even{even} + cnt[2]{cnt[2]} * odd{odd} + cnt[{last}]{cnt[last]}");
				ans = cnt[0] + cnt[1] * even + cnt[2] * odd + cnt[last];
			}
			Console.WriteLine(ans);


			Console.Out.Flush();
		}
	}
}

Measured memory_bytes: 11220
#a,bの最大公約数
def gcd(a,b):
    while b%a!=0:
        a,b=b,a%b
    return a

#a,bの最小公倍数
def lcm(a,b):
    return a*b//gcd(a,b)

N=int(input())
g=int(input())
for n in range(N-1):
    t=int(input())
    g=lcm(g,t)
print(g)


Measured memory_bytes: 2940
#include <iostream>
#include <math.h>
#include <string>
using namespace std;

int main()
{
    int a , b , m ;
    cin >> a >> b ;
    if(a < 13){
        if(a < 6){
            m = 0 ;
        }
        else{
            m = b/2 ;
        }
    }
    else{
        m = b ;
    }
    cout << m ;
    return 0;
}


Measured memory_bytes: 3616
N,x = map(int,input().split())

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

a.sort()
cnt=0

for i in range(N):
    if x - a[i] >= 0:
        cnt+=1
        x = x-a[i]

if x >0:
    if cnt == 0:
        cnt = 0
    else:
        if cnt == len(a):
            cnt = cnt -1
        
print(cnt)


Measured memory_bytes: 3064
n = int(input())
info = [[] for _ in range(n)]
for i in range(n):
    a = int(input())
    for _ in range(a):
        x, y = map(int, input().split())
        info[i].append((x, y))

# print(info)
ans = 0
for i in range(2**n):
    ok = True
    cnt = 0
    jdg = str(bin(i)[2:]).zfill(n)
    # print(str(bin(i)[2:]).zfill(n))
    for j in range(n):
        if (i >> j) & 1: # 左から見ている
            # print(i, j)
            for x, y in info[j]:
                if jdg[-x] != str(y):
                    ok = False
        if j == n-1:
            cnt = jdg.count('1')

    if ok and ans < cnt:
        ans = cnt

print(ans)
    
        

Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
typedef long long int ll;
using namespace std;
//-------------------------------------------------------------------
int N, K;
const int MAX_N = 100000;
int ran[MAX_N+1];
int tmp[MAX_N+1];
bool compare_sa(int i, int j){
  if(ran[i] != ran[j]) return ran[i] < ran[j];
  else{
    int ri = (i+K<=N?ran[i+K]:-1);
    int rj = (j+K<=N?ran[j+K]:-1);
    return ri < rj;
  }
}
void construct_sa(string S, int *sa){
  N = S.length();
  for(int i=0;i<=N;i++){
    sa[i] = i;
    ran[i] = (i < N ? S[i]:-1);
  }
  for(K=1;K<=N;K*=2){
    sort(sa, sa+N+1, compare_sa);
    tmp[sa[0]] = 0;
    for(int i=1;i<=N;i++) tmp[sa[i]] = tmp[sa[i-1]] + (compare_sa(sa[i-1], sa[i])?1:0);
    for(int i=0;i<=N;i++) ran[i] = tmp[i];
  }
}
bool contain(string S, int *sa, string T){
  int a = 0, b = S.length();
  while(b - a > 1){
    int c = (a+b)/2;
    if(S.compare(sa[c], T.length(), T) < 0) a = c;
    else b = c;
  }
  return S.compare(sa[b], T.length(), T) == 0;
}
void construct_lcp(string S, int *sa, int *lcp){
  int n = S.length();
  for(int i=0;i<=n;i++) ran[sa[i]] = i;
  int h = 0;
  lcp[0] = 0;
  for(int i=0;i<n;i++){
    int j=sa[ran[i]-1];
    if(h>0) h--;
    for(;j+h<n&&i+h<n;h++){
      if(S[j+h]!=S[i+h]) break;
    }
    lcp[ran[i]-1] = h;
  }
}
//-------------------------------------------------------------------
int main(int argc, char const *argv[]) {
  string s;
  int ans = 0;
  std::cin >> N;
  std::cin >> s;
  int sa[MAX_N+1];
  int lcp[MAX_N+1];
  construct_sa(s, sa);
  construct_lcp(s, sa, lcp);
  lcp[N] = 0;
  for(int i=0;i<N;i++){
    int tmp=1000000007, pre = 0;
    for(int j=i;j<N;j++){
      tmp = min(tmp, lcp[j]);
      pre = max(pre, min(abs(sa[i]-sa[j+1]), tmp));
    }
    if(tmp>=10000) continue;
    ans = max(ans, pre);
  }
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 384
#define _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>

using namespace std;

typedef long long ll;

ll index[200100];
ll treenep[800100];
ll treep[800100];

void updatep(ll v, ll tl, ll tr, ll pos, ll val) {
	if (tl == tr) {
		treep[v] = val;
		return;
	}
	ll tm = (tl + tr) / 2;
	if (pos <= tm)updatep(2 * v, tl, tm, pos, val);
	else updatep(2 * v + 1, tm + 1, tr, pos, val);
	treep[v] = min(treep[2 * v], treep[2 * v + 1]);
}
void updatenep(ll v, ll tl, ll tr, ll pos, ll val) {
	if (tl == tr) {
		treenep[v] = val;
		return;
	}
	ll tm = (tl + tr) / 2;
	if (pos <= tm)updatenep(2 * v, tl, tm, pos, val);
	else updatenep(2 * v + 1, tm + 1, tr, pos, val);
	treenep[v] = min(treenep[2 * v], treenep[2 * v + 1]);
}
ll minnp(ll v, ll tl, ll tr, ll l, ll r) {
	if (l > r)return 1000000000;
	if (tl == l && tr == r)return treep[v];
	ll tm = (tl + tr) / 2;
	return min(minnp(2 * v, tl, tm, l, min(r, tm)), minnp(2 * v + 1, tm + 1, tr, max(l, tm + 1), r));
}
ll minnnep(ll v, ll tl, ll tr, ll l, ll r) {
	if (l > r)return 1000000000;
	if (tl == l && tr == r)return treenep[v];
	ll tm = (tl + tr) / 2;
	return min(minnnep(2 * v, tl, tm, l, min(r, tm)), minnnep(2 * v + 1, tm + 1, tr, max(l, tm + 1), r));
}

ll n, temp;

ll calc(ll startindex, ll endindex) {
	if(startindex % 2 == 0)return minnp(1, 0, n - 1, startindex, endindex - 1);
	return minnnep(1, 0, n - 1, startindex, endindex - 1);
}

int main() {
	scanf("%lld", &n);
	for (int i = 0; i < n; i++) {
		scanf("%lld", &temp);
		index[temp] = i;
		if (i % 2 == 0) {
			updatep(1, 0, n - 1, i, temp);
			updatenep(1, 0, n - 1, i, 1000000000);
		}
		else {
			updatenep(1, 0, n - 1, i, temp);
			updatep(1, 0, n - 1, i, 1000000000);
		}
	}
	int counter = 0;
	set<pair<ll,pair<ll, ll>>> minimum;
	minimum.insert(make_pair(calc(0, n - 1), make_pair(0, n - 1)));
	set<pair<ll, pair<ll, ll>>>::iterator it;
	while (counter < n) {
		it = minimum.begin();
		pair<ll, pair<ll, ll>> from = *it;
		minimum.erase(from);
		ll f = from.first, s;
		ll startindex = from.second.first, toindex = from.second.second;
		if (index[f] % 2 == 0)s = minnnep(1, 0, n - 1, index[f] + 1, toindex);
		else s = minnp(1, 0, n - 1, index[f] + 1, toindex);
		printf("%lld %lld ", f, s);
		counter += 2;
		if (startindex < index[f])minimum.insert(make_pair(calc(startindex, index[f] - 1), make_pair(startindex, index[f] - 1)));
		if (index[s] - index[f] > 1)minimum.insert(make_pair(calc(index[f] + 1, index[s] - 1), make_pair(index[f] + 1, index[s] - 1)));
		if (index[s] < toindex)minimum.insert(make_pair(calc(index[s] + 1, toindex), make_pair(index[s] + 1, toindex)));
	}
	return 0;
}

Measured memory_bytes: 17920
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
  string s,t;
  cin>>s;
  cin>>t;
  int x=s.length();
  if(t.compare(0,x,s)==0)
    cout<<"Yes";
  else
    cout<<"No";
  return 0;
  
}

Measured memory_bytes: 3612
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#define rep(i,a,b) for(Int i=a;i<b;++i)
#define rrep(i,a,b) for(Int i=a;i>=b;--i)
using namespace std;

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

    set<char> st;
    int N; cin >> N;
    rep(i, 0, N) {
      char c; cin >> c;
      st.insert(c);
    }
  
    cout << (st.size() == 3 ? "Three" : "Four") << endl;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	log.SetFlags(log.Lshortfile)
	s := nextString()
	for i := 0; i < 3; i++ {
		if s[i] == s[i+1] {
			fmt.Println("Bad")
			return
		}
	}
	fmt.Println("Good")
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

var dy = []int{0, 1, 0, -1}
var dx = []int{1, 0, -1, 0}
var MAX = math.MaxInt32

func pow(a, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}
func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type pair struct {
	a, b int
}

type pairs []pair

func (p pairs) Len() int {
	return len(p)
}
func (p pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p pairs) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return p[i].a < p[j].a
}


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

using namespace std;

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

  string ans = "Possible";
  if (a % 3 && b % 3 && (a + b) % 3) {
    ans = "Impossible";
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int N=1e5+5;
char s[N];int fa[N],b[N],sum[N],vis[N],n,m;
inline int val(R int x){return x<0?x+26:x;}
inline int find(R int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
int main(){
	scanf("%s",s+1),n=strlen(s+1);
	fp(i,1,n+1)s[i]-='a',fa[i]=i;
	s[n+1]=0;
	scanf("%d",&m);
	for(R int i=1,l,r;i<=m;++i)scanf("%d%d",&l,&r),fa[find(r+1)]=find(l);
	fp(i,1,n+1)b[i]=val(s[i]-s[i-1]);
	fp(i,1,(n+1)>>1)fa[find(n+2-i)]=find(i);
//	fp(i,1,n+1)printf("%d ",b[i]);
//	puts("");
	fp(i,1,n+1)sum[find(i)]+=b[i];
	if((n+1)&1^1)vis[find((n+2)>>1)]=1;
	fp(i,1,n+1)if(i==find(i)&&sum[i]%26)
		if(!vis[i])return puts("NO"),0;
	puts("YES");
	return 0;
} 

Measured memory_bytes: 1280
import sys

def solve():
    n = int(sys.stdin.readline())
    ans = 0

    for i in range(n):
        num = int(sys.stdin.readline())

        ans += is_prime(num)

    print(ans)

def is_prime(n):
    if n < 2:
        return False

    for p in range(2, n + 1):
        if p*p > n:
            break
        if n % p == 0:
            return False

    return True

if __name__ == '__main__':
    solve()

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

using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    for(int i = 1; i <= 10000; i++)  {
        int x = (i*8) / 100;
        int y = (i*10) / 100;
        if(x == a && y == b) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 256
//By Tushar Gautam
#pragma GCC optimize ("-O2")
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define memreset(a) memset(a,0,sizeof(a))
#define testcase(t) int t;cin>>t;while(t--)
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i=0;i<e;++i)
#define forsn(i,s,e) for(int i=s;i<e;++i)
#define rforn(i,s) for(int i=s;i>=0;--i)
#define rforsn(i,s,e) for(int i=s;i>=e;--i)
#define bitcount(a) __builtin_popcount(a) // set bits (add ll)
#define ln '\n'
#define getcurrtime() cerr<<"Time = "<<((double)clock()/CLOCKS_PER_SEC)<<endl
#define dbgarr(v,s,e) cerr<<#v<<" = "; forsn(i,s,e) cerr<<v[i]<<", "; cerr<<endl
#define inputfile freopen("input.txt", "r", stdin)
#define outputfile freopen("output.txt", "w", stdout)
#define dbg(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) { cerr<<endl; }
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << "\t"; err(++it, args...);
}
template<typename T1,typename T2>
ostream& operator <<(ostream& c,pair<T1,T2> &v){
	c<<"("<<v.fi<<","<<v.se<<")"; return c;
}
template <template <class...> class TT, class ...T>
ostream& operator<<(ostream& out,TT<T...>& c){
    out<<"{ ";
    forstl(x,c) out<<x<<" ";
    out<<"}"; return out;
}
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> p64;
typedef pair<int,int> p32;
typedef pair<int,p32> p96;
typedef vector<ll> v64;
typedef vector<int> v32; 
typedef vector<v32> vv32;
typedef vector<v64> vv64;
typedef vector<p32> vp32;
typedef vector<p64> vp64;
typedef vector<vp32> vvp32;
typedef map<int,int> m32;
const int LIM=1e6+3,MOD=1e6+3;
int t,n,m,k,x,y,w;
inline ll powm(ll x,ll pw,ll Mod=MOD){ //return (x^pw)%Mod
	x%=Mod;
	ll res=1;
	while(pw){
		if(pw&1LL) res=((res*x))%Mod;
		pw>>=1;
		x=((x*x))%Mod;
	}
	return res;
}
inline ll inv(ll x,ll Mod=MOD){
	return powm(x,Mod-2,Mod); 
}
ll fac[LIM],ifac[LIM];
void pre(){
	fac[0]=1;
	forsn(i,1,LIM) fac[i]=fac[i-1]*i%MOD;
	ifac[LIM-1]=inv(fac[LIM-1]);
	rforn(i,LIM-2) ifac[i]=(i+1)*ifac[i+1]%MOD;
}
signed main(){
	fastio;
	cin>>n;
	ll a,b,c;
	pre();
	forn(i,n){
		cin>>a>>b>>c;
		if(b==0){
			cout<<powm(a,c)<<ln;
			continue;
		}
		ll t=a*inv(b)%MOD;
		ll ans=powm(b,c);
		if(a==0){
			cout<<0<<ln;
			continue;
		}
		if(t+c-1>=MOD){
			cout<<0<<ln;
		}else{
			// dbg(t,t+c,fac[t+c]-1,ifac[t-1]);
			ll cans=fac[t+c-1]*ifac[t-1]%MOD;
			cout<<ans*cans%MOD<<ln;
		}
	}
	return 0;
}

Measured memory_bytes: 16512
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <tuple>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<ll, ll>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << endl; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int x;
    cin, x;
    print(!x);
    return 0;
}


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

int main() {
  while(1) {
    int n;
    cin >> n;
    if(n == 0) break;

    int max = INT_MIN;
    int maxBfr = INT_MIN;
    int bfr = INT_MIN;

    for(int i = 0; i < n; i++) {
      int temp;
      cin >> temp;

      if(maxBfr > 0) {
	maxBfr += bfr;
      } else {
	maxBfr = bfr;
      }

      int sum;
      sum = maxBfr+temp;

      if(maxBfr != INT_MIN && sum > max && sum > temp) {
	max = sum;
      } else if(temp > max) {
	max = temp;
      }

      bfr = temp;
    }

    cout << max << endl;
  }
  return 0;
}

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

int main() {
    string n;
    cin>>n;
    string ans="ABC"+n;
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#!/usr/bin/env sbcl --script

(declaim (optimize (speed 3) (safety 0) (debug 0)))

(defun main ()
  (let* ((n (read))
         (k (read))
         (a (make-array n :element-type 'fixnum))
         (dp (make-array n :element-type 'fixnum :initial-element (floor most-positive-fixnum 2))))
    (dotimes (i n)
      (setf (aref a i) (read)))
    (flet ((relax (from to)
             (let* ((from-val (aref dp from))
                    (to-val (aref dp to))
                    (diff (abs (- (aref a to) (aref a from)))))
               (setf (aref dp to) (min to-val (+ from-val diff))))))
      (setf (aref dp 0) 0)
      (dotimes (i n)
        (dotimes (j k)
          (when (< (+ i (1+ j)) n) (relax i (+ i (1+ j)))))))
    (format t "~a~%" (aref dp (- n 1)))))

(main)


Measured memory_bytes: 59752
#include<iostream>
#include<cstdio>
#include<algorithm>
#define LL unsigned long long
using namespace std;
int n;
LL X,ans,A[2020200],sum[2020200];
int main(){
	scanf("%d %lld",&n,&X);
	for (int i=1;i<=n;i++) 
		scanf("%lld",&A[i]),sum[i]=A[i]+sum[i-1];
	for (int K=1;K<=n;K++){
		LL res=(LL)K*X+X*(LL)n;
		int pos=n;
		if (n<=2*K) res+=sum[n]*5;
		else{
			res+=(sum[n]-sum[n-2*K])*5;
			pos=n-2*K;int num=5;
			while (pos){
				num+=2; int x=min(pos,K);
				res+=(LL)num*(sum[pos]-sum[pos-x]);
				pos-=x;
			}
		}
		if (K==1||res<ans) ans=res;
	}
	cout<<ans;
}


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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

int64 Solve(int64 n) {
  if (n % 2) return 0;
  n /= 2;
  int64 ans = 0;
  while (n > 0) {
    ans += n / 5;
    n /= 5;
  }
  return ans;
}

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

  int64 n;
  cin >> n;
  cout << Solve(n) << endl;
}

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

using namespace std;

#if defined(_MSC_VER)
#pragma warning(disable: 4996)  // VSでscanfを使う．
#endif

vector<int> G[4];

int main() {
  for (int i = 0; i < 3; i++) {
    int a, b;
    cin >> a >> b;

    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  for (int i = 0; i < 4; i++) {
    if (G[i].size() >= 3) {
      cout << "NO" << endl;
      return 0;
    }
  }

  cout << "YES" << endl;

  return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
template<typename T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;}
template<typename T>inline auto vec2(typename vector<T>::size_type h,typename vector<T>::size_type w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}

int main()
{
    ll h=in(),w=in(),k=in();
    auto s=vec2<ll>(h,w);
    for(int i=0;i<h;++i){
        string str;cin>>str;
        for(int j=0;j<w;++j)s[i][j]=str[j]-'0';
    }

    bool broken=true;
    ll ans=100000;
    for(int c=0;c<(1<<(h-1));++c){
        ll ones=0;for(int i=c;i>0;i>>=1)if(i&1)++ones;
        vector<ll>v(ones+1);
        ll cols=0;
        for(int j=0;j<w;++j){
            ll g=0;
            for(int i=0;i<h;++i){
                if(s[i][j]==1)++v[g];
                if((c>>i)&1)++g;
            }
            for(auto vv:v){
                if(vv>k){
                    if(broken){
                        goto _break;
                    }else{
                        ++cols;
                        broken=true;
                        for(auto&vvv:v)vvv=0;
                        --j;
                        break;
                    }
                }
            }
            broken=false;
        }
        ans=min(ans,ones+cols);
_break:;
        broken=true;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <stdbool.h>
typedef long long LL;
typedef long double Lf;
#define Rep(i,a,n)for(int i=(int)(a);i<(int)(n);i++)
//#define Rep(i,a,n)for(LL i=(LL)(a);i<(LL)(n);i++)
#define rep(i,n)Rep(i,0,n)
#define Repp(i,l,r,k)for(int i=(int)(l);i<(int)(r);i+=(int)(k))
//#define Repp(i,l,r,k)for(LL i=(LL)(l);i<(LL)(r);i+=(LL)(k))
#define Ma(x,y) ((x)>(y)?(x):(y))
#define mi(x,y) ((x)<(y)?(x):(y))
#define MOD 1000000007//998244353,1000000007,1000000009 
int upi(const void* a, const void* b) { return*(int*)a<*(int*)b ? -1 : *(int*)a> * (int*)b ? 1 : 0; }
int downi(const void* a, const void* b) { return*(int*)a<*(int*)b ? 1 : *(int*)a> * (int*)b ? -1 : 0; }
void sortupi(int* a, int n) { qsort(a, n, sizeof(int), upi); } //1,2,3,4,...
void sortdowni(int* a, int n) { qsort(a, n, sizeof(int), downi); }
int upLL(const void* a, const void* b) { return*(LL*)a<*(LL*)b ? -1 : *(LL*)a> * (LL*)b ? 1 : 0; }
int downLL(const void* a, const void* b) { return*(LL*)a<*(LL*)b ? 1 : *(LL*)a> * (LL*)b ? -1 : 0; }
void sortupLL(LL* a, int n) { qsort(a, n, sizeof(LL), upLL); }
void sortdownLL(LL* a, int n) { qsort(a, n, sizeof(LL), downLL); }
int cmp_char(const void* a, const void* b) { return *(char*)a - *(char*)b; } // a,b,c,d
int cmp_str(const void* a, const void* b) { return strcmp(*(const char**)a, *(const char**)b); } // aaa,aab
LL gcd(LL p, LL q) { while (q) { LL t = p % q; p = q; q = t; }return p; }
LL modpow(LL a,LL n,int m){LL x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
#define invmodpow(b,p)modpow(b,p-2,p)// a/b≡a*b^{-1}(mod p)...return b^{-1}(mod p)
typedef struct fac { LL n, exp; }F;
LL fact(LL n,F*a){LL x,i,j,c=0;x=n;for(i=2;i*i<=x;i++){for(j=1;x%i==0;j++)x/=i;if(j>1){a[c].n=i;a[c++].exp=j-1;}}if(x-1){a[c].n=x;a[c++].exp=1;}return c;}
//snippet
//overflow...char 1e6

#define N 109

int main() {
	int x;
	scanf("%d", &x);
	for (int i = 8; i > 0; i--) {
		if (2000 - i * 200 <= x && x < 2200 - i * 200) {
			printf("%d\n", i);
			return 0;
		}
	}

	return 0;
}

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

int main ()
{
//	ios_base::sync_with_stdio(false);
//	cin.tie(NULL);
	
//	freopen ("//specify file name","r",stdin);
//	freopen ("output.txt","w",stdout);
	
	long long n,m;
	cin>>n>>m;
	
	if (n==1 && m==1)
	{
		cout<<1;
	} 	
	else if (n==1)
	{
		cout<<m-2;
	}
	else if (m==1)
	{
		cout<<n-2;
	}
	else 
	{
		long long ans = (n-2) * (m-2);
		cout<<ans;
	}
	
	return 0;
	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define REP(i, n) for (int i=0; i<n; ++i)
#define print(x) cout << x << endl;

using namespace std;

void solve() {
    int N;
    cin >> N;
    string S;
    cin >> S;
    vector<int> left(N), right(N);
    left[0] = 0;
    for (int i = 1; i < N; ++i) {
        left[i] += left[i-1];
        if (S[i-1] == 'E') left[i]++;
    }
    right[N-1] = 0;
    for (int i = N-2; i >= 0; --i) {
        right[i] += right[i+1];
        if (S[i+1] == 'W') right[i]++;
    }

    int ans = 0;
    for (int i = 0; i < N; ++i) {
        ans = max(ans, left[i] + right[i]);
    }
    print(N - ans - 1);

}

int main() {

    solve();
    return 0;
}


Measured memory_bytes: 3076
import java.util.*;
import java.io.*;
import static java.lang.System.*;

class FastScanner {
  private final InputStream in = System.in;
  private final byte[] buffer = new byte[1024];
  private int ptr = 0;
  private int buflen = 0;
  private boolean hasNextByte() {
      if (ptr < buflen) {
          return true;
      }else{
          ptr = 0;
          try {
              buflen = in.read(buffer);
          } catch (IOException e) {
              e.printStackTrace();
          }
          if (buflen <= 0) {
              return false;
          }
      }
      return true;
  }
  private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
  private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
  public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
  public String next() {
      if (!hasNext()) throw new NoSuchElementException();
      StringBuilder sb = new StringBuilder();
      int b = readByte();
      while(isPrintableChar(b)) {
          sb.appendCodePoint(b);
          b = readByte();
      }
      return sb.toString();
  }
  public long nextLong() {
      if (!hasNext()) throw new NoSuchElementException();
      long n = 0;
      boolean minus = false;
      int b = readByte();
      if (b == '-') {
          minus = true;
          b = readByte();
      }
      if (b < '0' || '9' < b) {
          throw new NumberFormatException();
      }
      while(true){
          if ('0' <= b && b <= '9') {
              n *= 10;
              n += b - '0';
          }else if(b == -1 || !isPrintableChar(b)){
              return minus ? -n : n;
          }else{
              throw new NumberFormatException();
          }
          b = readByte();
      }
  }
  public int nextInt() {
      long nl = nextLong();
      if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
      return (int) nl;
  }
  public double nextDouble() { return Double.parseDouble(next());}
}

class Main {
  public static final int MOD = 1000000007;
  public static final int INF = 1000000000;
  public static void main(String[] args) {
    FastScanner sc = new FastScanner();
    int n = sc.nextInt();
    int p[] = new int[n];
    for(int i=0; i<n; i++) p[i] = sc.nextInt();
    int cnt=0;
    for(int i=1; i<n-1; i++){
      if((p[i] > p[i-1] && p[i] < p[i+1]) || (p[i] < p[i-1] && p[i] > p[i+1]) ) cnt++;
    }
    out.println(cnt);
  }

  public static int gcd(int a, int b){
    if(b == 0) return a;
    return gcd(b, a%b);
  }
}

Measured memory_bytes: 21204
require 'set'

n, m = STDIN.gets.split.map(&:to_i)

cards = Set.new 1.upto(n)
l_max = 0
r_min = n + 1
m.times do
  l, r = STDIN.gets.split.map(&:to_i)
  l_max = l if l_max < l
  r_min = r if r < r_min
end

STDOUT.puts cards.delete_if {|c| c < l_max || r_min < c}.size

Measured memory_bytes: 9592
#include <vector>
#include <cstdio>
#include <algorithm>
using namespace std;
using ll = long long int;

int main() {
    ll N, Q; scanf("%lld%lld", &N, &Q);

    vector<ll> A(N), sum(N+2), part(N+2);
    for(int i=0; i<N; i++) {
        scanf("%lld", &A[i]);
        sum[i+1] = sum[i] + A[i];
        part[i+2] = part[i] + A[i];
    }

    int M1 = (N + 1) / 2, M2 = (N - 1) / 2;
    vector<ll> point(M1), X(M2);
    for(int i=1; i<=M1; i++) {
        point[i-1] = sum[N] - sum[N-i] + part[N - 2*i + 1];
    }

    for(int i=1; i<=M2; i++) {
        X[i-1] = A[N-i-1] + A[N-i*2-1];
    }

    reverse(point.begin(), point.end());
    reverse(X.begin(), X.end());
    for(int i=0; i<Q; i++) {
        ll val; scanf("%lld", &val);
        printf("%lld\n", point[lower_bound(X.begin(), X.end(), 2*val) - X.begin()]);
    }
    return 0;
}


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

using namespace std;

long long b[200000 + 5];

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

    for (int i = 1; i <= n; ++i) {
        int a;
        cin >> a;
        b[a] = i;
    }

    set<long long> st;
    st.insert(0);
    st.insert(n + 1);

    long long ans = 0;
    for (int i = 1; i <= n; ++i) {
        st.insert(b[i]);
        auto it = st.find(b[i]);
        long long lo = *(--it);
        it++;
        long long hi = *(++it);
        ans += i * (b[i] - lo) * (hi - b[i]);
    }

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

Measured memory_bytes: 11136
#include<cstdio>
typedef long long ll;
int main(){
	ll n,m;
	scanf("%lld %lld",&n,&m);
	if(n*2>=m){
		printf("%lld\n",m/2);
	}else{
		ll ans = n;
		m -= 2 * n;
		m /= 4;
		ans += m;
		printf("%lld\n",ans);
	}
	return 0;
}


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

int main() {
  int a,b,c,d,i;
  cin >>a >>b >>c >>d;
  for(i=0; i<1000; i++){
    if(c-b>0){
      c = c-b;
      if(a-d>0){
        a = a-d;
      }
      else{
        cout <<"No" <<endl;
        break;
      }
    }
    else{
      cout <<"Yes" <<endl;
      break;
    }
  }
}

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

using namespace std;

int main(void) {
    int n, m;
    while (cin >> n, n) {
        char be, af, ch;
        map<char, char> mp;
        for (int i = 0; i < n; i++) {
            cin >> be >> af;
            mp[be] = af;
        }
        
        cin >> m;
        string ans = "";
        for (int i = 0; i < m; i++) {
            cin >> ch;
            if (mp.find(ch) != mp.end()) ch = mp[ch];
            ans += ch;
        }

        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 3228
def gs() gets.chomp end
def gi() gets.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def desc(ar) ar.sort!{|x,y|y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end

n = gi
c = [0,0,0,0]

n.times do
  s = gs
  if s=="AC"
    c[0]+=1
  elsif s=="WA"
    c[1]+=1
  elsif s=="TLE"
    c[2]+=1
  elsif s=="RE"
    c[3]+=1
  end
end

puts "AC x #{c[0]}"
puts "WA x #{c[1]}"
puts "TLE x #{c[2]}"
puts "RE x #{c[3]}"


Measured memory_bytes: 14332
#include<bits/stdc++.h>
using namespace std;
#define int long long int
int d1[1000004]={0};

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout<<setprecision(9)<<fixed;
	
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)
		cin>>a[i];
	sort(a,a+n,greater<int>());
	int c=0;
	vector<int> v;
	v.push_back(a[0]);
	for(int i=1;i<n;i++)
	{
		v.push_back(a[i]);
		v.push_back(a[i]);
	}
	for(int i=0;i<n-1;i++)
		c+=v[i];
	cout<<c<<endl;
	return 0;
}

Measured memory_bytes: 8956
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

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

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define rep(i,x) for(int i=0;i<(x);++i)
#define rep1(i,x) for(int i=1;i<=(x);++i)
#define rrep(i,x) for(int i=(x)-1;i>=0;--i)
#define rrep1(i,x) for(int i=(x);i>=1;--i)
#define FOR(i,a,x) for(int i=(a);i<(x);++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()

#define omajinai ios::sync_with_stdio(false);cin.tie(0)

template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>T get(){T a;cin>>a;return a;}
template<typename T>T rev(T a){reverse(all(a));return a;}
template<typename T>istream&operator>>(istream&is,vector<T>&vec){rep(i,vec.size())is>>vec[i];return is;}
template<typename T>vector<T>&sort(vector<T>&a){sort(all(a));return a;}

const int inf = 1e9;
const ll linf = 3e18;
const double eps = 1e-9;

int dx[2] = {-1, 1};

int a[100000];

signed main()
{
    omajinai;

    int N, M; cin >> N >> M;

    memset(a, -1, sizeof(a));

    queue<int> q;

    rep(i, M) {
        int b; cin >> b; b--;
        a[b] = 0;
        q.push(b);
    }

    int ma = 0;

    while (q.size()) {
        int x = q.front(); q.pop();
        rep(i, 2) {
            int nx = x + dx[i];
            if (0 <= nx && nx < N) {
                if (~a[nx]) continue;
                a[nx] = a[x] + 1;
                q.push(nx);
                ma = max(ma, a[nx]);
            }
        }
    }

    cout << ma << endl;
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
  	int h,a; cin >> h >> a;
  	int ans = 0;
  	if(h%a != 0){
      cout << h/a + 1 << endl;
    }else{
      cout << h/a << endl;
    }
}

Measured memory_bytes: 256