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

using namespace std;
using i64 = int64_t;
using ui64 = uint64_t;

/////

int gcd(int a, int b){
    while(b){
        int t = b;
        b = a % b;
        a = t;
    }
    return a;
}

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(auto&& x:a)cin >> x;
    int ret = a[0];
    for(auto&& x:a){
        ret = ret * x / gcd(ret, x);   
    }
    cout << ret << endl;
}


Measured memory_bytes: 3084
Module Program
  Sub Main
    Dim s=GetInts()
    Dim a=s(0)
    Dim ans=a Mod 10
    ans+=(a\10)Mod 10
    ans+=(a\100)Mod 10
    Console.WriteLine(ans)
  End Sub
  
  '/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
  Function Gets() As String()
    Gets = Console.ReadLine().Split(" "c)
  End Function
  Function GetInts() As Integer()
    Dim s = Gets(), r(UBound(s)) As Integer
    For i As Integer=0 To UBound(s): r(i)=s(i): Next i
    GetInts = r
  End Function
End Module

Measured memory_bytes: 22352
import java.util.*;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
       int A = sc.nextInt();
        int arr[] = new int[1000100];
        for (int i = 0; i < A; i++) {
            int num = sc.nextInt();
            if (num != 0) {
            	arr[num - 1]++;} 
            arr[num]++;
            arr[num + 1]++;}
        int best = 0;
          for (int i = 0; i < arr.length; i++) {
            if (arr[i] > best) {
            	best = arr[i];}}
           System.out.println(best);
        sc.close();}}
 
    

Measured memory_bytes: 62292
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N,X,c,a=0,i=0;
    vector<int> b(10,0);
    cin >>N;
    X=N;
    for(int i=0;i<10;i++){
        b[i]=N%10;
        N=N/10;
    }

    for(int k=0;k<10;k++){
        a=a+b[k];
    }


    if(X%a==0){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <stack>
#include <queue>
#include <iomanip>
#include <set>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
bool visit[3000][3000];
int offsetx = 1500;
int offsety = 1500;

int main()
{
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    int dx = tx - sx;
    int dy = ty - sy;
    vector<char> res;

    for (int x = 0; x < dx; ++x)
    {
        res.push_back('R');
    }
    for (int y = 0; y < dy; ++y)
    {
        res.push_back('U');
    }
    for (int x = 0; x < dx; ++x)
    {
        res.push_back('L');
    }
    for (int y = 0; y < dy; ++y)
    {
        res.push_back('D');
    }
    res.push_back('D');
    for (int x = 0; x < dx + 1; ++x)
    {
        res.push_back('R');
    }
    for (int y = 0; y < dy + 1; ++y)
    {
        res.push_back('U');
    }
    res.push_back('L');

    res.push_back('U');
    for (int x = 0; x < dx + 1; ++x)
    {
        res.push_back('L');
    }
    for (int y = 0; y < dy + 1; ++y)
    {
        res.push_back('D');
    }
    res.push_back('R');

    for (const auto& c : res)
    {
        cout << c;
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3592
// スタックサイズ: 100MB

#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
using namespace std;

typedef int64_t ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
const ll INF = 1e18;
const double EPS = 1e-10;
const ll mod = 1e9 + 7;
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define fst first
#define snd second
ll pw(ll x, ll y) { ll r = 1;  rep(i, y) { r *= x; }; return r; }




int main() {
	fastio;

	ll N;
	cin >> N;
	vll v(N), c(N);
	rep(i, N) cin >> v[i];
	rep(i, N) cin >> c[i];
	ll ans = 0;
	rep(i, N) ans += max((ll)0, v[i] - c[i]);
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  int k;
  int a;
  int b;
  cin>>k;
  cin>>a;
  cin>>b;
  int count;
  int judge;
  judge=0;
  for (count=a; count<=b; count+=1){
    if(count%k==0){
      cout<<"OK"<<endl;
      judge=1;
      break;
    }
    else{
      continue;
    }
  }   
  if(judge==0){
    cout<<"NG"<<endl;
  }
  return 0;
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
#include <climits>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define srep(i, begin, end) for (__typeof(end) i = begin; i != end; i++)
#define si(x) int x = scanInt();
#define sll(x) LL x = scanLong();
#define sci(x) int x; scanf("%d", &x);
#define scll(x) LL x; scanf("%lld", &x);
#define pi(x) printf("%d ", x)
#define pll(x) printf("%lld ", x)
#define nl printf("\n")
#define clr(a) memset(a, 0, sizeof(a))
#define PB push_back
#define MP make_pair
using namespace std;
typedef unsigned int UI; // 32 bit integer
typedef long int LI; // 32 bit integer
typedef unsigned long int ULI; // 32 bit unsigned integer
typedef long long int LL; // 64 bit integer
typedef unsigned long long int  ULL; // 64 bit unsigned integer
typedef long double LD;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
const LL MOD = 1e9+7;

/* Fast I/O */
inline int scanInt() {
	int n = 0;
	char ch = getchar();
	int sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(int)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

inline LL scanLong() {
	LL n = 0;
	char ch = getchar();
	LL sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(LL)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

int main() {
	sll(a); sll(b); sll(c);
	if(min(a, b) <= c && c <= max(a, b))	puts("Yes");
	else	puts("No");
}


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

int main(){
  string S;
  cin>>S;
  vector <int> l(100000,-1);
  vector <int> r(100000,-1);
  int flag=0;
  int tempr=0;
  int templ=0;
  int temp=0;
  for(int i=0;i<S.length();i++){
    if((flag==0)&&(S[i]=='R')){
      tempr++;
    continue;
    }

    if((flag==0)&&(S[i]=='L')){
      templ++;
      flag=1;
      continue;
    }
      
    if((flag==1)&&(S[i]=='L')){
      templ++;
    continue;
    }    
    if((flag==1)&&(S[i]=='R')){
      r[temp]=tempr;
      l[temp]=templ;
      tempr=1;
      templ=0;
      temp++;
      flag=0;
    }
  }
  r[temp]=tempr;
  l[temp]=templ;
  int cnt=0;
  temp=0;
  while(1){
    if(r[temp]==-1)break;
    for(int i=0;i<r[temp]-1;i++){
      cout<<0<<" ";
      cnt++;
    }
    cout<<r[temp]/2+r[temp]%2+l[temp]/2<<" ";cnt++;
    cout<<l[temp]/2+l[temp]%2+r[temp]/2<<" ";cnt++;
    for(int i=0;i<l[temp]-1;i++){
      cout<<"0";
      cnt++;
      if(cnt<S.length()){
        cout<<" ";
      }
    }
    temp++;
  }
  return 0;
}

  

Measured memory_bytes: 1408
n,m = map(int,input().split())

ans = 0

class UnionFind:
    def __init__(self,n):
        self.root = [i for i in range(n+1)]

    def Root_Find(self,x):
        if self.root[x] == x:
            return x
        else:
            self.root[x] = self.Root_Find(self.root[x])
            return self.root[x]

    def Unite(self,x,y):
        x = self.Root_Find(x)
        y = self.Root_Find(y)
        if x == y:
            return
        self.root[y] = x

tree = UnionFind(n)

for i in range(m):
    a,b = map(int,input().split())
    tree.Unite(a,b)

for i in range(n+1):
    tree.Root_Find(i)

ans = len(list(set(tree.root))) - 2
print(ans)

Measured memory_bytes: 82304
#include <stdio.h>
#include <iostream>
#include <vector>

using namespace std;

int main(){

    int n, k;

    cin >> n >> k;

    // cout << n << " " << k << endl;

    vector<int> snukes(n, 0);

    int snackQ[k];

    for(int i= 0; i < k; i++){
        int quantity;

        cin >> quantity;

        snackQ[i] = quantity;

        // cout << quantity << endl;

        for(int j = 0; j < quantity; j++){
            int snuke;
            cin >> snuke;
            snukes[snuke-1]++;
            // cout << snuke << " ";
        }
        // cout<<endl;
    }

    int count = 0;
    for(int i = 0; i < n; i++){
        if(snukes[i] == 0){
            count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 3592
import array
import itertools
from collections import defaultdict, deque


def log(s):
    # print("| " + str(s), file=sys.stderr)
    pass


def output(x):
    print(x, flush=True)


def input_ints():
    return map(int, input().split())


def solve():
    def find_path(p0, p1):
        queue = deque()
        footsteps = dict()

        queue.append((p0, 0))

        while queue:
            p, s = queue.popleft()
            footsteps[p] = s

            if p == p1:
                return s

            for pp in [(p[0] + 1, p[1]), (p[0] - 1, p[1]), (p[0], p[1] + 1), (p[0], p[1] - 1)]:
                if 0 <= pp[0] < width and 0 <= pp[1] < height and field[pp[1]][pp[0]] == '.' and pp not in footsteps:
                    queue.append((pp, s + 1))
                    footsteps[pp] = -1  # placeholder

        return -1

    height, width = tuple(input_ints())
    field = [input() for _ in range(height)]

    s = find_path((0, 0), (width - 1, height - 1))

    if s < 0:
        return -1
    else:
        return "".join(field).count(".") - (s + 1)


def main():
    print(solve())


main()


Measured memory_bytes: 3692
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
int main(void){
    string s;
    cin >> s;
    for(auto & x : s){
        if(x == '9'){
            x = '1';
        }else if(x == '1'){
            x = '9';
        }
    }
    cout << s;
}

Measured memory_bytes: 384
package main

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

const (
	initialBufSize = 10000
	maxBufSize     = 10000000
)

var (
	sc = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		sc.Split(bufio.ScanWords)
		return sc
	}()
)

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

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

func nextFloat() float64 {
	sc.Scan()
	f, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func main() {
	x, n := nextInt(), nextInt()
	flags := make(map[int]bool)
	for i := 0; i < n; i++ {
		p := nextInt()
		flags[p] = true
	}

	dist := 0
	for {
		if !flags[x-dist] {
			fmt.Println(x - dist)
			return
		}
		if !flags[x+dist] {
			fmt.Println(x + dist)
			return
		}
		dist++
	}
	return
}


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

template<class T> struct Fenwick {
    vector<T> bit; int N;
    Fenwick(int n) : N(n) { bit.assign(n+1, 0); }
    // add w to a
    void add(int a, T w) {
        for (int x = ++a; x <= N; x += x & -x) bit[x] += w;
    }
    // sum [0, a)
    T sum(int a) {
        T ret = 0;
        for (int x = a; x > 0; x -= x & -x) ret += bit[x];
        return ret;
    }
    // sum [a, b)
    T sum(int a, int b) { return sum(b) - sum(a); }
};


int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; long long d, a; cin >> n >> d >> a;
    vector<pair<long long, long long>> v;
    set<long long> st; map<long long, int> compress;
    for (int i = 0; i < n; i++) {
        long long x, h; cin >> x >> h;
        v.emplace_back(x, h);
        st.insert(x); st.insert(x+2*d+1);
    }
    for (auto &x: st) {
        int t = compress.size();
        compress[x] = t;
    }
    int sz = compress.size();
    Fenwick<long long> f(sz);
    sort(v.begin(), v.end());
    long long ans = 0;
    for (int i = 0; i < n; i++) {
        long long diff = f.sum(compress[v[i].first]+1);
        long long remain = v[i].second - diff;
        if (remain <= 0) continue;
        long long req = (remain + a - 1) / a;
        ans += req;
        f.add(compress[v[i].first], req * a);
        f.add(compress[v[i].first+2*d+1], -req * a);
    }
    cout << ans << "\n";
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
//#define int long long

signed main(){
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    
    int x_max = x, y_min = y;
    rep(i,n){
        int t; cin >> t;
        x_max = max(x_max, t);
    }
    rep(i,m){
        int t; cin >> t;
        y_min = min(y_min, t);
    }
    
    if(x_max < y_min) cout << "No ";
    cout << "War" << endl;
}

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

int main() {
    string s;
    cin >> s;
    int ans1 = 0, ans2 = 0;
    rep(i,s.size()) {
      if (i%2 == 0 && s[i] == '0') ans1++;
      if (i%2 != 0 && s[i] == '1') ans1++;
    }
    rep(i,s.size()) {
      if (i%2 == 0 && s[i] == '1') ans2++;
      if (i%2 != 0 && s[i] == '0') ans2++;
    }
    int ans = min(ans1, ans2);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3776
import math

for i in range(50):
    
    m,f,r=list(map(float, input().split()))
    x=m+f
    if m==-1 and f==-1 and r==-1:
        break
    
    elif m==-1 or f==-1 :
        print("F")
        
    elif x>=80 :
        print("A")
    
    elif 80>x>=65 :
        print("B")
    
    elif 65>x>=50 :
        print("C")
        
    elif 50>x>=30 :
        if r>=50 :
            print("C")
        else :
            print("D")
    else :
        print("F")


Measured memory_bytes: 5632
#include <bits/stdc++.h>
#define P 1000000007
using namespace std;

signed main() {
    string k;
    int d;
    cin>>k>>d;
    vector<int> dp0(d,0),dp1(d,0);
    dp0[0] = 1;
    for(int i=0;i<k.size();i++)
    {
        vector<int> dp2(d,0),dp3(d,0);
    

        for(int i1=0;i1<d;i1++)
        {
            for(int j=0;j<=9;j++)
            {
                (dp3[(i1+j)%d] += dp1[i1]) %=P;
            }
            for(int j=0;j<=(k[i] - '0');j++)
            {    if(j <(k[i] - '0'))
                (dp3[(i1+j)%d] += dp0[i1]) %=P;
                else
                (dp2[(i1+j)%d] += dp0[i1]) %=P;
            }
        }
        
        dp1 = dp3;
        dp0 = dp2;
    }
    cout<<(dp1[0] + dp0[0] -1 + P)%P;
    return 0;
}

Measured memory_bytes: 3628
w, a, b = map(int, input().split())

if a <= b <= a + w or b <= a + w <= b + w or b <= a <= b+w or a <= b + w <= a + w:
    print(0)
elif a + w < b:
    print(b - a - w)
elif b+w < a:
    print(a - b - w)

Measured memory_bytes: 38256
/*
  By Anudeep Nekkanti
  Editorial at http://blog.anudeep2011.com/mos-algorithm/
  Question at http://www.spoj.com/problems/DQUERY/
  O( (N+M) * sqrt N )
*/

#include <cstdio>
#include <algorithm>
using namespace std;

#define N 511111
#define A 5111111
#define BLOCK 715 // ~sqrt(N)

int cnt[A], a[N], ans[N], answer = 0;

struct node {
  int L, R, i;
}q[N];

bool cmp(node x, node y) {
  if(x.L/BLOCK != y.L/BLOCK) {
    // different blocks, so sort by block.
    return x.L/BLOCK < y.L/BLOCK;
  }
  // same block, so sort by R value
  return x.R < y.R;
}

void add(int position) {
  cnt[a[position]]++;
  if(cnt[a[position]] == 1) {
    answer++;
  }
}

void remove(int position) {
  cnt[a[position]]--;
  if(cnt[a[position]] == 0) {
    answer--;
  }
}

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

  for(int i=0; i<m; i++) {
    scanf("%d%d", &q[i].L, &q[i].R);
    q[i].L--; q[i].R--;
    q[i].i = i;
  }

  sort(q, q + m, cmp);

  int currentL = 0, currentR = 0;
  for(int i=0; i<m; i++) {
    int L = q[i].L, R = q[i].R;
    while(currentL < L) {
      remove(currentL);
      currentL++;
    }
    while(currentL > L) {
      add(currentL-1);
      currentL--;
    }
    while(currentR <= R) {
      add(currentR);
      currentR++;
    }
    while(currentR > R+1) {
      remove(currentR-1);
      currentR--;
    }
    ans[q[i].i] = answer;
  }

  for(int i=0; i<m; i++)
    printf("%d\n", ans[i]);
}

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

int main() {
  ll N, C, m = 10000000000; // numeric_limits<ll>::infinity();
  vector<vector<ll>> D;
  vector<vector<ll>> c;
  cin >> N >> C;
  rep(i, C) {
    vector<ll> a;
    rep(j, C) {
      ll po;
      cin >> po;
      a.push_back(po);
    }
    D.push_back(a);
  }
  rep(i, 3) {
    vector<ll> a;
    rep(j, C) { a.push_back(0); }
    c.push_back(a);
  }
  rep(i, N) {
    rep(j, N) {
      ll po;
      cin >> po;
      c[(i + j) % 3][po - 1]++;
    }
  }
  rep(i0, C) rep(i1, C) rep(i2, C) {
    if (i0 == i1 || i1 == i2 || i0 == i2)
      continue;
    ll color[3] = {i0, i1, i2};
    ll po = 0;
    rep(j, C) rep(k, 3) { po += c[k][j] * D[j][color[k % 3]]; }
    if (po < m)
      m = po;
  }
  cout << m << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<vector>
    #include<array>
    #include<deque>
    #include<queue>
    #include<map>
    #include<cmath>
    #include<stdio.h>
     
    using std::cout;
    using std::cin;
    using std::setw;
    using std::setfill;
    using std::string;
    using std::pair;
    using std::make_pair;
    using std::vector;
    using std::array;
    using std::queue;
    using std::deque;
    using std::priority_queue;
    using std::multimap;
    using std::next_permutation;
    //using std::iota;
    using std::sort;
    using std::greater;
    using std::max;
    using std::min;
    using std::sin;
    using std::cos;
    using std::log;
     
    using lli = long long int;
    using ulli = unsigned long long int;
     
    #define INF 999999999;
    #define MOD 1000000007;
    #define PI 3.141592653589793;
     
    //#define EVEL 1
     
    #ifndef EVEL
    #define dbug(X) std::cout << #X << ":" <<X<<" " ;
    #define dbugf(s) std::cout << s << " ";
    #define dbugln std::cout<<"\n";
    #else
    #define dbug(X) {}
    #define dbugf(s) {}
    #define dbugln {}
    #endif
     
    int A, B;
     
    int main(void){
    	cin.tie(0);
    	std::ios::sync_with_stdio(false);
     
    	cin >> A >> B;
    	cout << (A-1)*(B-1);
     
    	return 0;
    }

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

namespace {

#ifdef LOCAL
#define run_if_local(statement) statement
#else
#define run_if_local(statement)
#endif

#ifdef LOCAL
auto start_timestamp = clock();
void tag_execution_time() {
  std::cerr << "Execution timestamp: " << std::setprecision(4) << std::fixed
            << ((double)clock() - start_timestamp) / CLOCKS_PER_SEC << "s\n";
}
#else
void tag_execution_time() {}
#endif

template <typename Arg, typename... Args>
void __internal_print(std::ostream& out, Arg&& arg, Args&&... args) {
  out << std::forward<Arg>(arg);
  using expander = int[];
  (void)expander{0, (void(out << ' ' << std::forward<Args>(args)), 0)...};
  out << "\n";
}

template <typename Arg, typename... Args>
void __internal_read(Arg&& arg, Args&&... args) {
  std::cin >> std::forward<Arg>(arg);
  using expander = int[];
  (void)expander{0, (void(std::cin >> std::forward<Args>(args)), 0)...};
}

#define __internal_print_array(out, start, end)     \
  for (auto iter = start; iter != end; ++iter) {    \
    out << *iter << (iter + 1 == end ? "\n" : " "); \
  }

#define __internal_print_2d_array(out, array, rows, cols) \
  for (int i = 1; i <= rows; ++i) {                       \
    for (int j = 1; j <= cols; ++j) {                     \
      out << array[i][j] << (j == cols ? "\n" : " ");     \
    }                                                     \
  }

#define print(...) __internal_print(std::cout, __VA_ARGS__)
#define debug(...) __internal_print(std::cerr, __VA_ARGS__)
#define print_array(start, end) __internal_print_array(std::cout, start, end)
#define debug_array(start, end) __internal_print_array(std::cout, start, end)
#define print_2d_array(array, rows, cols) __internal_print_2d_array(std::cin, array, rows, cols)
#define read(...) __internal_read(__VA_ARGS__)
#define read_array(array, start, end)     \
  for (int _i = start; _i <= end; ++_i) { \
    std::cin >> (array)[_i];              \
  }
#define read_2d_array(array, n, m) \
  for (int i = 1; i <= n; ++i) {   \
    for (int j = 1; j <= m; ++j) { \
      std::cin >> array[i][j];     \
    }                              \
  }

#define update_max(a, b) if ((a) < (b)) (a) = (b)
#define update_min(a, b) if ((a) > (b)) (a) = (b)

}  // namespace

const int N = 100000 + 10;

char string[N];
int n, k;

int solve(int token) {
  std::priority_queue<int> heap;
  for (int i = 1; i <= n; ) {
    int j = i;
    while (j <= n && string[i] == string[j]) j ++;
    if (string[i] == token) {
      int x = (i > 1) + (j <= n);
      heap.push(x);
    }
    i = j;
  }

  int result = 0;
  int used = 0;
  while (!heap.empty() && used < k) {
    int x = heap.top();
    heap.pop();
    result += x;
    used ++;
  }
  return result;
}

void run(int case_id = 0) {
  read(n, k);
  read(string + 1);

  int answer = 0;
  for (int i = 1; i <= n; ++ i) {
    if (string[i] == 'L' && string[i - 1] == 'L') {
      answer ++;
    }
    if (string[i] == 'R' && string[i + 1] == 'R') {
      answer ++;
    }
  }

  int r = std::max(solve('L'), solve('R'));
  print(answer + r);
}

int main() {
  std::ios::sync_with_stdio(false);
  run();
  return 0;
}


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

int main(void){
  int N;
  cin>>N;
  int H[N+1];
  for(int i=0;i<N;i++){
    cin>>H[i];
  }
  H[N]=1000000010;
  int ans=0;
  int cnt=0;
  for(int i=1;i<=N;i++){
    if(H[i-1]>=H[i]){
      cnt+=1;
    }
    else{
      ans=max(cnt,ans);
      cnt=0;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

ll search(const vector<ll> &val, int l, int r) {
    ll b = ((l == 0) ? 0 : val[l - 1]);
    ll t = (val[r] - b) / 2, ans;
    while ((l + 1) < r) {
        int m = (l + r) / 2;
        if ((val[m] - b) >= t) r = m;
        else l = m;
    }
    if (abs(t - (val[l] - b)) >= abs(t - (val[r] - b))) ans = val[r];
    else ans = val[l];
    return ans;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    vector<ll> dp(n);
    ll ans = LONG_LONG_MAX;
    rep(i, n) {
        if (i == 0) dp[i] = a[i];
        else dp[i] = dp[i - 1] + a[i];
    }
    reps(i, 1, n - 2) {
        ll p, q, r, s;
        ll ls = search(dp, 0, i);
        ll rs = search(dp, i + 1, n - 1);
        p = ls; q = dp[i] - ls;
        r = rs - dp[i]; s = (dp[n - 1] - dp[i]) - r;
        ans = min(ans, max(p, max(q, max(r, s))) - min(p, min(q, min(r, s))));
    }
    cout << ans << endl;
    return 0;
}

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

typedef long long ll;
#define REP(i, n, m) for(int i = n; i < m; i++)
#define REPR(i, n, m) for(int i = n; i >= m; i--)
#define LREP(i, n, m) for(ll i = n; i < m; i++)
#define LREPR(i, n, m) for(ll i = n; i >= m; i--)

#define P pair<int, int >


const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;



//---functions---//
int gcd(int a, int b){
    if(a < b) swap(a, b);
    return b?gcd(b, a%b):a;
}

int s2i(string num){stringstream ss; ss << num << flush; int n; ss >> n; return n;}
string i2s(int n){stringstream ss; ss << n << flush; return ss.str();}

bool firstCompare(const P& firstElof, const P& secondElof){
    return firstElof.first < secondElof.first;
}
bool secondCompare(const P& firstElof, const P& secondElof){
    return firstElof.second < secondElof.second;
}
//---------------//
//-----class-----//
class UnionFind{
    public:
        vector<ll> par; //parents
        vector<ll> siz; // sizes of set
        vector<ll> rank; // rank of each element 
    UnionFind(ll n): par(n), siz(n, 1LL), rank(n){
        LREP(i, 0, n) par[i] = i;
    }
    //initialization
    /*
    void init(ll n){
        par.assign(n);
        siz.assign(n, 1LL);
        rank.assign(n);
        LREP(i, 0, n) par[i] = i;
    }
    */

    // find the root of x
    ll find(ll x){
        if(par[x] == x) return x;
        else return par[x] = find(par[x]);
    }

    //Unite two set including x or y
    void unite(ll x, ll y){
        x = find(x);
        y = find(y);
        if(x == y) return;
        if(rank[x] < rank[y]){
            par[x] = y;
            siz[y] += siz[x];
        }else{
            par[y] = x;
            siz[x] += siz[y];
            if(rank[x] == rank[y]) rank[x]++;
        }
    }

    //Do x and y belong to the same set?
    bool issame(ll x, ll y){
        return find(x) == find(y);
    }

};

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

    cin >> N;
    int H[N];
    REP(i, 0, N) cin >> H[i];

    vector<int> v;
    int tmp = H[0];
    int count = 0;
    REP(i, 1, N){
        if(H[i] <= tmp){
            ++count;
        }else{
            v.push_back(count);
            count = 0;
        }
        tmp = H[i];
    }
    v.push_back(count);
    sort(v.begin(), v.end(), greater<int>());

    cout << v[0] << '\n';

}


Measured memory_bytes: 1276
#include <cstdio>
#include <utility>
#include <vector>
#include <complex>
#include <cmath>
#include <algorithm>
#include <set>

using namespace std;

static const double EPS=1e-12;
static const double INF=1e24;

using Point=complex<double>;
using Plane=vector<Point>;
using Polygon=vector<Point>;

namespace std {
    bool operator<(const Point &a, const Point &b) {
        return real(a)!=real(b)? real(a)<real(b) : imag(a)<imag(b);
    }
}

double cross_prod(const Point &a, const Point &b) {
    return imag(conj(a)*b);
}

double dot_prod(const Point &a, const Point &b) {
    return real(conj(a)*b);
}

struct Line: public pair<Point, Point> {
    Line() {}
    Line(const Point &a, const Point &b) {
        first = a;
        second = b;
    }
};

struct Circle {
    Point p;
    double r;
    Circle() {}
    Circle(const Point &p, const double r): p(p), r(r) {}
};

pair<Point, Point> get_cpoints(const Circle &c1, const Circle &c2) {
    Point p=c2.p-c1.p;

    double R=norm(p);
    double a=(R+(c1.r*c1.r)-(c2.r*c2.r))/2;
    double D=sqrt(R*(c1.r*c1.r)-a*a);

    Point p1=c1.p+p/R*Point(a, -D);
    Point p2=c1.p+p/R*Point(a, D);

    if (p2 < p1)
        swap(p1, p2);

    return make_pair(p1, p2);
}

int main() {
    double x, y, r;
    scanf("%lf %lf %lf", &x, &y, &r);
    Circle c1(Point(x, y), r);

    scanf("%lf %lf %lf", &x, &y, &r);
    Circle c2(Point(x, y), r);

    pair<Point, Point> cpoints=get_cpoints(c1, c2);
    printf("%.9f %.9f ", real(cpoints.first), imag(cpoints.first));
    printf("%.9f %.9f\n", real(cpoints.second), imag(cpoints.second));
    return 0;
}

Measured memory_bytes: 2784
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let n = get!(usize);
    let a = get!(String).chars().map(|e| e as usize - '1' as usize).collect::<Vec<_>>();

    let mut res = 0;
    for i in 0..n {
        if a[i]%2 == 1 && ((n-1)&i)==i {
            res = (res+1)%2;
        }
    }
    if res == 1 {
        println!("1");
        return;
    }
    if a.iter().any(|&e| e==1) {
        println!("0");
        return;
    }

    let mut res = 0;
    for i in 0..n {
        if a[i]/2%2 == 1 && ((n-1)&i) == i {
            res = (res+1)%2;
        }
    }
    if res == 1 {
        println!("2");
    } else {
        println!("0");
    }
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
    ost<<"{"<<p.first<<","<<p.second<<"}";
    return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
    ost<<"{";
    for(int i=0;i<v.size();i++){
        if(i)ost<<",";
        ost<<v[i];
    }
    ost<<"}";
    return ost;
}

template<uint32_t mod>
struct ModInt{
    uint32_t a;
    ModInt& s(uint32_t vv){
        a=vv<mod?vv:vv-mod;
        return *this;
    }

    ModInt(int64_t x=0){s(x%mod+mod);}

    ModInt& operator+=(const ModInt &x){return s(a+x.a);}
    ModInt& operator-=(const ModInt &x){return s(a+mod-x.a);}
    ModInt& operator*=(const ModInt &x){
        a=uint64_t(a)*x.a%mod;
        return *this;
    }
    ModInt& operator/=(const ModInt &x){
        *this*=x.inv();
        return *this;
    }

    ModInt operator+(const ModInt &x)const{return ModInt(*this)+=x;}
    ModInt operator-(const ModInt &x)const{return ModInt(*this)-=x;}
    ModInt operator*(const ModInt &x)const{return ModInt(*this)*=x;}
    ModInt operator/(const ModInt &x)const{return ModInt(*this)/=x;}
    bool operator==(const ModInt &x)const{return a==x.a;}
    bool operator!=(const ModInt &x)const{return a!=x.a;}
    bool operator<(const ModInt &x)const{return a<x.a;}

    ModInt operator-()const{return ModInt()-*this;}
    ModInt pow(int64_t n)const{
        ModInt res(1),x(*this);
        while(n){
            if(n&1)res*=x;
            x*=x;
            n>>=1;
        }
        return res;
    }

    ModInt inv()const{return pow(mod-2);}
};

template<uint32_t mod>
istream& operator>>(istream& in,const ModInt<mod>& a){
    return (in>>a.a);
}
template<uint32_t mod>
ostream& operator<<(ostream& out,const ModInt<mod>& a){
    return (out<<a.a);
}
using mint=ModInt<1000000007>;
//using mint=ModInt<998244353>;

signed main(){
    int N;
    cin>>N;
    vint A(N);
    rep(i,N)scanf("%lld",&A[i]);

    vint v{0,0,0};
    mint ans=1;

    rep(i,N){
        int c=count(all(v),A[i]);
        if(c==0){
            cout<<0<<endl;
            return 0;
        }
        ans*=c;
        int k=find(all(v),A[i])-v.begin();
        v[k]++;
        sort(all(v));
    }
    cout<<ans<<endl;
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  if(N<=111)cout << 111;
  else if(N<=222)cout << 222;
  else if(N<=333)cout << 333;
  else if(N<=444)cout << 444;
  else if(N<=555)cout << 555;
  else if(N<=666)cout << 666;
  else if(N<=777)cout << 777;
  else if(N<=888)cout << 888;
  else cout << 999;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<algorithm> 
#include<cmath>
#include<cstring>
using namespace std;
int  n,m;

int main()
{
  scanf("%d%d",&n,&m);
  if(n/2019 == m/2019)
   {
   	int ans=101002;
   	n%=2019,m%=2019;
   	for(int i=n;i<m;i++)
   	  for(int j=i+1;j<=m;j++)
   	    ans=min(ans,i*j%2019);
    printf("%d\n",ans);
   }
  else printf("0\n");
} 

Measured memory_bytes: 128
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  ll N, X, M;
  cin>>N>>X>>M;
  map<ll, ll> amap;
  ll ans = 0;
  ll num;
  ll cycle;
  vector<ll> sum;
  bool ok = true;
  for(ll i=0;i<N;++i) {
    sum.push_back(X);
    if(sum.size()>1) sum[sum.size()-1] += sum[sum.size()-2];
    if(amap[X]>0) {
      num = i;
      cycle = amap[X];
      ok = false;
      break;
    }
    amap[X] = i;
    ans += X;
    X = X*X%M;
  }
  if(ok) {
    cout<<ans<<endl;
    return 0;
  }
  ll tmp = sum[num-1] - sum[cycle-1];
  ans += (N-num)/(num-cycle)*tmp;
  ll K = (N-num)%(num-cycle);
  for(ll i=0;i<K;++i) {
    ans += X;
    X = X*X%M;
  }
  cout<<ans<<endl;
}



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

int main() {
    int n;
    cin >> n;
    vector<int> x(n);
    int ave1 = 0, ave2 = 0;
    rep (i, n) {
        cin >> x[i];
        ave1 += x[i];
    }
    ave1 /= n;
    ave2 = ave1 + 1;
    int bunsan1 = 0, bunsan2 = 0;
    rep (i, n) {
        bunsan1 += (ave1 - x[i]) * (ave1 - x[i]);
        bunsan2 += (ave2 - x[i]) * (ave2 - x[i]);
    }
    cout << min(bunsan1, bunsan2) << endl;
}

Measured memory_bytes: 256
/**
*    author:  souzai32
*    created: 14.08.2020 14:58:45
**/

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

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

long long lcm(long long a, long long b)
{
   return a * b / gcd(a, b);
}

int main() {

    int n,k;
    cin >> n >> k;
    vector<long long> a(n);
    rep(i,n) cin >> a.at(i);
    sort(a.begin(),a.end());
    string ans="POSSIBLE";

    if(k>a.at(n-1)) ans="IMPOSSIBLE";
    else if(n!=1){
        long long num=gcd(a.at(0),a.at(1));
        for(int i=2; i<n; i++){
            num=gcd(num,a.at(i));
        }
        if(k%num) ans="IMPOSSIBLE";
    } 
    else if(k!=a.at(0)) ans="IMPOSSIBLE";

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3908
fun main(args: Array<String>) {
  readLine()!!.toInt()
  val a = readLine()!!.split(" ").map { it.toInt() }
  val mn = a.min()!!
  val mx = a.max()!!
  val c = a.count { it == mn }
  var ans = true
  if (mn == 1) {
    if (c == 2) {
      if (mn != mx) ans = false
    } else {
      if (c > 2 || mn * 2 != mx) ans = false
    }
  } else {
    if (c == 1) {
      if (2 * mn != mx) ans = false
    } else if (c == 2) {
      if (2 * mn - 1 != mx) ans = false
    } else {
      ans = false
    }
    for (i in mn + 1..mx) {
      if (a.count { it == i } < 2) ans = false
    }
  }
  println(if (ans) "Possible" else "Impossible")
}


Measured memory_bytes: 37932
#include <bits/stdc++.h>
#define int long long
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define pii pair<int,int>
#define ff first
#define ss second
#define frr(i,n) for(int i=0;i<n;i++)
#define td(v) v.begin(),v.end()
#define inf 1000000000 // 1e9
#define M   1000000007 // 1e9 + 7
#define MAXN 55
using namespace std;
typedef long long ll;

int mod(int a,int m){
	int r = a%m;
	if(r<0)r+=m;
	return r;
}

struct matrix{
	int m [MAXN][MAXN];	
};

matrix base,identidade;
ll n;

matrix mul(matrix a,matrix b){
	matrix aux;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			   	aux.m[i][j]=0;
		}
	}
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			for(int A=0;A<n;A++)
				aux.m[i][j]=mod(aux.m[i][j]+a.m[i][A]*b.m[A][j],M);
	return aux;		
}

matrix exp(int k){
	if(k==0)return identidade;
	if(k==1)return base;
	if(k%2==1){
		matrix c = mul(base,exp(k-1));
		return c;
	}
	matrix c = exp(k/2);
	return mul(c,c);
}

int32_t main(){
	ll k;
	cin>>n>>k;
	for(ll i=0;i<n;i++)
		for(ll j=0;j<n;j++){
			cin>>base.m[i][j];
				  if(i==j)identidade.m[i][j]=1;
				  else identidade.m[i][j]=0;		
	}
	ll res=0;	
	matrix t = exp(k);		  	

	for(ll i=0;i<n;i++){
		for(ll j=0;j<n;j++){
			res=mod(res+t.m[i][j],M);
		}
	}
	cout<<res<<endl;
}

Measured memory_bytes: 10368
n, m = map(int, input().split())
s = input()
s = s[::-1]
idx = 0
ans = []
while(True):
    d = s[idx + 1:idx + m + 1].rfind('0')
    if d == -1:
        print(-1)
        break
    ans.append(d + 1)
    idx += d + 1
    if idx == n:
        print(*ans[::-1])
        break


Measured memory_bytes: 6408
#include <iostream>
#include <list>
#include <string>

using namespace std;

struct Segment {
	int start;
	int end;
	int id;
	
	Segment() {}
	Segment(int s, int e, int id) : start(s), end(e), id(id) {}
};

list<Segment> storage;
void do_write(const int id, const int sectors) {
	list<Segment>::iterator it = storage.begin();
	int prev_last = -1;
	int remain = sectors;
	while(it != storage.end()) {
		if(it->start > prev_last+1) {
			// insert file
			int size = min(remain, it->start - prev_last - 1);
			it = storage.insert(it, Segment(prev_last+1, prev_last+1+size-1, id));
			remain -= size;
			if(remain == 0) break;
		}
		prev_last = it->end;
		++it;
	}
	if(remain > 0) {
		storage.insert(it, Segment(prev_last+1, prev_last+1+remain-1, id));
	}
}

void do_delete(const int id) {
	list<Segment>::iterator it = storage.begin();
	while(it != storage.end()) {
		if(it->id == id) {
			it = storage.erase(it);
		} else {
			++it;
		}
	}
}

int read_sector(const int sector) {
	for(list<Segment>::const_iterator it = storage.begin(); it != storage.end(); ++it) {
		if(it->start <= sector && sector <= it->end) {
			return it->id;
		}
	}
	return -1;
}

bool solve() {
	int N;
	cin >> N;
	if(!N) return false;
	storage.clear();
	while(N--) {
		string cmd;
		cin >> cmd;
		if(cmd == "W") {
			int id, sectors;
			cin >> id >> sectors;
			do_write(id, sectors);
		} else if(cmd == "D") {
			int id;
			cin >> id;
			do_delete(id);
		} else if(cmd == "R") {
			int sector;
			cin >> sector;
			cout << read_sector(sector) << endl;
		}
	}
	cout << endl;
	return true;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	
	for(; solve(); ) ;
	return 0;
}

Measured memory_bytes: 1372
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const ll INF = 1LL<<60;
const int ny[4] = {-1,1,0,0}, nx[4] = {0,0,-1,1};
int sy,sx,gy,gx;


int main(){
  string s; cin >> s;
  int left = 0, right = 0;
  bool flg = false;
  for(int i = 0; i < s.size(); i++){
    if(flg){
      if(s[i] == 'Z') right = i+1;
    }else{
      if(s[i] == 'A'){
        flg = true;
        left = i+1;
      }
    }
  }
  int ans = right - left + 1;
  cout << ans << endl;
  return 0;
}


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

int main() {
    long long int t;
    cin>>t;
    long long int a[3 * t];
    for (long long int i = 0; i < (3 * t); i++) {
      cin >> a[i];
    }
    sort(a, a + (3 * t), greater<long long int>());
    long long int j = 1;
    long long int ans = 0;
    for (long long int i = 0; i < t; i++) {
      ans += a[j];
      j += 2;
    }
    cout<<ans<<endl;
    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

map<int, int> dp;

signed main() {
  int n;
  cin >> n;
  int ks = 1, rs = 1;
  vector<int> v;

  while(n >= ks) {
    ks *= 9;
    rep(i, 0, 5) v.pb(ks);
  }
  while(n >= rs) {
    rs *= 6;
    rep(i, 0, 8) v.pb(rs);
  }
  dp[0] = 0;
  rep(i, 0, v.size()) {
    for(auto it = dp.begin(); it != dp.end(); it++) {
      if(it->first + v[i] <= n) {
        if(dp[it->first + v[i]]) {
          dp[it->first + v[i]] = min(dp[it->first + v[i]], it->second + 1);
        }else {
          dp[it->first + v[i]] = it->second + 1;
        }
      }
    }
  }
  int ans = 1145141919;
  for(auto it = dp.begin(); it != dp.end(); it++) {
    ans = min(ans, it->second + (n - it->first));
  }
  cout << ans << endl;
}


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

ll solve(ll arr[], ll n)
{
    ll dp[100001]={0};
    dp[1]=0;
    
    for(ll i=2; i<n+1; i++)
    {
        ll a = abs(arr[i]-arr[i-1])+dp[i-1];
        ll b = (i==2) ? INT_MAX : abs(arr[i]-arr[i-2])+dp[i-2];
        dp[i]=min(a, b);
    }
    
    return dp[n];
}

int main() {
    ll n;
    cin>>n;
    ll arr[100001];
    for(ll i=1; i<n+1; i++)
    {
        cin>>arr[i];
    }
    cout<<solve(arr, n)<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
} 

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n=nxt();
    string s;
    cin>>s;

    for(int i=0;i<s.length();i++)
    {
        s[i]=(s[i]-65+n)%26+65;
    }
    cout<<s<<endl;

    
    
    

    return 0;   
}


 
 


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long mod=1e9+7;
long long dp[201][100005];
long long int power(long long int a,long long int b) {long long int ret=1;while(b) {if(b&1) ret*=a;a*=a;if(ret>=mod) ret%=mod;if(a>=mod) a%=mod;b>>=1;}return ret;}
long long int inv(long long int x) {return power(x,mod-2);}
int main()
{
    int n;
    cin>>n;
    long long fact[n+1];
    fact[0]=1;

    int i;
    for(i=1;i<=n;i++)
    {
        fact[i]=(i*fact[i-1]%mod)%mod;
    }
    long long x;
    cin>>x;
    long long a[n+1],b[n+1],inve[n+1];
    int j;
    for(i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    sort(a+1,a+n+1);
    for(i=1;i<=n;i++)
    {
        b[n-i+1]=a[i];
    }
    for(i=1;i<=n;i++)
    {
        inve[i]=inv(n-i+1);
    }
    for(i=1;i<=n;i++)
    {
        a[i]=b[i];
    }
    dp[0][x]=1;
    for(i=0;i<n;i++)
    {
        for(j=0;j<=x;j++)
        {
            dp[i+1][j%a[i+1]]=(dp[i+1][j%a[i+1]]%mod+(dp[i][j]%mod*inve[i+1]%mod)%mod)%mod;
            dp[i+1][j]=(dp[i+1][j]%mod+(dp[i][j]%mod*(1-(inve[i+1]%mod)+mod)%mod))%mod;
           // cout<<dp[i+1][j]<<endl;
        }
    }
    long long ans=0;
    for(i=0;i<=x;i++)
    {
       // cout<<dp[n][i]<<endl;
        ans=(ans%mod+(dp[n][i]%mod*i)%mod)%mod;
    }
    cout<<(ans*fact[n])%mod<<endl;
}


Measured memory_bytes: 156544
#include <stdio.h>

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

  int a[100];

  for(int i=0;i<n;i++)
    {
      scanf("%d",&a[n-i-1]);
    }

  for(int i=0;i<n;i++)
    {   if(i==n-1)
	{
	  printf("%d\n",a[i]);
	}
      else
	{
printf("%d ",a[i]);

	}
    }


  return 0;

}

Measured memory_bytes: 1028
#include <stdio.h>
#include<stdlib.h>
using namespace std;

int int_sort( const void * a , const void * b ) {
  /* 引数はvoid*型と規定されているのでint型にcastする */
  if( *( int * )a < *( int * )b ) {
    return -1;
  }
  else
  if( *( int * )a == *( int * )b ) {
    return 0;
  }
  return 1;
}


int main() {
  int n,k,i,j,a;
  scanf("%d %d",&n,&k);
  int h[n];
  for(i = 0;i<n;i++){
    scanf("%d",&h[i]);
  }
  
 /* for(i = 0;i<n-1;i++){
    for(j = n-1;j > i;j--){
      if(h[j-1] > h[j]){
        a = h[j-1];
        h[j-1] = h[j];
        h[j] = a;
      }
    }
  }*/
 


  /* ソート処理 */
  qsort(( void * )h , n , sizeof( h[0] ) , int_sort );
  
  
  for(i = 0;i < n-k+1;i++){
    if(i == 0){
      a = h[i+k-1] -h[i];
    }else if(a > h[i+k-1]-h[i]){
      a = h[i+k -1] - h[i];
    }
  }
  
  printf("%d",a);
  
}


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

int main() {
	int h, w;
	for (;;) {
		cin >> h >> w;
		if (h == 0 && w == 0) break;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (i%2==0&&j%2==0||i%2==1&&j%2==1) cout << "#";
				else cout << ".";
			}
			cout << endl;
		}
		cout << endl;
	}
}


Measured memory_bytes: 3084
#include <iostream>
#include <math.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <stdlib.h>
#include <deque>  
#include <iomanip>

using namespace std;

#define ll long long
#define INF 1e9
#define MOD 1e9 + 7
#define rep(i, n) for(int i = 0; i < n; i++)
#define loop(i, a, n) for(int i = a; i < n; i++)
#define all(in) in.begin(), in.end()


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

Measured memory_bytes: 256