akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (ll i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    ll N;
    cin >> N;
    vector<ll> A(N);
    map<ll, ll> mp;
    rep(i, N) {
        cin >> A[i];
        mp[A[i] - i]++;
    }

    ll ans = 0;
    rep(i, N) {
        ans += mp[-A[i] - i];
    }

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

Measured memory_bytes: 27492
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace ABC155C
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var sDict = new SortedDictionary<string, int>(new Comparer());

            for (var i = 0; i < N; i++)
            {
                var s = Console.ReadLine();
                int value;
                if (!sDict.TryGetValue(s, out value))
                    sDict.Add(s, 1);
                else
                    sDict[s] = value + 1;
            }

            var ansList = new List<string>();
            foreach (var kvp in sDict.OrderByDescending(x => x.Value))
            {
                if (ansList.Any() && kvp.Value != sDict[ansList.First()])
                    break;

                ansList.Add(kvp.Key);
            }
            //Console.WriteLine();
            var ans = string.Join(Environment.NewLine, ansList);

            Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
            Console.WriteLine(ans);
            Console.Out.Flush();
        }

        class Comparer : IComparer<string>
        {
            public int Compare(string x, string y) => string.Compare(x, y, StringComparison.OrdinalIgnoreCase);
        }
    }
}


Measured memory_bytes: 55900
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int N = 3e5 + 7;
int32_t main(){
    IOS;
    int n;
    cin  >> n;
    int arr[n];
    int cr=0,cw=0;
    for(int i =0; i<n; i++){
        char c;
        cin >> c;
        if(c=='R') arr[i] = 0, cr++;
        else arr[i] = 1, cw++;
    }
    int count=0;
    for(int i =0; i<n; i++){
        if(arr[i] == 0 && i>= (n-cw)) count++; 
        else if(arr[i] == 1 && i < (n-cw)) count++;
    }
    if(count%2==0) cout << count/2 << endl;
    else cout << (count/2) + 1 << endl;

}



Measured memory_bytes: 5212
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;
 
 
public class Main {

	static long MOD = 1_000_000_007;
	public static void main(String[] args) throws Exception {
		// TODO Auto-generated method stub
		//int N = Integer.parseInt(sc.next());
		//long L = Long.parseLong(sc.next());
		//char[] c = sc.next().toCharArray();
		int INF = Integer.MAX_VALUE;
		int INF_MIN = -1000;//Integer.MIN_VALUE;
		
		Scanner sc = new Scanner(System.in);
		

		int N = Integer.parseInt(sc.next());
		int A = Integer.parseInt(sc.next());
		int B = Integer.parseInt(sc.next());
		int base_cal = Integer.parseInt(sc.next());
		int[] cal = new int[N];
		for(int i=0; i<N; i++){
			cal[i] = Integer.parseInt(sc.next());
		}
		Arrays.sort(cal);
		int total_cal = base_cal;
		int cost = A;
		double rate_cal = (double)base_cal/(double)A;
		for(int i=N-1; i>=0; i--){
			int tmp_total = total_cal + cal[i];
			int tmp_cost = cost + B;
			double new_rate_cal = (double)tmp_total/(double)tmp_cost;
			if(new_rate_cal>rate_cal){
				total_cal = tmp_total;
				cost = tmp_cost;
				rate_cal = new_rate_cal;
			}
			//System.out.println("cal: "+total_cal+" cost:"+cost);
		}
		
		int ans = total_cal/cost;

		System.out.println(ans);
		
	
		
		
	}
}




Measured memory_bytes: 26072
#include<stdio.h>
#define Min(a,b) a<b?a:b
int main(void){
    int a,b,c,d;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    int train=Min(a,b);
    int bus=Min(c,d);
    printf("%d\n",train+bus);
    return 0;
}

Measured memory_bytes: 128
N, K = map(int, input().split())
 
count = 0
 
for b in range(K+1, N+1):
    q_max = N // b
    count += q_max * (b - K)
    
    rem = N % b - K + 1
    if rem > 0:
        count += rem
    if K == 0:
        count -= 1
print(count)

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

int main(){
  int h,w;
  cin>>h>>w;
  char m[51][51];
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++){
      scanf(" %c",&m[i][j]);
      if(m[i][j]=='.') m[i][j]='0';
    }
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++){
      if(m[i][j]=='#'){
        for(int a=(i==0?0:-1);a<=(i==h-1?0:1);a++){
          for(int b=(j==0?0:-1);b<=(j==w-1?0:1);b++){
            if(m[i+a][j+b]!='#') m[i+a][j+b]++;
          }
        }
      }
    }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cout<<m[i][j]<<flush;
    }
    cout<<endl;
  }
}

Measured memory_bytes: 384
n, a, b = gets.strip.split.map(&:to_i)
forward_ans = []
ans = 0

for num in 1..n do
  tmp = num.to_s.split("").to_a
  
  res = 0
  tmp.each do |i|
    res = res + i.to_i
  end
  
  if res >= a and res <= b
    forward_ans << num
  end
end

forward_ans.each do |i|
  ans = ans + i
end

puts ans

Measured memory_bytes: 4092
N,M = map(int,input().split())


#iから進める場所をリストにして保管
edges = {i:[] for i in range(1,N+1)}
for i in range(M):
  a,b = map(int,input().split())
  edges[a].append(b)
  edges[b].append(a)


#深さ優先探索
def dfs(list):
    #lst(通過点)の数がN(頂点数)と等しくなったら探索終了（成功）
  if len(list) == N:
    return 1
  else:
    a = list[-1]
    #lstの最後尾（現在地）が次に進める場所をnextとしてリスト化
    #nextに以前通った場所が入っていないか確認
    next = [n for n in edges[a] if n not in list]
    #次に進める場所がなくなったら探索終了（失敗）
    if len(next) == 0:
      return 0

    total = 0
    #再帰でさらに探索
    for n in next:
      total += dfs(list + [n])

    return total


ans = dfs([1])

print(ans)


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

using namespace std;

int main() {

	int N;
	cin >> N;

	int sum = 0;

	for (int i = 1; i < 10; i++) {
		for (int j = 1; j < 10; j++) {
			if ((i * j) == N) {
				cout << "Yes" << endl;
				sum++;
				break;
			}
		}
		if (sum > 0)
			break;
	}
	
	if (sum == 0)
		cout << "No" << endl;
}

Measured memory_bytes: 3628
#include <stdio.h>
#include <string.h>
#include <algorithm>

using namespace std;

int A, B;

int main(void)
{
	scanf("%d %d", &A, &B);

	if (A < B) swap(A, B);

	int maxi = B * 2 + (16 - B * 2 + 1) / 2;

	printf("%s\n", A + B <= maxi ? "Yay!" : ":(");

	return 0;
}

Measured memory_bytes: 128
N=int(input())
A=[]
B=[]
A=list(map(int,input().split()))
for i in range(N):
    B.append(0)
r=0
rain=0

for i in range(N):
    rain=rain+A[i]
n=N//2
for i in range(n):
    c=2*(i)
    r=r+2*A[c]
B[N-1]=rain-r
B[0]=int(2*(A[N-1]-B[N-1]/2))
for i in range(1,N-1):
    B[i]=int(2*(A[i-1]-B[i-1]/2))
print(*B)

Measured memory_bytes: 14400
#include <iostream>
using namespace std;
bool flag[10000001];

int main(){
    int n=0,ans=0;
	for(int i=0;i <= 1000000;i++){
		if(i<=1)flag[i]=false;
		else flag[i]=true;
	}
	for(int i=2;i <= 1001 ;i++){
		if(flag[i]==true){
			for(int j=i*2 ; j<=1000000 ; j=j+i){
				flag[j] = false;
			}
		}
	}
    while(cin>>n,n){
		ans=0;
		for(int i=n+1;i <= 2*n;i++){
			if(flag[i]==true){
				ans++;
			}
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 2136
#[allow(unused_imports)] use proconio::{input, marker::{Bytes, Chars, Usize1, Isize1}};
#[allow(unused_imports)] use std::cmp::{min, max};
#[allow(unused_imports)] use superslice::Ext as _;

/// Implement (union by size) + (path compression)
/// Reference:
/// Zvi Galil and Giuseppe F. Italiano,
/// Data structures and algorithms for disjoint set union problems
pub struct Dsu {
    n: usize,
    // root node: -1 * component size
    // otherwise: parent
    parent_or_size: Vec<i32>,
}

impl Dsu {
    // 0 <= size <= 10^8 is constrained.
    pub fn new(size: usize) -> Self {
        Self {
            n: size,
            parent_or_size: vec![-1; size],
        }
    }
    pub fn merge(&mut self, a: usize, b: usize) -> usize {
        assert!(a < self.n);
        assert!(b < self.n);
        let (mut x, mut y) = (self.leader(a), self.leader(b));
        if x == y {
            return x;
        }
        if -self.parent_or_size[x] < -self.parent_or_size[y] {
            std::mem::swap(&mut x, &mut y);
        }
        self.parent_or_size[x] += self.parent_or_size[y];
        self.parent_or_size[y] = x as i32;
        x
    }

    pub fn same(&mut self, a: usize, b: usize) -> bool {
        assert!(a < self.n);
        assert!(b < self.n);
        self.leader(a) == self.leader(b)
    }
    pub fn leader(&mut self, a: usize) -> usize {
        assert!(a < self.n);
        if self.parent_or_size[a] < 0 {
            return a;
        }
        self.parent_or_size[a] = self.leader(self.parent_or_size[a] as usize) as i32;
        self.parent_or_size[a] as usize
    }
    pub fn size(&mut self, a: usize) -> usize {
        assert!(a < self.n);
        let x = self.leader(a);
        -self.parent_or_size[x] as usize
    }
    pub fn groups(&mut self) -> Vec<Vec<usize>> {
        let mut leader_buf = vec![0; self.n];
        let mut group_size = vec![0; self.n];
        for i in 0..self.n {
            leader_buf[i] = self.leader(i);
            group_size[leader_buf[i]] += 1;
        }
        let mut result = vec![Vec::new(); self.n];
        for i in 0..self.n {
            result[i].reserve(group_size[i]);
        }
        for i in 0..self.n {
            result[leader_buf[i]].push(i);
        }
        result
            .into_iter()
            .filter(|x| !x.is_empty())
            .collect::<Vec<Vec<usize>>>()
    }
}

#[proconio::fastout]
fn main() {
	input! {
		n: usize,
		m: usize,
		ab: [(Usize1, Usize1); m],
	}

	let mut d = Dsu::new(n);
	for i in 0..m {
		d.merge(ab[i].0, ab[i].1);
	}

	let g = d.groups();

	println!("{}", g.len()-1);
}


Measured memory_bytes: 10604
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}

int main() {
  string s;
  int K;
  cin>>s>>K;
  int N=s.size();
  vector<string>t;
  for(int i=0;i<N;i++){
    for(int j=1;j<=K;j++){
     if(i+j<=N){t.push_back(s.substr(i,j));}
    }
  }
  sort(t.begin(),t.end());
  t.erase(unique(t.begin(),t.end()),t.end());
  cout<<t[K-1]<<endl;
  return 0;
}

Measured memory_bytes: 4268
import java.util.ArrayDeque

fun main() {
    val builder = StringBuilder()

    val (n, m) = readInputLine().split(" ").map { it.toInt() }

    val edges = Array(n) { mutableListOf<Int>() }

    repeat(m) {
        val (a, b) = readInputLine().split(" ").map { it.toInt() - 1 }
        edges[a].add(b)
        edges[b].add(a)
    }

    val ans = IntArray(n) { -1 }

    val queue = ArrayDeque<Int>()

    for (e in edges[0]) {
        ans[e] = 0
        queue.addLast(e)
    }

    while (queue.isNotEmpty()) {
        val pos = queue.pollFirst()

        for (e in edges[pos]) {
            if (ans[e] == -1) {
                ans[e] = pos
                queue.addLast(e)
            }
        }
    }

    builder.appendln("Yes")

    for (i in 1 until n) {
        builder.appendln(ans[i] + 1)
    }

    print(builder.toString())
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 82100
#include <bits/stdc++.h>
#include <iomanip>
#include <algorithm>
#define ll long long
#include <unordered_map>
using namespace std;
 
int main() {
  ll N, Q, r, l, cnt = 0;
  string S;
  cin >> N >> Q >> S;
  
  vector<ll> flag(S.size(), 0);
  for(ll i = 0; i < S.size(); i++) {
    if(i > 0) {
      if((S.at(i) == 'C') && (S.at(i - 1) == 'A')) cnt++;
      flag.at(i) = cnt;
    }
  }

  for(ll i = 0; i < Q; i++) {
    cin >> r >> l;
    cout << flag.at(l - 1) - flag.at(r - 1) << endl;
  }
}

Measured memory_bytes: 4272
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;

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

    ll n;
    cin >> n;
    ll a[n], x, ans = 0, sum = 0;
    for (ll i = 0; i < n; i++) {
        cin >> x;
        a[i] = x - i - 1;
    }
    sort(a, a + n);
    ll mid = (n % 2 ? a[n / 2] : a[n / 2 - 1]);
    for (ll i = 0; i < n; i++) {
        ans += abs(a[i] - mid);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
package main

import (
	"fmt"
    "sort"
)
 
func main() {
    var n, k int
    fmt.Scanf("%d %d", &n, &k)

    prices := make([]int, n)
    for i := range prices{
      fmt.Scan(&prices[i])
    }

    sum := 0
    if n != k {
      sort.Ints(prices)
    }
    for i:=0; i<k; i++ {
      sum += prices[i]    
    }
    fmt.Print(sum)
}

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

using namespace std;

const int N = 1e5 + 6;

vector< int > node[N][11];
bool used[N][11];
int col[N], n, m, vv[N], d[N], c[N], depth[N], done[N];
vector< int > g[N], ver;

void bfs(int v, int ncol, int lim) {
  queue< int > que, rem;
  depth[v] = 0;
  que.push(v);
  while (!que.empty()) {
    v = que.front(); que.pop();
    rem.push(v);
    if (col[v] == 0) col[v] = ncol;
    if (depth[v] == lim) continue;
    if (done[v] >= lim-depth[v]) continue;
    done[v] = lim-depth[v];
    for (int u : g[v]) if (depth[u] == -1) {
      depth[u] = depth[v] + 1;
      que.push(u);
    }
  }
  while (!rem.empty()) {
    depth[rem.front()] = -1;
    rem.pop();
  }
}

int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    u--; v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  memset(depth, -1, sizeof depth);
  memset(done, -1, sizeof done);
  int q;
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    scanf("%d %d %d", vv+i, d+i, c+i);
    vv[i]--;
  } 
  for (int i = q-1; i >= 0; i--) {
    bfs(vv[i], c[i], d[i]);
  } 
  for (int i = 0; i < n; i++)
    printf("%d ", col[i]);
  printf("\n");
  return 0;
}

Measured memory_bytes: 36088
N = int(input())
A = list(map(int, input().split()))
s = list(range(1, N+1))
c = [0]*N

for x in range(len(A)):
  c[A[x]-1] = str(s[x])
print(' '.join(c))
# c = []
# r = []
# def sv(t,y):
#   l = []
#   z = min(t)
#   for x in range(len(t)):
#     if t[x] == z:
#       tmp = y[y.index(t[x])]
#       c.insert(z, str(tmp))
#       z += 1
#     else:
#       l.append(y[x])
#       z += 1
#   print(z)
#   return [l,z]

# def main():

#   r = sv(A,s)
#   while True:
#     if len(r[0]) == 0:
#       print(c)
#       break
#     else:
#       r = sv(r[0],s)
#   print(' '.join(c))

# main()

Measured memory_bytes: 18980
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
int main(){
  while(true){
    vector<int>shop(5);
    rep(i,5){
      int a,b;
      cin >> a >> b;
      if(a == 0 && b == 0){
        return 0;
      }
      shop[i] = a + b;
    }
    int Max = 0;
    rep(i,5)Max = max(shop[i],Max);
    rep(i,5){
      if(Max == shop[i]){
        cout << (char)('A' + i) << " " << shop[i] << endl;
        break;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 3020
#include <bits/stdc++.h>
using namespace std;
using PP = pair<long, long>;
const int INF = 1e9;

long n, a, b, m;
long pre[20];
vector<PP> decomp() {
  long l = a;
  long rem = n;
  vector<PP> ret;
  for (long base = 1; ; base *= 10) {
    long num = (base - l + b - 1) / b;
    if (num < 0) num = 0;
    if (rem <= num) {
      ret.push_back(PP(l, rem));
      return ret;
    }
    ret.push_back(PP(l, num));
    l += num * b;
    rem -= num;
  }
}

long modpow(long b, long e) {
  if (e == 0) return 1;
  if (e % 2 == 1) return b * modpow(b, e - 1) % m;
  long t = modpow(b, e / 2);
  return t * t % m;
}

long cat(long d, long n) {
  if (n == 0) return 0;
  if (n % 2 == 1) {
    long res = modpow(pre[d], (n - 1)) % m;
    return (res + cat(d, n - 1)) % m;
  }
  
  long res = cat(d, n / 2);
  long t = (res + res * modpow(pre[d], (n / 2)) % m) % m;
  return t;
}

long sub(long a, long b, long d, long n) {
  if (n == 0) return 0;
  if (n % 2 == 1) {
    long res = a % m * cat(d, n) % m;
    return (res + sub(b, b, d, n - 1)) % m;
  }
  
  long res = sub(a, b, d, n / 2);
  long t = (res + res * modpow(pre[d], n / 2) % m) % m;
  long c = b % m * (n / 2) % m * cat(d, n / 2) % m;
  return (t + c) % m;
}

int main() {
  cin >> n >> a >> b >> m;
  vector<PP> res = decomp();
  
  long base = 1;
  for (int i = 0; i < 20; ++i) {
    pre[i] = base;
    base = base * 10 % m;
  }
  
  long sum = 0;
  long mul = 1;
  for (int i = (int)res.size() - 1; i >= 0; --i) {
    if (res[i].second == 0) continue;
    long ans = sub(res[i].first, b, i, res[i].second);
    sum = (sum + ans * mul % m) % m;
    mul = mul * modpow(pre[i], res[i].second) % m;
  }
  cout << sum << endl;
}

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

int64_t LucasNumber(int n) {
  vector<int64_t> LucasList(100);
  LucasList.at(0) = 2;
  LucasList.at(1) = 1;
  
  for (int i=2;i<=n;i++) {
    LucasList.at(i) = LucasList.at(i-1) + LucasList.at(i-2);
  }
  return LucasList.at(n);
}
  
int main() {
  int N;
  cin >> N;
  
  cout << LucasNumber(N) << endl;
  
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>

using namespace std;

const long long MOD = 1000000007;

int main(){
	int n;
	cin >> n;
	vector<int> v(n);
	
	for(int i=0;i<n;i++){
		cin >> v[i];
	}
	
	sort(v.begin(),v.end());
	double ans;
	
	ans=v[0];
	for(int i=1;i<n;i++){
		ans=(ans+v[i])/2;
	}
	
	cout << ans << endl;
	return 0;
}


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

typedef long long ll;
const ll mod=1e9+7;
const ll N=3e5+1;
const ll INF=1e10;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	double d,t,s;
	cin>>d>>t>>s;
	cout<<(d/s<=t?"Yes":"No");
} 


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

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	vector<bool> ok(2001, false);
	for (int bit = 1; bit < (1 << n); bit++) {
		int t = 0;
		rep(j, n) {
			if (bit & (1 << j)) t += a[j];
		}
		ok[t] = true;
	}
	int q;
	cin >> q;
	rep(i, q) {
		int m;
		cin >> m;
		if (ok[m]) cout << "yes" << endl;
		else cout << "no" << endl;
	}
	return 0;
}


Measured memory_bytes: 3096
from collections import deque
n=int(input())
A=deque()
B=deque()
ans=0
for i in range(n):
    a,b=map(int,input().split())
    A.appendleft(a)
    B.appendleft(b)
while A:
    A[0]+=ans
    if A[0]%B[0]!=0:
        k=B[0]-(A[0]%B[0])
        ans+=k
    A.popleft()
    B.popleft()

print(ans)

Measured memory_bytes: 11380
#include <bits/stdc++.h>
using namespace std;
int N, K;
int main() {
    cin >> N >> K;
    int sum = 1;
    for(int i = 0; i < N; ++i) {
        if(sum < K) {
            sum *= 2;
        }else {
            sum += K;
        }
    }

    cout << sum << endl;
}

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

int main()
{
    int t_HP, t_AT;
    int a_HP, a_AT;
    int turn = 1;

    cin >> t_HP >> t_AT >> a_HP >> a_AT;

    while (true)
    {
        if (t_HP <= 0 || a_HP <= 0)
        {
            break;
        }
        if (turn % 2 == 1)
        {
            a_HP = a_HP - t_AT;
        }
        else
        {
            t_HP = t_HP - a_AT;
        }
        turn++;
    }

    if (t_HP > 0)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}


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

typedef long long ll;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll n,k;
    cin>>n>>k;
    ll t=n%k;
    if(abs(t-k)<n%k){
        cout<<abs(t-k);
    }else cout<<n%k;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <iomanip>
using namespace std;
double dp[310][310][310];
int n;
double rec(int i, int j, int k) {
    if (dp[i][j][k] >= 0) return dp[i][j][k];
    if (i == 0 && j == 0 && k == 0) return 0.0;

    double res = 0.0;
    if (i > 0) res += rec(i-1, j, k) * i;
    if (j > 0) res += rec(i+1, j-1, k) * j;
    if (k > 0) res += rec(i, j+1, k-1) * k;
    res += n;
    res *= 1.0 / (i + j + k);

    return dp[i][j][k] = res;
}
int main(){
  cin >> n;
  int x;
  double y[4];
  for(int i=0;i<n;i++){
    cin >> x;
    y[x] += 1.0;
  }
  dp[0][0][0] = 0.0;
  int one=y[1],two=y[2],three=y[3];
  memset(dp, -1, sizeof(dp));
  cout << fixed << setprecision(10) << rec(one, two, three) << endl;
}



Measured memory_bytes: 233088
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    String T = sc.next();
    int A = sc.nextInt();
    int B = sc.nextInt();
    String U = sc.next();
    if (U.equals(S)){
      System.out.printf("%d %d", A-1, B);
    }else{
      System.out.printf("%d %d", A, B-1);
    }
  }
}


Measured memory_bytes: 35780
#include <iostream>
#include <algorithm>
using namespace std;
static const int MAX = 200000;

int main(void){
    // Here your code !
    
    int R[MAX], n;
    
    cin >> n;
    for(int i = 0; i < n; i++) cin >> R[i];
    
    int maxv = -2000000000;
    int minv = R[0];
    
    for(int i = 1; i < n; i++){
        maxv = max(maxv, R[i] - minv);
        minv = min(minv, R[i]);
    }
    
    cout << maxv << endl;
    
    return 0;
    
}

Measured memory_bytes: 1940
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1005;
ll ans,sum[N],q[N*N];
int n,k,x,top;
int calc(ll x)
{
	int cnt=0;
	for (int i=1;i<=top;i++)
	  if ((q[i]&x)==x) cnt++; 
	return cnt;
}
int main()
{
	scanf("%d%d",&n,&k);
	for (int i=1;i<=n;i++) scanf("%d",&x),sum[i]=sum[i-1]+x;
	for (int i=0;i<n;i++)
	  for (int j=i+1;j<=n;j++)
	    q[++top]=sum[j]-sum[i];
	for (int i=40;i>=0;i--)
	  if (calc(ans|(1ll<<i))>=k) ans|=(1ll<<i);
	printf("%lld\n",ans);
    return 0;	
} 

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

typedef struct { char c; int a; int id; } DATA;

void bubble_sort(int n, DATA *a)
{
	int i, f;
	DATA x;

	do {
		f = 0;
		for (i = n-1; i > 0; i--) {
			if (a[i].a < a[i-1].a) {
				x = a[i], a[i] = a[i-1], a[i-1] = x;
				f = 1;
			}
		}
	} while (f);
}

void selection_sort(int n, DATA *a)
{
	int i, j, minj;
	DATA x;

	for (i = 0; i < n; i++) {
		minj = i;
		for (j = i; j < n; j++) {
			if (a[j].a < a[minj].a) minj = j;
		}
		if (i != minj) {
			x = a[i], a[i] = a[minj], a[minj] = x;
		}
	}
}


//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0, c = getchar_unlocked();
	do n = 10*n + (c & 0xf), c = getchar_unlocked(); while (c >= '0');
	return n;
}

DATA a[102], b[102];

int main()
{
	int N, i, f;

	N = in();
	for (i = 0; i < N; i++) {
		a[i].c = getchar_unlocked();
		a[i].a = getchar_unlocked();
		a[i].id = i;
		getchar_unlocked();			// skip
	}
	memcpy(b, a, sizeof(DATA)*N);

	bubble_sort(N, a);
	f = 0;
	putchar(a[0].c), putchar(a[0].a);
	for (i = 1; i < N; i++) {
		putchar(' ');
		putchar(a[i].c), putchar(a[i].a);
		if (a[i-1].a == a[i].a && a[i-1].id > a[i].id) f = 1;
	}
	putchar('\n');
	puts(f? "Not stable": "Stable");

	selection_sort(N, b);
	f = 0;
	putchar(b[0].c), putchar(b[0].a);
	for (i = 1; i < N; i++) {
		putchar(' ');
		putchar(b[i].c), putchar(b[i].a);
		if (b[i-1].a == b[i].a && b[i-1].id > b[i].id) f = 1;
	}
	putchar('\n');
	puts(f? "Not stable": "Stable");
	return 0;
}



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

using namespace std;

using ll = long long;

pair<ll, ll> ps[1 << (40 / 2)];

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

    int N;
    ll W;
    cin >> N >> W;
    ll w[N], v[N];

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

    int N2 = N / 2;
    for (int i = 0; i < 1 << N2; ++i) {
        ll sw = 0, sv = 0;
        for (int j = 0; j < N2; ++j) {
            if (i >> j & 1) {
                sw += w[j];
                sv += v[j];
            }
        }
        ps[i] = make_pair(sw, sv);
    }

    sort(ps, ps + (1 << N2));

    int m = 1;
    for (int i = 1; i < 1 << N2; ++i) {
        if (ps[m - 1].second < ps[i].second) {
            ps[m++] = ps[i];
        }
    }

    ll res = 0;
    for (int i = 0; i < 1 << (N - N2); ++i) {
        ll sw = 0, sv = 0;
        for (int j = 0; j < N - N2; ++j) {
            if (i >> j & 1) {
                sw += w[N2 + j];
                sv += v[N2 + j];
            }
        }
        if (sw <= W) {
            ll tv = (lower_bound(ps, ps + m, make_pair(W - sw, (ll)1e15 )) - 1) ->second;
            res = max(res, sv + tv);
        }
    }

    cout << res << '\n';

    return 0;
}



Measured memory_bytes: 19600
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

using namespace std;

typedef unsigned int uint;
typedef long long ll;

int size[7] = {60, 80, 100, 120, 140, 160, INT_MAX};
int weig[7] = {2,  5,  10,  15,  20,  25,  INT_MAX};
int cost[7] = {600,800,1000,1200,1400,1600,0};

int main(){
  int n;
  while(cin>>n, n){
    int ans = 0;
    REP(i,n){
      int x,y,h,w,s,j=0;
      cin>>x>>y>>h>>w;
      s = x+y+h;
      while(s > size[j]) j++;
      while(w > weig[j]) j++;
      ans += cost[j];
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 1000010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = (1 << 30) - 1;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

int N;
int G[110][110];

void loop(int at) {
	if(at == N) {
		rep(i, 0, N - 1) {
			rep(j, 0, N - i - 1) {
				G[i + 1][j] = abs(G[i][j] - G[i][j + 1]);
			}
		}
		if(G[N - 1][0] == 2)
		debug(vi(G[0], G[0] + N), G[N - 1][0]);
		return;
	}
	rep(i, 0, 3) {
		G[0][at] = i;
		loop(at + 1);
	}
}

int A[MAX_N];
int S[MAX_N];

void solve() {
	cin >> N;
	// loop(0);
	bool even = true;
	rep(i, 0, N) {
		char c; cin >> c; A[i] = c - '1';
		if(A[i] == 1) even = false;
	}
	rep(i, 1, N) {
		int a = i, cnt = 0;
		while(a % 2 == 0) {
			a /= 2; cnt++;
		}
		S[i] = S[i - 1] + cnt;
	}
	if(even) {
		rep(i, 0, N) A[i] /= 2;
	}
	int v = 0;
	rep(i, 0, N) {
		v += A[i] * (S[N - 1] - S[i] - S[N - 1 - i] == 0);
		v %= 2;
	}
	int ans = even ? v ? 2 : 0 : v;
	cout << ans << "\n";
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
	if(!freopen("in.txt", "rt", stdin)) return 1;
#endif	
	solve();
    cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}



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

#if defined(DEBUG)

#include <unistd.h>
#include <sys/fcntl.h>
#define DLOG(...)        cerr << dbgFormat(__VA_ARGS__) << endl
#define DCALL(func, ...) func(__VA_ARGS__)

template <class... Args>
string dbgFormat(const char* fmt, Args... args) {
  size_t len = snprintf(nullptr, 0, fmt, args...);
  char buf[len + 1];
  snprintf(buf, len + 1, fmt, args...);
  return string(buf);
}

#else  // defined(DEBUG)

#define DLOG(...)
#define DCALL(func, ...)

#endif // defined(DEBUG)
// ----------------------------------------------------------------------

// ----------------------------------------------------------------------
int main(int argc, char *argv[]) {
#if defined(DEBUG)
  // GDB on Cygwin ignores redirection at run command.
  if (argc == 2) dup2(open(argv[1], 0), 0);
#else
  // For performance.  We should not use C-style stdio functions
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
#endif
  cout << setprecision(20);

  int N; cin >> N;
  vector<ll> P(N), od(N);
  for (int i = 0; i < N; i++) cin >> P.at(i);
  iota(od.begin(), od.end(), 0);
  sort(od.begin(), od.end(),
       [&](int i, int j) { return P.at(i) > P.at(j); });
  set<ll> indices;
  ll ans = 0;
  for (int i : od) {
    auto it = indices.insert(i).first;
    int x2 = -1, x1 = -1, y1 = N, y2 = N;
    auto it0 = it;
    if (it0 != indices.begin()) {
      x1 = *--it0;
      if (it0 != indices.begin()) x2 = *--it0;
    }
    it0 = it;
    if (++it0 != indices.end()) {
      y1 = *it0;
      if (++it0 != indices.end()) y2 = *it0;
    }
    DLOG("i=%d, x2=%d, x1=%d, i=%d, y1=%d, y2=%d, P.at(i)=%d",
	 i, x2, x1, i, y1, y2, P.at(i));
    ans += P.at(i) * ((x1 - x2) * (y1 - i) + (y2 - y1) * (i - x1));
  }
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());

typedef long long ll;

int main(){
  int k;//k=円周
  cin >> k;
  int n;//n=家の数
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  sort(a);
  int dis = k - a[n-1] + a[0];
  rep(i,n-1){
    dis = max(dis,a[i+1]-a[i]);
  }
  cout << k - dis << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include<string.h>
int main(int argc, char const *argv[])
{
  char s[6];
  scanf("%s",s);
  if(s[2]!=s[3] || s[4]!=s[5]){
      printf("No");
      return 0;
  }
  printf("Yes");
  return 0;
}

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

using namespace std;

typedef long long ll;

double getTime() { 
  return clock() / (double) CLOCKS_PER_SEC;
}

void read() {};

template<typename T, typename... Args>
void read(T& a, Args&... args) {
  cin >> a;
  read(args...);
}

void print() {};

template <typename T, typename... Args>
void print(T a, Args... args) {
  cout << a << " \n"[sizeof...(args) == 0];
  print(args...);
}

int main() {
  int n, m;
  read(n, m);
  map <char, int> cnt;
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < m; j++) {
      char c; 
      read(c);
      cnt[c]++;
    }
  }
  int g1 = (n * m) % 2;
  int g4 = (n / 2) * (m / 2);
  int g2 = (n * m - 4 * g4 - g1) / 2;
  for(auto &p : cnt) {
    while(p.second >= 4 and g4) {
      p.second -= 4;
      g4--;
    }
    while(p.second >= 2 and g2) {
      p.second -= 2;
      g2--;
    }
    while(p.second >= 1 and g1) {
      p.second -= 1;
      g1--;
    }
  }
  if(g1 or g2 or g4) {
    print("No");
  }
  else {
    print("Yes");
  }
}

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

const int MAX_N = 100100;
int A[MAX_N], coefficient[MAX_N], N;

ll up_down_so_on(){
    int down = N/2;
    int up = N - down;
    ll res = 0;
    if(N%2) { // up, down, ...., down, up
        res += A[down] + A[down + 1];
        for(int i = down + 2; i < N; ++i) res += 2*A[i];
        for(int i = 0; i < down; ++i) res += -2*A[i];
    }
    else { // up, down, ..., up, down
        res += A[down] - A[down-1];
        for(int i = down + 1; i < N; ++i) res += 2*A[i];
        for(int i = 0; i < down-1; ++i) res += -2*A[i];
    }
    return res;
}

ll down_up_so_on(){
    int up = N/2;
    int down = N - up;
    ll res = 0;
    if(N%2) { // down, up, ..., up, down
        res += -A[down-1] -A[down-2];
        for(int i = down; i< N; ++i) res += 2*A[i];
        for(int i = 0; i < down-2; ++i) res += -2*A[i];
    }
    else { // down, up, ..., down, up
        res += -A[down-1] + A[down];
        for(int i = down + 1; i < N; ++i) res += 2*A[i];
        for(int i = 0; i < down-1; ++i) res += -2*A[i];
    }
    return res;
}

int main()
{

    scanf("%d", &N);
    for(int i = 0; i < N; ++i) scanf("%d", &A[i]);

    sort(A, A + N);
    ll res = max(up_down_so_on(), down_up_so_on());
    printf("%lld\n", res);
    return 0;
}

Measured memory_bytes: 768
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC target("avx,avx2,fma,sse,sse2")
#pragma GCC optimization ("unroll-loops")

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

using ll = long long;
int main()
{
    ll n;
    cin>>n;
    vector<ll>a(n),b(3);
    for(auto &i:a)cin>>i;
    ll  ans=0;
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            for(int k=j+1;k<n;k++)
            {
                if((a[i]+a[j]+a[k])-max(a[i],max(a[j],a[k]))>max(a[i],max(a[j],a[k]))&&a[i]!=a[j]&&a[j]!=a[k]&&a[i]!=a[k])ans++;
            }
        }
    }
    cout<<ans<<endl;

}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
#include <iostream>
#include <functional>
#include <vector>
#include <stdio.h>
#include <queue>
#include <string.h>
#include <math.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define rep1(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
#define per1(i,a,n) for (int i=a;i>n;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define endl "\n"
#define pi 3.14159265358979323846264338327950288419716939937510
#define IOS cin.sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll mod=1000000007;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
ll qpow(ll a,ll b){ll s=1;while(b>0){if(b%2==1){s=s*a;}a=a*a;b=b>>1;}return s;}
ll qpowmod(ll a, ll b, ll c){ll res, t;res=1;t=a%c;while(b){if(b & 1){res=res*t%c;}t=t*t%c;b>>=1;}return res;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline long long read(){long long k=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){k=k*10+ch-'0';ch=getchar();}return k*f;}
inline void write(long long x){if(x<0)x=-x,putchar('-');if(x>9)write(x/10);putchar(x%10+'0');}
// head
ll n,ac,wa,tle,re;
string cnt;
int main()
{
    //IOS;
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>cnt;
        if(cnt=="AC")
        {
            ac++;
        }
        else if(cnt=="WA")
        {
            wa++;
        }
        else if(cnt=="TLE")
        {
            tle++;
        }
        else if(cnt=="RE")
        {
            re++;
        }
    }
    cout<<"AC x "<<ac<<endl;
    cout<<"WA x "<<wa<<endl;
    cout<<"TLE x "<<tle<<endl;
    cout<<"RE x "<<re<<endl;
    return 0;
}
/*
AC x 3
WA x 1
TLE x 2
RE x 0

*/


Measured memory_bytes: 3636
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine();

        String rest = "keyence";
        int restI = 0;
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == rest.charAt(restI)) {
                restI++;
                if (restI == rest.length()) {
                    System.out.println("YES");
                    return;
                }
                continue;
            }

            if (s.substring(s.length() - (rest.length() - restI), s.length()).equals(rest.substring(restI, rest.length()))) {
                System.out.println("YES");
                return;
            } else {
                break;
            }
        }
        System.out.println("NO");
    }
}


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

int main(void){
    int i;
    
    string str;
    cin >> str;
    
    int q;
    cin >> q;
    
    string op;
    int a, b;
    string p;
    
    while(cin >> op){
        if(op == "print"){
            cin >> a >> b;
            for(i = a; i <= b; i++){
                cout.put(str[i]);
            }
            cout << endl;
        }
        else if(op == "reverse"){
            cin >> a >> b;
            reverse(str.begin() + a, str.begin() + b + 1);
            }
        else if(op == "replace"){
            cin >> a >> b >> p;
            for(i = a; i <= b; i++){
                str[i] = p[i - a];
            }
        }else getline(cin, p);
        
    }
    
    return 0;
}

Measured memory_bytes: 3232
"use strict"
const create = () => {
    const input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
    const res = {
        "list": input, "index": 0, "max": input.length,
        "hasNext": function() {return this.index < this.max},
        "next": function() { if (!this.hasNext()) {throw "ArrayIndexOutOfBoundsException";}else{return this.list[this.index++];}}
    };
    return res;
}
const o = create();
const next = () => o.next()
const nextInt = () => parseInt(o.next())
const nextStrArray = () => o.next().split(" ")
const nextIntArray = () => o.next().split(" ").map(el => parseInt(el))
const nextCharArray = () => o.next().split("")
const hasNext = () => o.hasNext()
const myout = (...x) => console.log(...x)
const Main = () => {
    const alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    const n = nextInt()
    const s = next()
    let ans = ""
    for(let i = 0; i<s.length; i++){
        let idx = (alpha.indexOf(s[i]) + n ) % 26
        ans += alpha[idx]
    }
    console.log(ans)
}
Main()

Measured memory_bytes: 32976
#include<iostream>
#include<vector>
#include<queue>
#include <string>
#include <sstream>
#include <queue>
#include <cmath>
#include <map>
#include <algorithm>
using namespace std;

const long MOD = 1e9 + 7;
int main()
{
  string s;
  cin >> s;
  
  int mins=-1;
  int maxs=-1;
  for(int i=0;i<s.size();i++){
    if (s[i]=='A'){
      mins =i;
      break;
    }
  }
  for(int i=s.size()-1;i>=0;i--){
    if (s[i]=='Z'){
      maxs =i;
      break;
    }
  }


  cout << maxs-mins + 1<< endl;

  return 0;
}






Measured memory_bytes: 640
from itertools import combinations

N, D = map(int, input().split())
d = [tuple(map(int, input().split())) for _ in range(N)]

ans = 0
for a, b in combinations(d, 2):
    dist = sum(abs(i-j)**2 for i,j in zip(a, b))
    for i in range(1, int(dist**0.5)+1):
        if i**2==dist:
            ans += 1
            break
    
print(ans)

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


int main() {
	int ans=0;
	string s;
	cin>>s;
	for(int i=0;i<4;i++){
		if(s.substr(i,1)=="2")ans++;
	}
	cout<<ans<<endl;
		return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define N 233
const int inf=0x3f3f3f3f;
inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
int n,a[N],b[N],dp[1<<18][52],ans;
inline int Abs(int x){
	return x>=0?x:-x;
}
int main(){
	n=read();
	ans=inf;
	for(int i=1;i<=n;++i){
		a[i]=read();
	}
	for(int i=1;i<=n;++i){
		b[i]=read();
	}
	memset(dp,0x3f,sizeof(dp));
	dp[0][1]=0;
	for(int i=1;i<(1<<n);++i){
		int t=__builtin_popcount(i);
		for(int j=1;j<=n;++j){
			if((i>>j-1)&1){
				int p=(1<<j-1),num=Abs(t-j)&1?b[j]:a[j],re=0;
				for(int z=j+1;z<=n;++z){
					if((i>>z-1)&1)++re;
				}
				for(int d=0;d<=num;++d){
					dp[i][num]=min(dp[i][num],dp[i^p][d]+re);
				}
			}
		}
	}
	for(int i=1;i<=50;++i){
		ans=min(ans,dp[(1<<n)-1][i]);
	}
	printf("%d\n",ans==inf?-1:ans);
	return 0;
}



Measured memory_bytes: 56964
MOD = 10 ** 9 + 7
n, k, m = map(int, input().split())
a = list(map(int, input().split()))
def include_perm(a):
    for i in range(m - k + 1):
        seen = [False] * (k + 1)
        for j in range(i, i + k):
            if seen[a[j]]:
                break
            seen[a[j]] = True
        else:
            return True
    return False
def unique_len(a):
    seen = [False] * (k+1)
    ans = 0
    for ai in a:
        if seen[ai]:
            break
        seen[ai] = True
        ans += 1
    return ans
if unique_len(a) < m:
    dp_fw = [[0] * k for _ in range(n-m+1)]
    dp_bw = [[0] * k for _ in range(n-m+1)]
    if not include_perm(a):
        dp_fw[0][unique_len(reversed(a))] = 1
        dp_bw[0][unique_len(a)] = 1
    for i in range(n-m):
        for j in range(k):
            dp_fw[i+1][j] = dp_fw[i][j]
            dp_bw[i+1][j] = dp_bw[i][j]
        for j in range(k-2, 0, -1):
            dp_fw[i+1][j] += dp_fw[i+1][j+1]
            dp_fw[i+1][j] %= MOD
            dp_bw[i+1][j] += dp_bw[i+1][j+1]
            dp_bw[i+1][j] %= MOD
        for j in range(k-1):
            dp_fw[i+1][j+1] += dp_fw[i][j] * (k-j)
            dp_fw[i+1][j] %= MOD
            dp_bw[i+1][j+1] += dp_bw[i][j] * (k-j)
            dp_bw[i+1][j] %= MOD
    ans = 0
    tot = pow(k, n-m, MOD)
    for i in range(n-m+1):
        lcnt = i
        rcnt = n - m - i
        t = tot - sum(dp_fw[rcnt]) * sum(dp_bw[lcnt])
        ans = (ans + t) % MOD
    print(ans)
else:
    dp = [[0] * k for _ in range(n+1)]
    dp2 = [[0] * k for _ in range(n+1)]
    dp[0][0] = 1
    for i in range(n):
        for j in range(1, k):
            dp[i+1][j] = dp[i][j]
            dp2[i+1][j] = dp2[i][j]
        for j in range(k-2, 0, -1):
            dp[i+1][j] += dp[i+1][j+1]
            dp[i+1][j] %= MOD
            dp2[i+1][j] += dp2[i+1][j+1]
            dp2[i+1][j] %= MOD
        for j in range(k-1):
            dp[i+1][j+1] += dp[i][j] * (k-j)
            dp[i+1][j+1] %= MOD
            dp2[i+1][j+1] += dp2[i][j] * (k-j)
            dp2[i+1][j+1] %= MOD
        for j in range(m, k):
            dp2[i+1][j] += dp[i+1][j]
            dp2[i+1][j] %= MOD
    f = 1
    for i in range(m):
        f = f * (k - i) % MOD
    t = sum(dp2[n]) * pow(f, MOD-2, MOD) % MOD
    ans = ((n-m+1) * pow(k, n-m, MOD) - t) % MOD
    print(ans)

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;
#define rep(i,s,e) for(int i = (int)(s); i < (int)(e); ++i)
#define per(i,s,e) for(int i = (int)(s)-1; i >= (int)(e); --i)

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;

template<class T>
bool ChangeMax(T&a,const T&b){
  if(a >= b) return false;
  a = b;    return true;
}

template<class T>
bool ChangeMin(T&a,const T&b){
  if(a <= b) return false;
  a = b;    return true;  
}

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  int n; cin >> n;
  heaP<P<int,int>> hp;
  rep(i,0,n){
    int x; cin >> x;
    hp.push({x,i});
  }
  set<int> st;
  st.insert(-1);
  st.insert(n);
  ll ans = 0;  
  while(!hp.empty()){
    int x = hp.top().second;
    ll y = hp.top().first;
    hp.pop();
    st.insert(x);
    auto f = st.find(x);
    auto p = f;
    auto now = p;
    f++;
    p--;
    ll a = *f - *now;
    ll b = *now - *p;
    ans += (a * b)*y;
  }
  cout << ans << endl;
  return 0;
  
}


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

int main(){
  string s;
  cin >> s;
  int n = s.size();
  vector<string> a{"Sunny", "Cloudy", "Rainy"};
  int now;
  rep(i, n){
    if (s == a[i]) now = i;
  }
  int next = now + 1;
  if (next == 3) next = 0;
  cout << a[next] << endl;
  
  return 0;
}

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

int main() {
    int n;
    string s;
    cin >> n >> s;
    n = 0;
    while(!s.empty()) {
        if(s[0] == 'R')
            s = s.substr(1);
        else if(s.back() == 'W')
            s = s.substr(0, s.length() - 1);
        else
            n++, s = s.substr(1, s.length() - 2);
    }
    cout << n << endl;
    return 0;
}


Measured memory_bytes: 3848
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

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

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

void solve(long long M, long long D)
{
    ll ans = 0;
    for (int i = 1; i <= M; i++)
    {
        for (int j = 1; j <= D; j++)
        {
            if(j < 10){
                continue;
            }
            if (j / 10 >= 2 && j % 10 >= 2 && ((j / 10) * (j % 10)) == i)
            {
                ans++;
            }
        }
    }
    cout << ans << endl;
}

int main()
{
    long long M;
    scanf("%lld", &M);
    long long D;
    scanf("%lld", &D);
    solve(M, D);
    return 0;
}


Measured memory_bytes: 256