akhauriyash/Code-Regression huggingface dataset:
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
      let mut iter = $s.split_whitespace();
      let mut next = || { iter.next().unwrap() };
      input_inner!{next, $($r)*}
  };
  ($($r:tt)*) => {
      let stdin = std::io::stdin();
      let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
      let mut next = move || -> String{
          bytes
              .by_ref()
              .map(|r|r.unwrap() as char)
              .skip_while(|c|c.is_whitespace())
              .take_while(|c|!c.is_whitespace())
              .collect()
      };
      input_inner!{next, $($r)*}
  };
}

macro_rules! input_inner {
  ($next:expr) => {};
  ($next:expr, ) => {};

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

macro_rules! read_value {
  ($next:expr, ( $($t:tt),* )) => {
      ( $(read_value!($next, $t)),* )
  };

  ($next:expr, [ $t:tt ; $len:expr ]) => {
      (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
  };

  ($next:expr, chars) => {
      read_value!($next, String).chars().collect::<Vec<char>>()
  };

  ($next:expr, usize1) => {
      read_value!($next, usize) - 1
  };

  // 3
  // 1 2
  // 1 3
  // 1 4
  // のようなタイプ
  ($next:expr, [ $t:tt ]) => {{
      let len = read_value!($next, usize);
      (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
  }};

  ($next:expr, $t:ty) => {
      $next().parse::<$t>().expect("Parse error")
  };
}

fn main() {
  input! {
    n: usize,
    v: [u64;n]
  }

  let mut sum: u64 = 0;
  let trait_num = (10 as u64).pow(9) + 7;

  let mut bit_array = [0; 60];

  for i in 0..n {
    for d in 0..60 {
      bit_array[d] += (v[i] & (2 as u64).pow(d as u32)) >> d;
    }
  }

  for d in 0..60 {
    sum += (bit_array[d] * (n as u64 - bit_array[d]) % trait_num) * ((1 << d) % trait_num);
  }

  println!("{}", sum % trait_num);
}


Measured memory_bytes: 8444
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <utility>

using namespace std;

typedef long double ld;

class Point {
public:
	ld x, y;
	Point(ld x, ld y) :
			x(x), y(y) {
	}
	Point operator +(Point p) {
		return Point(x + p.x, y + p.y);
	}
	Point operator -(Point p) {
		return Point(x - p.x, y - p.y);
	}
};

class Circle {
public:
	Point c;
	ld r;
	Circle(Point c, ld r) :
			c(c), r(r) {
	}
};
ld norm(Point p) {
	return p.x * p.x + p.y * p.y;
}
ld abs(Point p) {
	return sqrt(norm(p));
}
ld arg(Point p) {
	return atan2(p.y, p.x);
}
Point polar(ld a, ld r) {
	return Point(cos(r) * a, sin(r) * a);
}
pair<Point, Point> getCrossPoints(Circle c1, Circle c2) {
	ld d = abs(c1.c - c2.c);
	ld a = acos((c1.r * c1.r + d * d - c2.r * c2.r) / (2 * c1.r * d));
	ld t = arg(c2.c - c1.c);
	return make_pair(c1.c + polar(c1.r, t + a), c1.c + polar(c1.r, t - a));
}
int main() {

	int c1x, c1y, r1;
	scanf("%d %d %d", &c1x, &c1y, &r1);
	Point p1(c1x, c1y);
	Circle c1(p1, r1);

	int c2x, c2y, r2;
	scanf("%d %d %d", &c2x, &c2y, &r2);
	Point p2(c2x, c2y);
	Circle c2(p2, r2);

	pair<Point, Point> ans = getCrossPoints(c1, c2);
	bool firstFirst = true;
	if (ans.first.x > ans.second.x) {
		firstFirst = false;
	} else {
		if (ans.first.x == ans.second.x && ans.first.y > ans.second.y) {
			firstFirst = false;
		}
	}

	if (firstFirst) {
		cout << fixed << setprecision(8) << ans.first.x << " " << ans.first.y << " " << ans.second.x << " " << ans.second.y << endl;
	} else {
		cout << fixed << setprecision(8) << ans.second.x << " " << ans.second.y << " " << ans.first.x << " " << ans.first.y << endl;
	}

	return 0;
}

Measured memory_bytes: 3644
#include <stdio.h>
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <ctime>
#include <string.h>
#include <assert.h>
#include <complex>
#include <random>

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define pb push_back

using namespace std;

typedef long long ll;
mt19937 rr(random_device{}());

const int MAXN = 2e5;
const int P = 1e9 + 7;
ll dp[MAXN][2];

int main() {
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int n;
    ll x, y;
    cin >> n >> x >> y;
    vector<ll> a(n);
    set<ll> s;
    map<ll, int> mp;

    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        s.insert(a[i]);
        mp[a[i]] = i;
    }

    set<int> forbid[2];
    for (int i = 0; i < n - 1; ++i) {
        if (a[i + 1] - a[i] < x)
            forbid[0].insert(i);
        if (a[i + 1] - a[i] < y)
            forbid[1].insert(i);
    }
    forbid[0].insert(n);
    forbid[1].insert(n);

    dp[0][1] = 1;
    dp[0][0] = 1;

    for (int i = 1; i < n; ++i) {
        int k;

        k = mp[*s.lower_bound(a[i] - x + 1)];
        if (k == i) {
            dp[i][0] = (dp[i - 1][0] + dp[i - 1][1]) % P;
        } else {
            int u = *forbid[1].lower_bound(k);
            if (u >= i - 1) {
                dp[i][0] = dp[k][1];
            }
        }
        
        k = mp[*s.lower_bound(a[i] - y + 1)];
        if (k == i) {
            dp[i][1] = (dp[i - 1][0] + dp[i - 1][1]) % P;
        } else {
            int u = *forbid[0].lower_bound(k);
            if (u >= i - 1) {
                dp[i][1] = dp[k][0];
            }
        }
    }
    // for (int i = 0; i < n; ++i)
    //     cout << dp[i][0] << " " << dp[i][1] << endl;

    ll ans = (dp[n - 1][0] + dp[n - 1][1]) % P;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 23040
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<string>
#include<functional>
using namespace std;
typedef	long long int ll;

int main(){
    int n;
    cin >> n;
    int a[n];
    ll sum = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        if(a[0] != 0){
            cout << -1 << endl;
            return 0;
        }
        if(i != 0 && a[i]-a[i-1] >= 2){
            cout << -1 << endl;
            return 0;
        }
    }
    for(int i = 1; i < n; i++){
        if(a[i] <= a[i-1]) sum += a[i];
        else sum++;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 1024
use std::io::*;

fn main() {
    let stdin = stdin();
    let mut handle = stdin.lock();
    let mut input: String = read(&mut handle);

    let mut hitachi_iter = "hi".chars().cycle();

    for input_iter in input.chars() {
        if input_iter != hitachi_iter.next().unwrap() {
            println!("No");
            return;
        }
    }
    if input.pop().unwrap() != 'i' {
        println!("No");
    } else {
        println!("Yes");
    }
}

fn read(handle: &mut StdinLock) -> String {
    handle
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>()
}


Measured memory_bytes: 4352
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <cstring>
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <numeric>
#include <float.h>
#include <math.h>
#include <sstream>
#include <iterator>
using namespace std;
// repマクロの定義
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// allマクロの定義
#define all(v) v.begin(), v.end()
// 大きい順
#define rall(v) v.rbegin(), v.rend()
#define vi vector<int>
#define vl vector<ll>
const  long long INF = 1LL << 60;
typedef  long long ll;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}



int ctoi(char c) {
 	switch (c) {
		case '0': return 0;
		case '1': return 1;
		case '2': return 2;
		case '3': return 3;
		case '4': return 4;
		case '5': return 5;
		case '6': return 6;
		case '7': return 7;
		case '8': return 8;
		case '9': return 9;
		default: return 0;
	}
}

bool is_prime(const unsigned n){
    switch(n){
        case 0: // fall-through
        case 1: return false;
        case 2: // fall-through
        case 3: return true;
    } // n > 3 が保証された

    if(n % 2 == 0 || n % 3 == 0) return false;
    // n は 2 と 3 のいずれの倍数でもないことが保証された
    // これより n は (6の倍数)-1 か (6の倍数)+1 である

    // 6の倍数前後の数を使って試し割りをする
    for(unsigned i = 5; i * i <= n; i += 6) {
        if(n % i     == 0) return false; // (6の倍数)-1
        if(n % (i+2) == 0) return false; // (6の倍数)+1
    }

    return true;
}

map<ll,ll> mp;

auto findFactors(ll num){
	
    ll i;
    while (num % 2 == 0){ // 偶数の素数は2のみ
        if(mp.count(2)){
			mp[2] = mp[2] + 1;
		}
		else{
			mp[2] = 1;
		}
        num /= 2;
    }
    for (i = 3; i <= num; i++){ // 他の素数で割っていく
        while (num % i == 0){
			if(mp.count(i)){
			mp[i] = mp[i] + 1;
		}
		else{
			mp[i] = 1;
		}
            num /= i;
        }
    }
    return 0;
}
ll kaizyou(ll n){
    if(n == 1){
        return 1;
    }
    else{
        return (n * kaizyou(n-1)) % 1000000007;
    }
}



int main(){
int N;cin >> N;
vector<ll> a(N);
vector<ll> x(N);
ll sum = 0;
rep(i,N) {
    cin >> a[i];
    sum += a[i];
    x[i] = sum;
    
}
ll ans = INF;
ll cnt;
for(int i = 0; i < N-1;i++){
    cnt = llabs(sum - 2 * x[i]);
    chmin(ans,cnt);
}
cout << ans << endl;
}

Measured memory_bytes: 3328
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	static int[][] a;
	static ArrayList<String> ans = new ArrayList<>();
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		final int h = scanner.nextInt();
		final int w = scanner.nextInt();
		a = new int[h][w];
		for (int r=0; r<h; r++){
			for (int c=0; c<w; c++){
				a[r][c] = scanner.nextInt();
			}
		}
		for(int r=0; r<h; r++){
			for (int c=0; c<w; c++){
				int now = a[r][c];
				if(now%2==1){
					int right = -1;
					int down = -1;
					boolean rightEven = true;
					boolean downEven = true;
					if (c!=w-1) {
						right=a[r][c+1];
						rightEven = right%2==0;
					}
					if (r!=h-1) {
						down=a[r+1][c];
						downEven = down%2==0;
					}
					if(rightEven && downEven) {
						if(c!=w-1 && r!=h-1) {
							if (right<=down) move(r,c,r,c+1);	//toRight
							else move(r,c,r+1,c);	//toDown
						}else if (c!=w-1) move(r,c,r,c+1);	//toRight
						else if (r!=h-1) move(r,c,r+1,c);	//toDown
					}else if (rightEven) move(r,c,r+1,c);	//toDown
					else if (downEven) move(r,c,r,c+1);	//toRight
					else {
						if (right<=down) move(r,c,r,c+1);	//toRight
						else move(r,c,r+1,c);	//toDown
					}
				}
			}
		}
		System.out.println(ans.size());
		ans.forEach(System.out::println);
	}

	static void move(int y, int x, int y_, int x_){
		ans.add((y+1)+" "+(x+1)+" "+(y_+1)+" "+(x_+1));
		a[y][x]--;
		a[y_][x_]++;
	}
}

Measured memory_bytes: 99212
//Use valgrind once if the submission doesn't go through. It can detect uninitialized variables and see where they could be an issue.
#include <bits/stdc++.h>
using namespace std;

int main(){

	ios_base::sync_with_stdio(false);
    	cin.tie(NULL);

	vector<long long> a,b,c,count(100000,0);
	long long sum=0;
	int n,q;
	cin>>n;
	a.resize(n);
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		sum+=a[i];
	}
	cin>>q;
	b.resize(q);
	c.resize(q);
	for(int i=0;i<n;i++)
	{
		count[a[i]-1]++;
	}
	for(int i=0;i<q;i++)
	{
		cin>>b[i]>>c[i];
		sum+=(c[i]-b[i])*count[b[i]-1];
		count[c[i]-1]+=count[b[i]-1];
		count[b[i]-1]=0;
		cout<<sum<<'\n';
	}
}


Measured memory_bytes: 6368
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define rep(i,n) for(int i=0; i<(int)(n);i++)

int main(){
  int n,q;
  cin >> n >> q;
  vi a(n-1),b(n-1),p(q),x(q);
  int ta,tb,tp;
  rep(i,n-1){
    cin >> ta >> tb;
    a.at(i) = ta-1;
    b.at(i) = tb-1;
  }
  rep(i,q){
    cin >> tp >> x.at(i);
    p.at(i) = tp-1;
  }
  vi par(n,-1);
  par.at(0) = 0;
  rep(i,n-1){
    par.at(b.at(i)) = a.at(i);
  }
  vector<long> c(n,0);
  rep(i,q){
    c.at(p.at(i)) += x.at(i);
  }
  //rep(i,n) cout << c.at(i) << endl;
  
  rep(i,n){
    if(i==0){
      cout << c.at(0) << " ";
    }else{
      c.at(i) += c.at(par.at(i));
      cout << c.at(i) << " ";
    }
  }
  
}


Measured memory_bytes: 7936
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"sort"
	"strconv"
	"strings"
)

func main() {
	io := NewIo(os.Stdin, os.Stdout)
	defer io.Flush()
	n := io.NextInt()
	a := io.NextInts(n)
	graph := make([][]int, n)
	for i := 0; i < n-1; i++ {
		ui, vi := io.NextInt(), io.NextInt()
		graph[ui-1] = append(graph[ui-1], vi-1)
		graph[vi-1] = append(graph[vi-1], ui-1)
	}
	ans := solve(n, a, graph)
	for i := range ans {
		io.Println(ans[i])
	}
}

func solve(n int, a []int, graph [][]int) []int {
	stk := newStack()
	dp := make([]int, n)
	for i := 0; i < n; i++ {
		dp[i] = inf
	}
	lis := make([]int, n)
	stk.push(pair{0, inf})
	dfs(0, stk, dp, lis, graph, a)
	return lis
}

func dfs(from int, stk *stack, dp []int, lis []int, graph [][]int, a []int) {
	if lis[from] != 0 {
		return
	}
	i := sort.Search(len(dp), func(i int) bool { return dp[i] >= a[from] })
	stk.push(pair{i, dp[i]})
	dp[i] = a[from]
	j := sort.Search(len(dp), func(j int) bool { return dp[j] >= inf })
	lis[from] = j
	for _, to := range graph[from] {
		dfs(to, stk, dp, lis, graph, a)
	}
	top := stk.pop()
	dp[top.key] = top.value
}

const inf = math.MaxInt64

type pair struct{ key, value int }

type stack []pair

func newStack() *stack {
	return &stack{}
}

func (s *stack) push(x pair) {
	*s = append(*s, x)
}

func (s *stack) pop() pair {
	x := (*s)[len(*s)-1]
	*s = (*s)[:len(*s)-1]
	return x
}

// Io is I/O object
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

// NewIo returns a new Io instance
func NewIo(r io.Reader, w io.Writer) *Io {
	return &Io{
		reader: bufio.NewReader(r),
		writer: bufio.NewWriter(w),
	}
}

// Flush flushes writer
func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

// NextLine scans a line from stdin
func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

// Next return a word from stdin
func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

// NextInt returns an integer from stdin
func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

// NextInts returns n integers from stdin
func (io *Io) NextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = io.NextInt()
	}
	return ret
}

// Println is a wrapper of fmt.Fprintln
func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}


Measured memory_bytes: 138368
import java.util.Map.Entry;
import java.io.*;
import java.util.*;

public class Main {
	
	public static void main(String[] args) throws IOException {
		FastScanner sc = new FastScanner(System.in);
		
		long N = sc.nextLong();
		long P = sc.nextLong();
		long ans = 1;
		
		if(N == 1){
			System.out.println(P);
			return;
		}
		
		for(int i = 2 ;; i++){
			long p = pow(i, N);
			if(p > P) break;
			if(p == 0) break;
			if(P % p == 0) ans = i;
		}
		
		
		System.out.println(ans);
	}
	
	public static long pow(long a, long n){
		if(n == 0) return 1;
		else if(n % 2 == 0){
			return pow(a * a, n / 2);
		}else{
			return a * pow(a * a, (n - 1) / 2);
		}
	}
}

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


Measured memory_bytes: 22996
import bisect
n, k = map(int, input().split())
a = list(map(int, input().split()))
b = [0] * 2001
c = [0] * 2001
cnt = 0
for i in range(len(a)):
    b[a[i]] += 1
for i in range(len(a)):
    c[a[i]] += 1
    sb = sum(b[a[i] + 1:])#全カウント
    sc = sum(c[a[i] + 1:])#これまでのカウント
    ss = (sc + (sc + sb * (k - 1))) * k // 2
    cnt += ss
    cnt %= (10 ** 9 + 7)
print(cnt)


Measured memory_bytes: 41836
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const ll INF = 1000000000000000000LL;

struct mint {
  ll x;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};

mint factorial(ll n) {
  mint answer = 1;
  while (n > 1) {
    answer *= n;
    n--;
  }
  return answer;
}

mint combination(ll n, ll r) {
  return factorial(n) / (factorial(r) * factorial(n - r));
}

mint permutation(ll n, ll r) { return factorial(n) / factorial(n - r); }

// setprecision(8) 桁数指定
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

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

template <typename T>
void remove(std::vector<T>& vector, unsigned int index) {
  vector.erase(vector.begin() + index);
}

map<ll, ll> prime_factor(ll n) {
  map<ll, ll> ret;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1) ret[n] = 1;
  return ret;
}
// for (auto p : prime_factor(n)) {
//	while (p.second--) {
//		cout << p.first << endl;
//	}
//}

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

bool compare_by_b(pair<ll, ll> a, pair<ll, ll> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

vector<ll> Eratosthenes(const ll N) {
  bool is_prime[1000000 + 1];
  vector<ll> P;
  for (ll i = 0; i <= N; i++) {
    is_prime[i] = true;
  }
  for (ll i = 2; i <= N; i++) {
    if (is_prime[i]) {
      for (ll j = 2 * i; j <= N; j += i) {
        is_prime[j] = false;
      }
      P.emplace_back(i);
    }
  }
  return P;
}

typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

int main() {
  int x, y, z;
  cin >> x >> y >> z;
  int ans = (x - z) / (y + z);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
/**
 *    This code has been written by YueGuang, feel free to ask me question. Blog: http://www.yx.telstudy.xyz
 *    created:
 */
#include <cstdio>
#include <iostream>
#include <set>
#include <map>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#define REP(i, a, b) for(int i = a; i < b; i++)
#define REP_(i, a, b) for(int i = a; i <= b; i++)
#define sl(n) scanf("%lld", &n);
#define si(n) scanf("%d", &n);
#define RepAll(a) for(auto x: a)
#define cout(ans) cout << ans << endl;
typedef long long ll;
using namespace std;
int main()
{
    int a, b;
    scanf("%d%d", &a, &b);
    cout<<"100 100\n";
    REP(i, 0, 100)
    {
        REP(j, 0, 100)
            i < 50 ? cout<< ( i%2 == 1 && j%2 == 1&& (--a) > 0 ? "." : "#" ) : cout << (i%2 == 1 && j%2 == 1&& (--b) > 0 ? "#" : ".");
        cout << '\n';
    }
}


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

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

const int dx[4] = {+1, 0, -1, 0};
const int dy[4] = {0, -1, 0, +1};

// AGC, GAC, ACG, A?GC, AG?C is invalid, otherwise valid
bool isvalid(string last3, string l0){
    if(last3 == "AGC" || last3 == "GAC" || last3 == "ACG") return false;
    if(last3.substr(1, 2) + l0 == "AGC") return false;
    if(last3.substr(1, 2) + l0 == "GAC") return false;
    if(last3.substr(1, 2) + l0 == "ACG") return false;
    if(last3.substr(0, 1) == "A" && (last3.substr(2, 1) + l0) == "GC") return false;
    if(last3.substr(0, 2) == "AG" && l0 == "C") return false;
    return true;
}

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    ll n; cin >> n;
    vector<string> c = {"A", "C", "G", "T"};
    unordered_map<string, ll> pdp;
    unordered_map<string, ll> dp;

    pdp["TTT"] = 1;

    for(int i=0;i<n;i++){
        for(string l3: c){
            for(string l2: c){
                for(string l1: c){
                    string last3 = l3 + l2 + l1;
                    for(string l0: c){
                        if(isvalid(last3, l0)){
                            string newlast3 = l2 + l1 + l0;
                            dp[newlast3] += pdp[last3];
                            dp[newlast3] %= MOD;
                        }
                    }
                }
            }
        }
        pdp = dp;
        dp = unordered_map<string, ll>();
    }
    ll ans = 0;
    for(string l3: c){
        for(string l2: c){
            for(string l1: c){
                string last3 = l3 + l2 + l1;
                ans += pdp[last3];
                ans %= MOD;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
   

  public static long ways(char matrix[][],int n,int m,int i,int j,long dp[][])
  {
	  
	  if(matrix[i][j]=='#') {
		  dp[i][j]=0;
		  return 0;}
	  if(i==n-1&&j==m-1)
		  return 1;
	  if(dp[i][j]==-1) {
	  int dx=i+1;
	  int dy=j;
	  int rx=i;
	  int ry=j+1;
	  long op1=0,op2=0;
	  if(dx<n&&dy<m)
	  {
		if(dp[dx][dy]==-1)
			op1=(ways(matrix,n,m,dx,dy,dp))%1000000007;
		else
			op1=dp[dx][dy];
	  }
	  if(rx<n&&ry<m)
	  {
		if(dp[rx][ry]==-1)
			op2=ways(matrix,n,m,rx,ry,dp)%1000000007;
		else
			op2=dp[rx][ry];
	  }
	  dp[i][j]=(op1+op2)%1000000007;
	  
	  
	  }
	  return dp[i][j];
  }
	
  public static void main(String[] args)
  {
     
  Scanner s=new Scanner(System.in);
  int n=s.nextInt();
  int m=s.nextInt();
  char matrix[][]=new char[n][m];
  for(int i=0;i<n;i++)
  {
	String line=s.next();
	String str[]=line.split("");
	  for(int j=0;j<m;j++) {
		  matrix[i][j]=str[j].charAt(0);}
  }
  long dp[][]=new long[n][m];
  for(int i=0;i<n;i++)
  {
	  for(int j=0;j<m;j++)
	  {
		  dp[i][j]=-1;
	  }
  }
//  for(int p=0;p<n;p++)
//  {
//	  for(int q=0;q<m;q++)
//		 System.out.print(matrix[p][q]+" ");
//	  System.out.println();
//  }
// 
  System.out.println( ways(matrix,n,m,0,0,dp));
  
  s.close();
    
  }
}


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

const int dy[4] = {0, 1, 0, -1};
const int dx[4] = {1, 0, -1, 0};

const vector<string> A {
    "6314",
    "2.2.",
    "1364",
    "5.5.",
};

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> S(H);
    for(auto &e : S) cin >> e;
    queue<pair<int, int>> que;
    vector<vector<int>> dist(H, vector<int>(W, -1));
    que.emplace(0, 0);
    dist[0][0] = 0;
    while(!que.empty()) {
        auto cur = que.front(); que.pop();
        int y = cur.first, x = cur.second;
        for(int i = 0; i < 4; ++i) {
            int ny = y + dy[i], nx = x + dx[i];
            if(ny < 0 || nx < 0 || ny >= H || nx >= W) continue;
            if(dist[ny][nx] != -1) continue;
            if(S[ny][nx] == A[ny % 4][nx % 4]) {
                que.emplace(ny, nx);
                dist[ny][nx] = dist[y][x] + 1;
            }
        }
    }
    cout << (dist[H - 1][W - 1] != -1 ? "YES" : "NO") << '\n';
    return 0;
}



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


int main(){
  int n;
  cin>>n;
  int p[n];
  rep(i,n)cin>>p[i];
  int m=n,cnt=0;
  rep(i,n){
    if(p[i]<=m){m=p[i];cnt++;}
  }
  cout << cnt;
}


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

int main() {
	int n, R[MAX];
	cin >> n;
	for (int i = 0; i < n; i++)cin >> R[i];

	int maxv = -2000000000;
	int minv = R[0];

	for (int i = 1; i < n; i++) {
		maxv = max(maxv, R[i] - minv);
		minv = min(minv, R[i]);
	}

	cout << maxv << endl;
}

Measured memory_bytes: 3860
#include <stdio.h>

int gcd(int a, int b) {
    if (a < b) {
        int tmp = a;
        a = b;
        b = tmp;
    }
    int r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }

    return b;
}

int main(void) {
    int i;
    int n;
    int x, x_next;
    int dx;
    int d;


    scanf("%d%d", &n, &x);
    scanf("%d", &x_next);
    dx = x_next - x;
    if (dx < 0) dx = -dx;
    x = x_next;
    d = dx;
    for (i = 2; i <= n; i++) {
        scanf("%d", &x_next);
        dx = x_next - x;
        if (dx < 0) dx = -dx;
        x = x_next;
        d = gcd(d, dx);
    }
   
    printf("%d\n", d);

    return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <cstring>

int main()
{
    char str[1001], buff[1001], command[100];
    int q, a, b;

    scanf("%s", str);
    scanf("%d", &q);

    for(int i = 0; i < q; i++){
        scanf("%s", command);
        if(strcmp(command, "print") == 0){
            scanf("%d", &a);
            scanf("%d", &b);
            for(int j = 0; j <= b - a; j++){
                buff[j] = str[a + j];
            }
            buff[b - a + 1] = '\0';
            printf("%s\n", buff);
        }
        else if(strcmp(command, "reverse") == 0){
            scanf("%d", &a);
            scanf("%d", &b);
            strcpy(buff, str);
            for(int j = 0; j <= b - a; j++){
                str[a + j] = buff[b - j];
            }
        }
        else if(strcmp(command , "replace") == 0){
            scanf("%d", &a);
            scanf("%d", &b);

            char p[b - a + 1];
            scanf("%s", p);

            for(int j = 0; j <= b - a; j++){
                str[a + j] = p[j];
            }
        }
        else {
            printf("ERROR\n");
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
using namespace std;
int v[100005];
int main()
{
    ios_base::sync_with_stdio(false);
    int n,i,s=0;
    cin>>n;
    for(i=1;i<=n;i++)
        cin>>v[i];
    bool ok=0;
    while(!ok)
    {
        ok=1;
        for(i=1;i<=n;i++)
        {
            ///i i+1
            if(v[i]==i)
            {
                swap(v[i],v[i+1]);
                ok=0;
                s++;
                break;
            }
        }
    }
    cout<<s;
    return 0;
}


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

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

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

	ll ans = 0;
	for (int C = 1; C < N; ++C) {
		int tmp = N;
		tmp -= C;

		int sq = sqrt(tmp);
		int ans_t = 0;
		for (int A = 1; A <= sq; ++A) {
			if (tmp % A == 0) {
				ans_t++;
			}
		}

		ans_t *= 2;
		if (sq * sq == tmp) {
			ans_t -= 1;
		}

		ans += ans_t;
	}

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


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

bool check(int N,int pos)
{
    return (bool)(N & (1<<pos));
}
int Set(int N,int pos)
{
    return N=N | (1<<pos);
}
int N=100005,prime[100005],counter;
int status[100005/32];
void sieve()
{
     int i, j, sqrtN;
     sqrtN = int( sqrt( N ) );
     for( i = 3; i <= sqrtN; i += 2 )
     {
		 if( check(status[i/32],i%32)==0)
		 {
	 		 for( j = i*i; j <= N; j += 2*i )
			 {
				 status[j/32]=Set(status[j/32],j % 32)   ;
	 		 }
		 }
	 }
	 prime[0]=2;
	 for(i=3,j=1;i<=N;i+=2)
	{
	    if( check(status[i/32],i%32)==0)
            {
                prime[j]=i;
                j++;
            }
	}
	counter=j;

}


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

    for(int i=0;i<counter;i++){
        if(prime[i]>=n)
        {
            cout<<prime[i]<<endl;
            break;
        }
    }

    return 0;
}



Measured memory_bytes: 256
// 入力例: 2 3
use whiteread::parse_line;

fn main() {
    let (mut a, mut b, mut c): (i32, i32, i32) = parse_line().unwrap();
    let k: i32 = parse_line().unwrap();
    let mut i: i32 = 0;

    while i < k {
        if a >= b && a >= c {
            a = a * 2;
        } else if b >= c {
            b = b * 2;
        } else {
            c = c * 2;
        }
        i = i + 1;
    }

    println!("{}", a+b+c);
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REPR(i, n) for(int i = (n); i >= 0; i--)
#define FOR(i, m, n) for(int i = (m); i < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << ": " << x << endl;

using namespace std;
typedef long long ll;

signed main() {
  int n, m, x;
  cin >> n >> m >> x;
  int c[n], a[n][m];
  int progress[m] = {};
  REP(i, n) {
    cin >> c[i];
    REP(j, m) { cin >> a[i][j]; }
  }

  vector<int> costs;

  for(int bit = 0; bit < (1 << n); bit++) {
    int cost = 0;
    for(int i = 0; i < n; ++i) {
      if(bit & (1 << i)) {
        for(int j = 0; j < m; j++) {
          progress[j] += a[i][j];
        }
        cost += c[i];
      }
    }

    bool judge = true;
    for(int j = 0; j < m; j++) {
      if(progress[j] < x) judge = false;
      progress[j] = 0;
    }
    if(judge) costs.push_back(cost);
  }

  if(costs.size() == 0) {
    cout << -1 << endl;
  } else {
    cout << *min_element(costs.begin(), costs.end()) << endl;
  }

  return 0;
}


Measured memory_bytes: 3660
import java.util.Scanner;

public class Main {
    static int N;
    static int[][] act;
    static int[][] dp;
    static int r;

    static int a = 0;
    static int b = 1;
    static int c = 2;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();

        act = new int[N+1][3];
        dp = new int[N+1][3];
        for(int i=1; i<=N; ++i) {
            act[i][a] = sc.nextInt();
            act[i][b] = sc.nextInt();
            act[i][c] = sc.nextInt();
        }

        for(int i=1; i<=N; ++i) {
            dp[i][a] = Math.max(dp[i-1][b], dp[i-1][c]) + act[i][a];
            dp[i][b] = Math.max(dp[i-1][a], dp[i-1][c]) + act[i][b];
            dp[i][c] = Math.max(dp[i-1][a], dp[i-1][b]) + act[i][c];
        }

        r = Math.max(dp[N][a], dp[N][b]);
        r = Math.max(r, dp[N][c]);
        System.out.println(r);
    }
}


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

int main(){
  int A, B;
  cin >> A >> B;
  
  int count;
  for(int i=A;i<=B;i++){
    if(i%10==i/10000 && i/10%10==i/1000%10) count++;
  }
  cout << count <<endl;
}

Measured memory_bytes: 256
let n = read_int ()
let m = ref (0, 1)
let rec f n = if n mod 2 <> 0 then 0 else 1 + f (n / 2)
let _ = for i = 1 to n do m := max !m @@ (f i, i) done; Printf.printf "%d\n" @@ snd !m

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

using namespace std;

int main()
{
    int n; cin >> n;
    int a[3][109];
    int visited[3][109];

    for (int i = 0; i <= 2; i++) {
        for (int j = 0; j <= n; j++) {
            visited[i][j] = 0;
            a[i][j] = 0;
        }
    }

    // for (int i = 1; i <= 2; i++) {
    //     for (int j = 1; j <= n; j++) {
            
    //     }
    // }

    // search
    for (int i = 1; i <= 2; i++) {
        for (int j = 1; j <= n; j++) {
            cin >> a[i][j];
            visited[i][j] = max(visited[i][j - 1] + a[i][j], visited[i - 1][j] + a[i][j]);
        }
    }

    cout << visited[2][n] << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {

	int a, b, c;
	int count=0;

	cin >> a >> b >> c;

	for (int num = a; num <= b; num++) {
		if (c%num==0){
			count++;
		}
	}

	cout << count << endl;

	return 0;
}

Measured memory_bytes: 3096
import sys
input = lambda : sys.stdin.readline().rstrip()

s = input()
n = len(s)
k = int(input())
ans = []
used = set()
"""
from collections import defaultdict
d = defaultdict(list)
for i in range(n):
    d[s[i]].append(i)
""" 
for i in range(n):
    start = list(s[i])
    if s[i] not in used:
        ans.append(s[i])
        used.add(s[i])
    for j in range(i + 1, min(i + k, n)):
        start.append(s[j])
        temp = "".join(start)
        if temp not in used:
            ans.append(temp)
            used.add(temp)
ans.sort()
print(ans[k - 1])


Measured memory_bytes: 41072
// C++ program to find LCM of two numbers  
#include <iostream>
#include <vector>
#include <numeric>

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPONE(i, n) for(int i = 1; i < n; i++)
#define ll long long

using namespace std; 

// Driver program to test above function  
int main()  
{  
    int n; cin >> n;
    vector<ll> time;
    ll t;
    REP(i, n) {
        cin >> t;
        time.push_back(t);
    }

    ll ans = time[0];

    REPONE(i, n) {
        ans = ans / gcd(ans, time[i]) * time[i];
    }

    cout << ans << endl;

    return 0;  
}  

Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<functional>
#include<map>
using namespace std;

int main() {
	int a; cin >> a;
	for (int b = 0; b < a; b++) {
		string c, d; cin >> c >> d;
		for (int i = c.length() - 1; i >= 0;i--) {
			char e = c[i];
			switch (e) {
			case 'P':for (int f = 0; f < d.length(); f++) {
				if (d[f] == '0')d[f] = '9';
				else if (d[f] <= '9')d[f]--;
			} break;
			case 'M':for (int f = 0; f < d.length(); f++) {
				if (d[f] == '9')d[f] = '0';
				else if (d[f] <= '9')d[f]++;
			} break;
			case 'C':d = d.substr(1, d.length() - 1) + d[0]; break;
			case 'J':d = d[d.length() - 1] + d.substr(0, d.length() - 1); break;
			case 'A': {string f = d;
				for (int g = 0; g < d.length(); g++) {
					d[g] = f[d.length() - 1 - g];
				}
				break; }
			default: {
				if (d.length() & 1)
				{
					string f = d;
					d = ""; 
					d += f.substr(f.length() - f.length() / 2, f.length() / 2);
					d += f[f.length() / 2];
					d += f.substr(0, f.length() / 2);
				}
				else {
					string f = d;
					d = "";
					d += f.substr(f.length() - f.length() / 2, f.length() / 2);
					d += f.substr(0, f.length() / 2);
				}}
			}
		}
		cout << d << endl;
	}
}

Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi 2*acos(0.0)
#define f first
#define s second
#define pb push_back
#define gap ' '
#define fastio {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define mod 1000000007
#define N 305

int n;
double dp[N][N][N];

double solve(int one,int two,int three)
{
    if(!one && !two && !three) return 0;
    double &ret=dp[one][two][three];
    if(ret!=-1) return ret;
    double tot=one+two+three;
    ret=(n-tot)/tot;
    if(one) ret+=(one+one*solve(one-1,two,three))/tot;
    if(two) ret+=(two+two*solve(one+1,two-1,three))/tot;
    if(three) ret+=(three+three*solve(one,two+1,three-1))/tot;
    return ret;

}

int main()
{
    fastio;
    cin>>n;
    int one=0,two=0,three=0;
    for(int i=0;i<n;i++)
    {
        int x;
        cin>>x;
        if(x==1) one++;
        if(x==2) two++;
        if(x==3) three++;
    }
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=n;j++)
        {
            for(int k=0;k<=n;k++) dp[i][j][k]=-1;
        }
    }
    cout<<setprecision(8)<<fixed<<solve(one,two,three)<<endl;

}


Measured memory_bytes: 219520
#include<bits/stdc++.h>
using namespace std;
#define ll int64_t
#define rep(i,n) for(int64_t i=0;i<n;++i)
#define P pair<ll,ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr int64_t INF=(1ll<<60);
constexpr int64_t mod=1000000007;
constexpr double pi=3.14159265358979323846;
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    vector<ll> san(3);
    rep(i,3) cin>>san[i];

    sort(san.begin(),san.end());

    bool yes=false;
    if(san[0]==san[1] && san[1]!=san[2]) yes=true;
    if(san[0]!=san[1] && san[1]==san[2]) yes=true;

    if(yes) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

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

int sum(int n){
  int r = 0;
  
  for(int i = 1; i <= 5; i++){
    r += n % 10;
    n /= 10;
  }
  
  return r;
}

int main() {
  int N;
  cin >> N;
  int ans = 0;
  
  int a1 = 1;		// Aの最初の値
  int a2 = N/2;		// Aの最後の値
  int b1 = N/2 + 1;	// Bの最初の値
  int b2 = N - 1;	// Bの最後の値    
  if(N%2 == 0 ){
    b1 = N/2;		// Nが偶数ならBの最初の値を変更
  }
  vector<int> vec(a2);

  for(int i = a1; i <= a2; i++){
    for(int j = b2; j >= b1; j--){
      if( (i + j) == N ) { // A+BがNの値になった場合、AとBの各桁を計算して配列に格納する
        vec.at(i-1) = sum(i) + sum(j);
        break;
      }
    }
  }
 
  // 格納した配列の中で最小の値を求める
  int min = *std::min_element(vec.begin(), vec.end());
  cout << min << endl;
  
  return 0;
}


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

using i64 = int64_t;

#define rep(i, x, y) for (i64 i = i64(x), i##_max_for_repmacro = i64(y); i < i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf = 1.01e9;
const i64 inf64 = 4.01e18;
const double eps = 1e-9;

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

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

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

template<typename T, size_t size> void fill(T (&ary)[size], const T& val){
    fill_n((T*)ary, size, val);
}

void solve() {
    //const i64 mod = 1'000'000'007;
    i64 N;
    cin >> N;

    vector<string> s(N);
    rep(i,0,N) cin >> s[i];

    i64 ab=0,a=0,b=0;
    rep(i,0,N){
        if(s[i].back()=='A' and s[i].front()=='B') ++ab;
        else if(s[i].back()=='A') ++a;
        else if(s[i].front()=='B') ++b;
    }

    i64 ans=0;
    rep(i,0,N){
        rep(j,0,s[i].size()-1){
            if(s[i][j]=='A' and s[i][j+1]=='B') ++ans;
        }
    }

    ans+=min(a,b);
    ans+=min(max(a,b)-min(a,b),ab);
    i64 rem=ab-min(max(a,b)-min(a,b),ab);
    if(a>0 or b>0) ans+=rem;
    else ans+=max(rem-1,i64(0));

    cout << ans << endl;
}

int main() {\
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#include <string.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m; i < n; i++) 
#define mod 1000000007
typedef long long ll;
int main(){
    int X,Y,Z;
    cin>>X>>Y>>Z;
    cout<<Z<<" "<<X<<" "<<Y<<endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
Q = int(input())

# 値がiであるようなA_iの個数を格納する
val_count = [0] * (10 ** 5 + 1)

total_A = 0
for a in A:
    total_A += a
    val_count[a] += 1

S = []
for i in range(Q):
    B, C = map(int, input().split())
    # cur_S = total_A
    B_count = val_count[B]
    # cur_S -= B * B_count
    # cur_S += C * B_count
    total_A -= B * B_count
    total_A += C * B_count
    # S.append(cur_S)
    S.append(total_A)

    val_count[B] = 0
    val_count[C] += B_count

for s in S:
    print(s)


Measured memory_bytes: 87104
import java.util.Scanner

object Main {

  def read() = {
    val sc = new Scanner(System.in)
    val l = sc.nextInt()
    l
  }

  def solve(l:Int): Double = {
    val edge = l.toDouble/3
    edge * edge * edge
  }

  def main(args: Array[String]): Unit = {
    val l = read()
    val result = solve(l)
    printf("%f", result)
    println()
  }
}

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

int main(void)
{

	int i;
	char str[1001];

	scanf("%s", str);

	for(i = 0; i < strlen(str); i++) {
		if(str[i] - 3 >= 65) {
			str[i] -= 3;
		}
		else {
			str[i] += 23;
		}
	}

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

	return 0;

}

Measured memory_bytes: 524
#include<cstdio>
char s[305][305];
int sum0[605][605], sum1[605][605];

int getSum0(int i,int l,int r,int n,int m){
    if(i<=0 || i>=n+m) return 0;
    else if(l>r) return 0; 
    else return sum0[i][r]-sum0[i][l-1];
}

int getSum1(int i,int l,int r,int n,int m){
    if(i<=1 || i>=n+m+1) return 0;
    else if(l>r) return 0;
    else return sum1[i][r]-sum1[i][l-1];
}

int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i = 1; i <= n; i++){
        scanf("%s",s[i]+1);
        for(int j = 1; j <= m; j++){
            if(s[i][j]=='#'){
                sum0[i-j+m][i+j] = 1;
                sum1[i+j][i-j+m] = 1;
            }
        }
    }
    for(int i = 1; i <= n+m-1; i++){
        sum0[i][0] = 0;
        for(int j = 1; j <= n+m; j++) sum0[i][j] += sum0[i][j-1];
    }
    for(int i = 2; i <= n+m; i++){
        sum1[i][0] = 0;
        for(int j = 1; j <= n+m-1; j++) sum1[i][j] += sum1[i][j-1];
    }
    long long ans = 0;
    for(int i = 1; i <= n+m-1; i++){
        for(int j = 2; j <=n+m; j++){
            if(sum0[i][j]==sum0[i][j-1]) continue;
            for(int k = 2; k < j; k++){
                if(sum0[i][k]==sum0[i][k-1]) continue;
                //printf("i = %d, j = %d, k = %d\n",i,j,k);
                int diff = j-k;
                //printf("diff = %d\n",diff);
                long long add = getSum0(i+diff,k,j,n,m)+getSum0(i-diff,k,j,n,m);
                ans += add;
            }
        }
    }
    for(int i = 2; i <= n+m; i++){
        for(int j = 1; j <=n+m-1; j++){
            if(sum1[i][j]==sum1[i][j-1]) continue;
            for(int k = 1; k < j; k++){
                if(sum1[i][k]==sum1[i][k-1]) continue;
                int diff = j-k;
                long long add = getSum1(i+diff,k+1,j-1,n,m)+getSum1(i-diff,k+1,j-1,n,m);
                ans += add;
            }
        }
    }
    printf("%lld\n",ans);
    return 0;
}


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

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define fst first
#define snd second

int main()
{
    int h, w;
    cin >> h >> w;
    char s[h][w];
    for(int i = 0; i < h; i++)
    {
        for(int j = 0; j < w; j++)
            cin >> s[i][j];
    }

    int dp[h][w];
    dp[0][0] = s[0][0] == '#';
    for(int i = 0; i < h; i++)
    {
        for(int j = 0; j < w; j++)
        {
            if(i == 0 && j == 0)
                continue;
            dp[i][j] = min(i > 0 ? dp[i - 1][j] + (s[i][j] == '#' && s[i - 1][j] == '.') : 1e9,
                           j > 0 ? dp[i][j - 1] + (s[i][j] == '#' && s[i][j - 1] == '.') : 1e9);
        }
    }

    cout << dp[h - 1][w - 1];

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC141
{
    class B
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            bool flag = true;

            for (int i = 0; i < S.Length; i++)
            {
                if (i%2 == 0 && S[i].Equals('L'))
                {
                    flag = false;
                    break;
                }
                if (i%2 == 1 && S[i].Equals('R'))
                {
                    flag = false;
                    break;
                }
            }

            if (flag)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


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

using namespace std;

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

    int N;
    cin >> N;

    vector<pair<int, int>> job(N);

    for(int i = 0; i < N; i++)
    {
        int j, k;
        cin >> j >> k;
        job[i] = make_pair(k, j);
    }

    int now = 0;
    int out = 0;

    sort(job.begin(), job.end());

    for(int i = 0; i < N; i++)
    {
        now += job[i].second;
        if(now > job[i].first)
        {
            out = 1;
            break;
        }
    }

    if(out == 0)
    {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

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

int main()
{
	//input
	int N; cin >> N;
	vector<int> d(N);
	for (int i = 0; i < N; i++) cin >> d[i];
	//compute
	sort(d.begin(), d.end());
	d.erase(unique(d.begin(), d.end()), d.end());
	size_t ans = d.size();
	//output
	cout << ans << endl;
} 

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


int main(){
    int n,i,count=0;
    char s[52];
    scanf("%d",&n);
    scanf("%s",s);
    for (i=0; i<n-2; i++) {
        if (s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C') {
            count++;
        }
    }printf("%d",count);
    return 0;
}


Measured memory_bytes: 128