akhauriyash/Code-Regression huggingface dataset:
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

ll mod(ll a){
  return a % 1000000007;
}


int main(){
  ll n; cin >> n; map<string,ll> table;
  
  
  for(ll i=0; i < n; i++){
    string s; cin >> s;
    
    if(table.count(s)) table[s]++;
    else table[s] = 1;
  }
  

  ll maxvote = 0;
  
  for(auto p : table){
    ll vote = p.second;
    maxvote = max(vote,maxvote);
  }
  
  
  for(auto p : table){
    if(p.second == maxvote) cout << p.first << endl;
  }
  
}

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

namespace abc_060_B
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            bool flag = false;
            for (int i = 1; i <= a[1] ; i++)
            {
                if ((i * a[0]) % a[1] == a[2]) { flag = true; break; }
            }
            Console.WriteLine(flag ? "YES" : "NO");
            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 13396
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int h = Integer.parseInt(in.next());
            int w = Integer.parseInt(in.next());
            int k = Integer.parseInt(in.next());
            char[][] c = new char[h][w];
            for (int i = 0; i < h; i++) {
                c[i] = in.next().toCharArray();
            }
            int ans = 0;

            // {0, 1, ..., n-1} の部分集合の全探索
            for (int bith = 0; bith < (1 << h); ++bith) {
                for (int bitw = 0; bitw < (1 << w); ++bitw) {
                    /* bit で表される集合の処理を書く */

                    int black = 0;
                    for (int i = 0; i < h; i++) {
                        if ((bith & (1 << i)) == 0) continue;
                        for (int j = 0; j < w; j++) {
                            if ((bitw & (1 << j)) == 0) continue;
                            if (c[i][j] == '#') black++;
                        }
                    }
                    if (black == k) ans++;
                }
            }

            // 出力
            out.println(ans);

        }

    }
}



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


string s,t,k;
int main()
{
	bool q=true;
	int a,b;
	cin>>s>>t;
	scanf("%d%d",&a,&b);
	cin>>k;
	for(int i=0;i<=s.size();i++)
	{
		if(s[i]==k[i]) continue;
		q=false;
	}
	if(q)
	printf("%d %d",--a,b);
	else printf("%d %d",a,--b);
	return 0;
 } 

Measured memory_bytes: 256
// Problem : C - Fennec vs Monster
// Contest : AtCoder - AtCoder Beginner Contest 153
// URL : https://atcoder.jp/contests/abc153/tasks/abc153_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

//Macros

#define ll long long
#define db long double
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int,int>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define inf 1e10
#define PI acos(-1.0)
#define int long long
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define N 100005

//Solution

void solve(){
    int n,k;
    cin>>n>>k;
    vi a(n);
    for(int &i : a) cin>>i;
    sort(all(a));
    int cnt = 0, ans = 0;
    for(int i=n-1;i>=0;i--){
        if(cnt < k);
        else ans += a[i];
        cnt++;
    }
    cout<<ans<<endl;
}

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    int tests;
    //cin>>tests;
    tests = 1;
    while(tests--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,s,n) for(int i = (s); i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()



int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll n, k;
  cin >> n >> k;
  
  vector<ll> a(n);
  vector<ll> b(n);
  map<ll, ll> m;
  rep(i, 0, n) {
    cin >> a[i] >> b[i];
    m[a[i]] += b[i];
  }
  
  ll sum = 0;
  for(auto p : m) {
    sum += p.second;
    if(sum >= k) {
      cout << p.first << "\n";
      return 0;
    }
  }
}


Measured memory_bytes: 5760
#[allow(dead_code)]
fn getline() -> String {
    let mut res = String::new();
    std::io::stdin().read_line(&mut res).ok();
    res
}

#[allow(unused_macros)]
macro_rules! readl {
    ($t: ty) => {
        {
            let s = getline();
            s.trim().parse::<$t>().unwrap()
        }
    };
    ($( $t: ty),+ ) => {
        {
            let s = getline();
            let mut iter = s.trim().split(' ');
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
}

#[allow(unused_macros)]
macro_rules! readlvec {
    ($t:ty) => {{
        let s = getline();
        let iter = s.trim().split(' ');
        iter.map(|x| x.parse().unwrap()).collect::<Vec<$t>>()
    }};
}

#[allow(unused_macros)]
macro_rules! debug {
    ($x:expr) => {
        println!("{}: {:?}", stringify!($x), $x)
    };
}
// macro_rules! debug { ($x: expr) => () }

#[allow(dead_code)]
fn show<T>(iter: T) -> String
where
    T: Iterator,
    T::Item: std::fmt::Display,
{
    let mut res = iter.fold(String::new(), |sum, e| sum + &format!("{} ", e));
    res.pop();
    res
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::btree_map::Entry::{Occupied, Vacant};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

fn main() {
    use std::io::Write;
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    macro_rules! printf { ($($arg:tt)*) => (write!(out, $($arg)*).unwrap()); }
    macro_rules! printfln { () => (writeln!(out).unwrap()); ($($arg:tt)*) => (writeln!(out, $($arg)*).unwrap()); }

    let (n, c) = readl!(usize, usize);
    let d: Vec<_> = (0..c).map(|_| readlvec!(i64)).collect();

    let cv: Vec<Vec<_>> = (0..n)
        .map(|_| readlvec!(i64).into_iter().map(|x| x - 1).collect())
        .collect();

    let mut cov = vec![vec![0; c]; 3];
    for (i, row) in cv.iter().enumerate() {
        for (j, &e) in row.iter().enumerate() {
            cov[(i + j) % 3][e as usize] += 1;
        }
    }
    let cov = cov;

    let inf = 1_000_000_000_000;
    let mut ans = inf;
    for c0 in 0..c {
        for c1 in 0..c {
            for c2 in 0..c {
                if c0 == c1 || c1 == c2 || c0 == c2 {
                    continue;
                }
                let ccv = [c0, c1, c2];
                let mut cost = 0;
                for (cr, &cce) in cov.iter().zip(ccv.iter()) {
                    for (&ce, dr) in cr.iter().zip(d.iter()) {
                        // unsafe {
                        //     cost += ce * dr.get_unchecked(cce);
                        // }
                        cost += ce * dr[cce];
                    }
                }
                ans = min(ans, cost);
            }
        }
    }
    printfln!("{}", ans);
}


Measured memory_bytes: 6396
#include <bits/stdc++.h>
#define LL long long int
#define Max(x, y) (x > y ? x : y)
#define Min(x, y) (x < y ? x : y)
#define Abs(x) ( (x) > 0 ? (x) : -(x) )
#define Swap(x,y) do{x = x ^ y; y = x ^ y; x = x ^ y;}while(0)
#define IO_BOOST                      \
    ios_base::sync_with_stdio(false); \
    cin.tie(0)
#define setp(x) fixed << setprecision(x)
#define INF 0x3f3f3f3f
#define Lowbit(x) ((x) & (-x))
#define Pii pair<int, int>
#define x first
#define y second
#define MOD ((int)1e9+7)
using namespace std;

string s, t;
int dp[3001][3001];
int backt[3001][3001];
void solve(){
    
    for(int i = 0 ; s[i] ; i++){
        for(int j = 0 ; t[j] ; j++){
            if( s[i] == t[j] ){
                dp[i+1][j+1] = dp[i][j] + 1, backt[i+1][j+1] = 3;
            }else{
                if( dp[i][j+1] >= dp[i+1][j] ){
                    dp[i+1][j+1] = dp[i][j+1];
                    backt[i+1][j+1] = 1;
                }else{
                    dp[i+1][j+1] =  dp[i+1][j];
                    backt[i+1][j+1] = 2;
                }
            }
                
        }
    }
    
    int x = s.length(), y = t.length();
    string ans;
    while( x > 0 && y > 0 ){
        if( backt[x][y] == 3 ){
            ans.push_back(s[x-1]);
            x--, y--;
        }else if( backt[x][y] == 2 ){
            y--;
        }else if( backt[x][y] == 1 ){
            x--;
        }else{
            break;
        }
    }
    reverse(ans.begin(), ans.end());
    cout << ans << '\n';
    

   
}
int main(){
    IO_BOOST;
    cin >> s >> t;
    solve();

}

Measured memory_bytes: 70656
const EPS: f64 = 1e-7;

fn main() {
	let mut s = String::new();
	use std::io::Read;
	std::io::stdin().read_to_string(&mut s).unwrap();
	let mut s = s.split_whitespace();
	let n: usize = s.next().unwrap().parse().unwrap();
	let k: usize = s.next().unwrap().parse().unwrap();
	let b: Vec<_> = (0..n).map(|_| (s.next().unwrap().parse::<f64>().unwrap(), s.next().unwrap().parse::<f64>().unwrap(), s.next().unwrap().parse::<f64>().unwrap())).collect();

	let mut l = 0.;
	let mut r = 1e7;
	for _ in 0..256 {
		let mid = (l + r) / 2.;

		if check(mid, k, &b) {
			r = mid;
		} else {
			l = mid;
		}
	}
	println!("{:9}", l);
}

fn check(t: f64, k: usize, b: &Vec<(f64, f64, f64)>) -> bool {
	let mut point = vec![];

	for i in 1..b.len() {
		for j in 0..i {
			let (x1, y1, r1) = (b[i].0, b[i].1, t / b[i].2);
			let (x2, y2, r2) = (b[j].0, b[j].1, t / b[j].2);
			let (dx, dy) = (x2 - x1, y2 - y1);
			let dd = dx * dx + dy * dy;
			if dd == 0. {
				continue;
			}
			let ad = (dd + r1 * r1 - r2 * r2) / 2.;
			let h = dd * r1 * r1 - ad * ad;
			if h <= 0. {
				continue;
			}
			let h = h.sqrt();
			let x3 = x1 + ad * dx / dd;
			let x4 = h * dy / dd;
			let y3 = y1 + ad * dy / dd;
			let y4 = h * dx / dd;
			point.push((x3 + x4, y3 - y4));
			point.push((x3 - x4, y3 + y4));
		}
	}

	for &(x, y, _) in b.iter() {
		point.push((x, y));
	}

	for (px, py) in point {
		let mut cnt = 0;
		for &(x, y, c) in b.iter() {
			let dx = x - px;
			let dy = y - py;
			let d = dx * dx + dy * dy;
			let r = t / c;
			if d < r * r + EPS {
				cnt += 1;
			}
		}
		if cnt >= k {
			return true;
		}
	}
	false
}


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

int main() {
    int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int K; cin >> K;
    cout << a[K-1] << endl;
    return 0;
}

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

using namespace std;

#define EGG 0
#define CHICKEN 1
#define Judge( c ) ((c == 'e')? EGG : CHICKEN)
#define Next( n ) ((n == EGG)? 3 : 7)

int main( void )
{
	string input;
	
	while(cin >> input)
	{
		int len = input.size();
		int pnt = 0, nextpnt = 0;;
		int now, next;
		int age = 0, maxAge = 0;
		int ansType;
		ansType = Judge(input[0]);
		while(true) {
			now = Judge(input[pnt]);
			nextpnt = pnt + Next(now);
			age++;
			if(nextpnt < len) {
				next = Judge(input[nextpnt]);
				if(now == next) {
					if(maxAge < age) {
						maxAge = age;
						ansType = now;
					}
					age = 0;
				}
				pnt = nextpnt;
			}
			else{
				if(maxAge < age) {
					maxAge = age;
					ansType = now;
				}
				age = 0;
				break;
			}
		}
		if(ansType == EGG)
			cout << "egg" << endl;
		else
			cout << "chicken" << endl;
	}
	return 0;
}

Measured memory_bytes: 0
class WeightedUnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
        # 根への距離を管理
        self.weight = [0] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            y = self.find(self.par[x])
            # 親への重みを追加しながら根まで走査
            self.weight[x] += self.weight[self.par[x]]
            self.par[x] = y
            return y

    # 併合
    def union(self, x, y, w):
        rx = self.find(x)
        ry = self.find(y)
        # xの木の高さ < yの木の高さ
        if self.rank[rx] < self.rank[ry]:
            self.par[rx] = ry
            self.weight[rx] = w - self.weight[x] + self.weight[y]
        # xの木の高さ ≧ yの木の高さ
        else:
            self.par[ry] = rx
            self.weight[ry] = -w - self.weight[y] + self.weight[x]
            # 木の高さが同じだった場合の処理
            if self.rank[rx] == self.rank[ry]:
                self.rank[rx] += 1

    # 同じ集合に属するか
    def same(self, x, y):
        return self.find(x) == self.find(y)

    # xからyへのコスト
    def diff(self, x, y):
        if self.same(x, y):
            return self.weight[x] - self.weight[y]
n, m=map(int, input().split())
U=WeightedUnionFind(n)
def C(U):
    for i in range(m):
        l, r, d = map(int, input().split())
        if U.same(l-1, r-1):
            if U.diff(l-1, r-1)!=d:
                return False
        else:
            U.union(l-1, r-1, d)
    return True
if C(U):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 113568
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5;
long long ans;
int n, p[maxn + 10], fa[maxn + 10];
int sz[maxn + 10][2];

struct data {
	int p, x, y;
	bool operator < (const data &t) const {
		return 1ll * x * t.y < 1ll * t.x * y;
	}
};
priority_queue<data> pq;

int getf(int p) {
	return fa[p] == p ? p : fa[p] = getf(fa[p]);
}

int main() {
	scanf("%d", &n);
	for (int i = 2; i <= n; ++i) scanf("%d", &p[i]);
	for (int i = 1; i <= n; ++i) {
		int x; scanf("%d", &x);
		++sz[i][x]; fa[i] = i;
	}
	for (int i = 2; i <= n; ++i)
		pq.push((data){i, sz[i][0], sz[i][1]});
	while (!pq.empty()) {
		data e = pq.top(); pq.pop();
		if (fa[e.p] == e.p && e.x == sz[e.p][0] && e.y == sz[e.p][1]) {
			int f = getf(p[e.p]);
			ans += 1ll * sz[f][1] * sz[e.p][0];
			sz[f][0] += sz[e.p][0]; sz[f][1] += sz[e.p][1];
			fa[e.p] = f;
			if (f != 1) pq.push((data){f, sz[f][0], sz[f][1]});
		}
	}
	printf("%lld", ans);
}


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

struct Ps{
  int r,c;
  Ps():r(0),c(0){}
  Ps(int r,int c):r(r),c(c){}
  Ps operator+(const Ps&p)const
  { return Ps(r+p.r,c+p.c);  }
  friend istream& operator>>(istream&is,Ps&p)
  {is >> p.r >> p.c; return is;  }
};

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int h,w; cin >> h >> w;
  Ps s,g; cin >> s >> g;
  s = s+Ps(-1,-1);
  g = g+Ps(-1,-1);
  bitset<1000> mz[1000];
  for(int i = 0; i < h; ++i)for(int j = 0; j < w; ++j)
      mz[i][j] = []{char c; cin >> c; return c;}() == '.';
  optional<int> distance[1000][1000];
  deque<pair<Ps,int>> dq;
  dq.emplace_front(s,0);
  while(!dq.empty()){
    auto [ps,di] = dq.front();
    dq.pop_front();
    if(distance[ps.r][ps.c])continue;
    distance[ps.r][ps.c] = di;
    mz[ps.r][ps.c] = 0;
    if(ps.r==g.r && ps.c==g.c)break;
    for(int i = -2; i <= 2; ++i){
      for(int j = -2; j <= 2; ++j){
	Ps nps = ps + Ps(i,j);
	if(nps.r < 0 || nps.c < 0 || nps.r >= h || nps.c >= w)continue;
	if(!mz[nps.r][nps.c])continue;
	if(abs(i)+abs(j) > 1){
	  dq.emplace_back(move(nps),di+1);
	} else {
	  mz[nps.r][nps.c] = 0;
	  dq.emplace_front(move(nps),di);
	}
      }
    }
  }
  cout << (distance[g.r][g.c] ? distance[g.r][g.c].value() : -1) << endl;
}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int n, m;
    cin >> n >> m;
    vector<int> v(m);
    int s = 0;
    for(int i = 0; i < m; ++i) {
        cin >> v[i];
        s += v[i];

    }

    if(s > n) cout << -1 << endl;
    else cout << n - s << endl;


    return 0;
}



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

int main()
{
    int n,ans=0;
    cin>>n;
    string s;
    cin>>s;
    for(int i=0; i<n-1; i++)
    {
        if(s[i]==s[i+1]) continue;
        else ans++;
    }
    ans++;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 512
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        FastScanner scanner = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        int N = scanner.nextInt();
        int ans = 0;
        for(int i=1; i <= N; i++) {
            if (Integer.toString(i).length()%2==1) ans++;
        }
        out.println(ans);
        out.flush();
    }
    
    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;
        
        public FastScanner(Reader in) {
            br = new BufferedReader(in);
        }
        
        public FastScanner() {
            this(new InputStreamReader(System.in));
        }
        
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        
        int nextInt() {
            return Integer.parseInt(next());
        }
        
        long nextLong() {
            return Long.parseLong(next());
        }
        
        double nextDouble() {
            return Double.parseDouble(next());
        }
        
        String readNextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 26192
import math
x,k,d=map(int, input().split())
if k*d <= abs(x):
	print(abs(x)-d*k)
else:
	n = math.floor(abs(x)/d)
	if (k-n)%2==0:
		print(abs(x)-d*n)
	else:
		print(abs(abs(x)-d*(n+1)))

Measured memory_bytes: 9176
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define mod ((int)1e9+7)
#define lim 1000000000000000007
#define lim1 18446744073709551615  //Unsigned
#define sq(a) ((a)*(a))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mms(v,i) memset(v,i,sizeof(v))
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define REPN(i,a,b) for (int i = a; i >= b; i--)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pi;
typedef pair<ll,ll> PL;
typedef pair<ll,int> PLI;
typedef pair<int,ll> PIL;
typedef pair<int,pair<int,int> > pii;
typedef pair<double,double> pdd;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a,ll b) {
   ll res=1;
   while(b){
      if(b%2==1) res=(res*a)%mod;
      a=(a*a)%mod;
      b>>=1;
   }
   return res;
}
ll gcdll(ll a,ll b) {
    if (b==0) return a;
    return gcdll(b,a%b);
}
int gcd(int a,int b) {
    if (b==0) return a;
    return gcd(b,a%b);
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

const int N = (int)1e6+5;
const int M = (int)3e3+5;
const int Q = 301;
const int logN = 19;

void solve() {
    int n,k;
    cin>>n>>k;
    vector<int> v(n+1);
    while(k--) {
        int d,p;
        cin>>d;
        while(d--) {
            cin>>p;
            v[p]++;
        }
    }
    int ans = 0;
    REP(i,1,n) {
        if(!v[i]) {
            ans++;
        }
    }
    cout<<ans;
}
int main() {
    //freopen("output.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int T=1;
    //cin>>T;
    REP(TC,1,T) {
        //cout<<"Case #"<<TC<<": ";
        solve();
        cout<<"\n";
    }
}


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

#define f(i,a,b) for( ll i = a; i < b ; i++ ) 
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ones(x) (ll) __builtin_popcount(x)
#define fs first
#define sc second
#define pb push_back
#define po pop_back
#define mp make_pair	
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ller ios::sync_with_stdio(false);cin.tsie(nullptr);cout.tie(nullptr)

#define PI 3.1415926535
using namespace std;
typedef long long ll;
typedef long double ld;	
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;
	 
const ll MAX = 1e5+7;
const ll inf = 1e18+5;


ll n,k,h[MAX];
ll dp[MAX];

ll DP(ll u){
  ll &ans = dp[u];
  if(u==1) return 0;
  if(ans!=inf) return ans;
  f(i,u-k,u){
    if(i<=0) continue;
    ans=min(ans,DP(i)+abs(h[u]-h[i]));
  }
  return ans;
}
int main() {
  fastio;
  cin>>n>>k;
  f(i,0,n+3)dp[i]=inf;
  f(i,1,n+1){
    cin>>h[i];
  }
  cout<<DP(n)<<endl;

  return 0;
}


Measured memory_bytes: 9852
#include<stdio.h>
int v[51];
int c[51];
int main()
{
	int n;
	scanf("%d",&n);
	int max = 0;
	int t;
	for(int i = 0; i < n; i++){
		scanf("%d",&v[i]);
	}
	for(int i = 0; i < n; i++){
		scanf("%d",&c[i]);
	}
	for(int i = 0; i < n; i++){
		t = v[i] - c[i];
		if(t>0){
			max += t;
		}
	}
	printf("%d",max);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i=(a) ; i<=(b) ; ++i)
#define mp make_pair
#define pii pair<int, int>
#define PB push_back
#define F first
#define S second
using namespace std;
const int N=200005;
int a[N], n, dd[N], same[N], dd2[N], b[N]; /// dd[i]: so i dau tien, same[i]: giong i sau i
long long k;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen(".inp", "r", stdin);
    cin >> n >> k;
    rep(i, 1, n) {
        cin >> a[i];
        if(dd[a[i]]==0) dd[a[i]]=i;
        dd2[a[i]]=n+1;
    }

    same[n+1]=n+1;
    for(int i=n ; i ; --i) {
        same[i]=dd2[a[i]];
        dd2[a[i]]=i;
    }
    int ptr=1, num=1;
    while(1) {
        while(same[ptr]!=n+1) {
            ptr=same[ptr]+1;
        }

        if(ptr==n+1) break;
        b[num]=ptr;

        ptr=dd[a[ptr]]+1;
        ++num;
    }
    int remain=k%num;

    if(remain) {
        int xx=b[remain];
        while(xx<=n) {
            if(same[xx]==n+1) { cout << a[xx] << ' '; ++xx; }
            else xx=same[xx]+1;
        }

    }


    return 0;
}


Measured memory_bytes: 5376
import java.util.*;
 
public class Main
{
	public static void main(String args[])
	{
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int b=0,c=0;
		for(int i=0;i<a;i++)
		{
			for(int j=0;j<a;j++)
			{
				if(i*4+j*7 == a)
					b++;
				else
					c++;
			}
		}
		if(b>0)
			System.out.println("Yes");
		else
			System.out.println("No");
	}	
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int A,B;
  cin >> A >> B;
  if(A > B) cout << 2 * A - 1 << endl;
  else if(A == B) cout << A + B << endl;
  else cout << 2 * B - 1 << endl;
 }


Measured memory_bytes: 256
import scala.io.StdIn._
object Main extends App {
  val Array(height, width) = readLine.trim.split(' ').map(_.toInt)
  val state = Array.fill(height){readLine.trim}
  val up = Array.fill(height){Array.fill(width){0}}
  val down = Array.fill(height){Array.fill(width){0}}
  val left = Array.fill(height){Array.fill(width){0}}
  val right = Array.fill(height){Array.fill(width){0}}
  for (w ← 0 until width if state(0)(w) == '.') up(0)(w) = 1
  for (w ← 0 until width if state(height - 1)(w) == '.') down(height - 1)(w) = 1
  for (h ← 0 until height if state(h)(0) == '.') left(h)(0) = 1
  for (h ← 0 until height if state(h)(width - 1) == '.') right(h)(width - 1) = 1
  for {h ← 1 until height
       w ← 0 until width} {
    if (state(h)(w) == '.') {
      up(h)(w) = up(h - 1)(w) + 1
    }
    if (state(height - h - 1)(w) == '.') {
      down(height - h - 1)(w) = down(height - h)(w) + 1
    }
  }
  for {h ← 0 until height
       w ← 1 until width} {
    if (state(h)(w) == '.') {
      left(h)(w) = left(h)(w - 1) + 1
    }
    if (state(h)(width - w - 1) == '.') {
      right(h)(width - w - 1) = right(h)(width - w) + 1
    }
  }
  println(
    (0 until height).flatMap(h ⇒ (0 until width).map(w ⇒ up(h)(w) + down(h)(w) + left(h)(w) + right(h)(w) - 3)).max
  )
}


Measured memory_bytes: 235340
N,M = map(int,input().split())
K = [0]*(10**5)
for i in range(M):
  P,Q = map(int,input().split())
  K[P-1] += 1
  K[Q-1] += 1
flag = True
for i in range(10**5):
  if K[i]%2 != 0:
    flag = False
    break
if flag:
  print('YES')
else:
  print('NO')

Measured memory_bytes: 3828
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>
#include<iomanip>
#include<queue>

using ll = long long;
const int inf = 99999999;

using namespace std;

int main(){
	int n,m,x;
	cin >> n >> m >> x;
	vector<int> c(n);
	vector<vector<int>> a(n,vector<int>(m,0));
	for(int i = 0; i < n; i++){
		cin >> c[i];
		for(int j = 0; j < m; j++){
			cin >> a[i][j];
		}
	}
	
	//bit 
	ll ans = inf;
	for(int i = 0; i < (1 << n); i++){
		ll cost = 0;
		vector<int> xall(m,0);
		for(int j = 0; j < n; j++){
			if(i & (1 << j)){
				cost += c[j];
				for(int k = 0; k < m; k++){
					xall[k] += a[j][k];
				}
			}
		}
		bool ok = true;
		for(int k = 0; k < m; k++){
			if(xall[k] >= x)continue;
			ok = false;
		}
		if(ok)ans=min(ans,cost);
	}
	if(ans == inf)ans = -1;
	cout << ans << endl;
	
	return 0;
}
 

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

int main() {
    string S,T;
    cin >> S >> T;
    rep(i, S.size()){
        if(S.at(i) != T.at(i)){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}



Measured memory_bytes: 3536
import Control.Monad

matrixDotVector :: [[Int]] -> [Int] -> [Int]
matrixDotVector m v = map (f v) m
  where
    f :: [Int] -> [Int] -> Int
    f vec1 vec2 = sum $ zipWith (*) vec1 vec2

main = do
  [n,m] <- fmap (map read . words) getLine
  matrix <- replicateM n $ fmap (map read . words) getLine :: IO [[Int]]
  vector <- replicateM m $ fmap read getLine :: IO [Int]


  -- print matrix
  -- print vector
  -- print $ matrixDotVector matrix vector
  forM_ (matrixDotVector matrix vector) $ \i -> do
    print i


Measured memory_bytes: 7528
n = int(input())
A = [int(x) for x in input().split()]

flag = 1
count = 0
for i in range(n):
    for j in range(n-1):
        if (A[j+1] < A[j]):
            A[j],A[j+1] = A[j+1],A[j]
            count += 1

for k in range(n-1):
    print(str(A[k])+" ",end = "")
print(str(A[n-1]))
print(count)



Measured memory_bytes: 5612
#include<iostream>
#include<algorithm>

using namespace std;

short max(int a,int b){
  if(a>b)return a;
  return b;
}

short nails[5001][5001];

int main(void){

  int n,m,a,b,x;
 
  cin >> n >> m;

  for(int i=0;i<m;i++){
    cin >> a >> b >> x;
    nails[a][b]=x+1;
  }

  for(int i=1;i<=n;i++){
    for(int j=1;j<=i;j++){
      nails[i][j]=max(nails[i][j],max(nails[i-1][j-1],nails[i-1][j])-1);      
    }
  }

  int cnt=0;
  for(int i=1;i<=n;i++)
    for(int j=1;j<=i;j++)
      if(nails[i][j]>0)cnt++;
     
  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 48856
#include <bits/stdc++.h>
//#define inf 0x3f3f3f3f3f3f3f3f
#define inf 0x3f3f3f3f
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define inv(x) Power(x, mod - 2)
#define fi first
#define se second
#define MP make_pair
#define PB push_back

using namespace std;
typedef pair<int,int> Pair;
typedef long double ld;
typedef long long ll;

const int mod = 1e9, MAX = 600000, N = 200005;
const long double Pi = 3.14159265358979323846l;
inline int add(int x, int y) { x += y; return x >= mod ? x - mod : x; };
inline void inc(int &x, int y) { x += y; x -= (x >= mod ? mod : 0); }
inline int mul(int x, int y) { return 1ll * x * y % mod; }
inline int Power(int x, int y) {
	int ans = 1;
	while (y) {
		if (y & 1) ans = mul(ans, x);
		x = mul(x, x), y >>= 1;
	} return ans;
}

template <class T> inline T	input() {
	T x; char ch; while (!isdigit(ch = getchar()));
	for (x = ch ^ 48; isdigit(ch = getchar()); x = x * 10 + (ch ^ 48));
	return x;
}

template <class T> inline bool chkmin(T &x, T y) { x = x < y ? x : y; return x == y; }
template <class T> inline bool chkmax(T &x, T y) { x = x > y ? x : y; return x == y; }
template <class T> inline T gcd(T x, T y) { return !y ? x : gcd(y, x % y); }
template <class T> inline T sqrm(T x) { return (ll) x * x % mod; }
template <class T> inline T sqr(T x) { return x * x; }

struct {
	inline operator int () { return input<int>(); }
	inline operator long long () { return input<long long>(); }
	template <class T> inline void operator () (T &x) { x = *this; }
	template<class T, class ...A> inline void operator () (T &x, A &...a)
	{ x = *this; this -> operator ()(a...); }
} read;

struct BIT {
	int Max[MAX + 5];
	void modify(int pos, int val) {
		for (int i = pos; i <= MAX; i += i & -i)
			chkmax(Max[i], val);
	}
	int query(int pos) {
		if (!pos) return 0;
		if (pos < 0) return -inf;
		int res = 0;
		for (int i = pos; i; i ^= i & -i)
			chkmax(res, Max[i]);
		return res;
	}
}bit;

int n;
struct Node {
	int l, r;
}a[N];
int num[N << 3], tot;

inline bool cmp(Node &a, Node &b) { return a.l < b.l; }

signed main() {
#ifdef local
	freopen("in", "r", stdin);
	freopen("out", "w", stdout);
	freopen("log", "w", stderr);
#endif
	ios::sync_with_stdio(false);

	cin >> n;
	for (int i = 1; i <= n; ++i) {
		int x, L;
		cin >> x >> L;
		a[i].l = x - L;
		a[i].r = x + L;
		num[++tot] = a[i].l;
		num[++tot] = a[i].r;
	}

	sort(num + 1, num + tot + 1);
	for (int i = 1; i <= n; ++i) {
		a[i].l = lower_bound(num + 1, num + tot + 1, a[i].l) - num;
		a[i].r = lower_bound(num + 1, num + tot + 1, a[i].r) - num;
	}
	sort(a + 1, a + n + 1, cmp);

	for (int i = 1; i <= n; ++i)
		bit.modify(a[i].r, bit.query(a[i].l) + 1);
	printf("%d\n", bit.query(MAX));
	return 0;
}


Measured memory_bytes: 3584
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>

#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


#define ARRAY_MAX 100005
const ll INF = 1e9;
const ll MOD = 1e9 + 7;

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




/******************************************************************************************/

ll sum[200005];


int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}

	for (int i = 1; i <= n; i++)
	{
		sum[i] = sum[i - 1] + a[i - 1];
	}
	
	ll ans = 1LL << 60;


	int left = 1, center = 2,right = 3;
	while(center < n - 1)
	{

		while (left < center -1) {
			if (abs(sum[left] - (sum[center] - sum[left])) > abs(sum[left + 1] - (sum[center] - sum[left + 1]))) {
				left++;
			}
			else
			{
				break;
			}
		}
		
		while (right < n - 1) {
			if (abs(sum[n] - sum[right] - (sum[right] - sum[center])) > abs(sum[n] - sum[right + 1] - (sum[right + 1] - sum[center]))) {
				right++;
			}
			else
			{
				break;
			}
		}

		ll mini = min(min(sum[left], sum[center] - sum[left]), min(sum[right] - sum[center], sum[n] - sum[right]));
		ll maxi = max(max(sum[left], sum[center] - sum[left]), max(sum[right] - sum[center], sum[n] - sum[right]));
		ans = min(ans, maxi - mini);
		center++;
	}

	cout << ans << endl;


	return 0;
}


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

int main(){
  string s;
  cin>>s;
  int count=0,i=0;
  while(s.size()>i){
    if(i%2==0){
      if(s.at(i)=='p') count--;
    }else{
      if(s.at(i)=='g') count++;
    }i++;
  }
  cout<<count<<endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(ll i = m, i##_len = (n); i < i##_len; ++i)
#define reprev(i, n) for(ll i = (n-1LL); i >= 0; --i)
#define all(x) (x).begin(), (x).end()
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; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll t1, t2, a1, a2, b1, b2, d1, d2;
	cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;
	d1 = a1 - b1; d2 = a2 - b2;
	// ll g = gcd(d1, d2);
	// d1 /= g; d2 /= g;
	ll s = t1 * d1 + t2 * d2;
	ll ans;
	bool pittari = false;
	if (s == 0) cout << "infinity\n";
	else if ((d1 > 0 &&  s > 0) || (d1 < 0 &&  s < 0)) cout << "0\n";
	else {
		// iki
		ans = abs(d1 * t1) / abs(s);
		pittari = (abs(d1 * t1) % abs(s) == 0);
		// cout << d1 * t1 << " " << s << " " << ans << "\n";
		// cout << abs(d1 * t1) << " " << abs(s) << " " << ans << "\n";
		if (pittari) ans = ans * 2;
		else ans = ans * 2 + 1;
		cout << ans << "\n";
	}
	return 0;
}

Measured memory_bytes: 256
// Vicfred
// https://atcoder.jp/contests/abc156/tasks/abc156_d
// math

import std.stdio: writeln, readf;

ulong binpow(ulong a, ulong b, ulong m) {
    a %= m;
    ulong res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
	}
    return res;
}

ulong binomial(ulong n, ulong k, ulong m) {
    ulong x = 1;
    ulong y = 1;
    foreach  (ulong i; 0..k) {
        x *= n-i;
        x %= m;
        y *= i+1;
        y %= m;
	}
    y = binpow(y, m-2, m);
    return (x*y)%m;
}

void main()
{

ulong mod = 10^^9+7;

ulong n, a, b;
"%s %s %s\n".readf(&n, &a, &b);

writeln((binpow(2, n, mod) - binomial(n,a, mod) - binomial(n,b, mod) - 1 + 3*mod)%mod);

}


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

int main() {
    int n, m, x, a, dp[101] = {};
    cin >> n >> m >> x;
    for ( int i = 0; i < m; i++ ) {
        cin >> a;
        dp[a] ++;
    }
    
    for ( int i = 0; i < n; i++ ) {
        dp[i+1] += dp[i];
    }
    
    cout << min(dp[n]-dp[x], dp[x]) << endl;
    
    return (0);
}


Measured memory_bytes: 3628
import * as fs from 'fs';


function solve(): number {
    const lines = fs.readFileSync('/dev/stdin', 'utf8').trim().split('\n');
    const N = Number(lines[0]);
    const A: number[] = [];

    for(let i=0; i<N; i++) {
        A.push(Number(lines[i+1]));
    }

    if (A[0] != 0) {
        return -1;
    }
    A.push(0);
    
    let i = N, answer = 0;
    while (i > 0) {
        if (A[i]-A[i-1] > 1)
            return -1;
        else if (A[i]-A[i-1] != 1) {
            answer += A[i-1]
        }
        i -= 1;
    }
    return answer;
}

console.log(solve());


Measured memory_bytes: 55072
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll mod = 1e09 + 7;

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

  ll n;
  cin >> n;
  ll a[n];
  REP(i, n) cin >> a[i];

  SORT(a, n);

  ll ans = 0, cnt = 1;

  REP(i, n - 1){
    if(a[i + 1] == a[i]) cnt++;
    else{
      if(cnt % 2) ans++;
      cnt = 1;
    }
    if(i == n - 2 && cnt % 2) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
N, K, S=[int(i) for i in input().split()]

if S!=10**9:
    ans=[S]*K
    for i in range(N-K):
        ans.append(S+1)
    print(" ".join([str(n) for n in ans]))
else:
    ans=[S]*K
    for i in range(N-K):
        ans.append(1)
    print(" ".join([str(n) for n in ans]))


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

const int INF=1<<30;

vector<int> dx={1, 0, -1, 0}, dy={0, 1, 0, -1};

int main(){
    int H, W; cin >> H >> W;
    int cnt=0;
    vector<vector<char>> s(H, vector<char>(W));
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            cin >> s[i][j];
            if(s[i][j] == '#') cnt++;
        }
    }
    int res=0;
    vector<vector<int>> dist(H, vector<int>(W, -1));
    dist[0][0]=0;
    queue<pair<int, int>> que;
    que.push(make_pair(0, 0));
    while(!que.empty()){
        int x, y;
        tie(x, y)=que.front();
        que.pop();
        for(int i=0; i<4; i++){
            int nx=x+dx[i];
            int ny=y+dy[i];
            if(nx<0 || nx>=H || ny<0 || ny>=W) continue;
            if(dist[nx][ny] != -1) continue;
            if(s[nx][ny] == '#') continue;
            dist[nx][ny]=dist[x][y]+1;
            que.push(make_pair(nx, ny));
        }
    }
    res=H*W-cnt-(dist[H-1][W-1]+1);
    if(dist[H-1][W-1] == -1) cout << -1 << endl;
    else cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
str_ab = 0
top_b = 0
bottom_a = 0
tbba = 0
for i in range(n):
    s = input()
    str_ab += s.count('AB')
    if s[0] == 'B' and s[-1] == 'A':
        tbba += 1
    elif s[0] == 'B':
        top_b += 1
    elif s[-1] == 'A':
        bottom_a += 1

if tbba == 0:
    ans = min(top_b, bottom_a) + str_ab
else:
    if top_b > 0 and bottom_a > 0:
        ans = str_ab + tbba - 1 + 2 + min(top_b, bottom_a) - 1
    else :
        if top_b > 0 or bottom_a > 0:
            ans = str_ab + tbba - 1 + 1
        else :
            ans = str_ab + tbba - 1

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main()
{
    ll N, K;
    cin >> N >> K;
    double ans = 0.0;
    for (int i = 1; i <= N; ++i)
    {
        int tmp = i;
        int num = 0;
        while (tmp < K)
        {
            tmp *= 2;
            ++num;
        }
        ans += (1.0 / N) * (1.0 / pow(2.0, num));
    }
    printf("%.12f\n", ans);
}


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

using namespace std;

#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pow(x) x*x
#define ll long long
static const ll MAX = 1000000;
static const ll INFTY = 1e12;
static const ll MOD = 1000000007;

template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };

struct edge {
    ll to, cost;
};

using Graph = vector<vector<int>>;
using _Graph = vector<vector<edge>>;


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

// 深さ優先探索
vector<bool> seen;
vector<int> colors;

int H, W, N;
int sx, sy, gx, gy; 
vector<vector<char>> field;
vector<vector<int>> dist;
//vector<pair<int, int>> gx, gy;
deque<pair<int, int>> que;

typedef vector<vector<int> > Matrix;

const int INF = 100000000;


int main() {

    ll N, K;
    string S;
    cin >> N >> K;
    cin >> S;
    vector<int> num;

    int pos = 0;

    REP(i, S.length()-1){
      if(S[i] != S[i+1]){
        num.push_back(i-pos+1);
        pos = i+1;
      }      
    }
    num.push_back(S.length()-pos);
    if(S[0]=='0')num.insert(num.begin(), 0);
    if(S[S.length()-1]=='0')num.push_back(0);

    int span = 2*K+1;
    // if(span >= num.size()-1)span=num.size()-1;
    vector<int> sum(num.size()+1, 0);
    REP(i, num.size()){
      sum[i+1] = sum[i] + num[i];
    }

    int max_ = 0;
    for(int i = sum.size()-1; i >= 0; i-=2){
      // cout << span << endl;
      if(i-span < 0){
        max_ = max(max_, sum[i]-sum[0]);
        
      }
      else {
        max_ = max(max_, sum[i]-sum[i-span]);
      }
      // cout << max_ << endl;
    }

    // REP(i, sum.size()){
    //   cout << sum[i] << " ";
    // }
    cout << max_ << endl;

}


/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/


Measured memory_bytes: 1272
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#include<map>
#include<iostream>
#include <cstring>
#include <iomanip>
#include <algorithm>
#define forr(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define input ios_base::sync_with_stdio(0);cin.tie(0);

const double PI  = acos(-1.0);
using namespace std;
//typedef pair<double,double>pdd;
typedef long long  ll;
typedef pair<ll, ll>pii;
//typedef complex<double> point;
//int x[8]={1,0,0,-1,-1,-1,1,1};
//int y[8]={0,1,-1,0,-1,1,-1,1};
//char rv[4]={'D','R','L','U'};
const double EPS = 1e-9;
const int N = 100000 + 9;
int n,m,vis[N];
vector<int> adj[N];


void dfs(int u)
{
    vis[u] = 1;
    for(auto v:adj[u])
    {
        if(!vis[v])
        {
            dfs(v);
        }
    }
}
 int main()
{
//freopen("calc.in","r",stdin);
//freopen("calc.out","w",stdout);
//__builtin_popcount()
input
        cin>>n>>m;
        int u,v;
        forr(i,1,m)
        {
            cin>>u>>v;
            adj[u].push_back(v);
            adj[v].push_back(u);
        }
        int c=0;
        forr(i,1,n)
        {
            if(!vis[i])dfs(i),c++;
        }

        cout<<c-1<<endl;





return 0;
}


Measured memory_bytes: 9996
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <bitset>

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define INF 2000000000
#define rep(i,n) for(int i=0;i<(n);i++)
typedef pair<string, string> P;
const ll MOD=1000000007;
using Graph = vector<vector<int>>;

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


ull gcd(ull a, ull b) {
    while (a % b != 0) {
        ull tmp = b;
        b = a % b;
        a = tmp;
    }
    return b;
}

ull lcm(ull a, ull b) {
    if (a == b) return b;
    ull g = gcd(a, b);
    return (a / g) * b;
}

int n;
ll W;
ll w[105], v[105];
ll dp[105][100005];
int main() {
    cin >> n >> W;
    for (int i = 1; i <= n; i++) {
        cin >> w[i] >> v[i];
    }
    rep(i, W) dp[0][i] = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= W; j++) {
            chmax(dp[i][j], dp[i - 1][j]);
            if (j >= w[i]) chmax(dp[i][j], dp[i - 1][j - w[i]] + v[i]);
            
        }
    }
    
    cout << dp[n][W] << endl;
    return 0;
}

Measured memory_bytes: 80128
#include <bits/stdc++.h>
 
#define rep(i, n) for(int i = 0; i < (n); i++)
using ll = long long;
constexpr ll INF = 1000000000;
 
using namespace std;
 
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}
 
int main() {
	int n; cin >> n;
	vector<int>a(n);
	rep(i, n)cin >> a[i];
 
	vector<int>g1(n);
 
	int k = a[0];
	g1[0] = a[0];
 
	for (int i = 1; i < n; i++) {
		g1[i] = gcd(k, a[i]);
		k = gcd(k, a[i]);
	}
 
	reverse(a.begin(), a.end());
 
	vector<int>g2(n);
 
	int kl = a[0];
	g2[0] = kl;
 
	for (int i = 1; i < n; i++) {
		g2[i] = gcd(kl, a[i]);
		kl = gcd(kl, a[i]);
	}
 
	reverse(g2.begin(), g2.end());
 
	vector<int>ans(n);
	for (int i = 1; i < n - 1; i++) {
		ans[i] = gcd(g1[i - 1], g2[i + 1]);
	}
	ans[0] = g2[1];
	ans[n - 1] = g1[n - 2];
 
	sort(ans.begin(), ans.end());
	reverse(ans.begin(), ans.end());
	cout << ans[0] << endl;
}

Measured memory_bytes: 1792