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

using ll = long long;
using boost::irange;

int main(){
    int N;

    cin >> N;
    
    int current, prev;
    ll ans = 0;
    for(const int i : irange(0, N - 1)){
        cin >> current;

        if (i > 0){
            ans += min({current, prev});
        } else {
            ans += current;
        }
        prev = current;
    }
    ans += prev;

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <stdio.h>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional> //operator[]
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
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;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;



signed main(){
    int x; cin >> x;
    ll ans=x/500;
    x-=500*ans;
    ans*=1000;
    
    ans+=5*(x/5);
    cout << ans << endl;
    
}


Measured memory_bytes: 256
n, x, t = map(int, input().split())
# 入力を受け取る

k = (n + x - 1) // x
# 何回焼く必要があるかというkを、焼く必要のあるたこ焼きの個数 N を、
# 一度に焼ける個数 X で割った答えを、小数点切り上げすることで求める(整数除算)
ans = k * t # kと時間をかけて何分かかるかという答えを求める
print(ans)


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

int main()
{
    int N, M, K;
    cin >> N >> M >> K;
    vector<int> A(N), B(M);
    for (int i = 0; i < N; i++)
        cin >> A[i];
    for (int i = 0; i < M; i++)
        cin >> B[i];
    //累積和の定義
    vector<long long> sa = {0}, sb = {0};
    for (int i = 1; i <= N; i++)
    {
        //Kを越えればその先はいらない
        if (sa[i - 1] + A[i - 1] > K)
            break;
        sa.emplace_back(sa[i - 1] + A[i - 1]);
    }
    for (int i = 1; i <= M; i++)
    {
        //Kを越えればその先はいらない
        if (sb[i - 1] + B[i - 1] > K)
            break;
        sb.emplace_back(sb[i - 1] + B[i - 1]);
    }
    //机Aが0冊の時
    // a->机aの冊数, b->bの冊数
    int a = 0, b = sb.size() - 1;
    if (b == 0)
        cout << 0;
    else
    {
        int ans = b;
        for (; a < sa.size(); a++)
        {
            for (; 0 <= b; b--)
                if (sa[a] + sb[b] <= K)
                    break;
            ans = max(a + b, ans);
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 9568
#ABC-131-C
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a
    
A, B, C, D = map(int, input().split())
lcm = C * D // gcd(C, D)
#1~A-1までの数字でCでもDでも割り切れないものの個数
A_divided_C = (A-1) // C
A_divided_D = (A-1) // D
A_divided_CD = (A-1) // (lcm)
one_to_A = (A-1) - A_divided_C - A_divided_D + A_divided_CD

#1~Bまでの数字でCでもDでも割り切れないものの個数
B_divided_C = B // C
B_divided_D = B // D
B_divided_CD = B // (lcm)
one_to_B = B - B_divided_C - B_divided_D + B_divided_CD

ans = one_to_B - one_to_A
print(ans)

Measured memory_bytes: 3064
N,Q=map(int,input().split())
edge=[[] for _ in range(N)]
cnt=[0]*N
for _ in range(N-1):
  a,b=map(int,input().split())
  edge[a-1]+=(b-1),
  edge[b-1]+=(a-1),
for _ in range(Q):
  p,x=map(int,input().split())
  cnt[p-1]+=x
done=[False]*N
done[0]=True
stack=[0]
while stack:
  par=stack.pop()
  for child in edge[par]:
    if not done[child]:
      done[child]=True
      cnt[child]+=cnt[par]
      stack.append(child)
print(*cnt)

Measured memory_bytes: 55732
import math
N, D = map(int, input().split())
X = []
for i in range(N):
    temp = list(map(int, input().split()))
    X.append(temp)

ans = 0
for i in range(N):
    for j in range(i+1,N):
        dist = 0
        for d in range(D):
            dist += (X[i][d] - X[j][d])**2
        dist = math.sqrt(dist)
        if dist == float(int(dist)):
            ans += 1

print(ans)

Measured memory_bytes: 3064
# D - Friend Suggestions
class UnionFind:
    __slots__ = ["_size", "_first_idx", "_parents"]

    def __init__(self, size: int, first_index: int = 0) -> None:
        self._size = size
        self._first_idx = first_index
        self._parents = [-1] * (size + first_index)

    def find(self, x: int) -> int:
        """Find the group (root) of vertex x"""
        if self._parents[x] < 0:
            return x
        self._parents[x] = self.find(self._parents[x])
        return self._parents[x]

    def is_same(self, x: int, y: int) -> bool:
        """Return whether two vertices x and y are in the same group or not."""
        return self.find(x) == self.find(y)

    def unite(self, x: int, y: int) -> None:
        """Unite two groups of vertices x and y."""
        x, y = self.find(x), self.find(y)
        if x == y:
            return

        if self._parents[x] > self._parents[y]:
            x, y = y, x
        self._parents[x] += self._parents[y]
        self._parents[y] = x

    def get_size(self, x: int) -> int:
        """Get the size of the group vertex x belongs"""
        return -self._parents[self.find(x)]


def main():
    N, M, K, *ABCD = map(int, open(0).read().split())
    AB, CD = ABCD[:2 * M], ABCD[2 * M:]
    relationships = UnionFind(N, 1)
    non_candidates = [1] * (N + 1)  # Friends, mutually blocked persons, and user themselves can't be candidates.
    for a, b in zip(*[iter(AB)] * 2):
        relationships.unite(a, b)
        non_candidates[a] += 1
        non_candidates[b] += 1
    for c, d in zip(*[iter(CD)] * 2):
        if relationships.is_same(c, d):
            non_candidates[c] += 1
            non_candidates[d] += 1
    ans = [relationships.get_size(i) - non_candidates[i] for i in range(1, N + 1)]
    print(" ".join(map(str, ans)))


if __name__ == "__main__":
    main()


Measured memory_bytes: 47332
import java.util.Scanner;
import java.util.PriorityQueue;
import java.util.Comparator;
import java.util.Arrays;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		PriorityQueue<Integer> q=new PriorityQueue<>(Comparator.reverseOrder());
		Job[] a=new Job[n];
		for(int i=0; i<n; i++){
			a[i]=new Job(sc.nextInt()-1,sc.nextInt());
		}
		Arrays.sort(a);
		long ans=0;
		int ain=0;
		for(int i=0; i<m; i++){
			while(ain<n && a[ain].day==i){
				q.add(a[ain].salary);
				ain++;
			}
			if(!q.isEmpty()){
				ans+=q.poll();
			}
		}
		System.out.println(ans);
	}
	static class Job implements Comparable<Job>{
		int salary,day;
		public Job(int day,int salary){
			this.salary=salary;
			this.day=day;
		}
		@Override
		public int compareTo(Job j){
			return this.day-j.day;
		}
	}
}


Measured memory_bytes: 88380
#include <cstdio>
using namespace std;
int a, b, c, ans;

int main() {
    scanf("%d %d %d", &a, &b, &c);
    ans = c - (a - b);
    if(ans < 0)
        ans = 0;
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 128
def InputData():
    
    sequence_len = int(input())
    sequence = [input().split(" ") for _ in range(sequence_len)]
    sequence_m = [(a[0], int(a[1])) for a in sequence]
    sequence_q = [(a[0], int(a[1])) for a in sequence]
    return sequence_len, sequence_m, sequence_q

def partition(sequence, p, r):
    x = sequence[r]
    i = p - 1
    for j in range(p, r):
        if sequence[j][1] <= x[1]:
            i += 1
            sequence[i], sequence[j]= sequence[j], sequence[i]
    
    sequence[i+1], sequence[r] = sequence[r], sequence[i+1]
    return i+1

def quickSort(sequence, p, r):
    if p < r:
        q = partition(sequence, p, r)
        quickSort(sequence, p, q-1)
        quickSort(sequence, q+1, r)

def merge(sequence, left, mid, right):
    n1 = mid - left
    n2 = right - mid
    sequence_left = sequence[left:left + n1]
    sequence_right = sequence[mid:mid + n2]
    sequence_left.append([None, float('inf')])
    sequence_right.append([None, float('inf')])

    left_cnt = 0
    right_cnt = 0
    for i in range(left, right):
        if sequence_left[left_cnt][1] <= sequence_right[right_cnt][1]:
            sequence[i] = sequence_left[left_cnt]
            left_cnt += 1
        else:
            sequence[i] = sequence_right[right_cnt]
            right_cnt += 1

def mergeSort(sequence, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        mergeSort(sequence, left, mid)
        mergeSort(sequence, mid, right)
        merge(sequence, left, mid, right)

def PrintOut(sequence_m, sequence_q):
    if sequence_m == sequence_q:
        print("Stable")
    else:
        print("Not stable")
    
    for a in sequence_q:
        print(a[0], a[1])

def main():
    [sequence_len, sequence_m, sequence_q] = InputData()
    mergeSort(sequence_m, 0, sequence_len)
    quickSort(sequence_q, 0, sequence_len-1)
    
    PrintOut(sequence_m, sequence_q)

if __name__=="__main__":
    main()


Measured memory_bytes: 48436
#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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)*}
    };

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

#[allow(unused_macros)]
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, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input! {
        n: usize,
        k: usize,
        h: [usize; n],
    }
    let mut result = 0;
    for i in 0..n {
        if h[i] >= k {
            result += 1;
        }
    }
    println!("{}", result);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(c) begin(c), end(c)
#define dump(x) cerr << __LINE__ << ":\t" #x " = " << x << endl

using ld = double;
using P = complex<ld>;
using G = vector<P>;
const ld pi = acos(-1);
const ld eps = 1e-10;
const ld inf = 1e12;

ld cross(const P &a, const P &b) {
    return a.real() * b.imag() - a.imag() * b.real();
}
ld dot(const P &a, const P &b) {
    return a.real() * b.real() + a.imag() * b.imag();
}

using C = pair<ld, P>;
#define rad first
#define pnt second

C smallest_enclosing_disc(vector<P> ps) {
    auto c3 = [](const P &a, const P &b, const P &c) {
        ld A = norm(b - c);
        ld B = norm(c - a);
        ld C = norm(a - b);
        ld S = abs(cross(b - a, c - a));
        P p =
            (A * (B + C - A) * a + B * (C + A - B) * b + C * (A + B - C) * c) /
            (4 * S * S);
        ld r = abs(p - a);
        return make_pair(r, p);
    };

    auto c2 = [](const P &a, const P &b) {
        P c = (a + b) / (ld)2;
        ld r = abs(a - c);
        return make_pair(r, c);
    };

    auto in_circle = [](const P &a, const C &c) {
        return norm(a - c.pnt) <= c.rad * c.rad + eps;
    };

    int n = ps.size();
    random_shuffle(ps.begin(), ps.end());
    C c = c2(ps[0], ps[1]);
    for (int i = 2; i < n; ++i) {
        if (!in_circle(ps[i], c)) {
            c = c2(ps[0], ps[i]);
            for (int j = 1; j < i; ++j) {
                if (!in_circle(ps[j], c)) {
                    c = c2(ps[j], ps[i]);
                    for (int k = 0; k < j; ++k) {
                        if (!in_circle(ps[k], c)) {
                            c = c3(ps[i], ps[j], ps[k]);
                        }
                    }
                }
            }
        }
    }
    return c;
}

int main() {
    int n;
    cin >> n;
    vector<P> vec(n);
    rep(i, n) {
        ld x, y;
        cin >> x >> y;
        vec[i] = P(x, y);
    }
    auto ans = smallest_enclosing_disc(vec).first;
    cout << fixed << setprecision(10) << ans << endl;
}


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

#define ll long long



using namespace std;

const int N_MAX = 3002;
const int T_MAX = 3002;

int n, t;

struct Dish
{
    int a, b;
};

bool operator < (const Dish &a, const Dish &b)
{
    return a.a < b.a;
}

Dish d[N_MAX];

int dp[T_MAX];
int dp1[T_MAX];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> t;
    t--;
    for(int i = 1; i <= n; i++)
        cin >> d[i].a >> d[i].b;
    sort(d + 1, d + n + 1);
    for(int i = 1; i <= n; i++)
        for(int j = t; j >= 0; j--)
        {
            if(dp[j] + d[i].b > dp1[j])
                dp1[j] = dp[j] + d[i].b;
            if(j + d[i].a <= t && dp[j] + d[i].b > dp[j + d[i].a])
                dp[j + d[i].a] = dp[j] + d[i].b;
        }
    int ans = 0;
    for(int i = 0; i <= t; i++)
        ans = max(ans, dp1[i]);
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<map>
#include<queue>
#include<set>
#include<bitset>
#include<stdio.h>
#include<deque>
#include<iomanip>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long ll;

int main() {
	int h;
	cin >> h;
	int w;
	cin >> w;
	vector<string> a(h);
	for (int i = 0; i < h; i++) {
		cin >> a[i];
	}
 
	vector<bool> row(h, false);
	vector<bool> col(w, false);
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (a[i][j] == '#') {
				row[i] = true;
				col[j] = true;
			}
		}
	}
 
	for (int i = 0; i < h; i++) {
		if (row[i]) {
			for (int j = 0; j < w; j++) {
				if (col[j]) {
					cout << a[i][j];
				}
			}
			cout << endl;
		}
	}
}

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

int main(){
    int n;
    cin >> n;
    for(int i=0;i<n;++i){
        int a[4] = {0};
        cin >> a[0] >> a[1] >> a[2];
        sort(a, a+3);
        cout << (a[0] * a[0] + a[1] * a[1] == a[2] * a[2] ? "YES" : "NO") << endl;
        
    }

    return 0;
}


Measured memory_bytes: 3156
#include<bits/stdc++.h>
using namespace std;
const int N=4e3+2;
const int mod=998244353;
int ans[N],c[N][N];
void add(int &x,int y){
	x+=y;
	if(x>=mod){
		x-=mod;
	}
}
int mul(int x,int y){
	return (1ll*x*y)%mod;
}
void sub(int &x,int y){
	x-=y;
	if(x<0){
		x+=mod;
	}
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,i,j,k,l,m;
	cin>>k>>n;
	c[0][0]=1;
	for(i=1;i<N;i++){
		for(j=0;j<N;j++){
			c[j][i]=c[j][i-1];
			if(j){
				add(c[j][i],c[j-1][i-1]);
			}
		}
	}
	for(i=2;i<=k+1;i++){
		if(!(i&1)){
			m=i/2-1;
			for(j=0;j<=m;j++){
				if(2*j>n){
					break;
				}
				if(!(j&1)){
					add(ans[i],mul(c[j][m],c[k-1][n-2*j+k-1]));
				}
				else{
					sub(ans[i],mul(c[j][m],c[k-1][n-2*j+k-1]));
				}
			}
			for(j=0;j<=m;j++){
				if(2*j+2>n){
					break;
				}
				if(!(j&1)){
					sub(ans[i],mul(c[j][m],c[k-1][n-2*j-2+k-1]));
				}
				else{
					add(ans[i],mul(c[j][m],c[k-1][n-2*j-2+k-1]));
				}
			}
		}
		else{
			m=i/2;
			for(j=0;j<=m;j++){
				if(2*j>n){
					break;
				}
				if(!(j&1)){
					add(ans[i],mul(c[j][m],c[k-1][n-2*j+k-1]));
				}
				else{
					sub(ans[i],mul(c[j][m],c[k-1][n-2*j+k-1]));
				}
			}
		}
	}
	for(i=2;i<=2*k;i++){
		if(i<=k+1){
			cout<<ans[i]<<'\n';
		}
		else{
			cout<<ans[2*k+2-i]<<'\n';
		}
	}
}

Measured memory_bytes: 62976
// Best practice
 
#include<bits/stdc++.h>
 
#define int         long long
#define pb          push_back
#define pf          emplace_front
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define pii 		pair<int,int>
#define psi 		pair<string,int>
#define vi 			vector<int>
#define vpii  		vector<pii>
#define vvi 		vector<vi>
#define sz(x)	    (int)(x).size()
#define x           first
#define y           second
#define endl        '\n'
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MOD         1000000007
#define hell        998244353
#define prec(n) 	fixed<<setprecision(n)
#define ini(a, i) 	memset(a, i, sizeof(a))
#define output(x)   cout << (x ? "YES" : "NO")<<endl;
using namespace std;
 
#define debug(vec) cout<<(#vec)<<" : [ "; for (auto& i: vec) cout<<i<<" "; cout<< "]" << endl
#define debugp(vec) cout<<(#vec)<<" : [ "; for (auto& i: vec) cout<<"("<<i.x<<","<<i.y<<")"<<" "; cout<< "]" << endl
#define trace(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);cout << endl; }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << "[" << *it << ": " << a << "]\t";
    err(++it, args...);
}
 
// const int dx[4] = { -1, 1, 0, 0};
// const int dy[4] = {0, 0, -1, 1};
// int dX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
// int dY[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
 
 
// Code from Here -------------------------------------------------------------------------------

signed main() {
	tezz
 
	// #ifndef ONLINE_JUDGE
	// 	freopen("input.txt", "r", stdin);
	// 	freopen("output.txt", "w", stdout);
	// #endif

	int n,m;
	cin >> n >> m;
	char a[n][m];
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			cin >> a[i][j];	
		}
	}
	int dp[n][m];
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			if(a[i][j]=='#')dp[i][j]=0;
			else if(i==0 && j==0)dp[i][j]=1;
			else if(i==0){
				dp[i][j] = dp[i][j-1];
			}
			else if(j==0){
				dp[i][j] = dp[i-1][j];
			}
			else{
				dp[i][j] = (dp[i-1][j] + dp[i][j-1])%MOD;
			}
		}
	}
	cout << dp[n-1][m-1];
 
	return 0;
}  

Measured memory_bytes: 12300
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.NoSuchElementException;
import java.util.concurrent.PriorityBlockingQueue;

public class Main {

    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        String s = sc.next();

        if(s.charAt(2) == s.charAt(3) && s.charAt(4) == s.charAt(5)){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }

    }

    private static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;

        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }

        private int readByte() {
            if (hasNextByte())
                return buffer[ptr++];
            else
                return -1;
        }

        private static boolean isPrintableChar(int c) {
            return 33 <= c && c <= 126;
        }

        public boolean hasNext() {
            while (hasNextByte() && !isPrintableChar(buffer[ptr]))
                ptr++;
            return hasNextByte();
        }

        public String next() {
            if (!hasNext())
                throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while (isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }

        public long nextLong() {
            if (!hasNext())
                throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while (true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if (b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }

        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
                throw new NumberFormatException();
            return (int) nl;
        }

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

}



Measured memory_bytes: 23252
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue> 
 
using namespace std;
 
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	string S, T, U;

	int A, B;

	cin >> S >> T >> A >> B >> U;

	if(S == U) {
		A--;
	} else {
		B--;
	}

	cout << A << " " << B << endl;
}

Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define all(x) (x).begin(), (x).end()
#define ff first
#define ss second
#define setbits(x) __builtin_popcount(x)
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<db, db> pdd;
typedef vector<int> vi;
#define m1 make_pair
#define in insert
#define pb push_back
#define IOS                           \
    std::ios::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define endl "\n"
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

inline ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
inline ll power(ll a, ll n, ll m)
{
    if (n == 0)
        return 1;
    ll p = power(a, n / 2, m);
    p = (p * p) % m;
    if (n % 2)
        return (p * a) % m;
    else
        return p;
}
const ll MOD = 1000000007;
const int N = int(3e5) + 999;
#define int long long int

struct st{
	int x,y,d,b;
};
int n,m;
int dist[101][101][2];

int isvalid(int x,int y){
	return x>=0 and x<n and y>=0 and y<m;
}
int dx[]={1,0};
int dy[]={0,1};

int32_t main(){
    IOS;

    
    cin>>n>>m;
    string a[n];
    for(int i=0;i<n;i++)
    	cin>>a[i];

    for(int i=0;i<=n;i++){
    	for(int j=0;j<=m;j++)
    		dist[i][j][0]=dist[i][j][1]=1e15;
    }

    st tmp;
    tmp.x=0;tmp.y=0;tmp.d=(a[0][0]=='#');tmp.b=(a[0][0]=='#');
    deque<st> q;
    q.push_back(tmp);
    dist[0][0][tmp.b]=(tmp.b==1);

    while(!q.empty()){

    	st frnt = q.front();
    	q.pop_front();

    	int x = frnt.x;
    	int y = frnt.y;
    	int d = frnt.d;
    	int b = frnt.b;

    	for(int i=0;i<2;i++){

    		int xx = x+dx[i];
    		int yy = y+dy[i];
    		if(isvalid(xx,yy)){
    			//cerr<<xx<<" "<<yy<<" "<<b<<endl;
    			st tmp;
    			tmp.x=xx;
    			tmp.y=yy;
    			tmp.d=d;

    			if(b==1){    				
    				if(dist[xx][yy][1]>d and a[xx][yy]=='#'){
    					tmp.b=b;
    					dist[xx][yy][1]=d;
    					q.push_back(tmp);
    				}
    				else if(dist[xx][yy][0]>d and a[xx][yy]=='.'){
    					tmp.b=0;
    					dist[xx][yy][0]=d;
    					q.push_back(tmp);
    				}
    			}
    			else{
    				if(dist[xx][yy][0]>d and a[xx][yy]=='.'){
    					tmp.b=0;
    					dist[xx][yy][0]=d;
    					q.push_front(tmp);
    				}
    				else if(dist[xx][yy][1]>d+1 and a[xx][yy]=='#'){
    					tmp.d=d+1;
    					tmp.b=1;
    					dist[xx][yy][1]=d+1;
    					q.push_back(tmp);
    				}
    			}
    		}
    	}
    }

    int ans = min(dist[n-1][m-1][0],dist[n-1][m-1][1]);
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 512
from collections import deque
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
    N, M = map(int, readline().split())
    G = [[] for i in range(N)]
    for i in range(M):
        u, v = map(int, readline().split())
        G[u-1].append(v-1)
        G[v-1].append(u-1)
    cnts = [1, 0]
    dist = [[-1]*N for i in range(2)]
    dist[0][0] = 0
    que = deque([(0, 0)])
    while que:
        v, t = que.popleft()
        t1 = t^1
        dist1 = dist[t^1]
        d1 = dist[t][v]+1
        for w in G[v]:
            if dist1[w] != -1:
                continue
            dist1[w] = d1
            que.append((w, t1))
            cnts[t1] += 1
            if cnts[t1] == N:
                write("%d\n" % d1)
                break
        else:
            continue
        break
    else:
        write("-1\n")
solve()


Measured memory_bytes: 31912
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int[] c=new int[9];
    for(int i=0;i<9;i++)c[i]=sc.nextInt();
    for(int i=0;i<=Math.max(c[0], Math.max(c[1], c[2]));i++) {
    	int a1=i,b1=c[0]-a1,b2=c[1]-a1,b3=c[2]-a1,a2=c[3]-b1,a3=c[6]-b1;
    	if(a1+b1==c[0] && a1+b2==c[1]&& a1+b3==c[2]&& a2+b1==c[3]&& a2+b2==c[4]&& a2+b3==c[5]&& a3+b1==c[6]&& a3+b2==c[7]&& a3+b3==c[8]) {
    		System.out.println("Yes");
    		//System.out.println(a1+" "+a2+" "+a3+" "+b1+" "+b2+" "+b3);
    		System.exit(0);
    	}
    }
    System.out.println("No");
  }
}

Measured memory_bytes: 21844
import bisect

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return len(divisors) // 2

n = int(input())
ans = 1
if n == 2:
  print(1)
  exit()
if n == 3:
  print(2)
  exit()
a = []
for i in range(2,int(n ** 0.5)+1):
  now = n
  while not now % i:
    now //= i
  if now % i == 1:
    a.append(i)
    ans += 1
ans += make_divisors(n-1)
print(ans)

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

int main()
{
    string a;
  	cin >> a;
    string str;
    string b = "B";
  	for(int i = 0; i < a.size(); ++i){      
      	if(a[i] == b[0]){
          	if(str.size() > 0){
        	str.pop_back();
            }
        }else{
        	str += a[i];
        }
    }
  
  	cout << str << endl;
  
    return 0;
}

Measured memory_bytes: 256
from collections import Counter
import bisect

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

n = int(input())
L = Counter(prime_factorize(n))
A = [0]*50
for i in range(50):
    cnt = 1
    while i >= (cnt+1)*(cnt+2)//2:
        cnt += 1
    A[i] = cnt
ans = 0
for c in L.values():
    ans += A[c]
print(ans)

Measured memory_bytes: 67768
#pragma GCC target ("avx2") 
#pragma GCC optimization ("O3") 
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#define fast_az_fuk ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long 
#define int ll 
#define ull unsigned ll
#define ld long double 
#define pb push_back 
#define pf push_front
#define dll deque<ll> 
#define vll vector<ll> 
#define pll pair<ll,ll> 
#define mapll map<ll,ll>
#define endl "\n" 
#define all(v) v.begin(),v.end() 
#define ms(a,x) memset(a,x,sizeof(a))
using namespace std;
void swap(auto*,auto*);
int32_t main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    fast_az_fuk
    string s; cin>>s;
    if(s.back()=='s') s+="es"; else s+='s'; cout<<s;
    return 0;
}
void swap(auto &a,auto &b)
{
    auto temp=a; a=b; b=temp;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
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;
}
struct RollingHash {
    static const int base1 = 1007, base2 = 2009;
    static const int mod1 = 1000000007, mod2 = 1000000009;
    vector<long long> hash1, hash2, power1, power2;

    // construct
    RollingHash(const string &S) {
        int n = (int)S.size();
        hash1.assign(n+1, 0);
        hash2.assign(n+1, 0);
        power1.assign(n+1, 1);
        power2.assign(n+1, 1);
        for (int i = 0; i < n; ++i) {
            hash1[i+1] = (hash1[i] * base1 + S[i]) % mod1;
            hash2[i+1] = (hash2[i] * base2 + S[i]) % mod2;
            power1[i+1] = (power1[i] * base1) % mod1;
            power2[i+1] = (power2[i] * base2) % mod2;
        }
    }
    
    // get hash of S[left:right]
    inline pair<long long, long long> get(int l, int r) const {
        long long res1 = hash1[r] - hash1[l] * power1[r-l] % mod1;
        if (res1 < 0) res1 += mod1;
        long long res2 = hash2[r] - hash2[l] * power2[r-l] % mod2;
        if (res2 < 0) res2 += mod2;
        return {res1, res2};
    }

    // get lcp of S[a:] and T[b:]
    inline int getLCP(int a, int b) const {
        int len = min((int)hash1.size()-a, (int)hash1.size()-b);
        int low = 0, high = len;
        while (high - low > 1) {
            int mid = (low + high) >> 1;
            if (get(a, a+mid) != get(b, b+mid)) high = mid;
            else low = mid;
        }
        return low;
    }
};
int main(){
    ll n;string s;cin >> n >>s;
    RollingHash rh(s);
    ll ng=n/2+1,ok=0;
    while(abs(ok-ng)>1){
        bool check=false;
        ll mid=(ng+ok)/2;
        map<pl,ll> ma;
        for(int i=0;i+mid<=n;i++){
            auto p=rh.get(i,i+mid);
            if(ma.count(p)){
                if(i-ma[p]>=mid){
                    check=true;
                }
            }
            else ma[p]=i;
        }
        if(check)ok=mid;
        else ng=mid;
    }
    cout <<ok <<endl;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  int n;
  cin >> n;
  if(n<1000){
    cout << "ABC" << endl;
  }else{
    cout << "ABD" << endl;
  }
}


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

int main() {
  int n;
  
  while( cin >> n, n ) {
    int perfectNumber = 0;
    
    for(int i=1; i*i<n; i++) {
      if( n % i == 0 ) {
	perfectNumber += n/i;
	perfectNumber += i;
      }
    }
    perfectNumber -= n;
    if( perfectNumber < n ) cout << "deficient number" << endl;
    else if( perfectNumber == n ) cout << "perfect number" << endl;
    else cout << "abundant number" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1152
import java.util.*

data class State(val x: Int, val y: Int)

fun main(args: Array<String>) {
  val (h, w, k) = readLine()!!.split(" ").map { it.toInt() }
  val a = Array<String>(h) { readLine()!! }
  val INF = 1000000000
  val q: Queue<State> = ArrayDeque<State>()
  var dist = Array<IntArray>(h) { IntArray(w) { INF } }
  for (i in 0 until h) {
    for (j in 0 until w) {
      if (a[i][j] == 'S') {
        dist[i][j] = 0
        q.add(State(i, j))
      }
    }
  }
  val dx = arrayOf(1, 0, -1, 0)
  val dy = arrayOf(0, 1, 0, -1)
  var ans = INF
  while (!q.isEmpty()) {
    val (x, y) = q.remove()
    if (x == 0 || x == h - 1 || y == 0 || y == w - 1) {
      ans = arrayOf(ans, (dist[x][y] + k - 1) / k).min()!!
      continue
    }
    for (i in 0 until 4) {
      val tx = x + dx[i]
      val ty = y + dy[i]
      if (dist[tx][ty] <= dist[x][y] + 1) continue
      dist[tx][ty] = dist[x][y] + 1
      if (a[tx][ty] == '#') dist[tx][ty] = arrayOf(dist[tx][ty], k + 1).max()!!
      q.add(State(tx, ty))
    }
  }
  println(ans)
}


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

#define h_MAX 500010

long h, A[h_MAX];

long parent(long i) { return i / 2; }
long left(long i) { return i * 2; }
long right(long i) { return i * 2 + 1; }

void maxHeapify(long i) {
    long idx_l = left(i);
    long idx_r = right(i);

    long idx_largest = i;
    if (idx_l <= h && A[idx_l] > A[i]) {
        idx_largest = idx_l;
    }
    if (idx_r <= h && A[idx_r] > A[idx_largest]) {
        idx_largest = idx_r;
    }

    if (idx_largest != i) {
        long temp = A[idx_largest];
        A[idx_largest] = A[i];
        A[i] = temp;
        maxHeapify(idx_largest);
    }
}

void buildMaxHeap() {
    for (long i = h / 2; i >= 1; i--) {
        maxHeapify(i);
    }
}

int main() {
    cin >> h;
    for (long i = 1; i < h + 1; i++) {
        cin >> A[i];
    }

    buildMaxHeap();

    for (long i = 1; i < h + 1; i++) {
        cout << " " << A[i];
    }
    cout << endl;

    return 0;
}



Measured memory_bytes: 7004
#include <stdio.h>

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

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

    int b[n];
    for(i=0;i<n;i++){
        b[i]=0;
    }
    for(i=0;i<n-1;i++){
        b[a[i]-1]++;
        /*bの添字(社員番号)の部下の数*/
    }
    for(i=0;i<n;i++){
        printf("%d\n",b[i]);
    }
    return 0;
}


Measured memory_bytes: 3288
#include <bits/stdc++.h>
 
using namespace std;
 
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define repr(i, n) for(int i = n;i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define PI 3.141592653589793
#define MOD 1000000007
 
typedef long long ll;
 

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

    int h,w;
    cin >> h >> w;
    string s[h];
    
    rep(i,h){
        cin >> s[i];
    }

    rep(i,h){
        cout << s[i] << endl;
        cout << s[i] << endl;
    }

	return 0;
}

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// ====================================================================

int main() {
  int x, n;
  cin >> x >> n;
  vector<bool> v(200, true);
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    v[a] = false;
  }

  int ans = 0;
  for (int i = 1; i <= 101; i++) {
    if (v[i] == true && abs(x - i) < abs(x - ans)) {
      ans = i;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <climits>
#include <queue>
#include <cstring>
#include <stack>
#include <map>
#include <ctime>
using namespace std;
#define rep(i,a,b) for(int i=a; i<=b; i++)
#define ii pair <int, int>
#define fi first
#define se second
#define ll long long
int a[3001];
ll f[3002][3002];
ll s[3002];

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0);
//	freopen("Test.inp", "r", stdin);
//    freopen("Test.out", "w", stdout);
    int n;
    cin>>n;
    rep(i,1,n) cin>>a[i];
    rep(i,1,n) f[i][i]=a[i];
    rep(i,1,n) s[i]=a[i]+s[i-1];
    for(int i=n-1;i;i--){
        rep(j,i+1,n){
            f[i][j]=s[j]-s[i-1]-min(f[i+1][j], f[i][j-1]);
        }
    }
//    rep(i,1,n){
//        rep(j,1,n) cout<<f[i][j]<<' ';
//        cout<<endl;
//    }
    cout<<2ll*f[1][n]-s[n];
	return 0;
}


Measured memory_bytes: 70016
#include<stdio.h>
#include<cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>

typedef long long int ll;

#define BIG_NUM 2000000000

using namespace std;

struct Node {
    Node(int arg_to, int arg_cost) {
        to = arg_to;
        cost = arg_cost;
    }
    
    bool operator<(const struct Node &arg) const{
        return cost > arg.cost;
    };
    
    int to, cost;
};

int main() {
    int N;
    scanf("%d", &N);
    
    vector<Node> V[N];
    
    int node, num, to, cost, D[N];
    
    for(int loop = 0; loop < N; loop++) {
        scanf("%d", &node);
        scanf("%d", &num);
        
        for(int i = 0; i < num; i++) {
            scanf("%d %d", &to, &cost);
            V[node].push_back(Node(to, cost));
        }
        D[loop] = BIG_NUM;
    }
    
    D[0] = 0;
    
    priority_queue<Node> Q;
    
    for(int i = 0; i < V[0].size(); i++) {
        D[V[0][i].to] = V[0][i].cost;
        Q.push(Node(V[0][i].to, V[0][i].cost));
    }
    
    int min_index;
    
    while(!Q.empty()) {
        if(Q.top().cost == D[Q.top().to]) {
            min_index = Q.top().to;
            Q.pop();
        }else {
            Q.pop();
            continue;
        }
        
        for(int k = 0; k < V[min_index].size(); k++) {
            if(D[V[min_index][k].to] > D[min_index] + V[min_index][k].cost) {
                D[V[min_index][k].to] = D[min_index] + V[min_index][k].cost;
                Q.push(Node(V[min_index][k].to, D[V[min_index][k].to]));
            }
        }
    }
    
    for(int i = 0; i < N; i++) printf("%d %d\n", i, D[i]);
    
    return 0;
}


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


int main(){
    ll A,B;
    cin >> A >> B;
    ll sumA=0, sumB=0;
    
    if(A%2==0){
        if((A/2)%2==1){
            sumA=1;
        }else{
            sumA=0;
        }
    }else if(A%2==1){
        if((A/2)%2==1){
            sumA=1 ^ (A-1);
        }else{
            sumA=0 ^ (A-1);
        }
    }
    
    if(B%2==1){
        if((B/2)%2==1){
            sumB=0;
        }else{
            sumB=1;
        }
    }else if(B%2==0){
        if((B/2)%2==1){
            sumB=1 ^ B;
        }else{
            sumB=0 ^ B;
        }
    }
    ll ans = sumA ^ sumB;
    //cout << sumA << endl;
    //cout << sumB << endl;
    cout << ans << endl;

    
}



Measured memory_bytes: 256
// Contest: AtCoder Beginner Contest 150 (https://atcoder.jp/contests/abc150)
// Problem: B: Count ABC (https://atcoder.jp/contests/abc150/tasks/abc150_b)


// region {{{ boilerplate
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <chrono>
#include <cstdint>
#include <deque>
#include <exception>
#include <forward_list>
#include <functional>
#include <initializer_list>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#if __cplusplus >= 201703L
#   include <optional>
#   include <string_view>
#   include <variant>
#endif

using namespace std;

#if __cplusplus >= 201703L
#   define all(a)      begin(a),end(a)
#   define sz(x)       ((int)size(x))
#else
#   define all(a)      (a).begin(),(a).end()
#   define sz(x)       ((int)(x).size())
#endif

#define rep(a, b)      for(int a = 0; a < (b); ++a)
#define reps(a, b, c)  for(int a = (b); a < (c); ++a)
#define trav(a, b)     for(auto& a : b)

using ll = long long;
using ld = long double;
using u64 = uint64_t;
using u32 = uint32_t;

using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vpi = vector<pi>;

#if __cplusplus >= 201703L
#   define MAYBE_UNUSED [[maybe_unused]]
#else
#   define MAYBE_UNUSED
#endif

MAYBE_UNUSED static constexpr int INF = (int)1e9 + 5;
MAYBE_UNUSED static constexpr ll INFL = (ll)1e18 + 5;
MAYBE_UNUSED static mt19937 rng((u32)chrono::duration_cast<chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count());
//endregion }}}

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

    int n; string s; cin >> n >> s;
    int cnt = 0;
    rep(i, n - 2)
        if (s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C')
            ++cnt;
    cout << cnt << '\n';

    return 0;
}


Measured memory_bytes: 256
import copy

class Card:
    def __init__(self, mark_num):
        self.mark_num = mark_num
        self.mark = mark_num[0]
        self.num = int(mark_num[1:])

def bubble_sort(cards, n):
    flag = True
    while flag:
        flag = False
        for i in reversed(range(1, n)):
            if cards[i].num < cards[i-1].num:
                tmp = cards[i]
                cards[i] = cards[i-1]
                cards[i-1] = tmp
                flag = True
    
    # for c in cards:
    #     print(c.mark_num + " ", end="")

    mark_nums = []
    for c in cards:
        mark_nums.append(c.mark_num)

    print(" ".join(mark_nums))
    print("Stable")

    return cards

    # nums_str = map(str, nums)
    # print(" ".join(cards))
    # print(cards)

def selection_sort(cards, n):
    for i in range(n):
        minj = i
        flag = False
        for j in range(i, n-1):
            if cards[minj].num > cards[j+1].num:
                minj = j+1
                flag = True
        
        if flag:
            tmp = cards[i]
            cards[i] = cards[minj]
            cards[minj] = tmp

    mark_nums = []
    for c in cards:
        mark_nums.append(c.mark_num)

    print(" ".join(mark_nums))

    return cards

def is_stable(cards1, cards2, n):
    is_stable = True
    for i in range(n):
        if cards1[i].mark_num != cards2[i].mark_num:
            is_stable = False
            break

    if is_stable:
        print("Stable")
    else:
        print("Not stable")
    
#     nums_str = map(str, nums)
#     print(" ".join(nums_str))
#     print(count)

if __name__=="__main__":
    n = int(input())
    input_cards = list(input().split())
    card_list = []
    for input_card in input_cards:
        card = Card(input_card)
        card_list.append(card)

    cards_1 = bubble_sort(copy.deepcopy(card_list), n)
    cards_2 = selection_sort(copy.deepcopy(card_list), n)

    is_stable(cards_1, cards_2, n)



Measured memory_bytes: 6348
import Text.Printf

main = do
  l <- getLine
  let i = map read $ words l :: [Int]
      a = (i!!0) `div` (i!!1)
      b = (i!!0) `mod` (i!!1)
      c = (fromIntegral (i!!0)) / (fromIntegral (i!!1)) :: Double
  printf "%d %d %.5f\n" a b c

  

Measured memory_bytes: 3804
#include<stdio.h>


int main()
{
	int N, b,i;
        int MAX=0;
int MIN=1000;
	scanf("%d", &N);
	int a[1000];
	for (i = 0; i < N; i++) {
		scanf("%d", &a[i]);
	}
	for (i = 0; i < N; i++) {
		if (a[i] > MAX) {
MAX=a[i];
		}
if(a[i]<MIN){
MIN=a[i];
	}
}
printf("%d", MAX-MIN);
    return 0;
}



Measured memory_bytes: 128
#include <iostream>

using namespace std;

 

int main()
{
    int a, b;
    cin >> a >> b;
    if (a > b)
       cout << "a > b" << endl;
    else if (a < b)
       cout << "a < b" <<endl;
    else if (a == b)
       cout << "a == b" << endl;
     
    return 0;
}


Measured memory_bytes: 3084
#include<iostream>
#include<climits>
using namespace std;
int numStones,k;
int heights[100005],b[100005];
int main(){
	cin>>numStones>>k;
	for(int i=1;i<=numStones;i++){
	    cin>>heights[i];
	}
	b[0]=b[1]=0;
	for(int i=2;i<=numStones;i++){
		b[i]=INT_MAX;
		for(int j=1;j<=k&&j!=i;j++){
			b[i]=min(b[i],b[i-j]+abs(heights[i-j]-heights[i]));
		}
	}
	cout<<b[numStones];
	return 0;
}

Measured memory_bytes: 1024
#n = int(input())
#a, b = map(int,input().split())
#l = list(map(int,input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
a = str(input())
b = str(input())
if len(a) < len(b):
    ans = 'LESS'
elif len(a) > len(b):
    ans = 'GREATER'
else:
    n = len(a)
    ans = 'EQUAL'
    for i in range(n):
        if a[i] < b[i]:
            ans = 'LESS'
            break
        elif a[i] > b[i]:
            ans = 'GREATER'
            break
print(ans)


Measured memory_bytes: 9124
def resolve():
    n = int(input())
    a = list(map(int, input().split()))
    cuma = [0]
    for i in range(n):
        cuma.append(cuma[-1]+a[i])
    dict = {}
    for i in cuma:
        if i in dict:
            dict[i] += 1
        else:
            dict[i] = 1
    ans = 0    
    for i in dict:
        ans += dict[i]*(dict[i]-1)//2
    print(ans)
resolve()

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

static const int NMAX = 1000000;
static const int MMAX = 100;
static const int AMAX = 1e9;


void insertionSort(const int N, int A[], int g, int* cnt)
{
    for (int i=g; i < N; i++) {
        int v = A[i];
        int j = i - g;
        while (j >= 0 && A[j] > v) {
            A[j+g] = A[j];
            j = j - g;
            *cnt += 1;
        }
        A[j+g] = v;
    }
}

void shellSort(int N, int A[]) {
    int cnt = 0;
    int m = 0;
    int g = 1;
    int G[MMAX];
    
    while (1) {
        G[m] = g;
        m++;
        g = 3*g + 1;
        if ( g > N) break;
    }

    for (int i = m; i > 0; i--) {
        insertionSort(N, A, G[i-1], &cnt);
    }

    cout << m << endl;
    for (int i = m; i > 1; i--) {
        cout << G[i-1] << " ";
    }
    cout << G[0] << endl;
    cout << cnt << endl;
    for (int i = 0; i < N; i++) {
        cout << A[i] << endl;
    }
}

int main (void) {

    int N;
    int* A;

    cin >> N;
    A = new int[N];
    for (int i=0; i < N; i++) cin >> A[i];
    
    shellSort(N, A);
}



Measured memory_bytes: 6920
#include<bits/stdc++.h>
using namespace std;
const int N=110;
int n,a[N];
int main()
{
    cin>>n;
    int l=1e9,r=0;
    for(int i=1;i<=n;++i) cin>>a[i],l=min(l,a[i]),r=max(r,a[i]);
    int ans=2e9;
    for(int i=l;i<=r;++i)
    {
        int sur=0;
        for(int j=1;j<=n;++j) sur+=(a[j]-i)*(a[j]-i);
        ans=min(ans,sur);
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256