akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

#include <cmath>
#include <iomanip>

void _126() {
    int n, k;
    cin >> n >> k;

    double probability = 0.0;
    for (int i = 1; i <= n; ++i) {
        for (int j = 0; ; ++j) {
            if (i * pow(2, j) >= k) {
                probability += (pow(0.5, j)) / n;
                break;
            }
        }
    }
    cout << fixed << setprecision(12);
    cout << probability << endl;
}

void _127() {
    int n, m, limit_l, limit_r, l, r;
    cin >> n >> m;
    limit_l = 1;
    limit_r = n;
    for (int i = 0; i < m; ++i) {
        cin >> l >> r;
        if (l > limit_l) {
            limit_l = l;
        }
        if (r < limit_r) {
            limit_r = r;
        }
    }
    int count = max(limit_r - limit_l + 1, 0);
    cout << count << endl;
}

void _128() {
    int n, m;
    cin >> n >> m;

    int k[10], s[10][10];
    for (int i = 0; i < m; ++i) {
        cin >> k[i];
        for (int j = 0; j < k[i]; ++j) {
            cin >> s[i][j];
        }
    }
    int p[10];
    for (int i = 0; i < m; ++i) 
        cin >> p[i];

    int count = 0;
    bool off_flag = false;
    int sw_count = 0;
    for (int i = 0; i < pow(2, n); ++i) {
        off_flag = false;
        for (int j = 0; j < m; ++j) {
            sw_count = 0;
            for (int l = 0; l < k[j]; ++l) {
                if (((i >> (s[j][l] - 1)) & 1) == 1) {
                    sw_count++;
                }
            }
            if (sw_count % 2 != p[j]) {
                // cout << "off " << sw_count <<  endl;
                off_flag = true;
                break;
            }
        }
        if (!off_flag) {
            count++;
        }
    }
    cout << count << endl;
}

int main()
{
    _128();
    return 0;
}



Measured memory_bytes: 512
#include <algorithm>
#include <cmath>
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

/* a と b の最大公約数を返す関数 */
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

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

	bool find = false;;
	for (int i = a; i <= b; ++i)
	{
		if (i % k == 0)
		{
			find = true;
			cout << "OK" << endl;
			break;
		}
	}

	if (!find)
	{
		cout << "NG" << endl;
	}

	return 0;
}

Measured memory_bytes: 3600
N = int(input())
C = [list(map(int, input().split())) for _ in range(N)]

counter = 0
for d1, d2 in C:
    if d1 == d2:
        counter += 1
    else:
        counter = 0

    if counter == 3:
        print('Yes')
        exit()
print('No')


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

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

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

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

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

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

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

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

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

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

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        d: usize,
        v: [[i64; d]; n]
    }
    let mut ans: usize = 0;
    for i in 0..n {
        for j in i + 1..n {
            let mut d2 = 0;
            for k in 0..d {
                d2 += (v[i][k] - v[j][k]) * (v[i][k] - v[j][k]);
            }
            let mut m = 0;
            while m * m <= d2 {
                if m * m == d2 {
                    ans += 1;
                    break;
                }
                m += 1;
            }
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Hassan El Desouky
 */

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"

using namespace std;
#define el '\n'
#define F first
#define S second
#define FOR(i,a,b) for(int i = a; i <= b; ++i)
#define FORD(i,a,b) for(int i = a; i >= b; --i)
#define RI(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(n)-1)
#define SQR(x) (x)*(x)
#define all(v)  	((v).begin()),((v).end())
typedef long long ll;
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pll;
typedef long double ld;
typedef vector<int>		vi;
typedef vector<int>		vll;
typedef vector<pii>		vpii;
const double EPS = 1e-9;
const int N = 1e3+2, M = 3e5+5, OO = 0x3f3f3f3f;
int dx[] = {1,-1,0,0} , dy[] = {0,0,1,-1}; // 4 Direction
//int dx[] = {1,-1,0,0,1,1,-1,-1}, dy[] = {0,0,1,-1,1,-1,1,-1}; // 8 Direction
/* int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1}; */ // Knight Direction
/* int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1}; */ // Hexagonal Direction


class AUOIAUAI {
public:
	void solve(std::istream& in, std::ostream& out) {
        char c; in >>c;
        if (c == 'a' || c == 'o' || c == 'i' || c == 'u' || c == 'e') out << "vowel\n";
        else out << "consonant\n";
	}
};


int main() {
	AUOIAUAI solver;
    ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
///////////////////////////////////////////// Template /////////////////////////////////////////////
#![allow(non_snake_case, unused)]
use std::collections::*;

//////////////////// missing functions in 1.15.1 ////////////////////
macro_rules! eprint {
	($($t:tt)*) => { {
		use ::std::io::Write;
		let _ = write!(::std::io::stderr(), $($t)*);
	} };
}
macro_rules! eprintln {
	($($t:tt)*) => { {
		use ::std::io::Write;
		let _ = writeln!(::std::io::stderr(), $($t)*);
	} };
}

//////////////////// useful functions ////////////////////
pub trait SetMin {
	fn setmin(&mut self, v: Self) -> bool;
}
impl<T> SetMin for T where T: PartialOrd {
	fn setmin(&mut self, v: T) -> bool {
		*self > v && { *self = v; true }
	}
}
pub trait SetMax {
	fn setmax(&mut self, v: Self) -> bool;
}
impl<T> SetMax for T where T: PartialOrd {
	fn setmax(&mut self, v: T) -> bool {
		*self < v && { *self = v; true }
	}
}

macro_rules! debug {
	($($v: expr),*) => {
		$(eprint!("{} = {:?} ", stringify!($v), $v);)*
		eprintln!("@ {}:{}", file!(), line!());
	}
}

macro_rules! mat {
	($($e:expr),*) => { Vec::from(vec![$($e),*]) };
	($($e:expr,)*) => { Vec::from(vec![$($e),*]) };
	($e:expr; $d:expr) => { Vec::from(vec![$e; $d]) };
	($e:expr; $d:expr $(; $ds:expr)+) => { Vec::from(vec![mat![$e $(; $ds)*]; $d]) };
}

pub fn readln() -> String {
	let mut line = String::new();
	::std::io::stdin().read_line(&mut line).unwrap_or_else(|e| panic!("{}", e));
	line
}

macro_rules! read {
	($($t:tt),*; $n:expr) => {{
		let stdin = ::std::io::stdin();
		let ret = ::std::io::BufRead::lines(stdin.lock()).take($n).map(|line| {
			let line = line.unwrap();
			let mut it = line.split_whitespace();
			_read!(it; $($t),*)
		}).collect::<Vec<_>>();
		ret
	}};
	($($t:tt),*) => {{
		let line = readln();
		let mut it = line.split_whitespace();
		_read!(it; $($t),*)
	}};
}

macro_rules! _read {
	($it:ident; [char]) => {
		_read!($it; String).chars().collect::<Vec<_>>()
	};
	($it:ident; [u8]) => {
		Vec::from(_read!($it; String).into_bytes())
	};
	($it:ident; [$t:ty]) => {
		$it.map(|s| s.parse::<$t>().unwrap_or_else(|e| panic!("{}", e))).collect::<Vec<_>>()
	};
	($it:ident; $t:ty) => {
		$it.next().unwrap_or_else(|| panic!("input mismatch")).parse::<$t>().unwrap_or_else(|e| panic!("{}", e))
	};
	($it:ident; $($t:ty),+) => {
		($(_read!($it; $t)),*)
	};
}

pub fn main() {
	let _ = ::std::thread::Builder::new().name("run".to_string()).stack_size(32 * 1024 * 1024).spawn(run).unwrap().join();
}
////////////////////////////////////////////////////////////////////////////////////////////////////

fn run() {
	let (N, M) = read!(usize, usize);
	let mut ab = read!(usize, usize; M);
	ab.sort_by(|x, y| (x.1, x.0).cmp(&(y.1, y.0)));
	let mut del = 0;
	let mut count = 0;
	for (a, b) in ab {
		if del <= a {
			count += 1;
			del = b;
		}
	}
	println!("{}", count);
}


Measured memory_bytes: 10492
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <cmath>

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)

int count(int N)
{
        int ans = 0;
        while (N)
        {
                ans++;
                N /= 10;
        }
        return ans;
}

int main()
{
        int a, b;
        string S;
        cin >> S;
        if (S[2] == S[3] && S[4] == S[5])
        {
                cout << "Yes" << endl;
        }
        else
        {
                cout << "No" << endl;
        }

        return 0;
}


Measured memory_bytes: 256
X = gets.chomp.split(' ').map(&:to_i)

def swap_first(arr)
  tmp = 0
  tmp = arr[0]
  arr[0] = arr[1]
  arr[1] = tmp
end

def swap_second(arr)
  tmp = 0
  tmp = arr[0]
  arr[0] = arr[2]
  arr[2] = tmp
end

swap_first(X)
swap_second(X)

print X[0]," ",X[1]," ",X[2]

Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define ll long long
#define all(a) a.begin(),a.end()
#define sz(a) a.size()
#define re return 
#define MP make_pair
#define pb push_back
#define pii pair<int,int>
using namespace std;
string s;
int n;
int ans,x;
signed main(){
	ios_base::sync_with_stdio(0);
	cin>>n;
	cin>>s;
	x=s.find('W');
	if(x==-1){
		cout<<ans;
		re 0;
	}
	for(int i=n-1;i>=x;i--){
		if(s[i]=='R'){
			swap(s[i],s[x]);
			x=s.find('W');
			ans++;
			if(x==-1){
				cout<<ans;
				re 0;
			}
		}
	}
	cout<<ans;
	re 0;
}

Measured memory_bytes: 3696
#include<bits/stdc++.h>
using namespace std;
int a[1401][1401],dp[1401][1401],m,h,w;
#define r(i,n) for(int i=0;i<n;i++)
main(){
  cin>>h>>w;
  r(i,h)r(j,w)cin>>a[i][j],m|=dp[i][j]=(a[i][j]+1)%2;
  r(i,h-1)r(j,w-1)if(!a[i+1][j+1])
    dp[i+1][j+1]=min(dp[i][j],min(dp[i+1][j],dp[i][j+1]))+1,
    m=max(m,dp[i+1][j+1]);
  cout<<m*m<<endl;
}

Measured memory_bytes: 18404
#include <iostream>
#include <algorithm>
#include <math.h>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
using namespace std;
using ll = long long;
using graph = std::vector<std::vector<long long>>;
int main(){
    ll N,Q;
    cin >> N >> Q;
    bool seen[N];
    ll sum[N];
    graph G(N);
    for(int i = 0; i < N; i++){
        seen[i] = false;
        sum[i] = 0;
        G[i] = vector<ll>(0);
    }
    for(int i = 0; i < N - 1; i++){
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    for(int i = 0; i < Q; i++){
        ll p,x;
        cin >> p >> x;
        p--;
        sum[p] += x;
    }
    queue<ll> q = queue<ll>();
    q.push(0);
    seen[0] = true;
    while(!q.empty()){
        ll current = q.front();q.pop();
        for(int i = 0; i < G[current].size();i++){
            ll next = G[current][i];
            if(seen[next]){
                continue;
            }
            sum[next] += sum[current];
            seen[next] = true;
            q.push(next);
        }
    }
    for(int i = 0; i < N; i++){
        cout << sum[i] << " ";
    }
    cout << endl;
}

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

#define PI acos(-1)
#define pb push_back
#define int long long int
#define mp make_pair
#define pi pair<int, int>
#define pii pair<int, pi>
#define fir first
#define sec second
#define MAXN 100001
#define MAXL 20
#define mod 1000000007

signed main()
{
  string s, t;
  cin >> s >> t;
  int ans = 0;
  for (int i = 0; i < s.size(); i++)
    if (s[i] != t[i])
      ans++;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3916
s = raw_input()
t = raw_input()


def trans_to_num(arr):
    letter_used = []
    num_arr = []
    for i in range(len(arr)):
        if arr[i] not in letter_used:
            letter_used.append(arr[i])
        num_arr.append(letter_used.index(arr[i]))
    return num_arr

if trans_to_num(s) == trans_to_num(t):
    print "Yes"
else:
    print "No"

Measured memory_bytes: 12420
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f3f3f3f3f;

ll d[MAXn];
int main(){
  IOS();
  int n,k;
  cin>>n>>k;
  REP(i,n) cin>>d[i];
  ll ans = INF;
  for(int i=0;i+k-1<n;i++) chkmin(ans,d[i+k-1]-d[i]+min(abs(d[i]),abs(d[i+k-1])));
  cout<<ans<<endl;
}


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

int main()
{
    std::ios::sync_with_stdio(false);
    lld t = 1;
    // cin >> t;
    while(t--) {
        lld N;
        cin >> N;
        vector<lld> v(N);
        for(lld i = 0; i < N; i++) {
            cin >> v[i];
        }
        vector<lld> post(N, 0);
        post[N - 1] = 0;
        for(lld i = N - 2; i >= 0; i--) {
            if(v[i + 1] <= v[i]) {
                post[i] = post[i + 1] + 1;
            } else {
                post[i] = 0;
            }
        }
        lld ans = 0;
        for(lld i = 0; i < N; i++) {
            ans = max(ans, post[i]);
        }
        cout << ans << "\n";
    }
}

Measured memory_bytes: 1792
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;


public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> list = new ArrayList<Integer>();            
        for(int i=1;i<=n;i++){
            if(i%3==0){
                list.add(i);
            }else{
                String s = String.valueOf(i);
                if(s.contains("3")){
                    list.add(i);
                }
            }
        }
        for(int i =0;i<list.size();i++){
            if(i==list.size()-1){
                System.out.println(" "  + list.get(i));
            }else{
                System.out.print(" "  + list.get(i));
            }
        }
    }
}




Measured memory_bytes: 30592
#include <algorithm>
#include <bits/stdc++.h>
#define MOD 1000000007

using namespace std;
using ll = long long;

int main()
{
    ll n;
    while(cin >> n){
        ll a = 10;
        ll sum = 0;
        if(n%2){
            cout << "0\n"; continue;
        }
        while( n >= a ){
            sum = sum + n/a;
            a = a*5;
        }
        cout << sum << "\n";
    }
}


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

#define sws ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define vvi vector<vi>
#define all(x) x.begin(), x.end()
#define fo(i, n) for( int i = 0; i < n; i++ )

const int INF = 1e9;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9 + 7;


int main() {sws;

    string s, t;
    cin >> s >> t;

    int difs = 0;
    for ( size_t i = 0; i < s.size(); i++ ) {
        if ( s[i] != t[i] ) difs++;
    }

    cout << difs << endl;

    return 0;
}

Measured memory_bytes: 3824
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define MOD 1000000007

long long dp[3003];


long long bipow(long long n, int m) {
    if (m == 0) return 1;
    if (m % 2 == 0) {
        n = (n * n) % MOD;
        return bipow(n, m / 2) % MOD;
    } else
        return (n * bipow(n, m - 1)) % MOD;
}

void set_table(int N, vector<long long> &fact_num, vector<long long> &fact_den){
    fact_num.resize(N+1, 0);
    fact_den.resize(N+1, 0);
    vector<long long> fact_denpow(N+1, 0);

    fact_num[0] = 1;
    for(int i=1; i<=N; i++) fact_num[i] = (fact_num[i-1] * i) % MOD;

    for(int i=0; i<=N; i++) fact_denpow[i] = bipow(i, MOD-2);
    fact_den[0] = 1;
    for(int i=1; i<=N; i++) fact_den[i] = (fact_den[i-1] * fact_denpow[i]) % MOD;
}

long long comb(const vector<long long> &fact_num, const vector<long long> &fact_den, int m, int n){
    return ((fact_num[m] * fact_den[n]) % MOD * fact_den[m-n]) % MOD;
}

void add(long long &x, long long y){
    x = (x%MOD+y%MOD)%MOD;
}
void sub(long long &x, long long y){
    x = (x%MOD-y%MOD+MOD)%MOD;
}
void mul(long long &x, long long y){
    x = ((x%MOD)*(y%MOD))%MOD;
}

int main(){
    vector<long long> fact_num, fact_den;
    set_table(223456, fact_num, fact_den);

    int H, W, N;
    cin >> H >> W >> N;
    vector<pair<int, int>> rc(N+1);
    for(int i=0; i<N; i++){
        int r, c;
        cin >> r >> c;
        rc[i] = make_pair(r, c);
    }
    rc[N] = make_pair(H, W);
    sort(rc.begin(), rc.end());

    for(int i=0; i<=N; i++){
        long long r = rc[i].first;
        long long c = rc[i].second;
        long long tmp = comb(fact_num, fact_den, r+c-2, r-1);
        for(int j=0; j<=i-1; j++){
            long long r2 = rc[j].first;
            long long c2 = rc[j].second;
            if(r2 > r || c2 > c) continue;
            long long tmp2 = comb(fact_num, fact_den, r-r2+c-c2, r-r2);
            mul(tmp2, dp[j]);
            sub(tmp, tmp2);
        }
        dp[i] = tmp;
    }
    cout << dp[N] << endl;
    return 0;
}

Measured memory_bytes: 5504
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>

using namespace std;

int main(){

    int S;
    cin >> S;
    int first = S / 100;
    int second = S % 100;

    if(0 < first && first <= 12 && 0 < second && second <= 12){
        cout << "AMBIGUOUS" << endl;
    }
    else if(0 < first && first <= 12){
        cout << "MMYY" << endl;
    }
    else if(0 < second && second <= 12){
        cout << "YYMM" << endl;
    }
    else{
        cout << "NA" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
"""ABC106D AtCoder Express2 diff:1306
"""

N, M, Q = map(int, input().split())
x = [[0]*(N+1) for _ in range(N+1)]
for _ in range(M):
    L, R = map(int, input().split())
    x[L][R] += 1
cum = [[0]*(N+1) for _ in range(N+1)]
for i in range(1, N+1):
    for j in range(1, N+1):
        cum[i][j] = cum[i-1][j] + cum[i][j-1] - cum[i-1][j-1] + x[i][j]

for _ in range(Q):
    p, q = map(int, input().split())
    ans = cum[q][q] - cum[p-1][q] - cum[q][p-1] + cum[p-1][p-1]
    print(ans)


Measured memory_bytes: 80208
B = ""
L = []
N = int(input())
W1 = input()
L.append(W1)
for _ in range(N-1):
    W = input()
    if W in L:
        print("No")
        exit()
    L.append(W)
    if not W1[-1] == W[0]:
        print("No")
        exit()
    W1 = W
print("Yes")
    
    


Measured memory_bytes: 3060
from fractions import gcd

MOD = 1000000000 + 7

N = int(input())
A = list(map(int, input().split()))

l = 1
ans = 0
for a in A:
    g = gcd(a, l)
    l = (l // g) * a
    ans = (ans * (a // g)) % MOD
    ans = (ans + (l // a)) % MOD
print(int(ans))


Measured memory_bytes: 6112
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>

using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < n; i++)
#define P pair<ll, ll>

typedef vector<int> vec;
typedef vector<vec> mat;

bool f(P x, P y){
    if (x.second != y.second) return x.second > y.second;
    else return x.first < y.first;
}

int main(){
    ll n, m;
    cin >> n >> m;
    ll a[n];
    rep(i, n) cin >> a[i];
    P b[m];
    rep(i, m) cin >> b[i].first >> b[i].second;
    sort(a, a + n);
    sort(b, b + m, f);
    ll ans = 0;
    ll idx = 0;
    rep(i, n){
        if(idx < m){
            if(a[i] < b[idx].second) {
                ans += b[idx].second;
                b[idx].first--;
            }else{
                ans += a[i];
                idx = m;
            }
        }else{
            ans += a[i];
        }
        if(b[idx].first == 0) idx++;
    }
    // rep(i, m){
    //     cout << b[i].first << " " << b[i].second << endl;
    // }
    cout << ans << endl;
}

Measured memory_bytes: 5912
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    S=STR()
    S2=S.replace('2017', '2018')
    print(S2)
if __name__ == '__main__':
    do()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
//#include "library/debug.cpp"

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

    int k, x;
    cin >> k >> x;
    if (k * 500 >= x) {
        cout << "Yes" << endl;
    } else
        cout << "No" << endl;

    return 0;
}


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

public class Program
{
    public static void Main(string[] args)
    {
        new A().test();
    }
}

public class A
{
    public void test()
    {
		// スペース区切りの整数の入力
		var input = CommonRead.ReadIntA();

		var alist = new List<int>();
		// 2,4,6...と続く数
		for (var i=1;i <= input[0]; i++)
		{
			alist.Add(i * 2);
		}

		// 1,3,5...と続く数
		var blist = new List<int>();
		for (var i = 1; i <= input[1]; i++)
		{
			blist.Add(i);
		}

		var acount = 0;
		var j = 1;
		while (j < alist.Count)
		{
			acount = acount + j;
			j++;
		}
		j = 1;
		while (j < blist.Count)
		{
			acount = acount + j;
			j++;
		}

		//出力
		Console.WriteLine(acount);

		
	}
}

static class CommonRead
{
    public static string ReadStr()
    {
        return Console.ReadLine();
    }
    public static string[] ReadStrA()
    {
        return ReadStr().Split(' ');
    }
    public static List<string> ReadStrL()
    {
        return ReadStrA().ToList();
    }
    public static int ReadInt()
    {
        return Convert.ToInt32(ReadStr());
    }
    public static int[] ReadIntA()
    {
        return ReadStrA().Select(s => Convert.ToInt32(s)).ToArray();
    }
    public static List<int> ReadIntL()
    {
        return ReadStrA().Select(s => Convert.ToInt32(s)).ToList();
    }
    public static long ReadLong()
    {
        return Convert.ToInt64(ReadStr());
    }
    public static long[] ReadLongA()
    {
        return ReadStrA().Select(s => Convert.ToInt64(s)).ToArray();
    }
    public static List<long> ReadLongL()
    {
        return ReadStrA().Select(s => Convert.ToInt64(s)).ToList();
    }

    public static decimal ReadDecimal()
    {
        return Convert.ToDecimal(ReadStr());
    }
    public static decimal[] ReadDecimalA()
    {
        return ReadStrA().Select(s => Convert.ToDecimal(s)).ToArray();
    }
    public static List<decimal> ReadDecimalL()
    {
        return ReadStrA().Select(s => Convert.ToDecimal(s)).ToList();
    }

    public static double ReadDouble()
    {
        return Convert.ToDouble(ReadStr());
    }
    public static double[] ReadDoubleA()
    {
        return ReadStrA().Select(s => Convert.ToDouble(s)).ToArray();
    }
    public static List<double> ReadDoubleL()
    {
        return ReadStrA().Select(s => Convert.ToDouble(s)).ToList();
    }

}


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

typedef long long ll;

int main() {
    int N, M, s = 0;
    cin >> N >> M;
    vector<int> A(N);
    rep(i, N) {
        cin >> A[i];
        s += A[i];
    }
    sort(A.begin(), A.end());
    if (A[N - M] * 4 * M < s) cout << "No\n";
    else cout << "Yes\n";
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define PRECISION(x) cout << fixed << setprecision(x)
#define FAST_IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define ALLR(X) (X).rbegin(), (X).rend()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second

using namespace std;
 
template<class T> bool max_self(T & a, const T & b){ 
  return b > a ? a = b, true : false; 
}
template<class T> bool min_self(T & a, const T & b){ 
  return b < a ? a = b, true : false;    
}
typedef long long LL;
//const int INF = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = (1e-9);
const LL INF = 1e18;

int N, num[(int)1e5 + 7];
LL memo[(int)1e5 + 7][2];

int main(){
  FAST_IO
  memset(memo, -1, sizeof memo);
  cin >> N;
  for(int idx = 0; idx < N; ++idx) cin >> num[idx];

  memo[N - 1][0] = num[N - 1];
  memo[N - 1][1] = -1LL * num[N - 1];

  for(int idx = N - 2; idx >= 0; --idx){
    memo[idx][0] = max(num[idx] + memo[idx + 1][0],
                       num[idx] * -1LL + memo[idx + 1][1]);

    memo[idx][1] = max(num[idx] * -1LL + memo[idx + 1][0],
                       num[idx] + memo[idx + 1][1]);
  }

  cout << memo[0][0] << '\n';
  return 0;
}


Measured memory_bytes: 2176
import java.util.Scanner;

public class Main{
    public Main(){
	Scanner sc = new Scanner(System.in);

	while(true){
	    float v = sc.nextFloat();
	    if(v == -1.0){
		break;
	    }
	    int t = (int)v;
	    String str = "";
	    while(t >= 1 && str.length() <= 8){
		str = Integer.toString(t%2) + str;
		t /= 2;
	    }
	    int s = str.length();
	    if(s > 8){
		System.out.println("NA");
		continue;
	    }
	    for(int i = 8 - s; i > 0; i--){
		str = "0" +str;
	    }
	    v = v - (int)v;
	    String st = "";
	    while(v !=  0.0 && st.length() <= 4){
		v *= 2;
		st += Integer.toString((int)(v));
		if(v >= 1.0){
		    v -= 1.0;
		}
	    }
	    s = st.length();
	    if(s > 4){
		System.out.println("NA");
		continue;
	    }

	    for(int i = 4 - s; i > 0; i--){
		st += "0";
	    }

	    System.out.println(str+"."+st);
	}
    }

    public static void main(String[] args){
	new Main();
    }
}

Measured memory_bytes: 13000
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = System.Console.ReadLine().Trim().Split(' ');
            int iN = int.Parse(sS[0]);
            sS = System.Console.ReadLine().Trim().Split(' ');

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            List<ClsUnk> lstUnk = new List<ClsUnk>();
            for (int i = 0; i < sS.Length; i++)
            {
                ClsUnk oneUsr = new ClsUnk();
                oneUsr.iI = i + 1;
                oneUsr.iN = int.Parse(sS[i]);
                lstUnk.Add(oneUsr);
            }
            lstUnk.Sort(delegate (ClsUnk mca1, ClsUnk mca2) { return mca1.iN - mca2.iN; });     // 昇順

            // 出力
            StringBuilder sbOut = new StringBuilder();
            for (int i = 0; i < lstUnk.Count; i++)
            {
                sbOut.Append(lstUnk[i].iI.ToString() + " ");
            }
            System.Console.WriteLine("{0}", sbOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

        // 情報
        private class ClsUnk
        {
            public int iI { get; set; } = 0;
            public int iN { get; set; } = 0;
        }

}


Measured memory_bytes: 35668
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
int main()
{
    int arr[110],n;
    while(cin>>n)
    {
        for(int i=0;i<n;i++)
         cin>>arr[i];
         int maxn=*max_element(arr,arr+n);
         int minn=*min_element(arr,arr+n);
         cout<<(int)abs(maxn-minn)<<"\n";
    }
    return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(dead_code)]
use std::io::prelude::*;
use std::cmp::{max, min};
use std::collections::BinaryHeap;

const MOD: i64 = 1e9 as i64 + 7; 

fn main(){
    let n: usize = read();
    let mut a: Vec<usize> = (0..n).map(|_| read()).collect();
    let mut ans: usize = 0;
    let mut p: usize = 2;
    ans += a[0] - 1;
    for i in 1..n{
        if a[i] < p{
            continue;
        }else if a[i] == p{
            p += 1;
        }else if a[i] % p == 0{
            a[i] -= p + 1;
            ans += 1;
        }
        let t = (a[i] - 1) / p;
        ans += t;
    }
    println!("{}", ans);
}

fn read<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
	string s, t;
	cin >> s >> t;
	sort(s.begin(), s.end());
	sort(t.begin(), t.end());
	reverse(t.begin(), t.end());
	if (s < t)cout << "Yes" << endl;
	else cout << "No" << endl;
	int x;
	cin >> x;
}

Measured memory_bytes: 256
main=do
 getLine;a<-map read.words<$>getLine;b<-map read.words<$>getLine
 print(f b a)
  where f [] _ = 0
        f (x:a) (y:z:b) = if y>=x then x+(f a (z:b)) else (min (z+y) x)+(f a ((max 0 (z+y-x)):b))

Measured memory_bytes: 95740
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.stream.Stream;
import java.util.Scanner;
import java.util.stream.Collectors;

/**
 * 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);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            int L = in.nextInt();
            String[] S = new String[N];
            for (int i = 0; i < N; i++) {
                S[i] = in.next();
            }
            out.println(Arrays.stream(S).sorted().collect(Collectors.joining()));
        }

    }
}



Measured memory_bytes: 27200
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
//typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define NP(X,Y) next_permutation(X,Y)
#define setdouble(X,Y) cout<<fixed<<setprecision(X)<<Y
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N,Q;
string S;
set<int> U[30];

signed main(){
	cin>>N>>S>>Q;
	REP(i,26){
		U[i].insert(INF);
	}
	REP(i,N){
		U[S[i]-'a'].insert(i);
	}
	REP(i,Q){
		int command;
		cin>>command;
		if(command==1){
			int p;
			char c;
			cin>>p>>c;
			p--;
			char pc=S[p];
			S[p]=c;
			U[pc-'a'].erase(p);
			U[c-'a'].insert(p);
		}
		else{
			int res=0;
			int l,r;
			cin>>l>>r;
			l--;
			REP(j,26){
				if(U[j].empty())continue;
				int lp=*U[j].lower_bound(l);
				int rp=*U[j].lower_bound(r);
				if(rp>lp){
					res++;
				}
			}
			cout<<res<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 24196
using System;

class Plogram
{
    static void Main()
    {

        var S = Console.ReadLine();

        int count0 = 0;
        int count1 = 0;

        for(int i = 0; i < S.Length; i++)
        {
            if(S.Substring(i,1) == "0")
            {
                count0++;
            }
            else
            {
                count1++;
            }
        }

        Console.WriteLine(2 * Math.Min(count0, count1));
    }
}

Measured memory_bytes: 15292
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

using namespace std;

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }

template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}

struct yes_no : numpunct<char> {
  string_type do_truename()  const { return "Yes"; }
  string_type do_falsename() const { return "No"; }
};

void solve(ll x, ll y) {
  ll res = 1e18;
  if (x <= y) chmin(res, y - x);
  if (x <= -y) chmin(res, -y - x + 1);
  if (-x <= y) chmin(res, y + x + 1);
  if (-x <= -y) chmin(res, -y + x + 2);
  cout << res << endl;
}

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha << setprecision(12) << fixed;
  cout.imbue(loc);
	ll x;
	ll y;
	scanf("%lld", &x);
	scanf("%lld", &y);
	solve(x, y);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    int H, W;
    while(cin >> H >> W, H != 0 && W != 0){
        for(int i = 0; i < H; i++){
            for(int j = 0; j <W; j++){
                if(i == 0 || i == H - 1 || j == 0 || j == W-1){
                    cout << "#" ;
            }else{
                    cout << ".";
                }
            }
            cout << "" << endl;
        }
        cout << "" << endl;
    }

return 0;
}

Measured memory_bytes: 3076
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        //int N = sc.nextInt();
        char[] S = sc.next().toCharArray();
        int count=0;
        int max = 0;
        for(int i=0; i<S.length; i++){
            if(S[i]=='A' || S[i]=='G' || S[i]=='C' || S[i]=='T'){
                  count++;
                  max = Math.max(max, count);
            }else{
                    count=0;
            }
        }

        
        
        
        
        
        
        
        
        
        
        
        
          System.out.println(max);
        }
    }

Measured memory_bytes: 35788
#include <bits/stdc++.h>
using namespace std;
/*
*/
struct Item {
	long long w;
	long long v;
};
vector<Item> a;
long long dp[102][100005];
int main () {
	long long n, w, t1, t2;
	cin >> n >> w;
	a.resize(n);
	for (int i=0; i<n; ++i) {
		cin >> t1 >> t2;
		a[i] = {t1, t2};
	}
	for (int j=a[0].w; j<=w; ++j) {
			dp[0][j] = a[0].v;
		}
	for (int i=1; i<n; ++i) {
		for (int j=0; j<=w; ++j) {
			if (j<a[i].w) {
				dp[i][j] = dp[i-1][j];
			}
			else
				dp[i][j] = max(dp[i-1][j], a[i].v+dp[i-1][j-a[i].w]);
		}
	}
	cout << dp[n-1][w];
}

Measured memory_bytes: 78336
#include <bits/stdc++.h>
using namespace std;
int main(){
    double a,b,h,m;
    cin >> a >> b >> h >> m;
    double c;
    c = sqrt(a*a+b*b-2*a*b*cos(2*M_PI*(1.0*h*60-1.0*11*m)/(12*60*1.0)));
    cout << fixed << setprecision(16);
    cout << c << endl;
}

Measured memory_bytes: 4216
#include <bits/stdc++.h>
#define endl '\n';

typedef long long ll;

using namespace std;

const string YES = "YES";
const string NO  = "NO";

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

    int n;

    cin >> n;

    if (n == 7 || n == 5 || n == 3) {
        cout << YES;
    } else {
        cout << NO;
    }
    cout << endl;

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;
  
  vector<int> r(n);
  for (auto& item : r) {
    cin >> item;
  }

  vector<int> m(n);
  int tmp = m[n - 1] = r[n - 1];
  for (int i = n - 1; 0 < i; --i) {
    tmp = m[i - 1] = max(tmp, r[i - 1]);
  }

  int result = m[1] - r[0];
  for (int i = 1; i < n - 1; ++i) {
    result = max(result, m[i + 1] - r[i]);
  }
  cout << result << endl;
  return 0;
}



Measured memory_bytes: 4356
def deque(a): # aの先頭or末尾を得点とする A,Bともに最適解の時得点差x-yを求める
    n=len(a)
    # dp[i][j] : a[i],...,a[j-i]の部分文字列でゲームをスタートしたときの最適解
    dp=[[0 for _ in range(n+1)] for _ in range(n+1)] 
    # 初期条件はdp[i][i]=0
    for length in range(1,n+1):
        for i in range(n-length+1):
            j=i+length
            if (n-(j-i))%2==0: # 先手
                dp[i][j]=max( dp[i+1][j] + a[i] , dp[i][j-1] + a[j-1] )
            else: # 後手
                dp[i][j]=min( dp[i+1][j] - a[i] , dp[i][j-1] - a[j-1] )
    print(dp[0][n])

def main():
    int(input())
    a = list(map(int,input().split()))
    deque(a)
if __name__ == "__main__":
    main()


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


int main()
{	
	int a,b,cnt=1;
	while(cin>>a>>b)
	{
		if(a==0&&b==0)break;
		if(a>b)swap(a,b);
		cout<<a<<" "<<b<<endl;
		cnt++;
	}
	return 0;	
}


Measured memory_bytes: 3068
#include <iostream>
#include <cassert>
#include <vector>
#include <string>

int main()
{
  // Input
  int N;
  std::cin >> N;
  std::vector<std::string> S(N);
  for (int i = 0; i < N; ++i)
    std::cin >> S[i];

  // Main
  int countBA = 0;
  int countB = 0;
  int countA = 0;
  int countAB = 0;
  for (int i = 0; i < N; ++i) {
    if (S[i].front() == 'B' and S[i].back() == 'A')
      countBA += 1;
    else if (S[i].front() == 'B')
      countB += 1;
    else if (S[i].back() == 'A')
      countA += 1;
    for (int j = 0; j < S[i].size() - 1; ++j)
      if (S[i][j] == 'A' and S[i][j + 1] == 'B')
        countAB += 1;
  }

  // Output
  int res = countAB;
  if (countBA == 0)
    res += std::min(countA, countB);
  else if (countA > 0 or countB > 0)
    res += countBA + std::min(countA, countB);
  else
    res += countBA - 1;

  std::cout << res << std::endl;

  return 0;
}


Measured memory_bytes: 896
n,k=map(int,input().split())
arr=list(map(int,input().split()))
arr=sorted(arr)
nc=0
zc=0
pc=0
for i in range(n):
  if arr[i]<0:
    nc+=1
  elif arr[i]==0:
    zc+=1
  else:
    pc+=1
ncc=nc*pc
zcc=zc*(nc+pc)+(zc*(zc-1))//2
pcc=(nc*(nc-1))//2+(pc*(pc-1))//2
if k<=ncc:
  arr1=[]
  arr2=[]
  for i in range(n):
    if arr[i]<0:
      arr1.append(-arr[i])
    elif arr[i]>0:
      arr2.append(arr[i])
  arr1=arr1[::-1]
  c1=len(arr1)
  c2=len(arr2)
  l=0
  r=10**18+1
  k=ncc-k
  while r-l!=1:
    mid=(l+r)//2
    cnt=0
    pos=c2-1
    for i in range(c1):
      while pos!=-1:
        if arr2[pos]>mid//arr1[i]:
          pos-=1
        else:
          break        
      cnt+=pos+1
    if cnt>k:
      r=mid
    else:
      l=mid
  print(-r)
elif k<=(ncc+zcc):
  print(0)
else:
  arr1=[]
  arr2=[]
  for i in range(n):
    if arr[i]<0:
      arr1.append(-arr[i])
    elif arr[i]>0:
      arr2.append(arr[i])
  arr1=arr1[::-1]
  c1=len(arr1)
  c2=len(arr2)
  l=0
  r=10**18+1
  k-=(ncc+zcc)
  while r-l!=1:
    mid=(l+r)//2
    cnt1=0
    pos1=c1-1
    for i in range(c1):
      tmp=0
      while pos1!=-1:
        if arr1[pos1]>mid//arr1[i]:
          pos1-=1
        else:
          break
      tmp+=pos1+1
      if arr1[i]**2<mid:
        tmp-=1
      cnt1+=tmp
    cnt1=cnt1//2
    cnt2=0
    pos2=c2-1
    for i in range(c2):
      tmp=0
      while pos2!=-1:
        if arr2[pos2]>mid//arr2[i]:
          pos2-=1
        else:
          break
      tmp+=pos2+1
      if arr2[i]**2<mid:
        tmp-=1
      cnt2+=tmp
    cnt2=cnt2//2
    cnt=cnt1+cnt2
    if cnt>=k:
      r=mid
    else:
      l=mid
  print(r)


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

typedef pair<int, int> pii;

const int MX = 1000010;
const int MN = 500010;

int N, M;
vector<pii> E[MX];
vector<int> X[MX];
vector<pii> adj[MN];
int ccnt;

priority_queue<pii> pq;
int dist[MN];

void dijkstra() {
    for(int i = 0; i < N + ccnt; i++) dist[i] = 1e9;
    pq.push(pii(0, 0));
    dist[0] = 0;
    while(!pq.empty()) {
        int u = pq.top().second;
        int d = -pq.top().first;
        pq.pop();

        if(d > dist[u]) continue;

        for(int i = 0; i < adj[u].size(); i++) {
            int v = adj[u][i].first;
            int w = adj[u][i].second;

            if(dist[v] > dist[u] + w) {
                dist[v] = dist[u] + w;
                pq.push(pii(-dist[v], v));
            }
        }
    }
}

int main() {
    scanf("%d %d", &N, &M);

    for(int i = 0; i < M; i++) {
        int u, v, c; scanf("%d %d %d", &u, &v, &c);
        u--; v--; c--;

        E[c].push_back(pii(u, v));
        X[c].push_back(u);
        X[c].push_back(v);
    }

    for(int c = 0; c < MX; c++) {
        sort(X[c].begin(), X[c].end());
        X[c].resize(unique(X[c].begin(), X[c].end()) - X[c].begin());

        int n = X[c].size();
        int m = E[c].size();
        vector<vector<int> > grp(n);
        vector<int> vis(n, 0), id(n);

        for(int i = 0; i < m; i++) {
            int u = E[c][i].first;
            int v = E[c][i].second;

            u = lower_bound(X[c].begin(), X[c].end(), u) - X[c].begin();
            v = lower_bound(X[c].begin(), X[c].end(), v) - X[c].begin();
            grp[u].push_back(v);
            grp[v].push_back(u);
        }

        for(int s = 0; s < n; s++) if(!vis[s]) {
            queue<int> q;
            q.push(s);
            vis[s] = 1;
            id[s] = ccnt;
            while(!q.empty()) {
                int u = q.front(); q.pop();

                for(int i = 0; i < grp[u].size(); i++) {
                    int v = grp[u][i];
                    if(!vis[v]) {
                        q.push(v);
                        vis[v] = 1;
                        id[v] = ccnt;
                    }
                }
            }
            ccnt++;
        }

        for(int i = 0; i < n; i++) {
            adj[ X[c][i] ].push_back(pii(N + id[i], 1));
            adj[ N + id[i] ].push_back(pii(X[c][i], 1));
        }
    }

    dijkstra();

    if(dist[N - 1] == 1e9) printf("-1");
    else printf("%d", dist[N - 1] / 2);
}


Measured memory_bytes: 84476
/*|In The Name Of Allah|*/
//This Month Will Be Expert ISA
#include <bits/stdc++.h>

using namespace std;

const int N = 1e5+5;

const int mod = 1e9+7;

int main(){
    int a;
    cin >> a;
    for(int i = 1; i <= 9; i++){
        for(int j = 1; j <= 9; j++){
            if(i*j == a){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 256