akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define h1 7897897897897897
#define h2 7897466719774591
#define b1 98762051
#define b2 98765431
#define inf 1000000000
#define pi 3.1415926535897932384626
#define LMAX 9223372036854775807
#define ll long long
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vp vector<pii>
#define SET(a, b) memset(a, b, sizeof(a));
#define all(x) (x).begin(), (x).end()
#define flush fflush(stdout)
#define debug printf("Hello\n")
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
int n, m, k, x, y, sum, cnt, a[200005], b[200005];
ll ans;
int f(int x) {
  if (x==0) return n;
  if (x==n+1) return 1;
  return x;
}
int main () {
  ios::sync_with_stdio(false);
  cin.tie(0);
  scanf("%d", &n);
  FOR(i, 1, n) {
    scanf("%d", &a[i]);
  }
  FOR(i, 1, n) {
    scanf("%d", &b[i]);
  }
  int i = 1, cnt = 0, tot = 0;
  while (true) {
    tot++;
    if (tot > 33*n) {
      printf("-1\n");
      return 0;
    }
    if (a[i] == b[i]) {
      cnt++;
      if (cnt == n) break;
      i=f(i+1);
      continue;
    }
    if (b[i] > b[f(i-1)] && b[i] > b[f(i+1)]) {
      m = a[i];
      int op = (b[i] - m) / (b[f(i-1)] + b[f(i+1)]);
      ans += op;
      b[i] -= op * (b[f(i-1)] + b[f(i+1)]);
      if (a[i] == b[i]) {
        cnt++;
        if (cnt==n) break;
      } else cnt = 0;
    } else cnt = 0;
    //FOR(j, 1, n) printf("%d ", b[j]);
    //printf(": %d %d\n", ans, cnt);
    i = f(i+1);
  }
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 1792
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn diff(x: i32, y: i32) -> i32 {
    if x > y {
        x - y
    } else {
        y - x
    }
}

use std::cmp::max;

fn main() {
    let n: usize = read();
    let mut xyh: Vec<Vec<i32>> = read_vec2(n);

    xyh.sort_by(|a, b| b[2].partial_cmp(&a[2]).unwrap());

    for cy in 0..101 {
        'l: for cx in 0..101 {
            let ch = xyh[0][2] + diff(xyh[0][0], cx) + diff(xyh[0][1], cy);
            for i in 1..n {
                if !(xyh[i][2] == max(0, ch - diff(cx, xyh[i][0]) - diff(cy, xyh[i][1]))) {
                    continue 'l;
                }
            }
            println!("{} {} {}", cx, cy, ch);
        }
    }
}


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

int main (){
  string s;
cin >> s;
 if(s.size()<4){
   cout << "No" << endl;
   return 0;
 }
if(s.at(0) != 'Y'||s.at(1) != 'A'||s.at(2) != 'K'||s.at(3) != 'I'){
  cout << "No" << endl;
  return 0;
}
else cout << "Yes" << endl;
}


Measured memory_bytes: 256
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = 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 size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


n, m = map(int, input().split())
p = list(map(int, input().split()))
s = [list(map(int, input().split())) for i in range(m)]

uf = UnionFind(n)
for x, y in s:
    uf.union(x-1, y-1)

ans = 0
for i in range(n):
    if uf.same(i, p[i]-1):
        ans += 1
print(ans)


Measured memory_bytes: 100844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 200000;

int n, a[N], b[N], c[N]; ll sum = 0;
// b[i] : i --> i + 1
// c[i] : i --> i + 2 

int main()
{
	scanf( "%d", &n );
	for( int i = 1; i <= n; i ++ ) 
		scanf( "%d", &a[i] );
	a[0] = a[n+1] = 0;
	
	for( int i = 0; i <= n; i ++ )
	{
		b[i] = abs( a[i] - a[i+1] );
		c[i] = abs( a[i] - a[i+2] );
		sum += b[i];
	}
	
	for( int i = 1; i <= n; i ++ )
	{
		ll ans = sum - b[i-1] - b[i];
		ans += c[i-1];
		printf( "%lld\n", ans );
	}
	
	return 0;
}

Measured memory_bytes: 2432
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <list>
#include <ctime>
#include <complex>
#include <bitset>
#include <tuple>

#define ff first
#define ss second

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

int main()
{
    ios::sync_with_stdio(false);
	cin.tie(0);
    
    int n,m;
    cin>>n>>m;
    int cnt[2]={0};
    for(int i=0; i<m; i++){
        cnt[i%2]+=1;
    }
    int l1=cnt[0]*2;
    int l2=cnt[1]*2+1;
    int c1=l1/2-1;
    int c2=l2/2+l1;
    for(int i=0; i<cnt[0]; i++) cout<<c1+1-i<<" "<<c1+i+2<<"\n";
    for(int i=0; i<cnt[1]; i++) cout<<c2-i<<" "<<c2+2+i<<"\n";

    return 0;
}


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

using namespace std;

typedef long long ll;
const int maxn = 132000;

int ch[maxn][2];
int len[maxn][2];
int son_cnt[maxn];

struct node {
  ll a, b;
  node(ll _a = 0, ll _b = 0) : a(_a), b(_b) {}
  bool operator<(const node& o) const { return a < o.a; }
} A[maxn * 20], tmp[maxn * 20];

int L[maxn], R[maxn];
int n, cnt;

void gb_Merge(int l_1, int r_1, int l_2, int r_2) {
  int l = l_1, k = l_1;
  while (l_1 <= r_1 && l_2 <= r_2)
    tmp[k++] = A[A[l_1] < A[l_2] ? l_1++ : l_2++];
  while (l_1 <= r_1) tmp[k++] = A[l_1++];
  while (l_2 <= r_2) tmp[k++] = A[l_2++];
  while (k > l) k--, A[k] = tmp[k];
}

void Merge(int x, int l, int r, ll lim) {
  int pl_1 = cnt + 1, pr_1 = cnt;
  ll mi = 1LL << 61;
  for (int i = L[l], j = L[r] - 1; i <= R[l]; i++) {
    while (j < R[r] && A[i].b + A[j + 1].a <= lim)
      j++, mi = mi < A[j].b ? mi : A[j].b;
    if (j < L[r]) continue;
    A[++pr_1] = node(A[i].a, mi);
  }
  cnt = pr_1;
  int pl_2 = cnt + 1, pr_2 = cnt;
  mi = 1LL << 61, swap(l, r);
  for (int i = L[l], j = L[r] - 1; i <= R[l]; i++) {
    while (j < R[r] && A[i].b + A[j + 1].a <= lim)
      j++, mi = mi < A[j].b ? mi : A[j].b;
    if (j < L[r]) continue;
    A[++pr_2] = node(A[i].a, A[j].b);
  }
  cnt = pr_2, L[x] = pl_1, R[x] = pr_2;
  if (L[x] > R[x]) return;
  gb_Merge(pl_1, pr_1, pl_2, pr_2);
  int Sum = 0;
  for (int i = L[x] + 1; i <= R[x]; i++) {
    if (A[i].b >= A[L[x] + Sum].b)
      continue;
    else
      ++Sum, A[L[x] + Sum] = A[i];
  }
  cnt = R[x] = L[x] + Sum;
}

void dfs(int x, ll lim) {
  if (!son_cnt[x]) {
    A[L[x] = R[x] = ++cnt] = node(0, 0);
    return;
  }
  int val = 0;
  L[x] = cnt + 1, R[x] = cnt;

  for(int type = 0; type <= 1; type++) {
    int now_son = ch[x][type];
    dfs(now_son, lim), val = len[x][type];
    if(L[now_son] > R[now_son]) return;
    for(int i = L[now_son]; i <= R[now_son]; i++)
      A[i].a += val, A[i].b += val;
  }

  Merge(x, ch[x][0], ch[x][1], lim);
}

bool check(ll lim) {
  cnt = 0, dfs(1, lim);
  return L[1] <= R[1];
}

int main() {
//  freopen("a.in", "r", stdin);
//  freopen("a.out", "w", stdout);
  scanf("%d", &n);
  ll mx = 0;
  for(int i = 2; i <= n; i++) {
    int f = 0, v = 0;
    scanf("%d%d", &f, &v);
    ch[f][son_cnt[f]] = i;
    len[f][son_cnt[f]] = v;
    son_cnt[f]++, mx += v;
  }
  ll l = 0, r = mx, res;
  while(l <= r) {
    ll mid = (l + r) >> 1;
    if(!check(mid)) l = mid + 1;
    else res = mid, r = mid - 1;
  }
  printf("%lld\n", res);
  return 0;
}


Measured memory_bytes: 89472
#include "bits/stdc++.h"
using namespace std;

int main()
{
    std::cin.sync_with_stdio(false);
    std::cin.tie(0);
    long long n;
    cin >> n;
    long long mi = numeric_limits<long long>::max() / 2;
    long long ans = 0;
    for(int i = 0; i < 5; i++){
        long long a;
        cin >> a;
        if(a < mi){
            mi = a;
        }
    }
    ans = 4 + ((n + mi - 1) / mi);
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int judge(int,int);

int memo[1000001];

int main(void){
  int n,m,i,count;

  for(i=0;i<1000001;i++)
    memo[i]=-1;
  
  memo[0]=1;
  memo[1]=0;

  while(scanf("%d",&n),n){
      scanf("%d",&m);

    count=0;
    for(i=n;i<=m;i++){
      if(judge(i,1)==0){
	memo[i]=0;
	count++;
      }
    }
    printf("%d\n",count);
  }
  return 0;
}

int judge(int x,int fg){

  if(x%2==0)judge(x/2,2);
  else if(x%3==0)judge(x/3,3);
  else if(x%5==0)judge(x/5,5);

  if(memo[x]==0){
    memo[x*fg]=0;
    return 0;
  }
  return memo[x]=1;
}

Measured memory_bytes: 4664
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i > 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;

void trace(int a[], int n) {
  REP(i, n) {
    if (i > 0) cout << " ";
    cout << a[i];
  }
  cout << endl;
}

int selectionSort(int a[], int n) {
  int count = 0;
  REP(i, n) {
    int minJ = i;
    FOR(j, i, n) {
      if (a[j] < a[minJ]) {
        minJ = j;
      }
    }
    if (i != minJ) {
      swap(a[i], a[minJ]);
      count++;
    }
  }
  return count;
}

int main() {
  int n;
  cin >> n;
  int a[n];
  REP(i, n) {
    cin >> a[i];
  }

  int count = selectionSort(a, n);
  trace(a, n);
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 3076
//Created by Kira

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

#define IOS cin.sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pii pair<int,int> 
#define pb push_back
#define vi vector<int> 
using ll = long long;

const int mod = 1e9 + 7;

ll pwr(ll a, ll b);
   



int main(){
   IOS

   int n; cin>>n;
   int a[200];

   int cnt = 0;
   for(int i = 1; i <= n; i++){
      cin>>a[i];
      if(i & 1){
         if(a[i] & 1){
            cnt++;
         }
      }
   }
   cout<<cnt<<"\n";






}

ll pwr(ll a, ll b){
   a %= mod;	//Remove mod if not required
   ll res = 1;
   while(b > 0){
   if(b&1) res = res * a % mod;
        a = a * a % mod;
   b >>= 1;
    }

    return res;
}



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

long long asd[100005];
long long dp[100005];
int z;

long long rekur(int a)
{
	if(a==z)return 0;
	if(dp[a]!=-1)return dp[a];
	dp[a]=0;
	long long temp;
	if(a+1<=z)
	{
		temp=asd[a+1]-asd[a];
		if(temp<0)temp=-temp;
		dp[a]=temp+rekur(a+1);
	}
	if(a+2<=z)
	{
		temp=asd[a+2]-asd[a];
		if(temp<0)temp=-temp;
		dp[a]=min(dp[a],temp+rekur(a+2));
	}
	return dp[a];
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	memset(dp,-1,sizeof(dp));
	cin>>z;
	for(int q=1;q<=z;q++)
	cin>>asd[q];
	long long ans=rekur(1);
	cout<<ans<<endl;
}

Measured memory_bytes: 6528
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix


H,W = map(int,input().split())
C = [list(map(int,input().split())) for _ in range(10)]
A = [list(map(int,input().split())) for _ in range(H)]
#print(C)
#print(A)

csr = csr_matrix(C)
SP = shortest_path(csr)
#print(SP)
#print(csr)
#print(shortest_path(csr))

dicA = {}
for i in range(H):
  for j in range(W):
    if A[i][j] != -1 and A[i][j] != 1:
      if A[i][j] in dicA:
        dicA[A[i][j]] += 1
      else:
        dicA[A[i][j]] = 1
#print(dicA)

ans = 0
for key,val in dicA.items():
  ans += SP[key][1] * val
print(int(ans))


Measured memory_bytes: 14096
#include <iostream>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
using namespace std;

int main ()
{
	int a, b, c;
	cin >> a >> b >> c;

	cout << (a < b && b < c ? "Yes" : "No") << endl;
	
	return 0;
}


Measured memory_bytes: 3088
H, W = map(int, input().split())
h, w = map(int, input().split())

# H = 2
# W = 4
#
# h = 1
# w = 3

h -= 1
w -= 1

panel = [[1] * W for i in range(H)]

cnt = H * W
for x in range(0, H):
    for y in range(0, W):
        if x <= h or y <= w:
            if 0 < panel[x][y]:
                panel[x][y] = 0
                cnt -= 1

# print(panel)
print(cnt)


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

int main(void)
{
    char s[7];
    cin >> s;
    if(s[0] == 'S'){
        cout << "Cloudy" << endl;
    }else if(s[0]=='C'){
        cout << "Rainy" << endl;
    }else
    {
        cout << "Sunny" << endl;
    }

    return 0;
}


Measured memory_bytes: 3556
#include <bits/stdc++.h>
using namespace std;
int convert_to_num(string s,int i1,int i2){
    int num =0;
    num = num*10 +(s[i1]-'0');
    num = num*10 +(s[i2]-'0');
    return num;
}
int main(){
   string s;
   cin >> s;
   //cout << convert_to_num(s,0,1) << " " << convert_to_num(s,2,3)<<endl;
   bool month1 = false,month2=false;
   int num1 = convert_to_num(s,0,1) , num2 = convert_to_num(s,2,3);
   if (num1>=1 && num1<=12) month1=true;
   if (num2>=1 && num2<=12) month2=true;
   if(month1&&month2){
        cout << "AMBIGUOUS"<<endl;
   }else if(month1){
    cout <<"MMYY"<<endl;
   }else if(month2){
    cout << "YYMM"<<endl;
   }else{
    cout <<"NA"<<endl;
   }

}


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

int main(){
	int n,m,l;
	cin>>n>>m>>l;
	long int A[100][100],B[100][100],C[100][100]={};
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cin>>A[i][j];
		}
	}
	
	for(int i=0;i<m;i++){
		for(int j=0;j<l;j++){
			cin>>B[i][j];
		}
	}
		
		for(int i=0;i<n;i++){
			for(int j=0;j<m; j++){
				for(int k=0;k<l;k++){
					C[i][k]+=A[i][j]*B[j][k];
					}
				}
			}
			
			for(int i=0;i<n;i++){
				for(int j=0;j<l;j++){
					if(j!=l-1)cout<<C[i][j]<<" ";
					else cout<<C[i][j]<<endl;
				}
			}
			
	return 0;
}


Measured memory_bytes: 3304
import Control.Monad
import Control.Applicative

main = do
        [n,m] <- map read.words<$>getLine
        unless (n == 0 && m == 0) $ do
            print $ josephLoop m [1..n]
            main

joseph :: Int -> [Int] -> [Int]
joseph _ [] = []
joseph m xs = let i = m `mod` length xs
                  (l,r) = splitAt i xs
               in if null l then init r
                            else r ++ init l

josephLoop m xs = if length xs == 1 then head xs
                                    else josephLoop m (joseph m xs)



Measured memory_bytes: 4216
import itertools
H,W,K=map(int,input().split())
c=[list(input()) for i in range(H)]
count=0
for bit_h in itertools.product([0,1],repeat=H):
    for bit_w in itertools.product([0,1],repeat=W):
        black=0
        for h,w in itertools.product(range(H),range(W)):
            if c[h][w]=="#" and bit_h[h]&1 and bit_w[w]&1:
                black+=1
        if black==K:
            count+=1
print(count)

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

int main() {
  long long N, A, B;
  cin >> N >> A >> B;
  long long S = A + B; //Sは1回の操作で並べる個数
  
  long long x = N / S;
  long long y = N % S;
  
  if (A == 0) {
    cout << 0 << endl;
  }
  
  else if (y <= A) {
    cout << x * A + y << endl;
  }
  
  else {
    cout << x * A + A << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <functional>

using namespace std;

int main(){
    int A, B;
    cin >> A >> B;

    if(A==B){
        cout << 0 << endl;
        return 0;
    }
    int K = (A+B)/2;
    if(A+B== 2*K){
        cout << K << endl;
        return 0;
    }
    cout << "IMPOSSIBLE" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,s,f) for(i=s;i<f;i++)
#define print(v) for(auto &z:v) cout<<z<<' ';cout<<'\n'
#define db cout<<"db: "
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define B begin()
#define E end()
#define all(v) v.B,v.E
#define sz(v) (int)((v).size())
#define vi vector<int>
#define vii vector<pair<int,int>>
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define clk1 clock_t start_time=clock()
#define clk2 cout<<(clock()-start_time)/(double)CLOCKS_PER_SEC
#define clean(arr) memset(arr,0,sizeof(arr))
#define mod 1000000007
#define mod2 998244353
#define space 500005
//<<fixed << setprecision(9)

int arr[space];
int cnt[space];
int distinct;

const int block_size=700;

struct Query
{
    int l, r, idx;
    bool operator<(Query other) const
    {
        if(l/block_size != other.l/block_size) return l<other.l;
        return ((l/block_size)&1) ? r<other.r : r>other.r ;
    }
};

void add(int& x)
{
    cnt[arr[x]]++;
    if(cnt[arr[x]]==1) distinct++;
}
void remove(int& x)
{
    cnt[arr[x]]--;
    if(cnt[arr[x]]==0) distinct--;
}

int main()
{
    int n,i,j,t;
    boost;

    cin>>n>>t;

    rep(i,1,n+1) cin>>arr[i];

    Query Q[t];
    int ans[t];
    rep(i,0,t)
    {
        int l,r;
        cin>>l>>r;
        Q[i]={l,r,i};
    }
    sort(Q,Q+t);

    int cur_l = 1;
    int cur_r = 0;
    
    for (Query q : Q)
    {
        while (cur_l > q.l) {
            cur_l--;
            add(cur_l);
        }
        while (cur_r < q.r) {
            cur_r++;
            add(cur_r);
        }
        while (cur_l < q.l) {
            remove(cur_l);
            cur_l++;
        }
        while (cur_r > q.r) {
            remove(cur_r);
            cur_r--;
        }
        ans[q.idx] = distinct;
    }

    rep(i,0,t)cout<<ans[i]<<'\n';

    return 0;
}


Measured memory_bytes: 15400
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstdio>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include <set>
#include <utility>
#include <functional>
using namespace std;
typedef pair<int, int> pii;
typedef pair<string, int> P;
typedef long long ll;
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
const int MAXN = 100000;
const int MAXE = 100000;
const int MAXV = 10000;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
struct UnionFind{
    vector<int> par,rank;
    UnionFind(int n):par(n),rank(n){
        for(int i=0;i<n;++i) par[i]=i;
    }
    int root(int x){
        if(par[x]==x) return x;
        return par[x]=root(par[x]);
    }
    void unite(int x,int y){
        int rx=root(x),ry=root(y);
        if(rx==ry) return ;
        if(rank[ry]>rank[rx]) par[rx]=ry;
        else par[ry]=rx;
        if(rank[rx]==rank[ry]) rank[rx]++;
    }
    bool same(int x,int y){
        return root(x)==root(y);
    }
};
int main(){
    int n,m;cin>>n>>m;
    UnionFind uf(n+m);
    for(int i=0;i<n;++i){
        int k;cin>>k;
        for(int j=0;j<k;++j){
            int l;cin>>l;--l;
            uf.unite(i,n+l);
        }
    }
    for(int i=0;i<n;++i){
        if(!uf.same(i,0)){
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
    return 0;
}

Measured memory_bytes: 4640
N,K = map(int,input().split())
A = list(map(int,input().split()))
for i in range(N):
    A[i] -= 1
path = []
now = 0
used = [False]*N
while not used[now]:
    path.append(now)
    used[now] = True
    now = A[now]

s = path.index(now)
loop_len = len(path) - s
if K < s:
    print(path[K] + 1)
else:
    print(path[(K-s)%loop_len + s] + 1)

Measured memory_bytes: 95152
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int H = scn.nextInt(), W = scn.nextInt(), K = scn.nextInt();
		char[][] cake = new char[H][W];
		int[][] cake_int = new int[H][W];
		scn.nextLine();
		for (int i = 0; i < H; i++) {
			char[] ch = scn.nextLine().toCharArray();
			cake[i] = ch;
		}
		int num = 1;
		int h = -1;
		int count = 0;
		for (int i = 0; i < H; i++) {
			int s = 0;
			int w = -1;
			int nw = 0;
			for (int j = 0; j < W; j++) {
				if (cake[i][j] == '#')
					s++;
			}
			count+=s;
			if(s==0)continue;
			while (s != 0) {
				if (s == 1) {
					for (int k = h+1; k <= ((count==K)?H-1:i); k++) {
						for (int j = w+1; j < W; j++) {
							cake_int[k][j] = num;
						}
					}
					num++;
				} else {
					for(int j=w+1;j<W;j++) {
						if(cake[i][j]=='#') {
							nw = j;
							break;
						}
					}
					for (int k = h+1; k <= ((count==K)?H-1:i); k++) {
						for (int j = w+1; j <= nw; j++) {
							cake_int[k][j] = num;
						}
					}
					num++;
					w=nw;
				}
				s--;
			}
			h=i;
		}

		Printer.printMatrix(cake_int);
	}

}

class Printer{
	static void printArrayLine(int[] a) {
		int N = a.length;
		for(int i = 0;i < N;i++) {
			System.out.print(a[i] + ((i==N-1)?"\n":" "));
		}
	}

	static void printMatrix(int[][] a) {
		int N = a.length;
		int M = a[0].length;
		for(int i = 0;i < N;i++) {
			printArrayLine(a[i]);
		}
	}
}


Measured memory_bytes: 42480
#import <iostream>
using namespace std;

int main() {
  int A, B, C;
  cin >> A >> B >> C;

  int i,k;
  k = A % B;
  for (i = 0; i <= B; i++) {
    if ((k * i) % B == C) {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
  return 0;
}


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

int main(){
    int N, x, y, z, i;
    cin >> N;
    int count[1000000];
    for (i=1; i<=N; i++){
        count[i]=0;
    }
    for (x=1; x<=100; ++x){
        for (y=1; y<=100; ++y){
            for (z=1; z<=100; ++z){
                count[x*x+y*y+z*z+x*y+x*z+y*z]++;
            }
        }
    }
    for (i=1; i<=N; ++i){
        cout << count[i] << endl;
    }
    return 0;
}


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

constexpr ll INF = ll(1e+18) + 1;

int main() {
    int l;
    long double edge;

    cin >> l;
    edge = l / 3.0;

    cout << fixed << setprecision(12) << pow(edge, 3) << endl;

    return 0;
}

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

#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



int main(){
  int N;
  cin >> N;
  int ans = INF;
  FOR(i, 1, N){
    int A = i, B= N-i;
    int sum = 0;
    while(A){
      sum += A % 10;
      A/= 10;
    }
    while(B){
      sum += B % 10;
      B/=10;
    }
    ans = min(ans, sum);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
input = Array.new(5){gets.to_i}
ans = []

def calc(w)
  tmp = w%10
  return tmp==0 ? 0 : (10-tmp)
end

input.permutation(5).to_a.each do |ary|
  ans << ary.inject([]) {|memo, w|
    memo + [w, calc(w)]
  }[0..-2].map.inject(:+)
end

p ans.min

Measured memory_bytes: 1788
#include <iostream>
#include <string>
using namespace std;
int main()
{
  string S;
  cin >> S;
  bool ans = false;
  for (int i = 0; i <= 2; i++) {
    if (S[i]==S[i+1]) ans = true;
  }
  if (ans) cout << "Bad" << endl;
  else cout << "Good" << endl;
  return 0;
}


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

int main()
{
  int i,  n, q, nq, t, x;
  fscanf(stdin, "%d %d", &n, &nq);
  int **queue = (int**)malloc(sizeof(int*)*n);
  int *head = (int*)malloc(sizeof(int)*n);
  int *tail = (int*)malloc(sizeof(int)*n);
  for (i=0; i<n; i++) {
    queue[i] = (int*)malloc(sizeof(int)*nq);
    head[i]=0;
    tail[i]=0;
  }
  
  for (i=0; i<nq; i++) {
    fscanf(stdin, "%d %d", &q, &t);
    switch (q) {
    case 0:
      fscanf(stdin, "%d", &x);
      queue[t][(tail[t]++ % nq)] = x;
      break;
    case 1:
      if (head[t]!=tail[t])
	printf("%d\n", queue[t][head[t] % nq]);
      break;
    case 2:
      //      if (head[t]%nq!=tail[t]%nq)
      if (head[t] != tail[t])
	head[t]++;
    }
  }
  return 0;
}



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

int main() {
  int h,w;
  cin >> h >> w;
  vector<vector<char>> a(h,vector<char>(w));
  vector<bool> h_flag(h,false),w_flag(w,false);

  //入力から配列を生成し、判定するためのフラグの配列も更新する
  for (int i = 0 ; i < h ; i++) {
    for (int j =0 ; j < w ; j++) {
      cin >> a.at(i).at(j);
      if (a.at(i).at(j)== '#') {
        h_flag.at(i)=true;
        w_flag.at(j)=true;
      }
    }
  }
  
  for (int i = 0 ; i < h ; i++) {
    if (h_flag.at(i) == true) {
      for (int j = 0 ; j < w ; j++) {
        if (w_flag.at(j) == true) {
          cout << a.at(i).at(j);
        }
      }
      cout << endl;
    }
  }
}

Measured memory_bytes: 256
while True:
    n = input().split()
    a,b = int(n[0]),int(n[2])
    if n[1] == '+':
        print(a + b)
    elif n[1] == '-':
        print(a - b)
    elif n[1] == '*':
        print(a * b)
    elif n[1] == '/':
        print(a // b)
    else:
        if n[1] == '?':
            break

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

using namespace std;

#define ll long long int
#define ld long double
#define MAX 200007
#define MOD 1000000007
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)

int main(){

    fast;

    ll a,b,c,k;
    cin >> a >> b >> c >> k;

    if(k<=a){
        cout << k << endl;
    }
    else if(k<=a+b){
        cout << a << endl;
    }
    else{
        cout << a - (k-(a+b)) << endl;
    }



}


//    cout << fixed << setprecision(2);


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

std::vector<bool> IsPrime;

bool isPrime(const unsigned n) {
    switch(n) {
    case 0:
    case 1:
        return false;
    case 2:
        return true;
    }

    if(n % 2 == 0) {
        return false;
    }

    for(unsigned i = 3; i * i <= n; i += 2) {
        if(n % i == 0) {
            return false;
        }
    }

    return true;
}

int main() {
    long long X;
    cin >> X;

    for(int i = X; i <= 1000000; ++i) {
        if(isPrime(i)) {
            cout << i << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
<?php

class Dice
{
  public $top = 0;
  public $bottom = 0;
  public $north = 0;
  public $east = 0;
  public $south = 0;
  public $west = 0;

  public function toNorth()
  {
    $t = $this->top;
    $this->top = $this->south;
    $this->south = $this->bottom;
    $this->bottom = $this->north;
    $this->north = $t;
  }

  public function toEast()
  {
    $t = $this->top;
    $this->top = $this->west;
    $this->west = $this->bottom;
    $this->bottom = $this->east;
    $this->east = $t;
  }

  public function toSouth()
  {
    $t = $this->top;
    $this->top = $this->north;
    $this->north = $this->bottom;
    $this->bottom = $this->south;
    $this->south = $t;
  }

  public function toWest()
  {
    $t = $this->top;
    $this->top = $this->east;
    $this->east = $this->bottom;
    $this->bottom = $this->west;
    $this->west = $t;
  }

  public function spin()
  {
    $n = $this->north;
    $this->north = $this->west;
    $this->west = $this->south;
    $this->south = $this->east;
    $this->east = $n;
  }

  public function toBottom()
  {
    $this->toNorth();
    $this->toNorth();
  }

  public function toTop($x)
  {
    if ($x == $this->north) $this->toSouth();
    elseif ($x == $this->east) $this->toWest();
    elseif ($x == $this->south) $this->toNorth();
    elseif ($x == $this->west) $this->toEast();
    elseif ($x == $this->bottom) $this->toBottom();
  }
}

$dice = new Dice();
$n = explode(" ", trim(fgets(STDIN)));
$dice->top = $n[0];
$dice->south = $n[1];
$dice->east = $n[2];
$dice->west = $n[3];
$dice->north = $n[4];
$dice->bottom = $n[5];

$q = trim(fgets(STDIN));

for ($i = 0; $i < $q; $i++) {
  list($a, $b) = explode(" ", trim(fgets(STDIN)));
  $dice->toTop($a);
  while ($b != $dice->south) $dice->spin();
  echo $dice->east . "\n";
}



Measured memory_bytes: 9340
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <iomanip>
#include <algorithm>
using namespace std;

#define int long long

int n, m[4001], k;
string s;
vector<int> a;

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

    cin >> n;

    for (int i = 0; i < n; ++i) {
        cin >> s;
        s.erase(1, 1);
        //cout << s << stoi(s) << endl;
        k = stoi(s);
        m[k]++;
        a.push_back(k);
    }

    for (int i = 1; i <= 4000; i++) {
        m[i] = m[i] + m[i - 1];
    }

    for (int i = 0; i < n; ++i) {
        //cout << m[a[i]] << endl;
        cout << (m[a[i]] - m[a[i] - 1] - 1) + 3 * m[a[i] - 1] << "\n";
    }

    return 0;
}

Measured memory_bytes: 3876
#include "bits/stdc++.h"
using namespace std;

int main(){
  int h,w;
  cin>>h>>w;
  vector<string> a(h);
  for(int i=0;i<h;i++)cin>>a[i];

  vector<int> t(h,1);
  for(int i=0;i<h;i++){
    int f=0;
    for(int j=0;j<w;j++){
      if(a[i][j]=='#')f=1;
    }
    if(f==0)t[i]=0;
  }

  vector<int> y(w,1);
  for(int i=0;i<w;i++){
    int f=0;
    for(int j=0;j<h;j++){
      if(a[j][i]=='#')f=1;
    }
    if(f==0)y[i]=0;
  }

  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(t[i]&&y[j])cout<<a[i][j];
    }
    if(t[i])cout<<endl;
  }

}


Measured memory_bytes: 256
import java.util.*;

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

    char[] arr = scan.next().toCharArray();
    int n = scan.nextInt();

    for(int i = 0; i < arr.length-1; i++) {
      int dummy = 'z'+1-arr[i];
      if(dummy <= n && arr[i]!='a') {
        n -= dummy;
        arr[i] = 'a';
      }
    }
    
    arr[arr.length-1] = (char)(arr[arr.length-1] + (char)(n%26));
    if(arr[arr.length-1]> 'z') arr[arr.length-1] -= (char)26;

    System.out.println(arr);
  }
}


Measured memory_bytes: 13692
#include<bits/stdc++.h>
using namespace std;
#define de_x(x) cout<<"debug_val: "<<x<<endl;
#define de_ve(x) for(auto it: x) cout<<it<<" ";
#define rep(i,a,n) for (int i=a;i<n;i++)
#define _rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef double db;
std::mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x ; }
const ll MOD=1e9 +7;
ll ksm(ll a,ll b) {ll res=1;a%=MOD; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
int _;
/***********************/
void run(){
}
const int N = 4e5+5;
ll f[N],invf[N];
ll Con(int n ,int m){
	return f[n]*invf[n-m]%MOD*invf[m]%MOD;
}
int n , k;
int main(){
//	for(scanf("%d",&_); _;_--) run();	
	f[0] = invf[0] = f[1]= invf[1] =1;
	for(int i=2 ;i<N;i++){
		f[i] = f[i-1]*i%MOD;
		invf[i] =(MOD -MOD /i)*invf[MOD%i]%MOD;
	}
	for(int i =2 ;i<N;i++) invf[i] =invf[i-1]*invf[i]%MOD;
	cin>>n>>k;
	ll ans =0;
	for(int i=0;i<=n&&i<=k;i++)
		ans = (ans+Con(n,i)*Con(n-1,i)%MOD)%MOD;
	ans = (ans%MOD +MOD)%MOD;
	cout<<ans<<endl; 
	return 0;
}


Measured memory_bytes: 6528
s = input()

if s == "SUN":
    print(7)
if s == "MON":
    print(6)
if s == "TUE":
    print(5)
if s == "WED":
    print(4)
if s == "THU":
    print(3)
if s == "FRI":
    print(2)
if s == "SAT":
    print(1)


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

int main() {
  long N;
  cin >> N;
  vector<long> A(N);
  for (long i = 0; i < N; i++) cin >> A.at(i);
  long now = 1000, k = 0;
  for (long i = 0; i + 1 < N; i++) {
    if (A.at(i + 1) > A.at(i)) {
      k += now / A.at(i);
      now %= A.at(i);
      continue;
    }
    now += k * A.at(i);
    k = 0;
  }
  cout << now + k * A.at(N - 1) << "\n";
}

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    deque<int> d;
    if(n == 1) {
        cout<< a[0] << endl;
        return 0;
    }
    else if(n == 2) {
        cout << a[1] << ' ' << a[0] << endl;
        return 0;
    }
    else if(n % 2 == 0) {
        d.push_back(a[1]);
        d.push_back(a[0]);
        for(int i = 2; i < n; i++) {
            i % 2 == 0 ? d.push_back(a[i]) : d.push_front(a[i]);
        }
    }
    else {
        d.push_back(a[0]);
        for(int i = 1; i < n; i++) {
            i % 2 == 0 ? d.push_front(a[i]) : d.push_back(a[i]);
        }
    }
    rep(i, n) cout << d[i] << ' ';
}


Measured memory_bytes: 4824
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>

using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = ((ll)(x) - 1); i >= 0; i--)

#define _upgrade ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
//ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}
/*bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}*/

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

const ll mod = 1e9 + 7;
const ll IMF = 1LL<<29;
const double PI = 3.14159265358979323846;


// ******************************CODE**********************************//




int a,b,c,x,y;

int main(){
        cin >> a >> b >> c >> x >> y;

        int sum = 1e9;
        for(int i = 0; i < 100001; i++){
                int tmp = 2*c*i + a*(max(x-i,0)) + b*(max(y-i,0));
                chmin(sum,tmp);
        }

        cout << sum << endl;
        return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"
vector<int>topo_sort(const vector<vector<int>>&edges) {
	int size_ = edges.size();
	vector<int>nums(size_);	
	for(const auto& es:edges){
		for (auto e : es) {
			nums[e]++;
		}
	}
	queue<int>que;
	for (int i = 0; i < size_; ++i) {
		if (!nums[i]) {
			que.push(i);
		}
	}
	vector<int>topo;
	while (!que.empty()) {
		int ver(que.front());
		topo.push_back(ver);
		que.pop();
		for (auto e : edges[ver]) {
			nums[e]--;
			if (!nums[e])que.push(e);
		}
	}
	if (topo.size() == size_)return topo;
	else return vector<int>();
}
int main() {
	int V, E; cin >> V >> E;
	vector<vector<int>>edges(V);
	for (int i = 0; i < E; ++i) {
		int s, t; cin >> s >> t;
		edges[s].push_back(t);
	}
	auto vs=topo_sort(edges);
	cout << int(vs.empty()) << endl;
	return 0;
}

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



int main() {
	int n;
	scanf("%d", &n);
	int x, need = 1;
	for (int i = 0; i < n; ++i) {
		scanf("%d", &x);
		if (x == need) {
			++need;
		}
	}
	--need;
	int ans = n - need;
	if (!need) ans = -1;
	printf("%d\n", ans);
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define MOD 1000000007
#define ALL(a) (a).begin(),(a).end()
#define ms(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(10) 
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef long long ll;
struct edge
{
	int from, to, cost;
	bool operator < (const edge& e) { return cost < e.cost; }
	bool operator > (const edge& e) { return cost > e.cost; }
};
///************************************************************///
///************************************************************///
///************************************************************///

int login[10005][1300];
struct data{ int t, n, m, s; };

int main()
{
	int n, m;
	while (cin >> n >> m, n)
	{
		int r, q;
		ms(login, 0);
		queue<data> que;
		cin >> r;
		REP(i, r)
		{
			int a, b, c, d;
			cin >> a >> b >> c >> d;
			c--;
			que.push(data{a,b,c,d});
		}

		FOR(i, 1, 1261)
		{
			REP(j, m)
			{
				login[j][i] = login[j][i - 1];
			}
			while (!que.empty()&&que.front().t == i)
			{
				login[que.front().m][i] += (que.front().s == 1 ? 1 : -1);
				que.pop();
			}
		}
		cin >> q;
		REP(i, q)
		{
			int ans = 0;
			int a, b, c;
			cin >> a >> b >> c;
			c--;
			FOR(j, a, b)
			{
				if (login[c][j] > 0)
				{
					ans++;
					//cout <<"j="<< j << endl;
				}
			}
			cout << ans << endl;
		}

	}
	return 0;
}

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

#define rep(x, y) for (int i = (x); i < (y); i++)

typedef long long ll;

using namespace std;

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

    int cnt = 0;
    for (int i = 1; i <= k; i++) {
        for (int j = 1; j <= k; j++) {
            if (i % 2 == 0 && j % 2 != 0) cnt++;
        }
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MN = 1e5 + 5;
int N;

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> N;
    priority_queue<double, vector<double>, greater<>> q;
    for (int i = 0, v; i < N; i++) cin >> v, q.push(v);
    while (q.size() > 1) {
        double a = q.top();
        q.pop();
        double b = q.top();
        q.pop();
        q.push((a + b) / 2);
    }
    cout << fixed << setprecision(5) << q.top() << '\n';
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<utility>
#include<queue>

#define rep(i,x) for(ll i=0;i<(int)(x);i++)
#define reps(i,x) for(ll i=1;i<=(int)(x);i++)
#define rrep(i,x) for(ll i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(ll i=((int)(x));i>0;i--)

#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define INF 2e9

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

using namespace std;

int main()
{
    ll n;
    cin >> n;
    vector<string> v(n);
    rep(i, n){
        cin >> v[i];
    }

    ll a1 = 0;
    ll a2 = 0;
    ll b1 = 0;
    ll b2 = 0;
    ll ab = 0;
    ll p = 0;
    rep(i, n){
        string s = v[i];
        if(s[s.size()-1] == 'A') {
            a1++;
            if(s[0] == 'B') ab++;
            else a2++;
        }
        if(s[0] == 'B'){
            b1++;
            if(s[s.size()-1] != 'A') b2++;
        }

        rep(j, s.size()-1){
            if(s[j] == 'A' && s[j+1] == 'B') p++;
        }
    }
    ll q = min(a1, b1);
    if (a2==0 && b2==0){
        if(ab > 0){
            if(q > 0) q--;
            else q = 0;
        }
    }
    ll ans = p + min(q, n-1);
    cout << ans;
}


Measured memory_bytes: 768
/* --- author: dxm --- */
#include<bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;

#define INF 1e9
#define Inf 1e18
#define rep(i,n) for(int (i)=0;(i)<n;i++)
#define REP(i,n) for(int (i)=1;(i)<=n;i++)
#define mp make_pair
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;

void qread(int &x){
	int neg=1;x=0;
	char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')neg=-1;c=getchar();}
	while(c>='0'&&c<='9')x=10*x+c-'0',c=getchar();
	x*=neg;
}

int main(){
#ifdef FILE
	freopen("FILE.in","r",stdin);
	freopen("FILE.out","w",stdout);
#endif
	ll a,b,c;
	cin>>a>>b>>c;
	cout<<b+min(c,a+b+1);
#ifdef TIME
	printf("Running Time = %d ms\n",int(clock()*1000.0/CLOCKS_PER_SEC));
#endif
	return 0;
}

/*
Input:
-----------------
Output:
*/


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

using namespace std;

// Common DS shorteners
using ll = long long; using ull = unsigned long long;
using pii = pair<int, int>; using pll = pair<ll, ll>;
template <typename T> using vec = vector<T>;
template <typename K, typename V> using mp = unordered_map<K, V>;
template <typename K> using us = unordered_set<K>;
using vi = vec<int>; using vl = vec<ll>; using vpi = vec<pii>; using vpl = vec<pll>;
// Shorthand Macros
#define INF 0x3f3f3f3f
#define LLINF 0x3f3f3f3f3f3f3f3f
#define mpr make_pair
#define pb push_back
// Shorthand Functions
template<typename T> inline void maxa(T& st, T v) { st = max(st, v); }
template<typename T> inline void mina(T& st, T v) { st = min(st, v); }
// Out operators and printing for arrays and vectors
template <typename T> ostream& operator<<(ostream& out,vector<T> iter){out<<"[";for(auto t:iter){out<<t<<", ";}out<<"]";return out;}
template <typename T> void printDebug(T *arr,int sz){cout<<"[";for(int i=0;i<sz;i++){cout<<arr[i]<<", "; } cout<<"]\n";}
template <typename T> void printArray(T *arr,int sz){for(int i=0;i<sz;i++){cout<<arr[i]<<" "; } cout<<"\n";}
#define OUT_OPERATOR(type, propa, propb) ostream& operator<<(ostream& out,type obj){out<<"("<<#propa<<"="<<obj. propa<<", "<<#propb<<"="<<obj. propb<<")";return out;}
// I/O Operations
inline void scan(){}
template<typename F, typename... R> inline void scan(F &f,R&... r){cin>>f;scan(r...);}
inline void println(){cout<<"\n";}
template<typename F, typename... R> inline void println(F f,R... r){cout<<f<<" ";println(r...);}
inline void print(){}
template<typename F, typename... R> inline void print(F f,R... r){cout<<f;print(r...);}
// Debugging
int di_; string dnms_, co_ = ",";
void debug_(){cout<<endl;}
template<typename F, typename... R>
void debug_(F f,R... r){int bc=0;while (bc != 0 || dnms_[di_] != ','){if (dnms_[di_] == '(') {bc++;}else if (dnms_[di_] == ')') {bc--;}cout << dnms_[di_++];}di_++;cout << ": " << f << ",";debug_(r...);}
#define debug(...) do{dnms_=#__VA_ARGS__+co_,di_=0,debug_(__VA_ARGS__);}while(0)

int n;
double buf, ans;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    scan(n);

    for (int i = 0; i < n; i++) {
        scan(buf);
        ans += 1. / buf;
    }

    ans = 1. / ans;
    cout << fixed << setprecision(10) << ans << "\n";

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>

using namespace std;
int main(){
	int k; cin>>k;
	for(int i = 0; i < k; i++){
		cout<<"ACL";
	}
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;

const int INF = 1e9;
const int mod = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1.0);

int main()
{
    int n,k;
    cin >> n >> k;
    cout << (n%k ? 1 : 0) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define SZ(x) (int)(x).size()
#define endl '\n'
#define FOR(a, b, c) for (auto a = (b); (a) < (c); ++(a))
#define F0R(a, b) FOR (a, 0, (b))
#define CEIL(a, b) ((a) + (b)-1) / (b)
template <class T>
bool ckmin(T& a, const T& b) {
  return a > b ? a = b, true : false;
}
template <class T>
bool ckmax(T& a, const T& b) {
  return a < b ? a = b, true : false;
}
#ifndef DEBUG
#define DEBUG 0
#endif
#define dout \
  if (DEBUG) std::cerr
#define dvar(...) " [" << #__VA_ARGS__ ": " << mt(__VA_ARGS__) << "] "
template <typename T>
struct IsC {
  template <typename C>
  static char test(typename C::const_iterator*);
  template <typename C>
  static int test(...);
  static const bool value = sizeof(test<T>(0)) == sizeof(char);
};
template <>
struct IsC<string> {
  static const bool value = false;
};
template <typename C>
typename enable_if<IsC<C>::value, ostream&>::type operator<<(ostream&, const C&);
template <typename T1, typename T2>
ostream& operator<<(ostream&, const pair<T1, T2>&);
template <typename... T> using TS = tuple_size<tuple<T...>>;
template<size_t idx, typename... T>
typename enable_if<TS<T...>::value == idx + 1, ostream&>::type
operator<<(ostream& o, const tuple<T...>& t) {
  return o << ", " << get<idx>(t) << ')';
}
template<size_t idx, typename... T>
typename enable_if<0 < idx && idx + 1 < TS<T...>::value, ostream&>::type
operator<<(ostream& o, const tuple<T...>& t) {
  return operator<<<idx + 1>(o << ", " << get<idx>(t), t);
}
template<size_t idx = 0, typename... T>
typename enable_if<1 < TS<T...>::value && !idx, ostream&>::type
operator<<(ostream& o, const tuple<T...>& t) {
  return operator<<<idx + 1>(o << '(' << get<idx>(t), t);
}
template<typename T>
ostream& operator<<(ostream& o, const tuple<T>& t) {
  return o << get<0>(t);
}
template <typename T1, typename T2>
ostream& operator<<(ostream& o, const pair<T1, T2>& p) {
  return o << mt(p.fi, p.se);
}
template <typename C>
typename enable_if<IsC<C>::value, ostream&>::type operator<<(
    ostream& o, const C& c) {
  o << '[';
  for (auto it = c.cbegin(); it != c.cend(); ++it)
    o << *it << (next(it) != c.cend() ? ", " : "");
  return o << ']';
}
template <typename T>
void tprint(vector<vector<T>>& v, size_t width = 0, ostream& o = cerr) {
  if (!DEBUG) return;
  for (const auto& vv : v) {
    for (const auto& i : vv) o << setw(width) << i;
    o << endl;
  }
}

int main() {
  ios_base::sync_with_stdio(0);
  cout.tie(0); cin.tie(0);

  string n; cin >> n;
  ll sum = 0;
  for (char c : n) sum += c - '0';
  cout << (sum % 9 ? "No" : "Yes") << endl;
  
  return 0;
}


Measured memory_bytes: 3740
S = input()
if S[0] != "A":
    print("WA")
else:
    l = [x for x in S[2:-1] if x == "C"]
    if len(l) != 1:
        print("WA")
    else:
        i = S.index("C")
        for x in S[1:i]+S[i+1:]:
            if not x.islower():
                print("WA")
                exit()
        else:
            print("AC")


Measured memory_bytes: 3060
import java.util.*;
//System.out.println("")

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int n = s.length();
        String ss[]= s.split("");
        
        
        int cnt = 0;
        int gnt = 0;
        for(int i = 0; i<n; i+=2){
            if(ss[i].equals("0")){
                ss[i]="1";
                cnt++;
            }
        }
        for(int i = 1; i<n; i+=2){
            if(ss[i].equals("1")){
                ss[i]="0";
                cnt++;
            }
        }
        String rr[]=s.split("");
        
        for(int i = 1; i<n; i+=2){
            if(rr[i].equals("0")){
                rr[i]="1";
                gnt++;
            }
        }
        for(int i = 0; i<n; i+=2){
            if(rr[i].equals("1")){
                rr[i]="0";
                gnt++;
            }
        }
        cnt = Math.min(gnt,cnt);
        System.out.println(cnt);
    }
}

Measured memory_bytes: 39052
import heapq
N , M =map(int,input().split())
L = [[] for _ in range(M + 1)]

for i in range(N):
  a,b = map(int,input().split())
  if a <= M:
    L[M - a].append(-b)

work = []
heapq.heapify(work)
ans = 0

for i in range(M,-1,-1):
  for j in range(len(L[i])):
    heapq.heappush(work,L[i][j])
  if len(work) > 0:
    ans -= heapq.heappop(work)

print(ans)


Measured memory_bytes: 17604