akhauriyash/Code-Regression huggingface dataset:
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

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

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main() {
    let n :i32 = read();
    let mut an:Vec<i32> = Vec::new();
    for _ in 0..n {
        an.push(read::<i32>());
    }
    an.sort();
    let mut i= 0;
    let mut ans = 0;
    while i < n {
        let j = an[i as usize];
        let mut count = 0;
        while i < n && an[i as usize] == j {
            count += 1;
            i += 1;
        }
        ans += count %2;
    }
    println!("{}",ans);
}

Measured memory_bytes: 4352
fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let s = sc.chars();
    let ans = match s.last().unwrap().to_digit(10).unwrap() {
        3 => "bon",
        0 => "pon",
        1 => "pon",
        6 => "pon",
        8 => "pon",
        _ => "hon",
    };
    println!("{}", ans);
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}

Measured memory_bytes: 2124
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000



int main(){
	
	int N;
	cin>>N;
	int t = 0;
	vector<int> a(N);
	for(int i=0;i<N;i++){
		cin>>a[i];
		t ^= a[i];
	}
	
	for(int i=0;i<N;i++)a[i] = (t^a[i]);
	
	for(int i=0;i<N;i++){
		if(i!=0)cout<<' ';
		cout<<a[i];
	}
	cout<<endl;
	
	return 0;
}

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

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

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

    string s;
    cin >> s;

    int nl = 0;
    int nr = 0;
    int pl = -1;
    int pr = -1;
    char prev = s[0];

    vs32 ans(s.size(), 0);
    rep (i, s.size())
    {
        if (prev == 'R' && s[i] == 'L')
        {
            pr = i - 1;
            pl = i;
            prev = s[i];
        }
        else if (prev == 'L' && s[i] == 'R')
        {
            ans[pr] = CEIL(nr, 2) + nl / 2;
            ans[pl] = nr / 2 + CEIL(nl, 2);
            prev = s[i];
            nl = nr = 0;
            pl = pr = -1;
        }
        if (s[i] == 'L') ++nl;
        else ++nr;
    }

    if (pr >= 0 && pl >= 0)
    {
        ans[pr] = CEIL(nr, 2) + nl / 2;
        ans[pl] = nr / 2 + CEIL(nl, 2);
    }
    else if (nl == 0 && nr > 0)
    {
        ans[s.size() - 1] = nr;
    }
    else if (nr == 0 && nl > 0)
    {
        ans[0] = nl;
    }

    rep (i, s.size())
    {
        cout << ans[i] << " ";
    }
    cout << "\n";
    return 0;
}



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

int R;
int main() {
	cin >> R;
	if (R < 1200) cout << "ABC" << endl;
	else if (R >= 1200 && R < 2800) cout << "ARC" << endl;
	else if (R >= 2800) cout << "AGC" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back 
#define pf push_front 
#define mp make_pair
#define fr first
#define sc second
#define Rep(i,n) for(int i=0;i<(n);i++)
#define All(v) v.begin(),v.end()
typedef pair<int, int> Pii; typedef pair<int, Pii> Pip;
const int INF = 1107110711071107;


main()
{
  string s;
  while( 1 ) {
    getline( cin, s );
    if( s == "." ) break;

    stack<bool> st;
    bool flag = true;
    for(int i=0; i<s.size(); i++) {
      if( s[i] == '(' ) st.push( true );
      if( s[i] == '[' ) st.push( false );
      if( s[i] == ')' ) {
	if( st.size() == 0 ) {flag = false; break;}
	bool tmp = st.top(); st.pop();
	if( !tmp ) {flag = false; break;}  
      }
      if( s[i] == ']' ) {
	if( st.size() == 0 ) {flag = false; break;}
	bool tmp = st.top(); st.pop();
	if( tmp ) {flag = false; break;}  
      }
    }

    if( flag && st.size() == 0 ) cout << "yes" << endl;
    else cout << "no" << endl;
  }
}

Measured memory_bytes: 3132
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
using namespace std;
namespace adaptor = boost::adaptors;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define cy cout << "Yes" << endl
#define cn cout << "No" << endl
typedef long long ll;

void Main()
{
	int N;
  	cin >> N;
  	cout << 800*N - 200*(N/15) << endl;
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 256
n,y = gets.split.map(&:to_i)

i,j,k = -1,-1,-1

(0..n).each do |a|
  (0..n-a).each do |b|
    sum = (10000 * a) + (5000 * b) + 1000 * (n - (a+b)) if n - (a+b) >= 0
    if sum == y
      i,j,k = a,b,n-(a+b)
      break
    end
  end
end

puts "#{i} #{j} #{k}"

Measured memory_bytes: 3836
import java.util.Scanner;

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

		// 入力値の取得
		long N = sc.nextLong();
		
		long sum = 0;
		for (int i = 1; i <= N; i++) {
			if (i % 3 == 0) {
				continue;
			}
			if (i % 5 == 0) {
				continue;
			}
			sum += i;
		}
		
		// 結果の出力
		System.out.println(sum);

		sc.close();
	}
}


Measured memory_bytes: 27188
/*
 _     _                             
| |__ | |__   __ _  __ _ _   _  __ _ 
| '_ \| '_ \ / _` |/ _` | | | |/ _` |
| |_) | | | | (_| | (_| | |_| | (_| |
|_.__/|_| |_|\__,_|\__, |\__, |\__,_|
                   |___/ |___/       
*/
#include<bits/stdc++.h>
 
#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<ll int,ll int>
#define msi         map<string,ll int>
#define mis         map<ll int, string>
#define mpi         map<pair<ll int,ll int>,ll int>
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
using namespace std;
 
#define N  100005

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		ll int n;
		cin>>n;
		ll int arr[n+2];
		arr[n+1]=hell;
		for(ll int i=1;i<=n;i++) cin>>arr[i];
		ll int dp[n+2];
		dp[n+1]=0;
		for(ll int i=n;i>=1;i--)
		{
			if(arr[i]>=arr[i+1]) dp[i]=1+dp[i+1];
			else dp[i]=1;
		}
		sort(dp+1,dp+n+1);
		cout<<dp[n]-1;
	}
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
static const int MAX = 2000;
static const int NIL = 1001;

int N;
vector<int> A(MAX,NIL);

int binarysearch(int x,int y){
    int left = y;
    int right = N;
    while (left + 1 < right) {
        int mid = (left + right)/2;
        if (A.at(mid) >= A.at(x) + A.at(y)) {
            right = mid;
        } else {
            left = mid;
        }
    }
    //cout << right << endl;
    return right - y - 1;
}

int main() {
    cin >> N;
    
    for (int i=0;i<N;i++){
        cin >> A.at(i);
    }
    sort(A.begin(),A.end());
    int cnt=0;
    for(int i=0;i<N-2;i++) {
        for(int j=i+1;j<N-1;j++) {
            cnt += binarysearch(i,j);
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3656
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner scn = new Scanner(System.in);
        int h = scn.nextInt();
        int w = scn.nextInt();
        int k = scn.nextInt();
        int map[][] = new int[h][w];
        int clone[][]= new int[h][w];
        int clone2[][]= new int[h][w];
        int count = 0;
        int ans = 0;

        for (int i = 0; i < h; i++) {
            String str = scn.next();
            for (int j = 0; j < w; j++) {
                if (str.charAt(j) == '#') {
                    map[i][j] = 1;
                } else {
                    map[i][j] = 0;
                }
            }
        }


        for (int i = 0; i < (1 << h); i++) {
            for (int x = 0; x < h; x++) {
                for (int y = 0; y < w; y++) {
                     clone[x][y] = map[x][y];
                }
            }
            for (int j = 0; j < h; j++) {
                if ((1 & (i >> j)) == 1) {
                    for(int s=0;s<w;s++){
                        clone[j][s]=0;

                    }
                }
            }
            for (int a = 0; a < (1 << w); a++) {
                for (int x = 0; x < h; x++) {
                    for (int y = 0; y < w; y++) {
                        clone2[x][y] = clone[x][y];
                    }
                }
                for (int b = 0; b < w; b++) {
                    if ((1 & (a >> b)) == 1) {
                        for(int s=0;s<h;s++){
                            clone2[s][b]=0;
                        }
                    }
                }
                count = 0;
                for (int x = 0; x < h; x++) {
                    for (int y = 0; y < w; y++) {
                        count += clone2[x][y];
                    }
                }
                if (count == k) {
                    ans += 1;
                }

            }


        }
        System.out.println(ans);

        scn.close();

    }


}


Measured memory_bytes: 28892
#include <iostream>
#include <string>
#include <cctype>

using namespace std;

string solve(int A, int B, const string &S)
{
	for (auto i = 0u; i < S.length(); ++i) {
		if (i == A) {
			if (S[i] != '-') {
				return "No";
			}
		}
		else {
			if (!isdigit(S[i])) {
				return "No";
			}
		}
	}
	return "Yes";
}

int main()
{
	int A, B;
	string S;
	cin >> A >> B >> S;
	cout << solve(A, B, S) << endl;
}


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

using namespace std;


int main(){
 
 long long n,k;cin >> n >> k;

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

 for (int i = 0; i < n; ++i)
 {
    cin >> f[i];
 }
 
sort(a.begin(),a.end());
sort(f.rbegin(),f.rend());


long long sum = 0,l,r,mid;
l = -1; r = a[n-1] * f[0];

while(l+1<r){

    sum = 0;
    mid = (l+r)/2;

    bool ok = [&]{
        for (int i = 0; i < n; ++i)
        {
            if (a[i] - mid/f[i]>0)
            {
               sum += a[i] - mid/f[i];
            }
            else continue;
        }
        if (sum<=k)
        {
            return true;
        }
        else{
            return false;
        }
    }();

    if (ok)
    {
        r = mid;
    }
    else{
        l = mid;
    }

}

cout << r;
return 0;
}


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

int main(){
    int n, k, d, a, ans = 0;
    cin >> n >> k;
    vector<bool>check(n);
    for (int i = 0; i < n; i++) {
        check.at(i) = true;
    }
    for (int i = 0; i < k; i++) {
        cin >> d;
        for (int j = 0; j < d; j++) {
            cin >> a;
            check.at(a-1) = false;
        }
    }
    for (int i = 0; i < n; i++) {
        if (check.at(i)) {
            ans++;
        }
    }
    cout << ans;
} 

Measured memory_bytes: 3620
use POSIX;
($N,$A,$B,@@)=glob`dd`;
for($l=-1, $r=1<<30; abs($r-$l) > 1;) {
  $= = $% = ($l + $r) / 2;
  $=-=ceil(($-=$_-$B*$%)/($A-$B))for@@;
  # print"`$l $% $r` $=$/";
  if (0 > $=){
    $l = $%;
  } else {
    $r = $%;
  }
}
print$r;


Measured memory_bytes: 28880
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <algorithm>
#include <cstring>

using namespace std;

int main(void)
{
    int N;
    cin >> N;
    int ok[10001];
    memset(ok, 0, sizeof(ok));
    for (int i = 1; i < 10; i++)
    {
        for (int j = 1; j < 10; j++)
        {
            ok[i * j] = 1;
        }
    }
    if (ok[N] == 1)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    long long n, k;
    cin >> n >> k;
    long long cnt = n / k;
    if(k%2==1)
        cout << cnt * cnt * cnt << endl;
        else{
            long long a = 0;
            for (int i = 1; i <= n;i++){
                if(i%k==k/2)
                    a++;
            }
            cout << cnt * cnt * cnt + a * a * a << endl;
        }
}

Measured memory_bytes: 256
max_n = 1_000_000

is_prime = [false]*2 + [true]*(max_n - 1)

m = Math.sqrt(max_n)
2.upto(m) do |i|
  next unless is_prime[i]
  (i*i).step(by: i, to: max_n) do |j|
    is_prime[j] = false
  end
end

count = 0
prime_count = []
0.upto(max_n) do |i|
  count += 1 if is_prime[i]
  prime_count[i] = count
end

while n = gets.to_i
  break if n == 0
  puts prime_count[n]
end

Measured memory_bytes: 32072
#include<iostream>
#include<string>
#define value( x ) cout<< "value of "<< #x << " is "<< x<<endl;
using namespace std;
int main()
{
	
   int n, m, a[100], b[100], c[1000], d[100], sol[100], counting=0;
   cin>>n>>m;
   for(int i=1 ;i<= n;i++)
   	cin>>a[i]>>b[i];
   for(int i=1;i<=m;i++)
   	{cin>>c[i]>>d[i];}
   int minimum, temp, solution;
    for(int i=1;i<=n;i++)
    {
    	minimum=300000000;
    	for(int j=1;j<=m;j++)
    	{
    		temp=abs(a[i]-c[j])+abs(b[i]-d[j]);
    		if(temp<minimum)
    		{minimum=temp;
    			solution=j;}
    				//value(temp);
    	}
    	sol[counting++]=solution;
    }
    for(int i=0;i<counting;i++) {cout<<sol[i]<<endl;}
return 0;
}


Measured memory_bytes: 256
K=int(input())

from collections import deque
num=deque()
for i in range(1,10):
  num.append(i)

for j in range(K):
  l=num.popleft()
  if l%10 !=0:
    num.append(l*10+(l%10-1))
  num.append(l*10+(l %10))
  if l%10 != 9:
    num.append(l*10+(l%10+1))

print(l)

Measured memory_bytes: 12384
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n,k;
  string s;
  cin >> n >> k >> s;
  s[k-1]=tolower(s[k-1]);
  pr(s);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 256
/*
        karmany evadhikaras te
        ma phalesu kadacana 
        ma karma-phala-hetur bhur
        ma re sango'stv akarmani (B.G.-2.47)
 
Translation:
        Lord Krsna to Arjuna.
You have a right to perform your prescribed duty, 
but you are not entitled to the fruits of action. 
Never consider yourself the cause of the results of your activities, 
and never be attached to not doing your duty.    
*/
#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define int long long
const int N = 105;
const ll mod = 1e9+7;
#define ld long double
#define PI 3.14159265358979323846
const int INF = 10000000;

void flash()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(2);
}

//3. Structure or classes
//3. Ends here

//1. Data structures declaration here
//1. Ends here

//2. Extra Functions here
//2. Ends here


void solve();
int32_t main()
{
    flash();
    int t;
    t = 1;
    //cin>>t;
    while(t--){
        solve();
        //cout<<"\n";
    }
    return 0;
}

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

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

    for(int i=k+1;i<=n;i++){
        if(a[i]>a[i-k]){
            cout<<"Yes";
        }
        else cout<<"No";
        cout<<"\n";
    }

    return;
}
// how r u bro

Measured memory_bytes: 5220
int main() {
  long long I, O, T, J, L, S, Z;
  scanf("%lld%lld%lld%lld%lld%lld%lld", &I, &O, &T, &J, &L, &S, &Z);
  long long n = (I&1?I-1:I) + (J&1?J-1:J) + (L&1?L-1:L);
  if (I && J && L) {
    long long m = (I&1?I-1:I-2) + (J&1?J-1:J-2) + (L&1?L-1:L-2) + 3;
    printf("%lld", (n<m?m:n) + O);
  } else {
    printf("%lld", n + O);
  }
}

Measured memory_bytes: 128
n = int(input())
a = list(map(int, input().split()))

# 貪欲法
# a[i] < a[i+1]なら全部買う
# a[i] > a[i+1]なら全部売る

money = 1000
stock = 0
for i in range(n):
    if i == n-1 or a[i] > a[i+1]:
        money += stock * a[i]
        stock = 0
    elif money > a[i]:
        stock = money // a[i]
        money = money % a[i]

print(money)

Measured memory_bytes: 8992
S = input()[::-1]

mods = [0]*2019
mods[0] += 1
f = 0
for i in range(len(S)):
    f = (f+pow(10,i,2019)*int(S[i]))%2019
    mods[f] += 1

print(sum([i*(i-1)//2 for i in mods]))

Measured memory_bytes: 9392
#include<iostream>
#include<vector>
#define MAX 1000010
using namespace std;
int main(){
	vector<int> pre(MAX);
	int a,d,n,now;
	for(int i=0;i<MAX;i++)
		pre[i]=1;
	pre[0]=0;
	pre[1]=0;
	for(int i=0;i*i<MAX;i++)
	if(pre[i]){
		for(int j=i*2;j<MAX;j+=i)
			pre[j]=0;
	}
	while(cin>>a>>d>>n,a||d||n){
		now=0;
		while(now!=n){if(pre[a]==1)
			now++;
			a+=d;
			
		}
		cout<<a-d<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const (
	N    = 3
	BASE = 10007
	MOD  = 1000000007
)

type Puzzle struct {
	board [N * N]int // (x, y). (0, 0) = 0,  (1, 0) = 1, (0, 1) = 3
}

type SolveContext struct {
	current *Puzzle
	count   int
}

type Position struct {
	x int
	y int
}

func NewPuzzle(b [N * N]int) *Puzzle {
	return &Puzzle{board: b}
}

func (puzzle *Puzzle) hash() int {
	arr := puzzle.board
	sum := arr[0]
	for i := 1; i < len(arr); i++ {
		sum = sum*BASE + arr[i]
		if sum > MOD {
			sum = sum % MOD
		}
	}
	return sum
}

func (puzzle *Puzzle) isSolved() bool {
	solvedBoard := [N * N]int{1, 2, 3, 4, 5, 6, 7, 8, 0}
	return puzzle.board == solvedBoard
}

func swap(puzzle *Puzzle, one, two Position) *Puzzle {
	swapped := NewPuzzle(puzzle.board)
	swapped.board[one.y*N+one.x], swapped.board[two.y*N+two.x] =
		swapped.board[two.y*N+two.x], swapped.board[one.y*N+one.x]
	return swapped
}

func (puzzle *Puzzle) getEmptyPosition() *Position {
	for i := 0; i < N; i++ {
		for j := 0; j < N; j++ {
			if puzzle.board[i*N+j] == 0 {
				return &Position{x: j, y: i}
			}
		}
	}
	return nil
}

func (puzzle *Puzzle) nextPuzzles() []*Puzzle {
	emptyPosition := puzzle.getEmptyPosition()
	if emptyPosition == nil {
		panic(fmt.Errorf("emptyPostion must not be empty"))
	}
	basePosition := *emptyPosition
	directions := [][2]int{[2]int{-1, 0}, [2]int{1, 0}, [2]int{0, -1}, [2]int{0, 1}} // []{x, y}
	nexts := []*Puzzle{}
	for _, dir := range directions {
		nextPosition := Position{basePosition.x + dir[0], basePosition.y + dir[1]}
		if nextPosition.x >= 0 && nextPosition.x <= N-1 &&
			nextPosition.y >= 0 && nextPosition.y <= N-1 {
			nexts = append(nexts, swap(puzzle, basePosition, nextPosition))
		}
	}
	return nexts
}

func solve(initialPuzzle *Puzzle) int {
	initial := SolveContext{initialPuzzle, 0}
	visited := make(map[int]*struct{})
	stack := []SolveContext{initial}
	var solved SolveContext
	for len(stack) > 0 {
		solveContext := stack[0]
		current := solveContext.current
		count := solveContext.count
		visited[current.hash()] = &struct{}{}
		stack = stack[1:]
		if current.isSolved() {
			solved = solveContext
			break
		}
		for _, v := range current.nextPuzzles() {
			if visited[v.hash()] == nil {
				nextContext := SolveContext{v, count + 1}
				stack = append(stack, nextContext)
			}
		}
	}
	return solved.count
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	var arr [N * N]int
	for i := 0; i < len(arr); i++ {
		x, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		arr[i] = x
	}

	puzzle := NewPuzzle(arr)
	fmt.Println(solve(puzzle))
}

func nextInt(sc *bufio.Scanner) (int, error) {
	sc.Scan()
	return strconv.Atoi(sc.Text())
}



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

string s;

int main(){
  cin >> s;
  string res = "";
  rep(i, s.size()){
    if(s.at(i) == '0'){
      res += '0';
    }else if(s.at(i) == '1'){
      res += '1';
    }else if(s.at(i) == 'B' && s.size()){
      res = res.substr(0, res.size() - 1);
    }
  }
  cout << res << endl;
  
  return 0;
}


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

int N;
int x[10],y[10];

double dist(int i, int j){
 int dx = x[i] - x[j];
 int dy = y[i] - y[j];
 return pow(dx*dx+dy*dy,0.5);
}

void solve(){
  cin >> N;
  for(int i=0;i<N;i++) cin >> x[i] >> y[i];
  double sum;
  vector<int> v(N);
  for(int i=0;i<N;i++) v.at(i)=i;
  do{
    for(int i=0; i<N-1; i++)sum += dist(v.at(i), v.at(i+1));
  }while(next_permutation(v.begin(),v.end()));
  int dn = 1;
  for(int i=2; i<=N; i++) dn *= i;
  cout << fixed << setprecision(10) << sum/dn <<endl;
  return;
}

int main(void){
  solve();
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define faster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define mp make_pair
#define mod 1000000007
#define qmod 998244353
#define endl "\n"
#define pb push_back
#define ff first
#define ss second
 
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
 
const int MOD = 1e9 + 7;
const int INF = 1e9 + 5;
const ll LINF = LLONG_MAX;

int main(){
	int a,b;
	cin>>a>>b;
	int x=1;
	int ans=0;
	while(x<b){
		x--;
		x +=a;
		ans++;
	}
	cout<<ans<<endl;

}

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

using namespace std;
int main()
{
    int n;
    cin>>n;
    double a[n],b[n],t=0,c[n];
    for(int i=0;i<n;i++){
        cin>>a[i]>>b[i];
    }
    int f=1;
    for(int i=1;i<=n;i++){
        f=f*i;
    }
    //cout<<f<<endl;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            t=t+sqrt(pow((a[i]-a[j]),2)+pow((b[i]-b[j]),2));
        }
    }

    t=t*(f/n)*2/f;
    printf("%.6lf",t);
}


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

int main(){
    char b;
    cin>>b;
    switch (b){
        case 'A':cout<<'T';break;
        case 'C':cout<<'G';break;
        case 'T':cout<<'A';break;
        case 'G':cout<<'C';break;
        default:break;
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
S = input()

count = 0

R_count = [0] * (N+1)
R = 0
G_count = [0] * (N+1)
G = 0
B_count = [0] * (N+1)
B = 0

for i, s in enumerate(reversed(list(S))):
    if s == 'R':
        R += 1
    if s == 'G':
        G += 1
    if s == 'B':
        B += 1

    R_count[N - i - 1] = R
    G_count[N-i-1] = G
    B_count[N-i-1] = B
# print(R_count)
# print(G_count)
# print(B_count)

for i in range(0, N-2):
    for j in range(i+1, N-1):
        if S[i] == S[j]:
            continue
        if (S[i] == 'R' and S[j] == 'G') or (S[i] == 'G' and S[j] == 'R'):
            count += B_count[j+1]
            if j + (j-i) < N and S[j + (j-i)] == 'B':
                count -= 1
        elif (S[i] == 'R' and S[j] == 'B') or (S[i] == 'B' and S[j] == 'R'):
            count += G_count[j+1]
            if j + (j-i) < N and S[j + (j-i)] == 'G':
                count -= 1
        if (S[i] == 'B' and S[j] == 'G') or (S[i] == 'G' and S[j] == 'B'):
            count += R_count[j+1]
            if j + (j-i) < N and S[j + (j-i)] == 'R':
                count -= 1
print(count)

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

#define INF (2e9)
#define FOR(i, a, b) for (ll (i) = (a); (i) < (b); ++(i))
#define REP(i, n) FOR(i, 0, n)

using namespace std;

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

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

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

#define ALL(x) (x).begin(), (x).end()
template<class T>
using vc = vector<T>;
using vi = vc<ll>;
using vvi = vc<vi>;

template<class T>
using va = valarray<T>;
using vad = va<ld>;
using vai = va<ll>;

vi Read(ll n) {
    auto      v = vi(n);
    for (auto i = std::size_t(0); i < n; ++i) {
        cin >> v[i];
    }
    return v;
}

template<class T>
void Dump(const T& A) {
    for (const auto& value : A)
        cout << value << "\n";
}

int main() {
    int n, p;
    cin >> n >> p;

    auto v = vc<queue<int>>(n);

    REP(i, p) {
        int query, t;
        cin >> query >> t;

        if (query == 0) {
            int x;
            cin >> x;
            v[t].push(x);
        } else if (query == 1) {
            if (!v[t].empty()) cout << v[t].front() << endl;
        } else if (query == 2) {
            if (!v[t].empty()) v[t].pop();
        } else cout << "Error: query is not correct\n";
    }

    return 0;
}



Measured memory_bytes: 4324
#include <iostream>
#include <iomanip>
#include <cmath>

double nth_round(double value, int n) {
    double scale = pow(10, n - 1);
    return std::round(value * scale + 0.01) / scale;
}

int main() {
    double a, b, c, d, e, f;
    double coef;
    
    while (std::cin >> a >> b >> c >> d >> e >> f) {
        coef = 1. / (a * e - b * d);
        std::cout << std::fixed
                  << std::setprecision(3)
                  << nth_round(coef * (c * e - b * f), 4) << " "
                  << nth_round(coef * (a * f - c * d), 4) << std::endl;
    }

    return 0;
}

Measured memory_bytes: 1328
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int a,b;

int main(){
	cin>>a>>b;
	if(a<6) b=0;
	if(a<13) b/=2;
	cout<<b<<endl;
}

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

using namespace std;
#define taskname "TEST"
#define pb	push_back
typedef long double ld;
typedef long long ll;
const int maxn = 1e6;
int dp[(int)1e5 + 5] , a[105] , n , k;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	if(fopen(taskname".INP","r"))
        freopen(taskname".INP", "r",stdin) ,
        freopen(taskname".OUT", "w",stdout);
    cin >> n >> k;
    for(int i = 1 ; i <= n ; ++i)
        cin >> a[i];
    dp[0] = 0;
    for(int i = 1 ; i <= k ; ++i)
    {
        for(int j = 1 ; j <= n ; ++j)
        {
            if(i >= a[j])dp[i] |= (!dp[i - a[j]]);
            else break;
        }
    }
    cout << (dp[k] == 1 ? "First" : "Second");
}


Measured memory_bytes: 640
def factorize(n):
    retlist = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            while temp%i==0:
                temp //= i
                retlist.append(i)
 
    if temp!=1:
        retlist.append(temp)
 
    if retlist==[]:
        retlist.append(n)
 
    return retlist
 
n=int(input())
a=[]
for i in range(1,n+1):
    a+=factorize(i)

from collections import Counter
c=Counter(a)
c=c.most_common()
c3=0
c5=0
c15=0
c25=0
c75=0
for k,v in c:
  if 2<=v<4:c3+=1
  elif 4<=v<14:c5+=1
  elif 14<=v<24:c15+=1
  elif 24<=v<74:c25+=1
  elif 74<=v:c75+=1
c3=c3+c5+c15+c25+c75
c5=c5+c15+c25+c75
c15=c15+c25+c75
c25=c25+c75
ans=0
ans+=(c5*(c5-1)//2)*(c3-2)
ans+=c15*(c5-1)
ans+=c25*(c3-1)
ans+=c75
print(ans)

Measured memory_bytes: 3316
using System;
 
public class ABC153 {
  public static void Main(string[] args) {
    var str = Console.ReadLine().Split(new string[]
                                       {" "}, StringSplitOptions.RemoveEmptyEntries);
    var h = int.Parse(str[0]);
    var a = int.Parse(str[1]);
    
    if (h % a == 0) {
      Console.WriteLine(h / a);
    }else {
      Console.WriteLine(h / a + 1);
    }
  }
}

Measured memory_bytes: 11220
s=input()
l=len(s)
se=dict()
k=0
for i in range(l-1,-1,-1):
    k+=(pow(10,l-1-i,2019)*int(s[i]))
    k%=2019
    if k in se:
        se[k]+=1
    else:
        se[k]=1

ans=0
for j in se:
    i=se[j]
    if i>1:
        ans+=(i*(i-1)//2)
    if j==0:
        ans+=i
print(ans)

Measured memory_bytes: 68648
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;
using ll = long long;

int main() {
    int m1, d1;
    cin >> m1 >> d1;

    int m2, d2;
    cin >> m2 >> d2;

    int r = m1 != m2;
    cout << r << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define pb push_back
#define eb emplace_back
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;


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

int main(){
    ll n; cin >> n;
    vector<ll> a(n);
    ll ma = 0;
    rep(i,n) {cin >> a[i];chmax(ma,a[i]);}
    ll cnt = 0;
    bool ok = true;
    rep(i,n){
        if(a[i] == ma)cnt++;
        if(a[i] < ma-1)ok = false;
    }
    if(ma == n-1){
        if(cnt != n && cnt != 2)ok = false;
    }
    else if(n / ma == 1){
        if(n-cnt < ma-(n%ma) || ma-1 < n-cnt)ok = false;
    }
    else{
        if(ma-1 < n-cnt)ok = false;
    }

    cout << (ok ? "Yes" : "No") << endl;

}

Measured memory_bytes: 1024
def check(b):
    b = int(b)
    if b > 753:
        a = b-753
    else:
        a = 753-b
    return a

S = str(input())
a = 0

b = int(S[0])*100+int(S[1])*10+int(S[2])

ans = check(b)

for i in range(1,len(S)-2):
    b = int(S[i])*100+int(S[i+1])*10+int(S[i+2])
    a = check(b)
    if ans > a:
        ans = a

print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1e9+7;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

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

int main(){
    ll N; cin >> N;
    if (N==1){
        cout << 1 << endl;
        return 0;
    }
    vector<ll> A(N);
    rep(i,N) cin >> A[i];
    rep(i,N-1){
        if (A[i+1]<=A[i]) break;
        if (i==N-2){
            cout << 1 << endl;
            return 0;
        }
    }
    ll lb=1,ub=N+1;
    map<ll,ll> m;
    while(ub-lb>1){
        ll mid=(ub+lb)/2;
        m.clear();
        bool ok=true;
        rep(i,N-1){
            if (A[i+1]<=A[i]){
                auto itr=m.upper_bound(A[i+1]);
                m.erase(itr,m.end());
                ll now=A[i+1];
                ++m[now];
                while(m[now]>=mid){
                    m.erase(now);
                    --now;
                    if (now==0){
                        ok=false;
                        break;
                    }
                    ++m[now];
                }
                if (!ok) break;
            }
        }
        if (ok) ub=mid;
        else lb=mid;
    }
    cout << ub << endl;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <math.h>
#include <string.h>
int main(){
    int i, n, ans=0;
    char s[200001], t[200001];

    scanf("%s",s);
    scanf("%s",t);

    n=strlen(s);
    for(int i=0;i<n;i++){
       if(s[i]!=t[i])
       ans++;
    }
    printf("%d",ans);

return 0;
}

Measured memory_bytes: 2116
#include <stdio.h>
int x[105];
int min(int a,int b){
	return a<b?a:b;
}
int main(){
	int n,i,ans1=0,ans2=0,avg=0;
	scanf("%d",&n);
	for(i=1;i<=n;i++)scanf("%d",&x[i]),avg+=x[i];
	avg/=n;
	for(i=1;i<=n;i++)ans1+=(x[i]-avg)*(x[i]-avg);
	avg+=1;
	for(i=1;i<=n;i++)ans2+=(x[i]-avg)*(x[i]-avg);
	printf("%d\n",min(ans1,ans2));
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
using Graph = vector<vector<int>>;
using Graphl = vector<vector<ll>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
#define RRep(i, k, n) for (int i = k; i > (int)(n); i--)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define ALL(a)  (a).begin(),(a).end()
#define rALL(a)  (a).rbegin(),(a).rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> void PrintVector(const vector<T> &vec) {for (auto val : vec) cout << val << " "; cout << endl;}
const long long INF = 1LL << 60;
const long long minusINF = -(1LL << 40);
const int MOD = 1000000007;
const double PI = acos(-1); //3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    int n; cin >> n;
    int div = n / 100;
    int ans = div * 111;
    if (div * 111 < n) ans = (div + 1) * 111;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <bitset>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <regex>
using namespace std;
using ll = long long int;
using dd = long double;
const ll MOD = 1e9 + 7;

vector<string> dfs(string s, ll depth, vector<char> symbol)
{
    vector<string> ret;
    if (depth == 0)
    {
        ret.push_back(s);
        return ret;
    }

    for (ll i = 0; i < symbol.size(); i++)
    {
        auto vec = dfs(s + symbol[i], depth - 1, symbol);
        for (auto &&e : vec)
        {
            ret.push_back(e);
        }
    }
    return ret;
}

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

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

    ll left = A + B;
    ll right = C + D;

    if (left == right) {
        cout << "Balanced" << endl;
    } else if (left > right) {
        cout << "Left" << endl;
    } else {
        cout << "Right" << endl;
    }
}

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

/// --- BIT Library {{{ ///

struct BIT{
  vector<ll> data;
  int n;
  BIT(int n): n(n){
    data.resize(n, 0);
  }
  void clear(int sz=0) {
    if(sz > 0) n = sz;
    data.assign(n, 0);
  }
  void add(int i, ll x) {
    i++;
    while(i<=n){
      data[i-1] += x;
      i += i&-i;
    }
  }
  ll sum(int i) {
    if(i<0) return 0;
    i++;
    ll s = 0;
    while(i>0){
      s += data[i-1];
      i -= i&-i;
    }
    return s;
  }
  ll range(int a, int b) {
    return sum(b) - sum(a-1);
  }
};

/// }}}--- ///

set<int> c[30];
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  string s; cin >> s;
  int n = s.size();
  BIT bit(n + 10);
  for(int i = 0; i < n; i++) c[s[i]%26].emplace(i);
  ll ans = 0;
  for(int i = 0; i < n; i++) bit.add(i, 1);
  for(int i = 0; i < n / 2; i++) {
    int mav = 1e9, pj = -1;
    for(int j = 0; j < 26; j++) {
      if(c[j].size() == 0) continue;
      int mi = *c[j].begin();
      int ma = *(--c[j].end());
      mi = bit.sum(mi) - 1;
      ma = bit.sum(ma) - 1;
      if(mi == ma) continue;
      int v = mi + (n - 1 - i * 2 - ma);
      if(v < mav) {
        mav = v; pj = j;
      }
    }
    if(pj == -1) return (cout << -1 << endl, 0);
    ans += mav;
    int mi = *c[pj].begin();
    int ma = *(--c[pj].end());
    c[pj].erase(c[pj].begin());
    c[pj].erase(--c[pj].end());
    bit.add(mi, -1);
    bit.add(ma, -1);
  }
  cout << ans << endl;
}


Measured memory_bytes: 11412
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define Int int32_t
#define all(c) c.begin(), c.end()
#define FAST ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define pii pair< int , int >
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define bitcnt(n) __builtin_popcountll(n)
#define setpre(n) cout << fixed << setprecision(n)
#define tr(c) for(auto x : c )cout << x << " ";
#define ol(c , s , e ) for(int pos=s; pos<e ; pos++) cout << c[pos] << " ";
#define PI acos(-1)
const int M = 1000000007;
const int N=1e6+5;
const int INF = 1e18+5;

//#define rohit
#ifdef rohit
template<typename... T >
void bug(T... __VA_ARGS__) {
    ((cerr << __VA_ARGS__ << " ") , ...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", bug(__VA_ARGS__) , cerr << endl;
#endif

void solve()
{
    int k;
    cin >> k;
    string s;
    cin >> s;
    if(k >=s.size()){
        cout << s << endl;
        return;
    }
    s.replace(s.begin()+k , s.end() ,  "...");
    cout << s << endl;


}

signed main()
{
    FAST;
    //TODO:  check test cases.
    int tc=1;
//    cin >> tc;
    for(int t = 1 ; t <= tc ; t++)
    {
        solve();
    }
}

/*TODO: (Extra Cares)
 * 1)Sometimes long long creates MLE.
 * 2)Check whether int to long long typecasting is commented or not?
 * 3)Check overflows.
*/

Measured memory_bytes: 3660
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int long long

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

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

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

    int X, Y, A, B, C;
    cin >> X >> Y >> A >> B >> C;

    vi p(A), q(B);
    vi ans(C);
    REP(i, A) cin >> p[i];
    REP(i, B) cin >> q[i];
    REP(i, C) cin >> ans[i];

    sort(ALL(p), greater<>());
    sort(ALL(q), greater<>());

    REP(i, min(A, X)) ans.emplace_back(p[i]);
    REP(i, min(B, Y)) ans.emplace_back(q[i]);

    sort(ALL(ans), greater<>());

    ll acc = 0;
    REP(i, X+Y) acc += ans[i];
    cout << acc << endl;
}


Measured memory_bytes: 6128
numbers = {str(i) for i in range(10)}
N, K = map(int, input().split())
*D, = map(str, input().split())
D = set(D)
available = numbers - D
ans = 0
for i in range(N, 100000):
    nums = set(str(i))
    if nums <= available:
        print(i)
        break

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std; 
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ll long long int
#define ld long double
#define fi first 
#define se second 
#define mp make_pair
#define pii pair<int ,int > 
#define pb push_back
#define mo 1000000007

int n ;ll w ; int v[102]; ll dp[100005];ll ww[102];


int main()
{ios; cin>>n>>w; 
for(int i = 0 ; i<n ; i++)
{
	cin>>ww[i]>>v[i];
	
}


int sum = 0; 
for(int i = 0; i<n; i++)
{  
    sum+= v[i];
	for(int j = sum ; j>=v[i]; j--)
	{
	    
	    	if(dp[j-v[i]]>0)
	    	{
	    		if(dp[j]==0)
	    		dp[j]= dp[j-v[i]]+ww[i];
	    		else
	    		dp[j]= min(dp[j],dp[j-v[i]]+ww[i]);
			}
		
	}
	if(dp[v[i]]==0)
	dp[v[i]]= ww[i];
	else
	dp[v[i]]= min(ww[i],dp[v[i]]);
}
ll ans = 0; 
for(int i = sum ; i>=0 ; i--)
{   
	
	if(dp[i]>0&&dp[i]<=w)
	{
		ans = i; break;
	}
	
}
cout<<ans; 
return(0);
}



Measured memory_bytes: 1024
#include<queue>
#include<cctype>
#include<cstdio>
#include<vector>
#include<utility>
#include<algorithm>
const int N=2007;
using pi=std::pair<int,int>;
int n,a[N],vis[N],deg[N];std::vector<int>e[N];std::priority_queue<pi>q;
int read(){int x=0,c=getchar();while(isspace(c))c=getchar();while(isdigit(c))(x*=10)+=c&15,c=getchar();return x;}
void dfs(int u)
{
    for(int v=vis[u]=1;v<=n;++v) if(!vis[v]&&std::__gcd(a[u],a[v])>1) e[u].push_back(v),++deg[v],dfs(v);
}
int main()
{
    n=read();
    for(int i=1;i<=n;++i) a[i]=read();
    std::sort(a+1,a+n+1);
    for(int i=1;i<=n;++i) if(!vis[i]) dfs(i);
    for(int i=1;i<=n;++i) if(!deg[i]) q.emplace(a[i],i);
    for(int u;!q.empty();)
    {
	printf("%d ",q.top().first),u=q.top().second,q.pop();
	for(int v:e[u]) if(!--deg[v]) q.emplace(a[v],v);
    }
}


Measured memory_bytes: 3452
import java.util.Scanner;

/**
 * TITLE : Digits
 * URL : https://atcoder.jp/contests/abc156/tasks/abc156_b
 */
public class Main {

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        System.out.println(Integer.toString(N, K).length());
        sc.close();
    }
}

Measured memory_bytes: 22612
def main():
    N, K = map(int, input().split())
    X = list(map(int, input().split()))
    P = []
    M = []
    for x in X:
        if x < 0:
            M.append(-1 * x)
        else:
            P.append(x)
    M.reverse()

    if len(P) == 0:
        print(M[K - 1])
        exit()
    elif len(M) == 0:
        print(P[K - 1])
        exit()

    ans = 10 ** 10
    for i, m in enumerate(M, start=1):
        d = None
        if i == K + 1:
            break
        elif i == K:
            d = m
        else:
            p_idx = K - i - 1
            if p_idx >= len(P):
                continue
            else:
                d = m * 2 + P[p_idx]
        if d < ans:
            ans = d

    for i, p in enumerate(P, start=1):
        d = None
        if i == K + 1:
            break
        elif i == K:
            d = p
        else:
            m_idx = K - i - 1
            if m_idx >= len(M):
                continue
            else:
                d = p * 2 + M[m_idx]
        if d < ans:
            ans = d

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 90740
// AOJ ALDS1_5_B Merge Sort
// 2018.4.30 bal4u

#include <stdio.h>
#include <string.h>

#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif

int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

char buf[20];
void mypr(int n)
{
	int w;
	if (!n) { pc('0'); return; }
	w = 0; while (n) buf[w++] = n%10 + '0', n/=10;
	while (w--) pc(buf[w]);
}

#define MAX_N 500002
int *a;
int w[MAX_N/2+2];
int cnt;

void merge(int low, int high) 
{ 
   int i, j, k, p, mid; 

   if (low < high) {
	   mid = (low + high) >> 1;
	   merge(low, mid);
	   merge(mid+1, high);

	   p = mid-low+1, cnt += high-low+1;
	   memcpy(w, a+low, p << 2);
	   i = mid+1, j = 0; k = low;
	   while (i <= high && j < p) {
		   if (w[j] <= a[i]) a[k++] = w[j++];
		   else              a[k++] = a[i++];
	   }
	   memcpy(a+k, w+j, (p-j) << 2);
   }
}

void merge_sort(int n, int *aa)
{
	a = aa;
	merge(0, n-1);
}

int aa[MAX_N];

int main()
{
	int n, i;
	
	n = in();
	for (i = 0; i < n; i++) aa[i] = in();

	cnt = 0;
	merge_sort(n, aa);
	mypr(a[0]); for (i = 1; i < n; i++) pc(' '), mypr(a[i]); pc('\n');
	mypr(cnt); pc('\n');
	return 0;
}


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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  int N; cin >> N;
  VI xs(N); REP(i,N) cin >> xs[i];

  LL ans = 1e15;
  for(int x=-100;x<=100;++x){
	LL sum = 0;
	REP(i,N){
	  sum += (xs[i]-x)*(xs[i]-x);
	}
	ans = min(ans, sum);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#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(int i = 0; i < n; i++)
#define P pair<int, int>

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

const ll mod = 1000000007;

int main(){
    int n;
    cin >> n;
    int d[2][n];
    rep(i, n){
        cin >> d[0][i] >> d[1][i];
    }
    int num = 0;
    rep(i, n){
        if(d[0][i] == d[1][i]){
            num++;
        }else{
            num = 0;
        }
        if(num == 3){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3628