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

const int MAX_N = 10010;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> Array;
typedef vector<Array> Graph;
typedef pair<double, double> pdd;
const ull mod = 1000000000 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

int main(){
    int N, M;
    cin >> N >> M;
    vector<int> count(N, 0);
    REP(i, M){
        int a, b;
        cin >> a >> b;
        count[a-1] += 1;
        count[b-1] += 1;
    }
    REP(i, N) cout << count[i] << endl;
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-


def main():
    from collections import deque

    n, q = map(int, input().split())
    graph = [[] for _ in range(n)]

    # KeyInsight
    # 直線のグラフとみなす
    # 累積和の考え方を応用

    # 隣接リストを作成
    for i in range(n - 1):
        ai, bi = map(int, input().split())
        graph[ai - 1].append(bi - 1)
        graph[bi - 1].append(ai - 1)

    values = [0 for _ in range(n)]

    for j in range(q):
        pi, xi = map(int, input().split())
        values[pi - 1] += xi

    # 木の持ち方
    d = deque()
    d.append(0)
    visited = [False for _ in range(n)]
    visited[0] = True

    # bfs
    while d:
        di = d.popleft()

        for g in graph[di]:
            if not visited[g]:
                visited[g] = True
                values[g] += values[di]
                d.append(g)

    print(' '.join(map(str, values)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 137464
use std::io::*;
use std::str::FromStr;

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


fn main() {
    let N: u32 = read();
    let A: u32 = read();
    let B: u32 = read();

    let mut total = 0;
    
    for n in 1..(N+1) {
        let mut sum = 0;
        let mut tmp = n;
        while tmp > 0 {
            sum += (tmp % 10);
            tmp /= 10;
        }

        if A <= sum && sum <= B {
            total += n;
        }
    }

    println!("{}", total);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> v(N);
  for (int i = 0; i < N; i++){
    cin >> v[i];
  }
  map<int, int> O;
  for (int i = 0; i < N; i += 2){
    O[v[i]]++;
  }
  vector<pair<int, int>> O2;
  for (auto P : O){
    O2.push_back(make_pair(P.second, P.first));
  }
  sort(O2.begin(), O2.end());
  reverse(O2.begin(), O2.end());
  O2.push_back(make_pair(0, -1));
  map<int, int> E;
  for (int i = 1; i < N; i += 2){
    E[v[i]]++;
  }
  vector<pair<int, int>> E2;
  for (auto P : E){
    E2.push_back(make_pair(P.second, P.first));
  }
  sort(E2.begin(), E2.end());
  reverse(E2.begin(), E2.end());
  E2.push_back(make_pair(0, -1));
  if (O2[0].second != E2[0].second){
    cout << N - O2[0].first - E2[0].first << endl;
  } else {
    cout << N - max(O2[0].first + E2[1].first, O2[1].first + E2[0].first) << endl;
  }
}

Measured memory_bytes: 6520
#import array
#import random
#import sys

#N, M = 200000, 200000
N, M = list(map(int, input().split()))
R = [[] for _ in range(N+1)]
G = [0] * (N+1)
Z = [0] * (N+1)

def grp(R, grpid, i, G, Z):
    stack = [i]
    while len(stack) > 0:
        k = stack.pop()
        if G[k] > 0: continue
        G[k] = grpid
        Z[grpid] += 1
        for l in range(len(R[k])):
            stack.append(R[k][l])
        
for i in range(M):
    a, b = list(map(int, input().split()))
#    a, b = random.choice(range(N)), random.choice(range(N))
    R[a].append(b)
    R[b].append(a)

grpid = 0
for i in range(1, N+1):
    if G[i] > 0: continue
    grpid += 1
    grp(R, grpid, i, G, Z)
    
Z.sort(reverse=True)
print(Z[0])


Measured memory_bytes: 46908
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int INT_INF = 2147483647;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef pair<string,int> P;

int main(){
  int n;
  cin >> n;
  vector<P> ans[10];
  ans[0].push_back(P("a",1));
  for(int i=1;i<n;i++){
    for(P p:ans[i-1]){
      for(int j=0;j<min(i+1,p.second+1);j++){
        ans[i].push_back(P(p.first+(char)('a'+j),max(p.second,j+1)));
      }
    }
  }
  for(P p:ans[n-1])cout << p.first << endl;
}


Measured memory_bytes: 10736
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) ll((a).size())
#define out(a) cout<<(a)<<endl;
const ll inf=1e9;
const int MAX = 510000;
const ll MOD = 998244353;
ll fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main(){
  ll n;cin>>n;
  vll a(n),b(n),big(0);
  ll suma=0,sumb=0;
  rep(i,0,n){
    cin>>a[i];
    suma+=a[i];
  }
  rep(i,0,n){
    cin>>b[i];
    sumb+=b[i];
  }
  if(suma<sumb){
    cout<<-1<<endl;return 0;
  }
  ll ans=0,cnt=0;
  rep(i,0,n){
      if(a[i]>b[i]){
        big.push_back(a[i]-b[i]);
        suma-=a[i];
        sumb-=b[i];
        ans++;
      }
    if(a[i]==b[i])cnt++;
  }
  ans=n-cnt-ans;
  sort(big.begin(),big.end());
  reverse(big.begin(),big.end());
  ll i=0;
  while(suma<sumb){
    suma+=big[i];
    i++;
  }
  cout<<ans+i<<endl;
}


Measured memory_bytes: 5488
import java.io.*;
import java.util.*;
import java.lang.*;

public class Main {
    public static MyScanner scan;
    public static PrintWriter out;
    public static void main(String[] args) {
        scan=new MyScanner();
        out=new PrintWriter(new BufferedOutputStream(System.out));

        int t=1;
//        int t=scan.nextInt();
        while(t-->0) {

            int a=scan.nextInt(),b=scan.nextInt(),opensockets=1,res=0;
            while(opensockets<b) {
                res++;
                opensockets+=a-1;
            } out.println(res);
        }
        out.close();
    }

    //scanner
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}

Measured memory_bytes: 25328
#include <iostream>
#include <vector>
#include <map>
#include <bitset>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <list>
#include <sstream>
#include <numeric>

#define ll long long
#define ld long double
#define ull unsigned long long
using namespace std;

const ll mod = 1000000007;
const ll inf = 8223372036854775803;
const int maxN = 300005;

int main() {
//    cout.precision(10);
//    cout << fixed;
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    ll n, k;
    cin >> n >> k;
    vector<int> A(n);

    for (int i = 0; i < n; i++) {
        cin >> A[i];
        A[i]--;
    }
    vector<int> ans;
    vector<bool> visited(n, false);
    int u = 0;
    int t = 0;
    while (!visited[u] && t < k) {
        visited[u] = true;
        ans.push_back(u);
        u = A[u];
        t++;
    }
    if (t == k) {
        cout << (u+1);
    } else {
        int i = 0;

        for (; ans[i] != u; i++) {}
        k -= i;
        vector<int> q;
        for (int j = i; j < ans.size(); j++) {
            q.push_back(ans[j]);
        }
        cout << q[k%q.size()] + 1;
    }
    return 0;
}



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

int main()
{
    int k;
    cin >> k;
    string s;
    cin >> s;
    int l = s.length();

    if (l <= k)
    {
        cout << s << endl;
    }
    else
    {
        for (int i = 0; i < k; i++)
        {
            cout << s[i];
        }
        cout << "..." << endl;
    }
    return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
template <typename T1, typename T2>
inline void chmin(T1 &a, T2 b) {
  if (a > b) a = b;
}
template <typename T1, typename T2>
inline void chmax(T1 &a, T2 b) {
  if (a < b) a = b;
}

int main() {
  string s;
  cin >> s;
  Int n = s.size();

  vector<Int> ls(n, -1);
  for (Int i = 0; i < n; i++) {
    if (s[i] == 'L') {
      if (s[i - 1] == 'R')
        ls[i] = 0;
      else
        ls[i] = ls[i - 1] + 1;
    }
  }

  vector<Int> rs(n, n);
  for (Int i = n - 1; i >= 0; i--) {
    if (s[i] == 'R') {
      if (s[i + 1] == 'L')
        rs[i] = 0;
      else
        rs[i] = rs[i + 1] + 1;
    }
  }

  vector<Int> ans(n, 0);
  for (Int i = 0; i < n; i++) {
    if (s[i] == 'L') {
      ans[i - ls[i] - (ls[i] & 1)]++;
    }
    if (s[i] == 'R') {
      ans[i + rs[i] + (rs[i] & 1)]++;
    }
  }

  for (Int i = 0; i < n; i++) {
    if (i) cout << " ";
    cout << ans[i];
  }
  cout << endl;
  return 0;
}


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

int main(){
  int N,M,X,A[100];
  cin>>N>>M>>X;
  int B[101]={0};
  for (int i(0);i<M;i++) {
    cin>>A[i];
    B[A[i]]++;
  }
  int mini(0);
  for (int i(X);i<=N;i++){
    if (B[i]==1) mini++;
  }
  int minn(0);
  for (int i(X);i>=0;i--){
    if (B[i]==1) minn++;
  }
  cout << min(mini,minn) << endl;
}



Measured memory_bytes: 256
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int n = sc.nextInt();
        long[] a = sc.nextLongArray(n);
        long prev = 0;
        long ans = 0;
        for(long b : a){
            if(prev > b){
                ans += prev-b;
            }else{
                prev = b;
            }
        }
        pw.println(ans);
        pw.flush();
    }

    static class GeekInteger {
        public static void save_sort(int[] array) {
            shuffle(array);
            Arrays.sort(array);
        }
 
        public static int[] shuffle(int[] array) {
            int n = array.length;
            Random random = new Random();
            for (int i = 0, j; i < n; i++) {
                j = i + random.nextInt(n - i);
                int randomElement = array[j];
                array[j] = array[i];
                array[i] = randomElement;
            }
            return array;
        }
 
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
    }
    
    public String[] nextArray(int n) {
        String[] a = new String[n];
        for (int i = 0; i < n; i++)
            a[i] = next();
        return a;
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}


Measured memory_bytes: 56096
class Arrow
  attr_reader :source, :sink, :label

  def initialize(source, sink, label)
    @source = source
    @sink = sink
    @label = label
  end
end

def push(queue, label)
  size = queue.size
  index = queue.index{|entry| entry[0] >= label} || size
  return queue[index][1] if index < size && queue[index][0] == label

  return nil if index > 0 && !label.start_with?(queue[index - 1][0])
  queue.slice!(index..-1) if index < size && !queue[index][0].start_with?(label)

  nodes = {}
  queue.insert(index, [label.dup, nodes])
  nodes
end

def calc(n, arrows, start, goal)
  ins = Array.new(n){[]}
  arrows.each do |arrow|
    ins[arrow.sink] << arrow.source
  end

  reachable_from = {}
  stack = [goal]
  until stack.empty?
    node = stack.pop
    reachable_from[node] = true
    ins[node].each do |source|
      stack << source unless reachable_from[source]
    end
  end

  return nil unless reachable_from[start]
  arrows.select!{|arrow| reachable_from[arrow.sink]}

  outs = Array.new(n){[]}
  arrows.each do |arrow|
    outs[arrow.source] << arrow
  end

  limit = n * arrows.map{|arrow| arrow.label.size}.max

  result = ''
  queue = [['', {start => true}]]
  until queue.empty?
    label, nodes = queue.shift
    result << label
    return result if nodes[goal]
    return nil if result.size > limit

    size = label.size
    queue.each do |next_label, _|
      next_label.slice!(0...size)
    end

    nodes.each do |node, _|
      outs[node].each do |arrow|
        new_nodes = push(queue, arrow.label)
        new_nodes[arrow.sink] = true if new_nodes
      end
    end
  end
  nil
end

loop do
  n, a, s, g = gets.split.map(&:to_i)
  break if n == 0

  arrows = a.times.map{
    x, y, lab = gets.split
    Arrow.new(x.to_i, y.to_i, lab)
  }

  puts calc(n, arrows, s, g) || 'NO'
end

Measured memory_bytes: 9524
import std.stdio, std.conv, std.string, std.array, std.math, std.regex, std.range, std.ascii, std.numeric, std.random;
import std.typecons, std.functional, std.traits,std.concurrency;
import std.algorithm, std.container;
import core.bitop, core.time, core.memory;
import std.bitmanip;
import std.regex;

enum INF = long.max/3;
enum MOD = 10L^^9+7;

//辞書順順列はiota(1,N),nextPermituionを使う


void end(T)(T v)
if(isIntegral!T||isSomeString!T||isSomeChar!T)
{
    import core.stdc.stdlib;
    writeln(v);
    exit(0);
}

T[] scanArray(T = long)()
{
    static char[] scanBuf;
    readln(scanBuf);
    return scanBuf.split.to!(T[]);
}

dchar scanChar()
{
    int c = ' ';
    while (isWhite(c) && c != -1)
    {
        c = getchar;
    }
    return cast(dchar)c;
}

T scanElem(T = long)()
{
    import core.stdc.stdlib;
    static auto scanBuf = appender!(char[])([]);

    scanBuf.clear;

    int c = ' ';
    while (isWhite(c) && c != -1)
    {
        c = getchar;
    }
    while (!isWhite(c) && c != -1)
    {
        scanBuf ~= cast(char) c;
        c = getchar;
    }
    return scanBuf.data.to!T;
}

dchar[] scanString(){
    return scanElem!(dchar[]);
}


void main()
{
  writeln("ABC"~scanString);
}


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

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define st first
#define nd second
#define endl '\n'
#define what_is(x) cerr << #x << " is " << x << endl;
#define what_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << e << ' '; cerr << '\n'; //vector, set
#define what_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << x[i] << ' '; cerr <<  '\n'; //n first element of array
#define cerr_pair(x) '{' << x.st << ", " << x.nd << '}'
#define pwhat_is(x) cerr << #x << " is " << cerr_pair(x) << endl;
#define pwhat_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << cerr_pair(e) << ' '; cerr << '\n'; //vector, set
#define pwhat_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << cerr_pair(x[i]) << ' '; cerr <<  '\n'; //n first element of array
// #define int long long
// #define pow mypow

typedef pair<int,int> pii;
const int N = 1e5+5;
const int INF = 1e9+5;
const int MOD = 1e9+7;

int n;
map<string, int> cnt;
int32_t main()
{
	IOS
	// freopen("input.txt", "r", stdin);
	cin >> n;
	while(n--) {
		string verdict; cin >> verdict;
		cnt[verdict]++;
	}
	for(string s:{"AC", "WA", "TLE", "RE"}) {
		cout << s << " x " << cnt[s] << endl;
	}
	
	return 0;
}


Measured memory_bytes: 3560
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
const int MAX=1e5;

int main(){
	int N;
	cin>>N;
	int a[MAX];
	int c1=0,c2=0,c4=0;
	rep(i,N){
		cin>>a[i];
		if(a[i]%4==0)c4++;
		else if(a[i]%2==1)c1++;
	}
  	if(N%2==1&&c4==N/2&&c1==N/2+1) cout<<"Yes";
	else if(c4>=c1) cout<<"Yes";
	else cout<<"No";
}

Measured memory_bytes: 640
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
	"unsafe"
)

func main() {
	L := sc.nextFloat()
	elem := L / float64(3)
	fmt.Printf("%.6f\n", elem*elem*elem)
}

var (
	sc scanner
)

func init() {
	sc = scanner{
		buf: make([]string, 0, 0),
		cur: 0,
		r:   bufio.NewReader(os.Stdin),
	}
}

type scanner struct {
	buf []string
	cur int
	r   *bufio.Reader
}

func (s *scanner) readln() {
	rbuf := make([]byte, 0, 0)
	for {
		line, prefix, err := s.r.ReadLine()
		if err != nil {
			panic(err)
		}
		rbuf = append(rbuf, line...)
		if prefix == false {
			break
		}
	}
	s.cur = 0
	s.buf = strings.Split(*(*string)(unsafe.Pointer(&rbuf)), " ")
}
func (s *scanner) isFull() bool {
	if s.cur == len(s.buf) {
		return true
	}
	return false
}
func (s *scanner) resetCur() {
	s.cur = 0
}
func (s *scanner) next() string {
	if s.cur == 0 {
		s.readln()
	}
	res := s.buf[s.cur]
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}
func (s *scanner) nexts() []string {
	s.readln()
	s.resetCur()
	return s.buf
}
func (s *scanner) nextInt() int {
	if s.cur == 0 {
		s.readln()
	}
	res, _ := strconv.Atoi(s.buf[s.cur])
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}
func (s *scanner) nextInts() []int {
	s.readln()
	res := make([]int, len(s.buf))
	for i := range s.buf {
		res[i], _ = strconv.Atoi(s.buf[i])
	}
	s.resetCur()
	return res
}
func (s *scanner) nextFloat() float64 {
	if s.cur == 0 {
		s.readln()
	}
	res, _ := strconv.ParseFloat(s.buf[s.cur],
		64)
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}
func (s *scanner) nextFloats() []float64 {
	s.readln()
	res := make([]float64, len(s.buf))
	for i := range s.buf {
		res[i], _ = strconv.ParseFloat(s.buf[i],
			64)
	}
	s.resetCur()
	return res
}
func digits(x int) int {
	return len(strconv.Itoa(x))
}
func powInt(x, p int) (result int) {
	result = 1
	for i := 0; i < p; i++ {
		result *= x
	}
	return
}
func max(x, y int) int {
	return int(math.Max(float64(x), float64(y)))
}
func min(x, y int) int {
	return int(math.Min(float64(x), float64(y)))
}
func abs(x int) int {
	return int(math.Abs(float64(x)))
}
func varDump(value ...interface{}) {
	for _, v := range value {
		fmt.Fprintf(os.Stderr, "%#v\n", v)
	}
}
func yes() {
	fmt.Println("Yes")
}
func no() {
	fmt.Println("No")
}

// Pair a
type Pair struct {
	first  int
	second int
}

// Queue a
type Queue struct {
	v []Pair
}

// Push for queue
func (q *Queue) Push(v Pair) {
	q.v = append(q.v, v)
}

// Pop for queue
func (q *Queue) Pop() Pair {
	r := q.v[0]
	q.v = q.v[1:]
	return r
}

// Front for queue
func (q Queue) Front() Pair {
	return q.v[0]
}

// Empty return true if empty
func (q Queue) Empty() bool {
	return len(q.v) == 0
}


Measured memory_bytes: 640
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

int main() {
    ll N;
    cin >> N;

    ll ans = 0;
    for (ll i = 1; i <= N; i += 2) {
        ll num = 0;
        for (ll j = 1; j <= i; j++) {
            if (i % j == 0) {
                num++;
            }
        }
        if (num == 8) {
            ans++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int K = Integer.parseInt(sc.next());
        int[] x = new int[N];
        for (int i = 0; i < N; i++) {
            x[i] = Integer.parseInt(sc.next());
        }

        int res = Integer.MAX_VALUE;

        for (int l = 0; l <= N - K; l++) {
            int r = l + K - 1;
            // left -> right
            int xl = Math.abs(x[l]) + Math.abs(x[r] - x[l]);
            res = Math.min(res, xl);

            // right -> left
            int xr = Math.abs(x[r]) + Math.abs(x[l] - x[r]);
            res = Math.min(res, xr);

        }

        System.out.println(res);
    }
}


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

int main()
{
    int n, n2, f{};
    scanf("%d", &n);
    n2 = n;
    while (n2)
    {
        f += n2 % 10;
        n2 /= 10;
    }
    printf(n % f?"No\n":"Yes\n");

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<int>>;
using dou =long double;
string yes="yes";
string Yes="Yes";
string YES="YES";
string no="no";
string No="No";
string NO="NO";

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout << "Case #" <<qqq+1<<": "
#define res resize
#define as assign
#define ffor for(;;)
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout << a<<" "<<b <<" "<< c<<std::endl
#define aall(x,n) (x).begin(),(x).begin()+(n)
 
typedef long long ll;
typedef pair<int,int> P;
//typedef long long T;
const int INF = 2000000000;
const ll INF64 = 922337203685477580ll;
const ll MOD = 1000000007ll;
int t=0;
void dfs(int n,std::vector<int>& d,std::vector<int> &f,std::vector<int>& k,std::vector<int> &al,Graph g){
    if(al[n]==-1){
       // std::cout << n << std::endl;
       al[n]=0;
        ++t;
        d[n]=t;
        erep(i,g[n]){
            
            dfs(i,d,f,k,al,g);
        }
        t++;
        f[n]=t;
        
    }
}

int main(){
    int n;
    std::cin >> n;
    std::vector<std::vector<int>>  g(n);
    std::vector<int> d(n,-1),f(n,-1),k(n,-1),al(n,-1);
    rep(i,n){
        int dd;
        std::cin >> dd;
        dd--;
        std::cin >> k[dd];
        
        rep(j,k[dd]){
            int ddd;
            std::cin >> ddd;
            ddd--;
            g[dd].pb(ddd);
        }
    }
    rep(i,n){
        if(al[i]==-1)dfs(i,d,f,k,al,g);
    }
    //std::cout << n << std::endl;
    rep(i,n){
 //       std::cout << i+1 << std::endl;
        pppri(i+1,d[i],f[i]);
    }
}


Measured memory_bytes: 3572
import collections


def permutations_count(n, r):
    return n*(n-1)//2

  
N = int(input().strip())
A = [int(a) for a in input().strip().split()]

cnt = collections.Counter(A)
per_cnt = {k:permutations_count(v, 2) for k,v in cnt.items()}
pre_total = sum(per_cnt.values())

for a in A:
    print(pre_total-per_cnt[a]+permutations_count(cnt[a]-1, 2))

Measured memory_bytes: 32020
#include<stdio.h>
#include<string.h>
int main(){
	char a[21] = "0",b[21] = "0";
	int i,n;
	scanf("%s",a);
	n = strlen(a);
	for(i = 0;i < n;i++){
		b[i] = a[n-1-i];
	}
	printf("%s\n",b);
	return 0;
}

Measured memory_bytes: 524
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = println(solve(new Scanner(System.in)))

  def solve(in: String): String = solve(new Scanner(in))

  def solve(sc: Scanner): String = {
    val N = sc.nextInt
    val S = sc.next

    var n = 0
    val sL = 0 +: S.map {
      case 'W' => n += 1; n
      case 'E' => n
    }
    n = 0
    val sR = 0 +: S.reverse.map {
      case 'E' => n += 1; n
      case 'W' => n
    }
    val ss = for (i <- 0 until N)
      yield sL(i) + sR(N - i - 1)
    ss.min.toString
  }
}


Measured memory_bytes: 55940
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

void _main() {
  map<int, int> mp;
  rep(i, 0, 6) {
    int t;
    cin >> t;
    if (mp[t] == 2) {
      cout << "NO" << "\n";
      return;
    }
    mp[t]++;
  }
  cout << "YES" << "\n";
}

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

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORR(i, a, b) for(int i = (a); i > (b); --i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"

typedef long long ll;
typedef unsigned long long ul;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef priority_queue<int> PQ;
typedef priority_queue<int, V, greater<int>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

ll N;
VL A;

int main() {
    cin >> N;
    A.resize(N);
    VECCIN(A);
    ll odd = 0;
    REP(i, N) if(A[i] % 2) odd++;
    cout << (odd % 2 ? "NO" : "YES") << "\n";
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);++(i))
#define all(x) (x).begin(),(x).end()
#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define yes(n) cout << ((n) ? "yes" : "no") << endl

using namespace std;
using ll = long long;
using P = pair<int, int>;

const int INF = 1001001001;
const vector<int> di = {-1,  0, 1, 0};
const vector<int> dj = { 0, -1, 0, 1};

void chmin(int &a, int b) { if (a > b) a = b; }

ll GCD(ll a, ll b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
ll LCM(ll a, ll b) {
    ll g = GCD(a, b);
    return a / g * b;
}


int main() {
    int MIN = -1000000;
    int MAX =  1000000;
    int k, x; cin >> k >> x;

    if (x - k + 1 <= MIN) {
        int m = MIN;
        while (m < x + k) {
            cout << m << " ";
            m++;
        }
    } else if (x + k -1 >= MAX) {
        int m = x - (k - 1);
        while (m < MAX) {
            cout << m << " ";
            m++;
        }
    } else{
        for (int i=(x-(k-1));i<=(x+(k-1));++i) {
            cout << i << " ";
        }
    }   
    cout << endl;
}

Measured memory_bytes: 256
import scala.io.StdIn.{readInt, readLine}
object Main {
    def main(args: Array[String]): Unit = {
        val len = readInt
        val arr = readLine.split(" ").map(_.toInt)
        val pivot = partition(arr, len)
        val ret = arr.zipWithIndex.map{case (v, i) =>
            if (i == pivot) "[" + v.toString + "]" else v.toString
        }
        println(ret.mkString(" "))
    }
    def partition(arr: Array[Int], len: Int): Int = {
        val pivot = arr(len - 1)
        def go(sep: Int, seek: Int): Int = {
            if (seek == len - 1) {
                swap(arr, sep + 1, seek)
                sep + 1
            } else {
                if (arr(seek) > pivot) {
                    go(sep, seek + 1)
                } else {
                    swap(arr, sep + 1, seek)
                    go(sep + 1, seek + 1)
                }
            }
        }
        go(-1, 0)
    }
    def swap(arr: Array[Int], a: Int, b: Int): Unit = {
        val tmp = arr(a)
        arr(a) = arr(b)
        arr(b) = tmp
    }
}


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

using namespace std;

int main() {
  string s;
  cin>>s;
  int res = 0;
  for (int i = 0; i < s.size() / 2; i++)
    res += s[i] != s[s.size() - 1 - i];
  cout<<res;
}

Measured memory_bytes: 256
//nani?
//omo ta tori da
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
#define pi acos(-1);
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define f(i,a,b) for( int i = a; i < b ; i++ )
#define sor(a) sort( a.begin(), a.end() )
#define rsor(a) sort( a.rbegin(), a.rend() )
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
//#define inf 1LL<<62
typedef long long ll;
typedef double ld;
using namespace std;
using namespace __gnu_pbds;
const ll inf=1e10;
const ll MOD=1e9+7;
const ll mod=998244353;
const ll N = 1e7 + 5;
// ac cmtr;
const int MAX_N = 2e5+5;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
 
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cout << name << " : " << arg1 << endl;}
 
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1<<" | ";
  __f(comma+1, args...);}
#else
#define trace(...)
#endif
//---------------------------

ll a[MAX_N];
ll b[MAX_N];
ll c[MAX_N];

bool cmp(ll a,ll b){
    return a>b;
}
int main(){
    fastio;
    ll x,y,a1,b1,c1;
    cin>>x>>y>>a1>>b1>>c1;
    f(i,0,a1) cin>>a[i];
    f(i,0,b1) cin>>b[i];
    f(i,0,c1) cin>>c[i];
    sort(a,a+a1,cmp);
    sort(b,b+b1,cmp);
    sort(c,c+c1,cmp);
    ll sum  =  0;
    vector <ll> v;
    vector <ll> g;
    f(i,0,x) v.pb(a[i]);
    f(i,0,y) v.pb(b[i]);
    f(i,0,c1) v.pb(c[i]);
    rsor(v);
    f(i,0,x+y){
        sum += v[i];
    }
    cout<<sum<<endl;

 //ga  
}

Measured memory_bytes: 9840
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"

using namespace std;

const long long int MOD = 1000000007;
//const long long int MOD = 1000003;
//const int MOD = 998244353;
//const long long int MOD = 998244353;

//long long int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

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

	while (cin >> N >> M, N) {
		vector<vector<long long int>>Ldis(N, vector<long long int>(N, MOD));
		vector<vector<long long int>>Sdis(N, vector<long long int>(N, MOD));
		for (int i = 0; i < N; i++) {
			Ldis[i][i] = Sdis[i][i] = 0;
		}

		for (int i = 0; i < M; i++) {
			cin >> L >> R >> K;
			L--;
			R--;
			char c;
			cin >> c;
			if (c == 'L') {
				Ldis[L][R] = K;
				Ldis[R][L] = K;
			}
			else {
				Sdis[L][R] = K;
				Sdis[R][L] = K;
			}
		}
		for (int k = 0; k < N; k++) {
			for (int i = 0; i < N; i++) {
				for (int j = 0; j < N; j++) {
					Ldis[i][j] = min(Ldis[i][j], Ldis[i][k] + Ldis[k][j]);
					Sdis[i][j] = min(Sdis[i][j], Sdis[i][k] + Sdis[k][j]);
				}
			}
		}
		cin >> K;
		vector<int>v(K);
		for (auto &i : v) {
			cin >> i;
			i--;
		}
		vector<vector<long long int>>dis(K, vector<long long int>(N, MOD*MOD));
		dis[0][v[0]] = 0;
		for (int i = 1; i < K; i++) {
			for (int j = 0; j < N; j++) {
				for (int k = 0; k < N; k++) {
					dis[i][k] = min(dis[i][k], dis[i - 1][j] + Ldis[v[i - 1]][j] + Sdis[j][k] + Ldis[k][v[i]]);
				}
				dis[i][j] = min(dis[i][j], dis[i - 1][j] + Ldis[v[i - 1]][v[i]]);
			}
		}
		long long int ans = MOD * MOD;
		for (int i = 0; i < N; i++) {
			ans = min(ans, dis.back()[i]);
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 5220
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}

template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}

template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}

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

	int ans = INT_MAX;
	rep(i,n){
		int c, t;
		cin >> c >> t;
		if(t <= T) ans = min(ans, c);
	}
	if(ans == INT_MAX) cout << "TLE" << endl;
	else cout << ans << endl;
}


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

int main() {

	int ans = 0;
	int N; cin >> N;

	for(int i = 105; i <= N; i = i + 2){
		int count = 0;
		for (int div = 1; div <= i; div++) {
			if (i % div == 0) count++;
		}
		if (count == 8) ans++;
    }
	cout << ans << endl;
}

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

#define int long long
#define itn int
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y) \
    cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
constexpr int MOD = 1e9 + 7;

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = LLONG_MAX / 2;
using P = pair<int, int>;
using vec = vector<int>;
template <typename T>
using mat = vector<vector<T>>;

// clang-format off
template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) { return stream << p.first << "," << p.second; }
template <typename T>
void print(const vector<T> vec) { rep (i, vec.size() - 1) cout << vec[i] << ' '; cout << vec[vec.size() - 1] << '\n'; }
template <typename Arg>
void print(const Arg arg) { cout << arg << '\n'; }
template <typename Head, typename... Args>
void print(const Head head, const Args... args) { cout << head << " "; print(args...); }
template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) { rep (i, v.size()) cin >> v[i] >> w[i]; }
template <typename T>
void init(vector<T>& v) { rep (i, v.size()) cin >> v[i]; }
template <typename T>
T sum_(vector<T> vec, T init = 0) { return std::accumulate(all(vec), T(init)); }
template<typename T>
bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <typename T>
int index(const T& vec, const typename T::iterator it) { return distance(vec.begin(), it); }
template <typename T = int>
mat<T> mmat(int n, int m=0) { return mat<T>(n, vector<T>(m)); }
template <typename T = int>
vector<T> ivec(int n) { vector<T> v(n); init(v); return v; }
// clang-format on

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
// -------------------------------------------------------------------
// sort 1 2 3 4
// pqr 1 2 3 must impl >
int a, b;

int kosuu(int x) {
    int low = (a - 1) / x * x, high = b / x * x;
    return (high - low) / x;
}

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    int c, d;
    cin >> a >> b >> c >> d;
    print(b - a + 1 - (kosuu(c) + kosuu(d) - kosuu(c * d / gcd(c, d))));

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define ll long long
#define maxn 1000005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second
#define all(x) x.begin(), x.end()
const int mod = 998244353;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n, m;
    while (cin >> n >> m) {
        cout << min(n % m, m - n % m) << '\n';
    }
    
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
typedef long long ll;
using namespace std;
const ll mod = 1000000007;
void PostalCode() {
	int A, B;
	string s;
	cin >> A >> B;
	cin >> s;
	int hi = -1;
	for (size_t i = 0; i < s.size(); i++)
	{
		if (s[i] == '-') {
			if (hi < 0) hi = i;
			else {
				cout << "No" << endl;
				return;
			}
			continue;
		}
		if (hi < 0) {
			A--;
		}
		else B--;
	}
	if (A == 0 && B == 0) {
		cout << "Yes" << endl;
	}
	else cout << "No" << endl;
}
int main() {
	PostalCode();
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define rep2(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;
typedef vector<long long int> vll;

int main() {
	string s;
	cin >> s;
	int ans = 0;
	rep(i, 0, 4) {
		if (s[i] == '+') ans++;
		else ans--;
	}
	cout << ans << endl;
}

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

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

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

    int total = a + b;
    if(total >= 10){
        cout << "error" << endl;
    }else{
        cout << total << endl;
    }

    return 0;
}

Measured memory_bytes: 256
int main(void)
{
  char str[200000];
  char* p;
  int i,size,start=-1,end=-1;
  
  scanf("%s",str);
  
  size = strlen(str);
  
  for(i=0;i<size;i++)
  {
    if(str[i] == 'A')
    {
      start = i;
      //printf("start:%d\n",i);
      break;
    }
  }
  
    for(i=0;i<size;i++)
  {
    if(str[size-i-1] == 'Z')
    {
      end = size-i-1;
      //printf("end:%d\n",size-i-1);
      break;
    }
  }
  
  printf("%d",end - start + 1);
  return 0;
}



Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int descending_compare(const void *a, const void *b){
    if (*(int*)a > *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}

int ascending_compare(const void *a, const void *b){
    if (*(int*)a < *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}


int lower_bound(int *a, int n, int key){
    int left, mid, right;
    left = 0, right = n;
    mid = (left + right)/2;
    while ((left+1 != mid || mid+1 != right) && mid != left){
        if (key > a[mid]){
            left = mid;
        }else{
            right = mid+1;
        }
        mid = (left + right)/2;
    }
    if (a[left] >= key)return left;
    if (a[mid] >= key)return mid;
    if (a[right] >= key)return right;
    return n;
}

//greatest common divisor
unsigned long  gcd(unsigned long x, unsigned long y){
    if (y == 0){ 
        return x;
    }else if (x > y){
        return gcd(y, x % y);
    }else{
        return gcd(x, y % x);
    }
}



long long factorial(int x){
    long long rtn = 1;
    int i;
    for (i = x; i > 1; i--){
        rtn = (rtn*i);
    }
    return rtn;
}
long long a[100005] = {0};

int main(void){
   char o[55];
   char e[55];
   int flag = 0;
   int olen = strlen(o);
   int elen = strlen(e);
   int totalen = olen>elen?olen:elen;
   scanf("%s %s", o, e);
   for (int i = 0; i < 100000000; i++){
       if (o[i] != '\0'){
           printf("%c", o[i]);
       }else{
           if (flag == 1){
               printf("\n");
               break;
           }
           flag = 1;
       }
       if (e[i] != '\0'){
           printf("%c", e[i]);
       }else{
           if (flag == 1){
               printf("\n");
               break;
           }
           flag = 1;
       }
   }

}


Measured memory_bytes: 128
#include <iostream>
#include <string>

int main(){
	int n, k, r, s, p;
	std::string t;
	std::cin >> n >> k >> r >> s >> p >> t;
	int ans = 0;
	for(int i=0;i<n; i++){
		if(t[i]=='r') ans += p;
		else if(t[i]=='s') ans += r;
		else ans += s;
	}
	for(int j=0; j<k; j++){
		for(int i=k+j; i<n; i+=k){
			if(t[i-k]==t[i]){
				if(t[i]=='r') ans -= p;
				else if(t[i]=='s') ans -= r;
				else ans -= s;
				t[i] = 'a';
			}
		}
	}
	std::cout << ans << std::endl;
	return 0;
}


Measured memory_bytes: 512
#include <cstdio>
#include <set>
using namespace std;

int main(){
  int N;
  scanf("%d",&N);
  int A;
  int i;
  set<int> s;
  for(i=0;i<N;i++){
    scanf("%d",&A);
    if(s.erase(A)==0) s.insert(A);
  }
  printf("%d",s.size());
  return 0;
  }


Measured memory_bytes: 4864
S = input()
N = len(S)

alp = 'BDEFHIJKLMNOPQRSUVWXYZ'

cnt = []

for i in range(0, N):
    for j in range(i, N+1):
        tmp = S[i:j]
        flg = 1
        for a in alp:
            if a in tmp:
                flg = 0
        if flg:
            cnt.append(len(tmp))

print(max(cnt))

Measured memory_bytes: 3060
### SNIPPET
  # n = gets.split.map(&:to_i)
  # array = n.times.map { gets.split.map(&:to_i) }
  # [].all?(&:even?)
  # a = [*1..m].repeated_combination(n).to_a
  # [1,2,3,4,5].select { |num| num.even? }  # => [2, 4]
  # ["a","a","b"].group_by(&:itself).map{|k,v| [k, v.count]}.to_h #=> {"a"=>2, "b"=>1}
  # 切り捨て: .floor(2).to_f ,切り上げ： .ceil(2).to_f,四捨五入: round(2)
  # 3.upto(6) do |i|, 6.downto(3) do |i|
  # 公約数125.gcd(100)、公倍数125.lcm(100)
  # PI = Math::PI
  # 高さ = a * Math.sin(w / 180.0 * Math::PI), 底辺 = a * Math.cos(w / 180.0 * Math::PI)
  # def chmax(a, b) a > b ? a : b end
  # INF = Float::INFINITY
  # def chmin(a, b) a < b ? a : b end

n,k = gets.split.map(&:to_i)
h = gets.split.map(&:to_i)

h.sort!.reverse!.slice!(0,k)

res = h.inject(:+) || 0
puts res

 



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

if N == 1:
    num_list = [0]
    done_list = [False]
else:
    num_list = [1] + [0] * (N-1)
    done_list = [False] * (N)

result = 0
for i in range(M):
    s, c = map(int, input().split())
    if not done_list[s-1]:
        num_list[s-1] = c
        done_list[s-1] = True
    elif num_list[s-1] == c:
        pass
    else:
        result = -1
        break
    if N > 1 and s == 1 and c == 0:
        result = -1
        break

if result == 0:
    result = "".join(map(str, num_list))
print(result)


Measured memory_bytes: 38384
def factrize(x):
    f = {}
    if x == 1:
        return f
    tmp = x
    i = 2
    while i**2 <= tmp:
        cnt = 0
        while tmp % i == 0:
            cnt += 1
            tmp = tmp//i
        if cnt > 0:
            f[i] = cnt
        i += 1
    if tmp != 1 or f == {}:
        f[tmp] = 1
    return f


def comb(n, r, p):
    x = 1
    for i in range(1, r + 1):
        x *= (n - i + 1) * pow(i, p - 2, p) % p
    return x % p


p = 10**9+7
n, m = map(int, input().split())
A = list(factrize(m).values())
ans = 1
for a in A:
    ans = (ans*comb(a+n-1, a, p)) % p
print(ans)


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

typedef pair<int, int> P;

int main() {
    ll n;
    cin >> n;
    string s[n];
    map<string,ll> mp;
    rep(i,n){
        cin >> s[i];
        sort(s[i].begin(),s[i].end());
        mp[s[i]]++;
    }

    auto begin = mp.begin(), end = mp.end();
    ll ans = 0;
    for(auto itr = begin; itr!=end; itr++){
        ans += (itr->second)*(itr->second-1)/2;
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 18176
import java.util.*;
public class Main {
  	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] array = new int[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
		}
		int ret = test(n, array);
		System.out.println(ret);
		sc.close();
	}
	static int test(int n, int[] array) {
		int count = 0;
		for (int i = 0; i < n - 2; i++) {
			int p1 = array[i];
			int p2 = array[i + 1];
			int p3 = array[i + 2];
			if ((p1 >= p2 && p2 > p3) || (p3 >= p2 && p2 > p1)) {
				count++;
			}
		}
		return count;
	}
}

Measured memory_bytes: 21972